u8500_i2c.c 15 KB

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