imx233: rewrite lcdif using the new register headers

Change-Id: I94329a65a7c6a4127fa05b77b9a7a291f8a50013
This commit is contained in:
Amaury Pouly 2013-06-16 16:32:03 +02:00
parent 0fa014a6fe
commit 8517cf8bed
5 changed files with 50 additions and 128 deletions

View file

@ -37,8 +37,8 @@ static unsigned lcd_yuv_options = 0;
static void setup_parameters(void)
{
imx233_lcdif_reset();
imx233_lcdif_set_lcd_databus_width(HW_LCDIF_CTRL__LCD_DATABUS_WIDTH_18_BIT);
imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_18_BIT);
imx233_lcdif_set_lcd_databus_width(BV_LCDIF_CTRL_LCD_DATABUS_WIDTH__18_BIT);
imx233_lcdif_set_word_length(BV_LCDIF_CTRL_WORD_LENGTH__18_BIT);
imx233_lcdif_set_timings(2, 2, 3, 3);
imx233_lcdif_enable_underflow_recover(true);
}
@ -120,7 +120,7 @@ static void lcd_write_reg(uint32_t reg, uint32_t data)
{
uint32_t old_reg = reg;
/* get back to 18-bit word length */
imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_18_BIT);
imx233_lcdif_set_word_length(BV_LCDIF_CTRL_WORD_LENGTH__18_BIT);
reg = encode_16_to_18(reg);
data = encode_16_to_18(data);
@ -208,11 +208,11 @@ void lcd_init_device(void)
setup_lcdif_clock();
// reset device
__REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
BF_SET(LCDIF_CTRL1, RESET);
mdelay(50);
__REG_CLR(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
BF_CLR(LCDIF_CTRL1, RESET);
mdelay(10);
__REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
BF_SET(LCDIF_CTRL1, RESET);
lcd_init_seq();
#ifdef HAVE_LCD_ENABLE
@ -283,7 +283,7 @@ void lcd_update_rect(int x, int y, int w, int h)
lcd_write_reg(0x201, 0);
lcd_write_reg(0x202, 0);
imx233_lcdif_wait_ready();
imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_16_BIT);
imx233_lcdif_set_word_length(BV_LCDIF_CTRL_WORD_LENGTH__16_BIT);
imx233_lcdif_set_byte_packing_format(0xf); /* two pixels per 32-bit word */
imx233_lcdif_set_data_format(false, false, false); /* RGB565, don't care, don't care */

View file

@ -37,8 +37,8 @@ static unsigned lcd_yuv_options = 0;
static void setup_parameters(void)
{
imx233_lcdif_reset();
imx233_lcdif_set_lcd_databus_width(HW_LCDIF_CTRL__LCD_DATABUS_WIDTH_16_BIT);
imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_16_BIT);
imx233_lcdif_set_lcd_databus_width(BV_LCDIF_CTRL_LCD_DATABUS_WIDTH__16_BIT);
imx233_lcdif_set_word_length(BV_LCDIF_CTRL_WORD_LENGTH__16_BIT);
imx233_lcdif_set_timings(2, 2, 3, 3);
imx233_lcdif_enable_underflow_recover(true);
}
@ -182,11 +182,11 @@ void lcd_init_device(void)
setup_lcdif_clock();
// reset device
__REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
BF_SET(LCDIF_CTRL1, RESET);
mdelay(50);
__REG_CLR(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
BF_CLR(LCDIF_CTRL1, RESET);
mdelay(10);
__REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
BF_SET(LCDIF_CTRL1, RESET);
lcd_init_seq();
#ifdef HAVE_LCD_ENABLE
@ -258,7 +258,7 @@ void lcd_update_rect(int x, int y, int w, int h)
lcd_write_reg(0x22, 0);
imx233_lcdif_wait_ready();
imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_16_BIT);
imx233_lcdif_set_word_length(BV_LCDIF_CTRL_WORD_LENGTH__16_BIT);
imx233_lcdif_set_byte_packing_format(0xf); /* two pixels per 32-bit word */
imx233_lcdif_set_data_format(false, false, false); /* RGB565, don't care, don't care */

View file

