Merge remote-tracking branches 'regulator/topic/88pg86x', 'regulator/topic/dt', 'regulator/topic/formatting' and 'regulator/topic/gpio' into regulator-next

This commit is contained in:
Mark Brown 2018-03-28 10:33:53 +08:00
Коммит 36fd679f45
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 24D68B725D5487D0
13 изменённых файлов: 196 добавлений и 35 удалений

Просмотреть файл

@ -0,0 +1,22 @@
Marvell 88PG867/88PG868 voltage regulators
Required properties:
- compatible: one of "marvell,88pg867", "marvell,88pg868";
- reg: I2C slave address.
Optional subnodes for regulators: "buck1", "buck2", using common regulator
bindings given in <Documentation/devicetree/bindings/regulator/regulator.txt>.
Example:
pg868@19 {
compatible = "marvell,88pg868";
reg = <0x19>;
vcpu: buck1 {
regulator-boot-on;
regulator-always-on;
regulator-min-microvolt = <1000000>;
regulator-max-microvolt = <1350000>;
};
};

Просмотреть файл

@ -2,6 +2,7 @@ Fixed Voltage regulators
Required properties:
- compatible: Must be "regulator-fixed";
- regulator-name: Defined in regulator.txt as optional, but required here.
Optional properties:
- gpio: gpio to use for enable control

Просмотреть файл

@ -2,6 +2,8 @@ GPIO controlled regulators
Required properties:
- compatible : Must be "regulator-gpio".
- regulator-name : Defined in regulator.txt as optional, but required
here.
- states : Selection of available voltages and GPIO configs.
if there are no states, then use a fixed regulator

114
drivers/regulator/88pg86x.c Normal file
Просмотреть файл

@ -0,0 +1,114 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/of.h>
#include <linux/regulator/driver.h>
#include <linux/regmap.h>
static const struct regulator_ops pg86x_ops = {
.set_voltage_sel = regulator_set_voltage_sel_regmap,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.list_voltage = regulator_list_voltage_linear_range,
};
static const struct regulator_linear_range pg86x_buck1_ranges[] = {
REGULATOR_LINEAR_RANGE( 0, 0, 10, 0),
REGULATOR_LINEAR_RANGE(1000000, 11, 34, 25000),
REGULATOR_LINEAR_RANGE(1600000, 35, 47, 50000),
};
static const struct regulator_linear_range pg86x_buck2_ranges[] = {
REGULATOR_LINEAR_RANGE( 0, 0, 15, 0),
REGULATOR_LINEAR_RANGE(1000000, 16, 39, 25000),
REGULATOR_LINEAR_RANGE(1600000, 40, 52, 50000),
};
static const struct regulator_desc pg86x_regulators[] = {
{
.id = 0,
.type = REGULATOR_VOLTAGE,
.name = "buck1",
.of_match = of_match_ptr("buck1"),
.n_voltages = 11 + 24 + 13,
.linear_ranges = pg86x_buck1_ranges,
.n_linear_ranges = 3,
.vsel_reg = 0x24,
.vsel_mask = 0xff,
.ops = &pg86x_ops,
.owner = THIS_MODULE
},
{
.id = 1,
.type = REGULATOR_VOLTAGE,
.name = "buck2",
.of_match = of_match_ptr("buck2"),
.n_voltages = 16 + 24 + 13,
.linear_ranges = pg86x_buck2_ranges,
.n_linear_ranges = 3,
.vsel_reg = 0x13,
.vsel_mask = 0xff,
.ops = &pg86x_ops,
.owner = THIS_MODULE
},
};
static const struct regmap_config pg86x_regmap = {
.reg_bits = 8,
.val_bits = 8,
};
static int pg86x_i2c_probe(struct i2c_client *i2c)
{
int id, ret;
struct regulator_config config = {.dev = &i2c->dev};
struct regmap *regmap = devm_regmap_init_i2c(i2c, &pg86x_regmap);
if (IS_ERR(regmap)) {
ret = PTR_ERR(regmap);
dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
return ret;
}
for (id = 0; id < ARRAY_SIZE(pg86x_regulators); id++) {
struct regulator_dev *rdev;
rdev = devm_regulator_register(&i2c->dev,
&pg86x_regulators[id],
&config);
if (IS_ERR(rdev)) {
ret = PTR_ERR(rdev);
dev_err(&i2c->dev, "failed to register %s: %d\n",
pg86x_regulators[id].name, ret);
return ret;
}
}
return 0;
}
static const struct of_device_id pg86x_dt_ids [] = {
{ .compatible = "marvell,88pg867" },
{ .compatible = "marvell,88pg868" },
{ }
};
MODULE_DEVICE_TABLE(of, pg86x_dt_ids);
static const struct i2c_device_id pg86x_i2c_id[] = {
{ "88pg867", },
{ "88pg868", },
{ }
};
MODULE_DEVICE_TABLE(i2c, pg86x_i2c_id);
static struct i2c_driver pg86x_regulator_driver = {
.driver = {
.name = "88pg86x",
.of_match_table = of_match_ptr(pg86x_dt_ids),
},
.probe_new = pg86x_i2c_probe,
.id_table = pg86x_i2c_id,
};
module_i2c_driver(pg86x_regulator_driver);
MODULE_DESCRIPTION("Marvell 88PG86X voltage regulator");
MODULE_AUTHOR("Alexander Monakov <amonakov@gmail.com>");
MODULE_LICENSE("GPL");

