diff options
Diffstat (limited to 'firmware/target/coldfire')
-rw-r--r-- | firmware/target/coldfire/iriver/h300/lcd-h300.c | 100 |
1 files changed, 40 insertions, 60 deletions
diff --git a/firmware/target/coldfire/iriver/h300/lcd-h300.c b/firmware/target/coldfire/iriver/h300/lcd-h300.c index c415ed6c37..7e73ea3905 100644 --- a/firmware/target/coldfire/iriver/h300/lcd-h300.c +++ b/firmware/target/coldfire/iriver/h300/lcd-h300.c | |||
@@ -32,16 +32,23 @@ | |||
32 | #include "font.h" | 32 | #include "font.h" |
33 | #include "bidi.h" | 33 | #include "bidi.h" |
34 | 34 | ||
35 | static bool display_on = false; /* Is the display turned on? */ | ||
36 | static bool display_flipped = false; | ||
37 | static int xoffset = 0; /* Needed for flip */ | ||
38 | #ifndef BOOTLOADER | 35 | #ifndef BOOTLOADER |
36 | #define LCD_MUTEX_INIT() mutex_init(&lcd_mtx) | ||
37 | #define LCD_MUTEX_LOCK() mutex_lock(&lcd_mtx) | ||
38 | #define LCD_MUTEX_UNLOCK() mutex_unlock(&lcd_mtx) | ||
39 | static struct mutex lcd_mtx; /* The update functions use DMA and yield */ | 39 | static struct mutex lcd_mtx; /* The update functions use DMA and yield */ |
40 | |||
41 | unsigned long dma_addr IBSS_ATTR; | 40 | unsigned long dma_addr IBSS_ATTR; |
42 | unsigned int dma_len IBSS_ATTR; | 41 | unsigned int dma_len IBSS_ATTR; |
43 | volatile int dma_count IBSS_ATTR; | 42 | volatile int dma_count IBSS_ATTR; |
44 | #endif | 43 | #else |
44 | #define LCD_MUTEX_INIT() | ||
45 | #define LCD_MUTEX_LOCK() | ||
46 | #define LCD_MUTEX_UNLOCK() | ||
47 | #endif /* def BOOTLOADER */ | ||
48 | |||
49 | static bool display_on = false; /* Is the display turned on? */ | ||
50 | static bool display_flipped = false; | ||
51 | static int xoffset = 0; /* Needed for flip */ | ||
45 | 52 | ||
46 | /* register defines */ | 53 | /* register defines */ |
47 | #define R_START_OSC 0x00 | 54 | #define R_START_OSC 0x00 |
@@ -141,13 +148,9 @@ void lcd_set_flip(bool yesno) | |||
141 | 148 | ||
142 | if (display_on) | 149 | if (display_on) |
143 | { | 150 | { |
144 | #ifndef BOOTLOADER | 151 | LCD_MUTEX_LOCK(); |
145 | mutex_lock(&lcd_mtx); | ||
146 | #endif | ||
147 | flip_lcd(yesno); | 152 | flip_lcd(yesno); |
148 | #ifndef BOOTLOADER | 153 | LCD_MUTEX_UNLOCK(); |
149 | mutex_unlock(&lcd_mtx); | ||
150 | #endif | ||
151 | } | 154 | } |
152 | } | 155 | } |
153 | 156 | ||
@@ -270,13 +273,12 @@ void lcd_init_device(void) | |||
270 | 273 | ||
271 | #ifndef BOOTLOADER | 274 | #ifndef BOOTLOADER |
272 | DAR3 = 0xf0000002; /* Configure DMA channel 3 */ | 275 | DAR3 = 0xf0000002; /* Configure DMA channel 3 */ |
273 | DSR3 = 1; | 276 | DSR3 = 1; /* Clear all bits in the status register */ |
274 | DIVR3 = 57; /* DMA3 is mapped into vector 57 in system.c */ | 277 | DIVR3 = 57; /* DMA3 is mapped into vector 57 in system.c */ |
275 | ICR9 = (6 << 2); /* Enable DMA3 interrupt at level 6, priority 0 */ | 278 | ICR9 = (6 << 2); /* Enable DMA3 interrupt at level 6, priority 0 */ |
276 | coldfire_imr_mod(0, 1 << 17); | 279 | coldfire_imr_mod(0, 1 << 17); |
277 | |||
278 | mutex_init(&lcd_mtx); | ||
279 | #endif | 280 | #endif |
281 | LCD_MUTEX_INIT(); | ||
280 | _display_on(); | 282 | _display_on(); |
281 | } | 283 | } |
282 | 284 | ||
@@ -284,9 +286,7 @@ void lcd_enable(bool on) | |||
284 | { | 286 | { |
285 | if (display_on != on) | 287 | if (display_on != on) |
286 | { | 288 | { |
287 | #ifndef BOOTLOADER | 289 | LCD_MUTEX_LOCK(); |
288 | mutex_lock(&lcd_mtx); | ||
289 | #endif | ||
290 | if (on) | 290 | if (on) |
291 | { | 291 | { |
292 | _display_on(); | 292 | _display_on(); |
@@ -314,9 +314,7 @@ void lcd_enable(bool on) | |||
314 | 314 | ||
315 | display_on=false; | 315 | display_on=false; |
316 | } | 316 | } |
317 | #ifndef BOOTLOADER | 317 | LCD_MUTEX_UNLOCK(); |
318 | mutex_unlock(&lcd_mtx); | ||
319 | #endif | ||
320 | } | 318 | } |
321 | } | 319 | } |
322 | 320 | ||
@@ -352,9 +350,7 @@ void lcd_blit_yuv(unsigned char * const src[3], | |||
352 | if (!display_on) | 350 | if (!display_on) |
353 | return; | 351 | return; |
354 | 352 | ||
355 | #ifndef BOOTLOADER | 353 | LCD_MUTEX_LOCK(); |
356 | mutex_lock(&lcd_mtx); | ||
357 | #endif | ||
358 | width &= ~1; /* stay on the safe side */ | 354 | width &= ~1; /* stay on the safe side */ |
359 | height &= ~1; | 355 | height &= ~1; |
360 | 356 | ||
@@ -385,10 +381,9 @@ void lcd_blit_yuv(unsigned char * const src[3], | |||
385 | usrc += stride >> 1; | 381 | usrc += stride >> 1; |
386 | vsrc += stride >> 1; | 382 | vsrc += stride >> 1; |
387 | } | 383 | } |
388 | while (ysrc < ysrc_max); | 384 | while (ysrc < ysrc_max) |
389 | #ifndef BOOTLOADER | 385 | ;; |
390 | mutex_unlock(&lcd_mtx); | 386 | LCD_MUTEX_UNLOCK(); |
391 | #endif | ||
392 | } | 387 | } |
393 | 388 | ||
394 | #ifndef BOOTLOADER | 389 | #ifndef BOOTLOADER |
@@ -396,7 +391,7 @@ void lcd_blit_yuv(unsigned char * const src[3], | |||
396 | void DMA3(void) __attribute__ ((interrupt_handler, section(".icode"))); | 391 | void DMA3(void) __attribute__ ((interrupt_handler, section(".icode"))); |
397 | void DMA3(void) | 392 | void DMA3(void) |
398 | { | 393 | { |
399 | DSR3 = 1; | 394 | DSR3 = 1; /* Clear all bits in the status register */ |
400 | if (--dma_count > 0) | 395 | if (--dma_count > 0) |
401 | { | 396 | { |
402 | dma_addr += LCD_WIDTH*sizeof(fb_data); | 397 | dma_addr += LCD_WIDTH*sizeof(fb_data); |
@@ -415,9 +410,7 @@ void lcd_update(void) | |||
415 | { | 410 | { |
416 | if (display_on) | 411 | if (display_on) |
417 | { | 412 | { |
418 | #ifndef BOOTLOADER | 413 | LCD_MUTEX_LOCK(); |
419 | mutex_lock(&lcd_mtx); | ||
420 | #endif | ||
421 | 414 | ||
422 | lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_VERT); | 415 | lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_VERT); |
423 | /* set start position window */ | 416 | /* set start position window */ |
@@ -437,25 +430,33 @@ void lcd_update(void) | |||
437 | 430 | ||
438 | while (dma_count > 0) | 431 | while (dma_count > 0) |
439 | yield(); | 432 | yield(); |
440 | |||
441 | mutex_unlock(&lcd_mtx); | ||
442 | #else | 433 | #else |
443 | DAR3 = 0xf0000002; | 434 | DAR3 = 0xf0000002; |
435 | DSR3 = 1; /* Clear all bits in the status register */ | ||
444 | SAR3 = (unsigned long)FBADDR(0, 0); | 436 | SAR3 = (unsigned long)FBADDR(0, 0); |
445 | BCR3 = LCD_WIDTH*LCD_HEIGHT*sizeof(fb_data); | 437 | BCR3 = LCD_WIDTH*LCD_HEIGHT*sizeof(fb_data); |
446 | DCR3 = DMA_AA | DMA_BWC(1) | 438 | DCR3 = DMA_AA | DMA_BWC(1) |
447 | | DMA_SINC | DMA_SSIZE(DMA_SIZE_LINE) | 439 | | DMA_SINC | DMA_SSIZE(DMA_SIZE_LINE) |
448 | | DMA_DSIZE(DMA_SIZE_WORD) | DMA_START; | 440 | | DMA_DSIZE(DMA_SIZE_WORD) | DMA_START; |
449 | 441 | ||
450 | while (!(DSR3 & 1)); | 442 | while (!(DSR3 & 1)) |
451 | DSR3 = 1; | 443 | ;; |
444 | DSR3 = 1; /* Clear all bits in the status register */ | ||
452 | #endif | 445 | #endif |
446 | LCD_MUTEX_UNLOCK(); | ||
453 | } | 447 | } |
454 | } | 448 | } |
455 | 449 | ||
456 | /* Update a fraction of the display. */ | 450 | /* Update a fraction of the display. */ |
457 | void lcd_update_rect(int x, int y, int width, int height) | 451 | void lcd_update_rect(int x, int y, int width, int height) |
458 | { | 452 | { |
453 | #ifdef BOOTLOADER | ||
454 | (void)x; | ||
455 | (void)y; | ||
456 | (void)width; | ||
457 | (void)height; | ||
458 | lcd_update(); /* in bootloader -- all or nothing */ | ||
459 | #else | ||
459 | if (display_on) | 460 | if (display_on) |
460 | { | 461 | { |
461 | if (x + width > LCD_WIDTH) | 462 | if (x + width > LCD_WIDTH) |
@@ -466,9 +467,7 @@ void lcd_update_rect(int x, int y, int width, int height) | |||
466 | if (width <= 0 || height <= 0) /* nothing to do */ | 467 | if (width <= 0 || height <= 0) /* nothing to do */ |
467 | return; | 468 | return; |
468 | 469 | ||
469 | #ifndef BOOTLOADER | 470 | LCD_MUTEX_LOCK(); |
470 | mutex_lock(&lcd_mtx); | ||
471 | #endif | ||
472 | 471 | ||
473 | lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_VERT); | 472 | lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_VERT); |
474 | /* set update window */ | 473 | /* set update window */ |
@@ -477,8 +476,7 @@ void lcd_update_rect(int x, int y, int width, int height) | |||
477 | lcd_write_reg(R_RAM_ADDR_SET, ((x+xoffset) << 8) | y); | 476 | lcd_write_reg(R_RAM_ADDR_SET, ((x+xoffset) << 8) | y); |
478 | 477 | ||
479 | lcd_begin_write_gram(); | 478 | lcd_begin_write_gram(); |
480 | 479 | ||
481 | #ifndef BOOTLOADER | ||
482 | if (width == LCD_WIDTH) | 480 | if (width == LCD_WIDTH) |
483 | { | 481 | { |
484 | dma_count = 1; | 482 | dma_count = 1; |
@@ -498,25 +496,7 @@ void lcd_update_rect(int x, int y, int width, int height) | |||
498 | while (dma_count > 0) | 496 | while (dma_count > 0) |
499 | yield(); | 497 | yield(); |
500 | 498 | ||
501 | mutex_unlock(&lcd_mtx); | 499 | LCD_MUTEX_UNLOCK(); |
502 | #else | ||
503 | DAR3 = 0xf0000002; | ||
504 | unsigned long dma_addr = (unsigned long)FBADDR(x, y); | ||
505 | width *= sizeof(fb_data); | ||
506 | |||
507 | for (; height > 0; height--) | ||
508 | { | ||
509 | SAR3 = dma_addr; | ||
510 | BCR3 = width; | ||
511 | DCR3 = DMA_AA | DMA_BWC(1) | ||
512 | | DMA_SINC | DMA_SSIZE(DMA_SIZE_LINE) | ||
513 | | DMA_DSIZE(DMA_SIZE_WORD) | DMA_START; | ||
514 | |||
515 | dma_addr += LCD_WIDTH*sizeof(fb_data); | ||
516 | |||
517 | while (!(DSR3 & 1)); | ||
518 | DSR3 = 1; | ||
519 | } | ||
520 | #endif | ||
521 | } | 500 | } |
501 | #endif /* ndef BOOTLOADER */ | ||
522 | } | 502 | } |