Lines Matching refs:i2c_bus

142 static uint8_t i2c_imx_get_clk(struct mxc_i2c_bus *i2c_bus, unsigned int rate)  in i2c_imx_get_clk()  argument
159 i2c_clk_rate = clk_get_rate(&i2c_bus->per_clk); in i2c_imx_get_clk()
180 static int bus_i2c_set_bus_speed(struct mxc_i2c_bus *i2c_bus, int speed) in bus_i2c_set_bus_speed() argument
182 ulong base = i2c_bus->base; in bus_i2c_set_bus_speed()
183 bool quirk = i2c_bus->driver_data & I2C_QUIRK_FLAG ? true : false; in bus_i2c_set_bus_speed()
184 u8 clk_idx = i2c_imx_get_clk(i2c_bus, speed); in bus_i2c_set_bus_speed()
204 static int wait_for_sr_state(struct mxc_i2c_bus *i2c_bus, unsigned state) in wait_for_sr_state() argument
208 bool quirk = i2c_bus->driver_data & I2C_QUIRK_FLAG ? true : false; in wait_for_sr_state()
210 ulong base = i2c_bus->base; in wait_for_sr_state()
238 static int tx_byte(struct mxc_i2c_bus *i2c_bus, u8 byte) in tx_byte() argument
241 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ? in tx_byte()
243 ulong base = i2c_bus->base; in tx_byte()
248 ret = wait_for_sr_state(i2c_bus, ST_IIF); in tx_byte()
268 static void i2c_imx_stop(struct mxc_i2c_bus *i2c_bus) in i2c_imx_stop() argument
271 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ? in i2c_imx_stop()
273 ulong base = i2c_bus->base; in i2c_imx_stop()
278 ret = wait_for_sr_state(i2c_bus, ST_BUS_IDLE); in i2c_imx_stop()
287 static int i2c_init_transfer_(struct mxc_i2c_bus *i2c_bus, u8 chip, in i2c_init_transfer_() argument
292 bool quirk = i2c_bus->driver_data & I2C_QUIRK_FLAG ? true : false; in i2c_init_transfer_()
293 ulong base = i2c_bus->base; in i2c_init_transfer_()
314 ret = wait_for_sr_state(i2c_bus, ST_BUS_IDLE); in i2c_init_transfer_()
323 ret = wait_for_sr_state(i2c_bus, ST_BUS_BUSY); in i2c_init_transfer_()
332 ret = tx_byte(i2c_bus, chip << 1); in i2c_init_transfer_()
337 ret = tx_byte(i2c_bus, (addr >> (alen * 8)) & 0xff); in i2c_init_transfer_()
398 int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus) in i2c_idle_bus() argument
400 if (i2c_bus && i2c_bus->idle_bus_fn) in i2c_idle_bus()
401 return i2c_bus->idle_bus_fn(i2c_bus->idle_bus_data); in i2c_idle_bus()
416 int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus) in i2c_idle_bus() argument
418 struct udevice *bus = i2c_bus->bus; in i2c_idle_bus()
420 struct gpio_desc *scl_gpio = &i2c_bus->scl_gpio; in i2c_idle_bus()
421 struct gpio_desc *sda_gpio = &i2c_bus->sda_gpio; in i2c_idle_bus()
509 static int i2c_init_transfer(struct mxc_i2c_bus *i2c_bus, u8 chip, in i2c_init_transfer() argument
514 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ? in i2c_init_transfer()
517 if (!i2c_bus->base) in i2c_init_transfer()
521 ret = i2c_init_transfer_(i2c_bus, chip, addr, alen); in i2c_init_transfer()
524 i2c_imx_stop(i2c_bus); in i2c_init_transfer()
532 writeb(I2CR_IDIS, i2c_bus->base + (I2CR << reg_shift)); in i2c_init_transfer()
534 if (i2c_idle_bus(i2c_bus) < 0) in i2c_init_transfer()
537 printf("%s: give up i2c_regs=0x%lx\n", __func__, i2c_bus->base); in i2c_init_transfer()
542 static int i2c_write_data(struct mxc_i2c_bus *i2c_bus, u8 chip, const u8 *buf, in i2c_write_data() argument
555 ret = tx_byte(i2c_bus, buf[i]); in i2c_write_data()
570 static int i2c_read_data(struct mxc_i2c_bus *i2c_bus, uchar chip, uchar *buf, in i2c_read_data() argument
576 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ? in i2c_read_data()
578 ulong base = i2c_bus->base; in i2c_read_data()
594 ret = wait_for_sr_state(i2c_bus, ST_IIF); in i2c_read_data()
597 i2c_imx_stop(i2c_bus); in i2c_read_data()
608 i2c_imx_stop(i2c_bus); in i2c_read_data()
637 i2c_imx_stop(i2c_bus); in i2c_read_data()
672 static int bus_i2c_read(struct mxc_i2c_bus *i2c_bus, u8 chip, u32 addr, in bus_i2c_read() argument
677 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ? in bus_i2c_read()
679 ulong base = i2c_bus->base; in bus_i2c_read()
681 ret = i2c_init_transfer(i2c_bus, chip, addr, alen); in bus_i2c_read()
691 ret = tx_byte(i2c_bus, (chip << 1) | 1); in bus_i2c_read()
693 i2c_imx_stop(i2c_bus); in bus_i2c_read()
697 ret = i2c_read_data(i2c_bus, chip, buf, len, true); in bus_i2c_read()
699 i2c_imx_stop(i2c_bus); in bus_i2c_read()
720 static int bus_i2c_write(struct mxc_i2c_bus *i2c_bus, u8 chip, u32 addr, in bus_i2c_write() argument
725 ret = i2c_init_transfer(i2c_bus, chip, addr, alen); in bus_i2c_write()
729 ret = i2c_write_data(i2c_bus, chip, buf, len); in bus_i2c_write()
731 i2c_imx_stop(i2c_bus); in bus_i2c_write()
890 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
892 return bus_i2c_set_bus_speed(i2c_bus, speed);
897 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
903 i2c_bus->driver_data = dev_get_driver_data(bus);
917 i2c_bus->base = addr;
918 i2c_bus->index = dev_seq(bus);
919 i2c_bus->bus = bus;
923 ret = clk_get_by_index(bus, 0, &i2c_bus->per_clk);
928 ret = clk_enable(&i2c_bus->per_clk);
946 dev_seq(bus), i2c_bus->base);
949 "scl-gpios", 0, &i2c_bus->scl_gpio,
952 "sda-gpios", 0, &i2c_bus->sda_gpio,
954 if (!dm_gpio_is_valid(&i2c_bus->sda_gpio) ||
955 !dm_gpio_is_valid(&i2c_bus->scl_gpio) ||
959 dev_seq(bus), i2c_bus->base);
970 dev_seq(bus), i2c_bus->base,
971 i2c_bus->speed);
981 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
983 ret = i2c_init_transfer(i2c_bus, chip_addr, 0, 0);
989 i2c_imx_stop(i2c_bus);
996 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
998 ulong base = i2c_bus->base;
999 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ?
1007 ret = i2c_init_transfer(i2c_bus, msg->addr, 0, -1);
1030 ret = tx_byte(i2c_bus, (msg->addr << 1) | msg_is_read);
1033 i2c_imx_stop(i2c_bus);
1040 ret = i2c_read_data(i2c_bus, msg->addr, msg->buf,
1044 ret = i2c_write_data(i2c_bus, msg->addr, msg->buf,
1054 i2c_imx_stop(i2c_bus);