PageRenderTime 63ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/platform/x86/asus-laptop.c

http://github.com/mirrors/linux
C | 1978 lines | 1447 code | 310 blank | 221 comment | 228 complexity | ab6c2b627ee3f30f5bfef47a59ec539f MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * asus-laptop.c - Asus Laptop Support
  4. *
  5. * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
  6. * Copyright (C) 2006-2007 Corentin Chary
  7. * Copyright (C) 2011 Wind River Systems
  8. *
  9. * The development page for this driver is located at
  10. * http://sourceforge.net/projects/acpi4asus/
  11. *
  12. * Credits:
  13. * Pontus Fuchs - Helper functions, cleanup
  14. * Johann Wiesner - Small compile fixes
  15. * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
  16. * Eric Burghard - LED display support for W1N
  17. * Josh Green - Light Sens support
  18. * Thomas Tuttle - His first patch for led support was very helpful
  19. * Sam Lin - GPS support
  20. */
  21. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/types.h>
  26. #include <linux/err.h>
  27. #include <linux/proc_fs.h>
  28. #include <linux/backlight.h>
  29. #include <linux/fb.h>
  30. #include <linux/leds.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/uaccess.h>
  33. #include <linux/input.h>
  34. #include <linux/input/sparse-keymap.h>
  35. #include <linux/rfkill.h>
  36. #include <linux/slab.h>
  37. #include <linux/dmi.h>
  38. #include <linux/acpi.h>
  39. #include <acpi/video.h>
  40. #define ASUS_LAPTOP_VERSION "0.42"
  41. #define ASUS_LAPTOP_NAME "Asus Laptop Support"
  42. #define ASUS_LAPTOP_CLASS "hotkey"
  43. #define ASUS_LAPTOP_DEVICE_NAME "Hotkey"
  44. #define ASUS_LAPTOP_FILE KBUILD_MODNAME
  45. #define ASUS_LAPTOP_PREFIX "\\_SB.ATKD."
  46. MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
  47. MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
  48. MODULE_LICENSE("GPL");
  49. /*
  50. * WAPF defines the behavior of the Fn+Fx wlan key
  51. * The significance of values is yet to be found, but
  52. * most of the time:
  53. * Bit | Bluetooth | WLAN
  54. * 0 | Hardware | Hardware
  55. * 1 | Hardware | Software
  56. * 4 | Software | Software
  57. */
  58. static uint wapf = 1;
  59. module_param(wapf, uint, 0444);
  60. MODULE_PARM_DESC(wapf, "WAPF value");
  61. static char *wled_type = "unknown";
  62. static char *bled_type = "unknown";
  63. module_param(wled_type, charp, 0444);
  64. MODULE_PARM_DESC(wled_type, "Set the wled type on boot "
  65. "(unknown, led or rfkill). "
  66. "default is unknown");
  67. module_param(bled_type, charp, 0444);
  68. MODULE_PARM_DESC(bled_type, "Set the bled type on boot "
  69. "(unknown, led or rfkill). "
  70. "default is unknown");
  71. static int wlan_status = 1;
  72. static int bluetooth_status = 1;
  73. static int wimax_status = -1;
  74. static int wwan_status = -1;
  75. static int als_status;
  76. module_param(wlan_status, int, 0444);
  77. MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
  78. "(0 = disabled, 1 = enabled, -1 = don't do anything). "
  79. "default is -1");
  80. module_param(bluetooth_status, int, 0444);
  81. MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
  82. "(0 = disabled, 1 = enabled, -1 = don't do anything). "
  83. "default is -1");
  84. module_param(wimax_status, int, 0444);
  85. MODULE_PARM_DESC(wimax_status, "Set the wireless status on boot "
  86. "(0 = disabled, 1 = enabled, -1 = don't do anything). "
  87. "default is -1");
  88. module_param(wwan_status, int, 0444);
  89. MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot "
  90. "(0 = disabled, 1 = enabled, -1 = don't do anything). "
  91. "default is -1");
  92. module_param(als_status, int, 0444);
  93. MODULE_PARM_DESC(als_status, "Set the ALS status on boot "
  94. "(0 = disabled, 1 = enabled). "
  95. "default is 0");
  96. /*
  97. * Some events we use, same for all Asus
  98. */
  99. #define ATKD_BRNUP_MIN 0x10
  100. #define ATKD_BRNUP_MAX 0x1f
  101. #define ATKD_BRNDOWN_MIN 0x20
  102. #define ATKD_BRNDOWN_MAX 0x2f
  103. #define ATKD_BRNDOWN 0x20
  104. #define ATKD_BRNUP 0x2f
  105. #define ATKD_LCD_ON 0x33
  106. #define ATKD_LCD_OFF 0x34
  107. /*
  108. * Known bits returned by \_SB.ATKD.HWRS
  109. */
  110. #define WL_HWRS 0x80
  111. #define BT_HWRS 0x100
  112. /*
  113. * Flags for hotk status
  114. * WL_ON and BT_ON are also used for wireless_status()
  115. */
  116. #define WL_RSTS 0x01 /* internal Wifi */
  117. #define BT_RSTS 0x02 /* internal Bluetooth */
  118. #define WM_RSTS 0x08 /* internal wimax */
  119. #define WW_RSTS 0x20 /* internal wwan */
  120. /* WLED and BLED type */
  121. #define TYPE_UNKNOWN 0
  122. #define TYPE_LED 1
  123. #define TYPE_RFKILL 2
  124. /* LED */
  125. #define METHOD_MLED "MLED"
  126. #define METHOD_TLED "TLED"
  127. #define METHOD_RLED "RLED" /* W1JC */
  128. #define METHOD_PLED "PLED" /* A7J */
  129. #define METHOD_GLED "GLED" /* G1, G2 (probably) */
  130. /* LEDD */
  131. #define METHOD_LEDD "SLCM"
  132. /*
  133. * Bluetooth and WLAN
  134. * WLED and BLED are not handled like other XLED, because in some dsdt
  135. * they also control the WLAN/Bluetooth device.
  136. */
  137. #define METHOD_WLAN "WLED"
  138. #define METHOD_BLUETOOTH "BLED"
  139. /* WWAN and WIMAX */
  140. #define METHOD_WWAN "GSMC"
  141. #define METHOD_WIMAX "WMXC"
  142. #define METHOD_WL_STATUS "RSTS"
  143. /* Brightness */
  144. #define METHOD_BRIGHTNESS_SET "SPLV"
  145. #define METHOD_BRIGHTNESS_GET "GPLV"
  146. /* Display */
  147. #define METHOD_SWITCH_DISPLAY "SDSP"
  148. #define METHOD_ALS_CONTROL "ALSC" /* Z71A Z71V */
  149. #define METHOD_ALS_LEVEL "ALSL" /* Z71A Z71V */
  150. /* GPS */
  151. /* R2H use different handle for GPS on/off */
  152. #define METHOD_GPS_ON "SDON"
  153. #define METHOD_GPS_OFF "SDOF"
  154. #define METHOD_GPS_STATUS "GPST"
  155. /* Keyboard light */
  156. #define METHOD_KBD_LIGHT_SET "SLKB"
  157. #define METHOD_KBD_LIGHT_GET "GLKB"
  158. /* For Pegatron Lucid tablet */
  159. #define DEVICE_NAME_PEGA "Lucid"
  160. #define METHOD_PEGA_ENABLE "ENPR"
  161. #define METHOD_PEGA_DISABLE "DAPR"
  162. #define PEGA_WLAN 0x00
  163. #define PEGA_BLUETOOTH 0x01
  164. #define PEGA_WWAN 0x02
  165. #define PEGA_ALS 0x04
  166. #define PEGA_ALS_POWER 0x05
  167. #define METHOD_PEGA_READ "RDLN"
  168. #define PEGA_READ_ALS_H 0x02
  169. #define PEGA_READ_ALS_L 0x03
  170. #define PEGA_ACCEL_NAME "pega_accel"
  171. #define PEGA_ACCEL_DESC "Pegatron Lucid Tablet Accelerometer"
  172. #define METHOD_XLRX "XLRX"
  173. #define METHOD_XLRY "XLRY"
  174. #define METHOD_XLRZ "XLRZ"
  175. #define PEGA_ACC_CLAMP 512 /* 1G accel is reported as ~256, so clamp to 2G */
  176. #define PEGA_ACC_RETRIES 3
  177. /*
  178. * Define a specific led structure to keep the main structure clean
  179. */
  180. struct asus_led {
  181. int wk;
  182. struct work_struct work;
  183. struct led_classdev led;
  184. struct asus_laptop *asus;
  185. const char *method;
  186. };
  187. /*
  188. * Same thing for rfkill
  189. */
  190. struct asus_rfkill {
  191. /* type of control. Maps to PEGA_* values or *_RSTS */
  192. int control_id;
  193. struct rfkill *rfkill;
  194. struct asus_laptop *asus;
  195. };
  196. /*
  197. * This is the main structure, we can use it to store anything interesting
  198. * about the hotk device
  199. */
  200. struct asus_laptop {
  201. char *name; /* laptop name */
  202. struct acpi_table_header *dsdt_info;
  203. struct platform_device *platform_device;
  204. struct acpi_device *device; /* the device we are in */
  205. struct backlight_device *backlight_device;
  206. struct input_dev *inputdev;
  207. struct key_entry *keymap;
  208. struct input_dev *pega_accel_poll;
  209. struct asus_led wled;
  210. struct asus_led bled;
  211. struct asus_led mled;
  212. struct asus_led tled;
  213. struct asus_led rled;
  214. struct asus_led pled;
  215. struct asus_led gled;
  216. struct asus_led kled;
  217. struct workqueue_struct *led_workqueue;
  218. int wled_type;
  219. int bled_type;
  220. int wireless_status;
  221. bool have_rsts;
  222. bool is_pega_lucid;
  223. bool pega_acc_live;
  224. int pega_acc_x;
  225. int pega_acc_y;
  226. int pega_acc_z;
  227. struct asus_rfkill wlan;
  228. struct asus_rfkill bluetooth;
  229. struct asus_rfkill wwan;
  230. struct asus_rfkill wimax;
  231. struct asus_rfkill gps;
  232. acpi_handle handle; /* the handle of the hotk device */
  233. u32 ledd_status; /* status of the LED display */
  234. u8 light_level; /* light sensor level */
  235. u8 light_switch; /* light sensor switch value */
  236. u16 event_count[128]; /* count for each event TODO make this better */
  237. };
  238. static const struct key_entry asus_keymap[] = {
  239. /* Lenovo SL Specific keycodes */
  240. {KE_KEY, 0x02, { KEY_SCREENLOCK } },
  241. {KE_KEY, 0x05, { KEY_WLAN } },
  242. {KE_KEY, 0x08, { KEY_F13 } },
  243. {KE_KEY, 0x09, { KEY_PROG2 } }, /* Dock */
  244. {KE_KEY, 0x17, { KEY_ZOOM } },
  245. {KE_KEY, 0x1f, { KEY_BATTERY } },
  246. /* End of Lenovo SL Specific keycodes */
  247. {KE_KEY, ATKD_BRNDOWN, { KEY_BRIGHTNESSDOWN } },
  248. {KE_KEY, ATKD_BRNUP, { KEY_BRIGHTNESSUP } },
  249. {KE_KEY, 0x30, { KEY_VOLUMEUP } },
  250. {KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
  251. {KE_KEY, 0x32, { KEY_MUTE } },
  252. {KE_KEY, 0x33, { KEY_DISPLAYTOGGLE } }, /* LCD on */
  253. {KE_KEY, 0x34, { KEY_DISPLAY_OFF } }, /* LCD off */
  254. {KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
  255. {KE_KEY, 0x41, { KEY_NEXTSONG } },
  256. {KE_KEY, 0x43, { KEY_STOPCD } }, /* Stop/Eject */
  257. {KE_KEY, 0x45, { KEY_PLAYPAUSE } },
  258. {KE_KEY, 0x4c, { KEY_MEDIA } }, /* WMP Key */
  259. {KE_KEY, 0x50, { KEY_EMAIL } },
  260. {KE_KEY, 0x51, { KEY_WWW } },
  261. {KE_KEY, 0x55, { KEY_CALC } },
  262. {KE_IGNORE, 0x57, }, /* Battery mode */
  263. {KE_IGNORE, 0x58, }, /* AC mode */
  264. {KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */
  265. {KE_KEY, 0x5D, { KEY_WLAN } }, /* WLAN Toggle */
  266. {KE_KEY, 0x5E, { KEY_WLAN } }, /* WLAN Enable */
  267. {KE_KEY, 0x5F, { KEY_WLAN } }, /* WLAN Disable */
  268. {KE_KEY, 0x60, { KEY_TOUCHPAD_ON } },
  269. {KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD only */
  270. {KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } }, /* SDSP CRT only */
  271. {KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + CRT */
  272. {KE_KEY, 0x64, { KEY_SWITCHVIDEOMODE } }, /* SDSP TV */
  273. {KE_KEY, 0x65, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + TV */
  274. {KE_KEY, 0x66, { KEY_SWITCHVIDEOMODE } }, /* SDSP CRT + TV */
  275. {KE_KEY, 0x67, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + CRT + TV */
  276. {KE_KEY, 0x6A, { KEY_TOUCHPAD_TOGGLE } }, /* Lock Touchpad Fn + F9 */
  277. {KE_KEY, 0x6B, { KEY_TOUCHPAD_TOGGLE } }, /* Lock Touchpad */
  278. {KE_KEY, 0x6C, { KEY_SLEEP } }, /* Suspend */
  279. {KE_KEY, 0x6D, { KEY_SLEEP } }, /* Hibernate */
  280. {KE_IGNORE, 0x6E, }, /* Low Battery notification */
  281. {KE_KEY, 0x7D, { KEY_BLUETOOTH } }, /* Bluetooth Enable */
  282. {KE_KEY, 0x7E, { KEY_BLUETOOTH } }, /* Bluetooth Disable */
  283. {KE_KEY, 0x82, { KEY_CAMERA } },
  284. {KE_KEY, 0x88, { KEY_RFKILL } }, /* Radio Toggle Key */
  285. {KE_KEY, 0x8A, { KEY_PROG1 } }, /* Color enhancement mode */
  286. {KE_KEY, 0x8C, { KEY_SWITCHVIDEOMODE } }, /* SDSP DVI only */
  287. {KE_KEY, 0x8D, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + DVI */
  288. {KE_KEY, 0x8E, { KEY_SWITCHVIDEOMODE } }, /* SDSP CRT + DVI */
  289. {KE_KEY, 0x8F, { KEY_SWITCHVIDEOMODE } }, /* SDSP TV + DVI */
  290. {KE_KEY, 0x90, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + CRT + DVI */
  291. {KE_KEY, 0x91, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + TV + DVI */
  292. {KE_KEY, 0x92, { KEY_SWITCHVIDEOMODE } }, /* SDSP CRT + TV + DVI */
  293. {KE_KEY, 0x93, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + CRT + TV + DVI */
  294. {KE_KEY, 0x95, { KEY_MEDIA } },
  295. {KE_KEY, 0x99, { KEY_PHONE } },
  296. {KE_KEY, 0xA0, { KEY_SWITCHVIDEOMODE } }, /* SDSP HDMI only */
  297. {KE_KEY, 0xA1, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + HDMI */
  298. {KE_KEY, 0xA2, { KEY_SWITCHVIDEOMODE } }, /* SDSP CRT + HDMI */
  299. {KE_KEY, 0xA3, { KEY_SWITCHVIDEOMODE } }, /* SDSP TV + HDMI */
  300. {KE_KEY, 0xA4, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + CRT + HDMI */
  301. {KE_KEY, 0xA5, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + TV + HDMI */
  302. {KE_KEY, 0xA6, { KEY_SWITCHVIDEOMODE } }, /* SDSP CRT + TV + HDMI */
  303. {KE_KEY, 0xA7, { KEY_SWITCHVIDEOMODE } }, /* SDSP LCD + CRT + TV + HDMI */
  304. {KE_KEY, 0xB5, { KEY_CALC } },
  305. {KE_KEY, 0xC4, { KEY_KBDILLUMUP } },
  306. {KE_KEY, 0xC5, { KEY_KBDILLUMDOWN } },
  307. {KE_END, 0},
  308. };
  309. /*
  310. * This function evaluates an ACPI method, given an int as parameter, the
  311. * method is searched within the scope of the handle, can be NULL. The output
  312. * of the method is written is output, which can also be NULL
  313. *
  314. * returns 0 if write is successful, -1 else.
  315. */
  316. static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
  317. struct acpi_buffer *output)
  318. {
  319. struct acpi_object_list params; /* list of input parameters (an int) */
  320. union acpi_object in_obj; /* the only param we use */
  321. acpi_status status;
  322. if (!handle)
  323. return -1;
  324. params.count = 1;
  325. params.pointer = &in_obj;
  326. in_obj.type = ACPI_TYPE_INTEGER;
  327. in_obj.integer.value = val;
  328. status = acpi_evaluate_object(handle, (char *)method, &params, output);
  329. if (status == AE_OK)
  330. return 0;
  331. else
  332. return -1;
  333. }
  334. static int write_acpi_int(acpi_handle handle, const char *method, int val)
  335. {
  336. return write_acpi_int_ret(handle, method, val, NULL);
  337. }
  338. static int acpi_check_handle(acpi_handle handle, const char *method,
  339. acpi_handle *ret)
  340. {
  341. acpi_status status;
  342. if (method == NULL)
  343. return -ENODEV;
  344. if (ret)
  345. status = acpi_get_handle(handle, (char *)method,
  346. ret);
  347. else {
  348. acpi_handle dummy;
  349. status = acpi_get_handle(handle, (char *)method,
  350. &dummy);
  351. }
  352. if (status != AE_OK) {
  353. if (ret)
  354. pr_warn("Error finding %s\n", method);
  355. return -ENODEV;
  356. }
  357. return 0;
  358. }
  359. static bool asus_check_pega_lucid(struct asus_laptop *asus)
  360. {
  361. return !strcmp(asus->name, DEVICE_NAME_PEGA) &&
  362. !acpi_check_handle(asus->handle, METHOD_PEGA_ENABLE, NULL) &&
  363. !acpi_check_handle(asus->handle, METHOD_PEGA_DISABLE, NULL) &&
  364. !acpi_check_handle(asus->handle, METHOD_PEGA_READ, NULL);
  365. }
  366. static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable)
  367. {
  368. char *method = enable ? METHOD_PEGA_ENABLE : METHOD_PEGA_DISABLE;
  369. return write_acpi_int(asus->handle, method, unit);
  370. }
  371. static int pega_acc_axis(struct asus_laptop *asus, int curr, char *method)
  372. {
  373. int i, delta;
  374. unsigned long long val;
  375. for (i = 0; i < PEGA_ACC_RETRIES; i++) {
  376. acpi_evaluate_integer(asus->handle, method, NULL, &val);
  377. /* The output is noisy. From reading the ASL
  378. * dissassembly, timeout errors are returned with 1's
  379. * in the high word, and the lack of locking around
  380. * thei hi/lo byte reads means that a transition
  381. * between (for example) -1 and 0 could be read as
  382. * 0xff00 or 0x00ff. */
  383. delta = abs(curr - (short)val);
  384. if (delta < 128 && !(val & ~0xffff))
  385. break;
  386. }
  387. return clamp_val((short)val, -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP);
  388. }
  389. static void pega_accel_poll(struct input_dev *input)
  390. {
  391. struct device *parent = input->dev.parent;
  392. struct asus_laptop *asus = dev_get_drvdata(parent);
  393. /* In some cases, the very first call to poll causes a
  394. * recursive fault under the polldev worker. This is
  395. * apparently related to very early userspace access to the
  396. * device, and perhaps a firmware bug. Fake the first report. */
  397. if (!asus->pega_acc_live) {
  398. asus->pega_acc_live = true;
  399. input_report_abs(input, ABS_X, 0);
  400. input_report_abs(input, ABS_Y, 0);
  401. input_report_abs(input, ABS_Z, 0);
  402. input_sync(input);
  403. return;
  404. }
  405. asus->pega_acc_x = pega_acc_axis(asus, asus->pega_acc_x, METHOD_XLRX);
  406. asus->pega_acc_y = pega_acc_axis(asus, asus->pega_acc_y, METHOD_XLRY);
  407. asus->pega_acc_z = pega_acc_axis(asus, asus->pega_acc_z, METHOD_XLRZ);
  408. /* Note transform, convert to "right/up/out" in the native
  409. * landscape orientation (i.e. the vector is the direction of
  410. * "real up" in the device's cartiesian coordinates). */
  411. input_report_abs(input, ABS_X, -asus->pega_acc_x);
  412. input_report_abs(input, ABS_Y, -asus->pega_acc_y);
  413. input_report_abs(input, ABS_Z, asus->pega_acc_z);
  414. input_sync(input);
  415. }
  416. static void pega_accel_exit(struct asus_laptop *asus)
  417. {
  418. if (asus->pega_accel_poll) {
  419. input_unregister_device(asus->pega_accel_poll);
  420. asus->pega_accel_poll = NULL;
  421. }
  422. }
  423. static int pega_accel_init(struct asus_laptop *asus)
  424. {
  425. int err;
  426. struct input_dev *input;
  427. if (!asus->is_pega_lucid)
  428. return -ENODEV;
  429. if (acpi_check_handle(asus->handle, METHOD_XLRX, NULL) ||
  430. acpi_check_handle(asus->handle, METHOD_XLRY, NULL) ||
  431. acpi_check_handle(asus->handle, METHOD_XLRZ, NULL))
  432. return -ENODEV;
  433. input = input_allocate_device();
  434. if (!input)
  435. return -ENOMEM;
  436. input->name = PEGA_ACCEL_DESC;
  437. input->phys = PEGA_ACCEL_NAME "/input0";
  438. input->dev.parent = &asus->platform_device->dev;
  439. input->id.bustype = BUS_HOST;
  440. input_set_abs_params(input, ABS_X,
  441. -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
  442. input_set_abs_params(input, ABS_Y,
  443. -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
  444. input_set_abs_params(input, ABS_Z,
  445. -PEGA_ACC_CLAMP, PEGA_ACC_CLAMP, 0, 0);
  446. err = input_setup_polling(input, pega_accel_poll);
  447. if (err)
  448. goto exit;
  449. input_set_poll_interval(input, 125);
  450. input_set_min_poll_interval(input, 50);
  451. input_set_max_poll_interval(input, 2000);
  452. err = input_register_device(input);
  453. if (err)
  454. goto exit;
  455. asus->pega_accel_poll = input;
  456. return 0;
  457. exit:
  458. input_free_device(input);
  459. return err;
  460. }
  461. /* Generic LED function */
  462. static int asus_led_set(struct asus_laptop *asus, const char *method,
  463. int value)
  464. {
  465. if (!strcmp(method, METHOD_MLED))
  466. value = !value;
  467. else if (!strcmp(method, METHOD_GLED))
  468. value = !value + 1;
  469. else
  470. value = !!value;
  471. return write_acpi_int(asus->handle, method, value);
  472. }
  473. /*
  474. * LEDs
  475. */
  476. /* /sys/class/led handlers */
  477. static void asus_led_cdev_set(struct led_classdev *led_cdev,
  478. enum led_brightness value)
  479. {
  480. struct asus_led *led = container_of(led_cdev, struct asus_led, led);
  481. struct asus_laptop *asus = led->asus;
  482. led->wk = !!value;
  483. queue_work(asus->led_workqueue, &led->work);
  484. }
  485. static void asus_led_cdev_update(struct work_struct *work)
  486. {
  487. struct asus_led *led = container_of(work, struct asus_led, work);
  488. struct asus_laptop *asus = led->asus;
  489. asus_led_set(asus, led->method, led->wk);
  490. }
  491. static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
  492. {
  493. return led_cdev->brightness;
  494. }
  495. /*
  496. * Keyboard backlight (also a LED)
  497. */
  498. static int asus_kled_lvl(struct asus_laptop *asus)
  499. {
  500. unsigned long long kblv;
  501. struct acpi_object_list params;
  502. union acpi_object in_obj;
  503. acpi_status rv;
  504. params.count = 1;
  505. params.pointer = &in_obj;
  506. in_obj.type = ACPI_TYPE_INTEGER;
  507. in_obj.integer.value = 2;
  508. rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
  509. &params, &kblv);
  510. if (ACPI_FAILURE(rv)) {
  511. pr_warn("Error reading kled level\n");
  512. return -ENODEV;
  513. }
  514. return kblv;
  515. }
  516. static int asus_kled_set(struct asus_laptop *asus, int kblv)
  517. {
  518. if (kblv > 0)
  519. kblv = (1 << 7) | (kblv & 0x7F);
  520. else
  521. kblv = 0;
  522. if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
  523. pr_warn("Keyboard LED display write failed\n");
  524. return -EINVAL;
  525. }
  526. return 0;
  527. }
  528. static void asus_kled_cdev_set(struct led_classdev *led_cdev,
  529. enum led_brightness value)
  530. {
  531. struct asus_led *led = container_of(led_cdev, struct asus_led, led);
  532. struct asus_laptop *asus = led->asus;
  533. led->wk = value;
  534. queue_work(asus->led_workqueue, &led->work);
  535. }
  536. static void asus_kled_cdev_update(struct work_struct *work)
  537. {
  538. struct asus_led *led = container_of(work, struct asus_led, work);
  539. struct asus_laptop *asus = led->asus;
  540. asus_kled_set(asus, led->wk);
  541. }
  542. static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
  543. {
  544. struct asus_led *led = container_of(led_cdev, struct asus_led, led);
  545. struct asus_laptop *asus = led->asus;
  546. return asus_kled_lvl(asus);
  547. }
  548. static void asus_led_exit(struct asus_laptop *asus)
  549. {
  550. if (!IS_ERR_OR_NULL(asus->wled.led.dev))
  551. led_classdev_unregister(&asus->wled.led);
  552. if (!IS_ERR_OR_NULL(asus->bled.led.dev))
  553. led_classdev_unregister(&asus->bled.led);
  554. if (!IS_ERR_OR_NULL(asus->mled.led.dev))
  555. led_classdev_unregister(&asus->mled.led);
  556. if (!IS_ERR_OR_NULL(asus->tled.led.dev))
  557. led_classdev_unregister(&asus->tled.led);
  558. if (!IS_ERR_OR_NULL(asus->pled.led.dev))
  559. led_classdev_unregister(&asus->pled.led);
  560. if (!IS_ERR_OR_NULL(asus->rled.led.dev))
  561. led_classdev_unregister(&asus->rled.led);
  562. if (!IS_ERR_OR_NULL(asus->gled.led.dev))
  563. led_classdev_unregister(&asus->gled.led);
  564. if (!IS_ERR_OR_NULL(asus->kled.led.dev))
  565. led_classdev_unregister(&asus->kled.led);
  566. if (asus->led_workqueue) {
  567. destroy_workqueue(asus->led_workqueue);
  568. asus->led_workqueue = NULL;
  569. }
  570. }
  571. /* Ugly macro, need to fix that later */
  572. static int asus_led_register(struct asus_laptop *asus,
  573. struct asus_led *led,
  574. const char *name, const char *method)
  575. {
  576. struct led_classdev *led_cdev = &led->led;
  577. if (!method || acpi_check_handle(asus->handle, method, NULL))
  578. return 0; /* Led not present */
  579. led->asus = asus;
  580. led->method = method;
  581. INIT_WORK(&led->work, asus_led_cdev_update);
  582. led_cdev->name = name;
  583. led_cdev->brightness_set = asus_led_cdev_set;
  584. led_cdev->brightness_get = asus_led_cdev_get;
  585. led_cdev->max_brightness = 1;
  586. return led_classdev_register(&asus->platform_device->dev, led_cdev);
  587. }
  588. static int asus_led_init(struct asus_laptop *asus)
  589. {
  590. int r = 0;
  591. /*
  592. * The Pegatron Lucid has no physical leds, but all methods are
  593. * available in the DSDT...
  594. */
  595. if (asus->is_pega_lucid)
  596. return 0;
  597. /*
  598. * Functions that actually update the LED's are called from a
  599. * workqueue. By doing this as separate work rather than when the LED
  600. * subsystem asks, we avoid messing with the Asus ACPI stuff during a
  601. * potentially bad time, such as a timer interrupt.
  602. */
  603. asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
  604. if (!asus->led_workqueue)
  605. return -ENOMEM;
  606. if (asus->wled_type == TYPE_LED)
  607. r = asus_led_register(asus, &asus->wled, "asus::wlan",
  608. METHOD_WLAN);
  609. if (r)
  610. goto error;
  611. if (asus->bled_type == TYPE_LED)
  612. r = asus_led_register(asus, &asus->bled, "asus::bluetooth",
  613. METHOD_BLUETOOTH);
  614. if (r)
  615. goto error;
  616. r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
  617. if (r)
  618. goto error;
  619. r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
  620. if (r)
  621. goto error;
  622. r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
  623. if (r)
  624. goto error;
  625. r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
  626. if (r)
  627. goto error;
  628. r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
  629. if (r)
  630. goto error;
  631. if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
  632. !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
  633. struct asus_led *led = &asus->kled;
  634. struct led_classdev *cdev = &led->led;
  635. led->asus = asus;
  636. INIT_WORK(&led->work, asus_kled_cdev_update);
  637. cdev->name = "asus::kbd_backlight";
  638. cdev->brightness_set = asus_kled_cdev_set;
  639. cdev->brightness_get = asus_kled_cdev_get;
  640. cdev->max_brightness = 3;
  641. r = led_classdev_register(&asus->platform_device->dev, cdev);
  642. }
  643. error:
  644. if (r)
  645. asus_led_exit(asus);
  646. return r;
  647. }
  648. /*
  649. * Backlight device
  650. */
  651. static int asus_read_brightness(struct backlight_device *bd)
  652. {
  653. struct asus_laptop *asus = bl_get_data(bd);
  654. unsigned long long value;
  655. acpi_status rv;
  656. rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
  657. NULL, &value);
  658. if (ACPI_FAILURE(rv)) {
  659. pr_warn("Error reading brightness\n");
  660. return 0;
  661. }
  662. return value;
  663. }
  664. static int asus_set_brightness(struct backlight_device *bd, int value)
  665. {
  666. struct asus_laptop *asus = bl_get_data(bd);
  667. if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
  668. pr_warn("Error changing brightness\n");
  669. return -EIO;
  670. }
  671. return 0;
  672. }
  673. static int update_bl_status(struct backlight_device *bd)
  674. {
  675. int value = bd->props.brightness;
  676. return asus_set_brightness(bd, value);
  677. }
  678. static const struct backlight_ops asusbl_ops = {
  679. .get_brightness = asus_read_brightness,
  680. .update_status = update_bl_status,
  681. };
  682. static int asus_backlight_notify(struct asus_laptop *asus)
  683. {
  684. struct backlight_device *bd = asus->backlight_device;
  685. int old = bd->props.brightness;
  686. backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
  687. return old;
  688. }
  689. static int asus_backlight_init(struct asus_laptop *asus)
  690. {
  691. struct backlight_device *bd;
  692. struct backlight_properties props;
  693. if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) ||
  694. acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL))
  695. return 0;
  696. memset(&props, 0, sizeof(struct backlight_properties));
  697. props.max_brightness = 15;
  698. props.type = BACKLIGHT_PLATFORM;
  699. bd = backlight_device_register(ASUS_LAPTOP_FILE,
  700. &asus->platform_device->dev, asus,
  701. &asusbl_ops, &props);
  702. if (IS_ERR(bd)) {
  703. pr_err("Could not register asus backlight device\n");
  704. asus->backlight_device = NULL;
  705. return PTR_ERR(bd);
  706. }
  707. asus->backlight_device = bd;
  708. bd->props.brightness = asus_read_brightness(bd);
  709. bd->props.power = FB_BLANK_UNBLANK;
  710. backlight_update_status(bd);
  711. return 0;
  712. }
  713. static void asus_backlight_exit(struct asus_laptop *asus)
  714. {
  715. backlight_device_unregister(asus->backlight_device);
  716. asus->backlight_device = NULL;
  717. }
  718. /*
  719. * Platform device handlers
  720. */
  721. /*
  722. * We write our info in page, we begin at offset off and cannot write more
  723. * than count bytes. We set eof to 1 if we handle those 2 values. We return the
  724. * number of bytes written in page
  725. */
  726. static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
  727. char *page)
  728. {
  729. struct asus_laptop *asus = dev_get_drvdata(dev);
  730. int len = 0;
  731. unsigned long long temp;
  732. char buf[16]; /* enough for all info */
  733. acpi_status rv;
  734. /*
  735. * We use the easy way, we don't care of off and count,
  736. * so we don't set eof to 1
  737. */
  738. len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
  739. len += sprintf(page + len, "Model reference : %s\n", asus->name);
  740. /*
  741. * The SFUN method probably allows the original driver to get the list
  742. * of features supported by a given model. For now, 0x0100 or 0x0800
  743. * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
  744. * The significance of others is yet to be found.
  745. */
  746. rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
  747. if (!ACPI_FAILURE(rv))
  748. len += sprintf(page + len, "SFUN value : %#x\n",
  749. (uint) temp);
  750. /*
  751. * The HWRS method return informations about the hardware.
  752. * 0x80 bit is for WLAN, 0x100 for Bluetooth.
  753. * 0x40 for WWAN, 0x10 for WIMAX.
  754. * The significance of others is yet to be found.
  755. * We don't currently use this for device detection, and it
  756. * takes several seconds to run on some systems.
  757. */
  758. rv = acpi_evaluate_integer(asus->handle, "HWRS", NULL, &temp);
  759. if (!ACPI_FAILURE(rv))
  760. len += sprintf(page + len, "HWRS value : %#x\n",
  761. (uint) temp);
  762. /*
  763. * Another value for userspace: the ASYM method returns 0x02 for
  764. * battery low and 0x04 for battery critical, its readings tend to be
  765. * more accurate than those provided by _BST.
  766. * Note: since not all the laptops provide this method, errors are
  767. * silently ignored.
  768. */
  769. rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
  770. if (!ACPI_FAILURE(rv))
  771. len += sprintf(page + len, "ASYM value : %#x\n",
  772. (uint) temp);
  773. if (asus->dsdt_info) {
  774. snprintf(buf, 16, "%d", asus->dsdt_info->length);
  775. len += sprintf(page + len, "DSDT length : %s\n", buf);
  776. snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
  777. len += sprintf(page + len, "DSDT checksum : %s\n", buf);
  778. snprintf(buf, 16, "%d", asus->dsdt_info->revision);
  779. len += sprintf(page + len, "DSDT revision : %s\n", buf);
  780. snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
  781. len += sprintf(page + len, "OEM id : %s\n", buf);
  782. snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
  783. len += sprintf(page + len, "OEM table id : %s\n", buf);
  784. snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
  785. len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
  786. snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
  787. len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
  788. snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
  789. len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
  790. }
  791. return len;
  792. }
  793. static DEVICE_ATTR_RO(infos);
  794. static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
  795. const char *buf, size_t count,
  796. const char *method)
  797. {
  798. int rv, value;
  799. rv = kstrtoint(buf, 0, &value);
  800. if (rv < 0)
  801. return rv;
  802. if (write_acpi_int(asus->handle, method, value))
  803. return -ENODEV;
  804. return count;
  805. }
  806. /*
  807. * LEDD display
  808. */
  809. static ssize_t ledd_show(struct device *dev, struct device_attribute *attr,
  810. char *buf)
  811. {
  812. struct asus_laptop *asus = dev_get_drvdata(dev);
  813. return sprintf(buf, "0x%08x\n", asus->ledd_status);
  814. }
  815. static ssize_t ledd_store(struct device *dev, struct device_attribute *attr,
  816. const char *buf, size_t count)
  817. {
  818. struct asus_laptop *asus = dev_get_drvdata(dev);
  819. int rv, value;
  820. rv = kstrtoint(buf, 0, &value);
  821. if (rv < 0)
  822. return rv;
  823. if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
  824. pr_warn("LED display write failed\n");
  825. return -ENODEV;
  826. }
  827. asus->ledd_status = (u32) value;
  828. return count;
  829. }
  830. static DEVICE_ATTR_RW(ledd);
  831. /*
  832. * Wireless
  833. */
  834. static int asus_wireless_status(struct asus_laptop *asus, int mask)
  835. {
  836. unsigned long long status;
  837. acpi_status rv = AE_OK;
  838. if (!asus->have_rsts)
  839. return (asus->wireless_status & mask) ? 1 : 0;
  840. rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
  841. NULL, &status);
  842. if (ACPI_FAILURE(rv)) {
  843. pr_warn("Error reading Wireless status\n");
  844. return -EINVAL;
  845. }
  846. return !!(status & mask);
  847. }
  848. /*
  849. * WLAN
  850. */
  851. static int asus_wlan_set(struct asus_laptop *asus, int status)
  852. {
  853. if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
  854. pr_warn("Error setting wlan status to %d\n", status);
  855. return -EIO;
  856. }
  857. return 0;
  858. }
  859. static ssize_t wlan_show(struct device *dev, struct device_attribute *attr,
  860. char *buf)
  861. {
  862. struct asus_laptop *asus = dev_get_drvdata(dev);
  863. return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
  864. }
  865. static ssize_t wlan_store(struct device *dev, struct device_attribute *attr,
  866. const char *buf, size_t count)
  867. {
  868. struct asus_laptop *asus = dev_get_drvdata(dev);
  869. return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
  870. }
  871. static DEVICE_ATTR_RW(wlan);
  872. /*e
  873. * Bluetooth
  874. */
  875. static int asus_bluetooth_set(struct asus_laptop *asus, int status)
  876. {
  877. if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
  878. pr_warn("Error setting bluetooth status to %d\n", status);
  879. return -EIO;
  880. }
  881. return 0;
  882. }
  883. static ssize_t bluetooth_show(struct device *dev, struct device_attribute *attr,
  884. char *buf)
  885. {
  886. struct asus_laptop *asus = dev_get_drvdata(dev);
  887. return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
  888. }
  889. static ssize_t bluetooth_store(struct device *dev,
  890. struct device_attribute *attr, const char *buf,
  891. size_t count)
  892. {
  893. struct asus_laptop *asus = dev_get_drvdata(dev);
  894. return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
  895. }
  896. static DEVICE_ATTR_RW(bluetooth);
  897. /*
  898. * Wimax
  899. */
  900. static int asus_wimax_set(struct asus_laptop *asus, int status)
  901. {
  902. if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
  903. pr_warn("Error setting wimax status to %d\n", status);
  904. return -EIO;
  905. }
  906. return 0;
  907. }
  908. static ssize_t wimax_show(struct device *dev, struct device_attribute *attr,
  909. char *buf)
  910. {
  911. struct asus_laptop *asus = dev_get_drvdata(dev);
  912. return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
  913. }
  914. static ssize_t wimax_store(struct device *dev, struct device_attribute *attr,
  915. const char *buf, size_t count)
  916. {
  917. struct asus_laptop *asus = dev_get_drvdata(dev);
  918. return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
  919. }
  920. static DEVICE_ATTR_RW(wimax);
  921. /*
  922. * Wwan
  923. */
  924. static int asus_wwan_set(struct asus_laptop *asus, int status)
  925. {
  926. if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
  927. pr_warn("Error setting wwan status to %d\n", status);
  928. return -EIO;
  929. }
  930. return 0;
  931. }
  932. static ssize_t wwan_show(struct device *dev, struct device_attribute *attr,
  933. char *buf)
  934. {
  935. struct asus_laptop *asus = dev_get_drvdata(dev);
  936. return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
  937. }
  938. static ssize_t wwan_store(struct device *dev, struct device_attribute *attr,
  939. const char *buf, size_t count)
  940. {
  941. struct asus_laptop *asus = dev_get_drvdata(dev);
  942. return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
  943. }
  944. static DEVICE_ATTR_RW(wwan);
  945. /*
  946. * Display
  947. */
  948. static void asus_set_display(struct asus_laptop *asus, int value)
  949. {
  950. /* no sanity check needed for now */
  951. if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
  952. pr_warn("Error setting display\n");
  953. return;
  954. }
  955. /*
  956. * Experimental support for display switching. As of now: 1 should activate
  957. * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
  958. * Any combination (bitwise) of these will suffice. I never actually tested 4
  959. * displays hooked up simultaneously, so be warned. See the acpi4asus README
  960. * for more info.
  961. */
  962. static ssize_t display_store(struct device *dev, struct device_attribute *attr,
  963. const char *buf, size_t count)
  964. {
  965. struct asus_laptop *asus = dev_get_drvdata(dev);
  966. int rv, value;
  967. rv = kstrtoint(buf, 0, &value);
  968. if (rv < 0)
  969. return rv;
  970. asus_set_display(asus, value);
  971. return count;
  972. }
  973. static DEVICE_ATTR_WO(display);
  974. /*
  975. * Light Sens
  976. */
  977. static void asus_als_switch(struct asus_laptop *asus, int value)
  978. {
  979. int ret;
  980. if (asus->is_pega_lucid) {
  981. ret = asus_pega_lucid_set(asus, PEGA_ALS, value);
  982. if (!ret)
  983. ret = asus_pega_lucid_set(asus, PEGA_ALS_POWER, value);
  984. } else {
  985. ret = write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value);
  986. }
  987. if (ret)
  988. pr_warn("Error setting light sensor switch\n");
  989. asus->light_switch = value;
  990. }
  991. static ssize_t ls_switch_show(struct device *dev, struct device_attribute *attr,
  992. char *buf)
  993. {
  994. struct asus_laptop *asus = dev_get_drvdata(dev);
  995. return sprintf(buf, "%d\n", asus->light_switch);
  996. }
  997. static ssize_t ls_switch_store(struct device *dev,
  998. struct device_attribute *attr, const char *buf,
  999. size_t count)
  1000. {
  1001. struct asus_laptop *asus = dev_get_drvdata(dev);
  1002. int rv, value;
  1003. rv = kstrtoint(buf, 0, &value);
  1004. if (rv < 0)
  1005. return rv;
  1006. asus_als_switch(asus, value ? 1 : 0);
  1007. return count;
  1008. }
  1009. static DEVICE_ATTR_RW(ls_switch);
  1010. static void asus_als_level(struct asus_laptop *asus, int value)
  1011. {
  1012. if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
  1013. pr_warn("Error setting light sensor level\n");
  1014. asus->light_level = value;
  1015. }
  1016. static ssize_t ls_level_show(struct device *dev, struct device_attribute *attr,
  1017. char *buf)
  1018. {
  1019. struct asus_laptop *asus = dev_get_drvdata(dev);
  1020. return sprintf(buf, "%d\n", asus->light_level);
  1021. }
  1022. static ssize_t ls_level_store(struct device *dev, struct device_attribute *attr,
  1023. const char *buf, size_t count)
  1024. {
  1025. struct asus_laptop *asus = dev_get_drvdata(dev);
  1026. int rv, value;
  1027. rv = kstrtoint(buf, 0, &value);
  1028. if (rv < 0)
  1029. return rv;
  1030. value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
  1031. /* 0 <= value <= 15 */
  1032. asus_als_level(asus, value);
  1033. return count;
  1034. }
  1035. static DEVICE_ATTR_RW(ls_level);
  1036. static int pega_int_read(struct asus_laptop *asus, int arg, int *result)
  1037. {
  1038. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1039. int err = write_acpi_int_ret(asus->handle, METHOD_PEGA_READ, arg,
  1040. &buffer);
  1041. if (!err) {
  1042. union acpi_object *obj = buffer.pointer;
  1043. if (obj && obj->type == ACPI_TYPE_INTEGER)
  1044. *result = obj->integer.value;
  1045. else
  1046. err = -EIO;
  1047. }
  1048. return err;
  1049. }
  1050. static ssize_t ls_value_show(struct device *dev, struct device_attribute *attr,
  1051. char *buf)
  1052. {
  1053. struct asus_laptop *asus = dev_get_drvdata(dev);
  1054. int err, hi, lo;
  1055. err = pega_int_read(asus, PEGA_READ_ALS_H, &hi);
  1056. if (!err)
  1057. err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
  1058. if (!err)
  1059. return sprintf(buf, "%d\n", 10 * hi + lo);
  1060. return err;
  1061. }
  1062. static DEVICE_ATTR_RO(ls_value);
  1063. /*
  1064. * GPS
  1065. */
  1066. static int asus_gps_status(struct asus_laptop *asus)
  1067. {
  1068. unsigned long long status;
  1069. acpi_status rv;
  1070. rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
  1071. NULL, &status);
  1072. if (ACPI_FAILURE(rv)) {
  1073. pr_warn("Error reading GPS status\n");
  1074. return -ENODEV;
  1075. }
  1076. return !!status;
  1077. }
  1078. static int asus_gps_switch(struct asus_laptop *asus, int status)
  1079. {
  1080. const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
  1081. if (write_acpi_int(asus->handle, meth, 0x02))
  1082. return -ENODEV;
  1083. return 0;
  1084. }
  1085. static ssize_t gps_show(struct device *dev, struct device_attribute *attr,
  1086. char *buf)
  1087. {
  1088. struct asus_laptop *asus = dev_get_drvdata(dev);
  1089. return sprintf(buf, "%d\n", asus_gps_status(asus));
  1090. }
  1091. static ssize_t gps_store(struct device *dev, struct device_attribute *attr,
  1092. const char *buf, size_t count)
  1093. {
  1094. struct asus_laptop *asus = dev_get_drvdata(dev);
  1095. int rv, value;
  1096. int ret;
  1097. rv = kstrtoint(buf, 0, &value);
  1098. if (rv < 0)
  1099. return rv;
  1100. ret = asus_gps_switch(asus, !!value);
  1101. if (ret)
  1102. return ret;
  1103. rfkill_set_sw_state(asus->gps.rfkill, !value);
  1104. return count;
  1105. }
  1106. static DEVICE_ATTR_RW(gps);
  1107. /*
  1108. * rfkill
  1109. */
  1110. static int asus_gps_rfkill_set(void *data, bool blocked)
  1111. {
  1112. struct asus_laptop *asus = data;
  1113. return asus_gps_switch(asus, !blocked);
  1114. }
  1115. static const struct rfkill_ops asus_gps_rfkill_ops = {
  1116. .set_block = asus_gps_rfkill_set,
  1117. };
  1118. static int asus_rfkill_set(void *data, bool blocked)
  1119. {
  1120. struct asus_rfkill *rfk = data;
  1121. struct asus_laptop *asus = rfk->asus;
  1122. if (rfk->control_id == WL_RSTS)
  1123. return asus_wlan_set(asus, !blocked);
  1124. else if (rfk->control_id == BT_RSTS)
  1125. return asus_bluetooth_set(asus, !blocked);
  1126. else if (rfk->control_id == WM_RSTS)
  1127. return asus_wimax_set(asus, !blocked);
  1128. else if (rfk->control_id == WW_RSTS)
  1129. return asus_wwan_set(asus, !blocked);
  1130. return -EINVAL;
  1131. }
  1132. static const struct rfkill_ops asus_rfkill_ops = {
  1133. .set_block = asus_rfkill_set,
  1134. };
  1135. static void asus_rfkill_terminate(struct asus_rfkill *rfk)
  1136. {
  1137. if (!rfk->rfkill)
  1138. return ;
  1139. rfkill_unregister(rfk->rfkill);
  1140. rfkill_destroy(rfk->rfkill);
  1141. rfk->rfkill = NULL;
  1142. }
  1143. static void asus_rfkill_exit(struct asus_laptop *asus)
  1144. {
  1145. asus_rfkill_terminate(&asus->wwan);
  1146. asus_rfkill_terminate(&asus->bluetooth);
  1147. asus_rfkill_terminate(&asus->wlan);
  1148. asus_rfkill_terminate(&asus->gps);
  1149. }
  1150. static int asus_rfkill_setup(struct asus_laptop *asus, struct asus_rfkill *rfk,
  1151. const char *name, int control_id, int type,
  1152. const struct rfkill_ops *ops)
  1153. {
  1154. int result;
  1155. rfk->control_id = control_id;
  1156. rfk->asus = asus;
  1157. rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev,
  1158. type, ops, rfk);
  1159. if (!rfk->rfkill)
  1160. return -EINVAL;
  1161. result = rfkill_register(rfk->rfkill);
  1162. if (result) {
  1163. rfkill_destroy(rfk->rfkill);
  1164. rfk->rfkill = NULL;
  1165. }
  1166. return result;
  1167. }
  1168. static int asus_rfkill_init(struct asus_laptop *asus)
  1169. {
  1170. int result = 0;
  1171. if (asus->is_pega_lucid)
  1172. return -ENODEV;
  1173. if (!acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) &&
  1174. !acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) &&
  1175. !acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
  1176. result = asus_rfkill_setup(asus, &asus->gps, "asus-gps",
  1177. -1, RFKILL_TYPE_GPS,
  1178. &asus_gps_rfkill_ops);
  1179. if (result)
  1180. goto exit;
  1181. if (!acpi_check_handle(asus->handle, METHOD_WLAN, NULL) &&
  1182. asus->wled_type == TYPE_RFKILL)
  1183. result = asus_rfkill_setup(asus, &asus->wlan, "asus-wlan",
  1184. WL_RSTS, RFKILL_TYPE_WLAN,
  1185. &asus_rfkill_ops);
  1186. if (result)
  1187. goto exit;
  1188. if (!acpi_check_handle(asus->handle, METHOD_BLUETOOTH, NULL) &&
  1189. asus->bled_type == TYPE_RFKILL)
  1190. result = asus_rfkill_setup(asus, &asus->bluetooth,
  1191. "asus-bluetooth", BT_RSTS,
  1192. RFKILL_TYPE_BLUETOOTH,
  1193. &asus_rfkill_ops);
  1194. if (result)
  1195. goto exit;
  1196. if (!acpi_check_handle(asus->handle, METHOD_WWAN, NULL))
  1197. result = asus_rfkill_setup(asus, &asus->wwan, "asus-wwan",
  1198. WW_RSTS, RFKILL_TYPE_WWAN,
  1199. &asus_rfkill_ops);
  1200. if (result)
  1201. goto exit;
  1202. if (!acpi_check_handle(asus->handle, METHOD_WIMAX, NULL))
  1203. result = asus_rfkill_setup(asus, &asus->wimax, "asus-wimax",
  1204. WM_RSTS, RFKILL_TYPE_WIMAX,
  1205. &asus_rfkill_ops);
  1206. if (result)
  1207. goto exit;
  1208. exit:
  1209. if (result)
  1210. asus_rfkill_exit(asus);
  1211. return result;
  1212. }
  1213. static int pega_rfkill_set(void *data, bool blocked)
  1214. {
  1215. struct asus_rfkill *rfk = data;
  1216. int ret = asus_pega_lucid_set(rfk->asus, rfk->control_id, !blocked);
  1217. return ret;
  1218. }
  1219. static const struct rfkill_ops pega_rfkill_ops = {
  1220. .set_block = pega_rfkill_set,
  1221. };
  1222. static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_rfkill *rfk,
  1223. const char *name, int controlid, int rfkill_type)
  1224. {
  1225. return asus_rfkill_setup(asus, rfk, name, controlid, rfkill_type,
  1226. &pega_rfkill_ops);
  1227. }
  1228. static int pega_rfkill_init(struct asus_laptop *asus)
  1229. {
  1230. int ret = 0;
  1231. if(!asus->is_pega_lucid)
  1232. return -ENODEV;
  1233. ret = pega_rfkill_setup(asus, &asus->wlan, "pega-wlan",
  1234. PEGA_WLAN, RFKILL_TYPE_WLAN);
  1235. if(ret)
  1236. goto exit;
  1237. ret = pega_rfkill_setup(asus, &asus->bluetooth, "pega-bt",
  1238. PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH);
  1239. if(ret)
  1240. goto exit;
  1241. ret = pega_rfkill_setup(asus, &asus->wwan, "pega-wwan",
  1242. PEGA_WWAN, RFKILL_TYPE_WWAN);
  1243. exit:
  1244. if (ret)
  1245. asus_rfkill_exit(asus);
  1246. return ret;
  1247. }
  1248. /*
  1249. * Input device (i.e. hotkeys)
  1250. */
  1251. static void asus_input_notify(struct asus_laptop *asus, int event)
  1252. {
  1253. if (!asus->inputdev)
  1254. return ;
  1255. if (!sparse_keymap_report_event(asus->inputdev, event, 1, true))
  1256. pr_info("Unknown key %x pressed\n", event);
  1257. }
  1258. static int asus_input_init(struct asus_laptop *asus)
  1259. {
  1260. struct input_dev *input;
  1261. int error;
  1262. input = input_allocate_device();
  1263. if (!input)
  1264. return -ENOMEM;
  1265. input->name = "Asus Laptop extra buttons";
  1266. input->phys = ASUS_LAPTOP_FILE "/input0";
  1267. input->id.bustype = BUS_HOST;
  1268. input->dev.parent = &asus->platform_device->dev;
  1269. error = sparse_keymap_setup(input, asus_keymap, NULL);
  1270. if (error) {
  1271. pr_err("Unable to setup input device keymap\n");
  1272. goto err_free_dev;
  1273. }
  1274. error = input_register_device(input);
  1275. if (error) {
  1276. pr_warn("Unable to register input device\n");
  1277. goto err_free_dev;
  1278. }
  1279. asus->inputdev = input;
  1280. return 0;
  1281. err_free_dev:
  1282. input_free_device(input);
  1283. return error;
  1284. }
  1285. static void asus_input_exit(struct asus_laptop *asus)
  1286. {
  1287. if (asus->inputdev)
  1288. input_unregister_device(asus->inputdev);
  1289. asus->inputdev = NULL;
  1290. }
  1291. /*
  1292. * ACPI driver
  1293. */
  1294. static void asus_acpi_notify(struct acpi_device *device, u32 event)
  1295. {
  1296. struct asus_laptop *asus = acpi_driver_data(device);
  1297. u16 count;
  1298. /* TODO Find a better way to handle events count. */
  1299. count = asus->event_count[event % 128]++;
  1300. acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
  1301. dev_name(&asus->device->dev), event,
  1302. count);
  1303. if (event >= ATKD_BRNUP_MIN && event <= ATKD_BRNUP_MAX)
  1304. event = ATKD_BRNUP;
  1305. else if (event >= ATKD_BRNDOWN_MIN &&
  1306. event <= ATKD_BRNDOWN_MAX)
  1307. event = ATKD_BRNDOWN;
  1308. /* Brightness events are special */
  1309. if (event == ATKD_BRNDOWN || event == ATKD_BRNUP) {
  1310. if (asus->backlight_device != NULL) {
  1311. /* Update the backlight device. */
  1312. asus_backlight_notify(asus);
  1313. return ;
  1314. }
  1315. }
  1316. /* Accelerometer "coarse orientation change" event */
  1317. if (asus->pega_accel_poll && event == 0xEA) {
  1318. kobject_uevent(&asus->pega_accel_poll->dev.kobj, KOBJ_CHANGE);
  1319. return ;
  1320. }
  1321. asus_input_notify(asus, event);
  1322. }
  1323. static struct attribute *asus_attributes[] = {
  1324. &dev_attr_infos.attr,
  1325. &dev_attr_wlan.attr,
  1326. &dev_attr_bluetooth.attr,
  1327. &dev_attr_wimax.attr,
  1328. &dev_attr_wwan.attr,
  1329. &dev_attr_display.attr,
  1330. &dev_attr_ledd.attr,
  1331. &dev_attr_ls_value.attr,
  1332. &dev_attr_ls_level.attr,
  1333. &dev_attr_ls_switch.attr,
  1334. &dev_attr_gps.attr,
  1335. NULL
  1336. };
  1337. static umode_t asus_sysfs_is_visible(struct kobject *kobj,
  1338. struct attribute *attr,
  1339. int idx)
  1340. {
  1341. struct device *dev = container_of(kobj, struct device, kobj);
  1342. struct asus_laptop *asus = dev_get_drvdata(dev);
  1343. acpi_handle handle = asus->handle;
  1344. bool supported;
  1345. if (asus->is_pega_lucid) {
  1346. /* no ls_level interface on the Lucid */
  1347. if (attr == &dev_attr_ls_switch.attr)
  1348. supported = true;
  1349. else if (attr == &dev_attr_ls_level.attr)
  1350. supported = false;
  1351. else
  1352. goto normal;
  1353. return supported ? attr->mode : 0;
  1354. }
  1355. normal:
  1356. if (attr == &dev_attr_wlan.attr) {
  1357. supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
  1358. } else if (attr == &dev_attr_bluetooth.attr) {
  1359. supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
  1360. } else if (attr == &dev_attr_display.attr) {
  1361. supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
  1362. } else if (attr == &dev_attr_wimax.attr) {
  1363. supported =
  1364. !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
  1365. } else if (attr == &dev_attr_wwan.attr) {
  1366. supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
  1367. } else if (attr == &dev_attr_ledd.attr) {
  1368. supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
  1369. } else if (attr == &dev_attr_ls_switch.attr ||
  1370. attr == &dev_attr_ls_level.attr) {
  1371. supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
  1372. !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
  1373. } else if (attr == &dev_attr_ls_value.attr) {
  1374. supported = asus->is_pega_lucid;
  1375. } else if (attr == &dev_attr_gps.attr) {
  1376. supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
  1377. !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
  1378. !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
  1379. } else {
  1380. supported = true;
  1381. }
  1382. return supported ? attr->mode : 0;
  1383. }
  1384. static const struct attribute_group asus_attr_group = {
  1385. .is_visible = asus_sysfs_is_visible,
  1386. .attrs = asus_attributes,
  1387. };
  1388. static int asus_platform_init(struct asus_laptop *asus)
  1389. {
  1390. int result;
  1391. asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
  1392. if (!asus->platform_device)
  1393. return -ENOMEM;
  1394. platform_set_drvdata(asus->platform_device, asus);
  1395. result = platform_device_add(asus->platform_device);
  1396. if (result)
  1397. goto fail_platform_device;
  1398. result = sysfs_create_group(&asus->platform_device->dev.kobj,
  1399. &asus_attr_group);
  1400. if (result)
  1401. goto fail_sysfs;
  1402. return 0;
  1403. fail_sysfs:
  1404. platform_device_del(asus->platform_device);
  1405. fail_platform_device:
  1406. platform_device_put(asus->platform_device);
  1407. return result;
  1408. }
  1409. static void asus_platform_exit(struct asus_laptop *asus)
  1410. {
  1411. sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
  1412. platform_device_unregister(asus->platform_device);
  1413. }
  1414. static struct platform_driver platform_driver = {
  1415. .driver = {
  1416. .name = ASUS_LAPTOP_FILE,
  1417. },
  1418. };
  1419. /*
  1420. * This function is used to initialize the context with right values. In this
  1421. * method, we can make all the detection we want, and modify the asus_laptop
  1422. * struct
  1423. */
  1424. static int asus_laptop_get_info(struct asus_laptop *asus)
  1425. {
  1426. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1427. union acpi_object *model = NULL;
  1428. unsigned long long bsts_result;
  1429. char *string = NULL;
  1430. acpi_status status;
  1431. /*
  1432. * Get DSDT headers early enough to allow for differentiating between
  1433. * models, but late enough to allow acpi_bus_register_driver() to fail
  1434. * before doing anything ACPI-specific. Should we encounter a machine,
  1435. * which needs special handling (i.e. its hotkey device has a different
  1436. * HID), this bit will be moved.
  1437. */
  1438. status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
  1439. if (ACPI_FAILURE(status))
  1440. pr_warn("Couldn't get the DSDT table header\n");
  1441. /* We have to write 0 on init this far for all ASUS models */
  1442. if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
  1443. pr_err("Hotkey initialization failed\n");
  1444. return -ENODEV;
  1445. }
  1446. /* This needs to be called for some laptops to init properly */
  1447. status =
  1448. acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
  1449. if (ACPI_FAILURE(status))
  1450. pr_warn("Error calling BSTS\n");
  1451. else if (bsts_result)
  1452. pr_notice("BSTS called, 0x%02x returned\n",
  1453. (uint) bsts_result);
  1454. /* This too ... */
  1455. if (write_acpi_int(asus->handle, "CWAP", wapf))
  1456. pr_err("Error calling CWAP(%d)\n", wapf);
  1457. /*
  1458. * Try to match the object returned by INIT to the specific model.
  1459. * Handle every possible object (or the lack of thereof) the DSDT
  1460. * writers might throw at us. When in trouble, we pass NULL to
  1461. * asus_model_match() and try something completely different.
  1462. */
  1463. if (buffer.pointer) {
  1464. model = buffer.pointer;
  1465. switch (model->type) {
  1466. case ACPI_TYPE_STRING:
  1467. string = model->string.pointer;
  1468. break;
  1469. case ACPI_TYPE_BUFFER:
  1470. string = model->buffer.pointer;
  1471. break;
  1472. default:
  1473. string = "";
  1474. break;
  1475. }
  1476. }
  1477. asus->name = kstrdup(string, GFP_KERNEL);
  1478. if (!asus->name) {
  1479. kfree(buffer.pointer);
  1480. return -ENOMEM;
  1481. }
  1482. if (string)
  1483. pr_notice(" %s model detected\n", string);
  1484. if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
  1485. asus->have_rsts = true;
  1486. kfree(model);
  1487. return AE_OK;
  1488. }
  1489. static int asus_acpi_init(struct asus_laptop *asus)
  1490. {
  1491. int result = 0;
  1492. result = acpi_bus_get_status(asus->device);
  1493. if (result)
  1494. return result;
  1495. if (!asus->device->status.present) {
  1496. pr_err("Hotkey device not present, aborting\n");
  1497. return -ENODEV;
  1498. }
  1499. result = asus_laptop_get_info(asus);
  1500. if (result)
  1501. return result;
  1502. if (!strcmp(bled_type, "led"))
  1503. asus->bled_type = TYPE_LED;
  1504. else if (!strcmp(bled_type, "rfkill"))
  1505. asus->bled_type = TYPE_RFKILL;
  1506. if (!strcmp(wled_type, "led"))
  1507. asus->wled_type = TYPE_LED;
  1508. else if (!strcmp(wled_type, "rfkill"))
  1509. asus->wled_type = TYPE_RFKILL;
  1510. if (bluetooth_status >= 0)
  1511. asus_bluetooth_set(asus, !!bluetooth_status);
  1512. if (wlan_status >= 0)
  1513. asus_wlan_set(asus, !!wlan_status);
  1514. if (wimax_status >= 0)
  1515. asus_wimax_set(asus, !!wimax_status);
  1516. if (wwan_status >= 0)
  1517. asus_wwan_set(asus, !!wwan_status);
  1518. /* Keyboard Backlight is on by default */
  1519. if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
  1520. asus_kled_set(asus, 1);
  1521. /* LED display is off by default */
  1522. asus->ledd_status = 0xFFF;
  1523. /* Set initial values of light sensor and level */
  1524. asus->light_switch = !!als_status;
  1525. asus->light_level = 5; /* level 5 for sensor sensitivity */
  1526. if (asus->is_pega_lucid) {
  1527. asus_als_switch(asus, asus->light_switch);
  1528. } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
  1529. !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
  1530. asus_als_switch(asus, asus->light_switch);
  1531. asus_als_level(asus, asus->light_level);
  1532. }
  1533. return result;
  1534. }
  1535. static void asus_dmi_check(void)
  1536. {
  1537. const char *model;
  1538. model = dmi_get_system_info(DMI_PRODUCT_NAME);
  1539. if (!model)
  1540. return;
  1541. /* On L1400B WLED control the sound card, don't mess with it ... */
  1542. if (strncmp(model, "L1400B", 6) == 0) {
  1543. wlan_status = -1;
  1544. }
  1545. }
  1546. static bool asus_device_present;
  1547. static int asus_acpi_add(struct acpi_device *device)
  1548. {
  1549. struct asus_laptop *asus;
  1550. int result;
  1551. pr_notice("Asus Laptop Support version %s\n",
  1552. ASUS_LAPTOP_VERSION);
  1553. asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
  1554. if (!asus)
  1555. return -ENOMEM;
  1556. asus->handle = device->handle;
  1557. strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
  1558. strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
  1559. device->driver_data = asus;
  1560. asus->device = device;
  1561. asus_dmi_check();
  1562. result = asus_acpi_init(asus);
  1563. if (result)
  1564. goto fail_platform;
  1565. /*
  1566. * Need platform type detection first, then the platform
  1567. * device. It is used as a parent for the sub-devices below.
  1568. */
  1569. asus->is_pega_lucid = asus_check_pega_lucid(asus);
  1570. result = asus_platform_init(asus);
  1571. if (result)
  1572. goto fail_platform;
  1573. if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
  1574. result = asus_backlight_init(asus);
  1575. if (result)
  1576. goto fail_backlight;
  1577. }
  1578. result = asus_input_init(asus);
  1579. if (result)
  1580. goto fail_input;
  1581. result = asus_led_init(asus);
  1582. if (result)
  1583. goto fail_led;
  1584. result = asus_rfkill_init(asus);
  1585. if (result && result != -ENODEV)
  1586. goto fail_rfkill;
  1587. result = pega_accel_init(asus);
  1588. if (result && result != -ENODEV)
  1589. goto fail_pega_accel;
  1590. result = pega_rfkill_init(asus);
  1591. if (result && result != -ENODEV)
  1592. goto fail_pega_rfkill;
  1593. asus_device_present = true;
  1594. return 0;
  1595. fail_pega_rfkill:
  1596. pega_accel_exit(asus);
  1597. fail_pega_accel:
  1598. asus_rfkill_exit(asus);
  1599. fail_rfkill:
  1600. asus_led_exit(asus);
  1601. fail_led:
  1602. asus_input_exit(asus);
  1603. fail_input:
  1604. asus_backlight_exit(asus);
  1605. fail_backlight:
  1606. asus_platform_exit(asus);
  1607. fail_platform:
  1608. kfree(asus);
  1609. return result;
  1610. }
  1611. static int asus_acpi_remove(struct acpi_device *device)
  1612. {
  1613. struct asus_laptop *asus = acpi_driver_data(device);
  1614. asus_backlight_exit(asus);
  1615. asus_rfkill_exit(asus);
  1616. asus_led_exit(asus);
  1617. asus_input_exit(asus);
  1618. pega_accel_exit(asus);
  1619. asus_platform_exit(asus);
  1620. kfree(asus->name);
  1621. kfree(asus);
  1622. return 0;
  1623. }
  1624. static const struct acpi_device_id asus_device_ids[] = {
  1625. {"ATK0100", 0},
  1626. {"ATK0101", 0},
  1627. {"", 0},
  1628. };
  1629. MODULE_DEVICE_TABLE(acpi, asus_device_ids);
  1630. static struct acpi_driver asus_acpi_driver = {
  1631. .name = ASUS_LAPTOP_NAME,
  1632. .class = ASUS_LAPTOP_CLASS,
  1633. .owner = THIS_MODULE,
  1634. .ids = asus_device_ids,
  1635. .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
  1636. .ops = {
  1637. .add = asus_acpi_add,
  1638. .remove = asus_acpi_remove,
  1639. .notify = asus_acpi_notify,
  1640. },
  1641. };
  1642. static int __init asus_laptop_init(void)
  1643. {
  1644. int result;
  1645. result = platform_driver_register(&platform_driver);
  1646. if (result < 0)
  1647. return result;
  1648. result = acpi_bus_register_driver(&asus_acpi_driver);
  1649. if (result < 0)
  1650. goto fail_acpi_driver;
  1651. if (!asus_device_present) {
  1652. result = -ENODEV;
  1653. goto fail_no_device;
  1654. }
  1655. return 0;
  1656. fail_no_device:
  1657. acpi_bus_unregister_driver(&asus_acpi_driver);
  1658. fail_acpi_driver:
  1659. platform_driver_unregister(&platform_driver);
  1660. return result;
  1661. }
  1662. static void __exit asus_laptop_exit(void)
  1663. {
  1664. acpi_bus_unregister_driver(&asus_acpi_driver);
  1665. platform_driver_unregister(&platform_driver);
  1666. }
  1667. module_init(asus_laptop_init);
  1668. module_exit(asus_laptop_exit);