19 #include <linux/device.h>
21 #include <linux/module.h>
24 #include <linux/slab.h>
31 #include "../common/hid-sensors/hid-sensor-attributes.h"
32 #include "../common/hid-sensors/hid-sensor-trigger.h"
36 #define DRIVER_NAME "HID-SENSOR-200041"
38 #define CHANNEL_SCAN_INDEX_ILLUM 0
73 static int als_read_raw(
struct iio_dev *indio_dev,
90 report_id = als_state->
als_illum.report_id;
114 *val = hid_sensor_convert_exponent(
137 static int als_write_raw(
struct iio_dev *indio_dev,
143 struct als_state *als_state = iio_priv(indio_dev);
162 static int als_write_raw_get_fmt(
struct iio_dev *indio_dev,
169 static const struct iio_info als_info = {
171 .read_raw = &als_read_raw,
172 .write_raw = &als_write_raw,
173 .write_raw_get_fmt = &als_write_raw_get_fmt,
177 static void hid_sensor_push_data(
struct iio_dev *indio_dev,
u8 *
data,
int len)
182 dev_dbg(&indio_dev->
dev,
"hid_sensor_push_data\n");
187 datum_sz = buffer->access->get_bytes_per_datum(buffer);
188 if (len > datum_sz) {
189 dev_err(&indio_dev->
dev,
"Datum size mismatch %d:%d\n", len,
201 struct iio_dev *indio_dev = platform_get_drvdata(priv);
202 struct als_state *als_state = iio_priv(indio_dev);
204 dev_dbg(&indio_dev->
dev,
"als_proc_event [%d]\n",
207 hid_sensor_push_data(indio_dev,
209 sizeof(als_state->
illum));
217 size_t raw_len,
char *raw_data,
220 struct iio_dev *indio_dev = platform_get_drvdata(priv);
221 struct als_state *als_state = iio_priv(indio_dev);
226 als_state->
illum = *(
u32 *)raw_data;
241 struct als_state *
st)
264 static const char *
name =
"als";
266 struct als_state *als_state;
271 if (indio_dev ==
NULL) {
275 platform_set_drvdata(pdev, indio_dev);
277 als_state = iio_priv(indio_dev);
284 dev_err(&pdev->
dev,
"failed to setup common attributes\n");
288 channels =
kmemdup(als_channels,
289 sizeof(als_channels),
292 dev_err(&pdev->
dev,
"failed to duplicate channels\n");
296 ret = als_parse_report(pdev, hsdev, channels,
299 dev_err(&pdev->
dev,
"failed to setup attributes\n");
300 goto error_free_dev_mem;
306 indio_dev->
dev.parent = &pdev->
dev;
307 indio_dev->
info = &als_info;
314 dev_err(&pdev->
dev,
"failed to initialize trigger buffer\n");
315 goto error_free_dev_mem;
321 dev_err(&pdev->
dev,
"trigger setup failed\n");
322 goto error_unreg_buffer_funcs;
327 dev_err(&pdev->
dev,
"device register failed\n");
328 goto error_remove_trigger;
331 als_state->
callbacks.send_event = als_proc_event;
332 als_state->
callbacks.capture_sample = als_capture_sample;
338 goto error_iio_unreg;
345 error_remove_trigger:
347 error_unreg_buffer_funcs:
361 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
378 .probe = hid_als_probe,
379 .remove = hid_als_remove,