York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 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 | |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 30 | #include "../../board/freescale/common/pixis.h" |
| 31 | #include "../../board/freescale/common/fsl_diu_fb.h" |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 32 | |
| 33 | #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) |
| 34 | #include <devices.h> |
| 35 | #include <video_fb.h> |
| 36 | #endif |
| 37 | |
John Rigby | 2a1979c | 2008-10-30 16:39:35 -0600 | [diff] [blame] | 38 | #ifdef CONFIG_FSL_DIU_LOGO_BMP |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 39 | extern unsigned int FSL_Logo_BMP[]; |
John Rigby | 2a1979c | 2008-10-30 16:39:35 -0600 | [diff] [blame] | 40 | #else |
| 41 | #define FSL_Logo_BMP NULL |
| 42 | #endif |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 43 | |
| 44 | static int xres, yres; |
| 45 | |
| 46 | void diu_set_pixel_clock(unsigned int pixclock) |
| 47 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 48 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 49 | volatile clk512x_t *clk = &immap->clk; |
| 50 | volatile unsigned int *clkdvdr = &clk->scfr[0]; |
| 51 | unsigned long speed_ccb, temp, pixval; |
| 52 | |
| 53 | speed_ccb = get_bus_freq(0) * 4; |
| 54 | temp = 1000000000/pixclock; |
| 55 | temp *= 1000; |
| 56 | pixval = speed_ccb / temp; |
| 57 | debug("DIU pixval = %lu\n", pixval); |
| 58 | |
| 59 | /* Modify PXCLK in GUTS CLKDVDR */ |
| 60 | debug("DIU: Current value of CLKDVDR = 0x%08x\n", *clkdvdr); |
| 61 | temp = *clkdvdr & 0xFFFFFF00; |
Kenneth Johansson | 9627310 | 2008-07-12 13:18:34 -0600 | [diff] [blame] | 62 | *clkdvdr = temp | (pixval & 0xFF); |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 63 | debug("DIU: Modified value of CLKDVDR = 0x%08x\n", *clkdvdr); |
| 64 | } |
| 65 | |
John Rigby | 3e6375f | 2008-11-19 13:57:34 -0700 | [diff] [blame] | 66 | char *valid_bmp(char *addr) |
| 67 | { |
| 68 | unsigned long h_addr; |
| 69 | |
| 70 | h_addr = simple_strtoul(addr, NULL, 16); |
| 71 | if (h_addr < CONFIG_SYS_FLASH_BASE || |
| 72 | h_addr >= (CONFIG_SYS_FLASH_BASE + CONFIG_SYS_FLASH_SIZE - 1)) { |
| 73 | printf("bmp addr %lx is not a valid flash address\n", h_addr); |
| 74 | return 0; |
| 75 | } else if ((*(char *)(h_addr) != 'B') || (*(char *)(h_addr+1) != 'M')) { |
| 76 | printf("bmp addr is not a bmp\n"); |
| 77 | return 0; |
| 78 | } else |
| 79 | return (char *)h_addr; |
| 80 | } |
| 81 | |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 82 | int mpc5121_diu_init(void) |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 83 | { |
| 84 | unsigned int pixel_format; |
John Rigby | 3e6375f | 2008-11-19 13:57:34 -0700 | [diff] [blame] | 85 | char *bmp = NULL; |
| 86 | char *bmp_env; |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 87 | |
| 88 | xres = 1024; |
| 89 | yres = 768; |
| 90 | pixel_format = 0x88883316; |
| 91 | |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 92 | debug("mpc5121_diu_init\n"); |
John Rigby | 3e6375f | 2008-11-19 13:57:34 -0700 | [diff] [blame] | 93 | bmp_env = getenv("diu_bmp_addr"); |
| 94 | if (bmp_env) { |
| 95 | bmp = valid_bmp(bmp_env); |
| 96 | } |
| 97 | if (!bmp) |
Wolfgang Denk | bde698d | 2009-05-16 10:47:40 +0200 | [diff] [blame^] | 98 | bmp = (char *)FSL_Logo_BMP; |
John Rigby | 3e6375f | 2008-11-19 13:57:34 -0700 | [diff] [blame] | 99 | return fsl_diu_init(xres, pixel_format, 0, (unsigned char *)bmp); |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 100 | } |
| 101 | |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 102 | int mpc5121diu_init_show_bmp(cmd_tbl_t *cmdtp, |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 103 | int flag, int argc, char *argv[]) |
| 104 | { |
| 105 | unsigned int addr; |
| 106 | |
| 107 | if (argc < 2) { |
Peter Tyser | ddb3af9 | 2009-01-27 18:03:10 -0600 | [diff] [blame] | 108 | cmd_usage(cmdtp); |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 109 | return 1; |
| 110 | } |
| 111 | |
| 112 | if (!strncmp(argv[1], "init", 4)) { |
| 113 | #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) |
| 114 | fsl_diu_clear_screen(); |
| 115 | drv_video_init(); |
| 116 | #else |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 117 | return mpc5121_diu_init(); |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 118 | #endif |
| 119 | } else { |
| 120 | addr = simple_strtoul(argv[1], NULL, 16); |
| 121 | fsl_diu_clear_screen(); |
| 122 | fsl_diu_display_bmp((unsigned char *)addr, 0, 0, 0); |
| 123 | } |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | U_BOOT_CMD( |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 129 | diufb, CONFIG_SYS_MAXARGS, 1, mpc5121diu_init_show_bmp, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 130 | "Init or Display BMP file", |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 131 | "init\n - initialize DIU\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 132 | "addr\n - display bmp at address 'addr'" |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 133 | ); |
| 134 | |
| 135 | |
| 136 | #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) |
| 137 | |
| 138 | /* |
| 139 | * The Graphic Device |
| 140 | */ |
| 141 | GraphicDevice ctfb; |
| 142 | void *video_hw_init(void) |
| 143 | { |
| 144 | GraphicDevice *pGD = (GraphicDevice *) &ctfb; |
| 145 | struct fb_info *info; |
| 146 | |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 147 | if (mpc5121_diu_init() < 0) |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 148 | return; |
| 149 | |
| 150 | /* fill in Graphic device struct */ |
| 151 | sprintf(pGD->modeIdent, "%dx%dx%d %ldkHz %ldHz", |
| 152 | xres, yres, 32, 64, 60); |
| 153 | |
| 154 | pGD->frameAdrs = (unsigned int)fsl_fb_open(&info); |
| 155 | pGD->winSizeX = xres; |
| 156 | pGD->winSizeY = yres - info->logo_height; |
| 157 | pGD->plnSizeX = pGD->winSizeX; |
| 158 | pGD->plnSizeY = pGD->winSizeY; |
| 159 | |
| 160 | pGD->gdfBytesPP = 4; |
| 161 | pGD->gdfIndex = GDF_32BIT_X888RGB; |
| 162 | |
| 163 | pGD->isaBase = 0; |
| 164 | pGD->pciBase = 0; |
| 165 | pGD->memSize = info->screen_size - info->logo_size; |
| 166 | |
| 167 | /* Cursor Start Address */ |
| 168 | pGD->dprBase = 0; |
| 169 | pGD->vprBase = 0; |
| 170 | pGD->cprBase = 0; |
| 171 | |
| 172 | return (void *)pGD; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Set the LUT |
| 177 | * |
| 178 | * @index: color number |
| 179 | * @r: red |
| 180 | * @b: blue |
| 181 | * @g: green |
| 182 | */ |
| 183 | void video_set_lut |
| 184 | (unsigned int index, unsigned char r, unsigned char g, unsigned char b) |
| 185 | { |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | #endif /* defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) */ |