From patchwork Fri Oct 17 17:16:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 38990 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8717A202DB for ; Fri, 17 Oct 2014 17:20:17 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id a1sf722984wgh.1 for ; Fri, 17 Oct 2014 10:20:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=MiKCd/MLq9wJ+gGgRvzl4/zSiMeGobigbf/ACG8U3A0=; b=Le4P8zEmpOjThPq9zrIz/njrhVZ88irr8t4C05u+Dssp8fC/7OVW+y51TuKl+Extln y1ElFpbdwpNCVy1gXd77k3yaiskq8R5ysSzL1tf+PIgDWNVbnKJxePc2P702q23dJNHM ZT8suGCj+suh4EXcGqBMxF91qIqy+ooLSyMDfE6Y3xpMqspEUt1aQHwKT0i5jEvl/IAe lowAofvOrIou7PiXRGcn1NsCKxPx/FD26re5Uq90Elz/6nWqp6Sdf0U5Rvh4FAlFvrte cQjW9zZf5LFiPAMkIPtk3mKFEirnbBJMTapalQj1wXpMcMBWwUso4BYzS10YXS/OyQzJ phOg== X-Gm-Message-State: ALoCoQmUNAQBwhHwGuBfswnvMirXvloCoXKG6tp4/OdhGxa1VNSPabOAczSDQ4EbWNIUOTrOXXm8 X-Received: by 10.194.241.232 with SMTP id wl8mr629386wjc.5.1413566416728; Fri, 17 Oct 2014 10:20:16 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.133 with SMTP id b5ls256921lah.26.gmail; Fri, 17 Oct 2014 10:20:16 -0700 (PDT) X-Received: by 10.152.204.103 with SMTP id kx7mr10285874lac.7.1413566416239; Fri, 17 Oct 2014 10:20:16 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id kv1si3015787lac.53.2014.10.17.10.20.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Oct 2014 10:20:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id p9so1061479lbv.33 for ; Fri, 17 Oct 2014 10:20:16 -0700 (PDT) X-Received: by 10.112.130.41 with SMTP id ob9mr10087154lbb.74.1413566416159; Fri, 17 Oct 2014 10:20:16 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp268454lbz; Fri, 17 Oct 2014 10:20:15 -0700 (PDT) X-Received: by 10.68.134.230 with SMTP id pn6mr9960832pbb.88.1413566414349; Fri, 17 Oct 2014 10:20:14 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gv6si1574384pac.208.2014.10.17.10.20.13 for ; Fri, 17 Oct 2014 10:20:14 -0700 (PDT) Received-SPF: none (google.com: linux-usb-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753862AbaJQRUK (ORCPT + 3 others); Fri, 17 Oct 2014 13:20:10 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:44322 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753364AbaJQRRs (ORCPT ); Fri, 17 Oct 2014 13:17:48 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s9HHHchI008032; Fri, 17 Oct 2014 12:17:38 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9HHHceG029271; Fri, 17 Oct 2014 12:17:38 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Fri, 17 Oct 2014 12:17:38 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s9HHHbii030298; Fri, 17 Oct 2014 12:17:38 -0500 From: Felipe Balbi To: Linux USB Mailing List CC: Greg KH , , Paul Zimmerman , , , , , , , Robert Jarzmik , Felipe Balbi Subject: [PATCH 13/67] usb: gadget: pxa27x_udc: prepare device-tree support Date: Fri, 17 Oct 2014 12:16:20 -0500 Message-ID: <1413566234-13537-14-git-send-email-balbi@ti.com> X-Mailer: git-send-email 2.1.0.GIT In-Reply-To: <1413566234-13537-1-git-send-email-balbi@ti.com> References: <1413566234-13537-1-git-send-email-balbi@ti.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: balbi@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Robert Jarzmik For this preparation, a preliminary cleanup is done : - convert the probing of pxa27x_udc to gpio_desc. The conversion is partial because : - the platform data still provides a gpio number, not a gpio desc Signed-off-by: Robert Jarzmik Signed-off-by: Felipe Balbi --- drivers/usb/gadget/udc/pxa27x_udc.c | 55 +++++++++++++++++++------------------ drivers/usb/gadget/udc/pxa27x_udc.h | 2 ++ 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c index 4868369..d583197 100644 --- a/drivers/usb/gadget/udc/pxa27x_udc.c +++ b/drivers/usb/gadget/udc/pxa27x_udc.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -1507,17 +1508,12 @@ 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->mach->gpio_pullup)) - gpio_set_value(udc->mach->gpio_pullup, - !udc->mach->gpio_pullup_inverted); - if (udc->mach->udc_command) + if (udc->gpiod) { + gpiod_set_value(udc->gpiod, on); + } else if (udc->mach && udc->mach->udc_command) { + if (on) udc->mach->udc_command(PXA2XX_UDC_CMD_CONNECT); - } else { - if (gpio_is_valid(udc->mach->gpio_pullup)) - gpio_set_value(udc->mach->gpio_pullup, - udc->mach->gpio_pullup_inverted); - if (udc->mach->udc_command) + else udc->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); } udc->pullup_on = on; @@ -1609,7 +1605,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->mach->gpio_pullup) && !udc->mach->udc_command) + if (!udc->gpiod && !udc->mach->udc_command) return -EOPNOTSUPP; dplus_pullup(udc, is_active); @@ -2416,6 +2412,22 @@ static int pxa_udc_probe(struct platform_device *pdev) struct resource *regs; struct pxa_udc *udc = &memory; int retval = 0, gpio; + struct pxa2xx_udc_mach_info *mach = dev_get_platdata(&pdev->dev); + unsigned long gpio_flags; + + if (mach) { + gpio_flags = mach->gpio_pullup_inverted ? GPIOF_ACTIVE_LOW : 0; + gpio = mach->gpio_pullup; + if (gpio_is_valid(gpio)) { + retval = devm_gpio_request_one(&pdev->dev, gpio, + gpio_flags, + "USB D+ pullup"); + if (retval) + return retval; + udc->gpiod = gpio_to_desc(mach->gpio_pullup); + } + udc->mach = mach; + } regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!regs) @@ -2425,21 +2437,15 @@ static int pxa_udc_probe(struct platform_device *pdev) return udc->irq; udc->dev = &pdev->dev; - udc->mach = dev_get_platdata(&pdev->dev); udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); - gpio = udc->mach->gpio_pullup; - if (gpio_is_valid(gpio)) { - retval = gpio_request(gpio, "USB D+ pullup"); - if (retval == 0) - gpio_direction_output(gpio, - udc->mach->gpio_pullup_inverted); - } - if (retval) { - dev_err(&pdev->dev, "Couldn't request gpio %d : %d\n", - gpio, 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 = clk_get(&pdev->dev, NULL); if (IS_ERR(udc->clk)) { @@ -2501,14 +2507,11 @@ err_clk: static int pxa_udc_remove(struct platform_device *_dev) { struct pxa_udc *udc = platform_get_drvdata(_dev); - int gpio = udc->mach->gpio_pullup; usb_del_gadget_udc(&udc->gadget); usb_gadget_unregister_driver(udc->driver); free_irq(udc->irq, udc); pxa_cleanup_debugfs(udc); - if (gpio_is_valid(gpio)) - gpio_free(gpio); usb_put_phy(udc->transceiver); diff --git a/drivers/usb/gadget/udc/pxa27x_udc.h b/drivers/usb/gadget/udc/pxa27x_udc.h index 28f2b53..f025693 100644 --- a/drivers/usb/gadget/udc/pxa27x_udc.h +++ b/drivers/usb/gadget/udc/pxa27x_udc.h @@ -421,6 +421,7 @@ struct udc_stats { * @driver: bound gadget (zero, g_ether, g_mass_storage, ...) * @dev: device * @mach: machine info, used to activate specific GPIO + * @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 @@ -447,6 +448,7 @@ struct pxa_udc { struct usb_gadget_driver *driver; struct device *dev; struct pxa2xx_udc_mach_info *mach; + struct gpio_desc *gpiod; struct usb_phy *transceiver; enum ep0_state ep0state;