Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: imx: Add i.MX95 MISC driver

The i.MX95 System manager exports SCMI MISC protocol for linux to do
various settings, such as set board gpio expander as wakeup source.

The driver is to add the support.

Reviewed-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Message-Id: <20240823-imx95-bbm-misc-v2-v8-5-e600ed9e9271@nxp.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

authored by

Peng Fan and committed by
Sudeep Holla
0b4f8a68 61c9f03e

+165
+11
drivers/firmware/imx/Kconfig
··· 22 22 23 23 This driver manages the IPC interface between host CPU and the 24 24 SCU firmware running on M4. 25 + 26 + config IMX_SCMI_MISC_DRV 27 + tristate "IMX SCMI MISC Protocol driver" 28 + depends on IMX_SCMI_MISC_EXT || COMPILE_TEST 29 + default y if ARCH_MXC 30 + help 31 + The System Controller Management Interface firmware (SCMI FW) is 32 + a low-level system function which runs on a dedicated Cortex-M 33 + core that could provide misc functions such as board control. 34 + 35 + This driver can also be built as a module.
+1
drivers/firmware/imx/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 obj-$(CONFIG_IMX_DSP) += imx-dsp.o 3 3 obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o 4 + obj-${CONFIG_IMX_SCMI_MISC_DRV} += sm-misc.o
+119
drivers/firmware/imx/sm-misc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Copyright 2024 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_misc_proto_ops *imx_misc_ctrl_ops; 14 + static struct scmi_protocol_handle *ph; 15 + struct notifier_block scmi_imx_misc_ctrl_nb; 16 + 17 + int scmi_imx_misc_ctrl_set(u32 id, u32 val) 18 + { 19 + if (!ph) 20 + return -EPROBE_DEFER; 21 + 22 + return imx_misc_ctrl_ops->misc_ctrl_set(ph, id, 1, &val); 23 + }; 24 + EXPORT_SYMBOL(scmi_imx_misc_ctrl_set); 25 + 26 + int scmi_imx_misc_ctrl_get(u32 id, u32 *num, u32 *val) 27 + { 28 + if (!ph) 29 + return -EPROBE_DEFER; 30 + 31 + return imx_misc_ctrl_ops->misc_ctrl_get(ph, id, num, val); 32 + } 33 + EXPORT_SYMBOL(scmi_imx_misc_ctrl_get); 34 + 35 + static int scmi_imx_misc_ctrl_notifier(struct notifier_block *nb, 36 + unsigned long event, void *data) 37 + { 38 + /* 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. 43 + */ 44 + return 0; 45 + } 46 + 47 + static int scmi_imx_misc_ctrl_probe(struct scmi_device *sdev) 48 + { 49 + const struct scmi_handle *handle = sdev->handle; 50 + struct device_node *np = sdev->dev.of_node; 51 + u32 src_id, flags; 52 + int ret, i, num; 53 + 54 + if (!handle) 55 + return -ENODEV; 56 + 57 + if (imx_misc_ctrl_ops) { 58 + dev_err(&sdev->dev, "misc ctrl already initialized\n"); 59 + return -EEXIST; 60 + } 61 + 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); 65 + 66 + num = of_property_count_u32_elems(np, "nxp,ctrl-ids"); 67 + if (num % 2) { 68 + dev_err(&sdev->dev, "Invalid wakeup-sources\n"); 69 + return -EINVAL; 70 + } 71 + 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); 75 + if (ret) { 76 + dev_err(&sdev->dev, "Failed to read ctrl-id: %i\n", i); 77 + continue; 78 + } 79 + 80 + ret = of_property_read_u32_index(np, "nxp,ctrl-ids", i + 1, &flags); 81 + if (ret) { 82 + dev_err(&sdev->dev, "Failed to read ctrl-id value: %d\n", i + 1); 83 + continue; 84 + } 85 + 86 + ret = handle->notify_ops->devm_event_notifier_register(sdev, SCMI_PROTOCOL_IMX_MISC, 87 + SCMI_EVENT_IMX_MISC_CONTROL, 88 + &src_id, 89 + &scmi_imx_misc_ctrl_nb); 90 + if (ret) { 91 + dev_err(&sdev->dev, "Failed to register scmi misc event: %d\n", src_id); 92 + } else { 93 + ret = imx_misc_ctrl_ops->misc_ctrl_req_notify(ph, src_id, 94 + SCMI_EVENT_IMX_MISC_CONTROL, 95 + flags); 96 + if (ret) 97 + dev_err(&sdev->dev, "Failed to req notify: %d\n", src_id); 98 + } 99 + } 100 + 101 + return 0; 102 + } 103 + 104 + static const struct scmi_device_id scmi_id_table[] = { 105 + { SCMI_PROTOCOL_IMX_MISC, "imx-misc-ctrl" }, 106 + { }, 107 + }; 108 + MODULE_DEVICE_TABLE(scmi, scmi_id_table); 109 + 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, 114 + }; 115 + module_scmi_driver(scmi_imx_misc_ctrl_driver); 116 + 117 + MODULE_AUTHOR("Peng Fan <peng.fan@nxp.com>"); 118 + MODULE_DESCRIPTION("IMX SM MISC driver"); 119 + MODULE_LICENSE("GPL");
+34
include/linux/firmware/imx/sm.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0+ */ 2 + /* 3 + * Copyright 2024 NXP 4 + */ 5 + 6 + #ifndef _SCMI_IMX_H 7 + #define _SCMI_IMX_H 8 + 9 + #include <linux/bitfield.h> 10 + #include <linux/errno.h> 11 + #include <linux/types.h> 12 + 13 + #define SCMI_IMX_CTRL_PDM_CLK_SEL 0 /* AON PDM clock sel */ 14 + #define SCMI_IMX_CTRL_MQS1_SETTINGS 1 /* AON MQS settings */ 15 + #define SCMI_IMX_CTRL_SAI1_MCLK 2 /* AON SAI1 MCLK */ 16 + #define SCMI_IMX_CTRL_SAI3_MCLK 3 /* WAKE SAI3 MCLK */ 17 + #define SCMI_IMX_CTRL_SAI4_MCLK 4 /* WAKE SAI4 MCLK */ 18 + #define SCMI_IMX_CTRL_SAI5_MCLK 5 /* WAKE SAI5 MCLK */ 19 + 20 + #if IS_ENABLED(CONFIG_IMX_SCMI_MISC_EXT) 21 + int scmi_imx_misc_ctrl_get(u32 id, u32 *num, u32 *val); 22 + int scmi_imx_misc_ctrl_set(u32 id, u32 val); 23 + #else 24 + static inline int scmi_imx_misc_ctrl_get(u32 id, u32 *num, u32 *val) 25 + { 26 + return -EOPNOTSUPP; 27 + } 28 + 29 + static inline int scmi_imx_misc_ctrl_set(u32 id, u32 val); 30 + { 31 + return -EOPNOTSUPP; 32 + } 33 + #endif 34 + #endif