Skip to content

Commit 5eb068d

Browse files
knaerzchelag-linaro
authored andcommitted
regulator: rk808: Add RK816 support
Add support for rk816 to the existing rk808 regulator driver. The infrastructure of the driver can be re-used as is. A peculiarity for this version is, that BUCK1/BUCK2 have a (common) bit which needs to toggled after a voltage change to confirm the change. Regulator regmap takes care of that by defining a apply_bit and apply_reg for those regulators. Signed-off-by: Alex Bee <knaerzche@gmail.com> Reviewed-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20240416161237.2500037-6-knaerzche@gmail.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 9f4e899 commit 5eb068d

1 file changed

Lines changed: 201 additions & 1 deletion

File tree

drivers/regulator/rk808-regulator.c

Lines changed: 201 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@
158158
RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
159159
_vmask, _ereg, _emask, 0, 0, _etime, &rk808_reg_ops)
160160

161+
#define RK816_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
162+
_vmask, _ereg, _emask, _disval, _etime) \
163+
RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
164+
_vmask, _ereg, _emask, _emask, _disval, _etime, &rk816_reg_ops)
165+
161166
#define RK817_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
162167
_vmask, _ereg, _emask, _disval, _etime) \
163168
RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
@@ -258,7 +263,7 @@ static const unsigned int rk808_buck1_2_ramp_table[] = {
258263
2000, 4000, 6000, 10000
259264
};
260265

261-
/* RK817 RK809 */
266+
/* RK817/RK809/RK816 (buck 1/2 only) */
262267
static const unsigned int rk817_buck1_4_ramp_table[] = {
263268
3000, 6300, 12500, 25000
264269
};
@@ -640,6 +645,38 @@ static int rk808_set_suspend_disable(struct regulator_dev *rdev)
640645
rdev->desc->enable_mask);
641646
}
642647

648+
static const struct rk8xx_register_bit rk816_suspend_bits[] = {
649+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 0),
650+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 1),
651+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 2),
652+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 3),
653+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 0),
654+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 1),
655+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 2),
656+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 3),
657+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 4),
658+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 5),
659+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 5),
660+
RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 6),
661+
};
662+
663+
static int rk816_set_suspend_enable(struct regulator_dev *rdev)
664+
{
665+
int rid = rdev_get_id(rdev);
666+
667+
return regmap_update_bits(rdev->regmap, rk816_suspend_bits[rid].reg,
668+
rk816_suspend_bits[rid].bit,
669+
rk816_suspend_bits[rid].bit);
670+
}
671+
672+
static int rk816_set_suspend_disable(struct regulator_dev *rdev)
673+
{
674+
int rid = rdev_get_id(rdev);
675+
676+
return regmap_update_bits(rdev->regmap, rk816_suspend_bits[rid].reg,
677+
rk816_suspend_bits[rid].bit, 0);
678+
}
679+
643680
static int rk817_set_suspend_enable_ctrl(struct regulator_dev *rdev,
644681
unsigned int en)
645682
{
@@ -913,6 +950,54 @@ static const struct regulator_ops rk809_buck5_ops_range = {
913950
.set_suspend_disable = rk817_set_suspend_disable,
914951
};
915952

953+
static const struct regulator_ops rk816_buck1_2_ops_ranges = {
954+
.list_voltage = regulator_list_voltage_linear_range,
955+
.map_voltage = regulator_map_voltage_linear_range,
956+
.get_voltage_sel = regulator_get_voltage_sel_regmap,
957+
.set_voltage_sel = regulator_set_voltage_sel_regmap,
958+
.set_voltage_time_sel = regulator_set_voltage_time_sel,
959+
.enable = regulator_enable_regmap,
960+
.disable = regulator_disable_regmap,
961+
.is_enabled = regulator_is_enabled_regmap,
962+
.set_mode = rk8xx_set_mode,
963+
.get_mode = rk8xx_get_mode,
964+
.set_suspend_mode = rk8xx_set_suspend_mode,
965+
.set_ramp_delay = regulator_set_ramp_delay_regmap,
966+
.set_suspend_voltage = rk808_set_suspend_voltage_range,
967+
.set_suspend_enable = rk816_set_suspend_enable,
968+
.set_suspend_disable = rk816_set_suspend_disable,
969+
};
970+
971+
static const struct regulator_ops rk816_buck4_ops_ranges = {
972+
.list_voltage = regulator_list_voltage_linear_range,
973+
.map_voltage = regulator_map_voltage_linear_range,
974+
.get_voltage_sel = regulator_get_voltage_sel_regmap,
975+
.set_voltage_sel = regulator_set_voltage_sel_regmap,
976+
.set_voltage_time_sel = regulator_set_voltage_time_sel,
977+
.enable = regulator_enable_regmap,
978+
.disable = regulator_disable_regmap,
979+
.is_enabled = regulator_is_enabled_regmap,
980+
.set_mode = rk8xx_set_mode,
981+
.get_mode = rk8xx_get_mode,
982+
.set_suspend_mode = rk8xx_set_suspend_mode,
983+
.set_suspend_voltage = rk808_set_suspend_voltage_range,
984+
.set_suspend_enable = rk816_set_suspend_enable,
985+
.set_suspend_disable = rk816_set_suspend_disable,
986+
};
987+
988+
static const struct regulator_ops rk816_reg_ops = {
989+
.list_voltage = regulator_list_voltage_linear,
990+
.map_voltage = regulator_map_voltage_linear,
991+
.get_voltage_sel = regulator_get_voltage_sel_regmap,
992+
.set_voltage_sel = regulator_set_voltage_sel_regmap,
993+
.enable = regulator_enable_regmap,
994+
.disable = regulator_disable_regmap,
995+
.is_enabled = rk8xx_is_enabled_wmsk_regmap,
996+
.set_suspend_voltage = rk808_set_suspend_voltage,
997+
.set_suspend_enable = rk816_set_suspend_enable,
998+
.set_suspend_disable = rk816_set_suspend_disable,
999+
};
1000+
9161001
static const struct regulator_ops rk817_reg_ops = {
9171002
.list_voltage = regulator_list_voltage_linear,
9181003
.map_voltage = regulator_map_voltage_linear,
@@ -1392,6 +1477,117 @@ static const struct regulator_desc rk809_reg[] = {
13921477
DISABLE_VAL(3)),
13931478
};
13941479

1480+
static const struct linear_range rk816_buck_4_voltage_ranges[] = {
1481+
REGULATOR_LINEAR_RANGE(800000, 0, 26, 100000),
1482+
REGULATOR_LINEAR_RANGE(3500000, 27, 31, 0),
1483+
};
1484+
1485+
static const struct regulator_desc rk816_reg[] = {
1486+
{
1487+
.name = "dcdc1",
1488+
.supply_name = "vcc1",
1489+
.of_match = of_match_ptr("dcdc1"),
1490+
.regulators_node = of_match_ptr("regulators"),
1491+
.id = RK816_ID_DCDC1,
1492+
.ops = &rk816_buck1_2_ops_ranges,
1493+
.type = REGULATOR_VOLTAGE,
1494+
.n_voltages = 64,
1495+
.linear_ranges = rk805_buck_1_2_voltage_ranges,
1496+
.n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges),
1497+
.vsel_reg = RK818_BUCK1_ON_VSEL_REG,
1498+
.vsel_mask = RK818_BUCK_VSEL_MASK,
1499+
.apply_reg = RK816_DCDC_EN_REG2,
1500+
.apply_bit = RK816_BUCK_DVS_CONFIRM,
1501+
.enable_reg = RK816_DCDC_EN_REG1,
1502+
.enable_mask = BIT(4) | BIT(0),
1503+
.enable_val = BIT(4) | BIT(0),
1504+
.disable_val = BIT(4),
1505+
.ramp_reg = RK818_BUCK1_CONFIG_REG,
1506+
.ramp_mask = RK808_RAMP_RATE_MASK,
1507+
.ramp_delay_table = rk817_buck1_4_ramp_table,
1508+
.n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1509+
.of_map_mode = rk8xx_regulator_of_map_mode,
1510+
.owner = THIS_MODULE,
1511+
}, {
1512+
.name = "dcdc2",
1513+
.supply_name = "vcc2",
1514+
.of_match = of_match_ptr("dcdc2"),
1515+
.regulators_node = of_match_ptr("regulators"),
1516+
.id = RK816_ID_DCDC2,
1517+
.ops = &rk816_buck1_2_ops_ranges,
1518+
.type = REGULATOR_VOLTAGE,
1519+
.n_voltages = 64,
1520+
.linear_ranges = rk805_buck_1_2_voltage_ranges,
1521+
.n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges),
1522+
.vsel_reg = RK818_BUCK2_ON_VSEL_REG,
1523+
.vsel_mask = RK818_BUCK_VSEL_MASK,
1524+
.apply_reg = RK816_DCDC_EN_REG2,
1525+
.apply_bit = RK816_BUCK_DVS_CONFIRM,
1526+
.enable_reg = RK816_DCDC_EN_REG1,
1527+
.enable_mask = BIT(5) | BIT(1),
1528+
.enable_val = BIT(5) | BIT(1),
1529+
.disable_val = BIT(5),
1530+
.ramp_reg = RK818_BUCK2_CONFIG_REG,
1531+
.ramp_mask = RK808_RAMP_RATE_MASK,
1532+
.ramp_delay_table = rk817_buck1_4_ramp_table,
1533+
.n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1534+
.of_map_mode = rk8xx_regulator_of_map_mode,
1535+
.owner = THIS_MODULE,
1536+
}, {
1537+
.name = "dcdc3",
1538+
.supply_name = "vcc3",
1539+
.of_match = of_match_ptr("dcdc3"),
1540+
.regulators_node = of_match_ptr("regulators"),
1541+
.id = RK816_ID_DCDC3,
1542+
.ops = &rk808_switch_ops,
1543+
.type = REGULATOR_VOLTAGE,
1544+
.n_voltages = 1,
1545+
.enable_reg = RK816_DCDC_EN_REG1,
1546+
.enable_mask = BIT(6) | BIT(2),
1547+
.enable_val = BIT(6) | BIT(2),
1548+
.disable_val = BIT(6),
1549+
.of_map_mode = rk8xx_regulator_of_map_mode,
1550+
.owner = THIS_MODULE,
1551+
}, {
1552+
.name = "dcdc4",
1553+
.supply_name = "vcc4",
1554+
.of_match = of_match_ptr("dcdc4"),
1555+
.regulators_node = of_match_ptr("regulators"),
1556+
.id = RK816_ID_DCDC4,
1557+
.ops = &rk816_buck4_ops_ranges,
1558+
.type = REGULATOR_VOLTAGE,
1559+
.n_voltages = 32,
1560+
.linear_ranges = rk816_buck_4_voltage_ranges,
1561+
.n_linear_ranges = ARRAY_SIZE(rk816_buck_4_voltage_ranges),
1562+
.vsel_reg = RK818_BUCK4_ON_VSEL_REG,
1563+
.vsel_mask = RK818_BUCK4_VSEL_MASK,
1564+
.enable_reg = RK816_DCDC_EN_REG1,
1565+
.enable_mask = BIT(7) | BIT(3),
1566+
.enable_val = BIT(7) | BIT(3),
1567+
.disable_val = BIT(7),
1568+
.of_map_mode = rk8xx_regulator_of_map_mode,
1569+
.owner = THIS_MODULE,
1570+
},
1571+
RK816_DESC(RK816_ID_LDO1, "ldo1", "vcc5", 800, 3400, 100,
1572+
RK818_LDO1_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1573+
RK816_LDO_EN_REG1, ENABLE_MASK(0), DISABLE_VAL(0), 400),
1574+
RK816_DESC(RK816_ID_LDO2, "ldo2", "vcc5", 800, 3400, 100,
1575+
RK818_LDO2_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1576+
RK816_LDO_EN_REG1, ENABLE_MASK(1), DISABLE_VAL(1), 400),
1577+
RK816_DESC(RK816_ID_LDO3, "ldo3", "vcc5", 800, 3400, 100,
1578+
RK818_LDO3_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1579+
RK816_LDO_EN_REG1, ENABLE_MASK(2), DISABLE_VAL(2), 400),
1580+
RK816_DESC(RK816_ID_LDO4, "ldo4", "vcc6", 800, 3400, 100,
1581+
RK818_LDO4_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1582+
RK816_LDO_EN_REG1, ENABLE_MASK(3), DISABLE_VAL(3), 400),
1583+
RK816_DESC(RK816_ID_LDO5, "ldo5", "vcc6", 800, 3400, 100,
1584+
RK818_LDO5_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1585+
RK816_LDO_EN_REG2, ENABLE_MASK(0), DISABLE_VAL(0), 400),
1586+
RK816_DESC(RK816_ID_LDO6, "ldo6", "vcc6", 800, 3400, 100,
1587+
RK818_LDO6_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1588+
RK816_LDO_EN_REG2, ENABLE_MASK(1), DISABLE_VAL(1), 400),
1589+
};
1590+
13951591
static const struct regulator_desc rk817_reg[] = {
13961592
{
13971593
.name = "DCDC_REG1",
@@ -1714,6 +1910,10 @@ static int rk808_regulator_probe(struct platform_device *pdev)
17141910
regulators = rk809_reg;
17151911
nregulators = RK809_NUM_REGULATORS;
17161912
break;
1913+
case RK816_ID:
1914+
regulators = rk816_reg;
1915+
nregulators = ARRAY_SIZE(rk816_reg);
1916+
break;
17171917
case RK817_ID:
17181918
regulators = rk817_reg;
17191919
nregulators = RK817_NUM_REGULATORS;

0 commit comments

Comments
 (0)