Skip to contentSkip to conversation

rockchip: use standard dr_mode parsing function

PATCH In review John Keeping 2 participants 4 messages Apr 12, 2023 – Apr 13, 2023

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

PATCH 1/2 rockchip: use standard dr_mode parsing function

Instead of duplicating the string values here, use usb_get_dr_mode() to handle the property lookup and converting the values to an enum.

This is implemented with a switch in preparation for the next patch which adds extra handling for peripheral mode.

---
 arch/arm/mach-rockchip/board.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
arch/arm/mach-rockchip/board.c +9 -3
index f1f70c81d0..6d33d65780 100644
@@ -212,6 +212,7 @@ void enable_caches(void)
 #include <usb.h>
 
 #if defined(CONFIG_USB_GADGET_DWC2_OTG)
+#include <linux/usb/otg.h>
 #include <usb/dwc2_udc.h>
 
 static struct dwc2_plat_otg_data otg_data = {
@@ -223,18 +224,23 @@ static struct dwc2_plat_otg_data otg_data = {
 int board_usb_init(int index, enum usb_init_type init)
 {
 	ofnode node;
-	const char *mode;
 	bool matched = false;
 
 	/* find the usb_otg node */
 	node = ofnode_by_compatible(ofnode_null(), "snps,dwc2");
 	while (ofnode_valid(node)) {
-		mode = ofnode_read_string(node, "dr_mode");
-		if (mode && strcmp(mode, "otg") == 0) {
+		switch (usb_get_dr_mode(node)) {
+		case USB_DR_MODE_OTG:
 			matched = true;
 			break;
+
+		default:
+			break;
 		}
 
+		if (matched)
+			break;
+
 		node = ofnode_by_compatible(node, "snps,dwc2");
 	}
 	if (!matched) {
Signature · 1 line
2.40.0
#1 lore raw

PATCH 2/2 rockchip: handle peripheral as well as otg dr_mode

The OTG port is identified by inspecting the "dr_mode" property which is expected to be "otg" for this port. But it will work just as well as a device controller when dr_mode is set to "peripheral", which may be required if the mode detection pin is not set up correctly and the device controller needs to be programmed to override this.

---
 arch/arm/mach-rockchip/board.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-rockchip/board.c +1 -0
index 6d33d65780..45d9eae870 100644
@@ -231,6 +231,7 @@ int board_usb_init(int index, enum usb_init_type init)
 	while (ofnode_valid(node)) {
 		switch (usb_get_dr_mode(node)) {
 		case USB_DR_MODE_OTG:
+		case USB_DR_MODE_PERIPHERAL:
 			matched = true;
 			break;
 
Signature · 1 line
2.40.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] rockchip: handle peripheral as well as otg dr_mode

Quoted 7 lines · John Keeping

The OTG port is identified by inspecting the "dr_mode" property which is expected to be "otg" for this port. But it will work just as well as a device controller when dr_mode is set to "peripheral", which may be required if the mode detection pin is not set up correctly and the device controller needs to be programmed to override this.

Thanks,
- Kever

Quoted 16 lines
---
  arch/arm/mach-rockchip/board.c | 1 +
  1 file changed, 1 insertion(+)
arch/arm/mach-rockchip/board.c +1 -0
index 6d33d65780..45d9eae870 100644
@@ -231,6 +231,7 @@ int board_usb_init(int index, enum usb_init_type init)
  	while (ofnode_valid(node)) {
  		switch (usb_get_dr_mode(node)) {
  		case USB_DR_MODE_OTG:
+		case USB_DR_MODE_PERIPHERAL:
  			matched = true;
  			break;
 
Reviewed-by on v1 1/2
#3 lore raw
In reply to John Keeping
Quoted 7 lines · John Keeping

Instead of duplicating the string values here, use usb_get_dr_mode() to handle the property lookup and converting the values to an enum.

This is implemented with a switch in preparation for the next patch which adds extra handling for peripheral mode.

Thanks,
- Kever

Quoted 43 lines
---
  arch/arm/mach-rockchip/board.c | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
arch/arm/mach-rockchip/board.c +9 -3
index f1f70c81d0..6d33d65780 100644
@@ -212,6 +212,7 @@ void enable_caches(void)
  #include <usb.h>
 
  #if defined(CONFIG_USB_GADGET_DWC2_OTG)
+#include <linux/usb/otg.h>
  #include <usb/dwc2_udc.h>
 
  static struct dwc2_plat_otg_data otg_data = {
@@ -223,18 +224,23 @@ static struct dwc2_plat_otg_data otg_data = {
  int board_usb_init(int index, enum usb_init_type init)
  {
  	ofnode node;
-	const char *mode;
  	bool matched = false;
 
  	/* find the usb_otg node */
  	node = ofnode_by_compatible(ofnode_null(), "snps,dwc2");
  	while (ofnode_valid(node)) {
-		mode = ofnode_read_string(node, "dr_mode");
-		if (mode && strcmp(mode, "otg") == 0) {
+		switch (usb_get_dr_mode(node)) {
+		case USB_DR_MODE_OTG:
  			matched = true;
  			break;
+
+		default:
+			break;
  		}
 
+		if (matched)
+			break;
+
  		node = ofnode_by_compatible(node, "snps,dwc2");
  	}
  	if (!matched) {