From: Gregory CLEMENT <gregory.clement@free-electrons.com>
To: Mathias Nyman <mathias.nyman@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Felipe Balbi <balbi@ti.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Jason Cooper <jason@lakedaemon.net>, Andrew Lunn <andrew@lunn.ch>,
Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
Gregory CLEMENT <gregory.clement@free-electrons.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
Ezequiel Garcia <ezequiel.garcia@free-electrons.com>,
linux-arm-kernel@lists.infradead.org,
Lior Amsalem <alior@marvell.com>,
Tawfik Bayouk <tawfik@marvell.com>,
Nadav Haklai <nadavh@marvell.com>,
Grant Likely <grant.likely@linaro.org>,
Rob Herring <robh+dt@kernel.org>,
devicetree@vger.kernel.org
Subject: [PATCH v3 05/20] usb: host: xhci-plat: Add clocks support
Date: Tue, 6 May 2014 02:14:00 +0200 [thread overview]
Message-ID: <1399335255-589-6-git-send-email-gregory.clement@free-electrons.com> (raw)
In-Reply-To: <1399335255-589-1-git-send-email-gregory.clement@free-electrons.com>
Some platform (such as the Armada 38x ones) can gate the clock of
their USB controller. This patch add the support for the clock, by
enabling them during probe and disabling them on remove.
As not all platforms have clock support then enabling and disabling
the clocks have been placed in separate functions. Then if the clocks
are not supported we still can use the same calls, and there is no
Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
---
drivers/usb/host/xhci-plat.c | 57 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 54 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index f5351af4b2c5..bb37b941c8ec 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -11,6 +11,7 @@
* version 2 as published by the Free Software Foundation.
*/
+#include <linux/clk.h>
#include <linux/dma-mapping.h>
#include <linux/module.h>
#include <linux/of.h>
@@ -19,6 +20,10 @@
#include "xhci.h"
+struct xhci_plat_priv {
+ struct clk *clk;
+};
+
static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
{
/*
@@ -38,7 +43,8 @@ static int xhci_plat_setup(struct usb_hcd *hcd)
static const struct hc_driver xhci_plat_xhci_driver = {
.description = "xhci-hcd",
.product_desc = "xHCI Host Controller",
- .hcd_priv_size = sizeof(struct xhci_hcd *),
+ .hcd_priv_size = sizeof(struct xhci_hcd *) +
+ sizeof(struct xhci_plat_priv),
/*
* generic hardware linkage
@@ -85,6 +91,40 @@ static const struct hc_driver xhci_plat_xhci_driver = {
.bus_resume = xhci_bus_resume,
};
+static int xhci_plat_enable_clk(struct platform_device *pdev)
+{
+ struct usb_hcd *hcd = platform_get_drvdata(pdev);
+ struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+ struct xhci_plat_priv *priv = (struct xhci_plat_priv *) xhci->priv;
+
+ priv->clk = devm_clk_get(&pdev->dev, NULL);
+
+ /*
+ * Not all platforms have a clk so it is not an error if the
+ * clock does not exists.
+ */
+ if (IS_ERR(priv->clk))
+ return 0;
+
+ return clk_prepare_enable(priv->clk);
+}
+
+static void xhci_plat_disable_clk(struct platform_device *pdev)
+{
+ struct usb_hcd *hcd = platform_get_drvdata(pdev);
+ struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+ struct xhci_plat_priv *priv = (struct xhci_plat_priv *) xhci->priv;
+
+ /*
+ * Not all platforms have a clk so it is not an error if the
+ * clock does not exists.
+ */
+ if (IS_ERR(priv->clk))
+ return;
+
+ clk_disable_unprepare(priv->clk);
+}
+
static int xhci_plat_probe(struct platform_device *pdev)
{
const struct hc_driver *driver;
@@ -118,7 +158,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
if (!hcd)
- return -ENOMEM;
+ ret = -ENOMEM;
hcd->rsrc_start = res->start;
hcd->rsrc_len = resource_size(res);
@@ -140,6 +180,13 @@ static int xhci_plat_probe(struct platform_device *pdev)
ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
if (ret)
goto unmap_registers;
+
+ ret = xhci_plat_enable_clk(pdev);
+ if (ret) {
+ dev_dbg(&pdev->dev, "error enabling clocks\n");
+ goto dealloc_usb2_hcd;
+ }
+
device_wakeup_enable(hcd->self.controller);
/* USB 2.0 roothub is stored in the platform_device now. */
@@ -149,7 +196,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
dev_name(&pdev->dev), hcd);
if (!xhci->shared_hcd) {
ret = -ENOMEM;
- goto dealloc_usb2_hcd;
+ goto disable_clk;
}
/*
@@ -170,6 +217,9 @@ static int xhci_plat_probe(struct platform_device *pdev)
put_usb3_hcd:
usb_put_hcd(xhci->shared_hcd);
+disable_clk:
+ xhci_plat_disable_clk(pdev);
+
dealloc_usb2_hcd:
usb_remove_hcd(hcd);
@@ -193,6 +243,7 @@ static int xhci_plat_remove(struct platform_device *dev)
usb_remove_hcd(xhci->shared_hcd);
usb_put_hcd(xhci->shared_hcd);
+ xhci_plat_disable_clk(dev);
usb_remove_hcd(hcd);
iounmap(hcd->regs);
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
--
1.8.1.2
next prev parent reply other threads:[~2014-05-06 0:19 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-06 0:13 [PATCH v3 00/20] USB support for Armada 38x and Armada 375 Gregory CLEMENT
2014-05-06 0:13 ` [PATCH v3 01/20] usb: ehci-orion: Fix clock reference leaking Gregory CLEMENT
2014-05-06 14:30 ` Alan Stern
2014-05-07 9:38 ` Thomas Petazzoni
2014-05-06 0:13 ` [PATCH v3 02/20] usb: ehci-orion: Add the optional PHY support Gregory CLEMENT
2014-05-06 13:33 ` Andrew Lunn
2014-05-07 9:40 ` Thomas Petazzoni
2014-05-07 13:21 ` Andrew Lunn
2014-05-07 13:56 ` Thomas Petazzoni
2014-05-06 0:13 ` [PATCH v3 03/20] usb: host: xhci-plat: Sort the headers in alphabetic order Gregory CLEMENT
2014-05-06 0:13 ` [PATCH v3 04/20] usb: xhci: add a platform-private field Gregory CLEMENT
2014-05-06 15:40 ` Felipe Balbi
2014-05-06 0:14 ` Gregory CLEMENT [this message]
2014-05-06 3:00 ` [PATCH v3 05/20] usb: host: xhci-plat: Add clocks support Felipe Balbi
2014-05-06 13:41 ` Jason Cooper
2014-05-07 12:26 ` Thomas Petazzoni
2014-05-06 0:14 ` [PATCH v3 06/20] usb: host: xhci-plat: Add support for the Armada 38x Gregory CLEMENT
2014-05-06 11:34 ` Bartlomiej Zolnierkiewicz
2014-05-06 11:57 ` Arnd Bergmann
2014-05-06 12:10 ` Thomas Petazzoni
2014-05-06 12:21 ` Arnd Bergmann
2014-05-06 12:42 ` Thomas Petazzoni
2014-05-06 15:39 ` Felipe Balbi
2014-05-07 10:23 ` Thomas Petazzoni
2014-05-07 15:10 ` Felipe Balbi
2014-05-07 15:14 ` Thomas Petazzoni
2014-05-06 0:14 ` [PATCH v3 07/20] xhci-platform: Add a new controller using xhci: " Gregory CLEMENT
2014-05-06 0:14 ` [PATCH v3 08/20] ARM: mvebu: Add Device Tree description of xHCI hosts on " Gregory CLEMENT
2014-05-06 13:42 ` Andrew Lunn
2014-05-06 0:14 ` [PATCH v3 09/20] ARM: mvebu: Add Device Tree description of the EHCI host " Gregory CLEMENT
2014-05-06 0:14 ` [PATCH v3 10/20] ARM: mvebu: Add USB3 support for " Gregory CLEMENT
2014-05-06 0:14 ` [PATCH v3 11/20] ARM: configs: Add usb_xhci_mvebu to mvebu_v7_defconfig Gregory CLEMENT
2014-05-06 0:14 ` [PATCH v3 12/20] ARM: configs: Add usb_xhci_mvebu to multi_v7_defconfig Gregory CLEMENT
2014-05-06 13:46 ` Jason Cooper
2014-05-06 0:14 ` [PATCH v3 13/20] usb: host: xhci-plat: Add support for the Armada 375 Gregory CLEMENT
2014-05-06 0:14 ` [PATCH v3 14/20] xhci-platform: Add a new controller using xHCI: " Gregory CLEMENT
2014-05-06 0:14 ` [PATCH v3 15/20] ARM: mvebu: Add Device Tree description of USB cluster controller on " Gregory CLEMENT
2014-05-06 0:14 ` [PATCH v3 16/20] dt: binding: Armada 375 USB cluster Gregory CLEMENT
2014-05-06 0:14 ` [PATCH v3 17/20] phy: Add support for USB cluster on the Armada 375 SoC Gregory CLEMENT
2014-05-06 11:37 ` Bartlomiej Zolnierkiewicz
2014-05-07 12:50 ` Thomas Petazzoni
2014-05-06 13:54 ` Andrew Lunn
2014-05-07 12:52 ` Thomas Petazzoni
2014-05-06 20:53 ` Ezequiel Garcia
2014-05-07 12:55 ` Thomas Petazzoni
2014-05-06 0:14 ` [PATCH v3 18/20] ARM: mvebu: Add USB3 support for Armada 375 Gregory CLEMENT
2014-05-06 0:14 ` [PATCH v3 19/20] ARM: mvebu: Add Device Tree description of the xHCI host on " Gregory CLEMENT
2014-05-06 0:14 ` [PATCH v3 20/20] ARM: mvebu: Add Device Tree description of the EHCI " Gregory CLEMENT
2014-05-07 8:33 ` [PATCH v3 00/20] USB support for Armada 38x and " Hans de Goede
2014-05-07 9:21 ` Sebastian Hesselbarth
2014-05-07 9:48 ` Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1399335255-589-6-git-send-email-gregory.clement@free-electrons.com \
--to=gregory.clement@free-electrons.com \
--cc=alior@marvell.com \
--cc=andrew@lunn.ch \
--cc=balbi@ti.com \
--cc=devicetree@vger.kernel.org \
--cc=ezequiel.garcia@free-electrons.com \
--cc=grant.likely@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=jason@lakedaemon.net \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=nadavh@marvell.com \
--cc=robh+dt@kernel.org \
--cc=sebastian.hesselbarth@gmail.com \
--cc=tawfik@marvell.com \
--cc=thomas.petazzoni@free-electrons.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®