Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * LEDs driver for PCEngines WRAP
0004  *
0005  * Copyright (C) 2006 Kristian Kielhofner <kris@krisk.org>
0006  *
0007  * Based on leds-net48xx.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/scx200_gpio.h>
0017 #include <linux/module.h>
0018 
0019 #define DRVNAME "wrap-led"
0020 #define WRAP_POWER_LED_GPIO 2
0021 #define WRAP_ERROR_LED_GPIO 3
0022 #define WRAP_EXTRA_LED_GPIO 18
0023 
0024 static struct platform_device *pdev;
0025 
0026 static void wrap_power_led_set(struct led_classdev *led_cdev,
0027         enum led_brightness value)
0028 {
0029     if (value)
0030         scx200_gpio_set_low(WRAP_POWER_LED_GPIO);
0031     else
0032         scx200_gpio_set_high(WRAP_POWER_LED_GPIO);
0033 }
0034 
0035 static void wrap_error_led_set(struct led_classdev *led_cdev,
0036         enum led_brightness value)
0037 {
0038     if (value)
0039         scx200_gpio_set_low(WRAP_ERROR_LED_GPIO);
0040     else
0041         scx200_gpio_set_high(WRAP_ERROR_LED_GPIO);
0042 }
0043 
0044 static void wrap_extra_led_set(struct led_classdev *led_cdev,
0045         enum led_brightness value)
0046 {
0047     if (value)
0048         scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO);
0049     else
0050         scx200_gpio_set_high(WRAP_EXTRA_LED_GPIO);
0051 }
0052 
0053 static struct led_classdev wrap_power_led = {
0054     .name           = "wrap::power",
0055     .brightness_set     = wrap_power_led_set,
0056     .default_trigger    = "default-on",
0057     .flags          = LED_CORE_SUSPENDRESUME,
0058 };
0059 
0060 static struct led_classdev wrap_error_led = {
0061     .name       = "wrap::error",
0062     .brightness_set = wrap_error_led_set,
0063     .flags          = LED_CORE_SUSPENDRESUME,
0064 };
0065 
0066 static struct led_classdev wrap_extra_led = {
0067     .name           = "wrap::extra",
0068     .brightness_set = wrap_extra_led_set,
0069     .flags          = LED_CORE_SUSPENDRESUME,
0070 };
0071 
0072 static int wrap_led_probe(struct platform_device *pdev)
0073 {
0074     int ret;
0075 
0076     ret = devm_led_classdev_register(&pdev->dev, &wrap_power_led);
0077     if (ret < 0)
0078         return ret;
0079 
0080     ret = devm_led_classdev_register(&pdev->dev, &wrap_error_led);
0081     if (ret < 0)
0082         return ret;
0083 
0084     return  devm_led_classdev_register(&pdev->dev, &wrap_extra_led);
0085 }
0086 
0087 static struct platform_driver wrap_led_driver = {
0088     .probe      = wrap_led_probe,
0089     .driver     = {
0090         .name       = DRVNAME,
0091     },
0092 };
0093 
0094 static int __init wrap_led_init(void)
0095 {
0096     int ret;
0097 
0098     if (!scx200_gpio_present()) {
0099         ret = -ENODEV;
0100         goto out;
0101     }
0102 
0103     ret = platform_driver_register(&wrap_led_driver);
0104     if (ret < 0)
0105         goto out;
0106 
0107     pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
0108     if (IS_ERR(pdev)) {
0109         ret = PTR_ERR(pdev);
0110         platform_driver_unregister(&wrap_led_driver);
0111         goto out;
0112     }
0113 
0114 out:
0115     return ret;
0116 }
0117 
0118 static void __exit wrap_led_exit(void)
0119 {
0120     platform_device_unregister(pdev);
0121     platform_driver_unregister(&wrap_led_driver);
0122 }
0123 
0124 module_init(wrap_led_init);
0125 module_exit(wrap_led_exit);
0126 
0127 MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>");
0128 MODULE_DESCRIPTION("PCEngines WRAP LED driver");
0129 MODULE_LICENSE("GPL");
0130