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

leds: simatic-ipc-leds-gpio: Add GPIO version of Siemens driver

On Apollo Lake the pinctrl drivers will now come up without ACPI. Use
that instead of open coding it.
Create a new driver for that which can later be filled with more GPIO
based models, and which has different dependencies.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Henning Schild and committed by
Lee Jones
a6c80bec 446f0cf9

+117 -81
+3 -4
drivers/leds/simple/Kconfig
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 config LEDS_SIEMENS_SIMATIC_IPC 3 3 tristate "LED driver for Siemens Simatic IPCs" 4 - depends on LEDS_CLASS 4 + depends on LEDS_GPIO 5 5 depends on SIEMENS_SIMATIC_IPC 6 - select P2SB 7 6 help 8 7 This option enables support for the LEDs of several Industrial PCs 9 8 from Siemens. 10 9 11 - To compile this driver as a module, choose M here: the module 12 - will be called simatic-ipc-leds. 10 + To compile this driver as a module, choose M here: the modules 11 + will be called simatic-ipc-leds and simatic-ipc-leds-gpio.
+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
+105
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 + 17 + static struct gpiod_lookup_table simatic_ipc_led_gpio_table = { 18 + .dev_id = "leds-gpio", 19 + .table = { 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), 28 + }, 29 + }; 30 + 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" }, 38 + }; 39 + 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, 43 + }; 44 + 45 + static struct platform_device *simatic_leds_pdev; 46 + 47 + static int simatic_ipc_leds_gpio_remove(struct platform_device *pdev) 48 + { 49 + gpiod_remove_lookup_table(&simatic_ipc_led_gpio_table); 50 + platform_device_unregister(simatic_leds_pdev); 51 + 52 + return 0; 53 + } 54 + 55 + static int simatic_ipc_leds_gpio_probe(struct platform_device *pdev) 56 + { 57 + struct gpio_desc *gpiod; 58 + int err; 59 + 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); 67 + goto out; 68 + } 69 + 70 + /* PM_BIOS_BOOT_N */ 71 + gpiod = gpiod_get_index(&simatic_leds_pdev->dev, NULL, 6, GPIOD_OUT_LOW); 72 + if (IS_ERR(gpiod)) { 73 + err = PTR_ERR(gpiod); 74 + goto out; 75 + } 76 + gpiod_put(gpiod); 77 + 78 + /* PM_WDT_OUT */ 79 + gpiod = gpiod_get_index(&simatic_leds_pdev->dev, NULL, 7, GPIOD_OUT_LOW); 80 + if (IS_ERR(gpiod)) { 81 + err = PTR_ERR(gpiod); 82 + goto out; 83 + } 84 + gpiod_put(gpiod); 85 + 86 + return 0; 87 + out: 88 + simatic_ipc_leds_gpio_remove(pdev); 89 + 90 + return err; 91 + } 92 + 93 + static struct platform_driver simatic_ipc_led_gpio_driver = { 94 + .probe = simatic_ipc_leds_gpio_probe, 95 + .remove = simatic_ipc_leds_gpio_remove, 96 + .driver = { 97 + .name = KBUILD_MODNAME, 98 + } 99 + }; 100 + module_platform_driver(simatic_ipc_led_gpio_driver); 101 + 102 + MODULE_LICENSE("GPL v2"); 103 + MODULE_ALIAS("platform:" KBUILD_MODNAME); 104 + MODULE_SOFTDEP("pre: platform:leds-gpio"); 105 + MODULE_AUTHOR("Henning Schild <henning.schild@siemens.com>");
+4 -76
drivers/leds/simple/simatic-ipc-leds.c
··· 15 15 #include <linux/leds.h> 16 16 #include <linux/module.h> 17 17 #include <linux/pci.h> 18 - #include <linux/platform_data/x86/p2sb.h> 19 18 #include <linux/platform_data/x86/simatic-ipc-base.h> 20 19 #include <linux/platform_device.h> 21 20 #include <linux/sizes.h> ··· 23 24 #define SIMATIC_IPC_LED_PORT_BASE 0x404E 24 25 25 26 struct simatic_ipc_led { 26 - unsigned int value; /* mask for io and offset for mem */ 27 + unsigned int value; /* mask for io */ 27 28 char *name; 28 29 struct led_classdev cdev; 29 30 }; ··· 35 36 {1 << 6, "yellow:" LED_FUNCTION_STATUS "-2" }, 36 37 {1 << 13, "red:" LED_FUNCTION_STATUS "-3" }, 37 38 {1 << 5, "yellow:" LED_FUNCTION_STATUS "-3" }, 38 - { } 39 - }; 40 - 41 - /* the actual start will be discovered with p2sb, 0 is a placeholder */ 42 - static struct resource simatic_ipc_led_mem_res = DEFINE_RES_MEM_NAMED(0, 0, KBUILD_MODNAME); 43 - 44 - static void __iomem *simatic_ipc_led_memory; 45 - 46 - static struct simatic_ipc_led simatic_ipc_leds_mem[] = { 47 - {0x500 + 0x1A0, "red:" LED_FUNCTION_STATUS "-1"}, 48 - {0x500 + 0x1A8, "green:" LED_FUNCTION_STATUS "-1"}, 49 - {0x500 + 0x1C8, "red:" LED_FUNCTION_STATUS "-2"}, 50 - {0x500 + 0x1D0, "green:" LED_FUNCTION_STATUS "-2"}, 51 - {0x500 + 0x1E0, "red:" LED_FUNCTION_STATUS "-3"}, 52 - {0x500 + 0x198, "green:" LED_FUNCTION_STATUS "-3"}, 53 39 { } 54 40 }; 55 41 ··· 73 89 return inw(SIMATIC_IPC_LED_PORT_BASE) & led->value ? LED_OFF : led_cd->max_brightness; 74 90 } 75 91 76 - static void simatic_ipc_led_set_mem(struct led_classdev *led_cd, 77 - enum led_brightness brightness) 78 - { 79 - struct simatic_ipc_led *led = cdev_to_led(led_cd); 80 - void __iomem *reg = simatic_ipc_led_memory + led->value; 81 - u32 val; 82 - 83 - val = readl(reg); 84 - val = (val & ~1) | (brightness == LED_OFF); 85 - writel(val, reg); 86 - } 87 - 88 - static enum led_brightness simatic_ipc_led_get_mem(struct led_classdev *led_cd) 89 - { 90 - struct simatic_ipc_led *led = cdev_to_led(led_cd); 91 - void __iomem *reg = simatic_ipc_led_memory + led->value; 92 - u32 val; 93 - 94 - val = readl(reg); 95 - return (val & 1) ? LED_OFF : led_cd->max_brightness; 96 - } 97 - 98 92 static int simatic_ipc_leds_probe(struct platform_device *pdev) 99 93 { 100 94 const struct simatic_ipc_platform *plat = pdev->dev.platform_data; ··· 80 118 struct simatic_ipc_led *ipcled; 81 119 struct led_classdev *cdev; 82 120 struct resource *res; 83 - void __iomem *reg; 84 - int err, type; 85 - u32 val; 121 + int err; 86 122 87 123 switch (plat->devmode) { 88 124 case SIMATIC_IPC_DEVICE_227D: ··· 95 135 } 96 136 ipcled = simatic_ipc_leds_io; 97 137 } 98 - type = IORESOURCE_IO; 99 138 if (!devm_request_region(dev, res->start, resource_size(res), KBUILD_MODNAME)) { 100 139 dev_err(dev, "Unable to register IO resource at %pR\n", res); 101 140 return -EBUSY; 102 141 } 103 - break; 104 - case SIMATIC_IPC_DEVICE_127E: 105 - res = &simatic_ipc_led_mem_res; 106 - ipcled = simatic_ipc_leds_mem; 107 - type = IORESOURCE_MEM; 108 - 109 - err = p2sb_bar(NULL, 0, res); 110 - if (err) 111 - return err; 112 - 113 - /* do the final address calculation */ 114 - res->start = res->start + (0xC5 << 16); 115 - res->end = res->start + SZ_4K - 1; 116 - 117 - simatic_ipc_led_memory = devm_ioremap_resource(dev, res); 118 - if (IS_ERR(simatic_ipc_led_memory)) 119 - return PTR_ERR(simatic_ipc_led_memory); 120 - 121 - /* initialize power/watchdog LED */ 122 - reg = simatic_ipc_led_memory + 0x500 + 0x1D8; /* PM_WDT_OUT */ 123 - val = readl(reg); 124 - writel(val & ~1, reg); 125 - 126 - reg = simatic_ipc_led_memory + 0x500 + 0x1C0; /* PM_BIOS_BOOT_N */ 127 - val = readl(reg); 128 - writel(val | 1, reg); 129 142 break; 130 143 default: 131 144 return -ENODEV; ··· 106 173 107 174 while (ipcled->value) { 108 175 cdev = &ipcled->cdev; 109 - if (type == IORESOURCE_MEM) { 110 - cdev->brightness_set = simatic_ipc_led_set_mem; 111 - cdev->brightness_get = simatic_ipc_led_get_mem; 112 - } else { 113 - cdev->brightness_set = simatic_ipc_led_set_io; 114 - cdev->brightness_get = simatic_ipc_led_get_io; 115 - } 176 + cdev->brightness_set = simatic_ipc_led_set_io; 177 + cdev->brightness_get = simatic_ipc_led_get_io; 116 178 cdev->max_brightness = LED_ON; 117 179 cdev->name = ipcled->name; 118 180
+4 -1
drivers/platform/x86/simatic-ipc.c
··· 51 51 { 52 52 u8 ledmode = SIMATIC_IPC_DEVICE_NONE; 53 53 u8 wdtmode = SIMATIC_IPC_DEVICE_NONE; 54 + char *pdevname = KBUILD_MODNAME "_leds"; 54 55 int i; 55 56 56 57 platform_data.devmode = SIMATIC_IPC_DEVICE_NONE; ··· 65 64 } 66 65 67 66 if (ledmode != SIMATIC_IPC_DEVICE_NONE) { 67 + if (ledmode == SIMATIC_IPC_DEVICE_127E) 68 + pdevname = KBUILD_MODNAME "_leds_gpio"; 68 69 platform_data.devmode = ledmode; 69 70 ipc_led_platform_device = 70 71 platform_device_register_data(NULL, 71 - KBUILD_MODNAME "_leds", PLATFORM_DEVID_NONE, 72 + pdevname, PLATFORM_DEVID_NONE, 72 73 &platform_data, 73 74 sizeof(struct simatic_ipc_platform)); 74 75 if (IS_ERR(ipc_led_platform_device))