summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/arm/mach-bcm283x/include/mach/gpio.h2
-rw-r--r--drivers/gpio/bcm2835_gpio.c30
2 files changed, 19 insertions, 13 deletions
diff --git a/arch/arm/mach-bcm283x/include/mach/gpio.h b/arch/arm/mach-bcm283x/include/mach/gpio.h
index e6e5d1605d..b2df75ad3f 100644
--- a/arch/arm/mach-bcm283x/include/mach/gpio.h
+++ b/arch/arm/mach-bcm283x/include/mach/gpio.h
@@ -66,4 +66,6 @@ struct bcm2835_gpio_platdata {
unsigned long base;
};
+int bcm2835_gpio_get_func_id(struct udevice *dev, unsigned gpio);
+
#endif /* _BCM2835_GPIO_H_ */
diff --git a/drivers/gpio/bcm2835_gpio.c b/drivers/gpio/bcm2835_gpio.c
index fbc641d662..8b88d7956e 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;
+ }
}