Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75d8663e authored by Heikki Krogerus's avatar Heikki Krogerus Committed by Will McVicker
Browse files

UPSTREAM: usb: typec: Find the ports by also matching against the device node



When the connections are defined in firmware, struct
device_connection will have the fwnode member pointing to
the device node (struct fwnode_handle) of the requested
device, and the endpoint will not be used at all in that
case.

Bug: 150877929
Acked-by: default avatarHans de Goede <hdegoede@redhat.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: default avatarJun Li <jun.li@nxp.com>
Signed-off-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Change-Id: Ie6e233c158bae77cf1f332c45957248e4521c7f8
Signed-off-by: default avatarWill McVicker <willmcvicker@google.com>
(cherry picked from commit 6a0bbcf96b2273f110a14d11a5952527c5921191)
parent 519f15d5
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include <linux/device.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/property.h>
#include <linux/slab.h>

#include "bus.h"
@@ -204,15 +205,32 @@ static void typec_altmode_put_partner(struct altmode *altmode)
	put_device(&adev->dev);
}

static int __typec_port_match(struct device *dev, const void *name)
static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
{
	return dev_fwnode(dev) == fwnode;
}

static int typec_port_name_match(struct device *dev, const void *name)
{
	return !strcmp((const char *)name, dev_name(dev));
}

static void *typec_port_match(struct device_connection *con, int ep, void *data)
{
	return class_find_device(typec_class, NULL, con->endpoint[ep],
				 __typec_port_match);
	struct device *dev;

	/*
	 * FIXME: Check does the fwnode supports the requested SVID. If it does
	 * we need to return ERR_PTR(-PROBE_DEFER) when there is no device.
	 */
	if (con->fwnode)
		return class_find_device(typec_class, NULL, con->fwnode,
					 typec_port_fwnode_match);

	dev = class_find_device(typec_class, NULL, con->endpoint[ep],
				typec_port_name_match);

	return dev ? dev : ERR_PTR(-EPROBE_DEFER);
}

struct typec_altmode *