Automatic merge of /spare/repo/netdev-2.6 branch ixgb
[linux-2.6.git] / drivers / video / aty / mach64_gx.c
blob01fdff79483b8a48fea6035e00aa35aedf99acd2
2 /*
3 * ATI Mach64 GX Support
4 */
6 #include <linux/delay.h>
7 #include <linux/fb.h>
8 #include <linux/sched.h>
10 #include <asm/io.h>
12 #include <video/mach64.h>
13 #include "atyfb.h"
15 /* Definitions for the ICS 2595 == ATI 18818_1 Clockchip */
17 #define REF_FREQ_2595 1432 /* 14.33 MHz (exact 14.31818) */
18 #define REF_DIV_2595 46 /* really 43 on ICS 2595 !!! */
19 /* ohne Prescaler */
20 #define MAX_FREQ_2595 15938 /* 159.38 MHz (really 170.486) */
21 #define MIN_FREQ_2595 8000 /* 80.00 MHz ( 85.565) */
22 /* mit Prescaler 2, 4, 8 */
23 #define ABS_MIN_FREQ_2595 1000 /* 10.00 MHz (really 10.697) */
24 #define N_ADJ_2595 257
26 #define STOP_BITS_2595 0x1800
29 #define MIN_N_408 2
31 #define MIN_N_1703 6
33 #define MIN_M 2
34 #define MAX_M 30
35 #define MIN_N 35
36 #define MAX_N 255-8
40 * Support Functions
43 static void aty_dac_waste4(const struct atyfb_par *par)
45 (void) aty_ld_8(DAC_REGS, par);
47 (void) aty_ld_8(DAC_REGS + 2, par);
48 (void) aty_ld_8(DAC_REGS + 2, par);
49 (void) aty_ld_8(DAC_REGS + 2, par);
50 (void) aty_ld_8(DAC_REGS + 2, par);
53 static void aty_StrobeClock(const struct atyfb_par *par)
55 u8 tmp;
57 udelay(26);
59 tmp = aty_ld_8(CLOCK_CNTL, par);
60 aty_st_8(CLOCK_CNTL + par->clk_wr_offset, tmp | CLOCK_STROBE, par);
61 return;
66 * IBM RGB514 DAC and Clock Chip
69 static void aty_st_514(int offset, u8 val, const struct atyfb_par *par)
71 aty_st_8(DAC_CNTL, 1, par);
72 /* right addr byte */
73 aty_st_8(DAC_W_INDEX, offset & 0xff, par);
74 /* left addr byte */
75 aty_st_8(DAC_DATA, (offset >> 8) & 0xff, par);
76 aty_st_8(DAC_MASK, val, par);
77 aty_st_8(DAC_CNTL, 0, par);
80 static int aty_set_dac_514(const struct fb_info *info,
81 const union aty_pll *pll, u32 bpp, u32 accel)
83 struct atyfb_par *par = (struct atyfb_par *) info->par;
84 static struct {
85 u8 pixel_dly;
86 u8 misc2_cntl;
87 u8 pixel_rep;
88 u8 pixel_cntl_index;
89 u8 pixel_cntl_v1;
90 } tab[3] = {
92 0, 0x41, 0x03, 0x71, 0x45}, /* 8 bpp */
94 0, 0x45, 0x04, 0x0c, 0x01}, /* 555 */
96 0, 0x45, 0x06, 0x0e, 0x00}, /* XRGB */
98 int i;
100 switch (bpp) {
101 case 8:
102 default:
103 i = 0;
104 break;
105 case 16:
106 i = 1;
107 break;
108 case 32:
109 i = 2;
110 break;
112 aty_st_514(0x90, 0x00, par); /* VRAM Mask Low */
113 aty_st_514(0x04, tab[i].pixel_dly, par); /* Horizontal Sync Control */
114 aty_st_514(0x05, 0x00, par); /* Power Management */
115 aty_st_514(0x02, 0x01, par); /* Misc Clock Control */
116 aty_st_514(0x71, tab[i].misc2_cntl, par); /* Misc Control 2 */
117 aty_st_514(0x0a, tab[i].pixel_rep, par); /* Pixel Format */
118 aty_st_514(tab[i].pixel_cntl_index, tab[i].pixel_cntl_v1, par);
119 /* Misc Control 2 / 16 BPP Control / 32 BPP Control */
120 return 0;
123 static int aty_var_to_pll_514(const struct fb_info *info, u32 vclk_per,
124 u32 bpp, union aty_pll *pll)
127 * FIXME: use real calculations instead of using fixed values from the old
128 * driver
130 static struct {
131 u32 limit; /* pixlock rounding limit (arbitrary) */
132 u8 m; /* (df<<6) | vco_div_count */
133 u8 n; /* ref_div_count */
134 } RGB514_clocks[7] = {
136 8000, (3 << 6) | 20, 9}, /* 7395 ps / 135.2273 MHz */
138 10000, (1 << 6) | 19, 3}, /* 9977 ps / 100.2273 MHz */
140 13000, (1 << 6) | 2, 3}, /* 12509 ps / 79.9432 MHz */
142 14000, (2 << 6) | 8, 7}, /* 13394 ps / 74.6591 MHz */
144 16000, (1 << 6) | 44, 6}, /* 15378 ps / 65.0284 MHz */
146 25000, (1 << 6) | 15, 5}, /* 17460 ps / 57.2727 MHz */
148 50000, (0 << 6) | 53, 7}, /* 33145 ps / 30.1705 MHz */
150 int i;
152 for (i = 0; i < sizeof(RGB514_clocks) / sizeof(*RGB514_clocks);
153 i++)
154 if (vclk_per <= RGB514_clocks[i].limit) {
155 pll->ibm514.m = RGB514_clocks[i].m;
156 pll->ibm514.n = RGB514_clocks[i].n;
157 return 0;
159 return -EINVAL;
162 static u32 aty_pll_514_to_var(const struct fb_info *info,
163 const union aty_pll *pll)
165 struct atyfb_par *par = (struct atyfb_par *) info->par;
166 u8 df, vco_div_count, ref_div_count;
168 df = pll->ibm514.m >> 6;
169 vco_div_count = pll->ibm514.m & 0x3f;
170 ref_div_count = pll->ibm514.n;
172 return ((par->ref_clk_per * ref_div_count) << (3 - df))/
173 (vco_div_count + 65);
176 static void aty_set_pll_514(const struct fb_info *info,
177 const union aty_pll *pll)
179 struct atyfb_par *par = (struct atyfb_par *) info->par;
181 aty_st_514(0x06, 0x02, par); /* DAC Operation */
182 aty_st_514(0x10, 0x01, par); /* PLL Control 1 */
183 aty_st_514(0x70, 0x01, par); /* Misc Control 1 */
184 aty_st_514(0x8f, 0x1f, par); /* PLL Ref. Divider Input */
185 aty_st_514(0x03, 0x00, par); /* Sync Control */
186 aty_st_514(0x05, 0x00, par); /* Power Management */
187 aty_st_514(0x20, pll->ibm514.m, par); /* F0 / M0 */
188 aty_st_514(0x21, pll->ibm514.n, par); /* F1 / N0 */
191 const struct aty_dac_ops aty_dac_ibm514 = {
192 .set_dac = aty_set_dac_514,
195 const struct aty_pll_ops aty_pll_ibm514 = {
196 .var_to_pll = aty_var_to_pll_514,
197 .pll_to_var = aty_pll_514_to_var,
198 .set_pll = aty_set_pll_514,
203 * ATI 68860-B DAC
206 static int aty_set_dac_ATI68860_B(const struct fb_info *info,
207 const union aty_pll *pll, u32 bpp,
208 u32 accel)
210 struct atyfb_par *par = (struct atyfb_par *) info->par;
211 u32 gModeReg, devSetupRegA, temp, mask;
213 gModeReg = 0;
214 devSetupRegA = 0;
216 switch (bpp) {
217 case 8:
218 gModeReg = 0x83;
219 devSetupRegA =
220 0x60 | 0x00 /*(info->mach64DAC8Bit ? 0x00 : 0x01) */ ;
221 break;
222 case 15:
223 gModeReg = 0xA0;
224 devSetupRegA = 0x60;
225 break;
226 case 16:
227 gModeReg = 0xA1;
228 devSetupRegA = 0x60;
229 break;
230 case 24:
231 gModeReg = 0xC0;
232 devSetupRegA = 0x60;
233 break;
234 case 32:
235 gModeReg = 0xE3;
236 devSetupRegA = 0x60;
237 break;
240 if (!accel) {
241 gModeReg = 0x80;
242 devSetupRegA = 0x61;
245 temp = aty_ld_8(DAC_CNTL, par);
246 aty_st_8(DAC_CNTL, (temp & ~DAC_EXT_SEL_RS2) | DAC_EXT_SEL_RS3,
247 par);
249 aty_st_8(DAC_REGS + 2, 0x1D, par);
250 aty_st_8(DAC_REGS + 3, gModeReg, par);
251 aty_st_8(DAC_REGS, 0x02, par);
253 temp = aty_ld_8(DAC_CNTL, par);
254 aty_st_8(DAC_CNTL, temp | DAC_EXT_SEL_RS2 | DAC_EXT_SEL_RS3, par);
256 if (info->fix.smem_len < ONE_MB)
257 mask = 0x04;
258 else if (info->fix.smem_len == ONE_MB)
259 mask = 0x08;
260 else
261 mask = 0x0C;
263 /* The following assumes that the BIOS has correctly set R7 of the
264 * Device Setup Register A at boot time.
266 #define A860_DELAY_L 0x80
268 temp = aty_ld_8(DAC_REGS, par);
269 aty_st_8(DAC_REGS, (devSetupRegA | mask) | (temp & A860_DELAY_L),
270 par);
271 temp = aty_ld_8(DAC_CNTL, par);
272 aty_st_8(DAC_CNTL, (temp & ~(DAC_EXT_SEL_RS2 | DAC_EXT_SEL_RS3)),
273 par);
275 aty_st_le32(BUS_CNTL, 0x890e20f1, par);
276 aty_st_le32(DAC_CNTL, 0x47052100, par);
277 return 0;
280 const struct aty_dac_ops aty_dac_ati68860b = {
281 .set_dac = aty_set_dac_ATI68860_B,
286 * AT&T 21C498 DAC
289 static int aty_set_dac_ATT21C498(const struct fb_info *info,
290 const union aty_pll *pll, u32 bpp,
291 u32 accel)
293 struct atyfb_par *par = (struct atyfb_par *) info->par;
294 u32 dotClock;
295 int muxmode = 0;
296 int DACMask = 0;
298 dotClock = 100000000 / pll->ics2595.period_in_ps;
300 switch (bpp) {
301 case 8:
302 if (dotClock > 8000) {
303 DACMask = 0x24;
304 muxmode = 1;
305 } else
306 DACMask = 0x04;
307 break;
308 case 15:
309 DACMask = 0x16;
310 break;
311 case 16:
312 DACMask = 0x36;
313 break;
314 case 24:
315 DACMask = 0xE6;
316 break;
317 case 32:
318 DACMask = 0xE6;
319 break;
322 if (1 /* info->mach64DAC8Bit */ )
323 DACMask |= 0x02;
325 aty_dac_waste4(par);
326 aty_st_8(DAC_REGS + 2, DACMask, par);
328 aty_st_le32(BUS_CNTL, 0x890e20f1, par);
329 aty_st_le32(DAC_CNTL, 0x00072000, par);
330 return muxmode;
333 const struct aty_dac_ops aty_dac_att21c498 = {
334 .set_dac = aty_set_dac_ATT21C498,
339 * ATI 18818 / ICS 2595 Clock Chip
342 static int aty_var_to_pll_18818(const struct fb_info *info, u32 vclk_per,
343 u32 bpp, union aty_pll *pll)
345 u32 MHz100; /* in 0.01 MHz */
346 u32 program_bits;
347 u32 post_divider;
349 /* Calculate the programming word */
350 MHz100 = 100000000 / vclk_per;
352 program_bits = -1;
353 post_divider = 1;
355 if (MHz100 > MAX_FREQ_2595) {
356 MHz100 = MAX_FREQ_2595;
357 return -EINVAL;
358 } else if (MHz100 < ABS_MIN_FREQ_2595) {
359 program_bits = 0; /* MHz100 = 257 */
360 return -EINVAL;
361 } else {
362 while (MHz100 < MIN_FREQ_2595) {
363 MHz100 *= 2;
364 post_divider *= 2;
367 MHz100 *= 1000;
368 MHz100 = (REF_DIV_2595 * MHz100) / REF_FREQ_2595;
370 MHz100 += 500; /* + 0.5 round */
371 MHz100 /= 1000;
373 if (program_bits == -1) {
374 program_bits = MHz100 - N_ADJ_2595;
375 switch (post_divider) {
376 case 1:
377 program_bits |= 0x0600;
378 break;
379 case 2:
380 program_bits |= 0x0400;
381 break;
382 case 4:
383 program_bits |= 0x0200;
384 break;
385 case 8:
386 default:
387 break;
391 program_bits |= STOP_BITS_2595;
393 pll->ics2595.program_bits = program_bits;
394 pll->ics2595.locationAddr = 0;
395 pll->ics2595.post_divider = post_divider;
396 pll->ics2595.period_in_ps = vclk_per;
398 return 0;
401 static u32 aty_pll_18818_to_var(const struct fb_info *info,
402 const union aty_pll *pll)
404 return (pll->ics2595.period_in_ps); /* default for now */
407 static void aty_ICS2595_put1bit(u8 data, const struct atyfb_par *par)
409 u8 tmp;
411 data &= 0x01;
412 tmp = aty_ld_8(CLOCK_CNTL, par);
413 aty_st_8(CLOCK_CNTL + par->clk_wr_offset,
414 (tmp & ~0x04) | (data << 2), par);
416 tmp = aty_ld_8(CLOCK_CNTL, par);
417 aty_st_8(CLOCK_CNTL + par->clk_wr_offset, (tmp & ~0x08) | (0 << 3),
418 par);
420 aty_StrobeClock(par);
422 tmp = aty_ld_8(CLOCK_CNTL, par);
423 aty_st_8(CLOCK_CNTL + par->clk_wr_offset, (tmp & ~0x08) | (1 << 3),
424 par);
426 aty_StrobeClock(par);
427 return;
430 static void aty_set_pll18818(const struct fb_info *info,
431 const union aty_pll *pll)
433 struct atyfb_par *par = (struct atyfb_par *) info->par;
434 u32 program_bits;
435 u32 locationAddr;
437 u32 i;
439 u8 old_clock_cntl;
440 u8 old_crtc_ext_disp;
442 old_clock_cntl = aty_ld_8(CLOCK_CNTL, par);
443 aty_st_8(CLOCK_CNTL + par->clk_wr_offset, 0, par);
445 old_crtc_ext_disp = aty_ld_8(CRTC_GEN_CNTL + 3, par);
446 aty_st_8(CRTC_GEN_CNTL + 3,
447 old_crtc_ext_disp | (CRTC_EXT_DISP_EN >> 24), par);
449 mdelay(15); /* delay for 50 (15) ms */
451 program_bits = pll->ics2595.program_bits;
452 locationAddr = pll->ics2595.locationAddr;
454 /* Program the clock chip */
455 aty_st_8(CLOCK_CNTL + par->clk_wr_offset, 0, par); /* Strobe = 0 */
456 aty_StrobeClock(par);
457 aty_st_8(CLOCK_CNTL + par->clk_wr_offset, 1, par); /* Strobe = 0 */
458 aty_StrobeClock(par);
460 aty_ICS2595_put1bit(1, par); /* Send start bits */
461 aty_ICS2595_put1bit(0, par); /* Start bit */
462 aty_ICS2595_put1bit(0, par); /* Read / ~Write */
464 for (i = 0; i < 5; i++) { /* Location 0..4 */
465 aty_ICS2595_put1bit(locationAddr & 1, par);
466 locationAddr >>= 1;
469 for (i = 0; i < 8 + 1 + 2 + 2; i++) {
470 aty_ICS2595_put1bit(program_bits & 1, par);
471 program_bits >>= 1;
474 mdelay(1); /* delay for 1 ms */
476 (void) aty_ld_8(DAC_REGS, par); /* Clear DAC Counter */
477 aty_st_8(CRTC_GEN_CNTL + 3, old_crtc_ext_disp, par);
478 aty_st_8(CLOCK_CNTL + par->clk_wr_offset,
479 old_clock_cntl | CLOCK_STROBE, par);
481 mdelay(50); /* delay for 50 (15) ms */
482 aty_st_8(CLOCK_CNTL + par->clk_wr_offset,
483 ((pll->ics2595.locationAddr & 0x0F) | CLOCK_STROBE), par);
484 return;
487 const struct aty_pll_ops aty_pll_ati18818_1 = {
488 .var_to_pll = aty_var_to_pll_18818,
489 .pll_to_var = aty_pll_18818_to_var,
490 .set_pll = aty_set_pll18818,
495 * STG 1703 Clock Chip
498 static int aty_var_to_pll_1703(const struct fb_info *info, u32 vclk_per,
499 u32 bpp, union aty_pll *pll)
501 u32 mhz100; /* in 0.01 MHz */
502 u32 program_bits;
503 /* u32 post_divider; */
504 u32 mach64MinFreq, mach64MaxFreq, mach64RefFreq;
505 u32 temp, tempB;
506 u16 remainder, preRemainder;
507 short divider = 0, tempA;
509 /* Calculate the programming word */
510 mhz100 = 100000000 / vclk_per;
511 mach64MinFreq = MIN_FREQ_2595;
512 mach64MaxFreq = MAX_FREQ_2595;
513 mach64RefFreq = REF_FREQ_2595; /* 14.32 MHz */
515 /* Calculate program word */
516 if (mhz100 == 0)
517 program_bits = 0xE0;
518 else {
519 if (mhz100 < mach64MinFreq)
520 mhz100 = mach64MinFreq;
521 if (mhz100 > mach64MaxFreq)
522 mhz100 = mach64MaxFreq;
524 divider = 0;
525 while (mhz100 < (mach64MinFreq << 3)) {
526 mhz100 <<= 1;
527 divider += 0x20;
530 temp = (unsigned int) (mhz100);
531 temp = (unsigned int) (temp * (MIN_N_1703 + 2));
532 temp -= (short) (mach64RefFreq << 1);
534 tempA = MIN_N_1703;
535 preRemainder = 0xffff;
537 do {
538 tempB = temp;
539 remainder = tempB % mach64RefFreq;
540 tempB = tempB / mach64RefFreq;
542 if ((tempB & 0xffff) <= 127
543 && (remainder <= preRemainder)) {
544 preRemainder = remainder;
545 divider &= ~0x1f;
546 divider |= tempA;
547 divider =
548 (divider & 0x00ff) +
549 ((tempB & 0xff) << 8);
552 temp += mhz100;
553 tempA++;
554 } while (tempA <= (MIN_N_1703 << 1));
556 program_bits = divider;
559 pll->ics2595.program_bits = program_bits;
560 pll->ics2595.locationAddr = 0;
561 pll->ics2595.post_divider = divider; /* fuer nix */
562 pll->ics2595.period_in_ps = vclk_per;
564 return 0;
567 static u32 aty_pll_1703_to_var(const struct fb_info *info,
568 const union aty_pll *pll)
570 return (pll->ics2595.period_in_ps); /* default for now */
573 static void aty_set_pll_1703(const struct fb_info *info,
574 const union aty_pll *pll)
576 struct atyfb_par *par = (struct atyfb_par *) info->par;
577 u32 program_bits;
578 u32 locationAddr;
580 char old_crtc_ext_disp;
582 old_crtc_ext_disp = aty_ld_8(CRTC_GEN_CNTL + 3, par);
583 aty_st_8(CRTC_GEN_CNTL + 3,
584 old_crtc_ext_disp | (CRTC_EXT_DISP_EN >> 24), par);
586 program_bits = pll->ics2595.program_bits;
587 locationAddr = pll->ics2595.locationAddr;
589 /* Program clock */
590 aty_dac_waste4(par);
592 (void) aty_ld_8(DAC_REGS + 2, par);
593 aty_st_8(DAC_REGS + 2, (locationAddr << 1) + 0x20, par);
594 aty_st_8(DAC_REGS + 2, 0, par);
595 aty_st_8(DAC_REGS + 2, (program_bits & 0xFF00) >> 8, par);
596 aty_st_8(DAC_REGS + 2, (program_bits & 0xFF), par);
598 (void) aty_ld_8(DAC_REGS, par); /* Clear DAC Counter */
599 aty_st_8(CRTC_GEN_CNTL + 3, old_crtc_ext_disp, par);
600 return;
603 const struct aty_pll_ops aty_pll_stg1703 = {
604 .var_to_pll = aty_var_to_pll_1703,
605 .pll_to_var = aty_pll_1703_to_var,
606 .set_pll = aty_set_pll_1703,
611 * Chrontel 8398 Clock Chip
614 static int aty_var_to_pll_8398(const struct fb_info *info, u32 vclk_per,
615 u32 bpp, union aty_pll *pll)
617 u32 tempA, tempB, fOut, longMHz100, diff, preDiff;
619 u32 mhz100; /* in 0.01 MHz */
620 u32 program_bits;
621 /* u32 post_divider; */
622 u32 mach64MinFreq, mach64MaxFreq, mach64RefFreq;
623 u16 m, n, k = 0, save_m, save_n, twoToKth;
625 /* Calculate the programming word */
626 mhz100 = 100000000 / vclk_per;
627 mach64MinFreq = MIN_FREQ_2595;
628 mach64MaxFreq = MAX_FREQ_2595;
629 mach64RefFreq = REF_FREQ_2595; /* 14.32 MHz */
631 save_m = 0;
632 save_n = 0;
634 /* Calculate program word */
635 if (mhz100 == 0)
636 program_bits = 0xE0;
637 else {
638 if (mhz100 < mach64MinFreq)
639 mhz100 = mach64MinFreq;
640 if (mhz100 > mach64MaxFreq)
641 mhz100 = mach64MaxFreq;
643 longMHz100 = mhz100 * 256 / 100; /* 8 bit scale this */
645 while (mhz100 < (mach64MinFreq << 3)) {
646 mhz100 <<= 1;
647 k++;
650 twoToKth = 1 << k;
651 diff = 0;
652 preDiff = 0xFFFFFFFF;
654 for (m = MIN_M; m <= MAX_M; m++) {
655 for (n = MIN_N; n <= MAX_N; n++) {
656 tempA = 938356; /* 14.31818 * 65536 */
657 tempA *= (n + 8); /* 43..256 */
658 tempB = twoToKth * 256;
659 tempB *= (m + 2); /* 4..32 */
660 fOut = tempA / tempB; /* 8 bit scale */
662 if (longMHz100 > fOut)
663 diff = longMHz100 - fOut;
664 else
665 diff = fOut - longMHz100;
667 if (diff < preDiff) {
668 save_m = m;
669 save_n = n;
670 preDiff = diff;
675 program_bits = (k << 6) + (save_m) + (save_n << 8);
678 pll->ics2595.program_bits = program_bits;
679 pll->ics2595.locationAddr = 0;
680 pll->ics2595.post_divider = 0;
681 pll->ics2595.period_in_ps = vclk_per;
683 return 0;
686 static u32 aty_pll_8398_to_var(const struct fb_info *info,
687 const union aty_pll *pll)
689 return (pll->ics2595.period_in_ps); /* default for now */
692 static void aty_set_pll_8398(const struct fb_info *info,
693 const union aty_pll *pll)
695 struct atyfb_par *par = (struct atyfb_par *) info->par;
696 u32 program_bits;
697 u32 locationAddr;
699 char old_crtc_ext_disp;
700 char tmp;
702 old_crtc_ext_disp = aty_ld_8(CRTC_GEN_CNTL + 3, par);
703 aty_st_8(CRTC_GEN_CNTL + 3,
704 old_crtc_ext_disp | (CRTC_EXT_DISP_EN >> 24), par);
706 program_bits = pll->ics2595.program_bits;
707 locationAddr = pll->ics2595.locationAddr;
709 /* Program clock */
710 tmp = aty_ld_8(DAC_CNTL, par);
711 aty_st_8(DAC_CNTL, tmp | DAC_EXT_SEL_RS2 | DAC_EXT_SEL_RS3, par);
713 aty_st_8(DAC_REGS, locationAddr, par);
714 aty_st_8(DAC_REGS + 1, (program_bits & 0xff00) >> 8, par);
715 aty_st_8(DAC_REGS + 1, (program_bits & 0xff), par);
717 tmp = aty_ld_8(DAC_CNTL, par);
718 aty_st_8(DAC_CNTL, (tmp & ~DAC_EXT_SEL_RS2) | DAC_EXT_SEL_RS3,
719 par);
721 (void) aty_ld_8(DAC_REGS, par); /* Clear DAC Counter */
722 aty_st_8(CRTC_GEN_CNTL + 3, old_crtc_ext_disp, par);
724 return;
727 const struct aty_pll_ops aty_pll_ch8398 = {
728 .var_to_pll = aty_var_to_pll_8398,
729 .pll_to_var = aty_pll_8398_to_var,
730 .set_pll = aty_set_pll_8398,
735 * AT&T 20C408 Clock Chip
738 static int aty_var_to_pll_408(const struct fb_info *info, u32 vclk_per,
739 u32 bpp, union aty_pll *pll)
741 u32 mhz100; /* in 0.01 MHz */
742 u32 program_bits;
743 /* u32 post_divider; */
744 u32 mach64MinFreq, mach64MaxFreq, mach64RefFreq;
745 u32 temp, tempB;
746 u16 remainder, preRemainder;
747 short divider = 0, tempA;
749 /* Calculate the programming word */
750 mhz100 = 100000000 / vclk_per;
751 mach64MinFreq = MIN_FREQ_2595;
752 mach64MaxFreq = MAX_FREQ_2595;
753 mach64RefFreq = REF_FREQ_2595; /* 14.32 MHz */
755 /* Calculate program word */
756 if (mhz100 == 0)
757 program_bits = 0xFF;
758 else {
759 if (mhz100 < mach64MinFreq)
760 mhz100 = mach64MinFreq;
761 if (mhz100 > mach64MaxFreq)
762 mhz100 = mach64MaxFreq;
764 while (mhz100 < (mach64MinFreq << 3)) {
765 mhz100 <<= 1;
766 divider += 0x40;
769 temp = (unsigned int) mhz100;
770 temp = (unsigned int) (temp * (MIN_N_408 + 2));
771 temp -= ((short) (mach64RefFreq << 1));
773 tempA = MIN_N_408;
774 preRemainder = 0xFFFF;
776 do {
777 tempB = temp;
778 remainder = tempB % mach64RefFreq;
779 tempB = tempB / mach64RefFreq;
780 if (((tempB & 0xFFFF) <= 255)
781 && (remainder <= preRemainder)) {
782 preRemainder = remainder;
783 divider &= ~0x3f;
784 divider |= tempA;
785 divider =
786 (divider & 0x00FF) +
787 ((tempB & 0xFF) << 8);
789 temp += mhz100;
790 tempA++;
791 } while (tempA <= 32);
793 program_bits = divider;
796 pll->ics2595.program_bits = program_bits;
797 pll->ics2595.locationAddr = 0;
798 pll->ics2595.post_divider = divider; /* fuer nix */
799 pll->ics2595.period_in_ps = vclk_per;
801 return 0;
804 static u32 aty_pll_408_to_var(const struct fb_info *info,
805 const union aty_pll *pll)
807 return (pll->ics2595.period_in_ps); /* default for now */
810 static void aty_set_pll_408(const struct fb_info *info,
811 const union aty_pll *pll)
813 struct atyfb_par *par = (struct atyfb_par *) info->par;
814 u32 program_bits;
815 u32 locationAddr;
817 u8 tmpA, tmpB, tmpC;
818 char old_crtc_ext_disp;
820 old_crtc_ext_disp = aty_ld_8(CRTC_GEN_CNTL + 3, par);
821 aty_st_8(CRTC_GEN_CNTL + 3,
822 old_crtc_ext_disp | (CRTC_EXT_DISP_EN >> 24), par);
824 program_bits = pll->ics2595.program_bits;
825 locationAddr = pll->ics2595.locationAddr;
827 /* Program clock */
828 aty_dac_waste4(par);
829 tmpB = aty_ld_8(DAC_REGS + 2, par) | 1;
830 aty_dac_waste4(par);
831 aty_st_8(DAC_REGS + 2, tmpB, par);
833 tmpA = tmpB;
834 tmpC = tmpA;
835 tmpA |= 8;
836 tmpB = 1;
838 aty_st_8(DAC_REGS, tmpB, par);
839 aty_st_8(DAC_REGS + 2, tmpA, par);
841 udelay(400); /* delay for 400 us */
843 locationAddr = (locationAddr << 2) + 0x40;
844 tmpB = locationAddr;
845 tmpA = program_bits >> 8;
847 aty_st_8(DAC_REGS, tmpB, par);
848 aty_st_8(DAC_REGS + 2, tmpA, par);
850 tmpB = locationAddr + 1;
851 tmpA = (u8) program_bits;
853 aty_st_8(DAC_REGS, tmpB, par);
854 aty_st_8(DAC_REGS + 2, tmpA, par);
856 tmpB = locationAddr + 2;
857 tmpA = 0x77;
859 aty_st_8(DAC_REGS, tmpB, par);
860 aty_st_8(DAC_REGS + 2, tmpA, par);
862 udelay(400); /* delay for 400 us */
863 tmpA = tmpC & (~(1 | 8));
864 tmpB = 1;
866 aty_st_8(DAC_REGS, tmpB, par);
867 aty_st_8(DAC_REGS + 2, tmpA, par);
869 (void) aty_ld_8(DAC_REGS, par); /* Clear DAC Counter */
870 aty_st_8(CRTC_GEN_CNTL + 3, old_crtc_ext_disp, par);
871 return;
874 const struct aty_pll_ops aty_pll_att20c408 = {
875 .var_to_pll = aty_var_to_pll_408,
876 .pll_to_var = aty_pll_408_to_var,
877 .set_pll = aty_set_pll_408,
882 * Unsupported DAC and Clock Chip
885 static int aty_set_dac_unsupported(const struct fb_info *info,
886 const union aty_pll *pll, u32 bpp,
887 u32 accel)
889 struct atyfb_par *par = (struct atyfb_par *) info->par;
891 aty_st_le32(BUS_CNTL, 0x890e20f1, par);
892 aty_st_le32(DAC_CNTL, 0x47052100, par);
893 /* new in 2.2.3p1 from Geert. ???????? */
894 aty_st_le32(BUS_CNTL, 0x590e10ff, par);
895 aty_st_le32(DAC_CNTL, 0x47012100, par);
896 return 0;
899 static int dummy(void)
901 return 0;
904 const struct aty_dac_ops aty_dac_unsupported = {
905 .set_dac = aty_set_dac_unsupported,
908 const struct aty_pll_ops aty_pll_unsupported = {
909 .var_to_pll = (void *) dummy,
910 .pll_to_var = (void *) dummy,
911 .set_pll = (void *) dummy,