Skip to content

Commit 8b518cd

Browse files
lixuzhajic23
authored andcommitted
iio: hid-sensor-prox: support multi-channel SCALE calculation
With the introduction of multi-channel support in commit 596ef5c ("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: 596ef5c ("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>
1 parent 83ded7c commit 8b518cd

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

drivers/iio/common/hid-sensors/hid-sensor-attributes.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ static struct {
6666
{HID_USAGE_SENSOR_HUMIDITY, 0, 1000, 0},
6767
{HID_USAGE_SENSOR_HINGE, 0, 0, 17453293},
6868
{HID_USAGE_SENSOR_HINGE, HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},
69+
70+
{HID_USAGE_SENSOR_HUMAN_PRESENCE, 0, 1, 0},
71+
{HID_USAGE_SENSOR_HUMAN_PROXIMITY, 0, 1, 0},
72+
{HID_USAGE_SENSOR_HUMAN_ATTENTION, 0, 1, 0},
6973
};
7074

7175
static void simple_div(int dividend, int divisor, int *whole,

drivers/iio/light/hid-sensor-prox.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ struct prox_state {
3434
struct iio_chan_spec channels[MAX_CHANNELS];
3535
u32 channel2usage[MAX_CHANNELS];
3636
u32 human_presence[MAX_CHANNELS];
37-
int scale_pre_decml;
38-
int scale_post_decml;
39-
int scale_precision;
37+
int scale_pre_decml[MAX_CHANNELS];
38+
int scale_post_decml[MAX_CHANNELS];
39+
int scale_precision[MAX_CHANNELS];
4040
unsigned long scan_mask[2]; /* One entry plus one terminator. */
4141
int num_channels;
4242
};
@@ -116,9 +116,12 @@ static int prox_read_raw(struct iio_dev *indio_dev,
116116
ret_type = IIO_VAL_INT;
117117
break;
118118
case IIO_CHAN_INFO_SCALE:
119-
*val = prox_state->scale_pre_decml;
120-
*val2 = prox_state->scale_post_decml;
121-
ret_type = prox_state->scale_precision;
119+
if (chan->scan_index >= prox_state->num_channels)
120+
return -EINVAL;
121+
122+
*val = prox_state->scale_pre_decml[chan->scan_index];
123+
*val2 = prox_state->scale_post_decml[chan->scan_index];
124+
ret_type = prox_state->scale_precision[chan->scan_index];
122125
break;
123126
case IIO_CHAN_INFO_OFFSET:
124127
*val = hid_sensor_convert_exponent(
@@ -249,6 +252,10 @@ static int prox_parse_report(struct platform_device *pdev,
249252
st->prox_attr[index].size);
250253
dev_dbg(&pdev->dev, "prox %x:%x\n", st->prox_attr[index].index,
251254
st->prox_attr[index].report_id);
255+
st->scale_precision[index] =
256+
hid_sensor_format_scale(usage_id, &st->prox_attr[index],
257+
&st->scale_pre_decml[index],
258+
&st->scale_post_decml[index]);
252259
index++;
253260
}
254261

@@ -257,11 +264,6 @@ static int prox_parse_report(struct platform_device *pdev,
257264

258265
st->num_channels = index;
259266

260-
st->scale_precision = hid_sensor_format_scale(hsdev->usage,
261-
&st->prox_attr[0],
262-
&st->scale_pre_decml,
263-
&st->scale_post_decml);
264-
265267
return 0;
266268
}
267269

0 commit comments

Comments
 (0)