]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
platform/x86: Add new intel_atomisp2_led driver
authorHans de Goede <hdegoede@redhat.com>
Sat, 20 Jun 2020 12:37:05 +0000 (14:37 +0200)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 9 Jul 2020 19:47:27 +0000 (22:47 +0300)
Many Bay Trail and Cherry Trail devices come with a camera attached to
Intel's Image Signal Processor. Linux currently does not have a driver for
these, so they do not work as a camera.

Some of these camera's have a status LED which is controlled through a GPIO
in some cases, e.g. on the Asus T100TA and Asus T200TA, there is a firmware
issue where the LED gets turned on at boot.

This commit adds a Linux LED driver for the camera LED on these devices.
This driver will turn the LED off at boot and also allows controlling the
LED (so the user can repurpose it) through the sysfs LED interface.

Which GPIO is attached to the LED is usually not described in the ACPI
tables, so this driver contains per-system info about the GPIO inside the
driver. This means that this driver only works on systems the driver knows
about.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
MAINTAINERS
drivers/platform/x86/Kconfig
drivers/platform/x86/Makefile
drivers/platform/x86/intel_atomisp2_led.c [new file with mode: 0644]

index 68f21d46614c46ce8e21ea80507610eb47a9ff30..8fd6d637f1c29345f0666a8a0a3617c70f0ead8c 100644 (file)
@@ -8600,6 +8600,12 @@ L:       platform-driver-x86@vger.kernel.org
 S:     Maintained
 F:     drivers/platform/x86/intel_atomisp2_pm.c
 
+INTEL ATOMISP2 LED DRIVER
+M:     Hans de Goede <hdegoede@redhat.com>
+L:     platform-driver-x86@vger.kernel.org
+S:     Maintained
+F:     drivers/platform/x86/intel_atomisp2_led.c
+
 INTEL BROXTON PMC DRIVER
 M:     Mika Westerberg <mika.westerberg@linux.intel.com>
 M:     Zha Qipeng <qipeng.zha@intel.com>
index 0581a54cf562f6989c58996a01e6d7b9ef976f7a..9fdeb3224dd0b03e7cb9a040a439358883c939b1 100644 (file)
@@ -748,6 +748,27 @@ config THINKPAD_ACPI_HOTKEY_POLL
          If you are not sure, say Y here.  The driver enables polling only if
          it is strictly necessary to do so.
 
+config INTEL_ATOMISP2_LED
+       tristate "Intel AtomISP2 camera LED driver"
+       depends on GPIOLIB && LEDS_GPIO
+       help
+         Many Bay Trail and Cherry Trail devices come with a camera attached
+         to Intel's Image Signal Processor. Linux currently does not have a
+         driver for these, so they do not work as a camera. Some of these
+         camera's have a LED which is controlled through a GPIO.
+
+         Some of these devices have a firmware issue where the LED gets turned
+         on at boot. This driver will turn the LED off at boot and also allows
+         controlling the LED (repurposing it) through the sysfs LED interface.
+
+         Which GPIO is attached to the LED is usually not described in the
+         ACPI tables, so this driver contains per-system info about the GPIO
+         inside the driver, this means that this driver only works on systems
+         the driver knows about.
+
+         To compile this driver as a module, choose M here: the module
+         will be called intel_atomisp2_led.
+
 config INTEL_ATOMISP2_PM
        tristate "Intel AtomISP2 dummy / power-management driver"
        depends on PCI && IOSF_MBI && PM
index 2b85852a1a87200f187b135234980ce5fa77fe17..5f823f7eff45280248f01197cd086fc81d3de66b 100644 (file)
@@ -69,6 +69,7 @@ obj-$(CONFIG_SENSORS_HDAPS)   += hdaps.o
 obj-$(CONFIG_THINKPAD_ACPI)    += thinkpad_acpi.o
 
 # Intel
+obj-$(CONFIG_INTEL_ATOMISP2_LED)       += intel_atomisp2_led.o
 obj-$(CONFIG_INTEL_ATOMISP2_PM)                += intel_atomisp2_pm.o
 obj-$(CONFIG_INTEL_CHT_INT33FE)                += intel_cht_int33fe.o
 intel_cht_int33fe-objs                 := intel_cht_int33fe_common.o \
