From patchwork Fri Jul 3 17:57:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 231623 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2605464ilg; Fri, 3 Jul 2020 10:59:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLvo34E+Q/TpyMtlrDrJEcAe/+OBZgmm/4lXBbt48NQZ+BRV0MQwoR5qHtmHrSYEurqUxc X-Received: by 2002:a17:906:2616:: with SMTP id h22mr32794153ejc.154.1593799149049; Fri, 03 Jul 2020 10:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593799149; cv=none; d=google.com; s=arc-20160816; b=Ot9n2r8fX63F/ue2SfjVSOSQvDrpHbbsk4T5emYQSvIMrCcZLv0RF/Al2Mf6HFJcsB t1QnaJOKcekfOeJ0rQIZHLsTnmenWqY654aVXaXdN5j8DIp6ePRht0VmmhXXEf2CPdbH 3iEUdHAdqQ2PAgd2QdCqfKPKWVvKxVq1stJEHCCdNEBgJb2Ij/KDJfE0rY9TNlMEq2wH 9u55HLew7lsrnDWw0GdpN/vqYva3nI/qYKIuE9VWMd2iEp7llbsbFQl0BF1oPaDsbUGB +U7RXylU/QZq/4O9Kyb0xWmJqD8cKrHRS/eN7ZeMBOGB0X/IsJD+PW+czMPPbBLaBWWV K5Rg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=p2WGN4yG0nEg0drnh+gOK4tXZi/zTWHJWqdGq3LW4Qo=; b=qSRilCo1R4tiI5tmhCd2lTW9ERROhlksm6ALfkShWGa/Z7M69PzKLOMrJBC1SDf+rG Lt9t2qoh3BiLLkT2HMYYQ1FW1e4nMiwgApF5D4WESuysgdLtZFyfkjJ5U4AntFGVeoz2 JcHV5zD+nt/51EGuIteRiR95d95w5XEt7rN6jGOc4btwa0QO48uN/JhzlsEL12niKzCd ysq9PlBqLMWO3sSD33H6RsnDMb/t72zQBItmHg7kJzvMUREtuuleAHYrkgBw+UphboOG k8/a5cgBIM+NEFbkVqW1e9z5IdMBy6dOssHU7o06KOWe2T8AfAfZhqiJv9E5Dds2fu/t xzdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jfk8OEAQ; 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 a26si6089106ejf.701.2020.07.03.10.59.08; Fri, 03 Jul 2020 10:59:09 -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=Jfk8OEAQ; 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 S1726258AbgGCR7H (ORCPT + 5 others); Fri, 3 Jul 2020 13:59:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726035AbgGCR7H (ORCPT ); Fri, 3 Jul 2020 13:59:07 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D4ABC061794 for ; Fri, 3 Jul 2020 10:59:07 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id c11so18947365lfh.8 for ; Fri, 03 Jul 2020 10:59:06 -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:mime-version :content-transfer-encoding; bh=p2WGN4yG0nEg0drnh+gOK4tXZi/zTWHJWqdGq3LW4Qo=; b=Jfk8OEAQzg60BJZWAPltXeKfZmdnixQUQNl3GQUItOCFFIZaa3vd90bm9NRQbejHwI j9R4XrLls+Pd4kjXCPbIUwXYL83fKwE5ov2ws8PvJY9QJBhF6c5GeAI6Vr2NGRGw3v+M P2zpimesxW62zaru7MBGgjLqcOH9qbGQEM1NmJo+/a2g3gAACKFmqWwA1xbvBxNBPuFq lSK+dJquvX0tWt2RumJahlMql7mgs3Cl1H7A2wPb0/yZDUnL1LYJZ/dyoNKBnIHxrAh6 tidBwnl1Fc6riaTDD8Y7dkxIxzs1hIiVwsNWd2nQe0dYZ+TGMQXfPnBIT6EJ8T/bDdw+ xbgQ== 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:mime-version :content-transfer-encoding; bh=p2WGN4yG0nEg0drnh+gOK4tXZi/zTWHJWqdGq3LW4Qo=; b=HWXrkNxYIUOnb9pcgLf0ctZmp1VBTjIkHV5rLFAdYP3CSnXFYmswyPHtwtei0QW/2X 2ppDJMwJ/0ZBkxq+4ofgry4eJh0pWPxngaiB9N2JXXLcD8WxBc1UAWcHcK6oitBzA/S0 C9PxYzmjSULjxAIjdumEBoBJ0nl/Me4J7CjFbCJSjqShNve5VYv1zXWcuZozTN0EZiX3 yJIj+95TPMinltMbR5+sfo6VtkHt1AOrUljkYo9reghHk/VY3J/9wntd+lvq0LvTYKay 68nDnjgqoT/Q7b2ulAZ3LeFhIsynnbvRXHV3Z/8NGGHL9Iblz6e4bPjSb1fUEcxyd+iQ hLjA== X-Gm-Message-State: AOAM5301mXe8LlL8ckENLLlu3/esc9j0O5ce9QBjPCcX6u0RmGtpdrt0 lp3c+y8X4x0OXmiBnbphSipGrg== X-Received: by 2002:ac2:5217:: with SMTP id a23mr22789469lfl.115.1593799145385; Fri, 03 Jul 2020 10:59:05 -0700 (PDT) Received: from localhost.localdomain (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id a23sm4900795lfb.10.2020.07.03.10.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 10:59:04 -0700 (PDT) From: Linus Walleij To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Linus Walleij , Janusz Krzysztofik , Tony Lindgren Subject: [PATCH 1/2] usb: ohci-omap: Create private state container Date: Fri, 3 Jul 2020 19:57:00 +0200 Message-Id: <20200703175701.570446-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.25.4 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 was using static locals to hold the clock handles which is uncommon and does not scale. Create a private data struct and use that to hold the clocks. Cc: Janusz Krzysztofik Cc: Tony Lindgren Signed-off-by: Linus Walleij --- drivers/usb/host/ohci-omap.c | 73 +++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 31 deletions(-) -- 2.25.4 diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c index d8d35d456456..add2eac53a98 100644 --- a/drivers/usb/host/ohci-omap.c +++ b/drivers/usb/host/ohci-omap.c @@ -69,22 +69,27 @@ static inline int tps65010_set_gpio_out_value(unsigned gpio, unsigned value) #endif -static struct clk *usb_host_ck; -static struct clk *usb_dc_ck; +struct ohci_omap_priv { + struct clk *usb_host_ck; + struct clk *usb_dc_ck; +}; static const char hcd_name[] = "ohci-omap"; static struct hc_driver __read_mostly ohci_omap_hc_driver; -static void omap_ohci_clock_power(int on) +#define hcd_to_ohci_omap_priv(h) \ + ((struct ohci_omap_priv *)hcd_to_ohci(h)->priv) + +static void omap_ohci_clock_power(struct ohci_omap_priv *priv, int on) { if (on) { - clk_enable(usb_dc_ck); - clk_enable(usb_host_ck); + clk_enable(priv->usb_dc_ck); + clk_enable(priv->usb_host_ck); /* guesstimate for T5 == 1x 32K clock + APLL lock time */ udelay(100); } else { - clk_disable(usb_host_ck); - clk_disable(usb_dc_ck); + clk_disable(priv->usb_host_ck); + clk_disable(priv->usb_dc_ck); } } @@ -196,6 +201,7 @@ static int ohci_omap_reset(struct usb_hcd *hcd) { struct ohci_hcd *ohci = hcd_to_ohci(hcd); struct omap_usb_config *config = dev_get_platdata(hcd->self.controller); + struct ohci_omap_priv *priv = hcd_to_ohci_omap_priv(hcd); int need_transceiver = (config->otg != 0); int ret; @@ -235,7 +241,7 @@ static int ohci_omap_reset(struct usb_hcd *hcd) } #endif - omap_ohci_clock_power(1); + omap_ohci_clock_power(priv, 1); if (cpu_is_omap15xx()) { omap_1510_local_bus_power(1); @@ -305,6 +311,7 @@ static int ohci_hcd_omap_probe(struct platform_device *pdev) { int retval, irq; struct usb_hcd *hcd = 0; + struct ohci_omap_priv *priv; if (pdev->num_resources != 2) { dev_err(&pdev->dev, "invalid num_resources: %i\n", @@ -318,21 +325,6 @@ static int ohci_hcd_omap_probe(struct platform_device *pdev) return -ENODEV; } - usb_host_ck = clk_get(&pdev->dev, "usb_hhc_ck"); - if (IS_ERR(usb_host_ck)) - return PTR_ERR(usb_host_ck); - - if (!cpu_is_omap15xx()) - usb_dc_ck = clk_get(&pdev->dev, "usb_dc_ck"); - else - usb_dc_ck = clk_get(&pdev->dev, "lb_ck"); - - if (IS_ERR(usb_dc_ck)) { - clk_put(usb_host_ck); - return PTR_ERR(usb_dc_ck); - } - - hcd = usb_create_hcd(&ohci_omap_hc_driver, &pdev->dev, dev_name(&pdev->dev)); if (!hcd) { @@ -341,6 +333,21 @@ static int ohci_hcd_omap_probe(struct platform_device *pdev) } hcd->rsrc_start = pdev->resource[0].start; hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; + priv = hcd_to_ohci_omap_priv(hcd); + + priv->usb_host_ck = clk_get(&pdev->dev, "usb_hhc_ck"); + if (IS_ERR(priv->usb_host_ck)) + return PTR_ERR(priv->usb_host_ck); + + if (!cpu_is_omap15xx()) + priv->usb_dc_ck = clk_get(&pdev->dev, "usb_dc_ck"); + else + priv->usb_dc_ck = clk_get(&pdev->dev, "lb_ck"); + + if (IS_ERR(priv->usb_dc_ck)) { + clk_put(priv->usb_host_ck); + return PTR_ERR(priv->usb_dc_ck); + } if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { dev_dbg(&pdev->dev, "request_mem_region failed\n"); @@ -373,8 +380,8 @@ static int ohci_hcd_omap_probe(struct platform_device *pdev) err1: usb_put_hcd(hcd); err0: - clk_put(usb_dc_ck); - clk_put(usb_host_ck); + clk_put(priv->usb_dc_ck); + clk_put(priv->usb_host_ck); return retval; } @@ -393,10 +400,11 @@ static int ohci_hcd_omap_probe(struct platform_device *pdev) static int ohci_hcd_omap_remove(struct platform_device *pdev) { struct usb_hcd *hcd = platform_get_drvdata(pdev); + struct ohci_omap_priv *priv = hcd_to_ohci_omap_priv(hcd); dev_dbg(hcd->self.controller, "stopping USB Controller\n"); usb_remove_hcd(hcd); - omap_ohci_clock_power(0); + omap_ohci_clock_power(priv, 0); if (!IS_ERR_OR_NULL(hcd->usb_phy)) { (void) otg_set_host(hcd->usb_phy->otg, 0); usb_put_phy(hcd->usb_phy); @@ -406,8 +414,8 @@ static int ohci_hcd_omap_remove(struct platform_device *pdev) iounmap(hcd->regs); release_mem_region(hcd->rsrc_start, hcd->rsrc_len); usb_put_hcd(hcd); - clk_put(usb_dc_ck); - clk_put(usb_host_ck); + clk_put(priv->usb_dc_ck); + clk_put(priv->usb_host_ck); return 0; } @@ -419,6 +427,7 @@ static int ohci_omap_suspend(struct platform_device *pdev, pm_message_t message) { struct usb_hcd *hcd = platform_get_drvdata(pdev); struct ohci_hcd *ohci = hcd_to_ohci(hcd); + struct ohci_omap_priv *priv = hcd_to_ohci_omap_priv(hcd); bool do_wakeup = device_may_wakeup(&pdev->dev); int ret; @@ -430,7 +439,7 @@ static int ohci_omap_suspend(struct platform_device *pdev, pm_message_t message) if (ret) return ret; - omap_ohci_clock_power(0); + omap_ohci_clock_power(priv, 0); return ret; } @@ -438,12 +447,13 @@ static int ohci_omap_resume(struct platform_device *dev) { struct usb_hcd *hcd = platform_get_drvdata(dev); struct ohci_hcd *ohci = hcd_to_ohci(hcd); + struct ohci_omap_priv *priv = hcd_to_ohci_omap_priv(hcd); if (time_before(jiffies, ohci->next_statechange)) msleep(5); ohci->next_statechange = jiffies; - omap_ohci_clock_power(1); + omap_ohci_clock_power(priv, 1); ohci_resume(hcd, false); return 0; } @@ -470,7 +480,8 @@ static struct platform_driver ohci_hcd_omap_driver = { static const struct ohci_driver_overrides omap_overrides __initconst = { .product_desc = "OMAP OHCI", - .reset = ohci_omap_reset + .reset = ohci_omap_reset, + .extra_priv_size = sizeof(struct ohci_omap_priv), }; static int __init ohci_omap_init(void) From patchwork Fri Jul 3 17:57:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 231625 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp2606615ilg; Fri, 3 Jul 2020 11:00:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxoQS7L2go+LNFjcUssWM7kfW592GNyxjD72GpvMYAr6jRkbWJAfysI/5HaSmg82MRLOMI X-Received: by 2002:a17:906:1a16:: with SMTP id i22mr14617708ejf.439.1593799238417; Fri, 03 Jul 2020 11:00:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593799238; cv=none; d=google.com; s=arc-20160816; b=0GWGqKN6ECR+aO799ec6I89sMoXJL5qiQQYsrJ78eSa1v+bV7O1cVE2wdXZic5cYOp Ax4oOoTI3GNRrnuGOiNucYUgXRIWeyvMQAHdd3xWGgDkud2hjpSCacPUGTLSCM9ddsic eqxjeOe1WWUJPeUclIjv6SSjcM+gQ6eu9TgNm0Na1fwdxrZtqdxwcY9LdCNsOV9ODD8c vdFat8F6xMWXaSfYZhycC4eqYeov8CBpkU2nHQu5XBYuVnQAQ4bIwQAwsyyGBPCOA+sL kCr98eEJz9vf1PgwP6MtZmkoWvr/ZeZ+qaMoMlcW5uUt8DxiZoJ8dVbaWM4UrIAUdw9x Kong== 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=tbO2ldHuRsGqvWzI09Mc6Y2vW9AGGHy5SX8r+bpR3WA=; b=y/S+CxFnn1C4H27PJIrqUEBWC6zT0evGk3dFYxebcNHFfTUWftksz+DbeaEcazJ2Il f42qQG9MyeIUfKUyfixUrIv4jgWjCREGB/NrBOWLrBlzDVmW90YWK/7qZlduwGWAtv2U V/mF+kgQyMXwzkP2vozjwgQ/+fVPmSHcYfbsuvXs5+1sEvxTg0lZ7BV/3IGJ0EYKxjNf /8L9BmMrDRCyviiDUPo2XMzdvP/sn7D3yyKXEXCPdWA2xlo3phU9wLFTGCPg0ZY4037D fHPvCsRZwjBUxAW+Uz0hMPqwsyIoxUtS6BQ9EDx5pPZ5viIGJOB8THhWW2E6SKFGH2EI 5AHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JuDoBwv1; 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 a8si8045987eds.491.2020.07.03.11.00.38; Fri, 03 Jul 2020 11:00:38 -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=JuDoBwv1; 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 S1726258AbgGCSAg (ORCPT + 5 others); Fri, 3 Jul 2020 14:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726035AbgGCSAg (ORCPT ); Fri, 3 Jul 2020 14:00:36 -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 398E9C061794 for ; Fri, 3 Jul 2020 11:00:36 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id q4so2226767lji.2 for ; Fri, 03 Jul 2020 11:00:36 -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=tbO2ldHuRsGqvWzI09Mc6Y2vW9AGGHy5SX8r+bpR3WA=; b=JuDoBwv1Khb5PQqJJkg88XXI2Vc+ZY2IveG053Y4UA7mztNJ291KBIRmYvI5Jn47Xd ioFDDO34TwNmqok/yetGaeecKhzni5Y+UUy8mlzAff6YL3aAenp3QIpkRvgA1phDV19H kUZbLCjdlU7A7MEyT4WrE4C4vi2CVkU97cxITlAeyyzRlUls18620TP2d1ZlQFdaHDsk meta87qqZdIwMLJnkgDm2GTAFLKBdStXE2fJhyXrfSzQ/15FtIfb0wD0OuNv5Lul0jJ0 89A/VB86cuHkEQnpALg4DyHOQxmE1TzgionZeqaeL5/z+VOW7tIvpV5vqArMhNTY+PB9 RgoQ== 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=tbO2ldHuRsGqvWzI09Mc6Y2vW9AGGHy5SX8r+bpR3WA=; b=PDW+mKyEzSfbNs7n1ucg7oARVrWyUI8aPt3jmbgwcmYhZjVcgFO73NwpuI55ghxhsI 1QaqADnEuP/qcpLttUSNbPKh4eXbz6qlZfQ7krU/6kfPBoOextsnSuDLvTeL8xKHbGQv z7RDdeuT5Ra5MvfTA29Arpzya0SNTnTdIsu33alXSlxfbM84qDuT9BjwC6JahuKxx6Fh 3cTdeiQdTLQ5GyQdtGq35MKHcxVl912kek/AmWI61kVOlmsErzCsMMTM4nf11tsfsKAa wnoZd6k8qSapexMwJYSCpTTKHdU2MpoxGkhKhEAUKOHWIzVk11pK7loxfkQjMDLNclv1 qH5A== X-Gm-Message-State: AOAM531pnrbKn/vM/qPj+ldwC9ys7f4Pj5pW24w2jIwRmKO8eyt/92Bb bpERjdoTS1lRktFW86ThAIpmhesNiK9cTw== X-Received: by 2002:a2e:3a15:: with SMTP id h21mr8580285lja.112.1593799234547; Fri, 03 Jul 2020 11:00:34 -0700 (PDT) Received: from localhost.localdomain (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id a23sm4900795lfb.10.2020.07.03.11.00.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2020 11:00:34 -0700 (PDT) From: Linus Walleij To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Linus Walleij , Janusz Krzysztofik , Tony Lindgren Subject: [PATCH 2/2] usb: ohci-omap: Convert to use GPIO descriptors Date: Fri, 3 Jul 2020 19:57:01 +0200 Message-Id: <20200703175701.570446-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200703175701.570446-1-linus.walleij@linaro.org> References: <20200703175701.570446-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 Signed-off-by: Linus Walleij --- arch/arm/mach-omap1/board-osk.c | 17 ++++++++ drivers/usb/host/ohci-omap.c | 75 ++++++++++++++++----------------- 2 files changed, 53 insertions(+), 39 deletions(-) -- 2.25.4 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 add2eac53a98..df44cc425036 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 @@ -327,17 +311,32 @@ static int ohci_hcd_omap_probe(struct platform_device *pdev) hcd = usb_create_hcd(&ohci_omap_hc_driver, &pdev->dev, dev_name(&pdev->dev)); - if (!hcd) { - retval = -ENOMEM; - goto err0; - } + if (!hcd) + return -ENOMEM; + hcd->rsrc_start = pdev->resource[0].start; 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)) + return PTR_ERR(priv->power); + 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)) + return PTR_ERR(priv->overcurrent); + 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)) - return PTR_ERR(priv->usb_host_ck); + if (IS_ERR(priv->usb_host_ck)) { + retval = PTR_ERR(priv->usb_host_ck); + goto err0; + } if (!cpu_is_omap15xx()) priv->usb_dc_ck = clk_get(&pdev->dev, "usb_dc_ck"); @@ -345,8 +344,8 @@ static int ohci_hcd_omap_probe(struct platform_device *pdev) priv->usb_dc_ck = clk_get(&pdev->dev, "lb_ck"); if (IS_ERR(priv->usb_dc_ck)) { - clk_put(priv->usb_host_ck); - return PTR_ERR(priv->usb_dc_ck); + retval = PTR_ERR(priv->usb_dc_ck); + goto err1; } if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { @@ -377,11 +376,11 @@ static int ohci_hcd_omap_probe(struct platform_device *pdev) iounmap(hcd->regs); err2: release_mem_region(hcd->rsrc_start, hcd->rsrc_len); -err1: - usb_put_hcd(hcd); -err0: clk_put(priv->usb_dc_ck); +err1: clk_put(priv->usb_host_ck); +err0: + usb_put_hcd(hcd); return retval; } @@ -409,13 +408,11 @@ 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); - usb_put_hcd(hcd); clk_put(priv->usb_dc_ck); clk_put(priv->usb_host_ck); + usb_put_hcd(hcd); return 0; }