dell-laptop.c 19 KB

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