From patchwork Tue Nov 8 18:57:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Haslam X-Patchwork-Id: 9417965 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 C99D960459 for ; Tue, 8 Nov 2016 18:59:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B991A289C2 for ; Tue, 8 Nov 2016 18:59:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC51C289C9; Tue, 8 Nov 2016 18:59:55 +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 17859289C2 for ; Tue, 8 Nov 2016 18:59:55 +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 1c4BbJ-0001kL-SE; Tue, 08 Nov 2016 18:58:29 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c4Baj-0001Sy-JC for linux-arm-kernel@lists.infradead.org; Tue, 08 Nov 2016 18:57:55 +0000 Received: by mail-wm0-x22a.google.com with SMTP id a197so264242727wmd.0 for ; Tue, 08 Nov 2016 10:57:33 -0800 (PST) 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=mhg+Vld3TQDOUg5rJni6+OHZqxp2fYdVbXTXILgxsxA=; b=vlfJKpyVE85RwkSIf6vCk40Dchb/wZkBcLJ1B15SDxyLLvPL5Ak2N8/icaOxU4qCyI GC0C08xAyDeHbj5Gzipv1x9Q/9fpOaXtrSPJ6jGo6ofbi6ZpMUYfsTP8RQMoO8CpTB2P 4fd+2Vu6JVufY8/DpudBc9z/xmP0rSsEhBRT42p5QjpHmxDWLxArXf+13RWNmEwUCYlf ZKoNreiveOFu1xNRdaVP/eVb0QgAmjrHWt4I6fZ03zRfp8hjeejtdFcmIaquZeDWejFi x2tpS1ZWLb0S1jWrGYmJXkvEPR0/ui2akH+I5IPznFqfDzNZ2nHyIPTpvdynjfqOaG3P qBhw== 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=mhg+Vld3TQDOUg5rJni6+OHZqxp2fYdVbXTXILgxsxA=; b=OWB0fb+hJgrrZW3hv8FjqSqm0kyP7zTvoJMx+n9ULsq++xt2h0MGY3qBpVBTchE5Nw TtpMyfx59RoLOSCo4iPfyoRuuBy7yIa5DzuxBmmu2ugmdqgWvZa+GvxDyek5FHFfisCk 6DBSx54oXcqfD0cG/HUmCU13J9oKLfsf+7xVNwyK92M+AgEyFJg5qwFNpmAcQulOCmFG onLooplsrv+CCp90hlAjMxZ0bTxVGSrcaqoFstyz538nk8paT/QZMNDjLYPiNJ4toueT rsjDXc+MPC0KXBMggm6VxcW4uLbFad5ym4hZKLmJuTEWJmxCbhSPYKahKdpBxaKiNabW Hnlw== X-Gm-Message-State: ABUngvdPHQWaEfJfYBcCn0GpTyRvWd50bp2uXFbuPdyURinBVVQ/fyRUY0aYCHBEuwZk+nuZ X-Received: by 10.194.87.7 with SMTP id t7mr11497450wjz.196.1478631452363; Tue, 08 Nov 2016 10:57:32 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id h2sm38593239wjy.40.2016.11.08.10.57.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Nov 2016 10:57:32 -0800 (PST) From: Axel Haslam To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, nsekhar@ti.com, khilman@kernel.org, david@lechnology.com Subject: [PATCH v4 2/3] USB: ohci: da8xx: Prepare to remove platform callbacks Date: Tue, 8 Nov 2016 19:57:22 +0100 Message-Id: <20161108185723.17518-3-ahaslam@baylibre.com> X-Mailer: git-send-email 2.10.1.502.g6598894 In-Reply-To: <20161108185723.17518-1-ahaslam@baylibre.com> References: <20161108185723.17518-1-ahaslam@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161108_105753_836824_1AA51EEE X-CRM114-Status: GOOD ( 15.69 ) 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: 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 Wrap the platform data callbacks into separate functions. This will help migrate to using a regulator by providing a well defined place to implement the regulator functions while the platform calls are still in place and users have not been converted. The platform callbacks will be removed on a following patch. Signed-off-by: Axel Haslam --- drivers/usb/host/ohci-da8xx.c | 125 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 102 insertions(+), 23 deletions(-) diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c index 0442c64..9ed43c7 100644 --- a/drivers/usb/host/ohci-da8xx.c +++ b/drivers/usb/host/ohci-da8xx.c @@ -80,6 +80,72 @@ static void ohci_da8xx_disable(struct usb_hcd *hcd) clk_disable_unprepare(da8xx_ohci->usb11_clk); } +static int ohci_da8xx_set_power(struct usb_hcd *hcd, int on) +{ + struct device *dev = hcd->self.controller; + struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); + + if (hub && hub->set_power) + return hub->set_power(1, on); + + return 0; +} + +static int ohci_da8xx_get_power(struct usb_hcd *hcd) +{ + struct device *dev = hcd->self.controller; + struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); + + if (hub && hub->get_power) + return hub->get_power(1); + + return 1; +} + +static int ohci_da8xx_get_oci(struct usb_hcd *hcd) +{ + struct device *dev = hcd->self.controller; + struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); + + if (hub && hub->get_oci) + return hub->get_oci(1); + + return 0; +} + +static int ohci_da8xx_has_set_power(struct usb_hcd *hcd) +{ + struct device *dev = hcd->self.controller; + struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); + + if (hub && hub->set_power) + return 1; + + return 0; +} + +static int ohci_da8xx_has_oci(struct usb_hcd *hcd) +{ + struct device *dev = hcd->self.controller; + struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); + + if (hub && hub->get_oci) + return 1; + + return 0; +} + +static int ohci_da8xx_has_potpgt(struct usb_hcd *hcd) +{ + struct device *dev = hcd->self.controller; + struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); + + if (hub && hub->potpgt) + return 1; + + return 0; +} + /* * Handle the port over-current indicator change. */ @@ -93,6 +159,26 @@ static void ohci_da8xx_ocic_handler(struct da8xx_ohci_root_hub *hub, hub->set_power(port, 0); } +static int ohci_da8xx_register_notify(struct usb_hcd *hcd) +{ + struct device *dev = hcd->self.controller; + struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); + + if (hub && hub->ocic_notify) + return hub->ocic_notify(ohci_da8xx_ocic_handler); + + return 0; +} + +static void ohci_da8xx_unregister_notify(struct usb_hcd *hcd) +{ + struct device *dev = hcd->self.controller; + struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); + + if (hub && hub->ocic_notify) + hub->ocic_notify(NULL); +} + static int ohci_da8xx_reset(struct usb_hcd *hcd) { struct device *dev = hcd->self.controller; @@ -126,16 +212,18 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd) * the correct hub descriptor... */ rh_a = ohci_readl(ohci, &ohci->regs->roothub.a); - if (hub->set_power) { + if (ohci_da8xx_has_set_power(hcd)) { rh_a &= ~RH_A_NPS; rh_a |= RH_A_PSM; } - if (hub->get_oci) { + if (ohci_da8xx_has_oci(hcd)) { rh_a &= ~RH_A_NOCP; rh_a |= RH_A_OCPM; } - rh_a &= ~RH_A_POTPGT; - rh_a |= hub->potpgt << 24; + if (ohci_da8xx_has_potpgt(hcd)) { + rh_a &= ~RH_A_POTPGT; + rh_a |= hub->potpgt << 24; + } ohci_writel(ohci, rh_a, &ohci->regs->roothub.a); return result; @@ -168,7 +256,6 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength) { struct device *dev = hcd->self.controller; - struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev); int temp; switch (typeReq) { @@ -182,11 +269,11 @@ 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 (hub->get_power && hub->get_power(wIndex) == 0) + if (!ohci_da8xx_get_power(hcd)) temp &= ~RH_PS_PPS; /* The port over-current indicator (POCI) bit is always 0 */ - if (hub->get_oci && hub->get_oci(wIndex) > 0) + if (ohci_da8xx_get_oci(hcd)) temp |= RH_PS_POCI; /* The over-current indicator change (OCIC) bit is 0 too */ @@ -211,10 +298,7 @@ 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"); - if (!hub->set_power) - return -EPIPE; - - return hub->set_power(wIndex, 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, @@ -236,15 +320,10 @@ 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_root_hub *hub = dev_get_platdata(&pdev->dev); struct da8xx_ohci_hcd *da8xx_ohci; struct usb_hcd *hcd; struct resource *mem; int error, irq; - - if (hub == NULL) - return -ENODEV; - hcd = usb_create_hcd(&ohci_da8xx_hc_driver, &pdev->dev, dev_name(&pdev->dev)); if (!hcd) @@ -290,12 +369,13 @@ static int ohci_da8xx_probe(struct platform_device *pdev) device_wakeup_enable(hcd->self.controller); - if (hub->ocic_notify) { - error = hub->ocic_notify(ohci_da8xx_ocic_handler); - if (!error) - return 0; - } + error = ohci_da8xx_register_notify(hcd); + if (error) + goto err_remove_hcd; + + return 0; +err_remove_hcd: usb_remove_hcd(hcd); err: usb_put_hcd(hcd); @@ -305,9 +385,8 @@ static int ohci_da8xx_probe(struct platform_device *pdev) static int ohci_da8xx_remove(struct platform_device *pdev) { struct usb_hcd *hcd = platform_get_drvdata(pdev); - struct da8xx_ohci_root_hub *hub = dev_get_platdata(&pdev->dev); - hub->ocic_notify(NULL); + ohci_da8xx_unregister_notify(hcd); usb_remove_hcd(hcd); usb_put_hcd(hcd);