// SPDX-License-Identifier: GPL-2.0-or-later // // helpers.c -- Voltage/Current Regulator framework helper functions. // // Copyright 2007, 2008 Wolfson Microelectronics PLC. // Copyright 2008 SlimLogic Ltd. #include <linux/bitops.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/export.h> #include <linux/kernel.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/regulator/driver.h> #include "internal.h" /** * regulator_is_enabled_regmap - standard is_enabled() for regmap users * * @rdev: regulator to operate on * * Regulators that use regmap for their register I/O can set the * enable_reg and enable_mask fields in their descriptor and then use * this as their is_enabled operation, saving some code. */ int regulator_is_enabled_regmap(struct regulator_dev *rdev) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_enable_regmap - standard enable() for regmap users * * @rdev: regulator to operate on * * Regulators that use regmap for their register I/O can set the * enable_reg and enable_mask fields in their descriptor and then use * this as their enable() operation, saving some code. */ int regulator_enable_regmap(struct regulator_dev *rdev) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_disable_regmap - standard disable() for regmap users * * @rdev: regulator to operate on * * Regulators that use regmap for their register I/O can set the * enable_reg and enable_mask fields in their descriptor and then use * this as their disable() operation, saving some code. */ int regulator_disable_regmap(struct regulator_dev *rdev) { … } EXPORT_SYMBOL_GPL(…); static int regulator_range_selector_to_index(struct regulator_dev *rdev, unsigned int rval) { … } /** * regulator_get_voltage_sel_pickable_regmap - pickable range get_voltage_sel * * @rdev: regulator to operate on * * Regulators that use regmap for their register I/O and use pickable * ranges can set the vsel_reg, vsel_mask, vsel_range_reg and vsel_range_mask * fields in their descriptor and then use this as their get_voltage_vsel * operation, saving some code. */ int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev) { … } EXPORT_SYMBOL_GPL(…); static int write_separate_vsel_and_range(struct regulator_dev *rdev, unsigned int sel, unsigned int range) { … } /** * regulator_set_voltage_sel_pickable_regmap - pickable range set_voltage_sel * * @rdev: regulator to operate on * @sel: Selector to set * * Regulators that use regmap for their register I/O and use pickable * ranges can set the vsel_reg, vsel_mask, vsel_range_reg and vsel_range_mask * fields in their descriptor and then use this as their set_voltage_vsel * operation, saving some code. */ int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev, unsigned int sel) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_get_voltage_sel_regmap - standard get_voltage_sel for regmap users * * @rdev: regulator to operate on * * Regulators that use regmap for their register I/O can set the * vsel_reg and vsel_mask fields in their descriptor and then use this * as their get_voltage_vsel operation, saving some code. */ int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_set_voltage_sel_regmap - standard set_voltage_sel for regmap users * * @rdev: regulator to operate on * @sel: Selector to set * * Regulators that use regmap for their register I/O can set the * vsel_reg and vsel_mask fields in their descriptor and then use this * as their set_voltage_vsel operation, saving some code. */ int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_map_voltage_iterate - map_voltage() based on list_voltage() * * @rdev: Regulator to operate on * @min_uV: Lower bound for voltage * @max_uV: Upper bound for voltage * * Drivers implementing set_voltage_sel() and list_voltage() can use * this as their map_voltage() operation. It will find a suitable * voltage by calling list_voltage() until it gets something in bounds * for the requested voltages. */ int regulator_map_voltage_iterate(struct regulator_dev *rdev, int min_uV, int max_uV) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_map_voltage_ascend - map_voltage() for ascendant voltage list * * @rdev: Regulator to operate on * @min_uV: Lower bound for voltage * @max_uV: Upper bound for voltage * * Drivers that have ascendant voltage list can use this as their * map_voltage() operation. */ int regulator_map_voltage_ascend(struct regulator_dev *rdev, int min_uV, int max_uV) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_map_voltage_linear - map_voltage() for simple linear mappings * * @rdev: Regulator to operate on * @min_uV: Lower bound for voltage * @max_uV: Upper bound for voltage * * Drivers providing min_uV and uV_step in their regulator_desc can * use this as their map_voltage() operation. */ int regulator_map_voltage_linear(struct regulator_dev *rdev, int min_uV, int max_uV) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_map_voltage_linear_range - map_voltage() for multiple linear ranges * * @rdev: Regulator to operate on * @min_uV: Lower bound for voltage * @max_uV: Upper bound for voltage * * Drivers providing linear_ranges in their descriptor can use this as * their map_voltage() callback. */ int regulator_map_voltage_linear_range(struct regulator_dev *rdev, int min_uV, int max_uV) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_map_voltage_pickable_linear_range - map_voltage, pickable ranges * * @rdev: Regulator to operate on * @min_uV: Lower bound for voltage * @max_uV: Upper bound for voltage * * Drivers providing pickable linear_ranges in their descriptor can use * this as their map_voltage() callback. */ int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev, int min_uV, int max_uV) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_desc_list_voltage_linear - List voltages with simple calculation * * @desc: Regulator desc for regulator which volatges are to be listed * @selector: Selector to convert into a voltage * * Regulators with a simple linear mapping between voltages and * selectors can set min_uV and uV_step in the regulator descriptor * and then use this function prior regulator registration to list * the voltages. This is useful when voltages need to be listed during * device-tree parsing. */ int regulator_desc_list_voltage_linear(const struct regulator_desc *desc, unsigned int selector) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_list_voltage_linear - List voltages with simple calculation * * @rdev: Regulator device * @selector: Selector to convert into a voltage * * Regulators with a simple linear mapping between voltages and * selectors can set min_uV and uV_step in the regulator descriptor * and then use this function as their list_voltage() operation, */ int regulator_list_voltage_linear(struct regulator_dev *rdev, unsigned int selector) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_list_voltage_pickable_linear_range - pickable range list voltages * * @rdev: Regulator device * @selector: Selector to convert into a voltage * * list_voltage() operation, intended to be used by drivers utilizing pickable * ranges helpers. */ int regulator_list_voltage_pickable_linear_range(struct regulator_dev *rdev, unsigned int selector) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_desc_list_voltage_linear_range - List voltages for linear ranges * * @desc: Regulator desc for regulator which volatges are to be listed * @selector: Selector to convert into a voltage * * Regulators with a series of simple linear mappings between voltages * and selectors who have set linear_ranges in the regulator descriptor * can use this function prior regulator registration to list voltages. * This is useful when voltages need to be listed during device-tree * parsing. */ int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc, unsigned int selector) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_list_voltage_linear_range - List voltages for linear ranges * * @rdev: Regulator device * @selector: Selector to convert into a voltage * * Regulators with a series of simple linear mappings between voltages * and selectors can set linear_ranges in the regulator descriptor and * then use this function as their list_voltage() operation, */ int regulator_list_voltage_linear_range(struct regulator_dev *rdev, unsigned int selector) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_list_voltage_table - List voltages with table based mapping * * @rdev: Regulator device * @selector: Selector to convert into a voltage * * Regulators with table based mapping between voltages and * selectors can set volt_table in the regulator descriptor * and then use this function as their list_voltage() operation. */ int regulator_list_voltage_table(struct regulator_dev *rdev, unsigned int selector) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_set_bypass_regmap - Default set_bypass() using regmap * * @rdev: device to operate on. * @enable: state to set. */ int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_set_soft_start_regmap - Default set_soft_start() using regmap * * @rdev: device to operate on. */ int regulator_set_soft_start_regmap(struct regulator_dev *rdev) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_set_pull_down_regmap - Default set_pull_down() using regmap * * @rdev: device to operate on. */ int regulator_set_pull_down_regmap(struct regulator_dev *rdev) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_get_bypass_regmap - Default get_bypass() using regmap * * @rdev: device to operate on. * @enable: current state. */ int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_set_active_discharge_regmap - Default set_active_discharge() * using regmap * * @rdev: device to operate on. * @enable: state to set, 0 to disable and 1 to enable. */ int regulator_set_active_discharge_regmap(struct regulator_dev *rdev, bool enable) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_set_current_limit_regmap - set_current_limit for regmap users * * @rdev: regulator to operate on * @min_uA: Lower bound for current limit * @max_uA: Upper bound for current limit * * Regulators that use regmap for their register I/O can set curr_table, * csel_reg and csel_mask fields in their descriptor and then use this * as their set_current_limit operation, saving some code. */ int regulator_set_current_limit_regmap(struct regulator_dev *rdev, int min_uA, int max_uA) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_get_current_limit_regmap - get_current_limit for regmap users * * @rdev: regulator to operate on * * Regulators that use regmap for their register I/O can set the * csel_reg and csel_mask fields in their descriptor and then use this * as their get_current_limit operation, saving some code. */ int regulator_get_current_limit_regmap(struct regulator_dev *rdev) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_bulk_set_supply_names - initialize the 'supply' fields in an array * of regulator_bulk_data structs * * @consumers: array of regulator_bulk_data entries to initialize * @supply_names: array of supply name strings * @num_supplies: number of supply names to initialize * * Note: the 'consumers' array must be the size of 'num_supplies'. */ void regulator_bulk_set_supply_names(struct regulator_bulk_data *consumers, const char *const *supply_names, unsigned int num_supplies) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_is_equal - test whether two regulators are the same * * @reg1: first regulator to operate on * @reg2: second regulator to operate on */ bool regulator_is_equal(struct regulator *reg1, struct regulator *reg2) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_find_closest_bigger - helper to find offset in ramp delay table * * @target: targeted ramp_delay * @table: table with supported ramp delays * @num_sel: number of entries in the table * @sel: Pointer to store table offset * * This is the internal helper used by regulator_set_ramp_delay_regmap to * map ramp delay to register value. It should only be used directly if * regulator_set_ramp_delay_regmap cannot handle a specific device setup * (e.g. because the value is split over multiple registers). */ int regulator_find_closest_bigger(unsigned int target, const unsigned int *table, unsigned int num_sel, unsigned int *sel) { … } EXPORT_SYMBOL_GPL(…); /** * regulator_set_ramp_delay_regmap - set_ramp_delay() helper * * @rdev: regulator to operate on * @ramp_delay: ramp-rate value given in units V/S (uV/uS) * * Regulators that use regmap for their register I/O can set the ramp_reg * and ramp_mask fields in their descriptor and then use this as their * set_ramp_delay operation, saving some code. */ int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay) { … } EXPORT_SYMBOL_GPL(…);