[PATCH 2/3] pinctrl: imx-scmi: Get daisy register offset from DT

Peng Fan (OSS) posted 3 patches 7 months, 1 week ago
[PATCH 2/3] pinctrl: imx-scmi: Get daisy register offset from DT
Posted by Peng Fan (OSS) 7 months, 1 week ago
From: Peng Fan <peng.fan@nxp.com>

Parsing the "nxp,iomuxc-daisy-off" to get the daisy register offset,
then no need to hardcode the register offset in driver for new SoCs.

To keep backwards comatibility, still keep the register offset for i.MX95.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/pinctrl/freescale/pinctrl-imx-scmi.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/pinctrl/freescale/pinctrl-imx-scmi.c b/drivers/pinctrl/freescale/pinctrl-imx-scmi.c
index 8f15c4c4dc4412dddb40505699fc3f459fdc0adc..7c15244371c20e0d99b1802e480c39aaeeec495b 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx-scmi.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx-scmi.c
@@ -35,6 +35,7 @@ struct scmi_pinctrl_imx {
 	struct pinctrl_dev *pctldev;
 	struct pinctrl_desc pctl_desc;
 	const struct scmi_pinctrl_proto_ops *ops;
+	uint32_t daisy_off;
 };
 
 /* SCMI pin control types, aligned with SCMI firmware */
@@ -57,6 +58,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;
@@ -65,16 +67,6 @@ 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 {
-			dev_err(pctldev->dev, "platform not support scmi pinctrl\n");
-			return -EINVAL;
-		}
-	}
 
 	list = of_get_property(np, "fsl,pins", &size);
 	if (!list) {
@@ -126,7 +118,7 @@ static int pinctrl_scmi_imx_dt_node_to_map(struct pinctrl_dev *pctldev,
 			ncfg -= 2;
 		} else {
 			cfg[j++] = pinconf_to_config_packed(IMX_SCMI_PIN_DAISY_ID,
-							    (input_reg - daisy_off) / 4);
+							    (input_reg - pmx->daisy_off) / 4);
 			cfg[j++] = pinconf_to_config_packed(IMX_SCMI_PIN_DAISY_CFG, input_val);
 		}
 
@@ -315,6 +307,18 @@ static int scmi_pinctrl_imx_probe(struct scmi_device *sdev)
 	if (!pmx)
 		return -ENOMEM;
 
+	ret = device_property_read_u32(dev, "nxp,iomuxc-daisy-off", &pmx->daisy_off);
+	if (ret) {
+		/*
+		 * To keep backwards compatible, new chips should specify
+		 * nxp,iomuxc-daisy_off
+		 */
+		if (of_machine_is_compatible("fsl,imx95"))
+			pmx->daisy_off = IMX95_DAISY_OFF;
+		else
+			return dev_err_probe(dev, ret, "Failed to get daisy off value\n");
+	}
+
 	pmx->ph = ph;
 	pmx->ops = pinctrl_ops;
 

-- 
2.37.1
Re: [PATCH 2/3] pinctrl: imx-scmi: Get daisy register offset from DT
Posted by Sascha Hauer 7 months, 1 week ago
On Mon, May 12, 2025 at 10:14:15AM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> Parsing the "nxp,iomuxc-daisy-off" to get the daisy register offset,
> then no need to hardcode the register offset in driver for new SoCs.
> 
> To keep backwards comatibility, still keep the register offset for i.MX95.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  drivers/pinctrl/freescale/pinctrl-imx-scmi.c | 26 +++++++++++++++-----------
>  1 file changed, 15 insertions(+), 11 deletions(-)
> 
> @@ -315,6 +307,18 @@ static int scmi_pinctrl_imx_probe(struct scmi_device *sdev)
>  	if (!pmx)
>  		return -ENOMEM;
>  
> +	ret = device_property_read_u32(dev, "nxp,iomuxc-daisy-off", &pmx->daisy_off);

"off" is really a poor acronym for "offset" as it unnecessarily confuses
the reader by suggesting this is about turning some feature off. Please
add the three bytes and just call it offset.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
Re: [PATCH 2/3] pinctrl: imx-scmi: Get daisy register offset from DT
Posted by Peng Fan 7 months, 1 week ago
On Mon, May 12, 2025 at 08:17:42AM +0200, Sascha Hauer wrote:
>On Mon, May 12, 2025 at 10:14:15AM +0800, Peng Fan (OSS) wrote:
>> From: Peng Fan <peng.fan@nxp.com>
>> 
>> Parsing the "nxp,iomuxc-daisy-off" to get the daisy register offset,
>> then no need to hardcode the register offset in driver for new SoCs.
>> 
>> To keep backwards comatibility, still keep the register offset for i.MX95.
>> 
>> Signed-off-by: Peng Fan <peng.fan@nxp.com>
>> ---
>>  drivers/pinctrl/freescale/pinctrl-imx-scmi.c | 26 +++++++++++++++-----------
>>  1 file changed, 15 insertions(+), 11 deletions(-)
>> 
>> @@ -315,6 +307,18 @@ static int scmi_pinctrl_imx_probe(struct scmi_device *sdev)
>>  	if (!pmx)
>>  		return -ENOMEM;
>>  
>> +	ret = device_property_read_u32(dev, "nxp,iomuxc-daisy-off", &pmx->daisy_off);
>
>"off" is really a poor acronym for "offset" as it unnecessarily confuses
>the reader by suggesting this is about turning some feature off. Please
>add the three bytes and just call it offset.

I will use "nxp,iomuxc-daisy-offset" in V2.

Thanks,
Peng

>
>Sascha
>
>-- 
>Pengutronix e.K.                           |                             |
>Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
>31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
>Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |