Merge tag 'dmaengine-5.3-rc1' of git://git.infradead.org/users/vkoul/slave-dma
[linux-2.6-microblaze.git] / drivers / leds / leds-s3c24xx.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* drivers/leds/leds-s3c24xx.c
3  *
4  * (c) 2006 Simtec Electronics
5  *      http://armlinux.simtec.co.uk/
6  *      Ben Dooks <ben@simtec.co.uk>
7  *
8  * S3C24XX - LEDs GPIO driver
9 */
10
11 #include <linux/kernel.h>
12 #include <linux/platform_device.h>
13 #include <linux/leds.h>
14 #include <linux/gpio.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
17 #include <linux/platform_data/leds-s3c24xx.h>
18
19 #include <mach/regs-gpio.h>
20 #include <plat/gpio-cfg.h>
21
22 /* our context */
23
24 struct s3c24xx_gpio_led {
25         struct led_classdev              cdev;
26         struct s3c24xx_led_platdata     *pdata;
27 };
28
29 static inline struct s3c24xx_gpio_led *to_gpio(struct led_classdev *led_cdev)
30 {
31         return container_of(led_cdev, struct s3c24xx_gpio_led, cdev);
32 }
33
34 static void s3c24xx_led_set(struct led_classdev *led_cdev,
35                             enum led_brightness value)
36 {
37         struct s3c24xx_gpio_led *led = to_gpio(led_cdev);
38         struct s3c24xx_led_platdata *pd = led->pdata;
39         int state = (value ? 1 : 0) ^ (pd->flags & S3C24XX_LEDF_ACTLOW);
40
41         /* there will be a short delay between setting the output and
42          * going from output to input when using tristate. */
43
44         gpio_set_value(pd->gpio, state);
45
46         if (pd->flags & S3C24XX_LEDF_TRISTATE) {
47                 if (value)
48                         gpio_direction_output(pd->gpio, state);
49                 else
50                         gpio_direction_input(pd->gpio);
51         }
52 }
53
54 static int s3c24xx_led_probe(struct platform_device *dev)
55 {
56         struct s3c24xx_led_platdata *pdata = dev_get_platdata(&dev->dev);
57         struct s3c24xx_gpio_led *led;
58         int ret;
59
60         led = devm_kzalloc(&dev->dev, sizeof(struct s3c24xx_gpio_led),
61                            GFP_KERNEL);
62         if (!led)
63                 return -ENOMEM;
64
65         led->cdev.brightness_set = s3c24xx_led_set;
66         led->cdev.default_trigger = pdata->def_trigger;
67         led->cdev.name = pdata->name;
68         led->cdev.flags |= LED_CORE_SUSPENDRESUME;
69
70         led->pdata = pdata;
71
72         ret = devm_gpio_request(&dev->dev, pdata->gpio, "S3C24XX_LED");
73         if (ret < 0)
74                 return ret;
75
76         /* no point in having a pull-up if we are always driving */
77
78         s3c_gpio_setpull(pdata->gpio, S3C_GPIO_PULL_NONE);
79
80         if (pdata->flags & S3C24XX_LEDF_TRISTATE)
81                 gpio_direction_input(pdata->gpio);
82         else
83                 gpio_direction_output(pdata->gpio,
84                         pdata->flags & S3C24XX_LEDF_ACTLOW ? 1 : 0);
85
86         /* register our new led device */
87
88         ret = devm_led_classdev_register(&dev->dev, &led->cdev);
89         if (ret < 0)
90                 dev_err(&dev->dev, "led_classdev_register failed\n");
91
92         return ret;
93 }
94
95 static struct platform_driver s3c24xx_led_driver = {
96         .probe          = s3c24xx_led_probe,
97         .driver         = {
98                 .name           = "s3c24xx_led",
99         },
100 };
101
102 module_platform_driver(s3c24xx_led_driver);
103
104 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
105 MODULE_DESCRIPTION("S3C24XX LED driver");
106 MODULE_LICENSE("GPL");
107 MODULE_ALIAS("platform:s3c24xx_led");