X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fgpio%2Fbcm2835_gpio.c;h=8dd7a28e2670c98492078e4bcd52be56ac2d6164;hb=4096f350d5218830ffedc56631e4382df478a370;hp=fbc641d662e4e481c99ab667107d623a71f78317;hpb=e564f054af002d9e6a1080ed9d4bc2c6052a4435;p=u-boot diff --git a/drivers/gpio/bcm2835_gpio.c b/drivers/gpio/bcm2835_gpio.c index fbc641d662..8dd7a28e26 100644 --- a/drivers/gpio/bcm2835_gpio.c +++ b/drivers/gpio/bcm2835_gpio.c @@ -44,15 +44,6 @@ static int bcm2835_gpio_direction_output(struct udevice *dev, unsigned gpio, return 0; } -static bool bcm2835_gpio_is_output(const struct bcm2835_gpios *gpios, int gpio) -{ - u32 val; - - val = readl(&gpios->reg->gpfsel[BCM2835_GPIO_FSEL_BANK(gpio)]); - val &= BCM2835_GPIO_FSEL_MASK << BCM2835_GPIO_FSEL_SHIFT(gpio); - return val ? true : false; -} - static int bcm2835_get_value(const struct bcm2835_gpios *gpios, unsigned gpio) { unsigned val; @@ -81,15 +72,28 @@ static int bcm2835_gpio_set_value(struct udevice *dev, unsigned gpio, return 0; } -static int bcm2835_gpio_get_function(struct udevice *dev, unsigned offset) +int bcm2835_gpio_get_func_id(struct udevice *dev, unsigned gpio) { struct bcm2835_gpios *gpios = dev_get_priv(dev); + u32 val; + + val = readl(&gpios->reg->gpfsel[BCM2835_GPIO_FSEL_BANK(gpio)]); + + return (val >> BCM2835_GPIO_FSEL_SHIFT(gpio) & BCM2835_GPIO_FSEL_MASK); +} + +static int bcm2835_gpio_get_function(struct udevice *dev, unsigned offset) +{ + int funcid = bcm2835_gpio_get_func_id(dev, offset); - /* GPIOF_FUNC is not implemented yet */ - if (bcm2835_gpio_is_output(gpios, offset)) + switch (funcid) { + case BCM2835_GPIO_OUTPUT: return GPIOF_OUTPUT; - else + case BCM2835_GPIO_INPUT: return GPIOF_INPUT; + default: + return GPIOF_FUNC; + } } @@ -119,5 +123,6 @@ U_BOOT_DRIVER(gpio_bcm2835) = { .id = UCLASS_GPIO, .ops = &gpio_bcm2835_ops, .probe = bcm2835_gpio_probe, + .flags = DM_FLAG_PRE_RELOC, .priv_auto_alloc_size = sizeof(struct bcm2835_gpios), };