ibm_acpi.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088
  1. /*
  2. * ibm_acpi.c - IBM ThinkPad ACPI Extras
  3. *
  4. *
  5. * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #define IBM_VERSION "0.12a"
  22. /*
  23. * Changelog:
  24. *
  25. * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
  26. * 2005-03-17 0.11 support for 600e, 770x
  27. * thanks to Jamie Lentin <lentinj@dial.pipex.com>
  28. * support for 770e, G41
  29. * G40 and G41 don't have a thinklight
  30. * temperatures no longer experimental
  31. * experimental brightness control
  32. * experimental volume control
  33. * experimental fan enable/disable
  34. * 2005-01-16 0.10 fix module loading on R30, R31
  35. * 2005-01-16 0.9 support for 570, R30, R31
  36. * ultrabay support on A22p, A3x
  37. * limit arg for cmos, led, beep, drop experimental status
  38. * more capable led control on A21e, A22p, T20-22, X20
  39. * experimental temperatures and fan speed
  40. * experimental embedded controller register dump
  41. * mark more functions as __init, drop incorrect __exit
  42. * use MODULE_VERSION
  43. * thanks to Henrik Brix Andersen <brix@gentoo.org>
  44. * fix parameter passing on module loading
  45. * thanks to Rusty Russell <rusty@rustcorp.com.au>
  46. * thanks to Jim Radford <radford@blackbean.org>
  47. * 2004-11-08 0.8 fix init error case, don't return from a macro
  48. * thanks to Chris Wright <chrisw@osdl.org>
  49. * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
  50. * fix led control on A21e
  51. * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
  52. * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
  53. * proc file format changed
  54. * video_switch command
  55. * experimental cmos control
  56. * experimental led control
  57. * experimental acpi sounds
  58. * 2004-09-16 0.4 support for module parameters
  59. * hotkey mask can be prefixed by 0x
  60. * video output switching
  61. * video expansion control
  62. * ultrabay eject support
  63. * removed lcd brightness/on/off control, didn't work
  64. * 2004-08-17 0.3 support for R40
  65. * lcd off, brightness control
  66. * thinklight on/off
  67. * 2004-08-14 0.2 support for T series, X20
  68. * bluetooth enable/disable
  69. * hotkey events disabled by default
  70. * removed fan control, currently useless
  71. * 2004-08-09 0.1 initial release, support for X series
  72. */
  73. #include <linux/kernel.h>
  74. #include <linux/module.h>
  75. #include <linux/init.h>
  76. #include <linux/types.h>
  77. #include <linux/proc_fs.h>
  78. #include <linux/backlight.h>
  79. #include <asm/uaccess.h>
  80. #include <acpi/acpi_drivers.h>
  81. #include <acpi/acnamesp.h>
  82. #define IBM_NAME "ibm"
  83. #define IBM_DESC "IBM ThinkPad ACPI Extras"
  84. #define IBM_FILE "ibm_acpi"
  85. #define IBM_URL "http://ibm-acpi.sf.net/"
  86. MODULE_AUTHOR("Borislav Deianov");
  87. MODULE_DESCRIPTION(IBM_DESC);
  88. MODULE_VERSION(IBM_VERSION);
  89. MODULE_LICENSE("GPL");
  90. #define IBM_DIR IBM_NAME
  91. #define IBM_LOG IBM_FILE ": "
  92. #define IBM_ERR KERN_ERR IBM_LOG
  93. #define IBM_NOTICE KERN_NOTICE IBM_LOG
  94. #define IBM_INFO KERN_INFO IBM_LOG
  95. #define IBM_DEBUG KERN_DEBUG IBM_LOG
  96. #define IBM_MAX_ACPI_ARGS 3
  97. #define __unused __attribute__ ((unused))
  98. static int experimental;
  99. module_param(experimental, int, 0);
  100. static acpi_handle root_handle = NULL;
  101. #define IBM_HANDLE(object, parent, paths...) \
  102. static acpi_handle object##_handle; \
  103. static acpi_handle *object##_parent = &parent##_handle; \
  104. static char *object##_path; \
  105. static char *object##_paths[] = { paths }
  106. /*
  107. * The following models are supported to various degrees:
  108. *
  109. * 570, 600e, 600x, 770e, 770x
  110. * A20m, A21e, A21m, A21p, A22p, A30, A30p, A31, A31p
  111. * G40, G41
  112. * R30, R31, R32, R40, R40e, R50, R50e, R50p, R51
  113. * T20, T21, T22, T23, T30, T40, T40p, T41, T41p, T42, T42p, T43
  114. * X20, X21, X22, X23, X24, X30, X31, X40
  115. *
  116. * The following models have no supported features:
  117. *
  118. * 240, 240x, i1400
  119. *
  120. * Still missing DSDTs for the following models:
  121. *
  122. * A20p, A22e, A22m
  123. * R52
  124. * S31
  125. * T43p
  126. */
  127. IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
  128. "\\_SB.PCI.ISA.EC", /* 570 */
  129. "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
  130. "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
  131. "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
  132. "\\_SB.PCI0.ICH3.EC0", /* R31 */
  133. "\\_SB.PCI0.LPC.EC", /* all others */
  134. );
  135. IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
  136. "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
  137. "\\_SB.PCI0.VID0", /* 770e */
  138. "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
  139. "\\_SB.PCI0.AGP.VID", /* all others */
  140. ); /* R30, R31 */
  141. IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
  142. IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
  143. "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
  144. "\\CMS", /* R40, R40e */
  145. ); /* all others */
  146. #ifdef CONFIG_ACPI_IBM_DOCK
  147. IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
  148. "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
  149. "\\_SB.PCI0.PCI1.DOCK", /* all others */
  150. "\\_SB.PCI.ISA.SLCE", /* 570 */
  151. ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
  152. #endif
  153. IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
  154. "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
  155. "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
  156. ); /* A21e, R30, R31 */
  157. IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
  158. "_EJ0", /* all others */
  159. ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
  160. IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
  161. "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
  162. ); /* all others */
  163. IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
  164. "_EJ0", /* 770x */
  165. ); /* all others */
  166. /* don't list other alternatives as we install a notify handler on the 570 */
  167. IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
  168. IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
  169. "^HKEY", /* R30, R31 */
  170. "HKEY", /* all others */
  171. ); /* 570 */
  172. IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
  173. IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
  174. IBM_HANDLE(led, ec, "SLED", /* 570 */
  175. "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
  176. "LED", /* all others */
  177. ); /* R30, R31 */
  178. IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
  179. IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
  180. IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
  181. IBM_HANDLE(fans, ec, "FANS"); /* X31, X40 */
  182. IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
  183. "\\FSPD", /* 600e/x, 770e, 770x */
  184. ); /* all others */
  185. IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
  186. "JFNS", /* 770x-JL */
  187. ); /* all others */
  188. #define IBM_HKEY_HID "IBM0068"
  189. #define IBM_PCI_HID "PNP0A03"
  190. struct ibm_struct {
  191. char *name;
  192. char param[32];
  193. char *hid;
  194. struct acpi_driver *driver;
  195. int (*init) (void);
  196. int (*read) (char *);
  197. int (*write) (char *);
  198. void (*exit) (void);
  199. void (*notify) (struct ibm_struct *, u32);
  200. acpi_handle *handle;
  201. int type;
  202. struct acpi_device *device;
  203. int driver_registered;
  204. int proc_created;
  205. int init_called;
  206. int notify_installed;
  207. int experimental;
  208. };
  209. static struct proc_dir_entry *proc_dir = NULL;
  210. static struct backlight_device *ibm_backlight_device;
  211. #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
  212. #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
  213. #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
  214. static int acpi_evalf(acpi_handle handle,
  215. void *res, char *method, char *fmt, ...)
  216. {
  217. char *fmt0 = fmt;
  218. struct acpi_object_list params;
  219. union acpi_object in_objs[IBM_MAX_ACPI_ARGS];
  220. struct acpi_buffer result, *resultp;
  221. union acpi_object out_obj;
  222. acpi_status status;
  223. va_list ap;
  224. char res_type;
  225. int success;
  226. int quiet;
  227. if (!*fmt) {
  228. printk(IBM_ERR "acpi_evalf() called with empty format\n");
  229. return 0;
  230. }
  231. if (*fmt == 'q') {
  232. quiet = 1;
  233. fmt++;
  234. } else
  235. quiet = 0;
  236. res_type = *(fmt++);
  237. params.count = 0;
  238. params.pointer = &in_objs[0];
  239. va_start(ap, fmt);
  240. while (*fmt) {
  241. char c = *(fmt++);
  242. switch (c) {
  243. case 'd': /* int */
  244. in_objs[params.count].integer.value = va_arg(ap, int);
  245. in_objs[params.count++].type = ACPI_TYPE_INTEGER;
  246. break;
  247. /* add more types as needed */
  248. default:
  249. printk(IBM_ERR "acpi_evalf() called "
  250. "with invalid format character '%c'\n", c);
  251. return 0;
  252. }
  253. }
  254. va_end(ap);
  255. if (res_type != 'v') {
  256. result.length = sizeof(out_obj);
  257. result.pointer = &out_obj;
  258. resultp = &result;
  259. } else
  260. resultp = NULL;
  261. status = acpi_evaluate_object(handle, method, &params, resultp);
  262. switch (res_type) {
  263. case 'd': /* int */
  264. if (res)
  265. *(int *)res = out_obj.integer.value;
  266. success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
  267. break;
  268. case 'v': /* void */
  269. success = status == AE_OK;
  270. break;
  271. /* add more types as needed */
  272. default:
  273. printk(IBM_ERR "acpi_evalf() called "
  274. "with invalid format character '%c'\n", res_type);
  275. return 0;
  276. }
  277. if (!success && !quiet)
  278. printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
  279. method, fmt0, status);
  280. return success;
  281. }
  282. static void __unused acpi_print_int(acpi_handle handle, char *method)
  283. {
  284. int i;
  285. if (acpi_evalf(handle, &i, method, "d"))
  286. printk(IBM_INFO "%s = 0x%x\n", method, i);
  287. else
  288. printk(IBM_ERR "error calling %s\n", method);
  289. }
  290. static char *next_cmd(char **cmds)
  291. {
  292. char *start = *cmds;
  293. char *end;
  294. while ((end = strchr(start, ',')) && end == start)
  295. start = end + 1;
  296. if (!end)
  297. return NULL;
  298. *end = 0;
  299. *cmds = end + 1;
  300. return start;
  301. }
  302. static int driver_init(void)
  303. {
  304. printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
  305. printk(IBM_INFO "%s\n", IBM_URL);
  306. return 0;
  307. }
  308. static int driver_read(char *p)
  309. {
  310. int len = 0;
  311. len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
  312. len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
  313. return len;
  314. }
  315. static int hotkey_supported;
  316. static int hotkey_mask_supported;
  317. static int hotkey_orig_status;
  318. static int hotkey_orig_mask;
  319. static int hotkey_get(int *status, int *mask)
  320. {
  321. if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
  322. return 0;
  323. if (hotkey_mask_supported)
  324. if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
  325. return 0;
  326. return 1;
  327. }
  328. static int hotkey_set(int status, int mask)
  329. {
  330. int i;
  331. if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
  332. return 0;
  333. if (hotkey_mask_supported)
  334. for (i = 0; i < 32; i++) {
  335. int bit = ((1 << i) & mask) != 0;
  336. if (!acpi_evalf(hkey_handle,
  337. NULL, "MHKM", "vdd", i + 1, bit))
  338. return 0;
  339. }
  340. return 1;
  341. }
  342. static int hotkey_init(void)
  343. {
  344. /* hotkey not supported on 570 */
  345. hotkey_supported = hkey_handle != NULL;
  346. if (hotkey_supported) {
  347. /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
  348. A30, R30, R31, T20-22, X20-21, X22-24 */
  349. hotkey_mask_supported =
  350. acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
  351. if (!hotkey_get(&hotkey_orig_status, &hotkey_orig_mask))
  352. return -ENODEV;
  353. }
  354. return 0;
  355. }
  356. static int hotkey_read(char *p)
  357. {
  358. int status, mask;
  359. int len = 0;
  360. if (!hotkey_supported) {
  361. len += sprintf(p + len, "status:\t\tnot supported\n");
  362. return len;
  363. }
  364. if (!hotkey_get(&status, &mask))
  365. return -EIO;
  366. len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
  367. if (hotkey_mask_supported) {
  368. len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
  369. len += sprintf(p + len,
  370. "commands:\tenable, disable, reset, <mask>\n");
  371. } else {
  372. len += sprintf(p + len, "mask:\t\tnot supported\n");
  373. len += sprintf(p + len, "commands:\tenable, disable, reset\n");
  374. }
  375. return len;
  376. }
  377. static int hotkey_write(char *buf)
  378. {
  379. int status, mask;
  380. char *cmd;
  381. int do_cmd = 0;
  382. if (!hotkey_supported)
  383. return -ENODEV;
  384. if (!hotkey_get(&status, &mask))
  385. return -EIO;
  386. while ((cmd = next_cmd(&buf))) {
  387. if (strlencmp(cmd, "enable") == 0) {
  388. status = 1;
  389. } else if (strlencmp(cmd, "disable") == 0) {
  390. status = 0;
  391. } else if (strlencmp(cmd, "reset") == 0) {
  392. status = hotkey_orig_status;
  393. mask = hotkey_orig_mask;
  394. } else if (sscanf(cmd, "0x%x", &mask) == 1) {
  395. /* mask set */
  396. } else if (sscanf(cmd, "%x", &mask) == 1) {
  397. /* mask set */
  398. } else
  399. return -EINVAL;
  400. do_cmd = 1;
  401. }
  402. if (do_cmd && !hotkey_set(status, mask))
  403. return -EIO;
  404. return 0;
  405. }
  406. static void hotkey_exit(void)
  407. {
  408. if (hotkey_supported)
  409. hotkey_set(hotkey_orig_status, hotkey_orig_mask);
  410. }
  411. static void hotkey_notify(struct ibm_struct *ibm, u32 event)
  412. {
  413. int hkey;
  414. if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
  415. acpi_bus_generate_event(ibm->device, event, hkey);
  416. else {
  417. printk(IBM_ERR "unknown hotkey event %d\n", event);
  418. acpi_bus_generate_event(ibm->device, event, 0);
  419. }
  420. }
  421. static int bluetooth_supported;
  422. static int bluetooth_init(void)
  423. {
  424. /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
  425. G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
  426. bluetooth_supported = hkey_handle &&
  427. acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
  428. return 0;
  429. }
  430. static int bluetooth_status(void)
  431. {
  432. int status;
  433. if (!bluetooth_supported ||
  434. !acpi_evalf(hkey_handle, &status, "GBDC", "d"))
  435. status = 0;
  436. return status;
  437. }
  438. static int bluetooth_read(char *p)
  439. {
  440. int len = 0;
  441. int status = bluetooth_status();
  442. if (!bluetooth_supported)
  443. len += sprintf(p + len, "status:\t\tnot supported\n");
  444. else if (!(status & 1))
  445. len += sprintf(p + len, "status:\t\tnot installed\n");
  446. else {
  447. len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
  448. len += sprintf(p + len, "commands:\tenable, disable\n");
  449. }
  450. return len;
  451. }
  452. static int bluetooth_write(char *buf)
  453. {
  454. int status = bluetooth_status();
  455. char *cmd;
  456. int do_cmd = 0;
  457. if (!bluetooth_supported)
  458. return -ENODEV;
  459. while ((cmd = next_cmd(&buf))) {
  460. if (strlencmp(cmd, "enable") == 0) {
  461. status |= 2;
  462. } else if (strlencmp(cmd, "disable") == 0) {
  463. status &= ~2;
  464. } else
  465. return -EINVAL;
  466. do_cmd = 1;
  467. }
  468. if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
  469. return -EIO;
  470. return 0;
  471. }
  472. static int wan_supported;
  473. static int wan_init(void)
  474. {
  475. wan_supported = hkey_handle &&
  476. acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
  477. return 0;
  478. }
  479. static int wan_status(void)
  480. {
  481. int status;
  482. if (!wan_supported ||
  483. !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
  484. status = 0;
  485. return status;
  486. }
  487. static int wan_read(char *p)
  488. {
  489. int len = 0;
  490. int status = wan_status();
  491. if (!wan_supported)
  492. len += sprintf(p + len, "status:\t\tnot supported\n");
  493. else if (!(status & 1))
  494. len += sprintf(p + len, "status:\t\tnot installed\n");
  495. else {
  496. len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
  497. len += sprintf(p + len, "commands:\tenable, disable\n");
  498. }
  499. return len;
  500. }
  501. static int wan_write(char *buf)
  502. {
  503. int status = wan_status();
  504. char *cmd;
  505. int do_cmd = 0;
  506. if (!wan_supported)
  507. return -ENODEV;
  508. while ((cmd = next_cmd(&buf))) {
  509. if (strlencmp(cmd, "enable") == 0) {
  510. status |= 2;
  511. } else if (strlencmp(cmd, "disable") == 0) {
  512. status &= ~2;
  513. } else
  514. return -EINVAL;
  515. do_cmd = 1;
  516. }
  517. if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
  518. return -EIO;
  519. return 0;
  520. }
  521. static int video_supported;
  522. static int video_orig_autosw;
  523. #define VIDEO_570 1
  524. #define VIDEO_770 2
  525. #define VIDEO_NEW 3
  526. static int video_init(void)
  527. {
  528. int ivga;
  529. if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
  530. /* G41, assume IVGA doesn't change */
  531. vid_handle = vid2_handle;
  532. if (!vid_handle)
  533. /* video switching not supported on R30, R31 */
  534. video_supported = 0;
  535. else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
  536. /* 570 */
  537. video_supported = VIDEO_570;
  538. else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
  539. /* 600e/x, 770e, 770x */
  540. video_supported = VIDEO_770;
  541. else
  542. /* all others */
  543. video_supported = VIDEO_NEW;
  544. return 0;
  545. }
  546. static int video_status(void)
  547. {
  548. int status = 0;
  549. int i;
  550. if (video_supported == VIDEO_570) {
  551. if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87))
  552. status = i & 3;
  553. } else if (video_supported == VIDEO_770) {
  554. if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
  555. status |= 0x01 * i;
  556. if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
  557. status |= 0x02 * i;
  558. } else if (video_supported == VIDEO_NEW) {
  559. acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
  560. if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
  561. status |= 0x02 * i;
  562. acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0);
  563. if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
  564. status |= 0x01 * i;
  565. if (acpi_evalf(NULL, &i, "\\VCDD", "d"))
  566. status |= 0x08 * i;
  567. }
  568. return status;
  569. }
  570. static int video_autosw(void)
  571. {
  572. int autosw = 0;
  573. if (video_supported == VIDEO_570)
  574. acpi_evalf(vid_handle, &autosw, "SWIT", "d");
  575. else if (video_supported == VIDEO_770 || video_supported == VIDEO_NEW)
  576. acpi_evalf(vid_handle, &autosw, "^VDEE", "d");
  577. return autosw & 1;
  578. }
  579. static int video_read(char *p)
  580. {
  581. int status = video_status();
  582. int autosw = video_autosw();
  583. int len = 0;
  584. if (!video_supported) {
  585. len += sprintf(p + len, "status:\t\tnot supported\n");
  586. return len;
  587. }
  588. len += sprintf(p + len, "status:\t\tsupported\n");
  589. len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
  590. len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
  591. if (video_supported == VIDEO_NEW)
  592. len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
  593. len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
  594. len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
  595. len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
  596. if (video_supported == VIDEO_NEW)
  597. len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
  598. len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
  599. len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
  600. return len;
  601. }
  602. static int video_switch(void)
  603. {
  604. int autosw = video_autosw();
  605. int ret;
  606. if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
  607. return -EIO;
  608. ret = video_supported == VIDEO_570 ?
  609. acpi_evalf(ec_handle, NULL, "_Q16", "v") :
  610. acpi_evalf(vid_handle, NULL, "VSWT", "v");
  611. acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
  612. return ret;
  613. }
  614. static int video_expand(void)
  615. {
  616. if (video_supported == VIDEO_570)
  617. return acpi_evalf(ec_handle, NULL, "_Q17", "v");
  618. else if (video_supported == VIDEO_770)
  619. return acpi_evalf(vid_handle, NULL, "VEXP", "v");
  620. else
  621. return acpi_evalf(NULL, NULL, "\\VEXP", "v");
  622. }
  623. static int video_switch2(int status)
  624. {
  625. int ret;
  626. if (video_supported == VIDEO_570) {
  627. ret = acpi_evalf(NULL, NULL,
  628. "\\_SB.PHS2", "vdd", 0x8b, status | 0x80);
  629. } else if (video_supported == VIDEO_770) {
  630. int autosw = video_autosw();
  631. if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
  632. return -EIO;
  633. ret = acpi_evalf(vid_handle, NULL,
  634. "ASWT", "vdd", status * 0x100, 0);
  635. acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
  636. } else {
  637. ret = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
  638. acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
  639. }
  640. return ret;
  641. }
  642. static int video_write(char *buf)
  643. {
  644. char *cmd;
  645. int enable, disable, status;
  646. if (!video_supported)
  647. return -ENODEV;
  648. enable = disable = 0;
  649. while ((cmd = next_cmd(&buf))) {
  650. if (strlencmp(cmd, "lcd_enable") == 0) {
  651. enable |= 0x01;
  652. } else if (strlencmp(cmd, "lcd_disable") == 0) {
  653. disable |= 0x01;
  654. } else if (strlencmp(cmd, "crt_enable") == 0) {
  655. enable |= 0x02;
  656. } else if (strlencmp(cmd, "crt_disable") == 0) {
  657. disable |= 0x02;
  658. } else if (video_supported == VIDEO_NEW &&
  659. strlencmp(cmd, "dvi_enable") == 0) {
  660. enable |= 0x08;
  661. } else if (video_supported == VIDEO_NEW &&
  662. strlencmp(cmd, "dvi_disable") == 0) {
  663. disable |= 0x08;
  664. } else if (strlencmp(cmd, "auto_enable") == 0) {
  665. if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
  666. return -EIO;
  667. } else if (strlencmp(cmd, "auto_disable") == 0) {
  668. if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 0))
  669. return -EIO;
  670. } else if (strlencmp(cmd, "video_switch") == 0) {
  671. if (!video_switch())
  672. return -EIO;
  673. } else if (strlencmp(cmd, "expand_toggle") == 0) {
  674. if (!video_expand())
  675. return -EIO;
  676. } else
  677. return -EINVAL;
  678. }
  679. if (enable || disable) {
  680. status = (video_status() & 0x0f & ~disable) | enable;
  681. if (!video_switch2(status))
  682. return -EIO;
  683. }
  684. return 0;
  685. }
  686. static void video_exit(void)
  687. {
  688. acpi_evalf(vid_handle, NULL, "_DOS", "vd", video_orig_autosw);
  689. }
  690. static int light_supported;
  691. static int light_status_supported;
  692. static int light_init(void)
  693. {
  694. /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
  695. light_supported = (cmos_handle || lght_handle) && !ledb_handle;
  696. if (light_supported)
  697. /* light status not supported on
  698. 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
  699. light_status_supported = acpi_evalf(ec_handle, NULL,
  700. "KBLT", "qv");
  701. return 0;
  702. }
  703. static int light_read(char *p)
  704. {
  705. int len = 0;
  706. int status = 0;
  707. if (!light_supported) {
  708. len += sprintf(p + len, "status:\t\tnot supported\n");
  709. } else if (!light_status_supported) {
  710. len += sprintf(p + len, "status:\t\tunknown\n");
  711. len += sprintf(p + len, "commands:\ton, off\n");
  712. } else {
  713. if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
  714. return -EIO;
  715. len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
  716. len += sprintf(p + len, "commands:\ton, off\n");
  717. }
  718. return len;
  719. }
  720. static int light_write(char *buf)
  721. {
  722. int cmos_cmd, lght_cmd;
  723. char *cmd;
  724. int success;
  725. if (!light_supported)
  726. return -ENODEV;
  727. while ((cmd = next_cmd(&buf))) {
  728. if (strlencmp(cmd, "on") == 0) {
  729. cmos_cmd = 0x0c;
  730. lght_cmd = 1;
  731. } else if (strlencmp(cmd, "off") == 0) {
  732. cmos_cmd = 0x0d;
  733. lght_cmd = 0;
  734. } else
  735. return -EINVAL;
  736. success = cmos_handle ?
  737. acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
  738. acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
  739. if (!success)
  740. return -EIO;
  741. }
  742. return 0;
  743. }
  744. static int _sta(acpi_handle handle)
  745. {
  746. int status;
  747. if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
  748. status = 0;
  749. return status;
  750. }
  751. #ifdef CONFIG_ACPI_IBM_DOCK
  752. #define dock_docked() (_sta(dock_handle) & 1)
  753. static int dock_read(char *p)
  754. {
  755. int len = 0;
  756. int docked = dock_docked();
  757. if (!dock_handle)
  758. len += sprintf(p + len, "status:\t\tnot supported\n");
  759. else if (!docked)
  760. len += sprintf(p + len, "status:\t\tundocked\n");
  761. else {
  762. len += sprintf(p + len, "status:\t\tdocked\n");
  763. len += sprintf(p + len, "commands:\tdock, undock\n");
  764. }
  765. return len;
  766. }
  767. static int dock_write(char *buf)
  768. {
  769. char *cmd;
  770. if (!dock_docked())
  771. return -ENODEV;
  772. while ((cmd = next_cmd(&buf))) {
  773. if (strlencmp(cmd, "undock") == 0) {
  774. if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
  775. !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
  776. return -EIO;
  777. } else if (strlencmp(cmd, "dock") == 0) {
  778. if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
  779. return -EIO;
  780. } else
  781. return -EINVAL;
  782. }
  783. return 0;
  784. }
  785. static void dock_notify(struct ibm_struct *ibm, u32 event)
  786. {
  787. int docked = dock_docked();
  788. int pci = ibm->hid && strstr(ibm->hid, IBM_PCI_HID);
  789. if (event == 1 && !pci) /* 570 */
  790. acpi_bus_generate_event(ibm->device, event, 1); /* button */
  791. else if (event == 1 && pci) /* 570 */
  792. acpi_bus_generate_event(ibm->device, event, 3); /* dock */
  793. else if (event == 3 && docked)
  794. acpi_bus_generate_event(ibm->device, event, 1); /* button */
  795. else if (event == 3 && !docked)
  796. acpi_bus_generate_event(ibm->device, event, 2); /* undock */
  797. else if (event == 0 && docked)
  798. acpi_bus_generate_event(ibm->device, event, 3); /* dock */
  799. else {
  800. printk(IBM_ERR "unknown dock event %d, status %d\n",
  801. event, _sta(dock_handle));
  802. acpi_bus_generate_event(ibm->device, event, 0); /* unknown */
  803. }
  804. }
  805. #endif
  806. static int bay_status_supported;
  807. static int bay_status2_supported;
  808. static int bay_eject_supported;
  809. static int bay_eject2_supported;
  810. static int bay_init(void)
  811. {
  812. bay_status_supported = bay_handle &&
  813. acpi_evalf(bay_handle, NULL, "_STA", "qv");
  814. bay_status2_supported = bay2_handle &&
  815. acpi_evalf(bay2_handle, NULL, "_STA", "qv");
  816. bay_eject_supported = bay_handle && bay_ej_handle &&
  817. (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
  818. bay_eject2_supported = bay2_handle && bay2_ej_handle &&
  819. (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
  820. return 0;
  821. }
  822. #define bay_occupied(b) (_sta(b##_handle) & 1)
  823. static int bay_read(char *p)
  824. {
  825. int len = 0;
  826. int occupied = bay_occupied(bay);
  827. int occupied2 = bay_occupied(bay2);
  828. int eject, eject2;
  829. len += sprintf(p + len, "status:\t\t%s\n", bay_status_supported ?
  830. (occupied ? "occupied" : "unoccupied") :
  831. "not supported");
  832. if (bay_status2_supported)
  833. len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
  834. "occupied" : "unoccupied");
  835. eject = bay_eject_supported && occupied;
  836. eject2 = bay_eject2_supported && occupied2;
  837. if (eject && eject2)
  838. len += sprintf(p + len, "commands:\teject, eject2\n");
  839. else if (eject)
  840. len += sprintf(p + len, "commands:\teject\n");
  841. else if (eject2)
  842. len += sprintf(p + len, "commands:\teject2\n");
  843. return len;
  844. }
  845. static int bay_write(char *buf)
  846. {
  847. char *cmd;
  848. if (!bay_eject_supported && !bay_eject2_supported)
  849. return -ENODEV;
  850. while ((cmd = next_cmd(&buf))) {
  851. if (bay_eject_supported && strlencmp(cmd, "eject") == 0) {
  852. if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
  853. return -EIO;
  854. } else if (bay_eject2_supported &&
  855. strlencmp(cmd, "eject2") == 0) {
  856. if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
  857. return -EIO;
  858. } else
  859. return -EINVAL;
  860. }
  861. return 0;
  862. }
  863. static void bay_notify(struct ibm_struct *ibm, u32 event)
  864. {
  865. acpi_bus_generate_event(ibm->device, event, 0);
  866. }
  867. static int cmos_read(char *p)
  868. {
  869. int len = 0;
  870. /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
  871. R30, R31, T20-22, X20-21 */
  872. if (!cmos_handle)
  873. len += sprintf(p + len, "status:\t\tnot supported\n");
  874. else {
  875. len += sprintf(p + len, "status:\t\tsupported\n");
  876. len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
  877. }
  878. return len;
  879. }
  880. static int cmos_eval(int cmos_cmd)
  881. {
  882. if (cmos_handle)
  883. return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd);
  884. else
  885. return 1;
  886. }
  887. static int cmos_write(char *buf)
  888. {
  889. char *cmd;
  890. int cmos_cmd;
  891. if (!cmos_handle)
  892. return -EINVAL;
  893. while ((cmd = next_cmd(&buf))) {
  894. if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
  895. cmos_cmd >= 0 && cmos_cmd <= 21) {
  896. /* cmos_cmd set */
  897. } else
  898. return -EINVAL;
  899. if (!cmos_eval(cmos_cmd))
  900. return -EIO;
  901. }
  902. return 0;
  903. }
  904. static int led_supported;
  905. #define LED_570 1
  906. #define LED_OLD 2
  907. #define LED_NEW 3
  908. static int led_init(void)
  909. {
  910. if (!led_handle)
  911. /* led not supported on R30, R31 */
  912. led_supported = 0;
  913. else if (strlencmp(led_path, "SLED") == 0)
  914. /* 570 */
  915. led_supported = LED_570;
  916. else if (strlencmp(led_path, "SYSL") == 0)
  917. /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
  918. led_supported = LED_OLD;
  919. else
  920. /* all others */
  921. led_supported = LED_NEW;
  922. return 0;
  923. }
  924. #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
  925. static int led_read(char *p)
  926. {
  927. int len = 0;
  928. if (!led_supported) {
  929. len += sprintf(p + len, "status:\t\tnot supported\n");
  930. return len;
  931. }
  932. len += sprintf(p + len, "status:\t\tsupported\n");
  933. if (led_supported == LED_570) {
  934. /* 570 */
  935. int i, status;
  936. for (i = 0; i < 8; i++) {
  937. if (!acpi_evalf(ec_handle,
  938. &status, "GLED", "dd", 1 << i))
  939. return -EIO;
  940. len += sprintf(p + len, "%d:\t\t%s\n",
  941. i, led_status(status));
  942. }
  943. }
  944. len += sprintf(p + len, "commands:\t"
  945. "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
  946. return len;
  947. }
  948. /* off, on, blink */
  949. static const int led_sled_arg1[] = { 0, 1, 3 };
  950. static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
  951. static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
  952. static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
  953. #define EC_HLCL 0x0c
  954. #define EC_HLBL 0x0d
  955. #define EC_HLMS 0x0e
  956. static int led_write(char *buf)
  957. {
  958. char *cmd;
  959. int led, ind, ret;
  960. if (!led_supported)
  961. return -ENODEV;
  962. while ((cmd = next_cmd(&buf))) {
  963. if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
  964. return -EINVAL;
  965. if (strstr(cmd, "off")) {
  966. ind = 0;
  967. } else if (strstr(cmd, "on")) {
  968. ind = 1;
  969. } else if (strstr(cmd, "blink")) {
  970. ind = 2;
  971. } else
  972. return -EINVAL;
  973. if (led_supported == LED_570) {
  974. /* 570 */
  975. led = 1 << led;
  976. if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
  977. led, led_sled_arg1[ind]))
  978. return -EIO;
  979. } else if (led_supported == LED_OLD) {
  980. /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
  981. led = 1 << led;
  982. ret = ec_write(EC_HLMS, led);
  983. if (ret >= 0)
  984. ret =
  985. ec_write(EC_HLBL, led * led_exp_hlbl[ind]);
  986. if (ret >= 0)
  987. ret =
  988. ec_write(EC_HLCL, led * led_exp_hlcl[ind]);
  989. if (ret < 0)
  990. return ret;
  991. } else {
  992. /* all others */
  993. if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
  994. led, led_led_arg1[ind]))
  995. return -EIO;
  996. }
  997. }
  998. return 0;
  999. }
  1000. static int beep_read(char *p)
  1001. {
  1002. int len = 0;
  1003. if (!beep_handle)
  1004. len += sprintf(p + len, "status:\t\tnot supported\n");
  1005. else {
  1006. len += sprintf(p + len, "status:\t\tsupported\n");
  1007. len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
  1008. }
  1009. return len;
  1010. }
  1011. static int beep_write(char *buf)
  1012. {
  1013. char *cmd;
  1014. int beep_cmd;
  1015. if (!beep_handle)
  1016. return -ENODEV;
  1017. while ((cmd = next_cmd(&buf))) {
  1018. if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
  1019. beep_cmd >= 0 && beep_cmd <= 17) {
  1020. /* beep_cmd set */
  1021. } else
  1022. return -EINVAL;
  1023. if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
  1024. return -EIO;
  1025. }
  1026. return 0;
  1027. }
  1028. static int acpi_ec_read(int i, u8 * p)
  1029. {
  1030. int v;
  1031. if (ecrd_handle) {
  1032. if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
  1033. return 0;
  1034. *p = v;
  1035. } else {
  1036. if (ec_read(i, p) < 0)
  1037. return 0;
  1038. }
  1039. return 1;
  1040. }
  1041. static int acpi_ec_write(int i, u8 v)
  1042. {
  1043. if (ecwr_handle) {
  1044. if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
  1045. return 0;
  1046. } else {
  1047. if (ec_write(i, v) < 0)
  1048. return 0;
  1049. }
  1050. return 1;
  1051. }
  1052. static int thermal_tmp_supported;
  1053. static int thermal_updt_supported;
  1054. static int thermal_init(void)
  1055. {
  1056. /* temperatures not supported on 570, G4x, R30, R31, R32 */
  1057. thermal_tmp_supported = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
  1058. /* 600e/x, 770e, 770x */
  1059. thermal_updt_supported = acpi_evalf(ec_handle, NULL, "UPDT", "qv");
  1060. return 0;
  1061. }
  1062. static int thermal_read(char *p)
  1063. {
  1064. int len = 0;
  1065. if (!thermal_tmp_supported)
  1066. len += sprintf(p + len, "temperatures:\tnot supported\n");
  1067. else {
  1068. int i, t;
  1069. char tmpi[] = "TMPi";
  1070. s8 tmp[8];
  1071. if (thermal_updt_supported)
  1072. if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
  1073. return -EIO;
  1074. for (i = 0; i < 8; i++) {
  1075. tmpi[3] = '0' + i;
  1076. if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
  1077. return -EIO;
  1078. if (thermal_updt_supported)
  1079. tmp[i] = (t - 2732 + 5) / 10;
  1080. else
  1081. tmp[i] = t;
  1082. }
  1083. len += sprintf(p + len,
  1084. "temperatures:\t%d %d %d %d %d %d %d %d\n",
  1085. tmp[0], tmp[1], tmp[2], tmp[3],
  1086. tmp[4], tmp[5], tmp[6], tmp[7]);
  1087. }
  1088. return len;
  1089. }
  1090. static u8 ecdump_regs[256];
  1091. static int ecdump_read(char *p)
  1092. {
  1093. int len = 0;
  1094. int i, j;
  1095. u8 v;
  1096. len += sprintf(p + len, "EC "
  1097. " +00 +01 +02 +03 +04 +05 +06 +07"
  1098. " +08 +09 +0a +0b +0c +0d +0e +0f\n");
  1099. for (i = 0; i < 256; i += 16) {
  1100. len += sprintf(p + len, "EC 0x%02x:", i);
  1101. for (j = 0; j < 16; j++) {
  1102. if (!acpi_ec_read(i + j, &v))
  1103. break;
  1104. if (v != ecdump_regs[i + j])
  1105. len += sprintf(p + len, " *%02x", v);
  1106. else
  1107. len += sprintf(p + len, " %02x", v);
  1108. ecdump_regs[i + j] = v;
  1109. }
  1110. len += sprintf(p + len, "\n");
  1111. if (j != 16)
  1112. break;
  1113. }
  1114. /* These are way too dangerous to advertise openly... */
  1115. #if 0
  1116. len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
  1117. " (<offset> is 00-ff, <value> is 00-ff)\n");
  1118. len += sprintf(p + len, "commands:\t0x<offset> <value> "
  1119. " (<offset> is 00-ff, <value> is 0-255)\n");
  1120. #endif
  1121. return len;
  1122. }
  1123. static int ecdump_write(char *buf)
  1124. {
  1125. char *cmd;
  1126. int i, v;
  1127. while ((cmd = next_cmd(&buf))) {
  1128. if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
  1129. /* i and v set */
  1130. } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
  1131. /* i and v set */
  1132. } else
  1133. return -EINVAL;
  1134. if (i >= 0 && i < 256 && v >= 0 && v < 256) {
  1135. if (!acpi_ec_write(i, v))
  1136. return -EIO;
  1137. } else
  1138. return -EINVAL;
  1139. }
  1140. return 0;
  1141. }
  1142. static int brightness_offset = 0x31;
  1143. static int brightness_get(struct backlight_device *bd)
  1144. {
  1145. u8 level;
  1146. if (!acpi_ec_read(brightness_offset, &level))
  1147. return -EIO;
  1148. level &= 0x7;
  1149. return level;
  1150. }
  1151. static int brightness_read(char *p)
  1152. {
  1153. int len = 0;
  1154. int level;
  1155. if ((level = brightness_get(NULL)) < 0) {
  1156. len += sprintf(p + len, "level:\t\tunreadable\n");
  1157. } else {
  1158. len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
  1159. len += sprintf(p + len, "commands:\tup, down\n");
  1160. len += sprintf(p + len, "commands:\tlevel <level>"
  1161. " (<level> is 0-7)\n");
  1162. }
  1163. return len;
  1164. }
  1165. #define BRIGHTNESS_UP 4
  1166. #define BRIGHTNESS_DOWN 5
  1167. static int brightness_set(int value)
  1168. {
  1169. int cmos_cmd, inc, i;
  1170. int current_value = brightness_get(NULL);
  1171. value &= 7;
  1172. cmos_cmd = value > current_value ? BRIGHTNESS_UP : BRIGHTNESS_DOWN;
  1173. inc = value > current_value ? 1 : -1;
  1174. for (i = current_value; i != value; i += inc) {
  1175. if (!cmos_eval(cmos_cmd))
  1176. return -EIO;
  1177. if (!acpi_ec_write(brightness_offset, i + inc))
  1178. return -EIO;
  1179. }
  1180. return 0;
  1181. }
  1182. static int brightness_write(char *buf)
  1183. {
  1184. int level;
  1185. int new_level;
  1186. char *cmd;
  1187. while ((cmd = next_cmd(&buf))) {
  1188. if ((level = brightness_get(NULL)) < 0)
  1189. return level;
  1190. level &= 7;
  1191. if (strlencmp(cmd, "up") == 0) {
  1192. new_level = level == 7 ? 7 : level + 1;
  1193. } else if (strlencmp(cmd, "down") == 0) {
  1194. new_level = level == 0 ? 0 : level - 1;
  1195. } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
  1196. new_level >= 0 && new_level <= 7) {
  1197. /* new_level set */
  1198. } else
  1199. return -EINVAL;
  1200. brightness_set(new_level);
  1201. }
  1202. return 0;
  1203. }
  1204. static int brightness_update_status(struct backlight_device *bd)
  1205. {
  1206. return brightness_set(bd->props->brightness);
  1207. }
  1208. static int volume_offset = 0x30;
  1209. static int volume_read(char *p)
  1210. {
  1211. int len = 0;
  1212. u8 level;
  1213. if (!acpi_ec_read(volume_offset, &level)) {
  1214. len += sprintf(p + len, "level:\t\tunreadable\n");
  1215. } else {
  1216. len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
  1217. len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
  1218. len += sprintf(p + len, "commands:\tup, down, mute\n");
  1219. len += sprintf(p + len, "commands:\tlevel <level>"
  1220. " (<level> is 0-15)\n");
  1221. }
  1222. return len;
  1223. }
  1224. #define VOLUME_DOWN 0
  1225. #define VOLUME_UP 1
  1226. #define VOLUME_MUTE 2
  1227. static int volume_write(char *buf)
  1228. {
  1229. int cmos_cmd, inc, i;
  1230. u8 level, mute;
  1231. int new_level, new_mute;
  1232. char *cmd;
  1233. while ((cmd = next_cmd(&buf))) {
  1234. if (!acpi_ec_read(volume_offset, &level))
  1235. return -EIO;
  1236. new_mute = mute = level & 0x40;
  1237. new_level = level = level & 0xf;
  1238. if (strlencmp(cmd, "up") == 0) {
  1239. if (mute)
  1240. new_mute = 0;
  1241. else
  1242. new_level = level == 15 ? 15 : level + 1;
  1243. } else if (strlencmp(cmd, "down") == 0) {
  1244. if (mute)
  1245. new_mute = 0;
  1246. else
  1247. new_level = level == 0 ? 0 : level - 1;
  1248. } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
  1249. new_level >= 0 && new_level <= 15) {
  1250. /* new_level set */
  1251. } else if (strlencmp(cmd, "mute") == 0) {
  1252. new_mute = 0x40;
  1253. } else
  1254. return -EINVAL;
  1255. if (new_level != level) { /* mute doesn't change */
  1256. cmos_cmd = new_level > level ? VOLUME_UP : VOLUME_DOWN;
  1257. inc = new_level > level ? 1 : -1;
  1258. if (mute && (!cmos_eval(cmos_cmd) ||
  1259. !acpi_ec_write(volume_offset, level)))
  1260. return -EIO;
  1261. for (i = level; i != new_level; i += inc)
  1262. if (!cmos_eval(cmos_cmd) ||
  1263. !acpi_ec_write(volume_offset, i + inc))
  1264. return -EIO;
  1265. if (mute && (!cmos_eval(VOLUME_MUTE) ||
  1266. !acpi_ec_write(volume_offset,
  1267. new_level + mute)))
  1268. return -EIO;
  1269. }
  1270. if (new_mute != mute) { /* level doesn't change */
  1271. cmos_cmd = new_mute ? VOLUME_MUTE : VOLUME_UP;
  1272. if (!cmos_eval(cmos_cmd) ||
  1273. !acpi_ec_write(volume_offset, level + new_mute))
  1274. return -EIO;
  1275. }
  1276. }
  1277. return 0;
  1278. }
  1279. static int fan_status_offset = 0x2f;
  1280. static int fan_rpm_offset = 0x84;
  1281. static int fan_read(char *p)
  1282. {
  1283. int len = 0;
  1284. int s;
  1285. u8 lo, hi, status;
  1286. if (gfan_handle) {
  1287. /* 570, 600e/x, 770e, 770x */
  1288. if (!acpi_evalf(gfan_handle, &s, NULL, "d"))
  1289. return -EIO;
  1290. len += sprintf(p + len, "level:\t\t%d\n", s);
  1291. } else {
  1292. /* all except 570, 600e/x, 770e, 770x */
  1293. if (!acpi_ec_read(fan_status_offset, &status))
  1294. len += sprintf(p + len, "status:\t\tunreadable\n");
  1295. else
  1296. len += sprintf(p + len, "status:\t\t%s\n",
  1297. enabled(status, 7));
  1298. if (!acpi_ec_read(fan_rpm_offset, &lo) ||
  1299. !acpi_ec_read(fan_rpm_offset + 1, &hi))
  1300. len += sprintf(p + len, "speed:\t\tunreadable\n");
  1301. else
  1302. len += sprintf(p + len, "speed:\t\t%d\n",
  1303. (hi << 8) + lo);
  1304. }
  1305. if (sfan_handle)
  1306. /* 570, 770x-JL */
  1307. len += sprintf(p + len, "commands:\tlevel <level>"
  1308. " (<level> is 0-7)\n");
  1309. if (!gfan_handle)
  1310. /* all except 570, 600e/x, 770e, 770x */
  1311. len += sprintf(p + len, "commands:\tenable, disable\n");
  1312. if (fans_handle)
  1313. /* X31, X40 */
  1314. len += sprintf(p + len, "commands:\tspeed <speed>"
  1315. " (<speed> is 0-65535)\n");
  1316. return len;
  1317. }
  1318. static int fan_write(char *buf)
  1319. {
  1320. char *cmd;
  1321. int level, speed;
  1322. while ((cmd = next_cmd(&buf))) {
  1323. if (sfan_handle &&
  1324. sscanf(cmd, "level %d", &level) == 1 &&
  1325. level >= 0 && level <= 7) {
  1326. /* 570, 770x-JL */
  1327. if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
  1328. return -EIO;
  1329. } else if (!gfan_handle && strlencmp(cmd, "enable") == 0) {
  1330. /* all except 570, 600e/x, 770e, 770x */
  1331. if (!acpi_ec_write(fan_status_offset, 0x80))
  1332. return -EIO;
  1333. } else if (!gfan_handle && strlencmp(cmd, "disable") == 0) {
  1334. /* all except 570, 600e/x, 770e, 770x */
  1335. if (!acpi_ec_write(fan_status_offset, 0x00))
  1336. return -EIO;
  1337. } else if (fans_handle &&
  1338. sscanf(cmd, "speed %d", &speed) == 1 &&
  1339. speed >= 0 && speed <= 65535) {
  1340. /* X31, X40 */
  1341. if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
  1342. speed, speed, speed))
  1343. return -EIO;
  1344. } else
  1345. return -EINVAL;
  1346. }
  1347. return 0;
  1348. }
  1349. static struct ibm_struct ibms[] = {
  1350. {
  1351. .name = "driver",
  1352. .init = driver_init,
  1353. .read = driver_read,
  1354. },
  1355. {
  1356. .name = "hotkey",
  1357. .hid = IBM_HKEY_HID,
  1358. .init = hotkey_init,
  1359. .read = hotkey_read,
  1360. .write = hotkey_write,
  1361. .exit = hotkey_exit,
  1362. .notify = hotkey_notify,
  1363. .handle = &hkey_handle,
  1364. .type = ACPI_DEVICE_NOTIFY,
  1365. },
  1366. {
  1367. .name = "bluetooth",
  1368. .init = bluetooth_init,
  1369. .read = bluetooth_read,
  1370. .write = bluetooth_write,
  1371. },
  1372. {
  1373. .name = "wan",
  1374. .init = wan_init,
  1375. .read = wan_read,
  1376. .write = wan_write,
  1377. .experimental = 1,
  1378. },
  1379. {
  1380. .name = "video",
  1381. .init = video_init,
  1382. .read = video_read,
  1383. .write = video_write,
  1384. .exit = video_exit,
  1385. },
  1386. {
  1387. .name = "light",
  1388. .init = light_init,
  1389. .read = light_read,
  1390. .write = light_write,
  1391. },
  1392. #ifdef CONFIG_ACPI_IBM_DOCK
  1393. {
  1394. .name = "dock",
  1395. .read = dock_read,
  1396. .write = dock_write,
  1397. .notify = dock_notify,
  1398. .handle = &dock_handle,
  1399. .type = ACPI_SYSTEM_NOTIFY,
  1400. },
  1401. {
  1402. .name = "dock",
  1403. .hid = IBM_PCI_HID,
  1404. .notify = dock_notify,
  1405. .handle = &pci_handle,
  1406. .type = ACPI_SYSTEM_NOTIFY,
  1407. },
  1408. #endif
  1409. {
  1410. .name = "bay",
  1411. .init = bay_init,
  1412. .read = bay_read,
  1413. .write = bay_write,
  1414. .notify = bay_notify,
  1415. .handle = &bay_handle,
  1416. .type = ACPI_SYSTEM_NOTIFY,
  1417. },
  1418. {
  1419. .name = "cmos",
  1420. .read = cmos_read,
  1421. .write = cmos_write,
  1422. },
  1423. {
  1424. .name = "led",
  1425. .init = led_init,
  1426. .read = led_read,
  1427. .write = led_write,
  1428. },
  1429. {
  1430. .name = "beep",
  1431. .read = beep_read,
  1432. .write = beep_write,
  1433. },
  1434. {
  1435. .name = "thermal",
  1436. .init = thermal_init,
  1437. .read = thermal_read,
  1438. },
  1439. {
  1440. .name = "ecdump",
  1441. .read = ecdump_read,
  1442. .write = ecdump_write,
  1443. .experimental = 1,
  1444. },
  1445. {
  1446. .name = "brightness",
  1447. .read = brightness_read,
  1448. .write = brightness_write,
  1449. },
  1450. {
  1451. .name = "volume",
  1452. .read = volume_read,
  1453. .write = volume_write,
  1454. },
  1455. {
  1456. .name = "fan",
  1457. .read = fan_read,
  1458. .write = fan_write,
  1459. .experimental = 1,
  1460. },
  1461. };
  1462. static int dispatch_read(char *page, char **start, off_t off, int count,
  1463. int *eof, void *data)
  1464. {
  1465. struct ibm_struct *ibm = (struct ibm_struct *)data;
  1466. int len;
  1467. if (!ibm || !ibm->read)
  1468. return -EINVAL;
  1469. len = ibm->read(page);
  1470. if (len < 0)
  1471. return len;
  1472. if (len <= off + count)
  1473. *eof = 1;
  1474. *start = page + off;
  1475. len -= off;
  1476. if (len > count)
  1477. len = count;
  1478. if (len < 0)
  1479. len = 0;
  1480. return len;
  1481. }
  1482. static int dispatch_write(struct file *file, const char __user * userbuf,
  1483. unsigned long count, void *data)
  1484. {
  1485. struct ibm_struct *ibm = (struct ibm_struct *)data;
  1486. char *kernbuf;
  1487. int ret;
  1488. if (!ibm || !ibm->write)
  1489. return -EINVAL;
  1490. kernbuf = kmalloc(count + 2, GFP_KERNEL);
  1491. if (!kernbuf)
  1492. return -ENOMEM;
  1493. if (copy_from_user(kernbuf, userbuf, count)) {
  1494. kfree(kernbuf);
  1495. return -EFAULT;
  1496. }
  1497. kernbuf[count] = 0;
  1498. strcat(kernbuf, ",");
  1499. ret = ibm->write(kernbuf);
  1500. if (ret == 0)
  1501. ret = count;
  1502. kfree(kernbuf);
  1503. return ret;
  1504. }
  1505. static void dispatch_notify(acpi_handle handle, u32 event, void *data)
  1506. {
  1507. struct ibm_struct *ibm = (struct ibm_struct *)data;
  1508. if (!ibm || !ibm->notify)
  1509. return;
  1510. ibm->notify(ibm, event);
  1511. }
  1512. static int __init setup_notify(struct ibm_struct *ibm)
  1513. {
  1514. acpi_status status;
  1515. int ret;
  1516. if (!*ibm->handle)
  1517. return 0;
  1518. ret = acpi_bus_get_device(*ibm->handle, &ibm->device);
  1519. if (ret < 0) {
  1520. printk(IBM_ERR "%s device not present\n", ibm->name);
  1521. return 0;
  1522. }
  1523. acpi_driver_data(ibm->device) = ibm;
  1524. sprintf(acpi_device_class(ibm->device), "%s/%s", IBM_NAME, ibm->name);
  1525. status = acpi_install_notify_handler(*ibm->handle, ibm->type,
  1526. dispatch_notify, ibm);
  1527. if (ACPI_FAILURE(status)) {
  1528. printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
  1529. ibm->name, status);
  1530. return -ENODEV;
  1531. }
  1532. return 0;
  1533. }
  1534. static int __init ibm_device_add(struct acpi_device *device)
  1535. {
  1536. return 0;
  1537. }
  1538. static int __init register_driver(struct ibm_struct *ibm)
  1539. {
  1540. int ret;
  1541. ibm->driver = kmalloc(sizeof(struct acpi_driver), GFP_KERNEL);
  1542. if (!ibm->driver) {
  1543. printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
  1544. return -1;
  1545. }
  1546. memset(ibm->driver, 0, sizeof(struct acpi_driver));
  1547. sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
  1548. ibm->driver->ids = ibm->hid;
  1549. ibm->driver->ops.add = &ibm_device_add;
  1550. ret = acpi_bus_register_driver(ibm->driver);
  1551. if (ret < 0) {
  1552. printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
  1553. ibm->hid, ret);
  1554. kfree(ibm->driver);
  1555. }
  1556. return ret;
  1557. }
  1558. static int __init ibm_init(struct ibm_struct *ibm)
  1559. {
  1560. int ret;
  1561. struct proc_dir_entry *entry;
  1562. if (ibm->experimental && !experimental)
  1563. return 0;
  1564. if (ibm->hid) {
  1565. ret = register_driver(ibm);
  1566. if (ret < 0)
  1567. return ret;
  1568. ibm->driver_registered = 1;
  1569. }
  1570. if (ibm->init) {
  1571. ret = ibm->init();
  1572. if (ret != 0)
  1573. return ret;
  1574. ibm->init_called = 1;
  1575. }
  1576. if (ibm->read) {
  1577. entry = create_proc_entry(ibm->name,
  1578. S_IFREG | S_IRUGO | S_IWUSR,
  1579. proc_dir);
  1580. if (!entry) {
  1581. printk(IBM_ERR "unable to create proc entry %s\n",
  1582. ibm->name);
  1583. return -ENODEV;
  1584. }
  1585. entry->owner = THIS_MODULE;
  1586. entry->data = ibm;
  1587. entry->read_proc = &dispatch_read;
  1588. if (ibm->write)
  1589. entry->write_proc = &dispatch_write;
  1590. ibm->proc_created = 1;
  1591. }
  1592. if (ibm->notify) {
  1593. ret = setup_notify(ibm);
  1594. if (ret < 0)
  1595. return ret;
  1596. ibm->notify_installed = 1;
  1597. }
  1598. return 0;
  1599. }
  1600. static void ibm_exit(struct ibm_struct *ibm)
  1601. {
  1602. if (ibm->notify_installed)
  1603. acpi_remove_notify_handler(*ibm->handle, ibm->type,
  1604. dispatch_notify);
  1605. if (ibm->proc_created)
  1606. remove_proc_entry(ibm->name, proc_dir);
  1607. if (ibm->init_called && ibm->exit)
  1608. ibm->exit();
  1609. if (ibm->driver_registered) {
  1610. acpi_bus_unregister_driver(ibm->driver);
  1611. kfree(ibm->driver);
  1612. }
  1613. }
  1614. static void __init ibm_handle_init(char *name,
  1615. acpi_handle * handle, acpi_handle parent,
  1616. char **paths, int num_paths, char **path)
  1617. {
  1618. int i;
  1619. acpi_status status;
  1620. for (i = 0; i < num_paths; i++) {
  1621. status = acpi_get_handle(parent, paths[i], handle);
  1622. if (ACPI_SUCCESS(status)) {
  1623. *path = paths[i];
  1624. return;
  1625. }
  1626. }
  1627. *handle = NULL;
  1628. }
  1629. #define IBM_HANDLE_INIT(object) \
  1630. ibm_handle_init(#object, &object##_handle, *object##_parent, \
  1631. object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
  1632. static int set_ibm_param(const char *val, struct kernel_param *kp)
  1633. {
  1634. unsigned int i;
  1635. for (i = 0; i < ARRAY_SIZE(ibms); i++)
  1636. if (strcmp(ibms[i].name, kp->name) == 0 && ibms[i].write) {
  1637. if (strlen(val) > sizeof(ibms[i].param) - 2)
  1638. return -ENOSPC;
  1639. strcpy(ibms[i].param, val);
  1640. strcat(ibms[i].param, ",");
  1641. return 0;
  1642. }
  1643. return -EINVAL;
  1644. }
  1645. #define IBM_PARAM(feature) \
  1646. module_param_call(feature, set_ibm_param, NULL, NULL, 0)
  1647. IBM_PARAM(hotkey);
  1648. IBM_PARAM(bluetooth);
  1649. IBM_PARAM(video);
  1650. IBM_PARAM(light);
  1651. #ifdef CONFIG_ACPI_IBM_DOCK
  1652. IBM_PARAM(dock);
  1653. #endif
  1654. IBM_PARAM(bay);
  1655. IBM_PARAM(cmos);
  1656. IBM_PARAM(led);
  1657. IBM_PARAM(beep);
  1658. IBM_PARAM(ecdump);
  1659. IBM_PARAM(brightness);
  1660. IBM_PARAM(volume);
  1661. IBM_PARAM(fan);
  1662. static struct backlight_properties ibm_backlight_data = {
  1663. .owner = THIS_MODULE,
  1664. .get_brightness = brightness_get,
  1665. .update_status = brightness_update_status,
  1666. .max_brightness = 7,
  1667. };
  1668. static void acpi_ibm_exit(void)
  1669. {
  1670. int i;
  1671. if (ibm_backlight_device)
  1672. backlight_device_unregister(ibm_backlight_device);
  1673. for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--)
  1674. ibm_exit(&ibms[i]);
  1675. remove_proc_entry(IBM_DIR, acpi_root_dir);
  1676. }
  1677. static int __init acpi_ibm_init(void)
  1678. {
  1679. int ret, i;
  1680. if (acpi_disabled)
  1681. return -ENODEV;
  1682. if (!acpi_specific_hotkey_enabled) {
  1683. printk(IBM_ERR "using generic hotkey driver\n");
  1684. return -ENODEV;
  1685. }
  1686. /* ec is required because many other handles are relative to it */
  1687. IBM_HANDLE_INIT(ec);
  1688. if (!ec_handle) {
  1689. printk(IBM_ERR "ec object not found\n");
  1690. return -ENODEV;
  1691. }
  1692. /* these handles are not required */
  1693. IBM_HANDLE_INIT(vid);
  1694. IBM_HANDLE_INIT(vid2);
  1695. IBM_HANDLE_INIT(ledb);
  1696. IBM_HANDLE_INIT(led);
  1697. IBM_HANDLE_INIT(hkey);
  1698. IBM_HANDLE_INIT(lght);
  1699. IBM_HANDLE_INIT(cmos);
  1700. #ifdef CONFIG_ACPI_IBM_DOCK
  1701. IBM_HANDLE_INIT(dock);
  1702. #endif
  1703. IBM_HANDLE_INIT(pci);
  1704. IBM_HANDLE_INIT(bay);
  1705. if (bay_handle)
  1706. IBM_HANDLE_INIT(bay_ej);
  1707. IBM_HANDLE_INIT(bay2);
  1708. if (bay2_handle)
  1709. IBM_HANDLE_INIT(bay2_ej);
  1710. IBM_HANDLE_INIT(beep);
  1711. IBM_HANDLE_INIT(ecrd);
  1712. IBM_HANDLE_INIT(ecwr);
  1713. IBM_HANDLE_INIT(fans);
  1714. IBM_HANDLE_INIT(gfan);
  1715. IBM_HANDLE_INIT(sfan);
  1716. proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
  1717. if (!proc_dir) {
  1718. printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
  1719. return -ENODEV;
  1720. }
  1721. proc_dir->owner = THIS_MODULE;
  1722. for (i = 0; i < ARRAY_SIZE(ibms); i++) {
  1723. ret = ibm_init(&ibms[i]);
  1724. if (ret >= 0 && *ibms[i].param)
  1725. ret = ibms[i].write(ibms[i].param);
  1726. if (ret < 0) {
  1727. acpi_ibm_exit();
  1728. return ret;
  1729. }
  1730. }
  1731. ibm_backlight_device = backlight_device_register("ibm", NULL,
  1732. &ibm_backlight_data);
  1733. if (IS_ERR(ibm_backlight_device)) {
  1734. printk(IBM_ERR "Could not register ibm backlight device\n");
  1735. ibm_backlight_device = NULL;
  1736. acpi_ibm_exit();
  1737. }
  1738. return 0;
  1739. }
  1740. module_init(acpi_ibm_init);
  1741. module_exit(acpi_ibm_exit);