blob: 7fc944ac2070c42e10d19eb1e96b9afbca788526 [file] [log] [blame]
Eric Coopere59f8792008-03-13 12:55:46 +01001/*
Alan Jenkinsa7624b62009-12-03 07:45:08 +00002 * eeepc-laptop.c - Asus Eee PC extras
Eric Coopere59f8792008-03-13 12:55:46 +01003 *
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
Joe Perches19b53282009-06-25 13:25:37 +020019#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
Eric Coopere59f8792008-03-13 12:55:46 +010021#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/types.h>
25#include <linux/platform_device.h>
Corentin Charya5fa4292008-03-13 12:56:37 +010026#include <linux/backlight.h>
27#include <linux/fb.h>
Corentin Charye1faa9d2008-03-13 12:57:18 +010028#include <linux/hwmon.h>
29#include <linux/hwmon-sysfs.h>
Eric Coopere59f8792008-03-13 12:55:46 +010030#include <acpi/acpi_drivers.h>
31#include <acpi/acpi_bus.h>
32#include <linux/uaccess.h>
Matthew Garretta195dcd2008-08-19 12:13:20 +010033#include <linux/input.h>
34#include <linux/rfkill.h>
Matthew Garrett57402942009-01-20 16:17:48 +010035#include <linux/pci.h>
Corentin Chary2b121bc2009-06-25 13:25:36 +020036#include <linux/pci_hotplug.h>
Corentin Chary3c0eb512009-12-03 07:44:52 +000037#include <linux/leds.h>
Alan Jenkinsda8ba012010-01-06 22:07:37 +010038#include <linux/dmi.h>
Eric Coopere59f8792008-03-13 12:55:46 +010039
40#define EEEPC_LAPTOP_VERSION "0.1"
Alan Jenkinsa7624b62009-12-03 07:45:08 +000041#define EEEPC_LAPTOP_NAME "Eee PC Hotkey Driver"
42#define EEEPC_LAPTOP_FILE "eeepc"
Eric Coopere59f8792008-03-13 12:55:46 +010043
Alan Jenkinsa7624b62009-12-03 07:45:08 +000044#define EEEPC_ACPI_CLASS "hotkey"
45#define EEEPC_ACPI_DEVICE_NAME "Hotkey"
46#define EEEPC_ACPI_HID "ASUS010"
Eric Coopere59f8792008-03-13 12:55:46 +010047
Alan Jenkins52bbe3c2009-12-03 07:45:07 +000048MODULE_AUTHOR("Corentin Chary, Eric Cooper");
Alan Jenkinsa7624b62009-12-03 07:45:08 +000049MODULE_DESCRIPTION(EEEPC_LAPTOP_NAME);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +000050MODULE_LICENSE("GPL");
Eric Coopere59f8792008-03-13 12:55:46 +010051
52/*
53 * Definitions for Asus EeePC
54 */
Corentin Charya5fa4292008-03-13 12:56:37 +010055#define NOTIFY_BRN_MIN 0x20
56#define NOTIFY_BRN_MAX 0x2f
Eric Coopere59f8792008-03-13 12:55:46 +010057
58enum {
59 DISABLE_ASL_WLAN = 0x0001,
60 DISABLE_ASL_BLUETOOTH = 0x0002,
61 DISABLE_ASL_IRDA = 0x0004,
62 DISABLE_ASL_CAMERA = 0x0008,
63 DISABLE_ASL_TV = 0x0010,
64 DISABLE_ASL_GPS = 0x0020,
65 DISABLE_ASL_DISPLAYSWITCH = 0x0040,
66 DISABLE_ASL_MODEM = 0x0080,
Corentin Charyb7b700d2009-06-16 19:28:52 +000067 DISABLE_ASL_CARDREADER = 0x0100,
68 DISABLE_ASL_3G = 0x0200,
69 DISABLE_ASL_WIMAX = 0x0400,
70 DISABLE_ASL_HWCF = 0x0800
Eric Coopere59f8792008-03-13 12:55:46 +010071};
72
73enum {
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,
Corentin Charyb7b700d2009-06-16 19:28:52 +000095 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
Eric Coopere59f8792008-03-13 12:55:46 +0100102};
103
Adrian Bunk14109462008-06-25 19:25:47 +0300104static const char *cm_getv[] = {
Jonathan McDowell3af9bfc2008-12-03 20:31:11 +0000105 "WLDG", "BTHG", NULL, NULL,
Eric Coopere59f8792008-03-13 12:55:46 +0100106 "CAMG", NULL, NULL, NULL,
107 NULL, "PBLG", NULL, NULL,
108 "CFVG", NULL, NULL, NULL,
109 "USBG", NULL, NULL, "MODG",
Corentin Charyb7b700d2009-06-16 19:28:52 +0000110 "CRDG", "M3GG", "WIMG", "HWCF",
111 "LIDG", "TYPE", "PBPG", "TPDG"
Eric Coopere59f8792008-03-13 12:55:46 +0100112};
113
Adrian Bunk14109462008-06-25 19:25:47 +0300114static const char *cm_setv[] = {
Jonathan McDowell3af9bfc2008-12-03 20:31:11 +0000115 "WLDS", "BTHS", NULL, NULL,
Eric Coopere59f8792008-03-13 12:55:46 +0100116 "CAMS", NULL, NULL, NULL,
117 "SDSP", "PBLS", "HDPS", NULL,
118 "CFVS", NULL, NULL, NULL,
119 "USBG", NULL, NULL, "MODS",
Corentin Charyb7b700d2009-06-16 19:28:52 +0000120 "CRDS", "M3GS", "WIMS", NULL,
121 NULL, NULL, "PBPS", "TPDS"
Eric Coopere59f8792008-03-13 12:55:46 +0100122};
123
Matthew Garretta195dcd2008-08-19 12:13:20 +0100124struct key_entry {
125 char type;
126 u8 code;
127 u16 keycode;
128};
129
130enum { KE_KEY, KE_END };
131
Alan Jenkins854c7832009-12-03 07:45:09 +0000132static const struct key_entry eeepc_keymap[] = {
Matthew Garretta195dcd2008-08-19 12:13:20 +0100133 /* Sleep already handled via generic ACPI code */
134 {KE_KEY, 0x10, KEY_WLAN },
Alan Jenkins978605c2009-04-27 09:23:39 +0200135 {KE_KEY, 0x11, KEY_WLAN },
Matthew Garretta195dcd2008-08-19 12:13:20 +0100136 {KE_KEY, 0x12, KEY_PROG1 },
137 {KE_KEY, 0x13, KEY_MUTE },
138 {KE_KEY, 0x14, KEY_VOLUMEDOWN },
139 {KE_KEY, 0x15, KEY_VOLUMEUP },
Corentin Charyb39b85e742009-12-03 07:45:13 +0000140 {KE_KEY, 0x16, KEY_DISPLAY_OFF },
Matthew Garrettb5f6f262009-01-20 16:17:46 +0100141 {KE_KEY, 0x1a, KEY_COFFEE },
142 {KE_KEY, 0x1b, KEY_ZOOM },
143 {KE_KEY, 0x1c, KEY_PROG2 },
144 {KE_KEY, 0x1d, KEY_PROG3 },
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000145 {KE_KEY, NOTIFY_BRN_MIN, KEY_BRIGHTNESSDOWN },
146 {KE_KEY, NOTIFY_BRN_MAX, KEY_BRIGHTNESSUP },
Matthew Garretta195dcd2008-08-19 12:13:20 +0100147 {KE_KEY, 0x30, KEY_SWITCHVIDEOMODE },
148 {KE_KEY, 0x31, KEY_SWITCHVIDEOMODE },
149 {KE_KEY, 0x32, KEY_SWITCHVIDEOMODE },
Corentin Charyb39b85e742009-12-03 07:45:13 +0000150 {KE_KEY, 0x37, KEY_F13 }, /* Disable Touchpad */
151 {KE_KEY, 0x38, KEY_F14 },
Matthew Garretta195dcd2008-08-19 12:13:20 +0100152 {KE_END, 0},
153};
154
Corentin Charye1faa9d2008-03-13 12:57:18 +0100155
Corentin Charya5fa4292008-03-13 12:56:37 +0100156/*
Eric Coopere59f8792008-03-13 12:55:46 +0100157 * This is the main structure, we can use it to store useful information
Corentin Charya5fa4292008-03-13 12:56:37 +0100158 */
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000159struct eeepc_laptop {
Alan Jenkins854c7832009-12-03 07:45:09 +0000160 acpi_handle handle; /* the handle of the acpi device */
Eric Coopere59f8792008-03-13 12:55:46 +0100161 u32 cm_supported; /* the control methods supported
162 by this BIOS */
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100163 bool cpufv_disabled;
Corentin Chary10ae4b52010-01-06 22:07:38 +0100164 bool hotplug_disabled;
Eric Coopere59f8792008-03-13 12:55:46 +0100165 u16 event_count[128]; /* count for each event */
Corentin Charya5fa4292008-03-13 12:56:37 +0100166
Alan Jenkins854c7832009-12-03 07:45:09 +0000167 struct platform_device *platform_device;
168 struct device *hwmon_device;
169 struct backlight_device *backlight_device;
170
Eric Coopere59f8792008-03-13 12:55:46 +0100171 struct input_dev *inputdev;
Alan Jenkins854c7832009-12-03 07:45:09 +0000172 struct key_entry *keymap;
173
Eric Coopere59f8792008-03-13 12:55:46 +0100174 struct rfkill *wlan_rfkill;
175 struct rfkill *bluetooth_rfkill;
176 struct rfkill *wwan3g_rfkill;
177 struct rfkill *wimax_rfkill;
Alan Jenkins854c7832009-12-03 07:45:09 +0000178
Eric Coopere59f8792008-03-13 12:55:46 +0100179 struct hotplug_slot *hotplug_slot;
180 struct mutex hotplug_lock;
Alan Jenkins854c7832009-12-03 07:45:09 +0000181
182 struct led_classdev tpd_led;
183 int tpd_led_wk;
184 struct workqueue_struct *led_workqueue;
185 struct work_struct tpd_led_work;
Eric Coopere59f8792008-03-13 12:55:46 +0100186};
Eric Coopere59f8792008-03-13 12:55:46 +0100187
188/*
189 * ACPI Helpers
190 */
Alan Jenkins6b188a72009-12-03 07:45:02 +0000191static int write_acpi_int(acpi_handle handle, const char *method, int val)
Eric Coopere59f8792008-03-13 12:55:46 +0100192{
193 struct acpi_object_list params;
194 union acpi_object in_obj;
195 acpi_status status;
196
197 params.count = 1;
198 params.pointer = &in_obj;
199 in_obj.type = ACPI_TYPE_INTEGER;
200 in_obj.integer.value = val;
201
Alan Jenkins6b188a72009-12-03 07:45:02 +0000202 status = acpi_evaluate_object(handle, (char *)method, &params, NULL);
Eric Coopere59f8792008-03-13 12:55:46 +0100203 return (status == AE_OK ? 0 : -1);
204}
205
206static int read_acpi_int(acpi_handle handle, const char *method, int *val)
207{
208 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400209 unsigned long long result;
Eric Coopere59f8792008-03-13 12:55:46 +0100210
211 status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
212 if (ACPI_FAILURE(status)) {
213 *val = -1;
214 return -1;
215 } else {
216 *val = result;
217 return 0;
218 }
219}
220
Alan Jenkins854c7832009-12-03 07:45:09 +0000221static int set_acpi(struct eeepc_laptop *eeepc, int cm, int value)
Eric Coopere59f8792008-03-13 12:55:46 +0100222{
Alan Jenkins13f70022009-12-03 07:44:59 +0000223 const char *method = cm_setv[cm];
224
225 if (method == NULL)
226 return -ENODEV;
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000227 if ((eeepc->cm_supported & (0x1 << cm)) == 0)
Alan Jenkins13f70022009-12-03 07:44:59 +0000228 return -ENODEV;
229
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000230 if (write_acpi_int(eeepc->handle, method, value))
Alan Jenkins13f70022009-12-03 07:44:59 +0000231 pr_warning("Error writing %s\n", method);
Eric Coopere59f8792008-03-13 12:55:46 +0100232 return 0;
233}
234
Alan Jenkins854c7832009-12-03 07:45:09 +0000235static int get_acpi(struct eeepc_laptop *eeepc, int cm)
Eric Coopere59f8792008-03-13 12:55:46 +0100236{
Alan Jenkins13f70022009-12-03 07:44:59 +0000237 const char *method = cm_getv[cm];
238 int value;
239
240 if (method == NULL)
241 return -ENODEV;
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000242 if ((eeepc->cm_supported & (0x1 << cm)) == 0)
Alan Jenkins13f70022009-12-03 07:44:59 +0000243 return -ENODEV;
244
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000245 if (read_acpi_int(eeepc->handle, method, &value))
Alan Jenkins13f70022009-12-03 07:44:59 +0000246 pr_warning("Error reading %s\n", method);
Eric Coopere59f8792008-03-13 12:55:46 +0100247 return value;
248}
249
Corentin Charyf90be872009-12-03 07:45:14 +0000250static int acpi_setter_handle(struct eeepc_laptop *eeepc, int cm,
251 acpi_handle *handle)
Alan Jenkins854c7832009-12-03 07:45:09 +0000252{
253 const char *method = cm_setv[cm];
254 acpi_status status;
255
256 if (method == NULL)
257 return -ENODEV;
258 if ((eeepc->cm_supported & (0x1 << cm)) == 0)
259 return -ENODEV;
260
261 status = acpi_get_handle(eeepc->handle, (char *)method,
Corentin Charyf90be872009-12-03 07:45:14 +0000262 handle);
Alan Jenkins854c7832009-12-03 07:45:09 +0000263 if (status != AE_OK) {
264 pr_warning("Error finding %s\n", method);
265 return -ENODEV;
Eric Coopere59f8792008-03-13 12:55:46 +0100266 }
267 return 0;
268}
269
Pekka Enbergcede2cb2009-06-16 19:28:45 +0000270
Matthew Garretta195dcd2008-08-19 12:13:20 +0100271/*
Eric Coopere59f8792008-03-13 12:55:46 +0100272 * Sys helpers
273 */
274static int parse_arg(const char *buf, unsigned long count, int *val)
275{
276 if (!count)
277 return 0;
278 if (sscanf(buf, "%i", val) != 1)
279 return -EINVAL;
280 return count;
281}
282
Alan Jenkins854c7832009-12-03 07:45:09 +0000283static ssize_t store_sys_acpi(struct device *dev, int cm,
284 const char *buf, size_t count)
Eric Coopere59f8792008-03-13 12:55:46 +0100285{
Alan Jenkins854c7832009-12-03 07:45:09 +0000286 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
Eric Coopere59f8792008-03-13 12:55:46 +0100287 int rv, value;
288
289 rv = parse_arg(buf, count, &value);
290 if (rv > 0)
Alan Jenkins854c7832009-12-03 07:45:09 +0000291 value = set_acpi(eeepc, cm, value);
Corentin Charyf36509e2009-06-25 13:25:40 +0200292 if (value < 0)
Alan Jenkins6dff29b2009-12-03 07:44:45 +0000293 return -EIO;
Eric Coopere59f8792008-03-13 12:55:46 +0100294 return rv;
295}
296
Alan Jenkins854c7832009-12-03 07:45:09 +0000297static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf)
Eric Coopere59f8792008-03-13 12:55:46 +0100298{
Alan Jenkins854c7832009-12-03 07:45:09 +0000299 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
300 int value = get_acpi(eeepc, cm);
Corentin Charyf36509e2009-06-25 13:25:40 +0200301
302 if (value < 0)
Alan Jenkins6dff29b2009-12-03 07:44:45 +0000303 return -EIO;
Corentin Charyf36509e2009-06-25 13:25:40 +0200304 return sprintf(buf, "%d\n", value);
Eric Coopere59f8792008-03-13 12:55:46 +0100305}
306
Alan Jenkins6dff29b2009-12-03 07:44:45 +0000307#define EEEPC_CREATE_DEVICE_ATTR(_name, _mode, _cm) \
Eric Coopere59f8792008-03-13 12:55:46 +0100308 static ssize_t show_##_name(struct device *dev, \
309 struct device_attribute *attr, \
310 char *buf) \
311 { \
Alan Jenkins854c7832009-12-03 07:45:09 +0000312 return show_sys_acpi(dev, _cm, buf); \
Eric Coopere59f8792008-03-13 12:55:46 +0100313 } \
314 static ssize_t store_##_name(struct device *dev, \
315 struct device_attribute *attr, \
316 const char *buf, size_t count) \
317 { \
Alan Jenkins854c7832009-12-03 07:45:09 +0000318 return store_sys_acpi(dev, _cm, buf, count); \
Eric Coopere59f8792008-03-13 12:55:46 +0100319 } \
320 static struct device_attribute dev_attr_##_name = { \
321 .attr = { \
322 .name = __stringify(_name), \
Alan Jenkins6dff29b2009-12-03 07:44:45 +0000323 .mode = _mode }, \
Eric Coopere59f8792008-03-13 12:55:46 +0100324 .show = show_##_name, \
325 .store = store_##_name, \
326 }
327
Alan Jenkins6dff29b2009-12-03 07:44:45 +0000328EEEPC_CREATE_DEVICE_ATTR(camera, 0644, CM_ASL_CAMERA);
329EEEPC_CREATE_DEVICE_ATTR(cardr, 0644, CM_ASL_CARDREADER);
330EEEPC_CREATE_DEVICE_ATTR(disp, 0200, CM_ASL_DISPLAYSWITCH);
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000331
332struct eeepc_cpufv {
333 int num;
334 int cur;
335};
336
Alan Jenkins854c7832009-12-03 07:45:09 +0000337static int get_cpufv(struct eeepc_laptop *eeepc, struct eeepc_cpufv *c)
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000338{
Alan Jenkins854c7832009-12-03 07:45:09 +0000339 c->cur = get_acpi(eeepc, CM_ASL_CPUFV);
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000340 c->num = (c->cur >> 8) & 0xff;
341 c->cur &= 0xff;
342 if (c->cur < 0 || c->num <= 0 || c->num > 12)
343 return -ENODEV;
344 return 0;
345}
346
347static ssize_t show_available_cpufv(struct device *dev,
348 struct device_attribute *attr,
349 char *buf)
350{
Alan Jenkins854c7832009-12-03 07:45:09 +0000351 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000352 struct eeepc_cpufv c;
353 int i;
354 ssize_t len = 0;
355
Alan Jenkins854c7832009-12-03 07:45:09 +0000356 if (get_cpufv(eeepc, &c))
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000357 return -ENODEV;
358 for (i = 0; i < c.num; i++)
359 len += sprintf(buf + len, "%d ", i);
360 len += sprintf(buf + len, "\n");
361 return len;
362}
363
364static ssize_t show_cpufv(struct device *dev,
365 struct device_attribute *attr,
366 char *buf)
367{
Alan Jenkins854c7832009-12-03 07:45:09 +0000368 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000369 struct eeepc_cpufv c;
370
Alan Jenkins854c7832009-12-03 07:45:09 +0000371 if (get_cpufv(eeepc, &c))
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000372 return -ENODEV;
373 return sprintf(buf, "%#x\n", (c.num << 8) | c.cur);
374}
375
376static ssize_t store_cpufv(struct device *dev,
377 struct device_attribute *attr,
378 const char *buf, size_t count)
379{
Alan Jenkins854c7832009-12-03 07:45:09 +0000380 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000381 struct eeepc_cpufv c;
382 int rv, value;
383
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100384 if (eeepc->cpufv_disabled)
385 return -EPERM;
Alan Jenkins854c7832009-12-03 07:45:09 +0000386 if (get_cpufv(eeepc, &c))
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000387 return -ENODEV;
388 rv = parse_arg(buf, count, &value);
389 if (rv < 0)
390 return rv;
391 if (!rv || value < 0 || value >= c.num)
392 return -EINVAL;
Alan Jenkins854c7832009-12-03 07:45:09 +0000393 set_acpi(eeepc, CM_ASL_CPUFV, value);
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000394 return rv;
395}
396
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100397static ssize_t show_cpufv_disabled(struct device *dev,
398 struct device_attribute *attr,
399 char *buf)
400{
401 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
402
403 return sprintf(buf, "%d\n", eeepc->cpufv_disabled);
404}
405
406static ssize_t store_cpufv_disabled(struct device *dev,
407 struct device_attribute *attr,
408 const char *buf, size_t count)
409{
410 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
411 int rv, value;
412
413 rv = parse_arg(buf, count, &value);
414 if (rv < 0)
415 return rv;
416
417 switch (value) {
418 case 0:
419 if (eeepc->cpufv_disabled)
420 pr_warning("cpufv enabled (not officially supported "
421 "on this model)\n");
422 eeepc->cpufv_disabled = false;
423 return rv;
424 case 1:
425 return -EPERM;
426 default:
427 return -EINVAL;
428 }
429}
430
431
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000432static struct device_attribute dev_attr_cpufv = {
433 .attr = {
434 .name = "cpufv",
435 .mode = 0644 },
436 .show = show_cpufv,
437 .store = store_cpufv
438};
439
440static struct device_attribute dev_attr_available_cpufv = {
441 .attr = {
442 .name = "available_cpufv",
443 .mode = 0444 },
444 .show = show_available_cpufv
445};
Eric Coopere59f8792008-03-13 12:55:46 +0100446
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100447static struct device_attribute dev_attr_cpufv_disabled = {
448 .attr = {
449 .name = "cpufv_disabled",
450 .mode = 0644 },
451 .show = show_cpufv_disabled,
452 .store = store_cpufv_disabled
453};
454
455
Eric Coopere59f8792008-03-13 12:55:46 +0100456static struct attribute *platform_attributes[] = {
457 &dev_attr_camera.attr,
458 &dev_attr_cardr.attr,
459 &dev_attr_disp.attr,
Grigori Goronzy158ca1d2009-04-27 09:23:40 +0200460 &dev_attr_cpufv.attr,
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000461 &dev_attr_available_cpufv.attr,
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100462 &dev_attr_cpufv_disabled.attr,
Eric Coopere59f8792008-03-13 12:55:46 +0100463 NULL
464};
465
466static struct attribute_group platform_attribute_group = {
467 .attrs = platform_attributes
468};
469
Alan Jenkins854c7832009-12-03 07:45:09 +0000470static int eeepc_platform_init(struct eeepc_laptop *eeepc)
Matthew Garretta195dcd2008-08-19 12:13:20 +0100471{
Eric Coopere59f8792008-03-13 12:55:46 +0100472 int result;
473
Alan Jenkins854c7832009-12-03 07:45:09 +0000474 eeepc->platform_device = platform_device_alloc(EEEPC_LAPTOP_FILE, -1);
475 if (!eeepc->platform_device)
Alan Jenkins9db106b2009-12-03 07:45:06 +0000476 return -ENOMEM;
Alan Jenkins854c7832009-12-03 07:45:09 +0000477 platform_set_drvdata(eeepc->platform_device, eeepc);
Alan Jenkins9db106b2009-12-03 07:45:06 +0000478
Alan Jenkins854c7832009-12-03 07:45:09 +0000479 result = platform_device_add(eeepc->platform_device);
Eric Coopere59f8792008-03-13 12:55:46 +0100480 if (result)
Alan Jenkins9db106b2009-12-03 07:45:06 +0000481 goto fail_platform_device;
482
Alan Jenkins854c7832009-12-03 07:45:09 +0000483 result = sysfs_create_group(&eeepc->platform_device->dev.kobj,
Alan Jenkins9db106b2009-12-03 07:45:06 +0000484 &platform_attribute_group);
485 if (result)
486 goto fail_sysfs;
Eric Coopere59f8792008-03-13 12:55:46 +0100487 return 0;
Alan Jenkins9db106b2009-12-03 07:45:06 +0000488
489fail_sysfs:
Alan Jenkins854c7832009-12-03 07:45:09 +0000490 platform_device_del(eeepc->platform_device);
Alan Jenkins9db106b2009-12-03 07:45:06 +0000491fail_platform_device:
Alan Jenkins854c7832009-12-03 07:45:09 +0000492 platform_device_put(eeepc->platform_device);
Alan Jenkins9db106b2009-12-03 07:45:06 +0000493 return result;
Eric Coopere59f8792008-03-13 12:55:46 +0100494}
495
Alan Jenkins854c7832009-12-03 07:45:09 +0000496static void eeepc_platform_exit(struct eeepc_laptop *eeepc)
Corentin Charya5fa4292008-03-13 12:56:37 +0100497{
Alan Jenkins854c7832009-12-03 07:45:09 +0000498 sysfs_remove_group(&eeepc->platform_device->dev.kobj,
Alan Jenkins9db106b2009-12-03 07:45:06 +0000499 &platform_attribute_group);
Alan Jenkins854c7832009-12-03 07:45:09 +0000500 platform_device_unregister(eeepc->platform_device);
Alan Jenkins9db106b2009-12-03 07:45:06 +0000501}
502
Eric Coopere59f8792008-03-13 12:55:46 +0100503/*
Corentin Chary3c0eb512009-12-03 07:44:52 +0000504 * LEDs
505 */
506/*
507 * These functions actually update the LED's, and are called from a
508 * workqueue. By doing this as separate work rather than when the LED
509 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
510 * potentially bad time, such as a timer interrupt.
511 */
Alan Jenkins854c7832009-12-03 07:45:09 +0000512static void tpd_led_update(struct work_struct *work)
513 {
514 struct eeepc_laptop *eeepc;
Corentin Chary3c0eb512009-12-03 07:44:52 +0000515
Alan Jenkins854c7832009-12-03 07:45:09 +0000516 eeepc = container_of(work, struct eeepc_laptop, tpd_led_work);
517
518 set_acpi(eeepc, CM_ASL_TPD, eeepc->tpd_led_wk);
Corentin Chary3c0eb512009-12-03 07:44:52 +0000519}
520
Corentin Chary3c0eb512009-12-03 07:44:52 +0000521static void tpd_led_set(struct led_classdev *led_cdev,
522 enum led_brightness value)
523{
Alan Jenkins854c7832009-12-03 07:45:09 +0000524 struct eeepc_laptop *eeepc;
525
526 eeepc = container_of(led_cdev, struct eeepc_laptop, tpd_led);
527
528 eeepc->tpd_led_wk = (value > 0) ? 1 : 0;
529 queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work);
Corentin Chary3c0eb512009-12-03 07:44:52 +0000530}
531
Alan Jenkins854c7832009-12-03 07:45:09 +0000532static int eeepc_led_init(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000533{
534 int rv;
535
Alan Jenkins854c7832009-12-03 07:45:09 +0000536 if (get_acpi(eeepc, CM_ASL_TPD) == -ENODEV)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000537 return 0;
538
Alan Jenkins854c7832009-12-03 07:45:09 +0000539 eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue");
540 if (!eeepc->led_workqueue)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000541 return -ENOMEM;
Alan Jenkins854c7832009-12-03 07:45:09 +0000542 INIT_WORK(&eeepc->tpd_led_work, tpd_led_update);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000543
Alan Jenkins854c7832009-12-03 07:45:09 +0000544 eeepc->tpd_led.name = "eeepc::touchpad";
545 eeepc->tpd_led.brightness_set = tpd_led_set;
546 eeepc->tpd_led.max_brightness = 1;
547
548 rv = led_classdev_register(&eeepc->platform_device->dev,
549 &eeepc->tpd_led);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000550 if (rv) {
Alan Jenkins854c7832009-12-03 07:45:09 +0000551 destroy_workqueue(eeepc->led_workqueue);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000552 return rv;
Darren Salt64b86b62009-04-27 09:23:38 +0200553 }
Corentin Chary2b121bc2009-06-25 13:25:36 +0200554
555 return 0;
556}
557
Alan Jenkins854c7832009-12-03 07:45:09 +0000558static void eeepc_led_exit(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000559{
Alan Jenkins854c7832009-12-03 07:45:09 +0000560 if (eeepc->tpd_led.dev)
561 led_classdev_unregister(&eeepc->tpd_led);
562 if (eeepc->led_workqueue)
563 destroy_workqueue(eeepc->led_workqueue);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000564}
565
566
Corentin Chary3c0eb512009-12-03 07:44:52 +0000567/*
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000568 * PCI hotplug (for wlan rfkill)
Eric Coopere59f8792008-03-13 12:55:46 +0100569 */
Alan Jenkins854c7832009-12-03 07:45:09 +0000570static bool eeepc_wlan_rfkill_blocked(struct eeepc_laptop *eeepc)
Eric Coopere59f8792008-03-13 12:55:46 +0100571{
Alan Jenkins854c7832009-12-03 07:45:09 +0000572 if (get_acpi(eeepc, CM_ASL_WLAN) == 1)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000573 return false;
574 return true;
Corentin Charya5fa4292008-03-13 12:56:37 +0100575}
576
Alan Jenkins854c7832009-12-03 07:45:09 +0000577static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc)
Matthew Garrett57402942009-01-20 16:17:48 +0100578{
579 struct pci_dev *dev;
Alan Jenkins6d418392009-08-28 12:56:32 +0000580 struct pci_bus *bus;
Alan Jenkins854c7832009-12-03 07:45:09 +0000581 bool blocked = eeepc_wlan_rfkill_blocked(eeepc);
Matthew Garrett57402942009-01-20 16:17:48 +0100582
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000583 if (eeepc->wlan_rfkill)
584 rfkill_set_sw_state(eeepc->wlan_rfkill, blocked);
Alan Jenkins6d418392009-08-28 12:56:32 +0000585
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000586 mutex_lock(&eeepc->hotplug_lock);
Alan Jenkinsdcf443b2009-08-28 12:56:33 +0000587
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000588 if (eeepc->hotplug_slot) {
Alan Jenkins07e84aa2009-08-28 12:56:34 +0000589 bus = pci_find_bus(0, 1);
590 if (!bus) {
591 pr_warning("Unable to find PCI bus 1?\n");
Alan Jenkinsdcf443b2009-08-28 12:56:33 +0000592 goto out_unlock;
Matthew Garrett57402942009-01-20 16:17:48 +0100593 }
Alan Jenkins07e84aa2009-08-28 12:56:34 +0000594
595 if (!blocked) {
596 dev = pci_get_slot(bus, 0);
597 if (dev) {
598 /* Device already present */
599 pci_dev_put(dev);
600 goto out_unlock;
601 }
602 dev = pci_scan_single_device(bus, 0);
603 if (dev) {
604 pci_bus_assign_resources(bus);
605 if (pci_bus_add_device(dev))
606 pr_err("Unable to hotplug wifi\n");
607 }
608 } else {
609 dev = pci_get_slot(bus, 0);
610 if (dev) {
611 pci_remove_bus_device(dev);
612 pci_dev_put(dev);
613 }
Matthew Garrett57402942009-01-20 16:17:48 +0100614 }
615 }
Alan Jenkinsdcf443b2009-08-28 12:56:33 +0000616
617out_unlock:
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000618 mutex_unlock(&eeepc->hotplug_lock);
Matthew Garrett57402942009-01-20 16:17:48 +0100619}
620
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100621static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
622{
Alan Jenkins854c7832009-12-03 07:45:09 +0000623 struct eeepc_laptop *eeepc = data;
624
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100625 if (event != ACPI_NOTIFY_BUS_CHECK)
626 return;
627
Alan Jenkins854c7832009-12-03 07:45:09 +0000628 eeepc_rfkill_hotplug(eeepc);
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100629}
630
Alan Jenkins854c7832009-12-03 07:45:09 +0000631static int eeepc_register_rfkill_notifier(struct eeepc_laptop *eeepc,
632 char *node)
Eric Coopere59f8792008-03-13 12:55:46 +0100633{
Alan Jenkins854c7832009-12-03 07:45:09 +0000634 acpi_status status;
Matthew Garrett57402942009-01-20 16:17:48 +0100635 acpi_handle handle;
636
637 status = acpi_get_handle(NULL, node, &handle);
638
639 if (ACPI_SUCCESS(status)) {
640 status = acpi_install_notify_handler(handle,
641 ACPI_SYSTEM_NOTIFY,
642 eeepc_rfkill_notify,
Alan Jenkins854c7832009-12-03 07:45:09 +0000643 eeepc);
Matthew Garrett57402942009-01-20 16:17:48 +0100644 if (ACPI_FAILURE(status))
Joe Perches19b53282009-06-25 13:25:37 +0200645 pr_warning("Failed to register notify on %s\n", node);
Matthew Garrett57402942009-01-20 16:17:48 +0100646 } else
647 return -ENODEV;
648
649 return 0;
650}
651
Alan Jenkins854c7832009-12-03 07:45:09 +0000652static void eeepc_unregister_rfkill_notifier(struct eeepc_laptop *eeepc,
653 char *node)
Matthew Garrett57402942009-01-20 16:17:48 +0100654{
655 acpi_status status = AE_OK;
656 acpi_handle handle;
657
658 status = acpi_get_handle(NULL, node, &handle);
659
660 if (ACPI_SUCCESS(status)) {
661 status = acpi_remove_notify_handler(handle,
662 ACPI_SYSTEM_NOTIFY,
663 eeepc_rfkill_notify);
664 if (ACPI_FAILURE(status))
Joe Perches19b53282009-06-25 13:25:37 +0200665 pr_err("Error removing rfkill notify handler %s\n",
Matthew Garrett57402942009-01-20 16:17:48 +0100666 node);
667 }
668}
669
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000670static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
671 u8 *value)
672{
Alan Jenkins854c7832009-12-03 07:45:09 +0000673 struct eeepc_laptop *eeepc = hotplug_slot->private;
674 int val = get_acpi(eeepc, CM_ASL_WLAN);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000675
676 if (val == 1 || val == 0)
677 *value = val;
678 else
679 return -EINVAL;
680
681 return 0;
682}
683
Corentin Chary2b121bc2009-06-25 13:25:36 +0200684static void eeepc_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot)
685{
686 kfree(hotplug_slot->info);
687 kfree(hotplug_slot);
688}
689
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000690static struct hotplug_slot_ops eeepc_hotplug_slot_ops = {
691 .owner = THIS_MODULE,
692 .get_adapter_status = eeepc_get_adapter_status,
693 .get_power_status = eeepc_get_adapter_status,
694};
695
Alan Jenkins854c7832009-12-03 07:45:09 +0000696static int eeepc_setup_pci_hotplug(struct eeepc_laptop *eeepc)
Corentin Chary2b121bc2009-06-25 13:25:36 +0200697{
698 int ret = -ENOMEM;
699 struct pci_bus *bus = pci_find_bus(0, 1);
700
701 if (!bus) {
Joe Perches19b53282009-06-25 13:25:37 +0200702 pr_err("Unable to find wifi PCI bus\n");
Corentin Chary2b121bc2009-06-25 13:25:36 +0200703 return -ENODEV;
704 }
705
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000706 eeepc->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
707 if (!eeepc->hotplug_slot)
Corentin Chary2b121bc2009-06-25 13:25:36 +0200708 goto error_slot;
709
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000710 eeepc->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
Corentin Chary2b121bc2009-06-25 13:25:36 +0200711 GFP_KERNEL);
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000712 if (!eeepc->hotplug_slot->info)
Corentin Chary2b121bc2009-06-25 13:25:36 +0200713 goto error_info;
714
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000715 eeepc->hotplug_slot->private = eeepc;
716 eeepc->hotplug_slot->release = &eeepc_cleanup_pci_hotplug;
717 eeepc->hotplug_slot->ops = &eeepc_hotplug_slot_ops;
718 eeepc_get_adapter_status(eeepc->hotplug_slot,
719 &eeepc->hotplug_slot->info->adapter_status);
Corentin Chary2b121bc2009-06-25 13:25:36 +0200720
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000721 ret = pci_hp_register(eeepc->hotplug_slot, bus, 0, "eeepc-wifi");
Corentin Chary2b121bc2009-06-25 13:25:36 +0200722 if (ret) {
Joe Perches19b53282009-06-25 13:25:37 +0200723 pr_err("Unable to register hotplug slot - %d\n", ret);
Corentin Chary2b121bc2009-06-25 13:25:36 +0200724 goto error_register;
725 }
726
727 return 0;
728
729error_register:
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000730 kfree(eeepc->hotplug_slot->info);
Corentin Chary2b121bc2009-06-25 13:25:36 +0200731error_info:
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000732 kfree(eeepc->hotplug_slot);
733 eeepc->hotplug_slot = NULL;
Corentin Chary2b121bc2009-06-25 13:25:36 +0200734error_slot:
735 return ret;
736}
737
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000738/*
739 * Rfkill devices
740 */
741static int eeepc_rfkill_set(void *data, bool blocked)
742{
Alan Jenkins854c7832009-12-03 07:45:09 +0000743 acpi_handle handle = data;
744
745 return write_acpi_int(handle, NULL, !blocked);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000746}
747
748static const struct rfkill_ops eeepc_rfkill_ops = {
749 .set_block = eeepc_rfkill_set,
750};
751
Alan Jenkins854c7832009-12-03 07:45:09 +0000752static int eeepc_new_rfkill(struct eeepc_laptop *eeepc,
753 struct rfkill **rfkill,
754 const char *name,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000755 enum rfkill_type type, int cm)
756{
Alan Jenkins854c7832009-12-03 07:45:09 +0000757 acpi_handle handle;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000758 int result;
759
Alan Jenkins854c7832009-12-03 07:45:09 +0000760 result = acpi_setter_handle(eeepc, cm, &handle);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000761 if (result < 0)
762 return result;
763
Alan Jenkins854c7832009-12-03 07:45:09 +0000764 *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
765 &eeepc_rfkill_ops, handle);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000766
767 if (!*rfkill)
768 return -EINVAL;
769
Alan Jenkins854c7832009-12-03 07:45:09 +0000770 rfkill_init_sw_state(*rfkill, get_acpi(eeepc, cm) != 1);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000771 result = rfkill_register(*rfkill);
772 if (result) {
773 rfkill_destroy(*rfkill);
774 *rfkill = NULL;
775 return result;
776 }
777 return 0;
778}
779
Alan Jenkins854c7832009-12-03 07:45:09 +0000780static void eeepc_rfkill_exit(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000781{
Alan Jenkins854c7832009-12-03 07:45:09 +0000782 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
783 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
784 eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000785 if (eeepc->wlan_rfkill) {
786 rfkill_unregister(eeepc->wlan_rfkill);
787 rfkill_destroy(eeepc->wlan_rfkill);
788 eeepc->wlan_rfkill = NULL;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000789 }
790 /*
791 * Refresh pci hotplug in case the rfkill state was changed after
792 * eeepc_unregister_rfkill_notifier()
793 */
Alan Jenkins854c7832009-12-03 07:45:09 +0000794 eeepc_rfkill_hotplug(eeepc);
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000795 if (eeepc->hotplug_slot)
796 pci_hp_deregister(eeepc->hotplug_slot);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000797
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000798 if (eeepc->bluetooth_rfkill) {
799 rfkill_unregister(eeepc->bluetooth_rfkill);
800 rfkill_destroy(eeepc->bluetooth_rfkill);
801 eeepc->bluetooth_rfkill = NULL;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000802 }
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000803 if (eeepc->wwan3g_rfkill) {
804 rfkill_unregister(eeepc->wwan3g_rfkill);
805 rfkill_destroy(eeepc->wwan3g_rfkill);
806 eeepc->wwan3g_rfkill = NULL;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000807 }
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000808 if (eeepc->wimax_rfkill) {
809 rfkill_unregister(eeepc->wimax_rfkill);
810 rfkill_destroy(eeepc->wimax_rfkill);
811 eeepc->wimax_rfkill = NULL;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000812 }
813}
814
Alan Jenkins854c7832009-12-03 07:45:09 +0000815static int eeepc_rfkill_init(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000816{
817 int result = 0;
818
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000819 mutex_init(&eeepc->hotplug_lock);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000820
Alan Jenkins854c7832009-12-03 07:45:09 +0000821 result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill,
822 "eeepc-wlan", RFKILL_TYPE_WLAN,
823 CM_ASL_WLAN);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000824
825 if (result && result != -ENODEV)
826 goto exit;
827
Alan Jenkins854c7832009-12-03 07:45:09 +0000828 result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill,
829 "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH,
830 CM_ASL_BLUETOOTH);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000831
832 if (result && result != -ENODEV)
833 goto exit;
834
Alan Jenkins854c7832009-12-03 07:45:09 +0000835 result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill,
836 "eeepc-wwan3g", RFKILL_TYPE_WWAN,
837 CM_ASL_3G);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000838
839 if (result && result != -ENODEV)
840 goto exit;
841
Alan Jenkins854c7832009-12-03 07:45:09 +0000842 result = eeepc_new_rfkill(eeepc, &eeepc->wimax_rfkill,
843 "eeepc-wimax", RFKILL_TYPE_WIMAX,
844 CM_ASL_WIMAX);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000845
846 if (result && result != -ENODEV)
847 goto exit;
848
Corentin Chary10ae4b52010-01-06 22:07:38 +0100849 if (eeepc->hotplug_disabled)
850 return 0;
851
Alan Jenkins854c7832009-12-03 07:45:09 +0000852 result = eeepc_setup_pci_hotplug(eeepc);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000853 /*
854 * If we get -EBUSY then something else is handling the PCI hotplug -
855 * don't fail in this case
856 */
857 if (result == -EBUSY)
858 result = 0;
859
Alan Jenkins854c7832009-12-03 07:45:09 +0000860 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
861 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
862 eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000863 /*
864 * Refresh pci hotplug in case the rfkill state was changed during
865 * setup.
866 */
Alan Jenkins854c7832009-12-03 07:45:09 +0000867 eeepc_rfkill_hotplug(eeepc);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000868
869exit:
870 if (result && result != -ENODEV)
Alan Jenkins854c7832009-12-03 07:45:09 +0000871 eeepc_rfkill_exit(eeepc);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000872 return result;
873}
874
875/*
876 * Platform driver - hibernate/resume callbacks
877 */
Alan Jenkinsc200da52009-08-28 12:56:40 +0000878static int eeepc_hotk_thaw(struct device *device)
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100879{
Alan Jenkins854c7832009-12-03 07:45:09 +0000880 struct eeepc_laptop *eeepc = dev_get_drvdata(device);
881
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000882 if (eeepc->wlan_rfkill) {
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100883 bool wlan;
884
Alan Jenkinsc1edd992009-08-28 12:56:39 +0000885 /*
886 * Work around bios bug - acpi _PTS turns off the wireless led
887 * during suspend. Normally it restores it on resume, but
Alan Jenkinsc200da52009-08-28 12:56:40 +0000888 * we should kick it ourselves in case hibernation is aborted.
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100889 */
Alan Jenkins854c7832009-12-03 07:45:09 +0000890 wlan = get_acpi(eeepc, CM_ASL_WLAN);
891 set_acpi(eeepc, CM_ASL_WLAN, wlan);
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100892 }
893
Alan Jenkinsc200da52009-08-28 12:56:40 +0000894 return 0;
895}
896
897static int eeepc_hotk_restore(struct device *device)
898{
Alan Jenkins854c7832009-12-03 07:45:09 +0000899 struct eeepc_laptop *eeepc = dev_get_drvdata(device);
Alan Jenkinsc200da52009-08-28 12:56:40 +0000900
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100901 /* Refresh both wlan rfkill state and pci hotplug */
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000902 if (eeepc->wlan_rfkill)
Alan Jenkins854c7832009-12-03 07:45:09 +0000903 eeepc_rfkill_hotplug(eeepc);
Corentin Charye1faa9d2008-03-13 12:57:18 +0100904
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000905 if (eeepc->bluetooth_rfkill)
906 rfkill_set_sw_state(eeepc->bluetooth_rfkill,
Alan Jenkins854c7832009-12-03 07:45:09 +0000907 get_acpi(eeepc, CM_ASL_BLUETOOTH) != 1);
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000908 if (eeepc->wwan3g_rfkill)
909 rfkill_set_sw_state(eeepc->wwan3g_rfkill,
Alan Jenkins854c7832009-12-03 07:45:09 +0000910 get_acpi(eeepc, CM_ASL_3G) != 1);
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000911 if (eeepc->wimax_rfkill)
912 rfkill_set_sw_state(eeepc->wimax_rfkill,
Alan Jenkins854c7832009-12-03 07:45:09 +0000913 get_acpi(eeepc, CM_ASL_WIMAX) != 1);
Corentin Charye1faa9d2008-03-13 12:57:18 +0100914
915 return 0;
916}
917
Len Brown9a3bff22009-12-15 22:34:48 -0500918static const struct dev_pm_ops eeepc_pm_ops = {
Alan Jenkins854c7832009-12-03 07:45:09 +0000919 .thaw = eeepc_hotk_thaw,
920 .restore = eeepc_hotk_restore,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000921};
922
923static struct platform_driver platform_driver = {
924 .driver = {
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000925 .name = EEEPC_LAPTOP_FILE,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000926 .owner = THIS_MODULE,
927 .pm = &eeepc_pm_ops,
928 }
929};
930
Eric Coopere59f8792008-03-13 12:55:46 +0100931/*
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000932 * Hwmon device
Eric Coopere59f8792008-03-13 12:55:46 +0100933 */
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000934
935#define EEEPC_EC_SC00 0x61
936#define EEEPC_EC_FAN_PWM (EEEPC_EC_SC00 + 2) /* Fan PWM duty cycle (%) */
937#define EEEPC_EC_FAN_HRPM (EEEPC_EC_SC00 + 5) /* High byte, fan speed (RPM) */
938#define EEEPC_EC_FAN_LRPM (EEEPC_EC_SC00 + 6) /* Low byte, fan speed (RPM) */
939
940#define EEEPC_EC_SFB0 0xD0
941#define EEEPC_EC_FAN_CTRL (EEEPC_EC_SFB0 + 3) /* Byte containing SF25 */
942
Corentin Charye1faa9d2008-03-13 12:57:18 +0100943static int eeepc_get_fan_pwm(void)
944{
Alan Jenkins463b4e42009-12-03 07:45:03 +0000945 u8 value = 0;
Corentin Charye1faa9d2008-03-13 12:57:18 +0100946
Alan Jenkins463b4e42009-12-03 07:45:03 +0000947 ec_read(EEEPC_EC_FAN_PWM, &value);
948 return value * 255 / 100;
Corentin Charye1faa9d2008-03-13 12:57:18 +0100949}
950
951static void eeepc_set_fan_pwm(int value)
952{
953 value = SENSORS_LIMIT(value, 0, 255);
954 value = value * 100 / 255;
Alan Jenkins463b4e42009-12-03 07:45:03 +0000955 ec_write(EEEPC_EC_FAN_PWM, value);
Corentin Charye1faa9d2008-03-13 12:57:18 +0100956}
957
958static int eeepc_get_fan_rpm(void)
959{
Alan Jenkins463b4e42009-12-03 07:45:03 +0000960 u8 high = 0;
961 u8 low = 0;
Corentin Charye1faa9d2008-03-13 12:57:18 +0100962
Alan Jenkins463b4e42009-12-03 07:45:03 +0000963 ec_read(EEEPC_EC_FAN_HRPM, &high);
964 ec_read(EEEPC_EC_FAN_LRPM, &low);
965 return high << 8 | low;
Corentin Charye1faa9d2008-03-13 12:57:18 +0100966}
967
968static int eeepc_get_fan_ctrl(void)
969{
Alan Jenkins463b4e42009-12-03 07:45:03 +0000970 u8 value = 0;
Corentin Charye1faa9d2008-03-13 12:57:18 +0100971
Alan Jenkins463b4e42009-12-03 07:45:03 +0000972 ec_read(EEEPC_EC_FAN_CTRL, &value);
Alan Jenkins48718682009-12-03 07:44:56 +0000973 if (value & 0x02)
974 return 1; /* manual */
975 else
976 return 2; /* automatic */
Corentin Charye1faa9d2008-03-13 12:57:18 +0100977}
978
979static void eeepc_set_fan_ctrl(int manual)
980{
Alan Jenkins463b4e42009-12-03 07:45:03 +0000981 u8 value = 0;
Corentin Charye1faa9d2008-03-13 12:57:18 +0100982
Alan Jenkins463b4e42009-12-03 07:45:03 +0000983 ec_read(EEEPC_EC_FAN_CTRL, &value);
Alan Jenkins48718682009-12-03 07:44:56 +0000984 if (manual == 1)
Corentin Charye1faa9d2008-03-13 12:57:18 +0100985 value |= 0x02;
986 else
987 value &= ~0x02;
Alan Jenkins463b4e42009-12-03 07:45:03 +0000988 ec_write(EEEPC_EC_FAN_CTRL, value);
Corentin Charye1faa9d2008-03-13 12:57:18 +0100989}
990
991static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
992{
993 int rv, value;
994
995 rv = parse_arg(buf, count, &value);
996 if (rv > 0)
997 set(value);
998 return rv;
999}
1000
1001static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
1002{
1003 return sprintf(buf, "%d\n", get());
1004}
1005
1006#define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _set, _get) \
1007 static ssize_t show_##_name(struct device *dev, \
1008 struct device_attribute *attr, \
1009 char *buf) \
1010 { \
1011 return show_sys_hwmon(_set, buf); \
1012 } \
1013 static ssize_t store_##_name(struct device *dev, \
1014 struct device_attribute *attr, \
1015 const char *buf, size_t count) \
1016 { \
1017 return store_sys_hwmon(_get, buf, count); \
1018 } \
1019 static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0);
1020
1021EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL);
Corentin Chary04dcd842008-10-09 15:33:57 +02001022EEEPC_CREATE_SENSOR_ATTR(pwm1, S_IRUGO | S_IWUSR,
Corentin Charye1faa9d2008-03-13 12:57:18 +01001023 eeepc_get_fan_pwm, eeepc_set_fan_pwm);
1024EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1025 eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
1026
Corentin Chary04dcd842008-10-09 15:33:57 +02001027static ssize_t
1028show_name(struct device *dev, struct device_attribute *attr, char *buf)
1029{
1030 return sprintf(buf, "eeepc\n");
1031}
1032static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
1033
Corentin Charye1faa9d2008-03-13 12:57:18 +01001034static struct attribute *hwmon_attributes[] = {
Corentin Chary04dcd842008-10-09 15:33:57 +02001035 &sensor_dev_attr_pwm1.dev_attr.attr,
Corentin Charye1faa9d2008-03-13 12:57:18 +01001036 &sensor_dev_attr_fan1_input.dev_attr.attr,
1037 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
Corentin Chary04dcd842008-10-09 15:33:57 +02001038 &sensor_dev_attr_name.dev_attr.attr,
Corentin Charye1faa9d2008-03-13 12:57:18 +01001039 NULL
1040};
1041
1042static struct attribute_group hwmon_attribute_group = {
1043 .attrs = hwmon_attributes
1044};
1045
Alan Jenkins854c7832009-12-03 07:45:09 +00001046static void eeepc_hwmon_exit(struct eeepc_laptop *eeepc)
Corentin Charye1faa9d2008-03-13 12:57:18 +01001047{
1048 struct device *hwmon;
1049
Alan Jenkins854c7832009-12-03 07:45:09 +00001050 hwmon = eeepc->hwmon_device;
Corentin Charye1faa9d2008-03-13 12:57:18 +01001051 if (!hwmon)
Alan Jenkins854c7832009-12-03 07:45:09 +00001052 return;
Corentin Charye1faa9d2008-03-13 12:57:18 +01001053 sysfs_remove_group(&hwmon->kobj,
1054 &hwmon_attribute_group);
Matthew Garrettf1441312008-08-20 14:08:57 -07001055 hwmon_device_unregister(hwmon);
Alan Jenkins854c7832009-12-03 07:45:09 +00001056 eeepc->hwmon_device = NULL;
Corentin Charye1faa9d2008-03-13 12:57:18 +01001057}
1058
Alan Jenkins854c7832009-12-03 07:45:09 +00001059static int eeepc_hwmon_init(struct eeepc_laptop *eeepc)
Corentin Chary7de39382009-06-25 13:25:38 +02001060{
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001061 struct device *hwmon;
Corentin Chary7de39382009-06-25 13:25:38 +02001062 int result;
1063
Alan Jenkins854c7832009-12-03 07:45:09 +00001064 hwmon = hwmon_device_register(&eeepc->platform_device->dev);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001065 if (IS_ERR(hwmon)) {
1066 pr_err("Could not register eeepc hwmon device\n");
Alan Jenkins854c7832009-12-03 07:45:09 +00001067 eeepc->hwmon_device = NULL;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001068 return PTR_ERR(hwmon);
Corentin Chary7de39382009-06-25 13:25:38 +02001069 }
Alan Jenkins854c7832009-12-03 07:45:09 +00001070 eeepc->hwmon_device = hwmon;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001071 result = sysfs_create_group(&hwmon->kobj,
1072 &hwmon_attribute_group);
1073 if (result)
Alan Jenkins854c7832009-12-03 07:45:09 +00001074 eeepc_hwmon_exit(eeepc);
Corentin Chary7de39382009-06-25 13:25:38 +02001075 return result;
1076}
1077
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001078/*
1079 * Backlight device
1080 */
1081static int read_brightness(struct backlight_device *bd)
Corentin Charya5fa4292008-03-13 12:56:37 +01001082{
Alan Jenkins854c7832009-12-03 07:45:09 +00001083 struct eeepc_laptop *eeepc = bl_get_data(bd);
1084
1085 return get_acpi(eeepc, CM_ASL_PANELBRIGHT);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001086}
Corentin Charya5fa4292008-03-13 12:56:37 +01001087
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001088static int set_brightness(struct backlight_device *bd, int value)
1089{
Alan Jenkins854c7832009-12-03 07:45:09 +00001090 struct eeepc_laptop *eeepc = bl_get_data(bd);
1091
1092 return set_acpi(eeepc, CM_ASL_PANELBRIGHT, value);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001093}
Corentin Charya5fa4292008-03-13 12:56:37 +01001094
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001095static int update_bl_status(struct backlight_device *bd)
1096{
1097 return set_brightness(bd, bd->props.brightness);
1098}
Corentin Charya9df80c2009-01-20 16:17:40 +01001099
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001100static struct backlight_ops eeepcbl_ops = {
1101 .get_brightness = read_brightness,
1102 .update_status = update_bl_status,
1103};
Eric Coopere59f8792008-03-13 12:55:46 +01001104
Alan Jenkins854c7832009-12-03 07:45:09 +00001105static int eeepc_backlight_notify(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001106{
Alan Jenkins854c7832009-12-03 07:45:09 +00001107 struct backlight_device *bd = eeepc->backlight_device;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001108 int old = bd->props.brightness;
Eric Coopere59f8792008-03-13 12:55:46 +01001109
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001110 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
Eric Coopere59f8792008-03-13 12:55:46 +01001111
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001112 return old;
Eric Coopere59f8792008-03-13 12:55:46 +01001113}
1114
Alan Jenkins854c7832009-12-03 07:45:09 +00001115static int eeepc_backlight_init(struct eeepc_laptop *eeepc)
Corentin Charya5fa4292008-03-13 12:56:37 +01001116{
1117 struct backlight_device *bd;
1118
Alan Jenkins854c7832009-12-03 07:45:09 +00001119 bd = backlight_device_register(EEEPC_LAPTOP_FILE,
1120 &eeepc->platform_device->dev,
1121 eeepc, &eeepcbl_ops);
Corentin Charya5fa4292008-03-13 12:56:37 +01001122 if (IS_ERR(bd)) {
Joe Perches19b53282009-06-25 13:25:37 +02001123 pr_err("Could not register eeepc backlight device\n");
Alan Jenkins854c7832009-12-03 07:45:09 +00001124 eeepc->backlight_device = NULL;
Corentin Charya5fa4292008-03-13 12:56:37 +01001125 return PTR_ERR(bd);
1126 }
Alan Jenkins854c7832009-12-03 07:45:09 +00001127 eeepc->backlight_device = bd;
Corentin Charya5fa4292008-03-13 12:56:37 +01001128 bd->props.max_brightness = 15;
Alan Jenkins854c7832009-12-03 07:45:09 +00001129 bd->props.brightness = read_brightness(bd);
Corentin Charya5fa4292008-03-13 12:56:37 +01001130 bd->props.power = FB_BLANK_UNBLANK;
1131 backlight_update_status(bd);
1132 return 0;
1133}
1134
Alan Jenkins854c7832009-12-03 07:45:09 +00001135static void eeepc_backlight_exit(struct eeepc_laptop *eeepc)
Corentin Charye1faa9d2008-03-13 12:57:18 +01001136{
Alan Jenkins854c7832009-12-03 07:45:09 +00001137 if (eeepc->backlight_device)
1138 backlight_device_unregister(eeepc->backlight_device);
1139 eeepc->backlight_device = NULL;
Corentin Charye1faa9d2008-03-13 12:57:18 +01001140}
1141
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001142
1143/*
1144 * Input device (i.e. hotkeys)
1145 */
Alan Jenkins854c7832009-12-03 07:45:09 +00001146static struct key_entry *eeepc_get_entry_by_scancode(
1147 struct eeepc_laptop *eeepc,
1148 int code)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001149{
1150 struct key_entry *key;
1151
Alan Jenkins854c7832009-12-03 07:45:09 +00001152 for (key = eeepc->keymap; key->type != KE_END; key++)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001153 if (code == key->code)
1154 return key;
1155
1156 return NULL;
1157}
1158
Alan Jenkins854c7832009-12-03 07:45:09 +00001159static void eeepc_input_notify(struct eeepc_laptop *eeepc, int event)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001160{
1161 static struct key_entry *key;
1162
Alan Jenkins854c7832009-12-03 07:45:09 +00001163 key = eeepc_get_entry_by_scancode(eeepc, event);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001164 if (key) {
1165 switch (key->type) {
1166 case KE_KEY:
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001167 input_report_key(eeepc->inputdev, key->keycode,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001168 1);
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001169 input_sync(eeepc->inputdev);
1170 input_report_key(eeepc->inputdev, key->keycode,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001171 0);
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001172 input_sync(eeepc->inputdev);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001173 break;
1174 }
Eric Coopere59f8792008-03-13 12:55:46 +01001175 }
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001176}
1177
Alan Jenkins854c7832009-12-03 07:45:09 +00001178static struct key_entry *eeepc_get_entry_by_keycode(
1179 struct eeepc_laptop *eeepc, int code)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001180{
1181 struct key_entry *key;
1182
Alan Jenkins854c7832009-12-03 07:45:09 +00001183 for (key = eeepc->keymap; key->type != KE_END; key++)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001184 if (code == key->keycode && key->type == KE_KEY)
1185 return key;
1186
1187 return NULL;
1188}
1189
1190static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
1191{
Alan Jenkins854c7832009-12-03 07:45:09 +00001192 struct eeepc_laptop *eeepc = input_get_drvdata(dev);
1193 struct key_entry *key = eeepc_get_entry_by_scancode(eeepc, scancode);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001194
1195 if (key && key->type == KE_KEY) {
1196 *keycode = key->keycode;
1197 return 0;
1198 }
1199
1200 return -EINVAL;
1201}
1202
1203static int eeepc_setkeycode(struct input_dev *dev, int scancode, int keycode)
1204{
Alan Jenkins854c7832009-12-03 07:45:09 +00001205 struct eeepc_laptop *eeepc = input_get_drvdata(dev);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001206 struct key_entry *key;
1207 int old_keycode;
1208
1209 if (keycode < 0 || keycode > KEY_MAX)
1210 return -EINVAL;
1211
Alan Jenkins854c7832009-12-03 07:45:09 +00001212 key = eeepc_get_entry_by_scancode(eeepc, scancode);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001213 if (key && key->type == KE_KEY) {
1214 old_keycode = key->keycode;
1215 key->keycode = keycode;
1216 set_bit(keycode, dev->keybit);
Alan Jenkins854c7832009-12-03 07:45:09 +00001217 if (!eeepc_get_entry_by_keycode(eeepc, old_keycode))
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001218 clear_bit(old_keycode, dev->keybit);
1219 return 0;
1220 }
1221
1222 return -EINVAL;
Eric Coopere59f8792008-03-13 12:55:46 +01001223}
1224
Alan Jenkins854c7832009-12-03 07:45:09 +00001225static int eeepc_input_init(struct eeepc_laptop *eeepc)
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001226{
1227 const struct key_entry *key;
1228 int result;
1229
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001230 eeepc->inputdev = input_allocate_device();
1231 if (!eeepc->inputdev) {
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001232 pr_info("Unable to allocate input device\n");
1233 return -ENOMEM;
1234 }
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001235 eeepc->inputdev->name = "Asus EeePC extra buttons";
Alan Jenkins854c7832009-12-03 07:45:09 +00001236 eeepc->inputdev->dev.parent = &eeepc->platform_device->dev;
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001237 eeepc->inputdev->phys = EEEPC_LAPTOP_FILE "/input0";
1238 eeepc->inputdev->id.bustype = BUS_HOST;
1239 eeepc->inputdev->getkeycode = eeepc_getkeycode;
1240 eeepc->inputdev->setkeycode = eeepc_setkeycode;
Alan Jenkins854c7832009-12-03 07:45:09 +00001241 input_set_drvdata(eeepc->inputdev, eeepc);
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001242
Alan Jenkins854c7832009-12-03 07:45:09 +00001243 eeepc->keymap = kmemdup(eeepc_keymap, sizeof(eeepc_keymap),
1244 GFP_KERNEL);
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001245 for (key = eeepc_keymap; key->type != KE_END; key++) {
1246 switch (key->type) {
1247 case KE_KEY:
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001248 set_bit(EV_KEY, eeepc->inputdev->evbit);
1249 set_bit(key->keycode, eeepc->inputdev->keybit);
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001250 break;
1251 }
1252 }
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001253 result = input_register_device(eeepc->inputdev);
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001254 if (result) {
1255 pr_info("Unable to register input device\n");
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001256 input_free_device(eeepc->inputdev);
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001257 return result;
1258 }
1259 return 0;
1260}
1261
Alan Jenkins854c7832009-12-03 07:45:09 +00001262static void eeepc_input_exit(struct eeepc_laptop *eeepc)
Eric Coopere59f8792008-03-13 12:55:46 +01001263{
Alan Jenkins854c7832009-12-03 07:45:09 +00001264 if (eeepc->inputdev) {
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001265 input_unregister_device(eeepc->inputdev);
Alan Jenkins854c7832009-12-03 07:45:09 +00001266 kfree(eeepc->keymap);
1267 }
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001268}
Corentin Chary3c0eb512009-12-03 07:44:52 +00001269
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001270/*
1271 * ACPI driver
1272 */
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001273static void eeepc_acpi_notify(struct acpi_device *device, u32 event)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001274{
Alan Jenkins854c7832009-12-03 07:45:09 +00001275 struct eeepc_laptop *eeepc = acpi_driver_data(device);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001276 u16 count;
Corentin Chary3c0eb512009-12-03 07:44:52 +00001277
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001278 if (event > ACPI_MAX_SYS_NOTIFY)
1279 return;
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001280 count = eeepc->event_count[event % 128]++;
Alan Jenkins854c7832009-12-03 07:45:09 +00001281 acpi_bus_generate_proc_event(device, event, count);
1282 acpi_bus_generate_netlink_event(device->pnp.device_class,
1283 dev_name(&device->dev), event,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001284 count);
Corentin Chary3c0eb512009-12-03 07:44:52 +00001285
Alan Jenkins325fb8e2009-12-03 07:45:15 +00001286 /* Brightness events are special */
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001287 if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX) {
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001288
Alan Jenkins325fb8e2009-12-03 07:45:15 +00001289 /* Ignore them completely if the acpi video driver is used */
1290 if (eeepc->backlight_device != NULL) {
1291 int old_brightness, new_brightness;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001292
Alan Jenkins325fb8e2009-12-03 07:45:15 +00001293 /* Update the backlight device. */
1294 old_brightness = eeepc_backlight_notify(eeepc);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001295
Alan Jenkins325fb8e2009-12-03 07:45:15 +00001296 /* Convert event to keypress (obsolescent hack) */
1297 new_brightness = event - NOTIFY_BRN_MIN;
1298
1299 if (new_brightness < old_brightness) {
1300 event = NOTIFY_BRN_MIN; /* brightness down */
1301 } else if (new_brightness > old_brightness) {
1302 event = NOTIFY_BRN_MAX; /* brightness up */
1303 } else {
1304 /*
1305 * no change in brightness - already at min/max,
1306 * event will be desired value (or else ignored)
1307 */
1308 }
1309 eeepc_input_notify(eeepc, event);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001310 }
Alan Jenkins325fb8e2009-12-03 07:45:15 +00001311 } else {
1312 /* Everything else is a bona-fide keypress event */
1313 eeepc_input_notify(eeepc, event);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001314 }
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001315}
1316
Alan Jenkinsda8ba012010-01-06 22:07:37 +01001317static void eeepc_dmi_check(struct eeepc_laptop *eeepc)
1318{
1319 const char *model;
1320
Corentin Chary10ae4b52010-01-06 22:07:38 +01001321 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1322 if (!model)
1323 return;
1324
Alan Jenkinsda8ba012010-01-06 22:07:37 +01001325 /*
1326 * Blacklist for setting cpufv (cpu speed).
1327 *
1328 * EeePC 4G ("701") implements CFVS, but it is not supported
1329 * by the pre-installed OS, and the original option to change it
1330 * in the BIOS setup screen was removed in later versions.
1331 *
1332 * Judging by the lack of "Super Hybrid Engine" on Asus product pages,
1333 * this applies to all "701" models (4G/4G Surf/2G Surf).
1334 *
1335 * So Asus made a deliberate decision not to support it on this model.
1336 * We have several reports that using it can cause the system to hang
1337 *
1338 * The hang has also been reported on a "702" (Model name "8G"?).
1339 *
1340 * We avoid dmi_check_system() / dmi_match(), because they use
1341 * substring matching. We don't want to affect the "701SD"
1342 * and "701SDX" models, because they do support S.H.E.
1343 */
Alan Jenkinsda8ba012010-01-06 22:07:37 +01001344 if (strcmp(model, "701") == 0 || strcmp(model, "702") == 0) {
1345 eeepc->cpufv_disabled = true;
1346 pr_info("model %s does not officially support setting cpu "
1347 "speed\n", model);
1348 pr_info("cpufv disabled to avoid instability\n");
1349 }
Corentin Chary10ae4b52010-01-06 22:07:38 +01001350
1351 /*
1352 * Blacklist for wlan hotplug
1353 *
1354 * Eeepc 1005HA doesn't work like others models and don't need the
1355 * hotplug code. In fact, current hotplug code seems to unplug another
1356 * device...
1357 */
1358 if (strcmp(model, "1005HA") == 0) {
1359 eeepc->hotplug_disabled = true;
1360 pr_info("wlan hotplug disabled\n");
1361 }
Alan Jenkinsda8ba012010-01-06 22:07:37 +01001362}
1363
Alan Jenkins854c7832009-12-03 07:45:09 +00001364static void cmsg_quirk(struct eeepc_laptop *eeepc, int cm, const char *name)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001365{
1366 int dummy;
1367
1368 /* Some BIOSes do not report cm although it is avaliable.
1369 Check if cm_getv[cm] works and, if yes, assume cm should be set. */
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001370 if (!(eeepc->cm_supported & (1 << cm))
1371 && !read_acpi_int(eeepc->handle, cm_getv[cm], &dummy)) {
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001372 pr_info("%s (%x) not reported by BIOS,"
1373 " enabling anyway\n", name, 1 << cm);
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001374 eeepc->cm_supported |= 1 << cm;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001375 }
1376}
1377
Alan Jenkins854c7832009-12-03 07:45:09 +00001378static void cmsg_quirks(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001379{
Alan Jenkins854c7832009-12-03 07:45:09 +00001380 cmsg_quirk(eeepc, CM_ASL_LID, "LID");
1381 cmsg_quirk(eeepc, CM_ASL_TYPE, "TYPE");
1382 cmsg_quirk(eeepc, CM_ASL_PANELPOWER, "PANELPOWER");
1383 cmsg_quirk(eeepc, CM_ASL_TPD, "TPD");
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001384}
1385
Corentin Charyf90be872009-12-03 07:45:14 +00001386static int eeepc_acpi_init(struct eeepc_laptop *eeepc,
1387 struct acpi_device *device)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001388{
1389 unsigned int init_flags;
Eric Coopere59f8792008-03-13 12:55:46 +01001390 int result;
1391
Alan Jenkins854c7832009-12-03 07:45:09 +00001392 result = acpi_bus_get_status(device);
Alan Jenkins1e779852009-08-28 12:56:35 +00001393 if (result)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001394 return result;
Alan Jenkins854c7832009-12-03 07:45:09 +00001395 if (!device->status.present) {
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001396 pr_err("Hotkey device not present, aborting\n");
1397 return -ENODEV;
Eric Coopere59f8792008-03-13 12:55:46 +01001398 }
Corentin Chary7de39382009-06-25 13:25:38 +02001399
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001400 init_flags = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
1401 pr_notice("Hotkey init flags 0x%x\n", init_flags);
1402
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001403 if (write_acpi_int(eeepc->handle, "INIT", init_flags)) {
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001404 pr_err("Hotkey initialization failed\n");
1405 return -ENODEV;
1406 }
1407
1408 /* get control methods supported */
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001409 if (read_acpi_int(eeepc->handle, "CMSG", &eeepc->cm_supported)) {
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001410 pr_err("Get control methods supported failed\n");
1411 return -ENODEV;
1412 }
Alan Jenkins854c7832009-12-03 07:45:09 +00001413 cmsg_quirks(eeepc);
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001414 pr_info("Get control methods supported: 0x%x\n", eeepc->cm_supported);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001415
Corentin Chary3c0eb512009-12-03 07:44:52 +00001416 return 0;
1417}
1418
Alan Jenkins854c7832009-12-03 07:45:09 +00001419static void __devinit eeepc_enable_camera(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001420{
1421 /*
1422 * If the following call to set_acpi() fails, it's because there's no
1423 * camera so we can ignore the error.
1424 */
Alan Jenkins854c7832009-12-03 07:45:09 +00001425 if (get_acpi(eeepc, CM_ASL_CAMERA) == 0)
1426 set_acpi(eeepc, CM_ASL_CAMERA, 1);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001427}
1428
Alan Jenkins854c7832009-12-03 07:45:09 +00001429static bool eeepc_device_present;
1430
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001431static int __devinit eeepc_acpi_add(struct acpi_device *device)
Eric Coopere59f8792008-03-13 12:55:46 +01001432{
Alan Jenkins854c7832009-12-03 07:45:09 +00001433 struct eeepc_laptop *eeepc;
Eric Coopere59f8792008-03-13 12:55:46 +01001434 int result;
1435
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001436 pr_notice(EEEPC_LAPTOP_NAME "\n");
1437 eeepc = kzalloc(sizeof(struct eeepc_laptop), GFP_KERNEL);
1438 if (!eeepc)
Eric Coopere59f8792008-03-13 12:55:46 +01001439 return -ENOMEM;
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001440 eeepc->handle = device->handle;
1441 strcpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME);
1442 strcpy(acpi_device_class(device), EEEPC_ACPI_CLASS);
1443 device->driver_data = eeepc;
Eric Coopere59f8792008-03-13 12:55:46 +01001444
Alan Jenkinsda8ba012010-01-06 22:07:37 +01001445 eeepc_dmi_check(eeepc);
1446
Alan Jenkins854c7832009-12-03 07:45:09 +00001447 result = eeepc_acpi_init(eeepc, device);
Eric Coopere59f8792008-03-13 12:55:46 +01001448 if (result)
Alan Jenkins9db106b2009-12-03 07:45:06 +00001449 goto fail_platform;
Alan Jenkins854c7832009-12-03 07:45:09 +00001450 eeepc_enable_camera(eeepc);
Eric Coopere59f8792008-03-13 12:55:46 +01001451
Alan Jenkins854c7832009-12-03 07:45:09 +00001452 /*
1453 * Register the platform device first. It is used as a parent for the
1454 * sub-devices below.
1455 *
1456 * Note that if there are multiple instances of this ACPI device it
1457 * will bail out, because the platform device is registered with a
1458 * fixed name. Of course it doesn't make sense to have more than one,
1459 * and machine-specific scripts find the fixed name convenient. But
1460 * It's also good for us to exclude multiple instances because both
1461 * our hwmon and our wlan rfkill subdevice use global ACPI objects
1462 * (the EC and the wlan PCI slot respectively).
1463 */
1464 result = eeepc_platform_init(eeepc);
Eric Coopere59f8792008-03-13 12:55:46 +01001465 if (result)
Alan Jenkins9db106b2009-12-03 07:45:06 +00001466 goto fail_platform;
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001467
1468 if (!acpi_video_backlight_support()) {
Alan Jenkins854c7832009-12-03 07:45:09 +00001469 result = eeepc_backlight_init(eeepc);
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001470 if (result)
1471 goto fail_backlight;
1472 } else
Alan Jenkins9db106b2009-12-03 07:45:06 +00001473 pr_info("Backlight controlled by ACPI video driver\n");
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001474
Alan Jenkins854c7832009-12-03 07:45:09 +00001475 result = eeepc_input_init(eeepc);
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001476 if (result)
1477 goto fail_input;
1478
Alan Jenkins854c7832009-12-03 07:45:09 +00001479 result = eeepc_hwmon_init(eeepc);
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001480 if (result)
1481 goto fail_hwmon;
1482
Alan Jenkins854c7832009-12-03 07:45:09 +00001483 result = eeepc_led_init(eeepc);
Corentin Chary3c0eb512009-12-03 07:44:52 +00001484 if (result)
1485 goto fail_led;
1486
Alan Jenkins854c7832009-12-03 07:45:09 +00001487 result = eeepc_rfkill_init(eeepc);
Corentin Chary7de39382009-06-25 13:25:38 +02001488 if (result)
1489 goto fail_rfkill;
1490
Alan Jenkins854c7832009-12-03 07:45:09 +00001491 eeepc_device_present = true;
Eric Coopere59f8792008-03-13 12:55:46 +01001492 return 0;
Alan Jenkins1e779852009-08-28 12:56:35 +00001493
Corentin Chary7de39382009-06-25 13:25:38 +02001494fail_rfkill:
Alan Jenkins854c7832009-12-03 07:45:09 +00001495 eeepc_led_exit(eeepc);
Corentin Chary3c0eb512009-12-03 07:44:52 +00001496fail_led:
Alan Jenkins854c7832009-12-03 07:45:09 +00001497 eeepc_hwmon_exit(eeepc);
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001498fail_hwmon:
Alan Jenkins854c7832009-12-03 07:45:09 +00001499 eeepc_input_exit(eeepc);
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001500fail_input:
Alan Jenkins854c7832009-12-03 07:45:09 +00001501 eeepc_backlight_exit(eeepc);
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001502fail_backlight:
Alan Jenkins854c7832009-12-03 07:45:09 +00001503 eeepc_platform_exit(eeepc);
Alan Jenkins9db106b2009-12-03 07:45:06 +00001504fail_platform:
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001505 kfree(eeepc);
Alan Jenkins1e779852009-08-28 12:56:35 +00001506
Eric Coopere59f8792008-03-13 12:55:46 +01001507 return result;
1508}
1509
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001510static int eeepc_acpi_remove(struct acpi_device *device, int type)
Alan Jenkins1e779852009-08-28 12:56:35 +00001511{
Alan Jenkins854c7832009-12-03 07:45:09 +00001512 struct eeepc_laptop *eeepc = acpi_driver_data(device);
Alan Jenkins1e779852009-08-28 12:56:35 +00001513
Alan Jenkins854c7832009-12-03 07:45:09 +00001514 eeepc_backlight_exit(eeepc);
1515 eeepc_rfkill_exit(eeepc);
1516 eeepc_input_exit(eeepc);
1517 eeepc_hwmon_exit(eeepc);
1518 eeepc_led_exit(eeepc);
1519 eeepc_platform_exit(eeepc);
Alan Jenkins1e779852009-08-28 12:56:35 +00001520
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001521 kfree(eeepc);
Alan Jenkins1e779852009-08-28 12:56:35 +00001522 return 0;
1523}
1524
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001525
1526static const struct acpi_device_id eeepc_device_ids[] = {
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001527 {EEEPC_ACPI_HID, 0},
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001528 {"", 0},
1529};
1530MODULE_DEVICE_TABLE(acpi, eeepc_device_ids);
1531
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001532static struct acpi_driver eeepc_acpi_driver = {
1533 .name = EEEPC_LAPTOP_NAME,
1534 .class = EEEPC_ACPI_CLASS,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001535 .owner = THIS_MODULE,
1536 .ids = eeepc_device_ids,
1537 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1538 .ops = {
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001539 .add = eeepc_acpi_add,
1540 .remove = eeepc_acpi_remove,
1541 .notify = eeepc_acpi_notify,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001542 },
1543};
1544
1545
Alan Jenkins1e779852009-08-28 12:56:35 +00001546static int __init eeepc_laptop_init(void)
1547{
1548 int result;
1549
Alan Jenkins22072e92009-12-03 07:45:05 +00001550 result = platform_driver_register(&platform_driver);
Alan Jenkins1e779852009-08-28 12:56:35 +00001551 if (result < 0)
1552 return result;
Alan Jenkins22072e92009-12-03 07:45:05 +00001553
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001554 result = acpi_bus_register_driver(&eeepc_acpi_driver);
Alan Jenkins22072e92009-12-03 07:45:05 +00001555 if (result < 0)
1556 goto fail_acpi_driver;
Alan Jenkins854c7832009-12-03 07:45:09 +00001557 if (!eeepc_device_present) {
Alan Jenkins22072e92009-12-03 07:45:05 +00001558 result = -ENODEV;
1559 goto fail_no_device;
Alan Jenkins1e779852009-08-28 12:56:35 +00001560 }
1561 return 0;
Alan Jenkins22072e92009-12-03 07:45:05 +00001562
1563fail_no_device:
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001564 acpi_bus_unregister_driver(&eeepc_acpi_driver);
Alan Jenkins22072e92009-12-03 07:45:05 +00001565fail_acpi_driver:
1566 platform_driver_unregister(&platform_driver);
1567 return result;
Alan Jenkins1e779852009-08-28 12:56:35 +00001568}
1569
1570static void __exit eeepc_laptop_exit(void)
1571{
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001572 acpi_bus_unregister_driver(&eeepc_acpi_driver);
Alan Jenkins22072e92009-12-03 07:45:05 +00001573 platform_driver_unregister(&platform_driver);
Alan Jenkins1e779852009-08-28 12:56:35 +00001574}
1575
Eric Coopere59f8792008-03-13 12:55:46 +01001576module_init(eeepc_laptop_init);
1577module_exit(eeepc_laptop_exit);