Skip to contentSkip to conversation

sh: i2c: Add support I2C controller of SH7734

PATCH Superseded Nobuhiro Iwamatsu 2 participants 3 messages Mar 1, 2012 – Mar 2, 2012 I2C

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 sh: i2c: Add support I2C controller of SH7734

Renesas SH7734 has two I2C interfaceis.
This supports these I2C.

V4: - Remove sh_i2c_dump_reg function.
- Use puts() when there's no format.
- Chnage check for I2C bus number.
- Remove space before the semi-colon.
V3: - Fix error for whitespace.
V2: - Changed bit control to use the clr|set|clrsetbits_* functions.
- Fix wrong comment style.
- Add new line before for loop in i2c_read.

---
 drivers/i2c/Makefile        |    1 +
 drivers/i2c/sh_sh7734_i2c.c |  426 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 427 insertions(+), 0 deletions(-)
 create mode 100644 drivers/i2c/sh_sh7734_i2c.c
drivers/i2c/Makefile +1 -0
index 504db03..506269d 100644
@@ -44,6 +44,7 @@ COBJS-$(CONFIG_SPEAR_I2C) += spr_i2c.o
 COBJS-$(CONFIG_TSI108_I2C) += tsi108_i2c.o
 COBJS-$(CONFIG_U8500_I2C) += u8500_i2c.o
 COBJS-$(CONFIG_SH_I2C) += sh_i2c.o
+COBJS-$(CONFIG_SH_SH7734_I2C) += sh_sh7734_i2c.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
drivers/i2c/sh_sh7734_i2c.c new file +426 -0

426 lines not on this page · raw message

Signature · 1 line
1.7.9.1
#1 lore raw

PATCH v4 1/1 sh: i2c: Add support I2C controller of SH7734

drivers/i2c/sh_sh7734_i2c.c line 22

Quoted 5 lines · On Wednesday 29 February 2012 21:58:42 Nobuhiro Iwamatsu wrote:
drivers/i2c/sh_sh7734_i2c.c new file +2 -0
 
+#include <common.h>
+#include <asm/io.h>

should include i2c.h too so you know your funcs match the prototypes everyone else uses

Quoted 57 lines
drivers/i2c/sh_sh7734_i2c.c new file +57 -0
+static int check_stop(struct sh_i2c *base)
+{
+	int i, ret = 1;
+
+	for (i = 0; i < IRQ_WAIT; i++) {
+		if (SH_I2C_ICSR_STOP & readb(&base->icsr)) {
+			ret = 0;
+			break;
+		}
+		udelay(10);
+	}
+
+	clrbits_le8(&base->icsr, SH_I2C_ICSR_STOP);
+
+	return ret;
+}
+
+static int check_tend(struct sh_i2c *base, int stop)
+{
+	int i, ret = 1;
+
+	for (i = 0; i < IRQ_WAIT; i++) {
+		if (SH_I2C_ICSR_TEND & readb(&base->icsr)) {
+			ret = 0;
+			break;
+		}
+		udelay(10);
+	}
+
+	if (stop) {
+		u8 data;
+
+		clrbits_le8(&base->icsr, SH_I2C_ICSR_STOP);
+
+		sh_i2c_send_stop(base);
+	}
+
+	clrbits_le8(&base->icsr, SH_I2C_ICSR_TEND);
+
+	return ret;
+}
+
+static int check_tdre(struct sh_i2c *base)
+{
+	int i;
+
+	for (i = 0; i < IRQ_WAIT; i++) {
+		if (SH_I2C_ICSR_TDRE & readb(&base->icsr))
+			return 0;
+		udelay(10);
+	}
+
+	return 1;
+}
+
+static int check_rdrf(struct sh_i2c *base)
+{

drivers/i2c/sh_sh7734_i2c.c line 149

Quoted 10 lines
drivers/i2c/sh_sh7734_i2c.c new file +10 -0
+	int i;
+
+	for (i = 0; i < IRQ_WAIT; i++) {
+		if (SH_I2C_ICSR_RDRF & readb(&base->icsr))
+			return 0;
+		udelay(10);
+	}
+
+	return 1;
+}

you've got the same icsr bit polling logic here. probably better to put it into a dedicated func which takes the bit flag to check and the rest will call that.

	static int check_icsr_bit(struct sh_i2c *base, uint bit)
	{
		int i;

		for (i = 0; i < IRQ_WAIT; i++) {
			if (bit & readb(&base->icsr))
				return 0;
			udelay(10);
		}

		return 1;
	}

	static int check_tdre(struct sh_i2c *base)
	{
		return check_icsr_bit(base, SH_I2C_ICSR_TDRE);
	}

drivers/i2c/sh_sh7734_i2c.c line 270

