Lines Matching +full:sensor +full:- +full:hub

1 // SPDX-License-Identifier: GPL-2.0-only
10 #include <linux/hid-sensor-hub.h>
13 #include "../common/hid-sensors/hid-sensor-trigger.h"
40 /* dynamically sized array to hold sensor values */
42 /* array of pointers to sensor value */
153 int report_id = -1; in magn_3d_read_raw()
162 hid_sensor_power_state(&magn_state->magn_flux_attributes, true); in magn_3d_read_raw()
163 report_id = magn_state->magn[chan->address].report_id; in magn_3d_read_raw()
164 min = magn_state->magn[chan->address].logical_minimum; in magn_3d_read_raw()
165 address = magn_3d_addresses[chan->address]; in magn_3d_read_raw()
168 magn_state->magn_flux_attributes.hsdev, in magn_3d_read_raw()
176 &magn_state->magn_flux_attributes, in magn_3d_read_raw()
178 return -EINVAL; in magn_3d_read_raw()
180 hid_sensor_power_state(&magn_state->magn_flux_attributes, in magn_3d_read_raw()
185 switch (chan->type) { in magn_3d_read_raw()
187 *val = magn_state->magn_flux_attr.scale_pre_decml; in magn_3d_read_raw()
188 *val2 = magn_state->magn_flux_attr.scale_post_decml; in magn_3d_read_raw()
189 ret_type = magn_state->magn_flux_attr.scale_precision; in magn_3d_read_raw()
192 *val = magn_state->rot_attr.scale_pre_decml; in magn_3d_read_raw()
193 *val2 = magn_state->rot_attr.scale_post_decml; in magn_3d_read_raw()
194 ret_type = magn_state->rot_attr.scale_precision; in magn_3d_read_raw()
197 ret_type = -EINVAL; in magn_3d_read_raw()
201 switch (chan->type) { in magn_3d_read_raw()
203 *val = magn_state->magn_flux_attr.value_offset; in magn_3d_read_raw()
207 *val = magn_state->rot_attr.value_offset; in magn_3d_read_raw()
211 ret_type = -EINVAL; in magn_3d_read_raw()
216 &magn_state->magn_flux_attributes, val, val2); in magn_3d_read_raw()
219 switch (chan->type) { in magn_3d_read_raw()
222 &magn_state->magn_flux_attributes, val, val2); in magn_3d_read_raw()
226 &magn_state->rot_attributes, val, val2); in magn_3d_read_raw()
229 ret_type = -EINVAL; in magn_3d_read_raw()
233 ret_type = -EINVAL; in magn_3d_read_raw()
253 &magn_state->magn_flux_attributes, val, val2); in magn_3d_write_raw()
256 switch (chan->type) { in magn_3d_write_raw()
259 &magn_state->magn_flux_attributes, val, val2); in magn_3d_write_raw()
263 &magn_state->rot_attributes, val, val2); in magn_3d_write_raw()
266 ret = -EINVAL; in magn_3d_write_raw()
270 ret = -EINVAL; in magn_3d_write_raw()
289 dev_dbg(&indio_dev->dev, "magn_3d_proc_event\n"); in magn_3d_proc_event()
290 if (atomic_read(&magn_state->magn_flux_attributes.data_ready)) { in magn_3d_proc_event()
291 if (!magn_state->timestamp) in magn_3d_proc_event()
292 magn_state->timestamp = iio_get_time_ns(indio_dev); in magn_3d_proc_event()
295 magn_state->iio_vals, in magn_3d_proc_event()
296 magn_state->timestamp); in magn_3d_proc_event()
297 magn_state->timestamp = 0; in magn_3d_proc_event()
319 offset = (usage_id - HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_X_AXIS) in magn_3d_capture_sample()
326 offset = (usage_id - HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH) in magn_3d_capture_sample()
330 magn_state->timestamp = in magn_3d_capture_sample()
331 hid_sensor_convert_timestamp(&magn_state->magn_flux_attributes, in magn_3d_capture_sample()
335 return -EINVAL; in magn_3d_capture_sample()
338 iio_val = magn_state->magn_val_addr[offset]; in magn_3d_capture_sample()
343 ret = -EINVAL; in magn_3d_capture_sample()
365 /* Check if usage attribute exists in the sensor hub device */ in magn_3d_parse_report()
370 &(st->magn[i])); in magn_3d_parse_report()
376 dev_err(&pdev->dev, in magn_3d_parse_report()
378 return -EINVAL; in magn_3d_parse_report()
381 dev_dbg(&pdev->dev, "magn_3d Found %d usage attributes\n", in magn_3d_parse_report()
383 dev_dbg(&pdev->dev, "magn_3d X: %x:%x Y: %x:%x Z: %x:%x\n", in magn_3d_parse_report()
384 st->magn[0].index, in magn_3d_parse_report()
385 st->magn[0].report_id, in magn_3d_parse_report()
386 st->magn[1].index, st->magn[1].report_id, in magn_3d_parse_report()
387 st->magn[2].index, st->magn[2].report_id); in magn_3d_parse_report()
390 _channels = devm_kcalloc(&pdev->dev, attr_count, in magn_3d_parse_report()
394 dev_err(&pdev->dev, in magn_3d_parse_report()
396 return -ENOMEM; in magn_3d_parse_report()
400 st->iio_vals = devm_kcalloc(&pdev->dev, in magn_3d_parse_report()
403 if (!st->iio_vals) { in magn_3d_parse_report()
404 dev_err(&pdev->dev, in magn_3d_parse_report()
406 return -ENOMEM; in magn_3d_parse_report()
412 if (st->magn[i].index >= 0) { in magn_3d_parse_report()
420 st->magn_val_addr[i] = &st->iio_vals[*chan_count]; in magn_3d_parse_report()
423 st->magn[i].size); in magn_3d_parse_report()
430 dev_err(&pdev->dev, in magn_3d_parse_report()
432 return -EINVAL; in magn_3d_parse_report()
437 dev_dbg(&pdev->dev, "magn_3d Setup %d IIO channels\n", in magn_3d_parse_report()
440 st->magn_flux_attr.scale_precision = hid_sensor_format_scale( in magn_3d_parse_report()
442 &st->magn[CHANNEL_SCAN_INDEX_X], in magn_3d_parse_report()
443 &st->magn_flux_attr.scale_pre_decml, in magn_3d_parse_report()
444 &st->magn_flux_attr.scale_post_decml); in magn_3d_parse_report()
445 st->rot_attr.scale_precision in magn_3d_parse_report()
448 &st->magn[CHANNEL_SCAN_INDEX_NORTH_MAGN_TILT_COMP], in magn_3d_parse_report()
449 &st->rot_attr.scale_pre_decml, in magn_3d_parse_report()
450 &st->rot_attr.scale_post_decml); in magn_3d_parse_report()
452 if (st->rot_attributes.sensitivity.index < 0) { in magn_3d_parse_report()
457 &st->rot_attributes.sensitivity); in magn_3d_parse_report()
458 dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n", in magn_3d_parse_report()
459 st->rot_attributes.sensitivity.index, in magn_3d_parse_report()
460 st->rot_attributes.sensitivity.report_id); in magn_3d_parse_report()
473 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; in hid_magn_3d_probe()
477 indio_dev = devm_iio_device_alloc(&pdev->dev, in hid_magn_3d_probe()
480 return -ENOMEM; in hid_magn_3d_probe()
485 magn_state->magn_flux_attributes.hsdev = hsdev; in hid_magn_3d_probe()
486 magn_state->magn_flux_attributes.pdev = pdev; in hid_magn_3d_probe()
490 &magn_state->magn_flux_attributes, in hid_magn_3d_probe()
494 dev_err(&pdev->dev, "failed to setup common attributes\n"); in hid_magn_3d_probe()
497 magn_state->rot_attributes = magn_state->magn_flux_attributes; in hid_magn_3d_probe()
499 magn_state->rot_attributes.sensitivity.index = -1; in hid_magn_3d_probe()
505 dev_err(&pdev->dev, "failed to parse report\n"); in hid_magn_3d_probe()
509 indio_dev->channels = channels; in hid_magn_3d_probe()
510 indio_dev->num_channels = chan_count; in hid_magn_3d_probe()
511 indio_dev->info = &magn_3d_info; in hid_magn_3d_probe()
512 indio_dev->name = name; in hid_magn_3d_probe()
513 indio_dev->modes = INDIO_DIRECT_MODE; in hid_magn_3d_probe()
515 atomic_set(&magn_state->magn_flux_attributes.data_ready, 0); in hid_magn_3d_probe()
518 &magn_state->magn_flux_attributes); in hid_magn_3d_probe()
520 dev_err(&pdev->dev, "trigger setup failed\n"); in hid_magn_3d_probe()
526 dev_err(&pdev->dev, "device register failed\n"); in hid_magn_3d_probe()
530 magn_state->callbacks.send_event = magn_3d_proc_event; in hid_magn_3d_probe()
531 magn_state->callbacks.capture_sample = magn_3d_capture_sample; in hid_magn_3d_probe()
532 magn_state->callbacks.pdev = pdev; in hid_magn_3d_probe()
534 &magn_state->callbacks); in hid_magn_3d_probe()
536 dev_err(&pdev->dev, "callback reg failed\n"); in hid_magn_3d_probe()
545 hid_sensor_remove_trigger(indio_dev, &magn_state->magn_flux_attributes); in hid_magn_3d_probe()
552 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; in hid_magn_3d_remove()
558 hid_sensor_remove_trigger(indio_dev, &magn_state->magn_flux_attributes); in hid_magn_3d_remove()
563 /* Format: HID-SENSOR-usage_id_in_hex_lowercase */
564 .name = "HID-SENSOR-200083",
581 MODULE_DESCRIPTION("HID Sensor Magnetometer 3D");