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
|
/*
* Voicetronix OpenPCI Interface Driver for Zapata Telephony interface
*
* Written by Mark Spencer <markster@linux-support.net>
* Matthew Fredrickson <creslin@linux-support.net>
* Ben Kramer <ben@voicetronix.com.au>
* Ron Lee <ron@voicetronix.com.au>
*
* Copyright (C) 2001, Linux Support Services, Inc.
* Copyright (C) 2005 - 2007, Voicetronix
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/* Conditional debug options */
#define VERBOSE_TIMING 0
/* Driver constants */
#define DRIVER_DESCRIPTION "Voicetronix OpenPCI DAHDI driver"
#define DRIVER_AUTHOR "Mark Spencer <markster@digium.com> "\
"Voicetronix <support@voicetronix.com.au>"
#define NAME "wcopenpci"
#define MAX_PORTS 8 /* Maximum number of ports on each carrier */
#define MAX_CARDS 8 /* Maximum number of carriers per host */
#define DEFAULT_COUNTRY "AUSTRALIA"
#include <linux/init.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/delay.h>
#include <linux/sched.h>
#include <dahdi/kernel.h>
#include <dahdi/version.h>
#include "proslic.h"
#include <dahdi/wctdm_user.h>
/* Compatibility helpers */
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
#include <linux/interrupt.h>
#else
typedef void irqreturn_t;
#define IRQ_NONE
#define IRQ_HANDLED
#define IRQ_RETVAL(x)
#define __devexit_p(x) x
#endif
// Centos4.3 uses a modified 2.6.9 kernel, with no indication that
// it is different from the mainstream (or even Centos4.2 2.6.9)
// kernel, so we must crowbar off the dunce-hat manually here.
#if !defined CENTOS4_3 && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
typedef int gfp_t;
static inline void *kzalloc( size_t n, gfp_t flags ){
void *p = kmalloc(n,flags);
if (p) memset(p, 0, n);
return p;
}
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
#define DEFINE_MUTEX(x) DECLARE_MUTEX(x)
#define mutex_init(x) init_MUTEX(x)
#define mutex_lock(x) down(x)
#define mutex_lock_interruptible(x) down_interruptible(x)
#define mutex_trylock(x) down_trylock(x)
#define mutex_unlock(x) up(x)
#else
#include <linux/mutex.h>
#endif
static struct fxo_mode {
char *name;
int ohs;
int ohs2;
int rz;
int rt;
int ilim;
int dcv;
int mini;
int acim;
int ring_osc;
int ring_x;
} fxo_modes[] =
{
{ "FCC", 0, 0, 0, 1, 0, 0x3, 0, 0, }, /* US, Canada */
{ "TBR21", 0, 0, 0, 0, 1, 0x3, 0, 0x2, 0x7e6c, 0x023a, },
/* Austria, Belgium, Denmark, Finland, France, Germany,
Greece, Iceland, Ireland, Italy, Luxembourg, Netherlands,
Norway, Portugal, Spain, Sweden, Switzerland, and UK */
{ "ARGENTINA", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "AUSTRALIA", 1, 0, 0, 0, 0, 0, 0x3, 0x3, },
{ "AUSTRIA", 0, 1, 0, 0, 1, 0x3, 0, 0x3, },
{ "BAHRAIN", 0, 0, 0, 0, 1, 0x3, 0, 0x2, },
{ "BELGIUM", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "BRAZIL", 0, 0, 0, 0, 0, 0, 0x3, 0, },
{ "BULGARIA", 0, 0, 0, 0, 1, 0x3, 0x0, 0x3, },
{ "CANADA", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "CHILE", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "CHINA", 0, 0, 0, 0, 0, 0, 0x3, 0xf, },
{ "COLUMBIA", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "CROATIA", 0, 0, 0, 0, 1, 0x3, 0, 0x2, },
{ "CYRPUS", 0, 0, 0, 0, 1, 0x3, 0, 0x2, },
{ "CZECH", 0, 0, 0, 0, 1, 0x3, 0, 0x2, },
{ "DENMARK", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "ECUADOR", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "EGYPT", 0, 0, 0, 0, 0, 0, 0x3, 0, },
{ "ELSALVADOR", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "FINLAND", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "FRANCE", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "GERMANY", 0, 1, 0, 0, 1, 0x3, 0, 0x3, },
{ "GREECE", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "GUAM", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "HONGKONG", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "HUNGARY", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "ICELAND", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "INDIA", 0, 0, 0, 0, 0, 0x3, 0, 0x4, },
{ "INDONESIA", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "IRELAND", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "ISRAEL", 0, 0, 0, 0, 1, 0x3, 0, 0x2, },
{ "ITALY", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "JAPAN", 0, 0, 0, 0, 0, 0, 0x3, 0, },
{ "JORDAN", 0, 0, 0, 0, 0, 0, 0x3, 0, },
{ "KAZAKHSTAN", 0, 0, 0, 0, 0, 0x3, 0, },
{ "KUWAIT", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "LATVIA", 0, 0, 0, 0, 1, 0x3, 0, 0x2, },
{ "LEBANON", 0, 0, 0, 0, 1, 0x3, 0, 0x2, },
{ "LUXEMBOURG", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "MACAO", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "MALAYSIA", 0, 0, 0, 0, 0, 0, 0x3, 0, }, /* Current loop >= 20ma */
{ "MALTA", 0, 0, 0, 0, 1, 0x3, 0, 0x2, },
{ "MEXICO", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "MOROCCO", 0, 0, 0, 0, 1, 0x3, 0, 0x2, },
{ "NETHERLANDS", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "NEWZEALAND", 0, 0, 0, 0, 0, 0x3, 0, 0x4, },
{ "NIGERIA", 0, 0, 0, 0, 0x1, 0x3, 0, 0x2, },
{ "NORWAY", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "OMAN", 0, 0, 0, 0, 0, 0, 0x3, 0, },
{ "PAKISTAN", 0, 0, 0, 0, 0, 0, 0x3, 0, },
{ "PERU", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "PHILIPPINES", 0, 0, 0, 0, 0, 0, 0x3, 0, },
{ "POLAND", 0, 0, 1, 1, 0, 0x3, 0, 0, },
{ "PORTUGAL", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "ROMANIA", 0, 0, 0, 0, 0, 3, 0, 0, },
{ "RUSSIA", 0, 0, 0, 0, 0, 0, 0x3, 0, },
{ "SAUDIARABIA", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "SINGAPORE", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "SLOVAKIA", 0, 0, 0, 0, 0, 0x3, 0, 0x3, },
{ "SLOVENIA", 0, 0, 0, 0, 0, 0x3, 0, 0x2, },
{ "SOUTHAFRICA", 1, 0, 1, 0, 0, 0x3, 0, 0x3, },
{ "SOUTHKOREA", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "SPAIN", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "SWEDEN", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "SWITZERLAND", 0, 1, 0, 0, 1, 0x3, 0, 0x2, },
{ "SYRIA", 0, 0, 0, 0, 0, 0, 0x3, 0, },
{ "TAIWAN", 0, 0, 0, 0, 0, 0, 0x3, 0, },
{ "THAILAND", 0, 0, 0, 0, 0, 0, 0x3, 0, },
{ "UAE", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "UK", 0, 1, 0, 0, 1, 0x3, 0, 0x5, },
{ "USA", 0, 0, 0, 0, 0, 0x3, 0, 0, },
{ "YEMEN", 0, 0, 0, 0, 0, 0x3, 0, 0, },
};
static struct ps_country_reg {
const char *country;
unsigned short value;
} ps_country_regs[] = {
{"ARGENTINA", 0x8},
{"AUSTRALIA", 0xD},
{"AUSTRIA", 0xD},
{"BAHRAIN", 0xC},
{"BELGIUM", 0xC},
{"BRAZIL", 0x8},
{"BULGARIA", 0xD},
{"CANADA", 0x8},
{"CHILE", 0x8},
{"CHINA", 0xC},
{"COLOMBIA", 0x8},
{"CROATIA", 0xC},
{"CYPRUS", 0xC},
{"CZECH", 0xC},
{"DENMARK", 0xC},
{"ECUADOR", 0x8},
{"EGYPT", 0x8},
{"ELSALVADOR", 0x8},
{"FINLAND", 0xC},
{"FRANCE", 0xC},
{"GERMANY", 0xD},
{"GREECE", 0xC},
{"GUAM", 0x8},
{"HONGKONG", 0x8},
{"HUNGARY", 0x8},
{"ICELAND", 0xC},
{"INDIA", 0xF},
{"INDONESIA", 0x8},
{"IRELAND", 0xC},
{"ISRAEL", 0xC},
{"ITALY", 0xC},
{"JAPAN", 0x8},
{"JORDAN", 0x8},
{"KAZAKHSTAN", 0x8},
{"KUWAIT", 0x8},
{"LATVIA", 0xC},
{"LEBANON", 0xC},
{"LUXEMBOURG", 0xC},
{"MACAO", 0x8},
{"MALAYSIA", 0x8},
{"MALTA", 0xC},
{"MEXICO", 0x8},
{"MOROCCO", 0xC},
{"NETHERLANDS",0xC},
{"NEWZEALAND", 0xF},
{"NIGERIA", 0xC},
{"NORWAY", 0xC},
{"OMAN", 0x8},
{"PAKISTAN", 0x8},
{"PERU", 0x8},
{"PHILIPPINES",0x8},
{"POLAND", 0x8},
{"PORTUGAL", 0xC},
{"ROMANIA", 0x8},
{"RUSSIA", 0x8},
{"SAUDIARABIA",0x8},
{"SINGAPORE", 0x8},
{"SLOVAKIA", 0xE},
{"SLOVENIA", 0xE},
{"SOUTHAFRICA",0xE},
{"SOUTHKOREA", 0x8},
{"SPAIN", 0xC},
{"SWEDEN", 0xC},
{"SWITZERLAND",0xC},
{"SYRIA", 0x8},
{"TAIWAN", 0x8},
{"THAILAND", 0x8},
{"UAE", 0x8},
{"UK", 0xC},
{"USA", 0x8},
{"YEMEN", 0x8}
};
#define INOUT 2
/* Allocate enough memory for two zt chunks, receive and transmit. Each sample uses
32 bits. Allocate an extra set just for control too */
#define VT_PCIDMA_BLOCKSIZE (DAHDI_MAX_CHUNKSIZE * INOUT * MAX_PORTS * 2 * 2)
#define VT_PCIDMA_MIDDLE (DAHDI_MAX_CHUNKSIZE * MAX_PORTS - 4)
#define VT_PCIDMA_END (DAHDI_MAX_CHUNKSIZE * MAX_PORTS * 2 - 4)
#define ID_DATA_MAXSIZE 30
#define NUM_CAL_REGS 12
#define NUM_FXO_REGS 60
#define TREG(addr) (wc->ioaddr + addr)
#define TJ_CNTL TREG(0x00)
#define TJ_OPER TREG(0x01)
#define TJ_AUXC TREG(0x02)
#define TJ_AUXD TREG(0x03)
#define TJ_MASK0 TREG(0x04)
#define TJ_MASK1 TREG(0x05)
#define TJ_INTSTAT TREG(0x06)
#define TJ_AUXR TREG(0x07)
#define TJ_DMAWS TREG(0x08)
#define TJ_DMAWI TREG(0x0c)
#define TJ_DMAWE TREG(0x10)
#define TJ_DMAWC TREG(0x14)
#define TJ_DMARS TREG(0x18)
#define TJ_DMARI TREG(0x1c)
#define TJ_DMARE TREG(0x20)
#define TJ_DMARC TREG(0x24)
#define TJ_AUXINTPOL TREG(0x2A)
#define TJ_AUXFUNC TREG(0x2b)
#define TJ_SFDELAY TREG(0x2c)
#define TJ_SERCTL TREG(0x2d)
#define TJ_SFLC TREG(0x2e)
#define TJ_FSCDELAY TREG(0x2f)
#define TJ_REGBASE TREG(0xc0)
#define PIB(addr) (TJ_REGBASE + addr * 4)
#define HTXF_READY (inb(PIB(0)) & 0x10)
#define HRXF_READY (inb(PIB(0)) & 0x20)
#define VT_PORT_EMPTY 0
#define VT_PORT_VDAA 1 /* Voice DAA - FXO */
#define VT_PORT_PROSLIC 2 /* ProSLIC - FXS */
#define VBAT 0xC7
#define HKMODE_FWDACT 1
#define HKMODE_FWDONACT 2
#define HKMODE_RINGING 4
#define HOOK_ONHOOK 0
#define HOOK_OFFHOOK 1
#define DSP_CODEC_RING 12 /* RING rising edge detected */
#define DSP_CODEC_HKOFF 22 /* station port off hook */
#define DSP_CODEC_HKON 23 /* station port on hook */
#define DSP_RING_OFF 24 /* RING falling edge detected */
#define DSP_DROP 25
#define DSP_CODEC_FLASH 26 /* station port hook flash */
#define DSP_LOOP_OFFHOOK 38 /* Loop Off hook from OpenPCI */
#define DSP_LOOP_ONHOOK 39 /* Loop On hook from OpenPCI */
#define DSP_LOOP_POLARITY 40 /* Loop Polarity from OpenPCI */
#define DSP_LOOP_NOBATT 41
#define DSP_PROSLIC_SANITY 50 /* Sanity alert from a ProSLIC port */
#define DSP_PROSLIC_PWR_ALARM 51 /* Power Alarm from a ProSLIC port */
#define DSP_VDAA_ISO_FRAME_E 52 /* ISO-cap frame sync lost on VDAA port*/
#if VERBOSE_TIMING
#define REPORT_WAIT(n,x) \
cardinfo(card->cardnum, #n " wait at %d, " #x " = %d", __LINE__, x )
#else
#define REPORT_WAIT(n,x)
#endif
#define BUSY_WAIT(countvar,cond,delay,iter,failret) \
countvar=0; \
while(cond){ \
udelay(delay); \
if(++countvar > iter){ \
cardcrit(wc->boardnum, "busy wait FAILED at %d", __LINE__); \
return failret; \
} \
} \
REPORT_WAIT(busy,i)
#define LOCKED_WAIT(countvar,cond,delay,iter,failret) \
countvar=0; \
while(cond){ \
udelay(delay); \
if(++countvar > iter){ \
dbginfo(wc->boardnum,"busy wait failed at %d",__LINE__); \
spin_unlock_irqrestore(&wc->lock, flags); \
return failret; \
} \
} \
REPORT_WAIT(locked,i)
#define HTXF_WAIT() BUSY_WAIT(i,HTXF_READY,5,500,RET_FAIL)
#define HRXF_WAIT() BUSY_WAIT(i,!HRXF_READY,5,70000,RET_FAIL)
#define HTXF_WAIT_RET(failret) BUSY_WAIT(i,HTXF_READY,5,500,failret)
#define HRXF_WAIT_RET(failret) BUSY_WAIT(i,!HRXF_READY,5,1000,failret)
#define HTXF_WAIT_LOCKED() LOCKED_WAIT(i,HTXF_READY,5,500,RET_FAIL)
#define HRXF_WAIT_LOCKED() LOCKED_WAIT(i,!HRXF_READY,5,1000,RET_FAIL)
#define HTXF_WAIT_LOCKED_RET(failret) LOCKED_WAIT(i,HTXF_READY,5,500,failret)
#define HRXF_WAIT_LOCKED_RET(failret) LOCKED_WAIT(i,!HRXF_READY,5,1000,failret)
struct openpci {
struct pci_dev *dev;
char *variety;
int boardnum;
int portcount;
int porttype[MAX_PORTS];
int firmware;
char serial[ID_DATA_MAXSIZE];
spinlock_t lock;
//XXX Replace these with proper try_module_get locking in the dahdi driver.
//int usecount; //XXX
//int dead; //XXX
union {
struct {
int offhook;
} fxo;
struct {
int ohttimer;
int idletxhookstate; /* IDLE changing hook state */
int lasttxhook;
} fxs;
} mod[MAX_PORTS];
unsigned long ioaddr;
dma_addr_t readdma;
dma_addr_t writedma;
volatile unsigned int *writechunk; /* Double-word aligned write memory */
volatile unsigned int *readchunk; /* Double-word aligned read memory */
struct dahdi_chan _chans[MAX_PORTS];
struct dahdi_chan *chans[MAX_PORTS];
struct dahdi_device *ddev;
struct dahdi_span span;
} *cards[MAX_CARDS];
// You must hold this lock anytime you access or modify the cards[] array.
DEFINE_MUTEX(cards_mutex);
static unsigned char fxo_port_lookup[8] = { 0x0, 0x8, 0x4, 0xc, 0x10, 0x18, 0x14, 0x1c};
static unsigned char fxs_port_lookup[8] = { 0x0, 0x1, 0x2, 0x3, 0x10, 0x11, 0x12, 0x13};
static char wcopenpci[] = "Voicetronix OpenPCI";
static char *country = DEFAULT_COUNTRY;
static int reversepolarity; // = 0
static int debug; // = 0
module_param(country, charp, 0444);
module_param(debug, int, 0600);
module_param(reversepolarity, int, 0600);
MODULE_PARM_DESC(country, "Set the default country name");
MODULE_PARM_DESC(debug, "Enable verbose logging");
//#define DEBUG_LOOP_VOLTAGE 1
#ifdef DEBUG_LOOP_VOLTAGE
// This param is a 32 bit bitfield where bit 1 << cardnum * 8 << portnum
// will enable voltage monitoring on that port (fxo only presently)
static int voltmeter; // = 0
module_param(voltmeter, int, 0600);
MODULE_PARM_DESC(voltmeter, "Enable loop voltage metering");
#endif
/* boolean return values */
#define RET_OK 1
#define RET_FAIL 0
/* Convenience macros for logging */
#define info(format,...) printk(KERN_INFO NAME ": " format "\n" , ## __VA_ARGS__)
#define warn(format,...) printk(KERN_WARNING NAME ": " format "\n" , ## __VA_ARGS__)
#define crit(format,...) printk(KERN_CRIT NAME ": " format "\n" , ## __VA_ARGS__)
#define cardinfo(cardnum,format,...) info("[%02d] " format, cardnum , ## __VA_ARGS__)
#define cardwarn(cardnum,format,...) warn("[%02d] " format, cardnum , ## __VA_ARGS__)
#define cardcrit(cardnum,format,...) crit("[%02d] " format, cardnum , ## __VA_ARGS__)
#define dbginfo(cardnum,format,...) if(debug) info("[%02d] " format, cardnum , ## __VA_ARGS__)
static inline const char *porttype(struct openpci *wc, int port)
{ //{{{
switch( wc->porttype[port] ) {
case VT_PORT_VDAA: return "VDAA";
case VT_PORT_PROSLIC: return "ProSLIC";
case VT_PORT_EMPTY: return "empty port";
default: return "unknown type";
}
} //}}}
static int __read_reg_fxo(struct openpci *wc, int port, unsigned char reg, unsigned char *value)
{ //{{{
unsigned char portadr = fxo_port_lookup[port];
int i;
if (HRXF_READY) *value = inb(PIB(1));
outb(0x11, PIB(1)); HTXF_WAIT();
outb(0x2, PIB(1)); HTXF_WAIT();
outb(portadr, PIB(1)); HTXF_WAIT();
outb(reg, PIB(1)); HTXF_WAIT();
HRXF_WAIT(); *value = inb(PIB(1));
return RET_OK;
} //}}}
static int read_reg_fxo(struct openpci *wc, int port, unsigned char reg, unsigned char *value)
{ //{{{
unsigned long flags;
spin_lock_irqsave(&wc->lock, flags);
if( __read_reg_fxo(wc, port, reg, value) ){
spin_unlock_irqrestore(&wc->lock, flags);
return RET_OK;
}
spin_unlock_irqrestore(&wc->lock, flags);
cardcrit(wc->boardnum, "FXO port %d, reg %d, read failed!", port, reg);
return RET_FAIL;
} //}}}
static int __read_reg_fxs(struct openpci *wc, int port, unsigned char reg, unsigned char *value)
{ //{{{
unsigned char portadr = fxs_port_lookup[port];
int i;
if (HRXF_READY) *value = inb(PIB(1));
outb(0x13, PIB(1)); HTXF_WAIT();
outb(0x2, PIB(1)); HTXF_WAIT();
outb(portadr, PIB(1)); HTXF_WAIT();
outb(reg, PIB(1)); HTXF_WAIT();
HRXF_WAIT(); *value = inb(PIB(1));
return RET_OK;
} //}}}
static int read_reg_fxs(struct openpci *wc, int port, unsigned char reg, unsigned char *value)
{ //{{{
unsigned long flags;
spin_lock_irqsave(&wc->lock, flags);
if( __read_reg_fxs(wc, port, reg, value) ) {
spin_unlock_irqrestore(&wc->lock, flags);
return RET_OK;
}
spin_unlock_irqrestore(&wc->lock, flags);
cardcrit(wc->boardnum, "FXS port %d, reg %d, read failed!", port, reg);
return RET_FAIL;
} //}}}
static int __write_reg_fxo(struct openpci *wc, int port, unsigned char reg, unsigned char value)
{ //{{{
unsigned char portadr = fxo_port_lookup[port];
int i;
outb(0x10, PIB(1) ); HTXF_WAIT();
outb(0x3, PIB(1)); HTXF_WAIT();
outb(portadr, PIB(1)); HTXF_WAIT();
outb(reg, PIB(1)); HTXF_WAIT();
outb(value, PIB(1)); HTXF_WAIT();
return RET_OK;
} //}}}
static int write_reg_fxo(struct openpci *wc, int port, unsigned char reg, unsigned char value)
{ //{{{
unsigned long flags;
spin_lock_irqsave(&wc->lock, flags);
if( __write_reg_fxo(wc, port, reg, value) ){
spin_unlock_irqrestore(&wc->lock, flags);
return RET_OK;
}
spin_unlock_irqrestore(&wc->lock, flags);
cardcrit(wc->boardnum, "FXO port %d, reg %d, write(%d) failed!", port, reg, value);
return RET_FAIL;
} //}}}
static int __write_reg_fxs(struct openpci *wc, int port, unsigned char reg, unsigned char value)
{ //{{{
unsigned char portadr = fxs_port_lookup[port];
int i;
outb(0x12, PIB(1) ); HTXF_WAIT();
outb(0x3, PIB(1)); HTXF_WAIT();
outb(portadr, PIB(1)); HTXF_WAIT();
outb(reg, PIB(1)); HTXF_WAIT();
outb(value, PIB(1)); HTXF_WAIT();
return RET_OK;
} //}}}
static int write_reg_fxs(struct openpci *wc, int port, unsigned char reg, unsigned char value)
{ //{{{
unsigned long flags;
spin_lock_irqsave(&wc->lock, flags);
if( __write_reg_fxs(wc, port, reg, value) ){
spin_unlock_irqrestore(&wc->lock, flags);
return RET_OK;
}
spin_unlock_irqrestore(&wc->lock, flags);
cardcrit(wc->boardnum, "FXS port %d, reg %d, write(%d) failed!", port, reg, value);
return RET_FAIL;
} //}}}
static int __wait_indreg_fxs(struct openpci *wc, int port)
{ //{{{
unsigned char value;
int count = 100;
while (--count)
{
if( __read_reg_fxs(wc, port, I_STATUS, &value) ){
if( value == 0 )
return RET_OK;
} else {
cardcrit(wc->boardnum,
"failed to read port %d PS_IND_ADDR_ST, retrying...",
port);
}
udelay(5);
}
cardcrit(wc->boardnum, "Failed to wait for indirect reg write to port %d", port);
return RET_FAIL;
} //}}}
static int write_indreg_fxs(struct openpci *wc, int port, unsigned char reg, unsigned short value)
{ //{{{
unsigned long flags;
spin_lock_irqsave(&wc->lock, flags);
if( __wait_indreg_fxs(wc, port)
&& __write_reg_fxs(wc, port, IDA_LO, value & 0xff)
&& __write_reg_fxs(wc, port, IDA_HI, (value & 0xff00)>>8)
&& __write_reg_fxs(wc, port, IAA, reg)
&& __wait_indreg_fxs(wc, port) )
{
spin_unlock_irqrestore(&wc->lock, flags);
return RET_OK;
}
spin_unlock_irqrestore(&wc->lock, flags);
cardcrit(wc->boardnum, "FXS indreg %d write failed on port %d", reg, port);
return RET_FAIL;
} //}}}
static int read_indreg_fxs(struct openpci *wc, int port, unsigned char reg, unsigned short *value)
{ //{{{
unsigned long flags;
unsigned char lo, hi;
spin_lock_irqsave(&wc->lock, flags);
if( __wait_indreg_fxs(wc, port)
&& __write_reg_fxs(wc, port, IAA, reg)
&& __wait_indreg_fxs(wc, port)
&& __read_reg_fxs(wc, port, IDA_LO, &lo)
&& __read_reg_fxs(wc, port, IDA_HI, &hi) )
{
*value = lo | hi << 8;
spin_unlock_irqrestore(&wc->lock, flags);
return RET_OK;
}
spin_unlock_irqrestore(&wc->lock, flags);
return RET_FAIL;
} //}}}
static void start_dma(struct openpci *wc)
{ //{{{
outb(0x0f, TJ_CNTL);
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1);
outb(0x01, TJ_CNTL);
outb(0x01, TJ_OPER);
} //}}}
static void restart_dma(struct openpci *wc)
{ //{{{
/* Reset Master and TDM */
outb(0x01, TJ_CNTL);
outb(0x01, TJ_OPER);
} //}}}
/* You must hold the card spinlock to call this function */
static int __ping_arm(struct openpci *wc)
{ //{{{
int i;
int pong=0;
while(pong != 0x02){
outb(0x02, PIB(1)); HTXF_WAIT();
HRXF_WAIT(); pong = inb(PIB(1));
dbginfo(wc->boardnum, "ping_arm returned %x", pong);
}
while(pong == 0x02){
// Poke no-ops into the arm while it is still returning data,
// if 500 usec elapses with no further response from it then
// the message queue is should be completely cleared.
outb(0x00, PIB(1)); HTXF_WAIT();
i = 100;
while( !HRXF_READY && --i ) udelay(5);
if( i == 0 ) break;
pong = inb(PIB(1));
dbginfo(wc->boardnum, "ping_arm returned %x.", pong);
}
return RET_OK;
} //}}}
static void arm_event(struct openpci *wc, char *msg)
{ //{{{
int port = msg[0];
switch(msg[1]){
case DSP_LOOP_OFFHOOK:
dahdi_hooksig(wc->chans[port], DAHDI_RXSIG_OFFHOOK);
dbginfo(wc->boardnum, "Port %d Loop OffHook", port);
break;
case DSP_LOOP_ONHOOK:
dahdi_hooksig(wc->chans[port], DAHDI_RXSIG_ONHOOK);
dbginfo(wc->boardnum, "Port %d Loop OnHook", port);
break;
case DSP_LOOP_POLARITY:
dahdi_qevent_lock(wc->chans[port], DAHDI_EVENT_POLARITY);
dbginfo(wc->boardnum, "Port %d Loop Polarity", port);
break;
case DSP_CODEC_RING:
dahdi_hooksig(wc->chans[port], DAHDI_RXSIG_RING);
dbginfo(wc->boardnum, "Port %d Ring On", port);
break;
case DSP_RING_OFF:
dahdi_hooksig(wc->chans[port], DAHDI_RXSIG_OFFHOOK);
dbginfo(wc->boardnum, "Port %d Ring Off", port);
break;
case DSP_CODEC_HKOFF:
dahdi_hooksig(wc->chans[port], DAHDI_RXSIG_OFFHOOK);
dbginfo(wc->boardnum, "Port %d Station OffHook", port);
if (reversepolarity)
wc->mod[port].fxs.idletxhookstate = 5;
else
wc->mod[port].fxs.idletxhookstate = 1;
break;
case DSP_CODEC_HKON:
dahdi_hooksig(wc->chans[port], DAHDI_RXSIG_ONHOOK);
dbginfo(wc->boardnum, "Port %d Station OnHook", port);
if (reversepolarity)
wc->mod[port].fxs.idletxhookstate = 6;
else
wc->mod[port].fxs.idletxhookstate = 2;
break;
case DSP_CODEC_FLASH:
dahdi_qevent_lock(wc->chans[port], DAHDI_EVENT_WINKFLASH);
dbginfo(wc->boardnum, "Port %d Station Flash", port);
break;
case DSP_DROP:
case DSP_LOOP_NOBATT:
break;
//XXX What to do to recover from these?
case DSP_PROSLIC_SANITY:
dbginfo(wc->boardnum, "Port %d ProSlic has gone insane!", port);
break;
case DSP_PROSLIC_PWR_ALARM:
{
char errbuf[32] = " Unknown", *p = errbuf;
int i = 49;
msg[2] >>= 2;
for(; i < 55; ++i, msg[2] >>= 1 )
if(msg[2] & 1){ *(++p)='Q'; *(++p)=i; *(++p)=','; }
if( p != errbuf ) *p = '\0';
cardcrit(wc->boardnum,"%d: ProSlic power ALARM:%s",msg[0],errbuf);
//write_reg_fxs(wc, port, 64, wc->mod[port].fxs.lasttxhook );
return;
}
case DSP_VDAA_ISO_FRAME_E:
dbginfo(wc->boardnum, "Port %d VDAA has lost ISO-Cap frame lock", port);
break;
default:
cardwarn(wc->boardnum, "Unknown message from Arm[%d] for port %d",
msg[1], port);
break;
}
} //}}}
/* You must hold the card spinlock to call this function */
static inline int __read_arm_byte( struct openpci *wc, unsigned char *msg )
{ //{{{
int i;
HRXF_WAIT(); *msg = inb(PIB(1));
return RET_OK;
} //}}}
static inline int read_arm_msg( struct openpci *wc, unsigned char *msg )
{ //{{{
unsigned long flags;
int i, d, count;
int ret = RET_OK;
spin_lock_irqsave(&wc->lock, flags);
outb(0x08, PIB(1)); HTXF_WAIT_LOCKED();
//XXX Do we need to clear the interrupt flag even if this fails?
HRXF_WAIT_LOCKED(); count = inb(PIB(1));
if( count == 0 ){
ret = RET_FAIL;
} else if( count < 3 || count > 4 ){
cardcrit(wc->boardnum, "BOGUS arm message size %d, flushing queue", count);
// NB: This may take a while (up to 500usec or more) to complete
// and we are in the isr at present when this is called, so
// we may miss an interrupt or two while this is done in the
// bottom half, but we are already in trouble, so...
d = debug; debug = 5; __ping_arm( wc ); debug = d;
ret = RET_FAIL;
} else while( --count ){
if( ! __read_arm_byte(wc, msg) ){
cardcrit(wc->boardnum,
"Failed to read arm message %d more bytes expected",
count);
ret = RET_FAIL;
break;
}
++msg;
}
outb(0x09, PIB(1)); HTXF_WAIT_LOCKED();
spin_unlock_irqrestore(&wc->lock, flags);
return ret;
} //}}}
static void openpci_arm_work( void *cardptr )
{ //{{{
struct openpci *wc = (struct openpci*)cardptr;
unsigned char armmsg[4];
if( read_arm_msg(wc, armmsg) ) arm_event(wc, armmsg);
} //}}}
static inline void openpci_write(struct openpci *wc, unsigned char flags)
{ //{{{
int x,y;
volatile unsigned int *writechunk;
if (flags & 0x01)
writechunk = wc->writechunk;
else if (flags & 0x02)
writechunk = wc->writechunk + DAHDI_CHUNKSIZE*2;
else {
cardcrit(wc->boardnum, "bad write interrupt flags %x, at %x",
flags, inb(TJ_DMAWC) );
return;
}
/* get data */
dahdi_transmit(&wc->span);
for (y=0,x=0;x<DAHDI_CHUNKSIZE;++x) {
/* Send a sample, as a 32-bit word */
#ifdef __BIG_ENDIAN
#warning No big endian support (yet)
#else
/* transmit second 4 ports */
writechunk[y]=0;
if (wc->porttype[4])
writechunk[y] |= (wc->chans[4]->writechunk[x] << 24);
else
writechunk[y] |= (0x01 << 24);
if (wc->porttype[5])
writechunk[y] |= (wc->chans[5]->writechunk[x] << 16);
if (wc->porttype[6])
writechunk[y] |= (wc->chans[6]->writechunk[x] << 8);
if (wc->porttype[7])
writechunk[y] |= (wc->chans[7]->writechunk[x]);
++y;
/* transmit first 4 ports */
writechunk[y]=0x01000000;
/* Make sure first port doesnt equal 0x00 */
if (wc->porttype[0]){
if (wc->chans[0]->writechunk[x] == 0)
writechunk[y] |= (0x01 << 24);
else
writechunk[y] |= (wc->chans[0]->writechunk[x] << 24);
}
//else writechunk[y] |= (0x00 << 24);
if (wc->porttype[1])
writechunk[y] |= (wc->chans[1]->writechunk[x] << 16);
if (wc->porttype[2])
writechunk[y] |= (wc->chans[2]->writechunk[x] << 8);
if (wc->porttype[3])
writechunk[y] |= (wc->chans[3]->writechunk[x]);
++y;
#endif
}
} //}}}
static inline void openpci_read(struct openpci *wc, unsigned char flags)
{ //{{{
int x,y;
volatile unsigned int *readchunk;
if (flags & 0x08)
readchunk = wc->readchunk + DAHDI_CHUNKSIZE*2;
else if (flags & 0x04)
readchunk = wc->readchunk;
else {
cardcrit(wc->boardnum, "bad read interrupt flags %x, at %x",
flags, inb(TJ_DMARC));
return;
}
for (y=0,x=0;x<DAHDI_CHUNKSIZE;++x) {
#ifdef __BIG_ENDIAN
#warning No big endian support (yet)
#else
/* Receive first 4 ports */
if (wc->porttype[0])
wc->chans[0]->readchunk[x] = (readchunk[y] >> 24) & 0xff;
if (wc->porttype[1])
wc->chans[1]->readchunk[x] = (readchunk[y] >> 16) & 0xff;
if (wc->porttype[2])
wc->chans[2]->readchunk[x] = (readchunk[y] >> 8) & 0xff;
if (wc->porttype[3])
wc->chans[3]->readchunk[x] = (readchunk[y]) & 0xff;
++y;
/* Receive second 4 ports */
if (wc->porttype[4])
wc->chans[4]->readchunk[x] = (readchunk[y] >> 24) & 0xff;
if (wc->porttype[5])
wc->chans[5]->readchunk[x] = (readchunk[y] >> 16) & 0xff;
if (wc->porttype[6])
wc->chans[6]->readchunk[x] = (readchunk[y] >> 8) & 0xff;
if (wc->porttype[7])
wc->chans[7]->readchunk[x] = (readchunk[y]) & 0xff;
++y;
#endif
}
/* XXX We're wasting 8 taps. We should get closer :( */
for (x = 0; x < MAX_PORTS; x++) {
if (wc->porttype[x])
dahdi_ec_chunk(wc->chans[x], wc->chans[x]->readchunk, wc->chans[x]->writechunk);
}
dahdi_receive(&wc->span);
} //}}}
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
static irqreturn_t openpci_isr(int irq, void *dev_id, struct pt_regs *regs)
#else
static irqreturn_t openpci_isr(int irq, void *dev_id)
#endif
{ //{{{
struct openpci *wc = dev_id;
unsigned long flags;
unsigned char status;
spin_lock_irqsave(&wc->lock, flags);
status = inb(TJ_INTSTAT);
outb(status, TJ_INTSTAT);
if (!status) {
if(inb(TJ_AUXR) & 0x02) {
spin_unlock_irqrestore(&wc->lock, flags);
return IRQ_NONE;
}
spin_unlock_irqrestore(&wc->lock, flags);
openpci_arm_work(wc);
return IRQ_HANDLED;
}
if (status & 0x10){
/* PCI Master abort */
cardcrit(wc->boardnum, "PCI Master Abort.");
/* Stop DMA, wait for watchdog */
outb(0x00, TJ_OPER);
spin_unlock_irqrestore(&wc->lock, flags);
return IRQ_HANDLED;
}
spin_unlock_irqrestore(&wc->lock, flags);
if (status & 0x20){
/* PCI Target abort */
cardcrit(wc->boardnum, "PCI Target Abort.");
return IRQ_HANDLED;
}
if (status & 0x03){
openpci_write(wc, status);
}
if (status & 0x0c){
#ifdef DEBUG_LOOP_VOLTAGE
//{{{
static int counter[MAX_CARDS];
int card = wc->boardnum;
int port = ++counter[card] & 0x07;
int ignore = counter[card] & 0xf0;
if( ! ignore && (voltmeter & ((1 << (card * 8)) << port)) ) {
unsigned char lv;
if( wc->porttype[port] == VT_PORT_VDAA && read_reg_fxo(wc, port, 29, &lv) )
cardinfo(wc->boardnum, "Port %d loop voltage %d",
port, lv < 128 ? lv : lv - 256);
}
//}}}
#endif
openpci_read(wc, status);
}
return IRQ_HANDLED;
} //}}}
static int openpci_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long data)
{ //{{{
struct wctdm_stats stats;
struct wctdm_regs regs;
struct wctdm_regop regop;
struct wctdm_echo_coefs echoregs;
struct openpci *wc = chan->pvt;
int port = chan->chanpos - 1;
int x;
switch (cmd) {
case DAHDI_ONHOOKTRANSFER:
if (wc->porttype[port] != VT_PORT_PROSLIC)
return -EINVAL;
if (get_user(x, (int *)data))
return -EFAULT;
wc->mod[port].fxs.ohttimer = x << 3;
if (reversepolarity)
wc->mod[port].fxs.idletxhookstate = 0x6; /* OHT mode when idle */
else
wc->mod[port].fxs.idletxhookstate = 0x2;
switch(wc->mod[port].fxs.lasttxhook) {
case 0x1:
case 0x5:
if (reversepolarity)
wc->mod[port].fxs.lasttxhook = 0x6;
else
wc->mod[port].fxs.lasttxhook = 0x2;
if( ! write_reg_fxs(wc, port, 64, wc->mod[port].fxs.lasttxhook) )
return -EIO;
}
break;
case DAHDI_SETPOLARITY:
if (get_user(x, (int *)data))
return -EFAULT;
if (wc->porttype[port] != VT_PORT_PROSLIC)
return -EINVAL;
/* Can't change polarity while ringing or when open */
if ((wc->mod[port].fxs.lasttxhook == 0x04) ||
(wc->mod[port].fxs.lasttxhook == 0x00))
return -EINVAL;
if ((x && !reversepolarity) || (!x && reversepolarity))
wc->mod[port].fxs.lasttxhook |= 0x04;
else
wc->mod[port].fxs.lasttxhook &= ~0x04;
if( ! write_reg_fxs(wc, port, 64, wc->mod[port].fxs.lasttxhook) )
return -EIO;
break;
case WCTDM_GET_STATS:
if (wc->porttype[port] == VT_PORT_PROSLIC) {
unsigned char linevolt;
if( read_reg_fxs(wc, port, 80, &linevolt) )
stats.tipvolt = linevolt * -376;
else
return -EIO;
if( read_reg_fxs(wc, port, 81, &linevolt) )
stats.ringvolt = linevolt * -376;
else
return -EIO;
if( read_reg_fxs(wc, port, 82, &linevolt) )
stats.batvolt = linevolt * -376;
else
return -EIO;
} else if (wc->porttype[port] == VT_PORT_VDAA) {
unsigned char linevolt;
if( read_reg_fxo(wc, port, 29, &linevolt) )
stats.tipvolt = stats.ringvolt = stats.batvolt = linevolt * 1000;
else
return -EIO;
} else
return -EINVAL;
if (copy_to_user((struct wctdm_stats *)data, &stats, sizeof(stats)))
return -EFAULT;
break;
case WCTDM_GET_REGS:
if (wc->porttype[port] == VT_PORT_PROSLIC) {
for (x=0;x<NUM_INDIRECT_REGS;x++)
if( ! read_indreg_fxs(wc, port, x, ®s.indirect[x]) )
return -EIO;
for (x=0;x<NUM_REGS;x++)
if( ! read_reg_fxs(wc, port, x, ®s.direct[x]) )
return -EIO;
} else {
memset(®s, 0, sizeof(regs));
for (x=0;x<NUM_FXO_REGS;x++){
if( ! read_reg_fxo(wc, port, x, ®s.direct[x]) )
return -EIO;
}
}
if (copy_to_user((struct wctdm_regs *)data, ®s, sizeof(regs)))
return -EFAULT;
break;
case WCTDM_SET_REG:
if (copy_from_user(®op, (struct wctdm_regop *)data, sizeof(regop)))
return -EFAULT;
if (regop.indirect) {
if (wc->porttype[port] != VT_PORT_PROSLIC)
return -EINVAL;
printk("Setting indirect %d to 0x%04x on %d\n",
regop.reg, regop.val, chan->chanpos);
if( ! write_indreg_fxs(wc, port, regop.reg, regop.val) )
return -EIO;
} else {
regop.val &= 0xff;
printk("Setting direct %d to %04x on %d\n",
regop.reg, regop.val, chan->chanpos);
if (wc->porttype[port] == VT_PORT_PROSLIC) {
if( ! write_reg_fxs(wc, port, regop.reg, regop.val) )
return -EIO;
} else {
if( ! write_reg_fxo(wc, port, regop.reg, regop.val) )
return -EIO;
}
}
break;
case WCTDM_SET_ECHOTUNE:
cardinfo(wc->boardnum, "Setting echo registers");
if (copy_from_user(&echoregs, (struct wctdm_echo_coefs*)data, sizeof(echoregs)))
return -EFAULT;
if (wc->porttype[port] == VT_PORT_VDAA) {
/* Set the ACIM and digital echo canceller registers */
if( ! write_reg_fxo(wc, port, 30, echoregs.acim)
|| ! write_reg_fxo(wc, port, 45, echoregs.coef1)
|| ! write_reg_fxo(wc, port, 46, echoregs.coef2)
|| ! write_reg_fxo(wc, port, 47, echoregs.coef3)
|| ! write_reg_fxo(wc, port, 48, echoregs.coef4)
|| ! write_reg_fxo(wc, port, 49, echoregs.coef5)
|| ! write_reg_fxo(wc, port, 50, echoregs.coef6)
|| ! write_reg_fxo(wc, port, 51, echoregs.coef7)
|| ! write_reg_fxo(wc, port, 52, echoregs.coef8) )
{
cardcrit(wc->boardnum, "Failed to set echo registers");
return -EIO;
}
break;
} else {
return -EINVAL;
}
break;
default:
return -ENOTTY;
}
return 0;
} //}}}
static int openpci_open(struct dahdi_chan *chan)
{
struct openpci *wc = chan->pvt;
if( ! wc->porttype[chan->chanpos-1] )
return -ENODEV;
//XXX This is WRONG and can prang in a race. We must pass THIS_MODULE
// as the owner of the span that holds the pointer to this function,
// then bump the refcount in the dahdi code _BEFORE_ the potentially
// fatal call to an invalid pointer is made.
//if( wc->dead ) return -ENODEV;
//wc->usecount++;
try_module_get(THIS_MODULE); //XXX
return 0;
}
static inline struct openpci* openpci_from_span(struct dahdi_span *span) {
return container_of(span, struct openpci, span);
}
static int openpci_watchdog(struct dahdi_span *span, int event)
{
info("TDM: Restarting DMA");
restart_dma(openpci_from_span(span));
return 0;
}
static int openpci_close(struct dahdi_chan *chan)
{
struct openpci *wc = chan->pvt;
int port = chan->chanpos - 1;
//XXX wc->usecount--;
//XXX This is WRONG and can prang in a race. We must pass THIS_MODULE
// as the owner of the span that holds the pointer to this function,
// then bump the refcount in the dahdi code _BEFORE_ the potentially
// fatal call to an invalid pointer is made.
module_put(THIS_MODULE);
if (wc->porttype[port] == VT_PORT_PROSLIC) {
if (reversepolarity)
wc->mod[port].fxs.idletxhookstate = 5;
else
wc->mod[port].fxs.idletxhookstate = 1;
}
/* If we're dead, release us now */
//XXX if (!wc->usecount && wc->dead) openpci_release(wc);
return 0;
}
static int openpci_hooksig(struct dahdi_chan *chan, enum dahdi_txsig txsig)
{ //{{{
struct openpci *wc = chan->pvt;
int port = chan->chanpos - 1;
int new_hk_state;
dbginfo(wc->boardnum, "Setting %s port %d hook state %s",
wc->porttype[port] == VT_PORT_VDAA ? "FXO" : "FXS",
port,
txsig == 0 ? "ONHOOK" :
txsig == 1 ? "OFFHOOK" :
txsig == 2 ? "START" :
txsig == 3 ? "KEWL" : "UNKNOWN" );
switch(wc->porttype[port]) {
case VT_PORT_VDAA:
switch(txsig) {
case DAHDI_TXSIG_START:
case DAHDI_TXSIG_OFFHOOK:
if( write_reg_fxo(wc, port, 5, 0x9)
&& write_reg_fxo(wc, port, 0x20, 0x0) )
wc->mod[port].fxo.offhook = 1;
else
cardcrit(wc->boardnum, "Failed set fxo off-hook");
break;
case DAHDI_TXSIG_ONHOOK:
if( write_reg_fxo(wc, port, 5, 0x8)
&& write_reg_fxo(wc, port, 0x20, 0x3) )
wc->mod[port].fxo.offhook = 0;
else
cardcrit(wc->boardnum, "Failed set fxo on-hook");
break;
default:
cardcrit(wc->boardnum,
"Can't set FXO port %d tx state to %d",
port, txsig);
}
break;
case VT_PORT_PROSLIC:
new_hk_state = wc->mod[port].fxs.lasttxhook;
switch(txsig) {
case DAHDI_TXSIG_ONHOOK:
switch(chan->sig) {
case DAHDI_SIG_EM:
case DAHDI_SIG_FXOKS:
case DAHDI_SIG_FXOLS:
new_hk_state = wc->mod[port].fxs.idletxhookstate;
break;
case DAHDI_SIG_FXOGS:
new_hk_state = 3;
break;
}
break;
case DAHDI_TXSIG_OFFHOOK:
switch(chan->sig) {
case DAHDI_SIG_EM:
new_hk_state = 5;
break;
default:
new_hk_state = wc->mod[port].fxs.idletxhookstate;
break;
}
break;
case DAHDI_TXSIG_START:
new_hk_state = 4;
break;
case DAHDI_TXSIG_KEWL:
new_hk_state = 0;
break;
default:
cardinfo(wc->boardnum,
"Can't set FXS port %d tx state to %d",
port, txsig);
}
dbginfo(wc->boardnum, "%s port %d hook state old %d, new %d",
wc->porttype[port] == VT_PORT_VDAA ? "FXO" : "FXS",
port, wc->mod[port].fxs.lasttxhook, new_hk_state );
if (new_hk_state != wc->mod[port].fxs.lasttxhook){
if( write_reg_fxs(wc, port, 64, new_hk_state) )
wc->mod[port].fxs.lasttxhook = new_hk_state;
else
cardcrit(wc->boardnum,
"Failed to set port %d fxs hookstate from %d to %d",
port, wc->mod[port].fxs.lasttxhook, new_hk_state);
}
break;
default:
cardcrit(wc->boardnum,
"Unknown module type %d in openpci_hooksig",
wc->porttype[port] );
}
return 0;
} //}}}
static const struct dahdi_span_ops openpci_span_ops = {
.owner = THIS_MODULE,
.hooksig = openpci_hooksig,
.open = openpci_open,
.close = openpci_close,
.ioctl = openpci_ioctl,
.watchdog = openpci_watchdog
};
static int span_initialize(struct openpci *wc)
{ //{{{
int x;
wc->ddev = dahdi_create_device();
//XXX Set a THIS_MODULE as the owner of the span...
/* Zapata stuff */
sprintf(wc->span.name, "WCTDM/%d", wc->boardnum);
sprintf(wc->span.desc, "%s Board %d", wc->variety, wc->boardnum + 1);
wc->ddev->location = kasprintf(GFP_KERNEL, "PCI Bus %02d Slot %02d",
wc->dev->bus->number,
PCI_SLOT(wc->dev->devfn) + 1);
if (!wc->ddev->location)
return -ENOMEM;
for (x = 0; x < MAX_PORTS; x++) {
struct dahdi_chan *chan = &wc->_chans[x];
wc->chans[x] = chan;
sprintf(chan->name, "WCTDM/%d/%d", wc->boardnum, x);
chan->sigcap = DAHDI_SIG_FXOKS | DAHDI_SIG_FXOLS | DAHDI_SIG_FXOGS
| DAHDI_SIG_SF | DAHDI_SIG_EM | DAHDI_SIG_CLEAR;
chan->sigcap |= DAHDI_SIG_FXSKS | DAHDI_SIG_FXSLS | DAHDI_SIG_SF | DAHDI_SIG_CLEAR;
chan->chanpos = x+1;
chan->pvt = wc;
}
wc->ddev->manufacturer = "Voicetronix";
wc->ddev->devicetype = wc->variety;
wc->span.deflaw = DAHDI_LAW_MULAW;
wc->span.chans = wc->chans;
wc->span.channels = MAX_PORTS;
wc->span.flags = DAHDI_FLAG_RBS;
wc->span.ops = &openpci_span_ops;
list_add_tail(&wc->span.device_node, &wc->ddev->spans);
if (dahdi_register_device(wc->ddev, &wc->dev->dev)) {
cardcrit(wc->boardnum, "Unable to register device with dahdi");
return RET_FAIL;
}
return RET_OK;
} //}}}
static int get_port_type(struct openpci *wc, int port)
{ //{{{
int i, type;
unsigned long flags;
spin_lock_irqsave(&wc->lock, flags);
outb(0x20, PIB(1)); HTXF_WAIT_LOCKED_RET(VT_PORT_EMPTY);
outb(port, PIB(1)); HTXF_WAIT_LOCKED_RET(VT_PORT_EMPTY);
HRXF_WAIT_LOCKED_RET(VT_PORT_EMPTY); type = inb(PIB(1));
spin_unlock_irqrestore(&wc->lock, flags);
return type;
} //}}}
static int check_ports(struct openpci *wc)
{ //{{{
int i = 0;
wc->portcount = 0;
for(; i < MAX_PORTS; ++i ){
wc->porttype[i] = get_port_type(wc, i);
dbginfo(wc->boardnum,"%d: %s", i, porttype(wc,i));
switch( wc->porttype[i] ) {
case VT_PORT_PROSLIC:
/* By default, don't send on hook */
if (reversepolarity)
wc->mod[i].fxs.idletxhookstate = 5;
else
wc->mod[i].fxs.idletxhookstate = 1;
case VT_PORT_VDAA:
++wc->portcount;
}
}
// we 'succeed' if any ports were discovered.
return wc->portcount ? RET_OK : RET_FAIL;
} //}}}
static int configure_vdaa_country(struct openpci *wc, int port, char *name)
{ //{{{
unsigned char value;
int i;
for (i=0; i < sizeof(fxo_modes)/sizeof(struct fxo_mode); ++i){
if(!strcmp(fxo_modes[i].name, name)){
dbginfo(wc->boardnum, "%d: Setting country to %s", port, name);
goto part2;
}
}
i = 3;
cardinfo(wc->boardnum, "Using default country %s", fxo_modes[i].name);
part2:
value = (fxo_modes[i].ohs << 6);
value |= (fxo_modes[i].rz << 1);
value |= (fxo_modes[i].rt << 0);
if( ! write_reg_fxo(wc, port, 16, value) ) goto hell;
/* DC Termination Control - Register 26 */
value = (fxo_modes[i].dcv << 6);
value |= (fxo_modes[i].mini << 4);
value |= (fxo_modes[i].ilim << 1);
if( ! write_reg_fxo(wc, port, 26, value) ) goto hell;
/* AC Termination Control - Register 30 */
value = (fxo_modes[i].acim << 0);
if( ! write_reg_fxo(wc, port, 30, value) ) goto hell;
/* DAA Control 5 - Register 31 */
msleep(1);
if( ! read_reg_fxo(wc, port, 31, &value) ) goto hell;
value = (value & 0xf7) | (fxo_modes[i].ohs2 << 3);
value = value | 0x02;
if( ! write_reg_fxo(wc, port, 31, value) ) goto hell;
return RET_OK;
hell:
cardcrit(wc->boardnum, "port %d failed configure vdaa country", port);
return RET_FAIL;
} //}}}
// Do not call this from an interrupt context, it may sleep.
static void configure_vdaa_port(struct openpci *wc, int port)
{ //{{{
/* Set Country - default to Australia */
if( configure_vdaa_country(wc, port, country) )
++wc->portcount;
else {
cardcrit(wc->boardnum, "FAILED to configure vdaa port %d. Disabled.", port);
wc->porttype[port] = VT_PORT_EMPTY;
}
} //}}}
static int configure_proslic_country(struct openpci *wc, int port, const char *name)
{ //{{{
int i;
for(i=0; i < sizeof(ps_country_regs)/sizeof(struct ps_country_reg); ++i) {
if(!strcmp(ps_country_regs[i].country, name)){
dbginfo(wc->boardnum, "%d: Setting country to %s", port, name);
goto part2;
}
}
return -EINVAL;
part2:
if( ! write_reg_fxs(wc, port, 10, ps_country_regs[i].value) ){
cardcrit(wc->boardnum,"%d: failed to write PS_IMPEDANCE", port);
return -EIO;
}
return 0;
} //}}}
// Do not call this from an interrupt context, it may sleep.
static void configure_proslic_port(struct openpci *wc, int port)
{ //{{{
/* Set Country - default to Australia */
switch( configure_proslic_country(wc, port, country) ){
case 0:
break;
case -EINVAL:
cardwarn(wc->boardnum,"%d: Country '%s' unknown, using default", port, country);
if( configure_proslic_country(wc, port, DEFAULT_COUNTRY) == 0 )
goto hell;
default:
goto hell;
}
++wc->portcount;
return;
hell:
cardcrit(wc->boardnum, "FAILED to configure proslic port %d. Disabled.", port);
wc->porttype[port] = VT_PORT_EMPTY;
} //}}}
// Do not call this from an interrupt context, it may (indirectly) sleep.
static int configure_ports(struct openpci *wc)
{ //{{{
unsigned long flags;
int i;
wc->portcount = 0;
for(i=0; i < MAX_PORTS; ++i){
switch (wc->porttype[i]){
case VT_PORT_VDAA: configure_vdaa_port(wc,i); break;
case VT_PORT_PROSLIC: configure_proslic_port(wc,i); break;
}
}
spin_lock_irqsave(&wc->lock, flags);
outb(0x2c, PIB(1)); HTXF_WAIT_LOCKED();
outb(0xff, PIB(1)); HTXF_WAIT_LOCKED();
spin_unlock_irqrestore(&wc->lock, flags);
// otherwise we 'succeed' if any ports were configured successfully.
return wc->portcount ? RET_OK : RET_FAIL;
} //}}}
static int __get_arm_id(struct openpci *wc, int field, char *value)
{ //{{{
int i;
int x=0;
int count=0;
outb(0x01, PIB(1)); HTXF_WAIT();
outb(field, PIB(1)); HTXF_WAIT();
HRXF_WAIT(); count = inb(PIB(1));
if (count > ID_DATA_MAXSIZE){
cardcrit(wc->boardnum, "Too many bytes of id(%d) data %d/%d",
field, count, ID_DATA_MAXSIZE);
return RET_FAIL;
}
//cardinfo(wc->boardnum, "get_arm_id(%d): byte count %d",field,count);
for(; x < count; ++x){
HRXF_WAIT(); *value = inb(PIB(1));
//cardinfo(wc->boardnum, "get_arm_id(%d): byte %d => 0x%02x",field,x,tmp);
++value;
}
return RET_OK;
} //}}}
static void enable_interrupts(struct openpci *wc)
{ //{{{
outb(0x3f, TJ_MASK0);
outb(0x02, TJ_MASK1);
} //}}}
static void disable_interrupts(struct openpci *wc)
{ //{{{
outb(0x00, TJ_MASK0);
outb(0x00, TJ_MASK1);
} //}}}
// Do not call this from an interrupt context, it may sleep.
static int check_arm(struct openpci *wc)
{ //{{{
char model[ID_DATA_MAXSIZE+1] = { 0 };
char date[ID_DATA_MAXSIZE+1] = { 0 };
unsigned long flags;
int i=0;
int tmp=0;
spin_lock_irqsave(&wc->lock, flags);
while ((tmp != 0x88)&&(++i<100)){
outb(0x88, PIB(0));
msleep(1);
tmp = inb(PIB(1));
}
if (i>=1000) goto limbo;
dbginfo(wc->boardnum, "Arm responded on attempt %d",i);
// Flush out the queue if we sent several pings before a response.
if(i>1) __ping_arm(wc);
if( ! __get_arm_id(wc, 0, model) ) goto hell;
sscanf(model, "OpenPCI8.%02d", &(wc->firmware));
cardinfo(wc->boardnum, " model: %s", model);
if( ! __get_arm_id(wc, 1, date) ) goto hell;
cardinfo(wc->boardnum, " date: %s", date);
if( ! __get_arm_id(wc, 2, wc->serial) ) goto hell;
cardinfo(wc->boardnum, " serial: %s", wc->serial);
spin_unlock_irqrestore(&wc->lock, flags);
return RET_OK;
hell:
spin_unlock_irqrestore(&wc->lock, flags);
cardwarn(wc->boardnum, "Found ARM processor, dumb firmware.");
return RET_OK;
limbo:
spin_unlock_irqrestore(&wc->lock, flags);
return RET_FAIL;
} //}}}
static int arm_monitor(struct openpci *wc, int on)
{ //{{{
int i;
outb( on ? 0x06 : 0x07, PIB(1) ); HTXF_WAIT();
return RET_OK;
} //}}}
static int __devinit openpci_probe_board(struct pci_dev *pdev, const struct pci_device_id *ent)
{ //{{{
struct openpci *wc;
int boardnum = 0;
int failret = -ENOMEM;
int tmp = 0;
int i;
unsigned long flags;
if( ent->driver_data != (kernel_ulong_t)&wcopenpci )
{
info("Probe of non-OpenPCI card, ignoring.");
return -EINVAL;
}
wc = kzalloc(sizeof(struct openpci), GFP_KERNEL);
if (!wc){
return -ENOMEM;
}
mutex_lock(&cards_mutex);
for (; boardnum < MAX_CARDS && cards[boardnum]; ++boardnum);
if (boardnum >= MAX_CARDS){
crit("Too many OpenPCI cards(%d), max is %d.", boardnum, MAX_CARDS);
mutex_unlock(&cards_mutex);
goto hell;
}
cards[boardnum] = wc;
mutex_unlock(&cards_mutex);
spin_lock_init(&wc->lock);
pci_set_drvdata(pdev, wc);
wc->boardnum = boardnum;
wc->dev = pdev;
wc->variety = wcopenpci;
cardinfo(boardnum, "Initialising card");
if (pci_enable_device(pdev)) {
failret = -EIO;
goto hell_2;
}
wc->ioaddr = pci_resource_start(pdev, 0);
if( ! request_region(wc->ioaddr, 0xff, NAME) ){
cardcrit(boardnum, "Failed to lock IO region, another driver already using it");
failret = -EBUSY;
goto hell_2;
}
spin_lock_irqsave(&wc->lock, flags);
outb(0xff, TJ_AUXD); /* Set up TJ to access the ARM */
outb(0x78, TJ_AUXC); /* Set up for Jtag */
outb(0x00, TJ_CNTL); /* pull ERST low */
spin_unlock_irqrestore(&wc->lock, flags);
msleep(1); /* Wait a bit */
dbginfo(boardnum,"Starting ARM");
spin_lock_irqsave(&wc->lock, flags);
outb(0x01, TJ_CNTL); /* pull ERST high again */
spin_unlock_irqrestore(&wc->lock, flags);
msleep(100); /* Give it all a chance to boot */
if( ! check_arm(wc) ){
cardcrit(boardnum, "Couldnt find ARM processor");
failret = -EIO;
goto hell_3;
}
if( wc->firmware < 11 ){
cardcrit(boardnum,
"Firmware version %d not supported by this driver",
wc->firmware);
cardcrit(boardnum, " contact Voicetronix to have it updated");
failret = -ENODEV;
goto hell_3;
}
if( ! check_ports(wc) ){
cardcrit(boardnum, "Couldnt find ports!");
failret = -EIO;
goto hell_3;
}
wc->writechunk = pci_alloc_consistent(pdev, VT_PCIDMA_BLOCKSIZE, &wc->writedma);
if (!wc->writechunk) {
cardcrit(boardnum, "Couldnt get DMA memory.");
goto hell_3;
}
wc->readchunk = wc->writechunk + DAHDI_MAX_CHUNKSIZE * (MAX_PORTS*2 / sizeof(int));
wc->readdma = wc->writedma + DAHDI_MAX_CHUNKSIZE * (MAX_PORTS*2);
memset((void*)wc->writechunk,0,VT_PCIDMA_BLOCKSIZE);
spin_lock_irqsave(&wc->lock, flags);
outb(0xc1, TJ_SERCTL);
outb(0x0, TJ_FSCDELAY);
outl(wc->writedma, TJ_DMAWS);
outl(wc->writedma + VT_PCIDMA_MIDDLE, TJ_DMAWI);
outl(wc->writedma + VT_PCIDMA_END, TJ_DMAWE);
outl(wc->readdma, TJ_DMARS);
outl(wc->readdma + VT_PCIDMA_MIDDLE, TJ_DMARI);
outl(wc->readdma + VT_PCIDMA_END, TJ_DMARE);
/* Clear interrupts */
outb(0xff, TJ_INTSTAT);
spin_unlock_irqrestore(&wc->lock, flags);
if( ! arm_monitor(wc, 1) ){
cardcrit(boardnum, "failed to start arm monitoring");
failret = -EIO;
goto hell_4;
}
msleep(1000);
i = 0;
while(tmp != 0x88 && ++i < 1000) {
outb(0x88, PIB(0));
msleep(250);
tmp = inb(PIB(1));
}
if(i>=1000) {
cardcrit(boardnum, "FAILED to initialise board");
goto hell_4;
}
if( ! check_ports(wc) ) {
cardcrit(boardnum, "FAILED to initialise ports");
failret = -EIO;
goto hell_4;
}
if( ! configure_ports(wc) ){
cardcrit(boardnum, "Failed to configure ports.");
failret = -EIO;
goto hell_4;
}
cardinfo(wc->boardnum, "have %d configured ports", wc->portcount);
if( ! span_initialize(wc) ) {
cardcrit(boardnum, "Failed to register with dahdi driver");
failret = -EFAULT;
goto hell_4;
}
/* Finalize signalling */
for (i=0; i < MAX_PORTS; ++i) {
if (wc->porttype[i] == VT_PORT_VDAA)
wc->chans[i]->sigcap = DAHDI_SIG_FXSKS | DAHDI_SIG_FXSLS
| DAHDI_SIG_CLEAR | DAHDI_SIG_SF;
else if (wc->porttype[i] == VT_PORT_PROSLIC)
wc->chans[i]->sigcap = DAHDI_SIG_FXOKS | DAHDI_SIG_FXOLS
| DAHDI_SIG_FXOGS | DAHDI_SIG_SF
| DAHDI_SIG_CLEAR | DAHDI_SIG_EM;
else if (wc->porttype[i])
cardcrit(wc->boardnum, "Port %d has unknown type (%d)",
i, wc->porttype[i]);
}
/* Enable bus mastering */
pci_set_master(pdev);
if (request_irq(pdev->irq, openpci_isr, DAHDI_IRQ_SHARED, NAME, wc)) {
cardcrit(boardnum, "Cant get IRQ!");
failret = -EIO;
goto hell_5;
}
cardinfo(boardnum, "Got IRQ %d", pdev->irq);
enable_interrupts(wc);
start_dma(wc);
cardinfo(boardnum,"Initialised card.");
return 0;
hell_5:
dahdi_unregister_device(wc->ddev);
hell_4:
if (wc->writechunk){
pci_free_consistent(pdev, VT_PCIDMA_BLOCKSIZE,
(void*)wc->writechunk, wc->writedma);
}
hell_3:
outb(0x00, TJ_CNTL);
release_region(wc->ioaddr, 0xff);
hell_2:
cards[boardnum] = NULL;
hell:
kfree(wc->ddev->location);
dahdi_free_device(wc->ddev);
kfree(wc);
return failret;
} //}}}
static void __devexit openpci_remove_board(struct pci_dev *pdev)
{ //{{{
struct openpci *wc = pci_get_drvdata(pdev);
if(!wc) return;
arm_monitor(wc,0);
/* Stop DMA */
outb(0x00, TJ_OPER);
disable_interrupts(wc);
//XXX Replace this usecount business...
// and do this BEFORE we invalidate everything above...
// check that we wont try to write to it in the meantime.
/* Release span, possibly delayed */
//XXX if (!wc->usecount) openpci_release(wc); else wc->dead = 1;
dahdi_unregister_device(wc->ddev);
outb(0x00, TJ_CNTL);
pci_free_consistent(pdev, VT_PCIDMA_BLOCKSIZE, (void *)wc->writechunk, wc->writedma);
free_irq(pdev->irq, wc);
release_region(wc->ioaddr, 0xff);
mutex_lock(&cards_mutex);
cards[wc->boardnum] = NULL;
mutex_unlock(&cards_mutex);
kfree(wc->ddev->location);
dahdi_free_device(wc->ddev);
kfree(wc);
cardinfo(wc->boardnum, "Removed OpenPCI card.");
} //}}}
static struct pci_device_id openpci_pci_tbl[] = {
{ 0xe159, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (kernel_ulong_t) &wcopenpci },
{ 0 }
};
MODULE_DEVICE_TABLE(pci, openpci_pci_tbl);
static struct pci_driver openpci_driver = {
name: NAME,
probe: openpci_probe_board,
remove: __devexit_p(openpci_remove_board),
suspend: NULL,
resume: NULL,
id_table: openpci_pci_tbl,
};
static int __init openpci_init(void)
{
#ifdef __BIG_ENDIAN
warn("No big endian support (yet)");
return -ENODEV;
#endif
if( dahdi_pci_module(&openpci_driver) )
return -ENODEV;
info("Module loaded %s", debug ? "with debug enabled" : "");
return 0;
}
static void __exit openpci_cleanup(void)
{
pci_unregister_driver(&openpci_driver);
info("Module exit");
}
module_init(openpci_init);
module_exit(openpci_cleanup);
MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_VERSION(DAHDI_VERSION);
MODULE_LICENSE("GPL");
|