cregit-Linux how code gets into the kernel

Release 4.14 drivers/regulator/helpers.c

/*
 * helpers.c  --  Voltage/Current Regulator framework helper functions.
 *
 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
 * Copyright 2008 SlimLogic Ltd.
 *
 *  This program is free software; you can redistribute  it and/or modify it
 *  under  the terms of  the GNU General  Public License as published by the
 *  Free Software Foundation;  either version 2 of the  License, or (at your
 *  option) any later version.
 *
 */

#include <linux/kernel.h>
#include <linux/err.h>
#include <linux/delay.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/regulator/driver.h>
#include <linux/module.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) { unsigned int val; int ret; ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); if (ret != 0) return ret; val &= rdev->desc->enable_mask; if (rdev->desc->enable_is_inverted) { if (rdev->desc->enable_val) return val != rdev->desc->enable_val; return val == 0; } else { if (rdev->desc->enable_val) return val == rdev->desc->enable_val; return val != 0; } }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown7165.14%150.00%
Carlo Caione3834.86%150.00%
Total109100.00%2100.00%

EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap); /** * 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) { unsigned int val; if (rdev->desc->enable_is_inverted) { val = rdev->desc->disable_val; } else { val = rdev->desc->enable_val; if (!val) val = rdev->desc->enable_mask; } return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, rdev->desc->enable_mask, val); }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown5671.79%150.00%
Carlo Caione2228.21%150.00%
Total78100.00%2100.00%

EXPORT_SYMBOL_GPL(regulator_enable_regmap); /** * 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) { unsigned int val; if (rdev->desc->enable_is_inverted) { val = rdev->desc->enable_val; if (!val) val = rdev->desc->enable_mask; } else { val = rdev->desc->disable_val; } return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, rdev->desc->enable_mask, val); }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown5671.79%150.00%
Carlo Caione2228.21%150.00%
Total78100.00%2100.00%

EXPORT_SYMBOL_GPL(regulator_disable_regmap); /** * 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) { unsigned int val; int ret; ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val); if (ret != 0) return ret; val &= rdev->desc->vsel_mask; val >>= ffs(rdev->desc->vsel_mask) - 1; return val; }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown68100.00%1100.00%
Total68100.00%1100.00%

EXPORT_SYMBOL_GPL(regulator_get_voltage_sel_regmap); /** * 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) { int ret; sel <<= ffs(rdev->desc->vsel_mask) - 1; ret = regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg, rdev->desc->vsel_mask, sel); if (ret) return ret; if (rdev->desc->apply_bit) ret = regmap_update_bits(rdev->regmap, rdev->desc->apply_reg, rdev->desc->apply_bit, rdev->desc->apply_bit); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown97100.00%1100.00%
Total97100.00%1100.00%

EXPORT_SYMBOL_GPL(regulator_set_voltage_sel_regmap); /** * 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) { int best_val = INT_MAX; int selector = 0; int i, ret; /* Find the smallest voltage that falls within the specified * range. */ for (i = 0; i < rdev->desc->n_voltages; i++) { ret = rdev->desc->ops->list_voltage(rdev, i); if (ret < 0) continue; if (ret < best_val && ret >= min_uV && ret <= max_uV) { best_val = ret; selector = i; } } if (best_val != INT_MAX) return selector; else return -EINVAL; }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown111100.00%1100.00%
Total111100.00%1100.00%

EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate); /** * 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) { int i, ret; for (i = 0; i < rdev->desc->n_voltages; i++) { ret = rdev->desc->ops->list_voltage(rdev, i); if (ret < 0) continue; if (ret > max_uV) break; if (ret >= min_uV && ret <= max_uV) return i; } return -EINVAL; }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown86100.00%1100.00%
Total86100.00%1100.00%

EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend); /** * 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) { int ret, voltage; /* Allow uV_step to be 0 for fixed voltage */ if (rdev->desc->n_voltages == 1 && rdev->desc->uV_step == 0) { if (min_uV <= rdev->desc->min_uV && rdev->desc->min_uV <= max_uV) return 0; else return -EINVAL; } if (!rdev->desc->uV_step) { BUG_ON(!rdev->desc->uV_step); return -EINVAL; } if (min_uV < rdev->desc->min_uV) min_uV = rdev->desc->min_uV; ret = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step); if (ret < 0) return ret; ret += rdev->desc->linear_min_sel; /* Map back into a voltage to verify we're still in bounds */ voltage = rdev->desc->ops->list_voltage(rdev, ret); if (voltage < min_uV || voltage > max_uV) return -EINVAL; return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown180100.00%1100.00%
Total180100.00%1100.00%

