1 // SPDX-License-Identifier: GPL-2.0
3 * Siemens SIMATIC IPC driver for GPIO based LEDs
5 * Copyright (c) Siemens AG, 2022
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>
17 static struct gpiod_lookup_table simatic_ipc_led_gpio_table = {
18 .dev_id = "leds-gpio",
20 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 51, NULL, 0, GPIO_ACTIVE_LOW),
21 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 52, NULL, 1, GPIO_ACTIVE_LOW),
22 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 53, NULL, 2, GPIO_ACTIVE_LOW),
23 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 57, NULL, 3, GPIO_ACTIVE_LOW),
24 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 58, NULL, 4, GPIO_ACTIVE_LOW),
25 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 60, NULL, 5, GPIO_ACTIVE_LOW),
26 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 56, NULL, 6, GPIO_ACTIVE_LOW),
27 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 59, NULL, 7, GPIO_ACTIVE_HIGH),
31 static const struct gpio_led simatic_ipc_gpio_leds[] = {
32 { .name = "green:" LED_FUNCTION_STATUS "-3" },
33 { .name = "red:" LED_FUNCTION_STATUS "-1" },
34 { .name = "green:" LED_FUNCTION_STATUS "-1" },
35 { .name = "red:" LED_FUNCTION_STATUS "-2" },
36 { .name = "green:" LED_FUNCTION_STATUS "-2" },
37 { .name = "red:" LED_FUNCTION_STATUS "-3" },
40 static const struct gpio_led_platform_data simatic_ipc_gpio_leds_pdata = {
41 .num_leds = ARRAY_SIZE(simatic_ipc_gpio_leds),
42 .leds = simatic_ipc_gpio_leds,
45 static struct platform_device *simatic_leds_pdev;
47 static int simatic_ipc_leds_gpio_remove(struct platform_device *pdev)
49 gpiod_remove_lookup_table(&simatic_ipc_led_gpio_table);
50 platform_device_unregister(simatic_leds_pdev);
55 static int simatic_ipc_leds_gpio_probe(struct platform_device *pdev)
57 struct gpio_desc *gpiod;
60 gpiod_add_lookup_table(&simatic_ipc_led_gpio_table);
61 simatic_leds_pdev = platform_device_register_resndata(NULL,
62 "leds-gpio", PLATFORM_DEVID_NONE, NULL, 0,
63 &simatic_ipc_gpio_leds_pdata,
64 sizeof(simatic_ipc_gpio_leds_pdata));
65 if (IS_ERR(simatic_leds_pdev)) {
66 err = PTR_ERR(simatic_leds_pdev);
71 gpiod = gpiod_get_index(&simatic_leds_pdev->dev, NULL, 6, GPIOD_OUT_LOW);
79 gpiod = gpiod_get_index(&simatic_leds_pdev->dev, NULL, 7, GPIOD_OUT_LOW);
88 simatic_ipc_leds_gpio_remove(pdev);
93 static struct platform_driver simatic_ipc_led_gpio_driver = {
94 .probe = simatic_ipc_leds_gpio_probe,
95 .remove = simatic_ipc_leds_gpio_remove,
97 .name = KBUILD_MODNAME,
100 module_platform_driver(simatic_ipc_led_gpio_driver);
102 MODULE_LICENSE("GPL v2");
103 MODULE_ALIAS("platform:" KBUILD_MODNAME);
104 MODULE_SOFTDEP("pre: platform:leds-gpio");