From 763aacc3110b69c0431db2d3ed35c3b55589f780 Mon Sep 17 00:00:00 2001 From: Bertrik Sikken Date: Sun, 23 Nov 2008 12:24:47 +0000 Subject: Initialise mutex before using it in as3525-codec.c, also use mutex for single codec register accesses. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19187 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/as3525/as3525-codec.c | 70 ++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 25 deletions(-) (limited to 'firmware/target/arm/as3525/as3525-codec.c') diff --git a/firmware/target/arm/as3525/as3525-codec.c b/firmware/target/arm/as3525/as3525-codec.c index 86bce86c39..223b52df53 100644 --- a/firmware/target/arm/as3525/as3525-codec.c +++ b/firmware/target/arm/as3525/as3525-codec.c @@ -75,6 +75,8 @@ void ascodec_init(void) I2C2_SLAD0 = AS3514_I2C_ADDR << 1; I2C2_CNTRL = 0x51; + + mutex_init(&as_mtx); } @@ -88,46 +90,64 @@ static int i2c_busy(void) /* returns 0 on success, <0 otherwise */ int ascodec_write(unsigned int index, unsigned int value) { - if (index == 0x21) { - /* prevent setting of the LREG_CP_not bit */ - value &= ~(1 << 5); - } - + int retval; + + ascodec_lock(); + /* check if still busy */ if (i2c_busy()) { - return -1; + 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; } - - /* start transfer */ - I2C2_SADDR = index; - I2C2_CNTRL &= ~(1 << 1); - I2C2_DATA = value; - I2C2_DACNT = 1; - - /* wait for transfer*/ - while (i2c_busy()); - return 0; + ascodec_unlock(); + + return retval; } /* returns value read on success, <0 otherwise */ int ascodec_read(unsigned int index) { + int data; + + ascodec_lock(); + /* check if still busy */ if (i2c_busy()) { - return -1; + data = -1; + } + else { + /* start transfer */ + I2C2_SADDR = index; + I2C2_CNTRL |= (1 << 1); + I2C2_DACNT = 1; + + /* wait for transfer*/ + while (i2c_busy()); + + data = I2C2_DATA; } - /* start transfer */ - I2C2_SADDR = index; - I2C2_CNTRL |= (1 << 1); - I2C2_DACNT = 1; - - /* wait for transfer*/ - while (i2c_busy()); + ascodec_unlock(); - return I2C2_DATA; + return data; } int ascodec_readbytes(int index, int len, unsigned char *data) -- cgit v1.2.3