asus-laptop.c 51 KB

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