From: Alice Guo <alice....@nxp.com>

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....@nxp.com>
---
 drivers/clk/clk_scmi.c                    |  8 +++++++
 drivers/firmware/scmi/scmi_agent-uclass.c | 28 ++++-------------------
 drivers/power/domain/scmi-power-domain.c  |  8 +++++++
 drivers/power/regulator/scmi_regulator.c  |  8 +++++++
 drivers/reset/reset-scmi.c                |  8 +++++++
 5 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c
index e42d2032d45..b8d40cc9653 100644
--- a/drivers/clk/clk_scmi.c
+++ b/drivers/clk/clk_scmi.c
@@ -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);
diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c 
b/drivers/firmware/scmi/scmi_agent-uclass.c
index ea79cfa0cf2..cc3f31d881e 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -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);
diff --git a/drivers/power/domain/scmi-power-domain.c 
b/drivers/power/domain/scmi-power-domain.c
index 3cd0f075d95..e8c0ba8878e 100644
--- a/drivers/power/domain/scmi-power-domain.c
+++ b/drivers/power/domain/scmi-power-domain.c
@@ -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);
diff --git a/drivers/power/regulator/scmi_regulator.c 
b/drivers/power/regulator/scmi_regulator.c
index 79db1a6a8aa..7d2db1e2bee 100644
--- a/drivers/power/regulator/scmi_regulator.c
+++ b/drivers/power/regulator/scmi_regulator.c
@@ -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);
diff --git a/drivers/reset/reset-scmi.c b/drivers/reset/reset-scmi.c
index 6dc1fcb3365..f92a9e35579 100644
--- a/drivers/reset/reset-scmi.c
+++ b/drivers/reset/reset-scmi.c
@@ -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);
-- 
2.43.0

Reply via email to