regulator: s2mps11: Pass descriptor instead of GPIO number
Instead of passing a global GPIO number for the enable GPIO, pass a descriptor looked up with the standard devm_gpiod_get_optional() call. This regulator supports passing platform data, but enable/sleep regulators are looked up from the device tree exclusively, so we can need not touch other files. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org> Tested-by: Krzysztof Kozlowski <krzk@kernel.org> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
c89c00e2b8
commit
0369e02b75
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#include <linux/bug.h>
|
#include <linux/bug.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/gpio.h>
|
#include <linux/gpio/consumer.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
@ -27,7 +27,6 @@
|
|||||||
#include <linux/regulator/driver.h>
|
#include <linux/regulator/driver.h>
|
||||||
#include <linux/regulator/machine.h>
|
#include <linux/regulator/machine.h>
|
||||||
#include <linux/regulator/of_regulator.h>
|
#include <linux/regulator/of_regulator.h>
|
||||||
#include <linux/of_gpio.h>
|
|
||||||
#include <linux/mfd/samsung/core.h>
|
#include <linux/mfd/samsung/core.h>
|
||||||
#include <linux/mfd/samsung/s2mps11.h>
|
#include <linux/mfd/samsung/s2mps11.h>
|
||||||
#include <linux/mfd/samsung/s2mps13.h>
|
#include <linux/mfd/samsung/s2mps13.h>
|
||||||
@ -57,7 +56,7 @@ struct s2mps11_info {
|
|||||||
* Array (size: number of regulators) with GPIO-s for external
|
* Array (size: number of regulators) with GPIO-s for external
|
||||||
* sleep control.
|
* sleep control.
|
||||||
*/
|
*/
|
||||||
int *ext_control_gpio;
|
struct gpio_desc **ext_control_gpiod;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int get_ramp_delay(int ramp_delay)
|
static int get_ramp_delay(int ramp_delay)
|
||||||
@ -524,7 +523,7 @@ static int s2mps14_regulator_enable(struct regulator_dev *rdev)
|
|||||||
case S2MPS14X:
|
case S2MPS14X:
|
||||||
if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
|
if (test_bit(rdev_get_id(rdev), s2mps11->suspend_state))
|
||||||
val = S2MPS14_ENABLE_SUSPEND;
|
val = S2MPS14_ENABLE_SUSPEND;
|
||||||
else if (gpio_is_valid(s2mps11->ext_control_gpio[rdev_get_id(rdev)]))
|
else if (s2mps11->ext_control_gpiod[rdev_get_id(rdev)])
|
||||||
val = S2MPS14_ENABLE_EXT_CONTROL;
|
val = S2MPS14_ENABLE_EXT_CONTROL;
|
||||||
else
|
else
|
||||||
val = rdev->desc->enable_mask;
|
val = rdev->desc->enable_mask;
|
||||||
@ -818,7 +817,7 @@ static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
|
|||||||
static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
|
static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
|
||||||
struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
|
struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
|
||||||
{
|
{
|
||||||
int *gpio = s2mps11->ext_control_gpio;
|
struct gpio_desc **gpio = s2mps11->ext_control_gpiod;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
|
unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
|
||||||
S2MPS14_LDO12 };
|
S2MPS14_LDO12 };
|
||||||
@ -829,11 +828,20 @@ static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
|
|||||||
if (!rdata[reg].init_data || !rdata[reg].of_node)
|
if (!rdata[reg].init_data || !rdata[reg].of_node)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
gpio[reg] = of_get_named_gpio(rdata[reg].of_node,
|
gpio[reg] = devm_gpiod_get_from_of_node(&pdev->dev,
|
||||||
"samsung,ext-control-gpios", 0);
|
rdata[reg].of_node,
|
||||||
if (gpio_is_valid(gpio[reg]))
|
"samsung,ext-control-gpios",
|
||||||
dev_dbg(&pdev->dev, "Using GPIO %d for ext-control over %d/%s\n",
|
0,
|
||||||
gpio[reg], reg, rdata[reg].name);
|
GPIOD_OUT_HIGH,
|
||||||
|
"s2mps11-LDO");
|
||||||
|
if (IS_ERR(gpio[reg])) {
|
||||||
|
dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n",
|
||||||
|
reg, rdata[reg].name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (gpio[reg])
|
||||||
|
dev_dbg(&pdev->dev, "Using GPIO for ext-control over %d/%s\n",
|
||||||
|
reg, rdata[reg].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1139,17 +1147,11 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev,
|
s2mps11->ext_control_gpiod = devm_kmalloc(&pdev->dev,
|
||||||
sizeof(*s2mps11->ext_control_gpio) * rdev_num,
|
sizeof(*s2mps11->ext_control_gpiod) * rdev_num,
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!s2mps11->ext_control_gpio)
|
if (!s2mps11->ext_control_gpiod)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
/*
|
|
||||||
* 0 is a valid GPIO so initialize all GPIO-s to negative value
|
|
||||||
* to indicate that external control won't be used for this regulator.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < rdev_num; i++)
|
|
||||||
s2mps11->ext_control_gpio[i] = -EINVAL;
|
|
||||||
|
|
||||||
if (!iodev->dev->of_node) {
|
if (!iodev->dev->of_node) {
|
||||||
if (iodev->pdata) {
|
if (iodev->pdata) {
|
||||||
@ -1179,8 +1181,6 @@ common_reg:
|
|||||||
config.dev = &pdev->dev;
|
config.dev = &pdev->dev;
|
||||||
config.regmap = iodev->regmap_pmic;
|
config.regmap = iodev->regmap_pmic;
|
||||||
config.driver_data = s2mps11;
|
config.driver_data = s2mps11;
|
||||||
config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
|
|
||||||
config.ena_gpio_initialized = true;
|
|
||||||
for (i = 0; i < rdev_num; i++) {
|
for (i = 0; i < rdev_num; i++) {
|
||||||
struct regulator_dev *regulator;
|
struct regulator_dev *regulator;
|
||||||
|
|
||||||
@ -1191,7 +1191,7 @@ common_reg:
|
|||||||
config.init_data = rdata[i].init_data;
|
config.init_data = rdata[i].init_data;
|
||||||
config.of_node = rdata[i].of_node;
|
config.of_node = rdata[i].of_node;
|
||||||
}
|
}
|
||||||
config.ena_gpio = s2mps11->ext_control_gpio[i];
|
config.ena_gpiod = s2mps11->ext_control_gpiod[i];
|
||||||
|
|
||||||
regulator = devm_regulator_register(&pdev->dev,
|
regulator = devm_regulator_register(&pdev->dev,
|
||||||
®ulators[i], &config);
|
®ulators[i], &config);
|
||||||
@ -1202,7 +1202,7 @@ common_reg:
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpio_is_valid(s2mps11->ext_control_gpio[i])) {
|
if (s2mps11->ext_control_gpiod[i]) {
|
||||||
ret = s2mps14_pmic_enable_ext_control(s2mps11,
|
ret = s2mps14_pmic_enable_ext_control(s2mps11,
|
||||||
regulator);
|
regulator);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user