blob: a72d1a125702dd7f3f55ec2476a80b91ad6d7fea [file] [log] [blame]
wdenkf8062712005-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>
wdenkcb99da52005-01-12 00:15:14 +000024
wdenkf8062712005-01-09 23:16:25 +000025#include <asm/arch/i2c.h>
26#include <asm/io.h>
27
Steve Sakoman10acc712010-06-12 06:42:57 -070028#include "omap24xx_i2c.h"
29
Steve Sakomanfb5c39a2010-10-20 06:07:44 -070030#define I2C_TIMEOUT 1000
Steve Sakomane2bdc132010-07-19 20:31:55 -070031
wdenkf8062712005-01-09 23:16:25 +000032static void wait_for_bb (void);
33static u16 wait_for_pin (void);
Wolfgang Denke1e46792005-09-25 18:41:04 +020034static void flush_fifo(void);
wdenkf8062712005-01-09 23:16:25 +000035
Dirk Behme7a8f6572009-11-02 20:36:26 +010036static struct i2c *i2c_base = (struct i2c *)I2C_DEFAULT_BASE;
37
38static unsigned int bus_initialized[I2C_BUS_MAX];
39static unsigned int current_bus;
40
wdenkf8062712005-01-09 23:16:25 +000041void i2c_init (int speed, int slaveadd)
42{
Heiko Schocher2afe3142010-09-17 13:10:37 +020043 DECLARE_GLOBAL_DATA_PTR;
Tom Rix03b2a742009-06-28 12:52:27 -050044 int psc, fsscll, fssclh;
45 int hsscll = 0, hssclh = 0;
46 u32 scll, sclh;
Steve Sakomane2bdc132010-07-19 20:31:55 -070047 int timeout = I2C_TIMEOUT;
Tom Rix03b2a742009-06-28 12:52:27 -050048
49 /* Only handle standard, fast and high speeds */
50 if ((speed != OMAP_I2C_STANDARD) &&
51 (speed != OMAP_I2C_FAST_MODE) &&
52 (speed != OMAP_I2C_HIGH_SPEED)) {
53 printf("Error : I2C unsupported speed %d\n", speed);
54 return;
55 }
56
57 psc = I2C_IP_CLK / I2C_INTERNAL_SAMPLING_CLK;
58 psc -= 1;
59 if (psc < I2C_PSC_MIN) {
60 printf("Error : I2C unsupported prescalar %d\n", psc);
61 return;
62 }
63
64 if (speed == OMAP_I2C_HIGH_SPEED) {
65 /* High speed */
66
67 /* For first phase of HS mode */
68 fsscll = fssclh = I2C_INTERNAL_SAMPLING_CLK /
69 (2 * OMAP_I2C_FAST_MODE);
70
71 fsscll -= I2C_HIGHSPEED_PHASE_ONE_SCLL_TRIM;
72 fssclh -= I2C_HIGHSPEED_PHASE_ONE_SCLH_TRIM;
73 if (((fsscll < 0) || (fssclh < 0)) ||
74 ((fsscll > 255) || (fssclh > 255))) {
75 printf("Error : I2C initializing first phase clock\n");
76 return;
77 }
78
79 /* For second phase of HS mode */
80 hsscll = hssclh = I2C_INTERNAL_SAMPLING_CLK / (2 * speed);
81
82 hsscll -= I2C_HIGHSPEED_PHASE_TWO_SCLL_TRIM;
83 hssclh -= I2C_HIGHSPEED_PHASE_TWO_SCLH_TRIM;
84 if (((fsscll < 0) || (fssclh < 0)) ||
85 ((fsscll > 255) || (fssclh > 255))) {
86 printf("Error : I2C initializing second phase clock\n");
87 return;
88 }
89
90 scll = (unsigned int)hsscll << 8 | (unsigned int)fsscll;
91 sclh = (unsigned int)hssclh << 8 | (unsigned int)fssclh;
92
93 } else {
94 /* Standard and fast speed */
95 fsscll = fssclh = I2C_INTERNAL_SAMPLING_CLK / (2 * speed);
96
97 fsscll -= I2C_FASTSPEED_SCLL_TRIM;
98 fssclh -= I2C_FASTSPEED_SCLH_TRIM;
99 if (((fsscll < 0) || (fssclh < 0)) ||
100 ((fsscll > 255) || (fssclh > 255))) {
101 printf("Error : I2C initializing clock\n");
102 return;
103 }
104
105 scll = (unsigned int)fsscll;
106 sclh = (unsigned int)fssclh;
107 }
wdenkf8062712005-01-09 23:16:25 +0000108
Dirk Behme7a8f6572009-11-02 20:36:26 +0100109 if (readw (&i2c_base->con) & I2C_CON_EN) {
110 writew (0, &i2c_base->con);
wdenkf8062712005-01-09 23:16:25 +0000111 udelay (50000);
112 }
113
Steve Sakomane2bdc132010-07-19 20:31:55 -0700114 writew(0x2, &i2c_base->sysc); /* for ES2 after soft reset */
115 udelay(1000);
116
117 writew(I2C_CON_EN, &i2c_base->con);
118 while (!(readw(&i2c_base->syss) & I2C_SYSS_RDONE) && timeout--) {
119 if (timeout <= 0) {
120 printf("ERROR: Timeout in soft-reset\n");
121 return;
122 }
123 udelay(1000);
124 }
125
126 writew(0, &i2c_base->con);
Dirk Behme7a8f6572009-11-02 20:36:26 +0100127 writew(psc, &i2c_base->psc);
128 writew(scll, &i2c_base->scll);
129 writew(sclh, &i2c_base->sclh);
Tom Rix03b2a742009-06-28 12:52:27 -0500130
wdenkf8062712005-01-09 23:16:25 +0000131 /* own address */
Dirk Behme7a8f6572009-11-02 20:36:26 +0100132 writew (slaveadd, &i2c_base->oa);
133 writew (I2C_CON_EN, &i2c_base->con);
Wolfgang Denke1e46792005-09-25 18:41:04 +0200134
wdenkf8062712005-01-09 23:16:25 +0000135 /* have to enable intrrupts or OMAP i2c module doesn't work */
Dirk Behme5a6dc872008-11-10 20:15:25 +0100136 writew (I2C_IE_XRDY_IE | I2C_IE_RRDY_IE | I2C_IE_ARDY_IE |
Dirk Behme7a8f6572009-11-02 20:36:26 +0100137 I2C_IE_NACK_IE | I2C_IE_AL_IE, &i2c_base->ie);
wdenkf8062712005-01-09 23:16:25 +0000138 udelay (1000);
Wolfgang Denke1e46792005-09-25 18:41:04 +0200139 flush_fifo();
Dirk Behme7a8f6572009-11-02 20:36:26 +0100140 writew (0xFFFF, &i2c_base->stat);
141 writew (0, &i2c_base->cnt);
142
Heiko Schocher2afe3142010-09-17 13:10:37 +0200143 if (gd->flags & GD_FLG_RELOC)
144 bus_initialized[current_bus] = 1;
wdenkf8062712005-01-09 23:16:25 +0000145}
146
147static int i2c_read_byte (u8 devaddr, u8 regoffset, u8 * value)
148{
149 int i2c_error = 0;
150 u16 status;
151
152 /* wait until bus not busy */
153 wait_for_bb ();
154
155 /* one byte only */
Dirk Behme7a8f6572009-11-02 20:36:26 +0100156 writew (1, &i2c_base->cnt);
wdenkf8062712005-01-09 23:16:25 +0000157 /* set slave address */
Dirk Behme7a8f6572009-11-02 20:36:26 +0100158 writew (devaddr, &i2c_base->sa);
wdenkf8062712005-01-09 23:16:25 +0000159 /* no stop bit needed here */
Dirk Behme7a8f6572009-11-02 20:36:26 +0100160 writew (I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_TRX, &i2c_base->con);
wdenkf8062712005-01-09 23:16:25 +0000161
Steve Sakoman519effe2010-10-20 06:07:45 -0700162 /* send register offset */
163 while (1) {
164 status = wait_for_pin();
165 if (status == 0 || status & I2C_STAT_NACK) {
wdenkf8062712005-01-09 23:16:25 +0000166 i2c_error = 1;
Steve Sakoman519effe2010-10-20 06:07:45 -0700167 goto read_exit;
wdenkf8062712005-01-09 23:16:25 +0000168 }
Steve Sakoman519effe2010-10-20 06:07:45 -0700169 if (status & I2C_STAT_XRDY) {
170 /* Important: have to use byte access */
171 writeb(regoffset, &i2c_base->data);
172 writew(I2C_STAT_XRDY, &i2c_base->stat);
wdenkf8062712005-01-09 23:16:25 +0000173 }
Steve Sakoman519effe2010-10-20 06:07:45 -0700174 if (status & I2C_STAT_ARDY) {
175 writew(I2C_STAT_ARDY, &i2c_base->stat);
176 break;
177 }
178 }
wdenkf8062712005-01-09 23:16:25 +0000179
Steve Sakoman519effe2010-10-20 06:07:45 -0700180 /* set slave address */
181 writew(devaddr, &i2c_base->sa);
182 /* read one byte from slave */
183 writew(1, &i2c_base->cnt);
184 /* need stop bit here */
185 writew(I2C_CON_EN | I2C_CON_MST |
186 I2C_CON_STT | I2C_CON_STP,
187 &i2c_base->con);
wdenkf8062712005-01-09 23:16:25 +0000188
Steve Sakoman519effe2010-10-20 06:07:45 -0700189 /* receive data */
190 while (1) {
191 status = wait_for_pin();
192 if (status == 0 || status & I2C_STAT_NACK) {
193 i2c_error = 1;
194 goto read_exit;
195 }
wdenkf8062712005-01-09 23:16:25 +0000196 if (status & I2C_STAT_RRDY) {
Steve Sakoman10acc712010-06-12 06:42:57 -0700197#if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX) || \
198 defined(CONFIG_OMAP44XX)
Steve Sakoman519effe2010-10-20 06:07:45 -0700199 *value = readb(&i2c_base->data);
Dirk Behme5648e512008-12-14 09:47:18 +0100200#else
Steve Sakoman519effe2010-10-20 06:07:45 -0700201 *value = readw(&i2c_base->data);
Dirk Behme5648e512008-12-14 09:47:18 +0100202#endif
Steve Sakoman519effe2010-10-20 06:07:45 -0700203 writew(I2C_STAT_RRDY, &i2c_base->stat);
wdenkf8062712005-01-09 23:16:25 +0000204 }
Steve Sakoman519effe2010-10-20 06:07:45 -0700205 if (status & I2C_STAT_ARDY) {
206 writew(I2C_STAT_ARDY, &i2c_base->stat);
207 break;
wdenkf8062712005-01-09 23:16:25 +0000208 }
209 }
Steve Sakoman519effe2010-10-20 06:07:45 -0700210
211read_exit:
wdenkf8062712005-01-09 23:16:25 +0000212 flush_fifo();
Dirk Behme7a8f6572009-11-02 20:36:26 +0100213 writew (0xFFFF, &i2c_base->stat);
214 writew (0, &i2c_base->cnt);
wdenkf8062712005-01-09 23:16:25 +0000215 return i2c_error;
216}
217
218static int i2c_write_byte (u8 devaddr, u8 regoffset, u8 value)
219{
220 int i2c_error = 0;
Steve Sakoman94be7612010-10-20 06:07:46 -0700221 u16 status;
wdenkf8062712005-01-09 23:16:25 +0000222
223 /* wait until bus not busy */
224 wait_for_bb ();
225
226 /* two bytes */
Dirk Behme7a8f6572009-11-02 20:36:26 +0100227 writew (2, &i2c_base->cnt);
wdenkf8062712005-01-09 23:16:25 +0000228 /* set slave address */
Dirk Behme7a8f6572009-11-02 20:36:26 +0100229 writew (devaddr, &i2c_base->sa);
wdenkf8062712005-01-09 23:16:25 +0000230 /* stop bit needed here */
Dirk Behme5a6dc872008-11-10 20:15:25 +0100231 writew (I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_TRX |
Dirk Behme7a8f6572009-11-02 20:36:26 +0100232 I2C_CON_STP, &i2c_base->con);
wdenkf8062712005-01-09 23:16:25 +0000233
Steve Sakoman94be7612010-10-20 06:07:46 -0700234 while (1) {
235 status = wait_for_pin();
236 if (status == 0 || status & I2C_STAT_NACK) {
237 i2c_error = 1;
238 goto write_exit;
239 }
240 if (status & I2C_STAT_XRDY) {
Steve Sakoman10acc712010-06-12 06:42:57 -0700241#if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX) || \
242 defined(CONFIG_OMAP44XX)
Steve Sakoman94be7612010-10-20 06:07:46 -0700243 /* send register offset */
244 writeb(regoffset, &i2c_base->data);
245 writew(I2C_STAT_XRDY, &i2c_base->stat);
Dirk Behme5648e512008-12-14 09:47:18 +0100246
Steve Sakoman94be7612010-10-20 06:07:46 -0700247 while (1) {
248 status = wait_for_pin();
249 if (status == 0 || status & I2C_STAT_NACK) {
250 i2c_error = 1;
251 goto write_exit;
252 }
253 if (status & I2C_STAT_XRDY) {
254 /* send data */
255 writeb(value, &i2c_base->data);
256 writew(I2C_STAT_XRDY, &i2c_base->stat);
257 }
258 if (status & I2C_STAT_ARDY) {
259 writew(I2C_STAT_ARDY, &i2c_base->stat);
260 break;
261 }
262 }
263 break;
Dirk Behme5648e512008-12-14 09:47:18 +0100264#else
Steve Sakoman94be7612010-10-20 06:07:46 -0700265 /* send out two bytes */
266 writew((value << 8) + regoffset, &i2c_base->data);
267 writew(I2C_STAT_XRDY, &i2c_base->stat);
Dirk Behme5648e512008-12-14 09:47:18 +0100268#endif
wdenkf8062712005-01-09 23:16:25 +0000269 }
Steve Sakoman94be7612010-10-20 06:07:46 -0700270 if (status & I2C_STAT_ARDY) {
271 writew(I2C_STAT_ARDY, &i2c_base->stat);
272 break;
273 }
wdenkf8062712005-01-09 23:16:25 +0000274 }
275
Steve Sakoman94be7612010-10-20 06:07:46 -0700276 wait_for_bb();
Wolfgang Denke1e46792005-09-25 18:41:04 +0200277
Steve Sakoman94be7612010-10-20 06:07:46 -0700278 status = readw(&i2c_base->stat);
279 if (status & I2C_STAT_NACK)
280 i2c_error = 1;
281
282write_exit:
wdenkf8062712005-01-09 23:16:25 +0000283 flush_fifo();
Dirk Behme7a8f6572009-11-02 20:36:26 +0100284 writew (0xFFFF, &i2c_base->stat);
285 writew (0, &i2c_base->cnt);
wdenkf8062712005-01-09 23:16:25 +0000286 return i2c_error;
287}
288
Wolfgang Denke1e46792005-09-25 18:41:04 +0200289static void flush_fifo(void)
wdenkf8062712005-01-09 23:16:25 +0000290{ u16 stat;
wdenk2e405bf2005-01-10 00:01:04 +0000291
292 /* note: if you try and read data when its not there or ready
293 * you get a bus error
294 */
wdenkf8062712005-01-09 23:16:25 +0000295 while(1){
Dirk Behme7a8f6572009-11-02 20:36:26 +0100296 stat = readw(&i2c_base->stat);
wdenkf8062712005-01-09 23:16:25 +0000297 if(stat == I2C_STAT_RRDY){
Steve Sakoman10acc712010-06-12 06:42:57 -0700298#if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX) || \
299 defined(CONFIG_OMAP44XX)
Dirk Behme7a8f6572009-11-02 20:36:26 +0100300 readb(&i2c_base->data);
Dirk Behme5648e512008-12-14 09:47:18 +0100301#else
Dirk Behme7a8f6572009-11-02 20:36:26 +0100302 readw(&i2c_base->data);
Dirk Behme5648e512008-12-14 09:47:18 +0100303#endif
Dirk Behme7a8f6572009-11-02 20:36:26 +0100304 writew(I2C_STAT_RRDY,&i2c_base->stat);
wdenkf8062712005-01-09 23:16:25 +0000305 udelay(1000);
306 }else
307 break;
308 }
309}
310
311int i2c_probe (uchar chip)
312{
Steve Sakomana91a1df2010-10-20 06:07:47 -0700313 u16 status;
wdenkf8062712005-01-09 23:16:25 +0000314 int res = 1; /* default = fail */
315
Dirk Behme7a8f6572009-11-02 20:36:26 +0100316 if (chip == readw (&i2c_base->oa)) {
wdenkf8062712005-01-09 23:16:25 +0000317 return res;
318 }
319
320 /* wait until bus not busy */
321 wait_for_bb ();
322
323 /* try to read one byte */
Dirk Behme7a8f6572009-11-02 20:36:26 +0100324 writew (1, &i2c_base->cnt);
wdenkf8062712005-01-09 23:16:25 +0000325 /* set slave address */
Dirk Behme7a8f6572009-11-02 20:36:26 +0100326 writew (chip, &i2c_base->sa);
wdenkf8062712005-01-09 23:16:25 +0000327 /* stop bit needed here */
Dirk Behme7a8f6572009-11-02 20:36:26 +0100328 writew (I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_STP, &i2c_base->con);
wdenkf8062712005-01-09 23:16:25 +0000329
Steve Sakomana91a1df2010-10-20 06:07:47 -0700330 while (1) {
331 status = wait_for_pin();
332 if (status == 0) {
333 res = 1;
334 goto probe_exit;
335 }
336 if (status & I2C_STAT_NACK) {
337 res = 1;
338 writew(0xff, &i2c_base->stat);
339 writew (readw (&i2c_base->con) | I2C_CON_STP, &i2c_base->con);
340 wait_for_bb ();
341 break;
342 }
343 if (status & I2C_STAT_ARDY) {
344 writew(I2C_STAT_ARDY, &i2c_base->stat);
345 break;
346 }
347 if (status & I2C_STAT_RRDY) {
348 res = 0;
349#if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX) || \
350 defined(CONFIG_OMAP44XX)
351 readb(&i2c_base->data);
352#else
353 readw(&i2c_base->data);
354#endif
355 writew(I2C_STAT_RRDY, &i2c_base->stat);
356 }
wdenkf8062712005-01-09 23:16:25 +0000357 }
Steve Sakomana91a1df2010-10-20 06:07:47 -0700358
359probe_exit:
wdenkf8062712005-01-09 23:16:25 +0000360 flush_fifo();
Dirk Behme7a8f6572009-11-02 20:36:26 +0100361 writew (0, &i2c_base->cnt); /* don't allow any more data in...we don't want it.*/
362 writew(0xFFFF, &i2c_base->stat);
wdenkf8062712005-01-09 23:16:25 +0000363 return res;
364}
365
366int i2c_read (uchar chip, uint addr, int alen, uchar * buffer, int len)
367{
368 int i;
369
370 if (alen > 1) {
371 printf ("I2C read: addr len %d not supported\n", alen);
372 return 1;
373 }
374
375 if (addr + len > 256) {
376 printf ("I2C read: address out of range\n");
377 return 1;
378 }
379
380 for (i = 0; i < len; i++) {
381 if (i2c_read_byte (chip, addr + i, &buffer[i])) {
382 printf ("I2C read: I/O error\n");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200383 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
wdenkf8062712005-01-09 23:16:25 +0000384 return 1;
385 }
386 }
387
388 return 0;
389}
390
391int i2c_write (uchar chip, uint addr, int alen, uchar * buffer, int len)
392{
393 int i;
394
395 if (alen > 1) {
396 printf ("I2C read: addr len %d not supported\n", alen);
397 return 1;
398 }
399
400 if (addr + len > 256) {
401 printf ("I2C read: address out of range\n");
402 return 1;
403 }
404
405 for (i = 0; i < len; i++) {
406 if (i2c_write_byte (chip, addr + i, buffer[i])) {
407 printf ("I2C read: I/O error\n");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200408 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
wdenkf8062712005-01-09 23:16:25 +0000409 return 1;
410 }
411 }
412
413 return 0;
414}
415
416static void wait_for_bb (void)
417{
Steve Sakomanfb5c39a2010-10-20 06:07:44 -0700418 int timeout = I2C_TIMEOUT;
wdenkf8062712005-01-09 23:16:25 +0000419 u16 stat;
420
Dirk Behme7a8f6572009-11-02 20:36:26 +0100421 writew(0xFFFF, &i2c_base->stat); /* clear current interruts...*/
422 while ((stat = readw (&i2c_base->stat) & I2C_STAT_BB) && timeout--) {
423 writew (stat, &i2c_base->stat);
Steve Sakomanfb5c39a2010-10-20 06:07:44 -0700424 udelay(1000);
wdenkf8062712005-01-09 23:16:25 +0000425 }
426
427 if (timeout <= 0) {
428 printf ("timed out in wait_for_bb: I2C_STAT=%x\n",
Dirk Behme7a8f6572009-11-02 20:36:26 +0100429 readw (&i2c_base->stat));
wdenkf8062712005-01-09 23:16:25 +0000430 }
Dirk Behme7a8f6572009-11-02 20:36:26 +0100431 writew(0xFFFF, &i2c_base->stat); /* clear delayed stuff*/
wdenkf8062712005-01-09 23:16:25 +0000432}
433
434static u16 wait_for_pin (void)
435{
436 u16 status;
Steve Sakomanfb5c39a2010-10-20 06:07:44 -0700437 int timeout = I2C_TIMEOUT;
wdenkf8062712005-01-09 23:16:25 +0000438
439 do {
440 udelay (1000);
Dirk Behme7a8f6572009-11-02 20:36:26 +0100441 status = readw (&i2c_base->stat);
wdenkf8062712005-01-09 23:16:25 +0000442 } while ( !(status &
443 (I2C_STAT_ROVR | I2C_STAT_XUDF | I2C_STAT_XRDY |
444 I2C_STAT_RRDY | I2C_STAT_ARDY | I2C_STAT_NACK |
445 I2C_STAT_AL)) && timeout--);
446
447 if (timeout <= 0) {
448 printf ("timed out in wait_for_pin: I2C_STAT=%x\n",
Dirk Behme7a8f6572009-11-02 20:36:26 +0100449 readw (&i2c_base->stat));
Steve Sakomanfb5c39a2010-10-20 06:07:44 -0700450 writew(0xFFFF, &i2c_base->stat);
451 status = 0;
452 }
453
wdenkf8062712005-01-09 23:16:25 +0000454 return status;
455}
Dirk Behme7a8f6572009-11-02 20:36:26 +0100456
457int i2c_set_bus_num(unsigned int bus)
458{
459 if ((bus < 0) || (bus >= I2C_BUS_MAX)) {
460 printf("Bad bus: %d\n", bus);
461 return -1;
462 }
463
464#if I2C_BUS_MAX==3
465 if (bus == 2)
466 i2c_base = (struct i2c *)I2C_BASE3;
467 else
468#endif
469 if (bus == 1)
470 i2c_base = (struct i2c *)I2C_BASE2;
471 else
472 i2c_base = (struct i2c *)I2C_BASE1;
473
474 current_bus = bus;
475
476 if(!bus_initialized[current_bus])
477 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
478
479 return 0;
480}
Steve Sakoman10acc712010-06-12 06:42:57 -0700481
482int i2c_get_bus_num(void)
483{
484 return (int) current_bus;
485}