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