]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - drivers/iio/common/hid-sensors/hid-sensor-attributes.c
iio: hid-sensor-hub: Implement batch mode
[mirror_ubuntu-jammy-kernel.git] / drivers / iio / common / hid-sensors / hid-sensor-attributes.c
index 0e05f6d1e76156a1fc5399ac994b3b5995b3cce3..f5d4d786e1932f93576e75e23468e694a24e827a 100644 (file)
@@ -410,6 +410,48 @@ int hid_sensor_get_reporting_interval(struct hid_sensor_hub_device *hsdev,
 
 }
 
+static void hid_sensor_get_report_latency_info(struct hid_sensor_hub_device *hsdev,
+                                              u32 usage_id,
+                                              struct hid_sensor_common *st)
+{
+       sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT,
+                                           usage_id,
+                                           HID_USAGE_SENSOR_PROP_REPORT_LATENCY,
+                                           &st->report_latency);
+
+       hid_dbg(hsdev->hdev, "Report latency attributes: %x:%x\n",
+               st->report_latency.index, st->report_latency.report_id);
+}
+
+int hid_sensor_get_report_latency(struct hid_sensor_common *st)
+{
+       int ret;
+       int value;
+
+       ret = sensor_hub_get_feature(st->hsdev, st->report_latency.report_id,
+                                    st->report_latency.index, sizeof(value),
+                                    &value);
+       if (ret < 0)
+               return ret;
+
+       return value;
+}
+EXPORT_SYMBOL(hid_sensor_get_report_latency);
+
+int hid_sensor_set_report_latency(struct hid_sensor_common *st, int latency_ms)
+{
+       return sensor_hub_set_feature(st->hsdev, st->report_latency.report_id,
+                                     st->report_latency.index,
+                                     sizeof(latency_ms), &latency_ms);
+}
+EXPORT_SYMBOL(hid_sensor_set_report_latency);
+
+bool hid_sensor_batch_mode_supported(struct hid_sensor_common *st)
+{
+       return st->report_latency.index > 0 && st->report_latency.report_id > 0;
+}
+EXPORT_SYMBOL(hid_sensor_batch_mode_supported);
+
 int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
                                        u32 usage_id,
                                        struct hid_sensor_common *st)
@@ -451,6 +493,8 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
        } else
                st->timestamp_ns_scale = 1000000000;
 
+       hid_sensor_get_report_latency_info(hsdev, usage_id, st);
+
        hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x %x:%x\n",
                st->poll.index, st->poll.report_id,
                st->report_state.index, st->report_state.report_id,