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

Configure Feed

Select the types of activity you want to include in your feed.

at v6.2-rc8 137 lines 4.2 kB view raw
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 18static struct gpiod_lookup_table *simatic_ipc_led_gpio_table; 19 20static struct gpiod_lookup_table simatic_ipc_led_gpio_table_127e = { 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 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), 31 }, 32}; 33 34static struct gpiod_lookup_table simatic_ipc_led_gpio_table_227g = { 35 .dev_id = "leds-gpio", 36 .table = { 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), 45 } 46}; 47 48static 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" }, 55}; 56 57static 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, 60}; 61 62static struct platform_device *simatic_leds_pdev; 63 64static int simatic_ipc_leds_gpio_remove(struct platform_device *pdev) 65{ 66 gpiod_remove_lookup_table(simatic_ipc_led_gpio_table); 67 platform_device_unregister(simatic_leds_pdev); 68 69 return 0; 70} 71 72static int simatic_ipc_leds_gpio_probe(struct platform_device *pdev) 73{ 74 const struct simatic_ipc_platform *plat = pdev->dev.platform_data; 75 struct gpio_desc *gpiod; 76 int err; 77 78 switch (plat->devmode) { 79 case SIMATIC_IPC_DEVICE_127E: 80 simatic_ipc_led_gpio_table = &simatic_ipc_led_gpio_table_127e; 81 break; 82 case SIMATIC_IPC_DEVICE_227G: 83 if (!IS_ENABLED(CONFIG_GPIO_F7188X)) 84 return -ENODEV; 85 request_module("gpio-f7188x"); 86 simatic_ipc_led_gpio_table = &simatic_ipc_led_gpio_table_227g; 87 break; 88 default: 89 return -ENODEV; 90 } 91 92 gpiod_add_lookup_table(simatic_ipc_led_gpio_table); 93 simatic_leds_pdev = platform_device_register_resndata(NULL, 94 "leds-gpio", PLATFORM_DEVID_NONE, NULL, 0, 95 &simatic_ipc_gpio_leds_pdata, 96 sizeof(simatic_ipc_gpio_leds_pdata)); 97 if (IS_ERR(simatic_leds_pdev)) { 98 err = PTR_ERR(simatic_leds_pdev); 99 goto out; 100 } 101 102 /* PM_BIOS_BOOT_N */ 103 gpiod = gpiod_get_index(&simatic_leds_pdev->dev, NULL, 6, GPIOD_OUT_LOW); 104 if (IS_ERR(gpiod)) { 105 err = PTR_ERR(gpiod); 106 goto out; 107 } 108 gpiod_put(gpiod); 109 110 /* PM_WDT_OUT */ 111 gpiod = gpiod_get_index(&simatic_leds_pdev->dev, NULL, 7, GPIOD_OUT_LOW); 112 if (IS_ERR(gpiod)) { 113 err = PTR_ERR(gpiod); 114 goto out; 115 } 116 gpiod_put(gpiod); 117 118 return 0; 119out: 120 simatic_ipc_leds_gpio_remove(pdev); 121 122 return err; 123} 124 125static struct platform_driver simatic_ipc_led_gpio_driver = { 126 .probe = simatic_ipc_leds_gpio_probe, 127 .remove = simatic_ipc_leds_gpio_remove, 128 .driver = { 129 .name = KBUILD_MODNAME, 130 } 131}; 132module_platform_driver(simatic_ipc_led_gpio_driver); 133 134MODULE_LICENSE("GPL v2"); 135MODULE_ALIAS("platform:" KBUILD_MODNAME); 136MODULE_SOFTDEP("pre: platform:leds-gpio"); 137MODULE_AUTHOR("Henning Schild <henning.schild@siemens.com>");