dell-laptop.c 19 KB

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