Re: [RFC PATCH 09/11] DT: regulator: Helper to extract regulator node based on supply name
On Friday 16 September 2011 04:33 AM, Mark Brown wrote: On Thu, Sep 15, 2011 at 04:50:35PM -0600, Grant Likely wrote: We've got two competing approaches here. For reg and interrupts, the proposal on the table that we talked about at LPC is to do reg-names and interrupts-names so as to preserve the existing semantics of the reg and interrupts properties. For gpios we're using the binding name-gpios for named gpio references. There isn't the same pressure to preserve existing bindings in that case. I'm okay with either approach, providing that -regulator is encoded into the name. I think I prefer the latter but I'm probably not too fussed. I'd rather use something like -supply for these just on the basis that you don't always connect things to regulators (for example, speaker supplies are generally attached direct to the battery). Ok, I'll go with name-supply then. -- To unsubscribe from this list: send the line unsubscribe linux-omap in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[RFC PATCH 09/11] DT: regulator: Helper to extract regulator node based on supply name
Device nodes in DT can associate themselves with one or more regulators by providing a list of phandles (to regulator nodes) and corresponding supply names. For Example: devicenode: node@0x0 { ... ... regulator = regulator1,regulator2; regulator-names = supply1,supply2; }; of_get_regulator() extracts the regulator node for a given device, based on the supply name. Signed-off-by: Rajendra Nayak rna...@ti.com --- drivers/of/of_regulator.c| 37 + include/linux/of_regulator.h |7 +++ 2 files changed, 44 insertions(+), 0 deletions(-) diff --git a/drivers/of/of_regulator.c b/drivers/of/of_regulator.c index 4d7a49d..6f8fd4e 100644 --- a/drivers/of/of_regulator.c +++ b/drivers/of/of_regulator.c @@ -114,3 +114,40 @@ struct fixed_voltage_config *of_get_fixed_voltage_config(struct device_node *np) return config; } EXPORT_SYMBOL(of_get_fixed_voltage_config); + +/** + * of_get_regulator - get a regulator device node based on supply name + * @dev: Device pointer for the consumer (of regulator) device + * @supply: regulator supply name + * + * Extract the regulator device node corresponding to the supply name. + * retruns the device node corresponding to the regulator if found, else + * returns NULL. + */ +struct device_node *of_get_regulator(struct device *dev, const char *supply) +{ + struct device_node *regnode = NULL; + u32 reghandle; + int regsz, namesz; + const void *regprop; + const char *namesprop; + + regprop = of_get_property(dev-of_node, regulator, regsz); + namesprop = of_get_property(dev-of_node, regulator-names, namesz); + if (!regprop || !namesprop) + return NULL; + + while (regsz namesz) { + if (!strcmp(namesprop, supply)) { + reghandle = be32_to_cpup(regprop); + regnode = of_find_node_by_phandle(reghandle); + break; + } + regsz -= 4; + regprop += 4; + namesz -= strlen(namesprop) + 1; + namesprop += strlen(namesprop) + 1; + } + return regnode; +} +EXPORT_SYMBOL(of_get_regulator); diff --git a/include/linux/of_regulator.h b/include/linux/of_regulator.h index 39860c5..5fc7329 100644 --- a/include/linux/of_regulator.h +++ b/include/linux/of_regulator.h @@ -13,6 +13,8 @@ extern struct regulator_init_data *of_get_regulator_init_data(struct device_node *np); extern struct fixed_voltage_config *of_get_fixed_voltage_config(struct device_node *np); +extern struct device_node *of_get_regulator(struct device *dev, + const char *id); #else static inline struct regulator_init_data *of_get_regulator_init_data(struct device_node *np) @@ -24,6 +26,11 @@ static inline struct fixed_voltage_config { return NULL; } +static inline struct device_node *of_get_regulator(struct device *dev, + const char *id) +{ + return NULL; +} #endif /* CONFIG_OF_REGULATOR */ #endif /* __LINUX_OF_REG_H */ -- 1.7.1 -- To unsubscribe from this list: send the line unsubscribe linux-omap in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH 09/11] DT: regulator: Helper to extract regulator node based on supply name
On Thu, Sep 15, 2011 at 04:52:05PM +0530, Rajendra Nayak wrote: regulator = regulator1,regulator2; regulator-names = supply1,supply2; }; This syntax is really painful - we're relying on keeping two arrays in sync which isn't good for legibility or robustness. I'd expect something like having a property with the supply name referencing the regulator node concerned like: dbvdd = regulator1; dcvdd = regulator2; or something. Keeping the two arrays separate doesn't seem great. -- To unsubscribe from this list: send the line unsubscribe linux-omap in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH 09/11] DT: regulator: Helper to extract regulator node based on supply name
On Thu, Sep 15, 2011 at 02:54:16PM +0100, Mark Brown wrote: On Thu, Sep 15, 2011 at 04:52:05PM +0530, Rajendra Nayak wrote: regulator = regulator1,regulator2; regulator-names = supply1,supply2; }; This syntax is really painful - we're relying on keeping two arrays in sync which isn't good for legibility or robustness. I'd expect something like having a property with the supply name referencing the regulator node concerned like: dbvdd = regulator1; dcvdd = regulator2; or something. Keeping the two arrays separate doesn't seem great. We've got two competing approaches here. For reg and interrupts, the proposal on the table that we talked about at LPC is to do reg-names and interrupts-names so as to preserve the existing semantics of the reg and interrupts properties. For gpios we're using the binding name-gpios for named gpio references. There isn't the same pressure to preserve existing bindings in that case. I'm okay with either approach, providing that -regulator is encoded into the name. g. -- To unsubscribe from this list: send the line unsubscribe linux-omap in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH 09/11] DT: regulator: Helper to extract regulator node based on supply name
On Thu, Sep 15, 2011 at 04:50:35PM -0600, Grant Likely wrote: We've got two competing approaches here. For reg and interrupts, the proposal on the table that we talked about at LPC is to do reg-names and interrupts-names so as to preserve the existing semantics of the reg and interrupts properties. For gpios we're using the binding name-gpios for named gpio references. There isn't the same pressure to preserve existing bindings in that case. I'm okay with either approach, providing that -regulator is encoded into the name. I think I prefer the latter but I'm probably not too fussed. I'd rather use something like -supply for these just on the basis that you don't always connect things to regulators (for example, speaker supplies are generally attached direct to the battery). -- To unsubscribe from this list: send the line unsubscribe linux-omap in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html