toshiba_acpi.c 88 KB

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