ibm_acpi.c 45 KB

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