/drivers/platform/x86/eeepc-laptop.c

http://github.com/mirrors/linux · C · 1513 lines · 1130 code · 259 blank · 124 comment · 165 complexity · a6cac80b7a3ade0bbd786a82a1670dbe MD5 · raw file

  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * eeepc-laptop.c - Asus Eee PC extras
  4. *
  5. * Based on asus_acpi.c as patched for the Eee PC by Asus:
  6. * ftp://ftp.asus.com/pub/ASUS/EeePC/701/ASUS_ACPI_071126.rar
  7. * Based on eee.c from eeepc-linux
  8. */
  9. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/types.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/backlight.h>
  16. #include <linux/fb.h>
  17. #include <linux/hwmon.h>
  18. #include <linux/hwmon-sysfs.h>
  19. #include <linux/slab.h>
  20. #include <linux/acpi.h>
  21. #include <linux/uaccess.h>
  22. #include <linux/input.h>
  23. #include <linux/input/sparse-keymap.h>
  24. #include <linux/rfkill.h>
  25. #include <linux/pci.h>
  26. #include <linux/pci_hotplug.h>
  27. #include <linux/leds.h>
  28. #include <linux/dmi.h>
  29. #include <acpi/video.h>
  30. #define EEEPC_LAPTOP_VERSION "0.1"
  31. #define EEEPC_LAPTOP_NAME "Eee PC Hotkey Driver"
  32. #define EEEPC_LAPTOP_FILE "eeepc"
  33. #define EEEPC_ACPI_CLASS "hotkey"
  34. #define EEEPC_ACPI_DEVICE_NAME "Hotkey"
  35. #define EEEPC_ACPI_HID "ASUS010"
  36. MODULE_AUTHOR("Corentin Chary, Eric Cooper");
  37. MODULE_DESCRIPTION(EEEPC_LAPTOP_NAME);
  38. MODULE_LICENSE("GPL");
  39. static bool hotplug_disabled;
  40. module_param(hotplug_disabled, bool, 0444);
  41. MODULE_PARM_DESC(hotplug_disabled,
  42. "Disable hotplug for wireless device. "
  43. "If your laptop need that, please report to "
  44. "acpi4asus-user@lists.sourceforge.net.");
  45. /*
  46. * Definitions for Asus EeePC
  47. */
  48. #define NOTIFY_BRN_MIN 0x20
  49. #define NOTIFY_BRN_MAX 0x2f
  50. enum {
  51. DISABLE_ASL_WLAN = 0x0001,
  52. DISABLE_ASL_BLUETOOTH = 0x0002,
  53. DISABLE_ASL_IRDA = 0x0004,
  54. DISABLE_ASL_CAMERA = 0x0008,
  55. DISABLE_ASL_TV = 0x0010,
  56. DISABLE_ASL_GPS = 0x0020,
  57. DISABLE_ASL_DISPLAYSWITCH = 0x0040,
  58. DISABLE_ASL_MODEM = 0x0080,
  59. DISABLE_ASL_CARDREADER = 0x0100,
  60. DISABLE_ASL_3G = 0x0200,
  61. DISABLE_ASL_WIMAX = 0x0400,
  62. DISABLE_ASL_HWCF = 0x0800
  63. };
  64. enum {
  65. CM_ASL_WLAN = 0,
  66. CM_ASL_BLUETOOTH,
  67. CM_ASL_IRDA,
  68. CM_ASL_1394,
  69. CM_ASL_CAMERA,
  70. CM_ASL_TV,
  71. CM_ASL_GPS,
  72. CM_ASL_DVDROM,
  73. CM_ASL_DISPLAYSWITCH,
  74. CM_ASL_PANELBRIGHT,
  75. CM_ASL_BIOSFLASH,
  76. CM_ASL_ACPIFLASH,
  77. CM_ASL_CPUFV,
  78. CM_ASL_CPUTEMPERATURE,
  79. CM_ASL_FANCPU,
  80. CM_ASL_FANCHASSIS,
  81. CM_ASL_USBPORT1,
  82. CM_ASL_USBPORT2,
  83. CM_ASL_USBPORT3,
  84. CM_ASL_MODEM,
  85. CM_ASL_CARDREADER,
  86. CM_ASL_3G,
  87. CM_ASL_WIMAX,
  88. CM_ASL_HWCF,
  89. CM_ASL_LID,
  90. CM_ASL_TYPE,
  91. CM_ASL_PANELPOWER, /*P901*/
  92. CM_ASL_TPD
  93. };
  94. static const char *cm_getv[] = {
  95. "WLDG", "BTHG", NULL, NULL,
  96. "CAMG", NULL, NULL, NULL,
  97. NULL, "PBLG", NULL, NULL,
  98. "CFVG", NULL, NULL, NULL,
  99. "USBG", NULL, NULL, "MODG",
  100. "CRDG", "M3GG", "WIMG", "HWCF",
  101. "LIDG", "TYPE", "PBPG", "TPDG"
  102. };
  103. static const char *cm_setv[] = {
  104. "WLDS", "BTHS", NULL, NULL,
  105. "CAMS", NULL, NULL, NULL,
  106. "SDSP", "PBLS", "HDPS", NULL,
  107. "CFVS", NULL, NULL, NULL,
  108. "USBG", NULL, NULL, "MODS",
  109. "CRDS", "M3GS", "WIMS", NULL,
  110. NULL, NULL, "PBPS", "TPDS"
  111. };
  112. static const struct key_entry eeepc_keymap[] = {
  113. { KE_KEY, 0x10, { KEY_WLAN } },
  114. { KE_KEY, 0x11, { KEY_WLAN } },
  115. { KE_KEY, 0x12, { KEY_PROG1 } },
  116. { KE_KEY, 0x13, { KEY_MUTE } },
  117. { KE_KEY, 0x14, { KEY_VOLUMEDOWN } },
  118. { KE_KEY, 0x15, { KEY_VOLUMEUP } },
  119. { KE_KEY, 0x16, { KEY_DISPLAY_OFF } },
  120. { KE_KEY, 0x1a, { KEY_COFFEE } },
  121. { KE_KEY, 0x1b, { KEY_ZOOM } },
  122. { KE_KEY, 0x1c, { KEY_PROG2 } },
  123. { KE_KEY, 0x1d, { KEY_PROG3 } },
  124. { KE_KEY, NOTIFY_BRN_MIN, { KEY_BRIGHTNESSDOWN } },
  125. { KE_KEY, NOTIFY_BRN_MAX, { KEY_BRIGHTNESSUP } },
  126. { KE_KEY, 0x30, { KEY_SWITCHVIDEOMODE } },
  127. { KE_KEY, 0x31, { KEY_SWITCHVIDEOMODE } },
  128. { KE_KEY, 0x32, { KEY_SWITCHVIDEOMODE } },
  129. { KE_KEY, 0x37, { KEY_F13 } }, /* Disable Touchpad */
  130. { KE_KEY, 0x38, { KEY_F14 } },
  131. { KE_IGNORE, 0x50, { KEY_RESERVED } }, /* AC plugged */
  132. { KE_IGNORE, 0x51, { KEY_RESERVED } }, /* AC unplugged */
  133. { KE_END, 0 },
  134. };
  135. /*
  136. * This is the main structure, we can use it to store useful information
  137. */
  138. struct eeepc_laptop {
  139. acpi_handle handle; /* the handle of the acpi device */
  140. u32 cm_supported; /* the control methods supported
  141. by this BIOS */
  142. bool cpufv_disabled;
  143. bool hotplug_disabled;
  144. u16 event_count[128]; /* count for each event */
  145. struct platform_device *platform_device;
  146. struct acpi_device *device; /* the device we are in */
  147. struct backlight_device *backlight_device;
  148. struct input_dev *inputdev;
  149. struct rfkill *wlan_rfkill;
  150. struct rfkill *bluetooth_rfkill;
  151. struct rfkill *wwan3g_rfkill;
  152. struct rfkill *wimax_rfkill;
  153. struct hotplug_slot hotplug_slot;
  154. struct mutex hotplug_lock;
  155. struct led_classdev tpd_led;
  156. int tpd_led_wk;
  157. struct workqueue_struct *led_workqueue;
  158. struct work_struct tpd_led_work;
  159. };
  160. /*
  161. * ACPI Helpers
  162. */
  163. static int write_acpi_int(acpi_handle handle, const char *method, int val)
  164. {
  165. acpi_status status;
  166. status = acpi_execute_simple_method(handle, (char *)method, val);
  167. return (status == AE_OK ? 0 : -1);
  168. }
  169. static int read_acpi_int(acpi_handle handle, const char *method, int *val)
  170. {
  171. acpi_status status;
  172. unsigned long long result;
  173. status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
  174. if (ACPI_FAILURE(status)) {
  175. *val = -1;
  176. return -1;
  177. } else {
  178. *val = result;
  179. return 0;
  180. }
  181. }
  182. static int set_acpi(struct eeepc_laptop *eeepc, int cm, int value)
  183. {
  184. const char *method = cm_setv[cm];
  185. if (method == NULL)
  186. return -ENODEV;
  187. if ((eeepc->cm_supported & (0x1 << cm)) == 0)
  188. return -ENODEV;
  189. if (write_acpi_int(eeepc->handle, method, value))
  190. pr_warn("Error writing %s\n", method);
  191. return 0;
  192. }
  193. static int get_acpi(struct eeepc_laptop *eeepc, int cm)
  194. {
  195. const char *method = cm_getv[cm];
  196. int value;
  197. if (method == NULL)
  198. return -ENODEV;
  199. if ((eeepc->cm_supported & (0x1 << cm)) == 0)
  200. return -ENODEV;
  201. if (read_acpi_int(eeepc->handle, method, &value))
  202. pr_warn("Error reading %s\n", method);
  203. return value;
  204. }
  205. static int acpi_setter_handle(struct eeepc_laptop *eeepc, int cm,
  206. acpi_handle *handle)
  207. {
  208. const char *method = cm_setv[cm];
  209. acpi_status status;
  210. if (method == NULL)
  211. return -ENODEV;
  212. if ((eeepc->cm_supported & (0x1 << cm)) == 0)
  213. return -ENODEV;
  214. status = acpi_get_handle(eeepc->handle, (char *)method,
  215. handle);
  216. if (status != AE_OK) {
  217. pr_warn("Error finding %s\n", method);
  218. return -ENODEV;
  219. }
  220. return 0;
  221. }
  222. /*
  223. * Sys helpers
  224. */
  225. static int parse_arg(const char *buf, int *val)
  226. {
  227. if (sscanf(buf, "%i", val) != 1)
  228. return -EINVAL;
  229. return 0;
  230. }
  231. static ssize_t store_sys_acpi(struct device *dev, int cm,
  232. const char *buf, size_t count)
  233. {
  234. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  235. int rv, value;
  236. rv = parse_arg(buf, &value);
  237. if (rv < 0)
  238. return rv;
  239. rv = set_acpi(eeepc, cm, value);
  240. if (rv < 0)
  241. return -EIO;
  242. return count;
  243. }
  244. static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf)
  245. {
  246. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  247. int value = get_acpi(eeepc, cm);
  248. if (value < 0)
  249. return -EIO;
  250. return sprintf(buf, "%d\n", value);
  251. }
  252. #define EEEPC_ACPI_SHOW_FUNC(_name, _cm) \
  253. static ssize_t _name##_show(struct device *dev, \
  254. struct device_attribute *attr, \
  255. char *buf) \
  256. { \
  257. return show_sys_acpi(dev, _cm, buf); \
  258. }
  259. #define EEEPC_ACPI_STORE_FUNC(_name, _cm) \
  260. static ssize_t _name##_store(struct device *dev, \
  261. struct device_attribute *attr, \
  262. const char *buf, size_t count) \
  263. { \
  264. return store_sys_acpi(dev, _cm, buf, count); \
  265. }
  266. #define EEEPC_CREATE_DEVICE_ATTR_RW(_name, _cm) \
  267. EEEPC_ACPI_SHOW_FUNC(_name, _cm) \
  268. EEEPC_ACPI_STORE_FUNC(_name, _cm) \
  269. static DEVICE_ATTR_RW(_name)
  270. #define EEEPC_CREATE_DEVICE_ATTR_WO(_name, _cm) \
  271. EEEPC_ACPI_STORE_FUNC(_name, _cm) \
  272. static DEVICE_ATTR_WO(_name)
  273. EEEPC_CREATE_DEVICE_ATTR_RW(camera, CM_ASL_CAMERA);
  274. EEEPC_CREATE_DEVICE_ATTR_RW(cardr, CM_ASL_CARDREADER);
  275. EEEPC_CREATE_DEVICE_ATTR_WO(disp, CM_ASL_DISPLAYSWITCH);
  276. struct eeepc_cpufv {
  277. int num;
  278. int cur;
  279. };
  280. static int get_cpufv(struct eeepc_laptop *eeepc, struct eeepc_cpufv *c)
  281. {
  282. c->cur = get_acpi(eeepc, CM_ASL_CPUFV);
  283. if (c->cur < 0)
  284. return -ENODEV;
  285. c->num = (c->cur >> 8) & 0xff;
  286. c->cur &= 0xff;
  287. if (c->num == 0 || c->num > 12)
  288. return -ENODEV;
  289. return 0;
  290. }
  291. static ssize_t available_cpufv_show(struct device *dev,
  292. struct device_attribute *attr,
  293. char *buf)
  294. {
  295. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  296. struct eeepc_cpufv c;
  297. int i;
  298. ssize_t len = 0;
  299. if (get_cpufv(eeepc, &c))
  300. return -ENODEV;
  301. for (i = 0; i < c.num; i++)
  302. len += sprintf(buf + len, "%d ", i);
  303. len += sprintf(buf + len, "\n");
  304. return len;
  305. }
  306. static ssize_t cpufv_show(struct device *dev,
  307. struct device_attribute *attr,
  308. char *buf)
  309. {
  310. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  311. struct eeepc_cpufv c;
  312. if (get_cpufv(eeepc, &c))
  313. return -ENODEV;
  314. return sprintf(buf, "%#x\n", (c.num << 8) | c.cur);
  315. }
  316. static ssize_t cpufv_store(struct device *dev,
  317. struct device_attribute *attr,
  318. const char *buf, size_t count)
  319. {
  320. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  321. struct eeepc_cpufv c;
  322. int rv, value;
  323. if (eeepc->cpufv_disabled)
  324. return -EPERM;
  325. if (get_cpufv(eeepc, &c))
  326. return -ENODEV;
  327. rv = parse_arg(buf, &value);
  328. if (rv < 0)
  329. return rv;
  330. if (value < 0 || value >= c.num)
  331. return -EINVAL;
  332. rv = set_acpi(eeepc, CM_ASL_CPUFV, value);
  333. if (rv)
  334. return rv;
  335. return count;
  336. }
  337. static ssize_t cpufv_disabled_show(struct device *dev,
  338. struct device_attribute *attr,
  339. char *buf)
  340. {
  341. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  342. return sprintf(buf, "%d\n", eeepc->cpufv_disabled);
  343. }
  344. static ssize_t cpufv_disabled_store(struct device *dev,
  345. struct device_attribute *attr,
  346. const char *buf, size_t count)
  347. {
  348. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  349. int rv, value;
  350. rv = parse_arg(buf, &value);
  351. if (rv < 0)
  352. return rv;
  353. switch (value) {
  354. case 0:
  355. if (eeepc->cpufv_disabled)
  356. pr_warn("cpufv enabled (not officially supported on this model)\n");
  357. eeepc->cpufv_disabled = false;
  358. return count;
  359. case 1:
  360. return -EPERM;
  361. default:
  362. return -EINVAL;
  363. }
  364. }
  365. static DEVICE_ATTR_RW(cpufv);
  366. static DEVICE_ATTR_RO(available_cpufv);
  367. static DEVICE_ATTR_RW(cpufv_disabled);
  368. static struct attribute *platform_attributes[] = {
  369. &dev_attr_camera.attr,
  370. &dev_attr_cardr.attr,
  371. &dev_attr_disp.attr,
  372. &dev_attr_cpufv.attr,
  373. &dev_attr_available_cpufv.attr,
  374. &dev_attr_cpufv_disabled.attr,
  375. NULL
  376. };
  377. static const struct attribute_group platform_attribute_group = {
  378. .attrs = platform_attributes
  379. };
  380. static int eeepc_platform_init(struct eeepc_laptop *eeepc)
  381. {
  382. int result;
  383. eeepc->platform_device = platform_device_alloc(EEEPC_LAPTOP_FILE, -1);
  384. if (!eeepc->platform_device)
  385. return -ENOMEM;
  386. platform_set_drvdata(eeepc->platform_device, eeepc);
  387. result = platform_device_add(eeepc->platform_device);
  388. if (result)
  389. goto fail_platform_device;
  390. result = sysfs_create_group(&eeepc->platform_device->dev.kobj,
  391. &platform_attribute_group);
  392. if (result)
  393. goto fail_sysfs;
  394. return 0;
  395. fail_sysfs:
  396. platform_device_del(eeepc->platform_device);
  397. fail_platform_device:
  398. platform_device_put(eeepc->platform_device);
  399. return result;
  400. }
  401. static void eeepc_platform_exit(struct eeepc_laptop *eeepc)
  402. {
  403. sysfs_remove_group(&eeepc->platform_device->dev.kobj,
  404. &platform_attribute_group);
  405. platform_device_unregister(eeepc->platform_device);
  406. }
  407. /*
  408. * LEDs
  409. */
  410. /*
  411. * These functions actually update the LED's, and are called from a
  412. * workqueue. By doing this as separate work rather than when the LED
  413. * subsystem asks, we avoid messing with the Asus ACPI stuff during a
  414. * potentially bad time, such as a timer interrupt.
  415. */
  416. static void tpd_led_update(struct work_struct *work)
  417. {
  418. struct eeepc_laptop *eeepc;
  419. eeepc = container_of(work, struct eeepc_laptop, tpd_led_work);
  420. set_acpi(eeepc, CM_ASL_TPD, eeepc->tpd_led_wk);
  421. }
  422. static void tpd_led_set(struct led_classdev *led_cdev,
  423. enum led_brightness value)
  424. {
  425. struct eeepc_laptop *eeepc;
  426. eeepc = container_of(led_cdev, struct eeepc_laptop, tpd_led);
  427. eeepc->tpd_led_wk = (value > 0) ? 1 : 0;
  428. queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work);
  429. }
  430. static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
  431. {
  432. struct eeepc_laptop *eeepc;
  433. eeepc = container_of(led_cdev, struct eeepc_laptop, tpd_led);
  434. return get_acpi(eeepc, CM_ASL_TPD);
  435. }
  436. static int eeepc_led_init(struct eeepc_laptop *eeepc)
  437. {
  438. int rv;
  439. if (get_acpi(eeepc, CM_ASL_TPD) == -ENODEV)
  440. return 0;
  441. eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue");
  442. if (!eeepc->led_workqueue)
  443. return -ENOMEM;
  444. INIT_WORK(&eeepc->tpd_led_work, tpd_led_update);
  445. eeepc->tpd_led.name = "eeepc::touchpad";
  446. eeepc->tpd_led.brightness_set = tpd_led_set;
  447. if (get_acpi(eeepc, CM_ASL_TPD) >= 0) /* if method is available */
  448. eeepc->tpd_led.brightness_get = tpd_led_get;
  449. eeepc->tpd_led.max_brightness = 1;
  450. rv = led_classdev_register(&eeepc->platform_device->dev,
  451. &eeepc->tpd_led);
  452. if (rv) {
  453. destroy_workqueue(eeepc->led_workqueue);
  454. return rv;
  455. }
  456. return 0;
  457. }
  458. static void eeepc_led_exit(struct eeepc_laptop *eeepc)
  459. {
  460. if (!IS_ERR_OR_NULL(eeepc->tpd_led.dev))
  461. led_classdev_unregister(&eeepc->tpd_led);
  462. if (eeepc->led_workqueue)
  463. destroy_workqueue(eeepc->led_workqueue);
  464. }
  465. /*
  466. * PCI hotplug (for wlan rfkill)
  467. */
  468. static bool eeepc_wlan_rfkill_blocked(struct eeepc_laptop *eeepc)
  469. {
  470. if (get_acpi(eeepc, CM_ASL_WLAN) == 1)
  471. return false;
  472. return true;
  473. }
  474. static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle)
  475. {
  476. struct pci_dev *port;
  477. struct pci_dev *dev;
  478. struct pci_bus *bus;
  479. bool blocked = eeepc_wlan_rfkill_blocked(eeepc);
  480. bool absent;
  481. u32 l;
  482. if (eeepc->wlan_rfkill)
  483. rfkill_set_sw_state(eeepc->wlan_rfkill, blocked);
  484. mutex_lock(&eeepc->hotplug_lock);
  485. pci_lock_rescan_remove();
  486. if (!eeepc->hotplug_slot.ops)
  487. goto out_unlock;
  488. port = acpi_get_pci_dev(handle);
  489. if (!port) {
  490. pr_warn("Unable to find port\n");
  491. goto out_unlock;
  492. }
  493. bus = port->subordinate;
  494. if (!bus) {
  495. pr_warn("Unable to find PCI bus 1?\n");
  496. goto out_put_dev;
  497. }
  498. if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
  499. pr_err("Unable to read PCI config space?\n");
  500. goto out_put_dev;
  501. }
  502. absent = (l == 0xffffffff);
  503. if (blocked != absent) {
  504. pr_warn("BIOS says wireless lan is %s, but the pci device is %s\n",
  505. blocked ? "blocked" : "unblocked",
  506. absent ? "absent" : "present");
  507. pr_warn("skipped wireless hotplug as probably inappropriate for this model\n");
  508. goto out_put_dev;
  509. }
  510. if (!blocked) {
  511. dev = pci_get_slot(bus, 0);
  512. if (dev) {
  513. /* Device already present */
  514. pci_dev_put(dev);
  515. goto out_put_dev;
  516. }
  517. dev = pci_scan_single_device(bus, 0);
  518. if (dev) {
  519. pci_bus_assign_resources(bus);
  520. pci_bus_add_device(dev);
  521. }
  522. } else {
  523. dev = pci_get_slot(bus, 0);
  524. if (dev) {
  525. pci_stop_and_remove_bus_device(dev);
  526. pci_dev_put(dev);
  527. }
  528. }
  529. out_put_dev:
  530. pci_dev_put(port);
  531. out_unlock:
  532. pci_unlock_rescan_remove();
  533. mutex_unlock(&eeepc->hotplug_lock);
  534. }
  535. static void eeepc_rfkill_hotplug_update(struct eeepc_laptop *eeepc, char *node)
  536. {
  537. acpi_status status = AE_OK;
  538. acpi_handle handle;
  539. status = acpi_get_handle(NULL, node, &handle);
  540. if (ACPI_SUCCESS(status))
  541. eeepc_rfkill_hotplug(eeepc, handle);
  542. }
  543. static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
  544. {
  545. struct eeepc_laptop *eeepc = data;
  546. if (event != ACPI_NOTIFY_BUS_CHECK)
  547. return;
  548. eeepc_rfkill_hotplug(eeepc, handle);
  549. }
  550. static int eeepc_register_rfkill_notifier(struct eeepc_laptop *eeepc,
  551. char *node)
  552. {
  553. acpi_status status;
  554. acpi_handle handle;
  555. status = acpi_get_handle(NULL, node, &handle);
  556. if (ACPI_FAILURE(status))
  557. return -ENODEV;
  558. status = acpi_install_notify_handler(handle,
  559. ACPI_SYSTEM_NOTIFY,
  560. eeepc_rfkill_notify,
  561. eeepc);
  562. if (ACPI_FAILURE(status))
  563. pr_warn("Failed to register notify on %s\n", node);
  564. /*
  565. * Refresh pci hotplug in case the rfkill state was
  566. * changed during setup.
  567. */
  568. eeepc_rfkill_hotplug(eeepc, handle);
  569. return 0;
  570. }
  571. static void eeepc_unregister_rfkill_notifier(struct eeepc_laptop *eeepc,
  572. char *node)
  573. {
  574. acpi_status status = AE_OK;
  575. acpi_handle handle;
  576. status = acpi_get_handle(NULL, node, &handle);
  577. if (ACPI_FAILURE(status))
  578. return;
  579. status = acpi_remove_notify_handler(handle,
  580. ACPI_SYSTEM_NOTIFY,
  581. eeepc_rfkill_notify);
  582. if (ACPI_FAILURE(status))
  583. pr_err("Error removing rfkill notify handler %s\n",
  584. node);
  585. /*
  586. * Refresh pci hotplug in case the rfkill
  587. * state was changed after
  588. * eeepc_unregister_rfkill_notifier()
  589. */
  590. eeepc_rfkill_hotplug(eeepc, handle);
  591. }
  592. static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
  593. u8 *value)
  594. {
  595. struct eeepc_laptop *eeepc;
  596. int val;
  597. eeepc = container_of(hotplug_slot, struct eeepc_laptop, hotplug_slot);
  598. val = get_acpi(eeepc, CM_ASL_WLAN);
  599. if (val == 1 || val == 0)
  600. *value = val;
  601. else
  602. return -EINVAL;
  603. return 0;
  604. }
  605. static const struct hotplug_slot_ops eeepc_hotplug_slot_ops = {
  606. .get_adapter_status = eeepc_get_adapter_status,
  607. .get_power_status = eeepc_get_adapter_status,
  608. };
  609. static int eeepc_setup_pci_hotplug(struct eeepc_laptop *eeepc)
  610. {
  611. int ret = -ENOMEM;
  612. struct pci_bus *bus = pci_find_bus(0, 1);
  613. if (!bus) {
  614. pr_err("Unable to find wifi PCI bus\n");
  615. return -ENODEV;
  616. }
  617. eeepc->hotplug_slot.ops = &eeepc_hotplug_slot_ops;
  618. ret = pci_hp_register(&eeepc->hotplug_slot, bus, 0, "eeepc-wifi");
  619. if (ret) {
  620. pr_err("Unable to register hotplug slot - %d\n", ret);
  621. goto error_register;
  622. }
  623. return 0;
  624. error_register:
  625. eeepc->hotplug_slot.ops = NULL;
  626. return ret;
  627. }
  628. /*
  629. * Rfkill devices
  630. */
  631. static int eeepc_rfkill_set(void *data, bool blocked)
  632. {
  633. acpi_handle handle = data;
  634. return write_acpi_int(handle, NULL, !blocked);
  635. }
  636. static const struct rfkill_ops eeepc_rfkill_ops = {
  637. .set_block = eeepc_rfkill_set,
  638. };
  639. static int eeepc_new_rfkill(struct eeepc_laptop *eeepc,
  640. struct rfkill **rfkill,
  641. const char *name,
  642. enum rfkill_type type, int cm)
  643. {
  644. acpi_handle handle;
  645. int result;
  646. result = acpi_setter_handle(eeepc, cm, &handle);
  647. if (result < 0)
  648. return result;
  649. *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
  650. &eeepc_rfkill_ops, handle);
  651. if (!*rfkill)
  652. return -EINVAL;
  653. rfkill_init_sw_state(*rfkill, get_acpi(eeepc, cm) != 1);
  654. result = rfkill_register(*rfkill);
  655. if (result) {
  656. rfkill_destroy(*rfkill);
  657. *rfkill = NULL;
  658. return result;
  659. }
  660. return 0;
  661. }
  662. static char EEEPC_RFKILL_NODE_1[] = "\\_SB.PCI0.P0P5";
  663. static char EEEPC_RFKILL_NODE_2[] = "\\_SB.PCI0.P0P6";
  664. static char EEEPC_RFKILL_NODE_3[] = "\\_SB.PCI0.P0P7";
  665. static void eeepc_rfkill_exit(struct eeepc_laptop *eeepc)
  666. {
  667. eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_1);
  668. eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_2);
  669. eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_3);
  670. if (eeepc->wlan_rfkill) {
  671. rfkill_unregister(eeepc->wlan_rfkill);
  672. rfkill_destroy(eeepc->wlan_rfkill);
  673. eeepc->wlan_rfkill = NULL;
  674. }
  675. if (eeepc->hotplug_slot.ops)
  676. pci_hp_deregister(&eeepc->hotplug_slot);
  677. if (eeepc->bluetooth_rfkill) {
  678. rfkill_unregister(eeepc->bluetooth_rfkill);
  679. rfkill_destroy(eeepc->bluetooth_rfkill);
  680. eeepc->bluetooth_rfkill = NULL;
  681. }
  682. if (eeepc->wwan3g_rfkill) {
  683. rfkill_unregister(eeepc->wwan3g_rfkill);
  684. rfkill_destroy(eeepc->wwan3g_rfkill);
  685. eeepc->wwan3g_rfkill = NULL;
  686. }
  687. if (eeepc->wimax_rfkill) {
  688. rfkill_unregister(eeepc->wimax_rfkill);
  689. rfkill_destroy(eeepc->wimax_rfkill);
  690. eeepc->wimax_rfkill = NULL;
  691. }
  692. }
  693. static int eeepc_rfkill_init(struct eeepc_laptop *eeepc)
  694. {
  695. int result = 0;
  696. mutex_init(&eeepc->hotplug_lock);
  697. result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill,
  698. "eeepc-wlan", RFKILL_TYPE_WLAN,
  699. CM_ASL_WLAN);
  700. if (result && result != -ENODEV)
  701. goto exit;
  702. result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill,
  703. "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH,
  704. CM_ASL_BLUETOOTH);
  705. if (result && result != -ENODEV)
  706. goto exit;
  707. result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill,
  708. "eeepc-wwan3g", RFKILL_TYPE_WWAN,
  709. CM_ASL_3G);
  710. if (result && result != -ENODEV)
  711. goto exit;
  712. result = eeepc_new_rfkill(eeepc, &eeepc->wimax_rfkill,
  713. "eeepc-wimax", RFKILL_TYPE_WIMAX,
  714. CM_ASL_WIMAX);
  715. if (result && result != -ENODEV)
  716. goto exit;
  717. if (eeepc->hotplug_disabled)
  718. return 0;
  719. result = eeepc_setup_pci_hotplug(eeepc);
  720. /*
  721. * If we get -EBUSY then something else is handling the PCI hotplug -
  722. * don't fail in this case
  723. */
  724. if (result == -EBUSY)
  725. result = 0;
  726. eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_1);
  727. eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_2);
  728. eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_3);
  729. exit:
  730. if (result && result != -ENODEV)
  731. eeepc_rfkill_exit(eeepc);
  732. return result;
  733. }
  734. /*
  735. * Platform driver - hibernate/resume callbacks
  736. */
  737. static int eeepc_hotk_thaw(struct device *device)
  738. {
  739. struct eeepc_laptop *eeepc = dev_get_drvdata(device);
  740. if (eeepc->wlan_rfkill) {
  741. int wlan;
  742. /*
  743. * Work around bios bug - acpi _PTS turns off the wireless led
  744. * during suspend. Normally it restores it on resume, but
  745. * we should kick it ourselves in case hibernation is aborted.
  746. */
  747. wlan = get_acpi(eeepc, CM_ASL_WLAN);
  748. if (wlan >= 0)
  749. set_acpi(eeepc, CM_ASL_WLAN, wlan);
  750. }
  751. return 0;
  752. }
  753. static int eeepc_hotk_restore(struct device *device)
  754. {
  755. struct eeepc_laptop *eeepc = dev_get_drvdata(device);
  756. /* Refresh both wlan rfkill state and pci hotplug */
  757. if (eeepc->wlan_rfkill) {
  758. eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_1);
  759. eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_2);
  760. eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_3);
  761. }
  762. if (eeepc->bluetooth_rfkill)
  763. rfkill_set_sw_state(eeepc->bluetooth_rfkill,
  764. get_acpi(eeepc, CM_ASL_BLUETOOTH) != 1);
  765. if (eeepc->wwan3g_rfkill)
  766. rfkill_set_sw_state(eeepc->wwan3g_rfkill,
  767. get_acpi(eeepc, CM_ASL_3G) != 1);
  768. if (eeepc->wimax_rfkill)
  769. rfkill_set_sw_state(eeepc->wimax_rfkill,
  770. get_acpi(eeepc, CM_ASL_WIMAX) != 1);
  771. return 0;
  772. }
  773. static const struct dev_pm_ops eeepc_pm_ops = {
  774. .thaw = eeepc_hotk_thaw,
  775. .restore = eeepc_hotk_restore,
  776. };
  777. static struct platform_driver platform_driver = {
  778. .driver = {
  779. .name = EEEPC_LAPTOP_FILE,
  780. .pm = &eeepc_pm_ops,
  781. }
  782. };
  783. /*
  784. * Hwmon device
  785. */
  786. #define EEEPC_EC_SC00 0x61
  787. #define EEEPC_EC_FAN_PWM (EEEPC_EC_SC00 + 2) /* Fan PWM duty cycle (%) */
  788. #define EEEPC_EC_FAN_HRPM (EEEPC_EC_SC00 + 5) /* High byte, fan speed (RPM) */
  789. #define EEEPC_EC_FAN_LRPM (EEEPC_EC_SC00 + 6) /* Low byte, fan speed (RPM) */
  790. #define EEEPC_EC_SFB0 0xD0
  791. #define EEEPC_EC_FAN_CTRL (EEEPC_EC_SFB0 + 3) /* Byte containing SF25 */
  792. static inline int eeepc_pwm_to_lmsensors(int value)
  793. {
  794. return value * 255 / 100;
  795. }
  796. static inline int eeepc_lmsensors_to_pwm(int value)
  797. {
  798. value = clamp_val(value, 0, 255);
  799. return value * 100 / 255;
  800. }
  801. static int eeepc_get_fan_pwm(void)
  802. {
  803. u8 value = 0;
  804. ec_read(EEEPC_EC_FAN_PWM, &value);
  805. return eeepc_pwm_to_lmsensors(value);
  806. }
  807. static void eeepc_set_fan_pwm(int value)
  808. {
  809. value = eeepc_lmsensors_to_pwm(value);
  810. ec_write(EEEPC_EC_FAN_PWM, value);
  811. }
  812. static int eeepc_get_fan_rpm(void)
  813. {
  814. u8 high = 0;
  815. u8 low = 0;
  816. ec_read(EEEPC_EC_FAN_HRPM, &high);
  817. ec_read(EEEPC_EC_FAN_LRPM, &low);
  818. return high << 8 | low;
  819. }
  820. #define EEEPC_EC_FAN_CTRL_BIT 0x02
  821. #define EEEPC_FAN_CTRL_MANUAL 1
  822. #define EEEPC_FAN_CTRL_AUTO 2
  823. static int eeepc_get_fan_ctrl(void)
  824. {
  825. u8 value = 0;
  826. ec_read(EEEPC_EC_FAN_CTRL, &value);
  827. if (value & EEEPC_EC_FAN_CTRL_BIT)
  828. return EEEPC_FAN_CTRL_MANUAL;
  829. else
  830. return EEEPC_FAN_CTRL_AUTO;
  831. }
  832. static void eeepc_set_fan_ctrl(int manual)
  833. {
  834. u8 value = 0;
  835. ec_read(EEEPC_EC_FAN_CTRL, &value);
  836. if (manual == EEEPC_FAN_CTRL_MANUAL)
  837. value |= EEEPC_EC_FAN_CTRL_BIT;
  838. else
  839. value &= ~EEEPC_EC_FAN_CTRL_BIT;
  840. ec_write(EEEPC_EC_FAN_CTRL, value);
  841. }
  842. static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
  843. {
  844. int rv, value;
  845. rv = parse_arg(buf, &value);
  846. if (rv < 0)
  847. return rv;
  848. set(value);
  849. return count;
  850. }
  851. static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
  852. {
  853. return sprintf(buf, "%d\n", get());
  854. }
  855. #define EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
  856. static ssize_t _name##_show(struct device *dev, \
  857. struct device_attribute *attr, \
  858. char *buf) \
  859. { \
  860. return show_sys_hwmon(_get, buf); \
  861. }
  862. #define EEEPC_SENSOR_STORE_FUNC(_name, _set) \
  863. static ssize_t _name##_store(struct device *dev, \
  864. struct device_attribute *attr, \
  865. const char *buf, size_t count) \
  866. { \
  867. return store_sys_hwmon(_set, buf, count); \
  868. }
  869. #define EEEPC_CREATE_SENSOR_ATTR_RW(_name, _get, _set) \
  870. EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
  871. EEEPC_SENSOR_STORE_FUNC(_name, _set) \
  872. static DEVICE_ATTR_RW(_name)
  873. #define EEEPC_CREATE_SENSOR_ATTR_RO(_name, _get) \
  874. EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
  875. static DEVICE_ATTR_RO(_name)
  876. EEEPC_CREATE_SENSOR_ATTR_RO(fan1_input, eeepc_get_fan_rpm);
  877. EEEPC_CREATE_SENSOR_ATTR_RW(pwm1, eeepc_get_fan_pwm,
  878. eeepc_set_fan_pwm);
  879. EEEPC_CREATE_SENSOR_ATTR_RW(pwm1_enable, eeepc_get_fan_ctrl,
  880. eeepc_set_fan_ctrl);
  881. static struct attribute *hwmon_attrs[] = {
  882. &dev_attr_pwm1.attr,
  883. &dev_attr_fan1_input.attr,
  884. &dev_attr_pwm1_enable.attr,
  885. NULL
  886. };
  887. ATTRIBUTE_GROUPS(hwmon);
  888. static int eeepc_hwmon_init(struct eeepc_laptop *eeepc)
  889. {
  890. struct device *dev = &eeepc->platform_device->dev;
  891. struct device *hwmon;
  892. hwmon = devm_hwmon_device_register_with_groups(dev, "eeepc", NULL,
  893. hwmon_groups);
  894. if (IS_ERR(hwmon)) {
  895. pr_err("Could not register eeepc hwmon device\n");
  896. return PTR_ERR(hwmon);
  897. }
  898. return 0;
  899. }
  900. /*
  901. * Backlight device
  902. */
  903. static int read_brightness(struct backlight_device *bd)
  904. {
  905. struct eeepc_laptop *eeepc = bl_get_data(bd);
  906. return get_acpi(eeepc, CM_ASL_PANELBRIGHT);
  907. }
  908. static int set_brightness(struct backlight_device *bd, int value)
  909. {
  910. struct eeepc_laptop *eeepc = bl_get_data(bd);
  911. return set_acpi(eeepc, CM_ASL_PANELBRIGHT, value);
  912. }
  913. static int update_bl_status(struct backlight_device *bd)
  914. {
  915. return set_brightness(bd, bd->props.brightness);
  916. }
  917. static const struct backlight_ops eeepcbl_ops = {
  918. .get_brightness = read_brightness,
  919. .update_status = update_bl_status,
  920. };
  921. static int eeepc_backlight_notify(struct eeepc_laptop *eeepc)
  922. {
  923. struct backlight_device *bd = eeepc->backlight_device;
  924. int old = bd->props.brightness;
  925. backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
  926. return old;
  927. }
  928. static int eeepc_backlight_init(struct eeepc_laptop *eeepc)
  929. {
  930. struct backlight_properties props;
  931. struct backlight_device *bd;
  932. memset(&props, 0, sizeof(struct backlight_properties));
  933. props.type = BACKLIGHT_PLATFORM;
  934. props.max_brightness = 15;
  935. bd = backlight_device_register(EEEPC_LAPTOP_FILE,
  936. &eeepc->platform_device->dev, eeepc,
  937. &eeepcbl_ops, &props);
  938. if (IS_ERR(bd)) {
  939. pr_err("Could not register eeepc backlight device\n");
  940. eeepc->backlight_device = NULL;
  941. return PTR_ERR(bd);
  942. }
  943. eeepc->backlight_device = bd;
  944. bd->props.brightness = read_brightness(bd);
  945. bd->props.power = FB_BLANK_UNBLANK;
  946. backlight_update_status(bd);
  947. return 0;
  948. }
  949. static void eeepc_backlight_exit(struct eeepc_laptop *eeepc)
  950. {
  951. backlight_device_unregister(eeepc->backlight_device);
  952. eeepc->backlight_device = NULL;
  953. }
  954. /*
  955. * Input device (i.e. hotkeys)
  956. */
  957. static int eeepc_input_init(struct eeepc_laptop *eeepc)
  958. {
  959. struct input_dev *input;
  960. int error;
  961. input = input_allocate_device();
  962. if (!input)
  963. return -ENOMEM;
  964. input->name = "Asus EeePC extra buttons";
  965. input->phys = EEEPC_LAPTOP_FILE "/input0";
  966. input->id.bustype = BUS_HOST;
  967. input->dev.parent = &eeepc->platform_device->dev;
  968. error = sparse_keymap_setup(input, eeepc_keymap, NULL);
  969. if (error) {
  970. pr_err("Unable to setup input device keymap\n");
  971. goto err_free_dev;
  972. }
  973. error = input_register_device(input);
  974. if (error) {
  975. pr_err("Unable to register input device\n");
  976. goto err_free_dev;
  977. }
  978. eeepc->inputdev = input;
  979. return 0;
  980. err_free_dev:
  981. input_free_device(input);
  982. return error;
  983. }
  984. static void eeepc_input_exit(struct eeepc_laptop *eeepc)
  985. {
  986. if (eeepc->inputdev)
  987. input_unregister_device(eeepc->inputdev);
  988. eeepc->inputdev = NULL;
  989. }
  990. /*
  991. * ACPI driver
  992. */
  993. static void eeepc_input_notify(struct eeepc_laptop *eeepc, int event)
  994. {
  995. if (!eeepc->inputdev)
  996. return;
  997. if (!sparse_keymap_report_event(eeepc->inputdev, event, 1, true))
  998. pr_info("Unknown key %x pressed\n", event);
  999. }
  1000. static void eeepc_acpi_notify(struct acpi_device *device, u32 event)
  1001. {
  1002. struct eeepc_laptop *eeepc = acpi_driver_data(device);
  1003. int old_brightness, new_brightness;
  1004. u16 count;
  1005. if (event > ACPI_MAX_SYS_NOTIFY)
  1006. return;
  1007. count = eeepc->event_count[event % 128]++;
  1008. acpi_bus_generate_netlink_event(device->pnp.device_class,
  1009. dev_name(&device->dev), event,
  1010. count);
  1011. /* Brightness events are special */
  1012. if (event < NOTIFY_BRN_MIN || event > NOTIFY_BRN_MAX) {
  1013. eeepc_input_notify(eeepc, event);
  1014. return;
  1015. }
  1016. /* Ignore them completely if the acpi video driver is used */
  1017. if (!eeepc->backlight_device)
  1018. return;
  1019. /* Update the backlight device. */
  1020. old_brightness = eeepc_backlight_notify(eeepc);
  1021. /* Convert event to keypress (obsolescent hack) */
  1022. new_brightness = event - NOTIFY_BRN_MIN;
  1023. if (new_brightness < old_brightness) {
  1024. event = NOTIFY_BRN_MIN; /* brightness down */
  1025. } else if (new_brightness > old_brightness) {
  1026. event = NOTIFY_BRN_MAX; /* brightness up */
  1027. } else {
  1028. /*
  1029. * no change in brightness - already at min/max,
  1030. * event will be desired value (or else ignored)
  1031. */
  1032. }
  1033. eeepc_input_notify(eeepc, event);
  1034. }
  1035. static void eeepc_dmi_check(struct eeepc_laptop *eeepc)
  1036. {
  1037. const char *model;
  1038. model = dmi_get_system_info(DMI_PRODUCT_NAME);
  1039. if (!model)
  1040. return;
  1041. /*
  1042. * Blacklist for setting cpufv (cpu speed).
  1043. *
  1044. * EeePC 4G ("701") implements CFVS, but it is not supported
  1045. * by the pre-installed OS, and the original option to change it
  1046. * in the BIOS setup screen was removed in later versions.
  1047. *
  1048. * Judging by the lack of "Super Hybrid Engine" on Asus product pages,
  1049. * this applies to all "701" models (4G/4G Surf/2G Surf).
  1050. *
  1051. * So Asus made a deliberate decision not to support it on this model.
  1052. * We have several reports that using it can cause the system to hang
  1053. *
  1054. * The hang has also been reported on a "702" (Model name "8G"?).
  1055. *
  1056. * We avoid dmi_check_system() / dmi_match(), because they use
  1057. * substring matching. We don't want to affect the "701SD"
  1058. * and "701SDX" models, because they do support S.H.E.
  1059. */
  1060. if (strcmp(model, "701") == 0 || strcmp(model, "702") == 0) {
  1061. eeepc->cpufv_disabled = true;
  1062. pr_info("model %s does not officially support setting cpu speed\n",
  1063. model);
  1064. pr_info("cpufv disabled to avoid instability\n");
  1065. }
  1066. /*
  1067. * Blacklist for wlan hotplug
  1068. *
  1069. * Eeepc 1005HA doesn't work like others models and don't need the
  1070. * hotplug code. In fact, current hotplug code seems to unplug another
  1071. * device...
  1072. */
  1073. if (strcmp(model, "1005HA") == 0 || strcmp(model, "1201N") == 0 ||
  1074. strcmp(model, "1005PE") == 0) {
  1075. eeepc->hotplug_disabled = true;
  1076. pr_info("wlan hotplug disabled\n");
  1077. }
  1078. }
  1079. static void cmsg_quirk(struct eeepc_laptop *eeepc, int cm, const char *name)
  1080. {
  1081. int dummy;
  1082. /* Some BIOSes do not report cm although it is available.
  1083. Check if cm_getv[cm] works and, if yes, assume cm should be set. */
  1084. if (!(eeepc->cm_supported & (1 << cm))
  1085. && !read_acpi_int(eeepc->handle, cm_getv[cm], &dummy)) {
  1086. pr_info("%s (%x) not reported by BIOS, enabling anyway\n",
  1087. name, 1 << cm);
  1088. eeepc->cm_supported |= 1 << cm;
  1089. }
  1090. }
  1091. static void cmsg_quirks(struct eeepc_laptop *eeepc)
  1092. {
  1093. cmsg_quirk(eeepc, CM_ASL_LID, "LID");
  1094. cmsg_quirk(eeepc, CM_ASL_TYPE, "TYPE");
  1095. cmsg_quirk(eeepc, CM_ASL_PANELPOWER, "PANELPOWER");
  1096. cmsg_quirk(eeepc, CM_ASL_TPD, "TPD");
  1097. }
  1098. static int eeepc_acpi_init(struct eeepc_laptop *eeepc)
  1099. {
  1100. unsigned int init_flags;
  1101. int result;
  1102. result = acpi_bus_get_status(eeepc->device);
  1103. if (result)
  1104. return result;
  1105. if (!eeepc->device->status.present) {
  1106. pr_err("Hotkey device not present, aborting\n");
  1107. return -ENODEV;
  1108. }
  1109. init_flags = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
  1110. pr_notice("Hotkey init flags 0x%x\n", init_flags);
  1111. if (write_acpi_int(eeepc->handle, "INIT", init_flags)) {
  1112. pr_err("Hotkey initialization failed\n");
  1113. return -ENODEV;
  1114. }
  1115. /* get control methods supported */
  1116. if (read_acpi_int(eeepc->handle, "CMSG", &eeepc->cm_supported)) {
  1117. pr_err("Get control methods supported failed\n");
  1118. return -ENODEV;
  1119. }
  1120. cmsg_quirks(eeepc);
  1121. pr_info("Get control methods supported: 0x%x\n", eeepc->cm_supported);
  1122. return 0;
  1123. }
  1124. static void eeepc_enable_camera(struct eeepc_laptop *eeepc)
  1125. {
  1126. /*
  1127. * If the following call to set_acpi() fails, it's because there's no
  1128. * camera so we can ignore the error.
  1129. */
  1130. if (get_acpi(eeepc, CM_ASL_CAMERA) == 0)
  1131. set_acpi(eeepc, CM_ASL_CAMERA, 1);
  1132. }
  1133. static bool eeepc_device_present;
  1134. static int eeepc_acpi_add(struct acpi_device *device)
  1135. {
  1136. struct eeepc_laptop *eeepc;
  1137. int result;
  1138. pr_notice(EEEPC_LAPTOP_NAME "\n");
  1139. eeepc = kzalloc(sizeof(struct eeepc_laptop), GFP_KERNEL);
  1140. if (!eeepc)
  1141. return -ENOMEM;
  1142. eeepc->handle = device->handle;
  1143. strcpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME);
  1144. strcpy(acpi_device_class(device), EEEPC_ACPI_CLASS);
  1145. device->driver_data = eeepc;
  1146. eeepc->device = device;
  1147. eeepc->hotplug_disabled = hotplug_disabled;
  1148. eeepc_dmi_check(eeepc);
  1149. result = eeepc_acpi_init(eeepc);
  1150. if (result)
  1151. goto fail_platform;
  1152. eeepc_enable_camera(eeepc);
  1153. /*
  1154. * Register the platform device first. It is used as a parent for the
  1155. * sub-devices below.
  1156. *
  1157. * Note that if there are multiple instances of this ACPI device it
  1158. * will bail out, because the platform device is registered with a
  1159. * fixed name. Of course it doesn't make sense to have more than one,
  1160. * and machine-specific scripts find the fixed name convenient. But
  1161. * It's also good for us to exclude multiple instances because both
  1162. * our hwmon and our wlan rfkill subdevice use global ACPI objects
  1163. * (the EC and the wlan PCI slot respectively).
  1164. */
  1165. result = eeepc_platform_init(eeepc);
  1166. if (result)
  1167. goto fail_platform;
  1168. if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
  1169. result = eeepc_backlight_init(eeepc);
  1170. if (result)
  1171. goto fail_backlight;
  1172. }
  1173. result = eeepc_input_init(eeepc);
  1174. if (result)
  1175. goto fail_input;
  1176. result = eeepc_hwmon_init(eeepc);
  1177. if (result)
  1178. goto fail_hwmon;
  1179. result = eeepc_led_init(eeepc);
  1180. if (result)
  1181. goto fail_led;
  1182. result = eeepc_rfkill_init(eeepc);
  1183. if (result)
  1184. goto fail_rfkill;
  1185. eeepc_device_present = true;
  1186. return 0;
  1187. fail_rfkill:
  1188. eeepc_led_exit(eeepc);
  1189. fail_led:
  1190. fail_hwmon:
  1191. eeepc_input_exit(eeepc);
  1192. fail_input:
  1193. eeepc_backlight_exit(eeepc);
  1194. fail_backlight:
  1195. eeepc_platform_exit(eeepc);
  1196. fail_platform:
  1197. kfree(eeepc);
  1198. return result;
  1199. }
  1200. static int eeepc_acpi_remove(struct acpi_device *device)
  1201. {
  1202. struct eeepc_laptop *eeepc = acpi_driver_data(device);
  1203. eeepc_backlight_exit(eeepc);
  1204. eeepc_rfkill_exit(eeepc);
  1205. eeepc_input_exit(eeepc);
  1206. eeepc_led_exit(eeepc);
  1207. eeepc_platform_exit(eeepc);
  1208. kfree(eeepc);
  1209. return 0;
  1210. }
  1211. static const struct acpi_device_id eeepc_device_ids[] = {
  1212. {EEEPC_ACPI_HID, 0},
  1213. {"", 0},
  1214. };
  1215. MODULE_DEVICE_TABLE(acpi, eeepc_device_ids);
  1216. static struct acpi_driver eeepc_acpi_driver = {
  1217. .name = EEEPC_LAPTOP_NAME,
  1218. .class = EEEPC_ACPI_CLASS,
  1219. .owner = THIS_MODULE,
  1220. .ids = eeepc_device_ids,
  1221. .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
  1222. .ops = {
  1223. .add = eeepc_acpi_add,
  1224. .remove = eeepc_acpi_remove,
  1225. .notify = eeepc_acpi_notify,
  1226. },
  1227. };
  1228. static int __init eeepc_laptop_init(void)
  1229. {
  1230. int result;
  1231. result = platform_driver_register(&platform_driver);
  1232. if (result < 0)
  1233. return result;
  1234. result = acpi_bus_register_driver(&eeepc_acpi_driver);
  1235. if (result < 0)
  1236. goto fail_acpi_driver;
  1237. if (!eeepc_device_present) {
  1238. result = -ENODEV;
  1239. goto fail_no_device;
  1240. }
  1241. return 0;
  1242. fail_no_device:
  1243. acpi_bus_unregister_driver(&eeepc_acpi_driver);
  1244. fail_acpi_driver:
  1245. platform_driver_unregister(&platform_driver);
  1246. return result;
  1247. }
  1248. static void __exit eeepc_laptop_exit(void)
  1249. {
  1250. acpi_bus_unregister_driver(&eeepc_acpi_driver);
  1251. platform_driver_unregister(&platform_driver);
  1252. }
  1253. module_init(eeepc_laptop_init);
  1254. module_exit(eeepc_laptop_exit);