summaryrefslogtreecommitdiff
path: root/drivers/regulator
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2023-04-11 16:11:32 +0100
committerMark Brown <broonie@kernel.org>2023-04-11 16:11:32 +0100
commit53e59b5c4645236f0014d3cc5c24bc71ad3f6120 (patch)
tree64c6005d6ffd496454fffb05b584ffb7011e12b4 /drivers/regulator
parent60bbee7db43b97bf8c0978cc91f78d1746351871 (diff)
parenta27e71a66ee0f887fefcc31b85a804b0905fa865 (diff)
Add support for Rockchip RK860X regulators
Merge series from Cristian Ciocaltea <cristian.ciocaltea@collabora.com>: This patch series introduces support for the Rockchip RK860X regulators, while also providing a few fixes and improvements to the existing fan53555 driver. RK8600/RK8601 are quite similar to the FAN53555 regulators. RK8602/RK8603 are a bit different, having a wider output voltage selection range, from 0.5 V to 1.5 V in 6.25 mV steps. They are used in the Rock 5B board to power the ARM Cortex-A76 cores and the NPU.
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/fan53555.c203
-rw-r--r--drivers/regulator/fixed.c2
2 files changed, 157 insertions, 48 deletions
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index d0c678767294..130f3dbe9840 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -8,23 +8,27 @@
// Copyright (c) 2012 Marvell Technology Ltd.
// Yunfan Zhang <yfzhang@marvell.com>
+#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
#include <linux/module.h>
+#include <linux/of_device.h>
#include <linux/param.h>
-#include <linux/err.h>
#include <linux/platform_device.h>
+#include <linux/regmap.h>
#include <linux/regulator/driver.h>
+#include <linux/regulator/fan53555.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/of_regulator.h>
-#include <linux/of_device.h>
-#include <linux/i2c.h>
#include <linux/slab.h>
-#include <linux/regmap.h>
-#include <linux/regulator/fan53555.h>
/* Voltage setting */
#define FAN53555_VSEL0 0x00
#define FAN53555_VSEL1 0x01
+#define RK8602_VSEL0 0x06
+#define RK8602_VSEL1 0x07
+
#define TCS4525_VSEL0 0x11
#define TCS4525_VSEL1 0x10
#define TCS4525_TIME 0x13
@@ -40,31 +44,32 @@
#define FAN53555_MONITOR 0x05
/* VSEL bit definitions */
-#define VSEL_BUCK_EN (1 << 7)
-#define VSEL_MODE (1 << 6)
+#define VSEL_BUCK_EN BIT(7)
+#define VSEL_MODE BIT(6)
/* Chip ID and Verison */
-#define DIE_ID 0x0F /* ID1 */
-#define DIE_REV 0x0F /* ID2 */
+#define DIE_ID 0x0F /* ID1 */
+#define DIE_REV 0x0F /* ID2 */
/* Control bit definitions */
-#define CTL_OUTPUT_DISCHG (1 << 7)
-#define CTL_SLEW_MASK (0x7 << 4)
-#define CTL_SLEW_SHIFT 4
-#define CTL_RESET (1 << 2)
+#define CTL_OUTPUT_DISCHG BIT(7)
+#define CTL_SLEW_MASK GENMASK(6, 4)
+#define CTL_RESET BIT(2)
#define CTL_MODE_VSEL0_MODE BIT(0)
#define CTL_MODE_VSEL1_MODE BIT(1)
#define FAN53555_NVOLTAGES 64 /* Numbers of voltages */
#define FAN53526_NVOLTAGES 128
+#define RK8602_NVOLTAGES 160
-#define TCS_VSEL0_MODE (1 << 7)
-#define TCS_VSEL1_MODE (1 << 6)
+#define TCS_VSEL0_MODE BIT(7)
+#define TCS_VSEL1_MODE BIT(6)
-#define TCS_SLEW_SHIFT 3
-#define TCS_SLEW_MASK (0x3 < 3)
+#define TCS_SLEW_MASK GENMASK(4, 3)
enum fan53555_vendor {
FAN53526_VENDOR_FAIRCHILD = 0,
FAN53555_VENDOR_FAIRCHILD,
+ FAN53555_VENDOR_ROCKCHIP, /* RK8600, RK8601 */
+ RK8602_VENDOR_ROCKCHIP, /* RK8602, RK8603 */
FAN53555_VENDOR_SILERGY,
FAN53526_VENDOR_TCS,
};
@@ -89,6 +94,14 @@ enum {
};
enum {
+ RK8600_CHIP_ID_08 = 8, /* RK8600, RK8601 */
+};
+
+enum {
+ RK8602_CHIP_ID_10 = 10, /* RK8602, RK8603 */
+};
+
+enum {
TCS4525_CHIP_ID_12 = 12,
};
@@ -118,6 +131,8 @@ struct fan53555_device_info {
/* Voltage setting register */
unsigned int vol_reg;
unsigned int sleep_reg;
+ unsigned int en_reg;
+ unsigned int sleep_en_reg;
/* Voltage range and step(linear) */
unsigned int vsel_min;
unsigned int vsel_step;
@@ -160,7 +175,7 @@ static int fan53555_set_suspend_enable(struct regulator_dev *rdev)
{
struct fan53555_device_info *di = rdev_get_drvdata(rdev);
- return regmap_update_bits(rdev->regmap, di->sleep_reg,
+ return regmap_update_bits(rdev->regmap, di->sleep_en_reg,
VSEL_BUCK_EN, VSEL_BUCK_EN);
}
@@ -168,7 +183,7 @@ static int fan53555_set_suspend_disable(struct regulator_dev *rdev)
{
struct fan53555_device_info *di = rdev_get_drvdata(rdev);
- return regmap_update_bits(rdev->regmap, di->sleep_reg,
+ return regmap_update_bits(rdev->regmap, di->sleep_en_reg,
VSEL_BUCK_EN, 0);
}
@@ -318,6 +333,50 @@ static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di)
return 0;
}
+static int fan53555_voltages_setup_rockchip(struct fan53555_device_info *di)
+{
+ /* Init voltage range and step */
+ switch (di->chip_id) {
+ case RK8600_CHIP_ID_08:
+ di->vsel_min = 712500;
+ di->vsel_step = 12500;
+ break;
+ default:
+ dev_err(di->dev,
+ "Chip ID %d not supported!\n", di->chip_id);
+ return -EINVAL;
+ }
+ di->slew_reg = FAN53555_CONTROL;
+ di->slew_mask = CTL_SLEW_MASK;
+ di->ramp_delay_table = slew_rates;
+ di->n_ramp_values = ARRAY_SIZE(slew_rates);
+ di->vsel_count = FAN53555_NVOLTAGES;
+
+ return 0;
+}
+
+static int rk8602_voltages_setup_rockchip(struct fan53555_device_info *di)
+{
+ /* Init voltage range and step */
+ switch (di->chip_id) {
+ case RK8602_CHIP_ID_10:
+ di->vsel_min = 500000;
+ di->vsel_step = 6250;
+ break;
+ default:
+ dev_err(di->dev,
+ "Chip ID %d not supported!\n", di->chip_id);
+ return -EINVAL;
+ }
+ di->slew_reg = FAN53555_CONTROL;
+ di->slew_mask = CTL_SLEW_MASK;
+ di->ramp_delay_table = slew_rates;
+ di->n_ramp_values = ARRAY_SIZE(slew_rates);
+ di->vsel_count = RK8602_NVOLTAGES;
+
+ return 0;
+}
+
static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di)
{
/* Init voltage range and step */
@@ -378,6 +437,7 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
switch (di->vendor) {
case FAN53526_VENDOR_FAIRCHILD:
case FAN53555_VENDOR_FAIRCHILD:
+ case FAN53555_VENDOR_ROCKCHIP:
case FAN53555_VENDOR_SILERGY:
switch (pdata->sleep_vsel_id) {
case FAN53555_VSEL_ID_0:
@@ -392,6 +452,27 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
dev_err(di->dev, "Invalid VSEL ID!\n");
return -EINVAL;
}
+ di->sleep_en_reg = di->sleep_reg;
+ di->en_reg = di->vol_reg;
+ break;
+ case RK8602_VENDOR_ROCKCHIP:
+ switch (pdata->sleep_vsel_id) {
+ case FAN53555_VSEL_ID_0:
+ di->sleep_reg = RK8602_VSEL0;
+ di->vol_reg = RK8602_VSEL1;
+ di->sleep_en_reg = FAN53555_VSEL0;
+ di->en_reg = FAN53555_VSEL1;
+ break;
+ case FAN53555_VSEL_ID_1:
+ di->sleep_reg = RK8602_VSEL1;
+ di->vol_reg = RK8602_VSEL0;
+ di->sleep_en_reg = FAN53555_VSEL1;
+ di->en_reg = FAN53555_VSEL0;
+ break;
+ default:
+ dev_err(di->dev, "Invalid VSEL ID!\n");
+ return -EINVAL;
+ }
break;
case FAN53526_VENDOR_TCS:
switch (pdata->sleep_vsel_id) {
@@ -407,6 +488,8 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
dev_err(di->dev, "Invalid VSEL ID!\n");
return -EINVAL;
}
+ di->sleep_en_reg = di->sleep_reg;
+ di->en_reg = di->vol_reg;
break;
default:
dev_err(di->dev, "vendor %d not supported!\n", di->vendor);
@@ -428,10 +511,23 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
}
break;
case FAN53555_VENDOR_FAIRCHILD:
+ case FAN53555_VENDOR_ROCKCHIP:
case FAN53555_VENDOR_SILERGY:
di->mode_reg = di->vol_reg;
di->mode_mask = VSEL_MODE;
break;
+ case RK8602_VENDOR_ROCKCHIP:
+ di->mode_mask = VSEL_MODE;
+
+ switch (pdata->sleep_vsel_id) {
+ case FAN53555_VSEL_ID_0:
+ di->mode_reg = FAN53555_VSEL1;
+ break;
+ case FAN53555_VSEL_ID_1:
+ di->mode_reg = FAN53555_VSEL0;
+ break;
+ }
+ break;
case FAN53526_VENDOR_TCS:
di->mode_reg = TCS4525_COMMAND;
@@ -457,6 +553,12 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
case FAN53555_VENDOR_FAIRCHILD:
ret = fan53555_voltages_setup_fairchild(di);
break;
+ case FAN53555_VENDOR_ROCKCHIP:
+ ret = fan53555_voltages_setup_rockchip(di);
+ break;
+ case RK8602_VENDOR_ROCKCHIP:
+ ret = rk8602_voltages_setup_rockchip(di);
+ break;
case FAN53555_VENDOR_SILERGY:
ret = fan53555_voltages_setup_silergy(di);
break;
@@ -482,12 +584,12 @@ static int fan53555_regulator_register(struct fan53555_device_info *di,
rdesc->ops = &fan53555_regulator_ops;
rdesc->type = REGULATOR_VOLTAGE;
rdesc->n_voltages = di->vsel_count;
- rdesc->enable_reg = di->vol_reg;
+ rdesc->enable_reg = di->en_reg;
rdesc->enable_mask = VSEL_BUCK_EN;
rdesc->min_uV = di->vsel_min;
rdesc->uV_step = di->vsel_step;
rdesc->vsel_reg = di->vol_reg;
- rdesc->vsel_mask = di->vsel_count - 1;
+ rdesc->vsel_mask = BIT(fls(di->vsel_count - 1)) - 1;
rdesc->ramp_reg = di->slew_reg;
rdesc->ramp_mask = di->slew_mask;
rdesc->ramp_delay_table = di->ramp_delay_table;
@@ -533,6 +635,12 @@ static const struct of_device_id __maybe_unused fan53555_dt_ids[] = {
.compatible = "fcs,fan53555",
.data = (void *)FAN53555_VENDOR_FAIRCHILD
}, {
+ .compatible = "rockchip,rk8600",
+ .data = (void *)FAN53555_VENDOR_ROCKCHIP
+ }, {
+ .compatible = "rockchip,rk8602",
+ .data = (void *)RK8602_VENDOR_ROCKCHIP
+ }, {
.compatible = "silergy,syr827",
.data = (void *)FAN53555_VENDOR_SILERGY,
}, {
@@ -569,10 +677,9 @@ static int fan53555_regulator_probe(struct i2c_client *client)
if (!pdata)
pdata = fan53555_parse_dt(&client->dev, np, &di->desc);
- if (!pdata || !pdata->regulator) {
- dev_err(&client->dev, "Platform data not found!\n");
- return -ENODEV;
- }
+ if (!pdata || !pdata->regulator)
+ return dev_err_probe(&client->dev, -ENODEV,
+ "Platform data not found!\n");
di->regulator = pdata->regulator;
if (client->dev.of_node) {
@@ -581,10 +688,9 @@ static int fan53555_regulator_probe(struct i2c_client *client)
} else {
/* if no ramp constraint set, get the pdata ramp_delay */
if (!di->regulator->constraints.ramp_delay) {
- if (pdata->slew_rate >= ARRAY_SIZE(slew_rates)) {
- dev_err(&client->dev, "Invalid slew_rate\n");
- return -EINVAL;
- }
+ if (pdata->slew_rate >= ARRAY_SIZE(slew_rates))
+ return dev_err_probe(&client->dev, -EINVAL,
+ "Invalid slew_rate\n");
di->regulator->constraints.ramp_delay
= slew_rates[pdata->slew_rate];
@@ -594,34 +700,31 @@ static int fan53555_regulator_probe(struct i2c_client *client)
}
regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);
- if (IS_ERR(regmap)) {
- dev_err(&client->dev, "Failed to allocate regmap!\n");
- return PTR_ERR(regmap);
- }
+ if (IS_ERR(regmap))
+ return dev_err_probe(&client->dev, PTR_ERR(regmap),
+ "Failed to allocate regmap!\n");
+
di->dev = &client->dev;
i2c_set_clientdata(client, di);
/* Get chip ID */
ret = regmap_read(regmap, FAN53555_ID1, &val);
- if (ret < 0) {
- dev_err(&client->dev, "Failed to get chip ID!\n");
- return ret;
- }
+ if (ret < 0)
+ return dev_err_probe(&client->dev, ret, "Failed to get chip ID!\n");
+
di->chip_id = val & DIE_ID;
/* Get chip revision */
ret = regmap_read(regmap, FAN53555_ID2, &val);
- if (ret < 0) {
- dev_err(&client->dev, "Failed to get chip Rev!\n");
- return ret;
- }
+ if (ret < 0)
+ return dev_err_probe(&client->dev, ret, "Failed to get chip Rev!\n");
+
di->chip_rev = val & DIE_REV;
dev_info(&client->dev, "FAN53555 Option[%d] Rev[%d] Detected!\n",
di->chip_id, di->chip_rev);
/* Device init */
ret = fan53555_device_setup(di, pdata);
- if (ret < 0) {
- dev_err(&client->dev, "Failed to setup device!\n");
- return ret;
- }
+ if (ret < 0)
+ return dev_err_probe(&client->dev, ret, "Failed to setup device!\n");
+
/* Register regulator */
config.dev = di->dev;
config.init_data = di->regulator;
@@ -631,9 +734,9 @@ static int fan53555_regulator_probe(struct i2c_client *client)
ret = fan53555_regulator_register(di, &config);
if (ret < 0)
- dev_err(&client->dev, "Failed to register regulator!\n");
- return ret;
+ dev_err_probe(&client->dev, ret, "Failed to register regulator!\n");
+ return ret;
}
static const struct i2c_device_id fan53555_id[] = {
@@ -644,6 +747,12 @@ static const struct i2c_device_id fan53555_id[] = {
.name = "fan53555",
.driver_data = FAN53555_VENDOR_FAIRCHILD
}, {
+ .name = "rk8600",
+ .driver_data = FAN53555_VENDOR_ROCKCHIP
+ }, {
+ .name = "rk8602",
+ .driver_data = RK8602_VENDOR_ROCKCHIP
+ }, {
.name = "syr827",
.driver_data = FAN53555_VENDOR_SILERGY
}, {
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index e3436f49dea4..364d1a2683b7 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -215,7 +215,7 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
drvdata->enable_clock = devm_clk_get(dev, NULL);
if (IS_ERR(drvdata->enable_clock)) {
dev_err(dev, "Can't get enable-clock from devicetree\n");
- return -ENOENT;
+ return PTR_ERR(drvdata->enable_clock);
}
} else if (drvtype && drvtype->has_performance_state) {
drvdata->desc.ops = &fixed_voltage_domain_ops;