asus-laptop.c 49 KB

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