History

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.

Linus Walleij committed 6 years ago

Commit fdabc461 parent eb7a3bb17 files · +188 −193Browse files

Unified · Split

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