@ -21,30 +21,29 @@
#include "lcdif-imx233.h"
static unsigned lcdif_word_length = 0;
static unsigned lcdif_byte_packing = 0;
void imx233_lcdif_enable_underflow_recover(bool enable)
{
if(enable)
__REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RECOVER_ON_UNDERFLOW;
BF_SET(LCDIF_CTRL1, RECOVER_ON_UNDERFLOW);
else
__REG_CLR(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RECOVER_ON_UNDERFLOW;
BF_CLR(LCDIF_CTRL1, RECOVER_ON_UNDERFLOW);
}
void imx233_lcdif_enable_bus_master(bool enable)
{
if(enable)
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__LCDIF_MASTER;
BF_SET(LCDIF_CTRL, LCDIF_MASTER);
else
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__LCDIF_MASTER;
BF_CLR(LCDIF_CTRL, LCDIF_MASTER);
}
void imx233_lcdif_enable(bool enable)
{
if(enable)
__REG_CLR(HW_LCDIF_CTRL) = __BLOCK_CLKGATE;
BF_CLR(LCDIF_CTRL, CLKGATE);
else
__REG_SET(HW_LCDIF_CTRL) = __BLOCK_CLKGATE;
BF_SET(LCDIF_CTRL, CLKGATE);
}
void imx233_lcdif_reset(void)
@ -55,64 +54,45 @@ void imx233_lcdif_reset(void)
void imx233_lcdif_set_timings(unsigned data_setup, unsigned data_hold,
unsigned cmd_setup, unsigned cmd_hold)
{
HW_LCDIF_TIMING = (data_setup << HW_LCDIF_TIMING__DATA_SETUP_BP) |
(data_hold << HW_LCDIF_TIMING__DATA_HOLD_BP) |
(cmd_setup << HW_LCDIF_TIMING__CMD_SETUP_BP) |
(cmd_hold << HW_LCDIF_TIMING__CMD_HOLD_BP);
HW_LCDIF_TIMING = BF_OR4(LCDIF_TIMING, DATA_SETUP(data_setup),
DATA_HOLD(data_hold), CMD_SETUP(cmd_setup), CMD_HOLD(cmd_hold));
}
void imx233_lcdif_set_lcd_databus_width(unsigned width)
{
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__LCD_DATABUS_WIDTH_BM;
__REG_SET(HW_LCDIF_CTRL) = width;
BF_WR(LCDIF_CTRL, LCD_DATABUS_WIDTH, width);
}
void imx233_lcdif_set_word_length(unsigned word_length)
{
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__WORD_LENGTH_BM;
__REG_SET(HW_LCDIF_CTRL) = word_length;
BF_WR(LCDIF_CTRL, WORD_LENGTH, word_length);
lcdif_word_length = word_length;
}
unsigned imx233_lcdif_enable_irqs(unsigned irq_bm)
{
unsigned old_msk = __XTRACT(HW_LCDIF_CTRL1, IRQ_EN);
/* clear irq status */
__REG_CLR(HW_LCDIF_CTRL1) = irq_bm << HW_LCDIF_CTRL1__IRQ_BP;
/* disable irqs */
__REG_CLR(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__IRQ_EN_BM;
/* enable irqs */
__REG_SET(HW_LCDIF_CTRL1) = irq_bm << HW_LCDIF_CTRL1__IRQ_EN_BP;
return old_msk;
}
void imx233_lcdif_set_byte_packing_format(unsigned byte_packing)
{
__REG_CLR(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__BYTE_PACKING_FORMAT_BM;
__REG_SET(HW_LCDIF_CTRL1) = byte_packing << HW_LCDIF_CTRL1__BYTE_PACKING_FORMAT_BP;
lcdif_byte_packing = byte_packing;
BF_WR(LCDIF_CTRL1, BYTE_PACKING_FORMAT, byte_packing);
}
void imx233_lcdif_set_data_format(bool data_fmt_16, bool data_fmt_18, bool data_fmt_24)
{
if(data_fmt_16)
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_FORMAT_16_BIT;
BF_SET(LCDIF_CTRL, DATA_FORMAT_16_BIT);
else
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_FORMAT_16_BIT;
BF_CLR(LCDIF_CTRL, DATA_FORMAT_16_BIT);
if(data_fmt_18)
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_FORMAT_18_BIT;
BF_SET(LCDIF_CTRL, DATA_FORMAT_18_BIT);
else
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_FORMAT_18_BIT;
BF_CLR(LCDIF_CTRL, DATA_FORMAT_18_BIT);
if(data_fmt_24)
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_FORMAT_24_BIT;
BF_SET(LCDIF_CTRL, DATA_FORMAT_24_BIT);
else
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_FORMAT_24_BIT;
BF_CLR(LCDIF_CTRL, DATA_FORMAT_24_BIT);
}
void imx233_lcdif_wait_ready(void)
{
while(HW_LCDIF_CTRL & HW_LCDIF_CTRL__RUN);
while(BF_RD(LCDIF_CTRL, RUN));
}
void imx233_lcdif_pio_send(bool data_mode, unsigned len, uint32_t *buf)
@ -120,10 +100,9 @@ void imx233_lcdif_pio_send(bool data_mode, unsigned len, uint32_t *buf)
unsigned max_xfer_size = 0xffff;
if(len == 0)
return;
if(lcdif_word_length == HW_LCDIF_CTRL__WORD_LENGTH_16_BIT)
if(lcdif_word_length == BV_LCDIF_CTRL_WORD_LENGTH__16_BIT)
max_xfer_size = 0x1fffe;
imx233_lcdif_wait_ready();
unsigned msk = imx233_lcdif_enable_irqs(0);
imx233_lcdif_enable_bus_master(false);
do
@ -131,7 +110,7 @@ void imx233_lcdif_pio_send(bool data_mode, unsigned len, uint32_t *buf)
unsigned burst = MIN(len, max_xfer_size);
len -= burst;
unsigned count = burst;
if(lcdif_word_length != HW_LCDIF_CTRL__WORD_LENGTH_8_BIT)
if(lcdif_word_length != BV_LCDIF_CTRL_WORD_LENGTH__8_BIT)
{
if(burst & 1)
burst++;
@ -141,20 +120,20 @@ void imx233_lcdif_pio_send(bool data_mode, unsigned len, uint32_t *buf)
count = burst;
HW_LCDIF_TRANSFER_COUNT = 0;
HW_LCDIF_TRANSFER_COUNT = 0x10000 | count;
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_SELECT | HW_LCDIF_CTRL__RUN;
BF_CLR(LCDIF_CTRL, DATA_SELECT);
BF_CLR(LCDIF_CTRL, RUN);
if(data_mode)
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_SELECT;
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__RUN;
BF_SET(LCDIF_CTRL, DATA_SELECT);
BF_SET(LCDIF_CTRL, RUN);
burst = (burst + 3) / 4;
while(burst-- > 0)
{
while(HW_LCDIF_STAT & HW_LCDIF_STAT__LFIFO_FULL);
while(BF_RD(LCDIF_STAT, LFIFO_FULL));
HW_LCDIF_DATA = *buf++;
}
while(HW_LCDIF_CTRL & HW_LCDIF_CTRL__RUN);
imx233_lcdif_wait_ready();
}while(len > 0);
imx233_lcdif_enable_bus_master(true);
imx233_lcdif_enable_irqs(msk);
}
void imx233_lcdif_dma_send(void *buf, unsigned width, unsigned height)
@ -162,7 +141,7 @@ void imx233_lcdif_dma_send(void *buf, unsigned width, unsigned height)
HW_LCDIF_CUR_BUF = (uint32_t)buf;
HW_LCDIF_TRANSFER_COUNT = 0;
HW_LCDIF_TRANSFER_COUNT = (height << 16) | width;
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__RUN;
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_SELECT;
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__RUN;
BF_CLR(LCDIF_CTRL, RUN);
BF_SET(LCDIF_CTRL, DATA_SELECT);
BF_SET(LCDIF_CTRL, RUN);
}

View file

@ -26,64 +26,7 @@
#include "system.h"
#include "system-target.h"
#define HW_LCDIF_BASE 0x80030000
#define HW_LCDIF_CTRL (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x0))
#define HW_LCDIF_CTRL__WORD_LENGTH_16_BIT (0 << 8)
#define HW_LCDIF_CTRL__WORD_LENGTH_8_BIT (1 << 8)
#define HW_LCDIF_CTRL__WORD_LENGTH_18_BIT (2 << 8)
#define HW_LCDIF_CTRL__WORD_LENGTH_24_BIT (3 << 8)
#define HW_LCDIF_CTRL__WORD_LENGTH_BM (3 << 8)
#define HW_LCDIF_CTRL__LCD_DATABUS_WIDTH_16_BIT (0 << 10)
#define HW_LCDIF_CTRL__LCD_DATABUS_WIDTH_18_BIT (2 << 10)
#define HW_LCDIF_CTRL__LCD_DATABUS_WIDTH_BM (3 << 10)
#define HW_LCDIF_CTRL__LCDIF_MASTER (1 << 5)
#define HW_LCDIF_CTRL__DATA_FORMAT_16_BIT (1 << 3)
#define HW_LCDIF_CTRL__DATA_FORMAT_18_BIT (1 << 2)
#define HW_LCDIF_CTRL__DATA_FORMAT_24_BIT (1 << 1)
#define HW_LCDIF_CTRL__RUN 0x1
#define HW_LCDIF_CTRL__DATA_SELECT (1 << 16)
#define HW_LCDIF_CTRL1 (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x10))
#define HW_LCDIF_CTRL1__RESET 1
#define HW_LCDIF_CTRL1__BUSY_ENABLE (1 << 2)
#define HW_LCDIF_CTRL1__MODE86 (1 << 1)
#define HW_LCDIF_CTRL1__IRQ_EN_BP 12
#define HW_LCDIF_CTRL1__IRQ_EN_BM (0xf << 12)
#define HW_LCDIF_CTRL1__IRQ_BP 8
#define HW_LCDIF_CTRL1__BYTE_PACKING_FORMAT_BM (0xf << 16)
#define HW_LCDIF_CTRL1__BYTE_PACKING_FORMAT_BP 16
#define HW_LCDIF_CTRL1__RECOVER_ON_UNDERFLOW (1 << 24)
#define HW_LCDIF__VSYNC_EDGE_IRQ 1
#define HW_LCDIF__CUR_FRAME_DONE_IRQ 2
#define HW_LCDIF__UNDERFLOW_IRQ 4
#define HW_LCDIF__OVERFLOW_IRQ 8
#define HW_LCDIF_TRANSFER_COUNT (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x20))
#define HW_LCDIF_CUR_BUF (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x30))
#define HW_LCDIF_NEXT_BUF (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x40))
#define HW_LCDIF_TIMING (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x60))
#define HW_LCDIF_TIMING__DATA_SETUP_BP 0
#define HW_LCDIF_TIMING__DATA_HOLD_BP 8
#define HW_LCDIF_TIMING__CMD_SETUP_BP 16
#define HW_LCDIF_TIMING__CMD_HOLD_BP 24
#define HW_LCDIF_CSC_COEFF0 (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x110))
#define HW_LCDIF_CSC_COEFF1 (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x120))
#define HW_LCDIF_CSC_COEFF2 (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x130))
#define HW_LCDIF_CSC_COEFF3 (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x140))
#define HW_LCDIF_CSC_COEFF4 (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x150))
#define HW_LCDIF_CSC_OFFSET (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x160))
#define HW_LCDIF_CSC_LIMIT (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x170))
#define HW_LCDIF_DATA (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x1b0))
#define HW_LCDIF_STAT (*(volatile uint32_t *)(HW_LCDIF_BASE + 0x1d0))
#define HW_LCDIF_STAT__LFIFO_FULL (1 << 29)
#define HW_LCDIF_STAT__LFIFO_EMPTY (1 << 28)
#define HW_LCDIF_STAT__TXFIFO_FULL (1 << 27)
#define HW_LCDIF_STAT__TXFIFO_EMPTY (1 << 26)
#define HW_LCDIF_STAT__BUSY (1 << 25)
#include "regs/regs-lcdif.h"
void imx233_lcdif_enable_underflow_recover(bool enable);
void imx233_lcdif_enable_bus_master(bool enable);

View file

@ -56,8 +56,8 @@ static enum lcd_kind_t
static void setup_parameters(void)
{
imx233_lcdif_reset();
imx233_lcdif_set_lcd_databus_width(HW_LCDIF_CTRL__LCD_DATABUS_WIDTH_18_BIT);
imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_18_BIT);
imx233_lcdif_set_lcd_databus_width(BV_LCDIF_CTRL_LCD_DATABUS_WIDTH__18_BIT);
imx233_lcdif_set_word_length(BV_LCDIF_CTRL_WORD_LENGTH__18_BIT);
imx233_lcdif_set_timings(1, 2, 2, 2);
imx233_lcdif_enable_underflow_recover(true);
}
@ -218,7 +218,7 @@ static void lcd_write_reg(uint32_t reg, uint32_t data)
uint32_t old_reg = reg;
imx233_lcdif_wait_ready();
/* get back to 18-bit word length */
imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_18_BIT);
imx233_lcdif_set_word_length(BV_LCDIF_CTRL_WORD_LENGTH__18_BIT);
reg = encode_16_to_18(reg);
data = encode_16_to_18(data);
@ -398,11 +398,11 @@ void lcd_init_device(void)
break;
}
// reset device
__REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
BF_SET(LCDIF_CTRL1, RESET);
mdelay(50);
__REG_CLR(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
BF_CLR(LCDIF_CTRL1, RESET);
mdelay(10);
__REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
BF_SET(LCDIF_CTRL1, RESET);
switch(lcd_kind)
{
@ -578,7 +578,7 @@ void lcd_update_rect(int x, int y, int w, int h)
lcd_write_reg(0x21, y);
lcd_write_reg(0x22, 0);
imx233_lcdif_wait_ready();
imx233_lcdif_set_word_length(HW_LCDIF_CTRL__WORD_LENGTH_16_BIT);
imx233_lcdif_set_word_length(BV_LCDIF_CTRL_WORD_LENGTH__16_BIT);
imx233_lcdif_set_byte_packing_format(0xf); /* two pixels per 32-bit word */
imx233_lcdif_set_data_format(false, false, false); /* RGB565, don't care, don't care */
/* there are two cases here: