summaryrefslogtreecommitdiff
path: root/drivers/usb/usb-common.c
diff options
context:
space:
mode:
authorFelipe Balbi <balbi@ti.com>2013-01-24 22:29:48 +0200
committerFelipe Balbi <balbi@ti.com>2013-03-18 11:17:11 +0200
commitd1e3d757f7aa91f15db347fc05ffd7ef7f413091 (patch)
tree1cace41a22eb5fc4d5c4e1fbc71442bb5234988e /drivers/usb/usb-common.c
parentb15a762f02acb4f1e695a17435f719350f9d5bc1 (diff)
usb: common: introduce usb_state_string()
this function will receive enum usb_device_state and return a human-readable string from it or, case an unknown value is passed as argument, the string "UNKNOWN". Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/usb-common.c')
-rw-r--r--drivers/usb/usb-common.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
index d29503e954ab..070b681e5d17 100644
--- a/drivers/usb/usb-common.c
+++ b/drivers/usb/usb-common.c
@@ -32,4 +32,25 @@ const char *usb_speed_string(enum usb_device_speed speed)
}
EXPORT_SYMBOL_GPL(usb_speed_string);
+const char *usb_state_string(enum usb_device_state state)
+{
+ static const char *const names[] = {
+ [USB_STATE_NOTATTACHED] = "not attached",
+ [USB_STATE_ATTACHED] = "attached",
+ [USB_STATE_POWERED] = "powered",
+ [USB_STATE_RECONNECTING] = "reconnecting",
+ [USB_STATE_UNAUTHENTICATED] = "unauthenticated",
+ [USB_STATE_DEFAULT] = "default",
+ [USB_STATE_ADDRESS] = "addresssed",
+ [USB_STATE_CONFIGURED] = "configured",
+ [USB_STATE_SUSPENDED] = "suspended",
+ };
+
+ if (state < 0 || state >= ARRAY_SIZE(names))
+ return "UNKNOWN";
+
+ return names[state];
+}
+EXPORT_SYMBOL_GPL(usb_state_string);
+
MODULE_LICENSE("GPL");