X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fi2c%2Frk_i2c.c;h=001af668a8a37d533522cea050ce4a0d81bd8682;hb=77b5ba5d2b94c5b028991c82782493f64bd4f392;hp=7c701cbed0a981d7c41b6c4fb1fc99735b9757c5;hpb=9a6535e05f17acf03e891266a650cb6029124743;p=u-boot diff --git a/drivers/i2c/rk_i2c.c b/drivers/i2c/rk_i2c.c index 7c701cbed0..001af668a8 100644 --- a/drivers/i2c/rk_i2c.c +++ b/drivers/i2c/rk_i2c.c @@ -1,10 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2015 Google, Inc * * (C) Copyright 2008-2014 Rockchip Electronics * Peter, Software Engineering, . - * - * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -19,8 +18,6 @@ #include #include -DECLARE_GLOBAL_DATA_PTR; - /* i2c timerout */ #define I2C_TIMEOUT_MS 100 #define I2C_RETRY_COUNT 3 @@ -164,6 +161,7 @@ static int rk_i2c_read(struct rk_i2c *i2c, uchar chip, uint reg, uint r_len, uint rxdata; uint i, j; int err; + bool snd_chunk = false; debug("rk_i2c_read: chip = %d, reg = %d, r_len = %d, b_len = %d\n", chip, reg, r_len, b_len); @@ -184,15 +182,26 @@ static int rk_i2c_read(struct rk_i2c *i2c, uchar chip, uint reg, uint r_len, while (bytes_remain_len) { if (bytes_remain_len > RK_I2C_FIFO_SIZE) { - con = I2C_CON_EN | I2C_CON_MOD(I2C_MODE_TRX); + con = I2C_CON_EN; bytes_xferred = 32; } else { - con = I2C_CON_EN | I2C_CON_MOD(I2C_MODE_TRX) | - I2C_CON_LASTACK; + /* + * The hw can read up to 32 bytes at a time. If we need + * more than one chunk, send an ACK after the last byte. + */ + con = I2C_CON_EN | I2C_CON_LASTACK; bytes_xferred = bytes_remain_len; } words_xferred = DIV_ROUND_UP(bytes_xferred, 4); + /* + * make sure we are in plain RX mode if we read a second chunk + */ + if (snd_chunk) + con |= I2C_CON_MOD(I2C_MODE_RX); + else + con |= I2C_CON_MOD(I2C_MODE_TRX); + writel(con, ®s->con); writel(bytes_xferred, ®s->mrxcnt); writel(I2C_MBRFIEN | I2C_NAKRCVIEN, ®s->ien); @@ -227,6 +236,7 @@ static int rk_i2c_read(struct rk_i2c *i2c, uchar chip, uint reg, uint r_len, } bytes_remain_len -= bytes_xferred; + snd_chunk = true; debug("I2C Read bytes_remain_len %d\n", bytes_remain_len); } @@ -369,7 +379,7 @@ static int rockchip_i2c_probe(struct udevice *bus) { struct rk_i2c *priv = dev_get_priv(bus); - priv->regs = (void *)dev_get_addr(bus); + priv->regs = dev_read_addr_ptr(bus); return 0; } @@ -380,7 +390,11 @@ static const struct dm_i2c_ops rockchip_i2c_ops = { }; static const struct udevice_id rockchip_i2c_ids[] = { + { .compatible = "rockchip,rk3066-i2c" }, + { .compatible = "rockchip,rk3188-i2c" }, { .compatible = "rockchip,rk3288-i2c" }, + { .compatible = "rockchip,rk3328-i2c" }, + { .compatible = "rockchip,rk3399-i2c" }, { } };