thinkpad_acpi.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272
  1. /*
  2. * thinkpad_acpi.c - ThinkPad ACPI Extras
  3. *
  4. *
  5. * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
  6. * Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301, USA.
  22. */
  23. #define IBM_VERSION "0.14"
  24. /*
  25. * Changelog:
  26. * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
  27. * drivers/misc.
  28. *
  29. * 2006-11-22 0.13 new maintainer
  30. * changelog now lives in git commit history, and will
  31. * not be updated further in-file.
  32. *
  33. * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
  34. * 2005-03-17 0.11 support for 600e, 770x
  35. * thanks to Jamie Lentin <lentinj@dial.pipex.com>
  36. * support for 770e, G41
  37. * G40 and G41 don't have a thinklight
  38. * temperatures no longer experimental
  39. * experimental brightness control
  40. * experimental volume control
  41. * experimental fan enable/disable
  42. * 2005-01-16 0.10 fix module loading on R30, R31
  43. * 2005-01-16 0.9 support for 570, R30, R31
  44. * ultrabay support on A22p, A3x
  45. * limit arg for cmos, led, beep, drop experimental status
  46. * more capable led control on A21e, A22p, T20-22, X20
  47. * experimental temperatures and fan speed
  48. * experimental embedded controller register dump
  49. * mark more functions as __init, drop incorrect __exit
  50. * use MODULE_VERSION
  51. * thanks to Henrik Brix Andersen <brix@gentoo.org>
  52. * fix parameter passing on module loading
  53. * thanks to Rusty Russell <rusty@rustcorp.com.au>
  54. * thanks to Jim Radford <radford@blackbean.org>
  55. * 2004-11-08 0.8 fix init error case, don't return from a macro
  56. * thanks to Chris Wright <chrisw@osdl.org>
  57. * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
  58. * fix led control on A21e
  59. * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
  60. * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
  61. * proc file format changed
  62. * video_switch command
  63. * experimental cmos control
  64. * experimental led control
  65. * experimental acpi sounds
  66. * 2004-09-16 0.4 support for module parameters
  67. * hotkey mask can be prefixed by 0x
  68. * video output switching
  69. * video expansion control
  70. * ultrabay eject support
  71. * removed lcd brightness/on/off control, didn't work
  72. * 2004-08-17 0.3 support for R40
  73. * lcd off, brightness control
  74. * thinklight on/off
  75. * 2004-08-14 0.2 support for T series, X20
  76. * bluetooth enable/disable
  77. * hotkey events disabled by default
  78. * removed fan control, currently useless
  79. * 2004-08-09 0.1 initial release, support for X series
  80. */
  81. #include "thinkpad_acpi.h"
  82. MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
  83. MODULE_DESCRIPTION(IBM_DESC);
  84. MODULE_VERSION(IBM_VERSION);
  85. MODULE_LICENSE("GPL");
  86. /* Please remove this in year 2009 */
  87. MODULE_ALIAS("ibm_acpi");
  88. #define __unused __attribute__ ((unused))
  89. /****************************************************************************
  90. ****************************************************************************
  91. *
  92. * ACPI Helpers and device model
  93. *
  94. ****************************************************************************
  95. ****************************************************************************/
  96. /*************************************************************************
  97. * ACPI basic handles
  98. */
  99. static acpi_handle root_handle = NULL;
  100. #define IBM_HANDLE(object, parent, paths...) \
  101. static acpi_handle object##_handle; \
  102. static acpi_handle *object##_parent = &parent##_handle; \
  103. static char *object##_path; \
  104. static char *object##_paths[] = { paths }
  105. IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
  106. "\\_SB.PCI.ISA.EC", /* 570 */
  107. "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
  108. "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
  109. "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
  110. "\\_SB.PCI0.ICH3.EC0", /* R31 */
  111. "\\_SB.PCI0.LPC.EC", /* all others */
  112. );
  113. IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
  114. IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
  115. /*************************************************************************
  116. * Misc ACPI handles
  117. */
  118. IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
  119. "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
  120. "\\CMS", /* R40, R40e */
  121. ); /* all others */
  122. IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
  123. "^HKEY", /* R30, R31 */
  124. "HKEY", /* all others */
  125. ); /* 570 */
  126. /*************************************************************************
  127. * ACPI helpers
  128. */
  129. static int acpi_evalf(acpi_handle handle,
  130. void *res, char *method, char *fmt, ...)
  131. {
  132. char *fmt0 = fmt;
  133. struct acpi_object_list params;
  134. union acpi_object in_objs[IBM_MAX_ACPI_ARGS];
  135. struct acpi_buffer result, *resultp;
  136. union acpi_object out_obj;
  137. acpi_status status;
  138. va_list ap;
  139. char res_type;
  140. int success;
  141. int quiet;
  142. if (!*fmt) {
  143. printk(IBM_ERR "acpi_evalf() called with empty format\n");
  144. return 0;
  145. }
  146. if (*fmt == 'q') {
  147. quiet = 1;
  148. fmt++;
  149. } else
  150. quiet = 0;
  151. res_type = *(fmt++);
  152. params.count = 0;
  153. params.pointer = &in_objs[0];
  154. va_start(ap, fmt);
  155. while (*fmt) {
  156. char c = *(fmt++);
  157. switch (c) {
  158. case 'd': /* int */
  159. in_objs[params.count].integer.value = va_arg(ap, int);
  160. in_objs[params.count++].type = ACPI_TYPE_INTEGER;
  161. break;
  162. /* add more types as needed */
  163. default:
  164. printk(IBM_ERR "acpi_evalf() called "
  165. "with invalid format character '%c'\n", c);
  166. return 0;
  167. }
  168. }
  169. va_end(ap);
  170. if (res_type != 'v') {
  171. result.length = sizeof(out_obj);
  172. result.pointer = &out_obj;
  173. resultp = &result;
  174. } else
  175. resultp = NULL;
  176. status = acpi_evaluate_object(handle, method, &params, resultp);
  177. switch (res_type) {
  178. case 'd': /* int */
  179. if (res)
  180. *(int *)res = out_obj.integer.value;
  181. success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
  182. break;
  183. case 'v': /* void */
  184. success = status == AE_OK;
  185. break;
  186. /* add more types as needed */
  187. default:
  188. printk(IBM_ERR "acpi_evalf() called "
  189. "with invalid format character '%c'\n", res_type);
  190. return 0;
  191. }
  192. if (!success && !quiet)
  193. printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
  194. method, fmt0, status);
  195. return success;
  196. }
  197. static void __unused acpi_print_int(acpi_handle handle, char *method)
  198. {
  199. int i;
  200. if (acpi_evalf(handle, &i, method, "d"))
  201. printk(IBM_INFO "%s = 0x%x\n", method, i);
  202. else
  203. printk(IBM_ERR "error calling %s\n", method);
  204. }
  205. static int acpi_ec_read(int i, u8 * p)
  206. {
  207. int v;
  208. if (ecrd_handle) {
  209. if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
  210. return 0;
  211. *p = v;
  212. } else {
  213. if (ec_read(i, p) < 0)
  214. return 0;
  215. }
  216. return 1;
  217. }
  218. static int acpi_ec_write(int i, u8 v)
  219. {
  220. if (ecwr_handle) {
  221. if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
  222. return 0;
  223. } else {
  224. if (ec_write(i, v) < 0)
  225. return 0;
  226. }
  227. return 1;
  228. }
  229. static int _sta(acpi_handle handle)
  230. {
  231. int status;
  232. if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
  233. status = 0;
  234. return status;
  235. }
  236. static int issue_thinkpad_cmos_command(int cmos_cmd)
  237. {
  238. if (!cmos_handle)
  239. return -ENXIO;
  240. if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd))
  241. return -EIO;
  242. return 0;
  243. }
  244. /*************************************************************************
  245. * ACPI device model
  246. */
  247. static void drv_acpi_handle_init(char *name,
  248. acpi_handle *handle, acpi_handle parent,
  249. char **paths, int num_paths, char **path)
  250. {
  251. int i;
  252. acpi_status status;
  253. for (i = 0; i < num_paths; i++) {
  254. status = acpi_get_handle(parent, paths[i], handle);
  255. if (ACPI_SUCCESS(status)) {
  256. *path = paths[i];
  257. return;
  258. }
  259. }
  260. *handle = NULL;
  261. }
  262. static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data)
  263. {
  264. struct ibm_struct *ibm = data;
  265. if (!ibm || !ibm->acpi || !ibm->acpi->notify)
  266. return;
  267. ibm->acpi->notify(ibm, event);
  268. }
  269. static int __init setup_acpi_notify(struct ibm_struct *ibm)
  270. {
  271. acpi_status status;
  272. int ret;
  273. BUG_ON(!ibm->acpi);
  274. if (!*ibm->acpi->handle)
  275. return 0;
  276. dbg_printk(TPACPI_DBG_INIT,
  277. "setting up ACPI notify for %s\n", ibm->name);
  278. ret = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
  279. if (ret < 0) {
  280. printk(IBM_ERR "%s device not present\n", ibm->name);
  281. return -ENODEV;
  282. }
  283. acpi_driver_data(ibm->acpi->device) = ibm;
  284. sprintf(acpi_device_class(ibm->acpi->device), "%s/%s",
  285. IBM_ACPI_EVENT_PREFIX,
  286. ibm->name);
  287. status = acpi_install_notify_handler(*ibm->acpi->handle,
  288. ibm->acpi->type, dispatch_acpi_notify, ibm);
  289. if (ACPI_FAILURE(status)) {
  290. if (status == AE_ALREADY_EXISTS) {
  291. printk(IBM_NOTICE "another device driver is already handling %s events\n",
  292. ibm->name);
  293. } else {
  294. printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
  295. ibm->name, status);
  296. }
  297. return -ENODEV;
  298. }
  299. ibm->flags.acpi_notify_installed = 1;
  300. return 0;
  301. }
  302. static int __init tpacpi_device_add(struct acpi_device *device)
  303. {
  304. return 0;
  305. }
  306. static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
  307. {
  308. int ret;
  309. dbg_printk(TPACPI_DBG_INIT,
  310. "registering %s as an ACPI driver\n", ibm->name);
  311. BUG_ON(!ibm->acpi);
  312. ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
  313. if (!ibm->acpi->driver) {
  314. printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
  315. return -ENOMEM;
  316. }
  317. sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name);
  318. ibm->acpi->driver->ids = ibm->acpi->hid;
  319. ibm->acpi->driver->ops.add = &tpacpi_device_add;
  320. ret = acpi_bus_register_driver(ibm->acpi->driver);
  321. if (ret < 0) {
  322. printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
  323. ibm->acpi->hid, ret);
  324. kfree(ibm->acpi->driver);
  325. ibm->acpi->driver = NULL;
  326. } else if (!ret)
  327. ibm->flags.acpi_driver_registered = 1;
  328. return ret;
  329. }
  330. /****************************************************************************
  331. ****************************************************************************
  332. *
  333. * Procfs Helpers
  334. *
  335. ****************************************************************************
  336. ****************************************************************************/
  337. static int dispatch_procfs_read(char *page, char **start, off_t off,
  338. int count, int *eof, void *data)
  339. {
  340. struct ibm_struct *ibm = data;
  341. int len;
  342. if (!ibm || !ibm->read)
  343. return -EINVAL;
  344. len = ibm->read(page);
  345. if (len < 0)
  346. return len;
  347. if (len <= off + count)
  348. *eof = 1;
  349. *start = page + off;
  350. len -= off;
  351. if (len > count)
  352. len = count;
  353. if (len < 0)
  354. len = 0;
  355. return len;
  356. }
  357. static int dispatch_procfs_write(struct file *file,
  358. const char __user * userbuf,
  359. unsigned long count, void *data)
  360. {
  361. struct ibm_struct *ibm = data;
  362. char *kernbuf;
  363. int ret;
  364. if (!ibm || !ibm->write)
  365. return -EINVAL;
  366. kernbuf = kmalloc(count + 2, GFP_KERNEL);
  367. if (!kernbuf)
  368. return -ENOMEM;
  369. if (copy_from_user(kernbuf, userbuf, count)) {
  370. kfree(kernbuf);
  371. return -EFAULT;
  372. }
  373. kernbuf[count] = 0;
  374. strcat(kernbuf, ",");
  375. ret = ibm->write(kernbuf);
  376. if (ret == 0)
  377. ret = count;
  378. kfree(kernbuf);
  379. return ret;
  380. }
  381. static char *next_cmd(char **cmds)
  382. {
  383. char *start = *cmds;
  384. char *end;
  385. while ((end = strchr(start, ',')) && end == start)
  386. start = end + 1;
  387. if (!end)
  388. return NULL;
  389. *end = 0;
  390. *cmds = end + 1;
  391. return start;
  392. }
  393. /****************************************************************************
  394. ****************************************************************************
  395. *
  396. * Subdrivers
  397. *
  398. ****************************************************************************
  399. ****************************************************************************/
  400. /*************************************************************************
  401. * thinkpad-acpi init subdriver
  402. */
  403. static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
  404. {
  405. printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
  406. printk(IBM_INFO "%s\n", IBM_URL);
  407. if (ibm_thinkpad_ec_found)
  408. printk(IBM_INFO "ThinkPad EC firmware %s\n",
  409. ibm_thinkpad_ec_found);
  410. return 0;
  411. }
  412. static int thinkpad_acpi_driver_read(char *p)
  413. {
  414. int len = 0;
  415. len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
  416. len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
  417. return len;
  418. }
  419. static struct ibm_struct thinkpad_acpi_driver_data = {
  420. .name = "driver",
  421. .read = thinkpad_acpi_driver_read,
  422. };
  423. /*************************************************************************
  424. * Hotkey subdriver
  425. */
  426. static int hotkey_orig_status;
  427. static int hotkey_orig_mask;
  428. static int __init hotkey_init(struct ibm_init_struct *iibm)
  429. {
  430. int res;
  431. vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
  432. IBM_ACPIHANDLE_INIT(hkey);
  433. /* hotkey not supported on 570 */
  434. tp_features.hotkey = hkey_handle != NULL;
  435. vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
  436. str_supported(tp_features.hotkey));
  437. if (tp_features.hotkey) {
  438. /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
  439. A30, R30, R31, T20-22, X20-21, X22-24 */
  440. tp_features.hotkey_mask =
  441. acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
  442. vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
  443. str_supported(tp_features.hotkey_mask));
  444. res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask);
  445. if (res)
  446. return res;
  447. }
  448. return (tp_features.hotkey)? 0 : 1;
  449. }
  450. static void hotkey_exit(void)
  451. {
  452. int res;
  453. if (tp_features.hotkey) {
  454. dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n");
  455. res = hotkey_set(hotkey_orig_status, hotkey_orig_mask);
  456. if (res)
  457. printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n");
  458. }
  459. }
  460. static void hotkey_notify(struct ibm_struct *ibm, u32 event)
  461. {
  462. int hkey;
  463. if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
  464. acpi_bus_generate_event(ibm->acpi->device, event, hkey);
  465. else {
  466. printk(IBM_ERR "unknown hotkey event %d\n", event);
  467. acpi_bus_generate_event(ibm->acpi->device, event, 0);
  468. }
  469. }
  470. static int hotkey_get(int *status, int *mask)
  471. {
  472. if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
  473. return -EIO;
  474. if (tp_features.hotkey_mask)
  475. if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
  476. return -EIO;
  477. return 0;
  478. }
  479. static int hotkey_set(int status, int mask)
  480. {
  481. int i;
  482. if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
  483. return -EIO;
  484. if (tp_features.hotkey_mask)
  485. for (i = 0; i < 32; i++) {
  486. int bit = ((1 << i) & mask) != 0;
  487. if (!acpi_evalf(hkey_handle,
  488. NULL, "MHKM", "vdd", i + 1, bit))
  489. return -EIO;
  490. }
  491. return 0;
  492. }
  493. static int hotkey_read(char *p)
  494. {
  495. int res, status, mask;
  496. int len = 0;
  497. if (!tp_features.hotkey) {
  498. len += sprintf(p + len, "status:\t\tnot supported\n");
  499. return len;
  500. }
  501. res = hotkey_get(&status, &mask);
  502. if (res)
  503. return res;
  504. len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
  505. if (tp_features.hotkey_mask) {
  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 res, status, mask;
  518. char *cmd;
  519. int do_cmd = 0;
  520. if (!tp_features.hotkey)
  521. return -ENODEV;
  522. res = hotkey_get(&status, &mask);
  523. if (res)
  524. return res;
  525. while ((cmd = next_cmd(&buf))) {
  526. if (strlencmp(cmd, "enable") == 0) {
  527. status = 1;
  528. } else if (strlencmp(cmd, "disable") == 0) {
  529. status = 0;
  530. } else if (strlencmp(cmd, "reset") == 0) {
  531. status = hotkey_orig_status;
  532. mask = hotkey_orig_mask;
  533. } else if (sscanf(cmd, "0x%x", &mask) == 1) {
  534. /* mask set */
  535. } else if (sscanf(cmd, "%x", &mask) == 1) {
  536. /* mask set */
  537. } else
  538. return -EINVAL;
  539. do_cmd = 1;
  540. }
  541. if (do_cmd) {
  542. res = hotkey_set(status, mask);
  543. if (res)
  544. return res;
  545. }
  546. return 0;
  547. }
  548. static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
  549. .hid = IBM_HKEY_HID,
  550. .notify = hotkey_notify,
  551. .handle = &hkey_handle,
  552. .type = ACPI_DEVICE_NOTIFY,
  553. };
  554. static struct ibm_struct hotkey_driver_data = {
  555. .name = "hotkey",
  556. .read = hotkey_read,
  557. .write = hotkey_write,
  558. .exit = hotkey_exit,
  559. .acpi = &ibm_hotkey_acpidriver,
  560. };
  561. /*************************************************************************
  562. * Bluetooth subdriver
  563. */
  564. static int __init bluetooth_init(struct ibm_init_struct *iibm)
  565. {
  566. int status = 0;
  567. vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
  568. IBM_ACPIHANDLE_INIT(hkey);
  569. /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
  570. G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
  571. tp_features.bluetooth = hkey_handle &&
  572. acpi_evalf(hkey_handle, &status, "GBDC", "qd");
  573. vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n",
  574. str_supported(tp_features.bluetooth),
  575. status);
  576. if (tp_features.bluetooth &&
  577. !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
  578. /* no bluetooth hardware present in system */
  579. tp_features.bluetooth = 0;
  580. dbg_printk(TPACPI_DBG_INIT,
  581. "bluetooth hardware not installed\n");
  582. }
  583. return (tp_features.bluetooth)? 0 : 1;
  584. }
  585. static int bluetooth_get_radiosw(void)
  586. {
  587. int status;
  588. if (!tp_features.bluetooth)
  589. return -ENODEV;
  590. if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
  591. return -EIO;
  592. return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0);
  593. }
  594. static int bluetooth_set_radiosw(int radio_on)
  595. {
  596. int status;
  597. if (!tp_features.bluetooth)
  598. return -ENODEV;
  599. if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
  600. return -EIO;
  601. if (radio_on)
  602. status |= TP_ACPI_BLUETOOTH_RADIOSSW;
  603. else
  604. status &= ~TP_ACPI_BLUETOOTH_RADIOSSW;
  605. if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
  606. return -EIO;
  607. return 0;
  608. }
  609. static int bluetooth_read(char *p)
  610. {
  611. int len = 0;
  612. int status = bluetooth_get_radiosw();
  613. if (!tp_features.bluetooth)
  614. len += sprintf(p + len, "status:\t\tnot supported\n");
  615. else {
  616. len += sprintf(p + len, "status:\t\t%s\n",
  617. (status)? "enabled" : "disabled");
  618. len += sprintf(p + len, "commands:\tenable, disable\n");
  619. }
  620. return len;
  621. }
  622. static int bluetooth_write(char *buf)
  623. {
  624. char *cmd;
  625. if (!tp_features.bluetooth)
  626. return -ENODEV;
  627. while ((cmd = next_cmd(&buf))) {
  628. if (strlencmp(cmd, "enable") == 0) {
  629. bluetooth_set_radiosw(1);
  630. } else if (strlencmp(cmd, "disable") == 0) {
  631. bluetooth_set_radiosw(0);
  632. } else
  633. return -EINVAL;
  634. }
  635. return 0;
  636. }
  637. static struct ibm_struct bluetooth_driver_data = {
  638. .name = "bluetooth",
  639. .read = bluetooth_read,
  640. .write = bluetooth_write,
  641. };
  642. /*************************************************************************
  643. * Wan subdriver
  644. */
  645. static int __init wan_init(struct ibm_init_struct *iibm)
  646. {
  647. int status = 0;
  648. vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
  649. IBM_ACPIHANDLE_INIT(hkey);
  650. tp_features.wan = hkey_handle &&
  651. acpi_evalf(hkey_handle, &status, "GWAN", "qd");
  652. vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n",
  653. str_supported(tp_features.wan),
  654. status);
  655. if (tp_features.wan &&
  656. !(status & TP_ACPI_WANCARD_HWPRESENT)) {
  657. /* no wan hardware present in system */
  658. tp_features.wan = 0;
  659. dbg_printk(TPACPI_DBG_INIT,
  660. "wan hardware not installed\n");
  661. }
  662. return (tp_features.wan)? 0 : 1;
  663. }
  664. static int wan_get_radiosw(void)
  665. {
  666. int status;
  667. if (!tp_features.wan)
  668. return -ENODEV;
  669. if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
  670. return -EIO;
  671. return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0);
  672. }
  673. static int wan_set_radiosw(int radio_on)
  674. {
  675. int status;
  676. if (!tp_features.wan)
  677. return -ENODEV;
  678. if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
  679. return -EIO;
  680. if (radio_on)
  681. status |= TP_ACPI_WANCARD_RADIOSSW;
  682. else
  683. status &= ~TP_ACPI_WANCARD_RADIOSSW;
  684. if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
  685. return -EIO;
  686. return 0;
  687. }
  688. static int wan_read(char *p)
  689. {
  690. int len = 0;
  691. int status = wan_get_radiosw();
  692. if (!tp_features.wan)
  693. len += sprintf(p + len, "status:\t\tnot supported\n");
  694. else {
  695. len += sprintf(p + len, "status:\t\t%s\n",
  696. (status)? "enabled" : "disabled");
  697. len += sprintf(p + len, "commands:\tenable, disable\n");
  698. }
  699. return len;
  700. }
  701. static int wan_write(char *buf)
  702. {
  703. char *cmd;
  704. if (!tp_features.wan)
  705. return -ENODEV;
  706. while ((cmd = next_cmd(&buf))) {
  707. if (strlencmp(cmd, "enable") == 0) {
  708. wan_set_radiosw(1);
  709. } else if (strlencmp(cmd, "disable") == 0) {
  710. wan_set_radiosw(0);
  711. } else
  712. return -EINVAL;
  713. }
  714. return 0;
  715. }
  716. static struct ibm_struct wan_driver_data = {
  717. .name = "wan",
  718. .read = wan_read,
  719. .write = wan_write,
  720. .flags.experimental = 1,
  721. };
  722. /*************************************************************************
  723. * Video subdriver
  724. */
  725. static enum video_access_mode video_supported;
  726. static int video_orig_autosw;
  727. IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
  728. "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
  729. "\\_SB.PCI0.VID0", /* 770e */
  730. "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
  731. "\\_SB.PCI0.AGP.VID", /* all others */
  732. ); /* R30, R31 */
  733. IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
  734. static int __init video_init(struct ibm_init_struct *iibm)
  735. {
  736. int ivga;
  737. vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
  738. IBM_ACPIHANDLE_INIT(vid);
  739. IBM_ACPIHANDLE_INIT(vid2);
  740. if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
  741. /* G41, assume IVGA doesn't change */
  742. vid_handle = vid2_handle;
  743. if (!vid_handle)
  744. /* video switching not supported on R30, R31 */
  745. video_supported = TPACPI_VIDEO_NONE;
  746. else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
  747. /* 570 */
  748. video_supported = TPACPI_VIDEO_570;
  749. else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
  750. /* 600e/x, 770e, 770x */
  751. video_supported = TPACPI_VIDEO_770;
  752. else
  753. /* all others */
  754. video_supported = TPACPI_VIDEO_NEW;
  755. vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n",
  756. str_supported(video_supported != TPACPI_VIDEO_NONE),
  757. video_supported);
  758. return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
  759. }
  760. static void video_exit(void)
  761. {
  762. dbg_printk(TPACPI_DBG_EXIT,
  763. "restoring original video autoswitch mode\n");
  764. if (video_autosw_set(video_orig_autosw))
  765. printk(IBM_ERR "error while trying to restore original "
  766. "video autoswitch mode\n");
  767. }
  768. static int video_outputsw_get(void)
  769. {
  770. int status = 0;
  771. int i;
  772. switch (video_supported) {
  773. case TPACPI_VIDEO_570:
  774. if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd",
  775. TP_ACPI_VIDEO_570_PHSCMD))
  776. return -EIO;
  777. status = i & TP_ACPI_VIDEO_570_PHSMASK;
  778. break;
  779. case TPACPI_VIDEO_770:
  780. if (!acpi_evalf(NULL, &i, "\\VCDL", "d"))
  781. return -EIO;
  782. if (i)
  783. status |= TP_ACPI_VIDEO_S_LCD;
  784. if (!acpi_evalf(NULL, &i, "\\VCDC", "d"))
  785. return -EIO;
  786. if (i)
  787. status |= TP_ACPI_VIDEO_S_CRT;
  788. break;
  789. case TPACPI_VIDEO_NEW:
  790. if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) ||
  791. !acpi_evalf(NULL, &i, "\\VCDC", "d"))
  792. return -EIO;
  793. if (i)
  794. status |= TP_ACPI_VIDEO_S_CRT;
  795. if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) ||
  796. !acpi_evalf(NULL, &i, "\\VCDL", "d"))
  797. return -EIO;
  798. if (i)
  799. status |= TP_ACPI_VIDEO_S_LCD;
  800. if (!acpi_evalf(NULL, &i, "\\VCDD", "d"))
  801. return -EIO;
  802. if (i)
  803. status |= TP_ACPI_VIDEO_S_DVI;
  804. break;
  805. default:
  806. return -ENOSYS;
  807. }
  808. return status;
  809. }
  810. static int video_outputsw_set(int status)
  811. {
  812. int autosw;
  813. int res = 0;
  814. switch (video_supported) {
  815. case TPACPI_VIDEO_570:
  816. res = acpi_evalf(NULL, NULL,
  817. "\\_SB.PHS2", "vdd",
  818. TP_ACPI_VIDEO_570_PHS2CMD,
  819. status | TP_ACPI_VIDEO_570_PHS2SET);
  820. break;
  821. case TPACPI_VIDEO_770:
  822. autosw = video_autosw_get();
  823. if (autosw < 0)
  824. return autosw;
  825. res = video_autosw_set(1);
  826. if (res)
  827. return res;
  828. res = acpi_evalf(vid_handle, NULL,
  829. "ASWT", "vdd", status * 0x100, 0);
  830. if (!autosw && video_autosw_set(autosw)) {
  831. printk(IBM_ERR "video auto-switch left enabled due to error\n");
  832. return -EIO;
  833. }
  834. break;
  835. case TPACPI_VIDEO_NEW:
  836. res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
  837. acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
  838. break;
  839. default:
  840. return -ENOSYS;
  841. }
  842. return (res)? 0 : -EIO;
  843. }
  844. static int video_autosw_get(void)
  845. {
  846. int autosw = 0;
  847. switch (video_supported) {
  848. case TPACPI_VIDEO_570:
  849. if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d"))
  850. return -EIO;
  851. break;
  852. case TPACPI_VIDEO_770:
  853. case TPACPI_VIDEO_NEW:
  854. if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d"))
  855. return -EIO;
  856. break;
  857. default:
  858. return -ENOSYS;
  859. }
  860. return autosw & 1;
  861. }
  862. static int video_autosw_set(int enable)
  863. {
  864. if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0))
  865. return -EIO;
  866. return 0;
  867. }
  868. static int video_outputsw_cycle(void)
  869. {
  870. int autosw = video_autosw_get();
  871. int res;
  872. if (autosw < 0)
  873. return autosw;
  874. switch (video_supported) {
  875. case TPACPI_VIDEO_570:
  876. res = video_autosw_set(1);
  877. if (res)
  878. return res;
  879. res = acpi_evalf(ec_handle, NULL, "_Q16", "v");
  880. break;
  881. case TPACPI_VIDEO_770:
  882. case TPACPI_VIDEO_NEW:
  883. res = video_autosw_set(1);
  884. if (res)
  885. return res;
  886. res = acpi_evalf(vid_handle, NULL, "VSWT", "v");
  887. break;
  888. default:
  889. return -ENOSYS;
  890. }
  891. if (!autosw && video_autosw_set(autosw)) {
  892. printk(IBM_ERR "video auto-switch left enabled due to error\n");
  893. return -EIO;
  894. }
  895. return (res)? 0 : -EIO;
  896. }
  897. static int video_expand_toggle(void)
  898. {
  899. switch (video_supported) {
  900. case TPACPI_VIDEO_570:
  901. return acpi_evalf(ec_handle, NULL, "_Q17", "v")?
  902. 0 : -EIO;
  903. case TPACPI_VIDEO_770:
  904. return acpi_evalf(vid_handle, NULL, "VEXP", "v")?
  905. 0 : -EIO;
  906. case TPACPI_VIDEO_NEW:
  907. return acpi_evalf(NULL, NULL, "\\VEXP", "v")?
  908. 0 : -EIO;
  909. default:
  910. return -ENOSYS;
  911. }
  912. /* not reached */
  913. }
  914. static int video_read(char *p)
  915. {
  916. int status, autosw;
  917. int len = 0;
  918. if (video_supported == TPACPI_VIDEO_NONE) {
  919. len += sprintf(p + len, "status:\t\tnot supported\n");
  920. return len;
  921. }
  922. status = video_outputsw_get();
  923. if (status < 0)
  924. return status;
  925. autosw = video_autosw_get();
  926. if (autosw < 0)
  927. return autosw;
  928. len += sprintf(p + len, "status:\t\tsupported\n");
  929. len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
  930. len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
  931. if (video_supported == TPACPI_VIDEO_NEW)
  932. len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
  933. len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
  934. len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
  935. len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
  936. if (video_supported == TPACPI_VIDEO_NEW)
  937. len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
  938. len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
  939. len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
  940. return len;
  941. }
  942. static int video_write(char *buf)
  943. {
  944. char *cmd;
  945. int enable, disable, status;
  946. int res;
  947. if (video_supported == TPACPI_VIDEO_NONE)
  948. return -ENODEV;
  949. enable = 0;
  950. disable = 0;
  951. while ((cmd = next_cmd(&buf))) {
  952. if (strlencmp(cmd, "lcd_enable") == 0) {
  953. enable |= TP_ACPI_VIDEO_S_LCD;
  954. } else if (strlencmp(cmd, "lcd_disable") == 0) {
  955. disable |= TP_ACPI_VIDEO_S_LCD;
  956. } else if (strlencmp(cmd, "crt_enable") == 0) {
  957. enable |= TP_ACPI_VIDEO_S_CRT;
  958. } else if (strlencmp(cmd, "crt_disable") == 0) {
  959. disable |= TP_ACPI_VIDEO_S_CRT;
  960. } else if (video_supported == TPACPI_VIDEO_NEW &&
  961. strlencmp(cmd, "dvi_enable") == 0) {
  962. enable |= TP_ACPI_VIDEO_S_DVI;
  963. } else if (video_supported == TPACPI_VIDEO_NEW &&
  964. strlencmp(cmd, "dvi_disable") == 0) {
  965. disable |= TP_ACPI_VIDEO_S_DVI;
  966. } else if (strlencmp(cmd, "auto_enable") == 0) {
  967. res = video_autosw_set(1);
  968. if (res)
  969. return res;
  970. } else if (strlencmp(cmd, "auto_disable") == 0) {
  971. res = video_autosw_set(0);
  972. if (res)
  973. return res;
  974. } else if (strlencmp(cmd, "video_switch") == 0) {
  975. res = video_outputsw_cycle();
  976. if (res)
  977. return res;
  978. } else if (strlencmp(cmd, "expand_toggle") == 0) {
  979. res = video_expand_toggle();
  980. if (res)
  981. return res;
  982. } else
  983. return -EINVAL;
  984. }
  985. if (enable || disable) {
  986. status = video_outputsw_get();
  987. if (status < 0)
  988. return status;
  989. res = video_outputsw_set((status & ~disable) | enable);
  990. if (res)
  991. return res;
  992. }
  993. return 0;
  994. }
  995. static struct ibm_struct video_driver_data = {
  996. .name = "video",
  997. .read = video_read,
  998. .write = video_write,
  999. .exit = video_exit,
  1000. };
  1001. /*************************************************************************
  1002. * Light (thinklight) subdriver
  1003. */
  1004. IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
  1005. IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
  1006. static int __init light_init(struct ibm_init_struct *iibm)
  1007. {
  1008. vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
  1009. IBM_ACPIHANDLE_INIT(ledb);
  1010. IBM_ACPIHANDLE_INIT(lght);
  1011. IBM_ACPIHANDLE_INIT(cmos);
  1012. /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
  1013. tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
  1014. if (tp_features.light)
  1015. /* light status not supported on
  1016. 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
  1017. tp_features.light_status =
  1018. acpi_evalf(ec_handle, NULL, "KBLT", "qv");
  1019. vdbg_printk(TPACPI_DBG_INIT, "light is %s\n",
  1020. str_supported(tp_features.light));
  1021. return (tp_features.light)? 0 : 1;
  1022. }
  1023. static int light_read(char *p)
  1024. {
  1025. int len = 0;
  1026. int status = 0;
  1027. if (!tp_features.light) {
  1028. len += sprintf(p + len, "status:\t\tnot supported\n");
  1029. } else if (!tp_features.light_status) {
  1030. len += sprintf(p + len, "status:\t\tunknown\n");
  1031. len += sprintf(p + len, "commands:\ton, off\n");
  1032. } else {
  1033. if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
  1034. return -EIO;
  1035. len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
  1036. len += sprintf(p + len, "commands:\ton, off\n");
  1037. }
  1038. return len;
  1039. }
  1040. static int light_write(char *buf)
  1041. {
  1042. int cmos_cmd, lght_cmd;
  1043. char *cmd;
  1044. int success;
  1045. if (!tp_features.light)
  1046. return -ENODEV;
  1047. while ((cmd = next_cmd(&buf))) {
  1048. if (strlencmp(cmd, "on") == 0) {
  1049. cmos_cmd = 0x0c;
  1050. lght_cmd = 1;
  1051. } else if (strlencmp(cmd, "off") == 0) {
  1052. cmos_cmd = 0x0d;
  1053. lght_cmd = 0;
  1054. } else
  1055. return -EINVAL;
  1056. success = cmos_handle ?
  1057. acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
  1058. acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
  1059. if (!success)
  1060. return -EIO;
  1061. }
  1062. return 0;
  1063. }
  1064. static struct ibm_struct light_driver_data = {
  1065. .name = "light",
  1066. .read = light_read,
  1067. .write = light_write,
  1068. };
  1069. /*************************************************************************
  1070. * Dock subdriver
  1071. */
  1072. #ifdef CONFIG_THINKPAD_ACPI_DOCK
  1073. IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
  1074. "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
  1075. "\\_SB.PCI0.PCI1.DOCK", /* all others */
  1076. "\\_SB.PCI.ISA.SLCE", /* 570 */
  1077. ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
  1078. /* don't list other alternatives as we install a notify handler on the 570 */
  1079. IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
  1080. #define dock_docked() (_sta(dock_handle) & 1)
  1081. static int __init dock_init(struct ibm_init_struct *iibm)
  1082. {
  1083. vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
  1084. IBM_ACPIHANDLE_INIT(dock);
  1085. IBM_ACPIHANDLE_INIT(pci);
  1086. vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
  1087. str_supported(dock_handle != NULL));
  1088. return (dock_handle)? 0 : 1;
  1089. }
  1090. static void dock_notify(struct ibm_struct *ibm, u32 event)
  1091. {
  1092. int docked = dock_docked();
  1093. int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, IBM_PCI_HID);
  1094. if (event == 1 && !pci) /* 570 */
  1095. acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
  1096. else if (event == 1 && pci) /* 570 */
  1097. acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
  1098. else if (event == 3 && docked)
  1099. acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
  1100. else if (event == 3 && !docked)
  1101. acpi_bus_generate_event(ibm->acpi->device, event, 2); /* undock */
  1102. else if (event == 0 && docked)
  1103. acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
  1104. else {
  1105. printk(IBM_ERR "unknown dock event %d, status %d\n",
  1106. event, _sta(dock_handle));
  1107. acpi_bus_generate_event(ibm->acpi->device, event, 0); /* unknown */
  1108. }
  1109. }
  1110. static int dock_read(char *p)
  1111. {
  1112. int len = 0;
  1113. int docked = dock_docked();
  1114. if (!dock_handle)
  1115. len += sprintf(p + len, "status:\t\tnot supported\n");
  1116. else if (!docked)
  1117. len += sprintf(p + len, "status:\t\tundocked\n");
  1118. else {
  1119. len += sprintf(p + len, "status:\t\tdocked\n");
  1120. len += sprintf(p + len, "commands:\tdock, undock\n");
  1121. }
  1122. return len;
  1123. }
  1124. static int dock_write(char *buf)
  1125. {
  1126. char *cmd;
  1127. if (!dock_docked())
  1128. return -ENODEV;
  1129. while ((cmd = next_cmd(&buf))) {
  1130. if (strlencmp(cmd, "undock") == 0) {
  1131. if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
  1132. !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
  1133. return -EIO;
  1134. } else if (strlencmp(cmd, "dock") == 0) {
  1135. if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
  1136. return -EIO;
  1137. } else
  1138. return -EINVAL;
  1139. }
  1140. return 0;
  1141. }
  1142. static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
  1143. {
  1144. .notify = dock_notify,
  1145. .handle = &dock_handle,
  1146. .type = ACPI_SYSTEM_NOTIFY,
  1147. },
  1148. {
  1149. .hid = IBM_PCI_HID,
  1150. .notify = dock_notify,
  1151. .handle = &pci_handle,
  1152. .type = ACPI_SYSTEM_NOTIFY,
  1153. },
  1154. };
  1155. static struct ibm_struct dock_driver_data[2] = {
  1156. {
  1157. .name = "dock",
  1158. .read = dock_read,
  1159. .write = dock_write,
  1160. .acpi = &ibm_dock_acpidriver[0],
  1161. },
  1162. {
  1163. .name = "dock",
  1164. .acpi = &ibm_dock_acpidriver[1],
  1165. },
  1166. };
  1167. #endif /* CONFIG_THINKPAD_ACPI_DOCK */
  1168. /*************************************************************************
  1169. * Bay subdriver
  1170. */
  1171. #ifdef CONFIG_THINKPAD_ACPI_BAY
  1172. IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
  1173. "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
  1174. "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
  1175. "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
  1176. ); /* A21e, R30, R31 */
  1177. IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
  1178. "_EJ0", /* all others */
  1179. ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
  1180. IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
  1181. "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
  1182. ); /* all others */
  1183. IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
  1184. "_EJ0", /* 770x */
  1185. ); /* all others */
  1186. static int __init bay_init(struct ibm_init_struct *iibm)
  1187. {
  1188. vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
  1189. IBM_ACPIHANDLE_INIT(bay);
  1190. if (bay_handle)
  1191. IBM_ACPIHANDLE_INIT(bay_ej);
  1192. IBM_ACPIHANDLE_INIT(bay2);
  1193. if (bay2_handle)
  1194. IBM_ACPIHANDLE_INIT(bay2_ej);
  1195. tp_features.bay_status = bay_handle &&
  1196. acpi_evalf(bay_handle, NULL, "_STA", "qv");
  1197. tp_features.bay_status2 = bay2_handle &&
  1198. acpi_evalf(bay2_handle, NULL, "_STA", "qv");
  1199. tp_features.bay_eject = bay_handle && bay_ej_handle &&
  1200. (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
  1201. tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
  1202. (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
  1203. vdbg_printk(TPACPI_DBG_INIT,
  1204. "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
  1205. str_supported(tp_features.bay_status),
  1206. str_supported(tp_features.bay_eject),
  1207. str_supported(tp_features.bay_status2),
  1208. str_supported(tp_features.bay_eject2));
  1209. return (tp_features.bay_status || tp_features.bay_eject ||
  1210. tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
  1211. }
  1212. static void bay_notify(struct ibm_struct *ibm, u32 event)
  1213. {
  1214. acpi_bus_generate_event(ibm->acpi->device, event, 0);
  1215. }
  1216. #define bay_occupied(b) (_sta(b##_handle) & 1)
  1217. static int bay_read(char *p)
  1218. {
  1219. int len = 0;
  1220. int occupied = bay_occupied(bay);
  1221. int occupied2 = bay_occupied(bay2);
  1222. int eject, eject2;
  1223. len += sprintf(p + len, "status:\t\t%s\n",
  1224. tp_features.bay_status ?
  1225. (occupied ? "occupied" : "unoccupied") :
  1226. "not supported");
  1227. if (tp_features.bay_status2)
  1228. len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
  1229. "occupied" : "unoccupied");
  1230. eject = tp_features.bay_eject && occupied;
  1231. eject2 = tp_features.bay_eject2 && occupied2;
  1232. if (eject && eject2)
  1233. len += sprintf(p + len, "commands:\teject, eject2\n");
  1234. else if (eject)
  1235. len += sprintf(p + len, "commands:\teject\n");
  1236. else if (eject2)
  1237. len += sprintf(p + len, "commands:\teject2\n");
  1238. return len;
  1239. }
  1240. static int bay_write(char *buf)
  1241. {
  1242. char *cmd;
  1243. if (!tp_features.bay_eject && !tp_features.bay_eject2)
  1244. return -ENODEV;
  1245. while ((cmd = next_cmd(&buf))) {
  1246. if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
  1247. if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
  1248. return -EIO;
  1249. } else if (tp_features.bay_eject2 &&
  1250. strlencmp(cmd, "eject2") == 0) {
  1251. if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
  1252. return -EIO;
  1253. } else
  1254. return -EINVAL;
  1255. }
  1256. return 0;
  1257. }
  1258. static struct tp_acpi_drv_struct ibm_bay_acpidriver = {
  1259. .notify = bay_notify,
  1260. .handle = &bay_handle,
  1261. .type = ACPI_SYSTEM_NOTIFY,
  1262. };
  1263. static struct ibm_struct bay_driver_data = {
  1264. .name = "bay",
  1265. .read = bay_read,
  1266. .write = bay_write,
  1267. .acpi = &ibm_bay_acpidriver,
  1268. };
  1269. #endif /* CONFIG_THINKPAD_ACPI_BAY */
  1270. /*************************************************************************
  1271. * CMOS subdriver
  1272. */
  1273. static int __init cmos_init(struct ibm_init_struct *iibm)
  1274. {
  1275. vdbg_printk(TPACPI_DBG_INIT,
  1276. "initializing cmos commands subdriver\n");
  1277. IBM_ACPIHANDLE_INIT(cmos);
  1278. vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
  1279. str_supported(cmos_handle != NULL));
  1280. return (cmos_handle)? 0 : 1;
  1281. }
  1282. static int cmos_read(char *p)
  1283. {
  1284. int len = 0;
  1285. /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
  1286. R30, R31, T20-22, X20-21 */
  1287. if (!cmos_handle)
  1288. len += sprintf(p + len, "status:\t\tnot supported\n");
  1289. else {
  1290. len += sprintf(p + len, "status:\t\tsupported\n");
  1291. len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
  1292. }
  1293. return len;
  1294. }
  1295. static int cmos_write(char *buf)
  1296. {
  1297. char *cmd;
  1298. int cmos_cmd, res;
  1299. while ((cmd = next_cmd(&buf))) {
  1300. if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
  1301. cmos_cmd >= 0 && cmos_cmd <= 21) {
  1302. /* cmos_cmd set */
  1303. } else
  1304. return -EINVAL;
  1305. res = issue_thinkpad_cmos_command(cmos_cmd);
  1306. if (res)
  1307. return res;
  1308. }
  1309. return 0;
  1310. }
  1311. static struct ibm_struct cmos_driver_data = {
  1312. .name = "cmos",
  1313. .read = cmos_read,
  1314. .write = cmos_write,
  1315. };
  1316. /*************************************************************************
  1317. * LED subdriver
  1318. */
  1319. static enum led_access_mode led_supported;
  1320. IBM_HANDLE(led, ec, "SLED", /* 570 */
  1321. "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
  1322. "LED", /* all others */
  1323. ); /* R30, R31 */
  1324. static int __init led_init(struct ibm_init_struct *iibm)
  1325. {
  1326. vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
  1327. IBM_ACPIHANDLE_INIT(led);
  1328. if (!led_handle)
  1329. /* led not supported on R30, R31 */
  1330. led_supported = TPACPI_LED_NONE;
  1331. else if (strlencmp(led_path, "SLED") == 0)
  1332. /* 570 */
  1333. led_supported = TPACPI_LED_570;
  1334. else if (strlencmp(led_path, "SYSL") == 0)
  1335. /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
  1336. led_supported = TPACPI_LED_OLD;
  1337. else
  1338. /* all others */
  1339. led_supported = TPACPI_LED_NEW;
  1340. vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
  1341. str_supported(led_supported), led_supported);
  1342. return (led_supported != TPACPI_LED_NONE)? 0 : 1;
  1343. }
  1344. #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
  1345. static int led_read(char *p)
  1346. {
  1347. int len = 0;
  1348. if (!led_supported) {
  1349. len += sprintf(p + len, "status:\t\tnot supported\n");
  1350. return len;
  1351. }
  1352. len += sprintf(p + len, "status:\t\tsupported\n");
  1353. if (led_supported == TPACPI_LED_570) {
  1354. /* 570 */
  1355. int i, status;
  1356. for (i = 0; i < 8; i++) {
  1357. if (!acpi_evalf(ec_handle,
  1358. &status, "GLED", "dd", 1 << i))
  1359. return -EIO;
  1360. len += sprintf(p + len, "%d:\t\t%s\n",
  1361. i, led_status(status));
  1362. }
  1363. }
  1364. len += sprintf(p + len, "commands:\t"
  1365. "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
  1366. return len;
  1367. }
  1368. /* off, on, blink */
  1369. static const int led_sled_arg1[] = { 0, 1, 3 };
  1370. static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
  1371. static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
  1372. static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
  1373. static int led_write(char *buf)
  1374. {
  1375. char *cmd;
  1376. int led, ind, ret;
  1377. if (!led_supported)
  1378. return -ENODEV;
  1379. while ((cmd = next_cmd(&buf))) {
  1380. if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
  1381. return -EINVAL;
  1382. if (strstr(cmd, "off")) {
  1383. ind = 0;
  1384. } else if (strstr(cmd, "on")) {
  1385. ind = 1;
  1386. } else if (strstr(cmd, "blink")) {
  1387. ind = 2;
  1388. } else
  1389. return -EINVAL;
  1390. if (led_supported == TPACPI_LED_570) {
  1391. /* 570 */
  1392. led = 1 << led;
  1393. if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
  1394. led, led_sled_arg1[ind]))
  1395. return -EIO;
  1396. } else if (led_supported == TPACPI_LED_OLD) {
  1397. /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
  1398. led = 1 << led;
  1399. ret = ec_write(TPACPI_LED_EC_HLMS, led);
  1400. if (ret >= 0)
  1401. ret =
  1402. ec_write(TPACPI_LED_EC_HLBL,
  1403. led * led_exp_hlbl[ind]);
  1404. if (ret >= 0)
  1405. ret =
  1406. ec_write(TPACPI_LED_EC_HLCL,
  1407. led * led_exp_hlcl[ind]);
  1408. if (ret < 0)
  1409. return ret;
  1410. } else {
  1411. /* all others */
  1412. if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
  1413. led, led_led_arg1[ind]))
  1414. return -EIO;
  1415. }
  1416. }
  1417. return 0;
  1418. }
  1419. static struct ibm_struct led_driver_data = {
  1420. .name = "led",
  1421. .read = led_read,
  1422. .write = led_write,
  1423. };
  1424. /*************************************************************************
  1425. * Beep subdriver
  1426. */
  1427. IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
  1428. static int __init beep_init(struct ibm_init_struct *iibm)
  1429. {
  1430. vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
  1431. IBM_ACPIHANDLE_INIT(beep);
  1432. vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
  1433. str_supported(beep_handle != NULL));
  1434. return (beep_handle)? 0 : 1;
  1435. }
  1436. static int beep_read(char *p)
  1437. {
  1438. int len = 0;
  1439. if (!beep_handle)
  1440. len += sprintf(p + len, "status:\t\tnot supported\n");
  1441. else {
  1442. len += sprintf(p + len, "status:\t\tsupported\n");
  1443. len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
  1444. }
  1445. return len;
  1446. }
  1447. static int beep_write(char *buf)
  1448. {
  1449. char *cmd;
  1450. int beep_cmd;
  1451. if (!beep_handle)
  1452. return -ENODEV;
  1453. while ((cmd = next_cmd(&buf))) {
  1454. if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
  1455. beep_cmd >= 0 && beep_cmd <= 17) {
  1456. /* beep_cmd set */
  1457. } else
  1458. return -EINVAL;
  1459. if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
  1460. return -EIO;
  1461. }
  1462. return 0;
  1463. }
  1464. static struct ibm_struct beep_driver_data = {
  1465. .name = "beep",
  1466. .read = beep_read,
  1467. .write = beep_write,
  1468. };
  1469. /*************************************************************************
  1470. * Thermal subdriver
  1471. */
  1472. static enum thermal_access_mode thermal_read_mode;
  1473. static int __init thermal_init(struct ibm_init_struct *iibm)
  1474. {
  1475. u8 t, ta1, ta2;
  1476. int i;
  1477. int acpi_tmp7;
  1478. vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
  1479. acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
  1480. if (ibm_thinkpad_ec_found && experimental) {
  1481. /*
  1482. * Direct EC access mode: sensors at registers
  1483. * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
  1484. * non-implemented, thermal sensors return 0x80 when
  1485. * not available
  1486. */
  1487. ta1 = ta2 = 0;
  1488. for (i = 0; i < 8; i++) {
  1489. if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
  1490. ta1 |= t;
  1491. } else {
  1492. ta1 = 0;
  1493. break;
  1494. }
  1495. if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
  1496. ta2 |= t;
  1497. } else {
  1498. ta1 = 0;
  1499. break;
  1500. }
  1501. }
  1502. if (ta1 == 0) {
  1503. /* This is sheer paranoia, but we handle it anyway */
  1504. if (acpi_tmp7) {
  1505. printk(IBM_ERR
  1506. "ThinkPad ACPI EC access misbehaving, "
  1507. "falling back to ACPI TMPx access mode\n");
  1508. thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
  1509. } else {
  1510. printk(IBM_ERR
  1511. "ThinkPad ACPI EC access misbehaving, "
  1512. "disabling thermal sensors access\n");
  1513. thermal_read_mode = TPACPI_THERMAL_NONE;
  1514. }
  1515. } else {
  1516. thermal_read_mode =
  1517. (ta2 != 0) ?
  1518. TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
  1519. }
  1520. } else if (acpi_tmp7) {
  1521. if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
  1522. /* 600e/x, 770e, 770x */
  1523. thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
  1524. } else {
  1525. /* Standard ACPI TMPx access, max 8 sensors */
  1526. thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
  1527. }
  1528. } else {
  1529. /* temperatures not supported on 570, G4x, R30, R31, R32 */
  1530. thermal_read_mode = TPACPI_THERMAL_NONE;
  1531. }
  1532. vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n",
  1533. str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
  1534. thermal_read_mode);
  1535. return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
  1536. }
  1537. /* idx is zero-based */
  1538. static int thermal_get_sensor(int idx, s32 *value)
  1539. {
  1540. int t;
  1541. s8 tmp;
  1542. char tmpi[5];
  1543. t = TP_EC_THERMAL_TMP0;
  1544. switch (thermal_read_mode) {
  1545. #if TPACPI_MAX_THERMAL_SENSORS >= 16
  1546. case TPACPI_THERMAL_TPEC_16:
  1547. if (idx >= 8 && idx <= 15) {
  1548. t = TP_EC_THERMAL_TMP8;
  1549. idx -= 8;
  1550. }
  1551. /* fallthrough */
  1552. #endif
  1553. case TPACPI_THERMAL_TPEC_8:
  1554. if (idx <= 7) {
  1555. if (!acpi_ec_read(t + idx, &tmp))
  1556. return -EIO;
  1557. *value = tmp * 1000;
  1558. return 0;
  1559. }
  1560. break;
  1561. case TPACPI_THERMAL_ACPI_UPDT:
  1562. if (idx <= 7) {
  1563. snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
  1564. if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
  1565. return -EIO;
  1566. if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
  1567. return -EIO;
  1568. *value = (t - 2732) * 100;
  1569. return 0;
  1570. }
  1571. break;
  1572. case TPACPI_THERMAL_ACPI_TMP07:
  1573. if (idx <= 7) {
  1574. snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
  1575. if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
  1576. return -EIO;
  1577. *value = t * 1000;
  1578. return 0;
  1579. }
  1580. break;
  1581. case TPACPI_THERMAL_NONE:
  1582. default:
  1583. return -ENOSYS;
  1584. }
  1585. return -EINVAL;
  1586. }
  1587. static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
  1588. {
  1589. int res, i;
  1590. int n;
  1591. n = 8;
  1592. i = 0;
  1593. if (!s)
  1594. return -EINVAL;
  1595. if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
  1596. n = 16;
  1597. for(i = 0 ; i < n; i++) {
  1598. res = thermal_get_sensor(i, &s->temp[i]);
  1599. if (res)
  1600. return res;
  1601. }
  1602. return n;
  1603. }
  1604. static int thermal_read(char *p)
  1605. {
  1606. int len = 0;
  1607. int n, i;
  1608. struct ibm_thermal_sensors_struct t;
  1609. n = thermal_get_sensors(&t);
  1610. if (unlikely(n < 0))
  1611. return n;
  1612. len += sprintf(p + len, "temperatures:\t");
  1613. if (n > 0) {
  1614. for (i = 0; i < (n - 1); i++)
  1615. len += sprintf(p + len, "%d ", t.temp[i] / 1000);
  1616. len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
  1617. } else
  1618. len += sprintf(p + len, "not supported\n");
  1619. return len;
  1620. }
  1621. static struct ibm_struct thermal_driver_data = {
  1622. .name = "thermal",
  1623. .read = thermal_read,
  1624. };
  1625. /*************************************************************************
  1626. * EC Dump subdriver
  1627. */
  1628. static u8 ecdump_regs[256];
  1629. static int ecdump_read(char *p)
  1630. {
  1631. int len = 0;
  1632. int i, j;
  1633. u8 v;
  1634. len += sprintf(p + len, "EC "
  1635. " +00 +01 +02 +03 +04 +05 +06 +07"
  1636. " +08 +09 +0a +0b +0c +0d +0e +0f\n");
  1637. for (i = 0; i < 256; i += 16) {
  1638. len += sprintf(p + len, "EC 0x%02x:", i);
  1639. for (j = 0; j < 16; j++) {
  1640. if (!acpi_ec_read(i + j, &v))
  1641. break;
  1642. if (v != ecdump_regs[i + j])
  1643. len += sprintf(p + len, " *%02x", v);
  1644. else
  1645. len += sprintf(p + len, " %02x", v);
  1646. ecdump_regs[i + j] = v;
  1647. }
  1648. len += sprintf(p + len, "\n");
  1649. if (j != 16)
  1650. break;
  1651. }
  1652. /* These are way too dangerous to advertise openly... */
  1653. #if 0
  1654. len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
  1655. " (<offset> is 00-ff, <value> is 00-ff)\n");
  1656. len += sprintf(p + len, "commands:\t0x<offset> <value> "
  1657. " (<offset> is 00-ff, <value> is 0-255)\n");
  1658. #endif
  1659. return len;
  1660. }
  1661. static int ecdump_write(char *buf)
  1662. {
  1663. char *cmd;
  1664. int i, v;
  1665. while ((cmd = next_cmd(&buf))) {
  1666. if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
  1667. /* i and v set */
  1668. } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
  1669. /* i and v set */
  1670. } else
  1671. return -EINVAL;
  1672. if (i >= 0 && i < 256 && v >= 0 && v < 256) {
  1673. if (!acpi_ec_write(i, v))
  1674. return -EIO;
  1675. } else
  1676. return -EINVAL;
  1677. }
  1678. return 0;
  1679. }
  1680. static struct ibm_struct ecdump_driver_data = {
  1681. .name = "ecdump",
  1682. .read = ecdump_read,
  1683. .write = ecdump_write,
  1684. .flags.experimental = 1,
  1685. };
  1686. /*************************************************************************
  1687. * Backlight/brightness subdriver
  1688. */
  1689. static struct backlight_device *ibm_backlight_device = NULL;
  1690. static struct backlight_ops ibm_backlight_data = {
  1691. .get_brightness = brightness_get,
  1692. .update_status = brightness_update_status,
  1693. };
  1694. static int __init brightness_init(struct ibm_init_struct *iibm)
  1695. {
  1696. int b;
  1697. vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
  1698. b = brightness_get(NULL);
  1699. if (b < 0)
  1700. return b;
  1701. ibm_backlight_device = backlight_device_register("ibm", NULL, NULL,
  1702. &ibm_backlight_data);
  1703. if (IS_ERR(ibm_backlight_device)) {
  1704. printk(IBM_ERR "Could not register backlight device\n");
  1705. return PTR_ERR(ibm_backlight_device);
  1706. }
  1707. vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
  1708. ibm_backlight_device->props.max_brightness = 7;
  1709. ibm_backlight_device->props.brightness = b;
  1710. backlight_update_status(ibm_backlight_device);
  1711. return 0;
  1712. }
  1713. static void brightness_exit(void)
  1714. {
  1715. if (ibm_backlight_device) {
  1716. vdbg_printk(TPACPI_DBG_EXIT,
  1717. "calling backlight_device_unregister()\n");
  1718. backlight_device_unregister(ibm_backlight_device);
  1719. ibm_backlight_device = NULL;
  1720. }
  1721. }
  1722. static int brightness_update_status(struct backlight_device *bd)
  1723. {
  1724. return brightness_set(
  1725. (bd->props.fb_blank == FB_BLANK_UNBLANK &&
  1726. bd->props.power == FB_BLANK_UNBLANK) ?
  1727. bd->props.brightness : 0);
  1728. }
  1729. static int brightness_get(struct backlight_device *bd)
  1730. {
  1731. u8 level;
  1732. if (!acpi_ec_read(brightness_offset, &level))
  1733. return -EIO;
  1734. level &= 0x7;
  1735. return level;
  1736. }
  1737. static int brightness_set(int value)
  1738. {
  1739. int cmos_cmd, inc, i;
  1740. int current_value = brightness_get(NULL);
  1741. value &= 7;
  1742. cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN;
  1743. inc = value > current_value ? 1 : -1;
  1744. for (i = current_value; i != value; i += inc) {
  1745. if (issue_thinkpad_cmos_command(cmos_cmd))
  1746. return -EIO;
  1747. if (!acpi_ec_write(brightness_offset, i + inc))
  1748. return -EIO;
  1749. }
  1750. return 0;
  1751. }
  1752. static int brightness_read(char *p)
  1753. {
  1754. int len = 0;
  1755. int level;
  1756. if ((level = brightness_get(NULL)) < 0) {
  1757. len += sprintf(p + len, "level:\t\tunreadable\n");
  1758. } else {
  1759. len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
  1760. len += sprintf(p + len, "commands:\tup, down\n");
  1761. len += sprintf(p + len, "commands:\tlevel <level>"
  1762. " (<level> is 0-7)\n");
  1763. }
  1764. return len;
  1765. }
  1766. static int brightness_write(char *buf)
  1767. {
  1768. int level;
  1769. int new_level;
  1770. char *cmd;
  1771. while ((cmd = next_cmd(&buf))) {
  1772. if ((level = brightness_get(NULL)) < 0)
  1773. return level;
  1774. level &= 7;
  1775. if (strlencmp(cmd, "up") == 0) {
  1776. new_level = level == 7 ? 7 : level + 1;
  1777. } else if (strlencmp(cmd, "down") == 0) {
  1778. new_level = level == 0 ? 0 : level - 1;
  1779. } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
  1780. new_level >= 0 && new_level <= 7) {
  1781. /* new_level set */
  1782. } else
  1783. return -EINVAL;
  1784. brightness_set(new_level);
  1785. }
  1786. return 0;
  1787. }
  1788. static struct ibm_struct brightness_driver_data = {
  1789. .name = "brightness",
  1790. .read = brightness_read,
  1791. .write = brightness_write,
  1792. .exit = brightness_exit,
  1793. };
  1794. /*************************************************************************
  1795. * Volume subdriver
  1796. */
  1797. static int volume_read(char *p)
  1798. {
  1799. int len = 0;
  1800. u8 level;
  1801. if (!acpi_ec_read(volume_offset, &level)) {
  1802. len += sprintf(p + len, "level:\t\tunreadable\n");
  1803. } else {
  1804. len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
  1805. len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
  1806. len += sprintf(p + len, "commands:\tup, down, mute\n");
  1807. len += sprintf(p + len, "commands:\tlevel <level>"
  1808. " (<level> is 0-15)\n");
  1809. }
  1810. return len;
  1811. }
  1812. static int volume_write(char *buf)
  1813. {
  1814. int cmos_cmd, inc, i;
  1815. u8 level, mute;
  1816. int new_level, new_mute;
  1817. char *cmd;
  1818. while ((cmd = next_cmd(&buf))) {
  1819. if (!acpi_ec_read(volume_offset, &level))
  1820. return -EIO;
  1821. new_mute = mute = level & 0x40;
  1822. new_level = level = level & 0xf;
  1823. if (strlencmp(cmd, "up") == 0) {
  1824. if (mute)
  1825. new_mute = 0;
  1826. else
  1827. new_level = level == 15 ? 15 : level + 1;
  1828. } else if (strlencmp(cmd, "down") == 0) {
  1829. if (mute)
  1830. new_mute = 0;
  1831. else
  1832. new_level = level == 0 ? 0 : level - 1;
  1833. } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
  1834. new_level >= 0 && new_level <= 15) {
  1835. /* new_level set */
  1836. } else if (strlencmp(cmd, "mute") == 0) {
  1837. new_mute = 0x40;
  1838. } else
  1839. return -EINVAL;
  1840. if (new_level != level) { /* mute doesn't change */
  1841. cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
  1842. inc = new_level > level ? 1 : -1;
  1843. if (mute && (issue_thinkpad_cmos_command(cmos_cmd) ||
  1844. !acpi_ec_write(volume_offset, level)))
  1845. return -EIO;
  1846. for (i = level; i != new_level; i += inc)
  1847. if (issue_thinkpad_cmos_command(cmos_cmd) ||
  1848. !acpi_ec_write(volume_offset, i + inc))
  1849. return -EIO;
  1850. if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) ||
  1851. !acpi_ec_write(volume_offset,
  1852. new_level + mute)))
  1853. return -EIO;
  1854. }
  1855. if (new_mute != mute) { /* level doesn't change */
  1856. cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
  1857. if (issue_thinkpad_cmos_command(cmos_cmd) ||
  1858. !acpi_ec_write(volume_offset, level + new_mute))
  1859. return -EIO;
  1860. }
  1861. }
  1862. return 0;
  1863. }
  1864. static struct ibm_struct volume_driver_data = {
  1865. .name = "volume",
  1866. .read = volume_read,
  1867. .write = volume_write,
  1868. };
  1869. /*************************************************************************
  1870. * Fan subdriver
  1871. */
  1872. /*
  1873. * FAN ACCESS MODES
  1874. *
  1875. * TPACPI_FAN_RD_ACPI_GFAN:
  1876. * ACPI GFAN method: returns fan level
  1877. *
  1878. * see TPACPI_FAN_WR_ACPI_SFAN
  1879. * EC 0x2f (HFSP) not available if GFAN exists
  1880. *
  1881. * TPACPI_FAN_WR_ACPI_SFAN:
  1882. * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
  1883. *
  1884. * EC 0x2f (HFSP) might be available *for reading*, but do not use
  1885. * it for writing.
  1886. *
  1887. * TPACPI_FAN_WR_TPEC:
  1888. * ThinkPad EC register 0x2f (HFSP): fan control loop mode
  1889. * Supported on almost all ThinkPads
  1890. *
  1891. * Fan speed changes of any sort (including those caused by the
  1892. * disengaged mode) are usually done slowly by the firmware as the
  1893. * maximum ammount of fan duty cycle change per second seems to be
  1894. * limited.
  1895. *
  1896. * Reading is not available if GFAN exists.
  1897. * Writing is not available if SFAN exists.
  1898. *
  1899. * Bits
  1900. * 7 automatic mode engaged;
  1901. * (default operation mode of the ThinkPad)
  1902. * fan level is ignored in this mode.
  1903. * 6 full speed mode (takes precedence over bit 7);
  1904. * not available on all thinkpads. May disable
  1905. * the tachometer while the fan controller ramps up
  1906. * the speed (which can take up to a few *minutes*).
  1907. * Speeds up fan to 100% duty-cycle, which is far above
  1908. * the standard RPM levels. It is not impossible that
  1909. * it could cause hardware damage.
  1910. * 5-3 unused in some models. Extra bits for fan level
  1911. * in others, but still useless as all values above
  1912. * 7 map to the same speed as level 7 in these models.
  1913. * 2-0 fan level (0..7 usually)
  1914. * 0x00 = stop
  1915. * 0x07 = max (set when temperatures critical)
  1916. * Some ThinkPads may have other levels, see
  1917. * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
  1918. *
  1919. * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
  1920. * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
  1921. * does so, its initial value is meaningless (0x07).
  1922. *
  1923. * For firmware bugs, refer to:
  1924. * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
  1925. *
  1926. * ----
  1927. *
  1928. * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
  1929. * Main fan tachometer reading (in RPM)
  1930. *
  1931. * This register is present on all ThinkPads with a new-style EC, and
  1932. * it is known not to be present on the A21m/e, and T22, as there is
  1933. * something else in offset 0x84 according to the ACPI DSDT. Other
  1934. * ThinkPads from this same time period (and earlier) probably lack the
  1935. * tachometer as well.
  1936. *
  1937. * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
  1938. * was never fixed by IBM to report the EC firmware version string
  1939. * probably support the tachometer (like the early X models), so
  1940. * detecting it is quite hard. We need more data to know for sure.
  1941. *
  1942. * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
  1943. * might result.
  1944. *
  1945. * FIRMWARE BUG: may go stale while the EC is switching to full speed
  1946. * mode.
  1947. *
  1948. * For firmware bugs, refer to:
  1949. * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
  1950. *
  1951. * TPACPI_FAN_WR_ACPI_FANS:
  1952. * ThinkPad X31, X40, X41. Not available in the X60.
  1953. *
  1954. * FANS ACPI handle: takes three arguments: low speed, medium speed,
  1955. * high speed. ACPI DSDT seems to map these three speeds to levels
  1956. * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
  1957. * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
  1958. *
  1959. * The speeds are stored on handles
  1960. * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
  1961. *
  1962. * There are three default speed sets, acessible as handles:
  1963. * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
  1964. *
  1965. * ACPI DSDT switches which set is in use depending on various
  1966. * factors.
  1967. *
  1968. * TPACPI_FAN_WR_TPEC is also available and should be used to
  1969. * command the fan. The X31/X40/X41 seems to have 8 fan levels,
  1970. * but the ACPI tables just mention level 7.
  1971. */
  1972. static enum fan_status_access_mode fan_status_access_mode;
  1973. static enum fan_control_access_mode fan_control_access_mode;
  1974. static enum fan_control_commands fan_control_commands;
  1975. static u8 fan_control_initial_status;
  1976. static void fan_watchdog_fire(struct work_struct *ignored);
  1977. static int fan_watchdog_maxinterval;
  1978. static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
  1979. IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
  1980. IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
  1981. "\\FSPD", /* 600e/x, 770e, 770x */
  1982. ); /* all others */
  1983. IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
  1984. "JFNS", /* 770x-JL */
  1985. ); /* all others */
  1986. static int __init fan_init(struct ibm_init_struct *iibm)
  1987. {
  1988. vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
  1989. fan_status_access_mode = TPACPI_FAN_NONE;
  1990. fan_control_access_mode = TPACPI_FAN_WR_NONE;
  1991. fan_control_commands = 0;
  1992. fan_watchdog_maxinterval = 0;
  1993. tp_features.fan_ctrl_status_undef = 0;
  1994. IBM_ACPIHANDLE_INIT(fans);
  1995. IBM_ACPIHANDLE_INIT(gfan);
  1996. IBM_ACPIHANDLE_INIT(sfan);
  1997. if (gfan_handle) {
  1998. /* 570, 600e/x, 770e, 770x */
  1999. fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
  2000. } else {
  2001. /* all other ThinkPads: note that even old-style
  2002. * ThinkPad ECs supports the fan control register */
  2003. if (likely(acpi_ec_read(fan_status_offset,
  2004. &fan_control_initial_status))) {
  2005. fan_status_access_mode = TPACPI_FAN_RD_TPEC;
  2006. /* In some ThinkPads, neither the EC nor the ACPI
  2007. * DSDT initialize the fan status, and it ends up
  2008. * being set to 0x07 when it *could* be either
  2009. * 0x07 or 0x80.
  2010. *
  2011. * Enable for TP-1Y (T43), TP-78 (R51e),
  2012. * TP-76 (R52), TP-70 (T43, R52), which are known
  2013. * to be buggy. */
  2014. if (fan_control_initial_status == 0x07 &&
  2015. ibm_thinkpad_ec_found &&
  2016. ((ibm_thinkpad_ec_found[0] == '1' &&
  2017. ibm_thinkpad_ec_found[1] == 'Y') ||
  2018. (ibm_thinkpad_ec_found[0] == '7' &&
  2019. (ibm_thinkpad_ec_found[1] == '6' ||
  2020. ibm_thinkpad_ec_found[1] == '8' ||
  2021. ibm_thinkpad_ec_found[1] == '0'))
  2022. )) {
  2023. printk(IBM_NOTICE
  2024. "fan_init: initial fan status is "
  2025. "unknown, assuming it is in auto "
  2026. "mode\n");
  2027. tp_features.fan_ctrl_status_undef = 1;
  2028. }
  2029. } else {
  2030. printk(IBM_ERR
  2031. "ThinkPad ACPI EC access misbehaving, "
  2032. "fan status and control unavailable\n");
  2033. return 1;
  2034. }
  2035. }
  2036. if (sfan_handle) {
  2037. /* 570, 770x-JL */
  2038. fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
  2039. fan_control_commands |=
  2040. TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
  2041. } else {
  2042. if (!gfan_handle) {
  2043. /* gfan without sfan means no fan control */
  2044. /* all other models implement TP EC 0x2f control */
  2045. if (fans_handle) {
  2046. /* X31, X40, X41 */
  2047. fan_control_access_mode =
  2048. TPACPI_FAN_WR_ACPI_FANS;
  2049. fan_control_commands |=
  2050. TPACPI_FAN_CMD_SPEED |
  2051. TPACPI_FAN_CMD_LEVEL |
  2052. TPACPI_FAN_CMD_ENABLE;
  2053. } else {
  2054. fan_control_access_mode = TPACPI_FAN_WR_TPEC;
  2055. fan_control_commands |=
  2056. TPACPI_FAN_CMD_LEVEL |
  2057. TPACPI_FAN_CMD_ENABLE;
  2058. }
  2059. }
  2060. }
  2061. vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n",
  2062. str_supported(fan_status_access_mode != TPACPI_FAN_NONE ||
  2063. fan_control_access_mode != TPACPI_FAN_WR_NONE),
  2064. fan_status_access_mode, fan_control_access_mode);
  2065. return (fan_status_access_mode != TPACPI_FAN_NONE ||
  2066. fan_control_access_mode != TPACPI_FAN_WR_NONE)?
  2067. 0 : 1;
  2068. }
  2069. static int fan_get_status(u8 *status)
  2070. {
  2071. u8 s;
  2072. /* TODO:
  2073. * Add TPACPI_FAN_RD_ACPI_FANS ? */
  2074. switch (fan_status_access_mode) {
  2075. case TPACPI_FAN_RD_ACPI_GFAN:
  2076. /* 570, 600e/x, 770e, 770x */
  2077. if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
  2078. return -EIO;
  2079. if (likely(status))
  2080. *status = s & 0x07;
  2081. break;
  2082. case TPACPI_FAN_RD_TPEC:
  2083. /* all except 570, 600e/x, 770e, 770x */
  2084. if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
  2085. return -EIO;
  2086. if (likely(status))
  2087. *status = s;
  2088. break;
  2089. default:
  2090. return -ENXIO;
  2091. }
  2092. return 0;
  2093. }
  2094. static void fan_exit(void)
  2095. {
  2096. vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending watchdogs\n");
  2097. cancel_delayed_work(&fan_watchdog_task);
  2098. flush_scheduled_work();
  2099. }
  2100. static int fan_get_speed(unsigned int *speed)
  2101. {
  2102. u8 hi, lo;
  2103. switch (fan_status_access_mode) {
  2104. case TPACPI_FAN_RD_TPEC:
  2105. /* all except 570, 600e/x, 770e, 770x */
  2106. if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
  2107. !acpi_ec_read(fan_rpm_offset + 1, &hi)))
  2108. return -EIO;
  2109. if (likely(speed))
  2110. *speed = (hi << 8) | lo;
  2111. break;
  2112. default:
  2113. return -ENXIO;
  2114. }
  2115. return 0;
  2116. }
  2117. static void fan_watchdog_fire(struct work_struct *ignored)
  2118. {
  2119. printk(IBM_NOTICE "fan watchdog: enabling fan\n");
  2120. if (fan_set_enable()) {
  2121. printk(IBM_ERR "fan watchdog: error while enabling fan\n");
  2122. /* reschedule for later */
  2123. fan_watchdog_reset();
  2124. }
  2125. }
  2126. static void fan_watchdog_reset(void)
  2127. {
  2128. static int fan_watchdog_active = 0;
  2129. if (fan_watchdog_active)
  2130. cancel_delayed_work(&fan_watchdog_task);
  2131. if (fan_watchdog_maxinterval > 0) {
  2132. fan_watchdog_active = 1;
  2133. if (!schedule_delayed_work(&fan_watchdog_task,
  2134. msecs_to_jiffies(fan_watchdog_maxinterval
  2135. * 1000))) {
  2136. printk(IBM_ERR "failed to schedule the fan watchdog, "
  2137. "watchdog will not trigger\n");
  2138. }
  2139. } else
  2140. fan_watchdog_active = 0;
  2141. }
  2142. static int fan_set_level(int level)
  2143. {
  2144. switch (fan_control_access_mode) {
  2145. case TPACPI_FAN_WR_ACPI_SFAN:
  2146. if (level >= 0 && level <= 7) {
  2147. if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
  2148. return -EIO;
  2149. } else
  2150. return -EINVAL;
  2151. break;
  2152. case TPACPI_FAN_WR_ACPI_FANS:
  2153. case TPACPI_FAN_WR_TPEC:
  2154. if ((level != TP_EC_FAN_AUTO) &&
  2155. (level != TP_EC_FAN_FULLSPEED) &&
  2156. ((level < 0) || (level > 7)))
  2157. return -EINVAL;
  2158. if (!acpi_ec_write(fan_status_offset, level))
  2159. return -EIO;
  2160. else
  2161. tp_features.fan_ctrl_status_undef = 0;
  2162. break;
  2163. default:
  2164. return -ENXIO;
  2165. }
  2166. return 0;
  2167. }
  2168. static int fan_set_enable(void)
  2169. {
  2170. u8 s;
  2171. int rc;
  2172. switch (fan_control_access_mode) {
  2173. case TPACPI_FAN_WR_ACPI_FANS:
  2174. case TPACPI_FAN_WR_TPEC:
  2175. if ((rc = fan_get_status(&s)) < 0)
  2176. return rc;
  2177. /* Don't go out of emergency fan mode */
  2178. if (s != 7)
  2179. s = TP_EC_FAN_AUTO;
  2180. if (!acpi_ec_write(fan_status_offset, s))
  2181. return -EIO;
  2182. else
  2183. tp_features.fan_ctrl_status_undef = 0;
  2184. break;
  2185. case TPACPI_FAN_WR_ACPI_SFAN:
  2186. if ((rc = fan_get_status(&s)) < 0)
  2187. return rc;
  2188. s &= 0x07;
  2189. /* Set fan to at least level 4 */
  2190. if (s < 4)
  2191. s = 4;
  2192. if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
  2193. return -EIO;
  2194. break;
  2195. default:
  2196. return -ENXIO;
  2197. }
  2198. return 0;
  2199. }
  2200. static int fan_set_disable(void)
  2201. {
  2202. switch (fan_control_access_mode) {
  2203. case TPACPI_FAN_WR_ACPI_FANS:
  2204. case TPACPI_FAN_WR_TPEC:
  2205. if (!acpi_ec_write(fan_status_offset, 0x00))
  2206. return -EIO;
  2207. else
  2208. tp_features.fan_ctrl_status_undef = 0;
  2209. break;
  2210. case TPACPI_FAN_WR_ACPI_SFAN:
  2211. if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
  2212. return -EIO;
  2213. break;
  2214. default:
  2215. return -ENXIO;
  2216. }
  2217. return 0;
  2218. }
  2219. static int fan_set_speed(int speed)
  2220. {
  2221. switch (fan_control_access_mode) {
  2222. case TPACPI_FAN_WR_ACPI_FANS:
  2223. if (speed >= 0 && speed <= 65535) {
  2224. if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
  2225. speed, speed, speed))
  2226. return -EIO;
  2227. } else
  2228. return -EINVAL;
  2229. break;
  2230. default:
  2231. return -ENXIO;
  2232. }
  2233. return 0;
  2234. }
  2235. static int fan_read(char *p)
  2236. {
  2237. int len = 0;
  2238. int rc;
  2239. u8 status;
  2240. unsigned int speed = 0;
  2241. switch (fan_status_access_mode) {
  2242. case TPACPI_FAN_RD_ACPI_GFAN:
  2243. /* 570, 600e/x, 770e, 770x */
  2244. if ((rc = fan_get_status(&status)) < 0)
  2245. return rc;
  2246. len += sprintf(p + len, "status:\t\t%s\n"
  2247. "level:\t\t%d\n",
  2248. (status != 0) ? "enabled" : "disabled", status);
  2249. break;
  2250. case TPACPI_FAN_RD_TPEC:
  2251. /* all except 570, 600e/x, 770e, 770x */
  2252. if ((rc = fan_get_status(&status)) < 0)
  2253. return rc;
  2254. if (unlikely(tp_features.fan_ctrl_status_undef)) {
  2255. if (status != fan_control_initial_status)
  2256. tp_features.fan_ctrl_status_undef = 0;
  2257. else
  2258. /* Return most likely status. In fact, it
  2259. * might be the only possible status */
  2260. status = TP_EC_FAN_AUTO;
  2261. }
  2262. len += sprintf(p + len, "status:\t\t%s\n",
  2263. (status != 0) ? "enabled" : "disabled");
  2264. if ((rc = fan_get_speed(&speed)) < 0)
  2265. return rc;
  2266. len += sprintf(p + len, "speed:\t\t%d\n", speed);
  2267. if (status & TP_EC_FAN_FULLSPEED)
  2268. /* Disengaged mode takes precedence */
  2269. len += sprintf(p + len, "level:\t\tdisengaged\n");
  2270. else if (status & TP_EC_FAN_AUTO)
  2271. len += sprintf(p + len, "level:\t\tauto\n");
  2272. else
  2273. len += sprintf(p + len, "level:\t\t%d\n", status);
  2274. break;
  2275. case TPACPI_FAN_NONE:
  2276. default:
  2277. len += sprintf(p + len, "status:\t\tnot supported\n");
  2278. }
  2279. if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
  2280. len += sprintf(p + len, "commands:\tlevel <level>");
  2281. switch (fan_control_access_mode) {
  2282. case TPACPI_FAN_WR_ACPI_SFAN:
  2283. len += sprintf(p + len, " (<level> is 0-7)\n");
  2284. break;
  2285. default:
  2286. len += sprintf(p + len, " (<level> is 0-7, "
  2287. "auto, disengaged)\n");
  2288. break;
  2289. }
  2290. }
  2291. if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
  2292. len += sprintf(p + len, "commands:\tenable, disable\n"
  2293. "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
  2294. "1-120 (seconds))\n");
  2295. if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
  2296. len += sprintf(p + len, "commands:\tspeed <speed>"
  2297. " (<speed> is 0-65535)\n");
  2298. return len;
  2299. }
  2300. static int fan_write_cmd_level(const char *cmd, int *rc)
  2301. {
  2302. int level;
  2303. if (strlencmp(cmd, "level auto") == 0)
  2304. level = TP_EC_FAN_AUTO;
  2305. else if (strlencmp(cmd, "level disengaged") == 0)
  2306. level = TP_EC_FAN_FULLSPEED;
  2307. else if (sscanf(cmd, "level %d", &level) != 1)
  2308. return 0;
  2309. if ((*rc = fan_set_level(level)) == -ENXIO)
  2310. printk(IBM_ERR "level command accepted for unsupported "
  2311. "access mode %d", fan_control_access_mode);
  2312. return 1;
  2313. }
  2314. static int fan_write_cmd_enable(const char *cmd, int *rc)
  2315. {
  2316. if (strlencmp(cmd, "enable") != 0)
  2317. return 0;
  2318. if ((*rc = fan_set_enable()) == -ENXIO)
  2319. printk(IBM_ERR "enable command accepted for unsupported "
  2320. "access mode %d", fan_control_access_mode);
  2321. return 1;
  2322. }
  2323. static int fan_write_cmd_disable(const char *cmd, int *rc)
  2324. {
  2325. if (strlencmp(cmd, "disable") != 0)
  2326. return 0;
  2327. if ((*rc = fan_set_disable()) == -ENXIO)
  2328. printk(IBM_ERR "disable command accepted for unsupported "
  2329. "access mode %d", fan_control_access_mode);
  2330. return 1;
  2331. }
  2332. static int fan_write_cmd_speed(const char *cmd, int *rc)
  2333. {
  2334. int speed;
  2335. /* TODO:
  2336. * Support speed <low> <medium> <high> ? */
  2337. if (sscanf(cmd, "speed %d", &speed) != 1)
  2338. return 0;
  2339. if ((*rc = fan_set_speed(speed)) == -ENXIO)
  2340. printk(IBM_ERR "speed command accepted for unsupported "
  2341. "access mode %d", fan_control_access_mode);
  2342. return 1;
  2343. }
  2344. static int fan_write_cmd_watchdog(const char *cmd, int *rc)
  2345. {
  2346. int interval;
  2347. if (sscanf(cmd, "watchdog %d", &interval) != 1)
  2348. return 0;
  2349. if (interval < 0 || interval > 120)
  2350. *rc = -EINVAL;
  2351. else
  2352. fan_watchdog_maxinterval = interval;
  2353. return 1;
  2354. }
  2355. static int fan_write(char *buf)
  2356. {
  2357. char *cmd;
  2358. int rc = 0;
  2359. while (!rc && (cmd = next_cmd(&buf))) {
  2360. if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
  2361. fan_write_cmd_level(cmd, &rc)) &&
  2362. !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
  2363. (fan_write_cmd_enable(cmd, &rc) ||
  2364. fan_write_cmd_disable(cmd, &rc) ||
  2365. fan_write_cmd_watchdog(cmd, &rc))) &&
  2366. !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
  2367. fan_write_cmd_speed(cmd, &rc))
  2368. )
  2369. rc = -EINVAL;
  2370. else if (!rc)
  2371. fan_watchdog_reset();
  2372. }
  2373. return rc;
  2374. }
  2375. static struct ibm_struct fan_driver_data = {
  2376. .name = "fan",
  2377. .read = fan_read,
  2378. .write = fan_write,
  2379. .exit = fan_exit,
  2380. .flags.experimental = 1,
  2381. };
  2382. /****************************************************************************
  2383. ****************************************************************************
  2384. *
  2385. * Infrastructure
  2386. *
  2387. ****************************************************************************
  2388. ****************************************************************************/
  2389. /* /proc support */
  2390. static struct proc_dir_entry *proc_dir = NULL;
  2391. /* Subdriver registry */
  2392. static LIST_HEAD(tpacpi_all_drivers);
  2393. /*
  2394. * Module and infrastructure proble, init and exit handling
  2395. */
  2396. #ifdef CONFIG_THINKPAD_ACPI_DEBUG
  2397. static const char * __init str_supported(int is_supported)
  2398. {
  2399. static char text_unsupported[] __initdata = "not supported";
  2400. return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
  2401. }
  2402. #endif /* CONFIG_THINKPAD_ACPI_DEBUG */
  2403. static int __init ibm_init(struct ibm_init_struct *iibm)
  2404. {
  2405. int ret;
  2406. struct ibm_struct *ibm = iibm->data;
  2407. struct proc_dir_entry *entry;
  2408. BUG_ON(ibm == NULL);
  2409. INIT_LIST_HEAD(&ibm->all_drivers);
  2410. if (ibm->flags.experimental && !experimental)
  2411. return 0;
  2412. dbg_printk(TPACPI_DBG_INIT,
  2413. "probing for %s\n", ibm->name);
  2414. if (iibm->init) {
  2415. ret = iibm->init(iibm);
  2416. if (ret > 0)
  2417. return 0; /* probe failed */
  2418. if (ret)
  2419. return ret;
  2420. ibm->flags.init_called = 1;
  2421. }
  2422. if (ibm->acpi) {
  2423. if (ibm->acpi->hid) {
  2424. ret = register_tpacpi_subdriver(ibm);
  2425. if (ret)
  2426. goto err_out;
  2427. }
  2428. if (ibm->acpi->notify) {
  2429. ret = setup_acpi_notify(ibm);
  2430. if (ret == -ENODEV) {
  2431. printk(IBM_NOTICE "disabling subdriver %s\n",
  2432. ibm->name);
  2433. ret = 0;
  2434. goto err_out;
  2435. }
  2436. if (ret < 0)
  2437. goto err_out;
  2438. }
  2439. }
  2440. dbg_printk(TPACPI_DBG_INIT,
  2441. "%s installed\n", ibm->name);
  2442. if (ibm->read) {
  2443. entry = create_proc_entry(ibm->name,
  2444. S_IFREG | S_IRUGO | S_IWUSR,
  2445. proc_dir);
  2446. if (!entry) {
  2447. printk(IBM_ERR "unable to create proc entry %s\n",
  2448. ibm->name);
  2449. ret = -ENODEV;
  2450. goto err_out;
  2451. }
  2452. entry->owner = THIS_MODULE;
  2453. entry->data = ibm;
  2454. entry->read_proc = &dispatch_procfs_read;
  2455. if (ibm->write)
  2456. entry->write_proc = &dispatch_procfs_write;
  2457. ibm->flags.proc_created = 1;
  2458. }
  2459. list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
  2460. return 0;
  2461. err_out:
  2462. dbg_printk(TPACPI_DBG_INIT,
  2463. "%s: at error exit path with result %d\n",
  2464. ibm->name, ret);
  2465. ibm_exit(ibm);
  2466. return (ret < 0)? ret : 0;
  2467. }
  2468. static void ibm_exit(struct ibm_struct *ibm)
  2469. {
  2470. dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
  2471. list_del_init(&ibm->all_drivers);
  2472. if (ibm->flags.acpi_notify_installed) {
  2473. dbg_printk(TPACPI_DBG_EXIT,
  2474. "%s: acpi_remove_notify_handler\n", ibm->name);
  2475. BUG_ON(!ibm->acpi);
  2476. acpi_remove_notify_handler(*ibm->acpi->handle,
  2477. ibm->acpi->type,
  2478. dispatch_acpi_notify);
  2479. ibm->flags.acpi_notify_installed = 0;
  2480. ibm->flags.acpi_notify_installed = 0;
  2481. }
  2482. if (ibm->flags.proc_created) {
  2483. dbg_printk(TPACPI_DBG_EXIT,
  2484. "%s: remove_proc_entry\n", ibm->name);
  2485. remove_proc_entry(ibm->name, proc_dir);
  2486. ibm->flags.proc_created = 0;
  2487. }
  2488. if (ibm->flags.acpi_driver_registered) {
  2489. dbg_printk(TPACPI_DBG_EXIT,
  2490. "%s: acpi_bus_unregister_driver\n", ibm->name);
  2491. BUG_ON(!ibm->acpi);
  2492. acpi_bus_unregister_driver(ibm->acpi->driver);
  2493. kfree(ibm->acpi->driver);
  2494. ibm->acpi->driver = NULL;
  2495. ibm->flags.acpi_driver_registered = 0;
  2496. }
  2497. if (ibm->flags.init_called && ibm->exit) {
  2498. ibm->exit();
  2499. ibm->flags.init_called = 0;
  2500. }
  2501. dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
  2502. }
  2503. /* Probing */
  2504. static char *ibm_thinkpad_ec_found = NULL;
  2505. static char* __init check_dmi_for_ec(void)
  2506. {
  2507. struct dmi_device *dev = NULL;
  2508. char ec_fw_string[18];
  2509. /*
  2510. * ThinkPad T23 or newer, A31 or newer, R50e or newer,
  2511. * X32 or newer, all Z series; Some models must have an
  2512. * up-to-date BIOS or they will not be detected.
  2513. *
  2514. * See http://thinkwiki.org/wiki/List_of_DMI_IDs
  2515. */
  2516. while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
  2517. if (sscanf(dev->name,
  2518. "IBM ThinkPad Embedded Controller -[%17c",
  2519. ec_fw_string) == 1) {
  2520. ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
  2521. ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
  2522. return kstrdup(ec_fw_string, GFP_KERNEL);
  2523. }
  2524. }
  2525. return NULL;
  2526. }
  2527. static int __init probe_for_thinkpad(void)
  2528. {
  2529. int is_thinkpad;
  2530. if (acpi_disabled)
  2531. return -ENODEV;
  2532. /*
  2533. * Non-ancient models have better DMI tagging, but very old models
  2534. * don't.
  2535. */
  2536. is_thinkpad = dmi_name_in_vendors("ThinkPad");
  2537. /* ec is required because many other handles are relative to it */
  2538. IBM_ACPIHANDLE_INIT(ec);
  2539. if (!ec_handle) {
  2540. if (is_thinkpad)
  2541. printk(IBM_ERR
  2542. "Not yet supported ThinkPad detected!\n");
  2543. return -ENODEV;
  2544. }
  2545. /*
  2546. * Risks a regression on very old machines, but reduces potential
  2547. * false positives a damn great deal
  2548. */
  2549. if (!is_thinkpad)
  2550. is_thinkpad = dmi_name_in_vendors("IBM");
  2551. if (!is_thinkpad && !force_load)
  2552. return -ENODEV;
  2553. return 0;
  2554. }
  2555. /* Module init, exit, parameters */
  2556. static struct ibm_init_struct ibms_init[] __initdata = {
  2557. {
  2558. .init = thinkpad_acpi_driver_init,
  2559. .data = &thinkpad_acpi_driver_data,
  2560. },
  2561. {
  2562. .init = hotkey_init,
  2563. .data = &hotkey_driver_data,
  2564. },
  2565. {
  2566. .init = bluetooth_init,
  2567. .data = &bluetooth_driver_data,
  2568. },
  2569. {
  2570. .init = wan_init,
  2571. .data = &wan_driver_data,
  2572. },
  2573. {
  2574. .init = video_init,
  2575. .data = &video_driver_data,
  2576. },
  2577. {
  2578. .init = light_init,
  2579. .data = &light_driver_data,
  2580. },
  2581. #ifdef CONFIG_THINKPAD_ACPI_DOCK
  2582. {
  2583. .init = dock_init,
  2584. .data = &dock_driver_data[0],
  2585. },
  2586. {
  2587. .data = &dock_driver_data[1],
  2588. },
  2589. #endif
  2590. #ifdef CONFIG_THINKPAD_ACPI_BAY
  2591. {
  2592. .init = bay_init,
  2593. .data = &bay_driver_data,
  2594. },
  2595. #endif
  2596. {
  2597. .init = cmos_init,
  2598. .data = &cmos_driver_data,
  2599. },
  2600. {
  2601. .init = led_init,
  2602. .data = &led_driver_data,
  2603. },
  2604. {
  2605. .init = beep_init,
  2606. .data = &beep_driver_data,
  2607. },
  2608. {
  2609. .init = thermal_init,
  2610. .data = &thermal_driver_data,
  2611. },
  2612. {
  2613. .data = &ecdump_driver_data,
  2614. },
  2615. {
  2616. .init = brightness_init,
  2617. .data = &brightness_driver_data,
  2618. },
  2619. {
  2620. .data = &volume_driver_data,
  2621. },
  2622. {
  2623. .init = fan_init,
  2624. .data = &fan_driver_data,
  2625. },
  2626. };
  2627. static int __init set_ibm_param(const char *val, struct kernel_param *kp)
  2628. {
  2629. unsigned int i;
  2630. struct ibm_struct *ibm;
  2631. for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
  2632. ibm = ibms_init[i].data;
  2633. BUG_ON(ibm == NULL);
  2634. if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
  2635. if (strlen(val) > sizeof(ibms_init[i].param) - 2)
  2636. return -ENOSPC;
  2637. strcpy(ibms_init[i].param, val);
  2638. strcat(ibms_init[i].param, ",");
  2639. return 0;
  2640. }
  2641. }
  2642. return -EINVAL;
  2643. }
  2644. static int experimental;
  2645. module_param(experimental, int, 0);
  2646. static u32 dbg_level;
  2647. module_param_named(debug, dbg_level, uint, 0);
  2648. static int force_load;
  2649. module_param(force_load, int, 0);
  2650. #define IBM_PARAM(feature) \
  2651. module_param_call(feature, set_ibm_param, NULL, NULL, 0)
  2652. IBM_PARAM(hotkey);
  2653. IBM_PARAM(bluetooth);
  2654. IBM_PARAM(video);
  2655. IBM_PARAM(light);
  2656. #ifdef CONFIG_THINKPAD_ACPI_DOCK
  2657. IBM_PARAM(dock);
  2658. #endif
  2659. #ifdef CONFIG_THINKPAD_ACPI_BAY
  2660. IBM_PARAM(bay);
  2661. #endif /* CONFIG_THINKPAD_ACPI_BAY */
  2662. IBM_PARAM(cmos);
  2663. IBM_PARAM(led);
  2664. IBM_PARAM(beep);
  2665. IBM_PARAM(ecdump);
  2666. IBM_PARAM(brightness);
  2667. IBM_PARAM(volume);
  2668. IBM_PARAM(fan);
  2669. static int __init thinkpad_acpi_module_init(void)
  2670. {
  2671. int ret, i;
  2672. ret = probe_for_thinkpad();
  2673. if (ret)
  2674. return ret;
  2675. ibm_thinkpad_ec_found = check_dmi_for_ec();
  2676. IBM_ACPIHANDLE_INIT(ecrd);
  2677. IBM_ACPIHANDLE_INIT(ecwr);
  2678. proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir);
  2679. if (!proc_dir) {
  2680. printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR);
  2681. thinkpad_acpi_module_exit();
  2682. return -ENODEV;
  2683. }
  2684. proc_dir->owner = THIS_MODULE;
  2685. for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
  2686. ret = ibm_init(&ibms_init[i]);
  2687. if (ret >= 0 && *ibms_init[i].param)
  2688. ret = ibms_init[i].data->write(ibms_init[i].param);
  2689. if (ret < 0) {
  2690. thinkpad_acpi_module_exit();
  2691. return ret;
  2692. }
  2693. }
  2694. return 0;
  2695. }
  2696. static void thinkpad_acpi_module_exit(void)
  2697. {
  2698. struct ibm_struct *ibm, *itmp;
  2699. list_for_each_entry_safe_reverse(ibm, itmp,
  2700. &tpacpi_all_drivers,
  2701. all_drivers) {
  2702. ibm_exit(ibm);
  2703. }
  2704. dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
  2705. if (proc_dir)
  2706. remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);
  2707. kfree(ibm_thinkpad_ec_found);
  2708. }
  2709. module_init(thinkpad_acpi_module_init);
  2710. module_exit(thinkpad_acpi_module_exit);