4 * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
5 * Licensed under the GPL-2 or later.
10 #ifndef CONFIG_SYS_GPIO_BASE
12 #define ALTERA_PIO_BASE LED_PIO_BASE
13 #define ALTERA_PIO_DATA (ALTERA_PIO_BASE + 0)
14 #define ALTERA_PIO_DIR (ALTERA_PIO_BASE + 4)
15 static u32 pio_data_reg;
16 static u32 pio_dir_reg;
18 int gpio_request(unsigned gpio, const char *label)
23 int gpio_direction_input(unsigned gpio)
26 writel(pio_dir_reg &= ~mask, ALTERA_PIO_DIR);
30 int gpio_direction_output(unsigned gpio, int value)
36 pio_data_reg &= ~mask;
37 writel(pio_data_reg, ALTERA_PIO_DATA);
38 writel(pio_dir_reg |= mask, ALTERA_PIO_DIR);
42 int gpio_get_value(unsigned gpio)
45 if (pio_dir_reg & mask)
46 return (pio_data_reg & mask) ? 1 : 0;
48 return (readl(ALTERA_PIO_DATA) & mask) ? 1 : 0;
51 void gpio_set_value(unsigned gpio, int value)
57 pio_data_reg &= ~mask;
58 writel(pio_data_reg, ALTERA_PIO_DATA);