simatic-ipc-leds-gpio-f7188x.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Siemens SIMATIC IPC driver for GPIO based LEDs
  4. *
  5. * Copyright (c) Siemens AG, 2023
  6. *
  7. * Author:
  8. * Henning Schild <henning.schild@siemens.com>
  9. */
  10. #include <linux/gpio/machine.h>
  11. #include <linux/gpio/consumer.h>
  12. #include <linux/leds.h>
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/platform_data/x86/simatic-ipc-base.h>
  16. #include "simatic-ipc-leds-gpio.h"
  17. struct simatic_ipc_led_tables {
  18. struct gpiod_lookup_table *led_lookup_table;
  19. struct gpiod_lookup_table *led_lookup_table_extra;
  20. };
  21. static struct gpiod_lookup_table simatic_ipc_led_gpio_table_227g = {
  22. .dev_id = "leds-gpio",
  23. .table = {
  24. GPIO_LOOKUP_IDX("gpio-f7188x-2", 0, NULL, 0, GPIO_ACTIVE_LOW),
  25. GPIO_LOOKUP_IDX("gpio-f7188x-2", 1, NULL, 1, GPIO_ACTIVE_LOW),
  26. GPIO_LOOKUP_IDX("gpio-f7188x-2", 2, NULL, 2, GPIO_ACTIVE_LOW),
  27. GPIO_LOOKUP_IDX("gpio-f7188x-2", 3, NULL, 3, GPIO_ACTIVE_LOW),
  28. GPIO_LOOKUP_IDX("gpio-f7188x-2", 4, NULL, 4, GPIO_ACTIVE_LOW),
  29. GPIO_LOOKUP_IDX("gpio-f7188x-2", 5, NULL, 5, GPIO_ACTIVE_LOW),
  30. {} /* Terminating entry */
  31. },
  32. };
  33. static struct gpiod_lookup_table simatic_ipc_led_gpio_table_extra_227g = {
  34. .dev_id = NULL, /* Filled during initialization */
  35. .table = {
  36. GPIO_LOOKUP_IDX("gpio-f7188x-3", 6, NULL, 6, GPIO_ACTIVE_HIGH),
  37. GPIO_LOOKUP_IDX("gpio-f7188x-3", 7, NULL, 7, GPIO_ACTIVE_HIGH),
  38. {} /* Terminating entry */
  39. },
  40. };
  41. static struct gpiod_lookup_table simatic_ipc_led_gpio_table_bx_59a = {
  42. .dev_id = "leds-gpio",
  43. .table = {
  44. GPIO_LOOKUP_IDX("gpio-f7188x-2", 0, NULL, 0, GPIO_ACTIVE_LOW),
  45. GPIO_LOOKUP_IDX("gpio-f7188x-2", 3, NULL, 1, GPIO_ACTIVE_LOW),
  46. GPIO_LOOKUP_IDX("gpio-f7188x-5", 3, NULL, 2, GPIO_ACTIVE_LOW),
  47. GPIO_LOOKUP_IDX("gpio-f7188x-5", 2, NULL, 3, GPIO_ACTIVE_LOW),
  48. GPIO_LOOKUP_IDX("gpio-f7188x-7", 7, NULL, 4, GPIO_ACTIVE_LOW),
  49. GPIO_LOOKUP_IDX("gpio-f7188x-7", 4, NULL, 5, GPIO_ACTIVE_LOW),
  50. {} /* Terminating entry */
  51. }
  52. };
  53. static int simatic_ipc_leds_gpio_f7188x_probe(struct platform_device *pdev)
  54. {
  55. const struct simatic_ipc_platform *plat = dev_get_platdata(&pdev->dev);
  56. struct simatic_ipc_led_tables *led_tables;
  57. led_tables = devm_kzalloc(&pdev->dev, sizeof(*led_tables), GFP_KERNEL);
  58. if (!led_tables)
  59. return -ENOMEM;
  60. switch (plat->devmode) {
  61. case SIMATIC_IPC_DEVICE_227G:
  62. led_tables->led_lookup_table = &simatic_ipc_led_gpio_table_227g;
  63. led_tables->led_lookup_table_extra = &simatic_ipc_led_gpio_table_extra_227g;
  64. break;
  65. case SIMATIC_IPC_DEVICE_BX_59A:
  66. led_tables->led_lookup_table = &simatic_ipc_led_gpio_table_bx_59a;
  67. break;
  68. default:
  69. return -ENODEV;
  70. }
  71. platform_set_drvdata(pdev, led_tables);
  72. return simatic_ipc_leds_gpio_probe(pdev, led_tables->led_lookup_table,
  73. led_tables->led_lookup_table_extra);
  74. }
  75. static void simatic_ipc_leds_gpio_f7188x_remove(struct platform_device *pdev)
  76. {
  77. struct simatic_ipc_led_tables *led_tables = platform_get_drvdata(pdev);
  78. simatic_ipc_leds_gpio_remove(pdev, led_tables->led_lookup_table,
  79. led_tables->led_lookup_table_extra);
  80. }
  81. static struct platform_driver simatic_ipc_led_gpio_driver = {
  82. .probe = simatic_ipc_leds_gpio_f7188x_probe,
  83. .remove_new = simatic_ipc_leds_gpio_f7188x_remove,
  84. .driver = {
  85. .name = KBUILD_MODNAME,
  86. },
  87. };
  88. module_platform_driver(simatic_ipc_led_gpio_driver);
  89. MODULE_DESCRIPTION("LED driver for Siemens Simatic IPCs based on Nuvoton GPIO");
  90. MODULE_LICENSE("GPL v2");
  91. MODULE_ALIAS("platform:" KBUILD_MODNAME);
  92. MODULE_SOFTDEP("pre: simatic-ipc-leds-gpio-core gpio_f7188x");
  93. MODULE_AUTHOR("Henning Schild <henning.schild@siemens.com>");