blob: 215be3419d1b58326ee5a38a16bb7261c76e2a88 [file] [log] [blame]
wdenk8ed96042005-01-09 23:16:25 +00001/*
2 * Basic I2C functions
3 *
4 * Copyright (c) 2004 Texas Instruments
5 *
6 * This package is free software; you can redistribute it and/or
7 * modify it under the terms of the license found in the file
8 * named COPYING that should have accompanied this file.
9 *
10 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
11 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * Author: Jian Zhang jzhang@ti.com, Texas Instruments
15 *
16 * Copyright (c) 2003 Wolfgang Denk, wd@denx.de
17 * Rewritten to fit into the current U-Boot framework
18 *
19 * Adapted for OMAP2420 I2C, r-woodruff2@ti.com
20 *
21 */
22
23#include <common.h>
wdenk289f9322005-01-12 00:15:14 +000024
wdenk8ed96042005-01-09 23:16:25 +000025#include <asm/arch/i2c.h>
26#include <asm/io.h>
27
Steve Sakoman938717c2010-06-12 06:42:57 -070028#include "omap24xx_i2c.h"
29
John Rigby29565322010-12-20 18:27:51 -070030DECLARE_GLOBAL_DATA_PTR;
31
Steve Sakoman73e87472010-10-20 06:07:44 -070032#define I2C_TIMEOUT 1000
Steve Sakomand7083952010-07-19 20:31:55 -070033
wdenk8ed96042005-01-09 23:16:25 +000034static void wait_for_bb (void);
35static u16 wait_for_pin (void);
Wolfgang Denk49a75812005-09-25 18:41:04 +020036static void flush_fifo(void);
wdenk8ed96042005-01-09 23:16:25 +000037
Dirk Behme1d2e96d2009-11-02 20:36:26 +010038static struct i2c *i2c_base = (struct i2c *)I2C_DEFAULT_BASE;
39
40static unsigned int bus_initialized[I2C_BUS_MAX];
41static unsigned int current_bus;
42
wdenk8ed96042005-01-09 23:16:25 +000043void i2c_init (int speed, int slaveadd)
44{
Tom Rix7f79dfb2009-06-28 12:52:27 -050045 int psc, fsscll, fssclh;
46 int hsscll = 0, hssclh = 0;
47 u32 scll, sclh;
Steve Sakomand7083952010-07-19 20:31:55 -070048 int timeout = I2C_TIMEOUT;
Tom Rix7f79dfb2009-06-28 12:52:27 -050049
50 /* Only handle standard, fast and high speeds */
51 if ((speed != OMAP_I2C_STANDARD) &&
52 (speed != OMAP_I2C_FAST_MODE) &&
53 (speed != OMAP_I2C_HIGH_SPEED)) {
54 printf("Error : I2C unsupported speed %d\n", speed);
55 return;
56 }
57
58 psc = I2C_IP_CLK / I2C_INTERNAL_SAMPLING_CLK;
59 psc -= 1;
60 if (psc < I2C_PSC_MIN) {
61 printf("Error : I2C unsupported prescalar %d\n", psc);
62 return;
63 }
64
65 if (speed == OMAP_I2C_HIGH_SPEED) {
66 /* High speed */
67
68 /* For first phase of HS mode */
69 fsscll = fssclh = I2C_INTERNAL_SAMPLING_CLK /
70 (2 * OMAP_I2C_FAST_MODE);
71
72 fsscll -= I2C_HIGHSPEED_PHASE_ONE_SCLL_TRIM;
73 fssclh -= I2C_HIGHSPEED_PHASE_ONE_SCLH_TRIM;
74 if (((fsscll < 0) || (fssclh < 0)) ||
75 ((fsscll > 255) || (fssclh > 255))) {
76 printf("Error : I2C initializing first phase clock\n");
77 return;
78 }
79
80 /* For second phase of HS mode */
81 hsscll = hssclh = I2C_INTERNAL_SAMPLING_CLK / (2 * speed);
82
83 hsscll -= I2C_HIGHSPEED_PHASE_TWO_SCLL_TRIM;
84 hssclh -= I2C_HIGHSPEED_PHASE_TWO_SCLH_TRIM;
85 if (((fsscll < 0) || (fssclh < 0)) ||
86 ((fsscll > 255) || (fssclh > 255))) {
87 printf("Error : I2C initializing second phase clock\n");
88 return;
89 }
90
91 scll = (unsigned int)hsscll << 8 | (unsigned int)fsscll;
92 sclh = (unsigned int)hssclh << 8 | (unsigned int)fssclh;
93
94 } else {
95 /* Standard and fast speed */
96 fsscll = fssclh = I2C_INTERNAL_SAMPLING_CLK / (2 * speed);
97
98 fsscll -= I2C_FASTSPEED_SCLL_TRIM;
99 fssclh -= I2C_FASTSPEED_SCLH_TRIM;
100 if (((fsscll < 0) || (fssclh < 0)) ||
101 ((fsscll > 255) || (fssclh > 255))) {
102 printf("Error : I2C initializing clock\n");
103 return;
104 }
105
106 scll = (unsigned int)fsscll;
107 sclh = (unsigned int)fssclh;
108 }
wdenk8ed96042005-01-09 23:16:25 +0000109
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100110 if (readw (&i2c_base->con) & I2C_CON_EN) {
111 writew (0, &i2c_base->con);
wdenk8ed96042005-01-09 23:16:25 +0000112 udelay (50000);
113 }
114
Steve Sakomand7083952010-07-19 20:31:55 -0700115 writew(0x2, &i2c_base->sysc); /* for ES2 after soft reset */
116 udelay(1000);
117
118 writew(I2C_CON_EN, &i2c_base->con);
119 while (!(readw(&i2c_base->syss) & I2C_SYSS_RDONE) && timeout--) {
120 if (timeout <= 0) {
121 printf("ERROR: Timeout in soft-reset\n");
122 return;
123 }
124 udelay(1000);
125 }
126
127 writew(0, &i2c_base->con);
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100128 writew(psc, &i2c_base->psc);
129 writew(scll, &i2c_base->scll);
130 writew(sclh, &i2c_base->sclh);
Tom Rix7f79dfb2009-06-28 12:52:27 -0500131
wdenk8ed96042005-01-09 23:16:25 +0000132 /* own address */
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100133 writew (slaveadd, &i2c_base->oa);
134 writew (I2C_CON_EN, &i2c_base->con);
Wolfgang Denk49a75812005-09-25 18:41:04 +0200135
wdenk8ed96042005-01-09 23:16:25 +0000136 /* have to enable intrrupts or OMAP i2c module doesn't work */
Dirk Behmee23c7c92008-11-10 20:15:25 +0100137 writew (I2C_IE_XRDY_IE | I2C_IE_RRDY_IE | I2C_IE_ARDY_IE |
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100138 I2C_IE_NACK_IE | I2C_IE_AL_IE, &i2c_base->ie);
wdenk8ed96042005-01-09 23:16:25 +0000139 udelay (1000);
Wolfgang Denk49a75812005-09-25 18:41:04 +0200140 flush_fifo();
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100141 writew (0xFFFF, &i2c_base->stat);
142 writew (0, &i2c_base->cnt);
143
Heiko Schocher1724fe92010-09-17 13:10:37 +0200144 if (gd->flags & GD_FLG_RELOC)
145 bus_initialized[current_bus] = 1;
wdenk8ed96042005-01-09 23:16:25 +0000146}
147
148static int i2c_read_byte (u8 devaddr, u8 regoffset, u8 * value)
149{
150 int i2c_error = 0;
151 u16 status;
152
153 /* wait until bus not busy */
154 wait_for_bb ();
155
156 /* one byte only */
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100157 writew (1, &i2c_base->cnt);
wdenk8ed96042005-01-09 23:16:25 +0000158 /* set slave address */
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100159 writew (devaddr, &i2c_base->sa);
wdenk8ed96042005-01-09 23:16:25 +0000160 /* no stop bit needed here */
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100161 writew (I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_TRX, &i2c_base->con);
wdenk8ed96042005-01-09 23:16:25 +0000162
Steve Sakomanda0cc662010-10-20 06:07:45 -0700163 /* send register offset */
164 while (1) {
165 status = wait_for_pin();
166 if (status == 0 || status & I2C_STAT_NACK) {
wdenk8ed96042005-01-09 23:16:25 +0000167 i2c_error = 1;
Steve Sakomanda0cc662010-10-20 06:07:45 -0700168 goto read_exit;
wdenk8ed96042005-01-09 23:16:25 +0000169 }
Steve Sakomanda0cc662010-10-20 06:07:45 -0700170 if (status & I2C_STAT_XRDY) {
171 /* Important: have to use byte access */
172 writeb(regoffset, &i2c_base->data);
173 writew(I2C_STAT_XRDY, &i2c_base->stat);
174 }
175 if (status & I2C_STAT_ARDY) {
176 writew(I2C_STAT_ARDY, &i2c_base->stat);
177 break;
178 }
wdenk8ed96042005-01-09 23:16:25 +0000179 }
180
Steve Sakomanda0cc662010-10-20 06:07:45 -0700181 /* set slave address */
182 writew(devaddr, &i2c_base->sa);
183 /* read one byte from slave */
184 writew(1, &i2c_base->cnt);
185 /* need stop bit here */
186 writew(I2C_CON_EN | I2C_CON_MST |
187 I2C_CON_STT | I2C_CON_STP,
188 &i2c_base->con);
189
190 /* receive data */
191 while (1) {
192 status = wait_for_pin();
193 if (status == 0 || status & I2C_STAT_NACK) {
194 i2c_error = 1;
195 goto read_exit;
wdenk8ed96042005-01-09 23:16:25 +0000196 }
wdenk8ed96042005-01-09 23:16:25 +0000197 if (status & I2C_STAT_RRDY) {
Steve Sakoman938717c2010-06-12 06:42:57 -0700198#if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX) || \
199 defined(CONFIG_OMAP44XX)
Steve Sakomanda0cc662010-10-20 06:07:45 -0700200 *value = readb(&i2c_base->data);
Dirk Behme7d264c12008-12-14 09:47:18 +0100201#else
Steve Sakomanda0cc662010-10-20 06:07:45 -0700202 *value = readw(&i2c_base->data);
Dirk Behme7d264c12008-12-14 09:47:18 +0100203#endif
Steve Sakomanda0cc662010-10-20 06:07:45 -0700204 writew(I2C_STAT_RRDY, &i2c_base->stat);
wdenk8ed96042005-01-09 23:16:25 +0000205 }
Steve Sakomanda0cc662010-10-20 06:07:45 -0700206 if (status & I2C_STAT_ARDY) {
207 writew(I2C_STAT_ARDY, &i2c_base->stat);
208 break;
wdenk8ed96042005-01-09 23:16:25 +0000209 }
210 }
Steve Sakomanda0cc662010-10-20 06:07:45 -0700211
212read_exit:
wdenk8ed96042005-01-09 23:16:25 +0000213 flush_fifo();
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100214 writew (0xFFFF, &i2c_base->stat);
215 writew (0, &i2c_base->cnt);
wdenk8ed96042005-01-09 23:16:25 +0000216 return i2c_error;
217}
218
219static int i2c_write_byte (u8 devaddr, u8 regoffset, u8 value)
220{
221 int i2c_error = 0;
Steve Sakomand480c462010-10-20 06:07:46 -0700222 u16 status;
wdenk8ed96042005-01-09 23:16:25 +0000223
224 /* wait until bus not busy */
225 wait_for_bb ();
226
227 /* two bytes */
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100228 writew (2, &i2c_base->cnt);
wdenk8ed96042005-01-09 23:16:25 +0000229 /* set slave address */
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100230 writew (devaddr, &i2c_base->sa);
wdenk8ed96042005-01-09 23:16:25 +0000231 /* stop bit needed here */
Dirk Behmee23c7c92008-11-10 20:15:25 +0100232 writew (I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_TRX |
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100233 I2C_CON_STP, &i2c_base->con);
wdenk8ed96042005-01-09 23:16:25 +0000234
Steve Sakomand480c462010-10-20 06:07:46 -0700235 while (1) {
236 status = wait_for_pin();
237 if (status == 0 || status & I2C_STAT_NACK) {
238 i2c_error = 1;
239 goto write_exit;
240 }
241 if (status & I2C_STAT_XRDY) {
Steve Sakoman938717c2010-06-12 06:42:57 -0700242#if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX) || \
243 defined(CONFIG_OMAP44XX)
Steve Sakomand480c462010-10-20 06:07:46 -0700244 /* send register offset */
245 writeb(regoffset, &i2c_base->data);
246 writew(I2C_STAT_XRDY, &i2c_base->stat);
Dirk Behme7d264c12008-12-14 09:47:18 +0100247
Steve Sakomand480c462010-10-20 06:07:46 -0700248 while (1) {
249 status = wait_for_pin();
250 if (status == 0 || status & I2C_STAT_NACK) {
251 i2c_error = 1;
252 goto write_exit;
253 }
254 if (status & I2C_STAT_XRDY) {
255 /* send data */
256 writeb(value, &i2c_base->data);
257 writew(I2C_STAT_XRDY, &i2c_base->stat);
258 }
259 if (status & I2C_STAT_ARDY) {
260 writew(I2C_STAT_ARDY, &i2c_base->stat);
261 break;
262 }
263 }
264 break;
Dirk Behme7d264c12008-12-14 09:47:18 +0100265#else
Steve Sakomand480c462010-10-20 06:07:46 -0700266 /* send out two bytes */
267 writew((value << 8) + regoffset, &i2c_base->data);
268 writew(I2C_STAT_XRDY, &i2c_base->stat);
Dirk Behme7d264c12008-12-14 09:47:18 +0100269#endif
wdenk8ed96042005-01-09 23:16:25 +0000270 }
Steve Sakomand480c462010-10-20 06:07:46 -0700271 if (status & I2C_STAT_ARDY) {
272 writew(I2C_STAT_ARDY, &i2c_base->stat);
273 break;
274 }
275 }
276
277 wait_for_bb();
278
279 status = readw(&i2c_base->stat);
280 if (status & I2C_STAT_NACK)
wdenk8ed96042005-01-09 23:16:25 +0000281 i2c_error = 1;
wdenk8ed96042005-01-09 23:16:25 +0000282
Steve Sakomand480c462010-10-20 06:07:46 -0700283write_exit:
wdenk8ed96042005-01-09 23:16:25 +0000284 flush_fifo();
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100285 writew (0xFFFF, &i2c_base->stat);
286 writew (0, &i2c_base->cnt);
wdenk8ed96042005-01-09 23:16:25 +0000287 return i2c_error;
288}
289
Wolfgang Denk49a75812005-09-25 18:41:04 +0200290static void flush_fifo(void)
wdenk8ed96042005-01-09 23:16:25 +0000291{ u16 stat;
wdenk082acfd2005-01-10 00:01:04 +0000292
293 /* note: if you try and read data when its not there or ready
294 * you get a bus error
295 */
wdenk8ed96042005-01-09 23:16:25 +0000296 while(1){
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100297 stat = readw(&i2c_base->stat);
wdenk8ed96042005-01-09 23:16:25 +0000298 if(stat == I2C_STAT_RRDY){
Steve Sakoman938717c2010-06-12 06:42:57 -0700299#if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX) || \
300 defined(CONFIG_OMAP44XX)
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100301 readb(&i2c_base->data);
Dirk Behme7d264c12008-12-14 09:47:18 +0100302#else
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100303 readw(&i2c_base->data);
Dirk Behme7d264c12008-12-14 09:47:18 +0100304#endif
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100305 writew(I2C_STAT_RRDY,&i2c_base->stat);
wdenk8ed96042005-01-09 23:16:25 +0000306 udelay(1000);
307 }else
308 break;
309 }
310}
311
312int i2c_probe (uchar chip)
313{
Steve Sakomanfbad3552010-10-20 06:07:47 -0700314 u16 status;
wdenk8ed96042005-01-09 23:16:25 +0000315 int res = 1; /* default = fail */
316
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100317 if (chip == readw (&i2c_base->oa)) {
wdenk8ed96042005-01-09 23:16:25 +0000318 return res;
319 }
320
321 /* wait until bus not busy */
322 wait_for_bb ();
323
324 /* try to read one byte */
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100325 writew (1, &i2c_base->cnt);
wdenk8ed96042005-01-09 23:16:25 +0000326 /* set slave address */
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100327 writew (chip, &i2c_base->sa);
wdenk8ed96042005-01-09 23:16:25 +0000328 /* stop bit needed here */
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100329 writew (I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_STP, &i2c_base->con);
wdenk8ed96042005-01-09 23:16:25 +0000330
Steve Sakomanfbad3552010-10-20 06:07:47 -0700331 while (1) {
332 status = wait_for_pin();
Steve Sakoman4df66892010-10-22 13:48:00 -0700333 if (status == 0 || status & I2C_STAT_AL) {
Steve Sakomanfbad3552010-10-20 06:07:47 -0700334 res = 1;
335 goto probe_exit;
336 }
337 if (status & I2C_STAT_NACK) {
338 res = 1;
339 writew(0xff, &i2c_base->stat);
340 writew (readw (&i2c_base->con) | I2C_CON_STP, &i2c_base->con);
341 wait_for_bb ();
342 break;
343 }
344 if (status & I2C_STAT_ARDY) {
345 writew(I2C_STAT_ARDY, &i2c_base->stat);
346 break;
347 }
348 if (status & I2C_STAT_RRDY) {
349 res = 0;
350#if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX) || \
351 defined(CONFIG_OMAP44XX)
352 readb(&i2c_base->data);
353#else
354 readw(&i2c_base->data);
355#endif
356 writew(I2C_STAT_RRDY, &i2c_base->stat);
357 }
wdenk8ed96042005-01-09 23:16:25 +0000358 }
Steve Sakomanfbad3552010-10-20 06:07:47 -0700359
360probe_exit:
wdenk8ed96042005-01-09 23:16:25 +0000361 flush_fifo();
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100362 writew (0, &i2c_base->cnt); /* don't allow any more data in...we don't want it.*/
363 writew(0xFFFF, &i2c_base->stat);
wdenk8ed96042005-01-09 23:16:25 +0000364 return res;
365}
366
367int i2c_read (uchar chip, uint addr, int alen, uchar * buffer, int len)
368{
369 int i;
370
371 if (alen > 1) {
372 printf ("I2C read: addr len %d not supported\n", alen);
373 return 1;
374 }
375
376 if (addr + len > 256) {
377 printf ("I2C read: address out of range\n");
378 return 1;
379 }
380
381 for (i = 0; i < len; i++) {
382 if (i2c_read_byte (chip, addr + i, &buffer[i])) {
383 printf ("I2C read: I/O error\n");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200384 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
wdenk8ed96042005-01-09 23:16:25 +0000385 return 1;
386 }
387 }
388
389 return 0;
390}
391
392int i2c_write (uchar chip, uint addr, int alen, uchar * buffer, int len)
393{
394 int i;
395
396 if (alen > 1) {
397 printf ("I2C read: addr len %d not supported\n", alen);
398 return 1;
399 }
400
401 if (addr + len > 256) {
402 printf ("I2C read: address out of range\n");
403 return 1;
404 }
405
406 for (i = 0; i < len; i++) {
407 if (i2c_write_byte (chip, addr + i, buffer[i])) {
408 printf ("I2C read: I/O error\n");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200409 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
wdenk8ed96042005-01-09 23:16:25 +0000410 return 1;
411 }
412 }
413
414 return 0;
415}
416
417static void wait_for_bb (void)
418{
Steve Sakoman73e87472010-10-20 06:07:44 -0700419 int timeout = I2C_TIMEOUT;
wdenk8ed96042005-01-09 23:16:25 +0000420 u16 stat;
421
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100422 writew(0xFFFF, &i2c_base->stat); /* clear current interruts...*/
423 while ((stat = readw (&i2c_base->stat) & I2C_STAT_BB) && timeout--) {
424 writew (stat, &i2c_base->stat);
Steve Sakoman73e87472010-10-20 06:07:44 -0700425 udelay(1000);
wdenk8ed96042005-01-09 23:16:25 +0000426 }
427
428 if (timeout <= 0) {
429 printf ("timed out in wait_for_bb: I2C_STAT=%x\n",
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100430 readw (&i2c_base->stat));
wdenk8ed96042005-01-09 23:16:25 +0000431 }
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100432 writew(0xFFFF, &i2c_base->stat); /* clear delayed stuff*/
wdenk8ed96042005-01-09 23:16:25 +0000433}
434
435static u16 wait_for_pin (void)
436{
437 u16 status;
Steve Sakoman73e87472010-10-20 06:07:44 -0700438 int timeout = I2C_TIMEOUT;
wdenk8ed96042005-01-09 23:16:25 +0000439
440 do {
441 udelay (1000);
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100442 status = readw (&i2c_base->stat);
wdenk8ed96042005-01-09 23:16:25 +0000443 } while ( !(status &
444 (I2C_STAT_ROVR | I2C_STAT_XUDF | I2C_STAT_XRDY |
445 I2C_STAT_RRDY | I2C_STAT_ARDY | I2C_STAT_NACK |
446 I2C_STAT_AL)) && timeout--);
447
448 if (timeout <= 0) {
449 printf ("timed out in wait_for_pin: I2C_STAT=%x\n",
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100450 readw (&i2c_base->stat));
Steve Sakoman73e87472010-10-20 06:07:44 -0700451 writew(0xFFFF, &i2c_base->stat);
452 status = 0;
453 }
454
wdenk8ed96042005-01-09 23:16:25 +0000455 return status;
456}
Dirk Behme1d2e96d2009-11-02 20:36:26 +0100457
458int i2c_set_bus_num(unsigned int bus)
459{
460 if ((bus < 0) || (bus >= I2C_BUS_MAX)) {
461 printf("Bad bus: %d\n", bus);
462 return -1;
463 }
464
465#if I2C_BUS_MAX==3
466 if (bus == 2)
467 i2c_base = (struct i2c *)I2C_BASE3;
468 else
469#endif
470 if (bus == 1)
471 i2c_base = (struct i2c *)I2C_BASE2;
472 else
473 i2c_base = (struct i2c *)I2C_BASE1;
474
475 current_bus = bus;
476
477 if(!bus_initialized[current_bus])
478 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
479
480 return 0;
481}
Steve Sakoman938717c2010-06-12 06:42:57 -0700482
483int i2c_get_bus_num(void)
484{
485 return (int) current_bus;
486}