Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: simatic-ipc-leds-gpio: Split up into multiple drivers

In order to clearly describe the dependencies between the GPIO
controller drivers and the users the driver is split up into a core,
two drivers and a common header.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Lee Jones <lee@kernel.org>
Link: https://lore.kernel.org/r/20230524124628.32295-4-henning.schild@siemens.com

authored by

Henning Schild and committed by
Lee Jones
2f5d6fe3 799c0197

+265 -168
+3 -1
drivers/leds/simple/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 obj-$(CONFIG_LEDS_SIEMENS_SIMATIC_IPC) += simatic-ipc-leds.o 3 - obj-$(CONFIG_LEDS_SIEMENS_SIMATIC_IPC) += simatic-ipc-leds-gpio.o 3 + obj-$(CONFIG_LEDS_SIEMENS_SIMATIC_IPC) += simatic-ipc-leds-gpio-core.o 4 + obj-$(CONFIG_LEDS_SIEMENS_SIMATIC_IPC) += simatic-ipc-leds-gpio-apollolake.o 5 + obj-$(CONFIG_LEDS_SIEMENS_SIMATIC_IPC) += simatic-ipc-leds-gpio-f7188x.o
+66
drivers/leds/simple/simatic-ipc-leds-gpio-apollolake.c
··· 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 + 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> 17 + 18 + #include "simatic-ipc-leds-gpio.h" 19 + 20 + static struct gpiod_lookup_table simatic_ipc_led_gpio_table = { 21 + .dev_id = "leds-gpio", 22 + .table = { 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 + {} /* Terminating entry */ 30 + }, 31 + }; 32 + 33 + static struct gpiod_lookup_table simatic_ipc_led_gpio_table_extra = { 34 + .dev_id = NULL, /* Filled during initialization */ 35 + .table = { 36 + GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 56, NULL, 6, GPIO_ACTIVE_LOW), 37 + GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 59, NULL, 7, GPIO_ACTIVE_HIGH), 38 + {} /* Terminating entry */ 39 + }, 40 + }; 41 + 42 + static int simatic_ipc_leds_gpio_apollolake_probe(struct platform_device *pdev) 43 + { 44 + return simatic_ipc_leds_gpio_probe(pdev, &simatic_ipc_led_gpio_table, 45 + &simatic_ipc_led_gpio_table_extra); 46 + } 47 + 48 + static int simatic_ipc_leds_gpio_apollolake_remove(struct platform_device *pdev) 49 + { 50 + return simatic_ipc_leds_gpio_remove(pdev, &simatic_ipc_led_gpio_table, 51 + &simatic_ipc_led_gpio_table_extra); 52 + } 53 + 54 + static struct platform_driver simatic_ipc_led_gpio_apollolake_driver = { 55 + .probe = simatic_ipc_leds_gpio_apollolake_probe, 56 + .remove = simatic_ipc_leds_gpio_apollolake_remove, 57 + .driver = { 58 + .name = KBUILD_MODNAME, 59 + }, 60 + }; 61 + module_platform_driver(simatic_ipc_led_gpio_apollolake_driver); 62 + 63 + MODULE_LICENSE("GPL v2"); 64 + MODULE_ALIAS("platform:" KBUILD_MODNAME); 65 + MODULE_SOFTDEP("pre: simatic-ipc-leds-gpio-core platform:apollolake-pinctrl"); 66 + MODULE_AUTHOR("Henning Schild <henning.schild@siemens.com>");
+104
drivers/leds/simple/simatic-ipc-leds-gpio-core.c
··· 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 + 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> 17 + 18 + #include "simatic-ipc-leds-gpio.h" 19 + 20 + static struct platform_device *simatic_leds_pdev; 21 + 22 + static const struct gpio_led simatic_ipc_gpio_leds[] = { 23 + { .name = "red:" LED_FUNCTION_STATUS "-1" }, 24 + { .name = "green:" LED_FUNCTION_STATUS "-1" }, 25 + { .name = "red:" LED_FUNCTION_STATUS "-2" }, 26 + { .name = "green:" LED_FUNCTION_STATUS "-2" }, 27 + { .name = "red:" LED_FUNCTION_STATUS "-3" }, 28 + { .name = "green:" LED_FUNCTION_STATUS "-3" }, 29 + }; 30 + 31 + static const struct gpio_led_platform_data simatic_ipc_gpio_leds_pdata = { 32 + .num_leds = ARRAY_SIZE(simatic_ipc_gpio_leds), 33 + .leds = simatic_ipc_gpio_leds, 34 + }; 35 + 36 + int simatic_ipc_leds_gpio_remove(struct platform_device *pdev, 37 + struct gpiod_lookup_table *table, 38 + struct gpiod_lookup_table *table_extra) 39 + { 40 + gpiod_remove_lookup_table(table); 41 + gpiod_remove_lookup_table(table_extra); 42 + platform_device_unregister(simatic_leds_pdev); 43 + 44 + return 0; 45 + } 46 + EXPORT_SYMBOL_GPL(simatic_ipc_leds_gpio_remove); 47 + 48 + int simatic_ipc_leds_gpio_probe(struct platform_device *pdev, 49 + struct gpiod_lookup_table *table, 50 + struct gpiod_lookup_table *table_extra) 51 + { 52 + const struct simatic_ipc_platform *plat = pdev->dev.platform_data; 53 + struct device *dev = &pdev->dev; 54 + struct gpio_desc *gpiod; 55 + int err; 56 + 57 + switch (plat->devmode) { 58 + case SIMATIC_IPC_DEVICE_127E: 59 + case SIMATIC_IPC_DEVICE_227G: 60 + break; 61 + default: 62 + return -ENODEV; 63 + } 64 + 65 + gpiod_add_lookup_table(table); 66 + simatic_leds_pdev = platform_device_register_resndata(NULL, 67 + "leds-gpio", PLATFORM_DEVID_NONE, NULL, 0, 68 + &simatic_ipc_gpio_leds_pdata, 69 + sizeof(simatic_ipc_gpio_leds_pdata)); 70 + if (IS_ERR(simatic_leds_pdev)) { 71 + err = PTR_ERR(simatic_leds_pdev); 72 + goto out; 73 + } 74 + 75 + table_extra->dev_id = dev_name(dev); 76 + gpiod_add_lookup_table(table_extra); 77 + 78 + /* PM_BIOS_BOOT_N */ 79 + gpiod = gpiod_get_index(dev, NULL, 6, GPIOD_OUT_LOW); 80 + if (IS_ERR(gpiod)) { 81 + err = PTR_ERR(gpiod); 82 + goto out; 83 + } 84 + gpiod_put(gpiod); 85 + 86 + /* PM_WDT_OUT */ 87 + gpiod = gpiod_get_index(dev, NULL, 7, GPIOD_OUT_LOW); 88 + if (IS_ERR(gpiod)) { 89 + err = PTR_ERR(gpiod); 90 + goto out; 91 + } 92 + gpiod_put(gpiod); 93 + 94 + return 0; 95 + out: 96 + simatic_ipc_leds_gpio_remove(pdev, table, table_extra); 97 + 98 + return err; 99 + } 100 + EXPORT_SYMBOL_GPL(simatic_ipc_leds_gpio_probe); 101 + 102 + MODULE_LICENSE("GPL v2"); 103 + MODULE_SOFTDEP("pre: platform:leds-gpio"); 104 + MODULE_AUTHOR("Henning Schild <henning.schild@siemens.com>");
+66
drivers/leds/simple/simatic-ipc-leds-gpio-f7188x.c
··· 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 + 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> 17 + 18 + #include "simatic-ipc-leds-gpio.h" 19 + 20 + static struct gpiod_lookup_table simatic_ipc_led_gpio_table = { 21 + .dev_id = "leds-gpio", 22 + .table = { 23 + GPIO_LOOKUP_IDX("gpio-f7188x-2", 0, NULL, 0, GPIO_ACTIVE_LOW), 24 + GPIO_LOOKUP_IDX("gpio-f7188x-2", 1, NULL, 1, GPIO_ACTIVE_LOW), 25 + GPIO_LOOKUP_IDX("gpio-f7188x-2", 2, NULL, 2, GPIO_ACTIVE_LOW), 26 + GPIO_LOOKUP_IDX("gpio-f7188x-2", 3, NULL, 3, GPIO_ACTIVE_LOW), 27 + GPIO_LOOKUP_IDX("gpio-f7188x-2", 4, NULL, 4, GPIO_ACTIVE_LOW), 28 + GPIO_LOOKUP_IDX("gpio-f7188x-2", 5, NULL, 5, GPIO_ACTIVE_LOW), 29 + {} /* Terminating entry */ 30 + }, 31 + }; 32 + 33 + static struct gpiod_lookup_table simatic_ipc_led_gpio_table_extra = { 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 + 42 + static int simatic_ipc_leds_gpio_f7188x_probe(struct platform_device *pdev) 43 + { 44 + return simatic_ipc_leds_gpio_probe(pdev, &simatic_ipc_led_gpio_table, 45 + &simatic_ipc_led_gpio_table_extra); 46 + } 47 + 48 + static int simatic_ipc_leds_gpio_f7188x_remove(struct platform_device *pdev) 49 + { 50 + return simatic_ipc_leds_gpio_remove(pdev, &simatic_ipc_led_gpio_table, 51 + &simatic_ipc_led_gpio_table_extra); 52 + } 53 + 54 + static struct platform_driver simatic_ipc_led_gpio_driver = { 55 + .probe = simatic_ipc_leds_gpio_f7188x_probe, 56 + .remove = simatic_ipc_leds_gpio_f7188x_remove, 57 + .driver = { 58 + .name = KBUILD_MODNAME, 59 + }, 60 + }; 61 + module_platform_driver(simatic_ipc_led_gpio_driver); 62 + 63 + MODULE_LICENSE("GPL v2"); 64 + MODULE_ALIAS("platform:" KBUILD_MODNAME); 65 + MODULE_SOFTDEP("pre: simatic-ipc-leds-gpio-core gpio_f7188x"); 66 + MODULE_AUTHOR("Henning Schild <henning.schild@siemens.com>");
-163
drivers/leds/simple/simatic-ipc-leds-gpio.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Siemens SIMATIC IPC driver for GPIO based LEDs 4 - * 5 - * Copyright (c) Siemens AG, 2022 6 - * 7 - * Authors: 8 - * Henning Schild <henning.schild@siemens.com> 9 - */ 10 - 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> 17 - 18 - static struct gpiod_lookup_table *simatic_ipc_led_gpio_table; 19 - static struct gpiod_lookup_table *simatic_ipc_led_gpio_table_extra; 20 - 21 - static struct gpiod_lookup_table simatic_ipc_led_gpio_table_127e = { 22 - .dev_id = "leds-gpio", 23 - .table = { 24 - GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 52, NULL, 0, GPIO_ACTIVE_LOW), 25 - GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 53, NULL, 1, GPIO_ACTIVE_LOW), 26 - GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 57, NULL, 2, GPIO_ACTIVE_LOW), 27 - GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 58, NULL, 3, GPIO_ACTIVE_LOW), 28 - GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 60, NULL, 4, GPIO_ACTIVE_LOW), 29 - GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 51, NULL, 5, GPIO_ACTIVE_LOW), 30 - {} /* Terminating entry */ 31 - }, 32 - }; 33 - 34 - static struct gpiod_lookup_table simatic_ipc_led_gpio_table_127e_extra = { 35 - .dev_id = NULL, /* Filled during initialization */ 36 - .table = { 37 - GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 56, NULL, 6, GPIO_ACTIVE_LOW), 38 - GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 59, NULL, 7, GPIO_ACTIVE_HIGH), 39 - {} /* Terminating entry */ 40 - }, 41 - }; 42 - 43 - static struct gpiod_lookup_table simatic_ipc_led_gpio_table_227g = { 44 - .dev_id = "leds-gpio", 45 - .table = { 46 - GPIO_LOOKUP_IDX("gpio-f7188x-2", 0, NULL, 0, GPIO_ACTIVE_LOW), 47 - GPIO_LOOKUP_IDX("gpio-f7188x-2", 1, NULL, 1, GPIO_ACTIVE_LOW), 48 - GPIO_LOOKUP_IDX("gpio-f7188x-2", 2, NULL, 2, GPIO_ACTIVE_LOW), 49 - GPIO_LOOKUP_IDX("gpio-f7188x-2", 3, NULL, 3, GPIO_ACTIVE_LOW), 50 - GPIO_LOOKUP_IDX("gpio-f7188x-2", 4, NULL, 4, GPIO_ACTIVE_LOW), 51 - GPIO_LOOKUP_IDX("gpio-f7188x-2", 5, NULL, 5, GPIO_ACTIVE_LOW), 52 - {} /* Terminating entry */ 53 - }, 54 - }; 55 - 56 - static struct gpiod_lookup_table simatic_ipc_led_gpio_table_227g_extra = { 57 - .dev_id = NULL, /* Filled during initialization */ 58 - .table = { 59 - GPIO_LOOKUP_IDX("gpio-f7188x-3", 6, NULL, 6, GPIO_ACTIVE_HIGH), 60 - GPIO_LOOKUP_IDX("gpio-f7188x-3", 7, NULL, 7, GPIO_ACTIVE_HIGH), 61 - {} /* Terminating entry */ 62 - }, 63 - }; 64 - 65 - static const struct gpio_led simatic_ipc_gpio_leds[] = { 66 - { .name = "red:" LED_FUNCTION_STATUS "-1" }, 67 - { .name = "green:" LED_FUNCTION_STATUS "-1" }, 68 - { .name = "red:" LED_FUNCTION_STATUS "-2" }, 69 - { .name = "green:" LED_FUNCTION_STATUS "-2" }, 70 - { .name = "red:" LED_FUNCTION_STATUS "-3" }, 71 - { .name = "green:" LED_FUNCTION_STATUS "-3" }, 72 - }; 73 - 74 - static const struct gpio_led_platform_data simatic_ipc_gpio_leds_pdata = { 75 - .num_leds = ARRAY_SIZE(simatic_ipc_gpio_leds), 76 - .leds = simatic_ipc_gpio_leds, 77 - }; 78 - 79 - static struct platform_device *simatic_leds_pdev; 80 - 81 - static int simatic_ipc_leds_gpio_remove(struct platform_device *pdev) 82 - { 83 - gpiod_remove_lookup_table(simatic_ipc_led_gpio_table); 84 - gpiod_remove_lookup_table(simatic_ipc_led_gpio_table_extra); 85 - platform_device_unregister(simatic_leds_pdev); 86 - 87 - return 0; 88 - } 89 - 90 - static int simatic_ipc_leds_gpio_probe(struct platform_device *pdev) 91 - { 92 - const struct simatic_ipc_platform *plat = pdev->dev.platform_data; 93 - struct device *dev = &pdev->dev; 94 - struct gpio_desc *gpiod; 95 - int err; 96 - 97 - switch (plat->devmode) { 98 - case SIMATIC_IPC_DEVICE_127E: 99 - if (!IS_ENABLED(CONFIG_PINCTRL_BROXTON)) 100 - return -ENODEV; 101 - simatic_ipc_led_gpio_table = &simatic_ipc_led_gpio_table_127e; 102 - simatic_ipc_led_gpio_table_extra = &simatic_ipc_led_gpio_table_127e_extra; 103 - break; 104 - case SIMATIC_IPC_DEVICE_227G: 105 - if (!IS_ENABLED(CONFIG_GPIO_F7188X)) 106 - return -ENODEV; 107 - request_module("gpio-f7188x"); 108 - simatic_ipc_led_gpio_table = &simatic_ipc_led_gpio_table_227g; 109 - simatic_ipc_led_gpio_table_extra = &simatic_ipc_led_gpio_table_227g_extra; 110 - break; 111 - default: 112 - return -ENODEV; 113 - } 114 - 115 - gpiod_add_lookup_table(simatic_ipc_led_gpio_table); 116 - simatic_leds_pdev = platform_device_register_resndata(NULL, 117 - "leds-gpio", PLATFORM_DEVID_NONE, NULL, 0, 118 - &simatic_ipc_gpio_leds_pdata, 119 - sizeof(simatic_ipc_gpio_leds_pdata)); 120 - if (IS_ERR(simatic_leds_pdev)) { 121 - err = PTR_ERR(simatic_leds_pdev); 122 - goto out; 123 - } 124 - 125 - simatic_ipc_led_gpio_table_extra->dev_id = dev_name(dev); 126 - gpiod_add_lookup_table(simatic_ipc_led_gpio_table_extra); 127 - 128 - /* PM_BIOS_BOOT_N */ 129 - gpiod = gpiod_get_index(dev, NULL, 6, GPIOD_OUT_LOW); 130 - if (IS_ERR(gpiod)) { 131 - err = PTR_ERR(gpiod); 132 - goto out; 133 - } 134 - gpiod_put(gpiod); 135 - 136 - /* PM_WDT_OUT */ 137 - gpiod = gpiod_get_index(dev, NULL, 7, GPIOD_OUT_LOW); 138 - if (IS_ERR(gpiod)) { 139 - err = PTR_ERR(gpiod); 140 - goto out; 141 - } 142 - gpiod_put(gpiod); 143 - 144 - return 0; 145 - out: 146 - simatic_ipc_leds_gpio_remove(pdev); 147 - 148 - return err; 149 - } 150 - 151 - static struct platform_driver simatic_ipc_led_gpio_driver = { 152 - .probe = simatic_ipc_leds_gpio_probe, 153 - .remove = simatic_ipc_leds_gpio_remove, 154 - .driver = { 155 - .name = KBUILD_MODNAME, 156 - } 157 - }; 158 - module_platform_driver(simatic_ipc_led_gpio_driver); 159 - 160 - MODULE_LICENSE("GPL v2"); 161 - MODULE_ALIAS("platform:" KBUILD_MODNAME); 162 - MODULE_SOFTDEP("pre: platform:leds-gpio"); 163 - MODULE_AUTHOR("Henning Schild <henning.schild@siemens.com>");
+22
drivers/leds/simple/simatic-ipc-leds-gpio.h
··· 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 + 11 + #ifndef _SIMATIC_IPC_LEDS_GPIO_H 12 + #define _SIMATIC_IPC_LEDS_GPIO_H 13 + 14 + int simatic_ipc_leds_gpio_probe(struct platform_device *pdev, 15 + struct gpiod_lookup_table *table, 16 + struct gpiod_lookup_table *table_extra); 17 + 18 + int simatic_ipc_leds_gpio_remove(struct platform_device *pdev, 19 + struct gpiod_lookup_table *table, 20 + struct gpiod_lookup_table *table_extra); 21 + 22 + #endif /* _SIMATIC_IPC_LEDS_GPIO_H */
-1
drivers/leds/simple/simatic-ipc-leds.c
··· 126 126 .name = KBUILD_MODNAME, 127 127 } 128 128 }; 129 - 130 129 module_platform_driver(simatic_ipc_led_driver); 131 130 132 131 MODULE_LICENSE("GPL v2");
+4 -3
drivers/platform/x86/simatic-ipc.c
··· 68 68 } 69 69 70 70 if (ledmode != SIMATIC_IPC_DEVICE_NONE) { 71 - if (ledmode == SIMATIC_IPC_DEVICE_127E || 72 - ledmode == SIMATIC_IPC_DEVICE_227G) 73 - pdevname = KBUILD_MODNAME "_leds_gpio"; 71 + if (ledmode == SIMATIC_IPC_DEVICE_127E) 72 + pdevname = KBUILD_MODNAME "_leds_gpio_apollolake"; 73 + if (ledmode == SIMATIC_IPC_DEVICE_227G) 74 + pdevname = KBUILD_MODNAME "_leds_gpio_f7188x"; 74 75 platform_data.devmode = ledmode; 75 76 ipc_led_platform_device = 76 77 platform_device_register_data(NULL,