1 // SPDX-License-Identifier: GPL-2.0-only
2 /* drivers/leds/leds-s3c24xx.c
4 * (c) 2006 Simtec Electronics
5 * http://armlinux.simtec.co.uk/
6 * Ben Dooks <ben@simtec.co.uk>
8 * S3C24XX - LEDs GPIO driver
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>
19 #include <mach/regs-gpio.h>
23 struct s3c24xx_gpio_led
{
24 struct led_classdev cdev
;
25 struct s3c24xx_led_platdata
*pdata
;
26 struct gpio_desc
*gpiod
;
29 static inline struct s3c24xx_gpio_led
*to_gpio(struct led_classdev
*led_cdev
)
31 return container_of(led_cdev
, struct s3c24xx_gpio_led
, cdev
);
34 static void s3c24xx_led_set(struct led_classdev
*led_cdev
,
35 enum led_brightness value
)
37 struct s3c24xx_gpio_led
*led
= to_gpio(led_cdev
);
39 gpiod_set_value(led
->gpiod
, !!value
);
42 static int s3c24xx_led_probe(struct platform_device
*dev
)
44 struct s3c24xx_led_platdata
*pdata
= dev_get_platdata(&dev
->dev
);
45 struct s3c24xx_gpio_led
*led
;
48 led
= devm_kzalloc(&dev
->dev
, sizeof(struct s3c24xx_gpio_led
),
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
;
61 led
->gpiod
= devm_gpiod_get(&dev
->dev
, NULL
, GPIOD_OUT_LOW
);
62 if (IS_ERR(led
->gpiod
))
63 return PTR_ERR(led
->gpiod
);
65 /* register our new led device */
66 ret
= devm_led_classdev_register(&dev
->dev
, &led
->cdev
);
68 dev_err(&dev
->dev
, "led_classdev_register failed\n");
73 static struct platform_driver s3c24xx_led_driver
= {
74 .probe
= s3c24xx_led_probe
,
76 .name
= "s3c24xx_led",
80 module_platform_driver(s3c24xx_led_driver
);
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");