eeepc-laptop.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  1. /*
  2. * eeepc-laptop.c - Asus Eee PC extras
  3. *
  4. * Based on asus_acpi.c as patched for the Eee PC by Asus:
  5. * ftp://ftp.asus.com/pub/ASUS/EeePC/701/ASUS_ACPI_071126.rar
  6. * Based on eee.c from eeepc-linux
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/types.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/backlight.h>
  25. #include <linux/fb.h>
  26. #include <linux/hwmon.h>
  27. #include <linux/hwmon-sysfs.h>
  28. #include <acpi/acpi_drivers.h>
  29. #include <acpi/acpi_bus.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/input.h>
  32. #include <linux/rfkill.h>
  33. #include <linux/pci.h>
  34. #include <linux/pci_hotplug.h>
  35. #include <linux/leds.h>
  36. #define EEEPC_LAPTOP_VERSION "0.1"
  37. #define EEEPC_LAPTOP_NAME "Eee PC Hotkey Driver"
  38. #define EEEPC_LAPTOP_FILE "eeepc"
  39. #define EEEPC_ACPI_CLASS "hotkey"
  40. #define EEEPC_ACPI_DEVICE_NAME "Hotkey"
  41. #define EEEPC_ACPI_HID "ASUS010"
  42. MODULE_AUTHOR("Corentin Chary, Eric Cooper");
  43. MODULE_DESCRIPTION(EEEPC_LAPTOP_NAME);
  44. MODULE_LICENSE("GPL");
  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. struct key_entry {
  113. char type;
  114. u8 code;
  115. u16 keycode;
  116. };
  117. enum { KE_KEY, KE_END };
  118. static struct key_entry eeepc_keymap[] = {
  119. /* Sleep already handled via generic ACPI code */
  120. {KE_KEY, 0x10, KEY_WLAN },
  121. {KE_KEY, 0x11, KEY_WLAN },
  122. {KE_KEY, 0x12, KEY_PROG1 },
  123. {KE_KEY, 0x13, KEY_MUTE },
  124. {KE_KEY, 0x14, KEY_VOLUMEDOWN },
  125. {KE_KEY, 0x15, KEY_VOLUMEUP },
  126. {KE_KEY, 0x1a, KEY_COFFEE },
  127. {KE_KEY, 0x1b, KEY_ZOOM },
  128. {KE_KEY, 0x1c, KEY_PROG2 },
  129. {KE_KEY, 0x1d, KEY_PROG3 },
  130. {KE_KEY, NOTIFY_BRN_MIN, KEY_BRIGHTNESSDOWN },
  131. {KE_KEY, NOTIFY_BRN_MAX, KEY_BRIGHTNESSUP },
  132. {KE_KEY, 0x30, KEY_SWITCHVIDEOMODE },
  133. {KE_KEY, 0x31, KEY_SWITCHVIDEOMODE },
  134. {KE_KEY, 0x32, KEY_SWITCHVIDEOMODE },
  135. {KE_END, 0},
  136. };
  137. /*
  138. * This is the main structure, we can use it to store useful information
  139. */
  140. struct eeepc_laptop {
  141. struct acpi_device *device; /* the device we are in */
  142. acpi_handle handle; /* the handle of the hotk device */
  143. u32 cm_supported; /* the control methods supported
  144. by this BIOS */
  145. u16 event_count[128]; /* count for each event */
  146. struct input_dev *inputdev;
  147. u16 *keycode_map;
  148. struct rfkill *wlan_rfkill;
  149. struct rfkill *bluetooth_rfkill;
  150. struct rfkill *wwan3g_rfkill;
  151. struct rfkill *wimax_rfkill;
  152. struct hotplug_slot *hotplug_slot;
  153. struct mutex hotplug_lock;
  154. };
  155. /* The actual device the driver binds to */
  156. static struct eeepc_laptop *eeepc;
  157. /* The platform device */
  158. static struct platform_device *platform_device;
  159. /* The backlight device /sys/class/backlight */
  160. static struct backlight_device *eeepc_backlight_device;
  161. /* The hwmon device */
  162. static struct device *eeepc_hwmon_device;
  163. /*
  164. * ACPI Helpers
  165. */
  166. static int write_acpi_int(acpi_handle handle, const char *method, int val)
  167. {
  168. struct acpi_object_list params;
  169. union acpi_object in_obj;
  170. acpi_status status;
  171. params.count = 1;
  172. params.pointer = &in_obj;
  173. in_obj.type = ACPI_TYPE_INTEGER;
  174. in_obj.integer.value = val;
  175. status = acpi_evaluate_object(handle, (char *)method, &params, NULL);
  176. return (status == AE_OK ? 0 : -1);
  177. }
  178. static int read_acpi_int(acpi_handle handle, const char *method, int *val)
  179. {
  180. acpi_status status;
  181. unsigned long long result;
  182. status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
  183. if (ACPI_FAILURE(status)) {
  184. *val = -1;
  185. return -1;
  186. } else {
  187. *val = result;
  188. return 0;
  189. }
  190. }
  191. static int set_acpi(int cm, int value)
  192. {
  193. const char *method = cm_setv[cm];
  194. if (method == NULL)
  195. return -ENODEV;
  196. if ((eeepc->cm_supported & (0x1 << cm)) == 0)
  197. return -ENODEV;
  198. if (write_acpi_int(eeepc->handle, method, value))
  199. pr_warning("Error writing %s\n", method);
  200. return 0;
  201. }
  202. static int get_acpi(int cm)
  203. {
  204. const char *method = cm_getv[cm];
  205. int value;
  206. if (method == NULL)
  207. return -ENODEV;
  208. if ((eeepc->cm_supported & (0x1 << cm)) == 0)
  209. return -ENODEV;
  210. if (read_acpi_int(eeepc->handle, method, &value))
  211. pr_warning("Error reading %s\n", method);
  212. return value;
  213. }
  214. /*
  215. * Sys helpers
  216. */
  217. static int parse_arg(const char *buf, unsigned long count, int *val)
  218. {
  219. if (!count)
  220. return 0;
  221. if (sscanf(buf, "%i", val) != 1)
  222. return -EINVAL;
  223. return count;
  224. }
  225. static ssize_t store_sys_acpi(int cm, const char *buf, size_t count)
  226. {
  227. int rv, value;
  228. rv = parse_arg(buf, count, &value);
  229. if (rv > 0)
  230. value = set_acpi(cm, value);
  231. if (value < 0)
  232. return -EIO;
  233. return rv;
  234. }
  235. static ssize_t show_sys_acpi(int cm, char *buf)
  236. {
  237. int value = get_acpi(cm);
  238. if (value < 0)
  239. return -EIO;
  240. return sprintf(buf, "%d\n", value);
  241. }
  242. #define EEEPC_CREATE_DEVICE_ATTR(_name, _mode, _cm) \
  243. static ssize_t show_##_name(struct device *dev, \
  244. struct device_attribute *attr, \
  245. char *buf) \
  246. { \
  247. return show_sys_acpi(_cm, buf); \
  248. } \
  249. static ssize_t store_##_name(struct device *dev, \
  250. struct device_attribute *attr, \
  251. const char *buf, size_t count) \
  252. { \
  253. return store_sys_acpi(_cm, buf, count); \
  254. } \
  255. static struct device_attribute dev_attr_##_name = { \
  256. .attr = { \
  257. .name = __stringify(_name), \
  258. .mode = _mode }, \
  259. .show = show_##_name, \
  260. .store = store_##_name, \
  261. }
  262. EEEPC_CREATE_DEVICE_ATTR(camera, 0644, CM_ASL_CAMERA);
  263. EEEPC_CREATE_DEVICE_ATTR(cardr, 0644, CM_ASL_CARDREADER);
  264. EEEPC_CREATE_DEVICE_ATTR(disp, 0200, CM_ASL_DISPLAYSWITCH);
  265. struct eeepc_cpufv {
  266. int num;
  267. int cur;
  268. };
  269. static int get_cpufv(struct eeepc_cpufv *c)
  270. {
  271. c->cur = get_acpi(CM_ASL_CPUFV);
  272. c->num = (c->cur >> 8) & 0xff;
  273. c->cur &= 0xff;
  274. if (c->cur < 0 || c->num <= 0 || c->num > 12)
  275. return -ENODEV;
  276. return 0;
  277. }
  278. static ssize_t show_available_cpufv(struct device *dev,
  279. struct device_attribute *attr,
  280. char *buf)
  281. {
  282. struct eeepc_cpufv c;
  283. int i;
  284. ssize_t len = 0;
  285. if (get_cpufv(&c))
  286. return -ENODEV;
  287. for (i = 0; i < c.num; i++)
  288. len += sprintf(buf + len, "%d ", i);
  289. len += sprintf(buf + len, "\n");
  290. return len;
  291. }
  292. static ssize_t show_cpufv(struct device *dev,
  293. struct device_attribute *attr,
  294. char *buf)
  295. {
  296. struct eeepc_cpufv c;
  297. if (get_cpufv(&c))
  298. return -ENODEV;
  299. return sprintf(buf, "%#x\n", (c.num << 8) | c.cur);
  300. }
  301. static ssize_t store_cpufv(struct device *dev,
  302. struct device_attribute *attr,
  303. const char *buf, size_t count)
  304. {
  305. struct eeepc_cpufv c;
  306. int rv, value;
  307. if (get_cpufv(&c))
  308. return -ENODEV;
  309. rv = parse_arg(buf, count, &value);
  310. if (rv < 0)
  311. return rv;
  312. if (!rv || value < 0 || value >= c.num)
  313. return -EINVAL;
  314. set_acpi(CM_ASL_CPUFV, value);
  315. return rv;
  316. }
  317. static struct device_attribute dev_attr_cpufv = {
  318. .attr = {
  319. .name = "cpufv",
  320. .mode = 0644 },
  321. .show = show_cpufv,
  322. .store = store_cpufv
  323. };
  324. static struct device_attribute dev_attr_available_cpufv = {
  325. .attr = {
  326. .name = "available_cpufv",
  327. .mode = 0444 },
  328. .show = show_available_cpufv
  329. };
  330. static struct attribute *platform_attributes[] = {
  331. &dev_attr_camera.attr,
  332. &dev_attr_cardr.attr,
  333. &dev_attr_disp.attr,
  334. &dev_attr_cpufv.attr,
  335. &dev_attr_available_cpufv.attr,
  336. NULL
  337. };
  338. static struct attribute_group platform_attribute_group = {
  339. .attrs = platform_attributes
  340. };
  341. static int eeepc_platform_init(void)
  342. {
  343. int result;
  344. platform_device = platform_device_alloc(EEEPC_LAPTOP_FILE, -1);
  345. if (!platform_device)
  346. return -ENOMEM;
  347. result = platform_device_add(platform_device);
  348. if (result)
  349. goto fail_platform_device;
  350. result = sysfs_create_group(&platform_device->dev.kobj,
  351. &platform_attribute_group);
  352. if (result)
  353. goto fail_sysfs;
  354. return 0;
  355. fail_sysfs:
  356. platform_device_del(platform_device);
  357. fail_platform_device:
  358. platform_device_put(platform_device);
  359. return result;
  360. }
  361. static void eeepc_platform_exit(void)
  362. {
  363. sysfs_remove_group(&platform_device->dev.kobj,
  364. &platform_attribute_group);
  365. platform_device_unregister(platform_device);
  366. }
  367. /*
  368. * LEDs
  369. */
  370. /*
  371. * These functions actually update the LED's, and are called from a
  372. * workqueue. By doing this as separate work rather than when the LED
  373. * subsystem asks, we avoid messing with the Asus ACPI stuff during a
  374. * potentially bad time, such as a timer interrupt.
  375. */
  376. static int tpd_led_wk;
  377. static void tpd_led_update(struct work_struct *ignored)
  378. {
  379. int value = tpd_led_wk;
  380. set_acpi(CM_ASL_TPD, value);
  381. }
  382. static struct workqueue_struct *led_workqueue;
  383. static DECLARE_WORK(tpd_led_work, tpd_led_update);
  384. static void tpd_led_set(struct led_classdev *led_cdev,
  385. enum led_brightness value)
  386. {
  387. tpd_led_wk = (value > 0) ? 1 : 0;
  388. queue_work(led_workqueue, &tpd_led_work);
  389. }
  390. static struct led_classdev tpd_led = {
  391. .name = "eeepc::touchpad",
  392. .brightness_set = tpd_led_set,
  393. .max_brightness = 1
  394. };
  395. static int eeepc_led_init(struct device *dev)
  396. {
  397. int rv;
  398. if (get_acpi(CM_ASL_TPD) == -ENODEV)
  399. return 0;
  400. led_workqueue = create_singlethread_workqueue("led_workqueue");
  401. if (!led_workqueue)
  402. return -ENOMEM;
  403. rv = led_classdev_register(dev, &tpd_led);
  404. if (rv) {
  405. destroy_workqueue(led_workqueue);
  406. return rv;
  407. }
  408. return 0;
  409. }
  410. static void eeepc_led_exit(void)
  411. {
  412. if (tpd_led.dev)
  413. led_classdev_unregister(&tpd_led);
  414. if (led_workqueue)
  415. destroy_workqueue(led_workqueue);
  416. }
  417. /*
  418. * PCI hotplug (for wlan rfkill)
  419. */
  420. static bool eeepc_wlan_rfkill_blocked(void)
  421. {
  422. if (get_acpi(CM_ASL_WLAN) == 1)
  423. return false;
  424. return true;
  425. }
  426. static void eeepc_rfkill_hotplug(void)
  427. {
  428. struct pci_dev *dev;
  429. struct pci_bus *bus;
  430. bool blocked = eeepc_wlan_rfkill_blocked();
  431. if (eeepc->wlan_rfkill)
  432. rfkill_set_sw_state(eeepc->wlan_rfkill, blocked);
  433. mutex_lock(&eeepc->hotplug_lock);
  434. if (eeepc->hotplug_slot) {
  435. bus = pci_find_bus(0, 1);
  436. if (!bus) {
  437. pr_warning("Unable to find PCI bus 1?\n");
  438. goto out_unlock;
  439. }
  440. if (!blocked) {
  441. dev = pci_get_slot(bus, 0);
  442. if (dev) {
  443. /* Device already present */
  444. pci_dev_put(dev);
  445. goto out_unlock;
  446. }
  447. dev = pci_scan_single_device(bus, 0);
  448. if (dev) {
  449. pci_bus_assign_resources(bus);
  450. if (pci_bus_add_device(dev))
  451. pr_err("Unable to hotplug wifi\n");
  452. }
  453. } else {
  454. dev = pci_get_slot(bus, 0);
  455. if (dev) {
  456. pci_remove_bus_device(dev);
  457. pci_dev_put(dev);
  458. }
  459. }
  460. }
  461. out_unlock:
  462. mutex_unlock(&eeepc->hotplug_lock);
  463. }
  464. static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
  465. {
  466. if (event != ACPI_NOTIFY_BUS_CHECK)
  467. return;
  468. eeepc_rfkill_hotplug();
  469. }
  470. static int eeepc_register_rfkill_notifier(char *node)
  471. {
  472. acpi_status status = AE_OK;
  473. acpi_handle handle;
  474. status = acpi_get_handle(NULL, node, &handle);
  475. if (ACPI_SUCCESS(status)) {
  476. status = acpi_install_notify_handler(handle,
  477. ACPI_SYSTEM_NOTIFY,
  478. eeepc_rfkill_notify,
  479. NULL);
  480. if (ACPI_FAILURE(status))
  481. pr_warning("Failed to register notify on %s\n", node);
  482. } else
  483. return -ENODEV;
  484. return 0;
  485. }
  486. static void eeepc_unregister_rfkill_notifier(char *node)
  487. {
  488. acpi_status status = AE_OK;
  489. acpi_handle handle;
  490. status = acpi_get_handle(NULL, node, &handle);
  491. if (ACPI_SUCCESS(status)) {
  492. status = acpi_remove_notify_handler(handle,
  493. ACPI_SYSTEM_NOTIFY,
  494. eeepc_rfkill_notify);
  495. if (ACPI_FAILURE(status))
  496. pr_err("Error removing rfkill notify handler %s\n",
  497. node);
  498. }
  499. }
  500. static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
  501. u8 *value)
  502. {
  503. int val = get_acpi(CM_ASL_WLAN);
  504. if (val == 1 || val == 0)
  505. *value = val;
  506. else
  507. return -EINVAL;
  508. return 0;
  509. }
  510. static void eeepc_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot)
  511. {
  512. kfree(hotplug_slot->info);
  513. kfree(hotplug_slot);
  514. }
  515. static struct hotplug_slot_ops eeepc_hotplug_slot_ops = {
  516. .owner = THIS_MODULE,
  517. .get_adapter_status = eeepc_get_adapter_status,
  518. .get_power_status = eeepc_get_adapter_status,
  519. };
  520. static int eeepc_setup_pci_hotplug(void)
  521. {
  522. int ret = -ENOMEM;
  523. struct pci_bus *bus = pci_find_bus(0, 1);
  524. if (!bus) {
  525. pr_err("Unable to find wifi PCI bus\n");
  526. return -ENODEV;
  527. }
  528. eeepc->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
  529. if (!eeepc->hotplug_slot)
  530. goto error_slot;
  531. eeepc->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
  532. GFP_KERNEL);
  533. if (!eeepc->hotplug_slot->info)
  534. goto error_info;
  535. eeepc->hotplug_slot->private = eeepc;
  536. eeepc->hotplug_slot->release = &eeepc_cleanup_pci_hotplug;
  537. eeepc->hotplug_slot->ops = &eeepc_hotplug_slot_ops;
  538. eeepc_get_adapter_status(eeepc->hotplug_slot,
  539. &eeepc->hotplug_slot->info->adapter_status);
  540. ret = pci_hp_register(eeepc->hotplug_slot, bus, 0, "eeepc-wifi");
  541. if (ret) {
  542. pr_err("Unable to register hotplug slot - %d\n", ret);
  543. goto error_register;
  544. }
  545. return 0;
  546. error_register:
  547. kfree(eeepc->hotplug_slot->info);
  548. error_info:
  549. kfree(eeepc->hotplug_slot);
  550. eeepc->hotplug_slot = NULL;
  551. error_slot:
  552. return ret;
  553. }
  554. /*
  555. * Rfkill devices
  556. */
  557. static int eeepc_rfkill_set(void *data, bool blocked)
  558. {
  559. unsigned long asl = (unsigned long)data;
  560. return set_acpi(asl, !blocked);
  561. }
  562. static const struct rfkill_ops eeepc_rfkill_ops = {
  563. .set_block = eeepc_rfkill_set,
  564. };
  565. static int eeepc_new_rfkill(struct rfkill **rfkill,
  566. const char *name, struct device *dev,
  567. enum rfkill_type type, int cm)
  568. {
  569. int result;
  570. result = get_acpi(cm);
  571. if (result < 0)
  572. return result;
  573. *rfkill = rfkill_alloc(name, dev, type,
  574. &eeepc_rfkill_ops, (void *)(unsigned long)cm);
  575. if (!*rfkill)
  576. return -EINVAL;
  577. rfkill_init_sw_state(*rfkill, get_acpi(cm) != 1);
  578. result = rfkill_register(*rfkill);
  579. if (result) {
  580. rfkill_destroy(*rfkill);
  581. *rfkill = NULL;
  582. return result;
  583. }
  584. return 0;
  585. }
  586. static void eeepc_rfkill_exit(void)
  587. {
  588. eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P5");
  589. eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
  590. eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
  591. if (eeepc->wlan_rfkill) {
  592. rfkill_unregister(eeepc->wlan_rfkill);
  593. rfkill_destroy(eeepc->wlan_rfkill);
  594. eeepc->wlan_rfkill = NULL;
  595. }
  596. /*
  597. * Refresh pci hotplug in case the rfkill state was changed after
  598. * eeepc_unregister_rfkill_notifier()
  599. */
  600. eeepc_rfkill_hotplug();
  601. if (eeepc->hotplug_slot)
  602. pci_hp_deregister(eeepc->hotplug_slot);
  603. if (eeepc->bluetooth_rfkill) {
  604. rfkill_unregister(eeepc->bluetooth_rfkill);
  605. rfkill_destroy(eeepc->bluetooth_rfkill);
  606. eeepc->bluetooth_rfkill = NULL;
  607. }
  608. if (eeepc->wwan3g_rfkill) {
  609. rfkill_unregister(eeepc->wwan3g_rfkill);
  610. rfkill_destroy(eeepc->wwan3g_rfkill);
  611. eeepc->wwan3g_rfkill = NULL;
  612. }
  613. if (eeepc->wimax_rfkill) {
  614. rfkill_unregister(eeepc->wimax_rfkill);
  615. rfkill_destroy(eeepc->wimax_rfkill);
  616. eeepc->wimax_rfkill = NULL;
  617. }
  618. }
  619. static int eeepc_rfkill_init(struct device *dev)
  620. {
  621. int result = 0;
  622. mutex_init(&eeepc->hotplug_lock);
  623. result = eeepc_new_rfkill(&eeepc->wlan_rfkill,
  624. "eeepc-wlan", dev,
  625. RFKILL_TYPE_WLAN, CM_ASL_WLAN);
  626. if (result && result != -ENODEV)
  627. goto exit;
  628. result = eeepc_new_rfkill(&eeepc->bluetooth_rfkill,
  629. "eeepc-bluetooth", dev,
  630. RFKILL_TYPE_BLUETOOTH, CM_ASL_BLUETOOTH);
  631. if (result && result != -ENODEV)
  632. goto exit;
  633. result = eeepc_new_rfkill(&eeepc->wwan3g_rfkill,
  634. "eeepc-wwan3g", dev,
  635. RFKILL_TYPE_WWAN, CM_ASL_3G);
  636. if (result && result != -ENODEV)
  637. goto exit;
  638. result = eeepc_new_rfkill(&eeepc->wimax_rfkill,
  639. "eeepc-wimax", dev,
  640. RFKILL_TYPE_WIMAX, CM_ASL_WIMAX);
  641. if (result && result != -ENODEV)
  642. goto exit;
  643. result = eeepc_setup_pci_hotplug();
  644. /*
  645. * If we get -EBUSY then something else is handling the PCI hotplug -
  646. * don't fail in this case
  647. */
  648. if (result == -EBUSY)
  649. result = 0;
  650. eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P5");
  651. eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
  652. eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
  653. /*
  654. * Refresh pci hotplug in case the rfkill state was changed during
  655. * setup.
  656. */
  657. eeepc_rfkill_hotplug();
  658. exit:
  659. if (result && result != -ENODEV)
  660. eeepc_rfkill_exit();
  661. return result;
  662. }
  663. /*
  664. * Platform driver - hibernate/resume callbacks
  665. */
  666. static int eeepc_thaw(struct device *device)
  667. {
  668. if (eeepc->wlan_rfkill) {
  669. bool wlan;
  670. /*
  671. * Work around bios bug - acpi _PTS turns off the wireless led
  672. * during suspend. Normally it restores it on resume, but
  673. * we should kick it ourselves in case hibernation is aborted.
  674. */
  675. wlan = get_acpi(CM_ASL_WLAN);
  676. set_acpi(CM_ASL_WLAN, wlan);
  677. }
  678. return 0;
  679. }
  680. static int eeepc_restore(struct device *device)
  681. {
  682. /* Refresh both wlan rfkill state and pci hotplug */
  683. if (eeepc->wlan_rfkill)
  684. eeepc_rfkill_hotplug();
  685. if (eeepc->bluetooth_rfkill)
  686. rfkill_set_sw_state(eeepc->bluetooth_rfkill,
  687. get_acpi(CM_ASL_BLUETOOTH) != 1);
  688. if (eeepc->wwan3g_rfkill)
  689. rfkill_set_sw_state(eeepc->wwan3g_rfkill,
  690. get_acpi(CM_ASL_3G) != 1);
  691. if (eeepc->wimax_rfkill)
  692. rfkill_set_sw_state(eeepc->wimax_rfkill,
  693. get_acpi(CM_ASL_WIMAX) != 1);
  694. return 0;
  695. }
  696. static struct dev_pm_ops eeepc_pm_ops = {
  697. .thaw = eeepc_thaw,
  698. .restore = eeepc_restore,
  699. };
  700. static struct platform_driver platform_driver = {
  701. .driver = {
  702. .name = EEEPC_LAPTOP_FILE,
  703. .owner = THIS_MODULE,
  704. .pm = &eeepc_pm_ops,
  705. }
  706. };
  707. /*
  708. * Hwmon device
  709. */
  710. #define EEEPC_EC_SC00 0x61
  711. #define EEEPC_EC_FAN_PWM (EEEPC_EC_SC00 + 2) /* Fan PWM duty cycle (%) */
  712. #define EEEPC_EC_FAN_HRPM (EEEPC_EC_SC00 + 5) /* High byte, fan speed (RPM) */
  713. #define EEEPC_EC_FAN_LRPM (EEEPC_EC_SC00 + 6) /* Low byte, fan speed (RPM) */
  714. #define EEEPC_EC_SFB0 0xD0
  715. #define EEEPC_EC_FAN_CTRL (EEEPC_EC_SFB0 + 3) /* Byte containing SF25 */
  716. static int eeepc_get_fan_pwm(void)
  717. {
  718. u8 value = 0;
  719. ec_read(EEEPC_EC_FAN_PWM, &value);
  720. return value * 255 / 100;
  721. }
  722. static void eeepc_set_fan_pwm(int value)
  723. {
  724. value = SENSORS_LIMIT(value, 0, 255);
  725. value = value * 100 / 255;
  726. ec_write(EEEPC_EC_FAN_PWM, value);
  727. }
  728. static int eeepc_get_fan_rpm(void)
  729. {
  730. u8 high = 0;
  731. u8 low = 0;
  732. ec_read(EEEPC_EC_FAN_HRPM, &high);
  733. ec_read(EEEPC_EC_FAN_LRPM, &low);
  734. return high << 8 | low;
  735. }
  736. static int eeepc_get_fan_ctrl(void)
  737. {
  738. u8 value = 0;
  739. ec_read(EEEPC_EC_FAN_CTRL, &value);
  740. if (value & 0x02)
  741. return 1; /* manual */
  742. else
  743. return 2; /* automatic */
  744. }
  745. static void eeepc_set_fan_ctrl(int manual)
  746. {
  747. u8 value = 0;
  748. ec_read(EEEPC_EC_FAN_CTRL, &value);
  749. if (manual == 1)
  750. value |= 0x02;
  751. else
  752. value &= ~0x02;
  753. ec_write(EEEPC_EC_FAN_CTRL, value);
  754. }
  755. static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
  756. {
  757. int rv, value;
  758. rv = parse_arg(buf, count, &value);
  759. if (rv > 0)
  760. set(value);
  761. return rv;
  762. }
  763. static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
  764. {
  765. return sprintf(buf, "%d\n", get());
  766. }
  767. #define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _set, _get) \
  768. static ssize_t show_##_name(struct device *dev, \
  769. struct device_attribute *attr, \
  770. char *buf) \
  771. { \
  772. return show_sys_hwmon(_set, buf); \
  773. } \
  774. static ssize_t store_##_name(struct device *dev, \
  775. struct device_attribute *attr, \
  776. const char *buf, size_t count) \
  777. { \
  778. return store_sys_hwmon(_get, buf, count); \
  779. } \
  780. static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0);
  781. EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL);
  782. EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
  783. eeepc_get_fan_pwm, eeepc_set_fan_pwm);
  784. EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
  785. eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
  786. static ssize_t
  787. show_name(struct device *dev, struct device_attribute *attr, char *buf)
  788. {
  789. return sprintf(buf, "eeepc\n");
  790. }
  791. static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
  792. static struct attribute *hwmon_attributes[] = {
  793. &sensor_dev_attr_pwm1.dev_attr.attr,
  794. &sensor_dev_attr_fan1_input.dev_attr.attr,
  795. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  796. &sensor_dev_attr_name.dev_attr.attr,
  797. NULL
  798. };
  799. static struct attribute_group hwmon_attribute_group = {
  800. .attrs = hwmon_attributes
  801. };
  802. static void eeepc_hwmon_exit(void)
  803. {
  804. struct device *hwmon;
  805. hwmon = eeepc_hwmon_device;
  806. if (!hwmon)
  807. return ;
  808. sysfs_remove_group(&hwmon->kobj,
  809. &hwmon_attribute_group);
  810. hwmon_device_unregister(hwmon);
  811. eeepc_hwmon_device = NULL;
  812. }
  813. static int eeepc_hwmon_init(struct device *dev)
  814. {
  815. struct device *hwmon;
  816. int result;
  817. hwmon = hwmon_device_register(dev);
  818. if (IS_ERR(hwmon)) {
  819. pr_err("Could not register eeepc hwmon device\n");
  820. eeepc_hwmon_device = NULL;
  821. return PTR_ERR(hwmon);
  822. }
  823. eeepc_hwmon_device = hwmon;
  824. result = sysfs_create_group(&hwmon->kobj,
  825. &hwmon_attribute_group);
  826. if (result)
  827. eeepc_hwmon_exit();
  828. return result;
  829. }
  830. /*
  831. * Backlight device
  832. */
  833. static int read_brightness(struct backlight_device *bd)
  834. {
  835. return get_acpi(CM_ASL_PANELBRIGHT);
  836. }
  837. static int set_brightness(struct backlight_device *bd, int value)
  838. {
  839. return set_acpi(CM_ASL_PANELBRIGHT, value);
  840. }
  841. static int update_bl_status(struct backlight_device *bd)
  842. {
  843. return set_brightness(bd, bd->props.brightness);
  844. }
  845. static struct backlight_ops eeepcbl_ops = {
  846. .get_brightness = read_brightness,
  847. .update_status = update_bl_status,
  848. };
  849. static int eeepc_backlight_notify(void)
  850. {
  851. struct backlight_device *bd = eeepc_backlight_device;
  852. int old = bd->props.brightness;
  853. backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
  854. return old;
  855. }
  856. static int eeepc_backlight_init(struct device *dev)
  857. {
  858. struct backlight_device *bd;
  859. bd = backlight_device_register(EEEPC_LAPTOP_FILE, dev,
  860. NULL, &eeepcbl_ops);
  861. if (IS_ERR(bd)) {
  862. pr_err("Could not register eeepc backlight device\n");
  863. eeepc_backlight_device = NULL;
  864. return PTR_ERR(bd);
  865. }
  866. eeepc_backlight_device = bd;
  867. bd->props.max_brightness = 15;
  868. bd->props.brightness = read_brightness(NULL);
  869. bd->props.power = FB_BLANK_UNBLANK;
  870. backlight_update_status(bd);
  871. return 0;
  872. }
  873. static void eeepc_backlight_exit(void)
  874. {
  875. if (eeepc_backlight_device)
  876. backlight_device_unregister(eeepc_backlight_device);
  877. eeepc_backlight_device = NULL;
  878. }
  879. /*
  880. * Input device (i.e. hotkeys)
  881. */
  882. static struct key_entry *eeepc_get_entry_by_scancode(int code)
  883. {
  884. struct key_entry *key;
  885. for (key = eeepc_keymap; key->type != KE_END; key++)
  886. if (code == key->code)
  887. return key;
  888. return NULL;
  889. }
  890. static void eeepc_input_notify(int event)
  891. {
  892. static struct key_entry *key;
  893. key = eeepc_get_entry_by_scancode(event);
  894. if (key) {
  895. switch (key->type) {
  896. case KE_KEY:
  897. input_report_key(eeepc->inputdev, key->keycode,
  898. 1);
  899. input_sync(eeepc->inputdev);
  900. input_report_key(eeepc->inputdev, key->keycode,
  901. 0);
  902. input_sync(eeepc->inputdev);
  903. break;
  904. }
  905. }
  906. }
  907. static struct key_entry *eepc_get_entry_by_keycode(int code)
  908. {
  909. struct key_entry *key;
  910. for (key = eeepc_keymap; key->type != KE_END; key++)
  911. if (code == key->keycode && key->type == KE_KEY)
  912. return key;
  913. return NULL;
  914. }
  915. static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
  916. {
  917. struct key_entry *key = eeepc_get_entry_by_scancode(scancode);
  918. if (key && key->type == KE_KEY) {
  919. *keycode = key->keycode;
  920. return 0;
  921. }
  922. return -EINVAL;
  923. }
  924. static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode)
  925. {
  926. struct key_entry *key;
  927. int old_keycode;
  928. if (keycode < 0 || keycode > KEY_MAX)
  929. return -EINVAL;
  930. key = eeepc_get_entry_by_scancode(scancode);
  931. if (key && key->type == KE_KEY) {
  932. old_keycode = key->keycode;
  933. key->keycode = keycode;
  934. set_bit(keycode, dev->keybit);
  935. if (!eepc_get_entry_by_keycode(old_keycode))
  936. clear_bit(old_keycode, dev->keybit);
  937. return 0;
  938. }
  939. return -EINVAL;
  940. }
  941. static int eeepc_input_init(struct device *dev)
  942. {
  943. const struct key_entry *key;
  944. int result;
  945. eeepc->inputdev = input_allocate_device();
  946. if (!eeepc->inputdev) {
  947. pr_info("Unable to allocate input device\n");
  948. return -ENOMEM;
  949. }
  950. eeepc->inputdev->name = "Asus EeePC extra buttons";
  951. eeepc->inputdev->dev.parent = dev;
  952. eeepc->inputdev->phys = EEEPC_LAPTOP_FILE "/input0";
  953. eeepc->inputdev->id.bustype = BUS_HOST;
  954. eeepc->inputdev->getkeycode = eeepc_getkeycode;
  955. eeepc->inputdev->setkeycode = eeepc_setkeycode;
  956. for (key = eeepc_keymap; key->type != KE_END; key++) {
  957. switch (key->type) {
  958. case KE_KEY:
  959. set_bit(EV_KEY, eeepc->inputdev->evbit);
  960. set_bit(key->keycode, eeepc->inputdev->keybit);
  961. break;
  962. }
  963. }
  964. result = input_register_device(eeepc->inputdev);
  965. if (result) {
  966. pr_info("Unable to register input device\n");
  967. input_free_device(eeepc->inputdev);
  968. return result;
  969. }
  970. return 0;
  971. }
  972. static void eeepc_input_exit(void)
  973. {
  974. if (eeepc->inputdev)
  975. input_unregister_device(eeepc->inputdev);
  976. }
  977. /*
  978. * ACPI driver
  979. */
  980. static void eeepc_acpi_notify(struct acpi_device *device, u32 event)
  981. {
  982. u16 count;
  983. if (event > ACPI_MAX_SYS_NOTIFY)
  984. return;
  985. count = eeepc->event_count[event % 128]++;
  986. acpi_bus_generate_proc_event(eeepc->device, event, count);
  987. acpi_bus_generate_netlink_event(eeepc->device->pnp.device_class,
  988. dev_name(&eeepc->device->dev), event,
  989. count);
  990. if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX) {
  991. int old_brightness, new_brightness;
  992. /* Update backlight device. */
  993. old_brightness = eeepc_backlight_notify();
  994. /* Convert brightness event to keypress (obsolescent hack). */
  995. new_brightness = event - NOTIFY_BRN_MIN;
  996. if (new_brightness < old_brightness) {
  997. event = NOTIFY_BRN_MIN; /* brightness down */
  998. } else if (new_brightness > old_brightness) {
  999. event = NOTIFY_BRN_MAX; /* brightness up */
  1000. } else {
  1001. /*
  1002. * no change in brightness - already at min/max,
  1003. * event will be desired value (or else ignored).
  1004. */
  1005. }
  1006. }
  1007. eeepc_input_notify(event);
  1008. }
  1009. static void cmsg_quirk(int cm, const char *name)
  1010. {
  1011. int dummy;
  1012. /* Some BIOSes do not report cm although it is avaliable.
  1013. Check if cm_getv[cm] works and, if yes, assume cm should be set. */
  1014. if (!(eeepc->cm_supported & (1 << cm))
  1015. && !read_acpi_int(eeepc->handle, cm_getv[cm], &dummy)) {
  1016. pr_info("%s (%x) not reported by BIOS,"
  1017. " enabling anyway\n", name, 1 << cm);
  1018. eeepc->cm_supported |= 1 << cm;
  1019. }
  1020. }
  1021. static void cmsg_quirks(void)
  1022. {
  1023. cmsg_quirk(CM_ASL_LID, "LID");
  1024. cmsg_quirk(CM_ASL_TYPE, "TYPE");
  1025. cmsg_quirk(CM_ASL_PANELPOWER, "PANELPOWER");
  1026. cmsg_quirk(CM_ASL_TPD, "TPD");
  1027. }
  1028. static int eeepc_acpi_init(void)
  1029. {
  1030. unsigned int init_flags;
  1031. int result;
  1032. result = acpi_bus_get_status(eeepc->device);
  1033. if (result)
  1034. return result;
  1035. if (!eeepc->device->status.present) {
  1036. pr_err("Hotkey device not present, aborting\n");
  1037. return -ENODEV;
  1038. }
  1039. init_flags = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
  1040. pr_notice("Hotkey init flags 0x%x\n", init_flags);
  1041. if (write_acpi_int(eeepc->handle, "INIT", init_flags)) {
  1042. pr_err("Hotkey initialization failed\n");
  1043. return -ENODEV;
  1044. }
  1045. /* get control methods supported */
  1046. if (read_acpi_int(eeepc->handle, "CMSG", &eeepc->cm_supported)) {
  1047. pr_err("Get control methods supported failed\n");
  1048. return -ENODEV;
  1049. }
  1050. cmsg_quirks();
  1051. pr_info("Get control methods supported: 0x%x\n", eeepc->cm_supported);
  1052. return 0;
  1053. }
  1054. static void __devinit eeepc_enable_camera(void)
  1055. {
  1056. /*
  1057. * If the following call to set_acpi() fails, it's because there's no
  1058. * camera so we can ignore the error.
  1059. */
  1060. if (get_acpi(CM_ASL_CAMERA) == 0)
  1061. set_acpi(CM_ASL_CAMERA, 1);
  1062. }
  1063. static int __devinit eeepc_acpi_add(struct acpi_device *device)
  1064. {
  1065. struct device *dev;
  1066. int result;
  1067. pr_notice(EEEPC_LAPTOP_NAME "\n");
  1068. eeepc = kzalloc(sizeof(struct eeepc_laptop), GFP_KERNEL);
  1069. if (!eeepc)
  1070. return -ENOMEM;
  1071. eeepc->handle = device->handle;
  1072. strcpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME);
  1073. strcpy(acpi_device_class(device), EEEPC_ACPI_CLASS);
  1074. device->driver_data = eeepc;
  1075. eeepc->device = device;
  1076. result = eeepc_acpi_init();
  1077. if (result)
  1078. goto fail_platform;
  1079. eeepc_enable_camera();
  1080. result = eeepc_platform_init();
  1081. if (result)
  1082. goto fail_platform;
  1083. dev = &platform_device->dev;
  1084. if (!acpi_video_backlight_support()) {
  1085. result = eeepc_backlight_init(dev);
  1086. if (result)
  1087. goto fail_backlight;
  1088. } else
  1089. pr_info("Backlight controlled by ACPI video driver\n");
  1090. result = eeepc_input_init(dev);
  1091. if (result)
  1092. goto fail_input;
  1093. result = eeepc_hwmon_init(dev);
  1094. if (result)
  1095. goto fail_hwmon;
  1096. result = eeepc_led_init(dev);
  1097. if (result)
  1098. goto fail_led;
  1099. result = eeepc_rfkill_init(dev);
  1100. if (result)
  1101. goto fail_rfkill;
  1102. return 0;
  1103. fail_rfkill:
  1104. eeepc_led_exit();
  1105. fail_led:
  1106. eeepc_hwmon_exit();
  1107. fail_hwmon:
  1108. eeepc_input_exit();
  1109. fail_input:
  1110. eeepc_backlight_exit();
  1111. fail_backlight:
  1112. eeepc_platform_exit();
  1113. fail_platform:
  1114. kfree(eeepc);
  1115. return result;
  1116. }
  1117. static int eeepc_acpi_remove(struct acpi_device *device, int type)
  1118. {
  1119. eeepc_backlight_exit();
  1120. eeepc_rfkill_exit();
  1121. eeepc_input_exit();
  1122. eeepc_hwmon_exit();
  1123. eeepc_led_exit();
  1124. eeepc_platform_exit();
  1125. kfree(eeepc);
  1126. return 0;
  1127. }
  1128. static const struct acpi_device_id eeepc_device_ids[] = {
  1129. {EEEPC_ACPI_HID, 0},
  1130. {"", 0},
  1131. };
  1132. MODULE_DEVICE_TABLE(acpi, eeepc_device_ids);
  1133. static struct acpi_driver eeepc_acpi_driver = {
  1134. .name = EEEPC_LAPTOP_NAME,
  1135. .class = EEEPC_ACPI_CLASS,
  1136. .owner = THIS_MODULE,
  1137. .ids = eeepc_device_ids,
  1138. .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
  1139. .ops = {
  1140. .add = eeepc_acpi_add,
  1141. .remove = eeepc_acpi_remove,
  1142. .notify = eeepc_acpi_notify,
  1143. },
  1144. };
  1145. static int __init eeepc_laptop_init(void)
  1146. {
  1147. int result;
  1148. result = platform_driver_register(&platform_driver);
  1149. if (result < 0)
  1150. return result;
  1151. result = acpi_bus_register_driver(&eeepc_acpi_driver);
  1152. if (result < 0)
  1153. goto fail_acpi_driver;
  1154. if (!eeepc) {
  1155. result = -ENODEV;
  1156. goto fail_no_device;
  1157. }
  1158. return 0;
  1159. fail_no_device:
  1160. acpi_bus_unregister_driver(&eeepc_acpi_driver);
  1161. fail_acpi_driver:
  1162. platform_driver_unregister(&platform_driver);
  1163. return result;
  1164. }
  1165. static void __exit eeepc_laptop_exit(void)
  1166. {
  1167. acpi_bus_unregister_driver(&eeepc_acpi_driver);
  1168. platform_driver_unregister(&platform_driver);
  1169. }
  1170. module_init(eeepc_laptop_init);
  1171. module_exit(eeepc_laptop_exit);