toshiba_acpi.c 49 KB

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