]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/powerpc/cpu/mpc512x/diu.c
video: cfb_console: add weak default video_set_lut()
[people/ms/u-boot.git] / arch / powerpc / cpu / mpc512x / diu.c
CommitLineData
0e1bad47
YS
1/*
2 * Copyright 2008 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>
29
8d1f2682 30#include "../../../../board/freescale/common/fsl_diu_fb.h"
0e1bad47
YS
31
32#if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
52cb4d4f 33#include <stdio_dev.h>
0e1bad47
YS
34#include <video_fb.h>
35#endif
36
a3921eef
AG
37DECLARE_GLOBAL_DATA_PTR;
38
92c20fbd 39#ifdef CONFIG_FSL_DIU_LOGO_BMP
0e1bad47 40extern unsigned int FSL_Logo_BMP[];
92c20fbd
JR
41#else
42#define FSL_Logo_BMP NULL
43#endif
0e1bad47
YS
44
45static int xres, yres;
46
47void diu_set_pixel_clock(unsigned int pixclock)
48{
6d0f6bcf 49 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
0e1bad47
YS
50 volatile clk512x_t *clk = &immap->clk;
51 volatile unsigned int *clkdvdr = &clk->scfr[0];
52 unsigned long speed_ccb, temp, pixval;
53
54 speed_ccb = get_bus_freq(0) * 4;
55 temp = 1000000000/pixclock;
56 temp *= 1000;
57 pixval = speed_ccb / temp;
58 debug("DIU pixval = %lu\n", pixval);
59
60 /* Modify PXCLK in GUTS CLKDVDR */
57ae8a5c
DZ
61 debug("DIU: Current value of CLKDVDR = 0x%08x\n", in_be32(clkdvdr));
62 temp = in_be32(clkdvdr) & 0xFFFFFF00;
63 out_be32(clkdvdr, temp | (pixval & 0xFF));
64 debug("DIU: Modified value of CLKDVDR = 0x%08x\n", in_be32(clkdvdr));
0e1bad47
YS
65}
66
4c154252
JR
67char *valid_bmp(char *addr)
68{
69 unsigned long h_addr;
a3921eef 70 bd_t *bd = gd->bd;
4c154252
JR
71
72 h_addr = simple_strtoul(addr, NULL, 16);
a3921eef
AG
73 if (h_addr < bd->bi_flashstart ||
74 h_addr >= (bd->bi_flashstart + bd->bi_flashsize - 1)) {
4c154252
JR
75 printf("bmp addr %lx is not a valid flash address\n", h_addr);
76 return 0;
77 } else if ((*(char *)(h_addr) != 'B') || (*(char *)(h_addr+1) != 'M')) {
78 printf("bmp addr is not a bmp\n");
79 return 0;
80 } else
81 return (char *)h_addr;
82}
83
de26ef99 84int mpc5121_diu_init(void)
0e1bad47
YS
85{
86 unsigned int pixel_format;
4c154252
JR
87 char *bmp = NULL;
88 char *bmp_env;
0e1bad47 89
a3921eef
AG
90#if defined(CONFIG_VIDEO_XRES) & defined(CONFIG_VIDEO_YRES)
91 xres = CONFIG_VIDEO_XRES;
92 yres = CONFIG_VIDEO_YRES;
93#else
0e1bad47
YS
94 xres = 1024;
95 yres = 768;
a3921eef 96#endif
0e1bad47
YS
97 pixel_format = 0x88883316;
98
de26ef99 99 debug("mpc5121_diu_init\n");
4c154252
JR
100 bmp_env = getenv("diu_bmp_addr");
101 if (bmp_env) {
102 bmp = valid_bmp(bmp_env);
103 }
104 if (!bmp)
debf8741 105 bmp = (char *)FSL_Logo_BMP;
4c154252 106 return fsl_diu_init(xres, pixel_format, 0, (unsigned char *)bmp);
0e1bad47
YS
107}
108
de26ef99 109int mpc5121diu_init_show_bmp(cmd_tbl_t *cmdtp,
0e1bad47
YS
110 int flag, int argc, char *argv[])
111{
112 unsigned int addr;
113
114 if (argc < 2) {
62c3ae7c 115 cmd_usage(cmdtp);
0e1bad47
YS
116 return 1;
117 }
118
119 if (!strncmp(argv[1], "init", 4)) {
120#if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
121 fsl_diu_clear_screen();
122 drv_video_init();
123#else
de26ef99 124 return mpc5121_diu_init();
0e1bad47
YS
125#endif
126 } else {
127 addr = simple_strtoul(argv[1], NULL, 16);
128 fsl_diu_clear_screen();
129 fsl_diu_display_bmp((unsigned char *)addr, 0, 0, 0);
130 }
131
132 return 0;
133}
134
135U_BOOT_CMD(
de26ef99 136 diufb, CONFIG_SYS_MAXARGS, 1, mpc5121diu_init_show_bmp,
2fb2604d 137 "Init or Display BMP file",
0e1bad47 138 "init\n - initialize DIU\n"
a89c33db 139 "addr\n - display bmp at address 'addr'"
0e1bad47
YS
140 );
141
142
143#if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
144
145/*
146 * The Graphic Device
147 */
148GraphicDevice ctfb;
149void *video_hw_init(void)
150{
151 GraphicDevice *pGD = (GraphicDevice *) &ctfb;
152 struct fb_info *info;
153
de26ef99 154 if (mpc5121_diu_init() < 0)
51c2ac9b 155 return NULL;
0e1bad47
YS
156
157 /* fill in Graphic device struct */
51c2ac9b 158 sprintf(pGD->modeIdent, "%dx%dx%d %dkHz %dHz",
0e1bad47
YS
159 xres, yres, 32, 64, 60);
160
161 pGD->frameAdrs = (unsigned int)fsl_fb_open(&info);
162 pGD->winSizeX = xres;
163 pGD->winSizeY = yres - info->logo_height;
164 pGD->plnSizeX = pGD->winSizeX;
165 pGD->plnSizeY = pGD->winSizeY;
166
167 pGD->gdfBytesPP = 4;
168 pGD->gdfIndex = GDF_32BIT_X888RGB;
169
170 pGD->isaBase = 0;
171 pGD->pciBase = 0;
172 pGD->memSize = info->screen_size - info->logo_size;
173
174 /* Cursor Start Address */
175 pGD->dprBase = 0;
176 pGD->vprBase = 0;
177 pGD->cprBase = 0;
178
179 return (void *)pGD;
180}
181
0e1bad47 182#endif /* defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) */