eeepc-laptop.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/types.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/backlight.h>
  24. #include <linux/fb.h>
  25. #include <linux/hwmon.h>
  26. #include <linux/hwmon-sysfs.h>
  27. #include <acpi/acpi_drivers.h>
  28. #include <acpi/acpi_bus.h>
  29. #include <linux/uaccess.h>
  30. #define EEEPC_LAPTOP_VERSION "0.1"
  31. #define EEEPC_HOTK_NAME "Eee PC Hotkey Driver"
  32. #define EEEPC_HOTK_FILE "eeepc"
  33. #define EEEPC_HOTK_CLASS "hotkey"
  34. #define EEEPC_HOTK_DEVICE_NAME "Hotkey"
  35. #define EEEPC_HOTK_HID "ASUS010"
  36. #define EEEPC_LOG EEEPC_HOTK_FILE ": "
  37. #define EEEPC_ERR KERN_ERR EEEPC_LOG
  38. #define EEEPC_WARNING KERN_WARNING EEEPC_LOG
  39. #define EEEPC_NOTICE KERN_NOTICE EEEPC_LOG
  40. #define EEEPC_INFO KERN_INFO EEEPC_LOG
  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. };
  58. enum {
  59. CM_ASL_WLAN = 0,
  60. CM_ASL_BLUETOOTH,
  61. CM_ASL_IRDA,
  62. CM_ASL_1394,
  63. CM_ASL_CAMERA,
  64. CM_ASL_TV,
  65. CM_ASL_GPS,
  66. CM_ASL_DVDROM,
  67. CM_ASL_DISPLAYSWITCH,
  68. CM_ASL_PANELBRIGHT,
  69. CM_ASL_BIOSFLASH,
  70. CM_ASL_ACPIFLASH,
  71. CM_ASL_CPUFV,
  72. CM_ASL_CPUTEMPERATURE,
  73. CM_ASL_FANCPU,
  74. CM_ASL_FANCHASSIS,
  75. CM_ASL_USBPORT1,
  76. CM_ASL_USBPORT2,
  77. CM_ASL_USBPORT3,
  78. CM_ASL_MODEM,
  79. CM_ASL_CARDREADER,
  80. CM_ASL_LID
  81. };
  82. static const char *cm_getv[] = {
  83. "WLDG", NULL, NULL, NULL,
  84. "CAMG", NULL, NULL, NULL,
  85. NULL, "PBLG", NULL, NULL,
  86. "CFVG", NULL, NULL, NULL,
  87. "USBG", NULL, NULL, "MODG",
  88. "CRDG", "LIDG"
  89. };
  90. static const char *cm_setv[] = {
  91. "WLDS", NULL, NULL, NULL,
  92. "CAMS", NULL, NULL, NULL,
  93. "SDSP", "PBLS", "HDPS", NULL,
  94. "CFVS", NULL, NULL, NULL,
  95. "USBG", NULL, NULL, "MODS",
  96. "CRDS", NULL
  97. };
  98. #define EEEPC_EC "\\_SB.PCI0.SBRG.EC0."
  99. #define EEEPC_EC_FAN_PWM EEEPC_EC "SC02" /* Fan PWM duty cycle (%) */
  100. #define EEEPC_EC_SC02 0x63
  101. #define EEEPC_EC_FAN_HRPM EEEPC_EC "SC05" /* High byte, fan speed (RPM) */
  102. #define EEEPC_EC_FAN_LRPM EEEPC_EC "SC06" /* Low byte, fan speed (RPM) */
  103. #define EEEPC_EC_FAN_CTRL EEEPC_EC "SFB3" /* Byte containing SF25 */
  104. #define EEEPC_EC_SFB3 0xD3
  105. /*
  106. * This is the main structure, we can use it to store useful information
  107. * about the hotk device
  108. */
  109. struct eeepc_hotk {
  110. struct acpi_device *device; /* the device we are in */
  111. acpi_handle handle; /* the handle of the hotk device */
  112. u32 cm_supported; /* the control methods supported
  113. by this BIOS */
  114. uint init_flag; /* Init flags */
  115. u16 event_count[128]; /* count for each event */
  116. };
  117. /* The actual device the driver binds to */
  118. static struct eeepc_hotk *ehotk;
  119. /* Platform device/driver */
  120. static struct platform_driver platform_driver = {
  121. .driver = {
  122. .name = EEEPC_HOTK_FILE,
  123. .owner = THIS_MODULE,
  124. }
  125. };
  126. static struct platform_device *platform_device;
  127. /*
  128. * The hotkey driver declaration
  129. */
  130. static int eeepc_hotk_add(struct acpi_device *device);
  131. static int eeepc_hotk_remove(struct acpi_device *device, int type);
  132. static const struct acpi_device_id eeepc_device_ids[] = {
  133. {EEEPC_HOTK_HID, 0},
  134. {"", 0},
  135. };
  136. MODULE_DEVICE_TABLE(acpi, eeepc_device_ids);
  137. static struct acpi_driver eeepc_hotk_driver = {
  138. .name = EEEPC_HOTK_NAME,
  139. .class = EEEPC_HOTK_CLASS,
  140. .ids = eeepc_device_ids,
  141. .ops = {
  142. .add = eeepc_hotk_add,
  143. .remove = eeepc_hotk_remove,
  144. },
  145. };
  146. /* The backlight device /sys/class/backlight */
  147. static struct backlight_device *eeepc_backlight_device;
  148. /* The hwmon device */
  149. static struct device *eeepc_hwmon_device;
  150. /*
  151. * The backlight class declaration
  152. */
  153. static int read_brightness(struct backlight_device *bd);
  154. static int update_bl_status(struct backlight_device *bd);
  155. static struct backlight_ops eeepcbl_ops = {
  156. .get_brightness = read_brightness,
  157. .update_status = update_bl_status,
  158. };
  159. MODULE_AUTHOR("Corentin Chary, Eric Cooper");
  160. MODULE_DESCRIPTION(EEEPC_HOTK_NAME);
  161. MODULE_LICENSE("GPL");
  162. /*
  163. * ACPI Helpers
  164. */
  165. static int write_acpi_int(acpi_handle handle, const char *method, int val,
  166. struct acpi_buffer *output)
  167. {
  168. struct acpi_object_list params;
  169. union acpi_object in_obj;
  170. acpi_status status;
  171. params.count = 1;
  172. params.pointer = &in_obj;
  173. in_obj.type = ACPI_TYPE_INTEGER;
  174. in_obj.integer.value = val;
  175. status = acpi_evaluate_object(handle, (char *)method, &params, output);
  176. return (status == AE_OK ? 0 : -1);
  177. }
  178. static int read_acpi_int(acpi_handle handle, const char *method, int *val)
  179. {
  180. acpi_status status;
  181. ulong result;
  182. status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
  183. if (ACPI_FAILURE(status)) {
  184. *val = -1;
  185. return -1;
  186. } else {
  187. *val = result;
  188. return 0;
  189. }
  190. }
  191. static int set_acpi(int cm, int value)
  192. {
  193. if (ehotk->cm_supported & (0x1 << cm)) {
  194. const char *method = cm_setv[cm];
  195. if (method == NULL)
  196. return -ENODEV;
  197. if (write_acpi_int(ehotk->handle, method, value, NULL))
  198. printk(EEEPC_WARNING "Error writing %s\n", method);
  199. }
  200. return 0;
  201. }
  202. static int get_acpi(int cm)
  203. {
  204. int value = -1;
  205. if ((ehotk->cm_supported & (0x1 << cm))) {
  206. const char *method = cm_getv[cm];
  207. if (method == NULL)
  208. return -ENODEV;
  209. if (read_acpi_int(ehotk->handle, method, &value))
  210. printk(EEEPC_WARNING "Error reading %s\n", method);
  211. }
  212. return value;
  213. }
  214. /*
  215. * Backlight
  216. */
  217. static int read_brightness(struct backlight_device *bd)
  218. {
  219. return get_acpi(CM_ASL_PANELBRIGHT);
  220. }
  221. static int set_brightness(struct backlight_device *bd, int value)
  222. {
  223. value = max(0, min(15, value));
  224. return set_acpi(CM_ASL_PANELBRIGHT, value);
  225. }
  226. static int update_bl_status(struct backlight_device *bd)
  227. {
  228. return set_brightness(bd, bd->props.brightness);
  229. }
  230. /*
  231. * Sys helpers
  232. */
  233. static int parse_arg(const char *buf, unsigned long count, int *val)
  234. {
  235. if (!count)
  236. return 0;
  237. if (sscanf(buf, "%i", val) != 1)
  238. return -EINVAL;
  239. return count;
  240. }
  241. static ssize_t store_sys_acpi(int cm, const char *buf, size_t count)
  242. {
  243. int rv, value;
  244. rv = parse_arg(buf, count, &value);
  245. if (rv > 0)
  246. set_acpi(cm, value);
  247. return rv;
  248. }
  249. static ssize_t show_sys_acpi(int cm, char *buf)
  250. {
  251. return sprintf(buf, "%d\n", get_acpi(cm));
  252. }
  253. #define EEEPC_CREATE_DEVICE_ATTR(_name, _cm) \
  254. static ssize_t show_##_name(struct device *dev, \
  255. struct device_attribute *attr, \
  256. char *buf) \
  257. { \
  258. return show_sys_acpi(_cm, buf); \
  259. } \
  260. static ssize_t store_##_name(struct device *dev, \
  261. struct device_attribute *attr, \
  262. const char *buf, size_t count) \
  263. { \
  264. return store_sys_acpi(_cm, buf, count); \
  265. } \
  266. static struct device_attribute dev_attr_##_name = { \
  267. .attr = { \
  268. .name = __stringify(_name), \
  269. .mode = 0644 }, \
  270. .show = show_##_name, \
  271. .store = store_##_name, \
  272. }
  273. EEEPC_CREATE_DEVICE_ATTR(camera, CM_ASL_CAMERA);
  274. EEEPC_CREATE_DEVICE_ATTR(cardr, CM_ASL_CARDREADER);
  275. EEEPC_CREATE_DEVICE_ATTR(disp, CM_ASL_DISPLAYSWITCH);
  276. EEEPC_CREATE_DEVICE_ATTR(wlan, CM_ASL_WLAN);
  277. static struct attribute *platform_attributes[] = {
  278. &dev_attr_camera.attr,
  279. &dev_attr_cardr.attr,
  280. &dev_attr_disp.attr,
  281. &dev_attr_wlan.attr,
  282. NULL
  283. };
  284. static struct attribute_group platform_attribute_group = {
  285. .attrs = platform_attributes
  286. };
  287. /*
  288. * Hotkey functions
  289. */
  290. static int eeepc_hotk_check(void)
  291. {
  292. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  293. int result;
  294. result = acpi_bus_get_status(ehotk->device);
  295. if (result)
  296. return result;
  297. if (ehotk->device->status.present) {
  298. if (write_acpi_int(ehotk->handle, "INIT", ehotk->init_flag,
  299. &buffer)) {
  300. printk(EEEPC_ERR "Hotkey initialization failed\n");
  301. return -ENODEV;
  302. } else {
  303. printk(EEEPC_NOTICE "Hotkey init flags 0x%x\n",
  304. ehotk->init_flag);
  305. }
  306. /* get control methods supported */
  307. if (read_acpi_int(ehotk->handle, "CMSG"
  308. , &ehotk->cm_supported)) {
  309. printk(EEEPC_ERR
  310. "Get control methods supported failed\n");
  311. return -ENODEV;
  312. } else {
  313. printk(EEEPC_INFO
  314. "Get control methods supported: 0x%x\n",
  315. ehotk->cm_supported);
  316. }
  317. } else {
  318. printk(EEEPC_ERR "Hotkey device not present, aborting\n");
  319. return -EINVAL;
  320. }
  321. return 0;
  322. }
  323. static void notify_wlan(u32 *event)
  324. {
  325. /* if DISABLE_ASL_WLAN is set, the notify code for fn+f2
  326. will always be 0x10 */
  327. if (ehotk->cm_supported & (0x1 << CM_ASL_WLAN)) {
  328. const char *method = cm_getv[CM_ASL_WLAN];
  329. int value;
  330. if (read_acpi_int(ehotk->handle, method, &value))
  331. printk(EEEPC_WARNING "Error reading %s\n",
  332. method);
  333. else if (value == 1)
  334. *event = 0x11;
  335. }
  336. }
  337. static void notify_brn(void)
  338. {
  339. struct backlight_device *bd = eeepc_backlight_device;
  340. bd->props.brightness = read_brightness(bd);
  341. }
  342. static void eeepc_hotk_notify(acpi_handle handle, u32 event, void *data)
  343. {
  344. if (!ehotk)
  345. return;
  346. if (event == NOTIFY_WLAN_ON && (DISABLE_ASL_WLAN & ehotk->init_flag))
  347. notify_wlan(&event);
  348. if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX)
  349. notify_brn();
  350. acpi_bus_generate_proc_event(ehotk->device, event,
  351. ehotk->event_count[event % 128]++);
  352. }
  353. static int eeepc_hotk_add(struct acpi_device *device)
  354. {
  355. acpi_status status = AE_OK;
  356. int result;
  357. if (!device)
  358. return -EINVAL;
  359. printk(EEEPC_NOTICE EEEPC_HOTK_NAME "\n");
  360. ehotk = kzalloc(sizeof(struct eeepc_hotk), GFP_KERNEL);
  361. if (!ehotk)
  362. return -ENOMEM;
  363. ehotk->init_flag = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
  364. ehotk->handle = device->handle;
  365. strcpy(acpi_device_name(device), EEEPC_HOTK_DEVICE_NAME);
  366. strcpy(acpi_device_class(device), EEEPC_HOTK_CLASS);
  367. acpi_driver_data(device) = ehotk;
  368. ehotk->device = device;
  369. result = eeepc_hotk_check();
  370. if (result)
  371. goto end;
  372. status = acpi_install_notify_handler(ehotk->handle, ACPI_SYSTEM_NOTIFY,
  373. eeepc_hotk_notify, ehotk);
  374. if (ACPI_FAILURE(status))
  375. printk(EEEPC_ERR "Error installing notify handler\n");
  376. end:
  377. if (result) {
  378. kfree(ehotk);
  379. ehotk = NULL;
  380. }
  381. return result;
  382. }
  383. static int eeepc_hotk_remove(struct acpi_device *device, int type)
  384. {
  385. acpi_status status = 0;
  386. if (!device || !acpi_driver_data(device))
  387. return -EINVAL;
  388. status = acpi_remove_notify_handler(ehotk->handle, ACPI_SYSTEM_NOTIFY,
  389. eeepc_hotk_notify);
  390. if (ACPI_FAILURE(status))
  391. printk(EEEPC_ERR "Error removing notify handler\n");
  392. kfree(ehotk);
  393. return 0;
  394. }
  395. /*
  396. * Hwmon
  397. */
  398. static int eeepc_get_fan_pwm(void)
  399. {
  400. int value = 0;
  401. read_acpi_int(NULL, EEEPC_EC_FAN_PWM, &value);
  402. value = value * 255 / 100;
  403. return (value);
  404. }
  405. static void eeepc_set_fan_pwm(int value)
  406. {
  407. value = SENSORS_LIMIT(value, 0, 255);
  408. value = value * 100 / 255;
  409. ec_write(EEEPC_EC_SC02, value);
  410. }
  411. static int eeepc_get_fan_rpm(void)
  412. {
  413. int high = 0;
  414. int low = 0;
  415. read_acpi_int(NULL, EEEPC_EC_FAN_HRPM, &high);
  416. read_acpi_int(NULL, EEEPC_EC_FAN_LRPM, &low);
  417. return (high << 8 | low);
  418. }
  419. static int eeepc_get_fan_ctrl(void)
  420. {
  421. int value = 0;
  422. read_acpi_int(NULL, EEEPC_EC_FAN_CTRL, &value);
  423. return ((value & 0x02 ? 1 : 0));
  424. }
  425. static void eeepc_set_fan_ctrl(int manual)
  426. {
  427. int value = 0;
  428. read_acpi_int(NULL, EEEPC_EC_FAN_CTRL, &value);
  429. if (manual)
  430. value |= 0x02;
  431. else
  432. value &= ~0x02;
  433. ec_write(EEEPC_EC_SFB3, value);
  434. }
  435. static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
  436. {
  437. int rv, value;
  438. rv = parse_arg(buf, count, &value);
  439. if (rv > 0)
  440. set(value);
  441. return rv;
  442. }
  443. static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
  444. {
  445. return sprintf(buf, "%d\n", get());
  446. }
  447. #define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _set, _get) \
  448. static ssize_t show_##_name(struct device *dev, \
  449. struct device_attribute *attr, \
  450. char *buf) \
  451. { \
  452. return show_sys_hwmon(_set, buf); \
  453. } \
  454. static ssize_t store_##_name(struct device *dev, \
  455. struct device_attribute *attr, \
  456. const char *buf, size_t count) \
  457. { \
  458. return store_sys_hwmon(_get, buf, count); \
  459. } \
  460. static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0);
  461. EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL);
  462. EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
  463. eeepc_get_fan_pwm, eeepc_set_fan_pwm);
  464. EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
  465. eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
  466. static ssize_t
  467. show_name(struct device *dev, struct device_attribute *attr, char *buf)
  468. {
  469. return sprintf(buf, "eeepc\n");
  470. }
  471. static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
  472. static struct attribute *hwmon_attributes[] = {
  473. &sensor_dev_attr_pwm1.dev_attr.attr,
  474. &sensor_dev_attr_fan1_input.dev_attr.attr,
  475. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  476. &sensor_dev_attr_name.dev_attr.attr,
  477. NULL
  478. };
  479. static struct attribute_group hwmon_attribute_group = {
  480. .attrs = hwmon_attributes
  481. };
  482. /*
  483. * exit/init
  484. */
  485. static void eeepc_backlight_exit(void)
  486. {
  487. if (eeepc_backlight_device)
  488. backlight_device_unregister(eeepc_backlight_device);
  489. eeepc_backlight_device = NULL;
  490. }
  491. static void eeepc_hwmon_exit(void)
  492. {
  493. struct device *hwmon;
  494. hwmon = eeepc_hwmon_device;
  495. if (!hwmon)
  496. return ;
  497. sysfs_remove_group(&hwmon->kobj,
  498. &hwmon_attribute_group);
  499. hwmon_device_unregister(hwmon);
  500. eeepc_hwmon_device = NULL;
  501. }
  502. static void __exit eeepc_laptop_exit(void)
  503. {
  504. eeepc_backlight_exit();
  505. eeepc_hwmon_exit();
  506. acpi_bus_unregister_driver(&eeepc_hotk_driver);
  507. sysfs_remove_group(&platform_device->dev.kobj,
  508. &platform_attribute_group);
  509. platform_device_unregister(platform_device);
  510. platform_driver_unregister(&platform_driver);
  511. }
  512. static int eeepc_backlight_init(struct device *dev)
  513. {
  514. struct backlight_device *bd;
  515. bd = backlight_device_register(EEEPC_HOTK_FILE, dev,
  516. NULL, &eeepcbl_ops);
  517. if (IS_ERR(bd)) {
  518. printk(EEEPC_ERR
  519. "Could not register eeepc backlight device\n");
  520. eeepc_backlight_device = NULL;
  521. return PTR_ERR(bd);
  522. }
  523. eeepc_backlight_device = bd;
  524. bd->props.max_brightness = 15;
  525. bd->props.brightness = read_brightness(NULL);
  526. bd->props.power = FB_BLANK_UNBLANK;
  527. backlight_update_status(bd);
  528. return 0;
  529. }
  530. static int eeepc_hwmon_init(struct device *dev)
  531. {
  532. struct device *hwmon;
  533. int result;
  534. hwmon = hwmon_device_register(dev);
  535. if (IS_ERR(hwmon)) {
  536. printk(EEEPC_ERR
  537. "Could not register eeepc hwmon device\n");
  538. eeepc_hwmon_device = NULL;
  539. return PTR_ERR(hwmon);
  540. }
  541. eeepc_hwmon_device = hwmon;
  542. result = sysfs_create_group(&hwmon->kobj,
  543. &hwmon_attribute_group);
  544. if (result)
  545. eeepc_hwmon_exit();
  546. return result;
  547. }
  548. static int __init eeepc_laptop_init(void)
  549. {
  550. struct device *dev;
  551. int result;
  552. if (acpi_disabled)
  553. return -ENODEV;
  554. result = acpi_bus_register_driver(&eeepc_hotk_driver);
  555. if (result < 0)
  556. return result;
  557. if (!ehotk) {
  558. acpi_bus_unregister_driver(&eeepc_hotk_driver);
  559. return -ENODEV;
  560. }
  561. dev = acpi_get_physical_device(ehotk->device->handle);
  562. result = eeepc_backlight_init(dev);
  563. if (result)
  564. goto fail_backlight;
  565. result = eeepc_hwmon_init(dev);
  566. if (result)
  567. goto fail_hwmon;
  568. /* Register platform stuff */
  569. result = platform_driver_register(&platform_driver);
  570. if (result)
  571. goto fail_platform_driver;
  572. platform_device = platform_device_alloc(EEEPC_HOTK_FILE, -1);
  573. if (!platform_device) {
  574. result = -ENOMEM;
  575. goto fail_platform_device1;
  576. }
  577. result = platform_device_add(platform_device);
  578. if (result)
  579. goto fail_platform_device2;
  580. result = sysfs_create_group(&platform_device->dev.kobj,
  581. &platform_attribute_group);
  582. if (result)
  583. goto fail_sysfs;
  584. return 0;
  585. fail_sysfs:
  586. platform_device_del(platform_device);
  587. fail_platform_device2:
  588. platform_device_put(platform_device);
  589. fail_platform_device1:
  590. platform_driver_unregister(&platform_driver);
  591. fail_platform_driver:
  592. eeepc_hwmon_exit();
  593. fail_hwmon:
  594. eeepc_backlight_exit();
  595. fail_backlight:
  596. return result;
  597. }
  598. module_init(eeepc_laptop_init);
  599. module_exit(eeepc_laptop_exit);