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
This commit is contained in:
Bertrik Sikken 2009-05-31 17:48:19 +00:00
parent 29d7db4a46
commit 9067c915ad

View file

@ -97,19 +97,14 @@ static int i2c_busy(void)
return (I2C2_SR & 1); return (I2C2_SR & 1);
} }
/* returns 0 on success, <0 otherwise */ /* returns 0 on success, <0 otherwise */
int ascodec_write(unsigned int index, unsigned int value) int ascodec_write(unsigned int index, unsigned int value)
{ {
int retval;
ascodec_lock(); ascodec_lock();
/* check if still busy */ /* wait if still busy */
if (i2c_busy()) { while (i2c_busy());
retval = -1;
}
else {
if (index == AS3514_CVDD_DCDC3) { if (index == AS3514_CVDD_DCDC3) {
/* prevent setting of the LREG_CP_not bit */ /* prevent setting of the LREG_CP_not bit */
value &= ~(1 << 5); value &= ~(1 << 5);
@ -122,14 +117,11 @@ int ascodec_write(unsigned int index, unsigned int value)
I2C2_DACNT = 1; I2C2_DACNT = 1;
/* wait for transfer */ /* wait for transfer */
while (i2c_busy()); while (I2C2_DACNT != 0);
retval = 0;
}
ascodec_unlock(); ascodec_unlock();
return retval; return 0;
} }
@ -140,21 +132,17 @@ int ascodec_read(unsigned int index)
ascodec_lock(); ascodec_lock();
/* check if still busy */ /* wait if still busy */
if (i2c_busy()) { while (i2c_busy());
data = -1;
}
else {
/* start transfer */ /* start transfer */
I2C2_SADDR = index; I2C2_SADDR = index;
I2C2_CNTRL |= (1 << 1); I2C2_CNTRL |= (1 << 1);
I2C2_DACNT = 1; I2C2_DACNT = 1;
/* wait for transfer*/ /* wait for transfer*/
while (i2c_busy()); while (I2C2_DACNT != 0);
data = I2C2_DATA; data = I2C2_DATA;
}
ascodec_unlock(); ascodec_unlock();