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)  * Regulator driver for TI TPS6586x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2010 Compulab Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: Mike Rapoport <mike@compulab.co.il>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Based on da903x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 2006-2008 Marvell International Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Copyright (C) 2008 Compulab Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/mfd/tps6586x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /* supply control and voltage setting  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define TPS6586X_SUPPLYENA	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define TPS6586X_SUPPLYENB	0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define TPS6586X_SUPPLYENC	0x12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define TPS6586X_SUPPLYEND	0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define TPS6586X_SUPPLYENE	0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define TPS6586X_VCC1		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define TPS6586X_VCC2		0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define TPS6586X_SM1V1		0x23
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define TPS6586X_SM1V2		0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define TPS6586X_SM1SL		0x25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define TPS6586X_SM0V1		0x26
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define TPS6586X_SM0V2		0x27
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define TPS6586X_SM0SL		0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define TPS6586X_LDO2AV1	0x29
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define TPS6586X_LDO2AV2	0x2A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define TPS6586X_LDO2BV1	0x2F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define TPS6586X_LDO2BV2	0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define TPS6586X_LDO4V1		0x32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define TPS6586X_LDO4V2		0x33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /* converter settings  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define TPS6586X_SUPPLYV1	0x41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define TPS6586X_SUPPLYV2	0x42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define TPS6586X_SUPPLYV3	0x43
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define TPS6586X_SUPPLYV4	0x44
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define TPS6586X_SUPPLYV5	0x45
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define TPS6586X_SUPPLYV6	0x46
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define TPS6586X_SMODE1		0x47
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define TPS6586X_SMODE2		0x48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) struct tps6586x_regulator {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct regulator_desc desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	int enable_bit[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	int enable_reg[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static const struct regulator_ops tps6586x_rw_regulator_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	.list_voltage = regulator_list_voltage_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	.map_voltage = regulator_map_voltage_ascend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	.is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	.enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	.disable = regulator_disable_regmap,
^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 const struct regulator_ops tps6586x_rw_linear_regulator_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	.is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	.enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	.disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static const struct regulator_ops tps6586x_ro_regulator_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	.list_voltage = regulator_list_voltage_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	.map_voltage = regulator_map_voltage_ascend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	.is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	.enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	.disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static const struct regulator_ops tps6586x_sys_regulator_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static const unsigned int tps6586x_ldo0_voltages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	1200000, 1500000, 1800000, 2500000, 2700000, 2850000, 3100000, 3300000,
^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) static const unsigned int tps6586x_ldo_voltages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	1250000, 1500000, 1800000, 2500000, 2700000, 2850000, 3100000, 3300000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static const unsigned int tps658640_rtc_voltages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	2500000, 2850000, 3100000, 3300000,
^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) #define TPS6586X_REGULATOR(_id, _ops, _pin_name, vdata, vreg, shift, nbits, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			   ereg0, ebit0, ereg1, ebit1, goreg, gobit)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	.desc	= {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		.supply_name = _pin_name,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		.name	= "REG-" #_id,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		.ops	= &tps6586x_## _ops ## _regulator_ops,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		.type	= REGULATOR_VOLTAGE,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		.id	= TPS6586X_ID_##_id,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		.n_voltages = ARRAY_SIZE(vdata##_voltages),		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		.volt_table = vdata##_voltages,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		.owner	= THIS_MODULE,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		.enable_reg = TPS6586X_SUPPLY##ereg0,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		.enable_mask = 1 << (ebit0),				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		.vsel_reg = TPS6586X_##vreg,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		.vsel_mask = ((1 << (nbits)) - 1) << (shift),		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		.apply_reg = (goreg),				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		.apply_bit = (gobit),				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	},								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	.enable_reg[0]	= TPS6586X_SUPPLY##ereg0,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	.enable_bit[0]	= (ebit0),					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	.enable_reg[1]	= TPS6586X_SUPPLY##ereg1,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	.enable_bit[1]	= (ebit1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define TPS6586X_REGULATOR_LINEAR(_id, _ops, _pin_name, n_volt, min_uv,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 				  uv_step, vreg, shift, nbits, ereg0,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 				  ebit0, ereg1, ebit1, goreg, gobit)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	.desc	= {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		.supply_name = _pin_name,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		.name	= "REG-" #_id,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		.ops	= &tps6586x_## _ops ## _regulator_ops,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		.type	= REGULATOR_VOLTAGE,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		.id	= TPS6586X_ID_##_id,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		.n_voltages = n_volt,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		.min_uV = min_uv,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		.uV_step = uv_step,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		.owner	= THIS_MODULE,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		.enable_reg = TPS6586X_SUPPLY##ereg0,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		.enable_mask = 1 << (ebit0),				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		.vsel_reg = TPS6586X_##vreg,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		.vsel_mask = ((1 << (nbits)) - 1) << (shift),		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		.apply_reg = (goreg),				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		.apply_bit = (gobit),				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	},								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	.enable_reg[0]	= TPS6586X_SUPPLY##ereg0,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	.enable_bit[0]	= (ebit0),					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	.enable_reg[1]	= TPS6586X_SUPPLY##ereg1,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	.enable_bit[1]	= (ebit1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define TPS6586X_LDO(_id, _pname, vdata, vreg, shift, nbits,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		     ereg0, ebit0, ereg1, ebit1)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	TPS6586X_REGULATOR(_id, rw, _pname, vdata, vreg, shift, nbits,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			   ereg0, ebit0, ereg1, ebit1, 0, 0)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #define TPS6586X_LDO_LINEAR(_id, _pname, n_volt, min_uv, uv_step, vreg,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			    shift, nbits, ereg0, ebit0, ereg1, ebit1)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	TPS6586X_REGULATOR_LINEAR(_id, rw_linear, _pname, n_volt,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				  min_uv, uv_step, vreg, shift, nbits,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				  ereg0, ebit0, ereg1, ebit1, 0, 0)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #define TPS6586X_FIXED_LDO(_id, _pname, vdata, vreg, shift, nbits,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			  ereg0, ebit0, ereg1, ebit1)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	TPS6586X_REGULATOR(_id, ro, _pname, vdata, vreg, shift, nbits,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			   ereg0, ebit0, ereg1, ebit1, 0, 0)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #define TPS6586X_DVM(_id, _pname, n_volt, min_uv, uv_step, vreg, shift,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		     nbits, ereg0, ebit0, ereg1, ebit1, goreg, gobit)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	TPS6586X_REGULATOR_LINEAR(_id, rw_linear, _pname, n_volt,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				  min_uv, uv_step, vreg, shift, nbits,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				  ereg0, ebit0, ereg1, ebit1, goreg,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 				  gobit)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #define TPS6586X_SYS_REGULATOR()					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	.desc	= {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		.supply_name = "sys",					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		.name	= "REG-SYS",					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		.ops	= &tps6586x_sys_regulator_ops,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		.type	= REGULATOR_VOLTAGE,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		.id	= TPS6586X_ID_SYS,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		.owner	= THIS_MODULE,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	},								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static struct tps6586x_regulator tps6586x_regulator[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	TPS6586X_SYS_REGULATOR(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	TPS6586X_LDO(LDO_0, "vinldo01", tps6586x_ldo0, SUPPLYV1, 5, 3, ENC, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 					END, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	TPS6586X_LDO(LDO_3, "vinldo23", tps6586x_ldo, SUPPLYV4, 0, 3, ENC, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 					END, 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	TPS6586X_LDO(LDO_5, "REG-SYS", tps6586x_ldo, SUPPLYV6, 0, 3, ENE, 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 					ENE, 6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	TPS6586X_LDO(LDO_6, "vinldo678", tps6586x_ldo, SUPPLYV3, 0, 3, ENC, 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 					END, 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	TPS6586X_LDO(LDO_7, "vinldo678", tps6586x_ldo, SUPPLYV3, 3, 3, ENC, 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 					END, 5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	TPS6586X_LDO(LDO_8, "vinldo678", tps6586x_ldo, SUPPLYV2, 5, 3, ENC, 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 					END, 6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	TPS6586X_LDO(LDO_9, "vinldo9", tps6586x_ldo, SUPPLYV6, 3, 3, ENE, 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 					ENE, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	TPS6586X_LDO(LDO_RTC, "REG-SYS", tps6586x_ldo, SUPPLYV4, 3, 3, V4, 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 					V4, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	TPS6586X_LDO_LINEAR(LDO_1, "vinldo01", 32, 725000, 25000, SUPPLYV1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			    0, 5, ENC, 1, END, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	TPS6586X_LDO_LINEAR(SM_2, "vin-sm2", 32, 3000000, 50000, SUPPLYV2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			    0, 5, ENC, 7, END, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	TPS6586X_DVM(LDO_2, "vinldo23", 32, 725000, 25000, LDO2BV1, 0, 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		     ENA, 3, ENB, 3, TPS6586X_VCC2, BIT(6)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	TPS6586X_DVM(LDO_4, "vinldo4", 32, 1700000, 25000, LDO4V1, 0, 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		     ENC, 3, END, 3, TPS6586X_VCC1, BIT(6)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	TPS6586X_DVM(SM_0, "vin-sm0", 32, 725000, 25000, SM0V1, 0, 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		     ENA, 1, ENB, 1, TPS6586X_VCC1, BIT(2)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	TPS6586X_DVM(SM_1, "vin-sm1", 32, 725000, 25000, SM1V1, 0, 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		     ENA, 0, ENB, 0, TPS6586X_VCC1, BIT(0)),
^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) static struct tps6586x_regulator tps658623_regulator[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	TPS6586X_LDO_LINEAR(SM_2, "vin-sm2", 32, 1700000, 25000, SUPPLYV2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			    0, 5, ENC, 7, END, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static struct tps6586x_regulator tps658640_regulator[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	TPS6586X_LDO(LDO_3, "vinldo23", tps6586x_ldo0, SUPPLYV4, 0, 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 					ENC, 2, END, 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	TPS6586X_LDO(LDO_5, "REG-SYS", tps6586x_ldo0, SUPPLYV6, 0, 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 					ENE, 6, ENE, 6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	TPS6586X_LDO(LDO_6, "vinldo678", tps6586x_ldo0, SUPPLYV3, 0, 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 					ENC, 4, END, 4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	TPS6586X_LDO(LDO_7, "vinldo678", tps6586x_ldo0, SUPPLYV3, 3, 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 					ENC, 5, END, 5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	TPS6586X_LDO(LDO_8, "vinldo678", tps6586x_ldo0, SUPPLYV2, 5, 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 					ENC, 6, END, 6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	TPS6586X_LDO(LDO_9, "vinldo9", tps6586x_ldo0, SUPPLYV6, 3, 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 					ENE, 7, ENE, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	TPS6586X_LDO_LINEAR(SM_2, "vin-sm2", 32, 2150000, 50000, SUPPLYV2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			    0, 5, ENC, 7, END, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	TPS6586X_FIXED_LDO(LDO_RTC, "REG-SYS", tps658640_rtc, SUPPLYV4, 3, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 					V4, 7, V4, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static struct tps6586x_regulator tps658643_regulator[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	TPS6586X_LDO_LINEAR(SM_2, "vin-sm2", 32, 1025000, 25000, SUPPLYV2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			    0, 5, ENC, 7, END, 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * TPS6586X has 2 enable bits that are OR'ed to determine the actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * regulator state. Clearing one of this bits allows switching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * regulator on and of with single register write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static inline int tps6586x_regulator_preinit(struct device *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 					     struct tps6586x_regulator *ri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	uint8_t val1, val2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (ri->enable_reg[0] == ri->enable_reg[1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	    ri->enable_bit[0] == ri->enable_bit[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	ret = tps6586x_read(parent, ri->enable_reg[0], &val1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	ret = tps6586x_read(parent, ri->enable_reg[1], &val2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (!(val2 & (1 << ri->enable_bit[1])))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	 * The regulator is on, but it's enabled with the bit we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 * want to use, so we switch the enable bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (!(val1 & (1 << ri->enable_bit[0]))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		ret = tps6586x_set_bits(parent, ri->enable_reg[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 					1 << ri->enable_bit[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			return ret;
^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) 	return tps6586x_clr_bits(parent, ri->enable_reg[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 				 1 << ri->enable_bit[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static int tps6586x_regulator_set_slew_rate(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			int id, struct regulator_init_data *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	struct device *parent = pdev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct tps6586x_settings *setting = p->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	uint8_t reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (setting == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (!(setting->slew_rate & TPS6586X_SLEW_RATE_SET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	/* only SM0 and SM1 can have the slew rate settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	switch (id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	case TPS6586X_ID_SM_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		reg = TPS6586X_SM0SL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	case TPS6586X_ID_SM_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		reg = TPS6586X_SM1SL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		dev_err(&pdev->dev, "Only SM0/SM1 can set slew rate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	return tps6586x_write(parent, reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			setting->slew_rate & TPS6586X_SLEW_RATE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static struct tps6586x_regulator *find_regulator_info(int id, int version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	struct tps6586x_regulator *ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct tps6586x_regulator *table = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	int num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	switch (version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	case TPS658623:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	case TPS658624:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		table = tps658623_regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		num = ARRAY_SIZE(tps658623_regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	case TPS658640:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	case TPS658640v2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		table = tps658640_regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		num = ARRAY_SIZE(tps658640_regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	case TPS658643:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		table = tps658643_regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		num = ARRAY_SIZE(tps658643_regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	/* Search version specific table first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (table) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		for (i = 0; i < num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			ri = &table[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			if (ri->desc.id == id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 				return ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	for (i = 0; i < ARRAY_SIZE(tps6586x_regulator); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		ri = &tps6586x_regulator[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		if (ri->desc.id == id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			return ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static struct of_regulator_match tps6586x_matches[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	{ .name = "sys",     .driver_data = (void *)TPS6586X_ID_SYS     },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	{ .name = "sm0",     .driver_data = (void *)TPS6586X_ID_SM_0    },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	{ .name = "sm1",     .driver_data = (void *)TPS6586X_ID_SM_1    },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	{ .name = "sm2",     .driver_data = (void *)TPS6586X_ID_SM_2    },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	{ .name = "ldo0",    .driver_data = (void *)TPS6586X_ID_LDO_0   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	{ .name = "ldo1",    .driver_data = (void *)TPS6586X_ID_LDO_1   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	{ .name = "ldo2",    .driver_data = (void *)TPS6586X_ID_LDO_2   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	{ .name = "ldo3",    .driver_data = (void *)TPS6586X_ID_LDO_3   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	{ .name = "ldo4",    .driver_data = (void *)TPS6586X_ID_LDO_4   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	{ .name = "ldo5",    .driver_data = (void *)TPS6586X_ID_LDO_5   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	{ .name = "ldo6",    .driver_data = (void *)TPS6586X_ID_LDO_6   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	{ .name = "ldo7",    .driver_data = (void *)TPS6586X_ID_LDO_7   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	{ .name = "ldo8",    .driver_data = (void *)TPS6586X_ID_LDO_8   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	{ .name = "ldo9",    .driver_data = (void *)TPS6586X_ID_LDO_9   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	{ .name = "ldo_rtc", .driver_data = (void *)TPS6586X_ID_LDO_RTC },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static struct tps6586x_platform_data *tps6586x_parse_regulator_dt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		struct of_regulator_match **tps6586x_reg_matches)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	const unsigned int num = ARRAY_SIZE(tps6586x_matches);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct device_node *np = pdev->dev.parent->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct device_node *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	const char *sys_rail = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	struct tps6586x_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	regs = of_get_child_by_name(np, "regulators");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	if (!regs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		dev_err(&pdev->dev, "regulator node not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	err = of_regulator_match(&pdev->dev, regs, tps6586x_matches, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	of_node_put(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		dev_err(&pdev->dev, "Regulator match failed, e %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	for (i = 0; i < num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		uintptr_t id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		if (!tps6586x_matches[i].init_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		pdata->reg_init_data[i] = tps6586x_matches[i].init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		id = (uintptr_t)tps6586x_matches[i].driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		if (id == TPS6586X_ID_SYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			sys_rail = pdata->reg_init_data[i]->constraints.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		if ((id == TPS6586X_ID_LDO_5) || (id == TPS6586X_ID_LDO_RTC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			pdata->reg_init_data[i]->supply_regulator = sys_rail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	*tps6586x_reg_matches = tps6586x_matches;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	return pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static struct tps6586x_platform_data *tps6586x_parse_regulator_dt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		struct of_regulator_match **tps6586x_reg_matches)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	*tps6586x_reg_matches = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static int tps6586x_regulator_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	struct tps6586x_regulator *ri = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	struct regulator_init_data *reg_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	struct tps6586x_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	struct of_regulator_match *tps6586x_reg_matches = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	int version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	dev_dbg(&pdev->dev, "Probing regulator\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	pdata = dev_get_platdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	if ((!pdata) && (pdev->dev.parent->of_node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		pdata = tps6586x_parse_regulator_dt(pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 					&tps6586x_reg_matches);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	if (!pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		dev_err(&pdev->dev, "Platform data not available, exiting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	version = tps6586x_get_version(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	for (id = 0; id < TPS6586X_ID_MAX_REGULATOR; ++id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		reg_data = pdata->reg_init_data[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		ri = find_regulator_info(id, version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		if (!ri) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			dev_err(&pdev->dev, "invalid regulator ID specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		err = tps6586x_regulator_preinit(pdev->dev.parent, ri);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 				"regulator %d preinit failed, e %d\n", id, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		config.dev = pdev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		config.init_data = reg_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		config.driver_data = ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		if (tps6586x_reg_matches)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			config.of_node = tps6586x_reg_matches[id].of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			dev_err(&pdev->dev, "failed to register regulator %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 					ri->desc.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 			return PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		if (reg_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 			err = tps6586x_regulator_set_slew_rate(pdev, id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 					reg_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 			if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 				dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 					"Slew rate config failed, e %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	platform_set_drvdata(pdev, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) static struct platform_driver tps6586x_regulator_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		.name	= "tps6586x-regulator",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	.probe		= tps6586x_regulator_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) static int __init tps6586x_regulator_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	return platform_driver_register(&tps6586x_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) subsys_initcall(tps6586x_regulator_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static void __exit tps6586x_regulator_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	platform_driver_unregister(&tps6586x_regulator_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) module_exit(tps6586x_regulator_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) MODULE_DESCRIPTION("Regulator Driver for TI TPS6586X PMIC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) MODULE_ALIAS("platform:tps6586x-regulator");