EXPORT_SYMBOL_GPL(regulator_map_voltage_linear); /** * 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) { const struct regulator_linear_range *range; int ret = -EINVAL; int voltage, i; if (!rdev->desc->n_linear_ranges) { BUG_ON(!rdev->desc->n_linear_ranges); return -EINVAL; } for (i = 0; i < rdev->desc->n_linear_ranges; i++) { int linear_max_uV; range = &rdev->desc->linear_ranges[i]; linear_max_uV = range->min_uV + (range->max_sel - range->min_sel) * range->uV_step; if (!(min_uV <= linear_max_uV && max_uV >= range->min_uV)) continue; if (min_uV <= range->min_uV) min_uV = range->min_uV; /* range->uV_step == 0 means fixed voltage range */ if (range->uV_step == 0) { ret = 0; } else { ret = DIV_ROUND_UP(min_uV - range->min_uV, range->uV_step); if (ret < 0) return ret; } ret += range->min_sel; break; } if (i == rdev->desc->n_linear_ranges) return -EINVAL; /* Map back into a voltage to verify we're still in bounds */ voltage = rdev->desc->ops->list_voltage(rdev, ret); if (voltage < min_uV || voltage > max_uV) return -EINVAL; return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown21489.92%150.00%
Axel Lin2410.08%150.00%
Total238100.00%2100.00%

EXPORT_SYMBOL_GPL(regulator_map_voltage_linear_range); /** * 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) { if (selector >= rdev->desc->n_voltages) return -EINVAL; if (selector < rdev->desc->linear_min_sel) return 0; selector -= rdev->desc->linear_min_sel; return rdev->desc->min_uV + (rdev->desc->uV_step * selector); }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin66100.00%1100.00%
Total66100.00%1100.00%

EXPORT_SYMBOL_GPL(regulator_list_voltage_linear); /** * 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) { const struct regulator_linear_range *range; int i; if (!rdev->desc->n_linear_ranges) { BUG_ON(!rdev->desc->n_linear_ranges); return -EINVAL; } for (i = 0; i < rdev->desc->n_linear_ranges; i++) { range = &rdev->desc->linear_ranges[i]; if (!(selector >= range->min_sel && selector <= range->max_sel)) continue; selector -= range->min_sel; return range->min_uV + (range->uV_step * selector); } return -EINVAL; }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin120100.00%1100.00%
Total120100.00%1100.00%

EXPORT_SYMBOL_GPL(regulator_list_voltage_linear_range); /** * 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) { if (!rdev->desc->volt_table) { BUG_ON(!rdev->desc->volt_table); return -EINVAL; } if (selector >= rdev->desc->n_voltages) return -EINVAL; return rdev->desc->volt_table[selector]; }

Contributors

PersonTokensPropCommitsCommitProp
Axel Lin63100.00%1100.00%
Total63100.00%1100.00%

EXPORT_SYMBOL_GPL(regulator_list_voltage_table); /** * 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) { unsigned int val; if (enable) { val = rdev->desc->bypass_val_on; if (!val) val = rdev->desc->bypass_mask; } else { val = rdev->desc->bypass_val_off; } return regmap_update_bits(rdev->regmap, rdev->desc->bypass_reg, rdev->desc->bypass_mask, val); }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown5571.43%150.00%
Carlo Caione2228.57%150.00%
Total77100.00%2100.00%

EXPORT_SYMBOL_GPL(regulator_set_bypass_regmap); /** * 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) { unsigned int val; val = rdev->desc->soft_start_val_on; if (!val) val = rdev->desc->soft_start_mask; return regmap_update_bits(rdev->regmap, rdev->desc->soft_start_reg, rdev->desc->soft_start_mask, val); }

Contributors

PersonTokensPropCommitsCommitProp
Charles Keepax57100.00%1100.00%
Total57100.00%1100.00%

EXPORT_SYMBOL_GPL(regulator_set_soft_start_regmap); /** * 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) { unsigned int val; val = rdev->desc->pull_down_val_on; if (!val) val = rdev->desc->pull_down_mask; return regmap_update_bits(rdev->regmap, rdev->desc->pull_down_reg, rdev->desc->pull_down_mask, val); }

Contributors

PersonTokensPropCommitsCommitProp
Charles Keepax57100.00%1100.00%
Total57100.00%1100.00%

EXPORT_SYMBOL_GPL(regulator_set_pull_down_regmap); /** * 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) { unsigned int val; unsigned int val_on = rdev->desc->bypass_val_on; int ret; ret = regmap_read(rdev->regmap, rdev->desc->bypass_reg, &val); if (ret != 0) return ret; if (!val_on) val_on = rdev->desc->bypass_mask; *enable = (val & rdev->desc->bypass_mask) == val_on; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown6269.66%133.33%
Charles Keepax2426.97%133.33%
Jon Hunter33.37%133.33%
Total89100.00%3100.00%

EXPORT_SYMBOL_GPL(regulator_get_bypass_regmap); /** * 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) { unsigned int val; if (enable) val = rdev->desc->active_discharge_on; else val = rdev->desc->active_discharge_off; return regmap_update_bits(rdev->regmap, rdev->desc->active_discharge_reg, rdev->desc->active_discharge_mask, val); }

Contributors

PersonTokensPropCommitsCommitProp
Laxman Dewangan60100.00%1100.00%
Total60100.00%1100.00%

EXPORT_SYMBOL_GPL(regulator_set_active_discharge_regmap);

Overall Contributors

PersonTokensPropCommitsCommitProp
Mark Brown114365.02%110.00%
Axel Lin29116.55%220.00%
Charles Keepax1508.53%330.00%
Carlo Caione1045.92%110.00%
Laxman Dewangan663.75%110.00%
Jon Hunter30.17%110.00%
Krzysztof Kozlowski10.06%110.00%
Total1758100.00%10100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.