toshiba_acpi.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084
  1. /*
  2. * toshiba_acpi.c - Toshiba Laptop ACPI Extras
  3. *
  4. *
  5. * Copyright (C) 2002-2004 John Belmonte
  6. * Copyright (C) 2008 Philip Langdale
  7. * Copyright (C) 2010 Pierre Ducroquet
  8. * Copyright (C) 2014 Azael Avalos
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. *
  25. * The devolpment page for this driver is located at
  26. * http://memebeam.org/toys/ToshibaAcpiDriver.
  27. *
  28. * Credits:
  29. * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
  30. * engineering the Windows drivers
  31. * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
  32. * Rob Miller - TV out and hotkeys help
  33. *
  34. *
  35. * TODO
  36. *
  37. */
  38. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  39. #define TOSHIBA_ACPI_VERSION "0.20"
  40. #define PROC_INTERFACE_VERSION 1
  41. #include <linux/kernel.h>
  42. #include <linux/module.h>
  43. #include <linux/init.h>
  44. #include <linux/types.h>
  45. #include <linux/proc_fs.h>
  46. #include <linux/seq_file.h>
  47. #include <linux/backlight.h>
  48. #include <linux/rfkill.h>
  49. #include <linux/input.h>
  50. #include <linux/input/sparse-keymap.h>
  51. #include <linux/leds.h>
  52. #include <linux/slab.h>
  53. #include <linux/workqueue.h>
  54. #include <linux/i8042.h>
  55. #include <linux/acpi.h>
  56. #include <linux/dmi.h>
  57. #include <asm/uaccess.h>
  58. MODULE_AUTHOR("John Belmonte");
  59. MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
  60. MODULE_LICENSE("GPL");
  61. #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
  62. /* Scan code for Fn key on TOS1900 models */
  63. #define TOS1900_FN_SCAN 0x6e
  64. /* Toshiba ACPI method paths */
  65. #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
  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_OPEN_CLOSE_OK 0x0044
  90. #define TOS_FAILURE 0x1000
  91. #define TOS_NOT_SUPPORTED 0x8000
  92. #define TOS_ALREADY_OPEN 0x8100
  93. #define TOS_NOT_OPENED 0x8200
  94. #define TOS_INPUT_DATA_ERROR 0x8300
  95. #define TOS_WRITE_PROTECTED 0x8400
  96. #define TOS_NOT_PRESENT 0x8600
  97. #define TOS_FIFO_EMPTY 0x8c00
  98. #define TOS_DATA_NOT_AVAILABLE 0x8d20
  99. #define TOS_NOT_INITIALIZED 0x8d50
  100. /* registers */
  101. #define HCI_FAN 0x0004
  102. #define HCI_TR_BACKLIGHT 0x0005
  103. #define HCI_SYSTEM_EVENT 0x0016
  104. #define HCI_VIDEO_OUT 0x001c
  105. #define HCI_HOTKEY_EVENT 0x001e
  106. #define HCI_LCD_BRIGHTNESS 0x002a
  107. #define HCI_WIRELESS 0x0056
  108. #define HCI_ACCELEROMETER 0x006d
  109. #define HCI_KBD_ILLUMINATION 0x0095
  110. #define HCI_ECO_MODE 0x0097
  111. #define HCI_ACCELEROMETER2 0x00a6
  112. #define SCI_ILLUMINATION 0x014e
  113. #define SCI_KBD_ILLUM_STATUS 0x015c
  114. #define SCI_TOUCHPAD 0x050e
  115. /* field definitions */
  116. #define HCI_ACCEL_MASK 0x7fff
  117. #define HCI_HOTKEY_DISABLE 0x0b
  118. #define HCI_HOTKEY_ENABLE 0x09
  119. #define HCI_LCD_BRIGHTNESS_BITS 3
  120. #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
  121. #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
  122. #define HCI_MISC_SHIFT 0x10
  123. #define HCI_VIDEO_OUT_LCD 0x1
  124. #define HCI_VIDEO_OUT_CRT 0x2
  125. #define HCI_VIDEO_OUT_TV 0x4
  126. #define HCI_WIRELESS_KILL_SWITCH 0x01
  127. #define HCI_WIRELESS_BT_PRESENT 0x0f
  128. #define HCI_WIRELESS_BT_ATTACH 0x40
  129. #define HCI_WIRELESS_BT_POWER 0x80
  130. #define SCI_KBD_MODE_MASK 0x1f
  131. #define SCI_KBD_MODE_FNZ 0x1
  132. #define SCI_KBD_MODE_AUTO 0x2
  133. #define SCI_KBD_MODE_ON 0x8
  134. #define SCI_KBD_MODE_OFF 0x10
  135. #define SCI_KBD_TIME_MAX 0x3c001a
  136. struct toshiba_acpi_dev {
  137. struct acpi_device *acpi_dev;
  138. const char *method_hci;
  139. struct rfkill *bt_rfk;
  140. struct input_dev *hotkey_dev;
  141. struct work_struct hotkey_work;
  142. struct backlight_device *backlight_dev;
  143. struct led_classdev led_dev;
  144. struct led_classdev kbd_led;
  145. struct led_classdev eco_led;
  146. int force_fan;
  147. int last_key_event;
  148. int key_event_valid;
  149. int kbd_type;
  150. int kbd_mode;
  151. int kbd_time;
  152. unsigned int illumination_supported:1;
  153. unsigned int video_supported:1;
  154. unsigned int fan_supported:1;
  155. unsigned int system_event_supported:1;
  156. unsigned int ntfy_supported:1;
  157. unsigned int info_supported:1;
  158. unsigned int tr_backlight_supported:1;
  159. unsigned int kbd_illum_supported:1;
  160. unsigned int kbd_led_registered:1;
  161. unsigned int touchpad_supported:1;
  162. unsigned int eco_supported:1;
  163. unsigned int accelerometer_supported:1;
  164. unsigned int sysfs_created:1;
  165. struct mutex mutex;
  166. };
  167. static struct toshiba_acpi_dev *toshiba_acpi;
  168. static const struct acpi_device_id toshiba_device_ids[] = {
  169. {"TOS6200", 0},
  170. {"TOS6208", 0},
  171. {"TOS1900", 0},
  172. {"", 0},
  173. };
  174. MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
  175. static const struct key_entry toshiba_acpi_keymap[] = {
  176. { KE_KEY, 0x9e, { KEY_RFKILL } },
  177. { KE_KEY, 0x101, { KEY_MUTE } },
  178. { KE_KEY, 0x102, { KEY_ZOOMOUT } },
  179. { KE_KEY, 0x103, { KEY_ZOOMIN } },
  180. { KE_KEY, 0x10f, { KEY_TAB } },
  181. { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
  182. { KE_KEY, 0x139, { KEY_ZOOMRESET } },
  183. { KE_KEY, 0x13b, { KEY_COFFEE } },
  184. { KE_KEY, 0x13c, { KEY_BATTERY } },
  185. { KE_KEY, 0x13d, { KEY_SLEEP } },
  186. { KE_KEY, 0x13e, { KEY_SUSPEND } },
  187. { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
  188. { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
  189. { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
  190. { KE_KEY, 0x142, { KEY_WLAN } },
  191. { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
  192. { KE_KEY, 0x17f, { KEY_FN } },
  193. { KE_KEY, 0xb05, { KEY_PROG2 } },
  194. { KE_KEY, 0xb06, { KEY_WWW } },
  195. { KE_KEY, 0xb07, { KEY_MAIL } },
  196. { KE_KEY, 0xb30, { KEY_STOP } },
  197. { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
  198. { KE_KEY, 0xb32, { KEY_NEXTSONG } },
  199. { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
  200. { KE_KEY, 0xb5a, { KEY_MEDIA } },
  201. { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
  202. { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
  203. { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
  204. { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
  205. { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
  206. { KE_END, 0 },
  207. };
  208. /* alternative keymap */
  209. static const struct dmi_system_id toshiba_alt_keymap_dmi[] = {
  210. {
  211. .matches = {
  212. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  213. DMI_MATCH(DMI_PRODUCT_NAME, "Satellite M840"),
  214. },
  215. },
  216. {
  217. .matches = {
  218. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  219. DMI_MATCH(DMI_PRODUCT_NAME, "Qosmio X75-A"),
  220. },
  221. },
  222. {}
  223. };
  224. static const struct key_entry toshiba_acpi_alt_keymap[] = {
  225. { KE_KEY, 0x157, { KEY_MUTE } },
  226. { KE_KEY, 0x102, { KEY_ZOOMOUT } },
  227. { KE_KEY, 0x103, { KEY_ZOOMIN } },
  228. { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
  229. { KE_KEY, 0x139, { KEY_ZOOMRESET } },
  230. { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
  231. { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
  232. { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
  233. { KE_KEY, 0x158, { KEY_WLAN } },
  234. { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
  235. { KE_END, 0 },
  236. };
  237. /* utility
  238. */
  239. static __inline__ void _set_bit(u32 * word, u32 mask, int value)
  240. {
  241. *word = (*word & ~mask) | (mask * value);
  242. }
  243. /* acpi interface wrappers
  244. */
  245. static int write_acpi_int(const char *methodName, int val)
  246. {
  247. acpi_status status;
  248. status = acpi_execute_simple_method(NULL, (char *)methodName, val);
  249. return (status == AE_OK) ? 0 : -EIO;
  250. }
  251. /* Perform a raw configuration call. Here we don't care about input or output
  252. * buffer format.
  253. */
  254. static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
  255. const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
  256. {
  257. struct acpi_object_list params;
  258. union acpi_object in_objs[TCI_WORDS];
  259. struct acpi_buffer results;
  260. union acpi_object out_objs[TCI_WORDS + 1];
  261. acpi_status status;
  262. int i;
  263. params.count = TCI_WORDS;
  264. params.pointer = in_objs;
  265. for (i = 0; i < TCI_WORDS; ++i) {
  266. in_objs[i].type = ACPI_TYPE_INTEGER;
  267. in_objs[i].integer.value = in[i];
  268. }
  269. results.length = sizeof(out_objs);
  270. results.pointer = out_objs;
  271. status = acpi_evaluate_object(dev->acpi_dev->handle,
  272. (char *)dev->method_hci, &params,
  273. &results);
  274. if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
  275. for (i = 0; i < out_objs->package.count; ++i) {
  276. out[i] = out_objs->package.elements[i].integer.value;
  277. }
  278. }
  279. return status;
  280. }
  281. /* common hci tasks (get or set one or two value)
  282. *
  283. * In addition to the ACPI status, the HCI system returns a result which
  284. * may be useful (such as "not supported").
  285. */
  286. static u32 hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
  287. {
  288. u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
  289. u32 out[TCI_WORDS];
  290. acpi_status status = tci_raw(dev, in, out);
  291. return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
  292. }
  293. static u32 hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
  294. {
  295. u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
  296. u32 out[TCI_WORDS];
  297. acpi_status status = tci_raw(dev, in, out);
  298. if (ACPI_FAILURE(status))
  299. return TOS_FAILURE;
  300. *out1 = out[2];
  301. return out[0];
  302. }
  303. static u32 hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2)
  304. {
  305. u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
  306. u32 out[TCI_WORDS];
  307. acpi_status status = tci_raw(dev, in, out);
  308. return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
  309. }
  310. static u32 hci_read2(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1, u32 *out2)
  311. {
  312. u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
  313. u32 out[TCI_WORDS];
  314. acpi_status status = tci_raw(dev, in, out);
  315. if (ACPI_FAILURE(status))
  316. return TOS_FAILURE;
  317. *out1 = out[2];
  318. *out2 = out[3];
  319. return out[0];
  320. }
  321. /* common sci tasks
  322. */
  323. static int sci_open(struct toshiba_acpi_dev *dev)
  324. {
  325. u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
  326. u32 out[TCI_WORDS];
  327. acpi_status status;
  328. status = tci_raw(dev, in, out);
  329. if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
  330. pr_err("ACPI call to open SCI failed\n");
  331. return 0;
  332. }
  333. if (out[0] == TOS_OPEN_CLOSE_OK) {
  334. return 1;
  335. } else if (out[0] == TOS_ALREADY_OPEN) {
  336. pr_info("Toshiba SCI already opened\n");
  337. return 1;
  338. } else if (out[0] == TOS_NOT_PRESENT) {
  339. pr_info("Toshiba SCI is not present\n");
  340. }
  341. return 0;
  342. }
  343. static void sci_close(struct toshiba_acpi_dev *dev)
  344. {
  345. u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
  346. u32 out[TCI_WORDS];
  347. acpi_status status;
  348. status = tci_raw(dev, in, out);
  349. if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
  350. pr_err("ACPI call to close SCI failed\n");
  351. return;
  352. }
  353. if (out[0] == TOS_OPEN_CLOSE_OK)
  354. return;
  355. else if (out[0] == TOS_NOT_OPENED)
  356. pr_info("Toshiba SCI not opened\n");
  357. else if (out[0] == TOS_NOT_PRESENT)
  358. pr_info("Toshiba SCI is not present\n");
  359. }
  360. static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
  361. {
  362. u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
  363. u32 out[TCI_WORDS];
  364. acpi_status status = tci_raw(dev, in, out);
  365. if (ACPI_FAILURE(status))
  366. return TOS_FAILURE;
  367. *out1 = out[2];
  368. return out[0];
  369. }
  370. static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
  371. {
  372. u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
  373. u32 out[TCI_WORDS];
  374. acpi_status status = tci_raw(dev, in, out);
  375. return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
  376. }
  377. /* Illumination support */
  378. static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
  379. {
  380. u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
  381. u32 out[TCI_WORDS];
  382. acpi_status status;
  383. if (!sci_open(dev))
  384. return 0;
  385. status = tci_raw(dev, in, out);
  386. sci_close(dev);
  387. if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
  388. pr_err("ACPI call to query Illumination support failed\n");
  389. return 0;
  390. } else if (out[0] == TOS_NOT_SUPPORTED) {
  391. pr_info("Illumination device not available\n");
  392. return 0;
  393. }
  394. return 1;
  395. }
  396. static void toshiba_illumination_set(struct led_classdev *cdev,
  397. enum led_brightness brightness)
  398. {
  399. struct toshiba_acpi_dev *dev = container_of(cdev,
  400. struct toshiba_acpi_dev, led_dev);
  401. u32 state, result;
  402. /* First request : initialize communication. */
  403. if (!sci_open(dev))
  404. return;
  405. /* Switch the illumination on/off */
  406. state = brightness ? 1 : 0;
  407. result = sci_write(dev, SCI_ILLUMINATION, state);
  408. sci_close(dev);
  409. if (result == TOS_FAILURE) {
  410. pr_err("ACPI call for illumination failed\n");
  411. return;
  412. } else if (result == TOS_NOT_SUPPORTED) {
  413. pr_info("Illumination not supported\n");
  414. return;
  415. }
  416. }
  417. static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
  418. {
  419. struct toshiba_acpi_dev *dev = container_of(cdev,
  420. struct toshiba_acpi_dev, led_dev);
  421. u32 state, result;
  422. /* First request : initialize communication. */
  423. if (!sci_open(dev))
  424. return LED_OFF;
  425. /* Check the illumination */
  426. result = sci_read(dev, SCI_ILLUMINATION, &state);
  427. sci_close(dev);
  428. if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
  429. pr_err("ACPI call for illumination failed\n");
  430. return LED_OFF;
  431. } else if (result == TOS_NOT_SUPPORTED) {
  432. pr_info("Illumination not supported\n");
  433. return LED_OFF;
  434. }
  435. return state ? LED_FULL : LED_OFF;
  436. }
  437. /* KBD Illumination */
  438. static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
  439. {
  440. u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
  441. u32 out[TCI_WORDS];
  442. acpi_status status;
  443. if (!sci_open(dev))
  444. return 0;
  445. status = tci_raw(dev, in, out);
  446. sci_close(dev);
  447. if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
  448. pr_err("ACPI call to query kbd illumination support failed\n");
  449. return 0;
  450. } else if (out[0] == TOS_NOT_SUPPORTED) {
  451. pr_info("Keyboard illumination not available\n");
  452. return 0;
  453. }
  454. /* Check for keyboard backlight timeout max value,
  455. * previous kbd backlight implementation set this to
  456. * 0x3c0003, and now the new implementation set this
  457. * to 0x3c001a, use this to distinguish between them
  458. */
  459. if (out[3] == SCI_KBD_TIME_MAX)
  460. dev->kbd_type = 2;
  461. else
  462. dev->kbd_type = 1;
  463. /* Get the current keyboard backlight mode */
  464. dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
  465. /* Get the current time (1-60 seconds) */
  466. dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
  467. return 1;
  468. }
  469. static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
  470. {
  471. u32 result;
  472. if (!sci_open(dev))
  473. return -EIO;
  474. result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
  475. sci_close(dev);
  476. if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
  477. pr_err("ACPI call to set KBD backlight status failed\n");
  478. return -EIO;
  479. } else if (result == TOS_NOT_SUPPORTED) {
  480. pr_info("Keyboard backlight status not supported\n");
  481. return -ENODEV;
  482. }
  483. return 0;
  484. }
  485. static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
  486. {
  487. u32 result;
  488. if (!sci_open(dev))
  489. return -EIO;
  490. result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
  491. sci_close(dev);
  492. if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
  493. pr_err("ACPI call to get KBD backlight status failed\n");
  494. return -EIO;
  495. } else if (result == TOS_NOT_SUPPORTED) {
  496. pr_info("Keyboard backlight status not supported\n");
  497. return -ENODEV;
  498. }
  499. return 0;
  500. }
  501. static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
  502. {
  503. struct toshiba_acpi_dev *dev = container_of(cdev,
  504. struct toshiba_acpi_dev, kbd_led);
  505. u32 state, result;
  506. /* Check the keyboard backlight state */
  507. result = hci_read1(dev, HCI_KBD_ILLUMINATION, &state);
  508. if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
  509. pr_err("ACPI call to get the keyboard backlight failed\n");
  510. return LED_OFF;
  511. } else if (result == TOS_NOT_SUPPORTED) {
  512. pr_info("Keyboard backlight not supported\n");
  513. return LED_OFF;
  514. }
  515. return state ? LED_FULL : LED_OFF;
  516. }
  517. static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
  518. enum led_brightness brightness)
  519. {
  520. struct toshiba_acpi_dev *dev = container_of(cdev,
  521. struct toshiba_acpi_dev, kbd_led);
  522. u32 state, result;
  523. /* Set the keyboard backlight state */
  524. state = brightness ? 1 : 0;
  525. result = hci_write1(dev, HCI_KBD_ILLUMINATION, state);
  526. if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
  527. pr_err("ACPI call to set KBD Illumination mode failed\n");
  528. return;
  529. } else if (result == TOS_NOT_SUPPORTED) {
  530. pr_info("Keyboard backlight not supported\n");
  531. return;
  532. }
  533. }
  534. /* TouchPad support */
  535. static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
  536. {
  537. u32 result;
  538. if (!sci_open(dev))
  539. return -EIO;
  540. result = sci_write(dev, SCI_TOUCHPAD, state);
  541. sci_close(dev);
  542. if (result == TOS_FAILURE) {
  543. pr_err("ACPI call to set the touchpad failed\n");
  544. return -EIO;
  545. } else if (result == TOS_NOT_SUPPORTED) {
  546. return -ENODEV;
  547. }
  548. return 0;
  549. }
  550. static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
  551. {
  552. u32 result;
  553. if (!sci_open(dev))
  554. return -EIO;
  555. result = sci_read(dev, SCI_TOUCHPAD, state);
  556. sci_close(dev);
  557. if (result == TOS_FAILURE) {
  558. pr_err("ACPI call to query the touchpad failed\n");
  559. return -EIO;
  560. } else if (result == TOS_NOT_SUPPORTED) {
  561. return -ENODEV;
  562. }
  563. return 0;
  564. }
  565. /* Eco Mode support */
  566. static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
  567. {
  568. acpi_status status;
  569. u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
  570. u32 out[TCI_WORDS];
  571. status = tci_raw(dev, in, out);
  572. if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
  573. pr_info("ACPI call to get ECO led failed\n");
  574. return 0;
  575. }
  576. return 1;
  577. }
  578. static enum led_brightness toshiba_eco_mode_get_status(struct led_classdev *cdev)
  579. {
  580. struct toshiba_acpi_dev *dev = container_of(cdev,
  581. struct toshiba_acpi_dev, eco_led);
  582. u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
  583. u32 out[TCI_WORDS];
  584. acpi_status status;
  585. status = tci_raw(dev, in, out);
  586. if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
  587. pr_err("ACPI call to get ECO led failed\n");
  588. return LED_OFF;
  589. }
  590. return out[2] ? LED_FULL : LED_OFF;
  591. }
  592. static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
  593. enum led_brightness brightness)
  594. {
  595. struct toshiba_acpi_dev *dev = container_of(cdev,
  596. struct toshiba_acpi_dev, eco_led);
  597. u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
  598. u32 out[TCI_WORDS];
  599. acpi_status status;
  600. /* Switch the Eco Mode led on/off */
  601. in[2] = (brightness) ? 1 : 0;
  602. status = tci_raw(dev, in, out);
  603. if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
  604. pr_err("ACPI call to set ECO led failed\n");
  605. return;
  606. }
  607. }
  608. /* Accelerometer support */
  609. static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
  610. {
  611. u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
  612. u32 out[TCI_WORDS];
  613. acpi_status status;
  614. /* Check if the accelerometer call exists,
  615. * this call also serves as initialization
  616. */
  617. status = tci_raw(dev, in, out);
  618. if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
  619. pr_err("ACPI call to query the accelerometer failed\n");
  620. return -EIO;
  621. } else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
  622. out[0] == TOS_NOT_INITIALIZED) {
  623. pr_err("Accelerometer not initialized\n");
  624. return -EIO;
  625. } else if (out[0] == TOS_NOT_SUPPORTED) {
  626. pr_info("Accelerometer not supported\n");
  627. return -ENODEV;
  628. }
  629. return 0;
  630. }
  631. static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
  632. u32 *xy, u32 *z)
  633. {
  634. u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
  635. u32 out[TCI_WORDS];
  636. acpi_status status;
  637. /* Check the Accelerometer status */
  638. status = tci_raw(dev, in, out);
  639. if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
  640. pr_err("ACPI call to query the accelerometer failed\n");
  641. return -EIO;
  642. }
  643. *xy = out[2];
  644. *z = out[4];
  645. return 0;
  646. }
  647. /* Bluetooth rfkill handlers */
  648. static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
  649. {
  650. u32 hci_result;
  651. u32 value, value2;
  652. value = 0;
  653. value2 = 0;
  654. hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
  655. if (hci_result == TOS_SUCCESS)
  656. *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
  657. return hci_result;
  658. }
  659. static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
  660. {
  661. u32 hci_result;
  662. u32 value, value2;
  663. value = 0;
  664. value2 = 0x0001;
  665. hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
  666. *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
  667. return hci_result;
  668. }
  669. static int bt_rfkill_set_block(void *data, bool blocked)
  670. {
  671. struct toshiba_acpi_dev *dev = data;
  672. u32 result1, result2;
  673. u32 value;
  674. int err;
  675. bool radio_state;
  676. value = (blocked == false);
  677. mutex_lock(&dev->mutex);
  678. if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) {
  679. err = -EIO;
  680. goto out;
  681. }
  682. if (!radio_state) {
  683. err = 0;
  684. goto out;
  685. }
  686. result1 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER);
  687. result2 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH);
  688. if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS)
  689. err = -EIO;
  690. else
  691. err = 0;
  692. out:
  693. mutex_unlock(&dev->mutex);
  694. return err;
  695. }
  696. static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
  697. {
  698. bool new_rfk_state;
  699. bool value;
  700. u32 hci_result;
  701. struct toshiba_acpi_dev *dev = data;
  702. mutex_lock(&dev->mutex);
  703. hci_result = hci_get_radio_state(dev, &value);
  704. if (hci_result != TOS_SUCCESS) {
  705. /* Can't do anything useful */
  706. mutex_unlock(&dev->mutex);
  707. return;
  708. }
  709. new_rfk_state = value;
  710. mutex_unlock(&dev->mutex);
  711. if (rfkill_set_hw_state(rfkill, !new_rfk_state))
  712. bt_rfkill_set_block(data, true);
  713. }
  714. static const struct rfkill_ops toshiba_rfk_ops = {
  715. .set_block = bt_rfkill_set_block,
  716. .poll = bt_rfkill_poll,
  717. };
  718. static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
  719. {
  720. u32 hci_result;
  721. u32 status;
  722. hci_result = hci_read1(dev, HCI_TR_BACKLIGHT, &status);
  723. *enabled = !status;
  724. return hci_result == TOS_SUCCESS ? 0 : -EIO;
  725. }
  726. static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
  727. {
  728. u32 hci_result;
  729. u32 value = !enable;
  730. hci_result = hci_write1(dev, HCI_TR_BACKLIGHT, value);
  731. return hci_result == TOS_SUCCESS ? 0 : -EIO;
  732. }
  733. static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
  734. static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
  735. {
  736. u32 hci_result;
  737. u32 value;
  738. int brightness = 0;
  739. if (dev->tr_backlight_supported) {
  740. bool enabled;
  741. int ret = get_tr_backlight_status(dev, &enabled);
  742. if (ret)
  743. return ret;
  744. if (enabled)
  745. return 0;
  746. brightness++;
  747. }
  748. hci_result = hci_read1(dev, HCI_LCD_BRIGHTNESS, &value);
  749. if (hci_result == TOS_SUCCESS)
  750. return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
  751. return -EIO;
  752. }
  753. static int get_lcd_brightness(struct backlight_device *bd)
  754. {
  755. struct toshiba_acpi_dev *dev = bl_get_data(bd);
  756. return __get_lcd_brightness(dev);
  757. }
  758. static int lcd_proc_show(struct seq_file *m, void *v)
  759. {
  760. struct toshiba_acpi_dev *dev = m->private;
  761. int value;
  762. int levels;
  763. if (!dev->backlight_dev)
  764. return -ENODEV;
  765. levels = dev->backlight_dev->props.max_brightness + 1;
  766. value = get_lcd_brightness(dev->backlight_dev);
  767. if (value >= 0) {
  768. seq_printf(m, "brightness: %d\n", value);
  769. seq_printf(m, "brightness_levels: %d\n", levels);
  770. return 0;
  771. }
  772. pr_err("Error reading LCD brightness\n");
  773. return -EIO;
  774. }
  775. static int lcd_proc_open(struct inode *inode, struct file *file)
  776. {
  777. return single_open(file, lcd_proc_show, PDE_DATA(inode));
  778. }
  779. static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
  780. {
  781. u32 in[TCI_WORDS] = { HCI_SET, HCI_LCD_BRIGHTNESS, 0, 0, 0, 0 };
  782. u32 out[TCI_WORDS];
  783. acpi_status status;
  784. if (dev->tr_backlight_supported) {
  785. bool enable = !value;
  786. int ret = set_tr_backlight_status(dev, enable);
  787. if (ret)
  788. return ret;
  789. if (value)
  790. value--;
  791. }
  792. in[2] = value << HCI_LCD_BRIGHTNESS_SHIFT;
  793. status = tci_raw(dev, in, out);
  794. if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
  795. pr_err("ACPI call to set brightness failed");
  796. return -EIO;
  797. }
  798. /* Extra check for "incomplete" backlight method, where the AML code
  799. * doesn't check for HCI_SET or HCI_GET and returns TOS_SUCCESS,
  800. * the actual brightness, and in some cases the max brightness.
  801. */
  802. if (out[2] > 0 || out[3] == 0xE000)
  803. return -ENODEV;
  804. return out[0] == TOS_SUCCESS ? 0 : -EIO;
  805. }
  806. static int set_lcd_status(struct backlight_device *bd)
  807. {
  808. struct toshiba_acpi_dev *dev = bl_get_data(bd);
  809. return set_lcd_brightness(dev, bd->props.brightness);
  810. }
  811. static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
  812. size_t count, loff_t *pos)
  813. {
  814. struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  815. char cmd[42];
  816. size_t len;
  817. int value;
  818. int ret;
  819. int levels = dev->backlight_dev->props.max_brightness + 1;
  820. len = min(count, sizeof(cmd) - 1);
  821. if (copy_from_user(cmd, buf, len))
  822. return -EFAULT;
  823. cmd[len] = '\0';
  824. if (sscanf(cmd, " brightness : %i", &value) == 1 &&
  825. value >= 0 && value < levels) {
  826. ret = set_lcd_brightness(dev, value);
  827. if (ret == 0)
  828. ret = count;
  829. } else {
  830. ret = -EINVAL;
  831. }
  832. return ret;
  833. }
  834. static const struct file_operations lcd_proc_fops = {
  835. .owner = THIS_MODULE,
  836. .open = lcd_proc_open,
  837. .read = seq_read,
  838. .llseek = seq_lseek,
  839. .release = single_release,
  840. .write = lcd_proc_write,
  841. };
  842. static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
  843. {
  844. u32 hci_result;
  845. hci_result = hci_read1(dev, HCI_VIDEO_OUT, status);
  846. return hci_result == TOS_SUCCESS ? 0 : -EIO;
  847. }
  848. static int video_proc_show(struct seq_file *m, void *v)
  849. {
  850. struct toshiba_acpi_dev *dev = m->private;
  851. u32 value;
  852. int ret;
  853. ret = get_video_status(dev, &value);
  854. if (!ret) {
  855. int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
  856. int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
  857. int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
  858. seq_printf(m, "lcd_out: %d\n", is_lcd);
  859. seq_printf(m, "crt_out: %d\n", is_crt);
  860. seq_printf(m, "tv_out: %d\n", is_tv);
  861. }
  862. return ret;
  863. }
  864. static int video_proc_open(struct inode *inode, struct file *file)
  865. {
  866. return single_open(file, video_proc_show, PDE_DATA(inode));
  867. }
  868. static ssize_t video_proc_write(struct file *file, const char __user *buf,
  869. size_t count, loff_t *pos)
  870. {
  871. struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  872. char *cmd, *buffer;
  873. int ret;
  874. int value;
  875. int remain = count;
  876. int lcd_out = -1;
  877. int crt_out = -1;
  878. int tv_out = -1;
  879. u32 video_out;
  880. cmd = kmalloc(count + 1, GFP_KERNEL);
  881. if (!cmd)
  882. return -ENOMEM;
  883. if (copy_from_user(cmd, buf, count)) {
  884. kfree(cmd);
  885. return -EFAULT;
  886. }
  887. cmd[count] = '\0';
  888. buffer = cmd;
  889. /* scan expression. Multiple expressions may be delimited with ;
  890. *
  891. * NOTE: to keep scanning simple, invalid fields are ignored
  892. */
  893. while (remain) {
  894. if (sscanf(buffer, " lcd_out : %i", &value) == 1)
  895. lcd_out = value & 1;
  896. else if (sscanf(buffer, " crt_out : %i", &value) == 1)
  897. crt_out = value & 1;
  898. else if (sscanf(buffer, " tv_out : %i", &value) == 1)
  899. tv_out = value & 1;
  900. /* advance to one character past the next ; */
  901. do {
  902. ++buffer;
  903. --remain;
  904. }
  905. while (remain && *(buffer - 1) != ';');
  906. }
  907. kfree(cmd);
  908. ret = get_video_status(dev, &video_out);
  909. if (!ret) {
  910. unsigned int new_video_out = video_out;
  911. if (lcd_out != -1)
  912. _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
  913. if (crt_out != -1)
  914. _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
  915. if (tv_out != -1)
  916. _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
  917. /* To avoid unnecessary video disruption, only write the new
  918. * video setting if something changed. */
  919. if (new_video_out != video_out)
  920. ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
  921. }
  922. return ret ? ret : count;
  923. }
  924. static const struct file_operations video_proc_fops = {
  925. .owner = THIS_MODULE,
  926. .open = video_proc_open,
  927. .read = seq_read,
  928. .llseek = seq_lseek,
  929. .release = single_release,
  930. .write = video_proc_write,
  931. };
  932. static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
  933. {
  934. u32 hci_result;
  935. hci_result = hci_read1(dev, HCI_FAN, status);
  936. return hci_result == TOS_SUCCESS ? 0 : -EIO;
  937. }
  938. static int fan_proc_show(struct seq_file *m, void *v)
  939. {
  940. struct toshiba_acpi_dev *dev = m->private;
  941. int ret;
  942. u32 value;
  943. ret = get_fan_status(dev, &value);
  944. if (!ret) {
  945. seq_printf(m, "running: %d\n", (value > 0));
  946. seq_printf(m, "force_on: %d\n", dev->force_fan);
  947. }
  948. return ret;
  949. }
  950. static int fan_proc_open(struct inode *inode, struct file *file)
  951. {
  952. return single_open(file, fan_proc_show, PDE_DATA(inode));
  953. }
  954. static ssize_t fan_proc_write(struct file *file, const char __user *buf,
  955. size_t count, loff_t *pos)
  956. {
  957. struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  958. char cmd[42];
  959. size_t len;
  960. int value;
  961. u32 hci_result;
  962. len = min(count, sizeof(cmd) - 1);
  963. if (copy_from_user(cmd, buf, len))
  964. return -EFAULT;
  965. cmd[len] = '\0';
  966. if (sscanf(cmd, " force_on : %i", &value) == 1 &&
  967. value >= 0 && value <= 1) {
  968. hci_result = hci_write1(dev, HCI_FAN, value);
  969. if (hci_result != TOS_SUCCESS)
  970. return -EIO;
  971. else
  972. dev->force_fan = value;
  973. } else {
  974. return -EINVAL;
  975. }
  976. return count;
  977. }
  978. static const struct file_operations fan_proc_fops = {
  979. .owner = THIS_MODULE,
  980. .open = fan_proc_open,
  981. .read = seq_read,
  982. .llseek = seq_lseek,
  983. .release = single_release,
  984. .write = fan_proc_write,
  985. };
  986. static int keys_proc_show(struct seq_file *m, void *v)
  987. {
  988. struct toshiba_acpi_dev *dev = m->private;
  989. u32 hci_result;
  990. u32 value;
  991. if (!dev->key_event_valid && dev->system_event_supported) {
  992. hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
  993. if (hci_result == TOS_SUCCESS) {
  994. dev->key_event_valid = 1;
  995. dev->last_key_event = value;
  996. } else if (hci_result == TOS_FIFO_EMPTY) {
  997. /* better luck next time */
  998. } else if (hci_result == TOS_NOT_SUPPORTED) {
  999. /* This is a workaround for an unresolved issue on
  1000. * some machines where system events sporadically
  1001. * become disabled. */
  1002. hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
  1003. pr_notice("Re-enabled hotkeys\n");
  1004. } else {
  1005. pr_err("Error reading hotkey status\n");
  1006. return -EIO;
  1007. }
  1008. }
  1009. seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
  1010. seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
  1011. return 0;
  1012. }
  1013. static int keys_proc_open(struct inode *inode, struct file *file)
  1014. {
  1015. return single_open(file, keys_proc_show, PDE_DATA(inode));
  1016. }
  1017. static ssize_t keys_proc_write(struct file *file, const char __user *buf,
  1018. size_t count, loff_t *pos)
  1019. {
  1020. struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  1021. char cmd[42];
  1022. size_t len;
  1023. int value;
  1024. len = min(count, sizeof(cmd) - 1);
  1025. if (copy_from_user(cmd, buf, len))
  1026. return -EFAULT;
  1027. cmd[len] = '\0';
  1028. if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
  1029. dev->key_event_valid = 0;
  1030. } else {
  1031. return -EINVAL;
  1032. }
  1033. return count;
  1034. }
  1035. static const struct file_operations keys_proc_fops = {
  1036. .owner = THIS_MODULE,
  1037. .open = keys_proc_open,
  1038. .read = seq_read,
  1039. .llseek = seq_lseek,
  1040. .release = single_release,
  1041. .write = keys_proc_write,
  1042. };
  1043. static int version_proc_show(struct seq_file *m, void *v)
  1044. {
  1045. seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
  1046. seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
  1047. return 0;
  1048. }
  1049. static int version_proc_open(struct inode *inode, struct file *file)
  1050. {
  1051. return single_open(file, version_proc_show, PDE_DATA(inode));
  1052. }
  1053. static const struct file_operations version_proc_fops = {
  1054. .owner = THIS_MODULE,
  1055. .open = version_proc_open,
  1056. .read = seq_read,
  1057. .llseek = seq_lseek,
  1058. .release = single_release,
  1059. };
  1060. /* proc and module init
  1061. */
  1062. #define PROC_TOSHIBA "toshiba"
  1063. static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
  1064. {
  1065. if (dev->backlight_dev)
  1066. proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1067. &lcd_proc_fops, dev);
  1068. if (dev->video_supported)
  1069. proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1070. &video_proc_fops, dev);
  1071. if (dev->fan_supported)
  1072. proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1073. &fan_proc_fops, dev);
  1074. if (dev->hotkey_dev)
  1075. proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1076. &keys_proc_fops, dev);
  1077. proc_create_data("version", S_IRUGO, toshiba_proc_dir,
  1078. &version_proc_fops, dev);
  1079. }
  1080. static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
  1081. {
  1082. if (dev->backlight_dev)
  1083. remove_proc_entry("lcd", toshiba_proc_dir);
  1084. if (dev->video_supported)
  1085. remove_proc_entry("video", toshiba_proc_dir);
  1086. if (dev->fan_supported)
  1087. remove_proc_entry("fan", toshiba_proc_dir);
  1088. if (dev->hotkey_dev)
  1089. remove_proc_entry("keys", toshiba_proc_dir);
  1090. remove_proc_entry("version", toshiba_proc_dir);
  1091. }
  1092. static const struct backlight_ops toshiba_backlight_data = {
  1093. .options = BL_CORE_SUSPENDRESUME,
  1094. .get_brightness = get_lcd_brightness,
  1095. .update_status = set_lcd_status,
  1096. };
  1097. /*
  1098. * Sysfs files
  1099. */
  1100. static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
  1101. struct device_attribute *attr,
  1102. const char *buf, size_t count);
  1103. static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
  1104. struct device_attribute *attr,
  1105. char *buf);
  1106. static ssize_t toshiba_kbd_type_show(struct device *dev,
  1107. struct device_attribute *attr,
  1108. char *buf);
  1109. static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
  1110. struct device_attribute *attr,
  1111. char *buf);
  1112. static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
  1113. struct device_attribute *attr,
  1114. const char *buf, size_t count);
  1115. static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
  1116. struct device_attribute *attr,
  1117. char *buf);
  1118. static ssize_t toshiba_touchpad_store(struct device *dev,
  1119. struct device_attribute *attr,
  1120. const char *buf, size_t count);
  1121. static ssize_t toshiba_touchpad_show(struct device *dev,
  1122. struct device_attribute *attr,
  1123. char *buf);
  1124. static ssize_t toshiba_position_show(struct device *dev,
  1125. struct device_attribute *attr,
  1126. char *buf);
  1127. static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
  1128. toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
  1129. static DEVICE_ATTR(kbd_type, S_IRUGO, toshiba_kbd_type_show, NULL);
  1130. static DEVICE_ATTR(available_kbd_modes, S_IRUGO,
  1131. toshiba_available_kbd_modes_show, NULL);
  1132. static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR,
  1133. toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store);
  1134. static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
  1135. toshiba_touchpad_show, toshiba_touchpad_store);
  1136. static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
  1137. static struct attribute *toshiba_attributes[] = {
  1138. &dev_attr_kbd_backlight_mode.attr,
  1139. &dev_attr_kbd_type.attr,
  1140. &dev_attr_available_kbd_modes.attr,
  1141. &dev_attr_kbd_backlight_timeout.attr,
  1142. &dev_attr_touchpad.attr,
  1143. &dev_attr_position.attr,
  1144. NULL,
  1145. };
  1146. static umode_t toshiba_sysfs_is_visible(struct kobject *,
  1147. struct attribute *, int);
  1148. static struct attribute_group toshiba_attr_group = {
  1149. .is_visible = toshiba_sysfs_is_visible,
  1150. .attrs = toshiba_attributes,
  1151. };
  1152. static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
  1153. struct device_attribute *attr,
  1154. const char *buf, size_t count)
  1155. {
  1156. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1157. int mode;
  1158. int time;
  1159. int ret;
  1160. ret = kstrtoint(buf, 0, &mode);
  1161. if (ret)
  1162. return ret;
  1163. /* Check for supported modes depending on keyboard backlight type */
  1164. if (toshiba->kbd_type == 1) {
  1165. /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
  1166. if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
  1167. return -EINVAL;
  1168. } else if (toshiba->kbd_type == 2) {
  1169. /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
  1170. if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
  1171. mode != SCI_KBD_MODE_OFF)
  1172. return -EINVAL;
  1173. }
  1174. /* Set the Keyboard Backlight Mode where:
  1175. * Auto - KBD backlight turns off automatically in given time
  1176. * FN-Z - KBD backlight "toggles" when hotkey pressed
  1177. * ON - KBD backlight is always on
  1178. * OFF - KBD backlight is always off
  1179. */
  1180. /* Only make a change if the actual mode has changed */
  1181. if (toshiba->kbd_mode != mode) {
  1182. /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
  1183. time = toshiba->kbd_time << HCI_MISC_SHIFT;
  1184. /* OR the "base time" to the actual method format */
  1185. if (toshiba->kbd_type == 1) {
  1186. /* Type 1 requires the current mode */
  1187. time |= toshiba->kbd_mode;
  1188. } else if (toshiba->kbd_type == 2) {
  1189. /* Type 2 requires the desired mode */
  1190. time |= mode;
  1191. }
  1192. ret = toshiba_kbd_illum_status_set(toshiba, time);
  1193. if (ret)
  1194. return ret;
  1195. /* Update sysfs entries on successful mode change*/
  1196. ret = sysfs_update_group(&toshiba->acpi_dev->dev.kobj,
  1197. &toshiba_attr_group);
  1198. if (ret)
  1199. return ret;
  1200. toshiba->kbd_mode = mode;
  1201. }
  1202. return count;
  1203. }
  1204. static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
  1205. struct device_attribute *attr,
  1206. char *buf)
  1207. {
  1208. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1209. u32 time;
  1210. if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
  1211. return -EIO;
  1212. return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
  1213. }
  1214. static ssize_t toshiba_kbd_type_show(struct device *dev,
  1215. struct device_attribute *attr,
  1216. char *buf)
  1217. {
  1218. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1219. return sprintf(buf, "%d\n", toshiba->kbd_type);
  1220. }
  1221. static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
  1222. struct device_attribute *attr,
  1223. char *buf)
  1224. {
  1225. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1226. if (toshiba->kbd_type == 1)
  1227. return sprintf(buf, "%x %x\n",
  1228. SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
  1229. return sprintf(buf, "%x %x %x\n",
  1230. SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
  1231. }
  1232. static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
  1233. struct device_attribute *attr,
  1234. const char *buf, size_t count)
  1235. {
  1236. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1237. int time;
  1238. int ret;
  1239. ret = kstrtoint(buf, 0, &time);
  1240. if (ret)
  1241. return ret;
  1242. /* Check for supported values depending on kbd_type */
  1243. if (toshiba->kbd_type == 1) {
  1244. if (time < 0 || time > 60)
  1245. return -EINVAL;
  1246. } else if (toshiba->kbd_type == 2) {
  1247. if (time < 1 || time > 60)
  1248. return -EINVAL;
  1249. }
  1250. /* Set the Keyboard Backlight Timeout */
  1251. /* Only make a change if the actual timeout has changed */
  1252. if (toshiba->kbd_time != time) {
  1253. /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
  1254. time = time << HCI_MISC_SHIFT;
  1255. /* OR the "base time" to the actual method format */
  1256. if (toshiba->kbd_type == 1)
  1257. time |= SCI_KBD_MODE_FNZ;
  1258. else if (toshiba->kbd_type == 2)
  1259. time |= SCI_KBD_MODE_AUTO;
  1260. ret = toshiba_kbd_illum_status_set(toshiba, time);
  1261. if (ret)
  1262. return ret;
  1263. toshiba->kbd_time = time >> HCI_MISC_SHIFT;
  1264. }
  1265. return count;
  1266. }
  1267. static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
  1268. struct device_attribute *attr,
  1269. char *buf)
  1270. {
  1271. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1272. u32 time;
  1273. if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
  1274. return -EIO;
  1275. return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
  1276. }
  1277. static ssize_t toshiba_touchpad_store(struct device *dev,
  1278. struct device_attribute *attr,
  1279. const char *buf, size_t count)
  1280. {
  1281. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1282. int state;
  1283. int ret;
  1284. /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
  1285. ret = kstrtoint(buf, 0, &state);
  1286. if (ret)
  1287. return ret;
  1288. if (state != 0 && state != 1)
  1289. return -EINVAL;
  1290. ret = toshiba_touchpad_set(toshiba, state);
  1291. if (ret)
  1292. return ret;
  1293. return count;
  1294. }
  1295. static ssize_t toshiba_touchpad_show(struct device *dev,
  1296. struct device_attribute *attr, char *buf)
  1297. {
  1298. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1299. u32 state;
  1300. int ret;
  1301. ret = toshiba_touchpad_get(toshiba, &state);
  1302. if (ret < 0)
  1303. return ret;
  1304. return sprintf(buf, "%i\n", state);
  1305. }
  1306. static ssize_t toshiba_position_show(struct device *dev,
  1307. struct device_attribute *attr, char *buf)
  1308. {
  1309. struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1310. u32 xyval, zval, tmp;
  1311. u16 x, y, z;
  1312. int ret;
  1313. xyval = zval = 0;
  1314. ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
  1315. if (ret < 0)
  1316. return ret;
  1317. x = xyval & HCI_ACCEL_MASK;
  1318. tmp = xyval >> HCI_MISC_SHIFT;
  1319. y = tmp & HCI_ACCEL_MASK;
  1320. z = zval & HCI_ACCEL_MASK;
  1321. return sprintf(buf, "%d %d %d\n", x, y, z);
  1322. }
  1323. static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
  1324. struct attribute *attr, int idx)
  1325. {
  1326. struct device *dev = container_of(kobj, struct device, kobj);
  1327. struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
  1328. bool exists = true;
  1329. if (attr == &dev_attr_kbd_backlight_mode.attr)
  1330. exists = (drv->kbd_illum_supported) ? true : false;
  1331. else if (attr == &dev_attr_kbd_backlight_timeout.attr)
  1332. exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
  1333. else if (attr == &dev_attr_touchpad.attr)
  1334. exists = (drv->touchpad_supported) ? true : false;
  1335. else if (attr == &dev_attr_position.attr)
  1336. exists = (drv->accelerometer_supported) ? true : false;
  1337. return exists ? attr->mode : 0;
  1338. }
  1339. static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
  1340. struct serio *port)
  1341. {
  1342. if (str & 0x20)
  1343. return false;
  1344. if (unlikely(data == 0xe0))
  1345. return false;
  1346. if ((data & 0x7f) == TOS1900_FN_SCAN) {
  1347. schedule_work(&toshiba_acpi->hotkey_work);
  1348. return true;
  1349. }
  1350. return false;
  1351. }
  1352. static void toshiba_acpi_hotkey_work(struct work_struct *work)
  1353. {
  1354. acpi_handle ec_handle = ec_get_handle();
  1355. acpi_status status;
  1356. if (!ec_handle)
  1357. return;
  1358. status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
  1359. if (ACPI_FAILURE(status))
  1360. pr_err("ACPI NTFY method execution failed\n");
  1361. }
  1362. /*
  1363. * Returns hotkey scancode, or < 0 on failure.
  1364. */
  1365. static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
  1366. {
  1367. unsigned long long value;
  1368. acpi_status status;
  1369. status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
  1370. NULL, &value);
  1371. if (ACPI_FAILURE(status)) {
  1372. pr_err("ACPI INFO method execution failed\n");
  1373. return -EIO;
  1374. }
  1375. return value;
  1376. }
  1377. static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
  1378. int scancode)
  1379. {
  1380. if (scancode == 0x100)
  1381. return;
  1382. /* act on key press; ignore key release */
  1383. if (scancode & 0x80)
  1384. return;
  1385. if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
  1386. pr_info("Unknown key %x\n", scancode);
  1387. }
  1388. static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
  1389. {
  1390. acpi_status status;
  1391. acpi_handle ec_handle;
  1392. int error;
  1393. u32 hci_result;
  1394. const struct key_entry *keymap = toshiba_acpi_keymap;
  1395. dev->hotkey_dev = input_allocate_device();
  1396. if (!dev->hotkey_dev)
  1397. return -ENOMEM;
  1398. dev->hotkey_dev->name = "Toshiba input device";
  1399. dev->hotkey_dev->phys = "toshiba_acpi/input0";
  1400. dev->hotkey_dev->id.bustype = BUS_HOST;
  1401. if (dmi_check_system(toshiba_alt_keymap_dmi))
  1402. keymap = toshiba_acpi_alt_keymap;
  1403. error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
  1404. if (error)
  1405. goto err_free_dev;
  1406. /*
  1407. * For some machines the SCI responsible for providing hotkey
  1408. * notification doesn't fire. We can trigger the notification
  1409. * whenever the Fn key is pressed using the NTFY method, if
  1410. * supported, so if it's present set up an i8042 key filter
  1411. * for this purpose.
  1412. */
  1413. status = AE_ERROR;
  1414. ec_handle = ec_get_handle();
  1415. if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
  1416. INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
  1417. error = i8042_install_filter(toshiba_acpi_i8042_filter);
  1418. if (error) {
  1419. pr_err("Error installing key filter\n");
  1420. goto err_free_keymap;
  1421. }
  1422. dev->ntfy_supported = 1;
  1423. }
  1424. /*
  1425. * Determine hotkey query interface. Prefer using the INFO
  1426. * method when it is available.
  1427. */
  1428. if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
  1429. dev->info_supported = 1;
  1430. else {
  1431. hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
  1432. if (hci_result == TOS_SUCCESS)
  1433. dev->system_event_supported = 1;
  1434. }
  1435. if (!dev->info_supported && !dev->system_event_supported) {
  1436. pr_warn("No hotkey query interface found\n");
  1437. goto err_remove_filter;
  1438. }
  1439. status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, NULL);
  1440. if (ACPI_FAILURE(status)) {
  1441. pr_info("Unable to enable hotkeys\n");
  1442. error = -ENODEV;
  1443. goto err_remove_filter;
  1444. }
  1445. error = input_register_device(dev->hotkey_dev);
  1446. if (error) {
  1447. pr_info("Unable to register input device\n");
  1448. goto err_remove_filter;
  1449. }
  1450. hci_result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
  1451. return 0;
  1452. err_remove_filter:
  1453. if (dev->ntfy_supported)
  1454. i8042_remove_filter(toshiba_acpi_i8042_filter);
  1455. err_free_keymap:
  1456. sparse_keymap_free(dev->hotkey_dev);
  1457. err_free_dev:
  1458. input_free_device(dev->hotkey_dev);
  1459. dev->hotkey_dev = NULL;
  1460. return error;
  1461. }
  1462. static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
  1463. {
  1464. struct backlight_properties props;
  1465. int brightness;
  1466. int ret;
  1467. bool enabled;
  1468. /*
  1469. * Some machines don't support the backlight methods at all, and
  1470. * others support it read-only. Either of these is pretty useless,
  1471. * so only register the backlight device if the backlight method
  1472. * supports both reads and writes.
  1473. */
  1474. brightness = __get_lcd_brightness(dev);
  1475. if (brightness < 0)
  1476. return 0;
  1477. ret = set_lcd_brightness(dev, brightness);
  1478. if (ret) {
  1479. pr_debug("Backlight method is read-only, disabling backlight support\n");
  1480. return 0;
  1481. }
  1482. /* Determine whether or not BIOS supports transflective backlight */
  1483. ret = get_tr_backlight_status(dev, &enabled);
  1484. dev->tr_backlight_supported = !ret;
  1485. memset(&props, 0, sizeof(props));
  1486. props.type = BACKLIGHT_PLATFORM;
  1487. props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
  1488. /* adding an extra level and having 0 change to transflective mode */
  1489. if (dev->tr_backlight_supported)
  1490. props.max_brightness++;
  1491. dev->backlight_dev = backlight_device_register("toshiba",
  1492. &dev->acpi_dev->dev,
  1493. dev,
  1494. &toshiba_backlight_data,
  1495. &props);
  1496. if (IS_ERR(dev->backlight_dev)) {
  1497. ret = PTR_ERR(dev->backlight_dev);
  1498. pr_err("Could not register toshiba backlight device\n");
  1499. dev->backlight_dev = NULL;
  1500. return ret;
  1501. }
  1502. dev->backlight_dev->props.brightness = brightness;
  1503. return 0;
  1504. }
  1505. static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
  1506. {
  1507. struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
  1508. remove_toshiba_proc_entries(dev);
  1509. if (dev->sysfs_created)
  1510. sysfs_remove_group(&dev->acpi_dev->dev.kobj,
  1511. &toshiba_attr_group);
  1512. if (dev->ntfy_supported) {
  1513. i8042_remove_filter(toshiba_acpi_i8042_filter);
  1514. cancel_work_sync(&dev->hotkey_work);
  1515. }
  1516. if (dev->hotkey_dev) {
  1517. input_unregister_device(dev->hotkey_dev);
  1518. sparse_keymap_free(dev->hotkey_dev);
  1519. }
  1520. if (dev->bt_rfk) {
  1521. rfkill_unregister(dev->bt_rfk);
  1522. rfkill_destroy(dev->bt_rfk);
  1523. }
  1524. if (dev->backlight_dev)
  1525. backlight_device_unregister(dev->backlight_dev);
  1526. if (dev->illumination_supported)
  1527. led_classdev_unregister(&dev->led_dev);
  1528. if (dev->kbd_led_registered)
  1529. led_classdev_unregister(&dev->kbd_led);
  1530. if (dev->eco_supported)
  1531. led_classdev_unregister(&dev->eco_led);
  1532. if (toshiba_acpi)
  1533. toshiba_acpi = NULL;
  1534. kfree(dev);
  1535. return 0;
  1536. }
  1537. static const char *find_hci_method(acpi_handle handle)
  1538. {
  1539. if (acpi_has_method(handle, "GHCI"))
  1540. return "GHCI";
  1541. if (acpi_has_method(handle, "SPFC"))
  1542. return "SPFC";
  1543. return NULL;
  1544. }
  1545. static int toshiba_acpi_add(struct acpi_device *acpi_dev)
  1546. {
  1547. struct toshiba_acpi_dev *dev;
  1548. const char *hci_method;
  1549. u32 dummy;
  1550. bool bt_present;
  1551. int ret = 0;
  1552. if (toshiba_acpi)
  1553. return -EBUSY;
  1554. pr_info("Toshiba Laptop ACPI Extras version %s\n",
  1555. TOSHIBA_ACPI_VERSION);
  1556. hci_method = find_hci_method(acpi_dev->handle);
  1557. if (!hci_method) {
  1558. pr_err("HCI interface not found\n");
  1559. return -ENODEV;
  1560. }
  1561. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  1562. if (!dev)
  1563. return -ENOMEM;
  1564. dev->acpi_dev = acpi_dev;
  1565. dev->method_hci = hci_method;
  1566. acpi_dev->driver_data = dev;
  1567. dev_set_drvdata(&acpi_dev->dev, dev);
  1568. if (toshiba_acpi_setup_keyboard(dev))
  1569. pr_info("Unable to activate hotkeys\n");
  1570. mutex_init(&dev->mutex);
  1571. ret = toshiba_acpi_setup_backlight(dev);
  1572. if (ret)
  1573. goto error;
  1574. /* Register rfkill switch for Bluetooth */
  1575. if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) {
  1576. dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
  1577. &acpi_dev->dev,
  1578. RFKILL_TYPE_BLUETOOTH,
  1579. &toshiba_rfk_ops,
  1580. dev);
  1581. if (!dev->bt_rfk) {
  1582. pr_err("unable to allocate rfkill device\n");
  1583. ret = -ENOMEM;
  1584. goto error;
  1585. }
  1586. ret = rfkill_register(dev->bt_rfk);
  1587. if (ret) {
  1588. pr_err("unable to register rfkill device\n");
  1589. rfkill_destroy(dev->bt_rfk);
  1590. goto error;
  1591. }
  1592. }
  1593. if (toshiba_illumination_available(dev)) {
  1594. dev->led_dev.name = "toshiba::illumination";
  1595. dev->led_dev.max_brightness = 1;
  1596. dev->led_dev.brightness_set = toshiba_illumination_set;
  1597. dev->led_dev.brightness_get = toshiba_illumination_get;
  1598. if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
  1599. dev->illumination_supported = 1;
  1600. }
  1601. if (toshiba_eco_mode_available(dev)) {
  1602. dev->eco_led.name = "toshiba::eco_mode";
  1603. dev->eco_led.max_brightness = 1;
  1604. dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
  1605. dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
  1606. if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
  1607. dev->eco_supported = 1;
  1608. }
  1609. dev->kbd_illum_supported = toshiba_kbd_illum_available(dev);
  1610. /*
  1611. * Only register the LED if KBD illumination is supported
  1612. * and the keyboard backlight operation mode is set to FN-Z
  1613. */
  1614. if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
  1615. dev->kbd_led.name = "toshiba::kbd_backlight";
  1616. dev->kbd_led.max_brightness = 1;
  1617. dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
  1618. dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
  1619. if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
  1620. dev->kbd_led_registered = 1;
  1621. }
  1622. ret = toshiba_touchpad_get(dev, &dummy);
  1623. dev->touchpad_supported = !ret;
  1624. ret = toshiba_accelerometer_supported(dev);
  1625. dev->accelerometer_supported = !ret;
  1626. /* Determine whether or not BIOS supports fan and video interfaces */
  1627. ret = get_video_status(dev, &dummy);
  1628. dev->video_supported = !ret;
  1629. ret = get_fan_status(dev, &dummy);
  1630. dev->fan_supported = !ret;
  1631. ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
  1632. &toshiba_attr_group);
  1633. if (ret) {
  1634. dev->sysfs_created = 0;
  1635. goto error;
  1636. }
  1637. dev->sysfs_created = !ret;
  1638. create_toshiba_proc_entries(dev);
  1639. toshiba_acpi = dev;
  1640. return 0;
  1641. error:
  1642. toshiba_acpi_remove(acpi_dev);
  1643. return ret;
  1644. }
  1645. static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
  1646. {
  1647. struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
  1648. u32 hci_result, value;
  1649. int retries = 3;
  1650. int scancode;
  1651. if (event != 0x80)
  1652. return;
  1653. if (dev->info_supported) {
  1654. scancode = toshiba_acpi_query_hotkey(dev);
  1655. if (scancode < 0)
  1656. pr_err("Failed to query hotkey event\n");
  1657. else if (scancode != 0)
  1658. toshiba_acpi_report_hotkey(dev, scancode);
  1659. } else if (dev->system_event_supported) {
  1660. do {
  1661. hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
  1662. switch (hci_result) {
  1663. case TOS_SUCCESS:
  1664. toshiba_acpi_report_hotkey(dev, (int)value);
  1665. break;
  1666. case TOS_NOT_SUPPORTED:
  1667. /*
  1668. * This is a workaround for an unresolved
  1669. * issue on some machines where system events
  1670. * sporadically become disabled.
  1671. */
  1672. hci_result =
  1673. hci_write1(dev, HCI_SYSTEM_EVENT, 1);
  1674. pr_notice("Re-enabled hotkeys\n");
  1675. /* fall through */
  1676. default:
  1677. retries--;
  1678. break;
  1679. }
  1680. } while (retries && hci_result != TOS_FIFO_EMPTY);
  1681. }
  1682. }
  1683. #ifdef CONFIG_PM_SLEEP
  1684. static int toshiba_acpi_suspend(struct device *device)
  1685. {
  1686. struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
  1687. u32 result;
  1688. if (dev->hotkey_dev)
  1689. result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
  1690. return 0;
  1691. }
  1692. static int toshiba_acpi_resume(struct device *device)
  1693. {
  1694. struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
  1695. u32 result;
  1696. acpi_status status;
  1697. if (dev->hotkey_dev) {
  1698. status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB",
  1699. NULL, NULL);
  1700. if (ACPI_FAILURE(status))
  1701. pr_info("Unable to re-enable hotkeys\n");
  1702. result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
  1703. }
  1704. return 0;
  1705. }
  1706. #endif
  1707. static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
  1708. toshiba_acpi_suspend, toshiba_acpi_resume);
  1709. static struct acpi_driver toshiba_acpi_driver = {
  1710. .name = "Toshiba ACPI driver",
  1711. .owner = THIS_MODULE,
  1712. .ids = toshiba_device_ids,
  1713. .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
  1714. .ops = {
  1715. .add = toshiba_acpi_add,
  1716. .remove = toshiba_acpi_remove,
  1717. .notify = toshiba_acpi_notify,
  1718. },
  1719. .drv.pm = &toshiba_acpi_pm,
  1720. };
  1721. static int __init toshiba_acpi_init(void)
  1722. {
  1723. int ret;
  1724. /*
  1725. * Machines with this WMI guid aren't supported due to bugs in
  1726. * their AML. This check relies on wmi initializing before
  1727. * toshiba_acpi to guarantee guids have been identified.
  1728. */
  1729. if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
  1730. return -ENODEV;
  1731. toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
  1732. if (!toshiba_proc_dir) {
  1733. pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
  1734. return -ENODEV;
  1735. }
  1736. ret = acpi_bus_register_driver(&toshiba_acpi_driver);
  1737. if (ret) {
  1738. pr_err("Failed to register ACPI driver: %d\n", ret);
  1739. remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
  1740. }
  1741. return ret;
  1742. }
  1743. static void __exit toshiba_acpi_exit(void)
  1744. {
  1745. acpi_bus_unregister_driver(&toshiba_acpi_driver);
  1746. if (toshiba_proc_dir)
  1747. remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
  1748. }
  1749. module_init(toshiba_acpi_init);
  1750. module_exit(toshiba_acpi_exit);