ARM: OMAP: Fix GPIO switch initial output state handling
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Jani,
Please see my comments below.
Quoted 25 lines · Jani Nikula
The switchover to cross-platform GPIO interface unexpectedly caused all output GPIO switches to be set to high state by default, unlike the original OMAP code. Introduce a new GPIO switch flag to define the initial state. Unless the flag is set, the default is now low state.
Also store the state of output switches directly into the switch struct instead of trying to read an output GPIO.
Signed-off-by Jani Nikula <[email protected]>--- arch/arm/plat-omap/gpio-switch.c | 13 +++++++++---- arch/arm/plat-omap/include/mach/gpio-switch.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-)arch/arm/plat-omap/gpio-switch.c +1
-1@@ -286,12 +286,17 @@ static int __init new_switch(struct gpio_switch *sw)/* input: 1, output: 0 */ direction = !(sw->flags &OMAP_GPIO_SWITCH_FLAG_OUTPUT ); -if (direction) +if (direction) {gpio_direction_input (sw->gpio);
arch/arm/plat-omap/gpio-switch.c static int __init new_switch(struct gpio_switch *sw) · line 297
Quoted 10 lines
arch/arm/plat-omap/gpio-switch.c +6
-3-else -gpio_direction_output (sw->gpio, true); + sw->state =gpio_sw_get_state (sw); + }else { +int state = sw->state = + !!(sw->flags &OMAP_GPIO_SWITCH_FLAG_OUTPUT_INIT_HIGH ); - sw->state =gpio_sw_get_state (sw); +if (sw->flags &OMAP_GPIO_SWITCH_FLAG_INVERTED ) + state = !state;
Using OMAP_GPIO_SWITCH_FLAG_INVERTED along with OMAP_GPIO_SWITCH_FLAG_OUTPUT_INIT_HIGH here is somewhat confusing to me.
INIT_HIGH indicates the state of the gpio, not the state of the switch. Why not ignore the OMAP_GPIO_SWITCH_FLAG_INVERTED all together when setting up the switch. This way, the user does not have to think twice. :)
Quoted 25 lines
arch/arm/plat-omap/gpio-switch.c +2
-0+gpio_direction_output (sw->gpio, state); + } r =0 ; r |=device_create_file (&sw->pdev.dev, &dev_attr_state);arch/arm/plat-omap/include/mach/gpio-switch.h +1
-1@@ -29,6 +29,7 @@#define OMAP_GPIO_SWITCH_TYPE_ACTIVITY 0x0002#define OMAP_GPIO_SWITCH_FLAG_INVERTED 0x0001#define OMAP_GPIO_SWITCH_FLAG_OUTPUT 0x0002 +#define OMAP_GPIO_SWITCH_FLAG_OUTPUT_INIT_HIGH 0x0004struct omap_gpio_switch {const char *name; --1.6.0.4
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 46 lines · ext Kainan Cha
Jani,
Please see my comments below.
Quoted 25 lines · Jani Nikula
The switchover to cross-platform GPIO interface unexpectedly caused all output GPIO switches to be set to high state by default, unlike the original OMAP code. Introduce a new GPIO switch flag to define the initial state. Unless the flag is set, the default is now low state.
Also store the state of output switches directly into the switch struct instead of trying to read an output GPIO.
Signed-off-by Jani Nikula <[email protected]>--- arch/arm/plat-omap/gpio-switch.c | 13 +++++++++---- arch/arm/plat-omap/include/mach/gpio-switch.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-)arch/arm/plat-omap/gpio-switch.c +1
-1@@ -286,12 +286,17 @@ static int __init new_switch(struct gpio_switch *sw)/* input: 1, output: 0 */ direction = !(sw->flags &OMAP_GPIO_SWITCH_FLAG_OUTPUT ); -if (direction) +if (direction) {gpio_direction_input (sw->gpio);arch/arm/plat-omap/gpio-switch.c static int __init new_switch(struct gpio_switch *sw) · line 297
Quoted 10 lines
arch/arm/plat-omap/gpio-switch.c +6
-3-else -gpio_direction_output (sw->gpio, true); + sw->state =gpio_sw_get_state (sw); + }else { +int state = sw->state = + !!(sw->flags &OMAP_GPIO_SWITCH_FLAG_OUTPUT_INIT_HIGH ); - sw->state =gpio_sw_get_state (sw); +if (sw->flags &OMAP_GPIO_SWITCH_FLAG_INVERTED ) + state = !state;Using
OMAP_GPIO_SWITCH_FLAG_INVERTEDalong withOMAP_GPIO_SWITCH_FLAG_OUTPUT_INIT_HIGHhere is somewhat confusing to me.
Quoted 4 lines
INIT_HIGHindicates the state of the gpio, not the state of the switch. Why not ignore theOMAP_GPIO_SWITCH_FLAG_INVERTEDall together when setting up the switch. This way, the user does not have to think twice. :)
The INVERTED flag can't be ignored, since sw->state must be the opposite of the GPIO if the flag is set. The only question is, should INIT_HIGH flag refer to the GPIO or the switch.
I did think about this, and the patch is as I intended it to be, i.e. INIT_HIGH refers to the switch. I thought this would be less confusing. If INVERTED is set, it's inverted *everywhere* - why not also when setting the initial value?
BR,
Jani.
Quoted 26 lines
Quoted 26 lines
arch/arm/plat-omap/gpio-switch.c +2
-0+gpio_direction_output (sw->gpio, state); + } r =0 ; r |=device_create_file (&sw->pdev.dev, &dev_attr_state);arch/arm/plat-omap/include/mach/gpio-switch.h +1
-1@@ -29,6 +29,7 @@#define OMAP_GPIO_SWITCH_TYPE_ACTIVITY 0x0002#define OMAP_GPIO_SWITCH_FLAG_INVERTED 0x0001#define OMAP_GPIO_SWITCH_FLAG_OUTPUT 0x0002 +#define OMAP_GPIO_SWITCH_FLAG_OUTPUT_INIT_HIGH 0x0004struct omap_gpio_switch {const char *name; --1.6.0.4
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 5 lines · Jani Nikula
Quoted 4 lines
INIT_HIGHindicates the state of the gpio, not the state of the switch. Why not ignore theOMAP_GPIO_SWITCH_FLAG_INVERTEDall together when setting up the switch. This way, the user does not have to think twice. :)
Quoted 8 lines
The INVERTED flag can't be ignored, since
sw->statemust be the opposite of the GPIO if the flag is set. The only question is, shouldINIT_HIGHflag refer to the GPIO or the switch.I did think about this, and the patch is as I intended it to be, i.e.
INIT_HIGHrefers to the switch. I thought this would be less confusing. If INVERTED is set, it's inverted *everywhere* - why not also when setting the initial value?
How about INIT_ACTIVE to reduce possible confusion? HIGH does imply an electrical level, as opposed to a more abstract activation level.
Cheers,
Juha
PATCH v2 1/1 ARM: OMAP: Fix GPIO switch initial output state handling
The switchover to cross-platform GPIO interface unexpectedly caused all output GPIO switches to be set to high state by default, unlike the original OMAP code. Introduce a new GPIO switch flag to define the initial state of the switch. Unless the flag is set, the default is now inactive state of the switch.
Also store the state of output switches directly into the switch struct instead of trying to read an output GPIO.
--- arch/arm/plat-omap/gpio-switch.c | 13 +++++++++---- arch/arm/plat-omap/include/mach/gpio-switch.h | 11 ++++++----- 2 files changed, 15 insertions(+), 9 deletions(-)
arch/arm/plat-omap/gpio-switch.c +9 -4
@@ -286,12 +286,17 @@ static int __init new_switch(struct gpio_switch *sw)/* input: 1, output: 0 */ direction = !(sw->flags &OMAP_GPIO_SWITCH_FLAG_OUTPUT ); -if (direction) +if (direction) {gpio_direction_input (sw->gpio); -else -gpio_direction_output (sw->gpio, true); + sw->state =gpio_sw_get_state (sw); + }else { +int state = sw->state = !!(sw->flags & +OMAP_GPIO_SWITCH_FLAG_OUTPUT_INIT_ACTIVE ); - sw->state =gpio_sw_get_state (sw); +if (sw->flags &OMAP_GPIO_SWITCH_FLAG_INVERTED ) + state = !state; +gpio_direction_output (sw->gpio, state); + } r =0 ; r |=device_create_file (&sw->pdev.dev, &dev_attr_state);
arch/arm/plat-omap/include/mach/gpio-switch.h +6 -5
@@ -24,11 +24,12 @@* low -> inactive * */ -#define OMAP_GPIO_SWITCH_TYPE_COVER 0x0000 -#define OMAP_GPIO_SWITCH_TYPE_CONNECTION 0x0001 -#define OMAP_GPIO_SWITCH_TYPE_ACTIVITY 0x0002 -#define OMAP_GPIO_SWITCH_FLAG_INVERTED 0x0001 -#define OMAP_GPIO_SWITCH_FLAG_OUTPUT 0x0002 +#define OMAP_GPIO_SWITCH_TYPE_COVER 0x0000 +#define OMAP_GPIO_SWITCH_TYPE_CONNECTION 0x0001 +#define OMAP_GPIO_SWITCH_TYPE_ACTIVITY 0x0002 +#define OMAP_GPIO_SWITCH_FLAG_INVERTED 0x0001 +#define OMAP_GPIO_SWITCH_FLAG_OUTPUT 0x0002 +#define OMAP_GPIO_SWITCH_FLAG_OUTPUT_INIT_ACTIVE 0x0004struct omap_gpio_switch {const char *name;
Signature · 1 line
1.6.0.4
I am okay with this. Thanks for the patch.
Quoted 71 lines · Jani Nikula
The switchover to cross-platform GPIO interface unexpectedly caused all output GPIO switches to be set to high state by default, unlike the original OMAP code. Introduce a new GPIO switch flag to define the initial state of the switch. Unless the flag is set, the default is now inactive state of the switch.
Also store the state of output switches directly into the switch struct instead of trying to read an output GPIO.
Signed-off-by Jani Nikula <[email protected]>--- arch/arm/plat-omap/gpio-switch.c | 13 +++++++++---- arch/arm/plat-omap/include/mach/gpio-switch.h | 11 ++++++----- 2 files changed, 15 insertions(+), 9 deletions(-)arch/arm/plat-omap/gpio-switch.c +9
-4@@ -286,12 +286,17 @@ static int __init new_switch(struct gpio_switch *sw)/* input: 1, output: 0 */ direction = !(sw->flags &OMAP_GPIO_SWITCH_FLAG_OUTPUT ); -if (direction) +if (direction) {gpio_direction_input (sw->gpio); -else -gpio_direction_output (sw->gpio, true); + sw->state =gpio_sw_get_state (sw); + }else { +int state = sw->state = !!(sw->flags & +OMAP_GPIO_SWITCH_FLAG_OUTPUT_INIT_ACTIVE ); - sw->state =gpio_sw_get_state (sw); +if (sw->flags &OMAP_GPIO_SWITCH_FLAG_INVERTED ) + state = !state; +gpio_direction_output (sw->gpio, state); + } r =0 ; r |=device_create_file (&sw->pdev.dev, &dev_attr_state);arch/arm/plat-omap/include/mach/gpio-switch.h +6
-6@@ -24,11 +24,12 @@* low -> inactive * */ -#define OMAP_GPIO_SWITCH_TYPE_COVER 0x0000 -#define OMAP_GPIO_SWITCH_TYPE_CONNECTION 0x0001 -#define OMAP_GPIO_SWITCH_TYPE_ACTIVITY 0x0002 -#define OMAP_GPIO_SWITCH_FLAG_INVERTED 0x0001 -#define OMAP_GPIO_SWITCH_FLAG_OUTPUT 0x0002 +#define OMAP_GPIO_SWITCH_TYPE_COVER 0x0000 +#define OMAP_GPIO_SWITCH_TYPE_CONNECTION 0x0001 +#define OMAP_GPIO_SWITCH_TYPE_ACTIVITY 0x0002 +#define OMAP_GPIO_SWITCH_FLAG_INVERTED 0x0001 +#define OMAP_GPIO_SWITCH_FLAG_OUTPUT 0x0002 +#define OMAP_GPIO_SWITCH_FLAG_OUTPUT_INIT_ACTIVE 0x0004struct omap_gpio_switch {const char *name; --1.6.0.4
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/1 ARM: OMAP: Fix GPIO switch initial output state handling
In reply to Jani NikulaThis patch has been applied to the linux-omap
by youw fwiendly patch wobot.
Commit: cc2b459c066361098704c586f3134c3c3ac13be3
PatchWorks
http://patchwork.kernel.org/patch/11128/