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.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>
20 #include <plat/gpio-cfg.h>
24 struct s3c24xx_gpio_led
{
25 struct led_classdev cdev
;
26 struct s3c24xx_led_platdata
*pdata
;
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
);
38 struct s3c24xx_led_platdata
*pd
= led
->pdata
;
39 int state
= (value
? 1 : 0) ^ (pd
->flags
& S3C24XX_LEDF_ACTLOW
);
41 /* there will be a short delay between setting the output and
42 * going from output to input when using tristate. */
44 gpio_set_value(pd
->gpio
, state
);
46 if (pd
->flags
& S3C24XX_LEDF_TRISTATE
) {
48 gpio_direction_output(pd
->gpio
, state
);
50 gpio_direction_input(pd
->gpio
);
54 static int s3c24xx_led_probe(struct platform_device
*dev
)
56 struct s3c24xx_led_platdata
*pdata
= dev_get_platdata(&dev
->dev
);
57 struct s3c24xx_gpio_led
*led
;
60 led
= devm_kzalloc(&dev
->dev
, sizeof(struct s3c24xx_gpio_led
),
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
;
72 ret
= devm_gpio_request(&dev
->dev
, pdata
->gpio
, "S3C24XX_LED");
76 /* no point in having a pull-up if we are always driving */
78 s3c_gpio_setpull(pdata
->gpio
, S3C_GPIO_PULL_NONE
);
80 if (pdata
->flags
& S3C24XX_LEDF_TRISTATE
)
81 gpio_direction_input(pdata
->gpio
);
83 gpio_direction_output(pdata
->gpio
,
84 pdata
->flags
& S3C24XX_LEDF_ACTLOW
? 1 : 0);
86 /* register our new led device */
88 ret
= devm_led_classdev_register(&dev
->dev
, &led
->cdev
);
90 dev_err(&dev
->dev
, "led_classdev_register failed\n");
95 static struct platform_driver s3c24xx_led_driver
= {
96 .probe
= s3c24xx_led_probe
,
98 .name
= "s3c24xx_led",
102 module_platform_driver(s3c24xx_led_driver
);
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");