Просмотреть файл

@ -54,6 +54,15 @@ config REGULATOR_USERSPACE_CONSUMER
If unsure, say no.
config REGULATOR_88PG86X
tristate "Marvell 88PG86X voltage regulators"
depends on I2C
select REGMAP_I2C
help
This driver supports Marvell 88PG867 and 88PG868 voltage regulators.
They provide two I2C-controlled DC/DC step-down converters with
sleep mode and separate enable pins.
config REGULATOR_88PM800
tristate "Marvell 88PM800 Power regulators"
depends on MFD_88PM800

Просмотреть файл

@ -10,6 +10,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_88PG86X) += 88pg86x.o
obj-$(CONFIG_REGULATOR_88PM800) += 88pm800.o
obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
obj-$(CONFIG_REGULATOR_CPCAP) += cpcap-regulator.o

Просмотреть файл

@ -1937,7 +1937,10 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
struct gpio_desc *gpiod;
int ret;
gpiod = gpio_to_desc(config->ena_gpio);
if (config->ena_gpiod)
gpiod = config->ena_gpiod;
else
gpiod = gpio_to_desc(config->ena_gpio);
list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
if (pin->gpiod == gpiod) {
@ -1947,15 +1950,18 @@ static int regulator_ena_gpio_request(struct regulator_dev *rdev,
}
}
ret = gpio_request_one(config->ena_gpio,
GPIOF_DIR_OUT | config->ena_gpio_flags,
rdev_get_name(rdev));
if (ret)
return ret;
if (!config->ena_gpiod) {
ret = gpio_request_one(config->ena_gpio,
GPIOF_DIR_OUT | config->ena_gpio_flags,
rdev_get_name(rdev));
if (ret)
return ret;
}
pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL);
if (pin == NULL) {
gpio_free(config->ena_gpio);
if (!config->ena_gpiod)
gpio_free(config->ena_gpio);
return -ENOMEM;
}
@ -4154,8 +4160,9 @@ regulator_register(const struct regulator_desc *regulator_desc,
goto clean;
}
if ((config->ena_gpio || config->ena_gpio_initialized) &&
gpio_is_valid(config->ena_gpio)) {
if (config->ena_gpiod ||
((config->ena_gpio || config->ena_gpio_initialized) &&
gpio_is_valid(config->ena_gpio))) {
mutex_lock(&regulator_list_mutex);
ret = regulator_ena_gpio_request(rdev, config);
mutex_unlock(&regulator_list_mutex);
@ -4301,6 +4308,7 @@ static int regulator_suspend_late(struct device *dev)
return class_for_each_device(&regulator_class, NULL, &state,
_regulator_suspend_late);
}
static int _regulator_resume_early(struct device *dev, void *data)
{
int ret = 0;

Просмотреть файл

@ -16,6 +16,7 @@
#include <linux/init.h>
#include <linux/err.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
@ -455,8 +456,7 @@ static int da9055_gpio_init(struct da9055_regulator *regulator,
char name[18];
int gpio_mux = pdata->gpio_ren[id];
config->ena_gpio = pdata->ena_gpio[id];
config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
config->ena_gpiod = pdata->ena_gpiods[id];
config->ena_gpio_invert = 1;
/*

Просмотреть файл

@ -15,7 +15,6 @@
*/
#include <linux/err.h>
#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/init.h>
@ -25,7 +24,7 @@
#include <linux/regmap.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/regulator/of_regulator.h>
#include <linux/regulator/da9211.h>
#include "da9211-regulator.h"
@ -294,9 +293,12 @@ static struct da9211_pdata *da9211_parse_regulators_dt(
pdata->init_data[n] = da9211_matches[i].init_data;
pdata->reg_node[n] = da9211_matches[i].of_node;
pdata->gpio_ren[n] =
of_get_named_gpio(da9211_matches[i].of_node,
"enable-gpios", 0);
pdata->gpiod_ren[n] = devm_gpiod_get_from_of_node(dev,
da9211_matches[i].of_node,
"enable",
0,
GPIOD_OUT_HIGH,
"da9211-enable");
n++;
}
@ -382,13 +384,10 @@ static int da9211_regulator_init(struct da9211 *chip)
config.regmap = chip->regmap;
config.of_node = chip->pdata->reg_node[i];
if (gpio_is_valid(chip->pdata->gpio_ren[i])) {
config.ena_gpio = chip->pdata->gpio_ren[i];
config.ena_gpio_initialized = true;
} else {
config.ena_gpio = -EINVAL;
config.ena_gpio_initialized = false;
}
if (chip->pdata->gpiod_ren[i])
config.ena_gpiod = chip->pdata->gpiod_ren[i];
else
config.ena_gpiod = NULL;
chip->rdev[i] = devm_regulator_register(chip->dev,
&da9211_regulators[i], &config);

Просмотреть файл

@ -196,6 +196,7 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np,
break;
}
config->gpios[i].gpio = gpio;
config->gpios[i].label = config->supply_name;
if (proplen > 0) {
of_property_read_u32_index(np, "gpios-states",
i, &ret);
@ -271,8 +272,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL);
if (drvdata->desc.name == NULL) {
dev_err(&pdev->dev, "Failed to allocate supply name\n");
ret = -ENOMEM;
goto err;
return -ENOMEM;
}
if (config->nr_gpios != 0) {
@ -292,7 +292,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
dev_err(&pdev->dev,
"Could not obtain regulator setting GPIOs: %d\n",
ret);
goto err_memstate;
goto err_memgpio;
}
}
@ -303,7 +303,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
if (drvdata->states == NULL) {
dev_err(&pdev->dev, "Failed to allocate state data\n");
ret = -ENOMEM;
goto err_memgpio;
goto err_stategpio;
}
drvdata->nr_states = config->nr_states;
@ -324,7 +324,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
default:
dev_err(&pdev->dev, "No regulator type set\n");
ret = -EINVAL;
goto err_memgpio;
goto err_memstate;
}
/* build initial state from gpio init data. */
@ -361,22 +361,21 @@ static int gpio_regulator_probe(struct platform_device *pdev)
if (IS_ERR(drvdata->dev)) {
ret = PTR_ERR(drvdata->dev);
dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
goto err_stategpio;
goto err_memstate;
}
platform_set_drvdata(pdev, drvdata);
return 0;
err_stategpio:
gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
err_memstate:
kfree(drvdata->states);
err_stategpio:
gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
err_memgpio:
kfree(drvdata->gpios);
err_name:
kfree(drvdata->desc.name);
err:
return ret;
}

