Lines Matching refs:sensor_inst

152 	struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);  in enable_sensor_show()  local
154 return sprintf(buf, "%d\n", sensor_inst->enable); in enable_sensor_show()
157 static int set_power_report_state(struct hid_sensor_custom *sensor_inst, in set_power_report_state() argument
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()
231 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev); in enable_sensor_store() local
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()
244 ret = set_power_report_state(sensor_inst, true); 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()
251 ret = set_power_report_state(sensor_inst, false); 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()
276 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev); in show_value() local
287 field_index = index + sensor_inst->input_field_count; in show_value()
299 attribute = &sensor_inst->fields[field_index].attribute; in show_value()
307 ret = sensor_hub_get_feature(sensor_inst->hsdev, 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()
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()
384 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev); in store_value() local
391 field_index = index + sensor_inst->input_field_count; 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()
416 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(priv); in hid_sensor_capture_sample() local
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()
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()
457 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(priv); in hid_sensor_send_event() local
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()
470 static int hid_sensor_custom_add_field(struct hid_sensor_custom *sensor_inst, in hid_sensor_custom_add_field() argument
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()
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()
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()
518 sensor_inst->sensor_field_count++; in hid_sensor_custom_add_field()
523 static int hid_sensor_custom_add_fields(struct hid_sensor_custom *sensor_inst, in hid_sensor_custom_add_fields() argument
531 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev; in hid_sensor_custom_add_fields()
542 ret = hid_sensor_custom_add_field(sensor_inst, in hid_sensor_custom_add_fields()
558 *sensor_inst) in hid_sensor_custom_add_attributes()
560 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev; in hid_sensor_custom_add_attributes()
569 ret = hid_sensor_custom_add_fields(sensor_inst, 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()
587 sensor_inst->fields[i].group_name, in hid_sensor_custom_add_attributes()
591 (char *)&sensor_inst->fields[i].attr_name[j]; 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()
623 sensor_inst) in hid_sensor_custom_remove_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()
638 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_read() local
642 sensor_inst = container_of(file->private_data, in hid_sensor_custom_read()
649 if (kfifo_is_empty(&sensor_inst->data_fifo)) { 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()
670 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_release() local
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()
682 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_open() local
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()
696 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_poll() local
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()
718 static int hid_sensor_custom_dev_if_add(struct hid_sensor_custom *sensor_inst) in hid_sensor_custom_dev_if_add() argument
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()
741 *sensor_inst) in hid_sensor_custom_dev_if_remove()
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()
751 struct hid_sensor_custom *sensor_inst; in hid_sensor_custom_probe() local
755 sensor_inst = devm_kzalloc(&pdev->dev, sizeof(*sensor_inst), in hid_sensor_custom_probe()
757 if (!sensor_inst) 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()
766 platform_set_drvdata(pdev, sensor_inst); in hid_sensor_custom_probe()
768 &sensor_inst->callbacks); in hid_sensor_custom_probe()
774 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_probe()
779 ret = hid_sensor_custom_add_attributes(sensor_inst); in hid_sensor_custom_probe()
783 ret = hid_sensor_custom_dev_if_add(sensor_inst); in hid_sensor_custom_probe()
790 hid_sensor_custom_remove_attributes(sensor_inst); in hid_sensor_custom_probe()
792 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_probe()
802 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev); in hid_sensor_custom_remove() local
805 hid_sensor_custom_dev_if_remove(sensor_inst); in hid_sensor_custom_remove()
806 hid_sensor_custom_remove_attributes(sensor_inst); in hid_sensor_custom_remove()
807 sysfs_remove_group(&sensor_inst->pdev->dev.kobj, in hid_sensor_custom_remove()