dell-laptop.c 19 KB

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