xref: /linux/drivers/hid/hid-sensor-hub.c (revision 2b7c4b8e3edfd109a8423ff593a12a5fe09615b2)
1401ca24fSsrinivas pandruvada /*
2401ca24fSsrinivas pandruvada  * HID Sensors Driver
3401ca24fSsrinivas pandruvada  * Copyright (c) 2012, Intel Corporation.
4401ca24fSsrinivas pandruvada  *
5401ca24fSsrinivas pandruvada  * This program is free software; you can redistribute it and/or modify it
6401ca24fSsrinivas pandruvada  * under the terms and conditions of the GNU General Public License,
7401ca24fSsrinivas pandruvada  * version 2, as published by the Free Software Foundation.
8401ca24fSsrinivas pandruvada  *
9401ca24fSsrinivas pandruvada  * This program is distributed in the hope it will be useful, but WITHOUT
10401ca24fSsrinivas pandruvada  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11401ca24fSsrinivas pandruvada  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12401ca24fSsrinivas pandruvada  * more details.
13401ca24fSsrinivas pandruvada  *
14401ca24fSsrinivas pandruvada  * You should have received a copy of the GNU General Public License along with
15401ca24fSsrinivas pandruvada  * this program; if not, write to the Free Software Foundation, Inc.,
16401ca24fSsrinivas pandruvada  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17401ca24fSsrinivas pandruvada  *
18401ca24fSsrinivas pandruvada  */
19401ca24fSsrinivas pandruvada #include <linux/device.h>
20401ca24fSsrinivas pandruvada #include <linux/hid.h>
21401ca24fSsrinivas pandruvada #include <linux/usb.h>
22401ca24fSsrinivas pandruvada #include "usbhid/usbhid.h"
23401ca24fSsrinivas pandruvada #include <linux/module.h>
24401ca24fSsrinivas pandruvada #include <linux/slab.h>
25401ca24fSsrinivas pandruvada #include <linux/mfd/core.h>
26401ca24fSsrinivas pandruvada #include <linux/list.h>
27401ca24fSsrinivas pandruvada #include <linux/hid-sensor-ids.h>
28401ca24fSsrinivas pandruvada #include <linux/hid-sensor-hub.h>
29401ca24fSsrinivas pandruvada #include "hid-ids.h"
30401ca24fSsrinivas pandruvada 
31401ca24fSsrinivas pandruvada /**
32401ca24fSsrinivas pandruvada  * struct sensor_hub_pending - Synchronous read pending information
33401ca24fSsrinivas pandruvada  * @status:		Pending status true/false.
34401ca24fSsrinivas pandruvada  * @ready:		Completion synchronization data.
35401ca24fSsrinivas pandruvada  * @usage_id:		Usage id for physical device, E.g. Gyro usage id.
36401ca24fSsrinivas pandruvada  * @attr_usage_id:	Usage Id of a field, E.g. X-AXIS for a gyro.
37401ca24fSsrinivas pandruvada  * @raw_size:		Response size for a read request.
38401ca24fSsrinivas pandruvada  * @raw_data:		Place holder for received response.
39401ca24fSsrinivas pandruvada  */
40401ca24fSsrinivas pandruvada struct sensor_hub_pending {
41401ca24fSsrinivas pandruvada 	bool status;
42401ca24fSsrinivas pandruvada 	struct completion ready;
43401ca24fSsrinivas pandruvada 	u32 usage_id;
44401ca24fSsrinivas pandruvada 	u32 attr_usage_id;
45401ca24fSsrinivas pandruvada 	int raw_size;
46401ca24fSsrinivas pandruvada 	u8  *raw_data;
47401ca24fSsrinivas pandruvada };
48401ca24fSsrinivas pandruvada 
49401ca24fSsrinivas pandruvada /**
50401ca24fSsrinivas pandruvada  * struct sensor_hub_data - Hold a instance data for a HID hub device
51401ca24fSsrinivas pandruvada  * @hsdev:		Stored hid instance for current hub device.
52401ca24fSsrinivas pandruvada  * @mutex:		Mutex to serialize synchronous request.
53401ca24fSsrinivas pandruvada  * @lock:		Spin lock to protect pending request structure.
54401ca24fSsrinivas pandruvada  * @pending:		Holds information of pending sync read request.
55401ca24fSsrinivas pandruvada  * @dyn_callback_list:	Holds callback function
56401ca24fSsrinivas pandruvada  * @dyn_callback_lock:	spin lock to protect callback list
57401ca24fSsrinivas pandruvada  * @hid_sensor_hub_client_devs:	Stores all MFD cells for a hub instance.
58401ca24fSsrinivas pandruvada  * @hid_sensor_client_cnt: Number of MFD cells, (no of sensors attached).
59401ca24fSsrinivas pandruvada  */
60401ca24fSsrinivas pandruvada struct sensor_hub_data {
61401ca24fSsrinivas pandruvada 	struct hid_sensor_hub_device *hsdev;
62401ca24fSsrinivas pandruvada 	struct mutex mutex;
63401ca24fSsrinivas pandruvada 	spinlock_t lock;
64401ca24fSsrinivas pandruvada 	struct sensor_hub_pending pending;
65401ca24fSsrinivas pandruvada 	struct list_head dyn_callback_list;
66401ca24fSsrinivas pandruvada 	spinlock_t dyn_callback_lock;
67401ca24fSsrinivas pandruvada 	struct mfd_cell *hid_sensor_hub_client_devs;
68401ca24fSsrinivas pandruvada 	int hid_sensor_client_cnt;
69401ca24fSsrinivas pandruvada };
70401ca24fSsrinivas pandruvada 
71401ca24fSsrinivas pandruvada /**
72401ca24fSsrinivas pandruvada  * struct hid_sensor_hub_callbacks_list - Stores callback list
73401ca24fSsrinivas pandruvada  * @list:		list head.
74401ca24fSsrinivas pandruvada  * @usage_id:		usage id for a physical device.
75401ca24fSsrinivas pandruvada  * @usage_callback:	Stores registered callback functions.
76401ca24fSsrinivas pandruvada  * @priv:		Private data for a physical device.
77401ca24fSsrinivas pandruvada  */
78401ca24fSsrinivas pandruvada struct hid_sensor_hub_callbacks_list {
79401ca24fSsrinivas pandruvada 	struct list_head list;
80401ca24fSsrinivas pandruvada 	u32 usage_id;
81401ca24fSsrinivas pandruvada 	struct hid_sensor_hub_callbacks *usage_callback;
82401ca24fSsrinivas pandruvada 	void *priv;
83401ca24fSsrinivas pandruvada };
84401ca24fSsrinivas pandruvada 
85401ca24fSsrinivas pandruvada static int sensor_hub_check_for_sensor_page(struct hid_device *hdev)
86401ca24fSsrinivas pandruvada {
87401ca24fSsrinivas pandruvada 	int i;
88401ca24fSsrinivas pandruvada 	int ret = -EINVAL;
89401ca24fSsrinivas pandruvada 
90401ca24fSsrinivas pandruvada 	for (i = 0; i < hdev->maxcollection; i++) {
91401ca24fSsrinivas pandruvada 		struct hid_collection *col = &hdev->collection[i];
92401ca24fSsrinivas pandruvada 		if (col->type == HID_COLLECTION_PHYSICAL &&
93401ca24fSsrinivas pandruvada 		   (col->usage & HID_USAGE_PAGE) == HID_UP_SENSOR) {
94401ca24fSsrinivas pandruvada 			ret = 0;
95401ca24fSsrinivas pandruvada 			break;
96401ca24fSsrinivas pandruvada 		}
97401ca24fSsrinivas pandruvada 	}
98401ca24fSsrinivas pandruvada 
99401ca24fSsrinivas pandruvada 	return ret;
100401ca24fSsrinivas pandruvada }
101401ca24fSsrinivas pandruvada 
102401ca24fSsrinivas pandruvada static struct hid_report *sensor_hub_report(int id, struct hid_device *hdev,
103401ca24fSsrinivas pandruvada 						int dir)
104401ca24fSsrinivas pandruvada {
105401ca24fSsrinivas pandruvada 	struct hid_report *report;
106401ca24fSsrinivas pandruvada 
107401ca24fSsrinivas pandruvada 	list_for_each_entry(report, &hdev->report_enum[dir].report_list, list) {
108401ca24fSsrinivas pandruvada 		if (report->id == id)
109401ca24fSsrinivas pandruvada 			return report;
110401ca24fSsrinivas pandruvada 	}
111401ca24fSsrinivas pandruvada 	hid_warn(hdev, "No report with id 0x%x found\n", id);
112401ca24fSsrinivas pandruvada 
113401ca24fSsrinivas pandruvada 	return NULL;
114401ca24fSsrinivas pandruvada }
115401ca24fSsrinivas pandruvada 
116401ca24fSsrinivas pandruvada static int sensor_hub_get_physical_device_count(
117401ca24fSsrinivas pandruvada 				struct hid_report_enum *report_enum)
118401ca24fSsrinivas pandruvada {
119401ca24fSsrinivas pandruvada 	struct hid_report *report;
120401ca24fSsrinivas pandruvada 	struct hid_field *field;
121401ca24fSsrinivas pandruvada 	int cnt = 0;
122401ca24fSsrinivas pandruvada 
123401ca24fSsrinivas pandruvada 	list_for_each_entry(report, &report_enum->report_list, list) {
124401ca24fSsrinivas pandruvada 		field = report->field[0];
125401ca24fSsrinivas pandruvada 		if (report->maxfield && field &&
126401ca24fSsrinivas pandruvada 					field->physical)
127401ca24fSsrinivas pandruvada 			cnt++;
128401ca24fSsrinivas pandruvada 	}
129401ca24fSsrinivas pandruvada 
130401ca24fSsrinivas pandruvada 	return cnt;
131401ca24fSsrinivas pandruvada }
132401ca24fSsrinivas pandruvada 
133401ca24fSsrinivas pandruvada static void sensor_hub_fill_attr_info(
134401ca24fSsrinivas pandruvada 		struct hid_sensor_hub_attribute_info *info,
135401ca24fSsrinivas pandruvada 		s32 index, s32 report_id, s32 units, s32 unit_expo, s32 size)
136401ca24fSsrinivas pandruvada {
137401ca24fSsrinivas pandruvada 	info->index = index;
138401ca24fSsrinivas pandruvada 	info->report_id = report_id;
139401ca24fSsrinivas pandruvada 	info->units = units;
140401ca24fSsrinivas pandruvada 	info->unit_expo = unit_expo;
141401ca24fSsrinivas pandruvada 	info->size = size/8;
142401ca24fSsrinivas pandruvada }
143401ca24fSsrinivas pandruvada 
144401ca24fSsrinivas pandruvada static struct hid_sensor_hub_callbacks *sensor_hub_get_callback(
145401ca24fSsrinivas pandruvada 					struct hid_device *hdev,
146401ca24fSsrinivas pandruvada 					u32 usage_id, void **priv)
147401ca24fSsrinivas pandruvada {
148401ca24fSsrinivas pandruvada 	struct hid_sensor_hub_callbacks_list *callback;
149401ca24fSsrinivas pandruvada 	struct sensor_hub_data *pdata = hid_get_drvdata(hdev);
150401ca24fSsrinivas pandruvada 
151401ca24fSsrinivas pandruvada 	spin_lock(&pdata->dyn_callback_lock);
152401ca24fSsrinivas pandruvada 	list_for_each_entry(callback, &pdata->dyn_callback_list, list)
153401ca24fSsrinivas pandruvada 		if (callback->usage_id == usage_id) {
154401ca24fSsrinivas pandruvada 			*priv = callback->priv;
155401ca24fSsrinivas pandruvada 			spin_unlock(&pdata->dyn_callback_lock);
156401ca24fSsrinivas pandruvada 			return callback->usage_callback;
157401ca24fSsrinivas pandruvada 		}
158401ca24fSsrinivas pandruvada 	spin_unlock(&pdata->dyn_callback_lock);
159401ca24fSsrinivas pandruvada 
160401ca24fSsrinivas pandruvada 	return NULL;
161401ca24fSsrinivas pandruvada }
162401ca24fSsrinivas pandruvada 
163401ca24fSsrinivas pandruvada int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
164401ca24fSsrinivas pandruvada 			u32 usage_id,
165401ca24fSsrinivas pandruvada 			struct hid_sensor_hub_callbacks *usage_callback)
166401ca24fSsrinivas pandruvada {
167401ca24fSsrinivas pandruvada 	struct hid_sensor_hub_callbacks_list *callback;
168401ca24fSsrinivas pandruvada 	struct sensor_hub_data *pdata = hid_get_drvdata(hsdev->hdev);
169401ca24fSsrinivas pandruvada 
170401ca24fSsrinivas pandruvada 	spin_lock(&pdata->dyn_callback_lock);
171401ca24fSsrinivas pandruvada 	list_for_each_entry(callback, &pdata->dyn_callback_list, list)
172401ca24fSsrinivas pandruvada 		if (callback->usage_id == usage_id) {
173401ca24fSsrinivas pandruvada 			spin_unlock(&pdata->dyn_callback_lock);
174401ca24fSsrinivas pandruvada 			return -EINVAL;
175401ca24fSsrinivas pandruvada 		}
176*2b7c4b8eSDan Carpenter 	callback = kzalloc(sizeof(*callback), GFP_ATOMIC);
177401ca24fSsrinivas pandruvada 	if (!callback) {
178401ca24fSsrinivas pandruvada 		spin_unlock(&pdata->dyn_callback_lock);
179401ca24fSsrinivas pandruvada 		return -ENOMEM;
180401ca24fSsrinivas pandruvada 	}
181401ca24fSsrinivas pandruvada 	callback->usage_callback = usage_callback;
182401ca24fSsrinivas pandruvada 	callback->usage_id = usage_id;
183401ca24fSsrinivas pandruvada 	callback->priv = NULL;
184401ca24fSsrinivas pandruvada 	list_add_tail(&callback->list, &pdata->dyn_callback_list);
185401ca24fSsrinivas pandruvada 	spin_unlock(&pdata->dyn_callback_lock);
186401ca24fSsrinivas pandruvada 
187401ca24fSsrinivas pandruvada 	return 0;
188401ca24fSsrinivas pandruvada }
189401ca24fSsrinivas pandruvada EXPORT_SYMBOL_GPL(sensor_hub_register_callback);
190401ca24fSsrinivas pandruvada 
191401ca24fSsrinivas pandruvada int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
192401ca24fSsrinivas pandruvada 				u32 usage_id)
193401ca24fSsrinivas pandruvada {
194401ca24fSsrinivas pandruvada 	struct hid_sensor_hub_callbacks_list *callback;
195401ca24fSsrinivas pandruvada 	struct sensor_hub_data *pdata = hid_get_drvdata(hsdev->hdev);
196401ca24fSsrinivas pandruvada 
197401ca24fSsrinivas pandruvada 	spin_lock(&pdata->dyn_callback_lock);
198401ca24fSsrinivas pandruvada 	list_for_each_entry(callback, &pdata->dyn_callback_list, list)
199401ca24fSsrinivas pandruvada 		if (callback->usage_id == usage_id) {
200401ca24fSsrinivas pandruvada 			list_del(&callback->list);
201401ca24fSsrinivas pandruvada 			kfree(callback);
202401ca24fSsrinivas pandruvada 			break;
203401ca24fSsrinivas pandruvada 		}
204401ca24fSsrinivas pandruvada 	spin_unlock(&pdata->dyn_callback_lock);
205401ca24fSsrinivas pandruvada 
206401ca24fSsrinivas pandruvada 	return 0;
207401ca24fSsrinivas pandruvada }
208401ca24fSsrinivas pandruvada EXPORT_SYMBOL_GPL(sensor_hub_remove_callback);
209401ca24fSsrinivas pandruvada 
210401ca24fSsrinivas pandruvada int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
211401ca24fSsrinivas pandruvada 				u32 field_index, s32 value)
212401ca24fSsrinivas pandruvada {
213401ca24fSsrinivas pandruvada 	struct hid_report *report;
214401ca24fSsrinivas pandruvada 	struct sensor_hub_data *data =  hid_get_drvdata(hsdev->hdev);
215401ca24fSsrinivas pandruvada 	int ret = 0;
216401ca24fSsrinivas pandruvada 
217401ca24fSsrinivas pandruvada 	if (report_id < 0)
218401ca24fSsrinivas pandruvada 		return -EINVAL;
219401ca24fSsrinivas pandruvada 
220401ca24fSsrinivas pandruvada 	mutex_lock(&data->mutex);
221401ca24fSsrinivas pandruvada 	report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
222401ca24fSsrinivas pandruvada 	if (!report || (field_index >=  report->maxfield)) {
223401ca24fSsrinivas pandruvada 		ret = -EINVAL;
224401ca24fSsrinivas pandruvada 		goto done_proc;
225401ca24fSsrinivas pandruvada 	}
226401ca24fSsrinivas pandruvada 	hid_set_field(report->field[field_index], 0, value);
227401ca24fSsrinivas pandruvada 	usbhid_submit_report(hsdev->hdev, report, USB_DIR_OUT);
228401ca24fSsrinivas pandruvada 	usbhid_wait_io(hsdev->hdev);
229401ca24fSsrinivas pandruvada 
230401ca24fSsrinivas pandruvada done_proc:
231401ca24fSsrinivas pandruvada 	mutex_unlock(&data->mutex);
232401ca24fSsrinivas pandruvada 
233401ca24fSsrinivas pandruvada 	return ret;
234401ca24fSsrinivas pandruvada }
235401ca24fSsrinivas pandruvada EXPORT_SYMBOL_GPL(sensor_hub_set_feature);
236401ca24fSsrinivas pandruvada 
237401ca24fSsrinivas pandruvada int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
238401ca24fSsrinivas pandruvada 				u32 field_index, s32 *value)
239401ca24fSsrinivas pandruvada {
240401ca24fSsrinivas pandruvada 	struct hid_report *report;
241401ca24fSsrinivas pandruvada 	struct sensor_hub_data *data =  hid_get_drvdata(hsdev->hdev);
242401ca24fSsrinivas pandruvada 	int ret = 0;
243401ca24fSsrinivas pandruvada 
244401ca24fSsrinivas pandruvada 	if (report_id < 0)
245401ca24fSsrinivas pandruvada 		return -EINVAL;
246401ca24fSsrinivas pandruvada 
247401ca24fSsrinivas pandruvada 	mutex_lock(&data->mutex);
248401ca24fSsrinivas pandruvada 	report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
249401ca24fSsrinivas pandruvada 	if (!report || (field_index >=  report->maxfield)) {
250401ca24fSsrinivas pandruvada 		ret = -EINVAL;
251401ca24fSsrinivas pandruvada 		goto done_proc;
252401ca24fSsrinivas pandruvada 	}
253401ca24fSsrinivas pandruvada 	usbhid_submit_report(hsdev->hdev, report, USB_DIR_IN);
254401ca24fSsrinivas pandruvada 	usbhid_wait_io(hsdev->hdev);
255401ca24fSsrinivas pandruvada 	*value = report->field[field_index]->value[0];
256401ca24fSsrinivas pandruvada 
257401ca24fSsrinivas pandruvada done_proc:
258401ca24fSsrinivas pandruvada 	mutex_unlock(&data->mutex);
259401ca24fSsrinivas pandruvada 
260401ca24fSsrinivas pandruvada 	return ret;
261401ca24fSsrinivas pandruvada }
262401ca24fSsrinivas pandruvada EXPORT_SYMBOL_GPL(sensor_hub_get_feature);
263401ca24fSsrinivas pandruvada 
264401ca24fSsrinivas pandruvada 
265401ca24fSsrinivas pandruvada int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
266401ca24fSsrinivas pandruvada 					u32 usage_id,
267401ca24fSsrinivas pandruvada 					u32 attr_usage_id, u32 report_id)
268401ca24fSsrinivas pandruvada {
269401ca24fSsrinivas pandruvada 	struct sensor_hub_data *data =  hid_get_drvdata(hsdev->hdev);
270401ca24fSsrinivas pandruvada 	unsigned long flags;
271401ca24fSsrinivas pandruvada 	struct hid_report *report;
272401ca24fSsrinivas pandruvada 	int ret_val = 0;
273401ca24fSsrinivas pandruvada 
274401ca24fSsrinivas pandruvada 	if (report_id < 0)
275401ca24fSsrinivas pandruvada 		return -EINVAL;
276401ca24fSsrinivas pandruvada 
277401ca24fSsrinivas pandruvada 	mutex_lock(&data->mutex);
278401ca24fSsrinivas pandruvada 	memset(&data->pending, 0, sizeof(data->pending));
279401ca24fSsrinivas pandruvada 	init_completion(&data->pending.ready);
280401ca24fSsrinivas pandruvada 	data->pending.usage_id = usage_id;
281401ca24fSsrinivas pandruvada 	data->pending.attr_usage_id = attr_usage_id;
282401ca24fSsrinivas pandruvada 	data->pending.raw_size = 0;
283401ca24fSsrinivas pandruvada 
284401ca24fSsrinivas pandruvada 	spin_lock_irqsave(&data->lock, flags);
285401ca24fSsrinivas pandruvada 	data->pending.status = true;
286401ca24fSsrinivas pandruvada 	report = sensor_hub_report(report_id, hsdev->hdev, HID_INPUT_REPORT);
287401ca24fSsrinivas pandruvada 	if (!report) {
288401ca24fSsrinivas pandruvada 		spin_unlock_irqrestore(&data->lock, flags);
289401ca24fSsrinivas pandruvada 		goto err_free;
290401ca24fSsrinivas pandruvada 	}
291401ca24fSsrinivas pandruvada 	usbhid_submit_report(hsdev->hdev, report, USB_DIR_IN);
292401ca24fSsrinivas pandruvada 	spin_unlock_irqrestore(&data->lock, flags);
293401ca24fSsrinivas pandruvada 	wait_for_completion_interruptible_timeout(&data->pending.ready, HZ*5);
294401ca24fSsrinivas pandruvada 	switch (data->pending.raw_size) {
295401ca24fSsrinivas pandruvada 	case 1:
296401ca24fSsrinivas pandruvada 		ret_val = *(u8 *)data->pending.raw_data;
297401ca24fSsrinivas pandruvada 		break;
298401ca24fSsrinivas pandruvada 	case 2:
299401ca24fSsrinivas pandruvada 		ret_val = *(u16 *)data->pending.raw_data;
300401ca24fSsrinivas pandruvada 		break;
301401ca24fSsrinivas pandruvada 	case 4:
302401ca24fSsrinivas pandruvada 		ret_val = *(u32 *)data->pending.raw_data;
303401ca24fSsrinivas pandruvada 		break;
304401ca24fSsrinivas pandruvada 	default:
305401ca24fSsrinivas pandruvada 		ret_val = 0;
306401ca24fSsrinivas pandruvada 	}
307401ca24fSsrinivas pandruvada 	kfree(data->pending.raw_data);
308401ca24fSsrinivas pandruvada 
309401ca24fSsrinivas pandruvada err_free:
310401ca24fSsrinivas pandruvada 	data->pending.status = false;
311401ca24fSsrinivas pandruvada 	mutex_unlock(&data->mutex);
312401ca24fSsrinivas pandruvada 
313401ca24fSsrinivas pandruvada 	return ret_val;
314401ca24fSsrinivas pandruvada }
315401ca24fSsrinivas pandruvada EXPORT_SYMBOL_GPL(sensor_hub_input_attr_get_raw_value);
316401ca24fSsrinivas pandruvada 
317401ca24fSsrinivas pandruvada int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
318401ca24fSsrinivas pandruvada 				u8 type,
319401ca24fSsrinivas pandruvada 				u32 usage_id,
320401ca24fSsrinivas pandruvada 				u32 attr_usage_id,
321401ca24fSsrinivas pandruvada 				struct hid_sensor_hub_attribute_info *info)
322401ca24fSsrinivas pandruvada {
323401ca24fSsrinivas pandruvada 	int ret = -1;
324401ca24fSsrinivas pandruvada 	int i, j;
325401ca24fSsrinivas pandruvada 	int collection_index = -1;
326401ca24fSsrinivas pandruvada 	struct hid_report *report;
327401ca24fSsrinivas pandruvada 	struct hid_field *field;
328401ca24fSsrinivas pandruvada 	struct hid_report_enum *report_enum;
329401ca24fSsrinivas pandruvada 	struct hid_device *hdev = hsdev->hdev;
330401ca24fSsrinivas pandruvada 
331401ca24fSsrinivas pandruvada 	/* Initialize with defaults */
332401ca24fSsrinivas pandruvada 	info->usage_id = usage_id;
333401ca24fSsrinivas pandruvada 	info->attrib_id =  attr_usage_id;
334401ca24fSsrinivas pandruvada 	info->report_id = -1;
335401ca24fSsrinivas pandruvada 	info->index = -1;
336401ca24fSsrinivas pandruvada 	info->units = -1;
337401ca24fSsrinivas pandruvada 	info->unit_expo = -1;
338401ca24fSsrinivas pandruvada 
339401ca24fSsrinivas pandruvada 	for (i = 0; i < hdev->maxcollection; ++i) {
340401ca24fSsrinivas pandruvada 		struct hid_collection *collection = &hdev->collection[i];
341401ca24fSsrinivas pandruvada 		if (usage_id == collection->usage) {
342401ca24fSsrinivas pandruvada 			collection_index = i;
343401ca24fSsrinivas pandruvada 			break;
344401ca24fSsrinivas pandruvada 		}
345401ca24fSsrinivas pandruvada 	}
346401ca24fSsrinivas pandruvada 	if (collection_index == -1)
347401ca24fSsrinivas pandruvada 		goto err_ret;
348401ca24fSsrinivas pandruvada 
349401ca24fSsrinivas pandruvada 	report_enum = &hdev->report_enum[type];
350401ca24fSsrinivas pandruvada 	list_for_each_entry(report, &report_enum->report_list, list) {
351401ca24fSsrinivas pandruvada 		for (i = 0; i < report->maxfield; ++i) {
352401ca24fSsrinivas pandruvada 			field = report->field[i];
353401ca24fSsrinivas pandruvada 			if (field->physical == usage_id &&
354401ca24fSsrinivas pandruvada 				field->logical == attr_usage_id) {
355401ca24fSsrinivas pandruvada 				sensor_hub_fill_attr_info(info, i, report->id,
356401ca24fSsrinivas pandruvada 					field->unit, field->unit_exponent,
357401ca24fSsrinivas pandruvada 					field->report_size);
358401ca24fSsrinivas pandruvada 				ret = 0;
359401ca24fSsrinivas pandruvada 			} else {
360401ca24fSsrinivas pandruvada 				for (j = 0; j < field->maxusage; ++j) {
361401ca24fSsrinivas pandruvada 					if (field->usage[j].hid ==
362401ca24fSsrinivas pandruvada 					attr_usage_id &&
363401ca24fSsrinivas pandruvada 					field->usage[j].collection_index ==
364401ca24fSsrinivas pandruvada 					collection_index)  {
365401ca24fSsrinivas pandruvada 						sensor_hub_fill_attr_info(info,
366401ca24fSsrinivas pandruvada 							i, report->id,
367401ca24fSsrinivas pandruvada 							field->unit,
368401ca24fSsrinivas pandruvada 							field->unit_exponent,
369401ca24fSsrinivas pandruvada 							field->report_size);
370401ca24fSsrinivas pandruvada 						ret = 0;
371401ca24fSsrinivas pandruvada 						break;
372401ca24fSsrinivas pandruvada 					}
373401ca24fSsrinivas pandruvada 				}
374401ca24fSsrinivas pandruvada 			}
375401ca24fSsrinivas pandruvada 			if (ret == 0)
376401ca24fSsrinivas pandruvada 				break;
377401ca24fSsrinivas pandruvada 		}
378401ca24fSsrinivas pandruvada 	}
379401ca24fSsrinivas pandruvada 
380401ca24fSsrinivas pandruvada err_ret:
381401ca24fSsrinivas pandruvada 	return ret;
382401ca24fSsrinivas pandruvada }
383401ca24fSsrinivas pandruvada EXPORT_SYMBOL_GPL(sensor_hub_input_get_attribute_info);
384401ca24fSsrinivas pandruvada 
385401ca24fSsrinivas pandruvada #ifdef CONFIG_PM
386401ca24fSsrinivas pandruvada static int sensor_hub_suspend(struct hid_device *hdev, pm_message_t message)
387401ca24fSsrinivas pandruvada {
388401ca24fSsrinivas pandruvada 	struct sensor_hub_data *pdata =  hid_get_drvdata(hdev);
389401ca24fSsrinivas pandruvada 	struct hid_sensor_hub_callbacks_list *callback;
390401ca24fSsrinivas pandruvada 
391401ca24fSsrinivas pandruvada 	hid_dbg(hdev, " sensor_hub_suspend\n");
392401ca24fSsrinivas pandruvada 	spin_lock(&pdata->dyn_callback_lock);
393401ca24fSsrinivas pandruvada 	list_for_each_entry(callback, &pdata->dyn_callback_list, list) {
394401ca24fSsrinivas pandruvada 		if (callback->usage_callback->suspend)
395401ca24fSsrinivas pandruvada 			callback->usage_callback->suspend(
396401ca24fSsrinivas pandruvada 					pdata->hsdev, callback->priv);
397401ca24fSsrinivas pandruvada 	}
398401ca24fSsrinivas pandruvada 	spin_unlock(&pdata->dyn_callback_lock);
399401ca24fSsrinivas pandruvada 
400401ca24fSsrinivas pandruvada 	return 0;
401401ca24fSsrinivas pandruvada }
402401ca24fSsrinivas pandruvada 
403401ca24fSsrinivas pandruvada static int sensor_hub_resume(struct hid_device *hdev)
404401ca24fSsrinivas pandruvada {
405401ca24fSsrinivas pandruvada 	struct sensor_hub_data *pdata =  hid_get_drvdata(hdev);
406401ca24fSsrinivas pandruvada 	struct hid_sensor_hub_callbacks_list *callback;
407401ca24fSsrinivas pandruvada 
408401ca24fSsrinivas pandruvada 	hid_dbg(hdev, " sensor_hub_resume\n");
409401ca24fSsrinivas pandruvada 	spin_lock(&pdata->dyn_callback_lock);
410401ca24fSsrinivas pandruvada 	list_for_each_entry(callback, &pdata->dyn_callback_list, list) {
411401ca24fSsrinivas pandruvada 		if (callback->usage_callback->resume)
412401ca24fSsrinivas pandruvada 			callback->usage_callback->resume(
413401ca24fSsrinivas pandruvada 					pdata->hsdev, callback->priv);
414401ca24fSsrinivas pandruvada 	}
415401ca24fSsrinivas pandruvada 	spin_unlock(&pdata->dyn_callback_lock);
416401ca24fSsrinivas pandruvada 
417401ca24fSsrinivas pandruvada 	return 0;
418401ca24fSsrinivas pandruvada }
419401ca24fSsrinivas pandruvada 
420401ca24fSsrinivas pandruvada static int sensor_hub_reset_resume(struct hid_device *hdev)
421401ca24fSsrinivas pandruvada {
422401ca24fSsrinivas pandruvada 	return 0;
423401ca24fSsrinivas pandruvada }
424401ca24fSsrinivas pandruvada #endif
425401ca24fSsrinivas pandruvada /*
426401ca24fSsrinivas pandruvada  * Handle raw report as sent by device
427401ca24fSsrinivas pandruvada  */
428401ca24fSsrinivas pandruvada static int sensor_hub_raw_event(struct hid_device *hdev,
429401ca24fSsrinivas pandruvada 		struct hid_report *report, u8 *raw_data, int size)
430401ca24fSsrinivas pandruvada {
431401ca24fSsrinivas pandruvada 	int i;
432401ca24fSsrinivas pandruvada 	u8 *ptr;
433401ca24fSsrinivas pandruvada 	int sz;
434401ca24fSsrinivas pandruvada 	struct sensor_hub_data *pdata = hid_get_drvdata(hdev);
435401ca24fSsrinivas pandruvada 	unsigned long flags;
436401ca24fSsrinivas pandruvada 	struct hid_sensor_hub_callbacks *callback = NULL;
437401ca24fSsrinivas pandruvada 	struct hid_collection *collection = NULL;
438401ca24fSsrinivas pandruvada 	void *priv = NULL;
439401ca24fSsrinivas pandruvada 
440401ca24fSsrinivas pandruvada 	hid_dbg(hdev, "sensor_hub_raw_event report id:0x%x size:%d type:%d\n",
441401ca24fSsrinivas pandruvada 			 report->id, size, report->type);
442401ca24fSsrinivas pandruvada 	hid_dbg(hdev, "maxfield:%d\n", report->maxfield);
443401ca24fSsrinivas pandruvada 	if (report->type != HID_INPUT_REPORT)
444401ca24fSsrinivas pandruvada 		return 1;
445401ca24fSsrinivas pandruvada 
446401ca24fSsrinivas pandruvada 	ptr = raw_data;
447401ca24fSsrinivas pandruvada 	ptr++; /*Skip report id*/
448401ca24fSsrinivas pandruvada 
449401ca24fSsrinivas pandruvada 	if (!report)
450401ca24fSsrinivas pandruvada 		goto err_report;
451401ca24fSsrinivas pandruvada 
452401ca24fSsrinivas pandruvada 	spin_lock_irqsave(&pdata->lock, flags);
453401ca24fSsrinivas pandruvada 
454401ca24fSsrinivas pandruvada 	for (i = 0; i < report->maxfield; ++i) {
455401ca24fSsrinivas pandruvada 
456401ca24fSsrinivas pandruvada 		hid_dbg(hdev, "%d collection_index:%x hid:%x sz:%x\n",
457401ca24fSsrinivas pandruvada 				i, report->field[i]->usage->collection_index,
458401ca24fSsrinivas pandruvada 				report->field[i]->usage->hid,
459401ca24fSsrinivas pandruvada 				report->field[i]->report_size/8);
460401ca24fSsrinivas pandruvada 
461401ca24fSsrinivas pandruvada 		sz = report->field[i]->report_size/8;
462401ca24fSsrinivas pandruvada 		if (pdata->pending.status && pdata->pending.attr_usage_id ==
463401ca24fSsrinivas pandruvada 				report->field[i]->usage->hid) {
464401ca24fSsrinivas pandruvada 			hid_dbg(hdev, "data was pending ...\n");
465*2b7c4b8eSDan Carpenter 			pdata->pending.raw_data = kmalloc(sz, GFP_ATOMIC);
466401ca24fSsrinivas pandruvada 			if (pdata->pending.raw_data) {
467401ca24fSsrinivas pandruvada 				memcpy(pdata->pending.raw_data, ptr, sz);
468401ca24fSsrinivas pandruvada 				pdata->pending.raw_size  = sz;
469401ca24fSsrinivas pandruvada 			} else
470401ca24fSsrinivas pandruvada 				pdata->pending.raw_size = 0;
471401ca24fSsrinivas pandruvada 			complete(&pdata->pending.ready);
472401ca24fSsrinivas pandruvada 		}
473401ca24fSsrinivas pandruvada 		collection = &hdev->collection[
474401ca24fSsrinivas pandruvada 				report->field[i]->usage->collection_index];
475401ca24fSsrinivas pandruvada 		hid_dbg(hdev, "collection->usage %x\n",
476401ca24fSsrinivas pandruvada 					collection->usage);
477401ca24fSsrinivas pandruvada 		callback = sensor_hub_get_callback(pdata->hsdev->hdev,
478401ca24fSsrinivas pandruvada 						report->field[i]->physical,
479401ca24fSsrinivas pandruvada 							&priv);
480401ca24fSsrinivas pandruvada 		if (callback && callback->capture_sample) {
481401ca24fSsrinivas pandruvada 			if (report->field[i]->logical)
482401ca24fSsrinivas pandruvada 				callback->capture_sample(pdata->hsdev,
483401ca24fSsrinivas pandruvada 					report->field[i]->logical, sz, ptr,
484401ca24fSsrinivas pandruvada 					callback->pdev);
485401ca24fSsrinivas pandruvada 			else
486401ca24fSsrinivas pandruvada 				callback->capture_sample(pdata->hsdev,
487401ca24fSsrinivas pandruvada 					report->field[i]->usage->hid, sz, ptr,
488401ca24fSsrinivas pandruvada 					callback->pdev);
489401ca24fSsrinivas pandruvada 		}
490401ca24fSsrinivas pandruvada 		ptr += sz;
491401ca24fSsrinivas pandruvada 	}
492401ca24fSsrinivas pandruvada 	if (callback && collection && callback->send_event)
493401ca24fSsrinivas pandruvada 		callback->send_event(pdata->hsdev, collection->usage,
494401ca24fSsrinivas pandruvada 				callback->pdev);
495401ca24fSsrinivas pandruvada 	spin_unlock_irqrestore(&pdata->lock, flags);
496401ca24fSsrinivas pandruvada 
497401ca24fSsrinivas pandruvada err_report:
498401ca24fSsrinivas pandruvada 	return 1;
499401ca24fSsrinivas pandruvada }
500401ca24fSsrinivas pandruvada 
501401ca24fSsrinivas pandruvada static int sensor_hub_probe(struct hid_device *hdev,
502401ca24fSsrinivas pandruvada 				const struct hid_device_id *id)
503401ca24fSsrinivas pandruvada {
504401ca24fSsrinivas pandruvada 	int ret;
505401ca24fSsrinivas pandruvada 	struct sensor_hub_data *sd;
506401ca24fSsrinivas pandruvada 	int i;
507401ca24fSsrinivas pandruvada 	char *name;
508401ca24fSsrinivas pandruvada 	struct hid_report *report;
509401ca24fSsrinivas pandruvada 	struct hid_report_enum *report_enum;
510401ca24fSsrinivas pandruvada 	struct hid_field *field;
511401ca24fSsrinivas pandruvada 	int dev_cnt;
512401ca24fSsrinivas pandruvada 
513401ca24fSsrinivas pandruvada 	sd = kzalloc(sizeof(struct sensor_hub_data), GFP_KERNEL);
514401ca24fSsrinivas pandruvada 	if (!sd) {
515401ca24fSsrinivas pandruvada 		hid_err(hdev, "cannot allocate Sensor data\n");
516401ca24fSsrinivas pandruvada 		return -ENOMEM;
517401ca24fSsrinivas pandruvada 	}
518401ca24fSsrinivas pandruvada 	sd->hsdev = kzalloc(sizeof(struct hid_sensor_hub_device), GFP_KERNEL);
519401ca24fSsrinivas pandruvada 	if (!sd->hsdev) {
520401ca24fSsrinivas pandruvada 		hid_err(hdev, "cannot allocate hid_sensor_hub_device\n");
521401ca24fSsrinivas pandruvada 		ret = -ENOMEM;
522401ca24fSsrinivas pandruvada 		goto err_free_hub;
523401ca24fSsrinivas pandruvada 	}
524401ca24fSsrinivas pandruvada 	hid_set_drvdata(hdev, sd);
525401ca24fSsrinivas pandruvada 	sd->hsdev->hdev = hdev;
526401ca24fSsrinivas pandruvada 	sd->hsdev->vendor_id = hdev->vendor;
527401ca24fSsrinivas pandruvada 	sd->hsdev->product_id = hdev->product;
528401ca24fSsrinivas pandruvada 	spin_lock_init(&sd->lock);
529401ca24fSsrinivas pandruvada 	spin_lock_init(&sd->dyn_callback_lock);
530401ca24fSsrinivas pandruvada 	mutex_init(&sd->mutex);
531401ca24fSsrinivas pandruvada 	ret = hid_parse(hdev);
532401ca24fSsrinivas pandruvada 	if (ret) {
533401ca24fSsrinivas pandruvada 		hid_err(hdev, "parse failed\n");
534401ca24fSsrinivas pandruvada 		goto err_free;
535401ca24fSsrinivas pandruvada 	}
536401ca24fSsrinivas pandruvada 	if (sensor_hub_check_for_sensor_page(hdev) < 0) {
537401ca24fSsrinivas pandruvada 		hid_err(hdev, "sensor page not found\n");
538401ca24fSsrinivas pandruvada 		goto err_free;
539401ca24fSsrinivas pandruvada 	}
540401ca24fSsrinivas pandruvada 	INIT_LIST_HEAD(&hdev->inputs);
541401ca24fSsrinivas pandruvada 
542401ca24fSsrinivas pandruvada 	hdev->claimed = HID_CLAIMED_INPUT;
543401ca24fSsrinivas pandruvada 	ret = hid_hw_start(hdev, 0);
544401ca24fSsrinivas pandruvada 	if (ret) {
545401ca24fSsrinivas pandruvada 		hid_err(hdev, "hw start failed\n");
546401ca24fSsrinivas pandruvada 		goto err_free;
547401ca24fSsrinivas pandruvada 	}
548401ca24fSsrinivas pandruvada 	ret = hid_hw_open(hdev);
549401ca24fSsrinivas pandruvada 	if (ret) {
550401ca24fSsrinivas pandruvada 		hid_err(hdev, "failed to open input interrupt pipe\n");
551401ca24fSsrinivas pandruvada 		goto err_stop_hw;
552401ca24fSsrinivas pandruvada 	}
553401ca24fSsrinivas pandruvada 
554401ca24fSsrinivas pandruvada 	INIT_LIST_HEAD(&sd->dyn_callback_list);
555401ca24fSsrinivas pandruvada 	sd->hid_sensor_client_cnt = 0;
556401ca24fSsrinivas pandruvada 	report_enum = &hdev->report_enum[HID_INPUT_REPORT];
557401ca24fSsrinivas pandruvada 
558401ca24fSsrinivas pandruvada 	dev_cnt = sensor_hub_get_physical_device_count(report_enum);
559401ca24fSsrinivas pandruvada 	if (dev_cnt > HID_MAX_PHY_DEVICES) {
560401ca24fSsrinivas pandruvada 		hid_err(hdev, "Invalid Physical device count\n");
561401ca24fSsrinivas pandruvada 		ret = -EINVAL;
562401ca24fSsrinivas pandruvada 		goto err_close;
563401ca24fSsrinivas pandruvada 	}
564401ca24fSsrinivas pandruvada 	sd->hid_sensor_hub_client_devs = kzalloc(dev_cnt *
565401ca24fSsrinivas pandruvada 						sizeof(struct mfd_cell),
566401ca24fSsrinivas pandruvada 						GFP_KERNEL);
567401ca24fSsrinivas pandruvada 	if (sd->hid_sensor_hub_client_devs == NULL) {
568401ca24fSsrinivas pandruvada 		hid_err(hdev,
569401ca24fSsrinivas pandruvada 			"Failed to allocate memory for mfd cells\n");
570401ca24fSsrinivas pandruvada 			ret = -ENOMEM;
571401ca24fSsrinivas pandruvada 			goto err_close;
572401ca24fSsrinivas pandruvada 	}
573401ca24fSsrinivas pandruvada 	list_for_each_entry(report, &report_enum->report_list, list) {
574401ca24fSsrinivas pandruvada 		hid_dbg(hdev, "Report id:%x\n", report->id);
575401ca24fSsrinivas pandruvada 		field = report->field[0];
576401ca24fSsrinivas pandruvada 		if (report->maxfield && field &&
577401ca24fSsrinivas pandruvada 					field->physical) {
578401ca24fSsrinivas pandruvada 			name = kasprintf(GFP_KERNEL, "HID-SENSOR-%x",
579401ca24fSsrinivas pandruvada 						field->physical);
580401ca24fSsrinivas pandruvada 			if (name  == NULL) {
581401ca24fSsrinivas pandruvada 				hid_err(hdev,
582401ca24fSsrinivas pandruvada 					"Failed MFD device name\n");
583401ca24fSsrinivas pandruvada 					ret = -ENOMEM;
584401ca24fSsrinivas pandruvada 					goto err_free_cells;
585401ca24fSsrinivas pandruvada 			}
586401ca24fSsrinivas pandruvada 			sd->hid_sensor_hub_client_devs[
587401ca24fSsrinivas pandruvada 				sd->hid_sensor_client_cnt].name = name;
588401ca24fSsrinivas pandruvada 			sd->hid_sensor_hub_client_devs[
589401ca24fSsrinivas pandruvada 				sd->hid_sensor_client_cnt].platform_data =
590401ca24fSsrinivas pandruvada 						sd->hsdev;
591401ca24fSsrinivas pandruvada 			sd->hid_sensor_hub_client_devs[
592401ca24fSsrinivas pandruvada 				sd->hid_sensor_client_cnt].pdata_size =
593401ca24fSsrinivas pandruvada 						sizeof(*sd->hsdev);
594401ca24fSsrinivas pandruvada 			hid_dbg(hdev, "Adding %s:%p\n", name, sd);
595401ca24fSsrinivas pandruvada 			sd->hid_sensor_client_cnt++;
596401ca24fSsrinivas pandruvada 		}
597401ca24fSsrinivas pandruvada 	}
598401ca24fSsrinivas pandruvada 	ret = mfd_add_devices(&hdev->dev, 0, sd->hid_sensor_hub_client_devs,
599f45c69b1SStephen Rothwell 		sd->hid_sensor_client_cnt, NULL, 0, NULL);
600401ca24fSsrinivas pandruvada 	if (ret < 0)
601401ca24fSsrinivas pandruvada 		goto err_free_names;
602401ca24fSsrinivas pandruvada 
603401ca24fSsrinivas pandruvada 	return ret;
604401ca24fSsrinivas pandruvada 
605401ca24fSsrinivas pandruvada err_free_names:
606401ca24fSsrinivas pandruvada 	for (i = 0; i < sd->hid_sensor_client_cnt ; ++i)
607401ca24fSsrinivas pandruvada 		kfree(sd->hid_sensor_hub_client_devs[i].name);
608401ca24fSsrinivas pandruvada err_free_cells:
609401ca24fSsrinivas pandruvada 	kfree(sd->hid_sensor_hub_client_devs);
610401ca24fSsrinivas pandruvada err_close:
611401ca24fSsrinivas pandruvada 	hid_hw_stop(hdev);
612401ca24fSsrinivas pandruvada 	hid_hw_close(hdev);
613401ca24fSsrinivas pandruvada err_stop_hw:
614401ca24fSsrinivas pandruvada 	hid_hw_stop(hdev);
615401ca24fSsrinivas pandruvada err_free:
616401ca24fSsrinivas pandruvada 	kfree(sd->hsdev);
617401ca24fSsrinivas pandruvada err_free_hub:
618401ca24fSsrinivas pandruvada 	kfree(sd);
619401ca24fSsrinivas pandruvada 
620401ca24fSsrinivas pandruvada 	return ret;
621401ca24fSsrinivas pandruvada }
622401ca24fSsrinivas pandruvada 
623401ca24fSsrinivas pandruvada static void sensor_hub_remove(struct hid_device *hdev)
624401ca24fSsrinivas pandruvada {
625401ca24fSsrinivas pandruvada 	struct sensor_hub_data *data = hid_get_drvdata(hdev);
626401ca24fSsrinivas pandruvada 	unsigned long flags;
627401ca24fSsrinivas pandruvada 	int i;
628401ca24fSsrinivas pandruvada 
629401ca24fSsrinivas pandruvada 	hid_dbg(hdev, " hardware removed\n");
630401ca24fSsrinivas pandruvada 	hdev->claimed &= ~HID_CLAIMED_INPUT;
631401ca24fSsrinivas pandruvada 	hid_hw_stop(hdev);
632401ca24fSsrinivas pandruvada 	hid_hw_close(hdev);
633401ca24fSsrinivas pandruvada 	spin_lock_irqsave(&data->lock, flags);
634401ca24fSsrinivas pandruvada 	if (data->pending.status)
635401ca24fSsrinivas pandruvada 		complete(&data->pending.ready);
636401ca24fSsrinivas pandruvada 	spin_unlock_irqrestore(&data->lock, flags);
637401ca24fSsrinivas pandruvada 	mfd_remove_devices(&hdev->dev);
638401ca24fSsrinivas pandruvada 	for (i = 0; i < data->hid_sensor_client_cnt ; ++i)
639401ca24fSsrinivas pandruvada 		kfree(data->hid_sensor_hub_client_devs[i].name);
640401ca24fSsrinivas pandruvada 	kfree(data->hid_sensor_hub_client_devs);
641401ca24fSsrinivas pandruvada 	hid_set_drvdata(hdev, NULL);
642401ca24fSsrinivas pandruvada 	mutex_destroy(&data->mutex);
643401ca24fSsrinivas pandruvada 	kfree(data->hsdev);
644401ca24fSsrinivas pandruvada 	kfree(data);
645401ca24fSsrinivas pandruvada }
646401ca24fSsrinivas pandruvada 
647401ca24fSsrinivas pandruvada static const struct hid_device_id sensor_hub_devices[] = {
648401ca24fSsrinivas pandruvada 	{ HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8086,
649401ca24fSsrinivas pandruvada 			USB_DEVICE_ID_SENSOR_HUB_1020) },
650401ca24fSsrinivas pandruvada 	{ HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8087,
651401ca24fSsrinivas pandruvada 			USB_DEVICE_ID_SENSOR_HUB_1020) },
652401ca24fSsrinivas pandruvada 	{ HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8086,
653401ca24fSsrinivas pandruvada 			USB_DEVICE_ID_SENSOR_HUB_09FA) },
654401ca24fSsrinivas pandruvada 	{ HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8087,
655401ca24fSsrinivas pandruvada 			USB_DEVICE_ID_SENSOR_HUB_09FA) },
656401ca24fSsrinivas pandruvada 	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
657401ca24fSsrinivas pandruvada 			USB_DEVICE_ID_SENSOR_HUB_7014) },
658401ca24fSsrinivas pandruvada 	{ }
659401ca24fSsrinivas pandruvada };
660401ca24fSsrinivas pandruvada MODULE_DEVICE_TABLE(hid, sensor_hub_devices);
661401ca24fSsrinivas pandruvada 
662401ca24fSsrinivas pandruvada static const struct hid_usage_id sensor_hub_grabbed_usages[] = {
663401ca24fSsrinivas pandruvada 	{ HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
664401ca24fSsrinivas pandruvada 	{ HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1 }
665401ca24fSsrinivas pandruvada };
666401ca24fSsrinivas pandruvada 
667401ca24fSsrinivas pandruvada static struct hid_driver sensor_hub_driver = {
668401ca24fSsrinivas pandruvada 	.name = "hid-sensor-hub",
669401ca24fSsrinivas pandruvada 	.id_table = sensor_hub_devices,
670401ca24fSsrinivas pandruvada 	.probe = sensor_hub_probe,
671401ca24fSsrinivas pandruvada 	.remove = sensor_hub_remove,
672401ca24fSsrinivas pandruvada 	.raw_event = sensor_hub_raw_event,
673401ca24fSsrinivas pandruvada #ifdef CONFIG_PM
674401ca24fSsrinivas pandruvada 	.suspend = sensor_hub_suspend,
675401ca24fSsrinivas pandruvada 	.resume =  sensor_hub_resume,
676401ca24fSsrinivas pandruvada 	.reset_resume =  sensor_hub_reset_resume,
677401ca24fSsrinivas pandruvada #endif
678401ca24fSsrinivas pandruvada };
679401ca24fSsrinivas pandruvada 
680401ca24fSsrinivas pandruvada static int __init sensor_hub_init(void)
681401ca24fSsrinivas pandruvada {
682401ca24fSsrinivas pandruvada 	return hid_register_driver(&sensor_hub_driver);
683401ca24fSsrinivas pandruvada }
684401ca24fSsrinivas pandruvada 
685401ca24fSsrinivas pandruvada static void __exit sensor_hub_exit(void)
686401ca24fSsrinivas pandruvada {
687401ca24fSsrinivas pandruvada 	hid_unregister_driver(&sensor_hub_driver);
688401ca24fSsrinivas pandruvada }
689401ca24fSsrinivas pandruvada 
690401ca24fSsrinivas pandruvada module_init(sensor_hub_init);
691401ca24fSsrinivas pandruvada module_exit(sensor_hub_exit);
692401ca24fSsrinivas pandruvada 
693401ca24fSsrinivas pandruvada MODULE_DESCRIPTION("HID Sensor Hub driver");
694401ca24fSsrinivas pandruvada MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@intel.com>");
695401ca24fSsrinivas pandruvada MODULE_LICENSE("GPL");
696