ibm_acpi.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580
  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 <linux/dmi.h>
  81. #include <acpi/acpi_drivers.h>
  82. #include <acpi/acnamesp.h>
  83. #define IBM_NAME "ibm"
  84. #define IBM_DESC "IBM ThinkPad ACPI Extras"
  85. #define IBM_FILE "ibm_acpi"
  86. #define IBM_URL "http://ibm-acpi.sf.net/"
  87. MODULE_AUTHOR("Borislav Deianov");
  88. MODULE_DESCRIPTION(IBM_DESC);
  89. MODULE_VERSION(IBM_VERSION);
  90. MODULE_LICENSE("GPL");
  91. #define IBM_DIR IBM_NAME
  92. #define IBM_LOG IBM_FILE ": "
  93. #define IBM_ERR KERN_ERR IBM_LOG
  94. #define IBM_NOTICE KERN_NOTICE IBM_LOG
  95. #define IBM_INFO KERN_INFO IBM_LOG
  96. #define IBM_DEBUG KERN_DEBUG IBM_LOG
  97. #define IBM_MAX_ACPI_ARGS 3
  98. #define __unused __attribute__ ((unused))
  99. static int experimental;
  100. module_param(experimental, int, 0);
  101. static acpi_handle root_handle = NULL;
  102. #define IBM_HANDLE(object, parent, paths...) \
  103. static acpi_handle object##_handle; \
  104. static acpi_handle *object##_parent = &parent##_handle; \
  105. static char *object##_path; \
  106. static char *object##_paths[] = { paths }
  107. /*
  108. * The following models are supported to various degrees:
  109. *
  110. * 570, 600e, 600x, 770e, 770x
  111. * A20m, A21e, A21m, A21p, A22p, A30, A30p, A31, A31p
  112. * G40, G41
  113. * R30, R31, R32, R40, R40e, R50, R50e, R50p, R51
  114. * T20, T21, T22, T23, T30, T40, T40p, T41, T41p, T42, T42p, T43
  115. * X20, X21, X22, X23, X24, X30, X31, X40
  116. *
  117. * The following models have no supported features:
  118. *
  119. * 240, 240x, i1400
  120. *
  121. * Still missing DSDTs for the following models:
  122. *
  123. * A20p, A22e, A22m
  124. * R52
  125. * S31
  126. * T43p
  127. */
  128. IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
  129. "\\_SB.PCI.ISA.EC", /* 570 */
  130. "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
  131. "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
  132. "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
  133. "\\_SB.PCI0.ICH3.EC0", /* R31 */
  134. "\\_SB.PCI0.LPC.EC", /* all others */
  135. );
  136. IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
  137. "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
  138. "\\_SB.PCI0.VID0", /* 770e */
  139. "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
  140. "\\_SB.PCI0.AGP.VID", /* all others */
  141. ); /* R30, R31 */
  142. IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
  143. IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
  144. "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
  145. "\\CMS", /* R40, R40e */
  146. ); /* all others */
  147. #ifdef CONFIG_ACPI_IBM_DOCK
  148. IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
  149. "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
  150. "\\_SB.PCI0.PCI1.DOCK", /* all others */
  151. "\\_SB.PCI.ISA.SLCE", /* 570 */
  152. ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
  153. #endif
  154. IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
  155. "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
  156. "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
  157. ); /* A21e, R30, R31 */
  158. IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
  159. "_EJ0", /* all others */
  160. ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
  161. IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
  162. "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
  163. ); /* all others */
  164. IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
  165. "_EJ0", /* 770x */
  166. ); /* all others */
  167. /* don't list other alternatives as we install a notify handler on the 570 */
  168. IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
  169. IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
  170. "^HKEY", /* R30, R31 */
  171. "HKEY", /* all others */
  172. ); /* 570 */
  173. IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
  174. IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
  175. IBM_HANDLE(led, ec, "SLED", /* 570 */
  176. "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
  177. "LED", /* all others */
  178. ); /* R30, R31 */
  179. IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
  180. IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
  181. IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
  182. IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
  183. IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
  184. "\\FSPD", /* 600e/x, 770e, 770x */
  185. ); /* all others */
  186. IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
  187. "JFNS", /* 770x-JL */
  188. ); /* all others */
  189. #define IBM_HKEY_HID "IBM0068"
  190. #define IBM_PCI_HID "PNP0A03"
  191. enum thermal_access_mode {
  192. IBMACPI_THERMAL_NONE = 0, /* No thermal support */
  193. IBMACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
  194. IBMACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
  195. IBMACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
  196. IBMACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
  197. };
  198. #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
  199. struct ibm_thermal_sensors_struct {
  200. s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
  201. };
  202. /*
  203. * FAN ACCESS MODES
  204. *
  205. * IBMACPI_FAN_RD_ACPI_GFAN:
  206. * ACPI GFAN method: returns fan level
  207. *
  208. * see IBMACPI_FAN_WR_ACPI_SFAN
  209. * EC 0x2f not available if GFAN exists
  210. *
  211. * IBMACPI_FAN_WR_ACPI_SFAN:
  212. * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
  213. *
  214. * EC 0x2f might be available *for reading*, but never for writing.
  215. *
  216. * IBMACPI_FAN_WR_TPEC:
  217. * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
  218. * on almost all ThinkPads
  219. *
  220. * Fan speed changes of any sort (including those caused by the
  221. * disengaged mode) are usually done slowly by the firmware as the
  222. * maximum ammount of fan duty cycle change per second seems to be
  223. * limited.
  224. *
  225. * Reading is not available if GFAN exists.
  226. * Writing is not available if SFAN exists.
  227. *
  228. * Bits
  229. * 7 automatic mode engaged;
  230. * (default operation mode of the ThinkPad)
  231. * fan level is ignored in this mode.
  232. * 6 disengage mode (takes precedence over bit 7);
  233. * not available on all thinkpads. May disable
  234. * the tachometer, and speeds up fan to 100% duty-cycle,
  235. * which speeds it up far above the standard RPM
  236. * levels. It is not impossible that it could cause
  237. * hardware damage.
  238. * 5-3 unused in some models. Extra bits for fan level
  239. * in others, but still useless as all values above
  240. * 7 map to the same speed as level 7 in these models.
  241. * 2-0 fan level (0..7 usually)
  242. * 0x00 = stop
  243. * 0x07 = max (set when temperatures critical)
  244. * Some ThinkPads may have other levels, see
  245. * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
  246. *
  247. * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
  248. * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
  249. * does so, its initial value is meaningless (0x07).
  250. *
  251. * For firmware bugs, refer to:
  252. * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
  253. *
  254. * ----
  255. *
  256. * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
  257. * Main fan tachometer reading (in RPM)
  258. *
  259. * This register is present on all ThinkPads with a new-style EC, and
  260. * it is known not to be present on the A21m/e, and T22, as there is
  261. * something else in offset 0x84 according to the ACPI DSDT. Other
  262. * ThinkPads from this same time period (and earlier) probably lack the
  263. * tachometer as well.
  264. *
  265. * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
  266. * was never fixed by IBM to report the EC firmware version string
  267. * probably support the tachometer (like the early X models), so
  268. * detecting it is quite hard. We need more data to know for sure.
  269. *
  270. * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
  271. * might result.
  272. *
  273. * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this
  274. * register is not invalidated in ThinkPads that disable tachometer
  275. * readings. Thus, the tachometer readings go stale.
  276. *
  277. * For firmware bugs, refer to:
  278. * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
  279. *
  280. * IBMACPI_FAN_WR_ACPI_FANS:
  281. * ThinkPad X31, X40, X41. Not available in the X60.
  282. *
  283. * FANS ACPI handle: takes three arguments: low speed, medium speed,
  284. * high speed. ACPI DSDT seems to map these three speeds to levels
  285. * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
  286. * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
  287. *
  288. * The speeds are stored on handles
  289. * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
  290. *
  291. * There are three default speed sets, acessible as handles:
  292. * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
  293. *
  294. * ACPI DSDT switches which set is in use depending on various
  295. * factors.
  296. *
  297. * IBMACPI_FAN_WR_TPEC is also available and should be used to
  298. * command the fan. The X31/X40/X41 seems to have 8 fan levels,
  299. * but the ACPI tables just mention level 7.
  300. */
  301. enum fan_status_access_mode {
  302. IBMACPI_FAN_NONE = 0, /* No fan status or control */
  303. IBMACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
  304. IBMACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
  305. };
  306. enum fan_control_access_mode {
  307. IBMACPI_FAN_WR_NONE = 0, /* No fan control */
  308. IBMACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
  309. IBMACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
  310. IBMACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
  311. };
  312. enum fan_control_commands {
  313. IBMACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
  314. IBMACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
  315. IBMACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd */
  316. };
  317. enum { /* Fan control constants */
  318. fan_status_offset = 0x2f, /* EC register 0x2f */
  319. fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
  320. * 0x84 must be read before 0x85 */
  321. IBMACPI_FAN_EC_DISENGAGED = 0x40, /* EC mode: tachometer
  322. * disengaged */
  323. IBMACPI_FAN_EC_AUTO = 0x80, /* EC mode: auto fan
  324. * control */
  325. };
  326. static int ibm_thinkpad_ec_found;
  327. struct ibm_struct {
  328. char *name;
  329. char param[32];
  330. char *hid;
  331. struct acpi_driver *driver;
  332. int (*init) (void);
  333. int (*read) (char *);
  334. int (*write) (char *);
  335. void (*exit) (void);
  336. void (*notify) (struct ibm_struct *, u32);
  337. acpi_handle *handle;
  338. int type;
  339. struct acpi_device *device;
  340. int driver_registered;
  341. int proc_created;
  342. int init_called;
  343. int notify_installed;
  344. int experimental;
  345. };
  346. static struct proc_dir_entry *proc_dir = NULL;
  347. static struct backlight_device *ibm_backlight_device;
  348. #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
  349. #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
  350. #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
  351. static int acpi_evalf(acpi_handle handle,
  352. void *res, char *method, char *fmt, ...)
  353. {
  354. char *fmt0 = fmt;
  355. struct acpi_object_list params;
  356. union acpi_object in_objs[IBM_MAX_ACPI_ARGS];
  357. struct acpi_buffer result, *resultp;
  358. union acpi_object out_obj;
  359. acpi_status status;
  360. va_list ap;
  361. char res_type;
  362. int success;
  363. int quiet;
  364. if (!*fmt) {
  365. printk(IBM_ERR "acpi_evalf() called with empty format\n");
  366. return 0;
  367. }
  368. if (*fmt == 'q') {
  369. quiet = 1;
  370. fmt++;
  371. } else
  372. quiet = 0;
  373. res_type = *(fmt++);
  374. params.count = 0;
  375. params.pointer = &in_objs[0];
  376. va_start(ap, fmt);
  377. while (*fmt) {
  378. char c = *(fmt++);
  379. switch (c) {
  380. case 'd': /* int */
  381. in_objs[params.count].integer.value = va_arg(ap, int);
  382. in_objs[params.count++].type = ACPI_TYPE_INTEGER;
  383. break;
  384. /* add more types as needed */
  385. default:
  386. printk(IBM_ERR "acpi_evalf() called "
  387. "with invalid format character '%c'\n", c);
  388. return 0;
  389. }
  390. }
  391. va_end(ap);
  392. if (res_type != 'v') {
  393. result.length = sizeof(out_obj);
  394. result.pointer = &out_obj;
  395. resultp = &result;
  396. } else
  397. resultp = NULL;
  398. status = acpi_evaluate_object(handle, method, &params, resultp);
  399. switch (res_type) {
  400. case 'd': /* int */
  401. if (res)
  402. *(int *)res = out_obj.integer.value;
  403. success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
  404. break;
  405. case 'v': /* void */
  406. success = status == AE_OK;
  407. break;
  408. /* add more types as needed */
  409. default:
  410. printk(IBM_ERR "acpi_evalf() called "
  411. "with invalid format character '%c'\n", res_type);
  412. return 0;
  413. }
  414. if (!success && !quiet)
  415. printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
  416. method, fmt0, status);
  417. return success;
  418. }
  419. static void __unused acpi_print_int(acpi_handle handle, char *method)
  420. {
  421. int i;
  422. if (acpi_evalf(handle, &i, method, "d"))
  423. printk(IBM_INFO "%s = 0x%x\n", method, i);
  424. else
  425. printk(IBM_ERR "error calling %s\n", method);
  426. }
  427. static char *next_cmd(char **cmds)
  428. {
  429. char *start = *cmds;
  430. char *end;
  431. while ((end = strchr(start, ',')) && end == start)
  432. start = end + 1;
  433. if (!end)
  434. return NULL;
  435. *end = 0;
  436. *cmds = end + 1;
  437. return start;
  438. }
  439. static int driver_init(void)
  440. {
  441. printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
  442. printk(IBM_INFO "%s\n", IBM_URL);
  443. return 0;
  444. }
  445. static int driver_read(char *p)
  446. {
  447. int len = 0;
  448. len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
  449. len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
  450. return len;
  451. }
  452. static int hotkey_supported;
  453. static int hotkey_mask_supported;
  454. static int hotkey_orig_status;
  455. static int hotkey_orig_mask;
  456. static int hotkey_get(int *status, int *mask)
  457. {
  458. if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
  459. return 0;
  460. if (hotkey_mask_supported)
  461. if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
  462. return 0;
  463. return 1;
  464. }
  465. static int hotkey_set(int status, int mask)
  466. {
  467. int i;
  468. if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
  469. return 0;
  470. if (hotkey_mask_supported)
  471. for (i = 0; i < 32; i++) {
  472. int bit = ((1 << i) & mask) != 0;
  473. if (!acpi_evalf(hkey_handle,
  474. NULL, "MHKM", "vdd", i + 1, bit))
  475. return 0;
  476. }
  477. return 1;
  478. }
  479. static int hotkey_init(void)
  480. {
  481. /* hotkey not supported on 570 */
  482. hotkey_supported = hkey_handle != NULL;
  483. if (hotkey_supported) {
  484. /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
  485. A30, R30, R31, T20-22, X20-21, X22-24 */
  486. hotkey_mask_supported =
  487. acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
  488. if (!hotkey_get(&hotkey_orig_status, &hotkey_orig_mask))
  489. return -ENODEV;
  490. }
  491. return 0;
  492. }
  493. static int hotkey_read(char *p)
  494. {
  495. int status, mask;
  496. int len = 0;
  497. if (!hotkey_supported) {
  498. len += sprintf(p + len, "status:\t\tnot supported\n");
  499. return len;
  500. }
  501. if (!hotkey_get(&status, &mask))
  502. return -EIO;
  503. len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
  504. if (hotkey_mask_supported) {
  505. len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
  506. len += sprintf(p + len,
  507. "commands:\tenable, disable, reset, <mask>\n");
  508. } else {
  509. len += sprintf(p + len, "mask:\t\tnot supported\n");
  510. len += sprintf(p + len, "commands:\tenable, disable, reset\n");
  511. }
  512. return len;
  513. }
  514. static int hotkey_write(char *buf)
  515. {
  516. int status, mask;
  517. char *cmd;
  518. int do_cmd = 0;
  519. if (!hotkey_supported)
  520. return -ENODEV;
  521. if (!hotkey_get(&status, &mask))
  522. return -EIO;
  523. while ((cmd = next_cmd(&buf))) {
  524. if (strlencmp(cmd, "enable") == 0) {
  525. status = 1;
  526. } else if (strlencmp(cmd, "disable") == 0) {
  527. status = 0;
  528. } else if (strlencmp(cmd, "reset") == 0) {
  529. status = hotkey_orig_status;
  530. mask = hotkey_orig_mask;
  531. } else if (sscanf(cmd, "0x%x", &mask) == 1) {
  532. /* mask set */
  533. } else if (sscanf(cmd, "%x", &mask) == 1) {
  534. /* mask set */
  535. } else
  536. return -EINVAL;
  537. do_cmd = 1;
  538. }
  539. if (do_cmd && !hotkey_set(status, mask))
  540. return -EIO;
  541. return 0;
  542. }
  543. static void hotkey_exit(void)
  544. {
  545. if (hotkey_supported)
  546. hotkey_set(hotkey_orig_status, hotkey_orig_mask);
  547. }
  548. static void hotkey_notify(struct ibm_struct *ibm, u32 event)
  549. {
  550. int hkey;
  551. if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
  552. acpi_bus_generate_event(ibm->device, event, hkey);
  553. else {
  554. printk(IBM_ERR "unknown hotkey event %d\n", event);
  555. acpi_bus_generate_event(ibm->device, event, 0);
  556. }
  557. }
  558. static int bluetooth_supported;
  559. static int bluetooth_init(void)
  560. {
  561. /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
  562. G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
  563. bluetooth_supported = hkey_handle &&
  564. acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
  565. return 0;
  566. }
  567. static int bluetooth_status(void)
  568. {
  569. int status;
  570. if (!bluetooth_supported ||
  571. !acpi_evalf(hkey_handle, &status, "GBDC", "d"))
  572. status = 0;
  573. return status;
  574. }
  575. static int bluetooth_read(char *p)
  576. {
  577. int len = 0;
  578. int status = bluetooth_status();
  579. if (!bluetooth_supported)
  580. len += sprintf(p + len, "status:\t\tnot supported\n");
  581. else if (!(status & 1))
  582. len += sprintf(p + len, "status:\t\tnot installed\n");
  583. else {
  584. len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
  585. len += sprintf(p + len, "commands:\tenable, disable\n");
  586. }
  587. return len;
  588. }
  589. static int bluetooth_write(char *buf)
  590. {
  591. int status = bluetooth_status();
  592. char *cmd;
  593. int do_cmd = 0;
  594. if (!bluetooth_supported)
  595. return -ENODEV;
  596. while ((cmd = next_cmd(&buf))) {
  597. if (strlencmp(cmd, "enable") == 0) {
  598. status |= 2;
  599. } else if (strlencmp(cmd, "disable") == 0) {
  600. status &= ~2;
  601. } else
  602. return -EINVAL;
  603. do_cmd = 1;
  604. }
  605. if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
  606. return -EIO;
  607. return 0;
  608. }
  609. static int wan_supported;
  610. static int wan_init(void)
  611. {
  612. wan_supported = hkey_handle &&
  613. acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
  614. return 0;
  615. }
  616. static int wan_status(void)
  617. {
  618. int status;
  619. if (!wan_supported || !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
  620. status = 0;
  621. return status;
  622. }
  623. static int wan_read(char *p)
  624. {
  625. int len = 0;
  626. int status = wan_status();
  627. if (!wan_supported)
  628. len += sprintf(p + len, "status:\t\tnot supported\n");
  629. else if (!(status & 1))
  630. len += sprintf(p + len, "status:\t\tnot installed\n");
  631. else {
  632. len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1));
  633. len += sprintf(p + len, "commands:\tenable, disable\n");
  634. }
  635. return len;
  636. }
  637. static int wan_write(char *buf)
  638. {
  639. int status = wan_status();
  640. char *cmd;
  641. int do_cmd = 0;
  642. if (!wan_supported)
  643. return -ENODEV;
  644. while ((cmd = next_cmd(&buf))) {
  645. if (strlencmp(cmd, "enable") == 0) {
  646. status |= 2;
  647. } else if (strlencmp(cmd, "disable") == 0) {
  648. status &= ~2;
  649. } else
  650. return -EINVAL;
  651. do_cmd = 1;
  652. }
  653. if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
  654. return -EIO;
  655. return 0;
  656. }
  657. static int video_supported;
  658. static int video_orig_autosw;
  659. #define VIDEO_570 1
  660. #define VIDEO_770 2
  661. #define VIDEO_NEW 3
  662. static int video_init(void)
  663. {
  664. int ivga;
  665. if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
  666. /* G41, assume IVGA doesn't change */
  667. vid_handle = vid2_handle;
  668. if (!vid_handle)
  669. /* video switching not supported on R30, R31 */
  670. video_supported = 0;
  671. else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
  672. /* 570 */
  673. video_supported = VIDEO_570;
  674. else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
  675. /* 600e/x, 770e, 770x */
  676. video_supported = VIDEO_770;
  677. else
  678. /* all others */
  679. video_supported = VIDEO_NEW;
  680. return 0;
  681. }
  682. static int video_status(void)
  683. {
  684. int status = 0;
  685. int i;
  686. if (video_supported == VIDEO_570) {
  687. if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87))
  688. status = i & 3;
  689. } else if (video_supported == VIDEO_770) {
  690. if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
  691. status |= 0x01 * i;
  692. if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
  693. status |= 0x02 * i;
  694. } else if (video_supported == VIDEO_NEW) {
  695. acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
  696. if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
  697. status |= 0x02 * i;
  698. acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0);
  699. if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
  700. status |= 0x01 * i;
  701. if (acpi_evalf(NULL, &i, "\\VCDD", "d"))
  702. status |= 0x08 * i;
  703. }
  704. return status;
  705. }
  706. static int video_autosw(void)
  707. {
  708. int autosw = 0;
  709. if (video_supported == VIDEO_570)
  710. acpi_evalf(vid_handle, &autosw, "SWIT", "d");
  711. else if (video_supported == VIDEO_770 || video_supported == VIDEO_NEW)
  712. acpi_evalf(vid_handle, &autosw, "^VDEE", "d");
  713. return autosw & 1;
  714. }
  715. static int video_read(char *p)
  716. {
  717. int status = video_status();
  718. int autosw = video_autosw();
  719. int len = 0;
  720. if (!video_supported) {
  721. len += sprintf(p + len, "status:\t\tnot supported\n");
  722. return len;
  723. }
  724. len += sprintf(p + len, "status:\t\tsupported\n");
  725. len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
  726. len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
  727. if (video_supported == VIDEO_NEW)
  728. len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
  729. len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
  730. len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
  731. len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
  732. if (video_supported == VIDEO_NEW)
  733. len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
  734. len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
  735. len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
  736. return len;
  737. }
  738. static int video_switch(void)
  739. {
  740. int autosw = video_autosw();
  741. int ret;
  742. if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
  743. return -EIO;
  744. ret = video_supported == VIDEO_570 ?
  745. acpi_evalf(ec_handle, NULL, "_Q16", "v") :
  746. acpi_evalf(vid_handle, NULL, "VSWT", "v");
  747. acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
  748. return ret;
  749. }
  750. static int video_expand(void)
  751. {
  752. if (video_supported == VIDEO_570)
  753. return acpi_evalf(ec_handle, NULL, "_Q17", "v");
  754. else if (video_supported == VIDEO_770)
  755. return acpi_evalf(vid_handle, NULL, "VEXP", "v");
  756. else
  757. return acpi_evalf(NULL, NULL, "\\VEXP", "v");
  758. }
  759. static int video_switch2(int status)
  760. {
  761. int ret;
  762. if (video_supported == VIDEO_570) {
  763. ret = acpi_evalf(NULL, NULL,
  764. "\\_SB.PHS2", "vdd", 0x8b, status | 0x80);
  765. } else if (video_supported == VIDEO_770) {
  766. int autosw = video_autosw();
  767. if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
  768. return -EIO;
  769. ret = acpi_evalf(vid_handle, NULL,
  770. "ASWT", "vdd", status * 0x100, 0);
  771. acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
  772. } else {
  773. ret = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
  774. acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
  775. }
  776. return ret;
  777. }
  778. static int video_write(char *buf)
  779. {
  780. char *cmd;
  781. int enable, disable, status;
  782. if (!video_supported)
  783. return -ENODEV;
  784. enable = disable = 0;
  785. while ((cmd = next_cmd(&buf))) {
  786. if (strlencmp(cmd, "lcd_enable") == 0) {
  787. enable |= 0x01;
  788. } else if (strlencmp(cmd, "lcd_disable") == 0) {
  789. disable |= 0x01;
  790. } else if (strlencmp(cmd, "crt_enable") == 0) {
  791. enable |= 0x02;
  792. } else if (strlencmp(cmd, "crt_disable") == 0) {
  793. disable |= 0x02;
  794. } else if (video_supported == VIDEO_NEW &&
  795. strlencmp(cmd, "dvi_enable") == 0) {
  796. enable |= 0x08;
  797. } else if (video_supported == VIDEO_NEW &&
  798. strlencmp(cmd, "dvi_disable") == 0) {
  799. disable |= 0x08;
  800. } else if (strlencmp(cmd, "auto_enable") == 0) {
  801. if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
  802. return -EIO;
  803. } else if (strlencmp(cmd, "auto_disable") == 0) {
  804. if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 0))
  805. return -EIO;
  806. } else if (strlencmp(cmd, "video_switch") == 0) {
  807. if (!video_switch())
  808. return -EIO;
  809. } else if (strlencmp(cmd, "expand_toggle") == 0) {
  810. if (!video_expand())
  811. return -EIO;
  812. } else
  813. return -EINVAL;
  814. }
  815. if (enable || disable) {
  816. status = (video_status() & 0x0f & ~disable) | enable;
  817. if (!video_switch2(status))
  818. return -EIO;
  819. }
  820. return 0;
  821. }
  822. static void video_exit(void)
  823. {
  824. acpi_evalf(vid_handle, NULL, "_DOS", "vd", video_orig_autosw);
  825. }
  826. static int light_supported;
  827. static int light_status_supported;
  828. static int light_init(void)
  829. {
  830. /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
  831. light_supported = (cmos_handle || lght_handle) && !ledb_handle;
  832. if (light_supported)
  833. /* light status not supported on
  834. 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
  835. light_status_supported = acpi_evalf(ec_handle, NULL,
  836. "KBLT", "qv");
  837. return 0;
  838. }
  839. static int light_read(char *p)
  840. {
  841. int len = 0;
  842. int status = 0;
  843. if (!light_supported) {
  844. len += sprintf(p + len, "status:\t\tnot supported\n");
  845. } else if (!light_status_supported) {
  846. len += sprintf(p + len, "status:\t\tunknown\n");
  847. len += sprintf(p + len, "commands:\ton, off\n");
  848. } else {
  849. if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
  850. return -EIO;
  851. len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
  852. len += sprintf(p + len, "commands:\ton, off\n");
  853. }
  854. return len;
  855. }
  856. static int light_write(char *buf)
  857. {
  858. int cmos_cmd, lght_cmd;
  859. char *cmd;
  860. int success;
  861. if (!light_supported)
  862. return -ENODEV;
  863. while ((cmd = next_cmd(&buf))) {
  864. if (strlencmp(cmd, "on") == 0) {
  865. cmos_cmd = 0x0c;
  866. lght_cmd = 1;
  867. } else if (strlencmp(cmd, "off") == 0) {
  868. cmos_cmd = 0x0d;
  869. lght_cmd = 0;
  870. } else
  871. return -EINVAL;
  872. success = cmos_handle ?
  873. acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
  874. acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
  875. if (!success)
  876. return -EIO;
  877. }
  878. return 0;
  879. }
  880. static int _sta(acpi_handle handle)
  881. {
  882. int status;
  883. if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
  884. status = 0;
  885. return status;
  886. }
  887. #ifdef CONFIG_ACPI_IBM_DOCK
  888. #define dock_docked() (_sta(dock_handle) & 1)
  889. static int dock_read(char *p)
  890. {
  891. int len = 0;
  892. int docked = dock_docked();
  893. if (!dock_handle)
  894. len += sprintf(p + len, "status:\t\tnot supported\n");
  895. else if (!docked)
  896. len += sprintf(p + len, "status:\t\tundocked\n");
  897. else {
  898. len += sprintf(p + len, "status:\t\tdocked\n");
  899. len += sprintf(p + len, "commands:\tdock, undock\n");
  900. }
  901. return len;
  902. }
  903. static int dock_write(char *buf)
  904. {
  905. char *cmd;
  906. if (!dock_docked())
  907. return -ENODEV;
  908. while ((cmd = next_cmd(&buf))) {
  909. if (strlencmp(cmd, "undock") == 0) {
  910. if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
  911. !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
  912. return -EIO;
  913. } else if (strlencmp(cmd, "dock") == 0) {
  914. if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
  915. return -EIO;
  916. } else
  917. return -EINVAL;
  918. }
  919. return 0;
  920. }
  921. static void dock_notify(struct ibm_struct *ibm, u32 event)
  922. {
  923. int docked = dock_docked();
  924. int pci = ibm->hid && strstr(ibm->hid, IBM_PCI_HID);
  925. if (event == 1 && !pci) /* 570 */
  926. acpi_bus_generate_event(ibm->device, event, 1); /* button */
  927. else if (event == 1 && pci) /* 570 */
  928. acpi_bus_generate_event(ibm->device, event, 3); /* dock */
  929. else if (event == 3 && docked)
  930. acpi_bus_generate_event(ibm->device, event, 1); /* button */
  931. else if (event == 3 && !docked)
  932. acpi_bus_generate_event(ibm->device, event, 2); /* undock */
  933. else if (event == 0 && docked)
  934. acpi_bus_generate_event(ibm->device, event, 3); /* dock */
  935. else {
  936. printk(IBM_ERR "unknown dock event %d, status %d\n",
  937. event, _sta(dock_handle));
  938. acpi_bus_generate_event(ibm->device, event, 0); /* unknown */
  939. }
  940. }
  941. #endif
  942. static int bay_status_supported;
  943. static int bay_status2_supported;
  944. static int bay_eject_supported;
  945. static int bay_eject2_supported;
  946. static int bay_init(void)
  947. {
  948. bay_status_supported = bay_handle &&
  949. acpi_evalf(bay_handle, NULL, "_STA", "qv");
  950. bay_status2_supported = bay2_handle &&
  951. acpi_evalf(bay2_handle, NULL, "_STA", "qv");
  952. bay_eject_supported = bay_handle && bay_ej_handle &&
  953. (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
  954. bay_eject2_supported = bay2_handle && bay2_ej_handle &&
  955. (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
  956. return 0;
  957. }
  958. #define bay_occupied(b) (_sta(b##_handle) & 1)
  959. static int bay_read(char *p)
  960. {
  961. int len = 0;
  962. int occupied = bay_occupied(bay);
  963. int occupied2 = bay_occupied(bay2);
  964. int eject, eject2;
  965. len += sprintf(p + len, "status:\t\t%s\n", bay_status_supported ?
  966. (occupied ? "occupied" : "unoccupied") :
  967. "not supported");
  968. if (bay_status2_supported)
  969. len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
  970. "occupied" : "unoccupied");
  971. eject = bay_eject_supported && occupied;
  972. eject2 = bay_eject2_supported && occupied2;
  973. if (eject && eject2)
  974. len += sprintf(p + len, "commands:\teject, eject2\n");
  975. else if (eject)
  976. len += sprintf(p + len, "commands:\teject\n");
  977. else if (eject2)
  978. len += sprintf(p + len, "commands:\teject2\n");
  979. return len;
  980. }
  981. static int bay_write(char *buf)
  982. {
  983. char *cmd;
  984. if (!bay_eject_supported && !bay_eject2_supported)
  985. return -ENODEV;
  986. while ((cmd = next_cmd(&buf))) {
  987. if (bay_eject_supported && strlencmp(cmd, "eject") == 0) {
  988. if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
  989. return -EIO;
  990. } else if (bay_eject2_supported &&
  991. strlencmp(cmd, "eject2") == 0) {
  992. if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
  993. return -EIO;
  994. } else
  995. return -EINVAL;
  996. }
  997. return 0;
  998. }
  999. static void bay_notify(struct ibm_struct *ibm, u32 event)
  1000. {
  1001. acpi_bus_generate_event(ibm->device, event, 0);
  1002. }
  1003. static int cmos_read(char *p)
  1004. {
  1005. int len = 0;
  1006. /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
  1007. R30, R31, T20-22, X20-21 */
  1008. if (!cmos_handle)
  1009. len += sprintf(p + len, "status:\t\tnot supported\n");
  1010. else {
  1011. len += sprintf(p + len, "status:\t\tsupported\n");
  1012. len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
  1013. }
  1014. return len;
  1015. }
  1016. static int cmos_eval(int cmos_cmd)
  1017. {
  1018. if (cmos_handle)
  1019. return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd);
  1020. else
  1021. return 1;
  1022. }
  1023. static int cmos_write(char *buf)
  1024. {
  1025. char *cmd;
  1026. int cmos_cmd;
  1027. if (!cmos_handle)
  1028. return -EINVAL;
  1029. while ((cmd = next_cmd(&buf))) {
  1030. if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
  1031. cmos_cmd >= 0 && cmos_cmd <= 21) {
  1032. /* cmos_cmd set */
  1033. } else
  1034. return -EINVAL;
  1035. if (!cmos_eval(cmos_cmd))
  1036. return -EIO;
  1037. }
  1038. return 0;
  1039. }
  1040. static int led_supported;
  1041. #define LED_570 1
  1042. #define LED_OLD 2
  1043. #define LED_NEW 3
  1044. static int led_init(void)
  1045. {
  1046. if (!led_handle)
  1047. /* led not supported on R30, R31 */
  1048. led_supported = 0;
  1049. else if (strlencmp(led_path, "SLED") == 0)
  1050. /* 570 */
  1051. led_supported = LED_570;
  1052. else if (strlencmp(led_path, "SYSL") == 0)
  1053. /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
  1054. led_supported = LED_OLD;
  1055. else
  1056. /* all others */
  1057. led_supported = LED_NEW;
  1058. return 0;
  1059. }
  1060. #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
  1061. static int led_read(char *p)
  1062. {
  1063. int len = 0;
  1064. if (!led_supported) {
  1065. len += sprintf(p + len, "status:\t\tnot supported\n");
  1066. return len;
  1067. }
  1068. len += sprintf(p + len, "status:\t\tsupported\n");
  1069. if (led_supported == LED_570) {
  1070. /* 570 */
  1071. int i, status;
  1072. for (i = 0; i < 8; i++) {
  1073. if (!acpi_evalf(ec_handle,
  1074. &status, "GLED", "dd", 1 << i))
  1075. return -EIO;
  1076. len += sprintf(p + len, "%d:\t\t%s\n",
  1077. i, led_status(status));
  1078. }
  1079. }
  1080. len += sprintf(p + len, "commands:\t"
  1081. "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
  1082. return len;
  1083. }
  1084. /* off, on, blink */
  1085. static const int led_sled_arg1[] = { 0, 1, 3 };
  1086. static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
  1087. static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
  1088. static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
  1089. #define EC_HLCL 0x0c
  1090. #define EC_HLBL 0x0d
  1091. #define EC_HLMS 0x0e
  1092. static int led_write(char *buf)
  1093. {
  1094. char *cmd;
  1095. int led, ind, ret;
  1096. if (!led_supported)
  1097. return -ENODEV;
  1098. while ((cmd = next_cmd(&buf))) {
  1099. if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
  1100. return -EINVAL;
  1101. if (strstr(cmd, "off")) {
  1102. ind = 0;
  1103. } else if (strstr(cmd, "on")) {
  1104. ind = 1;
  1105. } else if (strstr(cmd, "blink")) {
  1106. ind = 2;
  1107. } else
  1108. return -EINVAL;
  1109. if (led_supported == LED_570) {
  1110. /* 570 */
  1111. led = 1 << led;
  1112. if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
  1113. led, led_sled_arg1[ind]))
  1114. return -EIO;
  1115. } else if (led_supported == LED_OLD) {
  1116. /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
  1117. led = 1 << led;
  1118. ret = ec_write(EC_HLMS, led);
  1119. if (ret >= 0)
  1120. ret =
  1121. ec_write(EC_HLBL, led * led_exp_hlbl[ind]);
  1122. if (ret >= 0)
  1123. ret =
  1124. ec_write(EC_HLCL, led * led_exp_hlcl[ind]);
  1125. if (ret < 0)
  1126. return ret;
  1127. } else {
  1128. /* all others */
  1129. if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
  1130. led, led_led_arg1[ind]))
  1131. return -EIO;
  1132. }
  1133. }
  1134. return 0;
  1135. }
  1136. static int beep_read(char *p)
  1137. {
  1138. int len = 0;
  1139. if (!beep_handle)
  1140. len += sprintf(p + len, "status:\t\tnot supported\n");
  1141. else {
  1142. len += sprintf(p + len, "status:\t\tsupported\n");
  1143. len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
  1144. }
  1145. return len;
  1146. }
  1147. static int beep_write(char *buf)
  1148. {
  1149. char *cmd;
  1150. int beep_cmd;
  1151. if (!beep_handle)
  1152. return -ENODEV;
  1153. while ((cmd = next_cmd(&buf))) {
  1154. if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
  1155. beep_cmd >= 0 && beep_cmd <= 17) {
  1156. /* beep_cmd set */
  1157. } else
  1158. return -EINVAL;
  1159. if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
  1160. return -EIO;
  1161. }
  1162. return 0;
  1163. }
  1164. static int acpi_ec_read(int i, u8 * p)
  1165. {
  1166. int v;
  1167. if (ecrd_handle) {
  1168. if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
  1169. return 0;
  1170. *p = v;
  1171. } else {
  1172. if (ec_read(i, p) < 0)
  1173. return 0;
  1174. }
  1175. return 1;
  1176. }
  1177. static int acpi_ec_write(int i, u8 v)
  1178. {
  1179. if (ecwr_handle) {
  1180. if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
  1181. return 0;
  1182. } else {
  1183. if (ec_write(i, v) < 0)
  1184. return 0;
  1185. }
  1186. return 1;
  1187. }
  1188. static enum thermal_access_mode thermal_read_mode;
  1189. static int thermal_init(void)
  1190. {
  1191. u8 t, ta1, ta2;
  1192. int i;
  1193. int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
  1194. if (ibm_thinkpad_ec_found && experimental) {
  1195. /*
  1196. * Direct EC access mode: sensors at registers
  1197. * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
  1198. * non-implemented, thermal sensors return 0x80 when
  1199. * not available
  1200. */
  1201. ta1 = ta2 = 0;
  1202. for (i = 0; i < 8; i++) {
  1203. if (likely(acpi_ec_read(0x78 + i, &t))) {
  1204. ta1 |= t;
  1205. } else {
  1206. ta1 = 0;
  1207. break;
  1208. }
  1209. if (likely(acpi_ec_read(0xC0 + i, &t))) {
  1210. ta2 |= t;
  1211. } else {
  1212. ta1 = 0;
  1213. break;
  1214. }
  1215. }
  1216. if (ta1 == 0) {
  1217. /* This is sheer paranoia, but we handle it anyway */
  1218. if (acpi_tmp7) {
  1219. printk(IBM_ERR
  1220. "ThinkPad ACPI EC access misbehaving, "
  1221. "falling back to ACPI TMPx access mode\n");
  1222. thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
  1223. } else {
  1224. printk(IBM_ERR
  1225. "ThinkPad ACPI EC access misbehaving, "
  1226. "disabling thermal sensors access\n");
  1227. thermal_read_mode = IBMACPI_THERMAL_NONE;
  1228. }
  1229. } else {
  1230. thermal_read_mode =
  1231. (ta2 != 0) ?
  1232. IBMACPI_THERMAL_TPEC_16 : IBMACPI_THERMAL_TPEC_8;
  1233. }
  1234. } else if (acpi_tmp7) {
  1235. if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
  1236. /* 600e/x, 770e, 770x */
  1237. thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT;
  1238. } else {
  1239. /* Standard ACPI TMPx access, max 8 sensors */
  1240. thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
  1241. }
  1242. } else {
  1243. /* temperatures not supported on 570, G4x, R30, R31, R32 */
  1244. thermal_read_mode = IBMACPI_THERMAL_NONE;
  1245. }
  1246. return 0;
  1247. }
  1248. static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
  1249. {
  1250. int i, t;
  1251. s8 tmp;
  1252. char tmpi[] = "TMPi";
  1253. if (!s)
  1254. return -EINVAL;
  1255. switch (thermal_read_mode) {
  1256. #if IBMACPI_MAX_THERMAL_SENSORS >= 16
  1257. case IBMACPI_THERMAL_TPEC_16:
  1258. for (i = 0; i < 8; i++) {
  1259. if (!acpi_ec_read(0xC0 + i, &tmp))
  1260. return -EIO;
  1261. s->temp[i + 8] = tmp * 1000;
  1262. }
  1263. /* fallthrough */
  1264. #endif
  1265. case IBMACPI_THERMAL_TPEC_8:
  1266. for (i = 0; i < 8; i++) {
  1267. if (!acpi_ec_read(0x78 + i, &tmp))
  1268. return -EIO;
  1269. s->temp[i] = tmp * 1000;
  1270. }
  1271. return (thermal_read_mode == IBMACPI_THERMAL_TPEC_16) ? 16 : 8;
  1272. case IBMACPI_THERMAL_ACPI_UPDT:
  1273. if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
  1274. return -EIO;
  1275. for (i = 0; i < 8; i++) {
  1276. tmpi[3] = '0' + i;
  1277. if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
  1278. return -EIO;
  1279. s->temp[i] = (t - 2732) * 100;
  1280. }
  1281. return 8;
  1282. case IBMACPI_THERMAL_ACPI_TMP07:
  1283. for (i = 0; i < 8; i++) {
  1284. tmpi[3] = '0' + i;
  1285. if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
  1286. return -EIO;
  1287. s->temp[i] = t * 1000;
  1288. }
  1289. return 8;
  1290. case IBMACPI_THERMAL_NONE:
  1291. default:
  1292. return 0;
  1293. }
  1294. }
  1295. static int thermal_read(char *p)
  1296. {
  1297. int len = 0;
  1298. int n, i;
  1299. struct ibm_thermal_sensors_struct t;
  1300. n = thermal_get_sensors(&t);
  1301. if (unlikely(n < 0))
  1302. return n;
  1303. len += sprintf(p + len, "temperatures:\t");
  1304. if (n > 0) {
  1305. for (i = 0; i < (n - 1); i++)
  1306. len += sprintf(p + len, "%d ", t.temp[i] / 1000);
  1307. len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
  1308. } else
  1309. len += sprintf(p + len, "not supported\n");
  1310. return len;
  1311. }
  1312. static u8 ecdump_regs[256];
  1313. static int ecdump_read(char *p)
  1314. {
  1315. int len = 0;
  1316. int i, j;
  1317. u8 v;
  1318. len += sprintf(p + len, "EC "
  1319. " +00 +01 +02 +03 +04 +05 +06 +07"
  1320. " +08 +09 +0a +0b +0c +0d +0e +0f\n");
  1321. for (i = 0; i < 256; i += 16) {
  1322. len += sprintf(p + len, "EC 0x%02x:", i);
  1323. for (j = 0; j < 16; j++) {
  1324. if (!acpi_ec_read(i + j, &v))
  1325. break;
  1326. if (v != ecdump_regs[i + j])
  1327. len += sprintf(p + len, " *%02x", v);
  1328. else
  1329. len += sprintf(p + len, " %02x", v);
  1330. ecdump_regs[i + j] = v;
  1331. }
  1332. len += sprintf(p + len, "\n");
  1333. if (j != 16)
  1334. break;
  1335. }
  1336. /* These are way too dangerous to advertise openly... */
  1337. #if 0
  1338. len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
  1339. " (<offset> is 00-ff, <value> is 00-ff)\n");
  1340. len += sprintf(p + len, "commands:\t0x<offset> <value> "
  1341. " (<offset> is 00-ff, <value> is 0-255)\n");
  1342. #endif
  1343. return len;
  1344. }
  1345. static int ecdump_write(char *buf)
  1346. {
  1347. char *cmd;
  1348. int i, v;
  1349. while ((cmd = next_cmd(&buf))) {
  1350. if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
  1351. /* i and v set */
  1352. } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
  1353. /* i and v set */
  1354. } else
  1355. return -EINVAL;
  1356. if (i >= 0 && i < 256 && v >= 0 && v < 256) {
  1357. if (!acpi_ec_write(i, v))
  1358. return -EIO;
  1359. } else
  1360. return -EINVAL;
  1361. }
  1362. return 0;
  1363. }
  1364. static int brightness_offset = 0x31;
  1365. static int brightness_get(struct backlight_device *bd)
  1366. {
  1367. u8 level;
  1368. if (!acpi_ec_read(brightness_offset, &level))
  1369. return -EIO;
  1370. level &= 0x7;
  1371. return level;
  1372. }
  1373. static int brightness_read(char *p)
  1374. {
  1375. int len = 0;
  1376. int level;
  1377. if ((level = brightness_get(NULL)) < 0) {
  1378. len += sprintf(p + len, "level:\t\tunreadable\n");
  1379. } else {
  1380. len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
  1381. len += sprintf(p + len, "commands:\tup, down\n");
  1382. len += sprintf(p + len, "commands:\tlevel <level>"
  1383. " (<level> is 0-7)\n");
  1384. }
  1385. return len;
  1386. }
  1387. #define BRIGHTNESS_UP 4
  1388. #define BRIGHTNESS_DOWN 5
  1389. static int brightness_set(int value)
  1390. {
  1391. int cmos_cmd, inc, i;
  1392. int current_value = brightness_get(NULL);
  1393. value &= 7;
  1394. cmos_cmd = value > current_value ? BRIGHTNESS_UP : BRIGHTNESS_DOWN;
  1395. inc = value > current_value ? 1 : -1;
  1396. for (i = current_value; i != value; i += inc) {
  1397. if (!cmos_eval(cmos_cmd))
  1398. return -EIO;
  1399. if (!acpi_ec_write(brightness_offset, i + inc))
  1400. return -EIO;
  1401. }
  1402. return 0;
  1403. }
  1404. static int brightness_write(char *buf)
  1405. {
  1406. int level;
  1407. int new_level;
  1408. char *cmd;
  1409. while ((cmd = next_cmd(&buf))) {
  1410. if ((level = brightness_get(NULL)) < 0)
  1411. return level;
  1412. level &= 7;
  1413. if (strlencmp(cmd, "up") == 0) {
  1414. new_level = level == 7 ? 7 : level + 1;
  1415. } else if (strlencmp(cmd, "down") == 0) {
  1416. new_level = level == 0 ? 0 : level - 1;
  1417. } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
  1418. new_level >= 0 && new_level <= 7) {
  1419. /* new_level set */
  1420. } else
  1421. return -EINVAL;
  1422. brightness_set(new_level);
  1423. }
  1424. return 0;
  1425. }
  1426. static int brightness_update_status(struct backlight_device *bd)
  1427. {
  1428. return brightness_set(bd->props->brightness);
  1429. }
  1430. static int volume_offset = 0x30;
  1431. static int volume_read(char *p)
  1432. {
  1433. int len = 0;
  1434. u8 level;
  1435. if (!acpi_ec_read(volume_offset, &level)) {
  1436. len += sprintf(p + len, "level:\t\tunreadable\n");
  1437. } else {
  1438. len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
  1439. len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
  1440. len += sprintf(p + len, "commands:\tup, down, mute\n");
  1441. len += sprintf(p + len, "commands:\tlevel <level>"
  1442. " (<level> is 0-15)\n");
  1443. }
  1444. return len;
  1445. }
  1446. #define VOLUME_DOWN 0
  1447. #define VOLUME_UP 1
  1448. #define VOLUME_MUTE 2
  1449. static int volume_write(char *buf)
  1450. {
  1451. int cmos_cmd, inc, i;
  1452. u8 level, mute;
  1453. int new_level, new_mute;
  1454. char *cmd;
  1455. while ((cmd = next_cmd(&buf))) {
  1456. if (!acpi_ec_read(volume_offset, &level))
  1457. return -EIO;
  1458. new_mute = mute = level & 0x40;
  1459. new_level = level = level & 0xf;
  1460. if (strlencmp(cmd, "up") == 0) {
  1461. if (mute)
  1462. new_mute = 0;
  1463. else
  1464. new_level = level == 15 ? 15 : level + 1;
  1465. } else if (strlencmp(cmd, "down") == 0) {
  1466. if (mute)
  1467. new_mute = 0;
  1468. else
  1469. new_level = level == 0 ? 0 : level - 1;
  1470. } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
  1471. new_level >= 0 && new_level <= 15) {
  1472. /* new_level set */
  1473. } else if (strlencmp(cmd, "mute") == 0) {
  1474. new_mute = 0x40;
  1475. } else
  1476. return -EINVAL;
  1477. if (new_level != level) { /* mute doesn't change */
  1478. cmos_cmd = new_level > level ? VOLUME_UP : VOLUME_DOWN;
  1479. inc = new_level > level ? 1 : -1;
  1480. if (mute && (!cmos_eval(cmos_cmd) ||
  1481. !acpi_ec_write(volume_offset, level)))
  1482. return -EIO;
  1483. for (i = level; i != new_level; i += inc)
  1484. if (!cmos_eval(cmos_cmd) ||
  1485. !acpi_ec_write(volume_offset, i + inc))
  1486. return -EIO;
  1487. if (mute && (!cmos_eval(VOLUME_MUTE) ||
  1488. !acpi_ec_write(volume_offset,
  1489. new_level + mute)))
  1490. return -EIO;
  1491. }
  1492. if (new_mute != mute) { /* level doesn't change */
  1493. cmos_cmd = new_mute ? VOLUME_MUTE : VOLUME_UP;
  1494. if (!cmos_eval(cmos_cmd) ||
  1495. !acpi_ec_write(volume_offset, level + new_mute))
  1496. return -EIO;
  1497. }
  1498. }
  1499. return 0;
  1500. }
  1501. static enum fan_status_access_mode fan_status_access_mode;
  1502. static enum fan_control_access_mode fan_control_access_mode;
  1503. static enum fan_control_commands fan_control_commands;
  1504. static int fan_init(void)
  1505. {
  1506. u8 status;
  1507. fan_status_access_mode = IBMACPI_FAN_NONE;
  1508. fan_control_access_mode = IBMACPI_FAN_WR_NONE;
  1509. fan_control_commands = 0;
  1510. if (gfan_handle) {
  1511. /* 570, 600e/x, 770e, 770x */
  1512. fan_status_access_mode = IBMACPI_FAN_RD_ACPI_GFAN;
  1513. } else {
  1514. /* all other ThinkPads: note that even old-style
  1515. * ThinkPad ECs supports the fan control register */
  1516. if (likely(acpi_ec_read(fan_status_offset, &status))) {
  1517. fan_status_access_mode = IBMACPI_FAN_RD_TPEC;
  1518. } else {
  1519. printk(IBM_ERR
  1520. "ThinkPad ACPI EC access misbehaving, "
  1521. "fan status and control unavailable\n");
  1522. return 0;
  1523. }
  1524. }
  1525. if (sfan_handle) {
  1526. /* 570, 770x-JL */
  1527. fan_control_access_mode = IBMACPI_FAN_WR_ACPI_SFAN;
  1528. fan_control_commands |= IBMACPI_FAN_CMD_LEVEL;
  1529. } else {
  1530. if (!gfan_handle) {
  1531. /* gfan without sfan means no fan control */
  1532. /* all other models implement TP EC 0x2f control */
  1533. if (fans_handle) {
  1534. /* X31, X40, X41 */
  1535. fan_control_access_mode =
  1536. IBMACPI_FAN_WR_ACPI_FANS;
  1537. fan_control_commands |=
  1538. IBMACPI_FAN_CMD_SPEED |
  1539. IBMACPI_FAN_CMD_ENABLE;
  1540. } else {
  1541. fan_control_access_mode = IBMACPI_FAN_WR_TPEC;
  1542. fan_control_commands |= IBMACPI_FAN_CMD_ENABLE;
  1543. }
  1544. }
  1545. }
  1546. return 0;
  1547. }
  1548. static int fan_get_status(u8 *status)
  1549. {
  1550. u8 s;
  1551. /* TODO:
  1552. * Add IBMACPI_FAN_RD_ACPI_FANS ? */
  1553. switch (fan_status_access_mode) {
  1554. case IBMACPI_FAN_RD_ACPI_GFAN:
  1555. /* 570, 600e/x, 770e, 770x */
  1556. if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
  1557. return -EIO;
  1558. if (likely(status))
  1559. *status = s & 0x07;
  1560. break;
  1561. case IBMACPI_FAN_RD_TPEC:
  1562. /* all except 570, 600e/x, 770e, 770x */
  1563. if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
  1564. return -EIO;
  1565. if (likely(status))
  1566. *status = s;
  1567. break;
  1568. default:
  1569. return -ENXIO;
  1570. }
  1571. return 0;
  1572. }
  1573. static int fan_get_speed(unsigned int *speed)
  1574. {
  1575. u8 hi, lo;
  1576. switch (fan_status_access_mode) {
  1577. case IBMACPI_FAN_RD_TPEC:
  1578. /* all except 570, 600e/x, 770e, 770x */
  1579. if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
  1580. !acpi_ec_read(fan_rpm_offset + 1, &hi)))
  1581. return -EIO;
  1582. if (likely(speed))
  1583. *speed = (hi << 8) | lo;
  1584. break;
  1585. default:
  1586. return -ENXIO;
  1587. }
  1588. return 0;
  1589. }
  1590. static int fan_read(char *p)
  1591. {
  1592. int len = 0;
  1593. int rc;
  1594. u8 status;
  1595. unsigned int speed = 0;
  1596. switch (fan_status_access_mode) {
  1597. case IBMACPI_FAN_RD_ACPI_GFAN:
  1598. /* 570, 600e/x, 770e, 770x */
  1599. if ((rc = fan_get_status(&status)) < 0)
  1600. return rc;
  1601. len += sprintf(p + len, "status:\t\t%s\n"
  1602. "level:\t\t%d\n",
  1603. (status != 0) ? "enabled" : "disabled", status);
  1604. break;
  1605. case IBMACPI_FAN_RD_TPEC:
  1606. /* all except 570, 600e/x, 770e, 770x */
  1607. if ((rc = fan_get_status(&status)) < 0)
  1608. return rc;
  1609. len += sprintf(p + len, "status:\t\t%s\n",
  1610. (status != 0) ? "enabled" : "disabled");
  1611. if ((rc = fan_get_speed(&speed)) < 0)
  1612. return rc;
  1613. len += sprintf(p + len, "speed:\t\t%d\n", speed);
  1614. if (status & IBMACPI_FAN_EC_DISENGAGED)
  1615. /* Disengaged mode takes precedence */
  1616. len += sprintf(p + len, "level:\t\tdisengaged\n");
  1617. else if (status & IBMACPI_FAN_EC_AUTO)
  1618. len += sprintf(p + len, "level:\t\tauto\n");
  1619. else
  1620. len += sprintf(p + len, "level:\t\t%d\n", status);
  1621. break;
  1622. case IBMACPI_FAN_NONE:
  1623. default:
  1624. len += sprintf(p + len, "status:\t\tnot supported\n");
  1625. }
  1626. if (fan_control_commands & IBMACPI_FAN_CMD_LEVEL)
  1627. len += sprintf(p + len, "commands:\tlevel <level>"
  1628. " (<level> is 0-7)\n");
  1629. if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE)
  1630. len += sprintf(p + len, "commands:\tenable, disable\n");
  1631. if (fan_control_commands & IBMACPI_FAN_CMD_SPEED)
  1632. len += sprintf(p + len, "commands:\tspeed <speed>"
  1633. " (<speed> is 0-65535)\n");
  1634. return len;
  1635. }
  1636. static int fan_set_level(int level)
  1637. {
  1638. switch (fan_control_access_mode) {
  1639. case IBMACPI_FAN_WR_ACPI_SFAN:
  1640. if (level >= 0 && level <= 7) {
  1641. if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
  1642. return -EIO;
  1643. } else
  1644. return -EINVAL;
  1645. break;
  1646. default:
  1647. return -ENXIO;
  1648. }
  1649. return 0;
  1650. }
  1651. static int fan_set_enable(void)
  1652. {
  1653. switch (fan_control_access_mode) {
  1654. case IBMACPI_FAN_WR_ACPI_FANS:
  1655. case IBMACPI_FAN_WR_TPEC:
  1656. if (!acpi_ec_write(fan_status_offset, 0x80))
  1657. return -EIO;
  1658. break;
  1659. default:
  1660. return -ENXIO;
  1661. }
  1662. return 0;
  1663. }
  1664. static int fan_set_disable(void)
  1665. {
  1666. switch (fan_control_access_mode) {
  1667. case IBMACPI_FAN_WR_ACPI_FANS:
  1668. case IBMACPI_FAN_WR_TPEC:
  1669. if (!acpi_ec_write(fan_status_offset, 0x00))
  1670. return -EIO;
  1671. break;
  1672. default:
  1673. return -ENXIO;
  1674. }
  1675. return 0;
  1676. }
  1677. static int fan_set_speed(int speed)
  1678. {
  1679. switch (fan_control_access_mode) {
  1680. case IBMACPI_FAN_WR_ACPI_FANS:
  1681. if (speed >= 0 && speed <= 65535) {
  1682. if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
  1683. speed, speed, speed))
  1684. return -EIO;
  1685. } else
  1686. return -EINVAL;
  1687. break;
  1688. default:
  1689. return -ENXIO;
  1690. }
  1691. return 0;
  1692. }
  1693. static int fan_write_cmd_level(const char *cmd, int *rc)
  1694. {
  1695. int level;
  1696. if (sscanf(cmd, "level %d", &level) != 1)
  1697. return 0;
  1698. if ((*rc = fan_set_level(level)) == -ENXIO)
  1699. printk(IBM_ERR "level command accepted for unsupported "
  1700. "access mode %d", fan_control_access_mode);
  1701. return 1;
  1702. }
  1703. static int fan_write_cmd_enable(const char *cmd, int *rc)
  1704. {
  1705. if (strlencmp(cmd, "enable") != 0)
  1706. return 0;
  1707. if ((*rc = fan_set_enable()) == -ENXIO)
  1708. printk(IBM_ERR "enable command accepted for unsupported "
  1709. "access mode %d", fan_control_access_mode);
  1710. return 1;
  1711. }
  1712. static int fan_write_cmd_disable(const char *cmd, int *rc)
  1713. {
  1714. if (strlencmp(cmd, "disable") != 0)
  1715. return 0;
  1716. if ((*rc = fan_set_disable()) == -ENXIO)
  1717. printk(IBM_ERR "disable command accepted for unsupported "
  1718. "access mode %d", fan_control_access_mode);
  1719. return 1;
  1720. }
  1721. static int fan_write_cmd_speed(const char *cmd, int *rc)
  1722. {
  1723. int speed;
  1724. /* TODO:
  1725. * Support speed <low> <medium> <high> ? */
  1726. if (sscanf(cmd, "speed %d", &speed) != 1)
  1727. return 0;
  1728. if ((*rc = fan_set_speed(speed)) == -ENXIO)
  1729. printk(IBM_ERR "speed command accepted for unsupported "
  1730. "access mode %d", fan_control_access_mode);
  1731. return 1;
  1732. }
  1733. static int fan_write(char *buf)
  1734. {
  1735. char *cmd;
  1736. int rc = 0;
  1737. while (!rc && (cmd = next_cmd(&buf))) {
  1738. if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) &&
  1739. fan_write_cmd_level(cmd, &rc)) &&
  1740. !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) &&
  1741. (fan_write_cmd_enable(cmd, &rc) ||
  1742. fan_write_cmd_disable(cmd, &rc))) &&
  1743. !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) &&
  1744. fan_write_cmd_speed(cmd, &rc))
  1745. )
  1746. rc = -EINVAL;
  1747. }
  1748. return rc;
  1749. }
  1750. static struct ibm_struct ibms[] = {
  1751. {
  1752. .name = "driver",
  1753. .init = driver_init,
  1754. .read = driver_read,
  1755. },
  1756. {
  1757. .name = "hotkey",
  1758. .hid = IBM_HKEY_HID,
  1759. .init = hotkey_init,
  1760. .read = hotkey_read,
  1761. .write = hotkey_write,
  1762. .exit = hotkey_exit,
  1763. .notify = hotkey_notify,
  1764. .handle = &hkey_handle,
  1765. .type = ACPI_DEVICE_NOTIFY,
  1766. },
  1767. {
  1768. .name = "bluetooth",
  1769. .init = bluetooth_init,
  1770. .read = bluetooth_read,
  1771. .write = bluetooth_write,
  1772. },
  1773. {
  1774. .name = "wan",
  1775. .init = wan_init,
  1776. .read = wan_read,
  1777. .write = wan_write,
  1778. .experimental = 1,
  1779. },
  1780. {
  1781. .name = "video",
  1782. .init = video_init,
  1783. .read = video_read,
  1784. .write = video_write,
  1785. .exit = video_exit,
  1786. },
  1787. {
  1788. .name = "light",
  1789. .init = light_init,
  1790. .read = light_read,
  1791. .write = light_write,
  1792. },
  1793. #ifdef CONFIG_ACPI_IBM_DOCK
  1794. {
  1795. .name = "dock",
  1796. .read = dock_read,
  1797. .write = dock_write,
  1798. .notify = dock_notify,
  1799. .handle = &dock_handle,
  1800. .type = ACPI_SYSTEM_NOTIFY,
  1801. },
  1802. {
  1803. .name = "dock",
  1804. .hid = IBM_PCI_HID,
  1805. .notify = dock_notify,
  1806. .handle = &pci_handle,
  1807. .type = ACPI_SYSTEM_NOTIFY,
  1808. },
  1809. #endif
  1810. {
  1811. .name = "bay",
  1812. .init = bay_init,
  1813. .read = bay_read,
  1814. .write = bay_write,
  1815. .notify = bay_notify,
  1816. .handle = &bay_handle,
  1817. .type = ACPI_SYSTEM_NOTIFY,
  1818. },
  1819. {
  1820. .name = "cmos",
  1821. .read = cmos_read,
  1822. .write = cmos_write,
  1823. },
  1824. {
  1825. .name = "led",
  1826. .init = led_init,
  1827. .read = led_read,
  1828. .write = led_write,
  1829. },
  1830. {
  1831. .name = "beep",
  1832. .read = beep_read,
  1833. .write = beep_write,
  1834. },
  1835. {
  1836. .name = "thermal",
  1837. .init = thermal_init,
  1838. .read = thermal_read,
  1839. },
  1840. {
  1841. .name = "ecdump",
  1842. .read = ecdump_read,
  1843. .write = ecdump_write,
  1844. .experimental = 1,
  1845. },
  1846. {
  1847. .name = "brightness",
  1848. .read = brightness_read,
  1849. .write = brightness_write,
  1850. },
  1851. {
  1852. .name = "volume",
  1853. .read = volume_read,
  1854. .write = volume_write,
  1855. },
  1856. {
  1857. .name = "fan",
  1858. .read = fan_read,
  1859. .write = fan_write,
  1860. .init = fan_init,
  1861. .experimental = 1,
  1862. },
  1863. };
  1864. static int dispatch_read(char *page, char **start, off_t off, int count,
  1865. int *eof, void *data)
  1866. {
  1867. struct ibm_struct *ibm = (struct ibm_struct *)data;
  1868. int len;
  1869. if (!ibm || !ibm->read)
  1870. return -EINVAL;
  1871. len = ibm->read(page);
  1872. if (len < 0)
  1873. return len;
  1874. if (len <= off + count)
  1875. *eof = 1;
  1876. *start = page + off;
  1877. len -= off;
  1878. if (len > count)
  1879. len = count;
  1880. if (len < 0)
  1881. len = 0;
  1882. return len;
  1883. }
  1884. static int dispatch_write(struct file *file, const char __user * userbuf,
  1885. unsigned long count, void *data)
  1886. {
  1887. struct ibm_struct *ibm = (struct ibm_struct *)data;
  1888. char *kernbuf;
  1889. int ret;
  1890. if (!ibm || !ibm->write)
  1891. return -EINVAL;
  1892. kernbuf = kmalloc(count + 2, GFP_KERNEL);
  1893. if (!kernbuf)
  1894. return -ENOMEM;
  1895. if (copy_from_user(kernbuf, userbuf, count)) {
  1896. kfree(kernbuf);
  1897. return -EFAULT;
  1898. }
  1899. kernbuf[count] = 0;
  1900. strcat(kernbuf, ",");
  1901. ret = ibm->write(kernbuf);
  1902. if (ret == 0)
  1903. ret = count;
  1904. kfree(kernbuf);
  1905. return ret;
  1906. }
  1907. static void dispatch_notify(acpi_handle handle, u32 event, void *data)
  1908. {
  1909. struct ibm_struct *ibm = (struct ibm_struct *)data;
  1910. if (!ibm || !ibm->notify)
  1911. return;
  1912. ibm->notify(ibm, event);
  1913. }
  1914. static int __init setup_notify(struct ibm_struct *ibm)
  1915. {
  1916. acpi_status status;
  1917. int ret;
  1918. if (!*ibm->handle)
  1919. return 0;
  1920. ret = acpi_bus_get_device(*ibm->handle, &ibm->device);
  1921. if (ret < 0) {
  1922. printk(IBM_ERR "%s device not present\n", ibm->name);
  1923. return 0;
  1924. }
  1925. acpi_driver_data(ibm->device) = ibm;
  1926. sprintf(acpi_device_class(ibm->device), "%s/%s", IBM_NAME, ibm->name);
  1927. status = acpi_install_notify_handler(*ibm->handle, ibm->type,
  1928. dispatch_notify, ibm);
  1929. if (ACPI_FAILURE(status)) {
  1930. printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
  1931. ibm->name, status);
  1932. return -ENODEV;
  1933. }
  1934. return 0;
  1935. }
  1936. static int __init ibm_device_add(struct acpi_device *device)
  1937. {
  1938. return 0;
  1939. }
  1940. static int __init register_driver(struct ibm_struct *ibm)
  1941. {
  1942. int ret;
  1943. ibm->driver = kmalloc(sizeof(struct acpi_driver), GFP_KERNEL);
  1944. if (!ibm->driver) {
  1945. printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
  1946. return -1;
  1947. }
  1948. memset(ibm->driver, 0, sizeof(struct acpi_driver));
  1949. sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
  1950. ibm->driver->ids = ibm->hid;
  1951. ibm->driver->ops.add = &ibm_device_add;
  1952. ret = acpi_bus_register_driver(ibm->driver);
  1953. if (ret < 0) {
  1954. printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
  1955. ibm->hid, ret);
  1956. kfree(ibm->driver);
  1957. }
  1958. return ret;
  1959. }
  1960. static int __init ibm_init(struct ibm_struct *ibm)
  1961. {
  1962. int ret;
  1963. struct proc_dir_entry *entry;
  1964. if (ibm->experimental && !experimental)
  1965. return 0;
  1966. if (ibm->hid) {
  1967. ret = register_driver(ibm);
  1968. if (ret < 0)
  1969. return ret;
  1970. ibm->driver_registered = 1;
  1971. }
  1972. if (ibm->init) {
  1973. ret = ibm->init();
  1974. if (ret != 0)
  1975. return ret;
  1976. ibm->init_called = 1;
  1977. }
  1978. if (ibm->read) {
  1979. entry = create_proc_entry(ibm->name,
  1980. S_IFREG | S_IRUGO | S_IWUSR,
  1981. proc_dir);
  1982. if (!entry) {
  1983. printk(IBM_ERR "unable to create proc entry %s\n",
  1984. ibm->name);
  1985. return -ENODEV;
  1986. }
  1987. entry->owner = THIS_MODULE;
  1988. entry->data = ibm;
  1989. entry->read_proc = &dispatch_read;
  1990. if (ibm->write)
  1991. entry->write_proc = &dispatch_write;
  1992. ibm->proc_created = 1;
  1993. }
  1994. if (ibm->notify) {
  1995. ret = setup_notify(ibm);
  1996. if (ret < 0)
  1997. return ret;
  1998. ibm->notify_installed = 1;
  1999. }
  2000. return 0;
  2001. }
  2002. static void ibm_exit(struct ibm_struct *ibm)
  2003. {
  2004. if (ibm->notify_installed)
  2005. acpi_remove_notify_handler(*ibm->handle, ibm->type,
  2006. dispatch_notify);
  2007. if (ibm->proc_created)
  2008. remove_proc_entry(ibm->name, proc_dir);
  2009. if (ibm->init_called && ibm->exit)
  2010. ibm->exit();
  2011. if (ibm->driver_registered) {
  2012. acpi_bus_unregister_driver(ibm->driver);
  2013. kfree(ibm->driver);
  2014. }
  2015. }
  2016. static void __init ibm_handle_init(char *name,
  2017. acpi_handle * handle, acpi_handle parent,
  2018. char **paths, int num_paths, char **path)
  2019. {
  2020. int i;
  2021. acpi_status status;
  2022. for (i = 0; i < num_paths; i++) {
  2023. status = acpi_get_handle(parent, paths[i], handle);
  2024. if (ACPI_SUCCESS(status)) {
  2025. *path = paths[i];
  2026. return;
  2027. }
  2028. }
  2029. *handle = NULL;
  2030. }
  2031. #define IBM_HANDLE_INIT(object) \
  2032. ibm_handle_init(#object, &object##_handle, *object##_parent, \
  2033. object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
  2034. static int set_ibm_param(const char *val, struct kernel_param *kp)
  2035. {
  2036. unsigned int i;
  2037. for (i = 0; i < ARRAY_SIZE(ibms); i++)
  2038. if (strcmp(ibms[i].name, kp->name) == 0 && ibms[i].write) {
  2039. if (strlen(val) > sizeof(ibms[i].param) - 2)
  2040. return -ENOSPC;
  2041. strcpy(ibms[i].param, val);
  2042. strcat(ibms[i].param, ",");
  2043. return 0;
  2044. }
  2045. return -EINVAL;
  2046. }
  2047. #define IBM_PARAM(feature) \
  2048. module_param_call(feature, set_ibm_param, NULL, NULL, 0)
  2049. IBM_PARAM(hotkey);
  2050. IBM_PARAM(bluetooth);
  2051. IBM_PARAM(video);
  2052. IBM_PARAM(light);
  2053. #ifdef CONFIG_ACPI_IBM_DOCK
  2054. IBM_PARAM(dock);
  2055. #endif
  2056. IBM_PARAM(bay);
  2057. IBM_PARAM(cmos);
  2058. IBM_PARAM(led);
  2059. IBM_PARAM(beep);
  2060. IBM_PARAM(ecdump);
  2061. IBM_PARAM(brightness);
  2062. IBM_PARAM(volume);
  2063. IBM_PARAM(fan);
  2064. static struct backlight_properties ibm_backlight_data = {
  2065. .owner = THIS_MODULE,
  2066. .get_brightness = brightness_get,
  2067. .update_status = brightness_update_status,
  2068. .max_brightness = 7,
  2069. };
  2070. static void acpi_ibm_exit(void)
  2071. {
  2072. int i;
  2073. if (ibm_backlight_device)
  2074. backlight_device_unregister(ibm_backlight_device);
  2075. for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--)
  2076. ibm_exit(&ibms[i]);
  2077. remove_proc_entry(IBM_DIR, acpi_root_dir);
  2078. }
  2079. static int __init check_dmi_for_ec(void)
  2080. {
  2081. struct dmi_device *dev = NULL;
  2082. /*
  2083. * ThinkPad T23 or newer, A31 or newer, R50e or newer,
  2084. * X32 or newer, all Z series; Some models must have an
  2085. * up-to-date BIOS or they will not be detected.
  2086. *
  2087. * See http://thinkwiki.org/wiki/List_of_DMI_IDs
  2088. */
  2089. while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
  2090. if (strstr(dev->name, "IBM ThinkPad Embedded Controller"))
  2091. return 1;
  2092. }
  2093. return 0;
  2094. }
  2095. static int __init acpi_ibm_init(void)
  2096. {
  2097. int ret, i;
  2098. if (acpi_disabled)
  2099. return -ENODEV;
  2100. if (!acpi_specific_hotkey_enabled) {
  2101. printk(IBM_ERR "using generic hotkey driver\n");
  2102. return -ENODEV;
  2103. }
  2104. /* ec is required because many other handles are relative to it */
  2105. IBM_HANDLE_INIT(ec);
  2106. if (!ec_handle) {
  2107. printk(IBM_ERR "ec object not found\n");
  2108. return -ENODEV;
  2109. }
  2110. /* Models with newer firmware report the EC in DMI */
  2111. ibm_thinkpad_ec_found = check_dmi_for_ec();
  2112. /* these handles are not required */
  2113. IBM_HANDLE_INIT(vid);
  2114. IBM_HANDLE_INIT(vid2);
  2115. IBM_HANDLE_INIT(ledb);
  2116. IBM_HANDLE_INIT(led);
  2117. IBM_HANDLE_INIT(hkey);
  2118. IBM_HANDLE_INIT(lght);
  2119. IBM_HANDLE_INIT(cmos);
  2120. #ifdef CONFIG_ACPI_IBM_DOCK
  2121. IBM_HANDLE_INIT(dock);
  2122. #endif
  2123. IBM_HANDLE_INIT(pci);
  2124. IBM_HANDLE_INIT(bay);
  2125. if (bay_handle)
  2126. IBM_HANDLE_INIT(bay_ej);
  2127. IBM_HANDLE_INIT(bay2);
  2128. if (bay2_handle)
  2129. IBM_HANDLE_INIT(bay2_ej);
  2130. IBM_HANDLE_INIT(beep);
  2131. IBM_HANDLE_INIT(ecrd);
  2132. IBM_HANDLE_INIT(ecwr);
  2133. IBM_HANDLE_INIT(fans);
  2134. IBM_HANDLE_INIT(gfan);
  2135. IBM_HANDLE_INIT(sfan);
  2136. proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
  2137. if (!proc_dir) {
  2138. printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
  2139. return -ENODEV;
  2140. }
  2141. proc_dir->owner = THIS_MODULE;
  2142. for (i = 0; i < ARRAY_SIZE(ibms); i++) {
  2143. ret = ibm_init(&ibms[i]);
  2144. if (ret >= 0 && *ibms[i].param)
  2145. ret = ibms[i].write(ibms[i].param);
  2146. if (ret < 0) {
  2147. acpi_ibm_exit();
  2148. return ret;
  2149. }
  2150. }
  2151. ibm_backlight_device = backlight_device_register("ibm", NULL,
  2152. &ibm_backlight_data);
  2153. if (IS_ERR(ibm_backlight_device)) {
  2154. printk(IBM_ERR "Could not register ibm backlight device\n");
  2155. ibm_backlight_device = NULL;
  2156. acpi_ibm_exit();
  2157. }
  2158. return 0;
  2159. }
  2160. module_init(acpi_ibm_init);
  2161. module_exit(acpi_ibm_exit);