blob: 5a8af4da4ce8c5fe7816d1ee11dd2ab1aaf31fe6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/video/aty/radeon_base.c
3 *
4 * framebuffer driver for ATI Radeon chipset video boards
5 *
6 * Copyright 2003 Ben. Herrenschmidt <benh@kernel.crashing.org>
7 * Copyright 2000 Ani Joshi <ajoshi@kernel.crashing.org>
8 *
9 * i2c bits from Luca Tettamanti <kronos@kronoz.cjb.net>
10 *
11 * Special thanks to ATI DevRel team for their hardware donations.
12 *
13 * ...Insert GPL boilerplate here...
14 *
15 * Significant portions of this driver apdated from XFree86 Radeon
16 * driver which has the following copyright notice:
17 *
18 * Copyright 2000 ATI Technologies Inc., Markham, Ontario, and
19 * VA Linux Systems Inc., Fremont, California.
20 *
21 * All Rights Reserved.
22 *
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:
30 *
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.
34 *
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.
43 *
44 * XFree86 driver authors:
45 *
46 * Kevin E. Martin <martin@xfree86.org>
47 * Rickard E. Faith <faith@valinux.com>
48 * Alan Hourihane <alanh@fairlite.demon.co.uk>
49 *
50 */
51
52
53#define RADEON_VERSION "0.2.0"
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <linux/module.h>
56#include <linux/moduleparam.h>
57#include <linux/kernel.h>
58#include <linux/errno.h>
59#include <linux/string.h>
60#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <linux/slab.h>
62#include <linux/delay.h>
63#include <linux/time.h>
64#include <linux/fb.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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71#include <asm/io.h>
72#include <asm/uaccess.h>
73
74#ifdef CONFIG_PPC_OF
75
76#include <asm/pci-bridge.h>
77#include "../macmodes.h"
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#ifdef CONFIG_BOOTX_TEXT
80#include <asm/btext.h>
81#endif
82
83#endif /* CONFIG_PPC_OF */
84
85#ifdef CONFIG_MTRR
86#include <asm/mtrr.h>
87#endif
88
89#include <video/radeon.h>
90#include <linux/radeonfb.h>
91
92#include "../edid.h" // MOVE THAT TO include/video
93#include "ati_ids.h"
94#include "radeonfb.h"
95
96#define MAX_MAPPED_VRAM (2048*2048*4)
97#define MIN_MAPPED_VRAM (1024*768*1)
98
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) }
101
102static struct pci_device_id radeonfb_pci_table[] = {
johan henrikssondd144712007-05-08 00:37:59 -0700103 /* Radeon Xpress 200m */
104 CHIP_DEF(PCI_CHIP_RS480_5955, RS480, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* Mobility M6 */
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),
108 /* Radeon VE/7000 */
109 CHIP_DEF(PCI_CHIP_RV100_QY, RV100, CHIP_HAS_CRTC2),
110 CHIP_DEF(PCI_CHIP_RV100_QZ, RV100, CHIP_HAS_CRTC2),
Jake Moilanen183dee02005-11-07 01:00:55 -0800111 CHIP_DEF(PCI_CHIP_RN50, RV100, CHIP_HAS_CRTC2),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 /* 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),
122 /* 7000 IGP (A4+) */
123 CHIP_DEF(PCI_CHIP_RS250_4237, RS200, CHIP_HAS_CRTC2 | CHIP_IS_IGP),
124 /* 8500 AIW */
125 CHIP_DEF(PCI_CHIP_R200_BB, R200, CHIP_HAS_CRTC2),
126 CHIP_DEF(PCI_CHIP_R200_BC, R200, CHIP_HAS_CRTC2),
127 /* 8700/8800 */
128 CHIP_DEF(PCI_CHIP_R200_QH, R200, CHIP_HAS_CRTC2),
129 /* 8500 */
130 CHIP_DEF(PCI_CHIP_R200_QL, R200, CHIP_HAS_CRTC2),
131 /* 9100 */
132 CHIP_DEF(PCI_CHIP_R200_QM, R200, CHIP_HAS_CRTC2),
133 /* Mobility M7 */
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),
136 /* 7500 */
137 CHIP_DEF(PCI_CHIP_RV200_QW, RV200, CHIP_HAS_CRTC2),
138 CHIP_DEF(PCI_CHIP_RV200_QX, RV200, CHIP_HAS_CRTC2),
139 /* Mobility M9 */
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),
144 /* 9000/Pro */
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),
150 /* 9100 IGP (A5) */
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),
Stephan Wolfb5f2f4d2007-07-17 04:05:29 -0700156 /*Mobility Xpress 200 */
157 CHIP_DEF(PCI_CHIP_RS485_5975, R300, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 /* 9200 */
159 CHIP_DEF(PCI_CHIP_RV280_5960, RV280, CHIP_HAS_CRTC2),
160 CHIP_DEF(PCI_CHIP_RV280_5961, RV280, CHIP_HAS_CRTC2),
161 CHIP_DEF(PCI_CHIP_RV280_5962, RV280, CHIP_HAS_CRTC2),
162 CHIP_DEF(PCI_CHIP_RV280_5964, RV280, CHIP_HAS_CRTC2),
163 /* 9500 */
164 CHIP_DEF(PCI_CHIP_R300_AD, R300, CHIP_HAS_CRTC2),
165 CHIP_DEF(PCI_CHIP_R300_AE, R300, CHIP_HAS_CRTC2),
166 /* 9600TX / FireGL Z1 */
167 CHIP_DEF(PCI_CHIP_R300_AF, R300, CHIP_HAS_CRTC2),
168 CHIP_DEF(PCI_CHIP_R300_AG, R300, CHIP_HAS_CRTC2),
169 /* 9700/9500/Pro/FireGL X1 */
170 CHIP_DEF(PCI_CHIP_R300_ND, R300, CHIP_HAS_CRTC2),
171 CHIP_DEF(PCI_CHIP_R300_NE, R300, CHIP_HAS_CRTC2),
172 CHIP_DEF(PCI_CHIP_R300_NF, R300, CHIP_HAS_CRTC2),
173 CHIP_DEF(PCI_CHIP_R300_NG, R300, CHIP_HAS_CRTC2),
174 /* Mobility M10/M11 */
175 CHIP_DEF(PCI_CHIP_RV350_NP, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
176 CHIP_DEF(PCI_CHIP_RV350_NQ, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
177 CHIP_DEF(PCI_CHIP_RV350_NR, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
178 CHIP_DEF(PCI_CHIP_RV350_NS, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
179 CHIP_DEF(PCI_CHIP_RV350_NT, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
180 CHIP_DEF(PCI_CHIP_RV350_NV, RV350, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
181 /* 9600/FireGL T2 */
182 CHIP_DEF(PCI_CHIP_RV350_AP, RV350, CHIP_HAS_CRTC2),
183 CHIP_DEF(PCI_CHIP_RV350_AQ, RV350, CHIP_HAS_CRTC2),
184 CHIP_DEF(PCI_CHIP_RV360_AR, RV350, CHIP_HAS_CRTC2),
185 CHIP_DEF(PCI_CHIP_RV350_AS, RV350, CHIP_HAS_CRTC2),
186 CHIP_DEF(PCI_CHIP_RV350_AT, RV350, CHIP_HAS_CRTC2),
187 CHIP_DEF(PCI_CHIP_RV350_AV, RV350, CHIP_HAS_CRTC2),
188 /* 9800/Pro/FileGL X2 */
189 CHIP_DEF(PCI_CHIP_R350_AH, R350, CHIP_HAS_CRTC2),
190 CHIP_DEF(PCI_CHIP_R350_AI, R350, CHIP_HAS_CRTC2),
191 CHIP_DEF(PCI_CHIP_R350_AJ, R350, CHIP_HAS_CRTC2),
192 CHIP_DEF(PCI_CHIP_R350_AK, R350, CHIP_HAS_CRTC2),
193 CHIP_DEF(PCI_CHIP_R350_NH, R350, CHIP_HAS_CRTC2),
194 CHIP_DEF(PCI_CHIP_R350_NI, R350, CHIP_HAS_CRTC2),
195 CHIP_DEF(PCI_CHIP_R360_NJ, R350, CHIP_HAS_CRTC2),
196 CHIP_DEF(PCI_CHIP_R350_NK, R350, CHIP_HAS_CRTC2),
197 /* Newer stuff */
198 CHIP_DEF(PCI_CHIP_RV380_3E50, RV380, CHIP_HAS_CRTC2),
199 CHIP_DEF(PCI_CHIP_RV380_3E54, RV380, CHIP_HAS_CRTC2),
200 CHIP_DEF(PCI_CHIP_RV380_3150, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
201 CHIP_DEF(PCI_CHIP_RV380_3154, RV380, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
202 CHIP_DEF(PCI_CHIP_RV370_5B60, RV380, CHIP_HAS_CRTC2),
203 CHIP_DEF(PCI_CHIP_RV370_5B62, 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),
229 { 0, }
230};
231MODULE_DEVICE_TABLE(pci, radeonfb_pci_table);
232
233
234typedef struct {
235 u16 reg;
236 u32 val;
237} reg_val;
238
239
240/* these common regs are cleared before mode setting so they do not
241 * interfere with anything
242 */
243static reg_val common_regs[] = {
244 { OVR_CLR, 0 },
245 { OVR_WID_LEFT_RIGHT, 0 },
246 { OVR_WID_TOP_BOTTOM, 0 },
247 { OV0_SCALE_CNTL, 0 },
248 { SUBPIC_CNTL, 0 },
249 { VIPH_CONTROL, 0 },
250 { I2C_CNTL_1, 0 },
251 { GEN_INT_CNTL, 0 },
252 { CAP0_TRIG_CNTL, 0 },
253 { CAP1_TRIG_CNTL, 0 },
254};
255
256/*
257 * globals
258 */
259
260static char *mode_option;
261static char *monitor_layout;
262static int noaccel = 0;
263static int default_dynclk = -2;
264static int nomodeset = 0;
265static int ignore_edid = 0;
266static int mirror = 0;
267static int panel_yres = 0;
268static int force_dfp = 0;
269static int force_measure_pll = 0;
270#ifdef CONFIG_MTRR
271static int nomtrr = 0;
272#endif
Volker Braun994aad22006-07-30 03:04:18 -0700273static int force_sleep;
274static int ignore_devlist;
Richard Purdie202d4e62007-03-03 17:43:52 +0000275#ifdef CONFIG_PMAC_BACKLIGHT
276static int backlight = 1;
277#else
278static int backlight = 0;
279#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281/*
282 * prototypes
283 */
284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285static void radeon_unmap_ROM(struct radeonfb_info *rinfo, struct pci_dev *dev)
286{
287 if (!rinfo->bios_seg)
288 return;
289 pci_unmap_rom(dev, rinfo->bios_seg);
290}
291
292static int __devinit radeon_map_ROM(struct radeonfb_info *rinfo, struct pci_dev *dev)
293{
294 void __iomem *rom;
295 u16 dptr;
296 u8 rom_type;
297 size_t rom_size;
298
299 /* If this is a primary card, there is a shadow copy of the
300 * ROM somewhere in the first meg. We will just ignore the copy
301 * and use the ROM directly.
302 */
303
304 /* Fix from ATI for problem with Radeon hardware not leaving ROM enabled */
305 unsigned int temp;
306 temp = INREG(MPP_TB_CONFIG);
307 temp &= 0x00ffffffu;
308 temp |= 0x04 << 24;
309 OUTREG(MPP_TB_CONFIG, temp);
310 temp = INREG(MPP_TB_CONFIG);
311
312 rom = pci_map_rom(dev, &rom_size);
313 if (!rom) {
314 printk(KERN_ERR "radeonfb (%s): ROM failed to map\n",
315 pci_name(rinfo->pdev));
316 return -ENOMEM;
317 }
318
319 rinfo->bios_seg = rom;
320
321 /* Very simple test to make sure it appeared */
322 if (BIOS_IN16(0) != 0xaa55) {
Olaf Hering3b4abff2005-09-09 13:10:06 -0700323 printk(KERN_DEBUG "radeonfb (%s): Invalid ROM signature %x "
324 "should be 0xaa55\n",
325 pci_name(rinfo->pdev), BIOS_IN16(0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 goto failed;
327 }
328 /* Look for the PCI data to check the ROM type */
329 dptr = BIOS_IN16(0x18);
330
331 /* Check the PCI data signature. If it's wrong, we still assume a normal x86 ROM
332 * for now, until I've verified this works everywhere. The goal here is more
333 * to phase out Open Firmware images.
334 *
335 * Currently, we only look at the first PCI data, we could iteratre and deal with
336 * them all, and we should use fb_bios_start relative to start of image and not
337 * relative start of ROM, but so far, I never found a dual-image ATI card
338 *
339 * typedef struct {
340 * u32 signature; + 0x00
341 * u16 vendor; + 0x04
342 * u16 device; + 0x06
343 * u16 reserved_1; + 0x08
344 * u16 dlen; + 0x0a
345 * u8 drevision; + 0x0c
346 * u8 class_hi; + 0x0d
347 * u16 class_lo; + 0x0e
348 * u16 ilen; + 0x10
349 * u16 irevision; + 0x12
350 * u8 type; + 0x14
351 * u8 indicator; + 0x15
352 * u16 reserved_2; + 0x16
353 * } pci_data_t;
354 */
355 if (BIOS_IN32(dptr) != (('R' << 24) | ('I' << 16) | ('C' << 8) | 'P')) {
356 printk(KERN_WARNING "radeonfb (%s): PCI DATA signature in ROM"
357 "incorrect: %08x\n", pci_name(rinfo->pdev), BIOS_IN32(dptr));
358 goto anyway;
359 }
360 rom_type = BIOS_IN8(dptr + 0x14);
361 switch(rom_type) {
362 case 0:
363 printk(KERN_INFO "radeonfb: Found Intel x86 BIOS ROM Image\n");
364 break;
365 case 1:
366 printk(KERN_INFO "radeonfb: Found Open Firmware ROM Image\n");
367 goto failed;
368 case 2:
369 printk(KERN_INFO "radeonfb: Found HP PA-RISC ROM Image\n");
370 goto failed;
371 default:
372 printk(KERN_INFO "radeonfb: Found unknown type %d ROM Image\n", rom_type);
373 goto failed;
374 }
375 anyway:
376 /* Locate the flat panel infos, do some sanity checking !!! */
377 rinfo->fp_bios_start = BIOS_IN16(0x48);
378 return 0;
379
380 failed:
381 rinfo->bios_seg = NULL;
382 radeon_unmap_ROM(rinfo, dev);
383 return -ENXIO;
384}
385
386#ifdef CONFIG_X86
387static int __devinit radeon_find_mem_vbios(struct radeonfb_info *rinfo)
388{
389 /* I simplified this code as we used to miss the signatures in
390 * a lot of case. It's now closer to XFree, we just don't check
391 * for signatures at all... Something better will have to be done
392 * if we end up having conflicts
393 */
394 u32 segstart;
395 void __iomem *rom_base = NULL;
396
397 for(segstart=0x000c0000; segstart<0x000f0000; segstart+=0x00001000) {
398 rom_base = ioremap(segstart, 0x10000);
399 if (rom_base == NULL)
400 return -ENOMEM;
401 if (readb(rom_base) == 0x55 && readb(rom_base + 1) == 0xaa)
402 break;
403 iounmap(rom_base);
404 rom_base = NULL;
405 }
406 if (rom_base == NULL)
407 return -ENXIO;
408
409 /* Locate the flat panel infos, do some sanity checking !!! */
410 rinfo->bios_seg = rom_base;
411 rinfo->fp_bios_start = BIOS_IN16(0x48);
412
413 return 0;
414}
415#endif
416
David S. Miller9f47df22007-03-29 01:33:46 -0700417#if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418/*
419 * Read XTAL (ref clock), SCLK and MCLK from Open Firmware device
420 * tree. Hopefully, ATI OF driver is kind enough to fill these
421 */
422static int __devinit radeon_read_xtal_OF (struct radeonfb_info *rinfo)
423{
424 struct device_node *dp = rinfo->of_node;
Jeremy Kerrb04e3dd2006-07-12 15:40:40 +1000425 const u32 *val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 if (dp == NULL)
428 return -ENODEV;
Stephen Rothwell40cd3a42007-05-01 13:54:02 +1000429 val = of_get_property(dp, "ATY,RefCLK", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 if (!val || !*val) {
431 printk(KERN_WARNING "radeonfb: No ATY,RefCLK property !\n");
432 return -EINVAL;
433 }
434
435 rinfo->pll.ref_clk = (*val) / 10;
436
Stephen Rothwell40cd3a42007-05-01 13:54:02 +1000437 val = of_get_property(dp, "ATY,SCLK", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 if (val && *val)
439 rinfo->pll.sclk = (*val) / 10;
440
Stephen Rothwell40cd3a42007-05-01 13:54:02 +1000441 val = of_get_property(dp, "ATY,MCLK", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 if (val && *val)
443 rinfo->pll.mclk = (*val) / 10;
444
445 return 0;
446}
David S. Miller9f47df22007-03-29 01:33:46 -0700447#endif /* CONFIG_PPC_OF || CONFIG_SPARC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449/*
450 * Read PLL infos from chip registers
451 */
452static int __devinit radeon_probe_pll_params(struct radeonfb_info *rinfo)
453{
454 unsigned char ppll_div_sel;
455 unsigned Ns, Nm, M;
456 unsigned sclk, mclk, tmp, ref_div;
457 int hTotal, vTotal, num, denom, m, n;
458 unsigned long long hz, vclk;
459 long xtal;
460 struct timeval start_tv, stop_tv;
461 long total_secs, total_usecs;
462 int i;
463
464 /* Ugh, we cut interrupts, bad bad bad, but we want some precision
465 * here, so... --BenH
466 */
467
468 /* Flush PCI buffers ? */
David S. Miller017fb982005-09-29 19:26:51 -0700469 tmp = INREG16(DEVICE_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 local_irq_disable();
472
473 for(i=0; i<1000000; i++)
474 if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) == 0)
475 break;
476
477 do_gettimeofday(&start_tv);
478
479 for(i=0; i<1000000; i++)
480 if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) != 0)
481 break;
482
483 for(i=0; i<1000000; i++)
484 if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) == 0)
485 break;
486
487 do_gettimeofday(&stop_tv);
488
489 local_irq_enable();
490
491 total_secs = stop_tv.tv_sec - start_tv.tv_sec;
492 if (total_secs > 10)
493 return -1;
494 total_usecs = stop_tv.tv_usec - start_tv.tv_usec;
495 total_usecs += total_secs * 1000000;
496 if (total_usecs < 0)
497 total_usecs = -total_usecs;
498 hz = 1000000/total_usecs;
499
500 hTotal = ((INREG(CRTC_H_TOTAL_DISP) & 0x1ff) + 1) * 8;
501 vTotal = ((INREG(CRTC_V_TOTAL_DISP) & 0x3ff) + 1);
502 vclk = (long long)hTotal * (long long)vTotal * hz;
503
504 switch((INPLL(PPLL_REF_DIV) & 0x30000) >> 16) {
505 case 0:
506 default:
507 num = 1;
508 denom = 1;
509 break;
510 case 1:
511 n = ((INPLL(M_SPLL_REF_FB_DIV) >> 16) & 0xff);
512 m = (INPLL(M_SPLL_REF_FB_DIV) & 0xff);
513 num = 2*n;
514 denom = 2*m;
515 break;
516 case 2:
517 n = ((INPLL(M_SPLL_REF_FB_DIV) >> 8) & 0xff);
518 m = (INPLL(M_SPLL_REF_FB_DIV) & 0xff);
519 num = 2*n;
520 denom = 2*m;
521 break;
522 }
523
524 ppll_div_sel = INREG8(CLOCK_CNTL_INDEX + 1) & 0x3;
525 radeon_pll_errata_after_index(rinfo);
526
527 n = (INPLL(PPLL_DIV_0 + ppll_div_sel) & 0x7ff);
528 m = (INPLL(PPLL_REF_DIV) & 0x3ff);
529
530 num *= n;
531 denom *= m;
532
533 switch ((INPLL(PPLL_DIV_0 + ppll_div_sel) >> 16) & 0x7) {
534 case 1:
535 denom *= 2;
536 break;
537 case 2:
538 denom *= 4;
539 break;
540 case 3:
541 denom *= 8;
542 break;
543 case 4:
544 denom *= 3;
545 break;
546 case 6:
547 denom *= 6;
548 break;
549 case 7:
550 denom *= 12;
551 break;
552 }
553
554 vclk *= denom;
555 do_div(vclk, 1000 * num);
556 xtal = vclk;
557
558 if ((xtal > 26900) && (xtal < 27100))
559 xtal = 2700;
560 else if ((xtal > 14200) && (xtal < 14400))
561 xtal = 1432;
562 else if ((xtal > 29400) && (xtal < 29600))
563 xtal = 2950;
564 else {
565 printk(KERN_WARNING "xtal calculation failed: %ld\n", xtal);
566 return -1;
567 }
568
569 tmp = INPLL(M_SPLL_REF_FB_DIV);
570 ref_div = INPLL(PPLL_REF_DIV) & 0x3ff;
571
572 Ns = (tmp & 0xff0000) >> 16;
573 Nm = (tmp & 0xff00) >> 8;
574 M = (tmp & 0xff);
575 sclk = round_div((2 * Ns * xtal), (2 * M));
576 mclk = round_div((2 * Nm * xtal), (2 * M));
577
578 /* we're done, hopefully these are sane values */
579 rinfo->pll.ref_clk = xtal;
580 rinfo->pll.ref_div = ref_div;
581 rinfo->pll.sclk = sclk;
582 rinfo->pll.mclk = mclk;
583
584 return 0;
585}
586
587/*
Matt Mackall4a4efbd2006-01-03 13:27:11 +0100588 * Retrieve PLL infos by different means (BIOS, Open Firmware, register probing...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 */
590static void __devinit radeon_get_pllinfo(struct radeonfb_info *rinfo)
591{
592 /*
593 * In the case nothing works, these are defaults; they are mostly
594 * incomplete, however. It does provide ppll_max and _min values
595 * even for most other methods, however.
596 */
597 switch (rinfo->chipset) {
598 case PCI_DEVICE_ID_ATI_RADEON_QW:
599 case PCI_DEVICE_ID_ATI_RADEON_QX:
600 rinfo->pll.ppll_max = 35000;
601 rinfo->pll.ppll_min = 12000;
602 rinfo->pll.mclk = 23000;
603 rinfo->pll.sclk = 23000;
604 rinfo->pll.ref_clk = 2700;
605 break;
606 case PCI_DEVICE_ID_ATI_RADEON_QL:
607 case PCI_DEVICE_ID_ATI_RADEON_QN:
608 case PCI_DEVICE_ID_ATI_RADEON_QO:
609 case PCI_DEVICE_ID_ATI_RADEON_Ql:
610 case PCI_DEVICE_ID_ATI_RADEON_BB:
611 rinfo->pll.ppll_max = 35000;
612 rinfo->pll.ppll_min = 12000;
613 rinfo->pll.mclk = 27500;
614 rinfo->pll.sclk = 27500;
615 rinfo->pll.ref_clk = 2700;
616 break;
617 case PCI_DEVICE_ID_ATI_RADEON_Id:
618 case PCI_DEVICE_ID_ATI_RADEON_Ie:
619 case PCI_DEVICE_ID_ATI_RADEON_If:
620 case PCI_DEVICE_ID_ATI_RADEON_Ig:
621 rinfo->pll.ppll_max = 35000;
622 rinfo->pll.ppll_min = 12000;
623 rinfo->pll.mclk = 25000;
624 rinfo->pll.sclk = 25000;
625 rinfo->pll.ref_clk = 2700;
626 break;
627 case PCI_DEVICE_ID_ATI_RADEON_ND:
628 case PCI_DEVICE_ID_ATI_RADEON_NE:
629 case PCI_DEVICE_ID_ATI_RADEON_NF:
630 case PCI_DEVICE_ID_ATI_RADEON_NG:
631 rinfo->pll.ppll_max = 40000;
632 rinfo->pll.ppll_min = 20000;
633 rinfo->pll.mclk = 27000;
634 rinfo->pll.sclk = 27000;
635 rinfo->pll.ref_clk = 2700;
636 break;
637 case PCI_DEVICE_ID_ATI_RADEON_QD:
638 case PCI_DEVICE_ID_ATI_RADEON_QE:
639 case PCI_DEVICE_ID_ATI_RADEON_QF:
640 case PCI_DEVICE_ID_ATI_RADEON_QG:
641 default:
642 rinfo->pll.ppll_max = 35000;
643 rinfo->pll.ppll_min = 12000;
644 rinfo->pll.mclk = 16600;
645 rinfo->pll.sclk = 16600;
646 rinfo->pll.ref_clk = 2700;
647 break;
648 }
649 rinfo->pll.ref_div = INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK;
650
651
David S. Miller9f47df22007-03-29 01:33:46 -0700652#if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 /*
Matt Mackall4a4efbd2006-01-03 13:27:11 +0100654 * Retrieve PLL infos from Open Firmware first
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 */
656 if (!force_measure_pll && radeon_read_xtal_OF(rinfo) == 0) {
Matt Mackall4a4efbd2006-01-03 13:27:11 +0100657 printk(KERN_INFO "radeonfb: Retrieved PLL infos from Open Firmware\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 goto found;
659 }
David S. Miller9f47df22007-03-29 01:33:46 -0700660#endif /* CONFIG_PPC_OF || CONFIG_SPARC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 /*
663 * Check out if we have an X86 which gave us some PLL informations
Matt Mackall4a4efbd2006-01-03 13:27:11 +0100664 * and if yes, retrieve them
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 */
666 if (!force_measure_pll && rinfo->bios_seg) {
667 u16 pll_info_block = BIOS_IN16(rinfo->fp_bios_start + 0x30);
668
669 rinfo->pll.sclk = BIOS_IN16(pll_info_block + 0x08);
670 rinfo->pll.mclk = BIOS_IN16(pll_info_block + 0x0a);
671 rinfo->pll.ref_clk = BIOS_IN16(pll_info_block + 0x0e);
672 rinfo->pll.ref_div = BIOS_IN16(pll_info_block + 0x10);
673 rinfo->pll.ppll_min = BIOS_IN32(pll_info_block + 0x12);
674 rinfo->pll.ppll_max = BIOS_IN32(pll_info_block + 0x16);
675
Matt Mackall4a4efbd2006-01-03 13:27:11 +0100676 printk(KERN_INFO "radeonfb: Retrieved PLL infos from BIOS\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 goto found;
678 }
679
680 /*
681 * We didn't get PLL parameters from either OF or BIOS, we try to
682 * probe them
683 */
684 if (radeon_probe_pll_params(rinfo) == 0) {
Matt Mackall4a4efbd2006-01-03 13:27:11 +0100685 printk(KERN_INFO "radeonfb: Retrieved PLL infos from registers\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 goto found;
687 }
688
689 /*
690 * Fall back to already-set defaults...
691 */
692 printk(KERN_INFO "radeonfb: Used default PLL infos\n");
693
694found:
695 /*
Matt Mackall4a4efbd2006-01-03 13:27:11 +0100696 * Some methods fail to retrieve SCLK and MCLK values, we apply default
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 * settings in this case (200Mhz). If that really happne often, we could
698 * fetch from registers instead...
699 */
700 if (rinfo->pll.mclk == 0)
701 rinfo->pll.mclk = 20000;
702 if (rinfo->pll.sclk == 0)
703 rinfo->pll.sclk = 20000;
704
705 printk("radeonfb: Reference=%d.%02d MHz (RefDiv=%d) Memory=%d.%02d Mhz, System=%d.%02d MHz\n",
706 rinfo->pll.ref_clk / 100, rinfo->pll.ref_clk % 100,
707 rinfo->pll.ref_div,
708 rinfo->pll.mclk / 100, rinfo->pll.mclk % 100,
709 rinfo->pll.sclk / 100, rinfo->pll.sclk % 100);
710 printk("radeonfb: PLL min %d max %d\n", rinfo->pll.ppll_min, rinfo->pll.ppll_max);
711}
712
713static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info)
714{
715 struct radeonfb_info *rinfo = info->par;
716 struct fb_var_screeninfo v;
717 int nom, den;
718 unsigned int pitch;
719
720 if (radeon_match_mode(rinfo, &v, var))
721 return -EINVAL;
722
723 switch (v.bits_per_pixel) {
724 case 0 ... 8:
725 v.bits_per_pixel = 8;
726 break;
727 case 9 ... 16:
728 v.bits_per_pixel = 16;
729 break;
730 case 17 ... 24:
731#if 0 /* Doesn't seem to work */
732 v.bits_per_pixel = 24;
733 break;
734#endif
735 return -EINVAL;
736 case 25 ... 32:
737 v.bits_per_pixel = 32;
738 break;
739 default:
740 return -EINVAL;
741 }
742
743 switch (var_to_depth(&v)) {
744 case 8:
745 nom = den = 1;
746 v.red.offset = v.green.offset = v.blue.offset = 0;
747 v.red.length = v.green.length = v.blue.length = 8;
748 v.transp.offset = v.transp.length = 0;
749 break;
750 case 15:
751 nom = 2;
752 den = 1;
753 v.red.offset = 10;
754 v.green.offset = 5;
755 v.blue.offset = 0;
756 v.red.length = v.green.length = v.blue.length = 5;
757 v.transp.offset = v.transp.length = 0;
758 break;
759 case 16:
760 nom = 2;
761 den = 1;
762 v.red.offset = 11;
763 v.green.offset = 5;
764 v.blue.offset = 0;
765 v.red.length = 5;
766 v.green.length = 6;
767 v.blue.length = 5;
768 v.transp.offset = v.transp.length = 0;
769 break;
770 case 24:
771 nom = 4;
772 den = 1;
773 v.red.offset = 16;
774 v.green.offset = 8;
775 v.blue.offset = 0;
776 v.red.length = v.blue.length = v.green.length = 8;
777 v.transp.offset = v.transp.length = 0;
778 break;
779 case 32:
780 nom = 4;
781 den = 1;
782 v.red.offset = 16;
783 v.green.offset = 8;
784 v.blue.offset = 0;
785 v.red.length = v.blue.length = v.green.length = 8;
786 v.transp.offset = 24;
787 v.transp.length = 8;
788 break;
789 default:
790 printk ("radeonfb: mode %dx%dx%d rejected, color depth invalid\n",
791 var->xres, var->yres, var->bits_per_pixel);
792 return -EINVAL;
793 }
794
795 if (v.yres_virtual < v.yres)
796 v.yres_virtual = v.yres;
797 if (v.xres_virtual < v.xres)
798 v.xres_virtual = v.xres;
799
800
801 /* XXX I'm adjusting xres_virtual to the pitch, that may help XFree
802 * with some panels, though I don't quite like this solution
803 */
804 if (rinfo->info->flags & FBINFO_HWACCEL_DISABLED) {
805 v.xres_virtual = v.xres_virtual & ~7ul;
806 } else {
807 pitch = ((v.xres_virtual * ((v.bits_per_pixel + 1) / 8) + 0x3f)
808 & ~(0x3f)) >> 6;
809 v.xres_virtual = (pitch << 6) / ((v.bits_per_pixel + 1) / 8);
810 }
811
812 if (((v.xres_virtual * v.yres_virtual * nom) / den) > rinfo->mapped_vram)
813 return -EINVAL;
814
815 if (v.xres_virtual < v.xres)
816 v.xres = v.xres_virtual;
817
818 if (v.xoffset < 0)
819 v.xoffset = 0;
820 if (v.yoffset < 0)
821 v.yoffset = 0;
822
823 if (v.xoffset > v.xres_virtual - v.xres)
824 v.xoffset = v.xres_virtual - v.xres - 1;
825
826 if (v.yoffset > v.yres_virtual - v.yres)
827 v.yoffset = v.yres_virtual - v.yres - 1;
828
829 v.red.msb_right = v.green.msb_right = v.blue.msb_right =
830 v.transp.offset = v.transp.length =
831 v.transp.msb_right = 0;
832
833 memcpy(var, &v, sizeof(v));
834
835 return 0;
836}
837
838
839static int radeonfb_pan_display (struct fb_var_screeninfo *var,
840 struct fb_info *info)
841{
842 struct radeonfb_info *rinfo = info->par;
843
844 if ((var->xoffset + var->xres > var->xres_virtual)
845 || (var->yoffset + var->yres > var->yres_virtual))
846 return -EINVAL;
847
848 if (rinfo->asleep)
849 return 0;
850
851 radeon_fifo_wait(2);
852 OUTREG(CRTC_OFFSET, ((var->yoffset * var->xres_virtual + var->xoffset)
853 * var->bits_per_pixel / 8) & ~7);
854 return 0;
855}
856
857
Christoph Hellwig67a66802006-01-14 13:21:25 -0800858static int radeonfb_ioctl (struct fb_info *info, unsigned int cmd,
859 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860{
861 struct radeonfb_info *rinfo = info->par;
862 unsigned int tmp;
863 u32 value = 0;
864 int rc;
865
866 switch (cmd) {
867 /*
868 * TODO: set mirror accordingly for non-Mobility chipsets with 2 CRTC's
869 * and do something better using 2nd CRTC instead of just hackish
870 * routing to second output
871 */
872 case FBIO_RADEON_SET_MIRROR:
873 if (!rinfo->is_mobility)
874 return -EINVAL;
875
876 rc = get_user(value, (__u32 __user *)arg);
877
878 if (rc)
879 return rc;
880
881 radeon_fifo_wait(2);
882 if (value & 0x01) {
883 tmp = INREG(LVDS_GEN_CNTL);
884
885 tmp |= (LVDS_ON | LVDS_BLON);
886 } else {
887 tmp = INREG(LVDS_GEN_CNTL);
888
889 tmp &= ~(LVDS_ON | LVDS_BLON);
890 }
891
892 OUTREG(LVDS_GEN_CNTL, tmp);
893
894 if (value & 0x02) {
895 tmp = INREG(CRTC_EXT_CNTL);
896 tmp |= CRTC_CRT_ON;
897
898 mirror = 1;
899 } else {
900 tmp = INREG(CRTC_EXT_CNTL);
901 tmp &= ~CRTC_CRT_ON;
902
903 mirror = 0;
904 }
905
906 OUTREG(CRTC_EXT_CNTL, tmp);
907
908 return 0;
909 case FBIO_RADEON_GET_MIRROR:
910 if (!rinfo->is_mobility)
911 return -EINVAL;
912
913 tmp = INREG(LVDS_GEN_CNTL);
914 if ((LVDS_ON | LVDS_BLON) & tmp)
915 value |= 0x01;
916
917 tmp = INREG(CRTC_EXT_CNTL);
918 if (CRTC_CRT_ON & tmp)
919 value |= 0x02;
920
921 return put_user(value, (__u32 __user *)arg);
922 default:
923 return -EINVAL;
924 }
925
926 return -EINVAL;
927}
928
929
930int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch)
931{
932 u32 val;
933 u32 tmp_pix_clks;
934 int unblank = 0;
935
936 if (rinfo->lock_blank)
937 return 0;
938
939 radeon_engine_idle();
940
941 val = INREG(CRTC_EXT_CNTL);
942 val &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS |
943 CRTC_VSYNC_DIS);
944 switch (blank) {
945 case FB_BLANK_VSYNC_SUSPEND:
946 val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS);
947 break;
948 case FB_BLANK_HSYNC_SUSPEND:
949 val |= (CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS);
950 break;
951 case FB_BLANK_POWERDOWN:
952 val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS |
953 CRTC_HSYNC_DIS);
954 break;
955 case FB_BLANK_NORMAL:
956 val |= CRTC_DISPLAY_DIS;
957 break;
958 case FB_BLANK_UNBLANK:
959 default:
960 unblank = 1;
961 }
962 OUTREG(CRTC_EXT_CNTL, val);
963
964
965 switch (rinfo->mon1_type) {
966 case MT_DFP:
967 if (unblank)
968 OUTREGP(FP_GEN_CNTL, (FP_FPON | FP_TMDS_EN),
969 ~(FP_FPON | FP_TMDS_EN));
970 else {
971 if (mode_switch || blank == FB_BLANK_NORMAL)
972 break;
973 OUTREGP(FP_GEN_CNTL, 0, ~(FP_FPON | FP_TMDS_EN));
974 }
975 break;
976 case MT_LCD:
977 del_timer_sync(&rinfo->lvds_timer);
978 val = INREG(LVDS_GEN_CNTL);
979 if (unblank) {
980 u32 target_val = (val & ~LVDS_DISPLAY_DIS) | LVDS_BLON | LVDS_ON
981 | LVDS_EN | (rinfo->init_state.lvds_gen_cntl
982 & (LVDS_DIGON | LVDS_BL_MOD_EN));
983 if ((val ^ target_val) == LVDS_DISPLAY_DIS)
984 OUTREG(LVDS_GEN_CNTL, target_val);
985 else if ((val ^ target_val) != 0) {
986 OUTREG(LVDS_GEN_CNTL, target_val
987 & ~(LVDS_ON | LVDS_BL_MOD_EN));
988 rinfo->init_state.lvds_gen_cntl &= ~LVDS_STATE_MASK;
989 rinfo->init_state.lvds_gen_cntl |=
990 target_val & LVDS_STATE_MASK;
991 if (mode_switch) {
992 radeon_msleep(rinfo->panel_info.pwr_delay);
993 OUTREG(LVDS_GEN_CNTL, target_val);
994 }
995 else {
996 rinfo->pending_lvds_gen_cntl = target_val;
997 mod_timer(&rinfo->lvds_timer,
998 jiffies +
999 msecs_to_jiffies(rinfo->panel_info.pwr_delay));
1000 }
1001 }
1002 } else {
1003 val |= LVDS_DISPLAY_DIS;
1004 OUTREG(LVDS_GEN_CNTL, val);
1005
1006 /* We don't do a full switch-off on a simple mode switch */
1007 if (mode_switch || blank == FB_BLANK_NORMAL)
1008 break;
1009
1010 /* Asic bug, when turning off LVDS_ON, we have to make sure
1011 * RADEON_PIXCLK_LVDS_ALWAYS_ON bit is off
1012 */
1013 tmp_pix_clks = INPLL(PIXCLKS_CNTL);
1014 if (rinfo->is_mobility || rinfo->is_IGP)
1015 OUTPLLP(PIXCLKS_CNTL, 0, ~PIXCLK_LVDS_ALWAYS_ONb);
1016 val &= ~(LVDS_BL_MOD_EN);
1017 OUTREG(LVDS_GEN_CNTL, val);
1018 udelay(100);
1019 val &= ~(LVDS_ON | LVDS_EN);
1020 OUTREG(LVDS_GEN_CNTL, val);
1021 val &= ~LVDS_DIGON;
1022 rinfo->pending_lvds_gen_cntl = val;
1023 mod_timer(&rinfo->lvds_timer,
1024 jiffies +
1025 msecs_to_jiffies(rinfo->panel_info.pwr_delay));
1026 rinfo->init_state.lvds_gen_cntl &= ~LVDS_STATE_MASK;
1027 rinfo->init_state.lvds_gen_cntl |= val & LVDS_STATE_MASK;
1028 if (rinfo->is_mobility || rinfo->is_IGP)
1029 OUTPLL(PIXCLKS_CNTL, tmp_pix_clks);
1030 }
1031 break;
1032 case MT_CRT:
1033 // todo: powerdown DAC
1034 default:
1035 break;
1036 }
1037
David S. Miller7ab87672007-03-01 18:29:14 -08001038 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039}
1040
1041static int radeonfb_blank (int blank, struct fb_info *info)
1042{
1043 struct radeonfb_info *rinfo = info->par;
1044
1045 if (rinfo->asleep)
1046 return 0;
1047
1048 return radeon_screen_blank(rinfo, blank, 0);
1049}
1050
Benjamin Herrenschmidt71494372005-05-01 08:59:22 -07001051static int radeon_setcolreg (unsigned regno, unsigned red, unsigned green,
1052 unsigned blue, unsigned transp,
1053 struct radeonfb_info *rinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 u32 pindex;
1056 unsigned int i;
Benjamin Herrenschmidt71494372005-05-01 08:59:22 -07001057
1058
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 if (regno > 255)
Alan Currydb77ec22006-03-27 01:17:30 -08001060 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
1062 red >>= 8;
1063 green >>= 8;
1064 blue >>= 8;
1065 rinfo->palette[regno].red = red;
1066 rinfo->palette[regno].green = green;
1067 rinfo->palette[regno].blue = blue;
1068
1069 /* default */
1070 pindex = regno;
1071
1072 if (!rinfo->asleep) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 radeon_fifo_wait(9);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
1075 if (rinfo->bpp == 16) {
1076 pindex = regno * 8;
1077
1078 if (rinfo->depth == 16 && regno > 63)
Alan Currydb77ec22006-03-27 01:17:30 -08001079 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 if (rinfo->depth == 15 && regno > 31)
Alan Currydb77ec22006-03-27 01:17:30 -08001081 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Benjamin Herrenschmidt71494372005-05-01 08:59:22 -07001083 /* For 565, the green component is mixed one order
1084 * below
1085 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 if (rinfo->depth == 16) {
1087 OUTREG(PALETTE_INDEX, pindex>>1);
Benjamin Herrenschmidt71494372005-05-01 08:59:22 -07001088 OUTREG(PALETTE_DATA,
1089 (rinfo->palette[regno>>1].red << 16) |
1090 (green << 8) |
1091 (rinfo->palette[regno>>1].blue));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 green = rinfo->palette[regno<<1].green;
1093 }
1094 }
1095
1096 if (rinfo->depth != 16 || regno < 32) {
1097 OUTREG(PALETTE_INDEX, pindex);
Benjamin Herrenschmidt71494372005-05-01 08:59:22 -07001098 OUTREG(PALETTE_DATA, (red << 16) |
1099 (green << 8) | blue);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 }
1102 if (regno < 16) {
Benjamin Herrenschmidt71494372005-05-01 08:59:22 -07001103 u32 *pal = rinfo->info->pseudo_palette;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 switch (rinfo->depth) {
1105 case 15:
1106 pal[regno] = (regno << 10) | (regno << 5) | regno;
1107 break;
1108 case 16:
1109 pal[regno] = (regno << 11) | (regno << 5) | regno;
1110 break;
1111 case 24:
1112 pal[regno] = (regno << 16) | (regno << 8) | regno;
1113 break;
1114 case 32:
1115 i = (regno << 8) | regno;
1116 pal[regno] = (i << 16) | i;
1117 break;
1118 }
1119 }
1120 return 0;
1121}
1122
Benjamin Herrenschmidt71494372005-05-01 08:59:22 -07001123static int radeonfb_setcolreg (unsigned regno, unsigned red, unsigned green,
1124 unsigned blue, unsigned transp,
1125 struct fb_info *info)
1126{
1127 struct radeonfb_info *rinfo = info->par;
1128 u32 dac_cntl2, vclk_cntl = 0;
1129 int rc;
1130
1131 if (!rinfo->asleep) {
1132 if (rinfo->is_mobility) {
1133 vclk_cntl = INPLL(VCLK_ECP_CNTL);
1134 OUTPLL(VCLK_ECP_CNTL,
1135 vclk_cntl & ~PIXCLK_DAC_ALWAYS_ONb);
1136 }
1137
1138 /* Make sure we are on first palette */
1139 if (rinfo->has_CRTC2) {
1140 dac_cntl2 = INREG(DAC_CNTL2);
1141 dac_cntl2 &= ~DAC2_PALETTE_ACCESS_CNTL;
1142 OUTREG(DAC_CNTL2, dac_cntl2);
1143 }
1144 }
1145
1146 rc = radeon_setcolreg (regno, red, green, blue, transp, rinfo);
1147
1148 if (!rinfo->asleep && rinfo->is_mobility)
1149 OUTPLL(VCLK_ECP_CNTL, vclk_cntl);
1150
1151 return rc;
1152}
1153
1154static int radeonfb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
1155{
1156 struct radeonfb_info *rinfo = info->par;
1157 u16 *red, *green, *blue, *transp;
1158 u32 dac_cntl2, vclk_cntl = 0;
1159 int i, start, rc = 0;
1160
1161 if (!rinfo->asleep) {
1162 if (rinfo->is_mobility) {
1163 vclk_cntl = INPLL(VCLK_ECP_CNTL);
1164 OUTPLL(VCLK_ECP_CNTL,
1165 vclk_cntl & ~PIXCLK_DAC_ALWAYS_ONb);
1166 }
1167
1168 /* Make sure we are on first palette */
1169 if (rinfo->has_CRTC2) {
1170 dac_cntl2 = INREG(DAC_CNTL2);
1171 dac_cntl2 &= ~DAC2_PALETTE_ACCESS_CNTL;
1172 OUTREG(DAC_CNTL2, dac_cntl2);
1173 }
1174 }
1175
1176 red = cmap->red;
1177 green = cmap->green;
1178 blue = cmap->blue;
1179 transp = cmap->transp;
1180 start = cmap->start;
1181
1182 for (i = 0; i < cmap->len; i++) {
1183 u_int hred, hgreen, hblue, htransp = 0xffff;
1184
1185 hred = *red++;
1186 hgreen = *green++;
1187 hblue = *blue++;
1188 if (transp)
1189 htransp = *transp++;
1190 rc = radeon_setcolreg (start++, hred, hgreen, hblue, htransp,
1191 rinfo);
1192 if (rc)
1193 break;
1194 }
1195
1196 if (!rinfo->asleep && rinfo->is_mobility)
1197 OUTPLL(VCLK_ECP_CNTL, vclk_cntl);
1198
1199 return rc;
1200}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
1202static void radeon_save_state (struct radeonfb_info *rinfo,
1203 struct radeon_regs *save)
1204{
1205 /* CRTC regs */
1206 save->crtc_gen_cntl = INREG(CRTC_GEN_CNTL);
1207 save->crtc_ext_cntl = INREG(CRTC_EXT_CNTL);
1208 save->crtc_more_cntl = INREG(CRTC_MORE_CNTL);
1209 save->dac_cntl = INREG(DAC_CNTL);
1210 save->crtc_h_total_disp = INREG(CRTC_H_TOTAL_DISP);
1211 save->crtc_h_sync_strt_wid = INREG(CRTC_H_SYNC_STRT_WID);
1212 save->crtc_v_total_disp = INREG(CRTC_V_TOTAL_DISP);
1213 save->crtc_v_sync_strt_wid = INREG(CRTC_V_SYNC_STRT_WID);
1214 save->crtc_pitch = INREG(CRTC_PITCH);
1215 save->surface_cntl = INREG(SURFACE_CNTL);
1216
1217 /* FP regs */
1218 save->fp_crtc_h_total_disp = INREG(FP_CRTC_H_TOTAL_DISP);
1219 save->fp_crtc_v_total_disp = INREG(FP_CRTC_V_TOTAL_DISP);
1220 save->fp_gen_cntl = INREG(FP_GEN_CNTL);
1221 save->fp_h_sync_strt_wid = INREG(FP_H_SYNC_STRT_WID);
1222 save->fp_horz_stretch = INREG(FP_HORZ_STRETCH);
1223 save->fp_v_sync_strt_wid = INREG(FP_V_SYNC_STRT_WID);
1224 save->fp_vert_stretch = INREG(FP_VERT_STRETCH);
1225 save->lvds_gen_cntl = INREG(LVDS_GEN_CNTL);
1226 save->lvds_pll_cntl = INREG(LVDS_PLL_CNTL);
1227 save->tmds_crc = INREG(TMDS_CRC);
1228 save->tmds_transmitter_cntl = INREG(TMDS_TRANSMITTER_CNTL);
1229 save->vclk_ecp_cntl = INPLL(VCLK_ECP_CNTL);
1230
1231 /* PLL regs */
1232 save->clk_cntl_index = INREG(CLOCK_CNTL_INDEX) & ~0x3f;
1233 radeon_pll_errata_after_index(rinfo);
1234 save->ppll_div_3 = INPLL(PPLL_DIV_3);
1235 save->ppll_ref_div = INPLL(PPLL_REF_DIV);
1236}
1237
1238
1239static void radeon_write_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs *mode)
1240{
1241 int i;
1242
1243 radeon_fifo_wait(20);
1244
1245 /* Workaround from XFree */
1246 if (rinfo->is_mobility) {
1247 /* A temporal workaround for the occational blanking on certain laptop
1248 * panels. This appears to related to the PLL divider registers
1249 * (fail to lock?). It occurs even when all dividers are the same
1250 * with their old settings. In this case we really don't need to
1251 * fiddle with PLL registers. By doing this we can avoid the blanking
1252 * problem with some panels.
1253 */
1254 if ((mode->ppll_ref_div == (INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK)) &&
1255 (mode->ppll_div_3 == (INPLL(PPLL_DIV_3) &
1256 (PPLL_POST3_DIV_MASK | PPLL_FB3_DIV_MASK)))) {
1257 /* We still have to force a switch to selected PPLL div thanks to
1258 * an XFree86 driver bug which will switch it away in some cases
1259 * even when using UseFDev */
1260 OUTREGP(CLOCK_CNTL_INDEX,
1261 mode->clk_cntl_index & PPLL_DIV_SEL_MASK,
1262 ~PPLL_DIV_SEL_MASK);
1263 radeon_pll_errata_after_index(rinfo);
1264 radeon_pll_errata_after_data(rinfo);
1265 return;
1266 }
1267 }
1268
1269 /* Swich VCKL clock input to CPUCLK so it stays fed while PPLL updates*/
1270 OUTPLLP(VCLK_ECP_CNTL, VCLK_SRC_SEL_CPUCLK, ~VCLK_SRC_SEL_MASK);
1271
1272 /* Reset PPLL & enable atomic update */
1273 OUTPLLP(PPLL_CNTL,
1274 PPLL_RESET | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN,
1275 ~(PPLL_RESET | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN));
1276
1277 /* Switch to selected PPLL divider */
1278 OUTREGP(CLOCK_CNTL_INDEX,
1279 mode->clk_cntl_index & PPLL_DIV_SEL_MASK,
1280 ~PPLL_DIV_SEL_MASK);
1281 radeon_pll_errata_after_index(rinfo);
1282 radeon_pll_errata_after_data(rinfo);
1283
1284 /* Set PPLL ref. div */
1285 if (rinfo->family == CHIP_FAMILY_R300 ||
1286 rinfo->family == CHIP_FAMILY_RS300 ||
1287 rinfo->family == CHIP_FAMILY_R350 ||
aherrman@arcor.def2740e42007-09-11 20:22:28 +02001288 rinfo->family == CHIP_FAMILY_RV350 ||
1289 rinfo->family == CHIP_FAMILY_RV380 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 if (mode->ppll_ref_div & R300_PPLL_REF_DIV_ACC_MASK) {
1291 /* When restoring console mode, use saved PPLL_REF_DIV
1292 * setting.
1293 */
1294 OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, 0);
1295 } else {
1296 /* R300 uses ref_div_acc field as real ref divider */
1297 OUTPLLP(PPLL_REF_DIV,
1298 (mode->ppll_ref_div << R300_PPLL_REF_DIV_ACC_SHIFT),
1299 ~R300_PPLL_REF_DIV_ACC_MASK);
1300 }
1301 } else
1302 OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, ~PPLL_REF_DIV_MASK);
1303
1304 /* Set PPLL divider 3 & post divider*/
1305 OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_FB3_DIV_MASK);
1306 OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_POST3_DIV_MASK);
1307
1308 /* Write update */
1309 while (INPLL(PPLL_REF_DIV) & PPLL_ATOMIC_UPDATE_R)
1310 ;
1311 OUTPLLP(PPLL_REF_DIV, PPLL_ATOMIC_UPDATE_W, ~PPLL_ATOMIC_UPDATE_W);
1312
1313 /* Wait read update complete */
1314 /* FIXME: Certain revisions of R300 can't recover here. Not sure of
1315 the cause yet, but this workaround will mask the problem for now.
1316 Other chips usually will pass at the very first test, so the
1317 workaround shouldn't have any effect on them. */
1318 for (i = 0; (i < 10000 && INPLL(PPLL_REF_DIV) & PPLL_ATOMIC_UPDATE_R); i++)
1319 ;
1320
1321 OUTPLL(HTOTAL_CNTL, 0);
1322
1323 /* Clear reset & atomic update */
1324 OUTPLLP(PPLL_CNTL, 0,
1325 ~(PPLL_RESET | PPLL_SLEEP | PPLL_ATOMIC_UPDATE_EN | PPLL_VGA_ATOMIC_UPDATE_EN));
1326
1327 /* We may want some locking ... oh well */
1328 radeon_msleep(5);
1329
1330 /* Switch back VCLK source to PPLL */
1331 OUTPLLP(VCLK_ECP_CNTL, VCLK_SRC_SEL_PPLLCLK, ~VCLK_SRC_SEL_MASK);
1332}
1333
1334/*
1335 * Timer function for delayed LVDS panel power up/down
1336 */
1337static void radeon_lvds_timer_func(unsigned long data)
1338{
1339 struct radeonfb_info *rinfo = (struct radeonfb_info *)data;
1340
1341 radeon_engine_idle();
1342
1343 OUTREG(LVDS_GEN_CNTL, rinfo->pending_lvds_gen_cntl);
1344}
1345
1346/*
1347 * Apply a video mode. This will apply the whole register set, including
1348 * the PLL registers, to the card
1349 */
1350void radeon_write_mode (struct radeonfb_info *rinfo, struct radeon_regs *mode,
1351 int regs_only)
1352{
1353 int i;
1354 int primary_mon = PRIMARY_MONITOR(rinfo);
1355
1356 if (nomodeset)
1357 return;
1358
1359 if (!regs_only)
1360 radeon_screen_blank(rinfo, FB_BLANK_NORMAL, 0);
1361
1362 radeon_fifo_wait(31);
1363 for (i=0; i<10; i++)
1364 OUTREG(common_regs[i].reg, common_regs[i].val);
1365
1366 /* Apply surface registers */
1367 for (i=0; i<8; i++) {
1368 OUTREG(SURFACE0_LOWER_BOUND + 0x10*i, mode->surf_lower_bound[i]);
1369 OUTREG(SURFACE0_UPPER_BOUND + 0x10*i, mode->surf_upper_bound[i]);
1370 OUTREG(SURFACE0_INFO + 0x10*i, mode->surf_info[i]);
1371 }
1372
1373 OUTREG(CRTC_GEN_CNTL, mode->crtc_gen_cntl);
1374 OUTREGP(CRTC_EXT_CNTL, mode->crtc_ext_cntl,
1375 ~(CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS));
1376 OUTREG(CRTC_MORE_CNTL, mode->crtc_more_cntl);
1377 OUTREGP(DAC_CNTL, mode->dac_cntl, DAC_RANGE_CNTL | DAC_BLANKING);
1378 OUTREG(CRTC_H_TOTAL_DISP, mode->crtc_h_total_disp);
1379 OUTREG(CRTC_H_SYNC_STRT_WID, mode->crtc_h_sync_strt_wid);
1380 OUTREG(CRTC_V_TOTAL_DISP, mode->crtc_v_total_disp);
1381 OUTREG(CRTC_V_SYNC_STRT_WID, mode->crtc_v_sync_strt_wid);
1382 OUTREG(CRTC_OFFSET, 0);
1383 OUTREG(CRTC_OFFSET_CNTL, 0);
1384 OUTREG(CRTC_PITCH, mode->crtc_pitch);
1385 OUTREG(SURFACE_CNTL, mode->surface_cntl);
1386
1387 radeon_write_pll_regs(rinfo, mode);
1388
1389 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1390 radeon_fifo_wait(10);
1391 OUTREG(FP_CRTC_H_TOTAL_DISP, mode->fp_crtc_h_total_disp);
1392 OUTREG(FP_CRTC_V_TOTAL_DISP, mode->fp_crtc_v_total_disp);
1393 OUTREG(FP_H_SYNC_STRT_WID, mode->fp_h_sync_strt_wid);
1394 OUTREG(FP_V_SYNC_STRT_WID, mode->fp_v_sync_strt_wid);
1395 OUTREG(FP_HORZ_STRETCH, mode->fp_horz_stretch);
1396 OUTREG(FP_VERT_STRETCH, mode->fp_vert_stretch);
1397 OUTREG(FP_GEN_CNTL, mode->fp_gen_cntl);
1398 OUTREG(TMDS_CRC, mode->tmds_crc);
1399 OUTREG(TMDS_TRANSMITTER_CNTL, mode->tmds_transmitter_cntl);
1400 }
1401
1402 if (!regs_only)
1403 radeon_screen_blank(rinfo, FB_BLANK_UNBLANK, 0);
1404
1405 radeon_fifo_wait(2);
1406 OUTPLL(VCLK_ECP_CNTL, mode->vclk_ecp_cntl);
1407
1408 return;
1409}
1410
1411/*
1412 * Calculate the PLL values for a given mode
1413 */
1414static void radeon_calc_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs *regs,
1415 unsigned long freq)
1416{
1417 const struct {
1418 int divider;
1419 int bitvalue;
1420 } *post_div,
1421 post_divs[] = {
1422 { 1, 0 },
1423 { 2, 1 },
1424 { 4, 2 },
1425 { 8, 3 },
1426 { 3, 4 },
1427 { 16, 5 },
1428 { 6, 6 },
1429 { 12, 7 },
1430 { 0, 0 },
1431 };
1432 int fb_div, pll_output_freq = 0;
1433 int uses_dvo = 0;
1434
1435 /* Check if the DVO port is enabled and sourced from the primary CRTC. I'm
1436 * not sure which model starts having FP2_GEN_CNTL, I assume anything more
1437 * recent than an r(v)100...
1438 */
1439#if 1
1440 /* XXX I had reports of flicker happening with the cinema display
1441 * on TMDS1 that seem to be fixed if I also forbit odd dividers in
1442 * this case. This could just be a bandwidth calculation issue, I
1443 * haven't implemented the bandwidth code yet, but in the meantime,
1444 * forcing uses_dvo to 1 fixes it and shouln't have bad side effects,
1445 * I haven't seen a case were were absolutely needed an odd PLL
1446 * divider. I'll find a better fix once I have more infos on the
1447 * real cause of the problem.
1448 */
1449 while (rinfo->has_CRTC2) {
1450 u32 fp2_gen_cntl = INREG(FP2_GEN_CNTL);
1451 u32 disp_output_cntl;
1452 int source;
1453
1454 /* FP2 path not enabled */
1455 if ((fp2_gen_cntl & FP2_ON) == 0)
1456 break;
1457 /* Not all chip revs have the same format for this register,
1458 * extract the source selection
1459 */
1460 if (rinfo->family == CHIP_FAMILY_R200 ||
1461 rinfo->family == CHIP_FAMILY_R300 ||
1462 rinfo->family == CHIP_FAMILY_R350 ||
1463 rinfo->family == CHIP_FAMILY_RV350) {
1464 source = (fp2_gen_cntl >> 10) & 0x3;
1465 /* sourced from transform unit, check for transform unit
1466 * own source
1467 */
1468 if (source == 3) {
1469 disp_output_cntl = INREG(DISP_OUTPUT_CNTL);
1470 source = (disp_output_cntl >> 12) & 0x3;
1471 }
1472 } else
1473 source = (fp2_gen_cntl >> 13) & 0x1;
1474 /* sourced from CRTC2 -> exit */
1475 if (source == 1)
1476 break;
1477
1478 /* so we end up on CRTC1, let's set uses_dvo to 1 now */
1479 uses_dvo = 1;
1480 break;
1481 }
1482#else
1483 uses_dvo = 1;
1484#endif
1485 if (freq > rinfo->pll.ppll_max)
1486 freq = rinfo->pll.ppll_max;
1487 if (freq*12 < rinfo->pll.ppll_min)
1488 freq = rinfo->pll.ppll_min / 12;
1489 RTRACE("freq = %lu, PLL min = %u, PLL max = %u\n",
1490 freq, rinfo->pll.ppll_min, rinfo->pll.ppll_max);
1491
1492 for (post_div = &post_divs[0]; post_div->divider; ++post_div) {
1493 pll_output_freq = post_div->divider * freq;
1494 /* If we output to the DVO port (external TMDS), we don't allow an
1495 * odd PLL divider as those aren't supported on this path
1496 */
1497 if (uses_dvo && (post_div->divider & 1))
1498 continue;
1499 if (pll_output_freq >= rinfo->pll.ppll_min &&
1500 pll_output_freq <= rinfo->pll.ppll_max)
1501 break;
1502 }
1503
1504 /* If we fall through the bottom, try the "default value"
1505 given by the terminal post_div->bitvalue */
1506 if ( !post_div->divider ) {
1507 post_div = &post_divs[post_div->bitvalue];
1508 pll_output_freq = post_div->divider * freq;
1509 }
1510 RTRACE("ref_div = %d, ref_clk = %d, output_freq = %d\n",
1511 rinfo->pll.ref_div, rinfo->pll.ref_clk,
1512 pll_output_freq);
1513
1514 /* If we fall through the bottom, try the "default value"
1515 given by the terminal post_div->bitvalue */
1516 if ( !post_div->divider ) {
1517 post_div = &post_divs[post_div->bitvalue];
1518 pll_output_freq = post_div->divider * freq;
1519 }
1520 RTRACE("ref_div = %d, ref_clk = %d, output_freq = %d\n",
1521 rinfo->pll.ref_div, rinfo->pll.ref_clk,
1522 pll_output_freq);
1523
1524 fb_div = round_div(rinfo->pll.ref_div*pll_output_freq,
1525 rinfo->pll.ref_clk);
1526 regs->ppll_ref_div = rinfo->pll.ref_div;
1527 regs->ppll_div_3 = fb_div | (post_div->bitvalue << 16);
1528
1529 RTRACE("post div = 0x%x\n", post_div->bitvalue);
1530 RTRACE("fb_div = 0x%x\n", fb_div);
1531 RTRACE("ppll_div_3 = 0x%x\n", regs->ppll_div_3);
1532}
1533
1534static int radeonfb_set_par(struct fb_info *info)
1535{
1536 struct radeonfb_info *rinfo = info->par;
1537 struct fb_var_screeninfo *mode = &info->var;
1538 struct radeon_regs *newmode;
1539 int hTotal, vTotal, hSyncStart, hSyncEnd,
1540 hSyncPol, vSyncStart, vSyncEnd, vSyncPol, cSync;
1541 u8 hsync_adj_tab[] = {0, 0x12, 9, 9, 6, 5};
1542 u8 hsync_fudge_fp[] = {2, 2, 0, 0, 5, 5};
1543 u32 sync, h_sync_pol, v_sync_pol, dotClock, pixClock;
1544 int i, freq;
1545 int format = 0;
1546 int nopllcalc = 0;
1547 int hsync_start, hsync_fudge, bytpp, hsync_wid, vsync_wid;
1548 int primary_mon = PRIMARY_MONITOR(rinfo);
1549 int depth = var_to_depth(mode);
1550 int use_rmx = 0;
1551
1552 newmode = kmalloc(sizeof(struct radeon_regs), GFP_KERNEL);
1553 if (!newmode)
1554 return -ENOMEM;
1555
1556 /* We always want engine to be idle on a mode switch, even
1557 * if we won't actually change the mode
1558 */
1559 radeon_engine_idle();
1560
1561 hSyncStart = mode->xres + mode->right_margin;
1562 hSyncEnd = hSyncStart + mode->hsync_len;
1563 hTotal = hSyncEnd + mode->left_margin;
1564
1565 vSyncStart = mode->yres + mode->lower_margin;
1566 vSyncEnd = vSyncStart + mode->vsync_len;
1567 vTotal = vSyncEnd + mode->upper_margin;
1568 pixClock = mode->pixclock;
1569
1570 sync = mode->sync;
1571 h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
1572 v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
1573
1574 if (primary_mon == MT_DFP || primary_mon == MT_LCD) {
1575 if (rinfo->panel_info.xres < mode->xres)
1576 mode->xres = rinfo->panel_info.xres;
1577 if (rinfo->panel_info.yres < mode->yres)
1578 mode->yres = rinfo->panel_info.yres;
1579
1580 hTotal = mode->xres + rinfo->panel_info.hblank;
1581 hSyncStart = mode->xres + rinfo->panel_info.hOver_plus;
1582 hSyncEnd = hSyncStart + rinfo->panel_info.hSync_width;
1583
1584 vTotal = mode->yres + rinfo->panel_info.vblank;
1585 vSyncStart = mode->yres + rinfo->panel_info.vOver_plus;
1586 vSyncEnd = vSyncStart + rinfo->panel_info.vSync_width;
1587
1588 h_sync_pol = !rinfo->panel_info.hAct_high;
1589 v_sync_pol = !rinfo->panel_info.vAct_high;
1590
1591 pixClock = 100000000 / rinfo->panel_info.clock;
1592
1593 if (rinfo->panel_info.use_bios_dividers) {
1594 nopllcalc = 1;
1595 newmode->ppll_div_3 = rinfo->panel_info.fbk_divider |
1596 (rinfo->panel_info.post_divider << 16);
1597 newmode->ppll_ref_div = rinfo->panel_info.ref_divider;
1598 }
1599 }
1600 dotClock = 1000000000 / pixClock;
1601 freq = dotClock / 10; /* x100 */
1602
1603 RTRACE("hStart = %d, hEnd = %d, hTotal = %d\n",
1604 hSyncStart, hSyncEnd, hTotal);
1605 RTRACE("vStart = %d, vEnd = %d, vTotal = %d\n",
1606 vSyncStart, vSyncEnd, vTotal);
1607
1608 hsync_wid = (hSyncEnd - hSyncStart) / 8;
1609 vsync_wid = vSyncEnd - vSyncStart;
1610 if (hsync_wid == 0)
1611 hsync_wid = 1;
1612 else if (hsync_wid > 0x3f) /* max */
1613 hsync_wid = 0x3f;
1614
1615 if (vsync_wid == 0)
1616 vsync_wid = 1;
1617 else if (vsync_wid > 0x1f) /* max */
1618 vsync_wid = 0x1f;
1619
1620 hSyncPol = mode->sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
1621 vSyncPol = mode->sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
1622
1623 cSync = mode->sync & FB_SYNC_COMP_HIGH_ACT ? (1 << 4) : 0;
1624
1625 format = radeon_get_dstbpp(depth);
1626 bytpp = mode->bits_per_pixel >> 3;
1627
1628 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD))
1629 hsync_fudge = hsync_fudge_fp[format-1];
1630 else
1631 hsync_fudge = hsync_adj_tab[format-1];
1632
1633 hsync_start = hSyncStart - 8 + hsync_fudge;
1634
1635 newmode->crtc_gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN |
1636 (format << 8);
1637
1638 /* Clear auto-center etc... */
1639 newmode->crtc_more_cntl = rinfo->init_state.crtc_more_cntl;
1640 newmode->crtc_more_cntl &= 0xfffffff0;
1641
1642 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1643 newmode->crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN;
1644 if (mirror)
1645 newmode->crtc_ext_cntl |= CRTC_CRT_ON;
1646
1647 newmode->crtc_gen_cntl &= ~(CRTC_DBL_SCAN_EN |
1648 CRTC_INTERLACE_EN);
1649 } else {
1650 newmode->crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN |
1651 CRTC_CRT_ON;
1652 }
1653
1654 newmode->dac_cntl = /* INREG(DAC_CNTL) | */ DAC_MASK_ALL | DAC_VGA_ADR_EN |
1655 DAC_8BIT_EN;
1656
1657 newmode->crtc_h_total_disp = ((((hTotal / 8) - 1) & 0x3ff) |
1658 (((mode->xres / 8) - 1) << 16));
1659
1660 newmode->crtc_h_sync_strt_wid = ((hsync_start & 0x1fff) |
1661 (hsync_wid << 16) | (h_sync_pol << 23));
1662
1663 newmode->crtc_v_total_disp = ((vTotal - 1) & 0xffff) |
1664 ((mode->yres - 1) << 16);
1665
1666 newmode->crtc_v_sync_strt_wid = (((vSyncStart - 1) & 0xfff) |
1667 (vsync_wid << 16) | (v_sync_pol << 23));
1668
1669 if (!(info->flags & FBINFO_HWACCEL_DISABLED)) {
1670 /* We first calculate the engine pitch */
1671 rinfo->pitch = ((mode->xres_virtual * ((mode->bits_per_pixel + 1) / 8) + 0x3f)
1672 & ~(0x3f)) >> 6;
1673
1674 /* Then, re-multiply it to get the CRTC pitch */
1675 newmode->crtc_pitch = (rinfo->pitch << 3) / ((mode->bits_per_pixel + 1) / 8);
1676 } else
1677 newmode->crtc_pitch = (mode->xres_virtual >> 3);
1678
1679 newmode->crtc_pitch |= (newmode->crtc_pitch << 16);
1680
1681 /*
1682 * It looks like recent chips have a problem with SURFACE_CNTL,
1683 * setting SURF_TRANSLATION_DIS completely disables the
1684 * swapper as well, so we leave it unset now.
1685 */
1686 newmode->surface_cntl = 0;
1687
1688#if defined(__BIG_ENDIAN)
1689
1690 /* Setup swapping on both apertures, though we currently
1691 * only use aperture 0, enabling swapper on aperture 1
1692 * won't harm
1693 */
1694 switch (mode->bits_per_pixel) {
1695 case 16:
1696 newmode->surface_cntl |= NONSURF_AP0_SWP_16BPP;
1697 newmode->surface_cntl |= NONSURF_AP1_SWP_16BPP;
1698 break;
1699 case 24:
1700 case 32:
1701 newmode->surface_cntl |= NONSURF_AP0_SWP_32BPP;
1702 newmode->surface_cntl |= NONSURF_AP1_SWP_32BPP;
1703 break;
1704 }
1705#endif
1706
1707 /* Clear surface registers */
1708 for (i=0; i<8; i++) {
1709 newmode->surf_lower_bound[i] = 0;
1710 newmode->surf_upper_bound[i] = 0x1f;
1711 newmode->surf_info[i] = 0;
1712 }
1713
1714 RTRACE("h_total_disp = 0x%x\t hsync_strt_wid = 0x%x\n",
1715 newmode->crtc_h_total_disp, newmode->crtc_h_sync_strt_wid);
1716 RTRACE("v_total_disp = 0x%x\t vsync_strt_wid = 0x%x\n",
1717 newmode->crtc_v_total_disp, newmode->crtc_v_sync_strt_wid);
1718
1719 rinfo->bpp = mode->bits_per_pixel;
1720 rinfo->depth = depth;
1721
1722 RTRACE("pixclock = %lu\n", (unsigned long)pixClock);
1723 RTRACE("freq = %lu\n", (unsigned long)freq);
1724
1725 /* We use PPLL_DIV_3 */
1726 newmode->clk_cntl_index = 0x300;
1727
1728 /* Calculate PPLL value if necessary */
1729 if (!nopllcalc)
1730 radeon_calc_pll_regs(rinfo, newmode, freq);
1731
1732 newmode->vclk_ecp_cntl = rinfo->init_state.vclk_ecp_cntl;
1733
1734 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1735 unsigned int hRatio, vRatio;
1736
1737 if (mode->xres > rinfo->panel_info.xres)
1738 mode->xres = rinfo->panel_info.xres;
1739 if (mode->yres > rinfo->panel_info.yres)
1740 mode->yres = rinfo->panel_info.yres;
1741
1742 newmode->fp_horz_stretch = (((rinfo->panel_info.xres / 8) - 1)
1743 << HORZ_PANEL_SHIFT);
1744 newmode->fp_vert_stretch = ((rinfo->panel_info.yres - 1)
1745 << VERT_PANEL_SHIFT);
1746
1747 if (mode->xres != rinfo->panel_info.xres) {
1748 hRatio = round_div(mode->xres * HORZ_STRETCH_RATIO_MAX,
1749 rinfo->panel_info.xres);
1750 newmode->fp_horz_stretch = (((((unsigned long)hRatio) & HORZ_STRETCH_RATIO_MASK)) |
1751 (newmode->fp_horz_stretch &
1752 (HORZ_PANEL_SIZE | HORZ_FP_LOOP_STRETCH |
1753 HORZ_AUTO_RATIO_INC)));
1754 newmode->fp_horz_stretch |= (HORZ_STRETCH_BLEND |
1755 HORZ_STRETCH_ENABLE);
1756 use_rmx = 1;
1757 }
1758 newmode->fp_horz_stretch &= ~HORZ_AUTO_RATIO;
1759
1760 if (mode->yres != rinfo->panel_info.yres) {
1761 vRatio = round_div(mode->yres * VERT_STRETCH_RATIO_MAX,
1762 rinfo->panel_info.yres);
1763 newmode->fp_vert_stretch = (((((unsigned long)vRatio) & VERT_STRETCH_RATIO_MASK)) |
1764 (newmode->fp_vert_stretch &
1765 (VERT_PANEL_SIZE | VERT_STRETCH_RESERVED)));
1766 newmode->fp_vert_stretch |= (VERT_STRETCH_BLEND |
1767 VERT_STRETCH_ENABLE);
1768 use_rmx = 1;
1769 }
1770 newmode->fp_vert_stretch &= ~VERT_AUTO_RATIO_EN;
1771
1772 newmode->fp_gen_cntl = (rinfo->init_state.fp_gen_cntl & (u32)
1773 ~(FP_SEL_CRTC2 |
1774 FP_RMX_HVSYNC_CONTROL_EN |
1775 FP_DFP_SYNC_SEL |
1776 FP_CRT_SYNC_SEL |
1777 FP_CRTC_LOCK_8DOT |
1778 FP_USE_SHADOW_EN |
1779 FP_CRTC_USE_SHADOW_VEND |
1780 FP_CRT_SYNC_ALT));
1781
1782 newmode->fp_gen_cntl |= (FP_CRTC_DONT_SHADOW_VPAR |
1783 FP_CRTC_DONT_SHADOW_HEND |
1784 FP_PANEL_FORMAT);
1785
1786 if (IS_R300_VARIANT(rinfo) ||
1787 (rinfo->family == CHIP_FAMILY_R200)) {
1788 newmode->fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
1789 if (use_rmx)
1790 newmode->fp_gen_cntl |= R200_FP_SOURCE_SEL_RMX;
1791 else
1792 newmode->fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC1;
1793 } else
1794 newmode->fp_gen_cntl |= FP_SEL_CRTC1;
1795
1796 newmode->lvds_gen_cntl = rinfo->init_state.lvds_gen_cntl;
1797 newmode->lvds_pll_cntl = rinfo->init_state.lvds_pll_cntl;
1798 newmode->tmds_crc = rinfo->init_state.tmds_crc;
1799 newmode->tmds_transmitter_cntl = rinfo->init_state.tmds_transmitter_cntl;
1800
1801 if (primary_mon == MT_LCD) {
1802 newmode->lvds_gen_cntl |= (LVDS_ON | LVDS_BLON);
1803 newmode->fp_gen_cntl &= ~(FP_FPON | FP_TMDS_EN);
1804 } else {
1805 /* DFP */
1806 newmode->fp_gen_cntl |= (FP_FPON | FP_TMDS_EN);
1807 newmode->tmds_transmitter_cntl &= ~(TMDS_PLLRST);
1808 /* TMDS_PLL_EN bit is reversed on RV (and mobility) chips */
1809 if (IS_R300_VARIANT(rinfo) ||
1810 (rinfo->family == CHIP_FAMILY_R200) || !rinfo->has_CRTC2)
1811 newmode->tmds_transmitter_cntl &= ~TMDS_PLL_EN;
1812 else
1813 newmode->tmds_transmitter_cntl |= TMDS_PLL_EN;
1814 newmode->crtc_ext_cntl &= ~CRTC_CRT_ON;
1815 }
1816
1817 newmode->fp_crtc_h_total_disp = (((rinfo->panel_info.hblank / 8) & 0x3ff) |
1818 (((mode->xres / 8) - 1) << 16));
1819 newmode->fp_crtc_v_total_disp = (rinfo->panel_info.vblank & 0xffff) |
1820 ((mode->yres - 1) << 16);
1821 newmode->fp_h_sync_strt_wid = ((rinfo->panel_info.hOver_plus & 0x1fff) |
1822 (hsync_wid << 16) | (h_sync_pol << 23));
1823 newmode->fp_v_sync_strt_wid = ((rinfo->panel_info.vOver_plus & 0xfff) |
1824 (vsync_wid << 16) | (v_sync_pol << 23));
1825 }
1826
1827 /* do it! */
1828 if (!rinfo->asleep) {
1829 memcpy(&rinfo->state, newmode, sizeof(*newmode));
1830 radeon_write_mode (rinfo, newmode, 0);
1831 /* (re)initialize the engine */
1832 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
1833 radeonfb_engine_init (rinfo);
1834 }
1835 /* Update fix */
1836 if (!(info->flags & FBINFO_HWACCEL_DISABLED))
1837 info->fix.line_length = rinfo->pitch*64;
1838 else
1839 info->fix.line_length = mode->xres_virtual
1840 * ((mode->bits_per_pixel + 1) / 8);
1841 info->fix.visual = rinfo->depth == 8 ? FB_VISUAL_PSEUDOCOLOR
1842 : FB_VISUAL_DIRECTCOLOR;
1843
1844#ifdef CONFIG_BOOTX_TEXT
1845 /* Update debug text engine */
1846 btext_update_display(rinfo->fb_base_phys, mode->xres, mode->yres,
1847 rinfo->depth, info->fix.line_length);
1848#endif
1849
1850 kfree(newmode);
1851 return 0;
1852}
1853
1854
1855static struct fb_ops radeonfb_ops = {
1856 .owner = THIS_MODULE,
1857 .fb_check_var = radeonfb_check_var,
1858 .fb_set_par = radeonfb_set_par,
1859 .fb_setcolreg = radeonfb_setcolreg,
Benjamin Herrenschmidt71494372005-05-01 08:59:22 -07001860 .fb_setcmap = radeonfb_setcmap,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 .fb_pan_display = radeonfb_pan_display,
1862 .fb_blank = radeonfb_blank,
1863 .fb_ioctl = radeonfb_ioctl,
1864 .fb_sync = radeonfb_sync,
1865 .fb_fillrect = radeonfb_fillrect,
1866 .fb_copyarea = radeonfb_copyarea,
1867 .fb_imageblit = radeonfb_imageblit,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868};
1869
1870
1871static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo)
1872{
1873 struct fb_info *info = rinfo->info;
1874
1875 info->par = rinfo;
1876 info->pseudo_palette = rinfo->pseudo_palette;
1877 info->flags = FBINFO_DEFAULT
1878 | FBINFO_HWACCEL_COPYAREA
1879 | FBINFO_HWACCEL_FILLRECT
1880 | FBINFO_HWACCEL_XPAN
1881 | FBINFO_HWACCEL_YPAN;
1882 info->fbops = &radeonfb_ops;
1883 info->screen_base = rinfo->fb_base;
1884 info->screen_size = rinfo->mapped_vram;
1885 /* Fill fix common fields */
1886 strlcpy(info->fix.id, rinfo->name, sizeof(info->fix.id));
1887 info->fix.smem_start = rinfo->fb_base_phys;
1888 info->fix.smem_len = rinfo->video_ram;
1889 info->fix.type = FB_TYPE_PACKED_PIXELS;
1890 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
1891 info->fix.xpanstep = 8;
1892 info->fix.ypanstep = 1;
1893 info->fix.ywrapstep = 0;
1894 info->fix.type_aux = 0;
1895 info->fix.mmio_start = rinfo->mmio_base_phys;
1896 info->fix.mmio_len = RADEON_REGSIZE;
1897 info->fix.accel = FB_ACCEL_ATI_RADEON;
1898
1899 fb_alloc_cmap(&info->cmap, 256, 0);
1900
1901 if (noaccel)
1902 info->flags |= FBINFO_HWACCEL_DISABLED;
1903
1904 return 0;
1905}
1906
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907/*
1908 * This reconfigure the card's internal memory map. In theory, we'd like
1909 * to setup the card's memory at the same address as it's PCI bus address,
1910 * and the AGP aperture right after that so that system RAM on 32 bits
1911 * machines at least, is directly accessible. However, doing so would
1912 * conflict with the current XFree drivers...
1913 * Ultimately, I hope XFree, GATOS and ATI binary drivers will all agree
1914 * on the proper way to set this up and duplicate this here. In the meantime,
1915 * I put the card's memory at 0 in card space and AGP at some random high
1916 * local (0xe0000000 for now) that will be changed by XFree/DRI anyway
1917 */
1918#ifdef CONFIG_PPC_OF
1919#undef SET_MC_FB_FROM_APERTURE
1920static void fixup_memory_mappings(struct radeonfb_info *rinfo)
1921{
1922 u32 save_crtc_gen_cntl, save_crtc2_gen_cntl = 0;
1923 u32 save_crtc_ext_cntl;
1924 u32 aper_base, aper_size;
1925 u32 agp_base;
1926
1927 /* First, we disable display to avoid interfering */
1928 if (rinfo->has_CRTC2) {
1929 save_crtc2_gen_cntl = INREG(CRTC2_GEN_CNTL);
1930 OUTREG(CRTC2_GEN_CNTL, save_crtc2_gen_cntl | CRTC2_DISP_REQ_EN_B);
1931 }
1932 save_crtc_gen_cntl = INREG(CRTC_GEN_CNTL);
1933 save_crtc_ext_cntl = INREG(CRTC_EXT_CNTL);
1934
1935 OUTREG(CRTC_EXT_CNTL, save_crtc_ext_cntl | CRTC_DISPLAY_DIS);
1936 OUTREG(CRTC_GEN_CNTL, save_crtc_gen_cntl | CRTC_DISP_REQ_EN_B);
1937 mdelay(100);
1938
1939 aper_base = INREG(CONFIG_APER_0_BASE);
1940 aper_size = INREG(CONFIG_APER_SIZE);
1941
1942#ifdef SET_MC_FB_FROM_APERTURE
1943 /* Set framebuffer to be at the same address as set in PCI BAR */
1944 OUTREG(MC_FB_LOCATION,
1945 ((aper_base + aper_size - 1) & 0xffff0000) | (aper_base >> 16));
1946 rinfo->fb_local_base = aper_base;
1947#else
1948 OUTREG(MC_FB_LOCATION, 0x7fff0000);
1949 rinfo->fb_local_base = 0;
1950#endif
1951 agp_base = aper_base + aper_size;
1952 if (agp_base & 0xf0000000)
1953 agp_base = (aper_base | 0x0fffffff) + 1;
1954
1955 /* Set AGP to be just after the framebuffer on a 256Mb boundary. This
1956 * assumes the FB isn't mapped to 0xf0000000 or above, but this is
1957 * always the case on PPCs afaik.
1958 */
1959#ifdef SET_MC_FB_FROM_APERTURE
1960 OUTREG(MC_AGP_LOCATION, 0xffff0000 | (agp_base >> 16));
1961#else
1962 OUTREG(MC_AGP_LOCATION, 0xffffe000);
1963#endif
1964
1965 /* Fixup the display base addresses & engine offsets while we
1966 * are at it as well
1967 */
1968#ifdef SET_MC_FB_FROM_APERTURE
1969 OUTREG(DISPLAY_BASE_ADDR, aper_base);
1970 if (rinfo->has_CRTC2)
1971 OUTREG(CRTC2_DISPLAY_BASE_ADDR, aper_base);
1972 OUTREG(OV0_BASE_ADDR, aper_base);
1973#else
1974 OUTREG(DISPLAY_BASE_ADDR, 0);
1975 if (rinfo->has_CRTC2)
1976 OUTREG(CRTC2_DISPLAY_BASE_ADDR, 0);
1977 OUTREG(OV0_BASE_ADDR, 0);
1978#endif
1979 mdelay(100);
1980
1981 /* Restore display settings */
1982 OUTREG(CRTC_GEN_CNTL, save_crtc_gen_cntl);
1983 OUTREG(CRTC_EXT_CNTL, save_crtc_ext_cntl);
1984 if (rinfo->has_CRTC2)
1985 OUTREG(CRTC2_GEN_CNTL, save_crtc2_gen_cntl);
1986
1987 RTRACE("aper_base: %08x MC_FB_LOC to: %08x, MC_AGP_LOC to: %08x\n",
1988 aper_base,
1989 ((aper_base + aper_size - 1) & 0xffff0000) | (aper_base >> 16),
1990 0xffff0000 | (agp_base >> 16));
1991}
1992#endif /* CONFIG_PPC_OF */
1993
1994
1995static void radeon_identify_vram(struct radeonfb_info *rinfo)
1996{
1997 u32 tmp;
1998
1999 /* framebuffer size */
2000 if ((rinfo->family == CHIP_FAMILY_RS100) ||
2001 (rinfo->family == CHIP_FAMILY_RS200) ||
johan henrikssondd144712007-05-08 00:37:59 -07002002 (rinfo->family == CHIP_FAMILY_RS300) ||
2003 (rinfo->family == CHIP_FAMILY_RS480) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 u32 tom = INREG(NB_TOM);
2005 tmp = ((((tom >> 16) - (tom & 0xffff) + 1) << 6) * 1024);
2006
2007 radeon_fifo_wait(6);
2008 OUTREG(MC_FB_LOCATION, tom);
2009 OUTREG(DISPLAY_BASE_ADDR, (tom & 0xffff) << 16);
2010 OUTREG(CRTC2_DISPLAY_BASE_ADDR, (tom & 0xffff) << 16);
2011 OUTREG(OV0_BASE_ADDR, (tom & 0xffff) << 16);
2012
2013 /* This is supposed to fix the crtc2 noise problem. */
2014 OUTREG(GRPH2_BUFFER_CNTL, INREG(GRPH2_BUFFER_CNTL) & ~0x7f0000);
2015
2016 if ((rinfo->family == CHIP_FAMILY_RS100) ||
2017 (rinfo->family == CHIP_FAMILY_RS200)) {
2018 /* This is to workaround the asic bug for RMX, some versions
2019 of BIOS dosen't have this register initialized correctly.
2020 */
2021 OUTREGP(CRTC_MORE_CNTL, CRTC_H_CUTOFF_ACTIVE_EN,
2022 ~CRTC_H_CUTOFF_ACTIVE_EN);
2023 }
2024 } else {
2025 tmp = INREG(CONFIG_MEMSIZE);
2026 }
2027
2028 /* mem size is bits [28:0], mask off the rest */
2029 rinfo->video_ram = tmp & CONFIG_MEMSIZE_MASK;
2030
2031 /*
2032 * Hack to get around some busted production M6's
2033 * reporting no ram
2034 */
2035 if (rinfo->video_ram == 0) {
2036 switch (rinfo->pdev->device) {
2037 case PCI_CHIP_RADEON_LY:
2038 case PCI_CHIP_RADEON_LZ:
2039 rinfo->video_ram = 8192 * 1024;
2040 break;
2041 default:
2042 break;
2043 }
2044 }
2045
2046
2047 /*
2048 * Now try to identify VRAM type
2049 */
2050 if (rinfo->is_IGP || (rinfo->family >= CHIP_FAMILY_R300) ||
2051 (INREG(MEM_SDRAM_MODE_REG) & (1<<30)))
2052 rinfo->vram_ddr = 1;
2053 else
2054 rinfo->vram_ddr = 0;
2055
2056 tmp = INREG(MEM_CNTL);
2057 if (IS_R300_VARIANT(rinfo)) {
2058 tmp &= R300_MEM_NUM_CHANNELS_MASK;
2059 switch (tmp) {
2060 case 0: rinfo->vram_width = 64; break;
2061 case 1: rinfo->vram_width = 128; break;
2062 case 2: rinfo->vram_width = 256; break;
2063 default: rinfo->vram_width = 128; break;
2064 }
2065 } else if ((rinfo->family == CHIP_FAMILY_RV100) ||
2066 (rinfo->family == CHIP_FAMILY_RS100) ||
2067 (rinfo->family == CHIP_FAMILY_RS200)){
2068 if (tmp & RV100_MEM_HALF_MODE)
2069 rinfo->vram_width = 32;
2070 else
2071 rinfo->vram_width = 64;
2072 } else {
2073 if (tmp & MEM_NUM_CHANNELS_MASK)
2074 rinfo->vram_width = 128;
2075 else
2076 rinfo->vram_width = 64;
2077 }
2078
2079 /* This may not be correct, as some cards can have half of channel disabled
2080 * ToDo: identify these cases
2081 */
2082
2083 RTRACE("radeonfb (%s): Found %ldk of %s %d bits wide videoram\n",
2084 pci_name(rinfo->pdev),
2085 rinfo->video_ram / 1024,
2086 rinfo->vram_ddr ? "DDR" : "SDRAM",
2087 rinfo->vram_width);
2088}
2089
2090/*
2091 * Sysfs
2092 */
2093
2094static ssize_t radeon_show_one_edid(char *buf, loff_t off, size_t count, const u8 *edid)
2095{
2096 if (off > EDID_LENGTH)
2097 return 0;
2098
2099 if (off + count > EDID_LENGTH)
2100 count = EDID_LENGTH - off;
2101
2102 memcpy(buf, edid + off, count);
2103
2104 return count;
2105}
2106
2107
Zhang Rui91a69022007-06-09 13:57:22 +08002108static ssize_t radeon_show_edid1(struct kobject *kobj,
2109 struct bin_attribute *bin_attr,
2110 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111{
2112 struct device *dev = container_of(kobj, struct device, kobj);
2113 struct pci_dev *pdev = to_pci_dev(dev);
2114 struct fb_info *info = pci_get_drvdata(pdev);
2115 struct radeonfb_info *rinfo = info->par;
2116
2117 return radeon_show_one_edid(buf, off, count, rinfo->mon1_EDID);
2118}
2119
2120
Zhang Rui91a69022007-06-09 13:57:22 +08002121static ssize_t radeon_show_edid2(struct kobject *kobj,
2122 struct bin_attribute *bin_attr,
2123 char *buf, loff_t off, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
2125 struct device *dev = container_of(kobj, struct device, kobj);
2126 struct pci_dev *pdev = to_pci_dev(dev);
2127 struct fb_info *info = pci_get_drvdata(pdev);
2128 struct radeonfb_info *rinfo = info->par;
2129
2130 return radeon_show_one_edid(buf, off, count, rinfo->mon2_EDID);
2131}
2132
2133static struct bin_attribute edid1_attr = {
2134 .attr = {
2135 .name = "edid1",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 .mode = 0444,
2137 },
2138 .size = EDID_LENGTH,
2139 .read = radeon_show_edid1,
2140};
2141
2142static struct bin_attribute edid2_attr = {
2143 .attr = {
2144 .name = "edid2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 .mode = 0444,
2146 },
2147 .size = EDID_LENGTH,
2148 .read = radeon_show_edid2,
2149};
2150
2151
Randy Dunlap246846f2006-04-18 22:22:10 -07002152static int __devinit radeonfb_pci_register (struct pci_dev *pdev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 const struct pci_device_id *ent)
2154{
2155 struct fb_info *info;
2156 struct radeonfb_info *rinfo;
2157 int ret;
2158
2159 RTRACE("radeonfb_pci_register BEGIN\n");
2160
2161 /* Enable device in PCI config */
2162 ret = pci_enable_device(pdev);
2163 if (ret < 0) {
2164 printk(KERN_ERR "radeonfb (%s): Cannot enable PCI device\n",
2165 pci_name(pdev));
2166 goto err_out;
2167 }
2168
2169 info = framebuffer_alloc(sizeof(struct radeonfb_info), &pdev->dev);
2170 if (!info) {
2171 printk (KERN_ERR "radeonfb (%s): could not allocate memory\n",
2172 pci_name(pdev));
2173 ret = -ENOMEM;
2174 goto err_disable;
2175 }
2176 rinfo = info->par;
2177 rinfo->info = info;
2178 rinfo->pdev = pdev;
2179
2180 spin_lock_init(&rinfo->reg_lock);
2181 init_timer(&rinfo->lvds_timer);
2182 rinfo->lvds_timer.function = radeon_lvds_timer_func;
2183 rinfo->lvds_timer.data = (unsigned long)rinfo;
2184
2185 strcpy(rinfo->name, "ATI Radeon XX ");
2186 rinfo->name[11] = ent->device >> 8;
2187 rinfo->name[12] = ent->device & 0xFF;
2188 rinfo->family = ent->driver_data & CHIP_FAMILY_MASK;
2189 rinfo->chipset = pdev->device;
2190 rinfo->has_CRTC2 = (ent->driver_data & CHIP_HAS_CRTC2) != 0;
2191 rinfo->is_mobility = (ent->driver_data & CHIP_IS_MOBILITY) != 0;
2192 rinfo->is_IGP = (ent->driver_data & CHIP_IS_IGP) != 0;
2193
2194 /* Set base addrs */
2195 rinfo->fb_base_phys = pci_resource_start (pdev, 0);
2196 rinfo->mmio_base_phys = pci_resource_start (pdev, 2);
2197
2198 /* request the mem regions */
Daniel Burcaw5251bff2005-09-09 13:04:59 -07002199 ret = pci_request_region(pdev, 0, "radeonfb framebuffer");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 if (ret < 0) {
Daniel Burcaw5251bff2005-09-09 13:04:59 -07002201 printk( KERN_ERR "radeonfb (%s): cannot request region 0.\n",
2202 pci_name(rinfo->pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 goto err_release_fb;
2204 }
2205
Daniel Burcaw5251bff2005-09-09 13:04:59 -07002206 ret = pci_request_region(pdev, 2, "radeonfb mmio");
2207 if (ret < 0) {
2208 printk( KERN_ERR "radeonfb (%s): cannot request region 2.\n",
2209 pci_name(rinfo->pdev));
2210 goto err_release_pci0;
2211 }
2212
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 /* map the regions */
2214 rinfo->mmio_base = ioremap(rinfo->mmio_base_phys, RADEON_REGSIZE);
2215 if (!rinfo->mmio_base) {
Daniel Burcaw5251bff2005-09-09 13:04:59 -07002216 printk(KERN_ERR "radeonfb (%s): cannot map MMIO\n",
2217 pci_name(rinfo->pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 ret = -EIO;
Daniel Burcaw5251bff2005-09-09 13:04:59 -07002219 goto err_release_pci2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 }
2221
2222 rinfo->fb_local_base = INREG(MC_FB_LOCATION) << 16;
2223
2224 /*
2225 * Check for errata
2226 */
2227 rinfo->errata = 0;
2228 if (rinfo->family == CHIP_FAMILY_R300 &&
2229 (INREG(CONFIG_CNTL) & CFG_ATI_REV_ID_MASK)
2230 == CFG_ATI_REV_A11)
2231 rinfo->errata |= CHIP_ERRATA_R300_CG;
2232
2233 if (rinfo->family == CHIP_FAMILY_RV200 ||
2234 rinfo->family == CHIP_FAMILY_RS200)
2235 rinfo->errata |= CHIP_ERRATA_PLL_DUMMYREADS;
2236
2237 if (rinfo->family == CHIP_FAMILY_RV100 ||
2238 rinfo->family == CHIP_FAMILY_RS100 ||
2239 rinfo->family == CHIP_FAMILY_RS200)
2240 rinfo->errata |= CHIP_ERRATA_PLL_DELAY;
2241
David S. Miller9f47df22007-03-29 01:33:46 -07002242#if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 /* On PPC, we obtain the OF device-node pointer to the firmware
2244 * data for this chip
2245 */
2246 rinfo->of_node = pci_device_to_OF_node(pdev);
2247 if (rinfo->of_node == NULL)
2248 printk(KERN_WARNING "radeonfb (%s): Cannot match card to OF node !\n",
2249 pci_name(rinfo->pdev));
2250
David S. Miller9f47df22007-03-29 01:33:46 -07002251#endif /* CONFIG_PPC_OF || CONFIG_SPARC */
2252#ifdef CONFIG_PPC_OF
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 /* On PPC, the firmware sets up a memory mapping that tends
2254 * to cause lockups when enabling the engine. We reconfigure
2255 * the card internal memory mappings properly
2256 */
2257 fixup_memory_mappings(rinfo);
2258#endif /* CONFIG_PPC_OF */
2259
2260 /* Get VRAM size and type */
2261 radeon_identify_vram(rinfo);
2262
2263 rinfo->mapped_vram = min_t(unsigned long, MAX_MAPPED_VRAM, rinfo->video_ram);
2264
2265 do {
2266 rinfo->fb_base = ioremap (rinfo->fb_base_phys,
2267 rinfo->mapped_vram);
2268 } while ( rinfo->fb_base == 0 &&
2269 ((rinfo->mapped_vram /=2) >= MIN_MAPPED_VRAM) );
2270
Benjamin Herrenschmidt8d5f7b42005-06-11 09:45:30 +10002271 if (rinfo->fb_base == NULL) {
2272 printk (KERN_ERR "radeonfb (%s): cannot map FB\n",
2273 pci_name(rinfo->pdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 ret = -EIO;
2275 goto err_unmap_rom;
2276 }
2277
2278 RTRACE("radeonfb (%s): mapped %ldk videoram\n", pci_name(rinfo->pdev),
2279 rinfo->mapped_vram/1024);
2280
2281 /*
Matt Mackall4a4efbd2006-01-03 13:27:11 +01002282 * Map the BIOS ROM if any and retrieve PLL parameters from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 * the BIOS. We skip that on mobility chips as the real panel
2284 * values we need aren't in the ROM but in the BIOS image in
2285 * memory. This is definitely not the best meacnism though,
2286 * we really need the arch code to tell us which is the "primary"
2287 * video adapter to use the memory image (or better, the arch
2288 * should provide us a copy of the BIOS image to shield us from
2289 * archs who would store that elsewhere and/or could initialize
2290 * more than one adapter during boot).
2291 */
2292 if (!rinfo->is_mobility)
2293 radeon_map_ROM(rinfo, pdev);
2294
2295 /*
2296 * On x86, the primary display on laptop may have it's BIOS
2297 * ROM elsewhere, try to locate it at the legacy memory hole.
2298 * We probably need to make sure this is the primary display,
2299 * but that is difficult without some arch support.
2300 */
2301#ifdef CONFIG_X86
2302 if (rinfo->bios_seg == NULL)
2303 radeon_find_mem_vbios(rinfo);
2304#endif
2305
2306 /* If both above failed, try the BIOS ROM again for mobility
2307 * chips
2308 */
2309 if (rinfo->bios_seg == NULL && rinfo->is_mobility)
2310 radeon_map_ROM(rinfo, pdev);
2311
2312 /* Get informations about the board's PLL */
2313 radeon_get_pllinfo(rinfo);
2314
2315#ifdef CONFIG_FB_RADEON_I2C
2316 /* Register I2C bus */
2317 radeon_create_i2c_busses(rinfo);
2318#endif
2319
2320 /* set all the vital stuff */
2321 radeon_set_fbinfo (rinfo);
2322
2323 /* Probe screen types */
2324 radeon_probe_screens(rinfo, monitor_layout, ignore_edid);
2325
2326 /* Build mode list, check out panel native model */
2327 radeon_check_modes(rinfo, mode_option);
2328
2329 /* Register some sysfs stuff (should be done better) */
2330 if (rinfo->mon1_EDID)
2331 sysfs_create_bin_file(&rinfo->pdev->dev.kobj, &edid1_attr);
2332 if (rinfo->mon2_EDID)
2333 sysfs_create_bin_file(&rinfo->pdev->dev.kobj, &edid2_attr);
2334
2335 /* save current mode regs before we switch into the new one
2336 * so we can restore this upon __exit
2337 */
2338 radeon_save_state (rinfo, &rinfo->init_state);
2339 memcpy(&rinfo->state, &rinfo->init_state, sizeof(struct radeon_regs));
2340
2341 /* Setup Power Management capabilities */
2342 if (default_dynclk < -1) {
2343 /* -2 is special: means ON on mobility chips and do not
2344 * change on others
2345 */
Volker Braun994aad22006-07-30 03:04:18 -07002346 radeonfb_pm_init(rinfo, rinfo->is_mobility ? 1 : -1, ignore_devlist, force_sleep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 } else
Volker Braun994aad22006-07-30 03:04:18 -07002348 radeonfb_pm_init(rinfo, default_dynclk, ignore_devlist, force_sleep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
2350 pci_set_drvdata(pdev, info);
2351
2352 /* Register with fbdev layer */
2353 ret = register_framebuffer(info);
2354 if (ret < 0) {
2355 printk (KERN_ERR "radeonfb (%s): could not register framebuffer\n",
2356 pci_name(rinfo->pdev));
2357 goto err_unmap_fb;
2358 }
2359
2360#ifdef CONFIG_MTRR
2361 rinfo->mtrr_hdl = nomtrr ? -1 : mtrr_add(rinfo->fb_base_phys,
2362 rinfo->video_ram,
2363 MTRR_TYPE_WRCOMB, 1);
2364#endif
2365
Richard Purdie202d4e62007-03-03 17:43:52 +00002366 if (backlight)
2367 radeonfb_bl_init(rinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
2369 printk ("radeonfb (%s): %s\n", pci_name(rinfo->pdev), rinfo->name);
2370
2371 if (rinfo->bios_seg)
2372 radeon_unmap_ROM(rinfo, pdev);
2373 RTRACE("radeonfb_pci_register END\n");
2374
2375 return 0;
2376err_unmap_fb:
2377 iounmap(rinfo->fb_base);
2378err_unmap_rom:
2379 kfree(rinfo->mon1_EDID);
2380 kfree(rinfo->mon2_EDID);
2381 if (rinfo->mon1_modedb)
2382 fb_destroy_modedb(rinfo->mon1_modedb);
2383 fb_dealloc_cmap(&info->cmap);
2384#ifdef CONFIG_FB_RADEON_I2C
2385 radeon_delete_i2c_busses(rinfo);
2386#endif
2387 if (rinfo->bios_seg)
2388 radeon_unmap_ROM(rinfo, pdev);
2389 iounmap(rinfo->mmio_base);
Daniel Burcaw5251bff2005-09-09 13:04:59 -07002390err_release_pci2:
2391 pci_release_region(pdev, 2);
2392err_release_pci0:
2393 pci_release_region(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394err_release_fb:
Daniel Burcaw5251bff2005-09-09 13:04:59 -07002395 framebuffer_release(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396err_disable:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397err_out:
2398 return ret;
2399}
2400
2401
2402
2403static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
2404{
2405 struct fb_info *info = pci_get_drvdata(pdev);
2406 struct radeonfb_info *rinfo = info->par;
2407
2408 if (!rinfo)
2409 return;
Michael Hanselmann5474c122006-06-25 05:47:08 -07002410
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 radeonfb_pm_exit(rinfo);
2412
Jon Smirl3ca34fc2005-07-27 11:46:05 -07002413 if (rinfo->mon1_EDID)
2414 sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid1_attr);
2415 if (rinfo->mon2_EDID)
2416 sysfs_remove_bin_file(&rinfo->pdev->dev.kobj, &edid2_attr);
2417
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418#if 0
2419 /* restore original state
2420 *
2421 * Doesn't quite work yet, I suspect if we come from a legacy
2422 * VGA mode (or worse, text mode), we need to do some VGA black
2423 * magic here that I know nothing about. --BenH
2424 */
2425 radeon_write_mode (rinfo, &rinfo->init_state, 1);
2426 #endif
2427
2428 del_timer_sync(&rinfo->lvds_timer);
2429
2430#ifdef CONFIG_MTRR
2431 if (rinfo->mtrr_hdl >= 0)
2432 mtrr_del(rinfo->mtrr_hdl, 0, 0);
2433#endif
2434
2435 unregister_framebuffer(info);
2436
Richard Purdie37ce69a2007-02-10 14:10:33 +00002437 radeonfb_bl_exit(rinfo);
2438
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 iounmap(rinfo->mmio_base);
2440 iounmap(rinfo->fb_base);
2441
Daniel Burcaw5251bff2005-09-09 13:04:59 -07002442 pci_release_region(pdev, 2);
2443 pci_release_region(pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
2445 kfree(rinfo->mon1_EDID);
2446 kfree(rinfo->mon2_EDID);
2447 if (rinfo->mon1_modedb)
2448 fb_destroy_modedb(rinfo->mon1_modedb);
2449#ifdef CONFIG_FB_RADEON_I2C
2450 radeon_delete_i2c_busses(rinfo);
2451#endif
2452 fb_dealloc_cmap(&info->cmap);
2453 framebuffer_release(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454}
2455
2456
2457static struct pci_driver radeonfb_driver = {
2458 .name = "radeonfb",
2459 .id_table = radeonfb_pci_table,
2460 .probe = radeonfb_pci_register,
2461 .remove = __devexit_p(radeonfb_pci_unregister),
2462#ifdef CONFIG_PM
2463 .suspend = radeonfb_pci_suspend,
2464 .resume = radeonfb_pci_resume,
2465#endif /* CONFIG_PM */
2466};
2467
2468#ifndef MODULE
2469static int __init radeonfb_setup (char *options)
2470{
2471 char *this_opt;
2472
2473 if (!options || !*options)
2474 return 0;
2475
2476 while ((this_opt = strsep (&options, ",")) != NULL) {
2477 if (!*this_opt)
2478 continue;
2479
2480 if (!strncmp(this_opt, "noaccel", 7)) {
2481 noaccel = 1;
2482 } else if (!strncmp(this_opt, "mirror", 6)) {
2483 mirror = 1;
2484 } else if (!strncmp(this_opt, "force_dfp", 9)) {
2485 force_dfp = 1;
2486 } else if (!strncmp(this_opt, "panel_yres:", 11)) {
2487 panel_yres = simple_strtoul((this_opt+11), NULL, 0);
Richard Purdie202d4e62007-03-03 17:43:52 +00002488 } else if (!strncmp(this_opt, "backlight:", 10)) {
2489 backlight = simple_strtoul(this_opt+10, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490#ifdef CONFIG_MTRR
2491 } else if (!strncmp(this_opt, "nomtrr", 6)) {
2492 nomtrr = 1;
2493#endif
2494 } else if (!strncmp(this_opt, "nomodeset", 9)) {
2495 nomodeset = 1;
2496 } else if (!strncmp(this_opt, "force_measure_pll", 17)) {
2497 force_measure_pll = 1;
2498 } else if (!strncmp(this_opt, "ignore_edid", 11)) {
2499 ignore_edid = 1;
Volker Braun994aad22006-07-30 03:04:18 -07002500#if defined(CONFIG_PM) && defined(CONFIG_X86)
2501 } else if (!strncmp(this_opt, "force_sleep", 11)) {
2502 force_sleep = 1;
2503 } else if (!strncmp(this_opt, "ignore_devlist", 14)) {
2504 ignore_devlist = 1;
2505#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 } else
2507 mode_option = this_opt;
2508 }
2509 return 0;
2510}
2511#endif /* MODULE */
2512
2513static int __init radeonfb_init (void)
2514{
2515#ifndef MODULE
2516 char *option = NULL;
2517
2518 if (fb_get_options("radeonfb", &option))
2519 return -ENODEV;
2520 radeonfb_setup(option);
2521#endif
2522 return pci_register_driver (&radeonfb_driver);
2523}
2524
2525
2526static void __exit radeonfb_exit (void)
2527{
2528 pci_unregister_driver (&radeonfb_driver);
2529}
2530
2531module_init(radeonfb_init);
2532module_exit(radeonfb_exit);
2533
2534MODULE_AUTHOR("Ani Joshi");
2535MODULE_DESCRIPTION("framebuffer driver for ATI Radeon chipset");
2536MODULE_LICENSE("GPL");
2537module_param(noaccel, bool, 0);
2538module_param(default_dynclk, int, 0);
2539MODULE_PARM_DESC(default_dynclk, "int: -2=enable on mobility only,-1=do not change,0=off,1=on");
2540MODULE_PARM_DESC(noaccel, "bool: disable acceleration");
2541module_param(nomodeset, bool, 0);
2542MODULE_PARM_DESC(nomodeset, "bool: disable actual setting of video mode");
2543module_param(mirror, bool, 0);
2544MODULE_PARM_DESC(mirror, "bool: mirror the display to both monitors");
2545module_param(force_dfp, bool, 0);
2546MODULE_PARM_DESC(force_dfp, "bool: force display to dfp");
2547module_param(ignore_edid, bool, 0);
2548MODULE_PARM_DESC(ignore_edid, "bool: Ignore EDID data when doing DDC probe");
2549module_param(monitor_layout, charp, 0);
2550MODULE_PARM_DESC(monitor_layout, "Specify monitor mapping (like XFree86)");
2551module_param(force_measure_pll, bool, 0);
2552MODULE_PARM_DESC(force_measure_pll, "Force measurement of PLL (debug)");
2553#ifdef CONFIG_MTRR
2554module_param(nomtrr, bool, 0);
2555MODULE_PARM_DESC(nomtrr, "bool: disable use of MTRR registers");
2556#endif
2557module_param(panel_yres, int, 0);
2558MODULE_PARM_DESC(panel_yres, "int: set panel yres");
2559module_param(mode_option, charp, 0);
2560MODULE_PARM_DESC(mode_option, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
Volker Braun994aad22006-07-30 03:04:18 -07002561#if defined(CONFIG_PM) && defined(CONFIG_X86)
2562module_param(force_sleep, bool, 0);
2563MODULE_PARM_DESC(force_sleep, "bool: force D2 sleep mode on all hardware");
2564module_param(ignore_devlist, bool, 0);
2565MODULE_PARM_DESC(ignore_devlist, "bool: ignore workarounds for bugs in specific laptops");
2566#endif