aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/video/aty/atyfb_base.c829
1 files changed, 458 insertions, 371 deletions
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 63d3739d43a8..913b4a47ae52 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -132,7 +132,7 @@
132#endif 132#endif
133 133
134#define PRINTKI(fmt, args...) printk(KERN_INFO "atyfb: " fmt, ## args) 134#define PRINTKI(fmt, args...) printk(KERN_INFO "atyfb: " fmt, ## args)
135#define PRINTKE(fmt, args...) printk(KERN_ERR "atyfb: " fmt, ## args) 135#define PRINTKE(fmt, args...) printk(KERN_ERR "atyfb: " fmt, ## args)
136 136
137#if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || \ 137#if defined(CONFIG_PM) || defined(CONFIG_PMAC_BACKLIGHT) || \
138defined (CONFIG_FB_ATY_GENERIC_LCD) || defined(CONFIG_FB_ATY_BACKLIGHT) 138defined (CONFIG_FB_ATY_GENERIC_LCD) || defined(CONFIG_FB_ATY_BACKLIGHT)
@@ -188,24 +188,23 @@ u32 aty_ld_lcd(int index, const struct atyfb_par *par)
188 */ 188 */
189static void ATIReduceRatio(int *Numerator, int *Denominator) 189static void ATIReduceRatio(int *Numerator, int *Denominator)
190{ 190{
191 int Multiplier, Divider, Remainder; 191 int Multiplier, Divider, Remainder;
192 192
193 Multiplier = *Numerator; 193 Multiplier = *Numerator;
194 Divider = *Denominator; 194 Divider = *Denominator;
195 195
196 while ((Remainder = Multiplier % Divider)) 196 while ((Remainder = Multiplier % Divider)) {
197 { 197 Multiplier = Divider;
198 Multiplier = Divider; 198 Divider = Remainder;
199 Divider = Remainder; 199 }
200 }
201 200
202 *Numerator /= Divider; 201 *Numerator /= Divider;
203 *Denominator /= Divider; 202 *Denominator /= Divider;
204} 203}
205#endif 204#endif
206 /* 205/*
207 * The Hardware parameters for each card 206 * The Hardware parameters for each card
208 */ 207 */
209 208
210struct pci_mmap_map { 209struct pci_mmap_map {
211 unsigned long voff; 210 unsigned long voff;
@@ -223,17 +222,19 @@ static struct fb_fix_screeninfo atyfb_fix __devinitdata = {
223 .ypanstep = 1, 222 .ypanstep = 1,
224}; 223};
225 224
226 /* 225/*
227 * Frame buffer device API 226 * Frame buffer device API
228 */ 227 */
229 228
230static int atyfb_open(struct fb_info *info, int user); 229static int atyfb_open(struct fb_info *info, int user);
231static int atyfb_release(struct fb_info *info, int user); 230static int atyfb_release(struct fb_info *info, int user);
232static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info); 231static int atyfb_check_var(struct fb_var_screeninfo *var,
232 struct fb_info *info);
233static int atyfb_set_par(struct fb_info *info); 233static int atyfb_set_par(struct fb_info *info);
234static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, 234static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
235 u_int transp, struct fb_info *info); 235 u_int transp, struct fb_info *info);
236static int atyfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info); 236static int atyfb_pan_display(struct fb_var_screeninfo *var,
237 struct fb_info *info);
237static int atyfb_blank(int blank, struct fb_info *info); 238static int atyfb_blank(int blank, struct fb_info *info);
238static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg); 239static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg);
239#ifdef __sparc__ 240#ifdef __sparc__
@@ -241,9 +242,9 @@ static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma);
241#endif 242#endif
242static int atyfb_sync(struct fb_info *info); 243static int atyfb_sync(struct fb_info *info);
243 244
244 /* 245/*
245 * Internal routines 246 * Internal routines
246 */ 247 */
247 248
248static int aty_init(struct fb_info *info); 249static int aty_init(struct fb_info *info);
249 250
@@ -254,8 +255,11 @@ static int store_video_par(char *videopar, unsigned char m64_num);
254static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc); 255static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc);
255 256
256static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc); 257static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc);
257static int aty_var_to_crtc(const struct fb_info *info, const struct fb_var_screeninfo *var, struct crtc *crtc); 258static int aty_var_to_crtc(const struct fb_info *info,
258static int aty_crtc_to_var(const struct crtc *crtc, struct fb_var_screeninfo *var); 259 const struct fb_var_screeninfo *var,
260 struct crtc *crtc);
261static int aty_crtc_to_var(const struct crtc *crtc,
262 struct fb_var_screeninfo *var);
259static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info); 263static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info);
260#ifdef CONFIG_PPC 264#ifdef CONFIG_PPC
261static int read_aty_sense(const struct atyfb_par *par); 265static int read_aty_sense(const struct atyfb_par *par);
@@ -264,9 +268,9 @@ static int read_aty_sense(const struct atyfb_par *par);
264static DEFINE_MUTEX(reboot_lock); 268static DEFINE_MUTEX(reboot_lock);
265static struct fb_info *reboot_info; 269static struct fb_info *reboot_info;
266 270
267 /* 271/*
268 * Interface used by the world 272 * Interface used by the world
269 */ 273 */
270 274
271static struct fb_var_screeninfo default_var = { 275static struct fb_var_screeninfo default_var = {
272 /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */ 276 /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */
@@ -452,14 +456,14 @@ static int __devinit correct_chipset(struct atyfb_par *par)
452 type = chip_id & CFG_CHIP_TYPE; 456 type = chip_id & CFG_CHIP_TYPE;
453 rev = (chip_id & CFG_CHIP_REV) >> 24; 457 rev = (chip_id & CFG_CHIP_REV) >> 24;
454 458
455 switch(par->pci_id) { 459 switch (par->pci_id) {
456#ifdef CONFIG_FB_ATY_GX 460#ifdef CONFIG_FB_ATY_GX
457 case PCI_CHIP_MACH64GX: 461 case PCI_CHIP_MACH64GX:
458 if(type != 0x00d7) 462 if (type != 0x00d7)
459 return -ENODEV; 463 return -ENODEV;
460 break; 464 break;
461 case PCI_CHIP_MACH64CX: 465 case PCI_CHIP_MACH64CX:
462 if(type != 0x0057) 466 if (type != 0x0057)
463 return -ENODEV; 467 return -ENODEV;
464 break; 468 break;
465#endif 469#endif
@@ -564,7 +568,8 @@ static char *aty_xl_ram[8] __devinitdata = {
564}; 568};
565#endif /* CONFIG_FB_ATY_CT */ 569#endif /* CONFIG_FB_ATY_CT */
566 570
567static u32 atyfb_get_pixclock(struct fb_var_screeninfo *var, struct atyfb_par *par) 571static u32 atyfb_get_pixclock(struct fb_var_screeninfo *var,
572 struct atyfb_par *par)
568{ 573{
569 u32 pixclock = var->pixclock; 574 u32 pixclock = var->pixclock;
570#ifdef CONFIG_FB_ATY_GENERIC_LCD 575#ifdef CONFIG_FB_ATY_GENERIC_LCD
@@ -572,7 +577,7 @@ static u32 atyfb_get_pixclock(struct fb_var_screeninfo *var, struct atyfb_par *p
572 par->pll.ct.xres = 0; 577 par->pll.ct.xres = 0;
573 if (par->lcd_table != 0) { 578 if (par->lcd_table != 0) {
574 lcd_on_off = aty_ld_lcd(LCD_GEN_CNTL, par); 579 lcd_on_off = aty_ld_lcd(LCD_GEN_CNTL, par);
575 if(lcd_on_off & LCD_ON) { 580 if (lcd_on_off & LCD_ON) {
576 par->pll.ct.xres = var->xres; 581 par->pll.ct.xres = var->xres;
577 pixclock = par->lcd_pixclock; 582 pixclock = par->lcd_pixclock;
578 } 583 }
@@ -584,7 +589,7 @@ static u32 atyfb_get_pixclock(struct fb_var_screeninfo *var, struct atyfb_par *p
584#if defined(CONFIG_PPC) 589#if defined(CONFIG_PPC)
585 590
586/* 591/*
587 * Apple monitor sense 592 * Apple monitor sense
588 */ 593 */
589 594
590static int __devinit read_aty_sense(const struct atyfb_par *par) 595static int __devinit read_aty_sense(const struct atyfb_par *par)
@@ -625,16 +630,16 @@ static int __devinit read_aty_sense(const struct atyfb_par *par)
625/* ------------------------------------------------------------------------- */ 630/* ------------------------------------------------------------------------- */
626 631
627/* 632/*
628 * CRTC programming 633 * CRTC programming
629 */ 634 */
630 635
631static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc) 636static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc)
632{ 637{
633#ifdef CONFIG_FB_ATY_GENERIC_LCD 638#ifdef CONFIG_FB_ATY_GENERIC_LCD
634 if (par->lcd_table != 0) { 639 if (par->lcd_table != 0) {
635 if(!M64_HAS(LT_LCD_REGS)) { 640 if (!M64_HAS(LT_LCD_REGS)) {
636 crtc->lcd_index = aty_ld_le32(LCD_INDEX, par); 641 crtc->lcd_index = aty_ld_le32(LCD_INDEX, par);
637 aty_st_le32(LCD_INDEX, crtc->lcd_index, par); 642 aty_st_le32(LCD_INDEX, crtc->lcd_index, par);
638 } 643 }
639 crtc->lcd_config_panel = aty_ld_lcd(CNFG_PANEL, par); 644 crtc->lcd_config_panel = aty_ld_lcd(CNFG_PANEL, par);
640 crtc->lcd_gen_cntl = aty_ld_lcd(LCD_GEN_CNTL, par); 645 crtc->lcd_gen_cntl = aty_ld_lcd(LCD_GEN_CNTL, par);
@@ -642,7 +647,7 @@ static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc)
642 647
643 /* switch to non shadow registers */ 648 /* switch to non shadow registers */
644 aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl & 649 aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl &
645 ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par); 650 ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par);
646 651
647 /* save stretching */ 652 /* save stretching */
648 crtc->horz_stretching = aty_ld_lcd(HORZ_STRETCHING, par); 653 crtc->horz_stretching = aty_ld_lcd(HORZ_STRETCHING, par);
@@ -663,7 +668,7 @@ static void aty_get_crtc(const struct atyfb_par *par, struct crtc *crtc)
663 if (par->lcd_table != 0) { 668 if (par->lcd_table != 0) {
664 /* switch to shadow registers */ 669 /* switch to shadow registers */
665 aty_st_lcd(LCD_GEN_CNTL, (crtc->lcd_gen_cntl & ~CRTC_RW_SELECT) | 670 aty_st_lcd(LCD_GEN_CNTL, (crtc->lcd_gen_cntl & ~CRTC_RW_SELECT) |
666 SHADOW_EN | SHADOW_RW_EN, par); 671 SHADOW_EN | SHADOW_RW_EN, par);
667 672
668 crtc->shadow_h_tot_disp = aty_ld_le32(CRTC_H_TOTAL_DISP, par); 673 crtc->shadow_h_tot_disp = aty_ld_le32(CRTC_H_TOTAL_DISP, par);
669 crtc->shadow_h_sync_strt_wid = aty_ld_le32(CRTC_H_SYNC_STRT_WID, par); 674 crtc->shadow_h_sync_strt_wid = aty_ld_le32(CRTC_H_SYNC_STRT_WID, par);
@@ -680,21 +685,20 @@ static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc)
680#ifdef CONFIG_FB_ATY_GENERIC_LCD 685#ifdef CONFIG_FB_ATY_GENERIC_LCD
681 if (par->lcd_table != 0) { 686 if (par->lcd_table != 0) {
682 /* stop CRTC */ 687 /* stop CRTC */
683 aty_st_le32(CRTC_GEN_CNTL, crtc->gen_cntl & ~(CRTC_EXT_DISP_EN | CRTC_EN), par); 688 aty_st_le32(CRTC_GEN_CNTL, crtc->gen_cntl &
689 ~(CRTC_EXT_DISP_EN | CRTC_EN), par);
684 690
685 /* update non-shadow registers first */ 691 /* update non-shadow registers first */
686 aty_st_lcd(CNFG_PANEL, crtc->lcd_config_panel, par); 692 aty_st_lcd(CNFG_PANEL, crtc->lcd_config_panel, par);
687 aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl & 693 aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl &
688 ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par); 694 ~(CRTC_RW_SELECT | SHADOW_EN | SHADOW_RW_EN), par);
689 695
690 /* temporarily disable stretching */ 696 /* temporarily disable stretching */
691 aty_st_lcd(HORZ_STRETCHING, 697 aty_st_lcd(HORZ_STRETCHING, crtc->horz_stretching &
692 crtc->horz_stretching & 698 ~(HORZ_STRETCH_MODE | HORZ_STRETCH_EN), par);
693 ~(HORZ_STRETCH_MODE | HORZ_STRETCH_EN), par); 699 aty_st_lcd(VERT_STRETCHING, crtc->vert_stretching &
694 aty_st_lcd(VERT_STRETCHING, 700 ~(VERT_STRETCH_RATIO1 | VERT_STRETCH_RATIO2 |
695 crtc->vert_stretching & 701 VERT_STRETCH_USE0 | VERT_STRETCH_EN), par);
696 ~(VERT_STRETCH_RATIO1 | VERT_STRETCH_RATIO2 |
697 VERT_STRETCH_USE0 | VERT_STRETCH_EN), par);
698 } 702 }
699#endif 703#endif
700 /* turn off CRT */ 704 /* turn off CRT */
@@ -702,17 +706,19 @@ static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc)
702 706
703 DPRINTK("setting up CRTC\n"); 707 DPRINTK("setting up CRTC\n");
704 DPRINTK("set primary CRT to %ix%i %c%c composite %c\n", 708 DPRINTK("set primary CRT to %ix%i %c%c composite %c\n",
705 ((((crtc->h_tot_disp>>16) & 0xff) + 1)<<3), (((crtc->v_tot_disp>>16) & 0x7ff) + 1), 709 ((((crtc->h_tot_disp >> 16) & 0xff) + 1) << 3),
706 (crtc->h_sync_strt_wid & 0x200000)?'N':'P', (crtc->v_sync_strt_wid & 0x200000)?'N':'P', 710 (((crtc->v_tot_disp >> 16) & 0x7ff) + 1),
707 (crtc->gen_cntl & CRTC_CSYNC_EN)?'P':'N'); 711 (crtc->h_sync_strt_wid & 0x200000) ? 'N' : 'P',
708 712 (crtc->v_sync_strt_wid & 0x200000) ? 'N' : 'P',
709 DPRINTK("CRTC_H_TOTAL_DISP: %x\n",crtc->h_tot_disp); 713 (crtc->gen_cntl & CRTC_CSYNC_EN) ? 'P' : 'N');
710 DPRINTK("CRTC_H_SYNC_STRT_WID: %x\n",crtc->h_sync_strt_wid); 714
711 DPRINTK("CRTC_V_TOTAL_DISP: %x\n",crtc->v_tot_disp); 715 DPRINTK("CRTC_H_TOTAL_DISP: %x\n", crtc->h_tot_disp);
712 DPRINTK("CRTC_V_SYNC_STRT_WID: %x\n",crtc->v_sync_strt_wid); 716 DPRINTK("CRTC_H_SYNC_STRT_WID: %x\n", crtc->h_sync_strt_wid);
717 DPRINTK("CRTC_V_TOTAL_DISP: %x\n", crtc->v_tot_disp);
718 DPRINTK("CRTC_V_SYNC_STRT_WID: %x\n", crtc->v_sync_strt_wid);
713 DPRINTK("CRTC_OFF_PITCH: %x\n", crtc->off_pitch); 719 DPRINTK("CRTC_OFF_PITCH: %x\n", crtc->off_pitch);
714 DPRINTK("CRTC_VLINE_CRNT_VLINE: %x\n", crtc->vline_crnt_vline); 720 DPRINTK("CRTC_VLINE_CRNT_VLINE: %x\n", crtc->vline_crnt_vline);
715 DPRINTK("CRTC_GEN_CNTL: %x\n",crtc->gen_cntl); 721 DPRINTK("CRTC_GEN_CNTL: %x\n", crtc->gen_cntl);
716 722
717 aty_st_le32(CRTC_H_TOTAL_DISP, crtc->h_tot_disp, par); 723 aty_st_le32(CRTC_H_TOTAL_DISP, crtc->h_tot_disp, par);
718 aty_st_le32(CRTC_H_SYNC_STRT_WID, crtc->h_sync_strt_wid, par); 724 aty_st_le32(CRTC_H_SYNC_STRT_WID, crtc->h_sync_strt_wid, par);
@@ -732,16 +738,22 @@ static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc)
732 if (par->lcd_table != 0) { 738 if (par->lcd_table != 0) {
733 /* switch to shadow registers */ 739 /* switch to shadow registers */
734 aty_st_lcd(LCD_GEN_CNTL, (crtc->lcd_gen_cntl & ~CRTC_RW_SELECT) | 740 aty_st_lcd(LCD_GEN_CNTL, (crtc->lcd_gen_cntl & ~CRTC_RW_SELECT) |
735 (SHADOW_EN | SHADOW_RW_EN), par); 741 SHADOW_EN | SHADOW_RW_EN, par);
736 742
737 DPRINTK("set shadow CRT to %ix%i %c%c\n", 743 DPRINTK("set shadow CRT to %ix%i %c%c\n",
738 ((((crtc->shadow_h_tot_disp>>16) & 0xff) + 1)<<3), (((crtc->shadow_v_tot_disp>>16) & 0x7ff) + 1), 744 ((((crtc->shadow_h_tot_disp >> 16) & 0xff) + 1) << 3),
739 (crtc->shadow_h_sync_strt_wid & 0x200000)?'N':'P', (crtc->shadow_v_sync_strt_wid & 0x200000)?'N':'P'); 745 (((crtc->shadow_v_tot_disp >> 16) & 0x7ff) + 1),
740 746 (crtc->shadow_h_sync_strt_wid & 0x200000) ? 'N' : 'P',
741 DPRINTK("SHADOW CRTC_H_TOTAL_DISP: %x\n", crtc->shadow_h_tot_disp); 747 (crtc->shadow_v_sync_strt_wid & 0x200000) ? 'N' : 'P');
742 DPRINTK("SHADOW CRTC_H_SYNC_STRT_WID: %x\n", crtc->shadow_h_sync_strt_wid); 748
743 DPRINTK("SHADOW CRTC_V_TOTAL_DISP: %x\n", crtc->shadow_v_tot_disp); 749 DPRINTK("SHADOW CRTC_H_TOTAL_DISP: %x\n",
744 DPRINTK("SHADOW CRTC_V_SYNC_STRT_WID: %x\n", crtc->shadow_v_sync_strt_wid); 750 crtc->shadow_h_tot_disp);
751 DPRINTK("SHADOW CRTC_H_SYNC_STRT_WID: %x\n",
752 crtc->shadow_h_sync_strt_wid);
753 DPRINTK("SHADOW CRTC_V_TOTAL_DISP: %x\n",
754 crtc->shadow_v_tot_disp);
755 DPRINTK("SHADOW CRTC_V_SYNC_STRT_WID: %x\n",
756 crtc->shadow_v_sync_strt_wid);
745 757
746 aty_st_le32(CRTC_H_TOTAL_DISP, crtc->shadow_h_tot_disp, par); 758 aty_st_le32(CRTC_H_TOTAL_DISP, crtc->shadow_h_tot_disp, par);
747 aty_st_le32(CRTC_H_SYNC_STRT_WID, crtc->shadow_h_sync_strt_wid, par); 759 aty_st_le32(CRTC_H_SYNC_STRT_WID, crtc->shadow_h_sync_strt_wid, par);
@@ -752,16 +764,16 @@ static void aty_set_crtc(const struct atyfb_par *par, const struct crtc *crtc)
752 DPRINTK("LCD_GEN_CNTL: %x\n", crtc->lcd_gen_cntl); 764 DPRINTK("LCD_GEN_CNTL: %x\n", crtc->lcd_gen_cntl);
753 DPRINTK("HORZ_STRETCHING: %x\n", crtc->horz_stretching); 765 DPRINTK("HORZ_STRETCHING: %x\n", crtc->horz_stretching);
754 DPRINTK("VERT_STRETCHING: %x\n", crtc->vert_stretching); 766 DPRINTK("VERT_STRETCHING: %x\n", crtc->vert_stretching);
755 if(!M64_HAS(LT_LCD_REGS)) 767 if (!M64_HAS(LT_LCD_REGS))
756 DPRINTK("EXT_VERT_STRETCH: %x\n", crtc->ext_vert_stretch); 768 DPRINTK("EXT_VERT_STRETCH: %x\n", crtc->ext_vert_stretch);
757 769
758 aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl, par); 770 aty_st_lcd(LCD_GEN_CNTL, crtc->lcd_gen_cntl, par);
759 aty_st_lcd(HORZ_STRETCHING, crtc->horz_stretching, par); 771 aty_st_lcd(HORZ_STRETCHING, crtc->horz_stretching, par);
760 aty_st_lcd(VERT_STRETCHING, crtc->vert_stretching, par); 772 aty_st_lcd(VERT_STRETCHING, crtc->vert_stretching, par);
761 if(!M64_HAS(LT_LCD_REGS)) { 773 if (!M64_HAS(LT_LCD_REGS)) {
762 aty_st_lcd(EXT_VERT_STRETCH, crtc->ext_vert_stretch, par); 774 aty_st_lcd(EXT_VERT_STRETCH, crtc->ext_vert_stretch, par);
763 aty_ld_le32(LCD_INDEX, par); 775 aty_ld_le32(LCD_INDEX, par);
764 aty_st_le32(LCD_INDEX, crtc->lcd_index, par); 776 aty_st_le32(LCD_INDEX, crtc->lcd_index, par);
765 } 777 }
766 } 778 }
767#endif /* CONFIG_FB_ATY_GENERIC_LCD */ 779#endif /* CONFIG_FB_ATY_GENERIC_LCD */
@@ -779,7 +791,8 @@ static u32 calc_line_length(struct atyfb_par *par, u32 vxres, u32 bpp)
779} 791}
780 792
781static int aty_var_to_crtc(const struct fb_info *info, 793static int aty_var_to_crtc(const struct fb_info *info,
782 const struct fb_var_screeninfo *var, struct crtc *crtc) 794 const struct fb_var_screeninfo *var,
795 struct crtc *crtc)
783{ 796{
784 struct atyfb_par *par = (struct atyfb_par *) info->par; 797 struct atyfb_par *par = (struct atyfb_par *) info->par;
785 u32 xres, yres, vxres, vyres, xoffset, yoffset, bpp; 798 u32 xres, yres, vxres, vyres, xoffset, yoffset, bpp;
@@ -814,34 +827,32 @@ static int aty_var_to_crtc(const struct fb_info *info,
814 if (bpp <= 8) { 827 if (bpp <= 8) {
815 bpp = 8; 828 bpp = 8;
816 pix_width = CRTC_PIX_WIDTH_8BPP; 829 pix_width = CRTC_PIX_WIDTH_8BPP;
817 dp_pix_width = 830 dp_pix_width = HOST_8BPP | SRC_8BPP | DST_8BPP |
818 HOST_8BPP | SRC_8BPP | DST_8BPP | 831 BYTE_ORDER_LSB_TO_MSB;
819 BYTE_ORDER_LSB_TO_MSB;
820 dp_chain_mask = DP_CHAIN_8BPP; 832 dp_chain_mask = DP_CHAIN_8BPP;
821 } else if (bpp <= 15) { 833 } else if (bpp <= 15) {
822 bpp = 16; 834 bpp = 16;
823 pix_width = CRTC_PIX_WIDTH_15BPP; 835 pix_width = CRTC_PIX_WIDTH_15BPP;
824 dp_pix_width = HOST_15BPP | SRC_15BPP | DST_15BPP | 836 dp_pix_width = HOST_15BPP | SRC_15BPP | DST_15BPP |
825 BYTE_ORDER_LSB_TO_MSB; 837 BYTE_ORDER_LSB_TO_MSB;
826 dp_chain_mask = DP_CHAIN_15BPP; 838 dp_chain_mask = DP_CHAIN_15BPP;
827 } else if (bpp <= 16) { 839 } else if (bpp <= 16) {
828 bpp = 16; 840 bpp = 16;
829 pix_width = CRTC_PIX_WIDTH_16BPP; 841 pix_width = CRTC_PIX_WIDTH_16BPP;
830 dp_pix_width = HOST_16BPP | SRC_16BPP | DST_16BPP | 842 dp_pix_width = HOST_16BPP | SRC_16BPP | DST_16BPP |
831 BYTE_ORDER_LSB_TO_MSB; 843 BYTE_ORDER_LSB_TO_MSB;
832 dp_chain_mask = DP_CHAIN_16BPP; 844 dp_chain_mask = DP_CHAIN_16BPP;
833 } else if (bpp <= 24 && M64_HAS(INTEGRATED)) { 845 } else if (bpp <= 24 && M64_HAS(INTEGRATED)) {
834 bpp = 24; 846 bpp = 24;
835 pix_width = CRTC_PIX_WIDTH_24BPP; 847 pix_width = CRTC_PIX_WIDTH_24BPP;
836 dp_pix_width = 848 dp_pix_width = HOST_8BPP | SRC_8BPP | DST_8BPP |
837 HOST_8BPP | SRC_8BPP | DST_8BPP | 849 BYTE_ORDER_LSB_TO_MSB;
838 BYTE_ORDER_LSB_TO_MSB;
839 dp_chain_mask = DP_CHAIN_24BPP; 850 dp_chain_mask = DP_CHAIN_24BPP;
840 } else if (bpp <= 32) { 851 } else if (bpp <= 32) {
841 bpp = 32; 852 bpp = 32;
842 pix_width = CRTC_PIX_WIDTH_32BPP; 853 pix_width = CRTC_PIX_WIDTH_32BPP;
843 dp_pix_width = HOST_32BPP | SRC_32BPP | DST_32BPP | 854 dp_pix_width = HOST_32BPP | SRC_32BPP | DST_32BPP |
844 BYTE_ORDER_LSB_TO_MSB; 855 BYTE_ORDER_LSB_TO_MSB;
845 dp_chain_mask = DP_CHAIN_32BPP; 856 dp_chain_mask = DP_CHAIN_32BPP;
846 } else 857 } else
847 FAIL("invalid bpp"); 858 FAIL("invalid bpp");
@@ -854,9 +865,9 @@ static int aty_var_to_crtc(const struct fb_info *info,
854 h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1; 865 h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
855 v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1; 866 v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
856 867
857 if((xres > 1600) || (yres > 1200)) { 868 if ((xres > 1600) || (yres > 1200)) {
858 FAIL("MACH64 chips are designed for max 1600x1200\n" 869 FAIL("MACH64 chips are designed for max 1600x1200\n"
859 "select anoter resolution."); 870 "select anoter resolution.");
860 } 871 }
861 h_sync_strt = h_disp + var->right_margin; 872 h_sync_strt = h_disp + var->right_margin;
862 h_sync_end = h_sync_strt + var->hsync_len; 873 h_sync_end = h_sync_strt + var->hsync_len;
@@ -869,11 +880,12 @@ static int aty_var_to_crtc(const struct fb_info *info,
869 880
870#ifdef CONFIG_FB_ATY_GENERIC_LCD 881#ifdef CONFIG_FB_ATY_GENERIC_LCD
871 if (par->lcd_table != 0) { 882 if (par->lcd_table != 0) {
872 if(!M64_HAS(LT_LCD_REGS)) { 883 if (!M64_HAS(LT_LCD_REGS)) {
873 u32 lcd_index = aty_ld_le32(LCD_INDEX, par); 884 u32 lcd_index = aty_ld_le32(LCD_INDEX, par);
874 crtc->lcd_index = lcd_index & 885 crtc->lcd_index = lcd_index &
875 ~(LCD_INDEX_MASK | LCD_DISPLAY_DIS | LCD_SRC_SEL | CRTC2_DISPLAY_DIS); 886 ~(LCD_INDEX_MASK | LCD_DISPLAY_DIS |
876 aty_st_le32(LCD_INDEX, lcd_index, par); 887 LCD_SRC_SEL | CRTC2_DISPLAY_DIS);
888 aty_st_le32(LCD_INDEX, lcd_index, par);
877 } 889 }
878 890
879 if (!M64_HAS(MOBIL_BUS)) 891 if (!M64_HAS(MOBIL_BUS))
@@ -888,12 +900,14 @@ static int aty_var_to_crtc(const struct fb_info *info,
888 USE_SHADOWED_ROWCUR | SHADOW_EN | SHADOW_RW_EN); 900 USE_SHADOWED_ROWCUR | SHADOW_EN | SHADOW_RW_EN);
889 crtc->lcd_gen_cntl |= DONT_SHADOW_VPAR | LOCK_8DOT; 901 crtc->lcd_gen_cntl |= DONT_SHADOW_VPAR | LOCK_8DOT;
890 902
891 if((crtc->lcd_gen_cntl & LCD_ON) && 903 if ((crtc->lcd_gen_cntl & LCD_ON) &&
892 ((xres > par->lcd_width) || (yres > par->lcd_height))) { 904 ((xres > par->lcd_width) || (yres > par->lcd_height))) {
893 /* We cannot display the mode on the LCD. If the CRT is enabled 905 /*
894 we can turn off the LCD. 906 * We cannot display the mode on the LCD. If the CRT is
895 If the CRT is off, it isn't a good idea to switch it on; we don't 907 * enabled we can turn off the LCD.
896 know if one is connected. So it's better to fail then. 908 * If the CRT is off, it isn't a good idea to switch it
909 * on; we don't know if one is connected. So it's better
910 * to fail then.
897 */ 911 */
898 if (crtc->lcd_gen_cntl & CRT_ON) { 912 if (crtc->lcd_gen_cntl & CRT_ON) {
899 if (!(var->activate & FB_ACTIVATE_TEST)) 913 if (!(var->activate & FB_ACTIVATE_TEST))
@@ -916,17 +930,18 @@ static int aty_var_to_crtc(const struct fb_info *info,
916 930
917 vmode &= ~(FB_VMODE_DOUBLE | FB_VMODE_INTERLACED); 931 vmode &= ~(FB_VMODE_DOUBLE | FB_VMODE_INTERLACED);
918 932
919 /* This is horror! When we simulate, say 640x480 on an 800x600 933 /*
920 LCD monitor, the CRTC should be programmed 800x600 values for 934 * This is horror! When we simulate, say 640x480 on an 800x600
921 the non visible part, but 640x480 for the visible part. 935 * LCD monitor, the CRTC should be programmed 800x600 values for
922 This code has been tested on a laptop with it's 1400x1050 LCD 936 * the non visible part, but 640x480 for the visible part.
923 monitor and a conventional monitor both switched on. 937 * This code has been tested on a laptop with it's 1400x1050 LCD
924 Tested modes: 1280x1024, 1152x864, 1024x768, 800x600, 938 * monitor and a conventional monitor both switched on.
925 works with little glitches also with DOUBLESCAN modes 939 * Tested modes: 1280x1024, 1152x864, 1024x768, 800x600,
940 * works with little glitches also with DOUBLESCAN modes
926 */ 941 */
927 if (yres < par->lcd_height) { 942 if (yres < par->lcd_height) {
928 VScan = par->lcd_height / yres; 943 VScan = par->lcd_height / yres;
929 if(VScan > 1) { 944 if (VScan > 1) {
930 VScan = 2; 945 VScan = 2;
931 vmode |= FB_VMODE_DOUBLE; 946 vmode |= FB_VMODE_DOUBLE;
932 } 947 }
@@ -952,7 +967,7 @@ static int aty_var_to_crtc(const struct fb_info *info,
952 FAIL_MAX("h_disp too large", h_disp, 0xff); 967 FAIL_MAX("h_disp too large", h_disp, 0xff);
953 FAIL_MAX("h_sync_strt too large", h_sync_strt, 0x1ff); 968 FAIL_MAX("h_sync_strt too large", h_sync_strt, 0x1ff);
954 /*FAIL_MAX("h_sync_wid too large", h_sync_wid, 0x1f);*/ 969 /*FAIL_MAX("h_sync_wid too large", h_sync_wid, 0x1f);*/
955 if(h_sync_wid > 0x1f) 970 if (h_sync_wid > 0x1f)
956 h_sync_wid = 0x1f; 971 h_sync_wid = 0x1f;
957 FAIL_MAX("h_total too large", h_total, 0x1ff); 972 FAIL_MAX("h_total too large", h_total, 0x1ff);
958 973
@@ -978,7 +993,7 @@ static int aty_var_to_crtc(const struct fb_info *info,
978 FAIL_MAX("v_disp too large", v_disp, 0x7ff); 993 FAIL_MAX("v_disp too large", v_disp, 0x7ff);
979 FAIL_MAX("v_sync_stsrt too large", v_sync_strt, 0x7ff); 994 FAIL_MAX("v_sync_stsrt too large", v_sync_strt, 0x7ff);
980 /*FAIL_MAX("v_sync_wid too large", v_sync_wid, 0x1f);*/ 995 /*FAIL_MAX("v_sync_wid too large", v_sync_wid, 0x1f);*/
981 if(v_sync_wid > 0x1f) 996 if (v_sync_wid > 0x1f)
982 v_sync_wid = 0x1f; 997 v_sync_wid = 0x1f;
983 FAIL_MAX("v_total too large", v_total, 0x7ff); 998 FAIL_MAX("v_total too large", v_total, 0x7ff);
984 999
@@ -995,11 +1010,13 @@ static int aty_var_to_crtc(const struct fb_info *info,
995 ((line_length / bpp) << 22); 1010 ((line_length / bpp) << 22);
996 crtc->vline_crnt_vline = 0; 1011 crtc->vline_crnt_vline = 0;
997 1012
998 crtc->h_tot_disp = h_total | (h_disp<<16); 1013 crtc->h_tot_disp = h_total | (h_disp << 16);
999 crtc->h_sync_strt_wid = (h_sync_strt & 0xff) | (h_sync_dly<<8) | 1014 crtc->h_sync_strt_wid = (h_sync_strt & 0xff) | (h_sync_dly << 8) |
1000 ((h_sync_strt & 0x100)<<4) | (h_sync_wid<<16) | (h_sync_pol<<21); 1015 ((h_sync_strt & 0x100) << 4) | (h_sync_wid << 16) |
1001 crtc->v_tot_disp = v_total | (v_disp<<16); 1016 (h_sync_pol << 21);
1002 crtc->v_sync_strt_wid = v_sync_strt | (v_sync_wid<<16) | (v_sync_pol<<21); 1017 crtc->v_tot_disp = v_total | (v_disp << 16);
1018 crtc->v_sync_strt_wid = v_sync_strt | (v_sync_wid << 16) |
1019 (v_sync_pol << 21);
1003 1020
1004 /* crtc->gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_PRESERVED_MASK; */ 1021 /* crtc->gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_PRESERVED_MASK; */
1005 crtc->gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN | pix_width | c_sync; 1022 crtc->gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN | pix_width | c_sync;
@@ -1014,13 +1031,15 @@ static int aty_var_to_crtc(const struct fb_info *info,
1014#ifdef CONFIG_FB_ATY_GENERIC_LCD 1031#ifdef CONFIG_FB_ATY_GENERIC_LCD
1015 if (par->lcd_table != 0) { 1032 if (par->lcd_table != 0) {
1016 vdisplay = yres; 1033 vdisplay = yres;
1017 if(vmode & FB_VMODE_DOUBLE) 1034 if (vmode & FB_VMODE_DOUBLE)
1018 vdisplay <<= 1; 1035 vdisplay <<= 1;
1019 crtc->gen_cntl &= ~(CRTC2_EN | CRTC2_PIX_WIDTH); 1036 crtc->gen_cntl &= ~(CRTC2_EN | CRTC2_PIX_WIDTH);
1020 crtc->lcd_gen_cntl &= ~(HORZ_DIVBY2_EN | DIS_HOR_CRT_DIVBY2 | 1037 crtc->lcd_gen_cntl &= ~(HORZ_DIVBY2_EN | DIS_HOR_CRT_DIVBY2 |
1021 /*TVCLK_PM_EN | VCLK_DAC_PM_EN |*/ 1038 /*TVCLK_PM_EN | VCLK_DAC_PM_EN |*/
1022 USE_SHADOWED_VEND | USE_SHADOWED_ROWCUR | SHADOW_EN | SHADOW_RW_EN); 1039 USE_SHADOWED_VEND |
1023 crtc->lcd_gen_cntl |= (DONT_SHADOW_VPAR/* | LOCK_8DOT*/); 1040 USE_SHADOWED_ROWCUR |
1041 SHADOW_EN | SHADOW_RW_EN);
1042 crtc->lcd_gen_cntl |= DONT_SHADOW_VPAR/* | LOCK_8DOT*/;
1024 1043
1025 /* MOBILITY M1 tested, FIXME: LT */ 1044 /* MOBILITY M1 tested, FIXME: LT */
1026 crtc->horz_stretching = aty_ld_lcd(HORZ_STRETCHING, par); 1045 crtc->horz_stretching = aty_ld_lcd(HORZ_STRETCHING, par);
@@ -1028,28 +1047,32 @@ static int aty_var_to_crtc(const struct fb_info *info,
1028 crtc->ext_vert_stretch = aty_ld_lcd(EXT_VERT_STRETCH, par) & 1047 crtc->ext_vert_stretch = aty_ld_lcd(EXT_VERT_STRETCH, par) &
1029 ~(AUTO_VERT_RATIO | VERT_STRETCH_MODE | VERT_STRETCH_RATIO3); 1048 ~(AUTO_VERT_RATIO | VERT_STRETCH_MODE | VERT_STRETCH_RATIO3);
1030 1049
1031 crtc->horz_stretching &= 1050 crtc->horz_stretching &= ~(HORZ_STRETCH_RATIO |
1032 ~(HORZ_STRETCH_RATIO | HORZ_STRETCH_LOOP | AUTO_HORZ_RATIO | 1051 HORZ_STRETCH_LOOP | AUTO_HORZ_RATIO |
1033 HORZ_STRETCH_MODE | HORZ_STRETCH_EN); 1052 HORZ_STRETCH_MODE | HORZ_STRETCH_EN);
1034 if (xres < par->lcd_width && crtc->lcd_gen_cntl & LCD_ON) { 1053 if (xres < par->lcd_width && crtc->lcd_gen_cntl & LCD_ON) {
1035 do { 1054 do {
1036 /* 1055 /*
1037 * The horizontal blender misbehaves when HDisplay is less than a 1056 * The horizontal blender misbehaves when
1038 * a certain threshold (440 for a 1024-wide panel). It doesn't 1057 * HDisplay is less than a certain threshold
1039 * stretch such modes enough. Use pixel replication instead of 1058 * (440 for a 1024-wide panel). It doesn't
1040 * blending to stretch modes that can be made to exactly fit the 1059 * stretch such modes enough. Use pixel
1041 * panel width. The undocumented "NoLCDBlend" option allows the 1060 * replication instead of blending to stretch
1042 * pixel-replicated mode to be slightly wider or narrower than the 1061 * modes that can be made to exactly fit the
1043 * panel width. It also causes a mode that is exactly half as wide 1062 * panel width. The undocumented "NoLCDBlend"
1044 * as the panel to be pixel-replicated, rather than blended. 1063 * option allows the pixel-replicated mode to
1045 */ 1064 * be slightly wider or narrower than the
1065 * panel width. It also causes a mode that is
1066 * exactly half as wide as the panel to be
1067 * pixel-replicated, rather than blended.
1068 */
1046 int HDisplay = xres & ~7; 1069 int HDisplay = xres & ~7;
1047 int nStretch = par->lcd_width / HDisplay; 1070 int nStretch = par->lcd_width / HDisplay;
1048 int Remainder = par->lcd_width % HDisplay; 1071 int Remainder = par->lcd_width % HDisplay;
1049 1072
1050 if ((!Remainder && ((nStretch > 2))) || 1073 if ((!Remainder && ((nStretch > 2))) ||
1051 (((HDisplay * 16) / par->lcd_width) < 7)) { 1074 (((HDisplay * 16) / par->lcd_width) < 7)) {
1052 static const char StretchLoops[] = {10, 12, 13, 15, 16}; 1075 static const char StretchLoops[] = { 10, 12, 13, 15, 16 };
1053 int horz_stretch_loop = -1, BestRemainder; 1076 int horz_stretch_loop = -1, BestRemainder;
1054 int Numerator = HDisplay, Denominator = par->lcd_width; 1077 int Numerator = HDisplay, Denominator = par->lcd_width;
1055 int Index = 5; 1078 int Index = 5;
@@ -1098,12 +1121,12 @@ static int aty_var_to_crtc(const struct fb_info *info,
1098 (((vdisplay * (VERT_STRETCH_RATIO0 + 1)) / par->lcd_height) & VERT_STRETCH_RATIO0)); 1121 (((vdisplay * (VERT_STRETCH_RATIO0 + 1)) / par->lcd_height) & VERT_STRETCH_RATIO0));
1099 1122
1100 if (!M64_HAS(LT_LCD_REGS) && 1123 if (!M64_HAS(LT_LCD_REGS) &&
1101 xres <= (M64_HAS(MOBIL_BUS)?1024:800)) 1124 xres <= (M64_HAS(MOBIL_BUS) ? 1024 : 800))
1102 crtc->ext_vert_stretch |= VERT_STRETCH_MODE; 1125 crtc->ext_vert_stretch |= VERT_STRETCH_MODE;
1103 } else { 1126 } else {
1104 /* 1127 /*
1105 * Don't use vertical blending if the mode is too wide or not 1128 * Don't use vertical blending if the mode is too wide
1106 * vertically stretched. 1129 * or not vertically stretched.
1107 */ 1130 */
1108 crtc->vert_stretching = 0; 1131 crtc->vert_stretching = 0;
1109 } 1132 }
@@ -1125,11 +1148,11 @@ static int aty_var_to_crtc(const struct fb_info *info,
1125 return 0; 1148 return 0;
1126} 1149}
1127 1150
1128static int aty_crtc_to_var(const struct crtc *crtc, struct fb_var_screeninfo *var) 1151static int aty_crtc_to_var(const struct crtc *crtc,
1152 struct fb_var_screeninfo *var)
1129{ 1153{
1130 u32 xres, yres, bpp, left, right, upper, lower, hslen, vslen, sync; 1154 u32 xres, yres, bpp, left, right, upper, lower, hslen, vslen, sync;
1131 u32 h_total, h_disp, h_sync_strt, h_sync_dly, h_sync_wid, 1155 u32 h_total, h_disp, h_sync_strt, h_sync_dly, h_sync_wid, h_sync_pol;
1132 h_sync_pol;
1133 u32 v_total, v_disp, v_sync_strt, v_sync_wid, v_sync_pol, c_sync; 1156 u32 v_total, v_disp, v_sync_strt, v_sync_wid, v_sync_pol, c_sync;
1134 u32 pix_width; 1157 u32 pix_width;
1135 u32 double_scan, interlace; 1158 u32 double_scan, interlace;
@@ -1161,8 +1184,8 @@ static int aty_crtc_to_var(const struct crtc *crtc, struct fb_var_screeninfo *va
1161 lower = v_sync_strt - v_disp; 1184 lower = v_sync_strt - v_disp;
1162 vslen = v_sync_wid; 1185 vslen = v_sync_wid;
1163 sync = (h_sync_pol ? 0 : FB_SYNC_HOR_HIGH_ACT) | 1186 sync = (h_sync_pol ? 0 : FB_SYNC_HOR_HIGH_ACT) |
1164 (v_sync_pol ? 0 : FB_SYNC_VERT_HIGH_ACT) | 1187 (v_sync_pol ? 0 : FB_SYNC_VERT_HIGH_ACT) |
1165 (c_sync ? FB_SYNC_COMP_HIGH_ACT : 0); 1188 (c_sync ? FB_SYNC_COMP_HIGH_ACT : 0);
1166 1189
1167 switch (pix_width) { 1190 switch (pix_width) {
1168#if 0 1191#if 0
@@ -1252,20 +1275,21 @@ static int aty_crtc_to_var(const struct crtc *crtc, struct fb_var_screeninfo *va
1252 var->vsync_len = vslen; 1275 var->vsync_len = vslen;
1253 var->sync = sync; 1276 var->sync = sync;
1254 var->vmode = FB_VMODE_NONINTERLACED; 1277 var->vmode = FB_VMODE_NONINTERLACED;
1255 /* In double scan mode, the vertical parameters are doubled, so we need to 1278 /*
1256 half them to get the right values. 1279 * In double scan mode, the vertical parameters are doubled,
1257 In interlaced mode the values are already correct, so no correction is 1280 * so we need to halve them to get the right values.
1258 necessary. 1281 * In interlaced mode the values are already correct,
1282 * so no correction is necessary.
1259 */ 1283 */
1260 if (interlace) 1284 if (interlace)
1261 var->vmode = FB_VMODE_INTERLACED; 1285 var->vmode = FB_VMODE_INTERLACED;
1262 1286
1263 if (double_scan) { 1287 if (double_scan) {
1264 var->vmode = FB_VMODE_DOUBLE; 1288 var->vmode = FB_VMODE_DOUBLE;
1265 var->yres>>=1; 1289 var->yres >>= 1;
1266 var->upper_margin>>=1; 1290 var->upper_margin >>= 1;
1267 var->lower_margin>>=1; 1291 var->lower_margin >>= 1;
1268 var->vsync_len>>=1; 1292 var->vsync_len >>= 1;
1269 } 1293 }
1270 1294
1271 return 0; 1295 return 0;
@@ -1286,7 +1310,8 @@ static int atyfb_set_par(struct fb_info *info)
1286 if (par->asleep) 1310 if (par->asleep)
1287 return 0; 1311 return 0;
1288 1312
1289 if ((err = aty_var_to_crtc(info, var, &par->crtc))) 1313 err = aty_var_to_crtc(info, var, &par->crtc);
1314 if (err)
1290 return err; 1315 return err;
1291 1316
1292 pixclock = atyfb_get_pixclock(var, par); 1317 pixclock = atyfb_get_pixclock(var, par);
@@ -1295,7 +1320,9 @@ static int atyfb_set_par(struct fb_info *info)
1295 PRINTKE("Invalid pixclock\n"); 1320 PRINTKE("Invalid pixclock\n");
1296 return -EINVAL; 1321 return -EINVAL;
1297 } else { 1322 } else {
1298 if((err = par->pll_ops->var_to_pll(info, pixclock, var->bits_per_pixel, &par->pll))) 1323 err = par->pll_ops->var_to_pll(info, pixclock,
1324 var->bits_per_pixel, &par->pll);
1325 if (err)
1299 return err; 1326 return err;
1300 } 1327 }
1301 1328
@@ -1313,22 +1340,23 @@ static int atyfb_set_par(struct fb_info *info)
1313 wait_for_idle(par); 1340 wait_for_idle(par);
1314 1341
1315 aty_set_crtc(par, &par->crtc); 1342 aty_set_crtc(par, &par->crtc);
1316 par->dac_ops->set_dac(info, &par->pll, var->bits_per_pixel, par->accel_flags); 1343 par->dac_ops->set_dac(info, &par->pll,
1344 var->bits_per_pixel, par->accel_flags);
1317 par->pll_ops->set_pll(info, &par->pll); 1345 par->pll_ops->set_pll(info, &par->pll);
1318 1346
1319#ifdef DEBUG 1347#ifdef DEBUG
1320 if(par->pll_ops && par->pll_ops->pll_to_var) 1348 if (par->pll_ops && par->pll_ops->pll_to_var)
1321 pixclock_in_ps = par->pll_ops->pll_to_var(info, &(par->pll)); 1349 pixclock_in_ps = par->pll_ops->pll_to_var(info, &par->pll);
1322 else 1350 else
1323 pixclock_in_ps = 0; 1351 pixclock_in_ps = 0;
1324 1352
1325 if(0 == pixclock_in_ps) { 1353 if (0 == pixclock_in_ps) {
1326 PRINTKE("ALERT ops->pll_to_var get 0\n"); 1354 PRINTKE("ALERT ops->pll_to_var get 0\n");
1327 pixclock_in_ps = pixclock; 1355 pixclock_in_ps = pixclock;
1328 } 1356 }
1329 1357
1330 memset(&debug, 0, sizeof(debug)); 1358 memset(&debug, 0, sizeof(debug));
1331 if(!aty_crtc_to_var(&(par->crtc), &debug)) { 1359 if (!aty_crtc_to_var(&par->crtc, &debug)) {
1332 u32 hSync, vRefresh; 1360 u32 hSync, vRefresh;
1333 u32 h_disp, h_sync_strt, h_sync_end, h_total; 1361 u32 h_disp, h_sync_strt, h_sync_end, h_total;
1334 u32 v_disp, v_sync_strt, v_sync_end, v_total; 1362 u32 v_disp, v_sync_strt, v_sync_end, v_total;
@@ -1344,16 +1372,20 @@ static int atyfb_set_par(struct fb_info *info)
1344 1372
1345 hSync = 1000000000 / (pixclock_in_ps * h_total); 1373 hSync = 1000000000 / (pixclock_in_ps * h_total);
1346 vRefresh = (hSync * 1000) / v_total; 1374 vRefresh = (hSync * 1000) / v_total;
1347 if (par->crtc.gen_cntl & CRTC_INTERLACE_EN) 1375 if (par->crtc.gen_cntl & CRTC_INTERLACE_EN)
1348 vRefresh *= 2; 1376 vRefresh *= 2;
1349 if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN) 1377 if (par->crtc.gen_cntl & CRTC_DBL_SCAN_EN)
1350 vRefresh /= 2; 1378 vRefresh /= 2;
1351 1379
1352 DPRINTK("atyfb_set_par\n"); 1380 DPRINTK("atyfb_set_par\n");
1353 DPRINTK(" Set Visible Mode to %ix%i-%i\n", var->xres, var->yres, var->bits_per_pixel); 1381 DPRINTK(" Set Visible Mode to %ix%i-%i\n",
1354 DPRINTK(" Virtual resolution %ix%i, pixclock_in_ps %i (calculated %i)\n", 1382 var->xres, var->yres, var->bits_per_pixel);
1355 var->xres_virtual, var->yres_virtual, pixclock, pixclock_in_ps); 1383 DPRINTK(" Virtual resolution %ix%i, "
1356 DPRINTK(" Dot clock: %i MHz\n", 1000000 / pixclock_in_ps); 1384 "pixclock_in_ps %i (calculated %i)\n",
1385 var->xres_virtual, var->yres_virtual,
1386 pixclock, pixclock_in_ps);
1387 DPRINTK(" Dot clock: %i MHz\n",
1388 1000000 / pixclock_in_ps);
1357 DPRINTK(" Horizontal sync: %i kHz\n", hSync); 1389 DPRINTK(" Horizontal sync: %i kHz\n", hSync);
1358 DPRINTK(" Vertical refresh: %i Hz\n", vRefresh); 1390 DPRINTK(" Vertical refresh: %i Hz\n", vRefresh);
1359 DPRINTK(" x style: %i.%03i %i %i %i %i %i %i %i %i\n", 1391 DPRINTK(" x style: %i.%03i %i %i %i %i %i %i %i %i\n",
@@ -1448,7 +1480,8 @@ static int atyfb_set_par(struct fb_info *info)
1448 base = 0x2000; 1480 base = 0x2000;
1449 printk("debug atyfb: Mach64 non-shadow register values:"); 1481 printk("debug atyfb: Mach64 non-shadow register values:");
1450 for (i = 0; i < 256; i = i+4) { 1482 for (i = 0; i < 256; i = i+4) {
1451 if(i%16 == 0) printk("\ndebug atyfb: 0x%04X: ", base + i); 1483 if (i % 16 == 0)
1484 printk("\ndebug atyfb: 0x%04X: ", base + i);
1452 printk(" %08X", aty_ld_le32(i, par)); 1485 printk(" %08X", aty_ld_le32(i, par));
1453 } 1486 }
1454 printk("\n\n"); 1487 printk("\n\n");
@@ -1458,8 +1491,10 @@ static int atyfb_set_par(struct fb_info *info)
1458 base = 0x00; 1491 base = 0x00;
1459 printk("debug atyfb: Mach64 PLL register values:"); 1492 printk("debug atyfb: Mach64 PLL register values:");
1460 for (i = 0; i < 64; i++) { 1493 for (i = 0; i < 64; i++) {
1461 if(i%16 == 0) printk("\ndebug atyfb: 0x%02X: ", base + i); 1494 if (i % 16 == 0)
1462 if(i%4 == 0) printk(" "); 1495 printk("\ndebug atyfb: 0x%02X: ", base + i);
1496 if (i % 4 == 0)
1497 printk(" ");
1463 printk("%02X", aty_ld_pll_ct(i, par)); 1498 printk("%02X", aty_ld_pll_ct(i, par));
1464 } 1499 }
1465 printk("\n\n"); 1500 printk("\n\n");
@@ -1470,19 +1505,21 @@ static int atyfb_set_par(struct fb_info *info)
1470 /* LCD registers */ 1505 /* LCD registers */
1471 base = 0x00; 1506 base = 0x00;
1472 printk("debug atyfb: LCD register values:"); 1507 printk("debug atyfb: LCD register values:");
1473 if(M64_HAS(LT_LCD_REGS)) { 1508 if (M64_HAS(LT_LCD_REGS)) {
1474 for(i = 0; i <= POWER_MANAGEMENT; i++) { 1509 for (i = 0; i <= POWER_MANAGEMENT; i++) {
1475 if(i == EXT_VERT_STRETCH) 1510 if (i == EXT_VERT_STRETCH)
1476 continue; 1511 continue;
1477 printk("\ndebug atyfb: 0x%04X: ", lt_lcd_regs[i]); 1512 printk("\ndebug atyfb: 0x%04X: ",
1478 printk(" %08X", aty_ld_lcd(i, par)); 1513 lt_lcd_regs[i]);
1479 } 1514 printk(" %08X", aty_ld_lcd(i, par));
1480 1515 }
1481 } else { 1516 } else {
1482 for (i = 0; i < 64; i++) { 1517 for (i = 0; i < 64; i++) {
1483 if(i%4 == 0) printk("\ndebug atyfb: 0x%02X: ", base + i); 1518 if (i % 4 == 0)
1484 printk(" %08X", aty_ld_lcd(i, par)); 1519 printk("\ndebug atyfb: 0x%02X: ",
1485 } 1520 base + i);
1521 printk(" %08X", aty_ld_lcd(i, par));
1522 }
1486 } 1523 }
1487 printk("\n\n"); 1524 printk("\n\n");
1488 } 1525 }
@@ -1500,9 +1537,10 @@ static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1500 union aty_pll pll; 1537 union aty_pll pll;
1501 u32 pixclock; 1538 u32 pixclock;
1502 1539
1503 memcpy(&pll, &(par->pll), sizeof(pll)); 1540 memcpy(&pll, &par->pll, sizeof(pll));
1504 1541
1505 if((err = aty_var_to_crtc(info, var, &crtc))) 1542 err = aty_var_to_crtc(info, var, &crtc);
1543 if (err)
1506 return err; 1544 return err;
1507 1545
1508 pixclock = atyfb_get_pixclock(var, par); 1546 pixclock = atyfb_get_pixclock(var, par);
@@ -1512,7 +1550,9 @@ static int atyfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1512 PRINTKE("Invalid pixclock\n"); 1550 PRINTKE("Invalid pixclock\n");
1513 return -EINVAL; 1551 return -EINVAL;
1514 } else { 1552 } else {
1515 if((err = par->pll_ops->var_to_pll(info, pixclock, var->bits_per_pixel, &pll))) 1553 err = par->pll_ops->var_to_pll(info, pixclock,
1554 var->bits_per_pixel, &pll);
1555 if (err)
1516 return err; 1556 return err;
1517 } 1557 }
1518 1558
@@ -1539,9 +1579,9 @@ static void set_off_pitch(struct atyfb_par *par, const struct fb_info *info)
1539} 1579}
1540 1580
1541 1581
1542 /* 1582/*
1543 * Open/Release the frame buffer device 1583 * Open/Release the frame buffer device
1544 */ 1584 */
1545 1585
1546static int atyfb_open(struct fb_info *info, int user) 1586static int atyfb_open(struct fb_info *info, int user)
1547{ 1587{
@@ -1553,7 +1593,7 @@ static int atyfb_open(struct fb_info *info, int user)
1553 par->mmaped = 0; 1593 par->mmaped = 0;
1554#endif 1594#endif
1555 } 1595 }
1556 return (0); 1596 return 0;
1557} 1597}
1558 1598
1559static irqreturn_t aty_irq(int irq, void *dev_id) 1599static irqreturn_t aty_irq(int irq, void *dev_id)
@@ -1568,7 +1608,8 @@ static irqreturn_t aty_irq(int irq, void *dev_id)
1568 1608
1569 if (int_cntl & CRTC_VBLANK_INT) { 1609 if (int_cntl & CRTC_VBLANK_INT) {
1570 /* clear interrupt */ 1610 /* clear interrupt */
1571 aty_st_le32(CRTC_INT_CNTL, (int_cntl & CRTC_INT_EN_MASK) | CRTC_VBLANK_INT_AK, par); 1611 aty_st_le32(CRTC_INT_CNTL, (int_cntl & CRTC_INT_EN_MASK) |
1612 CRTC_VBLANK_INT_AK, par);
1572 par->vblank.count++; 1613 par->vblank.count++;
1573 if (par->vblank.pan_display) { 1614 if (par->vblank.pan_display) {
1574 par->vblank.pan_display = 0; 1615 par->vblank.pan_display = 0;
@@ -1603,9 +1644,11 @@ static int aty_enable_irq(struct atyfb_par *par, int reenable)
1603 spin_lock_irq(&par->int_lock); 1644 spin_lock_irq(&par->int_lock);
1604 int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK; 1645 int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK;
1605 if (!(int_cntl & CRTC_VBLANK_INT_EN)) { 1646 if (!(int_cntl & CRTC_VBLANK_INT_EN)) {
1606 printk("atyfb: someone disabled IRQ [%08x]\n", int_cntl); 1647 printk("atyfb: someone disabled IRQ [%08x]\n",
1648 int_cntl);
1607 /* re-enable interrupt */ 1649 /* re-enable interrupt */
1608 aty_st_le32(CRTC_INT_CNTL, int_cntl | CRTC_VBLANK_INT_EN, par ); 1650 aty_st_le32(CRTC_INT_CNTL, int_cntl |
1651 CRTC_VBLANK_INT_EN, par);
1609 } 1652 }
1610 spin_unlock_irq(&par->int_lock); 1653 spin_unlock_irq(&par->int_lock);
1611 } 1654 }
@@ -1625,7 +1668,7 @@ static int aty_disable_irq(struct atyfb_par *par)
1625 spin_lock_irq(&par->int_lock); 1668 spin_lock_irq(&par->int_lock);
1626 int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK; 1669 int_cntl = aty_ld_le32(CRTC_INT_CNTL, par) & CRTC_INT_EN_MASK;
1627 /* disable interrupt */ 1670 /* disable interrupt */
1628 aty_st_le32(CRTC_INT_CNTL, int_cntl & ~CRTC_VBLANK_INT_EN, par ); 1671 aty_st_le32(CRTC_INT_CNTL, int_cntl & ~CRTC_VBLANK_INT_EN, par);
1629 spin_unlock_irq(&par->int_lock); 1672 spin_unlock_irq(&par->int_lock);
1630 free_irq(par->irq, par); 1673 free_irq(par->irq, par);
1631 } 1674 }
@@ -1636,50 +1679,62 @@ static int aty_disable_irq(struct atyfb_par *par)
1636static int atyfb_release(struct fb_info *info, int user) 1679static int atyfb_release(struct fb_info *info, int user)
1637{ 1680{
1638 struct atyfb_par *par = (struct atyfb_par *) info->par; 1681 struct atyfb_par *par = (struct atyfb_par *) info->par;
1639 if (user) {
1640 par->open--;
1641 mdelay(1);
1642 wait_for_idle(par);
1643 if (!par->open) {
1644#ifdef __sparc__ 1682#ifdef __sparc__
1645 int was_mmaped = par->mmaped; 1683 int was_mmaped;
1684#endif
1646 1685
1647 par->mmaped = 0; 1686 if (!user)
1687 return 0;
1648 1688
1649 if (was_mmaped) { 1689 par->open--;
1650 struct fb_var_screeninfo var; 1690 mdelay(1);
1691 wait_for_idle(par);
1651 1692
1652 /* Now reset the default display config, we have no 1693 if (par->open)
1653 * idea what the program(s) which mmap'd the chip did 1694 return 0;
1654 * to the configuration, nor whether it restored it 1695
1655 * correctly. 1696#ifdef __sparc__
1656 */ 1697 was_mmaped = par->mmaped;
1657 var = default_var; 1698
1658 if (noaccel) 1699 par->mmaped = 0;
1659 var.accel_flags &= ~FB_ACCELF_TEXT; 1700
1660 else 1701 if (was_mmaped) {
1661 var.accel_flags |= FB_ACCELF_TEXT; 1702 struct fb_var_screeninfo var;
1662 if (var.yres == var.yres_virtual) { 1703
1663 u32 videoram = (info->fix.smem_len - (PAGE_SIZE << 2)); 1704 /*
1664 var.yres_virtual = ((videoram * 8) / var.bits_per_pixel) / var.xres_virtual; 1705 * Now reset the default display config, we have
1665 if (var.yres_virtual < var.yres) 1706 * no idea what the program(s) which mmap'd the
1666 var.yres_virtual = var.yres; 1707 * chip did to the configuration, nor whether it
1667 } 1708 * restored it correctly.
1668 } 1709 */
1669#endif 1710 var = default_var;
1670 aty_disable_irq(par); 1711 if (noaccel)
1712 var.accel_flags &= ~FB_ACCELF_TEXT;
1713 else
1714 var.accel_flags |= FB_ACCELF_TEXT;
1715 if (var.yres == var.yres_virtual) {
1716 u32 videoram = (info->fix.smem_len - (PAGE_SIZE << 2));
1717 var.yres_virtual =
1718 ((videoram * 8) / var.bits_per_pixel) /
1719 var.xres_virtual;
1720 if (var.yres_virtual < var.yres)
1721 var.yres_virtual = var.yres;
1671 } 1722 }
1672 } 1723 }
1673 return (0); 1724#endif
1725 aty_disable_irq(par);
1726
1727 return 0;
1674} 1728}
1675 1729
1676 /* 1730/*
1677 * Pan or Wrap the Display 1731 * Pan or Wrap the Display
1678 * 1732 *
1679 * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag 1733 * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
1680 */ 1734 */
1681 1735
1682static int atyfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) 1736static int atyfb_pan_display(struct fb_var_screeninfo *var,
1737 struct fb_info *info)
1683{ 1738{
1684 struct atyfb_par *par = (struct atyfb_par *) info->par; 1739 struct atyfb_par *par = (struct atyfb_par *) info->par;
1685 u32 xres, yres, xoffset, yoffset; 1740 u32 xres, yres, xoffset, yoffset;
@@ -1690,7 +1745,8 @@ static int atyfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info
1690 yres >>= 1; 1745 yres >>= 1;
1691 xoffset = (var->xoffset + 7) & ~7; 1746 xoffset = (var->xoffset + 7) & ~7;
1692 yoffset = var->yoffset; 1747 yoffset = var->yoffset;
1693 if (xoffset + xres > par->crtc.vxres || yoffset + yres > par->crtc.vyres) 1748 if (xoffset + xres > par->crtc.vxres ||
1749 yoffset + yres > par->crtc.vyres)
1694 return -EINVAL; 1750 return -EINVAL;
1695 info->var.xoffset = xoffset; 1751 info->var.xoffset = xoffset;
1696 info->var.yoffset = yoffset; 1752 info->var.yoffset = yoffset;
@@ -1727,10 +1783,10 @@ static int aty_waitforvblank(struct atyfb_par *par, u32 crtc)
1727 return ret; 1783 return ret;
1728 1784
1729 count = vbl->count; 1785 count = vbl->count;
1730 ret = wait_event_interruptible_timeout(vbl->wait, count != vbl->count, HZ/10); 1786 ret = wait_event_interruptible_timeout(vbl->wait,
1731 if (ret < 0) { 1787 count != vbl->count, HZ/10);
1788 if (ret < 0)
1732 return ret; 1789 return ret;
1733 }
1734 if (ret == 0) { 1790 if (ret == 0) {
1735 aty_enable_irq(par, 1); 1791 aty_enable_irq(par, 1);
1736 return -ETIMEDOUT; 1792 return -ETIMEDOUT;
@@ -1784,7 +1840,8 @@ static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
1784 fbtyp.fb_depth = info->var.bits_per_pixel; 1840 fbtyp.fb_depth = info->var.bits_per_pixel;
1785 fbtyp.fb_cmsize = info->cmap.len; 1841 fbtyp.fb_cmsize = info->cmap.len;
1786 fbtyp.fb_size = info->fix.smem_len; 1842 fbtyp.fb_size = info->fix.smem_len;
1787 if (copy_to_user((struct fbtype __user *) arg, &fbtyp, sizeof(fbtyp))) 1843 if (copy_to_user((struct fbtype __user *) arg, &fbtyp,
1844 sizeof(fbtyp)))
1788 return -EFAULT; 1845 return -EFAULT;
1789 break; 1846 break;
1790#endif /* __sparc__ */ 1847#endif /* __sparc__ */
@@ -1804,7 +1861,7 @@ static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
1804 case ATYIO_CLKR: 1861 case ATYIO_CLKR:
1805 if (M64_HAS(INTEGRATED)) { 1862 if (M64_HAS(INTEGRATED)) {
1806 struct atyclk clk; 1863 struct atyclk clk;
1807 union aty_pll *pll = &(par->pll); 1864 union aty_pll *pll = &par->pll;
1808 u32 dsp_config = pll->ct.dsp_config; 1865 u32 dsp_config = pll->ct.dsp_config;
1809 u32 dsp_on_off = pll->ct.dsp_on_off; 1866 u32 dsp_on_off = pll->ct.dsp_on_off;
1810 clk.ref_clk_per = par->ref_clk_per; 1867 clk.ref_clk_per = par->ref_clk_per;
@@ -1829,8 +1886,9 @@ static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
1829 case ATYIO_CLKW: 1886 case ATYIO_CLKW:
1830 if (M64_HAS(INTEGRATED)) { 1887 if (M64_HAS(INTEGRATED)) {
1831 struct atyclk clk; 1888 struct atyclk clk;
1832 union aty_pll *pll = &(par->pll); 1889 union aty_pll *pll = &par->pll;
1833 if (copy_from_user(&clk, (struct atyclk __user *) arg, sizeof(clk))) 1890 if (copy_from_user(&clk, (struct atyclk __user *) arg,
1891 sizeof(clk)))
1834 return -EFAULT; 1892 return -EFAULT;
1835 par->ref_clk_per = clk.ref_clk_per; 1893 par->ref_clk_per = clk.ref_clk_per;
1836 pll->ct.pll_ref_div = clk.pll_ref_div; 1894 pll->ct.pll_ref_div = clk.pll_ref_div;
@@ -1841,8 +1899,10 @@ static int atyfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
1841 pll->ct.vclk_fb_div = clk.vclk_fb_div; 1899 pll->ct.vclk_fb_div = clk.vclk_fb_div;
1842 pll->ct.vclk_post_div_real = clk.vclk_post_div; 1900 pll->ct.vclk_post_div_real = clk.vclk_post_div;
1843 pll->ct.dsp_config = (clk.dsp_xclks_per_row & 0x3fff) | 1901 pll->ct.dsp_config = (clk.dsp_xclks_per_row & 0x3fff) |
1844 ((clk.dsp_loop_latency & 0xf)<<16)| ((clk.dsp_precision & 7)<<20); 1902 ((clk.dsp_loop_latency & 0xf) << 16) |
1845 pll->ct.dsp_on_off = (clk.dsp_off & 0x7ff) | ((clk.dsp_on & 0x7ff)<<16); 1903 ((clk.dsp_precision & 7) << 20);
1904 pll->ct.dsp_on_off = (clk.dsp_off & 0x7ff) |
1905 ((clk.dsp_on & 0x7ff) << 16);
1846 /*aty_calc_pll_ct(info, &pll->ct);*/ 1906 /*aty_calc_pll_ct(info, &pll->ct);*/
1847 aty_set_pll_ct(info, pll); 1907 aty_set_pll_ct(info, pll);
1848 } else 1908 } else
@@ -1913,8 +1973,7 @@ static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1913 continue; 1973 continue;
1914 1974
1915 map_size = par->mmap_map[i].size - (offset - start); 1975 map_size = par->mmap_map[i].size - (offset - start);
1916 map_offset = 1976 map_offset = par->mmap_map[i].poff + (offset - start);
1917 par->mmap_map[i].poff + (offset - start);
1918 break; 1977 break;
1919 } 1978 }
1920 if (!map_size) { 1979 if (!map_size) {
@@ -1924,8 +1983,7 @@ static int atyfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1924 if (page + map_size > size) 1983 if (page + map_size > size)
1925 map_size = size - page; 1984 map_size = size - page;
1926 1985
1927 pgprot_val(vma->vm_page_prot) &= 1986 pgprot_val(vma->vm_page_prot) &= ~(par->mmap_map[i].prot_mask);
1928 ~(par->mmap_map[i].prot_mask);
1929 pgprot_val(vma->vm_page_prot) |= par->mmap_map[i].prot_flag; 1987 pgprot_val(vma->vm_page_prot) |= par->mmap_map[i].prot_flag;
1930 1988
1931 if (remap_pfn_range(vma, vma->vm_start + page, 1989 if (remap_pfn_range(vma, vma->vm_start + page,
@@ -2029,7 +2087,8 @@ static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2029 par->asleep = 1; 2087 par->asleep = 1;
2030 par->lock_blank = 1; 2088 par->lock_blank = 1;
2031 2089
2032 /* Because we may change PCI D state ourselves, we need to 2090 /*
2091 * Because we may change PCI D state ourselves, we need to
2033 * first save the config space content so the core can 2092 * first save the config space content so the core can
2034 * restore it properly on resume. 2093 * restore it properly on resume.
2035 */ 2094 */
@@ -2080,7 +2139,8 @@ static int atyfb_pci_resume(struct pci_dev *pdev)
2080 2139
2081 acquire_console_sem(); 2140 acquire_console_sem();
2082 2141
2083 /* PCI state will have been restored by the core, so 2142 /*
2143 * PCI state will have been restored by the core, so
2084 * we should be in D0 now with our config space fully 2144 * we should be in D0 now with our config space fully
2085 * restored 2145 * restored
2086 */ 2146 */
@@ -2192,8 +2252,8 @@ static void aty_bl_init(struct atyfb_par *par)
2192 2252
2193 info->bl_dev = bd; 2253 info->bl_dev = bd;
2194 fb_bl_default_curve(info, 0, 2254 fb_bl_default_curve(info, 0,
2195 0x3F * FB_BACKLIGHT_MAX / MAX_LEVEL, 2255 0x3F * FB_BACKLIGHT_MAX / MAX_LEVEL,
2196 0xFF * FB_BACKLIGHT_MAX / MAX_LEVEL); 2256 0xFF * FB_BACKLIGHT_MAX / MAX_LEVEL);
2197 2257
2198 bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1; 2258 bd->props.max_brightness = FB_BACKLIGHT_LEVELS - 1;
2199 bd->props.brightness = bd->props.max_brightness; 2259 bd->props.brightness = bd->props.max_brightness;
@@ -2236,16 +2296,16 @@ static void __devinit aty_calc_mem_refresh(struct atyfb_par *par, int xclk)
2236 size = ARRAY_SIZE(ragepro_tbl); 2296 size = ARRAY_SIZE(ragepro_tbl);
2237 } 2297 }
2238 2298
2239 for (i=0; i < size; i++) { 2299 for (i = 0; i < size; i++) {
2240 if (xclk < refresh_tbl[i]) 2300 if (xclk < refresh_tbl[i])
2241 break; 2301 break;
2242 } 2302 }
2243 par->mem_refresh_rate = i; 2303 par->mem_refresh_rate = i;
2244} 2304}
2245 2305
2246 /* 2306/*
2247 * Initialisation 2307 * Initialisation
2248 */ 2308 */
2249 2309
2250static struct fb_info *fb_list = NULL; 2310static struct fb_info *fb_list = NULL;
2251 2311
@@ -2375,8 +2435,10 @@ static int __devinit aty_init(struct fb_info *info)
2375 } 2435 }
2376#endif 2436#endif
2377#ifdef CONFIG_PPC_PMAC 2437#ifdef CONFIG_PPC_PMAC
2378 /* The Apple iBook1 uses non-standard memory frequencies. We detect it 2438 /*
2379 * and set the frequency manually. */ 2439 * The Apple iBook1 uses non-standard memory frequencies.
2440 * We detect it and set the frequency manually.
2441 */
2380 if (machine_is_compatible("PowerBook2,1")) { 2442 if (machine_is_compatible("PowerBook2,1")) {
2381 par->pll_limits.mclk = 70; 2443 par->pll_limits.mclk = 70;
2382 par->pll_limits.xclk = 53; 2444 par->pll_limits.xclk = 53;
@@ -2421,13 +2483,14 @@ static int __devinit aty_init(struct fb_info *info)
2421 2483
2422 /* save previous video mode */ 2484 /* save previous video mode */
2423 aty_get_crtc(par, &par->saved_crtc); 2485 aty_get_crtc(par, &par->saved_crtc);
2424 if(par->pll_ops->get_pll) 2486 if (par->pll_ops->get_pll)
2425 par->pll_ops->get_pll(info, &par->saved_pll); 2487 par->pll_ops->get_pll(info, &par->saved_pll);
2426 2488
2427 par->mem_cntl = aty_ld_le32(MEM_CNTL, par); 2489 par->mem_cntl = aty_ld_le32(MEM_CNTL, par);
2428 gtb_memsize = M64_HAS(GTB_DSP); 2490 gtb_memsize = M64_HAS(GTB_DSP);
2429 if (gtb_memsize) 2491 if (gtb_memsize)
2430 switch (par->mem_cntl & 0xF) { /* 0xF used instead of MEM_SIZE_ALIAS */ 2492 /* 0xF used instead of MEM_SIZE_ALIAS */
2493 switch (par->mem_cntl & 0xF) {
2431 case MEM_SIZE_512K: 2494 case MEM_SIZE_512K:
2432 info->fix.smem_len = 0x80000; 2495 info->fix.smem_len = 0x80000;
2433 break; 2496 break;
@@ -2496,8 +2559,8 @@ static int __devinit aty_init(struct fb_info *info)
2496 } 2559 }
2497 2560
2498 /* 2561 /*
2499 * Reg Block 0 (CT-compatible block) is at mmio_start 2562 * Reg Block 0 (CT-compatible block) is at mmio_start
2500 * Reg Block 1 (multimedia extensions) is at mmio_start - 0x400 2563 * Reg Block 1 (multimedia extensions) is at mmio_start - 0x400
2501 */ 2564 */
2502 if (M64_HAS(GX)) { 2565 if (M64_HAS(GX)) {
2503 info->fix.mmio_len = 0x400; 2566 info->fix.mmio_len = 0x400;
@@ -2516,84 +2579,98 @@ static int __devinit aty_init(struct fb_info *info)
2516 } 2579 }
2517 2580
2518 PRINTKI("%d%c %s, %s MHz XTAL, %d MHz PLL, %d Mhz MCLK, %d MHz XCLK\n", 2581 PRINTKI("%d%c %s, %s MHz XTAL, %d MHz PLL, %d Mhz MCLK, %d MHz XCLK\n",
2519 info->fix.smem_len == 0x80000 ? 512 : (info->fix.smem_len >> 20), 2582 info->fix.smem_len == 0x80000 ? 512 : (info->fix.smem_len>>20),
2520 info->fix.smem_len == 0x80000 ? 'K' : 'M', ramname, xtal, par->pll_limits.pll_max, 2583 info->fix.smem_len == 0x80000 ? 'K' : 'M', ramname, xtal,
2521 par->pll_limits.mclk, par->pll_limits.xclk); 2584 par->pll_limits.pll_max, par->pll_limits.mclk,
2585 par->pll_limits.xclk);
2522 2586
2523#if defined(DEBUG) && defined(CONFIG_FB_ATY_CT) 2587#if defined(DEBUG) && defined(CONFIG_FB_ATY_CT)
2524 if (M64_HAS(INTEGRATED)) { 2588 if (M64_HAS(INTEGRATED)) {
2525 int i; 2589 int i;
2526 printk("debug atyfb: BUS_CNTL DAC_CNTL MEM_CNTL EXT_MEM_CNTL CRTC_GEN_CNTL " 2590 printk("debug atyfb: BUS_CNTL DAC_CNTL MEM_CNTL "
2527 "DSP_CONFIG DSP_ON_OFF CLOCK_CNTL\n" 2591 "EXT_MEM_CNTL CRTC_GEN_CNTL DSP_CONFIG "
2528 "debug atyfb: %08x %08x %08x %08x %08x %08x %08x %08x\n" 2592 "DSP_ON_OFF CLOCK_CNTL\n"
2593 "debug atyfb: %08x %08x %08x "
2594 "%08x %08x %08x "
2595 "%08x %08x\n"
2529 "debug atyfb: PLL", 2596 "debug atyfb: PLL",
2530 aty_ld_le32(BUS_CNTL, par), aty_ld_le32(DAC_CNTL, par), 2597 aty_ld_le32(BUS_CNTL, par),
2531 aty_ld_le32(MEM_CNTL, par), aty_ld_le32(EXT_MEM_CNTL, par), 2598 aty_ld_le32(DAC_CNTL, par),
2532 aty_ld_le32(CRTC_GEN_CNTL, par), aty_ld_le32(DSP_CONFIG, par), 2599 aty_ld_le32(MEM_CNTL, par),
2533 aty_ld_le32(DSP_ON_OFF, par), aty_ld_le32(CLOCK_CNTL, par)); 2600 aty_ld_le32(EXT_MEM_CNTL, par),
2601 aty_ld_le32(CRTC_GEN_CNTL, par),
2602 aty_ld_le32(DSP_CONFIG, par),
2603 aty_ld_le32(DSP_ON_OFF, par),
2604 aty_ld_le32(CLOCK_CNTL, par));
2534 for (i = 0; i < 40; i++) 2605 for (i = 0; i < 40; i++)
2535 printk(" %02x", aty_ld_pll_ct(i, par)); 2606 printk(" %02x", aty_ld_pll_ct(i, par));
2536 printk("\n"); 2607 printk("\n");
2537 } 2608 }
2538#endif 2609#endif
2539 if(par->pll_ops->init_pll) 2610 if (par->pll_ops->init_pll)
2540 par->pll_ops->init_pll(info, &par->pll); 2611 par->pll_ops->init_pll(info, &par->pll);
2541 if (par->pll_ops->resume_pll) 2612 if (par->pll_ops->resume_pll)
2542 par->pll_ops->resume_pll(info, &par->pll); 2613 par->pll_ops->resume_pll(info, &par->pll);
2543 2614
2544 /* 2615 /*
2545 * Last page of 8 MB (4 MB on ISA) aperture is MMIO, 2616 * Last page of 8 MB (4 MB on ISA) aperture is MMIO,
2546 * unless the auxiliary register aperture is used. 2617 * unless the auxiliary register aperture is used.
2547 */ 2618 */
2548
2549 if (!par->aux_start && 2619 if (!par->aux_start &&
2550 (info->fix.smem_len == 0x800000 || (par->bus_type == ISA && info->fix.smem_len == 0x400000))) 2620 (info->fix.smem_len == 0x800000 ||
2621 (par->bus_type == ISA && info->fix.smem_len == 0x400000)))
2551 info->fix.smem_len -= GUI_RESERVE; 2622 info->fix.smem_len -= GUI_RESERVE;
2552 2623
2553 /* 2624 /*
2554 * Disable register access through the linear aperture 2625 * Disable register access through the linear aperture
2555 * if the auxiliary aperture is used so we can access 2626 * if the auxiliary aperture is used so we can access
2556 * the full 8 MB of video RAM on 8 MB boards. 2627 * the full 8 MB of video RAM on 8 MB boards.
2557 */ 2628 */
2558 if (par->aux_start) 2629 if (par->aux_start)
2559 aty_st_le32(BUS_CNTL, aty_ld_le32(BUS_CNTL, par) | BUS_APER_REG_DIS, par); 2630 aty_st_le32(BUS_CNTL, aty_ld_le32(BUS_CNTL, par) |
2631 BUS_APER_REG_DIS, par);
2560 2632
2561#ifdef CONFIG_MTRR 2633#ifdef CONFIG_MTRR
2562 par->mtrr_aper = -1; 2634 par->mtrr_aper = -1;
2563 par->mtrr_reg = -1; 2635 par->mtrr_reg = -1;
2564 if (!nomtrr) { 2636 if (!nomtrr) {
2565 /* Cover the whole resource. */ 2637 /* Cover the whole resource. */
2566 par->mtrr_aper = mtrr_add(par->res_start, par->res_size, MTRR_TYPE_WRCOMB, 1); 2638 par->mtrr_aper = mtrr_add(par->res_start, par->res_size,
2567 if (par->mtrr_aper >= 0 && !par->aux_start) { 2639 MTRR_TYPE_WRCOMB, 1);
2640 if (par->mtrr_aper >= 0 && !par->aux_start) {
2568 /* Make a hole for mmio. */ 2641 /* Make a hole for mmio. */
2569 par->mtrr_reg = mtrr_add(par->res_start + 0x800000 - GUI_RESERVE, 2642 par->mtrr_reg = mtrr_add(par->res_start + 0x800000 -
2570 GUI_RESERVE, MTRR_TYPE_UNCACHABLE, 1); 2643 GUI_RESERVE, GUI_RESERVE,
2644 MTRR_TYPE_UNCACHABLE, 1);
2571 if (par->mtrr_reg < 0) { 2645 if (par->mtrr_reg < 0) {
2572 mtrr_del(par->mtrr_aper, 0, 0); 2646 mtrr_del(par->mtrr_aper, 0, 0);
2573 par->mtrr_aper = -1; 2647 par->mtrr_aper = -1;
2574 } 2648 }
2575 } 2649 }
2576 } 2650 }
2577#endif 2651#endif
2578 2652
2579 info->fbops = &atyfb_ops; 2653 info->fbops = &atyfb_ops;
2580 info->pseudo_palette = par->pseudo_palette; 2654 info->pseudo_palette = par->pseudo_palette;
2581 info->flags = FBINFO_DEFAULT | 2655 info->flags = FBINFO_DEFAULT |
2582 FBINFO_HWACCEL_IMAGEBLIT | 2656 FBINFO_HWACCEL_IMAGEBLIT |
2583 FBINFO_HWACCEL_FILLRECT | 2657 FBINFO_HWACCEL_FILLRECT |
2584 FBINFO_HWACCEL_COPYAREA | 2658 FBINFO_HWACCEL_COPYAREA |
2585 FBINFO_HWACCEL_YPAN; 2659 FBINFO_HWACCEL_YPAN;
2586 2660
2587#ifdef CONFIG_PMAC_BACKLIGHT 2661#ifdef CONFIG_PMAC_BACKLIGHT
2588 if (M64_HAS(G3_PB_1_1) && machine_is_compatible("PowerBook1,1")) { 2662 if (M64_HAS(G3_PB_1_1) && machine_is_compatible("PowerBook1,1")) {
2589 /* these bits let the 101 powerbook wake up from sleep -- paulus */ 2663 /*
2590 aty_st_lcd(POWER_MANAGEMENT, aty_ld_lcd(POWER_MANAGEMENT, par) 2664 * these bits let the 101 powerbook
2591 | (USE_F32KHZ | TRISTATE_MEM_EN), par); 2665 * wake up from sleep -- paulus
2666 */
2667 aty_st_lcd(POWER_MANAGEMENT, aty_ld_lcd(POWER_MANAGEMENT, par) |
2668 USE_F32KHZ | TRISTATE_MEM_EN, par);
2592 } else 2669 } else
2593#endif 2670#endif
2594 if (M64_HAS(MOBIL_BUS) && backlight) { 2671 if (M64_HAS(MOBIL_BUS) && backlight) {
2595#ifdef CONFIG_FB_ATY_BACKLIGHT 2672#ifdef CONFIG_FB_ATY_BACKLIGHT
2596 aty_bl_init (par); 2673 aty_bl_init(par);
2597#endif 2674#endif
2598 } 2675 }
2599 2676
@@ -2601,8 +2678,8 @@ static int __devinit aty_init(struct fb_info *info)
2601#ifdef CONFIG_PPC 2678#ifdef CONFIG_PPC
2602 if (machine_is(powermac)) { 2679 if (machine_is(powermac)) {
2603 /* 2680 /*
2604 * FIXME: The NVRAM stuff should be put in a Mac-specific file, as it 2681 * FIXME: The NVRAM stuff should be put in a Mac-specific file,
2605 * applies to all Mac video cards 2682 * as it applies to all Mac video cards
2606 */ 2683 */
2607 if (mode) { 2684 if (mode) {
2608 if (mac_find_mode(&var, info, mode, 8)) 2685 if (mac_find_mode(&var, info, mode, 8))
@@ -2615,8 +2692,7 @@ static int __devinit aty_init(struct fb_info *info)
2615 default_vmode = VMODE_1024_768_60; 2692 default_vmode = VMODE_1024_768_60;
2616 else if (machine_is_compatible("iMac")) 2693 else if (machine_is_compatible("iMac"))
2617 default_vmode = VMODE_1024_768_75; 2694 default_vmode = VMODE_1024_768_75;
2618 else if (machine_is_compatible 2695 else if (machine_is_compatible("PowerBook2,1"))
2619 ("PowerBook2,1"))
2620 /* iBook with 800x600 LCD */ 2696 /* iBook with 800x600 LCD */
2621 default_vmode = VMODE_800_600_60; 2697 default_vmode = VMODE_800_600_60;
2622 else 2698 else
@@ -2630,7 +2706,7 @@ static int __devinit aty_init(struct fb_info *info)
2630 if (default_cmode < CMODE_8 || default_cmode > CMODE_32) 2706 if (default_cmode < CMODE_8 || default_cmode > CMODE_32)
2631 default_cmode = CMODE_8; 2707 default_cmode = CMODE_8;
2632 if (!mac_vmode_to_var(default_vmode, default_cmode, 2708 if (!mac_vmode_to_var(default_vmode, default_cmode,
2633 &var)) 2709 &var))
2634 has_var = 1; 2710 has_var = 1;
2635 } 2711 }
2636 } 2712 }
@@ -2702,12 +2778,12 @@ aty_init_exit:
2702 2778
2703#ifdef CONFIG_MTRR 2779#ifdef CONFIG_MTRR
2704 if (par->mtrr_reg >= 0) { 2780 if (par->mtrr_reg >= 0) {
2705 mtrr_del(par->mtrr_reg, 0, 0); 2781 mtrr_del(par->mtrr_reg, 0, 0);
2706 par->mtrr_reg = -1; 2782 par->mtrr_reg = -1;
2707 } 2783 }
2708 if (par->mtrr_aper >= 0) { 2784 if (par->mtrr_aper >= 0) {
2709 mtrr_del(par->mtrr_aper, 0, 0); 2785 mtrr_del(par->mtrr_aper, 0, 0);
2710 par->mtrr_aper = -1; 2786 par->mtrr_aper = -1;
2711 } 2787 }
2712#endif 2788#endif
2713 return ret; 2789 return ret;
@@ -2735,18 +2811,18 @@ static int __devinit store_video_par(char *video_str, unsigned char m64_num)
2735 phys_size[m64_num] = size; 2811 phys_size[m64_num] = size;
2736 phys_guiregbase[m64_num] = guiregbase; 2812 phys_guiregbase[m64_num] = guiregbase;
2737 PRINTKI("stored them all: $%08lX $%08lX $%08lX \n", vmembase, size, 2813 PRINTKI("stored them all: $%08lX $%08lX $%08lX \n", vmembase, size,
2738 guiregbase); 2814 guiregbase);
2739 return 0; 2815 return 0;
2740 2816
2741 mach64_invalid: 2817 mach64_invalid:
2742 phys_vmembase[m64_num] = 0; 2818 phys_vmembase[m64_num] = 0;
2743 return -1; 2819 return -1;
2744} 2820}
2745#endif /* CONFIG_ATARI */ 2821#endif /* CONFIG_ATARI */
2746 2822
2747 /* 2823/*
2748 * Blank the display. 2824 * Blank the display.
2749 */ 2825 */
2750 2826
2751static int atyfb_blank(int blank, struct fb_info *info) 2827static int atyfb_blank(int blank, struct fb_info *info)
2752{ 2828{
@@ -2768,20 +2844,20 @@ static int atyfb_blank(int blank, struct fb_info *info)
2768 gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par); 2844 gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
2769 gen_cntl &= ~0x400004c; 2845 gen_cntl &= ~0x400004c;
2770 switch (blank) { 2846 switch (blank) {
2771 case FB_BLANK_UNBLANK: 2847 case FB_BLANK_UNBLANK:
2772 break; 2848 break;
2773 case FB_BLANK_NORMAL: 2849 case FB_BLANK_NORMAL:
2774 gen_cntl |= 0x4000040; 2850 gen_cntl |= 0x4000040;
2775 break; 2851 break;
2776 case FB_BLANK_VSYNC_SUSPEND: 2852 case FB_BLANK_VSYNC_SUSPEND:
2777 gen_cntl |= 0x4000048; 2853 gen_cntl |= 0x4000048;
2778 break; 2854 break;
2779 case FB_BLANK_HSYNC_SUSPEND: 2855 case FB_BLANK_HSYNC_SUSPEND:
2780 gen_cntl |= 0x4000044; 2856 gen_cntl |= 0x4000044;
2781 break; 2857 break;
2782 case FB_BLANK_POWERDOWN: 2858 case FB_BLANK_POWERDOWN:
2783 gen_cntl |= 0x400004c; 2859 gen_cntl |= 0x400004c;
2784 break; 2860 break;
2785 } 2861 }
2786 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par); 2862 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par);
2787 2863
@@ -2806,15 +2882,15 @@ static void aty_st_pal(u_int regno, u_int red, u_int green, u_int blue,
2806 aty_st_8(DAC_DATA, blue, par); 2882 aty_st_8(DAC_DATA, blue, par);
2807} 2883}
2808 2884
2809 /* 2885/*
2810 * Set a single color register. The values supplied are already 2886 * Set a single color register. The values supplied are already
2811 * rounded down to the hardware's capabilities (according to the 2887 * rounded down to the hardware's capabilities (according to the
2812 * entries in the var structure). Return != 0 for invalid regno. 2888 * entries in the var structure). Return != 0 for invalid regno.
2813 * !! 4 & 8 = PSEUDO, > 8 = DIRECTCOLOR 2889 * !! 4 & 8 = PSEUDO, > 8 = DIRECTCOLOR
2814 */ 2890 */
2815 2891
2816static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, 2892static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
2817 u_int transp, struct fb_info *info) 2893 u_int transp, struct fb_info *info)
2818{ 2894{
2819 struct atyfb_par *par = (struct atyfb_par *) info->par; 2895 struct atyfb_par *par = (struct atyfb_par *) info->par;
2820 int i, depth; 2896 int i, depth;
@@ -2868,16 +2944,15 @@ static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
2868 if (depth == 16) { 2944 if (depth == 16) {
2869 if (regno < 32) 2945 if (regno < 32)
2870 aty_st_pal(regno << 3, red, 2946 aty_st_pal(regno << 3, red,
2871 par->palette[regno<<1].green, 2947 par->palette[regno << 1].green,
2872 blue, par); 2948 blue, par);
2873 red = par->palette[regno>>1].red; 2949 red = par->palette[regno >> 1].red;
2874 blue = par->palette[regno>>1].blue; 2950 blue = par->palette[regno >> 1].blue;
2875 regno <<= 2; 2951 regno <<= 2;
2876 } else if (depth == 15) { 2952 } else if (depth == 15) {
2877 regno <<= 3; 2953 regno <<= 3;
2878 for(i = 0; i < 8; i++) { 2954 for (i = 0; i < 8; i++)
2879 aty_st_pal(regno + i, red, green, blue, par); 2955 aty_st_pal(regno + i, red, green, blue, par);
2880 }
2881 } 2956 }
2882 } 2957 }
2883 aty_st_pal(regno, red, green, blue, par); 2958 aty_st_pal(regno, red, green, blue, par);
@@ -2890,7 +2965,8 @@ static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
2890#ifdef __sparc__ 2965#ifdef __sparc__
2891 2966
2892static int __devinit atyfb_setup_sparc(struct pci_dev *pdev, 2967static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
2893 struct fb_info *info, unsigned long addr) 2968 struct fb_info *info,
2969 unsigned long addr)
2894{ 2970{
2895 struct atyfb_par *par = info->par; 2971 struct atyfb_par *par = info->par;
2896 struct device_node *dp; 2972 struct device_node *dp;
@@ -2978,7 +3054,8 @@ static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
2978 j++; 3054 j++;
2979 } 3055 }
2980 3056
2981 if((ret = correct_chipset(par))) 3057 ret = correct_chipset(par);
3058 if (ret)
2982 return ret; 3059 return ret;
2983 3060
2984 if (IS_XL(pdev->device)) { 3061 if (IS_XL(pdev->device)) {
@@ -3108,28 +3185,28 @@ static void __devinit aty_init_lcd(struct atyfb_par *par, u32 bios_base)
3108 u32 driv_inf_tab, sig; 3185 u32 driv_inf_tab, sig;
3109 u16 lcd_ofs; 3186 u16 lcd_ofs;
3110 3187
3111 /* To support an LCD panel, we should know it's dimensions and 3188 /*
3189 * To support an LCD panel, we should know it's dimensions and
3112 * it's desired pixel clock. 3190 * it's desired pixel clock.
3113 * There are two ways to do it: 3191 * There are two ways to do it:
3114 * - Check the startup video mode and calculate the panel 3192 * - Check the startup video mode and calculate the panel
3115 * size from it. This is unreliable. 3193 * size from it. This is unreliable.
3116 * - Read it from the driver information table in the video BIOS. 3194 * - Read it from the driver information table in the video BIOS.
3117 */ 3195 */
3118 /* Address of driver information table is at offset 0x78. */ 3196 /* Address of driver information table is at offset 0x78. */
3119 driv_inf_tab = bios_base + *((u16 *)(bios_base+0x78)); 3197 driv_inf_tab = bios_base + *((u16 *)(bios_base+0x78));
3120 3198
3121 /* Check for the driver information table signature. */ 3199 /* Check for the driver information table signature. */
3122 sig = (*(u32 *)driv_inf_tab); 3200 sig = *(u32 *)driv_inf_tab;
3123 if ((sig == 0x54504c24) || /* Rage LT pro */ 3201 if ((sig == 0x54504c24) || /* Rage LT pro */
3124 (sig == 0x544d5224) || /* Rage mobility */ 3202 (sig == 0x544d5224) || /* Rage mobility */
3125 (sig == 0x54435824) || /* Rage XC */ 3203 (sig == 0x54435824) || /* Rage XC */
3126 (sig == 0x544c5824)) { /* Rage XL */ 3204 (sig == 0x544c5824)) { /* Rage XL */
3127 PRINTKI("BIOS contains driver information table.\n"); 3205 PRINTKI("BIOS contains driver information table.\n");
3128 lcd_ofs = (*(u16 *)(driv_inf_tab + 10)); 3206 lcd_ofs = *(u16 *)(driv_inf_tab + 10);
3129 par->lcd_table = 0; 3207 par->lcd_table = 0;
3130 if (lcd_ofs != 0) { 3208 if (lcd_ofs != 0)
3131 par->lcd_table = bios_base + lcd_ofs; 3209 par->lcd_table = bios_base + lcd_ofs;
3132 }
3133 } 3210 }
3134 3211
3135 if (par->lcd_table != 0) { 3212 if (par->lcd_table != 0) {
@@ -3144,14 +3221,16 @@ static void __devinit aty_init_lcd(struct atyfb_par *par, u32 bios_base)
3144 u16 width, height, panel_type, refresh_rates; 3221 u16 width, height, panel_type, refresh_rates;
3145 u16 *lcdmodeptr; 3222 u16 *lcdmodeptr;
3146 u32 format; 3223 u32 format;
3147 u8 lcd_refresh_rates[16] = {50,56,60,67,70,72,75,76,85,90,100,120,140,150,160,200}; 3224 u8 lcd_refresh_rates[16] = { 50, 56, 60, 67, 70, 72, 75, 76, 85,
3148 /* The most important information is the panel size at 3225 90, 100, 120, 140, 150, 160, 200 };
3226 /*
3227 * The most important information is the panel size at
3149 * offset 25 and 27, but there's some other nice information 3228 * offset 25 and 27, but there's some other nice information
3150 * which we print to the screen. 3229 * which we print to the screen.
3151 */ 3230 */
3152 id = *(u8 *)par->lcd_table; 3231 id = *(u8 *)par->lcd_table;
3153 strncpy(model,(char *)par->lcd_table+1,24); 3232 strncpy(model, (char *)par->lcd_table+1, 24);
3154 model[23]=0; 3233 model[23] = 0;
3155 3234
3156 width = par->lcd_width = *(u16 *)(par->lcd_table+25); 3235 width = par->lcd_width = *(u16 *)(par->lcd_table+25);
3157 height = par->lcd_height = *(u16 *)(par->lcd_table+27); 3236 height = par->lcd_height = *(u16 *)(par->lcd_table+27);
@@ -3164,7 +3243,7 @@ static void __devinit aty_init_lcd(struct atyfb_par *par, u32 bios_base)
3164 txtdual = "dual (split) "; 3243 txtdual = "dual (split) ";
3165 else 3244 else
3166 txtdual = ""; 3245 txtdual = "";
3167 tech = (panel_type>>2) & 63; 3246 tech = (panel_type >> 2) & 63;
3168 switch (tech) { 3247 switch (tech) {
3169 case 0: 3248 case 0:
3170 txtmonitor = "passive matrix"; 3249 txtmonitor = "passive matrix";
@@ -3224,22 +3303,24 @@ static void __devinit aty_init_lcd(struct atyfb_par *par, u32 bios_base)
3224 } 3303 }
3225 } 3304 }
3226 PRINTKI("%s%s %s monitor detected: %s\n", 3305 PRINTKI("%s%s %s monitor detected: %s\n",
3227 txtdual ,txtcolour, txtmonitor, model); 3306 txtdual, txtcolour, txtmonitor, model);
3228 PRINTKI(" id=%d, %dx%d pixels, %s\n", 3307 PRINTKI(" id=%d, %dx%d pixels, %s\n",
3229 id, width, height, txtformat); 3308 id, width, height, txtformat);
3230 refresh_rates_buf[0] = 0; 3309 refresh_rates_buf[0] = 0;
3231 refresh_rates = *(u16 *)(par->lcd_table+62); 3310 refresh_rates = *(u16 *)(par->lcd_table+62);
3232 m = 1; 3311 m = 1;
3233 f = 0; 3312 f = 0;
3234 for (i=0;i<16;i++) { 3313 for (i = 0; i < 16; i++) {
3235 if (refresh_rates & m) { 3314 if (refresh_rates & m) {
3236 if (f == 0) { 3315 if (f == 0) {
3237 sprintf(strbuf, "%d", lcd_refresh_rates[i]); 3316 sprintf(strbuf, "%d",
3317 lcd_refresh_rates[i]);
3238 f++; 3318 f++;
3239 } else { 3319 } else {
3240 sprintf(strbuf, ",%d", lcd_refresh_rates[i]); 3320 sprintf(strbuf, ",%d",
3321 lcd_refresh_rates[i]);
3241 } 3322 }
3242 strcat(refresh_rates_buf,strbuf); 3323 strcat(refresh_rates_buf, strbuf);
3243 } 3324 }
3244 m = m << 1; 3325 m = m << 1;
3245 } 3326 }
@@ -3247,7 +3328,8 @@ static void __devinit aty_init_lcd(struct atyfb_par *par, u32 bios_base)
3247 PRINTKI(" supports refresh rates [%s], default %d Hz\n", 3328 PRINTKI(" supports refresh rates [%s], default %d Hz\n",
3248 refresh_rates_buf, lcd_refresh_rates[default_refresh_rate]); 3329 refresh_rates_buf, lcd_refresh_rates[default_refresh_rate]);
3249 par->lcd_refreshrate = lcd_refresh_rates[default_refresh_rate]; 3330 par->lcd_refreshrate = lcd_refresh_rates[default_refresh_rate];
3250 /* We now need to determine the crtc parameters for the 3331 /*
3332 * We now need to determine the crtc parameters for the
3251 * LCD monitor. This is tricky, because they are not stored 3333 * LCD monitor. This is tricky, because they are not stored
3252 * individually in the BIOS. Instead, the BIOS contains a 3334 * individually in the BIOS. Instead, the BIOS contains a
3253 * table of display modes that work for this monitor. 3335 * table of display modes that work for this monitor.
@@ -3382,7 +3464,9 @@ static int __devinit init_from_bios(struct atyfb_par *par)
3382} 3464}
3383#endif /* __i386__ */ 3465#endif /* __i386__ */
3384 3466
3385static int __devinit atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, unsigned long addr) 3467static int __devinit atyfb_setup_generic(struct pci_dev *pdev,
3468 struct fb_info *info,
3469 unsigned long addr)
3386{ 3470{
3387 struct atyfb_par *par = info->par; 3471 struct atyfb_par *par = info->par;
3388 u16 tmp; 3472 u16 tmp;
@@ -3429,10 +3513,12 @@ static int __devinit atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *i
3429 goto atyfb_setup_generic_fail; 3513 goto atyfb_setup_generic_fail;
3430 } 3514 }
3431 3515
3432 if((ret = correct_chipset(par))) 3516 ret = correct_chipset(par);
3517 if (ret)
3433 goto atyfb_setup_generic_fail; 3518 goto atyfb_setup_generic_fail;
3434#ifdef __i386__ 3519#ifdef __i386__
3435 if((ret = init_from_bios(par))) 3520 ret = init_from_bios(par);
3521 if (ret)
3436 goto atyfb_setup_generic_fail; 3522 goto atyfb_setup_generic_fail;
3437#endif 3523#endif
3438 if (!(aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_EXT_DISP_EN)) 3524 if (!(aty_ld_le32(CRTC_GEN_CNTL, par) & CRTC_EXT_DISP_EN))
@@ -3457,7 +3543,8 @@ atyfb_setup_generic_fail:
3457 3543
3458#endif /* !__sparc__ */ 3544#endif /* !__sparc__ */
3459 3545
3460static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 3546static int __devinit atyfb_pci_probe(struct pci_dev *pdev,
3547 const struct pci_device_id *ent)
3461{ 3548{
3462 unsigned long addr, res_start, res_size; 3549 unsigned long addr, res_start, res_size;
3463 struct fb_info *info; 3550 struct fb_info *info;
@@ -3482,10 +3569,10 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
3482 /* Reserve space */ 3569 /* Reserve space */
3483 res_start = rp->start; 3570 res_start = rp->start;
3484 res_size = rp->end - rp->start + 1; 3571 res_size = rp->end - rp->start + 1;
3485 if (!request_mem_region (res_start, res_size, "atyfb")) 3572 if (!request_mem_region(res_start, res_size, "atyfb"))
3486 return -EBUSY; 3573 return -EBUSY;
3487 3574
3488 /* Allocate framebuffer */ 3575 /* Allocate framebuffer */
3489 info = framebuffer_alloc(sizeof(struct atyfb_par), &pdev->dev); 3576 info = framebuffer_alloc(sizeof(struct atyfb_par), &pdev->dev);
3490 if (!info) { 3577 if (!info) {
3491 PRINTKE("atyfb_pci_probe() can't alloc fb_info\n"); 3578 PRINTKE("atyfb_pci_probe() can't alloc fb_info\n");
@@ -3573,7 +3660,8 @@ static int __init atyfb_atari_probe(void)
3573 for (m64_num = 0; m64_num < mach64_count; m64_num++) { 3660 for (m64_num = 0; m64_num < mach64_count; m64_num++) {
3574 if (!phys_vmembase[m64_num] || !phys_size[m64_num] || 3661 if (!phys_vmembase[m64_num] || !phys_size[m64_num] ||
3575 !phys_guiregbase[m64_num]) { 3662 !phys_guiregbase[m64_num]) {
3576 PRINTKI("phys_*[%d] parameters not set => returning early. \n", m64_num); 3663 PRINTKI("phys_*[%d] parameters not set => "
3664 "returning early. \n", m64_num);
3577 continue; 3665 continue;
3578 } 3666 }
3579 3667
@@ -3589,8 +3677,8 @@ static int __init atyfb_atari_probe(void)
3589 par->irq = (unsigned int) -1; /* something invalid */ 3677 par->irq = (unsigned int) -1; /* something invalid */
3590 3678
3591 /* 3679 /*
3592 * Map the video memory (physical address given) to somewhere in the 3680 * Map the video memory (physical address given)
3593 * kernel address space. 3681 * to somewhere in the kernel address space.
3594 */ 3682 */
3595 info->screen_base = ioremap(phys_vmembase[m64_num], phys_size[m64_num]); 3683 info->screen_base = ioremap(phys_vmembase[m64_num], phys_size[m64_num]);
3596 info->fix.smem_start = (unsigned long)info->screen_base; /* Fake! */ 3684 info->fix.smem_start = (unsigned long)info->screen_base; /* Fake! */
@@ -3661,12 +3749,12 @@ static void __devexit atyfb_remove(struct fb_info *info)
3661 3749
3662#ifdef CONFIG_MTRR 3750#ifdef CONFIG_MTRR
3663 if (par->mtrr_reg >= 0) { 3751 if (par->mtrr_reg >= 0) {
3664 mtrr_del(par->mtrr_reg, 0, 0); 3752 mtrr_del(par->mtrr_reg, 0, 0);
3665 par->mtrr_reg = -1; 3753 par->mtrr_reg = -1;
3666 } 3754 }
3667 if (par->mtrr_aper >= 0) { 3755 if (par->mtrr_aper >= 0) {
3668 mtrr_del(par->mtrr_aper, 0, 0); 3756 mtrr_del(par->mtrr_aper, 0, 0);
3669 par->mtrr_aper = -1; 3757 par->mtrr_aper = -1;
3670 } 3758 }
3671#endif 3759#endif
3672#ifndef __sparc__ 3760#ifndef __sparc__
@@ -3900,29 +3988,29 @@ static const struct dmi_system_id atyfb_reboot_ids[] = {
3900 3988
3901static int __init atyfb_init(void) 3989static int __init atyfb_init(void)
3902{ 3990{
3903 int err1 = 1, err2 = 1; 3991 int err1 = 1, err2 = 1;
3904#ifndef MODULE 3992#ifndef MODULE
3905 char *option = NULL; 3993 char *option = NULL;
3906 3994
3907 if (fb_get_options("atyfb", &option)) 3995 if (fb_get_options("atyfb", &option))
3908 return -ENODEV; 3996 return -ENODEV;
3909 atyfb_setup(option); 3997 atyfb_setup(option);
3910#endif 3998#endif
3911 3999
3912#ifdef CONFIG_PCI 4000#ifdef CONFIG_PCI
3913 err1 = pci_register_driver(&atyfb_driver); 4001 err1 = pci_register_driver(&atyfb_driver);
3914#endif 4002#endif
3915#ifdef CONFIG_ATARI 4003#ifdef CONFIG_ATARI
3916 err2 = atyfb_atari_probe(); 4004 err2 = atyfb_atari_probe();
3917#endif 4005#endif
3918 4006
3919 if (err1 && err2) 4007 if (err1 && err2)
3920 return -ENODEV; 4008 return -ENODEV;
3921 4009
3922 if (dmi_check_system(atyfb_reboot_ids)) 4010 if (dmi_check_system(atyfb_reboot_ids))
3923 register_reboot_notifier(&atyfb_reboot_notifier); 4011 register_reboot_notifier(&atyfb_reboot_notifier);
3924 4012
3925 return 0; 4013 return 0;
3926} 4014}
3927 4015
3928static void __exit atyfb_exit(void) 4016static void __exit atyfb_exit(void)
@@ -3951,8 +4039,7 @@ MODULE_PARM_DESC(mclk, "int: override memory clock");
3951module_param(xclk, int, 0); 4039module_param(xclk, int, 0);
3952MODULE_PARM_DESC(xclk, "int: override accelerated engine clock"); 4040MODULE_PARM_DESC(xclk, "int: override accelerated engine clock");
3953module_param(comp_sync, int, 0); 4041module_param(comp_sync, int, 0);
3954MODULE_PARM_DESC(comp_sync, 4042MODULE_PARM_DESC(comp_sync, "Set composite sync signal to low (0) or high (1)");
3955 "Set composite sync signal to low (0) or high (1)");
3956module_param(mode, charp, 0); 4043module_param(mode, charp, 0);
3957MODULE_PARM_DESC(mode, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" "); 4044MODULE_PARM_DESC(mode, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
3958#ifdef CONFIG_MTRR 4045#ifdef CONFIG_MTRR