machfb.c revision 1.8.2.2 1 1.8.2.2 nathanw /* $NetBSD: machfb.c,v 1.8.2.2 2002/11/11 22:11:19 nathanw Exp $ */
2 1.8.2.2 nathanw
3 1.8.2.2 nathanw /*
4 1.8.2.2 nathanw * Copyright (c) 2002 Bang Jun-Young
5 1.8.2.2 nathanw * All rights reserved.
6 1.8.2.2 nathanw *
7 1.8.2.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.8.2.2 nathanw * modification, are permitted provided that the following conditions
9 1.8.2.2 nathanw * are met:
10 1.8.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.8.2.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.8.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.8.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.8.2.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.8.2.2 nathanw * 3. The name of the author may not be used to endorse or promote products
16 1.8.2.2 nathanw * derived from this software without specific prior written permission
17 1.8.2.2 nathanw *
18 1.8.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.8.2.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.8.2.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.8.2.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.8.2.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.8.2.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.8.2.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.8.2.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.8.2.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.8.2.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.8.2.2 nathanw */
29 1.8.2.2 nathanw
30 1.8.2.2 nathanw /*
31 1.8.2.2 nathanw * Some code is derived from ATI Rage Pro and Derivatives Programmer's Guide.
32 1.8.2.2 nathanw */
33 1.8.2.2 nathanw
34 1.8.2.2 nathanw #include <sys/cdefs.h>
35 1.8.2.2 nathanw
36 1.8.2.2 nathanw #include <sys/param.h>
37 1.8.2.2 nathanw #include <sys/systm.h>
38 1.8.2.2 nathanw #include <sys/kernel.h>
39 1.8.2.2 nathanw #include <sys/device.h>
40 1.8.2.2 nathanw #include <sys/malloc.h>
41 1.8.2.2 nathanw #include <sys/callout.h>
42 1.8.2.2 nathanw
43 1.8.2.2 nathanw #ifdef __sparc__
44 1.8.2.2 nathanw #include <machine/openfirm.h>
45 1.8.2.2 nathanw #endif
46 1.8.2.2 nathanw
47 1.8.2.2 nathanw #include <dev/ic/videomode.h>
48 1.8.2.2 nathanw
49 1.8.2.2 nathanw #include <dev/pci/pcivar.h>
50 1.8.2.2 nathanw #include <dev/pci/pcireg.h>
51 1.8.2.2 nathanw #include <dev/pci/pcidevs.h>
52 1.8.2.2 nathanw #include <dev/pci/pciio.h>
53 1.8.2.2 nathanw #include <dev/pci/machfbreg.h>
54 1.8.2.2 nathanw
55 1.8.2.2 nathanw #include <dev/wscons/wsdisplayvar.h>
56 1.8.2.2 nathanw #include <dev/wscons/wsconsio.h>
57 1.8.2.2 nathanw #include <dev/wsfont/wsfont.h>
58 1.8.2.2 nathanw #include <dev/rasops/rasops.h>
59 1.8.2.2 nathanw
60 1.8.2.2 nathanw #define MACH64_REG_SIZE 1024
61 1.8.2.2 nathanw #define MACH64_REG_OFF 0x7ffc00
62 1.8.2.2 nathanw
63 1.8.2.2 nathanw #define NBARS 3 /* number of Mach64 PCI BARs */
64 1.8.2.2 nathanw
65 1.8.2.2 nathanw struct vga_bar {
66 1.8.2.2 nathanw bus_addr_t vb_base;
67 1.8.2.2 nathanw bus_size_t vb_size;
68 1.8.2.2 nathanw pcireg_t vb_type;
69 1.8.2.2 nathanw int vb_flags;
70 1.8.2.2 nathanw };
71 1.8.2.2 nathanw
72 1.8.2.2 nathanw struct mach64_softc {
73 1.8.2.2 nathanw struct device sc_dev;
74 1.8.2.2 nathanw pci_chipset_tag_t sc_pc;
75 1.8.2.2 nathanw pcitag_t sc_pcitag;
76 1.8.2.2 nathanw
77 1.8.2.2 nathanw struct vga_bar sc_bars[NBARS];
78 1.8.2.2 nathanw struct vga_bar sc_rom;
79 1.8.2.2 nathanw
80 1.8.2.2 nathanw #define sc_aperbase sc_bars[0].vb_base
81 1.8.2.2 nathanw #define sc_apersize sc_bars[0].vb_size
82 1.8.2.2 nathanw
83 1.8.2.2 nathanw #define sc_iobase sc_bars[1].vb_base
84 1.8.2.2 nathanw #define sc_iosize sc_bars[1].vb_size
85 1.8.2.2 nathanw
86 1.8.2.2 nathanw #define sc_regbase sc_bars[2].vb_base
87 1.8.2.2 nathanw #define sc_regsize sc_bars[2].vb_size
88 1.8.2.2 nathanw
89 1.8.2.2 nathanw bus_space_tag_t sc_regt;
90 1.8.2.2 nathanw bus_space_tag_t sc_memt;
91 1.8.2.2 nathanw bus_space_handle_t sc_regh;
92 1.8.2.2 nathanw bus_space_handle_t sc_memh;
93 1.8.2.2 nathanw
94 1.8.2.2 nathanw size_t memsize;
95 1.8.2.2 nathanw int memtype;
96 1.8.2.2 nathanw
97 1.8.2.2 nathanw int has_dsp;
98 1.8.2.2 nathanw int bits_per_pixel;
99 1.8.2.2 nathanw int max_x, max_y;
100 1.8.2.2 nathanw int virt_x, virt_y;
101 1.8.2.2 nathanw int color_depth;
102 1.8.2.2 nathanw
103 1.8.2.2 nathanw int mem_freq;
104 1.8.2.2 nathanw int ramdac_freq;
105 1.8.2.2 nathanw int ref_freq;
106 1.8.2.2 nathanw
107 1.8.2.2 nathanw int ref_div;
108 1.8.2.2 nathanw int log2_vclk_post_div;
109 1.8.2.2 nathanw int vclk_post_div;
110 1.8.2.2 nathanw int vclk_fb_div;
111 1.8.2.2 nathanw int mclk_post_div;
112 1.8.2.2 nathanw int mclk_fb_div;
113 1.8.2.2 nathanw
114 1.8.2.2 nathanw struct mach64screen *wanted;
115 1.8.2.2 nathanw struct mach64screen *active;
116 1.8.2.2 nathanw void (*switchcb)(void *, int, int);
117 1.8.2.2 nathanw void *switchcbarg;
118 1.8.2.2 nathanw struct callout switch_callout;
119 1.8.2.2 nathanw LIST_HEAD(, mach64screen) screens;
120 1.8.2.2 nathanw const struct wsscreen_descr *currenttype;
121 1.8.2.2 nathanw };
122 1.8.2.2 nathanw
123 1.8.2.2 nathanw struct mach64screen {
124 1.8.2.2 nathanw struct rasops_info ri;
125 1.8.2.2 nathanw LIST_ENTRY(mach64screen) next;
126 1.8.2.2 nathanw struct mach64_softc *sc;
127 1.8.2.2 nathanw const struct wsscreen_descr *type;
128 1.8.2.2 nathanw int active;
129 1.8.2.2 nathanw u_int16_t *mem;
130 1.8.2.2 nathanw int dispoffset;
131 1.8.2.2 nathanw int mindispoffset;
132 1.8.2.2 nathanw int maxdispoffset;
133 1.8.2.2 nathanw
134 1.8.2.2 nathanw int cursoron;
135 1.8.2.2 nathanw int cursorcol;
136 1.8.2.2 nathanw int cursorrow;
137 1.8.2.2 nathanw u_int16_t cursortmp;
138 1.8.2.2 nathanw };
139 1.8.2.2 nathanw
140 1.8.2.2 nathanw struct mach64_crtcregs {
141 1.8.2.2 nathanw u_int32_t h_total_disp;
142 1.8.2.2 nathanw u_int32_t h_sync_strt_wid;
143 1.8.2.2 nathanw u_int32_t v_total_disp;
144 1.8.2.2 nathanw u_int32_t v_sync_strt_wid;
145 1.8.2.2 nathanw u_int32_t gen_cntl;
146 1.8.2.2 nathanw u_int32_t clock_cntl;
147 1.8.2.2 nathanw u_int32_t color_depth;
148 1.8.2.2 nathanw u_int32_t dot_clock;
149 1.8.2.2 nathanw };
150 1.8.2.2 nathanw
151 1.8.2.2 nathanw struct {
152 1.8.2.2 nathanw u_int16_t chip_id;
153 1.8.2.2 nathanw u_int32_t ramdac_freq;
154 1.8.2.2 nathanw } mach64_info[] = {
155 1.8.2.2 nathanw { PCI_PRODUCT_ATI_MACH64_CT, 135000 },
156 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_PRO_AGP, 230000 },
157 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_PRO_AGP1X, 230000 },
158 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_PRO_PCI_B, 230000 },
159 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_XL_AGP, 230000 },
160 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_PRO_PCI_P, 230000 },
161 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_PRO_PCI_L, 230000 },
162 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_XL_PCI, 230000 },
163 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_II, 135000 },
164 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_IIP, 200000 },
165 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_IIC_PCI, 230000 },
166 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_IIC_AGP_B, 230000 },
167 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_IIC_AGP_P, 230000 },
168 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_LT_PRO_AGP, 230000 },
169 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_MOB_M3_PCI, 230000 },
170 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_MOB_M3_AGP, 230000 },
171 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_LT, 230000 },
172 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_LT_PRO_PCI, 230000 },
173 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_MOBILITY, 230000 },
174 1.8.2.2 nathanw { PCI_PRODUCT_ATI_RAGE_LT_PRO, 230000 },
175 1.8.2.2 nathanw { PCI_PRODUCT_ATI_MACH64_VT, 170000 },
176 1.8.2.2 nathanw { PCI_PRODUCT_ATI_MACH64_VTB, 200000 },
177 1.8.2.2 nathanw { PCI_PRODUCT_ATI_MACH64_VT4, 230000 }
178 1.8.2.2 nathanw };
179 1.8.2.2 nathanw
180 1.8.2.2 nathanw static int mach64_chip_id, mach64_chip_rev;
181 1.8.2.2 nathanw static struct videomode default_mode;
182 1.8.2.2 nathanw static struct mach64screen mach64_console_screen;
183 1.8.2.2 nathanw
184 1.8.2.2 nathanw static char *mach64_memtype_names[] = {
185 1.8.2.2 nathanw "(N/A)", "DRAM", "EDO DRAM", "EDO DRAM", "SDRAM", "SGRAM", "WRAM",
186 1.8.2.2 nathanw "(unknown type)"
187 1.8.2.2 nathanw };
188 1.8.2.2 nathanw
189 1.8.2.2 nathanw struct videomode mach64_modes[] = {
190 1.8.2.2 nathanw /* 640x400 @ 70 Hz, 31.5 kHz */
191 1.8.2.2 nathanw { 25175, 640, 664, 760, 800, 400, 409, 411, 450, 0 },
192 1.8.2.2 nathanw /* 640x480 @ 72 Hz, 36.5 kHz */
193 1.8.2.2 nathanw { 25175, 640, 664, 760, 800, 480, 491, 493, 525, 0 },
194 1.8.2.2 nathanw /* 800x600 @ 72 Hz, 48.0 kHz */
195 1.8.2.2 nathanw { 50000, 800, 856, 976, 1040, 600, 637, 643, 666,
196 1.8.2.2 nathanw VID_PHSYNC | VID_PVSYNC },
197 1.8.2.2 nathanw /* 1024x768 @ 70 Hz, 56.5 kHz */
198 1.8.2.2 nathanw { 75000, 1024, 1048, 1184, 1328, 768, 771, 777, 806,
199 1.8.2.2 nathanw VID_NHSYNC | VID_NVSYNC },
200 1.8.2.2 nathanw /* 1152x864 @ 70 Hz, 62.4 kHz */
201 1.8.2.2 nathanw { 92000, 1152, 1208, 1368, 1474, 864, 865, 875, 895, 0 },
202 1.8.2.2 nathanw /* 1280x1024 @ 70 Hz, 74.59 kHz */
203 1.8.2.2 nathanw { 126500, 1280, 1312, 1472, 1696, 1024, 1032, 1040, 1068,
204 1.8.2.2 nathanw VID_NHSYNC | VID_NVSYNC }
205 1.8.2.2 nathanw };
206 1.8.2.2 nathanw
207 1.8.2.2 nathanw /* FIXME values are wrong! */
208 1.8.2.2 nathanw const u_char mach64_cmap[16 * 3] = {
209 1.8.2.2 nathanw 0x00, 0x00, 0x00, /* black */
210 1.8.2.2 nathanw 0x7f, 0x00, 0x00, /* red */
211 1.8.2.2 nathanw 0x00, 0x7f, 0x00, /* green */
212 1.8.2.2 nathanw 0x7f, 0x7f, 0x00, /* brown */
213 1.8.2.2 nathanw 0x00, 0x00, 0x7f, /* blue */
214 1.8.2.2 nathanw 0x7f, 0x00, 0x7f, /* magenta */
215 1.8.2.2 nathanw 0x00, 0x7f, 0x7f, /* cyan */
216 1.8.2.2 nathanw 0xff, 0xff, 0xff, /* white */
217 1.8.2.2 nathanw
218 1.8.2.2 nathanw 0x7f, 0x7f, 0x7f, /* black */
219 1.8.2.2 nathanw 0xff, 0x00, 0x00, /* red */
220 1.8.2.2 nathanw 0x00, 0xff, 0x00, /* green */
221 1.8.2.2 nathanw 0xff, 0xff, 0x00, /* brown */
222 1.8.2.2 nathanw 0x00, 0x00, 0xff, /* blue */
223 1.8.2.2 nathanw 0xff, 0x00, 0xff, /* magenta */
224 1.8.2.2 nathanw 0x00, 0xff, 0xff, /* cyan */
225 1.8.2.2 nathanw 0xff, 0xff, 0xff, /* white */
226 1.8.2.2 nathanw };
227 1.8.2.2 nathanw
228 1.8.2.2 nathanw int mach64_match(struct device *, struct cfdata *, void *);
229 1.8.2.2 nathanw void mach64_attach(struct device *, struct device *, void *);
230 1.8.2.2 nathanw
231 1.8.2.2 nathanw CFATTACH_DECL(machfb, sizeof(struct mach64_softc), mach64_match, mach64_attach,
232 1.8.2.2 nathanw NULL, NULL);
233 1.8.2.2 nathanw
234 1.8.2.2 nathanw void mach64_init(struct mach64_softc *);
235 1.8.2.2 nathanw int mach64_get_memsize(struct mach64_softc *);
236 1.8.2.2 nathanw int mach64_get_max_ramdac(struct mach64_softc *);
237 1.8.2.2 nathanw void mach64_get_mode(struct mach64_softc *, struct videomode *);
238 1.8.2.2 nathanw int mach64_calc_crtcregs(struct mach64_softc *, struct mach64_crtcregs *,
239 1.8.2.2 nathanw struct videomode *);
240 1.8.2.2 nathanw void mach64_set_crtcregs(struct mach64_softc *, struct mach64_crtcregs *);
241 1.8.2.2 nathanw int mach64_modeswitch(struct mach64_softc *, struct videomode *);
242 1.8.2.2 nathanw void mach64_set_dsp(struct mach64_softc *);
243 1.8.2.2 nathanw void mach64_set_pll(struct mach64_softc *, int);
244 1.8.2.2 nathanw void mach64_reset_engine(struct mach64_softc *);
245 1.8.2.2 nathanw void mach64_init_engine(struct mach64_softc *);
246 1.8.2.2 nathanw void mach64_adjust_frame(struct mach64_softc *, int, int);
247 1.8.2.2 nathanw void mach64_init_lut(struct mach64_softc *);
248 1.8.2.2 nathanw void mach64_switch_screen(struct mach64_softc *);
249 1.8.2.2 nathanw void mach64_init_screen(struct mach64_softc *, struct mach64screen *,
250 1.8.2.2 nathanw const struct wsscreen_descr *, int, long *, int);
251 1.8.2.2 nathanw void mach64_restore_screen(struct mach64screen *,
252 1.8.2.2 nathanw const struct wsscreen_descr *, u_int16_t *);
253 1.8.2.2 nathanw int mach64_set_screentype(struct mach64_softc *,
254 1.8.2.2 nathanw const struct wsscreen_descr *);
255 1.8.2.2 nathanw int mach64_is_console(struct pci_attach_args *);
256 1.8.2.2 nathanw
257 1.8.2.2 nathanw void mach64_cursor(void *, int, int, int);
258 1.8.2.2 nathanw int mach64_mapchar(void *, int, u_int *);
259 1.8.2.2 nathanw void mach64_putchar(void *, int, int, u_int, long);
260 1.8.2.2 nathanw void mach64_copycols(void *, int, int, int, int);
261 1.8.2.2 nathanw void mach64_erasecols(void *, int, int, int, long);
262 1.8.2.2 nathanw void mach64_copyrows(void *, int, int, int);
263 1.8.2.2 nathanw void mach64_eraserows(void *, int, int, long);
264 1.8.2.2 nathanw int mach64_allocattr(void *, int, int, int, long *);
265 1.8.2.2 nathanw
266 1.8.2.2 nathanw #if 0
267 1.8.2.2 nathanw const struct wsdisplay_emulops mach64_emulops = {
268 1.8.2.2 nathanw mach64_cursor,
269 1.8.2.2 nathanw mach64_mapchar,
270 1.8.2.2 nathanw mach64_putchar,
271 1.8.2.2 nathanw mach64_copycols,
272 1.8.2.2 nathanw mach64_erasecols,
273 1.8.2.2 nathanw mach64_copyrows,
274 1.8.2.2 nathanw mach64_eraserows,
275 1.8.2.2 nathanw mach64_allocattr,
276 1.8.2.2 nathanw };
277 1.8.2.2 nathanw #endif
278 1.8.2.2 nathanw
279 1.8.2.2 nathanw struct wsscreen_descr mach64_defaultscreen = {
280 1.8.2.2 nathanw "default",
281 1.8.2.2 nathanw 0, 0,
282 1.8.2.2 nathanw &mach64_console_screen.ri.ri_ops,
283 1.8.2.2 nathanw 8, 16,
284 1.8.2.2 nathanw WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
285 1.8.2.2 nathanw &default_mode
286 1.8.2.2 nathanw }, mach64_80x25_screen = {
287 1.8.2.2 nathanw "80x25", 80, 25,
288 1.8.2.2 nathanw &mach64_console_screen.ri.ri_ops,
289 1.8.2.2 nathanw 8, 16,
290 1.8.2.2 nathanw WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
291 1.8.2.2 nathanw &mach64_modes[0]
292 1.8.2.2 nathanw }, mach64_80x30_screen = {
293 1.8.2.2 nathanw "80x30", 80, 30,
294 1.8.2.2 nathanw &mach64_console_screen.ri.ri_ops,
295 1.8.2.2 nathanw 8, 16,
296 1.8.2.2 nathanw WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
297 1.8.2.2 nathanw &mach64_modes[1]
298 1.8.2.2 nathanw }, mach64_80x40_screen = {
299 1.8.2.2 nathanw "80x40", 80, 40,
300 1.8.2.2 nathanw &mach64_console_screen.ri.ri_ops,
301 1.8.2.2 nathanw 8, 10,
302 1.8.2.2 nathanw WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
303 1.8.2.2 nathanw &mach64_modes[0]
304 1.8.2.2 nathanw }, mach64_80x50_screen = {
305 1.8.2.2 nathanw "80x50", 80, 50,
306 1.8.2.2 nathanw &mach64_console_screen.ri.ri_ops,
307 1.8.2.2 nathanw 8, 8,
308 1.8.2.2 nathanw WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
309 1.8.2.2 nathanw &mach64_modes[0]
310 1.8.2.2 nathanw }, mach64_100x37_screen = {
311 1.8.2.2 nathanw "100x37", 100, 37,
312 1.8.2.2 nathanw &mach64_console_screen.ri.ri_ops,
313 1.8.2.2 nathanw 8, 16,
314 1.8.2.2 nathanw WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
315 1.8.2.2 nathanw &mach64_modes[2]
316 1.8.2.2 nathanw }, mach64_128x48_screen = {
317 1.8.2.2 nathanw "128x48", 128, 48,
318 1.8.2.2 nathanw &mach64_console_screen.ri.ri_ops,
319 1.8.2.2 nathanw 8, 16,
320 1.8.2.2 nathanw WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
321 1.8.2.2 nathanw &mach64_modes[3]
322 1.8.2.2 nathanw }, mach64_144x54_screen = {
323 1.8.2.2 nathanw "144x54", 144, 54,
324 1.8.2.2 nathanw &mach64_console_screen.ri.ri_ops,
325 1.8.2.2 nathanw 8, 16,
326 1.8.2.2 nathanw WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
327 1.8.2.2 nathanw &mach64_modes[4]
328 1.8.2.2 nathanw }, mach64_160x64_screen = {
329 1.8.2.2 nathanw "160x54", 160, 64,
330 1.8.2.2 nathanw &mach64_console_screen.ri.ri_ops,
331 1.8.2.2 nathanw 8, 16,
332 1.8.2.2 nathanw WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
333 1.8.2.2 nathanw &mach64_modes[5]
334 1.8.2.2 nathanw };
335 1.8.2.2 nathanw
336 1.8.2.2 nathanw const struct wsscreen_descr *_mach64_scrlist[] = {
337 1.8.2.2 nathanw &mach64_defaultscreen,
338 1.8.2.2 nathanw &mach64_80x25_screen,
339 1.8.2.2 nathanw &mach64_80x30_screen,
340 1.8.2.2 nathanw &mach64_80x40_screen,
341 1.8.2.2 nathanw &mach64_80x50_screen,
342 1.8.2.2 nathanw &mach64_100x37_screen,
343 1.8.2.2 nathanw &mach64_128x48_screen,
344 1.8.2.2 nathanw &mach64_144x54_screen,
345 1.8.2.2 nathanw &mach64_160x64_screen
346 1.8.2.2 nathanw };
347 1.8.2.2 nathanw
348 1.8.2.2 nathanw struct wsscreen_list mach64_screenlist = {
349 1.8.2.2 nathanw sizeof(_mach64_scrlist) / sizeof(struct wsscreen_descr *),
350 1.8.2.2 nathanw _mach64_scrlist
351 1.8.2.2 nathanw };
352 1.8.2.2 nathanw
353 1.8.2.2 nathanw int mach64_ioctl(void *, u_long, caddr_t, int, struct proc *);
354 1.8.2.2 nathanw paddr_t mach64_mmap(void *, off_t, int);
355 1.8.2.2 nathanw int mach64_alloc_screen(void *, const struct wsscreen_descr *, void **,
356 1.8.2.2 nathanw int *, int *, long *);
357 1.8.2.2 nathanw void mach64_free_screen(void *, void *);
358 1.8.2.2 nathanw int mach64_show_screen(void *, void *, int, void (*)(void *, int, int),
359 1.8.2.2 nathanw void *);
360 1.8.2.2 nathanw int mach64_load_font(void *, void *, struct wsdisplay_font *);
361 1.8.2.2 nathanw
362 1.8.2.2 nathanw struct wsdisplay_accessops mach64_accessops = {
363 1.8.2.2 nathanw mach64_ioctl,
364 1.8.2.2 nathanw mach64_mmap,
365 1.8.2.2 nathanw mach64_alloc_screen,
366 1.8.2.2 nathanw mach64_free_screen,
367 1.8.2.2 nathanw mach64_show_screen,
368 1.8.2.2 nathanw NULL
369 1.8.2.2 nathanw };
370 1.8.2.2 nathanw
371 1.8.2.2 nathanw /*
372 1.8.2.2 nathanw * Inline functions for getting access to register aperture.
373 1.8.2.2 nathanw */
374 1.8.2.2 nathanw static inline u_int32_t regr(struct mach64_softc *, u_int32_t);
375 1.8.2.2 nathanw static inline u_int8_t regrb(struct mach64_softc *, u_int32_t);
376 1.8.2.2 nathanw static inline void regw(struct mach64_softc *, u_int32_t, u_int32_t);
377 1.8.2.2 nathanw static inline void regwb(struct mach64_softc *, u_int32_t, u_int8_t);
378 1.8.2.2 nathanw static inline void regwb_pll(struct mach64_softc *, u_int32_t, u_int8_t);
379 1.8.2.2 nathanw
380 1.8.2.2 nathanw static inline u_int32_t
381 1.8.2.2 nathanw regr(struct mach64_softc *sc, u_int32_t index)
382 1.8.2.2 nathanw {
383 1.8.2.2 nathanw
384 1.8.2.2 nathanw return bus_space_read_4(sc->sc_regt, sc->sc_regh, index);
385 1.8.2.2 nathanw }
386 1.8.2.2 nathanw
387 1.8.2.2 nathanw static inline u_int8_t
388 1.8.2.2 nathanw regrb(struct mach64_softc *sc, u_int32_t index)
389 1.8.2.2 nathanw {
390 1.8.2.2 nathanw
391 1.8.2.2 nathanw return bus_space_read_1(sc->sc_regt, sc->sc_regh, index);
392 1.8.2.2 nathanw }
393 1.8.2.2 nathanw
394 1.8.2.2 nathanw static inline void
395 1.8.2.2 nathanw regw(struct mach64_softc *sc, u_int32_t index, u_int32_t data)
396 1.8.2.2 nathanw {
397 1.8.2.2 nathanw
398 1.8.2.2 nathanw bus_space_write_4(sc->sc_regt, sc->sc_regh, index, data);
399 1.8.2.2 nathanw }
400 1.8.2.2 nathanw
401 1.8.2.2 nathanw static inline void
402 1.8.2.2 nathanw regwb(struct mach64_softc *sc, u_int32_t index, u_int8_t data)
403 1.8.2.2 nathanw {
404 1.8.2.2 nathanw
405 1.8.2.2 nathanw bus_space_write_1(sc->sc_regt, sc->sc_regh, index, data);
406 1.8.2.2 nathanw }
407 1.8.2.2 nathanw
408 1.8.2.2 nathanw static inline void
409 1.8.2.2 nathanw regwb_pll(struct mach64_softc *sc, u_int32_t index, u_int8_t data)
410 1.8.2.2 nathanw {
411 1.8.2.2 nathanw
412 1.8.2.2 nathanw regwb(sc, CLOCK_CNTL + 1, (index << 2) | PLL_WR_EN);
413 1.8.2.2 nathanw regwb(sc, CLOCK_CNTL + 2, data);
414 1.8.2.2 nathanw regwb(sc, CLOCK_CNTL + 1, (index << 2) & ~PLL_WR_EN);
415 1.8.2.2 nathanw }
416 1.8.2.2 nathanw
417 1.8.2.2 nathanw static inline void
418 1.8.2.2 nathanw wait_for_fifo(struct mach64_softc *sc, u_int8_t v)
419 1.8.2.2 nathanw {
420 1.8.2.2 nathanw
421 1.8.2.2 nathanw while ((regr(sc, FIFO_STAT) & 0xffff) > (0x8000 >> v))
422 1.8.2.2 nathanw ;
423 1.8.2.2 nathanw }
424 1.8.2.2 nathanw
425 1.8.2.2 nathanw static inline void
426 1.8.2.2 nathanw wait_for_idle(struct mach64_softc *sc)
427 1.8.2.2 nathanw {
428 1.8.2.2 nathanw
429 1.8.2.2 nathanw wait_for_fifo(sc, 16);
430 1.8.2.2 nathanw while ((regr(sc, GUI_STAT) & 1) != 0)
431 1.8.2.2 nathanw ;
432 1.8.2.2 nathanw }
433 1.8.2.2 nathanw
434 1.8.2.2 nathanw int
435 1.8.2.2 nathanw mach64_match(struct device *parent, struct cfdata *match, void *aux)
436 1.8.2.2 nathanw {
437 1.8.2.2 nathanw struct pci_attach_args *pa = (struct pci_attach_args *)aux;
438 1.8.2.2 nathanw int i;
439 1.8.2.2 nathanw
440 1.8.2.2 nathanw if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
441 1.8.2.2 nathanw PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
442 1.8.2.2 nathanw return 0;
443 1.8.2.2 nathanw
444 1.8.2.2 nathanw for (i = 0; i < sizeof(mach64_info) / sizeof(mach64_info[0]); i++)
445 1.8.2.2 nathanw if (PCI_PRODUCT(pa->pa_id) == mach64_info[i].chip_id) {
446 1.8.2.2 nathanw mach64_chip_id = PCI_PRODUCT(pa->pa_id);
447 1.8.2.2 nathanw mach64_chip_rev = PCI_REVISION(pa->pa_class);
448 1.8.2.2 nathanw return 1;
449 1.8.2.2 nathanw }
450 1.8.2.2 nathanw
451 1.8.2.2 nathanw return 0;
452 1.8.2.2 nathanw }
453 1.8.2.2 nathanw
454 1.8.2.2 nathanw void
455 1.8.2.2 nathanw mach64_attach(struct device *parent, struct device *self, void *aux)
456 1.8.2.2 nathanw {
457 1.8.2.2 nathanw struct mach64_softc *sc = (void *)self;
458 1.8.2.2 nathanw struct pci_attach_args *pa = aux;
459 1.8.2.2 nathanw char devinfo[256];
460 1.8.2.2 nathanw int bar, reg, id;
461 1.8.2.2 nathanw struct wsemuldisplaydev_attach_args aa;
462 1.8.2.2 nathanw long defattr;
463 1.8.2.2 nathanw int setmode, console;
464 1.8.2.2 nathanw
465 1.8.2.2 nathanw sc->sc_pc = pa->pa_pc;
466 1.8.2.2 nathanw sc->sc_pcitag = pa->pa_tag;
467 1.8.2.2 nathanw
468 1.8.2.2 nathanw pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
469 1.8.2.2 nathanw printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
470 1.8.2.2 nathanw
471 1.8.2.2 nathanw for (bar = 0; bar < NBARS; bar++) {
472 1.8.2.2 nathanw reg = PCI_MAPREG_START + (bar * 4);
473 1.8.2.2 nathanw sc->sc_bars[bar].vb_type = pci_mapreg_type(sc->sc_pc,
474 1.8.2.2 nathanw sc->sc_pcitag, reg);
475 1.8.2.2 nathanw (void)pci_mapreg_info(sc->sc_pc, sc->sc_pcitag, reg,
476 1.8.2.2 nathanw sc->sc_bars[bar].vb_type, &sc->sc_bars[bar].vb_base,
477 1.8.2.2 nathanw &sc->sc_bars[bar].vb_size, &sc->sc_bars[bar].vb_flags);
478 1.8.2.2 nathanw }
479 1.8.2.2 nathanw sc->sc_memt = pa->pa_memt;
480 1.8.2.2 nathanw
481 1.8.2.2 nathanw mach64_init(sc);
482 1.8.2.2 nathanw
483 1.8.2.2 nathanw printf("%s: %d MB aperture at 0x%08x, %d KB registers at 0x%08x\n",
484 1.8.2.2 nathanw sc->sc_dev.dv_xname, (u_int)(sc->sc_apersize / (1024 * 1024)),
485 1.8.2.2 nathanw (u_int)sc->sc_aperbase, (u_int)(sc->sc_regsize / 1024),
486 1.8.2.2 nathanw (u_int)sc->sc_regbase);
487 1.8.2.2 nathanw
488 1.8.2.2 nathanw if (mach64_chip_id == PCI_PRODUCT_ATI_MACH64_CT ||
489 1.8.2.2 nathanw ((mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
490 1.8.2.2 nathanw mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II) &&
491 1.8.2.2 nathanw (mach64_chip_rev & 0x07) == 0))
492 1.8.2.2 nathanw sc->has_dsp = 0;
493 1.8.2.2 nathanw else
494 1.8.2.2 nathanw sc->has_dsp = 1;
495 1.8.2.2 nathanw
496 1.8.2.2 nathanw sc->memsize = mach64_get_memsize(sc);
497 1.8.2.2 nathanw if (sc->memsize == 8192)
498 1.8.2.2 nathanw /* The last page is used as register aperture. */
499 1.8.2.2 nathanw sc->memsize -= 4;
500 1.8.2.2 nathanw sc->memtype = regr(sc, CONFIG_STAT0) & 0x07;
501 1.8.2.2 nathanw
502 1.8.2.2 nathanw /* XXX is there any way to calculate reference frequency from
503 1.8.2.2 nathanw known values? */
504 1.8.2.2 nathanw if (mach64_chip_id == PCI_PRODUCT_ATI_RAGE_XL_PCI)
505 1.8.2.2 nathanw sc->ref_freq = 29498;
506 1.8.2.2 nathanw else
507 1.8.2.2 nathanw sc->ref_freq = 14318;
508 1.8.2.2 nathanw
509 1.8.2.2 nathanw regwb(sc, CLOCK_CNTL + 1, PLL_REF_DIV << 2);
510 1.8.2.2 nathanw sc->ref_div = regrb(sc, CLOCK_CNTL + 2);
511 1.8.2.2 nathanw regwb(sc, CLOCK_CNTL + 1, MCLK_FB_DIV << 2);
512 1.8.2.2 nathanw sc->mclk_fb_div = regrb(sc, CLOCK_CNTL + 2);
513 1.8.2.2 nathanw sc->mem_freq = (2 * sc->ref_freq * sc->mclk_fb_div) /
514 1.8.2.2 nathanw (sc->ref_div * 2);
515 1.8.2.2 nathanw sc->mclk_post_div = (sc->mclk_fb_div * 2 * sc->ref_freq) /
516 1.8.2.2 nathanw (sc->mem_freq * sc->ref_div);
517 1.8.2.2 nathanw sc->ramdac_freq = mach64_get_max_ramdac(sc);
518 1.8.2.2 nathanw printf("%s: %ld KB %s %d.%d MHz, maximum RAMDAC clock %d MHz\n",
519 1.8.2.2 nathanw sc->sc_dev.dv_xname, (u_long)sc->memsize,
520 1.8.2.2 nathanw mach64_memtype_names[sc->memtype],
521 1.8.2.2 nathanw sc->mem_freq / 1000, sc->mem_freq % 1000,
522 1.8.2.2 nathanw sc->ramdac_freq / 1000);
523 1.8.2.2 nathanw
524 1.8.2.2 nathanw id = regr(sc, CONFIG_CHIP_ID) & 0xffff;
525 1.8.2.2 nathanw if (id != mach64_chip_id) {
526 1.8.2.2 nathanw printf("%s: chip ID mismatch, 0x%x != 0x%x\n",
527 1.8.2.2 nathanw sc->sc_dev.dv_xname, id, mach64_chip_id);
528 1.8.2.2 nathanw return;
529 1.8.2.2 nathanw }
530 1.8.2.2 nathanw
531 1.8.2.2 nathanw console = mach64_is_console(pa);
532 1.8.2.2 nathanw
533 1.8.2.2 nathanw #ifdef __sparc__
534 1.8.2.2 nathanw if (console) {
535 1.8.2.2 nathanw mach64_get_mode(sc, &default_mode);
536 1.8.2.2 nathanw setmode = 0;
537 1.8.2.2 nathanw } else {
538 1.8.2.2 nathanw memcpy(&default_mode, &mach64_modes[4], sizeof(struct videomode));
539 1.8.2.2 nathanw setmode = 1;
540 1.8.2.2 nathanw }
541 1.8.2.2 nathanw #else
542 1.8.2.2 nathanw memcpy(&default_mode, &mach64_modes[0], sizeof(struct videomode));
543 1.8.2.2 nathanw setmode = 1;
544 1.8.2.2 nathanw #endif
545 1.8.2.2 nathanw
546 1.8.2.2 nathanw sc->bits_per_pixel = 8;
547 1.8.2.2 nathanw sc->virt_x = default_mode.hdisplay;
548 1.8.2.2 nathanw sc->virt_y = default_mode.vdisplay;
549 1.8.2.2 nathanw sc->max_x = sc->virt_x - 1;
550 1.8.2.2 nathanw sc->max_y = (sc->memsize * 1024) /
551 1.8.2.2 nathanw (sc->virt_x * (sc->bits_per_pixel / 8)) - 1;
552 1.8.2.2 nathanw
553 1.8.2.2 nathanw sc->color_depth = CRTC_PIX_WIDTH_8BPP;
554 1.8.2.2 nathanw
555 1.8.2.2 nathanw mach64_init_engine(sc);
556 1.8.2.2 nathanw #if 0
557 1.8.2.2 nathanw mach64_adjust_frame(0, 0);
558 1.8.2.2 nathanw if (sc->bits_per_pixel == 8)
559 1.8.2.2 nathanw mach64_init_lut(sc);
560 1.8.2.2 nathanw #endif
561 1.8.2.2 nathanw
562 1.8.2.2 nathanw printf("%s: initial resolution %dx%d at %d bpp\n", sc->sc_dev.dv_xname,
563 1.8.2.2 nathanw default_mode.hdisplay, default_mode.vdisplay,
564 1.8.2.2 nathanw sc->bits_per_pixel);
565 1.8.2.2 nathanw
566 1.8.2.2 nathanw mach64_console_screen.ri.ri_hw = sc;
567 1.8.2.2 nathanw mach64_console_screen.ri.ri_depth = sc->bits_per_pixel;
568 1.8.2.2 nathanw mach64_console_screen.ri.ri_bits = (void*)(u_long)sc->sc_aperbase;
569 1.8.2.2 nathanw mach64_console_screen.ri.ri_width = default_mode.hdisplay;
570 1.8.2.2 nathanw mach64_console_screen.ri.ri_height = default_mode.vdisplay;
571 1.8.2.2 nathanw mach64_console_screen.ri.ri_stride = mach64_console_screen.ri.ri_width;
572 1.8.2.2 nathanw mach64_console_screen.ri.ri_flg = RI_CLEAR;
573 1.8.2.2 nathanw
574 1.8.2.2 nathanw rasops_init(&mach64_console_screen.ri, mach64_console_screen.ri.ri_height / 16,
575 1.8.2.2 nathanw mach64_console_screen.ri.ri_width / 8);
576 1.8.2.2 nathanw
577 1.8.2.2 nathanw mach64_defaultscreen.nrows = mach64_console_screen.ri.ri_rows;
578 1.8.2.2 nathanw mach64_defaultscreen.ncols = mach64_console_screen.ri.ri_cols;
579 1.8.2.2 nathanw
580 1.8.2.2 nathanw mach64_console_screen.ri.ri_ops.allocattr(&mach64_console_screen.ri, 0, 0, 0,
581 1.8.2.2 nathanw &defattr);
582 1.8.2.2 nathanw
583 1.8.2.2 nathanw /* Initialize fonts */
584 1.8.2.2 nathanw wsfont_init();
585 1.8.2.2 nathanw
586 1.8.2.2 nathanw if (console) {
587 1.8.2.2 nathanw mach64_init_screen(sc, &mach64_console_screen,
588 1.8.2.2 nathanw &mach64_defaultscreen, 1, &defattr, setmode);
589 1.8.2.2 nathanw wsdisplay_cnattach(&mach64_defaultscreen, &mach64_console_screen.ri,
590 1.8.2.2 nathanw 0, 0, defattr);
591 1.8.2.2 nathanw }
592 1.8.2.2 nathanw
593 1.8.2.2 nathanw aa.console = console;
594 1.8.2.2 nathanw aa.scrdata = &mach64_screenlist;
595 1.8.2.2 nathanw aa.accessops = &mach64_accessops;
596 1.8.2.2 nathanw aa.accesscookie = sc;
597 1.8.2.2 nathanw
598 1.8.2.2 nathanw config_found(self, &aa, wsemuldisplaydevprint);
599 1.8.2.2 nathanw }
600 1.8.2.2 nathanw
601 1.8.2.2 nathanw void
602 1.8.2.2 nathanw mach64_init_screen(struct mach64_softc *sc, struct mach64screen *scr,
603 1.8.2.2 nathanw const struct wsscreen_descr *type, int existing, long *attrp, int setmode)
604 1.8.2.2 nathanw {
605 1.8.2.2 nathanw
606 1.8.2.2 nathanw scr->sc = sc;
607 1.8.2.2 nathanw scr->type = type;
608 1.8.2.2 nathanw scr->mindispoffset = 0;
609 1.8.2.2 nathanw scr->maxdispoffset = sc->memsize * 1024;
610 1.8.2.2 nathanw scr->dispoffset = 0;
611 1.8.2.2 nathanw scr->cursorcol = 0;
612 1.8.2.2 nathanw scr->cursorrow = 0;
613 1.8.2.2 nathanw
614 1.8.2.2 nathanw scr->mem = (u_int16_t *)malloc(type->nrows * type->ncols * 2,
615 1.8.2.2 nathanw M_DEVBUF, M_WAITOK);
616 1.8.2.2 nathanw if (existing) {
617 1.8.2.2 nathanw scr->active = 1;
618 1.8.2.2 nathanw
619 1.8.2.2 nathanw if (setmode && mach64_set_screentype(sc, type)) {
620 1.8.2.2 nathanw panic("%s: failed to switch video mode",
621 1.8.2.2 nathanw sc->sc_dev.dv_xname);
622 1.8.2.2 nathanw }
623 1.8.2.2 nathanw } else {
624 1.8.2.2 nathanw scr->active = 0;
625 1.8.2.2 nathanw }
626 1.8.2.2 nathanw
627 1.8.2.2 nathanw LIST_INSERT_HEAD(&sc->screens, scr, next);
628 1.8.2.2 nathanw }
629 1.8.2.2 nathanw
630 1.8.2.2 nathanw void
631 1.8.2.2 nathanw mach64_init(struct mach64_softc *sc)
632 1.8.2.2 nathanw {
633 1.8.2.2 nathanw
634 1.8.2.2 nathanw if (bus_space_map(sc->sc_memt, sc->sc_aperbase, sc->sc_apersize,
635 1.8.2.2 nathanw BUS_SPACE_MAP_LINEAR, &sc->sc_memh)) {
636 1.8.2.2 nathanw panic("%s: failed to map aperture", sc->sc_dev.dv_xname);
637 1.8.2.2 nathanw }
638 1.8.2.2 nathanw sc->sc_aperbase = (vaddr_t)bus_space_vaddr(sc->sc_memt, sc->sc_memh);
639 1.8.2.2 nathanw
640 1.8.2.2 nathanw sc->sc_regt = sc->sc_memt;
641 1.8.2.2 nathanw bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF,
642 1.8.2.2 nathanw sc->sc_regsize, &sc->sc_regh);
643 1.8.2.2 nathanw sc->sc_regbase = sc->sc_aperbase + 0x7ffc00;
644 1.8.2.2 nathanw
645 1.8.2.2 nathanw #if _BYTE_ORDER == _BIG_ENDIAN
646 1.8.2.2 nathanw sc->sc_aperbase += 0x800000;
647 1.8.2.2 nathanw sc->sc_apersize -= 0x800000;
648 1.8.2.2 nathanw #endif
649 1.8.2.2 nathanw
650 1.8.2.2 nathanw LIST_INIT(&sc->screens);
651 1.8.2.2 nathanw sc->active = NULL;
652 1.8.2.2 nathanw sc->currenttype = &mach64_defaultscreen;
653 1.8.2.2 nathanw callout_init(&sc->switch_callout);
654 1.8.2.2 nathanw }
655 1.8.2.2 nathanw
656 1.8.2.2 nathanw int
657 1.8.2.2 nathanw mach64_get_memsize(struct mach64_softc *sc)
658 1.8.2.2 nathanw {
659 1.8.2.2 nathanw int tmp, memsize;
660 1.8.2.2 nathanw int mem_tab[] = {
661 1.8.2.2 nathanw 512, 1024, 2048, 4096, 6144, 8192, 12288, 16384
662 1.8.2.2 nathanw };
663 1.8.2.2 nathanw
664 1.8.2.2 nathanw tmp = regr(sc, MEM_CNTL);
665 1.8.2.2 nathanw if (sc->has_dsp) {
666 1.8.2.2 nathanw tmp &= 0x0000000f;
667 1.8.2.2 nathanw if (tmp < 8)
668 1.8.2.2 nathanw memsize = (tmp + 1) * 512;
669 1.8.2.2 nathanw else if (tmp < 12)
670 1.8.2.2 nathanw memsize = (tmp - 3) * 1024;
671 1.8.2.2 nathanw else
672 1.8.2.2 nathanw memsize = (tmp - 7) * 2048;
673 1.8.2.2 nathanw } else {
674 1.8.2.2 nathanw memsize = mem_tab[tmp & 0x07];
675 1.8.2.2 nathanw }
676 1.8.2.2 nathanw
677 1.8.2.2 nathanw return memsize;
678 1.8.2.2 nathanw }
679 1.8.2.2 nathanw
680 1.8.2.2 nathanw int
681 1.8.2.2 nathanw mach64_get_max_ramdac(struct mach64_softc *sc)
682 1.8.2.2 nathanw {
683 1.8.2.2 nathanw int i;
684 1.8.2.2 nathanw
685 1.8.2.2 nathanw if ((mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
686 1.8.2.2 nathanw mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II) &&
687 1.8.2.2 nathanw (mach64_chip_rev & 0x07))
688 1.8.2.2 nathanw return 170000;
689 1.8.2.2 nathanw
690 1.8.2.2 nathanw for (i = 0; i < sizeof(mach64_info) / sizeof(mach64_info[0]); i++)
691 1.8.2.2 nathanw if (mach64_chip_id == mach64_info[i].chip_id)
692 1.8.2.2 nathanw return mach64_info[i].ramdac_freq;
693 1.8.2.2 nathanw
694 1.8.2.2 nathanw if (sc->bits_per_pixel == 8)
695 1.8.2.2 nathanw return 135000;
696 1.8.2.2 nathanw else
697 1.8.2.2 nathanw return 80000;
698 1.8.2.2 nathanw }
699 1.8.2.2 nathanw
700 1.8.2.2 nathanw void
701 1.8.2.2 nathanw mach64_get_mode(struct mach64_softc *sc, struct videomode *mode)
702 1.8.2.2 nathanw {
703 1.8.2.2 nathanw struct mach64_crtcregs crtc;
704 1.8.2.2 nathanw
705 1.8.2.2 nathanw crtc.h_total_disp = regr(sc, CRTC_H_TOTAL_DISP);
706 1.8.2.2 nathanw crtc.h_sync_strt_wid = regr(sc, CRTC_H_SYNC_STRT_WID);
707 1.8.2.2 nathanw crtc.v_total_disp = regr(sc, CRTC_V_TOTAL_DISP);
708 1.8.2.2 nathanw crtc.v_sync_strt_wid = regr(sc, CRTC_V_SYNC_STRT_WID);
709 1.8.2.2 nathanw
710 1.8.2.2 nathanw mode->htotal = ((crtc.h_total_disp & 0xffff) + 1) << 3;
711 1.8.2.2 nathanw mode->hdisplay = ((crtc.h_total_disp >> 16) + 1) << 3;
712 1.8.2.2 nathanw mode->hsync_start = ((crtc.h_sync_strt_wid & 0xffff) + 1) << 3;
713 1.8.2.2 nathanw mode->hsync_end = ((crtc.h_sync_strt_wid >> 16) << 3) +
714 1.8.2.2 nathanw mode->hsync_start;
715 1.8.2.2 nathanw mode->vtotal = (crtc.v_total_disp & 0xffff) + 1;
716 1.8.2.2 nathanw mode->vdisplay = (crtc.v_total_disp >> 16) + 1;
717 1.8.2.2 nathanw mode->vsync_start = (crtc.v_sync_strt_wid & 0xffff) + 1;
718 1.8.2.2 nathanw mode->vsync_end = (crtc.v_sync_strt_wid >> 16) + mode->vsync_start;
719 1.8.2.2 nathanw
720 1.8.2.2 nathanw #ifdef MACH64_DEBUG
721 1.8.2.2 nathanw printf("mach64_get_mode: %d %d %d %d %d %d %d %d\n",
722 1.8.2.2 nathanw mode->hdisplay, mode->hsync_start, mode->hsync_end, mode->htotal,
723 1.8.2.2 nathanw mode->vdisplay, mode->vsync_start, mode->vsync_end, mode->vtotal);
724 1.8.2.2 nathanw #endif
725 1.8.2.2 nathanw }
726 1.8.2.2 nathanw
727 1.8.2.2 nathanw int
728 1.8.2.2 nathanw mach64_calc_crtcregs(struct mach64_softc *sc, struct mach64_crtcregs *crtc,
729 1.8.2.2 nathanw struct videomode *mode)
730 1.8.2.2 nathanw {
731 1.8.2.2 nathanw
732 1.8.2.2 nathanw if (mode->dot_clock > sc->ramdac_freq)
733 1.8.2.2 nathanw /* Clock too high. */
734 1.8.2.2 nathanw return 1;
735 1.8.2.2 nathanw
736 1.8.2.2 nathanw crtc->h_total_disp = (((mode->hdisplay >> 3) - 1) << 16) |
737 1.8.2.2 nathanw ((mode->htotal >> 3) - 1);
738 1.8.2.2 nathanw crtc->h_sync_strt_wid =
739 1.8.2.2 nathanw (((mode->hsync_end - mode->hsync_start) >> 3) << 16) |
740 1.8.2.2 nathanw ((mode->hsync_start >> 3) - 1);
741 1.8.2.2 nathanw
742 1.8.2.2 nathanw crtc->v_total_disp = ((mode->vdisplay - 1) << 16) |
743 1.8.2.2 nathanw (mode->vtotal - 1);
744 1.8.2.2 nathanw crtc->v_sync_strt_wid =
745 1.8.2.2 nathanw ((mode->vsync_end - mode->vsync_start) << 16) |
746 1.8.2.2 nathanw (mode->vsync_start - 1);
747 1.8.2.2 nathanw
748 1.8.2.2 nathanw if (mode->flags & VID_NVSYNC)
749 1.8.2.2 nathanw crtc->v_sync_strt_wid |= CRTC_VSYNC_NEG;
750 1.8.2.2 nathanw
751 1.8.2.2 nathanw switch (sc->bits_per_pixel) {
752 1.8.2.2 nathanw case 8:
753 1.8.2.2 nathanw crtc->color_depth = CRTC_PIX_WIDTH_8BPP;
754 1.8.2.2 nathanw break;
755 1.8.2.2 nathanw case 16:
756 1.8.2.2 nathanw crtc->color_depth = CRTC_PIX_WIDTH_16BPP;
757 1.8.2.2 nathanw break;
758 1.8.2.2 nathanw case 32:
759 1.8.2.2 nathanw crtc->color_depth = CRTC_PIX_WIDTH_32BPP;
760 1.8.2.2 nathanw break;
761 1.8.2.2 nathanw }
762 1.8.2.2 nathanw
763 1.8.2.2 nathanw crtc->gen_cntl = 0;
764 1.8.2.2 nathanw if (mode->flags & VID_INTERLACE)
765 1.8.2.2 nathanw crtc->gen_cntl |= CRTC_INTERLACE_EN;
766 1.8.2.2 nathanw if (mode->flags & VID_CSYNC)
767 1.8.2.2 nathanw crtc->gen_cntl |= CRTC_CSYNC_EN;
768 1.8.2.2 nathanw
769 1.8.2.2 nathanw crtc->dot_clock = mode->dot_clock;
770 1.8.2.2 nathanw
771 1.8.2.2 nathanw return 0;
772 1.8.2.2 nathanw }
773 1.8.2.2 nathanw
774 1.8.2.2 nathanw void
775 1.8.2.2 nathanw mach64_set_crtcregs(struct mach64_softc *sc, struct mach64_crtcregs *crtc)
776 1.8.2.2 nathanw {
777 1.8.2.2 nathanw
778 1.8.2.2 nathanw mach64_set_pll(sc, crtc->dot_clock);
779 1.8.2.2 nathanw
780 1.8.2.2 nathanw if (sc->has_dsp)
781 1.8.2.2 nathanw mach64_set_dsp(sc);
782 1.8.2.2 nathanw
783 1.8.2.2 nathanw regw(sc, CRTC_H_TOTAL_DISP, crtc->h_total_disp);
784 1.8.2.2 nathanw regw(sc, CRTC_H_SYNC_STRT_WID, crtc->h_sync_strt_wid);
785 1.8.2.2 nathanw regw(sc, CRTC_V_TOTAL_DISP, crtc->v_total_disp);
786 1.8.2.2 nathanw regw(sc, CRTC_V_SYNC_STRT_WID, crtc->v_sync_strt_wid);
787 1.8.2.2 nathanw
788 1.8.2.2 nathanw regw(sc, CRTC_VLINE_CRNT_VLINE, 0);
789 1.8.2.2 nathanw
790 1.8.2.2 nathanw regw(sc, CRTC_OFF_PITCH, (sc->virt_x >> 3) << 22);
791 1.8.2.2 nathanw
792 1.8.2.2 nathanw regw(sc, CRTC_GEN_CNTL, crtc->gen_cntl | crtc->color_depth |
793 1.8.2.2 nathanw CRTC_EXT_DISP_EN | CRTC_EXT_EN);
794 1.8.2.2 nathanw }
795 1.8.2.2 nathanw
796 1.8.2.2 nathanw int
797 1.8.2.2 nathanw mach64_modeswitch(struct mach64_softc *sc, struct videomode *mode)
798 1.8.2.2 nathanw {
799 1.8.2.2 nathanw struct mach64_crtcregs crtc;
800 1.8.2.2 nathanw
801 1.8.2.2 nathanw if (mach64_calc_crtcregs(sc, &crtc, mode))
802 1.8.2.2 nathanw return 1;
803 1.8.2.2 nathanw
804 1.8.2.2 nathanw mach64_set_crtcregs(sc, &crtc);
805 1.8.2.2 nathanw return 0;
806 1.8.2.2 nathanw }
807 1.8.2.2 nathanw
808 1.8.2.2 nathanw void
809 1.8.2.2 nathanw mach64_reset_engine(struct mach64_softc *sc)
810 1.8.2.2 nathanw {
811 1.8.2.2 nathanw
812 1.8.2.2 nathanw /* Reset engine.*/
813 1.8.2.2 nathanw regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) & ~GUI_ENGINE_ENABLE);
814 1.8.2.2 nathanw
815 1.8.2.2 nathanw /* Enable engine. */
816 1.8.2.2 nathanw regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) | GUI_ENGINE_ENABLE);
817 1.8.2.2 nathanw
818 1.8.2.2 nathanw /* Ensure engine is not locked up by clearing any FIFO or
819 1.8.2.2 nathanw host errors. */
820 1.8.2.2 nathanw regw(sc, BUS_CNTL, regr(sc, BUS_CNTL) | BUS_HOST_ERR_ACK |
821 1.8.2.2 nathanw BUS_FIFO_ERR_ACK);
822 1.8.2.2 nathanw }
823 1.8.2.2 nathanw
824 1.8.2.2 nathanw void
825 1.8.2.2 nathanw mach64_init_engine(struct mach64_softc *sc)
826 1.8.2.2 nathanw {
827 1.8.2.2 nathanw u_int32_t pitch_value;
828 1.8.2.2 nathanw
829 1.8.2.2 nathanw pitch_value = sc->virt_x;
830 1.8.2.2 nathanw
831 1.8.2.2 nathanw if (sc->bits_per_pixel == 24)
832 1.8.2.2 nathanw pitch_value *= 3;
833 1.8.2.2 nathanw
834 1.8.2.2 nathanw mach64_reset_engine(sc);
835 1.8.2.2 nathanw
836 1.8.2.2 nathanw wait_for_fifo(sc, 14);
837 1.8.2.2 nathanw
838 1.8.2.2 nathanw regw(sc, CONTEXT_MASK, 0xffffffff);
839 1.8.2.2 nathanw
840 1.8.2.2 nathanw regw(sc, DST_OFF_PITCH, (pitch_value / 8) << 22);
841 1.8.2.2 nathanw
842 1.8.2.2 nathanw regw(sc, DST_Y_X, 0);
843 1.8.2.2 nathanw regw(sc, DST_HEIGHT, 0);
844 1.8.2.2 nathanw regw(sc, DST_BRES_ERR, 0);
845 1.8.2.2 nathanw regw(sc, DST_BRES_INC, 0);
846 1.8.2.2 nathanw regw(sc, DST_BRES_DEC, 0);
847 1.8.2.2 nathanw
848 1.8.2.2 nathanw regw(sc, DST_CNTL, DST_LAST_PEL | DST_X_LEFT_TO_RIGHT |
849 1.8.2.2 nathanw DST_Y_TOP_TO_BOTTOM);
850 1.8.2.2 nathanw
851 1.8.2.2 nathanw regw(sc, SRC_OFF_PITCH, (pitch_value / 8) << 22);
852 1.8.2.2 nathanw
853 1.8.2.2 nathanw regw(sc, SRC_Y_X, 0);
854 1.8.2.2 nathanw regw(sc, SRC_HEIGHT1_WIDTH1, 1);
855 1.8.2.2 nathanw regw(sc, SRC_Y_X_START, 0);
856 1.8.2.2 nathanw regw(sc, SRC_HEIGHT2_WIDTH2, 1);
857 1.8.2.2 nathanw
858 1.8.2.2 nathanw regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
859 1.8.2.2 nathanw
860 1.8.2.2 nathanw wait_for_fifo(sc, 13);
861 1.8.2.2 nathanw regw(sc, HOST_CNTL, 0);
862 1.8.2.2 nathanw
863 1.8.2.2 nathanw regw(sc, PAT_REG0, 0);
864 1.8.2.2 nathanw regw(sc, PAT_REG1, 0);
865 1.8.2.2 nathanw regw(sc, PAT_CNTL, 0);
866 1.8.2.2 nathanw
867 1.8.2.2 nathanw regw(sc, SC_LEFT, 0);
868 1.8.2.2 nathanw regw(sc, SC_TOP, 0);
869 1.8.2.2 nathanw regw(sc, SC_BOTTOM, default_mode.vdisplay - 1);
870 1.8.2.2 nathanw regw(sc, SC_RIGHT, pitch_value - 1);
871 1.8.2.2 nathanw
872 1.8.2.2 nathanw regw(sc, DP_BKGD_CLR, 0);
873 1.8.2.2 nathanw regw(sc, DP_FRGD_CLR, 0xffffffff);
874 1.8.2.2 nathanw regw(sc, DP_WRITE_MASK, 0xffffffff);
875 1.8.2.2 nathanw regw(sc, DP_MIX, (MIX_SRC << 16) | MIX_DST);
876 1.8.2.2 nathanw
877 1.8.2.2 nathanw regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
878 1.8.2.2 nathanw
879 1.8.2.2 nathanw wait_for_fifo(sc, 3);
880 1.8.2.2 nathanw regw(sc, CLR_CMP_CLR, 0);
881 1.8.2.2 nathanw regw(sc, CLR_CMP_MASK, 0xffffffff);
882 1.8.2.2 nathanw regw(sc, CLR_CMP_CNTL, 0);
883 1.8.2.2 nathanw
884 1.8.2.2 nathanw wait_for_fifo(sc, 2);
885 1.8.2.2 nathanw switch (sc->bits_per_pixel) {
886 1.8.2.2 nathanw case 8:
887 1.8.2.2 nathanw regw(sc, DP_PIX_WIDTH, HOST_8BPP | SRC_8BPP | DST_8BPP);
888 1.8.2.2 nathanw regw(sc, DP_CHAIN_MASK, DP_CHAIN_8BPP);
889 1.8.2.2 nathanw regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) & ~DAC_8BIT_EN);
890 1.8.2.2 nathanw break;
891 1.8.2.2 nathanw #if 0
892 1.8.2.2 nathanw case 32:
893 1.8.2.2 nathanw regw(sc, DP_PIX_WIDTH, HOST_32BPP | SRC_32BPP | DST_32BPP);
894 1.8.2.2 nathanw regw(sc, DP_CHAIN_MASK, DP_CHAIN_32BPP);
895 1.8.2.2 nathanw regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
896 1.8.2.2 nathanw break;
897 1.8.2.2 nathanw #endif
898 1.8.2.2 nathanw }
899 1.8.2.2 nathanw
900 1.8.2.2 nathanw wait_for_fifo(sc, 5);
901 1.8.2.2 nathanw regw(sc, CRTC_INT_CNTL, regr(sc, CRTC_INT_CNTL) & ~0x20);
902 1.8.2.2 nathanw regw(sc, GUI_TRAJ_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
903 1.8.2.2 nathanw
904 1.8.2.2 nathanw wait_for_idle(sc);
905 1.8.2.2 nathanw }
906 1.8.2.2 nathanw
907 1.8.2.2 nathanw void
908 1.8.2.2 nathanw mach64_adjust_frame(struct mach64_softc *sc, int x, int y)
909 1.8.2.2 nathanw {
910 1.8.2.2 nathanw int offset;
911 1.8.2.2 nathanw
912 1.8.2.2 nathanw offset = ((x + y * sc->virt_x) * (sc->bits_per_pixel >> 3)) >> 3;
913 1.8.2.2 nathanw
914 1.8.2.2 nathanw regw(sc, CRTC_OFF_PITCH, (regr(sc, CRTC_OFF_PITCH) & 0xfff00000) |
915 1.8.2.2 nathanw offset);
916 1.8.2.2 nathanw }
917 1.8.2.2 nathanw
918 1.8.2.2 nathanw void
919 1.8.2.2 nathanw mach64_set_dsp(struct mach64_softc *sc)
920 1.8.2.2 nathanw {
921 1.8.2.2 nathanw u_int32_t fifo_depth, page_size, dsp_precision, dsp_loop_latency;
922 1.8.2.2 nathanw u_int32_t dsp_off, dsp_on, dsp_xclks_per_qw;
923 1.8.2.2 nathanw u_int32_t xclks_per_qw, y;
924 1.8.2.2 nathanw u_int32_t fifo_off, fifo_on;
925 1.8.2.2 nathanw
926 1.8.2.2 nathanw if (mach64_chip_id == PCI_PRODUCT_ATI_MACH64_VT ||
927 1.8.2.2 nathanw mach64_chip_id == PCI_PRODUCT_ATI_RAGE_II ||
928 1.8.2.2 nathanw mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIP ||
929 1.8.2.2 nathanw mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_PCI ||
930 1.8.2.2 nathanw mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_AGP_B ||
931 1.8.2.2 nathanw mach64_chip_id == PCI_PRODUCT_ATI_RAGE_IIC_AGP_P) {
932 1.8.2.2 nathanw dsp_loop_latency = 0;
933 1.8.2.2 nathanw fifo_depth = 24;
934 1.8.2.2 nathanw } else {
935 1.8.2.2 nathanw dsp_loop_latency = 2;
936 1.8.2.2 nathanw fifo_depth = 32;
937 1.8.2.2 nathanw }
938 1.8.2.2 nathanw
939 1.8.2.2 nathanw dsp_precision = 0;
940 1.8.2.2 nathanw xclks_per_qw = (sc->mclk_fb_div * sc->vclk_post_div * 64 << 11) /
941 1.8.2.2 nathanw (sc->vclk_fb_div * sc->mclk_post_div * sc->bits_per_pixel);
942 1.8.2.2 nathanw y = (xclks_per_qw * fifo_depth) >> 11;
943 1.8.2.2 nathanw while (y) {
944 1.8.2.2 nathanw y >>= 1;
945 1.8.2.2 nathanw dsp_precision++;
946 1.8.2.2 nathanw }
947 1.8.2.2 nathanw dsp_precision -= 5;
948 1.8.2.2 nathanw fifo_off = ((xclks_per_qw * (fifo_depth - 1)) >> 5) + (3 << 6);
949 1.8.2.2 nathanw
950 1.8.2.2 nathanw switch (sc->memtype) {
951 1.8.2.2 nathanw case DRAM:
952 1.8.2.2 nathanw case EDO_DRAM:
953 1.8.2.2 nathanw case PSEUDO_EDO:
954 1.8.2.2 nathanw if (sc->memsize > 1024) {
955 1.8.2.2 nathanw page_size = 9;
956 1.8.2.2 nathanw dsp_loop_latency += 6;
957 1.8.2.2 nathanw } else {
958 1.8.2.2 nathanw page_size = 10;
959 1.8.2.2 nathanw if (sc->memtype == DRAM)
960 1.8.2.2 nathanw dsp_loop_latency += 8;
961 1.8.2.2 nathanw else
962 1.8.2.2 nathanw dsp_loop_latency += 7;
963 1.8.2.2 nathanw }
964 1.8.2.2 nathanw break;
965 1.8.2.2 nathanw case SDRAM:
966 1.8.2.2 nathanw case SGRAM:
967 1.8.2.2 nathanw if (sc->memsize > 1024) {
968 1.8.2.2 nathanw page_size = 8;
969 1.8.2.2 nathanw dsp_loop_latency += 8;
970 1.8.2.2 nathanw } else {
971 1.8.2.2 nathanw page_size = 10;
972 1.8.2.2 nathanw dsp_loop_latency += 9;
973 1.8.2.2 nathanw }
974 1.8.2.2 nathanw break;
975 1.8.2.2 nathanw default:
976 1.8.2.2 nathanw page_size = 10;
977 1.8.2.2 nathanw dsp_loop_latency += 9;
978 1.8.2.2 nathanw break;
979 1.8.2.2 nathanw }
980 1.8.2.2 nathanw
981 1.8.2.2 nathanw if (xclks_per_qw >= (page_size << 11))
982 1.8.2.2 nathanw fifo_on = ((2 * page_size + 1) << 6) + (xclks_per_qw >> 5);
983 1.8.2.2 nathanw else
984 1.8.2.2 nathanw fifo_on = (3 * page_size + 2) << 6;
985 1.8.2.2 nathanw
986 1.8.2.2 nathanw dsp_xclks_per_qw = xclks_per_qw >> dsp_precision;
987 1.8.2.2 nathanw dsp_on = fifo_on >> dsp_precision;
988 1.8.2.2 nathanw dsp_off = fifo_off >> dsp_precision;
989 1.8.2.2 nathanw
990 1.8.2.2 nathanw #ifdef MACH64_DEBUG
991 1.8.2.2 nathanw printf("dsp_xclks_per_qw = %d, dsp_on = %d, dsp_off = %d,\n"
992 1.8.2.2 nathanw "dsp_precision = %d, dsp_loop_latency = %d,\n"
993 1.8.2.2 nathanw "mclk_fb_div = %d, vclk_fb_div = %d,\n"
994 1.8.2.2 nathanw "mclk_post_div = %d, vclk_post_div = %d\n",
995 1.8.2.2 nathanw dsp_xclks_per_qw, dsp_on, dsp_off, dsp_precision, dsp_loop_latency,
996 1.8.2.2 nathanw sc->mclk_fb_div, sc->vclk_fb_div,
997 1.8.2.2 nathanw sc->mclk_post_div, sc->vclk_post_div);
998 1.8.2.2 nathanw #endif
999 1.8.2.2 nathanw
1000 1.8.2.2 nathanw regw(sc, DSP_ON_OFF, ((dsp_on << 16) & DSP_ON) | (dsp_off & DSP_OFF));
1001 1.8.2.2 nathanw regw(sc, DSP_CONFIG, ((dsp_precision << 20) & DSP_PRECISION) |
1002 1.8.2.2 nathanw ((dsp_loop_latency << 16) & DSP_LOOP_LATENCY) |
1003 1.8.2.2 nathanw (dsp_xclks_per_qw & DSP_XCLKS_PER_QW));
1004 1.8.2.2 nathanw }
1005 1.8.2.2 nathanw
1006 1.8.2.2 nathanw void
1007 1.8.2.2 nathanw mach64_set_pll(struct mach64_softc *sc, int clock)
1008 1.8.2.2 nathanw {
1009 1.8.2.2 nathanw int q;
1010 1.8.2.2 nathanw
1011 1.8.2.2 nathanw q = (clock * sc->ref_div * 100) / (2 * sc->ref_freq);
1012 1.8.2.2 nathanw #ifdef MACH64_DEBUG
1013 1.8.2.2 nathanw printf("q = %d\n", q);
1014 1.8.2.2 nathanw #endif
1015 1.8.2.2 nathanw if (q > 25500) {
1016 1.8.2.2 nathanw printf("Warning: q > 25500\n");
1017 1.8.2.2 nathanw q = 25500;
1018 1.8.2.2 nathanw sc->vclk_post_div = 1;
1019 1.8.2.2 nathanw sc->log2_vclk_post_div = 0;
1020 1.8.2.2 nathanw } else if (q > 12750) {
1021 1.8.2.2 nathanw sc->vclk_post_div = 1;
1022 1.8.2.2 nathanw sc->log2_vclk_post_div = 0;
1023 1.8.2.2 nathanw } else if (q > 6350) {
1024 1.8.2.2 nathanw sc->vclk_post_div = 2;
1025 1.8.2.2 nathanw sc->log2_vclk_post_div = 1;
1026 1.8.2.2 nathanw } else if (q > 3150) {
1027 1.8.2.2 nathanw sc->vclk_post_div = 4;
1028 1.8.2.2 nathanw sc->log2_vclk_post_div = 2;
1029 1.8.2.2 nathanw } else if (q >= 1600) {
1030 1.8.2.2 nathanw sc->vclk_post_div = 8;
1031 1.8.2.2 nathanw sc->log2_vclk_post_div = 3;
1032 1.8.2.2 nathanw } else {
1033 1.8.2.2 nathanw printf("Warning: q < 1600\n");
1034 1.8.2.2 nathanw sc->vclk_post_div = 8;
1035 1.8.2.2 nathanw sc->log2_vclk_post_div = 3;
1036 1.8.2.2 nathanw }
1037 1.8.2.2 nathanw sc->vclk_fb_div = q * sc->vclk_post_div / 100;
1038 1.8.2.2 nathanw
1039 1.8.2.2 nathanw regwb_pll(sc, MCLK_FB_DIV, sc->mclk_fb_div);
1040 1.8.2.2 nathanw regwb_pll(sc, VCLK_POST_DIV, sc->log2_vclk_post_div);
1041 1.8.2.2 nathanw regwb_pll(sc, VCLK0_FB_DIV, sc->vclk_fb_div);
1042 1.8.2.2 nathanw }
1043 1.8.2.2 nathanw
1044 1.8.2.2 nathanw void
1045 1.8.2.2 nathanw mach64_init_lut(struct mach64_softc *sc)
1046 1.8.2.2 nathanw {
1047 1.8.2.2 nathanw int i;
1048 1.8.2.2 nathanw
1049 1.8.2.2 nathanw regwb(sc, DAC_REGS, 0);
1050 1.8.2.2 nathanw
1051 1.8.2.2 nathanw for (i = 0; i < 16; i++) {
1052 1.8.2.2 nathanw regwb(sc, DAC_REGS + 1, mach64_cmap[i * 3]);
1053 1.8.2.2 nathanw regwb(sc, DAC_REGS + 1, mach64_cmap[i * 3 + 1]);
1054 1.8.2.2 nathanw regwb(sc, DAC_REGS + 1, mach64_cmap[i + 3 + 2]);
1055 1.8.2.2 nathanw }
1056 1.8.2.2 nathanw }
1057 1.8.2.2 nathanw
1058 1.8.2.2 nathanw void
1059 1.8.2.2 nathanw mach64_switch_screen(struct mach64_softc *sc)
1060 1.8.2.2 nathanw {
1061 1.8.2.2 nathanw struct mach64screen *scr, *oldscr;
1062 1.8.2.2 nathanw const struct wsscreen_descr *type;
1063 1.8.2.2 nathanw
1064 1.8.2.2 nathanw scr = sc->wanted;
1065 1.8.2.2 nathanw if (!scr) {
1066 1.8.2.2 nathanw printf("mach64_switch_screen: disappeared\n");
1067 1.8.2.2 nathanw (*sc->switchcb)(sc->switchcbarg, EIO, 0);
1068 1.8.2.2 nathanw return;
1069 1.8.2.2 nathanw }
1070 1.8.2.2 nathanw type = scr->type;
1071 1.8.2.2 nathanw oldscr = sc->active; /* can be NULL! */
1072 1.8.2.2 nathanw #ifdef DIAGNOSTIC
1073 1.8.2.2 nathanw if (oldscr) {
1074 1.8.2.2 nathanw if (!oldscr->active)
1075 1.8.2.2 nathanw panic("mach64_switch_screen: not active");
1076 1.8.2.2 nathanw if (oldscr->type != vc->currenttype)
1077 1.8.2.2 nathanw panic("mach64_switch_screen: bad type");
1078 1.8.2.2 nathanw }
1079 1.8.2.2 nathanw #endif
1080 1.8.2.2 nathanw if (scr == oldscr)
1081 1.8.2.2 nathanw return;
1082 1.8.2.2 nathanw
1083 1.8.2.2 nathanw #ifdef DIAGNOSTIC
1084 1.8.2.2 nathanw if (scr->active)
1085 1.8.2.2 nathanw panic("mach64_switch_screen: active");
1086 1.8.2.2 nathanw #endif
1087 1.8.2.2 nathanw
1088 1.8.2.2 nathanw if (oldscr)
1089 1.8.2.2 nathanw oldscr->active = 0;
1090 1.8.2.2 nathanw
1091 1.8.2.2 nathanw if (sc->currenttype != type) {
1092 1.8.2.2 nathanw mach64_set_screentype(sc, type);
1093 1.8.2.2 nathanw sc->currenttype = type;
1094 1.8.2.2 nathanw }
1095 1.8.2.2 nathanw
1096 1.8.2.2 nathanw scr->dispoffset = scr->mindispoffset;
1097 1.8.2.2 nathanw
1098 1.8.2.2 nathanw if (!oldscr || (scr->dispoffset != oldscr->dispoffset)) {
1099 1.8.2.2 nathanw
1100 1.8.2.2 nathanw }
1101 1.8.2.2 nathanw
1102 1.8.2.2 nathanw /* Clear the entire screen. */
1103 1.8.2.2 nathanw
1104 1.8.2.2 nathanw scr->active = 1;
1105 1.8.2.2 nathanw mach64_restore_screen(scr, type, scr->mem);
1106 1.8.2.2 nathanw
1107 1.8.2.2 nathanw sc->active = scr;
1108 1.8.2.2 nathanw
1109 1.8.2.2 nathanw mach64_cursor(scr, scr->cursoron, scr->cursorrow, scr->cursorcol);
1110 1.8.2.2 nathanw
1111 1.8.2.2 nathanw sc->wanted = 0;
1112 1.8.2.2 nathanw if (sc->switchcb)
1113 1.8.2.2 nathanw (*sc->switchcb)(sc->switchcbarg, 0, 0);
1114 1.8.2.2 nathanw }
1115 1.8.2.2 nathanw
1116 1.8.2.2 nathanw void
1117 1.8.2.2 nathanw mach64_restore_screen(struct mach64screen *scr,
1118 1.8.2.2 nathanw const struct wsscreen_descr *type, u_int16_t *mem)
1119 1.8.2.2 nathanw {
1120 1.8.2.2 nathanw
1121 1.8.2.2 nathanw }
1122 1.8.2.2 nathanw
1123 1.8.2.2 nathanw int
1124 1.8.2.2 nathanw mach64_set_screentype(struct mach64_softc *sc, const struct wsscreen_descr *des)
1125 1.8.2.2 nathanw {
1126 1.8.2.2 nathanw struct mach64_crtcregs regs;
1127 1.8.2.2 nathanw
1128 1.8.2.2 nathanw if (mach64_calc_crtcregs(sc, ®s,
1129 1.8.2.2 nathanw (struct videomode *)des->modecookie))
1130 1.8.2.2 nathanw return 1;
1131 1.8.2.2 nathanw
1132 1.8.2.2 nathanw mach64_set_crtcregs(sc, ®s);
1133 1.8.2.2 nathanw return 0;
1134 1.8.2.2 nathanw }
1135 1.8.2.2 nathanw
1136 1.8.2.2 nathanw int
1137 1.8.2.2 nathanw mach64_is_console(struct pci_attach_args *pa)
1138 1.8.2.2 nathanw {
1139 1.8.2.2 nathanw #ifdef __sparc__
1140 1.8.2.2 nathanw int node;
1141 1.8.2.2 nathanw
1142 1.8.2.2 nathanw node = PCITAG_NODE(pa->pa_tag);
1143 1.8.2.2 nathanw if (node == -1)
1144 1.8.2.2 nathanw return 0;
1145 1.8.2.2 nathanw
1146 1.8.2.2 nathanw return (node == OF_instance_to_package(OF_stdout()));
1147 1.8.2.2 nathanw #else
1148 1.8.2.2 nathanw return 1;
1149 1.8.2.2 nathanw #endif
1150 1.8.2.2 nathanw }
1151 1.8.2.2 nathanw
1152 1.8.2.2 nathanw /*
1153 1.8.2.2 nathanw * wsdisplay_emulops
1154 1.8.2.2 nathanw */
1155 1.8.2.2 nathanw
1156 1.8.2.2 nathanw void
1157 1.8.2.2 nathanw mach64_cursor(void *cookie, int on, int row, int col)
1158 1.8.2.2 nathanw {
1159 1.8.2.2 nathanw
1160 1.8.2.2 nathanw }
1161 1.8.2.2 nathanw
1162 1.8.2.2 nathanw #if 0
1163 1.8.2.2 nathanw int
1164 1.8.2.2 nathanw mach64_mapchar(void *cookie, int uni, u_int *index)
1165 1.8.2.2 nathanw {
1166 1.8.2.2 nathanw
1167 1.8.2.2 nathanw return 0;
1168 1.8.2.2 nathanw }
1169 1.8.2.2 nathanw
1170 1.8.2.2 nathanw void
1171 1.8.2.2 nathanw mach64_putchar(void *cookie, int row, int col, u_int c, long attr)
1172 1.8.2.2 nathanw {
1173 1.8.2.2 nathanw
1174 1.8.2.2 nathanw }
1175 1.8.2.2 nathanw
1176 1.8.2.2 nathanw void
1177 1.8.2.2 nathanw mach64_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
1178 1.8.2.2 nathanw {
1179 1.8.2.2 nathanw
1180 1.8.2.2 nathanw }
1181 1.8.2.2 nathanw
1182 1.8.2.2 nathanw void
1183 1.8.2.2 nathanw mach64_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
1184 1.8.2.2 nathanw {
1185 1.8.2.2 nathanw
1186 1.8.2.2 nathanw }
1187 1.8.2.2 nathanw
1188 1.8.2.2 nathanw void
1189 1.8.2.2 nathanw mach64_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
1190 1.8.2.2 nathanw {
1191 1.8.2.2 nathanw
1192 1.8.2.2 nathanw }
1193 1.8.2.2 nathanw
1194 1.8.2.2 nathanw int
1195 1.8.2.2 nathanw mach64_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
1196 1.8.2.2 nathanw {
1197 1.8.2.2 nathanw
1198 1.8.2.2 nathanw return 0;
1199 1.8.2.2 nathanw }
1200 1.8.2.2 nathanw #endif
1201 1.8.2.2 nathanw
1202 1.8.2.2 nathanw void
1203 1.8.2.2 nathanw mach64_eraserows(void *cookie, int row, int nrows, long fillattr)
1204 1.8.2.2 nathanw {
1205 1.8.2.2 nathanw
1206 1.8.2.2 nathanw }
1207 1.8.2.2 nathanw
1208 1.8.2.2 nathanw /*
1209 1.8.2.2 nathanw * wsdisplay_accessops
1210 1.8.2.2 nathanw */
1211 1.8.2.2 nathanw
1212 1.8.2.2 nathanw int
1213 1.8.2.2 nathanw mach64_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
1214 1.8.2.2 nathanw {
1215 1.8.2.2 nathanw
1216 1.8.2.2 nathanw return ENOTTY;
1217 1.8.2.2 nathanw }
1218 1.8.2.2 nathanw
1219 1.8.2.2 nathanw paddr_t
1220 1.8.2.2 nathanw mach64_mmap(void *v, off_t offset, int prot)
1221 1.8.2.2 nathanw {
1222 1.8.2.2 nathanw
1223 1.8.2.2 nathanw return -1;
1224 1.8.2.2 nathanw }
1225 1.8.2.2 nathanw
1226 1.8.2.2 nathanw int
1227 1.8.2.2 nathanw mach64_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
1228 1.8.2.2 nathanw int *curxp, int *curyp, long *defattrp)
1229 1.8.2.2 nathanw {
1230 1.8.2.2 nathanw struct mach64_softc *sc = v;
1231 1.8.2.2 nathanw struct mach64screen *scr;
1232 1.8.2.2 nathanw
1233 1.8.2.2 nathanw scr = malloc(sizeof(struct mach64screen), M_DEVBUF, M_WAITOK|M_ZERO);
1234 1.8.2.2 nathanw mach64_init_screen(sc, scr, type, 0, defattrp, sc->active == NULL);
1235 1.8.2.2 nathanw rasops_init(&scr->ri, mach64_console_screen.ri.ri_height / 16,
1236 1.8.2.2 nathanw mach64_console_screen.ri.ri_width / 8);
1237 1.8.2.2 nathanw
1238 1.8.2.2 nathanw scr->mem = malloc(type->ncols * type->nrows * 2, M_DEVBUF,
1239 1.8.2.2 nathanw M_WAITOK);
1240 1.8.2.2 nathanw mach64_eraserows(sc, 0, type->nrows, *defattrp);
1241 1.8.2.2 nathanw if (sc->active == NULL) {
1242 1.8.2.2 nathanw scr->active = 1;
1243 1.8.2.2 nathanw sc->active = scr;
1244 1.8.2.2 nathanw sc->currenttype = type;
1245 1.8.2.2 nathanw }
1246 1.8.2.2 nathanw
1247 1.8.2.2 nathanw *cookiep = scr;
1248 1.8.2.2 nathanw *curxp = scr->cursorcol;
1249 1.8.2.2 nathanw *curyp = scr->cursorrow;
1250 1.8.2.2 nathanw
1251 1.8.2.2 nathanw return 0;
1252 1.8.2.2 nathanw }
1253 1.8.2.2 nathanw
1254 1.8.2.2 nathanw void
1255 1.8.2.2 nathanw mach64_free_screen(void *v, void *cookie)
1256 1.8.2.2 nathanw {
1257 1.8.2.2 nathanw struct mach64_softc *sc = v;
1258 1.8.2.2 nathanw struct mach64screen *scr = cookie;
1259 1.8.2.2 nathanw
1260 1.8.2.2 nathanw LIST_REMOVE(scr, next);
1261 1.8.2.2 nathanw if (scr != &mach64_console_screen)
1262 1.8.2.2 nathanw free(scr, M_DEVBUF);
1263 1.8.2.2 nathanw else
1264 1.8.2.2 nathanw panic("mach64_free_screen: console");
1265 1.8.2.2 nathanw
1266 1.8.2.2 nathanw if (sc->active == scr)
1267 1.8.2.2 nathanw sc->active = 0;
1268 1.8.2.2 nathanw }
1269 1.8.2.2 nathanw
1270 1.8.2.2 nathanw int
1271 1.8.2.2 nathanw mach64_show_screen(void *v, void *cookie, int waitok,
1272 1.8.2.2 nathanw void (*cb)(void *, int, int), void *cbarg)
1273 1.8.2.2 nathanw {
1274 1.8.2.2 nathanw struct mach64_softc *sc = v;
1275 1.8.2.2 nathanw struct mach64screen *scr, *oldscr;
1276 1.8.2.2 nathanw
1277 1.8.2.2 nathanw scr = cookie;
1278 1.8.2.2 nathanw oldscr = sc->active;
1279 1.8.2.2 nathanw if (scr == oldscr)
1280 1.8.2.2 nathanw return 0;
1281 1.8.2.2 nathanw
1282 1.8.2.2 nathanw sc->wanted = scr;
1283 1.8.2.2 nathanw sc->switchcb = cb;
1284 1.8.2.2 nathanw sc->switchcbarg = cbarg;
1285 1.8.2.2 nathanw if (cb) {
1286 1.8.2.2 nathanw callout_reset(&sc->switch_callout, 0,
1287 1.8.2.2 nathanw (void(*)(void *))mach64_switch_screen, sc);
1288 1.8.2.2 nathanw return EAGAIN;
1289 1.8.2.2 nathanw }
1290 1.8.2.2 nathanw
1291 1.8.2.2 nathanw mach64_switch_screen(sc);
1292 1.8.2.2 nathanw
1293 1.8.2.2 nathanw return 0;
1294 1.8.2.2 nathanw }
1295 1.8.2.2 nathanw
1296 1.8.2.2 nathanw #if 0
1297 1.8.2.2 nathanw int
1298 1.8.2.2 nathanw mach64_load_font(void *v, void *cookie, struct wsdisplay_font *data)
1299 1.8.2.2 nathanw {
1300 1.8.2.2 nathanw
1301 1.8.2.2 nathanw return 0;
1302 1.8.2.2 nathanw }
1303 1.8.2.2 nathanw #endif
1304