eeepc-laptop.c 31 KB

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