]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/altera/nios2-generic/gpio.c
powerpc/83xx: fix sdram initialization for keymile boards
[karo-tx-uboot.git] / 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_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;
18
19 int gpio_request(unsigned gpio, const char *label)
20 {
21         return 0;
22 }
23
24 int gpio_free(unsigned gpio)
25 {
26         return 0;
27 }
28
29 int gpio_direction_input(unsigned gpio)
30 {
31         u32 mask = 1 << gpio;
32         writel(pio_dir_reg &= ~mask, ALTERA_PIO_DIR);
33         return 0;
34 }
35
36 int gpio_direction_output(unsigned gpio, int value)
37 {
38         u32 mask = 1 << gpio;
39         if (value)
40                 pio_data_reg |= mask;
41         else
42                 pio_data_reg &= ~mask;
43         writel(pio_data_reg, ALTERA_PIO_DATA);
44         writel(pio_dir_reg |= mask, ALTERA_PIO_DIR);
45         return 0;
46 }
47
48 int gpio_get_value(unsigned gpio)
49 {
50         u32 mask = 1 << gpio;
51         if (pio_dir_reg & mask)
52                 return (pio_data_reg & mask) ? 1 : 0;
53         else
54                 return (readl(ALTERA_PIO_DATA) & mask) ? 1 : 0;
55 }
56
57 void gpio_set_value(unsigned gpio, int value)
58 {
59         u32 mask = 1 << gpio;
60         if (value)
61                 pio_data_reg |= mask;
62         else
63                 pio_data_reg &= ~mask;
64         writel(pio_data_reg, ALTERA_PIO_DATA);
65 }
66
67 int gpio_is_valid(int number)
68 {
69         return ((unsigned)number) < ALTERA_PIO_WIDTH;
70 }
71 #endif