Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 | /* * Based on retz3fb.c and clgen.c */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/string.h> #include <linux/mm.h> #include <linux/tty.h> #include <linux/malloc.h> #include <linux/delay.h> #include <linux/fb.h> #include <linux/zorro.h> #include <linux/init.h> #include <asm/amigahw.h> #include <asm/pgtable.h> #include <asm/delay.h> #include <asm/io.h> #include <video/fbcon.h> #include <video/fbcon-mfb.h> #include <video/fbcon-cfb8.h> #include <video/fbcon-cfb16.h> #include <video/fbcon-cfb24.h> #include <video/fbcon-cfb32.h> #include "clgenfb.h" #define CLGEN_VERSION "1.4 ?" /* #define DEBUG if(1) */ #define DEBUG if(0) #define arraysize(x) (sizeof(x)/sizeof(*(x))) /* board types */ #define BT_NONE 0 #define BT_SD64 1 #define BT_PICCOLO 2 #define BT_PICASSO 3 #define BT_SPECTRUM 4 #define BT_PICASSO4 5 #define MAX_NUM_BOARDS 7 #define TRUE 1 #define FALSE 0 struct clgenfb_par { struct fb_var_screeninfo var; __u32 line_length; /* in BYTES! */ __u32 visual; __u32 type; long freq; long nom; long den; long div; long HorizRes; /* The x resolution in pixel */ long HorizTotal; long HorizDispEnd; long HorizBlankStart; long HorizBlankEnd; long HorizSyncStart; long HorizSyncEnd; long VertRes; /* the physical y resolution in scanlines */ long VertTotal; long VertDispEnd; long VertSyncStart; long VertSyncEnd; long VertBlankStart; long VertBlankEnd; }; /* info about board */ struct clgenfb_info { struct fb_info_gen gen; int keyRAM; /* RAM, REG zorro board keys */ int keyREG; unsigned long fbmem; volatile unsigned char *regs; unsigned long mem; unsigned long size; int btype; int smallboard; unsigned char SFR; /* Shadow of special function register */ unsigned long fbmem_phys; unsigned long fbregs_phys; struct clgenfb_par currentmode; union { #ifdef FBCON_HAS_CFB16 u16 cfb16[16]; #endif #ifdef FBCON_HAS_CFB24 u32 cfb24[16]; #endif #ifdef FBCON_HAS_CFB32 u32 cfb32[16]; #endif } fbcon_cmap; }; static struct display disp; static struct clgenfb_info boards[MAX_NUM_BOARDS]; /* the boards */ static struct clgenfb_info *fb_info=NULL; /* pointer to current board */ /* * Predefined Video Modes */ static struct fb_videomode clgenfb_predefined[] __initdata = { { "Autodetect", /* autodetect mode */ { 0 } }, { "640x480", /* 640x480, 31.25 kHz, 60 Hz, 25 MHz PixClock */ { 640, 480, 640, 480, 0, 0, 8, 0, {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, 0, -1, -1, FB_ACCEL_NONE, 40000, 32, 32, 33, 10, 96, 2, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED } }, /* 1024x768, 55.8 kHz, 70 Hz, 80 MHz PixClock */ /* Modeline from XF86Config: Mode "1024x768" 80 1024 1136 1340 1432 768 770 774 805 */ { "1024x768", { 1024, 768, 1024, 768, 0, 0, 8, 0, {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, 0, -1, -1, FB_ACCEL_NONE, 12500, 92, 112, 31, 2, 204, 4, FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED } } }; #define NUM_TOTAL_MODES arraysize(clgenfb_predefined) static struct fb_var_screeninfo clgenfb_default; /* * Frame Buffer Name */ static char clgenfb_name[16] = "CLgen"; /****************************************************************************/ /**** BEGIN PROTOTYPES ******************************************************/ /*--- Interface used by the world ------------------------------------------*/ void clgenfb_init(void); void clgenfb_setup(char *options, int *ints); int clgenfb_open(struct fb_info *info, int user); int clgenfb_release(struct fb_info *info, int user); int clgenfb_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg, int con, struct fb_info *info); /* function table of the above functions */ static struct fb_ops clgenfb_ops = { clgenfb_open, clgenfb_release, fbgen_get_fix, /* using the generic functions */ fbgen_get_var, /* makes things much easier... */ fbgen_set_var, fbgen_get_cmap, fbgen_set_cmap, fbgen_pan_display, clgenfb_ioctl, NULL }; /*--- Hardware Specific Routines -------------------------------------------*/ static void clgen_detect(void); static int clgen_encode_fix(struct fb_fix_screeninfo *fix, const void *par, struct fb_info_gen *info); static int clgen_decode_var(const struct fb_var_screeninfo *var, void *par, struct fb_info_gen *info); static int clgen_encode_var(struct fb_var_screeninfo *var, const void *par, struct fb_info_gen *info); static void clgen_get_par(void *par, struct fb_info_gen *info); static void clgen_set_par(const void *par, struct fb_info_gen *info); static int clgen_getcolreg(unsigned regno, unsigned *red, unsigned *green, unsigned *blue, unsigned *transp, struct fb_info *info); static int clgen_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info); static int clgen_pan_display(const struct fb_var_screeninfo *var, struct fb_info_gen *info); static int clgen_blank(int blank_mode, struct fb_info_gen *info); static void clgen_set_disp(const void *par, struct display *disp, struct fb_info_gen *info); /* function table of the above functions */ static struct fbgen_hwswitch clgen_hwswitch = { clgen_detect, clgen_encode_fix, clgen_decode_var, clgen_encode_var, clgen_get_par, clgen_set_par, clgen_getcolreg, clgen_setcolreg, clgen_pan_display, clgen_blank, clgen_set_disp }; /* Text console acceleration */ #ifdef FBCON_HAS_CFB8 static void fbcon_clgen8_bmove(struct display *p, int sy, int sx, int dy, int dx, int height, int width); static void fbcon_clgen8_clear(struct vc_data *conp, struct display *p, int sy, int sx, int height, int width); static struct display_switch fbcon_clgen_8 = { fbcon_cfb8_setup, fbcon_clgen8_bmove, fbcon_clgen8_clear, fbcon_cfb8_putc, fbcon_cfb8_putcs, fbcon_cfb8_revc, NULL, NULL, fbcon_cfb8_clear_margins, FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16) }; #endif /*--- Internal routines ----------------------------------------------------*/ static void init_vgachip(void); static void switch_monitor(int on); static void WGen( int regnum, unsigned char val ); static unsigned char RGen( int regnum ); static void WSeq( unsigned char regnum, unsigned char val ); static unsigned char RSeq( unsigned char regnum ); static void WCrt( unsigned char regnum, unsigned char val ); static unsigned char RCrt( unsigned char regnum ); static void WGfx( unsigned char regnum, unsigned char val ); static unsigned char RGfx( unsigned char regnum ); static void WAttr( unsigned char regnum, unsigned char val ); static void AttrOn( void ); static unsigned char RAttr( unsigned char regnum ); static void WHDR( unsigned char val ); static unsigned char RHDR( void ); static void WSFR( unsigned char val ); static void WSFR2( unsigned char val ); static void WClut( unsigned char regnum, unsigned char red, unsigned char green, unsigned char blue ); static void RClut( unsigned char regnum, unsigned char *red, unsigned char *green, unsigned char *blue ); static void clgen_WaitBLT( void ); static void clgen_BitBLT (u_short curx, u_short cury, u_short destx, u_short desty, u_short width, u_short height, u_short line_length); static void clgen_RectFill (u_short x, u_short y, u_short width, u_short height, u_char color, u_short line_length); static void bestclock(long freq, long *best, long *nom, long *den, long *div, long maxfreq); /*** END PROTOTYPES ********************************************************/ /*****************************************************************************/ /*** BEGIN Interface Used by the World ***************************************/ static int opencount = 0; /*--- Open /dev/fbx ---------------------------------------------------------*/ int clgenfb_open(struct fb_info *info, int user) { MOD_INC_USE_COUNT; if (opencount++ == 0) switch_monitor(1); return 0; } /*--- Close /dev/fbx --------------------------------------------------------*/ int clgenfb_release(struct fb_info *info, int user) { if (--opencount == 0) switch_monitor(0); MOD_DEC_USE_COUNT; return 0; } /*--- handle /dev/fbx ioctl calls ------------------------------------------*/ int clgenfb_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg, int con, struct fb_info *info) { printk(">clgenfb_ioctl()\n"); /* Nothing exciting here... */ printk("<clgenfb_ioctl()\n"); return -EINVAL; } /**** END Interface used by the World *************************************/ /****************************************************************************/ /**** BEGIN Hardware specific Routines **************************************/ static void clgen_detect(void) { printk(">clgen_detect()\n"); printk("<clgen_detect()\n"); } static int clgen_encode_fix(struct fb_fix_screeninfo *fix, const void *par, struct fb_info_gen *info) { struct clgenfb_par *_par = (struct clgenfb_par*) par; struct clgenfb_info *_info = (struct clgenfb_info*)info; memset(fix, 0, sizeof(struct fb_fix_screeninfo)); strcpy(fix->id, clgenfb_name); fix->smem_start = (char*)_info->fbmem_phys; /* monochrome: only 1 memory plane */ /* 8 bit and above: Use whole memory area */ fix->smem_len = _par->var.bits_per_pixel == 1 ? _info->size / 4 : _info->size; fix->type = _par->type; fix->type_aux = 0; fix->visual = _par->visual; fix->xpanstep = 1; fix->ypanstep = 1; fix->ywrapstep = 0; fix->line_length = _par->line_length; fix->mmio_start = (char *)_info->fbregs_phys; fix->mmio_len = 0x10000; fix->accel = FB_ACCEL_NONE; return 0; } static int clgen_decode_var(const struct fb_var_screeninfo *var, void *par, struct fb_info_gen *info) { long freq; int xres, hfront, hsync, hback; int yres, vfront, vsync, vback; int nom,den; /* translyting from pixels->bytes */ int i; static struct { int xres,yres; } modes[] = { {1600,1280}, {1280,1024}, {1024,768}, {800,600}, {640,480}, {-1,-1} }; struct clgenfb_par *_par = (struct clgenfb_par *)par; fb_info = (struct clgenfb_info*)info; printk("clgen_decode_var()\n"); printk("Requested: %dx%dx%d\n", var->xres,var->yres,var->bits_per_pixel); printk(" virtual: %dx%d\n", var->xres_virtual,var->yres_virtual); printk(" offset: (%d,%d)\n", var->xoffset, var->yoffset); printk("grayscale: %d\n", var->grayscale); #if 0 printk(" activate: 0x%x\n", var->activate); printk(" pixclock: %d\n", var->pixclock); printk(" htiming: %d;%d %d\n", var->left_margin,var->right_margin,var->hsync_len); printk(" vtiming: %d;%d %d\n", var->upper_margin,var->lower_margin,var->vsync_len); printk(" sync: 0x%x\n", var->sync); printk(" vmode: 0x%x\n", var->vmode); #endif _par->var = *var; switch (var->bits_per_pixel) { case 1: nom = 4; den = 8; break; /* 8 pixel per byte, only 1/4th of mem usable */ case 8: nom = 1; den = 1; break; /* 1 pixel == 1 byte */ case 16: nom = 2; den = 1; break; /* 2 bytes per pixel */ case 24: nom = 3; den = 1; break; /* 3 bytes per pixel */ case 32: nom = 4; den = 1; break; /* 4 bytes per pixel */ default: printk("clgen: mode %dx%dx%d rejected...color depth not supported.\n", var->xres, var->yres, var->bits_per_pixel); return -EINVAL; } if (_par->var.xres*nom/den * _par->var.yres > fb_info->size) { printk("clgen: mode %dx%dx%d rejected...resolution too high to fit into video memory!\n", var->xres, var->yres, var->bits_per_pixel); return -EINVAL; } /* use highest possible virtual resolution */ if (_par->var.xres_virtual == -1 && _par->var.yres_virtual == -1) { printk("clgen: using maximum available virtual resolution\n"); for (i=0; modes[i].xres != -1; i++) { if (modes[i].xres*nom/den * modes[i].yres < fb_info->size/2) break; } if (modes[i].xres == -1) { printk("clgen: could not find a virtual resolution that fits into video memory!!\n"); return -EINVAL; } _par->var.xres_virtual = modes[i].xres; _par->var.yres_virtual = modes[i].yres; printk("clgen: virtual resolution set to maximum of %dx%d\n", _par->var.xres_virtual, _par->var.yres_virtual); } else if (_par->var.xres_virtual == -1) { } else if (_par->var.yres_virtual == -1) { } if (_par->var.xoffset < 0) _par->var.xoffset = 0; if (_par->var.yoffset < 0) _par->var.yoffset = 0; /* truncate xoffset and yoffset to maximum if too high */ if (_par->var.xoffset > _par->var.xres_virtual-_par->var.xres) _par->var.xoffset = _par->var.xres_virtual-_par->var.xres -1; if (_par->var.yoffset > _par->var.yres_virtual-_par->var.yres) _par->var.yoffset = _par->var.yres_virtual-_par->var.yres -1; switch (var->bits_per_pixel) { case 1: _par->line_length = _par->var.xres_virtual / 8; _par->visual = FB_VISUAL_MONO10; break; case 8: _par->line_length = _par->var.xres_virtual; _par->visual = FB_VISUAL_PSEUDOCOLOR; _par->var.red.offset = 0; _par->var.red.length = 6; _par->var.green.offset = 0; _par->var.green.length = 6; _par->var.blue.offset = 0; _par->var.blue.length = 6; break; case 16: _par->line_length = _par->var.xres_virtual * 2; _par->visual = FB_VISUAL_DIRECTCOLOR; _par->var.red.offset = 10; _par->var.red.length = 5; _par->var.green.offset = 5; _par->var.green.length = 5; _par->var.blue.offset = 0; _par->var.blue.length = 5; break; case 24: _par->line_length = _par->var.xres_virtual * 3; _par->visual = FB_VISUAL_DIRECTCOLOR; _par->var.red.offset = 16; _par->var.red.length = 8; _par->var.green.offset = 8; _par->var.green.length = 8; _par->var.blue.offset = 0; _par->var.blue.length = 8; break; case 32: _par->line_length = _par->var.xres_virtual * 4; _par->visual = FB_VISUAL_DIRECTCOLOR; _par->var.red.offset = 16; _par->var.red.length = 8; _par->var.green.offset = 8; _par->var.green.length = 8; _par->var.blue.offset = 0; _par->var.blue.length = 8; break; } _par->var.red.msb_right = 0; _par->var.green.msb_right = 0; _par->var.blue.msb_right = 0; _par->var.transp.offset = 0; _par->var.transp.length = 0; _par->var.transp.msb_right = 0; _par->type = FB_TYPE_PACKED_PIXELS; /* convert from ps to kHz */ freq = 1000000000 / var->pixclock; DEBUG printk("desired pixclock: %ld kHz\n", freq); /* the SD64/P4 have a higher max. videoclock */ bestclock(freq, &_par->freq, &_par->nom, &_par->den, &_par->div, fb_info->btype == BT_SD64 || fb_info->btype == BT_PICASSO4 ? 140000 : 90000); DEBUG printk("Best possible values for given frequency: best: %ld kHz nom: %ld den: %ld div: %ld\n", _par->freq, _par->nom, _par->den, _par->div); xres = _par->var.xres; hfront = _par->var.right_margin; hsync = _par->var.hsync_len; hback = _par->var.left_margin; yres = _par->var.yres; vfront = _par->var.lower_margin; vsync = _par->var.vsync_len; vback = _par->var.upper_margin; if (_par->var.vmode & FB_VMODE_DOUBLE) { yres *= 2; vfront *= 2; vsync *= 2; vback *= 2; } else if (_par->var.vmode & FB_VMODE_INTERLACED) { yres = ++yres / 2; vfront = ++vfront / 2; vsync = ++vsync / 2; vback = ++vback / 2; } _par->HorizRes = xres; _par->HorizTotal = (xres + hfront + hsync + hback)/8 - 5; _par->HorizDispEnd = xres/8 - 1; _par->HorizBlankStart = xres/8; _par->HorizBlankEnd = _par->HorizTotal+5; /* does not count with "-5" */ _par->HorizSyncStart = (xres + hfront)/8 + 1; _par->HorizSyncEnd = (xres + hfront + hsync)/8 + 1; _par->VertRes = yres; _par->VertTotal = yres + vfront + vsync + vback -2; _par->VertDispEnd = yres - 1; _par->VertBlankStart = yres; _par->VertBlankEnd = _par->VertTotal; _par->VertSyncStart = yres + vfront - 1; _par->VertSyncEnd = yres + vfront + vsync - 1; if (_par->VertTotal >= 1024) { printk(KERN_WARNING "clgen: ERROR: VerticalTotal >= 1024; special treatment required! (TODO)\n"); return -EINVAL; } return 0; } static int clgen_encode_var(struct fb_var_screeninfo *var, const void *par, struct fb_info_gen *info) { *var = ((struct clgenfb_par*)par)->var; return 0; } /* get current video mode */ static void clgen_get_par(void *par, struct fb_info_gen *info) { struct clgenfb_par *_par = (struct clgenfb_par*)par; struct clgenfb_info*_info = (struct clgenfb_info*)fb_info; *_par = _info->currentmode; } /************************************************************************* clgen_set_par() actually writes the values for a new video mode into the hardware, **************************************************************************/ static void clgen_set_par(const void *par, struct fb_info_gen *info) { unsigned char tmp; int offset = 0; struct clgenfb_par *_par = (struct clgenfb_par*)par; printk(KERN_INFO">clgen_set_par()\n"); printk(KERN_INFO"Requested mode: %dx%dx%d\n", _par->var.xres, _par->var.yres, _par->var.bits_per_pixel); printk(KERN_INFO"pixclock: %d\n", _par->var.pixclock); fb_info = (struct clgenfb_info *)info; /* unlock register CRT0..CRT7 */ WCrt(CRT11, 0x20); /* previously: 0x00) */ /* if DEBUG is set, all parameters get output before writing */ DEBUG printk("CRT0: %ld\n", _par->HorizTotal); WCrt(CRT0, _par->HorizTotal); DEBUG printk("CRT1: %ld\n", _par->HorizDispEnd); WCrt(CRT1, _par->HorizDispEnd); DEBUG printk("CRT2: %ld\n", _par->HorizBlankStart); WCrt(CRT2, _par->HorizBlankStart); DEBUG printk("CRT3: 128+%ld\n", _par->HorizBlankEnd % 32); /* + 128: Compatible read */ WCrt(CRT3, 128 + (_par->HorizBlankEnd % 32)); DEBUG printk("CRT4: %ld\n", _par->HorizSyncStart); WCrt(CRT4, _par->HorizSyncStart); tmp = _par->HorizSyncEnd % 32; if (_par->HorizBlankEnd & 32) tmp += 128; DEBUG printk("CRT5: %d\n", tmp); WCrt(CRT5, tmp); DEBUG printk("CRT6: %ld\n", _par->VertTotal & 0xff); WCrt(CRT6, (_par->VertTotal & 0xff)); tmp = 16; /* LineCompare bit #9 */ if (_par->VertTotal & 256) tmp |= 1; if (_par->VertDispEnd & 256) tmp |= 2; if (_par->VertSyncStart & 256) tmp |= 4; if (_par->VertBlankStart & 256) tmp |= 8; if (_par->VertTotal & 512) tmp |= 32; if (_par->VertDispEnd & 512) tmp |= 64; if (_par->VertSyncStart & 512) tmp |= 128; DEBUG printk("CRT7: %d\n", tmp); WCrt(CRT7, tmp); tmp = 0x40; /* LineCompare bit #8 */ if (_par->VertBlankStart & 512) tmp |= 0x20; if (_par->var.vmode & FB_VMODE_DOUBLE) tmp |= 0x80; DEBUG printk("CRT9: %d\n", tmp); WCrt(CRT9, tmp); DEBUG printk("CRT10: %ld\n", _par->VertSyncStart & 0xff); WCrt(CRT10, (_par->VertSyncStart & 0xff)); DEBUG printk("CRT11: 64+32+%ld\n", _par->VertSyncEnd % 16); WCrt(CRT11, (_par->VertSyncEnd % 16 + 64 + 32)); DEBUG printk("CRT12: %ld\n", _par->VertDispEnd & 0xff); WCrt(CRT12, (_par->VertDispEnd & 0xff)); DEBUG printk("CRT15: %ld\n", _par->VertBlankStart & 0xff); WCrt(CRT15, (_par->VertBlankStart & 0xff)); DEBUG printk("CRT16: %ld\n", _par->VertBlankEnd & 0xff); WCrt(CRT16, (_par->VertBlankEnd & 0xff)); DEBUG printk("CRT18: 0xff\n"); WCrt(CRT18, 0xff); tmp = 0; if (_par->var.vmode & FB_VMODE_INTERLACED) tmp |= 1; if (_par->HorizBlankEnd & 64) tmp |= 16; if (_par->HorizBlankEnd & 128) tmp |= 32; if (_par->VertBlankEnd & 256) tmp |= 64; if (_par->VertBlankEnd & 512) tmp |= 128; DEBUG printk("CRT1a: %d\n", tmp); WCrt(CRT1A, tmp); /* set VCLK0 */ /* hardware RefClock: 14.31818 MHz */ /* formula: VClk = (OSC * N) / (D * (1+P)) */ /* Example: VClk = (14.31818 * 91) / (23 * (1+1)) = 28.325 MHz */ WSeq(SEQRB, _par->nom); tmp = _par->den<<1; if (_par->div != 0) tmp |= 1; if (fb_info->btype == BT_SD64) tmp |= 0x80; /* 6 bit denom; ONLY 5434!!! (bugged me 10 days) */ WSeq(SEQR1B, tmp); WCrt(CRT17, 0xc3); /* mode control: CRTC enable, ROTATE(?), 16bit address wrap, no compat. */ /* HAEH? WCrt(CRT11, 0x20); * previously: 0x00 unlock CRT0..CRT7 */ /* don't know if it would hurt to also program this if no interlaced */ /* mode is used, but I feel better this way.. :-) */ if (_par->var.vmode & FB_VMODE_INTERLACED) WCrt(CRT19, _par->HorizTotal / 2); else WCrt(CRT19, 0x00); /* interlace control */ WSeq(SEQR3, 0); /* adjust horizontal/vertical sync type (low/high) */ tmp = 0x03; /* enable display memory & CRTC I/O address for color mode */ if (_par->var.sync & FB_SYNC_HOR_HIGH_ACT) tmp |= 0x40; if (_par->var.sync & FB_SYNC_VERT_HIGH_ACT) tmp |= 0x80; WGen(MISC_W, tmp); WCrt(CRT8, 0); /* Screen A Preset Row-Scan register */ WCrt(CRTA, 0); /* text cursor on and start line */ WCrt(CRTB, 31); /* text cursor end line */ /* programming for different color depths */ if (_par->var.bits_per_pixel == 1) { DEBUG printk(KERN_INFO "clgen: preparing for 1 bit deep display\n"); #if 0 /* restore first 2 color registers for mono mode */ WClut( 0, 0x00, 0x00, 0x00); /* background: black */ WClut( 1, 0x3f, 0x3f, 0x3f); /* foreground: white */ #endif WGfx(GR5, 0); /* mode register */ /* Extended Sequencer Mode */ switch(fb_info->btype) { case BT_SD64: /* setting the SEQRF on SD64 is not necessary (only during init) */ DEBUG printk(KERN_INFO "(for SD64)\n"); WSeq(SEQR7, 0xf0); WSeq(SEQR1F, 0x1a); /* MCLK select */ break; case BT_PICCOLO: DEBUG printk(KERN_INFO "(for Piccolo)\n"); WSeq(SEQR7, 0x80); /* ### ueberall 0x22? */ WSeq(SEQR1F, 0x22); /* ##vorher 1c MCLK select */ WSeq(SEQRF, 0xb0); /* evtl d0 bei 1 bit? avoid FIFO underruns..? */ break; case BT_PICASSO: DEBUG printk(KERN_INFO "(for Picasso)\n"); WSeq(SEQR7, 0x20); WSeq(SEQR1F, 0x22); /* ##vorher 22 MCLK select */ WSeq(SEQRF, 0xd0); /* ## vorher d0 avoid FIFO underruns..? */ break; case BT_SPECTRUM: DEBUG printk(KERN_INFO "(for Spectrum)\n"); WSeq(SEQR7, 0x80); /* ### ueberall 0x22? */ WSeq(SEQR1F, 0x22); /* ##vorher 1c MCLK select */ WSeq(SEQRF, 0xb0); /* evtl d0? avoid FIFO underruns..? */ break; case BT_PICASSO4: DEBUG printk(KERN_INFO "(for Picasso 4)\n"); WSeq(SEQR7, 0x20); /* WSeq(SEQR1F, 0x1c); */ /* SEQRF not being set here... WSeq(SEQRF, 0xd0); */ break; default: printk(KERN_WARNING "clgen: unknown Board\n"); break; } WGen(M_3C6,0x01); /* pixel mask: pass-through for first plane */ WHDR(0); /* hidden dac reg: nothing special */ WSeq(SEQR4, 0x06); /* memory mode: odd/even, ext. memory */ WSeq(SEQR2, 0x01); /* plane mask: only write to first plane */ offset = _par->var.xres_virtual / 16; } else if (_par->var.bits_per_pixel == 8) { DEBUG printk(KERN_INFO "clgen: preparing for 8 bit deep display\n"); switch(fb_info->btype) { case BT_SD64: WSeq(SEQR7, 0xf1); /* Extended Sequencer Mode: 256c col. mode */ WSeq(SEQR1F, 0x1d); /* MCLK select */ break; case BT_PICCOLO: WSeq(SEQR7, 0x81); WSeq(SEQR1F, 0x22); /* ### vorher 1c MCLK select */ WSeq(SEQRF, 0xb0); /* Fast Page-Mode writes */ break; case BT_PICASSO: WSeq(SEQR7, 0x21); WSeq(SEQR1F, 0x22); /* ### vorher 1c MCLK select */ WSeq(SEQRF, 0xb0); /* Fast Page-Mode writes */ break; case BT_SPECTRUM: WSeq(SEQR7, 0x81); WSeq(SEQR1F, 0x22); /* ### vorher 1c MCLK select */ WSeq(SEQRF, 0xb0); /* Fast Page-Mode writes */ break; case BT_PICASSO4: WSeq(SEQR7, 0x21); WSeq(SEQRF, 0xb8); /* ### INCOMPLETE!! */ /* WSeq(SEQR1F, 0x1c); */ break; default: printk(KERN_WARNING "clgen: unknown Board\n"); break; } WGfx(GR5, 64); /* mode register: 256 color mode */ WGen(M_3C6,0xff); /* pixel mask: pass-through all planes */ WHDR(0); /* hidden dac reg: nothing special */ WSeq(SEQR4, 0x0a); /* memory mode: chain4, ext. memory */ WSeq(SEQR2, 0xff); /* plane mask: enable writing to all 4 planes */ offset = _par->var.xres_virtual / 8; } else if (_par->var.bits_per_pixel == 16) { DEBUG printk(KERN_INFO "clgen: preparing for 16 bit deep display\n"); switch(fb_info->btype) { case BT_SD64: WSeq(SEQR7, 0xf7); /* Extended Sequencer Mode: 256c col. mode */ WSeq(SEQR1F, 0x1e); /* MCLK select */ break; case BT_PICCOLO: WSeq(SEQR7, 0x87); WSeq(SEQRF, 0xb0); /* Fast Page-Mode writes */ WSeq(SEQR1F, 0x22); /* MCLK select */ break; case BT_PICASSO: WSeq(SEQR7, 0x27); WSeq(SEQRF, 0xb0); /* Fast Page-Mode writes */ WSeq(SEQR1F, 0x22); /* MCLK select */ break; case BT_SPECTRUM: WSeq(SEQR7, 0x87); WSeq(SEQRF, 0xb0); /* Fast Page-Mode writes */ WSeq(SEQR1F, 0x22); /* MCLK select */ break; case BT_PICASSO4: WSeq(SEQR7, 0x27); /* WSeq(SEQR1F, 0x1c); */ break; default: printk(KERN_WARNING "CLGEN: unknown Board\n"); break; } WGfx(GR5, 64); /* mode register: 256 color mode */ WGen(M_3C6,0xff); /* pixel mask: pass-through all planes */ WHDR(0xa0); /* hidden dac reg: nothing special */ WSeq(SEQR4, 0x0a); /* memory mode: chain4, ext. memory */ WSeq(SEQR2, 0xff); /* plane mask: enable writing to all 4 planes */ offset = _par->var.xres_virtual / 4; } else if (_par->var.bits_per_pixel == 32) { DEBUG printk(KERN_INFO "clgen: preparing for 24/32 bit deep display\n"); switch(fb_info->btype) { case BT_SD64: WSeq(SEQR7, 0xf9); /* Extended Sequencer Mode: 256c col. mode */ WSeq(SEQR1F, 0x1e); /* MCLK select */ break; case BT_PICCOLO: WSeq(SEQR7, 0x85); WSeq(SEQRF, 0xb0); /* Fast Page-Mode writes */ WSeq(SEQR1F, 0x22); /* MCLK select */ break; case BT_PICASSO: WSeq(SEQR7, 0x25); WSeq(SEQRF, 0xb0); /* Fast Page-Mode writes */ WSeq(SEQR1F, 0x22); /* MCLK select */ break; case BT_SPECTRUM: WSeq(SEQR7, 0x85); WSeq(SEQRF, 0xb0); /* Fast Page-Mode writes */ WSeq(SEQR1F, 0x22); /* MCLK select */ break; case BT_PICASSO4: WSeq(SEQR7, 0x25); /* WSeq(SEQR1F, 0x1c); */ break; default: printk(KERN_WARNING "clgen: unknown Board\n"); break; } WGfx(GR5, 64); /* mode register: 256 color mode */ WGen(M_3C6,0xff); /* pixel mask: pass-through all planes */ WHDR(0xc5); /* hidden dac reg: 8-8-8 mode (24 or 32) */ WSeq(SEQR4, 0x0a); /* memory mode: chain4, ext. memory */ WSeq(SEQR2, 0xff); /* plane mask: enable writing to all 4 planes */ offset = _par->var.xres_virtual / 4; } else printk(KERN_ERR "clgen: What's this?? requested color depth == %d.\n", _par->var.bits_per_pixel); WCrt(CRT13, offset & 0xff); tmp = 0x22; if (offset & 0x100) tmp |= 0x10; /* offset overflow bit */ WCrt(CRT1B,tmp); /* screen start addr #16-18, fastpagemode cycles */ if (fb_info->btype == BT_SD64 || fb_info->btype == BT_PICASSO4) WCrt(CRT1D, 0x00); /* screen start address bit 19 */ WCrt(CRTE, 0); /* text cursor location high */ WCrt(CRTF, 0); /* text cursor location low */ WCrt(CRT14, 0); /* underline row scanline = at very bottom */ WAttr(AR10, 1); /* controller mode */ WAttr(AR11, 0); /* overscan (border) color */ WAttr(AR12, 15); /* color plane enable */ WAttr(AR33, 0); /* pixel panning */ WAttr(AR14, 0); /* color select */ /* [ EGS: SetOffset(); ] */ /* From SetOffset(): Turn on VideoEnable bit in Attribute controller */ AttrOn(); WGfx(GR0, 0); /* set/reset register */ WGfx(GR1, 0); /* set/reset enable */ WGfx(GR2, 0); /* color compare */ WGfx(GR3, 0); /* data rotate */ WGfx(GR4, 0); /* read map select */ WGfx(GR6, 1); /* miscellaneous register */ WGfx(GR7, 15); /* color don't care */ WGfx(GR8, 255); /* bit mask */ WSeq(SEQR12, 0x0); /* graphics cursor attributes: nothing special */ /* finally, turn on everything - turn off "FullBandwidth" bit */ /* also, set "DotClock%2" bit where requested */ tmp = 0x01; /*** FB_VMODE_CLOCK_HALVE in linux/fb.h not defined anymore ? if (var->vmode & FB_VMODE_CLOCK_HALVE) tmp |= 0x08; */ WSeq(SEQR1, tmp); DEBUG printk("SEQR1: %d\n", tmp); #if 0 DEBUG printk(KERN_INFO "clgen: clearing display..."); clgen_RectFill(0, 0, _par->HorizRes, _par->VertRes, 0, _par->line_length); clgen_WaitBLT(); DEBUG printk("done.\n"); #endif fb_info->currentmode = *_par; printk("virtual offset: (%d,%d)\n", _par->var.xoffset,_par->var.yoffset); /* pan to requested offset */ clgen_pan_display (&fb_info->currentmode.var, (struct fb_info_gen*)fb_info); DEBUG printk("<clgen_set_par()\n"); return; } static int clgen_getcolreg(unsigned regno, unsigned *red, unsigned *green, unsigned *blue, unsigned *transp, struct fb_info *info) { unsigned char bred, bgreen, bblue; if (regno > 255) return (1); fb_info = (struct clgenfb_info *)info; RClut(regno, &bred, &bgreen, &bblue); *red = (bred<<10) | (bred<<4) | (bred>>2); *green = (bgreen<<10) | (bgreen<<4) | (bgreen>>2); *blue = (bblue<<10) | (bblue<<4) | (bblue>>2); *transp = 0; return (0); } static int clgen_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info) { if (regno > 255) return (1); fb_info = (struct clgenfb_info *)info; /* "transparent" stuff is completely ignored. */ WClut(regno, red>>10, green>>10, blue>>10); return (0); } /************************************************************************* clgen_pan_display() performs display panning - provided hardware permits this **************************************************************************/ static int clgen_pan_display(const struct fb_var_screeninfo *var, struct fb_info_gen *info) { int xoffset = 0; int yoffset = 0; unsigned long base; unsigned char tmp = 0, tmp2 = 0, xpix; fb_info = (struct clgenfb_info*)fb_info; /* no range checks for xoffset and yoffset, */ /* as fbgen_pan_display has already done this */ fb_info->currentmode.var.xoffset = var->xoffset; fb_info->currentmode.var.yoffset = var->yoffset; xoffset = var->xoffset * fb_info->currentmode.var.bits_per_pixel / 8; yoffset = var->yoffset; base = yoffset * fb_info->currentmode.line_length + xoffset; if (fb_info->currentmode.var.bits_per_pixel == 1) { /* base is already correct */ xpix = (unsigned char)(var->xoffset % 8); } else { base /= 4; xpix = (unsigned char)((xoffset % 4) * 2); } /* lower 8 + 8 bits of screen start address */ WCrt(CRTD, (unsigned char)(base & 0xff)); WCrt(CRTC, (unsigned char)(base >> 8)); /* construct bits 16, 17 and 18 of screen start address */ if (base & 0x10000) tmp |= 0x01; if (base & 0x20000) tmp |= 0x04; if (base & 0x40000) tmp |= 0x08; tmp2 = (RCrt(CRT1B) & 0xf2) | tmp; /* 0xf2 is %11110010, exclude tmp bits */ WCrt(CRT1B, tmp2); /* construct bit 19 of screen start address (only on SD64) */ if (fb_info->btype == BT_SD64 || fb_info->btype == BT_PICASSO4) { tmp2 = 0; if (base & 0x80000) tmp2 = 0x80; WCrt(CRT1D, tmp2); } /* write pixel panning value to AR33; this does not quite work in 8bpp */ /* ### Piccolo..? Will this work? */ if (fb_info->currentmode.var.bits_per_pixel == 1) WAttr(AR33, xpix); return(0); } static int clgen_blank(int blank_mode, struct fb_info_gen *info) { unsigned char val; printk(">clgen_blank(%d)\n",blank_mode); fb_info = (struct clgenfb_info *)info; val = RSeq(SEQR1); if (blank_mode) WSeq(SEQR1, val | 0x20); /* set "FullBandwidth" bit */ else WSeq(SEQR1, val & 0xdf); /* clear "FullBandwidth" bit */ printk("<clgen_blank()\n"); return 0; } /**** END Hardware specific Routines **************************************/ /****************************************************************************/ /**** BEGIN Internal Routines ***********************************************/ static void init_vgachip(void) { printk(">init_vgachip()\n"); /* reset board globally */ switch(fb_info->btype) { case BT_SD64: WSFR(0x1f); udelay(500); WSFR(0x4f); udelay(500); break; case BT_PICCOLO: WSFR(0x01); udelay(500); WSFR(0x51); udelay(500); break; case BT_PICASSO: WSFR2(0xff); udelay(500); break; case BT_SPECTRUM: WSFR(0x1f); udelay(500); WSFR(0x4f); udelay(500); break; case BT_PICASSO4: WCrt(CRT51, 0x00); /* disable flickerfixer */ udelay(100000); WGfx(GR2F, 0x00); /* from Klaus' NetBSD driver: */ WGfx(GR33, 0x00); /* put blitter into 542x compat */ WGfx(GR31, 0x00); /* mode */ break; default: printk(KERN_ERR "clgen: Warning: Unknown board type\n"); break; } /* "pre-set" a RAMsize; if the test succeeds, double it */ if (fb_info->btype == BT_SD64 || fb_info->btype == BT_PICASSO4) fb_info->size = 0x400000; else fb_info->size = 0x200000; /* assume it's a "large memory" board (2/4 MB) */ fb_info->smallboard = FALSE; /* the P4 is not fully initialized here; I rely on it having been */ /* inited under AmigaOS already, which seems to work just fine */ /* (Klaus advised to do it this way) */ if (fb_info->btype != BT_PICASSO4) { WGen(VSSM, 0x10); /* EGS: 0x16 */ WGen(POS102, 0x01); WGen(VSSM, 0x08); /* EGS: 0x0e */ if(fb_info->btype != BT_SD64) WGen(VSSM2, 0x01); WSeq(SEQR0, 0x03); /* reset sequencer logic */ WSeq(SEQR1, 0x21); /* FullBandwidth (video off) and 8/9 dot clock */ WGen(MISC_W, 0xc1); /* polarity (-/-), disable access to display memory, CRTC base address: color */ /* WGfx(GRA, 0xce); "magic cookie" - doesn't make any sense to me.. */ WSeq(SEQR6, 0x12); /* unlock all extension registers */ WGfx(GR31, 0x04); /* reset blitter */ if (fb_info->btype == BT_SD64) { WSeq(SEQRF, 0xb8); /* 4 MB Ram SD64, disable CRT fifo(!), 64 bit bus */ } else { WSeq(SEQR16, 0x0f); /* Perf. Tuning: Fix value..(?) */ WSeq(SEQRF, 0xb0); /* 2 MB DRAM, 8level write buffer, 32bit bus */ } } WSeq(SEQR2, 0xff); /* plane mask: nothing */ WSeq(SEQR3, 0x00); /* character map select: doesn't even matter in gx mode */ WSeq(SEQR4, 0x0e); /* memory mode: chain-4, no odd/even, ext. memory */ /* controller-internal base address of video memory */ switch(fb_info->btype) { case BT_SD64: WSeq(SEQR7, 0xf0); break; case BT_PICCOLO: WSeq(SEQR7, 0x80); break; case BT_SPECTRUM: WSeq(SEQR7, 0x80); break; case BT_PICASSO: WSeq(SEQR7, 0x20); break; case BT_PICASSO4: WSeq(SEQR7, 0x20); break; } /* WSeq(SEQR8, 0x00);*/ /* EEPROM control: shouldn't be necessary to write to this at all.. */ WSeq(SEQR10, 0x00); /* graphics cursor X position (incomplete; position gives rem. 3 bits */ WSeq(SEQR11, 0x00); /* graphics cursor Y position (..."... ) */ WSeq(SEQR12, 0x00); /* graphics cursor attributes */ WSeq(SEQR13, 0x00); /* graphics cursor pattern address */ /* writing these on a P4 might give problems.. */ if (fb_info->btype != BT_PICASSO4) { WSeq(SEQR17, 0x00); /* configuration readback and ext. color */ WSeq(SEQR18, 0x02); /* signature generator */ } /* MCLK select etc. */ switch(fb_info->btype) { case BT_PICCOLO: case BT_PICASSO: case BT_SPECTRUM: WSeq(SEQR1F, 0x22); break; case BT_SD64: WSeq(SEQR1F, 0x20); break; case BT_PICASSO4:/*WSeq(SEQR1F, 0x1c); */ break; } WCrt(CRT8, 0x00); /* Screen A preset row scan: none */ WCrt(CRTA, 0x20); /* Text cursor start: disable text cursor */ WCrt(CRTB, 0x00); /* Text cursor end: - */ WCrt(CRTC, 0x00); /* Screen start address high: 0 */ WCrt(CRTD, 0x00); /* Screen start address low: 0 */ WCrt(CRTE, 0x00); /* text cursor location high: 0 */ WCrt(CRTF, 0x00); /* text cursor location low: 0 */ WCrt(CRT14, 0x00); /* Underline Row scanline: - */ WCrt(CRT17, 0xc3); /* mode control: timing enable, byte mode, no compat modes */ WCrt(CRT18, 0x00); /* Line Compare: not needed */ /* ### add 0x40 for text modes with > 30 MHz pixclock */ WCrt(CRT1B, 0x02); /* ext. display controls: ext.adr. wrap */ WGfx(GR0, 0x00); /* Set/Reset registes: - */ WGfx(GR1, 0x00); /* Set/Reset enable: - */ WGfx(GR2, 0x00); /* Color Compare: - */ WGfx(GR3, 0x00); /* Data Rotate: - */ WGfx(GR4, 0x00); /* Read Map Select: - */ WGfx(GR5, 0x00); /* Mode: conf. for 16/4/2 color mode, no odd/even, read/write mode 0 */ WGfx(GR6, 0x01); /* Miscellaneous: memory map base address, graphics mode */ WGfx(GR7, 0x0f); /* Color Don't care: involve all planes */ WGfx(GR8, 0xff); /* Bit Mask: no mask at all */ WGfx(GRB, 0x28); /* Graphics controller mode extensions: finer granularity, 8byte data latches */ WGfx(GRC, 0xff); /* Color Key compare: - */ WGfx(GRD, 0x00); /* Color Key compare mask: - */ WGfx(GRE, 0x00); /* Miscellaneous control: - */ /* WGfx(GR10, 0x00);*/ /* Background color byte 1: - */ /* WGfx(GR11, 0x00); */ WAttr(AR0, 0x00); /* Attribute Controller palette registers: "identity mapping" */ WAttr(AR1, 0x01); WAttr(AR2, 0x02); WAttr(AR3, 0x03); WAttr(AR4, 0x04); WAttr(AR5, 0x05); WAttr(AR6, 0x06); WAttr(AR7, 0x07); WAttr(AR8, 0x08); WAttr(AR9, 0x09); WAttr(ARA, 0x0a); WAttr(ARB, 0x0b); WAttr(ARC, 0x0c); WAttr(ARD, 0x0d); WAttr(ARE, 0x0e); WAttr(ARF, 0x0f); WAttr(AR10, 0x01); /* Attribute Controller mode: graphics mode */ WAttr(AR11, 0x00); /* Overscan color reg.: reg. 0 */ WAttr(AR12, 0x0f); /* Color Plane enable: Enable all 4 planes */ /* ### WAttr(AR33, 0x00); * Pixel Panning: - */ WAttr(AR14, 0x00); /* Color Select: - */ WGen(M_3C6, 0xff); /* Pixel mask: no mask */ WGen(MISC_W, 0xc3); /* polarity (-/-), enable display mem, CRTC i/o base = color */ WGfx(GR31, 0x04); /* BLT Start/status: Blitter reset */ WGfx(GR31, 0x00); /* - " - : "end-of-reset" */ /* CLUT setup */ WClut( 0, 0x00, 0x00, 0x00); /* background: black */ WClut( 1, 0x3f, 0x3f, 0x3f); /* foreground: white */ WClut( 2, 0x00, 0x20, 0x00); WClut( 3, 0x00, 0x20, 0x20); WClut( 4, 0x20, 0x00, 0x00); WClut( 5, 0x20, 0x00, 0x20); WClut( 6, 0x20, 0x10, 0x00); WClut( 7, 0x20, 0x20, 0x20); WClut( 8, 0x10, 0x10, 0x10); WClut( 9, 0x10, 0x10, 0x30); WClut(10, 0x10, 0x30, 0x10); WClut(11, 0x10, 0x30, 0x30); WClut(12, 0x30, 0x10, 0x10); WClut(13, 0x30, 0x10, 0x30); WClut(14, 0x30, 0x30, 0x10); WClut(15, 0x30, 0x30, 0x30); /* the rest a grey ramp */ { int i; for (i = 16; i < 256; i++) WClut(i, i>>2, i>>2, i>>2); } /* misc... */ WHDR(0); /* Hidden DAC register: - */ #if 0 /* check for 1/2 MB Piccolo/Picasso/Spectrum resp. 2/4 MB SD64 */ /* DRAM register has already been pre-set for "large", so it is*/ /* only modified if we find that this is a "small" version */ { unsigned volatile char *ram = fb_info->fbmem; int i, flag = 0; ram += (fb_info->size >> 1); for (i = 0; i < 256; i++) ram[i] = (unsigned char)i; for (i = 0; i < 256; i++) { if (ram[i] != i) flag = 1; } /* if the DRAM test failed, halve RAM value */ if (flag) { fb_info->size /= 2; fb_info->smallboard = TRUE; switch(fb_info->btype) { case BT_SD64: WSeq(SEQRF, 0x38); break; /* 2 MB Ram SD64 */ case BT_PICASSO4: WSeq(SEQRF, 0x38); break; /* ### like SD64? */ case BT_PICCOLO: case BT_PICASSO: case BT_SPECTRUM: WSeq(SEQRF, 0x30); break; /* 1 MB DRAM */ default: printk(KERN_WARNING "clgen: Uuhh..could not determine RAM size!\n"); } } } #endif printk(KERN_INFO "clgen: This board has %ld bytes of DRAM memory\n", fb_info->size); printk("<init_vgachip()\n"); return; } static void switch_monitor(int on) { static int IsOn = 0; /* XXX not ok for multiple boards */ if (fb_info->btype == BT_PICASSO4) return; /* nothing to switch */ if (fb_info->btype == BT_PICASSO) { if ((on && !IsOn) || (!on && IsOn)) WSFR(0xff); return; } if (on) switch(fb_info->btype) { case BT_SD64: WSFR(fb_info->SFR | 0x21); break; case BT_PICCOLO: WSFR(fb_info->SFR | 0x28); break; case BT_SPECTRUM: WSFR(0x6f); break; } else switch(fb_info->btype) { case BT_SD64: WSFR(fb_info->SFR & 0xde); break; case BT_PICCOLO: WSFR(fb_info->SFR & 0xd7); break; case BT_SPECTRUM: WSFR(0x4f); break; } } static void clgen_set_disp(const void *par, struct display *disp, struct fb_info_gen *info) { struct clgenfb_par *_par = (struct clgenfb_par*) par; struct clgenfb_info *info2 = (struct clgenfb_info *)info; printk("clgen_set_disp(): "); disp->screen_base = info2->fbmem; switch (_par->var.bits_per_pixel) { #ifdef FBCON_HAS_MFB case 1: printk("monochrome\n"); disp->dispsw = &fbcon_mfb; break; #endif #ifdef FBCON_HAS_CFB8 case 8: printk("8 bit color depth\n"); disp->dispsw = &fbcon_clgen_8; break; #endif #ifdef FBCON_HAS_CFB16 case 16: printk("16 bit color depth\n"); disp->dispsw = &fbcon_cfb16; disp->dispsw_data = info2->fbcon_cmap.cfb16; break; #endif #ifdef FBCON_HAS_CFB24 case 24: printk("24 bit color depth\n"); disp->dispsw = &fbcon_cfb24; disp->dispsw_data = info2->fbcon_cmap.cfb24; break; #endif #ifdef FBCON_HAS_CFB32 case 32: printk("32 bit color depth\n"); disp->dispsw = &fbcon_cfb32; disp->dispsw_data = info2->fbcon_cmap.cfb32; break; #endif default: printk("unsupported color depth\n"); disp->dispsw = &fbcon_dummy; break; } } static void fbcon_clgen8_bmove(struct display *p, int sy, int sx, int dy, int dx, int height, int width) { sx *= fontwidth(p); sy *= fontheight(p); dx *= fontwidth(p); dy *= fontheight(p); width *= fontwidth(p); height *= fontheight(p); fb_info = (struct clgenfb_info*)p->fb_info; clgen_BitBLT((unsigned short)sx, (unsigned short)sy, (unsigned short)dx, (unsigned short)dy, (unsigned short)width, (unsigned short)height, fb_info->currentmode.line_length); clgen_WaitBLT(); } static void fbcon_clgen8_clear(struct vc_data *conp, struct display *p, int sy, int sx, int height, int width) { unsigned short col; fb_info = (struct clgenfb_info*)p->fb_info; sx *= fontwidth(p); sy *= fontheight(p); width *= fontwidth(p); height *= fontheight(p); col = attr_bgcol_ec(p, conp); col &= 0xff; clgen_RectFill((unsigned short)sx, (unsigned short)sy, (unsigned short)width,(unsigned short)height, col, fb_info->currentmode.line_length); clgen_WaitBLT(); } /********************************************************************/ /* clgenfb_init() - master initialization function */ /********************************************************************/ __initfunc(void clgenfb_init(void)) { const struct ConfigDev *cd = NULL; const struct ConfigDev *cd2 = NULL; int err; int btype; int key,key2; unsigned long board_addr,board_size; printk(">clgenfb_init()\n"); printk(KERN_INFO "clgen: Driver for Cirrus Logic based graphic boards, v" CLGEN_VERSION "\n"); btype = -1; if ((key = zorro_find(ZORRO_PROD_HELFRICH_SD64_RAM, 0, 0))) { key2 = zorro_find(ZORRO_PROD_HELFRICH_SD64_REG, 0, 0); btype = BT_SD64; printk(KERN_INFO "clgen: SD64 board detected; "); } else if ((key = zorro_find(ZORRO_PROD_HELFRICH_PICCOLO_RAM, 0, 0))) { key2 = zorro_find(ZORRO_PROD_HELFRICH_PICCOLO_REG, 0, 0); btype = BT_PICCOLO; printk(KERN_INFO "clgen: Piccolo board detected; "); } else if ((key = zorro_find(ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_RAM, 0, 0))) { key2 = zorro_find(ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_REG, 0, 0); btype = BT_PICASSO; printk(KERN_INFO "clgen: Picasso II board detected; "); } else if ((key = zorro_find(ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_RAM, 0, 0))) { key2 = zorro_find(ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_REG, 0, 0); btype = BT_SPECTRUM; printk(KERN_INFO "clgen: Spectrum board detected; "); } else if ((key = zorro_find(ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z3, 0, 0))) { btype = BT_PICASSO4; printk(KERN_INFO "clgen: Picasso 4 board detected; "); } else { printk(KERN_NOTICE "clgen: no supported board found.\n"); return; } fb_info = &boards[0]; /* FIXME support multiple boards ...*/ fb_info->keyRAM = key; fb_info->keyREG = key2; fb_info->btype = btype; cd = zorro_get_board(key); board_addr = (unsigned long)cd->cd_BoardAddr; board_size = (unsigned long)cd->cd_BoardSize; printk(" RAM (%lu MB) at $%lx, ", board_size/0x100000, board_addr); if (btype == BT_PICASSO4) { printk(" REG at $%lx\n", board_addr + 0x600000); /* To be precise, for the P4 this is not the */ /* begin of the board, but the begin of RAM. */ /* for P4, map in its address space in 2 chunks (### TEST! ) */ /* (note the ugly hardcoded 16M number) */ fb_info->regs = ioremap(board_addr, 16777216); DEBUG printk(KERN_INFO "clgen: Virtual address for board set to: $%p\n", fb_info->regs); fb_info->regs += 0x600000; fb_info->fbregs_phys = board_addr + 0x600000; fb_info->fbmem_phys = board_addr + 16777216; fb_info->fbmem = ioremap(fb_info->fbmem_phys, 16777216); DEBUG printk(KERN_INFO "clgen: (RAM start set to: $%lx)\n", fb_info->fbmem); } else { cd2 = zorro_get_board(key2); printk(" REG at $%lx\n", (unsigned long)cd2->cd_BoardAddr); fb_info->fbmem_phys = board_addr; if (board_addr > 0x01000000) fb_info->fbmem = ioremap(board_addr, board_size); else fb_info->fbmem = ZTWO_VADDR(board_addr); /* set address for REG area of board */ fb_info->regs = (unsigned char *)ZTWO_VADDR(cd2->cd_BoardAddr); fb_info->fbregs_phys = (unsigned long) cd2->cd_BoardAddr; DEBUG printk(KERN_INFO "clgen: Virtual address for board set to: $%p\n", fb_info->regs); DEBUG printk(KERN_INFO "clgen: (RAM start set to: $%lx)\n", fb_info->fbmem); } init_vgachip(); /* set up a few more things, register framebuffer driver etc */ fb_info->gen.parsize = sizeof(struct clgenfb_par); fb_info->gen.fbhw = &clgen_hwswitch; strcpy (fb_info->gen.info.modename, clgenfb_name); fb_info->gen.info.node = -1; fb_info->gen.info.fbops = &clgenfb_ops; fb_info->gen.info.disp = &disp; fb_info->gen.info.changevar = NULL; fb_info->gen.info.switch_con = &fbgen_switch; fb_info->gen.info.updatevar = &fbgen_update_var; fb_info->gen.info.blank = &fbgen_blank; fb_info->gen.info.flags = FBINFO_FLAG_DEFAULT; /* mark this board as "autoconfigured" */ zorro_config_board(key, 0); if (btype != BT_PICASSO4) zorro_config_board(key2, 0); /* now that we know the board has been registered n' stuff, we */ /* can finally initialize it to a default mode (640x480) */ clgenfb_default = clgenfb_predefined[1].var; clgenfb_default.activate = FB_ACTIVATE_NOW; clgenfb_default.yres_virtual = 480*3; /* for fast scrolling (YPAN-Mode) */ err = fbgen_do_set_var(&clgenfb_default, 1, &fb_info->gen); if (err) return; disp.var = clgenfb_default; fbgen_set_disp(-1, &fb_info->gen); fbgen_install_cmap(0, &fb_info->gen); err = register_framebuffer(&fb_info->gen.info); if (err) { printk(KERN_ERR "clgen: ERROR - could not register fb device; err = %d!\n", err); return; } printk("<clgenfb_init()\n"); return; } /* * Cleanup */ void clgenfb_cleanup(struct clgenfb_info *info) { printk(">clgenfb_cleanup()\n"); fb_info = info; switch_monitor(0); zorro_unconfig_board(info->keyRAM, 0); if (fb_info->btype != BT_PICASSO4) zorro_unconfig_board(info->keyREG, 0); unregister_framebuffer(&info->gen.info); printk("Framebuffer unregistered\n"); printk("<clgenfb_cleanup()\n"); } /* A strtok which returns empty strings, too */ static char *strtoke(char *s,const char *ct) { char *sbegin, *send; static char *ssave = NULL; sbegin = s ? s : ssave; if (!sbegin) return NULL; if (*sbegin == '\0') { ssave = NULL; return NULL; } send = strpbrk(sbegin, ct); if (send && *send != '\0') *send++ = '\0'; ssave = send; return sbegin; } /*****************************************************************/ /* clgenfb_setup() might be used later for parsing possible */ /* arguments to the video= bootstrap parameter. Right now, there */ /* is nothing I do here. */ /*****************************************************************/ __initfunc(void clgenfb_setup(char *options, int *ints)) { // char *this_opt; // printk("clgenfb_setup(): options: %s\n", options); } /* * Modularization */ #ifdef MODULE int init_module(void) { printk("init_module()\n"); clgenfb_init(); return 0; } void cleanup_module(void) { printk("module_cleanup()\n"); clgenfb_cleanup(fb_info); } #endif /* MODULE */ /**********************************************************************/ /* about the following functions - I have used the same names for the */ /* functions as Markus Wild did in his Retina driver for NetBSD as */ /* they just made sense for this purpose. Apart from that, I wrote */ /* these functions myself. */ /**********************************************************************/ /*** WGen() - write into one of the external/general registers ***/ void WGen(int regnum, unsigned char val) { unsigned volatile char *reg = fb_info->regs + regnum; if(fb_info->btype == BT_PICASSO) { /* Picasso II specific hack */ /* if (regnum == M_3C7_W || regnum == M_3C9 || regnum == VSSM2) */ if (regnum == M_3C7_W || regnum == M_3C9) reg += 0xfff; } *reg = val; } /*** RGen() - read out one of the external/general registers ***/ unsigned char RGen(int regnum) { unsigned volatile char *reg = fb_info->regs + regnum; if(fb_info->btype == BT_PICASSO) { /* Picasso II specific hack */ /* if (regnum == M_3C7_W || regnum == M_3C9 || regnum == VSSM2) */ if (regnum == M_3C7_W || regnum == M_3C9) reg += 0xfff; } return *reg; } /*** WSeq() - write into a register of the sequencer ***/ void WSeq(unsigned char regnum, unsigned char val) { fb_info->regs[SEQRX] = regnum; fb_info->regs[SEQRX+1] = val; } /*** RSeq() - read out one of the Sequencer registers ***/ unsigned char RSeq(unsigned char regnum) { fb_info->regs[SEQRX] = regnum; return fb_info->regs[SEQRX+1]; } /*** WCrt() - write into a register of the CRT controller ***/ void WCrt(unsigned char regnum, unsigned char val) { fb_info->regs[CRTX] = regnum; fb_info->regs[CRTX+1] = val; } /*** RCrt() - read out one of the CRT controller registers ***/ unsigned char RCrt(unsigned char regnum) { fb_info->regs[CRTX] = regnum; return fb_info->regs[CRTX+1]; } /*** WGfx() - write into a register of the Gfx controller ***/ void WGfx(unsigned char regnum, unsigned char val) { fb_info->regs[GRX] = regnum; fb_info->regs[GRX+1] = val; } /*** RGfx() - read out one of the Gfx controller registers ***/ unsigned char RGfx(unsigned char regnum) { fb_info->regs[GRX] = regnum; return fb_info->regs[GRX+1]; } /*** WAttr() - write into a register of the Attribute controller ***/ void WAttr(unsigned char regnum, unsigned char val) { /* if the next access to the attribute controller is a data write access, */ /* simply write back the information that was already there before, so that */ /* the next write access after that will be an index write. */ if (RCrt(CRT24) & 0x80) /* can't use WAttr() here - we would go into a recursive loop otherwise */ fb_info->regs[ARX] = fb_info->regs[ARX+1]; if (RCrt(CRT24) & 0x80) printk(KERN_WARNING "clgen: *** AttrIdx BAD!***\n"); /* now, first set index and after that the value - both to the same address (!) */ fb_info->regs[ARX] = regnum; fb_info->regs[ARX] = val; } /*** AttrOn() - turn on VideoEnable for Attribute controller ***/ void AttrOn() { if (RCrt(CRT24) & 0x80) /* if we're just in "write value" mode, write back the */ /* same value as before to not modify anything */ fb_info->regs[ARX] = fb_info->regs[ARX+1]; /* turn on video bit */ /* fb_info->regs[ARX] = 0x20; */ fb_info->regs[ARX] = 0x33; /* dummy write on Reg0 to be on "write index" mode next time */ fb_info->regs[ARX] = 0x00; } /*** RAttr() - read out a register of the Attribute controller ***/ unsigned char RAttr(unsigned char regnum) { /* (explanation see above in WAttr() ) */ if (RCrt(CRT24) & 0x80) fb_info->regs[ARX] = fb_info->regs[ARX+1]; fb_info->regs[ARX] = regnum; return fb_info->regs[ARX+1]; } /*** WHDR() - write into the Hidden DAC register ***/ /* as the HDR is the only extension register that requires special treatment * (the other extension registers are accessible just like the "ordinary" * registers of their functional group) here is a specialized routine for * accessing the HDR */ void WHDR(unsigned char val) { unsigned char dummy; if(fb_info->btype == BT_PICASSO) { /* Klaus' hint for correct access to HDR on some boards */ /* first write 0 to pixel mask (3c6) */ WGen(M_3C6, 0x00); udelay(200); /* next read dummy from pixel address (3c8) */ dummy = RGen(M_3C8); udelay(200); } /* now do the usual stuff to access the HDR */ dummy = RGen(M_3C6); udelay(200); dummy = RGen(M_3C6); udelay(200); dummy = RGen(M_3C6); udelay(200); dummy = RGen(M_3C6); udelay(200); WGen(M_3C6, val); udelay(200); if(fb_info->btype == BT_PICASSO) { /* now first reset HDR access counter */ dummy = RGen(M_3C8); udelay(200); /* and at the end, restore the mask value */ /* ## is this mask always 0xff? */ WGen(M_3C6, 0xff); udelay(200); } } /*** RHDR() - read out the Hidden DAC register ***/ /* I hope this does not break on the GD5428 - cannot test it. */ /* (Is there any board for the Amiga that uses the 5428 ?) */ unsigned char RHDR() { unsigned char dummy; dummy = RGen(M_3C6); dummy = RGen(M_3C6); dummy = RGen(M_3C6); dummy = RGen(M_3C6); return RGen(M_3C6); } /*** WSFR() - write to the "special function register" (SFR) ***/ void WSFR(unsigned char val) { fb_info->SFR = val; fb_info->regs[0x8000] = val; } /* The Picasso has a second register for switching the monitor bit */ void WSFR2(unsigned char val) { /* writing an arbitrary value to this one causes the monitor switcher */ /* to flip to Amiga display */ fb_info->SFR = val; fb_info->regs[0x9000] = val; } /*** WClut - set CLUT entry (range: 0..63) ***/ void WClut(unsigned char regnum, unsigned char red, unsigned char green, unsigned char blue) { unsigned int data = 0x3c9; /* address write mode register is not translated.. */ fb_info->regs[0x3c8] = regnum; if(fb_info->btype == BT_PICASSO || fb_info->btype == BT_PICASSO4) { /* but DAC data register IS, at least for Picasso II */ if(fb_info->btype == BT_PICASSO) data += 0xfff; fb_info->regs[data] = red; fb_info->regs[data] = green; fb_info->regs[data] = blue; } else { fb_info->regs[data] = blue; fb_info->regs[data] = green; fb_info->regs[data] = red; } } /*** RClut - read CLUT entry (range 0..63) ***/ void RClut(unsigned char regnum, unsigned char *red, unsigned char *green, unsigned char *blue) { unsigned int data = 0x3c9; fb_info->regs[0x3c7] = regnum; if(fb_info->btype == BT_PICASSO || fb_info->btype == BT_PICASSO4) { if(fb_info->btype == BT_PICASSO) data += 0xfff; *red = fb_info->regs[data]; *green = fb_info->regs[data]; *blue = fb_info->regs[data]; } else { *blue = fb_info->regs[data]; *green = fb_info->regs[data]; *red = fb_info->regs[data]; } } /******************************************************************* clgen_WaitBLT() Wait for the BitBLT engine to complete a possible earlier job *********************************************************************/ void clgen_WaitBLT() { /* now busy-wait until we're done */ while (RGfx(GR31) & 0x08) ; } /******************************************************************* clgen_BitBLT() perform accelerated "scrolling" ********************************************************************/ void clgen_BitBLT (u_short curx, u_short cury, u_short destx, u_short desty, u_short width, u_short height, u_short line_length) { u_short nwidth, nheight; u_long nsrc, ndest; u_char bltmode; nwidth = width - 1; nheight = height - 1; bltmode = 0x00; /* if source adr < dest addr, do the Blt backwards */ if (cury <= desty) { if (cury == desty) { /* if src and dest are on the same line, check x */ if (curx < destx) bltmode |= 0x01; } else bltmode |= 0x01; } if (!bltmode) { /* standard case: forward blitting */ nsrc = (cury * line_length) + curx; ndest = (desty * line_length) + destx; } else { /* this means start addresses are at the end, counting backwards */ nsrc = cury * line_length + curx + nheight * line_length + nwidth; ndest = desty * line_length + destx + nheight * line_length + nwidth; } // clgen_WaitBLT(); /* ### NOT OK for multiple boards! */ /* run-down of registers to be programmed: destination pitch source pitch BLT width/height source start destination start BLT mode BLT ROP GR0 / GR1: "fill color" start/stop */ /* pitch: set to line_length */ WGfx(GR24, line_length & 0xff); /* dest pitch low */ WGfx(GR25, (line_length >> 8)); /* dest pitch hi */ WGfx(GR26, line_length & 0xff); /* source pitch low */ WGfx(GR27, (line_length >> 8)); /* source pitch hi */ /* BLT width: actual number of pixels - 1 */ WGfx(GR20, nwidth & 0xff); /* BLT width low */ WGfx(GR21, (nwidth >> 8)); /* BLT width hi */ /* BLT height: actual number of lines -1 */ WGfx(GR22, nheight & 0xff); /* BLT height low */ WGfx(GR23, (nheight >> 8)); /* BLT width hi */ /* BLT destination */ WGfx(GR28, (u_char)(ndest & 0xff)); /* BLT dest low */ WGfx(GR29, (u_char)(ndest >> 8)); /* BLT dest mid */ WGfx(GR2A, (u_char)(ndest >> 16)); /* BLT dest hi */ /* BLT source */ WGfx(GR2C, (u_char)(nsrc & 0xff)); /* BLT src low */ WGfx(GR2D, (u_char)(nsrc >> 8)); /* BLT src mid */ WGfx(GR2E, (u_char)(nsrc >> 16)); /* BLT src hi */ /* BLT mode */ WGfx(GR30, bltmode); /* BLT mode */ /* BLT ROP: SrcCopy */ WGfx(GR32, 0x0d); /* BLT ROP */ /* and finally: GO! */ WGfx(GR31, 0x02); /* BLT Start/status */ } /******************************************************************* clgen_RectFill() perform accelerated rectangle fill ********************************************************************/ void clgen_RectFill (u_short x, u_short y, u_short width, u_short height, u_char color, u_short line_length) { u_short nwidth, nheight; u_long ndest; nwidth = width - 1; nheight = height - 1; ndest = (y * line_length) + x; // clgen_WaitBLT(); /* ### NOT OK for multiple boards! */ /* pitch: set to line_length */ WGfx(GR24, line_length & 0xff); /* dest pitch low */ WGfx(GR25, (line_length >> 8)); /* dest pitch hi */ WGfx(GR26, line_length & 0xff); /* source pitch low */ WGfx(GR27, (line_length >> 8)); /* source pitch hi */ /* BLT width: actual number of pixels - 1 */ WGfx(GR20, nwidth & 0xff); /* BLT width low */ WGfx(GR21, (nwidth >> 8)); /* BLT width hi */ /* BLT height: actual number of lines -1 */ WGfx(GR22, nheight & 0xff); /* BLT height low */ WGfx(GR23, (nheight >> 8)); /* BLT width hi */ /* BLT destination */ WGfx(GR28, (u_char)(ndest & 0xff)); /* BLT dest low */ WGfx(GR29, (u_char)(ndest >> 8)); /* BLT dest mid */ WGfx(GR2A, (u_char)(ndest >> 16)); /* BLT dest hi */ /* BLT source: set to 0 (is a dummy here anyway) */ WGfx(GR2C, 0x00); /* BLT src low */ WGfx(GR2D, 0x00); /* BLT src mid */ WGfx(GR2E, 0x00); /* BLT src hi */ /* This is a ColorExpand Blt, using the */ /* same color for foreground and background */ WGfx(GR0, color); /* foreground color */ WGfx(GR1, color); /* background color */ /* BLT mode: color expand, Enable 8x8 copy (faster?) */ WGfx(GR30, 0xc0); /* BLT mode */ /* BLT ROP: SrcCopy */ WGfx(GR32, 0x0d); /* BLT ROP */ /* and finally: GO! */ WGfx(GR31, 0x02); /* BLT Start/status */ } /************************************************************************** * bestclock() - determine closest possible clock lower(?) than the * desired pixel clock **************************************************************************/ #define abs(x) ((x)<0 ? -(x) : (x)) static void bestclock(long freq, long *best, long *nom, long *den, long *div, long maxfreq) { long n, h, d, f; *nom = 0; *den = 0; *div = 0; if (freq < 8000) freq = 8000; if (freq > maxfreq) freq = maxfreq; *best = 0; f = freq * 10; for(n = 32; n < 128; n++) { d = (143181 * n) / f; if ( (d >= 7) && (d <= 63) ) { if (d > 31) d = (d / 2) * 2; h = (14318 * n) / d; if ( abs(h - freq) < abs(*best - freq) ) { *best = h; *nom = n; if (d < 32) { *den = d; *div = 0; } else { *den = d / 2; *div = 1; } } } d = ( (143181 * n)+f-1) / f; if ( (d >= 7) && (d <= 63) ) { if (d > 31) d = (d / 2) * 2; h = (14318 * n) / d; if ( abs(h - freq) < abs(*best - freq) ) { *best = h; *nom = n; if (d < 32) { *den = d; *div = 0; } else { *den = d / 2; *div = 1; } } } } } |