2 * drivers/video/aty/radeon_base.c
4 * framebuffer driver for ATI Radeon chipset video boards
6 * Copyright 2003 Ben. Herrenschmidt <benh@kernel.crashing.org>
7 * Copyright 2000 Ani Joshi <ajoshi@kernel.crashing.org>
9 * i2c bits from Luca Tettamanti <kronos@kronoz.cjb.net>
11 * Special thanks to ATI DevRel team for their hardware donations.
13 * ...Insert GPL boilerplate here...
15 * Significant portions of this driver apdated from XFree86 Radeon
16 * driver which has the following copyright notice:
18 * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
19 * VA Linux Systems Inc., Fremont, California.
21 * All Rights Reserved.
23 * Permission is hereby granted, free of charge, to any person obtaining
24 * a copy of this software and associated documentation files (the
25 * "Software"), to deal in the Software without restriction, including
26 * without limitation on the rights to use, copy, modify, merge,
27 * publish, distribute, sublicense, and/or sell copies of the Software,
28 * and to permit persons to whom the Software is furnished to do so,
29 * subject to the following conditions:
31 * The above copyright notice and this permission notice (including the
32 * next paragraph) shall be included in all copies or substantial
33 * portions of the Software.
35 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
38 * NON-INFRINGEMENT. IN NO EVENT SHALL ATI, VA LINUX SYSTEMS AND/OR
39 * THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
40 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
42 * DEALINGS IN THE SOFTWARE.
44 * XFree86 driver authors:
46 * Kevin E. Martin <martin@xfree86.org>
47 * Rickard E. Faith <faith@valinux.com>
48 * Alan Hourihane <alanh@fairlite.demon.co.uk>
53 #define RADEON_VERSION "0.2.0"
55 #include <linux/module.h>
56 #include <linux/moduleparam.h>
57 #include <linux/kernel.h>
58 #include <linux/errno.h>
59 #include <linux/string.h>
61 #include <linux/slab.h>
62 #include <linux/delay.h>
63 #include <linux/time.h>
65 #include <linux/ioport.h>
66 #include <linux/init.h>
67 #include <linux/pci.h>
68 #include <linux/vmalloc.h>
69 #include <linux/device.h>
72 #include <asm/uaccess.h>
76 #include <asm/pci-bridge.h>
77 #include "../macmodes.h"
79 #ifdef CONFIG_BOOTX_TEXT
80 #include <asm/btext.h>
83 #endif /* CONFIG_PPC_OF */
89 #include <video/radeon.h>
90 #include <linux/radeonfb.h>
92 #include "../edid.h" // MOVE THAT TO include/video
96 #define MAX_MAPPED_VRAM (2048*2048*4)
97 #define MIN_MAPPED_VRAM (1024*768*1)
99 #define CHIP_DEF(id, family, flags) \
100 { PCI_VENDOR_ID_ATI, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (flags) | (CHIP_FAMILY_##family) }
102 static struct pci_device_id radeonfb_pci_table
[] = {
103 /* Radeon Xpress 200m */
104 CHIP_DEF(PCI_CHIP_RS480_5955
, RS480
, CHIP_HAS_CRTC2
| CHIP_IS_IGP
| CHIP_IS_MOBILITY
),
106 CHIP_DEF(PCI_CHIP_RADEON_LY
, RV100
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
107 CHIP_DEF(PCI_CHIP_RADEON_LZ
, RV100
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
109 CHIP_DEF(PCI_CHIP_RV100_QY
, RV100
, CHIP_HAS_CRTC2
),
110 CHIP_DEF(PCI_CHIP_RV100_QZ
, RV100
, CHIP_HAS_CRTC2
),
111 CHIP_DEF(PCI_CHIP_RN50
, RV100
, CHIP_HAS_CRTC2
),
112 /* Radeon IGP320M (U1) */
113 CHIP_DEF(PCI_CHIP_RS100_4336
, RS100
, CHIP_HAS_CRTC2
| CHIP_IS_IGP
| CHIP_IS_MOBILITY
),
114 /* Radeon IGP320 (A3) */
115 CHIP_DEF(PCI_CHIP_RS100_4136
, RS100
, CHIP_HAS_CRTC2
| CHIP_IS_IGP
),
116 /* IGP330M/340M/350M (U2) */
117 CHIP_DEF(PCI_CHIP_RS200_4337
, RS200
, CHIP_HAS_CRTC2
| CHIP_IS_IGP
| CHIP_IS_MOBILITY
),
118 /* IGP330/340/350 (A4) */
119 CHIP_DEF(PCI_CHIP_RS200_4137
, RS200
, CHIP_HAS_CRTC2
| CHIP_IS_IGP
),
120 /* Mobility 7000 IGP */
121 CHIP_DEF(PCI_CHIP_RS250_4437
, RS200
, CHIP_HAS_CRTC2
| CHIP_IS_IGP
| CHIP_IS_MOBILITY
),
123 CHIP_DEF(PCI_CHIP_RS250_4237
, RS200
, CHIP_HAS_CRTC2
| CHIP_IS_IGP
),
125 CHIP_DEF(PCI_CHIP_R200_BB
, R200
, CHIP_HAS_CRTC2
),
126 CHIP_DEF(PCI_CHIP_R200_BC
, R200
, CHIP_HAS_CRTC2
),
128 CHIP_DEF(PCI_CHIP_R200_QH
, R200
, CHIP_HAS_CRTC2
),
130 CHIP_DEF(PCI_CHIP_R200_QL
, R200
, CHIP_HAS_CRTC2
),
132 CHIP_DEF(PCI_CHIP_R200_QM
, R200
, CHIP_HAS_CRTC2
),
134 CHIP_DEF(PCI_CHIP_RADEON_LW
, RV200
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
135 CHIP_DEF(PCI_CHIP_RADEON_LX
, RV200
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
137 CHIP_DEF(PCI_CHIP_RV200_QW
, RV200
, CHIP_HAS_CRTC2
),
138 CHIP_DEF(PCI_CHIP_RV200_QX
, RV200
, CHIP_HAS_CRTC2
),
140 CHIP_DEF(PCI_CHIP_RV250_Ld
, RV250
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
141 CHIP_DEF(PCI_CHIP_RV250_Le
, RV250
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
142 CHIP_DEF(PCI_CHIP_RV250_Lf
, RV250
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
143 CHIP_DEF(PCI_CHIP_RV250_Lg
, RV250
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
145 CHIP_DEF(PCI_CHIP_RV250_If
, RV250
, CHIP_HAS_CRTC2
),
146 CHIP_DEF(PCI_CHIP_RV250_Ig
, RV250
, CHIP_HAS_CRTC2
),
147 /* Mobility 9100 IGP (U3) */
148 CHIP_DEF(PCI_CHIP_RS300_5835
, RS300
, CHIP_HAS_CRTC2
| CHIP_IS_IGP
| CHIP_IS_MOBILITY
),
149 CHIP_DEF(PCI_CHIP_RS350_7835
, RS300
, CHIP_HAS_CRTC2
| CHIP_IS_IGP
| CHIP_IS_MOBILITY
),
151 CHIP_DEF(PCI_CHIP_RS300_5834
, RS300
, CHIP_HAS_CRTC2
| CHIP_IS_IGP
),
152 CHIP_DEF(PCI_CHIP_RS350_7834
, RS300
, CHIP_HAS_CRTC2
| CHIP_IS_IGP
),
153 /* Mobility 9200 (M9+) */
154 CHIP_DEF(PCI_CHIP_RV280_5C61
, RV280
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
155 CHIP_DEF(PCI_CHIP_RV280_5C63
, RV280
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
157 CHIP_DEF(PCI_CHIP_RV280_5960
, RV280
, CHIP_HAS_CRTC2
),
158 CHIP_DEF(PCI_CHIP_RV280_5961
, RV280
, CHIP_HAS_CRTC2
),
159 CHIP_DEF(PCI_CHIP_RV280_5962
, RV280
, CHIP_HAS_CRTC2
),
160 CHIP_DEF(PCI_CHIP_RV280_5964
, RV280
, CHIP_HAS_CRTC2
),
162 CHIP_DEF(PCI_CHIP_R300_AD
, R300
, CHIP_HAS_CRTC2
),
163 CHIP_DEF(PCI_CHIP_R300_AE
, R300
, CHIP_HAS_CRTC2
),
164 /* 9600TX / FireGL Z1 */
165 CHIP_DEF(PCI_CHIP_R300_AF
, R300
, CHIP_HAS_CRTC2
),
166 CHIP_DEF(PCI_CHIP_R300_AG
, R300
, CHIP_HAS_CRTC2
),
167 /* 9700/9500/Pro/FireGL X1 */
168 CHIP_DEF(PCI_CHIP_R300_ND
, R300
, CHIP_HAS_CRTC2
),
169 CHIP_DEF(PCI_CHIP_R300_NE
, R300
, CHIP_HAS_CRTC2
),
170 CHIP_DEF(PCI_CHIP_R300_NF
, R300
, CHIP_HAS_CRTC2
),
171 CHIP_DEF(PCI_CHIP_R300_NG
, R300
, CHIP_HAS_CRTC2
),
172 /* Mobility M10/M11 */
173 CHIP_DEF(PCI_CHIP_RV350_NP
, RV350
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
174 CHIP_DEF(PCI_CHIP_RV350_NQ
, RV350
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
175 CHIP_DEF(PCI_CHIP_RV350_NR
, RV350
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
176 CHIP_DEF(PCI_CHIP_RV350_NS
, RV350
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
177 CHIP_DEF(PCI_CHIP_RV350_NT
, RV350
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
178 CHIP_DEF(PCI_CHIP_RV350_NV
, RV350
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
180 CHIP_DEF(PCI_CHIP_RV350_AP
, RV350
, CHIP_HAS_CRTC2
),
181 CHIP_DEF(PCI_CHIP_RV350_AQ
, RV350
, CHIP_HAS_CRTC2
),
182 CHIP_DEF(PCI_CHIP_RV360_AR
, RV350
, CHIP_HAS_CRTC2
),
183 CHIP_DEF(PCI_CHIP_RV350_AS
, RV350
, CHIP_HAS_CRTC2
),
184 CHIP_DEF(PCI_CHIP_RV350_AT
, RV350
, CHIP_HAS_CRTC2
),
185 CHIP_DEF(PCI_CHIP_RV350_AV
, RV350
, CHIP_HAS_CRTC2
),
186 /* 9800/Pro/FileGL X2 */
187 CHIP_DEF(PCI_CHIP_R350_AH
, R350
, CHIP_HAS_CRTC2
),
188 CHIP_DEF(PCI_CHIP_R350_AI
, R350
, CHIP_HAS_CRTC2
),
189 CHIP_DEF(PCI_CHIP_R350_AJ
, R350
, CHIP_HAS_CRTC2
),
190 CHIP_DEF(PCI_CHIP_R350_AK
, R350
, CHIP_HAS_CRTC2
),
191 CHIP_DEF(PCI_CHIP_R350_NH
, R350
, CHIP_HAS_CRTC2
),
192 CHIP_DEF(PCI_CHIP_R350_NI
, R350
, CHIP_HAS_CRTC2
),
193 CHIP_DEF(PCI_CHIP_R360_NJ
, R350
, CHIP_HAS_CRTC2
),
194 CHIP_DEF(PCI_CHIP_R350_NK
, R350
, CHIP_HAS_CRTC2
),
196 CHIP_DEF(PCI_CHIP_RV380_3E50
, RV380
, CHIP_HAS_CRTC2
),
197 CHIP_DEF(PCI_CHIP_RV380_3E54
, RV380
, CHIP_HAS_CRTC2
),
198 CHIP_DEF(PCI_CHIP_RV380_3150
, RV380
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
199 CHIP_DEF(PCI_CHIP_RV380_3154
, RV380
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
200 CHIP_DEF(PCI_CHIP_RV370_5B60
, RV380
, CHIP_HAS_CRTC2
),
201 CHIP_DEF(PCI_CHIP_RV370_5B62
, RV380
, CHIP_HAS_CRTC2
),
202 CHIP_DEF(PCI_CHIP_RV370_5B64
, RV380
, CHIP_HAS_CRTC2
),
203 CHIP_DEF(PCI_CHIP_RV370_5B65
, RV380
, CHIP_HAS_CRTC2
),
204 CHIP_DEF(PCI_CHIP_RV370_5460
, RV380
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
205 CHIP_DEF(PCI_CHIP_RV370_5464
, RV380
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
206 CHIP_DEF(PCI_CHIP_R420_JH
, R420
, CHIP_HAS_CRTC2
),
207 CHIP_DEF(PCI_CHIP_R420_JI
, R420
, CHIP_HAS_CRTC2
),
208 CHIP_DEF(PCI_CHIP_R420_JJ
, R420
, CHIP_HAS_CRTC2
),
209 CHIP_DEF(PCI_CHIP_R420_JK
, R420
, CHIP_HAS_CRTC2
),
210 CHIP_DEF(PCI_CHIP_R420_JL
, R420
, CHIP_HAS_CRTC2
),
211 CHIP_DEF(PCI_CHIP_R420_JM
, R420
, CHIP_HAS_CRTC2
),
212 CHIP_DEF(PCI_CHIP_R420_JN
, R420
, CHIP_HAS_CRTC2
| CHIP_IS_MOBILITY
),
213 CHIP_DEF(PCI_CHIP_R420_JP
, R420
, CHIP_HAS_CRTC2
),
214 CHIP_DEF(PCI_CHIP_R423_UH
, R420
, CHIP_HAS_CRTC2
),
215 CHIP_DEF(PCI_CHIP_R423_UI
, R420
, CHIP_HAS_CRTC2
),
216 CHIP_DEF(PCI_CHIP_R423_UJ
, R420
, CHIP_HAS_CRTC2
),
217 CHIP_DEF(PCI_CHIP_R423_UK
, R420
, CHIP_HAS_CRTC2
),
218 CHIP_DEF(PCI_CHIP_R423_UQ
, R420
, CHIP_HAS_CRTC2
),
219 CHIP_DEF(PCI_CHIP_R423_UR
, R420
, CHIP_HAS_CRTC2
),
220 CHIP_DEF(PCI_CHIP_R423_UT
, R420
, CHIP_HAS_CRTC2
),
221 CHIP_DEF(PCI_CHIP_R423_5D57
, R420
, CHIP_HAS_CRTC2
),
222 /* Original Radeon/7200 */
223 CHIP_DEF(PCI_CHIP_RADEON_QD
, RADEON
, 0),
224 CHIP_DEF(PCI_CHIP_RADEON_QE
, RADEON
, 0),
225 CHIP_DEF(PCI_CHIP_RADEON_QF
, RADEON
, 0),
226 CHIP_DEF(PCI_CHIP_RADEON_QG
, RADEON
, 0),
229 MODULE_DEVICE_TABLE(pci
, radeonfb_pci_table
);
238 /* these common regs are cleared before mode setting so they do not
239 * interfere with anything
241 static reg_val common_regs
[] = {
243 { OVR_WID_LEFT_RIGHT
, 0 },
244 { OVR_WID_TOP_BOTTOM
, 0 },
245 { OV0_SCALE_CNTL
, 0 },
250 { CAP0_TRIG_CNTL
, 0 },
251 { CAP1_TRIG_CNTL
, 0 },
258 static char *mode_option
;
259 static char *monitor_layout
;
260 static int noaccel
= 0;
261 static int default_dynclk
= -2;
262 static int nomodeset
= 0;
263 static int ignore_edid
= 0;
264 static int mirror
= 0;
265 static int panel_yres
= 0;
266 static int force_dfp
= 0;
267 static int force_measure_pll
= 0;
269 static int nomtrr
= 0;
271 static int force_sleep
;
272 static int ignore_devlist
;
273 #ifdef CONFIG_PMAC_BACKLIGHT
274 static int backlight
= 1;
276 static int backlight
= 0;
283 static void radeon_unmap_ROM(struct radeonfb_info
*rinfo
, struct pci_dev
*dev
)
285 if (!rinfo
->bios_seg
)
287 pci_unmap_rom(dev
, rinfo
->bios_seg
);
290 static int __devinit
radeon_map_ROM(struct radeonfb_info
*rinfo
, struct pci_dev
*dev
)
297 /* If this is a primary card, there is a shadow copy of the
298 * ROM somewhere in the first meg. We will just ignore the copy
299 * and use the ROM directly.
302 /* Fix from ATI for problem with Radeon hardware not leaving ROM enabled */
304 temp
= INREG(MPP_TB_CONFIG
);
307 OUTREG(MPP_TB_CONFIG
, temp
);
308 temp
= INREG(MPP_TB_CONFIG
);
310 rom
= pci_map_rom(dev
, &rom_size
);
312 printk(KERN_ERR
"radeonfb (%s): ROM failed to map\n",
313 pci_name(rinfo
->pdev
));
317 rinfo
->bios_seg
= rom
;
319 /* Very simple test to make sure it appeared */
320 if (BIOS_IN16(0) != 0xaa55) {
321 printk(KERN_DEBUG
"radeonfb (%s): Invalid ROM signature %x "
322 "should be 0xaa55\n",
323 pci_name(rinfo
->pdev
), BIOS_IN16(0));
326 /* Look for the PCI data to check the ROM type */
327 dptr
= BIOS_IN16(0x18);
329 /* Check the PCI data signature. If it's wrong, we still assume a normal x86 ROM
330 * for now, until I've verified this works everywhere. The goal here is more
331 * to phase out Open Firmware images.
333 * Currently, we only look at the first PCI data, we could iteratre and deal with
334 * them all, and we should use fb_bios_start relative to start of image and not
335 * relative start of ROM, but so far, I never found a dual-image ATI card
338 * u32 signature; + 0x00
341 * u16 reserved_1; + 0x08
343 * u8 drevision; + 0x0c
344 * u8 class_hi; + 0x0d
345 * u16 class_lo; + 0x0e
347 * u16 irevision; + 0x12
349 * u8 indicator; + 0x15
350 * u16 reserved_2; + 0x16
353 if (BIOS_IN32(dptr
) != (('R' << 24) | ('I' << 16) | ('C' << 8) | 'P')) {
354 printk(KERN_WARNING
"radeonfb (%s): PCI DATA signature in ROM"
355 "incorrect: %08x\n", pci_name(rinfo
->pdev
), BIOS_IN32(dptr
));
358 rom_type
= BIOS_IN8(dptr
+ 0x14);
361 printk(KERN_INFO
"radeonfb: Found Intel x86 BIOS ROM Image\n");
364 printk(KERN_INFO
"radeonfb: Found Open Firmware ROM Image\n");
367 printk(KERN_INFO
"radeonfb: Found HP PA-RISC ROM Image\n");
370 printk(KERN_INFO
"radeonfb: Found unknown type %d ROM Image\n", rom_type
);
374 /* Locate the flat panel infos, do some sanity checking !!! */
375 rinfo
->fp_bios_start
= BIOS_IN16(0x48);
379 rinfo
->bios_seg
= NULL
;
380 radeon_unmap_ROM(rinfo
, dev
);
385 static int __devinit
radeon_find_mem_vbios(struct radeonfb_info
*rinfo
)
387 /* I simplified this code as we used to miss the signatures in
388 * a lot of case. It's now closer to XFree, we just don't check
389 * for signatures at all... Something better will have to be done
390 * if we end up having conflicts
393 void __iomem
*rom_base
= NULL
;
395 for(segstart
=0x000c0000; segstart
<0x000f0000; segstart
+=0x00001000) {
396 rom_base
= ioremap(segstart
, 0x10000);
397 if (rom_base
== NULL
)
399 if (readb(rom_base
) == 0x55 && readb(rom_base
+ 1) == 0xaa)
404 if (rom_base
== NULL
)
407 /* Locate the flat panel infos, do some sanity checking !!! */
408 rinfo
->bios_seg
= rom_base
;
409 rinfo
->fp_bios_start
= BIOS_IN16(0x48);
415 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
417 * Read XTAL (ref clock), SCLK and MCLK from Open Firmware device
418 * tree. Hopefully, ATI OF driver is kind enough to fill these
420 static int __devinit
radeon_read_xtal_OF (struct radeonfb_info
*rinfo
)
422 struct device_node
*dp
= rinfo
->of_node
;
427 val
= of_get_property(dp
, "ATY,RefCLK", NULL
);
429 printk(KERN_WARNING
"radeonfb: No ATY,RefCLK property !\n");
433 rinfo
->pll
.ref_clk
= (*val
) / 10;
435 val
= of_get_property(dp
, "ATY,SCLK", NULL
);
437 rinfo
->pll
.sclk
= (*val
) / 10;
439 val
= of_get_property(dp
, "ATY,MCLK", NULL
);
441 rinfo
->pll
.mclk
= (*val
) / 10;
445 #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
448 * Read PLL infos from chip registers
450 static int __devinit
radeon_probe_pll_params(struct radeonfb_info
*rinfo
)
452 unsigned char ppll_div_sel
;
454 unsigned sclk
, mclk
, tmp
, ref_div
;
455 int hTotal
, vTotal
, num
, denom
, m
, n
;
456 unsigned long long hz
, vclk
;
458 struct timeval start_tv
, stop_tv
;
459 long total_secs
, total_usecs
;
462 /* Ugh, we cut interrupts, bad bad bad, but we want some precision
466 /* Flush PCI buffers ? */
467 tmp
= INREG16(DEVICE_ID
);
471 for(i
=0; i
<1000000; i
++)
472 if (((INREG(CRTC_VLINE_CRNT_VLINE
) >> 16) & 0x3ff) == 0)
475 do_gettimeofday(&start_tv
);
477 for(i
=0; i
<1000000; i
++)
478 if (((INREG(CRTC_VLINE_CRNT_VLINE
) >> 16) & 0x3ff) != 0)
481 for(i
=0; i
<1000000; i
++)
482 if (((INREG(CRTC_VLINE_CRNT_VLINE
) >> 16) & 0x3ff) == 0)
485 do_gettimeofday(&stop_tv
);
489 total_secs
= stop_tv
.tv_sec
- start_tv
.tv_sec
;
492 total_usecs
= stop_tv
.tv_usec
- start_tv
.tv_usec
;
493 total_usecs
+= total_secs
* 1000000;
495 total_usecs
= -total_usecs
;
496 hz
= 1000000/total_usecs
;
498 hTotal
= ((INREG(CRTC_H_TOTAL_DISP
) & 0x1ff) + 1) * 8;
499 vTotal
= ((INREG(CRTC_V_TOTAL_DISP
) & 0x3ff) + 1);
500 vclk
= (long long)hTotal
* (long long)vTotal
* hz
;
502 switch((INPLL(PPLL_REF_DIV
) & 0x30000) >> 16) {
509 n
= ((INPLL(M_SPLL_REF_FB_DIV
) >> 16) & 0xff);
510 m
= (INPLL(M_SPLL_REF_FB_DIV
) & 0xff);
515 n
= ((INPLL(M_SPLL_REF_FB_DIV
) >> 8) & 0xff);
516 m
= (INPLL(M_SPLL_REF_FB_DIV
) & 0xff);
522 ppll_div_sel
= INREG8(CLOCK_CNTL_INDEX
+ 1) & 0x3;
523 radeon_pll_errata_after_index(rinfo
);
525 n
= (INPLL(PPLL_DIV_0
+ ppll_div_sel
) & 0x7ff);
526 m
= (INPLL(PPLL_REF_DIV
) & 0x3ff);
531 switch ((INPLL(PPLL_DIV_0
+ ppll_div_sel
) >> 16) & 0x7) {
553 do_div(vclk
, 1000 * num
);
556 if ((xtal
> 26900) && (xtal
< 27100))
558 else if ((xtal
> 14200) && (xtal
< 14400))
560 else if ((xtal
> 29400) && (xtal
< 29600))
563 printk(KERN_WARNING
"xtal calculation failed: %ld\n", xtal
);
567 tmp
= INPLL(M_SPLL_REF_FB_DIV
);
568 ref_div
= INPLL(PPLL_REF_DIV
) & 0x3ff;
570 Ns
= (tmp
& 0xff0000) >> 16;
571 Nm
= (tmp
& 0xff00) >> 8;
573 sclk
= round_div((2 * Ns
* xtal
), (2 * M
));
574 mclk
= round_div((2 * Nm
* xtal
), (2 * M
));
576 /* we're done, hopefully these are sane values */
577 rinfo
->pll
.ref_clk
= xtal
;
578 rinfo
->pll
.ref_div
= ref_div
;
579 rinfo
->pll
.sclk
= sclk
;
580 rinfo
->pll
.mclk
= mclk
;
586 * Retrieve PLL infos by different means (BIOS, Open Firmware, register probing...)
588 static void __devinit
radeon_get_pllinfo(struct radeonfb_info
*rinfo
)
591 * In the case nothing works, these are defaults; they are mostly
592 * incomplete, however. It does provide ppll_max and _min values
593 * even for most other methods, however.
595 switch (rinfo
->chipset
) {
596 case PCI_DEVICE_ID_ATI_RADEON_QW
:
597 case PCI_DEVICE_ID_ATI_RADEON_QX
:
598 rinfo
->pll
.ppll_max
= 35000;
599 rinfo
->pll
.ppll_min
= 12000;
600 rinfo
->pll
.mclk
= 23000;
601 rinfo
->pll
.sclk
= 23000;
602 rinfo
->pll
.ref_clk
= 2700;
604 case PCI_DEVICE_ID_ATI_RADEON_QL
:
605 case PCI_DEVICE_ID_ATI_RADEON_QN
:
606 case PCI_DEVICE_ID_ATI_RADEON_QO
:
607 case PCI_DEVICE_ID_ATI_RADEON_Ql
:
608 case PCI_DEVICE_ID_ATI_RADEON_BB
:
609 rinfo
->pll
.ppll_max
= 35000;
610 rinfo
->pll
.ppll_min
= 12000;
611 rinfo
->pll
.mclk
= 27500;
612 rinfo
->pll
.sclk
= 27500;
613 rinfo
->pll
.ref_clk
= 2700;
615 case PCI_DEVICE_ID_ATI_RADEON_Id
:
616 case PCI_DEVICE_ID_ATI_RADEON_Ie
:
617 case PCI_DEVICE_ID_ATI_RADEON_If
:
618 case PCI_DEVICE_ID_ATI_RADEON_Ig
:
619 rinfo
->pll
.ppll_max
= 35000;
620 rinfo
->pll
.ppll_min
= 12000;
621 rinfo
->pll
.mclk
= 25000;
622 rinfo
->pll
.sclk
= 25000;
623 rinfo
->pll
.ref_clk
= 2700;
625 case PCI_DEVICE_ID_ATI_RADEON_ND
:
626 case PCI_DEVICE_ID_ATI_RADEON_NE
:
627 case PCI_DEVICE_ID_ATI_RADEON_NF
:
628 case PCI_DEVICE_ID_ATI_RADEON_NG
:
629 rinfo
->pll
.ppll_max
= 40000;
630 rinfo
->pll
.ppll_min
= 20000;
631 rinfo
->pll
.mclk
= 27000;
632 rinfo
->pll
.sclk
= 27000;
633 rinfo
->pll
.ref_clk
= 2700;
635 case PCI_DEVICE_ID_ATI_RADEON_QD
:
636 case PCI_DEVICE_ID_ATI_RADEON_QE
:
637 case PCI_DEVICE_ID_ATI_RADEON_QF
:
638 case PCI_DEVICE_ID_ATI_RADEON_QG
:
640 rinfo
->pll
.ppll_max
= 35000;
641 rinfo
->pll
.ppll_min
= 12000;
642 rinfo
->pll
.mclk
= 16600;
643 rinfo
->pll
.sclk
= 16600;
644 rinfo
->pll
.ref_clk
= 2700;
647 rinfo
->pll
.ref_div
= INPLL(PPLL_REF_DIV
) & PPLL_REF_DIV_MASK
;
650 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
652 * Retrieve PLL infos from Open Firmware first
654 if (!force_measure_pll
&& radeon_read_xtal_OF(rinfo
) == 0) {
655 printk(KERN_INFO
"radeonfb: Retrieved PLL infos from Open Firmware\n");
658 #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
661 * Check out if we have an X86 which gave us some PLL informations
662 * and if yes, retrieve them
664 if (!force_measure_pll
&& rinfo
->bios_seg
) {
665 u16 pll_info_block
= BIOS_IN16(rinfo
->fp_bios_start
+ 0x30);
667 rinfo
->pll
.sclk
= BIOS_IN16(pll_info_block
+ 0x08);
668 rinfo
->pll
.mclk
= BIOS_IN16(pll_info_block
+ 0x0a);
669 rinfo
->pll
.ref_clk
= BIOS_IN16(pll_info_block
+ 0x0e);
670 rinfo
->pll
.ref_div
= BIOS_IN16(pll_info_block
+ 0x10);
671 rinfo
->pll
.ppll_min
= BIOS_IN32(pll_info_block
+ 0x12);
672 rinfo
->pll
.ppll_max
= BIOS_IN32(pll_info_block
+ 0x16);
674 printk(KERN_INFO
"radeonfb: Retrieved PLL infos from BIOS\n");
679 * We didn't get PLL parameters from either OF or BIOS, we try to
682 if (radeon_probe_pll_params(rinfo
) == 0) {
683 printk(KERN_INFO
"radeonfb: Retrieved PLL infos from registers\n");
688 * Fall back to already-set defaults...
690 printk(KERN_INFO
"radeonfb: Used default PLL infos\n");
694 * Some methods fail to retrieve SCLK and MCLK values, we apply default
695 * settings in this case (200Mhz). If that really happne often, we could
696 * fetch from registers instead...
698 if (rinfo
->pll
.mclk
== 0)
699 rinfo
->pll
.mclk
= 20000;
700 if (rinfo
->pll
.sclk
== 0)
701 rinfo
->pll
.sclk
= 20000;
703 printk("radeonfb: Reference=%d.%02d MHz (RefDiv=%d) Memory=%d.%02d Mhz, System=%d.%02d MHz\n",
704 rinfo
->pll
.ref_clk
/ 100, rinfo
->pll
.ref_clk
% 100,
706 rinfo
->pll
.mclk
/ 100, rinfo
->pll
.mclk
% 100,
707 rinfo
->pll
.sclk
/ 100, rinfo
->pll
.sclk
% 100);
708 printk("radeonfb: PLL min %d max %d\n", rinfo
->pll
.ppll_min
, rinfo
->pll
.ppll_max
);
711 static int radeonfb_check_var (struct fb_var_screeninfo
*var
, struct fb_info
*info
)
713 struct radeonfb_info
*rinfo
= info
->par
;
714 struct fb_var_screeninfo v
;
718 if (radeon_match_mode(rinfo
, &v
, var
))
721 switch (v
.bits_per_pixel
) {
723 v
.bits_per_pixel
= 8;
726 v
.bits_per_pixel
= 16;
729 #if 0 /* Doesn't seem to work */
730 v
.bits_per_pixel
= 24;
735 v
.bits_per_pixel
= 32;
741 switch (var_to_depth(&v
)) {
744 v
.red
.offset
= v
.green
.offset
= v
.blue
.offset
= 0;
745 v
.red
.length
= v
.green
.length
= v
.blue
.length
= 8;
746 v
.transp
.offset
= v
.transp
.length
= 0;
754 v
.red
.length
= v
.green
.length
= v
.blue
.length
= 5;
755 v
.transp
.offset
= v
.transp
.length
= 0;
766 v
.transp
.offset
= v
.transp
.length
= 0;
774 v
.red
.length
= v
.blue
.length
= v
.green
.length
= 8;
775 v
.transp
.offset
= v
.transp
.length
= 0;
783 v
.red
.length
= v
.blue
.length
= v
.green
.length
= 8;
784 v
.transp
.offset
= 24;
788 printk ("radeonfb: mode %dx%dx%d rejected, color depth invalid\n",
789 var
->xres
, var
->yres
, var
->bits_per_pixel
);
793 if (v
.yres_virtual
< v
.yres
)
794 v
.yres_virtual
= v
.yres
;
795 if (v
.xres_virtual
< v
.xres
)
796 v
.xres_virtual
= v
.xres
;
799 /* XXX I'm adjusting xres_virtual to the pitch, that may help XFree
800 * with some panels, though I don't quite like this solution
802 if (rinfo
->info
->flags
& FBINFO_HWACCEL_DISABLED
) {
803 v
.xres_virtual
= v
.xres_virtual
& ~7ul;
805 pitch
= ((v
.xres_virtual
* ((v
.bits_per_pixel
+ 1) / 8) + 0x3f)
807 v
.xres_virtual
= (pitch
<< 6) / ((v
.bits_per_pixel
+ 1) / 8);
810 if (((v
.xres_virtual
* v
.yres_virtual
* nom
) / den
) > rinfo
->mapped_vram
)
813 if (v
.xres_virtual
< v
.xres
)
814 v
.xres
= v
.xres_virtual
;
821 if (v
.xoffset
> v
.xres_virtual
- v
.xres
)
822 v
.xoffset
= v
.xres_virtual
- v
.xres
- 1;
824 if (v
.yoffset
> v
.yres_virtual
- v
.yres
)
825 v
.yoffset
= v
.yres_virtual
- v
.yres
- 1;
827 v
.red
.msb_right
= v
.green
.msb_right
= v
.blue
.msb_right
=
828 v
.transp
.offset
= v
.transp
.length
=
829 v
.transp
.msb_right
= 0;
831 memcpy(var
, &v
, sizeof(v
));
837 static int radeonfb_pan_display (struct fb_var_screeninfo
*var
,
838 struct fb_info
*info
)
840 struct radeonfb_info
*rinfo
= info
->par
;
842 if ((var
->xoffset
+ var
->xres
> var
->xres_virtual
)
843 || (var
->yoffset
+ var
->yres
> var
->yres_virtual
))
850 OUTREG(CRTC_OFFSET
, ((var
->yoffset
* var
->xres_virtual
+ var
->xoffset
)
851 * var
->bits_per_pixel
/ 8) & ~7);
856 static int radeonfb_ioctl (struct fb_info
*info
, unsigned int cmd
,
859 struct radeonfb_info
*rinfo
= info
->par
;
866 * TODO: set mirror accordingly for non-Mobility chipsets with 2 CRTC's
867 * and do something better using 2nd CRTC instead of just hackish
868 * routing to second output
870 case FBIO_RADEON_SET_MIRROR
:
871 if (!rinfo
->is_mobility
)
874 rc
= get_user(value
, (__u32 __user
*)arg
);
881 tmp
= INREG(LVDS_GEN_CNTL
);
883 tmp
|= (LVDS_ON
| LVDS_BLON
);
885 tmp
= INREG(LVDS_GEN_CNTL
);
887 tmp
&= ~(LVDS_ON
| LVDS_BLON
);
890 OUTREG(LVDS_GEN_CNTL
, tmp
);
893 tmp
= INREG(CRTC_EXT_CNTL
);
898 tmp
= INREG(CRTC_EXT_CNTL
);
904 OUTREG(CRTC_EXT_CNTL
, tmp
);
907 case FBIO_RADEON_GET_MIRROR
:
908 if (!rinfo
->is_mobility
)
911 tmp
= INREG(LVDS_GEN_CNTL
);
912 if ((LVDS_ON
| LVDS_BLON
) & tmp
)
915 tmp
= INREG(CRTC_EXT_CNTL
);
916 if (CRTC_CRT_ON
& tmp
)
919 return put_user(value
, (__u32 __user
*)arg
);
928 int radeon_screen_blank(struct radeonfb_info
*rinfo
, int blank
, int mode_switch
)
934 if (rinfo
->lock_blank
)
937 radeon_engine_idle();
939 val
= INREG(CRTC_EXT_CNTL
);
940 val
&= ~(CRTC_DISPLAY_DIS
| CRTC_HSYNC_DIS
|
943 case FB_BLANK_VSYNC_SUSPEND
:
944 val
|= (CRTC_DISPLAY_DIS
| CRTC_VSYNC_DIS
);
946 case FB_BLANK_HSYNC_SUSPEND
:
947 val
|= (CRTC_DISPLAY_DIS
| CRTC_HSYNC_DIS
);
949 case FB_BLANK_POWERDOWN
:
950 val
|= (CRTC_DISPLAY_DIS
| CRTC_VSYNC_DIS
|
953 case FB_BLANK_NORMAL
:
954 val
|= CRTC_DISPLAY_DIS
;
956 case FB_BLANK_UNBLANK
:
960 OUTREG(CRTC_EXT_CNTL
, val
);
963 switch (rinfo
->mon1_type
) {
966 OUTREGP(FP_GEN_CNTL
, (FP_FPON
| FP_TMDS_EN
),
967 ~(FP_FPON
| FP_TMDS_EN
));
969 if (mode_switch
|| blank
== FB_BLANK_NORMAL
)
971 OUTREGP(FP_GEN_CNTL
, 0, ~(FP_FPON
| FP_TMDS_EN
));
975 del_timer_sync(&rinfo
->lvds_timer
);
976 val
= INREG(LVDS_GEN_CNTL
);
978 u32 target_val
= (val
& ~LVDS_DISPLAY_DIS
) | LVDS_BLON
| LVDS_ON
979 | LVDS_EN
| (rinfo
->init_state
.lvds_gen_cntl
980 & (LVDS_DIGON
| LVDS_BL_MOD_EN
));
981 if ((val
^ target_val
) == LVDS_DISPLAY_DIS
)
982 OUTREG(LVDS_GEN_CNTL
, target_val
);
983 else if ((val
^ target_val
) != 0) {
984 OUTREG(LVDS_GEN_CNTL
, target_val
985 & ~(LVDS_ON
| LVDS_BL_MOD_EN
));
986 rinfo
->init_state
.lvds_gen_cntl
&= ~LVDS_STATE_MASK
;
987 rinfo
->init_state
.lvds_gen_cntl
|=
988 target_val
& LVDS_STATE_MASK
;
990 radeon_msleep(rinfo
->panel_info
.pwr_delay
);
991 OUTREG(LVDS_GEN_CNTL
, target_val
);
994 rinfo
->pending_lvds_gen_cntl
= target_val
;
995 mod_timer(&rinfo
->lvds_timer
,
997 msecs_to_jiffies(rinfo
->panel_info
.pwr_delay
));
1001 val
|= LVDS_DISPLAY_DIS
;
1002 OUTREG(LVDS_GEN_CNTL
, val
);
1004 /* We don't do a full switch-off on a simple mode switch */
1005 if (mode_switch
|| blank
== FB_BLANK_NORMAL
)
1008 /* Asic bug, when turning off LVDS_ON, we have to make sure
1009 * RADEON_PIXCLK_LVDS_ALWAYS_ON bit is off
1011 tmp_pix_clks
= INPLL(PIXCLKS_CNTL
);
1012 if (rinfo
->is_mobility
|| rinfo
->is_IGP
)
1013 OUTPLLP(PIXCLKS_CNTL
, 0, ~PIXCLK_LVDS_ALWAYS_ONb
);
1014 val
&= ~(LVDS_BL_MOD_EN
);
1015 OUTREG(LVDS_GEN_CNTL
, val
);
1017 val
&= ~(LVDS_ON
| LVDS_EN
);
1018 OUTREG(LVDS_GEN_CNTL
, val
);
1020 rinfo
->pending_lvds_gen_cntl
= val
;
1021 mod_timer(&rinfo
->lvds_timer
,
1023 msecs_to_jiffies(rinfo
->panel_info
.pwr_delay
));
1024 rinfo
->init_state
.lvds_gen_cntl
&= ~LVDS_STATE_MASK
;
1025 rinfo
->init_state
.lvds_gen_cntl
|= val
& LVDS_STATE_MASK
;
1026 if (rinfo
->is_mobility
|| rinfo
->is_IGP
)
1027 OUTPLL(PIXCLKS_CNTL
, tmp_pix_clks
);
1031 // todo: powerdown DAC
1039 static int radeonfb_blank (int blank
, struct fb_info
*info
)
1041 struct radeonfb_info
*rinfo
= info
->par
;
1046 return radeon_screen_blank(rinfo
, blank
, 0);
1049 static int radeon_setcolreg (unsigned regno
, unsigned red
, unsigned green
,
1050 unsigned blue
, unsigned transp
,
1051 struct radeonfb_info
*rinfo
)
1063 rinfo
->palette
[regno
].red
= red
;
1064 rinfo
->palette
[regno
].green
= green
;
1065 rinfo
->palette
[regno
].blue
= blue
;
1070 if (!rinfo
->asleep
) {
1071 radeon_fifo_wait(9);
1073 if (rinfo
->bpp
== 16) {
1076 if (rinfo
->depth
== 16 && regno
> 63)
1078 if (rinfo
->depth
== 15 && regno
> 31)
1081 /* For 565, the green component is mixed one order
1084 if (rinfo
->depth
== 16) {
1085 OUTREG(PALETTE_INDEX
, pindex
>>1);
1086 OUTREG(PALETTE_DATA
,
1087 (rinfo
->palette
[regno
>>1].red
<< 16) |
1089 (rinfo
->palette
[regno
>>1].blue
));
1090 green
= rinfo
->palette
[regno
<<1].green
;
1094 if (rinfo
->depth
!= 16 || regno
< 32) {
1095 OUTREG(PALETTE_INDEX
, pindex
);
1096 OUTREG(PALETTE_DATA
, (red
<< 16) |
1097 (green
<< 8) | blue
);
1101 u32
*pal
= rinfo
->info
->pseudo_palette
;
1102 switch (rinfo
->depth
) {
1104 pal
[regno
] = (regno
<< 10) | (regno
<< 5) | regno
;
1107 pal
[regno
] = (regno
<< 11) | (regno
<< 5) | regno
;
1110 pal
[regno
] = (regno
<< 16) | (regno
<< 8) | regno
;
1113 i
= (regno
<< 8) | regno
;
1114 pal
[regno
] = (i
<< 16) | i
;
1121 static int radeonfb_setcolreg (unsigned regno
, unsigned red
, unsigned green
,
1122 unsigned blue
, unsigned transp
,
1123 struct fb_info
*info
)
1125 struct radeonfb_info
*rinfo
= info
->par
;
1126 u32 dac_cntl2
, vclk_cntl
= 0;
1129 if (!rinfo
->asleep
) {
1130 if (rinfo
->is_mobility
) {
1131 vclk_cntl
= INPLL(VCLK_ECP_CNTL
);
1132 OUTPLL(VCLK_ECP_CNTL
,
1133 vclk_cntl
& ~PIXCLK_DAC_ALWAYS_ONb
);
1136 /* Make sure we are on first palette */
1137 if (rinfo
->has_CRTC2
) {
1138 dac_cntl2
= INREG(DAC_CNTL2
);
1139 dac_cntl2
&= ~DAC2_PALETTE_ACCESS_CNTL
;
1140 OUTREG(DAC_CNTL2
, dac_cntl2
);
1144 rc
= radeon_setcolreg (regno
, red
, green
, blue
, transp
, rinfo
);
1146 if (!rinfo
->asleep
&& rinfo
->is_mobility
)
1147 OUTPLL(VCLK_ECP_CNTL
, vclk_cntl
);
1152 static int radeonfb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
1154 struct radeonfb_info
*rinfo
= info
->par
;
1155 u16
*red
, *green
, *blue
, *transp
;
1156 u32 dac_cntl2
, vclk_cntl
= 0;
1157 int i
, start
, rc
= 0;
1159 if (!rinfo
->asleep
) {
1160 if (rinfo
->is_mobility
) {
1161 vclk_cntl
= INPLL(VCLK_ECP_CNTL
);
1162 OUTPLL(VCLK_ECP_CNTL
,
1163 vclk_cntl
& ~PIXCLK_DAC_ALWAYS_ONb
);
1166 /* Make sure we are on first palette */
1167 if (rinfo
->has_CRTC2
) {
1168 dac_cntl2
= INREG(DAC_CNTL2
);
1169 dac_cntl2
&= ~DAC2_PALETTE_ACCESS_CNTL
;
1170 OUTREG(DAC_CNTL2
, dac_cntl2
);
1175 green
= cmap
->green
;
1177 transp
= cmap
->transp
;
1178 start
= cmap
->start
;
1180 for (i
= 0; i
< cmap
->len
; i
++) {
1181 u_int hred
, hgreen
, hblue
, htransp
= 0xffff;
1187 htransp
= *transp
++;
1188 rc
= radeon_setcolreg (start
++, hred
, hgreen
, hblue
, htransp
,
1194 if (!rinfo
->asleep
&& rinfo
->is_mobility
)
1195 OUTPLL(VCLK_ECP_CNTL
, vclk_cntl
);
1200 static void radeon_save_state (struct radeonfb_info
*rinfo
,
1201 struct radeon_regs
*save
)
1204 save
->crtc_gen_cntl
= INREG(CRTC_GEN_CNTL
);
1205 save
->crtc_ext_cntl
= INREG(CRTC_EXT_CNTL
);
1206 save
->crtc_more_cntl
= INREG(CRTC_MORE_CNTL
);
1207 save
->dac_cntl
= INREG(DAC_CNTL
);
1208 save
->crtc_h_total_disp
= INREG(CRTC_H_TOTAL_DISP
);
1209 save
->crtc_h_sync_strt_wid
= INREG(CRTC_H_SYNC_STRT_WID
);
1210 save
->crtc_v_total_disp
= INREG(CRTC_V_TOTAL_DISP
);
1211 save
->crtc_v_sync_strt_wid
= INREG(CRTC_V_SYNC_STRT_WID
);
1212 save
->crtc_pitch
= INREG(CRTC_PITCH
);
1213 save
->surface_cntl
= INREG(SURFACE_CNTL
);
1216 save
->fp_crtc_h_total_disp
= INREG(FP_CRTC_H_TOTAL_DISP
);
1217 save
->fp_crtc_v_total_disp
= INREG(FP_CRTC_V_TOTAL_DISP
);
1218 save
->fp_gen_cntl
= INREG(FP_GEN_CNTL
);
1219 save
->fp_h_sync_strt_wid
= INREG(FP_H_SYNC_STRT_WID
);
1220 save
->fp_horz_stretch
= INREG(FP_HORZ_STRETCH
);
1221 save
->fp_v_sync_strt_wid
= INREG(FP_V_SYNC_STRT_WID
);
1222 save
->fp_vert_stretch
= INREG(FP_VERT_STRETCH
);
1223 save
->lvds_gen_cntl
= INREG(LVDS_GEN_CNTL
);
1224 save
->lvds_pll_cntl
= INREG(LVDS_PLL_CNTL
);
1225 save
->tmds_crc
= INREG(TMDS_CRC
);
1226 save
->tmds_transmitter_cntl
= INREG(TMDS_TRANSMITTER_CNTL
);
1227 save
->vclk_ecp_cntl
= INPLL(VCLK_ECP_CNTL
);
1230 save
->clk_cntl_index
= INREG(CLOCK_CNTL_INDEX
) & ~0x3f;
1231 radeon_pll_errata_after_index(rinfo
);
1232 save
->ppll_div_3
= INPLL(PPLL_DIV_3
);
1233 save
->ppll_ref_div
= INPLL(PPLL_REF_DIV
);
1237 static void radeon_write_pll_regs(struct radeonfb_info
*rinfo
, struct radeon_regs
*mode
)
1241 radeon_fifo_wait(20);
1243 /* Workaround from XFree */
1244 if (rinfo
->is_mobility
) {
1245 /* A temporal workaround for the occational blanking on certain laptop
1246 * panels. This appears to related to the PLL divider registers
1247 * (fail to lock?). It occurs even when all dividers are the same
1248 * with their old settings. In this case we really don't need to
1249 * fiddle with PLL registers. By doing this we can avoid the blanking
1250 * problem with some panels.
1252 if ((mode
->ppll_ref_div
== (INPLL(PPLL_REF_DIV
) & PPLL_REF_DIV_MASK
)) &&
1253 (mode
->ppll_div_3
== (INPLL(PPLL_DIV_3
) &
1254 (PPLL_POST3_DIV_MASK
| PPLL_FB3_DIV_MASK
)))) {
1255 /* We still have to force a switch to selected PPLL div thanks to
1256 * an XFree86 driver bug which will switch it away in some cases
1257 * even when using UseFDev */
1258 OUTREGP(CLOCK_CNTL_INDEX
,
1259 mode
->clk_cntl_index
& PPLL_DIV_SEL_MASK
,
1260 ~PPLL_DIV_SEL_MASK
);
1261 radeon_pll_errata_after_index(rinfo
);
1262 radeon_pll_errata_after_data(rinfo
);
1267 /* Swich VCKL clock input to CPUCLK so it stays fed while PPLL updates*/
1268 OUTPLLP(VCLK_ECP_CNTL
, VCLK_SRC_SEL_CPUCLK
, ~VCLK_SRC_SEL_MASK
);
1270 /* Reset PPLL & enable atomic update */
1272 PPLL_RESET
| PPLL_ATOMIC_UPDATE_EN
| PPLL_VGA_ATOMIC_UPDATE_EN
,
1273 ~(PPLL_RESET
| PPLL_ATOMIC_UPDATE_EN
| PPLL_VGA_ATOMIC_UPDATE_EN
));
1275 /* Switch to selected PPLL divider */
1276 OUTREGP(CLOCK_CNTL_INDEX
,
1277 mode
->clk_cntl_index
& PPLL_DIV_SEL_MASK
,
1278 ~PPLL_DIV_SEL_MASK
);
1279 radeon_pll_errata_after_index(rinfo
);
1280 radeon_pll_errata_after_data(rinfo
);
1282 /* Set PPLL ref. div */
1283 if (rinfo
->family
== CHIP_FAMILY_R300
||
1284 rinfo
->family
== CHIP_FAMILY_RS300
||
1285 rinfo
->family
== CHIP_FAMILY_R350
||
1286 rinfo
->family
== CHIP_FAMILY_RV350
) {
1287 if (mode
->ppll_ref_div
& R300_PPLL_REF_DIV_ACC_MASK
) {
1288 /* When restoring console mode, use saved PPLL_REF_DIV
1291 OUTPLLP(PPLL_REF_DIV
, mode
->ppll_ref_div
, 0);
1293 /* R300 uses ref_div_acc field as real ref divider */
1294 OUTPLLP(PPLL_REF_DIV
,
1295 (mode
->ppll_ref_div
<< R300_PPLL_REF_DIV_ACC_SHIFT
),
1296 ~R300_PPLL_REF_DIV_ACC_MASK
);
1299 OUTPLLP(PPLL_REF_DIV
, mode
->ppll_ref_div
, ~PPLL_REF_DIV_MASK
);
1301 /* Set PPLL divider 3 & post divider*/
1302 OUTPLLP(PPLL_DIV_3
, mode
->ppll_div_3
, ~PPLL_FB3_DIV_MASK
);
1303 OUTPLLP(PPLL_DIV_3
, mode
->ppll_div_3
, ~PPLL_POST3_DIV_MASK
);
1306 while (INPLL(PPLL_REF_DIV
) & PPLL_ATOMIC_UPDATE_R
)
1308 OUTPLLP(PPLL_REF_DIV
, PPLL_ATOMIC_UPDATE_W
, ~PPLL_ATOMIC_UPDATE_W
);
1310 /* Wait read update complete */
1311 /* FIXME: Certain revisions of R300 can't recover here. Not sure of
1312 the cause yet, but this workaround will mask the problem for now.
1313 Other chips usually will pass at the very first test, so the
1314 workaround shouldn't have any effect on them. */
1315 for (i
= 0; (i
< 10000 && INPLL(PPLL_REF_DIV
) & PPLL_ATOMIC_UPDATE_R
); i
++)
1318 OUTPLL(HTOTAL_CNTL
, 0);
1320 /* Clear reset & atomic update */
1321 OUTPLLP(PPLL_CNTL
, 0,
1322 ~(PPLL_RESET
| PPLL_SLEEP
| PPLL_ATOMIC_UPDATE_EN
| PPLL_VGA_ATOMIC_UPDATE_EN
));
1324 /* We may want some locking ... oh well */
1327 /* Switch back VCLK source to PPLL */
1328 OUTPLLP(VCLK_ECP_CNTL
, VCLK_SRC_SEL_PPLLCLK
, ~VCLK_SRC_SEL_MASK
);
1332 * Timer function for delayed LVDS panel power up/down
1334 static void radeon_lvds_timer_func(unsigned long data
)
1336 struct radeonfb_info
*rinfo
= (struct radeonfb_info
*)data
;
1338 radeon_engine_idle();
1340 OUTREG(LVDS_GEN_CNTL
, rinfo
->pending_lvds_gen_cntl
);
1344 * Apply a video mode. This will apply the whole register set, including
1345 * the PLL registers, to the card
1347 void radeon_write_mode (struct radeonfb_info
*rinfo
, struct radeon_regs
*mode
,
1351 int primary_mon
= PRIMARY_MONITOR(rinfo
);
1357 radeon_screen_blank(rinfo
, FB_BLANK_NORMAL
, 0);
1359 radeon_fifo_wait(31);
1360 for (i
=0; i
<10; i
++)
1361 OUTREG(common_regs
[i
].reg
, common_regs
[i
].val
);
1363 /* Apply surface registers */
1364 for (i
=0; i
<8; i
++) {
1365 OUTREG(SURFACE0_LOWER_BOUND
+ 0x10*i
, mode
->surf_lower_bound
[i
]);
1366 OUTREG(SURFACE0_UPPER_BOUND
+ 0x10*i
, mode
->surf_upper_bound
[i
]);
1367 OUTREG(SURFACE0_INFO
+ 0x10*i
, mode
->surf_info
[i
]);
1370 OUTREG(CRTC_GEN_CNTL
, mode
->crtc_gen_cntl
);
1371 OUTREGP(CRTC_EXT_CNTL
, mode
->crtc_ext_cntl
,
1372 ~(CRTC_HSYNC_DIS
| CRTC_VSYNC_DIS
| CRTC_DISPLAY_DIS
));
1373 OUTREG(CRTC_MORE_CNTL
, mode
->crtc_more_cntl
);
1374 OUTREGP(DAC_CNTL
, mode
->dac_cntl
, DAC_RANGE_CNTL
| DAC_BLANKING
);
1375 OUTREG(CRTC_H_TOTAL_DISP
, mode
->crtc_h_total_disp
);
1376 OUTREG(CRTC_H_SYNC_STRT_WID
, mode
->crtc_h_sync_strt_wid
);
1377 OUTREG(CRTC_V_TOTAL_DISP
, mode
->crtc_v_total_disp
);
1378 OUTREG(CRTC_V_SYNC_STRT_WID
, mode
->crtc_v_sync_strt_wid
);
1379 OUTREG(CRTC_OFFSET
, 0);
1380 OUTREG(CRTC_OFFSET_CNTL
, 0);
1381 OUTREG(CRTC_PITCH
, mode
->crtc_pitch
);
1382 OUTREG(SURFACE_CNTL
, mode
->surface_cntl
);
1384 radeon_write_pll_regs(rinfo
, mode
);
1386 if ((primary_mon
== MT_DFP
) || (primary_mon
== MT_LCD
)) {
1387 radeon_fifo_wait(10);
1388 OUTREG(FP_CRTC_H_TOTAL_DISP
, mode
->fp_crtc_h_total_disp
);
1389 OUTREG(FP_CRTC_V_TOTAL_DISP
, mode
->fp_crtc_v_total_disp
);
1390 OUTREG(FP_H_SYNC_STRT_WID
, mode
->fp_h_sync_strt_wid
);
1391 OUTREG(FP_V_SYNC_STRT_WID
, mode
->fp_v_sync_strt_wid
);
1392 OUTREG(FP_HORZ_STRETCH
, mode
->fp_horz_stretch
);
1393 OUTREG(FP_VERT_STRETCH
, mode
->fp_vert_stretch
);
1394 OUTREG(FP_GEN_CNTL
, mode
->fp_gen_cntl
);
1395 OUTREG(TMDS_CRC
, mode
->tmds_crc
);
1396 OUTREG(TMDS_TRANSMITTER_CNTL
, mode
->tmds_transmitter_cntl
);
1400 radeon_screen_blank(rinfo
, FB_BLANK_UNBLANK
, 0);
1402 radeon_fifo_wait(2);
1403 OUTPLL(VCLK_ECP_CNTL
, mode
->vclk_ecp_cntl
);
1409 * Calculate the PLL values for a given mode
1411 static void radeon_calc_pll_regs(struct radeonfb_info
*rinfo
, struct radeon_regs
*regs
,
1429 int fb_div
, pll_output_freq
= 0;
1432 /* Check if the DVO port is enabled and sourced from the primary CRTC. I'm
1433 * not sure which model starts having FP2_GEN_CNTL, I assume anything more
1434 * recent than an r(v)100...
1437 /* XXX I had reports of flicker happening with the cinema display
1438 * on TMDS1 that seem to be fixed if I also forbit odd dividers in
1439 * this case. This could just be a bandwidth calculation issue, I
1440 * haven't implemented the bandwidth code yet, but in the meantime,
1441 * forcing uses_dvo to 1 fixes it and shouln't have bad side effects,
1442 * I haven't seen a case were were absolutely needed an odd PLL
1443 * divider. I'll find a better fix once I have more infos on the
1444 * real cause of the problem.
1446 while (rinfo
->has_CRTC2
) {
1447 u32 fp2_gen_cntl
= INREG(FP2_GEN_CNTL
);
1448 u32 disp_output_cntl
;
1451 /* FP2 path not enabled */
1452 if ((fp2_gen_cntl
& FP2_ON
) == 0)
1454 /* Not all chip revs have the same format for this register,
1455 * extract the source selection
1457 if (rinfo
->family
== CHIP_FAMILY_R200
||
1458 rinfo
->family
== CHIP_FAMILY_R300
||
1459 rinfo
->family
== CHIP_FAMILY_R350
||
1460 rinfo
->family
== CHIP_FAMILY_RV350
) {
1461 source
= (fp2_gen_cntl
>> 10) & 0x3;
1462 /* sourced from transform unit, check for transform unit
1466 disp_output_cntl
= INREG(DISP_OUTPUT_CNTL
);
1467 source
= (disp_output_cntl
>> 12) & 0x3;
1470 source
= (fp2_gen_cntl
>> 13) & 0x1;
1471 /* sourced from CRTC2 -> exit */
1475 /* so we end up on CRTC1, let's set uses_dvo to 1 now */
1482 if (freq
> rinfo
->pll
.ppll_max
)
1483 freq
= rinfo
->pll
.ppll_max
;
1484 if (freq
*12 < rinfo
->pll
.ppll_min
)
1485 freq
= rinfo
->pll
.ppll_min
/ 12;
1486 RTRACE("freq = %lu, PLL min = %u, PLL max = %u\n",
1487 freq
, rinfo
->pll
.ppll_min
, rinfo
->pll
.ppll_max
);
1489 for (post_div
= &post_divs
[0]; post_div
->divider
; ++post_div
) {
1490 pll_output_freq
= post_div
->divider
* freq
;
1491 /* If we output to the DVO port (external TMDS), we don't allow an
1492 * odd PLL divider as those aren't supported on this path
1494 if (uses_dvo
&& (post_div
->divider
& 1))
1496 if (pll_output_freq
>= rinfo
->pll
.ppll_min
&&
1497 pll_output_freq
<= rinfo
->pll
.ppll_max
)
1501 /* If we fall through the bottom, try the "default value"
1502 given by the terminal post_div->bitvalue */
1503 if ( !post_div
->divider
) {
1504 post_div
= &post_divs
[post_div
->bitvalue
];
1505 pll_output_freq
= post_div
->divider
* freq
;
1507 RTRACE("ref_div = %d, ref_clk = %d, output_freq = %d\n",
1508 rinfo
->pll
.ref_div
, rinfo
->pll
.ref_clk
,
1511 /* If we fall through the bottom, try the "default value"
1512 given by the terminal post_div->bitvalue */
1513 if ( !post_div
->divider
) {
1514 post_div
= &post_divs
[post_div
->bitvalue
];
1515 pll_output_freq
= post_div
->divider
* freq
;
1517 RTRACE("ref_div = %d, ref_clk = %d, output_freq = %d\n",
1518 rinfo
->pll
.ref_div
, rinfo
->pll
.ref_clk
,
1521 fb_div
= round_div(rinfo
->pll
.ref_div
*pll_output_freq
,
1522 rinfo
->pll
.ref_clk
);
1523 regs
->ppll_ref_div
= rinfo
->pll
.ref_div
;
1524 regs
->ppll_div_3
= fb_div
| (post_div
->bitvalue
<< 16);
1526 RTRACE("post div = 0x%x\n", post_div
->bitvalue
);
1527 RTRACE("fb_div = 0x%x\n", fb_div
);
1528 RTRACE("ppll_div_3 = 0x%x\n", regs
->ppll_div_3
);
1531 static int radeonfb_set_par(struct fb_info
*info
)
1533 struct radeonfb_info
*rinfo
= info
->par
;
1534 struct fb_var_screeninfo
*mode
= &info
->var
;
1535 struct radeon_regs
*newmode
;
1536 int hTotal
, vTotal
, hSyncStart
, hSyncEnd
,
1537 hSyncPol
, vSyncStart
, vSyncEnd
, vSyncPol
, cSync
;
1538 u8 hsync_adj_tab
[] = {0, 0x12, 9, 9, 6, 5};
1539 u8 hsync_fudge_fp
[] = {2, 2, 0, 0, 5, 5};
1540 u32 sync
, h_sync_pol
, v_sync_pol
, dotClock
, pixClock
;
1544 int hsync_start
, hsync_fudge
, bytpp
, hsync_wid
, vsync_wid
;
1545 int primary_mon
= PRIMARY_MONITOR(rinfo
);
1546 int depth
= var_to_depth(mode
);
1549 newmode
= kmalloc(sizeof(struct radeon_regs
), GFP_KERNEL
);
1553 /* We always want engine to be idle on a mode switch, even
1554 * if we won't actually change the mode
1556 radeon_engine_idle();
1558 hSyncStart
= mode
->xres
+ mode
->right_margin
;
1559 hSyncEnd
= hSyncStart
+ mode
->hsync_len
;
1560 hTotal
= hSyncEnd
+ mode
->left_margin
;
1562 vSyncStart
= mode
->yres
+ mode
->lower_margin
;
1563 vSyncEnd
= vSyncStart
+ mode
->vsync_len
;
1564 vTotal
= vSyncEnd
+ mode
->upper_margin
;
1565 pixClock
= mode
->pixclock
;
1568 h_sync_pol
= sync
& FB_SYNC_HOR_HIGH_ACT
? 0 : 1;
1569 v_sync_pol
= sync
& FB_SYNC_VERT_HIGH_ACT
? 0 : 1;
1571 if (primary_mon
== MT_DFP
|| primary_mon
== MT_LCD
) {
1572 if (rinfo
->panel_info
.xres
< mode
->xres
)
1573 mode
->xres
= rinfo
->panel_info
.xres
;
1574 if (rinfo
->panel_info
.yres
< mode
->yres
)
1575 mode
->yres
= rinfo
->panel_info
.yres
;
1577 hTotal
= mode
->xres
+ rinfo
->panel_info
.hblank
;
1578 hSyncStart
= mode
->xres
+ rinfo
->panel_info
.hOver_plus
;
1579 hSyncEnd
= hSyncStart
+ rinfo
->panel_info
.hSync_width
;
1581 vTotal
= mode
->yres
+ rinfo
->panel_info
.vblank
;
1582 vSyncStart
= mode
->yres
+ rinfo
->panel_info
.vOver_plus
;
1583 vSyncEnd
= vSyncStart
+ rinfo
->panel_info
.vSync_width
;
1585 h_sync_pol
= !rinfo
->panel_info
.hAct_high
;
1586 v_sync_pol
= !rinfo
->panel_info
.vAct_high
;
1588 pixClock
= 100000000 / rinfo
->panel_info
.clock
;
1590 if (rinfo
->panel_info
.use_bios_dividers
) {
1592 newmode
->ppll_div_3
= rinfo
->panel_info
.fbk_divider
|
1593 (rinfo
->panel_info
.post_divider
<< 16);
1594 newmode
->ppll_ref_div
= rinfo
->panel_info
.ref_divider
;
1597 dotClock
= 1000000000 / pixClock
;
1598 freq
= dotClock
/ 10; /* x100 */
1600 RTRACE("hStart = %d, hEnd = %d, hTotal = %d\n",
1601 hSyncStart
, hSyncEnd
, hTotal
);
1602 RTRACE("vStart = %d, vEnd = %d, vTotal = %d\n",
1603 vSyncStart
, vSyncEnd
, vTotal
);
1605 hsync_wid
= (hSyncEnd
- hSyncStart
) / 8;
1606 vsync_wid
= vSyncEnd
- vSyncStart
;
1609 else if (hsync_wid
> 0x3f) /* max */
1614 else if (vsync_wid
> 0x1f) /* max */
1617 hSyncPol
= mode
->sync
& FB_SYNC_HOR_HIGH_ACT
? 0 : 1;
1618 vSyncPol
= mode
->sync
& FB_SYNC_VERT_HIGH_ACT
? 0 : 1;
1620 cSync
= mode
->sync
& FB_SYNC_COMP_HIGH_ACT
? (1 << 4) : 0;
1622 format
= radeon_get_dstbpp(depth
);
1623 bytpp
= mode
->bits_per_pixel
>> 3;
1625 if ((primary_mon
== MT_DFP
) || (primary_mon
== MT_LCD
))
1626 hsync_fudge
= hsync_fudge_fp
[format
-1];
1628 hsync_fudge
= hsync_adj_tab
[format
-1];
1630 hsync_start
= hSyncStart
- 8 + hsync_fudge
;
1632 newmode
->crtc_gen_cntl
= CRTC_EXT_DISP_EN
| CRTC_EN
|
1635 /* Clear auto-center etc... */
1636 newmode
->crtc_more_cntl
= rinfo
->init_state
.crtc_more_cntl
;
1637 newmode
->crtc_more_cntl
&= 0xfffffff0;
1639 if ((primary_mon
== MT_DFP
) || (primary_mon
== MT_LCD
)) {
1640 newmode
->crtc_ext_cntl
= VGA_ATI_LINEAR
| XCRT_CNT_EN
;
1642 newmode
->crtc_ext_cntl
|= CRTC_CRT_ON
;
1644 newmode
->crtc_gen_cntl
&= ~(CRTC_DBL_SCAN_EN
|
1647 newmode
->crtc_ext_cntl
= VGA_ATI_LINEAR
| XCRT_CNT_EN
|
1651 newmode
->dac_cntl
= /* INREG(DAC_CNTL) | */ DAC_MASK_ALL
| DAC_VGA_ADR_EN
|
1654 newmode
->crtc_h_total_disp
= ((((hTotal
/ 8) - 1) & 0x3ff) |
1655 (((mode
->xres
/ 8) - 1) << 16));
1657 newmode
->crtc_h_sync_strt_wid
= ((hsync_start
& 0x1fff) |
1658 (hsync_wid
<< 16) | (h_sync_pol
<< 23));
1660 newmode
->crtc_v_total_disp
= ((vTotal
- 1) & 0xffff) |
1661 ((mode
->yres
- 1) << 16);
1663 newmode
->crtc_v_sync_strt_wid
= (((vSyncStart
- 1) & 0xfff) |
1664 (vsync_wid
<< 16) | (v_sync_pol
<< 23));
1666 if (!(info
->flags
& FBINFO_HWACCEL_DISABLED
)) {
1667 /* We first calculate the engine pitch */
1668 rinfo
->pitch
= ((mode
->xres_virtual
* ((mode
->bits_per_pixel
+ 1) / 8) + 0x3f)
1671 /* Then, re-multiply it to get the CRTC pitch */
1672 newmode
->crtc_pitch
= (rinfo
->pitch
<< 3) / ((mode
->bits_per_pixel
+ 1) / 8);
1674 newmode
->crtc_pitch
= (mode
->xres_virtual
>> 3);
1676 newmode
->crtc_pitch
|= (newmode
->crtc_pitch
<< 16);
1679 * It looks like recent chips have a problem with SURFACE_CNTL,
1680 * setting SURF_TRANSLATION_DIS completely disables the
1681 * swapper as well, so we leave it unset now.
1683 newmode
->surface_cntl
= 0;
1685 #if defined(__BIG_ENDIAN)
1687 /* Setup swapping on both apertures, though we currently
1688 * only use aperture 0, enabling swapper on aperture 1
1691 switch (mode
->bits_per_pixel
) {
1693 newmode
->surface_cntl
|= NONSURF_AP0_SWP_16BPP
;
1694 newmode
->surface_cntl
|= NONSURF_AP1_SWP_16BPP
;
1698 newmode
->surface_cntl
|= NONSURF_AP0_SWP_32BPP
;
1699 newmode
->surface_cntl
|= NONSURF_AP1_SWP_32BPP
;
1704 /* Clear surface registers */
1705 for (i
=0; i
<8; i
++) {
1706 newmode
->surf_lower_bound
[i
] = 0;
1707 newmode
->surf_upper_bound
[i
] = 0x1f;
1708 newmode
->surf_info
[i
] = 0;
1711 RTRACE("h_total_disp = 0x%x\t hsync_strt_wid = 0x%x\n",
1712 newmode
->crtc_h_total_disp
, newmode
->crtc_h_sync_strt_wid
);
1713 RTRACE("v_total_disp = 0x%x\t vsync_strt_wid = 0x%x\n",
1714 newmode
->crtc_v_total_disp
, newmode
->crtc_v_sync_strt_wid
);
1716 rinfo
->bpp
= mode
->bits_per_pixel
;
1717 rinfo
->depth
= depth
;
1719 RTRACE("pixclock = %lu\n", (unsigned long)pixClock
);
1720 RTRACE("freq = %lu\n", (unsigned long)freq
);
1722 /* We use PPLL_DIV_3 */
1723 newmode
->clk_cntl_index
= 0x300;
1725 /* Calculate PPLL value if necessary */
1727 radeon_calc_pll_regs(rinfo
, newmode
, freq
);
1729 newmode
->vclk_ecp_cntl
= rinfo
->init_state
.vclk_ecp_cntl
;
1731 if ((primary_mon
== MT_DFP
) || (primary_mon
== MT_LCD
)) {
1732 unsigned int hRatio
, vRatio
;
1734 if (mode
->xres
> rinfo
->panel_info
.xres
)
1735 mode
->xres
= rinfo
->panel_info
.xres
;
1736 if (mode
->yres
> rinfo
->panel_info
.yres
)
1737 mode
->yres
= rinfo
->panel_info
.yres
;
1739 newmode
->fp_horz_stretch
= (((rinfo
->panel_info
.xres
/ 8) - 1)
1740 << HORZ_PANEL_SHIFT
);
1741 newmode
->fp_vert_stretch
= ((rinfo
->panel_info
.yres
- 1)
1742 << VERT_PANEL_SHIFT
);
1744 if (mode
->xres
!= rinfo
->panel_info
.xres
) {
1745 hRatio
= round_div(mode
->xres
* HORZ_STRETCH_RATIO_MAX
,
1746 rinfo
->panel_info
.xres
);
1747 newmode
->fp_horz_stretch
= (((((unsigned long)hRatio
) & HORZ_STRETCH_RATIO_MASK
)) |
1748 (newmode
->fp_horz_stretch
&
1749 (HORZ_PANEL_SIZE
| HORZ_FP_LOOP_STRETCH
|
1750 HORZ_AUTO_RATIO_INC
)));
1751 newmode
->fp_horz_stretch
|= (HORZ_STRETCH_BLEND
|
1752 HORZ_STRETCH_ENABLE
);
1755 newmode
->fp_horz_stretch
&= ~HORZ_AUTO_RATIO
;
1757 if (mode
->yres
!= rinfo
->panel_info
.yres
) {
1758 vRatio
= round_div(mode
->yres
* VERT_STRETCH_RATIO_MAX
,
1759 rinfo
->panel_info
.yres
);
1760 newmode
->fp_vert_stretch
= (((((unsigned long)vRatio
) & VERT_STRETCH_RATIO_MASK
)) |
1761 (newmode
->fp_vert_stretch
&
1762 (VERT_PANEL_SIZE
| VERT_STRETCH_RESERVED
)));
1763 newmode
->fp_vert_stretch
|= (VERT_STRETCH_BLEND
|
1764 VERT_STRETCH_ENABLE
);
1767 newmode
->fp_vert_stretch
&= ~VERT_AUTO_RATIO_EN
;
1769 newmode
->fp_gen_cntl
= (rinfo
->init_state
.fp_gen_cntl
& (u32
)
1771 FP_RMX_HVSYNC_CONTROL_EN
|
1776 FP_CRTC_USE_SHADOW_VEND
|
1779 newmode
->fp_gen_cntl
|= (FP_CRTC_DONT_SHADOW_VPAR
|
1780 FP_CRTC_DONT_SHADOW_HEND
|
1783 if (IS_R300_VARIANT(rinfo
) ||
1784 (rinfo
->family
== CHIP_FAMILY_R200
)) {
1785 newmode
->fp_gen_cntl
&= ~R200_FP_SOURCE_SEL_MASK
;
1787 newmode
->fp_gen_cntl
|= R200_FP_SOURCE_SEL_RMX
;
1789 newmode
->fp_gen_cntl
|= R200_FP_SOURCE_SEL_CRTC1
;
1791 newmode
->fp_gen_cntl
|= FP_SEL_CRTC1
;
1793 newmode
->lvds_gen_cntl
= rinfo
->init_state
.lvds_gen_cntl
;
1794 newmode
->lvds_pll_cntl
= rinfo
->init_state
.lvds_pll_cntl
;
1795 newmode
->tmds_crc
= rinfo
->init_state
.tmds_crc
;
1796 newmode
->tmds_transmitter_cntl
= rinfo
->init_state
.tmds_transmitter_cntl
;
1798 if (primary_mon
== MT_LCD
) {
1799 newmode
->lvds_gen_cntl
|= (LVDS_ON
| LVDS_BLON
);
1800 newmode
->fp_gen_cntl
&= ~(FP_FPON
| FP_TMDS_EN
);
1803 newmode
->fp_gen_cntl
|= (FP_FPON
| FP_TMDS_EN
);
1804 newmode
->tmds_transmitter_cntl
&= ~(TMDS_PLLRST
);
1805 /* TMDS_PLL_EN bit is reversed on RV (and mobility) chips */
1806 if (IS_R300_VARIANT(rinfo
) ||
1807 (rinfo
->family
== CHIP_FAMILY_R200
) || !rinfo
->has_CRTC2
)
1808 newmode
->tmds_transmitter_cntl
&= ~TMDS_PLL_EN
;
1810 newmode
->tmds_transmitter_cntl
|= TMDS_PLL_EN
;
1811 newmode
->crtc_ext_cntl
&= ~CRTC_CRT_ON
;
1814 newmode
->fp_crtc_h_total_disp
= (((rinfo
->panel_info
.hblank
/ 8) & 0x3ff) |
1815 (((mode
->xres
/ 8) - 1) << 16));
1816 newmode
->fp_crtc_v_total_disp
= (rinfo
->panel_info
.vblank
& 0xffff) |
1817 ((mode
->yres
- 1) << 16);
1818 newmode
->fp_h_sync_strt_wid
= ((rinfo
->panel_info
.hOver_plus
& 0x1fff) |
1819 (hsync_wid
<< 16) | (h_sync_pol
<< 23));
1820 newmode
->fp_v_sync_strt_wid
= ((rinfo
->panel_info
.vOver_plus
& 0xfff) |
1821 (vsync_wid
<< 16) | (v_sync_pol
<< 23));
1825 if (!rinfo
->asleep
) {
1826 memcpy(&rinfo
->state
, newmode
, sizeof(*newmode
));
1827 radeon_write_mode (rinfo
, newmode
, 0);
1828 /* (re)initialize the engine */
1829 if (!(info
->flags
& FBINFO_HWACCEL_DISABLED
))
1830 radeonfb_engine_init (rinfo
);
1833 if (!(info
->flags
& FBINFO_HWACCEL_DISABLED
))
1834 info
->fix
.line_length
= rinfo
->pitch
*64;
1836 info
->fix
.line_length
= mode
->xres_virtual
1837 * ((mode
->bits_per_pixel
+ 1) / 8);
1838 info
->fix
.visual
= rinfo
->depth
== 8 ? FB_VISUAL_PSEUDOCOLOR
1839 : FB_VISUAL_DIRECTCOLOR
;
1841 #ifdef CONFIG_BOOTX_TEXT
1842 /* Update debug text engine */
1843 btext_update_display(rinfo
->fb_base_phys
, mode
->xres
, mode
->yres
,
1844 rinfo
->depth
, info
->fix
.line_length
);
1852 static struct fb_ops radeonfb_ops
= {
1853 .owner
= THIS_MODULE
,
1854 .fb_check_var
= radeonfb_check_var
,
1855 .fb_set_par
= radeonfb_set_par
,
1856 .fb_setcolreg
= radeonfb_setcolreg
,
1857 .fb_setcmap
= radeonfb_setcmap
,
1858 .fb_pan_display
= radeonfb_pan_display
,
1859 .fb_blank
= radeonfb_blank
,
1860 .fb_ioctl
= radeonfb_ioctl
,
1861 .fb_sync
= radeonfb_sync
,
1862 .fb_fillrect
= radeonfb_fillrect
,
1863 .fb_copyarea
= radeonfb_copyarea
,
1864 .fb_imageblit
= radeonfb_imageblit
,
1868 static int __devinit
radeon_set_fbinfo (struct radeonfb_info
*rinfo
)
1870 struct fb_info
*info
= rinfo
->info
;
1873 info
->pseudo_palette
= rinfo
->pseudo_palette
;
1874 info
->flags
= FBINFO_DEFAULT
1875 | FBINFO_HWACCEL_COPYAREA
1876 | FBINFO_HWACCEL_FILLRECT
1877 | FBINFO_HWACCEL_XPAN
1878 | FBINFO_HWACCEL_YPAN
;
1879 info
->fbops
= &radeonfb_ops
;
1880 info
->screen_base
= rinfo
->fb_base
;
1881 info
->screen_size
= rinfo
->mapped_vram
;
1882 /* Fill fix common fields */
1883 strlcpy(info
->fix
.id
, rinfo
->name
, sizeof(info
->fix
.id
));
1884 info
->fix
.smem_start
= rinfo
->fb_base_phys
;
1885 info
->fix
.smem_len
= rinfo
->video_ram
;
1886 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1887 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
1888 info
->fix
.xpanstep
= 8;
1889 info
->fix
.ypanstep
= 1;
1890 info
->fix
.ywrapstep
= 0;
1891 info
->fix
.type_aux
= 0;
1892 info
->fix
.mmio_start
= rinfo
->mmio_base_phys
;
1893 info
->fix
.mmio_len
= RADEON_REGSIZE
;
1894 info
->fix
.accel
= FB_ACCEL_ATI_RADEON
;
1896 fb_alloc_cmap(&info
->cmap
, 256, 0);
1899 info
->flags
|= FBINFO_HWACCEL_DISABLED
;
1905 * This reconfigure the card's internal memory map. In theory, we'd like
1906 * to setup the card's memory at the same address as it's PCI bus address,
1907 * and the AGP aperture right after that so that system RAM on 32 bits
1908 * machines at least, is directly accessible. However, doing so would
1909 * conflict with the current XFree drivers...
1910 * Ultimately, I hope XFree, GATOS and ATI binary drivers will all agree
1911 * on the proper way to set this up and duplicate this here. In the meantime,
1912 * I put the card's memory at 0 in card space and AGP at some random high
1913 * local (0xe0000000 for now) that will be changed by XFree/DRI anyway
1915 #ifdef CONFIG_PPC_OF
1916 #undef SET_MC_FB_FROM_APERTURE
1917 static void fixup_memory_mappings(struct radeonfb_info
*rinfo
)
1919 u32 save_crtc_gen_cntl
, save_crtc2_gen_cntl
= 0;
1920 u32 save_crtc_ext_cntl
;
1921 u32 aper_base
, aper_size
;
1924 /* First, we disable display to avoid interfering */
1925 if (rinfo
->has_CRTC2
) {
1926 save_crtc2_gen_cntl
= INREG(CRTC2_GEN_CNTL
);
1927 OUTREG(CRTC2_GEN_CNTL
, save_crtc2_gen_cntl
| CRTC2_DISP_REQ_EN_B
);
1929 save_crtc_gen_cntl
= INREG(CRTC_GEN_CNTL
);
1930 save_crtc_ext_cntl
= INREG(CRTC_EXT_CNTL
);
1932 OUTREG(CRTC_EXT_CNTL
, save_crtc_ext_cntl
| CRTC_DISPLAY_DIS
);
1933 OUTREG(CRTC_GEN_CNTL
, save_crtc_gen_cntl
| CRTC_DISP_REQ_EN_B
);
1936 aper_base
= INREG(CONFIG_APER_0_BASE
);
1937 aper_size
= INREG(CONFIG_APER_SIZE
);
1939 #ifdef SET_MC_FB_FROM_APERTURE
1940 /* Set framebuffer to be at the same address as set in PCI BAR */
1941 OUTREG(MC_FB_LOCATION
,
1942 ((aper_base
+ aper_size
- 1) & 0xffff0000) | (aper_base
>> 16));
1943 rinfo
->fb_local_base
= aper_base
;
1945 OUTREG(MC_FB_LOCATION
, 0x7fff0000);
1946 rinfo
->fb_local_base
= 0;
1948 agp_base
= aper_base
+ aper_size
;
1949 if (agp_base
& 0xf0000000)
1950 agp_base
= (aper_base
| 0x0fffffff) + 1;
1952 /* Set AGP to be just after the framebuffer on a 256Mb boundary. This
1953 * assumes the FB isn't mapped to 0xf0000000 or above, but this is
1954 * always the case on PPCs afaik.
1956 #ifdef SET_MC_FB_FROM_APERTURE
1957 OUTREG(MC_AGP_LOCATION
, 0xffff0000 | (agp_base
>> 16));
1959 OUTREG(MC_AGP_LOCATION
, 0xffffe000);
1962 /* Fixup the display base addresses & engine offsets while we
1965 #ifdef SET_MC_FB_FROM_APERTURE
1966 OUTREG(DISPLAY_BASE_ADDR
, aper_base
);
1967 if (rinfo
->has_CRTC2
)
1968 OUTREG(CRTC2_DISPLAY_BASE_ADDR
, aper_base
);
1969 OUTREG(OV0_BASE_ADDR
, aper_base
);
1971 OUTREG(DISPLAY_BASE_ADDR
, 0);
1972 if (rinfo
->has_CRTC2
)
1973 OUTREG(CRTC2_DISPLAY_BASE_ADDR
, 0);
1974 OUTREG(OV0_BASE_ADDR
, 0);
1978 /* Restore display settings */
1979 OUTREG(CRTC_GEN_CNTL
, save_crtc_gen_cntl
);
1980 OUTREG(CRTC_EXT_CNTL
, save_crtc_ext_cntl
);
1981 if (rinfo
->has_CRTC2
)
1982 OUTREG(CRTC2_GEN_CNTL
, save_crtc2_gen_cntl
);
1984 RTRACE("aper_base: %08x MC_FB_LOC to: %08x, MC_AGP_LOC to: %08x\n",
1986 ((aper_base
+ aper_size
- 1) & 0xffff0000) | (aper_base
>> 16),
1987 0xffff0000 | (agp_base
>> 16));
1989 #endif /* CONFIG_PPC_OF */
1992 static void radeon_identify_vram(struct radeonfb_info
*rinfo
)
1996 /* framebuffer size */
1997 if ((rinfo
->family
== CHIP_FAMILY_RS100
) ||
1998 (rinfo
->family
== CHIP_FAMILY_RS200
) ||
1999 (rinfo
->family
== CHIP_FAMILY_RS300
) ||
2000 (rinfo
->family
== CHIP_FAMILY_RS480
) ) {
2001 u32 tom
= INREG(NB_TOM
);
2002 tmp
= ((((tom
>> 16) - (tom
& 0xffff) + 1) << 6) * 1024);
2004 radeon_fifo_wait(6);
2005 OUTREG(MC_FB_LOCATION
, tom
);
2006 OUTREG(DISPLAY_BASE_ADDR
, (tom
& 0xffff) << 16);
2007 OUTREG(CRTC2_DISPLAY_BASE_ADDR
, (tom
& 0xffff) << 16);
2008 OUTREG(OV0_BASE_ADDR
, (tom
& 0xffff) << 16);
2010 /* This is supposed to fix the crtc2 noise problem. */
2011 OUTREG(GRPH2_BUFFER_CNTL
, INREG(GRPH2_BUFFER_CNTL
) & ~0x7f0000);
2013 if ((rinfo
->family
== CHIP_FAMILY_RS100
) ||
2014 (rinfo
->family
== CHIP_FAMILY_RS200
)) {
2015 /* This is to workaround the asic bug for RMX, some versions
2016 of BIOS dosen't have this register initialized correctly.
2018 OUTREGP(CRTC_MORE_CNTL
, CRTC_H_CUTOFF_ACTIVE_EN
,
2019 ~CRTC_H_CUTOFF_ACTIVE_EN
);
2022 tmp
= INREG(CONFIG_MEMSIZE
);
2025 /* mem size is bits [28:0], mask off the rest */
2026 rinfo
->video_ram
= tmp
& CONFIG_MEMSIZE_MASK
;
2029 * Hack to get around some busted production M6's
2032 if (rinfo
->video_ram
== 0) {
2033 switch (rinfo
->pdev
->device
) {
2034 case PCI_CHIP_RADEON_LY
:
2035 case PCI_CHIP_RADEON_LZ
:
2036 rinfo
->video_ram
= 8192 * 1024;
2045 * Now try to identify VRAM type
2047 if (rinfo
->is_IGP
|| (rinfo
->family
>= CHIP_FAMILY_R300
) ||
2048 (INREG(MEM_SDRAM_MODE_REG
) & (1<<30)))
2049 rinfo
->vram_ddr
= 1;
2051 rinfo
->vram_ddr
= 0;
2053 tmp
= INREG(MEM_CNTL
);
2054 if (IS_R300_VARIANT(rinfo
)) {
2055 tmp
&= R300_MEM_NUM_CHANNELS_MASK
;
2057 case 0: rinfo
->vram_width
= 64; break;
2058 case 1: rinfo
->vram_width
= 128; break;
2059 case 2: rinfo
->vram_width
= 256; break;
2060 default: rinfo
->vram_width
= 128; break;
2062 } else if ((rinfo
->family
== CHIP_FAMILY_RV100
) ||
2063 (rinfo
->family
== CHIP_FAMILY_RS100
) ||
2064 (rinfo
->family
== CHIP_FAMILY_RS200
)){
2065 if (tmp
& RV100_MEM_HALF_MODE
)
2066 rinfo
->vram_width
= 32;
2068 rinfo
->vram_width
= 64;
2070 if (tmp
& MEM_NUM_CHANNELS_MASK
)
2071 rinfo
->vram_width
= 128;
2073 rinfo
->vram_width
= 64;
2076 /* This may not be correct, as some cards can have half of channel disabled
2077 * ToDo: identify these cases
2080 RTRACE("radeonfb (%s): Found %ldk of %s %d bits wide videoram\n",
2081 pci_name(rinfo
->pdev
),
2082 rinfo
->video_ram
/ 1024,
2083 rinfo
->vram_ddr
? "DDR" : "SDRAM",
2091 static ssize_t
radeon_show_one_edid(char *buf
, loff_t off
, size_t count
, const u8
*edid
)
2093 if (off
> EDID_LENGTH
)
2096 if (off
+ count
> EDID_LENGTH
)
2097 count
= EDID_LENGTH
- off
;
2099 memcpy(buf
, edid
+ off
, count
);
2105 static ssize_t
radeon_show_edid1(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
2107 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2108 struct pci_dev
*pdev
= to_pci_dev(dev
);
2109 struct fb_info
*info
= pci_get_drvdata(pdev
);
2110 struct radeonfb_info
*rinfo
= info
->par
;
2112 return radeon_show_one_edid(buf
, off
, count
, rinfo
->mon1_EDID
);
2116 static ssize_t
radeon_show_edid2(struct kobject
*kobj
, char *buf
, loff_t off
, size_t count
)
2118 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2119 struct pci_dev
*pdev
= to_pci_dev(dev
);
2120 struct fb_info
*info
= pci_get_drvdata(pdev
);
2121 struct radeonfb_info
*rinfo
= info
->par
;
2123 return radeon_show_one_edid(buf
, off
, count
, rinfo
->mon2_EDID
);
2126 static struct bin_attribute edid1_attr
= {
2129 .owner
= THIS_MODULE
,
2132 .size
= EDID_LENGTH
,
2133 .read
= radeon_show_edid1
,
2136 static struct bin_attribute edid2_attr
= {
2139 .owner
= THIS_MODULE
,
2142 .size
= EDID_LENGTH
,
2143 .read
= radeon_show_edid2
,
2147 static int __devinit
radeonfb_pci_register (struct pci_dev
*pdev
,
2148 const struct pci_device_id
*ent
)
2150 struct fb_info
*info
;
2151 struct radeonfb_info
*rinfo
;
2154 RTRACE("radeonfb_pci_register BEGIN\n");
2156 /* Enable device in PCI config */
2157 ret
= pci_enable_device(pdev
);
2159 printk(KERN_ERR
"radeonfb (%s): Cannot enable PCI device\n",
2164 info
= framebuffer_alloc(sizeof(struct radeonfb_info
), &pdev
->dev
);
2166 printk (KERN_ERR
"radeonfb (%s): could not allocate memory\n",
2175 spin_lock_init(&rinfo
->reg_lock
);
2176 init_timer(&rinfo
->lvds_timer
);
2177 rinfo
->lvds_timer
.function
= radeon_lvds_timer_func
;
2178 rinfo
->lvds_timer
.data
= (unsigned long)rinfo
;
2180 strcpy(rinfo
->name
, "ATI Radeon XX ");
2181 rinfo
->name
[11] = ent
->device
>> 8;
2182 rinfo
->name
[12] = ent
->device
& 0xFF;
2183 rinfo
->family
= ent
->driver_data
& CHIP_FAMILY_MASK
;
2184 rinfo
->chipset
= pdev
->device
;
2185 rinfo
->has_CRTC2
= (ent
->driver_data
& CHIP_HAS_CRTC2
) != 0;
2186 rinfo
->is_mobility
= (ent
->driver_data
& CHIP_IS_MOBILITY
) != 0;
2187 rinfo
->is_IGP
= (ent
->driver_data
& CHIP_IS_IGP
) != 0;
2189 /* Set base addrs */
2190 rinfo
->fb_base_phys
= pci_resource_start (pdev
, 0);
2191 rinfo
->mmio_base_phys
= pci_resource_start (pdev
, 2);
2193 /* request the mem regions */
2194 ret
= pci_request_region(pdev
, 0, "radeonfb framebuffer");
2196 printk( KERN_ERR
"radeonfb (%s): cannot request region 0.\n",
2197 pci_name(rinfo
->pdev
));
2198 goto err_release_fb
;
2201 ret
= pci_request_region(pdev
, 2, "radeonfb mmio");
2203 printk( KERN_ERR
"radeonfb (%s): cannot request region 2.\n",
2204 pci_name(rinfo
->pdev
));
2205 goto err_release_pci0
;
2208 /* map the regions */
2209 rinfo
->mmio_base
= ioremap(rinfo
->mmio_base_phys
, RADEON_REGSIZE
);
2210 if (!rinfo
->mmio_base
) {
2211 printk(KERN_ERR
"radeonfb (%s): cannot map MMIO\n",
2212 pci_name(rinfo
->pdev
));
2214 goto err_release_pci2
;
2217 rinfo
->fb_local_base
= INREG(MC_FB_LOCATION
) << 16;
2223 if (rinfo
->family
== CHIP_FAMILY_R300
&&
2224 (INREG(CONFIG_CNTL
) & CFG_ATI_REV_ID_MASK
)
2226 rinfo
->errata
|= CHIP_ERRATA_R300_CG
;
2228 if (rinfo
->family
== CHIP_FAMILY_RV200
||
2229 rinfo
->family
== CHIP_FAMILY_RS200
)
2230 rinfo
->errata
|= CHIP_ERRATA_PLL_DUMMYREADS
;
2232 if (rinfo
->family
== CHIP_FAMILY_RV100
||
2233 rinfo
->family
== CHIP_FAMILY_RS100
||
2234 rinfo
->family
== CHIP_FAMILY_RS200
)
2235 rinfo
->errata
|= CHIP_ERRATA_PLL_DELAY
;
2237 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
2238 /* On PPC, we obtain the OF device-node pointer to the firmware
2239 * data for this chip
2241 rinfo
->of_node
= pci_device_to_OF_node(pdev
);
2242 if (rinfo
->of_node
== NULL
)
2243 printk(KERN_WARNING
"radeonfb (%s): Cannot match card to OF node !\n",
2244 pci_name(rinfo
->pdev
));
2246 #endif /* CONFIG_PPC_OF || CONFIG_SPARC */
2247 #ifdef CONFIG_PPC_OF
2248 /* On PPC, the firmware sets up a memory mapping that tends
2249 * to cause lockups when enabling the engine. We reconfigure
2250 * the card internal memory mappings properly
2252 fixup_memory_mappings(rinfo
);
2253 #endif /* CONFIG_PPC_OF */
2255 /* Get VRAM size and type */
2256 radeon_identify_vram(rinfo
);
2258 rinfo
->mapped_vram
= min_t(unsigned long, MAX_MAPPED_VRAM
, rinfo
->video_ram
);
2261 rinfo
->fb_base
= ioremap (rinfo
->fb_base_phys
,
2262 rinfo
->mapped_vram
);
2263 } while ( rinfo
->fb_base
== 0 &&
2264 ((rinfo
->mapped_vram
/=2) >= MIN_MAPPED_VRAM
) );
2266 if (rinfo
->fb_base
== NULL
) {
2267 printk (KERN_ERR
"radeonfb (%s): cannot map FB\n",
2268 pci_name(rinfo
->pdev
));
2273 RTRACE("radeonfb (%s): mapped %ldk videoram\n", pci_name(rinfo
->pdev
),
2274 rinfo
->mapped_vram
/1024);
2277 * Map the BIOS ROM if any and retrieve PLL parameters from
2278 * the BIOS. We skip that on mobility chips as the real panel
2279 * values we need aren't in the ROM but in the BIOS image in
2280 * memory. This is definitely not the best meacnism though,
2281 * we really need the arch code to tell us which is the "primary"
2282 * video adapter to use the memory image (or better, the arch
2283 * should provide us a copy of the BIOS image to shield us from
2284 * archs who would store that elsewhere and/or could initialize
2285 * more than one adapter during boot).
2287 if (!rinfo
->is_mobility
)
2288 radeon_map_ROM(rinfo
, pdev
);
2291 * On x86, the primary display on laptop may have it's BIOS
2292 * ROM elsewhere, try to locate it at the legacy memory hole.
2293 * We probably need to make sure this is the primary display,
2294 * but that is difficult without some arch support.
2297 if (rinfo
->bios_seg
== NULL
)
2298 radeon_find_mem_vbios(rinfo
);
2301 /* If both above failed, try the BIOS ROM again for mobility
2304 if (rinfo
->bios_seg
== NULL
&& rinfo
->is_mobility
)
2305 radeon_map_ROM(rinfo
, pdev
);
2307 /* Get informations about the board's PLL */
2308 radeon_get_pllinfo(rinfo
);
2310 #ifdef CONFIG_FB_RADEON_I2C
2311 /* Register I2C bus */
2312 radeon_create_i2c_busses(rinfo
);
2315 /* set all the vital stuff */
2316 radeon_set_fbinfo (rinfo
);
2318 /* Probe screen types */
2319 radeon_probe_screens(rinfo
, monitor_layout
, ignore_edid
);
2321 /* Build mode list, check out panel native model */
2322 radeon_check_modes(rinfo
, mode_option
);
2324 /* Register some sysfs stuff (should be done better) */
2325 if (rinfo
->mon1_EDID
)
2326 sysfs_create_bin_file(&rinfo
->pdev
->dev
.kobj
, &edid1_attr
);
2327 if (rinfo
->mon2_EDID
)
2328 sysfs_create_bin_file(&rinfo
->pdev
->dev
.kobj
, &edid2_attr
);
2330 /* save current mode regs before we switch into the new one
2331 * so we can restore this upon __exit
2333 radeon_save_state (rinfo
, &rinfo
->init_state
);
2334 memcpy(&rinfo
->state
, &rinfo
->init_state
, sizeof(struct radeon_regs
));
2336 /* Setup Power Management capabilities */
2337 if (default_dynclk
< -1) {
2338 /* -2 is special: means ON on mobility chips and do not
2341 radeonfb_pm_init(rinfo
, rinfo
->is_mobility
? 1 : -1, ignore_devlist
, force_sleep
);
2343 radeonfb_pm_init(rinfo
, default_dynclk
, ignore_devlist
, force_sleep
);
2345 pci_set_drvdata(pdev
, info
);
2347 /* Register with fbdev layer */
2348 ret
= register_framebuffer(info
);
2350 printk (KERN_ERR
"radeonfb (%s): could not register framebuffer\n",
2351 pci_name(rinfo
->pdev
));
2356 rinfo
->mtrr_hdl
= nomtrr
? -1 : mtrr_add(rinfo
->fb_base_phys
,
2358 MTRR_TYPE_WRCOMB
, 1);
2362 radeonfb_bl_init(rinfo
);
2364 printk ("radeonfb (%s): %s\n", pci_name(rinfo
->pdev
), rinfo
->name
);
2366 if (rinfo
->bios_seg
)
2367 radeon_unmap_ROM(rinfo
, pdev
);
2368 RTRACE("radeonfb_pci_register END\n");
2372 iounmap(rinfo
->fb_base
);
2374 kfree(rinfo
->mon1_EDID
);
2375 kfree(rinfo
->mon2_EDID
);
2376 if (rinfo
->mon1_modedb
)
2377 fb_destroy_modedb(rinfo
->mon1_modedb
);
2378 fb_dealloc_cmap(&info
->cmap
);
2379 #ifdef CONFIG_FB_RADEON_I2C
2380 radeon_delete_i2c_busses(rinfo
);
2382 if (rinfo
->bios_seg
)
2383 radeon_unmap_ROM(rinfo
, pdev
);
2384 iounmap(rinfo
->mmio_base
);
2386 pci_release_region(pdev
, 2);
2388 pci_release_region(pdev
, 0);
2390 framebuffer_release(info
);
2398 static void __devexit
radeonfb_pci_unregister (struct pci_dev
*pdev
)
2400 struct fb_info
*info
= pci_get_drvdata(pdev
);
2401 struct radeonfb_info
*rinfo
= info
->par
;
2406 radeonfb_pm_exit(rinfo
);
2408 if (rinfo
->mon1_EDID
)
2409 sysfs_remove_bin_file(&rinfo
->pdev
->dev
.kobj
, &edid1_attr
);
2410 if (rinfo
->mon2_EDID
)
2411 sysfs_remove_bin_file(&rinfo
->pdev
->dev
.kobj
, &edid2_attr
);
2414 /* restore original state
2416 * Doesn't quite work yet, I suspect if we come from a legacy
2417 * VGA mode (or worse, text mode), we need to do some VGA black
2418 * magic here that I know nothing about. --BenH
2420 radeon_write_mode (rinfo
, &rinfo
->init_state
, 1);
2423 del_timer_sync(&rinfo
->lvds_timer
);
2426 if (rinfo
->mtrr_hdl
>= 0)
2427 mtrr_del(rinfo
->mtrr_hdl
, 0, 0);
2430 unregister_framebuffer(info
);
2432 radeonfb_bl_exit(rinfo
);
2434 iounmap(rinfo
->mmio_base
);
2435 iounmap(rinfo
->fb_base
);
2437 pci_release_region(pdev
, 2);
2438 pci_release_region(pdev
, 0);
2440 kfree(rinfo
->mon1_EDID
);
2441 kfree(rinfo
->mon2_EDID
);
2442 if (rinfo
->mon1_modedb
)
2443 fb_destroy_modedb(rinfo
->mon1_modedb
);
2444 #ifdef CONFIG_FB_RADEON_I2C
2445 radeon_delete_i2c_busses(rinfo
);
2447 fb_dealloc_cmap(&info
->cmap
);
2448 framebuffer_release(info
);
2452 static struct pci_driver radeonfb_driver
= {
2454 .id_table
= radeonfb_pci_table
,
2455 .probe
= radeonfb_pci_register
,
2456 .remove
= __devexit_p(radeonfb_pci_unregister
),
2458 .suspend
= radeonfb_pci_suspend
,
2459 .resume
= radeonfb_pci_resume
,
2460 #endif /* CONFIG_PM */
2464 static int __init
radeonfb_setup (char *options
)
2468 if (!options
|| !*options
)
2471 while ((this_opt
= strsep (&options
, ",")) != NULL
) {
2475 if (!strncmp(this_opt
, "noaccel", 7)) {
2477 } else if (!strncmp(this_opt
, "mirror", 6)) {
2479 } else if (!strncmp(this_opt
, "force_dfp", 9)) {
2481 } else if (!strncmp(this_opt
, "panel_yres:", 11)) {
2482 panel_yres
= simple_strtoul((this_opt
+11), NULL
, 0);
2483 } else if (!strncmp(this_opt
, "backlight:", 10)) {
2484 backlight
= simple_strtoul(this_opt
+10, NULL
, 0);
2486 } else if (!strncmp(this_opt
, "nomtrr", 6)) {
2489 } else if (!strncmp(this_opt
, "nomodeset", 9)) {
2491 } else if (!strncmp(this_opt
, "force_measure_pll", 17)) {
2492 force_measure_pll
= 1;
2493 } else if (!strncmp(this_opt
, "ignore_edid", 11)) {
2495 #if defined(CONFIG_PM) && defined(CONFIG_X86)
2496 } else if (!strncmp(this_opt
, "force_sleep", 11)) {
2498 } else if (!strncmp(this_opt
, "ignore_devlist", 14)) {
2502 mode_option
= this_opt
;
2508 static int __init
radeonfb_init (void)
2511 char *option
= NULL
;
2513 if (fb_get_options("radeonfb", &option
))
2515 radeonfb_setup(option
);
2517 return pci_register_driver (&radeonfb_driver
);
2521 static void __exit
radeonfb_exit (void)
2523 pci_unregister_driver (&radeonfb_driver
);
2526 module_init(radeonfb_init
);
2527 module_exit(radeonfb_exit
);
2529 MODULE_AUTHOR("Ani Joshi");
2530 MODULE_DESCRIPTION("framebuffer driver for ATI Radeon chipset");
2531 MODULE_LICENSE("GPL");
2532 module_param(noaccel
, bool, 0);
2533 module_param(default_dynclk
, int, 0);
2534 MODULE_PARM_DESC(default_dynclk
, "int: -2=enable on mobility only,-1=do not change,0=off,1=on");
2535 MODULE_PARM_DESC(noaccel
, "bool: disable acceleration");
2536 module_param(nomodeset
, bool, 0);
2537 MODULE_PARM_DESC(nomodeset
, "bool: disable actual setting of video mode");
2538 module_param(mirror
, bool, 0);
2539 MODULE_PARM_DESC(mirror
, "bool: mirror the display to both monitors");
2540 module_param(force_dfp
, bool, 0);
2541 MODULE_PARM_DESC(force_dfp
, "bool: force display to dfp");
2542 module_param(ignore_edid
, bool, 0);
2543 MODULE_PARM_DESC(ignore_edid
, "bool: Ignore EDID data when doing DDC probe");
2544 module_param(monitor_layout
, charp
, 0);
2545 MODULE_PARM_DESC(monitor_layout
, "Specify monitor mapping (like XFree86)");
2546 module_param(force_measure_pll
, bool, 0);
2547 MODULE_PARM_DESC(force_measure_pll
, "Force measurement of PLL (debug)");
2549 module_param(nomtrr
, bool, 0);
2550 MODULE_PARM_DESC(nomtrr
, "bool: disable use of MTRR registers");
2552 module_param(panel_yres
, int, 0);
2553 MODULE_PARM_DESC(panel_yres
, "int: set panel yres");
2554 module_param(mode_option
, charp
, 0);
2555 MODULE_PARM_DESC(mode_option
, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
2556 #if defined(CONFIG_PM) && defined(CONFIG_X86)
2557 module_param(force_sleep
, bool, 0);
2558 MODULE_PARM_DESC(force_sleep
, "bool: force D2 sleep mode on all hardware");
2559 module_param(ignore_devlist
, bool, 0);
2560 MODULE_PARM_DESC(ignore_devlist
, "bool: ignore workarounds for bugs in specific laptops");