blob: 0d214c2e403c2a049ca9287f265312d93390da23 [file] [log] [blame]
Chris Boot1a87d942006-07-10 04:45:34 -07001/*
2 * LEDs driver for Soekris net48xx
3 *
4 * Copyright (C) 2006 Chris Boot <bootc@bootc.net>
5 *
6 * Based on leds-ams-delta.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 Kamat6023ff72012-11-25 12:14:13 +053018#include <linux/io.h>
Chris Bootcfedc922006-09-29 01:59:08 -070019#include <linux/nsc_gpio.h>
Chris Boot1a87d942006-07-10 04:45:34 -070020#include <linux/scx200_gpio.h>
Paul Gortmaker54f4ded2011-07-03 13:56:03 -040021#include <linux/module.h>
Chris Boot1a87d942006-07-10 04:45:34 -070022
Chris Bootbca3bff2006-07-14 00:24:21 -070023#define DRVNAME "net48xx-led"
Chris Boot1a87d942006-07-10 04:45:34 -070024#define NET48XX_ERROR_LED_GPIO 20
25
26static struct platform_device *pdev;
27
28static void net48xx_error_led_set(struct led_classdev *led_cdev,
29 enum led_brightness value)
30{
Chris Bootcfedc922006-09-29 01:59:08 -070031 scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
Chris Boot1a87d942006-07-10 04:45:34 -070032}
33
34static struct led_classdev net48xx_error_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010035 .name = "net48xx::error",
Chris Boot1a87d942006-07-10 04:45:34 -070036 .brightness_set = net48xx_error_led_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +000037 .flags = LED_CORE_SUSPENDRESUME,
Chris Boot1a87d942006-07-10 04:45:34 -070038};
39
Chris Boot1a87d942006-07-10 04:45:34 -070040static int net48xx_led_probe(struct platform_device *pdev)
41{
Muhammad Falak R Wani51167622015-10-17 05:02:57 +053042 return devm_led_classdev_register(&pdev->dev, &net48xx_error_led);
Chris Boot1a87d942006-07-10 04:45:34 -070043}
44
45static struct platform_driver net48xx_led_driver = {
Chris Boot1a87d942006-07-10 04:45:34 -070046 .probe = net48xx_led_probe,
Chris Boot1a87d942006-07-10 04:45:34 -070047 .driver = {
Chris Bootbca3bff2006-07-14 00:24:21 -070048 .name = DRVNAME,
Chris Boot1a87d942006-07-10 04:45:34 -070049 },
50};
51
52static int __init net48xx_led_init(void)
53{
54 int ret;
55
Chris Bootcfedc922006-09-29 01:59:08 -070056 /* small hack, but scx200_gpio doesn't set .dev if the probe fails */
57 if (!scx200_gpio_ops.dev) {
Chris Boot1a87d942006-07-10 04:45:34 -070058 ret = -ENODEV;
59 goto out;
60 }
61
62 ret = platform_driver_register(&net48xx_led_driver);
63 if (ret < 0)
64 goto out;
65
Chris Bootbca3bff2006-07-14 00:24:21 -070066 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
Chris Boot1a87d942006-07-10 04:45:34 -070067 if (IS_ERR(pdev)) {
68 ret = PTR_ERR(pdev);
69 platform_driver_unregister(&net48xx_led_driver);
70 goto out;
71 }
72
73out:
74 return ret;
75}
76
77static void __exit net48xx_led_exit(void)
78{
79 platform_device_unregister(pdev);
80 platform_driver_unregister(&net48xx_led_driver);
81}
82
83module_init(net48xx_led_init);
84module_exit(net48xx_led_exit);
85
86MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
87MODULE_DESCRIPTION("Soekris net48xx LED driver");
88MODULE_LICENSE("GPL");
89