intel_atomisp2_led.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
  47. },
  48. .driver_data = &asus_t100ta_lookup,
  49. },
  50. {
  51. .matches = {
  52. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  53. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T200TA"),
  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, "T100CHI"),
  61. },
  62. .driver_data = &asus_t100chi_lookup,
  63. },
  64. {} /* Terminating entry */
  65. };
  66. MODULE_DEVICE_TABLE(dmi, atomisp2_led_systems);
  67. static struct gpiod_lookup_table *gpio_lookup;
  68. static struct platform_device *pdev;
  69. static int __init atomisp2_led_init(void)
  70. {
  71. const struct dmi_system_id *system;
  72. system = dmi_first_match(atomisp2_led_systems);
  73. if (!system)
  74. return -ENODEV;
  75. gpio_lookup = system->driver_data;
  76. gpiod_add_lookup_table(gpio_lookup);
  77. pdev = platform_device_register_resndata(NULL,
  78. DEV_NAME, PLATFORM_DEVID_NONE,
  79. NULL, 0, &atomisp2_leds_pdata,
  80. sizeof(atomisp2_leds_pdata));
  81. if (IS_ERR(pdev))
  82. gpiod_remove_lookup_table(gpio_lookup);
  83. return PTR_ERR_OR_ZERO(pdev);
  84. }
  85. static void __exit atomisp2_led_cleanup(void)
  86. {
  87. platform_device_unregister(pdev);
  88. gpiod_remove_lookup_table(gpio_lookup);
  89. }
  90. module_init(atomisp2_led_init);
  91. module_exit(atomisp2_led_cleanup);
  92. /*
  93. * The ACPI INIT method from Asus WMI's code on the T100TA and T200TA turns the
  94. * LED on (without the WMI interface allowing further control over the LED).
  95. * Ensure we are loaded after asus-nb-wmi so that we turn the LED off again.
  96. */
  97. MODULE_SOFTDEP("pre: asus_nb_wmi");
  98. MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com");
  99. MODULE_DESCRIPTION("Intel atomisp2 camera LED driver");
  100. MODULE_LICENSE("GPL");