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

usb: phy: phy-gpio-vbus-usb: Convert to GPIO descriptors

Instead of using the legacy GPIO API and keeping track on
polarity inversion semantics in the driver, switch to use
GPIO descriptors for this driver and change all consumers
in the process.

This makes it possible to retire platform data completely:
the only remaining platform data member was "wakeup" which
was intended to make the vbus interrupt wakeup capable,
but was not set by any users and thus remained unused. VBUS
was not waking any devices up. Leave a comment about it so
later developers using the platform can consider setting it
to always enabled so plugging in USB wakes up the platform.

Cc: Daniel Mack <daniel@zonque.org>
Cc: Haojian Zhuang <haojian.zhuang@gmail.com>
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Acked-by: Felipe Balbi <balbi@kernel.org>
Acked-by: Sylwester Nawrocki <snawrocki@kernel.org>
Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20200123155013.93249-1-linus.walleij@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Linus Walleij and committed by
Greg Kroah-Hartman
fdabc466 eb7a3bb8

+188 -193
+9 -7
arch/arm/mach-pxa/colibri-pxa320.c
··· 11 11 #include <linux/init.h> 12 12 #include <linux/kernel.h> 13 13 #include <linux/platform_device.h> 14 + #include <linux/gpio/machine.h> 14 15 #include <linux/gpio.h> 15 16 #include <linux/interrupt.h> 16 - #include <linux/usb/gpio_vbus.h> 17 17 18 18 #include <asm/mach-types.h> 19 19 #include <linux/sizes.h> ··· 144 144 #endif /* CONFIG_AX88796 */ 145 145 146 146 #if defined(CONFIG_USB_PXA27X)||defined(CONFIG_USB_PXA27X_MODULE) 147 - static struct gpio_vbus_mach_info colibri_pxa320_gpio_vbus_info = { 148 - .gpio_vbus = mfp_to_gpio(MFP_PIN_GPIO96), 149 - .gpio_pullup = -1, 147 + static struct gpiod_lookup_table gpio_vbus_gpiod_table = { 148 + .dev_id = "gpio-vbus", 149 + .table = { 150 + GPIO_LOOKUP("gpio-pxa", MFP_PIN_GPIO96, 151 + "vbus", GPIO_ACTIVE_HIGH), 152 + { }, 153 + }, 150 154 }; 151 155 152 156 static struct platform_device colibri_pxa320_gpio_vbus = { 153 157 .name = "gpio-vbus", 154 158 .id = -1, 155 - .dev = { 156 - .platform_data = &colibri_pxa320_gpio_vbus_info, 157 - }, 158 159 }; 159 160 160 161 static void colibri_pxa320_udc_command(int cmd) ··· 174 173 static void __init colibri_pxa320_init_udc(void) 175 174 { 176 175 pxa_set_udc_info(&colibri_pxa320_udc_info); 176 + gpiod_add_lookup_table(&gpio_vbus_gpiod_table); 177 177 platform_device_register(&colibri_pxa320_gpio_vbus); 178 178 } 179 179 #else
+25 -15
arch/arm/mach-pxa/eseries.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/init.h> 16 16 #include <linux/clk-provider.h> 17 + #include <linux/gpio/machine.h> 17 18 #include <linux/gpio.h> 18 19 #include <linux/delay.h> 19 20 #include <linux/platform_device.h> ··· 23 22 #include <linux/mfd/t7l66xb.h> 24 23 #include <linux/mtd/rawnand.h> 25 24 #include <linux/mtd/partitions.h> 26 - #include <linux/usb/gpio_vbus.h> 27 25 #include <linux/memblock.h> 28 26 29 27 #include <video/w100fb.h> ··· 51 51 memblock_add(0xa0000000, SZ_64M); 52 52 } 53 53 54 - struct gpio_vbus_mach_info e7xx_udc_info = { 55 - .gpio_vbus = GPIO_E7XX_USB_DISC, 56 - .gpio_pullup = GPIO_E7XX_USB_PULLUP, 57 - .gpio_pullup_inverted = 1 54 + static struct gpiod_lookup_table e7xx_gpio_vbus_gpiod_table __maybe_unused = { 55 + .dev_id = "gpio-vbus", 56 + .table = { 57 + GPIO_LOOKUP("gpio-pxa", GPIO_E7XX_USB_DISC, 58 + "vbus", GPIO_ACTIVE_HIGH), 59 + GPIO_LOOKUP("gpio-pxa", GPIO_E7XX_USB_PULLUP, 60 + "pullup", GPIO_ACTIVE_LOW), 61 + { }, 62 + }, 58 63 }; 59 64 60 65 static struct platform_device e7xx_gpio_vbus __maybe_unused = { 61 66 .name = "gpio-vbus", 62 67 .id = -1, 63 - .dev = { 64 - .platform_data = &e7xx_udc_info, 65 - }, 66 68 }; 67 69 68 70 struct pxaficp_platform_data e7xx_ficp_platform_data = { ··· 167 165 pxa_set_stuart_info(NULL); 168 166 eseries_register_clks(); 169 167 eseries_get_tmio_gpios(); 168 + gpiod_add_lookup_table(&e7xx_gpio_vbus_gpiod_table); 170 169 platform_add_devices(ARRAY_AND_SIZE(e330_devices)); 171 170 } 172 171 ··· 219 216 pxa_set_stuart_info(NULL); 220 217 eseries_register_clks(); 221 218 eseries_get_tmio_gpios(); 219 + gpiod_add_lookup_table(&e7xx_gpio_vbus_gpiod_table); 222 220 platform_add_devices(ARRAY_AND_SIZE(e350_devices)); 223 221 } 224 222 ··· 344 340 eseries_register_clks(); 345 341 eseries_get_tmio_gpios(); 346 342 pxa_set_fb_info(NULL, &e400_pxafb_mach_info); 343 + gpiod_add_lookup_table(&e7xx_gpio_vbus_gpiod_table); 347 344 platform_add_devices(ARRAY_AND_SIZE(e400_devices)); 348 345 } 349 346 ··· 539 534 clk_add_alias("CLK_CK48M", e740_t7l66xb_device.name, 540 535 "UDCCLK", &pxa25x_device_udc.dev), 541 536 eseries_get_tmio_gpios(); 537 + gpiod_add_lookup_table(&e7xx_gpio_vbus_gpiod_table); 542 538 platform_add_devices(ARRAY_AND_SIZE(e740_devices)); 543 539 pxa_set_ac97_info(NULL); 544 540 pxa_set_ficp_info(&e7xx_ficp_platform_data); ··· 739 733 clk_add_alias("CLK_CK3P6MI", e750_tc6393xb_device.name, 740 734 "GPIO11_CLK", NULL), 741 735 eseries_get_tmio_gpios(); 736 + gpiod_add_lookup_table(&e7xx_gpio_vbus_gpiod_table); 742 737 platform_add_devices(ARRAY_AND_SIZE(e750_devices)); 743 738 pxa_set_ac97_info(NULL); 744 739 pxa_set_ficp_info(&e7xx_ficp_platform_data); ··· 895 888 896 889 /* --------------------------- UDC definitions --------------------------- */ 897 890 898 - static struct gpio_vbus_mach_info e800_udc_info = { 899 - .gpio_vbus = GPIO_E800_USB_DISC, 900 - .gpio_pullup = GPIO_E800_USB_PULLUP, 901 - .gpio_pullup_inverted = 1 891 + static struct gpiod_lookup_table e800_gpio_vbus_gpiod_table = { 892 + .dev_id = "gpio-vbus", 893 + .table = { 894 + GPIO_LOOKUP("gpio-pxa", GPIO_E800_USB_DISC, 895 + "vbus", GPIO_ACTIVE_HIGH), 896 + GPIO_LOOKUP("gpio-pxa", GPIO_E800_USB_PULLUP, 897 + "pullup", GPIO_ACTIVE_LOW), 898 + { }, 899 + }, 902 900 }; 903 901 904 902 static struct platform_device e800_gpio_vbus = { 905 903 .name = "gpio-vbus", 906 904 .id = -1, 907 - .dev = { 908 - .platform_data = &e800_udc_info, 909 - }, 910 905 }; 911 906 912 907 ··· 958 949 clk_add_alias("CLK_CK3P6MI", e800_tc6393xb_device.name, 959 950 "GPIO11_CLK", NULL), 960 951 eseries_get_tmio_gpios(); 952 + gpiod_add_lookup_table(&e800_gpio_vbus_gpiod_table); 961 953 platform_add_devices(ARRAY_AND_SIZE(e800_devices)); 962 954 pxa_set_ac97_info(NULL); 963 955 }
+11 -7
arch/arm/mach-pxa/gumstix.c
··· 20 20 #include <linux/delay.h> 21 21 #include <linux/mtd/mtd.h> 22 22 #include <linux/mtd/partitions.h> 23 + #include <linux/gpio/machine.h> 23 24 #include <linux/gpio.h> 24 25 #include <linux/err.h> 25 26 #include <linux/clk.h> 26 - #include <linux/usb/gpio_vbus.h> 27 27 28 28 #include <asm/setup.h> 29 29 #include <asm/memory.h> ··· 101 101 #endif 102 102 103 103 #ifdef CONFIG_USB_PXA25X 104 - static struct gpio_vbus_mach_info gumstix_udc_info = { 105 - .gpio_vbus = GPIO_GUMSTIX_USB_GPIOn, 106 - .gpio_pullup = GPIO_GUMSTIX_USB_GPIOx, 104 + static struct gpiod_lookup_table gumstix_gpio_vbus_gpiod_table = { 105 + .dev_id = "gpio-vbus", 106 + .table = { 107 + GPIO_LOOKUP("gpio-pxa", GPIO_GUMSTIX_USB_GPIOn, 108 + "vbus", GPIO_ACTIVE_HIGH), 109 + GPIO_LOOKUP("gpio-pxa", GPIO_GUMSTIX_USB_GPIOx, 110 + "pullup", GPIO_ACTIVE_HIGH), 111 + { }, 112 + }, 107 113 }; 108 114 109 115 static struct platform_device gumstix_gpio_vbus = { 110 116 .name = "gpio-vbus", 111 117 .id = -1, 112 - .dev = { 113 - .platform_data = &gumstix_udc_info, 114 - }, 115 118 }; 116 119 117 120 static void __init gumstix_udc_init(void) 118 121 { 122 + gpiod_add_lookup_table(&gumstix_gpio_vbus_gpiod_table); 119 123 platform_device_register(&gumstix_gpio_vbus); 120 124 } 121 125 #else
+14 -8
arch/arm/mach-pxa/hx4700.c
··· 34 34 #include <linux/spi/ads7846.h> 35 35 #include <linux/spi/spi.h> 36 36 #include <linux/spi/pxa2xx_spi.h> 37 - #include <linux/usb/gpio_vbus.h> 38 37 #include <linux/platform_data/i2c-pxa.h> 39 38 40 39 #include <mach/hardware.h> ··· 577 578 * USB "Transceiver" 578 579 */ 579 580 580 - static struct gpio_vbus_mach_info gpio_vbus_info = { 581 - .gpio_pullup = GPIO76_HX4700_USBC_PUEN, 582 - .gpio_vbus = GPIOD14_nUSBC_DETECT, 583 - .gpio_vbus_inverted = 1, 581 + static struct gpiod_lookup_table gpio_vbus_gpiod_table = { 582 + .dev_id = "gpio-vbus", 583 + .table = { 584 + /* This GPIO is on ASIC3 */ 585 + GPIO_LOOKUP("asic3", 586 + /* Convert to a local offset on the ASIC3 */ 587 + GPIOD14_nUSBC_DETECT - HX4700_ASIC3_GPIO_BASE, 588 + "vbus", GPIO_ACTIVE_LOW), 589 + /* This one is on the primary SOC GPIO */ 590 + GPIO_LOOKUP("gpio-pxa", GPIO76_HX4700_USBC_PUEN, 591 + "pullup", GPIO_ACTIVE_HIGH), 592 + { }, 593 + }, 584 594 }; 585 595 586 596 static struct platform_device gpio_vbus = { 587 597 .name = "gpio-vbus", 588 598 .id = -1, 589 - .dev = { 590 - .platform_data = &gpio_vbus_info, 591 - }, 592 599 }; 593 600 594 601 static struct pxa2xx_udc_mach_info hx4700_udc_info; ··· 888 883 pxa_set_stuart_info(NULL); 889 884 890 885 gpiod_add_lookup_table(&bq24022_gpiod_table); 886 + gpiod_add_lookup_table(&gpio_vbus_gpiod_table); 891 887 platform_add_devices(devices, ARRAY_SIZE(devices)); 892 888 pwm_add_table(hx4700_pwm_lookup, ARRAY_SIZE(hx4700_pwm_lookup)); 893 889
+15 -7
arch/arm/mach-pxa/magician.c
··· 27 27 #include <linux/regulator/fixed.h> 28 28 #include <linux/regulator/gpio-regulator.h> 29 29 #include <linux/regulator/machine.h> 30 - #include <linux/usb/gpio_vbus.h> 31 30 #include <linux/platform_data/i2c-pxa.h> 32 31 33 32 #include <mach/hardware.h> ··· 505 506 .end = IRQ_MAGICIAN_VBUS, 506 507 }; 507 508 508 - static struct gpio_vbus_mach_info gpio_vbus_info = { 509 - .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN, 510 - .gpio_vbus = EGPIO_MAGICIAN_CABLE_VBUS, 509 + static struct gpiod_lookup_table gpio_vbus_gpiod_table = { 510 + .dev_id = "gpio-vbus", 511 + .table = { 512 + /* 513 + * EGPIO on register 4 index 1, the second EGPIO chip 514 + * starts at register 4 so this will be at index 1 on that 515 + * chip. 516 + */ 517 + GPIO_LOOKUP("htc-egpio-1", 1, 518 + "vbus", GPIO_ACTIVE_HIGH), 519 + GPIO_LOOKUP("gpio-pxa", GPIO27_MAGICIAN_USBC_PUEN, 520 + "pullup", GPIO_ACTIVE_HIGH), 521 + { }, 522 + }, 511 523 }; 512 524 513 525 static struct platform_device gpio_vbus = { ··· 526 516 .id = -1, 527 517 .num_resources = 1, 528 518 .resource = &gpio_vbus_resource, 529 - .dev = { 530 - .platform_data = &gpio_vbus_info, 531 - }, 532 519 }; 533 520 534 521 /* ··· 1039 1032 ARRAY_SIZE(pwm_backlight_supply), 5000000); 1040 1033 1041 1034 gpiod_add_lookup_table(&bq24022_gpiod_table); 1035 + gpiod_add_lookup_table(&gpio_vbus_gpiod_table); 1042 1036 platform_add_devices(ARRAY_AND_SIZE(devices)); 1043 1037 } 1044 1038
+9 -6
arch/arm/mach-pxa/mioa701.c
··· 24 24 #include <linux/power_supply.h> 25 25 #include <linux/wm97xx.h> 26 26 #include <linux/mtd/physmap.h> 27 - #include <linux/usb/gpio_vbus.h> 28 27 #include <linux/reboot.h> 29 28 #include <linux/regulator/fixed.h> 30 29 #include <linux/regulator/max1586.h> ··· 367 368 .gpio_pullup = GPIO22_USB_ENABLE, 368 369 }; 369 370 370 - struct gpio_vbus_mach_info gpio_vbus_data = { 371 - .gpio_vbus = GPIO13_nUSB_DETECT, 372 - .gpio_vbus_inverted = 1, 373 - .gpio_pullup = -1, 371 + static struct gpiod_lookup_table gpio_vbus_gpiod_table = { 372 + .dev_id = "gpio-vbus", 373 + .table = { 374 + GPIO_LOOKUP("gpio-pxa", GPIO13_nUSB_DETECT, 375 + "vbus", GPIO_ACTIVE_LOW), 376 + { }, 377 + }, 374 378 }; 375 379 376 380 /* ··· 679 677 MIO_SIMPLE_DEV(pxa2xx_pcm, "pxa2xx-pcm", NULL) 680 678 MIO_SIMPLE_DEV(mioa701_sound, "mioa701-wm9713", NULL) 681 679 MIO_SIMPLE_DEV(mioa701_board, "mioa701-board", NULL) 682 - MIO_SIMPLE_DEV(gpio_vbus, "gpio-vbus", &gpio_vbus_data); 680 + MIO_SIMPLE_DEV(gpio_vbus, "gpio-vbus", NULL); 683 681 684 682 static struct platform_device *devices[] __initdata = { 685 683 &mioa701_gpio_keys, ··· 752 750 pxa_set_ac97_info(&mioa701_ac97_info); 753 751 pm_power_off = mioa701_poweroff; 754 752 pwm_add_table(mioa701_pwm_lookup, ARRAY_SIZE(mioa701_pwm_lookup)); 753 + gpiod_add_lookup_table(&gpio_vbus_gpiod_table); 755 754 platform_add_devices(devices, ARRAY_SIZE(devices)); 756 755 gsm_init(); 757 756
+17 -17
arch/arm/mach-pxa/palm27x.c
··· 13 13 #include <linux/pda_power.h> 14 14 #include <linux/pwm.h> 15 15 #include <linux/pwm_backlight.h> 16 + #include <linux/gpio/machine.h> 16 17 #include <linux/gpio.h> 17 18 #include <linux/wm97xx.h> 18 19 #include <linux/power_supply.h> 19 - #include <linux/usb/gpio_vbus.h> 20 20 #include <linux/regulator/max1586.h> 21 21 #include <linux/platform_data/i2c-pxa.h> 22 22 ··· 159 159 ******************************************************************************/ 160 160 #if defined(CONFIG_USB_PXA27X) || \ 161 161 defined(CONFIG_USB_PXA27X_MODULE) 162 - static struct gpio_vbus_mach_info palm27x_udc_info = { 163 - .gpio_vbus_inverted = 1, 162 + 163 + /* The actual GPIO offsets get filled in in the palm27x_udc_init() call */ 164 + static struct gpiod_lookup_table palm27x_udc_gpiod_table = { 165 + .dev_id = "gpio-vbus", 166 + .table = { 167 + GPIO_LOOKUP("gpio-pxa", 0, 168 + "vbus", GPIO_ACTIVE_HIGH), 169 + GPIO_LOOKUP("gpio-pxa", 0, 170 + "pullup", GPIO_ACTIVE_HIGH), 171 + { }, 172 + }, 164 173 }; 165 174 166 175 static struct platform_device palm27x_gpio_vbus = { 167 176 .name = "gpio-vbus", 168 177 .id = -1, 169 - .dev = { 170 - .platform_data = &palm27x_udc_info, 171 - }, 172 178 }; 173 179 174 180 void __init palm27x_udc_init(int vbus, int pullup, int vbus_inverted) 175 181 { 176 - palm27x_udc_info.gpio_vbus = vbus; 177 - palm27x_udc_info.gpio_pullup = pullup; 182 + palm27x_udc_gpiod_table.table[0].chip_hwnum = vbus; 183 + palm27x_udc_gpiod_table.table[1].chip_hwnum = pullup; 184 + if (vbus_inverted) 185 + palm27x_udc_gpiod_table.table[0].flags = GPIO_ACTIVE_LOW; 178 186 179 - palm27x_udc_info.gpio_vbus_inverted = vbus_inverted; 180 - 181 - if (!gpio_request(pullup, "USB Pullup")) { 182 - gpio_direction_output(pullup, 183 - palm27x_udc_info.gpio_vbus_inverted); 184 - gpio_free(pullup); 185 - } else 186 - return; 187 - 187 + gpiod_add_lookup_table(&palm27x_udc_gpiod_table); 188 188 platform_device_register(&palm27x_gpio_vbus); 189 189 } 190 190 #endif
-1
arch/arm/mach-pxa/palmt5.c
··· 23 23 #include <linux/gpio.h> 24 24 #include <linux/wm97xx.h> 25 25 #include <linux/power_supply.h> 26 - #include <linux/usb/gpio_vbus.h> 27 26 28 27 #include <asm/mach-types.h> 29 28 #include <asm/mach/arch.h>
+10 -8
arch/arm/mach-pxa/palmtc.c
··· 23 23 #include <linux/power_supply.h> 24 24 #include <linux/gpio_keys.h> 25 25 #include <linux/mtd/physmap.h> 26 - #include <linux/usb/gpio_vbus.h> 27 26 28 27 #include <asm/mach-types.h> 29 28 #include <asm/mach/arch.h> ··· 318 319 * UDC 319 320 ******************************************************************************/ 320 321 #if defined(CONFIG_USB_PXA25X)||defined(CONFIG_USB_PXA25X_MODULE) 321 - static struct gpio_vbus_mach_info palmtc_udc_info = { 322 - .gpio_vbus = GPIO_NR_PALMTC_USB_DETECT_N, 323 - .gpio_vbus_inverted = 1, 324 - .gpio_pullup = GPIO_NR_PALMTC_USB_POWER, 322 + static struct gpiod_lookup_table palmtc_udc_gpiod_table = { 323 + .dev_id = "gpio-vbus", 324 + .table = { 325 + GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTC_USB_DETECT_N, 326 + "vbus", GPIO_ACTIVE_LOW), 327 + GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTC_USB_POWER, 328 + "pullup", GPIO_ACTIVE_HIGH), 329 + { }, 330 + }, 325 331 }; 326 332 327 333 static struct platform_device palmtc_gpio_vbus = { 328 334 .name = "gpio-vbus", 329 335 .id = -1, 330 - .dev = { 331 - .platform_data = &palmtc_udc_info, 332 - }, 333 336 }; 334 337 335 338 static void __init palmtc_udc_init(void) 336 339 { 340 + gpiod_add_lookup_table(&palmtc_udc_gpiod_table); 337 341 platform_device_register(&palmtc_gpio_vbus); 338 342 }; 339 343 #else
+10 -8
arch/arm/mach-pxa/palmte2.c
··· 23 23 #include <linux/gpio.h> 24 24 #include <linux/wm97xx.h> 25 25 #include <linux/power_supply.h> 26 - #include <linux/usb/gpio_vbus.h> 27 26 28 27 #include <asm/mach-types.h> 29 28 #include <asm/mach/arch.h> ··· 200 201 /****************************************************************************** 201 202 * UDC 202 203 ******************************************************************************/ 203 - static struct gpio_vbus_mach_info palmte2_udc_info = { 204 - .gpio_vbus = GPIO_NR_PALMTE2_USB_DETECT_N, 205 - .gpio_vbus_inverted = 1, 206 - .gpio_pullup = GPIO_NR_PALMTE2_USB_PULLUP, 204 + static struct gpiod_lookup_table palmte2_udc_gpiod_table = { 205 + .dev_id = "gpio-vbus", 206 + .table = { 207 + GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTE2_USB_DETECT_N, 208 + "vbus", GPIO_ACTIVE_LOW), 209 + GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTE2_USB_PULLUP, 210 + "pullup", GPIO_ACTIVE_HIGH), 211 + { }, 212 + }, 207 213 }; 208 214 209 215 static struct platform_device palmte2_gpio_vbus = { 210 216 .name = "gpio-vbus", 211 217 .id = -1, 212 - .dev = { 213 - .platform_data = &palmte2_udc_info, 214 - }, 215 218 }; 216 219 217 220 /****************************************************************************** ··· 369 368 pxa_set_ficp_info(&palmte2_ficp_platform_data); 370 369 371 370 pwm_add_table(palmte2_pwm_lookup, ARRAY_SIZE(palmte2_pwm_lookup)); 371 + gpiod_add_lookup_table(&palmte2_udc_gpiod_table); 372 372 platform_add_devices(devices, ARRAY_SIZE(devices)); 373 373 } 374 374
-1
arch/arm/mach-pxa/palmtx.c
··· 23 23 #include <linux/gpio.h> 24 24 #include <linux/wm97xx.h> 25 25 #include <linux/power_supply.h> 26 - #include <linux/usb/gpio_vbus.h> 27 26 #include <linux/mtd/platnand.h> 28 27 #include <linux/mtd/mtd.h> 29 28 #include <linux/mtd/physmap.h>
-1
arch/arm/mach-pxa/palmz72.c
··· 25 25 #include <linux/gpio.h> 26 26 #include <linux/wm97xx.h> 27 27 #include <linux/power_supply.h> 28 - #include <linux/usb/gpio_vbus.h> 29 28 #include <linux/platform_data/i2c-gpio.h> 30 29 #include <linux/gpio/machine.h> 31 30
+10 -8
arch/arm/mach-pxa/tosa.c
··· 33 33 #include <linux/spi/pxa2xx_spi.h> 34 34 #include <linux/input/matrix_keypad.h> 35 35 #include <linux/platform_data/i2c-pxa.h> 36 - #include <linux/usb/gpio_vbus.h> 37 36 #include <linux/reboot.h> 38 37 #include <linux/memblock.h> 39 38 ··· 239 240 /* 240 241 * USB Device Controller 241 242 */ 242 - static struct gpio_vbus_mach_info tosa_udc_info = { 243 - .gpio_pullup = TOSA_GPIO_USB_PULLUP, 244 - .gpio_vbus = TOSA_GPIO_USB_IN, 245 - .gpio_vbus_inverted = 1, 243 + static struct gpiod_lookup_table tosa_udc_gpiod_table = { 244 + .dev_id = "gpio-vbus", 245 + .table = { 246 + GPIO_LOOKUP("gpio-pxa", TOSA_GPIO_USB_IN, 247 + "vbus", GPIO_ACTIVE_LOW), 248 + GPIO_LOOKUP("gpio-pxa", TOSA_GPIO_USB_PULLUP, 249 + "pullup", GPIO_ACTIVE_HIGH), 250 + { }, 251 + }, 246 252 }; 247 253 248 254 static struct platform_device tosa_gpio_vbus = { 249 255 .name = "gpio-vbus", 250 256 .id = -1, 251 - .dev = { 252 - .platform_data = &tosa_udc_info, 253 - }, 254 257 }; 255 258 256 259 /* ··· 950 949 951 950 clk_add_alias("CLK_CK3P6MI", tc6393xb_device.name, "GPIO11_CLK", NULL); 952 951 952 + gpiod_add_lookup_table(&tosa_udc_gpiod_table); 953 953 platform_add_devices(devices, ARRAY_SIZE(devices)); 954 954 } 955 955
+8 -7
arch/arm/mach-pxa/vpac270.c
··· 14 14 #include <linux/leds.h> 15 15 #include <linux/gpio.h> 16 16 #include <linux/gpio/machine.h> 17 - #include <linux/usb/gpio_vbus.h> 18 17 #include <linux/mtd/mtd.h> 19 18 #include <linux/mtd/partitions.h> 20 19 #include <linux/mtd/physmap.h> ··· 351 352 * USB Gadget 352 353 ******************************************************************************/ 353 354 #if defined(CONFIG_USB_PXA27X)||defined(CONFIG_USB_PXA27X_MODULE) 354 - static struct gpio_vbus_mach_info vpac270_gpio_vbus_info = { 355 - .gpio_vbus = GPIO41_VPAC270_UDC_DETECT, 356 - .gpio_pullup = -1, 355 + static struct gpiod_lookup_table vpac270_gpio_vbus_gpiod_table = { 356 + .dev_id = "gpio-vbus", 357 + .table = { 358 + GPIO_LOOKUP("gpio-pxa", GPIO41_VPAC270_UDC_DETECT, 359 + "vbus", GPIO_ACTIVE_HIGH), 360 + { }, 361 + }, 357 362 }; 358 363 359 364 static struct platform_device vpac270_gpio_vbus = { 360 365 .name = "gpio-vbus", 361 366 .id = -1, 362 - .dev = { 363 - .platform_data = &vpac270_gpio_vbus_info, 364 - }, 365 367 }; 366 368 367 369 static void vpac270_udc_command(int cmd) ··· 381 381 static void __init vpac270_udc_init(void) 382 382 { 383 383 pxa_set_udc_info(&vpac270_udc_info); 384 + gpiod_add_lookup_table(&vpac270_gpio_vbus_gpiod_table); 384 385 platform_device_register(&vpac270_gpio_vbus); 385 386 } 386 387 #else
+7 -6
arch/arm/mach-s3c64xx/mach-smartq.c
··· 13 13 #include <linux/serial_core.h> 14 14 #include <linux/serial_s3c.h> 15 15 #include <linux/spi/spi_gpio.h> 16 - #include <linux/usb/gpio_vbus.h> 17 16 #include <linux/platform_data/s3c-hsotg.h> 18 17 19 18 #include <asm/mach-types.h> ··· 123 124 .enable_oc = smartq_usb_host_enableoc, 124 125 }; 125 126 126 - static struct gpio_vbus_mach_info smartq_usb_otg_vbus_pdata = { 127 - .gpio_vbus = S3C64XX_GPL(9), 128 - .gpio_pullup = -1, 129 - .gpio_vbus_inverted = true, 127 + static struct gpiod_lookup_table smartq_usb_otg_vbus_gpiod_table = { 128 + .dev_id = "gpio-vbus", 129 + .table = { 130 + GPIO_LOOKUP("GPL", 9, "vbus", GPIO_ACTIVE_LOW), 131 + { }, 132 + }, 130 133 }; 131 134 132 135 static struct platform_device smartq_usb_otg_vbus_dev = { 133 136 .name = "gpio-vbus", 134 - .dev.platform_data = &smartq_usb_otg_vbus_pdata, 135 137 }; 136 138 137 139 static struct pwm_lookup smartq_pwm_lookup[] = { ··· 418 418 419 419 pwm_add_table(smartq_pwm_lookup, ARRAY_SIZE(smartq_pwm_lookup)); 420 420 gpiod_add_lookup_table(&smartq_lcd_control_gpiod_table); 421 + gpiod_add_lookup_table(&smartq_usb_otg_vbus_gpiod_table); 421 422 platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices)); 422 423 423 424 gpiod_add_lookup_table(&smartq_audio_gpios);
+43 -53
drivers/usb/phy/phy-gpio-vbus-usb.c
··· 7 7 8 8 #include <linux/kernel.h> 9 9 #include <linux/platform_device.h> 10 - #include <linux/gpio.h> 10 + #include <linux/gpio/consumer.h> 11 11 #include <linux/module.h> 12 12 #include <linux/slab.h> 13 13 #include <linux/interrupt.h> ··· 17 17 #include <linux/regulator/consumer.h> 18 18 19 19 #include <linux/usb/gadget.h> 20 - #include <linux/usb/gpio_vbus.h> 21 20 #include <linux/usb/otg.h> 22 21 23 22 ··· 28 29 * Needs to be loaded before the UDC driver that will use it. 29 30 */ 30 31 struct gpio_vbus_data { 32 + struct gpio_desc *vbus_gpiod; 33 + struct gpio_desc *pullup_gpiod; 31 34 struct usb_phy phy; 32 35 struct device *dev; 33 36 struct regulator *vbus_draw; ··· 84 83 gpio_vbus->mA = mA; 85 84 } 86 85 87 - static int is_vbus_powered(struct gpio_vbus_mach_info *pdata) 86 + static int is_vbus_powered(struct gpio_vbus_data *gpio_vbus) 88 87 { 89 - int vbus; 90 - 91 - vbus = gpio_get_value(pdata->gpio_vbus); 92 - if (pdata->gpio_vbus_inverted) 93 - vbus = !vbus; 94 - 95 - return vbus; 88 + return gpiod_get_value(gpio_vbus->vbus_gpiod); 96 89 } 97 90 98 91 static void gpio_vbus_work(struct work_struct *work) 99 92 { 100 93 struct gpio_vbus_data *gpio_vbus = 101 94 container_of(work, struct gpio_vbus_data, work.work); 102 - struct gpio_vbus_mach_info *pdata = dev_get_platdata(gpio_vbus->dev); 103 - int gpio, status, vbus; 95 + int status, vbus; 104 96 105 97 if (!gpio_vbus->phy.otg->gadget) 106 98 return; 107 99 108 - vbus = is_vbus_powered(pdata); 100 + vbus = is_vbus_powered(gpio_vbus); 109 101 if ((vbus ^ gpio_vbus->vbus) == 0) 110 102 return; 111 103 gpio_vbus->vbus = vbus; 112 104 113 105 /* Peripheral controllers which manage the pullup themselves won't have 114 - * gpio_pullup configured here. If it's configured here, we'll do what 115 - * isp1301_omap::b_peripheral() does and enable the pullup here... although 116 - * that may complicate usb_gadget_{,dis}connect() support. 106 + * a pullup GPIO configured here. If it's configured here, we'll do 107 + * what isp1301_omap::b_peripheral() does and enable the pullup here... 108 + * although that may complicate usb_gadget_{,dis}connect() support. 117 109 */ 118 - gpio = pdata->gpio_pullup; 119 110 120 111 if (vbus) { 121 112 status = USB_EVENT_VBUS; ··· 119 126 set_vbus_draw(gpio_vbus, 100); 120 127 121 128 /* optionally enable D+ pullup */ 122 - if (gpio_is_valid(gpio)) 123 - gpio_set_value(gpio, !pdata->gpio_pullup_inverted); 129 + if (gpio_vbus->pullup_gpiod) 130 + gpiod_set_value(gpio_vbus->pullup_gpiod, 1); 124 131 125 132 atomic_notifier_call_chain(&gpio_vbus->phy.notifier, 126 133 status, gpio_vbus->phy.otg->gadget); 127 134 usb_phy_set_event(&gpio_vbus->phy, USB_EVENT_ENUMERATED); 128 135 } else { 129 136 /* optionally disable D+ pullup */ 130 - if (gpio_is_valid(gpio)) 131 - gpio_set_value(gpio, pdata->gpio_pullup_inverted); 137 + if (gpio_vbus->pullup_gpiod) 138 + gpiod_set_value(gpio_vbus->pullup_gpiod, 0); 132 139 133 140 set_vbus_draw(gpio_vbus, 0); 134 141 ··· 147 154 static irqreturn_t gpio_vbus_irq(int irq, void *data) 148 155 { 149 156 struct platform_device *pdev = data; 150 - struct gpio_vbus_mach_info *pdata = dev_get_platdata(&pdev->dev); 151 157 struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); 152 158 struct usb_otg *otg = gpio_vbus->phy.otg; 153 159 154 160 dev_dbg(&pdev->dev, "VBUS %s (gadget: %s)\n", 155 - is_vbus_powered(pdata) ? "supplied" : "inactive", 161 + is_vbus_powered(gpio_vbus) ? "supplied" : "inactive", 156 162 otg->gadget ? otg->gadget->name : "none"); 157 163 158 164 if (otg->gadget) ··· 167 175 struct usb_gadget *gadget) 168 176 { 169 177 struct gpio_vbus_data *gpio_vbus; 170 - struct gpio_vbus_mach_info *pdata; 171 178 struct platform_device *pdev; 172 - int gpio; 173 179 174 180 gpio_vbus = container_of(otg->usb_phy, struct gpio_vbus_data, phy); 175 181 pdev = to_platform_device(gpio_vbus->dev); 176 - pdata = dev_get_platdata(gpio_vbus->dev); 177 - gpio = pdata->gpio_pullup; 178 182 179 183 if (!gadget) { 180 184 dev_dbg(&pdev->dev, "unregistering gadget '%s'\n", 181 185 otg->gadget->name); 182 186 183 187 /* optionally disable D+ pullup */ 184 - if (gpio_is_valid(gpio)) 185 - gpio_set_value(gpio, pdata->gpio_pullup_inverted); 188 + if (gpio_vbus->pullup_gpiod) 189 + gpiod_set_value(gpio_vbus->pullup_gpiod, 0); 186 190 187 191 set_vbus_draw(gpio_vbus, 0); 188 192 ··· 230 242 231 243 static int gpio_vbus_probe(struct platform_device *pdev) 232 244 { 233 - struct gpio_vbus_mach_info *pdata = dev_get_platdata(&pdev->dev); 234 245 struct gpio_vbus_data *gpio_vbus; 235 246 struct resource *res; 236 - int err, gpio, irq; 247 + struct device *dev = &pdev->dev; 248 + int err, irq; 237 249 unsigned long irqflags; 238 - 239 - if (!pdata || !gpio_is_valid(pdata->gpio_vbus)) 240 - return -EINVAL; 241 - gpio = pdata->gpio_vbus; 242 250 243 251 gpio_vbus = devm_kzalloc(&pdev->dev, sizeof(struct gpio_vbus_data), 244 252 GFP_KERNEL); ··· 257 273 gpio_vbus->phy.otg->usb_phy = &gpio_vbus->phy; 258 274 gpio_vbus->phy.otg->set_peripheral = gpio_vbus_set_peripheral; 259 275 260 - err = devm_gpio_request(&pdev->dev, gpio, "vbus_detect"); 261 - if (err) { 262 - dev_err(&pdev->dev, "can't request vbus gpio %d, err: %d\n", 263 - gpio, err); 276 + /* Look up the VBUS sensing GPIO */ 277 + gpio_vbus->vbus_gpiod = devm_gpiod_get(dev, "vbus", GPIOD_IN); 278 + if (IS_ERR(gpio_vbus->vbus_gpiod)) { 279 + err = PTR_ERR(gpio_vbus->vbus_gpiod); 280 + dev_err(&pdev->dev, "can't request vbus gpio, err: %d\n", err); 264 281 return err; 265 282 } 266 - gpio_direction_input(gpio); 283 + gpiod_set_consumer_name(gpio_vbus->vbus_gpiod, "vbus_detect"); 267 284 268 285 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 269 286 if (res) { 270 287 irq = res->start; 271 288 irqflags = (res->flags & IRQF_TRIGGER_MASK) | IRQF_SHARED; 272 289 } else { 273 - irq = gpio_to_irq(gpio); 290 + irq = gpiod_to_irq(gpio_vbus->vbus_gpiod); 274 291 irqflags = VBUS_IRQ_FLAGS; 275 292 } 276 293 277 294 gpio_vbus->irq = irq; 278 295 279 - /* if data line pullup is in use, initialize it to "not pulling up" */ 280 - gpio = pdata->gpio_pullup; 281 - if (gpio_is_valid(gpio)) { 282 - err = devm_gpio_request(&pdev->dev, gpio, "udc_pullup"); 283 - if (err) { 284 - dev_err(&pdev->dev, 285 - "can't request pullup gpio %d, err: %d\n", 286 - gpio, err); 287 - return err; 288 - } 289 - gpio_direction_output(gpio, pdata->gpio_pullup_inverted); 296 + /* 297 + * The VBUS sensing GPIO should have a pulldown, which will normally be 298 + * part of a resistor ladder turning a 4.0V-5.25V level on VBUS into a 299 + * value the GPIO detects as active. Some systems will use comparators. 300 + * Get the optional D+ or D- pullup GPIO. If the data line pullup is 301 + * in use, initialize it to "not pulling up" 302 + */ 303 + gpio_vbus->pullup_gpiod = devm_gpiod_get_optional(dev, "pullup", 304 + GPIOD_OUT_LOW); 305 + if (IS_ERR(gpio_vbus->pullup_gpiod)) { 306 + err = PTR_ERR(gpio_vbus->pullup_gpiod); 307 + dev_err(&pdev->dev, "can't request pullup gpio, err: %d\n", 308 + err); 309 + return err; 290 310 } 311 + if (gpio_vbus->pullup_gpiod) 312 + gpiod_set_consumer_name(gpio_vbus->pullup_gpiod, "udc_pullup"); 291 313 292 314 err = devm_request_irq(&pdev->dev, irq, gpio_vbus_irq, irqflags, 293 315 "vbus_detect", pdev); ··· 320 330 return err; 321 331 } 322 332 323 - device_init_wakeup(&pdev->dev, pdata->wakeup); 333 + /* TODO: wakeup could be enabled here with device_init_wakeup(dev, 1) */ 324 334 325 335 return 0; 326 336 }
-33
include/linux/usb/gpio_vbus.h
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * A simple GPIO VBUS sensing driver for B peripheral only devices 4 - * with internal transceivers. 5 - * Optionally D+ pullup can be controlled by a second GPIO. 6 - * 7 - * Copyright (c) 2008 Philipp Zabel <philipp.zabel@gmail.com> 8 - * 9 - * This program is free software; you can redistribute it and/or modify 10 - * it under the terms of the GNU General Public License version 2 as 11 - * published by the Free Software Foundation. 12 - * 13 - */ 14 - 15 - /** 16 - * struct gpio_vbus_mach_info - configuration for gpio_vbus 17 - * @gpio_vbus: VBUS sensing GPIO 18 - * @gpio_pullup: optional D+ or D- pullup GPIO (else negative/invalid) 19 - * @gpio_vbus_inverted: true if gpio_vbus is active low 20 - * @gpio_pullup_inverted: true if gpio_pullup is active low 21 - * @wakeup: configure gpio_vbus as a wake-up source 22 - * 23 - * The VBUS sensing GPIO should have a pulldown, which will normally be 24 - * part of a resistor ladder turning a 4.0V-5.25V level on VBUS into a 25 - * value the GPIO detects as active. Some systems will use comparators. 26 - */ 27 - struct gpio_vbus_mach_info { 28 - int gpio_vbus; 29 - int gpio_pullup; 30 - bool gpio_vbus_inverted; 31 - bool gpio_pullup_inverted; 32 - bool wakeup; 33 - };