MXC_GPIO_DIRECTION_OUT,
};
-#define GPIO_TO_PORT(n) (n / 32)
+#define GPIO_TO_PORT(n) ((n) / 32)
/* GPIO port description */
static unsigned long gpio_ports[] = {
defined(CONFIG_MX53) || defined(CONFIG_MX6)
[3] = GPIO4_BASE_ADDR,
#endif
-#if defined(CONFIG_MX27) || defined(CONFIG_MX53) || defined(CONFIG_MX6)
+#if defined(CONFIG_MX27) || defined(CONFIG_MX53) || defined(CONFIG_MX6Q)
[4] = GPIO5_BASE_ADDR,
[5] = GPIO6_BASE_ADDR,
#endif
-#if defined(CONFIG_MX53) || defined(CONFIG_MX6)
+#if defined(CONFIG_MX53) || defined(CONFIG_MX6Q)
[6] = GPIO7_BASE_ADDR,
#endif
};
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;
}
int gpio_direction_output(unsigned gpio, int value)
{
- int ret = mxc_gpio_direction(gpio, MXC_GPIO_DIRECTION_OUT);
+ int ret = gpio_set_value(gpio, value);
if (ret < 0)
return ret;
- return gpio_set_value(gpio, value);
+ return mxc_gpio_direction(gpio, MXC_GPIO_DIRECTION_OUT);
}