regulator: wm831x: Convert to use GPIO descriptors

This converts the Wolfson Micro WM831x DCDC converter to use
a GPIO descriptor for the GPIO driving the DVS pin.

There is just one (non-DT) machine in the kernel using this, and
that is the Wolfson Micro (now Cirrus) Cragganmore 6410 so we
patch this board to pass a descriptor table and fix up the driver
accordingly.

Cc: Charles Keepax <ckeepax@opensource.cirrus.com>
Cc: Richard Fitzgerald <rf@opensource.cirrus.com>
Cc: patches@opensource.cirrus.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Linus Walleij 2019-06-12 09:42:22 +02:00 committed by Mark Brown
parent d17adf7d3f
commit 9a5ed0bac8
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
3 changed files with 33 additions and 18 deletions

View File

@ -15,6 +15,7 @@
#include <linux/io.h> #include <linux/io.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/gpio/machine.h>
#include <linux/leds.h> #include <linux/leds.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/mmc/host.h> #include <linux/mmc/host.h>
@ -398,7 +399,6 @@ static struct pca953x_platform_data crag6410_pca_data = {
/* VDDARM is controlled by DVS1 connected to GPK(0) */ /* VDDARM is controlled by DVS1 connected to GPK(0) */
static struct wm831x_buckv_pdata vddarm_pdata = { static struct wm831x_buckv_pdata vddarm_pdata = {
.dvs_control_src = 1, .dvs_control_src = 1,
.dvs_gpio = S3C64XX_GPK(0),
}; };
static struct regulator_consumer_supply vddarm_consumers[] = { static struct regulator_consumer_supply vddarm_consumers[] = {
@ -596,6 +596,24 @@ static struct wm831x_pdata crag_pmic_pdata = {
.touch = &touch_pdata, .touch = &touch_pdata,
}; };
/*
* VDDARM is eventually ending up as a regulator hanging on the MFD cell device
* "wm831x-buckv.1" spawn from drivers/mfd/wm831x-core.c.
*
* From the note on the platform data we can see that this is clearly DVS1
* and assigned as dcdc1 resource to the MFD core which sets .id of the cell
* spawning the DVS1 platform device to 1, then the cell platform device
* name is calculated from 10*instance + id resulting in the device name
* "wm831x-buckv.11"
*/
static struct gpiod_lookup_table crag_pmic_gpiod_table = {
.dev_id = "wm831x-buckv.11",
.table = {
GPIO_LOOKUP("GPIOK", 0, "dvs", GPIO_ACTIVE_HIGH),
{ },
},
};
static struct i2c_board_info i2c_devs0[] = { static struct i2c_board_info i2c_devs0[] = {
{ I2C_BOARD_INFO("24c08", 0x50), }, { I2C_BOARD_INFO("24c08", 0x50), },
{ I2C_BOARD_INFO("tca6408", 0x20), { I2C_BOARD_INFO("tca6408", 0x20),
@ -836,6 +854,7 @@ static void __init crag6410_machine_init(void)
s3c_fb_set_platdata(&crag6410_lcd_pdata); s3c_fb_set_platdata(&crag6410_lcd_pdata);
dwc2_hsotg_set_platdata(&crag6410_hsotg_pdata); dwc2_hsotg_set_platdata(&crag6410_hsotg_pdata);
gpiod_add_lookup_table(&crag_pmic_gpiod_table);
i2c_register_board_info(0, i2c_devs0, ARRAY_SIZE(i2c_devs0)); i2c_register_board_info(0, i2c_devs0, ARRAY_SIZE(i2c_devs0));
i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1)); i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1));

View File

@ -15,7 +15,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/regulator/driver.h> #include <linux/regulator/driver.h>
#include <linux/regulator/machine.h> #include <linux/regulator/machine.h>
#include <linux/gpio.h> #include <linux/gpio/consumer.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/mfd/wm831x/core.h> #include <linux/mfd/wm831x/core.h>
@ -50,7 +50,7 @@ struct wm831x_dcdc {
int base; int base;
struct wm831x *wm831x; struct wm831x *wm831x;
struct regulator_dev *regulator; struct regulator_dev *regulator;
int dvs_gpio; struct gpio_desc *dvs_gpiod;
int dvs_gpio_state; int dvs_gpio_state;
int on_vsel; int on_vsel;
int dvs_vsel; int dvs_vsel;
@ -217,7 +217,7 @@ static int wm831x_buckv_set_dvs(struct regulator_dev *rdev, int state)
return 0; return 0;
dcdc->dvs_gpio_state = state; dcdc->dvs_gpio_state = state;
gpio_set_value(dcdc->dvs_gpio, state); gpiod_set_value(dcdc->dvs_gpiod, state);
/* Should wait for DVS state change to be asserted if we have /* Should wait for DVS state change to be asserted if we have
* a GPIO for it, for now assume the device is configured * a GPIO for it, for now assume the device is configured
@ -237,10 +237,10 @@ static int wm831x_buckv_set_voltage_sel(struct regulator_dev *rdev,
int ret; int ret;
/* If this value is already set then do a GPIO update if we can */ /* If this value is already set then do a GPIO update if we can */
if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) if (dcdc->dvs_gpiod && dcdc->on_vsel == vsel)
return wm831x_buckv_set_dvs(rdev, 0); return wm831x_buckv_set_dvs(rdev, 0);
if (dcdc->dvs_gpio && dcdc->dvs_vsel == vsel) if (dcdc->dvs_gpiod && dcdc->dvs_vsel == vsel)
return wm831x_buckv_set_dvs(rdev, 1); return wm831x_buckv_set_dvs(rdev, 1);
/* Always set the ON status to the minimum voltage */ /* Always set the ON status to the minimum voltage */
@ -249,7 +249,7 @@ static int wm831x_buckv_set_voltage_sel(struct regulator_dev *rdev,
return ret; return ret;
dcdc->on_vsel = vsel; dcdc->on_vsel = vsel;
if (!dcdc->dvs_gpio) if (!dcdc->dvs_gpiod)
return ret; return ret;
/* Kick the voltage transition now */ /* Kick the voltage transition now */
@ -296,7 +296,7 @@ static int wm831x_buckv_get_voltage_sel(struct regulator_dev *rdev)
{ {
struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev);
if (dcdc->dvs_gpio && dcdc->dvs_gpio_state) if (dcdc->dvs_gpiod && dcdc->dvs_gpio_state)
return dcdc->dvs_vsel; return dcdc->dvs_vsel;
else else
return dcdc->on_vsel; return dcdc->on_vsel;
@ -337,7 +337,7 @@ static void wm831x_buckv_dvs_init(struct platform_device *pdev,
int ret; int ret;
u16 ctrl; u16 ctrl;
if (!pdata || !pdata->dvs_gpio) if (!pdata)
return; return;
/* gpiolib won't let us read the GPIO status so pick the higher /* gpiolib won't let us read the GPIO status so pick the higher
@ -345,17 +345,14 @@ static void wm831x_buckv_dvs_init(struct platform_device *pdev,
*/ */
dcdc->dvs_gpio_state = pdata->dvs_init_state; dcdc->dvs_gpio_state = pdata->dvs_init_state;
ret = devm_gpio_request_one(&pdev->dev, pdata->dvs_gpio, dcdc->dvs_gpiod = devm_gpiod_get(&pdev->dev, "dvs",
dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0, dcdc->dvs_gpio_state ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW);
"DCDC DVS"); if (IS_ERR(dcdc->dvs_gpiod)) {
if (ret < 0) { dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %ld\n",
dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n", dcdc->name, PTR_ERR(dcdc->dvs_gpiod));
dcdc->name, ret);
return; return;
} }
dcdc->dvs_gpio = pdata->dvs_gpio;
switch (pdata->dvs_control_src) { switch (pdata->dvs_control_src) {
case 1: case 1:
ctrl = 2 << WM831X_DC1_DVS_SRC_SHIFT; ctrl = 2 << WM831X_DC1_DVS_SRC_SHIFT;

View File

@ -52,7 +52,6 @@ struct wm831x_battery_pdata {
* I2C or SPI buses. * I2C or SPI buses.
*/ */
struct wm831x_buckv_pdata { struct wm831x_buckv_pdata {
int dvs_gpio; /** CPU GPIO to use for DVS switching */
int dvs_control_src; /** Hardware DVS source to use (1 or 2) */ int dvs_control_src; /** Hardware DVS source to use (1 or 2) */
int dvs_init_state; /** DVS state to expect on startup */ int dvs_init_state; /** DVS state to expect on startup */
int dvs_state_gpio; /** CPU GPIO to use for monitoring status */ int dvs_state_gpio; /** CPU GPIO to use for monitoring status */