regulator: qpnp: Add property to override type registers
On some regulator hardware, the values read on SPMI offset 0x4 (type)
and 0x5 (subtype) are incorrect. Add a new optional property called
qcom,force-type that allows a user to override the hardware values
with values supplied in the Device Tree.
Change-Id: Id73fe69873f5dc9d0f2623771872aa2eaddd66f1
Signed-off-by: Michael Bohan <mbohan@codeaurora.org>
diff --git a/Documentation/devicetree/bindings/regulator/qpnp-regulator.txt b/Documentation/devicetree/bindings/regulator/qpnp-regulator.txt
index c9bc284..2116888 100644
--- a/Documentation/devicetree/bindings/regulator/qpnp-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/qpnp-regulator.txt
@@ -76,11 +76,13 @@
1 = 0.25 uA
2 = 0.55 uA
3 = 0.75 uA
-
-- spmi-dev-container: This specifies that all the device nodes specified
- within this node should have their resources coalesced into a single
- spmi_device. This is used to specify all SPMI peripherals that
- logically make up a single regulator device.
+- qcom,force-type: Override the type and subtype register values. Useful for some
+ regulators that have invalid types advertised by the hardware.
+ The format is two unsigned integers of the form <type subtype>.
+- spmi-dev-container: Specifies that all the device nodes specified
+ within this node should have their resources coalesced into a
+ single spmi_device. This is used to specify all SPMI peripherals
+ that logically make up a single regulator device.
Note, if a given optional qcom,* binding is not present, then the qpnp-regulator
driver will leave that feature in the default hardware state.
diff --git a/drivers/regulator/qpnp-regulator.c b/drivers/regulator/qpnp-regulator.c
index f8176b9..0e836c7 100644
--- a/drivers/regulator/qpnp-regulator.c
+++ b/drivers/regulator/qpnp-regulator.c
@@ -982,16 +982,26 @@
static int qpnp_regulator_match(struct qpnp_regulator *vreg)
{
const struct qpnp_regulator_mapping *mapping;
+ struct device_node *node = vreg->spmi_dev->dev.of_node;
int rc, i;
u8 raw_type[2], type, subtype;
+ u32 type_reg[2];
- rc = qpnp_vreg_read(vreg, QPNP_COMMON_REG_TYPE, raw_type, 2);
- if (rc) {
- vreg_err(vreg, "could not read type register, rc=%d\n", rc);
- return rc;
+ rc = of_property_read_u32_array(node, "qcom,force-type",
+ type_reg, 2);
+ if (!rc) {
+ type = type_reg[0];
+ subtype = type_reg[1];
+ } else {
+ rc = qpnp_vreg_read(vreg, QPNP_COMMON_REG_TYPE, raw_type, 2);
+ if (rc) {
+ vreg_err(vreg,
+ "could not read type register, rc=%d\n", rc);
+ return rc;
+ }
+ type = raw_type[0];
+ subtype = raw_type[1];
}
- type = raw_type[0];
- subtype = raw_type[1];
rc = -ENODEV;
for (i = 0; i < ARRAY_SIZE(supported_regulators); i++) {