gpio: max732x: fix input configuration for open-drain pins
PATCH 1/1 gpio: max732x: fix input configuration for open-drain pins
Eric,
The attached patch tries to fix a bug I noticed while hacking on the max732x driver for interrupt support.
According to the datasheets, open-drain pins have to be configured as output-high (which in that case is actually high impedance) to be used as input.
Note that this patch has only been compile tested, as I still have to solder the actual chip to one of my boards...
Thanks,
M.
Signature · 1 line
Who you jivin' with that Cosmik Debris?
From 059eb9b61b276a681d634781abaa1159dfb547bc Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Mon, 15 Mar 2010 22:14:51 +0000
Subject: [PATCH] gpio: max732x: fix input configuration for open-drain pins
max732x datasheets indicate that open-drain pins must be configured as output-high to be used as input...
--- drivers/gpio/max732x.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)
drivers/gpio/max732x.c +11 -1
@@ -179,15 +179,25 @@ static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off) {struct max732x_chip *chip;unsigned int mask =1u << off; +unsigned int is_input; chip = container_of(gc, struct max732x_chip, gpio_chip); -if ((mask & chip->dir_input) ==0 ) { + is_input = mask & chip->dir_input; + +if (!is_input) {dev_dbg (&chip->client->dev,"%s port %d is output only\n" , chip->client->name, off);return -EACCES ; } +/* +* Open-drain pins must be set to high impedance (which is +* equivalent to output-high) to be turned into an input. +*/ +if ((is_input & chip->dir_output)) +max732x_gpio_set_value (gc, off,1 ); +return 0 ; }
Signature · 1 line
1.7.0.2
Quoted 11 lines · Marc Zyngier
Eric,
The attached patch tries to fix a bug I noticed while hacking on the max732x driver for interrupt support.
According to the datasheets, open-drain pins have to be configured as output-high (which in that case is actually high impedance) to be used as input.Note that this patch has only been compile tested, as I still have to solder the actual chip to one of my boards...
Ack.
(PS: Sorry for late reply, overlooked.)
Quoted 1 line
On Tue, 16 Mar 2010 10:19:00 +0100
I bet you thought I'd forgotten.
Quoted 24 lines · Marc Zyngier
max732x datasheets indicate that open-drain pins must be configured as output-high to be used as input...
Signed-off-by Marc Zyngier <[email protected]>--- drivers/gpio/max732x.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)drivers/gpio/max732x.c +4
-1@@ -179,15 +179,25 @@ static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off) {struct max732x_chip *chip;unsigned int mask =1u << off; +unsigned int is_input; chip = container_of(gc, struct max732x_chip, gpio_chip); -if ((mask & chip->dir_input) ==0 ) { + is_input = mask & chip->dir_input; + +if (!is_input) {
drivers/gpio/max732x.c static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off) · line 198
Quoted 10 lines
drivers/gpio/max732x.c +5
-0dev_dbg (&chip->client->dev,"%s port %d is output only\n" , chip->client->name, off);return -EACCES ; } +/* +* Open-drain pins must be set to high impedance (which is +* equivalent to output-high) to be turned into an input. +*/ +if ((is_input & chip->dir_output))
You really did mean &' here, but one very much expects a variable called is_foo to be a boolean, and booleans want &&'.
Can you think of a more appropriate name for this guy? input_lines, maybe?
Quoted 4 lines
drivers/gpio/max732x.c +2
-0+max732x_gpio_set_value (gc, off,1 ); +return 0 ; }
Marc Zyngier
Acked-by Eric MiaoQuoted 3 lines · Andrew Morton
Quoted 1 line
On Tue, 16 Mar 2010 10:19:00 +0100
I bet you thought I'd forgotten.
Naaaah... I trust your memory more than mine... ;-)
Quoted 2 lines
You really did mean
&' here, but one very much expects a variable called is_foo to be a boolean, and booleans want&&'.
Actually, the attached patch is a much simpler solution to this particular one. We already checked that the pin is input-capable. Use the same mask to check that the pin is also output-capable, and thus open-drain. No need for an additional variable.
Thanks,
M.
Signature · 1 line
Who you jivin' with that Cosmik Debris?
From 3ff7ff7f13145a6a46ffa2e0cc350bee1f120577 Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Fri, 23 Apr 2010 12:25:53 +0100
Subject: [PATCH] gpio: max732x: fix input configuration for open-drain pins
Fix a bug I noticed while hacking on the max732x driver for interrupt support. According to the datasheets, open-drain pins have to be configured as output-high (which in that case is actually high impedance) to be used as input.
--- drivers/gpio/max732x.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/gpio/max732x.c +7 -0
@@ -188,6 +188,13 @@ static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off)return -EACCES ; } +/* +* Open-drain pins must be set to high impedance (which is +* equivalent to output-high) to be turned into an input. +*/ +if ((mask & chip->dir_output)) +max732x_gpio_set_value (gc, off,1 ); +return 0 ; }
Signature · 1 line
1.7.0.4