toshiba_acpi.c 80 KB

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