u8500_i2c.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010
  3. *
  4. * Basic U-Boot I2C interface for STn8500/DB8500
  5. * Author: Michael Brandt <Michael.Brandt@stericsson.com> for ST-Ericsson
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. /*
  22. * Only 7-bit I2C device addresses are supported.
  23. */
  24. #include <common.h>
  25. #include <i2c.h>
  26. #include "u8500_i2c.h"
  27. #include <asm/io.h>
  28. #include <asm/arch/clock.h>
  29. #define U8500_I2C_ENDAD_COUNTER (CONFIG_SYS_HZ/100) /* I2C bus timeout */
  30. #define U8500_I2C_FIFO_FLUSH_COUNTER 500000 /* flush "timeout" */
  31. #define U8500_I2C_SCL_FREQ 100000 /* I2C bus clock freq */
  32. #define U8500_I2C_INPUT_FREQ 48000000 /* Input clock freq */
  33. #define TX_FIFO_THRESHOLD 0x4
  34. #define RX_FIFO_THRESHOLD 0x4
  35. #define SLAVE_SETUP_TIME 14 /* Slave data setup time, 250ns for 48MHz i2c_clk */
  36. #define WRITE_FIELD(var, mask, shift, value) \
  37. (var = ((var & ~(mask)) | ((value) << (shift))))
  38. static unsigned int bus_initialized[CONFIG_SYS_U8500_I2C_BUS_MAX];
  39. static unsigned int i2c_bus_num;
  40. static unsigned int i2c_bus_speed[] = {
  41. CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SPEED,
  42. CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SPEED
  43. };
  44. static struct u8500_i2c_regs *i2c_dev[] = {
  45. (struct u8500_i2c_regs *)CONFIG_SYS_U8500_I2C0_BASE,
  46. (struct u8500_i2c_regs *)CONFIG_SYS_U8500_I2C1_BASE,
  47. (struct u8500_i2c_regs *)CONFIG_SYS_U8500_I2C2_BASE,
  48. (struct u8500_i2c_regs *)CONFIG_SYS_U8500_I2C3_BASE,
  49. };
  50. static struct {
  51. int periph;
  52. int pcken;
  53. int kcken;
  54. } i2c_clock_bits[] = {
  55. {3, 3, 3}, /* I2C0 */
  56. {1, 2, 2}, /* I2C1 */
  57. {1, 6, 6}, /* I2C2 */
  58. {2, 0, 0}, /* I2C3 */
  59. };
  60. static void i2c_set_bit(void *reg, u32 mask)
  61. {
  62. writel(readl(reg) | mask, reg);
  63. }
  64. static void i2c_clr_bit(void *reg, u32 mask)
  65. {
  66. writel(readl(reg) & ~mask, reg);
  67. }
  68. static void i2c_write_field(void *reg, u32 mask, uint shift, u32 value)
  69. {
  70. writel((readl(reg) & ~mask) | (value << shift), reg);
  71. }
  72. static int __i2c_set_bus_speed(unsigned int speed)
  73. {
  74. u32 value;
  75. struct u8500_i2c_regs *i2c_regs;
  76. i2c_regs = i2c_dev[i2c_bus_num];
  77. /* Select standard (100 kbps) speed mode */
  78. i2c_write_field(&i2c_regs->cr, U8500_I2C_CR_SM,
  79. U8500_I2C_CR_SHIFT_SM, 0x0);
  80. /*
  81. * Set the Baud Rate Counter 2 value
  82. * Baud rate (standard) = fi2cclk / ( (BRCNT2 x 2) + Foncycle )
  83. * Foncycle = 0 (no digital filtering)
  84. */
  85. value = (u32) (U8500_I2C_INPUT_FREQ / (speed * 2));
  86. i2c_write_field(&i2c_regs->brcr, U8500_I2C_BRCR_BRCNT2,
  87. U8500_I2C_BRCR_SHIFT_BRCNT2, value);
  88. /* ensure that BRCNT value is zero */
  89. i2c_write_field(&i2c_regs->brcr, U8500_I2C_BRCR_BRCNT1,
  90. U8500_I2C_BRCR_SHIFT_BRCNT1, 0);
  91. return U8500_I2C_INPUT_FREQ/(value * 2);
  92. }
  93. /*
  94. * i2c_init - initialize the i2c bus
  95. *
  96. * speed: bus speed (in HZ)
  97. * slaveaddr: address of device in slave mode
  98. *
  99. * Slave mode is not implemented.
  100. */
  101. void i2c_init(int speed, int slaveaddr)
  102. {
  103. struct u8500_i2c_regs *i2c_regs;
  104. debug("i2c_init bus %d, speed %d\n", i2c_bus_num, speed);
  105. u8500_clock_enable(i2c_clock_bits[i2c_bus_num].periph,
  106. i2c_clock_bits[i2c_bus_num].pcken,
  107. i2c_clock_bits[i2c_bus_num].kcken);
  108. i2c_regs = i2c_dev[i2c_bus_num];
  109. /* Disable the controller */
  110. i2c_clr_bit(&i2c_regs->cr, U8500_I2C_CR_PE);
  111. /* Clear registers */
  112. writel(0, &i2c_regs->cr);
  113. writel(0, &i2c_regs->scr);
  114. writel(0, &i2c_regs->hsmcr);
  115. writel(0, &i2c_regs->tftr);
  116. writel(0, &i2c_regs->rftr);
  117. writel(0, &i2c_regs->dmar);
  118. i2c_bus_speed[i2c_bus_num] = __i2c_set_bus_speed(speed);
  119. /*
  120. * Set our own address.
  121. * Set slave address mode to 7 bit addressing mode
  122. */
  123. i2c_clr_bit(&i2c_regs->cr, U8500_I2C_CR_SAM);
  124. i2c_write_field(&i2c_regs->scr, U8500_I2C_SCR_ADDR,
  125. U8500_I2C_SCR_SHIFT_ADDR, slaveaddr);
  126. /* Slave Data Set up Time */
  127. i2c_write_field(&i2c_regs->scr, U8500_I2C_SCR_DATA_SETUP_TIME,
  128. U8500_I2C_SCR_SHIFT_DATA_SETUP_TIME, SLAVE_SETUP_TIME);
  129. /* Disable the DMA sync logic */
  130. i2c_write_field(&i2c_regs->cr, U8500_I2C_CR_DMA_SLE,
  131. U8500_I2C_CR_SHIFT_DMA_SLE, 0);
  132. /* Disable interrupts */
  133. writel(0, &i2c_regs->imscr);
  134. /* Configure bus master mode */
  135. i2c_write_field(&i2c_regs->cr, U8500_I2C_CR_OM, U8500_I2C_CR_SHIFT_OM,
  136. U8500_I2C_BUS_MASTER_MODE);
  137. /* Set FIFO threshold values */
  138. writel(TX_FIFO_THRESHOLD, &i2c_regs->tftr);
  139. writel(RX_FIFO_THRESHOLD, &i2c_regs->rftr);
  140. /* Enable the I2C Controller */
  141. i2c_set_bit(&i2c_regs->cr, U8500_I2C_CR_PE);
  142. bus_initialized[i2c_bus_num] = 1;
  143. }
  144. /*
  145. * loop_till_bit_clear - polls on a bit till it clears
  146. * ioreg: register where you want to check status
  147. * mask: bit mask for the bit you wish to check
  148. * timeout: timeout in ticks/s
  149. */
  150. static int loop_till_bit_clear(void *io_reg, u32 mask, unsigned long timeout)
  151. {
  152. unsigned long timebase = get_timer(0);
  153. do {
  154. if ((readl(io_reg) & mask) == 0x0UL)
  155. return 0;
  156. } while (get_timer(timebase) < timeout);
  157. debug("loop_till_bit_clear timed out\n");
  158. return -1;
  159. }
  160. /*
  161. * loop_till_bit_set - polls on a bit till it is set.
  162. * ioreg: register where you want to check status
  163. * mask: bit mask for the bit you wish to check
  164. * timeout: timeout in ticks/s
  165. */
  166. static int loop_till_bit_set(void *io_reg, u32 mask, unsigned long timeout)
  167. {
  168. unsigned long timebase = get_timer(0);
  169. do {
  170. if ((readl(io_reg) & mask) != 0x0UL)
  171. return 0;
  172. } while (get_timer(timebase) < timeout);
  173. debug("loop_till_bit_set timed out\n");
  174. return -1;
  175. }
  176. /*
  177. * flush_fifo - flush the I2C TX and RX FIFOs
  178. */
  179. static void flush_fifo(struct u8500_i2c_regs *i2c_regs)
  180. {
  181. int counter = U8500_I2C_FIFO_FLUSH_COUNTER;
  182. /* Flush Tx FIFO */
  183. i2c_set_bit(&i2c_regs->cr, U8500_I2C_CR_FTX);
  184. /* Flush Rx FIFO */
  185. i2c_set_bit(&i2c_regs->cr, U8500_I2C_CR_FRX);
  186. while (counter--) {
  187. if (!(readl(&i2c_regs->cr) &
  188. (U8500_I2C_CR_FTX | U8500_I2C_CR_FRX)))
  189. break;
  190. }
  191. return;
  192. }
  193. #ifdef DEBUG
  194. static void print_abort_reason(struct u8500_i2c_regs *i2c_regs)
  195. {
  196. int cause;
  197. printf("abort: risr %08x, sr %08x\n", i2c_regs->risr, i2c_regs->sr);
  198. cause = (readl(&i2c_regs->sr) & U8500_I2C_SR_CAUSE) >>
  199. U8500_I2C_SR_SHIFT_CAUSE;
  200. switch (cause) {
  201. case U8500_I2C_NACK_ADDR:
  202. printf("No Ack received after Slave Address xmission\n");
  203. break;
  204. case U8500_I2C_NACK_DATA:
  205. printf("Valid for MASTER_WRITE: No Ack received "
  206. "during data phase\n");
  207. break;
  208. case U8500_I2C_ACK_MCODE:
  209. printf("Master recv ack after xmission of master code"
  210. "in hs mode\n");
  211. break;
  212. case U8500_I2C_ARB_LOST:
  213. printf("Master Lost arbitration\n");
  214. break;
  215. case U8500_I2C_BERR_START:
  216. printf("Slave restarts\n");
  217. break;
  218. case U8500_I2C_BERR_STOP:
  219. printf("Slave reset\n");
  220. break;
  221. case U8500_I2C_OVFL:
  222. printf("Overflow\n");
  223. break;
  224. default:
  225. printf("Unknown error type\n");
  226. }
  227. }
  228. #endif
  229. /*
  230. * i2c_abort - called when a I2C transaction failed
  231. */
  232. static void i2c_abort(struct u8500_i2c_regs *i2c_regs)
  233. {
  234. #ifdef DEBUG
  235. print_abort_reason(i2c_regs);
  236. #endif
  237. /* flush RX and TX fifos */
  238. flush_fifo(i2c_regs);
  239. /* Acknowledge the Master Transaction Done */
  240. i2c_set_bit(&i2c_regs->icr, U8500_I2C_INT_MTD);
  241. /* Acknowledge the Master Transaction Done Without Stop */
  242. i2c_set_bit(&i2c_regs->icr, U8500_I2C_INT_MTDWS);
  243. i2c_init(i2c_bus_speed[i2c_bus_num], CONFIG_SYS_I2C_SLAVE);
  244. }
  245. /*
  246. * write addr, alias index, to I2C bus.
  247. */
  248. static int i2c_write_addr(struct u8500_i2c_regs *i2c_regs, uint addr, int alen)
  249. {
  250. while (alen--) {
  251. /* Wait until the Tx Fifo is not full */
  252. if (loop_till_bit_clear((void *)&i2c_regs->risr,
  253. U8500_I2C_INT_TXFF,
  254. U8500_I2C_ENDAD_COUNTER)) {
  255. i2c_abort(i2c_regs);
  256. return -1;
  257. }
  258. /* MSB first */
  259. writeb((addr >> (alen * 8)) & 0xff, &i2c_regs->tfr);
  260. }
  261. return 0;
  262. }
  263. /*
  264. * Internal simplified read function:
  265. * i2c_regs: Pointer to I2C registers for current bus
  266. * chip: I2C chip address, range 0..127
  267. * addr: Memory (register) address within the chip
  268. * alen: Number of bytes to use for addr (typically 1, 2 for larger
  269. * memories, 0 for register type devices with only one register)
  270. * value: Where to put the data
  271. *
  272. * Returns: 0 on success, not 0 on failure
  273. */
  274. static int i2c_read_byte(struct u8500_i2c_regs *i2c_regs, uchar chip,
  275. uint addr, int alen, uchar *value)
  276. {
  277. u32 mcr = 0;
  278. /* Set the address mode to 7 bit */
  279. WRITE_FIELD(mcr, U8500_I2C_MCR_AM, U8500_I2C_MCR_SHIFT_AM, 1);
  280. /* Store the slave address in the master control register */
  281. WRITE_FIELD(mcr, U8500_I2C_MCR_A7, U8500_I2C_MCR_SHIFT_A7, chip);
  282. if (alen != 0) {
  283. /* Master write operation */
  284. mcr &= ~(U8500_I2C_MCR_OP);
  285. /* Configure the Frame length to one byte */
  286. WRITE_FIELD(mcr, U8500_I2C_MCR_LENGTH,
  287. U8500_I2C_MCR_SHIFT_LENGTH, 1);
  288. /* Repeated start, no stop */
  289. mcr &= ~(U8500_I2C_MCR_STOP);
  290. /* Write Master Control Register */
  291. writel(mcr, &i2c_regs->mcr);
  292. /* send addr/index */
  293. if (i2c_write_addr(i2c_regs, addr, alen) != 0)
  294. return -1;
  295. /* Check for the Master Transaction Done Without Stop */
  296. if (loop_till_bit_set((void *)&i2c_regs->risr,
  297. U8500_I2C_INT_MTDWS,
  298. U8500_I2C_ENDAD_COUNTER)) {
  299. return -1;
  300. }
  301. /* Acknowledge the Master Transaction Done Without Stop */
  302. i2c_set_bit(&i2c_regs->icr, U8500_I2C_INT_MTDWS);
  303. }
  304. /* Master control configuration for read operation */
  305. mcr |= U8500_I2C_MCR_OP;
  306. /* Configure the STOP condition, we read only one byte */
  307. mcr |= U8500_I2C_MCR_STOP;
  308. /* Set the frame length to one byte, we support only 1 byte reads */
  309. WRITE_FIELD(mcr, U8500_I2C_MCR_LENGTH, U8500_I2C_MCR_SHIFT_LENGTH, 1);
  310. i2c_write_field(&i2c_regs->mcr, U8500_I2C_MCR_LENGTH_STOP_OP,
  311. U8500_I2C_MCR_SHIFT_LENGTH_STOP_OP, mcr);
  312. /*
  313. * receive_data_polling
  314. */
  315. /* Wait until the Rx FIFO is not empty */
  316. if (loop_till_bit_clear((void *)&i2c_regs->risr,
  317. U8500_I2C_INT_RXFE,
  318. U8500_I2C_ENDAD_COUNTER))
  319. return -1;
  320. /* Read the data byte from Rx FIFO */
  321. *value = readb(&i2c_regs->rfr);
  322. /* Wait until the work is done */
  323. if (loop_till_bit_set((void *)&i2c_regs->risr, U8500_I2C_INT_MTD,
  324. U8500_I2C_ENDAD_COUNTER))
  325. return -1;
  326. /* Acknowledge the Master Transaction Done */
  327. i2c_set_bit(&i2c_regs->icr, U8500_I2C_INT_MTD);
  328. /* If MTD is set, Master Transaction Done Without Stop is set too */
  329. i2c_set_bit(&i2c_regs->icr, U8500_I2C_INT_MTDWS);
  330. return 0;
  331. }
  332. /*
  333. * Internal simplified write function:
  334. * i2c_regs: Pointer to I2C registers for current bus
  335. * chip: I2C chip address, range 0..127
  336. * addr: Memory (register) address within the chip
  337. * alen: Number of bytes to use for addr (typically 1, 2 for larger
  338. * memories, 0 for register type devices with only one register)
  339. * data: Where to read the data
  340. * len: How many bytes to write
  341. *
  342. * Returns: 0 on success, not 0 on failure
  343. */
  344. static int __i2c_write(struct u8500_i2c_regs *i2c_regs, u8 chip, uint addr,
  345. int alen, u8 *data, int len)
  346. {
  347. int i;
  348. u32 mcr = 0;
  349. /* Set the address mode to 7 bit */
  350. WRITE_FIELD(mcr, U8500_I2C_MCR_AM, U8500_I2C_MCR_SHIFT_AM, 1);
  351. /* Store the slave address in the master control register */
  352. WRITE_FIELD(mcr, U8500_I2C_MCR_A7, U8500_I2C_MCR_SHIFT_A7, chip);
  353. /* Write operation */
  354. mcr &= ~(U8500_I2C_MCR_OP);
  355. /* Current transaction is terminated by STOP condition */
  356. mcr |= U8500_I2C_MCR_STOP;
  357. /* Frame length: addr byte + len */
  358. WRITE_FIELD(mcr, U8500_I2C_MCR_LENGTH, U8500_I2C_MCR_SHIFT_LENGTH,
  359. (alen + len));
  360. /* Write MCR register */
  361. writel(mcr, &i2c_regs->mcr);
  362. if (i2c_write_addr(i2c_regs, addr, alen) != 0)
  363. return -1;
  364. for (i = 0; i < len; i++) {
  365. /* Wait until the Tx FIFO is not full */
  366. if (loop_till_bit_clear((void *)&i2c_regs->risr,
  367. U8500_I2C_INT_TXFF,
  368. U8500_I2C_ENDAD_COUNTER))
  369. return -1;
  370. /* it is a 32 bit register with upper 24 reserved R/O */
  371. writeb(data[i], &i2c_regs->tfr);
  372. }
  373. /* Check for Master Transaction Done */
  374. if (loop_till_bit_set((void *)&i2c_regs->risr,
  375. U8500_I2C_INT_MTD,
  376. U8500_I2C_ENDAD_COUNTER)) {
  377. printf("i2c_write_byte error2: risr %08x\n",
  378. i2c_regs->risr);
  379. return -1;
  380. }
  381. /* Acknowledge Master Transaction Done */
  382. i2c_set_bit(&i2c_regs->icr, U8500_I2C_INT_MTD);
  383. /* Acknowledge Master Transaction Done Without Stop */
  384. i2c_set_bit(&i2c_regs->icr, U8500_I2C_INT_MTDWS);
  385. return 0;
  386. }
  387. /*
  388. * Probe the given I2C chip address. Returns 0 if a chip responded,
  389. * not 0 on failure.
  390. */
  391. int i2c_probe(uchar chip)
  392. {
  393. u32 mcr = 0;
  394. struct u8500_i2c_regs *i2c_regs;
  395. if (chip == CONFIG_SYS_I2C_SLAVE)
  396. return 1;
  397. i2c_regs = i2c_dev[i2c_bus_num];
  398. /* Set the address mode to 7 bit */
  399. WRITE_FIELD(mcr, U8500_I2C_MCR_AM, U8500_I2C_MCR_SHIFT_AM, 1);
  400. /* Store the slave address in the master control register */
  401. WRITE_FIELD(mcr, U8500_I2C_MCR_A10, U8500_I2C_MCR_SHIFT_A7, chip);
  402. /* Read operation */
  403. mcr |= U8500_I2C_MCR_OP;
  404. /* Set the frame length to one byte */
  405. WRITE_FIELD(mcr, U8500_I2C_MCR_LENGTH, U8500_I2C_MCR_SHIFT_LENGTH, 1);
  406. /* Current transaction is terminated by STOP condition */
  407. mcr |= U8500_I2C_MCR_STOP;
  408. /* Write MCR register */
  409. writel(mcr, &i2c_regs->mcr);
  410. /* Wait until the Rx Fifo is not empty */
  411. if (loop_till_bit_clear((void *)&i2c_regs->risr,
  412. U8500_I2C_INT_RXFE,
  413. U8500_I2C_ENDAD_COUNTER)) {
  414. i2c_abort(i2c_regs);
  415. return -1;
  416. }
  417. flush_fifo(i2c_regs);
  418. /* Acknowledge the Master Transaction Done */
  419. i2c_set_bit(&i2c_regs->icr, U8500_I2C_INT_MTD);
  420. /* Acknowledge the Master Transaction Done Without Stop */
  421. i2c_set_bit(&i2c_regs->icr, U8500_I2C_INT_MTDWS);
  422. return 0;
  423. }
  424. /*
  425. * Read/Write interface:
  426. * chip: I2C chip address, range 0..127
  427. * addr: Memory (register) address within the chip
  428. * alen: Number of bytes to use for addr (typically 1, 2 for larger
  429. * memories, 0 for register type devices with only one
  430. * register)
  431. * buffer: Where to read/write the data
  432. * len: How many bytes to read/write
  433. *
  434. * Returns: 0 on success, not 0 on failure
  435. */
  436. int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
  437. {
  438. int i;
  439. int rc;
  440. struct u8500_i2c_regs *i2c_regs;
  441. if (alen > 2) {
  442. debug("I2C read: addr len %d not supported\n", alen);
  443. return 1;
  444. }
  445. i2c_regs = i2c_dev[i2c_bus_num];
  446. for (i = 0; i < len; i++) {
  447. rc = i2c_read_byte(i2c_regs, chip, addr + i, alen, &buffer[i]);
  448. if (rc != 0) {
  449. debug("I2C read: I/O error: %d\n", rc);
  450. i2c_abort(i2c_regs);
  451. return rc;
  452. }
  453. }
  454. return 0;
  455. }
  456. int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
  457. {
  458. int rc;
  459. struct u8500_i2c_regs *i2c_regs;
  460. i2c_regs = i2c_dev[i2c_bus_num];
  461. rc = __i2c_write(i2c_regs, chip, addr, alen, buffer,
  462. len);
  463. if (rc != 0) {
  464. debug("I2C write: I/O error\n");
  465. i2c_abort(i2c_regs);
  466. return rc;
  467. }
  468. return 0;
  469. }
  470. int i2c_set_bus_num(unsigned int bus)
  471. {
  472. if (bus > ARRAY_SIZE(i2c_dev) - 1) {
  473. debug("i2c_set_bus_num: only up to bus %d supported\n",
  474. ARRAY_SIZE(i2c_dev)-1);
  475. return -1;
  476. }
  477. i2c_bus_num = bus;
  478. if (!bus_initialized[i2c_bus_num])
  479. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  480. return 0;
  481. }
  482. int i2c_set_bus_speed(unsigned int speed)
  483. {
  484. if (speed > U8500_I2C_MAX_STANDARD_SCL) {
  485. debug("i2c_set_bus_speed: only up to %d supported\n",
  486. U8500_I2C_MAX_STANDARD_SCL);
  487. return -1;
  488. }
  489. /* sets as side effect i2c_bus_speed[i2c_bus_num] */
  490. i2c_init(speed, CONFIG_SYS_I2C_SLAVE);
  491. return 0;
  492. }
  493. unsigned int i2c_get_bus_num(void)
  494. {
  495. return i2c_bus_num;
  496. }
  497. unsigned int i2c_get_bus_speed(void)
  498. {
  499. return i2c_bus_speed[i2c_bus_num];
  500. }