asus-laptop.c 52 KB

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