regulator: Add driver for gpio-controlled regulators
PATCH 1/1 regulator: Add driver for gpio-controlled regulators
This patch adds support for regulators that can be controlled via gpios.
Examples for such regulators are the TI-tps65024x voltage regulators with 4 fixed and 1 runtime-switchable voltage regulators or the TI-bq240XX charger regulators.
The number of controlling gpios is not limited, the mapping between voltage/current and target gpio state is done via the states map and the driver can be used for either voltage or current regulators.
A mapping for a regulator with two GPIOs could look like:
gpios = {
GPIO1,
GPIO2,
}states = {
{ .value = volt_or_cur1, .gpios = (0 << 1) | (0 << 0) },
{ .value = volt_or_cur2, .gpios = (0 << 1) | (1 << 0) },
{ .value = volt_or_cur3, .gpios = (1 << 1) | (0 << 0) },
{ .value = volt_or_cur4, .gpios = (1 << 1) | (1 << 0) },
}The target-state for the n-th gpio is determined by the n-th bit in the bitfield of the target-value.
--- drivers/regulator/Kconfig | 9 + drivers/regulator/Makefile | 1 + drivers/regulator/gpio-regulator.c | 364 ++++++++++++++++++++++++++++++ include/linux/regulator/gpio-regulator.h | 90 ++++++++ 4 files changed, 464 insertions(+), 0 deletions(-)
drivers/regulator/Kconfig +9 -0
@@ -64,6 +64,15 @@ config REGULATOR_USERSPACE_CONSUMER If unsure, say no. +config REGULATOR_GPIO + tristate "GPIO regulator support" + help + This driver provides support for regulators that can be + controlled via gpios. + It is capable of supporting current and voltage regulators + and the platform has to provide a mapping of GPIO-states + to target volts/amps. + config REGULATOR_BQ24022 tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" help
drivers/regulator/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o +obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
drivers/regulator/gpio-regulator.c new file +364 -0
364 lines not on this page · raw message
include/linux/regulator/gpio-regulator.h new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
tg: (c6a389f..) topic/drivers/reg-switch (depends on: master)
Quoted 5 lines · Heiko Stübner
This patch adds support for regulators that can be controlled via gpios.
Examples for such regulators are the TI-tps65024x voltage regulators with 4 fixed and 1 runtime-switchable voltage regulators or the TI-bq240XX charger regulators.
What's the difference between this and the patch you posted on Friday?
drivers/regulator/gpio-regulator.c line 189
Quoted 1 line
drivers/regulator/gpio-regulator.c new file +1
-0+ drvdata->gpios =kmalloc (config->nr_gpios *sizeof (int ),GFP_KERNEL );
calloc.
drivers/regulator/gpio-regulator.c line 249
Quoted 6 lines
drivers/regulator/gpio-regulator.c new file +6
-0+/* set output direction without changing state +* to prevent glitch +*/ + drvdata->is_enabled = config->enabled_at_boot; + ret = drvdata->is_enabled ? + config->enable_high : !config->enable_high;
I'm fairly sure this could be written more cleanly.
drivers/regulator/gpio-regulator.c line 273
Quoted 9 lines
drivers/regulator/gpio-regulator.c new file +9
-0+ drvdata->nr_gpios = config->nr_gpios; +for (ptr =0 ; ptr < drvdata->nr_gpios; ptr++) { + ret =gpio_request (config->gpios[ptr], config->supply_name); +if (ret) { +dev_err (&pdev->dev, +"Could not obtain regulator setting GPIO %d: %d\n" , + config->gpios[ptr], ret); + goto err_stategpio; + }
This might be easier written using gpio_request_array().