From patchwork Mon Oct 24 16:46:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Haslam X-Patchwork-Id: 9392669 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AA61C6077A for ; Mon, 24 Oct 2016 16:55:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97476291AA for ; Mon, 24 Oct 2016 16:55:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B846291B3; Mon, 24 Oct 2016 16:55:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E9BA5291AA for ; Mon, 24 Oct 2016 16:55:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1byiVa-0000Fs-9V; Mon, 24 Oct 2016 16:53:58 +0000 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1byiP1-000280-OQ for linux-arm-kernel@lists.infradead.org; Mon, 24 Oct 2016 16:47:19 +0000 Received: by mail-wm0-x233.google.com with SMTP id f193so132318804wmg.0 for ; Mon, 24 Oct 2016 09:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IIZ/0G56Od6emyGOe+aQnGgRonhc/GERBORkwfrmYGQ=; b=RBXUIPdZhOkPdBi9sxNkHdPNh8fKiuQkrNzso3wCbAsEi0GO61rPvlyzHgpVnuKjHw nY59cFZywlRblGdAqOe6JVpsyovf6CZBdXJAS8DAJnO0G9gaj/Sn1VRiVxVlJWXOmd0v thUhbybNEUSZ5Oha47/FFPqZBsvG6+QN3mo2kpKyQDKbBYCB2Nw4bsnmlxiU06UvX+31 bmOCH5D3YxeJpYCCDvKo3XcmAj1OlFlavKyAtx07IBET80mFLqqGCRAvp3j6iHreVjo2 dSkCCGN+YvrzcvzcfGFpghJl+xnVdKXFnsKZIph4/De3XbJMFERv6wFEMBUi5wPYus7C gipw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IIZ/0G56Od6emyGOe+aQnGgRonhc/GERBORkwfrmYGQ=; b=ljVWEtf1FpwNLFQlk3YLj8GCYFtkJTlP+ljfFVj8uiXR72CZK2KBSgemWSOfUpY+qa weEd1mabSizODXwAaFzkle6h9doQYGkUHIz90izI9ESKKJvjCaRrCfiyLVXZcQuhc3v4 PGuqUNATQ4Qm+VwqKZkSa8erCA9oxaJrLGwUQ8fCk7iLLBomYcNjun8lCNTZfo2EbuPG pJeiL2MDbPgQnGe4qPSbPSuv0RrqAE0jNGjEfo3AvUMZg+CnybHCWTD0ZXg70Q6FjjoP fytFOuUJOEc+KFIlMzi5l68R32D/CIR7gO52FdndpqRzLKmi2HosaMasoupHyUsZS6wr yvcQ== X-Gm-Message-State: AA6/9Rmy6udXxu7ELENbJlq42bghOBcbLBqde0doxO5wYq/lpJSklaVsvYzz1oT1c81v9poV X-Received: by 10.28.150.20 with SMTP id y20mr22512388wmd.67.1477327614538; Mon, 24 Oct 2016 09:46:54 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id o62sm15710148wmg.9.2016.10.24.09.46.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Oct 2016 09:46:53 -0700 (PDT) From: ahaslam@baylibre.com To: gregkh@linuxfoundation.org, johan@kernel.org, robh+dt@kernel.org, nsekhar@ti.com, stern@rowland.harvard.edu, khilman@baylibre.com, sshtylyov@ru.mvista.com, david@lechnology.com, manjunath.goudar@linaro.org, broonie@kernel.org, abailon@baylibre.com Subject: [PATCH/RFT v2 13/17] USB: da8xx: use ohci priv data instead of globals Date: Mon, 24 Oct 2016 18:46:30 +0200 Message-Id: <20161024164634.4330-14-ahaslam@baylibre.com> X-Mailer: git-send-email 2.10.1.502.g6598894 In-Reply-To: <20161024164634.4330-1-ahaslam@baylibre.com> References: <20161024164634.4330-1-ahaslam@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161024_094712_363215_98ED5FE7 X-CRM114-Status: GOOD ( 18.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Axel Haslam , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Axel Haslam Instead of global variables, use the extra_priv_size of the ohci driver to add a reference to driver private data. Signed-off-by: Axel Haslam --- drivers/usb/host/ohci-da8xx.c | 135 ++++++++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 56 deletions(-) diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c index f4bda4d..bebc3f0 100644 --- a/drivers/usb/host/ohci-da8xx.c +++ b/drivers/usb/host/ohci-da8xx.c @@ -37,60 +37,66 @@ static int (*orig_ohci_hub_control)(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength); static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf); -static struct clk *usb11_clk; -static struct phy *usb11_phy; -static struct regulator *vbus_reg; -struct notifier_block nb; - -/* Over-current indicator change flag */ -static int ocic_flag; +struct da8xx_ohci_hcd { + struct usb_hcd *hcd; + struct clk *usb11_clk; + struct phy *usb11_phy; + struct regulator *vbus_reg; + struct notifier_block nb; + int ocic_flag; +}; +#define to_da8xx_ohci(hcd) (struct da8xx_ohci_hcd *)(hcd_to_ohci(hcd)->priv) -static int ohci_da8xx_enable(void) +static int ohci_da8xx_enable(struct usb_hcd *hcd) { + struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd); int ret; - ret = clk_prepare_enable(usb11_clk); + ret = clk_prepare_enable(da8xx_ohci->usb11_clk); if (ret) return ret; - ret = phy_init(usb11_phy); + ret = phy_init(da8xx_ohci->usb11_phy); if (ret) goto err_phy_init; - ret = phy_power_on(usb11_phy); + ret = phy_power_on(da8xx_ohci->usb11_phy); if (ret) goto err_phy_power_on; return 0; err_phy_power_on: - phy_exit(usb11_phy); + phy_exit(da8xx_ohci->usb11_phy); err_phy_init: - clk_disable_unprepare(usb11_clk); + clk_disable_unprepare(da8xx_ohci->usb11_clk); return ret; } -static void ohci_da8xx_disable(void) +static void ohci_da8xx_disable(struct usb_hcd *hcd) { - phy_power_off(usb11_phy); - phy_exit(usb11_phy); - clk_disable_unprepare(usb11_clk); + struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd); + + phy_power_off(da8xx_ohci->usb11_phy); + phy_exit(da8xx_ohci->usb11_phy); + clk_disable_unprepare(da8xx_ohci->usb11_clk); } -static int ohci_da8xx_set_power(int on) +static int ohci_da8xx_set_power(struct usb_hcd *hcd, int on) { + struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd); int ret = 0; - if (!vbus_reg) + if (!da8xx_ohci->vbus_reg) return 0; if (on) { - ret = regulator_enable(vbus_reg); + ret = regulator_enable(da8xx_ohci->vbus_reg); if (ret) pr_err("fail to enable regulator: %d\n", ret); } else { - ret = regulator_disable(vbus_reg); + ret = regulator_disable(da8xx_ohci->vbus_reg); if (ret) pr_err("fail to disable regulator: %d\n", ret); } @@ -98,17 +104,22 @@ static int ohci_da8xx_set_power(int on) return ret; } -static int ohci_da8xx_get_power(void) +static int ohci_da8xx_get_power(struct usb_hcd *hcd) { - if (!vbus_reg) + struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd); + + if (!da8xx_ohci->vbus_reg) return 1; - return regulator_is_enabled(vbus_reg); + return regulator_is_enabled(da8xx_ohci->vbus_reg); } -static int ohci_da8xx_get_oci(void) +static int ohci_da8xx_get_oci(struct usb_hcd *hcd) { - if (regulator_get_mode(vbus_reg) == REGULATOR_MODE_OVERCURRENT) + struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd); + + if (regulator_get_mode(da8xx_ohci->vbus_reg) == + REGULATOR_MODE_OVERCURRENT) return 1; return 0; @@ -117,10 +128,13 @@ static int ohci_da8xx_get_oci(void) static int ohci_da8xx_regulator_event(struct notifier_block *nb, unsigned long event, void *data) { + struct da8xx_ohci_hcd *da8xx_ohci = + container_of(nb, struct da8xx_ohci_hcd, nb); + if (event & REGULATOR_EVENT_OVER_CURRENT) { - ocic_flag = 1; - if (ohci_da8xx_get_oci()) - ohci_da8xx_set_power(0); + da8xx_ohci->ocic_flag = 1; + if (ohci_da8xx_get_oci(da8xx_ohci->hcd)) + ohci_da8xx_set_power(da8xx_ohci->hcd, 0); } return 0; @@ -130,12 +144,13 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd) { struct device *dev = hcd->self.controller; struct ohci_hcd *ohci = hcd_to_ohci(hcd); + struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd); int result; u32 rh_a; dev_dbg(dev, "starting USB controller\n"); - result = ohci_da8xx_enable(); + result = ohci_da8xx_enable(hcd); if (result < 0) return result; @@ -147,7 +162,7 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd) result = ohci_setup(hcd); if (result < 0) { - ohci_da8xx_disable(); + ohci_da8xx_disable(hcd); return result; } @@ -159,7 +174,7 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd) */ rh_a = ohci_readl(ohci, &ohci->regs->roothub.a); - if (vbus_reg) { + if (da8xx_ohci->vbus_reg) { rh_a &= ~RH_A_NPS; rh_a |= RH_A_PSM; rh_a &= ~RH_A_NOCP; @@ -176,10 +191,11 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd) */ static int ohci_da8xx_hub_status_data(struct usb_hcd *hcd, char *buf) { + struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd); int length = orig_ohci_hub_status_data(hcd, buf); /* See if we have OCIC flag set */ - if (ocic_flag) { + if (da8xx_ohci->ocic_flag) { dev_dbg(hcd->self.controller, "over-current indicator change " "on port 1\n"); @@ -197,6 +213,7 @@ static int ohci_da8xx_hub_status_data(struct usb_hcd *hcd, char *buf) static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength) { + struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd); struct device *dev = hcd->self.controller; int temp; @@ -211,15 +228,15 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, temp = roothub_portstatus(hcd_to_ohci(hcd), wIndex - 1); /* The port power status (PPS) bit defaults to 1 */ - if (ohci_da8xx_get_power() == 0) + if (ohci_da8xx_get_power(hcd) == 0) temp &= ~RH_PS_PPS; /* The port over-current indicator (POCI) bit is always 0 */ - if (ohci_da8xx_get_oci() > 0) + if (ohci_da8xx_get_oci(hcd) > 0) temp |= RH_PS_POCI; /* The over-current indicator change (OCIC) bit is 0 too */ - if (ocic_flag) + if (da8xx_ohci->ocic_flag) temp |= RH_PS_OCIC; put_unaligned(cpu_to_le32(temp), (__le32 *)buf); @@ -240,13 +257,13 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, dev_dbg(dev, "%sPortFeature(%u): %s\n", temp ? "Set" : "Clear", wIndex, "POWER"); - return ohci_da8xx_set_power(temp) ? -EPIPE : 0; + return ohci_da8xx_set_power(hcd, temp) ? -EPIPE : 0; case USB_PORT_FEAT_C_OVER_CURRENT: dev_dbg(dev, "%sPortFeature(%u): %s\n", temp ? "Set" : "Clear", wIndex, "C_OVER_CURRENT"); - ocic_flag = temp; + da8xx_ohci->ocic_flag = temp; return 0; } } @@ -259,6 +276,7 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, static int ohci_da8xx_probe(struct platform_device *pdev) { + struct da8xx_ohci_hcd *da8xx_ohci; struct usb_hcd *hcd; struct resource *mem; int error, irq; @@ -268,30 +286,34 @@ static int ohci_da8xx_probe(struct platform_device *pdev) if (!hcd) return -ENOMEM; - usb11_clk = devm_clk_get(&pdev->dev, "usb11"); - if (IS_ERR(usb11_clk)) { - if (PTR_ERR(usb11_clk) != -EPROBE_DEFER) + da8xx_ohci = to_da8xx_ohci(hcd); + da8xx_ohci->hcd = hcd; + + da8xx_ohci->usb11_clk = devm_clk_get(&pdev->dev, "usb11"); + if (IS_ERR(da8xx_ohci->usb11_clk)) { + if (PTR_ERR(da8xx_ohci->usb11_clk) != -EPROBE_DEFER) dev_err(&pdev->dev, "Failed to get clock.\n"); - return PTR_ERR(usb11_clk); + return PTR_ERR(da8xx_ohci->usb11_clk); } - usb11_phy = devm_phy_get(&pdev->dev, "usb-phy"); - if (IS_ERR(usb11_phy)) { - if (PTR_ERR(usb11_phy) != -EPROBE_DEFER) + da8xx_ohci->usb11_phy = devm_phy_get(&pdev->dev, "usb-phy"); + if (IS_ERR(da8xx_ohci->usb11_phy)) { + if (PTR_ERR(da8xx_ohci->usb11_phy) != -EPROBE_DEFER) dev_err(&pdev->dev, "Failed to get phy.\n"); - return PTR_ERR(usb11_phy); + return PTR_ERR(da8xx_ohci->usb11_phy); } - vbus_reg = devm_regulator_get(&pdev->dev, "vbus"); - if (IS_ERR(vbus_reg)) { - if (PTR_ERR(vbus_reg) != -EPROBE_DEFER) + da8xx_ohci->vbus_reg = devm_regulator_get(&pdev->dev, "vbus"); + if (IS_ERR(da8xx_ohci->vbus_reg)) { + if (PTR_ERR(da8xx_ohci->vbus_reg) != -EPROBE_DEFER) dev_err(&pdev->dev, "Failed to get regulator.\n"); - return PTR_ERR(vbus_reg); + return PTR_ERR(da8xx_ohci->vbus_reg); } - if (vbus_reg) { - nb.notifier_call = ohci_da8xx_regulator_event; - error = devm_regulator_register_notifier(vbus_reg, &nb); + if (da8xx_ohci->vbus_reg) { + da8xx_ohci->nb.notifier_call = ohci_da8xx_regulator_event; + error = devm_regulator_register_notifier(da8xx_ohci->vbus_reg, + &da8xx_ohci->nb); if (error) { dev_err(&pdev->dev, "Could not register regulator notifier\n"); @@ -354,7 +376,7 @@ static int ohci_da8xx_suspend(struct platform_device *pdev, if (ret) return ret; - ohci_da8xx_disable(); + ohci_da8xx_disable(hcd); hcd->state = HC_STATE_SUSPENDED; return ret; @@ -370,7 +392,7 @@ static int ohci_da8xx_resume(struct platform_device *dev) msleep(5); ohci->next_statechange = jiffies; - ret = ohci_da8xx_enable(); + ret = ohci_da8xx_enable(hcd); if (ret) return ret; @@ -382,7 +404,8 @@ static int ohci_da8xx_resume(struct platform_device *dev) #endif static const struct ohci_driver_overrides da8xx_overrides __initconst = { - .reset = ohci_da8xx_reset + .reset = ohci_da8xx_reset, + .extra_priv_size = sizeof(struct da8xx_ohci_hcd), }; /*