ibm_acpi.c 60 KB

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