blob: 473fb6b97ed4f5f5ca86710f9b0afbfbaefa6ff3 [file] [log] [blame]
Kristian Kielhofner0d755652006-12-06 20:37:28 -08001/*
2 * LEDs driver for PCEngines WRAP
3 *
4 * Copyright (C) 2006 Kristian Kielhofner <kris@krisk.org>
5 *
6 * Based on leds-net48xx.c
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
16#include <linux/leds.h>
17#include <linux/err.h>
Sachin Kamat572dc622012-11-25 12:48:32 +053018#include <linux/io.h>
Kristian Kielhofner0d755652006-12-06 20:37:28 -080019#include <linux/scx200_gpio.h>
Paul Gortmaker54f4ded2011-07-03 13:56:03 -040020#include <linux/module.h>
Kristian Kielhofner0d755652006-12-06 20:37:28 -080021
22#define DRVNAME "wrap-led"
Michael Loefflerf5506a22008-01-13 23:20:52 +000023#define WRAP_POWER_LED_GPIO 2
Kristian Kielhofner0d755652006-12-06 20:37:28 -080024#define WRAP_ERROR_LED_GPIO 3
Michael Loefflerf5506a22008-01-13 23:20:52 +000025#define WRAP_EXTRA_LED_GPIO 18
Kristian Kielhofner0d755652006-12-06 20:37:28 -080026
27static struct platform_device *pdev;
28
Michael Loefflerf5506a22008-01-13 23:20:52 +000029static void wrap_power_led_set(struct led_classdev *led_cdev,
30 enum led_brightness value)
31{
32 if (value)
33 scx200_gpio_set_low(WRAP_POWER_LED_GPIO);
34 else
35 scx200_gpio_set_high(WRAP_POWER_LED_GPIO);
36}
37
Kristian Kielhofner0d755652006-12-06 20:37:28 -080038static void wrap_error_led_set(struct led_classdev *led_cdev,
39 enum led_brightness value)
40{
41 if (value)
42 scx200_gpio_set_low(WRAP_ERROR_LED_GPIO);
43 else
44 scx200_gpio_set_high(WRAP_ERROR_LED_GPIO);
45}
46
47static void wrap_extra_led_set(struct led_classdev *led_cdev,
48 enum led_brightness value)
49{
50 if (value)
51 scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO);
52 else
53 scx200_gpio_set_high(WRAP_EXTRA_LED_GPIO);
54}
55
Michael Loefflerf5506a22008-01-13 23:20:52 +000056static struct led_classdev wrap_power_led = {
Sven Wegener6af4f552008-10-13 10:43:47 +010057 .name = "wrap::power",
58 .brightness_set = wrap_power_led_set,
59 .default_trigger = "default-on",
Richard Purdie859cb7f2009-01-08 17:55:03 +000060 .flags = LED_CORE_SUSPENDRESUME,
Michael Loefflerf5506a22008-01-13 23:20:52 +000061};
62
Kristian Kielhofner0d755652006-12-06 20:37:28 -080063static struct led_classdev wrap_error_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010064 .name = "wrap::error",
Kristian Kielhofner0d755652006-12-06 20:37:28 -080065 .brightness_set = wrap_error_led_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +000066 .flags = LED_CORE_SUSPENDRESUME,
Kristian Kielhofner0d755652006-12-06 20:37:28 -080067};
68
69static struct led_classdev wrap_extra_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010070 .name = "wrap::extra",
Kristian Kielhofner0d755652006-12-06 20:37:28 -080071 .brightness_set = wrap_extra_led_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +000072 .flags = LED_CORE_SUSPENDRESUME,
Kristian Kielhofner0d755652006-12-06 20:37:28 -080073};
74
Kristian Kielhofner0d755652006-12-06 20:37:28 -080075static int wrap_led_probe(struct platform_device *pdev)
76{
77 int ret;
78
Fida Mohammade9aadb82015-10-21 03:58:35 -070079 ret = devm_led_classdev_register(&pdev->dev, &wrap_power_led);
Michael Loefflerf5506a22008-01-13 23:20:52 +000080 if (ret < 0)
81 return ret;
82
Fida Mohammade9aadb82015-10-21 03:58:35 -070083 ret = devm_led_classdev_register(&pdev->dev, &wrap_error_led);
Michael Loefflerf5506a22008-01-13 23:20:52 +000084 if (ret < 0)
Fida Mohammade9aadb82015-10-21 03:58:35 -070085 return ret;
Michael Loefflerf5506a22008-01-13 23:20:52 +000086
Fida Mohammade9aadb82015-10-21 03:58:35 -070087 return devm_led_classdev_register(&pdev->dev, &wrap_extra_led);
Kristian Kielhofner0d755652006-12-06 20:37:28 -080088}
89
90static struct platform_driver wrap_led_driver = {
91 .probe = wrap_led_probe,
Kristian Kielhofner0d755652006-12-06 20:37:28 -080092 .driver = {
93 .name = DRVNAME,
Kristian Kielhofner0d755652006-12-06 20:37:28 -080094 },
95};
96
97static int __init wrap_led_init(void)
98{
99 int ret;
100
101 if (!scx200_gpio_present()) {
102 ret = -ENODEV;
103 goto out;
104 }
105
106 ret = platform_driver_register(&wrap_led_driver);
107 if (ret < 0)
108 goto out;
109
110 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
111 if (IS_ERR(pdev)) {
112 ret = PTR_ERR(pdev);
113 platform_driver_unregister(&wrap_led_driver);
114 goto out;
115 }
116
117out:
118 return ret;
119}
120
121static void __exit wrap_led_exit(void)
122{
123 platform_device_unregister(pdev);
124 platform_driver_unregister(&wrap_led_driver);
125}
126
127module_init(wrap_led_init);
128module_exit(wrap_led_exit);
129
130MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>");
131MODULE_DESCRIPTION("PCEngines WRAP LED driver");
132MODULE_LICENSE("GPL");
133