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>
This commit is contained in:
Chunfeng Yun 2021-07-15 17:07:50 +08:00 committed by Greg Kroah-Hartman
parent 72c1b91f5d
commit 2037f2991d
2 changed files with 21 additions and 0 deletions

View File

@ -200,6 +200,26 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev)
}
EXPORT_SYMBOL_GPL(usb_get_dr_mode);
/**
* usb_get_role_switch_default_mode - Get default mode for given device
* @dev: Pointer to the given device
*
* The function gets string from property 'role-switch-default-mode',
* and returns the corresponding enum usb_dr_mode.
*/
enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev)
{
const char *str;
int ret;
ret = device_property_read_string(dev, "role-switch-default-mode", &str);
if (ret < 0)
return USB_DR_MODE_UNKNOWN;
return usb_get_dr_mode_from_string(str);
}
EXPORT_SYMBOL_GPL(usb_get_role_switch_default_mode);
/**
* usb_decode_interval - Decode bInterval into the time expressed in 1us unit
* @epd: The descriptor of the endpoint

View File

@ -128,5 +128,6 @@ enum usb_dr_mode {
* and returns the corresponding enum usb_dr_mode
*/
extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
extern enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev);
#endif /* __LINUX_USB_OTG_H */