Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Driver for controlling LEDs for cameras connected to the Intel atomisp2
0004  * The main purpose of this driver is to turn off LEDs which are on at boot.
0005  *
0006  * Copyright (C) 2020 Hans de Goede <hdegoede@redhat.com>
0007  */
0008 
0009 #include <linux/dmi.h>
0010 #include <linux/gpio/consumer.h>
0011 #include <linux/gpio/machine.h>
0012 #include <linux/leds.h>
0013 #include <linux/module.h>
0014 #include <linux/mod_devicetable.h>
0015 #include <linux/platform_device.h>
0016 #include <linux/workqueue.h>
0017 
0018 /* This must be leds-gpio as the leds-gpio driver binds to the name */
0019 #define DEV_NAME        "leds-gpio"
0020 
0021 static const struct gpio_led atomisp2_leds[] = {
0022     {
0023         .name = "atomisp2::camera",
0024         .default_state  = LEDS_GPIO_DEFSTATE_OFF,
0025     },
0026 };
0027 
0028 static const struct gpio_led_platform_data atomisp2_leds_pdata = {
0029     .num_leds   = ARRAY_SIZE(atomisp2_leds),
0030     .leds       = atomisp2_leds,
0031 };
0032 
0033 static struct gpiod_lookup_table asus_t100ta_lookup = {
0034     .dev_id = DEV_NAME,
0035     .table = {
0036         GPIO_LOOKUP_IDX("INT33FC:02", 8, NULL, 0, GPIO_ACTIVE_HIGH),
0037         { }
0038     }
0039 };
0040 
0041 static struct gpiod_lookup_table asus_t100chi_lookup = {
0042     .dev_id = DEV_NAME,
0043     .table = {
0044         GPIO_LOOKUP_IDX("INT33FC:01", 24, NULL, 0, GPIO_ACTIVE_HIGH),
0045         { }
0046     }
0047 };
0048 
0049 static const struct dmi_system_id atomisp2_led_systems[] __initconst = {
0050     {
0051         .matches = {
0052             DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
0053             /* Non exact match to also match T100TAF */
0054             DMI_MATCH(DMI_PRODUCT_NAME, "T100TA"),
0055         },
0056         .driver_data = &asus_t100ta_lookup,
0057     },
0058     {
0059         .matches = {
0060             DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
0061             DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T200TA"),
0062         },
0063         .driver_data = &asus_t100ta_lookup,
0064     },
0065     {
0066         .matches = {
0067             DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
0068             DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100CHI"),
0069         },
0070         .driver_data = &asus_t100chi_lookup,
0071     },
0072     {} /* Terminating entry */
0073 };
0074 MODULE_DEVICE_TABLE(dmi, atomisp2_led_systems);
0075 
0076 static struct gpiod_lookup_table *gpio_lookup;
0077 static struct platform_device *pdev;
0078 
0079 static int __init atomisp2_led_init(void)
0080 {
0081     const struct dmi_system_id *system;
0082 
0083     system = dmi_first_match(atomisp2_led_systems);
0084     if (!system)
0085         return -ENODEV;
0086 
0087     gpio_lookup = system->driver_data;
0088     gpiod_add_lookup_table(gpio_lookup);
0089 
0090     pdev = platform_device_register_resndata(NULL,
0091                          DEV_NAME, PLATFORM_DEVID_NONE,
0092                          NULL, 0, &atomisp2_leds_pdata,
0093                          sizeof(atomisp2_leds_pdata));
0094     if (IS_ERR(pdev))
0095         gpiod_remove_lookup_table(gpio_lookup);
0096 
0097     return PTR_ERR_OR_ZERO(pdev);
0098 }
0099 
0100 static void __exit atomisp2_led_cleanup(void)
0101 {
0102     platform_device_unregister(pdev);
0103     gpiod_remove_lookup_table(gpio_lookup);
0104 }
0105 
0106 module_init(atomisp2_led_init);
0107 module_exit(atomisp2_led_cleanup);
0108 
0109 /*
0110  * The ACPI INIT method from Asus WMI's code on the T100TA and T200TA turns the
0111  * LED on (without the WMI interface allowing further control over the LED).
0112  * Ensure we are loaded after asus-nb-wmi so that we turn the LED off again.
0113  */
0114 MODULE_SOFTDEP("pre: asus_nb_wmi");
0115 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com");
0116 MODULE_DESCRIPTION("Intel atomisp2 camera LED driver");
0117 MODULE_LICENSE("GPL");