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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * tps65217_bl.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * TPS65217 backlight driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2012 Matthias Kaehlcke
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: Matthias Kaehlcke <matthias@kaehlcke.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * modify it under the terms of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * published by the Free Software Foundation version 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * kind, whether express or implied; without even the implied warranty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/backlight.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/mfd/tps65217.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct tps65217_bl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct tps65217 *tps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct backlight_device *bl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	bool is_enabled;
^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 int tps65217_bl_enable(struct tps65217_bl *tps65217_bl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	rc = tps65217_set_bits(tps65217_bl->tps, TPS65217_REG_WLEDCTRL1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			TPS65217_WLEDCTRL1_ISINK_ENABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			TPS65217_WLEDCTRL1_ISINK_ENABLE, TPS65217_PROTECT_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		dev_err(tps65217_bl->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			"failed to enable backlight: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	tps65217_bl->is_enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	dev_dbg(tps65217_bl->dev, "backlight enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static int tps65217_bl_disable(struct tps65217_bl *tps65217_bl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	rc = tps65217_clear_bits(tps65217_bl->tps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 				TPS65217_REG_WLEDCTRL1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 				TPS65217_WLEDCTRL1_ISINK_ENABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 				TPS65217_PROTECT_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		dev_err(tps65217_bl->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			"failed to disable backlight: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return rc;
^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) 	tps65217_bl->is_enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	dev_dbg(tps65217_bl->dev, "backlight disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static int tps65217_bl_update_status(struct backlight_device *bl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct tps65217_bl *tps65217_bl = bl_get_data(bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int brightness = backlight_get_brightness(bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	if (brightness > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		rc = tps65217_reg_write(tps65217_bl->tps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 					TPS65217_REG_WLEDCTRL2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 					brightness - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 					TPS65217_PROTECT_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			dev_err(tps65217_bl->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 				"failed to set brightness level: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			return rc;
^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) 		dev_dbg(tps65217_bl->dev, "brightness set to %d\n", brightness);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		if (!tps65217_bl->is_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			rc = tps65217_bl_enable(tps65217_bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		rc = tps65217_bl_disable(tps65217_bl);
^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) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static const struct backlight_ops tps65217_bl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	.options	= BL_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	.update_status	= tps65217_bl_update_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int tps65217_bl_hw_init(struct tps65217_bl *tps65217_bl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			struct tps65217_bl_pdata *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	rc = tps65217_bl_disable(tps65217_bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	switch (pdata->isel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	case TPS65217_BL_ISET1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		/* select ISET_1 current level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		rc = tps65217_clear_bits(tps65217_bl->tps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 					TPS65217_REG_WLEDCTRL1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 					TPS65217_WLEDCTRL1_ISEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 					TPS65217_PROTECT_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			dev_err(tps65217_bl->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 				"failed to select ISET1 current level: %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 				rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			return rc;
^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) 		dev_dbg(tps65217_bl->dev, "selected ISET1 current level\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	case TPS65217_BL_ISET2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		/* select ISET2 current level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		rc = tps65217_set_bits(tps65217_bl->tps, TPS65217_REG_WLEDCTRL1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				TPS65217_WLEDCTRL1_ISEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				TPS65217_WLEDCTRL1_ISEL, TPS65217_PROTECT_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			dev_err(tps65217_bl->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 				"failed to select ISET2 current level: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		dev_dbg(tps65217_bl->dev, "selected ISET2 current level\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		dev_err(tps65217_bl->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			"invalid value for current level: %d\n", pdata->isel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	/* set PWM frequency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	rc = tps65217_set_bits(tps65217_bl->tps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			TPS65217_REG_WLEDCTRL1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			TPS65217_WLEDCTRL1_FDIM_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			pdata->fdim,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			TPS65217_PROTECT_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		dev_err(tps65217_bl->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			"failed to select PWM dimming frequency: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static struct tps65217_bl_pdata *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) tps65217_bl_parse_dt(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct device_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct tps65217_bl_pdata *pdata, *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	node = of_get_child_by_name(tps->dev->of_node, "backlight");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (!pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		err = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	pdata->isel = TPS65217_BL_ISET1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (!of_property_read_u32(node, "isel", &val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		if (val < TPS65217_BL_ISET1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			val > TPS65217_BL_ISET2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 				"invalid 'isel' value in the device tree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			err = ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		pdata->isel = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	pdata->fdim = TPS65217_BL_FDIM_200HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (!of_property_read_u32(node, "fdim", &val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		switch (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		case 100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			pdata->fdim = TPS65217_BL_FDIM_100HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		case 200:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			pdata->fdim = TPS65217_BL_FDIM_200HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		case 500:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			pdata->fdim = TPS65217_BL_FDIM_500HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		case 1000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			pdata->fdim = TPS65217_BL_FDIM_1000HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 				"invalid 'fdim' value in the device tree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			err = ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (!of_property_read_u32(node, "default-brightness", &val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		if (val > 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 				"invalid 'default-brightness' value in the device tree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			err = ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		pdata->dft_brightness = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	of_node_put(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	of_node_put(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static struct tps65217_bl_pdata *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) tps65217_bl_parse_dt(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int tps65217_bl_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	struct tps65217_bl *tps65217_bl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct tps65217_bl_pdata *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct backlight_properties bl_props;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	pdata = tps65217_bl_parse_dt(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (IS_ERR(pdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		return PTR_ERR(pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	tps65217_bl = devm_kzalloc(&pdev->dev, sizeof(*tps65217_bl),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (tps65217_bl == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	tps65217_bl->tps = tps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	tps65217_bl->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	tps65217_bl->is_enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	rc = tps65217_bl_hw_init(tps65217_bl, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	memset(&bl_props, 0, sizeof(struct backlight_properties));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	bl_props.type = BACKLIGHT_RAW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	bl_props.max_brightness = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	tps65217_bl->bl = devm_backlight_device_register(&pdev->dev, pdev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 						tps65217_bl->dev, tps65217_bl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 						&tps65217_bl_ops, &bl_props);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (IS_ERR(tps65217_bl->bl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		dev_err(tps65217_bl->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			"registration of backlight device failed: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		return PTR_ERR(tps65217_bl->bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	tps65217_bl->bl->props.brightness = pdata->dft_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	backlight_update_status(tps65217_bl->bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	platform_set_drvdata(pdev, tps65217_bl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static const struct of_device_id tps65217_bl_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	{ .compatible = "ti,tps65217-bl", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	{ /* sentinel */ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) MODULE_DEVICE_TABLE(of, tps65217_bl_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static struct platform_driver tps65217_bl_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	.probe		= tps65217_bl_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		.name	= "tps65217-bl",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		.of_match_table = of_match_ptr(tps65217_bl_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) module_platform_driver(tps65217_bl_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) MODULE_DESCRIPTION("TPS65217 Backlight driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) MODULE_AUTHOR("Matthias Kaehlcke <matthias@kaehlcke.net>");