blob: 3c0c7aa63b8cdd1c0b4adbe00d68ec02537da9a2 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Ben Dooks54bdc472006-04-10 22:54:00 -07002/* 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
Ben Dooks54bdc472006-04-10 22:54:00 -07009*/
10
Ben Dooks54bdc472006-04-10 22:54:00 -070011#include <linux/kernel.h>
Ben Dooks54bdc472006-04-10 22:54:00 -070012#include <linux/platform_device.h>
13#include <linux/leds.h>
Linus Walleijf7f611f2020-07-08 09:11:49 +020014#include <linux/gpio/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Paul Gortmaker54f4ded2011-07-03 13:56:03 -040016#include <linux/module.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020017#include <linux/platform_data/leds-s3c24xx.h>
Ben Dooks54bdc472006-04-10 22:54:00 -070018
Ben Dooks54bdc472006-04-10 22:54:00 -070019/* our context */
20
21struct s3c24xx_gpio_led {
22 struct led_classdev cdev;
23 struct s3c24xx_led_platdata *pdata;
Linus Walleijf7f611f2020-07-08 09:11:49 +020024 struct gpio_desc *gpiod;
Ben Dooks54bdc472006-04-10 22:54:00 -070025};
26
Ben Dooks54bdc472006-04-10 22:54:00 -070027static inline struct s3c24xx_gpio_led *to_gpio(struct led_classdev *led_cdev)
28{
29 return container_of(led_cdev, struct s3c24xx_gpio_led, cdev);
30}
31
32static void s3c24xx_led_set(struct led_classdev *led_cdev,
33 enum led_brightness value)
34{
35 struct s3c24xx_gpio_led *led = to_gpio(led_cdev);
Ben Dooks54bdc472006-04-10 22:54:00 -070036
Linus Walleijf7f611f2020-07-08 09:11:49 +020037 gpiod_set_value(led->gpiod, !!value);
Ben Dooks54bdc472006-04-10 22:54:00 -070038}
39
Ben Dooks54bdc472006-04-10 22:54:00 -070040static int s3c24xx_led_probe(struct platform_device *dev)
41{
Jingoo Han87aae1e2013-07-30 01:07:35 -070042 struct s3c24xx_led_platdata *pdata = dev_get_platdata(&dev->dev);
Ben Dooks54bdc472006-04-10 22:54:00 -070043 struct s3c24xx_gpio_led *led;
44 int ret;
45
Sylwester Nawrocki7e97b582012-06-30 20:30:25 +080046 led = devm_kzalloc(&dev->dev, sizeof(struct s3c24xx_gpio_led),
47 GFP_KERNEL);
Xiubo Li0c9a03b2014-05-07 20:25:52 -070048 if (!led)
Ben Dooks54bdc472006-04-10 22:54:00 -070049 return -ENOMEM;
Ben Dooks54bdc472006-04-10 22:54:00 -070050
Ben Dooks54bdc472006-04-10 22:54:00 -070051 led->cdev.brightness_set = s3c24xx_led_set;
52 led->cdev.default_trigger = pdata->def_trigger;
53 led->cdev.name = pdata->name;
Richard Purdie859cb7f2009-01-08 17:55:03 +000054 led->cdev.flags |= LED_CORE_SUSPENDRESUME;
Ben Dooks54bdc472006-04-10 22:54:00 -070055
56 led->pdata = pdata;
57
Linus Walleijf7f611f2020-07-08 09:11:49 +020058 /* Default to off */
59 led->gpiod = devm_gpiod_get(&dev->dev, NULL, GPIOD_OUT_LOW);
60 if (IS_ERR(led->gpiod))
61 return PTR_ERR(led->gpiod);
Ben Dooks54bdc472006-04-10 22:54:00 -070062
63 /* register our new led device */
Amitoj Kaur Chawla48a70322016-03-09 08:53:57 +053064 ret = devm_led_classdev_register(&dev->dev, &led->cdev);
Sylwester Nawrocki7e97b582012-06-30 20:30:25 +080065 if (ret < 0)
Ben Dooks54bdc472006-04-10 22:54:00 -070066 dev_err(&dev->dev, "led_classdev_register failed\n");
Ben Dooks54bdc472006-04-10 22:54:00 -070067
Devendra Naga1522d022012-06-20 02:22:39 +080068 return ret;
Ben Dooks54bdc472006-04-10 22:54:00 -070069}
70
Ben Dooks54bdc472006-04-10 22:54:00 -070071static struct platform_driver s3c24xx_led_driver = {
72 .probe = s3c24xx_led_probe,
Ben Dooks54bdc472006-04-10 22:54:00 -070073 .driver = {
74 .name = "s3c24xx_led",
Ben Dooks54bdc472006-04-10 22:54:00 -070075 },
76};
77
Axel Lin892a8842012-01-10 15:09:24 -080078module_platform_driver(s3c24xx_led_driver);
Ben Dooks54bdc472006-04-10 22:54:00 -070079
80MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
81MODULE_DESCRIPTION("S3C24XX LED driver");
82MODULE_LICENSE("GPL");
Kay Sievers3c4ded92008-04-15 14:34:30 -070083MODULE_ALIAS("platform:s3c24xx_led");