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 | |
Peter Tyser | 29514c7 | 2010-04-12 22:28:09 -0500 | [diff] [blame] | 30 | #include "../../../../board/freescale/common/fsl_diu_fb.h" |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 31 | |
| 32 | #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 33 | #include <stdio_dev.h> |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 34 | #include <video_fb.h> |
| 35 | #endif |
| 36 | |
Anatolij Gustschin | 81cad14 | 2010-04-24 19:27:09 +0200 | [diff] [blame] | 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
John Rigby | 2a1979c | 2008-10-30 16:39:35 -0600 | [diff] [blame] | 39 | #ifdef CONFIG_FSL_DIU_LOGO_BMP |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 40 | extern unsigned int FSL_Logo_BMP[]; |
John Rigby | 2a1979c | 2008-10-30 16:39:35 -0600 | [diff] [blame] | 41 | #else |
| 42 | #define FSL_Logo_BMP NULL |
| 43 | #endif |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 44 | |
| 45 | static int xres, yres; |
| 46 | |
| 47 | void diu_set_pixel_clock(unsigned int pixclock) |
| 48 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 49 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 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 */ |
Detlev Zundel | 00c2716 | 2010-01-21 17:55:58 +0100 | [diff] [blame] | 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)); |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 65 | } |
| 66 | |
John Rigby | 3e6375f | 2008-11-19 13:57:34 -0700 | [diff] [blame] | 67 | char *valid_bmp(char *addr) |
| 68 | { |
| 69 | unsigned long h_addr; |
Anatolij Gustschin | 81cad14 | 2010-04-24 19:27:09 +0200 | [diff] [blame] | 70 | bd_t *bd = gd->bd; |
John Rigby | 3e6375f | 2008-11-19 13:57:34 -0700 | [diff] [blame] | 71 | |
| 72 | h_addr = simple_strtoul(addr, NULL, 16); |
Anatolij Gustschin | 81cad14 | 2010-04-24 19:27:09 +0200 | [diff] [blame] | 73 | if (h_addr < bd->bi_flashstart || |
| 74 | h_addr >= (bd->bi_flashstart + bd->bi_flashsize - 1)) { |
John Rigby | 3e6375f | 2008-11-19 13:57:34 -0700 | [diff] [blame] | 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 | |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 84 | int mpc5121_diu_init(void) |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 85 | { |
| 86 | unsigned int pixel_format; |
John Rigby | 3e6375f | 2008-11-19 13:57:34 -0700 | [diff] [blame] | 87 | char *bmp = NULL; |
| 88 | char *bmp_env; |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 89 | |
Anatolij Gustschin | 81cad14 | 2010-04-24 19:27:09 +0200 | [diff] [blame] | 90 | #if defined(CONFIG_VIDEO_XRES) & defined(CONFIG_VIDEO_YRES) |
| 91 | xres = CONFIG_VIDEO_XRES; |
| 92 | yres = CONFIG_VIDEO_YRES; |
| 93 | #else |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 94 | xres = 1024; |
| 95 | yres = 768; |
Anatolij Gustschin | 81cad14 | 2010-04-24 19:27:09 +0200 | [diff] [blame] | 96 | #endif |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 97 | pixel_format = 0x88883316; |
| 98 | |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 99 | debug("mpc5121_diu_init\n"); |
John Rigby | 3e6375f | 2008-11-19 13:57:34 -0700 | [diff] [blame] | 100 | bmp_env = getenv("diu_bmp_addr"); |
| 101 | if (bmp_env) { |
| 102 | bmp = valid_bmp(bmp_env); |
| 103 | } |
| 104 | if (!bmp) |
Wolfgang Denk | bde698d | 2009-05-16 10:47:40 +0200 | [diff] [blame] | 105 | bmp = (char *)FSL_Logo_BMP; |
John Rigby | 3e6375f | 2008-11-19 13:57:34 -0700 | [diff] [blame] | 106 | return fsl_diu_init(xres, pixel_format, 0, (unsigned char *)bmp); |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 107 | } |
| 108 | |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 109 | int mpc5121diu_init_show_bmp(cmd_tbl_t *cmdtp, |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 110 | int flag, int argc, char * const argv[]) |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 111 | { |
| 112 | unsigned int addr; |
| 113 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame^] | 114 | if (argc < 2) |
| 115 | return cmd_usage(cmdtp); |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 116 | |
| 117 | if (!strncmp(argv[1], "init", 4)) { |
| 118 | #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) |
| 119 | fsl_diu_clear_screen(); |
| 120 | drv_video_init(); |
| 121 | #else |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 122 | return mpc5121_diu_init(); |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 123 | #endif |
| 124 | } else { |
| 125 | addr = simple_strtoul(argv[1], NULL, 16); |
| 126 | fsl_diu_clear_screen(); |
| 127 | fsl_diu_display_bmp((unsigned char *)addr, 0, 0, 0); |
| 128 | } |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | U_BOOT_CMD( |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 134 | diufb, CONFIG_SYS_MAXARGS, 1, mpc5121diu_init_show_bmp, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 135 | "Init or Display BMP file", |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 136 | "init\n - initialize DIU\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 137 | "addr\n - display bmp at address 'addr'" |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 138 | ); |
| 139 | |
| 140 | |
| 141 | #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) |
| 142 | |
| 143 | /* |
| 144 | * The Graphic Device |
| 145 | */ |
| 146 | GraphicDevice ctfb; |
| 147 | void *video_hw_init(void) |
| 148 | { |
| 149 | GraphicDevice *pGD = (GraphicDevice *) &ctfb; |
| 150 | struct fb_info *info; |
| 151 | |
Wolfgang Denk | e384d2e | 2009-05-16 10:47:38 +0200 | [diff] [blame] | 152 | if (mpc5121_diu_init() < 0) |
Anatolij Gustschin | 1f70edc | 2010-03-16 17:10:08 +0100 | [diff] [blame] | 153 | return NULL; |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 154 | |
| 155 | /* fill in Graphic device struct */ |
Anatolij Gustschin | 1f70edc | 2010-03-16 17:10:08 +0100 | [diff] [blame] | 156 | sprintf(pGD->modeIdent, "%dx%dx%d %dkHz %dHz", |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 157 | xres, yres, 32, 64, 60); |
| 158 | |
| 159 | pGD->frameAdrs = (unsigned int)fsl_fb_open(&info); |
| 160 | pGD->winSizeX = xres; |
| 161 | pGD->winSizeY = yres - info->logo_height; |
| 162 | pGD->plnSizeX = pGD->winSizeX; |
| 163 | pGD->plnSizeY = pGD->winSizeY; |
| 164 | |
| 165 | pGD->gdfBytesPP = 4; |
| 166 | pGD->gdfIndex = GDF_32BIT_X888RGB; |
| 167 | |
| 168 | pGD->isaBase = 0; |
| 169 | pGD->pciBase = 0; |
| 170 | pGD->memSize = info->screen_size - info->logo_size; |
| 171 | |
| 172 | /* Cursor Start Address */ |
| 173 | pGD->dprBase = 0; |
| 174 | pGD->vprBase = 0; |
| 175 | pGD->cprBase = 0; |
| 176 | |
| 177 | return (void *)pGD; |
| 178 | } |
| 179 | |
York Sun | fd7cbfd | 2008-05-05 10:20:01 -0500 | [diff] [blame] | 180 | #endif /* defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) */ |