2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 static int hw_bitblt_1(void __iomem *engine, u8 op, u32 width, u32 height,
24 u8 dst_bpp, u32 dst_addr, u32 dst_pitch, u32 dst_x, u32 dst_y,
25 u32 *src_mem, u32 src_addr, u32 src_pitch, u32 src_x, u32 src_y,
26 u32 fg_color, u32 bg_color, u8 fill_rop)
28 u32 ge_cmd = 0, tmp, i;
31 printk(KERN_WARNING "hw_bitblt_1: Invalid operation: %d\n", op);
35 if (op != VIA_BITBLT_FILL && !src_mem && src_addr == dst_addr) {
48 if (op == VIA_BITBLT_FILL) {
50 case 0x00: /* blackness */
51 case 0x5A: /* pattern inversion */
52 case 0xF0: /* pattern copy */
53 case 0xFF: /* whiteness */
56 printk(KERN_WARNING "hw_bitblt_1: Invalid fill rop: "
73 printk(KERN_WARNING "hw_bitblt_1: Unsupported bpp %d\n",
77 writel(tmp, engine + 0x04);
79 if (op != VIA_BITBLT_FILL) {
80 if (src_x & (op == VIA_BITBLT_MONO ? 0xFFFF8000 : 0xFFFFF000)
81 || src_y & 0xFFFFF000) {
82 printk(KERN_WARNING "hw_bitblt_1: Unsupported source "
83 "x/y %d %d\n", src_x, src_y);
86 tmp = src_x | (src_y << 16);
87 writel(tmp, engine + 0x08);
90 if (dst_x & 0xFFFFF000 || dst_y & 0xFFFFF000) {
91 printk(KERN_WARNING "hw_bitblt_1: Unsupported destination x/y "
92 "%d %d\n", dst_x, dst_y);
95 tmp = dst_x | (dst_y << 16);
96 writel(tmp, engine + 0x0C);
98 if ((width - 1) & 0xFFFFF000 || (height - 1) & 0xFFFFF000) {
99 printk(KERN_WARNING "hw_bitblt_1: Unsupported width/height "
100 "%d %d\n", width, height);
103 tmp = (width - 1) | ((height - 1) << 16);
104 writel(tmp, engine + 0x10);
106 if (op != VIA_BITBLT_COLOR)
107 writel(fg_color, engine + 0x18);
109 if (op == VIA_BITBLT_MONO)
110 writel(bg_color, engine + 0x1C);
112 if (op != VIA_BITBLT_FILL) {
113 tmp = src_mem ? 0 : src_addr;
114 if (dst_addr & 0xE0000007) {
115 printk(KERN_WARNING "hw_bitblt_1: Unsupported source "
116 "address %X\n", tmp);
120 writel(tmp, engine + 0x30);
123 if (dst_addr & 0xE0000007) {
124 printk(KERN_WARNING "hw_bitblt_1: Unsupported destination "
125 "address %X\n", dst_addr);
129 writel(tmp, engine + 0x34);
131 if (op == VIA_BITBLT_FILL)
135 if (tmp & 0xFFFFC007 || dst_pitch & 0xFFFFC007) {
136 printk(KERN_WARNING "hw_bitblt_1: Unsupported pitch %X %X\n",
140 tmp = VIA_PITCH_ENABLE | (tmp >> 3) | (dst_pitch << (16 - 3));
141 writel(tmp, engine + 0x38);
143 if (op == VIA_BITBLT_FILL)
144 ge_cmd |= fill_rop << 24 | 0x00002000 | 0x00000001;
146 ge_cmd |= 0xCC000000; /* ROP=SRCCOPY */
148 ge_cmd |= 0x00000040;
149 if (op == VIA_BITBLT_MONO)
150 ge_cmd |= 0x00000002 | 0x00000100 | 0x00020000;
152 ge_cmd |= 0x00000001;
154 writel(ge_cmd, engine);
156 if (op == VIA_BITBLT_FILL || !src_mem)
159 tmp = (width * height * (op == VIA_BITBLT_MONO ? 1 : (dst_bpp >> 3)) +
162 for (i = 0; i < tmp; i++)
163 writel(src_mem[i], engine + VIA_MMIO_BLTBASE);
169 * Figure out an appropriate bytes-per-pixel setting.
171 static int viafb_set_bpp(void __iomem *engine, u8 bpp)
175 /* Preserve the reserved bits */
176 /* Lowest 2 bits to zero gives us no rotation */
177 gemode = readl(engine + VIA_REG_GEMODE) & 0xfffffcfc;
180 gemode |= VIA_GEM_8bpp;
183 gemode |= VIA_GEM_16bpp;
186 gemode |= VIA_GEM_32bpp;
189 printk(KERN_WARNING "hw_bitblt_2: Unsupported bpp %d\n", bpp);
192 writel(gemode, engine + VIA_REG_GEMODE);
197 static int hw_bitblt_2(void __iomem *engine, u8 op, u32 width, u32 height,
198 u8 dst_bpp, u32 dst_addr, u32 dst_pitch, u32 dst_x, u32 dst_y,
199 u32 *src_mem, u32 src_addr, u32 src_pitch, u32 src_x, u32 src_y,
200 u32 fg_color, u32 bg_color, u8 fill_rop)
202 u32 ge_cmd = 0, tmp, i;
206 printk(KERN_WARNING "hw_bitblt_2: Invalid operation: %d\n", op);
210 if (op != VIA_BITBLT_FILL && !src_mem && src_addr == dst_addr) {
212 ge_cmd |= 0x00008000;
217 ge_cmd |= 0x00004000;
223 if (op == VIA_BITBLT_FILL) {
225 case 0x00: /* blackness */
226 case 0x5A: /* pattern inversion */
227 case 0xF0: /* pattern copy */
228 case 0xFF: /* whiteness */
231 printk(KERN_WARNING "hw_bitblt_2: Invalid fill rop: "
237 ret = viafb_set_bpp(engine, dst_bpp);
241 if (op == VIA_BITBLT_FILL)
245 if (tmp & 0xFFFFC007 || dst_pitch & 0xFFFFC007) {
246 printk(KERN_WARNING "hw_bitblt_2: Unsupported pitch %X %X\n",
250 tmp = (tmp >> 3) | (dst_pitch << (16 - 3));
251 writel(tmp, engine + 0x08);
253 if ((width - 1) & 0xFFFFF000 || (height - 1) & 0xFFFFF000) {
254 printk(KERN_WARNING "hw_bitblt_2: Unsupported width/height "
255 "%d %d\n", width, height);
258 tmp = (width - 1) | ((height - 1) << 16);
259 writel(tmp, engine + 0x0C);
261 if (dst_x & 0xFFFFF000 || dst_y & 0xFFFFF000) {
262 printk(KERN_WARNING "hw_bitblt_2: Unsupported destination x/y "
263 "%d %d\n", dst_x, dst_y);
266 tmp = dst_x | (dst_y << 16);
267 writel(tmp, engine + 0x10);
269 if (dst_addr & 0xE0000007) {
270 printk(KERN_WARNING "hw_bitblt_2: Unsupported destination "
271 "address %X\n", dst_addr);
275 writel(tmp, engine + 0x14);
277 if (op != VIA_BITBLT_FILL) {
278 if (src_x & (op == VIA_BITBLT_MONO ? 0xFFFF8000 : 0xFFFFF000)
279 || src_y & 0xFFFFF000) {
280 printk(KERN_WARNING "hw_bitblt_2: Unsupported source "
281 "x/y %d %d\n", src_x, src_y);
284 tmp = src_x | (src_y << 16);
285 writel(tmp, engine + 0x18);
287 tmp = src_mem ? 0 : src_addr;
288 if (dst_addr & 0xE0000007) {
289 printk(KERN_WARNING "hw_bitblt_2: Unsupported source "
290 "address %X\n", tmp);
294 writel(tmp, engine + 0x1C);
297 if (op != VIA_BITBLT_COLOR)
298 writel(fg_color, engine + 0x4C);
300 if (op == VIA_BITBLT_MONO)
301 writel(bg_color, engine + 0x50);
303 if (op == VIA_BITBLT_FILL)
304 ge_cmd |= fill_rop << 24 | 0x00002000 | 0x00000001;
306 ge_cmd |= 0xCC000000; /* ROP=SRCCOPY */
308 ge_cmd |= 0x00000040;
309 if (op == VIA_BITBLT_MONO)
310 ge_cmd |= 0x00000002 | 0x00000100 | 0x00020000;
312 ge_cmd |= 0x00000001;
314 writel(ge_cmd, engine);
316 if (op == VIA_BITBLT_FILL || !src_mem)
319 tmp = (width * height * (op == VIA_BITBLT_MONO ? 1 : (dst_bpp >> 3)) +
322 for (i = 0; i < tmp; i++)
323 writel(src_mem[i], engine + VIA_MMIO_BLTBASE);
328 int viafb_init_engine(struct fb_info *info)
330 struct viafb_par *viapar = info->par;
331 void __iomem *engine;
332 u32 vq_start_addr, vq_end_addr, vq_start_low, vq_end_low, vq_high,
333 vq_len, chip_name = viapar->shared->chip_info.gfx_chip_name;
335 engine = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
336 viapar->shared->engine_mmio = engine;
338 printk(KERN_WARNING "viafb_init_accel: ioremap failed, "
339 "hardware acceleration disabled\n");
344 case UNICHROME_CLE266:
347 case UNICHROME_PM800:
348 case UNICHROME_CN700:
349 case UNICHROME_CX700:
350 case UNICHROME_CN750:
351 case UNICHROME_K8M890:
352 case UNICHROME_P4M890:
353 case UNICHROME_P4M900:
354 viapar->shared->hw_bitblt = hw_bitblt_1;
356 case UNICHROME_VX800:
357 case UNICHROME_VX855:
358 viapar->shared->hw_bitblt = hw_bitblt_2;
361 viapar->shared->hw_bitblt = NULL;
364 viapar->fbmem_free -= CURSOR_SIZE;
365 viapar->shared->cursor_vram_addr = viapar->fbmem_free;
366 viapar->fbmem_used += CURSOR_SIZE;
368 viapar->fbmem_free -= VQ_SIZE;
369 viapar->shared->vq_vram_addr = viapar->fbmem_free;
370 viapar->fbmem_used += VQ_SIZE;
372 /* Init 2D engine reg to reset 2D engine */
373 writel(0x0, engine + VIA_REG_KEYCONTROL);
375 /* Init AGP and VQ regs */
377 case UNICHROME_K8M890:
378 case UNICHROME_P4M900:
379 writel(0x00100000, engine + VIA_REG_CR_TRANSET);
380 writel(0x680A0000, engine + VIA_REG_CR_TRANSPACE);
381 writel(0x02000000, engine + VIA_REG_CR_TRANSPACE);
385 writel(0x00100000, engine + VIA_REG_TRANSET);
386 writel(0x00000000, engine + VIA_REG_TRANSPACE);
387 writel(0x00333004, engine + VIA_REG_TRANSPACE);
388 writel(0x60000000, engine + VIA_REG_TRANSPACE);
389 writel(0x61000000, engine + VIA_REG_TRANSPACE);
390 writel(0x62000000, engine + VIA_REG_TRANSPACE);
391 writel(0x63000000, engine + VIA_REG_TRANSPACE);
392 writel(0x64000000, engine + VIA_REG_TRANSPACE);
393 writel(0x7D000000, engine + VIA_REG_TRANSPACE);
395 writel(0xFE020000, engine + VIA_REG_TRANSET);
396 writel(0x00000000, engine + VIA_REG_TRANSPACE);
401 vq_start_addr = viapar->shared->vq_vram_addr;
402 vq_end_addr = viapar->shared->vq_vram_addr + VQ_SIZE - 1;
404 vq_start_low = 0x50000000 | (vq_start_addr & 0xFFFFFF);
405 vq_end_low = 0x51000000 | (vq_end_addr & 0xFFFFFF);
406 vq_high = 0x52000000 | ((vq_start_addr & 0xFF000000) >> 24) |
407 ((vq_end_addr & 0xFF000000) >> 16);
408 vq_len = 0x53000000 | (VQ_SIZE >> 3);
411 case UNICHROME_K8M890:
412 case UNICHROME_P4M900:
413 vq_start_low |= 0x20000000;
414 vq_end_low |= 0x20000000;
415 vq_high |= 0x20000000;
416 vq_len |= 0x20000000;
418 writel(0x00100000, engine + VIA_REG_CR_TRANSET);
419 writel(vq_high, engine + VIA_REG_CR_TRANSPACE);
420 writel(vq_start_low, engine + VIA_REG_CR_TRANSPACE);
421 writel(vq_end_low, engine + VIA_REG_CR_TRANSPACE);
422 writel(vq_len, engine + VIA_REG_CR_TRANSPACE);
423 writel(0x74301001, engine + VIA_REG_CR_TRANSPACE);
424 writel(0x00000000, engine + VIA_REG_CR_TRANSPACE);
427 writel(0x00FE0000, engine + VIA_REG_TRANSET);
428 writel(0x080003FE, engine + VIA_REG_TRANSPACE);
429 writel(0x0A00027C, engine + VIA_REG_TRANSPACE);
430 writel(0x0B000260, engine + VIA_REG_TRANSPACE);
431 writel(0x0C000274, engine + VIA_REG_TRANSPACE);
432 writel(0x0D000264, engine + VIA_REG_TRANSPACE);
433 writel(0x0E000000, engine + VIA_REG_TRANSPACE);
434 writel(0x0F000020, engine + VIA_REG_TRANSPACE);
435 writel(0x1000027E, engine + VIA_REG_TRANSPACE);
436 writel(0x110002FE, engine + VIA_REG_TRANSPACE);
437 writel(0x200F0060, engine + VIA_REG_TRANSPACE);
439 writel(0x00000006, engine + VIA_REG_TRANSPACE);
440 writel(0x40008C0F, engine + VIA_REG_TRANSPACE);
441 writel(0x44000000, engine + VIA_REG_TRANSPACE);
442 writel(0x45080C04, engine + VIA_REG_TRANSPACE);
443 writel(0x46800408, engine + VIA_REG_TRANSPACE);
445 writel(vq_high, engine + VIA_REG_TRANSPACE);
446 writel(vq_start_low, engine + VIA_REG_TRANSPACE);
447 writel(vq_end_low, engine + VIA_REG_TRANSPACE);
448 writel(vq_len, engine + VIA_REG_TRANSPACE);
452 /* Set Cursor Image Base Address */
453 writel(viapar->shared->cursor_vram_addr, engine + VIA_REG_CURSOR_MODE);
454 writel(0x0, engine + VIA_REG_CURSOR_POS);
455 writel(0x0, engine + VIA_REG_CURSOR_ORG);
456 writel(0x0, engine + VIA_REG_CURSOR_BG);
457 writel(0x0, engine + VIA_REG_CURSOR_FG);
461 void viafb_show_hw_cursor(struct fb_info *info, int Status)
463 struct viafb_par *viapar = info->par;
464 u32 temp, iga_path = viapar->iga_path;
466 temp = readl(viapar->shared->engine_mmio + VIA_REG_CURSOR_MODE);
483 writel(temp, viapar->shared->engine_mmio + VIA_REG_CURSOR_MODE);
486 void viafb_wait_engine_idle(struct fb_info *info)
488 struct viafb_par *viapar = info->par;
491 while (!(readl(viapar->shared->engine_mmio + VIA_REG_STATUS) &
492 VIA_VR_QUEUE_BUSY) && (loop < MAXLOOP)) {
497 while ((readl(viapar->shared->engine_mmio + VIA_REG_STATUS) &
498 (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY | VIA_3D_ENG_BUSY)) &&
505 printk(KERN_ERR "viafb_wait_engine_idle: not syncing\n");