diff --git a/drivers/platform/x86/intel_atomisp2_led.c b/drivers/platform/x86/intel_atomisp2_led.c
new file mode 100644 (file)
index 0000000..5935dfc
--- /dev/null
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Driver for controlling LEDs for cameras connected to the Intel atomisp2
+ * The main purpose of this driver is to turn off LEDs which are on at boot.
+ *
+ * Copyright (C) 2020 Hans de Goede <hdegoede@redhat.com>
+ */
+
+#include <linux/dmi.h>
+#include <linux/gpio/consumer.h>
+#include <linux/gpio/machine.h>
+#include <linux/leds.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+#include <linux/workqueue.h>
+
+/* This must be leds-gpio as the leds-gpio driver binds to the name */
+#define DEV_NAME               "leds-gpio"
+
+static const struct gpio_led atomisp2_leds[] = {
+       {
+               .name = "atomisp2::camera",
+               .default_state  = LEDS_GPIO_DEFSTATE_OFF,
+       },
+};
+
+static const struct gpio_led_platform_data atomisp2_leds_pdata = {
+       .num_leds       = ARRAY_SIZE(atomisp2_leds),
+       .leds           = atomisp2_leds,
+};
+
+static struct gpiod_lookup_table asus_t100ta_lookup = {
+       .dev_id = DEV_NAME,
+       .table = {
+               GPIO_LOOKUP_IDX("INT33FC:02", 8, NULL, 0, GPIO_ACTIVE_HIGH),
+               { }
+       }
+};
+
+static struct gpiod_lookup_table asus_t100chi_lookup = {
+       .dev_id = DEV_NAME,
+       .table = {
+               GPIO_LOOKUP_IDX("INT33FC:01", 24, NULL, 0, GPIO_ACTIVE_HIGH),
+               { }
+       }
+};
+
+static const struct dmi_system_id atomisp2_led_systems[] __initconst = {
+       {
+               .matches = {
+                       DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+                       DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
+               },
+               .driver_data = &asus_t100ta_lookup,
+       },
+       {
+               .matches = {
+                       DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+                       DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T200TA"),
+               },
+               .driver_data = &asus_t100ta_lookup,
+       },
+       {
+               .matches = {
+                       DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+                       DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100CHI"),
+               },
+               .driver_data = &asus_t100chi_lookup,
+       },
+       {} /* Terminating entry */
+};
+MODULE_DEVICE_TABLE(dmi, atomisp2_led_systems);
+
+static struct gpiod_lookup_table *gpio_lookup;
+static struct platform_device *pdev;
+
+static int __init atomisp2_led_init(void)
+{
+       const struct dmi_system_id *system;
+
+       system = dmi_first_match(atomisp2_led_systems);
+       if (!system)
+               return -ENODEV;
+
+       gpio_lookup = system->driver_data;
+       gpiod_add_lookup_table(gpio_lookup);
+
+       pdev = platform_device_register_resndata(NULL,
+                                                DEV_NAME, PLATFORM_DEVID_NONE,
+                                                NULL, 0, &atomisp2_leds_pdata,
+                                                sizeof(atomisp2_leds_pdata));
+       if (IS_ERR(pdev))
+               gpiod_remove_lookup_table(gpio_lookup);
+
+       return PTR_ERR_OR_ZERO(pdev);
+}
+
+static void __exit atomisp2_led_cleanup(void)
+{
+       platform_device_unregister(pdev);
+       gpiod_remove_lookup_table(gpio_lookup);
+}
+
+module_init(atomisp2_led_init);
+module_exit(atomisp2_led_cleanup);
+
+/*
+ * The ACPI INIT method from Asus WMI's code on the T100TA and T200TA turns the
+ * LED on (without the WMI interface allowing further control over the LED).
+ * Ensure we are loaded after asus-nb-wmi so that we turn the LED off again.
+ */
+MODULE_SOFTDEP("pre: asus_nb_wmi");
+MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com");
+MODULE_DESCRIPTION("Intel atomisp2 camera LED driver");
+MODULE_LICENSE("GPL");