// SPDX-License-Identifier: GPL-2.0-or-later /* * OF helpers for regulator framework * * Copyright (C) 2011 Texas Instruments, Inc. * Rajendra Nayak <[email protected]> */ #include <linux/module.h> #include <linux/slab.h> #include <linux/of.h> #include <linux/regulator/machine.h> #include <linux/regulator/driver.h> #include <linux/regulator/of_regulator.h> #include "internal.h" static const char *const regulator_states[PM_SUSPEND_MAX + 1] = …; static void fill_limit(int *limit, int val) { … } static void of_get_regulator_prot_limits(struct device_node *np, struct regulation_constraints *constraints) { … } static int of_get_regulation_constraints(struct device *dev, struct device_node *np, struct regulator_init_data **init_data, const struct regulator_desc *desc) { … } /** * of_get_regulator_init_data - extract regulator_init_data structure info * @dev: device requesting for regulator_init_data * @node: regulator device node * @desc: regulator description * * Populates regulator_init_data structure by extracting data from device * tree node, returns a pointer to the populated structure or NULL if memory * alloc fails. */ struct regulator_init_data *of_get_regulator_init_data(struct device *dev, struct device_node *node, const struct regulator_desc *desc) { … } EXPORT_SYMBOL_GPL(…); struct devm_of_regulator_matches { … }; static void devm_of_regulator_put_matches(struct device *dev, void *res) { … } /** * of_regulator_match - extract multiple regulator init data from device tree. * @dev: device requesting the data * @node: parent device node of the regulators * @matches: match table for the regulators * @num_matches: number of entries in match table * * This function uses a match table specified by the regulator driver to * parse regulator init data from the device tree. @node is expected to * contain a set of child nodes, each providing the init data for one * regulator. The data parsed from a child node will be matched to a regulator * based on either the deprecated property regulator-compatible if present, * or otherwise the child node's name. Note that the match table is modified * in place and an additional of_node reference is taken for each matched * regulator. * * Returns the number of matches found or a negative error code on failure. */ int of_regulator_match(struct device *dev, struct device_node *node, struct of_regulator_match *matches, unsigned int num_matches) { … } EXPORT_SYMBOL_GPL(…); static struct device_node *regulator_of_get_init_node(struct device *dev, const struct regulator_desc *desc) { … } struct regulator_init_data *regulator_of_get_init_data(struct device *dev, const struct regulator_desc *desc, struct regulator_config *config, struct device_node **node) { … } struct regulator_dev *of_find_regulator_by_node(struct device_node *np) { … } /* * Returns number of regulators coupled with rdev. */ int of_get_n_coupled(struct regulator_dev *rdev) { … } /* Looks for "to_find" device_node in src's "regulator-coupled-with" property */ static bool of_coupling_find_node(struct device_node *src, struct device_node *to_find, int *index) { … } /** * of_check_coupling_data - Parse rdev's coupling properties and check data * consistency * @rdev: pointer to regulator_dev whose data is checked * * Function checks if all the following conditions are met: * - rdev's max_spread is greater than 0 * - all coupled regulators have the same max_spread * - all coupled regulators have the same number of regulator_dev phandles * - all regulators are linked to each other * * Returns true if all conditions are met. */ bool of_check_coupling_data(struct regulator_dev *rdev) { … } /** * of_parse_coupled_regulator() - Get regulator_dev pointer from rdev's property * @rdev: Pointer to regulator_dev, whose DTS is used as a source to parse * "regulator-coupled-with" property * @index: Index in phandles array * * Returns the regulator_dev pointer parsed from DTS. If it has not been yet * registered, returns NULL */ struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev, int index) { … } /* * Check if name is a supply name according to the '*-supply' pattern * return 0 if false * return length of supply name without the -supply */ static int is_supply_name(const char *name) { … } /* * of_regulator_bulk_get_all - get multiple regulator consumers * * @dev: Device to supply * @np: device node to search for consumers * @consumers: Configuration of consumers; clients are stored here. * * @return number of regulators on success, an errno on failure. * * This helper function allows drivers to get several regulator * consumers in one operation. If any of the regulators cannot be * acquired then any regulators that were allocated will be freed * before returning to the caller. */ int of_regulator_bulk_get_all(struct device *dev, struct device_node *np, struct regulator_bulk_data **consumers) { … } EXPORT_SYMBOL_GPL(…);