Skip to content

Commit

Permalink
usb: roles: Add usb_role_switch_find_by_fwnode()
Browse files Browse the repository at this point in the history
Simple wrapper function that searches USB role switches with
class_find_device_by_fwnode().

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20191008122600.22340-2-heikki.krogerus@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Heikki Krogerus authored and gregkh committed Nov 4, 2019
1 parent 16c8373 commit c6919d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions drivers/usb/roles/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,27 @@ void usb_role_switch_put(struct usb_role_switch *sw)
}
EXPORT_SYMBOL_GPL(usb_role_switch_put);

/**
* usb_role_switch_find_by_fwnode - Find USB role switch with its fwnode
* @fwnode: fwnode of the USB Role Switch
*
* Finds and returns role switch with @fwnode. The reference count for the
* found switch is incremented.
*/
struct usb_role_switch *
usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode)
{
struct device *dev;

if (!fwnode)
return NULL;

dev = class_find_device_by_fwnode(role_class, fwnode);

return dev ? to_role_switch(dev) : NULL;
}
EXPORT_SYMBOL_GPL(usb_role_switch_find_by_fwnode);

static umode_t
usb_role_switch_is_visible(struct kobject *kobj, struct attribute *attr, int n)
{
Expand Down
3 changes: 3 additions & 0 deletions include/linux/usb/role.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ struct usb_role_switch *usb_role_switch_get(struct device *dev);
struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *node);
void usb_role_switch_put(struct usb_role_switch *sw);

struct usb_role_switch *
usb_role_switch_find_by_fwnode(const struct fwnode_handle *fwnode);

struct usb_role_switch *
usb_role_switch_register(struct device *parent,
const struct usb_role_switch_desc *desc);
Expand Down

0 comments on commit c6919d5

Please sign in to comment.