usb: roles: get usb-role-switch from parent
when the USB host controller is the parent of the connector, usually type-B, sometimes don't need the graph, so we should check whether it's parent registers usb-role-switch or not firstly, and get it if exists. Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> Link: https://lore.kernel.org/r/1567070558-29417-9-git-send-email-chunfeng.yun@mediatek.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
c5c0283a9d
commit
6fadd72943
|
@ -102,6 +102,19 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
|
||||||
return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
|
return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct usb_role_switch *
|
||||||
|
usb_role_switch_is_parent(struct fwnode_handle *fwnode)
|
||||||
|
{
|
||||||
|
struct fwnode_handle *parent = fwnode_get_parent(fwnode);
|
||||||
|
struct device *dev;
|
||||||
|
|
||||||
|
if (!parent || !fwnode_property_present(parent, "usb-role-switch"))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
dev = class_find_device_by_fwnode(role_class, parent);
|
||||||
|
return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* usb_role_switch_get - Find USB role switch linked with the caller
|
* usb_role_switch_get - Find USB role switch linked with the caller
|
||||||
* @dev: The caller device
|
* @dev: The caller device
|
||||||
|
@ -113,6 +126,8 @@ struct usb_role_switch *usb_role_switch_get(struct device *dev)
|
||||||
{
|
{
|
||||||
struct usb_role_switch *sw;
|
struct usb_role_switch *sw;
|
||||||
|
|
||||||
|
sw = usb_role_switch_is_parent(dev_fwnode(dev));
|
||||||
|
if (!sw)
|
||||||
sw = device_connection_find_match(dev, "usb-role-switch", NULL,
|
sw = device_connection_find_match(dev, "usb-role-switch", NULL,
|
||||||
usb_role_switch_match);
|
usb_role_switch_match);
|
||||||
|
|
||||||
|
@ -134,8 +149,10 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode)
|
||||||
{
|
{
|
||||||
struct usb_role_switch *sw;
|
struct usb_role_switch *sw;
|
||||||
|
|
||||||
sw = fwnode_connection_find_match(fwnode, "usb-role-switch", NULL,
|
sw = usb_role_switch_is_parent(fwnode);
|
||||||
usb_role_switch_match);
|
if (!sw)
|
||||||
|
sw = fwnode_connection_find_match(fwnode, "usb-role-switch",
|
||||||
|
NULL, usb_role_switch_match);
|
||||||
if (!IS_ERR_OR_NULL(sw))
|
if (!IS_ERR_OR_NULL(sw))
|
||||||
WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
|
WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue