omap24xx_i2c.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  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. * Copyright (c) 2013 Lubomir Popov <lpopov@mm-sol.com>, MM Solutions
  22. * New i2c_read, i2c_write and i2c_probe functions, tested on OMAP4
  23. * (4430/60/70), OMAP5 (5430) and AM335X (3359); should work on older
  24. * OMAPs and derivatives as well. The only anticipated exception would
  25. * be the OMAP2420, which shall require driver modification.
  26. * - Rewritten i2c_read to operate correctly with all types of chips
  27. * (old function could not read consistent data from some I2C slaves).
  28. * - Optimized i2c_write.
  29. * - New i2c_probe, performs write access vs read. The old probe could
  30. * hang the system under certain conditions (e.g. unconfigured pads).
  31. * - The read/write/probe functions try to identify unconfigured bus.
  32. * - Status functions now read irqstatus_raw as per TRM guidelines
  33. * (except for OMAP243X and OMAP34XX).
  34. * - Driver now supports up to I2C5 (OMAP5).
  35. *
  36. * Copyright (c) 2014 Hannes Petermaier <oe5hpm@oevsv.at>, B&R
  37. * - Added support for set_speed
  38. *
  39. */
  40. #include <common.h>
  41. #include <i2c.h>
  42. #include <asm/arch/i2c.h>
  43. #include <asm/io.h>
  44. #include "omap24xx_i2c.h"
  45. DECLARE_GLOBAL_DATA_PTR;
  46. #define I2C_TIMEOUT 1000
  47. /* Absolutely safe for status update at 100 kHz I2C: */
  48. #define I2C_WAIT 200
  49. static int wait_for_bb(struct i2c_adapter *adap);
  50. static struct i2c *omap24_get_base(struct i2c_adapter *adap);
  51. static u16 wait_for_event(struct i2c_adapter *adap);
  52. static void flush_fifo(struct i2c_adapter *adap);
  53. static int omap24_i2c_findpsc(u32 *pscl, u32 *psch, uint speed)
  54. {
  55. unsigned int sampleclk, prescaler;
  56. int fsscll, fssclh;
  57. speed <<= 1;
  58. prescaler = 0;
  59. /*
  60. * some divisors may cause a precission loss, but shouldn't
  61. * be a big thing, because i2c_clk is then allready very slow.
  62. */
  63. while (prescaler <= 0xFF) {
  64. sampleclk = I2C_IP_CLK / (prescaler+1);
  65. fsscll = sampleclk / speed;
  66. fssclh = fsscll;
  67. fsscll -= I2C_FASTSPEED_SCLL_TRIM;
  68. fssclh -= I2C_FASTSPEED_SCLH_TRIM;
  69. if (((fsscll > 0) && (fssclh > 0)) &&
  70. ((fsscll <= (255-I2C_FASTSPEED_SCLL_TRIM)) &&
  71. (fssclh <= (255-I2C_FASTSPEED_SCLH_TRIM)))) {
  72. if (pscl)
  73. *pscl = fsscll;
  74. if (psch)
  75. *psch = fssclh;
  76. return prescaler;
  77. }
  78. prescaler++;
  79. }
  80. return -1;
  81. }
  82. static uint omap24_i2c_setspeed(struct i2c_adapter *adap, uint speed)
  83. {
  84. struct i2c *i2c_base = omap24_get_base(adap);
  85. int psc, fsscll = 0, fssclh = 0;
  86. int hsscll = 0, hssclh = 0;
  87. u32 scll = 0, sclh = 0;
  88. if (speed >= OMAP_I2C_HIGH_SPEED) {
  89. /* High speed */
  90. psc = I2C_IP_CLK / I2C_INTERNAL_SAMPLING_CLK;
  91. psc -= 1;
  92. if (psc < I2C_PSC_MIN) {
  93. printf("Error : I2C unsupported prescaler %d\n", psc);
  94. return -1;
  95. }
  96. /* For first phase of HS mode */
  97. fsscll = I2C_INTERNAL_SAMPLING_CLK / (2 * speed);
  98. fssclh = fsscll;
  99. fsscll -= I2C_HIGHSPEED_PHASE_ONE_SCLL_TRIM;
  100. fssclh -= I2C_HIGHSPEED_PHASE_ONE_SCLH_TRIM;
  101. if (((fsscll < 0) || (fssclh < 0)) ||
  102. ((fsscll > 255) || (fssclh > 255))) {
  103. puts("Error : I2C initializing first phase clock\n");
  104. return -1;
  105. }
  106. /* For second phase of HS mode */
  107. hsscll = hssclh = I2C_INTERNAL_SAMPLING_CLK / (2 * speed);
  108. hsscll -= I2C_HIGHSPEED_PHASE_TWO_SCLL_TRIM;
  109. hssclh -= I2C_HIGHSPEED_PHASE_TWO_SCLH_TRIM;
  110. if (((fsscll < 0) || (fssclh < 0)) ||
  111. ((fsscll > 255) || (fssclh > 255))) {
  112. puts("Error : I2C initializing second phase clock\n");
  113. return -1;
  114. }
  115. scll = (unsigned int)hsscll << 8 | (unsigned int)fsscll;
  116. sclh = (unsigned int)hssclh << 8 | (unsigned int)fssclh;
  117. } else {
  118. /* Standard and fast speed */
  119. psc = omap24_i2c_findpsc(&scll, &sclh, speed);
  120. if (0 > psc) {
  121. puts("Error : I2C initializing clock\n");
  122. return -1;
  123. }
  124. }
  125. adap->speed = speed;
  126. adap->waitdelay = (10000000 / speed) * 2; /* wait for 20 clkperiods */
  127. writew(0, &i2c_base->con);
  128. writew(psc, &i2c_base->psc);
  129. writew(scll, &i2c_base->scll);
  130. writew(sclh, &i2c_base->sclh);
  131. writew(I2C_CON_EN, &i2c_base->con);
  132. writew(0xFFFF, &i2c_base->stat); /* clear all pending status */
  133. return 0;
  134. }
  135. static void omap24_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd)
  136. {
  137. struct i2c *i2c_base = omap24_get_base(adap);
  138. int timeout = I2C_TIMEOUT;
  139. if (readw(&i2c_base->con) & I2C_CON_EN) {
  140. writew(0, &i2c_base->con);
  141. udelay(50000);
  142. }
  143. writew(0x2, &i2c_base->sysc); /* for ES2 after soft reset */
  144. udelay(1000);
  145. writew(I2C_CON_EN, &i2c_base->con);
  146. while (!(readw(&i2c_base->syss) & I2C_SYSS_RDONE) && timeout--) {
  147. if (timeout <= 0) {
  148. puts("ERROR: Timeout in soft-reset\n");
  149. return;
  150. }
  151. udelay(1000);
  152. }
  153. if (0 != omap24_i2c_setspeed(adap, speed)) {
  154. printf("ERROR: failed to setup I2C bus-speed!\n");
  155. return;
  156. }
  157. /* own address */
  158. writew(slaveadd, &i2c_base->oa);
  159. #if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX)
  160. /*
  161. * Have to enable interrupts for OMAP2/3, these IPs don't have
  162. * an 'irqstatus_raw' register and we shall have to poll 'stat'
  163. */
  164. writew(I2C_IE_XRDY_IE | I2C_IE_RRDY_IE | I2C_IE_ARDY_IE |
  165. I2C_IE_NACK_IE | I2C_IE_AL_IE, &i2c_base->ie);
  166. #endif
  167. udelay(1000);
  168. flush_fifo(adap);
  169. writew(0xFFFF, &i2c_base->stat);
  170. }
  171. static void flush_fifo(struct i2c_adapter *adap)
  172. {
  173. struct i2c *i2c_base = omap24_get_base(adap);
  174. u16 stat;
  175. /*
  176. * note: if you try and read data when its not there or ready
  177. * you get a bus error
  178. */
  179. while (1) {
  180. stat = readw(&i2c_base->stat);
  181. if (stat == I2C_STAT_RRDY) {
  182. readb(&i2c_base->data);
  183. writew(I2C_STAT_RRDY, &i2c_base->stat);
  184. udelay(1000);
  185. } else
  186. break;
  187. }
  188. }
  189. /*
  190. * i2c_probe: Use write access. Allows to identify addresses that are
  191. * write-only (like the config register of dual-port EEPROMs)
  192. */
  193. static int omap24_i2c_probe(struct i2c_adapter *adap, uchar chip)
  194. {
  195. struct i2c *i2c_base = omap24_get_base(adap);
  196. u16 status;
  197. int res = 1; /* default = fail */
  198. if (chip == readw(&i2c_base->oa))
  199. return res;
  200. /* Wait until bus is free */
  201. if (wait_for_bb(adap))
  202. return res;
  203. /* No data transfer, slave addr only */
  204. writew(chip, &i2c_base->sa);
  205. /* Stop bit needed here */
  206. writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_TRX |
  207. I2C_CON_STP, &i2c_base->con);
  208. status = wait_for_event(adap);
  209. if ((status & ~I2C_STAT_XRDY) == 0 || (status & I2C_STAT_AL)) {
  210. /*
  211. * With current high-level command implementation, notifying
  212. * the user shall flood the console with 127 messages. If
  213. * silent exit is desired upon unconfigured bus, remove the
  214. * following 'if' section:
  215. */
  216. if (status == I2C_STAT_XRDY)
  217. printf("i2c_probe: pads on bus %d probably not configured (status=0x%x)\n",
  218. adap->hwadapnr, status);
  219. goto pr_exit;
  220. }
  221. /* Check for ACK (!NAK) */
  222. if (!(status & I2C_STAT_NACK)) {
  223. res = 0; /* Device found */
  224. udelay(adap->waitdelay);/* Required by AM335X in SPL */
  225. /* Abort transfer (force idle state) */
  226. writew(I2C_CON_MST | I2C_CON_TRX, &i2c_base->con); /* Reset */
  227. udelay(1000);
  228. writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_TRX |
  229. I2C_CON_STP, &i2c_base->con); /* STP */
  230. }
  231. pr_exit:
  232. flush_fifo(adap);
  233. writew(0xFFFF, &i2c_base->stat);
  234. return res;
  235. }
  236. /*
  237. * i2c_read: Function now uses a single I2C read transaction with bulk transfer
  238. * of the requested number of bytes (note that the 'i2c md' command
  239. * limits this to 16 bytes anyway). If CONFIG_I2C_REPEATED_START is
  240. * defined in the board config header, this transaction shall be with
  241. * Repeated Start (Sr) between the address and data phases; otherwise
  242. * Stop-Start (P-S) shall be used (some I2C chips do require a P-S).
  243. * The address (reg offset) may be 0, 1 or 2 bytes long.
  244. * Function now reads correctly from chips that return more than one
  245. * byte of data per addressed register (like TI temperature sensors),
  246. * or that do not need a register address at all (such as some clock
  247. * distributors).
  248. */
  249. static int omap24_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr,
  250. int alen, uchar *buffer, int len)
  251. {
  252. struct i2c *i2c_base = omap24_get_base(adap);
  253. int i2c_error = 0;
  254. u16 status;
  255. if (alen < 0) {
  256. puts("I2C read: addr len < 0\n");
  257. return 1;
  258. }
  259. if (len < 0) {
  260. puts("I2C read: data len < 0\n");
  261. return 1;
  262. }
  263. if (buffer == NULL) {
  264. puts("I2C read: NULL pointer passed\n");
  265. return 1;
  266. }
  267. if (alen > 2) {
  268. printf("I2C read: addr len %d not supported\n", alen);
  269. return 1;
  270. }
  271. if (addr + len > (1 << 16)) {
  272. puts("I2C read: address out of range\n");
  273. return 1;
  274. }
  275. /* Wait until bus not busy */
  276. if (wait_for_bb(adap))
  277. return 1;
  278. /* Zero, one or two bytes reg address (offset) */
  279. writew(alen, &i2c_base->cnt);
  280. /* Set slave address */
  281. writew(chip, &i2c_base->sa);
  282. if (alen) {
  283. /* Must write reg offset first */
  284. #ifdef CONFIG_I2C_REPEATED_START
  285. /* No stop bit, use Repeated Start (Sr) */
  286. writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_STT |
  287. I2C_CON_TRX, &i2c_base->con);
  288. #else
  289. /* Stop - Start (P-S) */
  290. writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_STP |
  291. I2C_CON_TRX, &i2c_base->con);
  292. #endif
  293. /* Send register offset */
  294. while (1) {
  295. status = wait_for_event(adap);
  296. /* Try to identify bus that is not padconf'd for I2C */
  297. if (status == I2C_STAT_XRDY) {
  298. i2c_error = 2;
  299. printf("i2c_read (addr phase): pads on bus %d probably not configured (status=0x%x)\n",
  300. adap->hwadapnr, status);
  301. goto rd_exit;
  302. }
  303. if (status == 0 || (status & I2C_STAT_NACK)) {
  304. i2c_error = 1;
  305. printf("i2c_read: error waiting for addr ACK (status=0x%x)\n",
  306. status);
  307. goto rd_exit;
  308. }
  309. if (alen) {
  310. if (status & I2C_STAT_XRDY) {
  311. alen--;
  312. /* Do we have to use byte access? */
  313. writeb((addr >> (8 * alen)) & 0xff,
  314. &i2c_base->data);
  315. writew(I2C_STAT_XRDY, &i2c_base->stat);
  316. }
  317. }
  318. if (status & I2C_STAT_ARDY) {
  319. writew(I2C_STAT_ARDY, &i2c_base->stat);
  320. break;
  321. }
  322. }
  323. }
  324. /* Set slave address */
  325. writew(chip, &i2c_base->sa);
  326. /* Read len bytes from slave */
  327. writew(len, &i2c_base->cnt);
  328. /* Need stop bit here */
  329. writew(I2C_CON_EN | I2C_CON_MST |
  330. I2C_CON_STT | I2C_CON_STP,
  331. &i2c_base->con);
  332. /* Receive data */
  333. while (1) {
  334. status = wait_for_event(adap);
  335. /*
  336. * Try to identify bus that is not padconf'd for I2C. This
  337. * state could be left over from previous transactions if
  338. * the address phase is skipped due to alen=0.
  339. */
  340. if (status == I2C_STAT_XRDY) {
  341. i2c_error = 2;
  342. printf("i2c_read (data phase): pads on bus %d probably not configured (status=0x%x)\n",
  343. adap->hwadapnr, status);
  344. goto rd_exit;
  345. }
  346. if (status == 0 || (status & I2C_STAT_NACK)) {
  347. i2c_error = 1;
  348. goto rd_exit;
  349. }
  350. if (status & I2C_STAT_RRDY) {
  351. *buffer++ = readb(&i2c_base->data);
  352. writew(I2C_STAT_RRDY, &i2c_base->stat);
  353. }
  354. if (status & I2C_STAT_ARDY) {
  355. writew(I2C_STAT_ARDY, &i2c_base->stat);
  356. break;
  357. }
  358. }
  359. rd_exit:
  360. flush_fifo(adap);
  361. writew(0xFFFF, &i2c_base->stat);
  362. return i2c_error;
  363. }
  364. /* i2c_write: Address (reg offset) may be 0, 1 or 2 bytes long. */
  365. static int omap24_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr,
  366. int alen, uchar *buffer, int len)
  367. {
  368. struct i2c *i2c_base = omap24_get_base(adap);
  369. int i;
  370. u16 status;
  371. int i2c_error = 0;
  372. int timeout = I2C_TIMEOUT;
  373. if (alen < 0) {
  374. puts("I2C write: addr len < 0\n");
  375. return 1;
  376. }
  377. if (len < 0) {
  378. puts("I2C write: data len < 0\n");
  379. return 1;
  380. }
  381. if (buffer == NULL) {
  382. puts("I2C write: NULL pointer passed\n");
  383. return 1;
  384. }
  385. if (alen > 2) {
  386. printf("I2C write: addr len %d not supported\n", alen);
  387. return 1;
  388. }
  389. if (addr + len > (1 << 16)) {
  390. printf("I2C write: address 0x%x + 0x%x out of range\n",
  391. addr, len);
  392. return 1;
  393. }
  394. /* Wait until bus not busy */
  395. if (wait_for_bb(adap))
  396. return 1;
  397. /* Start address phase - will write regoffset + len bytes data */
  398. writew(alen + len, &i2c_base->cnt);
  399. /* Set slave address */
  400. writew(chip, &i2c_base->sa);
  401. /* Stop bit needed here */
  402. writew(I2C_CON_EN | I2C_CON_MST | I2C_CON_STT | I2C_CON_TRX |
  403. I2C_CON_STP, &i2c_base->con);
  404. while (alen) {
  405. /* Must write reg offset (one or two bytes) */
  406. status = wait_for_event(adap);
  407. /* Try to identify bus that is not padconf'd for I2C */
  408. if (status == I2C_STAT_XRDY) {
  409. i2c_error = 2;
  410. printf("i2c_write: pads on bus %d probably not configured (status=0x%x)\n",
  411. adap->hwadapnr, status);
  412. goto wr_exit;
  413. }
  414. if (status == 0 || (status & I2C_STAT_NACK)) {
  415. i2c_error = 1;
  416. printf("i2c_write: error waiting for addr ACK (status=0x%x)\n",
  417. status);
  418. goto wr_exit;
  419. }
  420. if (status & I2C_STAT_XRDY) {
  421. alen--;
  422. writeb((addr >> (8 * alen)) & 0xff, &i2c_base->data);
  423. writew(I2C_STAT_XRDY, &i2c_base->stat);
  424. } else {
  425. i2c_error = 1;
  426. printf("i2c_write: bus not ready for addr Tx (status=0x%x)\n",
  427. status);
  428. goto wr_exit;
  429. }
  430. }
  431. /* Address phase is over, now write data */
  432. for (i = 0; i < len; i++) {
  433. status = wait_for_event(adap);
  434. if (status == 0 || (status & I2C_STAT_NACK)) {
  435. i2c_error = 1;
  436. printf("i2c_write: error waiting for data ACK (status=0x%x)\n",
  437. status);
  438. goto wr_exit;
  439. }
  440. if (status & I2C_STAT_XRDY) {
  441. writeb(buffer[i], &i2c_base->data);
  442. writew(I2C_STAT_XRDY, &i2c_base->stat);
  443. } else {
  444. i2c_error = 1;
  445. printf("i2c_write: bus not ready for data Tx (i=%d)\n",
  446. i);
  447. goto wr_exit;
  448. }
  449. }
  450. /*
  451. * poll ARDY bit for making sure that last byte really has been
  452. * transferred on the bus.
  453. */
  454. do {
  455. status = wait_for_event(adap);
  456. } while (!(status & I2C_STAT_ARDY) && timeout--);
  457. if (timeout <= 0)
  458. printf("i2c_write: timed out writig last byte!\n");
  459. wr_exit:
  460. flush_fifo(adap);
  461. writew(0xFFFF, &i2c_base->stat);
  462. return i2c_error;
  463. }
  464. /*
  465. * Wait for the bus to be free by checking the Bus Busy (BB)
  466. * bit to become clear
  467. */
  468. static int wait_for_bb(struct i2c_adapter *adap)
  469. {
  470. struct i2c *i2c_base = omap24_get_base(adap);
  471. int timeout = I2C_TIMEOUT;
  472. u16 stat;
  473. writew(0xFFFF, &i2c_base->stat); /* clear current interrupts...*/
  474. #if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX)
  475. while ((stat = readw(&i2c_base->stat) & I2C_STAT_BB) && timeout--) {
  476. #else
  477. /* Read RAW status */
  478. while ((stat = readw(&i2c_base->irqstatus_raw) &
  479. I2C_STAT_BB) && timeout--) {
  480. #endif
  481. writew(stat, &i2c_base->stat);
  482. udelay(adap->waitdelay);
  483. }
  484. if (timeout <= 0) {
  485. printf("Timed out in wait_for_bb: status=%04x\n",
  486. stat);
  487. return 1;
  488. }
  489. writew(0xFFFF, &i2c_base->stat); /* clear delayed stuff*/
  490. return 0;
  491. }
  492. /*
  493. * Wait for the I2C controller to complete current action
  494. * and update status
  495. */
  496. static u16 wait_for_event(struct i2c_adapter *adap)
  497. {
  498. struct i2c *i2c_base = omap24_get_base(adap);
  499. u16 status;
  500. int timeout = I2C_TIMEOUT;
  501. do {
  502. udelay(adap->waitdelay);
  503. #if defined(CONFIG_OMAP243X) || defined(CONFIG_OMAP34XX)
  504. status = readw(&i2c_base->stat);
  505. #else
  506. /* Read RAW status */
  507. status = readw(&i2c_base->irqstatus_raw);
  508. #endif
  509. } while (!(status &
  510. (I2C_STAT_ROVR | I2C_STAT_XUDF | I2C_STAT_XRDY |
  511. I2C_STAT_RRDY | I2C_STAT_ARDY | I2C_STAT_NACK |
  512. I2C_STAT_AL)) && timeout--);
  513. if (timeout <= 0) {
  514. printf("Timed out in wait_for_event: status=%04x\n",
  515. status);
  516. /*
  517. * If status is still 0 here, probably the bus pads have
  518. * not been configured for I2C, and/or pull-ups are missing.
  519. */
  520. printf("Check if pads/pull-ups of bus %d are properly configured\n",
  521. adap->hwadapnr);
  522. writew(0xFFFF, &i2c_base->stat);
  523. status = 0;
  524. }
  525. return status;
  526. }
  527. static struct i2c *omap24_get_base(struct i2c_adapter *adap)
  528. {
  529. switch (adap->hwadapnr) {
  530. case 0:
  531. return (struct i2c *)I2C_BASE1;
  532. break;
  533. case 1:
  534. return (struct i2c *)I2C_BASE2;
  535. break;
  536. #if (I2C_BUS_MAX > 2)
  537. case 2:
  538. return (struct i2c *)I2C_BASE3;
  539. break;
  540. #if (I2C_BUS_MAX > 3)
  541. case 3:
  542. return (struct i2c *)I2C_BASE4;
  543. break;
  544. #if (I2C_BUS_MAX > 4)
  545. case 4:
  546. return (struct i2c *)I2C_BASE5;
  547. break;
  548. #endif
  549. #endif
  550. #endif
  551. default:
  552. printf("wrong hwadapnr: %d\n", adap->hwadapnr);
  553. break;
  554. }
  555. return NULL;
  556. }
  557. #if !defined(CONFIG_SYS_OMAP24_I2C_SPEED1)
  558. #define CONFIG_SYS_OMAP24_I2C_SPEED1 CONFIG_SYS_OMAP24_I2C_SPEED
  559. #endif
  560. #if !defined(CONFIG_SYS_OMAP24_I2C_SLAVE1)
  561. #define CONFIG_SYS_OMAP24_I2C_SLAVE1 CONFIG_SYS_OMAP24_I2C_SLAVE
  562. #endif
  563. U_BOOT_I2C_ADAP_COMPLETE(omap24_0, omap24_i2c_init, omap24_i2c_probe,
  564. omap24_i2c_read, omap24_i2c_write, omap24_i2c_setspeed,
  565. CONFIG_SYS_OMAP24_I2C_SPEED,
  566. CONFIG_SYS_OMAP24_I2C_SLAVE,
  567. 0)
  568. U_BOOT_I2C_ADAP_COMPLETE(omap24_1, omap24_i2c_init, omap24_i2c_probe,
  569. omap24_i2c_read, omap24_i2c_write, omap24_i2c_setspeed,
  570. CONFIG_SYS_OMAP24_I2C_SPEED1,
  571. CONFIG_SYS_OMAP24_I2C_SLAVE1,
  572. 1)
  573. #if (I2C_BUS_MAX > 2)
  574. #if !defined(CONFIG_SYS_OMAP24_I2C_SPEED2)
  575. #define CONFIG_SYS_OMAP24_I2C_SPEED2 CONFIG_SYS_OMAP24_I2C_SPEED
  576. #endif
  577. #if !defined(CONFIG_SYS_OMAP24_I2C_SLAVE2)
  578. #define CONFIG_SYS_OMAP24_I2C_SLAVE2 CONFIG_SYS_OMAP24_I2C_SLAVE
  579. #endif
  580. U_BOOT_I2C_ADAP_COMPLETE(omap24_2, omap24_i2c_init, omap24_i2c_probe,
  581. omap24_i2c_read, omap24_i2c_write, NULL,
  582. CONFIG_SYS_OMAP24_I2C_SPEED2,
  583. CONFIG_SYS_OMAP24_I2C_SLAVE2,
  584. 2)
  585. #if (I2C_BUS_MAX > 3)
  586. #if !defined(CONFIG_SYS_OMAP24_I2C_SPEED3)
  587. #define CONFIG_SYS_OMAP24_I2C_SPEED3 CONFIG_SYS_OMAP24_I2C_SPEED
  588. #endif
  589. #if !defined(CONFIG_SYS_OMAP24_I2C_SLAVE3)
  590. #define CONFIG_SYS_OMAP24_I2C_SLAVE3 CONFIG_SYS_OMAP24_I2C_SLAVE
  591. #endif
  592. U_BOOT_I2C_ADAP_COMPLETE(omap24_3, omap24_i2c_init, omap24_i2c_probe,
  593. omap24_i2c_read, omap24_i2c_write, NULL,
  594. CONFIG_SYS_OMAP24_I2C_SPEED3,
  595. CONFIG_SYS_OMAP24_I2C_SLAVE3,
  596. 3)
  597. #if (I2C_BUS_MAX > 4)
  598. #if !defined(CONFIG_SYS_OMAP24_I2C_SPEED4)
  599. #define CONFIG_SYS_OMAP24_I2C_SPEED4 CONFIG_SYS_OMAP24_I2C_SPEED
  600. #endif
  601. #if !defined(CONFIG_SYS_OMAP24_I2C_SLAVE4)
  602. #define CONFIG_SYS_OMAP24_I2C_SLAVE4 CONFIG_SYS_OMAP24_I2C_SLAVE
  603. #endif
  604. U_BOOT_I2C_ADAP_COMPLETE(omap24_4, omap24_i2c_init, omap24_i2c_probe,
  605. omap24_i2c_read, omap24_i2c_write, NULL,
  606. CONFIG_SYS_OMAP24_I2C_SPEED4,
  607. CONFIG_SYS_OMAP24_I2C_SLAVE4,
  608. 4)
  609. #endif
  610. #endif
  611. #endif