eeepc-laptop.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  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. /*
  443. * LEDs
  444. */
  445. /*
  446. * These functions actually update the LED's, and are called from a
  447. * workqueue. By doing this as separate work rather than when the LED
  448. * subsystem asks, we avoid messing with the Asus ACPI stuff during a
  449. * potentially bad time, such as a timer interrupt.
  450. */
  451. static int tpd_led_wk;
  452. static void tpd_led_update(struct work_struct *ignored)
  453. {
  454. int value = tpd_led_wk;
  455. set_acpi(CM_ASL_TPD, value);
  456. }
  457. static struct workqueue_struct *led_workqueue;
  458. static DECLARE_WORK(tpd_led_work, tpd_led_update);
  459. static void tpd_led_set(struct led_classdev *led_cdev,
  460. enum led_brightness value)
  461. {
  462. tpd_led_wk = (value > 0) ? 1 : 0;
  463. queue_work(led_workqueue, &tpd_led_work);
  464. }
  465. static struct led_classdev tpd_led = {
  466. .name = "eeepc::touchpad",
  467. .brightness_set = tpd_led_set,
  468. .max_brightness = 1
  469. };
  470. /*
  471. * Hotkey functions
  472. */
  473. static struct key_entry *eepc_get_entry_by_scancode(int code)
  474. {
  475. struct key_entry *key;
  476. for (key = eeepc_keymap; key->type != KE_END; key++)
  477. if (code == key->code)
  478. return key;
  479. return NULL;
  480. }
  481. static struct key_entry *eepc_get_entry_by_keycode(int code)
  482. {
  483. struct key_entry *key;
  484. for (key = eeepc_keymap; key->type != KE_END; key++)
  485. if (code == key->keycode && key->type == KE_KEY)
  486. return key;
  487. return NULL;
  488. }
  489. static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
  490. {
  491. struct key_entry *key = eepc_get_entry_by_scancode(scancode);
  492. if (key && key->type == KE_KEY) {
  493. *keycode = key->keycode;
  494. return 0;
  495. }
  496. return -EINVAL;
  497. }
  498. static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode)
  499. {
  500. struct key_entry *key;
  501. int old_keycode;
  502. if (keycode < 0 || keycode > KEY_MAX)
  503. return -EINVAL;
  504. key = eepc_get_entry_by_scancode(scancode);
  505. if (key && key->type == KE_KEY) {
  506. old_keycode = key->keycode;
  507. key->keycode = keycode;
  508. set_bit(keycode, dev->keybit);
  509. if (!eepc_get_entry_by_keycode(old_keycode))
  510. clear_bit(old_keycode, dev->keybit);
  511. return 0;
  512. }
  513. return -EINVAL;
  514. }
  515. static void cmsg_quirk(int cm, const char *name)
  516. {
  517. int dummy;
  518. /* Some BIOSes do not report cm although it is avaliable.
  519. Check if cm_getv[cm] works and, if yes, assume cm should be set. */
  520. if (!(ehotk->cm_supported & (1 << cm))
  521. && !read_acpi_int(ehotk->handle, cm_getv[cm], &dummy)) {
  522. pr_info("%s (%x) not reported by BIOS,"
  523. " enabling anyway\n", name, 1 << cm);
  524. ehotk->cm_supported |= 1 << cm;
  525. }
  526. }
  527. static void cmsg_quirks(void)
  528. {
  529. cmsg_quirk(CM_ASL_LID, "LID");
  530. cmsg_quirk(CM_ASL_TYPE, "TYPE");
  531. cmsg_quirk(CM_ASL_PANELPOWER, "PANELPOWER");
  532. cmsg_quirk(CM_ASL_TPD, "TPD");
  533. }
  534. static int eeepc_hotk_init(void)
  535. {
  536. unsigned int init_flags;
  537. int result;
  538. result = acpi_bus_get_status(ehotk->device);
  539. if (result)
  540. return result;
  541. if (!ehotk->device->status.present) {
  542. pr_err("Hotkey device not present, aborting\n");
  543. return -ENODEV;
  544. }
  545. init_flags = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
  546. pr_notice("Hotkey init flags 0x%x\n", init_flags);
  547. if (write_acpi_int(ehotk->handle, "INIT", init_flags)) {
  548. pr_err("Hotkey initialization failed\n");
  549. return -ENODEV;
  550. }
  551. /* get control methods supported */
  552. if (read_acpi_int(ehotk->handle, "CMSG",
  553. &ehotk->cm_supported)) {
  554. pr_err("Get control methods supported failed\n");
  555. return -ENODEV;
  556. }
  557. cmsg_quirks();
  558. pr_info("Get control methods supported: 0x%x\n", ehotk->cm_supported);
  559. return 0;
  560. }
  561. static int notify_brn(void)
  562. {
  563. /* returns the *previous* brightness, or -1 */
  564. struct backlight_device *bd = eeepc_backlight_device;
  565. int old = bd->props.brightness;
  566. backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
  567. return old;
  568. }
  569. static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
  570. u8 *value)
  571. {
  572. int val = get_acpi(CM_ASL_WLAN);
  573. if (val == 1 || val == 0)
  574. *value = val;
  575. else
  576. return -EINVAL;
  577. return 0;
  578. }
  579. static void eeepc_rfkill_hotplug(void)
  580. {
  581. struct pci_dev *dev;
  582. struct pci_bus *bus;
  583. bool blocked = eeepc_wlan_rfkill_blocked();
  584. if (ehotk->wlan_rfkill)
  585. rfkill_set_sw_state(ehotk->wlan_rfkill, blocked);
  586. mutex_lock(&ehotk->hotplug_lock);
  587. if (ehotk->hotplug_slot) {
  588. bus = pci_find_bus(0, 1);
  589. if (!bus) {
  590. pr_warning("Unable to find PCI bus 1?\n");
  591. goto out_unlock;
  592. }
  593. if (!blocked) {
  594. dev = pci_get_slot(bus, 0);
  595. if (dev) {
  596. /* Device already present */
  597. pci_dev_put(dev);
  598. goto out_unlock;
  599. }
  600. dev = pci_scan_single_device(bus, 0);
  601. if (dev) {
  602. pci_bus_assign_resources(bus);
  603. if (pci_bus_add_device(dev))
  604. pr_err("Unable to hotplug wifi\n");
  605. }
  606. } else {
  607. dev = pci_get_slot(bus, 0);
  608. if (dev) {
  609. pci_remove_bus_device(dev);
  610. pci_dev_put(dev);
  611. }
  612. }
  613. }
  614. out_unlock:
  615. mutex_unlock(&ehotk->hotplug_lock);
  616. }
  617. static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
  618. {
  619. if (event != ACPI_NOTIFY_BUS_CHECK)
  620. return;
  621. eeepc_rfkill_hotplug();
  622. }
  623. static void eeepc_hotk_notify(struct acpi_device *device, u32 event)
  624. {
  625. static struct key_entry *key;
  626. u16 count;
  627. int brn = -ENODEV;
  628. if (event > ACPI_MAX_SYS_NOTIFY)
  629. return;
  630. if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX)
  631. brn = notify_brn();
  632. count = ehotk->event_count[event % 128]++;
  633. acpi_bus_generate_proc_event(ehotk->device, event, count);
  634. acpi_bus_generate_netlink_event(ehotk->device->pnp.device_class,
  635. dev_name(&ehotk->device->dev), event,
  636. count);
  637. if (ehotk->inputdev) {
  638. /* brightness-change events need special
  639. * handling for conversion to key events
  640. */
  641. if (brn < 0)
  642. brn = event;
  643. else
  644. brn += NOTIFY_BRN_MIN;
  645. if (event < brn)
  646. event = NOTIFY_BRN_MIN; /* brightness down */
  647. else if (event > brn)
  648. event = NOTIFY_BRN_MIN + 2; /* ... up */
  649. else
  650. event = NOTIFY_BRN_MIN + 1; /* ... unchanged */
  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. }
  666. static int eeepc_register_rfkill_notifier(char *node)
  667. {
  668. acpi_status status = AE_OK;
  669. acpi_handle handle;
  670. status = acpi_get_handle(NULL, node, &handle);
  671. if (ACPI_SUCCESS(status)) {
  672. status = acpi_install_notify_handler(handle,
  673. ACPI_SYSTEM_NOTIFY,
  674. eeepc_rfkill_notify,
  675. NULL);
  676. if (ACPI_FAILURE(status))
  677. pr_warning("Failed to register notify on %s\n", node);
  678. } else
  679. return -ENODEV;
  680. return 0;
  681. }
  682. static void eeepc_unregister_rfkill_notifier(char *node)
  683. {
  684. acpi_status status = AE_OK;
  685. acpi_handle handle;
  686. status = acpi_get_handle(NULL, node, &handle);
  687. if (ACPI_SUCCESS(status)) {
  688. status = acpi_remove_notify_handler(handle,
  689. ACPI_SYSTEM_NOTIFY,
  690. eeepc_rfkill_notify);
  691. if (ACPI_FAILURE(status))
  692. pr_err("Error removing rfkill notify handler %s\n",
  693. node);
  694. }
  695. }
  696. static void eeepc_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot)
  697. {
  698. kfree(hotplug_slot->info);
  699. kfree(hotplug_slot);
  700. }
  701. static int eeepc_setup_pci_hotplug(void)
  702. {
  703. int ret = -ENOMEM;
  704. struct pci_bus *bus = pci_find_bus(0, 1);
  705. if (!bus) {
  706. pr_err("Unable to find wifi PCI bus\n");
  707. return -ENODEV;
  708. }
  709. ehotk->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
  710. if (!ehotk->hotplug_slot)
  711. goto error_slot;
  712. ehotk->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
  713. GFP_KERNEL);
  714. if (!ehotk->hotplug_slot->info)
  715. goto error_info;
  716. ehotk->hotplug_slot->private = ehotk;
  717. ehotk->hotplug_slot->release = &eeepc_cleanup_pci_hotplug;
  718. ehotk->hotplug_slot->ops = &eeepc_hotplug_slot_ops;
  719. eeepc_get_adapter_status(ehotk->hotplug_slot,
  720. &ehotk->hotplug_slot->info->adapter_status);
  721. ret = pci_hp_register(ehotk->hotplug_slot, bus, 0, "eeepc-wifi");
  722. if (ret) {
  723. pr_err("Unable to register hotplug slot - %d\n", ret);
  724. goto error_register;
  725. }
  726. return 0;
  727. error_register:
  728. kfree(ehotk->hotplug_slot->info);
  729. error_info:
  730. kfree(ehotk->hotplug_slot);
  731. ehotk->hotplug_slot = NULL;
  732. error_slot:
  733. return ret;
  734. }
  735. static int eeepc_hotk_thaw(struct device *device)
  736. {
  737. if (ehotk->wlan_rfkill) {
  738. bool wlan;
  739. /*
  740. * Work around bios bug - acpi _PTS turns off the wireless led
  741. * during suspend. Normally it restores it on resume, but
  742. * we should kick it ourselves in case hibernation is aborted.
  743. */
  744. wlan = get_acpi(CM_ASL_WLAN);
  745. set_acpi(CM_ASL_WLAN, wlan);
  746. }
  747. return 0;
  748. }
  749. static int eeepc_hotk_restore(struct device *device)
  750. {
  751. /* Refresh both wlan rfkill state and pci hotplug */
  752. if (ehotk->wlan_rfkill)
  753. eeepc_rfkill_hotplug();
  754. if (ehotk->bluetooth_rfkill)
  755. rfkill_set_sw_state(ehotk->bluetooth_rfkill,
  756. get_acpi(CM_ASL_BLUETOOTH) != 1);
  757. if (ehotk->wwan3g_rfkill)
  758. rfkill_set_sw_state(ehotk->wwan3g_rfkill,
  759. get_acpi(CM_ASL_3G) != 1);
  760. if (ehotk->wimax_rfkill)
  761. rfkill_set_sw_state(ehotk->wimax_rfkill,
  762. get_acpi(CM_ASL_WIMAX) != 1);
  763. return 0;
  764. }
  765. /*
  766. * Hwmon
  767. */
  768. static int eeepc_get_fan_pwm(void)
  769. {
  770. u8 value = 0;
  771. ec_read(EEEPC_EC_FAN_PWM, &value);
  772. return value * 255 / 100;
  773. }
  774. static void eeepc_set_fan_pwm(int value)
  775. {
  776. value = SENSORS_LIMIT(value, 0, 255);
  777. value = value * 100 / 255;
  778. ec_write(EEEPC_EC_FAN_PWM, value);
  779. }
  780. static int eeepc_get_fan_rpm(void)
  781. {
  782. u8 high = 0;
  783. u8 low = 0;
  784. ec_read(EEEPC_EC_FAN_HRPM, &high);
  785. ec_read(EEEPC_EC_FAN_LRPM, &low);
  786. return high << 8 | low;
  787. }
  788. static int eeepc_get_fan_ctrl(void)
  789. {
  790. u8 value = 0;
  791. ec_read(EEEPC_EC_FAN_CTRL, &value);
  792. if (value & 0x02)
  793. return 1; /* manual */
  794. else
  795. return 2; /* automatic */
  796. }
  797. static void eeepc_set_fan_ctrl(int manual)
  798. {
  799. u8 value = 0;
  800. ec_read(EEEPC_EC_FAN_CTRL, &value);
  801. if (manual == 1)
  802. value |= 0x02;
  803. else
  804. value &= ~0x02;
  805. ec_write(EEEPC_EC_FAN_CTRL, value);
  806. }
  807. static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
  808. {
  809. int rv, value;
  810. rv = parse_arg(buf, count, &value);
  811. if (rv > 0)
  812. set(value);
  813. return rv;
  814. }
  815. static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
  816. {
  817. return sprintf(buf, "%d\n", get());
  818. }
  819. #define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _set, _get) \
  820. static ssize_t show_##_name(struct device *dev, \
  821. struct device_attribute *attr, \
  822. char *buf) \
  823. { \
  824. return show_sys_hwmon(_set, buf); \
  825. } \
  826. static ssize_t store_##_name(struct device *dev, \
  827. struct device_attribute *attr, \
  828. const char *buf, size_t count) \
  829. { \
  830. return store_sys_hwmon(_get, buf, count); \
  831. } \
  832. static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0);
  833. EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL);
  834. EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
  835. eeepc_get_fan_pwm, eeepc_set_fan_pwm);
  836. EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
  837. eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
  838. static ssize_t
  839. show_name(struct device *dev, struct device_attribute *attr, char *buf)
  840. {
  841. return sprintf(buf, "eeepc\n");
  842. }
  843. static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
  844. static struct attribute *hwmon_attributes[] = {
  845. &sensor_dev_attr_pwm1.dev_attr.attr,
  846. &sensor_dev_attr_fan1_input.dev_attr.attr,
  847. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  848. &sensor_dev_attr_name.dev_attr.attr,
  849. NULL
  850. };
  851. static struct attribute_group hwmon_attribute_group = {
  852. .attrs = hwmon_attributes
  853. };
  854. /*
  855. * exit/init
  856. */
  857. static void eeepc_backlight_exit(void)
  858. {
  859. if (eeepc_backlight_device)
  860. backlight_device_unregister(eeepc_backlight_device);
  861. eeepc_backlight_device = NULL;
  862. }
  863. static void eeepc_rfkill_exit(void)
  864. {
  865. eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P5");
  866. eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
  867. eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
  868. if (ehotk->wlan_rfkill) {
  869. rfkill_unregister(ehotk->wlan_rfkill);
  870. rfkill_destroy(ehotk->wlan_rfkill);
  871. ehotk->wlan_rfkill = NULL;
  872. }
  873. /*
  874. * Refresh pci hotplug in case the rfkill state was changed after
  875. * eeepc_unregister_rfkill_notifier()
  876. */
  877. eeepc_rfkill_hotplug();
  878. if (ehotk->hotplug_slot)
  879. pci_hp_deregister(ehotk->hotplug_slot);
  880. if (ehotk->bluetooth_rfkill) {
  881. rfkill_unregister(ehotk->bluetooth_rfkill);
  882. rfkill_destroy(ehotk->bluetooth_rfkill);
  883. ehotk->bluetooth_rfkill = NULL;
  884. }
  885. if (ehotk->wwan3g_rfkill) {
  886. rfkill_unregister(ehotk->wwan3g_rfkill);
  887. rfkill_destroy(ehotk->wwan3g_rfkill);
  888. ehotk->wwan3g_rfkill = NULL;
  889. }
  890. if (ehotk->wimax_rfkill) {
  891. rfkill_unregister(ehotk->wimax_rfkill);
  892. rfkill_destroy(ehotk->wimax_rfkill);
  893. ehotk->wimax_rfkill = NULL;
  894. }
  895. }
  896. static void eeepc_input_exit(void)
  897. {
  898. if (ehotk->inputdev)
  899. input_unregister_device(ehotk->inputdev);
  900. }
  901. static void eeepc_hwmon_exit(void)
  902. {
  903. struct device *hwmon;
  904. hwmon = eeepc_hwmon_device;
  905. if (!hwmon)
  906. return ;
  907. sysfs_remove_group(&hwmon->kobj,
  908. &hwmon_attribute_group);
  909. hwmon_device_unregister(hwmon);
  910. eeepc_hwmon_device = NULL;
  911. }
  912. static void eeepc_led_exit(void)
  913. {
  914. if (tpd_led.dev)
  915. led_classdev_unregister(&tpd_led);
  916. if (led_workqueue)
  917. destroy_workqueue(led_workqueue);
  918. }
  919. static int eeepc_new_rfkill(struct rfkill **rfkill,
  920. const char *name, struct device *dev,
  921. enum rfkill_type type, int cm)
  922. {
  923. int result;
  924. result = get_acpi(cm);
  925. if (result < 0)
  926. return result;
  927. *rfkill = rfkill_alloc(name, dev, type,
  928. &eeepc_rfkill_ops, (void *)(unsigned long)cm);
  929. if (!*rfkill)
  930. return -EINVAL;
  931. rfkill_init_sw_state(*rfkill, get_acpi(cm) != 1);
  932. result = rfkill_register(*rfkill);
  933. if (result) {
  934. rfkill_destroy(*rfkill);
  935. *rfkill = NULL;
  936. return result;
  937. }
  938. return 0;
  939. }
  940. static int eeepc_rfkill_init(struct device *dev)
  941. {
  942. int result = 0;
  943. mutex_init(&ehotk->hotplug_lock);
  944. result = eeepc_new_rfkill(&ehotk->wlan_rfkill,
  945. "eeepc-wlan", dev,
  946. RFKILL_TYPE_WLAN, CM_ASL_WLAN);
  947. if (result && result != -ENODEV)
  948. goto exit;
  949. result = eeepc_new_rfkill(&ehotk->bluetooth_rfkill,
  950. "eeepc-bluetooth", dev,
  951. RFKILL_TYPE_BLUETOOTH, CM_ASL_BLUETOOTH);
  952. if (result && result != -ENODEV)
  953. goto exit;
  954. result = eeepc_new_rfkill(&ehotk->wwan3g_rfkill,
  955. "eeepc-wwan3g", dev,
  956. RFKILL_TYPE_WWAN, CM_ASL_3G);
  957. if (result && result != -ENODEV)
  958. goto exit;
  959. result = eeepc_new_rfkill(&ehotk->wimax_rfkill,
  960. "eeepc-wimax", dev,
  961. RFKILL_TYPE_WIMAX, CM_ASL_WIMAX);
  962. if (result && result != -ENODEV)
  963. goto exit;
  964. result = eeepc_setup_pci_hotplug();
  965. /*
  966. * If we get -EBUSY then something else is handling the PCI hotplug -
  967. * don't fail in this case
  968. */
  969. if (result == -EBUSY)
  970. result = 0;
  971. eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P5");
  972. eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
  973. eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
  974. /*
  975. * Refresh pci hotplug in case the rfkill state was changed during
  976. * setup.
  977. */
  978. eeepc_rfkill_hotplug();
  979. exit:
  980. if (result && result != -ENODEV)
  981. eeepc_rfkill_exit();
  982. return result;
  983. }
  984. static int eeepc_backlight_init(struct device *dev)
  985. {
  986. struct backlight_device *bd;
  987. bd = backlight_device_register(EEEPC_HOTK_FILE, dev,
  988. NULL, &eeepcbl_ops);
  989. if (IS_ERR(bd)) {
  990. pr_err("Could not register eeepc backlight device\n");
  991. eeepc_backlight_device = NULL;
  992. return PTR_ERR(bd);
  993. }
  994. eeepc_backlight_device = bd;
  995. bd->props.max_brightness = 15;
  996. bd->props.brightness = read_brightness(NULL);
  997. bd->props.power = FB_BLANK_UNBLANK;
  998. backlight_update_status(bd);
  999. return 0;
  1000. }
  1001. static int eeepc_hwmon_init(struct device *dev)
  1002. {
  1003. struct device *hwmon;
  1004. int result;
  1005. hwmon = hwmon_device_register(dev);
  1006. if (IS_ERR(hwmon)) {
  1007. pr_err("Could not register eeepc hwmon device\n");
  1008. eeepc_hwmon_device = NULL;
  1009. return PTR_ERR(hwmon);
  1010. }
  1011. eeepc_hwmon_device = hwmon;
  1012. result = sysfs_create_group(&hwmon->kobj,
  1013. &hwmon_attribute_group);
  1014. if (result)
  1015. eeepc_hwmon_exit();
  1016. return result;
  1017. }
  1018. static int eeepc_input_init(struct device *dev)
  1019. {
  1020. const struct key_entry *key;
  1021. int result;
  1022. ehotk->inputdev = input_allocate_device();
  1023. if (!ehotk->inputdev) {
  1024. pr_info("Unable to allocate input device\n");
  1025. return -ENOMEM;
  1026. }
  1027. ehotk->inputdev->name = "Asus EeePC extra buttons";
  1028. ehotk->inputdev->dev.parent = dev;
  1029. ehotk->inputdev->phys = EEEPC_HOTK_FILE "/input0";
  1030. ehotk->inputdev->id.bustype = BUS_HOST;
  1031. ehotk->inputdev->getkeycode = eeepc_getkeycode;
  1032. ehotk->inputdev->setkeycode = eeepc_setkeycode;
  1033. for (key = eeepc_keymap; key->type != KE_END; key++) {
  1034. switch (key->type) {
  1035. case KE_KEY:
  1036. set_bit(EV_KEY, ehotk->inputdev->evbit);
  1037. set_bit(key->keycode, ehotk->inputdev->keybit);
  1038. break;
  1039. }
  1040. }
  1041. result = input_register_device(ehotk->inputdev);
  1042. if (result) {
  1043. pr_info("Unable to register input device\n");
  1044. input_free_device(ehotk->inputdev);
  1045. return result;
  1046. }
  1047. return 0;
  1048. }
  1049. static int eeepc_led_init(struct device *dev)
  1050. {
  1051. int rv;
  1052. if (get_acpi(CM_ASL_TPD) == -ENODEV)
  1053. return 0;
  1054. led_workqueue = create_singlethread_workqueue("led_workqueue");
  1055. if (!led_workqueue)
  1056. return -ENOMEM;
  1057. rv = led_classdev_register(dev, &tpd_led);
  1058. if (rv) {
  1059. destroy_workqueue(led_workqueue);
  1060. return rv;
  1061. }
  1062. return 0;
  1063. }
  1064. static int __devinit eeepc_hotk_add(struct acpi_device *device)
  1065. {
  1066. struct device *dev;
  1067. int result;
  1068. pr_notice(EEEPC_HOTK_NAME "\n");
  1069. ehotk = kzalloc(sizeof(struct eeepc_hotk), GFP_KERNEL);
  1070. if (!ehotk)
  1071. return -ENOMEM;
  1072. ehotk->handle = device->handle;
  1073. strcpy(acpi_device_name(device), EEEPC_HOTK_DEVICE_NAME);
  1074. strcpy(acpi_device_class(device), EEEPC_HOTK_CLASS);
  1075. device->driver_data = ehotk;
  1076. ehotk->device = device;
  1077. result = eeepc_hotk_init();
  1078. if (result)
  1079. goto fail_platform_driver;
  1080. eeepc_enable_camera();
  1081. /* Register platform stuff */
  1082. result = platform_driver_register(&platform_driver);
  1083. if (result)
  1084. goto fail_platform_driver;
  1085. platform_device = platform_device_alloc(EEEPC_HOTK_FILE, -1);
  1086. if (!platform_device) {
  1087. result = -ENOMEM;
  1088. goto fail_platform_device1;
  1089. }
  1090. result = platform_device_add(platform_device);
  1091. if (result)
  1092. goto fail_platform_device2;
  1093. result = sysfs_create_group(&platform_device->dev.kobj,
  1094. &platform_attribute_group);
  1095. if (result)
  1096. goto fail_sysfs;
  1097. dev = &platform_device->dev;
  1098. if (!acpi_video_backlight_support()) {
  1099. result = eeepc_backlight_init(dev);
  1100. if (result)
  1101. goto fail_backlight;
  1102. } else
  1103. pr_info("Backlight controlled by ACPI video "
  1104. "driver\n");
  1105. result = eeepc_input_init(dev);
  1106. if (result)
  1107. goto fail_input;
  1108. result = eeepc_hwmon_init(dev);
  1109. if (result)
  1110. goto fail_hwmon;
  1111. result = eeepc_led_init(dev);
  1112. if (result)
  1113. goto fail_led;
  1114. result = eeepc_rfkill_init(dev);
  1115. if (result)
  1116. goto fail_rfkill;
  1117. return 0;
  1118. fail_rfkill:
  1119. eeepc_led_exit();
  1120. fail_led:
  1121. eeepc_hwmon_exit();
  1122. fail_hwmon:
  1123. eeepc_input_exit();
  1124. fail_input:
  1125. eeepc_backlight_exit();
  1126. fail_backlight:
  1127. sysfs_remove_group(&platform_device->dev.kobj,
  1128. &platform_attribute_group);
  1129. fail_sysfs:
  1130. platform_device_del(platform_device);
  1131. fail_platform_device2:
  1132. platform_device_put(platform_device);
  1133. fail_platform_device1:
  1134. platform_driver_unregister(&platform_driver);
  1135. fail_platform_driver:
  1136. kfree(ehotk);
  1137. return result;
  1138. }
  1139. static int eeepc_hotk_remove(struct acpi_device *device, int type)
  1140. {
  1141. eeepc_backlight_exit();
  1142. eeepc_rfkill_exit();
  1143. eeepc_input_exit();
  1144. eeepc_hwmon_exit();
  1145. eeepc_led_exit();
  1146. sysfs_remove_group(&platform_device->dev.kobj,
  1147. &platform_attribute_group);
  1148. platform_device_unregister(platform_device);
  1149. platform_driver_unregister(&platform_driver);
  1150. kfree(ehotk);
  1151. return 0;
  1152. }
  1153. static int __init eeepc_laptop_init(void)
  1154. {
  1155. int result;
  1156. result = acpi_bus_register_driver(&eeepc_hotk_driver);
  1157. if (result < 0)
  1158. return result;
  1159. if (!ehotk) {
  1160. acpi_bus_unregister_driver(&eeepc_hotk_driver);
  1161. return -ENODEV;
  1162. }
  1163. return 0;
  1164. }
  1165. static void __exit eeepc_laptop_exit(void)
  1166. {
  1167. acpi_bus_unregister_driver(&eeepc_hotk_driver);
  1168. }
  1169. module_init(eeepc_laptop_init);
  1170. module_exit(eeepc_laptop_exit);