ibm_acpi.c 47 KB

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