Skip to contentSkip to conversation

usb: musb: omap2430: use *syscon* framework API to write to mailbox register

PATCH In review Kishon Vijay Abraham I 3 participants 8 messages Aug 4, 2015 – Aug 21, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: musb: omap2430: use *syscon* framework API to write to mailbox register

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

---
 Documentation/devicetree/bindings/usb/omap-usb.txt |    7 +-
 drivers/usb/musb/omap2430.c                        |  115 ++++++++++++++++----
 2 files changed, 99 insertions(+), 23 deletions(-)
Documentation/devicetree/bindings/usb/omap-usb.txt +6 -1
index 38d9bb8..c001306 100644
@@ -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";
drivers/usb/musb/omap2430.c +93 -22

191 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

Hi,

Quoted 63 lines · Kishon Vijay Abraham I

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

---
 Documentation/devicetree/bindings/usb/omap-usb.txt |    7 +-
 drivers/usb/musb/omap2430.c                        |  115 ++++++++++++++++----
 2 files changed, 99 insertions(+), 23 deletions(-)
Documentation/devicetree/bindings/usb/omap-usb.txt +6 -1
index 38d9bb8..c001306 100644
@@ -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";
drivers/usb/musb/omap2430.c +11 -0
index 70f2b8a..a03cf1e 100644
@@ -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	BIT(0)
+#define OMAP2430_MUSB_BVALID	BIT(1)
+#define OMAP2430_MUSB_VBUSVALID	BIT(2)
+#define OMAP2430_MUSB_SESSEND	BIT(3)
+#define OMAP2430_MUSB_IDDIG	BIT(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)
 

drivers/usb/musb/omap2430.c void omap_musb_mailbox(enum omap_musb_vbus_id_status status) · line 272

Quoted 9 lines
drivers/usb/musb/omap2430.c +6 -0
@@ -253,6 +264,44 @@ 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) {
		omap_control_usb_set_mode(glue->control_otghs, mode);
		return;
	}

	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");
		dev_err(glue->dev, "Failed to set mode to %d\n", mode);
	}

	ret = regmap_update_bits(glue->syscon_otghs,
				 glue->otghs_reg,
				 OMAP2430_MUSB_MODE_MASK, val);
	if (ret < 0)
		dev_err(glue->dev, "Failed to update regmap\n");

other than that, looks fine.

Signature · 1 line
balbi
#3 lore raw
In reply to Kishon Vijay Abraham I
Quoted 2 lines · Kishon Vijay Abraham I

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

..

