regulator: qcom-smd: Batch up requests for disabled regulators

In some scenarios the early stages of the boot chain has configured
regulators to be in a required state, but the later stages has skipped
to inform the RPM about it's requirements.

But as the SMD RPM regulators are being initialized voltage change
requests will be issued to align the voltage with the valid ranges. The
RPM aggregates all parameters for the specific regulator, the voltage
will be adjusted and the "enabled" state will be "off" - and the
regulator is turned off.

This patch addresses this problem by caching the requested enable state,
voltage and load and send the parameters in a batch, depending on the
enable state - effectively delaying the voltage request for disabled
regulators.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Bjorn Andersson 2019-01-22 11:01:47 -08:00 committed by Mark Brown
parent ccffcb8e9a
commit fd805d9935
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
1 changed files with 69 additions and 35 deletions

View File

@ -31,6 +31,11 @@ struct qcom_rpm_reg {
int is_enabled; int is_enabled;
int uV; int uV;
u32 load;
unsigned int enabled_updated:1;
unsigned int uv_updated:1;
unsigned int load_updated:1;
}; };
struct rpm_regulator_req { struct rpm_regulator_req {
@ -43,30 +48,59 @@ struct rpm_regulator_req {
#define RPM_KEY_UV 0x00007675 /* "uv" */ #define RPM_KEY_UV 0x00007675 /* "uv" */
#define RPM_KEY_MA 0x0000616d /* "ma" */ #define RPM_KEY_MA 0x0000616d /* "ma" */
static int rpm_reg_write_active(struct qcom_rpm_reg *vreg, static int rpm_reg_write_active(struct qcom_rpm_reg *vreg)
struct rpm_regulator_req *req,
size_t size)
{ {
return qcom_rpm_smd_write(vreg->rpm, struct rpm_regulator_req req[3];
QCOM_SMD_RPM_ACTIVE_STATE, int reqlen = 0;
vreg->type, int ret;
vreg->id,
req, size); if (vreg->enabled_updated) {
req[reqlen].key = cpu_to_le32(RPM_KEY_SWEN);
req[reqlen].nbytes = cpu_to_le32(sizeof(u32));
req[reqlen].value = cpu_to_le32(vreg->is_enabled);
reqlen++;
}
if (vreg->uv_updated && vreg->is_enabled) {
req[reqlen].key = cpu_to_le32(RPM_KEY_UV);
req[reqlen].nbytes = cpu_to_le32(sizeof(u32));
req[reqlen].value = cpu_to_le32(vreg->uV);
reqlen++;
}
if (vreg->load_updated && vreg->is_enabled) {
req[reqlen].key = cpu_to_le32(RPM_KEY_MA);
req[reqlen].nbytes = cpu_to_le32(sizeof(u32));
req[reqlen].value = cpu_to_le32(vreg->load / 1000);
reqlen++;
}
if (!reqlen)
return 0;
ret = qcom_rpm_smd_write(vreg->rpm, QCOM_SMD_RPM_ACTIVE_STATE,
vreg->type, vreg->id,
req, sizeof(req[0]) * reqlen);
if (!ret) {
vreg->enabled_updated = 0;
vreg->uv_updated = 0;
vreg->load_updated = 0;
}
return ret;
} }
static int rpm_reg_enable(struct regulator_dev *rdev) static int rpm_reg_enable(struct regulator_dev *rdev)
{ {
struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
struct rpm_regulator_req req;
int ret; int ret;
req.key = cpu_to_le32(RPM_KEY_SWEN); vreg->is_enabled = 1;
req.nbytes = cpu_to_le32(sizeof(u32)); vreg->enabled_updated = 1;
req.value = cpu_to_le32(1);
ret = rpm_reg_write_active(vreg, &req, sizeof(req)); ret = rpm_reg_write_active(vreg);
if (!ret) if (ret)
vreg->is_enabled = 1; vreg->is_enabled = 0;
return ret; return ret;
} }
@ -81,16 +115,14 @@ static int rpm_reg_is_enabled(struct regulator_dev *rdev)
static int rpm_reg_disable(struct regulator_dev *rdev) static int rpm_reg_disable(struct regulator_dev *rdev)
{ {
struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
struct rpm_regulator_req req;
int ret; int ret;
req.key = cpu_to_le32(RPM_KEY_SWEN); vreg->is_enabled = 0;
req.nbytes = cpu_to_le32(sizeof(u32)); vreg->enabled_updated = 1;
req.value = 0;
ret = rpm_reg_write_active(vreg, &req, sizeof(req)); ret = rpm_reg_write_active(vreg);
if (!ret) if (ret)
vreg->is_enabled = 0; vreg->is_enabled = 1;
return ret; return ret;
} }
@ -108,16 +140,15 @@ static int rpm_reg_set_voltage(struct regulator_dev *rdev,
unsigned *selector) unsigned *selector)
{ {
struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
struct rpm_regulator_req req; int ret;
int ret = 0; int old_uV = vreg->uV;
req.key = cpu_to_le32(RPM_KEY_UV); vreg->uV = min_uV;
req.nbytes = cpu_to_le32(sizeof(u32)); vreg->uv_updated = 1;
req.value = cpu_to_le32(min_uV);
ret = rpm_reg_write_active(vreg, &req, sizeof(req)); ret = rpm_reg_write_active(vreg);
if (!ret) if (ret)
vreg->uV = min_uV; vreg->uV = old_uV;
return ret; return ret;
} }
@ -125,13 +156,16 @@ static int rpm_reg_set_voltage(struct regulator_dev *rdev,
static int rpm_reg_set_load(struct regulator_dev *rdev, int load_uA) static int rpm_reg_set_load(struct regulator_dev *rdev, int load_uA)
{ {
struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev); struct qcom_rpm_reg *vreg = rdev_get_drvdata(rdev);
struct rpm_regulator_req req; u32 old_load = vreg->load;
int ret;
req.key = cpu_to_le32(RPM_KEY_MA); vreg->load = load_uA;
req.nbytes = cpu_to_le32(sizeof(u32)); vreg->load_updated = 1;
req.value = cpu_to_le32(load_uA / 1000); ret = rpm_reg_write_active(vreg);
if (ret)
vreg->load = old_load;
return rpm_reg_write_active(vreg, &req, sizeof(req)); return ret;
} }
static const struct regulator_ops rpm_smps_ldo_ops = { static const struct regulator_ops rpm_smps_ldo_ops = {