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

USB: FHCI: Switch to GPIO descriptors

This driver for the PPC Freescale SoC is using device tree
accessors and imperative GPIO semantics control using the old
GPIO API, switch it over to use GPIO descriptors.

Cc: Li Yang <leoyang.li@nxp.com>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: Zhao Qiang <qiang.zhao@freescale.com>
Cc: Guilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20220831082932.488724-1-linus.walleij@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Linus Walleij and committed by
Greg Kroah-Hartman
a4efdb8a 10174220

+26 -54
+17 -44
drivers/usb/host/fhci-hcd.c
··· 25 25 #include <linux/of_address.h> 26 26 #include <linux/of_irq.h> 27 27 #include <linux/of_platform.h> 28 - #include <linux/of_gpio.h> 29 28 #include <linux/slab.h> 29 + #include <linux/gpio/consumer.h> 30 30 #include <soc/fsl/qe/qe.h> 31 31 #include <asm/fsl_gtm.h> 32 32 #include "fhci.h" ··· 150 150 u8 bits = 0; 151 151 152 152 /* check USBOE,if transmitting,exit */ 153 - if (!gpio_get_value(fhci->gpios[GPIO_USBOE])) 153 + if (!gpiod_get_value(fhci->gpiods[GPIO_USBOE])) 154 154 return -1; 155 155 156 156 /* check USBRP */ 157 - if (gpio_get_value(fhci->gpios[GPIO_USBRP])) 157 + if (gpiod_get_value(fhci->gpiods[GPIO_USBRP])) 158 158 bits |= 0x2; 159 159 160 160 /* check USBRN */ 161 - if (gpio_get_value(fhci->gpios[GPIO_USBRN])) 161 + if (gpiod_get_value(fhci->gpiods[GPIO_USBRN])) 162 162 bits |= 0x1; 163 163 164 164 return bits; ··· 630 630 631 631 /* GPIOs and pins */ 632 632 for (i = 0; i < NUM_GPIOS; i++) { 633 - int gpio; 634 - enum of_gpio_flags flags; 633 + if (i < GPIO_SPEED) 634 + fhci->gpiods[i] = devm_gpiod_get_index(dev, 635 + NULL, i, GPIOD_IN); 635 636 636 - gpio = of_get_gpio_flags(node, i, &flags); 637 - fhci->gpios[i] = gpio; 638 - fhci->alow_gpios[i] = flags & OF_GPIO_ACTIVE_LOW; 637 + else 638 + fhci->gpiods[i] = devm_gpiod_get_index_optional(dev, 639 + NULL, i, GPIOD_OUT_LOW); 639 640 640 - if (!gpio_is_valid(gpio)) { 641 - if (i < GPIO_SPEED) { 642 - dev_err(dev, "incorrect GPIO%d: %d\n", 643 - i, gpio); 644 - goto err_gpios; 645 - } else { 646 - dev_info(dev, "assuming board doesn't have " 647 - "%s gpio\n", i == GPIO_SPEED ? 648 - "speed" : "power"); 649 - continue; 650 - } 651 - } 652 - 653 - ret = gpio_request(gpio, dev_name(dev)); 654 - if (ret) { 655 - dev_err(dev, "failed to request gpio %d", i); 641 + if (IS_ERR(fhci->gpiods[i])) { 642 + dev_err(dev, "incorrect GPIO%d: %ld\n", 643 + i, PTR_ERR(fhci->gpiods[i])); 656 644 goto err_gpios; 657 645 } 658 - 659 - if (i >= GPIO_SPEED) { 660 - ret = gpio_direction_output(gpio, 0); 661 - if (ret) { 662 - dev_err(dev, "failed to set gpio %d as " 663 - "an output\n", i); 664 - i++; 665 - goto err_gpios; 666 - } 646 + if (!fhci->gpiods[i]) { 647 + dev_info(dev, "assuming board doesn't have " 648 + "%s gpio\n", i == GPIO_SPEED ? 649 + "speed" : "power"); 667 650 } 668 651 } 669 652 ··· 749 766 while (--j >= 0) 750 767 qe_pin_free(fhci->pins[j]); 751 768 err_gpios: 752 - while (--i >= 0) { 753 - if (gpio_is_valid(fhci->gpios[i])) 754 - gpio_free(fhci->gpios[i]); 755 - } 756 769 cpm_muram_free(pram_addr); 757 770 err_pram: 758 771 iounmap(hcd->regs); ··· 761 782 { 762 783 struct usb_hcd *hcd = dev_get_drvdata(dev); 763 784 struct fhci_hcd *fhci = hcd_to_fhci(hcd); 764 - int i; 765 785 int j; 766 786 767 787 usb_remove_hcd(hcd); 768 788 free_irq(fhci->timer->irq, hcd); 769 789 gtm_put_timer16(fhci->timer); 770 790 cpm_muram_free(cpm_muram_offset(fhci->pram)); 771 - for (i = 0; i < NUM_GPIOS; i++) { 772 - if (!gpio_is_valid(fhci->gpios[i])) 773 - continue; 774 - gpio_free(fhci->gpios[i]); 775 - } 776 791 for (j = 0; j < NUM_PINS; j++) 777 792 qe_pin_free(fhci->pins[j]); 778 793 fhci_dfs_destroy(fhci);
+7 -8
drivers/usb/host/fhci-hub.c
··· 19 19 #include <linux/io.h> 20 20 #include <linux/usb.h> 21 21 #include <linux/usb/hcd.h> 22 - #include <linux/gpio.h> 22 + #include <linux/gpio/consumer.h> 23 23 #include <soc/fsl/qe/qe.h> 24 24 #include "fhci.h" 25 25 ··· 38 38 39 39 static void fhci_gpio_set_value(struct fhci_hcd *fhci, int gpio_nr, bool on) 40 40 { 41 - int gpio = fhci->gpios[gpio_nr]; 42 - bool alow = fhci->alow_gpios[gpio_nr]; 41 + struct gpio_desc *gpiod = fhci->gpiods[gpio_nr]; 43 42 44 - if (!gpio_is_valid(gpio)) 43 + if (!gpiod) 45 44 return; 46 45 47 - gpio_set_value(gpio, on ^ alow); 46 + gpiod_set_value(gpiod, on); 48 47 mdelay(5); 49 48 } 50 49 ··· 128 129 { 129 130 fhci_dbg(fhci, "-> %s\n", __func__); 130 131 131 - gpio_direction_output(fhci->gpios[GPIO_USBOE], 0); 132 - gpio_direction_output(fhci->gpios[GPIO_USBTP], 0); 133 - gpio_direction_output(fhci->gpios[GPIO_USBTN], 0); 132 + gpiod_direction_output(fhci->gpiods[GPIO_USBOE], 0); 133 + gpiod_direction_output(fhci->gpiods[GPIO_USBTP], 0); 134 + gpiod_direction_output(fhci->gpiods[GPIO_USBTN], 0); 134 135 135 136 mdelay(5); 136 137
+2 -2
drivers/usb/host/fhci.h
··· 23 23 #include <linux/io.h> 24 24 #include <linux/usb.h> 25 25 #include <linux/usb/hcd.h> 26 + #include <linux/gpio/consumer.h> 26 27 #include <soc/fsl/qe/qe.h> 27 28 #include <soc/fsl/qe/immap_qe.h> 28 29 ··· 243 242 enum qe_clock fullspeed_clk; 244 243 enum qe_clock lowspeed_clk; 245 244 struct qe_pin *pins[NUM_PINS]; 246 - int gpios[NUM_GPIOS]; 247 - bool alow_gpios[NUM_GPIOS]; 245 + struct gpio_desc *gpiods[NUM_GPIOS]; 248 246 249 247 struct qe_usb_ctlr __iomem *regs; /* I/O memory used to communicate */ 250 248 struct fhci_pram __iomem *pram; /* Parameter RAM */