mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-09 05:05:20 -05:00
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
This commit is contained in:
parent
baf4b6102d
commit
763aacc311
1 changed files with 45 additions and 25 deletions
|
|
@ -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;
|
||||
ascodec_unlock();
|
||||
|
||||
/* wait for transfer*/
|
||||
while (i2c_busy());
|
||||
|
||||
return I2C2_DATA;
|
||||
return data;
|
||||
}
|
||||
|
||||
int ascodec_readbytes(int index, int len, unsigned char *data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue