1 // SPDX-License-Identifier: GPL-2.0
6 #include <dt-bindings/firmware/imx/rsrc.h>
7 #include <linux/firmware/imx/sci.h>
8 #include <linux/slab.h>
9 #include <linux/sys_soc.h>
10 #include <linux/platform_device.h>
13 #define IMX_SCU_SOC_DRIVER_NAME "imx-scu-soc"
15 static struct imx_sc_ipc *soc_ipc_handle;
17 struct imx_sc_msg_misc_get_soc_id {
18 struct imx_sc_rpc_msg hdr;
30 static int imx_scu_soc_id(void)
32 struct imx_sc_msg_misc_get_soc_id msg;
33 struct imx_sc_rpc_msg *hdr = &msg.hdr;
36 hdr->ver = IMX_SC_RPC_VERSION;
37 hdr->svc = IMX_SC_RPC_SVC_MISC;
38 hdr->func = IMX_SC_MISC_FUNC_GET_CONTROL;
41 msg.data.req.control = IMX_SC_C_ID;
42 msg.data.req.resource = IMX_SC_R_SYSTEM;
44 ret = imx_scu_call_rpc(soc_ipc_handle, &msg, true);
46 pr_err("%s: get soc info failed, ret %d\n", __func__, ret);
50 return msg.data.resp.id;
53 static int imx_scu_soc_probe(struct platform_device *pdev)
55 struct soc_device_attribute *soc_dev_attr;
56 struct soc_device *soc_dev;
60 ret = imx_scu_get_handle(&soc_ipc_handle);
64 soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr),
69 soc_dev_attr->family = "Freescale i.MX";
71 ret = of_property_read_string(of_root,
73 &soc_dev_attr->machine);
77 id = imx_scu_soc_id();
81 /* format soc_id value passed from SCU firmware */
83 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "0x%x", val);
84 if (!soc_dev_attr->soc_id)
87 /* format revision value passed from SCU firmware */
88 val = (id >> 5) & 0xf;
89 val = (((val >> 2) + 1) << 4) | (val & 0x3);
90 soc_dev_attr->revision = kasprintf(GFP_KERNEL,
94 if (!soc_dev_attr->revision) {
99 soc_dev = soc_device_register(soc_dev_attr);
100 if (IS_ERR(soc_dev)) {
101 ret = PTR_ERR(soc_dev);
108 kfree(soc_dev_attr->revision);
110 kfree(soc_dev_attr->soc_id);
114 static struct platform_driver imx_scu_soc_driver = {
116 .name = IMX_SCU_SOC_DRIVER_NAME,
118 .probe = imx_scu_soc_probe,
121 static int __init imx_scu_soc_init(void)
123 struct platform_device *pdev;
124 struct device_node *np;
127 np = of_find_compatible_node(NULL, NULL, "fsl,imx-scu");
133 ret = platform_driver_register(&imx_scu_soc_driver);
137 pdev = platform_device_register_simple(IMX_SCU_SOC_DRIVER_NAME,
140 platform_driver_unregister(&imx_scu_soc_driver);
142 return PTR_ERR_OR_ZERO(pdev);
144 device_initcall(imx_scu_soc_init);