usb: roles: add helper usb_role_string()
Subsystems (2)
PATCH 1/2 usb: roles: add helper usb_role_string()
Introduces usb_role_string() function, which returns a human-readable name of provided usb role, it's useful to make the log readable.
Signed-off-by Chunfeng Yun <[email protected]>
--- drivers/usb/roles/class.c | 9 +++++++++ include/linux/usb/role.h | 6 ++++++ 2 files changed, 15 insertions(+)
drivers/usb/roles/class.c +9 -0
@@ -214,6 +214,15 @@ static const char * const usb_roles[] = { [USB_ROLE_DEVICE] = "device", }; +const char *usb_role_string (enum usb_role role) +{ +if (role <0 || role >=ARRAY_SIZE (usb_roles)) +return "unknown" ; + +return usb_roles[role]; +} +EXPORT_SYMBOL_GPL (usb_role_string); +static ssize_t role_show (struct device *dev,struct device_attribute *attr,char *buf) {
include/linux/usb/role.h +6 -0
@@ -65,6 +65,7 @@ void usb_role_switch_unregister(struct usb_role_switch *sw);void usb_role_switch_set_drvdata (struct usb_role_switch *sw,void *data);void *usb_role_switch_get_drvdata (struct usb_role_switch *sw); +const char *usb_role_string (enum usb_role role);#else static inline int usb_role_switch_set_role (struct usb_role_switch *sw,enum usb_role role)
@@ -109,6 +110,11 @@ static inline void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)return NULL ; } +static inline const char *usb_role_string (enum usb_role role) +{ +return "unknown" ; +} +#endif #endif /* __LINUX_USB_ROLE_H */
Signature · 1 line
2.18.0
PATCH 2/2 usb: common: usb-conn-gpio: use usb_role_string() to print role status
Use usb_role_string() to print role status, make the log readable.
Signed-off-by Chunfeng Yun <[email protected]>
--- drivers/usb/common/usb-conn-gpio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/common/usb-conn-gpio.c +3 -3
@@ -83,11 +83,11 @@ static void usb_conn_detect_cable(struct work_struct *work)else role =USB_ROLE_NONE ; -dev_dbg (info->dev,"role %d/%d, gpios: id %d, vbus %d\n" , - info->last_role, role, id, vbus); +dev_dbg (info->dev,"role %s -> %s, gpios: id %d, vbus %d\n" , +usb_role_string (info->last_role),usb_role_string (role), id, vbus);if (info->last_role == role) { -dev_warn (info->dev,"repeated role: %d\n" , role); +dev_warn (info->dev,"repeated role: %s\n" ,usb_role_string (role));return ; }
Signature · 1 line
2.18.0
Quoted 5 lines · Chunfeng Yun
Introduces
usb_role_string()function, which returns a human-readable name of provided usb role, it's useful to make the log readable.Signed-off-by Chunfeng Yun <[email protected]>
Reviewed-by Heikki Krogerus <[email protected]>
Quoted 51 lines
--- drivers/usb/roles/class.c | 9 +++++++++ include/linux/usb/role.h | 6 ++++++ 2 files changed, 15 insertions(+)drivers/usb/roles/class.c +9
-0@@ -214,6 +214,15 @@ static const char * const usb_roles[] = { [USB_ROLE_DEVICE] = "device", }; +const char *usb_role_string (enum usb_role role) +{ +if (role <0 || role >=ARRAY_SIZE (usb_roles)) +return "unknown" ; + +return usb_roles[role]; +} +EXPORT_SYMBOL_GPL (usb_role_string); +static ssize_t role_show (struct device *dev,struct device_attribute *attr,char *buf) {include/linux/usb/role.h +6
-0@@ -65,6 +65,7 @@ void usb_role_switch_unregister(struct usb_role_switch *sw);void usb_role_switch_set_drvdata (struct usb_role_switch *sw,void *data);void *usb_role_switch_get_drvdata (struct usb_role_switch *sw); +const char *usb_role_string (enum usb_role role);#else static inline int usb_role_switch_set_role (struct usb_role_switch *sw,enum usb_role role)@@ -109,6 +110,11 @@ static inline void *usb_role_switch_get_drvdata(struct usb_role_switch *sw)return NULL ; } +static inline const char *usb_role_string (enum usb_role role) +{ +return "unknown" ; +} +#endif #endif /* __LINUX_USB_ROLE_H */ Signature · 1 line
2.18.0
Signature · 1 line
heikki