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