summaryrefslogtreecommitdiff
path: root/drivers/firmware/arm_scmi/bus.c
diff options
context:
space:
mode:
authorCristian Marussi <cristian.marussi@arm.com>2021-03-16 15:49:03 +0300
committerSudeep Holla <sudeep.holla@arm.com>2021-03-30 18:35:16 +0300
commitd4f9dddd21f39395c62ea12d3d91239637d4805f (patch)
treebc84ab12611d2da1d2e465e6b16a61f3276de3ca /drivers/firmware/arm_scmi/bus.c
parentf5800e0bf6f9b7ff7dfa4db8b0681bd062eb16a4 (diff)
downloadlinux-d4f9dddd21f39395c62ea12d3d91239637d4805f.tar.xz
firmware: arm_scmi: Add dynamic scmi devices creation
Having added the support for SCMI protocols as modules in order to let vendors extend the SCMI core with their own additions it seems odd to then force SCMI drivers built on top to use a static device table to declare their devices since this way any new SCMI drivers addition would need the core SCMI device table to be updated too. Remove the static core device table and let SCMI drivers to simply declare which device/protocol pair they need at initialization time: the core will then take care to generate such devices dynamically during platform initialization or at module loading time, as long as the requested underlying protocol is defined in the devicetree. Link: https://lore.kernel.org/r/20210316124903.35011-39-cristian.marussi@arm.com Tested-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Diffstat (limited to 'drivers/firmware/arm_scmi/bus.c')
-rw-r--r--drivers/firmware/arm_scmi/bus.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index aadf2da21561..784cf0027da3 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -51,6 +51,31 @@ static int scmi_dev_match(struct device *dev, struct device_driver *drv)
return 0;
}
+static int scmi_match_by_id_table(struct device *dev, void *data)
+{
+ struct scmi_device *sdev = to_scmi_dev(dev);
+ struct scmi_device_id *id_table = data;
+
+ return sdev->protocol_id == id_table->protocol_id &&
+ !strcmp(sdev->name, id_table->name);
+}
+
+struct scmi_device *scmi_child_dev_find(struct device *parent,
+ int prot_id, const char *name)
+{
+ struct scmi_device_id id_table;
+ struct device *dev;
+
+ id_table.protocol_id = prot_id;
+ id_table.name = name;
+
+ dev = device_find_child(parent, &id_table, scmi_match_by_id_table);
+ if (!dev)
+ return NULL;
+
+ return to_scmi_dev(dev);
+}
+
const struct scmi_protocol *scmi_protocol_get(int protocol_id)
{
const struct scmi_protocol *proto;
@@ -114,6 +139,10 @@ int scmi_driver_register(struct scmi_driver *driver, struct module *owner,
{
int retval;
+ retval = scmi_protocol_device_request(driver->id_table);
+ if (retval)
+ return retval;
+
driver->driver.bus = &scmi_bus_type;
driver->driver.name = driver->name;
driver->driver.owner = owner;
@@ -130,6 +159,7 @@ EXPORT_SYMBOL_GPL(scmi_driver_register);
void scmi_driver_unregister(struct scmi_driver *driver)
{
driver_unregister(&driver->driver);
+ scmi_protocol_device_unrequest(driver->id_table);
}
EXPORT_SYMBOL_GPL(scmi_driver_unregister);