asus-laptop.c 53 KB

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