Skip to contentSkip to conversation

iMX51 small fixes

PATCH New Arnaud Patard (Rtp) 4 participants 9 messages Dec 1, 2010

lore
Share & tools
lore
#0 lore raw

cover iMX51 small fixes

Hi,

This series is containing 2 small patches for iMX5 SoC.

The first one is touching at the gpiolib support. Currently, it's always returning 0 as gpio value when configured as output so I've modified it to report what we asked. I've only tested it by looking at /sys/kernel/debug/gpio so I've no idea if this can actively break something.

The second one is less interesting. It's "only" fixing a build failure so not a lot of things to say.

I've tested them against Sascha's Hauer imx-for-2.6.38 branch but they do apply on current mainline tree.

Arnaud

#2 lore raw

PATCH 1/2 imx51: fix gpiolib support

Hi,

Quoted 10 lines

The gpiolib code is always returning 0 when reading pad values if the pads are configured as output. Using DR registers instead of PSR is fixing that.

Index: linux-2.6-submit/arch/arm/plat-mxc/gpio.c
===================================================================

arch/arm/plat-mxc/gpio.c line 285

Quoted 10 lines
arch/arm/plat-mxc/gpio.c +4 -0
@@ -276,6 +276,10 @@
 {
 	struct mxc_gpio_port *port =
 		container_of(chip, struct mxc_gpio_port, chip);
+	u32 l = __raw_readl(port->base + GPIO_GDIR);
+
+	if (cpu_is_mx51() && (l & (1 << offset)))
+		return (__raw_readl(port->base + GPIO_DR) >> offset) & 1;
 
 	return (__raw_readl(port->base + GPIO_PSR) >> offset) & 1;
 }

Now you are not reading the actual pin state as with GPIO_PSR, but the value that has been programmed into the output register (thus you would not be able to determine whether an Open Drain output that is programmed to HIGH is driven LOW by an external device).

Note that for being able to read back the actual pin state of an output, the SION bit in the MUX_CTL register of the corresponding pad has to be asserted.

Lothar Wa?mann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________
#3 lore raw

PATCH 1/2 imx51: fix gpiolib support

Quoted 1 line · Lothar Wa?mann

Hi,

Hi,

Quoted 18 lines
Quoted 18 lines

The gpiolib code is always returning 0 when reading pad values if the pads are configured as output. Using DR registers instead of PSR is fixing that.

Index: linux-2.6-submit/arch/arm/plat-mxc/gpio.c
===================================================================

arch/arm/plat-mxc/gpio.c +4 -0
@@ -276,6 +276,10 @@
 {
 	struct mxc_gpio_port *port =
 		container_of(chip, struct mxc_gpio_port, chip);
+	u32 l = __raw_readl(port->base + GPIO_GDIR);
+
+	if (cpu_is_mx51() && (l & (1 << offset)))
+		return (__raw_readl(port->base + GPIO_DR) >> offset) & 1;
 
Quoted 7 lines

arch/arm/plat-mxc/gpio.c line 285

Quoted 3 lines
arch/arm/plat-mxc/gpio.c +0 -0
 	return (__raw_readl(port->base + GPIO_PSR) >> offset) & 1;
 }

Now you are not reading the actual pin state as with GPIO_PSR, but the value that has been programmed into the output register (thus you would not be able to determine whether an Open Drain output that is programmed to HIGH is driven LOW by an external device).

yeah, I know. I didn't say it was the right fix. I noticed a problem and proposed a solution.

Quoted 4 lines

Note that for being able to read back the actual pin state of an output, the SION bit in the MUX_CTL register of the corresponding pad has to be asserted.

Is it working no matter of the MUX_MODE setting ? I thought that it was working only if the MUX_MODE setting was 0 and not for every possible MUX_MODE setting.

Arnaud

#4 lore raw

PATCH 1/2 imx51: fix gpiolib support

In reply to Arnaud Patard (Rtp)

Hello Arnaud,

Quoted 9 lines · Arnaud Patard

The gpiolib code is always returning 0 when reading pad values if the pads are configured as output. Using DR registers instead of PSR is fixing that.

Index: linux-2.6-submit/arch/arm/plat-mxc/gpio.c
===================================================================

arch/arm/plat-mxc/gpio.c line 282

