linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: balbi@ti.com, george.cherian@ti.com,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH 02/16] usb: phy: phy-nop: add support for am335x PHY
Date: Mon, 22 Jul 2013 20:09:53 +0200	[thread overview]
Message-ID: <1374516607-2705-3-git-send-email-bigeasy@linutronix.de> (raw)
In-Reply-To: <1374516607-2705-1-git-send-email-bigeasy@linutronix.de>

The am335x PHY code is well hidden in multiple places. The glue layer
uses the nop and does up/down in the background. This patch copies the
power on / power off part out of dsps so it can be removed later in
dsps. At this point I am not sure if it is better to write a new phy
driver for am335x or just add the missing pieces to this one.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/usb/phy/phy-nop.c | 114 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 102 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/phy/phy-nop.c b/drivers/usb/phy/phy-nop.c
index 55445e5d..7c84eec 100644
--- a/drivers/usb/phy/phy-nop.c
+++ b/drivers/usb/phy/phy-nop.c
@@ -35,6 +35,7 @@
 #include <linux/clk.h>
 #include <linux/regulator/consumer.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
 
 struct nop_usb_xceiv {
 	struct usb_phy phy;
@@ -42,6 +43,14 @@ struct nop_usb_xceiv {
 	struct clk *clk;
 	struct regulator *vcc;
 	struct regulator *reset;
+
+	void __iomem *priv_reg;
+};
+
+struct phy_data {
+	int	(*phy_init)(struct usb_phy *x);
+	void	(*phy_shutdown)(struct usb_phy *x);
+	int	(*reg_init)(struct platform_device *pdev);
 };
 
 static struct platform_device *pd;
@@ -139,10 +148,85 @@ static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
 	return 0;
 }
 
+static int am335x_reg_init(struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+	struct nop_usb_xceiv *nop;
+	struct resource res;
+	int ret;
+
+	nop = platform_get_drvdata(pdev);
+	ret = of_address_to_resource(node, 0, &res);
+	if (ret)
+		return ret;
+
+	nop->priv_reg = devm_request_and_ioremap(&pdev->dev, &res);
+	if (!nop->priv_reg)
+		return -EINVAL;
+	return 0;
+}
+
+#define AM335X_USB_CTRL	0x00
+#define AM335x_USB_STS	0x04
+
+#define USBPHY_CM_PWRDN		(1 << 0)
+#define USBPHY_OTG_PWRDN	(1 << 1)
+#define USBPHY_OTGVDET_EN	(1 << 19)
+#define USBPHY_OTGSESSEND_EN	(1 << 20)
+
+static void am335x_phy_power(struct nop_usb_xceiv *nop, bool on)
+{
+	u32 val;
+
+	val = readl(nop->priv_reg);
+	if (on) {
+		val &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN);
+		val |= USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN;
+	} else {
+		val |= USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN;
+	}
+
+	writel(val, nop->priv_reg);
+}
+
+static int am335x_phy_init(struct usb_phy *phy)
+{
+	struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev);
+	int ret;
+
+	ret = nop_init(phy);
+	if (ret)
+		return ret;
+	am335x_phy_power(nop, true);
+	return 0;
+}
+
+static void am335x_phy_shutdown(struct usb_phy *phy)
+{
+	struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev);
+
+	am335x_phy_power(nop, false);
+	nop_shutdown(phy);
+}
+
+struct phy_data am335x_phy_data = {
+	.reg_init	= am335x_reg_init,
+	.phy_init	= am335x_phy_init,
+	.phy_shutdown	= am335x_phy_shutdown,
+};
+
+static const struct of_device_id nop_xceiv_dt_ids[] = {
+	{ .compatible = "usb-nop-xceiv" },
+	{ .compatible = "ti,am335x-usb-phy", .data = &am335x_phy_data },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids);
+
 static int nop_usb_xceiv_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data;
+	const struct phy_data	*phy_data = NULL;
 	struct nop_usb_xceiv	*nop;
 	enum usb_phy_type	type = USB_PHY_TYPE_USB2;
 	int err;
@@ -154,6 +238,7 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
 	if (!nop)
 		return -ENOMEM;
 
+	platform_set_drvdata(pdev, nop);
 	nop->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*nop->phy.otg),
 							GFP_KERNEL);
 	if (!nop->phy.otg)
@@ -161,13 +246,20 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
 
 	if (dev->of_node) {
 		struct device_node *node = dev->of_node;
+		const struct of_device_id *of_id;
 
 		if (of_property_read_u32(node, "clock-frequency", &clk_rate))
 			clk_rate = 0;
 
 		needs_vcc = of_property_read_bool(node, "vcc-supply");
 		needs_reset = of_property_read_bool(node, "reset-supply");
-
+		of_id = of_match_node(nop_xceiv_dt_ids, node);
+		if (of_id) {
+			phy_data = of_id->data;
+			err = phy_data->reg_init(pdev);
+			if (err)
+				return err;
+		}
 	} else if (pdata) {
 		type = pdata->type;
 		clk_rate = pdata->clk_rate;
@@ -217,8 +309,15 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
 	nop->phy.dev		= nop->dev;
 	nop->phy.label		= "nop-xceiv";
 	nop->phy.set_suspend	= nop_set_suspend;
-	nop->phy.init		= nop_init;
-	nop->phy.shutdown	= nop_shutdown;
+	if (phy_data && phy_data->phy_init)
+		nop->phy.init	= phy_data->phy_init;
+	else
+		nop->phy.init	= nop_init;
+
+	if (phy_data && phy_data->phy_shutdown)
+		nop->phy.shutdown = phy_data->phy_shutdown;
+	else
+		nop->phy.shutdown	= nop_shutdown;
 	nop->phy.state		= OTG_STATE_UNDEFINED;
 	nop->phy.type		= type;
 
@@ -233,8 +332,6 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
 		goto err_add;
 	}
 
-	platform_set_drvdata(pdev, nop);
-
 	ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
 
 	return 0;
@@ -257,13 +354,6 @@ static int nop_usb_xceiv_remove(struct platform_device *pdev)
 	return 0;
 }
 
-static const struct of_device_id nop_xceiv_dt_ids[] = {
-	{ .compatible = "usb-nop-xceiv" },
-	{ }
-};
-
-MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids);
-
 static struct platform_driver nop_usb_xceiv_driver = {
 	.probe		= nop_usb_xceiv_probe,
 	.remove		= nop_usb_xceiv_remove,
-- 
1.8.3.2


  parent reply	other threads:[~2013-07-22 18:14 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-22 18:09 am33x: multiple instances and dma support, v2 Sebastian Andrzej Siewior
2013-07-22 18:09 ` [PATCH 01/16] usb: musb: dsps: init / shutdown the phy Sebastian Andrzej Siewior
2013-07-25 14:32   ` Felipe Balbi
2013-07-22 18:09 ` Sebastian Andrzej Siewior [this message]
2013-07-25 14:33   ` [PATCH 02/16] usb: phy: phy-nop: add support for am335x PHY Felipe Balbi
2013-07-25 14:45     ` Sebastian Andrzej Siewior
2013-07-25 14:54       ` Felipe Balbi
2013-07-22 18:09 ` [PATCH 03/16] usb: musb: dsps: remove the hardcoded phy pieces Sebastian Andrzej Siewior
2013-07-22 18:09 ` [PATCH 04/16] usb: musb: remove ti81xx pieces from musb Sebastian Andrzej Siewior
2013-07-22 18:09 ` [PATCH 05/16] usb: musb: dsps: use proper child nodes Sebastian Andrzej Siewior
2013-07-23  6:46   ` George Cherian
2013-07-23  9:15     ` Sebastian Andrzej Siewior
2013-07-22 18:09 ` [PATCH 06/16] usb: musb: dsps: rename ti81xx_driver_data to am33xx_driver_data Sebastian Andrzej Siewior
2013-07-23  6:04   ` George Cherian
2013-07-23  9:09     ` Sebastian Andrzej Siewior
2013-07-23  9:14       ` George Cherian
     [not found]   ` <CADYTM3avh7GFTDQW01FnojKZkmL0_hi+=K-VVwCw5peJL2hwTA@mail.gmail.com>
2013-07-23 19:09     ` Bin Liu
2013-07-25 14:41     ` Sebastian Andrzej Siewior
2013-07-25 15:12       ` Bin Liu
2013-07-25 15:16         ` Sebastian Andrzej Siewior
2013-07-25 15:28           ` Bin Liu
2013-07-25 16:11             ` Felipe Balbi
2013-07-26  9:11               ` [PATCH 06/16 => 1/2] " Sebastian Andrzej Siewior
2013-07-26  9:11                 ` [PATCH 06/16 => 2/2] usb: musb: dsps: remove EOI access Sebastian Andrzej Siewior
2013-07-25 15:37           ` [PATCH 06/16] usb: musb: dsps: rename ti81xx_driver_data to am33xx_driver_data Felipe Balbi
2013-07-22 18:09 ` [PATCH 07/16] usb: musb: replace ifndef with ifdef for CONFIG_MUSB_PIO_ONLY Sebastian Andrzej Siewior
2013-07-22 18:09 ` [PATCH 08/16] usb: musb: dma: merge ->start/stop into create/destroy Sebastian Andrzej Siewior
2013-07-22 18:10 ` [PATCH 09/16] usb: musb: provide empty dma_controller_create() in PIO mode Sebastian Andrzej Siewior
2013-07-22 18:10 ` [PATCH 10/16] usb: musb: remove a few is_dma_capable() in init/exit code Sebastian Andrzej Siewior
2013-07-22 18:10 ` [PATCH 11/16] usb: musb: core: call dma_controller_destroy() in the err path Sebastian Andrzej Siewior
2013-07-22 18:10 ` [PATCH 12/16] usb: musb: unmap reqs in musb_gadget_queue()'s error case Sebastian Andrzej Siewior
2013-07-22 18:10 ` [PATCH 13/16] usb: musb: do not change dev's dma_mask Sebastian Andrzej Siewior
2013-07-22 18:10 ` [PATCH 14/16] usb: musb: dsps: add MUSB_DEVCTL_SESSION back after removal Sebastian Andrzej Siewior
     [not found]   ` <CADYTM3a5xzs+-VCTeKLGiRjo7JOqOJ5H4EWDACpTMovY5_ooRA@mail.gmail.com>
2013-07-23 17:31     ` Sebastian Andrzej Siewior
2013-07-23 18:55       ` Bin Liu
2013-07-26 15:44         ` Sebastian Andrzej Siewior
2013-07-26 16:31         ` Sebastian Andrzej Siewior
2013-07-26 17:53           ` Bin Liu
2013-07-26 18:17             ` Bin Liu
2013-07-26 18:22               ` Sebastian Andrzej Siewior
2013-07-26 18:29                 ` Bin Liu
2013-07-26 19:55                   ` Sebastian Andrzej Siewior
2013-07-26 20:15                     ` Bin Liu
2013-07-26 20:35                       ` Sebastian Andrzej Siewior
2013-07-27  3:07                         ` Bin Liu
2013-07-29 16:53                           ` Sebastian Andrzej Siewior
2013-07-29 17:26                             ` Bin Liu
2013-07-29 17:51                               ` Sebastian Andrzej Siewior
2013-07-29 18:41                                 ` Bin Liu
2013-08-09 16:03                                   ` [PATCH] usb: musb: am335x: Do not remove the session bin HOST-only mode Sebastian Andrzej Siewior
2013-08-09 20:30                                     ` Sergei Shtylyov
2013-08-13  7:14                                       ` Sebastian Andrzej Siewior
2013-08-13 13:03                                         ` Bin Liu
2013-08-13 13:17                                           ` Sebastian Andrzej Siewior
2013-08-13 13:33                                             ` Bin Liu
2013-08-13 13:44                                               ` Sebastian Andrzej Siewior
2013-08-13 14:01                                                 ` Bin Liu
2013-08-13 14:23                                                   ` Sebastian Andrzej Siewior
2013-08-13 14:32                                                     ` Bin Liu
2013-08-14 18:17                                                       ` Sebastian Andrzej Siewior
2013-08-14 18:43                                                         ` Bin Liu
2013-07-22 18:10 ` [PATCH 15/16] dmaengine: add transfered member to dma_async_tx_descriptor Sebastian Andrzej Siewior
2013-07-22 18:52   ` Sergei Shtylyov
2013-07-23 17:12     ` Sebastian Andrzej Siewior
2013-07-25 14:57   ` Lars-Peter Clausen
2013-07-25 15:12     ` Sebastian Andrzej Siewior
2013-07-25 15:32       ` Lars-Peter Clausen
2013-07-26  9:30         ` Sebastian Andrzej Siewior
2013-07-29 11:39   ` Vinod Koul
2013-07-29 12:33     ` Sebastian Andrzej Siewior
2013-07-22 18:10 ` [PATCH 16/16] usb/musb dma: add cppi41 dma driver Sebastian Andrzej Siewior

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=1374516607-2705-3-git-send-email-bigeasy@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=balbi@ti.com \
    --cc=george.cherian@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).