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

regulator: fixed/gpio: Pull inversion/OD into gpiolib

This pushes the handling of inversion semantics and open drain
settings to the GPIO descriptor and gpiolib. All affected board
files are also augmented.

This is especially nice since we don't have to have any
confusing flags passed around to the left and right littering
the fixed and GPIO regulator drivers and the regulator core.
It is all just very straight-forward: the core asks the GPIO
line to be asserted or deasserted and gpiolib deals with the
rest depending on how the platform is configured: if the line
is active low, it deals with that, if the line is open drain,
it deals with that too.

Cc: Alexander Shiyan <shc_work@mail.ru> # i.MX boards user
Cc: Haojian Zhuang <haojian.zhuang@gmail.com> # MMP2 maintainer
Cc: Aaro Koskinen <aaro.koskinen@iki.fi> # OMAP1 maintainer
Cc: Tony Lindgren <tony@atomide.com> # OMAP1,2,3 maintainer
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com> # EM-X270 maintainer
Cc: Robert Jarzmik <robert.jarzmik@free.fr> # EZX maintainer
Cc: Philipp Zabel <philipp.zabel@gmail.com> # Magician maintainer
Cc: Petr Cvek <petr.cvek@tul.cz> # Magician
Cc: Robert Jarzmik <robert.jarzmik@free.fr> # PXA
Cc: Paul Parsons <lost.distance@yahoo.com> # hx4700
Cc: Daniel Mack <zonque@gmail.com> # Raumfeld maintainer
Cc: Marc Zyngier <marc.zyngier@arm.com> # Zeus maintainer
Cc: Geert Uytterhoeven <geert+renesas@glider.be> # SuperH pinctrl/GPIO maintainer
Cc: Russell King <rmk+kernel@armlinux.org.uk> # SA1100
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Janusz Krzysztofik <jmkrzyszt@gmail.com> #OMAP1 Amstrad Delta
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Linus Walleij and committed by
Mark Brown
01dc79cd d6cd33ad

