Skip to contentSkip to conversation

doc: usb: usbmisc-imx: add imx7d compatible string

PATCH New Li Jun 4 participants 12 messages Jul 18, 2016 – Jul 20, 2016

Subsystems (4)
lore
Share & tools
lore

Li Jun

author
#0 lore raw

PATCH 1/4 doc: usb: usbmisc-imx: add imx7d compatible string

Add compatible string for imx7d-usbmisc.

---
 Documentation/devicetree/bindings/usb/usbmisc-imx.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/usb/usbmisc-imx.txt +1 -0
index 3539d4e..f1e27fa 100644
@@ -6,6 +6,7 @@ Required properties:
 	"fsl,imx6q-usbmisc" for imx6q
 	"fsl,vf610-usbmisc" for Vybrid vf610
 	"fsl,imx6sx-usbmisc" for imx6sx
+	"fsl,imx7d-usbmisc" for imx7d
 - reg: Should contain registers location and length
 
 Examples:
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 2/4 doc: usb: ci-hdrc-usb2: add property over-current-polarity

Adding over-current-polarity to indicate the over current flag is low active or high active.

---
 Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +2 -0
index 341dc67..c5d35f4 100644
@@ -81,6 +81,8 @@ i.mx specific properties
 - fsl,usbmisc: phandler of non-core register device, with one
   argument that indicate usb controller index
 - disable-over-current: disable over current detect
+- over-current-polarity: 0 if the over current signal polarity is low active,
+  1 if the over current signal polarity is high active.
 - external-vbus-divider: enables off-chip resistor divider for Vbus
 
 Example:
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/4 doc: usb: ci-hdrc-usb2: add property over-current-polarity

Greetings,

Quoted 13 lines · Li Jun

Adding over-current-polarity to indicate the over current flag is low active or high active.

---
 Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +0 -0
index 341dc67..c5d35f4 100644

Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt i.mx specific properties · line 88

Quoted 8 lines
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +2 -0
@@ -81,6 +81,8 @@ i.mx specific properties
 - fsl,usbmisc: phandler of non-core register device, with one
   argument that indicate usb controller index
 - disable-over-current: disable over current detect
+- over-current-polarity: 0 if the over current signal polarity is low active,
+  1 if the over current signal polarity is high active.
 - external-vbus-divider: enables off-chip resistor divider for Vbus
 
 Example:

The gpio device bindings already have active low/ active high. Could that be used here?

In the imx SPI subsystem, for instance, the developers used gpio rather than MUXED spi chipselect lines for exactly this kind of flexibility.

If there is no magic happening in silicon (which would seem to be the case if we can handle inverting polarity in the driver), I would suggest going the gpiod route.

Thanks,
Joshua

#3 lore raw

PATCH 2/4 doc: usb: ci-hdrc-usb2: add property over-current-polarity

Quoted 22 lines · Joshua Clayton

Greetings,

Quoted 20 lines · Li Jun

Adding over-current-polarity to indicate the over current flag is low active or high active.

---
 Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +2 -0
index 341dc67..c5d35f4 100644
@@ -81,6 +81,8 @@ i.mx specific properties
 - fsl,usbmisc: phandler of non-core register device, with one
   argument that indicate usb controller index
 - disable-over-current: disable over current detect
+- over-current-polarity: 0 if the over current signal polarity is low active,
+  1 if the over current signal polarity is high active.
 - external-vbus-divider: enables off-chip resistor divider for Vbus
 
Quoted 4 lines

Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt i.mx specific properties · line 88

Quoted 1 line
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +0 -0
 Example:

The gpio device bindings already have active low/ active high. Could that be used here?

No, the over current pin is a dedicated pin for USB, you need to configure it through pinmux. If we are using a gpio (even the same pin as OC pin), the USB subsystem will not know OC event. The polarity is for OC pin and configured through USB register.

Quoted 6 lines

In the imx SPI subsystem, for instance, the developers used gpio rather than MUXED spi chipselect lines for exactly this kind of flexibility.

If there is no magic happening in silicon (which would seem to be the case if we can handle inverting polarity in the driver), I would suggest going the gpiod route.

