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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
/*
* Freescale STMP378X dvi panel initialization
*
* Embedded Alley Solutions, Inc <source@embeddedalley.com>
*
* Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
* Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
*/
/*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
/* #define DEBUG */
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/clk.h>
#include <mach/regs-lcdif.h>
#include <mach/regs-lradc.h>
#include <mach/regs-pinctrl.h>
#include <mach/regs-clkctrl.h>
#include <mach/regs-pwm.h>
#include <mach/regs-apbh.h>
#include <mach/gpio.h>
#include <mach/pins.h>
#include <mach/lcdif.h>
#include <mach/cpu.h>
#include <mach/stmp3xxx.h>
#include "pinmux.h"
#include <mach/regs-tvenc.h>
enum {
TVENC_MODE_OFF = 0,
TVENC_MODE_NTSC,
TVENC_MODE_PAL,
};
/* NTSC 720x480 mode */
#define NTSC_X_RES 720
#define NTSC_Y_RES 480
#define NTSC_H_BLANKING 262
#define NTSC_V_LINES 525
/* PAL 720x576 mode */
#define PAL_X_RES 720
#define PAL_Y_RES 576
#define PAL_H_BLANKING 274
#define PAL_V_LINES 625
/* frame size */
#define DVI_H_BLANKING(m) (m == TVENC_MODE_NTSC ? \
NTSC_H_BLANKING : PAL_H_BLANKING)
#define DVI_V_LINES(m) (m == TVENC_MODE_NTSC ? \
NTSC_V_LINES : PAL_V_LINES)
#define DVI_H_ACTIVE(m) (m == TVENC_MODE_NTSC ? NTSC_X_RES : PAL_X_RES)
#define DVI_V_ACTIVE(m) (m == TVENC_MODE_NTSC ? NTSC_Y_RES : PAL_Y_RES)
/* fileds range */
#define DVI_F1_START(m) 1
#define DVI_F1_END(m) (DVI_V_LINES(m) / 2)
#define DVI_F2_START(m) (DVI_F1_END(m) + 1)
#define DVI_F2_END(m) DVI_V_LINES(m)
/* blanking range */
#define DVI_V1_BLANK_START(m) DVI_F1_END(m)
#define DVI_V1_BLANK_END(m) (DVI_V1_BLANK_START(m) + \
(DVI_V_LINES(m) - DVI_V_ACTIVE(m)) / 2)
#define DVI_V2_BLANK_START(m) DVI_F2_END(m)
#define DVI_V2_BLANK_END(m) ((DVI_V2_BLANK_START(m) + \
(DVI_V_LINES(m) - DVI_V_ACTIVE(m)) / 2 - 1) % \
DVI_V_LINES(m))
static struct clk *lcd_clk;
static struct clk *clk_ref_vid;
static struct clk *clk_tv108M_ng;
static struct clk *clk_tv27M;
static int tvenc_mode;
static void init_tvenc_hw(int mode)
{
/* Reset module */
HW_TVENC_CTRL_SET(BM_TVENC_CTRL_SFTRST);
udelay(10);
/* Take module out of reset */
HW_TVENC_CTRL_CLR(BM_TVENC_CTRL_SFTRST | BM_TVENC_CTRL_CLKGATE);
if (mode == TVENC_MODE_NTSC) {
/* Config NTSC-M mode, 8-bit Y/C in, SYNC out */
HW_TVENC_CONFIG_CLR(BM_TVENC_CONFIG_SYNC_MODE |
BM_TVENC_CONFIG_PAL_SHAPE |
BM_TVENC_CONFIG_YGAIN_SEL |
BM_TVENC_CONFIG_CGAIN);
HW_TVENC_CONFIG_SET(BM_TVENC_CONFIG_FSYNC_PHS |
BF_TVENC_CONFIG_SYNC_MODE(0x4));
/* 859 pixels/line for NTSC */
HW_TVENC_SYNCOFFSET_WR(857);
HW_TVENC_COLORSUB0_WR(0x21F07C1F);
HW_TVENC_COLORBURST_CLR(BM_TVENC_COLORBURST_NBA |
BM_TVENC_COLORBURST_PBA);
HW_TVENC_COLORBURST_SET(BF_TVENC_COLORBURST_NBA(0xc8) |
BF_TVENC_COLORBURST_PBA(0));
} else if (mode == TVENC_MODE_PAL) {
/* Config PAL-B mode, 8-bit Y/C in, SYNC out */
HW_TVENC_CONFIG_CLR(BM_TVENC_CONFIG_SYNC_MODE |
BM_TVENC_CONFIG_ENCD_MODE |
BM_TVENC_CONFIG_YGAIN_SEL |
BM_TVENC_CONFIG_CGAIN |
BM_TVENC_CONFIG_FSYNC_PHS);
HW_TVENC_CONFIG_SET(BM_TVENC_CONFIG_PAL_SHAPE |
BF_TVENC_CONFIG_YGAIN_SEL(1) |
BF_TVENC_CONFIG_CGAIN(1) |
BF_TVENC_CONFIG_ENCD_MODE(0x1) |
BF_TVENC_CONFIG_SYNC_MODE(0x4));
/* 863 pixels/line for PAL */
HW_TVENC_SYNCOFFSET_WR(863);
HW_TVENC_COLORSUB0_WR(0x2A098ACB);
HW_TVENC_COLORBURST_CLR(BM_TVENC_COLORBURST_NBA |
BM_TVENC_COLORBURST_PBA);
HW_TVENC_COLORBURST_SET(BF_TVENC_COLORBURST_NBA(0xd6) |
BF_TVENC_COLORBURST_PBA(0x2a));
}
/* Power up DAC */
HW_TVENC_DACCTRL_WR(BM_TVENC_DACCTRL_GAINDN |
BM_TVENC_DACCTRL_GAINUP |
BM_TVENC_DACCTRL_PWRUP1 |
BM_TVENC_DACCTRL_DUMP_TOVDD1 |
BF_TVENC_DACCTRL_RVAL(3));
/* set all to zero is a requirement for NTSC */
HW_TVENC_MACROVISION0_WR(0);
HW_TVENC_MACROVISION1_WR(0);
HW_TVENC_MACROVISION2_WR(0);
HW_TVENC_MACROVISION3_WR(0);
HW_TVENC_MACROVISION4_WR(0);
}
static int init_panel(struct device *dev, dma_addr_t phys, int memsize,
struct stmp3xxx_platform_fb_entry *pentry)
{
int ret = 0;
lcd_clk = clk_get(dev, "lcdif");
clk_enable(lcd_clk);
clk_set_rate(lcd_clk, 1000000/pentry->cycle_time_ns); /* kHz */
clk_ref_vid = clk_get(NULL, "ref_vid");
clk_tv108M_ng = clk_get(NULL, "tv108M_ng");
clk_tv27M = clk_get(NULL, "tv27M");
clk_enable(clk_ref_vid);
clk_enable(clk_tv108M_ng);
clk_enable(clk_tv27M);
tvenc_mode = pentry->x_res == NTSC_Y_RES ? TVENC_MODE_NTSC : \
TVENC_MODE_PAL;
init_tvenc_hw(tvenc_mode);
setup_dvi_panel(DVI_H_ACTIVE(tvenc_mode), DVI_V_ACTIVE(tvenc_mode),
DVI_H_BLANKING(tvenc_mode), DVI_V_LINES(tvenc_mode),
DVI_V1_BLANK_START(tvenc_mode),
DVI_V1_BLANK_END(tvenc_mode),
DVI_V2_BLANK_START(tvenc_mode),
DVI_V2_BLANK_END(tvenc_mode),
DVI_F1_START(tvenc_mode), DVI_F1_END(tvenc_mode),
DVI_F2_START(tvenc_mode), DVI_F2_END(tvenc_mode));
ret = stmp3xxx_lcdif_dma_init(dev, phys, memsize, 1);
return ret;
}
static void release_panel(struct device *dev,
struct stmp3xxx_platform_fb_entry *pentry)
{
release_dvi_panel();
stmp3xxx_lcdif_dma_release();
clk_disable(clk_ref_vid);
clk_disable(clk_tv108M_ng);
clk_disable(clk_tv27M);
clk_disable(lcd_clk);
clk_put(clk_ref_vid);
clk_put(clk_tv108M_ng);
clk_put(clk_tv27M);
clk_put(lcd_clk);
}
static int blank_panel(int blank)
{
int ret = 0, count;
switch (blank) {
case FB_BLANK_NORMAL:
case FB_BLANK_VSYNC_SUSPEND:
case FB_BLANK_HSYNC_SUSPEND:
case FB_BLANK_POWERDOWN:
HW_LCDIF_CTRL_CLR(BM_LCDIF_CTRL_BYPASS_COUNT);
/* Wait until current transfer is complete, max 30ms */
for (count = 30000; count > 0; count--) {
if (HW_LCDIF_STAT_RD() & BM_LCDIF_STAT_TXFIFO_EMPTY)
break;
udelay(1);
}
break;
case FB_BLANK_UNBLANK:
HW_LCDIF_CTRL_SET(BM_LCDIF_CTRL_BYPASS_COUNT);
break;
default:
ret = -EINVAL;
}
return ret;
}
static struct stmp3xxx_platform_fb_entry ntsc_fb_entry = {
.name = "tvenc_ntsc",
/* x/y swapped */
.x_res = NTSC_Y_RES,
.y_res = NTSC_X_RES,
.bpp = 32,
/* the pix_clk should be near 27Mhz for proper syncronization */
.cycle_time_ns = 74,
.lcd_type = STMP3XXX_LCD_PANEL_DVI,
.init_panel = init_panel,
.release_panel = release_panel,
.blank_panel = blank_panel,
.run_panel = stmp3xxx_lcdif_run,
.pan_display = stmp3xxx_lcdif_pan_display,
};
static struct stmp3xxx_platform_fb_entry pal_fb_entry = {
.name = "tvenc_pal",
/* x/y swapped */
.x_res = PAL_Y_RES,
.y_res = PAL_X_RES,
.bpp = 32,
/* the pix_clk should be near 27Mhz for proper syncronization */
.cycle_time_ns = 74,
.lcd_type = STMP3XXX_LCD_PANEL_DVI,
.init_panel = init_panel,
.release_panel = release_panel,
.blank_panel = blank_panel,
.run_panel = stmp3xxx_lcdif_run,
.pan_display = stmp3xxx_lcdif_pan_display,
};
static int __init register_devices(void)
{
stmp3xxx_lcd_register_entry(&ntsc_fb_entry,
stmp3xxx_framebuffer.dev.platform_data);
stmp3xxx_lcd_register_entry(&pal_fb_entry,
stmp3xxx_framebuffer.dev.platform_data);
return 0;
}
subsys_initcall(register_devices);
|