xref: /openbmc/u-boot/drivers/video/mvebu_lcd.c (revision 50e24381)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2913d1be2SStefan Roese /*
3913d1be2SStefan Roese  * Video driver for Marvell Armada XP SoC
4913d1be2SStefan Roese  *
5913d1be2SStefan Roese  * Initialization of LCD interface and setup of SPLASH screen image
6913d1be2SStefan Roese  */
7913d1be2SStefan Roese 
8913d1be2SStefan Roese #include <common.h>
9*6d9a98c5SStefan Roese #include <dm.h>
10*6d9a98c5SStefan Roese #include <video.h>
11913d1be2SStefan Roese #include <linux/mbus.h>
12913d1be2SStefan Roese #include <asm/io.h>
13913d1be2SStefan Roese #include <asm/arch/cpu.h>
14913d1be2SStefan Roese #include <asm/arch/soc.h>
15913d1be2SStefan Roese 
16*6d9a98c5SStefan Roese #define MVEBU_LCD_WIN_CONTROL(w)	(0xf000 + ((w) << 4))
17*6d9a98c5SStefan Roese #define MVEBU_LCD_WIN_BASE(w)		(0xf004 + ((w) << 4))
18*6d9a98c5SStefan Roese #define MVEBU_LCD_WIN_REMAP(w)		(0xf00c + ((w) << 4))
19913d1be2SStefan Roese 
20*6d9a98c5SStefan Roese #define MVEBU_LCD_CFG_DMA_START_ADDR_0	0x00cc
21*6d9a98c5SStefan Roese #define MVEBU_LCD_CFG_DMA_START_ADDR_1	0x00dc
22913d1be2SStefan Roese 
23*6d9a98c5SStefan Roese #define MVEBU_LCD_CFG_GRA_START_ADDR0	0x00f4
24*6d9a98c5SStefan Roese #define MVEBU_LCD_CFG_GRA_START_ADDR1	0x00f8
25*6d9a98c5SStefan Roese #define MVEBU_LCD_CFG_GRA_PITCH		0x00fc
26*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_GRA_OVSA_HPXL_VLN	0x0100
27*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_GRA_HPXL_VLN	0x0104
28*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_GZM_HPXL_VLN	0x0108
29*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_HWC_OVSA_HPXL_VLN	0x010c
30*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_HWC_HPXL_VLN	0x0110
31*6d9a98c5SStefan Roese #define MVEBU_LCD_SPUT_V_H_TOTAL	0x0114
32*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_V_H_ACTIVE	0x0118
33*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_H_PORCH		0x011c
34*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_V_PORCH		0x0120
35*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_BLANKCOLOR	0x0124
36*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_ALPHA_COLOR1	0x0128
37*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_ALPHA_COLOR2	0x012c
38*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_COLORKEY_Y	0x0130
39*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_COLORKEY_U	0x0134
40*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_COLORKEY_V	0x0138
41*6d9a98c5SStefan Roese #define MVEBU_LCD_CFG_RDREG4F		0x013c
42*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_SPI_RXDATA	0x0140
43*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_ISA_RXDATA	0x0144
44*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_DBG_ISA		0x0148
45913d1be2SStefan Roese 
46*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_HWC_RDDAT		0x0158
47*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_GAMMA_RDDAT	0x015c
48*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_PALETTE_RDDAT	0x0160
49*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_IOPAD_IN		0x0178
50*6d9a98c5SStefan Roese #define MVEBU_LCD_FRAME_COUNT		0x017c
51*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_DMA_CTRL0		0x0190
52*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_DMA_CTRL1		0x0194
53*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_SRAM_CTRL		0x0198
54*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_SRAM_WRDAT	0x019c
55*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_SRAM_PARA0	0x01a0
56*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_SRAM_PARA1	0x01a4
57*6d9a98c5SStefan Roese #define MVEBU_LCD_CFG_SCLK_DIV		0x01a8
58*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_CONTRAST		0x01ac
59*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_SATURATION	0x01b0
60*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_CBSH_HUE		0x01b4
61*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_DUMB_CTRL		0x01b8
62*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_IOPAD_CONTROL	0x01bc
63*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_IRQ_ENA_2		0x01d8
64*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_IRQ_ISR_2		0x01dc
65*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_IRQ_ENA		0x01c0
66*6d9a98c5SStefan Roese #define MVEBU_LCD_SPU_IRQ_ISR		0x01c4
67*6d9a98c5SStefan Roese #define MVEBU_LCD_ADLL_CTRL		0x01c8
68*6d9a98c5SStefan Roese #define MVEBU_LCD_CLK_DIS		0x01cc
69*6d9a98c5SStefan Roese #define MVEBU_LCD_VGA_HVSYNC_DELAY	0x01d4
70*6d9a98c5SStefan Roese #define MVEBU_LCD_CLK_CFG_0		0xf0a0
71*6d9a98c5SStefan Roese #define MVEBU_LCD_CLK_CFG_1		0xf0a4
72*6d9a98c5SStefan Roese #define MVEBU_LCD_LVDS_CLK_CFG		0xf0ac
73913d1be2SStefan Roese 
74913d1be2SStefan Roese #define MVEBU_LVDS_PADS_REG		(MVEBU_SYSTEM_REG_BASE + 0xf0)
75913d1be2SStefan Roese 
76*6d9a98c5SStefan Roese enum {
77*6d9a98c5SStefan Roese 	/* Maximum LCD size we support */
78*6d9a98c5SStefan Roese 	LCD_MAX_WIDTH		= 640,
79*6d9a98c5SStefan Roese 	LCD_MAX_HEIGHT		= 480,
80*6d9a98c5SStefan Roese 	LCD_MAX_LOG2_BPP	= VIDEO_BPP16,
81*6d9a98c5SStefan Roese };
82*6d9a98c5SStefan Roese 
83*6d9a98c5SStefan Roese struct mvebu_lcd_info {
84*6d9a98c5SStefan Roese 	u32 fb_base;
85*6d9a98c5SStefan Roese 	int x_res;
86*6d9a98c5SStefan Roese 	int y_res;
87*6d9a98c5SStefan Roese 	int x_fp;
88*6d9a98c5SStefan Roese 	int y_fp;
89*6d9a98c5SStefan Roese 	int x_bp;
90*6d9a98c5SStefan Roese 	int y_bp;
91*6d9a98c5SStefan Roese };
92*6d9a98c5SStefan Roese 
93*6d9a98c5SStefan Roese struct mvebu_video_priv {
94*6d9a98c5SStefan Roese 	uintptr_t regs;
95*6d9a98c5SStefan Roese };
96*6d9a98c5SStefan Roese 
97913d1be2SStefan Roese /* Setup Mbus Bridge Windows for LCD */
mvebu_lcd_conf_mbus_registers(uintptr_t regs)98*6d9a98c5SStefan Roese static void mvebu_lcd_conf_mbus_registers(uintptr_t regs)
99913d1be2SStefan Roese {
100913d1be2SStefan Roese 	const struct mbus_dram_target_info *dram;
101913d1be2SStefan Roese 	int i;
102913d1be2SStefan Roese 
103913d1be2SStefan Roese 	dram = mvebu_mbus_dram_info();
104913d1be2SStefan Roese 
105913d1be2SStefan Roese 	/* Disable windows, set size/base/remap to 0  */
106913d1be2SStefan Roese 	for (i = 0; i < 6; i++) {
107*6d9a98c5SStefan Roese 		writel(0, regs + MVEBU_LCD_WIN_CONTROL(i));
108*6d9a98c5SStefan Roese 		writel(0, regs + MVEBU_LCD_WIN_BASE(i));
109*6d9a98c5SStefan Roese 		writel(0, regs + MVEBU_LCD_WIN_REMAP(i));
110913d1be2SStefan Roese 	}
111913d1be2SStefan Roese 
112913d1be2SStefan Roese 	/* Write LCD bridge window registers */
113913d1be2SStefan Roese 	for (i = 0; i < dram->num_cs; i++) {
114913d1be2SStefan Roese 		const struct mbus_dram_window *cs = dram->cs + i;
115913d1be2SStefan Roese 		writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
116913d1be2SStefan Roese 		       (dram->mbus_dram_target_id << 4) | 1,
117*6d9a98c5SStefan Roese 		       regs + MVEBU_LCD_WIN_CONTROL(i));
118913d1be2SStefan Roese 
119*6d9a98c5SStefan Roese 		writel(cs->base & 0xffff0000, regs + MVEBU_LCD_WIN_BASE(i));
120913d1be2SStefan Roese 	}
121913d1be2SStefan Roese }
122913d1be2SStefan Roese 
123913d1be2SStefan Roese /* Initialize LCD registers */
mvebu_lcd_register_init(struct mvebu_lcd_info * lcd_info,uintptr_t regs)124*6d9a98c5SStefan Roese static void mvebu_lcd_register_init(struct mvebu_lcd_info *lcd_info,
125*6d9a98c5SStefan Roese 				    uintptr_t regs)
126913d1be2SStefan Roese {
127913d1be2SStefan Roese 	/* Local variable for easier handling */
128913d1be2SStefan Roese 	int x = lcd_info->x_res;
129913d1be2SStefan Roese 	int y = lcd_info->y_res;
130913d1be2SStefan Roese 	u32 val;
131913d1be2SStefan Roese 
132913d1be2SStefan Roese 	/* Setup Mbus Bridge Windows */
133*6d9a98c5SStefan Roese 	mvebu_lcd_conf_mbus_registers(regs);
134913d1be2SStefan Roese 
135913d1be2SStefan Roese 	/*
136913d1be2SStefan Roese 	 * Set LVDS Pads Control Register
137913d1be2SStefan Roese 	 * wr 0 182F0 FFE00000
138913d1be2SStefan Roese 	 */
139913d1be2SStefan Roese 	clrbits_le32(MVEBU_LVDS_PADS_REG, 0x1f << 16);
140913d1be2SStefan Roese 
141913d1be2SStefan Roese 	/*
142913d1be2SStefan Roese 	 * Set the LCD_CFG_GRA_START_ADDR0/1 Registers
143913d1be2SStefan Roese 	 * This is supposed to point to the "physical" memory at memory
144913d1be2SStefan Roese 	 * end (currently 1GB-64MB but also may be 2GB-64MB).
145913d1be2SStefan Roese 	 * See also the Window 0 settings!
146913d1be2SStefan Roese 	 */
147*6d9a98c5SStefan Roese 	writel(lcd_info->fb_base, regs + MVEBU_LCD_CFG_GRA_START_ADDR0);
148*6d9a98c5SStefan Roese 	writel(lcd_info->fb_base, regs + MVEBU_LCD_CFG_GRA_START_ADDR1);
149913d1be2SStefan Roese 
150913d1be2SStefan Roese 	/*
151913d1be2SStefan Roese 	 * Set the LCD_CFG_GRA_PITCH Register
152913d1be2SStefan Roese 	 * Bits 31-28: Duty Cycle of Backlight. value/16=High (0x8=Mid Setting)
153913d1be2SStefan Roese 	 * Bits 25-16: Backlight divider from 32kHz Clock
154913d1be2SStefan Roese 	 *             (here 16=0x10 for 1kHz)
155913d1be2SStefan Roese 	 * Bits 15-00: Line Length in Bytes
156913d1be2SStefan Roese 	 *             240*2 (for RGB1555)=480=0x1E0
157913d1be2SStefan Roese 	 */
158*6d9a98c5SStefan Roese 	writel(0x80100000 + 2 * x, regs + MVEBU_LCD_CFG_GRA_PITCH);
159913d1be2SStefan Roese 
160913d1be2SStefan Roese 	/*
161913d1be2SStefan Roese 	 * Set the LCD_SPU_GRA_OVSA_HPXL_VLN Register
162913d1be2SStefan Roese 	 * Bits 31-16: Vertical start of graphical overlay on screen
163913d1be2SStefan Roese 	 * Bits 15-00: Horizontal start of graphical overlay on screen
164913d1be2SStefan Roese 	 */
165*6d9a98c5SStefan Roese 	writel(0x00000000, regs + MVEBU_LCD_SPU_GRA_OVSA_HPXL_VLN);
166913d1be2SStefan Roese 
167913d1be2SStefan Roese 	/*
168913d1be2SStefan Roese 	 * Set the LCD_SPU_GRA_HPXL_VLN Register
169913d1be2SStefan Roese 	 * Bits 31-16: Vertical size of graphical overlay 320=0x140
170913d1be2SStefan Roese 	 * Bits 15-00: Horizontal size of graphical overlay 240=0xF0
171913d1be2SStefan Roese 	 * Values before zooming
172913d1be2SStefan Roese 	 */
173*6d9a98c5SStefan Roese 	writel((y << 16) | x, regs + MVEBU_LCD_SPU_GRA_HPXL_VLN);
174913d1be2SStefan Roese 
175913d1be2SStefan Roese 	/*
176913d1be2SStefan Roese 	 * Set the LCD_SPU_GZM_HPXL_VLN Register
177913d1be2SStefan Roese 	 * Bits 31-16: Vertical size of graphical overlay 320=0x140
178913d1be2SStefan Roese 	 * Bits 15-00: Horizontal size of graphical overlay 240=0xF0
179913d1be2SStefan Roese 	 * Values after zooming
180913d1be2SStefan Roese 	 */
181*6d9a98c5SStefan Roese 	writel((y << 16) | x, regs + MVEBU_LCD_SPU_GZM_HPXL_VLN);
182913d1be2SStefan Roese 
183913d1be2SStefan Roese 	/*
184913d1be2SStefan Roese 	 * Set the LCD_SPU_HWC_OVSA_HPXL_VLN Register
185913d1be2SStefan Roese 	 * Bits 31-16: Vertical position of HW Cursor 320=0x140
186913d1be2SStefan Roese 	 * Bits 15-00: Horizontal position of HW Cursor 240=0xF0
187913d1be2SStefan Roese 	 */
188*6d9a98c5SStefan Roese 	writel((y << 16) | x, regs + MVEBU_LCD_SPU_HWC_OVSA_HPXL_VLN);
189913d1be2SStefan Roese 
190913d1be2SStefan Roese 	/*
191913d1be2SStefan Roese 	 * Set the LCD_SPU_HWC_OVSA_HPXL_VLN Register
192913d1be2SStefan Roese 	 * Bits 31-16: Vertical size of HW Cursor
193913d1be2SStefan Roese 	 * Bits 15-00: Horizontal size of HW Cursor
194913d1be2SStefan Roese 	 */
195*6d9a98c5SStefan Roese 	writel(0x00000000, regs + MVEBU_LCD_SPU_HWC_HPXL_VLN);
196913d1be2SStefan Roese 
197913d1be2SStefan Roese 	/*
198913d1be2SStefan Roese 	 * Set the LCD_SPU_HWC_OVSA_HPXL_VLN Register
199913d1be2SStefan Roese 	 * Bits 31-16: Screen total vertical lines:
200913d1be2SStefan Roese 	 *             VSYNC                = 1
201913d1be2SStefan Roese 	 *             Vertical Front Porch = 2
202913d1be2SStefan Roese 	 *             Vertical Lines       = 320
203913d1be2SStefan Roese 	 *             Vertical Back Porch  = 2
204913d1be2SStefan Roese 	 *             SUM                  = 325 = 0x0145
205913d1be2SStefan Roese 	 * Bits 15-00: Screen total horizontal pixels:
206913d1be2SStefan Roese 	 *             HSYNC                  = 1
207913d1be2SStefan Roese 	 *             Horizontal Front Porch = 44
208913d1be2SStefan Roese 	 *             Horizontal Lines       = 240
209913d1be2SStefan Roese 	 *             Horizontal Back Porch  = 2
210913d1be2SStefan Roese 	 *             SUM                    = 287 = 0x011F
211913d1be2SStefan Roese 	 * Note: For the display the backporch is between SYNC and
212913d1be2SStefan Roese 	 *       the start of the pixels.
213913d1be2SStefan Roese 	 *       This is not certain for the Marvell (!?)
214913d1be2SStefan Roese 	 */
215913d1be2SStefan Roese 	val = ((y + lcd_info->y_fp + lcd_info->y_bp + 1) << 16) |
216913d1be2SStefan Roese 		(x + lcd_info->x_fp + lcd_info->x_bp + 1);
217*6d9a98c5SStefan Roese 	writel(val, regs + MVEBU_LCD_SPUT_V_H_TOTAL);
218913d1be2SStefan Roese 
219913d1be2SStefan Roese 	/*
220913d1be2SStefan Roese 	 * Set the LCD_SPU_V_H_ACTIVE Register
221913d1be2SStefan Roese 	 * Bits 31-16: Screen active vertical lines 320=0x140
222913d1be2SStefan Roese 	 * Bits 15-00: Screen active horizontakl pixels 240=0x00F0
223913d1be2SStefan Roese 	 */
224*6d9a98c5SStefan Roese 	writel((y << 16) | x, regs + MVEBU_LCD_SPU_V_H_ACTIVE);
225913d1be2SStefan Roese 
226913d1be2SStefan Roese 	/*
227913d1be2SStefan Roese 	 * Set the LCD_SPU_H_PORCH Register
228913d1be2SStefan Roese 	 * Bits 31-16: Screen horizontal backporch 44=0x2c
229913d1be2SStefan Roese 	 * Bits 15-00: Screen horizontal frontporch 2=0x02
230913d1be2SStefan Roese 	 * Note: The terms "front" and "back" for the Marvell seem to be
231913d1be2SStefan Roese 	 *       exactly opposite to the display.
232913d1be2SStefan Roese 	 */
233*6d9a98c5SStefan Roese 	writel((lcd_info->x_fp << 16) | lcd_info->x_bp,
234*6d9a98c5SStefan Roese 	       regs + MVEBU_LCD_SPU_H_PORCH);
235913d1be2SStefan Roese 
236913d1be2SStefan Roese 	/*
237913d1be2SStefan Roese 	 * Set the LCD_SPU_V_PORCH Register
238913d1be2SStefan Roese 	 * Bits 31-16: Screen vertical backporch  2=0x02
239913d1be2SStefan Roese 	 * Bits 15-00: Screen vertical frontporch 2=0x02
240913d1be2SStefan Roese 	 * Note: The terms "front" and "back" for the Marvell seem to be exactly
241913d1be2SStefan Roese 	 *       opposite to the display.
242913d1be2SStefan Roese 	 */
243*6d9a98c5SStefan Roese 	writel((lcd_info->y_fp << 16) | lcd_info->y_bp,
244*6d9a98c5SStefan Roese 	       regs + MVEBU_LCD_SPU_V_PORCH);
245913d1be2SStefan Roese 
246913d1be2SStefan Roese 	/*
247913d1be2SStefan Roese 	 * Set the LCD_SPU_BLANKCOLOR Register
248913d1be2SStefan Roese 	 * This should be black = 0
249913d1be2SStefan Roese 	 * For tests this is magenta=00FF00FF
250913d1be2SStefan Roese 	 */
251*6d9a98c5SStefan Roese 	writel(0x00FF00FF, regs + MVEBU_LCD_SPU_BLANKCOLOR);
252913d1be2SStefan Roese 
253913d1be2SStefan Roese 	/*
254913d1be2SStefan Roese 	 * Registers in the range of 0x0128 to 0x012C are colors for the cursor
255913d1be2SStefan Roese 	 * Registers in the range of 0x0130 to 0x0138 are colors for video
256913d1be2SStefan Roese 	 * color keying
257913d1be2SStefan Roese 	 */
258913d1be2SStefan Roese 
259913d1be2SStefan Roese 	/*
260913d1be2SStefan Roese 	 * Set the LCD_SPU_RDREG4F Register
261913d1be2SStefan Roese 	 * Bits 31-12: Reservd
262913d1be2SStefan Roese 	 * Bit     11: SRAM Wait
263913d1be2SStefan Roese 	 * Bit     10: Smart display fast TX (must be 1)
264913d1be2SStefan Roese 	 * Bit      9: DMA Arbitration Video/Graphics overlay: 0=interleaved
265913d1be2SStefan Roese 	 * Bit      8: FIFO watermark for DMA: 0=disable
266913d1be2SStefan Roese 	 * Bits 07-00: Empty 8B FIFO entries to trigger DMA, default=0x80
267913d1be2SStefan Roese 	 */
268*6d9a98c5SStefan Roese 	writel(0x00000780, regs + MVEBU_LCD_CFG_RDREG4F);
269913d1be2SStefan Roese 
270913d1be2SStefan Roese 	/*
271913d1be2SStefan Roese 	 * Set the LCD_SPU_DMACTRL 0 Register
272913d1be2SStefan Roese 	 * Bit     31: Disable overlay blending 1=disable
273913d1be2SStefan Roese 	 * Bit     30: Gamma correction enable, 0=disable
274913d1be2SStefan Roese 	 * Bit     29: Video Contrast/Saturation/Hue Adjust enable, 0=disable
275913d1be2SStefan Roese 	 * Bit     28: Color palette enable, 0=disable
276913d1be2SStefan Roese 	 * Bit     27: DMA AXI Arbiter, 1=default
277913d1be2SStefan Roese 	 * Bit     26: HW Cursor 1-bit mode
278913d1be2SStefan Roese 	 * Bit     25: HW Cursor or 1- or 2-bit mode
279913d1be2SStefan Roese 	 * Bit     24: HW Cursor enabled, 0=disable
280913d1be2SStefan Roese 	 * Bits 23-20: Graphics Memory Color Format: 0x1=RGB1555
281913d1be2SStefan Roese 	 * Bits 19-16: Video Memory Color Format:    0x1=RGB1555
282913d1be2SStefan Roese 	 * Bit     15: Memory Toggle between frame 0 and 1: 0=disable
283913d1be2SStefan Roese 	 * Bit     14: Graphics horizontal scaling enable: 0=disable
284913d1be2SStefan Roese 	 * Bit     13: Graphics test mode: 0=disable
285913d1be2SStefan Roese 	 * Bit     12: Graphics SWAP R and B: 0=disable
286913d1be2SStefan Roese 	 * Bit     11: Graphics SWAP U and V: 0=disable
287913d1be2SStefan Roese 	 * Bit     10: Graphics SWAP Y and U/V: 0=disable
288913d1be2SStefan Roese 	 * Bit     09: Graphic YUV to RGB Conversion: 0=disable
289913d1be2SStefan Roese 	 * Bit     08: Graphic Transfer: 1=enable
290913d1be2SStefan Roese 	 * Bit     07: Memory Toggle: 0=disable
291913d1be2SStefan Roese 	 * Bit     06: Video horizontal scaling enable: 0=disable
292913d1be2SStefan Roese 	 * Bit     05: Video test mode: 0=disable
293913d1be2SStefan Roese 	 * Bit     04: Video SWAP R and B: 0=disable
294913d1be2SStefan Roese 	 * Bit     03: Video SWAP U and V: 0=disable
295913d1be2SStefan Roese 	 * Bit     02: Video SWAP Y and U/V: 0=disable
296913d1be2SStefan Roese 	 * Bit     01: Video YUV to RGB Conversion: 0=disable
297913d1be2SStefan Roese 	 * Bit     00: Video  Transfer: 0=disable
298913d1be2SStefan Roese 	 */
299*6d9a98c5SStefan Roese 	writel(0x88111100, regs + MVEBU_LCD_SPU_DMA_CTRL0);
300913d1be2SStefan Roese 
301913d1be2SStefan Roese 	/*
302913d1be2SStefan Roese 	 * Set the LCD_SPU_DMA_CTRL1 Register
303913d1be2SStefan Roese 	 * Bit     31: Manual DMA Trigger = 0
304913d1be2SStefan Roese 	 * Bits 30-28: DMA Trigger Source: 0x2 VSYNC
305913d1be2SStefan Roese 	 * Bit     28: VSYNC_INV: 0=Rising Edge, 1=Falling Edge
306913d1be2SStefan Roese 	 * Bits 26-24: Color Key Mode: 0=disable
307913d1be2SStefan Roese 	 * Bit     23: Fill low bits: 0=fill with zeroes
308913d1be2SStefan Roese 	 * Bit     22: Reserved
309913d1be2SStefan Roese 	 * Bit     21: Gated Clock: 0=disable
310913d1be2SStefan Roese 	 * Bit     20: Power Save enable: 0=disable
311913d1be2SStefan Roese 	 * Bits 19-18: Reserved
312913d1be2SStefan Roese 	 * Bits 17-16: Configure Video/Graphic Path: 0x1: Graphic path alpha.
313913d1be2SStefan Roese 	 * Bits 15-08: Configure Alpha: 0x00.
314913d1be2SStefan Roese 	 * Bits 07-00: Reserved.
315913d1be2SStefan Roese 	 */
316*6d9a98c5SStefan Roese 	writel(0x20010000, regs + MVEBU_LCD_SPU_DMA_CTRL1);
317913d1be2SStefan Roese 
318913d1be2SStefan Roese 	/*
319913d1be2SStefan Roese 	 * Set the LCD_SPU_SRAM_CTRL Register
320913d1be2SStefan Roese 	 * Reset to default = 0000C000
321913d1be2SStefan Roese 	 * Bits 15-14: SRAM control: init=0x3, Read=0, Write=2
322913d1be2SStefan Roese 	 * Bits 11-08: SRAM address ID: 0=gamma_yr, 1=gammy_ug, 2=gamma_vb,
323913d1be2SStefan Roese 	 *             3=palette, 15=cursor
324913d1be2SStefan Roese 	 */
325*6d9a98c5SStefan Roese 	writel(0x0000C000, regs + MVEBU_LCD_SPU_SRAM_CTRL);
326913d1be2SStefan Roese 
327913d1be2SStefan Roese 	/*
328913d1be2SStefan Roese 	 * LCD_SPU_SRAM_WRDAT register: 019C
329913d1be2SStefan Roese 	 * LCD_SPU_SRAM_PARA0 register: 01A0
330913d1be2SStefan Roese 	 * LCD_SPU_SRAM_PARA1 register: 01A4 - Cursor control/Power settings
331913d1be2SStefan Roese 	 */
332*6d9a98c5SStefan Roese 	writel(0x00000000, regs + MVEBU_LCD_SPU_SRAM_PARA1);
333913d1be2SStefan Roese 
334913d1be2SStefan Roese 
335913d1be2SStefan Roese 	/* Clock settings in the at 01A8 and in the range F0A0 see below */
336913d1be2SStefan Roese 
337913d1be2SStefan Roese 	/*
338913d1be2SStefan Roese 	 * Set LCD_SPU_CONTRAST
339913d1be2SStefan Roese 	 * Bits 31-16: Brightness sign ext. 8-bit value +255 to -255: default=0
340913d1be2SStefan Roese 	 * Bits 15-00: Contrast sign ext. 8-bit value +255 to -255: default=0
341913d1be2SStefan Roese 	 */
342*6d9a98c5SStefan Roese 	writel(0x00000000, regs + MVEBU_LCD_SPU_CONTRAST);
343913d1be2SStefan Roese 
344913d1be2SStefan Roese 	/*
345913d1be2SStefan Roese 	 * Set LCD_SPU_SATURATION
346913d1be2SStefan Roese 	 * Bits 31-16: Multiplier signed 4.12 fixed point value
347913d1be2SStefan Roese 	 * Bits 15-00: Saturation signed 4.12 fixed point value
348913d1be2SStefan Roese 	 */
349*6d9a98c5SStefan Roese 	writel(0x10001000, regs + MVEBU_LCD_SPU_SATURATION);
350913d1be2SStefan Roese 
351913d1be2SStefan Roese 	/*
352913d1be2SStefan Roese 	 * Set LCD_SPU_HUE
353913d1be2SStefan Roese 	 * Bits 31-16: Sine signed 2.14 fixed point value
354913d1be2SStefan Roese 	 * Bits 15-00: Cosine signed 2.14 fixed point value
355913d1be2SStefan Roese 	 */
356*6d9a98c5SStefan Roese 	writel(0x00000000, regs + MVEBU_LCD_SPU_CBSH_HUE);
357913d1be2SStefan Roese 
358913d1be2SStefan Roese 	/*
359913d1be2SStefan Roese 	 * Set LCD_SPU_DUMB_CTRL
360913d1be2SStefan Roese 	 * Bits 31-28: LCD Type: 3=18 bit RGB | 6=24 bit RGB888
361913d1be2SStefan Roese 	 * Bits 27-12: Reserved
362913d1be2SStefan Roese 	 * Bit     11: LCD DMA Pipeline Enable: 1=Enable
363913d1be2SStefan Roese 	 * Bits 10-09: Reserved
364913d1be2SStefan Roese 	 * Bit      8: LCD GPIO pin (??)
365913d1be2SStefan Roese 	 * Bit      7: Reverse RGB
366913d1be2SStefan Roese 	 * Bit      6: Invert composite blank signal DE/EN (??)
367913d1be2SStefan Roese 	 * Bit      5: Invert composite sync signal
368913d1be2SStefan Roese 	 * Bit      4: Invert Pixel Valid Enable DE/EN (??)
369913d1be2SStefan Roese 	 * Bit      3: Invert VSYNC
370913d1be2SStefan Roese 	 * Bit      2: Invert HSYNC
371913d1be2SStefan Roese 	 * Bit      1: Invert Pixel Clock
372913d1be2SStefan Roese 	 * Bit      0: Enable LCD Panel: 1=Enable
373913d1be2SStefan Roese 	 * Question: Do we have to disable Smart and Dumb LCD
374913d1be2SStefan Roese 	 * and separately enable LVDS?
375913d1be2SStefan Roese 	 */
376*6d9a98c5SStefan Roese 	writel(0x6000080F, regs + MVEBU_LCD_SPU_DUMB_CTRL);
377913d1be2SStefan Roese 
378913d1be2SStefan Roese 	/*
379913d1be2SStefan Roese 	 * Set LCD_SPU_IOPAD_CTRL
380913d1be2SStefan Roese 	 * Bits 31-20: Reserved
381913d1be2SStefan Roese 	 * Bits 19-18: Vertical Interpolation: 0=Disable
382913d1be2SStefan Roese 	 * Bits 17-16: Reserved
383913d1be2SStefan Roese 	 * Bit     15: Graphics Vertical Mirror enable: 0=disable
384913d1be2SStefan Roese 	 * Bit     14: Reserved
385913d1be2SStefan Roese 	 * Bit     13: Video Vertical Mirror enable: 0=disable
386913d1be2SStefan Roese 	 * Bit     12: Reserved
387913d1be2SStefan Roese 	 * Bit     11: Command Vertical Mirror enable: 0=disable
388913d1be2SStefan Roese 	 * Bit     10: Reserved
389913d1be2SStefan Roese 	 * Bits 09-08: YUV to RGB Color space conversion: 0 (Not used)
390913d1be2SStefan Roese 	 * Bits 07-04: AXI Bus Master: 0x4: no crossing of 4k boundary,
391913d1be2SStefan Roese 	 *             128 Bytes burst
392913d1be2SStefan Roese 	 * Bits 03-00: LCD pins: ??? 0=24-bit Dump panel ??
393913d1be2SStefan Roese 	 */
394*6d9a98c5SStefan Roese 	writel(0x000000C0, regs + MVEBU_LCD_SPU_IOPAD_CONTROL);
395913d1be2SStefan Roese 
396913d1be2SStefan Roese 	/*
397913d1be2SStefan Roese 	 * Set SUP_IRQ_ENA_2: Disable all interrupts
398913d1be2SStefan Roese 	 */
399*6d9a98c5SStefan Roese 	writel(0x00000000, regs + MVEBU_LCD_SPU_IRQ_ENA_2);
400913d1be2SStefan Roese 
401913d1be2SStefan Roese 	/*
402913d1be2SStefan Roese 	 * Set SUP_IRQ_ENA: Disable all interrupts.
403913d1be2SStefan Roese 	 */
404*6d9a98c5SStefan Roese 	writel(0x00000000, regs + MVEBU_LCD_SPU_IRQ_ENA);
405913d1be2SStefan Roese 
406913d1be2SStefan Roese 	/*
407913d1be2SStefan Roese 	 * Set up ADDL Control Register
408913d1be2SStefan Roese 	 * Bits 31-29: 0x0 = Fastest Delay Line (default)
409913d1be2SStefan Roese 	 *             0x3 = Slowest Delay Line (default)
410913d1be2SStefan Roese 	 * Bit     28: Calibration done status.
411913d1be2SStefan Roese 	 * Bit     27: Reserved
412913d1be2SStefan Roese 	 * Bit     26: Set Pixel Clock to ADDL output
413913d1be2SStefan Roese 	 * Bit     25: Reduce CAL Enable
414913d1be2SStefan Roese 	 * Bits 24-22: Manual calibration value.
415913d1be2SStefan Roese 	 * Bit     21: Manual calibration enable.
416913d1be2SStefan Roese 	 * Bit     20: Restart Auto Cal
417913d1be2SStefan Roese 	 * Bits 19-16: Calibration Threshold voltage, default= 0x2
418913d1be2SStefan Roese 	 * Bite 15-14: Reserved
419913d1be2SStefan Roese 	 * Bits 13-11: Divisor for ADDL Clock: 0x1=/2, 0x3=/8, 0x5=/16
420913d1be2SStefan Roese 	 * Bit     10: Power Down ADDL module, default = 1!
421913d1be2SStefan Roese 	 * Bits 09-08: Test point configuration: 0x2=Bias, 0x3=High-z
422913d1be2SStefan Roese 	 * Bit     07: Reset ADDL
423913d1be2SStefan Roese 	 * Bit     06: Invert ADLL Clock
424913d1be2SStefan Roese 	 * Bits 05-00: Delay taps, 0x3F=Half Cycle, 0x00=No delay
425913d1be2SStefan Roese 	 * Note: ADLL is used for a VGA interface with DAC - not used here
426913d1be2SStefan Roese 	 */
427*6d9a98c5SStefan Roese 	writel(0x00000000, regs + MVEBU_LCD_ADLL_CTRL);
428913d1be2SStefan Roese 
429913d1be2SStefan Roese 	/*
430913d1be2SStefan Roese 	 * Set the LCD_CLK_DIS Register:
431913d1be2SStefan Roese 	 * Bits 3 and 4 must be 1
432913d1be2SStefan Roese 	 */
433*6d9a98c5SStefan Roese 	writel(0x00000018, regs + MVEBU_LCD_CLK_DIS);
434913d1be2SStefan Roese 
435913d1be2SStefan Roese 	/*
436913d1be2SStefan Roese 	 * Set the LCD_VGA_HSYNC/VSYNC Delay Register:
437913d1be2SStefan Roese 	 * Bits 03-00: Sets the delay for the HSYNC and VSYNC signals
438913d1be2SStefan Roese 	 */
439*6d9a98c5SStefan Roese 	writel(0x00000000, regs + MVEBU_LCD_VGA_HVSYNC_DELAY);
440913d1be2SStefan Roese 
441913d1be2SStefan Roese 	/*
442913d1be2SStefan Roese 	 * Clock registers
443913d1be2SStefan Roese 	 * See page 475 in the functional spec.
444913d1be2SStefan Roese 	 */
445913d1be2SStefan Roese 
446913d1be2SStefan Roese 	/* Step 1 and 2: Disable the PLL */
447913d1be2SStefan Roese 
448913d1be2SStefan Roese 	/*
449913d1be2SStefan Roese 	 * Disable PLL, see "LCD Clock Configuration 1 Register" below
450913d1be2SStefan Roese 	 */
451*6d9a98c5SStefan Roese 	writel(0x8FF40007, regs + MVEBU_LCD_CLK_CFG_1);
452913d1be2SStefan Roese 
453913d1be2SStefan Roese 	/*
454913d1be2SStefan Roese 	 * Powerdown, see "LCD Clock Configuration 0 Register" below
455913d1be2SStefan Roese 	 */
456*6d9a98c5SStefan Roese 	writel(0x94000174, regs + MVEBU_LCD_CLK_CFG_0);
457913d1be2SStefan Roese 
458913d1be2SStefan Roese 	/*
459913d1be2SStefan Roese 	 * Set the LCD_CFG_SCLK_DIV Register
460913d1be2SStefan Roese 	 * This is set fix to 0x40000001 for the LVDS output:
461913d1be2SStefan Roese 	 * Bits 31-30: SCLCK Source: 0=AXIBus, 1=AHBus, 2=PLLDivider0
462913d1be2SStefan Roese 	 * Bits 15-01: Clock Divider: Bypass for LVDS=0x0001
463913d1be2SStefan Roese 	 * See page 475 in section 28.5.
464913d1be2SStefan Roese 	 */
465*6d9a98c5SStefan Roese 	writel(0x80000001, regs + MVEBU_LCD_CFG_SCLK_DIV);
466913d1be2SStefan Roese 
467913d1be2SStefan Roese 	/*
468913d1be2SStefan Roese 	 * Set the LCD Clock Configuration 0 Register:
469913d1be2SStefan Roese 	 * Bit     31: Powerdown: 0=Power up
470913d1be2SStefan Roese 	 * Bits 30-29: Reserved
471913d1be2SStefan Roese 	 * Bits 28-26: PLL_KDIV: This encodes K
472913d1be2SStefan Roese 	 *             K=16 => 0x5
473913d1be2SStefan Roese 	 * Bits 25-17: PLL_MDIV: This is M-1:
474913d1be2SStefan Roese 	 *             M=1 => 0x0
475913d1be2SStefan Roese 	 * Bits 16-13: VCO band: 0x1 for 700-920MHz
476913d1be2SStefan Roese 	 * Bits 12-04: PLL_NDIV: This is N-1 and corresponds to R1_CTRL!
477913d1be2SStefan Roese 	 *             N=28=0x1C => 0x1B
478913d1be2SStefan Roese 	 * Bits 03-00: R1_CTRL (for N=28 => 0x4)
479913d1be2SStefan Roese 	 */
480*6d9a98c5SStefan Roese 	writel(0x940021B4, regs + MVEBU_LCD_CLK_CFG_0);
481913d1be2SStefan Roese 
482913d1be2SStefan Roese 	/*
483913d1be2SStefan Roese 	 * Set the LCD Clock Configuration 1 Register:
484913d1be2SStefan Roese 	 * Bits 31-19: Reserved
485913d1be2SStefan Roese 	 * Bit     18: Select PLL: Core PLL, 1=Dedicated PPL
486913d1be2SStefan Roese 	 * Bit     17: Clock Output Enable: 0=disable, 1=enable
487913d1be2SStefan Roese 	 * Bit     16: Select RefClk: 0=RefClk (25MHz), 1=External
488913d1be2SStefan Roese 	 * Bit     15: Half-Div, Device Clock by DIV+0.5*Half-Dev
489913d1be2SStefan Roese 	 * Bits 14-13: Reserved
490913d1be2SStefan Roese 	 * Bits 12-00: PLL Full Divider [Note: Assumed to be the Post-Divider
491913d1be2SStefan Roese 	 *             M' for LVDS=7!]
492913d1be2SStefan Roese 	 */
493*6d9a98c5SStefan Roese 	writel(0x8FF40007, regs + MVEBU_LCD_CLK_CFG_1);
494913d1be2SStefan Roese 
495913d1be2SStefan Roese 	/*
496913d1be2SStefan Roese 	 * Set the LVDS Clock Configuration Register:
497913d1be2SStefan Roese 	 * Bit     31: Clock Gating for the input clock to the LVDS
498913d1be2SStefan Roese 	 * Bit     30: LVDS Serializer enable: 1=Enabled
499913d1be2SStefan Roese 	 * Bits 29-11: Reserved
500913d1be2SStefan Roese 	 * Bit  11-08: LVDS Clock delay: 0x02 (default): by 2 pixel clock/7
501913d1be2SStefan Roese 	 * Bits 07-02: Reserved
502913d1be2SStefan Roese 	 * Bit     01: 24bbp Option: 0=Option_1,1=Option2
503913d1be2SStefan Roese 	 * Bit     00: 1=24bbp Panel: 0=18bpp Panel
504913d1be2SStefan Roese 	 * Note: Bits 0 and must be verified with the help of the
505913d1be2SStefan Roese 	 *       Interface/display
506913d1be2SStefan Roese 	 */
507*6d9a98c5SStefan Roese 	writel(0xC0000201, regs + MVEBU_LCD_LVDS_CLK_CFG);
508913d1be2SStefan Roese 
509913d1be2SStefan Roese 	/*
510913d1be2SStefan Roese 	 * Power up PLL (Clock Config 0)
511913d1be2SStefan Roese 	 */
512*6d9a98c5SStefan Roese 	writel(0x140021B4, regs + MVEBU_LCD_CLK_CFG_0);
513913d1be2SStefan Roese 
514913d1be2SStefan Roese 	/* wait 10 ms */
515913d1be2SStefan Roese 	mdelay(10);
516913d1be2SStefan Roese 
517913d1be2SStefan Roese 	/*
518913d1be2SStefan Roese 	 * Enable PLL (Clock Config 1)
519913d1be2SStefan Roese 	 */
520*6d9a98c5SStefan Roese 	writel(0x8FF60007, regs + MVEBU_LCD_CLK_CFG_1);
521*6d9a98c5SStefan Roese }
522*6d9a98c5SStefan Roese 
mvebu_video_probe(struct udevice * dev)523*6d9a98c5SStefan Roese static int mvebu_video_probe(struct udevice *dev)
524*6d9a98c5SStefan Roese {
525*6d9a98c5SStefan Roese 	struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
526*6d9a98c5SStefan Roese 	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
527*6d9a98c5SStefan Roese 	struct mvebu_video_priv *priv = dev_get_priv(dev);
528*6d9a98c5SStefan Roese 	struct mvebu_lcd_info lcd_info;
529*6d9a98c5SStefan Roese 	struct display_timing timings;
530*6d9a98c5SStefan Roese 	u32 fb_start, fb_end;
531*6d9a98c5SStefan Roese 	int ret;
532*6d9a98c5SStefan Roese 
533*6d9a98c5SStefan Roese 	priv->regs = dev_read_addr(dev);
534*6d9a98c5SStefan Roese 	if (priv->regs == FDT_ADDR_T_NONE) {
535*6d9a98c5SStefan Roese 		dev_err(dev, "failed to get LCD address\n");
536*6d9a98c5SStefan Roese 		return -ENXIO;
537*6d9a98c5SStefan Roese 	}
538*6d9a98c5SStefan Roese 
539*6d9a98c5SStefan Roese 	ret = ofnode_decode_display_timing(dev_ofnode(dev), 0, &timings);
540*6d9a98c5SStefan Roese 	if (ret) {
541*6d9a98c5SStefan Roese 		dev_err(dev, "failed to get any display timings\n");
542*6d9a98c5SStefan Roese 		return -EINVAL;
543*6d9a98c5SStefan Roese 	}
544*6d9a98c5SStefan Roese 
545*6d9a98c5SStefan Roese 	/* Use DT timing (resolution) in internal info struct */
546*6d9a98c5SStefan Roese 	lcd_info.fb_base = plat->base;
547*6d9a98c5SStefan Roese 	lcd_info.x_res = timings.hactive.typ;
548*6d9a98c5SStefan Roese 	lcd_info.x_fp = timings.hfront_porch.typ;
549*6d9a98c5SStefan Roese 	lcd_info.x_bp = timings.hback_porch.typ;
550*6d9a98c5SStefan Roese 	lcd_info.y_res = timings.vactive.typ;
551*6d9a98c5SStefan Roese 	lcd_info.y_fp = timings.vfront_porch.typ;
552*6d9a98c5SStefan Roese 	lcd_info.y_bp = timings.vback_porch.typ;
553*6d9a98c5SStefan Roese 
554*6d9a98c5SStefan Roese 	/* Initialize the LCD controller */
555*6d9a98c5SStefan Roese 	mvebu_lcd_register_init(&lcd_info, priv->regs);
556*6d9a98c5SStefan Roese 
557*6d9a98c5SStefan Roese 	/* Enable dcache for the frame buffer */
558*6d9a98c5SStefan Roese 	fb_start = plat->base & ~(MMU_SECTION_SIZE - 1);
559*6d9a98c5SStefan Roese 	fb_end = plat->base + plat->size;
560*6d9a98c5SStefan Roese 	fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
561*6d9a98c5SStefan Roese 	mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
562*6d9a98c5SStefan Roese 					DCACHE_WRITEBACK);
563*6d9a98c5SStefan Roese 	video_set_flush_dcache(dev, true);
564*6d9a98c5SStefan Roese 
565*6d9a98c5SStefan Roese 	uc_priv->xsize = lcd_info.x_res;
566*6d9a98c5SStefan Roese 	uc_priv->ysize = lcd_info.y_res;
567*6d9a98c5SStefan Roese 	uc_priv->bpix = VIDEO_BPP16;	/* Uses RGB555 format */
568913d1be2SStefan Roese 
569913d1be2SStefan Roese 	return 0;
570913d1be2SStefan Roese }
571913d1be2SStefan Roese 
mvebu_video_bind(struct udevice * dev)572*6d9a98c5SStefan Roese static int mvebu_video_bind(struct udevice *dev)
573913d1be2SStefan Roese {
574*6d9a98c5SStefan Roese 	struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
575*6d9a98c5SStefan Roese 
576*6d9a98c5SStefan Roese 	plat->size = LCD_MAX_WIDTH * LCD_MAX_HEIGHT *
577*6d9a98c5SStefan Roese 		(1 << LCD_MAX_LOG2_BPP) / 8;
578*6d9a98c5SStefan Roese 
579*6d9a98c5SStefan Roese 	return 0;
580913d1be2SStefan Roese }
581913d1be2SStefan Roese 
582*6d9a98c5SStefan Roese static const struct udevice_id mvebu_video_ids[] = {
583*6d9a98c5SStefan Roese 	{ .compatible = "marvell,armada-xp-lcd" },
584*6d9a98c5SStefan Roese 	{ }
585*6d9a98c5SStefan Roese };
586913d1be2SStefan Roese 
587*6d9a98c5SStefan Roese U_BOOT_DRIVER(mvebu_video) = {
588*6d9a98c5SStefan Roese 	.name	= "mvebu_video",
589*6d9a98c5SStefan Roese 	.id	= UCLASS_VIDEO,
590*6d9a98c5SStefan Roese 	.of_match = mvebu_video_ids,
591*6d9a98c5SStefan Roese 	.bind	= mvebu_video_bind,
592*6d9a98c5SStefan Roese 	.probe	= mvebu_video_probe,
593*6d9a98c5SStefan Roese 	.priv_auto_alloc_size = sizeof(struct mvebu_video_priv),
594*6d9a98c5SStefan Roese };
595