Signature · 2 lines
Best Regards,
Peter Chen
author
#4 lore raw

PATCH 2/4 doc: usb: ci-hdrc-usb2: add property over-current-polarity

Hi,

Quoted 40 lines

-----Original Message-----
From: Peter Chen [mailto:hzpeterchen at gmail.com]
Sent: Tuesday, July 19, 2016 9:47 AM
To: Joshua Clayton <[email protected]>
Cc: Jun Li <[email protected]>; Peter Chen <[email protected]>; robh+dt at kernel.org; shawnguo at kernel.org; devicetree at vger.kernel.org; linux-usb at vger.kernel.org; linux-arm-kernel at lists.infradead.org
Subject: Re: [PATCH 2/4] doc: usb: ci-hdrc-usb2: add property over- current-polarity

Quoted 24 lines · Joshua Clayton

Greetings,

Quoted 22 lines · Li Jun

Adding over-current-polarity to indicate the over current flag is low active or high active.

---
 Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +3 -0
index 341dc67..c5d35f4 100644
@@ -81,6 +81,8 @@ i.mx specific properties
 - fsl,usbmisc: phandler of non-core register device, with one
   argument that indicate usb controller index
 - disable-over-current: disable over current detect
+- over-current-polarity: 0 if the over current signal polarity is
+low active,
+  1 if the over current signal polarity is high active.
 - external-vbus-divider: enables off-chip resistor divider for Vbus
 
Quoted 4 lines
Quoted 1 line

Example:

The gpio device bindings already have active low/ active high. Could that be used here?

Quoted 4 lines

No, the over current pin is a dedicated pin for USB, you need to configure it through pinmux. If we are using a gpio (even the same pin as OC pin), the USB subsystem will not know OC event. The polarity is for OC pin and configured through USB register.

Agree with Peter, there is do have magic in silicon of usb controller, which is part of ehci spec so ehci host driver can take care of it as a standard usb event.

Quoted 4 lines
Quoted 3 lines

In the imx SPI subsystem, for instance, the developers used gpio rather than MUXED spi chipselect lines for exactly this kind of

flexibility.

I guess your SPI example is not a normal usage, but by that way to workaround some silicon issue.

Li Jun

Quoted 10 lines
Quoted 3 lines

If there is no magic happening in silicon (which would seem to be the case if we can handle inverting polarity in the driver), I would suggest

going the gpiod route.

Quoted 1 line

--

Best Regards,
Peter Chen

maintainer
#5 lore raw

PATCH 2/4 doc: usb: ci-hdrc-usb2: add property over-current-polarity

In reply to Li Jun
Quoted 13 lines · Li Jun

Adding over-current-polarity to indicate the over current flag is low active or high active.

---
 Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +0 -0
index 341dc67..c5d35f4 100644

Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt i.mx specific properties · line 85

Quoted 5 lines
Documentation/devicetree/bindings/usb/ci-hdrc-usb2.txt +2 -0
@@ -81,6 +81,8 @@ i.mx specific properties
 - fsl,usbmisc: phandler of non-core register device, with one
   argument that indicate usb controller index
 - disable-over-current: disable over current detect
+- over-current-polarity: 0 if the over current signal polarity is low active,
+  1 if the over current signal polarity is high active.

Make the common case be no property and make this bool. So if typically active high, the property is "over-current-active-low".

Rob

author
#6 lore raw

PATCH 3/4 ARM: dts: imx7d-sdb: Set OTG2 oc polarity to be active low

In reply to Li Jun

Set OTG2 over current flag to be active low, OTG1 OC is not used by default.

---
 arch/arm/boot/dts/imx7d-sdb.dts | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm/boot/dts/imx7d-sdb.dts +8 -0
index b267f79..44ed399 100644
@@ -287,7 +287,9 @@
 
 &usbotg2 {
 	vbus-supply = <&reg_usb_otg2_vbus>;
+	pinctrl-0 = <&pinctrl_usbotg2>;
 	dr_mode = "host";
+	over-current-polarity = <0>;
 	status = "okay";
 };
 
@@ -415,6 +417,12 @@
 			>;
 		};
 
