Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Linus Walleij and committed by
Mark Brown
9a5ed0ba d17adf7d

+33 -18
+20 -1
arch/arm/mach-s3c64xx/mach-crag6410.c
··· 15 15 #include <linux/io.h> 16 16 #include <linux/init.h> 17 17 #include <linux/gpio.h> 18 + #include <linux/gpio/machine.h> 18 19 #include <linux/leds.h> 19 20 #include <linux/delay.h> 20 21 #include <linux/mmc/host.h> ··· 399 398 /* VDDARM is controlled by DVS1 connected to GPK(0) */ 400 399 static struct wm831x_buckv_pdata vddarm_pdata = { 401 400 .dvs_control_src = 1, 402 - .dvs_gpio = S3C64XX_GPK(0), 403 401 }; 404 402 405 403 static struct regulator_consumer_supply vddarm_consumers[] = { ··· 594 594 }, 595 595 596 596 .touch = &touch_pdata, 597 + }; 598 + 599 + /* 600 + * VDDARM is eventually ending up as a regulator hanging on the MFD cell device 601 + * "wm831x-buckv.1" spawn from drivers/mfd/wm831x-core.c. 602 + * 603 + * From the note on the platform data we can see that this is clearly DVS1 604 + * and assigned as dcdc1 resource to the MFD core which sets .id of the cell 605 + * spawning the DVS1 platform device to 1, then the cell platform device 606 + * name is calculated from 10*instance + id resulting in the device name 607 + * "wm831x-buckv.11" 608 + */ 609 + static struct gpiod_lookup_table crag_pmic_gpiod_table = { 610 + .dev_id = "wm831x-buckv.11", 611 + .table = { 612 + GPIO_LOOKUP("GPIOK", 0, "dvs", GPIO_ACTIVE_HIGH), 613 + { }, 614 + }, 597 615 }; 598 616 599 617 static struct i2c_board_info i2c_devs0[] = { ··· 854 836 s3c_fb_set_platdata(&crag6410_lcd_pdata); 855 837 dwc2_hsotg_set_platdata(&crag6410_hsotg_pdata); 856 838 839 + gpiod_add_lookup_table(&crag_pmic_gpiod_table); 857 840 i2c_register_board_info(0, i2c_devs0, ARRAY_SIZE(i2c_devs0)); 858 841 i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1)); 859 842
+13 -16
drivers/regulator/wm831x-dcdc.c
··· 15 15 #include <linux/platform_device.h> 16 16 #include <linux/regulator/driver.h> 17 17 #include <linux/regulator/machine.h> 18 - #include <linux/gpio.h> 18 + #include <linux/gpio/consumer.h> 19 19 #include <linux/slab.h> 20 20 21 21 #include <linux/mfd/wm831x/core.h> ··· 50 50 int base; 51 51 struct wm831x *wm831x; 52 52 struct regulator_dev *regulator; 53 - int dvs_gpio; 53 + struct gpio_desc *dvs_gpiod; 54 54 int dvs_gpio_state; 55 55 int on_vsel; 56 56 int dvs_vsel; ··· 217 217 return 0; 218 218 219 219 dcdc->dvs_gpio_state = state; 220 - gpio_set_value(dcdc->dvs_gpio, state); 220 + gpiod_set_value(dcdc->dvs_gpiod, state); 221 221 222 222 /* Should wait for DVS state change to be asserted if we have 223 223 * a GPIO for it, for now assume the device is configured ··· 237 237 int ret; 238 238 239 239 /* If this value is already set then do a GPIO update if we can */ 240 - if (dcdc->dvs_gpio && dcdc->on_vsel == vsel) 240 + if (dcdc->dvs_gpiod && dcdc->on_vsel == vsel) 241 241 return wm831x_buckv_set_dvs(rdev, 0); 242 242 243 - if (dcdc->dvs_gpio && dcdc->dvs_vsel == vsel) 243 + if (dcdc->dvs_gpiod && dcdc->dvs_vsel == vsel) 244 244 return wm831x_buckv_set_dvs(rdev, 1); 245 245 246 246 /* Always set the ON status to the minimum voltage */ ··· 249 249 return ret; 250 250 dcdc->on_vsel = vsel; 251 251 252 - if (!dcdc->dvs_gpio) 252 + if (!dcdc->dvs_gpiod) 253 253 return ret; 254 254 255 255 /* Kick the voltage transition now */ ··· 296 296 { 297 297 struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); 298 298 299 - if (dcdc->dvs_gpio && dcdc->dvs_gpio_state) 299 + if (dcdc->dvs_gpiod && dcdc->dvs_gpio_state) 300 300 return dcdc->dvs_vsel; 301 301 else 302 302 return dcdc->on_vsel; ··· 337 337 int ret; 338 338 u16 ctrl; 339 339 340 - if (!pdata || !pdata->dvs_gpio) 340 + if (!pdata) 341 341 return; 342 342 343 343 /* gpiolib won't let us read the GPIO status so pick the higher ··· 345 345 */ 346 346 dcdc->dvs_gpio_state = pdata->dvs_init_state; 347 347 348 - ret = devm_gpio_request_one(&pdev->dev, pdata->dvs_gpio, 349 - dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0, 350 - "DCDC DVS"); 351 - if (ret < 0) { 352 - dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n", 353 - dcdc->name, ret); 348 + dcdc->dvs_gpiod = devm_gpiod_get(&pdev->dev, "dvs", 349 + dcdc->dvs_gpio_state ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW); 350 + if (IS_ERR(dcdc->dvs_gpiod)) { 351 + dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %ld\n", 352 + dcdc->name, PTR_ERR(dcdc->dvs_gpiod)); 354 353 return; 355 354 } 356 - 357 - dcdc->dvs_gpio = pdata->dvs_gpio; 358 355 359 356 switch (pdata->dvs_control_src) { 360 357 case 1:
-1
include/linux/mfd/wm831x/pdata.h
··· 52 52 * I2C or SPI buses. 53 53 */ 54 54 struct wm831x_buckv_pdata { 55 - int dvs_gpio; /** CPU GPIO to use for DVS switching */ 56 55 int dvs_control_src; /** Hardware DVS source to use (1 or 2) */ 57 56 int dvs_init_state; /** DVS state to expect on startup */ 58 57 int dvs_state_gpio; /** CPU GPIO to use for monitoring status */