blob: 794697e160685cbfd8ccb381f9e814880f62965d [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Kristian Kielhofner0d755652006-12-06 20:37:28 -08002/*
3 * LEDs driver for PCEngines WRAP
4 *
5 * Copyright (C) 2006 Kristian Kielhofner <kris@krisk.org>
6 *
7 * Based on leds-net48xx.c
Kristian Kielhofner0d755652006-12-06 20:37:28 -08008 */
9
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/platform_device.h>
13#include <linux/leds.h>
14#include <linux/err.h>
Sachin Kamat572dc622012-11-25 12:48:32 +053015#include <linux/io.h>
Kristian Kielhofner0d755652006-12-06 20:37:28 -080016#include <linux/scx200_gpio.h>
Paul Gortmaker54f4ded2011-07-03 13:56:03 -040017#include <linux/module.h>
Kristian Kielhofner0d755652006-12-06 20:37:28 -080018
19#define DRVNAME "wrap-led"
Michael Loefflerf5506a22008-01-13 23:20:52 +000020#define WRAP_POWER_LED_GPIO 2
Kristian Kielhofner0d755652006-12-06 20:37:28 -080021#define WRAP_ERROR_LED_GPIO 3
Michael Loefflerf5506a22008-01-13 23:20:52 +000022#define WRAP_EXTRA_LED_GPIO 18
Kristian Kielhofner0d755652006-12-06 20:37:28 -080023
24static struct platform_device *pdev;
25
Michael Loefflerf5506a22008-01-13 23:20:52 +000026static void wrap_power_led_set(struct led_classdev *led_cdev,
27 enum led_brightness value)
28{
29 if (value)
30 scx200_gpio_set_low(WRAP_POWER_LED_GPIO);
31 else
32 scx200_gpio_set_high(WRAP_POWER_LED_GPIO);
33}
34
Kristian Kielhofner0d755652006-12-06 20:37:28 -080035static void wrap_error_led_set(struct led_classdev *led_cdev,
36 enum led_brightness value)
37{
38 if (value)
39 scx200_gpio_set_low(WRAP_ERROR_LED_GPIO);
40 else
41 scx200_gpio_set_high(WRAP_ERROR_LED_GPIO);
42}
43
44static void wrap_extra_led_set(struct led_classdev *led_cdev,
45 enum led_brightness value)
46{
47 if (value)
48 scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO);
49 else
50 scx200_gpio_set_high(WRAP_EXTRA_LED_GPIO);
51}
52
Michael Loefflerf5506a22008-01-13 23:20:52 +000053static struct led_classdev wrap_power_led = {
Sven Wegener6af4f552008-10-13 10:43:47 +010054 .name = "wrap::power",
55 .brightness_set = wrap_power_led_set,
56 .default_trigger = "default-on",
Richard Purdie859cb7f2009-01-08 17:55:03 +000057 .flags = LED_CORE_SUSPENDRESUME,
Michael Loefflerf5506a22008-01-13 23:20:52 +000058};
59
Kristian Kielhofner0d755652006-12-06 20:37:28 -080060static struct led_classdev wrap_error_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010061 .name = "wrap::error",
Kristian Kielhofner0d755652006-12-06 20:37:28 -080062 .brightness_set = wrap_error_led_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +000063 .flags = LED_CORE_SUSPENDRESUME,
Kristian Kielhofner0d755652006-12-06 20:37:28 -080064};
65
66static struct led_classdev wrap_extra_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010067 .name = "wrap::extra",
Kristian Kielhofner0d755652006-12-06 20:37:28 -080068 .brightness_set = wrap_extra_led_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +000069 .flags = LED_CORE_SUSPENDRESUME,
Kristian Kielhofner0d755652006-12-06 20:37:28 -080070};
71
Kristian Kielhofner0d755652006-12-06 20:37:28 -080072static int wrap_led_probe(struct platform_device *pdev)
73{
74 int ret;
75
Fida Mohammade9aadb82015-10-21 03:58:35 -070076 ret = devm_led_classdev_register(&pdev->dev, &wrap_power_led);
Michael Loefflerf5506a22008-01-13 23:20:52 +000077 if (ret < 0)
78 return ret;
79
Fida Mohammade9aadb82015-10-21 03:58:35 -070080 ret = devm_led_classdev_register(&pdev->dev, &wrap_error_led);
Michael Loefflerf5506a22008-01-13 23:20:52 +000081 if (ret < 0)
Fida Mohammade9aadb82015-10-21 03:58:35 -070082 return ret;
Michael Loefflerf5506a22008-01-13 23:20:52 +000083
Fida Mohammade9aadb82015-10-21 03:58:35 -070084 return devm_led_classdev_register(&pdev->dev, &wrap_extra_led);
Kristian Kielhofner0d755652006-12-06 20:37:28 -080085}
86
87static struct platform_driver wrap_led_driver = {
88 .probe = wrap_led_probe,
Kristian Kielhofner0d755652006-12-06 20:37:28 -080089 .driver = {
90 .name = DRVNAME,
Kristian Kielhofner0d755652006-12-06 20:37:28 -080091 },
92};
93
94static int __init wrap_led_init(void)
95{
96 int ret;
97
98 if (!scx200_gpio_present()) {
99 ret = -ENODEV;
100 goto out;
101 }
102
103 ret = platform_driver_register(&wrap_led_driver);
104 if (ret < 0)
105 goto out;
106
107 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
108 if (IS_ERR(pdev)) {
109 ret = PTR_ERR(pdev);
110 platform_driver_unregister(&wrap_led_driver);
111 goto out;
112 }
113
114out:
115 return ret;
116}
117
118static void __exit wrap_led_exit(void)
119{
120 platform_device_unregister(pdev);
121 platform_driver_unregister(&wrap_led_driver);
122}
123
124module_init(wrap_led_init);
125module_exit(wrap_led_exit);
126
127MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>");
128MODULE_DESCRIPTION("PCEngines WRAP LED driver");
129MODULE_LICENSE("GPL");
130