dell-laptop.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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 __initdata dell_device_table[] = {
  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 3555",
  174. .matches = {
  175. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  176. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3555"),
  177. },
  178. .driver_data = &quirk_dell_vostro_v130,
  179. },
  180. {
  181. .callback = dmi_matched,
  182. .ident = "Dell Inspiron N311z",
  183. .matches = {
  184. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  185. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N311z"),
  186. },
  187. .driver_data = &quirk_dell_vostro_v130,
  188. },
  189. {
  190. .callback = dmi_matched,
  191. .ident = "Dell Inspiron M5110",
  192. .matches = {
  193. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  194. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"),
  195. },
  196. .driver_data = &quirk_dell_vostro_v130,
  197. },
  198. { }
  199. };
  200. static struct calling_interface_buffer *buffer;
  201. static struct page *bufferpage;
  202. static DEFINE_MUTEX(buffer_mutex);
  203. static int hwswitch_state;
  204. static void get_buffer(void)
  205. {
  206. mutex_lock(&buffer_mutex);
  207. memset(buffer, 0, sizeof(struct calling_interface_buffer));
  208. }
  209. static void release_buffer(void)
  210. {
  211. mutex_unlock(&buffer_mutex);
  212. }
  213. static void __init parse_da_table(const struct dmi_header *dm)
  214. {
  215. /* Final token is a terminator, so we don't want to copy it */
  216. int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1;
  217. struct calling_interface_structure *table =
  218. container_of(dm, struct calling_interface_structure, header);
  219. /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
  220. 6 bytes of entry */
  221. if (dm->length < 17)
  222. return;
  223. da_command_address = table->cmdIOAddress;
  224. da_command_code = table->cmdIOCode;
  225. da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) *
  226. sizeof(struct calling_interface_token),
  227. GFP_KERNEL);
  228. if (!da_tokens)
  229. return;
  230. memcpy(da_tokens+da_num_tokens, table->tokens,
  231. sizeof(struct calling_interface_token) * tokens);
  232. da_num_tokens += tokens;
  233. }
  234. static void __init find_tokens(const struct dmi_header *dm, void *dummy)
  235. {
  236. switch (dm->type) {
  237. case 0xd4: /* Indexed IO */
  238. case 0xd5: /* Protected Area Type 1 */
  239. case 0xd6: /* Protected Area Type 2 */
  240. break;
  241. case 0xda: /* Calling interface */
  242. parse_da_table(dm);
  243. break;
  244. }
  245. }
  246. static int find_token_location(int tokenid)
  247. {
  248. int i;
  249. for (i = 0; i < da_num_tokens; i++) {
  250. if (da_tokens[i].tokenID == tokenid)
  251. return da_tokens[i].location;
  252. }
  253. return -1;
  254. }
  255. static struct calling_interface_buffer *
  256. dell_send_request(struct calling_interface_buffer *buffer, int class,
  257. int select)
  258. {
  259. struct smi_cmd command;
  260. command.magic = SMI_CMD_MAGIC;
  261. command.command_address = da_command_address;
  262. command.command_code = da_command_code;
  263. command.ebx = virt_to_phys(buffer);
  264. command.ecx = 0x42534931;
  265. buffer->class = class;
  266. buffer->select = select;
  267. dcdbas_smi_request(&command);
  268. return buffer;
  269. }
  270. /* Derived from information in DellWirelessCtl.cpp:
  271. Class 17, select 11 is radio control. It returns an array of 32-bit values.
  272. Input byte 0 = 0: Wireless information
  273. result[0]: return code
  274. result[1]:
  275. Bit 0: Hardware switch supported
  276. Bit 1: Wifi locator supported
  277. Bit 2: Wifi is supported
  278. Bit 3: Bluetooth is supported
  279. Bit 4: WWAN is supported
  280. Bit 5: Wireless keyboard supported
  281. Bits 6-7: Reserved
  282. Bit 8: Wifi is installed
  283. Bit 9: Bluetooth is installed
  284. Bit 10: WWAN is installed
  285. Bits 11-15: Reserved
  286. Bit 16: Hardware switch is on
  287. Bit 17: Wifi is blocked
  288. Bit 18: Bluetooth is blocked
  289. Bit 19: WWAN is blocked
  290. Bits 20-31: Reserved
  291. result[2]: NVRAM size in bytes
  292. result[3]: NVRAM format version number
  293. Input byte 0 = 2: Wireless switch configuration
  294. result[0]: return code
  295. result[1]:
  296. Bit 0: Wifi controlled by switch
  297. Bit 1: Bluetooth controlled by switch
  298. Bit 2: WWAN controlled by switch
  299. Bits 3-6: Reserved
  300. Bit 7: Wireless switch config locked
  301. Bit 8: Wifi locator enabled
  302. Bits 9-14: Reserved
  303. Bit 15: Wifi locator setting locked
  304. Bits 16-31: Reserved
  305. */
  306. static int dell_rfkill_set(void *data, bool blocked)
  307. {
  308. int disable = blocked ? 1 : 0;
  309. unsigned long radio = (unsigned long)data;
  310. int hwswitch_bit = (unsigned long)data - 1;
  311. int ret = 0;
  312. get_buffer();
  313. dell_send_request(buffer, 17, 11);
  314. /* If the hardware switch controls this radio, and the hardware
  315. switch is disabled, don't allow changing the software state */
  316. if ((hwswitch_state & BIT(hwswitch_bit)) &&
  317. !(buffer->output[1] & BIT(16))) {
  318. ret = -EINVAL;
  319. goto out;
  320. }
  321. buffer->input[0] = (1 | (radio<<8) | (disable << 16));
  322. dell_send_request(buffer, 17, 11);
  323. out:
  324. release_buffer();
  325. return ret;
  326. }
  327. static void dell_rfkill_query(struct rfkill *rfkill, void *data)
  328. {
  329. int status;
  330. int bit = (unsigned long)data + 16;
  331. int hwswitch_bit = (unsigned long)data - 1;
  332. get_buffer();
  333. dell_send_request(buffer, 17, 11);
  334. status = buffer->output[1];
  335. release_buffer();
  336. rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
  337. if (hwswitch_state & (BIT(hwswitch_bit)))
  338. rfkill_set_hw_state(rfkill, !(status & BIT(16)));
  339. }
  340. static const struct rfkill_ops dell_rfkill_ops = {
  341. .set_block = dell_rfkill_set,
  342. .query = dell_rfkill_query,
  343. };
  344. static struct dentry *dell_laptop_dir;
  345. static int dell_debugfs_show(struct seq_file *s, void *data)
  346. {
  347. int status;
  348. get_buffer();
  349. dell_send_request(buffer, 17, 11);
  350. status = buffer->output[1];
  351. release_buffer();
  352. seq_printf(s, "status:\t0x%X\n", status);
  353. seq_printf(s, "Bit 0 : Hardware switch supported: %lu\n",
  354. status & BIT(0));
  355. seq_printf(s, "Bit 1 : Wifi locator supported: %lu\n",
  356. (status & BIT(1)) >> 1);
  357. seq_printf(s, "Bit 2 : Wifi is supported: %lu\n",
  358. (status & BIT(2)) >> 2);
  359. seq_printf(s, "Bit 3 : Bluetooth is supported: %lu\n",
  360. (status & BIT(3)) >> 3);
  361. seq_printf(s, "Bit 4 : WWAN is supported: %lu\n",
  362. (status & BIT(4)) >> 4);
  363. seq_printf(s, "Bit 5 : Wireless keyboard supported: %lu\n",
  364. (status & BIT(5)) >> 5);
  365. seq_printf(s, "Bit 8 : Wifi is installed: %lu\n",
  366. (status & BIT(8)) >> 8);
  367. seq_printf(s, "Bit 9 : Bluetooth is installed: %lu\n",
  368. (status & BIT(9)) >> 9);
  369. seq_printf(s, "Bit 10: WWAN is installed: %lu\n",
  370. (status & BIT(10)) >> 10);
  371. seq_printf(s, "Bit 16: Hardware switch is on: %lu\n",
  372. (status & BIT(16)) >> 16);
  373. seq_printf(s, "Bit 17: Wifi is blocked: %lu\n",
  374. (status & BIT(17)) >> 17);
  375. seq_printf(s, "Bit 18: Bluetooth is blocked: %lu\n",
  376. (status & BIT(18)) >> 18);
  377. seq_printf(s, "Bit 19: WWAN is blocked: %lu\n",
  378. (status & BIT(19)) >> 19);
  379. seq_printf(s, "\nhwswitch_state:\t0x%X\n", hwswitch_state);
  380. seq_printf(s, "Bit 0 : Wifi controlled by switch: %lu\n",
  381. hwswitch_state & BIT(0));
  382. seq_printf(s, "Bit 1 : Bluetooth controlled by switch: %lu\n",
  383. (hwswitch_state & BIT(1)) >> 1);
  384. seq_printf(s, "Bit 2 : WWAN controlled by switch: %lu\n",
  385. (hwswitch_state & BIT(2)) >> 2);
  386. seq_printf(s, "Bit 7 : Wireless switch config locked: %lu\n",
  387. (hwswitch_state & BIT(7)) >> 7);
  388. seq_printf(s, "Bit 8 : Wifi locator enabled: %lu\n",
  389. (hwswitch_state & BIT(8)) >> 8);
  390. seq_printf(s, "Bit 15: Wifi locator setting locked: %lu\n",
  391. (hwswitch_state & BIT(15)) >> 15);
  392. return 0;
  393. }
  394. static int dell_debugfs_open(struct inode *inode, struct file *file)
  395. {
  396. return single_open(file, dell_debugfs_show, inode->i_private);
  397. }
  398. static const struct file_operations dell_debugfs_fops = {
  399. .owner = THIS_MODULE,
  400. .open = dell_debugfs_open,
  401. .read = seq_read,
  402. .llseek = seq_lseek,
  403. .release = single_release,
  404. };
  405. static void dell_update_rfkill(struct work_struct *ignored)
  406. {
  407. if (wifi_rfkill)
  408. dell_rfkill_query(wifi_rfkill, (void *)1);
  409. if (bluetooth_rfkill)
  410. dell_rfkill_query(bluetooth_rfkill, (void *)2);
  411. if (wwan_rfkill)
  412. dell_rfkill_query(wwan_rfkill, (void *)3);
  413. }
  414. static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
  415. static int __init dell_setup_rfkill(void)
  416. {
  417. int status;
  418. int ret;
  419. if (dmi_check_system(dell_blacklist)) {
  420. pr_info("Blacklisted hardware detected - not enabling rfkill\n");
  421. return 0;
  422. }
  423. get_buffer();
  424. dell_send_request(buffer, 17, 11);
  425. status = buffer->output[1];
  426. buffer->input[0] = 0x2;
  427. dell_send_request(buffer, 17, 11);
  428. hwswitch_state = buffer->output[1];
  429. release_buffer();
  430. if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {
  431. wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev,
  432. RFKILL_TYPE_WLAN,
  433. &dell_rfkill_ops, (void *) 1);
  434. if (!wifi_rfkill) {
  435. ret = -ENOMEM;
  436. goto err_wifi;
  437. }
  438. ret = rfkill_register(wifi_rfkill);
  439. if (ret)
  440. goto err_wifi;
  441. }
  442. if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) {
  443. bluetooth_rfkill = rfkill_alloc("dell-bluetooth",
  444. &platform_device->dev,
  445. RFKILL_TYPE_BLUETOOTH,
  446. &dell_rfkill_ops, (void *) 2);
  447. if (!bluetooth_rfkill) {
  448. ret = -ENOMEM;
  449. goto err_bluetooth;
  450. }
  451. ret = rfkill_register(bluetooth_rfkill);
  452. if (ret)
  453. goto err_bluetooth;
  454. }
  455. if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) {
  456. wwan_rfkill = rfkill_alloc("dell-wwan",
  457. &platform_device->dev,
  458. RFKILL_TYPE_WWAN,
  459. &dell_rfkill_ops, (void *) 3);
  460. if (!wwan_rfkill) {
  461. ret = -ENOMEM;
  462. goto err_wwan;
  463. }
  464. ret = rfkill_register(wwan_rfkill);
  465. if (ret)
  466. goto err_wwan;
  467. }
  468. return 0;
  469. err_wwan:
  470. rfkill_destroy(wwan_rfkill);
  471. if (bluetooth_rfkill)
  472. rfkill_unregister(bluetooth_rfkill);
  473. err_bluetooth:
  474. rfkill_destroy(bluetooth_rfkill);
  475. if (wifi_rfkill)
  476. rfkill_unregister(wifi_rfkill);
  477. err_wifi:
  478. rfkill_destroy(wifi_rfkill);
  479. return ret;
  480. }
  481. static void dell_cleanup_rfkill(void)
  482. {
  483. if (wifi_rfkill) {
  484. rfkill_unregister(wifi_rfkill);
  485. rfkill_destroy(wifi_rfkill);
  486. }
  487. if (bluetooth_rfkill) {
  488. rfkill_unregister(bluetooth_rfkill);
  489. rfkill_destroy(bluetooth_rfkill);
  490. }
  491. if (wwan_rfkill) {
  492. rfkill_unregister(wwan_rfkill);
  493. rfkill_destroy(wwan_rfkill);
  494. }
  495. }
  496. static int dell_send_intensity(struct backlight_device *bd)
  497. {
  498. int ret = 0;
  499. get_buffer();
  500. buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
  501. buffer->input[1] = bd->props.brightness;
  502. if (buffer->input[0] == -1) {
  503. ret = -ENODEV;
  504. goto out;
  505. }
  506. if (power_supply_is_system_supplied() > 0)
  507. dell_send_request(buffer, 1, 2);
  508. else
  509. dell_send_request(buffer, 1, 1);
  510. out:
  511. release_buffer();
  512. return 0;
  513. }
  514. static int dell_get_intensity(struct backlight_device *bd)
  515. {
  516. int ret = 0;
  517. get_buffer();
  518. buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
  519. if (buffer->input[0] == -1) {
  520. ret = -ENODEV;
  521. goto out;
  522. }
  523. if (power_supply_is_system_supplied() > 0)
  524. dell_send_request(buffer, 0, 2);
  525. else
  526. dell_send_request(buffer, 0, 1);
  527. ret = buffer->output[1];
  528. out:
  529. release_buffer();
  530. return ret;
  531. }
  532. static const struct backlight_ops dell_ops = {
  533. .get_brightness = dell_get_intensity,
  534. .update_status = dell_send_intensity,
  535. };
  536. static void touchpad_led_on(void)
  537. {
  538. int command = 0x97;
  539. char data = 1;
  540. i8042_command(&data, command | 1 << 12);
  541. }
  542. static void touchpad_led_off(void)
  543. {
  544. int command = 0x97;
  545. char data = 2;
  546. i8042_command(&data, command | 1 << 12);
  547. }
  548. static void touchpad_led_set(struct led_classdev *led_cdev,
  549. enum led_brightness value)
  550. {
  551. if (value > 0)
  552. touchpad_led_on();
  553. else
  554. touchpad_led_off();
  555. }
  556. static struct led_classdev touchpad_led = {
  557. .name = "dell-laptop::touchpad",
  558. .brightness_set = touchpad_led_set,
  559. .flags = LED_CORE_SUSPENDRESUME,
  560. };
  561. static int __devinit touchpad_led_init(struct device *dev)
  562. {
  563. return led_classdev_register(dev, &touchpad_led);
  564. }
  565. static void touchpad_led_exit(void)
  566. {
  567. led_classdev_unregister(&touchpad_led);
  568. }
  569. static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
  570. struct serio *port)
  571. {
  572. static bool extended;
  573. if (str & 0x20)
  574. return false;
  575. if (unlikely(data == 0xe0)) {
  576. extended = true;
  577. return false;
  578. } else if (unlikely(extended)) {
  579. switch (data) {
  580. case 0x8:
  581. schedule_delayed_work(&dell_rfkill_work,
  582. round_jiffies_relative(HZ));
  583. break;
  584. }
  585. extended = false;
  586. }
  587. return false;
  588. }
  589. static int __init dell_init(void)
  590. {
  591. int max_intensity = 0;
  592. int ret;
  593. if (!dmi_check_system(dell_device_table))
  594. return -ENODEV;
  595. quirks = NULL;
  596. /* find if this machine support other functions */
  597. dmi_check_system(dell_quirks);
  598. dmi_walk(find_tokens, NULL);
  599. if (!da_tokens) {
  600. pr_info("Unable to find dmi tokens\n");
  601. return -ENODEV;
  602. }
  603. ret = platform_driver_register(&platform_driver);
  604. if (ret)
  605. goto fail_platform_driver;
  606. platform_device = platform_device_alloc("dell-laptop", -1);
  607. if (!platform_device) {
  608. ret = -ENOMEM;
  609. goto fail_platform_device1;
  610. }
  611. ret = platform_device_add(platform_device);
  612. if (ret)
  613. goto fail_platform_device2;
  614. /*
  615. * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
  616. * is passed to SMI handler.
  617. */
  618. bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32);
  619. if (!bufferpage)
  620. goto fail_buffer;
  621. buffer = page_address(bufferpage);
  622. ret = dell_setup_rfkill();
  623. if (ret) {
  624. pr_warn("Unable to setup rfkill\n");
  625. goto fail_rfkill;
  626. }
  627. ret = i8042_install_filter(dell_laptop_i8042_filter);
  628. if (ret) {
  629. pr_warn("Unable to install key filter\n");
  630. goto fail_filter;
  631. }
  632. if (quirks && quirks->touchpad_led)
  633. touchpad_led_init(&platform_device->dev);
  634. dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL);
  635. if (dell_laptop_dir != NULL)
  636. debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL,
  637. &dell_debugfs_fops);
  638. #ifdef CONFIG_ACPI
  639. /* In the event of an ACPI backlight being available, don't
  640. * register the platform controller.
  641. */
  642. if (acpi_video_backlight_support())
  643. return 0;
  644. #endif
  645. get_buffer();
  646. buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
  647. if (buffer->input[0] != -1) {
  648. dell_send_request(buffer, 0, 2);
  649. max_intensity = buffer->output[3];
  650. }
  651. release_buffer();
  652. if (max_intensity) {
  653. struct backlight_properties props;
  654. memset(&props, 0, sizeof(struct backlight_properties));
  655. props.type = BACKLIGHT_PLATFORM;
  656. props.max_brightness = max_intensity;
  657. dell_backlight_device = backlight_device_register("dell_backlight",
  658. &platform_device->dev,
  659. NULL,
  660. &dell_ops,
  661. &props);
  662. if (IS_ERR(dell_backlight_device)) {
  663. ret = PTR_ERR(dell_backlight_device);
  664. dell_backlight_device = NULL;
  665. goto fail_backlight;
  666. }
  667. dell_backlight_device->props.brightness =
  668. dell_get_intensity(dell_backlight_device);
  669. backlight_update_status(dell_backlight_device);
  670. }
  671. return 0;
  672. fail_backlight:
  673. i8042_remove_filter(dell_laptop_i8042_filter);
  674. cancel_delayed_work_sync(&dell_rfkill_work);
  675. fail_filter:
  676. dell_cleanup_rfkill();
  677. fail_rfkill:
  678. free_page((unsigned long)bufferpage);
  679. fail_buffer:
  680. platform_device_del(platform_device);
  681. fail_platform_device2:
  682. platform_device_put(platform_device);
  683. fail_platform_device1:
  684. platform_driver_unregister(&platform_driver);
  685. fail_platform_driver:
  686. kfree(da_tokens);
  687. return ret;
  688. }
  689. static void __exit dell_exit(void)
  690. {
  691. debugfs_remove_recursive(dell_laptop_dir);
  692. if (quirks && quirks->touchpad_led)
  693. touchpad_led_exit();
  694. i8042_remove_filter(dell_laptop_i8042_filter);
  695. cancel_delayed_work_sync(&dell_rfkill_work);
  696. backlight_device_unregister(dell_backlight_device);
  697. dell_cleanup_rfkill();
  698. if (platform_device) {
  699. platform_device_unregister(platform_device);
  700. platform_driver_unregister(&platform_driver);
  701. }
  702. kfree(da_tokens);
  703. free_page((unsigned long)buffer);
  704. }
  705. module_init(dell_init);
  706. module_exit(dell_exit);
  707. MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
  708. MODULE_DESCRIPTION("Dell laptop driver");
  709. MODULE_LICENSE("GPL");