Lines Matching refs:sensor_inst

161 	struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);  in enable_sensor_show()  local
163 return sprintf(buf, "%d\n", sensor_inst->enable); in enable_sensor_show()
166 static int set_power_report_state(struct hid_sensor_custom *sensor_inst, in set_power_report_state() argument
192 if (sensor_inst->power_state) in set_power_report_state()
193 power_val = hid_sensor_get_usage_index(sensor_inst->hsdev, in set_power_report_state()
194 sensor_inst->power_state->attribute.report_id, in set_power_report_state()
195 sensor_inst->power_state->attribute.index, in set_power_report_state()
197 if (sensor_inst->report_state) in set_power_report_state()
198 report_val = hid_sensor_get_usage_index(sensor_inst->hsdev, in set_power_report_state()
199 sensor_inst->report_state->attribute.report_id, in set_power_report_state()
200 sensor_inst->report_state->attribute.index, in set_power_report_state()
205 sensor_inst->power_state->attribute.logical_minimum; in set_power_report_state()
206 ret = sensor_hub_set_feature(sensor_inst->hsdev, in set_power_report_state()
207 sensor_inst->power_state->attribute.report_id, in set_power_report_state()
208 sensor_inst->power_state->attribute.index, in set_power_report_state()
212 hid_err(sensor_inst->hsdev->hdev, in set_power_report_state()
220 sensor_inst->report_state->attribute.logical_minimum; in set_power_report_state()
221 ret = sensor_hub_set_feature(sensor_inst->hsdev, in set_power_report_state()
222 sensor_inst->report_state->attribute.report_id, in set_power_report_state()
223 sensor_inst->report_state->attribute.index, in set_power_report_state()
227 hid_err(sensor_inst->hsdev->hdev, in set_power_report_state()
241 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev); in enable_sensor_store() local
248 mutex_lock(&sensor_inst->mutex); in enable_sensor_store()
249 if (value && !sensor_inst->enable) { in enable_sensor_store()
250 ret = sensor_hub_device_open(sensor_inst->hsdev); in enable_sensor_store()
254 ret = set_power_report_state(sensor_inst, true); in enable_sensor_store()
256 sensor_hub_device_close(sensor_inst->hsdev); in enable_sensor_store()
259 sensor_inst->enable = true; in enable_sensor_store()
260 } else if (!value && sensor_inst->enable) { in enable_sensor_store()
261 ret = set_power_report_state(sensor_inst, false); in enable_sensor_store()
262 sensor_hub_device_close(sensor_inst->hsdev); in enable_sensor_store()
263 sensor_inst->enable = false; in enable_sensor_store()
266 mutex_unlock(&sensor_inst->mutex); in enable_sensor_store()
287 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev); in show_value() local
298 field_index = index + sensor_inst->input_field_count; in show_value()
310 attribute = &sensor_inst->fields[field_index].attribute; in show_value()
318 ret = sensor_hub_get_feature(sensor_inst->hsdev, in show_value()
358 sensor_inst->hsdev, in show_value()
359 sensor_inst->hsdev->usage, in show_value()
363 value = sensor_inst->fields[field_index].attribute.units; in show_value()
365 value = sensor_inst->fields[field_index].attribute.unit_expo; in show_value()
367 value = sensor_inst->fields[field_index].attribute.size; in show_value()
369 value = sensor_inst->fields[field_index].attribute. in show_value()
372 value = sensor_inst->fields[field_index].attribute. in show_value()
396 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev); in store_value() local
403 field_index = index + sensor_inst->input_field_count; in store_value()
414 report_id = sensor_inst->fields[field_index].attribute. in store_value()
416 ret = sensor_hub_set_feature(sensor_inst->hsdev, report_id, in store_value()
428 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(priv); in hid_sensor_capture_sample() local
432 if (sensor_inst->input_skip_sample) { in hid_sensor_capture_sample()
433 hid_err(sensor_inst->hsdev->hdev, "Skipped remaining data\n"); in hid_sensor_capture_sample()
437 hid_dbg(sensor_inst->hsdev->hdev, "%s received %d of %d\n", __func__, in hid_sensor_capture_sample()
438 (int) (sensor_inst->input_report_recd_size + raw_len), in hid_sensor_capture_sample()
439 sensor_inst->input_report_size); in hid_sensor_capture_sample()
441 if (!test_bit(0, &sensor_inst->misc_opened)) in hid_sensor_capture_sample()
444 if (!sensor_inst->input_report_recd_size) { in hid_sensor_capture_sample()
446 sensor_inst->input_report_size; in hid_sensor_capture_sample()
448 header.raw_len = sensor_inst->input_report_size; in hid_sensor_capture_sample()
450 if (kfifo_avail(&sensor_inst->data_fifo) >= required_size) { in hid_sensor_capture_sample()
451 kfifo_in(&sensor_inst->data_fifo, in hid_sensor_capture_sample()
455 sensor_inst->input_skip_sample = true; in hid_sensor_capture_sample()
457 if (kfifo_avail(&sensor_inst->data_fifo) >= raw_len) in hid_sensor_capture_sample()
458 kfifo_in(&sensor_inst->data_fifo, (unsigned char *)raw_data, in hid_sensor_capture_sample()
461 sensor_inst->input_report_recd_size += raw_len; in hid_sensor_capture_sample()
469 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(priv); in hid_sensor_send_event() local
471 if (!test_bit(0, &sensor_inst->misc_opened)) in hid_sensor_send_event()
474 sensor_inst->input_report_recd_size = 0; in hid_sensor_send_event()
475 sensor_inst->input_skip_sample = false; in hid_sensor_send_event()
477 wake_up(&sensor_inst->wait); in hid_sensor_send_event()
482 static int hid_sensor_custom_add_field(struct hid_sensor_custom *sensor_inst, in hid_sensor_custom_add_field() argument
490 fields = krealloc(sensor_inst->fields, in hid_sensor_custom_add_field()
491 (sensor_inst->sensor_field_count + 1) * in hid_sensor_custom_add_field()
494 kfree(sensor_inst->fields); in hid_sensor_custom_add_field()
497 sensor_inst->fields = fields; in hid_sensor_custom_add_field()
498 sensor_field = &sensor_inst->fields[sensor_inst->sensor_field_count]; in hid_sensor_custom_add_field()
499 sensor_field->attribute.usage_id = sensor_inst->hsdev->usage; in hid_sensor_custom_add_field()
523 sensor_inst->input_field_count++; in hid_sensor_custom_add_field()
524 sensor_inst->input_report_size += (field->report_size * in hid_sensor_custom_add_field()
530 sensor_inst->sensor_field_count++; in hid_sensor_custom_add_field()
535 static int hid_sensor_custom_add_fields(struct hid_sensor_custom *sensor_inst, in hid_sensor_custom_add_fields() argument
543 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev; in hid_sensor_custom_add_fields()
554 ret = hid_sensor_custom_add_field(sensor_inst, in hid_sensor_custom_add_fields()
570 *sensor_inst) in hid_sensor_custom_add_attributes()
572 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev; in hid_sensor_custom_add_attributes()
581 ret = hid_sensor_custom_add_fields(sensor_inst, in hid_sensor_custom_add_attributes()
589 for (i = 0; i < sensor_inst->sensor_field_count; ++i) { in hid_sensor_custom_add_attributes()
595 device_attr = &sensor_inst->fields[i].sd_attrs[j]; in hid_sensor_custom_add_attributes()
597 snprintf((char *)&sensor_inst->fields[i].attr_name[j], in hid_sensor_custom_add_attributes()
599 sensor_inst->fields[i].group_name, in hid_sensor_custom_add_attributes()
603 (char *)&sensor_inst->fields[i].attr_name[j]; in hid_sensor_custom_add_attributes()
608 sensor_inst->fields[i].attrs[j] = &device_attr->attr; in hid_sensor_custom_add_attributes()
611 sensor_inst->fields[i].attrs[j] = NULL; in hid_sensor_custom_add_attributes()
612 sensor_inst->fields[i].hid_custom_attribute_group.attrs = in hid_sensor_custom_add_attributes()
613 sensor_inst->fields[i].attrs; in hid_sensor_custom_add_attributes()
614 sensor_inst->fields[i].hid_custom_attribute_group.name = in hid_sensor_custom_add_attributes()
615 sensor_inst->fields[i].group_name; in hid_sensor_custom_add_attributes()
616 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_add_attributes()
617 &sensor_inst->fields[i]. in hid_sensor_custom_add_attributes()
623 if (sensor_inst->fields[i].attribute.attrib_id == in hid_sensor_custom_add_attributes()
625 sensor_inst->power_state = &sensor_inst->fields[i]; in hid_sensor_custom_add_attributes()
626 else if (sensor_inst->fields[i].attribute.attrib_id == in hid_sensor_custom_add_attributes()
628 sensor_inst->report_state = &sensor_inst->fields[i]; in hid_sensor_custom_add_attributes()
635 sensor_inst) in hid_sensor_custom_remove_attributes()
639 for (i = 0; i < sensor_inst->sensor_field_count; ++i) in hid_sensor_custom_remove_attributes()
640 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_remove_attributes()
641 &sensor_inst->fields[i]. in hid_sensor_custom_remove_attributes()
644 kfree(sensor_inst->fields); in hid_sensor_custom_remove_attributes()
650 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_read() local
654 sensor_inst = container_of(file->private_data, in hid_sensor_custom_read()
661 if (kfifo_is_empty(&sensor_inst->data_fifo)) { in hid_sensor_custom_read()
665 ret = wait_event_interruptible(sensor_inst->wait, in hid_sensor_custom_read()
666 !kfifo_is_empty(&sensor_inst->data_fifo)); in hid_sensor_custom_read()
670 ret = kfifo_to_user(&sensor_inst->data_fifo, buf, count, in hid_sensor_custom_read()
682 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_release() local
684 sensor_inst = container_of(file->private_data, in hid_sensor_custom_release()
687 clear_bit(0, &sensor_inst->misc_opened); in hid_sensor_custom_release()
694 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_open() local
696 sensor_inst = container_of(file->private_data, in hid_sensor_custom_open()
699 if (test_and_set_bit(0, &sensor_inst->misc_opened)) in hid_sensor_custom_open()
708 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_poll() local
711 sensor_inst = container_of(file->private_data, in hid_sensor_custom_poll()
714 poll_wait(file, &sensor_inst->wait, wait); in hid_sensor_custom_poll()
716 if (!kfifo_is_empty(&sensor_inst->data_fifo)) in hid_sensor_custom_poll()
730 static int hid_sensor_custom_dev_if_add(struct hid_sensor_custom *sensor_inst) in hid_sensor_custom_dev_if_add() argument
734 ret = kfifo_alloc(&sensor_inst->data_fifo, HID_CUSTOM_FIFO_SIZE, in hid_sensor_custom_dev_if_add()
739 init_waitqueue_head(&sensor_inst->wait); in hid_sensor_custom_dev_if_add()
741 sensor_inst->custom_dev.minor = MISC_DYNAMIC_MINOR; in hid_sensor_custom_dev_if_add()
742 sensor_inst->custom_dev.name = dev_name(&sensor_inst->pdev->dev); in hid_sensor_custom_dev_if_add()
743 sensor_inst->custom_dev.fops = &hid_sensor_custom_fops, in hid_sensor_custom_dev_if_add()
744 ret = misc_register(&sensor_inst->custom_dev); in hid_sensor_custom_dev_if_add()
746 kfifo_free(&sensor_inst->data_fifo); in hid_sensor_custom_dev_if_add()
753 *sensor_inst) in hid_sensor_custom_dev_if_remove()
755 wake_up(&sensor_inst->wait); in hid_sensor_custom_dev_if_remove()
756 misc_deregister(&sensor_inst->custom_dev); in hid_sensor_custom_dev_if_remove()
757 kfifo_free(&sensor_inst->data_fifo); in hid_sensor_custom_dev_if_remove()
763 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_probe() local
767 sensor_inst = devm_kzalloc(&pdev->dev, sizeof(*sensor_inst), in hid_sensor_custom_probe()
769 if (!sensor_inst) in hid_sensor_custom_probe()
772 sensor_inst->callbacks.capture_sample = hid_sensor_capture_sample; in hid_sensor_custom_probe()
773 sensor_inst->callbacks.send_event = hid_sensor_send_event; in hid_sensor_custom_probe()
774 sensor_inst->callbacks.pdev = pdev; in hid_sensor_custom_probe()
775 sensor_inst->hsdev = hsdev; in hid_sensor_custom_probe()
776 sensor_inst->pdev = pdev; in hid_sensor_custom_probe()
777 mutex_init(&sensor_inst->mutex); in hid_sensor_custom_probe()
778 platform_set_drvdata(pdev, sensor_inst); in hid_sensor_custom_probe()
780 &sensor_inst->callbacks); in hid_sensor_custom_probe()
786 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_probe()
791 ret = hid_sensor_custom_add_attributes(sensor_inst); in hid_sensor_custom_probe()
795 ret = hid_sensor_custom_dev_if_add(sensor_inst); in hid_sensor_custom_probe()
802 hid_sensor_custom_remove_attributes(sensor_inst); in hid_sensor_custom_probe()
804 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_probe()
814 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev); in hid_sensor_custom_remove() local
817 hid_sensor_custom_dev_if_remove(sensor_inst); in hid_sensor_custom_remove()
818 hid_sensor_custom_remove_attributes(sensor_inst); in hid_sensor_custom_remove()
819 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_remove()