hid-sensor-hub.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * HID Sensors Driver
  3. * Copyright (c) 2012, Intel Corporation.
  4. *
  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.
  8. *
  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
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. #include <linux/device.h>
  20. #include <linux/hid.h>
  21. #include <linux/usb.h>
  22. #include "usbhid/usbhid.h"
  23. #include <linux/module.h>
  24. #include <linux/slab.h>
  25. #include <linux/mfd/core.h>
  26. #include <linux/list.h>
  27. #include <linux/hid-sensor-ids.h>
  28. #include <linux/hid-sensor-hub.h>
  29. #include "hid-ids.h"
  30. /**
  31. * struct sensor_hub_pending - Synchronous read pending information
  32. * @status: Pending status true/false.
  33. * @ready: Completion synchronization data.
  34. * @usage_id: Usage id for physical device, E.g. Gyro usage id.
  35. * @attr_usage_id: Usage Id of a field, E.g. X-AXIS for a gyro.
  36. * @raw_size: Response size for a read request.
  37. * @raw_data: Place holder for received response.
  38. */
  39. struct sensor_hub_pending {
  40. bool status;
  41. struct completion ready;
  42. u32 usage_id;
  43. u32 attr_usage_id;
  44. int raw_size;
  45. u8 *raw_data;
  46. };
  47. /**
  48. * struct sensor_hub_data - Hold a instance data for a HID hub device
  49. * @hsdev: Stored hid instance for current hub device.
  50. * @mutex: Mutex to serialize synchronous request.
  51. * @lock: Spin lock to protect pending request structure.
  52. * @pending: Holds information of pending sync read request.
  53. * @dyn_callback_list: Holds callback function
  54. * @dyn_callback_lock: spin lock to protect callback list
  55. * @hid_sensor_hub_client_devs: Stores all MFD cells for a hub instance.
  56. * @hid_sensor_client_cnt: Number of MFD cells, (no of sensors attached).
  57. */
  58. struct sensor_hub_data {
  59. struct hid_sensor_hub_device *hsdev;
  60. struct mutex mutex;
  61. spinlock_t lock;
  62. struct sensor_hub_pending pending;
  63. struct list_head dyn_callback_list;
  64. spinlock_t dyn_callback_lock;
  65. struct mfd_cell *hid_sensor_hub_client_devs;
  66. int hid_sensor_client_cnt;
  67. };
  68. /**
  69. * struct hid_sensor_hub_callbacks_list - Stores callback list
  70. * @list: list head.
  71. * @usage_id: usage id for a physical device.
  72. * @usage_callback: Stores registered callback functions.
  73. * @priv: Private data for a physical device.
  74. */
  75. struct hid_sensor_hub_callbacks_list {
  76. struct list_head list;
  77. u32 usage_id;
  78. struct hid_sensor_hub_callbacks *usage_callback;
  79. void *priv;
  80. };
  81. static int sensor_hub_check_for_sensor_page(struct hid_device *hdev)
  82. {
  83. int i;
  84. int ret = -EINVAL;
  85. for (i = 0; i < hdev->maxcollection; i++) {
  86. struct hid_collection *col = &hdev->collection[i];
  87. if (col->type == HID_COLLECTION_PHYSICAL &&
  88. (col->usage & HID_USAGE_PAGE) == HID_UP_SENSOR) {
  89. ret = 0;
  90. break;
  91. }
  92. }
  93. return ret;
  94. }
  95. static struct hid_report *sensor_hub_report(int id, struct hid_device *hdev,
  96. int dir)
  97. {
  98. struct hid_report *report;
  99. list_for_each_entry(report, &hdev->report_enum[dir].report_list, list) {
  100. if (report->id == id)
  101. return report;
  102. }
  103. hid_warn(hdev, "No report with id 0x%x found\n", id);
  104. return NULL;
  105. }
  106. static int sensor_hub_get_physical_device_count(
  107. struct hid_report_enum *report_enum)
  108. {
  109. struct hid_report *report;
  110. struct hid_field *field;
  111. int cnt = 0;
  112. list_for_each_entry(report, &report_enum->report_list, list) {
  113. field = report->field[0];
  114. if (report->maxfield && field &&
  115. field->physical)
  116. cnt++;
  117. }
  118. return cnt;
  119. }
  120. static void sensor_hub_fill_attr_info(
  121. struct hid_sensor_hub_attribute_info *info,
  122. s32 index, s32 report_id, s32 units, s32 unit_expo, s32 size)
  123. {
  124. info->index = index;
  125. info->report_id = report_id;
  126. info->units = units;
  127. info->unit_expo = unit_expo;
  128. info->size = size/8;
  129. }
  130. static struct hid_sensor_hub_callbacks *sensor_hub_get_callback(
  131. struct hid_device *hdev,
  132. u32 usage_id, void **priv)
  133. {
  134. struct hid_sensor_hub_callbacks_list *callback;
  135. struct sensor_hub_data *pdata = hid_get_drvdata(hdev);
  136. spin_lock(&pdata->dyn_callback_lock);
  137. list_for_each_entry(callback, &pdata->dyn_callback_list, list)
  138. if (callback->usage_id == usage_id) {
  139. *priv = callback->priv;
  140. spin_unlock(&pdata->dyn_callback_lock);
  141. return callback->usage_callback;
  142. }
  143. spin_unlock(&pdata->dyn_callback_lock);
  144. return NULL;
  145. }
  146. int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
  147. u32 usage_id,
  148. struct hid_sensor_hub_callbacks *usage_callback)
  149. {
  150. struct hid_sensor_hub_callbacks_list *callback;
  151. struct sensor_hub_data *pdata = hid_get_drvdata(hsdev->hdev);
  152. spin_lock(&pdata->dyn_callback_lock);
  153. list_for_each_entry(callback, &pdata->dyn_callback_list, list)
  154. if (callback->usage_id == usage_id) {
  155. spin_unlock(&pdata->dyn_callback_lock);
  156. return -EINVAL;
  157. }
  158. callback = kzalloc(sizeof(*callback), GFP_ATOMIC);
  159. if (!callback) {
  160. spin_unlock(&pdata->dyn_callback_lock);
  161. return -ENOMEM;
  162. }
  163. callback->usage_callback = usage_callback;
  164. callback->usage_id = usage_id;
  165. callback->priv = NULL;
  166. list_add_tail(&callback->list, &pdata->dyn_callback_list);
  167. spin_unlock(&pdata->dyn_callback_lock);
  168. return 0;
  169. }
  170. EXPORT_SYMBOL_GPL(sensor_hub_register_callback);
  171. int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
  172. u32 usage_id)
  173. {
  174. struct hid_sensor_hub_callbacks_list *callback;
  175. struct sensor_hub_data *pdata = hid_get_drvdata(hsdev->hdev);
  176. spin_lock(&pdata->dyn_callback_lock);
  177. list_for_each_entry(callback, &pdata->dyn_callback_list, list)
  178. if (callback->usage_id == usage_id) {
  179. list_del(&callback->list);
  180. kfree(callback);
  181. break;
  182. }
  183. spin_unlock(&pdata->dyn_callback_lock);
  184. return 0;
  185. }
  186. EXPORT_SYMBOL_GPL(sensor_hub_remove_callback);
  187. int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
  188. u32 field_index, s32 value)
  189. {
  190. struct hid_report *report;
  191. struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
  192. int ret = 0;
  193. mutex_lock(&data->mutex);
  194. report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
  195. if (!report || (field_index >= report->maxfield)) {
  196. ret = -EINVAL;
  197. goto done_proc;
  198. }
  199. hid_set_field(report->field[field_index], 0, value);
  200. usbhid_submit_report(hsdev->hdev, report, USB_DIR_OUT);
  201. usbhid_wait_io(hsdev->hdev);
  202. done_proc:
  203. mutex_unlock(&data->mutex);
  204. return ret;
  205. }
  206. EXPORT_SYMBOL_GPL(sensor_hub_set_feature);
  207. int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
  208. u32 field_index, s32 *value)
  209. {
  210. struct hid_report *report;
  211. struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
  212. int ret = 0;
  213. mutex_lock(&data->mutex);
  214. report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
  215. if (!report || (field_index >= report->maxfield)) {
  216. ret = -EINVAL;
  217. goto done_proc;
  218. }
  219. usbhid_submit_report(hsdev->hdev, report, USB_DIR_IN);
  220. usbhid_wait_io(hsdev->hdev);
  221. *value = report->field[field_index]->value[0];
  222. done_proc:
  223. mutex_unlock(&data->mutex);
  224. return ret;
  225. }
  226. EXPORT_SYMBOL_GPL(sensor_hub_get_feature);
  227. int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
  228. u32 usage_id,
  229. u32 attr_usage_id, u32 report_id)
  230. {
  231. struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
  232. unsigned long flags;
  233. struct hid_report *report;
  234. int ret_val = 0;
  235. mutex_lock(&data->mutex);
  236. memset(&data->pending, 0, sizeof(data->pending));
  237. init_completion(&data->pending.ready);
  238. data->pending.usage_id = usage_id;
  239. data->pending.attr_usage_id = attr_usage_id;
  240. data->pending.raw_size = 0;
  241. spin_lock_irqsave(&data->lock, flags);
  242. data->pending.status = true;
  243. report = sensor_hub_report(report_id, hsdev->hdev, HID_INPUT_REPORT);
  244. if (!report) {
  245. spin_unlock_irqrestore(&data->lock, flags);
  246. goto err_free;
  247. }
  248. usbhid_submit_report(hsdev->hdev, report, USB_DIR_IN);
  249. spin_unlock_irqrestore(&data->lock, flags);
  250. wait_for_completion_interruptible_timeout(&data->pending.ready, HZ*5);
  251. switch (data->pending.raw_size) {
  252. case 1:
  253. ret_val = *(u8 *)data->pending.raw_data;
  254. break;
  255. case 2:
  256. ret_val = *(u16 *)data->pending.raw_data;
  257. break;
  258. case 4:
  259. ret_val = *(u32 *)data->pending.raw_data;
  260. break;
  261. default:
  262. ret_val = 0;
  263. }
  264. kfree(data->pending.raw_data);
  265. err_free:
  266. data->pending.status = false;
  267. mutex_unlock(&data->mutex);
  268. return ret_val;
  269. }
  270. EXPORT_SYMBOL_GPL(sensor_hub_input_attr_get_raw_value);
  271. int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
  272. u8 type,
  273. u32 usage_id,
  274. u32 attr_usage_id,
  275. struct hid_sensor_hub_attribute_info *info)
  276. {
  277. int ret = -1;
  278. int i, j;
  279. int collection_index = -1;
  280. struct hid_report *report;
  281. struct hid_field *field;
  282. struct hid_report_enum *report_enum;
  283. struct hid_device *hdev = hsdev->hdev;
  284. /* Initialize with defaults */
  285. info->usage_id = usage_id;
  286. info->attrib_id = attr_usage_id;
  287. info->report_id = -1;
  288. info->index = -1;
  289. info->units = -1;
  290. info->unit_expo = -1;
  291. for (i = 0; i < hdev->maxcollection; ++i) {
  292. struct hid_collection *collection = &hdev->collection[i];
  293. if (usage_id == collection->usage) {
  294. collection_index = i;
  295. break;
  296. }
  297. }
  298. if (collection_index == -1)
  299. goto err_ret;
  300. report_enum = &hdev->report_enum[type];
  301. list_for_each_entry(report, &report_enum->report_list, list) {
  302. for (i = 0; i < report->maxfield; ++i) {
  303. field = report->field[i];
  304. if (field->physical == usage_id &&
  305. field->logical == attr_usage_id) {
  306. sensor_hub_fill_attr_info(info, i, report->id,
  307. field->unit, field->unit_exponent,
  308. field->report_size);
  309. ret = 0;
  310. } else {
  311. for (j = 0; j < field->maxusage; ++j) {
  312. if (field->usage[j].hid ==
  313. attr_usage_id &&
  314. field->usage[j].collection_index ==
  315. collection_index) {
  316. sensor_hub_fill_attr_info(info,
  317. i, report->id,
  318. field->unit,
  319. field->unit_exponent,
  320. field->report_size);
  321. ret = 0;
  322. break;
  323. }
  324. }
  325. }
  326. if (ret == 0)
  327. break;
  328. }
  329. }
  330. err_ret:
  331. return ret;
  332. }
  333. EXPORT_SYMBOL_GPL(sensor_hub_input_get_attribute_info);
  334. #ifdef CONFIG_PM
  335. static int sensor_hub_suspend(struct hid_device *hdev, pm_message_t message)
  336. {
  337. struct sensor_hub_data *pdata = hid_get_drvdata(hdev);
  338. struct hid_sensor_hub_callbacks_list *callback;
  339. hid_dbg(hdev, " sensor_hub_suspend\n");
  340. spin_lock(&pdata->dyn_callback_lock);
  341. list_for_each_entry(callback, &pdata->dyn_callback_list, list) {
  342. if (callback->usage_callback->suspend)
  343. callback->usage_callback->suspend(
  344. pdata->hsdev, callback->priv);
  345. }
  346. spin_unlock(&pdata->dyn_callback_lock);
  347. return 0;
  348. }
  349. static int sensor_hub_resume(struct hid_device *hdev)
  350. {
  351. struct sensor_hub_data *pdata = hid_get_drvdata(hdev);
  352. struct hid_sensor_hub_callbacks_list *callback;
  353. hid_dbg(hdev, " sensor_hub_resume\n");
  354. spin_lock(&pdata->dyn_callback_lock);
  355. list_for_each_entry(callback, &pdata->dyn_callback_list, list) {
  356. if (callback->usage_callback->resume)
  357. callback->usage_callback->resume(
  358. pdata->hsdev, callback->priv);
  359. }
  360. spin_unlock(&pdata->dyn_callback_lock);
  361. return 0;
  362. }
  363. static int sensor_hub_reset_resume(struct hid_device *hdev)
  364. {
  365. return 0;
  366. }
  367. #endif
  368. /*
  369. * Handle raw report as sent by device
  370. */
  371. static int sensor_hub_raw_event(struct hid_device *hdev,
  372. struct hid_report *report, u8 *raw_data, int size)
  373. {
  374. int i;
  375. u8 *ptr;
  376. int sz;
  377. struct sensor_hub_data *pdata = hid_get_drvdata(hdev);
  378. unsigned long flags;
  379. struct hid_sensor_hub_callbacks *callback = NULL;
  380. struct hid_collection *collection = NULL;
  381. void *priv = NULL;
  382. hid_dbg(hdev, "sensor_hub_raw_event report id:0x%x size:%d type:%d\n",
  383. report->id, size, report->type);
  384. hid_dbg(hdev, "maxfield:%d\n", report->maxfield);
  385. if (report->type != HID_INPUT_REPORT)
  386. return 1;
  387. ptr = raw_data;
  388. ptr++; /*Skip report id*/
  389. if (!report)
  390. goto err_report;
  391. spin_lock_irqsave(&pdata->lock, flags);
  392. for (i = 0; i < report->maxfield; ++i) {
  393. hid_dbg(hdev, "%d collection_index:%x hid:%x sz:%x\n",
  394. i, report->field[i]->usage->collection_index,
  395. report->field[i]->usage->hid,
  396. report->field[i]->report_size/8);
  397. sz = report->field[i]->report_size/8;
  398. if (pdata->pending.status && pdata->pending.attr_usage_id ==
  399. report->field[i]->usage->hid) {
  400. hid_dbg(hdev, "data was pending ...\n");
  401. pdata->pending.raw_data = kmalloc(sz, GFP_ATOMIC);
  402. if (pdata->pending.raw_data) {
  403. memcpy(pdata->pending.raw_data, ptr, sz);
  404. pdata->pending.raw_size = sz;
  405. } else
  406. pdata->pending.raw_size = 0;
  407. complete(&pdata->pending.ready);
  408. }
  409. collection = &hdev->collection[
  410. report->field[i]->usage->collection_index];
  411. hid_dbg(hdev, "collection->usage %x\n",
  412. collection->usage);
  413. callback = sensor_hub_get_callback(pdata->hsdev->hdev,
  414. report->field[i]->physical,
  415. &priv);
  416. if (callback && callback->capture_sample) {
  417. if (report->field[i]->logical)
  418. callback->capture_sample(pdata->hsdev,
  419. report->field[i]->logical, sz, ptr,
  420. callback->pdev);
  421. else
  422. callback->capture_sample(pdata->hsdev,
  423. report->field[i]->usage->hid, sz, ptr,
  424. callback->pdev);
  425. }
  426. ptr += sz;
  427. }
  428. if (callback && collection && callback->send_event)
  429. callback->send_event(pdata->hsdev, collection->usage,
  430. callback->pdev);
  431. spin_unlock_irqrestore(&pdata->lock, flags);
  432. err_report:
  433. return 1;
  434. }
  435. static int sensor_hub_probe(struct hid_device *hdev,
  436. const struct hid_device_id *id)
  437. {
  438. int ret;
  439. struct sensor_hub_data *sd;
  440. int i;
  441. char *name;
  442. struct hid_report *report;
  443. struct hid_report_enum *report_enum;
  444. struct hid_field *field;
  445. int dev_cnt;
  446. sd = kzalloc(sizeof(struct sensor_hub_data), GFP_KERNEL);
  447. if (!sd) {
  448. hid_err(hdev, "cannot allocate Sensor data\n");
  449. return -ENOMEM;
  450. }
  451. sd->hsdev = kzalloc(sizeof(struct hid_sensor_hub_device), GFP_KERNEL);
  452. if (!sd->hsdev) {
  453. hid_err(hdev, "cannot allocate hid_sensor_hub_device\n");
  454. ret = -ENOMEM;
  455. goto err_free_hub;
  456. }
  457. hid_set_drvdata(hdev, sd);
  458. sd->hsdev->hdev = hdev;
  459. sd->hsdev->vendor_id = hdev->vendor;
  460. sd->hsdev->product_id = hdev->product;
  461. spin_lock_init(&sd->lock);
  462. spin_lock_init(&sd->dyn_callback_lock);
  463. mutex_init(&sd->mutex);
  464. ret = hid_parse(hdev);
  465. if (ret) {
  466. hid_err(hdev, "parse failed\n");
  467. goto err_free;
  468. }
  469. if (sensor_hub_check_for_sensor_page(hdev) < 0) {
  470. hid_err(hdev, "sensor page not found\n");
  471. goto err_free;
  472. }
  473. INIT_LIST_HEAD(&hdev->inputs);
  474. ret = hid_hw_start(hdev, 0);
  475. if (ret) {
  476. hid_err(hdev, "hw start failed\n");
  477. goto err_free;
  478. }
  479. ret = hid_hw_open(hdev);
  480. if (ret) {
  481. hid_err(hdev, "failed to open input interrupt pipe\n");
  482. goto err_stop_hw;
  483. }
  484. INIT_LIST_HEAD(&sd->dyn_callback_list);
  485. sd->hid_sensor_client_cnt = 0;
  486. report_enum = &hdev->report_enum[HID_INPUT_REPORT];
  487. dev_cnt = sensor_hub_get_physical_device_count(report_enum);
  488. if (dev_cnt > HID_MAX_PHY_DEVICES) {
  489. hid_err(hdev, "Invalid Physical device count\n");
  490. ret = -EINVAL;
  491. goto err_close;
  492. }
  493. sd->hid_sensor_hub_client_devs = kzalloc(dev_cnt *
  494. sizeof(struct mfd_cell),
  495. GFP_KERNEL);
  496. if (sd->hid_sensor_hub_client_devs == NULL) {
  497. hid_err(hdev, "Failed to allocate memory for mfd cells\n");
  498. ret = -ENOMEM;
  499. goto err_close;
  500. }
  501. list_for_each_entry(report, &report_enum->report_list, list) {
  502. hid_dbg(hdev, "Report id:%x\n", report->id);
  503. field = report->field[0];
  504. if (report->maxfield && field &&
  505. field->physical) {
  506. name = kasprintf(GFP_KERNEL, "HID-SENSOR-%x",
  507. field->physical);
  508. if (name == NULL) {
  509. hid_err(hdev, "Failed MFD device name\n");
  510. ret = -ENOMEM;
  511. goto err_free_names;
  512. }
  513. sd->hid_sensor_hub_client_devs[
  514. sd->hid_sensor_client_cnt].name = name;
  515. sd->hid_sensor_hub_client_devs[
  516. sd->hid_sensor_client_cnt].platform_data =
  517. sd->hsdev;
  518. sd->hid_sensor_hub_client_devs[
  519. sd->hid_sensor_client_cnt].pdata_size =
  520. sizeof(*sd->hsdev);
  521. hid_dbg(hdev, "Adding %s:%p\n", name, sd);
  522. sd->hid_sensor_client_cnt++;
  523. }
  524. }
  525. ret = mfd_add_devices(&hdev->dev, 0, sd->hid_sensor_hub_client_devs,
  526. sd->hid_sensor_client_cnt, NULL, 0, NULL);
  527. if (ret < 0)
  528. goto err_free_names;
  529. return ret;
  530. err_free_names:
  531. for (i = 0; i < sd->hid_sensor_client_cnt ; ++i)
  532. kfree(sd->hid_sensor_hub_client_devs[i].name);
  533. kfree(sd->hid_sensor_hub_client_devs);
  534. err_close:
  535. hid_hw_close(hdev);
  536. err_stop_hw:
  537. hid_hw_stop(hdev);
  538. err_free:
  539. kfree(sd->hsdev);
  540. err_free_hub:
  541. kfree(sd);
  542. return ret;
  543. }
  544. static void sensor_hub_remove(struct hid_device *hdev)
  545. {
  546. struct sensor_hub_data *data = hid_get_drvdata(hdev);
  547. unsigned long flags;
  548. int i;
  549. hid_dbg(hdev, " hardware removed\n");
  550. hid_hw_close(hdev);
  551. hid_hw_stop(hdev);
  552. spin_lock_irqsave(&data->lock, flags);
  553. if (data->pending.status)
  554. complete(&data->pending.ready);
  555. spin_unlock_irqrestore(&data->lock, flags);
  556. mfd_remove_devices(&hdev->dev);
  557. for (i = 0; i < data->hid_sensor_client_cnt ; ++i)
  558. kfree(data->hid_sensor_hub_client_devs[i].name);
  559. kfree(data->hid_sensor_hub_client_devs);
  560. hid_set_drvdata(hdev, NULL);
  561. mutex_destroy(&data->mutex);
  562. kfree(data->hsdev);
  563. kfree(data);
  564. }
  565. static const struct hid_device_id sensor_hub_devices[] = {
  566. { HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8086,
  567. USB_DEVICE_ID_SENSOR_HUB_1020) },
  568. { HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8087,
  569. USB_DEVICE_ID_SENSOR_HUB_1020) },
  570. { HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8086,
  571. USB_DEVICE_ID_SENSOR_HUB_09FA) },
  572. { HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8087,
  573. USB_DEVICE_ID_SENSOR_HUB_09FA) },
  574. { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
  575. USB_DEVICE_ID_SENSOR_HUB_7014) },
  576. { }
  577. };
  578. MODULE_DEVICE_TABLE(hid, sensor_hub_devices);
  579. static const struct hid_usage_id sensor_hub_grabbed_usages[] = {
  580. { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
  581. { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1 }
  582. };
  583. static struct hid_driver sensor_hub_driver = {
  584. .name = "hid-sensor-hub",
  585. .id_table = sensor_hub_devices,
  586. .probe = sensor_hub_probe,
  587. .remove = sensor_hub_remove,
  588. .raw_event = sensor_hub_raw_event,
  589. #ifdef CONFIG_PM
  590. .suspend = sensor_hub_suspend,
  591. .resume = sensor_hub_resume,
  592. .reset_resume = sensor_hub_reset_resume,
  593. #endif
  594. };
  595. static int __init sensor_hub_init(void)
  596. {
  597. return hid_register_driver(&sensor_hub_driver);
  598. }
  599. static void __exit sensor_hub_exit(void)
  600. {
  601. hid_unregister_driver(&sensor_hub_driver);
  602. }
  603. module_init(sensor_hub_init);
  604. module_exit(sensor_hub_exit);
  605. MODULE_DESCRIPTION("HID Sensor Hub driver");
  606. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@intel.com>");
  607. MODULE_LICENSE("GPL");