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 void viafb_init_accel(void)
25 viaparinfo->fbmem_free -= CURSOR_SIZE;
26 viaparinfo->cursor_start = viaparinfo->fbmem_free;
27 viaparinfo->fbmem_used += CURSOR_SIZE;
29 /* Reverse 8*1024 memory space for cursor image */
30 viaparinfo->fbmem_free -= (CURSOR_SIZE + VQ_SIZE);
31 viaparinfo->VQ_start = viaparinfo->fbmem_free;
32 viaparinfo->VQ_end = viaparinfo->VQ_start + VQ_SIZE - 1;
33 viaparinfo->fbmem_used += (CURSOR_SIZE + VQ_SIZE); }
35 void viafb_init_2d_engine(void)
37 u32 dwVQStartAddr, dwVQEndAddr;
38 u32 dwVQLen, dwVQStartL, dwVQEndL, dwVQStartEndH;
40 /* init 2D engine regs to reset 2D engine */
41 writel(0x0, viaparinfo->io_virt + VIA_REG_GEMODE);
42 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCPOS);
43 writel(0x0, viaparinfo->io_virt + VIA_REG_DSTPOS);
44 writel(0x0, viaparinfo->io_virt + VIA_REG_DIMENSION);
45 writel(0x0, viaparinfo->io_virt + VIA_REG_PATADDR);
46 writel(0x0, viaparinfo->io_virt + VIA_REG_FGCOLOR);
47 writel(0x0, viaparinfo->io_virt + VIA_REG_BGCOLOR);
48 writel(0x0, viaparinfo->io_virt + VIA_REG_CLIPTL);
49 writel(0x0, viaparinfo->io_virt + VIA_REG_CLIPBR);
50 writel(0x0, viaparinfo->io_virt + VIA_REG_OFFSET);
51 writel(0x0, viaparinfo->io_virt + VIA_REG_KEYCONTROL);
52 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE);
53 writel(0x0, viaparinfo->io_virt + VIA_REG_DSTBASE);
54 writel(0x0, viaparinfo->io_virt + VIA_REG_PITCH);
55 writel(0x0, viaparinfo->io_virt + VIA_REG_MONOPAT1);
57 /* Init AGP and VQ regs */
58 switch (viaparinfo->chip_info->gfx_chip_name) {
59 case UNICHROME_K8M890:
60 case UNICHROME_P4M900:
61 writel(0x00100000, viaparinfo->io_virt + VIA_REG_CR_TRANSET);
62 writel(0x680A0000, viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
63 writel(0x02000000, viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
67 writel(0x00100000, viaparinfo->io_virt + VIA_REG_TRANSET);
68 writel(0x00000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
69 writel(0x00333004, viaparinfo->io_virt + VIA_REG_TRANSPACE);
70 writel(0x60000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
71 writel(0x61000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
72 writel(0x62000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
73 writel(0x63000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
74 writel(0x64000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
75 writel(0x7D000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
77 writel(0xFE020000, viaparinfo->io_virt + VIA_REG_TRANSET);
78 writel(0x00000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
81 if (viaparinfo->VQ_start != 0) {
83 dwVQStartAddr = viaparinfo->VQ_start;
84 dwVQEndAddr = viaparinfo->VQ_end;
86 dwVQStartL = 0x50000000 | (dwVQStartAddr & 0xFFFFFF);
87 dwVQEndL = 0x51000000 | (dwVQEndAddr & 0xFFFFFF);
88 dwVQStartEndH = 0x52000000 |
89 ((dwVQStartAddr & 0xFF000000) >> 24) |
90 ((dwVQEndAddr & 0xFF000000) >> 16);
91 dwVQLen = 0x53000000 | (VQ_SIZE >> 3);
92 switch (viaparinfo->chip_info->gfx_chip_name) {
93 case UNICHROME_K8M890:
94 case UNICHROME_P4M900:
95 dwVQStartL |= 0x20000000;
96 dwVQEndL |= 0x20000000;
97 dwVQStartEndH |= 0x20000000;
98 dwVQLen |= 0x20000000;
104 switch (viaparinfo->chip_info->gfx_chip_name) {
105 case UNICHROME_K8M890:
106 case UNICHROME_P4M900:
108 viaparinfo->io_virt + VIA_REG_CR_TRANSET);
109 writel(dwVQStartEndH,
110 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
112 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
114 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
116 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
118 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
120 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
124 viaparinfo->io_virt + VIA_REG_TRANSET);
126 viaparinfo->io_virt + VIA_REG_TRANSPACE);
128 viaparinfo->io_virt + VIA_REG_TRANSPACE);
130 viaparinfo->io_virt + VIA_REG_TRANSPACE);
132 viaparinfo->io_virt + VIA_REG_TRANSPACE);
134 viaparinfo->io_virt + VIA_REG_TRANSPACE);
136 viaparinfo->io_virt + VIA_REG_TRANSPACE);
138 viaparinfo->io_virt + VIA_REG_TRANSPACE);
140 viaparinfo->io_virt + VIA_REG_TRANSPACE);
142 viaparinfo->io_virt + VIA_REG_TRANSPACE);
144 viaparinfo->io_virt + VIA_REG_TRANSPACE);
147 viaparinfo->io_virt + VIA_REG_TRANSPACE);
149 viaparinfo->io_virt + VIA_REG_TRANSPACE);
151 viaparinfo->io_virt + VIA_REG_TRANSPACE);
153 viaparinfo->io_virt + VIA_REG_TRANSPACE);
155 viaparinfo->io_virt + VIA_REG_TRANSPACE);
157 writel(dwVQStartEndH,
158 viaparinfo->io_virt + VIA_REG_TRANSPACE);
160 viaparinfo->io_virt + VIA_REG_TRANSPACE);
162 viaparinfo->io_virt + VIA_REG_TRANSPACE);
164 viaparinfo->io_virt + VIA_REG_TRANSPACE);
169 switch (viaparinfo->chip_info->gfx_chip_name) {
170 case UNICHROME_K8M890:
171 case UNICHROME_P4M900:
173 viaparinfo->io_virt + VIA_REG_CR_TRANSET);
175 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
179 viaparinfo->io_virt + VIA_REG_TRANSET);
181 viaparinfo->io_virt + VIA_REG_TRANSPACE);
183 viaparinfo->io_virt + VIA_REG_TRANSPACE);
185 viaparinfo->io_virt + VIA_REG_TRANSPACE);
187 viaparinfo->io_virt + VIA_REG_TRANSPACE);
189 viaparinfo->io_virt + VIA_REG_TRANSPACE);
194 viafb_set_2d_color_depth(viaparinfo->bpp);
196 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE);
197 writel(0x0, viaparinfo->io_virt + VIA_REG_DSTBASE);
199 writel(VIA_PITCH_ENABLE |
200 (((viaparinfo->hres *
201 viaparinfo->bpp >> 3) >> 3) | (((viaparinfo->hres *
203 bpp >> 3) >> 3) << 16)),
204 viaparinfo->io_virt + VIA_REG_PITCH);
207 void viafb_set_2d_color_depth(int bpp)
211 dwGEMode = readl(viaparinfo->io_virt + 0x04) & 0xFFFFFCFF;
215 dwGEMode |= VIA_GEM_16bpp;
218 dwGEMode |= VIA_GEM_32bpp;
221 dwGEMode |= VIA_GEM_8bpp;
225 /* Set BPP and Pitch */
226 writel(dwGEMode, viaparinfo->io_virt + VIA_REG_GEMODE);
229 void viafb_hw_cursor_init(void)
231 /* Set Cursor Image Base Address */
232 writel(viaparinfo->cursor_start,
233 viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
234 writel(0x0, viaparinfo->io_virt + VIA_REG_CURSOR_POS);
235 writel(0x0, viaparinfo->io_virt + VIA_REG_CURSOR_ORG);
236 writel(0x0, viaparinfo->io_virt + VIA_REG_CURSOR_BG);
237 writel(0x0, viaparinfo->io_virt + VIA_REG_CURSOR_FG);
240 void viafb_show_hw_cursor(struct fb_info *info, int Status)
243 u32 iga_path = ((struct viafb_par *)(info->par))->iga_path;
245 temp = readl(viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
262 writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
265 int viafb_wait_engine_idle(void)
269 while (!(readl(viaparinfo->io_virt + VIA_REG_STATUS) &
270 VIA_VR_QUEUE_BUSY) && (loop < MAXLOOP)) {
275 while ((readl(viaparinfo->io_virt + VIA_REG_STATUS) &
276 (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY | VIA_3D_ENG_BUSY)) &&
282 return loop >= MAXLOOP;