Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc144558 authored by Chen-Yu Tsai's avatar Chen-Yu Tsai Committed by Linus Walleij
Browse files

pinctrl: sunxi: Fix and simplify pin bank regulator handling



The new per-pin-bank regulator handling code in the sunxi pinctrl driver
has mismatched conditions for enabling and disabling the regulator: it
is enabled each time a pin is requested, but only disabled when the
pin-bank's reference count reaches zero.

Since we are doing reference counting already, there's no need to enable
the regulator each time a pin is requested. Instead we can just do it
for the first requested pin of each pin-bank. Thus we can reverse the
test and bail out early if it's not the first occurrence.

Fixes: 9a2a566a ("pinctrl: sunxi: Deal with per-bank regulators")
Acked-by: default avatarMaxime Ripard <maxime.ripard@bootlin.com>
Signed-off-by: default avatarChen-Yu Tsai <wens@csie.org>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 2d2d4785
Loading
Loading
Loading
Loading
+16 −20
Original line number Diff line number Diff line
@@ -699,12 +699,14 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset)
	struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
	unsigned short bank = offset / PINS_PER_BANK;
	struct sunxi_pinctrl_regulator *s_reg = &pctl->regulators[bank];
	struct regulator *reg;
	struct regulator *reg = s_reg->regulator;
	char supply[16];
	int ret;

	reg = s_reg->regulator;
	if (!reg) {
		char supply[16];
	if (reg) {
		refcount_inc(&s_reg->refcount);
		return 0;
	}

	snprintf(supply, sizeof(supply), "vcc-p%c", 'a' + bank);
	reg = regulator_get(pctl->dev, supply);
@@ -714,12 +716,6 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset)
		return PTR_ERR(reg);
	}

		s_reg->regulator = reg;
		refcount_set(&s_reg->refcount, 1);
	} else {
		refcount_inc(&s_reg->refcount);
	}

	ret = regulator_enable(reg);
	if (ret) {
		dev_err(pctl->dev,
@@ -727,13 +723,13 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset)
		goto out;
	}

	s_reg->regulator = reg;
	refcount_set(&s_reg->refcount, 1);

	return 0;

out:
	if (refcount_dec_and_test(&s_reg->refcount)) {
	regulator_put(s_reg->regulator);
		s_reg->regulator = NULL;
	}

	return ret;
}