Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * LEDs driver for PCEngines WRAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2006 Kristian Kielhofner <kris@krisk.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Based on leds-net48xx.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/scx200_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define DRVNAME "wrap-led"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define WRAP_POWER_LED_GPIO	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define WRAP_ERROR_LED_GPIO	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define WRAP_EXTRA_LED_GPIO	18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static void wrap_power_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		scx200_gpio_set_low(WRAP_POWER_LED_GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		scx200_gpio_set_high(WRAP_POWER_LED_GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static void wrap_error_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		scx200_gpio_set_low(WRAP_ERROR_LED_GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		scx200_gpio_set_high(WRAP_ERROR_LED_GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static void wrap_extra_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		scx200_gpio_set_high(WRAP_EXTRA_LED_GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static struct led_classdev wrap_power_led = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.name			= "wrap::power",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.brightness_set		= wrap_power_led_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.default_trigger	= "default-on",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.flags			= LED_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static struct led_classdev wrap_error_led = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	.name		= "wrap::error",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	.brightness_set	= wrap_error_led_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.flags			= LED_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static struct led_classdev wrap_extra_led = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	.name           = "wrap::extra",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	.brightness_set = wrap_extra_led_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	.flags			= LED_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static int wrap_led_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	ret = devm_led_classdev_register(&pdev->dev, &wrap_power_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	ret = devm_led_classdev_register(&pdev->dev, &wrap_error_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	return  devm_led_classdev_register(&pdev->dev, &wrap_extra_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static struct platform_driver wrap_led_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	.probe		= wrap_led_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		.name		= DRVNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static int __init wrap_led_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (!scx200_gpio_present()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	ret = platform_driver_register(&wrap_led_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (IS_ERR(pdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		ret = PTR_ERR(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		platform_driver_unregister(&wrap_led_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static void __exit wrap_led_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	platform_device_unregister(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	platform_driver_unregister(&wrap_led_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) module_init(wrap_led_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) module_exit(wrap_led_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) MODULE_DESCRIPTION("PCEngines WRAP LED driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)