Quoted 27 lines
drivers/usb/musb/omap2430.c +23 -0
@@ -512,6 +558,40 @@ static const struct musb_platform_ops omap2430_ops = {
 
 static u64 omap2430_dmamask = DMA_BIT_MASK(32);
 
+static int omap2430_get_sys_ctrl(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_dbg(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 {

drivers/usb/musb/omap2430.c static const struct musb_platform_ops omap2430_ops = { · line 593

Quoted 10 lines
drivers/usb/musb/omap2430.c +10 -0
+		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;
+}

We don't have syscon-otghs and to me it seems we need a PHY driver as I pointed out at:

https://lkml.org/lkml/2015/6/24/231

So let's sort that issue first. It also seems this just completely breaks the MUSB support?

Regards,

Tony

#2 lore raw
In reply to Felipe Balbi

Hi,

Quoted 87 lines · Felipe Balbi

Hi,

Quoted 63 lines · Kishon Vijay Abraham I

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

---
 Documentation/devicetree/bindings/usb/omap-usb.txt |    7 +-
 drivers/usb/musb/omap2430.c                        |  115 ++++++++++++++++----
 2 files changed, 99 insertions(+), 23 deletions(-)
Documentation/devicetree/bindings/usb/omap-usb.txt +6 -1
index 38d9bb8..c001306 100644
@@ -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";
drivers/usb/musb/omap2430.c +11 -0
index 70f2b8a..a03cf1e 100644
@@ -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	BIT(0)
+#define OMAP2430_MUSB_BVALID	BIT(1)
+#define OMAP2430_MUSB_VBUSVALID	BIT(2)
+#define OMAP2430_MUSB_SESSEND	BIT(3)
+#define OMAP2430_MUSB_IDDIG	BIT(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)
 

drivers/usb/musb/omap2430.c void omap_musb_mailbox(enum omap_musb_vbus_id_status status) · line 272

Quoted 9 lines
drivers/usb/musb/omap2430.c +6 -0
@@ -253,6 +264,44 @@ 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) {
		omap_control_usb_set_mode(glue->control_otghs, mode);
		return;
	}

	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 |
Quoted 8 lines
			OMAP2430_MUSB_VBUSVALID;
		break;
	case USB_MODE_DISCONNECT:
		val = OMAP2430_MUSB_IDDIG | OMAP2430_MUSB_SESSEND;
		break;
	default:
		dev_dbg(glue->dev, "Invalid mode\n");
		dev_err(glue->dev, "Failed to set mode to %d\n", mode);

Don't we have to return here? Maybe we should set IDDIG and SESSEND (the same value as USB_MODE_DISCONNECT). That seems to be the reset value as well.

Quoted 7 lines
	}

	ret = regmap_update_bits(glue->syscon_otghs,
				 glue->otghs_reg,
				 OMAP2430_MUSB_MODE_MASK, val);
	if (ret < 0)
		dev_err(glue->dev, "Failed to update regmap\n");

Thanks
Kishon

#4 lore raw
In reply to Tony Lindgren

Hi Tony,

Quoted 36 lines · Tony Lindgren
Quoted 2 lines · Kishon Vijay Abraham I

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

..

Quoted 32 lines
drivers/usb/musb/omap2430.c +28 -0
@@ -512,6 +558,40 @@ static const struct musb_platform_ops omap2430_ops = {
 
 static u64 omap2430_dmamask = DMA_BIT_MASK(32);
 
+static int omap2430_get_sys_ctrl(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_dbg(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;
Quoted 8 lines

drivers/usb/musb/omap2430.c static const struct musb_platform_ops omap2430_ops = { · line 593

Quoted 5 lines
drivers/usb/musb/omap2430.c +5 -0
+		}
+	}
+
+	return 0;
+}

We don't have syscon-otghs and to me it seems we need a PHY driver as I pointed out at:

If *syscon-otghs* is not present, then it'll fall-back to using the *ctrl-module*.

Quoted 2 lines

https://lkml.org/lkml/2015/6/24/231

Maybe I should have explained this in the previous thread. The *otghs* register that we are trying to access here does _not_ belong to the PHY. It acts as mailbox register from MUSB glue (TI integration layer) to MUSB core. That's why it's programmed in the TI glue layer (omap2430.c).

Even when we were using the older API [omap_control_usb_set_mode()], we first call omap_musb_mailbox from the PHY drivers (phy-twl4030-usb.c, phy-twl6030-usb.c) and then omap_musb_mailbox in the TI glue writes to the control module instead of PHY drivers directly calling omap_control_usb_set_mode().

Quoted 3 lines

So let's sort that issue first. It also seems this just completely breaks the MUSB support?

Why do you think so? If *syscon-otghs* is not present in dt, then it'll fall-back to using the *ctrl-module* and everything should work seamlessly.

Thanks
Kishon
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 6 lines · Kishon Vijay Abraham I
Quoted 3 lines · Tony Lindgren

We don't have syscon-otghs and to me it seems we need a PHY driver as I pointed out at:

If *syscon-otghs* is not present, then it'll fall-back to using the *ctrl-module*.

OK great.

Quoted 8 lines
Quoted 2 lines

https://lkml.org/lkml/2015/6/24/231

Maybe I should have explained this in the previous thread. The *otghs* register that we are trying to access here does _not_ belong to the PHY. It acts as mailbox register from MUSB glue (TI integration layer) to MUSB core. That's why it's programmed in the TI glue layer (omap2430.c).

Quoted 4 lines

Even when we were using the older API [omap_control_usb_set_mode()], we first call omap_musb_mailbox from the PHY drivers (phy-twl4030-usb.c, phy-twl6030-usb.c) and then omap_musb_mailbox in the TI glue writes to the control module instead of PHY drivers directly calling omap_control_usb_set_mode().

Hmm looking at "Table 18-204. CONTROL_USBOTGHS_CONTROL" it seems to mention "transceiver" for quite a few bitfields :) Probably what that register does is control a PHY over ULPI.

So from Linux kernel point of view we're best off treating it as a PHY. It seems it should have a minimal PHY driver similar to what we have for dm816x control module in drivers/phy/phy-dm816x-usb.c.

For reference, here is the register bitfields pasted from 4460 TRM:

Table 18-204. CONTROL_USBOTGHS_CONTROL, p3972
Physical Address 0x4A00 233C

BIT NAME DESCIPTION
8 DISCHRGVBUS ... OTG transceiver does (not) discharge VBUS ...
7 CHRGVBUS ... OTG transceiver does (not) charge VBUS ...
6 IDPULLUP ... OTG transceiver does (not) drive VBUS ...
4 IDDIG ... OTG transceiver does (not) apply a pullup to ID ...
3 SESSEND ... VBUS voltage is above/below VB_SESS_END ...
2 VBUSVALID ... VBUS is above the threshold ...
1 BVALID ... VBUS voltage is above/below VB_SESS_VLD ...
0 AVALID ... BUS voltage is above/below VA_SESS_VLD ...

So how about just adding ONTROL_USBOTGHS_CONTROL support to the existing drivers/phy/phy-omap-usb2.c instead? It seems that it should allow us to completely get rid of the custom mailbox stuff for MUSB 2430 support?

Quoted 5 lines
Quoted 2 lines

So let's sort that issue first. It also seems this just completely breaks the MUSB support?

Why do you think so? If *syscon-otghs* is not present in dt, then it'll fall-back to using the *ctrl-module* and everything should work seamlessly.

OK that's good to hear. IMO drivers/phy/phy-omap4.c or similar should manage the syscon-otghs syscon register, not MUSB driver.

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

Hi,

Quoted 18 lines · Tony Lindgren
Quoted 6 lines · Kishon Vijay Abraham I
Quoted 3 lines · Tony Lindgren

We don't have syscon-otghs and to me it seems we need a PHY driver as I pointed out at:

If *syscon-otghs* is not present, then it'll fall-back to using the *ctrl-module*.

OK great.

Quoted 8 lines
Quoted 2 lines

https://lkml.org/lkml/2015/6/24/231

Maybe I should have explained this in the previous thread. The *otghs* register that we are trying to access here does _not_ belong to the PHY. It acts as mailbox register from MUSB glue (TI integration layer) to MUSB core. That's why it's programmed in the TI glue layer (omap2430.c).

Quoted 8 lines
Quoted 4 lines

Even when we were using the older API [omap_control_usb_set_mode()], we first call omap_musb_mailbox from the PHY drivers (phy-twl4030-usb.c, phy-twl6030-usb.c) and then omap_musb_mailbox in the TI glue writes to the control module instead of PHY drivers directly calling omap_control_usb_set_mode().

Hmm looking at "Table 18-204. CONTROL_USBOTGHS_CONTROL" it seems to mention "transceiver" for quite a few bitfields :) Probably what that register does is control a PHY over ULPI.

OMAP4 uses UTMI PHY and it uses CONTROL_USBOTGHS_CONTROL too.

Quoted 4 lines

So from Linux kernel point of view we're best off treating it as a PHY. It seems it should have a minimal PHY driver similar to what we have for dm816x control module in drivers/phy/phy-dm816x-usb.c.

hmm.. IMHO CONTROL_USBOTGHS_CONTROL register belongs to the TI MUSB glue and should be programmed in omap2430.c. It's better to get the opinion of Felipe here. Felipe?

Quoted 16 lines

For reference, here is the register bitfields pasted from 4460 TRM:

Table 18-204. CONTROL_USBOTGHS_CONTROL, p3972
Physical Address 0x4A00 233C

BIT NAME DESCIPTION
8 DISCHRGVBUS ... OTG transceiver does (not) discharge VBUS ...
7 CHRGVBUS ... OTG transceiver does (not) charge VBUS ...
6 IDPULLUP ... OTG transceiver does (not) drive VBUS ...
4 IDDIG ... OTG transceiver does (not) apply a pullup to ID ...
3 SESSEND ... VBUS voltage is above/below VB_SESS_END ...
2 VBUSVALID ... VBUS is above the threshold ...
1 BVALID ... VBUS voltage is above/below VB_SESS_VLD ...
0 AVALID ... BUS voltage is above/below VA_SESS_VLD ...

Quoted 3 lines

So how about just adding ONTROL_USBOTGHS_CONTROL support to the existing drivers/phy/phy-omap-usb2.c instead? It seems that it should allow us to completely get rid of the custom mailbox stuff for MUSB 2430 support?

Not in phy-omap-usb2.c. It's the UTMI PHY driver and is not used by OMAP3 based boards (uses twl4030 ULPI PHY). CONTROL_USBOTGHS_CONTROL has to be programmed for OMAP3 also.

Thanks
Kishon

#7 lore raw
Quoted 26 lines · Kishon Vijay Abraham I

Hi,

Quoted 23 lines · Tony Lindgren
Quoted 6 lines · Kishon Vijay Abraham I
Quoted 3 lines · Tony Lindgren

We don't have syscon-otghs and to me it seems we need a PHY driver as I pointed out at:

If *syscon-otghs* is not present, then it'll fall-back to using the *ctrl-module*.

OK great.

Quoted 12 lines
Quoted 2 lines

https://lkml.org/lkml/2015/6/24/231

Maybe I should have explained this in the previous thread. The *otghs* register that we are trying to access here does _not_ belong to the PHY. It acts as mailbox register from MUSB glue (TI integration layer) to MUSB core. That's why it's programmed in the TI glue layer (omap2430.c).

Even when we were using the older API [omap_control_usb_set_mode()], we first call omap_musb_mailbox from the PHY drivers (phy-twl4030-usb.c, phy-twl6030-usb.c) and then omap_musb_mailbox in the TI glue writes to the control module instead of PHY drivers directly calling omap_control_usb_set_mode().

Quoted 5 lines
Quoted 3 lines

Hmm looking at "Table 18-204. CONTROL_USBOTGHS_CONTROL" it seems to mention "transceiver" for quite a few bitfields :) Probably what that register does is control a PHY over ULPI.

