bcm2835_gpio_direction_output not setting up GPIO value

Stephen Warren swarren at wwwdotorg.org
Mon Apr 6 19:38:10 PDT 2015


On 04/06/2015 03:10 AM, Martin Sperl wrote:
> Is there any reason why bcm2835_gpio_direction_output is
> not setting up the value of GPIO as requested?
> 
> static int bcm2835_gpio_direction_output(struct gpio_chip *chip,
> 					 unsigned offset, int value)
> {
> 	return pinctrl_gpio_direction_output(chip->base + offset);
> }
> Some oversight?
> 
> Maybe it should look like this (untested)?
> 
> static int bcm2835_gpio_direction_output(struct gpio_chip *chip,
> 					 unsigned offset, int value)
> {
> 	int err = pinctrl_gpio_direction_output(chip->base + offset);
> 	if (!err)
> 		bcm2835_gpio_set(chip, offset, value);
> 	return err;
> }

That sounds reasonable. I'm not sure why I didn't code it like that before.

One change though: The output value should be set before changing the
direction. That way, the pin won't become an output and drive some stale
value (whatever is in the output register) before the desired output
value is written, thus potentially causing a glitch on the pin.



More information about the linux-rpi-kernel mailing list