ec.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  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. if (!test_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags))
  737. return;
  738. acpi_disable_gpe(NULL, ec->gpe);
  739. if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
  740. ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
  741. pr_err("failed to remove space handler\n");
  742. if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
  743. &acpi_ec_gpe_handler)))
  744. pr_err("failed to remove gpe handler\n");
  745. clear_bit(EC_FLAGS_HANDLERS_INSTALLED, &ec->flags);
  746. }
  747. static int acpi_ec_add(struct acpi_device *device)
  748. {
  749. struct acpi_ec *ec = NULL;
  750. int ret;
  751. strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
  752. strcpy(acpi_device_class(device), ACPI_EC_CLASS);
  753. /* Check for boot EC */
  754. if (boot_ec &&
  755. (boot_ec->handle == device->handle ||
  756. boot_ec->handle == ACPI_ROOT_OBJECT)) {
  757. ec = boot_ec;
  758. boot_ec = NULL;
  759. } else {
  760. ec = make_acpi_ec();
  761. if (!ec)
  762. return -ENOMEM;
  763. }
  764. if (ec_parse_device(device->handle, 0, ec, NULL) !=
  765. AE_CTRL_TERMINATE) {
  766. kfree(ec);
  767. return -EINVAL;
  768. }
  769. /* Find and register all query methods */
  770. acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1,
  771. acpi_ec_register_query_methods, NULL, ec, NULL);
  772. if (!first_ec)
  773. first_ec = ec;
  774. device->driver_data = ec;
  775. ret = !!request_region(ec->data_addr, 1, "EC data");
  776. WARN(!ret, "Could not request EC data io port 0x%lx", ec->data_addr);
  777. ret = !!request_region(ec->command_addr, 1, "EC cmd");
  778. WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr);
  779. pr_info("GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n",
  780. ec->gpe, ec->command_addr, ec->data_addr);
  781. ret = ec_install_handlers(ec);
  782. /* EC is fully operational, allow queries */
  783. clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
  784. /* Clear stale _Q events if hardware might require that */
  785. if (EC_FLAGS_CLEAR_ON_RESUME) {
  786. mutex_lock(&ec->mutex);
  787. acpi_ec_clear(ec);
  788. mutex_unlock(&ec->mutex);
  789. }
  790. return ret;
  791. }
  792. static int acpi_ec_remove(struct acpi_device *device)
  793. {
  794. struct acpi_ec *ec;
  795. struct acpi_ec_query_handler *handler, *tmp;
  796. if (!device)
  797. return -EINVAL;
  798. ec = acpi_driver_data(device);
  799. ec_remove_handlers(ec);
  800. mutex_lock(&ec->mutex);
  801. list_for_each_entry_safe(handler, tmp, &ec->list, node) {
  802. list_del(&handler->node);
  803. kfree(handler);
  804. }
  805. mutex_unlock(&ec->mutex);
  806. release_region(ec->data_addr, 1);
  807. release_region(ec->command_addr, 1);
  808. device->driver_data = NULL;
  809. if (ec == first_ec)
  810. first_ec = NULL;
  811. kfree(ec);
  812. return 0;
  813. }
  814. static acpi_status
  815. ec_parse_io_ports(struct acpi_resource *resource, void *context)
  816. {
  817. struct acpi_ec *ec = context;
  818. if (resource->type != ACPI_RESOURCE_TYPE_IO)
  819. return AE_OK;
  820. /*
  821. * The first address region returned is the data port, and
  822. * the second address region returned is the status/command
  823. * port.
  824. */
  825. if (ec->data_addr == 0)
  826. ec->data_addr = resource->data.io.minimum;
  827. else if (ec->command_addr == 0)
  828. ec->command_addr = resource->data.io.minimum;
  829. else
  830. return AE_CTRL_TERMINATE;
  831. return AE_OK;
  832. }
  833. int __init acpi_boot_ec_enable(void)
  834. {
  835. if (!boot_ec || test_bit(EC_FLAGS_HANDLERS_INSTALLED, &boot_ec->flags))
  836. return 0;
  837. if (!ec_install_handlers(boot_ec)) {
  838. first_ec = boot_ec;
  839. return 0;
  840. }
  841. return -EFAULT;
  842. }
  843. static const struct acpi_device_id ec_device_ids[] = {
  844. {"PNP0C09", 0},
  845. {"", 0},
  846. };
  847. /* Some BIOS do not survive early DSDT scan, skip it */
  848. static int ec_skip_dsdt_scan(const struct dmi_system_id *id)
  849. {
  850. EC_FLAGS_SKIP_DSDT_SCAN = 1;
  851. return 0;
  852. }
  853. /* ASUStek often supplies us with broken ECDT, validate it */
  854. static int ec_validate_ecdt(const struct dmi_system_id *id)
  855. {
  856. EC_FLAGS_VALIDATE_ECDT = 1;
  857. return 0;
  858. }
  859. /* MSI EC needs special treatment, enable it */
  860. static int ec_flag_msi(const struct dmi_system_id *id)
  861. {
  862. pr_debug("Detected MSI hardware, enabling workarounds.\n");
  863. EC_FLAGS_MSI = 1;
  864. EC_FLAGS_VALIDATE_ECDT = 1;
  865. return 0;
  866. }
  867. /*
  868. * Clevo M720 notebook actually works ok with IRQ mode, if we lifted
  869. * the GPE storm threshold back to 20
  870. */
  871. static int ec_enlarge_storm_threshold(const struct dmi_system_id *id)
  872. {
  873. pr_debug("Setting the EC GPE storm threshold to 20\n");
  874. ec_storm_threshold = 20;
  875. return 0;
  876. }
  877. /*
  878. * Acer EC firmware refuses to respond QR_EC when SCI_EVT is not set, for
  879. * which case, we complete the QR_EC without issuing it to the firmware.
  880. * https://bugzilla.kernel.org/show_bug.cgi?id=86211
  881. */
  882. static int ec_flag_query_handshake(const struct dmi_system_id *id)
  883. {
  884. pr_debug("Detected the EC firmware requiring QR_EC issued when SCI_EVT set\n");
  885. EC_FLAGS_QUERY_HANDSHAKE = 1;
  886. return 0;
  887. }
  888. /*
  889. * On some hardware it is necessary to clear events accumulated by the EC during
  890. * sleep. These ECs stop reporting GPEs until they are manually polled, if too
  891. * many events are accumulated. (e.g. Samsung Series 5/9 notebooks)
  892. *
  893. * https://bugzilla.kernel.org/show_bug.cgi?id=44161
  894. *
  895. * Ideally, the EC should also be instructed NOT to accumulate events during
  896. * sleep (which Windows seems to do somehow), but the interface to control this
  897. * behaviour is not known at this time.
  898. *
  899. * Models known to be affected are Samsung 530Uxx/535Uxx/540Uxx/550Pxx/900Xxx,
  900. * however it is very likely that other Samsung models are affected.
  901. *
  902. * On systems which don't accumulate _Q events during sleep, this extra check
  903. * should be harmless.
  904. */
  905. static int ec_clear_on_resume(const struct dmi_system_id *id)
  906. {
  907. pr_debug("Detected system needing EC poll on resume.\n");
  908. EC_FLAGS_CLEAR_ON_RESUME = 1;
  909. return 0;
  910. }
  911. static struct dmi_system_id ec_dmi_table[] __initdata = {
  912. {
  913. ec_skip_dsdt_scan, "Compal JFL92", {
  914. DMI_MATCH(DMI_BIOS_VENDOR, "COMPAL"),
  915. DMI_MATCH(DMI_BOARD_NAME, "JFL92") }, NULL},
  916. {
  917. ec_flag_msi, "MSI hardware", {
  918. DMI_MATCH(DMI_BIOS_VENDOR, "Micro-Star")}, NULL},
  919. {
  920. ec_flag_msi, "MSI hardware", {
  921. DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star")}, NULL},
  922. {
  923. ec_flag_msi, "MSI hardware", {
  924. DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-Star")}, NULL},
  925. {
  926. ec_flag_msi, "MSI hardware", {
  927. DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-STAR")}, NULL},
  928. {
  929. ec_flag_msi, "Quanta hardware", {
  930. DMI_MATCH(DMI_SYS_VENDOR, "Quanta"),
  931. DMI_MATCH(DMI_PRODUCT_NAME, "TW8/SW8/DW8"),}, NULL},
  932. {
  933. ec_flag_msi, "Quanta hardware", {
  934. DMI_MATCH(DMI_SYS_VENDOR, "Quanta"),
  935. DMI_MATCH(DMI_PRODUCT_NAME, "TW9/SW9"),}, NULL},
  936. {
  937. ec_flag_msi, "Clevo W350etq", {
  938. DMI_MATCH(DMI_SYS_VENDOR, "CLEVO CO."),
  939. DMI_MATCH(DMI_PRODUCT_NAME, "W35_37ET"),}, NULL},
  940. {
  941. ec_validate_ecdt, "ASUS hardware", {
  942. DMI_MATCH(DMI_BIOS_VENDOR, "ASUS") }, NULL},
  943. {
  944. ec_validate_ecdt, "ASUS hardware", {
  945. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer Inc.") }, NULL},
  946. {
  947. ec_enlarge_storm_threshold, "CLEVO hardware", {
  948. DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."),
  949. DMI_MATCH(DMI_PRODUCT_NAME, "M720T/M730T"),}, NULL},
  950. {
  951. ec_skip_dsdt_scan, "HP Folio 13", {
  952. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  953. DMI_MATCH(DMI_PRODUCT_NAME, "HP Folio 13"),}, NULL},
  954. {
  955. ec_validate_ecdt, "ASUS hardware", {
  956. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTek Computer Inc."),
  957. DMI_MATCH(DMI_PRODUCT_NAME, "L4R"),}, NULL},
  958. {
  959. ec_clear_on_resume, "Samsung hardware", {
  960. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD.")}, NULL},
  961. {
  962. ec_flag_query_handshake, "Acer hardware", {
  963. DMI_MATCH(DMI_SYS_VENDOR, "Acer"), }, NULL},
  964. {},
  965. };
  966. int __init acpi_ec_ecdt_probe(void)
  967. {
  968. acpi_status status;
  969. struct acpi_ec *saved_ec = NULL;
  970. struct acpi_table_ecdt *ecdt_ptr;
  971. boot_ec = make_acpi_ec();
  972. if (!boot_ec)
  973. return -ENOMEM;
  974. /*
  975. * Generate a boot ec context
  976. */
  977. dmi_check_system(ec_dmi_table);
  978. status = acpi_get_table(ACPI_SIG_ECDT, 1,
  979. (struct acpi_table_header **)&ecdt_ptr);
  980. if (ACPI_SUCCESS(status)) {
  981. pr_info("EC description table is found, configuring boot EC\n");
  982. boot_ec->command_addr = ecdt_ptr->control.address;
  983. boot_ec->data_addr = ecdt_ptr->data.address;
  984. boot_ec->gpe = ecdt_ptr->gpe;
  985. boot_ec->handle = ACPI_ROOT_OBJECT;
  986. acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id,
  987. &boot_ec->handle);
  988. /* Don't trust ECDT, which comes from ASUSTek */
  989. if (!EC_FLAGS_VALIDATE_ECDT)
  990. goto install;
  991. saved_ec = kmemdup(boot_ec, sizeof(struct acpi_ec), GFP_KERNEL);
  992. if (!saved_ec)
  993. return -ENOMEM;
  994. /* fall through */
  995. }
  996. if (EC_FLAGS_SKIP_DSDT_SCAN) {
  997. kfree(saved_ec);
  998. return -ENODEV;
  999. }
  1000. /* This workaround is needed only on some broken machines,
  1001. * which require early EC, but fail to provide ECDT */
  1002. pr_debug("Look up EC in DSDT\n");
  1003. status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device,
  1004. boot_ec, NULL);
  1005. /* Check that acpi_get_devices actually find something */
  1006. if (ACPI_FAILURE(status) || !boot_ec->handle)
  1007. goto error;
  1008. if (saved_ec) {
  1009. /* try to find good ECDT from ASUSTek */
  1010. if (saved_ec->command_addr != boot_ec->command_addr ||
  1011. saved_ec->data_addr != boot_ec->data_addr ||
  1012. saved_ec->gpe != boot_ec->gpe ||
  1013. saved_ec->handle != boot_ec->handle)
  1014. pr_info("ASUSTek keeps feeding us with broken "
  1015. "ECDT tables, which are very hard to workaround. "
  1016. "Trying to use DSDT EC info instead. Please send "
  1017. "output of acpidump to linux-acpi@vger.kernel.org\n");
  1018. kfree(saved_ec);
  1019. saved_ec = NULL;
  1020. } else {
  1021. /* We really need to limit this workaround, the only ASUS,
  1022. * which needs it, has fake EC._INI method, so use it as flag.
  1023. * Keep boot_ec struct as it will be needed soon.
  1024. */
  1025. if (!dmi_name_in_vendors("ASUS") ||
  1026. !acpi_has_method(boot_ec->handle, "_INI"))
  1027. return -ENODEV;
  1028. }
  1029. install:
  1030. if (!ec_install_handlers(boot_ec)) {
  1031. first_ec = boot_ec;
  1032. return 0;
  1033. }
  1034. error:
  1035. kfree(boot_ec);
  1036. kfree(saved_ec);
  1037. boot_ec = NULL;
  1038. return -ENODEV;
  1039. }
  1040. static struct acpi_driver acpi_ec_driver = {
  1041. .name = "ec",
  1042. .class = ACPI_EC_CLASS,
  1043. .ids = ec_device_ids,
  1044. .ops = {
  1045. .add = acpi_ec_add,
  1046. .remove = acpi_ec_remove,
  1047. },
  1048. };
  1049. int __init acpi_ec_init(void)
  1050. {
  1051. int result = 0;
  1052. /* Now register the driver for the EC */
  1053. result = acpi_bus_register_driver(&acpi_ec_driver);
  1054. if (result < 0)
  1055. return -ENODEV;
  1056. return result;
  1057. }
  1058. /* EC driver currently not unloadable */
  1059. #if 0
  1060. static void __exit acpi_ec_exit(void)
  1061. {
  1062. acpi_bus_unregister_driver(&acpi_ec_driver);
  1063. }
  1064. #endif /* 0 */