[PATCH v6 partial 0/2] pxa27x_udc port to device-tree and gpio_desc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Felipe and Linus,

As you requested, Felipe, I made the translation for the driver's
probing from gpio to gpio_desc. Even if the code is functional, I'm
pretty unhappy about my patch 1, because I lost the "active_low"
notion in the transformation.

I have not found in the gpiolib anything for a driver to set that
active_low value, only for machine code. The legacy behaviour was that
that information was handed over to the driver.

As transforming the different pxa27x_udc users will be not part of
this serie, ie. because the mach info should be kept ISO for this
serie, Linus, do you have an idea so that I still can port to
gpio_desc this driver, and keep the gpio_inverted notion in it ?

Ah, and I sent only 2 out of the 6 patches of the serie, mainly
because Linus doesn't care about the remaining stuff, which remained
constant from last version (at rebase conflicts resolution exception
of course).

Cheers.

--
Robert

Robert Jarzmik (2):
  usb: gadget: pxa27x_udc: prepare device-tree support
  usb: gadget: pxa27x_udc: add devicetree support

 drivers/usb/gadget/udc/pxa27x_udc.c | 61 +++++++++++++++++++++----------------
 drivers/usb/gadget/udc/pxa27x_udc.h |  6 ++--
 2 files changed, 38 insertions(+), 29 deletions(-)

-- 
2.0.0.rc2

PS: For Felipe, the diff of the complete serie, for a one quick glance
    overview, and not for review is attached to this mail.
 drivers/usb/gadget/udc/pxa27x_udc.c | 96 +++++++++----------------------------
 drivers/usb/gadget/udc/pxa27x_udc.h | 10 ++--
 2 files changed, 26 insertions(+), 80 deletions(-)

diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c
index 9506da8..adbe74a 100644
--- a/drivers/usb/gadget/udc/pxa27x_udc.c
+++ b/drivers/usb/gadget/udc/pxa27x_udc.c
@@ -22,6 +22,7 @@
 #include <linux/clk.h>
 #include <linux/irq.h>
 #include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/slab.h>
 #include <linux/prefetch.h>
 #include <linux/byteorder/generic.h>
