blob: d6983951717a079e8e8c5e91a0a548e243ead4be [file] [log] [blame]
wdenk7a428cc2003-06-15 22:40:42 +00001/*
wdenk9ca7bbc2004-10-09 23:25:58 +00002 * PXA LCD Controller
3 *
wdenk7a428cc2003-06-15 22:40:42 +00004 * (C) Copyright 2001-2002
5 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26/************************************************************************/
27/* ** HEADER FILES */
28/************************************************************************/
29
wdenk7a428cc2003-06-15 22:40:42 +000030#include <config.h>
31#include <common.h>
32#include <version.h>
33#include <stdarg.h>
wdenk7a428cc2003-06-15 22:40:42 +000034#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020035#include <stdio_dev.h>
wdenk9ca7bbc2004-10-09 23:25:58 +000036#include <lcd.h>
wdenk7a428cc2003-06-15 22:40:42 +000037#include <asm/arch/pxa-regs.h>
Marek Vasut2db1e962010-09-09 09:50:39 +020038#include <asm/io.h>
wdenk7a428cc2003-06-15 22:40:42 +000039
wdenk9ca7bbc2004-10-09 23:25:58 +000040/* #define DEBUG */
wdenk7a428cc2003-06-15 22:40:42 +000041
wdenk9ca7bbc2004-10-09 23:25:58 +000042#ifdef CONFIG_LCD
wdenk7a428cc2003-06-15 22:40:42 +000043
44/*----------------------------------------------------------------------*/
wdenk7a428cc2003-06-15 22:40:42 +000045/*
wdenk9ca7bbc2004-10-09 23:25:58 +000046 * Define panel bpp, LCCR0, LCCR3 and panel_info video struct for
47 * your display.
wdenk7a428cc2003-06-15 22:40:42 +000048 */
49
wdenk9ca7bbc2004-10-09 23:25:58 +000050#ifdef CONFIG_PXA_VGA
51/* LCD outputs connected to a video DAC */
52# define LCD_BPP LCD_COLOR8
wdenk7a428cc2003-06-15 22:40:42 +000053
54/* you have to set lccr0 and lccr3 (including pcd) */
wdenk9ca7bbc2004-10-09 23:25:58 +000055# define REG_LCCR0 0x003008f8
56# define REG_LCCR3 0x0300FF01
wdenk7a428cc2003-06-15 22:40:42 +000057
58/* 640x480x16 @ 61 Hz */
wdenk9ca7bbc2004-10-09 23:25:58 +000059vidinfo_t panel_info = {
Marek Vasut8c4a26e2010-09-23 08:32:54 +020060 .vl_col = 640,
61 .vl_row = 480,
62 .vl_width = 640,
63 .vl_height = 480,
64 .vl_clkp = CONFIG_SYS_HIGH,
65 .vl_oep = CONFIG_SYS_HIGH,
66 .vl_hsp = CONFIG_SYS_HIGH,
67 .vl_vsp = CONFIG_SYS_HIGH,
68 .vl_dp = CONFIG_SYS_HIGH,
69 .vl_bpix = LCD_BPP,
70 .vl_lbw = 0,
71 .vl_splt = 0,
72 .vl_clor = 0,
73 .vl_tft = 1,
74 .vl_hpw = 40,
75 .vl_blw = 56,
76 .vl_elw = 56,
77 .vl_vpw = 20,
78 .vl_bfw = 8,
79 .vl_efw = 8,
wdenk7a428cc2003-06-15 22:40:42 +000080};
81#endif /* CONFIG_PXA_VIDEO */
82
wdenk9ca7bbc2004-10-09 23:25:58 +000083/*----------------------------------------------------------------------*/
wdenk7a428cc2003-06-15 22:40:42 +000084#ifdef CONFIG_SHARP_LM8V31
85
wdenk9ca7bbc2004-10-09 23:25:58 +000086# define LCD_BPP LCD_COLOR8
87# define LCD_INVERT_COLORS /* Needed for colors to be correct, but why? */
wdenk7a428cc2003-06-15 22:40:42 +000088
89/* you have to set lccr0 and lccr3 (including pcd) */
wdenk9ca7bbc2004-10-09 23:25:58 +000090# define REG_LCCR0 0x0030087C
91# define REG_LCCR3 0x0340FF08
wdenk7a428cc2003-06-15 22:40:42 +000092
wdenk9ca7bbc2004-10-09 23:25:58 +000093vidinfo_t panel_info = {
Marek Vasut8c4a26e2010-09-23 08:32:54 +020094 .vl_col = 640,
95 .vl_row = 480,
96 .vl_width = 157,
97 .vl_height = 118,
98 .vl_clkp = CONFIG_SYS_HIGH,
99 .vl_oep = CONFIG_SYS_HIGH,
100 .vl_hsp = CONFIG_SYS_HIGH,
101 .vl_vsp = CONFIG_SYS_HIGH,
102 .vl_dp = CONFIG_SYS_HIGH,
103 .vl_bpix = LCD_BPP,
104 .vl_lbw = 0,
105 .vl_splt = 1,
106 .vl_clor = 1,
107 .vl_tft = 0,
108 .vl_hpw = 1,
109 .vl_blw = 3,
110 .vl_elw = 3,
111 .vl_vpw = 1,
112 .vl_bfw = 0,
113 .vl_efw = 0,
wdenk7a428cc2003-06-15 22:40:42 +0000114};
115#endif /* CONFIG_SHARP_LM8V31 */
Marek Vasut846d9b62010-03-07 23:35:48 +0100116/*----------------------------------------------------------------------*/
117#ifdef CONFIG_VOIPAC_LCD
118
119# define LCD_BPP LCD_COLOR8
120# define LCD_INVERT_COLORS
121
122/* you have to set lccr0 and lccr3 (including pcd) */
123# define REG_LCCR0 0x043008f8
124# define REG_LCCR3 0x0340FF08
125
126vidinfo_t panel_info = {
Marek Vasut8c4a26e2010-09-23 08:32:54 +0200127 .vl_col = 640,
128 .vl_row = 480,
129 .vl_width = 157,
130 .vl_height = 118,
131 .vl_clkp = CONFIG_SYS_HIGH,
132 .vl_oep = CONFIG_SYS_HIGH,
133 .vl_hsp = CONFIG_SYS_HIGH,
134 .vl_vsp = CONFIG_SYS_HIGH,
135 .vl_dp = CONFIG_SYS_HIGH,
136 .vl_bpix = LCD_BPP,
137 .vl_lbw = 0,
138 .vl_splt = 1,
139 .vl_clor = 1,
140 .vl_tft = 1,
141 .vl_hpw = 32,
142 .vl_blw = 144,
143 .vl_elw = 32,
144 .vl_vpw = 2,
145 .vl_bfw = 13,
146 .vl_efw = 30,
Marek Vasut846d9b62010-03-07 23:35:48 +0100147};
148#endif /* CONFIG_VOIPAC_LCD */
wdenk7a428cc2003-06-15 22:40:42 +0000149
150/*----------------------------------------------------------------------*/
wdenk9ca7bbc2004-10-09 23:25:58 +0000151#ifdef CONFIG_HITACHI_SX14
152/* Hitachi SX14Q004-ZZA color STN LCD */
153#define LCD_BPP LCD_COLOR8
wdenk7a428cc2003-06-15 22:40:42 +0000154
wdenk9ca7bbc2004-10-09 23:25:58 +0000155/* you have to set lccr0 and lccr3 (including pcd) */
156#define REG_LCCR0 0x00301079
157#define REG_LCCR3 0x0340FF20
wdenk7a428cc2003-06-15 22:40:42 +0000158
wdenk9ca7bbc2004-10-09 23:25:58 +0000159vidinfo_t panel_info = {
Marek Vasut8c4a26e2010-09-23 08:32:54 +0200160 .vl_col = 320,
161 .vl_row = 240,
162 .vl_width = 167,
163 .vl_height = 109,
164 .vl_clkp = CONFIG_SYS_HIGH,
165 .vl_oep = CONFIG_SYS_HIGH,
166 .vl_hsp = CONFIG_SYS_HIGH,
167 .vl_vsp = CONFIG_SYS_HIGH,
168 .vl_dp = CONFIG_SYS_HIGH,
169 .vl_bpix = LCD_BPP,
170 .vl_lbw = 1,
171 .vl_splt = 0,
172 .vl_clor = 1,
173 .vl_tft = 0,
174 .vl_hpw = 1,
175 .vl_blw = 1,
176 .vl_elw = 1,
177 .vl_vpw = 7,
178 .vl_bfw = 0,
179 .vl_efw = 0,
wdenk7a428cc2003-06-15 22:40:42 +0000180};
wdenk9ca7bbc2004-10-09 23:25:58 +0000181#endif /* CONFIG_HITACHI_SX14 */
wdenk7a428cc2003-06-15 22:40:42 +0000182
183/*----------------------------------------------------------------------*/
Marek Vasutc2e92e02010-07-03 09:38:03 +0200184#ifdef CONFIG_LMS283GF05
185
186# define LCD_BPP LCD_COLOR8
Wolfgang Denk34ed1092010-09-19 17:47:52 +0200187/*# define LCD_INVERT_COLORS*/
Marek Vasutc2e92e02010-07-03 09:38:03 +0200188
189/* you have to set lccr0 and lccr3 (including pcd) */
190# define REG_LCCR0 0x043008f8
191# define REG_LCCR3 0x03b00009
192
193vidinfo_t panel_info = {
Marek Vasut8c4a26e2010-09-23 08:32:54 +0200194 .vl_col = 240,
195 .vl_row = 320,
196 .vl_width = 240,
197 .vl_height = 320,
198 .vl_clkp = CONFIG_SYS_HIGH,
199 .vl_oep = CONFIG_SYS_LOW,
200 .vl_hsp = CONFIG_SYS_LOW,
201 .vl_vsp = CONFIG_SYS_LOW,
202 .vl_dp = CONFIG_SYS_HIGH,
203 .vl_bpix = LCD_BPP,
204 .vl_lbw = 0,
205 .vl_splt = 1,
206 .vl_clor = 1,
207 .vl_tft = 1,
208 .vl_hpw = 4,
209 .vl_blw = 4,
210 .vl_elw = 8,
211 .vl_vpw = 4,
212 .vl_bfw = 4,
213 .vl_efw = 8,
Marek Vasutc2e92e02010-07-03 09:38:03 +0200214};
215#endif /* CONFIG_LMS283GF05 */
216
217/*----------------------------------------------------------------------*/
wdenk7a428cc2003-06-15 22:40:42 +0000218
Marek Vasutabd23e82010-07-18 04:46:55 +0200219#ifdef CONFIG_ACX517AKN
220
221# define LCD_BPP LCD_COLOR8
222
223/* you have to set lccr0 and lccr3 (including pcd) */
224# define REG_LCCR0 0x003008f9
225# define REG_LCCR3 0x03700006
226
227vidinfo_t panel_info = {
228 .vl_col = 320,
229 .vl_row = 320,
230 .vl_width = 320,
231 .vl_height = 320,
232 .vl_clkp = CONFIG_SYS_HIGH,
233 .vl_oep = CONFIG_SYS_LOW,
234 .vl_hsp = CONFIG_SYS_LOW,
235 .vl_vsp = CONFIG_SYS_LOW,
236 .vl_dp = CONFIG_SYS_HIGH,
237 .vl_bpix = LCD_BPP,
238 .vl_lbw = 0,
239 .vl_splt = 1,
240 .vl_clor = 1,
241 .vl_tft = 1,
242 .vl_hpw = 0x04,
243 .vl_blw = 0x1c,
244 .vl_elw = 0x08,
245 .vl_vpw = 0x01,
246 .vl_bfw = 0x07,
247 .vl_efw = 0x08,
248};
249#endif /* CONFIG_ACX517AKN */
250
251/*----------------------------------------------------------------------*/
252
wdenk9ca7bbc2004-10-09 23:25:58 +0000253#if LCD_BPP == LCD_COLOR8
254void lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue);
255#endif
wdenk7a428cc2003-06-15 22:40:42 +0000256#if LCD_BPP == LCD_MONOCHROME
wdenk9ca7bbc2004-10-09 23:25:58 +0000257void lcd_initcolregs (void);
wdenk7a428cc2003-06-15 22:40:42 +0000258#endif
259
wdenk9ca7bbc2004-10-09 23:25:58 +0000260#ifdef NOT_USED_SO_FAR
261void lcd_disable (void);
262void lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue);
263#endif /* NOT_USED_SO_FAR */
wdenk7a428cc2003-06-15 22:40:42 +0000264
wdenk9ca7bbc2004-10-09 23:25:58 +0000265void lcd_ctrl_init (void *lcdbase);
266void lcd_enable (void);
wdenk7a428cc2003-06-15 22:40:42 +0000267
wdenk9ca7bbc2004-10-09 23:25:58 +0000268int lcd_line_length;
269int lcd_color_fg;
270int lcd_color_bg;
wdenk7a428cc2003-06-15 22:40:42 +0000271
wdenk9ca7bbc2004-10-09 23:25:58 +0000272void *lcd_base; /* Start of framebuffer memory */
273void *lcd_console_address; /* Start of console buffer */
wdenk7a428cc2003-06-15 22:40:42 +0000274
wdenk9ca7bbc2004-10-09 23:25:58 +0000275short console_col;
276short console_row;
wdenk7a428cc2003-06-15 22:40:42 +0000277
wdenk9ca7bbc2004-10-09 23:25:58 +0000278static int pxafb_init_mem (void *lcdbase, vidinfo_t *vid);
279static void pxafb_setup_gpio (vidinfo_t *vid);
280static void pxafb_enable_controller (vidinfo_t *vid);
281static int pxafb_init (vidinfo_t *vid);
wdenk7a428cc2003-06-15 22:40:42 +0000282/************************************************************************/
283
wdenk7a428cc2003-06-15 22:40:42 +0000284/************************************************************************/
wdenk9ca7bbc2004-10-09 23:25:58 +0000285/* --------------- PXA chipset specific functions ------------------- */
wdenk7a428cc2003-06-15 22:40:42 +0000286/************************************************************************/
287
wdenk9ca7bbc2004-10-09 23:25:58 +0000288void lcd_ctrl_init (void *lcdbase)
wdenk7a428cc2003-06-15 22:40:42 +0000289{
wdenk57b2d802003-06-27 21:31:46 +0000290 pxafb_init_mem(lcdbase, &panel_info);
wdenk7a428cc2003-06-15 22:40:42 +0000291 pxafb_init(&panel_info);
292 pxafb_setup_gpio(&panel_info);
293 pxafb_enable_controller(&panel_info);
294}
295
296/*----------------------------------------------------------------------*/
wdenk9ca7bbc2004-10-09 23:25:58 +0000297#ifdef NOT_USED_SO_FAR
298void
wdenk7a428cc2003-06-15 22:40:42 +0000299lcd_getcolreg (ushort regno, ushort *red, ushort *green, ushort *blue)
300{
301}
wdenk9ca7bbc2004-10-09 23:25:58 +0000302#endif /* NOT_USED_SO_FAR */
wdenk7a428cc2003-06-15 22:40:42 +0000303
304/*----------------------------------------------------------------------*/
wdenk7a428cc2003-06-15 22:40:42 +0000305#if LCD_BPP == LCD_COLOR8
wdenk9ca7bbc2004-10-09 23:25:58 +0000306void
wdenk7a428cc2003-06-15 22:40:42 +0000307lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
308{
309 struct pxafb_info *fbi = &panel_info.pxa;
310 unsigned short *palette = (unsigned short *)fbi->palette;
311 u_int val;
wdenk57b2d802003-06-27 21:31:46 +0000312
wdenk7a428cc2003-06-15 22:40:42 +0000313 if (regno < fbi->palette_size) {
314 val = ((red << 8) & 0xf800);
315 val |= ((green << 4) & 0x07e0);
316 val |= (blue & 0x001f);
317
318#ifdef LCD_INVERT_COLORS
319 palette[regno] = ~val;
320#else
wdenk9ca7bbc2004-10-09 23:25:58 +0000321 palette[regno] = val;
wdenk7a428cc2003-06-15 22:40:42 +0000322#endif
323 }
324
325 debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %04X\n",
326 regno, &palette[regno],
327 red, green, blue,
328 palette[regno]);
329}
wdenk9ca7bbc2004-10-09 23:25:58 +0000330#endif /* LCD_COLOR8 */
wdenk7a428cc2003-06-15 22:40:42 +0000331
332/*----------------------------------------------------------------------*/
wdenk7a428cc2003-06-15 22:40:42 +0000333#if LCD_BPP == LCD_MONOCHROME
wdenk7a428cc2003-06-15 22:40:42 +0000334void lcd_initcolregs (void)
335{
wdenk9ca7bbc2004-10-09 23:25:58 +0000336 struct pxafb_info *fbi = &panel_info.pxa;
337 cmap = (ushort *)fbi->palette;
wdenk7a428cc2003-06-15 22:40:42 +0000338 ushort regno;
339
340 for (regno = 0; regno < 16; regno++) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000341 cmap[regno * 2] = 0;
342 cmap[(regno * 2) + 1] = regno & 0x0f;
wdenk7a428cc2003-06-15 22:40:42 +0000343 }
344}
wdenk9ca7bbc2004-10-09 23:25:58 +0000345#endif /* LCD_MONOCHROME */
wdenk7a428cc2003-06-15 22:40:42 +0000346
347/*----------------------------------------------------------------------*/
wdenk9ca7bbc2004-10-09 23:25:58 +0000348void lcd_enable (void)
wdenk7a428cc2003-06-15 22:40:42 +0000349{
350}
351
352/*----------------------------------------------------------------------*/
wdenk7a428cc2003-06-15 22:40:42 +0000353#ifdef NOT_USED_SO_FAR
354static void lcd_disable (void)
355{
356}
wdenk9ca7bbc2004-10-09 23:25:58 +0000357#endif /* NOT_USED_SO_FAR */
wdenk7a428cc2003-06-15 22:40:42 +0000358
wdenk9ca7bbc2004-10-09 23:25:58 +0000359/*----------------------------------------------------------------------*/
wdenk7a428cc2003-06-15 22:40:42 +0000360
361/************************************************************************/
wdenk9ca7bbc2004-10-09 23:25:58 +0000362/* ** PXA255 specific routines */
wdenk7a428cc2003-06-15 22:40:42 +0000363/************************************************************************/
364
wdenk9ca7bbc2004-10-09 23:25:58 +0000365/*
366 * Calculate fb size for VIDEOLFB_ATAG. Size returned contains fb,
367 * descriptors and palette areas.
368 */
369ulong calc_fbsize (void)
wdenk7a428cc2003-06-15 22:40:42 +0000370{
wdenk9ca7bbc2004-10-09 23:25:58 +0000371 ulong size;
372 int line_length = (panel_info.vl_col * NBITS (panel_info.vl_bpix)) / 8;
wdenk7a428cc2003-06-15 22:40:42 +0000373
wdenk9ca7bbc2004-10-09 23:25:58 +0000374 size = line_length * panel_info.vl_row;
375 size += PAGE_SIZE;
wdenk7a428cc2003-06-15 22:40:42 +0000376
wdenk9ca7bbc2004-10-09 23:25:58 +0000377 return size;
wdenk7a428cc2003-06-15 22:40:42 +0000378}
379
wdenk9ca7bbc2004-10-09 23:25:58 +0000380static int pxafb_init_mem (void *lcdbase, vidinfo_t *vid)
wdenk7a428cc2003-06-15 22:40:42 +0000381{
382 u_long palette_mem_size;
383 struct pxafb_info *fbi = &vid->pxa;
384 int fb_size = vid->vl_row * (vid->vl_col * NBITS (vid->vl_bpix)) / 8;
385
386 fbi->screen = (u_long)lcdbase;
387
388 fbi->palette_size = NBITS(vid->vl_bpix) == 8 ? 256 : 16;
389 palette_mem_size = fbi->palette_size * sizeof(u16);
wdenk9ca7bbc2004-10-09 23:25:58 +0000390
wdenk7a428cc2003-06-15 22:40:42 +0000391 debug("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
392 /* locate palette and descs at end of page following fb */
wdenk9ca7bbc2004-10-09 23:25:58 +0000393 fbi->palette = (u_long)lcdbase + fb_size + PAGE_SIZE - palette_mem_size;
wdenk7a428cc2003-06-15 22:40:42 +0000394
395 return 0;
396}
Marek Vasut23cf8e42009-11-28 13:57:43 +0100397#ifdef CONFIG_CPU_MONAHANS
398static inline void pxafb_setup_gpio (vidinfo_t *vid) {}
399#else
wdenk9ca7bbc2004-10-09 23:25:58 +0000400static void pxafb_setup_gpio (vidinfo_t *vid)
wdenk7a428cc2003-06-15 22:40:42 +0000401{
402 u_long lccr0;
403
404 /*
405 * setup is based on type of panel supported
406 */
407
408 lccr0 = vid->pxa.reg_lccr0;
409
410 /* 4 bit interface */
411 if ((lccr0 & LCCR0_CMS) && (lccr0 & LCCR0_SDS) && !(lccr0 & LCCR0_DPD))
412 {
413 debug("Setting GPIO for 4 bit data\n");
414 /* bits 58-61 */
Marek Vasut2db1e962010-09-09 09:50:39 +0200415 writel(readl(GPDR1) | (0xf << 26), GPDR1);
416 writel((readl(GAFR1_U) & ~(0xff << 20)) | (0xaa << 20),
417 GAFR1_U);
wdenk7a428cc2003-06-15 22:40:42 +0000418
419 /* bits 74-77 */
Marek Vasut2db1e962010-09-09 09:50:39 +0200420 writel(readl(GPDR2) | (0xf << 10), GPDR2);
421 writel((readl(GAFR2_L) & ~(0xff << 20)) | (0xaa << 20),
422 GAFR2_L);
wdenk7a428cc2003-06-15 22:40:42 +0000423 }
424
425 /* 8 bit interface */
426 else if (((lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_DPD))) ||
wdenk9ca7bbc2004-10-09 23:25:58 +0000427 (!(lccr0 & LCCR0_CMS) && !(lccr0 & LCCR0_PAS) && !(lccr0 & LCCR0_SDS)))
wdenk7a428cc2003-06-15 22:40:42 +0000428 {
429 debug("Setting GPIO for 8 bit data\n");
430 /* bits 58-65 */
Marek Vasut2db1e962010-09-09 09:50:39 +0200431 writel(readl(GPDR1) | (0x3f << 26), GPDR1);
432 writel(readl(GPDR2) | (0x3), GPDR2);
wdenk7a428cc2003-06-15 22:40:42 +0000433
Marek Vasut2db1e962010-09-09 09:50:39 +0200434 writel((readl(GAFR1_U) & ~(0xfff << 20)) | (0xaaa << 20),
435 GAFR1_U);
436 writel((readl(GAFR2_L) & ~0xf) | (0xa), GAFR2_L);
wdenk7a428cc2003-06-15 22:40:42 +0000437
438 /* bits 74-77 */
Marek Vasut2db1e962010-09-09 09:50:39 +0200439 writel(readl(GPDR2) | (0xf << 10), GPDR2);
440 writel((readl(GAFR2_L) & ~(0xff << 20)) | (0xaa << 20),
441 GAFR2_L);
wdenk7a428cc2003-06-15 22:40:42 +0000442 }
443
444 /* 16 bit interface */
445 else if (!(lccr0 & LCCR0_CMS) && ((lccr0 & LCCR0_SDS) || (lccr0 & LCCR0_PAS)))
446 {
447 debug("Setting GPIO for 16 bit data\n");
448 /* bits 58-77 */
Marek Vasut2db1e962010-09-09 09:50:39 +0200449 writel(readl(GPDR1) | (0x3f << 26), GPDR1);
450 writel(readl(GPDR2) | 0x00003fff, GPDR2);
wdenk7a428cc2003-06-15 22:40:42 +0000451
Marek Vasut2db1e962010-09-09 09:50:39 +0200452 writel((readl(GAFR1_U) & ~(0xfff << 20)) | (0xaaa << 20),
453 GAFR1_U);
454 writel((readl(GAFR2_L) & 0xf0000000) | 0x0aaaaaaa, GAFR2_L);
wdenk7a428cc2003-06-15 22:40:42 +0000455 }
456 else
457 {
458 printf("pxafb_setup_gpio: unable to determine bits per pixel\n");
459 }
460}
Marek Vasut23cf8e42009-11-28 13:57:43 +0100461#endif
wdenk7a428cc2003-06-15 22:40:42 +0000462
wdenk9ca7bbc2004-10-09 23:25:58 +0000463static void pxafb_enable_controller (vidinfo_t *vid)
wdenk7a428cc2003-06-15 22:40:42 +0000464{
465 debug("Enabling LCD controller\n");
466
467 /* Sequence from 11.7.10 */
Marek Vasut2db1e962010-09-09 09:50:39 +0200468 writel(vid->pxa.reg_lccr3, LCCR3);
469 writel(vid->pxa.reg_lccr2, LCCR2);
470 writel(vid->pxa.reg_lccr1, LCCR1);
471 writel(vid->pxa.reg_lccr0 & ~LCCR0_ENB, LCCR0);
472 writel(vid->pxa.fdadr0, FDADR0);
473 writel(vid->pxa.fdadr1, FDADR1);
474 writel(readl(LCCR0) | LCCR0_ENB, LCCR0);
wdenk7a428cc2003-06-15 22:40:42 +0000475
Marek Vasut23cf8e42009-11-28 13:57:43 +0100476#ifdef CONFIG_CPU_MONAHANS
Marek Vasut2db1e962010-09-09 09:50:39 +0200477 writel(readl(CKENA) | CKENA_1_LCD, CKENA);
Marek Vasut23cf8e42009-11-28 13:57:43 +0100478#else
Marek Vasut2db1e962010-09-09 09:50:39 +0200479 writel(readl(CKEN) | CKEN16_LCD, CKEN);
Marek Vasut23cf8e42009-11-28 13:57:43 +0100480#endif
wdenk7a428cc2003-06-15 22:40:42 +0000481
Marek Vasut2db1e962010-09-09 09:50:39 +0200482 debug("FDADR0 = 0x%08x\n", readl(FDADR0));
483 debug("FDADR1 = 0x%08x\n", readl(FDADR1));
484 debug("LCCR0 = 0x%08x\n", readl(LCCR0));
485 debug("LCCR1 = 0x%08x\n", readl(LCCR1));
486 debug("LCCR2 = 0x%08x\n", readl(LCCR2));
487 debug("LCCR3 = 0x%08x\n", readl(LCCR3));
wdenk7a428cc2003-06-15 22:40:42 +0000488}
489
wdenk9ca7bbc2004-10-09 23:25:58 +0000490static int pxafb_init (vidinfo_t *vid)
wdenk7a428cc2003-06-15 22:40:42 +0000491{
492 struct pxafb_info *fbi = &vid->pxa;
493
494 debug("Configuring PXA LCD\n");
495
496 fbi->reg_lccr0 = REG_LCCR0;
497 fbi->reg_lccr3 = REG_LCCR3;
498
499 debug("vid: vl_col=%d hslen=%d lm=%d rm=%d\n",
500 vid->vl_col, vid->vl_hpw,
501 vid->vl_blw, vid->vl_elw);
502 debug("vid: vl_row=%d vslen=%d um=%d bm=%d\n",
503 vid->vl_row, vid->vl_vpw,
504 vid->vl_bfw, vid->vl_efw);
505
506 fbi->reg_lccr1 =
507 LCCR1_DisWdth(vid->vl_col) +
508 LCCR1_HorSnchWdth(vid->vl_hpw) +
509 LCCR1_BegLnDel(vid->vl_blw) +
510 LCCR1_EndLnDel(vid->vl_elw);
wdenk57b2d802003-06-27 21:31:46 +0000511
wdenk7a428cc2003-06-15 22:40:42 +0000512 fbi->reg_lccr2 =
513 LCCR2_DisHght(vid->vl_row) +
514 LCCR2_VrtSnchWdth(vid->vl_vpw) +
515 LCCR2_BegFrmDel(vid->vl_bfw) +
516 LCCR2_EndFrmDel(vid->vl_efw);
517
wdenk57b2d802003-06-27 21:31:46 +0000518 fbi->reg_lccr3 = REG_LCCR3 & ~(LCCR3_HSP | LCCR3_VSP);
wdenk9ca7bbc2004-10-09 23:25:58 +0000519 fbi->reg_lccr3 |= (vid->vl_hsp ? LCCR3_HorSnchL : LCCR3_HorSnchH)
520 | (vid->vl_vsp ? LCCR3_VrtSnchL : LCCR3_VrtSnchH);
wdenk57b2d802003-06-27 21:31:46 +0000521
wdenk7a428cc2003-06-15 22:40:42 +0000522
523 /* setup dma descriptors */
524 fbi->dmadesc_fblow = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 3*16);
525 fbi->dmadesc_fbhigh = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 2*16);
526 fbi->dmadesc_palette = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette - 1*16);
527
528 #define BYTES_PER_PANEL ((fbi->reg_lccr0 & LCCR0_SDS) ? \
wdenk57b2d802003-06-27 21:31:46 +0000529 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8 / 2) : \
530 (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8))
531
wdenk7a428cc2003-06-15 22:40:42 +0000532 /* populate descriptors */
533 fbi->dmadesc_fblow->fdadr = (u_long)fbi->dmadesc_fblow;
534 fbi->dmadesc_fblow->fsadr = fbi->screen + BYTES_PER_PANEL;
535 fbi->dmadesc_fblow->fidr = 0;
536 fbi->dmadesc_fblow->ldcmd = BYTES_PER_PANEL;
537
538 fbi->fdadr1 = (u_long)fbi->dmadesc_fblow; /* only used in dual-panel mode */
wdenk57b2d802003-06-27 21:31:46 +0000539
wdenk7a428cc2003-06-15 22:40:42 +0000540 fbi->dmadesc_fbhigh->fsadr = fbi->screen;
541 fbi->dmadesc_fbhigh->fidr = 0;
542 fbi->dmadesc_fbhigh->ldcmd = BYTES_PER_PANEL;
543
544 fbi->dmadesc_palette->fsadr = fbi->palette;
545 fbi->dmadesc_palette->fidr = 0;
546 fbi->dmadesc_palette->ldcmd = (fbi->palette_size * 2) | LDCMD_PAL;
547
548 if( NBITS(vid->vl_bpix) < 12)
549 {
550 /* assume any mode with <12 bpp is palette driven */
551 fbi->dmadesc_palette->fdadr = (u_long)fbi->dmadesc_fbhigh;
552 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_palette;
553 /* flips back and forth between pal and fbhigh */
wdenk57b2d802003-06-27 21:31:46 +0000554 fbi->fdadr0 = (u_long)fbi->dmadesc_palette;
wdenk7a428cc2003-06-15 22:40:42 +0000555 }
556 else
557 {
558 /* palette shouldn't be loaded in true-color mode */
559 fbi->dmadesc_fbhigh->fdadr = (u_long)fbi->dmadesc_fbhigh;
560 fbi->fdadr0 = (u_long)fbi->dmadesc_fbhigh; /* no pal just fbhigh */
561 }
562
563 debug("fbi->dmadesc_fblow = 0x%lx\n", (u_long)fbi->dmadesc_fblow);
564 debug("fbi->dmadesc_fbhigh = 0x%lx\n", (u_long)fbi->dmadesc_fbhigh);
565 debug("fbi->dmadesc_palette = 0x%lx\n", (u_long)fbi->dmadesc_palette);
566
567 debug("fbi->dmadesc_fblow->fdadr = 0x%lx\n", fbi->dmadesc_fblow->fdadr);
568 debug("fbi->dmadesc_fbhigh->fdadr = 0x%lx\n", fbi->dmadesc_fbhigh->fdadr);
569 debug("fbi->dmadesc_palette->fdadr = 0x%lx\n", fbi->dmadesc_palette->fdadr);
570
571 debug("fbi->dmadesc_fblow->fsadr = 0x%lx\n", fbi->dmadesc_fblow->fsadr);
572 debug("fbi->dmadesc_fbhigh->fsadr = 0x%lx\n", fbi->dmadesc_fbhigh->fsadr);
573 debug("fbi->dmadesc_palette->fsadr = 0x%lx\n", fbi->dmadesc_palette->fsadr);
574
575 debug("fbi->dmadesc_fblow->ldcmd = 0x%lx\n", fbi->dmadesc_fblow->ldcmd);
576 debug("fbi->dmadesc_fbhigh->ldcmd = 0x%lx\n", fbi->dmadesc_fbhigh->ldcmd);
577 debug("fbi->dmadesc_palette->ldcmd = 0x%lx\n", fbi->dmadesc_palette->ldcmd);
wdenk57b2d802003-06-27 21:31:46 +0000578
wdenk7a428cc2003-06-15 22:40:42 +0000579 return 0;
580}
581
582/************************************************************************/
583/************************************************************************/
584
585#endif /* CONFIG_LCD */