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+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * LCD Backlight driver for RAVE SP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Copyright (C) 2018 Zodiac Inflight Innovations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  *
^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/backlight.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/mfd/rave-sp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define	RAVE_SP_BACKLIGHT_LCD_EN	BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static int rave_sp_backlight_update_status(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	const struct backlight_properties *p = &bd->props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	const u8 intensity =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 		(p->power == FB_BLANK_UNBLANK) ? p->brightness : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	struct rave_sp *sp = dev_get_drvdata(&bd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	u8 cmd[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 		[0] = RAVE_SP_CMD_SET_BACKLIGHT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 		[1] = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 		[2] = intensity ? RAVE_SP_BACKLIGHT_LCD_EN | intensity : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 		[3] = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 		[4] = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	return rave_sp_exec(sp, cmd, sizeof(cmd), NULL, 0);
^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 const struct backlight_ops rave_sp_backlight_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	.options	= BL_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	.update_status	= rave_sp_backlight_update_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static struct backlight_properties rave_sp_backlight_props = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	.type		= BACKLIGHT_PLATFORM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	.max_brightness = 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	.brightness	= 50,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static int rave_sp_backlight_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	struct backlight_device *bd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	bd = devm_backlight_device_register(dev, pdev->name, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 					    dev_get_drvdata(dev->parent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 					    &rave_sp_backlight_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 					    &rave_sp_backlight_props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	if (IS_ERR(bd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 		return PTR_ERR(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	 * If there is a phandle pointing to the device node we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	 * assume that another device will manage the status changes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	 * If not we make sure the backlight is in a consistent state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	if (!dev->of_node->phandle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 		backlight_update_status(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static const struct of_device_id rave_sp_backlight_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	{ .compatible = "zii,rave-sp-backlight" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static struct platform_driver rave_sp_backlight_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	.probe = rave_sp_backlight_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 		.name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 		.of_match_table = rave_sp_backlight_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) module_platform_driver(rave_sp_backlight_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) MODULE_DEVICE_TABLE(of, rave_sp_backlight_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) MODULE_AUTHOR("Andrey Vostrikov <andrey.vostrikov@cogentembedded.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) MODULE_AUTHOR("Nikita Yushchenko <nikita.yoush@cogentembedded.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) MODULE_DESCRIPTION("RAVE SP Backlight driver");