@@ -1509,18 +1510,13 @@ static struct usb_ep_ops pxa_ep_ops = {
  */
 static void dplus_pullup(struct pxa_udc *udc, int on)
 {
-	if (on) {
-		if (gpio_is_valid(udc->gpio_pullup))
-			gpio_set_value(udc->gpio_pullup,
-				       !udc->gpio_pullup_inverted);
-		if (udc->mach && udc->mach->udc_command)
-			udc->mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
-	} else {
-		if (gpio_is_valid(udc->gpio_pullup))
-			gpio_set_value(udc->gpio_pullup,
-				       udc->gpio_pullup_inverted);
-		if (udc->mach && udc->mach->udc_command)
-			udc->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
+	if (udc->gpiod) {
+		gpiod_set_value(udc->gpiod, on);
+	} else if (udc->udc_command) {
+		if (on)
+			udc->udc_command(PXA2XX_UDC_CMD_CONNECT);
+		else
+			udc->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
 	}
 	udc->pullup_on = on;
 }
@@ -1611,8 +1607,7 @@ static int pxa_udc_pullup(struct usb_gadget *_gadget, int is_active)
 {
 	struct pxa_udc *udc = to_gadget_udc(_gadget);
 
-	if (!gpio_is_valid(udc->gpio_pullup)
-	    && !(udc->mach && udc->mach->udc_command))
+	if (!udc->gpiod && !udc->udc_command)
 		return -EOPNOTSUPP;
 
 	dplus_pullup(udc, is_active);
@@ -2414,50 +2409,6 @@ static struct of_device_id udc_pxa_dt_ids[] = {
 MODULE_DEVICE_TABLE(of, udc_pxa_dt_ids);
 
 /**
- * pxa_udc_probe_dt - device tree specific probe
- * @pdev: platform data
- * @udc: pxa_udc structure to fill
- *
- * Fills udc from platform data out of device tree.
- *
- * Returns 0 if DT found, 1 if DT not found, and <0 on error
- */
-static int pxa_udc_probe_dt(struct platform_device *pdev, struct pxa_udc *udc)
-{
-	struct device_node *np = pdev->dev.of_node;
-	const struct of_device_id *of_id =
-			of_match_device(udc_pxa_dt_ids, &pdev->dev);
-	u32 gpio_pullup;
-	enum of_gpio_flags flags;
-
-	if (!np || !of_id)
-		return 1;
-	pdev->id = -1;
-
-	gpio_pullup = of_get_gpio_flags(np, 0, &flags);
-	if (gpio_pullup >= 0) {
-		udc->gpio_pullup = gpio_pullup;
-		udc->gpio_pullup_inverted = (flags & OF_GPIO_ACTIVE_LOW);
-	}
-	return 0;
-}
-
-/**
- * pxa_udc_probe_pdata - legacy platform data probe
- * @pdev: platform device
- * @udc: pxa_udc structure to fill
- *
- * Simple copy of data from platform_data to udc control structure
- */
-static void pxa_udc_probe_pdata(struct platform_device *pdev,
-			       struct pxa_udc *udc)
-{
-	udc->mach = dev_get_platdata(&pdev->dev);
-	udc->gpio_pullup = udc->mach->gpio_pullup;
-	udc->gpio_pullup_inverted = udc->mach->gpio_pullup_inverted;
-}
-
-/**
  * pxa_udc_probe - probes the udc device
  * @_dev: platform device
  *
@@ -2468,13 +2419,15 @@ static int pxa_udc_probe(struct platform_device *pdev)
 {
 	struct resource *regs;
 	struct pxa_udc *udc = &memory;
+	struct pxa2xx_udc_mach_info *mach = dev_get_platdata(&pdev->dev);
 	int retval = 0;
 
-	retval = pxa_udc_probe_dt(pdev, udc);
-	if (retval < 0)
-		return retval;
-	if (retval > 0)
-		pxa_udc_probe_pdata(pdev, udc);
+	if (mach) {
+		udc->gpiod = gpio_to_desc(mach->gpio_pullup);
+		udc->udc_command = mach->udc_command;
+	} else {
+		udc->gpiod = devm_gpiod_get(&pdev->dev, NULL);
+	}
 
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	udc->regs = devm_ioremap_resource(&pdev->dev, regs);
@@ -2487,18 +2440,13 @@ static int pxa_udc_probe(struct platform_device *pdev)
 	udc->dev = &pdev->dev;
 	udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
 
-	if (gpio_is_valid(udc->gpio_pullup)) {
-		retval = devm_gpio_request(&pdev->dev,
-					   udc->gpio_pullup, "USB D+ pullup");
-		if (retval == 0)
-			gpio_direction_output(udc->gpio_pullup,
-				       udc->gpio_pullup_inverted);
-	}
-	if (retval) {
-		dev_err(&pdev->dev, "Couldn't request gpio %d : %d\n",
-			udc->gpio_pullup, retval);
-		return retval;
+	if (IS_ERR(udc->gpiod)) {
+		dev_err(&pdev->dev, "Couldn't find or request D+ gpio : %ld\n",
+			PTR_ERR(udc->gpiod));
+		return PTR_ERR(udc->gpiod);
 	}
+	if (udc->gpiod)
+		gpiod_direction_output(udc->gpiod, 0);
 
 	udc->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(udc->clk))
diff --git a/drivers/usb/gadget/udc/pxa27x_udc.h b/drivers/usb/gadget/udc/pxa27x_udc.h
index 8995b34..11e1423 100644
--- a/drivers/usb/gadget/udc/pxa27x_udc.h
+++ b/drivers/usb/gadget/udc/pxa27x_udc.h
@@ -420,9 +420,8 @@ struct udc_stats {
  * @usb_gadget: udc gadget structure
  * @driver: bound gadget (zero, g_ether, g_mass_storage, ...)
  * @dev: device
- * @mach: machine info, used to activate specific GPIO
- * @gpio_pullup: if valid, D+ pullup GPIO
- * @gpio_pullup_inverted: 1 if pullup has inverted logic
+ * @udc_command: machine specific function to activate D+ pullup
+ * @gpiod: gpio descriptor of gpio for D+ pullup (or NULL if none)
  * @transceiver: external transceiver to handle vbus sense and D+ pullup
  * @ep0state: control endpoint state machine state
  * @stats: statistics on udc usage
@@ -448,10 +447,9 @@ struct pxa_udc {
 	struct usb_gadget			gadget;
 	struct usb_gadget_driver		*driver;
 	struct device				*dev;
-	struct pxa2xx_udc_mach_info		*mach;
+	void					(*udc_command)(int);
+	struct gpio_desc			*gpiod;
 	struct usb_phy				*transceiver;
-	int					gpio_pullup;
-	int					gpio_pullup_inverted;
 
 	enum ep0_state				ep0state;
 	struct udc_stats			stats;
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux