gpio: mxc_gpio: Fix i.MX8M GPIO output status read
Subsystems (2)
PATCH 1/1 gpio: mxc_gpio: Fix i.MX8M GPIO output status read
Currently the driver gets value from PSR register, but this register is only for input mode. For output mode, it always returns 0, not the value we set for output.
This patch changes to use DR register, which returns the DR value for output mode, and PSR value for input mode.
This patch is based on code from Ye Li <[email protected]>
---
drivers/gpio/mxc_gpio.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/gpio/mxc_gpio.c +13 -7
@@ -36,6 +36,17 @@ struct mxc_bank_info {struct gpio_regs *regs; }; +static int gpio_bank_get_value (struct gpio_regs *regs,int offset) +{ +u32 gpio_val; + +if (IS_ENABLED (CONFIG_ARCH_IMX8M )) + gpio_val =readl (®s->gpio_dr); +else + gpio_val =readl (®s->gpio_psr); +return (gpio_val >> offset) &0x01 ; +} +#if !CONFIG_IS_ENABLED (DM_GPIO )#define GPIO_TO_PORT (n) ((n) / 32)
@@ -125,18 +136,13 @@ int gpio_get_value(unsigned gpio) {unsigned int port =GPIO_TO_PORT (gpio);struct gpio_regs *regs; -u32 val; -if (port >=ARRAY_SIZE (gpio_ports))return -1 ; gpio &=0x1f ; regs = (struct gpio_regs *)gpio_ports[port]; - - val = (readl (®s->gpio_psr) >> gpio) &0x01 ; - -return val; +return gpio_bank_get_value (regs, gpio); }int gpio_request (unsigned gpio,const char *label)
@@ -211,7 +217,7 @@ static void mxc_gpio_bank_set_value(struct gpio_regs *regs, int offset,static int mxc_gpio_bank_get_value (struct gpio_regs *regs,int offset) { -return (readl (®s->gpio_psr) >> offset) &0x01 ; +return gpio_bank_get_value (regs, offset); }/* set GPIO pin 'gpio' as an input */
Signature · 1 line
2.32.0
Fabio Estevam
reviewerHi Harm and Ye Li,
Quoted 9 lines · Harm Berntsen
Currently the driver gets value from PSR register, but this register is only for input mode. For output mode, it always returns 0, not the value we set for output.
This patch changes to use DR register, which returns the DR value for output mode, and PSR value for input mode.
This patch is based on code from Ye Li <[email protected]>
Could this issue be fixed by setting the SION bit mode?
Hi Fabio Estevam and Ye Li,
Quoted 11 lines · Fabio Estevam
Hi Harm and Ye Li,
Quoted 7 lines · Harm Berntsen
Currently the driver gets value from PSR register, but this register is
only for input mode. For output mode, it always returns 0, not the value
we set for output.
Quoted 7 lines
Quoted 5 lines
This patch changes to use DR register, which returns the DR value for
output mode, and PSR value for input mode.This patch is based on code from Ye Li <[email protected]>
Could this issue be fixed by setting the SION bit mode?
SION works! I did not know about it :). I see the imxrt1020-evk, imxrt1050-evk and imx53-kp use it in their device tree. To make this feature available, I had to ensure the IMX_PAD_SION was available in my dts by adding a define:
#define IMX_PAD_SION 0x40000000
I could then configure the pinmux in my dts file. It would be nice to make this define available by default.
To conclude, I would now need to enable SION in order to remove the 'Warning: value of pin is still 0' text in my serial output. I'm fine with that.
Fabio Estevam
reviewerHi Harm,
Adding Angus, who submitted a similar patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
Quoted 3 lines · Harm Berntsen
Quoted 1 line
Could this issue be fixed by setting the SION bit mode?
SION works! I did not know about it :). I see the imxrt1020-evk,
Ok, great!
Quoted 4 lines
imxrt1050-evk and imx53-kp use it in their device tree. To make this feature available, I had to ensure the
IMX_PAD_SIONwas available in my dts by adding a define:
Quoted 8 lines
#define
IMX_PAD_SION0x40000000I could then configure the pinmux in my dts file. It would be nice to make this define available by default.
To conclude, I would now need to enable SION in order to remove the 'Warning: value of pin is still 0' text in my serial output. I'm fine with that.
Actually, there are several i.MX dts files that set bit 30 (SION bit):
For example, the I2C pins in imx8mq-evk.dts look like this:
MX8MQ_IOMUXC_I2C1_SCL_I2C1_SCL 0x4000007f
Does it work if you just set bit 30 in your device tree? Which SoC are you using?
Hi,
Quoted 34 lines · Fabio Estevam
Hi Harm,
Adding Angus, who submitted a similar patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Quoted 3 lines · Harm Berntsen
Quoted 1 line
Could this issue be fixed by setting the SION bit mode?
SION works! I did not know about it :). I see the imxrt1020-evk,
Ok, great!
Quoted 8 lines
imxrt1050-evk and imx53-kp use it in their device tree. To make this
feature available, I had to ensure theIMX_PAD_SIONwas available in my
dts by adding a define:#define IMX_PAD_SION
0x40000000Quoted 8 lines
I could then configure the pinmux in my dts file. It would be nice to
make this define available by default.To conclude, I would now need to enable SION in order to remove the 'Warning: value of pin is still 0' text in my serial output. I'm fine
with that.Actually, there are several i.MX dts files that set bit 30 (SION bit):
Quoted 7 lines
For example, the I2C pins in
imx8mq-evk.dtslook like this:
MX8MQ_IOMUXC_I2C1_SCL_I2C1_SCL0x4000007fDoes it work if you just set bit 30 in your device tree? Which SoC are
you using?
I did not check the manual assignment of bit 30 in the dts, I now see that it is used more often than I thought.
I'm using an imx8mn on U-Boot 2021.10. It was as simple as setting the pinctrl as you described and in the same way as Angus has done. I don't see why it does not work for him. He has an imx8mq so maybe that chip behaves differently?
Just for completeness, some snippets from my device tree:
#define IMX_PAD_SION 0x40000000
&gpio3 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_misc_gpio3>;
};pinctrl_misc_gpio3: misc-gpio3 {
fsl,pins = <
MX8MN_IOMUXC_SAI5_RXD2_GPIO3_IO23 IMX_PAD_SION
MX8MN_IOMUXC_SAI5_RXD3_GPIO3_IO24 IMX_PAD_SION
>;
};Fabio Estevam
reviewerQuoted 7 lines · Harm Berntsen
I did not check the manual assignment of bit 30 in the dts, I now see that it is used more often than I thought.
I'm using an imx8mn on U-Boot 2021.10. It was as simple as setting the pinctrl as you described and in the same way as Angus has done. I don't see why it does not work for him. He has an imx8mq so maybe that chip behaves differently?
After reading Angus' thread again, maybe there is an issue with his dts, where he uses pinctrl_hog1 and pinctrl_hog3.
I suspect that these pinctrl groups are not getting initialized at all.
To confirm that I would suggest Angus look at the IOMUXC_SW_MUX_CTL_PAD registers contents and verify whether the SION bit is set or not.
Another suggestion is to group all hog pins into pinctrl_hog instead.
Quoted 16 lines
Just for completeness, some snippets from my device tree:
#define
IMX_PAD_SION0x40000000&gpio3 { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_misc_gpio3>; };
pinctrl_misc_gpio3: misc-gpio3 {
fsl,pins = <
MX8MN_IOMUXC_SAI5_RXD2_GPIO3_IO23IMX_PAD_SION
MX8MN_IOMUXC_SAI5_RXD3_GPIO3_IO24IMX_PAD_SION
>;
};