hid-sensor-hub.c 18 KB

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