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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) // Copyright (C) 2020 ROHM Semiconductors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // ROHM BD9576MUF/BD9573MUF regulator driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/interrupt.h>
^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/mfd/rohm-bd957x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/mfd/rohm-generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/regulator/of_regulator.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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define BD957X_VOUTS1_VOLT	3300000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define BD957X_VOUTS4_BASE_VOLT	1030000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define BD957X_VOUTS34_NUM_VOLT	32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int vout1_volt_table[] = {5000000, 4900000, 4800000, 4700000, 4600000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 				 4500000, 4500000, 4500000, 5000000, 5100000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 				 5200000, 5300000, 5400000, 5500000, 5500000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 				 5500000};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static int vout2_volt_table[] = {1800000, 1780000, 1760000, 1740000, 1720000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 				 1700000, 1680000, 1660000, 1800000, 1820000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 				 1840000, 1860000, 1880000, 1900000, 1920000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 				 1940000};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static int voutl1_volt_table[] = {2500000, 2540000, 2580000, 2620000, 2660000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 				  2700000, 2740000, 2780000, 2500000, 2460000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 				  2420000, 2380000, 2340000, 2300000, 2260000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 				  2220000};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) struct bd957x_regulator_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct regulator_desc desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int base_voltage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static int bd957x_vout34_list_voltage(struct regulator_dev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 				      unsigned int selector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	const struct regulator_desc *desc = rdev->desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	int multiplier = selector & desc->vsel_mask & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	int tune;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	/* VOUT3 and 4 has 10mV step */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	tune = multiplier * 10000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (!(selector & 0x80))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return desc->fixed_uV - tune;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return desc->fixed_uV + tune;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static int bd957x_list_voltage(struct regulator_dev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			       unsigned int selector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	const struct regulator_desc *desc = rdev->desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	int index = selector & desc->vsel_mask & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (!(selector & 0x80))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		index += desc->n_voltages/2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (index >= desc->n_voltages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return desc->volt_table[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static const struct regulator_ops bd957x_vout34_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.list_voltage = bd957x_vout34_list_voltage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static const struct regulator_ops bd957X_vouts1_regulator_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	.is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static const struct regulator_ops bd957x_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	.is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	.list_voltage = bd957x_list_voltage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	.get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static struct bd957x_regulator_data bd9576_regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		.desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			.name = "VD50",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			.of_match = of_match_ptr("regulator-vd50"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			.regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			.id = BD957X_VD50,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			.ops = &bd957x_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			.volt_table = &vout1_volt_table[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			.n_voltages = ARRAY_SIZE(vout1_volt_table),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			.vsel_reg = BD957X_REG_VOUT1_TUNE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			.vsel_mask = BD957X_MASK_VOUT1_TUNE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			.enable_reg = BD957X_REG_POW_TRIGGER1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			.enable_mask = BD957X_REGULATOR_EN_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			.enable_val = BD957X_REGULATOR_DIS_VAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			.enable_is_inverted = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		.desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			.name = "VD18",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			.of_match = of_match_ptr("regulator-vd18"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			.regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			.id = BD957X_VD18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			.ops = &bd957x_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			.volt_table = &vout2_volt_table[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			.n_voltages = ARRAY_SIZE(vout2_volt_table),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			.vsel_reg = BD957X_REG_VOUT2_TUNE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			.vsel_mask = BD957X_MASK_VOUT2_TUNE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			.enable_reg = BD957X_REG_POW_TRIGGER2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			.enable_mask = BD957X_REGULATOR_EN_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			.enable_val = BD957X_REGULATOR_DIS_VAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			.enable_is_inverted = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		.desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			.name = "VDDDR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			.of_match = of_match_ptr("regulator-vdddr"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			.regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			.id = BD957X_VDDDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			.ops = &bd957x_vout34_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			.n_voltages = BD957X_VOUTS34_NUM_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			.vsel_reg = BD957X_REG_VOUT3_TUNE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			.vsel_mask = BD957X_MASK_VOUT3_TUNE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			.enable_reg = BD957X_REG_POW_TRIGGER3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			.enable_mask = BD957X_REGULATOR_EN_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			.enable_val = BD957X_REGULATOR_DIS_VAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			.enable_is_inverted = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			.owner = THIS_MODULE,
^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) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		.desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			.name = "VD10",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			.of_match = of_match_ptr("regulator-vd10"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			.regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			.id = BD957X_VD10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			.ops = &bd957x_vout34_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			.fixed_uV = BD957X_VOUTS4_BASE_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			.n_voltages = BD957X_VOUTS34_NUM_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			.vsel_reg = BD957X_REG_VOUT4_TUNE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			.vsel_mask = BD957X_MASK_VOUT4_TUNE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			.enable_reg = BD957X_REG_POW_TRIGGER4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			.enable_mask = BD957X_REGULATOR_EN_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			.enable_val = BD957X_REGULATOR_DIS_VAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			.enable_is_inverted = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		.desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			.name = "VOUTL1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			.of_match = of_match_ptr("regulator-voutl1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			.regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			.id = BD957X_VOUTL1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			.ops = &bd957x_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			.volt_table = &voutl1_volt_table[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			.n_voltages = ARRAY_SIZE(voutl1_volt_table),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			.vsel_reg = BD957X_REG_VOUTL1_TUNE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			.vsel_mask = BD957X_MASK_VOUTL1_TUNE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			.enable_reg = BD957X_REG_POW_TRIGGERL1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			.enable_mask = BD957X_REGULATOR_EN_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			.enable_val = BD957X_REGULATOR_DIS_VAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			.enable_is_inverted = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		.desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			.name = "VOUTS1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			.of_match = of_match_ptr("regulator-vouts1"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			.regulators_node = of_match_ptr("regulators"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			.id = BD957X_VOUTS1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			.ops = &bd957X_vouts1_regulator_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			.type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			.n_voltages = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			.fixed_uV = BD957X_VOUTS1_VOLT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			.enable_reg = BD957X_REG_POW_TRIGGERS1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			.enable_mask = BD957X_REGULATOR_EN_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			.enable_val = BD957X_REGULATOR_DIS_VAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			.enable_is_inverted = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			.owner = THIS_MODULE,
^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) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static int bd957x_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct regulator_config config = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	bool vout_mode, ddr_sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	const struct bd957x_regulator_data *reg_data = &bd9576_regulators[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	unsigned int num_reg_data = ARRAY_SIZE(bd9576_regulators);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	regmap = dev_get_regmap(pdev->dev.parent, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (!regmap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		dev_err(&pdev->dev, "No regmap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	vout_mode = of_property_read_bool(pdev->dev.parent->of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 					 "rohm,vout1-en-low");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (vout_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		struct gpio_desc *en;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		dev_dbg(&pdev->dev, "GPIO controlled mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		/* VOUT1 enable state judged by VOUT1_EN pin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		/* See if we have GPIO defined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		en = devm_gpiod_get_from_of_node(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 						 pdev->dev.parent->of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 						 "rohm,vout1-en-gpios", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 						 GPIOD_OUT_LOW, "vout1-en");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if (!IS_ERR(en)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			/* VOUT1_OPS gpio ctrl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			 * Regulator core prioritizes the ena_gpio over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			 * enable/disable/is_enabled callbacks so no need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			 * clear them. We can still use same ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			config.ena_gpiod = en;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			 * In theory it is possible someone wants to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			 * vout1-en LOW during OTP loading and set VOUT1 to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			 * controlled by GPIO - but control the GPIO from some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			 * where else than this driver. For that to work we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			 * should unset the is_enabled callback here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			 * I believe such case where rohm,vout1-en-low is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			 * and vout1-en-gpios is not is likely to be a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			 * misconfiguration. So let's just err out for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				"Failed to get VOUT1 control GPIO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			return PTR_ERR(en);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	 * If more than one PMIC needs to be controlled by same processor then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	 * allocate the regulator data array here and use bd9576_regulators as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	 * template. At the moment I see no such use-case so I spare some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	 * bytes and use bd9576_regulators directly for non-constant configs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	 * like DDR voltage selection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	ddr_sel =  of_property_read_bool(pdev->dev.parent->of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 					 "rohm,ddr-sel-low");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (ddr_sel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		bd9576_regulators[2].desc.fixed_uV = 1350000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		bd9576_regulators[2].desc.fixed_uV = 1500000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	switch (chip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	case ROHM_CHIP_TYPE_BD9576:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		dev_dbg(&pdev->dev, "Found BD9576MUF\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	case ROHM_CHIP_TYPE_BD9573:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		dev_dbg(&pdev->dev, "Found BD9573MUF\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		dev_err(&pdev->dev, "Unsupported chip type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	config.dev = pdev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	config.regmap = regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	for (i = 0; i < num_reg_data; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		const struct regulator_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		const struct bd957x_regulator_data *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		r = &reg_data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		desc = &r->desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		rdev = devm_regulator_register(&pdev->dev, desc, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 				"failed to register %s regulator\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 				desc->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			return PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		 * Clear the VOUT1 GPIO setting - rest of the regulators do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		 * support GPIO control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		config.ena_gpiod = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static const struct platform_device_id bd957x_pmic_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	{ "bd9573-pmic", ROHM_CHIP_TYPE_BD9573 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	{ "bd9576-pmic", ROHM_CHIP_TYPE_BD9576 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) MODULE_DEVICE_TABLE(platform, bd957x_pmic_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static struct platform_driver bd957x_regulator = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		.name = "bd957x-pmic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	.probe = bd957x_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	.id_table = bd957x_pmic_id,
^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) module_platform_driver(bd957x_regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) MODULE_DESCRIPTION("ROHM BD9576/BD9573 voltage regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) MODULE_ALIAS("platform:bd957x-pmic");