diff options
author | Bertrik Sikken <bertrik@sikken.nl> | 2008-11-23 12:24:47 +0000 |
---|---|---|
committer | Bertrik Sikken <bertrik@sikken.nl> | 2008-11-23 12:24:47 +0000 |
commit | 763aacc3110b69c0431db2d3ed35c3b55589f780 (patch) | |
tree | bcf548fcd6f0301a3d6a9ca202a4c7a4fa624e7e /firmware/target | |
parent | baf4b6102d4fe270f963916084b818077e4688ee (diff) | |
download | rockbox-763aacc3110b69c0431db2d3ed35c3b55589f780.tar.gz rockbox-763aacc3110b69c0431db2d3ed35c3b55589f780.zip |
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
Diffstat (limited to 'firmware/target')
-rw-r--r-- | firmware/target/arm/as3525/as3525-codec.c | 70 |
1 files changed, 45 insertions, 25 deletions
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) | |||
75 | I2C2_SLAD0 = AS3514_I2C_ADDR << 1; | 75 | I2C2_SLAD0 = AS3514_I2C_ADDR << 1; |
76 | 76 | ||
77 | I2C2_CNTRL = 0x51; | 77 | I2C2_CNTRL = 0x51; |
78 | |||
79 | mutex_init(&as_mtx); | ||
78 | } | 80 | } |
79 | 81 | ||
80 | 82 | ||
@@ -88,46 +90,64 @@ static int i2c_busy(void) | |||
88 | /* returns 0 on success, <0 otherwise */ | 90 | /* returns 0 on success, <0 otherwise */ |
89 | int ascodec_write(unsigned int index, unsigned int value) | 91 | int ascodec_write(unsigned int index, unsigned int value) |
90 | { | 92 | { |
91 | if (index == 0x21) { | 93 | int retval; |
92 | /* prevent setting of the LREG_CP_not bit */ | 94 | |
93 | value &= ~(1 << 5); | 95 | ascodec_lock(); |
94 | } | 96 | |
95 | |||
96 | /* check if still busy */ | 97 | /* check if still busy */ |
97 | if (i2c_busy()) { | 98 | if (i2c_busy()) { |
98 | return -1; | 99 | retval = -1; |
100 | } | ||
101 | else { | ||
102 | if (index == AS3514_CVDD_DCDC3) { | ||
103 | /* prevent setting of the LREG_CP_not bit */ | ||
104 | value &= ~(1 << 5); | ||
105 | } | ||
106 | |||
107 | /* start transfer */ | ||
108 | I2C2_SADDR = index; | ||
109 | I2C2_CNTRL &= ~(1 << 1); | ||
110 | I2C2_DATA = value; | ||
111 | I2C2_DACNT = 1; | ||
112 | |||
113 | /* wait for transfer*/ | ||
114 | while (i2c_busy()); | ||
115 | |||
116 | retval = 0; | ||
99 | } | 117 | } |
100 | |||
101 | /* start transfer */ | ||
102 | I2C2_SADDR = index; | ||
103 | I2C2_CNTRL &= ~(1 << 1); | ||
104 | I2C2_DATA = value; | ||
105 | I2C2_DACNT = 1; | ||
106 | |||
107 | /* wait for transfer*/ | ||
108 | while (i2c_busy()); | ||
109 | 118 | ||
110 | return 0; | 119 | ascodec_unlock(); |
120 | |||
121 | return retval; | ||
111 | } | 122 | } |
112 | 123 | ||
113 | 124 | ||
114 | /* returns value read on success, <0 otherwise */ | 125 | /* returns value read on success, <0 otherwise */ |
115 | int ascodec_read(unsigned int index) | 126 | int ascodec_read(unsigned int index) |
116 | { | 127 | { |
128 | int data; | ||
129 | |||
130 | ascodec_lock(); | ||
131 | |||
117 | /* check if still busy */ | 132 | /* check if still busy */ |
118 | if (i2c_busy()) { | 133 | if (i2c_busy()) { |
119 | return -1; | 134 | data = -1; |
135 | } | ||
136 | else { | ||
137 | /* start transfer */ | ||
138 | I2C2_SADDR = index; | ||
139 | I2C2_CNTRL |= (1 << 1); | ||
140 | I2C2_DACNT = 1; | ||
141 | |||
142 | /* wait for transfer*/ | ||
143 | while (i2c_busy()); | ||
144 | |||
145 | data = I2C2_DATA; | ||
120 | } | 146 | } |
121 | 147 | ||
122 | /* start transfer */ | 148 | ascodec_unlock(); |
123 | I2C2_SADDR = index; | ||
124 | I2C2_CNTRL |= (1 << 1); | ||
125 | I2C2_DACNT = 1; | ||
126 | |||
127 | /* wait for transfer*/ | ||
128 | while (i2c_busy()); | ||
129 | 149 | ||
130 | return I2C2_DATA; | 150 | return data; |
131 | } | 151 | } |
132 | 152 | ||
133 | int ascodec_readbytes(int index, int len, unsigned char *data) | 153 | int ascodec_readbytes(int index, int len, unsigned char *data) |