toshiba_acpi.c 82 KB

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