dell-laptop.c 18 KB

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