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)  *  LCD / Backlight control code for Sharp SL-6000x (tosa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (c) 2005		Dirk Opfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (c) 2007,2008	Dmitry Baryshkov
^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) #include <linux/kernel.h>
^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/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/spi/spi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/gpio/consumer.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/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/mach/sharpsl_param.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "tosa_bl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define COMADJ_DEFAULT	97
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define DAC_CH1		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define DAC_CH2		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct tosa_bl_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct i2c_client *i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct backlight_device *bl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct gpio_desc *gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	int comadj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static void tosa_bl_set_backlight(struct tosa_bl_data *data, int brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct spi_device *spi = dev_get_platdata(&data->i2c->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	i2c_smbus_write_byte_data(data->i2c, DAC_CH1, data->comadj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	/* SetBacklightDuty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	i2c_smbus_write_byte_data(data->i2c, DAC_CH2, (u8)(brightness & 0xff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/* SetBacklightVR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	gpiod_set_value(data->gpio, brightness & 0x100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	tosa_bl_enable(spi, brightness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static int tosa_bl_update_status(struct backlight_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct backlight_properties *props = &dev->props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct tosa_bl_data *data = bl_get_data(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	int power = max(props->power, props->fb_blank);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int brightness = props->brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (power)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		brightness = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	tosa_bl_set_backlight(data, brightness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	return 0;
^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 int tosa_bl_get_brightness(struct backlight_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct backlight_properties *props = &dev->props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return props->brightness;
^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) static const struct backlight_ops bl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.get_brightness		= tosa_bl_get_brightness,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.update_status		= tosa_bl_update_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static int tosa_bl_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct backlight_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct tosa_bl_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	data = devm_kzalloc(&client->dev, sizeof(struct tosa_bl_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 				GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	data->comadj = sharpsl_param.comadj == -1 ? COMADJ_DEFAULT : sharpsl_param.comadj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	data->gpio = devm_gpiod_get(&client->dev, "backlight", GPIOD_OUT_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	ret = PTR_ERR_OR_ZERO(data->gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		dev_dbg(&data->bl->dev, "Unable to request gpio!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	i2c_set_clientdata(client, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	data->i2c = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	memset(&props, 0, sizeof(struct backlight_properties));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	props.type = BACKLIGHT_RAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	props.max_brightness = 512 - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	data->bl = devm_backlight_device_register(&client->dev, "tosa-bl",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 						&client->dev, data, &bl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 						&props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (IS_ERR(data->bl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		ret = PTR_ERR(data->bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		goto err_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	data->bl->props.brightness = 69;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	data->bl->props.power = FB_BLANK_UNBLANK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	backlight_update_status(data->bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^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) err_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	data->bl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return ret;
^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) static int tosa_bl_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct tosa_bl_data *data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	data->bl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int tosa_bl_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct tosa_bl_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	tosa_bl_set_backlight(data, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int tosa_bl_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct tosa_bl_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	backlight_update_status(data->bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static SIMPLE_DEV_PM_OPS(tosa_bl_pm_ops, tosa_bl_suspend, tosa_bl_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static const struct i2c_device_id tosa_bl_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	{ "tosa-bl", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) MODULE_DEVICE_TABLE(i2c, tosa_bl_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static struct i2c_driver tosa_bl_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		.name		= "tosa-bl",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		.pm		= &tosa_bl_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	.probe		= tosa_bl_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	.remove		= tosa_bl_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	.id_table	= tosa_bl_id,
^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) module_i2c_driver(tosa_bl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) MODULE_AUTHOR("Dmitry Baryshkov");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) MODULE_DESCRIPTION("LCD/Backlight control for Sharp SL-6000 PDA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)