Linux Audio

Check our new training course

Loading...
v3.1
 1/*
 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>
19#include <linux/nsc_gpio.h>
20#include <linux/scx200_gpio.h>
 
21
22#define DRVNAME "net48xx-led"
23#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{
30	scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
31}
32
33static struct led_classdev net48xx_error_led = {
34	.name		= "net48xx::error",
35	.brightness_set	= net48xx_error_led_set,
36	.flags		= LED_CORE_SUSPENDRESUME,
37};
38
39static int net48xx_led_probe(struct platform_device *pdev)
40{
41	return led_classdev_register(&pdev->dev, &net48xx_error_led);
42}
43
44static int net48xx_led_remove(struct platform_device *pdev)
45{
46	led_classdev_unregister(&net48xx_error_led);
47	return 0;
48}
49
50static struct platform_driver net48xx_led_driver = {
51	.probe		= net48xx_led_probe,
52	.remove		= net48xx_led_remove,
53	.driver		= {
54		.name		= DRVNAME,
55		.owner		= THIS_MODULE,
56	},
57};
58
59static int __init net48xx_led_init(void)
60{
61	int ret;
62
63	/* small hack, but scx200_gpio doesn't set .dev if the probe fails */
64	if (!scx200_gpio_ops.dev) {
65		ret = -ENODEV;
66		goto out;
67	}
68
69	ret = platform_driver_register(&net48xx_led_driver);
70	if (ret < 0)
71		goto out;
72
73	pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
74	if (IS_ERR(pdev)) {
75		ret = PTR_ERR(pdev);
76		platform_driver_unregister(&net48xx_led_driver);
77		goto out;
78	}
79
80out:
81	return ret;
82}
83
84static void __exit net48xx_led_exit(void)
85{
86	platform_device_unregister(pdev);
87	platform_driver_unregister(&net48xx_led_driver);
88}
89
90module_init(net48xx_led_init);
91module_exit(net48xx_led_exit);
92
93MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
94MODULE_DESCRIPTION("Soekris net48xx LED driver");
95MODULE_LICENSE("GPL");
96
v4.17
 1/*
 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 <linux/io.h>
19#include <linux/nsc_gpio.h>
20#include <linux/scx200_gpio.h>
21#include <linux/module.h>
22
23#define DRVNAME "net48xx-led"
24#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{
31	scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
32}
33
34static struct led_classdev net48xx_error_led = {
35	.name		= "net48xx::error",
36	.brightness_set	= net48xx_error_led_set,
37	.flags		= LED_CORE_SUSPENDRESUME,
38};
39
40static int net48xx_led_probe(struct platform_device *pdev)
41{
42	return devm_led_classdev_register(&pdev->dev, &net48xx_error_led);
 
 
 
 
 
 
43}
44
45static struct platform_driver net48xx_led_driver = {
46	.probe		= net48xx_led_probe,
 
47	.driver		= {
48		.name		= DRVNAME,
 
49	},
50};
51
52static int __init net48xx_led_init(void)
53{
54	int ret;
55
56	/* small hack, but scx200_gpio doesn't set .dev if the probe fails */
57	if (!scx200_gpio_ops.dev) {
58		ret = -ENODEV;
59		goto out;
60	}
61
62	ret = platform_driver_register(&net48xx_led_driver);
63	if (ret < 0)
64		goto out;
65
66	pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
67	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