York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 1 | /* |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 2 | * Copyright 2007, 2010-2011 Freescale Semiconductor, Inc. |
| 3 | * Authors: York Sun <yorksun@freescale.com> |
| 4 | * Timur Tabi <timur@freescale.com> |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 5 | * |
| 6 | * FSL DIU Framebuffer driver |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 27 | #include <common.h> |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 28 | #include <malloc.h> |
Jerry Huang | 54e4b89 | 2010-04-08 15:56:07 +0800 | [diff] [blame] | 29 | #include <asm/io.h> |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 30 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 31 | #include "videomodes.h" |
| 32 | #include <video_fb.h> |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame] | 33 | #include <fsl_diu_fb.h> |
Timur Tabi | d8cf0b5 | 2011-08-22 10:54:02 -0500 | [diff] [blame] | 34 | #include <linux/list.h> |
| 35 | #include <linux/fb.h> |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 36 | |
Anatolij Gustschin | 81cad14 | 2010-04-24 19:27:09 +0200 | [diff] [blame] | 37 | /* This setting is used for the ifm pdm360ng with PRIMEVIEW PM070WL3 */ |
Timur Tabi | 6d99ce2 | 2011-05-26 09:02:17 -0500 | [diff] [blame] | 38 | static struct fb_videomode fsl_diu_mode_800_480 = { |
| 39 | .name = "800x480-60", |
Anatolij Gustschin | 81cad14 | 2010-04-24 19:27:09 +0200 | [diff] [blame] | 40 | .refresh = 60, |
| 41 | .xres = 800, |
| 42 | .yres = 480, |
| 43 | .pixclock = 31250, |
| 44 | .left_margin = 86, |
| 45 | .right_margin = 42, |
| 46 | .upper_margin = 33, |
| 47 | .lower_margin = 10, |
| 48 | .hsync_len = 128, |
| 49 | .vsync_len = 2, |
| 50 | .sync = 0, |
| 51 | .vmode = FB_VMODE_NONINTERLACED |
| 52 | }; |
| 53 | |
Timur Tabi | 6d99ce2 | 2011-05-26 09:02:17 -0500 | [diff] [blame] | 54 | /* For the SHARP LQ084S3LG01, used on the P1022DS board */ |
| 55 | static struct fb_videomode fsl_diu_mode_800_600 = { |
| 56 | .name = "800x600-60", |
| 57 | .refresh = 60, |
| 58 | .xres = 800, |
| 59 | .yres = 600, |
| 60 | .pixclock = 25000, |
| 61 | .left_margin = 88, |
| 62 | .right_margin = 40, |
| 63 | .upper_margin = 23, |
| 64 | .lower_margin = 1, |
| 65 | .hsync_len = 128, |
| 66 | .vsync_len = 4, |
| 67 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 68 | .vmode = FB_VMODE_NONINTERLACED |
| 69 | }; |
| 70 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 71 | /* |
| 72 | * These parameters give default parameters |
| 73 | * for video output 1024x768, |
| 74 | * FIXME - change timing to proper amounts |
| 75 | * hsync 31.5kHz, vsync 60Hz |
| 76 | */ |
Timur Tabi | 6d99ce2 | 2011-05-26 09:02:17 -0500 | [diff] [blame] | 77 | static struct fb_videomode fsl_diu_mode_1024_768 = { |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 78 | .name = "1024x768-60", |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 79 | .refresh = 60, |
| 80 | .xres = 1024, |
| 81 | .yres = 768, |
| 82 | .pixclock = 15385, |
| 83 | .left_margin = 160, |
| 84 | .right_margin = 24, |
| 85 | .upper_margin = 29, |
| 86 | .lower_margin = 3, |
| 87 | .hsync_len = 136, |
| 88 | .vsync_len = 6, |
| 89 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 90 | .vmode = FB_VMODE_NONINTERLACED |
| 91 | }; |
| 92 | |
Timur Tabi | 6d99ce2 | 2011-05-26 09:02:17 -0500 | [diff] [blame] | 93 | static struct fb_videomode fsl_diu_mode_1280_1024 = { |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 94 | .name = "1280x1024-60", |
| 95 | .refresh = 60, |
| 96 | .xres = 1280, |
| 97 | .yres = 1024, |
| 98 | .pixclock = 9375, |
| 99 | .left_margin = 38, |
| 100 | .right_margin = 128, |
| 101 | .upper_margin = 2, |
| 102 | .lower_margin = 7, |
| 103 | .hsync_len = 216, |
| 104 | .vsync_len = 37, |
| 105 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 106 | .vmode = FB_VMODE_NONINTERLACED |
| 107 | }; |
| 108 | |
| 109 | /* |
| 110 | * These are the fields of area descriptor(in DDR memory) for every plane |
| 111 | */ |
| 112 | struct diu_ad { |
| 113 | /* Word 0(32-bit) in DDR memory */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 114 | __le32 pix_fmt; /* hard coding pixel format */ |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 115 | /* Word 1(32-bit) in DDR memory */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 116 | __le32 addr; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 117 | /* Word 2(32-bit) in DDR memory */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 118 | __le32 src_size_g_alpha; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 119 | /* Word 3(32-bit) in DDR memory */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 120 | __le32 aoi_size; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 121 | /* Word 4(32-bit) in DDR memory */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 122 | __le32 offset_xyi; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 123 | /* Word 5(32-bit) in DDR memory */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 124 | __le32 offset_xyd; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 125 | /* Word 6(32-bit) in DDR memory */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 126 | __le32 ckmax_r:8; |
| 127 | __le32 ckmax_g:8; |
| 128 | __le32 ckmax_b:8; |
| 129 | __le32 res9:8; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 130 | /* Word 7(32-bit) in DDR memory */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 131 | __le32 ckmin_r:8; |
| 132 | __le32 ckmin_g:8; |
| 133 | __le32 ckmin_b:8; |
| 134 | __le32 res10:8; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 135 | /* Word 8(32-bit) in DDR memory */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 136 | __le32 next_ad; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 137 | /* Word 9(32-bit) in DDR memory, just for 64-bit aligned */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 138 | __le32 res[3]; |
| 139 | } __attribute__ ((packed)); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * DIU register map |
| 143 | */ |
| 144 | struct diu { |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 145 | __be32 desc[3]; |
| 146 | __be32 gamma; |
| 147 | __be32 pallete; |
| 148 | __be32 cursor; |
| 149 | __be32 curs_pos; |
| 150 | __be32 diu_mode; |
| 151 | __be32 bgnd; |
| 152 | __be32 bgnd_wb; |
| 153 | __be32 disp_size; |
| 154 | __be32 wb_size; |
| 155 | __be32 wb_mem_addr; |
| 156 | __be32 hsyn_para; |
| 157 | __be32 vsyn_para; |
| 158 | __be32 syn_pol; |
| 159 | __be32 thresholds; |
| 160 | __be32 int_status; |
| 161 | __be32 int_mask; |
| 162 | __be32 colorbar[8]; |
| 163 | __be32 filling; |
| 164 | __be32 plut; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 165 | } __attribute__ ((packed)); |
| 166 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 167 | struct diu_addr { |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 168 | void *vaddr; /* Virtual address */ |
| 169 | u32 paddr; /* 32-bit physical address */ |
| 170 | unsigned int offset; /* Alignment offset */ |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 171 | }; |
| 172 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 173 | static struct fb_info info; |
| 174 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 175 | /* |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 176 | * Align to 64-bit(8-byte), 32-byte, etc. |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 177 | */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 178 | static int allocate_buf(struct diu_addr *buf, u32 size, u32 bytes_align) |
| 179 | { |
| 180 | u32 offset, ssize; |
| 181 | u32 mask; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 182 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 183 | ssize = size + bytes_align; |
| 184 | buf->vaddr = malloc(ssize); |
| 185 | if (!buf->vaddr) |
| 186 | return -1; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 187 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 188 | memset(buf->vaddr, 0, ssize); |
| 189 | mask = bytes_align - 1; |
| 190 | offset = (u32)buf->vaddr & mask; |
| 191 | if (offset) { |
| 192 | buf->offset = bytes_align - offset; |
| 193 | buf->vaddr += offset; |
| 194 | } else |
| 195 | buf->offset = 0; |
| 196 | |
| 197 | buf->paddr = virt_to_phys(buf->vaddr); |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | * Allocate a framebuffer and an Area Descriptor that points to it. Both |
| 203 | * are created in the same memory block. The Area Descriptor is updated to |
| 204 | * point to the framebuffer memory. Memory is aligned as needed. |
| 205 | */ |
| 206 | static struct diu_ad *allocate_fb(unsigned int xres, unsigned int yres, |
Timur Tabi | d8cf0b5 | 2011-08-22 10:54:02 -0500 | [diff] [blame] | 207 | unsigned int depth, char **fb) |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 208 | { |
| 209 | unsigned long size = xres * yres * depth; |
| 210 | struct diu_addr addr; |
| 211 | struct diu_ad *ad; |
| 212 | size_t ad_size = roundup(sizeof(struct diu_ad), 32); |
| 213 | |
| 214 | /* |
| 215 | * Allocate a memory block that holds the Area Descriptor and the |
| 216 | * frame buffer right behind it. To keep the code simple, everything |
| 217 | * is aligned on a 32-byte address. |
| 218 | */ |
| 219 | if (allocate_buf(&addr, ad_size + size, 32) < 0) |
| 220 | return NULL; |
| 221 | |
| 222 | ad = addr.vaddr; |
| 223 | ad->addr = cpu_to_le32(addr.paddr + ad_size); |
| 224 | ad->aoi_size = cpu_to_le32((yres << 16) | xres); |
| 225 | ad->src_size_g_alpha = cpu_to_le32((yres << 12) | xres); |
| 226 | ad->offset_xyi = 0; |
| 227 | ad->offset_xyd = 0; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 228 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 229 | if (fb) |
| 230 | *fb = addr.vaddr + ad_size; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 231 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 232 | return ad; |
| 233 | } |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 234 | |
Timur Tabi | 6d99ce2 | 2011-05-26 09:02:17 -0500 | [diff] [blame] | 235 | int fsl_diu_init(u16 xres, u16 yres, u32 pixel_format, int gamma_fix) |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 236 | { |
| 237 | struct fb_videomode *fsl_diu_mode_db; |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 238 | struct diu_ad *ad; |
| 239 | struct diu *hw = (struct diu *)CONFIG_SYS_DIU_ADDR; |
| 240 | u8 *gamma_table_base; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 241 | unsigned int i, j; |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 242 | struct diu_ad *dummy_ad; |
| 243 | struct diu_addr gamma; |
| 244 | struct diu_addr cursor; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 245 | |
Timur Tabi | 6d99ce2 | 2011-05-26 09:02:17 -0500 | [diff] [blame] | 246 | /* Convert the X,Y resolution pair into a single number */ |
| 247 | #define RESOLUTION(x, y) (((u32)(x) << 16) | (y)) |
| 248 | |
| 249 | switch (RESOLUTION(xres, yres)) { |
| 250 | case RESOLUTION(800, 480): |
| 251 | fsl_diu_mode_db = &fsl_diu_mode_800_480; |
Anatolij Gustschin | 81cad14 | 2010-04-24 19:27:09 +0200 | [diff] [blame] | 252 | break; |
Timur Tabi | 6d99ce2 | 2011-05-26 09:02:17 -0500 | [diff] [blame] | 253 | case RESOLUTION(800, 600): |
| 254 | fsl_diu_mode_db = &fsl_diu_mode_800_600; |
| 255 | case RESOLUTION(1024, 768): |
| 256 | fsl_diu_mode_db = &fsl_diu_mode_1024_768; |
| 257 | case RESOLUTION(1280, 1024): |
| 258 | fsl_diu_mode_db = &fsl_diu_mode_1280_1024; |
Anatolij Gustschin | 81cad14 | 2010-04-24 19:27:09 +0200 | [diff] [blame] | 259 | break; |
| 260 | default: |
Timur Tabi | 6d99ce2 | 2011-05-26 09:02:17 -0500 | [diff] [blame] | 261 | printf("DIU: Unsupported resolution %ux%u\n", xres, yres); |
| 262 | return -1; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 263 | } |
| 264 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 265 | /* The AD struct for the dummy framebuffer and the FB itself */ |
| 266 | dummy_ad = allocate_fb(2, 4, 4, NULL); |
| 267 | if (!dummy_ad) { |
| 268 | printf("DIU: Out of memory\n"); |
| 269 | return -1; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 270 | } |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 271 | dummy_ad->pix_fmt = 0x88883316; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 272 | |
| 273 | /* read mode info */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 274 | info.var.xres = fsl_diu_mode_db->xres; |
| 275 | info.var.yres = fsl_diu_mode_db->yres; |
| 276 | info.var.bits_per_pixel = 32; |
| 277 | info.var.pixclock = fsl_diu_mode_db->pixclock; |
| 278 | info.var.left_margin = fsl_diu_mode_db->left_margin; |
| 279 | info.var.right_margin = fsl_diu_mode_db->right_margin; |
| 280 | info.var.upper_margin = fsl_diu_mode_db->upper_margin; |
| 281 | info.var.lower_margin = fsl_diu_mode_db->lower_margin; |
| 282 | info.var.hsync_len = fsl_diu_mode_db->hsync_len; |
| 283 | info.var.vsync_len = fsl_diu_mode_db->vsync_len; |
| 284 | info.var.sync = fsl_diu_mode_db->sync; |
| 285 | info.var.vmode = fsl_diu_mode_db->vmode; |
Timur Tabi | d8cf0b5 | 2011-08-22 10:54:02 -0500 | [diff] [blame] | 286 | info.fix.line_length = info.var.xres * info.var.bits_per_pixel / 8; |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 287 | |
| 288 | /* Memory allocation for framebuffer */ |
Timur Tabi | d8cf0b5 | 2011-08-22 10:54:02 -0500 | [diff] [blame] | 289 | info.screen_size = |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 290 | info.var.xres * info.var.yres * (info.var.bits_per_pixel / 8); |
| 291 | ad = allocate_fb(info.var.xres, info.var.yres, |
| 292 | info.var.bits_per_pixel / 8, &info.screen_base); |
| 293 | if (!ad) { |
| 294 | printf("DIU: Out of memory\n"); |
| 295 | return -1; |
| 296 | } |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 297 | |
| 298 | ad->pix_fmt = pixel_format; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 299 | |
| 300 | /* Disable chroma keying function */ |
| 301 | ad->ckmax_r = 0; |
| 302 | ad->ckmax_g = 0; |
| 303 | ad->ckmax_b = 0; |
| 304 | |
| 305 | ad->ckmin_r = 255; |
| 306 | ad->ckmin_g = 255; |
| 307 | ad->ckmin_b = 255; |
| 308 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 309 | /* Initialize the gamma table */ |
| 310 | if (allocate_buf(&gamma, 256 * 3, 32) < 0) { |
| 311 | printf("DIU: Out of memory\n"); |
| 312 | return -1; |
| 313 | } |
| 314 | gamma_table_base = gamma.vaddr; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 315 | for (i = 0; i <= 2; i++) |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 316 | for (j = 0; j < 256; j++) |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 317 | *gamma_table_base++ = j; |
| 318 | |
| 319 | if (gamma_fix == 1) { /* fix the gamma */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 320 | gamma_table_base = gamma.vaddr; |
| 321 | for (i = 0; i < 256 * 3; i++) { |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 322 | gamma_table_base[i] = (gamma_table_base[i] << 2) |
| 323 | | ((gamma_table_base[i] >> 6) & 0x03); |
| 324 | } |
| 325 | } |
| 326 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 327 | /* Initialize the cursor */ |
| 328 | if (allocate_buf(&cursor, 32 * 32 * 2, 32) < 0) { |
| 329 | printf("DIU: Can't alloc cursor data\n"); |
| 330 | return -1; |
| 331 | } |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 332 | |
| 333 | /* Program DIU registers */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 334 | out_be32(&hw->diu_mode, 0); /* Temporarily disable the DIU */ |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 335 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 336 | out_be32(&hw->gamma, gamma.paddr); |
| 337 | out_be32(&hw->cursor, cursor.paddr); |
Jerry Huang | 54e4b89 | 2010-04-08 15:56:07 +0800 | [diff] [blame] | 338 | out_be32(&hw->bgnd, 0x007F7F7F); |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 339 | out_be32(&hw->bgnd_wb, 0); |
| 340 | out_be32(&hw->disp_size, info.var.yres << 16 | info.var.xres); |
| 341 | out_be32(&hw->wb_size, 0); |
| 342 | out_be32(&hw->wb_mem_addr, 0); |
| 343 | out_be32(&hw->hsyn_para, info.var.left_margin << 22 | |
| 344 | info.var.hsync_len << 11 | |
| 345 | info.var.right_margin); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 346 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 347 | out_be32(&hw->vsyn_para, info.var.upper_margin << 22 | |
| 348 | info.var.vsync_len << 11 | |
| 349 | info.var.lower_margin); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 350 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 351 | out_be32(&hw->syn_pol, 0); |
| 352 | out_be32(&hw->thresholds, 0x00037800); |
| 353 | out_be32(&hw->int_status, 0); |
| 354 | out_be32(&hw->int_mask, 0); |
Jerry Huang | 54e4b89 | 2010-04-08 15:56:07 +0800 | [diff] [blame] | 355 | out_be32(&hw->plut, 0x01F5F666); |
York Sun | c496438 | 2008-05-05 10:19:59 -0500 | [diff] [blame] | 356 | /* Pixel Clock configuration */ |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 357 | diu_set_pixel_clock(info.var.pixclock); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 358 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 359 | /* Set the frame buffers */ |
| 360 | out_be32(&hw->desc[0], virt_to_phys(ad)); |
| 361 | out_be32(&hw->desc[1], virt_to_phys(dummy_ad)); |
| 362 | out_be32(&hw->desc[2], virt_to_phys(dummy_ad)); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 363 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 364 | /* Enable the DIU, set display to all three planes */ |
| 365 | out_be32(&hw->diu_mode, 1); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 366 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 370 | void *video_hw_init(void) |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 371 | { |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 372 | static GraphicDevice ctfb; |
| 373 | const char *options; |
| 374 | unsigned int depth = 0, freq = 0; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 375 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 376 | if (!video_get_video_mode(&ctfb.winSizeX, &ctfb.winSizeY, &depth, &freq, |
| 377 | &options)) |
| 378 | return NULL; |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame] | 379 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 380 | /* Find the monitor port, which is a required option */ |
| 381 | if (!options) |
| 382 | return NULL; |
| 383 | if (strncmp(options, "monitor=", 8) != 0) |
| 384 | return NULL; |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame] | 385 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 386 | if (platform_diu_init(ctfb.winSizeX, ctfb.winSizeY, options + 8) < 0) |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame] | 387 | return NULL; |
| 388 | |
| 389 | /* fill in Graphic device struct */ |
| 390 | sprintf(ctfb.modeIdent, "%ix%ix%i %ikHz %iHz", |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 391 | ctfb.winSizeX, ctfb.winSizeY, depth, 64, freq); |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame] | 392 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 393 | ctfb.frameAdrs = (unsigned int)info.screen_base; |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame] | 394 | ctfb.plnSizeX = ctfb.winSizeX; |
| 395 | ctfb.plnSizeY = ctfb.winSizeY; |
| 396 | |
| 397 | ctfb.gdfBytesPP = 4; |
| 398 | ctfb.gdfIndex = GDF_32BIT_X888RGB; |
| 399 | |
| 400 | ctfb.isaBase = 0; |
| 401 | ctfb.pciBase = 0; |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 402 | ctfb.memSize = info.screen_size; |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame] | 403 | |
| 404 | /* Cursor Start Address */ |
| 405 | ctfb.dprBase = 0; |
| 406 | ctfb.vprBase = 0; |
| 407 | ctfb.cprBase = 0; |
| 408 | |
| 409 | return &ctfb; |
| 410 | } |