+		pinctrl_usbotg2: usbotg2grp {
+			fsl,pins = <
+				MX7D_PAD_GPIO1_IO06__USB_OTG2_OC	0x59
+			>;
+		};
+
 		pinctrl_usdhc1: usdhc1grp {
 			fsl,pins = <
 				MX7D_PAD_SD1_CMD__SD1_CMD		0x59
Signature · 1 line
1.9.1
author
#7 lore raw

PATCH 4/4 usb: chipidea: imx: set over current polarity per dts setting

In reply to Li Jun

With over-current-polarity property added, imx usb over current polarity can be configed to be low or high active, since the default setting value(0) is for active high, so keep this setting for those legacy platforms without this property specified.

---
 drivers/usb/chipidea/ci_hdrc_imx.c |  9 +++++++++
 drivers/usb/chipidea/ci_hdrc_imx.h |  1 +
 drivers/usb/chipidea/usbmisc_imx.c | 30 +++++++++++++++++++++++++-----
 3 files changed, 35 insertions(+), 5 deletions(-)
drivers/usb/chipidea/ci_hdrc_imx.c +9 -0
index dedc33e..61e712b 100644
@@ -140,6 +140,15 @@ static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev)
 	if (of_find_property(np, "disable-over-current", NULL))
 		data->disable_oc = 1;
 
+	if (!of_property_read_u32(np, "over-current-polarity", &ret))
+		data->oc_polarity = ret ? 1 : 0;
+	else
+		/*
+		 * Keep the oc polarity setting of legacy
+		 * platforms unchanged.
+		 */
+		data->oc_polarity = 1;
+
 	if (of_find_property(np, "external-vbus-divider", NULL))
 		data->evdo = 1;
 
drivers/usb/chipidea/ci_hdrc_imx.h +1 -0
index 635717e..409aa5ca8 100644
@@ -17,6 +17,7 @@ struct imx_usbmisc_data {
 	int index;
 
 	unsigned int disable_oc:1; /* over current detect disabled */
+	unsigned int oc_polarity:1; /* over current polarity if oc enabled */
 	unsigned int evdo:1; /* set external vbus divider option */
 };
 
drivers/usb/chipidea/usbmisc_imx.c +25 -5
index ab8b027..193dbe4 100644
@@ -56,6 +56,7 @@
 
 #define MX6_BM_NON_BURST_SETTING	BIT(1)
 #define MX6_BM_OVER_CUR_DIS		BIT(7)
+#define MX6_BM_OVER_CUR_POLARITY	BIT(8)
 #define MX6_BM_WAKEUP_ENABLE		BIT(10)
 #define MX6_BM_ID_WAKEUP		BIT(16)
 #define MX6_BM_VBUS_WAKEUP		BIT(17)
@@ -266,11 +267,18 @@ static int usbmisc_imx6q_init(struct imx_usbmisc_data *data)
 
 	spin_lock_irqsave(&usbmisc->lock, flags);
 
+	reg = readl(usbmisc->base + data->index * 4);
 	if (data->disable_oc) {
-		reg = readl(usbmisc->base + data->index * 4);
-		writel(reg | MX6_BM_OVER_CUR_DIS,
-			usbmisc->base + data->index * 4);
+		reg |= MX6_BM_OVER_CUR_DIS;
+	} else if (data->oc_polarity == 1) {
+		/* High active */
+		reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY);
+	} else {
+		/* Low active */
+		reg &= ~MX6_BM_OVER_CUR_DIS;
+		reg |= MX6_BM_OVER_CUR_POLARITY;
 	}
+	writel(reg, usbmisc->base + data->index * 4);
 
 	/* SoC non-burst setting */
 	reg = readl(usbmisc->base + data->index * 4);
@@ -365,10 +373,18 @@ static int usbmisc_imx7d_init(struct imx_usbmisc_data *data)
 		return -EINVAL;
 
 	spin_lock_irqsave(&usbmisc->lock, flags);
