19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/kernel.h>
22 #include <linux/module.h>
24 #include <linux/types.h>
30 #include <linux/slab.h>
34 #include <linux/input.h>
36 #include <linux/rfkill.h>
37 #include <linux/pci.h>
42 #define EEEPC_LAPTOP_VERSION "0.1"
43 #define EEEPC_LAPTOP_NAME "Eee PC Hotkey Driver"
44 #define EEEPC_LAPTOP_FILE "eeepc"
46 #define EEEPC_ACPI_CLASS "hotkey"
47 #define EEEPC_ACPI_DEVICE_NAME "Hotkey"
48 #define EEEPC_ACPI_HID "ASUS010"
54 static bool hotplug_disabled;
58 "Disable hotplug for wireless device. "
59 "If your laptop need that, please report to "
65 #define NOTIFY_BRN_MIN 0x20
66 #define NOTIFY_BRN_MAX 0x2f
114 static const char *cm_getv[] = {
120 "CRDG",
"M3GG",
"WIMG",
"HWCF",
121 "LIDG",
"TYPE",
"PBPG",
"TPDG"
124 static const char *cm_setv[] = {
127 "SDSP",
"PBLS",
"HDPS",
NULL,
130 "CRDS",
"M3GS",
"WIMS",
NULL,
134 static const struct key_entry eeepc_keymap[] = {
200 in_obj.integer.value =
val;
203 return (status ==
AE_OK ? 0 : -1);
206 static int read_acpi_int(
acpi_handle handle,
const char *method,
int *val)
209 unsigned long long result;
223 const char *method = cm_setv[cm];
230 if (write_acpi_int(eeepc->
handle, method, value))
231 pr_warn(
"Error writing %s\n", method);
237 const char *method = cm_getv[cm];
245 if (read_acpi_int(eeepc->
handle, method, &value))
246 pr_warn(
"Error reading %s\n", method);
250 static int acpi_setter_handle(
struct eeepc_laptop *eeepc,
int cm,
253 const char *method = cm_setv[cm];
263 if (status !=
AE_OK) {
264 pr_warn(
"Error finding %s\n", method);
274 static int parse_arg(
const char *
buf,
unsigned long count,
int *val)
278 if (
sscanf(buf,
"%i", val) != 1)
284 const char *buf,
size_t count)
289 rv = parse_arg(buf, count, &value);
291 value = set_acpi(eeepc, cm, value);
297 static ssize_t show_sys_acpi(
struct device *dev,
int cm,
char *buf)
300 int value = get_acpi(eeepc, cm);
304 return sprintf(buf,
"%d\n", value);
307 #define EEEPC_CREATE_DEVICE_ATTR(_name, _mode, _cm) \
308 static ssize_t show_##_name(struct device *dev, \
309 struct device_attribute *attr, \
312 return show_sys_acpi(dev, _cm, buf); \
314 static ssize_t store_##_name(struct device *dev, \
315 struct device_attribute *attr, \
316 const char *buf, size_t count) \
318 return store_sys_acpi(dev, _cm, buf, count); \
320 static struct device_attribute dev_attr_##_name = { \
322 .name = __stringify(_name), \
324 .show = show_##_name, \
325 .store = store_##_name, \
340 c->
num = (c->
cur >> 8) & 0xff;
342 if (c->
cur < 0 || c->
num <= 0 || c->
num > 12)
356 if (get_cpufv(eeepc, &
c))
358 for (i = 0; i <
c.num; i++)
359 len +=
sprintf(buf + len,
"%d ", i);
360 len +=
sprintf(buf + len,
"\n");
371 if (get_cpufv(eeepc, &
c))
373 return sprintf(buf,
"%#x\n", (
c.num << 8) |
c.cur);
378 const char *buf,
size_t count)
386 if (get_cpufv(eeepc, &
c))
388 rv = parse_arg(buf, count, &value);
391 if (!rv || value < 0 || value >=
c.num)
408 const char *buf,
size_t count)
413 rv = parse_arg(buf, count, &value);
420 pr_warn(
"cpufv enabled (not officially supported "
442 .name =
"available_cpufv",
444 .show = show_available_cpufv
449 .name =
"cpufv_disabled",
451 .show = show_cpufv_disabled,
452 .store = store_cpufv_disabled
456 static struct attribute *platform_attributes[] = {
457 &dev_attr_camera.attr,
458 &dev_attr_cardr.attr,
460 &dev_attr_cpufv.
attr,
461 &dev_attr_available_cpufv.
attr,
462 &dev_attr_cpufv_disabled.
attr,
467 .attrs = platform_attributes
470 static int eeepc_platform_init(
struct eeepc_laptop *eeepc)
481 goto fail_platform_device;
484 &platform_attribute_group);
491 fail_platform_device:
496 static void eeepc_platform_exit(
struct eeepc_laptop *eeepc)
499 &platform_attribute_group);
553 eeepc->
tpd_led.name =
"eeepc::touchpad";
554 eeepc->
tpd_led.brightness_set = tpd_led_set;
556 eeepc->
tpd_led.brightness_get = tpd_led_get;
557 eeepc->
tpd_led.max_brightness = 1;
571 if (!IS_ERR_OR_NULL(eeepc->
tpd_led.dev))
581 static bool eeepc_wlan_rfkill_blocked(
struct eeepc_laptop *eeepc)
593 bool blocked = eeepc_wlan_rfkill_blocked(eeepc);
612 pr_warn(
"Unable to find PCI bus 1?\n");
617 pr_err(
"Unable to read PCI config space?\n");
621 absent = (l == 0xffffffff);
623 if (blocked != absent) {
624 pr_warn(
"BIOS says wireless lan is %s, "
625 "but the pci device is %s\n",
626 blocked ?
"blocked" :
"unblocked",
627 absent ?
"absent" :
"present");
628 pr_warn(
"skipped wireless hotplug as probably "
629 "inappropriate for this model\n");
644 pr_err(
"Unable to hotplug wifi\n");
661 static void eeepc_rfkill_hotplug_update(
struct eeepc_laptop *eeepc,
char *
node)
669 eeepc_rfkill_hotplug(eeepc, handle);
679 eeepc_rfkill_hotplug(eeepc, handle);
682 static int eeepc_register_rfkill_notifier(
struct eeepc_laptop *eeepc,
696 pr_warn(
"Failed to register notify on %s\n", node);
702 eeepc_rfkill_hotplug(eeepc, handle);
709 static void eeepc_unregister_rfkill_notifier(
struct eeepc_laptop *eeepc,
720 eeepc_rfkill_notify);
722 pr_err(
"Error removing rfkill notify handler %s\n",
729 eeepc_rfkill_hotplug(eeepc, handle);
739 if (val == 1 || val == 0)
747 static void eeepc_cleanup_pci_hotplug(
struct hotplug_slot *hotplug_slot)
749 kfree(hotplug_slot->info);
755 .get_adapter_status = eeepc_get_adapter_status,
756 .get_power_status = eeepc_get_adapter_status,
759 static int eeepc_setup_pci_hotplug(
struct eeepc_laptop *eeepc)
765 pr_err(
"Unable to find wifi PCI bus\n");
779 eeepc->
hotplug_slot->release = &eeepc_cleanup_pci_hotplug;
786 pr_err(
"Unable to register hotplug slot - %d\n", ret);
804 static int eeepc_rfkill_set(
void *data,
bool blocked)
808 return write_acpi_int(handle,
NULL, !blocked);
811 static const struct rfkill_ops eeepc_rfkill_ops = {
812 .set_block = eeepc_rfkill_set,
823 result = acpi_setter_handle(eeepc, cm, &handle);
828 &eeepc_rfkill_ops, handle);
843 static void eeepc_rfkill_exit(
struct eeepc_laptop *eeepc)
845 eeepc_unregister_rfkill_notifier(eeepc,
"\\_SB.PCI0.P0P5");
846 eeepc_unregister_rfkill_notifier(eeepc,
"\\_SB.PCI0.P0P6");
847 eeepc_unregister_rfkill_notifier(eeepc,
"\\_SB.PCI0.P0P7");
874 static int eeepc_rfkill_init(
struct eeepc_laptop *eeepc)
880 result = eeepc_new_rfkill(eeepc, &eeepc->
wlan_rfkill,
884 if (result && result != -
ENODEV)
891 if (result && result != -
ENODEV)
898 if (result && result != -
ENODEV)
905 if (result && result != -
ENODEV)
911 result = eeepc_setup_pci_hotplug(eeepc);
916 if (result == -
EBUSY)
919 eeepc_register_rfkill_notifier(eeepc,
"\\_SB.PCI0.P0P5");
920 eeepc_register_rfkill_notifier(eeepc,
"\\_SB.PCI0.P0P6");
921 eeepc_register_rfkill_notifier(eeepc,
"\\_SB.PCI0.P0P7");
924 if (result && result != -
ENODEV)
925 eeepc_rfkill_exit(eeepc);
951 static int eeepc_hotk_restore(
struct device *device)
957 eeepc_rfkill_hotplug_update(eeepc,
"\\_SB.PCI0.P0P5");
958 eeepc_rfkill_hotplug_update(eeepc,
"\\_SB.PCI0.P0P6");
959 eeepc_rfkill_hotplug_update(eeepc,
"\\_SB.PCI0.P0P7");
975 static const struct dev_pm_ops eeepc_pm_ops = {
976 .thaw = eeepc_hotk_thaw,
977 .restore = eeepc_hotk_restore,
992 #define EEEPC_EC_SC00 0x61
993 #define EEEPC_EC_FAN_PWM (EEEPC_EC_SC00 + 2)
994 #define EEEPC_EC_FAN_HRPM (EEEPC_EC_SC00 + 5)
995 #define EEEPC_EC_FAN_LRPM (EEEPC_EC_SC00 + 6)
997 #define EEEPC_EC_SFB0 0xD0
998 #define EEEPC_EC_FAN_CTRL (EEEPC_EC_SFB0 + 3)
1000 static int eeepc_get_fan_pwm(
void)
1005 return value * 255 / 100;
1008 static void eeepc_set_fan_pwm(
int value)
1010 value = SENSORS_LIMIT(value, 0, 255);
1011 value = value * 100 / 255;
1015 static int eeepc_get_fan_rpm(
void)
1022 return high << 8 |
low;
1025 static int eeepc_get_fan_ctrl(
void)
1036 static void eeepc_set_fan_ctrl(
int manual)
1048 static ssize_t store_sys_hwmon(
void (*
set)(
int),
const char *buf,
size_t count)
1052 rv = parse_arg(buf, count, &value);
1058 static ssize_t show_sys_hwmon(
int (*
get)(
void),
char *buf)
1060 return sprintf(buf,
"%d\n",
get());
1063 #define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _set, _get) \
1064 static ssize_t show_##_name(struct device *dev, \
1065 struct device_attribute *attr, \
1068 return show_sys_hwmon(_set, buf); \
1070 static ssize_t store_##_name(struct device *dev, \
1071 struct device_attribute *attr, \
1072 const char *buf, size_t count) \
1074 return store_sys_hwmon(_get, buf, count); \
1076 static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0);
1080 eeepc_get_fan_pwm, eeepc_set_fan_pwm);
1082 eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
1087 return sprintf(buf,
"eeepc\n");
1091 static struct attribute *hwmon_attributes[] = {
1092 &sensor_dev_attr_pwm1.dev_attr.attr,
1093 &sensor_dev_attr_fan1_input.dev_attr.attr,
1094 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1095 &sensor_dev_attr_name.dev_attr.attr,
1100 .attrs = hwmon_attributes
1103 static void eeepc_hwmon_exit(
struct eeepc_laptop *eeepc)
1105 struct device *hwmon;
1111 &hwmon_attribute_group);
1116 static int eeepc_hwmon_init(
struct eeepc_laptop *eeepc)
1118 struct device *hwmon;
1122 if (IS_ERR(hwmon)) {
1123 pr_err(
"Could not register eeepc hwmon device\n");
1125 return PTR_ERR(hwmon);
1129 &hwmon_attribute_group);
1131 eeepc_hwmon_exit(eeepc);
1154 return set_brightness(bd, bd->
props.brightness);
1158 .get_brightness = read_brightness,
1159 .update_status = update_bl_status,
1162 static int eeepc_backlight_notify(
struct eeepc_laptop *eeepc)
1165 int old = bd->
props.brightness;
1172 static int eeepc_backlight_init(
struct eeepc_laptop *eeepc)
1179 props.max_brightness = 15;
1182 &eeepcbl_ops, &
props);
1184 pr_err(
"Could not register eeepc backlight device\n");
1189 bd->
props.brightness = read_brightness(bd);
1191 backlight_update_status(bd);
1195 static void eeepc_backlight_exit(
struct eeepc_laptop *eeepc)
1206 static int eeepc_input_init(
struct eeepc_laptop *eeepc)
1208 struct input_dev *
input;
1211 input = input_allocate_device();
1213 pr_info(
"Unable to allocate input device\n");
1217 input->name =
"Asus EeePC extra buttons";
1222 error = sparse_keymap_setup(input, eeepc_keymap,
NULL);
1224 pr_err(
"Unable to setup input device keymap\n");
1228 error = input_register_device(input);
1230 pr_err(
"Unable to register input device\n");
1231 goto err_free_keymap;
1238 sparse_keymap_free(input);
1240 input_free_device(input);
1244 static void eeepc_input_exit(
struct eeepc_laptop *eeepc)
1247 sparse_keymap_free(eeepc->
inputdev);
1248 input_unregister_device(eeepc->
inputdev);
1256 static void eeepc_input_notify(
struct eeepc_laptop *eeepc,
int event)
1260 if (!sparse_keymap_report_event(eeepc->
inputdev, event, 1,
true))
1261 pr_info(
"Unknown key %x pressed\n", event);
1264 static void eeepc_acpi_notify(
struct acpi_device *device,
u32 event)
1272 acpi_bus_generate_proc_event(device, event, count);
1274 dev_name(&device->dev), event,
1282 int old_brightness, new_brightness;
1285 old_brightness = eeepc_backlight_notify(eeepc);
1290 if (new_brightness < old_brightness) {
1292 }
else if (new_brightness > old_brightness) {
1300 eeepc_input_notify(eeepc, event);
1304 eeepc_input_notify(eeepc, event);
1308 static void eeepc_dmi_check(
struct eeepc_laptop *eeepc)
1335 if (
strcmp(model,
"701") == 0 ||
strcmp(model,
"702") == 0) {
1337 pr_info(
"model %s does not officially support setting cpu "
1339 pr_info(
"cpufv disabled to avoid instability\n");
1349 if (
strcmp(model,
"1005HA") == 0 ||
strcmp(model,
"1201N") == 0 ||
1350 strcmp(model,
"1005PE") == 0) {
1352 pr_info(
"wlan hotplug disabled\n");
1356 static void cmsg_quirk(
struct eeepc_laptop *eeepc,
int cm,
const char *name)
1363 && !read_acpi_int(eeepc->
handle, cm_getv[cm], &dummy)) {
1364 pr_info(
"%s (%x) not reported by BIOS,"
1365 " enabling anyway\n", name, 1 << cm);
1386 if (!eeepc->
device->status.present) {
1387 pr_err(
"Hotkey device not present, aborting\n");
1392 pr_notice(
"Hotkey init flags 0x%x\n", init_flags);
1394 if (write_acpi_int(eeepc->
handle,
"INIT", init_flags)) {
1395 pr_err(
"Hotkey initialization failed\n");
1401 pr_err(
"Get control methods supported failed\n");
1420 static bool eeepc_device_present;
1422 static int __devinit eeepc_acpi_add(
struct acpi_device *device)
1431 eeepc->
handle = device->handle;
1434 device->driver_data = eeepc;
1439 eeepc_dmi_check(eeepc);
1441 result = eeepc_acpi_init(eeepc);
1444 eeepc_enable_camera(eeepc);
1458 result = eeepc_platform_init(eeepc);
1463 result = eeepc_backlight_init(eeepc);
1465 goto fail_backlight;
1467 pr_info(
"Backlight controlled by ACPI video driver\n");
1469 result = eeepc_input_init(eeepc);
1473 result = eeepc_hwmon_init(eeepc);
1477 result = eeepc_led_init(eeepc);
1481 result = eeepc_rfkill_init(eeepc);
1485 eeepc_device_present =
true;
1489 eeepc_led_exit(eeepc);
1491 eeepc_hwmon_exit(eeepc);
1493 eeepc_input_exit(eeepc);
1495 eeepc_backlight_exit(eeepc);
1497 eeepc_platform_exit(eeepc);
1504 static int eeepc_acpi_remove(
struct acpi_device *device,
int type)
1508 eeepc_backlight_exit(eeepc);
1509 eeepc_rfkill_exit(eeepc);
1510 eeepc_input_exit(eeepc);
1511 eeepc_hwmon_exit(eeepc);
1512 eeepc_led_exit(eeepc);
1513 eeepc_platform_exit(eeepc);
1526 static struct acpi_driver eeepc_acpi_driver = {
1530 .ids = eeepc_device_ids,
1531 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1533 .add = eeepc_acpi_add,
1534 .remove = eeepc_acpi_remove,
1535 .notify = eeepc_acpi_notify,
1540 static int __init eeepc_laptop_init(
void)
1550 goto fail_acpi_driver;
1552 if (!eeepc_device_present) {
1554 goto fail_no_device;
1566 static void __exit eeepc_laptop_exit(
void)