diff options
-rw-r--r-- | firmware/export/mc13783.h | 4 | ||||
-rw-r--r-- | firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c | 62 |
2 files changed, 20 insertions, 46 deletions
diff --git a/firmware/export/mc13783.h b/firmware/export/mc13783.h index eede1cd307..32b788544e 100644 --- a/firmware/export/mc13783.h +++ b/firmware/export/mc13783.h | |||
@@ -1281,12 +1281,12 @@ uint32_t mc13783_set(unsigned address, uint32_t bits); | |||
1281 | uint32_t mc13783_clear(unsigned address, uint32_t bits); | 1281 | uint32_t mc13783_clear(unsigned address, uint32_t bits); |
1282 | int mc13783_write(unsigned address, uint32_t data); | 1282 | int mc13783_write(unsigned address, uint32_t data); |
1283 | uint32_t mc13783_write_masked(unsigned address, uint32_t data, uint32_t mask); | 1283 | uint32_t mc13783_write_masked(unsigned address, uint32_t data, uint32_t mask); |
1284 | int mc13783_write_multiple(unsigned start, const uint32_t *buffer, int count); | ||
1285 | int mc13783_write_regset(const unsigned char *regs, const uint32_t *data, int count); | 1284 | int mc13783_write_regset(const unsigned char *regs, const uint32_t *data, int count); |
1286 | uint32_t mc13783_read(unsigned address); | 1285 | uint32_t mc13783_read(unsigned address); |
1287 | int mc13783_read_multiple(unsigned start, uint32_t *buffer, int count); | ||
1288 | int mc13783_read_regset(const unsigned char *regs, uint32_t *buffer, int count); | 1286 | int mc13783_read_regset(const unsigned char *regs, uint32_t *buffer, int count); |
1289 | 1287 | ||
1288 | #define MC13783_DATA_ERROR UINT32_MAX | ||
1289 | |||
1290 | /* Statically-registered event enable/disable */ | 1290 | /* Statically-registered event enable/disable */ |
1291 | enum mc13783_event_sets | 1291 | enum mc13783_event_sets |
1292 | { | 1292 | { |
diff --git a/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c b/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c index 8cd2ea87f6..c185994bfc 100644 --- a/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c +++ b/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c | |||
@@ -210,7 +210,7 @@ uint32_t mc13783_set(unsigned address, uint32_t bits) | |||
210 | 210 | ||
211 | uint32_t data = mc13783_read(address); | 211 | uint32_t data = mc13783_read(address); |
212 | 212 | ||
213 | if (data != (uint32_t)-1) | 213 | if (data != MC13783_DATA_ERROR) |
214 | mc13783_write(address, data | bits); | 214 | mc13783_write(address, data | bits); |
215 | 215 | ||
216 | spi_unlock(&mc13783_spi); | 216 | spi_unlock(&mc13783_spi); |
@@ -224,7 +224,7 @@ uint32_t mc13783_clear(unsigned address, uint32_t bits) | |||
224 | 224 | ||
225 | uint32_t data = mc13783_read(address); | 225 | uint32_t data = mc13783_read(address); |
226 | 226 | ||
227 | if (data != (uint32_t)-1) | 227 | if (data != MC13783_DATA_ERROR) |
228 | mc13783_write(address, data & ~bits); | 228 | mc13783_write(address, data & ~bits); |
229 | 229 | ||
230 | spi_unlock(&mc13783_spi); | 230 | spi_unlock(&mc13783_spi); |
@@ -251,29 +251,25 @@ int mc13783_write(unsigned address, uint32_t data) | |||
251 | return 1 - xfer.count; | 251 | return 1 - xfer.count; |
252 | } | 252 | } |
253 | 253 | ||
254 | int mc13783_write_multiple(unsigned start, const uint32_t *data, int count) | 254 | uint32_t mc13783_write_masked(unsigned address, uint32_t data, uint32_t mask) |
255 | { | 255 | { |
256 | int i; | 256 | uint32_t old; |
257 | struct spi_transfer xfer; | ||
258 | uint32_t packets[MC13783_NUM_REGS]; | ||
259 | 257 | ||
260 | if (start + count > MC13783_NUM_REGS) | 258 | spi_lock(&mc13783_spi); |
261 | return -1; | 259 | |
260 | old = mc13783_read(address); | ||
262 | 261 | ||
263 | /* Prepare payload */ | 262 | if (old != MC13783_DATA_ERROR) |
264 | for (i = 0; i < count; i++, start++) | ||
265 | { | 263 | { |
266 | packets[i] = (1 << 31) | (start << 25) | (data[i] & 0xffffff); | 264 | data = (old & ~mask) | (data & mask); |
265 | |||
266 | if (mc13783_write(address, data) != 1) | ||
267 | old = MC13783_DATA_ERROR; | ||
267 | } | 268 | } |
268 | 269 | ||
269 | xfer.txbuf = packets; | 270 | spi_unlock(&mc13783_spi); |
270 | xfer.rxbuf = packets; | ||
271 | xfer.count = count; | ||
272 | |||
273 | if (!spi_transfer(&mc13783_spi, &xfer)) | ||
274 | return -1; | ||
275 | 271 | ||
276 | return count - xfer.count; | 272 | return old; |
277 | } | 273 | } |
278 | 274 | ||
279 | int mc13783_write_regset(const unsigned char *regs, const uint32_t *data, | 275 | int mc13783_write_regset(const unsigned char *regs, const uint32_t *data, |
@@ -283,7 +279,7 @@ int mc13783_write_regset(const unsigned char *regs, const uint32_t *data, | |||
283 | struct spi_transfer xfer; | 279 | struct spi_transfer xfer; |
284 | uint32_t packets[MC13783_NUM_REGS]; | 280 | uint32_t packets[MC13783_NUM_REGS]; |
285 | 281 | ||
286 | if (count > MC13783_NUM_REGS) | 282 | if ((unsigned)count > MC13783_NUM_REGS) |
287 | return -1; | 283 | return -1; |
288 | 284 | ||
289 | for (i = 0; i < count; i++) | 285 | for (i = 0; i < count; i++) |
@@ -312,7 +308,7 @@ uint32_t mc13783_read(unsigned address) | |||
312 | struct spi_transfer xfer; | 308 | struct spi_transfer xfer; |
313 | 309 | ||
314 | if (address >= MC13783_NUM_REGS) | 310 | if (address >= MC13783_NUM_REGS) |
315 | return (uint32_t)-1; | 311 | return MC13783_DATA_ERROR; |
316 | 312 | ||
317 | packet = address << 25; | 313 | packet = address << 25; |
318 | 314 | ||
@@ -321,40 +317,18 @@ uint32_t mc13783_read(unsigned address) | |||
321 | xfer.count = 1; | 317 | xfer.count = 1; |
322 | 318 | ||
323 | if (!spi_transfer(&mc13783_spi, &xfer)) | 319 | if (!spi_transfer(&mc13783_spi, &xfer)) |
324 | return (uint32_t)-1; | 320 | return MC13783_DATA_ERROR; |
325 | 321 | ||
326 | return packet; | 322 | return packet; |
327 | } | 323 | } |
328 | 324 | ||
329 | int mc13783_read_multiple(unsigned start, uint32_t *buffer, int count) | ||
330 | { | ||
331 | int i; | ||
332 | struct spi_transfer xfer; | ||
333 | |||
334 | if (start + count > MC13783_NUM_REGS) | ||
335 | return -1; | ||
336 | |||
337 | xfer.txbuf = buffer; | ||
338 | xfer.rxbuf = buffer; | ||
339 | xfer.count = count; | ||
340 | |||
341 | /* Prepare TX payload */ | ||
342 | for (i = 0; i < count; i++, start++) | ||
343 | buffer[i] = start << 25; | ||
344 | |||
345 | if (!spi_transfer(&mc13783_spi, &xfer)) | ||
346 | return -1; | ||
347 | |||
348 | return count - xfer.count; | ||
349 | } | ||
350 | |||
351 | int mc13783_read_regset(const unsigned char *regs, uint32_t *buffer, | 325 | int mc13783_read_regset(const unsigned char *regs, uint32_t *buffer, |
352 | int count) | 326 | int count) |
353 | { | 327 | { |
354 | int i; | 328 | int i; |
355 | struct spi_transfer xfer; | 329 | struct spi_transfer xfer; |
356 | 330 | ||
357 | if (count > MC13783_NUM_REGS) | 331 | if ((unsigned)count > MC13783_NUM_REGS) |
358 | return -1; | 332 | return -1; |
359 | 333 | ||
360 | for (i = 0; i < count; i++) | 334 | for (i = 0; i < count; i++) |