[PATCH v2] pinctrl: imx: Use of_device_id match table for per-SoC data
From: joy . zou
Date: Fri Nov 20 2026 - 05:46:51 EST
From: Peng Fan <peng.fan@xxxxxxx>
Replace the hardcoded of_machine_is_compatible() if-else chain and the
static string allowlist with a proper of_device_id match table carrying
per-SoC data via the .data field.
This eliminates the static local variable anti-pattern for daisy_off
(lazy-initialized, shared across instances) and adopts the idiomatic
kernel of_machine_get_match_data() APIs.
A new pinctrl_scmi_imx_data struct captures the daisy register offset
for future extensibility when new SoCs may not use register-offset based
daisy configuration.
No functional changes.
Reviewed-by: Frank Li <Frank.Li@xxxxxxx>
Signed-off-by: Peng Fan <peng.fan@xxxxxxx>
Signed-off-by: Joy Zou <joy.zou@xxxxxxx>
---
Replace the hardcoded of_machine_is_compatible() if-else chain and the
static string allowlist with an of_device_id match table that carries the
per-SoC daisy register offset in its .data field.
This drops the lazily-initialized "static uint32_t daisy_off" local and
lets probe do the compatible match and per-SoC data lookup in one step
via of_machine_get_match_data().
No functional change intended.
Signed-off-by: Joy Zou <joy.zou@xxxxxxxxxxx>
---
Changes in v2:
- remove redundant pmx->data check.
- add Reviewed-by tag.
- Link to v1: https://patch.msgid.link/20261019-b4-imx937-frdm-scmi-pinctrl-v1-1-0576fb20964b@xxxxxxxxxxx
---
Changes in v2:
- remove redundant pmx->data check.
- add Reviewed-by tag.
- Link to v1: https://patch.msgid.link/20261019-b4-imx937-frdm-scmi-pinctrl-v1-1-0576fb20964b@xxxxxxxxxxx
---
drivers/pinctrl/freescale/pinctrl-imx-scmi.c | 52 ++++++++++++++++------------
1 file changed, 30 insertions(+), 22 deletions(-)
diff --git a/drivers/pinctrl/freescale/pinctrl-imx-scmi.c b/drivers/pinctrl/freescale/pinctrl-imx-scmi.c
index 7c3860f890c9..1d1f2fea3a49 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx-scmi.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx-scmi.c
@@ -28,12 +28,17 @@
#define DRV_NAME "scmi-pinctrl-imx"
+struct pinctrl_scmi_imx_data {
+ uint32_t daisy_off;
+};
+
struct scmi_pinctrl_imx {
struct device *dev;
struct scmi_protocol_handle *ph;
struct pinctrl_dev *pctldev;
struct pinctrl_desc pctl_desc;
const struct scmi_pinctrl_proto_ops *ops;
+ const struct pinctrl_scmi_imx_data *data;
};
/* SCMI pin control types, aligned with SCMI firmware */
@@ -59,6 +64,7 @@ static int pinctrl_scmi_imx_dt_node_to_map(struct pinctrl_dev *pctldev,
struct pinctrl_map **map,
unsigned int *num_maps)
{
+ struct scmi_pinctrl_imx *pmx = pinctrl_dev_get_drvdata(pctldev);
struct pinctrl_map *new_map;
const __be32 *list;
unsigned long *configs = NULL;
@@ -67,20 +73,9 @@ static int pinctrl_scmi_imx_dt_node_to_map(struct pinctrl_dev *pctldev,
int mux_reg, conf_reg, input_reg, mux_val, conf_val, input_val;
int i, j;
uint32_t ncfg;
- static uint32_t daisy_off;
-
- if (!daisy_off) {
- if (of_machine_is_compatible("fsl,imx95")) {
- daisy_off = IMX95_DAISY_OFF;
- } else if (of_machine_is_compatible("fsl,imx94")) {
- daisy_off = IMX94_DAISY_OFF;
- } else if (of_machine_is_compatible("fsl,imx952")) {
- daisy_off = IMX952_DAISY_OFF;
- } else {
- dev_err(pctldev->dev, "platform not support scmi pinctrl\n");
- return -EINVAL;
- }
- }
+ uint32_t daisy_off;
+
+ daisy_off = pmx->data->daisy_off;
list = of_get_property(np, "fsl,pins", &size);
if (!list) {
@@ -293,11 +288,23 @@ scmi_pinctrl_imx_get_pins(struct scmi_pinctrl_imx *pmx, struct pinctrl_desc *des
return 0;
}
-static const char * const scmi_pinctrl_imx_allowlist[] = {
- "fsl,imx94",
- "fsl,imx95",
- "fsl,imx952",
- NULL
+static const struct pinctrl_scmi_imx_data imx94_pin_data = {
+ .daisy_off = IMX94_DAISY_OFF,
+};
+
+static const struct pinctrl_scmi_imx_data imx95_pin_data = {
+ .daisy_off = IMX95_DAISY_OFF,
+};
+
+static const struct pinctrl_scmi_imx_data imx952_pin_data = {
+ .daisy_off = IMX952_DAISY_OFF,
+};
+
+static const struct of_device_id scmi_pinctrl_imx_data[] = {
+ { .compatible = "fsl,imx94", .data = &imx94_pin_data, },
+ { .compatible = "fsl,imx95", .data = &imx95_pin_data, },
+ { .compatible = "fsl,imx952", .data = &imx952_pin_data, },
+ { }
};
static int scmi_pinctrl_imx_probe(struct scmi_device *sdev)
@@ -312,9 +319,6 @@ static int scmi_pinctrl_imx_probe(struct scmi_device *sdev)
if (!handle)
return -EINVAL;
- if (!of_machine_compatible_match(scmi_pinctrl_imx_allowlist))
- return -ENODEV;
-
pinctrl_ops = handle->devm_protocol_get(sdev, SCMI_PROTOCOL_PINCTRL, &ph);
if (IS_ERR(pinctrl_ops))
return PTR_ERR(pinctrl_ops);
@@ -323,6 +327,10 @@ static int scmi_pinctrl_imx_probe(struct scmi_device *sdev)
if (!pmx)
return -ENOMEM;
+ pmx->data = of_machine_get_match_data(scmi_pinctrl_imx_data);
+ if (!pmx->data)
+ return -ENODEV;
+
pmx->ph = ph;
pmx->ops = pinctrl_ops;
---
base-commit: adcad7f4e6332cff3d6d7165f41584899f598534
change-id: 20261019-b4-imx937-frdm-scmi-pinctrl-7bce28f895f7
Best regards,
--
Joy Zou <joy.zou@xxxxxxxxxxx>