From 9067c915ad4fb8104a0f44e340a915a11614b379 Mon Sep 17 00:00:00 2001 From: Bertrik Sikken Date: Sun, 31 May 2009 17:48:19 +0000 Subject: Use I2C2_DACNT register (number of pending i2c bytes to read/write) to determine if an ascodec i2c transfer is done. This should fix i2c problems with MMU enabled. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21150 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/as3525/ascodec-as3525.c | 66 ++++++++++++----------------- 1 file changed, 27 insertions(+), 39 deletions(-) (limited to 'firmware/target/arm/as3525/ascodec-as3525.c') diff --git a/firmware/target/arm/as3525/ascodec-as3525.c b/firmware/target/arm/as3525/ascodec-as3525.c index 668c001f9b..ad85f0c186 100644 --- a/firmware/target/arm/as3525/ascodec-as3525.c +++ b/firmware/target/arm/as3525/ascodec-as3525.c @@ -97,39 +97,31 @@ static int i2c_busy(void) return (I2C2_SR & 1); } - /* returns 0 on success, <0 otherwise */ int ascodec_write(unsigned int index, unsigned int value) { - int retval; - ascodec_lock(); - /* check if still busy */ - if (i2c_busy()) { - retval = -1; - } - else { - if (index == AS3514_CVDD_DCDC3) { - /* prevent setting of the LREG_CP_not bit */ - value &= ~(1 << 5); - } - - /* start transfer */ - I2C2_SADDR = index; - I2C2_CNTRL &= ~(1 << 1); - I2C2_DATA = value; - I2C2_DACNT = 1; - - /* wait for transfer*/ - while (i2c_busy()); - - retval = 0; + /* wait if still busy */ + while (i2c_busy()); + + if (index == AS3514_CVDD_DCDC3) { + /* prevent setting of the LREG_CP_not bit */ + value &= ~(1 << 5); } + + /* start transfer */ + I2C2_SADDR = index; + I2C2_CNTRL &= ~(1 << 1); + I2C2_DATA = value; + I2C2_DACNT = 1; + + /* wait for transfer */ + while (I2C2_DACNT != 0); ascodec_unlock(); - return retval; + return 0; } @@ -140,21 +132,17 @@ int ascodec_read(unsigned int index) ascodec_lock(); - /* check if still busy */ - if (i2c_busy()) { - data = -1; - } - else { - /* start transfer */ - I2C2_SADDR = index; - I2C2_CNTRL |= (1 << 1); - I2C2_DACNT = 1; - - /* wait for transfer*/ - while (i2c_busy()); - - data = I2C2_DATA; - } + /* wait if still busy */ + while (i2c_busy()); + + /* start transfer */ + I2C2_SADDR = index; + I2C2_CNTRL |= (1 << 1); + I2C2_DACNT = 1; + + /* wait for transfer*/ + while (I2C2_DACNT != 0); + data = I2C2_DATA; ascodec_unlock(); -- cgit v1.2.3