+13 -66
-1
arch/arm/mach-imx/mach-mx21ads.c
··· 205 205 static struct fixed_voltage_config mx21ads_lcd_regulator_pdata = { 206 206 .supply_name = "LCD", 207 207 .microvolts = 3300000, 208 - .enable_high = 1, 209 208 .init_data = &mx21ads_lcd_regulator_init_data, 210 209 }; 211 210
+1 -1
arch/arm/mach-imx/mach-mx27ads.c
··· 237 237 static struct gpiod_lookup_table mx27ads_lcd_regulator_gpiod_table = { 238 238 .dev_id = "reg-fixed-voltage.0", /* Let's hope ID 0 is what we get */ 239 239 .table = { 240 - GPIO_LOOKUP("LCD", 0, NULL, GPIO_ACTIVE_HIGH), 240 + GPIO_LOOKUP("LCD", 0, NULL, GPIO_ACTIVE_LOW), 241 241 { }, 242 242 }, 243 243 };
-1
arch/arm/mach-mmp/brownstone.c
··· 149 149 static struct fixed_voltage_config brownstone_v_5vp = { 150 150 .supply_name = "v_5vp", 151 151 .microvolts = 5000000, 152 - .enable_high = 1, 153 152 .enabled_at_boot = 1, 154 153 .init_data = &brownstone_v_5vp_data, 155 154 };
-2
arch/arm/mach-omap1/board-ams-delta.c
··· 267 267 .supply_name = "modem_nreset", 268 268 .microvolts = 3300000, 269 269 .startup_delay = 25000, 270 - .enable_high = 1, 271 270 .enabled_at_boot = 1, 272 271 .init_data = &modem_nreset_data, 273 272 }; ··· 532 533 static struct fixed_voltage_config keybrd_pwr_config = { 533 534 .supply_name = "keybrd_pwr", 534 535 .microvolts = 5000000, 535 - .enable_high = 1, 536 536 .init_data = &keybrd_pwr_initdata, 537 537 }; 538 538
-1
arch/arm/mach-omap2/pdata-quirks.c
··· 330 330 .supply_name = "vwlan", 331 331 .microvolts = 1800000, /* 1.8V */ 332 332 .startup_delay = 50000, /* 50ms */ 333 - .enable_high = 1, 334 333 .init_data = &pandora_vmmc3, 335 334 }; 336 335
-1
arch/arm/mach-pxa/em-x270.c
··· 976 976 .supply_name = "camera_vdd", 977 977 .input_supply = "vcc cam", 978 978 .microvolts = 2800000, 979 - .enable_high = 0, 980 979 .init_data = &camera_dummy_initdata, 981 980 }; 982 981
+1 -2
arch/arm/mach-pxa/ezx.c
··· 714 714 static struct fixed_voltage_config camera_regulator_config = { 715 715 .supply_name = "camera_vdd", 716 716 .microvolts = 2800000, 717 - .enable_high = 0, 718 717 .init_data = &camera_regulator_initdata, 719 718 }; 720 719 ··· 729 730 .dev_id = "reg-fixed-voltage.1", 730 731 .table = { 731 732 GPIO_LOOKUP("gpio-pxa", GPIO50_nCAM_EN, 732 - NULL, GPIO_ACTIVE_HIGH), 733 + NULL, GPIO_ACTIVE_LOW), 733 734 { }, 734 735 }, 735 736 };
-1
arch/arm/mach-pxa/raumfeld.c
··· 883 883 static struct fixed_voltage_config audio_va_config = { 884 884 .supply_name = "audio_va", 885 885 .microvolts = 5000000, 886 - .enable_high = 1, 887 886 .enabled_at_boot = 0, 888 887 .init_data = &audio_va_initdata, 889 888 };
+1 -2
arch/arm/mach-pxa/zeus.c
··· 426 426 .dev_id = "reg-fixed-voltage.0", 427 427 .table = { 428 428 GPIO_LOOKUP("gpio-pxa", ZEUS_CAN_SHDN_GPIO, 429 - NULL, GPIO_ACTIVE_HIGH), 429 + NULL, GPIO_ACTIVE_LOW), 430 430 { }, 431 431 }, 432 432 }; ··· 547 547 static struct fixed_voltage_config zeus_ohci_regulator_config = { 548 548 .supply_name = "vbus2", 549 549 .microvolts = 5000000, /* 5.0V */ 550 - .enable_high = 1, 551 550 .startup_delay = 0, 552 551 .init_data = &zeus_ohci_regulator_data, 553 552 };
-1
arch/arm/mach-sa1100/assabet.c
··· 469 469 static struct fixed_voltage_config assabet_cf_vcc_pdata __initdata = { 470 470 .supply_name = "cf-power", 471 471 .microvolts = 3300000, 472 - .enable_high = 1, 473 472 }; 474 473 475 474 static struct gpiod_lookup_table assabet_cf_vcc_gpio_table = {
-2
arch/sh/boards/mach-ecovec24/setup.c
··· 630 630 static struct fixed_voltage_config cn12_power_info = { 631 631 .supply_name = "CN12 SD/MMC Vdd", 632 632 .microvolts = 3300000, 633 - .enable_high = 1, 634 633 .init_data = &cn12_power_init_data, 635 634 }; 636 635 ··· 670 671 static struct fixed_voltage_config sdhi0_power_info = { 671 672 .supply_name = "CN11 SD/MMC Vdd", 672 673 .microvolts = 3300000, 673 - .enable_high = 1, 674 674 .init_data = &sdhi0_power_init_data, 675 675 }; 676 676
-1
arch/x86/platform/intel-mid/device_libs/platform_bcm43xx.c
··· 44 44 */ 45 45 .microvolts = 2000000, /* 1.8V */ 46 46 .startup_delay = 250 * 1000, /* 250ms */ 47 - .enable_high = 1, /* active high */ 48 47 .enabled_at_boot = 0, /* disabled at boot */ 49 48 .init_data = &bcm43xx_vmmc_data, 50 49 };
+2 -6
drivers/regulator/core.c
··· 82 82 struct gpio_desc *gpiod; 83 83 u32 enable_count; /* a number of enabled shared GPIO */ 84 84 u32 request_count; /* a number of requested shared GPIO */ 85 - unsigned int ena_gpio_invert:1; 86 85 }; 87 86 88 87 /* ··· 2267 2268 } 2268 2269 2269 2270 pin->gpiod = gpiod; 2270 - pin->ena_gpio_invert = config->ena_gpio_invert; 2271 2271 list_add(&pin->list, &regulator_ena_gpio_list); 2272 2272 2273 2273 update_ena_gpio_to_rdev: ··· 2317 2319 if (enable) { 2318 2320 /* Enable GPIO at initial use */ 2319 2321 if (pin->enable_count == 0) 2320 - gpiod_set_value_cansleep(pin->gpiod, 2321 - !pin->ena_gpio_invert); 2322 + gpiod_set_value_cansleep(pin->gpiod, 1); 2322 2323 2323 2324 pin->enable_count++; 2324 2325 } else { ··· 2328 2331 2329 2332 /* Disable GPIO if not used */ 2330 2333 if (pin->enable_count <= 1) { 2331 - gpiod_set_value_cansleep(pin->gpiod, 2332 - pin->ena_gpio_invert); 2334 + gpiod_set_value_cansleep(pin->gpiod, 0); 2333 2335 pin->enable_count = 0; 2334 2336 } 2335 2337 }
-1
drivers/regulator/da9055-regulator.c
··· 457 457 int gpio_mux = pdata->gpio_ren[id]; 458 458 459 459 config->ena_gpiod = pdata->ena_gpiods[id]; 460 - config->ena_gpio_invert = 1; 461 460 462 461 /* 463 462 * GPI pin is muxed with regulator to control the
+8 -27
drivers/regulator/fixed.c
··· 79 79 80 80 of_property_read_u32(np, "startup-delay-us", &config->startup_delay); 81 81 82 - /* 83 - * FIXME: we pulled active low/high and open drain handling into 84 - * gpiolib so it will be handled there. Delete this in the second 85 - * step when we also remove the custom inversion handling for all 86 - * legacy boardfiles. 87 - */ 88 - config->enable_high = 1; 89 - config->gpio_is_open_drain = 0; 90 - 91 82 if (of_find_property(np, "vin-supply", NULL)) 92 83 config->input_supply = "vin"; 93 84 ··· 142 151 143 152 drvdata->desc.fixed_uV = config->microvolts; 144 153 145 - cfg.ena_gpio_invert = !config->enable_high; 146 - if (config->enabled_at_boot) { 147 - if (config->enable_high) 148 - gflags = GPIOD_OUT_HIGH; 149 - else 150 - gflags = GPIOD_OUT_LOW; 151 - } else { 152 - if (config->enable_high) 153 - gflags = GPIOD_OUT_LOW; 154 - else 155 - gflags = GPIOD_OUT_HIGH; 156 - } 157 - if (config->gpio_is_open_drain) { 158 - if (gflags == GPIOD_OUT_HIGH) 159 - gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; 160 - else 161 - gflags = GPIOD_OUT_LOW_OPEN_DRAIN; 162 - } 154 + /* 155 + * The signal will be inverted by the GPIO core if flagged so in the 156 + * decriptor. 157 + */ 158 + if (config->enabled_at_boot) 159 + gflags = GPIOD_OUT_HIGH; 160 + else 161 + gflags = GPIOD_OUT_LOW; 163 162 164 163 /* 165 164 * Some fixed regulators share the enable line between two
-10
include/linux/regulator/fixed.h
··· 25 25 * @input_supply: Name of the input regulator supply 26 26 * @microvolts: Output voltage of regulator 27 27 * @startup_delay: Start-up time in microseconds 28 - * @gpio_is_open_drain: Gpio pin is open drain or normal type. 29 - * If it is open drain type then HIGH will be set 30 - * through PULL-UP with setting gpio as input 31 - * and low will be set as gpio-output with driven 32 - * to low. For non-open-drain case, the gpio will 33 - * will be in output and drive to low/high accordingly. 34 - * @enable_high: Polarity of enable GPIO 35 - * 1 = Active high, 0 = Active low 36 28 * @enabled_at_boot: Whether regulator has been enabled at 37 29 * boot or not. 1 = Yes, 0 = No 38 30 * This is used to keep the regulator at ··· 40 48 const char *input_supply; 41 49 int microvolts; 42 50 unsigned startup_delay; 43 - unsigned gpio_is_open_drain:1; 44 - unsigned enable_high:1; 45 51 unsigned enabled_at_boot:1; 46 52 struct regulator_init_data *init_data; 47 53 };
-6
include/linux/regulator/gpio-regulator.h
··· 46 46 /** 47 47 * struct gpio_regulator_config - config structure 48 48 * @supply_name: Name of the regulator supply 49 - * @enable_gpio: GPIO to use for enable control 50 - * set to -EINVAL if not used 51 - * @enable_high: Polarity of enable GPIO 52 - * 1 = Active high, 0 = Active low 53 49 * @enabled_at_boot: Whether regulator has been enabled at 54 50 * boot or not. 1 = Yes, 0 = No 55 51 * This is used to keep the regulator at ··· 67 71 struct gpio_regulator_config { 68 72 const char *supply_name; 69 73 70 - int enable_gpio; 71 - unsigned enable_high:1; 72 74 unsigned enabled_at_boot:1; 73 75 unsigned startup_delay; 74 76