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-200083"
102 static int magn_3d_read_raw(
struct iio_dev *indio_dev,
119 address = magn_3d_addresses[chan->
scan_index];
136 *val = hid_sensor_convert_exponent(
159 static int magn_3d_write_raw(
struct iio_dev *indio_dev,
184 static int magn_3d_write_raw_get_fmt(
struct iio_dev *indio_dev,
191 static const struct iio_info magn_3d_info = {
193 .read_raw = &magn_3d_read_raw,
194 .write_raw = &magn_3d_write_raw,
195 .write_raw_get_fmt = &magn_3d_write_raw_get_fmt,
199 static void hid_sensor_push_data(
struct iio_dev *indio_dev,
u8 *
data,
int len)
204 dev_dbg(&indio_dev->
dev,
"hid_sensor_push_data\n");
209 datum_sz = buffer->access->get_bytes_per_datum(buffer);
210 if (len > datum_sz) {
211 dev_err(&indio_dev->
dev,
"Datum size mismatch %d:%d\n", len,
223 struct iio_dev *indio_dev = platform_get_drvdata(priv);
226 dev_dbg(&indio_dev->
dev,
"magn_3d_proc_event [%d]\n",
229 hid_sensor_push_data(indio_dev,
239 size_t raw_len,
char *raw_data,
242 struct iio_dev *indio_dev = platform_get_drvdata(priv);
281 magn_3d_adjust_channel_bit_mask(channels,
285 dev_dbg(&pdev->
dev,
"magn_3d %x:%x, %x:%x, %x:%x\n",
287 st->
magn[0].report_id,
288 st->
magn[1].index, st->
magn[1].report_id,
289 st->
magn[2].index, st->
magn[2].report_id);
298 static char *
name =
"magn_3d";
305 if (indio_dev ==
NULL) {
309 platform_set_drvdata(pdev, indio_dev);
311 magn_state = iio_priv(indio_dev);
319 dev_err(&pdev->
dev,
"failed to setup common attributes\n");
323 channels =
kmemdup(magn_3d_channels,
324 sizeof(magn_3d_channels),
327 dev_err(&pdev->
dev,
"failed to duplicate channels\n");
331 ret = magn_3d_parse_report(pdev, hsdev, channels,
334 dev_err(&pdev->
dev,
"failed to setup attributes\n");
335 goto error_free_dev_mem;
340 indio_dev->
dev.parent = &pdev->
dev;
341 indio_dev->
info = &magn_3d_info;
348 dev_err(&pdev->
dev,
"failed to initialize trigger buffer\n");
349 goto error_free_dev_mem;
355 dev_err(&pdev->
dev,
"trigger setup failed\n");
356 goto error_unreg_buffer_funcs;
361 dev_err(&pdev->
dev,
"device register failed\n");
362 goto error_remove_trigger;
365 magn_state->
callbacks.send_event = magn_3d_proc_event;
366 magn_state->
callbacks.capture_sample = magn_3d_capture_sample;
372 goto error_iio_unreg;
379 error_remove_trigger:
381 error_unreg_buffer_funcs:
395 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
412 .probe = hid_magn_3d_probe,
413 .remove = hid_magn_3d_remove,