1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright 2025 NXP
4 */
5
6 #include <linux/firmware/imx/sm.h>
7 #include <linux/module.h>
8 #include <linux/of.h>
9 #include <linux/platform_device.h>
10 #include <linux/scmi_protocol.h>
11 #include <linux/scmi_imx_protocol.h>
12
13 static const struct scmi_imx_cpu_proto_ops *imx_cpu_ops;
14 static struct scmi_protocol_handle *ph;
15
scmi_imx_cpu_reset_vector_set(u32 cpuid,u64 vector,bool start,bool boot,bool resume)16 int scmi_imx_cpu_reset_vector_set(u32 cpuid, u64 vector, bool start, bool boot,
17 bool resume)
18 {
19 if (!ph)
20 return -EPROBE_DEFER;
21
22 return imx_cpu_ops->cpu_reset_vector_set(ph, cpuid, vector, start,
23 boot, resume);
24 }
25 EXPORT_SYMBOL(scmi_imx_cpu_reset_vector_set);
26
scmi_imx_cpu_start(u32 cpuid,bool start)27 int scmi_imx_cpu_start(u32 cpuid, bool start)
28 {
29 if (!ph)
30 return -EPROBE_DEFER;
31
32 if (start)
33 return imx_cpu_ops->cpu_start(ph, cpuid, true);
34
35 return imx_cpu_ops->cpu_start(ph, cpuid, false);
36 };
37 EXPORT_SYMBOL(scmi_imx_cpu_start);
38
scmi_imx_cpu_started(u32 cpuid,bool * started)39 int scmi_imx_cpu_started(u32 cpuid, bool *started)
40 {
41 if (!ph)
42 return -EPROBE_DEFER;
43
44 if (!started)
45 return -EINVAL;
46
47 return imx_cpu_ops->cpu_started(ph, cpuid, started);
48 };
49 EXPORT_SYMBOL(scmi_imx_cpu_started);
50
scmi_imx_cpu_probe(struct scmi_device * sdev)51 static int scmi_imx_cpu_probe(struct scmi_device *sdev)
52 {
53 const struct scmi_handle *handle = sdev->handle;
54
55 if (!handle)
56 return -ENODEV;
57
58 if (imx_cpu_ops) {
59 dev_err(&sdev->dev, "sm cpu already initialized\n");
60 return -EEXIST;
61 }
62
63 imx_cpu_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_IMX_CPU, &ph);
64 if (IS_ERR(imx_cpu_ops))
65 return PTR_ERR(imx_cpu_ops);
66
67 return 0;
68 }
69
70 static const struct scmi_device_id scmi_id_table[] = {
71 { SCMI_PROTOCOL_IMX_CPU, "imx-cpu" },
72 { },
73 };
74 MODULE_DEVICE_TABLE(scmi, scmi_id_table);
75
76 static struct scmi_driver scmi_imx_cpu_driver = {
77 .name = "scmi-imx-cpu",
78 .probe = scmi_imx_cpu_probe,
79 .id_table = scmi_id_table,
80 };
81 module_scmi_driver(scmi_imx_cpu_driver);
82
83 MODULE_AUTHOR("Peng Fan <peng.fan@nxp.com>");
84 MODULE_DESCRIPTION("IMX SM CPU driver");
85 MODULE_LICENSE("GPL");
86