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