+	reg = readl(usbmisc->base);
 	if (data->disable_oc) {
-		reg = readl(usbmisc->base);
-		writel(reg | MX6_BM_OVER_CUR_DIS, usbmisc->base);
+		reg |= MX6_BM_OVER_CUR_DIS;
+	} else if (data->oc_polarity == 1) {
+		/* High active */
+		reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY);
+	} else {
+		/* Low active */
+		reg &= ~MX6_BM_OVER_CUR_DIS;
+		reg |= MX6_BM_OVER_CUR_POLARITY;
 	}
+	writel(reg, usbmisc->base);
 
 	reg = readl(usbmisc->base + MX7D_USBNC_USB_CTRL2);
 	reg &= ~MX7D_USB_VBUS_WAKEUP_SOURCE_MASK;
@@ -492,6 +508,10 @@ static const struct of_device_id usbmisc_imx_dt_ids[] = {
 		.compatible = "fsl,imx6ul-usbmisc",
 		.data = &imx6sx_usbmisc_ops,
 	},
+	{
+		.compatible = "fsl,imx7d-usbmisc",
+		.data = &imx7d_usbmisc_ops,
+	},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids);
Signature · 1 line
1.9.1
#8 lore raw

PATCH 4/4 usb: chipidea: imx: set over current polarity per dts setting

Quoted 18 lines · Li Jun

With over-current-polarity property added, imx usb over current polarity can be configed to be low or high active, since the default setting value(0) is for active high, so keep this setting for those legacy platforms without this property specified.

---
 drivers/usb/chipidea/ci_hdrc_imx.c |  9 +++++++++
 drivers/usb/chipidea/ci_hdrc_imx.h |  1 +
 drivers/usb/chipidea/usbmisc_imx.c | 30 +++++++++++++++++++++++++-----
 3 files changed, 35 insertions(+), 5 deletions(-)
drivers/usb/chipidea/ci_hdrc_imx.c +0 -0
index dedc33e..61e712b 100644
@@ -140,6 +140,15 @@ static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev)
 	if (of_find_property(np, "disable-over-current", NULL))

drivers/usb/chipidea/ci_hdrc_imx.c static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev) · line 150

Quoted 10 lines
drivers/usb/chipidea/ci_hdrc_imx.c +8 -0
 		data->disable_oc = 1;
 
+	if (!of_property_read_u32(np, "over-current-polarity", &ret))
+		data->oc_polarity = ret ? 1 : 0;
+	else
+		/*
+		 * Keep the oc polarity setting of legacy
+		 * platforms unchanged.
+		 */
+		data->oc_polarity = 1;

We may can't ensure that, since there are lots of i.mx platforms, eg from imx27 to imx7.

If the user does not assign oc polarity at DT, we need to read it from register.

Peter

Quoted 90 lines
drivers/usb/chipidea/ci_hdrc_imx.c +1 -0
+
 	if (of_find_property(np, "external-vbus-divider", NULL))
 		data->evdo = 1;
 
drivers/usb/chipidea/ci_hdrc_imx.h +1 -0
index 635717e..409aa5ca8 100644
@@ -17,6 +17,7 @@ struct imx_usbmisc_data {
 	int index;
 
 	unsigned int disable_oc:1; /* over current detect disabled */
+	unsigned int oc_polarity:1; /* over current polarity if oc enabled */
 	unsigned int evdo:1; /* set external vbus divider option */
 };
 
drivers/usb/chipidea/usbmisc_imx.c +25 -5
index ab8b027..193dbe4 100644
@@ -56,6 +56,7 @@
 
 #define MX6_BM_NON_BURST_SETTING	BIT(1)
 #define MX6_BM_OVER_CUR_DIS		BIT(7)
+#define MX6_BM_OVER_CUR_POLARITY	BIT(8)
 #define MX6_BM_WAKEUP_ENABLE		BIT(10)
 #define MX6_BM_ID_WAKEUP		BIT(16)
 #define MX6_BM_VBUS_WAKEUP		BIT(17)
@@ -266,11 +267,18 @@ static int usbmisc_imx6q_init(struct imx_usbmisc_data *data)
 
 	spin_lock_irqsave(&usbmisc->lock, flags);
 
