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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2010-05-06 21:04:40 +00:00
|
|
|
#include <sys/types.h> /* off_t */
|
2009-08-19 22:15:45 +00:00
|
|
|
|
2008-07-14 15:03:10 +00:00
|
|
|
#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-12-20 01:48:46 +00:00
|
|
|
|
|
|
|
/*
|
2009-03-09 22:17:37 +00:00
|
|
|
Warning: code behaviour is unpredictable when switch_thread() gets called in IRQ mode!
|
2008-12-20 01:48:46 +00:00
|
|
|
So don't update the LCD in an interrupt handler!
|
|
|
|
*/
|
2008-07-14 15:03:10 +00:00
|
|
|
|
2008-12-04 18:26:19 +00:00
|
|
|
static volatile bool lcd_is_on = false;
|
2008-11-24 18:41:17 +00:00
|
|
|
static struct mutex lcd_mtx;
|
2008-12-20 01:48:46 +00:00
|
|
|
static struct wakeup lcd_wkup;
|
2010-01-03 16:28:15 +00:00
|
|
|
static int lcd_count = 0;
|
|
|
|
|
|
|
|
void lcd_clock_enable(void)
|
|
|
|
{
|
|
|
|
if(++lcd_count == 1)
|
|
|
|
__cpm_start_lcd();
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_clock_disable(void)
|
|
|
|
{
|
|
|
|
if(--lcd_count == 0)
|
|
|
|
__cpm_stop_lcd();
|
|
|
|
}
|
2008-07-14 15:03:10 +00:00
|
|
|
|
|
|
|
/* LCD init */
|
|
|
|
void lcd_init_device(void)
|
|
|
|
{
|
|
|
|
lcd_init_controller();
|
2009-03-09 22:17:37 +00:00
|
|
|
|
2008-12-04 18:26:19 +00:00
|
|
|
lcd_is_on = true;
|
2008-11-24 18:41:17 +00:00
|
|
|
mutex_init(&lcd_mtx);
|
2008-12-20 01:48:46 +00:00
|
|
|
wakeup_init(&lcd_wkup);
|
|
|
|
system_enable_irq(DMA_IRQ(DMA_LCD_CHANNEL));
|
2008-07-14 15:03:10 +00:00
|
|
|
}
|
|
|
|
|
2010-01-03 15:57:09 +00:00
|
|
|
#ifdef HAVE_LCD_ENABLE
|
2008-07-14 15:03:10 +00:00
|
|
|
void lcd_enable(bool state)
|
|
|
|
{
|
2010-01-03 15:57:09 +00:00
|
|
|
if(lcd_is_on == state)
|
|
|
|
return;
|
|
|
|
|
2008-07-14 15:03:10 +00:00
|
|
|
if(state)
|
2008-08-06 21:07:45 +00:00
|
|
|
{
|
2008-07-14 15:03:10 +00:00
|
|
|
lcd_on();
|
2009-10-20 21:54:59 +00:00
|
|
|
send_event(LCD_EVENT_ACTIVATION, NULL);
|
2008-08-06 21:07:45 +00:00
|
|
|
}
|
2008-07-14 15:03:10 +00:00
|
|
|
else
|
|
|
|
lcd_off();
|
2010-01-03 15:57:09 +00:00
|
|
|
|
2008-12-04 18:26:19 +00:00
|
|
|
lcd_is_on = state;
|
2008-07-14 15:03:10 +00:00
|
|
|
}
|
2010-01-03 15:57:09 +00:00
|
|
|
#endif
|
2008-07-14 15:03:10 +00:00
|
|
|
|
2009-03-17 02:43:47 +00:00
|
|
|
bool lcd_active(void)
|
2008-07-14 15:03:10 +00:00
|
|
|
{
|
2008-12-04 18:26:19 +00:00
|
|
|
return lcd_is_on;
|
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)
|
|
|
|
{
|
2009-05-20 12:43:23 +00:00
|
|
|
/* Currently only do updates with full LCD width.
|
|
|
|
* DMA can't handle full partial updates and CPU is too slow compared
|
|
|
|
* to DMA updates */
|
2009-04-18 17:38:55 +00:00
|
|
|
x = 0;
|
|
|
|
width = LCD_WIDTH;
|
|
|
|
|
2008-12-20 01:48:46 +00:00
|
|
|
mutex_lock(&lcd_mtx);
|
2008-11-24 18:41:17 +00:00
|
|
|
|
2010-01-03 16:28:15 +00:00
|
|
|
lcd_clock_enable();
|
2008-12-20 01:57:55 +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-12-20 01:48:46 +00:00
|
|
|
dma_enable();
|
|
|
|
|
|
|
|
REG_DMAC_DCCSR(DMA_LCD_CHANNEL) = DMAC_DCCSR_NDES;
|
|
|
|
REG_DMAC_DSAR(DMA_LCD_CHANNEL) = PHYSADDR((unsigned long)&lcd_framebuffer[y][x]);
|
2009-04-18 17:38:55 +00:00
|
|
|
REG_DMAC_DRSR(DMA_LCD_CHANNEL) = DMAC_DRSR_RS_SLCD;
|
2008-12-20 01:48:46 +00:00
|
|
|
REG_DMAC_DTAR(DMA_LCD_CHANNEL) = PHYSADDR(SLCD_FIFO);
|
2009-04-18 17:38:55 +00:00
|
|
|
REG_DMAC_DTCR(DMA_LCD_CHANNEL) = (width * height) >> 3;
|
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
|
2009-04-18 17:38:55 +00:00
|
|
|
| DMAC_DCMD_DWDH_16 | DMAC_DCMD_DS_16BYTE );
|
2008-07-14 15:03:10 +00:00
|
|
|
|
2008-12-20 01:48:46 +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-20 01:48:46 +00:00
|
|
|
REG_SLCD_CTRL |= SLCD_CTRL_DMA_EN; /* Enable SLCD DMA support */
|
2008-09-17 21:44:47 +00:00
|
|
|
|
2008-12-20 01:48:46 +00:00
|
|
|
REG_DMAC_DCCSR(DMA_LCD_CHANNEL) |= DMAC_DCCSR_EN; /* Enable DMA channel */
|
|
|
|
REG_DMAC_DCMD(DMA_LCD_CHANNEL) |= DMAC_DCMD_TIE; /* Enable DMA interrupt */
|
2008-07-14 15:03:10 +00:00
|
|
|
|
2009-01-21 20:58:33 +00:00
|
|
|
wakeup_wait(&lcd_wkup, TIMEOUT_BLOCK); /* Sleeping in lcd_update() should be safe */
|
2008-12-20 01:48:46 +00:00
|
|
|
|
|
|
|
REG_DMAC_DCCSR(DMA_LCD_CHANNEL) &= ~DMAC_DCCSR_EN; /* Disable DMA channel */
|
|
|
|
dma_disable();
|
2008-07-16 15:29:03 +00:00
|
|
|
|
2008-09-17 21:44:47 +00:00
|
|
|
while(REG_SLCD_STATE & SLCD_STATE_BUSY);
|
2008-12-20 01:48:46 +00:00
|
|
|
REG_SLCD_CTRL &= ~SLCD_CTRL_DMA_EN; /* Disable SLCD DMA support */
|
2008-11-24 18:41:17 +00:00
|
|
|
|
2010-01-03 16:28:15 +00:00
|
|
|
lcd_clock_disable();
|
2008-12-20 01:57:55 +00:00
|
|
|
|
2008-12-20 01:48:46 +00:00
|
|
|
mutex_unlock(&lcd_mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DMA_CALLBACK(DMA_LCD_CHANNEL)(void)
|
|
|
|
{
|
|
|
|
if (REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_HLT)
|
|
|
|
REG_DMAC_DCCSR(DMA_LCD_CHANNEL) &= ~DMAC_DCCSR_HLT;
|
|
|
|
|
|
|
|
if (REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_AR)
|
|
|
|
REG_DMAC_DCCSR(DMA_LCD_CHANNEL) &= ~DMAC_DCCSR_AR;
|
|
|
|
|
|
|
|
if (REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_CT)
|
|
|
|
REG_DMAC_DCCSR(DMA_LCD_CHANNEL) &= ~DMAC_DCCSR_CT;
|
|
|
|
|
|
|
|
if (REG_DMAC_DCCSR(DMA_LCD_CHANNEL) & DMAC_DCCSR_TT)
|
|
|
|
REG_DMAC_DCCSR(DMA_LCD_CHANNEL) &= ~DMAC_DCCSR_TT;
|
2008-12-03 00:20:24 +00:00
|
|
|
|
2008-12-20 01:48:46 +00:00
|
|
|
wakeup_signal(&lcd_wkup);
|
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)
|
|
|
|
{
|
2009-03-09 22:17:37 +00:00
|
|
|
if(!lcd_is_on)
|
2008-07-14 15:03:10 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
|
|
|
|
}
|
2009-02-09 10:02:38 +00:00
|
|
|
|
2009-04-18 17:38:55 +00:00
|
|
|
/* (Mis)use LCD framebuffer as a temporary buffer */
|
2009-02-09 10:02:38 +00:00
|
|
|
void lcd_blit_yuv(unsigned char * const src[3],
|
|
|
|
int src_x, int src_y, int stride,
|
|
|
|
int x, int y, int width, int height)
|
|
|
|
{
|
2009-04-18 21:00:32 +00:00
|
|
|
unsigned char const * yuv_src[3];
|
|
|
|
register off_t z;
|
|
|
|
|
|
|
|
if(!lcd_is_on)
|
|
|
|
return;
|
|
|
|
|
|
|
|
z = stride * src_y;
|
|
|
|
yuv_src[0] = src[0] + z + src_x;
|
|
|
|
yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
|
|
|
|
yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
|
|
|
|
|
2009-04-18 17:38:55 +00:00
|
|
|
__dcache_writeback_all();
|
|
|
|
|
|
|
|
__cpm_start_ipu();
|
|
|
|
|
|
|
|
IPU_STOP_IPU();
|
2009-04-18 21:00:32 +00:00
|
|
|
IPU_RESET_IPU();
|
2009-04-18 17:38:55 +00:00
|
|
|
IPU_CLEAR_END_FLAG();
|
|
|
|
|
|
|
|
IPU_DISABLE_RSIZE();
|
|
|
|
IPU_DISABLE_IRQ();
|
|
|
|
|
|
|
|
IPU_SET_INFMT(INFMT_YUV420);
|
|
|
|
IPU_SET_OUTFMT(OUTFMT_RGB565);
|
|
|
|
|
|
|
|
IPU_SET_IN_FM(width, height);
|
|
|
|
IPU_SET_Y_STRIDE(stride);
|
|
|
|
IPU_SET_UV_STRIDE(stride, stride);
|
|
|
|
|
2009-04-18 21:00:32 +00:00
|
|
|
IPU_SET_Y_ADDR(PHYSADDR((unsigned long)yuv_src[0]));
|
|
|
|
IPU_SET_U_ADDR(PHYSADDR((unsigned long)yuv_src[1]));
|
|
|
|
IPU_SET_V_ADDR(PHYSADDR((unsigned long)yuv_src[2]));
|
|
|
|
IPU_SET_OUT_ADDR(PHYSADDR((unsigned long)&lcd_framebuffer[x][y]));
|
2009-04-18 17:38:55 +00:00
|
|
|
|
2009-04-18 21:00:32 +00:00
|
|
|
IPU_SET_OUT_FM(height, width);
|
|
|
|
IPU_SET_OUT_STRIDE(height);
|
2009-04-18 17:38:55 +00:00
|
|
|
|
|
|
|
IPU_SET_CSC_C0_COEF(YUV_CSC_C0);
|
|
|
|
IPU_SET_CSC_C1_COEF(YUV_CSC_C1);
|
|
|
|
IPU_SET_CSC_C2_COEF(YUV_CSC_C2);
|
2009-04-18 21:00:32 +00:00
|
|
|
IPU_SET_CSC_C3_COEF(YUV_CSC_C3);
|
2009-04-18 17:38:55 +00:00
|
|
|
IPU_SET_CSC_C4_COEF(YUV_CSC_C4);
|
|
|
|
|
|
|
|
IPU_RUN_IPU();
|
|
|
|
|
|
|
|
while(!(IPU_POLLING_END_FLAG()) && IPU_IS_ENABLED());
|
|
|
|
|
|
|
|
IPU_CLEAR_END_FLAG();
|
|
|
|
IPU_STOP_IPU();
|
2009-04-18 21:00:32 +00:00
|
|
|
IPU_RESET_IPU();
|
2009-04-18 17:38:55 +00:00
|
|
|
|
2009-04-18 21:00:32 +00:00
|
|
|
__cpm_stop_ipu();
|
2009-04-18 17:38:55 +00:00
|
|
|
|
|
|
|
/* YUV speed is limited by LCD speed */
|
2009-04-18 21:00:32 +00:00
|
|
|
lcd_update_rect(y, x, height, width);
|
2009-02-09 10:02:38 +00:00
|
|
|
}
|