Lines Matching refs:sensor_inst
155 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev); in enable_sensor_show() local
157 return sprintf(buf, "%d\n", sensor_inst->enable); in enable_sensor_show()
160 static int set_power_report_state(struct hid_sensor_custom *sensor_inst, in set_power_report_state() argument
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()
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()
234 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev); in enable_sensor_store() local
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()
247 ret = set_power_report_state(sensor_inst, true); 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()
254 ret = set_power_report_state(sensor_inst, false); 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()
279 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev); in show_value() local
290 field_index = index + sensor_inst->input_field_count; in show_value()
302 attribute = &sensor_inst->fields[field_index].attribute; in show_value()
310 ret = sensor_hub_get_feature(sensor_inst->hsdev, 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()
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()
387 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev); in store_value() local
394 field_index = index + sensor_inst->input_field_count; 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()
420 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(priv); in hid_sensor_capture_sample() local
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()
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()
461 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(priv); in hid_sensor_send_event() local
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()
474 static int hid_sensor_custom_add_field(struct hid_sensor_custom *sensor_inst, in hid_sensor_custom_add_field() argument
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()
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()
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()
522 sensor_inst->sensor_field_count++; in hid_sensor_custom_add_field()
527 static int hid_sensor_custom_add_fields(struct hid_sensor_custom *sensor_inst, in hid_sensor_custom_add_fields() argument
535 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev; in hid_sensor_custom_add_fields()
546 ret = hid_sensor_custom_add_field(sensor_inst, in hid_sensor_custom_add_fields()
562 *sensor_inst) in hid_sensor_custom_add_attributes()
564 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev; in hid_sensor_custom_add_attributes()
573 ret = hid_sensor_custom_add_fields(sensor_inst, 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()
591 sensor_inst->fields[i].group_name, in hid_sensor_custom_add_attributes()
595 (char *)&sensor_inst->fields[i].attr_name[j]; 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()
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()
627 sensor_inst) in hid_sensor_custom_remove_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()
642 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_read() local
646 sensor_inst = container_of(file->private_data, in hid_sensor_custom_read()
653 if (kfifo_is_empty(&sensor_inst->data_fifo)) { 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()
674 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_release() local
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()
686 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_open() local
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()
700 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_poll() local
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()
722 static int hid_sensor_custom_dev_if_add(struct hid_sensor_custom *sensor_inst) in hid_sensor_custom_dev_if_add() argument
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()
745 *sensor_inst) in hid_sensor_custom_dev_if_remove()
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()
873 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_probe() local
878 sensor_inst = devm_kzalloc(&pdev->dev, sizeof(*sensor_inst), in hid_sensor_custom_probe()
880 if (!sensor_inst) 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()
889 platform_set_drvdata(pdev, sensor_inst); 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()
907 &sensor_inst->callbacks); in hid_sensor_custom_probe()
913 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_probe()
918 ret = hid_sensor_custom_add_attributes(sensor_inst); in hid_sensor_custom_probe()
922 ret = hid_sensor_custom_dev_if_add(sensor_inst); in hid_sensor_custom_probe()
929 hid_sensor_custom_remove_attributes(sensor_inst); in hid_sensor_custom_probe()
931 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_probe()
941 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev); in hid_sensor_custom_remove() local
944 if (sensor_inst->custom_pdev) { in hid_sensor_custom_remove()
945 platform_device_unregister(sensor_inst->custom_pdev); in hid_sensor_custom_remove()
949 hid_sensor_custom_dev_if_remove(sensor_inst); in hid_sensor_custom_remove()
950 hid_sensor_custom_remove_attributes(sensor_inst); in hid_sensor_custom_remove()
951 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_remove()