Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/x86: Add new intel_atomisp2_led driver

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>

authored by

Hans de Goede and committed by
Andy Shevchenko
4b2d688f ddc605f9

+144
+6
MAINTAINERS
··· 8600 8600 S: Maintained 8601 8601 F: drivers/platform/x86/intel_atomisp2_pm.c 8602 8602 8603 + INTEL ATOMISP2 LED DRIVER 8604 + M: Hans de Goede <hdegoede@redhat.com> 8605 + L: platform-driver-x86@vger.kernel.org 8606 + S: Maintained 8607 + F: drivers/platform/x86/intel_atomisp2_led.c 8608 + 8603 8609 INTEL BROXTON PMC DRIVER 8604 8610 M: Mika Westerberg <mika.westerberg@linux.intel.com> 8605 8611 M: Zha Qipeng <qipeng.zha@intel.com>
+21
drivers/platform/x86/Kconfig
··· 748 748 If you are not sure, say Y here. The driver enables polling only if 749 749 it is strictly necessary to do so. 750 750 751 + config INTEL_ATOMISP2_LED 752 + tristate "Intel AtomISP2 camera LED driver" 753 + depends on GPIOLIB && LEDS_GPIO 754 + help 755 + Many Bay Trail and Cherry Trail devices come with a camera attached 756 + to Intel's Image Signal Processor. Linux currently does not have a 757 + driver for these, so they do not work as a camera. Some of these 758 + camera's have a LED which is controlled through a GPIO. 759 + 760 + Some of these devices have a firmware issue where the LED gets turned 761 + on at boot. This driver will turn the LED off at boot and also allows 762 + controlling the LED (repurposing it) through the sysfs LED interface. 763 + 764 + Which GPIO is attached to the LED is usually not described in the 765 + ACPI tables, so this driver contains per-system info about the GPIO 766 + inside the driver, this means that this driver only works on systems 767 + the driver knows about. 768 + 769 + To compile this driver as a module, choose M here: the module 770 + will be called intel_atomisp2_led. 771 + 751 772 config INTEL_ATOMISP2_PM 752 773 tristate "Intel AtomISP2 dummy / power-management driver" 753 774 depends on PCI && IOSF_MBI && PM
+1
drivers/platform/x86/Makefile
··· 69 69 obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o 70 70 71 71 # Intel 72 + obj-$(CONFIG_INTEL_ATOMISP2_LED) += intel_atomisp2_led.o 72 73 obj-$(CONFIG_INTEL_ATOMISP2_PM) += intel_atomisp2_pm.o 73 74 obj-$(CONFIG_INTEL_CHT_INT33FE) += intel_cht_int33fe.o 74 75 intel_cht_int33fe-objs := intel_cht_int33fe_common.o \
+116
drivers/platform/x86/intel_atomisp2_led.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Driver for controlling LEDs for cameras connected to the Intel atomisp2 4 + * The main purpose of this driver is to turn off LEDs which are on at boot. 5 + * 6 + * Copyright (C) 2020 Hans de Goede <hdegoede@redhat.com> 7 + */ 8 + 9 + #include <linux/dmi.h> 10 + #include <linux/gpio/consumer.h> 11 + #include <linux/gpio/machine.h> 12 + #include <linux/leds.h> 13 + #include <linux/module.h> 14 + #include <linux/mod_devicetable.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/workqueue.h> 17 + 18 + /* This must be leds-gpio as the leds-gpio driver binds to the name */ 19 + #define DEV_NAME "leds-gpio" 20 + 21 + static const struct gpio_led atomisp2_leds[] = { 22 + { 23 + .name = "atomisp2::camera", 24 + .default_state = LEDS_GPIO_DEFSTATE_OFF, 25 + }, 26 + }; 27 + 28 + static const struct gpio_led_platform_data atomisp2_leds_pdata = { 29 + .num_leds = ARRAY_SIZE(atomisp2_leds), 30 + .leds = atomisp2_leds, 31 + }; 32 + 33 + static struct gpiod_lookup_table asus_t100ta_lookup = { 34 + .dev_id = DEV_NAME, 35 + .table = { 36 + GPIO_LOOKUP_IDX("INT33FC:02", 8, NULL, 0, GPIO_ACTIVE_HIGH), 37 + { } 38 + } 39 + }; 40 + 41 + static struct gpiod_lookup_table asus_t100chi_lookup = { 42 + .dev_id = DEV_NAME, 43 + .table = { 44 + GPIO_LOOKUP_IDX("INT33FC:01", 24, NULL, 0, GPIO_ACTIVE_HIGH), 45 + { } 46 + } 47 + }; 48 + 49 + static const struct dmi_system_id atomisp2_led_systems[] __initconst = { 50 + { 51 + .matches = { 52 + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), 53 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"), 54 + }, 55 + .driver_data = &asus_t100ta_lookup, 56 + }, 57 + { 58 + .matches = { 59 + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), 60 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T200TA"), 61 + }, 62 + .driver_data = &asus_t100ta_lookup, 63 + }, 64 + { 65 + .matches = { 66 + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), 67 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100CHI"), 68 + }, 69 + .driver_data = &asus_t100chi_lookup, 70 + }, 71 + {} /* Terminating entry */ 72 + }; 73 + MODULE_DEVICE_TABLE(dmi, atomisp2_led_systems); 74 + 75 + static struct gpiod_lookup_table *gpio_lookup; 76 + static struct platform_device *pdev; 77 + 78 + static int __init atomisp2_led_init(void) 79 + { 80 + const struct dmi_system_id *system; 81 + 82 + system = dmi_first_match(atomisp2_led_systems); 83 + if (!system) 84 + return -ENODEV; 85 + 86 + gpio_lookup = system->driver_data; 87 + gpiod_add_lookup_table(gpio_lookup); 88 + 89 + pdev = platform_device_register_resndata(NULL, 90 + DEV_NAME, PLATFORM_DEVID_NONE, 91 + NULL, 0, &atomisp2_leds_pdata, 92 + sizeof(atomisp2_leds_pdata)); 93 + if (IS_ERR(pdev)) 94 + gpiod_remove_lookup_table(gpio_lookup); 95 + 96 + return PTR_ERR_OR_ZERO(pdev); 97 + } 98 + 99 + static void __exit atomisp2_led_cleanup(void) 100 + { 101 + platform_device_unregister(pdev); 102 + gpiod_remove_lookup_table(gpio_lookup); 103 + } 104 + 105 + module_init(atomisp2_led_init); 106 + module_exit(atomisp2_led_cleanup); 107 + 108 + /* 109 + * The ACPI INIT method from Asus WMI's code on the T100TA and T200TA turns the 110 + * LED on (without the WMI interface allowing further control over the LED). 111 + * Ensure we are loaded after asus-nb-wmi so that we turn the LED off again. 112 + */ 113 + MODULE_SOFTDEP("pre: asus_nb_wmi"); 114 + MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com"); 115 + MODULE_DESCRIPTION("Intel atomisp2 camera LED driver"); 116 + MODULE_LICENSE("GPL");