dell-laptop.c 20 KB

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