blob: e768cdedb0db99530eb9c9a34da290cf1191e0a4 [file] [log] [blame]
Vipin KUMARfc9589f2010-01-15 19:15:44 +05301/*
2 * (C) Copyright 2009
3 * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Vipin KUMARfc9589f2010-01-15 19:15:44 +05306 */
7
8#include <common.h>
Stefan Roeseef6073e2014-10-28 12:12:00 +01009#include <i2c.h>
Vipin KUMARfc9589f2010-01-15 19:15:44 +053010#include <asm/io.h>
Vipin KUMAR3f64acb2012-02-26 23:13:29 +000011#include "designware_i2c.h"
Vipin KUMARfc9589f2010-01-15 19:15:44 +053012
Stefan Roeseef6073e2014-10-28 12:12:00 +010013static struct i2c_regs *i2c_get_base(struct i2c_adapter *adap)
14{
15 switch (adap->hwadapnr) {
16#if CONFIG_SYS_I2C_BUS_MAX >= 4
17 case 3:
18 return (struct i2c_regs *)CONFIG_SYS_I2C_BASE3;
Armando Visconti4a7b4ec2012-12-06 00:04:15 +000019#endif
Stefan Roeseef6073e2014-10-28 12:12:00 +010020#if CONFIG_SYS_I2C_BUS_MAX >= 3
21 case 2:
22 return (struct i2c_regs *)CONFIG_SYS_I2C_BASE2;
23#endif
24#if CONFIG_SYS_I2C_BUS_MAX >= 2
25 case 1:
26 return (struct i2c_regs *)CONFIG_SYS_I2C_BASE1;
27#endif
28 case 0:
29 return (struct i2c_regs *)CONFIG_SYS_I2C_BASE;
30 default:
31 printf("Wrong I2C-adapter number %d\n", adap->hwadapnr);
32 }
Armando Visconti4a7b4ec2012-12-06 00:04:15 +000033
Stefan Roeseef6073e2014-10-28 12:12:00 +010034 return NULL;
35}
Vipin KUMARfc9589f2010-01-15 19:15:44 +053036
37/*
38 * set_speed - Set the i2c speed mode (standard, high, fast)
39 * @i2c_spd: required i2c speed mode
40 *
41 * Set the i2c speed mode (standard, high, fast)
42 */
Stefan Roeseef6073e2014-10-28 12:12:00 +010043static void set_speed(struct i2c_adapter *adap, int i2c_spd)
Vipin KUMARfc9589f2010-01-15 19:15:44 +053044{
Stefan Roeseef6073e2014-10-28 12:12:00 +010045 struct i2c_regs *i2c_base = i2c_get_base(adap);
Vipin KUMARfc9589f2010-01-15 19:15:44 +053046 unsigned int cntl;
47 unsigned int hcnt, lcnt;
Armando Visconti631e6932012-03-29 20:10:17 +000048 unsigned int enbl;
49
50 /* to set speed cltr must be disabled */
Stefan Roeseef6073e2014-10-28 12:12:00 +010051 enbl = readl(&i2c_base->ic_enable);
Armando Visconti631e6932012-03-29 20:10:17 +000052 enbl &= ~IC_ENABLE_0B;
Stefan Roeseef6073e2014-10-28 12:12:00 +010053 writel(enbl, &i2c_base->ic_enable);
Armando Visconti631e6932012-03-29 20:10:17 +000054
Stefan Roeseef6073e2014-10-28 12:12:00 +010055 cntl = (readl(&i2c_base->ic_con) & (~IC_CON_SPD_MSK));
Vipin KUMARfc9589f2010-01-15 19:15:44 +053056
57 switch (i2c_spd) {
58 case IC_SPEED_MODE_MAX:
59 cntl |= IC_CON_SPD_HS;
Armando Visconti28a724f2012-12-06 00:04:17 +000060 hcnt = (IC_CLK * MIN_HS_SCL_HIGHTIME) / NANO_TO_MICRO;
Stefan Roeseef6073e2014-10-28 12:12:00 +010061 writel(hcnt, &i2c_base->ic_hs_scl_hcnt);
Armando Visconti28a724f2012-12-06 00:04:17 +000062 lcnt = (IC_CLK * MIN_HS_SCL_LOWTIME) / NANO_TO_MICRO;
Stefan Roeseef6073e2014-10-28 12:12:00 +010063 writel(lcnt, &i2c_base->ic_hs_scl_lcnt);
Vipin KUMARfc9589f2010-01-15 19:15:44 +053064 break;
65
66 case IC_SPEED_MODE_STANDARD:
67 cntl |= IC_CON_SPD_SS;
Armando Visconti28a724f2012-12-06 00:04:17 +000068 hcnt = (IC_CLK * MIN_SS_SCL_HIGHTIME) / NANO_TO_MICRO;
Stefan Roeseef6073e2014-10-28 12:12:00 +010069 writel(hcnt, &i2c_base->ic_ss_scl_hcnt);
Armando Visconti28a724f2012-12-06 00:04:17 +000070 lcnt = (IC_CLK * MIN_SS_SCL_LOWTIME) / NANO_TO_MICRO;
Stefan Roeseef6073e2014-10-28 12:12:00 +010071 writel(lcnt, &i2c_base->ic_ss_scl_lcnt);
Vipin KUMARfc9589f2010-01-15 19:15:44 +053072 break;
73
74 case IC_SPEED_MODE_FAST:
75 default:
76 cntl |= IC_CON_SPD_FS;
Armando Visconti28a724f2012-12-06 00:04:17 +000077 hcnt = (IC_CLK * MIN_FS_SCL_HIGHTIME) / NANO_TO_MICRO;
Stefan Roeseef6073e2014-10-28 12:12:00 +010078 writel(hcnt, &i2c_base->ic_fs_scl_hcnt);
Armando Visconti28a724f2012-12-06 00:04:17 +000079 lcnt = (IC_CLK * MIN_FS_SCL_LOWTIME) / NANO_TO_MICRO;
Stefan Roeseef6073e2014-10-28 12:12:00 +010080 writel(lcnt, &i2c_base->ic_fs_scl_lcnt);
Vipin KUMARfc9589f2010-01-15 19:15:44 +053081 break;
82 }
83
Stefan Roeseef6073e2014-10-28 12:12:00 +010084 writel(cntl, &i2c_base->ic_con);
Vipin KUMARfc9589f2010-01-15 19:15:44 +053085
Armando Visconti28a724f2012-12-06 00:04:17 +000086 /* Enable back i2c now speed set */
Armando Visconti631e6932012-03-29 20:10:17 +000087 enbl |= IC_ENABLE_0B;
Stefan Roeseef6073e2014-10-28 12:12:00 +010088 writel(enbl, &i2c_base->ic_enable);
Vipin KUMARfc9589f2010-01-15 19:15:44 +053089}
90
91/*
92 * i2c_set_bus_speed - Set the i2c speed
93 * @speed: required i2c speed
94 *
95 * Set the i2c speed.
96 */
Stefan Roeseef6073e2014-10-28 12:12:00 +010097static unsigned int dw_i2c_set_bus_speed(struct i2c_adapter *adap,
98 unsigned int speed)
Vipin KUMARfc9589f2010-01-15 19:15:44 +053099{
Jeroen Hofsteedffb8272014-10-08 22:58:09 +0200100 int i2c_spd;
101
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530102 if (speed >= I2C_MAX_SPEED)
Jeroen Hofsteedffb8272014-10-08 22:58:09 +0200103 i2c_spd = IC_SPEED_MODE_MAX;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530104 else if (speed >= I2C_FAST_SPEED)
Jeroen Hofsteedffb8272014-10-08 22:58:09 +0200105 i2c_spd = IC_SPEED_MODE_FAST;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530106 else
Jeroen Hofsteedffb8272014-10-08 22:58:09 +0200107 i2c_spd = IC_SPEED_MODE_STANDARD;
Stefan Roesef6322ebd2012-01-20 11:52:33 +0100108
Stefan Roeseef6073e2014-10-28 12:12:00 +0100109 set_speed(adap, i2c_spd);
110 adap->speed = speed;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530111
112 return 0;
113}
114
115/*
116 * i2c_init - Init function
117 * @speed: required i2c speed
Stefan Roeseef6073e2014-10-28 12:12:00 +0100118 * @slaveaddr: slave address for the device
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530119 *
120 * Initialization function.
121 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100122static void dw_i2c_init(struct i2c_adapter *adap, int speed,
123 int slaveaddr)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530124{
Stefan Roeseef6073e2014-10-28 12:12:00 +0100125 struct i2c_regs *i2c_base = i2c_get_base(adap);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530126 unsigned int enbl;
127
128 /* Disable i2c */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100129 enbl = readl(&i2c_base->ic_enable);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530130 enbl &= ~IC_ENABLE_0B;
Stefan Roeseef6073e2014-10-28 12:12:00 +0100131 writel(enbl, &i2c_base->ic_enable);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530132
Stefan Roeseef6073e2014-10-28 12:12:00 +0100133 writel((IC_CON_SD | IC_CON_SPD_FS | IC_CON_MM), &i2c_base->ic_con);
134 writel(IC_RX_TL, &i2c_base->ic_rx_tl);
135 writel(IC_TX_TL, &i2c_base->ic_tx_tl);
136 dw_i2c_set_bus_speed(adap, speed);
137 writel(IC_STOP_DET, &i2c_base->ic_intr_mask);
138 writel(slaveaddr, &i2c_base->ic_sar);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530139
140 /* Enable i2c */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100141 enbl = readl(&i2c_base->ic_enable);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530142 enbl |= IC_ENABLE_0B;
Stefan Roeseef6073e2014-10-28 12:12:00 +0100143 writel(enbl, &i2c_base->ic_enable);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530144}
145
146/*
147 * i2c_setaddress - Sets the target slave address
148 * @i2c_addr: target i2c address
149 *
150 * Sets the target slave address.
151 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100152static void i2c_setaddress(struct i2c_adapter *adap, unsigned int i2c_addr)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530153{
Stefan Roeseef6073e2014-10-28 12:12:00 +0100154 struct i2c_regs *i2c_base = i2c_get_base(adap);
Alexey Brodkin41c56552013-11-07 17:52:18 +0400155 unsigned int enbl;
156
157 /* Disable i2c */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100158 enbl = readl(&i2c_base->ic_enable);
Alexey Brodkin41c56552013-11-07 17:52:18 +0400159 enbl &= ~IC_ENABLE_0B;
Stefan Roeseef6073e2014-10-28 12:12:00 +0100160 writel(enbl, &i2c_base->ic_enable);
Alexey Brodkin41c56552013-11-07 17:52:18 +0400161
Stefan Roeseef6073e2014-10-28 12:12:00 +0100162 writel(i2c_addr, &i2c_base->ic_tar);
Alexey Brodkin41c56552013-11-07 17:52:18 +0400163
164 /* Enable i2c */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100165 enbl = readl(&i2c_base->ic_enable);
Alexey Brodkin41c56552013-11-07 17:52:18 +0400166 enbl |= IC_ENABLE_0B;
Stefan Roeseef6073e2014-10-28 12:12:00 +0100167 writel(enbl, &i2c_base->ic_enable);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530168}
169
170/*
171 * i2c_flush_rxfifo - Flushes the i2c RX FIFO
172 *
173 * Flushes the i2c RX FIFO
174 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100175static void i2c_flush_rxfifo(struct i2c_adapter *adap)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530176{
Stefan Roeseef6073e2014-10-28 12:12:00 +0100177 struct i2c_regs *i2c_base = i2c_get_base(adap);
178
179 while (readl(&i2c_base->ic_status) & IC_STATUS_RFNE)
180 readl(&i2c_base->ic_cmd_data);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530181}
182
183/*
184 * i2c_wait_for_bb - Waits for bus busy
185 *
186 * Waits for bus busy
187 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100188static int i2c_wait_for_bb(struct i2c_adapter *adap)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530189{
Stefan Roeseef6073e2014-10-28 12:12:00 +0100190 struct i2c_regs *i2c_base = i2c_get_base(adap);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530191 unsigned long start_time_bb = get_timer(0);
192
Stefan Roeseef6073e2014-10-28 12:12:00 +0100193 while ((readl(&i2c_base->ic_status) & IC_STATUS_MA) ||
194 !(readl(&i2c_base->ic_status) & IC_STATUS_TFE)) {
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530195
196 /* Evaluate timeout */
197 if (get_timer(start_time_bb) > (unsigned long)(I2C_BYTE_TO_BB))
198 return 1;
199 }
200
201 return 0;
202}
203
Stefan Roeseef6073e2014-10-28 12:12:00 +0100204static int i2c_xfer_init(struct i2c_adapter *adap, uchar chip, uint addr,
205 int alen)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530206{
Stefan Roeseef6073e2014-10-28 12:12:00 +0100207 struct i2c_regs *i2c_base = i2c_get_base(adap);
208
209 if (i2c_wait_for_bb(adap))
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530210 return 1;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530211
Stefan Roeseef6073e2014-10-28 12:12:00 +0100212 i2c_setaddress(adap, chip);
Chin Liang Seea0c26262014-02-04 11:56:23 -0600213 while (alen) {
214 alen--;
215 /* high byte address going out first */
216 writel((addr >> (alen * 8)) & 0xff,
Stefan Roeseef6073e2014-10-28 12:12:00 +0100217 &i2c_base->ic_cmd_data);
Chin Liang Seea0c26262014-02-04 11:56:23 -0600218 }
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530219 return 0;
220}
221
Stefan Roeseef6073e2014-10-28 12:12:00 +0100222static int i2c_xfer_finish(struct i2c_adapter *adap)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530223{
Stefan Roeseef6073e2014-10-28 12:12:00 +0100224 struct i2c_regs *i2c_base = i2c_get_base(adap);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530225 ulong start_stop_det = get_timer(0);
226
227 while (1) {
Stefan Roeseef6073e2014-10-28 12:12:00 +0100228 if ((readl(&i2c_base->ic_raw_intr_stat) & IC_STOP_DET)) {
229 readl(&i2c_base->ic_clr_stop_det);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530230 break;
231 } else if (get_timer(start_stop_det) > I2C_STOPDET_TO) {
232 break;
233 }
234 }
235
Stefan Roeseef6073e2014-10-28 12:12:00 +0100236 if (i2c_wait_for_bb(adap)) {
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530237 printf("Timed out waiting for bus\n");
238 return 1;
239 }
240
Stefan Roeseef6073e2014-10-28 12:12:00 +0100241 i2c_flush_rxfifo(adap);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530242
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530243 return 0;
244}
245
246/*
247 * i2c_read - Read from i2c memory
248 * @chip: target i2c address
249 * @addr: address to read from
250 * @alen:
251 * @buffer: buffer for read data
252 * @len: no of bytes to be read
253 *
254 * Read from i2c memory.
255 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100256static int dw_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr,
257 int alen, u8 *buffer, int len)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530258{
Stefan Roeseef6073e2014-10-28 12:12:00 +0100259 struct i2c_regs *i2c_base = i2c_get_base(adap);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530260 unsigned long start_time_rx;
261
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400262#ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW
263 /*
264 * EEPROM chips that implement "address overflow" are ones
265 * like Catalyst 24WC04/08/16 which has 9/10/11 bits of
266 * address and the extra bits end up in the "chip address"
267 * bit slots. This makes a 24WC08 (1Kbyte) chip look like
268 * four 256 byte chips.
269 *
270 * Note that we consider the length of the address field to
271 * still be one byte because the extra address bits are
272 * hidden in the chip address.
273 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100274 dev |= ((addr >> (alen * 8)) & CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW);
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400275 addr &= ~(CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW << (alen * 8));
276
Stefan Roeseef6073e2014-10-28 12:12:00 +0100277 debug("%s: fix addr_overflow: dev %02x addr %02x\n", __func__, dev,
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400278 addr);
279#endif
280
Stefan Roeseef6073e2014-10-28 12:12:00 +0100281 if (i2c_xfer_init(adap, dev, addr, alen))
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530282 return 1;
283
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530284 start_time_rx = get_timer(0);
285 while (len) {
Armando Visconti6bc6ef72012-12-06 00:04:16 +0000286 if (len == 1)
Stefan Roeseef6073e2014-10-28 12:12:00 +0100287 writel(IC_CMD | IC_STOP, &i2c_base->ic_cmd_data);
Armando Visconti6bc6ef72012-12-06 00:04:16 +0000288 else
Stefan Roeseef6073e2014-10-28 12:12:00 +0100289 writel(IC_CMD, &i2c_base->ic_cmd_data);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530290
Stefan Roeseef6073e2014-10-28 12:12:00 +0100291 if (readl(&i2c_base->ic_status) & IC_STATUS_RFNE) {
292 *buffer++ = (uchar)readl(&i2c_base->ic_cmd_data);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530293 len--;
294 start_time_rx = get_timer(0);
295
296 } else if (get_timer(start_time_rx) > I2C_BYTE_TO) {
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530297 return 1;
298 }
299 }
300
Stefan Roeseef6073e2014-10-28 12:12:00 +0100301 return i2c_xfer_finish(adap);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530302}
303
304/*
305 * i2c_write - Write to i2c memory
306 * @chip: target i2c address
307 * @addr: address to read from
308 * @alen:
309 * @buffer: buffer for read data
310 * @len: no of bytes to be read
311 *
312 * Write to i2c memory.
313 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100314static int dw_i2c_write(struct i2c_adapter *adap, u8 dev, uint addr,
315 int alen, u8 *buffer, int len)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530316{
Stefan Roeseef6073e2014-10-28 12:12:00 +0100317 struct i2c_regs *i2c_base = i2c_get_base(adap);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530318 int nb = len;
319 unsigned long start_time_tx;
320
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400321#ifdef CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW
322 /*
323 * EEPROM chips that implement "address overflow" are ones
324 * like Catalyst 24WC04/08/16 which has 9/10/11 bits of
325 * address and the extra bits end up in the "chip address"
326 * bit slots. This makes a 24WC08 (1Kbyte) chip look like
327 * four 256 byte chips.
328 *
329 * Note that we consider the length of the address field to
330 * still be one byte because the extra address bits are
331 * hidden in the chip address.
332 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100333 dev |= ((addr >> (alen * 8)) & CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW);
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400334 addr &= ~(CONFIG_SYS_I2C_EEPROM_ADDR_OVERFLOW << (alen * 8));
335
Stefan Roeseef6073e2014-10-28 12:12:00 +0100336 debug("%s: fix addr_overflow: dev %02x addr %02x\n", __func__, dev,
Alexey Brodkin7ef00362013-12-16 15:30:35 +0400337 addr);
338#endif
339
Stefan Roeseef6073e2014-10-28 12:12:00 +0100340 if (i2c_xfer_init(adap, dev, addr, alen))
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530341 return 1;
342
343 start_time_tx = get_timer(0);
344 while (len) {
Stefan Roeseef6073e2014-10-28 12:12:00 +0100345 if (readl(&i2c_base->ic_status) & IC_STATUS_TFNF) {
346 if (--len == 0) {
347 writel(*buffer | IC_STOP,
348 &i2c_base->ic_cmd_data);
349 } else {
350 writel(*buffer, &i2c_base->ic_cmd_data);
351 }
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530352 buffer++;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530353 start_time_tx = get_timer(0);
354
355 } else if (get_timer(start_time_tx) > (nb * I2C_BYTE_TO)) {
356 printf("Timed out. i2c write Failed\n");
357 return 1;
358 }
359 }
360
Stefan Roeseef6073e2014-10-28 12:12:00 +0100361 return i2c_xfer_finish(adap);
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530362}
363
364/*
365 * i2c_probe - Probe the i2c chip
366 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100367static int dw_i2c_probe(struct i2c_adapter *adap, u8 dev)
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530368{
369 u32 tmp;
Stefan Roesef6322ebd2012-01-20 11:52:33 +0100370 int ret;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530371
372 /*
373 * Try to read the first location of the chip.
374 */
Stefan Roeseef6073e2014-10-28 12:12:00 +0100375 ret = dw_i2c_read(adap, dev, 0, 1, (uchar *)&tmp, 1);
Stefan Roesef6322ebd2012-01-20 11:52:33 +0100376 if (ret)
Stefan Roeseef6073e2014-10-28 12:12:00 +0100377 dw_i2c_init(adap, adap->speed, adap->slaveaddr);
Stefan Roesef6322ebd2012-01-20 11:52:33 +0100378
379 return ret;
Vipin KUMARfc9589f2010-01-15 19:15:44 +0530380}
Armando Visconti4a7b4ec2012-12-06 00:04:15 +0000381
Stefan Roeseef6073e2014-10-28 12:12:00 +0100382U_BOOT_I2C_ADAP_COMPLETE(dw_0, dw_i2c_init, dw_i2c_probe, dw_i2c_read,
383 dw_i2c_write, dw_i2c_set_bus_speed,
384 CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE, 0)
Armando Visconti4a7b4ec2012-12-06 00:04:15 +0000385
Stefan Roeseef6073e2014-10-28 12:12:00 +0100386#if CONFIG_SYS_I2C_BUS_MAX >= 2
387U_BOOT_I2C_ADAP_COMPLETE(dw_1, dw_i2c_init, dw_i2c_probe, dw_i2c_read,
388 dw_i2c_write, dw_i2c_set_bus_speed,
389 CONFIG_SYS_I2C_SPEED1, CONFIG_SYS_I2C_SLAVE1, 1)
390#endif
Armando Visconti4a7b4ec2012-12-06 00:04:15 +0000391
Stefan Roeseef6073e2014-10-28 12:12:00 +0100392#if CONFIG_SYS_I2C_BUS_MAX >= 3
393U_BOOT_I2C_ADAP_COMPLETE(dw_2, dw_i2c_init, dw_i2c_probe, dw_i2c_read,
394 dw_i2c_write, dw_i2c_set_bus_speed,
395 CONFIG_SYS_I2C_SPEED2, CONFIG_SYS_I2C_SLAVE2, 2)
396#endif
Armando Visconti4a7b4ec2012-12-06 00:04:15 +0000397
Stefan Roeseef6073e2014-10-28 12:12:00 +0100398#if CONFIG_SYS_I2C_BUS_MAX >= 4
399U_BOOT_I2C_ADAP_COMPLETE(dw_3, dw_i2c_init, dw_i2c_probe, dw_i2c_read,
400 dw_i2c_write, dw_i2c_set_bus_speed,
401 CONFIG_SYS_I2C_SPEED3, CONFIG_SYS_I2C_SLAVE3, 3)
Armando Visconti4a7b4ec2012-12-06 00:04:15 +0000402#endif