dell-laptop.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. /*
  2. * Driver for Dell laptop extras
  3. *
  4. * Copyright (c) Red Hat <mjg@redhat.com>
  5. *
  6. * Based on documentation in the libsmbios package, Copyright (C) 2005 Dell
  7. * Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/backlight.h>
  19. #include <linux/err.h>
  20. #include <linux/dmi.h>
  21. #include <linux/io.h>
  22. #include <linux/rfkill.h>
  23. #include <linux/power_supply.h>
  24. #include <linux/acpi.h>
  25. #include <linux/mm.h>
  26. #include <linux/i8042.h>
  27. #include <linux/slab.h>
  28. #include <linux/debugfs.h>
  29. #include <linux/seq_file.h>
  30. #include "../../firmware/dcdbas.h"
  31. #define BRIGHTNESS_TOKEN 0x7d
  32. /* This structure will be modified by the firmware when we enter
  33. * system management mode, hence the volatiles */
  34. struct calling_interface_buffer {
  35. u16 class;
  36. u16 select;
  37. volatile u32 input[4];
  38. volatile u32 output[4];
  39. } __packed;
  40. struct calling_interface_token {
  41. u16 tokenID;
  42. u16 location;
  43. union {
  44. u16 value;
  45. u16 stringlength;
  46. };
  47. };
  48. struct calling_interface_structure {
  49. struct dmi_header header;
  50. u16 cmdIOAddress;
  51. u8 cmdIOCode;
  52. u32 supportedCmds;
  53. struct calling_interface_token tokens[];
  54. } __packed;
  55. struct quirk_entry {
  56. u8 touchpad_led;
  57. };
  58. static struct quirk_entry *quirks;
  59. static struct quirk_entry quirk_dell_vostro_v130 = {
  60. .touchpad_led = 1,
  61. };
  62. static int dmi_matched(const struct dmi_system_id *dmi)
  63. {
  64. quirks = dmi->driver_data;
  65. return 1;
  66. }
  67. static int da_command_address;
  68. static int da_command_code;
  69. static int da_num_tokens;
  70. static struct calling_interface_token *da_tokens;
  71. static struct platform_driver platform_driver = {
  72. .driver = {
  73. .name = "dell-laptop",
  74. .owner = THIS_MODULE,
  75. }
  76. };
  77. static struct platform_device *platform_device;
  78. static struct backlight_device *dell_backlight_device;
  79. static struct rfkill *wifi_rfkill;
  80. static struct rfkill *bluetooth_rfkill;
  81. static struct rfkill *wwan_rfkill;
  82. static const struct dmi_system_id dell_device_table[] __initconst = {
  83. {
  84. .ident = "Dell laptop",
  85. .matches = {
  86. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  87. DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
  88. },
  89. },
  90. {
  91. .matches = {
  92. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  93. DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /*Laptop*/
  94. },
  95. },
  96. {
  97. .ident = "Dell Computer Corporation",
  98. .matches = {
  99. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
  100. DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
  101. },
  102. },
  103. { }
  104. };
  105. MODULE_DEVICE_TABLE(dmi, dell_device_table);
  106. static struct dmi_system_id __devinitdata dell_blacklist[] = {
  107. /* Supported by compal-laptop */
  108. {
  109. .ident = "Dell Mini 9",
  110. .matches = {
  111. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  112. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
  113. },
  114. },
  115. {
  116. .ident = "Dell Mini 10",
  117. .matches = {
  118. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  119. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"),
  120. },
  121. },
  122. {
  123. .ident = "Dell Mini 10v",
  124. .matches = {
  125. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  126. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"),
  127. },
  128. },
  129. {
  130. .ident = "Dell Mini 1012",
  131. .matches = {
  132. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  133. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1012"),
  134. },
  135. },
  136. {
  137. .ident = "Dell Inspiron 11z",
  138. .matches = {
  139. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  140. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"),
  141. },
  142. },
  143. {
  144. .ident = "Dell Mini 12",
  145. .matches = {
  146. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  147. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"),
  148. },
  149. },
  150. {}
  151. };
  152. static struct dmi_system_id __devinitdata dell_quirks[] = {
  153. {
  154. .callback = dmi_matched,
  155. .ident = "Dell Vostro V130",
  156. .matches = {
  157. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  158. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V130"),
  159. },
  160. .driver_data = &quirk_dell_vostro_v130,
  161. },
  162. {
  163. .callback = dmi_matched,
  164. .ident = "Dell Vostro V131",
  165. .matches = {
  166. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  167. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
  168. },
  169. .driver_data = &quirk_dell_vostro_v130,
  170. },
  171. {
  172. .callback = dmi_matched,
  173. .ident = "Dell Vostro 3350",
  174. .matches = {
  175. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  176. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3350"),
  177. },
  178. .driver_data = &quirk_dell_vostro_v130,
  179. },
  180. {
  181. .callback = dmi_matched,
  182. .ident = "Dell Vostro 3555",
  183. .matches = {
  184. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  185. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3555"),
  186. },
  187. .driver_data = &quirk_dell_vostro_v130,
  188. },
  189. {
  190. .callback = dmi_matched,
  191. .ident = "Dell Inspiron N311z",
  192. .matches = {
  193. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  194. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N311z"),
  195. },
  196. .driver_data = &quirk_dell_vostro_v130,
  197. },
  198. {
  199. .callback = dmi_matched,
  200. .ident = "Dell Inspiron M5110",
  201. .matches = {
  202. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  203. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"),
  204. },
  205. .driver_data = &quirk_dell_vostro_v130,
  206. },
  207. {
  208. .callback = dmi_matched,
  209. .ident = "Dell Vostro 3360",
  210. .matches = {
  211. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  212. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
  213. },
  214. .driver_data = &quirk_dell_vostro_v130,
  215. },
  216. {
  217. .callback = dmi_matched,
  218. .ident = "Dell Vostro 3460",
  219. .matches = {
  220. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  221. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3460"),
  222. },
  223. .driver_data = &quirk_dell_vostro_v130,
  224. },
  225. {
  226. .callback = dmi_matched,
  227. .ident = "Dell Vostro 3560",
  228. .matches = {
  229. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  230. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3560"),
  231. },
  232. .driver_data = &quirk_dell_vostro_v130,
  233. },
  234. {
  235. .callback = dmi_matched,
  236. .ident = "Dell Vostro 3450",
  237. .matches = {
  238. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  239. DMI_MATCH(DMI_PRODUCT_NAME, "Dell System Vostro 3450"),
  240. },
  241. .driver_data = &quirk_dell_vostro_v130,
  242. },
  243. { }
  244. };
  245. static struct calling_interface_buffer *buffer;
  246. static struct page *bufferpage;
  247. static DEFINE_MUTEX(buffer_mutex);
  248. static int hwswitch_state;
  249. static void get_buffer(void)
  250. {
  251. mutex_lock(&buffer_mutex);
  252. memset(buffer, 0, sizeof(struct calling_interface_buffer));
  253. }
  254. static void release_buffer(void)
  255. {
  256. mutex_unlock(&buffer_mutex);
  257. }
  258. static void __init parse_da_table(const struct dmi_header *dm)
  259. {
  260. /* Final token is a terminator, so we don't want to copy it */
  261. int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1;
  262. struct calling_interface_structure *table =
  263. container_of(dm, struct calling_interface_structure, header);
  264. /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
  265. 6 bytes of entry */
  266. if (dm->length < 17)
  267. return;
  268. da_command_address = table->cmdIOAddress;
  269. da_command_code = table->cmdIOCode;
  270. da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
  271. sizeof(struct calling_interface_token),
  272. GFP_KERNEL);
  273. if (!da_tokens)
  274. return;
  275. memcpy(da_tokens+da_num_tokens, table->tokens,
  276. sizeof(struct calling_interface_token) * tokens);
  277. da_num_tokens += tokens;
  278. }
  279. static void __init find_tokens(const struct dmi_header *dm, void *dummy)
  280. {
  281. switch (dm->type) {
  282. case 0xd4: /* Indexed IO */
  283. case 0xd5: /* Protected Area Type 1 */
  284. case 0xd6: /* Protected Area Type 2 */
  285. break;
  286. case 0xda: /* Calling interface */
  287. parse_da_table(dm);
  288. break;
  289. }
  290. }
  291. static int find_token_location(int tokenid)
  292. {
  293. int i;
  294. for (i = 0; i < da_num_tokens; i++) {
  295. if (da_tokens[i].tokenID == tokenid)
  296. return da_tokens[i].location;
  297. }
  298. return -1;
  299. }
  300. static struct calling_interface_buffer *
  301. dell_send_request(struct calling_interface_buffer *buffer, int class,
  302. int select)
  303. {
  304. struct smi_cmd command;
  305. command.magic = SMI_CMD_MAGIC;
  306. command.command_address = da_command_address;
  307. command.command_code = da_command_code;
  308. command.ebx = virt_to_phys(buffer);
  309. command.ecx = 0x42534931;
  310. buffer->class = class;
  311. buffer->select = select;
  312. dcdbas_smi_request(&command);
  313. return buffer;
  314. }
  315. /* Derived from information in DellWirelessCtl.cpp:
  316. Class 17, select 11 is radio control. It returns an array of 32-bit values.
  317. Input byte 0 = 0: Wireless information
  318. result[0]: return code
  319. result[1]:
  320. Bit 0: Hardware switch supported
  321. Bit 1: Wifi locator supported
  322. Bit 2: Wifi is supported
  323. Bit 3: Bluetooth is supported
  324. Bit 4: WWAN is supported
  325. Bit 5: Wireless keyboard supported
  326. Bits 6-7: Reserved
  327. Bit 8: Wifi is installed
  328. Bit 9: Bluetooth is installed
  329. Bit 10: WWAN is installed
  330. Bits 11-15: Reserved
  331. Bit 16: Hardware switch is on
  332. Bit 17: Wifi is blocked
  333. Bit 18: Bluetooth is blocked
  334. Bit 19: WWAN is blocked
  335. Bits 20-31: Reserved
  336. result[2]: NVRAM size in bytes
  337. result[3]: NVRAM format version number
  338. Input byte 0 = 2: Wireless switch configuration
  339. result[0]: return code
  340. result[1]:
  341. Bit 0: Wifi controlled by switch
  342. Bit 1: Bluetooth controlled by switch
  343. Bit 2: WWAN controlled by switch
  344. Bits 3-6: Reserved
  345. Bit 7: Wireless switch config locked
  346. Bit 8: Wifi locator enabled
  347. Bits 9-14: Reserved
  348. Bit 15: Wifi locator setting locked
  349. Bits 16-31: Reserved
  350. */
  351. static int dell_rfkill_set(void *data, bool blocked)
  352. {
  353. int disable = blocked ? 1 : 0;
  354. unsigned long radio = (unsigned long)data;
  355. int hwswitch_bit = (unsigned long)data - 1;
  356. int ret = 0;
  357. get_buffer();
  358. dell_send_request(buffer, 17, 11);
  359. /* If the hardware switch controls this radio, and the hardware
  360. switch is disabled, don't allow changing the software state */
  361. if ((hwswitch_state & BIT(hwswitch_bit)) &&
  362. !(buffer->output[1] & BIT(16))) {
  363. ret = -EINVAL;
  364. goto out;
  365. }
  366. buffer->input[0] = (1 | (radio<<8) | (disable << 16));
  367. dell_send_request(buffer, 17, 11);
  368. out:
  369. release_buffer();
  370. return ret;
  371. }
  372. static void dell_rfkill_query(struct rfkill *rfkill, void *data)
  373. {
  374. int status;
  375. int bit = (unsigned long)data + 16;
  376. int hwswitch_bit = (unsigned long)data - 1;
  377. get_buffer();
  378. dell_send_request(buffer, 17, 11);
  379. status = buffer->output[1];
  380. release_buffer();
  381. rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
  382. if (hwswitch_state & (BIT(hwswitch_bit)))
  383. rfkill_set_hw_state(rfkill, !(status & BIT(16)));
  384. }
  385. static const struct rfkill_ops dell_rfkill_ops = {
  386. .set_block = dell_rfkill_set,
  387. .query = dell_rfkill_query,
  388. };
  389. static struct dentry *dell_laptop_dir;
  390. static int dell_debugfs_show(struct seq_file *s, void *data)
  391. {
  392. int status;
  393. get_buffer();
  394. dell_send_request(buffer, 17, 11);
  395. status = buffer->output[1];
  396. release_buffer();
  397. seq_printf(s, "status:\t0x%X\n", status);
  398. seq_printf(s, "Bit 0 : Hardware switch supported: %lu\n",
  399. status & BIT(0));
  400. seq_printf(s, "Bit 1 : Wifi locator supported: %lu\n",
  401. (status & BIT(1)) >> 1);
  402. seq_printf(s, "Bit 2 : Wifi is supported: %lu\n",
  403. (status & BIT(2)) >> 2);
  404. seq_printf(s, "Bit 3 : Bluetooth is supported: %lu\n",
  405. (status & BIT(3)) >> 3);
  406. seq_printf(s, "Bit 4 : WWAN is supported: %lu\n",
  407. (status & BIT(4)) >> 4);
  408. seq_printf(s, "Bit 5 : Wireless keyboard supported: %lu\n",
  409. (status & BIT(5)) >> 5);
  410. seq_printf(s, "Bit 8 : Wifi is installed: %lu\n",
  411. (status & BIT(8)) >> 8);
  412. seq_printf(s, "Bit 9 : Bluetooth is installed: %lu\n",
  413. (status & BIT(9)) >> 9);
  414. seq_printf(s, "Bit 10: WWAN is installed: %lu\n",
  415. (status & BIT(10)) >> 10);
  416. seq_printf(s, "Bit 16: Hardware switch is on: %lu\n",
  417. (status & BIT(16)) >> 16);
  418. seq_printf(s, "Bit 17: Wifi is blocked: %lu\n",
  419. (status & BIT(17)) >> 17);
  420. seq_printf(s, "Bit 18: Bluetooth is blocked: %lu\n",
  421. (status & BIT(18)) >> 18);
  422. seq_printf(s, "Bit 19: WWAN is blocked: %lu\n",
  423. (status & BIT(19)) >> 19);
  424. seq_printf(s, "\nhwswitch_state:\t0x%X\n", hwswitch_state);
  425. seq_printf(s, "Bit 0 : Wifi controlled by switch: %lu\n",
  426. hwswitch_state & BIT(0));
  427. seq_printf(s, "Bit 1 : Bluetooth controlled by switch: %lu\n",
  428. (hwswitch_state & BIT(1)) >> 1);
  429. seq_printf(s, "Bit 2 : WWAN controlled by switch: %lu\n",
  430. (hwswitch_state & BIT(2)) >> 2);
  431. seq_printf(s, "Bit 7 : Wireless switch config locked: %lu\n",
  432. (hwswitch_state & BIT(7)) >> 7);
  433. seq_printf(s, "Bit 8 : Wifi locator enabled: %lu\n",
  434. (hwswitch_state & BIT(8)) >> 8);
  435. seq_printf(s, "Bit 15: Wifi locator setting locked: %lu\n",
  436. (hwswitch_state & BIT(15)) >> 15);
  437. return 0;
  438. }
  439. static int dell_debugfs_open(struct inode *inode, struct file *file)
  440. {
  441. return single_open(file, dell_debugfs_show, inode->i_private);
  442. }
  443. static const struct file_operations dell_debugfs_fops = {
  444. .owner = THIS_MODULE,
  445. .open = dell_debugfs_open,
  446. .read = seq_read,
  447. .llseek = seq_lseek,
  448. .release = single_release,
  449. };
  450. static void dell_update_rfkill(struct work_struct *ignored)
  451. {
  452. if (wifi_rfkill)
  453. dell_rfkill_query(wifi_rfkill, (void *)1);
  454. if (bluetooth_rfkill)
  455. dell_rfkill_query(bluetooth_rfkill, (void *)2);
  456. if (wwan_rfkill)
  457. dell_rfkill_query(wwan_rfkill, (void *)3);
  458. }
  459. static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
  460. static int __init dell_setup_rfkill(void)
  461. {
  462. int status;
  463. int ret;
  464. if (dmi_check_system(dell_blacklist)) {
  465. pr_info("Blacklisted hardware detected - not enabling rfkill\n");
  466. return 0;
  467. }
  468. get_buffer();
  469. dell_send_request(buffer, 17, 11);
  470. status = buffer->output[1];
  471. buffer->input[0] = 0x2;
  472. dell_send_request(buffer, 17, 11);
  473. hwswitch_state = buffer->output[1];
  474. release_buffer();
  475. if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {
  476. wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev,
  477. RFKILL_TYPE_WLAN,
  478. &dell_rfkill_ops, (void *) 1);
  479. if (!wifi_rfkill) {
  480. ret = -ENOMEM;
  481. goto err_wifi;
  482. }
  483. ret = rfkill_register(wifi_rfkill);
  484. if (ret)
  485. goto err_wifi;
  486. }
  487. if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) {
  488. bluetooth_rfkill = rfkill_alloc("dell-bluetooth",
  489. &platform_device->dev,
  490. RFKILL_TYPE_BLUETOOTH,
  491. &dell_rfkill_ops, (void *) 2);
  492. if (!bluetooth_rfkill) {
  493. ret = -ENOMEM;
  494. goto err_bluetooth;
  495. }
  496. ret = rfkill_register(bluetooth_rfkill);
  497. if (ret)
  498. goto err_bluetooth;
  499. }
  500. if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) {
  501. wwan_rfkill = rfkill_alloc("dell-wwan",
  502. &platform_device->dev,
  503. RFKILL_TYPE_WWAN,
  504. &dell_rfkill_ops, (void *) 3);
  505. if (!wwan_rfkill) {
  506. ret = -ENOMEM;
  507. goto err_wwan;
  508. }
  509. ret = rfkill_register(wwan_rfkill);
  510. if (ret)
  511. goto err_wwan;
  512. }
  513. return 0;
  514. err_wwan:
  515. rfkill_destroy(wwan_rfkill);
  516. if (bluetooth_rfkill)
  517. rfkill_unregister(bluetooth_rfkill);
  518. err_bluetooth:
  519. rfkill_destroy(bluetooth_rfkill);
  520. if (wifi_rfkill)
  521. rfkill_unregister(wifi_rfkill);
  522. err_wifi:
  523. rfkill_destroy(wifi_rfkill);
  524. return ret;
  525. }
  526. static void dell_cleanup_rfkill(void)
  527. {
  528. if (wifi_rfkill) {
  529. rfkill_unregister(wifi_rfkill);
  530. rfkill_destroy(wifi_rfkill);
  531. }
  532. if (bluetooth_rfkill) {
  533. rfkill_unregister(bluetooth_rfkill);
  534. rfkill_destroy(bluetooth_rfkill);
  535. }
  536. if (wwan_rfkill) {
  537. rfkill_unregister(wwan_rfkill);
  538. rfkill_destroy(wwan_rfkill);
  539. }
  540. }
  541. static int dell_send_intensity(struct backlight_device *bd)
  542. {
  543. int ret = 0;
  544. get_buffer();
  545. buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
  546. buffer->input[1] = bd->props.brightness;
  547. if (buffer->input[0] == -1) {
  548. ret = -ENODEV;
  549. goto out;
  550. }
  551. if (power_supply_is_system_supplied() > 0)
  552. dell_send_request(buffer, 1, 2);
  553. else
  554. dell_send_request(buffer, 1, 1);
  555. out:
  556. release_buffer();
  557. return 0;
  558. }
  559. static int dell_get_intensity(struct backlight_device *bd)
  560. {
  561. int ret = 0;
  562. get_buffer();
  563. buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
  564. if (buffer->input[0] == -1) {
  565. ret = -ENODEV;
  566. goto out;
  567. }
  568. if (power_supply_is_system_supplied() > 0)
  569. dell_send_request(buffer, 0, 2);
  570. else
  571. dell_send_request(buffer, 0, 1);
  572. ret = buffer->output[1];
  573. out:
  574. release_buffer();
  575. return ret;
  576. }
  577. static const struct backlight_ops dell_ops = {
  578. .get_brightness = dell_get_intensity,
  579. .update_status = dell_send_intensity,
  580. };
  581. static void touchpad_led_on(void)
  582. {
  583. int command = 0x97;
  584. char data = 1;
  585. i8042_command(&data, command | 1 << 12);
  586. }
  587. static void touchpad_led_off(void)
  588. {
  589. int command = 0x97;
  590. char data = 2;
  591. i8042_command(&data, command | 1 << 12);
  592. }
  593. static void touchpad_led_set(struct led_classdev *led_cdev,
  594. enum led_brightness value)
  595. {
  596. if (value > 0)
  597. touchpad_led_on();
  598. else
  599. touchpad_led_off();
  600. }
  601. static struct led_classdev touchpad_led = {
  602. .name = "dell-laptop::touchpad",
  603. .brightness_set = touchpad_led_set,
  604. .flags = LED_CORE_SUSPENDRESUME,
  605. };
  606. static int __devinit touchpad_led_init(struct device *dev)
  607. {
  608. return led_classdev_register(dev, &touchpad_led);
  609. }
  610. static void touchpad_led_exit(void)
  611. {
  612. led_classdev_unregister(&touchpad_led);
  613. }
  614. static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
  615. struct serio *port)
  616. {
  617. static bool extended;
  618. if (str & 0x20)
  619. return false;
  620. if (unlikely(data == 0xe0)) {
  621. extended = true;
  622. return false;
  623. } else if (unlikely(extended)) {
  624. switch (data) {
  625. case 0x8:
  626. schedule_delayed_work(&dell_rfkill_work,
  627. round_jiffies_relative(HZ));
  628. break;
  629. }
  630. extended = false;
  631. }
  632. return false;
  633. }
  634. static int __init dell_init(void)
  635. {
  636. int max_intensity = 0;
  637. int ret;
  638. if (!dmi_check_system(dell_device_table))
  639. return -ENODEV;
  640. quirks = NULL;
  641. /* find if this machine support other functions */
  642. dmi_check_system(dell_quirks);
  643. dmi_walk(find_tokens, NULL);
  644. if (!da_tokens) {
  645. pr_info("Unable to find dmi tokens\n");
  646. return -ENODEV;
  647. }
  648. ret = platform_driver_register(&platform_driver);
  649. if (ret)
  650. goto fail_platform_driver;
  651. platform_device = platform_device_alloc("dell-laptop", -1);
  652. if (!platform_device) {
  653. ret = -ENOMEM;
  654. goto fail_platform_device1;
  655. }
  656. ret = platform_device_add(platform_device);
  657. if (ret)
  658. goto fail_platform_device2;
  659. /*
  660. * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
  661. * is passed to SMI handler.
  662. */
  663. bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32);
  664. if (!bufferpage)
  665. goto fail_buffer;
  666. buffer = page_address(bufferpage);
  667. ret = dell_setup_rfkill();
  668. if (ret) {
  669. pr_warn("Unable to setup rfkill\n");
  670. goto fail_rfkill;
  671. }
  672. ret = i8042_install_filter(dell_laptop_i8042_filter);
  673. if (ret) {
  674. pr_warn("Unable to install key filter\n");
  675. goto fail_filter;
  676. }
  677. if (quirks && quirks->touchpad_led)
  678. touchpad_led_init(&platform_device->dev);
  679. dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL);
  680. if (dell_laptop_dir != NULL)
  681. debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL,
  682. &dell_debugfs_fops);
  683. #ifdef CONFIG_ACPI
  684. /* In the event of an ACPI backlight being available, don't
  685. * register the platform controller.
  686. */
  687. if (acpi_video_backlight_support())
  688. return 0;
  689. #endif
  690. get_buffer();
  691. buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
  692. if (buffer->input[0] != -1) {
  693. dell_send_request(buffer, 0, 2);
  694. max_intensity = buffer->output[3];
  695. }
  696. release_buffer();
  697. if (max_intensity) {
  698. struct backlight_properties props;
  699. memset(&props, 0, sizeof(struct backlight_properties));
  700. props.type = BACKLIGHT_PLATFORM;
  701. props.max_brightness = max_intensity;
  702. dell_backlight_device = backlight_device_register("dell_backlight",
  703. &platform_device->dev,
  704. NULL,
  705. &dell_ops,
  706. &props);
  707. if (IS_ERR(dell_backlight_device)) {
  708. ret = PTR_ERR(dell_backlight_device);
  709. dell_backlight_device = NULL;
  710. goto fail_backlight;
  711. }
  712. dell_backlight_device->props.brightness =
  713. dell_get_intensity(dell_backlight_device);
  714. backlight_update_status(dell_backlight_device);
  715. }
  716. return 0;
  717. fail_backlight:
  718. i8042_remove_filter(dell_laptop_i8042_filter);
  719. cancel_delayed_work_sync(&dell_rfkill_work);
  720. fail_filter:
  721. dell_cleanup_rfkill();
  722. fail_rfkill:
  723. free_page((unsigned long)bufferpage);
  724. fail_buffer:
  725. platform_device_del(platform_device);
  726. fail_platform_device2:
  727. platform_device_put(platform_device);
  728. fail_platform_device1:
  729. platform_driver_unregister(&platform_driver);
  730. fail_platform_driver:
  731. kfree(da_tokens);
  732. return ret;
  733. }
  734. static void __exit dell_exit(void)
  735. {
  736. debugfs_remove_recursive(dell_laptop_dir);
  737. if (quirks && quirks->touchpad_led)
  738. touchpad_led_exit();
  739. i8042_remove_filter(dell_laptop_i8042_filter);
  740. cancel_delayed_work_sync(&dell_rfkill_work);
  741. backlight_device_unregister(dell_backlight_device);
  742. dell_cleanup_rfkill();
  743. if (platform_device) {
  744. platform_device_unregister(platform_device);
  745. platform_driver_unregister(&platform_driver);
  746. }
  747. kfree(da_tokens);
  748. free_page((unsigned long)buffer);
  749. }
  750. module_init(dell_init);
  751. module_exit(dell_exit);
  752. MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
  753. MODULE_DESCRIPTION("Dell laptop driver");
  754. MODULE_LICENSE("GPL");