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