Skip to content

Commit c8aca35

Browse files
pjungkampJiri Kosina
authored andcommitted
IIO: hid-sensor-prox: Use generic usage
Use a generic 'hsdev->usage' instead of the HID_USAGE_SENSOR_PROX to allow this driver to drive the Lenvo custom proximity sensor, which is registered under a 'custom' usage and not HID_USAGE_SENSOR_PROX. Add the Lenovo Intelligent Sensing Solution (LISS) human presence sensor to the platform device ids. Signed-off-by: Philipp Jungkamp <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Acked-by: Srinivas Pandruvada <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 3a04a18 commit c8aca35

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static int prox_read_raw(struct iio_dev *indio_dev,
6161
long mask)
6262
{
6363
struct prox_state *prox_state = iio_priv(indio_dev);
64+
struct hid_sensor_hub_device *hsdev;
6465
int report_id = -1;
6566
u32 address;
6667
int ret_type;
@@ -75,6 +76,7 @@ static int prox_read_raw(struct iio_dev *indio_dev,
7576
report_id = prox_state->prox_attr.report_id;
7677
min = prox_state->prox_attr.logical_minimum;
7778
address = HID_USAGE_SENSOR_HUMAN_PRESENCE;
79+
hsdev = prox_state->common_attributes.hsdev;
7880
break;
7981
default:
8082
report_id = -1;
@@ -84,11 +86,8 @@ static int prox_read_raw(struct iio_dev *indio_dev,
8486
hid_sensor_power_state(&prox_state->common_attributes,
8587
true);
8688
*val = sensor_hub_input_attr_get_raw_value(
87-
prox_state->common_attributes.hsdev,
88-
HID_USAGE_SENSOR_PROX, address,
89-
report_id,
90-
SENSOR_HUB_SYNC,
91-
min < 0);
89+
hsdev, hsdev->usage, address, report_id,
90+
SENSOR_HUB_SYNC, min < 0);
9291
hid_sensor_power_state(&prox_state->common_attributes,
9392
false);
9493
} else {
@@ -191,10 +190,16 @@ static int prox_capture_sample(struct hid_sensor_hub_device *hsdev,
191190

192191
switch (usage_id) {
193192
case HID_USAGE_SENSOR_HUMAN_PRESENCE:
194-
prox_state->human_presence = *(u32 *)raw_data;
195-
ret = 0;
196-
break;
197-
default:
193+
switch (raw_len) {
194+
case 1:
195+
prox_state->human_presence = *(u8 *)raw_data;
196+
return 0;
197+
case 4:
198+
prox_state->human_presence = *(u32 *)raw_data;
199+
return 0;
200+
default:
201+
break;
202+
}
198203
break;
199204
}
200205

@@ -244,7 +249,7 @@ static int hid_prox_probe(struct platform_device *pdev)
244249
prox_state->common_attributes.hsdev = hsdev;
245250
prox_state->common_attributes.pdev = pdev;
246251

247-
ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_PROX,
252+
ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage,
248253
&prox_state->common_attributes,
249254
prox_sensitivity_addresses,
250255
ARRAY_SIZE(prox_sensitivity_addresses));
@@ -262,7 +267,7 @@ static int hid_prox_probe(struct platform_device *pdev)
262267

263268
ret = prox_parse_report(pdev, hsdev,
264269
(struct iio_chan_spec *)indio_dev->channels,
265-
HID_USAGE_SENSOR_PROX, prox_state);
270+
hsdev->usage, prox_state);
266271
if (ret) {
267272
dev_err(&pdev->dev, "failed to setup attributes\n");
268273
return ret;
@@ -291,8 +296,8 @@ static int hid_prox_probe(struct platform_device *pdev)
291296
prox_state->callbacks.send_event = prox_proc_event;
292297
prox_state->callbacks.capture_sample = prox_capture_sample;
293298
prox_state->callbacks.pdev = pdev;
294-
ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_PROX,
295-
&prox_state->callbacks);
299+
ret = sensor_hub_register_callback(hsdev, hsdev->usage,
300+
&prox_state->callbacks);
296301
if (ret < 0) {
297302
dev_err(&pdev->dev, "callback reg failed\n");
298303
goto error_iio_unreg;
@@ -314,7 +319,7 @@ static int hid_prox_remove(struct platform_device *pdev)
314319
struct iio_dev *indio_dev = platform_get_drvdata(pdev);
315320
struct prox_state *prox_state = iio_priv(indio_dev);
316321

317-
sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_PROX);
322+
sensor_hub_remove_callback(hsdev, hsdev->usage);
318323
iio_device_unregister(indio_dev);
319324
hid_sensor_remove_trigger(indio_dev, &prox_state->common_attributes);
320325

@@ -326,6 +331,10 @@ static const struct platform_device_id hid_prox_ids[] = {
326331
/* Format: HID-SENSOR-usage_id_in_hex_lowercase */
327332
.name = "HID-SENSOR-200011",
328333
},
334+
{
335+
/* Format: HID-SENSOR-tag-usage_id_in_hex_lowercase */
336+
.name = "HID-SENSOR-LISS-0226",
337+
},
329338
{ /* sentinel */ }
330339
};
331340
MODULE_DEVICE_TABLE(platform, hid_prox_ids);

0 commit comments

Comments
 (0)