summaryrefslogtreecommitdiff
path: root/drivers/i2c/sh_i2c.c
diff options
context:
space:
mode:
authorTetsuyuki Kobayashi <koba@kmckk.co.jp>2012-09-13 19:08:00 +0000
committerHeiko Schocher <hs@denx.de>2012-10-16 05:47:20 +0200
commitd042d7121b13d98bd403e7b64438ce55cfefd0d9 (patch)
tree46bb768ee28991cb13da59ecf9827c7836d1ae61 /drivers/i2c/sh_i2c.c
parent020ec727a6bda10f47d69926814d476c0085e8a9 (diff)
downloadu-boot-imx-d042d7121b13d98bd403e7b64438ce55cfefd0d9.zip
u-boot-imx-d042d7121b13d98bd403e7b64438ce55cfefd0d9.tar.gz
u-boot-imx-d042d7121b13d98bd403e7b64438ce55cfefd0d9.tar.bz2
i2c: sh_i2c: enable i2c_probe
Before this patch i2c_probe() always returned 0 and "i2c probe" command did not work properly. Modify i2c_set_addr() to check TACK when waiting DTE and make i2c_probe() call this function. Acked-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com> Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>
Diffstat (limited to 'drivers/i2c/sh_i2c.c')
-rw-r--r--drivers/i2c/sh_i2c.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/drivers/i2c/sh_i2c.c b/drivers/i2c/sh_i2c.c
index d50c8ec..a7204cc 100644
--- a/drivers/i2c/sh_i2c.c
+++ b/drivers/i2c/sh_i2c.c
@@ -69,6 +69,20 @@ static void irq_dte(struct sh_i2c *base)
}
}
+static int irq_dte_with_tack(struct sh_i2c *base)
+{
+ int i;
+
+ for (i = 0 ; i < IRQ_WAIT ; i++) {
+ if (SH_IC_DTE & readb(&base->icsr))
+ break;
+ if (SH_IC_TACK & readb(&base->icsr))
+ return -1;
+ udelay(10);
+ }
+ return 0;
+}
+
static void irq_busy(struct sh_i2c *base)
{
int i;
@@ -80,9 +94,9 @@ static void irq_busy(struct sh_i2c *base)
}
}
-static void i2c_set_addr(struct sh_i2c *base, u8 id, u8 reg, int stop)
+static int i2c_set_addr(struct sh_i2c *base, u8 id, u8 reg, int stop)
{
- u8 icic = 0;
+ u8 icic = SH_IC_TACK;
writeb(readb(&base->iccr) & ~SH_I2C_ICCR_ICE, &base->iccr);
writeb(readb(&base->iccr) | SH_I2C_ICCR_ICE, &base->iccr);
@@ -100,14 +114,18 @@ static void i2c_set_addr(struct sh_i2c *base, u8 id, u8 reg, int stop)
writeb((SH_I2C_ICCR_ICE|SH_I2C_ICCR_RTS|SH_I2C_ICCR_BUSY), &base->iccr);
irq_dte(base);
+ writeb(readb(&base->icsr) & ~SH_IC_TACK, &base->icsr);
writeb(id << 1, &base->icdr);
- irq_dte(base);
+ if (irq_dte_with_tack(base) != 0)
+ return -1;
writeb(reg, &base->icdr);
if (stop)
writeb((SH_I2C_ICCR_ICE|SH_I2C_ICCR_RTS), &base->iccr);
- irq_dte(base);
+ if (irq_dte_with_tack(base) != 0)
+ return -1;
+ return 0;
}
static void i2c_finish(struct sh_i2c *base)
@@ -305,5 +323,9 @@ int i2c_write(u8 chip, u32 addr, int alen, u8 *buffer, int len)
*/
int i2c_probe(u8 chip)
{
- return 0;
+ int ret;
+
+ ret = i2c_set_addr(base, chip, 0, 1);
+ i2c_finish(base);
+ return ret;
}