Merge tag 'efi-2020-04-rc3' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
[oweals/u-boot.git] / drivers / i2c / i2c-cdns.c
index 1af94d17614554cda01321f1a6626e3db234ab44..ac15da2c67ffea715dc5b3ece1c4b032dcd9f44b 100644 (file)
@@ -213,7 +213,7 @@ static int cdns_i2c_set_bus_speed(struct udevice *dev, unsigned int speed)
        unsigned long speed_p = speed;
        int ret = 0;
 
-       if (speed > 400000) {
+       if (speed > I2C_SPEED_FAST_RATE) {
                debug("%s, failed to set clock speed to %u\n", __func__,
                      speed);
                return -EINVAL;
@@ -265,7 +265,7 @@ static int cdns_i2c_write_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data,
 
        while (len-- && !is_arbitration_lost(regs)) {
                writel(*(cur_data++), &regs->data);
-               if (readl(&regs->transfer_size) == CDNS_I2C_FIFO_DEPTH) {
+               if (len && readl(&regs->transfer_size) == CDNS_I2C_FIFO_DEPTH) {
                        ret = cdns_i2c_wait(regs, CDNS_I2C_INTERRUPT_COMP |
                                            CDNS_I2C_INTERRUPT_ARBLOST);
                        if (ret & CDNS_I2C_INTERRUPT_ARBLOST)
@@ -308,14 +308,10 @@ static int cdns_i2c_read_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data,
 {
        u8 *cur_data = data;
        struct cdns_i2c_regs *regs = i2c_bus->regs;
-       int curr_recv_count;
+       u32 curr_recv_count;
        int updatetx, hold_quirk;
        u32 ret;
 
-       /* Check the hardware can handle the requested bytes */
-       if ((recv_count < 0))
-               return -EINVAL;
-
        curr_recv_count = recv_count;
 
        /* Check for the message size against the FIFO depth */