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_WIDTH LED_PIO_WIDTH
14 #define ALTERA_PIO_DATA (ALTERA_PIO_BASE + 0)
15 #define ALTERA_PIO_DIR (ALTERA_PIO_BASE + 4)
16 static u32 pio_data_reg;
17 static u32 pio_dir_reg;
19 int gpio_request(unsigned gpio, const char *label)
24 int gpio_free(unsigned gpio)
29 int gpio_direction_input(unsigned gpio)
32 writel(pio_dir_reg &= ~mask, ALTERA_PIO_DIR);
36 int gpio_direction_output(unsigned gpio, int value)
42 pio_data_reg &= ~mask;
43 writel(pio_data_reg, ALTERA_PIO_DATA);
44 writel(pio_dir_reg |= mask, ALTERA_PIO_DIR);
48 int gpio_get_value(unsigned gpio)
51 if (pio_dir_reg & mask)
52 return (pio_data_reg & mask) ? 1 : 0;
54 return (readl(ALTERA_PIO_DATA) & mask) ? 1 : 0;
57 void gpio_set_value(unsigned gpio, int value)
63 pio_data_reg &= ~mask;
64 writel(pio_data_reg, ALTERA_PIO_DATA);
67 int gpio_is_valid(int number)
69 return ((unsigned)number) < ALTERA_PIO_WIDTH;