summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/target/arm/as3525/ascodec-as3525.c66
1 files changed, 27 insertions, 39 deletions
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)
97 return (I2C2_SR & 1); 97 return (I2C2_SR & 1);
98} 98}
99 99
100
101/* returns 0 on success, <0 otherwise */ 100/* returns 0 on success, <0 otherwise */
102int ascodec_write(unsigned int index, unsigned int value) 101int ascodec_write(unsigned int index, unsigned int value)
103{ 102{
104 int retval;
105
106 ascodec_lock(); 103 ascodec_lock();
107 104
108 /* check if still busy */ 105 /* wait if still busy */
109 if (i2c_busy()) { 106 while (i2c_busy());
110 retval = -1; 107
111 } 108 if (index == AS3514_CVDD_DCDC3) {
112 else { 109 /* prevent setting of the LREG_CP_not bit */
113 if (index == AS3514_CVDD_DCDC3) { 110 value &= ~(1 << 5);
114 /* prevent setting of the LREG_CP_not bit */
115 value &= ~(1 << 5);
116 }
117
118 /* start transfer */
119 I2C2_SADDR = index;
120 I2C2_CNTRL &= ~(1 << 1);
121 I2C2_DATA = value;
122 I2C2_DACNT = 1;
123
124 /* wait for transfer*/
125 while (i2c_busy());
126
127 retval = 0;
128 } 111 }
112
113 /* start transfer */
114 I2C2_SADDR = index;
115 I2C2_CNTRL &= ~(1 << 1);
116 I2C2_DATA = value;
117 I2C2_DACNT = 1;
118
119 /* wait for transfer */
120 while (I2C2_DACNT != 0);
129 121
130 ascodec_unlock(); 122 ascodec_unlock();
131 123
132 return retval; 124 return 0;
133} 125}
134 126
135 127
@@ -140,21 +132,17 @@ int ascodec_read(unsigned int index)
140 132
141 ascodec_lock(); 133 ascodec_lock();
142 134
143 /* check if still busy */ 135 /* wait if still busy */
144 if (i2c_busy()) { 136 while (i2c_busy());
145 data = -1; 137
146 } 138 /* start transfer */
147 else { 139 I2C2_SADDR = index;
148 /* start transfer */ 140 I2C2_CNTRL |= (1 << 1);
149 I2C2_SADDR = index; 141 I2C2_DACNT = 1;
150 I2C2_CNTRL |= (1 << 1); 142
151 I2C2_DACNT = 1; 143 /* wait for transfer*/
152 144 while (I2C2_DACNT != 0);
153 /* wait for transfer*/ 145 data = I2C2_DATA;
154 while (i2c_busy());
155
156 data = I2C2_DATA;
157 }
158 146
159 ascodec_unlock(); 147 ascodec_unlock();
160 148