]> git.sur5r.net Git - u-boot/blob - board/altera/nios2-generic/gpio.c
nios2: add gpio_free
[u-boot] / board / altera / nios2-generic / gpio.c
1 /*
2  * board gpio driver
3  *
4  * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
5  * Licensed under the GPL-2 or later.
6  */
7 #include <common.h>
8 #include <asm/io.h>
9
10 #ifndef CONFIG_SYS_GPIO_BASE
11
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;
17
18 int gpio_request(unsigned gpio, const char *label)
19 {
20         return 0;
21 }
22
23 int gpio_free(unsigned gpio)
24 {
25         return 0;
26 }
27
28 int gpio_direction_input(unsigned gpio)
29 {
30         u32 mask = 1 << gpio;
31         writel(pio_dir_reg &= ~mask, ALTERA_PIO_DIR);
32         return 0;
33 }
34
35 int gpio_direction_output(unsigned gpio, int value)
36 {
37         u32 mask = 1 << gpio;
38         if (value)
39                 pio_data_reg |= mask;
40         else
41                 pio_data_reg &= ~mask;
42         writel(pio_data_reg, ALTERA_PIO_DATA);
43         writel(pio_dir_reg |= mask, ALTERA_PIO_DIR);
44         return 0;
45 }
46
47 int gpio_get_value(unsigned gpio)
48 {
49         u32 mask = 1 << gpio;
50         if (pio_dir_reg & mask)
51                 return (pio_data_reg & mask) ? 1 : 0;
52         else
53                 return (readl(ALTERA_PIO_DATA) & mask) ? 1 : 0;
54 }
55
56 void gpio_set_value(unsigned gpio, int value)
57 {
58         u32 mask = 1 << gpio;
59         if (value)
60                 pio_data_reg |= mask;
61         else
62                 pio_data_reg &= ~mask;
63         writel(pio_data_reg, ALTERA_PIO_DATA);
64 }
65 #endif