eeepc-laptop.c 31 KB

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