asus-laptop.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  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. * The significance of others is yet to be found.
  741. * If we don't find the method, we assume the device are present.
  742. */
  743. rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
  744. if (!ACPI_FAILURE(rv))
  745. len += sprintf(page + len, "HRWS value : %#x\n",
  746. (uint) temp);
  747. /*
  748. * Another value for userspace: the ASYM method returns 0x02 for
  749. * battery low and 0x04 for battery critical, its readings tend to be
  750. * more accurate than those provided by _BST.
  751. * Note: since not all the laptops provide this method, errors are
  752. * silently ignored.
  753. */
  754. rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
  755. if (!ACPI_FAILURE(rv))
  756. len += sprintf(page + len, "ASYM value : %#x\n",
  757. (uint) temp);
  758. if (asus->dsdt_info) {
  759. snprintf(buf, 16, "%d", asus->dsdt_info->length);
  760. len += sprintf(page + len, "DSDT length : %s\n", buf);
  761. snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
  762. len += sprintf(page + len, "DSDT checksum : %s\n", buf);
  763. snprintf(buf, 16, "%d", asus->dsdt_info->revision);
  764. len += sprintf(page + len, "DSDT revision : %s\n", buf);
  765. snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
  766. len += sprintf(page + len, "OEM id : %s\n", buf);
  767. snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
  768. len += sprintf(page + len, "OEM table id : %s\n", buf);
  769. snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
  770. len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
  771. snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
  772. len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
  773. snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
  774. len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
  775. }
  776. return len;
  777. }
  778. static int parse_arg(const char *buf, unsigned long count, int *val)
  779. {
  780. if (!count)
  781. return 0;
  782. if (count > 31)
  783. return -EINVAL;
  784. if (sscanf(buf, "%i", val) != 1)
  785. return -EINVAL;
  786. return count;
  787. }
  788. static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
  789. const char *buf, size_t count,
  790. const char *method)
  791. {
  792. int rv, value;
  793. int out = 0;
  794. rv = parse_arg(buf, count, &value);
  795. if (rv > 0)
  796. out = value ? 1 : 0;
  797. if (write_acpi_int(asus->handle, method, value))
  798. return -ENODEV;
  799. return rv;
  800. }
  801. /*
  802. * LEDD display
  803. */
  804. static ssize_t show_ledd(struct device *dev,
  805. struct device_attribute *attr, char *buf)
  806. {
  807. struct asus_laptop *asus = dev_get_drvdata(dev);
  808. return sprintf(buf, "0x%08x\n", asus->ledd_status);
  809. }
  810. static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
  811. const char *buf, size_t count)
  812. {
  813. struct asus_laptop *asus = dev_get_drvdata(dev);
  814. int rv, value;
  815. rv = parse_arg(buf, count, &value);
  816. if (rv > 0) {
  817. if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
  818. pr_warn("LED display write failed\n");
  819. return -ENODEV;
  820. }
  821. asus->ledd_status = (u32) value;
  822. }
  823. return rv;
  824. }
  825. /*
  826. * Wireless
  827. */
  828. static int asus_wireless_status(struct asus_laptop *asus, int mask)
  829. {
  830. unsigned long long status;
  831. acpi_status rv = AE_OK;
  832. if (!asus->have_rsts)
  833. return (asus->wireless_status & mask) ? 1 : 0;
  834. rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
  835. NULL, &status);
  836. if (ACPI_FAILURE(rv)) {
  837. pr_warn("Error reading Wireless status\n");
  838. return -EINVAL;
  839. }
  840. return !!(status & mask);
  841. }
  842. /*
  843. * WLAN
  844. */
  845. static int asus_wlan_set(struct asus_laptop *asus, int status)
  846. {
  847. if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
  848. pr_warn("Error setting wlan status to %d\n", status);
  849. return -EIO;
  850. }
  851. return 0;
  852. }
  853. static ssize_t show_wlan(struct device *dev,
  854. struct device_attribute *attr, char *buf)
  855. {
  856. struct asus_laptop *asus = dev_get_drvdata(dev);
  857. return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
  858. }
  859. static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
  860. const char *buf, size_t count)
  861. {
  862. struct asus_laptop *asus = dev_get_drvdata(dev);
  863. return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
  864. }
  865. /*e
  866. * Bluetooth
  867. */
  868. static int asus_bluetooth_set(struct asus_laptop *asus, int status)
  869. {
  870. if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
  871. pr_warn("Error setting bluetooth status to %d\n", status);
  872. return -EIO;
  873. }
  874. return 0;
  875. }
  876. static ssize_t show_bluetooth(struct device *dev,
  877. struct device_attribute *attr, char *buf)
  878. {
  879. struct asus_laptop *asus = dev_get_drvdata(dev);
  880. return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
  881. }
  882. static ssize_t store_bluetooth(struct device *dev,
  883. struct device_attribute *attr, const char *buf,
  884. size_t count)
  885. {
  886. struct asus_laptop *asus = dev_get_drvdata(dev);
  887. return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
  888. }
  889. /*
  890. * Wimax
  891. */
  892. static int asus_wimax_set(struct asus_laptop *asus, int status)
  893. {
  894. if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
  895. pr_warn("Error setting wimax status to %d\n", status);
  896. return -EIO;
  897. }
  898. return 0;
  899. }
  900. static ssize_t show_wimax(struct device *dev,
  901. struct device_attribute *attr, char *buf)
  902. {
  903. struct asus_laptop *asus = dev_get_drvdata(dev);
  904. return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
  905. }
  906. static ssize_t store_wimax(struct device *dev,
  907. struct device_attribute *attr, const char *buf,
  908. size_t count)
  909. {
  910. struct asus_laptop *asus = dev_get_drvdata(dev);
  911. return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
  912. }
  913. /*
  914. * Wwan
  915. */
  916. static int asus_wwan_set(struct asus_laptop *asus, int status)
  917. {
  918. if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
  919. pr_warn("Error setting wwan status to %d\n", status);
  920. return -EIO;
  921. }
  922. return 0;
  923. }
  924. static ssize_t show_wwan(struct device *dev,
  925. struct device_attribute *attr, char *buf)
  926. {
  927. struct asus_laptop *asus = dev_get_drvdata(dev);
  928. return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
  929. }
  930. static ssize_t store_wwan(struct device *dev,
  931. struct device_attribute *attr, const char *buf,
  932. size_t count)
  933. {
  934. struct asus_laptop *asus = dev_get_drvdata(dev);
  935. return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
  936. }
  937. /*
  938. * Display
  939. */
  940. static void asus_set_display(struct asus_laptop *asus, int value)
  941. {
  942. /* no sanity check needed for now */
  943. if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
  944. pr_warn("Error setting display\n");
  945. return;
  946. }
  947. /*
  948. * Experimental support for display switching. As of now: 1 should activate
  949. * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
  950. * Any combination (bitwise) of these will suffice. I never actually tested 4
  951. * displays hooked up simultaneously, so be warned. See the acpi4asus README
  952. * for more info.
  953. */
  954. static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
  955. const char *buf, size_t count)
  956. {
  957. struct asus_laptop *asus = dev_get_drvdata(dev);
  958. int rv, value;
  959. rv = parse_arg(buf, count, &value);
  960. if (rv > 0)
  961. asus_set_display(asus, value);
  962. return rv;
  963. }
  964. /*
  965. * Light Sens
  966. */
  967. static void asus_als_switch(struct asus_laptop *asus, int value)
  968. {
  969. int ret;
  970. if (asus->is_pega_lucid) {
  971. ret = asus_pega_lucid_set(asus, PEGA_ALS, value);
  972. if (!ret)
  973. ret = asus_pega_lucid_set(asus, PEGA_ALS_POWER, value);
  974. } else {
  975. ret = write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value);
  976. }
  977. if (ret)
  978. pr_warning("Error setting light sensor switch\n");
  979. asus->light_switch = value;
  980. }
  981. static ssize_t show_lssw(struct device *dev,
  982. struct device_attribute *attr, char *buf)
  983. {
  984. struct asus_laptop *asus = dev_get_drvdata(dev);
  985. return sprintf(buf, "%d\n", asus->light_switch);
  986. }
  987. static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
  988. const char *buf, size_t count)
  989. {
  990. struct asus_laptop *asus = dev_get_drvdata(dev);
  991. int rv, value;
  992. rv = parse_arg(buf, count, &value);
  993. if (rv > 0)
  994. asus_als_switch(asus, value ? 1 : 0);
  995. return rv;
  996. }
  997. static void asus_als_level(struct asus_laptop *asus, int value)
  998. {
  999. if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
  1000. pr_warn("Error setting light sensor level\n");
  1001. asus->light_level = value;
  1002. }
  1003. static ssize_t show_lslvl(struct device *dev,
  1004. struct device_attribute *attr, char *buf)
  1005. {
  1006. struct asus_laptop *asus = dev_get_drvdata(dev);
  1007. return sprintf(buf, "%d\n", asus->light_level);
  1008. }
  1009. static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
  1010. const char *buf, size_t count)
  1011. {
  1012. struct asus_laptop *asus = dev_get_drvdata(dev);
  1013. int rv, value;
  1014. rv = parse_arg(buf, count, &value);
  1015. if (rv > 0) {
  1016. value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
  1017. /* 0 <= value <= 15 */
  1018. asus_als_level(asus, value);
  1019. }
  1020. return rv;
  1021. }
  1022. static int pega_int_read(struct asus_laptop *asus, int arg, int *result)
  1023. {
  1024. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1025. int err = write_acpi_int_ret(asus->handle, METHOD_PEGA_READ, arg,
  1026. &buffer);
  1027. if (!err) {
  1028. union acpi_object *obj = buffer.pointer;
  1029. if (obj && obj->type == ACPI_TYPE_INTEGER)
  1030. *result = obj->integer.value;
  1031. else
  1032. err = -EIO;
  1033. }
  1034. return err;
  1035. }
  1036. static ssize_t show_lsvalue(struct device *dev,
  1037. struct device_attribute *attr, char *buf)
  1038. {
  1039. struct asus_laptop *asus = dev_get_drvdata(dev);
  1040. int err, hi, lo;
  1041. err = pega_int_read(asus, PEGA_READ_ALS_H, &hi);
  1042. if (!err)
  1043. err = pega_int_read(asus, PEGA_READ_ALS_L, &lo);
  1044. if (!err)
  1045. return sprintf(buf, "%d\n", 10 * hi + lo);
  1046. return err;
  1047. }
  1048. /*
  1049. * GPS
  1050. */
  1051. static int asus_gps_status(struct asus_laptop *asus)
  1052. {
  1053. unsigned long long status;
  1054. acpi_status rv = AE_OK;
  1055. rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
  1056. NULL, &status);
  1057. if (ACPI_FAILURE(rv)) {
  1058. pr_warn("Error reading GPS status\n");
  1059. return -ENODEV;
  1060. }
  1061. return !!status;
  1062. }
  1063. static int asus_gps_switch(struct asus_laptop *asus, int status)
  1064. {
  1065. const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
  1066. if (write_acpi_int(asus->handle, meth, 0x02))
  1067. return -ENODEV;
  1068. return 0;
  1069. }
  1070. static ssize_t show_gps(struct device *dev,
  1071. struct device_attribute *attr, char *buf)
  1072. {
  1073. struct asus_laptop *asus = dev_get_drvdata(dev);
  1074. return sprintf(buf, "%d\n", asus_gps_status(asus));
  1075. }
  1076. static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
  1077. const char *buf, size_t count)
  1078. {
  1079. struct asus_laptop *asus = dev_get_drvdata(dev);
  1080. int rv, value;
  1081. int ret;
  1082. rv = parse_arg(buf, count, &value);
  1083. if (rv <= 0)
  1084. return -EINVAL;
  1085. ret = asus_gps_switch(asus, !!value);
  1086. if (ret)
  1087. return ret;
  1088. rfkill_set_sw_state(asus->gps.rfkill, !value);
  1089. return rv;
  1090. }
  1091. /*
  1092. * rfkill
  1093. */
  1094. static int asus_gps_rfkill_set(void *data, bool blocked)
  1095. {
  1096. struct asus_laptop *asus = data;
  1097. return asus_gps_switch(asus, !blocked);
  1098. }
  1099. static const struct rfkill_ops asus_gps_rfkill_ops = {
  1100. .set_block = asus_gps_rfkill_set,
  1101. };
  1102. static int asus_rfkill_set(void *data, bool blocked)
  1103. {
  1104. struct asus_rfkill *rfk = data;
  1105. struct asus_laptop *asus = rfk->asus;
  1106. if (rfk->control_id == WL_RSTS)
  1107. return asus_wlan_set(asus, !blocked);
  1108. else if (rfk->control_id == BT_RSTS)
  1109. return asus_bluetooth_set(asus, !blocked);
  1110. else if (rfk->control_id == WM_RSTS)
  1111. return asus_wimax_set(asus, !blocked);
  1112. else if (rfk->control_id == WW_RSTS)
  1113. return asus_wwan_set(asus, !blocked);
  1114. return -EINVAL;
  1115. }
  1116. static const struct rfkill_ops asus_rfkill_ops = {
  1117. .set_block = asus_rfkill_set,
  1118. };
  1119. static void asus_rfkill_terminate(struct asus_rfkill *rfk)
  1120. {
  1121. if (!rfk->rfkill)
  1122. return ;
  1123. rfkill_unregister(rfk->rfkill);
  1124. rfkill_destroy(rfk->rfkill);
  1125. rfk->rfkill = NULL;
  1126. }
  1127. static void asus_rfkill_exit(struct asus_laptop *asus)
  1128. {
  1129. asus_rfkill_terminate(&asus->wwan);
  1130. asus_rfkill_terminate(&asus->bluetooth);
  1131. asus_rfkill_terminate(&asus->wlan);
  1132. asus_rfkill_terminate(&asus->gps);
  1133. }
  1134. static int asus_rfkill_setup(struct asus_laptop *asus, struct asus_rfkill *rfk,
  1135. const char *name, int control_id, int type,
  1136. const struct rfkill_ops *ops)
  1137. {
  1138. int result;
  1139. rfk->control_id = control_id;
  1140. rfk->asus = asus;
  1141. rfk->rfkill = rfkill_alloc(name, &asus->platform_device->dev,
  1142. type, ops, rfk);
  1143. if (!rfk->rfkill)
  1144. return -EINVAL;
  1145. result = rfkill_register(rfk->rfkill);
  1146. if (result) {
  1147. rfkill_destroy(rfk->rfkill);
  1148. rfk->rfkill = NULL;
  1149. }
  1150. return result;
  1151. }
  1152. static int asus_rfkill_init(struct asus_laptop *asus)
  1153. {
  1154. int result = 0;
  1155. if (asus->is_pega_lucid)
  1156. return -ENODEV;
  1157. if (!acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) &&
  1158. !acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) &&
  1159. !acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
  1160. result = asus_rfkill_setup(asus, &asus->gps, "asus-gps",
  1161. -1, RFKILL_TYPE_GPS,
  1162. &asus_gps_rfkill_ops);
  1163. if (result)
  1164. goto exit;
  1165. if (!acpi_check_handle(asus->handle, METHOD_WLAN, NULL) &&
  1166. asus->wled_type == TYPE_RFKILL)
  1167. result = asus_rfkill_setup(asus, &asus->wlan, "asus-wlan",
  1168. WL_RSTS, RFKILL_TYPE_WLAN,
  1169. &asus_rfkill_ops);
  1170. if (result)
  1171. goto exit;
  1172. if (!acpi_check_handle(asus->handle, METHOD_BLUETOOTH, NULL) &&
  1173. asus->bled_type == TYPE_RFKILL)
  1174. result = asus_rfkill_setup(asus, &asus->bluetooth,
  1175. "asus-bluetooth", BT_RSTS,
  1176. RFKILL_TYPE_BLUETOOTH,
  1177. &asus_rfkill_ops);
  1178. if (result)
  1179. goto exit;
  1180. if (!acpi_check_handle(asus->handle, METHOD_WWAN, NULL))
  1181. result = asus_rfkill_setup(asus, &asus->wwan, "asus-wwan",
  1182. WW_RSTS, RFKILL_TYPE_WWAN,
  1183. &asus_rfkill_ops);
  1184. if (result)
  1185. goto exit;
  1186. if (!acpi_check_handle(asus->handle, METHOD_WIMAX, NULL))
  1187. result = asus_rfkill_setup(asus, &asus->wimax, "asus-wimax",
  1188. WM_RSTS, RFKILL_TYPE_WIMAX,
  1189. &asus_rfkill_ops);
  1190. if (result)
  1191. goto exit;
  1192. exit:
  1193. if (result)
  1194. asus_rfkill_exit(asus);
  1195. return result;
  1196. }
  1197. static int pega_rfkill_set(void *data, bool blocked)
  1198. {
  1199. struct asus_rfkill *rfk = data;
  1200. int ret = asus_pega_lucid_set(rfk->asus, rfk->control_id, !blocked);
  1201. return ret;
  1202. }
  1203. static const struct rfkill_ops pega_rfkill_ops = {
  1204. .set_block = pega_rfkill_set,
  1205. };
  1206. static int pega_rfkill_setup(struct asus_laptop *asus, struct asus_rfkill *rfk,
  1207. const char *name, int controlid, int rfkill_type)
  1208. {
  1209. return asus_rfkill_setup(asus, rfk, name, controlid, rfkill_type,
  1210. &pega_rfkill_ops);
  1211. }
  1212. static int pega_rfkill_init(struct asus_laptop *asus)
  1213. {
  1214. int ret = 0;
  1215. if(!asus->is_pega_lucid)
  1216. return -ENODEV;
  1217. ret = pega_rfkill_setup(asus, &asus->wlan, "pega-wlan",
  1218. PEGA_WLAN, RFKILL_TYPE_WLAN);
  1219. if(ret)
  1220. goto exit;
  1221. ret = pega_rfkill_setup(asus, &asus->bluetooth, "pega-bt",
  1222. PEGA_BLUETOOTH, RFKILL_TYPE_BLUETOOTH);
  1223. if(ret)
  1224. goto exit;
  1225. ret = pega_rfkill_setup(asus, &asus->wwan, "pega-wwan",
  1226. PEGA_WWAN, RFKILL_TYPE_WWAN);
  1227. exit:
  1228. if (ret)
  1229. asus_rfkill_exit(asus);
  1230. return ret;
  1231. }
  1232. /*
  1233. * Input device (i.e. hotkeys)
  1234. */
  1235. static void asus_input_notify(struct asus_laptop *asus, int event)
  1236. {
  1237. if (!asus->inputdev)
  1238. return ;
  1239. if (!sparse_keymap_report_event(asus->inputdev, event, 1, true))
  1240. pr_info("Unknown key %x pressed\n", event);
  1241. }
  1242. static int asus_input_init(struct asus_laptop *asus)
  1243. {
  1244. struct input_dev *input;
  1245. int error;
  1246. input = input_allocate_device();
  1247. if (!input) {
  1248. pr_warn("Unable to allocate input device\n");
  1249. return -ENOMEM;
  1250. }
  1251. input->name = "Asus Laptop extra buttons";
  1252. input->phys = ASUS_LAPTOP_FILE "/input0";
  1253. input->id.bustype = BUS_HOST;
  1254. input->dev.parent = &asus->platform_device->dev;
  1255. error = sparse_keymap_setup(input, asus_keymap, NULL);
  1256. if (error) {
  1257. pr_err("Unable to setup input device keymap\n");
  1258. goto err_free_dev;
  1259. }
  1260. error = input_register_device(input);
  1261. if (error) {
  1262. pr_warn("Unable to register input device\n");
  1263. goto err_free_keymap;
  1264. }
  1265. asus->inputdev = input;
  1266. return 0;
  1267. err_free_keymap:
  1268. sparse_keymap_free(input);
  1269. err_free_dev:
  1270. input_free_device(input);
  1271. return error;
  1272. }
  1273. static void asus_input_exit(struct asus_laptop *asus)
  1274. {
  1275. if (asus->inputdev) {
  1276. sparse_keymap_free(asus->inputdev);
  1277. input_unregister_device(asus->inputdev);
  1278. }
  1279. asus->inputdev = NULL;
  1280. }
  1281. /*
  1282. * ACPI driver
  1283. */
  1284. static void asus_acpi_notify(struct acpi_device *device, u32 event)
  1285. {
  1286. struct asus_laptop *asus = acpi_driver_data(device);
  1287. u16 count;
  1288. /* TODO Find a better way to handle events count. */
  1289. count = asus->event_count[event % 128]++;
  1290. acpi_bus_generate_proc_event(asus->device, event, count);
  1291. acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
  1292. dev_name(&asus->device->dev), event,
  1293. count);
  1294. /* Brightness events are special */
  1295. if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
  1296. /* Ignore them completely if the acpi video driver is used */
  1297. if (asus->backlight_device != NULL) {
  1298. /* Update the backlight device. */
  1299. asus_backlight_notify(asus);
  1300. }
  1301. return ;
  1302. }
  1303. /* Accelerometer "coarse orientation change" event */
  1304. if (asus->pega_accel_poll && event == 0xEA) {
  1305. kobject_uevent(&asus->pega_accel_poll->input->dev.kobj,
  1306. KOBJ_CHANGE);
  1307. return ;
  1308. }
  1309. asus_input_notify(asus, event);
  1310. }
  1311. static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
  1312. static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
  1313. static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
  1314. show_bluetooth, store_bluetooth);
  1315. static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
  1316. static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
  1317. static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
  1318. static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
  1319. static DEVICE_ATTR(ls_value, S_IRUGO, show_lsvalue, NULL);
  1320. static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
  1321. static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
  1322. static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
  1323. static struct attribute *asus_attributes[] = {
  1324. &dev_attr_infos.attr,
  1325. &dev_attr_wlan.attr,
  1326. &dev_attr_bluetooth.attr,
  1327. &dev_attr_wimax.attr,
  1328. &dev_attr_wwan.attr,
  1329. &dev_attr_display.attr,
  1330. &dev_attr_ledd.attr,
  1331. &dev_attr_ls_value.attr,
  1332. &dev_attr_ls_level.attr,
  1333. &dev_attr_ls_switch.attr,
  1334. &dev_attr_gps.attr,
  1335. NULL
  1336. };
  1337. static umode_t asus_sysfs_is_visible(struct kobject *kobj,
  1338. struct attribute *attr,
  1339. int idx)
  1340. {
  1341. struct device *dev = container_of(kobj, struct device, kobj);
  1342. struct platform_device *pdev = to_platform_device(dev);
  1343. struct asus_laptop *asus = platform_get_drvdata(pdev);
  1344. acpi_handle handle = asus->handle;
  1345. bool supported;
  1346. if (asus->is_pega_lucid) {
  1347. /* no ls_level interface on the Lucid */
  1348. if (attr == &dev_attr_ls_switch.attr)
  1349. supported = true;
  1350. else if (attr == &dev_attr_ls_level.attr)
  1351. supported = false;
  1352. else
  1353. goto normal;
  1354. return supported;
  1355. }
  1356. normal:
  1357. if (attr == &dev_attr_wlan.attr) {
  1358. supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
  1359. } else if (attr == &dev_attr_bluetooth.attr) {
  1360. supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
  1361. } else if (attr == &dev_attr_display.attr) {
  1362. supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
  1363. } else if (attr == &dev_attr_wimax.attr) {
  1364. supported =
  1365. !acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
  1366. } else if (attr == &dev_attr_wwan.attr) {
  1367. supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
  1368. } else if (attr == &dev_attr_ledd.attr) {
  1369. supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
  1370. } else if (attr == &dev_attr_ls_switch.attr ||
  1371. attr == &dev_attr_ls_level.attr) {
  1372. supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
  1373. !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
  1374. } else if (attr == &dev_attr_ls_value.attr) {
  1375. supported = asus->is_pega_lucid;
  1376. } else if (attr == &dev_attr_gps.attr) {
  1377. supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
  1378. !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
  1379. !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
  1380. } else {
  1381. supported = true;
  1382. }
  1383. return supported ? attr->mode : 0;
  1384. }
  1385. static const struct attribute_group asus_attr_group = {
  1386. .is_visible = asus_sysfs_is_visible,
  1387. .attrs = asus_attributes,
  1388. };
  1389. static int asus_platform_init(struct asus_laptop *asus)
  1390. {
  1391. int result;
  1392. asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
  1393. if (!asus->platform_device)
  1394. return -ENOMEM;
  1395. platform_set_drvdata(asus->platform_device, asus);
  1396. result = platform_device_add(asus->platform_device);
  1397. if (result)
  1398. goto fail_platform_device;
  1399. result = sysfs_create_group(&asus->platform_device->dev.kobj,
  1400. &asus_attr_group);
  1401. if (result)
  1402. goto fail_sysfs;
  1403. return 0;
  1404. fail_sysfs:
  1405. platform_device_del(asus->platform_device);
  1406. fail_platform_device:
  1407. platform_device_put(asus->platform_device);
  1408. return result;
  1409. }
  1410. static void asus_platform_exit(struct asus_laptop *asus)
  1411. {
  1412. sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
  1413. platform_device_unregister(asus->platform_device);
  1414. }
  1415. static struct platform_driver platform_driver = {
  1416. .driver = {
  1417. .name = ASUS_LAPTOP_FILE,
  1418. .owner = THIS_MODULE,
  1419. },
  1420. };
  1421. /*
  1422. * This function is used to initialize the context with right values. In this
  1423. * method, we can make all the detection we want, and modify the asus_laptop
  1424. * struct
  1425. */
  1426. static int asus_laptop_get_info(struct asus_laptop *asus)
  1427. {
  1428. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1429. union acpi_object *model = NULL;
  1430. unsigned long long bsts_result, hwrs_result;
  1431. char *string = NULL;
  1432. acpi_status status;
  1433. /*
  1434. * Get DSDT headers early enough to allow for differentiating between
  1435. * models, but late enough to allow acpi_bus_register_driver() to fail
  1436. * before doing anything ACPI-specific. Should we encounter a machine,
  1437. * which needs special handling (i.e. its hotkey device has a different
  1438. * HID), this bit will be moved.
  1439. */
  1440. status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
  1441. if (ACPI_FAILURE(status))
  1442. pr_warn("Couldn't get the DSDT table header\n");
  1443. /* We have to write 0 on init this far for all ASUS models */
  1444. if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
  1445. pr_err("Hotkey initialization failed\n");
  1446. return -ENODEV;
  1447. }
  1448. /* This needs to be called for some laptops to init properly */
  1449. status =
  1450. acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
  1451. if (ACPI_FAILURE(status))
  1452. pr_warn("Error calling BSTS\n");
  1453. else if (bsts_result)
  1454. pr_notice("BSTS called, 0x%02x returned\n",
  1455. (uint) bsts_result);
  1456. /* This too ... */
  1457. if (write_acpi_int(asus->handle, "CWAP", wapf))
  1458. pr_err("Error calling CWAP(%d)\n", wapf);
  1459. /*
  1460. * Try to match the object returned by INIT to the specific model.
  1461. * Handle every possible object (or the lack of thereof) the DSDT
  1462. * writers might throw at us. When in trouble, we pass NULL to
  1463. * asus_model_match() and try something completely different.
  1464. */
  1465. if (buffer.pointer) {
  1466. model = buffer.pointer;
  1467. switch (model->type) {
  1468. case ACPI_TYPE_STRING:
  1469. string = model->string.pointer;
  1470. break;
  1471. case ACPI_TYPE_BUFFER:
  1472. string = model->buffer.pointer;
  1473. break;
  1474. default:
  1475. string = "";
  1476. break;
  1477. }
  1478. }
  1479. asus->name = kstrdup(string, GFP_KERNEL);
  1480. if (!asus->name) {
  1481. kfree(buffer.pointer);
  1482. return -ENOMEM;
  1483. }
  1484. if (*string)
  1485. pr_notice(" %s model detected\n", string);
  1486. /*
  1487. * The HWRS method return informations about the hardware.
  1488. * 0x80 bit is for WLAN, 0x100 for Bluetooth,
  1489. * 0x40 for WWAN, 0x10 for WIMAX.
  1490. * The significance of others is yet to be found.
  1491. */
  1492. status =
  1493. acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
  1494. if (!ACPI_FAILURE(status))
  1495. pr_notice(" HRWS returned %x", (int)hwrs_result);
  1496. if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
  1497. asus->have_rsts = true;
  1498. kfree(model);
  1499. return AE_OK;
  1500. }
  1501. static int __devinit asus_acpi_init(struct asus_laptop *asus)
  1502. {
  1503. int result = 0;
  1504. result = acpi_bus_get_status(asus->device);
  1505. if (result)
  1506. return result;
  1507. if (!asus->device->status.present) {
  1508. pr_err("Hotkey device not present, aborting\n");
  1509. return -ENODEV;
  1510. }
  1511. result = asus_laptop_get_info(asus);
  1512. if (result)
  1513. return result;
  1514. if (!strcmp(bled_type, "led"))
  1515. asus->bled_type = TYPE_LED;
  1516. else if (!strcmp(bled_type, "rfkill"))
  1517. asus->bled_type = TYPE_RFKILL;
  1518. if (!strcmp(wled_type, "led"))
  1519. asus->wled_type = TYPE_LED;
  1520. else if (!strcmp(wled_type, "rfkill"))
  1521. asus->wled_type = TYPE_RFKILL;
  1522. if (bluetooth_status >= 0)
  1523. asus_bluetooth_set(asus, !!bluetooth_status);
  1524. if (wlan_status >= 0)
  1525. asus_wlan_set(asus, !!wlan_status);
  1526. if (wimax_status >= 0)
  1527. asus_wimax_set(asus, !!wimax_status);
  1528. if (wwan_status >= 0)
  1529. asus_wwan_set(asus, !!wwan_status);
  1530. /* Keyboard Backlight is on by default */
  1531. if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
  1532. asus_kled_set(asus, 1);
  1533. /* LED display is off by default */
  1534. asus->ledd_status = 0xFFF;
  1535. /* Set initial values of light sensor and level */
  1536. asus->light_switch = !!als_status;
  1537. asus->light_level = 5; /* level 5 for sensor sensitivity */
  1538. if (asus->is_pega_lucid) {
  1539. asus_als_switch(asus, asus->light_switch);
  1540. } else if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
  1541. !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
  1542. asus_als_switch(asus, asus->light_switch);
  1543. asus_als_level(asus, asus->light_level);
  1544. }
  1545. return result;
  1546. }
  1547. static void __devinit asus_dmi_check(void)
  1548. {
  1549. const char *model;
  1550. model = dmi_get_system_info(DMI_PRODUCT_NAME);
  1551. if (!model)
  1552. return;
  1553. /* On L1400B WLED control the sound card, don't mess with it ... */
  1554. if (strncmp(model, "L1400B", 6) == 0) {
  1555. wlan_status = -1;
  1556. }
  1557. }
  1558. static bool asus_device_present;
  1559. static int __devinit asus_acpi_add(struct acpi_device *device)
  1560. {
  1561. struct asus_laptop *asus;
  1562. int result;
  1563. pr_notice("Asus Laptop Support version %s\n",
  1564. ASUS_LAPTOP_VERSION);
  1565. asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
  1566. if (!asus)
  1567. return -ENOMEM;
  1568. asus->handle = device->handle;
  1569. strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
  1570. strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
  1571. device->driver_data = asus;
  1572. asus->device = device;
  1573. asus_dmi_check();
  1574. result = asus_acpi_init(asus);
  1575. if (result)
  1576. goto fail_platform;
  1577. /*
  1578. * Need platform type detection first, then the platform
  1579. * device. It is used as a parent for the sub-devices below.
  1580. */
  1581. asus->is_pega_lucid = asus_check_pega_lucid(asus);
  1582. result = asus_platform_init(asus);
  1583. if (result)
  1584. goto fail_platform;
  1585. if (!acpi_video_backlight_support()) {
  1586. result = asus_backlight_init(asus);
  1587. if (result)
  1588. goto fail_backlight;
  1589. } else
  1590. pr_info("Backlight controlled by ACPI video driver\n");
  1591. result = asus_input_init(asus);
  1592. if (result)
  1593. goto fail_input;
  1594. result = asus_led_init(asus);
  1595. if (result)
  1596. goto fail_led;
  1597. result = asus_rfkill_init(asus);
  1598. if (result && result != -ENODEV)
  1599. goto fail_rfkill;
  1600. result = pega_accel_init(asus);
  1601. if (result && result != -ENODEV)
  1602. goto fail_pega_accel;
  1603. result = pega_rfkill_init(asus);
  1604. if (result && result != -ENODEV)
  1605. goto fail_pega_rfkill;
  1606. asus_device_present = true;
  1607. return 0;
  1608. fail_pega_rfkill:
  1609. pega_accel_exit(asus);
  1610. fail_pega_accel:
  1611. asus_rfkill_exit(asus);
  1612. fail_rfkill:
  1613. asus_led_exit(asus);
  1614. fail_led:
  1615. asus_input_exit(asus);
  1616. fail_input:
  1617. asus_backlight_exit(asus);
  1618. fail_backlight:
  1619. asus_platform_exit(asus);
  1620. fail_platform:
  1621. kfree(asus->name);
  1622. kfree(asus);
  1623. return result;
  1624. }
  1625. static int asus_acpi_remove(struct acpi_device *device, int type)
  1626. {
  1627. struct asus_laptop *asus = acpi_driver_data(device);
  1628. asus_backlight_exit(asus);
  1629. asus_rfkill_exit(asus);
  1630. asus_led_exit(asus);
  1631. asus_input_exit(asus);
  1632. pega_accel_exit(asus);
  1633. asus_platform_exit(asus);
  1634. kfree(asus->name);
  1635. kfree(asus);
  1636. return 0;
  1637. }
  1638. static const struct acpi_device_id asus_device_ids[] = {
  1639. {"ATK0100", 0},
  1640. {"ATK0101", 0},
  1641. {"", 0},
  1642. };
  1643. MODULE_DEVICE_TABLE(acpi, asus_device_ids);
  1644. static struct acpi_driver asus_acpi_driver = {
  1645. .name = ASUS_LAPTOP_NAME,
  1646. .class = ASUS_LAPTOP_CLASS,
  1647. .owner = THIS_MODULE,
  1648. .ids = asus_device_ids,
  1649. .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
  1650. .ops = {
  1651. .add = asus_acpi_add,
  1652. .remove = asus_acpi_remove,
  1653. .notify = asus_acpi_notify,
  1654. },
  1655. };
  1656. static int __init asus_laptop_init(void)
  1657. {
  1658. int result;
  1659. result = platform_driver_register(&platform_driver);
  1660. if (result < 0)
  1661. return result;
  1662. result = acpi_bus_register_driver(&asus_acpi_driver);
  1663. if (result < 0)
  1664. goto fail_acpi_driver;
  1665. if (!asus_device_present) {
  1666. result = -ENODEV;
  1667. goto fail_no_device;
  1668. }
  1669. return 0;
  1670. fail_no_device:
  1671. acpi_bus_unregister_driver(&asus_acpi_driver);
  1672. fail_acpi_driver:
  1673. platform_driver_unregister(&platform_driver);
  1674. return result;
  1675. }
  1676. static void __exit asus_laptop_exit(void)
  1677. {
  1678. acpi_bus_unregister_driver(&asus_acpi_driver);
  1679. platform_driver_unregister(&platform_driver);
  1680. }
  1681. module_init(asus_laptop_init);
  1682. module_exit(asus_laptop_exit);