ibm_acpi.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639
  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 |=
  1529. IBMACPI_FAN_CMD_LEVEL | IBMACPI_FAN_CMD_ENABLE;
  1530. } else {
  1531. if (!gfan_handle) {
  1532. /* gfan without sfan means no fan control */
  1533. /* all other models implement TP EC 0x2f control */
  1534. if (fans_handle) {
  1535. /* X31, X40, X41 */
  1536. fan_control_access_mode =
  1537. IBMACPI_FAN_WR_ACPI_FANS;
  1538. fan_control_commands |=
  1539. IBMACPI_FAN_CMD_SPEED |
  1540. IBMACPI_FAN_CMD_LEVEL |
  1541. IBMACPI_FAN_CMD_ENABLE;
  1542. } else {
  1543. fan_control_access_mode = IBMACPI_FAN_WR_TPEC;
  1544. fan_control_commands |=
  1545. IBMACPI_FAN_CMD_LEVEL |
  1546. IBMACPI_FAN_CMD_ENABLE;
  1547. }
  1548. }
  1549. }
  1550. return 0;
  1551. }
  1552. static int fan_get_status(u8 *status)
  1553. {
  1554. u8 s;
  1555. /* TODO:
  1556. * Add IBMACPI_FAN_RD_ACPI_FANS ? */
  1557. switch (fan_status_access_mode) {
  1558. case IBMACPI_FAN_RD_ACPI_GFAN:
  1559. /* 570, 600e/x, 770e, 770x */
  1560. if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
  1561. return -EIO;
  1562. if (likely(status))
  1563. *status = s & 0x07;
  1564. break;
  1565. case IBMACPI_FAN_RD_TPEC:
  1566. /* all except 570, 600e/x, 770e, 770x */
  1567. if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
  1568. return -EIO;
  1569. if (likely(status))
  1570. *status = s;
  1571. break;
  1572. default:
  1573. return -ENXIO;
  1574. }
  1575. return 0;
  1576. }
  1577. static int fan_get_speed(unsigned int *speed)
  1578. {
  1579. u8 hi, lo;
  1580. switch (fan_status_access_mode) {
  1581. case IBMACPI_FAN_RD_TPEC:
  1582. /* all except 570, 600e/x, 770e, 770x */
  1583. if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
  1584. !acpi_ec_read(fan_rpm_offset + 1, &hi)))
  1585. return -EIO;
  1586. if (likely(speed))
  1587. *speed = (hi << 8) | lo;
  1588. break;
  1589. default:
  1590. return -ENXIO;
  1591. }
  1592. return 0;
  1593. }
  1594. static int fan_read(char *p)
  1595. {
  1596. int len = 0;
  1597. int rc;
  1598. u8 status;
  1599. unsigned int speed = 0;
  1600. switch (fan_status_access_mode) {
  1601. case IBMACPI_FAN_RD_ACPI_GFAN:
  1602. /* 570, 600e/x, 770e, 770x */
  1603. if ((rc = fan_get_status(&status)) < 0)
  1604. return rc;
  1605. len += sprintf(p + len, "status:\t\t%s\n"
  1606. "level:\t\t%d\n",
  1607. (status != 0) ? "enabled" : "disabled", status);
  1608. break;
  1609. case IBMACPI_FAN_RD_TPEC:
  1610. /* all except 570, 600e/x, 770e, 770x */
  1611. if ((rc = fan_get_status(&status)) < 0)
  1612. return rc;
  1613. len += sprintf(p + len, "status:\t\t%s\n",
  1614. (status != 0) ? "enabled" : "disabled");
  1615. if ((rc = fan_get_speed(&speed)) < 0)
  1616. return rc;
  1617. len += sprintf(p + len, "speed:\t\t%d\n", speed);
  1618. if (status & IBMACPI_FAN_EC_DISENGAGED)
  1619. /* Disengaged mode takes precedence */
  1620. len += sprintf(p + len, "level:\t\tdisengaged\n");
  1621. else if (status & IBMACPI_FAN_EC_AUTO)
  1622. len += sprintf(p + len, "level:\t\tauto\n");
  1623. else
  1624. len += sprintf(p + len, "level:\t\t%d\n", status);
  1625. break;
  1626. case IBMACPI_FAN_NONE:
  1627. default:
  1628. len += sprintf(p + len, "status:\t\tnot supported\n");
  1629. }
  1630. if (fan_control_commands & IBMACPI_FAN_CMD_LEVEL) {
  1631. len += sprintf(p + len, "commands:\tlevel <level>");
  1632. switch (fan_control_access_mode) {
  1633. case IBMACPI_FAN_WR_ACPI_SFAN:
  1634. len += sprintf(p + len, " (<level> is 0-7)\n");
  1635. break;
  1636. default:
  1637. len += sprintf(p + len, " (<level> is 0-7, "
  1638. "auto, disengaged)\n");
  1639. break;
  1640. }
  1641. }
  1642. if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE)
  1643. len += sprintf(p + len, "commands:\tenable, disable\n");
  1644. if (fan_control_commands & IBMACPI_FAN_CMD_SPEED)
  1645. len += sprintf(p + len, "commands:\tspeed <speed>"
  1646. " (<speed> is 0-65535)\n");
  1647. return len;
  1648. }
  1649. static int fan_set_level(int level)
  1650. {
  1651. switch (fan_control_access_mode) {
  1652. case IBMACPI_FAN_WR_ACPI_SFAN:
  1653. if (level >= 0 && level <= 7) {
  1654. if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
  1655. return -EIO;
  1656. } else
  1657. return -EINVAL;
  1658. break;
  1659. case IBMACPI_FAN_WR_ACPI_FANS:
  1660. case IBMACPI_FAN_WR_TPEC:
  1661. if ((level != IBMACPI_FAN_EC_AUTO) &&
  1662. (level != IBMACPI_FAN_EC_DISENGAGED) &&
  1663. ((level < 0) || (level > 7)))
  1664. return -EINVAL;
  1665. if (!acpi_ec_write(fan_status_offset, level))
  1666. return -EIO;
  1667. break;
  1668. default:
  1669. return -ENXIO;
  1670. }
  1671. return 0;
  1672. }
  1673. static int fan_set_enable(void)
  1674. {
  1675. u8 s;
  1676. int rc;
  1677. switch (fan_control_access_mode) {
  1678. case IBMACPI_FAN_WR_ACPI_FANS:
  1679. case IBMACPI_FAN_WR_TPEC:
  1680. if ((rc = fan_get_status(&s)) < 0)
  1681. return rc;
  1682. /* Don't go out of emergency fan mode */
  1683. if (s != 7)
  1684. s = IBMACPI_FAN_EC_AUTO;
  1685. if (!acpi_ec_write(fan_status_offset, s))
  1686. return -EIO;
  1687. break;
  1688. case IBMACPI_FAN_WR_ACPI_SFAN:
  1689. if ((rc = fan_get_status(&s)) < 0)
  1690. return rc;
  1691. s &= 0x07;
  1692. /* Set fan to at least level 4 */
  1693. if (s < 4)
  1694. s = 4;
  1695. if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
  1696. return -EIO;
  1697. break;
  1698. default:
  1699. return -ENXIO;
  1700. }
  1701. return 0;
  1702. }
  1703. static int fan_set_disable(void)
  1704. {
  1705. switch (fan_control_access_mode) {
  1706. case IBMACPI_FAN_WR_ACPI_FANS:
  1707. case IBMACPI_FAN_WR_TPEC:
  1708. if (!acpi_ec_write(fan_status_offset, 0x00))
  1709. return -EIO;
  1710. break;
  1711. case IBMACPI_FAN_WR_ACPI_SFAN:
  1712. if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
  1713. return -EIO;
  1714. break;
  1715. default:
  1716. return -ENXIO;
  1717. }
  1718. return 0;
  1719. }
  1720. static int fan_set_speed(int speed)
  1721. {
  1722. switch (fan_control_access_mode) {
  1723. case IBMACPI_FAN_WR_ACPI_FANS:
  1724. if (speed >= 0 && speed <= 65535) {
  1725. if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
  1726. speed, speed, speed))
  1727. return -EIO;
  1728. } else
  1729. return -EINVAL;
  1730. break;
  1731. default:
  1732. return -ENXIO;
  1733. }
  1734. return 0;
  1735. }
  1736. static int fan_write_cmd_level(const char *cmd, int *rc)
  1737. {
  1738. int level;
  1739. if (strlencmp(cmd, "level auto") == 0)
  1740. level = IBMACPI_FAN_EC_AUTO;
  1741. else if (strlencmp(cmd, "level disengaged") == 0)
  1742. level = IBMACPI_FAN_EC_DISENGAGED;
  1743. else if (sscanf(cmd, "level %d", &level) != 1)
  1744. return 0;
  1745. if ((*rc = fan_set_level(level)) == -ENXIO)
  1746. printk(IBM_ERR "level command accepted for unsupported "
  1747. "access mode %d", fan_control_access_mode);
  1748. return 1;
  1749. }
  1750. static int fan_write_cmd_enable(const char *cmd, int *rc)
  1751. {
  1752. if (strlencmp(cmd, "enable") != 0)
  1753. return 0;
  1754. if ((*rc = fan_set_enable()) == -ENXIO)
  1755. printk(IBM_ERR "enable command accepted for unsupported "
  1756. "access mode %d", fan_control_access_mode);
  1757. return 1;
  1758. }
  1759. static int fan_write_cmd_disable(const char *cmd, int *rc)
  1760. {
  1761. if (strlencmp(cmd, "disable") != 0)
  1762. return 0;
  1763. if ((*rc = fan_set_disable()) == -ENXIO)
  1764. printk(IBM_ERR "disable command accepted for unsupported "
  1765. "access mode %d", fan_control_access_mode);
  1766. return 1;
  1767. }
  1768. static int fan_write_cmd_speed(const char *cmd, int *rc)
  1769. {
  1770. int speed;
  1771. /* TODO:
  1772. * Support speed <low> <medium> <high> ? */
  1773. if (sscanf(cmd, "speed %d", &speed) != 1)
  1774. return 0;
  1775. if ((*rc = fan_set_speed(speed)) == -ENXIO)
  1776. printk(IBM_ERR "speed command accepted for unsupported "
  1777. "access mode %d", fan_control_access_mode);
  1778. return 1;
  1779. }
  1780. static int fan_write(char *buf)
  1781. {
  1782. char *cmd;
  1783. int rc = 0;
  1784. while (!rc && (cmd = next_cmd(&buf))) {
  1785. if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) &&
  1786. fan_write_cmd_level(cmd, &rc)) &&
  1787. !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) &&
  1788. (fan_write_cmd_enable(cmd, &rc) ||
  1789. fan_write_cmd_disable(cmd, &rc))) &&
  1790. !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) &&
  1791. fan_write_cmd_speed(cmd, &rc))
  1792. )
  1793. rc = -EINVAL;
  1794. }
  1795. return rc;
  1796. }
  1797. static struct ibm_struct ibms[] = {
  1798. {
  1799. .name = "driver",
  1800. .init = driver_init,
  1801. .read = driver_read,
  1802. },
  1803. {
  1804. .name = "hotkey",
  1805. .hid = IBM_HKEY_HID,
  1806. .init = hotkey_init,
  1807. .read = hotkey_read,
  1808. .write = hotkey_write,
  1809. .exit = hotkey_exit,
  1810. .notify = hotkey_notify,
  1811. .handle = &hkey_handle,
  1812. .type = ACPI_DEVICE_NOTIFY,
  1813. },
  1814. {
  1815. .name = "bluetooth",
  1816. .init = bluetooth_init,
  1817. .read = bluetooth_read,
  1818. .write = bluetooth_write,
  1819. },
  1820. {
  1821. .name = "wan",
  1822. .init = wan_init,
  1823. .read = wan_read,
  1824. .write = wan_write,
  1825. .experimental = 1,
  1826. },
  1827. {
  1828. .name = "video",
  1829. .init = video_init,
  1830. .read = video_read,
  1831. .write = video_write,
  1832. .exit = video_exit,
  1833. },
  1834. {
  1835. .name = "light",
  1836. .init = light_init,
  1837. .read = light_read,
  1838. .write = light_write,
  1839. },
  1840. #ifdef CONFIG_ACPI_IBM_DOCK
  1841. {
  1842. .name = "dock",
  1843. .read = dock_read,
  1844. .write = dock_write,
  1845. .notify = dock_notify,
  1846. .handle = &dock_handle,
  1847. .type = ACPI_SYSTEM_NOTIFY,
  1848. },
  1849. {
  1850. .name = "dock",
  1851. .hid = IBM_PCI_HID,
  1852. .notify = dock_notify,
  1853. .handle = &pci_handle,
  1854. .type = ACPI_SYSTEM_NOTIFY,
  1855. },
  1856. #endif
  1857. {
  1858. .name = "bay",
  1859. .init = bay_init,
  1860. .read = bay_read,
  1861. .write = bay_write,
  1862. .notify = bay_notify,
  1863. .handle = &bay_handle,
  1864. .type = ACPI_SYSTEM_NOTIFY,
  1865. },
  1866. {
  1867. .name = "cmos",
  1868. .read = cmos_read,
  1869. .write = cmos_write,
  1870. },
  1871. {
  1872. .name = "led",
  1873. .init = led_init,
  1874. .read = led_read,
  1875. .write = led_write,
  1876. },
  1877. {
  1878. .name = "beep",
  1879. .read = beep_read,
  1880. .write = beep_write,
  1881. },
  1882. {
  1883. .name = "thermal",
  1884. .init = thermal_init,
  1885. .read = thermal_read,
  1886. },
  1887. {
  1888. .name = "ecdump",
  1889. .read = ecdump_read,
  1890. .write = ecdump_write,
  1891. .experimental = 1,
  1892. },
  1893. {
  1894. .name = "brightness",
  1895. .read = brightness_read,
  1896. .write = brightness_write,
  1897. },
  1898. {
  1899. .name = "volume",
  1900. .read = volume_read,
  1901. .write = volume_write,
  1902. },
  1903. {
  1904. .name = "fan",
  1905. .read = fan_read,
  1906. .write = fan_write,
  1907. .init = fan_init,
  1908. .experimental = 1,
  1909. },
  1910. };
  1911. static int dispatch_read(char *page, char **start, off_t off, int count,
  1912. int *eof, void *data)
  1913. {
  1914. struct ibm_struct *ibm = (struct ibm_struct *)data;
  1915. int len;
  1916. if (!ibm || !ibm->read)
  1917. return -EINVAL;
  1918. len = ibm->read(page);
  1919. if (len < 0)
  1920. return len;
  1921. if (len <= off + count)
  1922. *eof = 1;
  1923. *start = page + off;
  1924. len -= off;
  1925. if (len > count)
  1926. len = count;
  1927. if (len < 0)
  1928. len = 0;
  1929. return len;
  1930. }
  1931. static int dispatch_write(struct file *file, const char __user * userbuf,
  1932. unsigned long count, void *data)
  1933. {
  1934. struct ibm_struct *ibm = (struct ibm_struct *)data;
  1935. char *kernbuf;
  1936. int ret;
  1937. if (!ibm || !ibm->write)
  1938. return -EINVAL;
  1939. kernbuf = kmalloc(count + 2, GFP_KERNEL);
  1940. if (!kernbuf)
  1941. return -ENOMEM;
  1942. if (copy_from_user(kernbuf, userbuf, count)) {
  1943. kfree(kernbuf);
  1944. return -EFAULT;
  1945. }
  1946. kernbuf[count] = 0;
  1947. strcat(kernbuf, ",");
  1948. ret = ibm->write(kernbuf);
  1949. if (ret == 0)
  1950. ret = count;
  1951. kfree(kernbuf);
  1952. return ret;
  1953. }
  1954. static void dispatch_notify(acpi_handle handle, u32 event, void *data)
  1955. {
  1956. struct ibm_struct *ibm = (struct ibm_struct *)data;
  1957. if (!ibm || !ibm->notify)
  1958. return;
  1959. ibm->notify(ibm, event);
  1960. }
  1961. static int __init setup_notify(struct ibm_struct *ibm)
  1962. {
  1963. acpi_status status;
  1964. int ret;
  1965. if (!*ibm->handle)
  1966. return 0;
  1967. ret = acpi_bus_get_device(*ibm->handle, &ibm->device);
  1968. if (ret < 0) {
  1969. printk(IBM_ERR "%s device not present\n", ibm->name);
  1970. return 0;
  1971. }
  1972. acpi_driver_data(ibm->device) = ibm;
  1973. sprintf(acpi_device_class(ibm->device), "%s/%s", IBM_NAME, ibm->name);
  1974. status = acpi_install_notify_handler(*ibm->handle, ibm->type,
  1975. dispatch_notify, ibm);
  1976. if (ACPI_FAILURE(status)) {
  1977. printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
  1978. ibm->name, status);
  1979. return -ENODEV;
  1980. }
  1981. return 0;
  1982. }
  1983. static int __init ibm_device_add(struct acpi_device *device)
  1984. {
  1985. return 0;
  1986. }
  1987. static int __init register_driver(struct ibm_struct *ibm)
  1988. {
  1989. int ret;
  1990. ibm->driver = kmalloc(sizeof(struct acpi_driver), GFP_KERNEL);
  1991. if (!ibm->driver) {
  1992. printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
  1993. return -1;
  1994. }
  1995. memset(ibm->driver, 0, sizeof(struct acpi_driver));
  1996. sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
  1997. ibm->driver->ids = ibm->hid;
  1998. ibm->driver->ops.add = &ibm_device_add;
  1999. ret = acpi_bus_register_driver(ibm->driver);
  2000. if (ret < 0) {
  2001. printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
  2002. ibm->hid, ret);
  2003. kfree(ibm->driver);
  2004. }
  2005. return ret;
  2006. }
  2007. static int __init ibm_init(struct ibm_struct *ibm)
  2008. {
  2009. int ret;
  2010. struct proc_dir_entry *entry;
  2011. if (ibm->experimental && !experimental)
  2012. return 0;
  2013. if (ibm->hid) {
  2014. ret = register_driver(ibm);
  2015. if (ret < 0)
  2016. return ret;
  2017. ibm->driver_registered = 1;
  2018. }
  2019. if (ibm->init) {
  2020. ret = ibm->init();
  2021. if (ret != 0)
  2022. return ret;
  2023. ibm->init_called = 1;
  2024. }
  2025. if (ibm->read) {
  2026. entry = create_proc_entry(ibm->name,
  2027. S_IFREG | S_IRUGO | S_IWUSR,
  2028. proc_dir);
  2029. if (!entry) {
  2030. printk(IBM_ERR "unable to create proc entry %s\n",
  2031. ibm->name);
  2032. return -ENODEV;
  2033. }
  2034. entry->owner = THIS_MODULE;
  2035. entry->data = ibm;
  2036. entry->read_proc = &dispatch_read;
  2037. if (ibm->write)
  2038. entry->write_proc = &dispatch_write;
  2039. ibm->proc_created = 1;
  2040. }
  2041. if (ibm->notify) {
  2042. ret = setup_notify(ibm);
  2043. if (ret < 0)
  2044. return ret;
  2045. ibm->notify_installed = 1;
  2046. }
  2047. return 0;
  2048. }
  2049. static void ibm_exit(struct ibm_struct *ibm)
  2050. {
  2051. if (ibm->notify_installed)
  2052. acpi_remove_notify_handler(*ibm->handle, ibm->type,
  2053. dispatch_notify);
  2054. if (ibm->proc_created)
  2055. remove_proc_entry(ibm->name, proc_dir);
  2056. if (ibm->init_called && ibm->exit)
  2057. ibm->exit();
  2058. if (ibm->driver_registered) {
  2059. acpi_bus_unregister_driver(ibm->driver);
  2060. kfree(ibm->driver);
  2061. }
  2062. }
  2063. static void __init ibm_handle_init(char *name,
  2064. acpi_handle * handle, acpi_handle parent,
  2065. char **paths, int num_paths, char **path)
  2066. {
  2067. int i;
  2068. acpi_status status;
  2069. for (i = 0; i < num_paths; i++) {
  2070. status = acpi_get_handle(parent, paths[i], handle);
  2071. if (ACPI_SUCCESS(status)) {
  2072. *path = paths[i];
  2073. return;
  2074. }
  2075. }
  2076. *handle = NULL;
  2077. }
  2078. #define IBM_HANDLE_INIT(object) \
  2079. ibm_handle_init(#object, &object##_handle, *object##_parent, \
  2080. object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
  2081. static int set_ibm_param(const char *val, struct kernel_param *kp)
  2082. {
  2083. unsigned int i;
  2084. for (i = 0; i < ARRAY_SIZE(ibms); i++)
  2085. if (strcmp(ibms[i].name, kp->name) == 0 && ibms[i].write) {
  2086. if (strlen(val) > sizeof(ibms[i].param) - 2)
  2087. return -ENOSPC;
  2088. strcpy(ibms[i].param, val);
  2089. strcat(ibms[i].param, ",");
  2090. return 0;
  2091. }
  2092. return -EINVAL;
  2093. }
  2094. #define IBM_PARAM(feature) \
  2095. module_param_call(feature, set_ibm_param, NULL, NULL, 0)
  2096. IBM_PARAM(hotkey);
  2097. IBM_PARAM(bluetooth);
  2098. IBM_PARAM(video);
  2099. IBM_PARAM(light);
  2100. #ifdef CONFIG_ACPI_IBM_DOCK
  2101. IBM_PARAM(dock);
  2102. #endif
  2103. IBM_PARAM(bay);
  2104. IBM_PARAM(cmos);
  2105. IBM_PARAM(led);
  2106. IBM_PARAM(beep);
  2107. IBM_PARAM(ecdump);
  2108. IBM_PARAM(brightness);
  2109. IBM_PARAM(volume);
  2110. IBM_PARAM(fan);
  2111. static struct backlight_properties ibm_backlight_data = {
  2112. .owner = THIS_MODULE,
  2113. .get_brightness = brightness_get,
  2114. .update_status = brightness_update_status,
  2115. .max_brightness = 7,
  2116. };
  2117. static void acpi_ibm_exit(void)
  2118. {
  2119. int i;
  2120. if (ibm_backlight_device)
  2121. backlight_device_unregister(ibm_backlight_device);
  2122. for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--)
  2123. ibm_exit(&ibms[i]);
  2124. remove_proc_entry(IBM_DIR, acpi_root_dir);
  2125. }
  2126. static int __init check_dmi_for_ec(void)
  2127. {
  2128. struct dmi_device *dev = NULL;
  2129. /*
  2130. * ThinkPad T23 or newer, A31 or newer, R50e or newer,
  2131. * X32 or newer, all Z series; Some models must have an
  2132. * up-to-date BIOS or they will not be detected.
  2133. *
  2134. * See http://thinkwiki.org/wiki/List_of_DMI_IDs
  2135. */
  2136. while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
  2137. if (strstr(dev->name, "IBM ThinkPad Embedded Controller"))
  2138. return 1;
  2139. }
  2140. return 0;
  2141. }
  2142. static int __init acpi_ibm_init(void)
  2143. {
  2144. int ret, i;
  2145. if (acpi_disabled)
  2146. return -ENODEV;
  2147. if (!acpi_specific_hotkey_enabled) {
  2148. printk(IBM_ERR "using generic hotkey driver\n");
  2149. return -ENODEV;
  2150. }
  2151. /* ec is required because many other handles are relative to it */
  2152. IBM_HANDLE_INIT(ec);
  2153. if (!ec_handle) {
  2154. printk(IBM_ERR "ec object not found\n");
  2155. return -ENODEV;
  2156. }
  2157. /* Models with newer firmware report the EC in DMI */
  2158. ibm_thinkpad_ec_found = check_dmi_for_ec();
  2159. /* these handles are not required */
  2160. IBM_HANDLE_INIT(vid);
  2161. IBM_HANDLE_INIT(vid2);
  2162. IBM_HANDLE_INIT(ledb);
  2163. IBM_HANDLE_INIT(led);
  2164. IBM_HANDLE_INIT(hkey);
  2165. IBM_HANDLE_INIT(lght);
  2166. IBM_HANDLE_INIT(cmos);
  2167. #ifdef CONFIG_ACPI_IBM_DOCK
  2168. IBM_HANDLE_INIT(dock);
  2169. #endif
  2170. IBM_HANDLE_INIT(pci);
  2171. IBM_HANDLE_INIT(bay);
  2172. if (bay_handle)
  2173. IBM_HANDLE_INIT(bay_ej);
  2174. IBM_HANDLE_INIT(bay2);
  2175. if (bay2_handle)
  2176. IBM_HANDLE_INIT(bay2_ej);
  2177. IBM_HANDLE_INIT(beep);
  2178. IBM_HANDLE_INIT(ecrd);
  2179. IBM_HANDLE_INIT(ecwr);
  2180. IBM_HANDLE_INIT(fans);
  2181. IBM_HANDLE_INIT(gfan);
  2182. IBM_HANDLE_INIT(sfan);
  2183. proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
  2184. if (!proc_dir) {
  2185. printk(IBM_ERR "unable to create proc dir %s", IBM_DIR);
  2186. return -ENODEV;
  2187. }
  2188. proc_dir->owner = THIS_MODULE;
  2189. for (i = 0; i < ARRAY_SIZE(ibms); i++) {
  2190. ret = ibm_init(&ibms[i]);
  2191. if (ret >= 0 && *ibms[i].param)
  2192. ret = ibms[i].write(ibms[i].param);
  2193. if (ret < 0) {
  2194. acpi_ibm_exit();
  2195. return ret;
  2196. }
  2197. }
  2198. ibm_backlight_device = backlight_device_register("ibm", NULL,
  2199. &ibm_backlight_data);
  2200. if (IS_ERR(ibm_backlight_device)) {
  2201. printk(IBM_ERR "Could not register ibm backlight device\n");
  2202. ibm_backlight_device = NULL;
  2203. acpi_ibm_exit();
  2204. }
  2205. return 0;
  2206. }
  2207. module_init(acpi_ibm_init);
  2208. module_exit(acpi_ibm_exit);