asus-laptop.c 52 KB

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