[PATCH v6 1/7] usb: common: add a routine to print the OTG state

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a usb_otg_state_string() routine to print the OTG state for
debugging

Signed-off-by: Paul Zimmerman <paulz@xxxxxxxxxxxx>
Acked-by: Felipe Balbi <balbi@xxxxxx>
---
 drivers/usb/usb-common.c | 26 ++++++++++++++++++++++++++
 include/linux/usb/phy.h  |  8 ++++++++
 2 files changed, 34 insertions(+)

diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
index d29503e..33daf2a 100644
--- a/drivers/usb/usb-common.c
+++ b/drivers/usb/usb-common.c
@@ -14,6 +14,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/usb/ch9.h>
+#include <linux/usb/phy.h>
 
 const char *usb_speed_string(enum usb_device_speed speed)
 {
@@ -32,4 +33,29 @@ const char *usb_speed_string(enum usb_device_speed speed)
 }
 EXPORT_SYMBOL_GPL(usb_speed_string);
 
+const char *usb_otg_state_string(enum usb_otg_state state)
+{
+	static const char *const names[] = {
+		[OTG_STATE_UNDEFINED] = "UNDEFINED",
+		[OTG_STATE_B_IDLE] = "b_idle",
+		[OTG_STATE_B_SRP_INIT] = "b_srp_init",
+		[OTG_STATE_B_PERIPHERAL] = "b_peripheral",
+		[OTG_STATE_B_WAIT_ACON] = "b_wait_acon",
+		[OTG_STATE_B_HOST] = "b_host",
+		[OTG_STATE_A_IDLE] = "a_idle",
+		[OTG_STATE_A_WAIT_VRISE] = "a_wait_vrise",
+		[OTG_STATE_A_WAIT_BCON] = "a_wait_bcon",
+		[OTG_STATE_A_HOST] = "a_host",
+		[OTG_STATE_A_SUSPEND] = "a_suspend",
+		[OTG_STATE_A_PERIPHERAL] = "a_peripheral",
+		[OTG_STATE_A_WAIT_VFALL] = "a_wait_vfall",
+		[OTG_STATE_A_VBUS_ERR] = "a_vbus_err",
+	};
+
+	if (state < 0 || state >= ARRAY_SIZE(names))
+		state = OTG_STATE_UNDEFINED;
+	return names[state];
+}
+EXPORT_SYMBOL_GPL(usb_otg_state_string);
+
 MODULE_LICENSE("GPL");
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index 15847cb..e150155 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -276,4 +276,12 @@ static inline const char *usb_phy_type_string(enum usb_phy_type type)
 		return "UNKNOWN PHY TYPE";
 	}
 }
+
+/**
+ * usb_otg_state_string() - Returns human readable-name of the OTG state.
+ * @state: The state to return human-readable name for.  If it's not
+ *   any of the states defined in usb_otg_state enum, string for
+ *   OTG_STATE_UNDEFINED will be returned.
+ */
+extern const char *usb_otg_state_string(enum usb_otg_state state);
 #endif /* __LINUX_USB_PHY_H */
-- 
1.8.2.rc0.16.g20a599e

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux