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 Marvell Semiconductor 88PM8606
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2009 Marvell International Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Haojian Zhuang <haojian.zhuang@marvell.com>
^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/init.h>
^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/of.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/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/i2c.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/mfd/88pm860x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define MAX_BRIGHTNESS		(0xFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define MIN_BRIGHTNESS		(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define CURRENT_BITMASK		(0x1F << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) struct pm860x_backlight_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct pm860x_chip *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct i2c_client *i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	int	current_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	int	port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	int	pwm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	int	iset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	int	reg_duty_cycle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	int	reg_always_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	int	reg_current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static int backlight_power_set(struct pm860x_chip *chip, int port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	switch (port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		ret = on ? pm8606_osc_enable(chip, WLED1_DUTY) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			pm8606_osc_disable(chip, WLED1_DUTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		ret = on ? pm8606_osc_enable(chip, WLED2_DUTY) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			pm8606_osc_disable(chip, WLED2_DUTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		ret = on ? pm8606_osc_enable(chip, WLED3_DUTY) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			pm8606_osc_disable(chip, WLED3_DUTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return ret;
^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) static int pm860x_backlight_set(struct backlight_device *bl, int brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct pm860x_backlight_data *data = bl_get_data(bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct pm860x_chip *chip = data->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	unsigned char value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (brightness > MAX_BRIGHTNESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		value = MAX_BRIGHTNESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		value = brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (brightness)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		backlight_power_set(chip, data->port, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	ret = pm860x_reg_write(data->i2c, data->reg_duty_cycle, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if ((data->current_brightness == 0) && brightness) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		if (data->iset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			ret = pm860x_set_bits(data->i2c, data->reg_current,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 					      CURRENT_BITMASK, data->iset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		if (data->pwm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			ret = pm860x_set_bits(data->i2c, PM8606_PWM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 					      PM8606_PWM_FREQ_MASK, data->pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		if (brightness == MAX_BRIGHTNESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			/* set WLED_ON bit as 100% */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			ret = pm860x_set_bits(data->i2c, data->reg_always_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 					      PM8606_WLED_ON, PM8606_WLED_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		if (brightness == MAX_BRIGHTNESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			/* set WLED_ON bit as 100% */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			ret = pm860x_set_bits(data->i2c, data->reg_always_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 					      PM8606_WLED_ON, PM8606_WLED_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			/* clear WLED_ON bit since it's not 100% */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			ret = pm860x_set_bits(data->i2c, data->reg_always_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 					      PM8606_WLED_ON, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (brightness == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		backlight_power_set(chip, data->port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	dev_dbg(chip->dev, "set brightness %d\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	data->current_brightness = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	dev_dbg(chip->dev, "set brightness %d failure with return value: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		value, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int pm860x_backlight_update_status(struct backlight_device *bl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return pm860x_backlight_set(bl, backlight_get_brightness(bl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int pm860x_backlight_get_brightness(struct backlight_device *bl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct pm860x_backlight_data *data = bl_get_data(bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct pm860x_chip *chip = data->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ret = pm860x_reg_read(data->i2c, data->reg_duty_cycle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	data->current_brightness = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	dev_dbg(chip->dev, "get brightness %d\n", data->current_brightness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return data->current_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static const struct backlight_ops pm860x_backlight_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	.options	= BL_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	.update_status	= pm860x_backlight_update_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	.get_brightness	= pm860x_backlight_get_brightness,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int pm860x_backlight_dt_init(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				    struct pm860x_backlight_data *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				    char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct device_node *nproot, *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	int iset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	nproot = of_get_child_by_name(pdev->dev.parent->of_node, "backlights");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (!nproot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		dev_err(&pdev->dev, "failed to find backlights node\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	for_each_child_of_node(nproot, np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		if (of_node_name_eq(np, name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			of_property_read_u32(np, "marvell,88pm860x-iset",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 					     &iset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			data->iset = PM8606_WLED_CURRENT(iset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			of_property_read_u32(np, "marvell,88pm860x-pwm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 					     &data->pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	of_node_put(nproot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #define pm860x_backlight_dt_init(x, y, z)	(-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static int pm860x_backlight_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct pm860x_backlight_pdata *pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	struct pm860x_backlight_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct backlight_device *bl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct backlight_properties props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	char name[MFD_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	data = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_backlight_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			    GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	res = platform_get_resource_byname(pdev, IORESOURCE_REG, "duty cycle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		dev_err(&pdev->dev, "No REG resource for duty cycle\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	data->reg_duty_cycle = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	res = platform_get_resource_byname(pdev, IORESOURCE_REG, "always on");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		dev_err(&pdev->dev, "No REG resource for always on\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	data->reg_always_on = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	res = platform_get_resource_byname(pdev, IORESOURCE_REG, "current");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		dev_err(&pdev->dev, "No REG resource for current\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	data->reg_current = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	memset(name, 0, MFD_NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	sprintf(name, "backlight-%d", pdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	data->port = pdev->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	data->chip = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	data->i2c = (chip->id == CHIP_PM8606) ? chip->client : chip->companion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	data->current_brightness = MAX_BRIGHTNESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (pm860x_backlight_dt_init(pdev, data, name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		if (pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			data->pwm = pdata->pwm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			data->iset = pdata->iset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	memset(&props, 0, sizeof(struct backlight_properties));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	props.type = BACKLIGHT_RAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	props.max_brightness = MAX_BRIGHTNESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	bl = devm_backlight_device_register(&pdev->dev, name, &pdev->dev, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 					&pm860x_backlight_ops, &props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (IS_ERR(bl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		dev_err(&pdev->dev, "failed to register backlight\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		return PTR_ERR(bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	bl->props.brightness = MAX_BRIGHTNESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	platform_set_drvdata(pdev, bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	/* read current backlight */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	ret = pm860x_backlight_get_brightness(bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	backlight_update_status(bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static struct platform_driver pm860x_backlight_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		.name	= "88pm860x-backlight",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	.probe		= pm860x_backlight_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) module_platform_driver(pm860x_backlight_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) MODULE_DESCRIPTION("Backlight Driver for Marvell Semiconductor 88PM8606");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) MODULE_ALIAS("platform:88pm860x-backlight");