+	reg = readl(usbmisc->base + data->index * 4);
 	if (data->disable_oc) {
-		reg = readl(usbmisc->base + data->index * 4);
-		writel(reg | MX6_BM_OVER_CUR_DIS,
-			usbmisc->base + data->index * 4);
+		reg |= MX6_BM_OVER_CUR_DIS;
+	} else if (data->oc_polarity == 1) {
+		/* High active */
+		reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY);
+	} else {
+		/* Low active */
+		reg &= ~MX6_BM_OVER_CUR_DIS;
+		reg |= MX6_BM_OVER_CUR_POLARITY;
 	}
+	writel(reg, usbmisc->base + data->index * 4);
 
 	/* SoC non-burst setting */
 	reg = readl(usbmisc->base + data->index * 4);
@@ -365,10 +373,18 @@ static int usbmisc_imx7d_init(struct imx_usbmisc_data *data)
 		return -EINVAL;
 
 	spin_lock_irqsave(&usbmisc->lock, flags);
+	reg = readl(usbmisc->base);
 	if (data->disable_oc) {
-		reg = readl(usbmisc->base);
-		writel(reg | MX6_BM_OVER_CUR_DIS, usbmisc->base);
+		reg |= MX6_BM_OVER_CUR_DIS;
+	} else if (data->oc_polarity == 1) {
+		/* High active */
+		reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY);
+	} else {
+		/* Low active */
+		reg &= ~MX6_BM_OVER_CUR_DIS;
+		reg |= MX6_BM_OVER_CUR_POLARITY;
 	}
+	writel(reg, usbmisc->base);
 
 	reg = readl(usbmisc->base + MX7D_USBNC_USB_CTRL2);
 	reg &= ~MX7D_USB_VBUS_WAKEUP_SOURCE_MASK;
@@ -492,6 +508,10 @@ static const struct of_device_id usbmisc_imx_dt_ids[] = {
 		.compatible = "fsl,imx6ul-usbmisc",
 		.data = &imx6sx_usbmisc_ops,
 	},
+	{
+		.compatible = "fsl,imx7d-usbmisc",
+		.data = &imx7d_usbmisc_ops,
+	},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids);
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 2 lines
Best Regards,
Peter Chen
author
#9 lore raw

PATCH 4/4 usb: chipidea: imx: set over current polarity per dts setting

Hi

Quoted 45 lines

-----Original Message-----
From: Peter Chen [mailto:hzpeterchen at gmail.com]
Sent: Tuesday, July 19, 2016 9:57 AM
To: Jun Li <[email protected]>
Cc: Peter Chen <[email protected]>; robh+dt at kernel.org;
shawnguo at kernel.org; devicetree at vger.kernel.org; linux-usb at vger.kernel.org; linux-arm-kernel at lists.infradead.org
Subject: Re: [PATCH 4/4] usb: chipidea: imx: set over current polarity per dts setting

drivers/usb/chipidea/ci_hdrc_imx.c static struct imx_usbmisc_data

Quoted 18 lines · Li Jun

With over-current-polarity property added, imx usb over current polarity can be configed to be low or high active, since the default setting value(0) is for active high, so keep this setting for those legacy platforms without this property specified.

---
 drivers/usb/chipidea/ci_hdrc_imx.c |  9 +++++++++
drivers/usb/chipidea/ci_hdrc_imx.h |  1 +
drivers/usb/chipidea/usbmisc_imx.c | 30 +++++++++++++++++++++++++-----
 3 files changed, 35 insertions(+), 5 deletions(-)
drivers/usb/chipidea/ci_hdrc_imx.c +0 -0
index dedc33e..61e712b 100644
@@ -140,6 +140,15 @@ static struct imx_usbmisc_data

*usbmisc_get_init_data(struct device *dev)

drivers/usb/chipidea/ci_hdrc_imx.c static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev) · line 150

Quoted 11 lines
drivers/usb/chipidea/ci_hdrc_imx.c +8 -0
 	if (of_find_property(np, "disable-over-current", NULL))
 		data->disable_oc = 1;
 
+	if (!of_property_read_u32(np, "over-current-polarity", &ret))
+		data->oc_polarity = ret ? 1 : 0;
+	else
+		/*
+		 * Keep the oc polarity setting of legacy
+		 * platforms unchanged.
+		 */
+		data->oc_polarity = 1;

