eeepc-laptop.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * eeepc-laptop.c - Asus Eee PC extras
  4. *
  5. * Based on asus_acpi.c as patched for the Eee PC by Asus:
  6. * ftp://ftp.asus.com/pub/ASUS/EeePC/701/ASUS_ACPI_071126.rar
  7. * Based on eee.c from eeepc-linux
  8. */
  9. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/types.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/backlight.h>
  16. #include <linux/fb.h>
  17. #include <linux/hwmon.h>
  18. #include <linux/hwmon-sysfs.h>
  19. #include <linux/slab.h>
  20. #include <linux/acpi.h>
  21. #include <linux/uaccess.h>
  22. #include <linux/input.h>
  23. #include <linux/input/sparse-keymap.h>
  24. #include <linux/rfkill.h>
  25. #include <linux/pci.h>
  26. #include <linux/pci_hotplug.h>
  27. #include <linux/leds.h>
  28. #include <linux/dmi.h>
  29. #include <acpi/video.h>
  30. #define EEEPC_LAPTOP_VERSION "0.1"
  31. #define EEEPC_LAPTOP_NAME "Eee PC Hotkey Driver"
  32. #define EEEPC_LAPTOP_FILE "eeepc"
  33. #define EEEPC_ACPI_CLASS "hotkey"
  34. #define EEEPC_ACPI_DEVICE_NAME "Hotkey"
  35. #define EEEPC_ACPI_HID "ASUS010"
  36. MODULE_AUTHOR("Corentin Chary, Eric Cooper");
  37. MODULE_DESCRIPTION(EEEPC_LAPTOP_NAME);
  38. MODULE_LICENSE("GPL");
  39. static bool hotplug_disabled;
  40. module_param(hotplug_disabled, bool, 0444);
  41. MODULE_PARM_DESC(hotplug_disabled,
  42. "Disable hotplug for wireless device. "
  43. "If your laptop need that, please report to "
  44. "[email protected].");
  45. /*
  46. * Definitions for Asus EeePC
  47. */
  48. #define NOTIFY_BRN_MIN 0x20
  49. #define NOTIFY_BRN_MAX 0x2f
  50. enum {
  51. DISABLE_ASL_WLAN = 0x0001,
  52. DISABLE_ASL_BLUETOOTH = 0x0002,
  53. DISABLE_ASL_IRDA = 0x0004,
  54. DISABLE_ASL_CAMERA = 0x0008,
  55. DISABLE_ASL_TV = 0x0010,
  56. DISABLE_ASL_GPS = 0x0020,
  57. DISABLE_ASL_DISPLAYSWITCH = 0x0040,
  58. DISABLE_ASL_MODEM = 0x0080,
  59. DISABLE_ASL_CARDREADER = 0x0100,
  60. DISABLE_ASL_3G = 0x0200,
  61. DISABLE_ASL_WIMAX = 0x0400,
  62. DISABLE_ASL_HWCF = 0x0800
  63. };
  64. enum {
  65. CM_ASL_WLAN = 0,
  66. CM_ASL_BLUETOOTH,
  67. CM_ASL_IRDA,
  68. CM_ASL_1394,
  69. CM_ASL_CAMERA,
  70. CM_ASL_TV,
  71. CM_ASL_GPS,
  72. CM_ASL_DVDROM,
  73. CM_ASL_DISPLAYSWITCH,
  74. CM_ASL_PANELBRIGHT,
  75. CM_ASL_BIOSFLASH,
  76. CM_ASL_ACPIFLASH,
  77. CM_ASL_CPUFV,
  78. CM_ASL_CPUTEMPERATURE,
  79. CM_ASL_FANCPU,
  80. CM_ASL_FANCHASSIS,
  81. CM_ASL_USBPORT1,
  82. CM_ASL_USBPORT2,
  83. CM_ASL_USBPORT3,
  84. CM_ASL_MODEM,
  85. CM_ASL_CARDREADER,
  86. CM_ASL_3G,
  87. CM_ASL_WIMAX,
  88. CM_ASL_HWCF,
  89. CM_ASL_LID,
  90. CM_ASL_TYPE,
  91. CM_ASL_PANELPOWER, /*P901*/
  92. CM_ASL_TPD
  93. };
  94. static const char *cm_getv[] = {
  95. "WLDG", "BTHG", NULL, NULL,
  96. "CAMG", NULL, NULL, NULL,
  97. NULL, "PBLG", NULL, NULL,
  98. "CFVG", NULL, NULL, NULL,
  99. "USBG", NULL, NULL, "MODG",
  100. "CRDG", "M3GG", "WIMG", "HWCF",
  101. "LIDG", "TYPE", "PBPG", "TPDG"
  102. };
  103. static const char *cm_setv[] = {
  104. "WLDS", "BTHS", NULL, NULL,
  105. "CAMS", NULL, NULL, NULL,
  106. "SDSP", "PBLS", "HDPS", NULL,
  107. "CFVS", NULL, NULL, NULL,
  108. "USBG", NULL, NULL, "MODS",
  109. "CRDS", "M3GS", "WIMS", NULL,
  110. NULL, NULL, "PBPS", "TPDS"
  111. };
  112. static const struct key_entry eeepc_keymap[] = {
  113. { KE_KEY, 0x10, { KEY_WLAN } },
  114. { KE_KEY, 0x11, { KEY_WLAN } },
  115. { KE_KEY, 0x12, { KEY_PROG1 } },
  116. { KE_KEY, 0x13, { KEY_MUTE } },
  117. { KE_KEY, 0x14, { KEY_VOLUMEDOWN } },
  118. { KE_KEY, 0x15, { KEY_VOLUMEUP } },
  119. { KE_KEY, 0x16, { KEY_DISPLAY_OFF } },
  120. { KE_KEY, 0x1a, { KEY_COFFEE } },
  121. { KE_KEY, 0x1b, { KEY_ZOOM } },
  122. { KE_KEY, 0x1c, { KEY_PROG2 } },
  123. { KE_KEY, 0x1d, { KEY_PROG3 } },
  124. { KE_KEY, NOTIFY_BRN_MIN, { KEY_BRIGHTNESSDOWN } },
  125. { KE_KEY, NOTIFY_BRN_MAX, { KEY_BRIGHTNESSUP } },
  126. { KE_KEY, 0x30, { KEY_SWITCHVIDEOMODE } },
  127. { KE_KEY, 0x31, { KEY_SWITCHVIDEOMODE } },
  128. { KE_KEY, 0x32, { KEY_SWITCHVIDEOMODE } },
  129. { KE_KEY, 0x37, { KEY_F13 } }, /* Disable Touchpad */
  130. { KE_KEY, 0x38, { KEY_F14 } },
  131. { KE_IGNORE, 0x50, { KEY_RESERVED } }, /* AC plugged */
  132. { KE_IGNORE, 0x51, { KEY_RESERVED } }, /* AC unplugged */
  133. { KE_END, 0 },
  134. };
  135. /*
  136. * This is the main structure, we can use it to store useful information
  137. */
  138. struct eeepc_laptop {
  139. acpi_handle handle; /* the handle of the acpi device */
  140. u32 cm_supported; /* the control methods supported
  141. by this BIOS */
  142. bool cpufv_disabled;
  143. bool hotplug_disabled;
  144. u16 event_count[128]; /* count for each event */
  145. struct platform_device *platform_device;
  146. struct acpi_device *device; /* the device we are in */
  147. struct backlight_device *backlight_device;
  148. struct input_dev *inputdev;
  149. struct rfkill *wlan_rfkill;
  150. struct rfkill *bluetooth_rfkill;
  151. struct rfkill *wwan3g_rfkill;
  152. struct rfkill *wimax_rfkill;
  153. struct hotplug_slot hotplug_slot;
  154. struct mutex hotplug_lock;
  155. struct led_classdev tpd_led;
  156. int tpd_led_wk;
  157. struct workqueue_struct *led_workqueue;
  158. struct work_struct tpd_led_work;
  159. };
  160. /*
  161. * ACPI Helpers
  162. */
  163. static int write_acpi_int(acpi_handle handle, const char *method, int val)
  164. {
  165. acpi_status status;
  166. status = acpi_execute_simple_method(handle, (char *)method, val);
  167. return (status == AE_OK ? 0 : -1);
  168. }
  169. static int read_acpi_int(acpi_handle handle, const char *method, int *val)
  170. {
  171. acpi_status status;
  172. unsigned long long result;
  173. status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
  174. if (ACPI_FAILURE(status)) {
  175. *val = -1;
  176. return -1;
  177. } else {
  178. *val = result;
  179. return 0;
  180. }
  181. }
  182. static int set_acpi(struct eeepc_laptop *eeepc, int cm, int value)
  183. {
  184. const char *method = cm_setv[cm];
  185. if (method == NULL)
  186. return -ENODEV;
  187. if ((eeepc->cm_supported & (0x1 << cm)) == 0)
  188. return -ENODEV;
  189. if (write_acpi_int(eeepc->handle, method, value))
  190. pr_warn("Error writing %s\n", method);
  191. return 0;
  192. }
  193. static int get_acpi(struct eeepc_laptop *eeepc, int cm)
  194. {
  195. const char *method = cm_getv[cm];
  196. int value;
  197. if (method == NULL)
  198. return -ENODEV;
  199. if ((eeepc->cm_supported & (0x1 << cm)) == 0)
  200. return -ENODEV;
  201. if (read_acpi_int(eeepc->handle, method, &value))
  202. pr_warn("Error reading %s\n", method);
  203. return value;
  204. }
  205. static int acpi_setter_handle(struct eeepc_laptop *eeepc, int cm,
  206. acpi_handle *handle)
  207. {
  208. const char *method = cm_setv[cm];
  209. acpi_status status;
  210. if (method == NULL)
  211. return -ENODEV;
  212. if ((eeepc->cm_supported & (0x1 << cm)) == 0)
  213. return -ENODEV;
  214. status = acpi_get_handle(eeepc->handle, (char *)method,
  215. handle);
  216. if (status != AE_OK) {
  217. pr_warn("Error finding %s\n", method);
  218. return -ENODEV;
  219. }
  220. return 0;
  221. }
  222. /*
  223. * Sys helpers
  224. */
  225. static int parse_arg(const char *buf, int *val)
  226. {
  227. if (sscanf(buf, "%i", val) != 1)
  228. return -EINVAL;
  229. return 0;
  230. }
  231. static ssize_t store_sys_acpi(struct device *dev, int cm,
  232. const char *buf, size_t count)
  233. {
  234. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  235. int rv, value;
  236. rv = parse_arg(buf, &value);
  237. if (rv < 0)
  238. return rv;
  239. rv = set_acpi(eeepc, cm, value);
  240. if (rv < 0)
  241. return -EIO;
  242. return count;
  243. }
  244. static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf)
  245. {
  246. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  247. int value = get_acpi(eeepc, cm);
  248. if (value < 0)
  249. return -EIO;
  250. return sprintf(buf, "%d\n", value);
  251. }
  252. #define EEEPC_ACPI_SHOW_FUNC(_name, _cm) \
  253. static ssize_t _name##_show(struct device *dev, \
  254. struct device_attribute *attr, \
  255. char *buf) \
  256. { \
  257. return show_sys_acpi(dev, _cm, buf); \
  258. }
  259. #define EEEPC_ACPI_STORE_FUNC(_name, _cm) \
  260. static ssize_t _name##_store(struct device *dev, \
  261. struct device_attribute *attr, \
  262. const char *buf, size_t count) \
  263. { \
  264. return store_sys_acpi(dev, _cm, buf, count); \
  265. }
  266. #define EEEPC_CREATE_DEVICE_ATTR_RW(_name, _cm) \
  267. EEEPC_ACPI_SHOW_FUNC(_name, _cm) \
  268. EEEPC_ACPI_STORE_FUNC(_name, _cm) \
  269. static DEVICE_ATTR_RW(_name)
  270. #define EEEPC_CREATE_DEVICE_ATTR_WO(_name, _cm) \
  271. EEEPC_ACPI_STORE_FUNC(_name, _cm) \
  272. static DEVICE_ATTR_WO(_name)
  273. EEEPC_CREATE_DEVICE_ATTR_RW(camera, CM_ASL_CAMERA);
  274. EEEPC_CREATE_DEVICE_ATTR_RW(cardr, CM_ASL_CARDREADER);
  275. EEEPC_CREATE_DEVICE_ATTR_WO(disp, CM_ASL_DISPLAYSWITCH);
  276. struct eeepc_cpufv {
  277. int num;
  278. int cur;
  279. };
  280. static int get_cpufv(struct eeepc_laptop *eeepc, struct eeepc_cpufv *c)
  281. {
  282. c->cur = get_acpi(eeepc, CM_ASL_CPUFV);
  283. if (c->cur < 0)
  284. return -ENODEV;
  285. c->num = (c->cur >> 8) & 0xff;
  286. c->cur &= 0xff;
  287. if (c->num == 0 || c->num > 12)
  288. return -ENODEV;
  289. return 0;
  290. }
  291. static ssize_t available_cpufv_show(struct device *dev,
  292. struct device_attribute *attr,
  293. char *buf)
  294. {
  295. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  296. struct eeepc_cpufv c;
  297. int i;
  298. ssize_t len = 0;
  299. if (get_cpufv(eeepc, &c))
  300. return -ENODEV;
  301. for (i = 0; i < c.num; i++)
  302. len += sprintf(buf + len, "%d ", i);
  303. len += sprintf(buf + len, "\n");
  304. return len;
  305. }
  306. static ssize_t cpufv_show(struct device *dev,
  307. struct device_attribute *attr,
  308. char *buf)
  309. {
  310. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  311. struct eeepc_cpufv c;
  312. if (get_cpufv(eeepc, &c))
  313. return -ENODEV;
  314. return sprintf(buf, "%#x\n", (c.num << 8) | c.cur);
  315. }
  316. static ssize_t cpufv_store(struct device *dev,
  317. struct device_attribute *attr,
  318. const char *buf, size_t count)
  319. {
  320. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  321. struct eeepc_cpufv c;
  322. int rv, value;
  323. if (eeepc->cpufv_disabled)
  324. return -EPERM;
  325. if (get_cpufv(eeepc, &c))
  326. return -ENODEV;
  327. rv = parse_arg(buf, &value);
  328. if (rv < 0)
  329. return rv;
  330. if (value < 0 || value >= c.num)
  331. return -EINVAL;
  332. rv = set_acpi(eeepc, CM_ASL_CPUFV, value);
  333. if (rv)
  334. return rv;
  335. return count;
  336. }
  337. static ssize_t cpufv_disabled_show(struct device *dev,
  338. struct device_attribute *attr,
  339. char *buf)
  340. {
  341. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  342. return sprintf(buf, "%d\n", eeepc->cpufv_disabled);
  343. }
  344. static ssize_t cpufv_disabled_store(struct device *dev,
  345. struct device_attribute *attr,
  346. const char *buf, size_t count)
  347. {
  348. struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
  349. int rv, value;
  350. rv = parse_arg(buf, &value);
  351. if (rv < 0)
  352. return rv;
  353. switch (value) {
  354. case 0:
  355. if (eeepc->cpufv_disabled)
  356. pr_warn("cpufv enabled (not officially supported on this model)\n");
  357. eeepc->cpufv_disabled = false;
  358. return count;
  359. case 1:
  360. return -EPERM;
  361. default:
  362. return -EINVAL;
  363. }
  364. }
  365. static DEVICE_ATTR_RW(cpufv);
  366. static DEVICE_ATTR_RO(available_cpufv);
  367. static DEVICE_ATTR_RW(cpufv_disabled);
  368. static struct attribute *platform_attributes[] = {
  369. &dev_attr_camera.attr,
  370. &dev_attr_cardr.attr,
  371. &dev_attr_disp.attr,
  372. &dev_attr_cpufv.attr,
  373. &dev_attr_available_cpufv.attr,
  374. &dev_attr_cpufv_disabled.attr,
  375. NULL
  376. };
  377. static const struct attribute_group platform_attribute_group = {
  378. .attrs = platform_attributes
  379. };
  380. static int eeepc_platform_init(struct eeepc_laptop *eeepc)
  381. {
  382. int result;
  383. eeepc->platform_device = platform_device_alloc(EEEPC_LAPTOP_FILE, PLATFORM_DEVID_NONE);
  384. if (!eeepc->platform_device)
  385. return -ENOMEM;
  386. platform_set_drvdata(eeepc->platform_device, eeepc);
  387. result = platform_device_add(eeepc->platform_device);
  388. if (result)
  389. goto fail_platform_device;
  390. result = sysfs_create_group(&eeepc->platform_device->dev.kobj,
  391. &platform_attribute_group);
  392. if (result)
  393. goto fail_sysfs;
  394. return 0;
  395. fail_sysfs:
  396. platform_device_del(eeepc->platform_device);
  397. fail_platform_device:
  398. platform_device_put(eeepc->platform_device);
  399. return result;
  400. }
  401. static void eeepc_platform_exit(struct eeepc_laptop *eeepc)
  402. {
  403. sysfs_remove_group(&eeepc->platform_device->dev.kobj,
  404. &platform_attribute_group);
  405. platform_device_unregister(eeepc->platform_device);
  406. }
  407. /*
  408. * LEDs
  409. */
  410. /*
  411. * These functions actually update the LED's, and are called from a
  412. * workqueue. By doing this as separate work rather than when the LED
  413. * subsystem asks, we avoid messing with the Asus ACPI stuff during a
  414. * potentially bad time, such as a timer interrupt.
  415. */
  416. static void tpd_led_update(struct work_struct *work)
  417. {
  418. struct eeepc_laptop *eeepc;
  419. eeepc = container_of(work, struct eeepc_laptop, tpd_led_work);
  420. set_acpi(eeepc, CM_ASL_TPD, eeepc->tpd_led_wk);
  421. }
  422. static void tpd_led_set(struct led_classdev *led_cdev,
  423. enum led_brightness value)
  424. {
  425. struct eeepc_laptop *eeepc;
  426. eeepc = container_of(led_cdev, struct eeepc_laptop, tpd_led);
  427. eeepc->tpd_led_wk = (value > 0) ? 1 : 0;
  428. queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work);
  429. }
  430. static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
  431. {
  432. struct eeepc_laptop *eeepc;
  433. eeepc = container_of(led_cdev, struct eeepc_laptop, tpd_led);
  434. return get_acpi(eeepc, CM_ASL_TPD);
  435. }
  436. static int eeepc_led_init(struct eeepc_laptop *eeepc)
  437. {
  438. int rv;
  439. if (get_acpi(eeepc, CM_ASL_TPD) == -ENODEV)
  440. return 0;
  441. eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue");
  442. if (!eeepc->led_workqueue)
  443. return -ENOMEM;
  444. INIT_WORK(&eeepc->tpd_led_work, tpd_led_update);
  445. eeepc->tpd_led.name = "eeepc::touchpad";
  446. eeepc->tpd_led.brightness_set = tpd_led_set;
  447. if (get_acpi(eeepc, CM_ASL_TPD) >= 0) /* if method is available */
  448. eeepc->tpd_led.brightness_get = tpd_led_get;
  449. eeepc->tpd_led.max_brightness = 1;
  450. rv = led_classdev_register(&eeepc->platform_device->dev,
  451. &eeepc->tpd_led);
  452. if (rv) {
  453. destroy_workqueue(eeepc->led_workqueue);
  454. return rv;
  455. }
  456. return 0;
  457. }
  458. static void eeepc_led_exit(struct eeepc_laptop *eeepc)
  459. {
  460. led_classdev_unregister(&eeepc->tpd_led);
  461. if (eeepc->led_workqueue)
  462. destroy_workqueue(eeepc->led_workqueue);
  463. }
  464. /*
  465. * PCI hotplug (for wlan rfkill)
  466. */
  467. static bool eeepc_wlan_rfkill_blocked(struct eeepc_laptop *eeepc)
  468. {
  469. if (get_acpi(eeepc, CM_ASL_WLAN) == 1)
  470. return false;
  471. return true;
  472. }
  473. static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle)
  474. {
  475. struct pci_dev *port;
  476. struct pci_dev *dev;
  477. struct pci_bus *bus;
  478. bool blocked = eeepc_wlan_rfkill_blocked(eeepc);
  479. bool absent;
  480. u32 l;
  481. if (eeepc->wlan_rfkill)
  482. rfkill_set_sw_state(eeepc->wlan_rfkill, blocked);
  483. mutex_lock(&eeepc->hotplug_lock);
  484. pci_lock_rescan_remove();
  485. if (!eeepc->hotplug_slot.ops)
  486. goto out_unlock;
  487. port = acpi_get_pci_dev(handle);
  488. if (!port) {
  489. pr_warn("Unable to find port\n");
  490. goto out_unlock;
  491. }
  492. bus = port->subordinate;
  493. if (!bus) {
  494. pr_warn("Unable to find PCI bus 1?\n");
  495. goto out_put_dev;
  496. }
  497. if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
  498. pr_err("Unable to read PCI config space?\n");
  499. goto out_put_dev;
  500. }
  501. absent = (l == 0xffffffff);
  502. if (blocked != absent) {
  503. pr_warn("BIOS says wireless lan is %s, but the pci device is %s\n",
  504. blocked ? "blocked" : "unblocked",
  505. absent ? "absent" : "present");
  506. pr_warn("skipped wireless hotplug as probably inappropriate for this model\n");
  507. goto out_put_dev;
  508. }
  509. if (!blocked) {
  510. dev = pci_get_slot(bus, 0);
  511. if (dev) {
  512. /* Device already present */
  513. pci_dev_put(dev);
  514. goto out_put_dev;
  515. }
  516. dev = pci_scan_single_device(bus, 0);
  517. if (dev) {
  518. pci_bus_assign_resources(bus);
  519. pci_bus_add_device(dev);
  520. }
  521. } else {
  522. dev = pci_get_slot(bus, 0);
  523. if (dev) {
  524. pci_stop_and_remove_bus_device(dev);
  525. pci_dev_put(dev);
  526. }
  527. }
  528. out_put_dev:
  529. pci_dev_put(port);
  530. out_unlock:
  531. pci_unlock_rescan_remove();
  532. mutex_unlock(&eeepc->hotplug_lock);
  533. }
  534. static void eeepc_rfkill_hotplug_update(struct eeepc_laptop *eeepc, char *node)
  535. {
  536. acpi_status status = AE_OK;
  537. acpi_handle handle;
  538. status = acpi_get_handle(NULL, node, &handle);
  539. if (ACPI_SUCCESS(status))
  540. eeepc_rfkill_hotplug(eeepc, handle);
  541. }
  542. static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
  543. {
  544. struct eeepc_laptop *eeepc = data;
  545. if (event != ACPI_NOTIFY_BUS_CHECK)
  546. return;
  547. eeepc_rfkill_hotplug(eeepc, handle);
  548. }
  549. static int eeepc_register_rfkill_notifier(struct eeepc_laptop *eeepc,
  550. char *node)
  551. {
  552. acpi_status status;
  553. acpi_handle handle;
  554. status = acpi_get_handle(NULL, node, &handle);
  555. if (ACPI_FAILURE(status))
  556. return -ENODEV;
  557. status = acpi_install_notify_handler(handle,
  558. ACPI_SYSTEM_NOTIFY,
  559. eeepc_rfkill_notify,
  560. eeepc);
  561. if (ACPI_FAILURE(status))
  562. pr_warn("Failed to register notify on %s\n", node);
  563. /*
  564. * Refresh pci hotplug in case the rfkill state was
  565. * changed during setup.
  566. */
  567. eeepc_rfkill_hotplug(eeepc, handle);
  568. return 0;
  569. }
  570. static void eeepc_unregister_rfkill_notifier(struct eeepc_laptop *eeepc,
  571. char *node)
  572. {
  573. acpi_status status = AE_OK;
  574. acpi_handle handle;
  575. status = acpi_get_handle(NULL, node, &handle);
  576. if (ACPI_FAILURE(status))
  577. return;
  578. status = acpi_remove_notify_handler(handle,
  579. ACPI_SYSTEM_NOTIFY,
  580. eeepc_rfkill_notify);
  581. if (ACPI_FAILURE(status))
  582. pr_err("Error removing rfkill notify handler %s\n",
  583. node);
  584. /*
  585. * Refresh pci hotplug in case the rfkill
  586. * state was changed after
  587. * eeepc_unregister_rfkill_notifier()
  588. */
  589. eeepc_rfkill_hotplug(eeepc, handle);
  590. }
  591. static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
  592. u8 *value)
  593. {
  594. struct eeepc_laptop *eeepc;
  595. int val;
  596. eeepc = container_of(hotplug_slot, struct eeepc_laptop, hotplug_slot);
  597. val = get_acpi(eeepc, CM_ASL_WLAN);
  598. if (val == 1 || val == 0)
  599. *value = val;
  600. else
  601. return -EINVAL;
  602. return 0;
  603. }
  604. static const struct hotplug_slot_ops eeepc_hotplug_slot_ops = {
  605. .get_adapter_status = eeepc_get_adapter_status,
  606. .get_power_status = eeepc_get_adapter_status,
  607. };
  608. static int eeepc_setup_pci_hotplug(struct eeepc_laptop *eeepc)
  609. {
  610. int ret = -ENOMEM;
  611. struct pci_bus *bus = pci_find_bus(0, 1);
  612. if (!bus) {
  613. pr_err("Unable to find wifi PCI bus\n");
  614. return -ENODEV;
  615. }
  616. eeepc->hotplug_slot.ops = &eeepc_hotplug_slot_ops;
  617. ret = pci_hp_register(&eeepc->hotplug_slot, bus, 0, "eeepc-wifi");
  618. if (ret) {
  619. pr_err("Unable to register hotplug slot - %d\n", ret);
  620. goto error_register;
  621. }
  622. return 0;
  623. error_register:
  624. eeepc->hotplug_slot.ops = NULL;
  625. return ret;
  626. }
  627. /*
  628. * Rfkill devices
  629. */
  630. static int eeepc_rfkill_set(void *data, bool blocked)
  631. {
  632. acpi_handle handle = data;
  633. return write_acpi_int(handle, NULL, !blocked);
  634. }
  635. static const struct rfkill_ops eeepc_rfkill_ops = {
  636. .set_block = eeepc_rfkill_set,
  637. };
  638. static int eeepc_new_rfkill(struct eeepc_laptop *eeepc,
  639. struct rfkill **rfkill,
  640. const char *name,
  641. enum rfkill_type type, int cm)
  642. {
  643. acpi_handle handle;
  644. int result;
  645. result = acpi_setter_handle(eeepc, cm, &handle);
  646. if (result < 0)
  647. return result;
  648. *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
  649. &eeepc_rfkill_ops, handle);
  650. if (!*rfkill)
  651. return -EINVAL;
  652. rfkill_init_sw_state(*rfkill, get_acpi(eeepc, cm) != 1);
  653. result = rfkill_register(*rfkill);
  654. if (result) {
  655. rfkill_destroy(*rfkill);
  656. *rfkill = NULL;
  657. return result;
  658. }
  659. return 0;
  660. }
  661. static char EEEPC_RFKILL_NODE_1[] = "\\_SB.PCI0.P0P5";
  662. static char EEEPC_RFKILL_NODE_2[] = "\\_SB.PCI0.P0P6";
  663. static char EEEPC_RFKILL_NODE_3[] = "\\_SB.PCI0.P0P7";
  664. static void eeepc_rfkill_exit(struct eeepc_laptop *eeepc)
  665. {
  666. eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_1);
  667. eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_2);
  668. eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_3);
  669. if (eeepc->wlan_rfkill) {
  670. rfkill_unregister(eeepc->wlan_rfkill);
  671. rfkill_destroy(eeepc->wlan_rfkill);
  672. eeepc->wlan_rfkill = NULL;
  673. }
  674. if (eeepc->hotplug_slot.ops)
  675. pci_hp_deregister(&eeepc->hotplug_slot);
  676. if (eeepc->bluetooth_rfkill) {
  677. rfkill_unregister(eeepc->bluetooth_rfkill);
  678. rfkill_destroy(eeepc->bluetooth_rfkill);
  679. eeepc->bluetooth_rfkill = NULL;
  680. }
  681. if (eeepc->wwan3g_rfkill) {
  682. rfkill_unregister(eeepc->wwan3g_rfkill);
  683. rfkill_destroy(eeepc->wwan3g_rfkill);
  684. eeepc->wwan3g_rfkill = NULL;
  685. }
  686. if (eeepc->wimax_rfkill) {
  687. rfkill_unregister(eeepc->wimax_rfkill);
  688. rfkill_destroy(eeepc->wimax_rfkill);
  689. eeepc->wimax_rfkill = NULL;
  690. }
  691. }
  692. static int eeepc_rfkill_init(struct eeepc_laptop *eeepc)
  693. {
  694. int result = 0;
  695. mutex_init(&eeepc->hotplug_lock);
  696. result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill,
  697. "eeepc-wlan", RFKILL_TYPE_WLAN,
  698. CM_ASL_WLAN);
  699. if (result && result != -ENODEV)
  700. goto exit;
  701. result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill,
  702. "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH,
  703. CM_ASL_BLUETOOTH);
  704. if (result && result != -ENODEV)
  705. goto exit;
  706. result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill,
  707. "eeepc-wwan3g", RFKILL_TYPE_WWAN,
  708. CM_ASL_3G);
  709. if (result && result != -ENODEV)
  710. goto exit;
  711. result = eeepc_new_rfkill(eeepc, &eeepc->wimax_rfkill,
  712. "eeepc-wimax", RFKILL_TYPE_WIMAX,
  713. CM_ASL_WIMAX);
  714. if (result && result != -ENODEV)
  715. goto exit;
  716. if (eeepc->hotplug_disabled)
  717. return 0;
  718. result = eeepc_setup_pci_hotplug(eeepc);
  719. /*
  720. * If we get -EBUSY then something else is handling the PCI hotplug -
  721. * don't fail in this case
  722. */
  723. if (result == -EBUSY)
  724. result = 0;
  725. eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_1);
  726. eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_2);
  727. eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_3);
  728. exit:
  729. if (result && result != -ENODEV)
  730. eeepc_rfkill_exit(eeepc);
  731. return result;
  732. }
  733. /*
  734. * Platform driver - hibernate/resume callbacks
  735. */
  736. static int eeepc_hotk_thaw(struct device *device)
  737. {
  738. struct eeepc_laptop *eeepc = dev_get_drvdata(device);
  739. if (eeepc->wlan_rfkill) {
  740. int wlan;
  741. /*
  742. * Work around bios bug - acpi _PTS turns off the wireless led
  743. * during suspend. Normally it restores it on resume, but
  744. * we should kick it ourselves in case hibernation is aborted.
  745. */
  746. wlan = get_acpi(eeepc, CM_ASL_WLAN);
  747. if (wlan >= 0)
  748. set_acpi(eeepc, CM_ASL_WLAN, wlan);
  749. }
  750. return 0;
  751. }
  752. static int eeepc_hotk_restore(struct device *device)
  753. {
  754. struct eeepc_laptop *eeepc = dev_get_drvdata(device);
  755. /* Refresh both wlan rfkill state and pci hotplug */
  756. if (eeepc->wlan_rfkill) {
  757. eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_1);
  758. eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_2);
  759. eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_3);
  760. }
  761. if (eeepc->bluetooth_rfkill)
  762. rfkill_set_sw_state(eeepc->bluetooth_rfkill,
  763. get_acpi(eeepc, CM_ASL_BLUETOOTH) != 1);
  764. if (eeepc->wwan3g_rfkill)
  765. rfkill_set_sw_state(eeepc->wwan3g_rfkill,
  766. get_acpi(eeepc, CM_ASL_3G) != 1);
  767. if (eeepc->wimax_rfkill)
  768. rfkill_set_sw_state(eeepc->wimax_rfkill,
  769. get_acpi(eeepc, CM_ASL_WIMAX) != 1);
  770. return 0;
  771. }
  772. static const struct dev_pm_ops eeepc_pm_ops = {
  773. .thaw = eeepc_hotk_thaw,
  774. .restore = eeepc_hotk_restore,
  775. };
  776. static struct platform_driver platform_driver = {
  777. .driver = {
  778. .name = EEEPC_LAPTOP_FILE,
  779. .pm = &eeepc_pm_ops,
  780. }
  781. };
  782. /*
  783. * Hwmon device
  784. */
  785. #define EEEPC_EC_SC00 0x61
  786. #define EEEPC_EC_FAN_PWM (EEEPC_EC_SC00 + 2) /* Fan PWM duty cycle (%) */
  787. #define EEEPC_EC_FAN_HRPM (EEEPC_EC_SC00 + 5) /* High byte, fan speed (RPM) */
  788. #define EEEPC_EC_FAN_LRPM (EEEPC_EC_SC00 + 6) /* Low byte, fan speed (RPM) */
  789. #define EEEPC_EC_SFB0 0xD0
  790. #define EEEPC_EC_FAN_CTRL (EEEPC_EC_SFB0 + 3) /* Byte containing SF25 */
  791. static inline int eeepc_pwm_to_lmsensors(int value)
  792. {
  793. return value * 255 / 100;
  794. }
  795. static inline int eeepc_lmsensors_to_pwm(int value)
  796. {
  797. value = clamp_val(value, 0, 255);
  798. return value * 100 / 255;
  799. }
  800. static int eeepc_get_fan_pwm(void)
  801. {
  802. u8 value = 0;
  803. ec_read(EEEPC_EC_FAN_PWM, &value);
  804. return eeepc_pwm_to_lmsensors(value);
  805. }
  806. static void eeepc_set_fan_pwm(int value)
  807. {
  808. value = eeepc_lmsensors_to_pwm(value);
  809. ec_write(EEEPC_EC_FAN_PWM, value);
  810. }
  811. static int eeepc_get_fan_rpm(void)
  812. {
  813. u8 high = 0;
  814. u8 low = 0;
  815. ec_read(EEEPC_EC_FAN_HRPM, &high);
  816. ec_read(EEEPC_EC_FAN_LRPM, &low);
  817. return high << 8 | low;
  818. }
  819. #define EEEPC_EC_FAN_CTRL_BIT 0x02
  820. #define EEEPC_FAN_CTRL_MANUAL 1
  821. #define EEEPC_FAN_CTRL_AUTO 2
  822. static int eeepc_get_fan_ctrl(void)
  823. {
  824. u8 value = 0;
  825. ec_read(EEEPC_EC_FAN_CTRL, &value);
  826. if (value & EEEPC_EC_FAN_CTRL_BIT)
  827. return EEEPC_FAN_CTRL_MANUAL;
  828. else
  829. return EEEPC_FAN_CTRL_AUTO;
  830. }
  831. static void eeepc_set_fan_ctrl(int manual)
  832. {
  833. u8 value = 0;
  834. ec_read(EEEPC_EC_FAN_CTRL, &value);
  835. if (manual == EEEPC_FAN_CTRL_MANUAL)
  836. value |= EEEPC_EC_FAN_CTRL_BIT;
  837. else
  838. value &= ~EEEPC_EC_FAN_CTRL_BIT;
  839. ec_write(EEEPC_EC_FAN_CTRL, value);
  840. }
  841. static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
  842. {
  843. int rv, value;
  844. rv = parse_arg(buf, &value);
  845. if (rv < 0)
  846. return rv;
  847. set(value);
  848. return count;
  849. }
  850. static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
  851. {
  852. return sprintf(buf, "%d\n", get());
  853. }
  854. #define EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
  855. static ssize_t _name##_show(struct device *dev, \
  856. struct device_attribute *attr, \
  857. char *buf) \
  858. { \
  859. return show_sys_hwmon(_get, buf); \
  860. }
  861. #define EEEPC_SENSOR_STORE_FUNC(_name, _set) \
  862. static ssize_t _name##_store(struct device *dev, \
  863. struct device_attribute *attr, \
  864. const char *buf, size_t count) \
  865. { \
  866. return store_sys_hwmon(_set, buf, count); \
  867. }
  868. #define EEEPC_CREATE_SENSOR_ATTR_RW(_name, _get, _set) \
  869. EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
  870. EEEPC_SENSOR_STORE_FUNC(_name, _set) \
  871. static DEVICE_ATTR_RW(_name)
  872. #define EEEPC_CREATE_SENSOR_ATTR_RO(_name, _get) \
  873. EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
  874. static DEVICE_ATTR_RO(_name)
  875. EEEPC_CREATE_SENSOR_ATTR_RO(fan1_input, eeepc_get_fan_rpm);
  876. EEEPC_CREATE_SENSOR_ATTR_RW(pwm1, eeepc_get_fan_pwm,
  877. eeepc_set_fan_pwm);
  878. EEEPC_CREATE_SENSOR_ATTR_RW(pwm1_enable, eeepc_get_fan_ctrl,
  879. eeepc_set_fan_ctrl);
  880. static struct attribute *hwmon_attrs[] = {
  881. &dev_attr_pwm1.attr,
  882. &dev_attr_fan1_input.attr,
  883. &dev_attr_pwm1_enable.attr,
  884. NULL
  885. };
  886. ATTRIBUTE_GROUPS(hwmon);
  887. static int eeepc_hwmon_init(struct eeepc_laptop *eeepc)
  888. {
  889. struct device *dev = &eeepc->platform_device->dev;
  890. struct device *hwmon;
  891. hwmon = devm_hwmon_device_register_with_groups(dev, "eeepc", NULL,
  892. hwmon_groups);
  893. if (IS_ERR(hwmon)) {
  894. pr_err("Could not register eeepc hwmon device\n");
  895. return PTR_ERR(hwmon);
  896. }
  897. return 0;
  898. }
  899. /*
  900. * Backlight device
  901. */
  902. static int read_brightness(struct backlight_device *bd)
  903. {
  904. struct eeepc_laptop *eeepc = bl_get_data(bd);
  905. return get_acpi(eeepc, CM_ASL_PANELBRIGHT);
  906. }
  907. static int set_brightness(struct backlight_device *bd, int value)
  908. {
  909. struct eeepc_laptop *eeepc = bl_get_data(bd);
  910. return set_acpi(eeepc, CM_ASL_PANELBRIGHT, value);
  911. }
  912. static int update_bl_status(struct backlight_device *bd)
  913. {
  914. return set_brightness(bd, bd->props.brightness);
  915. }
  916. static const struct backlight_ops eeepcbl_ops = {
  917. .get_brightness = read_brightness,
  918. .update_status = update_bl_status,
  919. };
  920. static int eeepc_backlight_notify(struct eeepc_laptop *eeepc)
  921. {
  922. struct backlight_device *bd = eeepc->backlight_device;
  923. int old = bd->props.brightness;
  924. backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
  925. return old;
  926. }
  927. static int eeepc_backlight_init(struct eeepc_laptop *eeepc)
  928. {
  929. struct backlight_properties props;
  930. struct backlight_device *bd;
  931. memset(&props, 0, sizeof(struct backlight_properties));
  932. props.type = BACKLIGHT_PLATFORM;
  933. props.max_brightness = 15;
  934. bd = backlight_device_register(EEEPC_LAPTOP_FILE,
  935. &eeepc->platform_device->dev, eeepc,
  936. &eeepcbl_ops, &props);
  937. if (IS_ERR(bd)) {
  938. pr_err("Could not register eeepc backlight device\n");
  939. eeepc->backlight_device = NULL;
  940. return PTR_ERR(bd);
  941. }
  942. eeepc->backlight_device = bd;
  943. bd->props.brightness = read_brightness(bd);
  944. bd->props.power = FB_BLANK_UNBLANK;
  945. backlight_update_status(bd);
  946. return 0;
  947. }
  948. static void eeepc_backlight_exit(struct eeepc_laptop *eeepc)
  949. {
  950. backlight_device_unregister(eeepc->backlight_device);
  951. eeepc->backlight_device = NULL;
  952. }
  953. /*
  954. * Input device (i.e. hotkeys)
  955. */
  956. static int eeepc_input_init(struct eeepc_laptop *eeepc)
  957. {
  958. struct input_dev *input;
  959. int error;
  960. input = input_allocate_device();
  961. if (!input)
  962. return -ENOMEM;
  963. input->name = "Asus EeePC extra buttons";
  964. input->phys = EEEPC_LAPTOP_FILE "/input0";
  965. input->id.bustype = BUS_HOST;
  966. input->dev.parent = &eeepc->platform_device->dev;
  967. error = sparse_keymap_setup(input, eeepc_keymap, NULL);
  968. if (error) {
  969. pr_err("Unable to setup input device keymap\n");
  970. goto err_free_dev;
  971. }
  972. error = input_register_device(input);
  973. if (error) {
  974. pr_err("Unable to register input device\n");
  975. goto err_free_dev;
  976. }
  977. eeepc->inputdev = input;
  978. return 0;
  979. err_free_dev:
  980. input_free_device(input);
  981. return error;
  982. }
  983. static void eeepc_input_exit(struct eeepc_laptop *eeepc)
  984. {
  985. if (eeepc->inputdev)
  986. input_unregister_device(eeepc->inputdev);
  987. eeepc->inputdev = NULL;
  988. }
  989. /*
  990. * ACPI driver
  991. */
  992. static void eeepc_input_notify(struct eeepc_laptop *eeepc, int event)
  993. {
  994. if (!eeepc->inputdev)
  995. return;
  996. if (!sparse_keymap_report_event(eeepc->inputdev, event, 1, true))
  997. pr_info("Unknown key %x pressed\n", event);
  998. }
  999. static void eeepc_acpi_notify(struct acpi_device *device, u32 event)
  1000. {
  1001. struct eeepc_laptop *eeepc = acpi_driver_data(device);
  1002. int old_brightness, new_brightness;
  1003. u16 count;
  1004. if (event > ACPI_MAX_SYS_NOTIFY)
  1005. return;
  1006. count = eeepc->event_count[event % 128]++;
  1007. acpi_bus_generate_netlink_event(device->pnp.device_class,
  1008. dev_name(&device->dev), event,
  1009. count);
  1010. /* Brightness events are special */
  1011. if (event < NOTIFY_BRN_MIN || event > NOTIFY_BRN_MAX) {
  1012. eeepc_input_notify(eeepc, event);
  1013. return;
  1014. }
  1015. /* Ignore them completely if the acpi video driver is used */
  1016. if (!eeepc->backlight_device)
  1017. return;
  1018. /* Update the backlight device. */
  1019. old_brightness = eeepc_backlight_notify(eeepc);
  1020. /* Convert event to keypress (obsolescent hack) */
  1021. new_brightness = event - NOTIFY_BRN_MIN;
  1022. if (new_brightness < old_brightness) {
  1023. event = NOTIFY_BRN_MIN; /* brightness down */
  1024. } else if (new_brightness > old_brightness) {
  1025. event = NOTIFY_BRN_MAX; /* brightness up */
  1026. } else {
  1027. /*
  1028. * no change in brightness - already at min/max,
  1029. * event will be desired value (or else ignored)
  1030. */
  1031. }
  1032. eeepc_input_notify(eeepc, event);
  1033. }
  1034. static void eeepc_dmi_check(struct eeepc_laptop *eeepc)
  1035. {
  1036. const char *model;
  1037. model = dmi_get_system_info(DMI_PRODUCT_NAME);
  1038. if (!model)
  1039. return;
  1040. /*
  1041. * Blacklist for setting cpufv (cpu speed).
  1042. *
  1043. * EeePC 4G ("701") implements CFVS, but it is not supported
  1044. * by the pre-installed OS, and the original option to change it
  1045. * in the BIOS setup screen was removed in later versions.
  1046. *
  1047. * Judging by the lack of "Super Hybrid Engine" on Asus product pages,
  1048. * this applies to all "701" models (4G/4G Surf/2G Surf).
  1049. *
  1050. * So Asus made a deliberate decision not to support it on this model.
  1051. * We have several reports that using it can cause the system to hang
  1052. *
  1053. * The hang has also been reported on a "702" (Model name "8G"?).
  1054. *
  1055. * We avoid dmi_check_system() / dmi_match(), because they use
  1056. * substring matching. We don't want to affect the "701SD"
  1057. * and "701SDX" models, because they do support S.H.E.
  1058. */
  1059. if (strcmp(model, "701") == 0 || strcmp(model, "702") == 0) {
  1060. eeepc->cpufv_disabled = true;
  1061. pr_info("model %s does not officially support setting cpu speed\n",
  1062. model);
  1063. pr_info("cpufv disabled to avoid instability\n");
  1064. }
  1065. /*
  1066. * Blacklist for wlan hotplug
  1067. *
  1068. * Eeepc 1005HA doesn't work like others models and don't need the
  1069. * hotplug code. In fact, current hotplug code seems to unplug another
  1070. * device...
  1071. */
  1072. if (strcmp(model, "1005HA") == 0 || strcmp(model, "1201N") == 0 ||
  1073. strcmp(model, "1005PE") == 0) {
  1074. eeepc->hotplug_disabled = true;
  1075. pr_info("wlan hotplug disabled\n");
  1076. }
  1077. }
  1078. static void cmsg_quirk(struct eeepc_laptop *eeepc, int cm, const char *name)
  1079. {
  1080. int dummy;
  1081. /* Some BIOSes do not report cm although it is available.
  1082. Check if cm_getv[cm] works and, if yes, assume cm should be set. */
  1083. if (!(eeepc->cm_supported & (1 << cm))
  1084. && !read_acpi_int(eeepc->handle, cm_getv[cm], &dummy)) {
  1085. pr_info("%s (%x) not reported by BIOS, enabling anyway\n",
  1086. name, 1 << cm);
  1087. eeepc->cm_supported |= 1 << cm;
  1088. }
  1089. }
  1090. static void cmsg_quirks(struct eeepc_laptop *eeepc)
  1091. {
  1092. cmsg_quirk(eeepc, CM_ASL_LID, "LID");
  1093. cmsg_quirk(eeepc, CM_ASL_TYPE, "TYPE");
  1094. cmsg_quirk(eeepc, CM_ASL_PANELPOWER, "PANELPOWER");
  1095. cmsg_quirk(eeepc, CM_ASL_TPD, "TPD");
  1096. }
  1097. static int eeepc_acpi_init(struct eeepc_laptop *eeepc)
  1098. {
  1099. unsigned int init_flags;
  1100. int result;
  1101. result = acpi_bus_get_status(eeepc->device);
  1102. if (result)
  1103. return result;
  1104. if (!eeepc->device->status.present) {
  1105. pr_err("Hotkey device not present, aborting\n");
  1106. return -ENODEV;
  1107. }
  1108. init_flags = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
  1109. pr_notice("Hotkey init flags 0x%x\n", init_flags);
  1110. if (write_acpi_int(eeepc->handle, "INIT", init_flags)) {
  1111. pr_err("Hotkey initialization failed\n");
  1112. return -ENODEV;
  1113. }
  1114. /* get control methods supported */
  1115. if (read_acpi_int(eeepc->handle, "CMSG", &eeepc->cm_supported)) {
  1116. pr_err("Get control methods supported failed\n");
  1117. return -ENODEV;
  1118. }
  1119. cmsg_quirks(eeepc);
  1120. pr_info("Get control methods supported: 0x%x\n", eeepc->cm_supported);
  1121. return 0;
  1122. }
  1123. static void eeepc_enable_camera(struct eeepc_laptop *eeepc)
  1124. {
  1125. /*
  1126. * If the following call to set_acpi() fails, it's because there's no
  1127. * camera so we can ignore the error.
  1128. */
  1129. if (get_acpi(eeepc, CM_ASL_CAMERA) == 0)
  1130. set_acpi(eeepc, CM_ASL_CAMERA, 1);
  1131. }
  1132. static bool eeepc_device_present;
  1133. static int eeepc_acpi_add(struct acpi_device *device)
  1134. {
  1135. struct eeepc_laptop *eeepc;
  1136. int result;
  1137. pr_notice(EEEPC_LAPTOP_NAME "\n");
  1138. eeepc = kzalloc(sizeof(struct eeepc_laptop), GFP_KERNEL);
  1139. if (!eeepc)
  1140. return -ENOMEM;
  1141. eeepc->handle = device->handle;
  1142. strcpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME);
  1143. strcpy(acpi_device_class(device), EEEPC_ACPI_CLASS);
  1144. device->driver_data = eeepc;
  1145. eeepc->device = device;
  1146. eeepc->hotplug_disabled = hotplug_disabled;
  1147. eeepc_dmi_check(eeepc);
  1148. result = eeepc_acpi_init(eeepc);
  1149. if (result)
  1150. goto fail_platform;
  1151. eeepc_enable_camera(eeepc);
  1152. /*
  1153. * Register the platform device first. It is used as a parent for the
  1154. * sub-devices below.
  1155. *
  1156. * Note that if there are multiple instances of this ACPI device it
  1157. * will bail out, because the platform device is registered with a
  1158. * fixed name. Of course it doesn't make sense to have more than one,
  1159. * and machine-specific scripts find the fixed name convenient. But
  1160. * It's also good for us to exclude multiple instances because both
  1161. * our hwmon and our wlan rfkill subdevice use global ACPI objects
  1162. * (the EC and the wlan PCI slot respectively).
  1163. */
  1164. result = eeepc_platform_init(eeepc);
  1165. if (result)
  1166. goto fail_platform;
  1167. if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
  1168. result = eeepc_backlight_init(eeepc);
  1169. if (result)
  1170. goto fail_backlight;
  1171. }
  1172. result = eeepc_input_init(eeepc);
  1173. if (result)
  1174. goto fail_input;
  1175. result = eeepc_hwmon_init(eeepc);
  1176. if (result)
  1177. goto fail_hwmon;
  1178. result = eeepc_led_init(eeepc);
  1179. if (result)
  1180. goto fail_led;
  1181. result = eeepc_rfkill_init(eeepc);
  1182. if (result)
  1183. goto fail_rfkill;
  1184. eeepc_device_present = true;
  1185. return 0;
  1186. fail_rfkill:
  1187. eeepc_led_exit(eeepc);
  1188. fail_led:
  1189. fail_hwmon:
  1190. eeepc_input_exit(eeepc);
  1191. fail_input:
  1192. eeepc_backlight_exit(eeepc);
  1193. fail_backlight:
  1194. eeepc_platform_exit(eeepc);
  1195. fail_platform:
  1196. kfree(eeepc);
  1197. return result;
  1198. }
  1199. static int eeepc_acpi_remove(struct acpi_device *device)
  1200. {
  1201. struct eeepc_laptop *eeepc = acpi_driver_data(device);
  1202. eeepc_backlight_exit(eeepc);
  1203. eeepc_rfkill_exit(eeepc);
  1204. eeepc_input_exit(eeepc);
  1205. eeepc_led_exit(eeepc);
  1206. eeepc_platform_exit(eeepc);
  1207. kfree(eeepc);
  1208. return 0;
  1209. }
  1210. static const struct acpi_device_id eeepc_device_ids[] = {
  1211. {EEEPC_ACPI_HID, 0},
  1212. {"", 0},
  1213. };
  1214. MODULE_DEVICE_TABLE(acpi, eeepc_device_ids);
  1215. static struct acpi_driver eeepc_acpi_driver = {
  1216. .name = EEEPC_LAPTOP_NAME,
  1217. .class = EEEPC_ACPI_CLASS,
  1218. .owner = THIS_MODULE,
  1219. .ids = eeepc_device_ids,
  1220. .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
  1221. .ops = {
  1222. .add = eeepc_acpi_add,
  1223. .remove = eeepc_acpi_remove,
  1224. .notify = eeepc_acpi_notify,
  1225. },
  1226. };
  1227. static int __init eeepc_laptop_init(void)
  1228. {
  1229. int result;
  1230. result = platform_driver_register(&platform_driver);
  1231. if (result < 0)
  1232. return result;
  1233. result = acpi_bus_register_driver(&eeepc_acpi_driver);
  1234. if (result < 0)
  1235. goto fail_acpi_driver;
  1236. if (!eeepc_device_present) {
  1237. result = -ENODEV;
  1238. goto fail_no_device;
  1239. }
  1240. return 0;
  1241. fail_no_device:
  1242. acpi_bus_unregister_driver(&eeepc_acpi_driver);
  1243. fail_acpi_driver:
  1244. platform_driver_unregister(&platform_driver);
  1245. return result;
  1246. }
  1247. static void __exit eeepc_laptop_exit(void)
  1248. {
  1249. acpi_bus_unregister_driver(&eeepc_acpi_driver);
  1250. platform_driver_unregister(&platform_driver);
  1251. }
  1252. module_init(eeepc_laptop_init);
  1253. module_exit(eeepc_laptop_exit);