i2c-bfin-twi: fix CLKDIV calculation
PATCH 1/4 i2c-bfin-twi: fix CLKDIV calculation
From: Sonic Zhang <[email protected]>
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.
--- drivers/i2c/busses/i2c-bfin-twi.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-bfin-twi.c +3 -3
@@ -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);
Signature · 1 line
1.6.5.4
A message that is not in the archive (sent off-list or not yet received): 1261405713-7262-1-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org
PATCH 2/4 i2c-bfin-twi: fix lost interrupts at high speeds
From: Sonic Zhang <[email protected]>
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.
--- drivers/i2c/busses/i2c-bfin-twi.c | 37 +++++++++++++------------------------ 1 files changed, 13 insertions(+), 24 deletions(-)
drivers/i2c/busses/i2c-bfin-twi.c +13 -24
@@ -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 ; }
Signature · 1 line
1.6.5.4
PATCH 3/4 i2c-bfin-twi: remove redundant retry
In reply to a message not in the archiveFrom: Sonic Zhang <[email protected]>
--- drivers/i2c/busses/i2c-bfin-twi.c | 20 ++------------------ 1 files changed, 2 insertions(+), 18 deletions(-)
drivers/i2c/busses/i2c-bfin-twi.c +2 -18
@@ -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; }/*
Signature · 1 line
1.6.5.4
A message that is not in the archive (sent off-list or not yet received): 1261405713-7262-3-git-send-email-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org
Re: [PATCH 3/4] i2c-bfin-twi: remove redundant retry
Quoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
Failed to apply, not had a look at why.
Quoted 52 lines
Signed-off-by Sonic Zhang <[email protected]>Signed-off-by Mike Frysinger <[email protected]>--- drivers/i2c/busses/i2c-bfin-twi.c | 20 ++------------------ 1 files changed, 2 insertions(+), 18 deletions(-)drivers/i2c/busses/i2c-bfin-twi.c +2
-18@@ -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; }/* Signature · 6 lines
1.6.5.4 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [Uclinux-dist-devel] [PATCH 3/4] i2c-bfin-twi: remove redundant retry
Quoted 4 lines · Ben Dooks
Quoted 1 line · Mike Frysinger
From: Sonic Zhang <[email protected]>
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
PATCH 4/4 i2c-bfin-twi: return completion in interrupt for smbus quick transfers
In reply to a message not in the archiveFrom: Sonic Zhang <[email protected]>
A smbus quick transfer has no data after the address byte.
--- drivers/i2c/busses/i2c-bfin-twi.c | 18 +++++++----------- 1 files changed, 7 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-bfin-twi.c +7 -11
@@ -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 ; }
Signature · 1 line
1.6.5.4
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