We may can't ensure that, since there are lots of i.mx platforms, eg from imx27 to imx7.

Quoted 2 lines

If the user does not assign oc polarity at DT, we need to read it from register.

I suppose old platforms (other than i.mx6&7) should set either "over-current-polarity" or "disable-over-current" if want to use "data->oc_polarity".

Do you mean read the register value before set "data->oc_polarity" here? Even with that, as I still can't ensure all i.mx platforms have the same mapping:
0 <--> active high.
1 <--> active low.
How should I set "data->oc_polarity" accordingly?

Li Jun

Quoted 101 lines

Peter

drivers/usb/chipidea/usbmisc_imx.c static const struct of_device_id

Quoted 75 lines
drivers/usb/chipidea/ci_hdrc_imx.c +1 -0
+
 	if (of_find_property(np, "external-vbus-divider", NULL))
 		data->evdo = 1;
 
drivers/usb/chipidea/ci_hdrc_imx.h +2 -0
index 635717e..409aa5ca8 100644
@@ -17,6 +17,7 @@ struct imx_usbmisc_data {
 	int index;
 
 	unsigned int disable_oc:1; /* over current detect disabled */
+	unsigned int oc_polarity:1; /* over current polarity if oc enabled
+*/
 	unsigned int evdo:1; /* set external vbus divider option */  };
 
drivers/usb/chipidea/usbmisc_imx.c +11 -3
index ab8b027..193dbe4 100644
@@ -56,6 +56,7 @@
 
 #define MX6_BM_NON_BURST_SETTING	BIT(1)
 #define MX6_BM_OVER_CUR_DIS		BIT(7)
+#define MX6_BM_OVER_CUR_POLARITY	BIT(8)
 #define MX6_BM_WAKEUP_ENABLE		BIT(10)
 #define MX6_BM_ID_WAKEUP		BIT(16)
 #define MX6_BM_VBUS_WAKEUP		BIT(17)
@@ -266,11 +267,18 @@ static int usbmisc_imx6q_init(struct
 imx_usbmisc_data *data)
 
 	spin_lock_irqsave(&usbmisc->lock, flags);
 
+	reg = readl(usbmisc->base + data->index * 4);
 	if (data->disable_oc) {
-		reg = readl(usbmisc->base + data->index * 4);
-		writel(reg | MX6_BM_OVER_CUR_DIS,
-			usbmisc->base + data->index * 4);
+		reg |= MX6_BM_OVER_CUR_DIS;
+	} else if (data->oc_polarity == 1) {
+		/* High active */
+		reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY);
+	} else {
+		/* Low active */
+		reg &= ~MX6_BM_OVER_CUR_DIS;
+		reg |= MX6_BM_OVER_CUR_POLARITY;
 	}
+	writel(reg, usbmisc->base + data->index * 4);
 
 	/* SoC non-burst setting */

reg = readl(usbmisc->base + data->index * 4); @@ -365,10 +373,18 @@
static int usbmisc_imx7d_init(struct imx_usbmisc_data *data)

drivers/usb/chipidea/usbmisc_imx.c +10 -2
 		return -EINVAL;
 
 	spin_lock_irqsave(&usbmisc->lock, flags);
+	reg = readl(usbmisc->base);
 	if (data->disable_oc) {
-		reg = readl(usbmisc->base);
-		writel(reg | MX6_BM_OVER_CUR_DIS, usbmisc->base);
+		reg |= MX6_BM_OVER_CUR_DIS;
+	} else if (data->oc_polarity == 1) {
+		/* High active */
+		reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY);
+	} else {
+		/* Low active */
+		reg &= ~MX6_BM_OVER_CUR_DIS;
+		reg |= MX6_BM_OVER_CUR_POLARITY;
 	}
+	writel(reg, usbmisc->base);
 
 	reg = readl(usbmisc->base + MX7D_USBNC_USB_CTRL2);
 	reg &= ~MX7D_USB_VBUS_WAKEUP_SOURCE_MASK;
@@ -492,6 +508,10 @@ static const struct of_device_id

