]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: hid-sensor-prox: support multi-channel SCALE calculation
authorZhang Lixu <lixu.zhang@intel.com>
Mon, 31 Mar 2025 05:50:21 +0000 (13:50 +0800)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 7 Apr 2025 18:32:49 +0000 (19:32 +0100)
With the introduction of multi-channel support in commit 596ef5cf654b
("iio: hid-sensor-prox: Add support for more channels"), each channel
requires an independent SCALE calculation, but the existing code only
calculates SCALE for a single channel.

Addresses the problem by modifying the driver to perform independent
SCALE calculations for each channel.

Cc: stable@vger.kernel.org
Fixes: 596ef5cf654b ("iio: hid-sensor-prox: Add support for more channels")
Signed-off-by: Zhang Lixu <lixu.zhang@intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Link: https://patch.msgid.link/20250331055022.1149736-3-lixu.zhang@intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/common/hid-sensors/hid-sensor-attributes.c
drivers/iio/light/hid-sensor-prox.c

index ad1882f608c0a28a828fb65ffcabba9628fa2f63..2055a03cbeb187743e687c2ce3f8a339a2bd4cfc 100644 (file)
@@ -66,6 +66,10 @@ static struct {
        {HID_USAGE_SENSOR_HUMIDITY, 0, 1000, 0},
        {HID_USAGE_SENSOR_HINGE, 0, 0, 17453293},
        {HID_USAGE_SENSOR_HINGE, HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},
+
+       {HID_USAGE_SENSOR_HUMAN_PRESENCE, 0, 1, 0},
+       {HID_USAGE_SENSOR_HUMAN_PROXIMITY, 0, 1, 0},
+       {HID_USAGE_SENSOR_HUMAN_ATTENTION, 0, 1, 0},
 };
 
 static void simple_div(int dividend, int divisor, int *whole,
index 1dc6fb7cf614699f1ad6182303709890aa6d0d8b..941508e58286c939d2e28cbe8c1c01967123d468 100644 (file)
@@ -34,9 +34,9 @@ struct prox_state {
        struct iio_chan_spec channels[MAX_CHANNELS];
        u32 channel2usage[MAX_CHANNELS];
        u32 human_presence[MAX_CHANNELS];
-       int scale_pre_decml;
-       int scale_post_decml;
-       int scale_precision;
+       int scale_pre_decml[MAX_CHANNELS];
+       int scale_post_decml[MAX_CHANNELS];
+       int scale_precision[MAX_CHANNELS];
        unsigned long scan_mask[2]; /* One entry plus one terminator. */
        int num_channels;
 };
@@ -116,9 +116,12 @@ static int prox_read_raw(struct iio_dev *indio_dev,
                ret_type = IIO_VAL_INT;
                break;
        case IIO_CHAN_INFO_SCALE:
-               *val = prox_state->scale_pre_decml;
-               *val2 = prox_state->scale_post_decml;
-               ret_type = prox_state->scale_precision;
+               if (chan->scan_index >= prox_state->num_channels)
+                       return -EINVAL;
+
+               *val = prox_state->scale_pre_decml[chan->scan_index];
+               *val2 = prox_state->scale_post_decml[chan->scan_index];
+               ret_type = prox_state->scale_precision[chan->scan_index];
                break;
        case IIO_CHAN_INFO_OFFSET:
                *val = hid_sensor_convert_exponent(
@@ -249,6 +252,10 @@ static int prox_parse_report(struct platform_device *pdev,
                                             st->prox_attr[index].size);
                dev_dbg(&pdev->dev, "prox %x:%x\n", st->prox_attr[index].index,
                        st->prox_attr[index].report_id);
+               st->scale_precision[index] =
+                       hid_sensor_format_scale(usage_id, &st->prox_attr[index],
+                                               &st->scale_pre_decml[index],
+                                               &st->scale_post_decml[index]);
                index++;
        }
 
@@ -257,11 +264,6 @@ static int prox_parse_report(struct platform_device *pdev,
 
        st->num_channels = index;
 
-       st->scale_precision = hid_sensor_format_scale(hsdev->usage,
-                                                     &st->prox_attr[0],
-                                                     &st->scale_pre_decml,
-                                                     &st->scale_post_decml);
-
        return 0;
 }