Re: [PATCH 1/3] iio: hid-sensors: Move get sensitivity attribute to hid-sensor-common

2021-01-23 Thread Jonathan Cameron
On Wed, 20 Jan 2021 15:47:04 +0800
Ye Xiang  wrote:

> No functional change has been made with this patch. The main intent here
> is to reduce code repetition of get sensitivity attribute.
> 
> In the current implementation, sensor_hub_input_get_attribute_info() is
> called from multiple drivers to get attribute info for sensitivity
> field. Moving this to common place will avoid code repetition.
> 
> Signed-off-by: Ye Xiang 

One trivial note inline about an accidental indentation change. If that's
all I find in the series I'll fix it up whilst applying.

Thanks,

Jonathan

...
>  /* Channel definitions */
>  static const struct iio_chan_spec magn_3d_channels[] = {
>   {
> @@ -448,32 +453,11 @@ static int magn_3d_parse_report(struct platform_device 
> *pdev,
>   &st->rot_attr.scale_pre_decml,
>   &st->rot_attr.scale_post_decml);
>  
> - /* Set Sensitivity field ids, when there is no individual modifier */
> - if (st->magn_flux_attributes.sensitivity.index < 0) {
> - sensor_hub_input_get_attribute_info(hsdev,
> - HID_FEATURE_REPORT, usage_id,
> - HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
> - HID_USAGE_SENSOR_DATA_ORIENTATION,
> - &st->magn_flux_attributes.sensitivity);
> - dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
> - st->magn_flux_attributes.sensitivity.index,
> - st->magn_flux_attributes.sensitivity.report_id);
> - }
> - if (st->magn_flux_attributes.sensitivity.index < 0) {
> - sensor_hub_input_get_attribute_info(hsdev,
> - HID_FEATURE_REPORT, usage_id,
> - HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
> - HID_USAGE_SENSOR_ORIENT_MAGN_FLUX,
> - &st->magn_flux_attributes.sensitivity);
> - dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
> - st->magn_flux_attributes.sensitivity.index,
> - st->magn_flux_attributes.sensitivity.report_id);
> - }
>   if (st->rot_attributes.sensitivity.index < 0) {
>   sensor_hub_input_get_attribute_info(hsdev,
>   HID_FEATURE_REPORT, usage_id,
>   HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
> - HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH,
> + HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH,

This change of alignment shouldn't be here.

>   &st->rot_attributes.sensitivity);
>   dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
>   st->rot_attributes.sensitivity.index,
> @@ -507,12 +491,16 @@ static int hid_magn_3d_probe(struct platform_device 
> *pdev)
>  
>   ret = hid_sensor_parse_common_attributes(hsdev,
>   HID_USAGE_SENSOR_COMPASS_3D,
> - &magn_state->magn_flux_attributes);
> + &magn_state->magn_flux_attributes,
> + magn_3d_sensitivity_addresses,
> + ARRAY_SIZE(magn_3d_sensitivity_addresses));
>   if (ret) {
>   dev_err(&pdev->dev, "failed to setup common attributes\n");
>   return ret;
>   }
>   magn_state->rot_attributes = magn_state->magn_flux_attributes;
> + /* sensitivity of rot_attribute is not the same as magn_flux_attributes 
> */
> + magn_state->rot_attributes.sensitivity.index = -1;
>  
>   ret = magn_3d_parse_report(pdev, hsdev,
>   &channels, &chan_count,


[PATCH 1/3] iio: hid-sensors: Move get sensitivity attribute to hid-sensor-common

2021-01-19 Thread Ye Xiang
No functional change has been made with this patch. The main intent here
is to reduce code repetition of get sensitivity attribute.

In the current implementation, sensor_hub_input_get_attribute_info() is
called from multiple drivers to get attribute info for sensitivity
field. Moving this to common place will avoid code repetition.

Signed-off-by: Ye Xiang 
---
 drivers/iio/accel/hid-sensor-accel-3d.c   | 23 +
 .../hid-sensors/hid-sensor-attributes.c   | 17 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c | 19 ---
 drivers/iio/humidity/hid-sensor-humidity.c| 16 -
 drivers/iio/light/hid-sensor-als.c| 19 ---
 drivers/iio/light/hid-sensor-prox.c   | 27 +--
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 34 ++-
 drivers/iio/orientation/hid-sensor-incl-3d.c  | 19 ---
 drivers/iio/orientation/hid-sensor-rotation.c | 23 +
 .../position/hid-sensor-custom-intel-hinge.c  | 20 ---
 drivers/iio/pressure/hid-sensor-press.c   | 19 ---
 .../iio/temperature/hid-sensor-temperature.c  | 16 -
 drivers/rtc/rtc-hid-sensor-time.c |  4 ++-
 include/linux/hid-sensor-hub.h|  4 ++-
 14 files changed, 108 insertions(+), 152 deletions(-)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c 
b/drivers/iio/accel/hid-sensor-accel-3d.c
index 5d63ed19e6e2..2f9465cb382f 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -43,6 +43,10 @@ static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = {
HID_USAGE_SENSOR_ACCEL_Z_AXIS
 };
 
+static const u32 accel_3d_sensitivity_addresses[] = {
+   HID_USAGE_SENSOR_DATA_ACCELERATION,
+};
+
 /* Channel definitions */
 static const struct iio_chan_spec accel_3d_channels[] = {
{
@@ -317,18 +321,6 @@ static int accel_3d_parse_report(struct platform_device 
*pdev,
&st->accel[CHANNEL_SCAN_INDEX_X],
&st->scale_pre_decml, &st->scale_post_decml);
 
-   /* Set Sensitivity field ids, when there is no individual modifier */
-   if (st->common_attributes.sensitivity.index < 0) {
-   sensor_hub_input_get_attribute_info(hsdev,
-   HID_FEATURE_REPORT, usage_id,
-   HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
-   HID_USAGE_SENSOR_DATA_ACCELERATION,
-   &st->common_attributes.sensitivity);
-   dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
-   st->common_attributes.sensitivity.index,
-   st->common_attributes.sensitivity.report_id);
-   }
-
return ret;
 }
 
@@ -366,8 +358,11 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
channel_size = sizeof(gravity_channels);
indio_dev->num_channels = ARRAY_SIZE(gravity_channels);
}
-   ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage,
-   &accel_state->common_attributes);
+   ret = hid_sensor_parse_common_attributes(hsdev,
+hsdev->usage,
+
&accel_state->common_attributes,
+accel_3d_sensitivity_addresses,
+
ARRAY_SIZE(accel_3d_sensitivity_addresses));
if (ret) {
dev_err(&pdev->dev, "failed to setup common attributes\n");
return ret;
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c 
b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 5b822a4298a0..d349ace2e33f 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -448,12 +448,15 @@ 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)
+   struct hid_sensor_common *st,
+   const u32 *sensitivity_addresses,
+   u32 sensitivity_addresses_len)
 {
 
struct hid_sensor_hub_attribute_info timestamp;
s32 value;
int ret;
+   int i;
 
hid_sensor_get_reporting_interval(hsdev, usage_id, st);
 
@@ -475,6 +478,18 @@ int hid_sensor_parse_common_attributes(struct 
hid_sensor_hub_device *hsdev,
HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS,
 &st->sensitivity);
 
+   /*
+* Set Sensitivity field ids, when there is no individual modifier, will
+* check absolute sensitivity of data field
+*/
+   for (i = 0; i < sens