eeepc-laptop.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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. #define EEEPC_LAPTOP_VERSION "0.1"
  36. #define EEEPC_HOTK_NAME "Eee PC Hotkey Driver"
  37. #define EEEPC_HOTK_FILE "eeepc"
  38. #define EEEPC_HOTK_CLASS "hotkey"
  39. #define EEEPC_HOTK_DEVICE_NAME "Hotkey"
  40. #define EEEPC_HOTK_HID "ASUS010"
  41. /*
  42. * Definitions for Asus EeePC
  43. */
  44. #define NOTIFY_WLAN_ON 0x10
  45. #define NOTIFY_BRN_MIN 0x20
  46. #define NOTIFY_BRN_MAX 0x2f
  47. enum {
  48. DISABLE_ASL_WLAN = 0x0001,
  49. DISABLE_ASL_BLUETOOTH = 0x0002,
  50. DISABLE_ASL_IRDA = 0x0004,
  51. DISABLE_ASL_CAMERA = 0x0008,
  52. DISABLE_ASL_TV = 0x0010,
  53. DISABLE_ASL_GPS = 0x0020,
  54. DISABLE_ASL_DISPLAYSWITCH = 0x0040,
  55. DISABLE_ASL_MODEM = 0x0080,
  56. DISABLE_ASL_CARDREADER = 0x0100,
  57. DISABLE_ASL_3G = 0x0200,
  58. DISABLE_ASL_WIMAX = 0x0400,
  59. DISABLE_ASL_HWCF = 0x0800
  60. };
  61. enum {
  62. CM_ASL_WLAN = 0,
  63. CM_ASL_BLUETOOTH,
  64. CM_ASL_IRDA,
  65. CM_ASL_1394,
  66. CM_ASL_CAMERA,
  67. CM_ASL_TV,
  68. CM_ASL_GPS,
  69. CM_ASL_DVDROM,
  70. CM_ASL_DISPLAYSWITCH,
  71. CM_ASL_PANELBRIGHT,
  72. CM_ASL_BIOSFLASH,
  73. CM_ASL_ACPIFLASH,
  74. CM_ASL_CPUFV,
  75. CM_ASL_CPUTEMPERATURE,
  76. CM_ASL_FANCPU,
  77. CM_ASL_FANCHASSIS,
  78. CM_ASL_USBPORT1,
  79. CM_ASL_USBPORT2,
  80. CM_ASL_USBPORT3,
  81. CM_ASL_MODEM,
  82. CM_ASL_CARDREADER,
  83. CM_ASL_3G,
  84. CM_ASL_WIMAX,
  85. CM_ASL_HWCF,
  86. CM_ASL_LID,
  87. CM_ASL_TYPE,
  88. CM_ASL_PANELPOWER, /*P901*/
  89. CM_ASL_TPD
  90. };
  91. static const char *cm_getv[] = {
  92. "WLDG", "BTHG", NULL, NULL,
  93. "CAMG", NULL, NULL, NULL,
  94. NULL, "PBLG", NULL, NULL,
  95. "CFVG", NULL, NULL, NULL,
  96. "USBG", NULL, NULL, "MODG",
  97. "CRDG", "M3GG", "WIMG", "HWCF",
  98. "LIDG", "TYPE", "PBPG", "TPDG"
  99. };
  100. static const char *cm_setv[] = {
  101. "WLDS", "BTHS", NULL, NULL,
  102. "CAMS", NULL, NULL, NULL,
  103. "SDSP", "PBLS", "HDPS", NULL,
  104. "CFVS", NULL, NULL, NULL,
  105. "USBG", NULL, NULL, "MODS",
  106. "CRDS", "M3GS", "WIMS", NULL,
  107. NULL, NULL, "PBPS", "TPDS"
  108. };
  109. #define EEEPC_EC "\\_SB.PCI0.SBRG.EC0."
  110. #define EEEPC_EC_FAN_PWM EEEPC_EC "SC02" /* Fan PWM duty cycle (%) */
  111. #define EEEPC_EC_SC02 0x63
  112. #define EEEPC_EC_FAN_HRPM EEEPC_EC "SC05" /* High byte, fan speed (RPM) */
  113. #define EEEPC_EC_FAN_LRPM EEEPC_EC "SC06" /* Low byte, fan speed (RPM) */
  114. #define EEEPC_EC_FAN_CTRL EEEPC_EC "SFB3" /* Byte containing SF25 */
  115. #define EEEPC_EC_SFB3 0xD3
  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. uint init_flag; /* Init flags */
  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. static void eeepc_rfkill_hotplug(bool real);
  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. int ret;
  305. if (asl != CM_ASL_WLAN)
  306. return set_acpi(asl, !blocked);
  307. /* hack to avoid panic with rt2860sta */
  308. if (blocked)
  309. eeepc_rfkill_hotplug(false);
  310. ret = set_acpi(asl, !blocked);
  311. return ret;
  312. }
  313. static const struct rfkill_ops eeepc_rfkill_ops = {
  314. .set_block = eeepc_rfkill_set,
  315. };
  316. static void __devinit eeepc_enable_camera(void)
  317. {
  318. /*
  319. * If the following call to set_acpi() fails, it's because there's no
  320. * camera so we can ignore the error.
  321. */
  322. set_acpi(CM_ASL_CAMERA, 1);
  323. }
  324. /*
  325. * Sys helpers
  326. */
  327. static int parse_arg(const char *buf, unsigned long count, int *val)
  328. {
  329. if (!count)
  330. return 0;
  331. if (sscanf(buf, "%i", val) != 1)
  332. return -EINVAL;
  333. return count;
  334. }
  335. static ssize_t store_sys_acpi(int cm, const char *buf, size_t count)
  336. {
  337. int rv, value;
  338. rv = parse_arg(buf, count, &value);
  339. if (rv > 0)
  340. value = set_acpi(cm, value);
  341. if (value < 0)
  342. return value;
  343. return rv;
  344. }
  345. static ssize_t show_sys_acpi(int cm, char *buf)
  346. {
  347. int value = get_acpi(cm);
  348. if (value < 0)
  349. return value;
  350. return sprintf(buf, "%d\n", value);
  351. }
  352. #define EEEPC_CREATE_DEVICE_ATTR(_name, _cm) \
  353. static ssize_t show_##_name(struct device *dev, \
  354. struct device_attribute *attr, \
  355. char *buf) \
  356. { \
  357. return show_sys_acpi(_cm, buf); \
  358. } \
  359. static ssize_t store_##_name(struct device *dev, \
  360. struct device_attribute *attr, \
  361. const char *buf, size_t count) \
  362. { \
  363. return store_sys_acpi(_cm, buf, count); \
  364. } \
  365. static struct device_attribute dev_attr_##_name = { \
  366. .attr = { \
  367. .name = __stringify(_name), \
  368. .mode = 0644 }, \
  369. .show = show_##_name, \
  370. .store = store_##_name, \
  371. }
  372. EEEPC_CREATE_DEVICE_ATTR(camera, CM_ASL_CAMERA);
  373. EEEPC_CREATE_DEVICE_ATTR(cardr, CM_ASL_CARDREADER);
  374. EEEPC_CREATE_DEVICE_ATTR(disp, CM_ASL_DISPLAYSWITCH);
  375. struct eeepc_cpufv {
  376. int num;
  377. int cur;
  378. };
  379. static int get_cpufv(struct eeepc_cpufv *c)
  380. {
  381. c->cur = get_acpi(CM_ASL_CPUFV);
  382. c->num = (c->cur >> 8) & 0xff;
  383. c->cur &= 0xff;
  384. if (c->cur < 0 || c->num <= 0 || c->num > 12)
  385. return -ENODEV;
  386. return 0;
  387. }
  388. static ssize_t show_available_cpufv(struct device *dev,
  389. struct device_attribute *attr,
  390. char *buf)
  391. {
  392. struct eeepc_cpufv c;
  393. int i;
  394. ssize_t len = 0;
  395. if (get_cpufv(&c))
  396. return -ENODEV;
  397. for (i = 0; i < c.num; i++)
  398. len += sprintf(buf + len, "%d ", i);
  399. len += sprintf(buf + len, "\n");
  400. return len;
  401. }
  402. static ssize_t show_cpufv(struct device *dev,
  403. struct device_attribute *attr,
  404. char *buf)
  405. {
  406. struct eeepc_cpufv c;
  407. if (get_cpufv(&c))
  408. return -ENODEV;
  409. return sprintf(buf, "%#x\n", (c.num << 8) | c.cur);
  410. }
  411. static ssize_t store_cpufv(struct device *dev,
  412. struct device_attribute *attr,
  413. const char *buf, size_t count)
  414. {
  415. struct eeepc_cpufv c;
  416. int rv, value;
  417. if (get_cpufv(&c))
  418. return -ENODEV;
  419. rv = parse_arg(buf, count, &value);
  420. if (rv < 0)
  421. return rv;
  422. if (!rv || value < 0 || value >= c.num)
  423. return -EINVAL;
  424. set_acpi(CM_ASL_CPUFV, value);
  425. return rv;
  426. }
  427. static struct device_attribute dev_attr_cpufv = {
  428. .attr = {
  429. .name = "cpufv",
  430. .mode = 0644 },
  431. .show = show_cpufv,
  432. .store = store_cpufv
  433. };
  434. static struct device_attribute dev_attr_available_cpufv = {
  435. .attr = {
  436. .name = "available_cpufv",
  437. .mode = 0444 },
  438. .show = show_available_cpufv
  439. };
  440. static struct attribute *platform_attributes[] = {
  441. &dev_attr_camera.attr,
  442. &dev_attr_cardr.attr,
  443. &dev_attr_disp.attr,
  444. &dev_attr_cpufv.attr,
  445. &dev_attr_available_cpufv.attr,
  446. NULL
  447. };
  448. static struct attribute_group platform_attribute_group = {
  449. .attrs = platform_attributes
  450. };
  451. /*
  452. * Hotkey functions
  453. */
  454. static struct key_entry *eepc_get_entry_by_scancode(int code)
  455. {
  456. struct key_entry *key;
  457. for (key = eeepc_keymap; key->type != KE_END; key++)
  458. if (code == key->code)
  459. return key;
  460. return NULL;
  461. }
  462. static struct key_entry *eepc_get_entry_by_keycode(int code)
  463. {
  464. struct key_entry *key;
  465. for (key = eeepc_keymap; key->type != KE_END; key++)
  466. if (code == key->keycode && key->type == KE_KEY)
  467. return key;
  468. return NULL;
  469. }
  470. static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
  471. {
  472. struct key_entry *key = eepc_get_entry_by_scancode(scancode);
  473. if (key && key->type == KE_KEY) {
  474. *keycode = key->keycode;
  475. return 0;
  476. }
  477. return -EINVAL;
  478. }
  479. static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode)
  480. {
  481. struct key_entry *key;
  482. int old_keycode;
  483. if (keycode < 0 || keycode > KEY_MAX)
  484. return -EINVAL;
  485. key = eepc_get_entry_by_scancode(scancode);
  486. if (key && key->type == KE_KEY) {
  487. old_keycode = key->keycode;
  488. key->keycode = keycode;
  489. set_bit(keycode, dev->keybit);
  490. if (!eepc_get_entry_by_keycode(old_keycode))
  491. clear_bit(old_keycode, dev->keybit);
  492. return 0;
  493. }
  494. return -EINVAL;
  495. }
  496. static void cmsg_quirk(int cm, const char *name)
  497. {
  498. int dummy;
  499. /* Some BIOSes do not report cm although it is avaliable.
  500. Check if cm_getv[cm] works and, if yes, assume cm should be set. */
  501. if (!(ehotk->cm_supported & (1 << cm))
  502. && !read_acpi_int(ehotk->handle, cm_getv[cm], &dummy)) {
  503. pr_info("%s (%x) not reported by BIOS,"
  504. " enabling anyway\n", name, 1 << cm);
  505. ehotk->cm_supported |= 1 << cm;
  506. }
  507. }
  508. static void cmsg_quirks(void)
  509. {
  510. cmsg_quirk(CM_ASL_LID, "LID");
  511. cmsg_quirk(CM_ASL_TYPE, "TYPE");
  512. cmsg_quirk(CM_ASL_PANELPOWER, "PANELPOWER");
  513. cmsg_quirk(CM_ASL_TPD, "TPD");
  514. }
  515. static int eeepc_hotk_check(void)
  516. {
  517. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  518. int result;
  519. result = acpi_bus_get_status(ehotk->device);
  520. if (result)
  521. return result;
  522. if (ehotk->device->status.present) {
  523. if (write_acpi_int(ehotk->handle, "INIT", ehotk->init_flag,
  524. &buffer)) {
  525. pr_err("Hotkey initialization failed\n");
  526. return -ENODEV;
  527. } else {
  528. pr_notice("Hotkey init flags 0x%x\n", ehotk->init_flag);
  529. }
  530. /* get control methods supported */
  531. if (read_acpi_int(ehotk->handle, "CMSG"
  532. , &ehotk->cm_supported)) {
  533. pr_err("Get control methods supported failed\n");
  534. return -ENODEV;
  535. } else {
  536. cmsg_quirks();
  537. pr_info("Get control methods supported: 0x%x\n",
  538. ehotk->cm_supported);
  539. }
  540. } else {
  541. pr_err("Hotkey device not present, aborting\n");
  542. return -EINVAL;
  543. }
  544. return 0;
  545. }
  546. static int notify_brn(void)
  547. {
  548. /* returns the *previous* brightness, or -1 */
  549. struct backlight_device *bd = eeepc_backlight_device;
  550. if (bd) {
  551. int old = bd->props.brightness;
  552. backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
  553. return old;
  554. }
  555. return -1;
  556. }
  557. static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
  558. u8 *value)
  559. {
  560. int val = get_acpi(CM_ASL_WLAN);
  561. if (val == 1 || val == 0)
  562. *value = val;
  563. else
  564. return -EINVAL;
  565. return 0;
  566. }
  567. static void eeepc_rfkill_hotplug(bool real)
  568. {
  569. struct pci_dev *dev;
  570. struct pci_bus *bus;
  571. bool blocked = real ? eeepc_wlan_rfkill_blocked() : true;
  572. if (real && ehotk->wlan_rfkill)
  573. rfkill_set_sw_state(ehotk->wlan_rfkill, blocked);
  574. mutex_lock(&ehotk->hotplug_lock);
  575. if (ehotk->hotplug_slot) {
  576. bus = pci_find_bus(0, 1);
  577. if (!bus) {
  578. pr_warning("Unable to find PCI bus 1?\n");
  579. goto out_unlock;
  580. }
  581. if (!blocked) {
  582. dev = pci_get_slot(bus, 0);
  583. if (dev) {
  584. /* Device already present */
  585. pci_dev_put(dev);
  586. goto out_unlock;
  587. }
  588. dev = pci_scan_single_device(bus, 0);
  589. if (dev) {
  590. pci_bus_assign_resources(bus);
  591. if (pci_bus_add_device(dev))
  592. pr_err("Unable to hotplug wifi\n");
  593. }
  594. } else {
  595. dev = pci_get_slot(bus, 0);
  596. if (dev) {
  597. pci_remove_bus_device(dev);
  598. pci_dev_put(dev);
  599. }
  600. }
  601. }
  602. out_unlock:
  603. mutex_unlock(&ehotk->hotplug_lock);
  604. }
  605. static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
  606. {
  607. if (event != ACPI_NOTIFY_BUS_CHECK)
  608. return;
  609. eeepc_rfkill_hotplug(true);
  610. }
  611. static void eeepc_hotk_notify(struct acpi_device *device, u32 event)
  612. {
  613. static struct key_entry *key;
  614. u16 count;
  615. int brn = -ENODEV;
  616. if (!ehotk)
  617. return;
  618. if (event > ACPI_MAX_SYS_NOTIFY)
  619. return;
  620. if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX)
  621. brn = notify_brn();
  622. count = ehotk->event_count[event % 128]++;
  623. acpi_bus_generate_proc_event(ehotk->device, event, count);
  624. acpi_bus_generate_netlink_event(ehotk->device->pnp.device_class,
  625. dev_name(&ehotk->device->dev), event,
  626. count);
  627. if (ehotk->inputdev) {
  628. if (brn != -ENODEV) {
  629. /* brightness-change events need special
  630. * handling for conversion to key events
  631. */
  632. if (brn < 0)
  633. brn = event;
  634. else
  635. brn += NOTIFY_BRN_MIN;
  636. if (event < brn)
  637. event = NOTIFY_BRN_MIN; /* brightness down */
  638. else if (event > brn)
  639. event = NOTIFY_BRN_MIN + 2; /* ... up */
  640. else
  641. event = NOTIFY_BRN_MIN + 1; /* ... unchanged */
  642. }
  643. key = eepc_get_entry_by_scancode(event);
  644. if (key) {
  645. switch (key->type) {
  646. case KE_KEY:
  647. input_report_key(ehotk->inputdev, key->keycode,
  648. 1);
  649. input_sync(ehotk->inputdev);
  650. input_report_key(ehotk->inputdev, key->keycode,
  651. 0);
  652. input_sync(ehotk->inputdev);
  653. break;
  654. }
  655. }
  656. }
  657. }
  658. static int eeepc_register_rfkill_notifier(char *node)
  659. {
  660. acpi_status status = AE_OK;
  661. acpi_handle handle;
  662. status = acpi_get_handle(NULL, node, &handle);
  663. if (ACPI_SUCCESS(status)) {
  664. status = acpi_install_notify_handler(handle,
  665. ACPI_SYSTEM_NOTIFY,
  666. eeepc_rfkill_notify,
  667. NULL);
  668. if (ACPI_FAILURE(status))
  669. pr_warning("Failed to register notify on %s\n", node);
  670. } else
  671. return -ENODEV;
  672. return 0;
  673. }
  674. static void eeepc_unregister_rfkill_notifier(char *node)
  675. {
  676. acpi_status status = AE_OK;
  677. acpi_handle handle;
  678. status = acpi_get_handle(NULL, node, &handle);
  679. if (ACPI_SUCCESS(status)) {
  680. status = acpi_remove_notify_handler(handle,
  681. ACPI_SYSTEM_NOTIFY,
  682. eeepc_rfkill_notify);
  683. if (ACPI_FAILURE(status))
  684. pr_err("Error removing rfkill notify handler %s\n",
  685. node);
  686. }
  687. }
  688. static void eeepc_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot)
  689. {
  690. kfree(hotplug_slot->info);
  691. kfree(hotplug_slot);
  692. }
  693. static int eeepc_setup_pci_hotplug(void)
  694. {
  695. int ret = -ENOMEM;
  696. struct pci_bus *bus = pci_find_bus(0, 1);
  697. if (!bus) {
  698. pr_err("Unable to find wifi PCI bus\n");
  699. return -ENODEV;
  700. }
  701. ehotk->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
  702. if (!ehotk->hotplug_slot)
  703. goto error_slot;
  704. ehotk->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
  705. GFP_KERNEL);
  706. if (!ehotk->hotplug_slot->info)
  707. goto error_info;
  708. ehotk->hotplug_slot->private = ehotk;
  709. ehotk->hotplug_slot->release = &eeepc_cleanup_pci_hotplug;
  710. ehotk->hotplug_slot->ops = &eeepc_hotplug_slot_ops;
  711. eeepc_get_adapter_status(ehotk->hotplug_slot,
  712. &ehotk->hotplug_slot->info->adapter_status);
  713. ret = pci_hp_register(ehotk->hotplug_slot, bus, 0, "eeepc-wifi");
  714. if (ret) {
  715. pr_err("Unable to register hotplug slot - %d\n", ret);
  716. goto error_register;
  717. }
  718. return 0;
  719. error_register:
  720. kfree(ehotk->hotplug_slot->info);
  721. error_info:
  722. kfree(ehotk->hotplug_slot);
  723. ehotk->hotplug_slot = NULL;
  724. error_slot:
  725. return ret;
  726. }
  727. static int eeepc_hotk_thaw(struct device *device)
  728. {
  729. if (ehotk->wlan_rfkill) {
  730. bool wlan;
  731. /*
  732. * Work around bios bug - acpi _PTS turns off the wireless led
  733. * during suspend. Normally it restores it on resume, but
  734. * we should kick it ourselves in case hibernation is aborted.
  735. */
  736. wlan = get_acpi(CM_ASL_WLAN);
  737. set_acpi(CM_ASL_WLAN, wlan);
  738. }
  739. return 0;
  740. }
  741. static int eeepc_hotk_restore(struct device *device)
  742. {
  743. /* Refresh both wlan rfkill state and pci hotplug */
  744. if (ehotk->wlan_rfkill)
  745. eeepc_rfkill_hotplug(true);
  746. if (ehotk->bluetooth_rfkill)
  747. rfkill_set_sw_state(ehotk->bluetooth_rfkill,
  748. get_acpi(CM_ASL_BLUETOOTH) != 1);
  749. if (ehotk->wwan3g_rfkill)
  750. rfkill_set_sw_state(ehotk->wwan3g_rfkill,
  751. get_acpi(CM_ASL_3G) != 1);
  752. if (ehotk->wimax_rfkill)
  753. rfkill_set_sw_state(ehotk->wimax_rfkill,
  754. get_acpi(CM_ASL_WIMAX) != 1);
  755. return 0;
  756. }
  757. /*
  758. * Hwmon
  759. */
  760. static int eeepc_get_fan_pwm(void)
  761. {
  762. int value = 0;
  763. read_acpi_int(NULL, EEEPC_EC_FAN_PWM, &value);
  764. value = value * 255 / 100;
  765. return (value);
  766. }
  767. static void eeepc_set_fan_pwm(int value)
  768. {
  769. value = SENSORS_LIMIT(value, 0, 255);
  770. value = value * 100 / 255;
  771. ec_write(EEEPC_EC_SC02, value);
  772. }
  773. static int eeepc_get_fan_rpm(void)
  774. {
  775. int high = 0;
  776. int low = 0;
  777. read_acpi_int(NULL, EEEPC_EC_FAN_HRPM, &high);
  778. read_acpi_int(NULL, EEEPC_EC_FAN_LRPM, &low);
  779. return (high << 8 | low);
  780. }
  781. static int eeepc_get_fan_ctrl(void)
  782. {
  783. int value = 0;
  784. read_acpi_int(NULL, EEEPC_EC_FAN_CTRL, &value);
  785. return ((value & 0x02 ? 1 : 0));
  786. }
  787. static void eeepc_set_fan_ctrl(int manual)
  788. {
  789. int value = 0;
  790. read_acpi_int(NULL, EEEPC_EC_FAN_CTRL, &value);
  791. if (manual)
  792. value |= 0x02;
  793. else
  794. value &= ~0x02;
  795. ec_write(EEEPC_EC_SFB3, value);
  796. }
  797. static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
  798. {
  799. int rv, value;
  800. rv = parse_arg(buf, count, &value);
  801. if (rv > 0)
  802. set(value);
  803. return rv;
  804. }
  805. static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
  806. {
  807. return sprintf(buf, "%d\n", get());
  808. }
  809. #define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _set, _get) \
  810. static ssize_t show_##_name(struct device *dev, \
  811. struct device_attribute *attr, \
  812. char *buf) \
  813. { \
  814. return show_sys_hwmon(_set, buf); \
  815. } \
  816. static ssize_t store_##_name(struct device *dev, \
  817. struct device_attribute *attr, \
  818. const char *buf, size_t count) \
  819. { \
  820. return store_sys_hwmon(_get, buf, count); \
  821. } \
  822. static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0);
  823. EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL);
  824. EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
  825. eeepc_get_fan_pwm, eeepc_set_fan_pwm);
  826. EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
  827. eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
  828. static ssize_t
  829. show_name(struct device *dev, struct device_attribute *attr, char *buf)
  830. {
  831. return sprintf(buf, "eeepc\n");
  832. }
  833. static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
  834. static struct attribute *hwmon_attributes[] = {
  835. &sensor_dev_attr_pwm1.dev_attr.attr,
  836. &sensor_dev_attr_fan1_input.dev_attr.attr,
  837. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  838. &sensor_dev_attr_name.dev_attr.attr,
  839. NULL
  840. };
  841. static struct attribute_group hwmon_attribute_group = {
  842. .attrs = hwmon_attributes
  843. };
  844. /*
  845. * exit/init
  846. */
  847. static void eeepc_backlight_exit(void)
  848. {
  849. if (eeepc_backlight_device)
  850. backlight_device_unregister(eeepc_backlight_device);
  851. eeepc_backlight_device = NULL;
  852. }
  853. static void eeepc_rfkill_exit(void)
  854. {
  855. eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P5");
  856. eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P6");
  857. eeepc_unregister_rfkill_notifier("\\_SB.PCI0.P0P7");
  858. if (ehotk->wlan_rfkill) {
  859. rfkill_unregister(ehotk->wlan_rfkill);
  860. rfkill_destroy(ehotk->wlan_rfkill);
  861. ehotk->wlan_rfkill = NULL;
  862. }
  863. /*
  864. * Refresh pci hotplug in case the rfkill state was changed after
  865. * eeepc_unregister_rfkill_notifier()
  866. */
  867. eeepc_rfkill_hotplug(true);
  868. if (ehotk->hotplug_slot)
  869. pci_hp_deregister(ehotk->hotplug_slot);
  870. if (ehotk->bluetooth_rfkill) {
  871. rfkill_unregister(ehotk->bluetooth_rfkill);
  872. rfkill_destroy(ehotk->bluetooth_rfkill);
  873. ehotk->bluetooth_rfkill = NULL;
  874. }
  875. if (ehotk->wwan3g_rfkill) {
  876. rfkill_unregister(ehotk->wwan3g_rfkill);
  877. rfkill_destroy(ehotk->wwan3g_rfkill);
  878. ehotk->wwan3g_rfkill = NULL;
  879. }
  880. if (ehotk->wimax_rfkill) {
  881. rfkill_unregister(ehotk->wimax_rfkill);
  882. rfkill_destroy(ehotk->wimax_rfkill);
  883. ehotk->wimax_rfkill = NULL;
  884. }
  885. }
  886. static void eeepc_input_exit(void)
  887. {
  888. if (ehotk->inputdev)
  889. input_unregister_device(ehotk->inputdev);
  890. }
  891. static void eeepc_hwmon_exit(void)
  892. {
  893. struct device *hwmon;
  894. hwmon = eeepc_hwmon_device;
  895. if (!hwmon)
  896. return ;
  897. sysfs_remove_group(&hwmon->kobj,
  898. &hwmon_attribute_group);
  899. hwmon_device_unregister(hwmon);
  900. eeepc_hwmon_device = NULL;
  901. }
  902. static int eeepc_new_rfkill(struct rfkill **rfkill,
  903. const char *name, struct device *dev,
  904. enum rfkill_type type, int cm)
  905. {
  906. int result;
  907. result = get_acpi(cm);
  908. if (result < 0)
  909. return result;
  910. *rfkill = rfkill_alloc(name, dev, type,
  911. &eeepc_rfkill_ops, (void *)(unsigned long)cm);
  912. if (!*rfkill)
  913. return -EINVAL;
  914. rfkill_init_sw_state(*rfkill, get_acpi(cm) != 1);
  915. result = rfkill_register(*rfkill);
  916. if (result) {
  917. rfkill_destroy(*rfkill);
  918. *rfkill = NULL;
  919. return result;
  920. }
  921. return 0;
  922. }
  923. static int eeepc_rfkill_init(struct device *dev)
  924. {
  925. int result = 0;
  926. mutex_init(&ehotk->hotplug_lock);
  927. result = eeepc_new_rfkill(&ehotk->wlan_rfkill,
  928. "eeepc-wlan", dev,
  929. RFKILL_TYPE_WLAN, CM_ASL_WLAN);
  930. if (result && result != -ENODEV)
  931. goto exit;
  932. result = eeepc_new_rfkill(&ehotk->bluetooth_rfkill,
  933. "eeepc-bluetooth", dev,
  934. RFKILL_TYPE_BLUETOOTH, CM_ASL_BLUETOOTH);
  935. if (result && result != -ENODEV)
  936. goto exit;
  937. result = eeepc_new_rfkill(&ehotk->wwan3g_rfkill,
  938. "eeepc-wwan3g", dev,
  939. RFKILL_TYPE_WWAN, CM_ASL_3G);
  940. if (result && result != -ENODEV)
  941. goto exit;
  942. result = eeepc_new_rfkill(&ehotk->wimax_rfkill,
  943. "eeepc-wimax", dev,
  944. RFKILL_TYPE_WIMAX, CM_ASL_WIMAX);
  945. if (result && result != -ENODEV)
  946. goto exit;
  947. result = eeepc_setup_pci_hotplug();
  948. /*
  949. * If we get -EBUSY then something else is handling the PCI hotplug -
  950. * don't fail in this case
  951. */
  952. if (result == -EBUSY)
  953. result = 0;
  954. eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P5");
  955. eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P6");
  956. eeepc_register_rfkill_notifier("\\_SB.PCI0.P0P7");
  957. /*
  958. * Refresh pci hotplug in case the rfkill state was changed during
  959. * setup.
  960. */
  961. eeepc_rfkill_hotplug(true);
  962. exit:
  963. if (result && result != -ENODEV)
  964. eeepc_rfkill_exit();
  965. return result;
  966. }
  967. static int eeepc_backlight_init(struct device *dev)
  968. {
  969. struct backlight_device *bd;
  970. bd = backlight_device_register(EEEPC_HOTK_FILE, dev,
  971. NULL, &eeepcbl_ops);
  972. if (IS_ERR(bd)) {
  973. pr_err("Could not register eeepc backlight device\n");
  974. eeepc_backlight_device = NULL;
  975. return PTR_ERR(bd);
  976. }
  977. eeepc_backlight_device = bd;
  978. bd->props.max_brightness = 15;
  979. bd->props.brightness = read_brightness(NULL);
  980. bd->props.power = FB_BLANK_UNBLANK;
  981. backlight_update_status(bd);
  982. return 0;
  983. }
  984. static int eeepc_hwmon_init(struct device *dev)
  985. {
  986. struct device *hwmon;
  987. int result;
  988. hwmon = hwmon_device_register(dev);
  989. if (IS_ERR(hwmon)) {
  990. pr_err("Could not register eeepc hwmon device\n");
  991. eeepc_hwmon_device = NULL;
  992. return PTR_ERR(hwmon);
  993. }
  994. eeepc_hwmon_device = hwmon;
  995. result = sysfs_create_group(&hwmon->kobj,
  996. &hwmon_attribute_group);
  997. if (result)
  998. eeepc_hwmon_exit();
  999. return result;
  1000. }
  1001. static int eeepc_input_init(struct device *dev)
  1002. {
  1003. const struct key_entry *key;
  1004. int result;
  1005. ehotk->inputdev = input_allocate_device();
  1006. if (!ehotk->inputdev) {
  1007. pr_info("Unable to allocate input device\n");
  1008. return -ENOMEM;
  1009. }
  1010. ehotk->inputdev->name = "Asus EeePC extra buttons";
  1011. ehotk->inputdev->dev.parent = dev;
  1012. ehotk->inputdev->phys = EEEPC_HOTK_FILE "/input0";
  1013. ehotk->inputdev->id.bustype = BUS_HOST;
  1014. ehotk->inputdev->getkeycode = eeepc_getkeycode;
  1015. ehotk->inputdev->setkeycode = eeepc_setkeycode;
  1016. for (key = eeepc_keymap; key->type != KE_END; key++) {
  1017. switch (key->type) {
  1018. case KE_KEY:
  1019. set_bit(EV_KEY, ehotk->inputdev->evbit);
  1020. set_bit(key->keycode, ehotk->inputdev->keybit);
  1021. break;
  1022. }
  1023. }
  1024. result = input_register_device(ehotk->inputdev);
  1025. if (result) {
  1026. pr_info("Unable to register input device\n");
  1027. input_free_device(ehotk->inputdev);
  1028. return result;
  1029. }
  1030. return 0;
  1031. }
  1032. static int __devinit eeepc_hotk_add(struct acpi_device *device)
  1033. {
  1034. struct device *dev;
  1035. int result;
  1036. if (!device)
  1037. return -EINVAL;
  1038. pr_notice(EEEPC_HOTK_NAME "\n");
  1039. ehotk = kzalloc(sizeof(struct eeepc_hotk), GFP_KERNEL);
  1040. if (!ehotk)
  1041. return -ENOMEM;
  1042. ehotk->init_flag = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
  1043. ehotk->handle = device->handle;
  1044. strcpy(acpi_device_name(device), EEEPC_HOTK_DEVICE_NAME);
  1045. strcpy(acpi_device_class(device), EEEPC_HOTK_CLASS);
  1046. device->driver_data = ehotk;
  1047. ehotk->device = device;
  1048. result = eeepc_hotk_check();
  1049. if (result)
  1050. goto fail_platform_driver;
  1051. eeepc_enable_camera();
  1052. /* Register platform stuff */
  1053. result = platform_driver_register(&platform_driver);
  1054. if (result)
  1055. goto fail_platform_driver;
  1056. platform_device = platform_device_alloc(EEEPC_HOTK_FILE, -1);
  1057. if (!platform_device) {
  1058. result = -ENOMEM;
  1059. goto fail_platform_device1;
  1060. }
  1061. result = platform_device_add(platform_device);
  1062. if (result)
  1063. goto fail_platform_device2;
  1064. result = sysfs_create_group(&platform_device->dev.kobj,
  1065. &platform_attribute_group);
  1066. if (result)
  1067. goto fail_sysfs;
  1068. dev = &platform_device->dev;
  1069. if (!acpi_video_backlight_support()) {
  1070. result = eeepc_backlight_init(dev);
  1071. if (result)
  1072. goto fail_backlight;
  1073. } else
  1074. pr_info("Backlight controlled by ACPI video "
  1075. "driver\n");
  1076. result = eeepc_input_init(dev);
  1077. if (result)
  1078. goto fail_input;
  1079. result = eeepc_hwmon_init(dev);
  1080. if (result)
  1081. goto fail_hwmon;
  1082. result = eeepc_rfkill_init(dev);
  1083. if (result)
  1084. goto fail_rfkill;
  1085. return 0;
  1086. fail_rfkill:
  1087. eeepc_hwmon_exit();
  1088. fail_hwmon:
  1089. eeepc_input_exit();
  1090. fail_input:
  1091. eeepc_backlight_exit();
  1092. fail_backlight:
  1093. sysfs_remove_group(&platform_device->dev.kobj,
  1094. &platform_attribute_group);
  1095. fail_sysfs:
  1096. platform_device_del(platform_device);
  1097. fail_platform_device2:
  1098. platform_device_put(platform_device);
  1099. fail_platform_device1:
  1100. platform_driver_unregister(&platform_driver);
  1101. fail_platform_driver:
  1102. kfree(ehotk);
  1103. return result;
  1104. }
  1105. static int eeepc_hotk_remove(struct acpi_device *device, int type)
  1106. {
  1107. if (!device || !acpi_driver_data(device))
  1108. return -EINVAL;
  1109. eeepc_backlight_exit();
  1110. eeepc_rfkill_exit();
  1111. eeepc_input_exit();
  1112. eeepc_hwmon_exit();
  1113. sysfs_remove_group(&platform_device->dev.kobj,
  1114. &platform_attribute_group);
  1115. platform_device_unregister(platform_device);
  1116. platform_driver_unregister(&platform_driver);
  1117. kfree(ehotk);
  1118. return 0;
  1119. }
  1120. static int __init eeepc_laptop_init(void)
  1121. {
  1122. int result;
  1123. if (acpi_disabled)
  1124. return -ENODEV;
  1125. result = acpi_bus_register_driver(&eeepc_hotk_driver);
  1126. if (result < 0)
  1127. return result;
  1128. if (!ehotk) {
  1129. acpi_bus_unregister_driver(&eeepc_hotk_driver);
  1130. return -ENODEV;
  1131. }
  1132. return 0;
  1133. }
  1134. static void __exit eeepc_laptop_exit(void)
  1135. {
  1136. acpi_bus_unregister_driver(&eeepc_hotk_driver);
  1137. }
  1138. module_init(eeepc_laptop_init);
  1139. module_exit(eeepc_laptop_exit);