* [PATCH 1/4] i2c-bfin-twi: fix CLKDIV calculation
@ 2009-12-21 14:28 Mike Frysinger
[not found] ` <1261405713-7262-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Mike Frysinger @ 2009-12-21 14:28 UTC (permalink / raw)
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ben Dooks
Cc: uclinux-dist-devel-ZG0+EudsQA8dtHy/vicBwGD2FQJk+8+b, Sonic Zhang
From: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
Calculation of the CLKDIV speed setting should be done using base 10 math
rather than base 2. We also avoid exceeding the spec due to integer
truncation and a 50% duty cycle.
Signed-off-by: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Mike Frysinger <vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
---
drivers/i2c/busses/i2c-bfin-twi.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index a0efdab..758bb1f 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -712,13 +712,13 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
}
/* Set TWI internal clock as 10MHz */
- write_CONTROL(iface, ((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F);
+ write_CONTROL(iface, ((get_sclk() / 1000 / 1000 + 5) / 10) & 0x7F);
/*
* We will not end up with a CLKDIV=0 because no one will specify
- * 20kHz SCL or less in Kconfig now. (5 * 1024 / 20 = 0x100)
+ * 20kHz SCL or less in Kconfig now. (5 * 1000 / 20 = 250)
*/
- clkhilow = 5 * 1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ;
+ clkhilow = ((10 * 1000 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ) + 1) / 2;
/* Set Twi interface clock as specified */
write_CLKDIV(iface, (clkhilow << 8) | clkhilow);
--
1.6.5.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] i2c-bfin-twi: fix lost interrupts at high speeds
[not found] ` <1261405713-7262-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
@ 2009-12-21 14:28 ` Mike Frysinger
2009-12-21 14:28 ` [PATCH 3/4] i2c-bfin-twi: remove redundant retry Mike Frysinger
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2009-12-21 14:28 UTC (permalink / raw)
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ben Dooks
Cc: uclinux-dist-devel-ZG0+EudsQA8dtHy/vicBwGD2FQJk+8+b, Sonic Zhang
From: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
i2c event of next read/write byte may trigger before current int state
is cleared in the interrupt handler. So, this should be done at the
beginning of interrupt handler to avoid losing new i2c events.
Signed-off-by: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Mike Frysinger <vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
---
drivers/i2c/busses/i2c-bfin-twi.c | 37 +++++++++++++------------------------
1 files changed, 13 insertions(+), 24 deletions(-)
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index 758bb1f..3495019 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -80,14 +80,15 @@ static const u16 pin_req[2][3] = {
{P_TWI1_SCL, P_TWI1_SDA, 0},
};
-static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
+static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
+ unsigned short twi_int_status)
{
- unsigned short twi_int_status = read_INT_STAT(iface);
unsigned short mast_stat = read_MASTER_STAT(iface);
if (twi_int_status & XMTSERV) {
/* Transmit next data */
if (iface->writeNum > 0) {
+ SSYNC();
write_XMT_DATA8(iface, *(iface->transPtr++));
iface->writeNum--;
}
@@ -109,10 +110,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
write_MASTER_CTL(iface,
(read_MASTER_CTL(iface) | RSTART) & ~MDIR);
}
- SSYNC();
- /* Clear status */
- write_INT_STAT(iface, XMTSERV);
- SSYNC();
}
if (twi_int_status & RCVSERV) {
if (iface->readNum > 0) {
@@ -134,7 +131,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
} else if (iface->manual_stop) {
write_MASTER_CTL(iface,
read_MASTER_CTL(iface) | STOP);
- SSYNC();
} else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
iface->cur_msg + 1 < iface->msg_num) {
if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD)
@@ -143,18 +139,12 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
else
write_MASTER_CTL(iface,
(read_MASTER_CTL(iface) | RSTART) & ~MDIR);
- SSYNC();
}
- /* Clear interrupt source */
- write_INT_STAT(iface, RCVSERV);
- SSYNC();
}
if (twi_int_status & MERR) {
- write_INT_STAT(iface, MERR);
write_INT_MASK(iface, 0);
write_MASTER_STAT(iface, 0x3e);
write_MASTER_CTL(iface, 0);
- SSYNC();
iface->result = -EIO;
if (mast_stat & LOSTARB)
@@ -172,10 +162,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
* results.
*/
if (twi_int_status & MCOMP) {
- write_INT_STAT(iface, MCOMP);
- write_INT_MASK(iface, 0);
- write_MASTER_CTL(iface, 0);
- SSYNC();
/* If it is a quick transfer, only address without data,
* not an err, return 1.
* If address is acknowledged return 1.
@@ -188,8 +174,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
return;
}
if (twi_int_status & MCOMP) {
- write_INT_STAT(iface, MCOMP);
- SSYNC();
if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
if (iface->readNum == 0) {
/* set the read number to 1 and ask for manual
@@ -211,7 +195,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
/* remove restart bit and enable master receive */
write_MASTER_CTL(iface,
read_MASTER_CTL(iface) & ~RSTART);
- SSYNC();
} else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
iface->cur_msg+1 < iface->msg_num) {
iface->cur_msg++;
@@ -230,7 +213,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
write_XMT_DATA8(iface,
*(iface->transPtr++));
iface->writeNum--;
- SSYNC();
}
}
@@ -248,12 +230,10 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
/* remove restart bit and enable master receive */
write_MASTER_CTL(iface,
read_MASTER_CTL(iface) & ~RSTART);
- SSYNC();
} else {
iface->result = 1;
write_INT_MASK(iface, 0);
write_MASTER_CTL(iface, 0);
- SSYNC();
}
}
complete(&iface->complete);
@@ -264,9 +244,18 @@ static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id)
{
struct bfin_twi_iface *iface = dev_id;
unsigned long flags;
+ unsigned short twi_int_status;
spin_lock_irqsave(&iface->lock, flags);
- bfin_twi_handle_interrupt(iface);
+ while (1) {
+ twi_int_status = read_INT_STAT(iface);
+ if (!twi_int_status)
+ break;
+ /* Clear interrupt status */
+ write_INT_STAT(iface, twi_int_status);
+ bfin_twi_handle_interrupt(iface, twi_int_status);
+ SSYNC();
+ }
spin_unlock_irqrestore(&iface->lock, flags);
return IRQ_HANDLED;
}
--
1.6.5.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] i2c-bfin-twi: remove redundant retry
[not found] ` <1261405713-7262-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
2009-12-21 14:28 ` [PATCH 2/4] i2c-bfin-twi: fix lost interrupts at high speeds Mike Frysinger
@ 2009-12-21 14:28 ` Mike Frysinger
[not found] ` <1261405713-7262-3-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
2009-12-21 14:28 ` [PATCH 4/4] i2c-bfin-twi: return completion in interrupt for smbus quick transfers Mike Frysinger
2009-12-21 14:29 ` [Uclinux-dist-devel] [PATCH 1/4] i2c-bfin-twi: fix CLKDIV calculation Mike Frysinger
3 siblings, 1 reply; 7+ messages in thread
From: Mike Frysinger @ 2009-12-21 14:28 UTC (permalink / raw)
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ben Dooks
Cc: uclinux-dist-devel-ZG0+EudsQA8dtHy/vicBwGD2FQJk+8+b, Sonic Zhang
From: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Mike Frysinger <vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
---
drivers/i2c/busses/i2c-bfin-twi.c | 20 ++------------------
1 files changed, 2 insertions(+), 18 deletions(-)
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index 3495019..d157105 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -357,15 +357,7 @@ static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
static int bfin_twi_master_xfer(struct i2c_adapter *adap,
struct i2c_msg *msgs, int num)
{
- int i, ret = 0;
-
- for (i = 0; i < adap->retries; i++) {
- ret = bfin_twi_do_master_xfer(adap, msgs, num);
- if (ret > 0)
- break;
- }
-
- return ret;
+ return bfin_twi_do_master_xfer(adap, msgs, num);
}
/*
@@ -573,16 +565,8 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data *data)
{
- int i, ret = 0;
-
- for (i = 0; i < adap->retries; i++) {
- ret = bfin_twi_do_smbus_xfer(adap, addr, flags,
+ return bfin_twi_do_smbus_xfer(adap, addr, flags,
read_write, command, size, data);
- if (ret == 0)
- break;
- }
-
- return ret;
}
/*
--
1.6.5.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] i2c-bfin-twi: return completion in interrupt for smbus quick transfers
[not found] ` <1261405713-7262-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
2009-12-21 14:28 ` [PATCH 2/4] i2c-bfin-twi: fix lost interrupts at high speeds Mike Frysinger
2009-12-21 14:28 ` [PATCH 3/4] i2c-bfin-twi: remove redundant retry Mike Frysinger
@ 2009-12-21 14:28 ` Mike Frysinger
2009-12-21 14:29 ` [Uclinux-dist-devel] [PATCH 1/4] i2c-bfin-twi: fix CLKDIV calculation Mike Frysinger
3 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2009-12-21 14:28 UTC (permalink / raw)
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ben Dooks
Cc: uclinux-dist-devel-ZG0+EudsQA8dtHy/vicBwGD2FQJk+8+b, Sonic Zhang
From: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
A smbus quick transfer has no data after the address byte.
Signed-off-by: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Mike Frysinger <vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
---
drivers/i2c/busses/i2c-bfin-twi.c | 18 +++++++-----------
1 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index d157105..02a8c86 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -158,18 +158,14 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
if (mast_stat & BUFWRERR)
dev_dbg(&iface->adap.dev, "Buffer Write Error\n");
- /* if both err and complete int stats are set, return proper
- * results.
+ /* If it is a quick transfer, only address without data,
+ * not an err, return 1.
*/
- if (twi_int_status & MCOMP) {
- /* If it is a quick transfer, only address without data,
- * not an err, return 1.
- * If address is acknowledged return 1.
- */
- if ((iface->writeNum == 0 && (mast_stat & BUFRDERR))
- || !(mast_stat & ANAK))
- iface->result = 1;
- }
+ if (iface->cur_mode == TWI_I2C_MODE_STANDARD &&
+ iface->transPtr == NULL &&
+ (twi_int_status & MCOMP) && (mast_stat & DNAK))
+ iface->result = 1;
+
complete(&iface->complete);
return;
}
--
1.6.5.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Uclinux-dist-devel] [PATCH 1/4] i2c-bfin-twi: fix CLKDIV calculation
[not found] ` <1261405713-7262-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
` (2 preceding siblings ...)
2009-12-21 14:28 ` [PATCH 4/4] i2c-bfin-twi: return completion in interrupt for smbus quick transfers Mike Frysinger
@ 2009-12-21 14:29 ` Mike Frysinger
3 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2009-12-21 14:29 UTC (permalink / raw)
To: Ben Dooks
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
uclinux-dist-devel-ZG0+EudsQA8dtHy/vicBwGD2FQJk+8+b
Ben: all of these changes (and the ones sent previously) can be pulled
if that's easier for you:
git://git.kernel.org/pub/scm/linux/kernel/git/vapier/blackfin.git for-i2c
-mike
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/4] i2c-bfin-twi: remove redundant retry
[not found] ` <1261405713-7262-3-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
@ 2009-12-24 1:25 ` Ben Dooks
[not found] ` <20091224012537.GA10442-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>
0 siblings, 1 reply; 7+ messages in thread
From: Ben Dooks @ 2009-12-24 1:25 UTC (permalink / raw)
To: Mike Frysinger
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ben Dooks,
uclinux-dist-devel-ZG0+EudsQA8dtHy/vicBwGD2FQJk+8+b, Sonic Zhang
On Mon, Dec 21, 2009 at 09:28:32AM -0500, Mike Frysinger wrote:
> From: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
Failed to apply, not had a look at why.
> Signed-off-by: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Mike Frysinger <vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
> ---
> drivers/i2c/busses/i2c-bfin-twi.c | 20 ++------------------
> 1 files changed, 2 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
> index 3495019..d157105 100644
> --- a/drivers/i2c/busses/i2c-bfin-twi.c
> +++ b/drivers/i2c/busses/i2c-bfin-twi.c
> @@ -357,15 +357,7 @@ static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
> static int bfin_twi_master_xfer(struct i2c_adapter *adap,
> struct i2c_msg *msgs, int num)
> {
> - int i, ret = 0;
> -
> - for (i = 0; i < adap->retries; i++) {
> - ret = bfin_twi_do_master_xfer(adap, msgs, num);
> - if (ret > 0)
> - break;
> - }
> -
> - return ret;
> + return bfin_twi_do_master_xfer(adap, msgs, num);
> }
>
> /*
> @@ -573,16 +565,8 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
> unsigned short flags, char read_write,
> u8 command, int size, union i2c_smbus_data *data)
> {
> - int i, ret = 0;
> -
> - for (i = 0; i < adap->retries; i++) {
> - ret = bfin_twi_do_smbus_xfer(adap, addr, flags,
> + return bfin_twi_do_smbus_xfer(adap, addr, flags,
> read_write, command, size, data);
> - if (ret == 0)
> - break;
> - }
> -
> - return ret;
> }
>
> /*
> --
> 1.6.5.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Ben (ben-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org, http://www.fluff.org/)
'a smiley only costs 4 bytes'
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Uclinux-dist-devel] [PATCH 3/4] i2c-bfin-twi: remove redundant retry
[not found] ` <20091224012537.GA10442-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>
@ 2009-12-24 1:39 ` Mike Frysinger
0 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2009-12-24 1:39 UTC (permalink / raw)
To: Ben Dooks
Cc: uclinux-dist-devel-ZG0+EudsQA8dtHy/vicBwGD2FQJk+8+b,
linux-i2c-u79uwXL29TY76Z2rM5mHXA, Ben Dooks
On Wed, Dec 23, 2009 at 20:25, Ben Dooks wrote:
> On Mon, Dec 21, 2009 at 09:28:32AM -0500, Mike Frysinger wrote:
>> From: Sonic Zhang <sonic.zhang-OyLXuOCK7orQT0dZR+AlfA@public.gmane.org>
>
> Failed to apply, not had a look at why.
the presumption is that you applied the previous two patches i sent
out some time ago
or just pull all our pending changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/vapier/blackfin.git for-i2c
-mike
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-12-24 1:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-21 14:28 [PATCH 1/4] i2c-bfin-twi: fix CLKDIV calculation Mike Frysinger
[not found] ` <1261405713-7262-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
2009-12-21 14:28 ` [PATCH 2/4] i2c-bfin-twi: fix lost interrupts at high speeds Mike Frysinger
2009-12-21 14:28 ` [PATCH 3/4] i2c-bfin-twi: remove redundant retry Mike Frysinger
[not found] ` <1261405713-7262-3-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
2009-12-24 1:25 ` Ben Dooks
[not found] ` <20091224012537.GA10442-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>
2009-12-24 1:39 ` [Uclinux-dist-devel] " Mike Frysinger
2009-12-21 14:28 ` [PATCH 4/4] i2c-bfin-twi: return completion in interrupt for smbus quick transfers Mike Frysinger
2009-12-21 14:29 ` [Uclinux-dist-devel] [PATCH 1/4] i2c-bfin-twi: fix CLKDIV calculation Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).