OMAP4 uses UTMI PHY and it uses CONTROL_USBOTGHS_CONTROL too.

So can't we make the phy-omap-usb2.c driver the onlly user of this register then and get rid of the mailbox stuff? I think the phy framework can handle everything now?

Quoted 23 lines
Quoted 3 lines

So from Linux kernel point of view we're best off treating it as a PHY. It seems it should have a minimal PHY driver similar to what we have for dm816x control module in drivers/phy/phy-dm816x-usb.c.

hmm.. IMHO CONTROL_USBOTGHS_CONTROL register belongs to the TI MUSB glue and should be programmed in omap2430.c. It's better to get the opinion of Felipe here. Felipe?

Quoted 16 lines

For reference, here is the register bitfields pasted from 4460 TRM:

Table 18-204. CONTROL_USBOTGHS_CONTROL, p3972
Physical Address 0x4A00 233C

BIT NAME DESCIPTION
8 DISCHRGVBUS ... OTG transceiver does (not) discharge VBUS ...
7 CHRGVBUS ... OTG transceiver does (not) charge VBUS ...
6 IDPULLUP ... OTG transceiver does (not) drive VBUS ...
4 IDDIG ... OTG transceiver does (not) apply a pullup to ID ...
3 SESSEND ... VBUS voltage is above/below VB_SESS_END ...
2 VBUSVALID ... VBUS is above the threshold ...
1 BVALID ... VBUS voltage is above/below VB_SESS_VLD ...
0 AVALID ... BUS voltage is above/below VA_SESS_VLD ...

Quoted 7 lines
Quoted 3 lines

So how about just adding ONTROL_USBOTGHS_CONTROL support to the existing drivers/phy/phy-omap-usb2.c instead? It seems that it should allow us to completely get rid of the custom mailbox stuff for MUSB 2430 support?

Not in phy-omap-usb2.c. It's the UTMI PHY driver and is not used by OMAP3 based boards (uses twl4030 ULPI PHY). CONTROL_USBOTGHS_CONTROL has to be programmed for OMAP3 also.

Hmm I don't think omap3 uses that register? There's no ti,control-phy anything in the omap3 dts files? And no USBOTGHS_CONTROL in the TRM? Or am I missing something here?

Regards,

Tony