Commit 7739376e authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

USB: of: clean up device-node helper

Clean up the USB device-node helper that is used to look up a device
node given a parent hub device and a port number. Also pass in a struct
usb_device as first argument to provide some type checking.

Give the helper the more descriptive name usb_of_get_device_node(),
which matches the new usb_of_get_interface_node() helper that is used to
look up a second type of of child node from a USB device.

Note that the terms "device node" and "interface node" are defined and
used by the OF Recommended Practice for USB.
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 03310a15
...@@ -142,7 +142,7 @@ static bool usbport_trig_port_observed(struct usbport_trig_data *usbport_data, ...@@ -142,7 +142,7 @@ static bool usbport_trig_port_observed(struct usbport_trig_data *usbport_data,
* *
* FIXME: This is really the device node of the connected device * FIXME: This is really the device node of the connected device
*/ */
port_np = usb_of_get_child_node(usb_dev->dev.of_node, port1); port_np = usb_of_get_device_node(usb_dev, port1);
if (!port_np) if (!port_np)
return false; return false;
......
...@@ -12,31 +12,32 @@ ...@@ -12,31 +12,32 @@
#include <linux/usb/of.h> #include <linux/usb/of.h>
/** /**
* usb_of_get_child_node - Find the device node match port number * usb_of_get_device_node() - get a USB device node
* @parent: the parent device node * @hub: hub to which device is connected
* @portnum: the port number which device is connecting * @port1: one-based index of port
* *
* Find the node from device tree according to its port number. * Look up the node of a USB device given its parent hub device and one-based
* port number.
* *
* Return: A pointer to the node with incremented refcount if found, or * Return: A pointer to the node with incremented refcount if found, or
* %NULL otherwise. * %NULL otherwise.
*/ */
struct device_node *usb_of_get_child_node(struct device_node *parent, struct device_node *usb_of_get_device_node(struct usb_device *hub, int port1)
int portnum)
{ {
struct device_node *node; struct device_node *node;
u32 port; u32 reg;
for_each_child_of_node(parent, node) { for_each_child_of_node(hub->dev.of_node, node) {
if (!of_property_read_u32(node, "reg", &port)) { if (of_property_read_u32(node, "reg", &reg))
if (port == portnum) continue;
if (reg == port1)
return node; return node;
} }
}
return NULL; return NULL;
} }
EXPORT_SYMBOL_GPL(usb_of_get_child_node); EXPORT_SYMBOL_GPL(usb_of_get_device_node);
/** /**
* usb_of_has_combined_node() - determine whether a device has a combined node * usb_of_has_combined_node() - determine whether a device has a combined node
......
...@@ -645,8 +645,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, ...@@ -645,8 +645,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
raw_port = usb_hcd_find_raw_port_number(usb_hcd, raw_port = usb_hcd_find_raw_port_number(usb_hcd,
port1); port1);
} }
dev->dev.of_node = usb_of_get_child_node(parent->dev.of_node, dev->dev.of_node = usb_of_get_device_node(parent, raw_port);
raw_port);
/* hub driver sets up TT records */ /* hub driver sets up TT records */
} }
......
...@@ -19,8 +19,7 @@ enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0); ...@@ -19,8 +19,7 @@ enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0);
bool of_usb_host_tpl_support(struct device_node *np); bool of_usb_host_tpl_support(struct device_node *np);
int of_usb_update_otg_caps(struct device_node *np, int of_usb_update_otg_caps(struct device_node *np,
struct usb_otg_caps *otg_caps); struct usb_otg_caps *otg_caps);
struct device_node *usb_of_get_child_node(struct device_node *parent, struct device_node *usb_of_get_device_node(struct usb_device *hub, int port1);
int portnum);
bool usb_of_has_combined_node(struct usb_device *udev); bool usb_of_has_combined_node(struct usb_device *udev);
struct device_node *usb_of_get_interface_node(struct usb_device *udev, struct device_node *usb_of_get_interface_node(struct usb_device *udev,
u8 config, u8 ifnum); u8 config, u8 ifnum);
...@@ -40,8 +39,8 @@ static inline int of_usb_update_otg_caps(struct device_node *np, ...@@ -40,8 +39,8 @@ static inline int of_usb_update_otg_caps(struct device_node *np,
{ {
return 0; return 0;
} }
static inline struct device_node *usb_of_get_child_node static inline struct device_node *
(struct device_node *parent, int portnum) usb_of_get_device_node(struct usb_device *hub, int port1)
{ {
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment