blob: d4496843fa6d07c40e2d595c0507ebba3b8ea81d [file] [log] [blame]
Thomas Chou1e8e9ba2010-04-30 11:34:15 +08001/*
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)
15static u32 pio_data_reg;
16static u32 pio_dir_reg;
17
Thomas Chou6db6c182010-06-09 09:51:09 +080018int gpio_request(unsigned gpio, const char *label)
19{
20 return 0;
21}
22
Thomas Chou1e8e9ba2010-04-30 11:34:15 +080023int gpio_direction_input(unsigned gpio)
24{
25 u32 mask = 1 << gpio;
26 writel(pio_dir_reg &= ~mask, ALTERA_PIO_DIR);
27 return 0;
28}
29
30int gpio_direction_output(unsigned gpio, int value)
31{
32 u32 mask = 1 << gpio;
33 if (value)
34 pio_data_reg |= mask;
35 else
36 pio_data_reg &= ~mask;
37 writel(pio_data_reg, ALTERA_PIO_DATA);
38 writel(pio_dir_reg |= mask, ALTERA_PIO_DIR);
39 return 0;
40}
41
42int gpio_get_value(unsigned gpio)
43{
44 u32 mask = 1 << gpio;
45 if (pio_dir_reg & mask)
46 return (pio_data_reg & mask) ? 1 : 0;
47 else
48 return (readl(ALTERA_PIO_DATA) & mask) ? 1 : 0;
49}
50
51void gpio_set_value(unsigned gpio, int value)
52{
53 u32 mask = 1 << gpio;
54 if (value)
55 pio_data_reg |= mask;
56 else
57 pio_data_reg &= ~mask;
58 writel(pio_data_reg, ALTERA_PIO_DATA);
59}
60#endif