53 #define RADEON_VERSION "0.2.0"
57 #include <linux/module.h>
59 #include <linux/kernel.h>
60 #include <linux/errno.h>
61 #include <linux/string.h>
62 #include <linux/ctype.h>
64 #include <linux/slab.h>
66 #include <linux/time.h>
70 #include <linux/pci.h>
72 #include <linux/device.h>
79 #include <asm/pci-bridge.h>
80 #include "../macmodes.h"
82 #ifdef CONFIG_BOOTX_TEXT
83 #include <asm/btext.h>
98 #define MAX_MAPPED_VRAM (2048*2048*4)
99 #define MIN_MAPPED_VRAM (1024*768*1)
101 #define CHIP_DEF(id, family, flags) \
102 { PCI_VENDOR_ID_ATI, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (flags) | (CHIP_FAMILY_##family) }
247 static reg_val common_regs[] = {
264 static char *mode_option;
265 static char *monitor_layout;
266 static bool noaccel = 0;
267 static int default_dynclk = -2;
268 static bool nomodeset = 0;
269 static bool ignore_edid = 0;
271 static int panel_yres = 0;
272 static bool force_dfp = 0;
273 static bool force_measure_pll = 0;
275 static bool nomtrr = 0;
277 static bool force_sleep;
278 static bool ignore_devlist;
279 #ifdef CONFIG_PMAC_BACKLIGHT
280 static int backlight = 1;
282 static int backlight = 0;
319 pci_name(rinfo->
pdev));
328 "should be 0xaa55\n",
359 if (
BIOS_IN32(dptr) != ((
'R' << 24) | (
'I' << 16) | (
'C' << 8) |
'P')) {
361 "incorrect: %08x\n", pci_name(rinfo->
pdev),
BIOS_IN32(dptr));
376 printk(
KERN_INFO "radeonfb: Found unknown type %d ROM Image\n", rom_type);
386 radeon_unmap_ROM(rinfo, dev);
401 for(segstart=0x000c0000; segstart<0x000f0000; segstart+=0x00001000) {
402 rom_base =
ioremap(segstart, 0x10000);
403 if (rom_base ==
NULL)
405 if (
readb(rom_base) == 0x55 &&
readb(rom_base + 1) == 0xaa)
410 if (rom_base ==
NULL)
421 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
439 rinfo->
pll.ref_clk = (*val) / 10;
443 rinfo->
pll.sclk = (*val) / 10;
447 rinfo->
pll.mclk = (*val) / 10;
458 unsigned char ppll_div_sel;
461 int hTotal, vTotal,
num, denom,
m,
n;
462 unsigned long long hz,
vclk;
464 struct timeval start_tv, stop_tv;
465 long total_secs, total_usecs;
477 for(i=0; i<1000000; i++)
483 for(i=0; i<1000000; i++)
487 for(i=0; i<1000000; i++)
495 total_secs = stop_tv.tv_sec - start_tv.tv_sec;
498 total_usecs = stop_tv.tv_usec - start_tv.tv_usec;
499 total_usecs += total_secs * 1000000;
501 total_usecs = -total_usecs;
502 hz = 1000000/total_usecs;
506 vclk = (
long long)hTotal * (
long long)vTotal * hz;
529 radeon_pll_errata_after_index(rinfo);
562 if ((xtal > 26900) && (xtal < 27100))
564 else if ((xtal > 14200) && (xtal < 14400))
566 else if ((xtal > 29400) && (xtal < 29600))
576 Ns = (tmp & 0xff0000) >> 16;
577 Nm = (tmp & 0xff00) >> 8;
579 sclk =
round_div((2 * Ns * xtal), (2 * M));
580 mclk =
round_div((2 * Nm * xtal), (2 * M));
584 rinfo->
pll.ref_div = ref_div;
604 rinfo->
pll.ppll_max = 35000;
605 rinfo->
pll.ppll_min = 12000;
606 rinfo->
pll.mclk = 23000;
607 rinfo->
pll.sclk = 23000;
608 rinfo->
pll.ref_clk = 2700;
615 rinfo->
pll.ppll_max = 35000;
616 rinfo->
pll.ppll_min = 12000;
617 rinfo->
pll.mclk = 27500;
618 rinfo->
pll.sclk = 27500;
619 rinfo->
pll.ref_clk = 2700;
625 rinfo->
pll.ppll_max = 35000;
626 rinfo->
pll.ppll_min = 12000;
627 rinfo->
pll.mclk = 25000;
628 rinfo->
pll.sclk = 25000;
629 rinfo->
pll.ref_clk = 2700;
635 rinfo->
pll.ppll_max = 40000;
636 rinfo->
pll.ppll_min = 20000;
637 rinfo->
pll.mclk = 27000;
638 rinfo->
pll.sclk = 27000;
639 rinfo->
pll.ref_clk = 2700;
646 rinfo->
pll.ppll_max = 35000;
647 rinfo->
pll.ppll_min = 12000;
648 rinfo->
pll.mclk = 16600;
649 rinfo->
pll.sclk = 16600;
650 rinfo->
pll.ref_clk = 2700;
656 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
660 if (!force_measure_pll && radeon_read_xtal_OF(rinfo) == 0) {
661 printk(
KERN_INFO "radeonfb: Retrieved PLL infos from Open Firmware\n");
670 if (!force_measure_pll && rinfo->
bios_seg) {
688 if (radeon_probe_pll_params(rinfo) == 0) {
704 if (rinfo->
pll.mclk == 0)
705 rinfo->
pll.mclk = 20000;
706 if (rinfo->
pll.sclk == 0)
707 rinfo->
pll.sclk = 20000;
709 printk(
"radeonfb: Reference=%d.%02d MHz (RefDiv=%d) Memory=%d.%02d Mhz, System=%d.%02d MHz\n",
710 rinfo->
pll.ref_clk / 100, rinfo->
pll.ref_clk % 100,
712 rinfo->
pll.mclk / 100, rinfo->
pll.mclk % 100,
713 rinfo->
pll.sclk / 100, rinfo->
pll.sclk % 100);
714 printk(
"radeonfb: PLL min %d max %d\n", rinfo->
pll.ppll_min, rinfo->
pll.ppll_max);
727 switch (
v.bits_per_pixel) {
729 v.bits_per_pixel = 8;
732 v.bits_per_pixel = 16;
736 v.bits_per_pixel = 24;
741 v.bits_per_pixel = 32;
747 switch (var_to_depth(&
v)) {
750 v.red.offset =
v.green.offset =
v.blue.offset = 0;
751 v.red.length =
v.green.length =
v.blue.length = 8;
752 v.transp.offset =
v.transp.length = 0;
760 v.red.length =
v.green.length =
v.blue.length = 5;
761 v.transp.offset =
v.transp.length = 0;
772 v.transp.offset =
v.transp.length = 0;
780 v.red.length =
v.blue.length =
v.green.length = 8;
781 v.transp.offset =
v.transp.length = 0;
789 v.red.length =
v.blue.length =
v.green.length = 8;
790 v.transp.offset = 24;
794 printk (
"radeonfb: mode %dx%dx%d rejected, color depth invalid\n",
799 if (
v.yres_virtual <
v.yres)
800 v.yres_virtual =
v.yres;
801 if (
v.xres_virtual <
v.xres)
802 v.xres_virtual =
v.xres;
809 v.xres_virtual =
v.xres_virtual & ~7ul;
811 pitch = ((
v.xres_virtual * ((
v.bits_per_pixel + 1) / 8) + 0x3f)
813 v.xres_virtual = (pitch << 6) / ((
v.bits_per_pixel + 1) / 8);
819 if (
v.xres_virtual <
v.xres)
820 v.xres =
v.xres_virtual;
827 if (
v.xoffset >
v.xres_virtual -
v.xres)
828 v.xoffset =
v.xres_virtual -
v.xres - 1;
830 if (
v.yoffset >
v.yres_virtual -
v.yres)
831 v.yoffset =
v.yres_virtual -
v.yres - 1;
833 v.red.msb_right =
v.green.msb_right =
v.blue.msb_right =
834 v.transp.offset =
v.transp.length =
835 v.transp.msb_right = 0;
857 var->
xoffset * info->
var.bits_per_pixel / 8) & ~7);
862 static int radeonfb_ioctl (
struct fb_info *info,
unsigned int cmd,
989 else if ((val ^ target_val) != 0) {
1045 static int radeonfb_blank (
int blank,
struct fb_info *info)
1055 static int radeon_setcolreg (
unsigned regno,
unsigned red,
unsigned green,
1079 if (rinfo->
bpp == 16) {
1082 if (rinfo->
depth == 16 && regno > 63)
1084 if (rinfo->
depth == 15 && regno > 31)
1090 if (rinfo->
depth == 16) {
1093 (rinfo->
palette[regno>>1].red << 16) |
1095 (rinfo->
palette[regno>>1].blue));
1096 green = rinfo->
palette[regno<<1].green;
1100 if (rinfo->
depth != 16 || regno < 32) {
1103 (green << 8) | blue);
1108 switch (rinfo->
depth) {
1110 pal[regno] = (regno << 10) | (regno << 5) | regno;
1113 pal[regno] = (regno << 11) | (regno << 5) | regno;
1116 pal[regno] = (regno << 16) | (regno << 8) | regno;
1119 i = (regno << 8) | regno;
1120 pal[regno] = (i << 16) | i;
1127 static int radeonfb_setcolreg (
unsigned regno,
unsigned red,
unsigned green,
1128 unsigned blue,
unsigned transp,
1132 u32 dac_cntl2, vclk_cntl = 0;
1150 rc = radeon_setcolreg (regno, red, green, blue, transp, rinfo);
1158 static int radeonfb_setcmap(
struct fb_cmap *cmap,
struct fb_info *info)
1162 u32 dac_cntl2, vclk_cntl = 0;
1181 green = cmap->
green;
1184 start = cmap->
start;
1186 for (i = 0; i < cmap->
len; i++) {
1187 u_int hred, hgreen, hblue, htransp = 0xffff;
1193 htransp = *transp++;
1194 rc = radeon_setcolreg (start++, hred, hgreen, hblue, htransp,
1237 radeon_pll_errata_after_index(rinfo);
1267 radeon_pll_errata_after_index(rinfo);
1268 radeon_pll_errata_after_data(rinfo);
1285 radeon_pll_errata_after_index(rinfo);
1286 radeon_pll_errata_after_data(rinfo);
1340 static void radeon_lvds_timer_func(
unsigned long data)
1366 for (i=0; i<10; i++)
1367 OUTREG(common_regs[i].
reg, common_regs[i].val);
1370 for (i=0; i<8; i++) {
1390 radeon_write_pll_regs(rinfo, mode);
1392 if ((primary_mon ==
MT_DFP) || (primary_mon ==
MT_LCD)) {
1435 int fb_div, pll_output_freq = 0;
1454 u32 disp_output_cntl;
1458 if ((fp2_gen_cntl &
FP2_ON) == 0)
1464 source = (fp2_gen_cntl >> 10) & 0x3;
1470 source = (disp_output_cntl >> 12) & 0x3;
1473 source = (fp2_gen_cntl >> 13) & 0x1;
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 pr_debug(
"freq = %lu, PLL min = %u, PLL max = %u\n",
1490 freq, rinfo->
pll.ppll_min, rinfo->
pll.ppll_max);
1492 for (post_div = &post_divs[0]; post_div->divider; ++post_div) {
1493 pll_output_freq = post_div->divider *
freq;
1497 if (uses_dvo && (post_div->divider & 1))
1499 if (pll_output_freq >= rinfo->
pll.ppll_min &&
1500 pll_output_freq <= rinfo->
pll.ppll_max)
1506 if ( !post_div->divider ) {
1507 post_div = &post_divs[post_div->bitvalue];
1508 pll_output_freq = post_div->divider *
freq;
1510 pr_debug(
"ref_div = %d, ref_clk = %d, output_freq = %d\n",
1511 rinfo->
pll.ref_div, rinfo->
pll.ref_clk,
1516 if ( !post_div->divider ) {
1517 post_div = &post_divs[post_div->bitvalue];
1518 pll_output_freq = post_div->divider *
freq;
1520 pr_debug(
"ref_div = %d, ref_clk = %d, output_freq = %d\n",
1521 rinfo->
pll.ref_div, rinfo->
pll.ref_clk,
1525 rinfo->
pll.ref_clk);
1527 regs->
ppll_div_3 = fb_div | (post_div->bitvalue << 16);
1529 pr_debug(
"post div = 0x%x\n", post_div->bitvalue);
1530 pr_debug(
"fb_div = 0x%x\n", fb_div);
1534 static int radeonfb_set_par(
struct fb_info *info)
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;
1547 int hsync_start, hsync_fudge, bytpp, hsync_wid, vsync_wid;
1549 int depth = var_to_depth(mode);
1562 hSyncEnd = hSyncStart + mode->
hsync_len;
1566 vSyncEnd = vSyncStart + mode->
vsync_len;
1582 hSyncEnd = hSyncStart + rinfo->
panel_info.hSync_width;
1586 vSyncEnd = vSyncStart + rinfo->
panel_info.vSync_width;
1591 pixClock = 100000000 / rinfo->
panel_info.clock;
1600 dotClock = 1000000000 / pixClock;
1601 freq = dotClock / 10;
1603 pr_debug(
"hStart = %d, hEnd = %d, hTotal = %d\n",
1604 hSyncStart, hSyncEnd, hTotal);
1605 pr_debug(
"vStart = %d, vEnd = %d, vTotal = %d\n",
1606 vSyncStart, vSyncEnd, vTotal);
1608 hsync_wid = (hSyncEnd - hSyncStart) / 8;
1609 vsync_wid = vSyncEnd - vSyncStart;
1612 else if (hsync_wid > 0x3f)
1617 else if (vsync_wid > 0x1f)
1625 format = radeon_get_dstbpp(depth);
1628 if ((primary_mon ==
MT_DFP) || (primary_mon ==
MT_LCD))
1629 hsync_fudge = hsync_fudge_fp[format-1];
1631 hsync_fudge = hsync_adj_tab[format-1];
1633 hsync_start = hSyncStart - 8 + hsync_fudge;
1642 if ((primary_mon ==
MT_DFP) || (primary_mon ==
MT_LCD)) {
1658 (((mode->
xres / 8) - 1) << 16));
1661 (hsync_wid << 16) | (h_sync_pol << 23));
1664 ((mode->
yres - 1) << 16);
1667 (vsync_wid << 16) | (v_sync_pol << 23));
1688 #if defined(__BIG_ENDIAN)
1708 for (i=0; i<8; i++) {
1714 pr_debug(
"h_total_disp = 0x%x\t hsync_strt_wid = 0x%x\n",
1716 pr_debug(
"v_total_disp = 0x%x\t vsync_strt_wid = 0x%x\n",
1722 pr_debug(
"pixclock = %lu\n", (
unsigned long)pixClock);
1723 pr_debug(
"freq = %lu\n", (
unsigned long)freq);
1730 radeon_calc_pll_regs(rinfo, newmode, freq);
1734 if ((primary_mon ==
MT_DFP) || (primary_mon ==
MT_LCD)) {
1735 unsigned int hRatio, vRatio;
1801 if (primary_mon ==
MT_LCD) {
1818 (((mode->
xres / 8) - 1) << 16));
1820 ((mode->
yres - 1) << 16);
1822 (hsync_wid << 16) | (h_sync_pol << 23));
1824 (vsync_wid << 16) | (v_sync_pol << 23));
1837 info->
fix.line_length = rinfo->
pitch*64;
1844 #ifdef CONFIG_BOOTX_TEXT
1847 rinfo->
depth, info->
fix.line_length);
1855 static struct fb_ops radeonfb_ops = {
1857 .fb_check_var = radeonfb_check_var,
1858 .fb_set_par = radeonfb_set_par,
1859 .fb_setcolreg = radeonfb_setcolreg,
1860 .fb_setcmap = radeonfb_setcmap,
1861 .fb_pan_display = radeonfb_pan_display,
1862 .fb_blank = radeonfb_blank,
1863 .fb_ioctl = radeonfb_ioctl,
1882 info->
fbops = &radeonfb_ops;
1891 info->
fix.xpanstep = 8;
1892 info->
fix.ypanstep = 1;
1893 info->
fix.ywrapstep = 0;
1894 info->
fix.type_aux = 0;
1918 #ifdef CONFIG_PPC_OF
1919 #undef SET_MC_FB_FROM_APERTURE
1920 static void fixup_memory_mappings(
struct radeonfb_info *rinfo)
1922 u32 save_crtc_gen_cntl, save_crtc2_gen_cntl = 0;
1923 u32 save_crtc_ext_cntl;
1924 u32 aper_base, aper_size;
1942 #ifdef SET_MC_FB_FROM_APERTURE
1945 ((aper_base + aper_size - 1) & 0xffff0000) | (aper_base >> 16));
1951 agp_base = aper_base + aper_size;
1952 if (agp_base & 0xf0000000)
1953 agp_base = (aper_base | 0x0fffffff) + 1;
1959 #ifdef SET_MC_FB_FROM_APERTURE
1968 #ifdef SET_MC_FB_FROM_APERTURE
1987 pr_debug(
"aper_base: %08x MC_FB_LOC to: %08x, MC_AGP_LOC to: %08x\n",
1989 ((aper_base + aper_size - 1) & 0xffff0000) | (aper_base >> 16),
1990 0xffff0000 | (agp_base >> 16));
1995 static void radeon_identify_vram(
struct radeonfb_info *rinfo)
2007 tmp = ((((tom >> 16) - (tom & 0xffff) + 1) << 6) * 1024);
2038 switch (rinfo->
pdev->device) {
2085 pr_debug(
"radeonfb (%s): Found %ldk of %s %d bits wide videoram\n",
2086 pci_name(rinfo->
pdev),
2104 char *
buf, loff_t off,
size_t count)
2108 struct fb_info *info = pci_get_drvdata(pdev);
2111 return radeon_show_one_edid(buf, off, count, rinfo->
mon1_EDID);
2117 char *
buf, loff_t off,
size_t count)
2121 struct fb_info *info = pci_get_drvdata(pdev);
2124 return radeon_show_one_edid(buf, off, count, rinfo->
mon2_EDID);
2133 .read = radeon_show_edid1,
2142 .read = radeon_show_edid2,
2152 unsigned char c1, c2;
2155 pr_debug(
"radeonfb_pci_register BEGIN\n");
2178 rinfo->
lvds_timer.function = radeon_lvds_timer_func;
2185 "ATI Radeon %x \"%c%c\"", ent->
device & 0xffff, c1, c2);
2188 "ATI Radeon %x", ent->
device & 0xffff);
2204 pci_name(rinfo->
pdev));
2205 goto err_release_fb;
2211 pci_name(rinfo->
pdev));
2212 goto err_release_pci0;
2219 pci_name(rinfo->
pdev));
2221 goto err_release_pci2;
2244 #if defined(CONFIG_PPC_OF) || defined(CONFIG_SPARC)
2248 rinfo->of_node = pci_device_to_OF_node(pdev);
2249 if (rinfo->of_node ==
NULL)
2251 pci_name(rinfo->
pdev));
2254 #ifdef CONFIG_PPC_OF
2259 fixup_memory_mappings(rinfo);
2263 radeon_identify_vram(rinfo);
2275 pci_name(rinfo->
pdev));
2280 pr_debug(
"radeonfb (%s): mapped %ldk videoram\n", pci_name(rinfo->
pdev),
2295 radeon_map_ROM(rinfo, pdev);
2305 radeon_find_mem_vbios(rinfo);
2312 radeon_map_ROM(rinfo, pdev);
2315 radeon_get_pllinfo(rinfo);
2317 #ifdef CONFIG_FB_RADEON_I2C
2323 radeon_set_fbinfo (rinfo);
2339 pr_warning(
"%s() Creating sysfs files failed, continuing\n",
2345 radeon_save_state (rinfo, &rinfo->
init_state);
2349 if (default_dynclk < -1) {
2357 pci_set_drvdata(pdev, info);
2362 printk (
KERN_ERR "radeonfb (%s): could not register framebuffer\n",
2363 pci_name(rinfo->
pdev));
2376 printk (
"radeonfb (%s): %s\n", pci_name(rinfo->
pdev), rinfo->
name);
2379 radeon_unmap_ROM(rinfo, pdev);
2380 pr_debug(
"radeonfb_pci_register END\n");
2391 #ifdef CONFIG_FB_RADEON_I2C
2395 radeon_unmap_ROM(rinfo, pdev);
2412 struct fb_info *info = pci_get_drvdata(pdev);
2456 #ifdef CONFIG_FB_RADEON_I2C
2466 .id_table = radeonfb_pci_table,
2467 .probe = radeonfb_pci_register,
2480 if (!options || !*options)
2483 while ((this_opt =
strsep (&options,
",")) !=
NULL) {
2487 if (!
strncmp(this_opt,
"noaccel", 7)) {
2489 }
else if (!
strncmp(this_opt,
"mirror", 6)) {
2491 }
else if (!
strncmp(this_opt,
"force_dfp", 9)) {
2493 }
else if (!
strncmp(this_opt,
"panel_yres:", 11)) {
2495 }
else if (!
strncmp(this_opt,
"backlight:", 10)) {
2498 }
else if (!
strncmp(this_opt,
"nomtrr", 6)) {
2501 }
else if (!
strncmp(this_opt,
"nomodeset", 9)) {
2503 }
else if (!
strncmp(this_opt,
"force_measure_pll", 17)) {
2504 force_measure_pll = 1;
2505 }
else if (!
strncmp(this_opt,
"ignore_edid", 11)) {
2507 #if defined(CONFIG_PM) && defined(CONFIG_X86)
2508 }
else if (!
strncmp(this_opt,
"force_sleep", 11)) {
2510 }
else if (!
strncmp(this_opt,
"ignore_devlist", 14)) {
2514 mode_option = this_opt;
2520 static int __init radeonfb_init (
void)
2527 radeonfb_setup(option);
2529 return pci_register_driver (&radeonfb_driver);
2533 static void __exit radeonfb_exit (
void)
2546 MODULE_PARM_DESC(default_dynclk,
"int: -2=enable on mobility only,-1=do not change,0=off,1=on");
2555 MODULE_PARM_DESC(ignore_edid,
"bool: Ignore EDID data when doing DDC probe");
2557 MODULE_PARM_DESC(monitor_layout,
"Specify monitor mapping (like XFree86)");
2567 MODULE_PARM_DESC(mode_option,
"Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\" ");
2568 #if defined(CONFIG_PM) && defined(CONFIG_X86)
2570 MODULE_PARM_DESC(force_sleep,
"bool: force D2 sleep mode on all hardware");
2572 MODULE_PARM_DESC(ignore_devlist,
"bool: ignore workarounds for bugs in specific laptops");