2 * (C) Copyright 2009 Samsung Electronics
3 * Minkyu Kang <mk7.kang@samsung.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 #include <asm/arch/gpio.h>
25 #define CON_MASK(x) (0xf << ((x) << 2))
26 #define CON_SFR(x, v) ((v) << ((x) << 2))
28 #define DAT_MASK(x) (0x1 << (x))
29 #define DAT_SET(x) (0x1 << (x))
31 #define PULL_MASK(x) (0x3 << ((x) << 1))
32 #define PULL_MODE(x, v) ((v) << ((x) << 1))
34 #define DRV_MASK(x) (0x3 << ((x) << 1))
35 #define DRV_SET(x, m) ((m) << ((x) << 1))
36 #define RATE_MASK(x) (0x1 << (x + 16))
37 #define RATE_SET(x) (0x1 << (x + 16))
39 void gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg)
43 value = readl(&bank->con);
44 value &= ~CON_MASK(gpio);
45 value |= CON_SFR(gpio, cfg);
46 writel(value, &bank->con);
49 void gpio_direction_output(struct s5p_gpio_bank *bank, int gpio, int en)
53 gpio_cfg_pin(bank, gpio, GPIO_OUTPUT);
55 value = readl(&bank->dat);
56 value &= ~DAT_MASK(gpio);
58 value |= DAT_SET(gpio);
59 writel(value, &bank->dat);
62 void gpio_direction_input(struct s5p_gpio_bank *bank, int gpio)
64 gpio_cfg_pin(bank, gpio, GPIO_INPUT);
67 void gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en)
71 value = readl(&bank->dat);
72 value &= ~DAT_MASK(gpio);
74 value |= DAT_SET(gpio);
75 writel(value, &bank->dat);
78 unsigned int gpio_get_value(struct s5p_gpio_bank *bank, int gpio)
82 value = readl(&bank->dat);
83 return !!(value & DAT_MASK(gpio));
86 void gpio_set_pull(struct s5p_gpio_bank *bank, int gpio, int mode)
90 value = readl(&bank->pull);
91 value &= ~PULL_MASK(gpio);
96 value |= PULL_MODE(gpio, mode);
102 writel(value, &bank->pull);
105 void gpio_set_drv(struct s5p_gpio_bank *bank, int gpio, int mode)
109 value = readl(&bank->drv);
110 value &= ~DRV_MASK(gpio);
117 value |= DRV_SET(gpio, mode);
123 writel(value, &bank->drv);
126 void gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode)
130 value = readl(&bank->drv);
131 value &= ~RATE_MASK(gpio);
136 value |= RATE_SET(gpio);
142 writel(value, &bank->drv);