1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (c) 2011 by Amaury Pouly
*
* 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 "lcdif-imx233.h"
static unsigned lcdif_word_length = 0;
static unsigned lcdif_byte_packing = 0;
void imx233_lcdif_enable_bus_master(bool enable)
{
if(enable)
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__LCDIF_MASTER;
else
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__LCDIF_MASTER;
}
void imx233_lcdif_enable(bool enable)
{
if(enable)
__REG_CLR(HW_LCDIF_CTRL) = __BLOCK_CLKGATE;
else
__REG_SET(HW_LCDIF_CTRL) = __BLOCK_CLKGATE;
}
void imx233_lcdif_reset(void)
{
//imx233_reset_block(&HW_LCDIF_CTRL);// doesn't work
while(HW_LCDIF_CTRL & __BLOCK_CLKGATE)
HW_LCDIF_CTRL &= ~__BLOCK_CLKGATE;
while(!(HW_LCDIF_CTRL & __BLOCK_SFTRST))
HW_LCDIF_CTRL |= __BLOCK_SFTRST;
while(HW_LCDIF_CTRL & __BLOCK_CLKGATE)
HW_LCDIF_CTRL &= ~__BLOCK_CLKGATE;
while(HW_LCDIF_CTRL & __BLOCK_SFTRST)
HW_LCDIF_CTRL &= ~__BLOCK_SFTRST;
while(HW_LCDIF_CTRL & __BLOCK_CLKGATE)
HW_LCDIF_CTRL &= ~__BLOCK_CLKGATE;
__REG_SET(HW_LCDIF_CTRL1) = HW_LCDIF_CTRL1__RESET;
}
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);
}
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;
}
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;
lcdif_word_length = word_length;
}
unsigned imx233_lcdif_enable_irqs(unsigned irq_bm)
{
unsigned old_msk = (HW_LCDIF_CTRL1 & HW_LCDIF_CTRL1__IRQ_EN_BM) >>HW_LCDIF_CTRL1__IRQ_EN_BP ;
/* 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;
}
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;
else
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_FORMAT_16_BIT;
if(data_fmt_18)
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_FORMAT_18_BIT;
else
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_FORMAT_18_BIT;
if(data_fmt_24)
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_FORMAT_24_BIT;
else
__REG_CLR(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_FORMAT_24_BIT;
}
void imx233_lcdif_wait_ready(void)
{
while(HW_LCDIF_CTRL & HW_LCDIF_CTRL__RUN);
}
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)
max_xfer_size = 0x1fffe;
imx233_lcdif_wait_ready();
unsigned msk = imx233_lcdif_enable_irqs(0);
imx233_lcdif_enable_bus_master(false);
do
{
unsigned burst = MIN(len, max_xfer_size);
len -= burst;
unsigned count = burst;
if(lcdif_word_length != HW_LCDIF_CTRL__WORD_LENGTH_8_BIT)
{
if(burst & 1)
burst++;
count = burst / 2;
}
else
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;
if(data_mode)
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__DATA_SELECT;
__REG_SET(HW_LCDIF_CTRL) = HW_LCDIF_CTRL__RUN;
burst = (burst + 3) / 4;
while(burst-- > 0)
{
while(HW_LCDIF_STAT & HW_LCDIF_STAT__LFIFO_FULL);
HW_LCDIF_DATA = *buf++;
}
while(HW_LCDIF_CTRL & HW_LCDIF_CTRL__RUN);
}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)
{
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;
}
|