devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kishon Vijay Abraham I <kishon@ti.com>
To: bcousson@baylibre.com, tony@atomide.com, balbi@ti.com,
	rogerq@ti.com, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org,
	kishon@ti.com
Cc: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com,
	ijc+devicetree@hellion.org.uk, galak@codeaurora.org,
	linux@arm.linux.org.uk, gregkh@linuxfoundation.org,
	nsekhar@ti.com
Subject: [PATCH 07/17] usb: musb: omap2430: use *syscon* framework to write to mailbox register
Date: Tue, 23 Jun 2015 17:28:52 +0530	[thread overview]
Message-ID: <1435060743-5511-8-git-send-email-kishon@ti.com> (raw)
In-Reply-To: <1435060743-5511-1-git-send-email-kishon@ti.com>

Deprecate using phy-omap-control driver to write to the mailbox register
and start using *syscon* framework to do the same.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 Documentation/devicetree/bindings/usb/omap-usb.txt |    7 +-
 drivers/usb/musb/omap2430.c                        |  118 ++++++++++++++++----
 2 files changed, 102 insertions(+), 23 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
index 38d9bb8..c001306 100644
--- a/Documentation/devicetree/bindings/usb/omap-usb.txt
+++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
@@ -20,10 +20,15 @@ OMAP MUSB GLUE
  - phy-names : the names of the PHY corresponding to the PHYs present in the
    *phy* phandle.
 
-Optional properties:
+Optional Properties:
+Deprecated properties:
  - ctrl-module : phandle of the control module this glue uses to write to
    mailbox
 
+Recommended properies:
+ - syscon-otghs : phandle/offset pair. Phandle to the system control module and the
+   register offset of the mailbox.
+
 SOC specific device node entry
 usb_otg_hs: usb_otg_hs@4a0ab000 {
 	compatible = "ti,omap4-musb";
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index cc752d8..bcd6d1e 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -39,16 +39,27 @@
 #include <linux/usb/musb-omap.h>
 #include <linux/phy/omap_control_phy.h>
 #include <linux/of_platform.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
 
 #include "musb_core.h"
 #include "omap2430.h"
 
+#define OMAP2430_MUSB_MODE_MASK	0x1f
+#define OMAP2430_MUSB_AVALID	(0x1 << 0)
+#define OMAP2430_MUSB_BVALID	(0x1 << 1)
+#define OMAP2430_MUSB_VBUSVALID	(0x1 << 2)
+#define OMAP2430_MUSB_SESSEND	(0x1 << 3)
+#define OMAP2430_MUSB_IDDIG	(0x1 << 4)
+
 struct omap2430_glue {
 	struct device		*dev;
 	struct platform_device	*musb;
 	enum omap_musb_vbus_id_status status;
 	struct work_struct	omap_musb_mailbox_work;
 	struct device		*control_otghs;
+	struct regmap		*syscon_otghs; /* ctrl. reg. acces */
+	unsigned int            otghs_reg; /* otghs reg. index within syscon */
 };
 #define glue_to_musb(g)		platform_get_drvdata(g->musb)
 
@@ -253,6 +264,47 @@ void omap_musb_mailbox(enum omap_musb_vbus_id_status status)
 }
 EXPORT_SYMBOL_GPL(omap_musb_mailbox);
 
+static void omap2430_musb_set_usbmode(struct omap2430_glue *glue,
+				      enum omap_control_usb_mode mode)
+{
+	u32 val;
+	int ret;
+
+	if (glue->syscon_otghs) {
+		switch (mode) {
+		case USB_MODE_HOST:
+			val = OMAP2430_MUSB_AVALID | OMAP2430_MUSB_VBUSVALID;
+			break;
+
+		case USB_MODE_DEVICE:
+			val = OMAP2430_MUSB_IDDIG | OMAP2430_MUSB_AVALID |
+				OMAP2430_MUSB_VBUSVALID;
+			break;
+
+		case USB_MODE_DISCONNECT:
+			val = OMAP2430_MUSB_IDDIG | OMAP2430_MUSB_SESSEND;
+			break;
+
+		default:
+			dev_dbg(glue->dev, "Invalid mode\n");
+			goto err_regmap_update;
+		}
+
+		ret = regmap_update_bits(glue->syscon_otghs,
+					 glue->otghs_reg,
+					 OMAP2430_MUSB_MODE_MASK, val);
+		if (ret < 0)
+			goto err_regmap_update;
+	} else {
+		omap_control_usb_set_mode(glue->control_otghs, mode);
+	}
+
+	return;
+
+err_regmap_update:
+	dev_err(glue->dev, "Failed to set mode to %d\n", mode);
+}
+
 static void omap_musb_set_mailbox(struct omap2430_glue *glue)
 {
 	struct musb *musb = glue_to_musb(glue);
@@ -270,8 +322,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
 		musb->xceiv->last_event = USB_EVENT_ID;
 		if (musb->gadget_driver) {
 			pm_runtime_get_sync(dev);
-			omap_control_usb_set_mode(glue->control_otghs,
-				USB_MODE_HOST);
+			omap2430_musb_set_usbmode(glue, USB_MODE_HOST);
 			omap2430_musb_set_vbus(musb, 1);
 		}
 		break;
@@ -284,7 +335,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
 		musb->xceiv->last_event = USB_EVENT_VBUS;
 		if (musb->gadget_driver)
 			pm_runtime_get_sync(dev);
-		omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
+		omap2430_musb_set_usbmode(glue, USB_MODE_DEVICE);
 		break;
 
 	case OMAP_MUSB_ID_FLOAT:
@@ -301,8 +352,7 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
 		if (data->interface_type == MUSB_INTERFACE_UTMI)
 			otg_set_vbus(musb->xceiv->otg, 0);
 
-		omap_control_usb_set_mode(glue->control_otghs,
-			USB_MODE_DISCONNECT);
+		omap2430_musb_set_usbmode(glue, USB_MODE_DISCONNECT);
 		break;
 	default:
 		dev_dbg(dev, "ID float\n");
@@ -444,7 +494,7 @@ static void omap2430_musb_enable(struct musb *musb)
 	switch (glue->status) {
 
 	case OMAP_MUSB_ID_GROUND:
-		omap_control_usb_set_mode(glue->control_otghs, USB_MODE_HOST);
+		omap2430_musb_set_usbmode(glue, USB_MODE_HOST);
 		if (data->interface_type != MUSB_INTERFACE_UTMI)
 			break;
 		devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
@@ -463,7 +513,7 @@ static void omap2430_musb_enable(struct musb *musb)
 		break;
 
 	case OMAP_MUSB_VBUS_VALID:
-		omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE);
+		omap2430_musb_set_usbmode(glue, USB_MODE_DEVICE);
 		break;
 
 	default:
@@ -477,8 +527,7 @@ static void omap2430_musb_disable(struct musb *musb)
 	struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
 
 	if (glue->status != OMAP_MUSB_UNKNOWN)
-		omap_control_usb_set_mode(glue->control_otghs,
-			USB_MODE_DISCONNECT);
+		omap2430_musb_set_usbmode(glue, USB_MODE_DISCONNECT);
 }
 
 static int omap2430_musb_exit(struct musb *musb)
