diff options
Diffstat (limited to 'firmware/target/arm')
-rw-r--r-- | firmware/target/arm/i2c-pp.c | 25 | ||||
-rw-r--r-- | firmware/target/arm/sandisk/adc-c200_e200.c | 4 |
2 files changed, 19 insertions, 10 deletions
diff --git a/firmware/target/arm/i2c-pp.c b/firmware/target/arm/i2c-pp.c index 69bc60e672..b8e3869907 100644 --- a/firmware/target/arm/i2c-pp.c +++ b/firmware/target/arm/i2c-pp.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include "as3514.h" | 33 | #include "as3514.h" |
34 | 34 | ||
35 | /* Local functions definitions */ | 35 | /* Local functions definitions */ |
36 | static struct mutex i2c_mtx NOCACHEBSS_ATTR; | ||
36 | 37 | ||
37 | #define POLL_TIMEOUT (HZ) | 38 | #define POLL_TIMEOUT (HZ) |
38 | 39 | ||
@@ -133,18 +134,26 @@ static int pp_i2c_send_byte(unsigned int addr, int data0) | |||
133 | } | 134 | } |
134 | 135 | ||
135 | /* Public functions */ | 136 | /* Public functions */ |
136 | struct spinlock i2c_spin NOCACHEBSS_ATTR; | 137 | void i2c_lock(void) |
138 | { | ||
139 | mutex_lock(&i2c_mtx); | ||
140 | } | ||
141 | |||
142 | void i2c_unlock(void) | ||
143 | { | ||
144 | mutex_unlock(&i2c_mtx); | ||
145 | } | ||
137 | 146 | ||
138 | int i2c_readbytes(unsigned int dev_addr, int addr, int len, unsigned char *data) { | 147 | int i2c_readbytes(unsigned int dev_addr, int addr, int len, unsigned char *data) { |
139 | unsigned int temp; | 148 | unsigned int temp; |
140 | int i; | 149 | int i; |
141 | spinlock_lock(&i2c_spin); | 150 | mutex_lock(&i2c_mtx); |
142 | pp_i2c_send_byte(dev_addr, addr); | 151 | pp_i2c_send_byte(dev_addr, addr); |
143 | for (i = 0; i < len; i++) { | 152 | for (i = 0; i < len; i++) { |
144 | pp_i2c_read_byte(dev_addr, &temp); | 153 | pp_i2c_read_byte(dev_addr, &temp); |
145 | data[i] = temp; | 154 | data[i] = temp; |
146 | } | 155 | } |
147 | spinlock_unlock(&i2c_spin); | 156 | mutex_unlock(&i2c_mtx); |
148 | return i; | 157 | return i; |
149 | } | 158 | } |
150 | 159 | ||
@@ -152,10 +161,10 @@ int i2c_readbyte(unsigned int dev_addr, int addr) | |||
152 | { | 161 | { |
153 | int data; | 162 | int data; |
154 | 163 | ||
155 | spinlock_lock(&i2c_spin); | 164 | mutex_lock(&i2c_mtx); |
156 | pp_i2c_send_byte(dev_addr, addr); | 165 | pp_i2c_send_byte(dev_addr, addr); |
157 | pp_i2c_read_byte(dev_addr, &data); | 166 | pp_i2c_read_byte(dev_addr, &data); |
158 | spinlock_unlock(&i2c_spin); | 167 | mutex_unlock(&i2c_mtx); |
159 | 168 | ||
160 | return data; | 169 | return data; |
161 | } | 170 | } |
@@ -168,9 +177,9 @@ int pp_i2c_send(unsigned int addr, int data0, int data1) | |||
168 | data[0] = data0; | 177 | data[0] = data0; |
169 | data[1] = data1; | 178 | data[1] = data1; |
170 | 179 | ||
171 | spinlock_lock(&i2c_spin); | 180 | mutex_lock(&i2c_mtx); |
172 | retval = pp_i2c_send_bytes(addr, 2, data); | 181 | retval = pp_i2c_send_bytes(addr, 2, data); |
173 | spinlock_unlock(&i2c_spin); | 182 | mutex_unlock(&i2c_mtx); |
174 | 183 | ||
175 | return retval; | 184 | return retval; |
176 | } | 185 | } |
@@ -222,7 +231,7 @@ void i2c_init(void) | |||
222 | #endif | 231 | #endif |
223 | #endif | 232 | #endif |
224 | 233 | ||
225 | spinlock_init(&i2c_spin IF_COP(, SPINLOCK_TASK_SWITCH)); | 234 | mutex_init(&i2c_mtx); |
226 | 235 | ||
227 | i2c_readbyte(0x8, 0); | 236 | i2c_readbyte(0x8, 0); |
228 | } | 237 | } |
diff --git a/firmware/target/arm/sandisk/adc-c200_e200.c b/firmware/target/arm/sandisk/adc-c200_e200.c index 9dc8f3aabb..fd07812cfb 100644 --- a/firmware/target/arm/sandisk/adc-c200_e200.c +++ b/firmware/target/arm/sandisk/adc-c200_e200.c | |||
@@ -28,7 +28,7 @@ unsigned short adc_read(int channel) | |||
28 | 28 | ||
29 | if ((unsigned)channel < NUM_ADC_CHANNELS) | 29 | if ((unsigned)channel < NUM_ADC_CHANNELS) |
30 | { | 30 | { |
31 | spinlock_lock(&i2c_spin); | 31 | i2c_lock(); |
32 | 32 | ||
33 | /* Select channel */ | 33 | /* Select channel */ |
34 | if (pp_i2c_send( AS3514_I2C_ADDR, ADC_0, (channel << 4)) >= 0) | 34 | if (pp_i2c_send( AS3514_I2C_ADDR, ADC_0, (channel << 4)) >= 0) |
@@ -42,7 +42,7 @@ unsigned short adc_read(int channel) | |||
42 | } | 42 | } |
43 | } | 43 | } |
44 | 44 | ||
45 | spinlock_unlock(&i2c_spin); | 45 | i2c_unlock(); |
46 | } | 46 | } |
47 | 47 | ||
48 | return data; | 48 | return data; |