toshiba_acpi.c 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363
  1. /*
  2. * toshiba_acpi.c - Toshiba Laptop ACPI Extras
  3. *
  4. * Copyright (C) 2002-2004 John Belmonte
  5. * Copyright (C) 2008 Philip Langdale
  6. * Copyright (C) 2010 Pierre Ducroquet
  7. * Copyright (C) 2014-2016 Azael Avalos
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * The full GNU General Public License is included in this distribution in
  20. * the file called "COPYING".
  21. *
  22. * The devolpment page for this driver is located at
  23. * http://memebeam.org/toys/ToshibaAcpiDriver.
  24. *
  25. * Credits:
  26. * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
  27. * engineering the Windows drivers
  28. * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
  29. * Rob Miller - TV out and hotkeys help
  30. */
  31. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  32. #define TOSHIBA_ACPI_VERSION "0.24"
  33. #define PROC_INTERFACE_VERSION 1
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/moduleparam.h>
  37. #include <linux/init.h>
  38. #include <linux/types.h>
  39. #include <linux/proc_fs.h>
  40. #include <linux/seq_file.h>
  41. #include <linux/backlight.h>
  42. #include <linux/input.h>
  43. #include <linux/input/sparse-keymap.h>
  44. #include <linux/leds.h>
  45. #include <linux/slab.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/i8042.h>
  48. #include <linux/acpi.h>
  49. #include <linux/dmi.h>
  50. #include <linux/uaccess.h>
  51. #include <linux/miscdevice.h>
  52. #include <linux/rfkill.h>
  53. #include <linux/iio/iio.h>
  54. #include <linux/toshiba.h>
  55. #include <acpi/video.h>
  56. MODULE_AUTHOR("John Belmonte");
  57. MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
  58. MODULE_LICENSE("GPL");
  59. #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
  60. /* Scan code for Fn key on TOS1900 models */
  61. #define TOS1900_FN_SCAN 0x6e
  62. /* Toshiba ACPI method paths */
  63. #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
  64. /*
  65. * The Toshiba configuration interface is composed of the HCI and the SCI,
  66. * which are defined as follows:
  67. *
  68. * HCI is Toshiba's "Hardware Control Interface" which is supposed to
  69. * be uniform across all their models. Ideally we would just call
  70. * dedicated ACPI methods instead of using this primitive interface.
  71. * However the ACPI methods seem to be incomplete in some areas (for
  72. * example they allow setting, but not reading, the LCD brightness value),
  73. * so this is still useful.
  74. *
  75. * SCI stands for "System Configuration Interface" which aim is to
  76. * conceal differences in hardware between different models.
  77. */
  78. #define TCI_WORDS 6
  79. /* Operations */
  80. #define HCI_SET 0xff00
  81. #define HCI_GET 0xfe00
  82. #define SCI_OPEN 0xf100
  83. #define SCI_CLOSE 0xf200
  84. #define SCI_GET 0xf300
  85. #define SCI_SET 0xf400
  86. /* Return codes */
  87. #define TOS_SUCCESS 0x0000
  88. #define TOS_SUCCESS2 0x0001
  89. #define TOS_OPEN_CLOSE_OK 0x0044
  90. #define TOS_FAILURE 0x1000
  91. #define TOS_NOT_SUPPORTED 0x8000
  92. #define TOS_ALREADY_OPEN 0x8100
  93. #define TOS_NOT_OPENED 0x8200
  94. #define TOS_INPUT_DATA_ERROR 0x8300
  95. #define TOS_WRITE_PROTECTED 0x8400
  96. #define TOS_NOT_PRESENT 0x8600
  97. #define TOS_FIFO_EMPTY 0x8c00
  98. #define TOS_DATA_NOT_AVAILABLE 0x8d20
  99. #define TOS_NOT_INITIALIZED 0x8d50
  100. #define TOS_NOT_INSTALLED 0x8e00
  101. /* Registers */
  102. #define HCI_FAN 0x0004
  103. #define HCI_TR_BACKLIGHT 0x0005
  104. #define HCI_SYSTEM_EVENT 0x0016
  105. #define HCI_VIDEO_OUT 0x001c
  106. #define HCI_HOTKEY_EVENT 0x001e
  107. #define HCI_LCD_BRIGHTNESS 0x002a
  108. #define HCI_WIRELESS 0x0056
  109. #define HCI_ACCELEROMETER 0x006d
  110. #define HCI_COOLING_METHOD 0x007f
  111. #define HCI_KBD_ILLUMINATION 0x0095
  112. #define HCI_ECO_MODE 0x0097
  113. #define HCI_ACCELEROMETER2 0x00a6
  114. #define HCI_SYSTEM_INFO 0xc000
  115. #define SCI_PANEL_POWER_ON 0x010d
  116. #define SCI_ILLUMINATION 0x014e
  117. #define SCI_USB_SLEEP_CHARGE 0x0150
  118. #define SCI_KBD_ILLUM_STATUS 0x015c
  119. #define SCI_USB_SLEEP_MUSIC 0x015e
  120. #define SCI_USB_THREE 0x0169
  121. #define SCI_TOUCHPAD 0x050e
  122. #define SCI_KBD_FUNCTION_KEYS 0x0522
  123. /* Field definitions */
  124. #define HCI_ACCEL_MASK 0x7fff
  125. #define HCI_ACCEL_DIRECTION_MASK 0x8000
  126. #define HCI_HOTKEY_DISABLE 0x0b
  127. #define HCI_HOTKEY_ENABLE 0x09
  128. #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
  129. #define HCI_LCD_BRIGHTNESS_BITS 3
  130. #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
  131. #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
  132. #define HCI_MISC_SHIFT 0x10
  133. #define HCI_SYSTEM_TYPE1 0x10
  134. #define HCI_SYSTEM_TYPE2 0x11
  135. #define HCI_VIDEO_OUT_LCD 0x1
  136. #define HCI_VIDEO_OUT_CRT 0x2
  137. #define HCI_VIDEO_OUT_TV 0x4
  138. #define SCI_KBD_MODE_MASK 0x1f
  139. #define SCI_KBD_MODE_FNZ 0x1
  140. #define SCI_KBD_MODE_AUTO 0x2
  141. #define SCI_KBD_MODE_ON 0x8
  142. #define SCI_KBD_MODE_OFF 0x10
  143. #define SCI_KBD_TIME_MAX 0x3c001a
  144. #define HCI_WIRELESS_STATUS 0x1
  145. #define HCI_WIRELESS_WWAN 0x3
  146. #define HCI_WIRELESS_WWAN_STATUS 0x2000
  147. #define HCI_WIRELESS_WWAN_POWER 0x4000
  148. #define SCI_USB_CHARGE_MODE_MASK 0xff
  149. #define SCI_USB_CHARGE_DISABLED 0x00
  150. #define SCI_USB_CHARGE_ALTERNATE 0x09
  151. #define SCI_USB_CHARGE_TYPICAL 0x11
  152. #define SCI_USB_CHARGE_AUTO 0x21
  153. #define SCI_USB_CHARGE_BAT_MASK 0x7
  154. #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
  155. #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
  156. #define SCI_USB_CHARGE_BAT_LVL 0x0200
  157. #define SCI_USB_CHARGE_RAPID_DSP 0x0300
  158. struct toshiba_acpi_dev {
  159. struct acpi_device *acpi_dev;
  160. const char *method_hci;
  161. struct input_dev *hotkey_dev;
  162. struct work_struct hotkey_work;
  163. struct backlight_device *backlight_dev;
  164. struct led_classdev led_dev;
  165. struct led_classdev kbd_led;
  166. struct led_classdev eco_led;
  167. struct miscdevice miscdev;
  168. struct rfkill *wwan_rfk;
  169. struct iio_dev *indio_dev;
  170. int force_fan;
  171. int last_key_event;
  172. int key_event_valid;
  173. int kbd_type;
  174. int kbd_mode;
  175. int kbd_time;
  176. int usbsc_bat_level;
  177. int usbsc_mode_base;
  178. int hotkey_event_type;
  179. int max_cooling_method;
  180. unsigned int illumination_supported:1;
  181. unsigned int video_supported:1;
  182. unsigned int fan_supported:1;
  183. unsigned int system_event_supported:1;
  184. unsigned int ntfy_supported:1;
  185. unsigned int info_supported:1;
  186. unsigned int tr_backlight_supported:1;
  187. unsigned int kbd_illum_supported:1;
  188. unsigned int touchpad_supported:1;
  189. unsigned int eco_supported:1;
  190. unsigned int accelerometer_supported:1;
  191. unsigned int usb_sleep_charge_supported:1;
  192. unsigned int usb_rapid_charge_supported:1;
  193. unsigned int usb_sleep_music_supported:1;
  194. unsigned int kbd_function_keys_supported:1;
  195. unsigned int panel_power_on_supported:1;
  196. unsigned int usb_three_supported:1;
  197. unsigned int wwan_supported:1;
  198. unsigned int cooling_method_supported:1;
  199. unsigned int sysfs_created:1;
  200. unsigned int special_functions;
  201. bool kbd_event_generated;
  202. bool kbd_led_registered;
  203. bool illumination_led_registered;
  204. bool eco_led_registered;
  205. bool killswitch;
  206. };
  207. static struct toshiba_acpi_dev *toshiba_acpi;
  208. static bool disable_hotkeys;
  209. module_param(disable_hotkeys, bool, 0444);
  210. MODULE_PARM_DESC(disable_hotkeys, "Disables the hotkeys activation");
  211. static const struct acpi_device_id toshiba_device_ids[] = {
  212. {"TOS6200", 0},
  213. {"TOS6207", 0},
  214. {"TOS6208", 0},
  215. {"TOS1900", 0},
  216. {"", 0},
  217. };
  218. MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
  219. static const struct key_entry toshiba_acpi_keymap[] = {
  220. { KE_KEY, 0x9e, { KEY_RFKILL } },
  221. { KE_KEY, 0x101, { KEY_MUTE } },
  222. { KE_KEY, 0x102, { KEY_ZOOMOUT } },
  223. { KE_KEY, 0x103, { KEY_ZOOMIN } },
  224. { KE_KEY, 0x10f, { KEY_TAB } },
  225. { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
  226. { KE_KEY, 0x139, { KEY_ZOOMRESET } },
  227. { KE_KEY, 0x13b, { KEY_COFFEE } },
  228. { KE_KEY, 0x13c, { KEY_BATTERY } },
  229. { KE_KEY, 0x13d, { KEY_SLEEP } },
  230. { KE_KEY, 0x13e, { KEY_SUSPEND } },
  231. { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
  232. { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
  233. { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
  234. { KE_KEY, 0x142, { KEY_WLAN } },
  235. { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
  236. { KE_KEY, 0x17f, { KEY_FN } },
  237. { KE_KEY, 0xb05, { KEY_PROG2 } },
  238. { KE_KEY, 0xb06, { KEY_WWW } },
  239. { KE_KEY, 0xb07, { KEY_MAIL } },
  240. { KE_KEY, 0xb30, { KEY_STOP } },
  241. { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
  242. { KE_KEY, 0xb32, { KEY_NEXTSONG } },
  243. { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
  244. { KE_KEY, 0xb5a, { KEY_MEDIA } },
  245. { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
  246. { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
  247. { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
  248. { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
  249. { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
  250. { KE_END, 0 },
  251. };
  252. static const struct key_entry toshiba_acpi_alt_keymap[] = {
  253. { KE_KEY, 0x102, { KEY_ZOOMOUT } },
  254. { KE_KEY, 0x103, { KEY_ZOOMIN } },
  255. { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
  256. { KE_KEY, 0x139, { KEY_ZOOMRESET } },
  257. { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
  258. { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
  259. { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
  260. { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
  261. { KE_KEY, 0x157, { KEY_MUTE } },
  262. { KE_KEY, 0x158, { KEY_WLAN } },
  263. { KE_END, 0 },
  264. };
  265. /*
  266. * List of models which have a broken acpi-video backlight interface and thus
  267. * need to use the toshiba (vendor) interface instead.
  268. */
  269. static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
  270. {}
  271. };
  272. /*
  273. * Utility
  274. */
  275. static inline void _set_bit(u32 *word, u32 mask, int value)
  276. {
  277. *word = (*word & ~mask) | (mask * value);
  278. }
  279. /*
  280. * ACPI interface wrappers
  281. */
  282. static int write_acpi_int(const char *methodName, int val)
  283. {
  284. acpi_status status;
  285. status = acpi_execute_simple_method(NULL, (char *)methodName, val);
  286. return (status == AE_OK) ? 0 : -EIO;
  287. }
  288. /*
  289. * Perform a raw configuration call. Here we don't care about input or output
  290. * buffer format.
  291. */
  292. static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
  293. const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
  294. {
  295. union acpi_object in_objs[TCI_WORDS], out_objs[TCI_WORDS + 1];
  296. struct acpi_object_list params;
  297. struct acpi_buffer results;
  298. acpi_status status;
  299. int i;
  300. params.count = TCI_WORDS;
  301. params.pointer = in_objs;
  302. for (i = 0; i < TCI_WORDS; ++i) {
  303. in_objs[i].type = ACPI_TYPE_INTEGER;
  304. in_objs[i].integer.value = in[i];
  305. }
  306. results.length = sizeof(out_objs);
  307. results.pointer = out_objs;
  308. status = acpi_evaluate_object(dev->acpi_dev->handle,
  309. (char *)dev->method_hci, &params,
  310. &results);
  311. if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
  312. for (i = 0; i < out_objs->package.count; ++i)
  313. out[i] = out_objs->package.elements[i].integer.value;
  314. }
  315. return status;
  316. }
  317. /*
  318. * Common hci tasks
  319. *
  320. * In addition to the ACPI status, the HCI system returns a result which
  321. * may be useful (such as "not supported").
  322. */
  323. static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
  324. {
  325. u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
  326. u32 out[TCI_WORDS];
  327. acpi_status status = tci_raw(dev, in, out);
  328. return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
  329. }
  330. static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
  331. {
  332. u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
  333. u32 out[TCI_WORDS];
  334. acpi_status status = tci_raw(dev, in, out);
  335. if (ACPI_FAILURE(status))
  336. return TOS_FAILURE;
  337. *out1 = out[2];
  338. return out[0];
  339. }
  340. /*
  341. * Common sci tasks
  342. */
  343. static int sci_open(struct toshiba_acpi_dev *dev)
  344. {
  345. u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
  346. u32 out[TCI_WORDS];
  347. acpi_status status = tci_raw(dev, in, out);
  348. if (ACPI_FAILURE(status)) {
  349. pr_err("ACPI call to open SCI failed\n");
  350. return 0;
  351. }
  352. if (out[0] == TOS_OPEN_CLOSE_OK) {
  353. return 1;
  354. } else if (out[0] == TOS_ALREADY_OPEN) {
  355. pr_info("Toshiba SCI already opened\n");
  356. return 1;
  357. } else if (out[0] == TOS_NOT_SUPPORTED) {
  358. /*
  359. * Some BIOSes do not have the SCI open/close functions
  360. * implemented and return 0x8000 (Not Supported), failing to
  361. * register some supported features.
  362. *
  363. * Simply return 1 if we hit those affected laptops to make the
  364. * supported features work.
  365. *
  366. * In the case that some laptops really do not support the SCI,
  367. * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
  368. * and thus, not registering support for the queried feature.
  369. */
  370. return 1;
  371. } else if (out[0] == TOS_NOT_PRESENT) {
  372. pr_info("Toshiba SCI is not present\n");
  373. }
  374. return 0;
  375. }
  376. static void sci_close(struct toshiba_acpi_dev *dev)
  377. {
  378. u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
  379. u32 out[TCI_WORDS];
  380. acpi_status status = tci_raw(dev, in, out);
  381. if (ACPI_FAILURE(status)) {
  382. pr_err("ACPI call to close SCI failed\n");
  383. return;
  384. }
  385. if (out[0] == TOS_OPEN_CLOSE_OK)
  386. return;
  387. else if (out[0] == TOS_NOT_OPENED)
  388. pr_info("Toshiba SCI not opened\n");
  389. else if (out[0] == TOS_NOT_PRESENT)
  390. pr_info("Toshiba SCI is not present\n");
  391. }
  392. static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
  393. {
  394. u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
  395. u32 out[TCI_WORDS];
  396. acpi_status status = tci_raw(dev, in, out);
  397. if (ACPI_FAILURE(status))
  398. return TOS_FAILURE;
  399. *out1 = out[2];
  400. return out[0];
  401. }
  402. static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
  403. {
  404. u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
  405. u32 out[TCI_WORDS];
  406. acpi_status status = tci_raw(dev, in, out);
  407. return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
  408. }
  409. /* Illumination support */
  410. static void toshiba_illumination_available(struct toshiba_acpi_dev *dev)
  411. {
  412. u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
  413. u32 out[TCI_WORDS];
  414. acpi_status status;
  415. dev->illumination_supported = 0;
  416. dev->illumination_led_registered = false;
  417. if (!sci_open(dev))
  418. return;
  419. status = tci_raw(dev, in, out);
  420. sci_close(dev);
  421. if (ACPI_FAILURE(status)) {
  422. pr_err("ACPI call to query Illumination support failed\n");
  423. return;
  424. }
  425. if (out[0] != TOS_SUCCESS)
  426. return;
  427. dev->illumination_supported = 1;
  428. }
  429. static void toshiba_illumination_set(struct led_classdev *cdev,
  430. enum led_brightness brightness)
  431. {
  432. struct toshiba_acpi_dev *dev = container_of(cdev,
  433. struct toshiba_acpi_dev, led_dev);
  434. u32 result;
  435. u32 state;
  436. /* First request : initialize communication. */
  437. if (!sci_open(dev))
  438. return;
  439. /* Switch the illumination on/off */
  440. state = brightness ? 1 : 0;
  441. result = sci_write(dev, SCI_ILLUMINATION, state);
  442. sci_close(dev);
  443. if (result == TOS_FAILURE)
  444. pr_err("ACPI call for illumination failed\n");
  445. }
  446. static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
  447. {
  448. struct toshiba_acpi_dev *dev = container_of(cdev,
  449. struct toshiba_acpi_dev, led_dev);
  450. u32 result;
  451. u32 state;
  452. /* First request : initialize communication. */
  453. if (!sci_open(dev))
  454. return LED_OFF;
  455. /* Check the illumination */
  456. result = sci_read(dev, SCI_ILLUMINATION, &state);
  457. sci_close(dev);
  458. if (result == TOS_FAILURE) {
  459. pr_err("ACPI call for illumination failed\n");
  460. return LED_OFF;
  461. } else if (result != TOS_SUCCESS) {
  462. return LED_OFF;
  463. }
  464. return state ? LED_FULL : LED_OFF;
  465. }
  466. /* KBD Illumination */
  467. static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
  468. {
  469. u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
  470. u32 out[TCI_WORDS];
  471. acpi_status status;
  472. dev->kbd_illum_supported = 0;
  473. dev->kbd_led_registered = false;
  474. dev->kbd_event_generated = false;
  475. if (!sci_open(dev))
  476. return;
  477. status = tci_raw(dev, in, out);
  478. sci_close(dev);
  479. if (ACPI_FAILURE(status)) {
  480. pr_err("ACPI call to query kbd illumination support failed\n");
  481. return;
  482. }
  483. if (out[0] != TOS_SUCCESS)
  484. return;
  485. /*
  486. * Check for keyboard backlight timeout max value,
  487. * previous kbd backlight implementation set this to
  488. * 0x3c0003, and now the new implementation set this
  489. * to 0x3c001a, use this to distinguish between them.
  490. */
  491. if (out[3] == SCI_KBD_TIME_MAX)
  492. dev->kbd_type = 2;
  493. else
  494. dev->kbd_type = 1;
  495. /* Get the current keyboard backlight mode */
  496. dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
  497. /* Get the current time (1-60 seconds) */
  498. dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
  499. /* Flag as supported */
  500. dev->kbd_illum_supported = 1;
  501. }
  502. static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
  503. {
  504. u32 result;
  505. if (!sci_open(dev))
  506. return -EIO;
  507. result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
  508. sci_close(dev);
  509. if (result == TOS_FAILURE)
  510. pr_err("ACPI call to set KBD backlight status failed\n");
  511. else if (result == TOS_NOT_SUPPORTED)
  512. return -ENODEV;
  513. return result == TOS_SUCCESS ? 0 : -EIO;
  514. }
  515. static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
  516. {
  517. u32 result;
  518. if (!sci_open(dev))
  519. return -EIO;
  520. result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
  521. sci_close(dev);
  522. if (result == TOS_FAILURE)
  523. pr_err("ACPI call to get KBD backlight status failed\n");
  524. else if (result == TOS_NOT_SUPPORTED)
  525. return -ENODEV;
  526. return result == TOS_SUCCESS ? 0 : -EIO;
  527. }
  528. static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
  529. {
  530. struct toshiba_acpi_dev *dev = container_of(cdev,
  531. struct toshiba_acpi_dev, kbd_led);
  532. u32 result;
  533. u32 state;
  534. /* Check the keyboard backlight state */
  535. result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
  536. if (result == TOS_FAILURE) {
  537. pr_err("ACPI call to get the keyboard backlight failed\n");
  538. return LED_OFF;
  539. } else if (result != TOS_SUCCESS) {
  540. return LED_OFF;
  541. }
  542. return state ? LED_FULL : LED_OFF;
  543. }
  544. static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
  545. enum led_brightness brightness)
  546. {
  547. struct toshiba_acpi_dev *dev = container_of(cdev,
  548. struct toshiba_acpi_dev, kbd_led);
  549. u32 result;
  550. u32 state;
  551. /* Set the keyboard backlight state */
  552. state = brightness ? 1 : 0;
  553. result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
  554. if (result == TOS_FAILURE)
  555. pr_err("ACPI call to set KBD Illumination mode failed\n");
  556. }
  557. /* TouchPad support */
  558. static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
  559. {
  560. u32 result;
  561. if (!sci_open(dev))
  562. return -EIO;
  563. result = sci_write(dev, SCI_TOUCHPAD, state);
  564. sci_close(dev);
  565. if (result == TOS_FAILURE)
  566. pr_err("ACPI call to set the touchpad failed\n");
  567. else if (result == TOS_NOT_SUPPORTED)
  568. return -ENODEV;
  569. return result == TOS_SUCCESS ? 0 : -EIO;
  570. }
  571. static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
  572. {
  573. u32 result;
  574. if (!sci_open(dev))
  575. return -EIO;
  576. result = sci_read(dev, SCI_TOUCHPAD, state);
  577. sci_close(dev);
  578. if (result == TOS_FAILURE)
  579. pr_err("ACPI call to query the touchpad failed\n");
  580. else if (result == TOS_NOT_SUPPORTED)
  581. return -ENODEV;
  582. return result == TOS_SUCCESS ? 0 : -EIO;
  583. }
  584. /* Eco Mode support */
  585. static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
  586. {
  587. u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
  588. u32 out[TCI_WORDS];
  589. acpi_status status;
  590. dev->eco_supported = 0;
  591. dev->eco_led_registered = false;
  592. status = tci_raw(dev, in, out);
  593. if (ACPI_FAILURE(status)) {
  594. pr_err("ACPI call to get ECO led failed\n");
  595. return;
  596. }
  597. if (out[0] == TOS_INPUT_DATA_ERROR) {
  598. /*
  599. * If we receive 0x8300 (Input Data Error), it means that the
  600. * LED device is present, but that we just screwed the input
  601. * parameters.
  602. *
  603. * Let's query the status of the LED to see if we really have a
  604. * success response, indicating the actual presense of the LED,
  605. * bail out otherwise.
  606. */
  607. in[3] = 1;
  608. status = tci_raw(dev, in, out);
  609. if (ACPI_FAILURE(status)) {
  610. pr_err("ACPI call to get ECO led failed\n");
  611. return;
  612. }
  613. if (out[0] != TOS_SUCCESS)
  614. return;
  615. dev->eco_supported = 1;
  616. }
  617. }
  618. static enum led_brightness
  619. toshiba_eco_mode_get_status(struct led_classdev *cdev)
  620. {
  621. struct toshiba_acpi_dev *dev = container_of(cdev,
  622. struct toshiba_acpi_dev, eco_led);
  623. u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
  624. u32 out[TCI_WORDS];
  625. acpi_status status;
  626. status = tci_raw(dev, in, out);
  627. if (ACPI_FAILURE(status)) {
  628. pr_err("ACPI call to get ECO led failed\n");
  629. return LED_OFF;
  630. }
  631. if (out[0] != TOS_SUCCESS)
  632. return LED_OFF;
  633. return out[2] ? LED_FULL : LED_OFF;
  634. }
  635. static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
  636. enum led_brightness brightness)
  637. {
  638. struct toshiba_acpi_dev *dev = container_of(cdev,
  639. struct toshiba_acpi_dev, eco_led);
  640. u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
  641. u32 out[TCI_WORDS];
  642. acpi_status status;
  643. /* Switch the Eco Mode led on/off */
  644. in[2] = (brightness) ? 1 : 0;
  645. status = tci_raw(dev, in, out);
  646. if (ACPI_FAILURE(status))
  647. pr_err("ACPI call to set ECO led failed\n");
  648. }
  649. /* Accelerometer support */
  650. static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev)
  651. {
  652. u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
  653. u32 out[TCI_WORDS];
  654. acpi_status status;
  655. dev->accelerometer_supported = 0;
  656. /*
  657. * Check if the accelerometer call exists,
  658. * this call also serves as initialization
  659. */
  660. status = tci_raw(dev, in, out);
  661. if (ACPI_FAILURE(status)) {
  662. pr_err("ACPI call to query the accelerometer failed\n");
  663. return;
  664. }
  665. if (out[0] != TOS_SUCCESS)
  666. return;
  667. dev->accelerometer_supported = 1;
  668. }
  669. static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
  670. u32 *xy, u32 *z)
  671. {
  672. u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
  673. u32 out[TCI_WORDS];
  674. acpi_status status;
  675. /* Check the Accelerometer status */
  676. status = tci_raw(dev, in, out);
  677. if (ACPI_FAILURE(status)) {
  678. pr_err("ACPI call to query the accelerometer failed\n");
  679. return -EIO;
  680. }
  681. if (out[0] == TOS_NOT_SUPPORTED)
  682. return -ENODEV;
  683. if (out[0] != TOS_SUCCESS)
  684. return -EIO;
  685. *xy = out[2];
  686. *z = out[4];
  687. return 0;
  688. }
  689. /* Sleep (Charge and Music) utilities support */
  690. static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
  691. {
  692. u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
  693. u32 out[TCI_WORDS];
  694. acpi_status status;
  695. dev->usb_sleep_charge_supported = 0;
  696. if (!sci_open(dev))
  697. return;
  698. status = tci_raw(dev, in, out);
  699. if (ACPI_FAILURE(status)) {
  700. pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
  701. sci_close(dev);
  702. return;
  703. }
  704. if (out[0] != TOS_SUCCESS) {
  705. sci_close(dev);
  706. return;
  707. }
  708. dev->usbsc_mode_base = out[4];
  709. in[5] = SCI_USB_CHARGE_BAT_LVL;
  710. status = tci_raw(dev, in, out);
  711. sci_close(dev);
  712. if (ACPI_FAILURE(status)) {
  713. pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
  714. return;
  715. }
  716. if (out[0] != TOS_SUCCESS)
  717. return;
  718. dev->usbsc_bat_level = out[2];
  719. /* Flag as supported */
  720. dev->usb_sleep_charge_supported = 1;
  721. }
  722. static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
  723. u32 *mode)
  724. {
  725. u32 result;
  726. if (!sci_open(dev))
  727. return -EIO;
  728. result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
  729. sci_close(dev);
  730. if (result == TOS_FAILURE)
  731. pr_err("ACPI call to set USB S&C mode failed\n");
  732. else if (result == TOS_NOT_SUPPORTED)
  733. return -ENODEV;
  734. return result == TOS_SUCCESS ? 0 : -EIO;
  735. }
  736. static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
  737. u32 mode)
  738. {
  739. u32 result;
  740. if (!sci_open(dev))
  741. return -EIO;
  742. result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
  743. sci_close(dev);
  744. if (result == TOS_FAILURE)
  745. pr_err("ACPI call to set USB S&C mode failed\n");
  746. else if (result == TOS_NOT_SUPPORTED)
  747. return -ENODEV;
  748. return result == TOS_SUCCESS ? 0 : -EIO;
  749. }
  750. static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
  751. u32 *mode)
  752. {
  753. u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
  754. u32 out[TCI_WORDS];
  755. acpi_status status;
  756. if (!sci_open(dev))
  757. return -EIO;
  758. in[5] = SCI_USB_CHARGE_BAT_LVL;
  759. status = tci_raw(dev, in, out);
  760. sci_close(dev);
  761. if (ACPI_FAILURE(status)) {
  762. pr_err("ACPI call to get USB S&C battery level failed\n");
  763. return -EIO;
  764. }
  765. if (out[0] == TOS_NOT_SUPPORTED)
  766. return -ENODEV;
  767. if (out[0] != TOS_SUCCESS)
  768. return -EIO;
  769. *mode = out[2];
  770. return 0;
  771. }
  772. static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
  773. u32 mode)
  774. {
  775. u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
  776. u32 out[TCI_WORDS];
  777. acpi_status status;
  778. if (!sci_open(dev))
  779. return -EIO;
  780. in[2] = mode;
  781. in[5] = SCI_USB_CHARGE_BAT_LVL;
  782. status = tci_raw(dev, in, out);
  783. sci_close(dev);
  784. if (ACPI_FAILURE(status)) {
  785. pr_err("ACPI call to set USB S&C battery level failed\n");
  786. return -EIO;
  787. }
  788. if (out[0] == TOS_NOT_SUPPORTED)
  789. return -ENODEV;
  790. return out[0] == TOS_SUCCESS ? 0 : -EIO;
  791. }
  792. static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
  793. u32 *state)
  794. {
  795. u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
  796. u32 out[TCI_WORDS];
  797. acpi_status status;
  798. if (!sci_open(dev))
  799. return -EIO;
  800. in[5] = SCI_USB_CHARGE_RAPID_DSP;
  801. status = tci_raw(dev, in, out);
  802. sci_close(dev);
  803. if (ACPI_FAILURE(status)) {
  804. pr_err("ACPI call to get USB Rapid Charge failed\n");
  805. return -EIO;
  806. }
  807. if (out[0] == TOS_NOT_SUPPORTED)
  808. return -ENODEV;
  809. if (out[0] != TOS_SUCCESS && out[0] != TOS_SUCCESS2)
  810. return -EIO;
  811. *state = out[2];
  812. return 0;
  813. }
  814. static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
  815. u32 state)
  816. {
  817. u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
  818. u32 out[TCI_WORDS];
  819. acpi_status status;
  820. if (!sci_open(dev))
  821. return -EIO;
  822. in[2] = state;
  823. in[5] = SCI_USB_CHARGE_RAPID_DSP;
  824. status = tci_raw(dev, in, out);
  825. sci_close(dev);
  826. if (ACPI_FAILURE(status)) {
  827. pr_err("ACPI call to set USB Rapid Charge failed\n");
  828. return -EIO;
  829. }
  830. if (out[0] == TOS_NOT_SUPPORTED)
  831. return -ENODEV;
  832. return (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) ? 0 : -EIO;
  833. }
  834. static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
  835. {
  836. u32 result;
  837. if (!sci_open(dev))
  838. return -EIO;
  839. result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
  840. sci_close(dev);
  841. if (result == TOS_FAILURE)
  842. pr_err("ACPI call to get Sleep and Music failed\n");
  843. else if (result == TOS_NOT_SUPPORTED)
  844. return -ENODEV;
  845. return result == TOS_SUCCESS ? 0 : -EIO;
  846. }
  847. static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
  848. {
  849. u32 result;
  850. if (!sci_open(dev))
  851. return -EIO;
  852. result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
  853. sci_close(dev);
  854. if (result == TOS_FAILURE)
  855. pr_err("ACPI call to set Sleep and Music failed\n");
  856. else if (result == TOS_NOT_SUPPORTED)
  857. return -ENODEV;
  858. return result == TOS_SUCCESS ? 0 : -EIO;
  859. }
  860. /* Keyboard function keys */
  861. static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
  862. {
  863. u32 result;
  864. if (!sci_open(dev))
  865. return -EIO;
  866. result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
  867. sci_close(dev);
  868. if (result == TOS_FAILURE)
  869. pr_err("ACPI call to get KBD function keys failed\n");
  870. else if (result == TOS_NOT_SUPPORTED)
  871. return -ENODEV;
  872. return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  873. }
  874. static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
  875. {
  876. u32 result;
  877. if (!sci_open(dev))
  878. return -EIO;
  879. result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
  880. sci_close(dev);
  881. if (result == TOS_FAILURE)
  882. pr_err("ACPI call to set KBD function keys failed\n");
  883. else if (result == TOS_NOT_SUPPORTED)
  884. return -ENODEV;
  885. return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  886. }
  887. /* Panel Power ON */
  888. static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
  889. {
  890. u32 result;
  891. if (!sci_open(dev))
  892. return -EIO;
  893. result = sci_read(dev, SCI_PANEL_POWER_ON, state);
  894. sci_close(dev);
  895. if (result == TOS_FAILURE)
  896. pr_err("ACPI call to get Panel Power ON failed\n");
  897. else if (result == TOS_NOT_SUPPORTED)
  898. return -ENODEV;
  899. return result == TOS_SUCCESS ? 0 : -EIO;
  900. }
  901. static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
  902. {
  903. u32 result;
  904. if (!sci_open(dev))
  905. return -EIO;
  906. result = sci_write(dev, SCI_PANEL_POWER_ON, state);
  907. sci_close(dev);
  908. if (result == TOS_FAILURE)
  909. pr_err("ACPI call to set Panel Power ON failed\n");
  910. else if (result == TOS_NOT_SUPPORTED)
  911. return -ENODEV;
  912. return result == TOS_SUCCESS ? 0 : -EIO;
  913. }
  914. /* USB Three */
  915. static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
  916. {
  917. u32 result;
  918. if (!sci_open(dev))
  919. return -EIO;
  920. result = sci_read(dev, SCI_USB_THREE, state);
  921. sci_close(dev);
  922. if (result == TOS_FAILURE)
  923. pr_err("ACPI call to get USB 3 failed\n");
  924. else if (result == TOS_NOT_SUPPORTED)
  925. return -ENODEV;
  926. return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  927. }
  928. static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
  929. {
  930. u32 result;
  931. if (!sci_open(dev))
  932. return -EIO;
  933. result = sci_write(dev, SCI_USB_THREE, state);
  934. sci_close(dev);
  935. if (result == TOS_FAILURE)
  936. pr_err("ACPI call to set USB 3 failed\n");
  937. else if (result == TOS_NOT_SUPPORTED)
  938. return -ENODEV;
  939. return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  940. }
  941. /* Hotkey Event type */
  942. static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
  943. u32 *type)
  944. {
  945. u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
  946. u32 out[TCI_WORDS];
  947. acpi_status status;
  948. status = tci_raw(dev, in, out);
  949. if (ACPI_FAILURE(status)) {
  950. pr_err("ACPI call to get System type failed\n");
  951. return -EIO;
  952. }
  953. if (out[0] == TOS_NOT_SUPPORTED)
  954. return -ENODEV;
  955. if (out[0] != TOS_SUCCESS)
  956. return -EIO;
  957. *type = out[3];
  958. return 0;
  959. }
  960. /* Wireless status (RFKill, WLAN, BT, WWAN) */
  961. static int toshiba_wireless_status(struct toshiba_acpi_dev *dev)
  962. {
  963. u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
  964. u32 out[TCI_WORDS];
  965. acpi_status status;
  966. in[3] = HCI_WIRELESS_STATUS;
  967. status = tci_raw(dev, in, out);
  968. if (ACPI_FAILURE(status)) {
  969. pr_err("ACPI call to get Wireless status failed\n");
  970. return -EIO;
  971. }
  972. if (out[0] == TOS_NOT_SUPPORTED)
  973. return -ENODEV;
  974. if (out[0] != TOS_SUCCESS)
  975. return -EIO;
  976. dev->killswitch = !!(out[2] & HCI_WIRELESS_STATUS);
  977. return 0;
  978. }
  979. /* WWAN */
  980. static void toshiba_wwan_available(struct toshiba_acpi_dev *dev)
  981. {
  982. u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
  983. u32 out[TCI_WORDS];
  984. acpi_status status;
  985. dev->wwan_supported = 0;
  986. /*
  987. * WWAN support can be queried by setting the in[3] value to
  988. * HCI_WIRELESS_WWAN (0x03).
  989. *
  990. * If supported, out[0] contains TOS_SUCCESS and out[2] contains
  991. * HCI_WIRELESS_WWAN_STATUS (0x2000).
  992. *
  993. * If not supported, out[0] contains TOS_INPUT_DATA_ERROR (0x8300)
  994. * or TOS_NOT_SUPPORTED (0x8000).
  995. */
  996. in[3] = HCI_WIRELESS_WWAN;
  997. status = tci_raw(dev, in, out);
  998. if (ACPI_FAILURE(status)) {
  999. pr_err("ACPI call to get WWAN status failed\n");
  1000. return;
  1001. }
  1002. if (out[0] != TOS_SUCCESS)
  1003. return;
  1004. dev->wwan_supported = (out[2] == HCI_WIRELESS_WWAN_STATUS);
  1005. }
  1006. static int toshiba_wwan_set(struct toshiba_acpi_dev *dev, u32 state)
  1007. {
  1008. u32 in[TCI_WORDS] = { HCI_SET, HCI_WIRELESS, state, 0, 0, 0 };
  1009. u32 out[TCI_WORDS];
  1010. acpi_status status;
  1011. in[3] = HCI_WIRELESS_WWAN_STATUS;
  1012. status = tci_raw(dev, in, out);
  1013. if (ACPI_FAILURE(status)) {
  1014. pr_err("ACPI call to set WWAN status failed\n");
  1015. return -EIO;
  1016. }
  1017. if (out[0] == TOS_NOT_SUPPORTED)
  1018. return -ENODEV;
  1019. if (out[0] != TOS_SUCCESS)
  1020. return -EIO;
  1021. /*
  1022. * Some devices only need to call HCI_WIRELESS_WWAN_STATUS to
  1023. * (de)activate the device, but some others need the
  1024. * HCI_WIRELESS_WWAN_POWER call as well.
  1025. */
  1026. in[3] = HCI_WIRELESS_WWAN_POWER;
  1027. status = tci_raw(dev, in, out);
  1028. if (ACPI_FAILURE(status)) {
  1029. pr_err("ACPI call to set WWAN power failed\n");
  1030. return -EIO;
  1031. }
  1032. if (out[0] == TOS_NOT_SUPPORTED)
  1033. return -ENODEV;
  1034. return out[0] == TOS_SUCCESS ? 0 : -EIO;
  1035. }
  1036. /* Cooling Method */
  1037. static void toshiba_cooling_method_available(struct toshiba_acpi_dev *dev)
  1038. {
  1039. u32 in[TCI_WORDS] = { HCI_GET, HCI_COOLING_METHOD, 0, 0, 0, 0 };
  1040. u32 out[TCI_WORDS];
  1041. acpi_status status;
  1042. dev->cooling_method_supported = 0;
  1043. dev->max_cooling_method = 0;
  1044. status = tci_raw(dev, in, out);
  1045. if (ACPI_FAILURE(status)) {
  1046. pr_err("ACPI call to get Cooling Method failed\n");
  1047. return;
  1048. }
  1049. if (out[0] != TOS_SUCCESS && out[0] != TOS_SUCCESS2)
  1050. return;
  1051. dev->cooling_method_supported = 1;
  1052. dev->max_cooling_method = out[3];
  1053. }
  1054. static int toshiba_cooling_method_get(struct toshiba_acpi_dev *dev, u32 *state)
  1055. {
  1056. u32 result = hci_read(dev, HCI_COOLING_METHOD, state);
  1057. if (result == TOS_FAILURE)
  1058. pr_err("ACPI call to get Cooling Method failed\n");
  1059. if (result == TOS_NOT_SUPPORTED)
  1060. return -ENODEV;
  1061. return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  1062. }
  1063. static int toshiba_cooling_method_set(struct toshiba_acpi_dev *dev, u32 state)
  1064. {
  1065. u32 result = hci_write(dev, HCI_COOLING_METHOD, state);
  1066. if (result == TOS_FAILURE)
  1067. pr_err("ACPI call to set Cooling Method failed\n");
  1068. if (result == TOS_NOT_SUPPORTED)
  1069. return -ENODEV;
  1070. return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  1071. }
  1072. /* Transflective Backlight */
  1073. static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
  1074. {
  1075. u32 result = hci_read(dev, HCI_TR_BACKLIGHT, status);
  1076. if (result == TOS_FAILURE)
  1077. pr_err("ACPI call to get Transflective Backlight failed\n");
  1078. else if (result == TOS_NOT_SUPPORTED)
  1079. return -ENODEV;
  1080. return result == TOS_SUCCESS ? 0 : -EIO;
  1081. }
  1082. static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
  1083. {
  1084. u32 result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
  1085. if (result == TOS_FAILURE)
  1086. pr_err("ACPI call to set Transflective Backlight failed\n");
  1087. else if (result == TOS_NOT_SUPPORTED)
  1088. return -ENODEV;
  1089. return result == TOS_SUCCESS ? 0 : -EIO;
  1090. }
  1091. static struct proc_dir_entry *toshiba_proc_dir;
  1092. /* LCD Brightness */
  1093. static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
  1094. {
  1095. int brightness = 0;
  1096. u32 result;
  1097. u32 value;
  1098. if (dev->tr_backlight_supported) {
  1099. int ret = get_tr_backlight_status(dev, &value);
  1100. if (ret)
  1101. return ret;
  1102. if (value)
  1103. return 0;
  1104. brightness++;
  1105. }
  1106. result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
  1107. if (result == TOS_FAILURE)
  1108. pr_err("ACPI call to get LCD Brightness failed\n");
  1109. else if (result == TOS_NOT_SUPPORTED)
  1110. return -ENODEV;
  1111. return result == TOS_SUCCESS ?
  1112. brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT) :
  1113. -EIO;
  1114. }
  1115. static int get_lcd_brightness(struct backlight_device *bd)
  1116. {
  1117. struct toshiba_acpi_dev *dev = bl_get_data(bd);
  1118. return __get_lcd_brightness(dev);
  1119. }
  1120. static int lcd_proc_show(struct seq_file *m, void *v)
  1121. {
  1122. struct toshiba_acpi_dev *dev = m->private;
  1123. int levels;
  1124. int value;
  1125. if (!dev->backlight_dev)
  1126. return -ENODEV;
  1127. levels = dev->backlight_dev->props.max_brightness + 1;
  1128. value = get_lcd_brightness(dev->backlight_dev);
  1129. if (value < 0) {
  1130. pr_err("Error reading LCD brightness\n");
  1131. return value;
  1132. }
  1133. seq_printf(m, "brightness: %d\n", value);
  1134. seq_printf(m, "brightness_levels: %d\n", levels);
  1135. return 0;
  1136. }
  1137. static int lcd_proc_open(struct inode *inode, struct file *file)
  1138. {
  1139. return single_open(file, lcd_proc_show, PDE_DATA(inode));
  1140. }
  1141. static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
  1142. {
  1143. u32 result;
  1144. if (dev->tr_backlight_supported) {
  1145. int ret = set_tr_backlight_status(dev, !value);
  1146. if (ret)
  1147. return ret;
  1148. if (value)
  1149. value--;
  1150. }
  1151. value = value << HCI_LCD_BRIGHTNESS_SHIFT;
  1152. result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
  1153. if (result == TOS_FAILURE)
  1154. pr_err("ACPI call to set LCD Brightness failed\n");
  1155. else if (result == TOS_NOT_SUPPORTED)
  1156. return -ENODEV;
  1157. return result == TOS_SUCCESS ? 0 : -EIO;
  1158. }
  1159. static int set_lcd_status(struct backlight_device *bd)
  1160. {
  1161. struct toshiba_acpi_dev *dev = bl_get_data(bd);
  1162. return set_lcd_brightness(dev, bd->props.brightness);
  1163. }
  1164. static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
  1165. size_t count, loff_t *pos)
  1166. {
  1167. struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  1168. char cmd[42];
  1169. size_t len;
  1170. int levels;
  1171. int value;
  1172. len = min(count, sizeof(cmd) - 1);
  1173. if (copy_from_user(cmd, buf, len))
  1174. return -EFAULT;
  1175. cmd[len] = '\0';
  1176. levels = dev->backlight_dev->props.max_brightness + 1;
  1177. if (sscanf(cmd, " brightness : %i", &value) != 1 &&
  1178. value < 0 && value > levels)
  1179. return -EINVAL;
  1180. if (set_lcd_brightness(dev, value))
  1181. return -EIO;
  1182. return count;
  1183. }
  1184. static const struct file_operations lcd_proc_fops = {
  1185. .owner = THIS_MODULE,
  1186. .open = lcd_proc_open,
  1187. .read = seq_read,
  1188. .llseek = seq_lseek,
  1189. .release = single_release,
  1190. .write = lcd_proc_write,
  1191. };
  1192. /* Video-Out */
  1193. static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
  1194. {
  1195. u32 result = hci_read(dev, HCI_VIDEO_OUT, status);
  1196. if (result == TOS_FAILURE)
  1197. pr_err("ACPI call to get Video-Out failed\n");
  1198. else if (result == TOS_NOT_SUPPORTED)
  1199. return -ENODEV;
  1200. return result == TOS_SUCCESS ? 0 : -EIO;
  1201. }
  1202. static int video_proc_show(struct seq_file *m, void *v)
  1203. {
  1204. struct toshiba_acpi_dev *dev = m->private;
  1205. int is_lcd, is_crt, is_tv;
  1206. u32 value;
  1207. if (get_video_status(dev, &value))
  1208. return -EIO;
  1209. is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
  1210. is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
  1211. is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
  1212. seq_printf(m, "lcd_out: %d\n", is_lcd);
  1213. seq_printf(m, "crt_out: %d\n", is_crt);
  1214. seq_printf(m, "tv_out: %d\n", is_tv);
  1215. return 0;
  1216. }
  1217. static int video_proc_open(struct inode *inode, struct file *file)
  1218. {
  1219. return single_open(file, video_proc_show, PDE_DATA(inode));
  1220. }
  1221. static ssize_t video_proc_write(struct file *file, const char __user *buf,
  1222. size_t count, loff_t *pos)
  1223. {
  1224. struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  1225. char *buffer;
  1226. char *cmd;
  1227. int lcd_out, crt_out, tv_out;
  1228. int remain = count;
  1229. int value;
  1230. int ret;
  1231. u32 video_out;
  1232. cmd = kmalloc(count + 1, GFP_KERNEL);
  1233. if (!cmd)
  1234. return -ENOMEM;
  1235. if (copy_from_user(cmd, buf, count)) {
  1236. kfree(cmd);
  1237. return -EFAULT;
  1238. }
  1239. cmd[count] = '\0';
  1240. buffer = cmd;
  1241. /*
  1242. * Scan expression. Multiple expressions may be delimited with ;
  1243. * NOTE: To keep scanning simple, invalid fields are ignored.
  1244. */
  1245. while (remain) {
  1246. if (sscanf(buffer, " lcd_out : %i", &value) == 1)
  1247. lcd_out = value & 1;
  1248. else if (sscanf(buffer, " crt_out : %i", &value) == 1)
  1249. crt_out = value & 1;
  1250. else if (sscanf(buffer, " tv_out : %i", &value) == 1)
  1251. tv_out = value & 1;
  1252. /* Advance to one character past the next ; */
  1253. do {
  1254. ++buffer;
  1255. --remain;
  1256. } while (remain && *(buffer - 1) != ';');
  1257. }
  1258. kfree(cmd);
  1259. lcd_out = crt_out = tv_out = -1;
  1260. ret = get_video_status(dev, &video_out);
  1261. if (!ret) {
  1262. unsigned int new_video_out = video_out;
  1263. if (lcd_out != -1)
  1264. _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
  1265. if (crt_out != -1)
  1266. _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
  1267. if (tv_out != -1)
  1268. _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
  1269. /*
  1270. * To avoid unnecessary video disruption, only write the new
  1271. * video setting if something changed.
  1272. */
  1273. if (new_video_out != video_out)
  1274. ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
  1275. }
  1276. return ret ? -EIO : count;
  1277. }
  1278. static const struct file_operations video_proc_fops = {
  1279. .owner = THIS_MODULE,
  1280. .open = video_proc_open,
  1281. .read = seq_read,
  1282. .llseek = seq_lseek,
  1283. .release = single_release,
  1284. .write = video_proc_write,
  1285. };
  1286. /* Fan status */
  1287. static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
  1288. {
  1289. u32 result = hci_read(dev, HCI_FAN, status);
  1290. if (result == TOS_FAILURE)
  1291. pr_err("ACPI call to get Fan status failed\n");
  1292. else if (result == TOS_NOT_SUPPORTED)
  1293. return -ENODEV;
  1294. return result == TOS_SUCCESS ? 0 : -EIO;
  1295. }
  1296. static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
  1297. {
  1298. u32 result = hci_write(dev, HCI_FAN, status);
  1299. if (result == TOS_FAILURE)
  1300. pr_err("ACPI call to set Fan status failed\n");
  1301. else if (result == TOS_NOT_SUPPORTED)
  1302. return -ENODEV;
  1303. return result == TOS_SUCCESS ? 0 : -EIO;
  1304. }
  1305. static int fan_proc_show(struct seq_file *m, void *v)
  1306. {
  1307. struct toshiba_acpi_dev *dev = m->private;
  1308. u32 value;
  1309. if (get_fan_status(dev, &value))
  1310. return -EIO;
  1311. seq_printf(m, "running: %d\n", (value > 0));
  1312. seq_printf(m, "force_on: %d\n", dev->force_fan);
  1313. return 0;
  1314. }
  1315. static int fan_proc_open(struct inode *inode, struct file *file)
  1316. {
  1317. return single_open(file, fan_proc_show, PDE_DATA(inode));
  1318. }
  1319. static ssize_t fan_proc_write(struct file *file, const char __user *buf,
  1320. size_t count, loff_t *pos)
  1321. {
  1322. struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  1323. char cmd[42];
  1324. size_t len;
  1325. int value;
  1326. len = min(count, sizeof(cmd) - 1);
  1327. if (copy_from_user(cmd, buf, len))
  1328. return -EFAULT;
  1329. cmd[len] = '\0';
  1330. if (sscanf(cmd, " force_on : %i", &value) != 1 &&
  1331. value != 0 && value != 1)
  1332. return -EINVAL;
  1333. if (set_fan_status(dev, value))
  1334. return -EIO;
  1335. dev->force_fan = value;
  1336. return count;
  1337. }
  1338. static const struct file_operations fan_proc_fops = {
  1339. .owner = THIS_MODULE,
  1340. .open = fan_proc_open,
  1341. .read = seq_read,
  1342. .llseek = seq_lseek,
  1343. .release = single_release,
  1344. .write = fan_proc_write,
  1345. };
  1346. static int keys_proc_show(struct seq_file *m, void *v)
  1347. {
  1348. struct toshiba_acpi_dev *dev = m->private;
  1349. seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
  1350. seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
  1351. return 0;
  1352. }
  1353. static int keys_proc_open(struct inode *inode, struct file *file)
  1354. {
  1355. return single_open(file, keys_proc_show, PDE_DATA(inode));
  1356. }
  1357. static ssize_t keys_proc_write(struct file *file, const char __user *buf,
  1358. size_t count, loff_t *pos)
  1359. {
  1360. struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  1361. char cmd[42];
  1362. size_t len;
  1363. int value;
  1364. len = min(count, sizeof(cmd) - 1);
  1365. if (copy_from_user(cmd, buf, len))
  1366. return -EFAULT;
  1367. cmd[len] = '\0';
  1368. if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
  1369. dev->key_event_valid = 0;
  1370. else
  1371. return -EINVAL;
  1372. return count;
  1373. }
  1374. static const struct file_operations keys_proc_fops = {
  1375. .owner = THIS_MODULE,
  1376. .open = keys_proc_open,
  1377. .read = seq_read,
  1378. .llseek = seq_lseek,
  1379. .release = single_release,
  1380. .write = keys_proc_write,
  1381. };
  1382. static int version_proc_show(struct seq_file *m, void *v)
  1383. {
  1384. seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
  1385. seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
  1386. return 0;
  1387. }
  1388. static int version_proc_open(struct inode *inode, struct file *file)
  1389. {
  1390. return single_open(file, version_proc_show, PDE_DATA(inode));
  1391. }
  1392. static const struct file_operations version_proc_fops = {
  1393. .owner = THIS_MODULE,
  1394. .open = version_proc_open,
  1395. .read = seq_read,
  1396. .llseek = seq_lseek,
  1397. .release = single_release,
  1398. };
  1399. /*
  1400. * Proc and module init
  1401. */
  1402. #define PROC_TOSHIBA "toshiba"
  1403. static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
  1404. {
  1405. if (dev->backlight_dev)
  1406. proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1407. &lcd_proc_fops, dev);
  1408. if (dev->video_supported)
  1409. proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1410. &video_proc_fops, dev);
  1411. if (dev->fan_supported)
  1412. proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1413. &fan_proc_fops, dev);
  1414. if (dev->hotkey_dev)
  1415. proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1416. &keys_proc_fops, dev);
  1417. proc_create_data("version", S_IRUGO, toshiba_proc_dir,
  1418. &version_proc_fops, dev);
  1419. }
  1420. static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
  1421. {
  1422. if (dev->backlight_dev)
  1423. remove_proc_entry("lcd", toshiba_proc_dir);
  1424. if (dev->video_supported)
  1425. remove_proc_entry("video", toshiba_proc_dir);
  1426. if (dev->fan_supported)
  1427. remove_proc_entry("fan", toshiba_proc_dir);
  1428. if (dev->hotkey_dev)
  1429. remove_proc_entry("keys", toshiba_proc_dir);
  1430. remove_proc_entry("version", toshiba_proc_dir);
  1431. }
  1432. static const struct backlight_ops toshiba_backlight_data = {
  1433. .options = BL_CORE_SUSPENDRESUME,
  1434. .get_brightness = get_lcd_brightness,
  1435. .update_status = set_lcd_status,
  1436. };
  1437. /* Keyboard backlight work */
  1438. static void toshiba_acpi_kbd_bl_work(struct work_struct *work);
  1439. static DECLARE_WORK(kbd_bl_work, toshiba_acpi_kbd_bl_work);
  1440. /*
  1441. * Sysfs files
  1442. */
  1443. static ssize_t version_show(struct device *dev,
  1444. struct device_attribute *attr, char *buf)
  1445. {
  1446. return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
  1447. }
  1448. static DEVICE_ATTR_RO(version);
  1449. static ssize_t fan_store(struct device *dev,
  1450. struct device_attribute *attr,
  1451. const char *buf, size_t count)
  1452. {
  1453. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1454. int state;
  1455. int ret;
  1456. ret = kstrtoint(buf, 0, &state);
  1457. if (ret)
  1458. return ret;
  1459. if (state != 0 && state != 1)
  1460. return -EINVAL;
  1461. ret = set_fan_status(toshiba, state);
  1462. if (ret)
  1463. return ret;
  1464. return count;
  1465. }
  1466. static ssize_t fan_show(struct device *dev,
  1467. struct device_attribute *attr, char *buf)
  1468. {
  1469. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1470. u32 value;
  1471. int ret;
  1472. ret = get_fan_status(toshiba, &value);
  1473. if (ret)
  1474. return ret;
  1475. return sprintf(buf, "%d\n", value);
  1476. }
  1477. static DEVICE_ATTR_RW(fan);
  1478. static ssize_t kbd_backlight_mode_store(struct device *dev,
  1479. struct device_attribute *attr,
  1480. const char *buf, size_t count)
  1481. {
  1482. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1483. int mode;
  1484. int ret;
  1485. ret = kstrtoint(buf, 0, &mode);
  1486. if (ret)
  1487. return ret;
  1488. /* Check for supported modes depending on keyboard backlight type */
  1489. if (toshiba->kbd_type == 1) {
  1490. /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
  1491. if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
  1492. return -EINVAL;
  1493. } else if (toshiba->kbd_type == 2) {
  1494. /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
  1495. if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
  1496. mode != SCI_KBD_MODE_OFF)
  1497. return -EINVAL;
  1498. }
  1499. /*
  1500. * Set the Keyboard Backlight Mode where:
  1501. * Auto - KBD backlight turns off automatically in given time
  1502. * FN-Z - KBD backlight "toggles" when hotkey pressed
  1503. * ON - KBD backlight is always on
  1504. * OFF - KBD backlight is always off
  1505. */
  1506. /* Only make a change if the actual mode has changed */
  1507. if (toshiba->kbd_mode != mode) {
  1508. /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
  1509. int time = toshiba->kbd_time << HCI_MISC_SHIFT;
  1510. /* OR the "base time" to the actual method format */
  1511. if (toshiba->kbd_type == 1) {
  1512. /* Type 1 requires the current mode */
  1513. time |= toshiba->kbd_mode;
  1514. } else if (toshiba->kbd_type == 2) {
  1515. /* Type 2 requires the desired mode */
  1516. time |= mode;
  1517. }
  1518. ret = toshiba_kbd_illum_status_set(toshiba, time);
  1519. if (ret)
  1520. return ret;
  1521. toshiba->kbd_mode = mode;
  1522. /*
  1523. * Some laptop models with the second generation backlit
  1524. * keyboard (type 2) do not generate the keyboard backlight
  1525. * changed event (0x92), and thus, the driver will never update
  1526. * the sysfs entries.
  1527. *
  1528. * The event is generated right when changing the keyboard
  1529. * backlight mode and the *notify function will set the
  1530. * kbd_event_generated to true.
  1531. *
  1532. * In case the event is not generated, schedule the keyboard
  1533. * backlight work to update the sysfs entries and emulate the
  1534. * event via genetlink.
  1535. */
  1536. if (toshiba->kbd_type == 2 &&
  1537. !toshiba_acpi->kbd_event_generated)
  1538. schedule_work(&kbd_bl_work);
  1539. }
  1540. return count;
  1541. }
  1542. static ssize_t kbd_backlight_mode_show(struct device *dev,
  1543. struct device_attribute *attr,
  1544. char *buf)
  1545. {
  1546. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1547. u32 time;
  1548. if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
  1549. return -EIO;
  1550. return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
  1551. }
  1552. static DEVICE_ATTR_RW(kbd_backlight_mode);
  1553. static ssize_t kbd_type_show(struct device *dev,
  1554. struct device_attribute *attr, char *buf)
  1555. {
  1556. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1557. return sprintf(buf, "%d\n", toshiba->kbd_type);
  1558. }
  1559. static DEVICE_ATTR_RO(kbd_type);
  1560. static ssize_t available_kbd_modes_show(struct device *dev,
  1561. struct device_attribute *attr,
  1562. char *buf)
  1563. {
  1564. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1565. if (toshiba->kbd_type == 1)
  1566. return sprintf(buf, "0x%x 0x%x\n",
  1567. SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
  1568. return sprintf(buf, "0x%x 0x%x 0x%x\n",
  1569. SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
  1570. }
  1571. static DEVICE_ATTR_RO(available_kbd_modes);
  1572. static ssize_t kbd_backlight_timeout_store(struct device *dev,
  1573. struct device_attribute *attr,
  1574. const char *buf, size_t count)
  1575. {
  1576. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1577. int time;
  1578. int ret;
  1579. ret = kstrtoint(buf, 0, &time);
  1580. if (ret)
  1581. return ret;
  1582. /* Check for supported values depending on kbd_type */
  1583. if (toshiba->kbd_type == 1) {
  1584. if (time < 0 || time > 60)
  1585. return -EINVAL;
  1586. } else if (toshiba->kbd_type == 2) {
  1587. if (time < 1 || time > 60)
  1588. return -EINVAL;
  1589. }
  1590. /* Set the Keyboard Backlight Timeout */
  1591. /* Only make a change if the actual timeout has changed */
  1592. if (toshiba->kbd_time != time) {
  1593. /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
  1594. time = time << HCI_MISC_SHIFT;
  1595. /* OR the "base time" to the actual method format */
  1596. if (toshiba->kbd_type == 1)
  1597. time |= SCI_KBD_MODE_FNZ;
  1598. else if (toshiba->kbd_type == 2)
  1599. time |= SCI_KBD_MODE_AUTO;
  1600. ret = toshiba_kbd_illum_status_set(toshiba, time);
  1601. if (ret)
  1602. return ret;
  1603. toshiba->kbd_time = time >> HCI_MISC_SHIFT;
  1604. }
  1605. return count;
  1606. }
  1607. static ssize_t kbd_backlight_timeout_show(struct device *dev,
  1608. struct device_attribute *attr,
  1609. char *buf)
  1610. {
  1611. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1612. u32 time;
  1613. if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
  1614. return -EIO;
  1615. return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
  1616. }
  1617. static DEVICE_ATTR_RW(kbd_backlight_timeout);
  1618. static ssize_t touchpad_store(struct device *dev,
  1619. struct device_attribute *attr,
  1620. const char *buf, size_t count)
  1621. {
  1622. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1623. int state;
  1624. int ret;
  1625. /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
  1626. ret = kstrtoint(buf, 0, &state);
  1627. if (ret)
  1628. return ret;
  1629. if (state != 0 && state != 1)
  1630. return -EINVAL;
  1631. ret = toshiba_touchpad_set(toshiba, state);
  1632. if (ret)
  1633. return ret;
  1634. return count;
  1635. }
  1636. static ssize_t touchpad_show(struct device *dev,
  1637. struct device_attribute *attr, char *buf)
  1638. {
  1639. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1640. u32 state;
  1641. int ret;
  1642. ret = toshiba_touchpad_get(toshiba, &state);
  1643. if (ret < 0)
  1644. return ret;
  1645. return sprintf(buf, "%i\n", state);
  1646. }
  1647. static DEVICE_ATTR_RW(touchpad);
  1648. static ssize_t usb_sleep_charge_show(struct device *dev,
  1649. struct device_attribute *attr, char *buf)
  1650. {
  1651. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1652. u32 mode;
  1653. int ret;
  1654. ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
  1655. if (ret < 0)
  1656. return ret;
  1657. return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
  1658. }
  1659. static ssize_t usb_sleep_charge_store(struct device *dev,
  1660. struct device_attribute *attr,
  1661. const char *buf, size_t count)
  1662. {
  1663. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1664. int state;
  1665. u32 mode;
  1666. int ret;
  1667. ret = kstrtoint(buf, 0, &state);
  1668. if (ret)
  1669. return ret;
  1670. /*
  1671. * Check for supported values, where:
  1672. * 0 - Disabled
  1673. * 1 - Alternate (Non USB conformant devices that require more power)
  1674. * 2 - Auto (USB conformant devices)
  1675. * 3 - Typical
  1676. */
  1677. if (state != 0 && state != 1 && state != 2 && state != 3)
  1678. return -EINVAL;
  1679. /* Set the USB charging mode to internal value */
  1680. mode = toshiba->usbsc_mode_base;
  1681. if (state == 0)
  1682. mode |= SCI_USB_CHARGE_DISABLED;
  1683. else if (state == 1)
  1684. mode |= SCI_USB_CHARGE_ALTERNATE;
  1685. else if (state == 2)
  1686. mode |= SCI_USB_CHARGE_AUTO;
  1687. else if (state == 3)
  1688. mode |= SCI_USB_CHARGE_TYPICAL;
  1689. ret = toshiba_usb_sleep_charge_set(toshiba, mode);
  1690. if (ret)
  1691. return ret;
  1692. return count;
  1693. }
  1694. static DEVICE_ATTR_RW(usb_sleep_charge);
  1695. static ssize_t sleep_functions_on_battery_show(struct device *dev,
  1696. struct device_attribute *attr,
  1697. char *buf)
  1698. {
  1699. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1700. int bat_lvl, status;
  1701. u32 state;
  1702. int ret;
  1703. int tmp;
  1704. ret = toshiba_sleep_functions_status_get(toshiba, &state);
  1705. if (ret < 0)
  1706. return ret;
  1707. /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
  1708. tmp = state & SCI_USB_CHARGE_BAT_MASK;
  1709. status = (tmp == 0x4) ? 1 : 0;
  1710. /* Determine the battery level set */
  1711. bat_lvl = state >> HCI_MISC_SHIFT;
  1712. return sprintf(buf, "%d %d\n", status, bat_lvl);
  1713. }
  1714. static ssize_t sleep_functions_on_battery_store(struct device *dev,
  1715. struct device_attribute *attr,
  1716. const char *buf, size_t count)
  1717. {
  1718. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1719. u32 status;
  1720. int value;
  1721. int ret;
  1722. int tmp;
  1723. ret = kstrtoint(buf, 0, &value);
  1724. if (ret)
  1725. return ret;
  1726. /*
  1727. * Set the status of the function:
  1728. * 0 - Disabled
  1729. * 1-100 - Enabled
  1730. */
  1731. if (value < 0 || value > 100)
  1732. return -EINVAL;
  1733. if (value == 0) {
  1734. tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
  1735. status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
  1736. } else {
  1737. tmp = value << HCI_MISC_SHIFT;
  1738. status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
  1739. }
  1740. ret = toshiba_sleep_functions_status_set(toshiba, status);
  1741. if (ret < 0)
  1742. return ret;
  1743. toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
  1744. return count;
  1745. }
  1746. static DEVICE_ATTR_RW(sleep_functions_on_battery);
  1747. static ssize_t usb_rapid_charge_show(struct device *dev,
  1748. struct device_attribute *attr, char *buf)
  1749. {
  1750. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1751. u32 state;
  1752. int ret;
  1753. ret = toshiba_usb_rapid_charge_get(toshiba, &state);
  1754. if (ret < 0)
  1755. return ret;
  1756. return sprintf(buf, "%d\n", state);
  1757. }
  1758. static ssize_t usb_rapid_charge_store(struct device *dev,
  1759. struct device_attribute *attr,
  1760. const char *buf, size_t count)
  1761. {
  1762. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1763. int state;
  1764. int ret;
  1765. ret = kstrtoint(buf, 0, &state);
  1766. if (ret)
  1767. return ret;
  1768. if (state != 0 && state != 1)
  1769. return -EINVAL;
  1770. ret = toshiba_usb_rapid_charge_set(toshiba, state);
  1771. if (ret)
  1772. return ret;
  1773. return count;
  1774. }
  1775. static DEVICE_ATTR_RW(usb_rapid_charge);
  1776. static ssize_t usb_sleep_music_show(struct device *dev,
  1777. struct device_attribute *attr, char *buf)
  1778. {
  1779. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1780. u32 state;
  1781. int ret;
  1782. ret = toshiba_usb_sleep_music_get(toshiba, &state);
  1783. if (ret < 0)
  1784. return ret;
  1785. return sprintf(buf, "%d\n", state);
  1786. }
  1787. static ssize_t usb_sleep_music_store(struct device *dev,
  1788. struct device_attribute *attr,
  1789. const char *buf, size_t count)
  1790. {
  1791. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1792. int state;
  1793. int ret;
  1794. ret = kstrtoint(buf, 0, &state);
  1795. if (ret)
  1796. return ret;
  1797. if (state != 0 && state != 1)
  1798. return -EINVAL;
  1799. ret = toshiba_usb_sleep_music_set(toshiba, state);
  1800. if (ret)
  1801. return ret;
  1802. return count;
  1803. }
  1804. static DEVICE_ATTR_RW(usb_sleep_music);
  1805. static ssize_t kbd_function_keys_show(struct device *dev,
  1806. struct device_attribute *attr, char *buf)
  1807. {
  1808. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1809. int mode;
  1810. int ret;
  1811. ret = toshiba_function_keys_get(toshiba, &mode);
  1812. if (ret < 0)
  1813. return ret;
  1814. return sprintf(buf, "%d\n", mode);
  1815. }
  1816. static ssize_t kbd_function_keys_store(struct device *dev,
  1817. struct device_attribute *attr,
  1818. const char *buf, size_t count)
  1819. {
  1820. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1821. int mode;
  1822. int ret;
  1823. ret = kstrtoint(buf, 0, &mode);
  1824. if (ret)
  1825. return ret;
  1826. /*
  1827. * Check for the function keys mode where:
  1828. * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
  1829. * 1 - Special functions (Opposite of the above setting)
  1830. */
  1831. if (mode != 0 && mode != 1)
  1832. return -EINVAL;
  1833. ret = toshiba_function_keys_set(toshiba, mode);
  1834. if (ret)
  1835. return ret;
  1836. pr_info("Reboot for changes to KBD Function Keys to take effect");
  1837. return count;
  1838. }
  1839. static DEVICE_ATTR_RW(kbd_function_keys);
  1840. static ssize_t panel_power_on_show(struct device *dev,
  1841. struct device_attribute *attr, char *buf)
  1842. {
  1843. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1844. u32 state;
  1845. int ret;
  1846. ret = toshiba_panel_power_on_get(toshiba, &state);
  1847. if (ret < 0)
  1848. return ret;
  1849. return sprintf(buf, "%d\n", state);
  1850. }
  1851. static ssize_t panel_power_on_store(struct device *dev,
  1852. struct device_attribute *attr,
  1853. const char *buf, size_t count)
  1854. {
  1855. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1856. int state;
  1857. int ret;
  1858. ret = kstrtoint(buf, 0, &state);
  1859. if (ret)
  1860. return ret;
  1861. if (state != 0 && state != 1)
  1862. return -EINVAL;
  1863. ret = toshiba_panel_power_on_set(toshiba, state);
  1864. if (ret)
  1865. return ret;
  1866. pr_info("Reboot for changes to Panel Power ON to take effect");
  1867. return count;
  1868. }
  1869. static DEVICE_ATTR_RW(panel_power_on);
  1870. static ssize_t usb_three_show(struct device *dev,
  1871. struct device_attribute *attr, char *buf)
  1872. {
  1873. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1874. u32 state;
  1875. int ret;
  1876. ret = toshiba_usb_three_get(toshiba, &state);
  1877. if (ret < 0)
  1878. return ret;
  1879. return sprintf(buf, "%d\n", state);
  1880. }
  1881. static ssize_t usb_three_store(struct device *dev,
  1882. struct device_attribute *attr,
  1883. const char *buf, size_t count)
  1884. {
  1885. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1886. int state;
  1887. int ret;
  1888. ret = kstrtoint(buf, 0, &state);
  1889. if (ret)
  1890. return ret;
  1891. /*
  1892. * Check for USB 3 mode where:
  1893. * 0 - Disabled (Acts like a USB 2 port, saving power)
  1894. * 1 - Enabled
  1895. */
  1896. if (state != 0 && state != 1)
  1897. return -EINVAL;
  1898. ret = toshiba_usb_three_set(toshiba, state);
  1899. if (ret)
  1900. return ret;
  1901. pr_info("Reboot for changes to USB 3 to take effect");
  1902. return count;
  1903. }
  1904. static DEVICE_ATTR_RW(usb_three);
  1905. static ssize_t cooling_method_show(struct device *dev,
  1906. struct device_attribute *attr, char *buf)
  1907. {
  1908. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1909. int state;
  1910. int ret;
  1911. ret = toshiba_cooling_method_get(toshiba, &state);
  1912. if (ret < 0)
  1913. return ret;
  1914. return sprintf(buf, "%d %d\n", state, toshiba->max_cooling_method);
  1915. }
  1916. static ssize_t cooling_method_store(struct device *dev,
  1917. struct device_attribute *attr,
  1918. const char *buf, size_t count)
  1919. {
  1920. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1921. int state;
  1922. int ret;
  1923. ret = kstrtoint(buf, 0, &state);
  1924. if (ret)
  1925. return ret;
  1926. /*
  1927. * Check for supported values
  1928. * Depending on the laptop model, some only support these two:
  1929. * 0 - Maximum Performance
  1930. * 1 - Battery Optimized
  1931. *
  1932. * While some others support all three methods:
  1933. * 0 - Maximum Performance
  1934. * 1 - Performance
  1935. * 2 - Battery Optimized
  1936. */
  1937. if (state < 0 || state > toshiba->max_cooling_method)
  1938. return -EINVAL;
  1939. ret = toshiba_cooling_method_set(toshiba, state);
  1940. if (ret)
  1941. return ret;
  1942. return count;
  1943. }
  1944. static DEVICE_ATTR_RW(cooling_method);
  1945. static struct attribute *toshiba_attributes[] = {
  1946. &dev_attr_version.attr,
  1947. &dev_attr_fan.attr,
  1948. &dev_attr_kbd_backlight_mode.attr,
  1949. &dev_attr_kbd_type.attr,
  1950. &dev_attr_available_kbd_modes.attr,
  1951. &dev_attr_kbd_backlight_timeout.attr,
  1952. &dev_attr_touchpad.attr,
  1953. &dev_attr_usb_sleep_charge.attr,
  1954. &dev_attr_sleep_functions_on_battery.attr,
  1955. &dev_attr_usb_rapid_charge.attr,
  1956. &dev_attr_usb_sleep_music.attr,
  1957. &dev_attr_kbd_function_keys.attr,
  1958. &dev_attr_panel_power_on.attr,
  1959. &dev_attr_usb_three.attr,
  1960. &dev_attr_cooling_method.attr,
  1961. NULL,
  1962. };
  1963. static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
  1964. struct attribute *attr, int idx)
  1965. {
  1966. struct device *dev = container_of(kobj, struct device, kobj);
  1967. struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
  1968. bool exists = true;
  1969. if (attr == &dev_attr_fan.attr)
  1970. exists = (drv->fan_supported) ? true : false;
  1971. else if (attr == &dev_attr_kbd_backlight_mode.attr)
  1972. exists = (drv->kbd_illum_supported) ? true : false;
  1973. else if (attr == &dev_attr_kbd_backlight_timeout.attr)
  1974. exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
  1975. else if (attr == &dev_attr_touchpad.attr)
  1976. exists = (drv->touchpad_supported) ? true : false;
  1977. else if (attr == &dev_attr_usb_sleep_charge.attr)
  1978. exists = (drv->usb_sleep_charge_supported) ? true : false;
  1979. else if (attr == &dev_attr_sleep_functions_on_battery.attr)
  1980. exists = (drv->usb_sleep_charge_supported) ? true : false;
  1981. else if (attr == &dev_attr_usb_rapid_charge.attr)
  1982. exists = (drv->usb_rapid_charge_supported) ? true : false;
  1983. else if (attr == &dev_attr_usb_sleep_music.attr)
  1984. exists = (drv->usb_sleep_music_supported) ? true : false;
  1985. else if (attr == &dev_attr_kbd_function_keys.attr)
  1986. exists = (drv->kbd_function_keys_supported) ? true : false;
  1987. else if (attr == &dev_attr_panel_power_on.attr)
  1988. exists = (drv->panel_power_on_supported) ? true : false;
  1989. else if (attr == &dev_attr_usb_three.attr)
  1990. exists = (drv->usb_three_supported) ? true : false;
  1991. else if (attr == &dev_attr_cooling_method.attr)
  1992. exists = (drv->cooling_method_supported) ? true : false;
  1993. return exists ? attr->mode : 0;
  1994. }
  1995. static struct attribute_group toshiba_attr_group = {
  1996. .is_visible = toshiba_sysfs_is_visible,
  1997. .attrs = toshiba_attributes,
  1998. };
  1999. static void toshiba_acpi_kbd_bl_work(struct work_struct *work)
  2000. {
  2001. struct acpi_device *acpi_dev = toshiba_acpi->acpi_dev;
  2002. /* Update the sysfs entries */
  2003. if (sysfs_update_group(&acpi_dev->dev.kobj,
  2004. &toshiba_attr_group))
  2005. pr_err("Unable to update sysfs entries\n");
  2006. /* Emulate the keyboard backlight event */
  2007. acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
  2008. dev_name(&acpi_dev->dev),
  2009. 0x92, 0);
  2010. }
  2011. /*
  2012. * IIO device
  2013. */
  2014. enum toshiba_iio_accel_chan {
  2015. AXIS_X,
  2016. AXIS_Y,
  2017. AXIS_Z
  2018. };
  2019. static int toshiba_iio_accel_get_axis(enum toshiba_iio_accel_chan chan)
  2020. {
  2021. u32 xyval, zval;
  2022. int ret;
  2023. ret = toshiba_accelerometer_get(toshiba_acpi, &xyval, &zval);
  2024. if (ret < 0)
  2025. return ret;
  2026. switch (chan) {
  2027. case AXIS_X:
  2028. return xyval & HCI_ACCEL_DIRECTION_MASK ?
  2029. -(xyval & HCI_ACCEL_MASK) : xyval & HCI_ACCEL_MASK;
  2030. case AXIS_Y:
  2031. return (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ?
  2032. -((xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK) :
  2033. (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
  2034. case AXIS_Z:
  2035. return zval & HCI_ACCEL_DIRECTION_MASK ?
  2036. -(zval & HCI_ACCEL_MASK) : zval & HCI_ACCEL_MASK;
  2037. }
  2038. return ret;
  2039. }
  2040. static int toshiba_iio_accel_read_raw(struct iio_dev *indio_dev,
  2041. struct iio_chan_spec const *chan,
  2042. int *val, int *val2, long mask)
  2043. {
  2044. int ret;
  2045. switch (mask) {
  2046. case IIO_CHAN_INFO_RAW:
  2047. ret = toshiba_iio_accel_get_axis(chan->channel);
  2048. if (ret == -EIO || ret == -ENODEV)
  2049. return ret;
  2050. *val = ret;
  2051. return IIO_VAL_INT;
  2052. }
  2053. return -EINVAL;
  2054. }
  2055. #define TOSHIBA_IIO_ACCEL_CHANNEL(axis, chan) { \
  2056. .type = IIO_ACCEL, \
  2057. .modified = 1, \
  2058. .channel = chan, \
  2059. .channel2 = IIO_MOD_##axis, \
  2060. .output = 1, \
  2061. .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
  2062. }
  2063. static const struct iio_chan_spec toshiba_iio_accel_channels[] = {
  2064. TOSHIBA_IIO_ACCEL_CHANNEL(X, AXIS_X),
  2065. TOSHIBA_IIO_ACCEL_CHANNEL(Y, AXIS_Y),
  2066. TOSHIBA_IIO_ACCEL_CHANNEL(Z, AXIS_Z),
  2067. };
  2068. static const struct iio_info toshiba_iio_accel_info = {
  2069. .driver_module = THIS_MODULE,
  2070. .read_raw = &toshiba_iio_accel_read_raw,
  2071. };
  2072. /*
  2073. * Misc device
  2074. */
  2075. static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
  2076. {
  2077. u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
  2078. regs->edx, regs->esi, regs->edi };
  2079. u32 out[TCI_WORDS];
  2080. acpi_status status;
  2081. status = tci_raw(toshiba_acpi, in, out);
  2082. if (ACPI_FAILURE(status)) {
  2083. pr_err("ACPI call to query SMM registers failed\n");
  2084. return -EIO;
  2085. }
  2086. /* Fillout the SMM struct with the TCI call results */
  2087. regs->eax = out[0];
  2088. regs->ebx = out[1];
  2089. regs->ecx = out[2];
  2090. regs->edx = out[3];
  2091. regs->esi = out[4];
  2092. regs->edi = out[5];
  2093. return 0;
  2094. }
  2095. static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
  2096. unsigned long arg)
  2097. {
  2098. SMMRegisters __user *argp = (SMMRegisters __user *)arg;
  2099. SMMRegisters regs;
  2100. int ret;
  2101. if (!argp)
  2102. return -EINVAL;
  2103. switch (cmd) {
  2104. case TOSH_SMM:
  2105. if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
  2106. return -EFAULT;
  2107. ret = toshiba_acpi_smm_bridge(&regs);
  2108. if (ret)
  2109. return ret;
  2110. if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
  2111. return -EFAULT;
  2112. break;
  2113. case TOSHIBA_ACPI_SCI:
  2114. if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
  2115. return -EFAULT;
  2116. /* Ensure we are being called with a SCI_{GET, SET} register */
  2117. if (regs.eax != SCI_GET && regs.eax != SCI_SET)
  2118. return -EINVAL;
  2119. if (!sci_open(toshiba_acpi))
  2120. return -EIO;
  2121. ret = toshiba_acpi_smm_bridge(&regs);
  2122. sci_close(toshiba_acpi);
  2123. if (ret)
  2124. return ret;
  2125. if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
  2126. return -EFAULT;
  2127. break;
  2128. default:
  2129. return -EINVAL;
  2130. }
  2131. return 0;
  2132. }
  2133. static const struct file_operations toshiba_acpi_fops = {
  2134. .owner = THIS_MODULE,
  2135. .unlocked_ioctl = toshiba_acpi_ioctl,
  2136. .llseek = noop_llseek,
  2137. };
  2138. /*
  2139. * WWAN RFKill handlers
  2140. */
  2141. static int toshiba_acpi_wwan_set_block(void *data, bool blocked)
  2142. {
  2143. struct toshiba_acpi_dev *dev = data;
  2144. int ret;
  2145. ret = toshiba_wireless_status(dev);
  2146. if (ret)
  2147. return ret;
  2148. if (!dev->killswitch)
  2149. return 0;
  2150. return toshiba_wwan_set(dev, !blocked);
  2151. }
  2152. static void toshiba_acpi_wwan_poll(struct rfkill *rfkill, void *data)
  2153. {
  2154. struct toshiba_acpi_dev *dev = data;
  2155. if (toshiba_wireless_status(dev))
  2156. return;
  2157. rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
  2158. }
  2159. static const struct rfkill_ops wwan_rfk_ops = {
  2160. .set_block = toshiba_acpi_wwan_set_block,
  2161. .poll = toshiba_acpi_wwan_poll,
  2162. };
  2163. static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev)
  2164. {
  2165. int ret = toshiba_wireless_status(dev);
  2166. if (ret)
  2167. return ret;
  2168. dev->wwan_rfk = rfkill_alloc("Toshiba WWAN",
  2169. &dev->acpi_dev->dev,
  2170. RFKILL_TYPE_WWAN,
  2171. &wwan_rfk_ops,
  2172. dev);
  2173. if (!dev->wwan_rfk) {
  2174. pr_err("Unable to allocate WWAN rfkill device\n");
  2175. return -ENOMEM;
  2176. }
  2177. rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
  2178. ret = rfkill_register(dev->wwan_rfk);
  2179. if (ret) {
  2180. pr_err("Unable to register WWAN rfkill device\n");
  2181. rfkill_destroy(dev->wwan_rfk);
  2182. }
  2183. return ret;
  2184. }
  2185. /*
  2186. * Hotkeys
  2187. */
  2188. static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
  2189. {
  2190. acpi_status status;
  2191. u32 result;
  2192. status = acpi_evaluate_object(dev->acpi_dev->handle,
  2193. "ENAB", NULL, NULL);
  2194. if (ACPI_FAILURE(status))
  2195. return -ENODEV;
  2196. /*
  2197. * Enable the "Special Functions" mode only if they are
  2198. * supported and if they are activated.
  2199. */
  2200. if (dev->kbd_function_keys_supported && dev->special_functions)
  2201. result = hci_write(dev, HCI_HOTKEY_EVENT,
  2202. HCI_HOTKEY_SPECIAL_FUNCTIONS);
  2203. else
  2204. result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
  2205. if (result == TOS_FAILURE)
  2206. return -EIO;
  2207. else if (result == TOS_NOT_SUPPORTED)
  2208. return -ENODEV;
  2209. return 0;
  2210. }
  2211. static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
  2212. struct serio *port)
  2213. {
  2214. if (str & I8042_STR_AUXDATA)
  2215. return false;
  2216. if (unlikely(data == 0xe0))
  2217. return false;
  2218. if ((data & 0x7f) == TOS1900_FN_SCAN) {
  2219. schedule_work(&toshiba_acpi->hotkey_work);
  2220. return true;
  2221. }
  2222. return false;
  2223. }
  2224. static void toshiba_acpi_hotkey_work(struct work_struct *work)
  2225. {
  2226. acpi_handle ec_handle = ec_get_handle();
  2227. acpi_status status;
  2228. if (!ec_handle)
  2229. return;
  2230. status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
  2231. if (ACPI_FAILURE(status))
  2232. pr_err("ACPI NTFY method execution failed\n");
  2233. }
  2234. /*
  2235. * Returns hotkey scancode, or < 0 on failure.
  2236. */
  2237. static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
  2238. {
  2239. unsigned long long value;
  2240. acpi_status status;
  2241. status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
  2242. NULL, &value);
  2243. if (ACPI_FAILURE(status)) {
  2244. pr_err("ACPI INFO method execution failed\n");
  2245. return -EIO;
  2246. }
  2247. return value;
  2248. }
  2249. static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
  2250. int scancode)
  2251. {
  2252. if (scancode == 0x100)
  2253. return;
  2254. /* Act on key press; ignore key release */
  2255. if (scancode & 0x80)
  2256. return;
  2257. if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
  2258. pr_info("Unknown key %x\n", scancode);
  2259. }
  2260. static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
  2261. {
  2262. if (dev->info_supported) {
  2263. int scancode = toshiba_acpi_query_hotkey(dev);
  2264. if (scancode < 0) {
  2265. pr_err("Failed to query hotkey event\n");
  2266. } else if (scancode != 0) {
  2267. toshiba_acpi_report_hotkey(dev, scancode);
  2268. dev->key_event_valid = 1;
  2269. dev->last_key_event = scancode;
  2270. }
  2271. } else if (dev->system_event_supported) {
  2272. u32 result;
  2273. u32 value;
  2274. int retries = 3;
  2275. do {
  2276. result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
  2277. switch (result) {
  2278. case TOS_SUCCESS:
  2279. toshiba_acpi_report_hotkey(dev, (int)value);
  2280. dev->key_event_valid = 1;
  2281. dev->last_key_event = value;
  2282. break;
  2283. case TOS_NOT_SUPPORTED:
  2284. /*
  2285. * This is a workaround for an unresolved
  2286. * issue on some machines where system events
  2287. * sporadically become disabled.
  2288. */
  2289. result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
  2290. if (result == TOS_SUCCESS)
  2291. pr_notice("Re-enabled hotkeys\n");
  2292. /* Fall through */
  2293. default:
  2294. retries--;
  2295. break;
  2296. }
  2297. } while (retries && result != TOS_FIFO_EMPTY);
  2298. }
  2299. }
  2300. static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
  2301. {
  2302. const struct key_entry *keymap = toshiba_acpi_keymap;
  2303. acpi_handle ec_handle;
  2304. int error;
  2305. if (disable_hotkeys) {
  2306. pr_info("Hotkeys disabled by module parameter\n");
  2307. return 0;
  2308. }
  2309. if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
  2310. pr_info("WMI event detected, hotkeys will not be monitored\n");
  2311. return 0;
  2312. }
  2313. error = toshiba_acpi_enable_hotkeys(dev);
  2314. if (error)
  2315. return error;
  2316. if (toshiba_hotkey_event_type_get(dev, &dev->hotkey_event_type))
  2317. pr_notice("Unable to query Hotkey Event Type\n");
  2318. dev->hotkey_dev = input_allocate_device();
  2319. if (!dev->hotkey_dev)
  2320. return -ENOMEM;
  2321. dev->hotkey_dev->name = "Toshiba input device";
  2322. dev->hotkey_dev->phys = "toshiba_acpi/input0";
  2323. dev->hotkey_dev->id.bustype = BUS_HOST;
  2324. if (dev->hotkey_event_type == HCI_SYSTEM_TYPE1 ||
  2325. !dev->kbd_function_keys_supported)
  2326. keymap = toshiba_acpi_keymap;
  2327. else if (dev->hotkey_event_type == HCI_SYSTEM_TYPE2 ||
  2328. dev->kbd_function_keys_supported)
  2329. keymap = toshiba_acpi_alt_keymap;
  2330. else
  2331. pr_info("Unknown event type received %x\n",
  2332. dev->hotkey_event_type);
  2333. error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
  2334. if (error)
  2335. goto err_free_dev;
  2336. /*
  2337. * For some machines the SCI responsible for providing hotkey
  2338. * notification doesn't fire. We can trigger the notification
  2339. * whenever the Fn key is pressed using the NTFY method, if
  2340. * supported, so if it's present set up an i8042 key filter
  2341. * for this purpose.
  2342. */
  2343. ec_handle = ec_get_handle();
  2344. if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
  2345. INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
  2346. error = i8042_install_filter(toshiba_acpi_i8042_filter);
  2347. if (error) {
  2348. pr_err("Error installing key filter\n");
  2349. goto err_free_keymap;
  2350. }
  2351. dev->ntfy_supported = 1;
  2352. }
  2353. /*
  2354. * Determine hotkey query interface. Prefer using the INFO
  2355. * method when it is available.
  2356. */
  2357. if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
  2358. dev->info_supported = 1;
  2359. else if (hci_write(dev, HCI_SYSTEM_EVENT, 1) == TOS_SUCCESS)
  2360. dev->system_event_supported = 1;
  2361. if (!dev->info_supported && !dev->system_event_supported) {
  2362. pr_warn("No hotkey query interface found\n");
  2363. goto err_remove_filter;
  2364. }
  2365. error = input_register_device(dev->hotkey_dev);
  2366. if (error) {
  2367. pr_info("Unable to register input device\n");
  2368. goto err_remove_filter;
  2369. }
  2370. return 0;
  2371. err_remove_filter:
  2372. if (dev->ntfy_supported)
  2373. i8042_remove_filter(toshiba_acpi_i8042_filter);
  2374. err_free_keymap:
  2375. sparse_keymap_free(dev->hotkey_dev);
  2376. err_free_dev:
  2377. input_free_device(dev->hotkey_dev);
  2378. dev->hotkey_dev = NULL;
  2379. return error;
  2380. }
  2381. static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
  2382. {
  2383. struct backlight_properties props;
  2384. int brightness;
  2385. int ret;
  2386. /*
  2387. * Some machines don't support the backlight methods at all, and
  2388. * others support it read-only. Either of these is pretty useless,
  2389. * so only register the backlight device if the backlight method
  2390. * supports both reads and writes.
  2391. */
  2392. brightness = __get_lcd_brightness(dev);
  2393. if (brightness < 0)
  2394. return 0;
  2395. /*
  2396. * If transflective backlight is supported and the brightness is zero
  2397. * (lowest brightness level), the set_lcd_brightness function will
  2398. * activate the transflective backlight, making the LCD appear to be
  2399. * turned off, simply increment the brightness level to avoid that.
  2400. */
  2401. if (dev->tr_backlight_supported && brightness == 0)
  2402. brightness++;
  2403. ret = set_lcd_brightness(dev, brightness);
  2404. if (ret) {
  2405. pr_debug("Backlight method is read-only, disabling backlight support\n");
  2406. return 0;
  2407. }
  2408. /*
  2409. * Tell acpi-video-detect code to prefer vendor backlight on all
  2410. * systems with transflective backlight and on dmi matched systems.
  2411. */
  2412. if (dev->tr_backlight_supported ||
  2413. dmi_check_system(toshiba_vendor_backlight_dmi))
  2414. acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
  2415. if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
  2416. return 0;
  2417. memset(&props, 0, sizeof(props));
  2418. props.type = BACKLIGHT_PLATFORM;
  2419. props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
  2420. /* Adding an extra level and having 0 change to transflective mode */
  2421. if (dev->tr_backlight_supported)
  2422. props.max_brightness++;
  2423. dev->backlight_dev = backlight_device_register("toshiba",
  2424. &dev->acpi_dev->dev,
  2425. dev,
  2426. &toshiba_backlight_data,
  2427. &props);
  2428. if (IS_ERR(dev->backlight_dev)) {
  2429. ret = PTR_ERR(dev->backlight_dev);
  2430. pr_err("Could not register toshiba backlight device\n");
  2431. dev->backlight_dev = NULL;
  2432. return ret;
  2433. }
  2434. dev->backlight_dev->props.brightness = brightness;
  2435. return 0;
  2436. }
  2437. static void print_supported_features(struct toshiba_acpi_dev *dev)
  2438. {
  2439. pr_info("Supported laptop features:");
  2440. if (dev->hotkey_dev)
  2441. pr_cont(" hotkeys");
  2442. if (dev->backlight_dev)
  2443. pr_cont(" backlight");
  2444. if (dev->video_supported)
  2445. pr_cont(" video-out");
  2446. if (dev->fan_supported)
  2447. pr_cont(" fan");
  2448. if (dev->tr_backlight_supported)
  2449. pr_cont(" transflective-backlight");
  2450. if (dev->illumination_supported)
  2451. pr_cont(" illumination");
  2452. if (dev->kbd_illum_supported)
  2453. pr_cont(" keyboard-backlight");
  2454. if (dev->touchpad_supported)
  2455. pr_cont(" touchpad");
  2456. if (dev->eco_supported)
  2457. pr_cont(" eco-led");
  2458. if (dev->accelerometer_supported)
  2459. pr_cont(" accelerometer-axes");
  2460. if (dev->usb_sleep_charge_supported)
  2461. pr_cont(" usb-sleep-charge");
  2462. if (dev->usb_rapid_charge_supported)
  2463. pr_cont(" usb-rapid-charge");
  2464. if (dev->usb_sleep_music_supported)
  2465. pr_cont(" usb-sleep-music");
  2466. if (dev->kbd_function_keys_supported)
  2467. pr_cont(" special-function-keys");
  2468. if (dev->panel_power_on_supported)
  2469. pr_cont(" panel-power-on");
  2470. if (dev->usb_three_supported)
  2471. pr_cont(" usb3");
  2472. if (dev->wwan_supported)
  2473. pr_cont(" wwan");
  2474. if (dev->cooling_method_supported)
  2475. pr_cont(" cooling-method");
  2476. pr_cont("\n");
  2477. }
  2478. static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
  2479. {
  2480. struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
  2481. misc_deregister(&dev->miscdev);
  2482. remove_toshiba_proc_entries(dev);
  2483. if (dev->accelerometer_supported && dev->indio_dev) {
  2484. iio_device_unregister(dev->indio_dev);
  2485. iio_device_free(dev->indio_dev);
  2486. }
  2487. if (dev->sysfs_created)
  2488. sysfs_remove_group(&dev->acpi_dev->dev.kobj,
  2489. &toshiba_attr_group);
  2490. if (dev->ntfy_supported) {
  2491. i8042_remove_filter(toshiba_acpi_i8042_filter);
  2492. cancel_work_sync(&dev->hotkey_work);
  2493. }
  2494. if (dev->hotkey_dev) {
  2495. input_unregister_device(dev->hotkey_dev);
  2496. sparse_keymap_free(dev->hotkey_dev);
  2497. }
  2498. backlight_device_unregister(dev->backlight_dev);
  2499. if (dev->illumination_led_registered)
  2500. led_classdev_unregister(&dev->led_dev);
  2501. if (dev->kbd_led_registered)
  2502. led_classdev_unregister(&dev->kbd_led);
  2503. if (dev->eco_led_registered)
  2504. led_classdev_unregister(&dev->eco_led);
  2505. if (dev->wwan_rfk) {
  2506. rfkill_unregister(dev->wwan_rfk);
  2507. rfkill_destroy(dev->wwan_rfk);
  2508. }
  2509. if (toshiba_acpi)
  2510. toshiba_acpi = NULL;
  2511. kfree(dev);
  2512. return 0;
  2513. }
  2514. static const char *find_hci_method(acpi_handle handle)
  2515. {
  2516. if (acpi_has_method(handle, "GHCI"))
  2517. return "GHCI";
  2518. if (acpi_has_method(handle, "SPFC"))
  2519. return "SPFC";
  2520. return NULL;
  2521. }
  2522. static int toshiba_acpi_add(struct acpi_device *acpi_dev)
  2523. {
  2524. struct toshiba_acpi_dev *dev;
  2525. const char *hci_method;
  2526. u32 dummy;
  2527. int ret = 0;
  2528. if (toshiba_acpi)
  2529. return -EBUSY;
  2530. pr_info("Toshiba Laptop ACPI Extras version %s\n",
  2531. TOSHIBA_ACPI_VERSION);
  2532. hci_method = find_hci_method(acpi_dev->handle);
  2533. if (!hci_method) {
  2534. pr_err("HCI interface not found\n");
  2535. return -ENODEV;
  2536. }
  2537. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  2538. if (!dev)
  2539. return -ENOMEM;
  2540. dev->acpi_dev = acpi_dev;
  2541. dev->method_hci = hci_method;
  2542. dev->miscdev.minor = MISC_DYNAMIC_MINOR;
  2543. dev->miscdev.name = "toshiba_acpi";
  2544. dev->miscdev.fops = &toshiba_acpi_fops;
  2545. ret = misc_register(&dev->miscdev);
  2546. if (ret) {
  2547. pr_err("Failed to register miscdevice\n");
  2548. kfree(dev);
  2549. return ret;
  2550. }
  2551. acpi_dev->driver_data = dev;
  2552. dev_set_drvdata(&acpi_dev->dev, dev);
  2553. /* Query the BIOS for supported features */
  2554. /*
  2555. * The "Special Functions" are always supported by the laptops
  2556. * with the new keyboard layout, query for its presence to help
  2557. * determine the keymap layout to use.
  2558. */
  2559. ret = toshiba_function_keys_get(dev, &dev->special_functions);
  2560. dev->kbd_function_keys_supported = !ret;
  2561. dev->hotkey_event_type = 0;
  2562. if (toshiba_acpi_setup_keyboard(dev))
  2563. pr_info("Unable to activate hotkeys\n");
  2564. /* Determine whether or not BIOS supports transflective backlight */
  2565. ret = get_tr_backlight_status(dev, &dummy);
  2566. dev->tr_backlight_supported = !ret;
  2567. ret = toshiba_acpi_setup_backlight(dev);
  2568. if (ret)
  2569. goto error;
  2570. toshiba_illumination_available(dev);
  2571. if (dev->illumination_supported) {
  2572. dev->led_dev.name = "toshiba::illumination";
  2573. dev->led_dev.max_brightness = 1;
  2574. dev->led_dev.brightness_set = toshiba_illumination_set;
  2575. dev->led_dev.brightness_get = toshiba_illumination_get;
  2576. if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
  2577. dev->illumination_led_registered = true;
  2578. }
  2579. toshiba_eco_mode_available(dev);
  2580. if (dev->eco_supported) {
  2581. dev->eco_led.name = "toshiba::eco_mode";
  2582. dev->eco_led.max_brightness = 1;
  2583. dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
  2584. dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
  2585. if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
  2586. dev->eco_led_registered = true;
  2587. }
  2588. toshiba_kbd_illum_available(dev);
  2589. /*
  2590. * Only register the LED if KBD illumination is supported
  2591. * and the keyboard backlight operation mode is set to FN-Z
  2592. */
  2593. if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
  2594. dev->kbd_led.name = "toshiba::kbd_backlight";
  2595. dev->kbd_led.max_brightness = 1;
  2596. dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
  2597. dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
  2598. if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
  2599. dev->kbd_led_registered = true;
  2600. }
  2601. ret = toshiba_touchpad_get(dev, &dummy);
  2602. dev->touchpad_supported = !ret;
  2603. toshiba_accelerometer_available(dev);
  2604. if (dev->accelerometer_supported) {
  2605. dev->indio_dev = iio_device_alloc(sizeof(*dev));
  2606. if (!dev->indio_dev) {
  2607. pr_err("Unable to allocate iio device\n");
  2608. goto iio_error;
  2609. }
  2610. pr_info("Registering Toshiba accelerometer iio device\n");
  2611. dev->indio_dev->info = &toshiba_iio_accel_info;
  2612. dev->indio_dev->name = "Toshiba accelerometer";
  2613. dev->indio_dev->dev.parent = &acpi_dev->dev;
  2614. dev->indio_dev->modes = INDIO_DIRECT_MODE;
  2615. dev->indio_dev->channels = toshiba_iio_accel_channels;
  2616. dev->indio_dev->num_channels =
  2617. ARRAY_SIZE(toshiba_iio_accel_channels);
  2618. ret = iio_device_register(dev->indio_dev);
  2619. if (ret < 0) {
  2620. pr_err("Unable to register iio device\n");
  2621. iio_device_free(dev->indio_dev);
  2622. }
  2623. }
  2624. iio_error:
  2625. toshiba_usb_sleep_charge_available(dev);
  2626. ret = toshiba_usb_rapid_charge_get(dev, &dummy);
  2627. dev->usb_rapid_charge_supported = !ret;
  2628. ret = toshiba_usb_sleep_music_get(dev, &dummy);
  2629. dev->usb_sleep_music_supported = !ret;
  2630. ret = toshiba_panel_power_on_get(dev, &dummy);
  2631. dev->panel_power_on_supported = !ret;
  2632. ret = toshiba_usb_three_get(dev, &dummy);
  2633. dev->usb_three_supported = !ret;
  2634. ret = get_video_status(dev, &dummy);
  2635. dev->video_supported = !ret;
  2636. ret = get_fan_status(dev, &dummy);
  2637. dev->fan_supported = !ret;
  2638. toshiba_wwan_available(dev);
  2639. if (dev->wwan_supported)
  2640. toshiba_acpi_setup_wwan_rfkill(dev);
  2641. toshiba_cooling_method_available(dev);
  2642. print_supported_features(dev);
  2643. ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
  2644. &toshiba_attr_group);
  2645. if (ret) {
  2646. dev->sysfs_created = 0;
  2647. goto error;
  2648. }
  2649. dev->sysfs_created = !ret;
  2650. create_toshiba_proc_entries(dev);
  2651. toshiba_acpi = dev;
  2652. return 0;
  2653. error:
  2654. toshiba_acpi_remove(acpi_dev);
  2655. return ret;
  2656. }
  2657. static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
  2658. {
  2659. struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
  2660. switch (event) {
  2661. case 0x80: /* Hotkeys and some system events */
  2662. /*
  2663. * Machines with this WMI GUID aren't supported due to bugs in
  2664. * their AML.
  2665. *
  2666. * Return silently to avoid triggering a netlink event.
  2667. */
  2668. if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
  2669. return;
  2670. toshiba_acpi_process_hotkeys(dev);
  2671. break;
  2672. case 0x81: /* Dock events */
  2673. case 0x82:
  2674. case 0x83:
  2675. pr_info("Dock event received %x\n", event);
  2676. break;
  2677. case 0x88: /* Thermal events */
  2678. pr_info("Thermal event received\n");
  2679. break;
  2680. case 0x8f: /* LID closed */
  2681. case 0x90: /* LID is closed and Dock has been ejected */
  2682. break;
  2683. case 0x8c: /* SATA power events */
  2684. case 0x8b:
  2685. pr_info("SATA power event received %x\n", event);
  2686. break;
  2687. case 0x92: /* Keyboard backlight mode changed */
  2688. toshiba_acpi->kbd_event_generated = true;
  2689. /* Update sysfs entries */
  2690. if (sysfs_update_group(&acpi_dev->dev.kobj,
  2691. &toshiba_attr_group))
  2692. pr_err("Unable to update sysfs entries\n");
  2693. break;
  2694. case 0x85: /* Unknown */
  2695. case 0x8d: /* Unknown */
  2696. case 0x8e: /* Unknown */
  2697. case 0x94: /* Unknown */
  2698. case 0x95: /* Unknown */
  2699. default:
  2700. pr_info("Unknown event received %x\n", event);
  2701. break;
  2702. }
  2703. acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
  2704. dev_name(&acpi_dev->dev),
  2705. event, (event == 0x80) ?
  2706. dev->last_key_event : 0);
  2707. }
  2708. #ifdef CONFIG_PM_SLEEP
  2709. static int toshiba_acpi_suspend(struct device *device)
  2710. {
  2711. struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
  2712. if (dev->hotkey_dev) {
  2713. u32 result;
  2714. result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
  2715. if (result != TOS_SUCCESS)
  2716. pr_info("Unable to disable hotkeys\n");
  2717. }
  2718. return 0;
  2719. }
  2720. static int toshiba_acpi_resume(struct device *device)
  2721. {
  2722. struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
  2723. if (dev->hotkey_dev) {
  2724. if (toshiba_acpi_enable_hotkeys(dev))
  2725. pr_info("Unable to re-enable hotkeys\n");
  2726. }
  2727. if (dev->wwan_rfk) {
  2728. if (!toshiba_wireless_status(dev))
  2729. rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
  2730. }
  2731. return 0;
  2732. }
  2733. #endif
  2734. static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
  2735. toshiba_acpi_suspend, toshiba_acpi_resume);
  2736. static struct acpi_driver toshiba_acpi_driver = {
  2737. .name = "Toshiba ACPI driver",
  2738. .owner = THIS_MODULE,
  2739. .ids = toshiba_device_ids,
  2740. .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
  2741. .ops = {
  2742. .add = toshiba_acpi_add,
  2743. .remove = toshiba_acpi_remove,
  2744. .notify = toshiba_acpi_notify,
  2745. },
  2746. .drv.pm = &toshiba_acpi_pm,
  2747. };
  2748. static int __init toshiba_acpi_init(void)
  2749. {
  2750. int ret;
  2751. toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
  2752. if (!toshiba_proc_dir) {
  2753. pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
  2754. return -ENODEV;
  2755. }
  2756. ret = acpi_bus_register_driver(&toshiba_acpi_driver);
  2757. if (ret) {
  2758. pr_err("Failed to register ACPI driver: %d\n", ret);
  2759. remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
  2760. }
  2761. return ret;
  2762. }
  2763. static void __exit toshiba_acpi_exit(void)
  2764. {
  2765. acpi_bus_unregister_driver(&toshiba_acpi_driver);
  2766. if (toshiba_proc_dir)
  2767. remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
  2768. }
  2769. module_init(toshiba_acpi_init);
  2770. module_exit(toshiba_acpi_exit);