ec.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  1. /*
  2. * ec.c - ACPI Embedded Controller Driver (v2.2)
  3. *
  4. * Copyright (C) 2001-2014 Intel Corporation
  5. * Author: 2014 Lv Zheng <lv.zheng@intel.com>
  6. * 2006, 2007 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
  7. * 2006 Denis Sadykov <denis.m.sadykov@intel.com>
  8. * 2004 Luming Yu <luming.yu@intel.com>
  9. * 2001, 2002 Andy Grover <andrew.grover@intel.com>
  10. * 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  11. * Copyright (C) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
  12. *
  13. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or (at
  18. * your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful, but
  21. * WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. * General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License along
  26. * with this program; if not, write to the Free Software Foundation, Inc.,
  27. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  28. *
  29. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  30. */
  31. /* Uncomment next line to get verbose printout */
  32. /* #define DEBUG */
  33. #define pr_fmt(fmt) "ACPI : EC: " fmt
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/init.h>
  37. #include <linux/types.h>
  38. #include <linux/delay.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/list.h>
  41. #include <linux/spinlock.h>
  42. #include <linux/slab.h>
  43. #include <linux/acpi.h>
  44. #include <linux/dmi.h>
  45. #include <asm/io.h>
  46. #include "internal.h"
  47. #define ACPI_EC_CLASS "embedded_controller"
  48. #define ACPI_EC_DEVICE_NAME "Embedded Controller"
  49. #define ACPI_EC_FILE_INFO "info"
  50. /* EC status register */
  51. #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
  52. #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
  53. #define ACPI_EC_FLAG_CMD 0x08 /* Input buffer contains a command */
  54. #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
  55. #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
  56. /* EC commands */
  57. enum ec_command {
  58. ACPI_EC_COMMAND_READ = 0x80,
  59. ACPI_EC_COMMAND_WRITE = 0x81,
  60. ACPI_EC_BURST_ENABLE = 0x82,
  61. ACPI_EC_BURST_DISABLE = 0x83,
  62. ACPI_EC_COMMAND_QUERY = 0x84,
  63. };
  64. #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
  65. #define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
  66. #define ACPI_EC_MSI_UDELAY 550 /* Wait 550us for MSI EC */
  67. #define ACPI_EC_CLEAR_MAX 100 /* Maximum number of events to query
  68. * when trying to clear the EC */
  69. enum {
  70. EC_FLAGS_QUERY_PENDING, /* Query is pending */
  71. EC_FLAGS_GPE_STORM, /* GPE storm detected */
  72. EC_FLAGS_HANDLERS_INSTALLED, /* Handlers for GPE and
  73. * OpReg are installed */
  74. EC_FLAGS_BLOCKED, /* Transactions are blocked */
  75. };
  76. #define ACPI_EC_COMMAND_POLL 0x01 /* Available for command byte */
  77. #define ACPI_EC_COMMAND_COMPLETE 0x02 /* Completed last byte */
  78. /* ec.c is compiled in acpi namespace so this shows up as acpi.ec_delay param */
  79. static unsigned int ec_delay __read_mostly = ACPI_EC_DELAY;
  80. module_param(ec_delay, uint, 0644);
  81. MODULE_PARM_DESC(ec_delay, "Timeout(ms) waited until an EC command completes");
  82. /*
  83. * If the number of false interrupts per one transaction exceeds
  84. * this threshold, will think there is a GPE storm happened and
  85. * will disable the GPE for normal transaction.
  86. */
  87. static unsigned int ec_storm_threshold __read_mostly = 8;
  88. module_param(ec_storm_threshold, uint, 0644);
  89. MODULE_PARM_DESC(ec_storm_threshold, "Maxim false GPE numbers not considered as GPE storm");
  90. struct acpi_ec_query_handler {
  91. struct list_head node;
  92. acpi_ec_query_func func;
  93. acpi_handle handle;
  94. void *data;
  95. u8 query_bit;
  96. };
  97. struct transaction {
  98. const u8 *wdata;
  99. u8 *rdata;
  100. unsigned short irq_count;
  101. u8 command;
  102. u8 wi;
  103. u8 ri;
  104. u8 wlen;
  105. u8 rlen;
  106. u8 flags;
  107. };
  108. struct acpi_ec *boot_ec, *first_ec;
  109. EXPORT_SYMBOL(first_ec);
  110. static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */
  111. static int EC_FLAGS_VALIDATE_ECDT; /* ASUStec ECDTs need to be validated */
  112. static int EC_FLAGS_SKIP_DSDT_SCAN; /* Not all BIOS survive early DSDT scan */
  113. static int EC_FLAGS_CLEAR_ON_RESUME; /* Needs acpi_ec_clear() on boot/resume */
  114. static int EC_FLAGS_QUERY_HANDSHAKE; /* Needs QR_EC issued when SCI_EVT set */
  115. /* --------------------------------------------------------------------------
  116. * Transaction Management
  117. * -------------------------------------------------------------------------- */
  118. static inline u8 acpi_ec_read_status(struct acpi_ec *ec)
  119. {
  120. u8 x = inb(ec->command_addr);
  121. pr_debug("EC_SC(R) = 0x%2.2x "
  122. "SCI_EVT=%d BURST=%d CMD=%d IBF=%d OBF=%d\n",
  123. x,
  124. !!(x & ACPI_EC_FLAG_SCI),
  125. !!(x & ACPI_EC_FLAG_BURST),
  126. !!(x & ACPI_EC_FLAG_CMD),
  127. !!(x & ACPI_EC_FLAG_IBF),
  128. !!(x & ACPI_EC_FLAG_OBF));
  129. return x;
  130. }
  131. static inline u8 acpi_ec_read_data(struct acpi_ec *ec)
  132. {
  133. u8 x = inb(ec->data_addr);
  134. pr_debug("EC_DATA(R) = 0x%2.2x\n", x);
  135. return x;
  136. }
  137. static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command)
  138. {
  139. pr_debug("EC_SC(W) = 0x%2.2x\n", command);
  140. outb(command, ec->command_addr);
  141. }
  142. static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
  143. {
  144. pr_debug("EC_DATA(W) = 0x%2.2x\n", data);
  145. outb(data, ec->data_addr);
  146. }
  147. #ifdef DEBUG
  148. static const char *acpi_ec_cmd_string(u8 cmd)
  149. {
  150. switch (cmd) {
  151. case 0x80:
  152. return "RD_EC";
  153. case 0x81:
  154. return "WR_EC";
  155. case 0x82:
  156. return "BE_EC";
  157. case 0x83:
  158. return "BD_EC";
  159. case 0x84:
  160. return "QR_EC";
  161. }
  162. return "UNKNOWN";
  163. }
  164. #else
  165. #define acpi_ec_cmd_string(cmd) "UNDEF"
  166. #endif
  167. static int ec_transaction_completed(struct acpi_ec *ec)
  168. {
  169. unsigned long flags;
  170. int ret = 0;
  171. spin_lock_irqsave(&ec->lock, flags);
  172. if (ec->curr && (ec->curr->flags & ACPI_EC_COMMAND_COMPLETE))
  173. ret = 1;
  174. spin_unlock_irqrestore(&ec->lock, flags);
  175. return ret;
  176. }
  177. static bool advance_transaction(struct acpi_ec *ec)
  178. {
  179. struct transaction *t;
  180. u8 status;
  181. bool wakeup = false;
  182. pr_debug("===== %s (%d) =====\n",
  183. in_interrupt() ? "IRQ" : "TASK", smp_processor_id());
  184. status = acpi_ec_read_status(ec);
  185. t = ec->curr;
  186. if (!t)
  187. goto err;
  188. if (t->flags & ACPI_EC_COMMAND_POLL) {
  189. if (t->wlen > t->wi) {
  190. if ((status & ACPI_EC_FLAG_IBF) == 0)
  191. acpi_ec_write_data(ec, t->wdata[t->wi++]);
  192. else
  193. goto err;
  194. } else if (t->rlen > t->ri) {
  195. if ((status & ACPI_EC_FLAG_OBF) == 1) {
  196. t->rdata[t->ri++] = acpi_ec_read_data(ec);
  197. if (t->rlen == t->ri) {
  198. t->flags |= ACPI_EC_COMMAND_COMPLETE;
  199. if (t->command == ACPI_EC_COMMAND_QUERY)
  200. pr_debug("***** Command(%s) hardware completion *****\n",
  201. acpi_ec_cmd_string(t->command));
  202. wakeup = true;
  203. }
  204. } else
  205. goto err;
  206. } else if (t->wlen == t->wi &&
  207. (status & ACPI_EC_FLAG_IBF) == 0) {
  208. t->flags |= ACPI_EC_COMMAND_COMPLETE;
  209. wakeup = true;
  210. }
  211. return wakeup;
  212. } else {
  213. if (EC_FLAGS_QUERY_HANDSHAKE &&
  214. !(status & ACPI_EC_FLAG_SCI) &&
  215. (t->command == ACPI_EC_COMMAND_QUERY)) {
  216. t->flags |= ACPI_EC_COMMAND_POLL;
  217. t->rdata[t->ri++] = 0x00;
  218. t->flags |= ACPI_EC_COMMAND_COMPLETE;
  219. pr_debug("***** Command(%s) software completion *****\n",
  220. acpi_ec_cmd_string(t->command));
  221. wakeup = true;
  222. } else if ((status & ACPI_EC_FLAG_IBF) == 0) {
  223. acpi_ec_write_cmd(ec, t->command);
  224. t->flags |= ACPI_EC_COMMAND_POLL;
  225. } else
  226. goto err;
  227. return wakeup;
  228. }
  229. err:
  230. /*
  231. * If SCI bit is set, then don't think it's a false IRQ
  232. * otherwise will take a not handled IRQ as a false one.
  233. */
  234. if (!(status & ACPI_EC_FLAG_SCI)) {
  235. if (in_interrupt() && t)
  236. ++t->irq_count;
  237. }
  238. return wakeup;
  239. }
  240. static void start_transaction(struct acpi_ec *ec)
  241. {
  242. ec->curr->irq_count = ec->curr->wi = ec->curr->ri = 0;
  243. ec->curr->flags = 0;
  244. (void)advance_transaction(ec);
  245. }
  246. static int acpi_ec_sync_query(struct acpi_ec *ec, u8 *data);
  247. static int ec_check_sci_sync(struct acpi_ec *ec, u8 state)
  248. {
  249. if (state & ACPI_EC_FLAG_SCI) {
  250. if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
  251. return acpi_ec_sync_query(ec, NULL);
  252. }
  253. return 0;
  254. }
  255. static int ec_poll(struct acpi_ec *ec)
  256. {
  257. unsigned long flags;
  258. int repeat = 5; /* number of command restarts */
  259. while (repeat--) {
  260. unsigned long delay = jiffies +
  261. msecs_to_jiffies(ec_delay);
  262. do {
  263. /* don't sleep with disabled interrupts */
  264. if (EC_FLAGS_MSI || irqs_disabled()) {
  265. udelay(ACPI_EC_MSI_UDELAY);
  266. if (ec_transaction_completed(ec))
  267. return 0;
  268. } else {
  269. if (wait_event_timeout(ec->wait,
  270. ec_transaction_completed(ec),
  271. msecs_to_jiffies(1)))
  272. return 0;
  273. }
  274. spin_lock_irqsave(&ec->lock, flags);
  275. (void)advance_transaction(ec);
  276. spin_unlock_irqrestore(&ec->lock, flags);
  277. } while (time_before(jiffies, delay));
  278. pr_debug("controller reset, restart transaction\n");
  279. spin_lock_irqsave(&ec->lock, flags);
  280. start_transaction(ec);
  281. spin_unlock_irqrestore(&ec->lock, flags);
  282. }
  283. return -ETIME;
  284. }
  285. static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
  286. struct transaction *t)
  287. {
  288. unsigned long tmp;
  289. int ret = 0;
  290. if (EC_FLAGS_MSI)
  291. udelay(ACPI_EC_MSI_UDELAY);
  292. /* start transaction */
  293. spin_lock_irqsave(&ec->lock, tmp);
  294. /* following two actions should be kept atomic */
  295. ec->curr = t;
  296. pr_debug("***** Command(%s) started *****\n",
  297. acpi_ec_cmd_string(t->command));
  298. start_transaction(ec);
  299. if (ec->curr->command == ACPI_EC_COMMAND_QUERY) {
  300. clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
  301. pr_debug("***** Event stopped *****\n");
  302. }
  303. spin_unlock_irqrestore(&ec->lock, tmp);
  304. ret = ec_poll(ec);
  305. spin_lock_irqsave(&ec->lock, tmp);
  306. pr_debug("***** Command(%s) stopped *****\n",
  307. acpi_ec_cmd_string(t->command));
  308. ec->curr = NULL;
  309. spin_unlock_irqrestore(&ec->lock, tmp);
  310. return ret;
  311. }
  312. static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
  313. {
  314. int status;
  315. u32 glk;
  316. if (!ec || (!t) || (t->wlen && !t->wdata) || (t->rlen && !t->rdata))
  317. return -EINVAL;
  318. if (t->rdata)
  319. memset(t->rdata, 0, t->rlen);
  320. mutex_lock(&ec->mutex);
  321. if (test_bit(EC_FLAGS_BLOCKED, &ec->flags)) {
  322. status = -EINVAL;
  323. goto unlock;
  324. }
  325. if (ec->global_lock) {
  326. status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
  327. if (ACPI_FAILURE(status)) {
  328. status = -ENODEV;
  329. goto unlock;
  330. }
  331. }
  332. /* disable GPE during transaction if storm is detected */
  333. if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
  334. /* It has to be disabled, so that it doesn't trigger. */
  335. acpi_disable_gpe(NULL, ec->gpe);
  336. }
  337. status = acpi_ec_transaction_unlocked(ec, t);
  338. /* check if we received SCI during transaction */
  339. ec_check_sci_sync(ec, acpi_ec_read_status(ec));
  340. if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
  341. msleep(1);
  342. /* It is safe to enable the GPE outside of the transaction. */
  343. acpi_enable_gpe(NULL, ec->gpe);
  344. } else if (t->irq_count > ec_storm_threshold) {
  345. pr_info("GPE storm detected(%d GPEs), "
  346. "transactions will use polling mode\n",
  347. t->irq_count);
  348. set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
  349. }
  350. if (ec->global_lock)
  351. acpi_release_global_lock(glk);
  352. unlock:
  353. mutex_unlock(&ec->mutex);
  354. return status;
  355. }
  356. static int acpi_ec_burst_enable(struct acpi_ec *ec)
  357. {
  358. u8 d;
  359. struct transaction t = {.command = ACPI_EC_BURST_ENABLE,
  360. .wdata = NULL, .rdata = &d,
  361. .wlen = 0, .rlen = 1};
  362. return acpi_ec_transaction(ec, &t);
  363. }
  364. static int acpi_ec_burst_disable(struct acpi_ec *ec)
  365. {
  366. struct transaction t = {.command = ACPI_EC_BURST_DISABLE,
  367. .wdata = NULL, .rdata = NULL,
  368. .wlen = 0, .rlen = 0};
  369. return (acpi_ec_read_status(ec) & ACPI_EC_FLAG_BURST) ?
  370. acpi_ec_transaction(ec, &t) : 0;
  371. }
  372. static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 *data)
  373. {
  374. int result;
  375. u8 d;
  376. struct transaction t = {.command = ACPI_EC_COMMAND_READ,
  377. .wdata = &address, .rdata = &d,
  378. .wlen = 1, .rlen = 1};
  379. result = acpi_ec_transaction(ec, &t);
  380. *data = d;
  381. return result;
  382. }
  383. static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
  384. {
  385. u8 wdata[2] = { address, data };
  386. struct transaction t = {.command = ACPI_EC_COMMAND_WRITE,
  387. .wdata = wdata, .rdata = NULL,
  388. .wlen = 2, .rlen = 0};
  389. return acpi_ec_transaction(ec, &t);
  390. }
  391. int ec_read(u8 addr, u8 *val)
  392. {
  393. int err;
  394. u8 temp_data;
  395. if (!first_ec)
  396. return -ENODEV;
  397. err = acpi_ec_read(first_ec, addr, &temp_data);
  398. if (!err) {
  399. *val = temp_data;
  400. return 0;
  401. }
  402. return err;
  403. }
  404. EXPORT_SYMBOL(ec_read);
  405. int ec_write(u8 addr, u8 val)
  406. {
  407. int err;
  408. if (!first_ec)
  409. return -ENODEV;
  410. err = acpi_ec_write(first_ec, addr, val);
  411. return err;
  412. }
  413. EXPORT_SYMBOL(ec_write);
  414. int ec_transaction(u8 command,
  415. const u8 *wdata, unsigned wdata_len,
  416. u8 *rdata, unsigned rdata_len)
  417. {
  418. struct transaction t = {.command = command,
  419. .wdata = wdata, .rdata = rdata,
  420. .wlen = wdata_len, .rlen = rdata_len};
  421. if (!first_ec)
  422. return -ENODEV;
  423. return acpi_ec_transaction(first_ec, &t);
  424. }
  425. EXPORT_SYMBOL(ec_transaction);
  426. /* Get the handle to the EC device */
  427. acpi_handle ec_get_handle(void)
  428. {
  429. if (!first_ec)
  430. return NULL;
  431. return first_ec->handle;
  432. }
  433. EXPORT_SYMBOL(ec_get_handle);
  434. /*
  435. * Process _Q events that might have accumulated in the EC.
  436. * Run with locked ec mutex.
  437. */
  438. static void acpi_ec_clear(struct acpi_ec *ec)
  439. {
  440. int i, status;
  441. u8 value = 0;
  442. for (i = 0; i < ACPI_EC_CLEAR_MAX; i++) {
  443. status = acpi_ec_sync_query(ec, &value);
  444. if (status || !value)
  445. break;
  446. }
  447. if (unlikely(i == ACPI_EC_CLEAR_MAX))
  448. pr_warn("Warning: Maximum of %d stale EC events cleared\n", i);
  449. else
  450. pr_info("%d stale EC events cleared\n", i);
  451. }
  452. void acpi_ec_block_transactions(void)
  453. {
  454. struct acpi_ec *ec = first_ec;
  455. if (!ec)
  456. return;
  457. mutex_lock(&ec->mutex);
  458. /* Prevent transactions from being carried out */
  459. set_bit(EC_FLAGS_BLOCKED, &ec->flags);
  460. mutex_unlock(&ec->mutex);
  461. }
  462. void acpi_ec_unblock_transactions(void)
  463. {
  464. struct acpi_ec *ec = first_ec;
  465. if (!ec)
  466. return;
  467. mutex_lock(&ec->mutex);
  468. /* Allow transactions to be carried out again */
  469. clear_bit(EC_FLAGS_BLOCKED, &ec->flags);
  470. if (EC_FLAGS_CLEAR_ON_RESUME)
  471. acpi_ec_clear(ec);
  472. mutex_unlock(&ec->mutex);
  473. }
  474. void acpi_ec_unblock_transactions_early(void)
  475. {
  476. /*
  477. * Allow transactions to happen again (this function is called from
  478. * atomic context during wakeup, so we don't need to acquire the mutex).
  479. */
  480. if (first_ec)
  481. clear_bit(EC_FLAGS_BLOCKED, &first_ec->flags);
  482. }
  483. static int acpi_ec_query_unlocked(struct acpi_ec *ec, u8 *data)
  484. {
  485. int result;
  486. u8 d;
  487. struct transaction t = {.command = ACPI_EC_COMMAND_QUERY,
  488. .wdata = NULL, .rdata = &d,
  489. .wlen = 0, .rlen = 1};
  490. if (!ec || !data)
  491. return -EINVAL;
  492. /*
  493. * Query the EC to find out which _Qxx method we need to evaluate.
  494. * Note that successful completion of the query causes the ACPI_EC_SCI
  495. * bit to be cleared (and thus clearing the interrupt source).
  496. */
  497. result = acpi_ec_transaction_unlocked(ec, &t);
  498. if (result)
  499. return result;
  500. if (!d)
  501. return -ENODATA;
  502. *data = d;
  503. return 0;
  504. }
  505. /* --------------------------------------------------------------------------
  506. Event Management
  507. -------------------------------------------------------------------------- */
  508. int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
  509. acpi_handle handle, acpi_ec_query_func func,
  510. void *data)
  511. {
  512. struct acpi_ec_query_handler *handler =
  513. kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
  514. if (!handler)
  515. return -ENOMEM;
  516. handler->query_bit = query_bit;
  517. handler->handle = handle;
  518. handler->func = func;
  519. handler->data = data;
  520. mutex_lock(&ec->mutex);
  521. list_add(&handler->node, &ec->list);
  522. mutex_unlock(&ec->mutex);
  523. return 0;
  524. }
  525. EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
  526. void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
  527. {
  528. struct acpi_ec_query_handler *handler, *tmp;
  529. mutex_lock(&ec->mutex);
  530. list_for_each_entry_safe(handler, tmp, &ec->list, node) {
  531. if (query_bit == handler->query_bit) {
  532. list_del(&handler->node);
  533. kfree(handler);
  534. }
  535. }
  536. mutex_unlock(&ec->mutex);
  537. }
  538. EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
  539. static void acpi_ec_run(void *cxt)
  540. {
  541. struct acpi_ec_query_handler *handler = cxt;
  542. if (!handler)
  543. return;
  544. pr_debug("##### Query(0x%02x) started #####\n", handler->query_bit);
  545. if (handler->func)
  546. handler->func(handler->data);
  547. else if (handler->handle)
  548. acpi_evaluate_object(handler->handle, NULL, NULL, NULL);
  549. pr_debug("##### Query(0x%02x) stopped #####\n", handler->query_bit);
  550. kfree(handler);
  551. }
  552. static int acpi_ec_sync_query(struct acpi_ec *ec, u8 *data)
  553. {
  554. u8 value = 0;
  555. int status;
  556. struct acpi_ec_query_handler *handler, *copy;
  557. status = acpi_ec_query_unlocked(ec, &value);
  558. if (data)
  559. *data = value;
  560. if (status)
  561. return status;
  562. list_for_each_entry(handler, &ec->list, node) {
  563. if (value == handler->query_bit) {
  564. /* have custom handler for this bit */
  565. copy = kmalloc(sizeof(*handler), GFP_KERNEL);
  566. if (!copy)
  567. return -ENOMEM;
  568. memcpy(copy, handler, sizeof(*copy));
  569. pr_debug("##### Query(0x%02x) scheduled #####\n",
  570. handler->query_bit);
  571. return acpi_os_execute((copy->func) ?
  572. OSL_NOTIFY_HANDLER : OSL_GPE_HANDLER,
  573. acpi_ec_run, copy);
  574. }
  575. }
  576. return 0;
  577. }
  578. static void acpi_ec_gpe_query(void *ec_cxt)
  579. {
  580. struct acpi_ec *ec = ec_cxt;
  581. if (!ec)
  582. return;
  583. mutex_lock(&ec->mutex);
  584. acpi_ec_sync_query(ec, NULL);
  585. mutex_unlock(&ec->mutex);
  586. }
  587. static int ec_check_sci(struct acpi_ec *ec, u8 state)
  588. {
  589. if (state & ACPI_EC_FLAG_SCI) {
  590. if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) {
  591. pr_debug("***** Event started *****\n");
  592. return acpi_os_execute(OSL_NOTIFY_HANDLER,
  593. acpi_ec_gpe_query, ec);
  594. }
  595. }
  596. return 0;
  597. }
  598. static u32 acpi_ec_gpe_handler(acpi_handle gpe_device,
  599. u32 gpe_number, void *data)
  600. {
  601. unsigned long flags;
  602. struct acpi_ec *ec = data;
  603. spin_lock_irqsave(&ec->lock, flags);
  604. if (advance_transaction(ec))
  605. wake_up(&ec->wait);
  606. spin_unlock_irqrestore(&ec->lock, flags);
  607. ec_check_sci(ec, acpi_ec_read_status(ec));
  608. return ACPI_INTERRUPT_HANDLED | ACPI_REENABLE_GPE;
  609. }
  610. /* --------------------------------------------------------------------------
  611. * Address Space Management
  612. * -------------------------------------------------------------------------- */
  613. static acpi_status
  614. acpi_ec_space_handler(u32 function, acpi_physical_address address,
  615. u32 bits, u64 *value64,
  616. void *handler_context, void *region_context)
  617. {
  618. struct acpi_ec *ec = handler_context;
  619. int result = 0, i, bytes = bits / 8;
  620. u8 *value = (u8 *)value64;
  621. if ((address > 0xFF) || !value || !handler_context)
  622. return AE_BAD_PARAMETER;
  623. if (function != ACPI_READ && function != ACPI_WRITE)
  624. return AE_BAD_PARAMETER;
  625. if (EC_FLAGS_MSI || bits > 8)
  626. acpi_ec_burst_enable(ec);
  627. for (i = 0; i < bytes; ++i, ++address, ++value)
  628. result = (function == ACPI_READ) ?
  629. acpi_ec_read(ec, address, value) :
  630. acpi_ec_write(ec, address, *value);
  631. if (EC_FLAGS_MSI || bits > 8)
  632. acpi_ec_burst_disable(ec);
  633. switch (result) {
  634. case -EINVAL:
  635. return AE_BAD_PARAMETER;
  636. case -ENODEV:
  637. return AE_NOT_FOUND;
  638. case -ETIME:
  639. return AE_TIME;
  640. default:
  641. return AE_OK;
  642. }
  643. }
  644. /* --------------------------------------------------------------------------
  645. * Driver Interface
  646. * -------------------------------------------------------------------------- */
  647. static acpi_status
  648. ec_parse_io_ports(struct acpi_resource *resource, void *context);
  649. static struct acpi_ec *make_acpi_ec(void)
  650. {
  651. struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
  652. if (!ec)
  653. return NULL;
  654. ec->flags = 1 << EC_FLAGS_QUERY_PENDING;
  655. mutex_init(&ec->mutex);
  656. init_waitqueue_head(&ec->wait);
  657. INIT_LIST_HEAD(&ec->list);
  658. spin_lock_init(&ec->lock);
  659. return ec;
  660. }
  661. static acpi_status
  662. acpi_ec_register_query_methods(acpi_handle handle, u32 level,
  663. void *context, void **return_value)
  664. {
  665. char node_name[5];
  666. struct acpi_buffer buffer = { sizeof(node_name), node_name };
  667. struct acpi_ec *ec = context;
  668. int value = 0;
  669. acpi_status status;
  670. status = acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
  671. if (ACPI_SUCCESS(status) && sscanf(node_name, "_Q%x", &value) == 1)
  672. acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
  673. return AE_OK;
  674. }
  675. static acpi_status
  676. ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
  677. {
  678. acpi_status status;
  679. unsigned long long tmp = 0;
  680. struct acpi_ec *ec = context;
  681. /* clear addr values, ec_parse_io_ports depend on it */
  682. ec->command_addr = ec->data_addr = 0;
  683. status = acpi_walk_resources(handle, METHOD_NAME__CRS,
  684. ec_parse_io_ports, ec);
  685. if (ACPI_FAILURE(status))
  686. return status;
  687. /* Get GPE bit assignment (EC events). */
  688. /* TODO: Add support for _GPE returning a package */
  689. status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp);
  690. if (ACPI_FAILURE(status))
  691. return status;
  692. ec->gpe = tmp;
  693. /* Use the global lock for all EC transactions? */
  694. tmp = 0;
  695. acpi_evaluate_integer(handle, "_GLK", NULL, &tmp);
  696. ec->global_lock = tmp;
  697. ec->handle = handle;
  698. return AE_CTRL_TERMINATE;
  699. }
  700. static int ec_install_handlers(struct acpi_ec *ec)
  701. {
  702. acpi_status status;
  703. if (test_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags))
  704. return 0;
  705. status = acpi_install_gpe_handler(NULL, ec->gpe,
  706. ACPI_GPE_EDGE_TRIGGERED,
  707. &acpi_ec_gpe_handler, ec);
  708. if (ACPI_FAILURE(status))
  709. return -ENODEV;
  710. acpi_enable_gpe(NULL, ec->gpe);
  711. status = acpi_install_address_space_handler(ec->handle,
  712. ACPI_ADR_SPACE_EC,
  713. &acpi_ec_space_handler,
  714. NULL, ec);
  715. if (ACPI_FAILURE(status)) {
  716. if (status == AE_NOT_FOUND) {
  717. /*
  718. * Maybe OS fails in evaluating the _REG object.
  719. * The AE_NOT_FOUND error will be ignored and OS
  720. * continue to initialize EC.
  721. */
  722. pr_err("Fail in evaluating the _REG object"
  723. " of EC device. Broken bios is suspected.\n");
  724. } else {
  725. acpi_disable_gpe(NULL, ec->gpe);
  726. acpi_remove_gpe_handler(NULL, ec->gpe,
  727. &acpi_ec_gpe_handler);
  728. return -ENODEV;
  729. }
  730. }
  731. set_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
  732. return 0;
  733. }
  734. static void ec_remove_handlers(struct acpi_ec *ec)
  735. {
  736. acpi_disable_gpe(NULL, ec->gpe);
  737. if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
  738. ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
  739. pr_err("failed to remove space handler\n");
  740. if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
  741. &acpi_ec_gpe_handler)))
  742. pr_err("failed to remove gpe handler\n");
  743. clear_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
  744. }
  745. static int acpi_ec_add(struct acpi_device *device)
  746. {
  747. struct acpi_ec *ec = NULL;
  748. int ret;
  749. strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
  750. strcpy(acpi_device_class(device), ACPI_EC_CLASS);
  751. /* Check for boot EC */
  752. if (boot_ec &&
  753. (boot_ec->handle == device->handle ||
  754. boot_ec->handle == ACPI_ROOT_OBJECT)) {
  755. ec = boot_ec;
  756. boot_ec = NULL;
  757. } else {
  758. ec = make_acpi_ec();
  759. if (!ec)
  760. return -ENOMEM;
  761. }
  762. if (ec_parse_device(device->handle, 0, ec, NULL) !=
  763. AE_CTRL_TERMINATE) {
  764. kfree(ec);
  765. return -EINVAL;
  766. }
  767. /* Find and register all query methods */
  768. acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1,
  769. acpi_ec_register_query_methods, NULL, ec, NULL);
  770. if (!first_ec)
  771. first_ec = ec;
  772. device->driver_data = ec;
  773. ret = !!request_region(ec->data_addr, 1, "EC data");
  774. WARN(!ret, "Could not request EC data io port 0x%lx", ec->data_addr);
  775. ret = !!request_region(ec->command_addr, 1, "EC cmd");
  776. WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr);
  777. pr_info("GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
  778. ec->gpe, ec->command_addr, ec->data_addr);
  779. ret = ec_install_handlers(ec);
  780. /* EC is fully operational, allow queries */
  781. clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
  782. /* Clear stale _Q events if hardware might require that */
  783. if (EC_FLAGS_CLEAR_ON_RESUME) {
  784. mutex_lock(&ec->mutex);
  785. acpi_ec_clear(ec);
  786. mutex_unlock(&ec->mutex);
  787. }
  788. return ret;
  789. }
  790. static int acpi_ec_remove(struct acpi_device *device)
  791. {
  792. struct acpi_ec *ec;
  793. struct acpi_ec_query_handler *handler, *tmp;
  794. if (!device)
  795. return -EINVAL;
  796. ec = acpi_driver_data(device);
  797. ec_remove_handlers(ec);
  798. mutex_lock(&ec->mutex);
  799. list_for_each_entry_safe(handler, tmp, &ec->list, node) {
  800. list_del(&handler->node);
  801. kfree(handler);
  802. }
  803. mutex_unlock(&ec->mutex);
  804. release_region(ec->data_addr, 1);
  805. release_region(ec->command_addr, 1);
  806. device->driver_data = NULL;
  807. if (ec == first_ec)
  808. first_ec = NULL;
  809. kfree(ec);
  810. return 0;
  811. }
  812. static acpi_status
  813. ec_parse_io_ports(struct acpi_resource *resource, void *context)
  814. {
  815. struct acpi_ec *ec = context;
  816. if (resource->type != ACPI_RESOURCE_TYPE_IO)
  817. return AE_OK;
  818. /*
  819. * The first address region returned is the data port, and
  820. * the second address region returned is the status/command
  821. * port.
  822. */
  823. if (ec->data_addr == 0)
  824. ec->data_addr = resource->data.io.minimum;
  825. else if (ec->command_addr == 0)
  826. ec->command_addr = resource->data.io.minimum;
  827. else
  828. return AE_CTRL_TERMINATE;
  829. return AE_OK;
  830. }
  831. int __init acpi_boot_ec_enable(void)
  832. {
  833. if (!boot_ec || test_bit(EC_FLAGS_HANDLERS_INSTALLED, &boot_ec->flags))
  834. return 0;
  835. if (!ec_install_handlers(boot_ec)) {
  836. first_ec = boot_ec;
  837. return 0;
  838. }
  839. return -EFAULT;
  840. }
  841. static const struct acpi_device_id ec_device_ids[] = {
  842. {"PNP0C09", 0},
  843. {"", 0},
  844. };
  845. /* Some BIOS do not survive early DSDT scan, skip it */
  846. static int ec_skip_dsdt_scan(const struct dmi_system_id *id)
  847. {
  848. EC_FLAGS_SKIP_DSDT_SCAN = 1;
  849. return 0;
  850. }
  851. /* ASUStek often supplies us with broken ECDT, validate it */
  852. static int ec_validate_ecdt(const struct dmi_system_id *id)
  853. {
  854. EC_FLAGS_VALIDATE_ECDT = 1;
  855. return 0;
  856. }
  857. /* MSI EC needs special treatment, enable it */
  858. static int ec_flag_msi(const struct dmi_system_id *id)
  859. {
  860. pr_debug("Detected MSI hardware, enabling workarounds.\n");
  861. EC_FLAGS_MSI = 1;
  862. EC_FLAGS_VALIDATE_ECDT = 1;
  863. return 0;
  864. }
  865. /*
  866. * Clevo M720 notebook actually works ok with IRQ mode, if we lifted
  867. * the GPE storm threshold back to 20
  868. */
  869. static int ec_enlarge_storm_threshold(const struct dmi_system_id *id)
  870. {
  871. pr_debug("Setting the EC GPE storm threshold to 20\n");
  872. ec_storm_threshold = 20;
  873. return 0;
  874. }
  875. /*
  876. * Acer EC firmware refuses to respond QR_EC when SCI_EVT is not set, for
  877. * which case, we complete the QR_EC without issuing it to the firmware.
  878. * https://bugzilla.kernel.org/show_bug.cgi?id=86211
  879. */
  880. static int ec_flag_query_handshake(const struct dmi_system_id *id)
  881. {
  882. pr_debug("Detected the EC firmware requiring QR_EC issued when SCI_EVT set\n");
  883. EC_FLAGS_QUERY_HANDSHAKE = 1;
  884. return 0;
  885. }
  886. /*
  887. * On some hardware it is necessary to clear events accumulated by the EC during
  888. * sleep. These ECs stop reporting GPEs until they are manually polled, if too
  889. * many events are accumulated. (e.g. Samsung Series 5/9 notebooks)
  890. *
  891. * https://bugzilla.kernel.org/show_bug.cgi?id=44161
  892. *
  893. * Ideally, the EC should also be instructed NOT to accumulate events during
  894. * sleep (which Windows seems to do somehow), but the interface to control this
  895. * behaviour is not known at this time.
  896. *
  897. * Models known to be affected are Samsung 530Uxx/535Uxx/540Uxx/550Pxx/900Xxx,
  898. * however it is very likely that other Samsung models are affected.
  899. *
  900. * On systems which don't accumulate _Q events during sleep, this extra check
  901. * should be harmless.
  902. */
  903. static int ec_clear_on_resume(const struct dmi_system_id *id)
  904. {
  905. pr_debug("Detected system needing EC poll on resume.\n");
  906. EC_FLAGS_CLEAR_ON_RESUME = 1;
  907. return 0;
  908. }
  909. static struct dmi_system_id ec_dmi_table[] __initdata = {
  910. {
  911. ec_skip_dsdt_scan, "Compal JFL92", {
  912. DMI_MATCH(DMI_BIOS_VENDOR, "COMPAL"),
  913. DMI_MATCH(DMI_BOARD_NAME, "JFL92") }, NULL},
  914. {
  915. ec_flag_msi, "MSI hardware", {
  916. DMI_MATCH(DMI_BIOS_VENDOR, "Micro-Star")}, NULL},
  917. {
  918. ec_flag_msi, "MSI hardware", {
  919. DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star")}, NULL},
  920. {
  921. ec_flag_msi, "MSI hardware", {
  922. DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-Star")}, NULL},
  923. {
  924. ec_flag_msi, "MSI hardware", {
  925. DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-STAR")}, NULL},
  926. {
  927. ec_flag_msi, "Quanta hardware", {
  928. DMI_MATCH(DMI_SYS_VENDOR, "Quanta"),
  929. DMI_MATCH(DMI_PRODUCT_NAME, "TW8/SW8/DW8"),}, NULL},
  930. {
  931. ec_flag_msi, "Quanta hardware", {
  932. DMI_MATCH(DMI_SYS_VENDOR, "Quanta"),
  933. DMI_MATCH(DMI_PRODUCT_NAME, "TW9/SW9"),}, NULL},
  934. {
  935. ec_flag_msi, "Clevo W350etq", {
  936. DMI_MATCH(DMI_SYS_VENDOR, "CLEVO CO."),
  937. DMI_MATCH(DMI_PRODUCT_NAME, "W35_37ET"),}, NULL},
  938. {
  939. ec_validate_ecdt, "ASUS hardware", {
  940. DMI_MATCH(DMI_BIOS_VENDOR, "ASUS") }, NULL},
  941. {
  942. ec_validate_ecdt, "ASUS hardware", {
  943. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer Inc.") }, NULL},
  944. {
  945. ec_enlarge_storm_threshold, "CLEVO hardware", {
  946. DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."),
  947. DMI_MATCH(DMI_PRODUCT_NAME, "M720T/M730T"),}, NULL},
  948. {
  949. ec_skip_dsdt_scan, "HP Folio 13", {
  950. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  951. DMI_MATCH(DMI_PRODUCT_NAME, "HP Folio 13"),}, NULL},
  952. {
  953. ec_validate_ecdt, "ASUS hardware", {
  954. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTek Computer Inc."),
  955. DMI_MATCH(DMI_PRODUCT_NAME, "L4R"),}, NULL},
  956. {
  957. ec_clear_on_resume, "Samsung hardware", {
  958. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD.")}, NULL},
  959. {
  960. ec_flag_query_handshake, "Acer hardware", {
  961. DMI_MATCH(DMI_SYS_VENDOR, "Acer"), }, NULL},
  962. {},
  963. };
  964. int __init acpi_ec_ecdt_probe(void)
  965. {
  966. acpi_status status;
  967. struct acpi_ec *saved_ec = NULL;
  968. struct acpi_table_ecdt *ecdt_ptr;
  969. boot_ec = make_acpi_ec();
  970. if (!boot_ec)
  971. return -ENOMEM;
  972. /*
  973. * Generate a boot ec context
  974. */
  975. dmi_check_system(ec_dmi_table);
  976. status = acpi_get_table(ACPI_SIG_ECDT, 1,
  977. (struct acpi_table_header **)&ecdt_ptr);
  978. if (ACPI_SUCCESS(status)) {
  979. pr_info("EC description table is found, configuring boot EC\n");
  980. boot_ec->command_addr = ecdt_ptr->control.address;
  981. boot_ec->data_addr = ecdt_ptr->data.address;
  982. boot_ec->gpe = ecdt_ptr->gpe;
  983. boot_ec->handle = ACPI_ROOT_OBJECT;
  984. acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id,
  985. &boot_ec->handle);
  986. /* Don't trust ECDT, which comes from ASUSTek */
  987. if (!EC_FLAGS_VALIDATE_ECDT)
  988. goto install;
  989. saved_ec = kmemdup(boot_ec, sizeof(struct acpi_ec), GFP_KERNEL);
  990. if (!saved_ec)
  991. return -ENOMEM;
  992. /* fall through */
  993. }
  994. if (EC_FLAGS_SKIP_DSDT_SCAN) {
  995. kfree(saved_ec);
  996. return -ENODEV;
  997. }
  998. /* This workaround is needed only on some broken machines,
  999. * which require early EC, but fail to provide ECDT */
  1000. pr_debug("Look up EC in DSDT\n");
  1001. status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
  1002. boot_ec, NULL);
  1003. /* Check that acpi_get_devices actually find something */
  1004. if (ACPI_FAILURE(status) || !boot_ec->handle)
  1005. goto error;
  1006. if (saved_ec) {
  1007. /* try to find good ECDT from ASUSTek */
  1008. if (saved_ec->command_addr != boot_ec->command_addr ||
  1009. saved_ec->data_addr != boot_ec->data_addr ||
  1010. saved_ec->gpe != boot_ec->gpe ||
  1011. saved_ec->handle != boot_ec->handle)
  1012. pr_info("ASUSTek keeps feeding us with broken "
  1013. "ECDT tables, which are very hard to workaround. "
  1014. "Trying to use DSDT EC info instead. Please send "
  1015. "output of acpidump to linux-acpi@vger.kernel.org\n");
  1016. kfree(saved_ec);
  1017. saved_ec = NULL;
  1018. } else {
  1019. /* We really need to limit this workaround, the only ASUS,
  1020. * which needs it, has fake EC._INI method, so use it as flag.
  1021. * Keep boot_ec struct as it will be needed soon.
  1022. */
  1023. if (!dmi_name_in_vendors("ASUS") ||
  1024. !acpi_has_method(boot_ec->handle, "_INI"))
  1025. return -ENODEV;
  1026. }
  1027. install:
  1028. if (!ec_install_handlers(boot_ec)) {
  1029. first_ec = boot_ec;
  1030. return 0;
  1031. }
  1032. error:
  1033. kfree(boot_ec);
  1034. kfree(saved_ec);
  1035. boot_ec = NULL;
  1036. return -ENODEV;
  1037. }
  1038. static struct acpi_driver acpi_ec_driver = {
  1039. .name = "ec",
  1040. .class = ACPI_EC_CLASS,
  1041. .ids = ec_device_ids,
  1042. .ops = {
  1043. .add = acpi_ec_add,
  1044. .remove = acpi_ec_remove,
  1045. },
  1046. };
  1047. int __init acpi_ec_init(void)
  1048. {
  1049. int result = 0;
  1050. /* Now register the driver for the EC */
  1051. result = acpi_bus_register_driver(&acpi_ec_driver);
  1052. if (result < 0)
  1053. return -ENODEV;
  1054. return result;
  1055. }
  1056. /* EC driver currently not unloadable */
  1057. #if 0
  1058. static void __exit acpi_ec_exit(void)
  1059. {
  1060. acpi_bus_unregister_driver(&acpi_ec_driver);
  1061. }
  1062. #endif /* 0 */