1 // SPDX-License-Identifier: GPL-2.0
3 * Siemens SIMATIC IPC driver for GPIO based LEDs
5 * Copyright (c) Siemens AG, 2022
8 * Henning Schild <henning.schild@siemens.com>
11 #include <linux/gpio/machine.h>
12 #include <linux/gpio/consumer.h>
13 #include <linux/leds.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/platform_data/x86/simatic-ipc-base.h>
18 static struct gpiod_lookup_table *simatic_ipc_led_gpio_table;
20 static struct gpiod_lookup_table simatic_ipc_led_gpio_table_127e = {
21 .dev_id = "leds-gpio",
23 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 52, NULL, 0, GPIO_ACTIVE_LOW),
24 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 53, NULL, 1, GPIO_ACTIVE_LOW),
25 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 57, NULL, 2, GPIO_ACTIVE_LOW),
26 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 58, NULL, 3, GPIO_ACTIVE_LOW),
27 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 60, NULL, 4, GPIO_ACTIVE_LOW),
28 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 51, NULL, 5, GPIO_ACTIVE_LOW),
29 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 56, NULL, 6, GPIO_ACTIVE_LOW),
30 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 59, NULL, 7, GPIO_ACTIVE_HIGH),
34 static struct gpiod_lookup_table simatic_ipc_led_gpio_table_227g = {
35 .dev_id = "leds-gpio",
37 GPIO_LOOKUP_IDX("gpio-f7188x-2", 0, NULL, 0, GPIO_ACTIVE_LOW),
38 GPIO_LOOKUP_IDX("gpio-f7188x-2", 1, NULL, 1, GPIO_ACTIVE_LOW),
39 GPIO_LOOKUP_IDX("gpio-f7188x-2", 2, NULL, 2, GPIO_ACTIVE_LOW),
40 GPIO_LOOKUP_IDX("gpio-f7188x-2", 3, NULL, 3, GPIO_ACTIVE_LOW),
41 GPIO_LOOKUP_IDX("gpio-f7188x-2", 4, NULL, 4, GPIO_ACTIVE_LOW),
42 GPIO_LOOKUP_IDX("gpio-f7188x-2", 5, NULL, 5, GPIO_ACTIVE_LOW),
43 GPIO_LOOKUP_IDX("gpio-f7188x-3", 6, NULL, 6, GPIO_ACTIVE_HIGH),
44 GPIO_LOOKUP_IDX("gpio-f7188x-3", 7, NULL, 7, GPIO_ACTIVE_HIGH),
48 static const struct gpio_led simatic_ipc_gpio_leds[] = {
49 { .name = "red:" LED_FUNCTION_STATUS "-1" },
50 { .name = "green:" LED_FUNCTION_STATUS "-1" },
51 { .name = "red:" LED_FUNCTION_STATUS "-2" },
52 { .name = "green:" LED_FUNCTION_STATUS "-2" },
53 { .name = "red:" LED_FUNCTION_STATUS "-3" },
54 { .name = "green:" LED_FUNCTION_STATUS "-3" },
57 static const struct gpio_led_platform_data simatic_ipc_gpio_leds_pdata = {
58 .num_leds = ARRAY_SIZE(simatic_ipc_gpio_leds),
59 .leds = simatic_ipc_gpio_leds,
62 static struct platform_device *simatic_leds_pdev;
64 static int simatic_ipc_leds_gpio_remove(struct platform_device *pdev)
66 gpiod_remove_lookup_table(simatic_ipc_led_gpio_table);
67 platform_device_unregister(simatic_leds_pdev);
72 static int simatic_ipc_leds_gpio_probe(struct platform_device *pdev)
74 const struct simatic_ipc_platform *plat = pdev->dev.platform_data;
75 struct gpio_desc *gpiod;
78 switch (plat->devmode) {
79 case SIMATIC_IPC_DEVICE_127E:
80 if (!IS_ENABLED(CONFIG_PINCTRL_BROXTON))
82 simatic_ipc_led_gpio_table = &simatic_ipc_led_gpio_table_127e;
84 case SIMATIC_IPC_DEVICE_227G:
85 if (!IS_ENABLED(CONFIG_GPIO_F7188X))
87 request_module("gpio-f7188x");
88 simatic_ipc_led_gpio_table = &simatic_ipc_led_gpio_table_227g;
94 gpiod_add_lookup_table(simatic_ipc_led_gpio_table);
95 simatic_leds_pdev = platform_device_register_resndata(NULL,
96 "leds-gpio", PLATFORM_DEVID_NONE, NULL, 0,
97 &simatic_ipc_gpio_leds_pdata,
98 sizeof(simatic_ipc_gpio_leds_pdata));
99 if (IS_ERR(simatic_leds_pdev)) {
100 err = PTR_ERR(simatic_leds_pdev);
105 gpiod = gpiod_get_index(&simatic_leds_pdev->dev, NULL, 6, GPIOD_OUT_LOW);
107 err = PTR_ERR(gpiod);
113 gpiod = gpiod_get_index(&simatic_leds_pdev->dev, NULL, 7, GPIOD_OUT_LOW);
115 err = PTR_ERR(gpiod);
122 simatic_ipc_leds_gpio_remove(pdev);
127 static struct platform_driver simatic_ipc_led_gpio_driver = {
128 .probe = simatic_ipc_leds_gpio_probe,
129 .remove = simatic_ipc_leds_gpio_remove,
131 .name = KBUILD_MODNAME,
134 module_platform_driver(simatic_ipc_led_gpio_driver);
136 MODULE_LICENSE("GPL v2");
137 MODULE_ALIAS("platform:" KBUILD_MODNAME);
138 MODULE_SOFTDEP("pre: platform:leds-gpio");
139 MODULE_AUTHOR("Henning Schild <henning.schild@siemens.com>");