gpiolib: don't clear FLAG_IS_OUT when emulating open-drain/open-source
[ Upstream commit e735244e2cf068f98b6384681a38993e0517a838 ] When emulating open-drain/open-source by not actively driving the output lines - we're simply changing their mode to input. This is wrong as it will then make it impossible to change the value of such line - it's now considered to actually be in input mode. If we want to still use the direction_input() callback for simplicity then we need to set FLAG_IS_OUT manually in gpiod_direction_output() and not clear it in gpio_set_open_drain_value_commit() and gpio_set_open_source_value_commit(). Fixes: c663e5f56737 ("gpio: support native single-ended hardware drivers") Cc: stable@vger.kernel.org Reported-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> [Bartosz: backported to v4.14] Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
7b23f5f6cc
commit
a77def3a06
@ -2329,8 +2329,10 @@ static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value)
|
||||
if (!ret)
|
||||
goto set_output_value;
|
||||
/* Emulate open drain by not actively driving the line high */
|
||||
if (val)
|
||||
return gpiod_direction_input(desc);
|
||||
if (val) {
|
||||
ret = gpiod_direction_input(desc);
|
||||
goto set_output_flag;
|
||||
}
|
||||
}
|
||||
else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) {
|
||||
ret = gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc),
|
||||
@ -2338,8 +2340,10 @@ static int _gpiod_direction_output_raw(struct gpio_desc *desc, int value)
|
||||
if (!ret)
|
||||
goto set_output_value;
|
||||
/* Emulate open source by not actively driving the line low */
|
||||
if (!val)
|
||||
return gpiod_direction_input(desc);
|
||||
if (!val) {
|
||||
ret = gpiod_direction_input(desc);
|
||||
goto set_output_flag;
|
||||
}
|
||||
} else {
|
||||
gpio_set_drive_single_ended(gc, gpio_chip_hwgpio(desc),
|
||||
PIN_CONFIG_DRIVE_PUSH_PULL);
|
||||
@ -2359,6 +2363,17 @@ set_output_value:
|
||||
trace_gpio_value(desc_to_gpio(desc), 0, val);
|
||||
trace_gpio_direction(desc_to_gpio(desc), 0, ret);
|
||||
return ret;
|
||||
|
||||
set_output_flag:
|
||||
/*
|
||||
* When emulating open-source or open-drain functionalities by not
|
||||
* actively driving the line (setting mode to input) we still need to
|
||||
* set the IS_OUT flag or otherwise we won't be able to set the line
|
||||
* value anymore.
|
||||
*/
|
||||
if (ret == 0)
|
||||
set_bit(FLAG_IS_OUT, &desc->flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2540,8 +2555,6 @@ static void _gpio_set_open_drain_value(struct gpio_desc *desc, bool value)
|
||||
|
||||
if (value) {
|
||||
err = chip->direction_input(chip, offset);
|
||||
if (!err)
|
||||
clear_bit(FLAG_IS_OUT, &desc->flags);
|
||||
} else {
|
||||
err = chip->direction_output(chip, offset, 0);
|
||||
if (!err)
|
||||
@ -2571,8 +2584,6 @@ static void _gpio_set_open_source_value(struct gpio_desc *desc, bool value)
|
||||
set_bit(FLAG_IS_OUT, &desc->flags);
|
||||
} else {
|
||||
err = chip->direction_input(chip, offset);
|
||||
if (!err)
|
||||
clear_bit(FLAG_IS_OUT, &desc->flags);
|
||||
}
|
||||
trace_gpio_direction(desc_to_gpio(desc), !value, err);
|
||||
if (err < 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user