firmware: scmi: use scmi_proto_driver_get() function to get SCMI protocol driver
authorAlice Guo <alice.guo@nxp.com>
Mon, 28 Apr 2025 10:37:25 +0000 (18:37 +0800)
committerFabio Estevam <festevam@gmail.com>
Sat, 3 May 2025 19:55:32 +0000 (16:55 -0300)
If there is a SoC specific SCMI protocol driver, using
scmi_proto_driver_get() function can avoid to add SoC specific code to
scmi_agent-uclass.c.

Signed-off-by: Alice Guo <alice.guo@nxp.com>
drivers/clk/clk_scmi.c
drivers/firmware/scmi/scmi_agent-uclass.c
drivers/power/domain/scmi-power-domain.c
drivers/power/regulator/scmi_regulator.c
drivers/reset/reset-scmi.c

index e42d203..b8d40cc 100644 (file)
@@ -8,6 +8,7 @@
 #include <clk-uclass.h>
 #include <dm.h>
 #include <scmi_agent.h>
+#include <scmi_agent-uclass.h>
 #include <scmi_protocols.h>
 #include <asm/types.h>
 #include <linux/clk-provider.h>
@@ -191,3 +192,10 @@ U_BOOT_DRIVER(scmi_clock) = {
        .ops = &scmi_clk_ops,
        .probe = scmi_clk_probe,
 };
+
+static struct scmi_proto_match match[] = {
+       { .proto_id = SCMI_PROTOCOL_ID_CLOCK },
+       { /* Sentinel */ }
+};
+
+U_BOOT_SCMI_PROTO_DRIVER(scmi_clock, match);
index ea79cfa..cc3f31d 100644 (file)
@@ -425,31 +425,11 @@ static int scmi_bind_protocols(struct udevice *dev)
 
                drv = NULL;
                name = ofnode_get_name(node);
-               switch (protocol_id) {
-               case SCMI_PROTOCOL_ID_POWER_DOMAIN:
-                       if (CONFIG_IS_ENABLED(SCMI_POWER_DOMAIN) &&
-                           scmi_protocol_is_supported(dev, protocol_id))
-                               drv = DM_DRIVER_GET(scmi_power_domain);
-                       break;
-               case SCMI_PROTOCOL_ID_CLOCK:
-                       if (CONFIG_IS_ENABLED(CLK_SCMI) &&
-                           scmi_protocol_is_supported(dev, protocol_id))
-                               drv = DM_DRIVER_GET(scmi_clock);
-                       break;
-               case SCMI_PROTOCOL_ID_RESET_DOMAIN:
-                       if (IS_ENABLED(CONFIG_RESET_SCMI) &&
-                           scmi_protocol_is_supported(dev, protocol_id))
-                               drv = DM_DRIVER_GET(scmi_reset_domain);
-                       break;
-               case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN:
-                       if (IS_ENABLED(CONFIG_DM_REGULATOR_SCMI) &&
-                           scmi_protocol_is_supported(dev, protocol_id))
-                               drv = DM_DRIVER_GET(scmi_voltage_domain);
-                       break;
-               default:
-                       break;
-               }
 
+               if (!scmi_protocol_is_supported(dev, protocol_id))
+                       continue;
+
+               drv = scmi_proto_driver_get(protocol_id);
                if (!drv) {
                        dev_dbg(dev, "Ignore unsupported SCMI protocol %#x\n",
                                protocol_id);
index 3cd0f07..e8c0ba8 100644 (file)
@@ -11,6 +11,7 @@
 #include <power-domain.h>
 #include <power-domain-uclass.h>
 #include <scmi_agent.h>
+#include <scmi_agent-uclass.h>
 #include <scmi_protocols.h>
 #include <dm/device_compat.h>
 
@@ -190,3 +191,10 @@ U_BOOT_DRIVER(scmi_power_domain) = {
        .probe = scmi_power_domain_probe,
        .priv_auto = sizeof(struct scmi_power_domain_priv),
 };
+
+static struct scmi_proto_match match[] = {
+       { .proto_id = SCMI_PROTOCOL_ID_POWER_DOMAIN },
+       { /* Sentinel */ }
+};
+
+U_BOOT_SCMI_PROTO_DRIVER(scmi_power_domain, match);
index 79db1a6..7d2db1e 100644 (file)
@@ -8,6 +8,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <scmi_agent.h>
+#include <scmi_agent-uclass.h>
 #include <scmi_protocols.h>
 #include <asm/types.h>
 #include <dm/device.h>
@@ -202,3 +203,10 @@ U_BOOT_DRIVER(scmi_voltage_domain) = {
        .id = UCLASS_NOP,
        .bind = scmi_regulator_bind,
 };
+
+static struct scmi_proto_match match[] = {
+       { .proto_id = SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN },
+       { /* Sentinel */ }
+};
+
+U_BOOT_SCMI_PROTO_DRIVER(scmi_voltage_domain, match);
index 6dc1fcb..f92a9e3 100644 (file)
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <reset-uclass.h>
 #include <scmi_agent.h>
+#include <scmi_agent-uclass.h>
 #include <scmi_protocols.h>
 #include <asm/types.h>
 
@@ -81,3 +82,10 @@ U_BOOT_DRIVER(scmi_reset_domain) = {
        .ops = &scmi_reset_domain_ops,
        .probe = scmi_reset_probe,
 };
+
+static struct scmi_proto_match match[] = {
+       { .proto_id = SCMI_PROTOCOL_ID_RESET_DOMAIN },
+       { /* Sentinel */ }
+};
+
+U_BOOT_SCMI_PROTO_DRIVER(scmi_reset_domain, match);