Skip to content

Commit 3e10bbd

Browse files
JosephChen2017lag-linaro
authored andcommitted
regulator: rk808: Add RK801 support
Add support for rk801 to the existing rk808 regulator driver. It provides 4 BUCK, 2 LDO and 1 SWITCH. Signed-off-by: Joseph Chen <chenjh@rock-chips.com> Reviewed-by: Mark Brown <broonie@kernel.org> Link: https://patch.msgid.link/20260112124351.17707-4-chenjh@rock-chips.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 156442e commit 3e10bbd

1 file changed

Lines changed: 243 additions & 0 deletions

File tree

drivers/regulator/rk808-regulator.c

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include <linux/gpio/consumer.h>
2525

2626
/* Field definitions */
27+
#define RK801_BUCK_VSEL_MASK 0x7f
28+
#define RK801_LDO_VSEL_MASK 0x3f
29+
2730
#define RK808_BUCK_VSEL_MASK 0x3f
2831
#define RK808_BUCK4_VSEL_MASK 0xf
2932
#define RK808_LDO_VSEL_MASK 0x1f
@@ -158,6 +161,11 @@
158161
RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
159162
_vmask, _ereg, _emask, 0, 0, _etime, &rk808_reg_ops)
160163

164+
#define RK801_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
165+
_vmask, _ereg, _emask, _disval, _etime) \
166+
RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
167+
_vmask, _ereg, _emask, _emask, _disval, _etime, &rk801_reg_ops)
168+
161169
#define RK816_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
162170
_vmask, _ereg, _emask, _disval, _etime) \
163171
RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
@@ -185,6 +193,11 @@
185193
.ops = _ops \
186194
}
187195

196+
#define RK801_DESC_SWITCH(_id, _match, _supply, _ereg, _emask, \
197+
_disval) \
198+
RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \
199+
_emask, _disval, &rk801_switch_ops)
200+
188201
#define RK817_DESC_SWITCH(_id, _match, _supply, _ereg, _emask, \
189202
_disval) \
190203
RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \
@@ -802,6 +815,115 @@ static unsigned int rk8xx_regulator_of_map_mode(unsigned int mode)
802815
}
803816
}
804817

818+
static unsigned int rk801_get_mode(struct regulator_dev *rdev)
819+
{
820+
unsigned int val;
821+
int err;
822+
823+
err = regmap_read(rdev->regmap, RK801_POWER_FPWM_EN_REG, &val);
824+
if (err)
825+
return err;
826+
827+
if (val & BIT(rdev->desc->id))
828+
return REGULATOR_MODE_FAST;
829+
else
830+
return REGULATOR_MODE_NORMAL;
831+
}
832+
833+
static int rk801_set_mode(struct regulator_dev *rdev, unsigned int mode)
834+
{
835+
unsigned int offset = rdev->desc->id;
836+
837+
switch (mode) {
838+
case REGULATOR_MODE_FAST:
839+
return regmap_update_bits(rdev->regmap, RK801_POWER_FPWM_EN_REG,
840+
BIT(offset), RK801_FPWM_MODE << offset);
841+
case REGULATOR_MODE_NORMAL:
842+
return regmap_update_bits(rdev->regmap, RK801_POWER_FPWM_EN_REG,
843+
BIT(offset), RK801_AUTO_PWM_MODE << offset);
844+
default:
845+
dev_err(&rdev->dev, "do not support this mode\n");
846+
return -EINVAL;
847+
}
848+
849+
return 0;
850+
}
851+
852+
static int rk801_set_suspend_voltage(struct regulator_dev *rdev, int uv)
853+
{
854+
unsigned int reg;
855+
int sel;
856+
857+
if (rdev->desc->id < RK801_ID_LDO1)
858+
sel = regulator_map_voltage_linear_range(rdev, uv, uv);
859+
else
860+
sel = regulator_map_voltage_linear(rdev, uv, uv);
861+
if (sel < 0)
862+
return -EINVAL;
863+
864+
reg = rdev->desc->vsel_reg + RK801_SLP_REG_OFFSET;
865+
866+
return regmap_update_bits(rdev->regmap, reg,
867+
rdev->desc->vsel_mask, sel);
868+
}
869+
870+
static int rk801_set_suspend_enable(struct regulator_dev *rdev)
871+
{
872+
return regmap_update_bits(rdev->regmap, RK801_POWER_SLP_EN_REG,
873+
BIT(rdev->desc->id), BIT(rdev->desc->id));
874+
}
875+
876+
static int rk801_set_suspend_disable(struct regulator_dev *rdev)
877+
{
878+
return regmap_update_bits(rdev->regmap, RK801_POWER_SLP_EN_REG,
879+
BIT(rdev->desc->id), 0);
880+
}
881+
882+
static int rk801_set_voltage_time_sel(struct regulator_dev *rdev,
883+
unsigned int old_selector,
884+
unsigned int new_selector)
885+
{
886+
return regulator_set_voltage_time_sel(rdev, old_selector,
887+
new_selector) + RK801_HW_SYNC_US;
888+
}
889+
890+
static const struct regulator_ops rk801_buck_ops = {
891+
.list_voltage = regulator_list_voltage_linear_range,
892+
.map_voltage = regulator_map_voltage_linear_range,
893+
.get_voltage_sel = regulator_get_voltage_sel_regmap,
894+
.set_voltage_sel = regulator_set_voltage_sel_regmap,
895+
.set_voltage_time_sel = rk801_set_voltage_time_sel,
896+
.enable = regulator_enable_regmap,
897+
.disable = regulator_disable_regmap,
898+
.is_enabled = regulator_is_enabled_regmap,
899+
.set_mode = rk801_set_mode,
900+
.get_mode = rk801_get_mode,
901+
.set_suspend_voltage = rk801_set_suspend_voltage,
902+
.set_suspend_enable = rk801_set_suspend_enable,
903+
.set_suspend_disable = rk801_set_suspend_disable,
904+
};
905+
906+
static const struct regulator_ops rk801_reg_ops = {
907+
.list_voltage = regulator_list_voltage_linear,
908+
.map_voltage = regulator_map_voltage_linear,
909+
.get_voltage_sel = regulator_get_voltage_sel_regmap,
910+
.set_voltage_sel = regulator_set_voltage_sel_regmap,
911+
.enable = regulator_enable_regmap,
912+
.disable = regulator_disable_regmap,
913+
.is_enabled = regulator_is_enabled_regmap,
914+
.set_suspend_voltage = rk801_set_suspend_voltage,
915+
.set_suspend_enable = rk801_set_suspend_enable,
916+
.set_suspend_disable = rk801_set_suspend_disable,
917+
};
918+
919+
static const struct regulator_ops rk801_switch_ops = {
920+
.enable = regulator_enable_regmap,
921+
.disable = regulator_disable_regmap,
922+
.is_enabled = regulator_is_enabled_regmap,
923+
.set_suspend_enable = rk801_set_suspend_enable,
924+
.set_suspend_disable = rk801_set_suspend_disable,
925+
};
926+
805927
static const struct regulator_ops rk805_reg_ops = {
806928
.list_voltage = regulator_list_voltage_linear,
807929
.map_voltage = regulator_map_voltage_linear,
@@ -1049,6 +1171,123 @@ static const struct regulator_ops rk817_switch_ops = {
10491171
.set_suspend_disable = rk817_set_suspend_disable,
10501172
};
10511173

1174+
static const struct linear_range rk801_buck1_voltage_ranges[] = {
1175+
REGULATOR_LINEAR_RANGE(500000, 0, 80, 12500), /* 0.5v - 1.5v */
1176+
REGULATOR_LINEAR_RANGE(1800000, 81, 82, 400000),/* 1.8v - 2.2v */
1177+
REGULATOR_LINEAR_RANGE(3300000, 83, 83, 0), /* 3.3v */
1178+
REGULATOR_LINEAR_RANGE(5000000, 84, 84, 0), /* 5.0v */
1179+
REGULATOR_LINEAR_RANGE(5250000, 85, 85, 0), /* 5.25v */
1180+
};
1181+
1182+
static const struct linear_range rk801_buck2_voltage_ranges[] = {
1183+
REGULATOR_LINEAR_RANGE(800000, 0, 2, 50000), /* 0.8v - 0.9v */
1184+
REGULATOR_LINEAR_RANGE(1800000, 3, 4, 400000), /* 1.8v - 2.2v */
1185+
REGULATOR_LINEAR_RANGE(3300000, 5, 5, 0), /* 3.3v */
1186+
REGULATOR_LINEAR_RANGE(5000000, 6, 6, 0), /* 5.0v */
1187+
REGULATOR_LINEAR_RANGE(5250000, 7, 7, 0), /* 5.25v */
1188+
};
1189+
1190+
static const struct linear_range rk801_buck4_voltage_ranges[] = {
1191+
REGULATOR_LINEAR_RANGE(500000, 0, 80, 12500), /* 0.5v - 1.5v */
1192+
REGULATOR_LINEAR_RANGE(1800000, 81, 82, 400000),/* 1.8v - 2.2v */
1193+
REGULATOR_LINEAR_RANGE(2500000, 83, 83, 0), /* 2.5v */
1194+
REGULATOR_LINEAR_RANGE(2800000, 84, 84, 0), /* 2.8v */
1195+
REGULATOR_LINEAR_RANGE(3000000, 85, 85, 0), /* 3.0v */
1196+
REGULATOR_LINEAR_RANGE(3300000, 86, 86, 0), /* 3.3v */
1197+
};
1198+
1199+
static const struct regulator_desc rk801_reg[] = {
1200+
{
1201+
.name = "dcdc1",
1202+
.supply_name = "vcc1",
1203+
.of_match = of_match_ptr("dcdc1"),
1204+
.regulators_node = of_match_ptr("regulators"),
1205+
.id = RK801_ID_DCDC1,
1206+
.ops = &rk801_buck_ops,
1207+
.type = REGULATOR_VOLTAGE,
1208+
.n_voltages = 86,
1209+
.linear_ranges = rk801_buck1_voltage_ranges,
1210+
.n_linear_ranges = ARRAY_SIZE(rk801_buck1_voltage_ranges),
1211+
.vsel_reg = RK801_BUCK1_ON_VSEL_REG,
1212+
.vsel_mask = RK801_BUCK_VSEL_MASK,
1213+
.enable_reg = RK801_POWER_EN0_REG,
1214+
.enable_mask = ENABLE_MASK(RK801_ID_DCDC1),
1215+
.enable_val = ENABLE_MASK(RK801_ID_DCDC1),
1216+
.disable_val = DISABLE_VAL(RK801_ID_DCDC1),
1217+
.ramp_delay = 1000,
1218+
.of_map_mode = rk8xx_regulator_of_map_mode,
1219+
.enable_time = 400,
1220+
.owner = THIS_MODULE,
1221+
}, {
1222+
.name = "dcdc2",
1223+
.supply_name = "vcc2",
1224+
.of_match = of_match_ptr("dcdc2"),
1225+
.regulators_node = of_match_ptr("regulators"),
1226+
.id = RK801_ID_DCDC2,
1227+
.ops = &rk801_buck_ops,
1228+
.type = REGULATOR_VOLTAGE,
1229+
.n_voltages = 8,
1230+
.linear_ranges = rk801_buck2_voltage_ranges,
1231+
.n_linear_ranges = ARRAY_SIZE(rk801_buck2_voltage_ranges),
1232+
.vsel_reg = RK801_BUCK2_ON_VSEL_REG,
1233+
.vsel_mask = RK801_BUCK_VSEL_MASK,
1234+
.enable_reg = RK801_POWER_EN0_REG,
1235+
.enable_mask = ENABLE_MASK(RK801_ID_DCDC2),
1236+
.enable_val = ENABLE_MASK(RK801_ID_DCDC2),
1237+
.disable_val = DISABLE_VAL(RK801_ID_DCDC2),
1238+
.ramp_delay = 1000,
1239+
.of_map_mode = rk8xx_regulator_of_map_mode,
1240+
.enable_time = 400,
1241+
.owner = THIS_MODULE,
1242+
}, {
1243+
.name = "dcdc3",
1244+
.supply_name = "vcc3",
1245+
.of_match = of_match_ptr("dcdc3"),
1246+
.regulators_node = of_match_ptr("regulators"),
1247+
.id = RK801_ID_DCDC3,
1248+
.ops = &rk801_switch_ops,
1249+
.type = REGULATOR_VOLTAGE,
1250+
.n_voltages = 1,
1251+
.enable_reg = RK801_POWER_EN0_REG,
1252+
.enable_mask = ENABLE_MASK(RK801_ID_DCDC3),
1253+
.enable_val = ENABLE_MASK(RK801_ID_DCDC3),
1254+
.disable_val = DISABLE_VAL(RK801_ID_DCDC3),
1255+
.of_map_mode = rk8xx_regulator_of_map_mode,
1256+
.enable_time = 400,
1257+
.owner = THIS_MODULE,
1258+
}, {
1259+
.name = "dcdc4",
1260+
.supply_name = "vcc4",
1261+
.of_match = of_match_ptr("dcdc4"),
1262+
.regulators_node = of_match_ptr("regulators"),
1263+
.id = RK801_ID_DCDC4,
1264+
.ops = &rk801_buck_ops,
1265+
.type = REGULATOR_VOLTAGE,
1266+
.n_voltages = 87,
1267+
.linear_ranges = rk801_buck4_voltage_ranges,
1268+
.n_linear_ranges = ARRAY_SIZE(rk801_buck4_voltage_ranges),
1269+
.vsel_reg = RK801_BUCK4_ON_VSEL_REG,
1270+
.vsel_mask = RK801_BUCK_VSEL_MASK,
1271+
.enable_reg = RK801_POWER_EN0_REG,
1272+
.enable_mask = ENABLE_MASK(RK801_ID_DCDC4),
1273+
.enable_val = ENABLE_MASK(RK801_ID_DCDC4),
1274+
.disable_val = DISABLE_VAL(RK801_ID_DCDC4),
1275+
.ramp_delay = 1000,
1276+
.of_map_mode = rk8xx_regulator_of_map_mode,
1277+
.enable_time = 400,
1278+
.owner = THIS_MODULE,
1279+
},
1280+
1281+
RK801_DESC(RK801_ID_LDO1, "ldo1", "vcc5", 500, 3400, 50,
1282+
RK801_LDO1_ON_VSEL_REG, RK801_LDO_VSEL_MASK, RK801_POWER_EN1_REG,
1283+
ENABLE_MASK(0), DISABLE_VAL(0), 400),
1284+
RK801_DESC(RK801_ID_LDO2, "ldo2", "vcc6", 500, 3400, 50,
1285+
RK801_LDO2_ON_VSEL_REG, RK801_LDO_VSEL_MASK, RK801_POWER_EN1_REG,
1286+
ENABLE_MASK(1), DISABLE_VAL(1), 400),
1287+
RK801_DESC_SWITCH(RK801_ID_SWITCH, "switch", "vcc7", RK801_POWER_EN1_REG,
1288+
ENABLE_MASK(2), DISABLE_VAL(2)),
1289+
};
1290+
10521291
static const struct regulator_desc rk805_reg[] = {
10531292
{
10541293
.name = "DCDC_REG1",
@@ -1887,6 +2126,10 @@ static int rk808_regulator_probe(struct platform_device *pdev)
18872126
return -ENOMEM;
18882127

18892128
switch (rk808->variant) {
2129+
case RK801_ID:
2130+
regulators = rk801_reg;
2131+
nregulators = RK801_NUM_REGULATORS;
2132+
break;
18902133
case RK805_ID:
18912134
regulators = rk805_reg;
18922135
nregulators = RK805_NUM_REGULATORS;

0 commit comments

Comments
 (0)