Quoted 4 lines
drivers/i2c/sh_sh7734_i2c.c new file +3 -0
+static u8 i2c_raw_read(struct sh_i2c *base, u8 id, u8 reg)
+{
...
+	writeb(id << 1 | 1, &base->icdrt);

shifting and bit ops can lead to unexpected behavior ... might be better:

	writeb((id << 1) | 1, &base->icdrt);

drivers/i2c/sh_sh7734_i2c.c line 426

Quoted 10 lines
drivers/i2c/sh_sh7734_i2c.c new file +10 -0
+/*
+ * i2c_probe: - Test if a chip answers for a given i2c address
+ *
+ * @chip:   address of the chip which is searched for
+ * @return: 0 if a chip was found, -1 otherwhise
+ */
+int i2c_probe(u8 chip)
+{
+	return 0;
+}

should implement this. look at the Blackfin twi driver for an easy one. -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120229/7c82d16a/attachment.pgp>

#2 lore raw

PATCH v4 1/1 sh: i2c: Add support I2C controller of SH7734

Hi, Mike.

2012/3/1 Mike Frysinger <[email protected]>:

Quoted 9 lines · On Wednesday 29 February 2012 21:58:42 Nobuhiro Iwamatsu wrote:

drivers/i2c/sh_sh7734_i2c.c line 22

Quoted 5 lines
drivers/i2c/sh_sh7734_i2c.c new file +2 -0
 
+#include <common.h>
+#include <asm/io.h>

should include i2c.h too so you know your funcs match the prototypes everyone else uses

OK.

Quoted 82 lines
Quoted 58 lines
drivers/i2c/sh_sh7734_i2c.c new file +57 -0
+static int check_stop(struct sh_i2c *base)
+{
+ ? ? int i, ret = 1;
+
+ ? ? for (i = 0; i < IRQ_WAIT; i++) {
+ ? ? ? ? ? ? if (SH_I2C_ICSR_STOP & readb(&base->icsr)) {
+ ? ? ? ? ? ? ? ? ? ? ret = 0;
+ ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? }
+ ? ? ? ? ? ? udelay(10);
+ ? ? }
+
+ ? ? clrbits_le8(&base->icsr, SH_I2C_ICSR_STOP);
+
+ ? ? return ret;
+}
+
+static int check_tend(struct sh_i2c *base, int stop)
+{
+ ? ? int i, ret = 1;
+
+ ? ? for (i = 0; i < IRQ_WAIT; i++) {
+ ? ? ? ? ? ? if (SH_I2C_ICSR_TEND & readb(&base->icsr)) {
+ ? ? ? ? ? ? ? ? ? ? ret = 0;
+ ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? }
+ ? ? ? ? ? ? udelay(10);
+ ? ? }
+
+ ? ? if (stop) {
+ ? ? ? ? ? ? u8 data;
+
+ ? ? ? ? ? ? clrbits_le8(&base->icsr, SH_I2C_ICSR_STOP);
+
+ ? ? ? ? ? ? sh_i2c_send_stop(base);
+ ? ? }
+
+ ? ? clrbits_le8(&base->icsr, SH_I2C_ICSR_TEND);
+
+ ? ? return ret;
+}
+
+static int check_tdre(struct sh_i2c *base)
+{
+ ? ? int i;
+
+ ? ? for (i = 0; i < IRQ_WAIT; i++) {
+ ? ? ? ? ? ? if (SH_I2C_ICSR_TDRE & readb(&base->icsr))
+ ? ? ? ? ? ? ? ? ? ? return 0;
+ ? ? ? ? ? ? udelay(10);
+ ? ? }
+
+ ? ? return 1;
+}
+
+static int check_rdrf(struct sh_i2c *base)
+{

drivers/i2c/sh_sh7734_i2c.c

Quoted 10 lines
drivers/i2c/sh_sh7734_i2c.c new file +10 -0
+ ? ? int i;
+
+ ? ? for (i = 0; i < IRQ_WAIT; i++) {
+ ? ? ? ? ? ? if (SH_I2C_ICSR_RDRF & readb(&base->icsr))
+ ? ? ? ? ? ? ? ? ? ? return 0;
+ ? ? ? ? ? ? udelay(10);
+ ? ? }
+
+ ? ? return 1;
+}

you've got the same icsr bit polling logic here. ?probably better to put it into a dedicated func which takes the bit flag to check and the rest will call that.
? ? ? ?static int check_icsr_bit(struct sh_i2c *base, uint bit)
? ? ? ?{
? ? ? ? ? ? ? ?int i;

? ? ? ? ? ? ? ?for (i = 0; i < IRQ_WAIT; i++) { ? ? ? ? ? ? ? ? ? ? ? ?if (bit & readb(&base->icsr)) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?return 0;
? ? ? ? ? ? ? ? ? ? ? ?udelay(10);
? ? ? ? ? ? ? ?}

Quoted 7 lines

? ? ? ? ? ? ? ?return 1;
? ? ? ?}

? ? ? ?static int check_tdre(struct sh_i2c *base)
? ? ? ?{
? ? ? ? ? ? ? ?return check_icsr_bit(base, SH_I2C_ICSR_TDRE); ? ? ? ?}

OK, I fixed.

Quoted 9 lines

drivers/i2c/sh_sh7734_i2c.c

Quoted 5 lines
drivers/i2c/sh_sh7734_i2c.c new file +3 -0
+static u8 i2c_raw_read(struct sh_i2c *base, u8 id, u8 reg)
+{
...
+ ? ? writeb(id << 1 | 1, &base->icdrt);

shifting and bit ops can lead to unexpected behavior ... might be better:
? ? ? ?writeb((id << 1) | 1, &base->icdrt);

OK, I fixed.

Quoted 4 lines
Quoted 4 lines

+/*
+ * i2c_probe: - Test if a chip answers for a given i2c address
+ *
+ * @chip: ? address of the chip which is searched for

Quoted 8 lines

drivers/i2c/sh_sh7734_i2c.c line 426

Quoted 6 lines

+ * @return: 0 if a chip was found, -1 otherwhise
+ */

drivers/i2c/sh_sh7734_i2c.c new file +4 -0
+int i2c_probe(u8 chip)
+{
+ ? ? return 0;
+}

should implement this. ?look at the Blackfin twi driver for an easy one.

Thanks for your infomation.
I implemented this.

Thanks,
Nobuhiro

Signature · 1 line
Nobuhiro Iwamatsu