3 * Copyright (c) 2015, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/miscdevice.h>
19 #include <linux/kfifo.h>
20 #include <linux/sched.h>
21 #include <linux/wait.h>
22 #include <linux/poll.h>
23 #include <linux/bsearch.h>
24 #include <linux/platform_device.h>
25 #include <linux/hid-sensor-hub.h>
27 #define HID_CUSTOM_NAME_LENGTH 64
28 #define HID_CUSTOM_MAX_CORE_ATTRS 10
29 #define HID_CUSTOM_TOTAL_ATTRS (HID_CUSTOM_MAX_CORE_ATTRS + 1)
30 #define HID_CUSTOM_FIFO_SIZE 4096
31 #define HID_CUSTOM_MAX_FEATURE_BYTES 64
33 struct hid_sensor_custom_field {
35 char group_name[HID_CUSTOM_NAME_LENGTH];
36 struct hid_sensor_hub_attribute_info attribute;
37 struct device_attribute sd_attrs[HID_CUSTOM_MAX_CORE_ATTRS];
38 char attr_name[HID_CUSTOM_TOTAL_ATTRS][HID_CUSTOM_NAME_LENGTH];
39 struct attribute *attrs[HID_CUSTOM_TOTAL_ATTRS];
40 struct attribute_group hid_custom_attribute_group;
43 struct hid_sensor_custom {
45 struct platform_device *pdev;
46 struct hid_sensor_hub_device *hsdev;
47 struct hid_sensor_hub_callbacks callbacks;
48 int sensor_field_count;
49 struct hid_sensor_custom_field *fields;
50 int input_field_count;
51 int input_report_size;
52 int input_report_recd_size;
53 bool input_skip_sample;
55 struct hid_sensor_custom_field *power_state;
56 struct hid_sensor_custom_field *report_state;
57 struct miscdevice custom_dev;
58 struct kfifo data_fifo;
59 unsigned long misc_opened;
60 wait_queue_head_t wait;
63 /* Header for each sample to user space via dev interface */
64 struct hid_sensor_sample {
70 static struct attribute hid_custom_attrs[] = {
71 {.name = "name", .mode = S_IRUGO},
72 {.name = "units", .mode = S_IRUGO},
73 {.name = "unit-expo", .mode = S_IRUGO},
74 {.name = "minimum", .mode = S_IRUGO},
75 {.name = "maximum", .mode = S_IRUGO},
76 {.name = "size", .mode = S_IRUGO},
77 {.name = "value", .mode = S_IWUSR | S_IRUGO},
81 static const struct hid_custom_usage_desc {
84 } hid_custom_usage_desc_table[] = {
85 {0x200201, "event-sensor-state"},
86 {0x200202, "event-sensor-event"},
87 {0x200301, "property-friendly-name"},
88 {0x200302, "property-persistent-unique-id"},
89 {0x200303, "property-sensor-status"},
90 {0x200304, "property-min-report-interval"},
91 {0x200305, "property-sensor-manufacturer"},
92 {0x200306, "property-sensor-model"},
93 {0x200307, "property-sensor-serial-number"},
94 {0x200308, "property-sensor-description"},
95 {0x200309, "property-sensor-connection-type"},
96 {0x20030A, "property-sensor-device-path"},
97 {0x20030B, "property-hardware-revision"},
98 {0x20030C, "property-firmware-version"},
99 {0x20030D, "property-release-date"},
100 {0x20030E, "property-report-interval"},
101 {0x20030F, "property-change-sensitivity-absolute"},
102 {0x200310, "property-change-sensitivity-percent-range"},
103 {0x200311, "property-change-sensitivity-percent-relative"},
104 {0x200312, "property-accuracy"},
105 {0x200313, "property-resolution"},
106 {0x200314, "property-maximum"},
107 {0x200315, "property-minimum"},
108 {0x200316, "property-reporting-state"},
109 {0x200317, "property-sampling-rate"},
110 {0x200318, "property-response-curve"},
111 {0x200319, "property-power-state"},
112 {0x200540, "data-field-custom"},
113 {0x200541, "data-field-custom-usage"},
114 {0x200542, "data-field-custom-boolean-array"},
115 {0x200543, "data-field-custom-value"},
116 {0x200544, "data-field-custom-value_1"},
117 {0x200545, "data-field-custom-value_2"},
118 {0x200546, "data-field-custom-value_3"},
119 {0x200547, "data-field-custom-value_4"},
120 {0x200548, "data-field-custom-value_5"},
121 {0x200549, "data-field-custom-value_6"},
122 {0x20054A, "data-field-custom-value_7"},
123 {0x20054B, "data-field-custom-value_8"},
124 {0x20054C, "data-field-custom-value_9"},
125 {0x20054D, "data-field-custom-value_10"},
126 {0x20054E, "data-field-custom-value_11"},
127 {0x20054F, "data-field-custom-value_12"},
128 {0x200550, "data-field-custom-value_13"},
129 {0x200551, "data-field-custom-value_14"},
130 {0x200552, "data-field-custom-value_15"},
131 {0x200553, "data-field-custom-value_16"},
132 {0x200554, "data-field-custom-value_17"},
133 {0x200555, "data-field-custom-value_18"},
134 {0x200556, "data-field-custom-value_19"},
135 {0x200557, "data-field-custom-value_20"},
136 {0x200558, "data-field-custom-value_21"},
137 {0x200559, "data-field-custom-value_22"},
138 {0x20055A, "data-field-custom-value_23"},
139 {0x20055B, "data-field-custom-value_24"},
140 {0x20055C, "data-field-custom-value_25"},
141 {0x20055D, "data-field-custom-value_26"},
142 {0x20055E, "data-field-custom-value_27"},
143 {0x20055F, "data-field-custom-value_28"},
146 static int usage_id_cmp(const void *p1, const void *p2)
148 if (*(int *)p1 < *(int *)p2)
151 if (*(int *)p1 > *(int *)p2)
157 static ssize_t enable_sensor_show(struct device *dev,
158 struct device_attribute *attr, char *buf)
160 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
162 return sprintf(buf, "%d\n", sensor_inst->enable);
165 static int set_power_report_state(struct hid_sensor_custom *sensor_inst,
170 u32 power_state_usage_id;
171 u32 report_state_usage_id;
175 * It is possible that the power/report state ids are not present.
176 * In this case this function will return success. But if the
177 * ids are present, then it will return error if set fails.
180 power_state_usage_id =
181 HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM;
182 report_state_usage_id =
183 HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM;
185 power_state_usage_id =
186 HID_USAGE_SENSOR_PROP_POWER_STATE_D4_POWER_OFF_ENUM;
187 report_state_usage_id =
188 HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM;
191 if (sensor_inst->power_state)
192 power_val = hid_sensor_get_usage_index(sensor_inst->hsdev,
193 sensor_inst->power_state->attribute.report_id,
194 sensor_inst->power_state->attribute.index,
195 power_state_usage_id);
196 if (sensor_inst->report_state)
197 report_val = hid_sensor_get_usage_index(sensor_inst->hsdev,
198 sensor_inst->report_state->attribute.report_id,
199 sensor_inst->report_state->attribute.index,
200 report_state_usage_id);
202 if (power_val >= 0) {
204 sensor_inst->power_state->attribute.logical_minimum;
205 ret = sensor_hub_set_feature(sensor_inst->hsdev,
206 sensor_inst->power_state->attribute.report_id,
207 sensor_inst->power_state->attribute.index,
211 hid_err(sensor_inst->hsdev->hdev,
212 "Set power state failed\n");
217 if (report_val >= 0) {
219 sensor_inst->report_state->attribute.logical_minimum;
220 ret = sensor_hub_set_feature(sensor_inst->hsdev,
221 sensor_inst->report_state->attribute.report_id,
222 sensor_inst->report_state->attribute.index,
226 hid_err(sensor_inst->hsdev->hdev,
227 "Set report state failed\n");
235 static ssize_t enable_sensor_store(struct device *dev,
236 struct device_attribute *attr,
237 const char *buf, size_t count)
239 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
243 if (kstrtoint(buf, 0, &value) != 0)
246 mutex_lock(&sensor_inst->mutex);
247 if (value && !sensor_inst->enable) {
248 ret = sensor_hub_device_open(sensor_inst->hsdev);
252 ret = set_power_report_state(sensor_inst, true);
254 sensor_hub_device_close(sensor_inst->hsdev);
257 sensor_inst->enable = true;
258 } else if (!value && sensor_inst->enable) {
259 ret = set_power_report_state(sensor_inst, false);
260 sensor_hub_device_close(sensor_inst->hsdev);
261 sensor_inst->enable = false;
264 mutex_unlock(&sensor_inst->mutex);
270 static DEVICE_ATTR_RW(enable_sensor);
272 static struct attribute *enable_sensor_attrs[] = {
273 &dev_attr_enable_sensor.attr,
277 static const struct attribute_group enable_sensor_attr_group = {
278 .attrs = enable_sensor_attrs,
281 static ssize_t show_value(struct device *dev, struct device_attribute *attr,
284 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
285 struct hid_sensor_hub_attribute_info *attribute;
286 int index, usage, field_index;
287 char name[HID_CUSTOM_NAME_LENGTH];
288 bool feature = false;
292 if (sscanf(attr->attr.name, "feature-%x-%x-%s", &index, &usage,
295 field_index = index + sensor_inst->input_field_count;
296 } else if (sscanf(attr->attr.name, "input-%x-%x-%s", &index, &usage,
303 if (!strncmp(name, "value", strlen("value"))) {
307 attribute = &sensor_inst->fields[field_index].attribute;
308 report_id = attribute->report_id;
310 u8 values[HID_CUSTOM_MAX_FEATURE_BYTES];
315 ret = sensor_hub_get_feature(sensor_inst->hsdev,
318 sizeof(values), values);
323 if (i + attribute->size > ret) {
324 len += snprintf(&buf[len],
329 switch (attribute->size) {
331 value = (u64) *(u16 *)&values[i];
332 i += attribute->size;
335 value = (u64) *(u32 *)&values[i];
336 i += attribute->size;
339 value = *(u64 *)&values[i];
340 i += attribute->size;
343 value = (u64) values[i];
347 len += snprintf(&buf[len], PAGE_SIZE - len,
350 len += snprintf(&buf[len], PAGE_SIZE - len, "\n");
354 value = sensor_hub_input_attr_get_raw_value(
356 sensor_inst->hsdev->usage,
358 SENSOR_HUB_SYNC, false);
359 } else if (!strncmp(name, "units", strlen("units")))
360 value = sensor_inst->fields[field_index].attribute.units;
361 else if (!strncmp(name, "unit-expo", strlen("unit-expo")))
362 value = sensor_inst->fields[field_index].attribute.unit_expo;
363 else if (!strncmp(name, "size", strlen("size")))
364 value = sensor_inst->fields[field_index].attribute.size;
365 else if (!strncmp(name, "minimum", strlen("minimum")))
366 value = sensor_inst->fields[field_index].attribute.
368 else if (!strncmp(name, "maximum", strlen("maximum")))
369 value = sensor_inst->fields[field_index].attribute.
371 else if (!strncmp(name, "name", strlen("name"))) {
372 struct hid_custom_usage_desc *usage_desc;
374 usage_desc = bsearch(&usage, hid_custom_usage_desc_table,
375 ARRAY_SIZE(hid_custom_usage_desc_table),
376 sizeof(struct hid_custom_usage_desc),
379 return snprintf(buf, PAGE_SIZE, "%s\n",
382 return sprintf(buf, "not-specified\n");
386 return sprintf(buf, "%d\n", value);
389 static ssize_t store_value(struct device *dev, struct device_attribute *attr,
390 const char *buf, size_t count)
392 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
393 int index, field_index, usage;
394 char name[HID_CUSTOM_NAME_LENGTH];
397 if (sscanf(attr->attr.name, "feature-%x-%x-%s", &index, &usage,
399 field_index = index + sensor_inst->input_field_count;
403 if (!strncmp(name, "value", strlen("value"))) {
407 if (kstrtoint(buf, 0, &value) != 0)
410 report_id = sensor_inst->fields[field_index].attribute.
412 ret = sensor_hub_set_feature(sensor_inst->hsdev, report_id,
413 index, sizeof(value), &value);
420 static int hid_sensor_capture_sample(struct hid_sensor_hub_device *hsdev,
421 unsigned usage_id, size_t raw_len,
422 char *raw_data, void *priv)
424 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(priv);
425 struct hid_sensor_sample header;
427 /* If any error occurs in a sample, rest of the fields are ignored */
428 if (sensor_inst->input_skip_sample) {
429 hid_err(sensor_inst->hsdev->hdev, "Skipped remaining data\n");
433 hid_dbg(sensor_inst->hsdev->hdev, "%s received %d of %d\n", __func__,
434 (int) (sensor_inst->input_report_recd_size + raw_len),
435 sensor_inst->input_report_size);
437 if (!test_bit(0, &sensor_inst->misc_opened))
440 if (!sensor_inst->input_report_recd_size) {
441 int required_size = sizeof(struct hid_sensor_sample) +
442 sensor_inst->input_report_size;
443 header.usage_id = hsdev->usage;
444 header.raw_len = sensor_inst->input_report_size;
445 header.timestamp = ktime_get_real_ns();
446 if (kfifo_avail(&sensor_inst->data_fifo) >= required_size) {
447 kfifo_in(&sensor_inst->data_fifo,
448 (unsigned char *)&header,
451 sensor_inst->input_skip_sample = true;
453 if (kfifo_avail(&sensor_inst->data_fifo) >= raw_len)
454 kfifo_in(&sensor_inst->data_fifo, (unsigned char *)raw_data,
457 sensor_inst->input_report_recd_size += raw_len;
462 static int hid_sensor_send_event(struct hid_sensor_hub_device *hsdev,
463 unsigned usage_id, void *priv)
465 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(priv);
467 if (!test_bit(0, &sensor_inst->misc_opened))
470 sensor_inst->input_report_recd_size = 0;
471 sensor_inst->input_skip_sample = false;
473 wake_up(&sensor_inst->wait);
478 static int hid_sensor_custom_add_field(struct hid_sensor_custom *sensor_inst,
479 int index, int report_type,
480 struct hid_report *report,
481 struct hid_field *field)
483 struct hid_sensor_custom_field *sensor_field;
486 fields = krealloc(sensor_inst->fields,
487 (sensor_inst->sensor_field_count + 1) *
488 sizeof(struct hid_sensor_custom_field), GFP_KERNEL);
490 kfree(sensor_inst->fields);
493 sensor_inst->fields = fields;
494 sensor_field = &sensor_inst->fields[sensor_inst->sensor_field_count];
495 sensor_field->attribute.usage_id = sensor_inst->hsdev->usage;
497 sensor_field->attribute.attrib_id = field->logical;
499 sensor_field->attribute.attrib_id = field->usage[0].hid;
501 sensor_field->attribute.index = index;
502 sensor_field->attribute.report_id = report->id;
503 sensor_field->attribute.units = field->unit;
504 sensor_field->attribute.unit_expo = field->unit_exponent;
505 sensor_field->attribute.size = (field->report_size / 8);
506 sensor_field->attribute.logical_minimum = field->logical_minimum;
507 sensor_field->attribute.logical_maximum = field->logical_maximum;
509 if (report_type == HID_FEATURE_REPORT)
510 snprintf(sensor_field->group_name,
511 sizeof(sensor_field->group_name), "feature-%x-%x",
512 sensor_field->attribute.index,
513 sensor_field->attribute.attrib_id);
514 else if (report_type == HID_INPUT_REPORT) {
515 snprintf(sensor_field->group_name,
516 sizeof(sensor_field->group_name),
517 "input-%x-%x", sensor_field->attribute.index,
518 sensor_field->attribute.attrib_id);
519 sensor_inst->input_field_count++;
520 sensor_inst->input_report_size += (field->report_size *
521 field->report_count) / 8;
524 memset(&sensor_field->hid_custom_attribute_group, 0,
525 sizeof(struct attribute_group));
526 sensor_inst->sensor_field_count++;
531 static int hid_sensor_custom_add_fields(struct hid_sensor_custom *sensor_inst,
532 struct hid_report_enum *report_enum,
537 struct hid_report *report;
538 struct hid_field *field;
539 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev;
541 list_for_each_entry(report, &report_enum->report_list, list) {
542 for (i = 0; i < report->maxfield; ++i) {
543 field = report->field[i];
544 if (field->maxusage &&
545 ((field->usage[0].collection_index >=
546 hsdev->start_collection_index) &&
547 (field->usage[0].collection_index <
548 hsdev->end_collection_index))) {
550 ret = hid_sensor_custom_add_field(sensor_inst,
565 static int hid_sensor_custom_add_attributes(struct hid_sensor_custom
568 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev;
569 struct hid_device *hdev = hsdev->hdev;
573 for (j = 0; j < HID_REPORT_TYPES; ++j) {
574 if (j == HID_OUTPUT_REPORT)
577 ret = hid_sensor_custom_add_fields(sensor_inst,
578 &hdev->report_enum[j], j);
584 /* Create sysfs attributes */
585 for (i = 0; i < sensor_inst->sensor_field_count; ++i) {
587 while (j < HID_CUSTOM_TOTAL_ATTRS &&
588 hid_custom_attrs[j].name) {
589 struct device_attribute *device_attr;
591 device_attr = &sensor_inst->fields[i].sd_attrs[j];
593 snprintf((char *)&sensor_inst->fields[i].attr_name[j],
594 HID_CUSTOM_NAME_LENGTH, "%s-%s",
595 sensor_inst->fields[i].group_name,
596 hid_custom_attrs[j].name);
597 sysfs_attr_init(&device_attr->attr);
598 device_attr->attr.name =
599 (char *)&sensor_inst->fields[i].attr_name[j];
600 device_attr->attr.mode = hid_custom_attrs[j].mode;
601 device_attr->show = show_value;
602 if (hid_custom_attrs[j].mode & S_IWUSR)
603 device_attr->store = store_value;
604 sensor_inst->fields[i].attrs[j] = &device_attr->attr;
607 sensor_inst->fields[i].attrs[j] = NULL;
608 sensor_inst->fields[i].hid_custom_attribute_group.attrs =
609 sensor_inst->fields[i].attrs;
610 sensor_inst->fields[i].hid_custom_attribute_group.name =
611 sensor_inst->fields[i].group_name;
612 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj,
613 &sensor_inst->fields[i].
614 hid_custom_attribute_group);
618 /* For power or report field store indexes */
619 if (sensor_inst->fields[i].attribute.attrib_id ==
620 HID_USAGE_SENSOR_PROY_POWER_STATE)
621 sensor_inst->power_state = &sensor_inst->fields[i];
622 else if (sensor_inst->fields[i].attribute.attrib_id ==
623 HID_USAGE_SENSOR_PROP_REPORT_STATE)
624 sensor_inst->report_state = &sensor_inst->fields[i];
630 static void hid_sensor_custom_remove_attributes(struct hid_sensor_custom *
635 for (i = 0; i < sensor_inst->sensor_field_count; ++i)
636 sysfs_remove_group(&sensor_inst->pdev->dev.kobj,
637 &sensor_inst->fields[i].
638 hid_custom_attribute_group);
640 kfree(sensor_inst->fields);
643 static ssize_t hid_sensor_custom_read(struct file *file, char __user *buf,
644 size_t count, loff_t *f_ps)
646 struct hid_sensor_custom *sensor_inst;
650 sensor_inst = container_of(file->private_data,
651 struct hid_sensor_custom, custom_dev);
653 if (count < sizeof(struct hid_sensor_sample))
657 if (kfifo_is_empty(&sensor_inst->data_fifo)) {
658 if (file->f_flags & O_NONBLOCK)
661 ret = wait_event_interruptible(sensor_inst->wait,
662 !kfifo_is_empty(&sensor_inst->data_fifo));
666 ret = kfifo_to_user(&sensor_inst->data_fifo, buf, count,
671 } while (copied == 0);
676 static int hid_sensor_custom_release(struct inode *inode, struct file *file)
678 struct hid_sensor_custom *sensor_inst;
680 sensor_inst = container_of(file->private_data,
681 struct hid_sensor_custom, custom_dev);
683 clear_bit(0, &sensor_inst->misc_opened);
688 static int hid_sensor_custom_open(struct inode *inode, struct file *file)
690 struct hid_sensor_custom *sensor_inst;
692 sensor_inst = container_of(file->private_data,
693 struct hid_sensor_custom, custom_dev);
694 /* We essentially have single reader and writer */
695 if (test_and_set_bit(0, &sensor_inst->misc_opened))
698 return nonseekable_open(inode, file);
701 static __poll_t hid_sensor_custom_poll(struct file *file,
702 struct poll_table_struct *wait)
704 struct hid_sensor_custom *sensor_inst;
707 sensor_inst = container_of(file->private_data,
708 struct hid_sensor_custom, custom_dev);
710 poll_wait(file, &sensor_inst->wait, wait);
712 if (!kfifo_is_empty(&sensor_inst->data_fifo))
713 mask = EPOLLIN | EPOLLRDNORM;
718 static const struct file_operations hid_sensor_custom_fops = {
719 .open = hid_sensor_custom_open,
720 .read = hid_sensor_custom_read,
721 .release = hid_sensor_custom_release,
722 .poll = hid_sensor_custom_poll,
723 .llseek = noop_llseek,
726 static int hid_sensor_custom_dev_if_add(struct hid_sensor_custom *sensor_inst)
730 ret = kfifo_alloc(&sensor_inst->data_fifo, HID_CUSTOM_FIFO_SIZE,
735 init_waitqueue_head(&sensor_inst->wait);
737 sensor_inst->custom_dev.minor = MISC_DYNAMIC_MINOR;
738 sensor_inst->custom_dev.name = dev_name(&sensor_inst->pdev->dev);
739 sensor_inst->custom_dev.fops = &hid_sensor_custom_fops,
740 ret = misc_register(&sensor_inst->custom_dev);
742 kfifo_free(&sensor_inst->data_fifo);
748 static void hid_sensor_custom_dev_if_remove(struct hid_sensor_custom
751 wake_up(&sensor_inst->wait);
752 misc_deregister(&sensor_inst->custom_dev);
753 kfifo_free(&sensor_inst->data_fifo);
757 static int hid_sensor_custom_probe(struct platform_device *pdev)
759 struct hid_sensor_custom *sensor_inst;
760 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
763 sensor_inst = devm_kzalloc(&pdev->dev, sizeof(*sensor_inst),
768 sensor_inst->callbacks.capture_sample = hid_sensor_capture_sample;
769 sensor_inst->callbacks.send_event = hid_sensor_send_event;
770 sensor_inst->callbacks.pdev = pdev;
771 sensor_inst->hsdev = hsdev;
772 sensor_inst->pdev = pdev;
773 mutex_init(&sensor_inst->mutex);
774 platform_set_drvdata(pdev, sensor_inst);
775 ret = sensor_hub_register_callback(hsdev, hsdev->usage,
776 &sensor_inst->callbacks);
778 dev_err(&pdev->dev, "callback reg failed\n");
782 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj,
783 &enable_sensor_attr_group);
785 goto err_remove_callback;
787 ret = hid_sensor_custom_add_attributes(sensor_inst);
789 goto err_remove_group;
791 ret = hid_sensor_custom_dev_if_add(sensor_inst);
793 goto err_remove_attributes;
797 err_remove_attributes:
798 hid_sensor_custom_remove_attributes(sensor_inst);
800 sysfs_remove_group(&sensor_inst->pdev->dev.kobj,
801 &enable_sensor_attr_group);
803 sensor_hub_remove_callback(hsdev, hsdev->usage);
808 static int hid_sensor_custom_remove(struct platform_device *pdev)
810 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
811 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
813 hid_sensor_custom_dev_if_remove(sensor_inst);
814 hid_sensor_custom_remove_attributes(sensor_inst);
815 sysfs_remove_group(&sensor_inst->pdev->dev.kobj,
816 &enable_sensor_attr_group);
817 sensor_hub_remove_callback(hsdev, hsdev->usage);
822 static const struct platform_device_id hid_sensor_custom_ids[] = {
824 .name = "HID-SENSOR-2000e1",
827 .name = "HID-SENSOR-2000e2",
831 MODULE_DEVICE_TABLE(platform, hid_sensor_custom_ids);
833 static struct platform_driver hid_sensor_custom_platform_driver = {
834 .id_table = hid_sensor_custom_ids,
836 .name = KBUILD_MODNAME,
838 .probe = hid_sensor_custom_probe,
839 .remove = hid_sensor_custom_remove,
841 module_platform_driver(hid_sensor_custom_platform_driver);
843 MODULE_DESCRIPTION("HID Sensor Custom and Generic sensor Driver");
844 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
845 MODULE_LICENSE("GPL");