2008-07-14 15:03:10 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 by Maurus Cuelenaere
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "jz4740.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "lcd-target.h"
|
2008-12-03 00:20:24 +00:00
|
|
|
#include "system.h"
|
2008-09-17 21:44:47 +00:00
|
|
|
#include "kernel.h"
|
2008-07-14 15:03:10 +00:00
|
|
|
|
|
|
|
static volatile bool _lcd_on = false;
|
|
|
|
static volatile bool lcd_poweroff = false;
|
2008-11-24 18:41:17 +00:00
|
|
|
static struct mutex lcd_mtx;
|
2008-07-14 15:03:10 +00:00
|
|
|
|
|
|
|
/* LCD init */
|
|
|
|
void lcd_init_device(void)
|
|
|
|
{
|
|
|
|
lcd_init_controller();
|
|
|
|
_lcd_on = true;
|
2008-11-24 18:41:17 +00:00
|
|
|
mutex_init(&lcd_mtx);
|
2008-07-14 15:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_enable(bool state)
|
|
|
|
{
|
|
|
|
if(state)
|
2008-08-06 21:07:45 +00:00
|
|
|
{
|
2008-07-14 15:03:10 +00:00
|
|
|
lcd_on();
|
2008-08-06 21:07:45 +00:00
|
|
|
lcd_call_enable_hook();
|
|
|
|
}
|
2008-07-14 15:03:10 +00:00
|
|
|
else
|
|
|
|
lcd_off();
|
|
|
|
|
|
|
|
_lcd_on = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lcd_enabled(void)
|
|
|
|
{
|
|
|
|
return _lcd_on;
|
|
|
|
}
|
|
|
|
|
2008-12-03 00:20:24 +00:00
|
|
|
/* Don't switch threads when in interrupt mode! */
|
|
|
|
static void lcd_lock(void)
|
|
|
|
{
|
|
|
|
if(LIKELY(!in_interrupt_mode()))
|
|
|
|
mutex_lock(&lcd_mtx);
|
|
|
|
else
|
|
|
|
while( !(REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_TT));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lcd_unlock(void)
|
|
|
|
{
|
|
|
|
if(LIKELY(!in_interrupt_mode()))
|
|
|
|
mutex_unlock(&lcd_mtx);
|
|
|
|
else
|
|
|
|
while( !(REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_TT));
|
|
|
|
}
|
|
|
|
|
2008-07-14 15:03:10 +00:00
|
|
|
/* Update a fraction of the display. */
|
|
|
|
void lcd_update_rect(int x, int y, int width, int height)
|
|
|
|
{
|
2008-12-03 00:20:24 +00:00
|
|
|
lcd_lock();
|
2008-11-24 18:41:17 +00:00
|
|
|
|
2008-08-15 14:39:39 +00:00
|
|
|
lcd_set_target(x, y, width, height);
|
2008-07-14 15:03:10 +00:00
|
|
|
|
2008-11-04 20:30:01 +00:00
|
|
|
REG_DMAC_DCCSR(DMA_LCD_CHANNEL) = 0;
|
2008-12-03 00:20:24 +00:00
|
|
|
REG_DMAC_DRSR(DMA_LCD_CHANNEL) = DMAC_DRSR_RS_SLCD; /* source = SLCD */
|
|
|
|
REG_DMAC_DSAR(DMA_LCD_CHANNEL) = ((unsigned int)&lcd_framebuffer[y][x]) & 0x1FFFFFFF;
|
|
|
|
REG_DMAC_DTAR(DMA_LCD_CHANNEL) = 0x130500B0; /* SLCD_FIFO */
|
|
|
|
REG_DMAC_DTCR(DMA_LCD_CHANNEL) = width*height;
|
2008-07-14 15:03:10 +00:00
|
|
|
|
2008-12-03 00:20:24 +00:00
|
|
|
REG_DMAC_DCMD(DMA_LCD_CHANNEL) = ( DMAC_DCMD_SAI | DMAC_DCMD_RDIL_IGN | DMAC_DCMD_SWDH_32
|
|
|
|
| DMAC_DCMD_DWDH_16 | DMAC_DCMD_DS_16BIT );
|
|
|
|
REG_DMAC_DCCSR(DMA_LCD_CHANNEL) = DMAC_DCCSR_NDES;
|
2008-07-14 15:03:10 +00:00
|
|
|
|
2008-12-03 00:20:24 +00:00
|
|
|
__dcache_writeback_all(); /* Size of framebuffer is way bigger than cache size;
|
|
|
|
we need to find a way to make the framebuffer uncached, so this statement can get removed. */
|
2008-07-14 15:03:10 +00:00
|
|
|
|
2008-09-17 21:44:47 +00:00
|
|
|
while(REG_SLCD_STATE & SLCD_STATE_BUSY);
|
|
|
|
|
2008-12-03 00:20:24 +00:00
|
|
|
REG_SLCD_CTRL |= SLCD_CTRL_DMA_EN;
|
2008-11-04 20:30:01 +00:00
|
|
|
REG_DMAC_DCCSR(DMA_LCD_CHANNEL) |= DMAC_DCCSR_EN;
|
2008-07-14 15:03:10 +00:00
|
|
|
|
2008-12-03 00:20:24 +00:00
|
|
|
if(LIKELY(!in_interrupt_mode()))
|
|
|
|
{
|
|
|
|
while( !(REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_TT) )
|
|
|
|
yield();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
while( !(REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_TT));
|
2008-09-17 21:44:47 +00:00
|
|
|
|
2008-11-04 20:30:01 +00:00
|
|
|
REG_DMAC_DCCSR(DMA_LCD_CHANNEL) &= ~DMAC_DCCSR_EN;
|
2008-07-16 15:29:03 +00:00
|
|
|
|
2008-09-17 21:44:47 +00:00
|
|
|
while(REG_SLCD_STATE & SLCD_STATE_BUSY);
|
2008-11-24 18:41:17 +00:00
|
|
|
|
2008-12-03 00:20:24 +00:00
|
|
|
REG_SLCD_CTRL &= ~SLCD_CTRL_DMA_EN;
|
|
|
|
|
|
|
|
lcd_unlock();
|
2008-07-14 15:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the display.
|
|
|
|
This must be called after all other LCD functions that change the display. */
|
|
|
|
void lcd_update(void)
|
|
|
|
{
|
|
|
|
if (!_lcd_on)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
|
|
|
|
}
|