asus-laptop.c 52 KB

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