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)  *  Backlight Driver for the KB3886 Backlight
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (c) 2007-2008 Claudio Nieder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Based on corgi_bl.c by Richard Purdie and kb3886 driver by Robert Woerle
^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/module.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/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/backlight.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define KB3886_PARENT 0x64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define KB3886_IO 0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define KB3886_ADC_DAC_PWM 0xC4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define KB3886_PWM0_WRITE 0x81
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define KB3886_PWM0_READ 0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static DEFINE_MUTEX(bl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static void kb3886_bl_set_intensity(int intensity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	mutex_lock(&bl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	intensity = intensity&0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	outb(KB3886_ADC_DAC_PWM, KB3886_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	usleep_range(10000, 11000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	outb(KB3886_PWM0_WRITE, KB3886_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	usleep_range(10000, 11000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	outb(intensity, KB3886_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	mutex_unlock(&bl_mutex);
^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) struct kb3886bl_machinfo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int max_intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	int default_intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	int limit_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	void (*set_bl_intensity)(int intensity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static struct kb3886bl_machinfo kb3886_bl_machinfo = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.max_intensity = 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.default_intensity = 0xa0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.limit_mask = 0x7f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.set_bl_intensity = kb3886_bl_set_intensity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static struct platform_device kb3886bl_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.name		= "kb3886-bl",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.dev		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		.platform_data	= &kb3886_bl_machinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	.id		= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static struct platform_device *devices[] __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	&kb3886bl_device,
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * Back to driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static int kb3886bl_intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static struct backlight_device *kb3886_backlight_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static struct kb3886bl_machinfo *bl_machinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static unsigned long kb3886bl_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define KB3886BL_SUSPENDED     0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		.ident = "Sahara Touch-iT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		.matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			DMI_MATCH(DMI_SYS_VENDOR, "SDV"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			DMI_MATCH(DMI_PRODUCT_NAME, "iTouch T201"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	},
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static int kb3886bl_send_intensity(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int intensity = backlight_get_brightness(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (kb3886bl_flags & KB3886BL_SUSPENDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		intensity = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	bl_machinfo->set_bl_intensity(intensity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	kb3886bl_intensity = intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int kb3886bl_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct backlight_device *bd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	kb3886bl_flags |= KB3886BL_SUSPENDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	backlight_update_status(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int kb3886bl_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct backlight_device *bd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	kb3886bl_flags &= ~KB3886BL_SUSPENDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	backlight_update_status(bd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static SIMPLE_DEV_PM_OPS(kb3886bl_pm_ops, kb3886bl_suspend, kb3886bl_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int kb3886bl_get_intensity(struct backlight_device *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	return kb3886bl_intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static const struct backlight_ops kb3886bl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	.get_brightness = kb3886bl_get_intensity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	.update_status  = kb3886bl_send_intensity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int kb3886bl_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct backlight_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct kb3886bl_machinfo *machinfo = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	bl_machinfo = machinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (!machinfo->limit_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		machinfo->limit_mask = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	memset(&props, 0, sizeof(struct backlight_properties));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	props.type = BACKLIGHT_RAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	props.max_brightness = machinfo->max_intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	kb3886_backlight_device = devm_backlight_device_register(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 							"kb3886-bl", &pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 							NULL, &kb3886bl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 							&props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (IS_ERR(kb3886_backlight_device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return PTR_ERR(kb3886_backlight_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	platform_set_drvdata(pdev, kb3886_backlight_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	kb3886_backlight_device->props.power = FB_BLANK_UNBLANK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	kb3886_backlight_device->props.brightness = machinfo->default_intensity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	backlight_update_status(kb3886_backlight_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static struct platform_driver kb3886bl_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	.probe		= kb3886bl_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		.name	= "kb3886-bl",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		.pm	= &kb3886bl_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int __init kb3886_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (!dmi_check_system(kb3886bl_device_table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	platform_add_devices(devices, ARRAY_SIZE(devices));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return platform_driver_register(&kb3886bl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void __exit kb3886_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	platform_driver_unregister(&kb3886bl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) module_init(kb3886_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) module_exit(kb3886_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) MODULE_AUTHOR("Claudio Nieder <private@claudio.ch>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) MODULE_DESCRIPTION("Tabletkiosk Sahara Touch-iT Backlight Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) MODULE_ALIAS("dmi:*:svnSDV:pniTouchT201:*");