Linux Audio

Check our new training course

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