mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-29 02:59:13 +00:00
regulator: wm831x-isink: Convert to use regulator_set/get_current_limit_regmap
Use regulator_set/get_current_limit_regmap helpers to save some code. Signed-off-by: Axel Lin <axel.lin@ingics.com> Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
5816df2f75
commit
d48acfd037
@ -33,7 +33,7 @@
|
|||||||
/* Current settings - values are 2*2^(reg_val/4) microamps. These are
|
/* Current settings - values are 2*2^(reg_val/4) microamps. These are
|
||||||
* exported since they are used by multiple drivers.
|
* exported since they are used by multiple drivers.
|
||||||
*/
|
*/
|
||||||
int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {
|
const unsigned int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {
|
||||||
2,
|
2,
|
||||||
2,
|
2,
|
||||||
3,
|
3,
|
||||||
|
@ -92,48 +92,12 @@ static int wm831x_isink_is_enabled(struct regulator_dev *rdev)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wm831x_isink_set_current(struct regulator_dev *rdev,
|
|
||||||
int min_uA, int max_uA)
|
|
||||||
{
|
|
||||||
struct wm831x_isink *isink = rdev_get_drvdata(rdev);
|
|
||||||
struct wm831x *wm831x = isink->wm831x;
|
|
||||||
int ret, i;
|
|
||||||
|
|
||||||
for (i = ARRAY_SIZE(wm831x_isinkv_values) - 1; i >= 0; i--) {
|
|
||||||
int val = wm831x_isinkv_values[i];
|
|
||||||
if (min_uA <= val && val <= max_uA) {
|
|
||||||
ret = wm831x_set_bits(wm831x, isink->reg,
|
|
||||||
WM831X_CS1_ISEL_MASK, i);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int wm831x_isink_get_current(struct regulator_dev *rdev)
|
|
||||||
{
|
|
||||||
struct wm831x_isink *isink = rdev_get_drvdata(rdev);
|
|
||||||
struct wm831x *wm831x = isink->wm831x;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = wm831x_reg_read(wm831x, isink->reg);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
ret &= WM831X_CS1_ISEL_MASK;
|
|
||||||
if (ret > WM831X_ISINK_MAX_ISEL)
|
|
||||||
ret = WM831X_ISINK_MAX_ISEL;
|
|
||||||
|
|
||||||
return wm831x_isinkv_values[ret];
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct regulator_ops wm831x_isink_ops = {
|
static const struct regulator_ops wm831x_isink_ops = {
|
||||||
.is_enabled = wm831x_isink_is_enabled,
|
.is_enabled = wm831x_isink_is_enabled,
|
||||||
.enable = wm831x_isink_enable,
|
.enable = wm831x_isink_enable,
|
||||||
.disable = wm831x_isink_disable,
|
.disable = wm831x_isink_disable,
|
||||||
.set_current_limit = wm831x_isink_set_current,
|
.set_current_limit = regulator_set_current_limit_regmap,
|
||||||
.get_current_limit = wm831x_isink_get_current,
|
.get_current_limit = regulator_get_current_limit_regmap,
|
||||||
};
|
};
|
||||||
|
|
||||||
static irqreturn_t wm831x_isink_irq(int irq, void *data)
|
static irqreturn_t wm831x_isink_irq(int irq, void *data)
|
||||||
@ -189,10 +153,15 @@ static int wm831x_isink_probe(struct platform_device *pdev)
|
|||||||
isink->desc.ops = &wm831x_isink_ops;
|
isink->desc.ops = &wm831x_isink_ops;
|
||||||
isink->desc.type = REGULATOR_CURRENT;
|
isink->desc.type = REGULATOR_CURRENT;
|
||||||
isink->desc.owner = THIS_MODULE;
|
isink->desc.owner = THIS_MODULE;
|
||||||
|
isink->desc.curr_table = wm831x_isinkv_values,
|
||||||
|
isink->desc.n_current_limits = ARRAY_SIZE(wm831x_isinkv_values),
|
||||||
|
isink->desc.csel_reg = isink->reg,
|
||||||
|
isink->desc.csel_mask = WM831X_CS1_ISEL_MASK,
|
||||||
|
|
||||||
config.dev = pdev->dev.parent;
|
config.dev = pdev->dev.parent;
|
||||||
config.init_data = pdata->isink[id];
|
config.init_data = pdata->isink[id];
|
||||||
config.driver_data = isink;
|
config.driver_data = isink;
|
||||||
|
config.regmap = wm831x->regmap;
|
||||||
|
|
||||||
isink->regulator = devm_regulator_register(&pdev->dev, &isink->desc,
|
isink->regulator = devm_regulator_register(&pdev->dev, &isink->desc,
|
||||||
&config);
|
&config);
|
||||||
|
@ -1213,6 +1213,6 @@
|
|||||||
#define WM831X_LDO1_OK_WIDTH 1 /* LDO1_OK */
|
#define WM831X_LDO1_OK_WIDTH 1 /* LDO1_OK */
|
||||||
|
|
||||||
#define WM831X_ISINK_MAX_ISEL 55
|
#define WM831X_ISINK_MAX_ISEL 55
|
||||||
extern int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1];
|
extern const unsigned int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user