struct gpio_regs *regs;
u32 l;
- if (port >= ARRAY_SIZE(gpio_ports))
+ if (port >= ARRAY_SIZE(gpio_ports)) {
+ printf("%s: Invalid GPIO %d\n", __func__, gpio);
return -1;
+ }
gpio &= 0x1f;
struct gpio_regs *regs;
u32 l;
- if (port >= ARRAY_SIZE(gpio_ports))
+ if (port >= ARRAY_SIZE(gpio_ports)) {
+ printf("%s: Invalid GPIO %d\n", __func__, gpio);
return -1;
+ }
gpio &= 0x1f;
struct gpio_regs *regs;
u32 val;
- if (port >= ARRAY_SIZE(gpio_ports))
+ if (port >= ARRAY_SIZE(gpio_ports)) {
+ printf("%s: Invalid GPIO %d\n", __func__, gpio);
return -1;
+ }
gpio &= 0x1f;
regs = (struct gpio_regs *)gpio_ports[port];
- val = (readl(®s->gpio_psr) >> gpio) & 0x01;
-
+ if (readl(®s->gpio_dir) & (1 << gpio)) {
+ printf("WARNING: Reading status of output GPIO_%d_%d\n",
+ port - GPIO_TO_PORT(0), gpio);
+ val = (readl(®s->gpio_dr) >> gpio) & 0x01;
+ } else {
+ val = (readl(®s->gpio_psr) >> gpio) & 0x01;
+ }
return val;
}
int gpio_request(unsigned gpio, const char *label)
{
unsigned int port = GPIO_TO_PORT(gpio);
- if (port >= ARRAY_SIZE(gpio_ports))
+ if (port >= ARRAY_SIZE(gpio_ports)) {
+ printf("%s: Invalid GPIO %d\n", __func__, gpio);
return -1;
+ }
return 0;
}
int gpio_free(unsigned gpio)
{
+ unsigned int port = GPIO_TO_PORT(gpio);
+ if (port >= ARRAY_SIZE(gpio_ports)) {
+ printf("%s: Invalid GPIO %d\n", __func__, gpio);
+ return -1;
+ }
return 0;
}