]> Git Repo - linux.git/blob - drivers/leds/simple/simatic-ipc-leds-gpio.c
Merge tag 'audit-pr-20221003' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoor...
[linux.git] / 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 <[email protected]>
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 <[email protected]>");
This page took 0.04028 seconds and 4 git commands to generate.