2 * ATI Rage XL Initialization. Support for Xpert98 and Victoria
5 * Copyright (C) 2002 MontaVista Software Inc.
6 * Author: MontaVista Software, Inc.
7 * stevel@mvista.com or source@mvista.com
8 * Copyright (C) 2004 Tyan Computer.
9 * Auther: Yinghai Lu yhlu@tyan.com
11 * This code is distributed without warranty under the GPL v2 (see COPYING) *
18 #include <console/console.h>
19 #include <device/device.h>
20 #include <device/pci.h>
21 #include <device/pci_ids.h>
22 #include <device/pci_ops.h>
27 #include "mach64_ct.c"
29 #define MPLL_GAIN 0xad
30 #define VPLL_GAIN 0xd5
38 //static struct aty_pll_ops aty_pll_ct;
40 #define DEFAULT_CARD XPERT98
41 static int xl_card = DEFAULT_CARD;
43 static const struct xl_card_cfg_t {
44 int ref_crystal; // 10^4 Hz
53 u32 custom_macro_cntl;
56 } card_cfg[NUM_XL_CARDS] = {
58 { 2700, SDRAM, 0x800000,
59 0x10757A3B, 0x64000C81, 0x00110202, 0x7b33A040,
60 0x82010102, 0x48803800, 0x005E0179,
64 { 1432, WRAM, 0x800000,
65 0x00165A2B, 0xE0000CF1, 0x00200213, 0x7333A001,
66 0x8000000A, 0x48833800, 0x007F0779,
76 static const lcd_tbl_t lcd_tbl[] = {
92 static inline u32 aty_ld_lcd(u8 lcd_reg, struct fb_info_aty *info)
94 aty_st_8(LCD_INDEX, lcd_reg, info);
95 return aty_ld_le32(LCD_DATA, info);
98 static inline void aty_st_lcd(u8 lcd_reg, u32 val,
99 struct fb_info_aty *info)
101 aty_st_8(LCD_INDEX, lcd_reg, info);
102 aty_st_le32(LCD_DATA, val, info);
105 static void reset_gui(struct fb_info_aty *info)
107 aty_st_8(GEN_TEST_CNTL+1, 0x01, info);
108 aty_st_8(GEN_TEST_CNTL+1, 0x00, info);
109 aty_st_8(GEN_TEST_CNTL+1, 0x02, info);
114 static void reset_sdram(struct fb_info_aty *info)
118 temp = aty_ld_8(EXT_MEM_CNTL, info);
120 aty_st_8(EXT_MEM_CNTL, temp, info); // MEM_SDRAM_RESET = 1b
122 aty_st_8(EXT_MEM_CNTL, temp, info); // MEM_CYC_TEST = 10b
124 aty_st_8(EXT_MEM_CNTL, temp, info); // MEM_CYC_TEST = 11b
127 aty_st_8(EXT_MEM_CNTL, temp, info); // MEM_CYC_TEST = 00b
129 aty_st_8(EXT_MEM_CNTL, temp, info); // MEM_SDRAM_REST = 0b
133 static void init_dll(struct fb_info_aty *info)
136 aty_st_pll(PLL_GEN_CNTL,
137 aty_ld_pll(PLL_GEN_CNTL, info) & 0x7f,
141 aty_st_pll(DLL_CNTL, 0x82, info);
142 aty_st_pll(DLL_CNTL, 0xE2, info);
144 aty_st_pll(DLL_CNTL, 0x82, info);
148 static void reset_clocks(struct fb_info_aty *info, struct pll_ct *pll,
152 aty_st_pll(MCLK_FB_DIV, pll->mclk_fb_div, info);
153 aty_st_pll(SCLK_FB_DIV, pll->sclk_fb_div, info);
157 aty_st_8(GEN_TEST_CNTL+1, 0x00, info);
159 aty_st_8(CRTC_GEN_CNTL+3, 0x04, info);
162 aty_st_8(CRTC_GEN_CNTL+3,
163 hsync_enb ? 0x00 : 0x04, info);
165 aty_st_pll(SPLL_CNTL2, pll->spll_cntl2, info);
166 aty_st_pll(PLL_GEN_CNTL, pll->pll_gen_cntl, info);
167 aty_st_pll(PLL_VCLK_CNTL, pll->pll_vclk_cntl, info);
170 static int atyfb_xl_init(struct fb_info_aty *info)
175 const struct xl_card_cfg_t * card = &card_cfg[xl_card];
177 aty_st_8(CONFIG_STAT0, 0x85, info);
181 * The following needs to be set before the call
182 * to var_to_pll() below. They'll be re-set again
183 * to the same values in aty_init().
185 info->ref_clk_per = 100000000UL/card->ref_crystal;
186 info->ram_type = card->mem_type;
187 info->total_vram = card->mem_size;
188 if (xl_card == VICTORIA) {
189 // the MCLK, XCLK are 120MHz on victoria card
190 info->mclk_per = 1000000/120;
191 info->xclk_per = 1000000/120;
192 info->features &= ~M64F_MFB_TIMES_4;
196 * Calculate mclk and xclk dividers, etc. The passed
197 * pixclock and bpp values don't matter yet, the vclk
198 * isn't programmed until later.
201 if ((err = aty_var_to_pll_ct(info, 39726, 8, &pll))) return err;
202 // if ((err = aty_pll_ct.var_to_pll(info, 39726, 8, &pll))) return err;
205 aty_st_pll(LVDS_CNTL0, 0x00, info);
206 aty_st_pll(DLL2_CNTL, card->dll2_cntl, info);
207 aty_st_pll(V2PLL_CNTL, 0x10, info);
208 aty_st_pll(MPLL_CNTL, MPLL_GAIN, info);
209 aty_st_pll(VPLL_CNTL, VPLL_GAIN, info);
210 aty_st_pll(PLL_VCLK_CNTL, 0x00, info);
211 aty_st_pll(VFC_CNTL, 0x1B, info);
212 aty_st_pll(PLL_REF_DIV, pll.ct.pll_ref_div, info);
213 aty_st_pll(PLL_EXT_CNTL, pll.ct.pll_ext_cntl, info);
214 aty_st_pll(SPLL_CNTL2, 0x03, info);
215 aty_st_pll(PLL_GEN_CNTL, 0x44, info);
217 reset_clocks(info, &pll.ct, 0);
220 aty_st_pll(VCLK_POST_DIV, 0x03, info);
221 aty_st_pll(VCLK0_FB_DIV, 0xDA, info);
222 aty_st_pll(VCLK_POST_DIV, 0x0F, info);
223 aty_st_pll(VCLK1_FB_DIV, 0xF5, info);
224 aty_st_pll(VCLK_POST_DIV, 0x3F, info);
225 aty_st_pll(PLL_EXT_CNTL, 0x40 | pll.ct.pll_ext_cntl, info);
226 aty_st_pll(VCLK2_FB_DIV, 0x00, info);
227 aty_st_pll(VCLK_POST_DIV, 0xFF, info);
228 aty_st_pll(PLL_EXT_CNTL, 0xC0 | pll.ct.pll_ext_cntl, info);
229 aty_st_pll(VCLK3_FB_DIV, 0x00, info);
231 aty_st_8(BUS_CNTL, 0x01, info);
232 aty_st_le32(BUS_CNTL, card->bus_cntl | 0x08000000, info);
234 aty_st_le32(CRTC_GEN_CNTL, 0x04000200, info);
235 aty_st_le16(CONFIG_STAT0, 0x0020, info);
236 aty_st_le32(MEM_CNTL, 0x10151A33, info);
237 aty_st_le32(EXT_MEM_CNTL, 0xE0000C01, info);
238 aty_st_le16(CRTC_GEN_CNTL+2, 0x0000, info);
239 aty_st_le32(DAC_CNTL, card->dac_cntl, info);
240 aty_st_le16(GEN_TEST_CNTL, 0x0100, info);
241 aty_st_le32(CUSTOM_MACRO_CNTL, 0x003C0171, info);
242 aty_st_le32(MEM_BUF_CNTL, 0x00382848, info);
244 aty_st_le32(HW_DEBUG, card->hw_debug, info);
245 aty_st_le16(MEM_ADDR_CONFIG, 0x0000, info);
246 aty_st_le16(GP_IO+2, 0x0000, info);
247 aty_st_le16(GEN_TEST_CNTL, 0x0000, info);
248 aty_st_le16(EXT_DAC_REGS+2, 0x0000, info);
249 aty_st_le32(CRTC_INT_CNTL, 0x00000000, info);
250 aty_st_le32(TIMER_CONFIG, 0x00000000, info);
251 aty_st_le32(0xEC, 0x00000000, info);
252 aty_st_le32(0xFC, 0x00000000, info);
254 for (i=0; i<sizeof(lcd_tbl)/sizeof(lcd_tbl_t); i++) {
255 aty_st_lcd(lcd_tbl[i].lcd_reg, lcd_tbl[i].val, info);
258 aty_st_le16(CONFIG_STAT0, 0x00A4, info);
261 aty_st_8(BUS_CNTL+1, 0xA0, info);
264 reset_clocks(info, &pll.ct, 1);
267 // something about power management
268 aty_st_8(LCD_INDEX, 0x08, info);
269 aty_st_8(LCD_DATA, 0x0A, info);
270 aty_st_8(LCD_INDEX, 0x08, info);
271 aty_st_8(LCD_DATA+3, 0x02, info);
272 aty_st_8(LCD_INDEX, 0x08, info);
273 aty_st_8(LCD_DATA, 0x0B, info);
276 // enable display requests, enable CRTC
277 aty_st_8(CRTC_GEN_CNTL+3, 0x02, info);
279 aty_st_8(CRTC_GEN_CNTL, 0x40, info);
280 // disable display requests, disable CRTC
281 aty_st_8(CRTC_GEN_CNTL+3, 0x04, info);
284 aty_st_pll(PLL_YCLK_CNTL, 0x25, info);
286 aty_st_le16(CUSTOM_MACRO_CNTL, 0x0179, info);
287 aty_st_le16(CUSTOM_MACRO_CNTL+2, 0x005E, info);
288 aty_st_le16(CUSTOM_MACRO_CNTL+2, card->custom_macro_cntl>>16, info);
289 aty_st_8(CUSTOM_MACRO_CNTL+1,
290 (card->custom_macro_cntl>>8) & 0xff, info);
292 aty_st_le32(MEM_ADDR_CONFIG, card->mem_addr_config, info);
293 aty_st_le32(MEM_CNTL, card->mem_cntl, info);
294 aty_st_le32(EXT_MEM_CNTL, card->ext_mem_cntl, info);
296 aty_st_8(CONFIG_STAT0, 0xA0 | card->mem_type, info);
298 aty_st_pll(PLL_YCLK_CNTL, 0x01, info);
300 aty_st_pll(PLL_YCLK_CNTL, card->pll_yclk_cntl, info);
303 reset_clocks(info, &pll.ct, 0);
305 reset_clocks(info, &pll.ct, 0);
308 // enable extended register block
309 aty_st_8(BUS_CNTL+3, 0x7B, info);
311 // disable extended register block
312 aty_st_8(BUS_CNTL+3, 0x73, info);
314 aty_st_8(CONFIG_STAT0, 0x80 | card->mem_type, info);
316 // disable display requests, disable CRTC
317 aty_st_8(CRTC_GEN_CNTL+3, 0x04, info);
318 // disable mapping registers in VGA aperture
319 aty_st_8(CONFIG_CNTL, aty_ld_8(CONFIG_CNTL, info) & ~0x04, info);
321 // enable display requests, enable CRTC
322 aty_st_8(CRTC_GEN_CNTL+3, 0x02, info);
324 // make GPIO's 14,15,16 all inputs
325 aty_st_8(LCD_INDEX, 0x07, info);
326 aty_st_8(LCD_DATA+3, 0x00, info);
328 // enable the display
329 aty_st_8(CRTC_GEN_CNTL, 0x00, info);
331 // reset the memory controller
332 aty_st_8(GEN_TEST_CNTL+1, 0x02, info);
334 aty_st_8(GEN_TEST_CNTL+1, 0x00, info);
337 // enable extended register block
339 (u8)(aty_ld_8(BUS_CNTL+3, info) | 0x08),
341 // set FIFO size to 512 (PIO)
342 aty_st_le32(GUI_CNTL,
343 aty_ld_le32(GUI_CNTL, info) & ~0x3,
346 // enable CRT and disable lcd
347 aty_st_8(LCD_INDEX, 0x01, info);
348 temp = aty_ld_le32(LCD_DATA, info);
349 temp = (temp | 0x01) & ~0x02;
350 aty_st_le32(LCD_DATA, temp, info);
355 static char m64n_xl_33[] = "3D RAGE (XL PCI-33MHz)";
356 static char m64n_xl_66[] = "3D RAGE (XL PCI-66MHz)";
359 u16 pci_id, chip_type;
360 u8 rev_mask, rev_val;
365 /* 3D RAGE XL PCI-66/BGA */
366 { 0x474f, 0x474f, 0x00, 0x00, m64n_xl_66, 230, 83, 63, M64F_GT | M64F_INTEGRATED | M64F_RESET_3D | M64F_GTB_DSP | M64F_SDRAM_MAGIC_PLL | M64F_EXTRA_BRIGHT | M64F_XL_DLL | M64F_MFB_TIMES_4 },
367 /* 3D RAGE XL PCI-33/BGA */
368 { 0x4752, 0x4752, 0x00, 0x00, m64n_xl_33, 230, 83, 63, M64F_GT | M64F_INTEGRATED | M64F_RESET_3D | M64F_GTB_DSP | M64F_SDRAM_MAGIC_PLL | M64F_EXTRA_BRIGHT | M64F_XL_DLL | M64F_MFB_TIMES_4 },
371 static void aty_calc_mem_refresh(struct fb_info_aty *info,
376 const int ragepro_tbl[] = {
377 44, 50, 55, 66, 75, 80, 100
379 const int ragexl_tbl[] = {
380 50, 66, 75, 83, 90, 95, 100, 105,
381 110, 115, 120, 125, 133, 143, 166
383 const int *refresh_tbl;
386 refresh_tbl = ragexl_tbl;
387 size = sizeof(ragexl_tbl)/sizeof(int);
389 refresh_tbl = ragepro_tbl;
390 size = sizeof(ragepro_tbl)/sizeof(int);
393 for (i=0; i < size; i++) {
394 if (xclk < refresh_tbl[i])
398 info->mem_refresh_rate = i;
401 static void ati_ragexl_init(device_t dev) {
407 const char *chipname = NULL;
410 struct fb_info_aty *info;
411 struct fb_info_aty info_t;
412 struct resource *res;
415 #define USE_AUX_REG 1
418 res = &dev->resource[0];
419 if(res->flags & IORESOURCE_IO) {
420 res = &dev->resource[1];
422 info->ati_regbase = res->base+0x7ff000+0xc00;
424 res = &dev->resource[2];
425 if(res->flags & IORESOURCE_MEM) {
426 info->ati_regbase = res->base+0x400; //using auxiliary register
430 printk_debug("ati_regbase = 0x%08x\r\n", info->ati_regbase);
432 chip_id = aty_ld_le32(CONFIG_CHIP_ID, info);
433 type = chip_id & CFG_CHIP_TYPE;
434 rev = (chip_id & CFG_CHIP_REV)>>24;
435 for (j = 0; j < (sizeof(aty_chips)/sizeof(*aty_chips)); j++)
436 if (type == aty_chips[j].chip_type &&
437 (rev & aty_chips[j].rev_mask) == aty_chips[j].rev_val) {
438 chipname = aty_chips[j].name;
439 pll = aty_chips[j].pll;
440 mclk = aty_chips[j].mclk;
441 xclk = aty_chips[j].xclk;
442 info->features = aty_chips[j].features;
445 printk_debug("ati_ragexl_init: Unknown mach64 0x%04x rev 0x%04x\n", type, rev);
449 printk_debug("ati_ragexl_init: %s [0x%04x rev 0x%02x] ", chipname, type, rev);
451 if (M64_HAS(INTEGRATED)) {
452 /* for many chips, the mclk is 67 MHz for SDRAM, 63 MHz otherwise */
453 if (mclk == 67 && info->ram_type < SDRAM)
457 // aty_calc_mem_refresh(info, type, xclk);
458 info->pll_per = 1000000/pll;
459 info->mclk_per = 1000000/mclk;
460 info->xclk_per = 1000000/xclk;
462 // info->dac_ops = &aty_dac_ct;
463 // info->pll_ops = &aty_pll_ct;
464 info->bus_type = PCI;
470 static struct device_operations ati_ragexl_graph_ops = {
471 .read_resources = pci_dev_read_resources,
472 .set_resources = pci_dev_set_resources,
473 .enable_resources = pci_dev_enable_resources,
474 .init = ati_ragexl_init,
478 static struct pci_driver ati_ragexl_graph_driver __pci_driver = {
479 .ops = &ati_ragexl_graph_ops,
480 .vendor = PCI_VENDOR_ID_ATI,
481 .device = PCI_DEVICE_ID_ATI_215XL,