@@ -507,6 +556,40 @@ static const struct musb_platform_ops omap2430_ops = {
 
 static u64 omap2430_dmamask = DMA_BIT_MASK(32);
 
+static int omap2430_get_control(struct omap2430_glue *glue,
+				struct device_node *np)
+{
+	struct device_node *control_node;
+	struct platform_device *control_pdev;
+
+	glue->syscon_otghs = syscon_regmap_lookup_by_phandle(np,
+							     "syscon-otghs");
+	if (IS_ERR(glue->syscon_otghs)) {
+		dev_info(glue->dev, "can't get syscon, using control device\n");
+		glue->syscon_otghs = NULL;
+
+		control_node = of_parse_phandle(np, "ctrl-module", 0);
+		if (control_node) {
+			control_pdev = of_find_device_by_node(control_node);
+			if (!control_pdev) {
+				dev_err(glue->dev,
+					"Failed to get control device\n");
+				return -EINVAL;
+			}
+			glue->control_otghs = &control_pdev->dev;
+		}
+	} else {
+		if (of_property_read_u32_index(np, "syscon-otghs", 1,
+					       &glue->otghs_reg)) {
+			dev_err(glue->dev,
+				"couldn't get otghs reg. offset\n");
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
 static int omap2430_probe(struct platform_device *pdev)
 {
 	struct resource			musb_resources[3];
@@ -538,9 +621,6 @@ static int omap2430_probe(struct platform_device *pdev)
 	glue->control_otghs = ERR_PTR(-ENODEV);
 
 	if (np) {
-		struct device_node *control_node;
-		struct platform_device *control_pdev;
-
 		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
 		if (!pdata)
 			goto err2;
@@ -567,16 +647,10 @@ static int omap2430_probe(struct platform_device *pdev)
 		pdata->board_data	= data;
 		pdata->config		= config;
 
-		control_node = of_parse_phandle(np, "ctrl-module", 0);
-		if (control_node) {
-			control_pdev = of_find_device_by_node(control_node);
-			if (!control_pdev) {
-				dev_err(&pdev->dev, "Failed to get control device\n");
-				ret = -EINVAL;
-				goto err2;
-			}
-			glue->control_otghs = &control_pdev->dev;
-		}
+		ret = omap2430_get_control(glue, np);
+		if (ret)
+			goto err2;
+
 	}
 	pdata->platform_ops		= &omap2430_ops;
 
-- 
1.7.9.5

  parent reply	other threads:[~2015-06-23 11:58 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-23 11:58 [PATCH 00/17] Deprecate phy-omap-control and use SYSCON Kishon Vijay Abraham I
2015-06-23 11:58 ` [PATCH 01/17] phy: ti-pipe3: use ti_pipe3_power_off to power off the PHY during probe Kishon Vijay Abraham I
2015-06-23 14:47   ` Roger Quadros
2015-06-23 11:58 ` [PATCH 02/17] phy: ti-pipe3: use *syscon* framework to power on/off the PHY Kishon Vijay Abraham I
     [not found]   ` <1435060743-5511-3-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2015-06-23 14:53     ` Roger Quadros
     [not found]       ` <20150623175355.d80c1d6626439fbb6c26169c-l0cyMroinI0@public.gmane.org>
2015-06-24 11:26         ` Kishon Vijay Abraham I
2015-06-23 11:58 ` [PATCH 03/17] phy: ti-pipe3: use *syscon* framework to set PCS value of " Kishon Vijay Abraham I
     [not found]   ` <1435060743-5511-4-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2015-06-24 10:34     ` Roger Quadros
2015-06-24 13:16       ` Kishon Vijay Abraham I
     [not found]         ` <558AAD98.1090602-l0cyMroinI0@public.gmane.org>
2015-06-24 13:48           ` Roger Quadros
2015-06-23 11:58 ` [PATCH 04/17] phy: omap-usb2: use omap_usb_power_off to power off the PHY during probe Kishon Vijay Abraham I
     [not found]   ` <1435060743-5511-5-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2015-06-24 10:58     ` Roger Quadros
2015-06-23 11:58 ` Kishon Vijay Abraham I [this message]
2015-06-24 11:39   ` [PATCH 07/17] usb: musb: omap2430: use *syscon* framework to write to mailbox register Roger Quadros
2015-06-24 13:21     ` Kishon Vijay Abraham I
     [not found]   ` <1435060743-5511-8-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2015-06-24 11:49     ` Tony Lindgren
     [not found]       ` <20150624114907.GF4156-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2015-06-24 13:06         ` Kishon Vijay Abraham I
2015-06-23 11:58 ` [PATCH 08/17] ARM: dts: dra7: Add dt node for the sycon pcie Kishon Vijay Abraham I
     [not found]   ` <1435060743-5511-9-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2015-06-24 11:50     ` Roger Quadros
2015-06-24 11:56       ` Roger Quadros
     [not found]         ` <20150624145617.e5248d466fe5b2e0eb1ca087-l0cyMroinI0@public.gmane.org>
2015-06-24 12:09           ` Tony Lindgren
     [not found]             ` <20150624120938.GG4156-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org>
2015-06-24 12:19               ` Roger Quadros
     [not found]                 ` <20150624151931.87252315d0e61ddfd55c4724-l0cyMroinI0@public.gmane.org>
2015-06-24 12:49                   ` Tony Lindgren
2015-06-24 13:30           ` Kishon Vijay Abraham I
2015-06-24 13:29       ` Kishon Vijay Abraham I
     [not found] ` <1435060743-5511-1-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2015-06-23 11:58   ` [PATCH 05/17] phy: omap-usb2: Add a new compatible string for USB2 PHY2 Kishon Vijay Abraham I
2015-06-24 11:03     ` Roger Quadros
     [not found]       ` <20150624140354.c3c1b0fc24dc37eae5097b4c-l0cyMroinI0@public.gmane.org>
2015-06-24 13:21         ` Kishon Vijay Abraham I
2015-06-23 11:58   ` [PATCH 06/17] phy: omap-usb2: use *syscon* framework to power on/off the PHY Kishon Vijay Abraham I
     [not found]     ` <1435060743-5511-7-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2015-06-24 11:33       ` Roger Quadros
2015-06-24 12:59         ` Kishon Vijay Abraham I
2015-06-23 11:58   ` [PATCH 09/17] ARM: dts: dra7: Use "syscon-phy-power" instead of "ctrl-module" in SATA PHY node Kishon Vijay Abraham I
2015-06-24 12:06     ` Roger Quadros
     [not found]       ` <20150624150602.0e73fc8f9dda1624f22059db-l0cyMroinI0@public.gmane.org>
2015-06-24 12:12         ` Roger Quadros
     [not found]           ` <20150624151257.fe5f1594db1afe4c1da8027d-l0cyMroinI0@public.gmane.org>
2015-06-24 13:31             ` Kishon Vijay Abraham I
2015-06-23 11:58   ` [PATCH 10/17] ARM: dts: dra7: Use "syscon-phy-power" and "syscon-pcs" in PCIe " Kishon Vijay Abraham I
2015-06-23 11:58   ` [PATCH 11/17] ARM: dts: dra7: Use "ti,dra7x-usb2-phy2" compatible string for USB2 PHY2 Kishon Vijay Abraham I
     [not found]     ` <1435060743-5511-12-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2015-06-24 12:07       ` Roger Quadros
     [not found]         ` <20150624150750.9435096c85253cfe528ebbc3-l0cyMroinI0@public.gmane.org>
2015-06-24 13:10           ` Kishon Vijay Abraham I
     [not found]             ` <558AAC47.2070305-l0cyMroinI0@public.gmane.org>
2015-06-24 13:50               ` Roger Quadros
2015-06-23 11:58   ` [PATCH 13/17] ARM: dts: am4372: Use "syscon-phy-power" instead of "ctrl-module" in USB PHY node Kishon Vijay Abraham I
2015-06-23 11:58   ` [PATCH 14/17] ARM: dts: OMAP5: " Kishon Vijay Abraham I
2015-06-23 11:59   ` [PATCH 16/17] ARM: dts: omap4: " Kishon Vijay Abraham I
2015-06-23 11:59   ` [PATCH 17/17] ARM: dts: omap4: Use "syscon-otghs" instead of "ctrl-module" in USB node Kishon Vijay Abraham I
     [not found]     ` <1435060743-5511-18-git-send-email-kishon-l0cyMroinI0@public.gmane.org>
2015-06-24 10:41       ` Tony Lindgren
2015-06-24 11:21         ` Kishon Vijay Abraham I
     [not found]           ` <558A92A5.5070506-l0cyMroinI0@public.gmane.org>
2015-06-24 11:46             ` Tony Lindgren
2015-06-24 12:02         ` Roger Quadros
2015-06-23 11:58 ` [PATCH 12/17] ARM: dts: dra7: Use "syscon-phy-power" instead of "ctrl-module" in USB PHY node Kishon Vijay Abraham I
2015-06-23 11:59 ` [PATCH 15/17] ARM: dts: OMAP5: Use "syscon-phy-power" instead of "ctrl-module" in SATA " Kishon Vijay Abraham I

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=1435060743-5511-8-git-send-email-kishon@ti.com \
    --to=kishon@ti.com \
    --cc=balbi@ti.com \
    --cc=bcousson@baylibre.com \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=nsekhar@ti.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=rogerq@ti.com \
    --cc=tony@atomide.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;
as well as URLs for NNTP newsgroup(s).