1 // SPDX-License-Identifier: GPL-2.0+
6 #include <linux/firmware/imx/sm.h>
7 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/scmi_protocol.h>
11 #include <linux/scmi_imx_protocol.h>
13 static const struct scmi_imx_misc_proto_ops *imx_misc_ctrl_ops;
14 static struct scmi_protocol_handle *ph;
15 struct notifier_block scmi_imx_misc_ctrl_nb;
17 int scmi_imx_misc_ctrl_set(u32 id, u32 val)
22 return imx_misc_ctrl_ops->misc_ctrl_set(ph, id, 1, &val);
24 EXPORT_SYMBOL(scmi_imx_misc_ctrl_set);
26 int scmi_imx_misc_ctrl_get(u32 id, u32 *num, u32 *val)
31 return imx_misc_ctrl_ops->misc_ctrl_get(ph, id, num, val);
33 EXPORT_SYMBOL(scmi_imx_misc_ctrl_get);
35 static int scmi_imx_misc_ctrl_notifier(struct notifier_block *nb,
36 unsigned long event, void *data)
39 * notifier_chain_register requires a valid notifier_block and
40 * valid notifier_call. SCMI_EVENT_IMX_MISC_CONTROL is needed
41 * to let SCMI firmware enable control events, but the hook here
42 * is just a dummy function to avoid kernel panic as of now.
47 static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev)
49 const struct scmi_handle *handle = sdev->handle;
50 struct device_node *np = sdev->dev.of_node;
57 if (imx_misc_ctrl_ops) {
58 dev_err(&sdev->dev, "misc ctrl already initialized\n");
62 imx_misc_ctrl_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_IMX_MISC, &ph);
63 if (IS_ERR(imx_misc_ctrl_ops))
64 return PTR_ERR(imx_misc_ctrl_ops);
66 num = of_property_count_u32_elems(np, "nxp,ctrl-ids");
68 dev_err(&sdev->dev, "Invalid wakeup-sources\n");
72 scmi_imx_misc_ctrl_nb.notifier_call = &scmi_imx_misc_ctrl_notifier;
73 for (i = 0; i < num; i += 2) {
74 ret = of_property_read_u32_index(np, "nxp,ctrl-ids", i, &src_id);
76 dev_err(&sdev->dev, "Failed to read ctrl-id: %i\n", i);
80 ret = of_property_read_u32_index(np, "nxp,ctrl-ids", i + 1, &flags);
82 dev_err(&sdev->dev, "Failed to read ctrl-id value: %d\n", i + 1);
86 ret = handle->notify_ops->devm_event_notifier_register(sdev, SCMI_PROTOCOL_IMX_MISC,
87 SCMI_EVENT_IMX_MISC_CONTROL,
89 &scmi_imx_misc_ctrl_nb);
91 dev_err(&sdev->dev, "Failed to register scmi misc event: %d\n", src_id);
93 ret = imx_misc_ctrl_ops->misc_ctrl_req_notify(ph, src_id,
94 SCMI_EVENT_IMX_MISC_CONTROL,
97 dev_err(&sdev->dev, "Failed to req notify: %d\n", src_id);
104 static const struct scmi_device_id scmi_id_table[] = {
105 { SCMI_PROTOCOL_IMX_MISC, "imx-misc-ctrl" },
108 MODULE_DEVICE_TABLE(scmi, scmi_id_table);
110 static struct scmi_driver scmi_imx_misc_ctrl_driver = {
111 .name = "scmi-imx-misc-ctrl",
112 .probe = scmi_imx_misc_ctrl_probe,
113 .id_table = scmi_id_table,
115 module_scmi_driver(scmi_imx_misc_ctrl_driver);
118 MODULE_DESCRIPTION("IMX SM MISC driver");
119 MODULE_LICENSE("GPL");