blob: 81e53e734ffbfbb4d1cb28b98b7b0726246fcaee [file] [log] [blame]
York Sunb7145172007-10-29 13:58:39 -05001/*
2 * Copyright 2007 Freescale Semiconductor, Inc.
3 * York Sun <yorksun@freescale.com>
4 *
5 * FSL DIU Framebuffer driver
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#include <common.h>
27#include <command.h>
28#include <asm/io.h>
Anatolij Gustschin43ffc532010-09-24 01:06:37 +020029#include <fsl_diu_fb.h>
York Sun59e74682007-10-31 14:59:04 -050030
York Sunc4964382008-05-05 10:19:59 -050031void diu_set_pixel_clock(unsigned int pixclock)
32{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020033 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
York Sunc4964382008-05-05 10:19:59 -050034 volatile ccsr_gur_t *gur = &immap->im_gur;
35 volatile unsigned int *guts_clkdvdr = &gur->clkdvdr;
36 unsigned long speed_ccb, temp, pixval;
37
38 speed_ccb = get_bus_freq(0);
39 temp = 1000000000/pixclock;
40 temp *= 1000;
41 pixval = speed_ccb / temp;
42 debug("DIU pixval = %lu\n", pixval);
43
44 /* Modify PXCLK in GUTS CLKDVDR */
45 debug("DIU: Current value of CLKDVDR = 0x%08x\n", *guts_clkdvdr);
46 temp = *guts_clkdvdr & 0x2000FFFF;
47 *guts_clkdvdr = temp; /* turn off clock */
48 *guts_clkdvdr = temp | 0x80000000 | ((pixval & 0x1F) << 16);
49 debug("DIU: Modified value of CLKDVDR = 0x%08x\n", *guts_clkdvdr);
50}
York Sunb7145172007-10-29 13:58:39 -050051
Anatolij Gustschin43ffc532010-09-24 01:06:37 +020052int platform_diu_init(unsigned int *xres, unsigned int *yres)
York Sunb7145172007-10-29 13:58:39 -050053{
54 char *monitor_port;
York Sun59e74682007-10-31 14:59:04 -050055 int gamma_fix;
York Sunb7145172007-10-29 13:58:39 -050056 unsigned int pixel_format;
57 unsigned char tmp_val;
York Sun59e74682007-10-31 14:59:04 -050058 unsigned char pixis_arch;
Kumar Gala146c4b22009-07-22 10:12:39 -050059 u8 *pixis_base = (u8 *)PIXIS_BASE;
York Sunb7145172007-10-29 13:58:39 -050060
Kumar Gala146c4b22009-07-22 10:12:39 -050061 tmp_val = in_8(pixis_base + PIXIS_BRDCFG0);
62 pixis_arch = in_8(pixis_base + PIXIS_VER);
York Sunb7145172007-10-29 13:58:39 -050063
York Sun59e74682007-10-31 14:59:04 -050064 monitor_port = getenv("monitor");
York Sunb7145172007-10-29 13:58:39 -050065 if (!strncmp(monitor_port, "0", 1)) { /* 0 - DVI */
Anatolij Gustschin43ffc532010-09-24 01:06:37 +020066 *xres = 1280;
67 *yres = 1024;
York Sun59e74682007-10-31 14:59:04 -050068 if (pixis_arch == 0x01)
69 pixel_format = 0x88882317;
70 else
71 pixel_format = 0x88883316;
York Sunb7145172007-10-29 13:58:39 -050072 gamma_fix = 0;
Kumar Gala146c4b22009-07-22 10:12:39 -050073 out_8(pixis_base + PIXIS_BRDCFG0, tmp_val | 0x08);
York Sunb7145172007-10-29 13:58:39 -050074
75 } else if (!strncmp(monitor_port, "1", 1)) { /* 1 - Single link LVDS */
Anatolij Gustschin43ffc532010-09-24 01:06:37 +020076 *xres = 1024;
77 *yres = 768;
York Sunb7145172007-10-29 13:58:39 -050078 pixel_format = 0x88883316;
79 gamma_fix = 0;
Kumar Gala146c4b22009-07-22 10:12:39 -050080 out_8(pixis_base + PIXIS_BRDCFG0, (tmp_val & 0xf7) | 0x10);
York Sunb7145172007-10-29 13:58:39 -050081
82 } else if (!strncmp(monitor_port, "2", 1)) { /* 2 - Double link LVDS */
Anatolij Gustschin43ffc532010-09-24 01:06:37 +020083 *xres = 1280;
84 *yres = 1024;
York Sunb7145172007-10-29 13:58:39 -050085 pixel_format = 0x88883316;
86 gamma_fix = 1;
Kumar Gala146c4b22009-07-22 10:12:39 -050087 out_8(pixis_base + PIXIS_BRDCFG0, tmp_val & 0xe7);
York Sunb7145172007-10-29 13:58:39 -050088
89 } else { /* DVI */
Anatolij Gustschin43ffc532010-09-24 01:06:37 +020090 *xres = 1280;
91 *yres = 1024;
York Sunb7145172007-10-29 13:58:39 -050092 pixel_format = 0x88882317;
93 gamma_fix = 0;
Kumar Gala146c4b22009-07-22 10:12:39 -050094 out_8(pixis_base + PIXIS_BRDCFG0, tmp_val | 0x08);
York Sunb7145172007-10-29 13:58:39 -050095 }
96
Anatolij Gustschin43ffc532010-09-24 01:06:37 +020097 return fsl_diu_init(*xres, pixel_format, gamma_fix);
York Sun59e74682007-10-31 14:59:04 -050098}