diff options
-rw-r--r-- | Documentation/ABI/testing/sysfs-platform-ideapad-laptop | 26 | ||||
-rw-r--r-- | MAINTAINERS | 28 | ||||
-rw-r--r-- | drivers/platform/olpc/olpc-ec.c | 2 | ||||
-rw-r--r-- | drivers/platform/surface/Kconfig | 19 | ||||
-rw-r--r-- | drivers/platform/surface/Makefile | 1 | ||||
-rw-r--r-- | drivers/platform/surface/surface3-wmi.c | 6 | ||||
-rw-r--r-- | drivers/platform/surface/surface_hotplug.c | 282 | ||||
-rw-r--r-- | drivers/platform/x86/Kconfig | 179 | ||||
-rw-r--r-- | drivers/platform/x86/Makefile | 16 | ||||
-rw-r--r-- | drivers/platform/x86/acer-wmi.c | 4 | ||||
-rw-r--r-- | drivers/platform/x86/dell/Kconfig | 207 | ||||
-rw-r--r-- | drivers/platform/x86/dell/Makefile | 21 | ||||
-rw-r--r-- | drivers/platform/x86/dell/alienware-wmi.c (renamed from drivers/platform/x86/alienware-wmi.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dcdbas.c (renamed from drivers/platform/x86/dcdbas.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dcdbas.h (renamed from drivers/platform/x86/dcdbas.h) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-laptop.c (renamed from drivers/platform/x86/dell-laptop.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-rbtn.c (renamed from drivers/platform/x86/dell-rbtn.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-rbtn.h (renamed from drivers/platform/x86/dell-rbtn.h) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-smbios-base.c (renamed from drivers/platform/x86/dell-smbios-base.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-smbios-smm.c (renamed from drivers/platform/x86/dell-smbios-smm.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-smbios-wmi.c (renamed from drivers/platform/x86/dell-smbios-wmi.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-smbios.h (renamed from drivers/platform/x86/dell-smbios.h) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-smo8800.c (renamed from drivers/platform/x86/dell-smo8800.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-aio.c (renamed from drivers/platform/x86/dell-wmi-aio.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-descriptor.c (renamed from drivers/platform/x86/dell-wmi-descriptor.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-descriptor.h (renamed from drivers/platform/x86/dell-wmi-descriptor.h) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-led.c (renamed from drivers/platform/x86/dell-wmi-led.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-sysman/Makefile (renamed from drivers/platform/x86/dell-wmi-sysman/Makefile) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-sysman/biosattr-interface.c (renamed from drivers/platform/x86/dell-wmi-sysman/biosattr-interface.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-sysman/dell-wmi-sysman.h (renamed from drivers/platform/x86/dell-wmi-sysman/dell-wmi-sysman.h) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-sysman/enum-attributes.c (renamed from drivers/platform/x86/dell-wmi-sysman/enum-attributes.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-sysman/int-attributes.c (renamed from drivers/platform/x86/dell-wmi-sysman/int-attributes.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-sysman/passobj-attributes.c (renamed from drivers/platform/x86/dell-wmi-sysman/passobj-attributes.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-sysman/passwordattr-interface.c (renamed from drivers/platform/x86/dell-wmi-sysman/passwordattr-interface.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-sysman/string-attributes.c (renamed from drivers/platform/x86/dell-wmi-sysman/string-attributes.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi-sysman/sysman.c (renamed from drivers/platform/x86/dell-wmi-sysman/sysman.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell-wmi.c (renamed from drivers/platform/x86/dell-wmi.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/dell/dell_rbu.c (renamed from drivers/platform/x86/dell_rbu.c) | 0 | ||||
-rw-r--r-- | drivers/platform/x86/ideapad-laptop.c | 1277 | ||||
-rw-r--r-- | drivers/platform/x86/intel_scu_wdt.c | 2 | ||||
-rw-r--r-- | drivers/platform/x86/msi-wmi.c | 2 | ||||
-rw-r--r-- | drivers/platform/x86/thinkpad_acpi.c | 17 |
42 files changed, 1373 insertions, 716 deletions
diff --git a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop index fd2ac02bc5bd..4989ab266682 100644 --- a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop +++ b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop @@ -1,11 +1,11 @@ -What: /sys/devices/platform/ideapad/camera_power +What: /sys/bus/platform/devices/VPC2004:*/camera_power Date: Dec 2010 KernelVersion: 2.6.37 Contact: "Ike Panhc <ike.pan@canonical.com>" Description: Control the power of camera module. 1 means on, 0 means off. -What: /sys/devices/platform/ideapad/fan_mode +What: /sys/bus/platform/devices/VPC2004:*/fan_mode Date: June 2012 KernelVersion: 3.6 Contact: "Maxim Mikityanskiy <maxtram95@gmail.com>" @@ -18,7 +18,7 @@ Description: * 2 -> Dust Cleaning * 4 -> Efficient Thermal Dissipation Mode -What: /sys/devices/platform/ideapad/touchpad +What: /sys/bus/platform/devices/VPC2004:*/touchpad Date: May 2017 KernelVersion: 4.13 Contact: "Ritesh Raj Sarraf <rrs@debian.org>" @@ -27,7 +27,16 @@ Description: * 1 -> Switched On * 0 -> Switched Off -What: /sys/bus/pci/devices/<bdf>/<device>/VPC2004:00/fn_lock +What: /sys/bus/platform/devices/VPC2004:*/conservation_mode +Date: Aug 2017 +KernelVersion: 4.14 +Contact: platform-driver-x86@vger.kernel.org +Description: + Controls whether the conservation mode is enabled or not. + This feature limits the maximum battery charge percentage to + around 50-60% in order to prolong the lifetime of the battery. + +What: /sys/bus/platform/devices/VPC2004:*/fn_lock Date: May 2018 KernelVersion: 4.18 Contact: "Oleg Keri <ezhi99@gmail.com>" @@ -41,3 +50,12 @@ Description: # echo "0" > \ /sys/bus/pci/devices/0000:00:1f.0/PNP0C09:00/VPC2004:00/fn_lock + +What: /sys/bus/platform/devices/VPC2004:*/usb_charging +Date: Feb 2021 +KernelVersion: 5.12 +Contact: platform-driver-x86@vger.kernel.org +Description: + Controls whether the "always on USB charging" feature is + enabled or not. This feature enables charging USB devices + even if the computer is not turned on. diff --git a/MAINTAINERS b/MAINTAINERS index 25de2d7aaa46..4fcf3df517a8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4970,17 +4970,17 @@ M: Matthew Garrett <mjg59@srcf.ucam.org> M: Pali Rohár <pali@kernel.org> L: platform-driver-x86@vger.kernel.org S: Maintained -F: drivers/platform/x86/dell-laptop.c +F: drivers/platform/x86/dell/dell-laptop.c DELL LAPTOP FREEFALL DRIVER M: Pali Rohár <pali@kernel.org> S: Maintained -F: drivers/platform/x86/dell-smo8800.c +F: drivers/platform/x86/dell/dell-smo8800.c DELL LAPTOP RBTN DRIVER M: Pali Rohár <pali@kernel.org> S: Maintained -F: drivers/platform/x86/dell-rbtn.* +F: drivers/platform/x86/dell/dell-rbtn.* DELL LAPTOP SMM DRIVER M: Pali Rohár <pali@kernel.org> @@ -4992,26 +4992,26 @@ DELL REMOTE BIOS UPDATE DRIVER M: Stuart Hayes <stuart.w.hayes@gmail.com> L: platform-driver-x86@vger.kernel.org S: Maintained -F: drivers/platform/x86/dell_rbu.c +F: drivers/platform/x86/dell/dell_rbu.c DELL SMBIOS DRIVER M: Pali Rohár <pali@kernel.org> M: Mario Limonciello <mario.limonciello@dell.com> L: platform-driver-x86@vger.kernel.org S: Maintained -F: drivers/platform/x86/dell-smbios.* +F: drivers/platform/x86/dell/dell-smbios.* DELL SMBIOS SMM DRIVER M: Mario Limonciello <mario.limonciello@dell.com> L: platform-driver-x86@vger.kernel.org S: Maintained -F: drivers/platform/x86/dell-smbios-smm.c +F: drivers/platform/x86/dell/dell-smbios-smm.c DELL SMBIOS WMI DRIVER M: Mario Limonciello <mario.limonciello@dell.com> L: platform-driver-x86@vger.kernel.org S: Maintained -F: drivers/platform/x86/dell-smbios-wmi.c +F: drivers/platform/x86/dell/dell-smbios-wmi.c F: tools/wmi/dell-smbios-example.c DELL SYSTEMS MANAGEMENT BASE DRIVER (dcdbas) @@ -5019,12 +5019,12 @@ M: Stuart Hayes <stuart.w.hayes@gmail.com> L: platform-driver-x86@vger.kernel.org S: Maintained F: Documentation/driver-api/dcdbas.rst -F: drivers/platform/x86/dcdbas.* +F: drivers/platform/x86/dell/dcdbas.* DELL WMI DESCRIPTOR DRIVER M: Mario Limonciello <mario.limonciello@dell.com> S: Maintained -F: drivers/platform/x86/dell-wmi-descriptor.c +F: drivers/platform/x86/dell/dell-wmi-descriptor.c DELL WMI SYSMAN DRIVER M: Divya Bharathi <divya.bharathi@dell.com> @@ -5033,13 +5033,13 @@ M: Prasanth Ksr <prasanth.ksr@dell.com> L: platform-driver-x86@vger.kernel.org S: Maintained F: Documentation/ABI/testing/sysfs-class-firmware-attributes -F: drivers/platform/x86/dell-wmi-sysman/ +F: drivers/platform/x86/dell/dell-wmi-sysman/ DELL WMI NOTIFICATIONS DRIVER M: Matthew Garrett <mjg59@srcf.ucam.org> M: Pali Rohár <pali@kernel.org> S: Maintained -F: drivers/platform/x86/dell-wmi.c +F: drivers/platform/x86/dell/dell-wmi.c DELTA ST MEDIA DRIVER M: Hugues Fruchet <hugues.fruchet@st.com> @@ -11805,6 +11805,12 @@ S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git F: drivers/platform/surface/ +MICROSOFT SURFACE HOT-PLUG DRIVER +M: Maximilian Luz <luzmaximilian@gmail.com> +L: platform-driver-x86@vger.kernel.org +S: Maintained +F: drivers/platform/surface/surface_hotplug.c + MICROSOFT SURFACE PRO 3 BUTTON DRIVER M: Chen Yu <yu.c.chen@intel.com> L: platform-driver-x86@vger.kernel.org diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc-ec.c index 72dbbea0005c..4ff5c3a12991 100644 --- a/drivers/platform/olpc/olpc-ec.c +++ b/drivers/platform/olpc/olpc-ec.c @@ -386,7 +386,7 @@ static int dcon_regulator_is_enabled(struct regulator_dev *rdev) return ec->dcon_enabled ? 1 : 0; } -static struct regulator_ops dcon_regulator_ops = { +static const struct regulator_ops dcon_regulator_ops = { .enable = dcon_regulator_enable, .disable = dcon_regulator_disable, .is_enabled = dcon_regulator_is_enabled, diff --git a/drivers/platform/surface/Kconfig b/drivers/platform/surface/Kconfig index 83b0a4c7b352..0847b2dc97bf 100644 --- a/drivers/platform/surface/Kconfig +++ b/drivers/platform/surface/Kconfig @@ -86,6 +86,25 @@ config SURFACE_GPE accordingly. It is required on those devices to allow wake-ups from suspend by opening the lid. +config SURFACE_HOTPLUG + tristate "Surface Hot-Plug Driver" + depends on GPIOLIB + help + Driver for out-of-band hot-plug event signaling on Microsoft Surface + devices with hot-pluggable PCIe cards. + + This driver is used on Surface Book (2 and 3) devices with a + hot-pluggable discrete GPU (dGPU). When not in use, the dGPU on those + devices can enter D3cold, which prevents in-band (standard) PCIe + hot-plug signaling. Thus, without this driver, detaching the base + containing the dGPU will not correctly update the state of the + corresponding PCIe device if it is in D3cold. This driver adds support + for out-of-band hot-plug notifications, ensuring that the device state + is properly updated even when the device in question is in D3cold. + + Select M or Y here, if you want to (fully) support hot-plugging of + dGPU devices on the Surface Book 2 and/or 3 during D3cold. + config SURFACE_PRO3_BUTTON tristate "Power/home/volume buttons driver for Microsoft Surface Pro 3/4 tablet" depends on INPUT diff --git a/drivers/platform/surface/Makefile b/drivers/platform/surface/Makefile index 3eb971006877..990424c5f0c9 100644 --- a/drivers/platform/surface/Makefile +++ b/drivers/platform/surface/Makefile @@ -11,4 +11,5 @@ obj-$(CONFIG_SURFACE_ACPI_NOTIFY) += surface_acpi_notify.o obj-$(CONFIG_SURFACE_AGGREGATOR) += aggregator/ obj-$(CONFIG_SURFACE_AGGREGATOR_CDEV) += surface_aggregator_cdev.o obj-$(CONFIG_SURFACE_GPE) += surface_gpe.o +obj-$(CONFIG_SURFACE_HOTPLUG) += surface_hotplug.o obj-$(CONFIG_SURFACE_PRO3_BUTTON) += surfacepro3_button.o diff --git a/drivers/platform/surface/surface3-wmi.c b/drivers/platform/surface/surface3-wmi.c index 130b6f52a600..fcd1d4fb94d5 100644 --- a/drivers/platform/surface/surface3-wmi.c +++ b/drivers/platform/surface/surface3-wmi.c @@ -57,12 +57,16 @@ static DEFINE_MUTEX(s3_wmi_lock); static int s3_wmi_query_block(const char *guid, int instance, int *ret) { struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *obj = NULL; acpi_status status; - union acpi_object *obj; int error = 0; mutex_lock(&s3_wmi_lock); status = wmi_query_block(guid, instance, &output); + if (ACPI_FAILURE(status)) { + error = -EIO; + goto out_free_unlock; + } obj = output.pointer; diff --git a/drivers/platform/surface/surface_hotplug.c b/drivers/platform/surface/surface_hotplug.c new file mode 100644 index 000000000000..cfcc15cfbacb --- /dev/null +++ b/drivers/platform/surface/surface_hotplug.c @@ -0,0 +1,282 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Surface Book (2 and later) hot-plug driver. + * + * Surface Book devices (can) have a hot-pluggable discrete GPU (dGPU). This + * driver is responsible for out-of-band hot-plug event signaling on these + * devices. It is specifically required when the hot-plug device is in D3cold + * and can thus not generate PCIe hot-plug events itself. + * + * Event signaling is handled via ACPI, which will generate the appropriate + * device-check notifications to be picked up by the PCIe hot-plug driver. + * + * Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com> + */ + +#include <linux/acpi.h> +#include <linux/gpio.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> + +static const struct acpi_gpio_params shps_base_presence_int = { 0, 0, false }; +static const struct acpi_gpio_params shps_base_presence = { 1, 0, false }; +static const struct acpi_gpio_params shps_device_power_int = { 2, 0, false }; +static const struct acpi_gpio_params shps_device_power = { 3, 0, false }; +static const struct acpi_gpio_params shps_device_presence_int = { 4, 0, false }; +static const struct acpi_gpio_params shps_device_presence = { 5, 0, false }; + +static const struct acpi_gpio_mapping shps_acpi_gpios[] = { + { "base_presence-int-gpio", &shps_base_presence_int, 1 }, + { "base_presence-gpio", &shps_base_presence, 1 }, + { "device_power-int-gpio", &shps_device_power_int, 1 }, + { "device_power-gpio", &shps_device_power, 1 }, + { "device_presence-int-gpio", &shps_device_presence_int, 1 }, + { "device_presence-gpio", &shps_device_presence, 1 }, + { }, +}; + +/* 5515a847-ed55-4b27-8352-cd320e10360a */ +static const guid_t shps_dsm_guid = + GUID_INIT(0x5515a847, 0xed55, 0x4b27, 0x83, 0x52, 0xcd, 0x32, 0x0e, 0x10, 0x36, 0x0a); + +#define SHPS_DSM_REVISION 1 + +enum shps_dsm_fn { + SHPS_DSM_FN_PCI_NUM_ENTRIES = 0x01, + SHPS_DSM_FN_PCI_GET_ENTRIES = 0x02, + SHPS_DSM_FN_IRQ_BASE_PRESENCE = 0x03, + SHPS_DSM_FN_IRQ_DEVICE_POWER = 0x04, + SHPS_DSM_FN_IRQ_DEVICE_PRESENCE = 0x05, +}; + +enum shps_irq_type { + /* NOTE: Must be in order of enum shps_dsm_fn above. */ + SHPS_IRQ_TYPE_BASE_PRESENCE = 0, + SHPS_IRQ_TYPE_DEVICE_POWER = 1, + SHPS_IRQ_TYPE_DEVICE_PRESENCE = 2, + SHPS_NUM_IRQS, +}; + +static const char *const shps_gpio_names[] = { + [SHPS_IRQ_TYPE_BASE_PRESENCE] = "base_presence", + [SHPS_IRQ_TYPE_DEVICE_POWER] = "device_power", + [SHPS_IRQ_TYPE_DEVICE_PRESENCE] = "device_presence", +}; + +struct shps_device { + struct mutex lock[SHPS_NUM_IRQS]; /* Protects update in shps_dsm_notify_irq() */ + struct gpio_desc *gpio[SHPS_NUM_IRQS]; + unsigned int irq[SHPS_NUM_IRQS]; +}; + +#define SHPS_IRQ_NOT_PRESENT ((unsigned int)-1) + +static enum shps_dsm_fn shps_dsm_fn_for_irq(enum shps_irq_type type) +{ + return SHPS_DSM_FN_IRQ_BASE_PRESENCE + type; +} + +static void shps_dsm_notify_irq(struct platform_device *pdev, enum shps_irq_type type) +{ + struct shps_device *sdev = platform_get_drvdata(pdev); + acpi_handle handle = ACPI_HANDLE(&pdev->dev); + union acpi_object *result; + union acpi_object param; + int value; + + mutex_lock(&sdev->lock[type]); + + value = gpiod_get_value_cansleep(sdev->gpio[type]); + if (value < 0) { + mutex_unlock(&sdev->lock[type]); + dev_err(&pdev->dev, "failed to get gpio: %d (irq=%d)\n", type, value); + return; + } + + dev_dbg(&pdev->dev, "IRQ notification via DSM (irq=%d, value=%d)\n", type, value); + + param.type = ACPI_TYPE_INTEGER; + param.integer.value = value; + + result = acpi_evaluate_dsm(handle, &shps_dsm_guid, SHPS_DSM_REVISION, + shps_dsm_fn_for_irq(type), ¶m); + + if (!result) { + dev_err(&pdev->dev, "IRQ notification via DSM failed (irq=%d, gpio=%d)\n", + type, value); + + } else if (result->type != ACPI_TYPE_BUFFER) { + dev_err(&pdev->dev, + "IRQ notification via DSM failed: unexpected result type (irq=%d, gpio=%d)\n", + type, value); + + } else if (result->buffer.length != 1 || result->buffer.pointer[0] != 0) { + dev_err(&pdev->dev, + "IRQ notification via DSM failed: unexpected result value (irq=%d, gpio=%d)\n", + type, value); + } + + mutex_unlock(&sdev->lock[type]); + + if (result) + ACPI_FREE(result); +} + +static irqreturn_t shps_handle_irq(int irq, void *data) +{ + struct platform_device *pdev = data; + struct shps_device *sdev = platform_get_drvdata(pdev); + int type; + + /* Figure out which IRQ we're handling. */ + for (type = 0; type < SHPS_NUM_IRQS; type++) + if (irq == sdev->irq[type]) + break; + + /* We should have found our interrupt, if not: this is a bug. */ + if (WARN(type >= SHPS_NUM_IRQS, "invalid IRQ number: %d\n", irq)) + return IRQ_HANDLED; + + /* Forward interrupt to ACPI via DSM. */ + shps_dsm_notify_irq(pdev, type); + return IRQ_HANDLED; +} + +static int shps_setup_irq(struct platform_device *pdev, enum shps_irq_type type) +{ + unsigned long flags = IRQF_ONESHOT | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING; + struct shps_device *sdev = platform_get_drvdata(pdev); + struct gpio_desc *gpiod; + acpi_handle handle = ACPI_HANDLE(&pdev->dev); + const char *irq_name; + const int dsm = shps_dsm_fn_for_irq(type); + int status, irq; + + /* + * Only set up interrupts that we actually need: The Surface Book 3 + * does not have a DSM for base presence, so don't set up an interrupt + * for that. + */ + if (!acpi_check_dsm(handle, &shps_dsm_guid, SHPS_DSM_REVISION, BIT(dsm))) { + dev_dbg(&pdev->dev, "IRQ notification via DSM not present (irq=%d)\n", type); + return 0; + } + + gpiod = devm_gpiod_get(&pdev->dev, shps_gpio_names[type], GPIOD_ASIS); + if (IS_ERR(gpiod)) + return PTR_ERR(gpiod); + + irq = gpiod_to_irq(gpiod); + if (irq < 0) + return irq; + + irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "shps-irq-%d", type); + if (!irq_name) + return -ENOMEM; + + status = devm_request_threaded_irq(&pdev->dev, irq, NULL, shps_handle_irq, + flags, irq_name, pdev); + if (status) + return status; + + dev_dbg(&pdev->dev, "set up irq %d as type %d\n", irq, type); + + sdev->gpio[type] = gpiod; + sdev->irq[type] = irq; + + return 0; +} + +static int surface_hotplug_remove(struct platform_device *pdev) +{ + struct shps_device *sdev = platform_get_drvdata(pdev); + int i; + + /* Ensure that IRQs have been fully handled and won't trigger any more. */ + for (i = 0; i < SHPS_NUM_IRQS; i++) { + if (sdev->irq[i] != SHPS_IRQ_NOT_PRESENT) + disable_irq(sdev->irq[i]); + + mutex_destroy(&sdev->lock[i]); + } + + return 0; +} + +static int surface_hotplug_probe(struct platform_device *pdev) +{ + struct shps_device *sdev; + int status, i; + + /* + * The MSHW0153 device is also present on the Surface Laptop 3, + * however that doesn't have a hot-pluggable PCIe device. It also + * doesn't have any GPIO interrupts/pins under the MSHW0153, so filter + * it out here. + */ + if (gpiod_count(&pdev->dev, NULL) < 0) + return -ENODEV; + + status = devm_acpi_dev_add_driver_gpios(&pdev->dev, shps_acpi_gpios); + if (status) + return status; + + sdev = devm_kzalloc(&pdev->dev, sizeof(*sdev), GFP_KERNEL); + if (!sdev) + return -ENOMEM; + + platform_set_drvdata(pdev, sdev); + + /* + * Initialize IRQs so that we can safely call surface_hotplug_remove() + * on errors. + */ + for (i = 0; i < SHPS_NUM_IRQS; i++) + sdev->irq[i] = SHPS_IRQ_NOT_PRESENT; + + /* Set up IRQs. */ + for (i = 0; i < SHPS_NUM_IRQS; i++) { + mutex_init(&sdev->lock[i]); + + status = shps_setup_irq(pdev, i); + if (status) { + dev_err(&pdev->dev, "failed to set up IRQ %d: %d\n", i, status); + goto err; + } + } + + /* Ensure everything is up-to-date. */ + for (i = 0; i < SHPS_NUM_IRQS; i++) + if (sdev->irq[i] != SHPS_IRQ_NOT_PRESENT) + shps_dsm_notify_irq(pdev, i); + + return 0; + +err: + surface_hotplug_remove(pdev); + return status; +} + +static const struct acpi_device_id surface_hotplug_acpi_match[] = { + { "MSHW0153", 0 }, + { }, +}; +MODULE_DEVICE_TABLE(acpi, surface_hotplug_acpi_match); + +static struct platform_driver surface_hotplug_driver = { + .probe = surface_hotplug_probe, + .remove = surface_hotplug_remove, + .driver = { + .name = "surface_hotplug", + .acpi_match_table = surface_hotplug_acpi_match, + .probe_type = PROBE_PREFER_ASYNCHRONOUS, + }, +}; +module_platform_driver(surface_hotplug_driver); + +MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>"); +MODULE_DESCRIPTION("Surface Hot-Plug Signaling Driver for Surface Book Devices"); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 175ae4ae0028..56353e8c792a 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -49,18 +49,6 @@ config WMI_BMOF To compile this driver as a module, choose M here: the module will be called wmi-bmof. -config ALIENWARE_WMI - tristate "Alienware Special feature control" - depends on ACPI - depends on LEDS_CLASS - depends on NEW_LEDS - depends on ACPI_WMI - help - This is a driver for controlling Alienware BIOS driven - features. It exposes an interface for controlling the AlienFX - zones on Alienware machines that don't contain a dedicated AlienFX - USB MCU such as the X51 and X51-R2. - config HUAWEI_WMI tristate "Huawei WMI laptop extras driver" depends on ACPI_BATTERY @@ -327,169 +315,7 @@ config EEEPC_WMI If you have an ACPI-WMI compatible Eee PC laptop (>= 1000), say Y or M here. -config DCDBAS - tristate "Dell Systems Management Base Driver" - depends on X86 - help - The Dell Systems Management Base Driver provides a sysfs interface - for systems management software to perform System Management - Interrupts (SMIs) and Host Control Actions (system power cycle or - power off after OS shutdown) on certain Dell systems. - - See <file:Documentation/driver-api/dcdbas.rst> for more details on the driver - and the Dell systems on which Dell systems management software makes - use of this driver. - - Say Y or M here to enable the driver for use by Dell systems - management software such as Dell OpenManage. - -# -# The DELL_SMBIOS driver depends on ACPI_WMI and/or DCDBAS if those -# backends are selected. The "depends" line prevents a configuration -# where DELL_SMBIOS=y while either of those dependencies =m. -# -config DELL_SMBIOS - tristate "Dell SMBIOS driver" - depends on DCDBAS || DCDBAS=n - depends on ACPI_WMI || ACPI_WMI=n - help - This provides support for the Dell SMBIOS calling interface. - If you have a Dell computer you should enable this option. - - Be sure to select at least one backend for it to work properly. - -config DELL_SMBIOS_WMI - bool "Dell SMBIOS driver WMI backend" - default y - depends on ACPI_WMI - select DELL_WMI_DESCRIPTOR - depends on DELL_SMBIOS - help - This provides an implementation for the Dell SMBIOS calling interface - communicated over ACPI-WMI. - - If you have a Dell computer from >2007 you should say Y here. - If you aren't sure and this module doesn't work for your computer - it just won't load. - -config DELL_SMBIOS_SMM - bool "Dell SMBIOS driver SMM backend" - default y - depends on DCDBAS - depends on DELL_SMBIOS - help - This provides an implementation for the Dell SMBIOS calling interface - communicated over SMI/SMM. - - If you have a Dell computer from <=2017 you should say Y here. - If you aren't sure and this module doesn't work for your computer - it just won't load. - -config DELL_LAPTOP - tristate "Dell Laptop Extras" - depends on DMI - depends on BACKLIGHT_CLASS_DEVICE - depends on ACPI_VIDEO || ACPI_VIDEO = n - depends on RFKILL || RFKILL = n - depends on SERIO_I8042 - depends on DELL_SMBIOS - select POWER_SUPPLY - select LEDS_CLASS - select NEW_LEDS - select LEDS_TRIGGERS - select LEDS_TRIGGER_AUDIO - help - This driver adds support for rfkill and backlight control to Dell - laptops (except for some models covered by the Compal driver). - -config DELL_RBTN - tristate "Dell Airplane Mode Switch driver" - depends on ACPI - depends on INPUT - depends on RFKILL - help - Say Y here if you want to support Dell Airplane Mode Switch ACPI - device on Dell laptops. Sometimes it has names: DELLABCE or DELRBTN. - This driver register rfkill device or input hotkey device depending - on hardware type (hw switch slider or keyboard toggle button). For - rfkill devices it receive HW switch events and set correct hard - rfkill state. - - To compile this driver as a module, choose M here: the module will - be called dell-rbtn. - -config DELL_RBU - tristate "BIOS update support for DELL systems via sysfs" - depends on X86 - select FW_LOADER - select FW_LOADER_USER_HELPER - help - Say m if you want to have the option of updating the BIOS for your - DELL system. Note you need a Dell OpenManage or Dell Update package (DUP) - supporting application to communicate with the BIOS regarding the new - image for the image update to take effect. - See <file:Documentation/admin-guide/dell_rbu.rst> for more details on the driver. - -config DELL_SMO8800 - tristate "Dell Latitude freefall driver (ACPI SMO88XX)" - depends on ACPI - help - Say Y here if you want to support SMO88XX freefall devices - on Dell Latitude laptops. - - To compile this driver as a module, choose M here: the module will - be called dell-smo8800. - -config DELL_WMI - tristate "Dell WMI notifications" - depends on ACPI_WMI - depends on DMI - depends on INPUT - depends on ACPI_VIDEO || ACPI_VIDEO = n - depends on DELL_SMBIOS - select DELL_WMI_DESCRIPTOR - select INPUT_SPARSEKMAP - help - Say Y here if you want to support WMI-based hotkeys on Dell laptops. - - To compile this driver as a module, choose M here: the module will - be called dell-wmi. - -config DELL_WMI_SYSMAN - tristate "Dell WMI-based Systems management driver" - depends on ACPI_WMI - depends on DMI - select NLS - help - This driver allows changing BIOS settings on many Dell machines from - 2018 and newer without the use of any additional software. - - To compile this driver as a module, choose M here: the module will - be called dell-wmi-sysman. - -config DELL_WMI_DESCRIPTOR - tristate - depends on ACPI_WMI - -config DELL_WMI_AIO - tristate "WMI Hotkeys for Dell All-In-One series" - depends on ACPI_WMI - depends on INPUT - select INPUT_SPARSEKMAP - help - Say Y here if you want to support WMI-based hotkeys on Dell - All-In-One machines. - - To compile this driver as a module, choose M here: the module will - be called dell-wmi-aio. - -config DELL_WMI_LED - tristate "External LED on Dell Business Netbooks" - depends on LEDS_CLASS - depends on ACPI_WMI - help - This adds support for the Latitude 2100 and similar - notebooks that have an external LED. +source "drivers/platform/x86/dell/Kconfig" config AMILO_RFKILL tristate "Fujitsu-Siemens Amilo rfkill support" @@ -626,6 +452,8 @@ config IDEAPAD_LAPTOP depends on ACPI_WMI || ACPI_WMI = n depends on ACPI_PLATFORM_PROFILE select INPUT_SPARSEKMAP + select NEW_LEDS + select LEDS_CLASS help This is a driver for Lenovo IdeaPad netbooks contains drivers for rfkill switch, hotkey, fan control and backlight control. @@ -656,6 +484,7 @@ config THINKPAD_ACPI depends on RFKILL || RFKILL = n depends on ACPI_VIDEO || ACPI_VIDEO = n depends on BACKLIGHT_CLASS_DEVICE + depends on ACPI_PLATFORM_PROFILE select HWMON select NVRAM select NEW_LEDS diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 19306450d791..60d554073749 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -9,7 +9,6 @@ obj-$(CONFIG_ACPI_WMI) += wmi.o obj-$(CONFIG_WMI_BMOF) += wmi-bmof.o # WMI drivers -obj-$(CONFIG_ALIENWARE_WMI) += alienware-wmi.o obj-$(CONFIG_HUAWEI_WMI) += huawei-wmi.o obj-$(CONFIG_INTEL_WMI_SBL_FW_UPDATE) += intel-wmi-sbl-fw-update.o obj-$(CONFIG_INTEL_WMI_THUNDERBOLT) += intel-wmi-thunderbolt.o @@ -37,20 +36,7 @@ obj-$(CONFIG_EEEPC_LAPTOP) += eeepc-laptop.o obj-$(CONFIG_EEEPC_WMI) += eeepc-wmi.o # Dell -obj-$(CONFIG_DCDBAS) += dcdbas.o -obj-$(CONFIG_DELL_SMBIOS) += dell-smbios.o -dell-smbios-objs := dell-smbios-base.o -dell-smbios-$(CONFIG_DELL_SMBIOS_WMI) += dell-smbios-wmi.o -dell-smbios-$(CONFIG_DELL_SMBIOS_SMM) += dell-smbios-smm.o -obj-$(CONFIG_DELL_LAPTOP) += dell-laptop.o -obj-$(CONFIG_DELL_RBTN) += dell-rbtn.o -obj-$(CONFIG_DELL_RBU) += dell_rbu.o -obj-$(CONFIG_DELL_SMO8800) += dell-smo8800.o -obj-$(CONFIG_DELL_WMI) += dell-wmi.o -obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o -obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o -obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o -obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ +obj-$(CONFIG_X86_PLATFORM_DRIVERS_DELL) += dell/ # Fujitsu obj-$(CONFIG_AMILO_RFKILL) += amilo-rfkill.o diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c index c1a5357da885..85db9403cc14 100644 --- a/drivers/platform/x86/acer-wmi.c +++ b/drivers/platform/x86/acer-wmi.c @@ -30,7 +30,6 @@ #include <linux/input/sparse-keymap.h> #include <acpi/video.h> -ACPI_MODULE_NAME(KBUILD_MODNAME); MODULE_AUTHOR("Carlos Corbacho"); MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver"); MODULE_LICENSE("GPL"); @@ -1605,7 +1604,8 @@ static void acer_kbd_dock_get_initial_state(void) status = wmi_evaluate_method(WMID_GUID3, 0, 0x2, &input_buf, &output_buf); if (ACPI_FAILURE(status)) { - ACPI_EXCEPTION((AE_INFO, status, "Error getting keyboard-dock initial status")); + pr_err("Error getting keyboard-dock initial status: %s\n", + acpi_format_exception(status)); return; } diff --git a/drivers/platform/x86/dell/Kconfig b/drivers/platform/x86/dell/Kconfig new file mode 100644 index 000000000000..e0a55337f51a --- /dev/null +++ b/drivers/platform/x86/dell/Kconfig @@ -0,0 +1,207 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Dell X86 Platform Specific Drivers +# + +menuconfig X86_PLATFORM_DRIVERS_DELL + bool "Dell X86 Platform Specific Device Drivers" + default n + depends on X86_PLATFORM_DEVICES + help + Say Y here to get to see options for device drivers for various + Dell x86 platforms, including vendor-specific laptop extension drivers. + This option alone does not add any kernel code. + + If you say N, all options in this submenu will be skipped and disabled. + +if X86_PLATFORM_DRIVERS_DELL + +config ALIENWARE_WMI + tristate "Alienware Special feature control" + default m + depends on ACPI + depends on LEDS_CLASS + depends on NEW_LEDS + depends on ACPI_WMI + help + This is a driver for controlling Alienware BIOS driven + features. It exposes an interface for controlling the AlienFX + zones on Alienware machines that don't contain a dedicated AlienFX + USB MCU such as the X51 and X51-R2. + +config DCDBAS + tristate "Dell Systems Management Base Driver" + default m + depends on X86 + help + The Dell Systems Management Base Driver provides a sysfs interface + for systems management software to perform System Management + Interrupts (SMIs) and Host Control Actions (system power cycle or + power off after OS shutdown) on certain Dell systems. + + See <file:Documentation/driver-api/dcdbas.rst> for more details on the driver + and the Dell systems on which Dell systems management software makes + use of this driver. + + Say Y or M here to enable the driver for use by Dell systems + management software such as Dell OpenManage. + +config DELL_LAPTOP + tristate "Dell Laptop Extras" + default m + depends on DMI + depends on BACKLIGHT_CLASS_DEVICE + depends on ACPI_VIDEO || ACPI_VIDEO = n + depends on RFKILL || RFKILL = n + depends on SERIO_I8042 + depends on DELL_SMBIOS + select POWER_SUPPLY + select LEDS_CLASS + select NEW_LEDS + select LEDS_TRIGGERS + select LEDS_TRIGGER_AUDIO + help + This driver adds support for rfkill and backlight control to Dell + laptops (except for some models covered by the Compal driver). + +config DELL_RBU + tristate "BIOS update support for DELL systems via sysfs" + default m + depends on X86 + select FW_LOADER + select FW_LOADER_USER_HELPER + help + Say m if you want to have the option of updating the BIOS for your + DELL system. Note you need a Dell OpenManage or Dell Update package (DUP) + supporting application to communicate with the BIOS regarding the new + image for the image update to take effect. + See <file:Documentation/admin-guide/dell_rbu.rst> for more details on the driver. + +config DELL_RBTN + tristate "Dell Airplane Mode Switch driver" + default m + depends on ACPI + depends on INPUT + depends on RFKILL + help + Say Y here if you want to support Dell Airplane Mode Switch ACPI + device on Dell laptops. Sometimes it has names: DELLABCE or DELRBTN. + This driver register rfkill device or input hotkey device depending + on hardware type (hw switch slider or keyboard toggle button). For + rfkill devices it receive HW switch events and set correct hard + rfkill state. + + To compile this driver as a module, choose M here: the module will + be called dell-rbtn. + +# +# The DELL_SMBIOS driver depends on ACPI_WMI and/or DCDBAS if those +# backends are selected. The "depends" line prevents a configuration +# where DELL_SMBIOS=y while either of those dependencies =m. +# +config DELL_SMBIOS + tristate "Dell SMBIOS driver" + default m + depends on DCDBAS || DCDBAS=n + depends on ACPI_WMI || ACPI_WMI=n + help + This provides support for the Dell SMBIOS calling interface. + If you have a Dell computer you should enable this option. + + Be sure to select at least one backend for it to work properly. + +config DELL_SMBIOS_WMI + bool "Dell SMBIOS driver WMI backend" + default y + depends on ACPI_WMI + select DELL_WMI_DESCRIPTOR + depends on DELL_SMBIOS + help + This provides an implementation for the Dell SMBIOS calling interface + communicated over ACPI-WMI. + + If you have a Dell computer from >2007 you should say Y here. + If you aren't sure and this module doesn't work for your computer + it just won't load. + +config DELL_SMBIOS_SMM + bool "Dell SMBIOS driver SMM backend" + default y + depends on DCDBAS + depends on DELL_SMBIOS + help + This provides an implementation for the Dell SMBIOS calling interface + communicated over SMI/SMM. + + If you have a Dell computer from <=2017 you should say Y here. + If you aren't sure and this module doesn't work for your computer + it just won't load. + +config DELL_SMO8800 + tristate "Dell Latitude freefall driver (ACPI SMO88XX)" + default m + depends on ACPI + help + Say Y here if you want to support SMO88XX freefall devices + on Dell Latitude laptops. + + To compile this driver as a module, choose M here: the module will + be called dell-smo8800. + +config DELL_WMI + tristate "Dell WMI notifications" + default m + depends on ACPI_WMI + depends on DMI + depends on INPUT + depends on ACPI_VIDEO || ACPI_VIDEO = n + depends on DELL_SMBIOS + select DELL_WMI_DESCRIPTOR + select INPUT_SPARSEKMAP + help + Say Y here if you want to support WMI-based hotkeys on Dell laptops. + + To compile this driver as a module, choose M here: the module will + be called dell-wmi. + +config DELL_WMI_AIO + tristate "WMI Hotkeys for Dell All-In-One series" + default m + depends on ACPI_WMI + depends on INPUT + select INPUT_SPARSEKMAP + help + Say Y here if you want to support WMI-based hotkeys on Dell + All-In-One machines. + + To compile this driver as a module, choose M here: the module will + be called dell-wmi-aio. + +config DELL_WMI_DESCRIPTOR + tristate + default m + depends on ACPI_WMI + +config DELL_WMI_LED + tristate "External LED on Dell Business Netbooks" + default m + depends on LEDS_CLASS + depends on ACPI_WMI + help + This adds support for the Latitude 2100 and similar + notebooks that have an external LED. + +config DELL_WMI_SYSMAN + tristate "Dell WMI-based Systems management driver" + default m + depends on ACPI_WMI + depends on DMI + select NLS + help + This driver allows changing BIOS settings on many Dell machines from + 2018 and newer without the use of any additional software. + + To compile this driver as a module, choose M here: the module will + be called dell-wmi-sysman. + +endif # X86_PLATFORM_DRIVERS_DELL diff --git a/drivers/platform/x86/dell/Makefile b/drivers/platform/x86/dell/Makefile new file mode 100644 index 000000000000..d720a3e42ae3 --- /dev/null +++ b/drivers/platform/x86/dell/Makefile @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for linux/drivers/platform/x86/dell +# Dell x86 Platform-Specific Drivers +# + +obj-$(CONFIG_ALIENWARE_WMI) += alienware-wmi.o +obj-$(CONFIG_DCDBAS) += dcdbas.o +obj-$(CONFIG_DELL_LAPTOP) += dell-laptop.o +obj-$(CONFIG_DELL_RBTN) += dell-rbtn.o +obj-$(CONFIG_DELL_RBU) += dell_rbu.o +obj-$(CONFIG_DELL_SMBIOS) += dell-smbios.o +dell-smbios-objs := dell-smbios-base.o +dell-smbios-$(CONFIG_DELL_SMBIOS_WMI) += dell-smbios-wmi.o +dell-smbios-$(CONFIG_DELL_SMBIOS_SMM) += dell-smbios-smm.o +obj-$(CONFIG_DELL_SMO8800) += dell-smo8800.o +obj-$(CONFIG_DELL_WMI) += dell-wmi.o +obj-$(CONFIG_DELL_WMI_AIO) += dell-wmi-aio.o +obj-$(CONFIG_DELL_WMI_DESCRIPTOR) += dell-wmi-descriptor.o +obj-$(CONFIG_DELL_WMI_LED) += dell-wmi-led.o +obj-$(CONFIG_DELL_WMI_SYSMAN) += dell-wmi-sysman/ diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/dell/alienware-wmi.c index 5bb2859c8285..5bb2859c8285 100644 --- a/drivers/platform/x86/alienware-wmi.c +++ b/drivers/platform/x86/dell/alienware-wmi.c diff --git a/drivers/platform/x86/dcdbas.c b/drivers/platform/x86/dell/dcdbas.c index d513a59a5d47..d513a59a5d47 100644 --- a/drivers/platform/x86/dcdbas.c +++ b/drivers/platform/x86/dell/dcdbas.c diff --git a/drivers/platform/x86/dcdbas.h b/drivers/platform/x86/dell/dcdbas.h index c3cca5433525..c3cca5433525 100644 --- a/drivers/platform/x86/dcdbas.h +++ b/drivers/platform/x86/dell/dcdbas.h diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c index 70edc5bb3a14..70edc5bb3a14 100644 --- a/drivers/platform/x86/dell-laptop.c +++ b/drivers/platform/x86/dell/dell-laptop.c diff --git a/drivers/platform/x86/dell-rbtn.c b/drivers/platform/x86/dell/dell-rbtn.c index a89fad47ff13..a89fad47ff13 100644 --- a/drivers/platform/x86/dell-rbtn.c +++ b/drivers/platform/x86/dell/dell-rbtn.c diff --git a/drivers/platform/x86/dell-rbtn.h b/drivers/platform/x86/dell/dell-rbtn.h index 5e030f926c58..5e030f926c58 100644 --- a/drivers/platform/x86/dell-rbtn.h +++ b/drivers/platform/x86/dell/dell-rbtn.h diff --git a/drivers/platform/x86/dell-smbios-base.c b/drivers/platform/x86/dell/dell-smbios-base.c index 3a1dbf199441..3a1dbf199441 100644 --- a/drivers/platform/x86/dell-smbios-base.c +++ b/drivers/platform/x86/dell/dell-smbios-base.c diff --git a/drivers/platform/x86/dell-smbios-smm.c b/drivers/platform/x86/dell/dell-smbios-smm.c index 97c52a839a3e..97c52a839a3e 100644 --- a/drivers/platform/x86/dell-smbios-smm.c +++ b/drivers/platform/x86/dell/dell-smbios-smm.c diff --git a/drivers/platform/x86/dell-smbios-wmi.c b/drivers/platform/x86/dell/dell-smbios-wmi.c index 27a298b7c541..27a298b7c541 100644 --- a/drivers/platform/x86/dell-smbios-wmi.c +++ b/drivers/platform/x86/dell/dell-smbios-wmi.c diff --git a/drivers/platform/x86/dell-smbios.h b/drivers/platform/x86/dell/dell-smbios.h index 75fa8ea0476d..75fa8ea0476d 100644 --- a/drivers/platform/x86/dell-smbios.h +++ b/drivers/platform/x86/dell/dell-smbios.h diff --git a/drivers/platform/x86/dell-smo8800.c b/drivers/platform/x86/dell/dell-smo8800.c index 5d9304a7de1b..5d9304a7de1b 100644 --- a/drivers/platform/x86/dell-smo8800.c +++ b/drivers/platform/x86/dell/dell-smo8800.c diff --git a/drivers/platform/x86/dell-wmi-aio.c b/drivers/platform/x86/dell/dell-wmi-aio.c index c7b7f1e403fb..c7b7f1e403fb 100644 --- a/drivers/platform/x86/dell-wmi-aio.c +++ b/drivers/platform/x86/dell/dell-wmi-aio.c diff --git a/drivers/platform/x86/dell-wmi-descriptor.c b/drivers/platform/x86/dell/dell-wmi-descriptor.c index a068900ae8a1..a068900ae8a1 100644 --- a/drivers/platform/x86/dell-wmi-descriptor.c +++ b/drivers/platform/x86/dell/dell-wmi-descriptor.c diff --git a/drivers/platform/x86/dell-wmi-descriptor.h b/drivers/platform/x86/dell/dell-wmi-descriptor.h index 1f469fef1535..1f469fef1535 100644 --- a/drivers/platform/x86/dell-wmi-descriptor.h +++ b/drivers/platform/x86/dell/dell-wmi-descriptor.h diff --git a/drivers/platform/x86/dell-wmi-led.c b/drivers/platform/x86/dell/dell-wmi-led.c index 5bedaf7f0633..5bedaf7f0633 100644 --- a/drivers/platform/x86/dell-wmi-led.c +++ b/drivers/platform/x86/dell/dell-wmi-led.c diff --git a/drivers/platform/x86/dell-wmi-sysman/Makefile b/drivers/platform/x86/dell/dell-wmi-sysman/Makefile index 825fb2fbeea8..825fb2fbeea8 100644 --- a/drivers/platform/x86/dell-wmi-sysman/Makefile +++ b/drivers/platform/x86/dell/dell-wmi-sysman/Makefile diff --git a/drivers/platform/x86/dell-wmi-sysman/biosattr-interface.c b/drivers/platform/x86/dell/dell-wmi-sysman/biosattr-interface.c index f95d8ddace5a..f95d8ddace5a 100644 --- a/drivers/platform/x86/dell-wmi-sysman/biosattr-interface.c +++ b/drivers/platform/x86/dell/dell-wmi-sysman/biosattr-interface.c diff --git a/drivers/platform/x86/dell-wmi-sysman/dell-wmi-sysman.h b/drivers/platform/x86/dell/dell-wmi-sysman/dell-wmi-sysman.h index b80f2a62ea3f..b80f2a62ea3f 100644 --- a/drivers/platform/x86/dell-wmi-sysman/dell-wmi-sysman.h +++ b/drivers/platform/x86/dell/dell-wmi-sysman/dell-wmi-sysman.h diff --git a/drivers/platform/x86/dell-wmi-sysman/enum-attributes.c b/drivers/platform/x86/dell/dell-wmi-sysman/enum-attributes.c index 80f4b7785c6c..80f4b7785c6c 100644 --- a/drivers/platform/x86/dell-wmi-sysman/enum-attributes.c +++ b/drivers/platform/x86/dell/dell-wmi-sysman/enum-attributes.c diff --git a/drivers/platform/x86/dell-wmi-sysman/int-attributes.c b/drivers/platform/x86/dell/dell-wmi-sysman/int-attributes.c index 75aedbb733be..75aedbb733be 100644 --- a/drivers/platform/x86/dell-wmi-sysman/int-attributes.c +++ b/drivers/platform/x86/dell/dell-wmi-sysman/int-attributes.c diff --git a/drivers/platform/x86/dell-wmi-sysman/passobj-attributes.c b/drivers/platform/x86/dell/dell-wmi-sysman/passobj-attributes.c index 3abcd95477c0..3abcd95477c0 100644 --- a/drivers/platform/x86/dell-wmi-sysman/passobj-attributes.c +++ b/drivers/platform/x86/dell/dell-wmi-sysman/passobj-attributes.c diff --git a/drivers/platform/x86/dell-wmi-sysman/passwordattr-interface.c b/drivers/platform/x86/dell/dell-wmi-sysman/passwordattr-interface.c index 5780b4d94759..5780b4d94759 100644 --- a/drivers/platform/x86/dell-wmi-sysman/passwordattr-interface.c +++ b/drivers/platform/x86/dell/dell-wmi-sysman/passwordattr-interface.c diff --git a/drivers/platform/x86/dell-wmi-sysman/string-attributes.c b/drivers/platform/x86/dell/dell-wmi-sysman/string-attributes.c index ac75dce88a4c..ac75dce88a4c 100644 --- a/drivers/platform/x86/dell-wmi-sysman/string-attributes.c +++ b/drivers/platform/x86/dell/dell-wmi-sysman/string-attributes.c diff --git a/drivers/platform/x86/dell-wmi-sysman/sysman.c b/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c index cb81010ba1a2..cb81010ba1a2 100644 --- a/drivers/platform/x86/dell-wmi-sysman/sysman.c +++ b/drivers/platform/x86/dell/dell-wmi-sysman/sysman.c diff --git a/drivers/platform/x86/dell-wmi.c b/drivers/platform/x86/dell/dell-wmi.c index bbdb3e860892..bbdb3e860892 100644 --- a/drivers/platform/x86/dell-wmi.c +++ b/drivers/platform/x86/dell/dell-wmi.c diff --git a/drivers/platform/x86/dell_rbu.c b/drivers/platform/x86/dell/dell_rbu.c index 03c3ff34bcf5..03c3ff34bcf5 100644 --- a/drivers/platform/x86/dell_rbu.c +++ b/drivers/platform/x86/dell/dell_rbu.c diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index cc42af2a0a98..6cb5ad4be231 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -8,34 +8,34 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include <linux/acpi.h> +#include <linux/backlight.h> +#include <linux/bitops.h> +#include <linux/bug.h> +#include <linux/debugfs.h> +#include <linux/device.h> +#include <linux/dmi.h> +#include <linux/fb.h> +#include <linux/i8042.h> +#include <linux/init.h> +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> +#include <linux/jiffies.h> #include <linux/kernel.h> +#include <linux/leds.h> #include <linux/module.h> -#include <linux/init.h> -#include <linux/types.h> -#include <linux/acpi.h> -#include <linux/rfkill.h> #include <linux/platform_device.h> #include <linux/platform_profile.h> -#include <linux/input.h> -#include <linux/input/sparse-keymap.h> -#include <linux/backlight.h> -#include <linux/fb.h> -#include <linux/debugfs.h> +#include <linux/rfkill.h> #include <linux/seq_file.h> -#include <linux/i8042.h> -#include <linux/dmi.h> -#include <linux/device.h> -#include <acpi/video.h> +#include <linux/sysfs.h> +#include <linux/types.h> -#define IDEAPAD_RFKILL_DEV_NUM (3) +#include <acpi/video.h> -#define BM_CONSERVATION_BIT (5) -#define HA_FNLOCK_BIT (10) +#include <dt-bindings/leds/common.h> -#define CFG_BT_BIT (16) -#define CFG_3G_BIT (17) -#define CFG_WIFI_BIT (18) -#define CFG_CAMERA_BIT (19) +#define IDEAPAD_RFKILL_DEV_NUM 3 #if IS_ENABLED(CONFIG_ACPI_WMI) static const char *const ideapad_wmi_fnesc_events[] = { @@ -45,10 +45,39 @@ static const char *const ideapad_wmi_fnesc_events[] = { #endif enum { - BMCMD_CONSERVATION_ON = 3, - BMCMD_CONSERVATION_OFF = 5, - HACMD_FNLOCK_ON = 0xe, - HACMD_FNLOCK_OFF = 0xf, + CFG_CAP_BT_BIT = 16, + CFG_CAP_3G_BIT = 17, + CFG_CAP_WIFI_BIT = 18, + CFG_CAP_CAM_BIT = 19, + CFG_CAP_TOUCHPAD_BIT = 30, +}; + +enum { + GBMD_CONSERVATION_STATE_BIT = 5, +}; + +enum { + SMBC_CONSERVATION_ON = 3, + SMBC_CONSERVATION_OFF = 5, +}; + +enum { + HALS_KBD_BL_SUPPORT_BIT = 4, + HALS_KBD_BL_STATE_BIT = 5, + HALS_USB_CHARGING_SUPPORT_BIT = 6, + HALS_USB_CHARGING_STATE_BIT = 7, + HALS_FNLOCK_SUPPORT_BIT = 9, + HALS_FNLOCK_STATE_BIT = 10, + HALS_HOTKEYS_PRIMARY_BIT = 11, +}; + +enum { + SALS_KBD_BL_ON = 0x8, + SALS_KBD_BL_OFF = 0x9, + SALS_USB_CHARGING_ON = 0xa, + SALS_USB_CHARGING_OFF = 0xb, + SALS_FNLOCK_ON = 0xe, + SALS_FNLOCK_OFF = 0xf, }; enum { @@ -81,7 +110,7 @@ enum { struct ideapad_dytc_priv { enum platform_profile_option current_profile; struct platform_profile_handler pprof; - struct mutex mutex; + struct mutex mutex; /* protects the DYTC interface */ struct ideapad_private *priv; }; @@ -100,9 +129,22 @@ struct ideapad_private { struct ideapad_dytc_priv *dytc; struct dentry *debug; unsigned long cfg; - bool has_hw_rfkill_switch; - bool has_touchpad_switch; const char *fnesc_guid; + struct { + bool conservation_mode : 1; + bool dytc : 1; + bool fan_mode : 1; + bool fn_lock : 1; + bool hw_rfkill_switch : 1; + bool kbd_bl : 1; + bool touchpad_ctrl_via_ec : 1; + bool usb_charging : 1; + } features; + struct { + bool initialized; + struct led_classdev led; + unsigned int last_brightness; + } kbd_bl; }; static bool no_bt_rfkill; @@ -112,86 +154,82 @@ MODULE_PARM_DESC(no_bt_rfkill, "No rfkill for bluetooth."); /* * ACPI Helpers */ -#define IDEAPAD_EC_TIMEOUT (200) /* in ms */ +#define IDEAPAD_EC_TIMEOUT 200 /* in ms */ -static int read_method_int(acpi_handle handle, const char *method, int *val) +static int eval_int(acpi_handle handle, const char *name, unsigned long *res) { - acpi_status status; unsigned long long result; + acpi_status status; - status = acpi_evaluate_integer(handle, (char *)method, NULL, &result); - if (ACPI_FAILURE(status)) { - *val = -1; - return -1; - } - *val = result; - return 0; + status = acpi_evaluate_integer(handle, (char *)name, NULL, &result); + if (ACPI_FAILURE(status)) + return -EIO; + *res = result; + + return 0; } -static int method_gbmd(acpi_handle handle, unsigned long *ret) +static int exec_simple_method(acpi_handle handle, const char *name, unsigned long arg) { - int result, val; + acpi_status status = acpi_execute_simple_method(handle, (char *)name, arg); - result = read_method_int(handle, "GBMD", &val); - *ret = val; - return result; + return ACPI_FAILURE(status) ? -EIO : 0; } -static int method_int1(acpi_handle handle, char *method, int cmd) +static int eval_gbmd(acpi_handle handle, unsigned long *res) { - acpi_status status; - - status = acpi_execute_simple_method(handle, method, cmd); - return ACPI_FAILURE(status) ? -1 : 0; + return eval_int(handle, "GBMD", res); } -static int method_dytc(acpi_handle handle, int cmd, int *ret) +static int exec_smbc(acpi_handle handle, unsigned long arg) { - acpi_status status; - unsigned long long result; - struct acpi_object_list params; - union acpi_object in_obj; - - params.count = 1; - params.pointer = &in_obj; - in_obj.type = ACPI_TYPE_INTEGER; - in_obj.integer.value = cmd; + return exec_simple_method(handle, "SMBC", arg); +} - status = acpi_evaluate_integer(handle, "DYTC", ¶ms, &result); +static int eval_hals(acpi_handle handle, unsigned long *res) +{ + return eval_int(handle, "HALS", res); +} - if (ACPI_FAILURE(status)) { - *ret = -1; - return -1; - } - *ret = result; - return 0; +static int exec_sals(acpi_handle handle, unsigned long arg) +{ + return exec_simple_method(handle, "SALS", arg); } -static int method_vpcr(acpi_handle handle, int cmd, int *ret) +static int eval_int_with_arg(acpi_handle handle, const char *name, unsigned long arg, unsigned long *res) { - acpi_status status; - unsigned long long result; struct acpi_object_list params; + unsigned long long result; union acpi_object in_obj; + acpi_status status; params.count = 1; params.pointer = &in_obj; in_obj.type = ACPI_TYPE_INTEGER; - in_obj.integer.value = cmd; + in_obj.integer.value = arg; - status = acpi_evaluate_integer(handle, "VPCR", ¶ms, &result); + status = acpi_evaluate_integer(handle, (char *)name, ¶ms, &result); + if (ACPI_FAILURE(status)) + return -EIO; + + if (res) + *res = result; - if (ACPI_FAILURE(status)) { - *ret = -1; - return -1; - } - *ret = result; return 0; +} +static int eval_dytc(acpi_handle handle, unsigned long cmd, unsigned long *res) +{ + return eval_int_with_arg(handle, "DYTC", cmd, res); } -static int method_vpcw(acpi_handle handle, int cmd, int data) +static int eval_vpcr(acpi_handle handle, unsigned long cmd, unsigned long *res) +{ + return eval_int_with_arg(handle, "VPCR", cmd, res); +} + +static int eval_vpcw(acpi_handle handle, unsigned long cmd, unsigned long data) { struct acpi_object_list params; union acpi_object in_obj[2]; @@ -205,55 +243,68 @@ static int method_vpcw(acpi_handle handle, int cmd, int data) in_obj[1].integer.value = data; status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); - if (status != AE_OK) - return -1; + if (ACPI_FAILURE(status)) + return -EIO; + return 0; } -static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data) +static int read_ec_data(acpi_handle handle, unsigned long cmd, unsigned long *data) { - int val; - unsigned long int end_jiffies; + unsigned long end_jiffies, val; + int err; - if (method_vpcw(handle, 1, cmd)) - return -1; + err = eval_vpcw(handle, 1, cmd); + if (err) + return err; - for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1; - time_before(jiffies, end_jiffies);) { + end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; + + while (time_before(jiffies, end_jiffies)) { schedule(); - if (method_vpcr(handle, 1, &val)) - return -1; - if (val == 0) { - if (method_vpcr(handle, 0, &val)) - return -1; - *data = val; - return 0; - } + + err = eval_vpcr(handle, 1, &val); + if (err) + return err; + + if (val == 0) + return eval_vpcr(handle, 0, data); } - pr_err("timeout in %s\n", __func__); - return -1; + + acpi_handle_err(handle, "timeout in %s\n", __func__); + + return -ETIMEDOUT; } -static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data) +static int write_ec_cmd(acpi_handle handle, unsigned long cmd, unsigned long data) { - int val; - unsigned long int end_jiffies; + unsigned long end_jiffies, val; + int err; + + err = eval_vpcw(handle, 0, data); + if (err) + return err; + + err = eval_vpcw(handle, 1, cmd); + if (err) + return err; - if (method_vpcw(handle, 0, data)) - return -1; - if (method_vpcw(handle, 1, cmd)) - return -1; + end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; - for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1; - time_before(jiffies, end_jiffies);) { + while (time_before(jiffies, end_jiffies)) { schedule(); - if (method_vpcr(handle, 1, &val)) - return -1; + + err = eval_vpcr(handle, 1, &val); + if (err) + return err; + if (val == 0) return 0; } - pr_err("timeout in %s\n", __func__); - return -1; + + acpi_handle_err(handle, "timeout in %s\n", __func__); + + return -ETIMEDOUT; } /* @@ -264,44 +315,37 @@ static int debugfs_status_show(struct seq_file *s, void *data) struct ideapad_private *priv = s->private; unsigned long value; - if (!priv) - return -EINVAL; - if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &value)) - seq_printf(s, "Backlight max:\t%lu\n", value); + seq_printf(s, "Backlight max: %lu\n", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL, &value)) - seq_printf(s, "Backlight now:\t%lu\n", value); + seq_printf(s, "Backlight now: %lu\n", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &value)) - seq_printf(s, "BL power value:\t%s\n", value ? "On" : "Off"); - seq_printf(s, "=====================\n"); + seq_printf(s, "BL power value: %s (%lu)\n", value ? "on" : "off", value); + + seq_puts(s, "=====================\n"); if (!read_ec_data(priv->adev->handle, VPCCMD_R_RF, &value)) - seq_printf(s, "Radio status:\t%s(%lu)\n", - value ? "On" : "Off", value); + seq_printf(s, "Radio status: %s (%lu)\n", value ? "on" : "off", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_WIFI, &value)) - seq_printf(s, "Wifi status:\t%s(%lu)\n", - value ? "On" : "Off", value); + seq_printf(s, "Wifi status: %s (%lu)\n", value ? "on" : "off", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_BT, &value)) - seq_printf(s, "BT status:\t%s(%lu)\n", - value ? "On" : "Off", value); + seq_printf(s, "BT status: %s (%lu)\n", value ? "on" : "off", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_3G, &value)) - seq_printf(s, "3G status:\t%s(%lu)\n", - value ? "On" : "Off", value); - seq_printf(s, "=====================\n"); + seq_printf(s, "3G status: %s (%lu)\n", value ? "on" : "off", value); + + seq_puts(s, "=====================\n"); if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) - seq_printf(s, "Touchpad status:%s(%lu)\n", - value ? "On" : "Off", value); + seq_printf(s, "Touchpad status: %s (%lu)\n", value ? "on" : "off", value); if (!read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &value)) - seq_printf(s, "Camera status:\t%s(%lu)\n", - value ? "On" : "Off", value); + seq_printf(s, "Camera status: %s (%lu)\n", value ? "on" : "off", value); + seq_puts(s, "=====================\n"); - if (!method_gbmd(priv->adev->handle, &value)) { - seq_printf(s, "Conservation mode:\t%s(%lu)\n", - test_bit(BM_CONSERVATION_BIT, &value) ? "On" : "Off", - value); - } + if (!eval_gbmd(priv->adev->handle, &value)) + seq_printf(s, "GBMD: %#010lx\n", value); + if (!eval_hals(priv->adev->handle, &value)) + seq_printf(s, "HALS: %#010lx\n", value); return 0; } @@ -311,39 +355,41 @@ static int debugfs_cfg_show(struct seq_file *s, void *data) { struct ideapad_private *priv = s->private; - if (!priv) { - seq_printf(s, "cfg: N/A\n"); - } else { - seq_printf(s, "cfg: 0x%.8lX\n\nCapability: ", - priv->cfg); - if (test_bit(CFG_BT_BIT, &priv->cfg)) - seq_printf(s, "Bluetooth "); - if (test_bit(CFG_3G_BIT, &priv->cfg)) - seq_printf(s, "3G "); - if (test_bit(CFG_WIFI_BIT, &priv->cfg)) - seq_printf(s, "Wireless "); - if (test_bit(CFG_CAMERA_BIT, &priv->cfg)) - seq_printf(s, "Camera "); - seq_printf(s, "\nGraphic: "); - switch ((priv->cfg)&0x700) { - case 0x100: - seq_printf(s, "Intel"); - break; - case 0x200: - seq_printf(s, "ATI"); - break; - case 0x300: - seq_printf(s, "Nvidia"); - break; - case 0x400: - seq_printf(s, "Intel and ATI"); - break; - case 0x500: - seq_printf(s, "Intel and Nvidia"); - break; - } - seq_printf(s, "\n"); + seq_printf(s, "_CFG: %#010lx\n\n", priv->cfg); + + seq_puts(s, "Capabilities:"); + if (test_bit(CFG_CAP_BT_BIT, &priv->cfg)) + seq_puts(s, " bluetooth"); + if (test_bit(CFG_CAP_3G_BIT, &priv->cfg)) + seq_puts(s, " 3G"); + if (test_bit(CFG_CAP_WIFI_BIT, &priv->cfg)) + seq_puts(s, " wifi"); + if (test_bit(CFG_CAP_CAM_BIT, &priv->cfg)) + seq_puts(s, " camera"); + if (test_bit(CFG_CAP_TOUCHPAD_BIT, &priv->cfg)) + seq_puts(s, " touchpad"); + seq_puts(s, "\n"); + + seq_puts(s, "Graphics: "); + switch (priv->cfg & 0x700) { + case 0x100: + seq_puts(s, "Intel"); + break; + case 0x200: + seq_puts(s, "ATI"); + break; + case 0x300: + seq_puts(s, "Nvidia"); + break; + case 0x400: + seq_puts(s, "Intel and ATI"); + break; + case 0x500: + seq_puts(s, "Intel and Nvidia"); + break; } + seq_puts(s, "\n"); + return 0; } DEFINE_SHOW_ATTRIBUTE(debugfs_cfg); @@ -355,8 +401,8 @@ static void ideapad_debugfs_init(struct ideapad_private *priv) dir = debugfs_create_dir("ideapad", NULL); priv->debug = dir; - debugfs_create_file("cfg", S_IRUGO, dir, priv, &debugfs_cfg_fops); - debugfs_create_file("status", S_IRUGO, dir, priv, &debugfs_status_fops); + debugfs_create_file("cfg", 0444, dir, priv, &debugfs_cfg_fops); + debugfs_create_file("status", 0444, dir, priv, &debugfs_status_fops); } static void ideapad_debugfs_exit(struct ideapad_private *priv) @@ -368,209 +414,256 @@ static void ideapad_debugfs_exit(struct ideapad_private *priv) /* * sysfs */ -static ssize_t show_ideapad_cam(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t camera_power_show(struct device *dev, + struct device_attribute *attr, + char *buf) { - unsigned long result; struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned long result; + int err; + + err = read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result); + if (err) + return err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_CAMERA, &result)) - return sprintf(buf, "-1\n"); - return sprintf(buf, "%lu\n", result); + return sysfs_emit(buf, "%d\n", !!result); } -static ssize_t store_ideapad_cam(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t camera_power_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { - int ret, state; struct ideapad_private *priv = dev_get_drvdata(dev); + bool state; + int err; + + err = kstrtobool(buf, &state); + if (err) + return err; + + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); + if (err) + return err; - if (!count) - return 0; - if (sscanf(buf, "%i", &state) != 1) - return -EINVAL; - ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); - if (ret < 0) - return -EIO; return count; } -static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam); +static DEVICE_ATTR_RW(camera_power); -static ssize_t show_ideapad_fan(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t conservation_mode_show(struct device *dev, + struct device_attribute *attr, + char *buf) { - unsigned long result; struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned long result; + int err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result)) - return sprintf(buf, "-1\n"); - return sprintf(buf, "%lu\n", result); + err = eval_gbmd(priv->adev->handle, &result); + if (err) + return err; + + return sysfs_emit(buf, "%d\n", !!test_bit(GBMD_CONSERVATION_STATE_BIT, &result)); } -static ssize_t store_ideapad_fan(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t conservation_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { - int ret, state; struct ideapad_private *priv = dev_get_drvdata(dev); + bool state; + int err; + + err = kstrtobool(buf, &state); + if (err) + return err; + + err = exec_smbc(priv->adev->handle, state ? SMBC_CONSERVATION_ON : SMBC_CONSERVATION_OFF); + if (err) + return err; - if (!count) - return 0; - if (sscanf(buf, "%i", &state) != 1) - return -EINVAL; - if (state < 0 || state > 4 || state == 3) - return -EINVAL; - ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state); - if (ret < 0) - return -EIO; return count; } -static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan); +static DEVICE_ATTR_RW(conservation_mode); -static ssize_t touchpad_show(struct device *dev, +static ssize_t fan_mode_show(struct device *dev, struct device_attribute *attr, char *buf) { struct ideapad_private *priv = dev_get_drvdata(dev); unsigned long result; + int err; + + err = read_ec_data(priv->adev->handle, VPCCMD_R_FAN, &result); + if (err) + return err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result)) - return sprintf(buf, "-1\n"); - return sprintf(buf, "%lu\n", result); + return sysfs_emit(buf, "%lu\n", result); } -/* Switch to RO for now: It might be revisited in the future */ -static ssize_t __maybe_unused touchpad_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t fan_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { struct ideapad_private *priv = dev_get_drvdata(dev); - bool state; - int ret; + unsigned int state; + int err; + + err = kstrtouint(buf, 0, &state); + if (err) + return err; - ret = kstrtobool(buf, &state); - if (ret) - return ret; + if (state > 4 || state == 3) + return -EINVAL; + + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state); + if (err) + return err; - ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state); - if (ret < 0) - return -EIO; return count; } -static DEVICE_ATTR_RO(touchpad); +static DEVICE_ATTR_RW(fan_mode); -static ssize_t conservation_mode_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t fn_lock_show(struct device *dev, + struct device_attribute *attr, + char *buf) { struct ideapad_private *priv = dev_get_drvdata(dev); - unsigned long result; + unsigned long hals; + int err; + + err = eval_hals(priv->adev->handle, &hals); + if (err) + return err; - if (method_gbmd(priv->adev->handle, &result)) - return sprintf(buf, "-1\n"); - return sprintf(buf, "%u\n", test_bit(BM_CONSERVATION_BIT, &result)); + return sysfs_emit(buf, "%d\n", !!test_bit(HALS_FNLOCK_STATE_BIT, &hals)); } -static ssize_t conservation_mode_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t fn_lock_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { struct ideapad_private *priv = dev_get_drvdata(dev); bool state; - int ret; + int err; - ret = kstrtobool(buf, &state); - if (ret) - return ret; + err = kstrtobool(buf, &state); + if (err) + return err; + + err = exec_sals(priv->adev->handle, state ? SALS_FNLOCK_ON : SALS_FNLOCK_OFF); + if (err) + return err; - ret = method_int1(priv->adev->handle, "SBMC", state ? - BMCMD_CONSERVATION_ON : - BMCMD_CONSERVATION_OFF); - if (ret < 0) - return -EIO; return count; } -static DEVICE_ATTR_RW(conservation_mode); +static DEVICE_ATTR_RW(fn_lock); -static ssize_t fn_lock_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t touchpad_show(struct device *dev, + struct device_attribute *attr, + char *buf) { struct ideapad_private *priv = dev_get_drvdata(dev); unsigned long result; - int hals; - int fail = read_method_int(priv->adev->handle, "HALS", &hals); + int err; - if (fail) - return sprintf(buf, "-1\n"); + err = read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result); + if (err) + return err; - result = hals; - return sprintf(buf, "%u\n", test_bit(HA_FNLOCK_BIT, &result)); + return sysfs_emit(buf, "%d\n", !!result); } -static ssize_t fn_lock_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t touchpad_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { struct ideapad_private *priv = dev_get_drvdata(dev); bool state; - int ret; + int err; - ret = kstrtobool(buf, &state); - if (ret) - return ret; + err = kstrtobool(buf, &state); + if (err) + return err; + + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state); + if (err) + return err; - ret = method_int1(priv->adev->handle, "SALS", state ? - HACMD_FNLOCK_ON : - HACMD_FNLOCK_OFF); - if (ret < 0) - return -EIO; return count; } -static DEVICE_ATTR_RW(fn_lock); +static DEVICE_ATTR_RW(touchpad); + +static ssize_t usb_charging_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct ideapad_private *priv = dev_get_drvdata(dev); + unsigned long hals; + int err; + + err = eval_hals(priv->adev->handle, &hals); + if (err) + return err; + + return sysfs_emit(buf, "%d\n", !!test_bit(HALS_USB_CHARGING_STATE_BIT, &hals)); +} + +static ssize_t usb_charging_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct ideapad_private *priv = dev_get_drvdata(dev); + bool state; + int err; + + err = kstrtobool(buf, &state); + if (err) + return err; + + err = exec_sals(priv->adev->handle, state ? SALS_USB_CHARGING_ON : SALS_USB_CHARGING_OFF); + if (err) + return err; + + return count; +} +static DEVICE_ATTR_RW(usb_charging); static struct attribute *ideapad_attributes[] = { &dev_attr_camera_power.attr, - &dev_attr_fan_mode.attr, - &dev_attr_touchpad.attr, &dev_attr_conservation_mode.attr, + &dev_attr_fan_mode.attr, &dev_attr_fn_lock.attr, + &dev_attr_touchpad.attr, + &dev_attr_usb_charging.attr, NULL }; static umode_t ideapad_is_visible(struct kobject *kobj, - struct attribute *attr, - int idx) + struct attribute *attr, + int idx) { - struct device *dev = container_of(kobj, struct device, kobj); + struct device *dev = kobj_to_dev(kobj); struct ideapad_private *priv = dev_get_drvdata(dev); - bool supported; + bool supported = true; if (attr == &dev_attr_camera_power.attr) - supported = test_bit(CFG_CAMERA_BIT, &(priv->cfg)); - else if (attr == &dev_attr_fan_mode.attr) { - unsigned long value; - supported = !read_ec_data(priv->adev->handle, VPCCMD_R_FAN, - &value); - } else if (attr == &dev_attr_conservation_mode.attr) { - supported = acpi_has_method(priv->adev->handle, "GBMD") && - acpi_has_method(priv->adev->handle, "SBMC"); - } else if (attr == &dev_attr_fn_lock.attr) { - supported = acpi_has_method(priv->adev->handle, "HALS") && - acpi_has_method(priv->adev->handle, "SALS"); - } else if (attr == &dev_attr_touchpad.attr) - supported = priv->has_touchpad_switch; - else - supported = true; + supported = test_bit(CFG_CAP_CAM_BIT, &priv->cfg); + else if (attr == &dev_attr_conservation_mode.attr) + supported = priv->features.conservation_mode; + else if (attr == &dev_attr_fan_mode.attr) + supported = priv->features.fan_mode; + else if (attr == &dev_attr_fn_lock.attr) + supported = priv->features.fn_lock; + else if (attr == &dev_attr_touchpad.attr) + supported = priv->features.touchpad_ctrl_via_ec && + test_bit(CFG_CAP_TOUCHPAD_BIT, &priv->cfg); + else if (attr == &dev_attr_usb_charging.attr) + supported = priv->features.usb_charging; return supported ? attr->mode : 0; } @@ -631,6 +724,7 @@ static int convert_dytc_to_profile(int dytcmode, enum platform_profile_option *p default: /* Unknown mode */ return -EINVAL; } + return 0; } @@ -649,6 +743,7 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe default: /* Unknown profile */ return -EOPNOTSUPP; } + return 0; } @@ -656,49 +751,48 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe * dytc_profile_get: Function to register with platform_profile * handler. Returns current platform profile. */ -int dytc_profile_get(struct platform_profile_handler *pprof, - enum platform_profile_option *profile) +static int dytc_profile_get(struct platform_profile_handler *pprof, + enum platform_profile_option *profile) { - struct ideapad_dytc_priv *dytc; + struct ideapad_dytc_priv *dytc = container_of(pprof, struct ideapad_dytc_priv, pprof); - dytc = container_of(pprof, struct ideapad_dytc_priv, pprof); *profile = dytc->current_profile; return 0; } /* * Helper function - check if we are in CQL mode and if we are - * - disable CQL, + * - disable CQL, * - run the command * - enable CQL * If not in CQL mode, just run the command */ -int dytc_cql_command(struct ideapad_private *priv, int command, int *output) +static int dytc_cql_command(struct ideapad_private *priv, unsigned long cmd, + unsigned long *output) { - int err, cmd_err, dummy; - int cur_funcmode; + int err, cmd_err, cur_funcmode; /* Determine if we are in CQL mode. This alters the commands we do */ - err = method_dytc(priv->adev->handle, DYTC_CMD_GET, output); + err = eval_dytc(priv->adev->handle, DYTC_CMD_GET, output); if (err) return err; cur_funcmode = (*output >> DYTC_GET_FUNCTION_BIT) & 0xF; /* Check if we're OK to return immediately */ - if ((command == DYTC_CMD_GET) && (cur_funcmode != DYTC_FUNCTION_CQL)) + if (cmd == DYTC_CMD_GET && cur_funcmode != DYTC_FUNCTION_CQL) return 0; if (cur_funcmode == DYTC_FUNCTION_CQL) { - err = method_dytc(priv->adev->handle, DYTC_DISABLE_CQL, &dummy); + err = eval_dytc(priv->adev->handle, DYTC_DISABLE_CQL, NULL); if (err) return err; } - cmd_err = method_dytc(priv->adev->handle, command, output); + cmd_err = eval_dytc(priv->adev->handle, cmd, output); /* Check return condition after we've restored CQL state */ if (cur_funcmode == DYTC_FUNCTION_CQL) { - err = method_dytc(priv->adev->handle, DYTC_ENABLE_CQL, &dummy); + err = eval_dytc(priv->adev->handle, DYTC_ENABLE_CQL, NULL); if (err) return err; } @@ -710,24 +804,20 @@ int dytc_cql_command(struct ideapad_private *priv, int command, int *output) * dytc_profile_set: Function to register with platform_profile * handler. Sets current platform profile. */ -int dytc_profile_set(struct platform_profile_handler *pprof, - enum platform_profile_option profile) +static int dytc_profile_set(struct platform_profile_handler *pprof, + enum platform_profile_option profile) { - struct ideapad_dytc_priv *dytc; - struct ideapad_private *priv; - int output; + struct ideapad_dytc_priv *dytc = container_of(pprof, struct ideapad_dytc_priv, pprof); + struct ideapad_private *priv = dytc->priv; int err; - dytc = container_of(pprof, struct ideapad_dytc_priv, pprof); - priv = dytc->priv; - err = mutex_lock_interruptible(&dytc->mutex); if (err) return err; if (profile == PLATFORM_PROFILE_BALANCED) { /* To get back to balanced mode we just issue a reset command */ - err = method_dytc(priv->adev->handle, DYTC_CMD_RESET, &output); + err = eval_dytc(priv->adev->handle, DYTC_CMD_RESET, NULL); if (err) goto unlock; } else { @@ -738,24 +828,26 @@ int dytc_profile_set(struct platform_profile_handler *pprof, goto unlock; /* Determine if we are in CQL mode. This alters the commands we do */ - err = dytc_cql_command(priv, - DYTC_SET_COMMAND(DYTC_FUNCTION_MMC, perfmode, 1), - &output); + err = dytc_cql_command(priv, DYTC_SET_COMMAND(DYTC_FUNCTION_MMC, perfmode, 1), + NULL); if (err) goto unlock; } + /* Success - update current profile */ dytc->current_profile = profile; + unlock: mutex_unlock(&dytc->mutex); + return err; } static void dytc_profile_refresh(struct ideapad_private *priv) { enum platform_profile_option profile; - int output, err; - int perfmode; + unsigned long output; + int err, perfmode; mutex_lock(&priv->dytc->mutex); err = dytc_cql_command(priv, DYTC_CMD_GET, &output); @@ -764,7 +856,10 @@ static void dytc_profile_refresh(struct ideapad_private *priv) return; perfmode = (output >> DYTC_GET_MODE_BIT) & 0xF; - convert_dytc_to_profile(perfmode, &profile); + + if (convert_dytc_to_profile(perfmode, &profile)) + return; + if (profile != priv->dytc->current_profile) { priv->dytc->current_profile = profile; platform_profile_notify(); @@ -773,22 +868,26 @@ static void dytc_profile_refresh(struct ideapad_private *priv) static int ideapad_dytc_profile_init(struct ideapad_private *priv) { - int err, output, dytc_version; + int err, dytc_version; + unsigned long output; - err = method_dytc(priv->adev->handle, DYTC_CMD_QUERY, &output); + if (!priv->features.dytc) + return -ENODEV; + + err = eval_dytc(priv->adev->handle, DYTC_CMD_QUERY, &output); /* For all other errors we can flag the failure */ if (err) return err; /* Check DYTC is enabled and supports mode setting */ - if (!(output & BIT(DYTC_QUERY_ENABLE_BIT))) + if (!test_bit(DYTC_QUERY_ENABLE_BIT, &output)) return -ENODEV; dytc_version = (output >> DYTC_QUERY_REV_BIT) & 0xF; if (dytc_version < 5) return -ENODEV; - priv->dytc = kzalloc(sizeof(struct ideapad_dytc_priv), GFP_KERNEL); + priv->dytc = kzalloc(sizeof(*priv->dytc), GFP_KERNEL); if (!priv->dytc) return -ENOMEM; @@ -806,17 +905,18 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv) /* Create platform_profile structure and register */ err = platform_profile_register(&priv->dytc->pprof); if (err) - goto mutex_destroy; + goto pp_reg_failed; /* Ensure initial values are correct */ dytc_profile_refresh(priv); return 0; -mutex_destroy: +pp_reg_failed: mutex_destroy(&priv->dytc->mutex); kfree(priv->dytc); priv->dytc = NULL; + return err; } @@ -828,6 +928,7 @@ static void ideapad_dytc_profile_exit(struct ideapad_private *priv) platform_profile_remove(); mutex_destroy(&priv->dytc->mutex); kfree(priv->dytc); + priv->dytc = NULL; } @@ -842,9 +943,9 @@ struct ideapad_rfk_data { }; static const struct ideapad_rfk_data ideapad_rfk_data[] = { - { "ideapad_wlan", CFG_WIFI_BIT, VPCCMD_W_WIFI, RFKILL_TYPE_WLAN }, - { "ideapad_bluetooth", CFG_BT_BIT, VPCCMD_W_BT, RFKILL_TYPE_BLUETOOTH }, - { "ideapad_3g", CFG_3G_BIT, VPCCMD_W_3G, RFKILL_TYPE_WWAN }, + { "ideapad_wlan", CFG_CAP_WIFI_BIT, VPCCMD_W_WIFI, RFKILL_TYPE_WLAN }, + { "ideapad_bluetooth", CFG_CAP_BT_BIT, VPCCMD_W_BT, RFKILL_TYPE_BLUETOOTH }, + { "ideapad_3g", CFG_CAP_3G_BIT, VPCCMD_W_3G, RFKILL_TYPE_WWAN }, }; static int ideapad_rfk_set(void *data, bool blocked) @@ -864,7 +965,7 @@ static void ideapad_sync_rfk_state(struct ideapad_private *priv) unsigned long hw_blocked = 0; int i; - if (priv->has_hw_rfkill_switch) { + if (priv->features.hw_rfkill_switch) { if (read_ec_data(priv->adev->handle, VPCCMD_R_RF, &hw_blocked)) return; hw_blocked = !hw_blocked; @@ -877,16 +978,15 @@ static void ideapad_sync_rfk_state(struct ideapad_private *priv) static int ideapad_register_rfkill(struct ideapad_private *priv, int dev) { - int ret; - unsigned long sw_blocked; + unsigned long rf_enabled; + int err; - if (no_bt_rfkill && - (ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH)) { + if (no_bt_rfkill && ideapad_rfk_data[dev].type == RFKILL_TYPE_BLUETOOTH) { /* Force to enable bluetooth when no_bt_rfkill=1 */ - write_ec_cmd(priv->adev->handle, - ideapad_rfk_data[dev].opcode, 1); + write_ec_cmd(priv->adev->handle, ideapad_rfk_data[dev].opcode, 1); return 0; } + priv->rfk_priv[dev].dev = dev; priv->rfk_priv[dev].priv = priv; @@ -898,20 +998,17 @@ static int ideapad_register_rfkill(struct ideapad_private *priv, int dev) if (!priv->rfk[dev]) return -ENOMEM; - if (read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode-1, - &sw_blocked)) { - rfkill_init_sw_state(priv->rfk[dev], 0); - } else { - sw_blocked = !sw_blocked; - rfkill_init_sw_state(priv->rfk[dev], sw_blocked); - } + err = read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode - 1, &rf_enabled); + if (err) + rf_enabled = 1; - ret = rfkill_register(priv->rfk[dev]); - if (ret) { + rfkill_init_sw_state(priv->rfk[dev], !rf_enabled); + + err = rfkill_register(priv->rfk[dev]); + if (err) rfkill_destroy(priv->rfk[dev]); - return ret; - } - return 0; + + return err; } static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev) @@ -928,40 +1025,39 @@ static void ideapad_unregister_rfkill(struct ideapad_private *priv, int dev) */ static int ideapad_sysfs_init(struct ideapad_private *priv) { - return sysfs_create_group(&priv->platform_device->dev.kobj, - &ideapad_attribute_group); + return device_add_group(&priv->platform_device->dev, + &ideapad_attribute_group); } static void ideapad_sysfs_exit(struct ideapad_private *priv) { - sysfs_remove_group(&priv->platform_device->dev.kobj, - &ideapad_attribute_group); + device_remove_group(&priv->platform_device->dev, + &ideapad_attribute_group); } /* * input device */ static const struct key_entry ideapad_keymap[] = { - { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } }, - { KE_KEY, 7, { KEY_CAMERA } }, - { KE_KEY, 8, { KEY_MICMUTE } }, - { KE_KEY, 11, { KEY_F16 } }, - { KE_KEY, 13, { KEY_WLAN } }, - { KE_KEY, 16, { KEY_PROG1 } }, - { KE_KEY, 17, { KEY_PROG2 } }, - { KE_KEY, 64, { KEY_PROG3 } }, - { KE_KEY, 65, { KEY_PROG4 } }, - { KE_KEY, 66, { KEY_TOUCHPAD_OFF } }, - { KE_KEY, 67, { KEY_TOUCHPAD_ON } }, + { KE_KEY, 6, { KEY_SWITCHVIDEOMODE } }, + { KE_KEY, 7, { KEY_CAMERA } }, + { KE_KEY, 8, { KEY_MICMUTE } }, + { KE_KEY, 11, { KEY_F16 } }, + { KE_KEY, 13, { KEY_WLAN } }, + { KE_KEY, 16, { KEY_PROG1 } }, + { KE_KEY, 17, { KEY_PROG2 } }, + { KE_KEY, 64, { KEY_PROG3 } }, + { KE_KEY, 65, { KEY_PROG4 } }, + { KE_KEY, 66, { KEY_TOUCHPAD_OFF } }, + { KE_KEY, 67, { KEY_TOUCHPAD_ON } }, { KE_KEY, 128, { KEY_ESC } }, - - { KE_END, 0 }, + { KE_END }, }; static int ideapad_input_init(struct ideapad_private *priv) { struct input_dev *inputdev; - int error; + int err; inputdev = input_allocate_device(); if (!inputdev) @@ -972,24 +1068,28 @@ static int ideapad_input_init(struct ideapad_private *priv) inputdev->id.bustype = BUS_HOST; inputdev->dev.parent = &priv->platform_device->dev; - error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL); - if (error) { - pr_err("Unable to setup input device keymap\n"); + err = sparse_keymap_setup(inputdev, ideapad_keymap, NULL); + if (err) { + dev_err(&priv->platform_device->dev, + "Could not set up input device keymap: %d\n", err); goto err_free_dev; } - error = input_register_device(inputdev); - if (error) { - pr_err("Unable to register input device\n"); + err = input_register_device(inputdev); + if (err) { + dev_err(&priv->platform_device->dev, + "Could not register input device: %d\n", err); goto err_free_dev; } priv->inputdev = inputdev; + return 0; err_free_dev: input_free_device(inputdev); - return error; + + return err; } static void ideapad_input_exit(struct ideapad_private *priv) @@ -1010,6 +1110,7 @@ static void ideapad_input_novokey(struct ideapad_private *priv) if (read_ec_data(priv->adev->handle, VPCCMD_R_NOVO, &long_pressed)) return; + if (long_pressed) ideapad_input_report(priv, 17); else @@ -1020,24 +1121,24 @@ static void ideapad_check_special_buttons(struct ideapad_private *priv) { unsigned long bit, value; - read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value); - - for (bit = 0; bit < 16; bit++) { - if (test_bit(bit, &value)) { - switch (bit) { - case 0: /* Z580 */ - case 6: /* Z570 */ - /* Thermal Management button */ - ideapad_input_report(priv, 65); - break; - case 1: - /* OneKey Theater button */ - ideapad_input_report(priv, 64); - break; - default: - pr_info("Unknown special button: %lu\n", bit); - break; - } + if (read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value)) + return; + + for_each_set_bit (bit, &value, 16) { + switch (bit) { + case 6: /* Z570 */ + case 0: /* Z580 */ + /* Thermal Management button */ + ideapad_input_report(priv, 65); + break; + case 1: + /* OneKey Theater button */ + ideapad_input_report(priv, 64); + break; + default: + dev_info(&priv->platform_device->dev, + "Unknown special button: %lu\n", bit); + break; } } } @@ -1049,28 +1150,29 @@ static int ideapad_backlight_get_brightness(struct backlight_device *blightdev) { struct ideapad_private *priv = bl_get_data(blightdev); unsigned long now; + int err; - if (!priv) - return -EINVAL; + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); + if (err) + return err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now)) - return -EIO; return now; } static int ideapad_backlight_update_status(struct backlight_device *blightdev) { struct ideapad_private *priv = bl_get_data(blightdev); + int err; - if (!priv) - return -EINVAL; + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_BL, + blightdev->props.brightness); + if (err) + return err; - if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL, - blightdev->props.brightness)) - return -EIO; - if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER, - blightdev->props.power == FB_BLANK_POWERDOWN ? 0 : 1)) - return -EIO; + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER, + blightdev->props.power != FB_BLANK_POWERDOWN); + if (err) + return err; return 0; } @@ -1085,30 +1187,41 @@ static int ideapad_backlight_init(struct ideapad_private *priv) struct backlight_device *blightdev; struct backlight_properties props; unsigned long max, now, power; + int err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max)) - return -EIO; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now)) - return -EIO; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power)) - return -EIO; + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max); + if (err) + return err; + + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); + if (err) + return err; + + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power); + if (err) + return err; + + memset(&props, 0, sizeof(props)); - memset(&props, 0, sizeof(struct backlight_properties)); props.max_brightness = max; props.type = BACKLIGHT_PLATFORM; + blightdev = backlight_device_register("ideapad", &priv->platform_device->dev, priv, &ideapad_backlight_ops, &props); if (IS_ERR(blightdev)) { - pr_err("Could not register backlight device\n"); - return PTR_ERR(blightdev); + err = PTR_ERR(blightdev); + dev_err(&priv->platform_device->dev, + "Could not register backlight device: %d\n", err); + return err; } priv->blightdev = blightdev; blightdev->props.brightness = now; blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; + backlight_update_status(blightdev); return 0; @@ -1122,13 +1235,15 @@ static void ideapad_backlight_exit(struct ideapad_private *priv) static void ideapad_backlight_notify_power(struct ideapad_private *priv) { - unsigned long power; struct backlight_device *blightdev = priv->blightdev; + unsigned long power; if (!blightdev) return; + if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power)) return; + blightdev->props.power = power ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; } @@ -1137,12 +1252,112 @@ static void ideapad_backlight_notify_brightness(struct ideapad_private *priv) unsigned long now; /* if we control brightness via acpi video driver */ - if (priv->blightdev == NULL) { + if (!priv->blightdev) read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); + else + backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY); +} + +/* + * keyboard backlight + */ +static int ideapad_kbd_bl_brightness_get(struct ideapad_private *priv) +{ + unsigned long hals; + int err; + + err = eval_hals(priv->adev->handle, &hals); + if (err) + return err; + + return !!test_bit(HALS_KBD_BL_STATE_BIT, &hals); +} + +static enum led_brightness ideapad_kbd_bl_led_cdev_brightness_get(struct led_classdev *led_cdev) +{ + struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led); + + return ideapad_kbd_bl_brightness_get(priv); +} + +static int ideapad_kbd_bl_brightness_set(struct ideapad_private *priv, unsigned int brightness) +{ + int err = exec_sals(priv->adev->handle, brightness ? SALS_KBD_BL_ON : SALS_KBD_BL_OFF); + + if (err) + return err; + + priv->kbd_bl.last_brightness = brightness; + + return 0; +} + +static int ideapad_kbd_bl_led_cdev_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + struct ideapad_private *priv = container_of(led_cdev, struct ideapad_private, kbd_bl.led); + + return ideapad_kbd_bl_brightness_set(priv, brightness); +} + +static void ideapad_kbd_bl_notify(struct ideapad_private *priv) +{ + int brightness; + + if (!priv->kbd_bl.initialized) return; - } - backlight_force_update(priv->blightdev, BACKLIGHT_UPDATE_HOTKEY); + brightness = ideapad_kbd_bl_brightness_get(priv); + if (brightness < 0) + return; + + if (brightness == priv->kbd_bl.last_brightness) + return; + + priv->kbd_bl.last_brightness = brightness; + + led_classdev_notify_brightness_hw_changed(&priv->kbd_bl.led, brightness); +} + +static int ideapad_kbd_bl_init(struct ideapad_private *priv) +{ + int brightness, err; + + if (!priv->features.kbd_bl) + return -ENODEV; + + if (WARN_ON(priv->kbd_bl.initialized)) + return -EEXIST; + + brightness = ideapad_kbd_bl_brightness_get(priv); + if (brightness < 0) + return brightness; + + priv->kbd_bl.last_brightness = brightness; + + priv->kbd_bl.led.name = "platform::" LED_FUNCTION_KBD_BACKLIGHT; + priv->kbd_bl.led.max_brightness = 1; + priv->kbd_bl.led.brightness_get = ideapad_kbd_bl_led_cdev_brightness_get; + priv->kbd_bl.led.brightness_set_blocking = ideapad_kbd_bl_led_cdev_brightness_set; + priv->kbd_bl.led.flags = LED_BRIGHT_HW_CHANGED; + + err = led_classdev_register(&priv->platform_device->dev, &priv->kbd_bl.led); + if (err) + return err; + + priv->kbd_bl.initialized = true; + + return 0; +} + +static void ideapad_kbd_bl_exit(struct ideapad_private *priv) +{ + if (!priv->kbd_bl.initialized) + return; + + priv->kbd_bl.initialized = false; + + led_classdev_unregister(&priv->kbd_bl.led); } /* @@ -1152,71 +1367,77 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv) { unsigned long value; - if (!priv->has_touchpad_switch) + if (!priv->features.touchpad_ctrl_via_ec) return; /* Without reading from EC touchpad LED doesn't switch state */ if (!read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &value)) { - /* Some IdeaPads don't really turn off touchpad - they only + unsigned char param; + /* + * Some IdeaPads don't really turn off touchpad - they only * switch the LED state. We (de)activate KBC AUX port to turn * touchpad off and on. We send KEY_TOUCHPAD_OFF and - * KEY_TOUCHPAD_ON to not to get out of sync with LED */ - unsigned char param; - i8042_command(¶m, value ? I8042_CMD_AUX_ENABLE : - I8042_CMD_AUX_DISABLE); + * KEY_TOUCHPAD_ON to not to get out of sync with LED + */ + i8042_command(¶m, value ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE); ideapad_input_report(priv, value ? 67 : 66); + sysfs_notify(&priv->platform_device->dev.kobj, NULL, "touchpad"); } } static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) { struct ideapad_private *priv = data; - unsigned long vpc1, vpc2, vpc_bit; + unsigned long vpc1, vpc2, bit; if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1)) return; + if (read_ec_data(handle, VPCCMD_R_VPC2, &vpc2)) return; vpc1 = (vpc2 << 8) | vpc1; - for (vpc_bit = 0; vpc_bit < 16; vpc_bit++) { - if (test_bit(vpc_bit, &vpc1)) { - switch (vpc_bit) { - case 9: - ideapad_sync_rfk_state(priv); - break; - case 13: - case 11: - case 8: - case 7: - case 6: - ideapad_input_report(priv, vpc_bit); - break; - case 5: - ideapad_sync_touchpad_state(priv); - break; - case 4: - ideapad_backlight_notify_brightness(priv); - break; - case 3: - ideapad_input_novokey(priv); - break; - case 2: - ideapad_backlight_notify_power(priv); - break; - case 0: - ideapad_check_special_buttons(priv); - break; - case 1: - /* Some IdeaPads report event 1 every ~20 - * seconds while on battery power; some - * report this when changing to/from tablet - * mode. Squelch this event. - */ - break; - default: - pr_info("Unknown event: %lu\n", vpc_bit); - } + + for_each_set_bit (bit, &vpc1, 16) { + switch (bit) { + case 13: + case 11: + case 8: + case 7: + case 6: + ideapad_input_report(priv, bit); + break; + case 9: + ideapad_sync_rfk_state(priv); + break; + case 5: + ideapad_sync_touchpad_state(priv); + break; + case 4: + ideapad_backlight_notify_brightness(priv); + break; + case 3: + ideapad_input_novokey(priv); + break; + case 2: + ideapad_backlight_notify_power(priv); + break; + case 1: + /* + * Some IdeaPads report event 1 every ~20 + * seconds while on battery power; some + * report this when changing to/from tablet + * mode; some report this when the keyboard + * backlight has changed. + */ + ideapad_kbd_bl_notify(priv); + break; + case 0: + ideapad_check_special_buttons(priv); + break; + default: + dev_info(&priv->platform_device->dev, + "Unknown event: %lu\n", bit); } } } @@ -1224,12 +1445,15 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data) #if IS_ENABLED(CONFIG_ACPI_WMI) static void ideapad_wmi_notify(u32 value, void *context) { + struct ideapad_private *priv = context; + switch (value) { case 128: - ideapad_input_report(context, value); + ideapad_input_report(priv, value); break; default: - pr_info("Unknown WMI event %u\n", value); + dev_info(&priv->platform_device->dev, + "Unknown WMI event: %u\n", value); } } #endif @@ -1253,18 +1477,52 @@ static const struct dmi_system_id hw_rfkill_list[] = { {} }; +static void ideapad_check_features(struct ideapad_private *priv) +{ + acpi_handle handle = priv->adev->handle; + unsigned long val; + + priv->features.hw_rfkill_switch = dmi_check_system(hw_rfkill_list); + + /* Most ideapads with ELAN0634 touchpad don't use EC touchpad switch */ + priv->features.touchpad_ctrl_via_ec = !acpi_dev_present("ELAN0634", NULL, -1); + + if (!read_ec_data(handle, VPCCMD_R_FAN, &val)) + priv->features.fan_mode = true; + + if (acpi_has_method(handle, "GBMD") && acpi_has_method(handle, "SBMC")) + priv->features.conservation_mode = true; + + if (acpi_has_method(handle, "DYTC")) + priv->features.dytc = true; + + if (acpi_has_method(handle, "HALS") && acpi_has_method(handle, "SALS")) { + if (!eval_hals(handle, &val)) { + if (test_bit(HALS_FNLOCK_SUPPORT_BIT, &val)) + priv->features.fn_lock = true; + + if (test_bit(HALS_KBD_BL_SUPPORT_BIT, &val)) + priv->features.kbd_bl = true; + + if (test_bit(HALS_USB_CHARGING_SUPPORT_BIT, &val)) + priv->features.usb_charging = true; + } + } +} + static int ideapad_acpi_add(struct platform_device *pdev) { - int ret, i; - int cfg; struct ideapad_private *priv; struct acpi_device *adev; + acpi_status status; + unsigned long cfg; + int err, i; - ret = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev); - if (ret) + err = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev); + if (err) return -ENODEV; - if (read_method_int(adev->handle, "_CFG", &cfg)) + if (eval_int(adev->handle, "_CFG", &cfg)) return -ENODEV; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); @@ -1272,33 +1530,40 @@ static int ideapad_acpi_add(struct platform_device *pdev) return -ENOMEM; dev_set_drvdata(&pdev->dev, priv); + priv->cfg = cfg; priv->adev = adev; priv->platform_device = pdev; - priv->has_hw_rfkill_switch = dmi_check_system(hw_rfkill_list); - /* Most ideapads with ELAN0634 touchpad don't use EC touchpad switch */ - priv->has_touchpad_switch = !acpi_dev_present("ELAN0634", NULL, -1); + ideapad_check_features(priv); - ret = ideapad_sysfs_init(priv); - if (ret) - return ret; + err = ideapad_sysfs_init(priv); + if (err) + return err; ideapad_debugfs_init(priv); - ret = ideapad_input_init(priv); - if (ret) + err = ideapad_input_init(priv); + if (err) goto input_failed; + err = ideapad_kbd_bl_init(priv); + if (err) { + if (err != -ENODEV) + dev_warn(&pdev->dev, "Could not set up keyboard backlight LED: %d\n", err); + else + dev_info(&pdev->dev, "Keyboard backlight control not available\n"); + } + /* * On some models without a hw-switch (the yoga 2 13 at least) * VPCCMD_W_RF must be explicitly set to 1 for the wifi to work. */ - if (!priv->has_hw_rfkill_switch) + if (!priv->features.hw_rfkill_switch) write_ec_cmd(priv->adev->handle, VPCCMD_W_RF, 1); /* The same for Touchpad */ - if (!priv->has_touchpad_switch) + if (!priv->features.touchpad_ctrl_via_ec) write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, 1); for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) @@ -1308,47 +1573,70 @@ static int ideapad_acpi_add(struct platform_device *pdev) ideapad_sync_rfk_state(priv); ideapad_sync_touchpad_state(priv); - ideapad_dytc_profile_init(priv); + err = ideapad_dytc_profile_init(priv); + if (err) { + if (err != -ENODEV) + dev_warn(&pdev->dev, "Could not set up DYTC interface: %d\n", err); + else + dev_info(&pdev->dev, "DYTC interface is not available\n"); + } if (acpi_video_get_backlight_type() == acpi_backlight_vendor) { - ret = ideapad_backlight_init(priv); - if (ret && ret != -ENODEV) + err = ideapad_backlight_init(priv); + if (err && err != -ENODEV) goto backlight_failed; } - ret = acpi_install_notify_handler(adev->handle, - ACPI_DEVICE_NOTIFY, ideapad_acpi_notify, priv); - if (ret) + + status = acpi_install_notify_handler(adev->handle, + ACPI_DEVICE_NOTIFY, + ideapad_acpi_notify, priv); + if (ACPI_FAILURE(status)) { + err = -EIO; goto notification_failed; + } #if IS_ENABLED(CONFIG_ACPI_WMI) for (i = 0; i < ARRAY_SIZE(ideapad_wmi_fnesc_events); i++) { - ret = wmi_install_notify_handler(ideapad_wmi_fnesc_events[i], - ideapad_wmi_notify, priv); - if (ret == AE_OK) { + status = wmi_install_notify_handler(ideapad_wmi_fnesc_events[i], + ideapad_wmi_notify, priv); + if (ACPI_SUCCESS(status)) { priv->fnesc_guid = ideapad_wmi_fnesc_events[i]; break; } } - if (ret != AE_OK && ret != AE_NOT_EXIST) + + if (ACPI_FAILURE(status) && status != AE_NOT_EXIST) { + err = -EIO; goto notification_failed_wmi; + } #endif return 0; + #if IS_ENABLED(CONFIG_ACPI_WMI) notification_failed_wmi: acpi_remove_notify_handler(priv->adev->handle, - ACPI_DEVICE_NOTIFY, ideapad_acpi_notify); + ACPI_DEVICE_NOTIFY, + ideapad_acpi_notify); #endif + notification_failed: ideapad_backlight_exit(priv); + backlight_failed: + ideapad_dytc_profile_exit(priv); + for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) ideapad_unregister_rfkill(priv, i); + + ideapad_kbd_bl_exit(priv); ideapad_input_exit(priv); + input_failed: ideapad_debugfs_exit(priv); ideapad_sysfs_exit(priv); - return ret; + + return err; } static int ideapad_acpi_remove(struct platform_device *pdev) @@ -1360,28 +1648,29 @@ static int ideapad_acpi_remove(struct platform_device *pdev) if (priv->fnesc_guid) wmi_remove_notify_handler(priv->fnesc_guid); #endif + acpi_remove_notify_handler(priv->adev->handle, - ACPI_DEVICE_NOTIFY, ideapad_acpi_notify); + ACPI_DEVICE_NOTIFY, + ideapad_acpi_notify); + ideapad_backlight_exit(priv); ideapad_dytc_profile_exit(priv); + for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++) ideapad_unregister_rfkill(priv, i); + + ideapad_kbd_bl_exit(priv); ideapad_input_exit(priv); ideapad_debugfs_exit(priv); ideapad_sysfs_exit(priv); - dev_set_drvdata(&pdev->dev, NULL); return 0; } #ifdef CONFIG_PM_SLEEP -static int ideapad_acpi_resume(struct device *device) +static int ideapad_acpi_resume(struct device *dev) { - struct ideapad_private *priv; - - if (!device) - return -EINVAL; - priv = dev_get_drvdata(device); + struct ideapad_private *priv = dev_get_drvdata(dev); ideapad_sync_rfk_state(priv); ideapad_sync_touchpad_state(priv); @@ -1395,8 +1684,8 @@ static int ideapad_acpi_resume(struct device *device) static SIMPLE_DEV_PM_OPS(ideapad_pm, NULL, ideapad_acpi_resume); static const struct acpi_device_id ideapad_device_ids[] = { - { "VPC2004", 0}, - { "", 0}, + {"VPC2004", 0}, + {"", 0}, }; MODULE_DEVICE_TABLE(acpi, ideapad_device_ids); diff --git a/drivers/platform/x86/intel_scu_wdt.c b/drivers/platform/x86/intel_scu_wdt.c index 85ee85ca2215..c2479777a1d6 100644 --- a/drivers/platform/x86/intel_scu_wdt.c +++ b/drivers/platform/x86/intel_scu_wdt.c @@ -63,7 +63,7 @@ static int __init register_mid_wdt(void) if (!id) return -ENODEV; - wdt_dev.dev.platform_data = (const struct intel_mid_wdt_pdata *)id->driver_data; + wdt_dev.dev.platform_data = (struct intel_mid_wdt_pdata *)id->driver_data; return platform_device_register(&wdt_dev); } arch_initcall(register_mid_wdt); diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c index 64ee7819c9d3..fd318cdfe313 100644 --- a/drivers/platform/x86/msi-wmi.c +++ b/drivers/platform/x86/msi-wmi.c @@ -96,6 +96,8 @@ static int msi_wmi_query_block(int instance, int *ret) struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; status = wmi_query_block(MSIWMI_BIOS_GUID, instance, &output); + if (ACPI_FAILURE(status)) + return -EIO; obj = output.pointer; diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 18b390153e7f..b881044b31b0 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -9995,8 +9995,6 @@ static struct ibm_struct proxsensor_driver_data = { .exit = proxsensor_exit, }; -#if IS_ENABLED(CONFIG_ACPI_PLATFORM_PROFILE) - /************************************************************************* * DYTC Platform Profile interface */ @@ -10078,8 +10076,8 @@ static int convert_profile_to_dytc(enum platform_profile_option profile, int *pe * dytc_profile_get: Function to register with platform_profile * handler. Returns current platform profile. */ -int dytc_profile_get(struct platform_profile_handler *pprof, - enum platform_profile_option *profile) +static int dytc_profile_get(struct platform_profile_handler *pprof, + enum platform_profile_option *profile) { *profile = dytc_current_profile; return 0; @@ -10092,7 +10090,7 @@ int dytc_profile_get(struct platform_profile_handler *pprof, * - enable CQL * If not in CQL mode, just run the command */ -int dytc_cql_command(int command, int *output) +static int dytc_cql_command(int command, int *output) { int err, cmd_err, dummy; int cur_funcmode; @@ -10130,8 +10128,8 @@ int dytc_cql_command(int command, int *output) * dytc_profile_set: Function to register with platform_profile * handler. Sets current platform profile. */ -int dytc_profile_set(struct platform_profile_handler *pprof, - enum platform_profile_option profile) +static int dytc_profile_set(struct platform_profile_handler *pprof, + enum platform_profile_option profile) { int output; int err; @@ -10251,7 +10249,6 @@ static struct ibm_struct dytc_profile_driver_data = { .name = "dytc-profile", .exit = dytc_profile_exit, }; -#endif /* CONFIG_ACPI_PLATFORM_PROFILE */ /************************************************************************* * Keyboard language interface @@ -10476,11 +10473,9 @@ static void tpacpi_driver_event(const unsigned int hkey_event) if (hkey_event == TP_HKEY_EV_THM_CSM_COMPLETED) { lapsensor_refresh(); -#if IS_ENABLED(CONFIG_ACPI_PLATFORM_PROFILE) /* If we are already accessing DYTC then skip dytc update */ if (!atomic_add_unless(&dytc_ignore_event, -1, 0)) dytc_profile_refresh(); -#endif } } @@ -10924,12 +10919,10 @@ static struct ibm_init_struct ibms_init[] __initdata = { .init = tpacpi_proxsensor_init, .data = &proxsensor_driver_data, }, -#if IS_ENABLED(CONFIG_ACPI_PLATFORM_PROFILE) { .init = tpacpi_dytc_profile_init, .data = &dytc_profile_driver_data, }, -#endif { .init = tpacpi_kbdlang_init, .data = &kbdlang_driver_data, |