2 * i2c driver for Freescale i.MX series
4 * (c) 2007 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de>
5 * (c) 2011 Marek Vasut <marek.vasut@gmail.com>
7 * Based on i2c-imx.c from linux kernel:
8 * Copyright (C) 2005 Torsten Koschorrek <koschorrek at synertronixx.de>
9 * Copyright (C) 2005 Matthias Blaschke <blaschke at synertronixx.de>
10 * Copyright (C) 2007 RightHand Technologies, Inc.
11 * Copyright (C) 2008 Darius Augulis <darius.augulis at teltonika.lt>
14 * SPDX-License-Identifier: GPL-2.0+
18 #include <asm/arch/clock.h>
19 #include <asm/arch/imx-regs.h>
20 #include <asm/errno.h>
21 #include <asm/imx-common/mxc_i2c.h>
28 DECLARE_GLOBAL_DATA_PTR;
30 #define I2C_QUIRK_FLAG (1 << 0)
32 #define IMX_I2C_REGSHIFT 2
33 #define VF610_I2C_REGSHIFT 0
41 #define I2CR_IIEN (1 << 6)
42 #define I2CR_MSTA (1 << 5)
43 #define I2CR_MTX (1 << 4)
44 #define I2CR_TX_NO_AK (1 << 3)
45 #define I2CR_RSTA (1 << 2)
47 #define I2SR_ICF (1 << 7)
48 #define I2SR_IBB (1 << 5)
49 #define I2SR_IAL (1 << 4)
50 #define I2SR_IIF (1 << 1)
51 #define I2SR_RX_NO_AK (1 << 0)
54 #define I2CR_IEN (0 << 7)
55 #define I2CR_IDIS (1 << 7)
56 #define I2SR_IIF_CLEAR (1 << 1)
58 #define I2CR_IEN (1 << 7)
59 #define I2CR_IDIS (0 << 7)
60 #define I2SR_IIF_CLEAR (0 << 1)
63 #if defined(CONFIG_HARD_I2C) && !defined(CONFIG_SYS_I2C_BASE)
64 #error "define CONFIG_SYS_I2C_BASE to use the mxc_i2c driver"
68 static u16 i2c_clk_div[60][2] = {
69 { 20, 0x00 }, { 22, 0x01 }, { 24, 0x02 }, { 26, 0x03 },
70 { 28, 0x04 }, { 30, 0x05 }, { 32, 0x09 }, { 34, 0x06 },
71 { 36, 0x0A }, { 40, 0x07 }, { 44, 0x0C }, { 48, 0x0D },
72 { 52, 0x43 }, { 56, 0x0E }, { 60, 0x45 }, { 64, 0x12 },
73 { 68, 0x0F }, { 72, 0x13 }, { 80, 0x14 }, { 88, 0x15 },
74 { 96, 0x19 }, { 104, 0x16 }, { 112, 0x1A }, { 128, 0x17 },
75 { 136, 0x4F }, { 144, 0x1C }, { 160, 0x1D }, { 176, 0x55 },
76 { 192, 0x1E }, { 208, 0x56 }, { 224, 0x22 }, { 228, 0x24 },
77 { 240, 0x1F }, { 256, 0x23 }, { 288, 0x5C }, { 320, 0x25 },
78 { 384, 0x26 }, { 448, 0x2A }, { 480, 0x27 }, { 512, 0x2B },
79 { 576, 0x2C }, { 640, 0x2D }, { 768, 0x31 }, { 896, 0x32 },
80 { 960, 0x2F }, { 1024, 0x33 }, { 1152, 0x34 }, { 1280, 0x35 },
81 { 1536, 0x36 }, { 1792, 0x3A }, { 1920, 0x37 }, { 2048, 0x3B },
82 { 2304, 0x3C }, { 2560, 0x3D }, { 3072, 0x3E }, { 3584, 0x7A },
83 { 3840, 0x3F }, { 4096, 0x7B }, { 5120, 0x7D }, { 6144, 0x7E },
86 static u16 i2c_clk_div[50][2] = {
87 { 22, 0x20 }, { 24, 0x21 }, { 26, 0x22 }, { 28, 0x23 },
88 { 30, 0x00 }, { 32, 0x24 }, { 36, 0x25 }, { 40, 0x26 },
89 { 42, 0x03 }, { 44, 0x27 }, { 48, 0x28 }, { 52, 0x05 },
90 { 56, 0x29 }, { 60, 0x06 }, { 64, 0x2A }, { 72, 0x2B },
91 { 80, 0x2C }, { 88, 0x09 }, { 96, 0x2D }, { 104, 0x0A },
92 { 112, 0x2E }, { 128, 0x2F }, { 144, 0x0C }, { 160, 0x30 },
93 { 192, 0x31 }, { 224, 0x32 }, { 240, 0x0F }, { 256, 0x33 },
94 { 288, 0x10 }, { 320, 0x34 }, { 384, 0x35 }, { 448, 0x36 },
95 { 480, 0x13 }, { 512, 0x37 }, { 576, 0x14 }, { 640, 0x38 },
96 { 768, 0x39 }, { 896, 0x3A }, { 960, 0x17 }, { 1024, 0x3B },
97 { 1152, 0x18 }, { 1280, 0x3C }, { 1536, 0x3D }, { 1792, 0x3E },
98 { 1920, 0x1B }, { 2048, 0x3F }, { 2304, 0x1C }, { 2560, 0x1D },
99 { 3072, 0x1E }, { 3840, 0x1F }
103 #ifndef CONFIG_SYS_MXC_I2C1_SPEED
104 #define CONFIG_SYS_MXC_I2C1_SPEED 100000
106 #ifndef CONFIG_SYS_MXC_I2C2_SPEED
107 #define CONFIG_SYS_MXC_I2C2_SPEED 100000
109 #ifndef CONFIG_SYS_MXC_I2C3_SPEED
110 #define CONFIG_SYS_MXC_I2C3_SPEED 100000
112 #ifndef CONFIG_SYS_MXC_I2C4_SPEED
113 #define CONFIG_SYS_MXC_I2C4_SPEED 100000
116 #ifndef CONFIG_SYS_MXC_I2C1_SLAVE
117 #define CONFIG_SYS_MXC_I2C1_SLAVE 0
119 #ifndef CONFIG_SYS_MXC_I2C2_SLAVE
120 #define CONFIG_SYS_MXC_I2C2_SLAVE 0
122 #ifndef CONFIG_SYS_MXC_I2C3_SLAVE
123 #define CONFIG_SYS_MXC_I2C3_SLAVE 0
125 #ifndef CONFIG_SYS_MXC_I2C4_SLAVE
126 #define CONFIG_SYS_MXC_I2C4_SLAVE 0
130 * Calculate and set proper clock divider
132 static uint8_t i2c_imx_get_clk(struct mxc_i2c_bus *i2c_bus, unsigned int rate)
134 unsigned int i2c_clk_rate;
138 #if defined(CONFIG_MX31)
139 struct clock_control_regs *sc_regs =
140 (struct clock_control_regs *)CCM_BASE;
142 /* start the required I2C clock */
143 writel(readl(&sc_regs->cgr0) | (3 << CONFIG_SYS_I2C_CLK_OFFSET),
147 /* Divider value calculation */
148 i2c_clk_rate = mxc_get_clock(MXC_I2C_CLK);
149 div = (i2c_clk_rate + rate - 1) / rate;
150 if (div < i2c_clk_div[0][0])
152 else if (div > i2c_clk_div[ARRAY_SIZE(i2c_clk_div) - 1][0])
153 clk_div = ARRAY_SIZE(i2c_clk_div) - 1;
155 for (clk_div = 0; i2c_clk_div[clk_div][0] < div; clk_div++)
158 /* Store divider value */
165 static int bus_i2c_set_bus_speed(struct mxc_i2c_bus *i2c_bus, int speed)
167 ulong base = i2c_bus->base;
168 bool quirk = i2c_bus->driver_data & I2C_QUIRK_FLAG ? true : false;
169 u8 clk_idx = i2c_imx_get_clk(i2c_bus, speed);
170 u8 idx = i2c_clk_div[clk_idx][1];
171 int reg_shift = quirk ? VF610_I2C_REGSHIFT : IMX_I2C_REGSHIFT;
176 /* Store divider value */
177 writeb(idx, base + (IFDR << reg_shift));
180 writeb(I2CR_IDIS, base + (I2CR << reg_shift));
181 writeb(0, base + (I2SR << reg_shift));
185 #define ST_BUS_IDLE (0 | (I2SR_IBB << 8))
186 #define ST_BUS_BUSY (I2SR_IBB | (I2SR_IBB << 8))
187 #define ST_IIF (I2SR_IIF | (I2SR_IIF << 8))
189 static int wait_for_sr_state(struct mxc_i2c_bus *i2c_bus, unsigned state)
193 bool quirk = i2c_bus->driver_data & I2C_QUIRK_FLAG ? true : false;
194 int reg_shift = quirk ? VF610_I2C_REGSHIFT : IMX_I2C_REGSHIFT;
195 ulong base = i2c_bus->base;
196 ulong start_time = get_timer(0);
198 sr = readb(base + (I2SR << reg_shift));
201 writeb(sr | I2SR_IAL, base +
202 (I2SR << reg_shift));
204 writeb(sr & ~I2SR_IAL, base +
205 (I2SR << reg_shift));
206 printf("%s: Arbitration lost sr=%x cr=%x state=%x\n",
207 __func__, sr, readb(base + (I2CR << reg_shift)),
211 if ((sr & (state >> 8)) == (unsigned char)state)
214 elapsed = get_timer(start_time);
215 if (elapsed > (CONFIG_SYS_HZ / 10)) /* .1 seconds */
218 printf("%s: failed sr=%x cr=%x state=%x\n", __func__,
219 sr, readb(base + (I2CR << reg_shift)), state);
223 static int tx_byte(struct mxc_i2c_bus *i2c_bus, u8 byte)
226 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ?
227 VF610_I2C_REGSHIFT : IMX_I2C_REGSHIFT;
228 ulong base = i2c_bus->base;
230 writeb(I2SR_IIF_CLEAR, base + (I2SR << reg_shift));
231 writeb(byte, base + (I2DR << reg_shift));
233 ret = wait_for_sr_state(i2c_bus, ST_IIF);
236 if (ret & I2SR_RX_NO_AK)
242 * Stub implementations for outer i2c slave operations.
244 void __i2c_force_reset_slave(void)
247 void i2c_force_reset_slave(void)
248 __attribute__((weak, alias("__i2c_force_reset_slave")));
251 * Stop I2C transaction
253 static void i2c_imx_stop(struct mxc_i2c_bus *i2c_bus)
256 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ?
257 VF610_I2C_REGSHIFT : IMX_I2C_REGSHIFT;
258 ulong base = i2c_bus->base;
259 unsigned int temp = readb(base + (I2CR << reg_shift));
261 temp &= ~(I2CR_MSTA | I2CR_MTX);
262 writeb(temp, base + (I2CR << reg_shift));
263 ret = wait_for_sr_state(i2c_bus, ST_BUS_IDLE);
265 printf("%s:trigger stop failed\n", __func__);
269 * Send start signal, chip address and
270 * write register address
272 static int i2c_init_transfer_(struct mxc_i2c_bus *i2c_bus, u8 chip,
277 bool quirk = i2c_bus->driver_data & I2C_QUIRK_FLAG ? true : false;
278 ulong base = i2c_bus->base;
279 int reg_shift = quirk ? VF610_I2C_REGSHIFT : IMX_I2C_REGSHIFT;
281 /* Reset i2c slave */
282 i2c_force_reset_slave();
284 /* Enable I2C controller */
286 ret = readb(base + (I2CR << reg_shift)) & I2CR_IDIS;
288 ret = !(readb(base + (I2CR << reg_shift)) & I2CR_IEN);
291 writeb(I2CR_IEN, base + (I2CR << reg_shift));
292 /* Wait for controller to be stable */
296 if (readb(base + (IADR << reg_shift)) == (chip << 1))
297 writeb((chip << 1) ^ 2, base + (IADR << reg_shift));
298 writeb(I2SR_IIF_CLEAR, base + (I2SR << reg_shift));
299 ret = wait_for_sr_state(i2c_bus, ST_BUS_IDLE);
303 /* Start I2C transaction */
304 temp = readb(base + (I2CR << reg_shift));
306 writeb(temp, base + (I2CR << reg_shift));
308 ret = wait_for_sr_state(i2c_bus, ST_BUS_BUSY);
312 temp |= I2CR_MTX | I2CR_TX_NO_AK;
313 writeb(temp, base + (I2CR << reg_shift));
315 /* write slave address */
316 ret = tx_byte(i2c_bus, chip << 1);
321 ret = tx_byte(i2c_bus, (addr >> (alen * 8)) & 0xff);
328 #ifndef CONFIG_DM_I2C
329 int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus)
331 if (i2c_bus && i2c_bus->idle_bus_fn)
332 return i2c_bus->idle_bus_fn(i2c_bus->idle_bus_data);
337 * Since pinmux is not supported, implement a weak function here.
338 * You can implement your i2c_bus_idle in board file. When pinctrl
339 * is supported, this can be removed.
341 int __i2c_idle_bus(struct mxc_i2c_bus *i2c_bus)
346 int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus)
347 __attribute__((weak, alias("__i2c_idle_bus")));
350 static int i2c_init_transfer(struct mxc_i2c_bus *i2c_bus, u8 chip,
355 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ?
356 VF610_I2C_REGSHIFT : IMX_I2C_REGSHIFT;
361 for (retry = 0; retry < 3; retry++) {
362 ret = i2c_init_transfer_(i2c_bus, chip, addr, alen);
365 i2c_imx_stop(i2c_bus);
369 printf("%s: failed for chip 0x%x retry=%d\n", __func__, chip,
371 if (ret != -ERESTART)
372 /* Disable controller */
373 writeb(I2CR_IDIS, i2c_bus->base + (I2CR << reg_shift));
375 if (i2c_idle_bus(i2c_bus) < 0)
378 printf("%s: give up i2c_regs=0x%lx\n", __func__, i2c_bus->base);
383 static int i2c_write_data(struct mxc_i2c_bus *i2c_bus, u8 chip, const u8 *buf,
388 debug("i2c_write_data: chip=0x%x, len=0x%x\n", chip, len);
389 debug("write_data: ");
390 /* use rc for counter */
391 for (i = 0; i < len; ++i)
392 debug(" 0x%02x", buf[i]);
395 for (i = 0; i < len; i++) {
396 ret = tx_byte(i2c_bus, buf[i]);
398 debug("i2c_write_data(): rc=%d\n", ret);
406 static int i2c_read_data(struct mxc_i2c_bus *i2c_bus, uchar chip, uchar *buf,
412 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ?
413 VF610_I2C_REGSHIFT : IMX_I2C_REGSHIFT;
414 ulong base = i2c_bus->base;
416 debug("i2c_read_data: chip=0x%x, len=0x%x\n", chip, len);
418 /* setup bus to read data */
419 temp = readb(base + (I2CR << reg_shift));
420 temp &= ~(I2CR_MTX | I2CR_TX_NO_AK);
422 temp |= I2CR_TX_NO_AK;
423 writeb(temp, base + (I2CR << reg_shift));
424 writeb(I2SR_IIF_CLEAR, base + (I2SR << reg_shift));
425 /* dummy read to clear ICF */
426 readb(base + (I2DR << reg_shift));
429 for (i = 0; i < len; i++) {
430 ret = wait_for_sr_state(i2c_bus, ST_IIF);
432 debug("i2c_read_data(): ret=%d\n", ret);
433 i2c_imx_stop(i2c_bus);
438 * It must generate STOP before read I2DR to prevent
439 * controller from generating another clock cycle
441 if (i == (len - 1)) {
442 i2c_imx_stop(i2c_bus);
443 } else if (i == (len - 2)) {
444 temp = readb(base + (I2CR << reg_shift));
445 temp |= I2CR_TX_NO_AK;
446 writeb(temp, base + (I2CR << reg_shift));
448 writeb(I2SR_IIF_CLEAR, base + (I2SR << reg_shift));
449 buf[i] = readb(base + (I2DR << reg_shift));
452 /* reuse ret for counter*/
453 for (ret = 0; ret < len; ++ret)
454 debug(" 0x%02x", buf[ret]);
457 i2c_imx_stop(i2c_bus);
461 #ifndef CONFIG_DM_I2C
463 * Read data from I2C device
465 static int bus_i2c_read(struct mxc_i2c_bus *i2c_bus, u8 chip, u32 addr,
466 int alen, u8 *buf, int len)
470 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ?
471 VF610_I2C_REGSHIFT : IMX_I2C_REGSHIFT;
472 ulong base = i2c_bus->base;
474 ret = i2c_init_transfer(i2c_bus, chip, addr, alen);
478 temp = readb(base + (I2CR << reg_shift));
480 writeb(temp, base + (I2CR << reg_shift));
482 ret = tx_byte(i2c_bus, (chip << 1) | 1);
484 i2c_imx_stop(i2c_bus);
488 ret = i2c_read_data(i2c_bus, chip, buf, len);
490 i2c_imx_stop(i2c_bus);
495 * Write data to I2C device
497 static int bus_i2c_write(struct mxc_i2c_bus *i2c_bus, u8 chip, u32 addr,
498 int alen, const u8 *buf, int len)
502 ret = i2c_init_transfer(i2c_bus, chip, addr, alen);
506 ret = i2c_write_data(i2c_bus, chip, buf, len);
508 i2c_imx_stop(i2c_bus);
513 #if !defined(I2C2_BASE_ADDR)
514 #define I2C2_BASE_ADDR 0
517 #if !defined(I2C3_BASE_ADDR)
518 #define I2C3_BASE_ADDR 0
521 #if !defined(I2C4_BASE_ADDR)
522 #define I2C4_BASE_ADDR 0
525 static struct mxc_i2c_bus mxc_i2c_buses[] = {
526 #if defined(CONFIG_LS102XA) || defined(CONFIG_FSL_LSCH3)
527 { 0, I2C1_BASE_ADDR, I2C_QUIRK_FLAG },
528 { 1, I2C2_BASE_ADDR, I2C_QUIRK_FLAG },
529 { 2, I2C3_BASE_ADDR, I2C_QUIRK_FLAG },
530 { 3, I2C4_BASE_ADDR, I2C_QUIRK_FLAG },
532 { 0, I2C1_BASE_ADDR, 0 },
533 { 1, I2C2_BASE_ADDR, 0 },
534 { 2, I2C3_BASE_ADDR, 0 },
535 { 3, I2C4_BASE_ADDR, 0 },
539 struct mxc_i2c_bus *i2c_get_base(struct i2c_adapter *adap)
541 return &mxc_i2c_buses[adap->hwadapnr];
544 static int mxc_i2c_read(struct i2c_adapter *adap, uint8_t chip,
545 uint addr, int alen, uint8_t *buffer,
548 return bus_i2c_read(i2c_get_base(adap), chip, addr, alen, buffer, len);
551 static int mxc_i2c_write(struct i2c_adapter *adap, uint8_t chip,
552 uint addr, int alen, uint8_t *buffer,
555 return bus_i2c_write(i2c_get_base(adap), chip, addr, alen, buffer, len);
559 * Test if a chip at a given address responds (probe the chip)
561 static int mxc_i2c_probe(struct i2c_adapter *adap, uint8_t chip)
563 return bus_i2c_write(i2c_get_base(adap), chip, 0, 0, NULL, 0);
566 int __enable_i2c_clk(unsigned char enable, unsigned i2c_num)
570 int enable_i2c_clk(unsigned char enable, unsigned i2c_num)
571 __attribute__((weak, alias("__enable_i2c_clk")));
573 void bus_i2c_init(int index, int speed, int unused,
574 int (*idle_bus_fn)(void *p), void *idle_bus_data)
578 if (index >= ARRAY_SIZE(mxc_i2c_buses)) {
579 debug("Error i2c index\n");
583 mxc_i2c_buses[index].idle_bus_fn = idle_bus_fn;
584 mxc_i2c_buses[index].idle_bus_data = idle_bus_data;
586 ret = enable_i2c_clk(1, index);
588 debug("I2C-%d clk fail to enable.\n", index);
592 bus_i2c_set_bus_speed(&mxc_i2c_buses[index], speed);
598 static void mxc_i2c_init(struct i2c_adapter *adap, int speed, int slaveaddr)
600 bus_i2c_init(adap->hwadapnr, speed, slaveaddr, NULL, NULL);
606 static u32 mxc_i2c_set_bus_speed(struct i2c_adapter *adap, uint speed)
608 return bus_i2c_set_bus_speed(i2c_get_base(adap), speed);
612 * Register mxc i2c adapters
614 U_BOOT_I2C_ADAP_COMPLETE(mxc0, mxc_i2c_init, mxc_i2c_probe,
615 mxc_i2c_read, mxc_i2c_write,
616 mxc_i2c_set_bus_speed,
617 CONFIG_SYS_MXC_I2C1_SPEED,
618 CONFIG_SYS_MXC_I2C1_SLAVE, 0)
619 U_BOOT_I2C_ADAP_COMPLETE(mxc1, mxc_i2c_init, mxc_i2c_probe,
620 mxc_i2c_read, mxc_i2c_write,
621 mxc_i2c_set_bus_speed,
622 CONFIG_SYS_MXC_I2C2_SPEED,
623 CONFIG_SYS_MXC_I2C2_SLAVE, 1)
624 #ifdef CONFIG_SYS_I2C_MXC_I2C3
625 U_BOOT_I2C_ADAP_COMPLETE(mxc2, mxc_i2c_init, mxc_i2c_probe,
626 mxc_i2c_read, mxc_i2c_write,
627 mxc_i2c_set_bus_speed,
628 CONFIG_SYS_MXC_I2C3_SPEED,
629 CONFIG_SYS_MXC_I2C3_SLAVE, 2)
632 #ifdef CONFIG_SYS_I2C_MXC_I2C4
633 U_BOOT_I2C_ADAP_COMPLETE(mxc3, mxc_i2c_init, mxc_i2c_probe,
634 mxc_i2c_read, mxc_i2c_write,
635 mxc_i2c_set_bus_speed,
636 CONFIG_SYS_MXC_I2C4_SPEED,
637 CONFIG_SYS_MXC_I2C4_SLAVE, 3)
642 static int mxc_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
644 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
646 return bus_i2c_set_bus_speed(i2c_bus, speed);
649 static int mxc_i2c_probe(struct udevice *bus)
651 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
655 i2c_bus->driver_data = dev_get_driver_data(bus);
657 addr = dev_get_addr(bus);
658 if (addr == FDT_ADDR_T_NONE)
661 i2c_bus->base = addr;
662 i2c_bus->index = bus->seq;
665 ret = enable_i2c_clk(1, bus->seq);
669 ret = i2c_idle_bus(i2c_bus);
672 enable_i2c_clk(0, bus->seq);
677 * Pinmux settings are in board file now, until pinmux is supported,
678 * we can set pinmux here in probe function.
681 debug("i2c : controller bus %d at %lu , speed %d: ",
682 bus->seq, i2c_bus->base,
688 static int mxc_i2c_probe_chip(struct udevice *bus, u32 chip_addr,
692 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
694 ret = i2c_init_transfer(i2c_bus, chip_addr, 0, 0);
696 debug("%s failed, ret = %d\n", __func__, ret);
700 i2c_imx_stop(i2c_bus);
705 static int mxc_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, int nmsgs)
707 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
709 ulong base = i2c_bus->base;
710 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ?
711 VF610_I2C_REGSHIFT : IMX_I2C_REGSHIFT;
714 * Here the 3rd parameter addr and the 4th one alen are set to 0,
715 * because here we only want to send out chip address. The register
716 * address is wrapped in msg.
718 ret = i2c_init_transfer(i2c_bus, msg->addr, 0, 0);
720 debug("i2c_init_transfer error: %d\n", ret);
724 for (; nmsgs > 0; nmsgs--, msg++) {
725 bool next_is_read = nmsgs > 1 && (msg[1].flags & I2C_M_RD);
726 debug("i2c_xfer: chip=0x%x, len=0x%x\n", msg->addr, msg->len);
727 if (msg->flags & I2C_M_RD)
728 ret = i2c_read_data(i2c_bus, msg->addr, msg->buf,
731 ret = i2c_write_data(i2c_bus, msg->addr, msg->buf,
737 ret = readb(base + (I2CR << reg_shift));
739 writeb(ret, base + (I2CR << reg_shift));
741 ret = tx_byte(i2c_bus, (msg->addr << 1) | 1);
743 i2c_imx_stop(i2c_bus);
751 debug("i2c_write: error sending\n");
753 i2c_imx_stop(i2c_bus);
758 static const struct dm_i2c_ops mxc_i2c_ops = {
759 .xfer = mxc_i2c_xfer,
760 .probe_chip = mxc_i2c_probe_chip,
761 .set_bus_speed = mxc_i2c_set_bus_speed,
764 static const struct udevice_id mxc_i2c_ids[] = {
765 { .compatible = "fsl,imx21-i2c", },
766 { .compatible = "fsl,vf610-i2c", .data = I2C_QUIRK_FLAG, },
770 U_BOOT_DRIVER(i2c_mxc) = {
773 .of_match = mxc_i2c_ids,
774 .probe = mxc_i2c_probe,
775 .priv_auto_alloc_size = sizeof(struct mxc_i2c_bus),