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 struct imx_sc_msg_misc_get_soc_uid {
31 struct imx_sc_rpc_msg hdr;
36 static ssize_t soc_uid_show(struct device *dev,
37 struct device_attribute *attr, char *buf)
39 struct imx_sc_msg_misc_get_soc_uid msg;
40 struct imx_sc_rpc_msg *hdr = &msg.hdr;
44 hdr->ver = IMX_SC_RPC_VERSION;
45 hdr->svc = IMX_SC_RPC_SVC_MISC;
46 hdr->func = IMX_SC_MISC_FUNC_UNIQUE_ID;
49 ret = imx_scu_call_rpc(soc_ipc_handle, &msg, false);
51 pr_err("%s: get soc uid failed, ret %d\n", __func__, ret);
55 soc_uid = msg.uid_high;
57 soc_uid |= msg.uid_low;
59 return sprintf(buf, "%016llX\n", soc_uid);
62 static DEVICE_ATTR_RO(soc_uid);
64 static int imx_scu_soc_id(void)
66 struct imx_sc_msg_misc_get_soc_id msg;
67 struct imx_sc_rpc_msg *hdr = &msg.hdr;
70 hdr->ver = IMX_SC_RPC_VERSION;
71 hdr->svc = IMX_SC_RPC_SVC_MISC;
72 hdr->func = IMX_SC_MISC_FUNC_GET_CONTROL;
75 msg.data.req.control = IMX_SC_C_ID;
76 msg.data.req.resource = IMX_SC_R_SYSTEM;
78 ret = imx_scu_call_rpc(soc_ipc_handle, &msg, true);
80 pr_err("%s: get soc info failed, ret %d\n", __func__, ret);
84 return msg.data.resp.id;
87 static int imx_scu_soc_probe(struct platform_device *pdev)
89 struct soc_device_attribute *soc_dev_attr;
90 struct soc_device *soc_dev;
94 ret = imx_scu_get_handle(&soc_ipc_handle);
98 soc_dev_attr = devm_kzalloc(&pdev->dev, sizeof(*soc_dev_attr),
103 soc_dev_attr->family = "Freescale i.MX";
105 ret = of_property_read_string(of_root,
107 &soc_dev_attr->machine);
111 id = imx_scu_soc_id();
115 /* format soc_id value passed from SCU firmware */
117 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "0x%x", val);
118 if (!soc_dev_attr->soc_id)
121 /* format revision value passed from SCU firmware */
122 val = (id >> 5) & 0xf;
123 val = (((val >> 2) + 1) << 4) | (val & 0x3);
124 soc_dev_attr->revision = kasprintf(GFP_KERNEL,
128 if (!soc_dev_attr->revision) {
133 soc_dev = soc_device_register(soc_dev_attr);
134 if (IS_ERR(soc_dev)) {
135 ret = PTR_ERR(soc_dev);
139 ret = device_create_file(soc_device_to_device(soc_dev),
147 kfree(soc_dev_attr->revision);
149 kfree(soc_dev_attr->soc_id);
153 static struct platform_driver imx_scu_soc_driver = {
155 .name = IMX_SCU_SOC_DRIVER_NAME,
157 .probe = imx_scu_soc_probe,
160 static int __init imx_scu_soc_init(void)
162 struct platform_device *pdev;
163 struct device_node *np;
166 np = of_find_compatible_node(NULL, NULL, "fsl,imx-scu");
172 ret = platform_driver_register(&imx_scu_soc_driver);
176 pdev = platform_device_register_simple(IMX_SCU_SOC_DRIVER_NAME,
179 platform_driver_unregister(&imx_scu_soc_driver);
181 return PTR_ERR_OR_ZERO(pdev);
183 device_initcall(imx_scu_soc_init);