From 4ecbb8b67855e50b326a1fcc4ddcd66d2e408084 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sun, 26 Nov 2017 17:40:54 +0100 Subject: i2c: meson: improve Kconfig description Expand the Kconfig description with hardware features. Signed-off-by: Beniamino Galvani Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher --- drivers/i2c/Kconfig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig index cc370b9..0630712 100644 --- a/drivers/i2c/Kconfig +++ b/drivers/i2c/Kconfig @@ -141,7 +141,12 @@ config SYS_I2C_MESON bool "Amlogic Meson I2C driver" depends on DM_I2C && ARCH_MESON help - Add support for the Amlogic Meson I2C driver. + Add support for the I2C controller available in Amlogic Meson + SoCs. The controller supports programmable bus speed including + standard (100kbits/s) and fast (400kbit/s) speed and allows the + software to define a flexible format of the bit streams. It has an + internal buffer holding up to 8 bytes for transfers and supports + both 7-bit and 10-bit addresses. config SYS_I2C_MXC bool "NXP i.MX I2C driver" -- cgit v1.1 From 8c47ab6b3bdc696584d081d63daa2575db24cbfa Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sun, 26 Nov 2017 17:40:55 +0100 Subject: i2c: meson: reduce timeout The datasheet doesn't specify a suggested timeout and 500ms seems very long: reduce it to 100ms. Signed-off-by: Beniamino Galvani Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher --- drivers/i2c/meson_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/meson_i2c.c b/drivers/i2c/meson_i2c.c index 2434d9e..84e1997 100644 --- a/drivers/i2c/meson_i2c.c +++ b/drivers/i2c/meson_i2c.c @@ -9,7 +9,7 @@ #include #include -#define I2C_TIMEOUT_MS 500 +#define I2C_TIMEOUT_MS 100 /* Control register fields */ #define REG_CTRL_START BIT(0) -- cgit v1.1 From 989bb924c464f08ddac9c8ccb4bf6babbb9083f3 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sun, 26 Nov 2017 17:40:56 +0100 Subject: i2c: meson: fix return codes on error Change meson_i2c_xfer_msg() to return -EREMOTEIO in case of NACK, as done by other drivers. Also, don't change the return error in meson_i2c_xfer(). Signed-off-by: Beniamino Galvani Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher --- drivers/i2c/meson_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/meson_i2c.c b/drivers/i2c/meson_i2c.c index 84e1997..2f39214 100644 --- a/drivers/i2c/meson_i2c.c +++ b/drivers/i2c/meson_i2c.c @@ -178,7 +178,7 @@ static int meson_i2c_xfer_msg(struct meson_i2c *i2c, struct i2c_msg *msg, if (readl(&i2c->regs->ctrl) & REG_CTRL_ERROR) { debug("meson i2c: error\n"); - return -ENXIO; + return -EREMOTEIO; } if ((msg->flags & I2C_M_RD) && i2c->count) { @@ -200,7 +200,7 @@ static int meson_i2c_xfer(struct udevice *bus, struct i2c_msg *msg, for (i = 0; i < nmsgs; i++) { ret = meson_i2c_xfer_msg(i2c, msg + i, i == nmsgs - 1); if (ret) - return -EREMOTEIO; + return ret; } return 0; -- cgit v1.1 From 50a69095cbcaa0e17aebc3ec6a502017f6fed55a Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sun, 26 Nov 2017 17:40:57 +0100 Subject: i2c: meson: add some comments Add some comment describing the purpose of struct members and functions. Signed-off-by: Beniamino Galvani Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher --- drivers/i2c/meson_i2c.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/meson_i2c.c b/drivers/i2c/meson_i2c.c index 2f39214..4f37d2f 100644 --- a/drivers/i2c/meson_i2c.c +++ b/drivers/i2c/meson_i2c.c @@ -44,12 +44,12 @@ struct i2c_regs { struct meson_i2c { struct i2c_regs *regs; - struct i2c_msg *msg; - bool last; - uint count; - uint pos; - u32 tokens[2]; - uint num_tokens; + struct i2c_msg *msg; /* Current I2C message */ + bool last; /* Whether the message is the last */ + uint count; /* Number of bytes in the current transfer */ + uint pos; /* Position of current transfer in message */ + u32 tokens[2]; /* Sequence of tokens to be written */ + uint num_tokens; /* Number of tokens to be written */ }; static void meson_i2c_reset_tokens(struct meson_i2c *i2c) @@ -69,6 +69,10 @@ static void meson_i2c_add_token(struct meson_i2c *i2c, int token) i2c->num_tokens++; } +/* + * Retrieve data for the current transfer (which can be at most 8 + * bytes) from the device internal buffer. + */ static void meson_i2c_get_data(struct meson_i2c *i2c, u8 *buf, int len) { u32 rdata0, rdata1; @@ -86,6 +90,10 @@ static void meson_i2c_get_data(struct meson_i2c *i2c, u8 *buf, int len) *buf++ = (rdata1 >> (i - 4) * 8) & 0xff; } +/* + * Write data for the current transfer (which can be at most 8 bytes) + * to the device internal buffer. + */ static void meson_i2c_put_data(struct meson_i2c *i2c, u8 *buf, int len) { u32 wdata0 = 0, wdata1 = 0; @@ -103,6 +111,11 @@ static void meson_i2c_put_data(struct meson_i2c *i2c, u8 *buf, int len) debug("meson i2c: write data %08x %08x len %d\n", wdata0, wdata1, len); } +/* + * Prepare the next transfer: pick the next 8 bytes in the remaining + * part of message and write tokens and data (if needed) to the + * device. + */ static void meson_i2c_prepare_xfer(struct meson_i2c *i2c) { bool write = !(i2c->msg->flags & I2C_M_RD); -- cgit v1.1 From 0afbb0e1c01382f4bcd728ecbd4e49a928dbbccb Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 28 Nov 2017 22:25:23 -0500 Subject: i2c: at91_i2c: Wait for TXRDY after sending the first byte The driver must wait for TXRDY after each byte is pushed into the i2c FIFO before pushing the next byte. Previously this was not done for the first byte, causing a race condition with zeros sometimes being sent for the next byte (which is typically the first actual data byte). Signed-off-by: Alan Ott Reviewed-by: Heiko Schocher --- drivers/i2c/at91_i2c.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/i2c/at91_i2c.c b/drivers/i2c/at91_i2c.c index d394044..20d0929 100644 --- a/drivers/i2c/at91_i2c.c +++ b/drivers/i2c/at91_i2c.c @@ -72,6 +72,8 @@ static int at91_i2c_xfer_msg(struct at91_i2c_bus *bus, struct i2c_msg *msg) } else { writel(msg->buf[0], ®->thr); + ret = at91_wait_for_xfer(bus, TWI_SR_TXRDY); + for (i = 1; !ret && (i < msg->len); i++) { writel(msg->buf[i], ®->thr); ret = at91_wait_for_xfer(bus, TWI_SR_TXRDY); -- cgit v1.1 From cab8a27d80afbdcb7ba422c4c4f85130678373a9 Mon Sep 17 00:00:00 2001 From: Alan Ott Date: Tue, 28 Nov 2017 22:25:24 -0500 Subject: i2c: at91_i2c: remove the .probe_chip function The .probe_chip function is supposed to probe an i2c device on the bus to determine whether a device is answering to a particular address. at91_i2c_probe_chip() did not do anything resembling this and always returned 0. It looks as though at91_i2c_probe_chip() was intended to be a .probe function for the controller, as it was copied-and-pasted to become at91_i2c_probe() in 0bc8f640a4d7ed. Removing the at91_i2c_probe_chip() function makes the higher layer (i2c_probe_chip()) try a zero-length read transfer to test for the presence of a device instead, which does work. Signed-off-by: Alan Ott Acked-by: Wenyou Yang Reviewed-by: Heiko Schocher --- drivers/i2c/at91_i2c.c | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/drivers/i2c/at91_i2c.c b/drivers/i2c/at91_i2c.c index 20d0929..7917ca1 100644 --- a/drivers/i2c/at91_i2c.c +++ b/drivers/i2c/at91_i2c.c @@ -201,27 +201,6 @@ static int at91_i2c_enable_clk(struct udevice *dev) return 0; } -static int at91_i2c_probe_chip(struct udevice *dev, uint chip, uint chip_flags) -{ - struct at91_i2c_bus *bus = dev_get_priv(dev); - struct at91_i2c_regs *reg = bus->regs; - int ret; - - ret = at91_i2c_enable_clk(dev); - if (ret) - return ret; - - writel(TWI_CR_SWRST, ®->cr); - - at91_calc_i2c_clock(dev, bus->clock_frequency); - - writel(bus->cwgr_val, ®->cwgr); - writel(TWI_CR_MSEN, ®->cr); - writel(TWI_CR_SVDIS, ®->cr); - - return 0; -} - static int at91_i2c_set_bus_speed(struct udevice *dev, unsigned int speed) { struct at91_i2c_bus *bus = dev_get_priv(dev); @@ -256,7 +235,6 @@ static int at91_i2c_ofdata_to_platdata(struct udevice *dev) static const struct dm_i2c_ops at91_i2c_ops = { .xfer = at91_i2c_xfer, - .probe_chip = at91_i2c_probe_chip, .set_bus_speed = at91_i2c_set_bus_speed, .get_bus_speed = at91_i2c_get_bus_speed, }; -- cgit v1.1 From 28df8ed07f2ae936e9af28c146d555ed4d0c122a Mon Sep 17 00:00:00 2001 From: Nobuhiro Iwamatsu Date: Fri, 1 Dec 2017 14:39:40 +0900 Subject: cmd: i2c: Fix use sdram sub command with CONFIG_DM_I2C sdram sub command of i2c command does not support Drivers Model. This adds Drivers Model support to sdram sub command. Signed-off-by: Nobuhiro Iwamatsu Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher --- cmd/i2c.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/i2c.c b/cmd/i2c.c index 3dd7c6b..bfddf8b 100644 --- a/cmd/i2c.c +++ b/cmd/i2c.c @@ -1156,7 +1156,10 @@ static int do_sdram (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) uint chip; u_char data[128]; u_char cksum; - int j; + int j, ret; +#ifdef CONFIG_DM_I2C + struct udevice *dev; +#endif static const char *decode_CAS_DDR2[] = { " TBD", " 6", " 5", " 4", " 3", " 2", " TBD", " TBD" @@ -1210,7 +1213,14 @@ static int do_sdram (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) */ chip = simple_strtoul (argv[1], NULL, 16); - if (i2c_read (chip, 0, 1, data, sizeof (data)) != 0) { +#ifdef CONFIG_DM_I2C + ret = i2c_get_cur_bus_chip(chip, &dev); + if (!ret) + ret = dm_i2c_read(dev, 0, data, sizeof(data)); +#else + ret = i2c_read(chip, 0, 1, data, sizeof(data)); +#endif + if (ret) { puts ("No SDRAM Serial Presence Detect found.\n"); return 1; } -- cgit v1.1