blob: e6946a9beb5a352dd2ddbf967ed88ff9cef497eb [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Lv Zheng8b484632013-12-03 08:49:16 +080031#include <linux/acpi.h>
Eric Coopere59f8792008-03-13 12:55:46 +010032#include <linux/uaccess.h>
Matthew Garretta195dcd2008-08-19 12:13:20 +010033#include <linux/input.h>
Dmitry Torokhov642e0442010-01-06 22:07:39 +010034#include <linux/input/sparse-keymap.h>
Matthew Garretta195dcd2008-08-19 12:13:20 +010035#include <linux/rfkill.h>
Matthew Garrett57402942009-01-20 16:17:48 +010036#include <linux/pci.h>
Corentin Chary2b121bc2009-06-25 13:25:36 +020037#include <linux/pci_hotplug.h>
Corentin Chary3c0eb512009-12-03 07:44:52 +000038#include <linux/leds.h>
Alan Jenkinsda8ba012010-01-06 22:07:37 +010039#include <linux/dmi.h>
Hans de Goede21db4b12015-06-16 16:28:02 +020040#include <acpi/video.h>
Eric Coopere59f8792008-03-13 12:55:46 +010041
42#define EEEPC_LAPTOP_VERSION "0.1"
Alan Jenkinsa7624b62009-12-03 07:45:08 +000043#define EEEPC_LAPTOP_NAME "Eee PC Hotkey Driver"
44#define EEEPC_LAPTOP_FILE "eeepc"
Eric Coopere59f8792008-03-13 12:55:46 +010045
Alan Jenkinsa7624b62009-12-03 07:45:08 +000046#define EEEPC_ACPI_CLASS "hotkey"
47#define EEEPC_ACPI_DEVICE_NAME "Hotkey"
48#define EEEPC_ACPI_HID "ASUS010"
Eric Coopere59f8792008-03-13 12:55:46 +010049
Alan Jenkins52bbe3c2009-12-03 07:45:07 +000050MODULE_AUTHOR("Corentin Chary, Eric Cooper");
Alan Jenkinsa7624b62009-12-03 07:45:08 +000051MODULE_DESCRIPTION(EEEPC_LAPTOP_NAME);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +000052MODULE_LICENSE("GPL");
Eric Coopere59f8792008-03-13 12:55:46 +010053
Corentin Chary322a1352010-01-06 22:07:40 +010054static bool hotplug_disabled;
55
Axel Linbfa47962010-07-20 15:19:55 -070056module_param(hotplug_disabled, bool, 0444);
Corentin Chary322a1352010-01-06 22:07:40 +010057MODULE_PARM_DESC(hotplug_disabled,
58 "Disable hotplug for wireless device. "
59 "If your laptop need that, please report to "
60 "acpi4asus-user@lists.sourceforge.net.");
61
Eric Coopere59f8792008-03-13 12:55:46 +010062/*
63 * Definitions for Asus EeePC
64 */
Corentin Charya5fa4292008-03-13 12:56:37 +010065#define NOTIFY_BRN_MIN 0x20
66#define NOTIFY_BRN_MAX 0x2f
Eric Coopere59f8792008-03-13 12:55:46 +010067
68enum {
69 DISABLE_ASL_WLAN = 0x0001,
70 DISABLE_ASL_BLUETOOTH = 0x0002,
71 DISABLE_ASL_IRDA = 0x0004,
72 DISABLE_ASL_CAMERA = 0x0008,
73 DISABLE_ASL_TV = 0x0010,
74 DISABLE_ASL_GPS = 0x0020,
75 DISABLE_ASL_DISPLAYSWITCH = 0x0040,
76 DISABLE_ASL_MODEM = 0x0080,
Corentin Charyb7b700d2009-06-16 19:28:52 +000077 DISABLE_ASL_CARDREADER = 0x0100,
78 DISABLE_ASL_3G = 0x0200,
79 DISABLE_ASL_WIMAX = 0x0400,
80 DISABLE_ASL_HWCF = 0x0800
Eric Coopere59f8792008-03-13 12:55:46 +010081};
82
83enum {
84 CM_ASL_WLAN = 0,
85 CM_ASL_BLUETOOTH,
86 CM_ASL_IRDA,
87 CM_ASL_1394,
88 CM_ASL_CAMERA,
89 CM_ASL_TV,
90 CM_ASL_GPS,
91 CM_ASL_DVDROM,
92 CM_ASL_DISPLAYSWITCH,
93 CM_ASL_PANELBRIGHT,
94 CM_ASL_BIOSFLASH,
95 CM_ASL_ACPIFLASH,
96 CM_ASL_CPUFV,
97 CM_ASL_CPUTEMPERATURE,
98 CM_ASL_FANCPU,
99 CM_ASL_FANCHASSIS,
100 CM_ASL_USBPORT1,
101 CM_ASL_USBPORT2,
102 CM_ASL_USBPORT3,
103 CM_ASL_MODEM,
104 CM_ASL_CARDREADER,
Corentin Charyb7b700d2009-06-16 19:28:52 +0000105 CM_ASL_3G,
106 CM_ASL_WIMAX,
107 CM_ASL_HWCF,
108 CM_ASL_LID,
109 CM_ASL_TYPE,
110 CM_ASL_PANELPOWER, /*P901*/
111 CM_ASL_TPD
Eric Coopere59f8792008-03-13 12:55:46 +0100112};
113
Adrian Bunk14109462008-06-25 19:25:47 +0300114static const char *cm_getv[] = {
Jonathan McDowell3af9bfc2008-12-03 20:31:11 +0000115 "WLDG", "BTHG", NULL, NULL,
Eric Coopere59f8792008-03-13 12:55:46 +0100116 "CAMG", NULL, NULL, NULL,
117 NULL, "PBLG", NULL, NULL,
118 "CFVG", NULL, NULL, NULL,
119 "USBG", NULL, NULL, "MODG",
Corentin Charyb7b700d2009-06-16 19:28:52 +0000120 "CRDG", "M3GG", "WIMG", "HWCF",
121 "LIDG", "TYPE", "PBPG", "TPDG"
Eric Coopere59f8792008-03-13 12:55:46 +0100122};
123
Adrian Bunk14109462008-06-25 19:25:47 +0300124static const char *cm_setv[] = {
Jonathan McDowell3af9bfc2008-12-03 20:31:11 +0000125 "WLDS", "BTHS", NULL, NULL,
Eric Coopere59f8792008-03-13 12:55:46 +0100126 "CAMS", NULL, NULL, NULL,
127 "SDSP", "PBLS", "HDPS", NULL,
128 "CFVS", NULL, NULL, NULL,
129 "USBG", NULL, NULL, "MODS",
Corentin Charyb7b700d2009-06-16 19:28:52 +0000130 "CRDS", "M3GS", "WIMS", NULL,
131 NULL, NULL, "PBPS", "TPDS"
Eric Coopere59f8792008-03-13 12:55:46 +0100132};
133
Alan Jenkins854c7832009-12-03 07:45:09 +0000134static const struct key_entry eeepc_keymap[] = {
Dmitry Torokhov642e0442010-01-06 22:07:39 +0100135 { KE_KEY, 0x10, { KEY_WLAN } },
136 { KE_KEY, 0x11, { KEY_WLAN } },
137 { KE_KEY, 0x12, { KEY_PROG1 } },
138 { KE_KEY, 0x13, { KEY_MUTE } },
139 { KE_KEY, 0x14, { KEY_VOLUMEDOWN } },
140 { KE_KEY, 0x15, { KEY_VOLUMEUP } },
141 { KE_KEY, 0x16, { KEY_DISPLAY_OFF } },
142 { KE_KEY, 0x1a, { KEY_COFFEE } },
143 { KE_KEY, 0x1b, { KEY_ZOOM } },
144 { KE_KEY, 0x1c, { KEY_PROG2 } },
145 { KE_KEY, 0x1d, { KEY_PROG3 } },
146 { KE_KEY, NOTIFY_BRN_MIN, { KEY_BRIGHTNESSDOWN } },
147 { KE_KEY, NOTIFY_BRN_MAX, { KEY_BRIGHTNESSUP } },
148 { KE_KEY, 0x30, { KEY_SWITCHVIDEOMODE } },
149 { KE_KEY, 0x31, { KEY_SWITCHVIDEOMODE } },
150 { KE_KEY, 0x32, { KEY_SWITCHVIDEOMODE } },
151 { KE_KEY, 0x37, { KEY_F13 } }, /* Disable Touchpad */
152 { KE_KEY, 0x38, { KEY_F14 } },
Pau Espin Pedrol999ddbd2017-02-10 18:48:37 +0100153 { KE_IGNORE, 0x50, { KEY_RESERVED } }, /* AC plugged */
154 { KE_IGNORE, 0x51, { KEY_RESERVED } }, /* AC unplugged */
Dmitry Torokhov642e0442010-01-06 22:07:39 +0100155 { KE_END, 0 },
Matthew Garretta195dcd2008-08-19 12:13:20 +0100156};
157
Corentin Charya5fa4292008-03-13 12:56:37 +0100158/*
Eric Coopere59f8792008-03-13 12:55:46 +0100159 * This is the main structure, we can use it to store useful information
Corentin Charya5fa4292008-03-13 12:56:37 +0100160 */
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000161struct eeepc_laptop {
Alan Jenkins854c7832009-12-03 07:45:09 +0000162 acpi_handle handle; /* the handle of the acpi device */
Eric Coopere59f8792008-03-13 12:55:46 +0100163 u32 cm_supported; /* the control methods supported
164 by this BIOS */
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100165 bool cpufv_disabled;
Corentin Chary10ae4b52010-01-06 22:07:38 +0100166 bool hotplug_disabled;
Eric Coopere59f8792008-03-13 12:55:46 +0100167 u16 event_count[128]; /* count for each event */
Corentin Charya5fa4292008-03-13 12:56:37 +0100168
Alan Jenkins854c7832009-12-03 07:45:09 +0000169 struct platform_device *platform_device;
Corentin Chary71e687d2010-08-24 09:30:44 +0200170 struct acpi_device *device; /* the device we are in */
Alan Jenkins854c7832009-12-03 07:45:09 +0000171 struct backlight_device *backlight_device;
172
Eric Coopere59f8792008-03-13 12:55:46 +0100173 struct input_dev *inputdev;
Alan Jenkins854c7832009-12-03 07:45:09 +0000174
Eric Coopere59f8792008-03-13 12:55:46 +0100175 struct rfkill *wlan_rfkill;
176 struct rfkill *bluetooth_rfkill;
177 struct rfkill *wwan3g_rfkill;
178 struct rfkill *wimax_rfkill;
Alan Jenkins854c7832009-12-03 07:45:09 +0000179
Lukas Wunner125450f2018-09-08 09:59:01 +0200180 struct hotplug_slot hotplug_slot;
Eric Coopere59f8792008-03-13 12:55:46 +0100181 struct mutex hotplug_lock;
Alan Jenkins854c7832009-12-03 07:45:09 +0000182
183 struct led_classdev tpd_led;
184 int tpd_led_wk;
185 struct workqueue_struct *led_workqueue;
186 struct work_struct tpd_led_work;
Eric Coopere59f8792008-03-13 12:55:46 +0100187};
Eric Coopere59f8792008-03-13 12:55:46 +0100188
189/*
190 * ACPI Helpers
191 */
Alan Jenkins6b188a72009-12-03 07:45:02 +0000192static int write_acpi_int(acpi_handle handle, const char *method, int val)
Eric Coopere59f8792008-03-13 12:55:46 +0100193{
Eric Coopere59f8792008-03-13 12:55:46 +0100194 acpi_status status;
195
Zhang Ruifca41992013-09-03 08:31:51 +0800196 status = acpi_execute_simple_method(handle, (char *)method, val);
Eric Coopere59f8792008-03-13 12:55:46 +0100197
Eric Coopere59f8792008-03-13 12:55:46 +0100198 return (status == AE_OK ? 0 : -1);
199}
200
201static int read_acpi_int(acpi_handle handle, const char *method, int *val)
202{
203 acpi_status status;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400204 unsigned long long result;
Eric Coopere59f8792008-03-13 12:55:46 +0100205
206 status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
207 if (ACPI_FAILURE(status)) {
208 *val = -1;
209 return -1;
210 } else {
211 *val = result;
212 return 0;
213 }
214}
215
Alan Jenkins854c7832009-12-03 07:45:09 +0000216static int set_acpi(struct eeepc_laptop *eeepc, int cm, int value)
Eric Coopere59f8792008-03-13 12:55:46 +0100217{
Alan Jenkins13f70022009-12-03 07:44:59 +0000218 const char *method = cm_setv[cm];
219
220 if (method == NULL)
221 return -ENODEV;
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000222 if ((eeepc->cm_supported & (0x1 << cm)) == 0)
Alan Jenkins13f70022009-12-03 07:44:59 +0000223 return -ENODEV;
224
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000225 if (write_acpi_int(eeepc->handle, method, value))
Joe Perches22441ff2011-03-29 15:21:38 -0700226 pr_warn("Error writing %s\n", method);
Eric Coopere59f8792008-03-13 12:55:46 +0100227 return 0;
228}
229
Alan Jenkins854c7832009-12-03 07:45:09 +0000230static int get_acpi(struct eeepc_laptop *eeepc, int cm)
Eric Coopere59f8792008-03-13 12:55:46 +0100231{
Alan Jenkins13f70022009-12-03 07:44:59 +0000232 const char *method = cm_getv[cm];
233 int value;
234
235 if (method == NULL)
236 return -ENODEV;
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000237 if ((eeepc->cm_supported & (0x1 << cm)) == 0)
Alan Jenkins13f70022009-12-03 07:44:59 +0000238 return -ENODEV;
239
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000240 if (read_acpi_int(eeepc->handle, method, &value))
Joe Perches22441ff2011-03-29 15:21:38 -0700241 pr_warn("Error reading %s\n", method);
Eric Coopere59f8792008-03-13 12:55:46 +0100242 return value;
243}
244
Corentin Charyf90be872009-12-03 07:45:14 +0000245static int acpi_setter_handle(struct eeepc_laptop *eeepc, int cm,
246 acpi_handle *handle)
Alan Jenkins854c7832009-12-03 07:45:09 +0000247{
248 const char *method = cm_setv[cm];
249 acpi_status status;
250
251 if (method == NULL)
252 return -ENODEV;
253 if ((eeepc->cm_supported & (0x1 << cm)) == 0)
254 return -ENODEV;
255
256 status = acpi_get_handle(eeepc->handle, (char *)method,
Corentin Charyf90be872009-12-03 07:45:14 +0000257 handle);
Alan Jenkins854c7832009-12-03 07:45:09 +0000258 if (status != AE_OK) {
Joe Perches22441ff2011-03-29 15:21:38 -0700259 pr_warn("Error finding %s\n", method);
Alan Jenkins854c7832009-12-03 07:45:09 +0000260 return -ENODEV;
Eric Coopere59f8792008-03-13 12:55:46 +0100261 }
262 return 0;
263}
264
Pekka Enbergcede2cb2009-06-16 19:28:45 +0000265
Matthew Garretta195dcd2008-08-19 12:13:20 +0100266/*
Eric Coopere59f8792008-03-13 12:55:46 +0100267 * Sys helpers
268 */
Paul Bolle95369a72014-09-17 21:02:51 +0200269static int parse_arg(const char *buf, int *val)
Eric Coopere59f8792008-03-13 12:55:46 +0100270{
Eric Coopere59f8792008-03-13 12:55:46 +0100271 if (sscanf(buf, "%i", val) != 1)
272 return -EINVAL;
Paul Bolle95369a72014-09-17 21:02:51 +0200273 return 0;
Eric Coopere59f8792008-03-13 12:55:46 +0100274}
275
Alan Jenkins854c7832009-12-03 07:45:09 +0000276static ssize_t store_sys_acpi(struct device *dev, int cm,
277 const char *buf, size_t count)
Eric Coopere59f8792008-03-13 12:55:46 +0100278{
Alan Jenkins854c7832009-12-03 07:45:09 +0000279 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
Eric Coopere59f8792008-03-13 12:55:46 +0100280 int rv, value;
281
Paul Bolle95369a72014-09-17 21:02:51 +0200282 rv = parse_arg(buf, &value);
283 if (rv < 0)
284 return rv;
285 rv = set_acpi(eeepc, cm, value);
286 if (rv < 0)
Alan Jenkins6dff29b2009-12-03 07:44:45 +0000287 return -EIO;
Paul Bolle95369a72014-09-17 21:02:51 +0200288 return count;
Eric Coopere59f8792008-03-13 12:55:46 +0100289}
290
Alan Jenkins854c7832009-12-03 07:45:09 +0000291static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf)
Eric Coopere59f8792008-03-13 12:55:46 +0100292{
Alan Jenkins854c7832009-12-03 07:45:09 +0000293 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
294 int value = get_acpi(eeepc, cm);
Corentin Charyf36509e2009-06-25 13:25:40 +0200295
296 if (value < 0)
Alan Jenkins6dff29b2009-12-03 07:44:45 +0000297 return -EIO;
Corentin Charyf36509e2009-06-25 13:25:40 +0200298 return sprintf(buf, "%d\n", value);
Eric Coopere59f8792008-03-13 12:55:46 +0100299}
300
Frans Klaver97971322014-09-17 23:47:22 +0200301#define EEEPC_ACPI_SHOW_FUNC(_name, _cm) \
Frans Klaver8c72fc82014-09-17 23:47:20 +0200302 static ssize_t _name##_show(struct device *dev, \
Eric Coopere59f8792008-03-13 12:55:46 +0100303 struct device_attribute *attr, \
304 char *buf) \
305 { \
Alan Jenkins854c7832009-12-03 07:45:09 +0000306 return show_sys_acpi(dev, _cm, buf); \
Frans Klaver97971322014-09-17 23:47:22 +0200307 }
308
309#define EEEPC_ACPI_STORE_FUNC(_name, _cm) \
Frans Klaver8c72fc82014-09-17 23:47:20 +0200310 static ssize_t _name##_store(struct device *dev, \
Eric Coopere59f8792008-03-13 12:55:46 +0100311 struct device_attribute *attr, \
312 const char *buf, size_t count) \
313 { \
Alan Jenkins854c7832009-12-03 07:45:09 +0000314 return store_sys_acpi(dev, _cm, buf, count); \
Frans Klaver97971322014-09-17 23:47:22 +0200315 }
316
Frans Klaver6fe3a772014-09-17 23:47:23 +0200317#define EEEPC_CREATE_DEVICE_ATTR_RW(_name, _cm) \
Frans Klaver97971322014-09-17 23:47:22 +0200318 EEEPC_ACPI_SHOW_FUNC(_name, _cm) \
319 EEEPC_ACPI_STORE_FUNC(_name, _cm) \
Frans Klaver6fe3a772014-09-17 23:47:23 +0200320 static DEVICE_ATTR_RW(_name)
Eric Coopere59f8792008-03-13 12:55:46 +0100321
Frans Klaver6fe3a772014-09-17 23:47:23 +0200322#define EEEPC_CREATE_DEVICE_ATTR_WO(_name, _cm) \
323 EEEPC_ACPI_STORE_FUNC(_name, _cm) \
324 static DEVICE_ATTR_WO(_name)
325
326EEEPC_CREATE_DEVICE_ATTR_RW(camera, CM_ASL_CAMERA);
327EEEPC_CREATE_DEVICE_ATTR_RW(cardr, CM_ASL_CARDREADER);
328EEEPC_CREATE_DEVICE_ATTR_WO(disp, CM_ASL_DISPLAYSWITCH);
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000329
330struct eeepc_cpufv {
331 int num;
332 int cur;
333};
334
Alan Jenkins854c7832009-12-03 07:45:09 +0000335static int get_cpufv(struct eeepc_laptop *eeepc, struct eeepc_cpufv *c)
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000336{
Alan Jenkins854c7832009-12-03 07:45:09 +0000337 c->cur = get_acpi(eeepc, CM_ASL_CPUFV);
Frans Klavera5c155b2014-09-17 23:47:26 +0200338 if (c->cur < 0)
339 return -ENODEV;
340
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000341 c->num = (c->cur >> 8) & 0xff;
342 c->cur &= 0xff;
Frans Klavera5c155b2014-09-17 23:47:26 +0200343 if (c->num == 0 || c->num > 12)
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000344 return -ENODEV;
345 return 0;
346}
347
Frans Klaver8c72fc82014-09-17 23:47:20 +0200348static ssize_t available_cpufv_show(struct device *dev,
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000349 struct device_attribute *attr,
350 char *buf)
351{
Alan Jenkins854c7832009-12-03 07:45:09 +0000352 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000353 struct eeepc_cpufv c;
354 int i;
355 ssize_t len = 0;
356
Alan Jenkins854c7832009-12-03 07:45:09 +0000357 if (get_cpufv(eeepc, &c))
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000358 return -ENODEV;
359 for (i = 0; i < c.num; i++)
360 len += sprintf(buf + len, "%d ", i);
361 len += sprintf(buf + len, "\n");
362 return len;
363}
364
Frans Klaver8c72fc82014-09-17 23:47:20 +0200365static ssize_t cpufv_show(struct device *dev,
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000366 struct device_attribute *attr,
367 char *buf)
368{
Alan Jenkins854c7832009-12-03 07:45:09 +0000369 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000370 struct eeepc_cpufv c;
371
Alan Jenkins854c7832009-12-03 07:45:09 +0000372 if (get_cpufv(eeepc, &c))
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000373 return -ENODEV;
374 return sprintf(buf, "%#x\n", (c.num << 8) | c.cur);
375}
376
Frans Klaver8c72fc82014-09-17 23:47:20 +0200377static ssize_t cpufv_store(struct device *dev,
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000378 struct device_attribute *attr,
379 const char *buf, size_t count)
380{
Alan Jenkins854c7832009-12-03 07:45:09 +0000381 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000382 struct eeepc_cpufv c;
383 int rv, value;
384
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100385 if (eeepc->cpufv_disabled)
386 return -EPERM;
Alan Jenkins854c7832009-12-03 07:45:09 +0000387 if (get_cpufv(eeepc, &c))
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000388 return -ENODEV;
Paul Bolle95369a72014-09-17 21:02:51 +0200389 rv = parse_arg(buf, &value);
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000390 if (rv < 0)
391 return rv;
Paul Bolle95369a72014-09-17 21:02:51 +0200392 if (value < 0 || value >= c.num)
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000393 return -EINVAL;
Frans Klaverd4869032014-09-17 23:47:27 +0200394 rv = set_acpi(eeepc, CM_ASL_CPUFV, value);
395 if (rv)
396 return rv;
Paul Bolle95369a72014-09-17 21:02:51 +0200397 return count;
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000398}
399
Frans Klaver8c72fc82014-09-17 23:47:20 +0200400static ssize_t cpufv_disabled_show(struct device *dev,
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100401 struct device_attribute *attr,
402 char *buf)
403{
404 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
405
406 return sprintf(buf, "%d\n", eeepc->cpufv_disabled);
407}
408
Frans Klaver8c72fc82014-09-17 23:47:20 +0200409static ssize_t cpufv_disabled_store(struct device *dev,
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100410 struct device_attribute *attr,
411 const char *buf, size_t count)
412{
413 struct eeepc_laptop *eeepc = dev_get_drvdata(dev);
414 int rv, value;
415
Paul Bolle95369a72014-09-17 21:02:51 +0200416 rv = parse_arg(buf, &value);
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100417 if (rv < 0)
418 return rv;
419
420 switch (value) {
421 case 0:
422 if (eeepc->cpufv_disabled)
Frans Klaver9f662b22014-10-22 21:12:37 +0200423 pr_warn("cpufv enabled (not officially supported on this model)\n");
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100424 eeepc->cpufv_disabled = false;
Paul Bolle95369a72014-09-17 21:02:51 +0200425 return count;
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100426 case 1:
427 return -EPERM;
428 default:
429 return -EINVAL;
430 }
431}
432
433
Frans Klaverbb382db2014-09-17 23:47:21 +0200434static DEVICE_ATTR_RW(cpufv);
435static DEVICE_ATTR_RO(available_cpufv);
436static DEVICE_ATTR_RW(cpufv_disabled);
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100437
Eric Coopere59f8792008-03-13 12:55:46 +0100438static struct attribute *platform_attributes[] = {
439 &dev_attr_camera.attr,
440 &dev_attr_cardr.attr,
441 &dev_attr_disp.attr,
Grigori Goronzy158ca1d2009-04-27 09:23:40 +0200442 &dev_attr_cpufv.attr,
Corentin Charyb31d0fd2009-06-16 19:28:56 +0000443 &dev_attr_available_cpufv.attr,
Alan Jenkinsda8ba012010-01-06 22:07:37 +0100444 &dev_attr_cpufv_disabled.attr,
Eric Coopere59f8792008-03-13 12:55:46 +0100445 NULL
446};
447
Arvind Yadav130bbe62017-06-23 14:40:51 +0530448static const struct attribute_group platform_attribute_group = {
Eric Coopere59f8792008-03-13 12:55:46 +0100449 .attrs = platform_attributes
450};
451
Alan Jenkins854c7832009-12-03 07:45:09 +0000452static int eeepc_platform_init(struct eeepc_laptop *eeepc)
Matthew Garretta195dcd2008-08-19 12:13:20 +0100453{
Eric Coopere59f8792008-03-13 12:55:46 +0100454 int result;
455
Alan Jenkins854c7832009-12-03 07:45:09 +0000456 eeepc->platform_device = platform_device_alloc(EEEPC_LAPTOP_FILE, -1);
457 if (!eeepc->platform_device)
Alan Jenkins9db106b2009-12-03 07:45:06 +0000458 return -ENOMEM;
Alan Jenkins854c7832009-12-03 07:45:09 +0000459 platform_set_drvdata(eeepc->platform_device, eeepc);
Alan Jenkins9db106b2009-12-03 07:45:06 +0000460
Alan Jenkins854c7832009-12-03 07:45:09 +0000461 result = platform_device_add(eeepc->platform_device);
Eric Coopere59f8792008-03-13 12:55:46 +0100462 if (result)
Alan Jenkins9db106b2009-12-03 07:45:06 +0000463 goto fail_platform_device;
464
Alan Jenkins854c7832009-12-03 07:45:09 +0000465 result = sysfs_create_group(&eeepc->platform_device->dev.kobj,
Alan Jenkins9db106b2009-12-03 07:45:06 +0000466 &platform_attribute_group);
467 if (result)
468 goto fail_sysfs;
Eric Coopere59f8792008-03-13 12:55:46 +0100469 return 0;
Alan Jenkins9db106b2009-12-03 07:45:06 +0000470
471fail_sysfs:
Alan Jenkins854c7832009-12-03 07:45:09 +0000472 platform_device_del(eeepc->platform_device);
Alan Jenkins9db106b2009-12-03 07:45:06 +0000473fail_platform_device:
Alan Jenkins854c7832009-12-03 07:45:09 +0000474 platform_device_put(eeepc->platform_device);
Alan Jenkins9db106b2009-12-03 07:45:06 +0000475 return result;
Eric Coopere59f8792008-03-13 12:55:46 +0100476}
477
Alan Jenkins854c7832009-12-03 07:45:09 +0000478static void eeepc_platform_exit(struct eeepc_laptop *eeepc)
Corentin Charya5fa4292008-03-13 12:56:37 +0100479{
Alan Jenkins854c7832009-12-03 07:45:09 +0000480 sysfs_remove_group(&eeepc->platform_device->dev.kobj,
Alan Jenkins9db106b2009-12-03 07:45:06 +0000481 &platform_attribute_group);
Alan Jenkins854c7832009-12-03 07:45:09 +0000482 platform_device_unregister(eeepc->platform_device);
Alan Jenkins9db106b2009-12-03 07:45:06 +0000483}
484
Eric Coopere59f8792008-03-13 12:55:46 +0100485/*
Corentin Chary3c0eb512009-12-03 07:44:52 +0000486 * LEDs
487 */
488/*
489 * These functions actually update the LED's, and are called from a
490 * workqueue. By doing this as separate work rather than when the LED
491 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
492 * potentially bad time, such as a timer interrupt.
493 */
Alan Jenkins854c7832009-12-03 07:45:09 +0000494static void tpd_led_update(struct work_struct *work)
Joe Perches447a5642018-03-21 15:09:32 -0700495{
Alan Jenkins854c7832009-12-03 07:45:09 +0000496 struct eeepc_laptop *eeepc;
Corentin Chary3c0eb512009-12-03 07:44:52 +0000497
Alan Jenkins854c7832009-12-03 07:45:09 +0000498 eeepc = container_of(work, struct eeepc_laptop, tpd_led_work);
499
500 set_acpi(eeepc, CM_ASL_TPD, eeepc->tpd_led_wk);
Corentin Chary3c0eb512009-12-03 07:44:52 +0000501}
502
Corentin Chary3c0eb512009-12-03 07:44:52 +0000503static void tpd_led_set(struct led_classdev *led_cdev,
504 enum led_brightness value)
505{
Alan Jenkins854c7832009-12-03 07:45:09 +0000506 struct eeepc_laptop *eeepc;
507
508 eeepc = container_of(led_cdev, struct eeepc_laptop, tpd_led);
509
510 eeepc->tpd_led_wk = (value > 0) ? 1 : 0;
511 queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work);
Corentin Chary3c0eb512009-12-03 07:44:52 +0000512}
513
Corentin Chary62a75d832010-11-29 08:14:13 +0100514static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
515{
516 struct eeepc_laptop *eeepc;
517
518 eeepc = container_of(led_cdev, struct eeepc_laptop, tpd_led);
519
520 return get_acpi(eeepc, CM_ASL_TPD);
521}
522
Alan Jenkins854c7832009-12-03 07:45:09 +0000523static int eeepc_led_init(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000524{
525 int rv;
526
Alan Jenkins854c7832009-12-03 07:45:09 +0000527 if (get_acpi(eeepc, CM_ASL_TPD) == -ENODEV)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000528 return 0;
529
Alan Jenkins854c7832009-12-03 07:45:09 +0000530 eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue");
531 if (!eeepc->led_workqueue)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000532 return -ENOMEM;
Alan Jenkins854c7832009-12-03 07:45:09 +0000533 INIT_WORK(&eeepc->tpd_led_work, tpd_led_update);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000534
Alan Jenkins854c7832009-12-03 07:45:09 +0000535 eeepc->tpd_led.name = "eeepc::touchpad";
536 eeepc->tpd_led.brightness_set = tpd_led_set;
Corentin Chary62a75d832010-11-29 08:14:13 +0100537 if (get_acpi(eeepc, CM_ASL_TPD) >= 0) /* if method is available */
Frans Klaver39a3e172014-09-17 23:47:19 +0200538 eeepc->tpd_led.brightness_get = tpd_led_get;
Alan Jenkins854c7832009-12-03 07:45:09 +0000539 eeepc->tpd_led.max_brightness = 1;
540
541 rv = led_classdev_register(&eeepc->platform_device->dev,
542 &eeepc->tpd_led);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000543 if (rv) {
Alan Jenkins854c7832009-12-03 07:45:09 +0000544 destroy_workqueue(eeepc->led_workqueue);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000545 return rv;
Darren Salt64b86b62009-04-27 09:23:38 +0200546 }
Corentin Chary2b121bc2009-06-25 13:25:36 +0200547
548 return 0;
549}
550
Alan Jenkins854c7832009-12-03 07:45:09 +0000551static void eeepc_led_exit(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000552{
Axel Lin5d6afd152011-08-08 17:14:19 +0800553 if (!IS_ERR_OR_NULL(eeepc->tpd_led.dev))
Alan Jenkins854c7832009-12-03 07:45:09 +0000554 led_classdev_unregister(&eeepc->tpd_led);
555 if (eeepc->led_workqueue)
556 destroy_workqueue(eeepc->led_workqueue);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000557}
558
559
Corentin Chary3c0eb512009-12-03 07:44:52 +0000560/*
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000561 * PCI hotplug (for wlan rfkill)
Eric Coopere59f8792008-03-13 12:55:46 +0100562 */
Alan Jenkins854c7832009-12-03 07:45:09 +0000563static bool eeepc_wlan_rfkill_blocked(struct eeepc_laptop *eeepc)
Eric Coopere59f8792008-03-13 12:55:46 +0100564{
Alan Jenkins854c7832009-12-03 07:45:09 +0000565 if (get_acpi(eeepc, CM_ASL_WLAN) == 1)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000566 return false;
567 return true;
Corentin Charya5fa4292008-03-13 12:56:37 +0100568}
569
Matthew Garrett14fdb152011-05-09 10:44:01 -0400570static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle)
Matthew Garrett57402942009-01-20 16:17:48 +0100571{
Matthew Garrett14fdb152011-05-09 10:44:01 -0400572 struct pci_dev *port;
Matthew Garrett57402942009-01-20 16:17:48 +0100573 struct pci_dev *dev;
Alan Jenkins6d418392009-08-28 12:56:32 +0000574 struct pci_bus *bus;
Alan Jenkins854c7832009-12-03 07:45:09 +0000575 bool blocked = eeepc_wlan_rfkill_blocked(eeepc);
Alan Jenkinsbc9d24a2010-02-22 16:03:58 +0000576 bool absent;
577 u32 l;
Matthew Garrett57402942009-01-20 16:17:48 +0100578
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000579 if (eeepc->wlan_rfkill)
580 rfkill_set_sw_state(eeepc->wlan_rfkill, blocked);
Alan Jenkins6d418392009-08-28 12:56:32 +0000581
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000582 mutex_lock(&eeepc->hotplug_lock);
Rafael J. Wysocki8b9ec1d2014-01-10 15:27:08 +0100583 pci_lock_rescan_remove();
Alan Jenkinsdcf443b2009-08-28 12:56:33 +0000584
Lukas Wunner125450f2018-09-08 09:59:01 +0200585 if (!eeepc->hotplug_slot.ops)
Frans Klaver248d4902014-10-22 21:12:36 +0200586 goto out_unlock;
Matthew Garrett14fdb152011-05-09 10:44:01 -0400587
Frans Klaver248d4902014-10-22 21:12:36 +0200588 port = acpi_get_pci_dev(handle);
589 if (!port) {
590 pr_warning("Unable to find port\n");
591 goto out_unlock;
Matthew Garrett57402942009-01-20 16:17:48 +0100592 }
Alan Jenkinsdcf443b2009-08-28 12:56:33 +0000593
Frans Klaver248d4902014-10-22 21:12:36 +0200594 bus = port->subordinate;
595
596 if (!bus) {
597 pr_warn("Unable to find PCI bus 1?\n");
598 goto out_put_dev;
599 }
600
601 if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
602 pr_err("Unable to read PCI config space?\n");
603 goto out_put_dev;
604 }
605
606 absent = (l == 0xffffffff);
607
608 if (blocked != absent) {
Frans Klaver9f662b22014-10-22 21:12:37 +0200609 pr_warn("BIOS says wireless lan is %s, but the pci device is %s\n",
Frans Klaver248d4902014-10-22 21:12:36 +0200610 blocked ? "blocked" : "unblocked",
611 absent ? "absent" : "present");
Frans Klaver9f662b22014-10-22 21:12:37 +0200612 pr_warn("skipped wireless hotplug as probably inappropriate for this model\n");
Frans Klaver248d4902014-10-22 21:12:36 +0200613 goto out_put_dev;
614 }
615
616 if (!blocked) {
617 dev = pci_get_slot(bus, 0);
618 if (dev) {
619 /* Device already present */
620 pci_dev_put(dev);
621 goto out_put_dev;
622 }
623 dev = pci_scan_single_device(bus, 0);
624 if (dev) {
625 pci_bus_assign_resources(bus);
626 pci_bus_add_device(dev);
627 }
628 } else {
629 dev = pci_get_slot(bus, 0);
630 if (dev) {
631 pci_stop_and_remove_bus_device(dev);
632 pci_dev_put(dev);
633 }
634 }
635out_put_dev:
636 pci_dev_put(port);
637
Alan Jenkinsdcf443b2009-08-28 12:56:33 +0000638out_unlock:
Rafael J. Wysocki8b9ec1d2014-01-10 15:27:08 +0100639 pci_unlock_rescan_remove();
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000640 mutex_unlock(&eeepc->hotplug_lock);
Matthew Garrett57402942009-01-20 16:17:48 +0100641}
642
Matthew Garrett14fdb152011-05-09 10:44:01 -0400643static void eeepc_rfkill_hotplug_update(struct eeepc_laptop *eeepc, char *node)
644{
645 acpi_status status = AE_OK;
646 acpi_handle handle;
647
648 status = acpi_get_handle(NULL, node, &handle);
649
650 if (ACPI_SUCCESS(status))
651 eeepc_rfkill_hotplug(eeepc, handle);
652}
653
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100654static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
655{
Alan Jenkins854c7832009-12-03 07:45:09 +0000656 struct eeepc_laptop *eeepc = data;
657
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100658 if (event != ACPI_NOTIFY_BUS_CHECK)
659 return;
660
Matthew Garrett14fdb152011-05-09 10:44:01 -0400661 eeepc_rfkill_hotplug(eeepc, handle);
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100662}
663
Alan Jenkins854c7832009-12-03 07:45:09 +0000664static int eeepc_register_rfkill_notifier(struct eeepc_laptop *eeepc,
665 char *node)
Eric Coopere59f8792008-03-13 12:55:46 +0100666{
Alan Jenkins854c7832009-12-03 07:45:09 +0000667 acpi_status status;
Matthew Garrett57402942009-01-20 16:17:48 +0100668 acpi_handle handle;
669
670 status = acpi_get_handle(NULL, node, &handle);
671
Frans Klaver557b4542014-09-21 00:22:17 +0200672 if (ACPI_FAILURE(status))
Matthew Garrett57402942009-01-20 16:17:48 +0100673 return -ENODEV;
674
Frans Klaver557b4542014-09-21 00:22:17 +0200675 status = acpi_install_notify_handler(handle,
676 ACPI_SYSTEM_NOTIFY,
677 eeepc_rfkill_notify,
678 eeepc);
679 if (ACPI_FAILURE(status))
680 pr_warn("Failed to register notify on %s\n", node);
681
682 /*
683 * Refresh pci hotplug in case the rfkill state was
684 * changed during setup.
685 */
686 eeepc_rfkill_hotplug(eeepc, handle);
Matthew Garrett57402942009-01-20 16:17:48 +0100687 return 0;
688}
689
Alan Jenkins854c7832009-12-03 07:45:09 +0000690static void eeepc_unregister_rfkill_notifier(struct eeepc_laptop *eeepc,
691 char *node)
Matthew Garrett57402942009-01-20 16:17:48 +0100692{
693 acpi_status status = AE_OK;
694 acpi_handle handle;
695
696 status = acpi_get_handle(NULL, node, &handle);
697
Frans Klaver557b4542014-09-21 00:22:17 +0200698 if (ACPI_FAILURE(status))
699 return;
700
701 status = acpi_remove_notify_handler(handle,
702 ACPI_SYSTEM_NOTIFY,
703 eeepc_rfkill_notify);
704 if (ACPI_FAILURE(status))
705 pr_err("Error removing rfkill notify handler %s\n",
706 node);
707 /*
708 * Refresh pci hotplug in case the rfkill
709 * state was changed after
710 * eeepc_unregister_rfkill_notifier()
711 */
712 eeepc_rfkill_hotplug(eeepc, handle);
Matthew Garrett57402942009-01-20 16:17:48 +0100713}
714
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000715static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
716 u8 *value)
717{
Lukas Wunner125450f2018-09-08 09:59:01 +0200718 struct eeepc_laptop *eeepc;
719 int val;
720
721 eeepc = container_of(hotplug_slot, struct eeepc_laptop, hotplug_slot);
722 val = get_acpi(eeepc, CM_ASL_WLAN);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000723
724 if (val == 1 || val == 0)
725 *value = val;
726 else
727 return -EINVAL;
728
729 return 0;
730}
731
Lukas Wunner81c4b5b2018-09-08 09:59:01 +0200732static const struct hotplug_slot_ops eeepc_hotplug_slot_ops = {
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000733 .get_adapter_status = eeepc_get_adapter_status,
734 .get_power_status = eeepc_get_adapter_status,
735};
736
Alan Jenkins854c7832009-12-03 07:45:09 +0000737static int eeepc_setup_pci_hotplug(struct eeepc_laptop *eeepc)
Corentin Chary2b121bc2009-06-25 13:25:36 +0200738{
739 int ret = -ENOMEM;
740 struct pci_bus *bus = pci_find_bus(0, 1);
741
742 if (!bus) {
Joe Perches19b53282009-06-25 13:25:37 +0200743 pr_err("Unable to find wifi PCI bus\n");
Corentin Chary2b121bc2009-06-25 13:25:36 +0200744 return -ENODEV;
745 }
746
Lukas Wunner125450f2018-09-08 09:59:01 +0200747 eeepc->hotplug_slot.ops = &eeepc_hotplug_slot_ops;
Corentin Chary2b121bc2009-06-25 13:25:36 +0200748
Lukas Wunner125450f2018-09-08 09:59:01 +0200749 ret = pci_hp_register(&eeepc->hotplug_slot, bus, 0, "eeepc-wifi");
Corentin Chary2b121bc2009-06-25 13:25:36 +0200750 if (ret) {
Joe Perches19b53282009-06-25 13:25:37 +0200751 pr_err("Unable to register hotplug slot - %d\n", ret);
Corentin Chary2b121bc2009-06-25 13:25:36 +0200752 goto error_register;
753 }
754
755 return 0;
756
757error_register:
Lukas Wunner125450f2018-09-08 09:59:01 +0200758 eeepc->hotplug_slot.ops = NULL;
Corentin Chary2b121bc2009-06-25 13:25:36 +0200759 return ret;
760}
761
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000762/*
763 * Rfkill devices
764 */
765static int eeepc_rfkill_set(void *data, bool blocked)
766{
Alan Jenkins854c7832009-12-03 07:45:09 +0000767 acpi_handle handle = data;
768
769 return write_acpi_int(handle, NULL, !blocked);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000770}
771
772static const struct rfkill_ops eeepc_rfkill_ops = {
773 .set_block = eeepc_rfkill_set,
774};
775
Alan Jenkins854c7832009-12-03 07:45:09 +0000776static int eeepc_new_rfkill(struct eeepc_laptop *eeepc,
777 struct rfkill **rfkill,
778 const char *name,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000779 enum rfkill_type type, int cm)
780{
Alan Jenkins854c7832009-12-03 07:45:09 +0000781 acpi_handle handle;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000782 int result;
783
Alan Jenkins854c7832009-12-03 07:45:09 +0000784 result = acpi_setter_handle(eeepc, cm, &handle);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000785 if (result < 0)
786 return result;
787
Alan Jenkins854c7832009-12-03 07:45:09 +0000788 *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
789 &eeepc_rfkill_ops, handle);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000790
791 if (!*rfkill)
792 return -EINVAL;
793
Alan Jenkins854c7832009-12-03 07:45:09 +0000794 rfkill_init_sw_state(*rfkill, get_acpi(eeepc, cm) != 1);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000795 result = rfkill_register(*rfkill);
796 if (result) {
797 rfkill_destroy(*rfkill);
798 *rfkill = NULL;
799 return result;
800 }
801 return 0;
802}
803
Frans Klaver792bd2a2014-10-22 21:12:38 +0200804static char EEEPC_RFKILL_NODE_1[] = "\\_SB.PCI0.P0P5";
805static char EEEPC_RFKILL_NODE_2[] = "\\_SB.PCI0.P0P6";
806static char EEEPC_RFKILL_NODE_3[] = "\\_SB.PCI0.P0P7";
807
Alan Jenkins854c7832009-12-03 07:45:09 +0000808static void eeepc_rfkill_exit(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000809{
Frans Klaver792bd2a2014-10-22 21:12:38 +0200810 eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_1);
811 eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_2);
812 eeepc_unregister_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_3);
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000813 if (eeepc->wlan_rfkill) {
814 rfkill_unregister(eeepc->wlan_rfkill);
815 rfkill_destroy(eeepc->wlan_rfkill);
816 eeepc->wlan_rfkill = NULL;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000817 }
Matthew Garrett14fdb152011-05-09 10:44:01 -0400818
Lukas Wunner125450f2018-09-08 09:59:01 +0200819 if (eeepc->hotplug_slot.ops)
820 pci_hp_deregister(&eeepc->hotplug_slot);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000821
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000822 if (eeepc->bluetooth_rfkill) {
823 rfkill_unregister(eeepc->bluetooth_rfkill);
824 rfkill_destroy(eeepc->bluetooth_rfkill);
825 eeepc->bluetooth_rfkill = NULL;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000826 }
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000827 if (eeepc->wwan3g_rfkill) {
828 rfkill_unregister(eeepc->wwan3g_rfkill);
829 rfkill_destroy(eeepc->wwan3g_rfkill);
830 eeepc->wwan3g_rfkill = NULL;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000831 }
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000832 if (eeepc->wimax_rfkill) {
833 rfkill_unregister(eeepc->wimax_rfkill);
834 rfkill_destroy(eeepc->wimax_rfkill);
835 eeepc->wimax_rfkill = NULL;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000836 }
837}
838
Alan Jenkins854c7832009-12-03 07:45:09 +0000839static int eeepc_rfkill_init(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000840{
841 int result = 0;
842
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000843 mutex_init(&eeepc->hotplug_lock);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000844
Alan Jenkins854c7832009-12-03 07:45:09 +0000845 result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill,
846 "eeepc-wlan", RFKILL_TYPE_WLAN,
847 CM_ASL_WLAN);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000848
849 if (result && result != -ENODEV)
850 goto exit;
851
Alan Jenkins854c7832009-12-03 07:45:09 +0000852 result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill,
853 "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH,
854 CM_ASL_BLUETOOTH);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000855
856 if (result && result != -ENODEV)
857 goto exit;
858
Alan Jenkins854c7832009-12-03 07:45:09 +0000859 result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill,
860 "eeepc-wwan3g", RFKILL_TYPE_WWAN,
861 CM_ASL_3G);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000862
863 if (result && result != -ENODEV)
864 goto exit;
865
Alan Jenkins854c7832009-12-03 07:45:09 +0000866 result = eeepc_new_rfkill(eeepc, &eeepc->wimax_rfkill,
867 "eeepc-wimax", RFKILL_TYPE_WIMAX,
868 CM_ASL_WIMAX);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000869
870 if (result && result != -ENODEV)
871 goto exit;
872
Corentin Chary10ae4b52010-01-06 22:07:38 +0100873 if (eeepc->hotplug_disabled)
874 return 0;
875
Alan Jenkins854c7832009-12-03 07:45:09 +0000876 result = eeepc_setup_pci_hotplug(eeepc);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000877 /*
878 * If we get -EBUSY then something else is handling the PCI hotplug -
879 * don't fail in this case
880 */
881 if (result == -EBUSY)
882 result = 0;
883
Frans Klaver792bd2a2014-10-22 21:12:38 +0200884 eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_1);
885 eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_2);
886 eeepc_register_rfkill_notifier(eeepc, EEEPC_RFKILL_NODE_3);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000887
888exit:
889 if (result && result != -ENODEV)
Alan Jenkins854c7832009-12-03 07:45:09 +0000890 eeepc_rfkill_exit(eeepc);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000891 return result;
892}
893
894/*
895 * Platform driver - hibernate/resume callbacks
896 */
Alan Jenkinsc200da52009-08-28 12:56:40 +0000897static int eeepc_hotk_thaw(struct device *device)
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100898{
Alan Jenkins854c7832009-12-03 07:45:09 +0000899 struct eeepc_laptop *eeepc = dev_get_drvdata(device);
900
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000901 if (eeepc->wlan_rfkill) {
Frans Klaverefef8722014-10-22 21:12:43 +0200902 int wlan;
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100903
Alan Jenkinsc1edd992009-08-28 12:56:39 +0000904 /*
905 * Work around bios bug - acpi _PTS turns off the wireless led
906 * during suspend. Normally it restores it on resume, but
Alan Jenkinsc200da52009-08-28 12:56:40 +0000907 * we should kick it ourselves in case hibernation is aborted.
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100908 */
Alan Jenkins854c7832009-12-03 07:45:09 +0000909 wlan = get_acpi(eeepc, CM_ASL_WLAN);
Frans Klaverefef8722014-10-22 21:12:43 +0200910 if (wlan >= 0)
911 set_acpi(eeepc, CM_ASL_WLAN, wlan);
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100912 }
913
Alan Jenkinsc200da52009-08-28 12:56:40 +0000914 return 0;
915}
916
917static int eeepc_hotk_restore(struct device *device)
918{
Alan Jenkins854c7832009-12-03 07:45:09 +0000919 struct eeepc_laptop *eeepc = dev_get_drvdata(device);
Alan Jenkinsc200da52009-08-28 12:56:40 +0000920
Alan Jenkins96e9cfe2009-06-16 14:53:52 +0100921 /* Refresh both wlan rfkill state and pci hotplug */
Matthew Garrett14fdb152011-05-09 10:44:01 -0400922 if (eeepc->wlan_rfkill) {
Frans Klaver792bd2a2014-10-22 21:12:38 +0200923 eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_1);
924 eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_2);
925 eeepc_rfkill_hotplug_update(eeepc, EEEPC_RFKILL_NODE_3);
Matthew Garrett14fdb152011-05-09 10:44:01 -0400926 }
Corentin Charye1faa9d2008-03-13 12:57:18 +0100927
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000928 if (eeepc->bluetooth_rfkill)
929 rfkill_set_sw_state(eeepc->bluetooth_rfkill,
Alan Jenkins854c7832009-12-03 07:45:09 +0000930 get_acpi(eeepc, CM_ASL_BLUETOOTH) != 1);
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000931 if (eeepc->wwan3g_rfkill)
932 rfkill_set_sw_state(eeepc->wwan3g_rfkill,
Alan Jenkins854c7832009-12-03 07:45:09 +0000933 get_acpi(eeepc, CM_ASL_3G) != 1);
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000934 if (eeepc->wimax_rfkill)
935 rfkill_set_sw_state(eeepc->wimax_rfkill,
Alan Jenkins854c7832009-12-03 07:45:09 +0000936 get_acpi(eeepc, CM_ASL_WIMAX) != 1);
Corentin Charye1faa9d2008-03-13 12:57:18 +0100937
938 return 0;
939}
940
Len Brown9a3bff22009-12-15 22:34:48 -0500941static const struct dev_pm_ops eeepc_pm_ops = {
Alan Jenkins854c7832009-12-03 07:45:09 +0000942 .thaw = eeepc_hotk_thaw,
943 .restore = eeepc_hotk_restore,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000944};
945
946static struct platform_driver platform_driver = {
947 .driver = {
Alan Jenkinsa7624b62009-12-03 07:45:08 +0000948 .name = EEEPC_LAPTOP_FILE,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000949 .pm = &eeepc_pm_ops,
950 }
951};
952
Eric Coopere59f8792008-03-13 12:55:46 +0100953/*
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000954 * Hwmon device
Eric Coopere59f8792008-03-13 12:55:46 +0100955 */
Alan Jenkins52bbe3c2009-12-03 07:45:07 +0000956
957#define EEEPC_EC_SC00 0x61
958#define EEEPC_EC_FAN_PWM (EEEPC_EC_SC00 + 2) /* Fan PWM duty cycle (%) */
959#define EEEPC_EC_FAN_HRPM (EEEPC_EC_SC00 + 5) /* High byte, fan speed (RPM) */
960#define EEEPC_EC_FAN_LRPM (EEEPC_EC_SC00 + 6) /* Low byte, fan speed (RPM) */
961
962#define EEEPC_EC_SFB0 0xD0
963#define EEEPC_EC_FAN_CTRL (EEEPC_EC_SFB0 + 3) /* Byte containing SF25 */
964
Frans Klaver148a5dd2014-10-22 21:12:42 +0200965static inline int eeepc_pwm_to_lmsensors(int value)
966{
967 return value * 255 / 100;
968}
969
970static inline int eeepc_lmsensors_to_pwm(int value)
971{
972 value = clamp_val(value, 0, 255);
973 return value * 100 / 255;
974}
975
Corentin Charye1faa9d2008-03-13 12:57:18 +0100976static int eeepc_get_fan_pwm(void)
977{
Alan Jenkins463b4e42009-12-03 07:45:03 +0000978 u8 value = 0;
Corentin Charye1faa9d2008-03-13 12:57:18 +0100979
Alan Jenkins463b4e42009-12-03 07:45:03 +0000980 ec_read(EEEPC_EC_FAN_PWM, &value);
Frans Klaver148a5dd2014-10-22 21:12:42 +0200981 return eeepc_pwm_to_lmsensors(value);
Corentin Charye1faa9d2008-03-13 12:57:18 +0100982}
983
984static void eeepc_set_fan_pwm(int value)
985{
Frans Klaver148a5dd2014-10-22 21:12:42 +0200986 value = eeepc_lmsensors_to_pwm(value);
Alan Jenkins463b4e42009-12-03 07:45:03 +0000987 ec_write(EEEPC_EC_FAN_PWM, value);
Corentin Charye1faa9d2008-03-13 12:57:18 +0100988}
989
990static int eeepc_get_fan_rpm(void)
991{
Alan Jenkins463b4e42009-12-03 07:45:03 +0000992 u8 high = 0;
993 u8 low = 0;
Corentin Charye1faa9d2008-03-13 12:57:18 +0100994
Alan Jenkins463b4e42009-12-03 07:45:03 +0000995 ec_read(EEEPC_EC_FAN_HRPM, &high);
996 ec_read(EEEPC_EC_FAN_LRPM, &low);
997 return high << 8 | low;
Corentin Charye1faa9d2008-03-13 12:57:18 +0100998}
999
Frans Klavera5de6812014-10-22 21:12:41 +02001000#define EEEPC_EC_FAN_CTRL_BIT 0x02
1001#define EEEPC_FAN_CTRL_MANUAL 1
1002#define EEEPC_FAN_CTRL_AUTO 2
1003
Corentin Charye1faa9d2008-03-13 12:57:18 +01001004static int eeepc_get_fan_ctrl(void)
1005{
Alan Jenkins463b4e42009-12-03 07:45:03 +00001006 u8 value = 0;
Corentin Charye1faa9d2008-03-13 12:57:18 +01001007
Alan Jenkins463b4e42009-12-03 07:45:03 +00001008 ec_read(EEEPC_EC_FAN_CTRL, &value);
Frans Klavera5de6812014-10-22 21:12:41 +02001009 if (value & EEEPC_EC_FAN_CTRL_BIT)
1010 return EEEPC_FAN_CTRL_MANUAL;
Alan Jenkins48718682009-12-03 07:44:56 +00001011 else
Frans Klavera5de6812014-10-22 21:12:41 +02001012 return EEEPC_FAN_CTRL_AUTO;
Corentin Charye1faa9d2008-03-13 12:57:18 +01001013}
1014
1015static void eeepc_set_fan_ctrl(int manual)
1016{
Alan Jenkins463b4e42009-12-03 07:45:03 +00001017 u8 value = 0;
Corentin Charye1faa9d2008-03-13 12:57:18 +01001018
Alan Jenkins463b4e42009-12-03 07:45:03 +00001019 ec_read(EEEPC_EC_FAN_CTRL, &value);
Frans Klavera5de6812014-10-22 21:12:41 +02001020 if (manual == EEEPC_FAN_CTRL_MANUAL)
1021 value |= EEEPC_EC_FAN_CTRL_BIT;
Corentin Charye1faa9d2008-03-13 12:57:18 +01001022 else
Frans Klavera5de6812014-10-22 21:12:41 +02001023 value &= ~EEEPC_EC_FAN_CTRL_BIT;
Alan Jenkins463b4e42009-12-03 07:45:03 +00001024 ec_write(EEEPC_EC_FAN_CTRL, value);
Corentin Charye1faa9d2008-03-13 12:57:18 +01001025}
1026
1027static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
1028{
1029 int rv, value;
1030
Paul Bolle95369a72014-09-17 21:02:51 +02001031 rv = parse_arg(buf, &value);
1032 if (rv < 0)
1033 return rv;
1034 set(value);
1035 return count;
Corentin Charye1faa9d2008-03-13 12:57:18 +01001036}
1037
1038static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
1039{
1040 return sprintf(buf, "%d\n", get());
1041}
1042
Frans Klaver28ac85f2014-09-17 23:47:24 +02001043#define EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
Frans Klaver48d4a5b2014-09-17 23:47:25 +02001044 static ssize_t _name##_show(struct device *dev, \
Corentin Charye1faa9d2008-03-13 12:57:18 +01001045 struct device_attribute *attr, \
1046 char *buf) \
1047 { \
Paul Bolle1ec9d392014-06-17 14:06:30 +02001048 return show_sys_hwmon(_get, buf); \
Frans Klaver28ac85f2014-09-17 23:47:24 +02001049 }
1050
1051#define EEEPC_SENSOR_STORE_FUNC(_name, _set) \
Frans Klaver48d4a5b2014-09-17 23:47:25 +02001052 static ssize_t _name##_store(struct device *dev, \
Corentin Charye1faa9d2008-03-13 12:57:18 +01001053 struct device_attribute *attr, \
1054 const char *buf, size_t count) \
1055 { \
Paul Bolle1ec9d392014-06-17 14:06:30 +02001056 return store_sys_hwmon(_set, buf, count); \
Frans Klaver28ac85f2014-09-17 23:47:24 +02001057 }
1058
Frans Klaver48d4a5b2014-09-17 23:47:25 +02001059#define EEEPC_CREATE_SENSOR_ATTR_RW(_name, _get, _set) \
Frans Klaver28ac85f2014-09-17 23:47:24 +02001060 EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
1061 EEEPC_SENSOR_STORE_FUNC(_name, _set) \
Frans Klaver48d4a5b2014-09-17 23:47:25 +02001062 static DEVICE_ATTR_RW(_name)
Corentin Charye1faa9d2008-03-13 12:57:18 +01001063
Frans Klaver48d4a5b2014-09-17 23:47:25 +02001064#define EEEPC_CREATE_SENSOR_ATTR_RO(_name, _get) \
1065 EEEPC_SENSOR_SHOW_FUNC(_name, _get) \
1066 static DEVICE_ATTR_RO(_name)
1067
1068EEEPC_CREATE_SENSOR_ATTR_RO(fan1_input, eeepc_get_fan_rpm);
1069EEEPC_CREATE_SENSOR_ATTR_RW(pwm1, eeepc_get_fan_pwm,
1070 eeepc_set_fan_pwm);
1071EEEPC_CREATE_SENSOR_ATTR_RW(pwm1_enable, eeepc_get_fan_ctrl,
1072 eeepc_set_fan_ctrl);
Corentin Charye1faa9d2008-03-13 12:57:18 +01001073
Guenter Roeckf0c34c92013-11-23 11:03:21 -08001074static struct attribute *hwmon_attrs[] = {
1075 &dev_attr_pwm1.attr,
1076 &dev_attr_fan1_input.attr,
1077 &dev_attr_pwm1_enable.attr,
Corentin Charye1faa9d2008-03-13 12:57:18 +01001078 NULL
1079};
Guenter Roeckf0c34c92013-11-23 11:03:21 -08001080ATTRIBUTE_GROUPS(hwmon);
Corentin Charye1faa9d2008-03-13 12:57:18 +01001081
Alan Jenkins854c7832009-12-03 07:45:09 +00001082static int eeepc_hwmon_init(struct eeepc_laptop *eeepc)
Corentin Chary7de39382009-06-25 13:25:38 +02001083{
Guenter Roeckf0c34c92013-11-23 11:03:21 -08001084 struct device *dev = &eeepc->platform_device->dev;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001085 struct device *hwmon;
Corentin Chary7de39382009-06-25 13:25:38 +02001086
Guenter Roeckf0c34c92013-11-23 11:03:21 -08001087 hwmon = devm_hwmon_device_register_with_groups(dev, "eeepc", NULL,
1088 hwmon_groups);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001089 if (IS_ERR(hwmon)) {
1090 pr_err("Could not register eeepc hwmon device\n");
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001091 return PTR_ERR(hwmon);
Corentin Chary7de39382009-06-25 13:25:38 +02001092 }
Guenter Roeckf0c34c92013-11-23 11:03:21 -08001093 return 0;
Corentin Chary7de39382009-06-25 13:25:38 +02001094}
1095
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001096/*
1097 * Backlight device
1098 */
1099static int read_brightness(struct backlight_device *bd)
Corentin Charya5fa4292008-03-13 12:56:37 +01001100{
Alan Jenkins854c7832009-12-03 07:45:09 +00001101 struct eeepc_laptop *eeepc = bl_get_data(bd);
1102
1103 return get_acpi(eeepc, CM_ASL_PANELBRIGHT);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001104}
Corentin Charya5fa4292008-03-13 12:56:37 +01001105
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001106static int set_brightness(struct backlight_device *bd, int value)
1107{
Alan Jenkins854c7832009-12-03 07:45:09 +00001108 struct eeepc_laptop *eeepc = bl_get_data(bd);
1109
1110 return set_acpi(eeepc, CM_ASL_PANELBRIGHT, value);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001111}
Corentin Charya5fa4292008-03-13 12:56:37 +01001112
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001113static int update_bl_status(struct backlight_device *bd)
1114{
1115 return set_brightness(bd, bd->props.brightness);
1116}
Corentin Charya9df80c2009-01-20 16:17:40 +01001117
Lionel Debrouxacc24722010-11-16 14:14:02 +01001118static const struct backlight_ops eeepcbl_ops = {
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001119 .get_brightness = read_brightness,
1120 .update_status = update_bl_status,
1121};
Eric Coopere59f8792008-03-13 12:55:46 +01001122
Alan Jenkins854c7832009-12-03 07:45:09 +00001123static int eeepc_backlight_notify(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001124{
Alan Jenkins854c7832009-12-03 07:45:09 +00001125 struct backlight_device *bd = eeepc->backlight_device;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001126 int old = bd->props.brightness;
Eric Coopere59f8792008-03-13 12:55:46 +01001127
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001128 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
Eric Coopere59f8792008-03-13 12:55:46 +01001129
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001130 return old;
Eric Coopere59f8792008-03-13 12:55:46 +01001131}
1132
Alan Jenkins854c7832009-12-03 07:45:09 +00001133static int eeepc_backlight_init(struct eeepc_laptop *eeepc)
Corentin Charya5fa4292008-03-13 12:56:37 +01001134{
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001135 struct backlight_properties props;
Corentin Charya5fa4292008-03-13 12:56:37 +01001136 struct backlight_device *bd;
1137
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001138 memset(&props, 0, sizeof(struct backlight_properties));
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001139 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001140 props.max_brightness = 15;
Alan Jenkins854c7832009-12-03 07:45:09 +00001141 bd = backlight_device_register(EEEPC_LAPTOP_FILE,
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001142 &eeepc->platform_device->dev, eeepc,
1143 &eeepcbl_ops, &props);
Corentin Charya5fa4292008-03-13 12:56:37 +01001144 if (IS_ERR(bd)) {
Joe Perches19b53282009-06-25 13:25:37 +02001145 pr_err("Could not register eeepc backlight device\n");
Alan Jenkins854c7832009-12-03 07:45:09 +00001146 eeepc->backlight_device = NULL;
Corentin Charya5fa4292008-03-13 12:56:37 +01001147 return PTR_ERR(bd);
1148 }
Alan Jenkins854c7832009-12-03 07:45:09 +00001149 eeepc->backlight_device = bd;
Alan Jenkins854c7832009-12-03 07:45:09 +00001150 bd->props.brightness = read_brightness(bd);
Corentin Charya5fa4292008-03-13 12:56:37 +01001151 bd->props.power = FB_BLANK_UNBLANK;
1152 backlight_update_status(bd);
1153 return 0;
1154}
1155
Alan Jenkins854c7832009-12-03 07:45:09 +00001156static void eeepc_backlight_exit(struct eeepc_laptop *eeepc)
Corentin Charye1faa9d2008-03-13 12:57:18 +01001157{
Markus Elfring00981812014-11-24 20:30:29 +01001158 backlight_device_unregister(eeepc->backlight_device);
Alan Jenkins854c7832009-12-03 07:45:09 +00001159 eeepc->backlight_device = NULL;
Corentin Charye1faa9d2008-03-13 12:57:18 +01001160}
1161
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001162
1163/*
1164 * Input device (i.e. hotkeys)
1165 */
Alan Jenkins854c7832009-12-03 07:45:09 +00001166static int eeepc_input_init(struct eeepc_laptop *eeepc)
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001167{
Dmitry Torokhov642e0442010-01-06 22:07:39 +01001168 struct input_dev *input;
1169 int error;
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001170
Dmitry Torokhov642e0442010-01-06 22:07:39 +01001171 input = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07001172 if (!input)
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001173 return -ENOMEM;
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001174
Dmitry Torokhov642e0442010-01-06 22:07:39 +01001175 input->name = "Asus EeePC extra buttons";
1176 input->phys = EEEPC_LAPTOP_FILE "/input0";
1177 input->id.bustype = BUS_HOST;
1178 input->dev.parent = &eeepc->platform_device->dev;
1179
1180 error = sparse_keymap_setup(input, eeepc_keymap, NULL);
1181 if (error) {
1182 pr_err("Unable to setup input device keymap\n");
1183 goto err_free_dev;
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001184 }
Dmitry Torokhov642e0442010-01-06 22:07:39 +01001185
1186 error = input_register_device(input);
1187 if (error) {
1188 pr_err("Unable to register input device\n");
Michał Kępieńde3c91c2017-03-09 13:11:42 +01001189 goto err_free_dev;
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001190 }
Dmitry Torokhov642e0442010-01-06 22:07:39 +01001191
1192 eeepc->inputdev = input;
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001193 return 0;
Dmitry Torokhov642e0442010-01-06 22:07:39 +01001194
Corentin Chary71e687d2010-08-24 09:30:44 +02001195err_free_dev:
Dmitry Torokhov642e0442010-01-06 22:07:39 +01001196 input_free_device(input);
1197 return error;
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001198}
1199
Alan Jenkins854c7832009-12-03 07:45:09 +00001200static void eeepc_input_exit(struct eeepc_laptop *eeepc)
Eric Coopere59f8792008-03-13 12:55:46 +01001201{
Michał Kępieńde3c91c2017-03-09 13:11:42 +01001202 if (eeepc->inputdev)
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001203 input_unregister_device(eeepc->inputdev);
Corentin Chary71e687d2010-08-24 09:30:44 +02001204 eeepc->inputdev = NULL;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001205}
Corentin Chary3c0eb512009-12-03 07:44:52 +00001206
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001207/*
1208 * ACPI driver
1209 */
Corentin Charyce6c4682011-12-15 08:27:32 +01001210static void eeepc_input_notify(struct eeepc_laptop *eeepc, int event)
1211{
1212 if (!eeepc->inputdev)
Frans Klaverfb1d97a2014-11-02 22:14:58 +01001213 return;
Corentin Charyce6c4682011-12-15 08:27:32 +01001214 if (!sparse_keymap_report_event(eeepc->inputdev, event, 1, true))
1215 pr_info("Unknown key %x pressed\n", event);
1216}
1217
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001218static void eeepc_acpi_notify(struct acpi_device *device, u32 event)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001219{
Alan Jenkins854c7832009-12-03 07:45:09 +00001220 struct eeepc_laptop *eeepc = acpi_driver_data(device);
Frans Klaverfb1d97a2014-11-02 22:14:58 +01001221 int old_brightness, new_brightness;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001222 u16 count;
Corentin Chary3c0eb512009-12-03 07:44:52 +00001223
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001224 if (event > ACPI_MAX_SYS_NOTIFY)
1225 return;
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001226 count = eeepc->event_count[event % 128]++;
Alan Jenkins854c7832009-12-03 07:45:09 +00001227 acpi_bus_generate_netlink_event(device->pnp.device_class,
1228 dev_name(&device->dev), event,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001229 count);
Corentin Chary3c0eb512009-12-03 07:44:52 +00001230
Alan Jenkins325fb8e2009-12-03 07:45:15 +00001231 /* Brightness events are special */
Frans Klaverfb1d97a2014-11-02 22:14:58 +01001232 if (event < NOTIFY_BRN_MIN || event > NOTIFY_BRN_MAX) {
Corentin Charyce6c4682011-12-15 08:27:32 +01001233 eeepc_input_notify(eeepc, event);
Frans Klaverfb1d97a2014-11-02 22:14:58 +01001234 return;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001235 }
Frans Klaverfb1d97a2014-11-02 22:14:58 +01001236
1237 /* Ignore them completely if the acpi video driver is used */
1238 if (!eeepc->backlight_device)
1239 return;
1240
1241 /* Update the backlight device. */
1242 old_brightness = eeepc_backlight_notify(eeepc);
1243
1244 /* Convert event to keypress (obsolescent hack) */
1245 new_brightness = event - NOTIFY_BRN_MIN;
1246
1247 if (new_brightness < old_brightness) {
1248 event = NOTIFY_BRN_MIN; /* brightness down */
1249 } else if (new_brightness > old_brightness) {
1250 event = NOTIFY_BRN_MAX; /* brightness up */
1251 } else {
1252 /*
1253 * no change in brightness - already at min/max,
1254 * event will be desired value (or else ignored)
1255 */
1256 }
1257 eeepc_input_notify(eeepc, event);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001258}
1259
Alan Jenkinsda8ba012010-01-06 22:07:37 +01001260static void eeepc_dmi_check(struct eeepc_laptop *eeepc)
1261{
1262 const char *model;
1263
Corentin Chary10ae4b52010-01-06 22:07:38 +01001264 model = dmi_get_system_info(DMI_PRODUCT_NAME);
1265 if (!model)
1266 return;
1267
Alan Jenkinsda8ba012010-01-06 22:07:37 +01001268 /*
1269 * Blacklist for setting cpufv (cpu speed).
1270 *
1271 * EeePC 4G ("701") implements CFVS, but it is not supported
1272 * by the pre-installed OS, and the original option to change it
1273 * in the BIOS setup screen was removed in later versions.
1274 *
1275 * Judging by the lack of "Super Hybrid Engine" on Asus product pages,
1276 * this applies to all "701" models (4G/4G Surf/2G Surf).
1277 *
1278 * So Asus made a deliberate decision not to support it on this model.
1279 * We have several reports that using it can cause the system to hang
1280 *
1281 * The hang has also been reported on a "702" (Model name "8G"?).
1282 *
1283 * We avoid dmi_check_system() / dmi_match(), because they use
1284 * substring matching. We don't want to affect the "701SD"
1285 * and "701SDX" models, because they do support S.H.E.
1286 */
Alan Jenkinsda8ba012010-01-06 22:07:37 +01001287 if (strcmp(model, "701") == 0 || strcmp(model, "702") == 0) {
1288 eeepc->cpufv_disabled = true;
Frans Klaver9f662b22014-10-22 21:12:37 +02001289 pr_info("model %s does not officially support setting cpu speed\n",
1290 model);
Alan Jenkinsda8ba012010-01-06 22:07:37 +01001291 pr_info("cpufv disabled to avoid instability\n");
1292 }
Corentin Chary10ae4b52010-01-06 22:07:38 +01001293
1294 /*
1295 * Blacklist for wlan hotplug
1296 *
1297 * Eeepc 1005HA doesn't work like others models and don't need the
1298 * hotplug code. In fact, current hotplug code seems to unplug another
1299 * device...
1300 */
Alan Jenkinsced69c52010-02-20 11:02:24 +00001301 if (strcmp(model, "1005HA") == 0 || strcmp(model, "1201N") == 0 ||
1302 strcmp(model, "1005PE") == 0) {
Corentin Chary10ae4b52010-01-06 22:07:38 +01001303 eeepc->hotplug_disabled = true;
1304 pr_info("wlan hotplug disabled\n");
1305 }
Alan Jenkinsda8ba012010-01-06 22:07:37 +01001306}
1307
Alan Jenkins854c7832009-12-03 07:45:09 +00001308static void cmsg_quirk(struct eeepc_laptop *eeepc, int cm, const char *name)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001309{
1310 int dummy;
1311
Lucas De Marchic8440332011-03-17 17:18:22 -03001312 /* Some BIOSes do not report cm although it is available.
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001313 Check if cm_getv[cm] works and, if yes, assume cm should be set. */
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001314 if (!(eeepc->cm_supported & (1 << cm))
1315 && !read_acpi_int(eeepc->handle, cm_getv[cm], &dummy)) {
Frans Klaver9f662b22014-10-22 21:12:37 +02001316 pr_info("%s (%x) not reported by BIOS, enabling anyway\n",
1317 name, 1 << cm);
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001318 eeepc->cm_supported |= 1 << cm;
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001319 }
1320}
1321
Alan Jenkins854c7832009-12-03 07:45:09 +00001322static void cmsg_quirks(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001323{
Alan Jenkins854c7832009-12-03 07:45:09 +00001324 cmsg_quirk(eeepc, CM_ASL_LID, "LID");
1325 cmsg_quirk(eeepc, CM_ASL_TYPE, "TYPE");
1326 cmsg_quirk(eeepc, CM_ASL_PANELPOWER, "PANELPOWER");
1327 cmsg_quirk(eeepc, CM_ASL_TPD, "TPD");
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001328}
1329
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001330static int eeepc_acpi_init(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001331{
1332 unsigned int init_flags;
Eric Coopere59f8792008-03-13 12:55:46 +01001333 int result;
1334
Corentin Chary71e687d2010-08-24 09:30:44 +02001335 result = acpi_bus_get_status(eeepc->device);
Alan Jenkins1e779852009-08-28 12:56:35 +00001336 if (result)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001337 return result;
Corentin Chary71e687d2010-08-24 09:30:44 +02001338 if (!eeepc->device->status.present) {
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001339 pr_err("Hotkey device not present, aborting\n");
1340 return -ENODEV;
Eric Coopere59f8792008-03-13 12:55:46 +01001341 }
Corentin Chary7de39382009-06-25 13:25:38 +02001342
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001343 init_flags = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
1344 pr_notice("Hotkey init flags 0x%x\n", init_flags);
1345
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001346 if (write_acpi_int(eeepc->handle, "INIT", init_flags)) {
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001347 pr_err("Hotkey initialization failed\n");
1348 return -ENODEV;
1349 }
1350
1351 /* get control methods supported */
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001352 if (read_acpi_int(eeepc->handle, "CMSG", &eeepc->cm_supported)) {
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001353 pr_err("Get control methods supported failed\n");
1354 return -ENODEV;
1355 }
Alan Jenkins854c7832009-12-03 07:45:09 +00001356 cmsg_quirks(eeepc);
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001357 pr_info("Get control methods supported: 0x%x\n", eeepc->cm_supported);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001358
Corentin Chary3c0eb512009-12-03 07:44:52 +00001359 return 0;
1360}
1361
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001362static void eeepc_enable_camera(struct eeepc_laptop *eeepc)
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001363{
1364 /*
1365 * If the following call to set_acpi() fails, it's because there's no
1366 * camera so we can ignore the error.
1367 */
Alan Jenkins854c7832009-12-03 07:45:09 +00001368 if (get_acpi(eeepc, CM_ASL_CAMERA) == 0)
1369 set_acpi(eeepc, CM_ASL_CAMERA, 1);
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001370}
1371
Alan Jenkins854c7832009-12-03 07:45:09 +00001372static bool eeepc_device_present;
1373
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001374static int eeepc_acpi_add(struct acpi_device *device)
Eric Coopere59f8792008-03-13 12:55:46 +01001375{
Alan Jenkins854c7832009-12-03 07:45:09 +00001376 struct eeepc_laptop *eeepc;
Eric Coopere59f8792008-03-13 12:55:46 +01001377 int result;
1378
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001379 pr_notice(EEEPC_LAPTOP_NAME "\n");
1380 eeepc = kzalloc(sizeof(struct eeepc_laptop), GFP_KERNEL);
1381 if (!eeepc)
Eric Coopere59f8792008-03-13 12:55:46 +01001382 return -ENOMEM;
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001383 eeepc->handle = device->handle;
1384 strcpy(acpi_device_name(device), EEEPC_ACPI_DEVICE_NAME);
1385 strcpy(acpi_device_class(device), EEEPC_ACPI_CLASS);
1386 device->driver_data = eeepc;
Corentin Chary71e687d2010-08-24 09:30:44 +02001387 eeepc->device = device;
Eric Coopere59f8792008-03-13 12:55:46 +01001388
Corentin Chary322a1352010-01-06 22:07:40 +01001389 eeepc->hotplug_disabled = hotplug_disabled;
1390
Alan Jenkinsda8ba012010-01-06 22:07:37 +01001391 eeepc_dmi_check(eeepc);
1392
Corentin Chary71e687d2010-08-24 09:30:44 +02001393 result = eeepc_acpi_init(eeepc);
Eric Coopere59f8792008-03-13 12:55:46 +01001394 if (result)
Alan Jenkins9db106b2009-12-03 07:45:06 +00001395 goto fail_platform;
Alan Jenkins854c7832009-12-03 07:45:09 +00001396 eeepc_enable_camera(eeepc);
Eric Coopere59f8792008-03-13 12:55:46 +01001397
Alan Jenkins854c7832009-12-03 07:45:09 +00001398 /*
1399 * Register the platform device first. It is used as a parent for the
1400 * sub-devices below.
1401 *
1402 * Note that if there are multiple instances of this ACPI device it
1403 * will bail out, because the platform device is registered with a
1404 * fixed name. Of course it doesn't make sense to have more than one,
1405 * and machine-specific scripts find the fixed name convenient. But
1406 * It's also good for us to exclude multiple instances because both
1407 * our hwmon and our wlan rfkill subdevice use global ACPI objects
1408 * (the EC and the wlan PCI slot respectively).
1409 */
1410 result = eeepc_platform_init(eeepc);
Eric Coopere59f8792008-03-13 12:55:46 +01001411 if (result)
Alan Jenkins9db106b2009-12-03 07:45:06 +00001412 goto fail_platform;
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001413
Hans de Goede21db4b12015-06-16 16:28:02 +02001414 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Alan Jenkins854c7832009-12-03 07:45:09 +00001415 result = eeepc_backlight_init(eeepc);
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001416 if (result)
1417 goto fail_backlight;
Frans Klaver39a3e172014-09-17 23:47:19 +02001418 }
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001419
Alan Jenkins854c7832009-12-03 07:45:09 +00001420 result = eeepc_input_init(eeepc);
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001421 if (result)
1422 goto fail_input;
1423
Alan Jenkins854c7832009-12-03 07:45:09 +00001424 result = eeepc_hwmon_init(eeepc);
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001425 if (result)
1426 goto fail_hwmon;
1427
Alan Jenkins854c7832009-12-03 07:45:09 +00001428 result = eeepc_led_init(eeepc);
Corentin Chary3c0eb512009-12-03 07:44:52 +00001429 if (result)
1430 goto fail_led;
1431
Alan Jenkins854c7832009-12-03 07:45:09 +00001432 result = eeepc_rfkill_init(eeepc);
Corentin Chary7de39382009-06-25 13:25:38 +02001433 if (result)
1434 goto fail_rfkill;
1435
Alan Jenkins854c7832009-12-03 07:45:09 +00001436 eeepc_device_present = true;
Eric Coopere59f8792008-03-13 12:55:46 +01001437 return 0;
Alan Jenkins1e779852009-08-28 12:56:35 +00001438
Corentin Chary7de39382009-06-25 13:25:38 +02001439fail_rfkill:
Alan Jenkins854c7832009-12-03 07:45:09 +00001440 eeepc_led_exit(eeepc);
Corentin Chary3c0eb512009-12-03 07:44:52 +00001441fail_led:
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001442fail_hwmon:
Alan Jenkins854c7832009-12-03 07:45:09 +00001443 eeepc_input_exit(eeepc);
Alan Jenkinsf2a9d5e2009-08-28 12:56:36 +00001444fail_input:
Alan Jenkins854c7832009-12-03 07:45:09 +00001445 eeepc_backlight_exit(eeepc);
Corentin Chary1ddec2f2009-06-25 13:25:39 +02001446fail_backlight:
Alan Jenkins854c7832009-12-03 07:45:09 +00001447 eeepc_platform_exit(eeepc);
Alan Jenkins9db106b2009-12-03 07:45:06 +00001448fail_platform:
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001449 kfree(eeepc);
Alan Jenkins1e779852009-08-28 12:56:35 +00001450
Eric Coopere59f8792008-03-13 12:55:46 +01001451 return result;
1452}
1453
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01001454static int eeepc_acpi_remove(struct acpi_device *device)
Alan Jenkins1e779852009-08-28 12:56:35 +00001455{
Alan Jenkins854c7832009-12-03 07:45:09 +00001456 struct eeepc_laptop *eeepc = acpi_driver_data(device);
Alan Jenkins1e779852009-08-28 12:56:35 +00001457
Alan Jenkins854c7832009-12-03 07:45:09 +00001458 eeepc_backlight_exit(eeepc);
1459 eeepc_rfkill_exit(eeepc);
1460 eeepc_input_exit(eeepc);
Alan Jenkins854c7832009-12-03 07:45:09 +00001461 eeepc_led_exit(eeepc);
1462 eeepc_platform_exit(eeepc);
Alan Jenkins1e779852009-08-28 12:56:35 +00001463
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001464 kfree(eeepc);
Alan Jenkins1e779852009-08-28 12:56:35 +00001465 return 0;
1466}
1467
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001468
1469static const struct acpi_device_id eeepc_device_ids[] = {
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001470 {EEEPC_ACPI_HID, 0},
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001471 {"", 0},
1472};
1473MODULE_DEVICE_TABLE(acpi, eeepc_device_ids);
1474
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001475static struct acpi_driver eeepc_acpi_driver = {
1476 .name = EEEPC_LAPTOP_NAME,
1477 .class = EEEPC_ACPI_CLASS,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001478 .owner = THIS_MODULE,
1479 .ids = eeepc_device_ids,
1480 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1481 .ops = {
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001482 .add = eeepc_acpi_add,
1483 .remove = eeepc_acpi_remove,
1484 .notify = eeepc_acpi_notify,
Alan Jenkins52bbe3c2009-12-03 07:45:07 +00001485 },
1486};
1487
1488
Alan Jenkins1e779852009-08-28 12:56:35 +00001489static int __init eeepc_laptop_init(void)
1490{
1491 int result;
1492
Alan Jenkins22072e92009-12-03 07:45:05 +00001493 result = platform_driver_register(&platform_driver);
Alan Jenkins1e779852009-08-28 12:56:35 +00001494 if (result < 0)
1495 return result;
Alan Jenkins22072e92009-12-03 07:45:05 +00001496
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001497 result = acpi_bus_register_driver(&eeepc_acpi_driver);
Alan Jenkins22072e92009-12-03 07:45:05 +00001498 if (result < 0)
1499 goto fail_acpi_driver;
Dmitry Torokhov642e0442010-01-06 22:07:39 +01001500
Alan Jenkins854c7832009-12-03 07:45:09 +00001501 if (!eeepc_device_present) {
Alan Jenkins22072e92009-12-03 07:45:05 +00001502 result = -ENODEV;
1503 goto fail_no_device;
Alan Jenkins1e779852009-08-28 12:56:35 +00001504 }
Dmitry Torokhov642e0442010-01-06 22:07:39 +01001505
Alan Jenkins1e779852009-08-28 12:56:35 +00001506 return 0;
Alan Jenkins22072e92009-12-03 07:45:05 +00001507
1508fail_no_device:
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001509 acpi_bus_unregister_driver(&eeepc_acpi_driver);
Alan Jenkins22072e92009-12-03 07:45:05 +00001510fail_acpi_driver:
1511 platform_driver_unregister(&platform_driver);
1512 return result;
Alan Jenkins1e779852009-08-28 12:56:35 +00001513}
1514
1515static void __exit eeepc_laptop_exit(void)
1516{
Alan Jenkinsa7624b62009-12-03 07:45:08 +00001517 acpi_bus_unregister_driver(&eeepc_acpi_driver);
Alan Jenkins22072e92009-12-03 07:45:05 +00001518 platform_driver_unregister(&platform_driver);
Alan Jenkins1e779852009-08-28 12:56:35 +00001519}
1520
Eric Coopere59f8792008-03-13 12:55:46 +01001521module_init(eeepc_laptop_init);
1522module_exit(eeepc_laptop_exit);