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"
57 #include <linux/module.h>
58 #include <linux/moduleparam.h>
59 #include <linux/kernel.h>
60 #include <linux/errno.h>
61 #include <linux/string.h>
62 #include <linux/ctype.h>
64 #include <linux/slab.h>
65 #include <linux/delay.h>
66 #include <linux/time.h>
68 #include <linux/ioport.h>
69 #include <linux/init.h>
70 #include <linux/pci.h>
71 #include <linux/vmalloc.h>
72 #include <linux/device.h>
75 #include <linux/uaccess.h>
79 #include <asm/pci-bridge.h>
80 #include "../macmodes.h"
82 #ifdef CONFIG_BOOTX_TEXT
83 #include <asm/btext.h>
86 #endif /* CONFIG_PPC */
88 #include <video/radeon.h>
89 #include <linux/radeonfb.h>
91 #include "../edid.h" // MOVE THAT TO include/video
94 #define MAX_MAPPED_VRAM (2048*2048*4)
95 #define MIN_MAPPED_VRAM (1024*768*1)
97 #define CHIP_DEF(id, family, flags) \
98 { PCI_VENDOR_ID_ATI, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (flags) | (CHIP_FAMILY_##family) }
100 static struct pci_device_id radeonfb_pci_table[] = {
101 /* Radeon Xpress 200m */
102 CHIP_DEF(PCI_CHIP_RS480_5955, RS480, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
103 CHIP_DEF(PCI_CHIP_RS482_5975, RS480, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
105 CHIP_DEF(PCI_CHIP_RADEON_LY, RV100, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
106 CHIP_DEF(PCI_CHIP_RADEON_LZ, RV100, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
108 CHIP_DEF(PCI_CHIP_RV100_QY, RV100, CHIP_HAS_CRTC2),
109 CHIP_DEF(PCI_CHIP_RV100_QZ, RV100, CHIP_HAS_CRTC2),
110 CHIP_DEF(PCI_CHIP_RN50, RV100, CHIP_HAS_CRTC2),
111 /* Radeon IGP320M (U1) */
112 CHIP_DEF(PCI_CHIP_RS100_4336, RS100, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
113 /* Radeon IGP320 (A3) */
114 CHIP_DEF(PCI_CHIP_RS100_4136, RS100, CHIP_HAS_CRTC2 | CHIP_IS_IGP),
115 /* IGP330M/340M/350M (U2) */
116 CHIP_DEF(PCI_CHIP_RS200_4337, RS200, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
117 /* IGP330/340/350 (A4) */
118 CHIP_DEF(PCI_CHIP_RS200_4137, RS200, CHIP_HAS_CRTC2 | CHIP_IS_IGP),
119 /* Mobility 7000 IGP */
120 CHIP_DEF(PCI_CHIP_RS250_4437, RS200, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
122 CHIP_DEF(PCI_CHIP_RS250_4237, RS200, CHIP_HAS_CRTC2 | CHIP_IS_IGP),
124 CHIP_DEF(PCI_CHIP_R200_BB, R200, CHIP_HAS_CRTC2),
125 CHIP_DEF(PCI_CHIP_R200_BC, R200, CHIP_HAS_CRTC2),
127 CHIP_DEF(PCI_CHIP_R200_QH, R200, CHIP_HAS_CRTC2),
129 CHIP_DEF(PCI_CHIP_R200_QL, R200, CHIP_HAS_CRTC2),
131 CHIP_DEF(PCI_CHIP_R200_QM, R200, CHIP_HAS_CRTC2),
133 CHIP_DEF(PCI_CHIP_RADEON_LW, RV200, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
134 CHIP_DEF(PCI_CHIP_RADEON_LX, RV200, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
136 CHIP_DEF(PCI_CHIP_RV200_QW, RV200, CHIP_HAS_CRTC2),
137 CHIP_DEF(PCI_CHIP_RV200_QX, RV200, CHIP_HAS_CRTC2),
139 CHIP_DEF(PCI_CHIP_RV250_Ld, RV250, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
140 CHIP_DEF(PCI_CHIP_RV250_Le, RV250, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
141 CHIP_DEF(PCI_CHIP_RV250_Lf, RV250, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
142 CHIP_DEF(PCI_CHIP_RV250_Lg, RV250, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
144 CHIP_DEF(PCI_CHIP_RV250_If, RV250, CHIP_HAS_CRTC2),
145 CHIP_DEF(PCI_CHIP_RV250_Ig, RV250, CHIP_HAS_CRTC2),
147 CHIP_DEF(PCI_CHIP_RC410_5A62, RC410, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
148 /* Mobility 9100 IGP (U3) */
149 CHIP_DEF(PCI_CHIP_RS300_5835, RS300, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
150 CHIP_DEF(PCI_CHIP_RS350_7835, RS300, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
152 CHIP_DEF(PCI_CHIP_RS300_5834, RS300, CHIP_HAS_CRTC2 | CHIP_IS_IGP),
153 CHIP_DEF(PCI_CHIP_RS350_7834, RS300, CHIP_HAS_CRTC2 | CHIP_IS_IGP),
154 /* Mobility 9200 (M9+) */
155 CHIP_DEF(PCI_CHIP_RV280_5C61, RV280, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
156 CHIP_DEF(PCI_CHIP_RV280_5C63, RV280, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
158 CHIP_DEF(PCI_CHIP_RV280_5960, RV280, CHIP_HAS_CRTC2),
159 CHIP_DEF(PCI_CHIP_RV280_5961, RV280, CHIP_HAS_CRTC2),
160 CHIP_DEF(PCI_CHIP_RV280_5962, RV280, CHIP_HAS_CRTC2),
161 CHIP_DEF(PCI_CHIP_RV280_5964, RV280, CHIP_HAS_CRTC2),
163 CHIP_DEF(PCI_CHIP_R300_AD, R300, CHIP_HAS_CRTC2),
164 CHIP_DEF(PCI_CHIP_R300_AE, R300, CHIP_HAS_CRTC2),
165 /* 9600TX / FireGL Z1 */
166 CHIP_DEF(PCI_CHIP_R300_AF, R300, CHIP_HAS_CRTC2),
167 CHIP_DEF(PCI_CHIP_R300_AG, R300, CHIP_HAS_CRTC2),
168 /* 9700/9500/Pro/FireGL X1 */
169 CHIP_DEF(PCI_CHIP_R300_ND, R300, CHIP_HAS_CRTC2),
170 CHIP_DEF(PCI_CHIP_R300_NE, R300, CHIP_HAS_CRTC2),
171 CHIP_DEF(PCI_CHIP_R300_NF, R300, CHIP_HAS_CRTC2),
172 CHIP_DEF(PCI_CHIP_R300_NG, R300, CHIP_HAS_CRTC2),
173 /* Mobility M10/M11 */
174 CHIP_DEF(PCI_CHIP_RV350_NP, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
175 CHIP_DEF(PCI_CHIP_RV350_NQ, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
176 CHIP_DEF(PCI_CHIP_RV350_NR, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
177 CHIP_DEF(PCI_CHIP_RV350_NS, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
178 CHIP_DEF(PCI_CHIP_RV350_NT, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
179 CHIP_DEF(PCI_CHIP_RV350_NV, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
181 CHIP_DEF(PCI_CHIP_RV350_AP, RV350, CHIP_HAS_CRTC2),
182 CHIP_DEF(PCI_CHIP_RV350_AQ, RV350, CHIP_HAS_CRTC2),
183 CHIP_DEF(PCI_CHIP_RV360_AR, RV350, CHIP_HAS_CRTC2),
184 CHIP_DEF(PCI_CHIP_RV350_AS, RV350, CHIP_HAS_CRTC2),
185 CHIP_DEF(PCI_CHIP_RV350_AT, RV350, CHIP_HAS_CRTC2),
186 CHIP_DEF(PCI_CHIP_RV350_AV, RV350, CHIP_HAS_CRTC2),
187 /* 9800/Pro/FileGL X2 */
188 CHIP_DEF(PCI_CHIP_R350_AH, R350, CHIP_HAS_CRTC2),
189 CHIP_DEF(PCI_CHIP_R350_AI, R350, CHIP_HAS_CRTC2),
190 CHIP_DEF(PCI_CHIP_R350_AJ, R350, CHIP_HAS_CRTC2),
191 CHIP_DEF(PCI_CHIP_R350_AK, R350, CHIP_HAS_CRTC2),
192 CHIP_DEF(PCI_CHIP_R350_NH, R350, CHIP_HAS_CRTC2),
193 CHIP_DEF(PCI_CHIP_R350_NI, R350, CHIP_HAS_CRTC2),
194 CHIP_DEF(PCI_CHIP_R360_NJ, R350, CHIP_HAS_CRTC2),
195 CHIP_DEF(PCI_CHIP_R350_NK, R350, CHIP_HAS_CRTC2),
197 CHIP_DEF(PCI_CHIP_RV380_3E50, RV380, CHIP_HAS_CRTC2),
198 CHIP_DEF(PCI_CHIP_RV380_3E54, RV380, CHIP_HAS_CRTC2),
199 CHIP_DEF(PCI_CHIP_RV380_3150, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
200 CHIP_DEF(PCI_CHIP_RV380_3154, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
201 CHIP_DEF(PCI_CHIP_RV370_5B60, RV380, CHIP_HAS_CRTC2),
202 CHIP_DEF(PCI_CHIP_RV370_5B62, RV380, CHIP_HAS_CRTC2),
203 CHIP_DEF(PCI_CHIP_RV370_5B63, RV380, CHIP_HAS_CRTC2),
204 CHIP_DEF(PCI_CHIP_RV370_5B64, RV380, CHIP_HAS_CRTC2),
205 CHIP_DEF(PCI_CHIP_RV370_5B65, RV380, CHIP_HAS_CRTC2),
206 CHIP_DEF(PCI_CHIP_RV370_5460, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
207 CHIP_DEF(PCI_CHIP_RV370_5464, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
208 CHIP_DEF(PCI_CHIP_R420_JH, R420, CHIP_HAS_CRTC2),
209 CHIP_DEF(PCI_CHIP_R420_JI, R420, CHIP_HAS_CRTC2),
210 CHIP_DEF(PCI_CHIP_R420_JJ, R420, CHIP_HAS_CRTC2),
211 CHIP_DEF(PCI_CHIP_R420_JK, R420, CHIP_HAS_CRTC2),
212 CHIP_DEF(PCI_CHIP_R420_JL, R420, CHIP_HAS_CRTC2),
213 CHIP_DEF(PCI_CHIP_R420_JM, R420, CHIP_HAS_CRTC2),
214 CHIP_DEF(PCI_CHIP_R420_JN, R420, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
215 CHIP_DEF(PCI_CHIP_R420_JP, R420, CHIP_HAS_CRTC2),
216 CHIP_DEF(PCI_CHIP_R423_UH, R420, CHIP_HAS_CRTC2),
217 CHIP_DEF(PCI_CHIP_R423_UI, R420, CHIP_HAS_CRTC2),
218 CHIP_DEF(PCI_CHIP_R423_UJ, R420, CHIP_HAS_CRTC2),
219 CHIP_DEF(PCI_CHIP_R423_UK, R420, CHIP_HAS_CRTC2),
220 CHIP_DEF(PCI_CHIP_R423_UQ, R420, CHIP_HAS_CRTC2),
221 CHIP_DEF(PCI_CHIP_R423_UR, R420, CHIP_HAS_CRTC2),
222 CHIP_DEF(PCI_CHIP_R423_UT, R420, CHIP_HAS_CRTC2),
223 CHIP_DEF(PCI_CHIP_R423_5D57, R420, CHIP_HAS_CRTC2),
224 /* Original Radeon/7200 */
225 CHIP_DEF(PCI_CHIP_RADEON_QD, RADEON, 0),
226 CHIP_DEF(PCI_CHIP_RADEON_QE, RADEON, 0),
227 CHIP_DEF(PCI_CHIP_RADEON_QF, RADEON, 0),
228 CHIP_DEF(PCI_CHIP_RADEON_QG, RADEON, 0),
231 MODULE_DEVICE_TABLE(pci, radeonfb_pci_table);
240 /* these common regs are cleared before mode setting so they do not
241 * interfere with anything
243 static reg_val common_regs[] = {
245 { OVR_WID_LEFT_RIGHT, 0 },
246 { OVR_WID_TOP_BOTTOM, 0 },
247 { OV0_SCALE_CNTL, 0 },
252 { CAP0_TRIG_CNTL, 0 },
253 { CAP1_TRIG_CNTL, 0 },
260 static char *mode_option;
261 static char *monitor_layout;
262 static bool noaccel = 0;
263 static int default_dynclk = -2;
264 static bool nomodeset = 0;
265 static bool ignore_edid = 0;
266 static bool mirror = 0;
267 static int panel_yres = 0;
268 static bool force_dfp = 0;
269 static bool force_measure_pll = 0;
270 static bool nomtrr = 0;
271 static bool force_sleep;
272 static bool ignore_devlist;
273 #ifdef CONFIG_PMAC_BACKLIGHT
274 static int backlight = 1;
276 static int backlight = 0;
279 /* Note about this function: we have some rare cases where we must not schedule,
280 * this typically happen with our special "wake up early" hook which allows us to
281 * wake up the graphic chip (and thus get the console back) before everything else
282 * on some machines that support that mechanism. At this point, interrupts are off
283 * and scheduling is not permitted
285 void _radeon_msleep(struct radeonfb_info *rinfo, unsigned long ms)
287 if (rinfo->no_schedule || oops_in_progress)
293 void radeon_pll_errata_after_index_slow(struct radeonfb_info *rinfo)
295 /* Called if (rinfo->errata & CHIP_ERRATA_PLL_DUMMYREADS) is set */
296 (void)INREG(CLOCK_CNTL_DATA);
297 (void)INREG(CRTC_GEN_CNTL);
300 void radeon_pll_errata_after_data_slow(struct radeonfb_info *rinfo)
302 if (rinfo->errata & CHIP_ERRATA_PLL_DELAY) {
303 /* we can't deal with posted writes here ... */
304 _radeon_msleep(rinfo, 5);
306 if (rinfo->errata & CHIP_ERRATA_R300_CG) {
308 save = INREG(CLOCK_CNTL_INDEX);
309 tmp = save & ~(0x3f | PLL_WR_EN);
310 OUTREG(CLOCK_CNTL_INDEX, tmp);
311 tmp = INREG(CLOCK_CNTL_DATA);
312 OUTREG(CLOCK_CNTL_INDEX, save);
316 void _OUTREGP(struct radeonfb_info *rinfo, u32 addr, u32 val, u32 mask)
321 spin_lock_irqsave(&rinfo->reg_lock, flags);
326 spin_unlock_irqrestore(&rinfo->reg_lock, flags);
329 u32 __INPLL(struct radeonfb_info *rinfo, u32 addr)
333 OUTREG8(CLOCK_CNTL_INDEX, addr & 0x0000003f);
334 radeon_pll_errata_after_index(rinfo);
335 data = INREG(CLOCK_CNTL_DATA);
336 radeon_pll_errata_after_data(rinfo);
340 void __OUTPLL(struct radeonfb_info *rinfo, unsigned int index, u32 val)
342 OUTREG8(CLOCK_CNTL_INDEX, (index & 0x0000003f) | 0x00000080);
343 radeon_pll_errata_after_index(rinfo);
344 OUTREG(CLOCK_CNTL_DATA, val);
345 radeon_pll_errata_after_data(rinfo);
348 void __OUTPLLP(struct radeonfb_info *rinfo, unsigned int index,
353 tmp = __INPLL(rinfo, index);
356 __OUTPLL(rinfo, index, tmp);
359 void _radeon_fifo_wait(struct radeonfb_info *rinfo, int entries)
363 for (i=0; i<2000000; i++) {
364 if ((INREG(RBBM_STATUS) & 0x7f) >= entries)
368 printk(KERN_ERR "radeonfb: FIFO Timeout !\n");
371 void radeon_engine_flush(struct radeonfb_info *rinfo)
376 OUTREGP(DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL,
379 /* Ensure FIFO is empty, ie, make sure the flush commands
380 * has reached the cache
382 _radeon_fifo_wait(rinfo, 64);
384 /* Wait for the flush to complete */
385 for (i=0; i < 2000000; i++) {
386 if (!(INREG(DSTCACHE_CTLSTAT) & RB2D_DC_BUSY))
390 printk(KERN_ERR "radeonfb: Flush Timeout !\n");
393 void _radeon_engine_idle(struct radeonfb_info *rinfo)
397 /* ensure FIFO is empty before waiting for idle */
398 _radeon_fifo_wait(rinfo, 64);
400 for (i=0; i<2000000; i++) {
401 if (((INREG(RBBM_STATUS) & GUI_ACTIVE)) == 0) {
402 radeon_engine_flush(rinfo);
407 printk(KERN_ERR "radeonfb: Idle Timeout !\n");
412 static void radeon_unmap_ROM(struct radeonfb_info *rinfo, struct pci_dev *dev)
414 if (!rinfo->bios_seg)
416 pci_unmap_rom(dev, rinfo->bios_seg);
419 static int radeon_map_ROM(struct radeonfb_info *rinfo, struct pci_dev *dev)
426 /* If this is a primary card, there is a shadow copy of the
427 * ROM somewhere in the first meg. We will just ignore the copy
428 * and use the ROM directly.
431 /* Fix from ATI for problem with Radeon hardware not leaving ROM enabled */
433 temp = INREG(MPP_TB_CONFIG);
436 OUTREG(MPP_TB_CONFIG, temp);
437 temp = INREG(MPP_TB_CONFIG);
439 rom = pci_map_rom(dev, &rom_size);
441 printk(KERN_ERR "radeonfb (%s): ROM failed to map\n",
442 pci_name(rinfo->pdev));
446 rinfo->bios_seg = rom;
448 /* Very simple test to make sure it appeared */
449 if (BIOS_IN16(0) != 0xaa55) {
450 printk(KERN_DEBUG "radeonfb (%s): Invalid ROM signature %x "
451 "should be 0xaa55\n",
452 pci_name(rinfo->pdev), BIOS_IN16(0));
455 /* Look for the PCI data to check the ROM type */
456 dptr = BIOS_IN16(0x18);
458 /* Check the PCI data signature. If it's wrong, we still assume a normal x86 ROM
459 * for now, until I've verified this works everywhere. The goal here is more
460 * to phase out Open Firmware images.
462 * Currently, we only look at the first PCI data, we could iteratre and deal with
463 * them all, and we should use fb_bios_start relative to start of image and not
464 * relative start of ROM, but so far, I never found a dual-image ATI card
467 * u32 signature; + 0x00
470 * u16 reserved_1; + 0x08
472 * u8 drevision; + 0x0c
473 * u8 class_hi; + 0x0d
474 * u16 class_lo; + 0x0e
476 * u16 irevision; + 0x12
478 * u8 indicator; + 0x15
479 * u16 reserved_2; + 0x16
482 if (BIOS_IN32(dptr) != (('R' << 24) | ('I' << 16) | ('C' << 8) | 'P')) {
483 printk(KERN_WARNING "radeonfb (%s): PCI DATA signature in ROM"
484 "incorrect: %08x\n", pci_name(rinfo->pdev), BIOS_IN32(dptr));
487 rom_type = BIOS_IN8(dptr + 0x14);
490 printk(KERN_INFO "radeonfb: Found Intel x86 BIOS ROM Image\n");
493 printk(KERN_INFO "radeonfb: Found Open Firmware ROM Image\n");
496 printk(KERN_INFO "radeonfb: Found HP PA-RISC ROM Image\n");
499 printk(KERN_INFO "radeonfb: Found unknown type %d ROM Image\n", rom_type);
503 /* Locate the flat panel infos, do some sanity checking !!! */
504 rinfo->fp_bios_start = BIOS_IN16(0x48);
508 rinfo->bios_seg = NULL;
509 radeon_unmap_ROM(rinfo, dev);
514 static int radeon_find_mem_vbios(struct radeonfb_info *rinfo)
516 /* I simplified this code as we used to miss the signatures in
517 * a lot of case. It's now closer to XFree, we just don't check
518 * for signatures at all... Something better will have to be done
519 * if we end up having conflicts
522 void __iomem *rom_base = NULL;
524 for(segstart=0x000c0000; segstart<0x000f0000; segstart+=0x00001000) {
525 rom_base = ioremap(segstart, 0x10000);
526 if (rom_base == NULL)
528 if (readb(rom_base) == 0x55 && readb(rom_base + 1) == 0xaa)
533 if (rom_base == NULL)
536 /* Locate the flat panel infos, do some sanity checking !!! */
537 rinfo->bios_seg = rom_base;
538 rinfo->fp_bios_start = BIOS_IN16(0x48);
544 #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
546 * Read XTAL (ref clock), SCLK and MCLK from Open Firmware device
547 * tree. Hopefully, ATI OF driver is kind enough to fill these
549 static int radeon_read_xtal_OF(struct radeonfb_info *rinfo)
551 struct device_node *dp = rinfo->of_node;
556 val = of_get_property(dp, "ATY,RefCLK", NULL);
558 printk(KERN_WARNING "radeonfb: No ATY,RefCLK property !\n");
562 rinfo->pll.ref_clk = (*val) / 10;
564 val = of_get_property(dp, "ATY,SCLK", NULL);
566 rinfo->pll.sclk = (*val) / 10;
568 val = of_get_property(dp, "ATY,MCLK", NULL);
570 rinfo->pll.mclk = (*val) / 10;
574 #endif /* CONFIG_PPC || CONFIG_SPARC */
577 * Read PLL infos from chip registers
579 static int radeon_probe_pll_params(struct radeonfb_info *rinfo)
581 unsigned char ppll_div_sel;
583 unsigned sclk, mclk, tmp, ref_div;
584 int hTotal, vTotal, num, denom, m, n;
585 unsigned long long hz, vclk;
587 struct timeval start_tv, stop_tv;
588 long total_secs, total_usecs;
591 /* Ugh, we cut interrupts, bad bad bad, but we want some precision
595 /* Flush PCI buffers ? */
596 tmp = INREG16(DEVICE_ID);
600 for(i=0; i<1000000; i++)
601 if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) == 0)
604 do_gettimeofday(&start_tv);
606 for(i=0; i<1000000; i++)
607 if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) != 0)
610 for(i=0; i<1000000; i++)
611 if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) == 0)
614 do_gettimeofday(&stop_tv);
618 total_secs = stop_tv.tv_sec - start_tv.tv_sec;
621 total_usecs = stop_tv.tv_usec - start_tv.tv_usec;
622 total_usecs += total_secs * 1000000;
624 total_usecs = -total_usecs;
625 hz = 1000000/total_usecs;
627 hTotal = ((INREG(CRTC_H_TOTAL_DISP) & 0x1ff) + 1) * 8;
628 vTotal = ((INREG(CRTC_V_TOTAL_DISP) & 0x3ff) + 1);
629 vclk = (long long)hTotal * (long long)vTotal * hz;
631 switch((INPLL(PPLL_REF_DIV) & 0x30000) >> 16) {
638 n = ((INPLL(M_SPLL_REF_FB_DIV) >> 16) & 0xff);
639 m = (INPLL(M_SPLL_REF_FB_DIV) & 0xff);
644 n = ((INPLL(M_SPLL_REF_FB_DIV) >> 8) & 0xff);
645 m = (INPLL(M_SPLL_REF_FB_DIV) & 0xff);
651 ppll_div_sel = INREG8(CLOCK_CNTL_INDEX + 1) & 0x3;
652 radeon_pll_errata_after_index(rinfo);
654 n = (INPLL(PPLL_DIV_0 + ppll_div_sel) & 0x7ff);
655 m = (INPLL(PPLL_REF_DIV) & 0x3ff);
660 switch ((INPLL(PPLL_DIV_0 + ppll_div_sel) >> 16) & 0x7) {
682 do_div(vclk, 1000 * num);
685 if ((xtal > 26900) && (xtal < 27100))
687 else if ((xtal > 14200) && (xtal < 14400))
689 else if ((xtal > 29400) && (xtal < 29600))
692 printk(KERN_WARNING "xtal calculation failed: %ld\n", xtal);
696 tmp = INPLL(M_SPLL_REF_FB_DIV);
697 ref_div = INPLL(PPLL_REF_DIV) & 0x3ff;
699 Ns = (tmp & 0xff0000) >> 16;
700 Nm = (tmp & 0xff00) >> 8;
702 sclk = round_div((2 * Ns * xtal), (2 * M));
703 mclk = round_div((2 * Nm * xtal), (2 * M));
705 /* we're done, hopefully these are sane values */
706 rinfo->pll.ref_clk = xtal;
707 rinfo->pll.ref_div = ref_div;
708 rinfo->pll.sclk = sclk;
709 rinfo->pll.mclk = mclk;
715 * Retrieve PLL infos by different means (BIOS, Open Firmware, register probing...)
717 static void radeon_get_pllinfo(struct radeonfb_info *rinfo)
720 * In the case nothing works, these are defaults; they are mostly
721 * incomplete, however. It does provide ppll_max and _min values
722 * even for most other methods, however.
724 switch (rinfo->chipset) {
725 case PCI_DEVICE_ID_ATI_RADEON_QW:
726 case PCI_DEVICE_ID_ATI_RADEON_QX:
727 rinfo->pll.ppll_max = 35000;
728 rinfo->pll.ppll_min = 12000;
729 rinfo->pll.mclk = 23000;
730 rinfo->pll.sclk = 23000;
731 rinfo->pll.ref_clk = 2700;
733 case PCI_DEVICE_ID_ATI_RADEON_QL:
734 case PCI_DEVICE_ID_ATI_RADEON_QN:
735 case PCI_DEVICE_ID_ATI_RADEON_QO:
736 case PCI_DEVICE_ID_ATI_RADEON_Ql:
737 case PCI_DEVICE_ID_ATI_RADEON_BB:
738 rinfo->pll.ppll_max = 35000;
739 rinfo->pll.ppll_min = 12000;
740 rinfo->pll.mclk = 27500;
741 rinfo->pll.sclk = 27500;
742 rinfo->pll.ref_clk = 2700;
744 case PCI_DEVICE_ID_ATI_RADEON_Id:
745 case PCI_DEVICE_ID_ATI_RADEON_Ie:
746 case PCI_DEVICE_ID_ATI_RADEON_If:
747 case PCI_DEVICE_ID_ATI_RADEON_Ig:
748 rinfo->pll.ppll_max = 35000;
749 rinfo->pll.ppll_min = 12000;
750 rinfo->pll.mclk = 25000;
751 rinfo->pll.sclk = 25000;
752 rinfo->pll.ref_clk = 2700;
754 case PCI_DEVICE_ID_ATI_RADEON_ND:
755 case PCI_DEVICE_ID_ATI_RADEON_NE:
756 case PCI_DEVICE_ID_ATI_RADEON_NF:
757 case PCI_DEVICE_ID_ATI_RADEON_NG:
758 rinfo->pll.ppll_max = 40000;
759 rinfo->pll.ppll_min = 20000;
760 rinfo->pll.mclk = 27000;
761 rinfo->pll.sclk = 27000;
762 rinfo->pll.ref_clk = 2700;
764 case PCI_DEVICE_ID_ATI_RADEON_QD:
765 case PCI_DEVICE_ID_ATI_RADEON_QE:
766 case PCI_DEVICE_ID_ATI_RADEON_QF:
767 case PCI_DEVICE_ID_ATI_RADEON_QG:
769 rinfo->pll.ppll_max = 35000;
770 rinfo->pll.ppll_min = 12000;
771 rinfo->pll.mclk = 16600;
772 rinfo->pll.sclk = 16600;
773 rinfo->pll.ref_clk = 2700;
776 rinfo->pll.ref_div = INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK;
779 #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
781 * Retrieve PLL infos from Open Firmware first
783 if (!force_measure_pll && radeon_read_xtal_OF(rinfo) == 0) {
784 printk(KERN_INFO "radeonfb: Retrieved PLL infos from Open Firmware\n");
787 #endif /* CONFIG_PPC || CONFIG_SPARC */
790 * Check out if we have an X86 which gave us some PLL informations
791 * and if yes, retrieve them
793 if (!force_measure_pll && rinfo->bios_seg) {
794 u16 pll_info_block = BIOS_IN16(rinfo->fp_bios_start + 0x30);
796 rinfo->pll.sclk = BIOS_IN16(pll_info_block + 0x08);
797 rinfo->pll.mclk = BIOS_IN16(pll_info_block + 0x0a);
798 rinfo->pll.ref_clk = BIOS_IN16(pll_info_block + 0x0e);
799 rinfo->pll.ref_div = BIOS_IN16(pll_info_block + 0x10);
800 rinfo->pll.ppll_min = BIOS_IN32(pll_info_block + 0x12);
801 rinfo->pll.ppll_max = BIOS_IN32(pll_info_block + 0x16);
803 printk(KERN_INFO "radeonfb: Retrieved PLL infos from BIOS\n");
808 * We didn't get PLL parameters from either OF or BIOS, we try to
811 if (radeon_probe_pll_params(rinfo) == 0) {
812 printk(KERN_INFO "radeonfb: Retrieved PLL infos from registers\n");
817 * Fall back to already-set defaults...
819 printk(KERN_INFO "radeonfb: Used default PLL infos\n");
823 * Some methods fail to retrieve SCLK and MCLK values, we apply default
824 * settings in this case (200Mhz). If that really happens often, we
825 * could fetch from registers instead...
827 if (rinfo->pll.mclk == 0)
828 rinfo->pll.mclk = 20000;
829 if (rinfo->pll.sclk == 0)
830 rinfo->pll.sclk = 20000;
832 printk("radeonfb: Reference=%d.%02d MHz (RefDiv=%d) Memory=%d.%02d Mhz, System=%d.%02d MHz\n",
833 rinfo->pll.ref_clk / 100, rinfo->pll.ref_clk % 100,
835 rinfo->pll.mclk / 100, rinfo->pll.mclk % 100,
836 rinfo->pll.sclk / 100, rinfo->pll.sclk % 100);
837 printk("radeonfb: PLL min %d max %d\n", rinfo->pll.ppll_min, rinfo->pll.ppll_max);
840 static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info)
842 struct radeonfb_info *rinfo = info->par;
843 struct fb_var_screeninfo v;
847 if (radeon_match_mode(rinfo, &v, var))
850 switch (v.bits_per_pixel) {
852 v.bits_per_pixel = 8;
855 v.bits_per_pixel = 16;
858 #if 0 /* Doesn't seem to work */
859 v.bits_per_pixel = 24;
864 v.bits_per_pixel = 32;
870 switch (var_to_depth(&v)) {
873 v.red.offset = v.green.offset = v.blue.offset = 0;
874 v.red.length = v.green.length = v.blue.length = 8;
875 v.transp.offset = v.transp.length = 0;
883 v.red.length = v.green.length = v.blue.length = 5;
884 v.transp.offset = v.transp.length = 0;
895 v.transp.offset = v.transp.length = 0;
903 v.red.length = v.blue.length = v.green.length = 8;
904 v.transp.offset = v.transp.length = 0;
912 v.red.length = v.blue.length = v.green.length = 8;
913 v.transp.offset = 24;
917 printk ("radeonfb: mode %dx%dx%d rejected, color depth invalid\n",
918 var->xres, var->yres, var->bits_per_pixel);
922 if (v.yres_virtual < v.yres)
923 v.yres_virtual = v.yres;
924 if (v.xres_virtual < v.xres)
925 v.xres_virtual = v.xres;
928 /* XXX I'm adjusting xres_virtual to the pitch, that may help XFree
929 * with some panels, though I don't quite like this solution
931 if (rinfo->info->flags & FBINFO_HWACCEL_DISABLED) {
932 v.xres_virtual = v.xres_virtual & ~7ul;
934 pitch = ((v.xres_virtual * ((v.bits_per_pixel + 1) / 8) + 0x3f)
936 v.xres_virtual = (pitch << 6) / ((v.bits_per_pixel + 1) / 8);
939 if (((v.xres_virtual * v.yres_virtual * nom) / den) > rinfo->mapped_vram)
942 if (v.xres_virtual < v.xres)
943 v.xres = v.xres_virtual;
945 if (v.xoffset > v.xres_virtual - v.xres)
946 v.xoffset = v.xres_virtual - v.xres - 1;
948 if (v.yoffset > v.yres_virtual - v.yres)
949 v.yoffset = v.yres_virtual - v.yres - 1;
951 v.red.msb_right = v.green.msb_right = v.blue.msb_right =
952 v.transp.offset = v.transp.length =
953 v.transp.msb_right = 0;
955 memcpy(var, &v, sizeof(v));
961 static int radeonfb_pan_display (struct fb_var_screeninfo *var,
962 struct fb_info *info)
964 struct radeonfb_info *rinfo = info->par;
966 if ((var->xoffset + info->var.xres > info->var.xres_virtual)
967 || (var->yoffset + info->var.yres > info->var.yres_virtual))
974 OUTREG(CRTC_OFFSET, (var->yoffset * info->fix.line_length +
975 var->xoffset * info->var.bits_per_pixel / 8) & ~7);
980 static int radeonfb_ioctl (struct fb_info *info, unsigned int cmd,
983 struct radeonfb_info *rinfo = info->par;
990 * TODO: set mirror accordingly for non-Mobility chipsets with 2 CRTC's
991 * and do something better using 2nd CRTC instead of just hackish
992 * routing to second output
994 case FBIO_RADEON_SET_MIRROR:
995 if (!rinfo->is_mobility)
998 rc = get_user(value, (__u32 __user *)arg);
1003 radeon_fifo_wait(2);
1005 tmp = INREG(LVDS_GEN_CNTL);
1007 tmp |= (LVDS_ON | LVDS_BLON);
1009 tmp = INREG(LVDS_GEN_CNTL);
1011 tmp &= ~(LVDS_ON | LVDS_BLON);
1014 OUTREG(LVDS_GEN_CNTL, tmp);
1017 tmp = INREG(CRTC_EXT_CNTL);
1022 tmp = INREG(CRTC_EXT_CNTL);
1023 tmp &= ~CRTC_CRT_ON;
1028 OUTREG(CRTC_EXT_CNTL, tmp);
1031 case FBIO_RADEON_GET_MIRROR:
1032 if (!rinfo->is_mobility)
1035 tmp = INREG(LVDS_GEN_CNTL);
1036 if ((LVDS_ON | LVDS_BLON) & tmp)
1039 tmp = INREG(CRTC_EXT_CNTL);
1040 if (CRTC_CRT_ON & tmp)
1043 return put_user(value, (__u32 __user *)arg);
1052 int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch)
1058 if (rinfo->lock_blank)
1061 radeon_engine_idle();
1063 val = INREG(CRTC_EXT_CNTL);
1064 val &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS |
1067 case FB_BLANK_VSYNC_SUSPEND:
1068 val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS);
1070 case FB_BLANK_HSYNC_SUSPEND:
1071 val |= (CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS);
1073 case FB_BLANK_POWERDOWN:
1074 val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS |
1077 case FB_BLANK_NORMAL:
1078 val |= CRTC_DISPLAY_DIS;
1080 case FB_BLANK_UNBLANK:
1084 OUTREG(CRTC_EXT_CNTL, val);
1087 switch (rinfo->mon1_type) {
1090 OUTREGP(FP_GEN_CNTL, (FP_FPON | FP_TMDS_EN),
1091 ~(FP_FPON | FP_TMDS_EN));
1093 if (mode_switch || blank == FB_BLANK_NORMAL)
1095 OUTREGP(FP_GEN_CNTL, 0, ~(FP_FPON | FP_TMDS_EN));
1099 del_timer_sync(&rinfo->lvds_timer);
1100 val = INREG(LVDS_GEN_CNTL);
1102 u32 target_val = (val & ~LVDS_DISPLAY_DIS) | LVDS_BLON | LVDS_ON
1103 | LVDS_EN | (rinfo->init_state.lvds_gen_cntl
1104 & (LVDS_DIGON | LVDS_BL_MOD_EN));
1105 if ((val ^ target_val) == LVDS_DISPLAY_DIS)
1106 OUTREG(LVDS_GEN_CNTL, target_val);
1107 else if ((val ^ target_val) != 0) {
1108 OUTREG(LVDS_GEN_CNTL, target_val
1109 & ~(LVDS_ON | LVDS_BL_MOD_EN));
1110 rinfo->init_state.lvds_gen_cntl &= ~LVDS_STATE_MASK;
1111 rinfo->init_state.lvds_gen_cntl |=
1112 target_val & LVDS_STATE_MASK;
1114 radeon_msleep(rinfo->panel_info.pwr_delay);
1115 OUTREG(LVDS_GEN_CNTL, target_val);
1118 rinfo->pending_lvds_gen_cntl = target_val;
1119 mod_timer(&rinfo->lvds_timer,
1121 msecs_to_jiffies(rinfo->panel_info.pwr_delay));
1125 val |= LVDS_DISPLAY_DIS;
1126 OUTREG(LVDS_GEN_CNTL, val);
1128 /* We don't do a full switch-off on a simple mode switch */
1129 if (mode_switch || blank == FB_BLANK_NORMAL)
1132 /* Asic bug, when turning off LVDS_ON, we have to make sure
1133 * RADEON_PIXCLK_LVDS_ALWAYS_ON bit is off
1135 tmp_pix_clks = INPLL(PIXCLKS_CNTL);
1136 if (rinfo->is_mobility || rinfo->is_IGP)
1137 OUTPLLP(PIXCLKS_CNTL, 0, ~PIXCLK_LVDS_ALWAYS_ONb);
1138 val &= ~(LVDS_BL_MOD_EN);
1139 OUTREG(LVDS_GEN_CNTL, val);
1141 val &= ~(LVDS_ON | LVDS_EN);
1142 OUTREG(LVDS_GEN_CNTL, val);
1144 rinfo->pending_lvds_gen_cntl = val;
1145 mod_timer(&rinfo->lvds_timer,
1147 msecs_to_jiffies(rinfo->panel_info.pwr_delay));
1148 rinfo->init_state.lvds_gen_cntl &= ~LVDS_STATE_MASK;
1149 rinfo->init_state.lvds_gen_cntl |= val & LVDS_STATE_MASK;
1150 if (rinfo->is_mobility || rinfo->is_IGP)
1151 OUTPLL(PIXCLKS_CNTL, tmp_pix_clks);
1155 // todo: powerdown DAC
1163 static int radeonfb_blank (int blank, struct fb_info *info)
1165 struct radeonfb_info *rinfo = info->par;
1170 return radeon_screen_blank(rinfo, blank, 0);
1173 static int radeon_setcolreg (unsigned regno, unsigned red, unsigned green,
1174 unsigned blue, unsigned transp,
1175 struct radeonfb_info *rinfo)
1187 rinfo->palette[regno].red = red;
1188 rinfo->palette[regno].green = green;
1189 rinfo->palette[regno].blue = blue;
1194 if (!rinfo->asleep) {
1195 radeon_fifo_wait(9);
1197 if (rinfo->bpp == 16) {
1200 if (rinfo->depth == 16 && regno > 63)
1202 if (rinfo->depth == 15 && regno > 31)
1205 /* For 565, the green component is mixed one order
1208 if (rinfo->depth == 16) {
1209 OUTREG(PALETTE_INDEX, pindex>>1);
1210 OUTREG(PALETTE_DATA,
1211 (rinfo->palette[regno>>1].red << 16) |
1213 (rinfo->palette[regno>>1].blue));
1214 green = rinfo->palette[regno<<1].green;
1218 if (rinfo->depth != 16 || regno < 32) {
1219 OUTREG(PALETTE_INDEX, pindex);
1220 OUTREG(PALETTE_DATA, (red << 16) |
1221 (green << 8) | blue);
1225 u32 *pal = rinfo->info->pseudo_palette;
1226 switch (rinfo->depth) {
1228 pal[regno] = (regno << 10) | (regno << 5) | regno;
1231 pal[regno] = (regno << 11) | (regno << 5) | regno;
1234 pal[regno] = (regno << 16) | (regno << 8) | regno;
1237 i = (regno << 8) | regno;
1238 pal[regno] = (i << 16) | i;
1245 static int radeonfb_setcolreg (unsigned regno, unsigned red, unsigned green,
1246 unsigned blue, unsigned transp,
1247 struct fb_info *info)
1249 struct radeonfb_info *rinfo = info->par;
1250 u32 dac_cntl2, vclk_cntl = 0;
1253 if (!rinfo->asleep) {
1254 if (rinfo->is_mobility) {
1255 vclk_cntl = INPLL(VCLK_ECP_CNTL);
1256 OUTPLL(VCLK_ECP_CNTL,
1257 vclk_cntl & ~PIXCLK_DAC_ALWAYS_ONb);
1260 /* Make sure we are on first palette */
1261 if (rinfo->has_CRTC2) {
1262 dac_cntl2 = INREG(DAC_CNTL2);
1263 dac_cntl2 &= ~DAC2_PALETTE_ACCESS_CNTL;
1264 OUTREG(DAC_CNTL2, dac_cntl2);
1268 rc = radeon_setcolreg (regno, red, green, blue, transp, rinfo);
1270 if (!rinfo->asleep && rinfo->is_mobility)
1271 OUTPLL(VCLK_ECP_CNTL, vclk_cntl);
1276 static int radeonfb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
1278 struct radeonfb_info *rinfo = info->par;
1279 u16 *red, *green, *blue, *transp;
1280 u32 dac_cntl2, vclk_cntl = 0;
1281 int i, start, rc = 0;
1283 if (!rinfo->asleep) {
1284 if (rinfo->is_mobility) {
1285 vclk_cntl = INPLL(VCLK_ECP_CNTL);
1286 OUTPLL(VCLK_ECP_CNTL,
1287 vclk_cntl & ~PIXCLK_DAC_ALWAYS_ONb);
1290 /* Make sure we are on first palette */
1291 if (rinfo->has_CRTC2) {
1292 dac_cntl2 = INREG(DAC_CNTL2);
1293 dac_cntl2 &= ~DAC2_PALETTE_ACCESS_CNTL;
1294 OUTREG(DAC_CNTL2, dac_cntl2);
1299 green = cmap->green;
1301 transp = cmap->transp;
1302 start = cmap->start;
1304 for (i = 0; i < cmap->len; i++) {
1305 u_int hred, hgreen, hblue, htransp = 0xffff;
1311 htransp = *transp++;
1312 rc = radeon_setcolreg (start++, hred, hgreen, hblue, htransp,
1318 if (!rinfo->asleep && rinfo->is_mobility)
1319 OUTPLL(VCLK_ECP_CNTL, vclk_cntl);
1324 static void radeon_save_state (struct radeonfb_info *rinfo,
1325 struct radeon_regs *save)
1328 save->crtc_gen_cntl = INREG(CRTC_GEN_CNTL);
1329 save->crtc_ext_cntl = INREG(CRTC_EXT_CNTL);
1330 save->crtc_more_cntl = INREG(CRTC_MORE_CNTL);
1331 save->dac_cntl = INREG(DAC_CNTL);
1332 save->crtc_h_total_disp = INREG(CRTC_H_TOTAL_DISP);
1333 save->crtc_h_sync_strt_wid = INREG(CRTC_H_SYNC_STRT_WID);
1334 save->crtc_v_total_disp = INREG(CRTC_V_TOTAL_DISP);
1335 save->crtc_v_sync_strt_wid = INREG(CRTC_V_SYNC_STRT_WID);
1336 save->crtc_pitch = INREG(CRTC_PITCH);
1337 save->surface_cntl = INREG(SURFACE_CNTL);
1340 save->fp_crtc_h_total_disp = INREG(FP_CRTC_H_TOTAL_DISP);
1341 save->fp_crtc_v_total_disp = INREG(FP_CRTC_V_TOTAL_DISP);
1342 save->fp_gen_cntl = INREG(FP_GEN_CNTL);
1343 save->fp_h_sync_strt_wid = INREG(FP_H_SYNC_STRT_WID);
1344 save->fp_horz_stretch = INREG(FP_HORZ_STRETCH);
1345 save->fp_v_sync_strt_wid = INREG(FP_V_SYNC_STRT_WID);
1346 save->fp_vert_stretch = INREG(FP_VERT_STRETCH);
1347 save->lvds_gen_cntl = INREG(LVDS_GEN_CNTL);
1348 save->lvds_pll_cntl = INREG(LVDS_PLL_CNTL);
1349 save->tmds_crc = INREG(TMDS_CRC);
1350 save->tmds_transmitter_cntl = INREG(TMDS_TRANSMITTER_CNTL);
1351 save->vclk_ecp_cntl = INPLL(VCLK_ECP_CNTL);
1354 save->clk_cntl_index = INREG(CLOCK_CNTL_INDEX) & ~0x3f;
1355 radeon_pll_errata_after_index(rinfo);
1356 save->ppll_div_3 = INPLL(PPLL_DIV_3);
1357 save->ppll_ref_div = INPLL(PPLL_REF_DIV);
1361 static void radeon_write_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs *mode)
1365 radeon_fifo_wait(20);
1367 /* Workaround from XFree */
1368 if (rinfo->is_mobility) {
1369 /* A temporal workaround for the occasional blanking on certain laptop
1370 * panels. This appears to related to the PLL divider registers
1371 * (fail to lock?). It occurs even when all dividers are the same
1372 * with their old settings. In this case we really don't need to
1373 * fiddle with PLL registers. By doing this we can avoid the blanking
1374 * problem with some panels.
1376 if ((mode->ppll_ref_div == (INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK)) &&
1377 (mode->ppll_div_3 == (INPLL(PPLL_DIV_3) &
1378 (PPLL_POST3_DIV_MASK | PPLL_FB3_DIV_MASK)))) {
1379 /* We still have to force a switch to selected PPLL div thanks to
1380 * an XFree86 driver bug which will switch it away in some cases
1381 * even when using UseFDev */
1382 OUTREGP(CLOCK_CNTL_INDEX,
1383 mode->clk_cntl_index & PPLL_DIV_SEL_MASK,
1384 ~PPLL_DIV_SEL_MASK);
1385 radeon_pll_errata_after_index(rinfo);
1386 radeon_pll_errata_after_data(rinfo);
1391 /* Swich VCKL clock input to CPUCLK so it stays fed while PPLL updates*/
1392 OUTPLLP(VCLK_ECP_CNTL, VCLK_SRC_SEL_CPUCLK, ~VCLK_SRC_SEL_MASK);
1394 /* Reset PPLL & enable atomic update */
1396 PPLL_RESET | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN,
1397 ~(PPLL_RESET | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN));
1399 /* Switch to selected PPLL divider */
1400 OUTREGP(CLOCK_CNTL_INDEX,
1401 mode->clk_cntl_index & PPLL_DIV_SEL_MASK,
1402 ~PPLL_DIV_SEL_MASK);
1403 radeon_pll_errata_after_index(rinfo);
1404 radeon_pll_errata_after_data(rinfo);
1406 /* Set PPLL ref. div */
1407 if (IS_R300_VARIANT(rinfo) ||
1408 rinfo->family == CHIP_FAMILY_RS300 ||
1409 rinfo->family == CHIP_FAMILY_RS400 ||
1410 rinfo->family == CHIP_FAMILY_RS480) {
1411 if (mode->ppll_ref_div & R300_PPLL_REF_DIV_ACC_MASK) {
1412 /* When restoring console mode, use saved PPLL_REF_DIV
1415 OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, 0);
1417 /* R300 uses ref_div_acc field as real ref divider */
1418 OUTPLLP(PPLL_REF_DIV,
1419 (mode->ppll_ref_div << R300_PPLL_REF_DIV_ACC_SHIFT),
1420 ~R300_PPLL_REF_DIV_ACC_MASK);
1423 OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, ~PPLL_REF_DIV_MASK);
1425 /* Set PPLL divider 3 & post divider*/
1426 OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_FB3_DIV_MASK);
1427 OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_POST3_DIV_MASK);
1430 while (INPLL(PPLL_REF_DIV) & PPLL_ATOMIC_UPDATE_R)
1432 OUTPLLP(PPLL_REF_DIV, PPLL_ATOMIC_UPDATE_W, ~PPLL_ATOMIC_UPDATE_W);
1434 /* Wait read update complete */
1435 /* FIXME: Certain revisions of R300 can't recover here. Not sure of
1436 the cause yet, but this workaround will mask the problem for now.
1437 Other chips usually will pass at the very first test, so the
1438 workaround shouldn't have any effect on them. */
1439 for (i = 0; (i < 10000 && INPLL(PPLL_REF_DIV) & PPLL_ATOMIC_UPDATE_R); i++)
1442 OUTPLL(HTOTAL_CNTL, 0);
1444 /* Clear reset & atomic update */
1445 OUTPLLP(PPLL_CNTL, 0,
1446 ~(PPLL_RESET | PPLL_SLEEP | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN));
1448 /* We may want some locking ... oh well */
1451 /* Switch back VCLK source to PPLL */
1452 OUTPLLP(VCLK_ECP_CNTL, VCLK_SRC_SEL_PPLLCLK, ~VCLK_SRC_SEL_MASK);
1456 * Timer function for delayed LVDS panel power up/down
1458 static void radeon_lvds_timer_func(unsigned long data)
1460 struct radeonfb_info *rinfo = (struct radeonfb_info *)data;
1462 radeon_engine_idle();
1464 OUTREG(LVDS_GEN_CNTL, rinfo->pending_lvds_gen_cntl);
1468 * Apply a video mode. This will apply the whole register set, including
1469 * the PLL registers, to the card
1471 void radeon_write_mode (struct radeonfb_info *rinfo, struct radeon_regs *mode,
1475 int primary_mon = PRIMARY_MONITOR(rinfo);
1481 radeon_screen_blank(rinfo, FB_BLANK_NORMAL, 0);
1483 radeon_fifo_wait(31);
1484 for (i=0; i<10; i++)
1485 OUTREG(common_regs[i].reg, common_regs[i].val);
1487 /* Apply surface registers */
1488 for (i=0; i<8; i++) {
1489 OUTREG(SURFACE0_LOWER_BOUND + 0x10*i, mode->surf_lower_bound[i]);
1490 OUTREG(SURFACE0_UPPER_BOUND + 0x10*i, mode->surf_upper_bound[i]);
1491 OUTREG(SURFACE0_INFO + 0x10*i, mode->surf_info[i]);
1494 OUTREG(CRTC_GEN_CNTL, mode->crtc_gen_cntl);
1495 OUTREGP(CRTC_EXT_CNTL, mode->crtc_ext_cntl,
1496 ~(CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS));
1497 OUTREG(CRTC_MORE_CNTL, mode->crtc_more_cntl);
1498 OUTREGP(DAC_CNTL, mode->dac_cntl, DAC_RANGE_CNTL | DAC_BLANKING);
1499 OUTREG(CRTC_H_TOTAL_DISP, mode->crtc_h_total_disp);
1500 OUTREG(CRTC_H_SYNC_STRT_WID, mode->crtc_h_sync_strt_wid);
1501 OUTREG(CRTC_V_TOTAL_DISP, mode->crtc_v_total_disp);
1502 OUTREG(CRTC_V_SYNC_STRT_WID, mode->crtc_v_sync_strt_wid);
1503 OUTREG(CRTC_OFFSET, 0);
1504 OUTREG(CRTC_OFFSET_CNTL, 0);
1505 OUTREG(CRTC_PITCH, mode->crtc_pitch);
1506 OUTREG(SURFACE_CNTL, mode->surface_cntl);
1508 radeon_write_pll_regs(rinfo, mode);
1510 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1511 radeon_fifo_wait(10);
1512 OUTREG(FP_CRTC_H_TOTAL_DISP, mode->fp_crtc_h_total_disp);
1513 OUTREG(FP_CRTC_V_TOTAL_DISP, mode->fp_crtc_v_total_disp);
1514 OUTREG(FP_H_SYNC_STRT_WID, mode->fp_h_sync_strt_wid);
1515 OUTREG(FP_V_SYNC_STRT_WID, mode->fp_v_sync_strt_wid);
1516 OUTREG(FP_HORZ_STRETCH, mode->fp_horz_stretch);
1517 OUTREG(FP_VERT_STRETCH, mode->fp_vert_stretch);
1518 OUTREG(FP_GEN_CNTL, mode->fp_gen_cntl);
1519 OUTREG(TMDS_CRC, mode->tmds_crc);
1520 OUTREG(TMDS_TRANSMITTER_CNTL, mode->tmds_transmitter_cntl);
1524 radeon_screen_blank(rinfo, FB_BLANK_UNBLANK, 0);
1526 radeon_fifo_wait(2);
1527 OUTPLL(VCLK_ECP_CNTL, mode->vclk_ecp_cntl);
1533 * Calculate the PLL values for a given mode
1535 static void radeon_calc_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs *regs,
1553 int fb_div, pll_output_freq = 0;
1556 /* Check if the DVO port is enabled and sourced from the primary CRTC. I'm
1557 * not sure which model starts having FP2_GEN_CNTL, I assume anything more
1558 * recent than an r(v)100...
1561 /* XXX I had reports of flicker happening with the cinema display
1562 * on TMDS1 that seem to be fixed if I also forbit odd dividers in
1563 * this case. This could just be a bandwidth calculation issue, I
1564 * haven't implemented the bandwidth code yet, but in the meantime,
1565 * forcing uses_dvo to 1 fixes it and shouln't have bad side effects,
1566 * I haven't seen a case were were absolutely needed an odd PLL
1567 * divider. I'll find a better fix once I have more infos on the
1568 * real cause of the problem.
1570 while (rinfo->has_CRTC2) {
1571 u32 fp2_gen_cntl = INREG(FP2_GEN_CNTL);
1572 u32 disp_output_cntl;
1575 /* FP2 path not enabled */
1576 if ((fp2_gen_cntl & FP2_ON) == 0)
1578 /* Not all chip revs have the same format for this register,
1579 * extract the source selection
1581 if (rinfo->family == CHIP_FAMILY_R200 || IS_R300_VARIANT(rinfo)) {
1582 source = (fp2_gen_cntl >> 10) & 0x3;
1583 /* sourced from transform unit, check for transform unit
1587 disp_output_cntl = INREG(DISP_OUTPUT_CNTL);
1588 source = (disp_output_cntl >> 12) & 0x3;
1591 source = (fp2_gen_cntl >> 13) & 0x1;
1592 /* sourced from CRTC2 -> exit */
1596 /* so we end up on CRTC1, let's set uses_dvo to 1 now */
1603 if (freq > rinfo->pll.ppll_max)
1604 freq = rinfo->pll.ppll_max;
1605 if (freq*12 < rinfo->pll.ppll_min)
1606 freq = rinfo->pll.ppll_min / 12;
1607 pr_debug("freq = %lu, PLL min = %u, PLL max = %u\n",
1608 freq, rinfo->pll.ppll_min, rinfo->pll.ppll_max);
1610 for (post_div = &post_divs[0]; post_div->divider; ++post_div) {
1611 pll_output_freq = post_div->divider * freq;
1612 /* If we output to the DVO port (external TMDS), we don't allow an
1613 * odd PLL divider as those aren't supported on this path
1615 if (uses_dvo && (post_div->divider & 1))
1617 if (pll_output_freq >= rinfo->pll.ppll_min &&
1618 pll_output_freq <= rinfo->pll.ppll_max)
1622 /* If we fall through the bottom, try the "default value"
1623 given by the terminal post_div->bitvalue */
1624 if ( !post_div->divider ) {
1625 post_div = &post_divs[post_div->bitvalue];
1626 pll_output_freq = post_div->divider * freq;
1628 pr_debug("ref_div = %d, ref_clk = %d, output_freq = %d\n",
1629 rinfo->pll.ref_div, rinfo->pll.ref_clk,
1632 /* If we fall through the bottom, try the "default value"
1633 given by the terminal post_div->bitvalue */
1634 if ( !post_div->divider ) {
1635 post_div = &post_divs[post_div->bitvalue];
1636 pll_output_freq = post_div->divider * freq;
1638 pr_debug("ref_div = %d, ref_clk = %d, output_freq = %d\n",
1639 rinfo->pll.ref_div, rinfo->pll.ref_clk,
1642 fb_div = round_div(rinfo->pll.ref_div*pll_output_freq,
1643 rinfo->pll.ref_clk);
1644 regs->ppll_ref_div = rinfo->pll.ref_div;
1645 regs->ppll_div_3 = fb_div | (post_div->bitvalue << 16);
1647 pr_debug("post div = 0x%x\n", post_div->bitvalue);
1648 pr_debug("fb_div = 0x%x\n", fb_div);
1649 pr_debug("ppll_div_3 = 0x%x\n", regs->ppll_div_3);
1652 static int radeonfb_set_par(struct fb_info *info)
1654 struct radeonfb_info *rinfo = info->par;
1655 struct fb_var_screeninfo *mode = &info->var;
1656 struct radeon_regs *newmode;
1657 int hTotal, vTotal, hSyncStart, hSyncEnd,
1658 hSyncPol, vSyncStart, vSyncEnd, vSyncPol, cSync;
1659 u8 hsync_adj_tab[] = {0, 0x12, 9, 9, 6, 5};
1660 u8 hsync_fudge_fp[] = {2, 2, 0, 0, 5, 5};
1661 u32 sync, h_sync_pol, v_sync_pol, dotClock, pixClock;
1665 int hsync_start, hsync_fudge, bytpp, hsync_wid, vsync_wid;
1666 int primary_mon = PRIMARY_MONITOR(rinfo);
1667 int depth = var_to_depth(mode);
1670 newmode = kmalloc(sizeof(struct radeon_regs), GFP_KERNEL);
1674 /* We always want engine to be idle on a mode switch, even
1675 * if we won't actually change the mode
1677 radeon_engine_idle();
1679 hSyncStart = mode->xres + mode->right_margin;
1680 hSyncEnd = hSyncStart + mode->hsync_len;
1681 hTotal = hSyncEnd + mode->left_margin;
1683 vSyncStart = mode->yres + mode->lower_margin;
1684 vSyncEnd = vSyncStart + mode->vsync_len;
1685 vTotal = vSyncEnd + mode->upper_margin;
1686 pixClock = mode->pixclock;
1689 h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
1690 v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
1692 if (primary_mon == MT_DFP || primary_mon == MT_LCD) {
1693 if (rinfo->panel_info.xres < mode->xres)
1694 mode->xres = rinfo->panel_info.xres;
1695 if (rinfo->panel_info.yres < mode->yres)
1696 mode->yres = rinfo->panel_info.yres;
1698 hTotal = mode->xres + rinfo->panel_info.hblank;
1699 hSyncStart = mode->xres + rinfo->panel_info.hOver_plus;
1700 hSyncEnd = hSyncStart + rinfo->panel_info.hSync_width;
1702 vTotal = mode->yres + rinfo->panel_info.vblank;
1703 vSyncStart = mode->yres + rinfo->panel_info.vOver_plus;
1704 vSyncEnd = vSyncStart + rinfo->panel_info.vSync_width;
1706 h_sync_pol = !rinfo->panel_info.hAct_high;
1707 v_sync_pol = !rinfo->panel_info.vAct_high;
1709 pixClock = 100000000 / rinfo->panel_info.clock;
1711 if (rinfo->panel_info.use_bios_dividers) {
1713 newmode->ppll_div_3 = rinfo->panel_info.fbk_divider |
1714 (rinfo->panel_info.post_divider << 16);
1715 newmode->ppll_ref_div = rinfo->panel_info.ref_divider;
1718 dotClock = 1000000000 / pixClock;
1719 freq = dotClock / 10; /* x100 */
1721 pr_debug("hStart = %d, hEnd = %d, hTotal = %d\n",
1722 hSyncStart, hSyncEnd, hTotal);
1723 pr_debug("vStart = %d, vEnd = %d, vTotal = %d\n",
1724 vSyncStart, vSyncEnd, vTotal);
1726 hsync_wid = (hSyncEnd - hSyncStart) / 8;
1727 vsync_wid = vSyncEnd - vSyncStart;
1730 else if (hsync_wid > 0x3f) /* max */
1735 else if (vsync_wid > 0x1f) /* max */
1738 hSyncPol = mode->sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
1739 vSyncPol = mode->sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
1741 cSync = mode->sync & FB_SYNC_COMP_HIGH_ACT ? (1 << 4) : 0;
1743 format = radeon_get_dstbpp(depth);
1744 bytpp = mode->bits_per_pixel >> 3;
1746 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD))
1747 hsync_fudge = hsync_fudge_fp[format-1];
1749 hsync_fudge = hsync_adj_tab[format-1];
1751 hsync_start = hSyncStart - 8 + hsync_fudge;
1753 newmode->crtc_gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN |
1756 /* Clear auto-center etc... */
1757 newmode->crtc_more_cntl = rinfo->init_state.crtc_more_cntl;
1758 newmode->crtc_more_cntl &= 0xfffffff0;
1760 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1761 newmode->crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN;
1763 newmode->crtc_ext_cntl |= CRTC_CRT_ON;
1765 newmode->crtc_gen_cntl &= ~(CRTC_DBL_SCAN_EN |
1768 newmode->crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN |
1772 newmode->dac_cntl = /* INREG(DAC_CNTL) | */ DAC_MASK_ALL | DAC_VGA_ADR_EN |
1775 newmode->crtc_h_total_disp = ((((hTotal / 8) - 1) & 0x3ff) |
1776 (((mode->xres / 8) - 1) << 16));
1778 newmode->crtc_h_sync_strt_wid = ((hsync_start & 0x1fff) |
1779 (hsync_wid << 16) | (h_sync_pol << 23));
1781 newmode->crtc_v_total_disp = ((vTotal - 1) & 0xffff) |
1782 ((mode->yres - 1) << 16);
1784 newmode->crtc_v_sync_strt_wid = (((vSyncStart - 1) & 0xfff) |
1785 (vsync_wid << 16) | (v_sync_pol << 23));
1787 if (!(info->flags & FBINFO_HWACCEL_DISABLED)) {
1788 /* We first calculate the engine pitch */
1789 rinfo->pitch = ((mode->xres_virtual * ((mode->bits_per_pixel + 1) / 8) + 0x3f)
1792 /* Then, re-multiply it to get the CRTC pitch */
1793 newmode->crtc_pitch = (rinfo->pitch << 3) / ((mode->bits_per_pixel + 1) / 8);
1795 newmode->crtc_pitch = (mode->xres_virtual >> 3);
1797 newmode->crtc_pitch |= (newmode->crtc_pitch << 16);
1800 * It looks like recent chips have a problem with SURFACE_CNTL,
1801 * setting SURF_TRANSLATION_DIS completely disables the
1802 * swapper as well, so we leave it unset now.
1804 newmode->surface_cntl = 0;
1806 #if defined(__BIG_ENDIAN)
1808 /* Setup swapping on both apertures, though we currently
1809 * only use aperture 0, enabling swapper on aperture 1
1812 switch (mode->bits_per_pixel) {
1814 newmode->surface_cntl |= NONSURF_AP0_SWP_16BPP;
1815 newmode->surface_cntl |= NONSURF_AP1_SWP_16BPP;
1819 newmode->surface_cntl |= NONSURF_AP0_SWP_32BPP;
1820 newmode->surface_cntl |= NONSURF_AP1_SWP_32BPP;
1825 /* Clear surface registers */
1826 for (i=0; i<8; i++) {
1827 newmode->surf_lower_bound[i] = 0;
1828 newmode->surf_upper_bound[i] = 0x1f;
1829 newmode->surf_info[i] = 0;
1832 pr_debug("h_total_disp = 0x%x\t hsync_strt_wid = 0x%x\n",
1833 newmode->crtc_h_total_disp, newmode->crtc_h_sync_strt_wid);
1834 pr_debug("v_total_disp = 0x%x\t vsync_strt_wid = 0x%x\n",
1835 newmode->crtc_v_total_disp, newmode->crtc_v_sync_strt_wid);
1837 rinfo->bpp = mode->bits_per_pixel;
1838 rinfo->depth = depth;
1840 pr_debug("pixclock = %lu\n", (unsigned long)pixClock);
1841 pr_debug("freq = %lu\n", (unsigned long)freq);
1843 /* We use PPLL_DIV_3 */
1844 newmode->clk_cntl_index = 0x300;
1846 /* Calculate PPLL value if necessary */
1848 radeon_calc_pll_regs(rinfo, newmode, freq);
1850 newmode->vclk_ecp_cntl = rinfo->init_state.vclk_ecp_cntl;
1852 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1853 unsigned int hRatio, vRatio;
1855 if (mode->xres > rinfo->panel_info.xres)
1856 mode->xres = rinfo->panel_info.xres;
1857 if (mode->yres > rinfo->panel_info.yres)
1858 mode->yres = rinfo->panel_info.yres;
1860 newmode->fp_horz_stretch = (((rinfo->panel_info.xres / 8) - 1)
1861 << HORZ_PANEL_SHIFT);
1862 newmode->fp_vert_stretch = ((rinfo->panel_info.yres - 1)
1863 << VERT_PANEL_SHIFT);
1865 if (mode->xres != rinfo->panel_info.xres) {
1866 hRatio = round_div(mode->xres * HORZ_STRETCH_RATIO_MAX,
1867 rinfo->panel_info.xres);
1868 newmode->fp_horz_stretch = (((((unsigned long)hRatio) & HORZ_STRETCH_RATIO_MASK)) |
1869 (newmode->fp_horz_stretch &
1870 (HORZ_PANEL_SIZE | HORZ_FP_LOOP_STRETCH |
1871 HORZ_AUTO_RATIO_INC)));
1872 newmode->fp_horz_stretch |= (HORZ_STRETCH_BLEND |
1873 HORZ_STRETCH_ENABLE);
1876 newmode->fp_horz_stretch &= ~HORZ_AUTO_RATIO;
1878 if (mode->yres != rinfo->panel_info.yres) {
1879 vRatio = round_div(mode->yres * VERT_STRETCH_RATIO_MAX,
1880 rinfo->panel_info.yres);
1881 newmode->fp_vert_stretch = (((((unsigned long)vRatio) & VERT_STRETCH_RATIO_MASK)) |
1882 (newmode->fp_vert_stretch &
1883 (VERT_PANEL_SIZE | VERT_STRETCH_RESERVED)));
1884 newmode->fp_vert_stretch |= (VERT_STRETCH_BLEND |
1885 VERT_STRETCH_ENABLE);
1888 newmode->fp_vert_stretch &= ~VERT_AUTO_RATIO_EN;
1890 newmode->fp_gen_cntl = (rinfo->init_state.fp_gen_cntl & (u32)
1892 FP_RMX_HVSYNC_CONTROL_EN |
1897 FP_CRTC_USE_SHADOW_VEND |
1900 newmode->fp_gen_cntl |= (FP_CRTC_DONT_SHADOW_VPAR |
1901 FP_CRTC_DONT_SHADOW_HEND |
1904 if (IS_R300_VARIANT(rinfo) ||
1905 (rinfo->family == CHIP_FAMILY_R200)) {
1906 newmode->fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
1908 newmode->fp_gen_cntl |= R200_FP_SOURCE_SEL_RMX;
1910 newmode->fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC1;
1912 newmode->fp_gen_cntl |= FP_SEL_CRTC1;
1914 newmode->lvds_gen_cntl = rinfo->init_state.lvds_gen_cntl;
1915 newmode->lvds_pll_cntl = rinfo->init_state.lvds_pll_cntl;
1916 newmode->tmds_crc = rinfo->init_state.tmds_crc;
1917 newmode->tmds_transmitter_cntl = rinfo->init_state.tmds_transmitter_cntl;
1919 if (primary_mon == MT_LCD) {
1920 newmode->lvds_gen_cntl |= (LVDS_ON | LVDS_BLON);
1921 newmode->fp_gen_cntl &= ~(FP_FPON | FP_TMDS_EN);
1924 newmode->fp_gen_cntl |= (FP_FPON | FP_TMDS_EN);
1925 newmode->tmds_transmitter_cntl &= ~(TMDS_PLLRST);
1926 /* TMDS_PLL_EN bit is reversed on RV (and mobility) chips */
1927 if (IS_R300_VARIANT(rinfo) ||
1928 (rinfo->family == CHIP_FAMILY_R200) || !rinfo->has_CRTC2)
1929 newmode->tmds_transmitter_cntl &= ~TMDS_PLL_EN;
1931 newmode->tmds_transmitter_cntl |= TMDS_PLL_EN;
1932 newmode->crtc_ext_cntl &= ~CRTC_CRT_ON;
1935 newmode->fp_crtc_h_total_disp = (((rinfo->panel_info.hblank / 8) & 0x3ff) |
1936 (((mode->xres / 8) - 1) << 16));
1937 newmode->fp_crtc_v_total_disp = (rinfo->panel_info.vblank & 0xffff) |
1938 ((mode->yres - 1) << 16);
1939 newmode->fp_h_sync_strt_wid = ((rinfo->panel_info.hOver_plus & 0x1fff) |
1940 (hsync_wid << 16) | (h_sync_pol << 23));
1941 newmode->fp_v_sync_strt_wid = ((rinfo->panel_info.vOver_plus & 0xfff) |
1942 (vsync_wid << 16) | (v_sync_pol << 23));
1946 if (!rinfo->asleep) {
1947 memcpy(&rinfo->state, newmode, sizeof(*newmode));
1948 radeon_write_mode (rinfo, newmode, 0);
1949 /* (re)initialize the engine */
1950 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
1951 radeonfb_engine_init (rinfo);
1954 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
1955 info->fix.line_length = rinfo->pitch*64;
1957 info->fix.line_length = mode->xres_virtual
1958 * ((mode->bits_per_pixel + 1) / 8);
1959 info->fix.visual = rinfo->depth == 8 ? FB_VISUAL_PSEUDOCOLOR
1960 : FB_VISUAL_DIRECTCOLOR;
1962 #ifdef CONFIG_BOOTX_TEXT
1963 /* Update debug text engine */
1964 btext_update_display(rinfo->fb_base_phys, mode->xres, mode->yres,
1965 rinfo->depth, info->fix.line_length);
1973 static struct fb_ops radeonfb_ops = {
1974 .owner = THIS_MODULE,
1975 .fb_check_var = radeonfb_check_var,
1976 .fb_set_par = radeonfb_set_par,
1977 .fb_setcolreg = radeonfb_setcolreg,
1978 .fb_setcmap = radeonfb_setcmap,
1979 .fb_pan_display = radeonfb_pan_display,
1980 .fb_blank = radeonfb_blank,
1981 .fb_ioctl = radeonfb_ioctl,
1982 .fb_sync = radeonfb_sync,
1983 .fb_fillrect = radeonfb_fillrect,
1984 .fb_copyarea = radeonfb_copyarea,
1985 .fb_imageblit = radeonfb_imageblit,
1989 static int radeon_set_fbinfo(struct radeonfb_info *rinfo)
1991 struct fb_info *info = rinfo->info;
1994 info->pseudo_palette = rinfo->pseudo_palette;
1995 info->flags = FBINFO_DEFAULT
1996 | FBINFO_HWACCEL_COPYAREA
1997 | FBINFO_HWACCEL_FILLRECT
1998 | FBINFO_HWACCEL_XPAN
1999 | FBINFO_HWACCEL_YPAN;
2000 info->fbops = &radeonfb_ops;
2001 info->screen_base = rinfo->fb_base;
2002 info->screen_size = rinfo->mapped_vram;
2003 /* Fill fix common fields */
2004 strlcpy(info->fix.id, rinfo->name, sizeof(info->fix.id));
2005 info->fix.smem_start = rinfo->fb_base_phys;
2006 info->fix.smem_len = rinfo->video_ram;
2007 info->fix.type = FB_TYPE_PACKED_PIXELS;
2008 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
2009 info->fix.xpanstep = 8;
2010 info->fix.ypanstep = 1;
2011 info->fix.ywrapstep = 0;
2012 info->fix.type_aux = 0;
2013 info->fix.mmio_start = rinfo->mmio_base_phys;
2014 info->fix.mmio_len = RADEON_REGSIZE;
2015 info->fix.accel = FB_ACCEL_ATI_RADEON;
2017 fb_alloc_cmap(&info->cmap, 256, 0);
2020 info->flags |= FBINFO_HWACCEL_DISABLED;
2026 * This reconfigure the card's internal memory map. In theory, we'd like
2027 * to setup the card's memory at the same address as it's PCI bus address,
2028 * and the AGP aperture right after that so that system RAM on 32 bits
2029 * machines at least, is directly accessible. However, doing so would
2030 * conflict with the current XFree drivers...
2031 * Ultimately, I hope XFree, GATOS and ATI binary drivers will all agree
2032 * on the proper way to set this up and duplicate this here. In the meantime,
2033 * I put the card's memory at 0 in card space and AGP at some random high
2034 * local (0xe0000000 for now) that will be changed by XFree/DRI anyway
2037 #undef SET_MC_FB_FROM_APERTURE
2038 static void fixup_memory_mappings(struct radeonfb_info *rinfo)
2040 u32 save_crtc_gen_cntl, save_crtc2_gen_cntl = 0;
2041 u32 save_crtc_ext_cntl;
2042 u32 aper_base, aper_size;
2045 /* First, we disable display to avoid interfering */
2046 if (rinfo->has_CRTC2) {
2047 save_crtc2_gen_cntl = INREG(CRTC2_GEN_CNTL);
2048 OUTREG(CRTC2_GEN_CNTL, save_crtc2_gen_cntl | CRTC2_DISP_REQ_EN_B);
2050 save_crtc_gen_cntl = INREG(CRTC_GEN_CNTL);
2051 save_crtc_ext_cntl = INREG(CRTC_EXT_CNTL);
2053 OUTREG(CRTC_EXT_CNTL, save_crtc_ext_cntl | CRTC_DISPLAY_DIS);
2054 OUTREG(CRTC_GEN_CNTL, save_crtc_gen_cntl | CRTC_DISP_REQ_EN_B);
2057 aper_base = INREG(CNFG_APER_0_BASE);
2058 aper_size = INREG(CNFG_APER_SIZE);
2060 #ifdef SET_MC_FB_FROM_APERTURE
2061 /* Set framebuffer to be at the same address as set in PCI BAR */
2062 OUTREG(MC_FB_LOCATION,
2063 ((aper_base + aper_size - 1) & 0xffff0000) | (aper_base >> 16));
2064 rinfo->fb_local_base = aper_base;
2066 OUTREG(MC_FB_LOCATION, 0x7fff0000);
2067 rinfo->fb_local_base = 0;
2069 agp_base = aper_base + aper_size;
2070 if (agp_base & 0xf0000000)
2071 agp_base = (aper_base | 0x0fffffff) + 1;
2073 /* Set AGP to be just after the framebuffer on a 256Mb boundary. This
2074 * assumes the FB isn't mapped to 0xf0000000 or above, but this is
2075 * always the case on PPCs afaik.
2077 #ifdef SET_MC_FB_FROM_APERTURE
2078 OUTREG(MC_AGP_LOCATION, 0xffff0000 | (agp_base >> 16));
2080 OUTREG(MC_AGP_LOCATION, 0xffffe000);
2083 /* Fixup the display base addresses & engine offsets while we
2086 #ifdef SET_MC_FB_FROM_APERTURE
2087 OUTREG(DISPLAY_BASE_ADDR, aper_base);
2088 if (rinfo->has_CRTC2)
2089 OUTREG(CRTC2_DISPLAY_BASE_ADDR, aper_base);
2090 OUTREG(OV0_BASE_ADDR, aper_base);
2092 OUTREG(DISPLAY_BASE_ADDR, 0);
2093 if (rinfo->has_CRTC2)
2094 OUTREG(CRTC2_DISPLAY_BASE_ADDR, 0);
2095 OUTREG(OV0_BASE_ADDR, 0);
2099 /* Restore display settings */
2100 OUTREG(CRTC_GEN_CNTL, save_crtc_gen_cntl);
2101 OUTREG(CRTC_EXT_CNTL, save_crtc_ext_cntl);
2102 if (rinfo->has_CRTC2)
2103 OUTREG(CRTC2_GEN_CNTL, save_crtc2_gen_cntl);
2105 pr_debug("aper_base: %08x MC_FB_LOC to: %08x, MC_AGP_LOC to: %08x\n",
2107 ((aper_base + aper_size - 1) & 0xffff0000) | (aper_base >> 16),
2108 0xffff0000 | (agp_base >> 16));
2110 #endif /* CONFIG_PPC */
2113 static void radeon_identify_vram(struct radeonfb_info *rinfo)
2117 /* framebuffer size */
2118 if ((rinfo->family == CHIP_FAMILY_RS100) ||
2119 (rinfo->family == CHIP_FAMILY_RS200) ||
2120 (rinfo->family == CHIP_FAMILY_RS300) ||
2121 (rinfo->family == CHIP_FAMILY_RC410) ||
2122 (rinfo->family == CHIP_FAMILY_RS400) ||
2123 (rinfo->family == CHIP_FAMILY_RS480) ) {
2124 u32 tom = INREG(NB_TOM);
2125 tmp = ((((tom >> 16) - (tom & 0xffff) + 1) << 6) * 1024);
2127 radeon_fifo_wait(6);
2128 OUTREG(MC_FB_LOCATION, tom);
2129 OUTREG(DISPLAY_BASE_ADDR, (tom & 0xffff) << 16);
2130 OUTREG(CRTC2_DISPLAY_BASE_ADDR, (tom & 0xffff) << 16);
2131 OUTREG(OV0_BASE_ADDR, (tom & 0xffff) << 16);
2133 /* This is supposed to fix the crtc2 noise problem. */
2134 OUTREG(GRPH2_BUFFER_CNTL, INREG(GRPH2_BUFFER_CNTL) & ~0x7f0000);
2136 if ((rinfo->family == CHIP_FAMILY_RS100) ||
2137 (rinfo->family == CHIP_FAMILY_RS200)) {
2138 /* This is to workaround the asic bug for RMX, some versions
2139 of BIOS doesn't have this register initialized correctly.
2141 OUTREGP(CRTC_MORE_CNTL, CRTC_H_CUTOFF_ACTIVE_EN,
2142 ~CRTC_H_CUTOFF_ACTIVE_EN);
2145 tmp = INREG(CNFG_MEMSIZE);
2148 /* mem size is bits [28:0], mask off the rest */
2149 rinfo->video_ram = tmp & CNFG_MEMSIZE_MASK;
2152 * Hack to get around some busted production M6's
2155 if (rinfo->video_ram == 0) {
2156 switch (rinfo->pdev->device) {
2157 case PCI_CHIP_RADEON_LY:
2158 case PCI_CHIP_RADEON_LZ:
2159 rinfo->video_ram = 8192 * 1024;
2168 * Now try to identify VRAM type
2170 if (rinfo->is_IGP || (rinfo->family >= CHIP_FAMILY_R300) ||
2171 (INREG(MEM_SDRAM_MODE_REG) & (1<<30)))
2172 rinfo->vram_ddr = 1;
2174 rinfo->vram_ddr = 0;
2176 tmp = INREG(MEM_CNTL);
2177 if (IS_R300_VARIANT(rinfo)) {
2178 tmp &= R300_MEM_NUM_CHANNELS_MASK;
2180 case 0: rinfo->vram_width = 64; break;
2181 case 1: rinfo->vram_width = 128; break;
2182 case 2: rinfo->vram_width = 256; break;
2183 default: rinfo->vram_width = 128; break;
2185 } else if ((rinfo->family == CHIP_FAMILY_RV100) ||
2186 (rinfo->family == CHIP_FAMILY_RS100) ||
2187 (rinfo->family == CHIP_FAMILY_RS200)){
2188 if (tmp & RV100_MEM_HALF_MODE)
2189 rinfo->vram_width = 32;
2191 rinfo->vram_width = 64;
2193 if (tmp & MEM_NUM_CHANNELS_MASK)
2194 rinfo->vram_width = 128;
2196 rinfo->vram_width = 64;
2199 /* This may not be correct, as some cards can have half of channel disabled
2200 * ToDo: identify these cases
2203 pr_debug("radeonfb (%s): Found %ldk of %s %d bits wide videoram\n",
2204 pci_name(rinfo->pdev),
2205 rinfo->video_ram / 1024,
2206 rinfo->vram_ddr ? "DDR" : "SDRAM",
2214 static ssize_t radeon_show_one_edid(char *buf, loff_t off, size_t count, const u8 *edid)
2216 return memory_read_from_buffer(buf, count, &off, edid, EDID_LENGTH);
2220 static ssize_t radeon_show_edid1(struct file *filp, struct kobject *kobj,
2221 struct bin_attribute *bin_attr,
2222 char *buf, loff_t off, size_t count)
2224 struct device *dev = container_of(kobj, struct device, kobj);
2225 struct pci_dev *pdev = to_pci_dev(dev);
2226 struct fb_info *info = pci_get_drvdata(pdev);
2227 struct radeonfb_info *rinfo = info->par;
2229 return radeon_show_one_edid(buf, off, count, rinfo->mon1_EDID);
2233 static ssize_t radeon_show_edid2(struct file *filp, struct kobject *kobj,
2234 struct bin_attribute *bin_attr,
2235 char *buf, loff_t off, size_t count)
2237 struct device *dev = container_of(kobj, struct device, kobj);
2238 struct pci_dev *pdev = to_pci_dev(dev);
2239 struct fb_info *info = pci_get_drvdata(pdev);
2240 struct radeonfb_info *rinfo = info->par;
2242 return radeon_show_one_edid(buf, off, count, rinfo->mon2_EDID);
2245 static struct bin_attribute edid1_attr = {
2250 .size = EDID_LENGTH,
2251 .read = radeon_show_edid1,
2254 static struct bin_attribute edid2_attr = {
2259 .size = EDID_LENGTH,
2260 .read = radeon_show_edid2,
2264 static int radeonfb_pci_register(struct pci_dev *pdev,
2265 const struct pci_device_id *ent)
2267 struct fb_info *info;
2268 struct radeonfb_info *rinfo;
2270 unsigned char c1, c2;
2273 pr_debug("radeonfb_pci_register BEGIN\n");
2275 /* Enable device in PCI config */
2276 ret = pci_enable_device(pdev);
2278 printk(KERN_ERR "radeonfb (%s): Cannot enable PCI device\n",
2283 info = framebuffer_alloc(sizeof(struct radeonfb_info), &pdev->dev);
2285 printk (KERN_ERR "radeonfb (%s): could not allocate memory\n",
2294 spin_lock_init(&rinfo->reg_lock);
2295 init_timer(&rinfo->lvds_timer);
2296 rinfo->lvds_timer.function = radeon_lvds_timer_func;
2297 rinfo->lvds_timer.data = (unsigned long)rinfo;
2299 c1 = ent->device >> 8;
2300 c2 = ent->device & 0xff;
2301 if (isprint(c1) && isprint(c2))
2302 snprintf(rinfo->name, sizeof(rinfo->name),
2303 "ATI Radeon %x \"%c%c\"", ent->device & 0xffff, c1, c2);
2305 snprintf(rinfo->name, sizeof(rinfo->name),
2306 "ATI Radeon %x", ent->device & 0xffff);
2308 rinfo->family = ent->driver_data & CHIP_FAMILY_MASK;
2309 rinfo->chipset = pdev->device;
2310 rinfo->has_CRTC2 = (ent->driver_data & CHIP_HAS_CRTC2) != 0;
2311 rinfo->is_mobility = (ent->driver_data & CHIP_IS_MOBILITY) != 0;
2312 rinfo->is_IGP = (ent->driver_data & CHIP_IS_IGP) != 0;
2314 /* Set base addrs */
2315 rinfo->fb_base_phys = pci_resource_start (pdev, 0);
2316 rinfo->mmio_base_phys = pci_resource_start (pdev, 2);
2318 /* request the mem regions */
2319 ret = pci_request_region(pdev, 0, "radeonfb framebuffer");
2321 printk( KERN_ERR "radeonfb (%s): cannot request region 0.\n",
2322 pci_name(rinfo->pdev));
2323 goto err_release_fb;
2326 ret = pci_request_region(pdev, 2, "radeonfb mmio");
2328 printk( KERN_ERR "radeonfb (%s): cannot request region 2.\n",
2329 pci_name(rinfo->pdev));
2330 goto err_release_pci0;
2333 /* map the regions */
2334 rinfo->mmio_base = ioremap(rinfo->mmio_base_phys, RADEON_REGSIZE);
2335 if (!rinfo->mmio_base) {
2336 printk(KERN_ERR "radeonfb (%s): cannot map MMIO\n",
2337 pci_name(rinfo->pdev));
2339 goto err_release_pci2;
2342 rinfo->fb_local_base = INREG(MC_FB_LOCATION) << 16;
2348 if (rinfo->family == CHIP_FAMILY_R300 &&
2349 (INREG(CNFG_CNTL) & CFG_ATI_REV_ID_MASK)
2351 rinfo->errata |= CHIP_ERRATA_R300_CG;
2353 if (rinfo->family == CHIP_FAMILY_RV200 ||
2354 rinfo->family == CHIP_FAMILY_RS200)
2355 rinfo->errata |= CHIP_ERRATA_PLL_DUMMYREADS;
2357 if (rinfo->family == CHIP_FAMILY_RV100 ||
2358 rinfo->family == CHIP_FAMILY_RS100 ||
2359 rinfo->family == CHIP_FAMILY_RS200)
2360 rinfo->errata |= CHIP_ERRATA_PLL_DELAY;
2362 #if defined(CONFIG_PPC) || defined(CONFIG_SPARC)
2363 /* On PPC, we obtain the OF device-node pointer to the firmware
2364 * data for this chip
2366 rinfo->of_node = pci_device_to_OF_node(pdev);
2367 if (rinfo->of_node == NULL)
2368 printk(KERN_WARNING "radeonfb (%s): Cannot match card to OF node !\n",
2369 pci_name(rinfo->pdev));
2371 #endif /* CONFIG_PPC || CONFIG_SPARC */
2373 /* On PPC, the firmware sets up a memory mapping that tends
2374 * to cause lockups when enabling the engine. We reconfigure
2375 * the card internal memory mappings properly
2377 fixup_memory_mappings(rinfo);
2378 #endif /* CONFIG_PPC */
2380 /* Get VRAM size and type */
2381 radeon_identify_vram(rinfo);
2383 rinfo->mapped_vram = min_t(unsigned long, MAX_MAPPED_VRAM, rinfo->video_ram);
2386 rinfo->fb_base = ioremap_wc(rinfo->fb_base_phys,
2387 rinfo->mapped_vram);
2388 } while (rinfo->fb_base == NULL &&
2389 ((rinfo->mapped_vram /= 2) >= MIN_MAPPED_VRAM));
2391 if (rinfo->fb_base == NULL) {
2392 printk (KERN_ERR "radeonfb (%s): cannot map FB\n",
2393 pci_name(rinfo->pdev));
2398 pr_debug("radeonfb (%s): mapped %ldk videoram\n", pci_name(rinfo->pdev),
2399 rinfo->mapped_vram/1024);
2402 * Map the BIOS ROM if any and retrieve PLL parameters from
2403 * the BIOS. We skip that on mobility chips as the real panel
2404 * values we need aren't in the ROM but in the BIOS image in
2405 * memory. This is definitely not the best meacnism though,
2406 * we really need the arch code to tell us which is the "primary"
2407 * video adapter to use the memory image (or better, the arch
2408 * should provide us a copy of the BIOS image to shield us from
2409 * archs who would store that elsewhere and/or could initialize
2410 * more than one adapter during boot).
2412 if (!rinfo->is_mobility)
2413 radeon_map_ROM(rinfo, pdev);
2416 * On x86, the primary display on laptop may have it's BIOS
2417 * ROM elsewhere, try to locate it at the legacy memory hole.
2418 * We probably need to make sure this is the primary display,
2419 * but that is difficult without some arch support.
2422 if (rinfo->bios_seg == NULL)
2423 radeon_find_mem_vbios(rinfo);
2426 /* If both above failed, try the BIOS ROM again for mobility
2429 if (rinfo->bios_seg == NULL && rinfo->is_mobility)
2430 radeon_map_ROM(rinfo, pdev);
2432 /* Get informations about the board's PLL */
2433 radeon_get_pllinfo(rinfo);
2435 #ifdef CONFIG_FB_RADEON_I2C
2436 /* Register I2C bus */
2437 radeon_create_i2c_busses(rinfo);
2440 /* set all the vital stuff */
2441 radeon_set_fbinfo (rinfo);
2443 /* Probe screen types */
2444 radeon_probe_screens(rinfo, monitor_layout, ignore_edid);
2446 /* Build mode list, check out panel native model */
2447 radeon_check_modes(rinfo, mode_option);
2449 /* Register some sysfs stuff (should be done better) */
2450 if (rinfo->mon1_EDID)
2451 err |= sysfs_create_bin_file(&rinfo->pdev->dev.kobj,
2453 if (rinfo->mon2_EDID)
2454 err |= sysfs_create_bin_file(&rinfo->pdev->dev.kobj,
2457 pr_warning("%s() Creating sysfs files failed, continuing\n",
2460 /* save current mode regs before we switch into the new one
2461 * so we can restore this upon __exit
2463 radeon_save_state (rinfo, &rinfo->init_state);
2464 memcpy(&rinfo->state, &rinfo->init_state, sizeof(struct radeon_regs));
2466 /* Setup Power Management capabilities */
2467 if (default_dynclk < -1) {
2468 /* -2 is special: means ON on mobility chips and do not
2471 radeonfb_pm_init(rinfo, rinfo->is_mobility ? 1 : -1, ignore_devlist, force_sleep);
2473 radeonfb_pm_init(rinfo, default_dynclk, ignore_devlist, force_sleep);
2475 pci_set_drvdata(pdev, info);
2477 /* Register with fbdev layer */
2478 ret = register_framebuffer(info);
2480 printk (KERN_ERR "radeonfb (%s): could not register framebuffer\n",
2481 pci_name(rinfo->pdev));
2486 rinfo->wc_cookie = arch_phys_wc_add(rinfo->fb_base_phys,
2490 radeonfb_bl_init(rinfo);
2492 printk ("radeonfb (%s): %s\n", pci_name(rinfo->pdev), rinfo->name);
2494 if (rinfo->bios_seg)
2495 radeon_unmap_ROM(rinfo, pdev);
2496 pr_debug("radeonfb_pci_register END\n");
2500 iounmap(rinfo->fb_base);
2502 kfree(rinfo->mon1_EDID);
2503 kfree(rinfo->mon2_EDID);
2504 if (rinfo->mon1_modedb)
2505 fb_destroy_modedb(rinfo->mon1_modedb);
2506 fb_dealloc_cmap(&info->cmap);
2507 #ifdef CONFIG_FB_RADEON_I2C
2508 radeon_delete_i2c_busses(rinfo);
2510 if (rinfo->bios_seg)
2511 radeon_unmap_ROM(rinfo, pdev);
2512 iounmap(rinfo->mmio_base);
2514 pci_release_region(pdev, 2);
2516 pci_release_region(pdev, 0);
2518 framebuffer_release(info);
2526 static void radeonfb_pci_unregister(struct pci_dev *pdev)
2528 struct fb_info *info = pci_get_drvdata(pdev);
2529 struct radeonfb_info *rinfo = info->par;
2534 radeonfb_pm_exit(rinfo);
2536 if (rinfo->mon1_EDID)
2537 sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid1_attr);
2538 if (rinfo->mon2_EDID)
2539 sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid2_attr);
2542 /* restore original state
2544 * Doesn't quite work yet, I suspect if we come from a legacy
2545 * VGA mode (or worse, text mode), we need to do some VGA black
2546 * magic here that I know nothing about. --BenH
2548 radeon_write_mode (rinfo, &rinfo->init_state, 1);
2551 del_timer_sync(&rinfo->lvds_timer);
2552 arch_phys_wc_del(rinfo->wc_cookie);
2553 unregister_framebuffer(info);
2555 radeonfb_bl_exit(rinfo);
2557 iounmap(rinfo->mmio_base);
2558 iounmap(rinfo->fb_base);
2560 pci_release_region(pdev, 2);
2561 pci_release_region(pdev, 0);
2563 kfree(rinfo->mon1_EDID);
2564 kfree(rinfo->mon2_EDID);
2565 if (rinfo->mon1_modedb)
2566 fb_destroy_modedb(rinfo->mon1_modedb);
2567 #ifdef CONFIG_FB_RADEON_I2C
2568 radeon_delete_i2c_busses(rinfo);
2570 fb_dealloc_cmap(&info->cmap);
2571 framebuffer_release(info);
2575 static struct pci_driver radeonfb_driver = {
2577 .id_table = radeonfb_pci_table,
2578 .probe = radeonfb_pci_register,
2579 .remove = radeonfb_pci_unregister,
2581 .suspend = radeonfb_pci_suspend,
2582 .resume = radeonfb_pci_resume,
2583 #endif /* CONFIG_PM */
2587 static int __init radeonfb_setup (char *options)
2591 if (!options || !*options)
2594 while ((this_opt = strsep (&options, ",")) != NULL) {
2598 if (!strncmp(this_opt, "noaccel", 7)) {
2600 } else if (!strncmp(this_opt, "mirror", 6)) {
2602 } else if (!strncmp(this_opt, "force_dfp", 9)) {
2604 } else if (!strncmp(this_opt, "panel_yres:", 11)) {
2605 panel_yres = simple_strtoul((this_opt+11), NULL, 0);
2606 } else if (!strncmp(this_opt, "backlight:", 10)) {
2607 backlight = simple_strtoul(this_opt+10, NULL, 0);
2608 } else if (!strncmp(this_opt, "nomtrr", 6)) {
2610 } else if (!strncmp(this_opt, "nomodeset", 9)) {
2612 } else if (!strncmp(this_opt, "force_measure_pll", 17)) {
2613 force_measure_pll = 1;
2614 } else if (!strncmp(this_opt, "ignore_edid", 11)) {
2616 #if defined(CONFIG_PM) && defined(CONFIG_X86)
2617 } else if (!strncmp(this_opt, "force_sleep", 11)) {
2619 } else if (!strncmp(this_opt, "ignore_devlist", 14)) {
2623 mode_option = this_opt;
2629 static int __init radeonfb_init (void)
2632 char *option = NULL;
2634 if (fb_get_options("radeonfb", &option))
2636 radeonfb_setup(option);
2638 return pci_register_driver (&radeonfb_driver);
2642 static void __exit radeonfb_exit (void)
2644 pci_unregister_driver (&radeonfb_driver);
2647 module_init(radeonfb_init);
2648 module_exit(radeonfb_exit);
2650 MODULE_AUTHOR("Ani Joshi");
2651 MODULE_DESCRIPTION("framebuffer driver for ATI Radeon chipset");
2652 MODULE_LICENSE("GPL");
2653 module_param(noaccel, bool, 0);
2654 module_param(default_dynclk, int, 0);
2655 MODULE_PARM_DESC(default_dynclk, "int: -2=enable on mobility only,-1=do not change,0=off,1=on");
2656 MODULE_PARM_DESC(noaccel, "bool: disable acceleration");
2657 module_param(nomodeset, bool, 0);
2658 MODULE_PARM_DESC(nomodeset, "bool: disable actual setting of video mode");
2659 module_param(mirror, bool, 0);
2660 MODULE_PARM_DESC(mirror, "bool: mirror the display to both monitors");
2661 module_param(force_dfp, bool, 0);
2662 MODULE_PARM_DESC(force_dfp, "bool: force display to dfp");
2663 module_param(ignore_edid, bool, 0);
2664 MODULE_PARM_DESC(ignore_edid, "bool: Ignore EDID data when doing DDC probe");
2665 module_param(monitor_layout, charp, 0);
2666 MODULE_PARM_DESC(monitor_layout, "Specify monitor mapping (like XFree86)");
2667 module_param(force_measure_pll, bool, 0);
2668 MODULE_PARM_DESC(force_measure_pll, "Force measurement of PLL (debug)");
2669 module_param(nomtrr, bool, 0);
2670 MODULE_PARM_DESC(nomtrr, "bool: disable use of MTRR registers");
2671 module_param(panel_yres, int, 0);
2672 MODULE_PARM_DESC(panel_yres, "int: set panel yres");
2673 module_param(mode_option, charp, 0);
2674 MODULE_PARM_DESC(mode_option, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
2675 #if defined(CONFIG_PM) && defined(CONFIG_X86)
2676 module_param(force_sleep, bool, 0);
2677 MODULE_PARM_DESC(force_sleep, "bool: force D2 sleep mode on all hardware");
2678 module_param(ignore_devlist, bool, 0);
2679 MODULE_PARM_DESC(ignore_devlist, "bool: ignore workarounds for bugs in specific laptops");