]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/powerpc/cpu/mpc512x/diu.c
Move arch/ppc to arch/powerpc
[karo-tx-uboot.git] / arch / powerpc / cpu / mpc512x / diu.c
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
30 #include "../../../../board/freescale/common/fsl_diu_fb.h"
31
32 #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
33 #include <stdio_dev.h>
34 #include <video_fb.h>
35 #endif
36
37 #ifdef CONFIG_FSL_DIU_LOGO_BMP
38 extern unsigned int FSL_Logo_BMP[];
39 #else
40 #define FSL_Logo_BMP NULL
41 #endif
42
43 static int xres, yres;
44
45 void diu_set_pixel_clock(unsigned int pixclock)
46 {
47         volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
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 */
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));
63 }
64
65 char *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
81 int mpc5121_diu_init(void)
82 {
83         unsigned int pixel_format;
84         char *bmp = NULL;
85         char *bmp_env;
86
87         xres = 1024;
88         yres = 768;
89         pixel_format = 0x88883316;
90
91         debug("mpc5121_diu_init\n");
92         bmp_env = getenv("diu_bmp_addr");
93         if (bmp_env) {
94                 bmp = valid_bmp(bmp_env);
95         }
96         if (!bmp)
97                 bmp = (char *)FSL_Logo_BMP;
98         return fsl_diu_init(xres, pixel_format, 0, (unsigned char *)bmp);
99 }
100
101 int mpc5121diu_init_show_bmp(cmd_tbl_t *cmdtp,
102                              int flag, int argc, char *argv[])
103 {
104         unsigned int addr;
105
106         if (argc < 2) {
107                 cmd_usage(cmdtp);
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
116                 return mpc5121_diu_init();
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
127 U_BOOT_CMD(
128         diufb, CONFIG_SYS_MAXARGS, 1, mpc5121diu_init_show_bmp,
129         "Init or Display BMP file",
130         "init\n    - initialize DIU\n"
131         "addr\n    - display bmp at address 'addr'"
132         );
133
134
135 #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
136
137 /*
138  * The Graphic Device
139  */
140 GraphicDevice ctfb;
141 void *video_hw_init(void)
142 {
143         GraphicDevice *pGD = (GraphicDevice *) &ctfb;
144         struct fb_info *info;
145
146         if (mpc5121_diu_init() < 0)
147                 return NULL;
148
149         /* fill in Graphic device struct */
150         sprintf(pGD->modeIdent, "%dx%dx%d %dkHz %dHz",
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   */
182 void 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) */