2 * drivers/video/radeonfb.c
3 * framebuffer driver for ATI Radeon chipset video boards
5 * Copyright 2000 Ani Joshi <ajoshi@kernel.crashing.org>
9 * 2000-08-03 initial version 0.0.1
10 * 2000-09-10 more bug fixes, public release 0.0.5
11 * 2001-02-19 mode bug fixes, 0.0.7
12 * 2001-07-05 fixed scrolling issues, engine initialization,
13 * and minor mode tweaking, 0.0.9
14 * 2001-09-07 Radeon VE support, Nick Kurshev
15 * blanking, pan_display, and cmap fixes, 0.1.0
16 * 2001-10-10 Radeon 7500 and 8500 support, and experimental
17 * flat panel support, 0.1.1
18 * 2001-11-17 Radeon M6 (ppc) support, Daniel Berlin, 0.1.2
19 * 2001-11-18 DFP fixes, Kevin Hendricks, 0.1.3
20 * 2001-11-29 more cmap, backlight fixes, Benjamin Herrenschmidt
21 * 2002-01-18 DFP panel detection via BIOS, Michael Clark, 0.1.4
22 * 2002-06-02 console switching, mode set fixes, accel fixes
23 * 2002-06-03 MTRR support, Peter Horton, 0.1.5
24 * 2002-09-21 rv250, r300, m9 initial support,
25 * added mirror option, 0.1.6
27 * Special thanks to ATI DevRel team for their hardware donations.
32 #define RADEON_VERSION "0.1.6"
35 #include <linux/config.h>
36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/errno.h>
39 #include <linux/string.h>
41 #include <linux/tty.h>
42 #include <linux/slab.h>
43 #include <linux/delay.h>
45 #include <linux/ioport.h>
46 #include <linux/init.h>
47 #include <linux/pci.h>
48 #include <linux/vmalloc.h>
51 #include <asm/uaccess.h>
52 #if defined(__powerpc__)
54 #include <asm/pci-bridge.h>
58 #include <linux/nvram.h>
61 #ifdef CONFIG_PMAC_BACKLIGHT
62 #include <asm/backlight.h>
65 #ifdef CONFIG_BOOTX_TEXT
66 #include <asm/btext.h>
70 #include <linux/adb.h>
71 #include <linux/pmu.h>
74 #endif /* __powerpc__ */
80 #include <video/radeon.h>
81 #include <linux/radeonfb.h>
88 #define RTRACE if(0) printk
92 #undef CONFIG_PMAC_PBOOK
140 static struct radeon_chip_info {
143 } radeon_chip_info[] __devinitdata = {
144 { "QD", RADEON_R100 },
145 { "QE", RADEON_R100 },
146 { "QF", RADEON_R100 },
147 { "QG", RADEON_R100 },
148 { "VE QY", RADEON_RV100 },
149 { "VE QZ", RADEON_RV100 },
150 { "M7 LW", RADEON_M7 },
151 { "M7 LX", RADEON_M7 },
152 { "M6 LY", RADEON_M6 },
153 { "M6 LZ", RADEON_M6 },
154 { "8500 QL", RADEON_R200 },
155 { "8500 QN", RADEON_R200 },
156 { "8500 QO", RADEON_R200 },
157 { "8500 Ql", RADEON_R200 },
158 { "8500 BB", RADEON_R200 },
159 { "7500 QW", RADEON_RV200 },
160 { "7500 QX", RADEON_RV200 },
161 { "9000 Id", RADEON_RV250 },
162 { "9000 Ie", RADEON_RV250 },
163 { "9000 If", RADEON_RV250 },
164 { "9000 Ig", RADEON_RV250 },
165 { "M9 Ld", RADEON_M9 },
166 { "M9 Le", RADEON_M9 },
167 { "M9 Lf", RADEON_M9 },
168 { "M9 Lg", RADEON_M9 },
169 { "9700 ND", RADEON_R300 },
170 { "9700 NE", RADEON_R300 },
171 { "9700 NF", RADEON_R300 },
172 { "9700 NG", RADEON_R300 },
173 { "9100 QM", RADEON_R200 }
183 MT_CTV, /* composite TV */
184 MT_STV /* S-Video out */
188 static struct pci_device_id radeonfb_pci_table[] __devinitdata = {
189 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QD},
190 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QE},
191 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QF},
192 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QG, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QG},
193 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QY, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QY},
194 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QZ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QZ},
195 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LW, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LW},
196 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LX},
197 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LY, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LY},
198 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LZ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LZ},
199 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QL, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QL},
200 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QN, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QN},
201 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QO},
202 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ql, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ql},
203 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_BB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_BB},
204 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QW, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QW},
205 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QX},
206 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Id},
207 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ie, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ie},
208 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_If, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_If},
209 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ig, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ig},
210 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ld, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ld},
211 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Le, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Le},
212 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Lf, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Lf},
213 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Lg, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Lg},
214 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_ND, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_ND},
215 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NE},
216 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NF},
217 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NG, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NG},
218 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QM},
221 MODULE_DEVICE_TABLE(pci, radeonfb_pci_table);
230 /* these common regs are cleared before mode setting so they do not
231 * interfere with anything
233 reg_val common_regs[] = {
235 { OVR_WID_LEFT_RIGHT, 0 },
236 { OVR_WID_TOP_BOTTOM, 0 },
237 { OV0_SCALE_CNTL, 0 },
242 { CAP0_TRIG_CNTL, 0 },
245 reg_val common_regs_m6[] = {
247 { OVR_WID_LEFT_RIGHT, 0 },
248 { OVR_WID_TOP_BOTTOM, 0 },
249 { OV0_SCALE_CNTL, 0 },
252 { CAP0_TRIG_CNTL, 0 }
258 u8 accelerator_entry;
260 u16 VGA_table_offset;
261 u16 POST_table_offset;
267 u16 PCLK_ref_divider;
271 u16 MCLK_ref_divider;
275 u16 XCLK_ref_divider;
278 } __attribute__ ((packed)) PLL_BLOCK;
305 u32 crtc_h_total_disp;
306 u32 crtc_h_sync_strt_wid;
307 u32 crtc_v_total_disp;
308 u32 crtc_v_sync_strt_wid;
327 /* Flat panel regs */
328 u32 fp_crtc_h_total_disp;
329 u32 fp_crtc_v_total_disp;
331 u32 fp_h_sync_strt_wid;
334 u32 fp_v_sync_strt_wid;
339 u32 tmds_transmitter_cntl;
341 #if defined(__BIG_ENDIAN)
347 struct radeonfb_info {
350 struct radeon_regs state;
351 struct radeon_regs init_state;
356 unsigned long mmio_base_phys;
357 unsigned long fb_base_phys;
359 unsigned long mmio_base;
360 unsigned long fb_base;
362 struct pci_dev *pdev;
365 unsigned char *bios_seg;
367 u32 pseudo_palette[17];
368 struct { u8 red, green, blue, pad; } palette[256];
374 int pitch, bpp, depth;
375 int xres, yres, pixclock;
376 int xres_virtual, yres_virtual;
386 int panel_xres, panel_yres;
388 int hOver_plus, hSync_width, hblank;
389 int vOver_plus, vSync_width, vblank;
390 int hAct_high, vAct_high, interlaced;
393 u32 dp_gui_master_cntl;
396 int pll_output_freq, post_div, fb_div;
402 #ifdef CONFIG_PMAC_PBOOK
406 #endif /* CONFIG_PMAC_PBOOK */
409 struct radeonfb_info *next;
413 static struct fb_var_screeninfo radeonfb_default_var = {
414 640, 480, 640, 480, 0, 0, 8, 0,
415 {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
416 0, 0, -1, -1, 0, 39721, 40, 24, 32, 11, 96, 2,
417 0, FB_VMODE_NONINTERLACED
424 #define INREG8(addr) readb((rinfo->mmio_base)+addr)
425 #define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr)
426 #define INREG(addr) readl((rinfo->mmio_base)+addr)
427 #define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr)
429 #define OUTPLL(addr,val) \
431 OUTREG8(CLOCK_CNTL_INDEX, (addr & 0x0000003f) | 0x00000080); \
432 OUTREG(CLOCK_CNTL_DATA, val); \
435 #define OUTPLLP(addr,val,mask) \
437 unsigned int _tmp = INPLL(addr); \
440 OUTPLL(addr, _tmp); \
443 #define OUTREGP(addr,val,mask) \
445 unsigned int _tmp = INREG(addr); \
448 OUTREG(addr, _tmp); \
452 static __inline__ u32 _INPLL(struct radeonfb_info *rinfo, u32 addr)
454 OUTREG8(CLOCK_CNTL_INDEX, addr & 0x0000003f);
455 return (INREG(CLOCK_CNTL_DATA));
458 #define INPLL(addr) _INPLL(rinfo, addr)
460 #define PRIMARY_MONITOR(rinfo) ((rinfo->dviDisp_type != MT_NONE) && \
461 (rinfo->dviDisp_type != MT_STV) && \
462 (rinfo->dviDisp_type != MT_CTV) ? \
463 rinfo->dviDisp_type : rinfo->crtDisp_type)
465 static char *GET_MON_NAME(int type)
498 static __inline__ void radeon_engine_flush (struct radeonfb_info *rinfo)
503 OUTREGP(RB2D_DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL,
506 for (i=0; i < 2000000; i++) {
507 if (!(INREG(RB2D_DSTCACHE_CTLSTAT) & RB2D_DC_BUSY))
513 static __inline__ void _radeon_fifo_wait (struct radeonfb_info *rinfo, int entries)
517 for (i=0; i<2000000; i++)
518 if ((INREG(RBBM_STATUS) & 0x7f) >= entries)
523 static __inline__ void _radeon_engine_idle (struct radeonfb_info *rinfo)
527 /* ensure FIFO is empty before waiting for idle */
528 _radeon_fifo_wait (rinfo, 64);
530 for (i=0; i<2000000; i++) {
531 if (((INREG(RBBM_STATUS) & GUI_ACTIVE)) == 0) {
532 radeon_engine_flush (rinfo);
539 #define radeon_engine_idle() _radeon_engine_idle(rinfo)
540 #define radeon_fifo_wait(entries) _radeon_fifo_wait(rinfo,entries)
548 static __inline__ u32 radeon_get_dstbpp(u16 depth)
565 static inline int var_to_depth(const struct fb_var_screeninfo *var)
567 if (var->bits_per_pixel != 16)
568 return var->bits_per_pixel;
569 return (var->green.length == 6) ? 16 : 15;
573 static void _radeon_engine_reset(struct radeonfb_info *rinfo)
575 u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset;
577 radeon_engine_flush (rinfo);
579 clock_cntl_index = INREG(CLOCK_CNTL_INDEX);
580 mclk_cntl = INPLL(MCLK_CNTL);
582 OUTPLL(MCLK_CNTL, (mclk_cntl |
589 rbbm_soft_reset = INREG(RBBM_SOFT_RESET);
591 OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset |
599 INREG(RBBM_SOFT_RESET);
600 OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset & (u32)
608 INREG(RBBM_SOFT_RESET);
610 OUTPLL(MCLK_CNTL, mclk_cntl);
611 OUTREG(CLOCK_CNTL_INDEX, clock_cntl_index);
612 OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset);
617 #define radeon_engine_reset() _radeon_engine_reset(rinfo)
620 static __inline__ u8 radeon_get_post_div_bitval(int post_div)
644 static __inline__ int round_div(int num, int den)
646 return (num + (den / 2)) / den;
651 static __inline__ int min_bits_req(int val)
667 static __inline__ int _max(int val1, int val2)
681 static char *mode_option __initdata;
682 static char noaccel = 1;
683 static char mirror = 0;
684 static int panel_yres __initdata = 0;
685 static char force_dfp __initdata = 0;
686 static struct radeonfb_info *board_list = NULL;
687 static char nomtrr __initdata = 0;
693 static void radeon_save_state (struct radeonfb_info *rinfo,
694 struct radeon_regs *save);
695 static void radeon_engine_init (struct radeonfb_info *rinfo);
696 static void radeon_write_mode (struct radeonfb_info *rinfo,
697 struct radeon_regs *mode);
698 static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo);
699 static int __devinit radeon_init_disp (struct radeonfb_info *rinfo);
700 static int radeon_init_disp_var (struct radeonfb_info *rinfo, struct fb_var_screeninfo *var);
701 static char *radeon_find_rom(struct radeonfb_info *rinfo);
702 static void radeon_get_pllinfo(struct radeonfb_info *rinfo, char *bios_seg);
703 static void radeon_get_moninfo (struct radeonfb_info *rinfo);
704 static int radeon_get_dfpinfo (struct radeonfb_info *rinfo);
705 static int radeon_get_dfpinfo_BIOS(struct radeonfb_info *rinfo);
706 static void radeon_get_EDID(struct radeonfb_info *rinfo);
707 static int radeon_dfp_parse_EDID(struct radeonfb_info *rinfo);
708 static void radeon_update_default_var(struct radeonfb_info *rinfo);
710 #ifdef CONFIG_ALL_PPC
712 static int radeon_read_OF (struct radeonfb_info *rinfo);
713 static int radeon_get_EDID_OF(struct radeonfb_info *rinfo);
714 extern struct device_node *pci_device_to_OF_node(struct pci_dev *dev);
716 #ifdef CONFIG_PMAC_PBOOK
717 int radeon_sleep_notify(struct pmu_sleep_notifier *self, int when);
718 static struct pmu_sleep_notifier radeon_sleep_notifier = {
719 radeon_sleep_notify, SLEEP_LEVEL_VIDEO,
721 #endif /* CONFIG_PMAC_PBOOK */
722 #ifdef CONFIG_PMAC_BACKLIGHT
723 static int radeon_set_backlight_enable(int on, int level, void *data);
724 static int radeon_set_backlight_level(int level, void *data);
725 static struct backlight_controller radeon_backlight_controller = {
726 radeon_set_backlight_enable,
727 radeon_set_backlight_level
729 #endif /* CONFIG_PMAC_BACKLIGHT */
731 #endif /* CONFIG_ALL_PPC */
734 static char *radeon_find_rom(struct radeonfb_info *rinfo)
736 #if defined(__i386__)
742 char aty_rom_sig[] = "761295520";
743 char *radeon_sig[] = {
748 for(segstart=0x000c0000; segstart<0x000f0000; segstart+=0x00001000) {
752 rom_base = (char *)ioremap(segstart, 0x1000);
754 if ((*rom_base == 0x55) && (((*(rom_base + 1)) & 0xff) == 0xaa))
765 for (i = 0; (i < 128 - strlen(aty_rom_sig)) && (stage != 3); i++) {
766 if (aty_rom_sig[0] == *rom)
767 if (strncmp(aty_rom_sig, rom,
768 strlen(aty_rom_sig)) == 0)
778 for (i = 0; (i < 512) && (stage != 4); i++) {
779 for(j = 0;j < sizeof(radeon_sig)/sizeof(char *);j++) {
780 if (radeon_sig[j][0] == *rom)
781 if (strncmp(radeon_sig[j], rom,
782 strlen(radeon_sig[j])) == 0) {
803 static void radeon_get_pllinfo(struct radeonfb_info *rinfo, char *bios_seg)
807 u16 bios_header_offset, pll_info_offset;
811 bios_header = bios_seg + 0x48L;
812 header_ptr = bios_header;
814 bios_header_offset = readw(header_ptr);
815 bios_header = bios_seg + bios_header_offset;
818 header_ptr = bios_header;
819 pll_info_offset = readw(header_ptr);
820 header_ptr = bios_seg + pll_info_offset;
822 memcpy_fromio(&pll, header_ptr, 50);
824 rinfo->pll.xclk = (u32)pll.XCLK;
825 rinfo->pll.ref_clk = (u32)pll.PCLK_ref_freq;
826 rinfo->pll.ref_div = (u32)pll.PCLK_ref_divider;
827 rinfo->pll.ppll_min = pll.PCLK_min_freq;
828 rinfo->pll.ppll_max = pll.PCLK_max_freq;
830 printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d from BIOS\n",
831 rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk);
833 #ifdef CONFIG_ALL_PPC
834 if (radeon_read_OF(rinfo)) {
835 unsigned int tmp, Nx, M, ref_div, xclk;
837 tmp = INPLL(M_SPLL_REF_FB_DIV);
838 ref_div = INPLL(PPLL_REF_DIV) & 0x3ff;
840 Nx = (tmp & 0xff00) >> 8;
842 xclk = ((((2 * Nx * rinfo->pll.ref_clk) + (M)) /
845 rinfo->pll.xclk = xclk;
846 rinfo->pll.ref_div = ref_div;
847 rinfo->pll.ppll_min = 12000;
848 rinfo->pll.ppll_max = 35000;
850 printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d from OF\n",
851 rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk);
856 /* no BIOS or BIOS not found, use defaults */
857 switch (rinfo->chipset) {
858 case PCI_DEVICE_ID_ATI_RADEON_QW:
859 case PCI_DEVICE_ID_ATI_RADEON_QX:
860 rinfo->pll.ppll_max = 35000;
861 rinfo->pll.ppll_min = 12000;
862 rinfo->pll.xclk = 23000;
863 rinfo->pll.ref_div = 12;
864 rinfo->pll.ref_clk = 2700;
866 case PCI_DEVICE_ID_ATI_RADEON_QL:
867 case PCI_DEVICE_ID_ATI_RADEON_QN:
868 case PCI_DEVICE_ID_ATI_RADEON_QO:
869 case PCI_DEVICE_ID_ATI_RADEON_Ql:
870 case PCI_DEVICE_ID_ATI_RADEON_BB:
871 rinfo->pll.ppll_max = 35000;
872 rinfo->pll.ppll_min = 12000;
873 rinfo->pll.xclk = 27500;
874 rinfo->pll.ref_div = 12;
875 rinfo->pll.ref_clk = 2700;
877 case PCI_DEVICE_ID_ATI_RADEON_Id:
878 case PCI_DEVICE_ID_ATI_RADEON_Ie:
879 case PCI_DEVICE_ID_ATI_RADEON_If:
880 case PCI_DEVICE_ID_ATI_RADEON_Ig:
881 rinfo->pll.ppll_max = 35000;
882 rinfo->pll.ppll_min = 12000;
883 rinfo->pll.xclk = 25000;
884 rinfo->pll.ref_div = 12;
885 rinfo->pll.ref_clk = 2700;
887 case PCI_DEVICE_ID_ATI_RADEON_ND:
888 case PCI_DEVICE_ID_ATI_RADEON_NE:
889 case PCI_DEVICE_ID_ATI_RADEON_NF:
890 case PCI_DEVICE_ID_ATI_RADEON_NG:
891 rinfo->pll.ppll_max = 40000;
892 rinfo->pll.ppll_min = 20000;
893 rinfo->pll.xclk = 27000;
894 rinfo->pll.ref_div = 12;
895 rinfo->pll.ref_clk = 2700;
897 case PCI_DEVICE_ID_ATI_RADEON_QD:
898 case PCI_DEVICE_ID_ATI_RADEON_QE:
899 case PCI_DEVICE_ID_ATI_RADEON_QF:
900 case PCI_DEVICE_ID_ATI_RADEON_QG:
902 rinfo->pll.ppll_max = 35000;
903 rinfo->pll.ppll_min = 12000;
904 rinfo->pll.xclk = 16600;
905 rinfo->pll.ref_div = 67;
906 rinfo->pll.ref_clk = 2700;
910 printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d defaults\n",
911 rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk);
916 static void radeon_get_moninfo (struct radeonfb_info *rinfo)
921 rinfo->dviDisp_type = MT_DFP;
925 tmp = INREG(RADEON_BIOS_4_SCRATCH);
926 printk(KERN_DEBUG "radeon_get_moninfo: bios 4 scratch = %x\n", tmp);
928 if (rinfo->hasCRTC2) {
929 /* primary DVI port */
931 rinfo->dviDisp_type = MT_DFP;
933 rinfo->dviDisp_type = MT_LCD;
934 else if (tmp & 0x200)
935 rinfo->dviDisp_type = MT_CRT;
937 rinfo->dviDisp_type = MT_CTV;
939 rinfo->dviDisp_type = MT_STV;
941 /* secondary CRT port */
943 rinfo->crtDisp_type = MT_CRT;
944 else if (tmp & 0x800)
945 rinfo->crtDisp_type = MT_DFP;
946 else if (tmp & 0x400)
947 rinfo->crtDisp_type = MT_LCD;
948 else if (tmp & 0x1000)
949 rinfo->crtDisp_type = MT_CTV;
950 else if (tmp & 0x2000)
951 rinfo->crtDisp_type = MT_STV;
953 rinfo->dviDisp_type = MT_NONE;
955 tmp = INREG(FP_GEN_CNTL);
957 if (tmp & FP_EN_TMDS)
958 rinfo->crtDisp_type = MT_DFP;
960 rinfo->crtDisp_type = MT_CRT;
966 static void radeon_get_EDID(struct radeonfb_info *rinfo)
968 #ifdef CONFIG_ALL_PPC
969 if (!radeon_get_EDID_OF(rinfo))
970 RTRACE("radeonfb: could not retrieve EDID from OF\n");
972 /* XXX use other methods later */
977 #ifdef CONFIG_ALL_PPC
978 static int radeon_get_EDID_OF(struct radeonfb_info *rinfo)
980 struct device_node *dp;
981 unsigned char *pedid = NULL;
982 static char *propnames[] = { "DFP,EDID", "LCD,EDID", "EDID", "EDID1", NULL };
985 dp = pci_device_to_OF_node(rinfo->pdev);
987 for (i = 0; propnames[i] != NULL; ++i) {
988 pedid = (unsigned char *)
989 get_property(dp, propnames[i], NULL);
999 #endif /* CONFIG_ALL_PPC */
1002 static int radeon_dfp_parse_EDID(struct radeonfb_info *rinfo)
1004 unsigned char *block = rinfo->EDID;
1009 /* jump to the detailed timing block section */
1012 rinfo->clock = (block[0] + (block[1] << 8));
1013 rinfo->panel_xres = (block[2] + ((block[4] & 0xf0) << 4));
1014 rinfo->hblank = (block[3] + ((block[4] & 0x0f) << 8));
1015 rinfo->panel_yres = (block[5] + ((block[7] & 0xf0) << 4));
1016 rinfo->vblank = (block[6] + ((block[7] & 0x0f) << 8));
1017 rinfo->hOver_plus = (block[8] + ((block[11] & 0xc0) << 2));
1018 rinfo->hSync_width = (block[9] + ((block[11] & 0x30) << 4));
1019 rinfo->vOver_plus = ((block[10] >> 4) + ((block[11] & 0x0c) << 2));
1020 rinfo->vSync_width = ((block[10] & 0x0f) + ((block[11] & 0x03) << 4));
1021 rinfo->interlaced = ((block[17] & 0x80) >> 7);
1022 rinfo->synct = ((block[17] & 0x18) >> 3);
1023 rinfo->misc = ((block[17] & 0x06) >> 1);
1024 rinfo->hAct_high = rinfo->vAct_high = 0;
1025 if (rinfo->synct == 3) {
1026 if (rinfo->misc & 2)
1027 rinfo->hAct_high = 1;
1028 if (rinfo->misc & 1)
1029 rinfo->vAct_high = 1;
1032 printk("radeonfb: detected DFP panel size from EDID: %dx%d\n",
1033 rinfo->panel_xres, rinfo->panel_yres);
1035 rinfo->got_dfpinfo = 1;
1041 static void radeon_update_default_var(struct radeonfb_info *rinfo)
1043 struct fb_var_screeninfo *var = &radeonfb_default_var;
1045 var->xres = rinfo->panel_xres;
1046 var->yres = rinfo->panel_yres;
1047 var->xres_virtual = rinfo->panel_xres;
1048 var->yres_virtual = rinfo->panel_yres;
1049 var->xoffset = var->yoffset = 0;
1050 var->bits_per_pixel = 8;
1051 var->pixclock = 100000000 / rinfo->clock;
1052 var->left_margin = (rinfo->hblank - rinfo->hOver_plus - rinfo->hSync_width);
1053 var->right_margin = rinfo->hOver_plus;
1054 var->upper_margin = (rinfo->vblank - rinfo->vOver_plus - rinfo->vSync_width);
1055 var->lower_margin = rinfo->vOver_plus;
1056 var->hsync_len = rinfo->hSync_width;
1057 var->vsync_len = rinfo->vSync_width;
1059 if (rinfo->synct == 3) {
1060 if (rinfo->hAct_high)
1061 var->sync |= FB_SYNC_HOR_HIGH_ACT;
1062 if (rinfo->vAct_high)
1063 var->sync |= FB_SYNC_VERT_HIGH_ACT;
1067 if (rinfo->interlaced)
1068 var->vmode |= FB_VMODE_INTERLACED;
1070 rinfo->use_default_var = 1;
1074 static int radeon_get_dfpinfo_BIOS(struct radeonfb_info *rinfo)
1076 char *fpbiosstart, *tmp, *tmp0;
1080 if (!rinfo->bios_seg)
1083 if (!(fpbiosstart = rinfo->bios_seg + readw(rinfo->bios_seg + 0x48))) {
1084 printk("radeonfb: Failed to detect DFP panel info using BIOS\n");
1088 if (!(tmp = rinfo->bios_seg + readw(fpbiosstart + 0x40))) {
1089 printk("radeonfb: Failed to detect DFP panel info using BIOS\n");
1094 stmp[i] = readb(tmp+i+1);
1096 printk("radeonfb: panel ID string: %s\n", stmp);
1097 rinfo->panel_xres = readw(tmp + 25);
1098 rinfo->panel_yres = readw(tmp + 27);
1099 printk("radeonfb: detected DFP panel size from BIOS: %dx%d\n",
1100 rinfo->panel_xres, rinfo->panel_yres);
1102 for(i=0; i<20; i++) {
1103 tmp0 = rinfo->bios_seg + readw(tmp+64+i*2);
1106 if ((readw(tmp0) == rinfo->panel_xres) &&
1107 (readw(tmp0+2) == rinfo->panel_yres)) {
1108 rinfo->hblank = (readw(tmp0+17) - readw(tmp0+19)) * 8;
1109 rinfo->hOver_plus = ((readw(tmp0+21) - readw(tmp0+19) -1) * 8) & 0x7fff;
1110 rinfo->hSync_width = readb(tmp0+23) * 8;
1111 rinfo->vblank = readw(tmp0+24) - readw(tmp0+26);
1112 rinfo->vOver_plus = (readw(tmp0+28) & 0x7ff) - readw(tmp0+26);
1113 rinfo->vSync_width = (readw(tmp0+28) & 0xf800) >> 11;
1114 rinfo->clock = readw(tmp0+9);
1116 rinfo->got_dfpinfo = 1;
1126 static int radeon_get_dfpinfo (struct radeonfb_info *rinfo)
1129 unsigned short a, b;
1131 if (radeon_get_dfpinfo_BIOS(rinfo))
1132 radeon_update_default_var(rinfo);
1134 if (radeon_dfp_parse_EDID(rinfo))
1135 radeon_update_default_var(rinfo);
1137 if (!rinfo->got_dfpinfo) {
1139 * it seems all else has failed now and we
1140 * resort to probing registers for our DFP info
1143 rinfo->panel_yres = panel_yres;
1145 tmp = INREG(FP_VERT_STRETCH);
1147 rinfo->panel_yres = (unsigned short)(tmp >> 0x0c) + 1;
1150 switch (rinfo->panel_yres) {
1152 rinfo->panel_xres = 640;
1155 rinfo->panel_xres = 800;
1158 #if defined(__powerpc__)
1159 if (rinfo->dviDisp_type == MT_LCD)
1160 rinfo->panel_xres = 1152;
1163 rinfo->panel_xres = 1024;
1166 rinfo->panel_xres = 1280;
1169 rinfo->panel_xres = 1400;
1172 rinfo->panel_xres = 1600;
1175 printk("radeonfb: Failed to detect DFP panel size\n");
1179 printk("radeonfb: detected DFP panel size from registers: %dx%d\n",
1180 rinfo->panel_xres, rinfo->panel_yres);
1182 tmp = INREG(FP_CRTC_H_TOTAL_DISP);
1183 a = (tmp & FP_CRTC_H_TOTAL_MASK) + 4;
1184 b = (tmp & 0x01ff0000) >> FP_CRTC_H_DISP_SHIFT;
1185 rinfo->hblank = (a - b + 1) * 8;
1187 tmp = INREG(FP_H_SYNC_STRT_WID);
1188 rinfo->hOver_plus = (unsigned short) ((tmp & FP_H_SYNC_STRT_CHAR_MASK) >>
1189 FP_H_SYNC_STRT_CHAR_SHIFT) - b - 1;
1190 rinfo->hOver_plus *= 8;
1191 rinfo->hSync_width = (unsigned short) ((tmp & FP_H_SYNC_WID_MASK) >>
1192 FP_H_SYNC_WID_SHIFT);
1193 rinfo->hSync_width *= 8;
1194 tmp = INREG(FP_CRTC_V_TOTAL_DISP);
1195 a = (tmp & FP_CRTC_V_TOTAL_MASK) + 1;
1196 b = (tmp & FP_CRTC_V_DISP_MASK) >> FP_CRTC_V_DISP_SHIFT;
1197 rinfo->vblank = a - b /* + 24 */ ;
1199 tmp = INREG(FP_V_SYNC_STRT_WID);
1200 rinfo->vOver_plus = (unsigned short) (tmp & FP_V_SYNC_STRT_MASK)
1202 rinfo->vSync_width = (unsigned short) ((tmp & FP_V_SYNC_WID_MASK) >>
1203 FP_V_SYNC_WID_SHIFT);
1212 #ifdef CONFIG_ALL_PPC
1213 static int radeon_read_OF (struct radeonfb_info *rinfo)
1215 struct device_node *dp;
1218 dp = pci_device_to_OF_node(rinfo->pdev);
1220 xtal = (unsigned int *) get_property(dp, "ATY,RefCLK", 0);
1222 rinfo->pll.ref_clk = *xtal / 10;
1232 static void radeon_engine_init (struct radeonfb_info *rinfo)
1236 /* disable 3D engine */
1237 OUTREG(RB3D_CNTL, 0);
1239 radeon_engine_reset ();
1241 radeon_fifo_wait (1);
1242 OUTREG(RB2D_DSTCACHE_MODE, 0);
1245 rinfo->pitch = ((rinfo->xres_virtual * (rinfo->bpp / 8) + 0x3f)) >> 6;
1247 radeon_fifo_wait (1);
1248 temp = INREG(DEFAULT_PITCH_OFFSET);
1249 OUTREG(DEFAULT_PITCH_OFFSET, ((temp & 0xc0000000) |
1250 (rinfo->pitch << 0x16)));
1252 radeon_fifo_wait (1);
1253 OUTREGP(DP_DATATYPE, 0, ~HOST_BIG_ENDIAN_EN);
1255 radeon_fifo_wait (1);
1256 OUTREG(DEFAULT_SC_BOTTOM_RIGHT, (DEFAULT_SC_RIGHT_MAX |
1257 DEFAULT_SC_BOTTOM_MAX));
1259 temp = radeon_get_dstbpp(rinfo->depth);
1260 rinfo->dp_gui_master_cntl = ((temp << 8) | GMC_CLR_CMP_CNTL_DIS);
1261 radeon_fifo_wait (1);
1262 OUTREG(DP_GUI_MASTER_CNTL, (rinfo->dp_gui_master_cntl |
1263 GMC_BRUSH_SOLID_COLOR |
1264 GMC_SRC_DATATYPE_COLOR));
1266 radeon_fifo_wait (7);
1268 /* clear line drawing regs */
1269 OUTREG(DST_LINE_START, 0);
1270 OUTREG(DST_LINE_END, 0);
1272 /* set brush color regs */
1273 OUTREG(DP_BRUSH_FRGD_CLR, 0xffffffff);
1274 OUTREG(DP_BRUSH_BKGD_CLR, 0x00000000);
1276 /* set source color regs */
1277 OUTREG(DP_SRC_FRGD_CLR, 0xffffffff);
1278 OUTREG(DP_SRC_BKGD_CLR, 0x00000000);
1280 /* default write mask */
1281 OUTREG(DP_WRITE_MSK, 0xffffffff);
1283 radeon_engine_idle ();
1287 static int __devinit radeon_init_disp (struct radeonfb_info *rinfo)
1289 struct fb_info *info = &rinfo->info;
1290 struct fb_var_screeninfo var;
1292 var = radeonfb_default_var;
1293 if ((radeon_init_disp_var(rinfo, &var)) < 0)
1296 rinfo->depth = var_to_depth(&var);
1297 rinfo->bpp = var.bits_per_pixel;
1300 fb_alloc_cmap(&info->cmap, 256, 0);
1302 var.activate = FB_ACTIVATE_NOW;
1307 static int radeon_init_disp_var (struct radeonfb_info *rinfo,
1308 struct fb_var_screeninfo *var)
1312 fb_find_mode (var, &rinfo->info, mode_option,
1316 if (rinfo->use_default_var)
1317 /* We will use the modified default far */
1318 *var = radeonfb_default_var;
1321 fb_find_mode (var, &rinfo->info, "640x480-8@60",
1325 var->accel_flags &= ~FB_ACCELF_TEXT;
1327 var->accel_flags |= FB_ACCELF_TEXT;
1333 static int radeon_do_maximize(struct radeonfb_info *rinfo,
1334 struct fb_var_screeninfo *var,
1335 struct fb_var_screeninfo *v,
1350 /* use highest possible virtual resolution */
1351 if (v->xres_virtual == -1 && v->yres_virtual == -1) {
1352 printk("radeonfb: using max available virtual resolution\n");
1353 for (i=0; modes[i].xres != -1; i++) {
1354 if (modes[i].xres * nom / den * modes[i].yres <
1355 rinfo->video_ram / 2)
1358 if (modes[i].xres == -1) {
1359 printk("radeonfb: could not find virtual resolution that fits into video memory!\n");
1362 v->xres_virtual = modes[i].xres;
1363 v->yres_virtual = modes[i].yres;
1365 printk("radeonfb: virtual resolution set to max of %dx%d\n",
1366 v->xres_virtual, v->yres_virtual);
1367 } else if (v->xres_virtual == -1) {
1368 v->xres_virtual = (rinfo->video_ram * den /
1369 (nom * v->yres_virtual * 2)) & ~15;
1370 } else if (v->yres_virtual == -1) {
1371 v->xres_virtual = (v->xres_virtual + 15) & ~15;
1372 v->yres_virtual = rinfo->video_ram * den /
1373 (nom * v->xres_virtual *2);
1375 if (v->xres_virtual * nom / den * v->yres_virtual >
1381 if (v->xres_virtual * nom / den >= 8192) {
1382 v->xres_virtual = 8192 * den / nom - 16;
1385 if (v->xres_virtual < v->xres)
1388 if (v->yres_virtual < v->yres)
1395 static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info)
1397 struct radeonfb_info *rinfo = (struct radeonfb_info *) info->par;
1398 struct fb_var_screeninfo v;
1401 memcpy (&v, var, sizeof (v));
1403 switch (v.bits_per_pixel) {
1405 v.bits_per_pixel = 8;
1408 v.bits_per_pixel = 16;
1411 #if 0 /* Doesn't seem to work */
1412 v.bits_per_pixel = 24;
1417 v.bits_per_pixel = 32;
1423 switch (var_to_depth(&v)) {
1426 v.red.offset = v.green.offset = v.blue.offset = 0;
1427 v.red.length = v.green.length = v.blue.length = 8;
1428 v.transp.offset = v.transp.length = 0;
1436 v.red.length = v.green.length = v.blue.length = 5;
1437 v.transp.offset = v.transp.length = 0;
1448 v.transp.offset = v.transp.length = 0;
1456 v.red.length = v.blue.length = v.green.length = 8;
1457 v.transp.offset = v.transp.length = 0;
1465 v.red.length = v.blue.length = v.green.length = 8;
1466 v.transp.offset = 24;
1467 v.transp.length = 8;
1470 printk ("radeonfb: mode %dx%dx%d rejected, color depth invalid\n",
1471 var->xres, var->yres, var->bits_per_pixel);
1475 if (radeon_do_maximize(rinfo, var, &v, nom, den) < 0)
1483 if (v.xoffset > v.xres_virtual - v.xres)
1484 v.xoffset = v.xres_virtual - v.xres - 1;
1486 if (v.yoffset > v.yres_virtual - v.yres)
1487 v.yoffset = v.yres_virtual - v.yres - 1;
1489 v.red.msb_right = v.green.msb_right = v.blue.msb_right =
1490 v.transp.offset = v.transp.length =
1491 v.transp.msb_right = 0;
1496 memcpy(var, &v, sizeof(v));
1502 static int radeonfb_pan_display (struct fb_var_screeninfo *var,
1503 struct fb_info *info)
1505 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
1507 if ((var->xoffset + var->xres > var->xres_virtual)
1508 || (var->yoffset + var->yres > var->yres_virtual))
1514 OUTREG(CRTC_OFFSET, ((var->yoffset * var->xres_virtual + var->xoffset)
1515 * var->bits_per_pixel / 8) & ~7);
1520 static int radeonfb_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
1521 unsigned long arg, struct fb_info *info)
1523 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
1530 * TODO: set mirror accordingly for non-Mobility chipsets with 2 CRTC's
1532 case FBIO_RADEON_SET_MIRROR:
1533 switch (rinfo->arch) {
1542 /* RADEON M6, RADEON_M7, RADEON_M9 */
1546 rc = get_user(value, (__u32*)arg);
1552 tmp = INREG(LVDS_GEN_CNTL);
1554 tmp |= (LVDS_ON | LVDS_BLON);
1556 tmp = INREG(LVDS_GEN_CNTL);
1558 tmp &= ~(LVDS_ON | LVDS_BLON);
1561 OUTREG(LVDS_GEN_CNTL, tmp);
1564 tmp = INREG(CRTC_EXT_CNTL);
1569 tmp = INREG(CRTC_EXT_CNTL);
1570 tmp &= ~CRTC_CRT_ON;
1575 OUTREG(CRTC_EXT_CNTL, tmp);
1578 case FBIO_RADEON_GET_MIRROR:
1579 switch (rinfo->arch) {
1588 /* RADEON M6, RADEON_M7, RADEON_M9 */
1592 tmp = INREG(LVDS_GEN_CNTL);
1593 if ((LVDS_ON | LVDS_BLON) & tmp)
1596 tmp = INREG(CRTC_EXT_CNTL);
1597 if (CRTC_CRT_ON & tmp)
1600 return put_user(value, (__u32*)arg);
1609 static int radeonfb_blank (int blank, struct fb_info *info)
1611 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
1612 u32 val = INREG(CRTC_EXT_CNTL);
1613 u32 val2 = INREG(LVDS_GEN_CNTL);
1618 #ifdef CONFIG_PMAC_BACKLIGHT
1619 if (rinfo->dviDisp_type == MT_LCD && _machine == _MACH_Pmac) {
1620 set_backlight_enable(!blank);
1626 val &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS |
1628 val2 &= ~(LVDS_DISPLAY_DIS);
1631 case VESA_NO_BLANKING:
1633 case VESA_VSYNC_SUSPEND:
1634 val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS);
1636 case VESA_HSYNC_SUSPEND:
1637 val |= (CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS);
1639 case VESA_POWERDOWN:
1640 val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS |
1642 val2 |= (LVDS_DISPLAY_DIS);
1646 switch (rinfo->dviDisp_type) {
1648 OUTREG(LVDS_GEN_CNTL, val2);
1652 OUTREG(CRTC_EXT_CNTL, val);
1660 static int radeonfb_setcolreg (unsigned regno, unsigned red, unsigned green,
1661 unsigned blue, unsigned transp, struct fb_info *info)
1663 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
1664 u32 pindex, vclk_cntl;
1673 rinfo->palette[regno].red = red;
1674 rinfo->palette[regno].green = green;
1675 rinfo->palette[regno].blue = blue;
1680 if (!rinfo->asleep) {
1681 vclk_cntl = INPLL(VCLK_ECP_CNTL);
1682 OUTPLL(VCLK_ECP_CNTL, vclk_cntl & ~PIXCLK_DAC_ALWAYS_ONb);
1684 if (rinfo->bpp == 16) {
1687 if (rinfo->depth == 16 && regno > 63)
1689 if (rinfo->depth == 15 && regno > 31)
1692 /* For 565, the green component is mixed one order below */
1693 if (rinfo->depth == 16) {
1694 OUTREG(PALETTE_INDEX, pindex>>1);
1695 OUTREG(PALETTE_DATA, (rinfo->palette[regno>>1].red << 16) |
1696 (green << 8) | (rinfo->palette[regno>>1].blue));
1697 green = rinfo->palette[regno<<1].green;
1701 if (rinfo->depth != 16 || regno < 32) {
1702 OUTREG(PALETTE_INDEX, pindex);
1703 OUTREG(PALETTE_DATA, (red << 16) | (green << 8) | blue);
1706 OUTPLL(VCLK_ECP_CNTL, vclk_cntl);
1709 switch (rinfo->depth) {
1711 ((u16 *) (info->pseudo_palette))[regno] =
1712 (regno << 10) | (regno << 5) | regno;
1715 ((u16 *) (info->pseudo_palette))[regno] =
1716 (regno << 11) | (regno << 6) | regno;
1719 ((u32 *) (info->pseudo_palette))[regno] =
1720 (regno << 16) | (regno << 8) | regno;
1723 i = (regno << 8) | regno;
1724 ((u32 *) (info->pseudo_palette))[regno] =
1734 static void radeon_save_state (struct radeonfb_info *rinfo,
1735 struct radeon_regs *save)
1738 save->crtc_gen_cntl = INREG(CRTC_GEN_CNTL);
1739 save->crtc_ext_cntl = INREG(CRTC_EXT_CNTL);
1740 save->dac_cntl = INREG(DAC_CNTL);
1741 save->crtc_h_total_disp = INREG(CRTC_H_TOTAL_DISP);
1742 save->crtc_h_sync_strt_wid = INREG(CRTC_H_SYNC_STRT_WID);
1743 save->crtc_v_total_disp = INREG(CRTC_V_TOTAL_DISP);
1744 save->crtc_v_sync_strt_wid = INREG(CRTC_V_SYNC_STRT_WID);
1745 save->crtc_pitch = INREG(CRTC_PITCH);
1746 #if defined(__BIG_ENDIAN)
1747 save->surface_cntl = INREG(SURFACE_CNTL);
1751 save->fp_crtc_h_total_disp = INREG(FP_CRTC_H_TOTAL_DISP);
1752 save->fp_crtc_v_total_disp = INREG(FP_CRTC_V_TOTAL_DISP);
1753 save->fp_gen_cntl = INREG(FP_GEN_CNTL);
1754 save->fp_h_sync_strt_wid = INREG(FP_H_SYNC_STRT_WID);
1755 save->fp_horz_stretch = INREG(FP_HORZ_STRETCH);
1756 save->fp_v_sync_strt_wid = INREG(FP_V_SYNC_STRT_WID);
1757 save->fp_vert_stretch = INREG(FP_VERT_STRETCH);
1758 save->lvds_gen_cntl = INREG(LVDS_GEN_CNTL);
1759 save->lvds_pll_cntl = INREG(LVDS_PLL_CNTL);
1760 save->tmds_crc = INREG(TMDS_CRC);
1761 save->tmds_transmitter_cntl = INREG(TMDS_TRANSMITTER_CNTL);
1762 save->vclk_ecp_cntl = INPLL(VCLK_ECP_CNTL);
1767 static int radeonfb_set_par (struct fb_info *info)
1769 struct radeonfb_info *rinfo = (struct radeonfb_info *)info->par;
1770 struct fb_var_screeninfo *mode = &info->var;
1771 struct radeon_regs newmode;
1772 int hTotal, vTotal, hSyncStart, hSyncEnd,
1773 hSyncPol, vSyncStart, vSyncEnd, vSyncPol, cSync;
1774 u8 hsync_adj_tab[] = {0, 0x12, 9, 9, 6, 5};
1775 u8 hsync_fudge_fp[] = {2, 2, 0, 0, 5, 5};
1776 u32 dotClock = 1000000000 / mode->pixclock,
1777 sync, h_sync_pol, v_sync_pol;
1778 int freq = dotClock / 10; /* x 100 */
1779 int xclk_freq, vclk_freq, xclk_per_trans, xclk_per_trans_precise;
1780 int useable_precision, roff, ron;
1781 int min_bits, format = 0;
1782 int hsync_start, hsync_fudge, bytpp, hsync_wid, vsync_wid;
1783 int primary_mon = PRIMARY_MONITOR(rinfo);
1784 int depth = var_to_depth(mode);
1786 rinfo->xres = mode->xres;
1787 rinfo->yres = mode->yres;
1788 rinfo->xres_virtual = mode->xres_virtual;
1789 rinfo->yres_virtual = mode->yres_virtual;
1790 rinfo->pixclock = mode->pixclock;
1792 hSyncStart = mode->xres + mode->right_margin;
1793 hSyncEnd = hSyncStart + mode->hsync_len;
1794 hTotal = hSyncEnd + mode->left_margin;
1796 vSyncStart = mode->yres + mode->lower_margin;
1797 vSyncEnd = vSyncStart + mode->vsync_len;
1798 vTotal = vSyncEnd + mode->upper_margin;
1800 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1801 if (rinfo->panel_xres < mode->xres)
1802 rinfo->xres = mode->xres = rinfo->panel_xres;
1803 if (rinfo->panel_yres < mode->yres)
1804 rinfo->yres = mode->yres = rinfo->panel_yres;
1806 hTotal = mode->xres + rinfo->hblank;
1807 hSyncStart = mode->xres + rinfo->hOver_plus;
1808 hSyncEnd = hSyncStart + rinfo->hSync_width;
1810 vTotal = mode->yres + rinfo->vblank;
1811 vSyncStart = mode->yres + rinfo->vOver_plus;
1812 vSyncEnd = vSyncStart + rinfo->vSync_width;
1816 h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
1817 v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
1819 RTRACE("hStart = %d, hEnd = %d, hTotal = %d\n",
1820 hSyncStart, hSyncEnd, hTotal);
1821 RTRACE("vStart = %d, vEnd = %d, vTotal = %d\n",
1822 vSyncStart, vSyncEnd, vTotal);
1824 hsync_wid = (hSyncEnd - hSyncStart) / 8;
1825 vsync_wid = vSyncEnd - vSyncStart;
1828 else if (hsync_wid > 0x3f) /* max */
1833 else if (vsync_wid > 0x1f) /* max */
1836 hSyncPol = mode->sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
1837 vSyncPol = mode->sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
1839 cSync = mode->sync & FB_SYNC_COMP_HIGH_ACT ? (1 << 4) : 0;
1841 format = radeon_get_dstbpp(depth);
1842 bytpp = mode->bits_per_pixel >> 3;
1844 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD))
1845 hsync_fudge = hsync_fudge_fp[format-1];
1847 hsync_fudge = hsync_adj_tab[format-1];
1849 hsync_start = hSyncStart - 8 + hsync_fudge;
1851 newmode.crtc_gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN |
1854 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1855 newmode.crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN;
1857 newmode.crtc_ext_cntl |= CRTC_CRT_ON;
1859 newmode.crtc_gen_cntl &= ~(CRTC_DBL_SCAN_EN |
1862 newmode.crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN |
1866 newmode.dac_cntl = /* INREG(DAC_CNTL) | */ DAC_MASK_ALL | DAC_VGA_ADR_EN |
1869 newmode.crtc_h_total_disp = ((((hTotal / 8) - 1) & 0x3ff) |
1870 (((mode->xres / 8) - 1) << 16));
1872 newmode.crtc_h_sync_strt_wid = ((hsync_start & 0x1fff) |
1873 (hsync_wid << 16) | (h_sync_pol << 23));
1875 newmode.crtc_v_total_disp = ((vTotal - 1) & 0xffff) |
1876 ((mode->yres - 1) << 16);
1878 newmode.crtc_v_sync_strt_wid = (((vSyncStart - 1) & 0xfff) |
1879 (vsync_wid << 16) | (v_sync_pol << 23));
1881 newmode.crtc_pitch = (mode->xres_virtual >> 3);
1882 newmode.crtc_pitch |= (newmode.crtc_pitch << 16);
1884 #if defined(__BIG_ENDIAN)
1886 * It looks like recent chips have a problem with SURFACE_CNTL,
1887 * setting SURF_TRANSLATION_DIS completely disables the
1888 * swapper as well, so we leave it unset now.
1890 newmode.surface_cntl = 0;
1892 /* Setup swapping on both apertures, though we currently
1893 * only use aperture 0, enabling swapper on aperture 1
1896 switch (mode->bits_per_pixel) {
1898 newmode.surface_cntl |= NONSURF_AP0_SWP_16BPP;
1899 newmode.surface_cntl |= NONSURF_AP1_SWP_16BPP;
1903 newmode.surface_cntl |= NONSURF_AP0_SWP_32BPP;
1904 newmode.surface_cntl |= NONSURF_AP1_SWP_32BPP;
1909 rinfo->pitch = ((mode->xres_virtual * ((mode->bits_per_pixel + 1) / 8) + 0x3f)
1912 RTRACE("h_total_disp = 0x%x\t hsync_strt_wid = 0x%x\n",
1913 newmode.crtc_h_total_disp, newmode.crtc_h_sync_strt_wid);
1914 RTRACE("v_total_disp = 0x%x\t vsync_strt_wid = 0x%x\n",
1915 newmode.crtc_v_total_disp, newmode.crtc_v_sync_strt_wid);
1917 newmode.xres = mode->xres;
1918 newmode.yres = mode->yres;
1920 rinfo->bpp = mode->bits_per_pixel;
1921 rinfo->depth = depth;
1923 if (freq > rinfo->pll.ppll_max)
1924 freq = rinfo->pll.ppll_max;
1925 if (freq*12 < rinfo->pll.ppll_min)
1926 freq = rinfo->pll.ppll_min / 12;
1945 for (post_div = &post_divs[0]; post_div->divider; ++post_div) {
1946 rinfo->pll_output_freq = post_div->divider * freq;
1947 if (rinfo->pll_output_freq >= rinfo->pll.ppll_min &&
1948 rinfo->pll_output_freq <= rinfo->pll.ppll_max)
1952 rinfo->post_div = post_div->divider;
1953 rinfo->fb_div = round_div(rinfo->pll.ref_div*rinfo->pll_output_freq,
1954 rinfo->pll.ref_clk);
1955 newmode.ppll_ref_div = rinfo->pll.ref_div;
1956 newmode.ppll_div_3 = rinfo->fb_div | (post_div->bitvalue << 16);
1958 newmode.vclk_ecp_cntl = rinfo->init_state.vclk_ecp_cntl;
1960 #ifdef CONFIG_ALL_PPC
1961 /* Gross hack for iBook with M7 until I find out a proper fix */
1962 if (machine_is_compatible("PowerBook4,3") && rinfo->arch == RADEON_M7)
1963 newmode.ppll_div_3 = 0x000600ad;
1964 #endif /* CONFIG_ALL_PPC */
1966 RTRACE("post div = 0x%x\n", rinfo->post_div);
1967 RTRACE("fb_div = 0x%x\n", rinfo->fb_div);
1968 RTRACE("ppll_div_3 = 0x%x\n", newmode.ppll_div_3);
1971 vclk_freq = round_div(rinfo->pll.ref_clk * rinfo->fb_div,
1972 rinfo->pll.ref_div * rinfo->post_div);
1973 xclk_freq = rinfo->pll.xclk;
1975 xclk_per_trans = round_div(xclk_freq * 128, vclk_freq * mode->bits_per_pixel);
1977 min_bits = min_bits_req(xclk_per_trans);
1978 useable_precision = min_bits + 1;
1980 xclk_per_trans_precise = round_div((xclk_freq * 128) << (11 - useable_precision),
1981 vclk_freq * mode->bits_per_pixel);
1983 ron = (4 * rinfo->ram.mb + 3 * _max(rinfo->ram.trcd - 2, 0) +
1984 2 * rinfo->ram.trp + rinfo->ram.twr + rinfo->ram.cl + rinfo->ram.tr2w +
1985 xclk_per_trans) << (11 - useable_precision);
1986 roff = xclk_per_trans_precise * (32 - 4);
1988 RTRACE("ron = %d, roff = %d\n", ron, roff);
1989 RTRACE("vclk_freq = %d, per = %d\n", vclk_freq, xclk_per_trans_precise);
1991 if ((ron + rinfo->ram.rloop) >= roff) {
1992 printk("radeonfb: error ron out of range\n");
1996 newmode.dda_config = (xclk_per_trans_precise |
1997 (useable_precision << 16) |
1998 (rinfo->ram.rloop << 20));
1999 newmode.dda_on_off = (ron << 16) | roff;
2001 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
2002 unsigned int hRatio, vRatio;
2004 /* We force the pixel clock to be always enabled. Allowing it
2005 * to be power managed during blanking would save power, but has
2006 * nasty interactions with the 2D engine & sleep code that haven't
2007 * been solved yet. --BenH
2009 newmode.vclk_ecp_cntl &= ~PIXCLK_DAC_ALWAYS_ONb;
2011 if (mode->xres > rinfo->panel_xres)
2012 mode->xres = rinfo->panel_xres;
2013 if (mode->yres > rinfo->panel_yres)
2014 mode->yres = rinfo->panel_yres;
2016 newmode.fp_horz_stretch = (((rinfo->panel_xres / 8) - 1)
2017 << HORZ_PANEL_SHIFT);
2018 newmode.fp_vert_stretch = ((rinfo->panel_yres - 1)
2019 << VERT_PANEL_SHIFT);
2021 if (mode->xres != rinfo->panel_xres) {
2022 hRatio = round_div(mode->xres * HORZ_STRETCH_RATIO_MAX,
2024 newmode.fp_horz_stretch = (((((unsigned long)hRatio) & HORZ_STRETCH_RATIO_MASK)) |
2025 (newmode.fp_horz_stretch &
2026 (HORZ_PANEL_SIZE | HORZ_FP_LOOP_STRETCH |
2027 HORZ_AUTO_RATIO_INC)));
2028 newmode.fp_horz_stretch |= (HORZ_STRETCH_BLEND |
2029 HORZ_STRETCH_ENABLE);
2031 newmode.fp_horz_stretch &= ~HORZ_AUTO_RATIO;
2033 if (mode->yres != rinfo->panel_yres) {
2034 vRatio = round_div(mode->yres * VERT_STRETCH_RATIO_MAX,
2036 newmode.fp_vert_stretch = (((((unsigned long)vRatio) & VERT_STRETCH_RATIO_MASK)) |
2037 (newmode.fp_vert_stretch &
2038 (VERT_PANEL_SIZE | VERT_STRETCH_RESERVED)));
2039 newmode.fp_vert_stretch |= (VERT_STRETCH_BLEND |
2040 VERT_STRETCH_ENABLE);
2042 newmode.fp_vert_stretch &= ~VERT_AUTO_RATIO_EN;
2044 newmode.fp_gen_cntl = (rinfo->init_state.fp_gen_cntl & (u32)
2046 FP_RMX_HVSYNC_CONTROL_EN |
2051 FP_CRTC_USE_SHADOW_VEND |
2054 newmode.fp_gen_cntl |= (FP_CRTC_DONT_SHADOW_VPAR |
2055 FP_CRTC_DONT_SHADOW_HEND);
2057 newmode.lvds_gen_cntl = rinfo->init_state.lvds_gen_cntl;
2058 newmode.lvds_pll_cntl = rinfo->init_state.lvds_pll_cntl;
2059 newmode.tmds_crc = rinfo->init_state.tmds_crc;
2060 newmode.tmds_transmitter_cntl = rinfo->init_state.tmds_transmitter_cntl;
2062 if (primary_mon == MT_LCD) {
2063 newmode.lvds_gen_cntl |= (LVDS_ON | LVDS_BLON);
2064 newmode.fp_gen_cntl &= ~(FP_FPON | FP_TMDS_EN);
2067 newmode.fp_gen_cntl |= (FP_FPON | FP_TMDS_EN);
2068 newmode.tmds_transmitter_cntl = (TMDS_RAN_PAT_RST |
2069 ICHCSEL | TMDS_PLL_EN) &
2071 newmode.crtc_ext_cntl &= ~CRTC_CRT_ON;
2074 newmode.fp_crtc_h_total_disp = (((rinfo->hblank / 8) & 0x3ff) |
2075 (((mode->xres / 8) - 1) << 16));
2076 newmode.fp_crtc_v_total_disp = (rinfo->vblank & 0xffff) |
2077 ((mode->yres - 1) << 16);
2078 newmode.fp_h_sync_strt_wid = ((rinfo->hOver_plus & 0x1fff) |
2079 (hsync_wid << 16) | (h_sync_pol << 23));
2080 newmode.fp_v_sync_strt_wid = ((rinfo->vOver_plus & 0xfff) |
2081 (vsync_wid << 16) | (v_sync_pol << 23));
2085 if (!rinfo->asleep) {
2086 radeon_write_mode (rinfo, &newmode);
2087 /* (re)initialize the engine */
2089 radeon_engine_init (rinfo);
2093 info->fix.line_length = rinfo->pitch*64;
2094 info->fix.visual = rinfo->depth == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
2096 #ifdef CONFIG_BOOTX_TEXT
2097 /* Update debug text engine */
2098 btext_update_display(rinfo->fb_base_phys, mode->xres, mode->yres,
2099 rinfo->depth, rinfo->pitch*64);
2106 static void radeon_write_mode (struct radeonfb_info *rinfo,
2107 struct radeon_regs *mode)
2110 int primary_mon = PRIMARY_MONITOR(rinfo);
2112 radeonfb_blank(VESA_POWERDOWN, (struct fb_info *)rinfo);
2115 if (rinfo->arch == RADEON_M6) {
2117 OUTREG(common_regs_m6[i].reg, common_regs_m6[i].val);
2120 OUTREG(common_regs[i].reg, common_regs[i].val);
2123 OUTREG(CRTC_GEN_CNTL, mode->crtc_gen_cntl);
2124 OUTREGP(CRTC_EXT_CNTL, mode->crtc_ext_cntl,
2125 CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS);
2126 OUTREGP(DAC_CNTL, mode->dac_cntl, DAC_RANGE_CNTL | DAC_BLANKING);
2127 OUTREG(CRTC_H_TOTAL_DISP, mode->crtc_h_total_disp);
2128 OUTREG(CRTC_H_SYNC_STRT_WID, mode->crtc_h_sync_strt_wid);
2129 OUTREG(CRTC_V_TOTAL_DISP, mode->crtc_v_total_disp);
2130 OUTREG(CRTC_V_SYNC_STRT_WID, mode->crtc_v_sync_strt_wid);
2131 OUTREG(CRTC_OFFSET, 0);
2132 OUTREG(CRTC_OFFSET_CNTL, 0);
2133 OUTREG(CRTC_PITCH, mode->crtc_pitch);
2135 #if defined(__BIG_ENDIAN)
2136 OUTREG(SURFACE_CNTL, mode->surface_cntl);
2139 while ((INREG(CLOCK_CNTL_INDEX) & PPLL_DIV_SEL_MASK) !=
2140 PPLL_DIV_SEL_MASK) {
2141 OUTREGP(CLOCK_CNTL_INDEX, PPLL_DIV_SEL_MASK, 0xffff);
2144 OUTPLLP(PPLL_CNTL, PPLL_RESET, 0xffff);
2146 while ((INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK) !=
2147 (mode->ppll_ref_div & PPLL_REF_DIV_MASK)) {
2148 OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, ~PPLL_REF_DIV_MASK);
2151 while ((INPLL(PPLL_DIV_3) & PPLL_FB3_DIV_MASK) !=
2152 (mode->ppll_div_3 & PPLL_FB3_DIV_MASK)) {
2153 OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_FB3_DIV_MASK);
2156 while ((INPLL(PPLL_DIV_3) & PPLL_POST3_DIV_MASK) !=
2157 (mode->ppll_div_3 & PPLL_POST3_DIV_MASK)) {
2158 OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_POST3_DIV_MASK);
2161 OUTPLL(HTOTAL_CNTL, 0);
2163 OUTPLLP(PPLL_CNTL, 0, ~PPLL_RESET);
2165 // OUTREG(DDA_CONFIG, mode->dda_config);
2166 // OUTREG(DDA_ON_OFF, mode->dda_on_off);
2168 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
2169 OUTREG(FP_CRTC_H_TOTAL_DISP, mode->fp_crtc_h_total_disp);
2170 OUTREG(FP_CRTC_V_TOTAL_DISP, mode->fp_crtc_v_total_disp);
2171 OUTREG(FP_H_SYNC_STRT_WID, mode->fp_h_sync_strt_wid);
2172 OUTREG(FP_V_SYNC_STRT_WID, mode->fp_v_sync_strt_wid);
2173 OUTREG(FP_HORZ_STRETCH, mode->fp_horz_stretch);
2174 OUTREG(FP_VERT_STRETCH, mode->fp_vert_stretch);
2175 OUTREG(FP_GEN_CNTL, mode->fp_gen_cntl);
2176 OUTREG(TMDS_CRC, mode->tmds_crc);
2177 OUTREG(TMDS_TRANSMITTER_CNTL, mode->tmds_transmitter_cntl);
2179 if (primary_mon == MT_LCD) {
2180 unsigned int tmp = INREG(LVDS_GEN_CNTL);
2182 mode->lvds_gen_cntl &= ~LVDS_STATE_MASK;
2183 mode->lvds_gen_cntl |= (rinfo->init_state.lvds_gen_cntl & LVDS_STATE_MASK);
2185 if ((tmp & (LVDS_ON | LVDS_BLON)) ==
2186 (mode->lvds_gen_cntl & (LVDS_ON | LVDS_BLON))) {
2187 OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl);
2189 if (mode->lvds_gen_cntl & (LVDS_ON | LVDS_BLON)) {
2191 OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl);
2193 OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl |
2196 OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl);
2202 radeonfb_blank(VESA_NO_BLANKING, (struct fb_info *)rinfo);
2204 OUTPLL(VCLK_ECP_CNTL, mode->vclk_ecp_cntl);
2209 static struct fb_ops radeonfb_ops = {
2210 .owner = THIS_MODULE,
2211 .fb_check_var = radeonfb_check_var,
2212 .fb_set_par = radeonfb_set_par,
2213 .fb_setcolreg = radeonfb_setcolreg,
2214 .fb_pan_display = radeonfb_pan_display,
2215 .fb_blank = radeonfb_blank,
2216 .fb_ioctl = radeonfb_ioctl,
2218 .fb_fillrect = radeonfb_fillrect,
2219 .fb_copyarea = radeonfb_copyarea,
2220 .fb_imageblit = radeonfb_imageblit,
2221 .fb_rasterimg = radeonfb_rasterimg,
2223 .fb_fillrect = cfb_fillrect,
2224 .fb_copyarea = cfb_copyarea,
2225 .fb_imageblit = cfb_imageblit,
2227 .fb_cursor = soft_cursor,
2231 static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo)
2233 struct fb_info *info;
2235 info = &rinfo->info;
2239 info->pseudo_palette = rinfo->pseudo_palette;
2241 info->flags = FBINFO_FLAG_DEFAULT;
2242 info->fbops = &radeonfb_ops;
2243 info->display_fg = NULL;
2244 info->screen_base = (char *)rinfo->fb_base;
2246 /* Fill fix common fields */
2247 strncpy(info->fix.id, rinfo->name, sizeof(info->fix.id));
2248 info->fix.id[sizeof(info->fix.id) - 1] = '\0';
2249 info->fix.smem_start = rinfo->fb_base_phys;
2250 info->fix.smem_len = rinfo->video_ram;
2251 info->fix.type = FB_TYPE_PACKED_PIXELS;
2252 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
2253 info->fix.xpanstep = 8;
2254 info->fix.ypanstep = 1;
2255 info->fix.ywrapstep = 0;
2256 info->fix.type_aux = 0;
2257 info->fix.mmio_start = rinfo->mmio_base_phys;
2258 info->fix.mmio_len = RADEON_REGSIZE;
2260 info->fix.accel = FB_ACCEL_NONE;
2262 info->fix.accel = FB_ACCEL_ATI_RADEON;
2264 if (radeon_init_disp (rinfo) < 0)
2271 #ifdef CONFIG_PMAC_BACKLIGHT
2273 /* TODO: Dbl check these tables, we don't go up to full ON backlight
2274 * in these, possibly because we noticed MacOS doesn't, but I'd prefer
2275 * having some more official numbers from ATI
2277 static int backlight_conv_m6[] = {
2278 0xff, 0xc0, 0xb5, 0xaa, 0x9f, 0x94, 0x89, 0x7e,
2279 0x73, 0x68, 0x5d, 0x52, 0x47, 0x3c, 0x31, 0x24
2281 static int backlight_conv_m7[] = {
2282 0x00, 0x3f, 0x4a, 0x55, 0x60, 0x6b, 0x76, 0x81,
2283 0x8c, 0x97, 0xa2, 0xad, 0xb8, 0xc3, 0xce, 0xd9
2286 #define BACKLIGHT_LVDS_OFF
2287 #undef BACKLIGHT_DAC_OFF
2289 /* We turn off the LCD completely instead of just dimming the backlight.
2290 * This provides some greater power saving and the display is useless
2291 * without backlight anyway.
2294 static int radeon_set_backlight_enable(int on, int level, void *data)
2296 struct radeonfb_info *rinfo = (struct radeonfb_info *)data;
2297 unsigned int lvds_gen_cntl = INREG(LVDS_GEN_CNTL);
2300 /* Pardon me for that hack... maybe some day we can figure
2301 * out in what direction backlight should work on a given
2304 if ((rinfo->arch == RADEON_M7 || rinfo->arch == RADEON_M9)
2305 && !machine_is_compatible("PowerBook4,3"))
2306 conv_table = backlight_conv_m7;
2308 conv_table = backlight_conv_m6;
2310 lvds_gen_cntl |= (LVDS_BL_MOD_EN | LVDS_BLON);
2311 if (on && (level > BACKLIGHT_OFF)) {
2312 lvds_gen_cntl |= LVDS_DIGON;
2313 if (!lvds_gen_cntl & LVDS_ON) {
2314 lvds_gen_cntl &= ~LVDS_BLON;
2315 OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
2316 (void)INREG(LVDS_GEN_CNTL);
2318 lvds_gen_cntl |= LVDS_BLON;
2319 OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
2321 lvds_gen_cntl &= ~LVDS_BL_MOD_LEVEL_MASK;
2322 lvds_gen_cntl |= (conv_table[level] <<
2323 LVDS_BL_MOD_LEVEL_SHIFT);
2324 lvds_gen_cntl |= (LVDS_ON | LVDS_EN);
2325 lvds_gen_cntl &= ~LVDS_DISPLAY_DIS;
2327 lvds_gen_cntl &= ~LVDS_BL_MOD_LEVEL_MASK;
2328 lvds_gen_cntl |= (conv_table[0] <<
2329 LVDS_BL_MOD_LEVEL_SHIFT);
2330 lvds_gen_cntl |= LVDS_DISPLAY_DIS;
2331 OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
2333 lvds_gen_cntl &= ~(LVDS_ON | LVDS_EN | LVDS_BLON | LVDS_DIGON);
2336 OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
2337 rinfo->init_state.lvds_gen_cntl &= ~LVDS_STATE_MASK;
2338 rinfo->init_state.lvds_gen_cntl |= (lvds_gen_cntl & LVDS_STATE_MASK);
2343 static int radeon_set_backlight_level(int level, void *data)
2345 return radeon_set_backlight_enable(1, level, data);
2347 #endif /* CONFIG_PMAC_BACKLIGHT */
2350 #ifdef CONFIG_PMAC_PBOOK
2355 * Radeon M6 Power Management code. This code currently only supports
2356 * the mobile chips, it's based from some informations provided by ATI
2357 * along with hours of tracing of MacOS drivers
2360 static void radeon_pm_save_regs(struct radeonfb_info *rinfo)
2362 rinfo->save_regs[0] = INPLL(PLL_PWRMGT_CNTL);
2363 rinfo->save_regs[1] = INPLL(CLK_PWRMGT_CNTL);
2364 rinfo->save_regs[2] = INPLL(MCLK_CNTL);
2365 rinfo->save_regs[3] = INPLL(SCLK_CNTL);
2366 rinfo->save_regs[4] = INPLL(CLK_PIN_CNTL);
2367 rinfo->save_regs[5] = INPLL(VCLK_ECP_CNTL);
2368 rinfo->save_regs[6] = INPLL(PIXCLKS_CNTL);
2369 rinfo->save_regs[7] = INPLL(MCLK_MISC);
2370 rinfo->save_regs[8] = INPLL(P2PLL_CNTL);
2372 rinfo->save_regs[9] = INREG(DISP_MISC_CNTL);
2373 rinfo->save_regs[10] = INREG(DISP_PWR_MAN);
2374 rinfo->save_regs[11] = INREG(LVDS_GEN_CNTL);
2375 rinfo->save_regs[12] = INREG(LVDS_PLL_CNTL);
2376 rinfo->save_regs[13] = INREG(TV_DAC_CNTL);
2377 rinfo->save_regs[14] = INREG(BUS_CNTL1);
2378 rinfo->save_regs[15] = INREG(CRTC_OFFSET_CNTL);
2379 rinfo->save_regs[16] = INREG(AGP_CNTL);
2380 rinfo->save_regs[17] = (INREG(CRTC_GEN_CNTL) & 0xfdffffff) | 0x04000000;
2381 rinfo->save_regs[18] = (INREG(CRTC2_GEN_CNTL) & 0xfdffffff) | 0x04000000;
2382 rinfo->save_regs[19] = INREG(GPIOPAD_A);
2383 rinfo->save_regs[20] = INREG(GPIOPAD_EN);
2384 rinfo->save_regs[21] = INREG(GPIOPAD_MASK);
2385 rinfo->save_regs[22] = INREG(ZV_LCDPAD_A);
2386 rinfo->save_regs[23] = INREG(ZV_LCDPAD_EN);
2387 rinfo->save_regs[24] = INREG(ZV_LCDPAD_MASK);
2388 rinfo->save_regs[25] = INREG(GPIO_VGA_DDC);
2389 rinfo->save_regs[26] = INREG(GPIO_DVI_DDC);
2390 rinfo->save_regs[27] = INREG(GPIO_MONID);
2391 rinfo->save_regs[28] = INREG(GPIO_CRT2_DDC);
2393 rinfo->save_regs[29] = INREG(SURFACE_CNTL);
2394 rinfo->save_regs[30] = INREG(MC_FB_LOCATION);
2395 rinfo->save_regs[31] = INREG(DISPLAY_BASE_ADDR);
2396 rinfo->save_regs[32] = INREG(MC_AGP_LOCATION);
2397 rinfo->save_regs[33] = INREG(CRTC2_DISPLAY_BASE_ADDR);
2400 static void radeon_pm_restore_regs(struct radeonfb_info *rinfo)
2402 OUTPLL(P2PLL_CNTL, rinfo->save_regs[8] & 0xFFFFFFFE); /* First */
2404 OUTPLL(PLL_PWRMGT_CNTL, rinfo->save_regs[0]);
2405 OUTPLL(CLK_PWRMGT_CNTL, rinfo->save_regs[1]);
2406 OUTPLL(MCLK_CNTL, rinfo->save_regs[2]);
2407 OUTPLL(SCLK_CNTL, rinfo->save_regs[3]);
2408 OUTPLL(CLK_PIN_CNTL, rinfo->save_regs[4]);
2409 OUTPLL(VCLK_ECP_CNTL, rinfo->save_regs[5]);
2410 OUTPLL(PIXCLKS_CNTL, rinfo->save_regs[6]);
2411 OUTPLL(MCLK_MISC, rinfo->save_regs[7]);
2413 OUTREG(DISP_MISC_CNTL, rinfo->save_regs[9]);
2414 OUTREG(DISP_PWR_MAN, rinfo->save_regs[10]);
2415 OUTREG(LVDS_GEN_CNTL, rinfo->save_regs[11]);
2416 OUTREG(LVDS_PLL_CNTL,rinfo->save_regs[12]);
2417 OUTREG(TV_DAC_CNTL, rinfo->save_regs[13]);
2418 OUTREG(BUS_CNTL1, rinfo->save_regs[14]);
2419 OUTREG(CRTC_OFFSET_CNTL, rinfo->save_regs[15]);
2420 OUTREG(AGP_CNTL, rinfo->save_regs[16]);
2421 OUTREG(CRTC_GEN_CNTL, rinfo->save_regs[17]);
2422 OUTREG(CRTC2_GEN_CNTL, rinfo->save_regs[18]);
2424 // wait VBL before that one ?
2425 OUTPLL(P2PLL_CNTL, rinfo->save_regs[8]);
2427 OUTREG(GPIOPAD_A, rinfo->save_regs[19]);
2428 OUTREG(GPIOPAD_EN, rinfo->save_regs[20]);
2429 OUTREG(GPIOPAD_MASK, rinfo->save_regs[21]);
2430 OUTREG(ZV_LCDPAD_A, rinfo->save_regs[22]);
2431 OUTREG(ZV_LCDPAD_EN, rinfo->save_regs[23]);
2432 OUTREG(ZV_LCDPAD_MASK, rinfo->save_regs[24]);
2433 OUTREG(GPIO_VGA_DDC, rinfo->save_regs[25]);
2434 OUTREG(GPIO_DVI_DDC, rinfo->save_regs[26]);
2435 OUTREG(GPIO_MONID, rinfo->save_regs[27]);
2436 OUTREG(GPIO_CRT2_DDC, rinfo->save_regs[28]);
2439 static void radeon_pm_disable_iopad(struct radeonfb_info *rinfo)
2441 OUTREG(GPIOPAD_MASK, 0x0001ffff);
2442 OUTREG(GPIOPAD_EN, 0x00000400);
2443 OUTREG(GPIOPAD_A, 0x00000000);
2444 OUTREG(ZV_LCDPAD_MASK, 0x00000000);
2445 OUTREG(ZV_LCDPAD_EN, 0x00000000);
2446 OUTREG(ZV_LCDPAD_A, 0x00000000);
2447 OUTREG(GPIO_VGA_DDC, 0x00030000);
2448 OUTREG(GPIO_DVI_DDC, 0x00000000);
2449 OUTREG(GPIO_MONID, 0x00030000);
2450 OUTREG(GPIO_CRT2_DDC, 0x00000000);
2453 static void radeon_pm_program_v2clk(struct radeonfb_info *rinfo)
2458 // OUTPLL(P2PLL_REF_DIV, 0x0c);
2460 // .../... figure out what macos does here
2463 static void radeon_pm_low_current(struct radeonfb_info *rinfo)
2467 reg = INREG(BUS_CNTL1);
2468 reg &= ~BUS_CNTL1_MOBILE_PLATFORM_SEL_MASK;
2469 reg |= BUS_CNTL1_AGPCLK_VALID | (1<<BUS_CNTL1_MOBILE_PLATFORM_SEL_SHIFT);
2470 OUTREG(BUS_CNTL1, reg);
2472 reg = INPLL(PLL_PWRMGT_CNTL);
2473 reg |= PLL_PWRMGT_CNTL_SPLL_TURNOFF | PLL_PWRMGT_CNTL_PPLL_TURNOFF |
2474 PLL_PWRMGT_CNTL_P2PLL_TURNOFF | PLL_PWRMGT_CNTL_TVPLL_TURNOFF;
2475 reg &= ~PLL_PWRMGT_CNTL_SU_MCLK_USE_BCLK;
2476 reg &= ~PLL_PWRMGT_CNTL_MOBILE_SU;
2477 OUTPLL(PLL_PWRMGT_CNTL, reg);
2479 // reg = INPLL(TV_PLL_CNTL1);
2480 // reg |= TV_PLL_CNTL1__TVPLL_RESET | TV_PLL_CNTL1__TVPLL_SLEEP;
2481 // OUTPLL(TV_PLL_CNTL1, reg);
2483 reg = INREG(TV_DAC_CNTL);
2484 reg &= ~(TV_DAC_CNTL_BGADJ_MASK |TV_DAC_CNTL_DACADJ_MASK);
2485 reg |=TV_DAC_CNTL_BGSLEEP | TV_DAC_CNTL_RDACPD | TV_DAC_CNTL_GDACPD |
2486 TV_DAC_CNTL_BDACPD |
2487 (8<<TV_DAC_CNTL_BGADJ__SHIFT) | (8<<TV_DAC_CNTL_DACADJ__SHIFT);
2488 OUTREG(TV_DAC_CNTL, reg);
2490 reg = INREG(TMDS_TRANSMITTER_CNTL);
2491 reg &= ~(TMDS_PLL_EN |TMDS_PLLRST);
2492 OUTREG(TMDS_TRANSMITTER_CNTL, reg);
2494 // lvds_pll_cntl = regr32(g, LVDS_PLL_CNTL);
2495 // lvds_pll_cntl &= ~LVDS_PLL_CNTL__LVDS_PLL_EN;
2496 // lvds_pll_cntl |= LVDS_PLL_CNTL__LVDS_PLL_RESET;
2497 // regw32(g, LVDS_PLL_CNTL, lvds_pll_cntl);
2499 reg = INREG(DAC_CNTL);
2501 OUTREG(DAC_CNTL, reg);
2503 reg = INREG(DAC_CNTL2);
2504 reg &= ~DAC2_CMP_EN;
2505 OUTREG(DAC_CNTL2, reg);
2507 reg = INREG(TV_DAC_CNTL);
2508 reg &= ~TV_DAC_CNTL_DETECT;
2509 OUTREG(TV_DAC_CNTL, reg);
2512 static void radeon_pm_setup_for_suspend(struct radeonfb_info *rinfo)
2514 /* This code is disabled. It does what is in the pm_init
2515 * function of the MacOS driver code ATI sent me. However,
2516 * it doesn't fix my sleep problem, and is causing other issues
2517 * on wakeup (bascially the machine dying when switching consoles
2518 * I haven't had time to investigate this yet
2525 // set SPLL, MPLL, PPLL, P2PLL, TVPLL, SCLK, MCLK, PCLK, P2CLK,
2526 // TCLK and TEST_MODE to 0
2527 temp = INPLL(CLK_PWRMGT_CNTL);
2528 OUTPLL(CLK_PWRMGT_CNTL , temp & ~0xc00002ff);
2530 // Turn on Power Management
2531 temp = INPLL(CLK_PWRMGT_CNTL);
2532 OUTPLL(CLK_PWRMGT_CNTL , temp | 0x00000400);
2534 // Turn off display clock if using mobile chips
2535 temp = INPLL(CLK_PWRMGT_CNTL);
2536 OUTREG(CLK_PWRMGT_CNTL , temp | 0x00100000);
2538 // Force PIXCLK_ALWAYS_ON and PIXCLK_DAC_ALWAYS_ON
2539 temp = INPLL(VCLK_ECP_CNTL);
2540 OUTPLL(VCLK_ECP_CNTL, temp & ~0x000000c0);
2542 // Force ECP_FORCE_ON to 1
2543 temp = INPLL(VCLK_ECP_CNTL);
2544 OUTPLL(VCLK_ECP_CNTL, temp | 0x00040000);
2546 // Force PIXCLK_BLEND_ALWAYS_ON and PIXCLK_GV_ALWAYS_ON
2547 temp = INPLL(PIXCLKS_CNTL);
2548 OUTPLL(PIXCLKS_CNTL, temp & ~0x00001800);
2550 // Forcing SCLK_CNTL to ON
2551 OUTPLL(SCLK_CNTL, (INPLL(SCLK_CNTL)& 0x00000007) | 0xffff8000 );
2553 // Set PM control over XTALIN pad
2554 temp = INPLL(CLK_PIN_CNTL);
2555 OUTPLL(CLK_PIN_CNTL, temp | 0x00080000);
2557 // Force MCLK and YCLK and MC as dynamic
2558 temp = INPLL(MCLK_CNTL);
2559 OUTPLL(MCLK_CNTL, temp & 0xffeaffff);
2562 temp = INPLL(PLL_PWRMGT_CNTL);
2563 OUTPLL(PLL_PWRMGT_CNTL, temp | 0x0000001f);
2565 // set MOBILE_SU to 1 if M6 or DDR64 is detected
2566 temp = INPLL(PLL_PWRMGT_CNTL);
2567 OUTPLL(PLL_PWRMGT_CNTL, temp | 0x00010000);
2569 // select PM access mode (PM_MODE_SEL) (use ACPI mode)
2570 // temp = INPLL(PLL_PWRMGT_CNTL);
2571 // OUTPLL(PLL_PWRMGT_CNTL, temp | 0x00002000);
2572 temp = INPLL(PLL_PWRMGT_CNTL);
2573 OUTPLL(PLL_PWRMGT_CNTL, temp & ~0x00002000);
2575 // set DISP_MISC_CNTL register
2576 disp_misc_cntl = INREG(DISP_MISC_CNTL);
2577 disp_misc_cntl &= ~( DISP_MISC_CNTL_SOFT_RESET_GRPH_PP |
2578 DISP_MISC_CNTL_SOFT_RESET_SUBPIC_PP |
2579 DISP_MISC_CNTL_SOFT_RESET_OV0_PP |
2580 DISP_MISC_CNTL_SOFT_RESET_GRPH_SCLK |
2581 DISP_MISC_CNTL_SOFT_RESET_SUBPIC_SCLK |
2582 DISP_MISC_CNTL_SOFT_RESET_OV0_SCLK |
2583 DISP_MISC_CNTL_SOFT_RESET_GRPH2_PP |
2584 DISP_MISC_CNTL_SOFT_RESET_GRPH2_SCLK |
2585 DISP_MISC_CNTL_SOFT_RESET_LVDS |
2586 DISP_MISC_CNTL_SOFT_RESET_TMDS |
2587 DISP_MISC_CNTL_SOFT_RESET_DIG_TMDS |
2588 DISP_MISC_CNTL_SOFT_RESET_TV);
2589 OUTREG(DISP_MISC_CNTL, disp_misc_cntl);
2591 // set DISP_PWR_MAN register
2592 disp_pwr_man = INREG(DISP_PWR_MAN);
2593 // clau - 9.29.2000 - changes made to bit23:18 to set to 1 as requested by George
2594 disp_pwr_man |= (DISP_PWR_MAN_DIG_TMDS_ENABLE_RST |
2595 DISP_PWR_MAN_TV_ENABLE_RST |
2596 // DISP_PWR_MAN_AUTO_PWRUP_EN |
2597 DISP_PWR_MAN_DISP_D3_GRPH_RST |
2598 DISP_PWR_MAN_DISP_D3_SUBPIC_RST |
2599 DISP_PWR_MAN_DISP_D3_OV0_RST |
2600 DISP_PWR_MAN_DISP_D1D2_GRPH_RST |
2601 DISP_PWR_MAN_DISP_D1D2_SUBPIC_RST |
2602 DISP_PWR_MAN_DISP_D1D2_OV0_RST);
2603 disp_pwr_man &= ~(DISP_PWR_MAN_DISP_PWR_MAN_D3_CRTC_EN |
2604 DISP_PWR_MAN_DISP2_PWR_MAN_D3_CRTC2_EN|
2605 DISP_PWR_MAN_DISP_D3_RST |
2606 DISP_PWR_MAN_DISP_D3_REG_RST);
2607 OUTREG(DISP_PWR_MAN, disp_pwr_man);
2609 // clau - 10.24.2000
2610 // - add in setting for BUS_CNTL1 b27:26 = 0x01 and b31 = 0x1
2611 // - add in setting for AGP_CNTL b7:0 = 0x20
2612 // - add in setting for DVI_DDC_DATA_OUT_EN b17:16 = 0x0
2614 // the following settings (two lines) are applied at a later part of this function, only on mobile platform
2615 // requres -mobile flag
2616 OUTREG(BUS_CNTL1, (INREG(BUS_CNTL1) & 0xf3ffffff) | 0x04000000);
2617 OUTREG(BUS_CNTL1, INREG(BUS_CNTL1) | 0x80000000);
2618 OUTREG(AGP_CNTL, (INREG(AGP_CNTL) & 0xffffff00) | 0x20);
2619 OUTREG(GPIO_DVI_DDC, INREG(GPIO_DVI_DDC) & 0xfffcffff);
2621 // yulee - 12.12.2000
2623 // EN_MCLK_TRISTATE_IN_SUSPEND@MCLK_MISC = 1
2624 // ACCESS_REGS_IN_SUSPEND@CLK_PIN_CNTL = 0
2625 // only on mobile platform
2626 OUTPLL(MCLK_MISC, INPLL(MCLK_MISC) | 0x00040000 );
2628 // yulee -12.12.2000
2629 // AGPCLK_VALID@BUS_CNTL1 = 1
2630 // MOBILE_PLATFORM_SEL@BUS_CNTL1 = 01
2631 // CRTC_STEREO_SYNC_OUT_EN@CRTC_OFFSET_CNTL = 0
2632 // CG_CLK_TO_OUTPIN@CLK_PIN_CNTL = 0
2633 // only on mobile platform
2634 OUTPLL(CLK_PIN_CNTL, INPLL(CLK_PIN_CNTL ) & 0xFFFFF7FF );
2635 OUTREG(BUS_CNTL1, (INREG(BUS_CNTL1 ) & 0xF3FFFFFF) | 0x84000000 );
2636 OUTREG(CRTC_OFFSET_CNTL, INREG(CRTC_OFFSET_CNTL ) & 0xFFEFFFFF );
2642 OUTREG(CRTC_GEN_CNTL, (INREG(CRTC_GEN_CNTL) & ~CRTC_EN) | CRTC_DISP_REQ_EN_B);
2643 OUTREG(CRTC2_GEN_CNTL, (INREG(CRTC2_GEN_CNTL) & ~CRTC2_EN) | CRTC2_DISP_REQ_EN_B);
2644 (void)INREG(CRTC2_GEN_CNTL);
2648 static void radeon_set_suspend(struct radeonfb_info *rinfo, int suspend)
2655 /* Set the chip into appropriate suspend mode (we use D2,
2656 * D3 would require a compete re-initialization of the chip,
2657 * including PCI config registers, clocks, AGP conf, ...)
2660 /* According to ATI, we should program V2CLK here, I have
2661 * to verify what's up exactly
2663 /* Save some registers */
2664 radeon_pm_save_regs(rinfo);
2666 /* Check that on M7 too, might work might not. M7 may also
2667 * need explicit enabling of PM
2669 if (rinfo->arch == RADEON_M6) {
2671 radeon_pm_program_v2clk(rinfo);
2673 /* Disable IO PADs */
2674 radeon_pm_disable_iopad(rinfo);
2676 /* Set low current */
2677 radeon_pm_low_current(rinfo);
2679 /* Prepare chip for power management */
2680 radeon_pm_setup_for_suspend(rinfo);
2682 /* Reset the MDLL */
2683 OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) | MCKOA_RESET);
2684 (void)INPLL(MDLL_RDCKA);
2685 OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) & ~MCKOA_RESET);
2686 (void)INPLL(MDLL_RDCKA);
2689 /* Switch PCI power managment to D2. */
2691 pci_read_config_word(
2692 rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL,
2696 pci_write_config_word(
2697 rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL,
2698 (pwr_cmd & ~PCI_PM_CTRL_STATE_MASK) | 2);
2702 /* Switch back PCI powermanagment to D0 */
2704 pci_write_config_word(rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL, 0);
2709 /* Do we need that on M7 ? */
2710 if (rinfo->arch == RADEON_M6) {
2711 /* Restore the MDLL */
2712 OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) & ~MCKOA_RESET);
2713 (void)INPLL(MDLL_CKO);
2716 /* Restore some registers */
2717 radeon_pm_restore_regs(rinfo);
2722 * Save the contents of the framebuffer when we go to sleep,
2723 * and restore it when we wake up again.
2726 int radeon_sleep_notify(struct pmu_sleep_notifier *self, int when)
2728 struct radeonfb_info *rinfo;
2730 for (rinfo = board_list; rinfo != NULL; rinfo = rinfo->next) {
2731 struct fb_fix_screeninfo fix;
2733 struct display *disp;
2735 disp = (rinfo->currcon < 0) ? rinfo->info.disp : &fb_display[rinfo->currcon];
2737 switch (rinfo->arch) {
2743 return PBOOK_SLEEP_REFUSE;
2746 radeonfb_get_fix(&fix, fg_console, (struct fb_info *)rinfo);
2747 nb = fb_display[fg_console].var.yres * fix.line_length;
2750 case PBOOK_SLEEP_NOW:
2751 acquire_console_sem();
2752 disp->dispsw = &fbcon_dummy;
2755 /* Make sure engine is reset */
2756 radeon_engine_reset();
2757 radeon_engine_idle();
2760 /* Blank display and LCD */
2761 radeonfb_blank(VESA_POWERDOWN+1,
2762 (struct fb_info *)rinfo);
2766 radeon_set_suspend(rinfo, 1);
2767 release_console_sem();
2771 acquire_console_sem();
2773 radeon_set_suspend(rinfo, 0);
2776 radeon_engine_init(rinfo);
2778 radeon_set_dispsw(rinfo, disp);
2779 radeon_load_video_mode(rinfo, &disp->var);
2780 do_install_cmap(rinfo->currcon < 0 ? 0 : rinfo->currcon,
2781 (struct fb_info *)rinfo);
2783 radeonfb_blank(0, (struct fb_info *)rinfo);
2784 release_console_sem();
2785 printk("CLK_PIN_CNTL on wakeup was: %08x\n", dbg_clk);
2790 return PBOOK_SLEEP_OK;
2793 #endif /* CONFIG_PMAC_PBOOK */
2795 static int radeonfb_pci_register (struct pci_dev *pdev,
2796 const struct pci_device_id *ent)
2798 struct radeonfb_info *rinfo;
2799 struct radeon_chip_info *rci = &radeon_chip_info[ent->driver_data];
2802 RTRACE("radeonfb_pci_register BEGIN\n");
2804 /* Enable device in PCI config */
2805 if (pci_enable_device(pdev) != 0) {
2806 printk(KERN_ERR "radeonfb: Cannot enable PCI device\n");
2810 rinfo = kmalloc (sizeof (struct radeonfb_info), GFP_KERNEL);
2812 printk ("radeonfb: could not allocate memory\n");
2816 memset (rinfo, 0, sizeof (struct radeonfb_info));
2817 //info = &rinfo->info;
2819 strcpy(rinfo->name, rci->name);
2820 rinfo->arch = rci->arch;
2822 /* Set base addrs */
2823 rinfo->fb_base_phys = pci_resource_start (pdev, 0);
2824 rinfo->mmio_base_phys = pci_resource_start (pdev, 2);
2826 /* request the mem regions */
2827 if (!request_mem_region (rinfo->fb_base_phys,
2828 pci_resource_len(pdev, 0), "radeonfb")) {
2829 printk ("radeonfb: cannot reserve FB region\n");
2834 if (!request_mem_region (rinfo->mmio_base_phys,
2835 pci_resource_len(pdev, 2), "radeonfb")) {
2836 printk ("radeonfb: cannot reserve MMIO region\n");
2837 release_mem_region (rinfo->fb_base_phys,
2838 pci_resource_len(pdev, 0));
2843 /* map the regions */
2844 rinfo->mmio_base = (u32) ioremap (rinfo->mmio_base_phys,
2846 if (!rinfo->mmio_base) {
2847 printk ("radeonfb: cannot map MMIO\n");
2848 release_mem_region (rinfo->mmio_base_phys,
2849 pci_resource_len(pdev, 2));
2850 release_mem_region (rinfo->fb_base_phys,
2851 pci_resource_len(pdev, 0));
2856 rinfo->chipset = pdev->device;
2858 switch (rinfo->arch) {
2860 rinfo->hasCRTC2 = 0;
2863 /* all the rest have it */
2864 rinfo->hasCRTC2 = 1;
2868 if (rinfo->arch == RADEON_M7) {
2870 * Noticed some errors in accel with M7, will have to work these out...
2876 printk("radeonfb: mirroring display to CRT\n");
2878 /* framebuffer size */
2879 tmp = INREG(CONFIG_MEMSIZE);
2881 /* mem size is bits [28:0], mask off the rest */
2882 rinfo->video_ram = tmp & CONFIG_MEMSIZE_MASK;
2885 tmp = INREG(MEM_SDRAM_MODE_REG);
2886 switch ((MEM_CFG_TYPE & tmp) >> 30) {
2888 /* SDR SGRAM (2:1) */
2889 strcpy(rinfo->ram_type, "SDR SGRAM");
2892 rinfo->ram.trcd = 1;
2896 rinfo->ram.loop_latency = 16;
2897 rinfo->ram.rloop = 16;
2902 strcpy(rinfo->ram_type, "DDR SGRAM");
2905 rinfo->ram.trcd = 3;
2909 rinfo->ram.tr2w = 1;
2910 rinfo->ram.loop_latency = 16;
2911 rinfo->ram.rloop = 16;
2915 /* 64-bit SDR SGRAM */
2916 strcpy(rinfo->ram_type, "SDR SGRAM 64");
2919 rinfo->ram.trcd = 3;
2923 rinfo->ram.tr2w = 1;
2924 rinfo->ram.loop_latency = 17;
2925 rinfo->ram.rloop = 17;
2930 rinfo->bios_seg = radeon_find_rom(rinfo);
2931 radeon_get_pllinfo(rinfo, rinfo->bios_seg);
2934 * Hack to get around some busted production M6's
2937 if (rinfo->video_ram == 0) {
2938 switch (pdev->device) {
2939 case PCI_DEVICE_ID_ATI_RADEON_LY:
2940 case PCI_DEVICE_ID_ATI_RADEON_LZ:
2941 rinfo->video_ram = 8192 * 1024;
2949 RTRACE("radeonfb: probed %s %dk videoram\n", (rinfo->ram_type), (rinfo->video_ram/1024));
2951 #if !defined(__powerpc__)
2952 radeon_get_moninfo(rinfo);
2954 switch (pdev->device) {
2955 case PCI_DEVICE_ID_ATI_RADEON_LW:
2956 case PCI_DEVICE_ID_ATI_RADEON_LX:
2957 case PCI_DEVICE_ID_ATI_RADEON_LY:
2958 case PCI_DEVICE_ID_ATI_RADEON_LZ:
2959 rinfo->dviDisp_type = MT_LCD;
2962 radeon_get_moninfo(rinfo);
2967 radeon_get_EDID(rinfo);
2969 if ((rinfo->dviDisp_type == MT_DFP) || (rinfo->dviDisp_type == MT_LCD) ||
2970 (rinfo->crtDisp_type == MT_DFP)) {
2971 if (!radeon_get_dfpinfo(rinfo)) {
2972 iounmap ((void*)rinfo->mmio_base);
2973 release_mem_region (rinfo->mmio_base_phys,
2974 pci_resource_len(pdev, 2));
2975 release_mem_region (rinfo->fb_base_phys,
2976 pci_resource_len(pdev, 0));
2982 rinfo->fb_base = (u32) ioremap (rinfo->fb_base_phys,
2984 if (!rinfo->fb_base) {
2985 printk ("radeonfb: cannot map FB\n");
2986 iounmap ((void*)rinfo->mmio_base);
2987 release_mem_region (rinfo->mmio_base_phys,
2988 pci_resource_len(pdev, 2));
2989 release_mem_region (rinfo->fb_base_phys,
2990 pci_resource_len(pdev, 0));
2995 /* I SHOULD FIX THAT CRAP ! I should probably mimmic XFree DRI
2996 * driver setup here.
2998 * On PPC, OF based cards setup the internal memory
2999 * mapping in strange ways. We change it so that the
3000 * framebuffer is mapped at 0 and given half of the card's
3001 * address space (2Gb). AGP is mapped high (0xe0000000) and
3002 * can use up to 512Mb. Once DRI is fully implemented, we
3003 * will have to setup the PCI remapper to remap the agp_special_page
3004 * memory page somewhere between those regions so that the card
3005 * use a normal PCI bus master cycle to access the ring read ptr.
3008 #ifdef CONFIG_ALL_PPC
3009 if (rinfo->hasCRTC2)
3010 OUTREG(CRTC2_GEN_CNTL,
3011 (INREG(CRTC2_GEN_CNTL) & ~CRTC2_EN) | CRTC2_DISP_REQ_EN_B);
3012 OUTREG(CRTC_EXT_CNTL, INREG(CRTC_EXT_CNTL) | CRTC_DISPLAY_DIS);
3013 OUTREG(MC_FB_LOCATION, 0x7fff0000);
3014 OUTREG(MC_AGP_LOCATION, 0xffffe000);
3015 OUTREG(DISPLAY_BASE_ADDR, 0x00000000);
3016 if (rinfo->hasCRTC2)
3017 OUTREG(CRTC2_DISPLAY_BASE_ADDR, 0x00000000);
3018 OUTREG(SRC_OFFSET, 0x00000000);
3019 OUTREG(DST_OFFSET, 0x00000000);
3021 OUTREG(CRTC_EXT_CNTL, INREG(CRTC_EXT_CNTL) & ~CRTC_DISPLAY_DIS);
3022 #endif /* CONFIG_ALL_PPC */
3024 /* save current mode regs before we switch into the new one
3025 * so we can restore this upon __exit
3027 radeon_save_state (rinfo, &rinfo->init_state);
3030 /* initialize the engine */
3031 radeon_engine_init (rinfo);
3034 /* set all the vital stuff */
3035 radeon_set_fbinfo (rinfo);
3037 pci_set_drvdata(pdev, rinfo);
3038 rinfo->next = board_list;
3041 if (register_framebuffer ((struct fb_info *) rinfo) < 0) {
3042 printk ("radeonfb: could not register framebuffer\n");
3043 iounmap ((void*)rinfo->fb_base);
3044 iounmap ((void*)rinfo->mmio_base);
3045 release_mem_region (rinfo->mmio_base_phys,
3046 pci_resource_len(pdev, 2));
3047 release_mem_region (rinfo->fb_base_phys,
3048 pci_resource_len(pdev, 0));
3054 rinfo->mtrr_hdl = nomtrr ? -1 : mtrr_add(rinfo->fb_base_phys,
3056 MTRR_TYPE_WRCOMB, 1);
3059 #ifdef CONFIG_PMAC_BACKLIGHT
3060 if (rinfo->dviDisp_type == MT_LCD)
3061 register_backlight_controller(&radeon_backlight_controller,
3065 #ifdef CONFIG_PMAC_PBOOK
3066 if (rinfo->dviDisp_type == MT_LCD) {
3067 rinfo->pm_reg = pci_find_capability(pdev, PCI_CAP_ID_PM);
3068 pmu_register_sleep_notifier(&radeon_sleep_notifier);
3072 printk ("radeonfb: ATI Radeon %s %s %d MB\n", rinfo->name, rinfo->ram_type,
3073 (rinfo->video_ram/(1024*1024)));
3075 if (rinfo->hasCRTC2) {
3076 printk("radeonfb: DVI port %s monitor connected\n",
3077 GET_MON_NAME(rinfo->dviDisp_type));
3078 printk("radeonfb: CRT port %s monitor connected\n",
3079 GET_MON_NAME(rinfo->crtDisp_type));
3081 printk("radeonfb: CRT port %s monitor connected\n",
3082 GET_MON_NAME(rinfo->crtDisp_type));
3085 RTRACE("radeonfb_pci_register END\n");
3092 static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
3094 struct radeonfb_info *rinfo = pci_get_drvdata(pdev);
3099 /* restore original state
3101 * Doesn't quite work yet, possibly because of the PPC hacking
3102 * I do on startup, disable for now. --BenH
3104 radeon_write_mode (rinfo, &rinfo->init_state);
3107 if (rinfo->mtrr_hdl >= 0)
3108 mtrr_del(rinfo->mtrr_hdl, 0, 0);
3111 unregister_framebuffer ((struct fb_info *) rinfo);
3113 iounmap ((void*)rinfo->mmio_base);
3114 iounmap ((void*)rinfo->fb_base);
3116 release_mem_region (rinfo->mmio_base_phys,
3117 pci_resource_len(pdev, 2));
3118 release_mem_region (rinfo->fb_base_phys,
3119 pci_resource_len(pdev, 0));
3125 static struct pci_driver radeonfb_driver = {
3127 .id_table = radeonfb_pci_table,
3128 .probe = radeonfb_pci_register,
3129 .remove = __devexit_p(radeonfb_pci_unregister),
3133 int __init radeonfb_init (void)
3135 return pci_module_init (&radeonfb_driver);
3139 void __exit radeonfb_exit (void)
3141 pci_unregister_driver (&radeonfb_driver);
3145 int __init radeonfb_setup (char *options)
3149 if (!options || !*options)
3152 while ((this_opt = strsep (&options, ",")) != NULL) {
3155 if (!strncmp(this_opt, "noaccel", 7)) {
3157 } else if (!strncmp(this_opt, "mirror", 6)) {
3159 } else if (!strncmp(this_opt, "dfp", 3)) {
3161 } else if (!strncmp(this_opt, "panel_yres:", 11)) {
3162 panel_yres = simple_strtoul((this_opt+11), NULL, 0);
3163 } else if (!strncmp(this_opt, "nomtrr", 6)) {
3166 mode_option = this_opt;
3173 module_init(radeonfb_init);
3174 module_exit(radeonfb_exit);
3178 MODULE_AUTHOR("Ani Joshi");
3179 MODULE_DESCRIPTION("framebuffer driver for ATI Radeon chipset");
3180 MODULE_LICENSE("GPL");