blob: 8f4183b82916362c2b23744bc23953ea442d4a53 [file] [log] [blame]
York Suna8778802007-10-29 13:58:39 -05001/*
Timur Tabiba8e76b2011-04-11 14:18:22 -05002 * Copyright 2007-2011 Freescale Semiconductor, Inc.
3 * Authors: York Sun <yorksun@freescale.com>
4 * Timur Tabi <timur@freescale.com>
York Suna8778802007-10-29 13:58:39 -05005 *
6 * FSL DIU Framebuffer driver
7 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
York Suna8778802007-10-29 13:58:39 -05009 */
10
11#include <common.h>
12#include <command.h>
13#include <asm/io.h>
Anatolij Gustschin9e70d132010-09-24 01:06:37 +020014#include <fsl_diu_fb.h>
Timur Tabiba8e76b2011-04-11 14:18:22 -050015#include "../common/pixis.h"
16
17#define PX_BRDCFG0_DLINK 0x10
18#define PX_BRDCFG0_DVISEL 0x08
York Sun070ba562007-10-31 14:59:04 -050019
York Sun3b80c5f2008-05-05 10:19:59 -050020void diu_set_pixel_clock(unsigned int pixclock)
21{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020022 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
York Sun3b80c5f2008-05-05 10:19:59 -050023 volatile ccsr_gur_t *gur = &immap->im_gur;
24 volatile unsigned int *guts_clkdvdr = &gur->clkdvdr;
25 unsigned long speed_ccb, temp, pixval;
26
27 speed_ccb = get_bus_freq(0);
28 temp = 1000000000/pixclock;
29 temp *= 1000;
30 pixval = speed_ccb / temp;
31 debug("DIU pixval = %lu\n", pixval);
32
33 /* Modify PXCLK in GUTS CLKDVDR */
34 debug("DIU: Current value of CLKDVDR = 0x%08x\n", *guts_clkdvdr);
35 temp = *guts_clkdvdr & 0x2000FFFF;
36 *guts_clkdvdr = temp; /* turn off clock */
37 *guts_clkdvdr = temp | 0x80000000 | ((pixval & 0x1F) << 16);
38 debug("DIU: Modified value of CLKDVDR = 0x%08x\n", *guts_clkdvdr);
39}
York Suna8778802007-10-29 13:58:39 -050040
Timur Tabiba8e76b2011-04-11 14:18:22 -050041int platform_diu_init(unsigned int xres, unsigned int yres, const char *port)
York Suna8778802007-10-29 13:58:39 -050042{
Timur Tabiba8e76b2011-04-11 14:18:22 -050043 const char *name;
44 int gamma_fix = 0;
45 u32 pixel_format = 0x88883316;
46 u8 temp;
York Suna8778802007-10-29 13:58:39 -050047
Timur Tabiba8e76b2011-04-11 14:18:22 -050048 temp = in_8(&pixis->brdcfg0);
York Suna8778802007-10-29 13:58:39 -050049
Timur Tabiba8e76b2011-04-11 14:18:22 -050050 if (strncmp(port, "dlvds", 5) == 0) {
51 /* Dual link LVDS */
York Suna8778802007-10-29 13:58:39 -050052 gamma_fix = 1;
Timur Tabiba8e76b2011-04-11 14:18:22 -050053 temp &= ~(PX_BRDCFG0_DLINK | PX_BRDCFG0_DVISEL);
54 name = "Dual-Link LVDS";
55 } else if (strncmp(port, "lvds", 4) == 0) {
56 /* Single link LVDS */
57 temp = (temp & ~PX_BRDCFG0_DVISEL) | PX_BRDCFG0_DLINK;
58 name = "Single-Link LVDS";
59 } else {
60 /* DVI */
61 if (in_8(&pixis->ver) == 1) /* Board version */
62 pixel_format = 0x88882317;
63 temp |= PX_BRDCFG0_DVISEL;
64 name = "DVI";
York Suna8778802007-10-29 13:58:39 -050065 }
66
Timur Tabiba8e76b2011-04-11 14:18:22 -050067 printf("DIU: Switching to %s monitor @ %ux%u\n", name, xres, yres);
68 out_8(&pixis->brdcfg0, temp);
69
Timur Tabi3b4a2262011-05-26 09:02:17 -050070 return fsl_diu_init(xres, yres, pixel_format, gamma_fix);
York Suna8778802007-10-29 13:58:39 -050071}