Quoted 7 lines
arch/arm/plat-mxc/gpio.c +4 -0
@@ -276,6 +276,10 @@
 {
 	struct mxc_gpio_port *port =
 		container_of(chip, struct mxc_gpio_port, chip);
+	u32 l = __raw_readl(port->base + GPIO_GDIR);
+
+	if (cpu_is_mx51() && (l & (1 << offset)))
+		return (__raw_readl(port->base + GPIO_DR) >> offset) & 1;

Maybe only read GDIR on mx51? Isn't the direction saved by gpiolib somewhere in RAM? Is the same needed on other SoCs, too (see below for my grouping)? Technically it's not needed at all I think. (Documentation/gpio.txt has: "However, note that not all platforms can read the value of output pins; those that can't should always return zero.". I didn't check if the implementation conforms here though.)

I wonder if cpu_is_mx51 is the right macro to test, I'd prefer something like imx_gpio_vX(). IMHO the gpio stuff needs a major overhaul getting rid of most runtime checks.

We have at least the following groups:

	mx1
	mx21, mx27
	mx25, mx31, mx35, mx51, mxc91231

("at least" in the sense that socs on different lines are different. I don't guarantee that e.g. mx35 and mxc91231 are really equivalent.)

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#5 lore raw

PATCH 1/2 imx51: fix gpiolib support

Quoted 1 line · Uwe Kleine-K?nig

Hello Arnaud,

Hi,

Quoted 16 lines · Arnaud Patard
Quoted 14 lines

The gpiolib code is always returning 0 when reading pad values if the pads are configured as output. Using DR registers instead of PSR is fixing that.

Index: linux-2.6-submit/arch/arm/plat-mxc/gpio.c
===================================================================

arch/arm/plat-mxc/gpio.c +2 -0
@@ -276,6 +276,10 @@
 {
 	struct mxc_gpio_port *port =
 		container_of(chip, struct mxc_gpio_port, chip);
+	u32 l = __raw_readl(port->base + GPIO_GDIR);
+
Quoted 8 lines

arch/arm/plat-mxc/gpio.c line 282

Quoted 2 lines
arch/arm/plat-mxc/gpio.c +2 -0
+	if (cpu_is_mx51() && (l & (1 << offset)))
+		return (__raw_readl(port->base + GPIO_DR) >> offset) & 1;

Maybe only read GDIR on mx51? Isn't the direction saved by gpiolib somewhere in RAM? Is the same needed on other SoCs, too (see below for my grouping)? Technically it's not needed at all I think. (Documentation/gpio.txt has: "However, note that not all platforms can read the value of output pins; those that can't should always return zero.". I didn't check if the implementation conforms here though.)

yeah, I know that the gpiolib allows that and in this case, it's always returning 0 but while I was debugging an other problem, I wanted to read output value and it was not working. The manual was not explicitely saying it was not possible so I thought it was a bug and propose a fix. Hopefully, sending this patch allows me to get more feedback and tell me if I got something wrong and there's a better fix.

Quoted 4 lines

I wonder if cpu_is_mx51 is the right macro to test, I'd prefer something like imx_gpio_vX(). IMHO the gpio stuff needs a major overhaul getting rid of most runtime checks.

I used cpu_is_mx51() because I only had tested/seen that on imx515. I wanted to avoid breaking other systems while trying to fix mine. As regards getting rid of runtime checks, maybe registering different gpiochip depending on the SoC would allow to check it a init time and no more check later.

Arnaud

#6 lore raw

PATCH 1/2 imx51: fix gpiolib support

Quoted 18 lines · On Wednesday 01 December 2010, 11:09:32 Arnaud Patard wrote:
Quoted 6 lines

Maybe only read GDIR on mx51? Isn't the direction saved by gpiolib somewhere in RAM? Is the same needed on other SoCs, too (see below for my grouping)? Technically it's not needed at all I think. (Documentation/gpio.txt has: "However, note that not all platforms can read the value of output pins; those that can't should always return zero.". I didn't check if the implementation conforms here though.)

yeah, I know that the gpiolib allows that and in this case, it's always returning 0 but while I was debugging an other problem, I wanted to read output value and it was not working. The manual was not explicitely saying it was not possible so I thought it was a bug and propose a fix. Hopefully, sending this patch allows me to get more feedback and tell me if I got something wrong and there's a better fix.

Quoted 3 lines

I wonder if cpu_is_mx51 is the right macro to test, I'd prefer something like imx_gpio_vX(). IMHO the gpio stuff needs a major overhaul getting rid of most runtime checks.

Quoted 5 lines

I used cpu_is_mx51() because I only had tested/seen that on imx515. I wanted to avoid breaking other systems while trying to fix mine. As regards getting rid of runtime checks, maybe registering different gpiochip depending on the SoC would allow to check it a init time and no more check later.

I can conform, that reading from GPIO_DR on mx35 works too. Also checked with the description is this register. It seem to show exactly what we want, regarding GPIO_GDIR value. So even evaluating GPIO_DIR isn't needed at all. My fix was to simply replace GPIO_PSR with GPIO_DR.

Best regards,
Alexander

#7 lore raw

PATCH 1/2 imx51: fix gpiolib support

Alexander Stein <[email protected]> writes:

Hi,

Quoted 25 lines · On Wednesday 01 December 2010, 11:09:32 Arnaud Patard wrote:
Quoted 18 lines
Quoted 6 lines

Maybe only read GDIR on mx51? Isn't the direction saved by gpiolib somewhere in RAM? Is the same needed on other SoCs, too (see below for my grouping)? Technically it's not needed at all I think. (Documentation/gpio.txt has: "However, note that not all platforms can read the value of output pins; those that can't should always return zero.". I didn't check if the implementation conforms here though.)

yeah, I know that the gpiolib allows that and in this case, it's always returning 0 but while I was debugging an other problem, I wanted to read output value and it was not working. The manual was not explicitely saying it was not possible so I thought it was a bug and propose a fix. Hopefully, sending this patch allows me to get more feedback and tell me if I got something wrong and there's a better fix.

Quoted 3 lines

I wonder if cpu_is_mx51 is the right macro to test, I'd prefer something like imx_gpio_vX(). IMHO the gpio stuff needs a major overhaul getting rid of most runtime checks.

Quoted 5 lines

I used cpu_is_mx51() because I only had tested/seen that on imx515. I wanted to avoid breaking other systems while trying to fix mine. As regards getting rid of runtime checks, maybe registering different gpiochip depending on the SoC would allow to check it a init time and no more check later.

Quoted 4 lines

I can conform, that reading from GPIO_DR on mx35 works too. Also checked with the description is this register. It seem to show exactly what we want, regarding GPIO_GDIR value. So even evaluating GPIO_DIR isn't needed at all. My fix was to simply replace GPIO_PSR with GPIO_DR.

Please look also at Lothar Wa?mann's comments. I plan to test that later but if setting the SION bit allows things to work correctly, setting it by default for the GPIOs may be a better fix than my patch.

Arnaud