xref: /OK3568_Linux_fs/u-boot/drivers/video/mvebu_lcd.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Video driver for Marvell Armada XP SoC
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Initialization of LCD interface and setup of SPLASH screen image
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <common.h>
10*4882a593Smuzhiyun #include <video_fb.h>
11*4882a593Smuzhiyun #include <linux/mbus.h>
12*4882a593Smuzhiyun #include <asm/io.h>
13*4882a593Smuzhiyun #include <asm/arch/cpu.h>
14*4882a593Smuzhiyun #include <asm/arch/soc.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #define MVEBU_LCD_WIN_CONTROL(w)        (MVEBU_LCD_BASE + 0xf000 + ((w) << 4))
17*4882a593Smuzhiyun #define MVEBU_LCD_WIN_BASE(w)           (MVEBU_LCD_BASE + 0xf004 + ((w) << 4))
18*4882a593Smuzhiyun #define MVEBU_LCD_WIN_REMAP(w)          (MVEBU_LCD_BASE + 0xf00c + ((w) << 4))
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #define MVEBU_LCD_CFG_DMA_START_ADDR_0	(MVEBU_LCD_BASE + 0x00cc)
21*4882a593Smuzhiyun #define MVEBU_LCD_CFG_DMA_START_ADDR_1	(MVEBU_LCD_BASE + 0x00dc)
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #define MVEBU_LCD_CFG_GRA_START_ADDR0	(MVEBU_LCD_BASE + 0x00f4)
24*4882a593Smuzhiyun #define MVEBU_LCD_CFG_GRA_START_ADDR1	(MVEBU_LCD_BASE + 0x00f8)
25*4882a593Smuzhiyun #define MVEBU_LCD_CFG_GRA_PITCH		(MVEBU_LCD_BASE + 0x00fc)
26*4882a593Smuzhiyun #define MVEBU_LCD_SPU_GRA_OVSA_HPXL_VLN	(MVEBU_LCD_BASE + 0x0100)
27*4882a593Smuzhiyun #define MVEBU_LCD_SPU_GRA_HPXL_VLN	(MVEBU_LCD_BASE + 0x0104)
28*4882a593Smuzhiyun #define MVEBU_LCD_SPU_GZM_HPXL_VLN	(MVEBU_LCD_BASE + 0x0108)
29*4882a593Smuzhiyun #define MVEBU_LCD_SPU_HWC_OVSA_HPXL_VLN	(MVEBU_LCD_BASE + 0x010c)
30*4882a593Smuzhiyun #define MVEBU_LCD_SPU_HWC_HPXL_VLN	(MVEBU_LCD_BASE + 0x0110)
31*4882a593Smuzhiyun #define MVEBU_LCD_SPUT_V_H_TOTAL	(MVEBU_LCD_BASE + 0x0114)
32*4882a593Smuzhiyun #define MVEBU_LCD_SPU_V_H_ACTIVE	(MVEBU_LCD_BASE + 0x0118)
33*4882a593Smuzhiyun #define MVEBU_LCD_SPU_H_PORCH		(MVEBU_LCD_BASE + 0x011c)
34*4882a593Smuzhiyun #define MVEBU_LCD_SPU_V_PORCH		(MVEBU_LCD_BASE + 0x0120)
35*4882a593Smuzhiyun #define MVEBU_LCD_SPU_BLANKCOLOR	(MVEBU_LCD_BASE + 0x0124)
36*4882a593Smuzhiyun #define MVEBU_LCD_SPU_ALPHA_COLOR1	(MVEBU_LCD_BASE + 0x0128)
37*4882a593Smuzhiyun #define MVEBU_LCD_SPU_ALPHA_COLOR2	(MVEBU_LCD_BASE + 0x012c)
38*4882a593Smuzhiyun #define MVEBU_LCD_SPU_COLORKEY_Y	(MVEBU_LCD_BASE + 0x0130)
39*4882a593Smuzhiyun #define MVEBU_LCD_SPU_COLORKEY_U	(MVEBU_LCD_BASE + 0x0134)
40*4882a593Smuzhiyun #define MVEBU_LCD_SPU_COLORKEY_V	(MVEBU_LCD_BASE + 0x0138)
41*4882a593Smuzhiyun #define MVEBU_LCD_CFG_RDREG4F		(MVEBU_LCD_BASE + 0x013c)
42*4882a593Smuzhiyun #define MVEBU_LCD_SPU_SPI_RXDATA	(MVEBU_LCD_BASE + 0x0140)
43*4882a593Smuzhiyun #define MVEBU_LCD_SPU_ISA_RXDATA	(MVEBU_LCD_BASE + 0x0144)
44*4882a593Smuzhiyun #define MVEBU_LCD_SPU_DBG_ISA		(MVEBU_LCD_BASE + 0x0148)
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #define MVEBU_LCD_SPU_HWC_RDDAT		(MVEBU_LCD_BASE + 0x0158)
47*4882a593Smuzhiyun #define MVEBU_LCD_SPU_GAMMA_RDDAT	(MVEBU_LCD_BASE + 0x015c)
48*4882a593Smuzhiyun #define MVEBU_LCD_SPU_PALETTE_RDDAT	(MVEBU_LCD_BASE + 0x0160)
49*4882a593Smuzhiyun #define MVEBU_LCD_SPU_IOPAD_IN		(MVEBU_LCD_BASE + 0x0178)
50*4882a593Smuzhiyun #define MVEBU_LCD_FRAME_COUNT		(MVEBU_LCD_BASE + 0x017c)
51*4882a593Smuzhiyun #define MVEBU_LCD_SPU_DMA_CTRL0		(MVEBU_LCD_BASE + 0x0190)
52*4882a593Smuzhiyun #define MVEBU_LCD_SPU_DMA_CTRL1		(MVEBU_LCD_BASE + 0x0194)
53*4882a593Smuzhiyun #define MVEBU_LCD_SPU_SRAM_CTRL		(MVEBU_LCD_BASE + 0x0198)
54*4882a593Smuzhiyun #define MVEBU_LCD_SPU_SRAM_WRDAT	(MVEBU_LCD_BASE + 0x019c)
55*4882a593Smuzhiyun #define MVEBU_LCD_SPU_SRAM_PARA0	(MVEBU_LCD_BASE + 0x01a0)
56*4882a593Smuzhiyun #define MVEBU_LCD_SPU_SRAM_PARA1	(MVEBU_LCD_BASE + 0x01a4)
57*4882a593Smuzhiyun #define MVEBU_LCD_CFG_SCLK_DIV		(MVEBU_LCD_BASE + 0x01a8)
58*4882a593Smuzhiyun #define MVEBU_LCD_SPU_CONTRAST		(MVEBU_LCD_BASE + 0x01ac)
59*4882a593Smuzhiyun #define MVEBU_LCD_SPU_SATURATION	(MVEBU_LCD_BASE + 0x01b0)
60*4882a593Smuzhiyun #define MVEBU_LCD_SPU_CBSH_HUE		(MVEBU_LCD_BASE + 0x01b4)
61*4882a593Smuzhiyun #define MVEBU_LCD_SPU_DUMB_CTRL		(MVEBU_LCD_BASE + 0x01b8)
62*4882a593Smuzhiyun #define MVEBU_LCD_SPU_IOPAD_CONTROL	(MVEBU_LCD_BASE + 0x01bc)
63*4882a593Smuzhiyun #define MVEBU_LCD_SPU_IRQ_ENA_2		(MVEBU_LCD_BASE + 0x01d8)
64*4882a593Smuzhiyun #define MVEBU_LCD_SPU_IRQ_ISR_2		(MVEBU_LCD_BASE + 0x01dc)
65*4882a593Smuzhiyun #define MVEBU_LCD_SPU_IRQ_ENA		(MVEBU_LCD_BASE + 0x01c0)
66*4882a593Smuzhiyun #define MVEBU_LCD_SPU_IRQ_ISR		(MVEBU_LCD_BASE + 0x01c4)
67*4882a593Smuzhiyun #define MVEBU_LCD_ADLL_CTRL		(MVEBU_LCD_BASE + 0x01c8)
68*4882a593Smuzhiyun #define MVEBU_LCD_CLK_DIS		(MVEBU_LCD_BASE + 0x01cc)
69*4882a593Smuzhiyun #define MVEBU_LCD_VGA_HVSYNC_DELAY	(MVEBU_LCD_BASE + 0x01d4)
70*4882a593Smuzhiyun #define MVEBU_LCD_CLK_CFG_0		(MVEBU_LCD_BASE + 0xf0a0)
71*4882a593Smuzhiyun #define MVEBU_LCD_CLK_CFG_1		(MVEBU_LCD_BASE + 0xf0a4)
72*4882a593Smuzhiyun #define MVEBU_LCD_LVDS_CLK_CFG		(MVEBU_LCD_BASE + 0xf0ac)
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun #define MVEBU_LVDS_PADS_REG		(MVEBU_SYSTEM_REG_BASE + 0xf0)
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun /* Setup Mbus Bridge Windows for LCD */
mvebu_lcd_conf_mbus_registers(void)77*4882a593Smuzhiyun static void mvebu_lcd_conf_mbus_registers(void)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun 	const struct mbus_dram_target_info *dram;
80*4882a593Smuzhiyun 	int i;
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 	dram = mvebu_mbus_dram_info();
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun 	/* Disable windows, set size/base/remap to 0  */
85*4882a593Smuzhiyun 	for (i = 0; i < 6; i++) {
86*4882a593Smuzhiyun 		writel(0, MVEBU_LCD_WIN_CONTROL(i));
87*4882a593Smuzhiyun 		writel(0, MVEBU_LCD_WIN_BASE(i));
88*4882a593Smuzhiyun 		writel(0, MVEBU_LCD_WIN_REMAP(i));
89*4882a593Smuzhiyun 	}
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 	/* Write LCD bridge window registers */
92*4882a593Smuzhiyun 	for (i = 0; i < dram->num_cs; i++) {
93*4882a593Smuzhiyun 		const struct mbus_dram_window *cs = dram->cs + i;
94*4882a593Smuzhiyun 		writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
95*4882a593Smuzhiyun 		       (dram->mbus_dram_target_id << 4) | 1,
96*4882a593Smuzhiyun 		       MVEBU_LCD_WIN_CONTROL(i));
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun 		writel(cs->base & 0xffff0000, MVEBU_LCD_WIN_BASE(i));
99*4882a593Smuzhiyun 	}
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun /* Initialize LCD registers */
mvebu_lcd_register_init(struct mvebu_lcd_info * lcd_info)103*4882a593Smuzhiyun int mvebu_lcd_register_init(struct mvebu_lcd_info *lcd_info)
104*4882a593Smuzhiyun {
105*4882a593Smuzhiyun 	/* Local variable for easier handling */
106*4882a593Smuzhiyun 	int x = lcd_info->x_res;
107*4882a593Smuzhiyun 	int y = lcd_info->y_res;
108*4882a593Smuzhiyun 	u32 val;
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun 	/* Setup Mbus Bridge Windows */
111*4882a593Smuzhiyun 	mvebu_lcd_conf_mbus_registers();
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun 	/*
114*4882a593Smuzhiyun 	 * Set LVDS Pads Control Register
115*4882a593Smuzhiyun 	 * wr 0 182F0 FFE00000
116*4882a593Smuzhiyun 	 */
117*4882a593Smuzhiyun 	clrbits_le32(MVEBU_LVDS_PADS_REG, 0x1f << 16);
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun 	/*
120*4882a593Smuzhiyun 	 * Set the LCD_CFG_GRA_START_ADDR0/1 Registers
121*4882a593Smuzhiyun 	 * This is supposed to point to the "physical" memory at memory
122*4882a593Smuzhiyun 	 * end (currently 1GB-64MB but also may be 2GB-64MB).
123*4882a593Smuzhiyun 	 * See also the Window 0 settings!
124*4882a593Smuzhiyun 	 */
125*4882a593Smuzhiyun 	writel(lcd_info->fb_base, MVEBU_LCD_CFG_GRA_START_ADDR0);
126*4882a593Smuzhiyun 	writel(lcd_info->fb_base, MVEBU_LCD_CFG_GRA_START_ADDR1);
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	/*
129*4882a593Smuzhiyun 	 * Set the LCD_CFG_GRA_PITCH Register
130*4882a593Smuzhiyun 	 * Bits 31-28: Duty Cycle of Backlight. value/16=High (0x8=Mid Setting)
131*4882a593Smuzhiyun 	 * Bits 25-16: Backlight divider from 32kHz Clock
132*4882a593Smuzhiyun 	 *             (here 16=0x10 for 1kHz)
133*4882a593Smuzhiyun 	 * Bits 15-00: Line Length in Bytes
134*4882a593Smuzhiyun 	 *             240*2 (for RGB1555)=480=0x1E0
135*4882a593Smuzhiyun 	 */
136*4882a593Smuzhiyun 	writel(0x80100000 + 2 * x, MVEBU_LCD_CFG_GRA_PITCH);
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun 	/*
139*4882a593Smuzhiyun 	 * Set the LCD_SPU_GRA_OVSA_HPXL_VLN Register
140*4882a593Smuzhiyun 	 * Bits 31-16: Vertical start of graphical overlay on screen
141*4882a593Smuzhiyun 	 * Bits 15-00: Horizontal start of graphical overlay on screen
142*4882a593Smuzhiyun 	 */
143*4882a593Smuzhiyun 	writel(0x00000000, MVEBU_LCD_SPU_GRA_OVSA_HPXL_VLN);
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 	/*
146*4882a593Smuzhiyun 	 * Set the LCD_SPU_GRA_HPXL_VLN Register
147*4882a593Smuzhiyun 	 * Bits 31-16: Vertical size of graphical overlay 320=0x140
148*4882a593Smuzhiyun 	 * Bits 15-00: Horizontal size of graphical overlay 240=0xF0
149*4882a593Smuzhiyun 	 * Values before zooming
150*4882a593Smuzhiyun 	 */
151*4882a593Smuzhiyun 	writel((y << 16) | x, MVEBU_LCD_SPU_GRA_HPXL_VLN);
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun 	/*
154*4882a593Smuzhiyun 	 * Set the LCD_SPU_GZM_HPXL_VLN Register
155*4882a593Smuzhiyun 	 * Bits 31-16: Vertical size of graphical overlay 320=0x140
156*4882a593Smuzhiyun 	 * Bits 15-00: Horizontal size of graphical overlay 240=0xF0
157*4882a593Smuzhiyun 	 * Values after zooming
158*4882a593Smuzhiyun 	 */
159*4882a593Smuzhiyun 	writel((y << 16) | x, MVEBU_LCD_SPU_GZM_HPXL_VLN);
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	/*
162*4882a593Smuzhiyun 	 * Set the LCD_SPU_HWC_OVSA_HPXL_VLN Register
163*4882a593Smuzhiyun 	 * Bits 31-16: Vertical position of HW Cursor 320=0x140
164*4882a593Smuzhiyun 	 * Bits 15-00: Horizontal position of HW Cursor 240=0xF0
165*4882a593Smuzhiyun 	 */
166*4882a593Smuzhiyun 	writel((y << 16) | x, MVEBU_LCD_SPU_HWC_OVSA_HPXL_VLN);
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 	/*
169*4882a593Smuzhiyun 	 * Set the LCD_SPU_HWC_OVSA_HPXL_VLN Register
170*4882a593Smuzhiyun 	 * Bits 31-16: Vertical size of HW Cursor
171*4882a593Smuzhiyun 	 * Bits 15-00: Horizontal size of HW Cursor
172*4882a593Smuzhiyun 	 */
173*4882a593Smuzhiyun 	writel(0x00000000, MVEBU_LCD_SPU_HWC_HPXL_VLN);
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun 	/*
176*4882a593Smuzhiyun 	 * Set the LCD_SPU_HWC_OVSA_HPXL_VLN Register
177*4882a593Smuzhiyun 	 * Bits 31-16: Screen total vertical lines:
178*4882a593Smuzhiyun 	 *             VSYNC                = 1
179*4882a593Smuzhiyun 	 *             Vertical Front Porch = 2
180*4882a593Smuzhiyun 	 *             Vertical Lines       = 320
181*4882a593Smuzhiyun 	 *             Vertical Back Porch  = 2
182*4882a593Smuzhiyun 	 *             SUM                  = 325 = 0x0145
183*4882a593Smuzhiyun 	 * Bits 15-00: Screen total horizontal pixels:
184*4882a593Smuzhiyun 	 *             HSYNC                  = 1
185*4882a593Smuzhiyun 	 *             Horizontal Front Porch = 44
186*4882a593Smuzhiyun 	 *             Horizontal Lines       = 240
187*4882a593Smuzhiyun 	 *             Horizontal Back Porch  = 2
188*4882a593Smuzhiyun 	 *             SUM                    = 287 = 0x011F
189*4882a593Smuzhiyun 	 * Note: For the display the backporch is between SYNC and
190*4882a593Smuzhiyun 	 *       the start of the pixels.
191*4882a593Smuzhiyun 	 *       This is not certain for the Marvell (!?)
192*4882a593Smuzhiyun 	 */
193*4882a593Smuzhiyun 	val = ((y + lcd_info->y_fp + lcd_info->y_bp + 1) << 16) |
194*4882a593Smuzhiyun 		(x + lcd_info->x_fp + lcd_info->x_bp + 1);
195*4882a593Smuzhiyun 	writel(val, MVEBU_LCD_SPUT_V_H_TOTAL);
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun 	/*
198*4882a593Smuzhiyun 	 * Set the LCD_SPU_V_H_ACTIVE Register
199*4882a593Smuzhiyun 	 * Bits 31-16: Screen active vertical lines 320=0x140
200*4882a593Smuzhiyun 	 * Bits 15-00: Screen active horizontakl pixels 240=0x00F0
201*4882a593Smuzhiyun 	 */
202*4882a593Smuzhiyun 	writel((y << 16) | x, MVEBU_LCD_SPU_V_H_ACTIVE);
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun 	/*
205*4882a593Smuzhiyun 	 * Set the LCD_SPU_H_PORCH Register
206*4882a593Smuzhiyun 	 * Bits 31-16: Screen horizontal backporch 44=0x2c
207*4882a593Smuzhiyun 	 * Bits 15-00: Screen horizontal frontporch 2=0x02
208*4882a593Smuzhiyun 	 * Note: The terms "front" and "back" for the Marvell seem to be
209*4882a593Smuzhiyun 	 *       exactly opposite to the display.
210*4882a593Smuzhiyun 	 */
211*4882a593Smuzhiyun 	writel((lcd_info->x_fp << 16) | lcd_info->x_bp, MVEBU_LCD_SPU_H_PORCH);
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun 	/*
214*4882a593Smuzhiyun 	 * Set the LCD_SPU_V_PORCH Register
215*4882a593Smuzhiyun 	 * Bits 31-16: Screen vertical backporch  2=0x02
216*4882a593Smuzhiyun 	 * Bits 15-00: Screen vertical frontporch 2=0x02
217*4882a593Smuzhiyun 	 * Note: The terms "front" and "back" for the Marvell seem to be exactly
218*4882a593Smuzhiyun 	 *       opposite to the display.
219*4882a593Smuzhiyun 	 */
220*4882a593Smuzhiyun 	writel((lcd_info->y_fp << 16) | lcd_info->y_bp, MVEBU_LCD_SPU_V_PORCH);
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun 	/*
223*4882a593Smuzhiyun 	 * Set the LCD_SPU_BLANKCOLOR Register
224*4882a593Smuzhiyun 	 * This should be black = 0
225*4882a593Smuzhiyun 	 * For tests this is magenta=00FF00FF
226*4882a593Smuzhiyun 	 */
227*4882a593Smuzhiyun 	writel(0x00FF00FF, MVEBU_LCD_SPU_BLANKCOLOR);
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun 	/*
230*4882a593Smuzhiyun 	 * Registers in the range of 0x0128 to 0x012C are colors for the cursor
231*4882a593Smuzhiyun 	 * Registers in the range of 0x0130 to 0x0138 are colors for video
232*4882a593Smuzhiyun 	 * color keying
233*4882a593Smuzhiyun 	 */
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 	/*
236*4882a593Smuzhiyun 	 * Set the LCD_SPU_RDREG4F Register
237*4882a593Smuzhiyun 	 * Bits 31-12: Reservd
238*4882a593Smuzhiyun 	 * Bit     11: SRAM Wait
239*4882a593Smuzhiyun 	 * Bit     10: Smart display fast TX (must be 1)
240*4882a593Smuzhiyun 	 * Bit      9: DMA Arbitration Video/Graphics overlay: 0=interleaved
241*4882a593Smuzhiyun 	 * Bit      8: FIFO watermark for DMA: 0=disable
242*4882a593Smuzhiyun 	 * Bits 07-00: Empty 8B FIFO entries to trigger DMA, default=0x80
243*4882a593Smuzhiyun 	 */
244*4882a593Smuzhiyun 	writel(0x00000780, MVEBU_LCD_CFG_RDREG4F);
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun 	/*
247*4882a593Smuzhiyun 	 * Set the LCD_SPU_DMACTRL 0 Register
248*4882a593Smuzhiyun 	 * Bit     31: Disable overlay blending 1=disable
249*4882a593Smuzhiyun 	 * Bit     30: Gamma correction enable, 0=disable
250*4882a593Smuzhiyun 	 * Bit     29: Video Contrast/Saturation/Hue Adjust enable, 0=disable
251*4882a593Smuzhiyun 	 * Bit     28: Color palette enable, 0=disable
252*4882a593Smuzhiyun 	 * Bit     27: DMA AXI Arbiter, 1=default
253*4882a593Smuzhiyun 	 * Bit     26: HW Cursor 1-bit mode
254*4882a593Smuzhiyun 	 * Bit     25: HW Cursor or 1- or 2-bit mode
255*4882a593Smuzhiyun 	 * Bit     24: HW Cursor enabled, 0=disable
256*4882a593Smuzhiyun 	 * Bits 23-20: Graphics Memory Color Format: 0x1=RGB1555
257*4882a593Smuzhiyun 	 * Bits 19-16: Video Memory Color Format:    0x1=RGB1555
258*4882a593Smuzhiyun 	 * Bit     15: Memory Toggle between frame 0 and 1: 0=disable
259*4882a593Smuzhiyun 	 * Bit     14: Graphics horizontal scaling enable: 0=disable
260*4882a593Smuzhiyun 	 * Bit     13: Graphics test mode: 0=disable
261*4882a593Smuzhiyun 	 * Bit     12: Graphics SWAP R and B: 0=disable
262*4882a593Smuzhiyun 	 * Bit     11: Graphics SWAP U and V: 0=disable
263*4882a593Smuzhiyun 	 * Bit     10: Graphics SWAP Y and U/V: 0=disable
264*4882a593Smuzhiyun 	 * Bit     09: Graphic YUV to RGB Conversion: 0=disable
265*4882a593Smuzhiyun 	 * Bit     08: Graphic Transfer: 1=enable
266*4882a593Smuzhiyun 	 * Bit     07: Memory Toggle: 0=disable
267*4882a593Smuzhiyun 	 * Bit     06: Video horizontal scaling enable: 0=disable
268*4882a593Smuzhiyun 	 * Bit     05: Video test mode: 0=disable
269*4882a593Smuzhiyun 	 * Bit     04: Video SWAP R and B: 0=disable
270*4882a593Smuzhiyun 	 * Bit     03: Video SWAP U and V: 0=disable
271*4882a593Smuzhiyun 	 * Bit     02: Video SWAP Y and U/V: 0=disable
272*4882a593Smuzhiyun 	 * Bit     01: Video YUV to RGB Conversion: 0=disable
273*4882a593Smuzhiyun 	 * Bit     00: Video  Transfer: 0=disable
274*4882a593Smuzhiyun 	 */
275*4882a593Smuzhiyun 	writel(0x88111100, MVEBU_LCD_SPU_DMA_CTRL0);
276*4882a593Smuzhiyun 
277*4882a593Smuzhiyun 	/*
278*4882a593Smuzhiyun 	 * Set the LCD_SPU_DMA_CTRL1 Register
279*4882a593Smuzhiyun 	 * Bit     31: Manual DMA Trigger = 0
280*4882a593Smuzhiyun 	 * Bits 30-28: DMA Trigger Source: 0x2 VSYNC
281*4882a593Smuzhiyun 	 * Bit     28: VSYNC_INV: 0=Rising Edge, 1=Falling Edge
282*4882a593Smuzhiyun 	 * Bits 26-24: Color Key Mode: 0=disable
283*4882a593Smuzhiyun 	 * Bit     23: Fill low bits: 0=fill with zeroes
284*4882a593Smuzhiyun 	 * Bit     22: Reserved
285*4882a593Smuzhiyun 	 * Bit     21: Gated Clock: 0=disable
286*4882a593Smuzhiyun 	 * Bit     20: Power Save enable: 0=disable
287*4882a593Smuzhiyun 	 * Bits 19-18: Reserved
288*4882a593Smuzhiyun 	 * Bits 17-16: Configure Video/Graphic Path: 0x1: Graphic path alpha.
289*4882a593Smuzhiyun 	 * Bits 15-08: Configure Alpha: 0x00.
290*4882a593Smuzhiyun 	 * Bits 07-00: Reserved.
291*4882a593Smuzhiyun 	 */
292*4882a593Smuzhiyun 	writel(0x20010000, MVEBU_LCD_SPU_DMA_CTRL1);
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun 	/*
295*4882a593Smuzhiyun 	 * Set the LCD_SPU_SRAM_CTRL Register
296*4882a593Smuzhiyun 	 * Reset to default = 0000C000
297*4882a593Smuzhiyun 	 * Bits 15-14: SRAM control: init=0x3, Read=0, Write=2
298*4882a593Smuzhiyun 	 * Bits 11-08: SRAM address ID: 0=gamma_yr, 1=gammy_ug, 2=gamma_vb,
299*4882a593Smuzhiyun 	 *             3=palette, 15=cursor
300*4882a593Smuzhiyun 	 */
301*4882a593Smuzhiyun 	writel(0x0000C000, MVEBU_LCD_SPU_SRAM_CTRL);
302*4882a593Smuzhiyun 
303*4882a593Smuzhiyun 	/*
304*4882a593Smuzhiyun 	 * LCD_SPU_SRAM_WRDAT register: 019C
305*4882a593Smuzhiyun 	 * LCD_SPU_SRAM_PARA0 register: 01A0
306*4882a593Smuzhiyun 	 * LCD_SPU_SRAM_PARA1 register: 01A4 - Cursor control/Power settings
307*4882a593Smuzhiyun 	 */
308*4882a593Smuzhiyun 	writel(0x00000000, MVEBU_LCD_SPU_SRAM_PARA1);
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun 	/* Clock settings in the at 01A8 and in the range F0A0 see below */
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun 	/*
314*4882a593Smuzhiyun 	 * Set LCD_SPU_CONTRAST
315*4882a593Smuzhiyun 	 * Bits 31-16: Brightness sign ext. 8-bit value +255 to -255: default=0
316*4882a593Smuzhiyun 	 * Bits 15-00: Contrast sign ext. 8-bit value +255 to -255: default=0
317*4882a593Smuzhiyun 	 */
318*4882a593Smuzhiyun 	writel(0x00000000, MVEBU_LCD_SPU_CONTRAST);
319*4882a593Smuzhiyun 
320*4882a593Smuzhiyun 	/*
321*4882a593Smuzhiyun 	 * Set LCD_SPU_SATURATION
322*4882a593Smuzhiyun 	 * Bits 31-16: Multiplier signed 4.12 fixed point value
323*4882a593Smuzhiyun 	 * Bits 15-00: Saturation signed 4.12 fixed point value
324*4882a593Smuzhiyun 	 */
325*4882a593Smuzhiyun 	writel(0x10001000, MVEBU_LCD_SPU_SATURATION);
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	/*
328*4882a593Smuzhiyun 	 * Set LCD_SPU_HUE
329*4882a593Smuzhiyun 	 * Bits 31-16: Sine signed 2.14 fixed point value
330*4882a593Smuzhiyun 	 * Bits 15-00: Cosine signed 2.14 fixed point value
331*4882a593Smuzhiyun 	 */
332*4882a593Smuzhiyun 	writel(0x00000000, MVEBU_LCD_SPU_CBSH_HUE);
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun 	/*
335*4882a593Smuzhiyun 	 * Set LCD_SPU_DUMB_CTRL
336*4882a593Smuzhiyun 	 * Bits 31-28: LCD Type: 3=18 bit RGB | 6=24 bit RGB888
337*4882a593Smuzhiyun 	 * Bits 27-12: Reserved
338*4882a593Smuzhiyun 	 * Bit     11: LCD DMA Pipeline Enable: 1=Enable
339*4882a593Smuzhiyun 	 * Bits 10-09: Reserved
340*4882a593Smuzhiyun 	 * Bit      8: LCD GPIO pin (??)
341*4882a593Smuzhiyun 	 * Bit      7: Reverse RGB
342*4882a593Smuzhiyun 	 * Bit      6: Invert composite blank signal DE/EN (??)
343*4882a593Smuzhiyun 	 * Bit      5: Invert composite sync signal
344*4882a593Smuzhiyun 	 * Bit      4: Invert Pixel Valid Enable DE/EN (??)
345*4882a593Smuzhiyun 	 * Bit      3: Invert VSYNC
346*4882a593Smuzhiyun 	 * Bit      2: Invert HSYNC
347*4882a593Smuzhiyun 	 * Bit      1: Invert Pixel Clock
348*4882a593Smuzhiyun 	 * Bit      0: Enable LCD Panel: 1=Enable
349*4882a593Smuzhiyun 	 * Question: Do we have to disable Smart and Dumb LCD
350*4882a593Smuzhiyun 	 * and separately enable LVDS?
351*4882a593Smuzhiyun 	 */
352*4882a593Smuzhiyun 	writel(0x6000080F, MVEBU_LCD_SPU_DUMB_CTRL);
353*4882a593Smuzhiyun 
354*4882a593Smuzhiyun 	/*
355*4882a593Smuzhiyun 	 * Set LCD_SPU_IOPAD_CTRL
356*4882a593Smuzhiyun 	 * Bits 31-20: Reserved
357*4882a593Smuzhiyun 	 * Bits 19-18: Vertical Interpolation: 0=Disable
358*4882a593Smuzhiyun 	 * Bits 17-16: Reserved
359*4882a593Smuzhiyun 	 * Bit     15: Graphics Vertical Mirror enable: 0=disable
360*4882a593Smuzhiyun 	 * Bit     14: Reserved
361*4882a593Smuzhiyun 	 * Bit     13: Video Vertical Mirror enable: 0=disable
362*4882a593Smuzhiyun 	 * Bit     12: Reserved
363*4882a593Smuzhiyun 	 * Bit     11: Command Vertical Mirror enable: 0=disable
364*4882a593Smuzhiyun 	 * Bit     10: Reserved
365*4882a593Smuzhiyun 	 * Bits 09-08: YUV to RGB Color space conversion: 0 (Not used)
366*4882a593Smuzhiyun 	 * Bits 07-04: AXI Bus Master: 0x4: no crossing of 4k boundary,
367*4882a593Smuzhiyun 	 *             128 Bytes burst
368*4882a593Smuzhiyun 	 * Bits 03-00: LCD pins: ??? 0=24-bit Dump panel ??
369*4882a593Smuzhiyun 	 */
370*4882a593Smuzhiyun 	writel(0x000000C0, MVEBU_LCD_SPU_IOPAD_CONTROL);
371*4882a593Smuzhiyun 
372*4882a593Smuzhiyun 	/*
373*4882a593Smuzhiyun 	 * Set SUP_IRQ_ENA_2: Disable all interrupts
374*4882a593Smuzhiyun 	 */
375*4882a593Smuzhiyun 	writel(0x00000000, MVEBU_LCD_SPU_IRQ_ENA_2);
376*4882a593Smuzhiyun 
377*4882a593Smuzhiyun 	/*
378*4882a593Smuzhiyun 	 * Set SUP_IRQ_ENA: Disable all interrupts.
379*4882a593Smuzhiyun 	 */
380*4882a593Smuzhiyun 	writel(0x00000000, MVEBU_LCD_SPU_IRQ_ENA);
381*4882a593Smuzhiyun 
382*4882a593Smuzhiyun 	/*
383*4882a593Smuzhiyun 	 * Set up ADDL Control Register
384*4882a593Smuzhiyun 	 * Bits 31-29: 0x0 = Fastest Delay Line (default)
385*4882a593Smuzhiyun 	 *             0x3 = Slowest Delay Line (default)
386*4882a593Smuzhiyun 	 * Bit     28: Calibration done status.
387*4882a593Smuzhiyun 	 * Bit     27: Reserved
388*4882a593Smuzhiyun 	 * Bit     26: Set Pixel Clock to ADDL output
389*4882a593Smuzhiyun 	 * Bit     25: Reduce CAL Enable
390*4882a593Smuzhiyun 	 * Bits 24-22: Manual calibration value.
391*4882a593Smuzhiyun 	 * Bit     21: Manual calibration enable.
392*4882a593Smuzhiyun 	 * Bit     20: Restart Auto Cal
393*4882a593Smuzhiyun 	 * Bits 19-16: Calibration Threshold voltage, default= 0x2
394*4882a593Smuzhiyun 	 * Bite 15-14: Reserved
395*4882a593Smuzhiyun 	 * Bits 13-11: Divisor for ADDL Clock: 0x1=/2, 0x3=/8, 0x5=/16
396*4882a593Smuzhiyun 	 * Bit     10: Power Down ADDL module, default = 1!
397*4882a593Smuzhiyun 	 * Bits 09-08: Test point configuration: 0x2=Bias, 0x3=High-z
398*4882a593Smuzhiyun 	 * Bit     07: Reset ADDL
399*4882a593Smuzhiyun 	 * Bit     06: Invert ADLL Clock
400*4882a593Smuzhiyun 	 * Bits 05-00: Delay taps, 0x3F=Half Cycle, 0x00=No delay
401*4882a593Smuzhiyun 	 * Note: ADLL is used for a VGA interface with DAC - not used here
402*4882a593Smuzhiyun 	 */
403*4882a593Smuzhiyun 	writel(0x00000000, MVEBU_LCD_ADLL_CTRL);
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun 	/*
406*4882a593Smuzhiyun 	 * Set the LCD_CLK_DIS Register:
407*4882a593Smuzhiyun 	 * Bits 3 and 4 must be 1
408*4882a593Smuzhiyun 	 */
409*4882a593Smuzhiyun 	writel(0x00000018, MVEBU_LCD_CLK_DIS);
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun 	/*
412*4882a593Smuzhiyun 	 * Set the LCD_VGA_HSYNC/VSYNC Delay Register:
413*4882a593Smuzhiyun 	 * Bits 03-00: Sets the delay for the HSYNC and VSYNC signals
414*4882a593Smuzhiyun 	 */
415*4882a593Smuzhiyun 	writel(0x00000000, MVEBU_LCD_VGA_HVSYNC_DELAY);
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun 	/*
418*4882a593Smuzhiyun 	 * Clock registers
419*4882a593Smuzhiyun 	 * See page 475 in the functional spec.
420*4882a593Smuzhiyun 	 */
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun 	/* Step 1 and 2: Disable the PLL */
423*4882a593Smuzhiyun 
424*4882a593Smuzhiyun 	/*
425*4882a593Smuzhiyun 	 * Disable PLL, see "LCD Clock Configuration 1 Register" below
426*4882a593Smuzhiyun 	 */
427*4882a593Smuzhiyun 	writel(0x8FF40007, MVEBU_LCD_CLK_CFG_1);
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun 	/*
430*4882a593Smuzhiyun 	 * Powerdown, see "LCD Clock Configuration 0 Register" below
431*4882a593Smuzhiyun 	 */
432*4882a593Smuzhiyun 	writel(0x94000174, MVEBU_LCD_CLK_CFG_0);
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun 	/*
435*4882a593Smuzhiyun 	 * Set the LCD_CFG_SCLK_DIV Register
436*4882a593Smuzhiyun 	 * This is set fix to 0x40000001 for the LVDS output:
437*4882a593Smuzhiyun 	 * Bits 31-30: SCLCK Source: 0=AXIBus, 1=AHBus, 2=PLLDivider0
438*4882a593Smuzhiyun 	 * Bits 15-01: Clock Divider: Bypass for LVDS=0x0001
439*4882a593Smuzhiyun 	 * See page 475 in section 28.5.
440*4882a593Smuzhiyun 	 */
441*4882a593Smuzhiyun 	writel(0x80000001, MVEBU_LCD_CFG_SCLK_DIV);
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun 	/*
444*4882a593Smuzhiyun 	 * Set the LCD Clock Configuration 0 Register:
445*4882a593Smuzhiyun 	 * Bit     31: Powerdown: 0=Power up
446*4882a593Smuzhiyun 	 * Bits 30-29: Reserved
447*4882a593Smuzhiyun 	 * Bits 28-26: PLL_KDIV: This encodes K
448*4882a593Smuzhiyun 	 *             K=16 => 0x5
449*4882a593Smuzhiyun 	 * Bits 25-17: PLL_MDIV: This is M-1:
450*4882a593Smuzhiyun 	 *             M=1 => 0x0
451*4882a593Smuzhiyun 	 * Bits 16-13: VCO band: 0x1 for 700-920MHz
452*4882a593Smuzhiyun 	 * Bits 12-04: PLL_NDIV: This is N-1 and corresponds to R1_CTRL!
453*4882a593Smuzhiyun 	 *             N=28=0x1C => 0x1B
454*4882a593Smuzhiyun 	 * Bits 03-00: R1_CTRL (for N=28 => 0x4)
455*4882a593Smuzhiyun 	 */
456*4882a593Smuzhiyun 	writel(0x940021B4, MVEBU_LCD_CLK_CFG_0);
457*4882a593Smuzhiyun 
458*4882a593Smuzhiyun 	/*
459*4882a593Smuzhiyun 	 * Set the LCD Clock Configuration 1 Register:
460*4882a593Smuzhiyun 	 * Bits 31-19: Reserved
461*4882a593Smuzhiyun 	 * Bit     18: Select PLL: Core PLL, 1=Dedicated PPL
462*4882a593Smuzhiyun 	 * Bit     17: Clock Output Enable: 0=disable, 1=enable
463*4882a593Smuzhiyun 	 * Bit     16: Select RefClk: 0=RefClk (25MHz), 1=External
464*4882a593Smuzhiyun 	 * Bit     15: Half-Div, Device Clock by DIV+0.5*Half-Dev
465*4882a593Smuzhiyun 	 * Bits 14-13: Reserved
466*4882a593Smuzhiyun 	 * Bits 12-00: PLL Full Divider [Note: Assumed to be the Post-Divider
467*4882a593Smuzhiyun 	 *             M' for LVDS=7!]
468*4882a593Smuzhiyun 	 */
469*4882a593Smuzhiyun 	writel(0x8FF40007, MVEBU_LCD_CLK_CFG_1);
470*4882a593Smuzhiyun 
471*4882a593Smuzhiyun 	/*
472*4882a593Smuzhiyun 	 * Set the LVDS Clock Configuration Register:
473*4882a593Smuzhiyun 	 * Bit     31: Clock Gating for the input clock to the LVDS
474*4882a593Smuzhiyun 	 * Bit     30: LVDS Serializer enable: 1=Enabled
475*4882a593Smuzhiyun 	 * Bits 29-11: Reserved
476*4882a593Smuzhiyun 	 * Bit  11-08: LVDS Clock delay: 0x02 (default): by 2 pixel clock/7
477*4882a593Smuzhiyun 	 * Bits 07-02: Reserved
478*4882a593Smuzhiyun 	 * Bit     01: 24bbp Option: 0=Option_1,1=Option2
479*4882a593Smuzhiyun 	 * Bit     00: 1=24bbp Panel: 0=18bpp Panel
480*4882a593Smuzhiyun 	 * Note: Bits 0 and must be verified with the help of the
481*4882a593Smuzhiyun 	 *       Interface/display
482*4882a593Smuzhiyun 	 */
483*4882a593Smuzhiyun 	writel(0xC0000201, MVEBU_LCD_LVDS_CLK_CFG);
484*4882a593Smuzhiyun 
485*4882a593Smuzhiyun 	/*
486*4882a593Smuzhiyun 	 * Power up PLL (Clock Config 0)
487*4882a593Smuzhiyun 	 */
488*4882a593Smuzhiyun 	writel(0x140021B4, MVEBU_LCD_CLK_CFG_0);
489*4882a593Smuzhiyun 
490*4882a593Smuzhiyun 	/* wait 10 ms */
491*4882a593Smuzhiyun 	mdelay(10);
492*4882a593Smuzhiyun 
493*4882a593Smuzhiyun 	/*
494*4882a593Smuzhiyun 	 * Enable PLL (Clock Config 1)
495*4882a593Smuzhiyun 	 */
496*4882a593Smuzhiyun 	writel(0x8FF60007, MVEBU_LCD_CLK_CFG_1);
497*4882a593Smuzhiyun 
498*4882a593Smuzhiyun 	return 0;
499*4882a593Smuzhiyun }
500*4882a593Smuzhiyun 
board_video_init(void)501*4882a593Smuzhiyun int __weak board_video_init(void)
502*4882a593Smuzhiyun {
503*4882a593Smuzhiyun 	return -1;
504*4882a593Smuzhiyun }
505*4882a593Smuzhiyun 
video_hw_init(void)506*4882a593Smuzhiyun void *video_hw_init(void)
507*4882a593Smuzhiyun {
508*4882a593Smuzhiyun 	static GraphicDevice mvebufb;
509*4882a593Smuzhiyun 	GraphicDevice *pGD = &mvebufb;
510*4882a593Smuzhiyun 	u32 val;
511*4882a593Smuzhiyun 
512*4882a593Smuzhiyun 	/*
513*4882a593Smuzhiyun 	 * The board code needs to call mvebu_lcd_register_init()
514*4882a593Smuzhiyun 	 * in its board_video_init() implementation, with the board
515*4882a593Smuzhiyun 	 * specific parameters for its LCD.
516*4882a593Smuzhiyun 	 */
517*4882a593Smuzhiyun 	if (board_video_init() || !readl(MVEBU_LCD_CFG_GRA_START_ADDR0))
518*4882a593Smuzhiyun 		return NULL;
519*4882a593Smuzhiyun 
520*4882a593Smuzhiyun 	/* Provide the necessary values for the U-Boot video IF */
521*4882a593Smuzhiyun 	val = readl(MVEBU_LCD_SPU_V_H_ACTIVE);
522*4882a593Smuzhiyun 	pGD->winSizeY = val >> 16;
523*4882a593Smuzhiyun 	pGD->winSizeX = val & 0x0000ffff;
524*4882a593Smuzhiyun 	pGD->gdfBytesPP = 2;
525*4882a593Smuzhiyun 	pGD->gdfIndex = GDF_15BIT_555RGB;
526*4882a593Smuzhiyun 	pGD->frameAdrs = readl(MVEBU_LCD_CFG_GRA_START_ADDR0);
527*4882a593Smuzhiyun 
528*4882a593Smuzhiyun 	debug("LCD: buffer at 0x%08x resolution %dx%d\n", pGD->frameAdrs,
529*4882a593Smuzhiyun 	      pGD->winSizeX, pGD->winSizeY);
530*4882a593Smuzhiyun 
531*4882a593Smuzhiyun 	return pGD;
532*4882a593Smuzhiyun }
533