asus-laptop.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879
  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_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 asus_rfkill wlan;
  223. struct asus_rfkill bluetooth;
  224. struct asus_rfkill wwan;
  225. struct asus_rfkill gps;
  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_terminate(struct asus_rfkill *rfk)
  1066. {
  1067. if (!rfk->rfkill)
  1068. return ;
  1069. rfkill_unregister(rfk->rfkill);
  1070. rfkill_destroy(rfk->rfkill);
  1071. rfk->rfkill = NULL;
  1072. }
  1073. static void asus_rfkill_exit(struct asus_laptop *asus)
  1074. {
  1075. asus_rfkill_terminate(&asus->wwan);
  1076. asus_rfkill_terminate(&asus->bluetooth);
  1077. asus_rfkill_terminate(&asus->wlan);
  1078. asus_rfkill_terminate(&asus->gps);
  1079. }
  1080. static int asus_rfkill_init(struct asus_laptop *asus)
  1081. {
  1082. int result;
  1083. if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
  1084. acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
  1085. acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
  1086. return 0;
  1087. asus->gps.rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
  1088. RFKILL_TYPE_GPS,
  1089. &asus_gps_rfkill_ops, asus);
  1090. if (!asus->gps.rfkill)
  1091. return -EINVAL;
  1092. result = rfkill_register(asus->gps.rfkill);
  1093. if (result) {
  1094. rfkill_destroy(asus->gps.rfkill);
  1095. asus->gps.rfkill = NULL;
  1096. }
  1097. return result;
  1098. }
  1099. static int pega_rfkill_set(void *data, bool blocked)
  1100. {
  1101. struct asus_rfkill *rfk = data;
  1102. int ret = asus_pega_lucid_set(rfk->asus, rfk->control_id, !blocked);
  1103. return ret;
  1104. }
  1105. static const struct rfkill_ops pega_rfkill_ops = {
  1106. .set_block = pega_rfkill_set,
  1107. };
  1108. static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_rfkill *rfk,
  1109. const char *name, int controlid, int rfkill_type)
  1110. {
  1111. int result;
  1112. rfk->control_id = controlid;
  1113. rfk->asus = asus;
  1114. rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev,
  1115. rfkill_type, &pega_rfkill_ops, rfk);
  1116. if (!rfk->rfkill)
  1117. return -EINVAL;
  1118. result = rfkill_register(rfk->rfkill);
  1119. if (result) {
  1120. rfkill_destroy(rfk->rfkill);
  1121. rfk->rfkill = NULL;
  1122. }
  1123. return result;
  1124. }
  1125. static int pega_rfkill_init(struct asus_laptop *asus)
  1126. {
  1127. int ret = 0;
  1128. if(!asus->is_pega_lucid)
  1129. return -ENODEV;
  1130. ret = pega_rfkill_setup(asus, &asus->wlan, "pega-wlan",
  1131. PEGA_WLAN, RFKILL_TYPE_WLAN);
  1132. if(ret)
  1133. goto exit;
  1134. ret = pega_rfkill_setup(asus, &asus->bluetooth, "pega-bt",
  1135. PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH);
  1136. if(ret)
  1137. goto exit;
  1138. ret = pega_rfkill_setup(asus, &asus->wwan, "pega-wwan",
  1139. PEGA_WWAN, RFKILL_TYPE_WWAN);
  1140. exit:
  1141. if (ret)
  1142. asus_rfkill_exit(asus);
  1143. return ret;
  1144. }
  1145. /*
  1146. * Input device (i.e. hotkeys)
  1147. */
  1148. static void asus_input_notify(struct asus_laptop *asus, int event)
  1149. {
  1150. if (!asus->inputdev)
  1151. return ;
  1152. if (!sparse_keymap_report_event(asus->inputdev, event, 1, true))
  1153. pr_info("Unknown key %x pressed\n", event);
  1154. }
  1155. static int asus_input_init(struct asus_laptop *asus)
  1156. {
  1157. struct input_dev *input;
  1158. int error;
  1159. input = input_allocate_device();
  1160. if (!input) {
  1161. pr_warn("Unable to allocate input device\n");
  1162. return -ENOMEM;
  1163. }
  1164. input->name = "Asus Laptop extra buttons";
  1165. input->phys = ASUS_LAPTOP_FILE "/input0";
  1166. input->id.bustype = BUS_HOST;
  1167. input->dev.parent = &asus->platform_device->dev;
  1168. error = sparse_keymap_setup(input, asus_keymap, NULL);
  1169. if (error) {
  1170. pr_err("Unable to setup input device keymap\n");
  1171. goto err_free_dev;
  1172. }
  1173. error = input_register_device(input);
  1174. if (error) {
  1175. pr_warn("Unable to register input device\n");
  1176. goto err_free_keymap;
  1177. }
  1178. asus->inputdev = input;
  1179. return 0;
  1180. err_free_keymap:
  1181. sparse_keymap_free(input);
  1182. err_free_dev:
  1183. input_free_device(input);
  1184. return error;
  1185. }
  1186. static void asus_input_exit(struct asus_laptop *asus)
  1187. {
  1188. if (asus->inputdev) {
  1189. sparse_keymap_free(asus->inputdev);
  1190. input_unregister_device(asus->inputdev);
  1191. }
  1192. asus->inputdev = NULL;
  1193. }
  1194. /*
  1195. * ACPI driver
  1196. */
  1197. static void asus_acpi_notify(struct acpi_device *device, u32 event)
  1198. {
  1199. struct asus_laptop *asus = acpi_driver_data(device);
  1200. u16 count;
  1201. /* TODO Find a better way to handle events count. */
  1202. count = asus->event_count[event % 128]++;
  1203. acpi_bus_generate_proc_event(asus->device, event, count);
  1204. acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
  1205. dev_name(&asus->device->dev), event,
  1206. count);
  1207. /* Brightness events are special */
  1208. if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
  1209. /* Ignore them completely if the acpi video driver is used */
  1210. if (asus->backlight_device != NULL) {
  1211. /* Update the backlight device. */
  1212. asus_backlight_notify(asus);
  1213. }
  1214. return ;
  1215. }
  1216. /* Accelerometer "coarse orientation change" event */
  1217. if (asus->pega_accel_poll && event == 0xEA) {
  1218. kobject_uevent(&asus->pega_accel_poll->input->dev.kobj,
  1219. KOBJ_CHANGE);
  1220. return ;
  1221. }
  1222. asus_input_notify(asus, event);
  1223. }
  1224. static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
  1225. static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
  1226. static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
  1227. show_bluetooth, store_bluetooth);
  1228. static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
  1229. static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
  1230. static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
  1231. static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
  1232. static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL);
  1233. static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
  1234. static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
  1235. static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
  1236. static struct attribute *asus_attributes[] = {
  1237. &dev_attr_infos.attr,
  1238. &dev_attr_wlan.attr,
  1239. &dev_attr_bluetooth.attr,
  1240. &dev_attr_wimax.attr,
  1241. &dev_attr_wwan.attr,
  1242. &dev_attr_display.attr,
  1243. &dev_attr_ledd.attr,
  1244. &dev_attr_ls_value.attr,
  1245. &dev_attr_ls_level.attr,
  1246. &dev_attr_ls_switch.attr,
  1247. &dev_attr_gps.attr,
  1248. NULL
  1249. };
  1250. static umode_t asus_sysfs_is_visible(struct kobject *kobj,
  1251. struct attribute *attr,
  1252. int idx)
  1253. {
  1254. struct device *dev = container_of(kobj, struct device, kobj);
  1255. struct platform_device *pdev = to_platform_device(dev);
  1256. struct asus_laptop *asus = platform_get_drvdata(pdev);
  1257. acpi_handle handle = asus->handle;
  1258. bool supported;
  1259. if (asus->is_pega_lucid) {
  1260. /* no ls_level interface on the Lucid */
  1261. if (attr == &dev_attr_ls_switch.attr)
  1262. supported = true;
  1263. else if (attr == &dev_attr_ls_level.attr)
  1264. supported = false;
  1265. else
  1266. goto normal;
  1267. return supported;
  1268. }
  1269. normal:
  1270. if (attr == &dev_attr_wlan.attr) {
  1271. supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
  1272. } else if (attr == &dev_attr_bluetooth.attr) {
  1273. supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
  1274. } else if (attr == &dev_attr_display.attr) {
  1275. supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
  1276. } else if (attr == &dev_attr_wimax.attr) {
  1277. supported =
  1278. !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
  1279. } else if (attr == &dev_attr_wwan.attr) {
  1280. supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
  1281. } else if (attr == &dev_attr_ledd.attr) {
  1282. supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
  1283. } else if (attr == &dev_attr_ls_switch.attr ||
  1284. attr == &dev_attr_ls_level.attr) {
  1285. supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
  1286. !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
  1287. } else if (attr == &dev_attr_ls_value.attr) {
  1288. supported = asus->is_pega_lucid;
  1289. } else if (attr == &dev_attr_gps.attr) {
  1290. supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
  1291. !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
  1292. !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
  1293. } else {
  1294. supported = true;
  1295. }
  1296. return supported ? attr->mode : 0;
  1297. }
  1298. static const struct attribute_group asus_attr_group = {
  1299. .is_visible = asus_sysfs_is_visible,
  1300. .attrs = asus_attributes,
  1301. };
  1302. static int asus_platform_init(struct asus_laptop *asus)
  1303. {
  1304. int result;
  1305. asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
  1306. if (!asus->platform_device)
  1307. return -ENOMEM;
  1308. platform_set_drvdata(asus->platform_device, asus);
  1309. result = platform_device_add(asus->platform_device);
  1310. if (result)
  1311. goto fail_platform_device;
  1312. result = sysfs_create_group(&asus->platform_device->dev.kobj,
  1313. &asus_attr_group);
  1314. if (result)
  1315. goto fail_sysfs;
  1316. return 0;
  1317. fail_sysfs:
  1318. platform_device_del(asus->platform_device);
  1319. fail_platform_device:
  1320. platform_device_put(asus->platform_device);
  1321. return result;
  1322. }
  1323. static void asus_platform_exit(struct asus_laptop *asus)
  1324. {
  1325. sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
  1326. platform_device_unregister(asus->platform_device);
  1327. }
  1328. static struct platform_driver platform_driver = {
  1329. .driver = {
  1330. .name = ASUS_LAPTOP_FILE,
  1331. .owner = THIS_MODULE,
  1332. },
  1333. };
  1334. /*
  1335. * This function is used to initialize the context with right values. In this
  1336. * method, we can make all the detection we want, and modify the asus_laptop
  1337. * struct
  1338. */
  1339. static int asus_laptop_get_info(struct asus_laptop *asus)
  1340. {
  1341. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1342. union acpi_object *model = NULL;
  1343. unsigned long long bsts_result, hwrs_result;
  1344. char *string = NULL;
  1345. acpi_status status;
  1346. /*
  1347. * Get DSDT headers early enough to allow for differentiating between
  1348. * models, but late enough to allow acpi_bus_register_driver() to fail
  1349. * before doing anything ACPI-specific. Should we encounter a machine,
  1350. * which needs special handling (i.e. its hotkey device has a different
  1351. * HID), this bit will be moved.
  1352. */
  1353. status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
  1354. if (ACPI_FAILURE(status))
  1355. pr_warn("Couldn't get the DSDT table header\n");
  1356. /* We have to write 0 on init this far for all ASUS models */
  1357. if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
  1358. pr_err("Hotkey initialization failed\n");
  1359. return -ENODEV;
  1360. }
  1361. /* This needs to be called for some laptops to init properly */
  1362. status =
  1363. acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
  1364. if (ACPI_FAILURE(status))
  1365. pr_warn("Error calling BSTS\n");
  1366. else if (bsts_result)
  1367. pr_notice("BSTS called, 0x%02x returned\n",
  1368. (uint) bsts_result);
  1369. /* This too ... */
  1370. if (write_acpi_int(asus->handle, "CWAP", wapf))
  1371. pr_err("Error calling CWAP(%d)\n", wapf);
  1372. /*
  1373. * Try to match the object returned by INIT to the specific model.
  1374. * Handle every possible object (or the lack of thereof) the DSDT
  1375. * writers might throw at us. When in trouble, we pass NULL to
  1376. * asus_model_match() and try something completely different.
  1377. */
  1378. if (buffer.pointer) {
  1379. model = buffer.pointer;
  1380. switch (model->type) {
  1381. case ACPI_TYPE_STRING:
  1382. string = model->string.pointer;
  1383. break;
  1384. case ACPI_TYPE_BUFFER:
  1385. string = model->buffer.pointer;
  1386. break;
  1387. default:
  1388. string = "";
  1389. break;
  1390. }
  1391. }
  1392. asus->name = kstrdup(string, GFP_KERNEL);
  1393. if (!asus->name) {
  1394. kfree(buffer.pointer);
  1395. return -ENOMEM;
  1396. }
  1397. if (*string)
  1398. pr_notice(" %s model detected\n", string);
  1399. /*
  1400. * The HWRS method return informations about the hardware.
  1401. * 0x80 bit is for WLAN, 0x100 for Bluetooth,
  1402. * 0x40 for WWAN, 0x10 for WIMAX.
  1403. * The significance of others is yet to be found.
  1404. */
  1405. status =
  1406. acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
  1407. if (!ACPI_FAILURE(status))
  1408. pr_notice(" HRWS returned %x", (int)hwrs_result);
  1409. if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
  1410. asus->have_rsts = true;
  1411. kfree(model);
  1412. return AE_OK;
  1413. }
  1414. static int __devinit asus_acpi_init(struct asus_laptop *asus)
  1415. {
  1416. int result = 0;
  1417. result = acpi_bus_get_status(asus->device);
  1418. if (result)
  1419. return result;
  1420. if (!asus->device->status.present) {
  1421. pr_err("Hotkey device not present, aborting\n");
  1422. return -ENODEV;
  1423. }
  1424. result = asus_laptop_get_info(asus);
  1425. if (result)
  1426. return result;
  1427. /* WLED and BLED are on by default */
  1428. if (bluetooth_status >= 0)
  1429. asus_bluetooth_set(asus, !!bluetooth_status);
  1430. if (wlan_status >= 0)
  1431. asus_wlan_set(asus, !!wlan_status);
  1432. if (wimax_status >= 0)
  1433. asus_wimax_set(asus, !!wimax_status);
  1434. if (wwan_status >= 0)
  1435. asus_wwan_set(asus, !!wwan_status);
  1436. /* Keyboard Backlight is on by default */
  1437. if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
  1438. asus_kled_set(asus, 1);
  1439. /* LED display is off by default */
  1440. asus->ledd_status = 0xFFF;
  1441. /* Set initial values of light sensor and level */
  1442. asus->light_switch = !!als_status;
  1443. asus->light_level = 5; /* level 5 for sensor sensitivity */
  1444. if (asus->is_pega_lucid) {
  1445. asus_als_switch(asus, asus->light_switch);
  1446. } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
  1447. !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
  1448. asus_als_switch(asus, asus->light_switch);
  1449. asus_als_level(asus, asus->light_level);
  1450. }
  1451. return result;
  1452. }
  1453. static void __devinit asus_dmi_check(void)
  1454. {
  1455. const char *model;
  1456. model = dmi_get_system_info(DMI_PRODUCT_NAME);
  1457. if (!model)
  1458. return;
  1459. /* On L1400B WLED control the sound card, don't mess with it ... */
  1460. if (strncmp(model, "L1400B", 6) == 0) {
  1461. wlan_status = -1;
  1462. }
  1463. }
  1464. static bool asus_device_present;
  1465. static int __devinit asus_acpi_add(struct acpi_device *device)
  1466. {
  1467. struct asus_laptop *asus;
  1468. int result;
  1469. pr_notice("Asus Laptop Support version %s\n",
  1470. ASUS_LAPTOP_VERSION);
  1471. asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
  1472. if (!asus)
  1473. return -ENOMEM;
  1474. asus->handle = device->handle;
  1475. strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
  1476. strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
  1477. device->driver_data = asus;
  1478. asus->device = device;
  1479. asus_dmi_check();
  1480. result = asus_acpi_init(asus);
  1481. if (result)
  1482. goto fail_platform;
  1483. /*
  1484. * Need platform type detection first, then the platform
  1485. * device. It is used as a parent for the sub-devices below.
  1486. */
  1487. asus->is_pega_lucid = asus_check_pega_lucid(asus);
  1488. result = asus_platform_init(asus);
  1489. if (result)
  1490. goto fail_platform;
  1491. if (!acpi_video_backlight_support()) {
  1492. result = asus_backlight_init(asus);
  1493. if (result)
  1494. goto fail_backlight;
  1495. } else
  1496. pr_info("Backlight controlled by ACPI video driver\n");
  1497. result = asus_input_init(asus);
  1498. if (result)
  1499. goto fail_input;
  1500. result = asus_led_init(asus);
  1501. if (result)
  1502. goto fail_led;
  1503. result = asus_rfkill_init(asus);
  1504. if (result)
  1505. goto fail_rfkill;
  1506. result = pega_accel_init(asus);
  1507. if (result && result != -ENODEV)
  1508. goto fail_pega_accel;
  1509. result = pega_rfkill_init(asus);
  1510. if (result && result != -ENODEV)
  1511. goto fail_pega_rfkill;
  1512. asus_device_present = true;
  1513. return 0;
  1514. fail_pega_rfkill:
  1515. pega_accel_exit(asus);
  1516. fail_pega_accel:
  1517. asus_rfkill_exit(asus);
  1518. fail_rfkill:
  1519. asus_led_exit(asus);
  1520. fail_led:
  1521. asus_input_exit(asus);
  1522. fail_input:
  1523. asus_backlight_exit(asus);
  1524. fail_backlight:
  1525. asus_platform_exit(asus);
  1526. fail_platform:
  1527. kfree(asus->name);
  1528. kfree(asus);
  1529. return result;
  1530. }
  1531. static int asus_acpi_remove(struct acpi_device *device, int type)
  1532. {
  1533. struct asus_laptop *asus = acpi_driver_data(device);
  1534. asus_backlight_exit(asus);
  1535. asus_rfkill_exit(asus);
  1536. asus_led_exit(asus);
  1537. asus_input_exit(asus);
  1538. pega_accel_exit(asus);
  1539. asus_platform_exit(asus);
  1540. kfree(asus->name);
  1541. kfree(asus);
  1542. return 0;
  1543. }
  1544. static const struct acpi_device_id asus_device_ids[] = {
  1545. {"ATK0100", 0},
  1546. {"ATK0101", 0},
  1547. {"", 0},
  1548. };
  1549. MODULE_DEVICE_TABLE(acpi, asus_device_ids);
  1550. static struct acpi_driver asus_acpi_driver = {
  1551. .name = ASUS_LAPTOP_NAME,
  1552. .class = ASUS_LAPTOP_CLASS,
  1553. .owner = THIS_MODULE,
  1554. .ids = asus_device_ids,
  1555. .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
  1556. .ops = {
  1557. .add = asus_acpi_add,
  1558. .remove = asus_acpi_remove,
  1559. .notify = asus_acpi_notify,
  1560. },
  1561. };
  1562. static int __init asus_laptop_init(void)
  1563. {
  1564. int result;
  1565. result = platform_driver_register(&platform_driver);
  1566. if (result < 0)
  1567. return result;
  1568. result = acpi_bus_register_driver(&asus_acpi_driver);
  1569. if (result < 0)
  1570. goto fail_acpi_driver;
  1571. if (!asus_device_present) {
  1572. result = -ENODEV;
  1573. goto fail_no_device;
  1574. }
  1575. return 0;
  1576. fail_no_device:
  1577. acpi_bus_unregister_driver(&asus_acpi_driver);
  1578. fail_acpi_driver:
  1579. platform_driver_unregister(&platform_driver);
  1580. return result;
  1581. }
  1582. static void __exit asus_laptop_exit(void)
  1583. {
  1584. acpi_bus_unregister_driver(&asus_acpi_driver);
  1585. platform_driver_unregister(&platform_driver);
  1586. }
  1587. module_init(asus_laptop_init);
  1588. module_exit(asus_laptop_exit);