Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007 |
| 4 | * DENX Software Engineering, Anatolij Gustschin, agust@denx.de |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * mb862xx.c - Graphic interface for Fujitsu CoralP/Lime |
| 9 | * PCI and video mode code was derived from smiLynxEM driver. |
| 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 13 | #include <linux/delay.h> |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 14 | |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 15 | #include <asm/io.h> |
Simon Glass | 7b51b57 | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 16 | #include <env.h> |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 17 | #include <pci.h> |
| 18 | #include <video_fb.h> |
| 19 | #include "videomodes.h" |
| 20 | #include <mb862xx.h> |
| 21 | |
Yuri Tikhonov | 0d48926 | 2008-03-24 11:30:54 +0100 | [diff] [blame] | 22 | #if defined(CONFIG_POST) |
| 23 | #include <post.h> |
| 24 | #endif |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 25 | |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 26 | /* |
| 27 | * Graphic Device |
| 28 | */ |
| 29 | GraphicDevice mb862xx; |
| 30 | |
| 31 | /* |
| 32 | * 32MB external RAM - 256K Chip MMIO = 0x1FC0000 ; |
| 33 | */ |
| 34 | #define VIDEO_MEM_SIZE 0x01FC0000 |
| 35 | |
| 36 | #if defined(CONFIG_PCI) |
| 37 | #if defined(CONFIG_VIDEO_CORALP) |
| 38 | |
| 39 | static struct pci_device_id supported[] = { |
| 40 | { PCI_VENDOR_ID_FUJITSU, PCI_DEVICE_ID_CORAL_P }, |
| 41 | { PCI_VENDOR_ID_FUJITSU, PCI_DEVICE_ID_CORAL_PA }, |
| 42 | { } |
| 43 | }; |
| 44 | |
| 45 | /* Internal clock frequency divider table, index is mode number */ |
| 46 | unsigned int fr_div[] = { 0x00000f00, 0x00000900, 0x00000500 }; |
| 47 | #endif |
| 48 | #endif |
| 49 | |
| 50 | #if defined(CONFIG_VIDEO_CORALP) |
| 51 | #define rd_io in32r |
| 52 | #define wr_io out32r |
| 53 | #else |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 54 | #define rd_io(addr) in_be32((volatile unsigned *)(addr)) |
| 55 | #define wr_io(addr, val) out_be32((volatile unsigned *)(addr), (val)) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 56 | #endif |
| 57 | |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 58 | #define HOST_RD_REG(off) rd_io((dev->frameAdrs + GC_HOST_BASE + (off))) |
| 59 | #define HOST_WR_REG(off, val) wr_io((dev->frameAdrs + GC_HOST_BASE + (off)), \ |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 60 | (val)) |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 61 | #define DISP_RD_REG(off) rd_io((dev->frameAdrs + GC_DISP_BASE + (off))) |
| 62 | #define DISP_WR_REG(off, val) wr_io((dev->frameAdrs + GC_DISP_BASE + (off)), \ |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 63 | (val)) |
| 64 | #define DE_RD_REG(off) rd_io((dev->dprBase + (off))) |
| 65 | #define DE_WR_REG(off, val) wr_io((dev->dprBase + (off)), (val)) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 66 | |
| 67 | #if defined(CONFIG_VIDEO_CORALP) |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 68 | #define DE_WR_FIFO(val) wr_io((dev->dprBase + (GC_GEO_FIFO)), (val)) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 69 | #else |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 70 | #define DE_WR_FIFO(val) wr_io((dev->dprBase + (GC_FIFO)), (val)) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 71 | #endif |
| 72 | |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 73 | #define L0PAL_WR_REG(idx, val) wr_io((dev->frameAdrs + \ |
| 74 | (GC_DISP_BASE | GC_L0PAL0) + \ |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 75 | ((idx) << 2)), (val)) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 76 | |
Anatolij Gustschin | 5d16ca8 | 2009-10-23 12:03:14 +0200 | [diff] [blame] | 77 | #if defined(CONFIG_VIDEO_MB862xx_ACCEL) |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 78 | static void gdc_sw_reset (void) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 79 | { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 80 | GraphicDevice *dev = &mb862xx; |
| 81 | |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 82 | HOST_WR_REG (GC_SRST, 0x1); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 83 | udelay(500); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 84 | video_hw_init (); |
| 85 | } |
| 86 | |
| 87 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 88 | static void de_wait (void) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 89 | { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 90 | GraphicDevice *dev = &mb862xx; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 91 | int lc = 0x10000; |
| 92 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 93 | /* |
| 94 | * Sync with software writes to framebuffer, |
| 95 | * try to reset if engine locked |
| 96 | */ |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 97 | while (DE_RD_REG (GC_CTR) & 0x00000131) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 98 | if (lc-- < 0) { |
| 99 | gdc_sw_reset (); |
Anatolij Gustschin | 9d173e0 | 2009-07-07 13:11:36 +0200 | [diff] [blame] | 100 | puts ("gdc reset done after drawing engine lock.\n"); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 101 | break; |
| 102 | } |
| 103 | } |
| 104 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 105 | static void de_wait_slots (int slots) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 106 | { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 107 | GraphicDevice *dev = &mb862xx; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 108 | int lc = 0x10000; |
| 109 | |
| 110 | /* Wait for free fifo slots */ |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 111 | while (DE_RD_REG (GC_IFCNT) < slots) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 112 | if (lc-- < 0) { |
| 113 | gdc_sw_reset (); |
Anatolij Gustschin | 9d173e0 | 2009-07-07 13:11:36 +0200 | [diff] [blame] | 114 | puts ("gdc reset done after drawing engine lock.\n"); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 115 | break; |
| 116 | } |
| 117 | } |
Anatolij Gustschin | 5d16ca8 | 2009-10-23 12:03:14 +0200 | [diff] [blame] | 118 | #endif |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 119 | |
| 120 | #if !defined(CONFIG_VIDEO_CORALP) |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 121 | static void board_disp_init (void) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 122 | { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 123 | GraphicDevice *dev = &mb862xx; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 124 | const gdc_regs *regs = board_get_regs (); |
| 125 | |
| 126 | while (regs->index) { |
| 127 | DISP_WR_REG (regs->index, regs->value); |
| 128 | regs++; |
| 129 | } |
| 130 | } |
| 131 | #endif |
| 132 | |
| 133 | /* |
Anatolij Gustschin | 5d16ca8 | 2009-10-23 12:03:14 +0200 | [diff] [blame] | 134 | * Init drawing engine if accel enabled. |
| 135 | * Also clears visible framebuffer. |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 136 | */ |
| 137 | static void de_init (void) |
| 138 | { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 139 | GraphicDevice *dev = &mb862xx; |
Anatolij Gustschin | 5d16ca8 | 2009-10-23 12:03:14 +0200 | [diff] [blame] | 140 | #if defined(CONFIG_VIDEO_MB862xx_ACCEL) |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 141 | int cf = (dev->gdfBytesPP == 1) ? 0x0000 : 0x8000; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 142 | |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 143 | dev->dprBase = dev->frameAdrs + GC_DRAW_BASE; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 144 | |
| 145 | /* Setup mode and fbbase, xres, fg, bg */ |
| 146 | de_wait_slots (2); |
| 147 | DE_WR_FIFO (0xf1010108); |
| 148 | DE_WR_FIFO (cf | 0x0300); |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 149 | DE_WR_REG (GC_FBR, 0x0); |
| 150 | DE_WR_REG (GC_XRES, dev->winSizeX); |
| 151 | DE_WR_REG (GC_FC, 0x0); |
| 152 | DE_WR_REG (GC_BC, 0x0); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 153 | /* Reset clipping */ |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 154 | DE_WR_REG (GC_CXMIN, 0x0); |
| 155 | DE_WR_REG (GC_CXMAX, dev->winSizeX); |
| 156 | DE_WR_REG (GC_CYMIN, 0x0); |
| 157 | DE_WR_REG (GC_CYMAX, dev->winSizeY); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 158 | |
| 159 | /* Clear framebuffer using drawing engine */ |
| 160 | de_wait_slots (3); |
| 161 | DE_WR_FIFO (0x09410000); |
| 162 | DE_WR_FIFO (0x00000000); |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 163 | DE_WR_FIFO (dev->winSizeY << 16 | dev->winSizeX); |
Anatolij Gustschin | 322716a | 2008-07-12 17:31:36 +0200 | [diff] [blame] | 164 | /* sync with SW access to framebuffer */ |
| 165 | de_wait (); |
Anatolij Gustschin | 5d16ca8 | 2009-10-23 12:03:14 +0200 | [diff] [blame] | 166 | #else |
| 167 | unsigned int i, *p; |
| 168 | |
| 169 | i = dev->winSizeX * dev->winSizeY; |
| 170 | p = (unsigned int *)dev->frameAdrs; |
| 171 | while (i--) |
| 172 | *p++ = 0; |
| 173 | #endif |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | #if defined(CONFIG_VIDEO_CORALP) |
Anatolij Gustschin | d7ffd27 | 2011-05-27 16:08:20 +0200 | [diff] [blame] | 177 | /* use CCF and MMR parameters for Coral-P Eval. Board as default */ |
| 178 | #ifndef CONFIG_SYS_MB862xx_CCF |
| 179 | #define CONFIG_SYS_MB862xx_CCF 0x00090000 |
| 180 | #endif |
| 181 | #ifndef CONFIG_SYS_MB862xx_MMR |
| 182 | #define CONFIG_SYS_MB862xx_MMR 0x11d7fa13 |
| 183 | #endif |
| 184 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 185 | unsigned int pci_video_init (void) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 186 | { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 187 | GraphicDevice *dev = &mb862xx; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 188 | pci_dev_t devbusfn; |
Anatolij Gustschin | d7ffd27 | 2011-05-27 16:08:20 +0200 | [diff] [blame] | 189 | u16 device; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 190 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 191 | if ((devbusfn = pci_find_devices (supported, 0)) < 0) { |
Anatolij Gustschin | 01b0f50 | 2011-07-16 22:28:23 +0200 | [diff] [blame] | 192 | puts("controller not present\n"); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | /* PCI setup */ |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 197 | pci_write_config_dword (devbusfn, PCI_COMMAND, |
| 198 | (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)); |
| 199 | pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_0, &dev->frameAdrs); |
| 200 | dev->frameAdrs = pci_mem_to_phys (devbusfn, dev->frameAdrs); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 201 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 202 | if (dev->frameAdrs == 0) { |
Anatolij Gustschin | 9d173e0 | 2009-07-07 13:11:36 +0200 | [diff] [blame] | 203 | puts ("PCI config: failed to get base address\n"); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 204 | return 0; |
| 205 | } |
| 206 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 207 | dev->pciBase = dev->frameAdrs; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 208 | |
Anatolij Gustschin | d7ffd27 | 2011-05-27 16:08:20 +0200 | [diff] [blame] | 209 | puts("Coral-"); |
| 210 | |
| 211 | pci_read_config_word(devbusfn, PCI_DEVICE_ID, &device); |
| 212 | switch (device) { |
| 213 | case PCI_DEVICE_ID_CORAL_P: |
| 214 | puts("P\n"); |
| 215 | break; |
| 216 | case PCI_DEVICE_ID_CORAL_PA: |
| 217 | puts("PA\n"); |
| 218 | break; |
| 219 | default: |
| 220 | puts("Unknown\n"); |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | /* Setup clocks and memory mode for Coral-P(A) */ |
| 225 | HOST_WR_REG(GC_CCF, CONFIG_SYS_MB862xx_CCF); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 226 | udelay(200); |
Anatolij Gustschin | d7ffd27 | 2011-05-27 16:08:20 +0200 | [diff] [blame] | 227 | HOST_WR_REG(GC_MMR, CONFIG_SYS_MB862xx_MMR); |
Simon Glass | 07e1114 | 2020-05-10 11:40:10 -0600 | [diff] [blame] | 228 | udelay(100); |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 229 | return dev->frameAdrs; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | unsigned int card_init (void) |
| 233 | { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 234 | GraphicDevice *dev = &mb862xx; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 235 | unsigned int cf, videomode, div = 0; |
| 236 | unsigned long t1, hsync, vsync; |
| 237 | char *penv; |
| 238 | int tmp, i, bpp; |
| 239 | struct ctfb_res_modes *res_mode; |
| 240 | struct ctfb_res_modes var_mode; |
| 241 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 242 | memset (dev, 0, sizeof (GraphicDevice)); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 243 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 244 | if (!pci_video_init ()) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 245 | return 0; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 246 | |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 247 | tmp = 0; |
| 248 | videomode = 0x310; |
| 249 | /* get video mode via environment */ |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 250 | penv = env_get("videomode"); |
| 251 | if (penv) { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 252 | /* decide if it is a string */ |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 253 | if (penv[0] <= '9') { |
| 254 | videomode = (int) simple_strtoul (penv, NULL, 16); |
| 255 | tmp = 1; |
| 256 | } |
| 257 | } else { |
| 258 | tmp = 1; |
| 259 | } |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 260 | |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 261 | if (tmp) { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 262 | /* parameter are vesa modes, search params */ |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 263 | for (i = 0; i < VESA_MODES_COUNT; i++) { |
| 264 | if (vesa_modes[i].vesanr == videomode) |
| 265 | break; |
| 266 | } |
| 267 | if (i == VESA_MODES_COUNT) { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 268 | printf ("\tno VESA Mode found, fallback to mode 0x%x\n", |
| 269 | videomode); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 270 | i = 0; |
| 271 | } |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 272 | res_mode = (struct ctfb_res_modes *) |
| 273 | &res_mode_init[vesa_modes[i].resindex]; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 274 | if (vesa_modes[i].resindex > 2) { |
Anatolij Gustschin | 9d173e0 | 2009-07-07 13:11:36 +0200 | [diff] [blame] | 275 | puts ("\tUnsupported resolution, using default\n"); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 276 | bpp = vesa_modes[1].bits_per_pixel; |
| 277 | div = fr_div[1]; |
| 278 | } |
| 279 | bpp = vesa_modes[i].bits_per_pixel; |
| 280 | div = fr_div[vesa_modes[i].resindex]; |
| 281 | } else { |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 282 | res_mode = (struct ctfb_res_modes *) &var_mode; |
| 283 | bpp = video_get_params (res_mode, penv); |
| 284 | } |
| 285 | |
| 286 | /* calculate hsync and vsync freq (info only) */ |
| 287 | t1 = (res_mode->left_margin + res_mode->xres + |
| 288 | res_mode->right_margin + res_mode->hsync_len) / 8; |
| 289 | t1 *= 8; |
| 290 | t1 *= res_mode->pixclock; |
| 291 | t1 /= 1000; |
| 292 | hsync = 1000000000L / t1; |
| 293 | t1 *= (res_mode->upper_margin + res_mode->yres + |
| 294 | res_mode->lower_margin + res_mode->vsync_len); |
| 295 | t1 /= 1000; |
| 296 | vsync = 1000000000L / t1; |
| 297 | |
| 298 | /* fill in Graphic device struct */ |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 299 | sprintf (dev->modeIdent, "%dx%dx%d %ldkHz %ldHz", res_mode->xres, |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 300 | res_mode->yres, bpp, (hsync / 1000), (vsync / 1000)); |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 301 | printf ("\t%s\n", dev->modeIdent); |
| 302 | dev->winSizeX = res_mode->xres; |
| 303 | dev->winSizeY = res_mode->yres; |
| 304 | dev->memSize = VIDEO_MEM_SIZE; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 305 | |
| 306 | switch (bpp) { |
| 307 | case 8: |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 308 | dev->gdfIndex = GDF__8BIT_INDEX; |
| 309 | dev->gdfBytesPP = 1; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 310 | break; |
| 311 | case 15: |
| 312 | case 16: |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 313 | dev->gdfIndex = GDF_15BIT_555RGB; |
| 314 | dev->gdfBytesPP = 2; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 315 | break; |
| 316 | default: |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 317 | printf ("\t%d bpp configured, but only 8,15 and 16 supported\n", |
| 318 | bpp); |
Anatolij Gustschin | 9d173e0 | 2009-07-07 13:11:36 +0200 | [diff] [blame] | 319 | puts ("\tfallback to 15bpp\n"); |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 320 | dev->gdfIndex = GDF_15BIT_555RGB; |
| 321 | dev->gdfBytesPP = 2; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /* Setup dot clock (internal pll, division rate) */ |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 325 | DISP_WR_REG (GC_DCM1, div); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 326 | /* L0 init */ |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 327 | cf = (dev->gdfBytesPP == 1) ? 0x00000000 : 0x80000000; |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 328 | DISP_WR_REG (GC_L0M, ((dev->winSizeX * dev->gdfBytesPP) / 64) << 16 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 329 | (dev->winSizeY - 1) | cf); |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 330 | DISP_WR_REG (GC_L0OA0, 0x0); |
| 331 | DISP_WR_REG (GC_L0DA0, 0x0); |
| 332 | DISP_WR_REG (GC_L0DY_L0DX, 0x0); |
| 333 | DISP_WR_REG (GC_L0EM, 0x0); |
| 334 | DISP_WR_REG (GC_L0WY_L0WX, 0x0); |
| 335 | DISP_WR_REG (GC_L0WH_L0WW, (dev->winSizeY - 1) << 16 | dev->winSizeX); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 336 | |
| 337 | /* Display timing init */ |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 338 | DISP_WR_REG (GC_HTP_A, (dev->winSizeX + |
| 339 | res_mode->left_margin + |
| 340 | res_mode->right_margin + |
| 341 | res_mode->hsync_len - 1) << 16); |
| 342 | DISP_WR_REG (GC_HDB_HDP_A, (dev->winSizeX - 1) << 16 | |
| 343 | (dev->winSizeX - 1)); |
| 344 | DISP_WR_REG (GC_VSW_HSW_HSP_A, (res_mode->vsync_len - 1) << 24 | |
| 345 | (res_mode->hsync_len - 1) << 16 | |
| 346 | (dev->winSizeX + |
| 347 | res_mode->right_margin - 1)); |
| 348 | DISP_WR_REG (GC_VTR_A, (dev->winSizeY + res_mode->lower_margin + |
| 349 | res_mode->upper_margin + |
| 350 | res_mode->vsync_len - 1) << 16); |
| 351 | DISP_WR_REG (GC_VDP_VSP_A, (dev->winSizeY-1) << 16 | |
| 352 | (dev->winSizeY + |
| 353 | res_mode->lower_margin - 1)); |
| 354 | DISP_WR_REG (GC_WY_WX, 0x0); |
| 355 | DISP_WR_REG (GC_WH_WW, dev->winSizeY << 16 | dev->winSizeX); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 356 | /* Display enable, L0 layer */ |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 357 | DISP_WR_REG (GC_DCM1, 0x80010000 | div); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 358 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 359 | return dev->frameAdrs; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 360 | } |
| 361 | #endif |
| 362 | |
Wolfgang Grandegger | c28d3bb | 2009-10-23 12:03:13 +0200 | [diff] [blame] | 363 | |
| 364 | #if !defined(CONFIG_VIDEO_CORALP) |
| 365 | int mb862xx_probe(unsigned int addr) |
| 366 | { |
| 367 | GraphicDevice *dev = &mb862xx; |
| 368 | unsigned int reg; |
| 369 | |
| 370 | dev->frameAdrs = addr; |
| 371 | dev->dprBase = dev->frameAdrs + GC_DRAW_BASE; |
| 372 | |
| 373 | /* Try to access GDC ID/Revision registers */ |
| 374 | reg = HOST_RD_REG (GC_CID); |
| 375 | reg = HOST_RD_REG (GC_CID); |
| 376 | if (reg == 0x303) { |
| 377 | reg = DE_RD_REG(GC_REV); |
| 378 | reg = DE_RD_REG(GC_REV); |
| 379 | if ((reg & ~0xff) == 0x20050100) |
| 380 | return MB862XX_TYPE_LIME; |
| 381 | } |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | #endif |
| 386 | |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 387 | void *video_hw_init (void) |
| 388 | { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 389 | GraphicDevice *dev = &mb862xx; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 390 | |
Anatolij Gustschin | 9d173e0 | 2009-07-07 13:11:36 +0200 | [diff] [blame] | 391 | puts ("Video: Fujitsu "); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 392 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 393 | memset (dev, 0, sizeof (GraphicDevice)); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 394 | |
| 395 | #if defined(CONFIG_VIDEO_CORALP) |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 396 | if (card_init () == 0) |
| 397 | return NULL; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 398 | #else |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 399 | /* |
| 400 | * Preliminary init of the onboard graphic controller, |
| 401 | * retrieve base address |
| 402 | */ |
| 403 | if ((dev->frameAdrs = board_video_init ()) == 0) { |
Anatolij Gustschin | 9d173e0 | 2009-07-07 13:11:36 +0200 | [diff] [blame] | 404 | puts ("Controller not found!\n"); |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 405 | return NULL; |
Wolfgang Grandegger | c28d3bb | 2009-10-23 12:03:13 +0200 | [diff] [blame] | 406 | } else { |
Anatolij Gustschin | 9d173e0 | 2009-07-07 13:11:36 +0200 | [diff] [blame] | 407 | puts ("Lime\n"); |
Wolfgang Grandegger | c28d3bb | 2009-10-23 12:03:13 +0200 | [diff] [blame] | 408 | |
| 409 | /* Set Change of Clock Frequency Register */ |
| 410 | HOST_WR_REG (GC_CCF, CONFIG_SYS_MB862xx_CCF); |
| 411 | /* Delay required */ |
| 412 | udelay(300); |
| 413 | /* Set Memory I/F Mode Register) */ |
| 414 | HOST_WR_REG (GC_MMR, CONFIG_SYS_MB862xx_MMR); |
| 415 | } |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 416 | #endif |
| 417 | |
| 418 | de_init (); |
| 419 | |
| 420 | #if !defined(CONFIG_VIDEO_CORALP) |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 421 | board_disp_init (); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 422 | #endif |
| 423 | |
Stefan Roese | 04386f6 | 2015-10-02 08:20:35 +0200 | [diff] [blame] | 424 | #if (defined(CONFIG_LWMON5) || \ |
| 425 | defined(CONFIG_SOCRATES)) && !(CONFIG_POST & CONFIG_SYS_POST_SYSMON) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 426 | /* Lamp on */ |
| 427 | board_backlight_switch (1); |
| 428 | #endif |
| 429 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 430 | return dev; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* |
| 434 | * Set a RGB color in the LUT |
| 435 | */ |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 436 | void video_set_lut (unsigned int index, unsigned char r, |
| 437 | unsigned char g, unsigned char b) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 438 | { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 439 | GraphicDevice *dev = &mb862xx; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 440 | |
| 441 | L0PAL_WR_REG (index, (r << 16) | (g << 8) | (b)); |
| 442 | } |
| 443 | |
Anatolij Gustschin | 5d16ca8 | 2009-10-23 12:03:14 +0200 | [diff] [blame] | 444 | #if defined(CONFIG_VIDEO_MB862xx_ACCEL) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 445 | /* |
| 446 | * Drawing engine Fill and BitBlt screen region |
| 447 | */ |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 448 | void video_hw_rectfill (unsigned int bpp, unsigned int dst_x, |
| 449 | unsigned int dst_y, unsigned int dim_x, |
| 450 | unsigned int dim_y, unsigned int color) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 451 | { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 452 | GraphicDevice *dev = &mb862xx; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 453 | |
| 454 | de_wait_slots (3); |
Anatolij Gustschin | cce99b2 | 2009-07-07 13:27:07 +0200 | [diff] [blame] | 455 | DE_WR_REG (GC_FC, color); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 456 | DE_WR_FIFO (0x09410000); |
| 457 | DE_WR_FIFO ((dst_y << 16) | dst_x); |
| 458 | DE_WR_FIFO ((dim_y << 16) | dim_x); |
| 459 | de_wait (); |
| 460 | } |
| 461 | |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 462 | void video_hw_bitblt (unsigned int bpp, unsigned int src_x, |
| 463 | unsigned int src_y, unsigned int dst_x, |
| 464 | unsigned int dst_y, unsigned int width, |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 465 | unsigned int height) |
| 466 | { |
Anatolij Gustschin | e865286 | 2009-07-07 13:24:08 +0200 | [diff] [blame] | 467 | GraphicDevice *dev = &mb862xx; |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 468 | unsigned int ctrl = 0x0d000000L; |
| 469 | |
| 470 | if (src_x >= dst_x && src_y >= dst_y) |
| 471 | ctrl |= 0x00440000L; |
| 472 | else if (src_x >= dst_x && src_y <= dst_y) |
| 473 | ctrl |= 0x00460000L; |
| 474 | else if (src_x <= dst_x && src_y >= dst_y) |
| 475 | ctrl |= 0x00450000L; |
| 476 | else |
| 477 | ctrl |= 0x00470000L; |
| 478 | |
| 479 | de_wait_slots (4); |
| 480 | DE_WR_FIFO (ctrl); |
| 481 | DE_WR_FIFO ((src_y << 16) | src_x); |
| 482 | DE_WR_FIFO ((dst_y << 16) | dst_x); |
| 483 | DE_WR_FIFO ((height << 16) | width); |
| 484 | de_wait (); /* sync */ |
| 485 | } |
Anatolij Gustschin | 5d16ca8 | 2009-10-23 12:03:14 +0200 | [diff] [blame] | 486 | #endif |