svn commit: r354396 - in head/sys: arm/allwinner arm64/rockchip dev/extres/regulator
Emmanuel Vadot
manu at FreeBSD.org
Wed Nov 6 14:55:26 UTC 2019
Author: manu
Date: Wed Nov 6 14:55:24 2019
New Revision: 354396
URL: https://svnweb.freebsd.org/changeset/base/354396
Log:
regulator: Add regulator_check_voltage function
This function will call the regnode_check_voltage method for a given regulator
and check if the desired voltage in reachable by it.
Also adds a default method that check the std_param and which should be enough
for most regulators and add it as the method for axp* rk805 and fixed regulators.
Reviewed by: mmel
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D22260
Modified:
head/sys/arm/allwinner/axp209.c
head/sys/arm/allwinner/axp81x.c
head/sys/arm64/rockchip/rk805.c
head/sys/dev/extres/regulator/regnode_if.m
head/sys/dev/extres/regulator/regulator.c
head/sys/dev/extres/regulator/regulator.h
head/sys/dev/extres/regulator/regulator_fixed.c
Modified: head/sys/arm/allwinner/axp209.c
==============================================================================
--- head/sys/arm/allwinner/axp209.c Wed Nov 6 14:43:35 2019 (r354395)
+++ head/sys/arm/allwinner/axp209.c Wed Nov 6 14:55:24 2019 (r354396)
@@ -753,6 +753,7 @@ static regnode_method_t axp2xx_regnode_methods[] = {
REGNODEMETHOD(regnode_enable, axp2xx_regnode_enable),
REGNODEMETHOD(regnode_set_voltage, axp2xx_regnode_set_voltage),
REGNODEMETHOD(regnode_get_voltage, axp2xx_regnode_get_voltage),
+ REGNODEMETHOD(regnode_check_voltage, regnode_method_check_voltage),
REGNODEMETHOD_END
};
DEFINE_CLASS_1(axp2xx_regnode, axp2xx_regnode_class, axp2xx_regnode_methods,
Modified: head/sys/arm/allwinner/axp81x.c
==============================================================================
--- head/sys/arm/allwinner/axp81x.c Wed Nov 6 14:43:35 2019 (r354395)
+++ head/sys/arm/allwinner/axp81x.c Wed Nov 6 14:55:24 2019 (r354396)
@@ -866,6 +866,7 @@ static regnode_method_t axp8xx_regnode_methods[] = {
REGNODEMETHOD(regnode_enable, axp8xx_regnode_enable),
REGNODEMETHOD(regnode_set_voltage, axp8xx_regnode_set_voltage),
REGNODEMETHOD(regnode_get_voltage, axp8xx_regnode_get_voltage),
+ REGNODEMETHOD(regnode_check_voltage, regnode_method_check_voltage),
REGNODEMETHOD_END
};
DEFINE_CLASS_1(axp8xx_regnode, axp8xx_regnode_class, axp8xx_regnode_methods,
Modified: head/sys/arm64/rockchip/rk805.c
==============================================================================
--- head/sys/arm64/rockchip/rk805.c Wed Nov 6 14:43:35 2019 (r354395)
+++ head/sys/arm64/rockchip/rk805.c Wed Nov 6 14:55:24 2019 (r354396)
@@ -362,6 +362,7 @@ static regnode_method_t rk805_regnode_methods[] = {
REGNODEMETHOD(regnode_enable, rk805_regnode_enable),
REGNODEMETHOD(regnode_set_voltage, rk805_regnode_set_voltage),
REGNODEMETHOD(regnode_get_voltage, rk805_regnode_get_voltage),
+ REGNODEMETHOD(regnode_check_voltage, regnode_method_check_voltage),
REGNODEMETHOD_END
};
DEFINE_CLASS_1(rk805_regnode, rk805_regnode_class, rk805_regnode_methods,
Modified: head/sys/dev/extres/regulator/regnode_if.m
==============================================================================
--- head/sys/dev/extres/regulator/regnode_if.m Wed Nov 6 14:43:35 2019 (r354395)
+++ head/sys/dev/extres/regulator/regnode_if.m Wed Nov 6 14:55:24 2019 (r354396)
@@ -91,6 +91,15 @@ METHOD int get_voltage {
};
#
+# Check if a given voltage is supported by the regulator
+# Returns 0 on success or a standard errno value.
+#
+METHOD int check_voltage {
+ struct regnode *regnode;
+ int uvolt;
+};
+
+#
# Stop (shutdown) regulator
# Returns 0 on success or a standard errno value.
#
Modified: head/sys/dev/extres/regulator/regulator.c
==============================================================================
--- head/sys/dev/extres/regulator/regulator.c Wed Nov 6 14:43:35 2019 (r354395)
+++ head/sys/dev/extres/regulator/regulator.c Wed Nov 6 14:55:24 2019 (r354396)
@@ -84,6 +84,7 @@ static regnode_method_t regnode_methods[] = {
REGNODEMETHOD(regnode_status, regnode_method_status),
REGNODEMETHOD(regnode_set_voltage, regnode_method_set_voltage),
REGNODEMETHOD(regnode_get_voltage, regnode_method_get_voltage),
+ REGNODEMETHOD(regnode_check_voltage, regnode_method_check_voltage),
REGNODEMETHOD_END
};
@@ -278,6 +279,16 @@ regnode_method_get_voltage(struct regnode *regnode, in
(regnode->std_param.max_uvolt - regnode->std_param.min_uvolt) / 2);
}
+int
+regnode_method_check_voltage(struct regnode *regnode, int uvolt)
+{
+
+ if ((uvolt > regnode->std_param.max_uvolt) ||
+ (uvolt < regnode->std_param.min_uvolt))
+ return (ERANGE);
+ return (0);
+}
+
/* ----------------------------------------------------------------------------
*
* Internal functions.
@@ -991,6 +1002,22 @@ regulator_set_voltage(regulator_t reg, int min_uvolt,
reg->min_uvolt = min_uvolt;
reg->max_uvolt = max_uvolt;
}
+ REG_TOPO_UNLOCK();
+ return (rv);
+}
+
+int
+regulator_check_voltage(regulator_t reg, int uvolt)
+{
+ int rv;
+ struct regnode *regnode;
+
+ regnode = reg->regnode;
+ KASSERT(regnode->ref_cnt > 0,
+ ("Attempt to access unreferenced regulator: %s\n", regnode->name));
+
+ REG_TOPO_SLOCK();
+ rv = REGNODE_CHECK_VOLTAGE(regnode, uvolt);
REG_TOPO_UNLOCK();
return (rv);
}
Modified: head/sys/dev/extres/regulator/regulator.h
==============================================================================
--- head/sys/dev/extres/regulator/regulator.h Wed Nov 6 14:43:35 2019 (r354395)
+++ head/sys/dev/extres/regulator/regulator.h Wed Nov 6 14:55:24 2019 (r354396)
@@ -117,6 +117,10 @@ int regnode_status(struct regnode *regnode, int *statu
int regnode_get_voltage(struct regnode *regnode, int *uvolt);
int regnode_set_voltage(struct regnode *regnode, int min_uvolt, int max_uvolt);
int regnode_set_constraint(struct regnode *regnode);
+
+/* Standard method that aren't default */
+int regnode_method_check_voltage(struct regnode *regnode, int uvolt);
+
#ifdef FDT
phandle_t regnode_get_ofw_node(struct regnode *regnode);
#endif
@@ -134,6 +138,7 @@ int regulator_stop(regulator_t reg);
int regulator_status(regulator_t reg, int *status);
int regulator_get_voltage(regulator_t reg, int *uvolt);
int regulator_set_voltage(regulator_t reg, int min_uvolt, int max_uvolt);
+int regulator_check_voltage(regulator_t reg, int uvolt);
#ifdef FDT
int regulator_get_by_ofw_property(device_t dev, phandle_t node, char *name,
Modified: head/sys/dev/extres/regulator/regulator_fixed.c
==============================================================================
--- head/sys/dev/extres/regulator/regulator_fixed.c Wed Nov 6 14:43:35 2019 (r354395)
+++ head/sys/dev/extres/regulator/regulator_fixed.c Wed Nov 6 14:55:24 2019 (r354396)
@@ -80,6 +80,7 @@ static regnode_method_t regnode_fixed_methods[] = {
REGNODEMETHOD(regnode_enable, regnode_fixed_enable),
REGNODEMETHOD(regnode_status, regnode_fixed_status),
REGNODEMETHOD(regnode_stop, regnode_fixed_stop),
+ REGNODEMETHOD(regnode_check_voltage, regnode_method_check_voltage),
REGNODEMETHOD_END
};
DEFINE_CLASS_1(regnode_fixed, regnode_fixed_class, regnode_fixed_methods,
More information about the svn-src-all
mailing list