led.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include <linux/dmi.h>
  9. #include <linux/gpio/consumer.h>
  10. #include <linux/gpio/machine.h>
  11. #include <linux/leds.h>
  12. #include <linux/module.h>
  13. #include <linux/mod_devicetable.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/workqueue.h>
  16. /* This must be leds-gpio as the leds-gpio driver binds to the name */
  17. #define DEV_NAME "leds-gpio"
  18. static const struct gpio_led atomisp2_leds[] = {
  19. {
  20. .name = "atomisp2::camera",
  21. .default_state = LEDS_GPIO_DEFSTATE_OFF,
  22. },
  23. };
  24. static const struct gpio_led_platform_data atomisp2_leds_pdata = {
  25. .num_leds = ARRAY_SIZE(atomisp2_leds),
  26. .leds = atomisp2_leds,
  27. };
  28. static struct gpiod_lookup_table asus_t100ta_lookup = {
  29. .dev_id = DEV_NAME,
  30. .table = {
  31. GPIO_LOOKUP_IDX("INT33FC:02", 8, NULL, 0, GPIO_ACTIVE_HIGH),
  32. { }
  33. }
  34. };
  35. static struct gpiod_lookup_table asus_t100chi_lookup = {
  36. .dev_id = DEV_NAME,
  37. .table = {
  38. GPIO_LOOKUP_IDX("INT33FC:01", 24, NULL, 0, GPIO_ACTIVE_HIGH),
  39. { }
  40. }
  41. };
  42. static const struct dmi_system_id atomisp2_led_systems[] __initconst = {
  43. {
  44. .matches = {
  45. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  46. /* Non exact match to also match T100TAF */
  47. DMI_MATCH(DMI_PRODUCT_NAME, "T100TA"),
  48. },
  49. .driver_data = &asus_t100ta_lookup,
  50. },
  51. {
  52. .matches = {
  53. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  54. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T200TA"),
  55. },
  56. .driver_data = &asus_t100ta_lookup,
  57. },
  58. {
  59. .matches = {
  60. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  61. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100CHI"),
  62. },
  63. .driver_data = &asus_t100chi_lookup,
  64. },
  65. {} /* Terminating entry */
  66. };
  67. MODULE_DEVICE_TABLE(dmi, atomisp2_led_systems);
  68. static struct gpiod_lookup_table *gpio_lookup;
  69. static struct platform_device *pdev;
  70. static int __init atomisp2_led_init(void)
  71. {
  72. const struct dmi_system_id *system;
  73. system = dmi_first_match(atomisp2_led_systems);
  74. if (!system)
  75. return -ENODEV;
  76. gpio_lookup = system->driver_data;
  77. gpiod_add_lookup_table(gpio_lookup);
  78. pdev = platform_device_register_resndata(NULL,
  79. DEV_NAME, PLATFORM_DEVID_NONE,
  80. NULL, 0, &atomisp2_leds_pdata,
  81. sizeof(atomisp2_leds_pdata));
  82. if (IS_ERR(pdev))
  83. gpiod_remove_lookup_table(gpio_lookup);
  84. return PTR_ERR_OR_ZERO(pdev);
  85. }
  86. static void __exit atomisp2_led_cleanup(void)
  87. {
  88. platform_device_unregister(pdev);
  89. gpiod_remove_lookup_table(gpio_lookup);
  90. }
  91. module_init(atomisp2_led_init);
  92. module_exit(atomisp2_led_cleanup);
  93. /*
  94. * The ACPI INIT method from Asus WMI's code on the T100TA and T200TA turns the
  95. * LED on (without the WMI interface allowing further control over the LED).
  96. * Ensure we are loaded after asus-nb-wmi so that we turn the LED off again.
  97. */
  98. MODULE_SOFTDEP("pre: asus_nb_wmi");
  99. MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com");
  100. MODULE_DESCRIPTION("Intel atomisp2 camera LED driver");
  101. MODULE_LICENSE("GPL");