Просмотреть файл

@ -12,6 +12,7 @@
#define DA9055_MAX_REGULATORS 8
struct da9055;
struct gpio_desc;
enum gpio_select {
NO_GPIO = 0,
@ -47,7 +48,7 @@ struct da9055_pdata {
* controls the regulator set A/B, 0 if not available.
*/
enum gpio_select *reg_rsel;
/* GPIOs to enable regulator, 0 if not available */
int *ena_gpio;
/* GPIO descriptors to enable regulator, NULL if not available */
struct gpio_desc **ena_gpiods;
};
#endif /* __DA9055_PDATA_H */

Просмотреть файл

@ -21,6 +21,8 @@
#define DA9211_MAX_REGULATORS 2
struct gpio_desc;
enum da9211_chip_id {
DA9211,
DA9212,
@ -39,7 +41,7 @@ struct da9211_pdata {
* 2 : 2 phase 2 buck
*/
int num_buck;
int gpio_ren[DA9211_MAX_REGULATORS];
struct gpio_desc *gpiod_ren[DA9211_MAX_REGULATORS];
struct device_node *reg_node[DA9211_MAX_REGULATORS];
struct regulator_init_data *init_data[DA9211_MAX_REGULATORS];
};

Просмотреть файл

@ -19,6 +19,7 @@
#include <linux/notifier.h>
#include <linux/regulator/consumer.h>
struct gpio_desc;
struct regmap;
struct regulator_dev;
struct regulator_config;
@ -387,6 +388,7 @@ struct regulator_desc {
* initialized, meaning that >= 0 is a valid gpio
* identifier and < 0 is a non existent gpio.
* @ena_gpio: GPIO controlling regulator enable.
* @ena_gpiod: GPIO descriptor controlling regulator enable.
* @ena_gpio_invert: Sense for GPIO enable control.
* @ena_gpio_flags: Flags to use when calling gpio_request_one()
*/
@ -399,6 +401,7 @@ struct regulator_config {
bool ena_gpio_initialized;
int ena_gpio;
struct gpio_desc *ena_gpiod;
unsigned int ena_gpio_invert:1;
unsigned int ena_gpio_flags;
};