Lines Matching refs:i2c_bus
136 static uint8_t i2c_imx_get_clk(struct mxc_i2c_bus *i2c_bus, unsigned int rate) in i2c_imx_get_clk() argument
153 i2c_clk_rate = clk_get_rate(&i2c_bus->per_clk); in i2c_imx_get_clk()
174 static int bus_i2c_set_bus_speed(struct mxc_i2c_bus *i2c_bus, int speed) in bus_i2c_set_bus_speed() argument
176 ulong base = i2c_bus->base; in bus_i2c_set_bus_speed()
177 bool quirk = i2c_bus->driver_data & I2C_QUIRK_FLAG ? true : false; in bus_i2c_set_bus_speed()
178 u8 clk_idx = i2c_imx_get_clk(i2c_bus, speed); in bus_i2c_set_bus_speed()
198 static int wait_for_sr_state(struct mxc_i2c_bus *i2c_bus, unsigned state) in wait_for_sr_state() argument
202 bool quirk = i2c_bus->driver_data & I2C_QUIRK_FLAG ? true : false; in wait_for_sr_state()
204 ulong base = i2c_bus->base; in wait_for_sr_state()
232 static int tx_byte(struct mxc_i2c_bus *i2c_bus, u8 byte) in tx_byte() argument
235 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ? in tx_byte()
237 ulong base = i2c_bus->base; in tx_byte()
242 ret = wait_for_sr_state(i2c_bus, ST_IIF); in tx_byte()
262 static void i2c_imx_stop(struct mxc_i2c_bus *i2c_bus) in i2c_imx_stop() argument
265 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ? in i2c_imx_stop()
267 ulong base = i2c_bus->base; in i2c_imx_stop()
272 ret = wait_for_sr_state(i2c_bus, ST_BUS_IDLE); in i2c_imx_stop()
281 static int i2c_init_transfer_(struct mxc_i2c_bus *i2c_bus, u8 chip, in i2c_init_transfer_() argument
286 bool quirk = i2c_bus->driver_data & I2C_QUIRK_FLAG ? true : false; in i2c_init_transfer_()
287 ulong base = i2c_bus->base; in i2c_init_transfer_()
308 ret = wait_for_sr_state(i2c_bus, ST_BUS_IDLE); in i2c_init_transfer_()
317 ret = wait_for_sr_state(i2c_bus, ST_BUS_BUSY); in i2c_init_transfer_()
326 ret = tx_byte(i2c_bus, chip << 1); in i2c_init_transfer_()
331 ret = tx_byte(i2c_bus, (addr >> (alen * 8)) & 0xff); in i2c_init_transfer_()
341 int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus) in i2c_idle_bus() argument
343 if (i2c_bus && i2c_bus->idle_bus_fn) in i2c_idle_bus()
344 return i2c_bus->idle_bus_fn(i2c_bus->idle_bus_data); in i2c_idle_bus()
359 int i2c_idle_bus(struct mxc_i2c_bus *i2c_bus) in i2c_idle_bus() argument
361 struct udevice *bus = i2c_bus->bus; in i2c_idle_bus()
363 struct gpio_desc *scl_gpio = &i2c_bus->scl_gpio; in i2c_idle_bus()
364 struct gpio_desc *sda_gpio = &i2c_bus->sda_gpio; in i2c_idle_bus()
434 static int i2c_init_transfer(struct mxc_i2c_bus *i2c_bus, u8 chip, in i2c_init_transfer() argument
439 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ? in i2c_init_transfer()
442 if (!i2c_bus->base) in i2c_init_transfer()
446 ret = i2c_init_transfer_(i2c_bus, chip, addr, alen); in i2c_init_transfer()
449 i2c_imx_stop(i2c_bus); in i2c_init_transfer()
457 writeb(I2CR_IDIS, i2c_bus->base + (I2CR << reg_shift)); in i2c_init_transfer()
459 if (i2c_idle_bus(i2c_bus) < 0) in i2c_init_transfer()
462 printf("%s: give up i2c_regs=0x%lx\n", __func__, i2c_bus->base); in i2c_init_transfer()
467 static int i2c_write_data(struct mxc_i2c_bus *i2c_bus, u8 chip, const u8 *buf, in i2c_write_data() argument
480 ret = tx_byte(i2c_bus, buf[i]); in i2c_write_data()
495 static int i2c_read_data(struct mxc_i2c_bus *i2c_bus, uchar chip, uchar *buf, in i2c_read_data() argument
501 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ? in i2c_read_data()
503 ulong base = i2c_bus->base; in i2c_read_data()
519 ret = wait_for_sr_state(i2c_bus, ST_IIF); in i2c_read_data()
522 i2c_imx_stop(i2c_bus); in i2c_read_data()
533 i2c_imx_stop(i2c_bus); in i2c_read_data()
562 i2c_imx_stop(i2c_bus); in i2c_read_data()
597 static int bus_i2c_read(struct mxc_i2c_bus *i2c_bus, u8 chip, u32 addr, in bus_i2c_read() argument
602 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ? in bus_i2c_read()
604 ulong base = i2c_bus->base; in bus_i2c_read()
606 ret = i2c_init_transfer(i2c_bus, chip, addr, alen); in bus_i2c_read()
616 ret = tx_byte(i2c_bus, (chip << 1) | 1); in bus_i2c_read()
618 i2c_imx_stop(i2c_bus); in bus_i2c_read()
622 ret = i2c_read_data(i2c_bus, chip, buf, len, true); in bus_i2c_read()
624 i2c_imx_stop(i2c_bus); in bus_i2c_read()
645 static int bus_i2c_write(struct mxc_i2c_bus *i2c_bus, u8 chip, u32 addr, in bus_i2c_write() argument
650 ret = i2c_init_transfer(i2c_bus, chip, addr, alen); in bus_i2c_write()
654 ret = i2c_write_data(i2c_bus, chip, buf, len); in bus_i2c_write()
656 i2c_imx_stop(i2c_bus); in bus_i2c_write()
875 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
877 return bus_i2c_set_bus_speed(i2c_bus, speed);
882 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
888 i2c_bus->driver_data = dev_get_driver_data(bus);
894 i2c_bus->base = addr;
895 i2c_bus->index = bus->seq;
896 i2c_bus->bus = bus;
900 ret = clk_get_by_index(bus, 0, &i2c_bus->per_clk);
905 ret = clk_enable(&i2c_bus->per_clk);
922 debug("i2c bus %d at 0x%2lx, no gpio pinctrl state.\n", bus->seq, i2c_bus->base);
925 "scl-gpios", 0, &i2c_bus->scl_gpio,
928 "sda-gpios", 0, &i2c_bus->sda_gpio,
930 if (!dm_gpio_is_valid(&i2c_bus->sda_gpio) ||
931 !dm_gpio_is_valid(&i2c_bus->scl_gpio) ||
933 dev_err(dev, "i2c bus %d at %lu, fail to request scl/sda gpio\n", bus->seq, i2c_bus->base);
944 bus->seq, i2c_bus->base,
945 i2c_bus->speed);
955 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
957 ret = i2c_init_transfer(i2c_bus, chip_addr, 0, 0);
963 i2c_imx_stop(i2c_bus);
970 struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
972 ulong base = i2c_bus->base;
973 int reg_shift = i2c_bus->driver_data & I2C_QUIRK_FLAG ?
981 ret = i2c_init_transfer(i2c_bus, msg->addr, 0, -1);
1004 ret = tx_byte(i2c_bus, (msg->addr << 1) | msg_is_read);
1007 i2c_imx_stop(i2c_bus);
1014 ret = i2c_read_data(i2c_bus, msg->addr, msg->buf,
1018 ret = i2c_write_data(i2c_bus, msg->addr, msg->buf,
1028 i2c_imx_stop(i2c_bus);