asus-laptop.c 51 KB

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