blob: a93468c13772f878e1b0ca76fa37b53dc1bf70cf [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Chris Boot1a87d942006-07-10 04:45:34 -07002/*
3 * LEDs driver for Soekris net48xx
4 *
5 * Copyright (C) 2006 Chris Boot <bootc@bootc.net>
6 *
7 * Based on leds-ams-delta.c
Chris Boot1a87d942006-07-10 04:45:34 -07008 */
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 Kamat6023ff72012-11-25 12:14:13 +053015#include <linux/io.h>
Chris Bootcfedc922006-09-29 01:59:08 -070016#include <linux/nsc_gpio.h>
Chris Boot1a87d942006-07-10 04:45:34 -070017#include <linux/scx200_gpio.h>
Paul Gortmaker54f4ded2011-07-03 13:56:03 -040018#include <linux/module.h>
Chris Boot1a87d942006-07-10 04:45:34 -070019
Chris Bootbca3bff2006-07-14 00:24:21 -070020#define DRVNAME "net48xx-led"
Chris Boot1a87d942006-07-10 04:45:34 -070021#define NET48XX_ERROR_LED_GPIO 20
22
23static struct platform_device *pdev;
24
25static void net48xx_error_led_set(struct led_classdev *led_cdev,
26 enum led_brightness value)
27{
Chris Bootcfedc922006-09-29 01:59:08 -070028 scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
Chris Boot1a87d942006-07-10 04:45:34 -070029}
30
31static struct led_classdev net48xx_error_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010032 .name = "net48xx::error",
Chris Boot1a87d942006-07-10 04:45:34 -070033 .brightness_set = net48xx_error_led_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +000034 .flags = LED_CORE_SUSPENDRESUME,
Chris Boot1a87d942006-07-10 04:45:34 -070035};
36
Chris Boot1a87d942006-07-10 04:45:34 -070037static int net48xx_led_probe(struct platform_device *pdev)
38{
Muhammad Falak R Wani51167622015-10-17 05:02:57 +053039 return devm_led_classdev_register(&pdev->dev, &net48xx_error_led);
Chris Boot1a87d942006-07-10 04:45:34 -070040}
41
42static struct platform_driver net48xx_led_driver = {
Chris Boot1a87d942006-07-10 04:45:34 -070043 .probe = net48xx_led_probe,
Chris Boot1a87d942006-07-10 04:45:34 -070044 .driver = {
Chris Bootbca3bff2006-07-14 00:24:21 -070045 .name = DRVNAME,
Chris Boot1a87d942006-07-10 04:45:34 -070046 },
47};
48
49static int __init net48xx_led_init(void)
50{
51 int ret;
52
Chris Bootcfedc922006-09-29 01:59:08 -070053 /* small hack, but scx200_gpio doesn't set .dev if the probe fails */
54 if (!scx200_gpio_ops.dev) {
Chris Boot1a87d942006-07-10 04:45:34 -070055 ret = -ENODEV;
56 goto out;
57 }
58
59 ret = platform_driver_register(&net48xx_led_driver);
60 if (ret < 0)
61 goto out;
62
Chris Bootbca3bff2006-07-14 00:24:21 -070063 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
Chris Boot1a87d942006-07-10 04:45:34 -070064 if (IS_ERR(pdev)) {
65 ret = PTR_ERR(pdev);
66 platform_driver_unregister(&net48xx_led_driver);
67 goto out;
68 }
69
70out:
71 return ret;
72}
73
74static void __exit net48xx_led_exit(void)
75{
76 platform_device_unregister(pdev);
77 platform_driver_unregister(&net48xx_led_driver);
78}
79
80module_init(net48xx_led_init);
81module_exit(net48xx_led_exit);
82
83MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
84MODULE_DESCRIPTION("Soekris net48xx LED driver");
85MODULE_LICENSE("GPL");
86