]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/leds/leds-s3c24xx.c
Merge tag 'for-5.9/block-merge-20200804' of git://git.kernel.dk/linux-block
[mirror_ubuntu-jammy-kernel.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/consumer.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
21 /* our context */
22
23 struct s3c24xx_gpio_led {
24 struct led_classdev cdev;
25 struct s3c24xx_led_platdata *pdata;
26 struct gpio_desc *gpiod;
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
39 gpiod_set_value(led->gpiod, !!value);
40 }
41
42 static int s3c24xx_led_probe(struct platform_device *dev)
43 {
44 struct s3c24xx_led_platdata *pdata = dev_get_platdata(&dev->dev);
45 struct s3c24xx_gpio_led *led;
46 int ret;
47
48 led = devm_kzalloc(&dev->dev, sizeof(struct s3c24xx_gpio_led),
49 GFP_KERNEL);
50 if (!led)
51 return -ENOMEM;
52
53 led->cdev.brightness_set = s3c24xx_led_set;
54 led->cdev.default_trigger = pdata->def_trigger;
55 led->cdev.name = pdata->name;
56 led->cdev.flags |= LED_CORE_SUSPENDRESUME;
57
58 led->pdata = pdata;
59
60 /* Default to off */
61 led->gpiod = devm_gpiod_get(&dev->dev, NULL, GPIOD_OUT_LOW);
62 if (IS_ERR(led->gpiod))
63 return PTR_ERR(led->gpiod);
64
65 /* register our new led device */
66 ret = devm_led_classdev_register(&dev->dev, &led->cdev);
67 if (ret < 0)
68 dev_err(&dev->dev, "led_classdev_register failed\n");
69
70 return ret;
71 }
72
73 static struct platform_driver s3c24xx_led_driver = {
74 .probe = s3c24xx_led_probe,
75 .driver = {
76 .name = "s3c24xx_led",
77 },
78 };
79
80 module_platform_driver(s3c24xx_led_driver);
81
82 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
83 MODULE_DESCRIPTION("S3C24XX LED driver");
84 MODULE_LICENSE("GPL");
85 MODULE_ALIAS("platform:s3c24xx_led");