From patchwork Thu Jul 16 12:34:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 235644 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp753558ilg; Thu, 16 Jul 2020 05:34:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKcbZkSQmDDHT4qKsMuoe1j/PFDETKzcMXGT6Ks8SIpbRzsrtJ0Dy+3zcVGrHgGHvEUSfS X-Received: by 2002:a17:906:f91a:: with SMTP id lc26mr3386648ejb.372.1594902880706; Thu, 16 Jul 2020 05:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594902880; cv=none; d=google.com; s=arc-20160816; b=GcFNQUnrIyyDWmcW1AxoGjZJSW+8h4KK3bJGi33qf4DzDkdC8vNyER1mdtNFnOfqzM vqNZR6Ts/8nUyPtWijEYYhgkbvdPA7nZCoZTg7vzLgXT5k4j65qurbzwYzbypEvCj2Qe +G15bl9mxjAUZHUNtoL2DDRwT6blpUjx7PWRhhVRt4eyM4lr87uUWv7xEXb78XXP0ws5 omYjbtlZ7/4/FPE6RBGowT8OLfqW4BOT5VxrKuqwBUt6Ik5iTBVx7lNcqmu3/gMcVgCo ETHut0YE0qrmOIL85c57yVlOt0pW81IpVN5qceT/Q7nDVhzeky1yJNE4LBQTlRu/Nbj+ MvZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GkSuUeaNhG0iM2/NS7Qk3u9nsu4R5lVDbA2SMVNwMYY=; b=aBqzbENyfFFLEEX4XQALMtnHrR+EvBw+esmwwVMc3O2jedhoGdRql+OD2QN4Zicd0Q Yr4Q026QoTbjE48Ebmuj8D/9HGOE9U83VPRLf9asuXjKRXFlFFFZqVs9gnupJtAk47Vg nfTEvAFuLQQ68sygRp/jMwxEjRZHCRW3tTIOcKb3bt5L9XoleazYvEGkB70ASTgB5sqs WyRsrn4U8yG0HeStBc9q265pDcMI5napQ5i/z0P25nnrb2BeSV/xDdJPiwJ3jPwdXunp yi7P8zp0NcrLsZnTJWL015YOIgoc/YPAlxTox9c33YkCOqLBVlrC5dFVNn1AMNOappec 4zFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B1ksWRZI; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b2si3127551edt.413.2020.07.16.05.34.40; Thu, 16 Jul 2020 05:34:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B1ksWRZI; spf=pass (google.com: domain of linux-usb-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728422AbgGPMej (ORCPT + 4 others); Thu, 16 Jul 2020 08:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727844AbgGPMej (ORCPT ); Thu, 16 Jul 2020 08:34:39 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E81A2C061755 for ; Thu, 16 Jul 2020 05:34:38 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id q7so6990028ljm.1 for ; Thu, 16 Jul 2020 05:34:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GkSuUeaNhG0iM2/NS7Qk3u9nsu4R5lVDbA2SMVNwMYY=; b=B1ksWRZI3R2Sb7yQ2JX9PNPdepw2ZI7jrQvhZB12VEBzbQq1GYzSi0yAQNwr4TNzwh cLQpxq6Ib9jzPfE96kZy8H0spEwq5KL2g5N62vVnnjzOHCr8IRWM6Vkl64gBGe0YXBce KrqGqVRr1B+ATZnezAfhT9msaewlcublWikJ6w5+mT/VwE2xuQln1DT/JhCZKWhsK/w9 hfSo2DDyx95e5T0vzMwnleLuBbAt9Ugvisc2Z5/1nvSQaiqyvZ4bLNnjOeVOJbla+dgn Fnjb7AI7t7FZG77O2DxtIJJSDwOsLarjQR8Db7BPz+kqVA7vsiayu13IMYWvHpt76KZG kodA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GkSuUeaNhG0iM2/NS7Qk3u9nsu4R5lVDbA2SMVNwMYY=; b=qHedl1z17t96IXkuR74XfRNiNn3AcJ7xellV8wwHj2S/d7G6yVqjtpc5xUO6BriqNU K38BC1Fx9yjhMOWHpypijGxUA7J3ulULnqZ5pDjPsBtT4+l9Vn7uuaW/MnEoFR0nVEFZ b2xQQ/T0S81tEkWkHy5cDE0Np7iWxg7iBCjMHlFN2MXL33fGWVkPlXe8iQj2JsGtGHRx Jmz0IUqi3k8zfo7eREdSlI9BHXr+KOC4lhzp43x7Dz2bu4iBk8A5VzsV8FwKXTeBdmdk RONrvIXpeggkaJeLSy2Q6PFqJejdr8mmy+CwPZc72YxU/yX7JBFvIr6Ln0DQTcMaiAy+ PVgw== X-Gm-Message-State: AOAM530OADd4jPdTimY6iSHSvNUP+HX4V+ZT/7LDDhj/WCf9Y3oagtDV lx4JcpTh/qZ0Ggv3Rab8qWxwVvgdUCU= X-Received: by 2002:a2e:80cc:: with SMTP id r12mr2112153ljg.344.1594902877250; Thu, 16 Jul 2020 05:34:37 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id p4sm320682lfk.0.2020.07.16.05.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2020 05:34:36 -0700 (PDT) From: Linus Walleij To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Linus Walleij , Janusz Krzysztofik , Tony Lindgren , Alan Stern Subject: [PATCH 2/2 v2] usb: ohci-omap: Convert to use GPIO descriptors Date: Thu, 16 Jul 2020 14:34:33 +0200 Message-Id: <20200716123433.155854-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200716123433.155854-1-linus.walleij@linaro.org> References: <20200716123433.155854-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The OMAP1 OHCI driver is using the legacy GPIO API to grab some random GPIO lines. One is from the TPS65010 chip and used for power, another one is for overcurrent and while the driver picks this line it doesn't watch it at all. Convert the driver and the OMAP1 OSK board file to pass these two GPIOs as machine descrived GPIO descriptors. Cc: Janusz Krzysztofik Cc: Tony Lindgren Cc: Alan Stern Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebase on the changes to patch 1 - Fix up the errorpath in the same vein as in patch 1 --- arch/arm/mach-omap1/board-osk.c | 17 +++++++++++ drivers/usb/host/ohci-omap.c | 53 ++++++++++++++++----------------- 2 files changed, 43 insertions(+), 27 deletions(-) -- 2.26.2 diff --git a/arch/arm/mach-omap1/board-osk.c b/arch/arm/mach-omap1/board-osk.c index 4df15e693b6e..d5d139bbac34 100644 --- a/arch/arm/mach-omap1/board-osk.c +++ b/arch/arm/mach-omap1/board-osk.c @@ -26,6 +26,7 @@ * 675 Mass Ave, Cambridge, MA 02139, USA. */ #include +#include #include #include #include @@ -55,6 +56,9 @@ #include "common.h" +/* Name of the GPIO chip used by the OMAP for GPIOs 0..15 */ +#define OMAP_GPIO_LABEL "gpio-0-15" + /* At OMAP5912 OSK the Ethernet is directly connected to CS1 */ #define OMAP_OSK_ETHR_START 0x04800300 @@ -240,7 +244,9 @@ static struct tps65010_board tps_board = { static struct i2c_board_info __initdata osk_i2c_board_info[] = { { + /* This device will get the name "i2c-tps65010" */ I2C_BOARD_INFO("tps65010", 0x48), + .dev_name = "tps65010", .platform_data = &tps_board, }, @@ -278,6 +284,16 @@ static void __init osk_init_cf(void) irq_set_irq_type(gpio_to_irq(62), IRQ_TYPE_EDGE_FALLING); } +static struct gpiod_lookup_table osk_usb_gpio_table = { + .dev_id = "ohci", + .table = { + /* Power GPIO on the I2C-attached TPS65010 */ + GPIO_LOOKUP("i2c-tps65010", 1, "power", GPIO_ACTIVE_HIGH), + GPIO_LOOKUP(OMAP_GPIO_LABEL, 9, "overcurrent", + GPIO_ACTIVE_HIGH), + }, +}; + static struct omap_usb_config osk_usb_config __initdata = { /* has usb host connector (A) ... for development it can also * be used, with a NONSTANDARD gender-bending cable/dongle, as @@ -581,6 +597,7 @@ static void __init osk_init(void) l |= (3 << 1); omap_writel(l, USB_TRANSCEIVER_CTRL); + gpiod_add_lookup_table(&osk_usb_gpio_table); omap1_usb_init(&osk_usb_config); /* irq for tps65010 chip */ diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c index a4bdd2b7af83..5d5ecca3739e 100644 --- a/drivers/usb/host/ohci-omap.c +++ b/drivers/usb/host/ohci-omap.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -53,25 +53,11 @@ #define DRIVER_DESC "OHCI OMAP driver" -#ifdef CONFIG_TPS65010 -#include -#else - -#define LOW 0 -#define HIGH 1 - -#define GPIO1 1 - -static inline int tps65010_set_gpio_out_value(unsigned gpio, unsigned value) -{ - return 0; -} - -#endif - struct ohci_omap_priv { struct clk *usb_host_ck; struct clk *usb_dc_ck; + struct gpio_desc *power; + struct gpio_desc *overcurrent; }; static const char hcd_name[] = "ohci-omap"; @@ -97,22 +83,22 @@ static void omap_ohci_clock_power(struct ohci_omap_priv *priv, int on) * Board specific gang-switched transceiver power on/off. * NOTE: OSK supplies power from DC, not battery. */ -static int omap_ohci_transceiver_power(int on) +static int omap_ohci_transceiver_power(struct ohci_omap_priv *priv, int on) { if (on) { if (machine_is_omap_innovator() && cpu_is_omap1510()) __raw_writeb(__raw_readb(INNOVATOR_FPGA_CAM_USB_CONTROL) | ((1 << 5/*usb1*/) | (1 << 3/*usb2*/)), INNOVATOR_FPGA_CAM_USB_CONTROL); - else if (machine_is_omap_osk()) - tps65010_set_gpio_out_value(GPIO1, LOW); + else if (priv->power) + gpiod_set_value(priv->power, 0); } else { if (machine_is_omap_innovator() && cpu_is_omap1510()) __raw_writeb(__raw_readb(INNOVATOR_FPGA_CAM_USB_CONTROL) & ~((1 << 5/*usb1*/) | (1 << 3/*usb2*/)), INNOVATOR_FPGA_CAM_USB_CONTROL); - else if (machine_is_omap_osk()) - tps65010_set_gpio_out_value(GPIO1, HIGH); + else if (priv->power) + gpiod_set_value(priv->power, 1); } return 0; @@ -272,8 +258,6 @@ static int ohci_omap_reset(struct usb_hcd *hcd) /* gpio9 for overcurrent detction */ omap_cfg_reg(W8_1610_GPIO9); - gpio_request(9, "OHCI overcurrent"); - gpio_direction_input(9); /* for paranoia's sake: disable USB.PUEN */ omap_cfg_reg(W4_USB_HIGHZ); @@ -287,7 +271,7 @@ static int ohci_omap_reset(struct usb_hcd *hcd) } /* FIXME hub_wq hub requests should manage power switching */ - omap_ohci_transceiver_power(1); + omap_ohci_transceiver_power(priv, 1); /* board init will have already handled HMC and mux setup. * any external transceiver should already be initialized @@ -334,6 +318,23 @@ static int ohci_hcd_omap_probe(struct platform_device *pdev) hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; priv = hcd_to_ohci_omap_priv(hcd); + /* Obtain two optional GPIO lines */ + priv->power = devm_gpiod_get_optional(&pdev->dev, "power", GPIOD_ASIS); + if (IS_ERR(priv->power)) { + retval = PTR_ERR(priv->power); + goto err_put_hcd; + } + if (priv->power) + gpiod_set_consumer_name(priv->power, "OHCI power"); + priv->overcurrent = devm_gpiod_get_optional(&pdev->dev, "overcurrent", + GPIOD_IN); + if (IS_ERR(priv->overcurrent)) { + retval = PTR_ERR(priv->overcurrent); + goto err_put_hcd; + } + if (priv->overcurrent) + gpiod_set_consumer_name(priv->overcurrent, "OHCI overcurrent"); + priv->usb_host_ck = clk_get(&pdev->dev, "usb_hhc_ck"); if (IS_ERR(priv->usb_host_ck)) { retval = PTR_ERR(priv->usb_host_ck); @@ -411,8 +412,6 @@ static int ohci_hcd_omap_remove(struct platform_device *pdev) (void) otg_set_host(hcd->usb_phy->otg, 0); usb_put_phy(hcd->usb_phy); } - if (machine_is_omap_osk()) - gpio_free(9); iounmap(hcd->regs); release_mem_region(hcd->rsrc_start, hcd->rsrc_len); clk_put(priv->usb_dc_ck);