eeepc-laptop.c 31 KB

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