Lines Matching +full:bool +full:- +full:property

1 // SPDX-License-Identifier: GPL-2.0-only
3 * hid-sensor-custom.c
17 #include <linux/hid-sensor-hub.h>
45 bool input_skip_sample;
46 bool enable;
65 {.name = "unit-expo", .mode = S_IRUGO},
77 {0x200201, "event-sensor-state"},
78 {0x200202, "event-sensor-event"},
79 {0x200301, "property-friendly-name"},
80 {0x200302, "property-persistent-unique-id"},
81 {0x200303, "property-sensor-status"},
82 {0x200304, "property-min-report-interval"},
83 {0x200305, "property-sensor-manufacturer"},
84 {0x200306, "property-sensor-model"},
85 {0x200307, "property-sensor-serial-number"},
86 {0x200308, "property-sensor-description"},
87 {0x200309, "property-sensor-connection-type"},
88 {0x20030A, "property-sensor-device-path"},
89 {0x20030B, "property-hardware-revision"},
90 {0x20030C, "property-firmware-version"},
91 {0x20030D, "property-release-date"},
92 {0x20030E, "property-report-interval"},
93 {0x20030F, "property-change-sensitivity-absolute"},
94 {0x200310, "property-change-sensitivity-percent-range"},
95 {0x200311, "property-change-sensitivity-percent-relative"},
96 {0x200312, "property-accuracy"},
97 {0x200313, "property-resolution"},
98 {0x200314, "property-maximum"},
99 {0x200315, "property-minimum"},
100 {0x200316, "property-reporting-state"},
101 {0x200317, "property-sampling-rate"},
102 {0x200318, "property-response-curve"},
103 {0x200319, "property-power-state"},
104 {0x200540, "data-field-custom"},
105 {0x200541, "data-field-custom-usage"},
106 {0x200542, "data-field-custom-boolean-array"},
107 {0x200543, "data-field-custom-value"},
108 {0x200544, "data-field-custom-value_1"},
109 {0x200545, "data-field-custom-value_2"},
110 {0x200546, "data-field-custom-value_3"},
111 {0x200547, "data-field-custom-value_4"},
112 {0x200548, "data-field-custom-value_5"},
113 {0x200549, "data-field-custom-value_6"},
114 {0x20054A, "data-field-custom-value_7"},
115 {0x20054B, "data-field-custom-value_8"},
116 {0x20054C, "data-field-custom-value_9"},
117 {0x20054D, "data-field-custom-value_10"},
118 {0x20054E, "data-field-custom-value_11"},
119 {0x20054F, "data-field-custom-value_12"},
120 {0x200550, "data-field-custom-value_13"},
121 {0x200551, "data-field-custom-value_14"},
122 {0x200552, "data-field-custom-value_15"},
123 {0x200553, "data-field-custom-value_16"},
124 {0x200554, "data-field-custom-value_17"},
125 {0x200555, "data-field-custom-value_18"},
126 {0x200556, "data-field-custom-value_19"},
127 {0x200557, "data-field-custom-value_20"},
128 {0x200558, "data-field-custom-value_21"},
129 {0x200559, "data-field-custom-value_22"},
130 {0x20055A, "data-field-custom-value_23"},
131 {0x20055B, "data-field-custom-value_24"},
132 {0x20055C, "data-field-custom-value_25"},
133 {0x20055D, "data-field-custom-value_26"},
134 {0x20055E, "data-field-custom-value_27"},
135 {0x20055F, "data-field-custom-value_28"},
141 return -1; in usage_id_cmp()
154 return sprintf(buf, "%d\n", sensor_inst->enable); in enable_sensor_show()
158 bool state) in set_power_report_state()
160 int power_val = -1; in set_power_report_state()
161 int report_val = -1; in set_power_report_state()
183 if (sensor_inst->power_state) in set_power_report_state()
184 power_val = hid_sensor_get_usage_index(sensor_inst->hsdev, in set_power_report_state()
185 sensor_inst->power_state->attribute.report_id, in set_power_report_state()
186 sensor_inst->power_state->attribute.index, in set_power_report_state()
188 if (sensor_inst->report_state) in set_power_report_state()
189 report_val = hid_sensor_get_usage_index(sensor_inst->hsdev, in set_power_report_state()
190 sensor_inst->report_state->attribute.report_id, in set_power_report_state()
191 sensor_inst->report_state->attribute.index, in set_power_report_state()
196 sensor_inst->power_state->attribute.logical_minimum; in set_power_report_state()
197 ret = sensor_hub_set_feature(sensor_inst->hsdev, in set_power_report_state()
198 sensor_inst->power_state->attribute.report_id, in set_power_report_state()
199 sensor_inst->power_state->attribute.index, in set_power_report_state()
203 hid_err(sensor_inst->hsdev->hdev, in set_power_report_state()
211 sensor_inst->report_state->attribute.logical_minimum; in set_power_report_state()
212 ret = sensor_hub_set_feature(sensor_inst->hsdev, in set_power_report_state()
213 sensor_inst->report_state->attribute.report_id, in set_power_report_state()
214 sensor_inst->report_state->attribute.index, in set_power_report_state()
218 hid_err(sensor_inst->hsdev->hdev, in set_power_report_state()
233 int ret = -EINVAL; in enable_sensor_store()
236 return -EINVAL; in enable_sensor_store()
238 mutex_lock(&sensor_inst->mutex); in enable_sensor_store()
239 if (value && !sensor_inst->enable) { in enable_sensor_store()
240 ret = sensor_hub_device_open(sensor_inst->hsdev); in enable_sensor_store()
246 sensor_hub_device_close(sensor_inst->hsdev); in enable_sensor_store()
249 sensor_inst->enable = true; in enable_sensor_store()
250 } else if (!value && sensor_inst->enable) { in enable_sensor_store()
252 sensor_hub_device_close(sensor_inst->hsdev); in enable_sensor_store()
253 sensor_inst->enable = false; in enable_sensor_store()
256 mutex_unlock(&sensor_inst->mutex); in enable_sensor_store()
280 bool feature = false; in show_value()
281 bool input = false; in show_value()
284 if (sscanf(attr->attr.name, "feature-%x-%x-%s", &index, &usage, in show_value()
287 field_index = index + sensor_inst->input_field_count; in show_value()
288 } else if (sscanf(attr->attr.name, "input-%x-%x-%s", &index, &usage, in show_value()
293 return -EINVAL; in show_value()
299 attribute = &sensor_inst->fields[field_index].attribute; in show_value()
300 report_id = attribute->report_id; in show_value()
307 ret = sensor_hub_get_feature(sensor_inst->hsdev, in show_value()
315 if (i + attribute->size > ret) { in show_value()
317 PAGE_SIZE - len, in show_value()
321 switch (attribute->size) { in show_value()
324 i += attribute->size; in show_value()
328 i += attribute->size; in show_value()
332 i += attribute->size; in show_value()
339 len += scnprintf(&buf[len], PAGE_SIZE - len, in show_value()
342 len += scnprintf(&buf[len], PAGE_SIZE - len, "\n"); in show_value()
347 sensor_inst->hsdev, in show_value()
348 sensor_inst->hsdev->usage, in show_value()
352 value = sensor_inst->fields[field_index].attribute.units; in show_value()
353 else if (!strncmp(name, "unit-expo", strlen("unit-expo"))) in show_value()
354 value = sensor_inst->fields[field_index].attribute.unit_expo; in show_value()
356 value = sensor_inst->fields[field_index].attribute.size; in show_value()
358 value = sensor_inst->fields[field_index].attribute. in show_value()
361 value = sensor_inst->fields[field_index].attribute. in show_value()
372 usage_desc->desc); in show_value()
374 return sprintf(buf, "not-specified\n"); in show_value()
376 return -EINVAL; in show_value()
389 if (sscanf(attr->attr.name, "feature-%x-%x-%s", &index, &usage, in store_value()
391 field_index = index + sensor_inst->input_field_count; in store_value()
393 return -EINVAL; in store_value()
400 return -EINVAL; in store_value()
402 report_id = sensor_inst->fields[field_index].attribute. in store_value()
404 ret = sensor_hub_set_feature(sensor_inst->hsdev, report_id, in store_value()
407 return -EINVAL; in store_value()
420 if (sensor_inst->input_skip_sample) { in hid_sensor_capture_sample()
421 hid_err(sensor_inst->hsdev->hdev, "Skipped remaining data\n"); in hid_sensor_capture_sample()
425 hid_dbg(sensor_inst->hsdev->hdev, "%s received %d of %d\n", __func__, in hid_sensor_capture_sample()
426 (int) (sensor_inst->input_report_recd_size + raw_len), in hid_sensor_capture_sample()
427 sensor_inst->input_report_size); in hid_sensor_capture_sample()
429 if (!test_bit(0, &sensor_inst->misc_opened)) in hid_sensor_capture_sample()
432 if (!sensor_inst->input_report_recd_size) { in hid_sensor_capture_sample()
434 sensor_inst->input_report_size; in hid_sensor_capture_sample()
435 header.usage_id = hsdev->usage; in hid_sensor_capture_sample()
436 header.raw_len = sensor_inst->input_report_size; in hid_sensor_capture_sample()
438 if (kfifo_avail(&sensor_inst->data_fifo) >= required_size) { in hid_sensor_capture_sample()
439 kfifo_in(&sensor_inst->data_fifo, in hid_sensor_capture_sample()
443 sensor_inst->input_skip_sample = true; in hid_sensor_capture_sample()
445 if (kfifo_avail(&sensor_inst->data_fifo) >= raw_len) in hid_sensor_capture_sample()
446 kfifo_in(&sensor_inst->data_fifo, (unsigned char *)raw_data, in hid_sensor_capture_sample()
449 sensor_inst->input_report_recd_size += raw_len; in hid_sensor_capture_sample()
459 if (!test_bit(0, &sensor_inst->misc_opened)) in hid_sensor_send_event()
462 sensor_inst->input_report_recd_size = 0; in hid_sensor_send_event()
463 sensor_inst->input_skip_sample = false; in hid_sensor_send_event()
465 wake_up(&sensor_inst->wait); in hid_sensor_send_event()
478 fields = krealloc(sensor_inst->fields, in hid_sensor_custom_add_field()
479 (sensor_inst->sensor_field_count + 1) * in hid_sensor_custom_add_field()
482 kfree(sensor_inst->fields); in hid_sensor_custom_add_field()
483 return -ENOMEM; in hid_sensor_custom_add_field()
485 sensor_inst->fields = fields; in hid_sensor_custom_add_field()
486 sensor_field = &sensor_inst->fields[sensor_inst->sensor_field_count]; in hid_sensor_custom_add_field()
487 sensor_field->attribute.usage_id = sensor_inst->hsdev->usage; in hid_sensor_custom_add_field()
488 if (field->logical) in hid_sensor_custom_add_field()
489 sensor_field->attribute.attrib_id = field->logical; in hid_sensor_custom_add_field()
491 sensor_field->attribute.attrib_id = field->usage[0].hid; in hid_sensor_custom_add_field()
493 sensor_field->attribute.index = index; in hid_sensor_custom_add_field()
494 sensor_field->attribute.report_id = report->id; in hid_sensor_custom_add_field()
495 sensor_field->attribute.units = field->unit; in hid_sensor_custom_add_field()
496 sensor_field->attribute.unit_expo = field->unit_exponent; in hid_sensor_custom_add_field()
497 sensor_field->attribute.size = (field->report_size / 8); in hid_sensor_custom_add_field()
498 sensor_field->attribute.logical_minimum = field->logical_minimum; in hid_sensor_custom_add_field()
499 sensor_field->attribute.logical_maximum = field->logical_maximum; in hid_sensor_custom_add_field()
502 snprintf(sensor_field->group_name, in hid_sensor_custom_add_field()
503 sizeof(sensor_field->group_name), "feature-%x-%x", in hid_sensor_custom_add_field()
504 sensor_field->attribute.index, in hid_sensor_custom_add_field()
505 sensor_field->attribute.attrib_id); in hid_sensor_custom_add_field()
507 snprintf(sensor_field->group_name, in hid_sensor_custom_add_field()
508 sizeof(sensor_field->group_name), in hid_sensor_custom_add_field()
509 "input-%x-%x", sensor_field->attribute.index, in hid_sensor_custom_add_field()
510 sensor_field->attribute.attrib_id); in hid_sensor_custom_add_field()
511 sensor_inst->input_field_count++; in hid_sensor_custom_add_field()
512 sensor_inst->input_report_size += (field->report_size * in hid_sensor_custom_add_field()
513 field->report_count) / 8; in hid_sensor_custom_add_field()
516 memset(&sensor_field->hid_custom_attribute_group, 0, in hid_sensor_custom_add_field()
518 sensor_inst->sensor_field_count++; in hid_sensor_custom_add_field()
531 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev; in hid_sensor_custom_add_fields()
533 list_for_each_entry(report, &report_enum->report_list, list) { in hid_sensor_custom_add_fields()
534 for (i = 0; i < report->maxfield; ++i) { in hid_sensor_custom_add_fields()
535 field = report->field[i]; in hid_sensor_custom_add_fields()
536 if (field->maxusage && in hid_sensor_custom_add_fields()
537 ((field->usage[0].collection_index >= in hid_sensor_custom_add_fields()
538 hsdev->start_collection_index) && in hid_sensor_custom_add_fields()
539 (field->usage[0].collection_index < in hid_sensor_custom_add_fields()
540 hsdev->end_collection_index))) { in hid_sensor_custom_add_fields()
560 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev; in hid_sensor_custom_add_attributes()
561 struct hid_device *hdev = hsdev->hdev; in hid_sensor_custom_add_attributes()
562 int ret = -1; in hid_sensor_custom_add_attributes()
570 &hdev->report_enum[j], j); in hid_sensor_custom_add_attributes()
577 for (i = 0; i < sensor_inst->sensor_field_count; ++i) { in hid_sensor_custom_add_attributes()
583 device_attr = &sensor_inst->fields[i].sd_attrs[j]; in hid_sensor_custom_add_attributes()
585 snprintf((char *)&sensor_inst->fields[i].attr_name[j], in hid_sensor_custom_add_attributes()
586 HID_CUSTOM_NAME_LENGTH, "%s-%s", in hid_sensor_custom_add_attributes()
587 sensor_inst->fields[i].group_name, in hid_sensor_custom_add_attributes()
589 sysfs_attr_init(&device_attr->attr); in hid_sensor_custom_add_attributes()
590 device_attr->attr.name = in hid_sensor_custom_add_attributes()
591 (char *)&sensor_inst->fields[i].attr_name[j]; in hid_sensor_custom_add_attributes()
592 device_attr->attr.mode = hid_custom_attrs[j].mode; in hid_sensor_custom_add_attributes()
593 device_attr->show = show_value; in hid_sensor_custom_add_attributes()
595 device_attr->store = store_value; in hid_sensor_custom_add_attributes()
596 sensor_inst->fields[i].attrs[j] = &device_attr->attr; in hid_sensor_custom_add_attributes()
599 sensor_inst->fields[i].attrs[j] = NULL; in hid_sensor_custom_add_attributes()
600 sensor_inst->fields[i].hid_custom_attribute_group.attrs = in hid_sensor_custom_add_attributes()
601 sensor_inst->fields[i].attrs; in hid_sensor_custom_add_attributes()
602 sensor_inst->fields[i].hid_custom_attribute_group.name = in hid_sensor_custom_add_attributes()
603 sensor_inst->fields[i].group_name; in hid_sensor_custom_add_attributes()
604 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_add_attributes()
605 &sensor_inst->fields[i]. in hid_sensor_custom_add_attributes()
611 if (sensor_inst->fields[i].attribute.attrib_id == in hid_sensor_custom_add_attributes()
613 sensor_inst->power_state = &sensor_inst->fields[i]; in hid_sensor_custom_add_attributes()
614 else if (sensor_inst->fields[i].attribute.attrib_id == in hid_sensor_custom_add_attributes()
616 sensor_inst->report_state = &sensor_inst->fields[i]; in hid_sensor_custom_add_attributes()
627 for (i = 0; i < sensor_inst->sensor_field_count; ++i) in hid_sensor_custom_remove_attributes()
628 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_remove_attributes()
629 &sensor_inst->fields[i]. in hid_sensor_custom_remove_attributes()
632 kfree(sensor_inst->fields); in hid_sensor_custom_remove_attributes()
642 sensor_inst = container_of(file->private_data, in hid_sensor_custom_read()
646 return -EINVAL; in hid_sensor_custom_read()
649 if (kfifo_is_empty(&sensor_inst->data_fifo)) { in hid_sensor_custom_read()
650 if (file->f_flags & O_NONBLOCK) in hid_sensor_custom_read()
651 return -EAGAIN; in hid_sensor_custom_read()
653 ret = wait_event_interruptible(sensor_inst->wait, in hid_sensor_custom_read()
654 !kfifo_is_empty(&sensor_inst->data_fifo)); in hid_sensor_custom_read()
658 ret = kfifo_to_user(&sensor_inst->data_fifo, buf, count, in hid_sensor_custom_read()
672 sensor_inst = container_of(file->private_data, in hid_sensor_custom_release()
675 clear_bit(0, &sensor_inst->misc_opened); in hid_sensor_custom_release()
684 sensor_inst = container_of(file->private_data, in hid_sensor_custom_open()
687 if (test_and_set_bit(0, &sensor_inst->misc_opened)) in hid_sensor_custom_open()
688 return -EBUSY; in hid_sensor_custom_open()
699 sensor_inst = container_of(file->private_data, in hid_sensor_custom_poll()
702 poll_wait(file, &sensor_inst->wait, wait); in hid_sensor_custom_poll()
704 if (!kfifo_is_empty(&sensor_inst->data_fifo)) in hid_sensor_custom_poll()
722 ret = kfifo_alloc(&sensor_inst->data_fifo, HID_CUSTOM_FIFO_SIZE, in hid_sensor_custom_dev_if_add()
727 init_waitqueue_head(&sensor_inst->wait); in hid_sensor_custom_dev_if_add()
729 sensor_inst->custom_dev.minor = MISC_DYNAMIC_MINOR; in hid_sensor_custom_dev_if_add()
730 sensor_inst->custom_dev.name = dev_name(&sensor_inst->pdev->dev); in hid_sensor_custom_dev_if_add()
731 sensor_inst->custom_dev.fops = &hid_sensor_custom_fops, in hid_sensor_custom_dev_if_add()
732 ret = misc_register(&sensor_inst->custom_dev); in hid_sensor_custom_dev_if_add()
734 kfifo_free(&sensor_inst->data_fifo); in hid_sensor_custom_dev_if_add()
743 wake_up(&sensor_inst->wait); in hid_sensor_custom_dev_if_remove()
744 misc_deregister(&sensor_inst->custom_dev); in hid_sensor_custom_dev_if_remove()
745 kfifo_free(&sensor_inst->data_fifo); in hid_sensor_custom_dev_if_remove()
752 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; in hid_sensor_custom_probe()
755 sensor_inst = devm_kzalloc(&pdev->dev, sizeof(*sensor_inst), in hid_sensor_custom_probe()
758 return -ENOMEM; in hid_sensor_custom_probe()
760 sensor_inst->callbacks.capture_sample = hid_sensor_capture_sample; in hid_sensor_custom_probe()
761 sensor_inst->callbacks.send_event = hid_sensor_send_event; in hid_sensor_custom_probe()
762 sensor_inst->callbacks.pdev = pdev; in hid_sensor_custom_probe()
763 sensor_inst->hsdev = hsdev; in hid_sensor_custom_probe()
764 sensor_inst->pdev = pdev; in hid_sensor_custom_probe()
765 mutex_init(&sensor_inst->mutex); in hid_sensor_custom_probe()
767 ret = sensor_hub_register_callback(hsdev, hsdev->usage, in hid_sensor_custom_probe()
768 &sensor_inst->callbacks); in hid_sensor_custom_probe()
770 dev_err(&pdev->dev, "callback reg failed\n"); in hid_sensor_custom_probe()
774 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_probe()
792 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_probe()
795 sensor_hub_remove_callback(hsdev, hsdev->usage); in hid_sensor_custom_probe()
803 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; in hid_sensor_custom_remove()
807 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_remove()
809 sensor_hub_remove_callback(hsdev, hsdev->usage); in hid_sensor_custom_remove()
816 .name = "HID-SENSOR-2000e1",
819 .name = "HID-SENSOR-2000e2",