toshiba_acpi.c 48 KB

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