forked from luck/tmp_suning_uos_patched
drivers: Introduce device lookup variants by fwnode
Add a helper to match the firmware node handle of a device and provide wrappers for {bus/class/driver}_find_device() APIs to avoid proliferation of duplicate custom match functions. Cc: "David S. Miller" <davem@davemloft.net> Cc: Doug Ledford <dledford@redhat.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: linux-usb@vger.kernel.org Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Ulf Hansson <ulf.hansson@linaro.org> Cc: Joe Perches <joe@perches.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Joerg Roedel <joro@8bytes.org> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Acked-by: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://lore.kernel.org/r/20190723221838.12024-4-suzuki.poulose@arm.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
cfba5de9b9
commit
67843bbaf3
|
@ -3368,3 +3368,9 @@ int device_match_of_node(struct device *dev, const void *np)
|
|||
return dev->of_node == np;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(device_match_of_node);
|
||||
|
||||
int device_match_fwnode(struct device *dev, const void *fwnode)
|
||||
{
|
||||
return dev_fwnode(dev) == fwnode;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(device_match_fwnode);
|
||||
|
|
|
@ -133,19 +133,13 @@ static struct bus_type *generic_match_buses[] = {
|
|||
NULL,
|
||||
};
|
||||
|
||||
static int device_fwnode_match(struct device *dev, const void *fwnode)
|
||||
{
|
||||
return dev_fwnode(dev) == fwnode;
|
||||
}
|
||||
|
||||
static void *device_connection_fwnode_match(struct device_connection *con)
|
||||
{
|
||||
struct bus_type *bus;
|
||||
struct device *dev;
|
||||
|
||||
for (bus = generic_match_buses[0]; bus; bus++) {
|
||||
dev = bus_find_device(bus, NULL, (void *)con->fwnode,
|
||||
device_fwnode_match);
|
||||
dev = bus_find_device_by_fwnode(bus, con->fwnode);
|
||||
if (dev && !strncmp(dev_name(dev), con->id, strlen(con->id)))
|
||||
return dev;
|
||||
|
||||
|
|
|
@ -37,11 +37,6 @@ static int coresight_alloc_conns(struct device *dev,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int coresight_device_fwnode_match(struct device *dev, const void *fwnode)
|
||||
{
|
||||
return dev_fwnode(dev) == fwnode;
|
||||
}
|
||||
|
||||
static struct device *
|
||||
coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
|
||||
{
|
||||
|
@ -51,8 +46,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
|
|||
* If we have a non-configurable replicator, it will be found on the
|
||||
* platform bus.
|
||||
*/
|
||||
dev = bus_find_device(&platform_bus_type, NULL,
|
||||
fwnode, coresight_device_fwnode_match);
|
||||
dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
|
||||
if (dev)
|
||||
return dev;
|
||||
|
||||
|
@ -60,8 +54,7 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
|
|||
* We have a configurable component - circle through the AMBA bus
|
||||
* looking for the device that matches the endpoint node.
|
||||
*/
|
||||
return bus_find_device(&amba_bustype, NULL,
|
||||
fwnode, coresight_device_fwnode_match);
|
||||
return bus_find_device_by_fwnode(&amba_bustype, fwnode);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
|
|
|
@ -202,6 +202,4 @@ static inline void *coresight_get_uci_data(const struct amba_id *id)
|
|||
|
||||
void coresight_release_platform_data(struct coresight_platform_data *pdata);
|
||||
|
||||
int coresight_device_fwnode_match(struct device *dev, const void *fwnode);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1046,9 +1046,7 @@ static void coresight_fixup_device_conns(struct coresight_device *csdev)
|
|||
struct coresight_connection *conn = &csdev->pdata->conns[i];
|
||||
struct device *dev = NULL;
|
||||
|
||||
dev = bus_find_device(&coresight_bustype, NULL,
|
||||
(void *)conn->child_fwnode,
|
||||
coresight_device_fwnode_match);
|
||||
dev = bus_find_device_by_fwnode(&coresight_bustype, conn->child_fwnode);
|
||||
if (dev) {
|
||||
conn->child_dev = to_coresight_device(dev);
|
||||
/* and put reference from 'bus_find_device()' */
|
||||
|
|
|
@ -4499,19 +4499,13 @@ static const struct acpi_device_id hns_roce_acpi_match[] = {
|
|||
};
|
||||
MODULE_DEVICE_TABLE(acpi, hns_roce_acpi_match);
|
||||
|
||||
static int hns_roce_node_match(struct device *dev, const void *fwnode)
|
||||
{
|
||||
return dev->fwnode == fwnode;
|
||||
}
|
||||
|
||||
static struct
|
||||
platform_device *hns_roce_find_pdev(struct fwnode_handle *fwnode)
|
||||
{
|
||||
struct device *dev;
|
||||
|
||||
/* get the 'device' corresponding to the matching 'fwnode' */
|
||||
dev = bus_find_device(&platform_bus_type, NULL,
|
||||
fwnode, hns_roce_node_match);
|
||||
dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
|
||||
/* get the platform device */
|
||||
return dev ? to_platform_device(dev) : NULL;
|
||||
}
|
||||
|
|
|
@ -2034,16 +2034,11 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)
|
|||
|
||||
static struct platform_driver arm_smmu_driver;
|
||||
|
||||
static int arm_smmu_match_node(struct device *dev, const void *data)
|
||||
{
|
||||
return dev->fwnode == data;
|
||||
}
|
||||
|
||||
static
|
||||
struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
|
||||
{
|
||||
struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
|
||||
fwnode, arm_smmu_match_node);
|
||||
struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
|
||||
fwnode);
|
||||
put_device(dev);
|
||||
return dev ? dev_get_drvdata(dev) : NULL;
|
||||
}
|
||||
|
|
|
@ -1426,16 +1426,11 @@ static bool arm_smmu_capable(enum iommu_cap cap)
|
|||
}
|
||||
}
|
||||
|
||||
static int arm_smmu_match_node(struct device *dev, const void *data)
|
||||
{
|
||||
return dev->fwnode == data;
|
||||
}
|
||||
|
||||
static
|
||||
struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
|
||||
{
|
||||
struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
|
||||
fwnode, arm_smmu_match_node);
|
||||
struct device *dev = driver_find_device_by_fwnode(&arm_smmu_driver.driver,
|
||||
fwnode);
|
||||
put_device(dev);
|
||||
return dev ? dev_get_drvdata(dev) : NULL;
|
||||
}
|
||||
|
|
|
@ -754,17 +754,11 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
|
|||
return (void *)misc_op;
|
||||
}
|
||||
|
||||
static int hns_dsaf_dev_match(struct device *dev, const void *fwnode)
|
||||
{
|
||||
return dev->fwnode == fwnode;
|
||||
}
|
||||
|
||||
struct
|
||||
platform_device *hns_dsaf_find_platform_device(struct fwnode_handle *fwnode)
|
||||
{
|
||||
struct device *dev;
|
||||
|
||||
dev = bus_find_device(&platform_bus_type, NULL,
|
||||
fwnode, hns_dsaf_dev_match);
|
||||
dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
|
||||
return dev ? to_platform_device(dev) : NULL;
|
||||
}
|
||||
|
|
|
@ -85,11 +85,6 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw)
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(usb_role_switch_get_role);
|
||||
|
||||
static int switch_fwnode_match(struct device *dev, const void *fwnode)
|
||||
{
|
||||
return dev_fwnode(dev) == fwnode;
|
||||
}
|
||||
|
||||
static void *usb_role_switch_match(struct device_connection *con, int ep,
|
||||
void *data)
|
||||
{
|
||||
|
@ -99,8 +94,7 @@ static void *usb_role_switch_match(struct device_connection *con, int ep,
|
|||
if (con->id && !fwnode_property_present(con->fwnode, con->id))
|
||||
return NULL;
|
||||
|
||||
dev = class_find_device(role_class, NULL, con->fwnode,
|
||||
switch_fwnode_match);
|
||||
dev = class_find_device_by_fwnode(role_class, con->fwnode);
|
||||
} else {
|
||||
dev = class_find_device_by_name(role_class, con->endpoint[ep]);
|
||||
}
|
||||
|
|
|
@ -205,11 +205,6 @@ static void typec_altmode_put_partner(struct altmode *altmode)
|
|||
put_device(&adev->dev);
|
||||
}
|
||||
|
||||
static int typec_port_fwnode_match(struct device *dev, const void *fwnode)
|
||||
{
|
||||
return dev_fwnode(dev) == fwnode;
|
||||
}
|
||||
|
||||
static void *typec_port_match(struct device_connection *con, int ep, void *data)
|
||||
{
|
||||
struct device *dev;
|
||||
|
@ -219,8 +214,7 @@ static void *typec_port_match(struct device_connection *con, int ep, void *data)
|
|||
* 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);
|
||||
return class_find_device_by_fwnode(typec_class, con->fwnode);
|
||||
|
||||
dev = class_find_device_by_name(typec_class, con->endpoint[ep]);
|
||||
|
||||
|
|
|
@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
|
|||
|
||||
int device_match_name(struct device *dev, const void *name);
|
||||
int device_match_of_node(struct device *dev, const void *np);
|
||||
int device_match_fwnode(struct device *dev, const void *fwnode);
|
||||
|
||||
int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
|
||||
int (*fn)(struct device *dev, void *data));
|
||||
|
@ -198,6 +199,18 @@ bus_find_device_by_of_node(struct bus_type *bus, const struct device_node *np)
|
|||
return bus_find_device(bus, NULL, np, device_match_of_node);
|
||||
}
|
||||
|
||||
/**
|
||||
* bus_find_device_by_fwnode : device iterator for locating a particular device
|
||||
* matching the fwnode.
|
||||
* @bus: bus type
|
||||
* @fwnode: fwnode of the device to match.
|
||||
*/
|
||||
static inline struct device *
|
||||
bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle *fwnode)
|
||||
{
|
||||
return bus_find_device(bus, NULL, fwnode, device_match_fwnode);
|
||||
}
|
||||
|
||||
struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
|
||||
struct device *hint);
|
||||
int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
|
||||
|
@ -391,6 +404,19 @@ driver_find_device_by_of_node(struct device_driver *drv,
|
|||
return driver_find_device(drv, NULL, np, device_match_of_node);
|
||||
}
|
||||
|
||||
/**
|
||||
* driver_find_device_by_fwnode- device iterator for locating a particular device
|
||||
* by fwnode pointer.
|
||||
* @driver: the driver we're iterating
|
||||
* @fwnode: fwnode pointer to match.
|
||||
*/
|
||||
static inline struct device *
|
||||
driver_find_device_by_fwnode(struct device_driver *drv,
|
||||
const struct fwnode_handle *fwnode)
|
||||
{
|
||||
return driver_find_device(drv, NULL, fwnode, device_match_fwnode);
|
||||
}
|
||||
|
||||
void driver_deferred_probe_add(struct device *dev);
|
||||
int driver_deferred_probe_check_state(struct device *dev);
|
||||
int driver_deferred_probe_check_state_continue(struct device *dev);
|
||||
|
@ -544,6 +570,19 @@ class_find_device_by_of_node(struct class *class, const struct device_node *np)
|
|||
return class_find_device(class, NULL, np, device_match_of_node);
|
||||
}
|
||||
|
||||
/**
|
||||
* class_find_device_by_fwnode : device iterator for locating a particular device
|
||||
* matching the fwnode.
|
||||
* @class: class type
|
||||
* @fwnode: fwnode of the device to match.
|
||||
*/
|
||||
static inline struct device *
|
||||
class_find_device_by_fwnode(struct class *class,
|
||||
const struct fwnode_handle *fwnode)
|
||||
{
|
||||
return class_find_device(class, NULL, fwnode, device_match_fwnode);
|
||||
}
|
||||
|
||||
struct class_attribute {
|
||||
struct attribute attr;
|
||||
ssize_t (*show)(struct class *class, struct class_attribute *attr,
|
||||
|
|
Loading…
Reference in New Issue
Block a user