Tizen 2.0 Release
[platform/kernel/u-boot.git] / arch / arm / cpu / arm1176 / s5p64xx / i2c-gpio.c
1 /*
2  * Copyright (C) 2009 Samsung Electronics
3  * Minkyu Kang <mk7.kang@samsung.com>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <asm/io.h>
26 #include <asm/arch/gpio.h>
27 #include <i2c-gpio.h>
28 #include <i2c.h>
29
30 static struct i2c_gpio_bus *i2c_gpio;
31
32 void i2c_gpio_init(struct i2c_gpio_bus *bus, int len, int index)
33 {
34         int i;
35         struct s5p_gpio_bank *bank;
36
37         i2c_gpio = bus;
38
39         /* init all i2c gpio buses */
40         for (i = 0; i < len; i++) {
41                 bank = (struct s5p_gpio_bank *)i2c_gpio[i].bus->gpio_base;
42
43                 /* SDA */
44                 gpio_direction_output(bank,
45                                 i2c_gpio[i].bus->sda_pin, 1);
46
47                 /* SCL */
48                 gpio_direction_output(bank,
49                                 i2c_gpio[i].bus->scl_pin, 1);
50         }
51
52         /* set default bus */
53         i2c_set_bus_num(index);
54 }
55
56 void i2c_gpio_set(int line, int value)
57 {
58         struct s5p_gpio_bank *bank;
59         unsigned int bus_index;
60
61         bus_index = i2c_get_bus_num();
62
63         bank = (struct s5p_gpio_bank *)i2c_gpio[bus_index].bus->gpio_base;
64
65         if (line)
66                 line = i2c_gpio[bus_index].bus->sda_pin;
67         else
68                 line = i2c_gpio[bus_index].bus->scl_pin;
69
70         gpio_set_value(bank, line, value);
71 }
72
73 int i2c_gpio_get(void)
74 {
75         struct s5p_gpio_bank *bank;
76         unsigned int bus_index;
77
78         bus_index = i2c_get_bus_num();
79
80         bank = (struct s5p_gpio_bank *)i2c_gpio[bus_index].bus->gpio_base;
81
82         return gpio_get_value(bank, i2c_gpio[bus_index].bus->sda_pin);
83 }
84
85 void i2c_gpio_dir(int dir)
86 {
87         struct s5p_gpio_bank *bank;
88         unsigned int bus_index;
89
90         bus_index = i2c_get_bus_num();
91
92         bank = (struct s5p_gpio_bank *)i2c_gpio[bus_index].bus->gpio_base;
93
94         if (dir) {
95                 gpio_direction_output(bank,
96                                 i2c_gpio[bus_index].bus->sda_pin, 0);
97         } else {
98                 gpio_direction_input(bank,
99                                 i2c_gpio[bus_index].bus->sda_pin);
100         }
101 }