Lines Matching +full:power +full:- +full:friendly
1 // SPDX-License-Identifier: GPL-2.0-only
3 * hid-sensor-custom.c
18 #include <linux/hid-sensor-hub.h>
68 {.name = "unit-expo", .mode = S_IRUGO},
80 {0x200201, "event-sensor-state"},
81 {0x200202, "event-sensor-event"},
82 {0x200301, "property-friendly-name"},
83 {0x200302, "property-persistent-unique-id"},
84 {0x200303, "property-sensor-status"},
85 {0x200304, "property-min-report-interval"},
86 {0x200305, "property-sensor-manufacturer"},
87 {0x200306, "property-sensor-model"},
88 {0x200307, "property-sensor-serial-number"},
89 {0x200308, "property-sensor-description"},
90 {0x200309, "property-sensor-connection-type"},
91 {0x20030A, "property-sensor-device-path"},
92 {0x20030B, "property-hardware-revision"},
93 {0x20030C, "property-firmware-version"},
94 {0x20030D, "property-release-date"},
95 {0x20030E, "property-report-interval"},
96 {0x20030F, "property-change-sensitivity-absolute"},
97 {0x200310, "property-change-sensitivity-percent-range"},
98 {0x200311, "property-change-sensitivity-percent-relative"},
99 {0x200312, "property-accuracy"},
100 {0x200313, "property-resolution"},
101 {0x200314, "property-maximum"},
102 {0x200315, "property-minimum"},
103 {0x200316, "property-reporting-state"},
104 {0x200317, "property-sampling-rate"},
105 {0x200318, "property-response-curve"},
106 {0x200319, "property-power-state"},
107 {0x200540, "data-field-custom"},
108 {0x200541, "data-field-custom-usage"},
109 {0x200542, "data-field-custom-boolean-array"},
110 {0x200543, "data-field-custom-value"},
111 {0x200544, "data-field-custom-value_1"},
112 {0x200545, "data-field-custom-value_2"},
113 {0x200546, "data-field-custom-value_3"},
114 {0x200547, "data-field-custom-value_4"},
115 {0x200548, "data-field-custom-value_5"},
116 {0x200549, "data-field-custom-value_6"},
117 {0x20054A, "data-field-custom-value_7"},
118 {0x20054B, "data-field-custom-value_8"},
119 {0x20054C, "data-field-custom-value_9"},
120 {0x20054D, "data-field-custom-value_10"},
121 {0x20054E, "data-field-custom-value_11"},
122 {0x20054F, "data-field-custom-value_12"},
123 {0x200550, "data-field-custom-value_13"},
124 {0x200551, "data-field-custom-value_14"},
125 {0x200552, "data-field-custom-value_15"},
126 {0x200553, "data-field-custom-value_16"},
127 {0x200554, "data-field-custom-value_17"},
128 {0x200555, "data-field-custom-value_18"},
129 {0x200556, "data-field-custom-value_19"},
130 {0x200557, "data-field-custom-value_20"},
131 {0x200558, "data-field-custom-value_21"},
132 {0x200559, "data-field-custom-value_22"},
133 {0x20055A, "data-field-custom-value_23"},
134 {0x20055B, "data-field-custom-value_24"},
135 {0x20055C, "data-field-custom-value_25"},
136 {0x20055D, "data-field-custom-value_26"},
137 {0x20055E, "data-field-custom-value_27"},
138 {0x20055F, "data-field-custom-value_28"},
144 return -1; in usage_id_cmp()
157 return sprintf(buf, "%d\n", sensor_inst->enable); in enable_sensor_show()
163 int power_val = -1; in set_power_report_state()
164 int report_val = -1; in set_power_report_state()
170 * It is possible that the power/report state ids are not present. in set_power_report_state()
186 if (sensor_inst->power_state) in set_power_report_state()
187 power_val = hid_sensor_get_usage_index(sensor_inst->hsdev, in set_power_report_state()
188 sensor_inst->power_state->attribute.report_id, in set_power_report_state()
189 sensor_inst->power_state->attribute.index, in set_power_report_state()
191 if (sensor_inst->report_state) in set_power_report_state()
192 report_val = hid_sensor_get_usage_index(sensor_inst->hsdev, in set_power_report_state()
193 sensor_inst->report_state->attribute.report_id, in set_power_report_state()
194 sensor_inst->report_state->attribute.index, in set_power_report_state()
199 sensor_inst->power_state->attribute.logical_minimum; in set_power_report_state()
200 ret = sensor_hub_set_feature(sensor_inst->hsdev, in set_power_report_state()
201 sensor_inst->power_state->attribute.report_id, in set_power_report_state()
202 sensor_inst->power_state->attribute.index, in set_power_report_state()
206 hid_err(sensor_inst->hsdev->hdev, in set_power_report_state()
207 "Set power state failed\n"); in set_power_report_state()
214 sensor_inst->report_state->attribute.logical_minimum; in set_power_report_state()
215 ret = sensor_hub_set_feature(sensor_inst->hsdev, in set_power_report_state()
216 sensor_inst->report_state->attribute.report_id, in set_power_report_state()
217 sensor_inst->report_state->attribute.index, in set_power_report_state()
221 hid_err(sensor_inst->hsdev->hdev, in set_power_report_state()
236 int ret = -EINVAL; in enable_sensor_store()
239 return -EINVAL; in enable_sensor_store()
241 mutex_lock(&sensor_inst->mutex); in enable_sensor_store()
242 if (value && !sensor_inst->enable) { in enable_sensor_store()
243 ret = sensor_hub_device_open(sensor_inst->hsdev); in enable_sensor_store()
249 sensor_hub_device_close(sensor_inst->hsdev); in enable_sensor_store()
252 sensor_inst->enable = true; in enable_sensor_store()
253 } else if (!value && sensor_inst->enable) { in enable_sensor_store()
255 sensor_hub_device_close(sensor_inst->hsdev); in enable_sensor_store()
256 sensor_inst->enable = false; in enable_sensor_store()
259 mutex_unlock(&sensor_inst->mutex); in enable_sensor_store()
287 if (sscanf(attr->attr.name, "feature-%x-%x-%s", &index, &usage, in show_value()
290 field_index = index + sensor_inst->input_field_count; in show_value()
291 } else if (sscanf(attr->attr.name, "input-%x-%x-%s", &index, &usage, in show_value()
296 return -EINVAL; in show_value()
302 attribute = &sensor_inst->fields[field_index].attribute; in show_value()
303 report_id = attribute->report_id; in show_value()
310 ret = sensor_hub_get_feature(sensor_inst->hsdev, in show_value()
318 if (i + attribute->size > ret) { in show_value()
320 PAGE_SIZE - len, in show_value()
324 switch (attribute->size) { in show_value()
327 i += attribute->size; in show_value()
331 i += attribute->size; in show_value()
335 i += attribute->size; in show_value()
342 len += scnprintf(&buf[len], PAGE_SIZE - len, in show_value()
345 len += scnprintf(&buf[len], PAGE_SIZE - len, "\n"); in show_value()
350 sensor_inst->hsdev, in show_value()
351 sensor_inst->hsdev->usage, in show_value()
355 value = sensor_inst->fields[field_index].attribute.units; in show_value()
356 else if (!strncmp(name, "unit-expo", strlen("unit-expo"))) in show_value()
357 value = sensor_inst->fields[field_index].attribute.unit_expo; in show_value()
359 value = sensor_inst->fields[field_index].attribute.size; in show_value()
361 value = sensor_inst->fields[field_index].attribute. in show_value()
364 value = sensor_inst->fields[field_index].attribute. in show_value()
375 usage_desc->desc); in show_value()
377 return sprintf(buf, "not-specified\n"); in show_value()
379 return -EINVAL; in show_value()
392 if (sscanf(attr->attr.name, "feature-%x-%x-%s", &index, &usage, in store_value()
394 field_index = index + sensor_inst->input_field_count; in store_value()
396 return -EINVAL; in store_value()
402 return -EINVAL; in store_value()
404 report_id = sensor_inst->fields[field_index].attribute. in store_value()
406 ret = sensor_hub_set_feature(sensor_inst->hsdev, report_id, in store_value()
411 return -EINVAL; in store_value()
424 if (sensor_inst->input_skip_sample) { in hid_sensor_capture_sample()
425 hid_err(sensor_inst->hsdev->hdev, "Skipped remaining data\n"); in hid_sensor_capture_sample()
429 hid_dbg(sensor_inst->hsdev->hdev, "%s received %d of %d\n", __func__, in hid_sensor_capture_sample()
430 (int) (sensor_inst->input_report_recd_size + raw_len), in hid_sensor_capture_sample()
431 sensor_inst->input_report_size); in hid_sensor_capture_sample()
433 if (!test_bit(0, &sensor_inst->misc_opened)) in hid_sensor_capture_sample()
436 if (!sensor_inst->input_report_recd_size) { in hid_sensor_capture_sample()
438 sensor_inst->input_report_size; in hid_sensor_capture_sample()
439 header.usage_id = hsdev->usage; in hid_sensor_capture_sample()
440 header.raw_len = sensor_inst->input_report_size; in hid_sensor_capture_sample()
442 if (kfifo_avail(&sensor_inst->data_fifo) >= required_size) { in hid_sensor_capture_sample()
443 kfifo_in(&sensor_inst->data_fifo, in hid_sensor_capture_sample()
447 sensor_inst->input_skip_sample = true; in hid_sensor_capture_sample()
449 if (kfifo_avail(&sensor_inst->data_fifo) >= raw_len) in hid_sensor_capture_sample()
450 kfifo_in(&sensor_inst->data_fifo, (unsigned char *)raw_data, in hid_sensor_capture_sample()
453 sensor_inst->input_report_recd_size += raw_len; in hid_sensor_capture_sample()
463 if (!test_bit(0, &sensor_inst->misc_opened)) in hid_sensor_send_event()
466 sensor_inst->input_report_recd_size = 0; in hid_sensor_send_event()
467 sensor_inst->input_skip_sample = false; in hid_sensor_send_event()
469 wake_up(&sensor_inst->wait); in hid_sensor_send_event()
482 fields = krealloc(sensor_inst->fields, in hid_sensor_custom_add_field()
483 (sensor_inst->sensor_field_count + 1) * in hid_sensor_custom_add_field()
486 kfree(sensor_inst->fields); in hid_sensor_custom_add_field()
487 return -ENOMEM; in hid_sensor_custom_add_field()
489 sensor_inst->fields = fields; in hid_sensor_custom_add_field()
490 sensor_field = &sensor_inst->fields[sensor_inst->sensor_field_count]; in hid_sensor_custom_add_field()
491 sensor_field->attribute.usage_id = sensor_inst->hsdev->usage; in hid_sensor_custom_add_field()
492 if (field->logical) in hid_sensor_custom_add_field()
493 sensor_field->attribute.attrib_id = field->logical; in hid_sensor_custom_add_field()
495 sensor_field->attribute.attrib_id = field->usage[0].hid; in hid_sensor_custom_add_field()
497 sensor_field->attribute.index = index; in hid_sensor_custom_add_field()
498 sensor_field->attribute.report_id = report->id; in hid_sensor_custom_add_field()
499 sensor_field->attribute.units = field->unit; in hid_sensor_custom_add_field()
500 sensor_field->attribute.unit_expo = field->unit_exponent; in hid_sensor_custom_add_field()
501 sensor_field->attribute.size = (field->report_size / 8); in hid_sensor_custom_add_field()
502 sensor_field->attribute.logical_minimum = field->logical_minimum; in hid_sensor_custom_add_field()
503 sensor_field->attribute.logical_maximum = field->logical_maximum; in hid_sensor_custom_add_field()
506 snprintf(sensor_field->group_name, in hid_sensor_custom_add_field()
507 sizeof(sensor_field->group_name), "feature-%x-%x", in hid_sensor_custom_add_field()
508 sensor_field->attribute.index, in hid_sensor_custom_add_field()
509 sensor_field->attribute.attrib_id); in hid_sensor_custom_add_field()
511 snprintf(sensor_field->group_name, in hid_sensor_custom_add_field()
512 sizeof(sensor_field->group_name), in hid_sensor_custom_add_field()
513 "input-%x-%x", sensor_field->attribute.index, in hid_sensor_custom_add_field()
514 sensor_field->attribute.attrib_id); in hid_sensor_custom_add_field()
515 sensor_inst->input_field_count++; in hid_sensor_custom_add_field()
516 sensor_inst->input_report_size += (field->report_size * in hid_sensor_custom_add_field()
517 field->report_count) / 8; in hid_sensor_custom_add_field()
520 memset(&sensor_field->hid_custom_attribute_group, 0, in hid_sensor_custom_add_field()
522 sensor_inst->sensor_field_count++; in hid_sensor_custom_add_field()
535 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev; in hid_sensor_custom_add_fields()
537 list_for_each_entry(report, &report_enum->report_list, list) { in hid_sensor_custom_add_fields()
538 for (i = 0; i < report->maxfield; ++i) { in hid_sensor_custom_add_fields()
539 field = report->field[i]; in hid_sensor_custom_add_fields()
540 if (field->maxusage && in hid_sensor_custom_add_fields()
541 ((field->usage[0].collection_index >= in hid_sensor_custom_add_fields()
542 hsdev->start_collection_index) && in hid_sensor_custom_add_fields()
543 (field->usage[0].collection_index < in hid_sensor_custom_add_fields()
544 hsdev->end_collection_index))) { in hid_sensor_custom_add_fields()
564 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev; in hid_sensor_custom_add_attributes()
565 struct hid_device *hdev = hsdev->hdev; in hid_sensor_custom_add_attributes()
566 int ret = -1; in hid_sensor_custom_add_attributes()
574 &hdev->report_enum[j], j); in hid_sensor_custom_add_attributes()
581 for (i = 0; i < sensor_inst->sensor_field_count; ++i) { in hid_sensor_custom_add_attributes()
587 device_attr = &sensor_inst->fields[i].sd_attrs[j]; in hid_sensor_custom_add_attributes()
589 snprintf((char *)&sensor_inst->fields[i].attr_name[j], in hid_sensor_custom_add_attributes()
590 HID_CUSTOM_NAME_LENGTH, "%s-%s", in hid_sensor_custom_add_attributes()
591 sensor_inst->fields[i].group_name, in hid_sensor_custom_add_attributes()
593 sysfs_attr_init(&device_attr->attr); in hid_sensor_custom_add_attributes()
594 device_attr->attr.name = in hid_sensor_custom_add_attributes()
595 (char *)&sensor_inst->fields[i].attr_name[j]; in hid_sensor_custom_add_attributes()
596 device_attr->attr.mode = hid_custom_attrs[j].mode; in hid_sensor_custom_add_attributes()
597 device_attr->show = show_value; in hid_sensor_custom_add_attributes()
599 device_attr->store = store_value; in hid_sensor_custom_add_attributes()
600 sensor_inst->fields[i].attrs[j] = &device_attr->attr; in hid_sensor_custom_add_attributes()
603 sensor_inst->fields[i].attrs[j] = NULL; in hid_sensor_custom_add_attributes()
604 sensor_inst->fields[i].hid_custom_attribute_group.attrs = in hid_sensor_custom_add_attributes()
605 sensor_inst->fields[i].attrs; in hid_sensor_custom_add_attributes()
606 sensor_inst->fields[i].hid_custom_attribute_group.name = in hid_sensor_custom_add_attributes()
607 sensor_inst->fields[i].group_name; in hid_sensor_custom_add_attributes()
608 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_add_attributes()
609 &sensor_inst->fields[i]. in hid_sensor_custom_add_attributes()
614 /* For power or report field store indexes */ in hid_sensor_custom_add_attributes()
615 if (sensor_inst->fields[i].attribute.attrib_id == in hid_sensor_custom_add_attributes()
617 sensor_inst->power_state = &sensor_inst->fields[i]; in hid_sensor_custom_add_attributes()
618 else if (sensor_inst->fields[i].attribute.attrib_id == in hid_sensor_custom_add_attributes()
620 sensor_inst->report_state = &sensor_inst->fields[i]; in hid_sensor_custom_add_attributes()
631 for (i = 0; i < sensor_inst->sensor_field_count; ++i) in hid_sensor_custom_remove_attributes()
632 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_remove_attributes()
633 &sensor_inst->fields[i]. in hid_sensor_custom_remove_attributes()
636 kfree(sensor_inst->fields); in hid_sensor_custom_remove_attributes()
646 sensor_inst = container_of(file->private_data, in hid_sensor_custom_read()
650 return -EINVAL; in hid_sensor_custom_read()
653 if (kfifo_is_empty(&sensor_inst->data_fifo)) { in hid_sensor_custom_read()
654 if (file->f_flags & O_NONBLOCK) in hid_sensor_custom_read()
655 return -EAGAIN; in hid_sensor_custom_read()
657 ret = wait_event_interruptible(sensor_inst->wait, in hid_sensor_custom_read()
658 !kfifo_is_empty(&sensor_inst->data_fifo)); in hid_sensor_custom_read()
662 ret = kfifo_to_user(&sensor_inst->data_fifo, buf, count, in hid_sensor_custom_read()
676 sensor_inst = container_of(file->private_data, in hid_sensor_custom_release()
679 clear_bit(0, &sensor_inst->misc_opened); in hid_sensor_custom_release()
688 sensor_inst = container_of(file->private_data, in hid_sensor_custom_open()
691 if (test_and_set_bit(0, &sensor_inst->misc_opened)) in hid_sensor_custom_open()
692 return -EBUSY; in hid_sensor_custom_open()
703 sensor_inst = container_of(file->private_data, in hid_sensor_custom_poll()
706 poll_wait(file, &sensor_inst->wait, wait); in hid_sensor_custom_poll()
708 if (!kfifo_is_empty(&sensor_inst->data_fifo)) in hid_sensor_custom_poll()
726 ret = kfifo_alloc(&sensor_inst->data_fifo, HID_CUSTOM_FIFO_SIZE, in hid_sensor_custom_dev_if_add()
731 init_waitqueue_head(&sensor_inst->wait); in hid_sensor_custom_dev_if_add()
733 sensor_inst->custom_dev.minor = MISC_DYNAMIC_MINOR; in hid_sensor_custom_dev_if_add()
734 sensor_inst->custom_dev.name = dev_name(&sensor_inst->pdev->dev); in hid_sensor_custom_dev_if_add()
735 sensor_inst->custom_dev.fops = &hid_sensor_custom_fops, in hid_sensor_custom_dev_if_add()
736 ret = misc_register(&sensor_inst->custom_dev); in hid_sensor_custom_dev_if_add()
738 kfifo_free(&sensor_inst->data_fifo); in hid_sensor_custom_dev_if_add()
747 wake_up(&sensor_inst->wait); in hid_sensor_custom_dev_if_remove()
748 misc_deregister(&sensor_inst->custom_dev); in hid_sensor_custom_dev_if_remove()
749 kfifo_free(&sensor_inst->data_fifo); in hid_sensor_custom_dev_if_remove()
766 return -ENODEV; in get_luid_table_index()
784 HID_FEATURE_REPORT, hsdev->usage, in get_known_custom_sensor_index()
794 hid_err(hsdev->hdev, in get_known_custom_sensor_index()
797 return -ENODEV; in get_known_custom_sensor_index()
801 for (i = 0; i < ARRAY_SIZE(buf) - 1 && w_buf[i]; i++) in get_known_custom_sensor_index()
806 return -ENODEV; in get_known_custom_sensor_index()
813 HID_FEATURE_REPORT, hsdev->usage, in get_known_custom_sensor_index()
822 hid_err(hsdev->hdev, "Failed to get real usage info %d\n", in get_known_custom_sensor_index()
824 return -ENODEV; in get_known_custom_sensor_index()
828 for (i = 0; i < ARRAY_SIZE(buf) - 1 && w_buf[i]; i++) in get_known_custom_sensor_index()
832 hid_err(hsdev->hdev, in get_known_custom_sensor_index()
835 return -ENODEV; in get_known_custom_sensor_index()
859 /* HID-SENSOR-INT-REAL_USAGE_ID */ in hid_sensor_register_platform_device()
860 dev_name = kasprintf(GFP_KERNEL, "HID-SENSOR-INT-%s", real_usage); in hid_sensor_register_platform_device()
862 return ERR_PTR(-ENOMEM); in hid_sensor_register_platform_device()
864 custom_pdev = platform_device_register_data(pdev->dev.parent, dev_name, in hid_sensor_register_platform_device()
874 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; in hid_sensor_custom_probe()
878 sensor_inst = devm_kzalloc(&pdev->dev, sizeof(*sensor_inst), in hid_sensor_custom_probe()
881 return -ENOMEM; in hid_sensor_custom_probe()
883 sensor_inst->callbacks.capture_sample = hid_sensor_capture_sample; in hid_sensor_custom_probe()
884 sensor_inst->callbacks.send_event = hid_sensor_send_event; in hid_sensor_custom_probe()
885 sensor_inst->callbacks.pdev = pdev; in hid_sensor_custom_probe()
886 sensor_inst->hsdev = hsdev; in hid_sensor_custom_probe()
887 sensor_inst->pdev = pdev; in hid_sensor_custom_probe()
888 mutex_init(&sensor_inst->mutex); in hid_sensor_custom_probe()
893 sensor_inst->custom_pdev = in hid_sensor_custom_probe()
896 ret = PTR_ERR_OR_ZERO(sensor_inst->custom_pdev); in hid_sensor_custom_probe()
898 dev_err(&pdev->dev, in hid_sensor_custom_probe()
906 ret = sensor_hub_register_callback(hsdev, hsdev->usage, in hid_sensor_custom_probe()
907 &sensor_inst->callbacks); in hid_sensor_custom_probe()
909 dev_err(&pdev->dev, "callback reg failed\n"); in hid_sensor_custom_probe()
913 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_probe()
931 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_probe()
934 sensor_hub_remove_callback(hsdev, hsdev->usage); in hid_sensor_custom_probe()
942 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; in hid_sensor_custom_remove()
944 if (sensor_inst->custom_pdev) { in hid_sensor_custom_remove()
945 platform_device_unregister(sensor_inst->custom_pdev); in hid_sensor_custom_remove()
951 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_remove()
953 sensor_hub_remove_callback(hsdev, hsdev->usage); in hid_sensor_custom_remove()
960 .name = "HID-SENSOR-2000e1",
963 .name = "HID-SENSOR-2000e2",