Skip to content

Commit b0ce7b2

Browse files
Linus Walleijbroonie
authored andcommitted
regulator/gpio: Allow nonexclusive GPIO access
This allows nonexclusive (simultaneous) access to a single GPIO line for the fixed regulator enable line. This happens when several regulators use the same GPIO for enabling and disabling a regulator, and all need a handle on their GPIO descriptor. This solution with a special flag is not entirely elegant and should ideally be replaced by something more careful as this makes it possible for several consumers to enable/disable the same GPIO line to the left and right without any consistency. The current use inside the regulator core should however be fine as it takes special care to handle this. For the state of the GPIO backend, this is still the lesser evil compared to going back to global GPIO numbers. Cc: Marek Szyprowski <m.szyprowski@samsung.com> Cc: Jon Hunter <jonathanh@nvidia.com> Fixes: efdfeb0 ("regulator: fixed: Convert to use GPIO descriptor only") Reported-by: Marek Szyprowski <m.szyprowski@samsung.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent bef9391 commit b0ce7b2

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎drivers/gpio/gpiolib.c‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,8 +3908,23 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
39083908
* the device name as label
39093909
*/
39103910
status = gpiod_request(desc, con_id ? con_id : devname);
3911-
if (status < 0)
3912-
return ERR_PTR(status);
3911+
if (status < 0) {
3912+
if (status == -EBUSY && flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE) {
3913+
/*
3914+
* This happens when there are several consumers for
3915+
* the same GPIO line: we just return here without
3916+
* further initialization. It is a bit if a hack.
3917+
* This is necessary to support fixed regulators.
3918+
*
3919+
* FIXME: Make this more sane and safe.
3920+
*/
3921+
dev_info(dev, "nonexclusive access to GPIO for %s\n",
3922+
con_id ? con_id : devname);
3923+
return desc;
3924+
} else {
3925+
return ERR_PTR(status);
3926+
}
3927+
}
39133928

39143929
status = gpiod_configure_flags(desc, con_id, lookupflags, flags);
39153930
if (status < 0) {

‎drivers/regulator/fixed.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
170170
gflags = GPIOD_OUT_LOW_OPEN_DRAIN;
171171
}
172172

173+
/*
174+
* Some fixed regulators share the enable line between two
175+
* regulators which makes it necessary to get a handle on the
176+
* same descriptor for two different consumers. This will get
177+
* the GPIO descriptor, but only the first call will initialize
178+
* it so any flags such as inversion or open drain will only
179+
* be set up by the first caller and assumed identical on the
180+
* next caller.
181+
*
182+
* FIXME: find a better way to deal with this.
183+
*/
184+
gflags |= GPIOD_FLAGS_BIT_NONEXCLUSIVE;
185+
173186
cfg.ena_gpiod = devm_gpiod_get_optional(&pdev->dev, NULL, gflags);
174187
if (IS_ERR(cfg.ena_gpiod))
175188
return PTR_ERR(cfg.ena_gpiod);

‎include/linux/gpio/consumer.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct gpio_descs {
3030
#define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
3131
#define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
3232
#define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
33+
#define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4)
3334

3435
/**
3536
* Optional flags that can be passed to one of gpiod_* to configure direction

0 commit comments

Comments
 (0)