hid-sensor-hub.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. spin_lock_irqsave(&pdata->lock, flags);
  390. for (i = 0; i < report->maxfield; ++i) {
  391. hid_dbg(hdev, "%d collection_index:%x hid:%x sz:%x\n",
  392. i, report->field[i]->usage->collection_index,
  393. report->field[i]->usage->hid,
  394. report->field[i]->report_size/8);
  395. sz = report->field[i]->report_size/8;
  396. if (pdata->pending.status && pdata->pending.attr_usage_id ==
  397. report->field[i]->usage->hid) {
  398. hid_dbg(hdev, "data was pending ...\n");
  399. pdata->pending.raw_data = kmalloc(sz, GFP_ATOMIC);
  400. if (pdata->pending.raw_data) {
  401. memcpy(pdata->pending.raw_data, ptr, sz);
  402. pdata->pending.raw_size = sz;
  403. } else
  404. pdata->pending.raw_size = 0;
  405. complete(&pdata->pending.ready);
  406. }
  407. collection = &hdev->collection[
  408. report->field[i]->usage->collection_index];
  409. hid_dbg(hdev, "collection->usage %x\n",
  410. collection->usage);
  411. callback = sensor_hub_get_callback(pdata->hsdev->hdev,
  412. report->field[i]->physical,
  413. &priv);
  414. if (callback && callback->capture_sample) {
  415. if (report->field[i]->logical)
  416. callback->capture_sample(pdata->hsdev,
  417. report->field[i]->logical, sz, ptr,
  418. callback->pdev);
  419. else
  420. callback->capture_sample(pdata->hsdev,
  421. report->field[i]->usage->hid, sz, ptr,
  422. callback->pdev);
  423. }
  424. ptr += sz;
  425. }
  426. if (callback && collection && callback->send_event)
  427. callback->send_event(pdata->hsdev, collection->usage,
  428. callback->pdev);
  429. spin_unlock_irqrestore(&pdata->lock, flags);
  430. return 1;
  431. }
  432. static int sensor_hub_probe(struct hid_device *hdev,
  433. const struct hid_device_id *id)
  434. {
  435. int ret;
  436. struct sensor_hub_data *sd;
  437. int i;
  438. char *name;
  439. struct hid_report *report;
  440. struct hid_report_enum *report_enum;
  441. struct hid_field *field;
  442. int dev_cnt;
  443. sd = kzalloc(sizeof(struct sensor_hub_data), GFP_KERNEL);
  444. if (!sd) {
  445. hid_err(hdev, "cannot allocate Sensor data\n");
  446. return -ENOMEM;
  447. }
  448. sd->hsdev = kzalloc(sizeof(struct hid_sensor_hub_device), GFP_KERNEL);
  449. if (!sd->hsdev) {
  450. hid_err(hdev, "cannot allocate hid_sensor_hub_device\n");
  451. ret = -ENOMEM;
  452. goto err_free_hub;
  453. }
  454. hid_set_drvdata(hdev, sd);
  455. sd->hsdev->hdev = hdev;
  456. sd->hsdev->vendor_id = hdev->vendor;
  457. sd->hsdev->product_id = hdev->product;
  458. spin_lock_init(&sd->lock);
  459. spin_lock_init(&sd->dyn_callback_lock);
  460. mutex_init(&sd->mutex);
  461. ret = hid_parse(hdev);
  462. if (ret) {
  463. hid_err(hdev, "parse failed\n");
  464. goto err_free;
  465. }
  466. if (sensor_hub_check_for_sensor_page(hdev) < 0) {
  467. hid_err(hdev, "sensor page not found\n");
  468. goto err_free;
  469. }
  470. INIT_LIST_HEAD(&hdev->inputs);
  471. ret = hid_hw_start(hdev, 0);
  472. if (ret) {
  473. hid_err(hdev, "hw start failed\n");
  474. goto err_free;
  475. }
  476. ret = hid_hw_open(hdev);
  477. if (ret) {
  478. hid_err(hdev, "failed to open input interrupt pipe\n");
  479. goto err_stop_hw;
  480. }
  481. INIT_LIST_HEAD(&sd->dyn_callback_list);
  482. sd->hid_sensor_client_cnt = 0;
  483. report_enum = &hdev->report_enum[HID_INPUT_REPORT];
  484. dev_cnt = sensor_hub_get_physical_device_count(report_enum);
  485. if (dev_cnt > HID_MAX_PHY_DEVICES) {
  486. hid_err(hdev, "Invalid Physical device count\n");
  487. ret = -EINVAL;
  488. goto err_close;
  489. }
  490. sd->hid_sensor_hub_client_devs = kzalloc(dev_cnt *
  491. sizeof(struct mfd_cell),
  492. GFP_KERNEL);
  493. if (sd->hid_sensor_hub_client_devs == NULL) {
  494. hid_err(hdev, "Failed to allocate memory for mfd cells\n");
  495. ret = -ENOMEM;
  496. goto err_close;
  497. }
  498. list_for_each_entry(report, &report_enum->report_list, list) {
  499. hid_dbg(hdev, "Report id:%x\n", report->id);
  500. field = report->field[0];
  501. if (report->maxfield && field &&
  502. field->physical) {
  503. name = kasprintf(GFP_KERNEL, "HID-SENSOR-%x",
  504. field->physical);
  505. if (name == NULL) {
  506. hid_err(hdev, "Failed MFD device name\n");
  507. ret = -ENOMEM;
  508. goto err_free_names;
  509. }
  510. sd->hid_sensor_hub_client_devs[
  511. sd->hid_sensor_client_cnt].name = name;
  512. sd->hid_sensor_hub_client_devs[
  513. sd->hid_sensor_client_cnt].platform_data =
  514. sd->hsdev;
  515. sd->hid_sensor_hub_client_devs[
  516. sd->hid_sensor_client_cnt].pdata_size =
  517. sizeof(*sd->hsdev);
  518. hid_dbg(hdev, "Adding %s:%p\n", name, sd);
  519. sd->hid_sensor_client_cnt++;
  520. }
  521. }
  522. ret = mfd_add_devices(&hdev->dev, 0, sd->hid_sensor_hub_client_devs,
  523. sd->hid_sensor_client_cnt, NULL, 0, NULL);
  524. if (ret < 0)
  525. goto err_free_names;
  526. return ret;
  527. err_free_names:
  528. for (i = 0; i < sd->hid_sensor_client_cnt ; ++i)
  529. kfree(sd->hid_sensor_hub_client_devs[i].name);
  530. kfree(sd->hid_sensor_hub_client_devs);
  531. err_close:
  532. hid_hw_close(hdev);
  533. err_stop_hw:
  534. hid_hw_stop(hdev);
  535. err_free:
  536. kfree(sd->hsdev);
  537. err_free_hub:
  538. kfree(sd);
  539. return ret;
  540. }
  541. static void sensor_hub_remove(struct hid_device *hdev)
  542. {
  543. struct sensor_hub_data *data = hid_get_drvdata(hdev);
  544. unsigned long flags;
  545. int i;
  546. hid_dbg(hdev, " hardware removed\n");
  547. hid_hw_close(hdev);
  548. hid_hw_stop(hdev);
  549. spin_lock_irqsave(&data->lock, flags);
  550. if (data->pending.status)
  551. complete(&data->pending.ready);
  552. spin_unlock_irqrestore(&data->lock, flags);
  553. mfd_remove_devices(&hdev->dev);
  554. for (i = 0; i < data->hid_sensor_client_cnt ; ++i)
  555. kfree(data->hid_sensor_hub_client_devs[i].name);
  556. kfree(data->hid_sensor_hub_client_devs);
  557. hid_set_drvdata(hdev, NULL);
  558. mutex_destroy(&data->mutex);
  559. kfree(data->hsdev);
  560. kfree(data);
  561. }
  562. static const struct hid_device_id sensor_hub_devices[] = {
  563. { HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8086,
  564. USB_DEVICE_ID_SENSOR_HUB_1020) },
  565. { HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8087,
  566. USB_DEVICE_ID_SENSOR_HUB_1020) },
  567. { HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8086,
  568. USB_DEVICE_ID_SENSOR_HUB_09FA) },
  569. { HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8087,
  570. USB_DEVICE_ID_SENSOR_HUB_09FA) },
  571. { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
  572. USB_DEVICE_ID_SENSOR_HUB_7014) },
  573. { }
  574. };
  575. MODULE_DEVICE_TABLE(hid, sensor_hub_devices);
  576. static const struct hid_usage_id sensor_hub_grabbed_usages[] = {
  577. { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
  578. { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1 }
  579. };
  580. static struct hid_driver sensor_hub_driver = {
  581. .name = "hid-sensor-hub",
  582. .id_table = sensor_hub_devices,
  583. .probe = sensor_hub_probe,
  584. .remove = sensor_hub_remove,
  585. .raw_event = sensor_hub_raw_event,
  586. #ifdef CONFIG_PM
  587. .suspend = sensor_hub_suspend,
  588. .resume = sensor_hub_resume,
  589. .reset_resume = sensor_hub_reset_resume,
  590. #endif
  591. };
  592. static int __init sensor_hub_init(void)
  593. {
  594. return hid_register_driver(&sensor_hub_driver);
  595. }
  596. static void __exit sensor_hub_exit(void)
  597. {
  598. hid_unregister_driver(&sensor_hub_driver);
  599. }
  600. module_init(sensor_hub_init);
  601. module_exit(sensor_hub_exit);
  602. MODULE_DESCRIPTION("HID Sensor Hub driver");
  603. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@intel.com>");
  604. MODULE_LICENSE("GPL");