Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: common: add helper to get role-switch-default-mode

Add helper to get "role-switch-default-mode", and convert it
to the corresponding enum usb_dr_mode

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Link: https://lore.kernel.org/r/1626340078-29111-6-git-send-email-chunfeng.yun@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Chunfeng Yun and committed by
Greg Kroah-Hartman
2037f299 72c1b91f

+21
+20
drivers/usb/common/common.c
··· 201 201 EXPORT_SYMBOL_GPL(usb_get_dr_mode); 202 202 203 203 /** 204 + * usb_get_role_switch_default_mode - Get default mode for given device 205 + * @dev: Pointer to the given device 206 + * 207 + * The function gets string from property 'role-switch-default-mode', 208 + * and returns the corresponding enum usb_dr_mode. 209 + */ 210 + enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev) 211 + { 212 + const char *str; 213 + int ret; 214 + 215 + ret = device_property_read_string(dev, "role-switch-default-mode", &str); 216 + if (ret < 0) 217 + return USB_DR_MODE_UNKNOWN; 218 + 219 + return usb_get_dr_mode_from_string(str); 220 + } 221 + EXPORT_SYMBOL_GPL(usb_get_role_switch_default_mode); 222 + 223 + /** 204 224 * usb_decode_interval - Decode bInterval into the time expressed in 1us unit 205 225 * @epd: The descriptor of the endpoint 206 226 * @speed: The speed that the endpoint works as
+1
include/linux/usb/otg.h
··· 128 128 * and returns the corresponding enum usb_dr_mode 129 129 */ 130 130 extern enum usb_dr_mode usb_get_dr_mode(struct device *dev); 131 + extern enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev); 131 132 132 133 #endif /* __LINUX_USB_OTG_H */