ishtp_eclite.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Intel ECLite opregion driver for talking to ECLite firmware running on
  4. * Intel Integrated Sensor Hub (ISH) using ISH Transport Protocol (ISHTP)
  5. *
  6. * Copyright (c) 2021, Intel Corporation.
  7. */
  8. #include <linux/acpi.h>
  9. #include <linux/bitops.h>
  10. #include <linux/device.h>
  11. #include <linux/errno.h>
  12. #include <linux/intel-ish-client-if.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/mutex.h>
  16. #include <linux/slab.h>
  17. #include <linux/suspend.h>
  18. #include <linux/types.h>
  19. #include <linux/uuid.h>
  20. #include <linux/uaccess.h>
  21. #define ECLITE_DATA_OPREGION_ID 0x9E
  22. #define ECLITE_CMD_OPREGION_ID 0x9F
  23. #define ECL_MSG_DATA 0x1
  24. #define ECL_MSG_EVENT 0x2
  25. #define ECL_ISH_READ 0x1
  26. #define ECL_ISH_WRITE 0x2
  27. #define ECL_ISH_HEADER_VERSION 0
  28. #define ECL_CL_RX_RING_SIZE 16
  29. #define ECL_CL_TX_RING_SIZE 8
  30. #define ECL_DATA_OPR_BUFLEN 384
  31. #define ECL_EVENTS_NOTIFY 333
  32. #define cmd_opr_offsetof(element) offsetof(struct opregion_cmd, element)
  33. #define cl_data_to_dev(opr_dev) ishtp_device((opr_dev)->cl_device)
  34. #ifndef BITS_TO_BYTES
  35. #define BITS_TO_BYTES(x) ((x) / 8)
  36. #endif
  37. struct opregion_cmd {
  38. unsigned int command;
  39. unsigned int offset;
  40. unsigned int length;
  41. unsigned int event_id;
  42. };
  43. struct opregion_data {
  44. char data[ECL_DATA_OPR_BUFLEN];
  45. };
  46. struct opregion_context {
  47. struct opregion_cmd cmd_area;
  48. struct opregion_data data_area;
  49. };
  50. struct ecl_message_header {
  51. unsigned int version:2;
  52. unsigned int data_type:2;
  53. unsigned int request_type:2;
  54. unsigned int offset:9;
  55. unsigned int data_len:9;
  56. unsigned int event:8;
  57. };
  58. struct ecl_message {
  59. struct ecl_message_header header;
  60. char payload[ECL_DATA_OPR_BUFLEN];
  61. };
  62. struct ishtp_opregion_dev {
  63. struct opregion_context opr_context;
  64. struct ishtp_cl *ecl_ishtp_cl;
  65. struct ishtp_cl_device *cl_device;
  66. struct ishtp_fw_client *fw_client;
  67. struct ishtp_cl_rb *rb;
  68. struct acpi_device *adev;
  69. unsigned int dsm_event_id;
  70. unsigned int ish_link_ready;
  71. unsigned int ish_read_done;
  72. unsigned int acpi_init_done;
  73. wait_queue_head_t read_wait;
  74. struct work_struct event_work;
  75. struct work_struct reset_work;
  76. /* lock for opregion context */
  77. struct mutex lock;
  78. };
  79. /* eclite ishtp client UUID: 6a19cc4b-d760-4de3-b14d-f25ebd0fbcd9 */
  80. static const struct ishtp_device_id ecl_ishtp_id_table[] = {
  81. { .guid = GUID_INIT(0x6a19cc4b, 0xd760, 0x4de3,
  82. 0xb1, 0x4d, 0xf2, 0x5e, 0xbd, 0xf, 0xbc, 0xd9), },
  83. { }
  84. };
  85. MODULE_DEVICE_TABLE(ishtp, ecl_ishtp_id_table);
  86. /* ACPI DSM UUID: 91d936a7-1f01-49c6-a6b4-72f00ad8d8a5 */
  87. static const guid_t ecl_acpi_guid =
  88. GUID_INIT(0x91d936a7, 0x1f01, 0x49c6, 0xa6,
  89. 0xb4, 0x72, 0xf0, 0x0a, 0xd8, 0xd8, 0xa5);
  90. /**
  91. * ecl_ish_cl_read() - Read data from eclite FW
  92. *
  93. * @opr_dev: pointer to opregion device
  94. *
  95. * This function issues a read request to eclite FW and waits until it
  96. * receives a response. When response is received the read data is copied to
  97. * opregion buffer.
  98. */
  99. static int ecl_ish_cl_read(struct ishtp_opregion_dev *opr_dev)
  100. {
  101. struct ecl_message_header header;
  102. int len, rv;
  103. if (!opr_dev->ish_link_ready)
  104. return -EIO;
  105. if ((opr_dev->opr_context.cmd_area.offset +
  106. opr_dev->opr_context.cmd_area.length) > ECL_DATA_OPR_BUFLEN) {
  107. return -EINVAL;
  108. }
  109. header.version = ECL_ISH_HEADER_VERSION;
  110. header.data_type = ECL_MSG_DATA;
  111. header.request_type = ECL_ISH_READ;
  112. header.offset = opr_dev->opr_context.cmd_area.offset;
  113. header.data_len = opr_dev->opr_context.cmd_area.length;
  114. header.event = opr_dev->opr_context.cmd_area.event_id;
  115. len = sizeof(header);
  116. opr_dev->ish_read_done = false;
  117. rv = ishtp_cl_send(opr_dev->ecl_ishtp_cl, (uint8_t *)&header, len);
  118. if (rv) {
  119. dev_err(cl_data_to_dev(opr_dev), "ish-read : send failed\n");
  120. return -EIO;
  121. }
  122. dev_dbg(cl_data_to_dev(opr_dev),
  123. "[ish_rd] Req: off : %x, len : %x\n",
  124. header.offset,
  125. header.data_len);
  126. rv = wait_event_interruptible_timeout(opr_dev->read_wait,
  127. opr_dev->ish_read_done,
  128. 2 * HZ);
  129. if (!rv) {
  130. dev_err(cl_data_to_dev(opr_dev),
  131. "[ish_rd] No response from firmware\n");
  132. return -EIO;
  133. }
  134. return 0;
  135. }
  136. /**
  137. * ecl_ish_cl_write() - This function writes data to eclite FW.
  138. *
  139. * @opr_dev: pointer to opregion device
  140. *
  141. * This function writes data to eclite FW.
  142. */
  143. static int ecl_ish_cl_write(struct ishtp_opregion_dev *opr_dev)
  144. {
  145. struct ecl_message message;
  146. int len;
  147. if (!opr_dev->ish_link_ready)
  148. return -EIO;
  149. if ((opr_dev->opr_context.cmd_area.offset +
  150. opr_dev->opr_context.cmd_area.length) > ECL_DATA_OPR_BUFLEN) {
  151. return -EINVAL;
  152. }
  153. message.header.version = ECL_ISH_HEADER_VERSION;
  154. message.header.data_type = ECL_MSG_DATA;
  155. message.header.request_type = ECL_ISH_WRITE;
  156. message.header.offset = opr_dev->opr_context.cmd_area.offset;
  157. message.header.data_len = opr_dev->opr_context.cmd_area.length;
  158. message.header.event = opr_dev->opr_context.cmd_area.event_id;
  159. len = sizeof(struct ecl_message_header) + message.header.data_len;
  160. memcpy(message.payload,
  161. opr_dev->opr_context.data_area.data + message.header.offset,
  162. message.header.data_len);
  163. dev_dbg(cl_data_to_dev(opr_dev),
  164. "[ish_wr] off : %x, len : %x\n",
  165. message.header.offset,
  166. message.header.data_len);
  167. return ishtp_cl_send(opr_dev->ecl_ishtp_cl, (uint8_t *)&message, len);
  168. }
  169. static acpi_status
  170. ecl_opregion_cmd_handler(u32 function, acpi_physical_address address,
  171. u32 bits, u64 *value64,
  172. void *handler_context, void *region_context)
  173. {
  174. struct ishtp_opregion_dev *opr_dev;
  175. struct opregion_cmd *cmd;
  176. acpi_status status = AE_OK;
  177. if (!region_context || !value64)
  178. return AE_BAD_PARAMETER;
  179. if (function == ACPI_READ)
  180. return AE_ERROR;
  181. opr_dev = (struct ishtp_opregion_dev *)region_context;
  182. mutex_lock(&opr_dev->lock);
  183. cmd = &opr_dev->opr_context.cmd_area;
  184. switch (address) {
  185. case cmd_opr_offsetof(command):
  186. cmd->command = (u32)*value64;
  187. if (cmd->command == ECL_ISH_READ)
  188. status = ecl_ish_cl_read(opr_dev);
  189. else if (cmd->command == ECL_ISH_WRITE)
  190. status = ecl_ish_cl_write(opr_dev);
  191. else
  192. status = AE_ERROR;
  193. break;
  194. case cmd_opr_offsetof(offset):
  195. cmd->offset = (u32)*value64;
  196. break;
  197. case cmd_opr_offsetof(length):
  198. cmd->length = (u32)*value64;
  199. break;
  200. case cmd_opr_offsetof(event_id):
  201. cmd->event_id = (u32)*value64;
  202. break;
  203. default:
  204. status = AE_ERROR;
  205. }
  206. mutex_unlock(&opr_dev->lock);
  207. return status;
  208. }
  209. static acpi_status
  210. ecl_opregion_data_handler(u32 function, acpi_physical_address address,
  211. u32 bits, u64 *value64,
  212. void *handler_context, void *region_context)
  213. {
  214. struct ishtp_opregion_dev *opr_dev;
  215. unsigned int bytes = BITS_TO_BYTES(bits);
  216. void *data_addr;
  217. if (!region_context || !value64)
  218. return AE_BAD_PARAMETER;
  219. if (address + bytes > ECL_DATA_OPR_BUFLEN)
  220. return AE_BAD_PARAMETER;
  221. opr_dev = (struct ishtp_opregion_dev *)region_context;
  222. mutex_lock(&opr_dev->lock);
  223. data_addr = &opr_dev->opr_context.data_area.data[address];
  224. if (function == ACPI_READ) {
  225. memcpy(value64, data_addr, bytes);
  226. } else if (function == ACPI_WRITE) {
  227. memcpy(data_addr, value64, bytes);
  228. } else {
  229. mutex_unlock(&opr_dev->lock);
  230. return AE_BAD_PARAMETER;
  231. }
  232. mutex_unlock(&opr_dev->lock);
  233. return AE_OK;
  234. }
  235. static int acpi_find_eclite_device(struct ishtp_opregion_dev *opr_dev)
  236. {
  237. struct acpi_device *adev;
  238. /* Find ECLite device and save reference */
  239. adev = acpi_dev_get_first_match_dev("INTC1035", NULL, -1);
  240. if (!adev) {
  241. dev_err(cl_data_to_dev(opr_dev), "eclite ACPI device not found\n");
  242. return -ENODEV;
  243. }
  244. opr_dev->adev = adev;
  245. return 0;
  246. }
  247. static int acpi_opregion_init(struct ishtp_opregion_dev *opr_dev)
  248. {
  249. acpi_status status;
  250. status = acpi_install_address_space_handler(opr_dev->adev->handle,
  251. ECLITE_CMD_OPREGION_ID,
  252. ecl_opregion_cmd_handler,
  253. NULL, opr_dev);
  254. if (ACPI_FAILURE(status)) {
  255. dev_err(cl_data_to_dev(opr_dev),
  256. "cmd space handler install failed\n");
  257. return -ENODEV;
  258. }
  259. status = acpi_install_address_space_handler(opr_dev->adev->handle,
  260. ECLITE_DATA_OPREGION_ID,
  261. ecl_opregion_data_handler,
  262. NULL, opr_dev);
  263. if (ACPI_FAILURE(status)) {
  264. dev_err(cl_data_to_dev(opr_dev),
  265. "data space handler install failed\n");
  266. acpi_remove_address_space_handler(opr_dev->adev->handle,
  267. ECLITE_CMD_OPREGION_ID,
  268. ecl_opregion_cmd_handler);
  269. return -ENODEV;
  270. }
  271. opr_dev->acpi_init_done = true;
  272. dev_dbg(cl_data_to_dev(opr_dev), "Opregion handlers are installed\n");
  273. return 0;
  274. }
  275. static void acpi_opregion_deinit(struct ishtp_opregion_dev *opr_dev)
  276. {
  277. acpi_remove_address_space_handler(opr_dev->adev->handle,
  278. ECLITE_CMD_OPREGION_ID,
  279. ecl_opregion_cmd_handler);
  280. acpi_remove_address_space_handler(opr_dev->adev->handle,
  281. ECLITE_DATA_OPREGION_ID,
  282. ecl_opregion_data_handler);
  283. opr_dev->acpi_init_done = false;
  284. }
  285. static void ecl_acpi_invoke_dsm(struct work_struct *work)
  286. {
  287. struct ishtp_opregion_dev *opr_dev;
  288. union acpi_object *obj;
  289. opr_dev = container_of(work, struct ishtp_opregion_dev, event_work);
  290. if (!opr_dev->acpi_init_done)
  291. return;
  292. obj = acpi_evaluate_dsm(opr_dev->adev->handle, &ecl_acpi_guid, 0,
  293. opr_dev->dsm_event_id, NULL);
  294. if (!obj) {
  295. dev_warn(cl_data_to_dev(opr_dev), "_DSM fn call failed\n");
  296. return;
  297. }
  298. dev_dbg(cl_data_to_dev(opr_dev), "Exec DSM function code: %d success\n",
  299. opr_dev->dsm_event_id);
  300. ACPI_FREE(obj);
  301. }
  302. static void ecl_ish_process_rx_data(struct ishtp_opregion_dev *opr_dev)
  303. {
  304. struct ecl_message *message =
  305. (struct ecl_message *)opr_dev->rb->buffer.data;
  306. dev_dbg(cl_data_to_dev(opr_dev),
  307. "[ish_rd] Resp: off : %x, len : %x\n",
  308. message->header.offset,
  309. message->header.data_len);
  310. if ((message->header.offset + message->header.data_len) >
  311. ECL_DATA_OPR_BUFLEN) {
  312. return;
  313. }
  314. memcpy(opr_dev->opr_context.data_area.data + message->header.offset,
  315. message->payload, message->header.data_len);
  316. opr_dev->ish_read_done = true;
  317. wake_up_interruptible(&opr_dev->read_wait);
  318. }
  319. static void ecl_ish_process_rx_event(struct ishtp_opregion_dev *opr_dev)
  320. {
  321. struct ecl_message_header *header =
  322. (struct ecl_message_header *)opr_dev->rb->buffer.data;
  323. dev_dbg(cl_data_to_dev(opr_dev),
  324. "[ish_ev] Evt received: %8x\n", header->event);
  325. opr_dev->dsm_event_id = header->event;
  326. schedule_work(&opr_dev->event_work);
  327. }
  328. static int ecl_ish_cl_enable_events(struct ishtp_opregion_dev *opr_dev,
  329. bool config_enable)
  330. {
  331. struct ecl_message message;
  332. int len;
  333. message.header.version = ECL_ISH_HEADER_VERSION;
  334. message.header.data_type = ECL_MSG_DATA;
  335. message.header.request_type = ECL_ISH_WRITE;
  336. message.header.offset = ECL_EVENTS_NOTIFY;
  337. message.header.data_len = 1;
  338. message.payload[0] = config_enable;
  339. len = sizeof(struct ecl_message_header) + message.header.data_len;
  340. return ishtp_cl_send(opr_dev->ecl_ishtp_cl, (uint8_t *)&message, len);
  341. }
  342. static void ecl_ishtp_cl_event_cb(struct ishtp_cl_device *cl_device)
  343. {
  344. struct ishtp_cl *ecl_ishtp_cl = ishtp_get_drvdata(cl_device);
  345. struct ishtp_opregion_dev *opr_dev;
  346. struct ecl_message_header *header;
  347. struct ishtp_cl_rb *rb;
  348. opr_dev = ishtp_get_client_data(ecl_ishtp_cl);
  349. while ((rb = ishtp_cl_rx_get_rb(opr_dev->ecl_ishtp_cl)) != NULL) {
  350. opr_dev->rb = rb;
  351. header = (struct ecl_message_header *)rb->buffer.data;
  352. if (header->data_type == ECL_MSG_DATA)
  353. ecl_ish_process_rx_data(opr_dev);
  354. else if (header->data_type == ECL_MSG_EVENT)
  355. ecl_ish_process_rx_event(opr_dev);
  356. else
  357. /* Got an event with wrong data_type, ignore it */
  358. dev_err(cl_data_to_dev(opr_dev),
  359. "[ish_cb] Received wrong data_type\n");
  360. ishtp_cl_io_rb_recycle(rb);
  361. }
  362. }
  363. static int ecl_ishtp_cl_init(struct ishtp_cl *ecl_ishtp_cl)
  364. {
  365. struct ishtp_opregion_dev *opr_dev =
  366. ishtp_get_client_data(ecl_ishtp_cl);
  367. struct ishtp_fw_client *fw_client;
  368. struct ishtp_device *dev;
  369. int rv;
  370. rv = ishtp_cl_link(ecl_ishtp_cl);
  371. if (rv) {
  372. dev_err(cl_data_to_dev(opr_dev), "ishtp_cl_link failed\n");
  373. return rv;
  374. }
  375. dev = ishtp_get_ishtp_device(ecl_ishtp_cl);
  376. /* Connect to FW client */
  377. ishtp_set_tx_ring_size(ecl_ishtp_cl, ECL_CL_TX_RING_SIZE);
  378. ishtp_set_rx_ring_size(ecl_ishtp_cl, ECL_CL_RX_RING_SIZE);
  379. fw_client = ishtp_fw_cl_get_client(dev, &ecl_ishtp_id_table[0].guid);
  380. if (!fw_client) {
  381. dev_err(cl_data_to_dev(opr_dev), "fw client not found\n");
  382. return -ENOENT;
  383. }
  384. ishtp_cl_set_fw_client_id(ecl_ishtp_cl,
  385. ishtp_get_fw_client_id(fw_client));
  386. ishtp_set_connection_state(ecl_ishtp_cl, ISHTP_CL_CONNECTING);
  387. rv = ishtp_cl_connect(ecl_ishtp_cl);
  388. if (rv) {
  389. dev_err(cl_data_to_dev(opr_dev), "client connect failed\n");
  390. ishtp_cl_unlink(ecl_ishtp_cl);
  391. return rv;
  392. }
  393. dev_dbg(cl_data_to_dev(opr_dev), "Host connected to fw client\n");
  394. return 0;
  395. }
  396. static void ecl_ishtp_cl_deinit(struct ishtp_cl *ecl_ishtp_cl)
  397. {
  398. ishtp_cl_unlink(ecl_ishtp_cl);
  399. ishtp_cl_flush_queues(ecl_ishtp_cl);
  400. ishtp_cl_free(ecl_ishtp_cl);
  401. }
  402. static void ecl_ishtp_cl_reset_handler(struct work_struct *work)
  403. {
  404. struct ishtp_opregion_dev *opr_dev;
  405. struct ishtp_cl_device *cl_device;
  406. struct ishtp_cl *ecl_ishtp_cl;
  407. int rv;
  408. int retry;
  409. opr_dev = container_of(work, struct ishtp_opregion_dev, reset_work);
  410. opr_dev->ish_link_ready = false;
  411. cl_device = opr_dev->cl_device;
  412. ecl_ishtp_cl = opr_dev->ecl_ishtp_cl;
  413. ecl_ishtp_cl_deinit(ecl_ishtp_cl);
  414. ecl_ishtp_cl = ishtp_cl_allocate(cl_device);
  415. if (!ecl_ishtp_cl)
  416. return;
  417. ishtp_set_drvdata(cl_device, ecl_ishtp_cl);
  418. ishtp_set_client_data(ecl_ishtp_cl, opr_dev);
  419. opr_dev->ecl_ishtp_cl = ecl_ishtp_cl;
  420. for (retry = 0; retry < 3; ++retry) {
  421. rv = ecl_ishtp_cl_init(ecl_ishtp_cl);
  422. if (!rv)
  423. break;
  424. }
  425. if (rv) {
  426. ishtp_cl_free(ecl_ishtp_cl);
  427. opr_dev->ecl_ishtp_cl = NULL;
  428. dev_err(cl_data_to_dev(opr_dev),
  429. "[ish_rst] Reset failed. Link not ready.\n");
  430. return;
  431. }
  432. ishtp_register_event_cb(cl_device, ecl_ishtp_cl_event_cb);
  433. dev_info(cl_data_to_dev(opr_dev),
  434. "[ish_rst] Reset Success. Link ready.\n");
  435. opr_dev->ish_link_ready = true;
  436. if (opr_dev->acpi_init_done)
  437. return;
  438. rv = acpi_opregion_init(opr_dev);
  439. if (rv) {
  440. dev_err(cl_data_to_dev(opr_dev),
  441. "ACPI opregion init failed\n");
  442. }
  443. }
  444. static int ecl_ishtp_cl_probe(struct ishtp_cl_device *cl_device)
  445. {
  446. struct ishtp_cl *ecl_ishtp_cl;
  447. struct ishtp_opregion_dev *opr_dev;
  448. int rv;
  449. opr_dev = devm_kzalloc(ishtp_device(cl_device), sizeof(*opr_dev),
  450. GFP_KERNEL);
  451. if (!opr_dev)
  452. return -ENOMEM;
  453. ecl_ishtp_cl = ishtp_cl_allocate(cl_device);
  454. if (!ecl_ishtp_cl)
  455. return -ENOMEM;
  456. ishtp_set_drvdata(cl_device, ecl_ishtp_cl);
  457. ishtp_set_client_data(ecl_ishtp_cl, opr_dev);
  458. opr_dev->ecl_ishtp_cl = ecl_ishtp_cl;
  459. opr_dev->cl_device = cl_device;
  460. init_waitqueue_head(&opr_dev->read_wait);
  461. INIT_WORK(&opr_dev->event_work, ecl_acpi_invoke_dsm);
  462. INIT_WORK(&opr_dev->reset_work, ecl_ishtp_cl_reset_handler);
  463. /* Initialize ish client device */
  464. rv = ecl_ishtp_cl_init(ecl_ishtp_cl);
  465. if (rv) {
  466. dev_err(cl_data_to_dev(opr_dev), "Client init failed\n");
  467. goto err_exit;
  468. }
  469. dev_dbg(cl_data_to_dev(opr_dev), "eclite-ishtp client initialised\n");
  470. opr_dev->ish_link_ready = true;
  471. mutex_init(&opr_dev->lock);
  472. rv = acpi_find_eclite_device(opr_dev);
  473. if (rv) {
  474. dev_err(cl_data_to_dev(opr_dev), "ECLite ACPI ID not found\n");
  475. goto err_exit;
  476. }
  477. /* Register a handler for eclite fw events */
  478. ishtp_register_event_cb(cl_device, ecl_ishtp_cl_event_cb);
  479. /* Now init opregion handlers */
  480. rv = acpi_opregion_init(opr_dev);
  481. if (rv) {
  482. dev_err(cl_data_to_dev(opr_dev), "ACPI opregion init failed\n");
  483. goto err_exit;
  484. }
  485. /* Reprobe devices depending on ECLite - battery, fan, etc. */
  486. acpi_dev_clear_dependencies(opr_dev->adev);
  487. return 0;
  488. err_exit:
  489. ishtp_set_connection_state(ecl_ishtp_cl, ISHTP_CL_DISCONNECTING);
  490. ishtp_cl_disconnect(ecl_ishtp_cl);
  491. ecl_ishtp_cl_deinit(ecl_ishtp_cl);
  492. return rv;
  493. }
  494. static void ecl_ishtp_cl_remove(struct ishtp_cl_device *cl_device)
  495. {
  496. struct ishtp_cl *ecl_ishtp_cl = ishtp_get_drvdata(cl_device);
  497. struct ishtp_opregion_dev *opr_dev =
  498. ishtp_get_client_data(ecl_ishtp_cl);
  499. if (opr_dev->acpi_init_done)
  500. acpi_opregion_deinit(opr_dev);
  501. acpi_dev_put(opr_dev->adev);
  502. ishtp_set_connection_state(ecl_ishtp_cl, ISHTP_CL_DISCONNECTING);
  503. ishtp_cl_disconnect(ecl_ishtp_cl);
  504. ecl_ishtp_cl_deinit(ecl_ishtp_cl);
  505. cancel_work_sync(&opr_dev->reset_work);
  506. cancel_work_sync(&opr_dev->event_work);
  507. }
  508. static int ecl_ishtp_cl_reset(struct ishtp_cl_device *cl_device)
  509. {
  510. struct ishtp_cl *ecl_ishtp_cl = ishtp_get_drvdata(cl_device);
  511. struct ishtp_opregion_dev *opr_dev =
  512. ishtp_get_client_data(ecl_ishtp_cl);
  513. schedule_work(&opr_dev->reset_work);
  514. return 0;
  515. }
  516. static int ecl_ishtp_cl_suspend(struct device *device)
  517. {
  518. struct ishtp_cl_device *cl_device = ishtp_dev_to_cl_device(device);
  519. struct ishtp_cl *ecl_ishtp_cl = ishtp_get_drvdata(cl_device);
  520. struct ishtp_opregion_dev *opr_dev =
  521. ishtp_get_client_data(ecl_ishtp_cl);
  522. if (acpi_target_system_state() == ACPI_STATE_S0)
  523. return 0;
  524. acpi_opregion_deinit(opr_dev);
  525. ecl_ish_cl_enable_events(opr_dev, false);
  526. return 0;
  527. }
  528. static int ecl_ishtp_cl_resume(struct device *device)
  529. {
  530. /* A reset is expected to call after an Sx. At this point
  531. * we are not sure if the link is up or not to restore anything,
  532. * so do nothing in resume path
  533. */
  534. return 0;
  535. }
  536. static const struct dev_pm_ops ecl_ishtp_pm_ops = {
  537. .suspend = ecl_ishtp_cl_suspend,
  538. .resume = ecl_ishtp_cl_resume,
  539. };
  540. static struct ishtp_cl_driver ecl_ishtp_cl_driver = {
  541. .name = "ishtp-eclite",
  542. .id = ecl_ishtp_id_table,
  543. .probe = ecl_ishtp_cl_probe,
  544. .remove = ecl_ishtp_cl_remove,
  545. .reset = ecl_ishtp_cl_reset,
  546. .driver.pm = &ecl_ishtp_pm_ops,
  547. };
  548. static int __init ecl_ishtp_init(void)
  549. {
  550. return ishtp_cl_driver_register(&ecl_ishtp_cl_driver, THIS_MODULE);
  551. }
  552. static void __exit ecl_ishtp_exit(void)
  553. {
  554. return ishtp_cl_driver_unregister(&ecl_ishtp_cl_driver);
  555. }
  556. late_initcall(ecl_ishtp_init);
  557. module_exit(ecl_ishtp_exit);
  558. MODULE_DESCRIPTION("ISH ISHTP eclite client opregion driver");
  559. MODULE_AUTHOR("K Naduvalath, Sumesh <sumesh.k.naduvalath@intel.com>");
  560. MODULE_LICENSE("GPL v2");