usbmisc_imx_dt_ids[] = {

Quoted 14 lines
drivers/usb/chipidea/usbmisc_imx.c +4 -1
 		.compatible = "fsl,imx6ul-usbmisc",
 		.data = &imx6sx_usbmisc_ops,
 	},
+	{
+		.compatible = "fsl,imx7d-usbmisc",
+		.data = &imx7d_usbmisc_ops,
+	},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids);
--

1.9.1

Quoted 4 lines

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

--

Best Regards,
Peter Chen

#10 lore raw

PATCH 4/4 usb: chipidea: imx: set over current polarity per dts setting

Quoted 47 lines · Jun Li

Hi

Quoted 45 lines

-----Original Message-----
From: Peter Chen [mailto:hzpeterchen at gmail.com]
Sent: Tuesday, July 19, 2016 9:57 AM
To: Jun Li <[email protected]>
Cc: Peter Chen <[email protected]>; robh+dt at kernel.org;
shawnguo at kernel.org; devicetree at vger.kernel.org; linux-usb at vger.kernel.org; linux-arm-kernel at lists.infradead.org
Subject: Re: [PATCH 4/4] usb: chipidea: imx: set over current polarity per dts setting

drivers/usb/chipidea/ci_hdrc_imx.c static struct imx_usbmisc_data

Quoted 18 lines · Li Jun

With over-current-polarity property added, imx usb over current polarity can be configed to be low or high active, since the default setting value(0) is for active high, so keep this setting for those legacy platforms without this property specified.

---
 drivers/usb/chipidea/ci_hdrc_imx.c |  9 +++++++++
drivers/usb/chipidea/ci_hdrc_imx.h |  1 +
drivers/usb/chipidea/usbmisc_imx.c | 30 +++++++++++++++++++++++++-----
 3 files changed, 35 insertions(+), 5 deletions(-)
drivers/usb/chipidea/ci_hdrc_imx.c +0 -0
index dedc33e..61e712b 100644
@@ -140,6 +140,15 @@ static struct imx_usbmisc_data

*usbmisc_get_init_data(struct device *dev)

drivers/usb/chipidea/ci_hdrc_imx.c static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev) · line 150

Quoted 11 lines
drivers/usb/chipidea/ci_hdrc_imx.c +8 -0
 	if (of_find_property(np, "disable-over-current", NULL))
 		data->disable_oc = 1;
 
+	if (!of_property_read_u32(np, "over-current-polarity", &ret))
+		data->oc_polarity = ret ? 1 : 0;
+	else
+		/*
+		 * Keep the oc polarity setting of legacy
+		 * platforms unchanged.
+		 */
+		data->oc_polarity = 1;

We may can't ensure that, since there are lots of i.mx platforms, eg from imx27 to imx7.

Quoted 7 lines
Quoted 2 lines

If the user does not assign oc polarity at DT, we need to read it from register.

I suppose old platforms (other than i.mx6&7) should set either "over-current-polarity" or "disable-over-current" if want to use "data->oc_polarity".

The user may use old dtb and the latest kernel, so the introduced DT property should not affect old dtb platforms.

Quoted 1 line

Do you mean read the register value before set "data->oc_polarity" here?

yes, if there is a dts property, read it from DT; else, read it from the register.

if (!of_property_read_u32(np, "over-current-polarity", &ret))

	data->oc_polarity = ret ? 1 : 0;
else
	/*
	 * Keep the oc polarity setting of legacy
	 * platforms unchanged.
	 */
	data->oc_polarity = readl(oc_polarity);

Then, when you set register for oc polarity, you can depend on the flag.

	reg = readl(usbmisc->base + data->index * 4);
	value = data->oc_polarity ? MX6_BM_OVER_CUR_POLARITY : 0;
	writel(reg | value, usbmisc->base + data->index * 4);
Quoted 5 lines

Even with that, as I still can't ensure all i.mx platforms have the same mapping:
0 <--> active high.
1 <--> active low.
How should I set "data->oc_polarity" accordingly?

Just keep current register value unchanging if there is no dts property.

Peter

Quoted 102 lines

Li Jun

Quoted 101 lines

