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