blob: 054360473c9490ea6e4251188dcbf4cad92fa310 [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>
18#include <asm/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>
21
Chris Bootbca3bff2006-07-14 00:24:21 -070022#define DRVNAME "net48xx-led"
Chris Boot1a87d942006-07-10 04:45:34 -070023#define NET48XX_ERROR_LED_GPIO 20
24
25static struct platform_device *pdev;
26
27static void net48xx_error_led_set(struct led_classdev *led_cdev,
28 enum led_brightness value)
29{
Chris Bootcfedc922006-09-29 01:59:08 -070030 scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
Chris Boot1a87d942006-07-10 04:45:34 -070031}
32
33static struct led_classdev net48xx_error_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010034 .name = "net48xx::error",
Chris Boot1a87d942006-07-10 04:45:34 -070035 .brightness_set = net48xx_error_led_set,
36};
37
38#ifdef CONFIG_PM
39static int net48xx_led_suspend(struct platform_device *dev,
40 pm_message_t state)
41{
42 led_classdev_suspend(&net48xx_error_led);
43 return 0;
44}
45
46static int net48xx_led_resume(struct platform_device *dev)
47{
48 led_classdev_resume(&net48xx_error_led);
49 return 0;
50}
51#else
52#define net48xx_led_suspend NULL
53#define net48xx_led_resume NULL
54#endif
55
56static int net48xx_led_probe(struct platform_device *pdev)
57{
58 return led_classdev_register(&pdev->dev, &net48xx_error_led);
59}
60
61static int net48xx_led_remove(struct platform_device *pdev)
62{
63 led_classdev_unregister(&net48xx_error_led);
64 return 0;
65}
66
67static struct platform_driver net48xx_led_driver = {
Chris Boot1a87d942006-07-10 04:45:34 -070068 .probe = net48xx_led_probe,
69 .remove = net48xx_led_remove,
70 .suspend = net48xx_led_suspend,
71 .resume = net48xx_led_resume,
72 .driver = {
Chris Bootbca3bff2006-07-14 00:24:21 -070073 .name = DRVNAME,
74 .owner = THIS_MODULE,
Chris Boot1a87d942006-07-10 04:45:34 -070075 },
76};
77
78static int __init net48xx_led_init(void)
79{
80 int ret;
81
Chris Bootcfedc922006-09-29 01:59:08 -070082 /* small hack, but scx200_gpio doesn't set .dev if the probe fails */
83 if (!scx200_gpio_ops.dev) {
Chris Boot1a87d942006-07-10 04:45:34 -070084 ret = -ENODEV;
85 goto out;
86 }
87
88 ret = platform_driver_register(&net48xx_led_driver);
89 if (ret < 0)
90 goto out;
91
Chris Bootbca3bff2006-07-14 00:24:21 -070092 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
Chris Boot1a87d942006-07-10 04:45:34 -070093 if (IS_ERR(pdev)) {
94 ret = PTR_ERR(pdev);
95 platform_driver_unregister(&net48xx_led_driver);
96 goto out;
97 }
98
99out:
100 return ret;
101}
102
103static void __exit net48xx_led_exit(void)
104{
105 platform_device_unregister(pdev);
106 platform_driver_unregister(&net48xx_led_driver);
107}
108
109module_init(net48xx_led_init);
110module_exit(net48xx_led_exit);
111
112MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
113MODULE_DESCRIPTION("Soekris net48xx LED driver");
114MODULE_LICENSE("GPL");
115