asus-laptop.c 52 KB

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