eeepc-laptop.c 36 KB

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