NVIDIA: SAUCE: usb: typec: ucsi: Find connector fwnode without relying on order

BugLink: https://bugs.launchpad.net/bugs/2072591

The previous code relied on the order of "connector" nodes under the
ucsi device node to determine the correct fwnode handle for a connector.
However, the order of nodes should not be relied upon when parsing device
trees, especially when using live DT overlays.

This change modifies ucsi_find_fwnode() to find the correct connector
fwnode by reading the "reg" property of each connector node and
comparing it to the connector number. If only a single connector node
exists without a "reg" property, that single node is returned.

This ensures the correct connector fwnode is found regardless of node
order in the DT.

http://nvbugs/3960851
http://nvbugs/4063694

Signed-off-by: Wayne Chang <waynec@nvidia.com>
Reviewed-by: Prathamesh Shete <pshete@nvidia.com>
Tested-by: Prathamesh Shete <pshete@nvidia.com>
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Acked-by: Jacob Martin <jacob.martin@canonical.com>
Acked-by: Noah Wager <noah.wager@canonical.com>
Signed-off-by: Noah Wager <noah.wager@canonical.com>
This commit is contained in:
Wayne Chang
2023-05-25 08:05:01 +00:00
committed by Noah Wager
parent e86340544f
commit 3dbe65baaa
+7 -4
View File
@@ -1186,11 +1186,14 @@ static const struct typec_operations ucsi_ops = {
static struct fwnode_handle *ucsi_find_fwnode(struct ucsi_connector *con)
{
struct fwnode_handle *fwnode;
int i = 1;
u32 index;
device_for_each_child_node(con->ucsi->dev, fwnode) {
if (!fwnode_property_read_u32(fwnode, "reg", &index) && index+1 != con->num)
continue;
return fwnode;
}
device_for_each_child_node(con->ucsi->dev, fwnode)
if (i++ == con->num)
return fwnode;
return NULL;
}