Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * LEDs driver for Soekris net48xx
0004  *
0005  * Copyright (C) 2006 Chris Boot <bootc@bootc.net>
0006  *
0007  * Based on leds-ams-delta.c
0008  */
0009 
0010 #include <linux/kernel.h>
0011 #include <linux/init.h>
0012 #include <linux/platform_device.h>
0013 #include <linux/leds.h>
0014 #include <linux/err.h>
0015 #include <linux/io.h>
0016 #include <linux/nsc_gpio.h>
0017 #include <linux/scx200_gpio.h>
0018 #include <linux/module.h>
0019 
0020 #define DRVNAME "net48xx-led"
0021 #define NET48XX_ERROR_LED_GPIO  20
0022 
0023 static struct platform_device *pdev;
0024 
0025 static void net48xx_error_led_set(struct led_classdev *led_cdev,
0026         enum led_brightness value)
0027 {
0028     scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
0029 }
0030 
0031 static struct led_classdev net48xx_error_led = {
0032     .name       = "net48xx::error",
0033     .brightness_set = net48xx_error_led_set,
0034     .flags      = LED_CORE_SUSPENDRESUME,
0035 };
0036 
0037 static int net48xx_led_probe(struct platform_device *pdev)
0038 {
0039     return devm_led_classdev_register(&pdev->dev, &net48xx_error_led);
0040 }
0041 
0042 static struct platform_driver net48xx_led_driver = {
0043     .probe      = net48xx_led_probe,
0044     .driver     = {
0045         .name       = DRVNAME,
0046     },
0047 };
0048 
0049 static int __init net48xx_led_init(void)
0050 {
0051     int ret;
0052 
0053     /* small hack, but scx200_gpio doesn't set .dev if the probe fails */
0054     if (!scx200_gpio_ops.dev) {
0055         ret = -ENODEV;
0056         goto out;
0057     }
0058 
0059     ret = platform_driver_register(&net48xx_led_driver);
0060     if (ret < 0)
0061         goto out;
0062 
0063     pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
0064     if (IS_ERR(pdev)) {
0065         ret = PTR_ERR(pdev);
0066         platform_driver_unregister(&net48xx_led_driver);
0067         goto out;
0068     }
0069 
0070 out:
0071     return ret;
0072 }
0073 
0074 static void __exit net48xx_led_exit(void)
0075 {
0076     platform_device_unregister(pdev);
0077     platform_driver_unregister(&net48xx_led_driver);
0078 }
0079 
0080 module_init(net48xx_led_init);
0081 module_exit(net48xx_led_exit);
0082 
0083 MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
0084 MODULE_DESCRIPTION("Soekris net48xx LED driver");
0085 MODULE_LICENSE("GPL");
0086