Peter

drivers/usb/chipidea/usbmisc_imx.c static const struct of_device_id

Quoted 75 lines
drivers/usb/chipidea/ci_hdrc_imx.c +1 -0
+
 	if (of_find_property(np, "external-vbus-divider", NULL))
 		data->evdo = 1;
 
drivers/usb/chipidea/ci_hdrc_imx.h +2 -0
index 635717e..409aa5ca8 100644
@@ -17,6 +17,7 @@ struct imx_usbmisc_data {
 	int index;
 
 	unsigned int disable_oc:1; /* over current detect disabled */
+	unsigned int oc_polarity:1; /* over current polarity if oc enabled
+*/
 	unsigned int evdo:1; /* set external vbus divider option */  };
 
drivers/usb/chipidea/usbmisc_imx.c +11 -3
index ab8b027..193dbe4 100644
@@ -56,6 +56,7 @@
 
 #define MX6_BM_NON_BURST_SETTING	BIT(1)
 #define MX6_BM_OVER_CUR_DIS		BIT(7)
+#define MX6_BM_OVER_CUR_POLARITY	BIT(8)
 #define MX6_BM_WAKEUP_ENABLE		BIT(10)
 #define MX6_BM_ID_WAKEUP		BIT(16)
 #define MX6_BM_VBUS_WAKEUP		BIT(17)
@@ -266,11 +267,18 @@ static int usbmisc_imx6q_init(struct
 imx_usbmisc_data *data)
 
 	spin_lock_irqsave(&usbmisc->lock, flags);
 
+	reg = readl(usbmisc->base + data->index * 4);
 	if (data->disable_oc) {
-		reg = readl(usbmisc->base + data->index * 4);
-		writel(reg | MX6_BM_OVER_CUR_DIS,
-			usbmisc->base + data->index * 4);
+		reg |= MX6_BM_OVER_CUR_DIS;
+	} else if (data->oc_polarity == 1) {
+		/* High active */
+		reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY);
+	} else {
+		/* Low active */
+		reg &= ~MX6_BM_OVER_CUR_DIS;
+		reg |= MX6_BM_OVER_CUR_POLARITY;
 	}
+	writel(reg, usbmisc->base + data->index * 4);
 
 	/* SoC non-burst setting */

reg = readl(usbmisc->base + data->index * 4); @@ -365,10 +373,18 @@
static int usbmisc_imx7d_init(struct imx_usbmisc_data *data)

drivers/usb/chipidea/usbmisc_imx.c +10 -2
 		return -EINVAL;
 
 	spin_lock_irqsave(&usbmisc->lock, flags);
+	reg = readl(usbmisc->base);
 	if (data->disable_oc) {
-		reg = readl(usbmisc->base);
-		writel(reg | MX6_BM_OVER_CUR_DIS, usbmisc->base);
+		reg |= MX6_BM_OVER_CUR_DIS;
+	} else if (data->oc_polarity == 1) {
+		/* High active */
+		reg &= ~(MX6_BM_OVER_CUR_DIS | MX6_BM_OVER_CUR_POLARITY);
+	} else {
+		/* Low active */
+		reg &= ~MX6_BM_OVER_CUR_DIS;
+		reg |= MX6_BM_OVER_CUR_POLARITY;
 	}
+	writel(reg, usbmisc->base);
 
 	reg = readl(usbmisc->base + MX7D_USBNC_USB_CTRL2);
 	reg &= ~MX7D_USB_VBUS_WAKEUP_SOURCE_MASK;
@@ -492,6 +508,10 @@ static const struct of_device_id

usbmisc_imx_dt_ids[] = {

Quoted 14 lines
drivers/usb/chipidea/usbmisc_imx.c +4 -1
 		.compatible = "fsl,imx6ul-usbmisc",
 		.data = &imx6sx_usbmisc_ops,
 	},
+	{
+		.compatible = "fsl,imx7d-usbmisc",
+		.data = &imx7d_usbmisc_ops,
+	},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids);
--

1.9.1

Quoted 4 lines

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

--

Best Regards,
Peter Chen

Signature · 2 lines
Best Regards,
Peter Chen