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 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446
|
#!/usr/bin/perl
#
# sensors-detect - Detect PCI bus and chips
# Copyright (C) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>
# Copyright (C) 2000 - 2004 The lm_sensors team
# Copyright (C) 2005 - 2006 Jean Delvare <khali@linux-fr.org>
#
# 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.
#
# TODO: Better handling of chips with several addresses
# A Perl wizard really ought to look upon this; the PCI and I2C stuff should
# each be put in a separate file, using modules and packages. That is beyond
# me.
require 5.004;
use strict;
use Fcntl;
use POSIX;
use File::Basename;
# Just in case a root user doesn't have /sbin in his/her path for some reason
# (was seen once)
$ENV{PATH} = '/sbin:'.$ENV{PATH}
unless $ENV{PATH} =~ m,(^|:)/sbin/?(:|$),;
# Same for /usr/local/sbin since we need i2cdetect which is installed there
# by default (reported by Lennard Klein)
$ENV{PATH} = '/usr/local/sbin:'.$ENV{PATH}
unless $ENV{PATH} =~ m,(^|:)/usr/local/sbin/?(:|$),;
#########################
# CONSTANT DECLARATIONS #
#########################
use vars qw(@pci_adapters @chip_ids @superio_ids $revision);
$revision = '$Revision: 4171 $ ($Date: 2006-09-24 03:37:01 -0700 (Sun, 24 Sep 2006) $)';
$revision =~ s/\$\w+: (.*?) \$/$1/g;
$revision =~ s/ \([^()]*\)//;
# This is the list of SMBus or I2C adapters we recognize by their PCI
# signature. This is an easy and fast way to determine which SMBus or I2C
# adapters should be present.
# Each entry must have a vendid (Vendor ID), devid (Device ID) and
# procid (string as appears in /proc/pci; see linux/driver/pci,
# either pci.c or oldproc.c). If no driver is written yet, set the
# driver (Driver Name) field to "to-be-written".
# The match (Match Description) field should contain a regular expression
# matching the adapter name as it would appear in /proc/bus/i2c or /sys.
@pci_adapters = (
{
vendid => 0x8086,
devid => 0x7113,
procid => "Intel 82371AB PIIX4 ACPI",
driver => "i2c-piix4",
match => qr/^SMBus PIIX4 adapter at /,
} ,
{
vendid => 0x8086,
devid => 0x719b,
procid => "Intel 82443MX Mobile",
driver => "i2c-piix4",
match => qr/^SMBus PIIX4 adapter at /,
} ,
{
vendid => 0x8086,
devid => 0x2413,
procid => "Intel 82801AA ICH",
driver => "i2c-i801",
match => qr/^SMBus I801 adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x8086,
devid => 0x2423,
procid => "Intel 82801AB ICH0",
driver => "i2c-i801",
match => qr/^SMBus I801 adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x8086,
devid => 0x2443,
procid => "Intel 82801BA ICH2",
driver => "i2c-i801",
match => qr/^SMBus I801 adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x8086,
devid => 0x2483,
procid => "Intel 82801CA/CAM ICH3",
driver => "i2c-i801",
match => qr/^SMBus I801 adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x8086,
devid => 0x24C3,
procid => "Intel 82801DB ICH4",
driver => "i2c-i801",
match => qr/^SMBus I801 adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x8086,
devid => 0x24D3,
procid => "Intel 82801EB ICH5",
driver => "i2c-i801",
match => qr/^SMBus I801 adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x8086,
devid => 0x25A4,
procid => "Intel 6300ESB",
driver => "i2c-i801",
match => qr/^SMBus I801 adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x8086,
devid => 0x269B,
procid => "Intel Enterprise Southbridge - ESB2",
driver => "i2c-i801",
match => qr/^SMBus I801 adapter at [0-9a-f]{4}/,
},
{
vendid => 0x8086,
devid => 0x266A,
procid => "Intel 82801FB ICH6",
driver => "i2c-i801",
match => qr/^SMBus I801 adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x8086,
devid => 0x27DA,
procid => "Intel ICH7",
driver => "i2c-i801",
match => qr/^SMBus I801 adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x8086,
devid => 0x283E,
procid => "Intel ICH8",
driver => "i2c-i801",
match => qr/^SMBus I801 adapter at [0-9a-f]{4}/,
},
{
vendid => 0x1106,
devid => 0x3040,
procid => "VIA Technologies VT82C586B Apollo ACPI",
driver => "i2c-via",
match => qr/^VIA i2c/,
} ,
{
vendid => 0x1106,
devid => 0x3050,
procid => "VIA Technologies VT82C596 Apollo ACPI",
driver => "i2c-viapro",
match => qr/^SMBus V(IA|ia) Pro adapter at/,
} ,
{
vendid => 0x1106,
devid => 0x3051,
procid => "VIA Technologies VT82C596B ACPI",
driver => "i2c-viapro",
match => qr/^SMBus V(IA|ia) Pro adapter at/,
} ,
{
vendid => 0x1106,
devid => 0x3057,
procid => "VIA Technologies VT82C686 Apollo ACPI",
driver => "i2c-viapro",
match => qr/^SMBus V(IA|ia) Pro adapter at/,
} ,
{
vendid => 0x1106,
devid => 0x3074,
procid => "VIA Technologies VT8233 VLink South Bridge",
driver => "i2c-viapro",
match => qr/^SMBus V(IA|ia) Pro adapter at/,
} ,
{
vendid => 0x1106,
devid => 0x3147,
procid => "VIA Technologies VT8233A South Bridge",
driver => "i2c-viapro",
match => qr/^SMBus V(IA|ia) Pro adapter at/,
} ,
{
vendid => 0x1106,
devid => 0x3177,
procid => "VIA Technologies VT8233A/8235 South Bridge",
driver => "i2c-viapro",
match => qr/^SMBus V(IA|ia) Pro adapter at/,
} ,
{
vendid => 0x1106,
devid => 0x3227,
procid => "VIA Technologies VT8237 South Bridge",
driver => "i2c-viapro",
match => qr/^SMBus V(IA|ia) Pro adapter at/,
} ,
{
vendid => 0x1106,
devid => 0x3337,
procid => "VIA Technologies VT8237A South Bridge",
driver => "i2c-viapro",
match => qr/^SMBus V(IA|ia) Pro adapter at/,
} ,
{
vendid => 0x1106,
devid => 0x8235,
procid => "VIA Technologies VT8231 South Bridge",
driver => "i2c-viapro",
match => qr/^SMBus V(IA|ia) Pro adapter at/,
} ,
{
vendid => 0x1106,
devid => 0x3287,
procid => "VIA Technologies VT8251 South Bridge",
driver => "i2c-viapro",
match => qr/^SMBus V(IA|ia) Pro adapter at/,
} ,
{
vendid => 0x1039,
devid => 0x5597,
procid => "Silicon Integrated Systems SIS5581/5582/5597/5598 (To be written - Do not use 5595 drivers)",
driver => "to-be-written",
} ,
{
vendid => 0x1039,
devid => 0x5598,
procid => "Silicon Integrated Systems SIS5598 (To be written - Do not use 5595 drivers)",
driver => "to-be-written",
} ,
{
vendid => 0x1039,
devid => 0x0540,
procid => "Silicon Integrated Systems SIS540 (To be written - Do not use 5595 drivers)",
driver => "to-be-written",
} ,
{
vendid => 0x1039,
devid => 0x0630,
procid => "Silicon Integrated Systems SIS630",
driver => "i2c-sis630",
match => qr/^SMBus SIS630 adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x1039,
devid => 0x0730,
procid => "Silicon Integrated Systems SIS730",
driver => "i2c-sis630",
match => qr/^SMBus SIS630 adapter at [0-9a-f]{4}/,
} ,
#
# Both Ali chips below have same PCI ID. Can't be helped. Only one should load.
#
{
vendid => 0x10b9,
devid => 0x7101,
procid => "Acer Labs 1533/1543",
driver => "i2c-ali15x3",
match => qr/^SMBus ALI15X3 adapter at/,
},
{
vendid => 0x10b9,
devid => 0x7101,
procid => "Acer Labs 1535",
driver => "i2c-ali1535",
match => qr/^SMBus ALI1535 adapter at/,
},
{
vendid => 0x10b9,
devid => 0x1563,
procid => "Acer Labs 1563",
driver => "i2c-ali1563",
match => qr/^SMBus ALi 1563 Adapter @/,
},
{
vendid => 0x106b,
devid => 0x000e,
procid => "Apple Computer Inc. Hydra Mac I/O",
driver => "i2c-hydra",
match => qr/^Hydra i2c/,
},
{
vendid => 0x1022,
devid => 0x740b,
procid => "AMD-756 Athlon ACPI",
driver => "i2c-amd756",
match => qr/^SMBus AMD756 adapter at [0-9a-f]{4}/,
},
{
vendid => 0x1022,
devid => 0x7413,
procid => "AMD-766 Athlon ACPI",
driver => "i2c-amd756",
match => qr/^SMBus AMD766 adapter at [0-9a-f]{4}/,
},
{
vendid => 0x1022,
devid => 0x7443,
procid => "AMD-768 System Management",
driver => "i2c-amd756",
match => qr/^SMBus AMD768 adapter at [0-9a-f]{4}/,
},
{
vendid => 0x1022,
devid => 0x746b,
procid => "AMD-8111 ACPI",
driver => "i2c-amd756",
match => qr/^SMBus AMD8111 adapter at [0-9a-f]{4}/,
},
{
vendid => 0x1022,
devid => 0x746a,
procid => "AMD-8111 SMBus 2.0",
driver => "i2c-amd8111",
match => qr/^SMBus2 AMD8111 adapter at [0-9a-f]{4}/,
},
{
vendid => 0x102b,
devid => 0x0519,
procid => "MGA 2064W [Millennium]",
driver => "i2c-matroxfb",
match => qr/^DDC:fb[0-9]{1,2}/,
},
{
vendid => 0x102b,
devid => 0x051a,
procid => "MGA 1064SG [Mystique]",
driver => "i2c-matroxfb",
match => qr/^DDC:fb[0-9]{1,2}/,
},
{
vendid => 0x102b,
devid => 0x051b,
procid => "MGA 2164W [Millennium II]",
driver => "i2c-matroxfb",
match => qr/^DDC:fb[0-9]{1,2}/,
},
{
vendid => 0x102b,
devid => 0x051e,
procid => "MGA 1064SG [Mystique] AGP",
driver => "i2c-matroxfb",
match => qr/^DDC:fb[0-9]{1,2}/,
},
{
vendid => 0x102b,
devid => 0x051f,
procid => "MGA 2164W [Millennium II] AGP",
driver => "i2c-matroxfb",
match => qr/^DDC:fb[0-9]{1,2}/,
},
{
vendid => 0x102b,
devid => 0x1000,
procid => "MGA G100 [Productiva]",
driver => "i2c-matroxfb",
match => qr/^DDC:fb[0-9]{1,2}/,
},
{
vendid => 0x102b,
devid => 0x1001,
procid => "MGA G100 [Productiva] AGP",
driver => "i2c-matroxfb",
match => qr/^DDC:fb[0-9]{1,2}/,
},
{
vendid => 0x102b,
devid => 0x0520,
procid => "MGA G200",
driver => "i2c-matroxfb",
match => qr/^DDC:fb[0-9]{1,2}/,
},
{
vendid => 0x102b,
devid => 0x0521,
procid => "MGA G200 AGP",
driver => "i2c-matroxfb",
match => qr/^DDC:fb[0-9]{1,2}/,
},
{
vendid => 0x102b,
devid => 0x0525,
procid => "MGA G400 AGP",
driver => "i2c-matroxfb",
match => qr/^(DDC,MAVEN):fb[0-9]{1,2}/,
},
{
vendid => 0x121a,
devid => 0x0005,
procid => "3Dfx Voodoo3",
driver => "i2c-voodoo3",
match => qr/^(I2C|DDC) Voodoo3\/Banshee adapter/,
},
{
vendid => 0x121a,
devid => 0x0003,
procid => "3Dfx Voodoo Banshee",
driver => "i2c-voodoo3",
match => qr/^(I2C|DDC) Voodoo3\/Banshee adapter/,
},
{
vendid => 0x8086,
devid => 0x7121,
procid => "Intel 82810 GMCH",
driver => "i2c-i810",
match => qr/^I810/,
} ,
{
vendid => 0x8086,
devid => 0x7123,
procid => "Intel 82810-DC100 GMCH",
driver => "i2c-i810",
match => qr/^I810/ ,
} ,
{
vendid => 0x8086,
devid => 0x7125,
procid => "Intel 82810E GMCH",
driver => "i2c-i810",
match => qr/^I810/,
} ,
{
vendid => 0x8086,
devid => 0x1132,
procid => "Intel 82815 GMCH",
driver => "i2c-i810",
match => qr/^I810/,
} ,
{
vendid => 0x8086,
devid => 0x2562,
procid => "Intel 82845G GMCH",
driver => "i2c-i810",
match => qr/^I810/,
},
{
vendid => 0x10de,
devid => 0x01b4,
procid => "nVidia nForce SMBus",
driver => "i2c-amd756",
match => qr/^SMBus nVidia nForce adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x10de,
devid => 0x0064,
procid => "nVidia Corporation nForce2 SMBus (MCP)",
driver => "i2c-nforce2",
match => qr/^SMBus nForce2 adapter at /,
},
{
vendid => 0x10de,
devid => 0x0084,
procid => "nVidia Corporation nForce2 Ultra 400 SMBus (MCP)",
driver => "i2c-nforce2",
match => qr/^SMBus nForce2 adapter at /,
},
{
vendid => 0x10de,
devid => 0x00D4,
procid => "nVidia Corporation nForce3 Pro150 SMBus (MCP)",
driver => "i2c-nforce2",
match => qr/^SMBus nForce2 adapter at /,
},
{
vendid => 0x10de,
devid => 0x00E4,
procid => "nVidia Corporation nForce3 250Gb SMBus (MCP)",
driver => "i2c-nforce2",
match => qr/^SMBus nForce2 adapter at /,
},
{
vendid => 0x10de,
devid => 0x0052,
procid => "nVidia Corporation nForce4 SMBus (MCP)",
driver => "i2c-nforce2",
match => qr/^SMBus nForce2 adapter at /,
},
{
vendid => 0x10de,
devid => 0x0034,
procid => "nVidia Corporation nForce4 SMBus (MCP-04)",
driver => "i2c-nforce2",
match => qr/^SMBus nForce2 adapter at /,
},
{
vendid => 0x10de,
devid => 0x0264,
procid => "nVidia Corporation nForce4 SMBus (MCP51)",
driver => "i2c-nforce2",
match => qr/^SMBus nForce2 adapter at /,
},
{
vendid => 0x10de,
devid => 0x0368,
procid => "nVidia Corporation nForce4 SMBus (MCP55)",
driver => "i2c-nforce2",
match => qr/^SMBus nForce2 adapter at /,
},
{
vendid => 0x1166,
devid => 0x0200,
procid => "ServerWorks OSB4 South Bridge",
driver => "i2c-piix4",
match => qr/^SMBus PIIX4 adapter at /,
} ,
{
vendid => 0x1055,
devid => 0x9463,
procid => "SMSC Victory66 South Bridge",
driver => "i2c-piix4",
match => qr/^SMBus PIIX4 adapter at /,
} ,
{
vendid => 0x1166,
devid => 0x0201,
procid => "ServerWorks CSB5 South Bridge",
driver => "i2c-piix4",
match => qr/^SMBus PIIX4 adapter at /,
} ,
{
vendid => 0x1166,
devid => 0x0203,
procid => "ServerWorks CSB6 South Bridge",
driver => "i2c-piix4",
match => qr/^SMBus PIIX4 adapter at /,
} ,
{
vendid => 0x1166,
devid => 0x0205,
procid => "ServerWorks HT-1000 South Bridge",
driver => "i2c-piix4",
match => qr/^SMBus PIIX4 adapter at /,
},
{
vendid => 0x1283,
devid => 0x8172,
procid => "ITE 8172G MIPS/SH4 Support Chip",
driver => "i2c-adap-ite",
match => qr/^ITE IIC adapter/,
} ,
{
vendid => 0x5333,
devid => 0x8A20,
procid => "S3 Savage 3D",
driver => "to-be-written",
} ,
{
vendid => 0x5333,
devid => 0x8A21,
procid => "S3 Savage 3D MV",
driver => "to-be-written",
} ,
{
vendid => 0x5333,
devid => 0x8A22,
procid => "S3 Savage 4",
driver => "i2c-savage4",
match => qr/^I2C Savage4 adapter/,
} ,
{
vendid => 0x5333,
devid => 0x9102,
procid => "S3 Savage 2000",
driver => "i2c-savage4",
match => qr/^I2C Savage4 adapter/,
} ,
{
vendid => 0x5333,
devid => 0x8A25,
procid => "S3 ProSavage PM",
driver => "to-be-written",
} ,
{
vendid => 0x5333,
devid => 0x8A26,
procid => "S3 ProSavage KM",
driver => "to-be-written",
} ,
{
vendid => 0x5333,
devid => 0x8C10,
procid => "S3 Savage MX MV",
driver => "to-be-written",
} ,
{
vendid => 0x5333,
devid => 0x8C11,
procid => "S3 Savage MX",
driver => "to-be-written",
} ,
{
vendid => 0x5333,
devid => 0x8C12,
procid => "S3 Savage IX MV",
driver => "to-be-written",
} ,
{
vendid => 0x5333,
devid => 0x8C13,
procid => "S3 Savage IX",
driver => "to-be-written",
} ,
{
vendid => 0x1002,
devid => 0x4353,
procid => "ATI Technologies Inc ATI SMBus",
driver => "i2c-piix4",
match => qr/^SMBus PIIX4 adapter at /,
} ,
{
vendid => 0x1002,
devid => 0x4363,
procid => "ATI Technologies Inc ATI SMBus",
driver => "i2c-piix4",
match => qr/^SMBus PIIX4 adapter at /,
} ,
{
vendid => 0x1002,
devid => 0x4372,
procid => "ATI Technologies Inc ATI SMBus",
driver => "i2c-piix4",
match => qr/^SMBus PIIX4 adapter at /,
} ,
{
vendid => 0x100B,
devid => 0x0500,
procid => "SCx200 Bridge",
driver => "scx200_acb",
match => qr/^(NatSemi SCx200 ACCESS\.bus|SCx200 ACB\d+) /,
},
{
vendid => 0x100B,
devid => 0x0510,
procid => "SC1100 Bridge",
driver => "scx200_acb",
match => qr/^(NatSemi SCx200 ACCESS\.bus|SCx200 ACB\d+) /,
},
{
vendid => 0x100B,
devid => 0x002B,
procid => "CS5535 ISA bridge",
driver => "scx200_acb",
match => qr/^CS5535 ACB\d+ /,
},
{
vendid => 0x1022,
devid => 0x2090,
procid => "CS5536 [Geode companion] ISA",
driver => "scx200_acb",
match => qr/^CS553[56] ACB\d+ /,
},
);
# The following entries used to appear directly in @pci_adapters.
# Because of the tendency of SiS chipsets to have their real PCI
# IDs obscured, we have to qualify these with a custom detection
# routine before we add them to the @pci_adapters list.
#
use vars qw(@pci_adapters_sis5595 @pci_adapters_sis645 @pci_adapters_sis96x);
@pci_adapters_sis5595 = (
{
vendid => 0x1039,
devid => 0x0008,
procid => "Silicon Integrated Systems SIS5595",
driver => "i2c-sis5595",
match => qr/^SMBus SIS5595 adapter at [0-9a-f]{4}/,
} ,
);
@pci_adapters_sis645 = (
{
vendid => 0x1039,
devid => 0x0008,
procid => "Silicon Integrated Systems SIS5595",
driver => "i2c-sis645",
match => qr/^SiS645 SMBus adapter at [0-9a-f]{4}/,
} ,
{
vendid => 0x1039,
devid => 0x0016,
procid => "Silicon Integrated Systems SMBus Controller",
driver => "i2c-sis645",
match => qr/^SiS645 SMBus adapter at 0x[0-9a-f]{4}/,
} ,
{
vendid => 0x1039,
devid => 0x0018,
procid => "Silicon Integrated Systems 85C503/5513 (LPC Bridge)",
driver => "i2c-sis645",
match => qr/^SiS645 SMBus adapter at 0x[0-9a-f]{4}/,
} ,
);
@pci_adapters_sis96x = (
{
vendid => 0x1039,
devid => 0x0016,
procid => "Silicon Integrated Systems SMBus Controller",
driver => "i2c-sis96x",
match => qr/^SiS96x SMBus adapter at 0x[0-9a-f]{4}/,
} ,
);
# This is a list of all recognized chips.
# Each entry must have the following fields:
# name: The full chip name
# driver: The driver name (without .o extension). Put in exactly
# "to-be-written" if it is not yet available. Put in exactly
# "not-a-sensor" if it is not a hardware monitoring chip and
# there is no known driver for it.
# Put in exactly "use-isa-instead" if no i2c driver will be written.
# i2c_addrs (optional): For I2C chips, the range of valid I2C addresses to
# probe. Recommend avoiding 0x69 because of clock chips.
# i2c_detect (optional): For I2C chips, the function to call to detect
# this chip. The function should take two parameters: an open file
# descriptor to access the bus, and the I2C address to probe.
# isa_addrs (optional): For ISA chips, the range of valid port addresses to
# probe.
# isa_detect (optional): For ISA chips, the function to call to detect
# this chip. The function should take one parameter: the ISA address
# to probe.
# alias_detect (optional): For chips which can be both on the ISA and the
# I2C bus, a function which detectes whether two entries are the same.
# The function should take three parameters: The ISA address, the
# I2C bus number, and the I2C address.
@chip_ids = (
{
name => "Myson MTP008",
driver => "mtp008",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { mtp008_detect(@_); },
} ,
{
name => "National Semiconductor LM78",
driver => "lm78",
i2c_addrs => [0x20..0x2f],
i2c_detect => sub { lm78_detect(0, @_); },
isa_addrs => [0x290],
isa_detect => sub { lm78_isa_detect(0, @_); },
alias_detect => sub { lm78_alias_detect(0, @_); },
} ,
{
name => "National Semiconductor LM78-J",
driver => "lm78",
i2c_addrs => [0x20..0x2f],
i2c_detect => sub { lm78_detect(1, @_); },
isa_addrs => [0x290],
isa_detect => sub { lm78_isa_detect(1, @_); },
alias_detect => sub { lm78_alias_detect(1, @_); },
} ,
{
name => "National Semiconductor LM79",
driver => "lm78",
i2c_addrs => [0x20..0x2f],
i2c_detect => sub { lm78_detect(2, @_); },
isa_addrs => [0x290],
isa_detect => sub { lm78_isa_detect(2, @_); },
alias_detect => sub { lm78_alias_detect(2, @_); },
} ,
{
name => "National Semiconductor LM75",
driver => "lm75",
i2c_addrs => [0x48..0x4f],
i2c_detect => sub { lm75_detect(@_); },
} ,
{
name => "National Semiconductor LM77",
driver => "lm77",
i2c_addrs => [0x48..0x4b],
i2c_detect => sub { lm77_detect(@_); },
},
{
name => "National Semiconductor LM80",
driver => "lm80",
i2c_addrs => [0x28..0x2f],
i2c_detect => sub { lm80_detect(@_); },
},
{
name => "National Semiconductor LM85 or LM96000",
driver => "lm85",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { lm85_detect(0x01, @_); },
},
{
name => "Analog Devices ADM1027, ADT7460 or ADT7463",
driver => "lm85",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { lm85_detect(0x41, @_); },
},
{
name => "SMSC EMC6D100, EMC6D101 or EMC6D102",
driver => "lm85",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { lm85_detect(0x5c, @_); },
},
{
name => "Analog Devices ADT7462",
driver => "to-be-written",
# The datasheet says addresses 0x5C and 0x58, but I guess these are
# left-aligned values
i2c_addrs => [0x2c, 0x2e],
i2c_detect => sub { adt7467_detect(2, @_); },
},
{
name => "Analog Devices ADT7466",
driver => "to-be-written",
i2c_addrs => [0x4c],
i2c_detect => sub { adt7467_detect(3, @_); },
},
{
name => "Analog Devices ADT7467 or ADT7468",
driver => "to-be-written",
i2c_addrs => [0x2e],
i2c_detect => sub { adt7467_detect(0, @_); },
},
{
name => "Analog Devices ADT7470",
driver => "to-be-written",
i2c_addrs => [0x2c, 0x2e, 0x2f],
i2c_detect => sub { adt7467_detect(4, @_); },
},
{
name => "Analog Devices ADT7473",
driver => "to-be-written",
i2c_addrs => [0x2e],
i2c_detect => sub { adt7473_detect(0, @_); },
},
{
name => "Analog Devices ADT7475",
driver => "to-be-written",
i2c_addrs => [0x2e],
i2c_detect => sub { adt7473_detect(1, @_); },
},
{
name => "Analog Devices ADT7476",
driver => "to-be-written",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { adt7467_detect(1, @_); },
},
{
name => "National Semiconductor LM87",
driver => "lm87",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { lm87_detect(@_); },
},
{
name => "National Semiconductor LM93",
driver => "lm93",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { lm93_detect(@_); },
},
{
name => "Winbond W83781D",
driver => "w83781d",
i2c_detect => sub { w83781d_detect(0, @_); },
i2c_addrs => [0x20..0x2f],
isa_addrs => [0x290],
isa_detect => sub { w83781d_isa_detect(0, @_); },
alias_detect => sub { w83781d_alias_detect(0, @_); },
} ,
{
name => "Winbond W83782D",
driver => "w83781d",
i2c_addrs => [0x20..0x2f],
i2c_detect => sub { w83781d_detect(1, @_); },
isa_addrs => [0x290],
isa_detect => sub { w83781d_isa_detect(1, @_); },
alias_detect => sub { w83781d_alias_detect(1, @_); },
} ,
{
name => "Winbond W83783S",
driver => "w83781d",
i2c_addrs => [0x2d],
i2c_detect => sub { w83781d_detect(2, @_); },
} ,
{
name => "Winbond W83792D",
driver => "w83792d",
i2c_addrs => [0x2c..0x2f],
i2c_detect => sub { w83781d_detect(8, @_); },
},
{
name => "Winbond W83793R/G",
driver => "w83793",
i2c_addrs => [0x2c..0x2f],
i2c_detect => sub { w83793_detect(0, @_); },
},
{
name => "Winbond W83791SD",
driver => "not-a-sensor",
i2c_addrs => [0x2c..0x2f],
i2c_detect => sub { w83791sd_detect(@_); },
},
{
name => "Winbond W83627HF",
driver => "w83781d",
i2c_addrs => [0x20..0x2f],
i2c_detect => sub { w83781d_detect(3, @_); },
isa_addrs => [0x290],
isa_detect => sub { w83781d_isa_detect(3, @_); },
alias_detect => sub { w83781d_alias_detect(3, @_); },
} ,
{
name => "Winbond W83627EHF",
driver => "use-isa-instead",
i2c_addrs => [0x28..0x2f],
i2c_detect => sub { w83781d_detect(9, @_); },
},
{
name => "Winbond W83627DHG",
driver => "use-isa-instead",
i2c_addrs => [0x28..0x2f],
i2c_detect => sub { w83781d_detect(10, @_); },
},
{
name => "Asus AS99127F (rev.1)",
driver => "w83781d",
i2c_addrs => [0x28..0x2f],
i2c_detect => sub { w83781d_detect(4, @_); },
} ,
{
name => "Asus AS99127F (rev.2)",
driver => "w83781d",
i2c_addrs => [0x28..0x2f],
i2c_detect => sub { w83781d_detect(5, @_); },
} ,
{
name => "Asus ASB100 Bach",
driver => "asb100",
i2c_addrs => [0x28..0x2f],
i2c_detect => sub { w83781d_detect(6, @_); },
} ,
{
name => "Asus ASM58 Mozart-2",
driver => "to-be-written",
i2c_addrs => [0x77],
i2c_detect => sub { mozart_detect(0, @_); },
} ,
{
name => "Asus AS2K129R Mozart-2",
driver => "to-be-written",
i2c_addrs => [0x77],
i2c_detect => sub { mozart_detect(1, @_); },
} ,
{
name => "Asus Mozart-2",
driver => "to-be-written",
i2c_addrs => [0x77],
i2c_detect => sub { mozart_detect(2, @_); },
} ,
{
name => "Winbond W83L784R/AR",
driver => "to-be-written",
i2c_addrs => [0x2d],
i2c_detect => sub { w83l784r_detect(0, @_); },
} ,
{
name => "Winbond W83L785R",
driver => "to-be-written",
i2c_addrs => [0x2d],
i2c_detect => sub { w83l784r_detect(1, @_); },
} ,
{
name => "Winbond W83L785TS-S",
driver => "w83l785ts",
i2c_addrs => [0x2e],
i2c_detect => sub { w83l785ts_detect(0, @_); },
} ,
{
name => "Genesys Logic GL518SM Revision 0x00",
driver => "gl518sm",
i2c_addrs => [0x2c, 0x2d],
i2c_detect => sub { gl518sm_detect(0, @_); },
},
{
name => "Genesys Logic GL518SM Revision 0x80",
driver => "gl518sm",
i2c_addrs => [0x2c, 0x2d],
i2c_detect => sub { gl518sm_detect(1, @_); },
},
{
name => "Genesys Logic GL520SM",
driver => "gl520sm",
i2c_addrs => [0x2c, 0x2d],
i2c_detect => sub { gl520sm_detect(@_); },
},
{
name => "Genesys Logic GL525SM",
driver => "Unwritten (GL525SM)",
i2c_addrs => [0x2d],
i2c_detect => sub { gl525sm_detect(@_); },
},
{
name => "Analog Devices ADM9240",
driver => "adm9240",
i2c_addrs => [0x2c..0x2f],
i2c_detect => sub { adm9240_detect(0, @_); },
},
{
name => "Dallas Semiconductor DS1621",
driver => "ds1621",
i2c_addrs => [0x48..0x4f],
i2c_detect => sub { ds1621_detect(@_); },
} ,
{
name => "Dallas Semiconductor DS1780",
driver => "adm9240",
i2c_addrs => [0x2c..0x2f],
i2c_detect => sub { adm9240_detect(1, @_); },
},
{
name => "National Semiconductor LM81",
driver => "adm9240",
i2c_addrs => [0x2c..0x2f],
i2c_detect => sub { adm9240_detect(2, @_); },
},
{
name => "Analog Devices ADM1026",
driver => "adm1026",
i2c_addrs => [0x2c,0x2d,0x2e],
i2c_detect => sub { adm1026_detect(0, @_); },
},
{
name => "Analog Devices ADM1025",
driver => "adm1025",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { adm1025_detect(0, @_); },
},
{
name => "Philips NE1619",
driver => "adm1025",
i2c_addrs => [0x2c..0x2d],
i2c_detect => sub { adm1025_detect(1, @_); },
},
{
name => "Analog Devices ADM1024",
driver => "adm1024",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { adm1024_detect(0, @_); },
},
{
name => "Analog Devices ADM1021",
driver => "adm1021",
i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e],
i2c_detect => sub { adm1021_detect(0, @_); },
},
{
name => "Analog Devices ADM1021A/ADM1023",
driver => "adm1021",
i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e],
i2c_detect => sub { adm1021_detect(1, @_); },
},
{
name => "Maxim MAX1617",
driver => "adm1021",
i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e],
i2c_detect => sub { adm1021_detect(2, @_); },
},
{
name => "Maxim MAX1617A",
driver => "adm1021",
i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e],
i2c_detect => sub { adm1021_detect(3, @_); },
},
{
name => "Maxim MAX6650/MAX6651",
driver => "max6650",
i2c_addrs => [0x1b,0x1f,0x48,0x4b],
i2c_detect => sub { max6650_detect(0, @_); },
},
{
name => "TI THMC10",
driver => "adm1021",
i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e],
i2c_detect => sub { adm1021_detect(4, @_); },
},
{
name => "National Semiconductor LM84",
driver => "adm1021",
i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e],
i2c_detect => sub { adm1021_detect(5, @_); },
},
{
name => "Genesys Logic GL523SM",
driver => "adm1021",
i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e],
i2c_detect => sub { adm1021_detect(6, @_); },
},
{
name => "Onsemi MC1066",
driver => "adm1021",
i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e],
i2c_detect => sub { adm1021_detect(7, @_); },
},
{
name => "Maxim MAX1619",
driver => "max1619",
i2c_addrs => [0x18..0x1a, 0x29..0x2b, 0x4c..0x4e],
i2c_detect => sub { max1619_detect(0, @_); },
},
{
name => "National Semiconductor LM82/LM83",
driver => "lm83",
i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e],
i2c_detect => sub { lm83_detect(0, @_); },
},
{
name => "National Semiconductor LM90",
driver => "lm90",
i2c_addrs => [0x4c],
i2c_detect => sub { lm90_detect(0, @_); },
},
{
name => "National Semiconductor LM89/LM99",
driver => "lm90",
i2c_addrs => [0x4c..0x4d],
i2c_detect => sub { lm90_detect(1, @_); },
},
{
name => "National Semiconductor LM86",
driver => "lm90",
i2c_addrs => [0x4c],
i2c_detect => sub { lm90_detect(2, @_); },
},
{
name => "Analog Devices ADM1032",
driver => "lm90",
i2c_addrs => [0x4c..0x4d],
i2c_detect => sub { lm90_detect(3, @_); },
},
{
name => "Maxim MAX6657/MAX6658/MAX6659",
driver => "lm90",
i2c_addrs => [0x4c],
i2c_detect => sub { lm90_detect(4, @_); },
},
{
name => "Maxim MAX6659",
driver => "lm90",
i2c_addrs => [0x4d..0x4e], # 0x4c is handled above
i2c_detect => sub { lm90_detect(4, @_); },
},
{
name => "National Semiconductor LM63",
driver => "lm63",
i2c_addrs => [0x4c],
i2c_detect => sub { lm63_detect(1, @_); },
},
{
name => "Fintek F75363SG",
driver => "lm63", # Not yet
i2c_addrs => [0x4c],
i2c_detect => sub { lm63_detect(2, @_); },
},
{
name => "National Semiconductor LM92",
driver => "lm92",
i2c_addrs => [0x48..0x4b],
i2c_detect => sub { lm92_detect(0, @_); },
},
{
name => "National Semiconductor LM76",
driver => "lm92",
i2c_addrs => [0x48..0x4b],
i2c_detect => sub { lm92_detect(1, @_); },
},
{
name => "Maxim MAX6633/MAX6634/MAX6635",
driver => "lm92",
i2c_addrs => [0x40..0x4f],
i2c_detect => sub { lm92_detect(2, @_); },
},
{
name => "Analog Devices ADT7461",
driver => "lm90",
i2c_addrs => [0x4c..0x4d],
i2c_detect => sub { lm90_detect(5, @_); },
},
{
name => "Analog Devices ADM1029",
driver => "to-be-written",
i2c_addrs => [0x28..0x2f],
i2c_detect => sub { adm1029_detect(0, @_); },
},
{
name => "Analog Devices ADM1030",
driver => "adm1031",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { adm1031_detect(0, @_); },
},
{
name => "Analog Devices ADM1031",
driver => "adm1031",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { adm1031_detect(1, @_); },
},
{
name => "Analog Devices ADM1033",
driver => "to-be-written",
i2c_addrs => [0x50..0x53],
i2c_detect => sub { adm1034_detect(0, @_); },
},
{
name => "Analog Devices ADM1034",
driver => "to-be-written",
i2c_addrs => [0x50..0x53],
i2c_detect => sub { adm1034_detect(1, @_); },
},
{
name => "Analog Devices ADM1022",
driver => "thmc50",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { adm1022_detect(0, @_); },
},
{
name => "Texas Instruments THMC50",
driver => "thmc50",
i2c_addrs => [0x2c..0x2e],
i2c_detect => sub { adm1022_detect(1, @_); },
},
{
name => "Analog Devices ADM1028",
driver => "thmc50",
i2c_addrs => [0x2e],
i2c_detect => sub { adm1022_detect(2, @_); },
},
{
name => "Silicon Integrated Systems SIS5595",
driver => "sis5595",
isa_addrs => [ 0 ],
isa_detect => sub { sis5595_pci_detect(); },
},
{
name => "VIA VT82C686 Integrated Sensors",
driver => "via686a",
isa_addrs => [ 0 ],
isa_detect => sub { via686a_pci_detect(); },
},
{
name => "VIA VT8231 Integrated Sensors",
driver => "vt8231",
isa_addrs => [ 0 ],
isa_detect => sub { via8231_pci_detect(); },
},
{
name => "VIA VT1211 (I2C)",
driver => "use-isa-instead",
i2c_addrs => [0x2d],
i2c_detect => sub { vt1211_i2c_detect(0, @_); },
},
{
name => "ITE IT8712F",
driver => "it87",
i2c_addrs => [0x28..0x2f],
i2c_detect => sub { ite_detect(0, @_); },
},
{
name => "ITE IT8201R/IT8203R/IT8206R/IT8266R",
driver => "not-a-sensor",
i2c_addrs => [0x4e],
i2c_detect => sub { ite_overclock_detect(@_); },
},
{
name => "SPD EEPROM",
driver => "eeprom",
i2c_addrs => [0x50..0x57],
i2c_detect => sub { eeprom_detect(0, @_); },
},
{
name => "Sony Vaio EEPROM",
driver => "eeprom",
i2c_addrs => [0x57],
i2c_detect => sub { eeprom_detect(1, @_); },
},
# Disabled by default (potentially dangerous)
# {
# name => "SPD EEPROM with Software Write-Protect",
# driver => "eeprom",
# i2c_addrs => [0x50..0x57],
# i2c_detect => sub { eeprom_detect(2, @_); },
# },
{
name => "EDID EEPROM",
driver => "eeprom",
i2c_addrs => [0x50],
i2c_detect => sub { ddcmonitor_detect(@_); },
},
{
name => "FSC Poseidon",
driver => "fscpos",
i2c_addrs => [0x73],
i2c_detect => sub { fscpos_detect(@_); },
},
{
name => "FSC Scylla",
driver => "fscscy",
i2c_addrs => [0x73],
i2c_detect => sub { fscscy_detect(@_); },
},
{
name => "FSC Hermes",
driver => "fscher",
i2c_addrs => [0x73],
i2c_detect => sub { fscher_detect(@_); },
},
{
name => "ALi M5879",
driver => "to-be-written",
i2c_addrs => [0x2c..0x2d],
i2c_detect => sub { m5879_detect(@_); },
},
{
name => "SMSC LPC47M15x, LPC47M192 or LPC47M997",
driver => "smsc47m192",
i2c_addrs => [0x2c..0x2d],
i2c_detect => sub { smsc47m192_detect(@_); },
},
{
name => "Fintek F75111R/RG/N (GPIO)",
driver => "to-be-written",
i2c_addrs => [0x4e], # 0x37 not probed
i2c_detect => sub { fintek_detect(1, @_); },
},
{
name => "Fintek F75121R/F75122R/RG (VID+GPIO)",
driver => "to-be-written",
i2c_addrs => [0x4e], # 0x37 not probed
i2c_detect => sub { fintek_detect(2, @_); },
},
{
name => "Fintek F75373S/SG",
driver => "to-be-written",
i2c_addrs => [0x2d..0x2e],
i2c_detect => sub { fintek_detect(3, @_); },
},
{
name => "Fintek F75375S/SP",
driver => "to-be-written",
i2c_addrs => [0x2d..0x2e],
i2c_detect => sub { fintek_detect(4, @_); },
},
{
name => "Fintek F75387SG/RG",
driver => "to-be-written",
i2c_addrs => [0x2d..0x2e],
i2c_detect => sub { fintek_detect(5, @_); },
},
{
name => "Fintek F75383S/M",
driver => "to-be-written",
i2c_addrs => [0x4c],
i2c_detect => sub { fintek_detect(6, @_); },
},
{
name => "Fintek F75384S/M",
driver => "to-be-written",
i2c_addrs => [0x4d],
i2c_detect => sub { fintek_detect(6, @_); },
},
{
name => "Fintek custom power control IC",
driver => "to-be-written",
i2c_addrs => [0x2f],
i2c_detect => sub { fintek_detect(7, @_); },
},
{
name => "AMD K8 thermal sensors",
driver => "k8temp",
isa_addrs => [ 0 ],
isa_detect => sub { k8temp_pci_detect(); },
},
{
name => "Philips Semiconductors SAA1064",
driver => "saa1064",
i2c_addrs => [0x38..0x3b],
i2c_detect => sub { saa1064_detect(@_); },
},
{
name => "Philips Semiconductors PCA9540",
driver => "pca9540",
i2c_addrs => [0x70],
i2c_detect => sub { pca9540_detect(@_); },
},
{
name => "Philips Semiconductors PCA9556",
driver => "to-be-written",
i2c_addrs => [0x18..0x1f],
i2c_detect => sub { pca9556_detect(@_); },
},
{
name => "Maxim MAX6900",
driver => "to-be-written",
i2c_addrs => [0x50],
i2c_detect => sub { max6900_detect(@_); },
},
{
name => "SMBus 2.0 ARP-Capable Device",
driver => "not-a-sensor",
i2c_addrs => [0x61],
i2c_detect => sub { arp_detect(@_); },
},
{
name => "IPMI BMC KCS",
driver => "bmcsensors",
isa_addrs => [ 0x0ca0 ],
isa_detect => sub { ipmi_kcs_detect(@_); },
},
{
name => "IPMI BMC SMIC",
driver => "bmcsensors",
isa_addrs => [ 0x0ca8 ],
isa_detect => sub { ipmi_smic_detect(@_); },
},
{
name => "Smart Battery Charger",
driver => "to-be-written",
i2c_addrs => [0x09],
i2c_detect => sub { smartbatt_chgr_detect(@_); },
},
{
name => "Smart Battery Manager/Selector",
driver => "to-be-written",
i2c_addrs => [0x0a],
i2c_detect => sub { smartbatt_mgr_detect(@_); },
},
{
name => "Smart Battery",
driver => "smartbatt",
i2c_addrs => [0x0b],
i2c_detect => sub { smartbatt_detect(@_); },
},
);
# Special case chip information goes here and would be included in
# the chip_special_cases routine below
use vars qw($chip_kern24_w83791d $chip_kern26_w83791d);
$chip_kern24_w83791d = {
name => "Winbond W83791D",
driver => "w83781d",
i2c_addrs => [0x2c..0x2f],
i2c_detect => sub { w83781d_detect(7, @_); },
};
$chip_kern26_w83791d = {
name => "Winbond W83791D",
driver => "w83791d",
i2c_addrs => [0x2c..0x2f],
i2c_detect => sub { w83781d_detect(7, @_); },
};
# This is a list of all recognized superio chips.
# Each entry must have the following fields:
# name: The full chip name
# driver: The driver name (without .o extension). Put in
# "to-be-written" if it is not yet available.
# Put in "not-a-sensor" if the chip doesn't have hardware monitoring
# capabilities (listing such chips here removes the need of manual
# lookup when people report them).
# devid: The device ID(s) we have to match (base device)
# devid_mask (optional): Bitmask to apply before checking the device ID
# logdev: The logical device containing the sensors
# alias_detect (optional): For chips which can be both on the ISA and the
# I2C bus, a function which detectes whether two entries are the same.
# The function should take three parameters: The ISA address, the
# I2C bus number, and the I2C address.
# Entries are grouped by family. Each family entry has the following fields:
# family: The family name
# guess (optional): Typical logical device address. This lets us do
# generic probing if we fail to recognize the chip.
# enter: The password sequence to write to the address register
# chips: Array of chips
@superio_ids = (
{
family => "ITE",
guess => 0x290,
enter =>
{
0x2e => [0x87, 0x01, 0x55, 0x55],
0x4e => [0x87, 0x01, 0x55, 0xaa],
},
chips =>
[
{
name => "ITE IT8702F Super IO Sensors",
driver => "to-be-written",
devid => 0x8702,
logdev => 0x04,
},
{
name => "ITE IT8705F Super IO Sensors",
driver => "it87",
devid => 0x8705,
logdev => 0x04,
},
{
name => "ITE IT8712F Super IO Sensors",
driver => "it87",
devid => 0x8712,
logdev => 0x04,
alias_detect => sub { ite_alias_detect(0, @_); },
},
{
name => "ITE IT8716F Super IO Sensors",
driver => "it87",
devid => 0x8716,
logdev => 0x04,
},
{
name => "ITE IT8718F Super IO Sensors",
driver => "it87",
devid => 0x8718,
logdev => 0x04,
},
],
},
{
family => "National Semiconductor",
enter =>
{
0x2e => [],
0x4e => [],
},
chips =>
[
{
name => "Nat. Semi. PC87351 Super IO Fan Sensors",
driver => "to-be-written",
devid => 0xe2,
logdev => 0x08,
},
{
name => "Nat. Semi. PC87360 Super IO Fan Sensors",
driver => "pc87360",
devid => 0xe1,
logdev => 0x09,
},
{
name => "Nat. Semi. PC87363 Super IO Fan Sensors",
driver => "pc87360",
devid => 0xe8,
logdev => 0x09,
},
{
name => "Nat. Semi. PC87364 Super IO Fan Sensors",
driver => "pc87360",
devid => 0xe4,
logdev => 0x09,
},
{
name => "Nat. Semi. PC87365 Super IO Fan Sensors",
driver => "pc87360",
devid => 0xe5,
logdev => 0x09,
},
{
name => "Nat. Semi. PC87365 Super IO Voltage Sensors",
driver => "pc87360",
devid => 0xe5,
logdev => 0x0d,
},
{
name => "Nat. Semi. PC87365 Super IO Thermal Sensors",
driver => "pc87360",
devid => 0xe5,
logdev => 0x0e,
},
{
name => "Nat. Semi. PC87366 Super IO Fan Sensors",
driver => "pc87360",
devid => 0xe9,
logdev => 0x09,
},
{
name => "Nat. Semi. PC87366 Super IO Voltage Sensors",
driver => "pc87360",
devid => 0xe9,
logdev => 0x0d,
},
{
name => "Nat. Semi. PC87366 Super IO Thermal Sensors",
driver => "pc87360",
devid => 0xe9,
logdev => 0x0e,
},
{
name => "Nat. Semi. PC87372 Super IO Fan Sensors",
driver => "to-be-written",
devid => 0xf0,
logdev => 0x09,
},
{
name => "Nat. Semi. PC87373 Super IO Fan Sensors",
driver => "to-be-written",
devid => 0xf3,
logdev => 0x09,
},
{
name => "Nat. Semi. PC87591 Super IO",
driver => "to-be-written",
devid => 0xec,
logdev => 0x0f,
},
{
name => "Nat. Semi. PC87371 Super IO",
driver => "not-a-sensor",
devid => 0xd0,
},
{
name => "Nat. Semi. PC97371 Super IO",
driver => "not-a-sensor",
devid => 0xdf,
},
{
name => "Nat. Semi. PC8739x Super IO",
driver => "not-a-sensor",
devid => 0xea,
},
{
name => "Nat. Semi. PC8741x Super IO",
driver => "not-a-sensor",
devid => 0xee,
},
{
name => "Nat. Semi. PC87427 Super IO Fan Sensors",
driver => "to-be-written",
devid => 0xf2,
logdev => 0x09,
},
{
name => "Nat. Semi. PC87427 Super IO Health Sensors",
driver => "to-be-written",
devid => 0xf2,
logdev => 0x14,
},
],
},
{
family => "SMSC",
enter =>
{
0x2e => [0x55],
0x4e => [0x55],
},
chips =>
[
{
name => "SMSC LPC47B27x Super IO Fan Sensors",
driver => "smsc47m1",
devid => 0x51,
logdev => 0x0a,
},
{
name => "SMSC LPC47M10x/112/13x Super IO Fan Sensors",
driver => "smsc47m1",
devid => 0x59,
logdev => 0x0a,
},
{
name => "SMSC LPC47M14x Super IO Fan Sensors",
driver => "smsc47m1",
devid => 0x5f,
logdev => 0x0a,
},
{
name => "SMSC LPC47M15x/192/997 Super IO Fan Sensors",
driver => "smsc47m1",
devid => 0x60,
logdev => 0x0a,
},
{
name => "SMSC LPC47S42x Super IO Fan Sensors",
driver => "to-be-written",
devid => 0x57,
logdev => 0x0a,
},
{
name => "SMSC LPC47S45x Super IO Fan Sensors",
driver => "to-be-written",
devid => 0x62,
logdev => 0x0a,
},
{
name => "SMSC LPC47M172 Super IO Fan Sensors",
driver => "to-be-written",
devid => 0x14,
logdev => 0x0a,
},
{
name => "SMSC LPC47M182 Super IO Fan Sensors",
driver => "to-be-written",
devid => 0x74,
logdev => 0x0a,
},
{
name => "SMSC LPC47B397-NC Super IO",
driver => "smsc47b397",
devid => 0x6f,
logdev => 0x08,
},
{
name => "SMSC SCH5307-NS Super IO",
driver => "smsc47b397",
devid => 0x81,
logdev => 0x08,
},
{
name => "SMSC LPC47M584-NC Super IO",
# No datasheet
devid => 0x76,
},
],
},
{
family => "VIA/Winbond/Fintek",
guess => 0x290,
enter =>
{
0x2e => [0x87, 0x87],
0x4e => [0x87, 0x87],
},
chips =>
[
{
name => "VIA VT1211 Super IO Sensors",
driver => "vt1211",
devid => 0x3c,
logdev => 0x0b,
alias_detect => sub { vt1211_alias_detect(0, @_); },
},
{
name => "Winbond W83627HF Super IO Sensors",
driver => "w83627hf",
devid => 0x52,
logdev => 0x0b,
},
{
name => "Winbond W83627THF Super IO Sensors",
driver => "w83627hf",
devid => 0x82,
logdev => 0x0b,
},
{
name => "Winbond W83637HF Super IO Sensors",
driver => "w83627hf",
devid => 0x70,
logdev => 0x0b,
},
{
name => "Winbond W83687THF Super IO Sensors",
driver => "w83627hf",
devid => 0x85,
logdev => 0x0b,
},
{
name => "Winbond W83697HF Super IO Sensors",
driver => "w83627hf",
devid => 0x60,
logdev => 0x0b,
},
{
name => "Winbond W83697SF/UF Super IO PWM",
driver => "to-be-written",
devid => 0x68,
logdev => 0x0b,
},
{
name => "Winbond W83627EHF/EHG Super IO Sensors",
driver => "w83627ehf",
# W83627EHF datasheet says 0x886x but 0x8853 was seen, thus the
# broader mask. W83627EHG was seen with ID 0x8863.
devid => 0x8840,
devid_mask => 0xFFC0,
logdev => 0x0b,
alias_detect => sub { w83781d_alias_detect(9, @_); },
},
{
name => "Winbond W83627DHG Super IO Sensors",
driver => "w83627ehf",
devid => 0xA020,
devid_mask => 0xFFF0,
logdev => 0x0b,
alias_detect => sub { w83781d_alias_detect(10, @_); },
},
{
name => "Winbond W83L517D Super IO",
driver => "not-a-sensor",
devid => 0x61,
},
{
name => "Fintek F71805F/FG Super IO Sensors",
driver => "f71805f",
devid => 0x0406,
logdev => 0x04,
},
{
name => "Fintek F71872F/FG Super IO Sensors",
driver => "f71805f",
devid => 0x0341,
logdev => 0x04,
},
{
name => "Fintek F81218D Super IO",
driver => "not-a-sensor",
devid => 0x0206,
},
],
},
);
#######################
# AUXILIARY FUNCTIONS #
#######################
sub swap_bytes
{
return (($_[0] & 0xff00) >> 8) + (($_[0] & 0x00ff) << 8)
}
# $_[0] is the sought value
# @_[1..] is the list to seek in
# Returns: 0 on failure, 1 if found.
# Note: Every use of this sub probably indicates the use of the wrong
# datastructure
sub contains
{
my $sought = shift;
foreach (@_) {
return 1 if $sought eq $_;
}
return 0;
}
sub parse_not_to_scan
{
my ($min,$max,$to_parse) = @_;
my @ranges = split /\s*,\s*/, $to_parse;
my @res;
my $range;
foreach $range (@ranges) {
my ($start,$end) = split /\s*-s*/, $range;
$start = oct $start if $start =~ /^0/;
if (defined $end) {
$end = oct $end if $end =~ /^0/;
$start = $min if $start < $min;
$end = $max if $end > $max;
push @res, ($start+0..$end+0);
} else {
push @res, $start+0 if $start >= $min and $start <= $max;
}
}
return sort { $a <=> $b } @res;
}
# @_[0]: Reference to list 1
# @_[1]: Reference to list 2
# Result: 0 if they have no elements in common, 1 if they have
# Elements must be numeric.
sub any_list_match
{
my ($list1,$list2) = @_;
my ($el1,$el2);
foreach $el1 (@$list1) {
foreach $el2 (@$list2) {
return 1 if $el1 == $el2;
}
}
return 0;
}
###################
# I/O port access #
###################
sub initialize_ioports
{
sysopen (IOPORTS, "/dev/port", O_RDWR)
or die "/dev/port: $!\n";
binmode IOPORTS;
}
sub close_ioports
{
close (IOPORTS)
or print "Warning: $!\n";
}
# $_[0]: port to read
# Returns: -1 on failure, read value on success.
sub inb
{
my ($res,$nrchars);
sysseek IOPORTS, $_[0], 0 or return -1;
$nrchars = sysread IOPORTS, $res, 1;
return -1 if not defined $nrchars or $nrchars != 1;
$res = unpack "C",$res ;
return $res;
}
# $_[0]: port to write
# $_[1]: value to write
# Returns: -1 on failure, 0 on success.
sub outb
{
if ($_[1] > 0xff)
{
my ($package, $filename, $line, $sub) = caller(1);
print "\n*** Called outb with value=$_[1] from line $line\n",
"*** (in $sub). PLEASE REPORT!\n",
"*** Terminating.\n";
exit(-1);
}
my $towrite = pack "C", $_[1];
sysseek IOPORTS, $_[0], 0 or return -1;
my $nrchars = syswrite IOPORTS, $towrite, 1;
return -1 if not defined $nrchars or $nrchars != 1;
return 0;
}
# $_[0]: Address register
# $_[1]: Data register
# $_[2]: Register to read
# Returns: read value
sub isa_read_byte
{
outb $_[0],$_[2];
return inb $_[1];
}
# $_[0]: Address register
# $_[1]: Data register
# $_[2]: Register to write
# $_[3}: Value to write
# Returns: nothing
sub isa_write_byte
{
outb $_[0],$_[2];
outb $_[1],$_[3];
}
#################
# AUTODETECTION #
#################
use vars qw($modules_conf $dev_i2c $sysfs_root);
sub initialize_conf
{
my $use_devfs = 0;
open(local *INPUTFILE, "/proc/mounts") or die "Can't access /proc/mounts!";
local $_;
while (<INPUTFILE>) {
if (m@^\w+ /dev devfs @) {
$use_devfs = 1;
$dev_i2c = '/dev/i2c/';
}
if (m@^\S+ (/\w+) sysfs @) {
$sysfs_root = $1;
}
}
close INPUTFILE;
my $use_udev = 0;
if (open(*INPUTFILE, '/etc/udev/udev.conf')) {
while (<INPUTFILE>) {
if (m/^\s*udev_db\s*=\s*\"([^"]*)\"/ || m/^\s*udev_db\s*=\s*(\S+)/) {
if (-e $1) {
$use_udev = 1;
$dev_i2c = '/dev/i2c-';
}
last;
}
}
close INPUTFILE;
}
if (!$use_udev) {
# Try some known default udev db locations, just in case
if (-e '/dev/.udev.tdb' || -e '/dev/.udev'
|| -e '/dev/.udevdb') {
$use_udev = 1;
$dev_i2c = '/dev/i2c-';
}
}
if (-f '/etc/modules.conf') {
$modules_conf = '/etc/modules.conf';
} elsif (-f '/etc/conf.modules') {
$modules_conf = '/etc/conf.modules';
} else { # default
$modules_conf = '/etc/modules.conf';
}
if (!($use_devfs || $use_udev)) {
if (-c '/dev/i2c-0') {
$dev_i2c = '/dev/i2c-';
} else { # default
print "No i2c device files found. Use prog/mkdev/mkdev.sh to create them.\n";
exit -1;
}
}
}
# [0] -> VERSION
# [1] -> PATCHLEVEL
# [2] -> SUBLEVEL
# [3] -> EXTRAVERSION
#
use vars qw(@kernel_version);
sub initialize_kernel_version
{
`uname -r` =~ /(\d+)\.(\d+)\.(\d+)(.*)/;
@kernel_version = ($1, $2, $3, $4);
}
sub kernel_version_at_least
{
my ($vers, $plvl, $slvl) = @_;
return 1 if ($kernel_version[0] > $vers ||
($kernel_version[0] == $vers &&
($kernel_version[1] > $plvl ||
($kernel_version[1] == $plvl &&
($kernel_version[2] >= $slvl)))));
return 0;
}
###########
# MODULES #
###########
use vars qw(%modules_list %modules_supported);
sub initialize_modules_list
{
open(local *INPUTFILE, "/proc/modules") or return;
local $_;
while (<INPUTFILE>) {
tr/_/-/;
$modules_list{$1} = 1 if m/^(\S*)/;
}
}
sub initialize_modules_supported
{
foreach my $chip (@chip_ids) {
$modules_supported{$chip->{driver}}++;
}
}
#################
# SYSFS HELPERS #
#################
# From a sysfs device path, return the driver name, or undef
sub sysfs_device_driver($)
{
my $device = shift;
my $link = readlink("$device/driver");
return unless defined $link;
return basename($link);
}
# From a sysfs device path and an attribute name, return the attribute
# value, or undef
sub sysfs_device_attribute($$)
{
my ($device, $attr) = @_;
my $value;
open(local *FILE, "$device/$attr") or return;
return unless defined($value = <FILE>);
close(FILE);
chomp($value);
return $value;
}
##############
# PCI ACCESS #
##############
use vars qw(%pci_list);
# This function returns a list of hashes. Each hash has some PCI information:
# 'domain', 'bus', 'slot' and 'func' uniquely identify a PCI device in a
# computer; 'vendid' and 'devid' uniquely identify a type of device.
# 'class' lets us spot unknown SMBus adapters.
# This function is used when sysfs is available (Linux 2.6).
sub read_sys_dev_pci($)
{
my $devices = shift;
my ($dev, @pci_list);
opendir(local *DEVICES, "$devices")
or die "$devices: $!";
while (defined($dev = readdir(DEVICES))) {
my %record;
next unless $dev =~
m/^(?:([\da-f]+):)?([\da-f]+):([\da-f]+)\.([\da-f]+)$/;
$record{domain} = hex $1;
$record{bus} = hex $2;
$record{slot} = hex $3;
$record{func} = hex $4;
$record{vendid} = oct sysfs_device_attribute("$devices/$dev", "vendor");
$record{devid} = oct sysfs_device_attribute("$devices/$dev", "device");
$record{class} = (oct sysfs_device_attribute("$devices/$dev", "class"))
>> 8;
push @pci_list, \%record;
}
return \@pci_list;
}
# This function returns a list of hashes. Each hash has some PCI information:
# 'bus', 'slot' and 'func' uniquely identify a PCI device in a computer;
# 'vendid' and 'devid' uniquely identify a type of device.
# This function is used when sysfs is not available (Linux 2.4).
sub read_proc_dev_pci
{
my ($dfn, $vend, @pci_list);
open(local *INPUTFILE, "/proc/bus/pci/devices")
or die "/proc/bus/pci/devices: $!";
local $_;
while (<INPUTFILE>) {
my %record;
($dfn, $vend) = map { hex } (split) [0..1];
$record{bus} = $dfn >> 8;
$record{slot} = ($dfn & 0xf8) >> 3;
$record{func} = $dfn & 0x07;
$record{vendid} = $vend >> 16;
$record{devid} = $vend & 0xffff;
push @pci_list, \%record;
}
return \@pci_list;
}
sub initialize_proc_pci
{
my $pci_list;
if (defined $sysfs_root) {
$pci_list = read_sys_dev_pci("$sysfs_root/bus/pci/devices");
} else {
$pci_list = read_proc_dev_pci();
}
# Note that we lose duplicate devices at this point, but we don't
# really care. What matters to us is which unique devices are present,
# not how many of each.
%pci_list = map {
sprintf("%04x:%04x", $_->{vendid}, $_->{devid}) => $_
} @{$pci_list};
}
#####################
# ADAPTER DETECTION #
#####################
sub adapter_pci_detection_sis_96x
{
my $driver="";
# first, determine which driver if any...
if (kernel_version_at_least(2,6,0)) {
if (exists $pci_list{"1039:0016"}) {
$driver = "i2c-sis96x";
} elsif (exists $pci_list{"1039:0008"}) {
$driver = "i2c-sis5595";
}
} elsif (kernel_version_at_least(2,4,0)) {
if (exists $pci_list{"1039:0008"}) {
if ((exists $pci_list{"1039:0645"}) ||
(exists $pci_list{"1039:0646"}) ||
(exists $pci_list{"1039:0648"}) ||
(exists $pci_list{"1039:0650"}) ||
(exists $pci_list{"1039:0651"}) ||
(exists $pci_list{"1039:0655"}) ||
(exists $pci_list{"1039:0661"}) ||
(exists $pci_list{"1039:0735"}) ||
(exists $pci_list{"1039:0745"}) ||
(exists $pci_list{"1039:0746"})) {
$driver = "i2c-sis645";
} else {
$driver = "i2c-sis5595";
}
} elsif ((exists $pci_list{"1039:0016"}) ||
(exists $pci_list{"1039:0018"})) {
$driver = "i2c-sis645";
}
}
# then, add the appropriate entries to @pci_adapters
if ($driver eq "i2c-sis5595") {
push @pci_adapters, @pci_adapters_sis5595;
} elsif ($driver eq "i2c-sis645") {
push @pci_adapters, @pci_adapters_sis645;
} elsif ($driver eq "i2c-sis96x") {
push @pci_adapters, @pci_adapters_sis96x;
}
}
# Build and return a PCI device's bus ID
sub pci_busid($)
{
my $device = shift;
my $busid;
$busid = sprintf("\%02x:\%02x.\%x",
$device->{bus}, $device->{slot}, $device->{func});
$busid = sprintf("\%04x:", $device->{domain}) . $busid
if defined $device->{domain};
return $busid;
}
sub adapter_pci_detection
{
my ($key, $device, $try, @res, %smbus);
print "Probing for PCI bus adapters...\n";
# Custom detection routine for some SiS chipsets
adapter_pci_detection_sis_96x();
# Build a list of detected SMBus devices
foreach $key (keys %pci_list) {
$device = $pci_list{$key};
$smbus{$key}++
if exists $device->{class} && $device->{class} == 0x0c05; # SMBus
}
# Loop over the known I2C/SMBus adapters
foreach $try (@pci_adapters) {
$key = sprintf("%04x:%04x", $try->{vendid}, $try->{devid});
if (exists $pci_list{$key}) {
$device = $pci_list{$key};
printf "Use driver `\%s' for device \%s: \%s\n",
$try->{driver}, pci_busid($device), $try->{procid};
if ($try->{driver} eq "to-be-tested") {
print "\nWe are currently looking for testers for this adapter!\n".
"Please check http://www.lm-sensors.org/wiki/Devices\n".
"and/or contact us if you want to help.\n\n";
print "Continue... ";
<STDIN>;
print "\n";
}
push @res,$try->{driver};
# Delete from detected SMBus device list
delete $smbus{$key};
}
}
# Now see if there are unknown SMBus devices left
foreach $key (keys %smbus) {
$device = $pci_list{$key};
printf "Found unknown SMBus adapter \%04x:\%04x at \%s.\n",
$device->{vendid}, $device->{devid}, pci_busid($device);
}
if (! @res) {
print "Sorry, no known PCI bus adapters found.\n";
}
return @res;
}
# $_[0]: Adapter description as found in /proc/bus/i2c
sub find_adapter_driver
{
my $adapter;
for $adapter (@pci_adapters) {
return $adapter->{driver}
if (exists $adapter->{match} && $_[0] =~ $adapter->{match});
}
return "UNKNOWN";
}
#############################
# I2C AND SMBUS /DEV ACCESS #
#############################
# This should really go into a separate module/package.
# These are copied from <linux/i2c-dev.h>
use constant IOCTL_I2C_SLAVE => 0x0703;
use constant IOCTL_I2C_FUNCS => 0x0705;
use constant IOCTL_I2C_SMBUS => 0x0720;
use constant SMBUS_READ => 1;
use constant SMBUS_WRITE => 0;
use constant SMBUS_QUICK => 0;
use constant SMBUS_BYTE => 1;
use constant SMBUS_BYTE_DATA => 2;
use constant SMBUS_WORD_DATA => 3;
use constant I2C_FUNC_SMBUS_QUICK => 0x00010000;
use constant I2C_FUNC_SMBUS_READ_BYTE => 0x00020000;
# Get the i2c adapter's functionalities
# $_[0]: Reference to an opened filehandle
# Returns: -1 on failure, functionality bitfield on success.
sub i2c_get_funcs($)
{
my $file = shift;
my $funcs;
ioctl $file, IOCTL_I2C_FUNCS, $funcs='' or return -1;
$funcs = unpack "L", $funcs;
return $funcs;
}
# Select the device to communicate with through its address.
# $_[0]: Reference to an opened filehandle
# $_[1]: Address to select
# Returns: 0 on failure, 1 on success.
sub i2c_set_slave_addr
{
my ($file,$addr) = @_;
ioctl $file, IOCTL_I2C_SLAVE, $addr or return 0;
return 1;
}
# i2c_smbus_access is based upon the corresponding C function (see
# <linux/i2c-dev.h>). You should not need to call this directly.
# Exact calling conventions are intricate; read i2c-dev.c if you really need
# to know.
# $_[0]: Reference to an opened filehandle
# $_[1]: SMBUS_READ for reading, SMBUS_WRITE for writing
# $_[2]: Command (usually register number)
# $_[3]: Transaction kind (SMBUS_BYTE, SMBUS_BYTE_DATA, etc.)
# $_[4]: Reference to an array used for input/output of data
# Returns: 0 on failure, 1 on success.
# Note that we need to get back to Integer boundaries through the 'x2'
# in the pack. This is very compiler-dependent; I wish there was some other
# way to do this.
sub i2c_smbus_access
{
my ($file,$read_write,$command,$size,$data) = @_;
my $data_array = pack "C32", @$data;
my $ioctl_data = pack "C2x2Ip", ($read_write,$command,$size,$data_array);
ioctl $file, IOCTL_I2C_SMBUS, $ioctl_data or return 0;
@{$_[4]} = unpack "C32",$data_array;
return 1;
}
# $_[0]: Reference to an opened filehandle
# $_[1]: Either 0 or 1
# Returns: -1 on failure, the 0 on success.
sub i2c_smbus_write_quick
{
my ($file,$value) = @_;
my @data;
i2c_smbus_access $file, $value, 0, SMBUS_QUICK, \@data
or return -1;
return 0;
}
# $_[0]: Reference to an opened filehandle
# Returns: -1 on failure, the read byte on success.
sub i2c_smbus_read_byte
{
my ($file) = @_;
my @data;
i2c_smbus_access $file, SMBUS_READ, 0, SMBUS_BYTE, \@data
or return -1;
return $data[0];
}
# $_[0]: Reference to an opened filehandle
# $_[1]: Command byte (usually register number)
# Returns: -1 on failure, the read byte on success.
sub i2c_smbus_read_byte_data
{
my ($file,$command) = @_;
my @data;
i2c_smbus_access $file, SMBUS_READ, $command, SMBUS_BYTE_DATA, \@data
or return -1;
return $data[0];
}
# $_[0]: Reference to an opened filehandle
# $_[1]: Command byte (usually register number)
# Returns: -1 on failure, the read word on success.
# Note: some devices use the wrong endiannes; use swap_bytes to correct for
# this.
sub i2c_smbus_read_word_data
{
my ($file,$command) = @_;
my @data;
i2c_smbus_access $file, SMBUS_READ, $command, SMBUS_WORD_DATA, \@data
or return -1;
return $data[0] + 256 * $data[1];
}
# $_[0]: Reference to an opened filehandle
# $_[1]: Address
# $_[2]: Functionalities of this i2c adapter
# Returns: 1 on successful probing, 0 else.
# This function is meant to prevent AT24RF08 corruption and write-only
# chips locks. This is done by choosing the best probing method depending
# on the address range.
sub i2c_probe($$$)
{
my ($file, $addr, $funcs) = @_;
my $data = [];
if (($addr >= 0x50 && $addr <= 0x5F)
|| ($addr >= 0x30 && $addr <= 0x37)) {
# This covers all EEPROMs we know of, including page protection addresses.
# Note that some page protection addresses will not reveal themselves with
# this, because they ack on write only, but this is probably better since
# some EEPROMs write-protect themselves permanently on almost any write to
# their page protection address.
return 0 unless ($funcs & I2C_FUNC_SMBUS_READ_BYTE);
return i2c_smbus_access($file, SMBUS_READ, 0, SMBUS_BYTE, $data);
} else {
return 0 unless ($funcs & I2C_FUNC_SMBUS_QUICK);
return i2c_smbus_access($file, SMBUS_WRITE, 0, SMBUS_QUICK, $data);
}
}
####################
# ADAPTER SCANNING #
####################
use vars qw(@chips_detected);
# We will build a complicated structure @chips_detected here, being:
# A list of
# references to hashes
# with field 'driver', being a string with the driver name for this chip;
# with field 'detected'
# being a reference to a list of
# references to hashes of type 'detect_data';
# with field 'misdetected'
# being a reference to a list of
# references to hashes of type 'detect_data'
# Type detect_data:
# A hash
# with field 'i2c_adap' containing an adapter string as appearing
# in /proc/bus/i2c (if this is an I2C detection)
# with field 'i2c_devnr', contianing the /dev/i2c-* number of this
# adapter (if this is an I2C detection)
# with field 'i2c_driver', containing the driver name for this adapter
# (if this is an I2C detection)
# with field 'i2c_addr', containing the I2C address of the detection;
# (if this is an I2C detection)
# with field 'i2c_sub_addrs', containing a reference to a list of
# other I2C addresses (if this is an I2C detection)
# with field 'isa_addr' containing the ISA address this chip is on
# (if this is an ISA detection)
# with field 'conf', containing the confidence level of this detection
# with field 'chipname', containing the chip name
# This adds a detection to the above structure. We do no alias detection
# here; so you should do ISA detections *after* all I2C detections.
# Not all possibilities of i2c_addr and i2c_sub_addrs are exhausted.
# In all normal cases, it should be all right.
# $_[0]: chip driver
# $_[1]: reference to data hash
# Returns: Nothing
sub add_i2c_to_chips_detected
{
my ($chipdriver,$datahash) = @_;
my ($i,$new_detected_ref,$new_misdetected_ref,$detected_ref,$misdetected_ref,
$main_entry,$detected_entry,$put_in_detected,@hash_addrs,@entry_addrs,
$do_not_add);
# First determine where the hash has to be added.
for ($i = 0; $i < @chips_detected; $i++) {
last if ($chips_detected[$i]->{driver} eq $chipdriver);
}
if ($i == @chips_detected) {
push @chips_detected, { driver => $chipdriver,
detected => [],
misdetected => [] };
}
$new_detected_ref = $chips_detected[$i]->{detected};
$new_misdetected_ref = $chips_detected[$i]->{misdetected};
# Find out whether our new entry should go into the detected or the
# misdetected list. We compare all i2c addresses; if at least one matches,
# but our conf value is lower, we assume this is a misdetect.
@hash_addrs = ($datahash->{i2c_addr});
push @hash_addrs, @{$datahash->{i2c_sub_addrs}}
if exists $datahash->{i2c_sub_addrs};
$put_in_detected = 1;
$do_not_add = 0;
FIND_LOOP:
foreach $main_entry (@chips_detected) {
foreach $detected_entry (@{$main_entry->{detected}}) {
@entry_addrs = ($detected_entry->{i2c_addr});
push @entry_addrs, @{$detected_entry->{i2c_sub_addrs}}
if exists $detected_entry->{i2c_sub_addrs};
if ($detected_entry->{i2c_devnr} == $datahash->{i2c_devnr} and
any_list_match \@entry_addrs, \@hash_addrs) {
if ($detected_entry->{conf} >= $datahash->{conf}) {
$put_in_detected = 0;
}
if ($chipdriver eq $main_entry->{driver}) {
$do_not_add = 1;
}
last FIND_LOOP;
}
}
}
if ($put_in_detected) {
# Here, we move all entries from detected to misdetected which
# match at least in one main or sub address. This may not be the
# best idea to do, as it may remove detections without replacing
# them with second-best ones. Too bad.
# (Khali 2003-09-13) If the driver is the same, the "misdetected"
# entry is simply deleted; failing to do so cause the configuration
# lines generated later to look very confusing (the driver will
# be told to ignore valid addresses).
@hash_addrs = ($datahash->{i2c_addr});
push @hash_addrs, @{$datahash->{i2c_sub_addrs}}
if exists $datahash->{i2c_sub_addrs};
foreach $main_entry (@chips_detected) {
$detected_ref = $main_entry->{detected};
$misdetected_ref = $main_entry->{misdetected};
for ($i = @$detected_ref-1; $i >=0; $i--) {
@entry_addrs = ($detected_ref->[$i]->{i2c_addr});
push @entry_addrs, @{$detected_ref->[$i]->{i2c_sub_addrs}}
if exists $detected_ref->[$i]->{i2c_sub_addrs};
if ($detected_ref->[$i]->{i2c_devnr} == $datahash->{i2c_devnr} and
any_list_match \@entry_addrs, \@hash_addrs) {
push @$misdetected_ref,$detected_ref->[$i]
unless $chipdriver eq $main_entry->{driver};
splice @$detected_ref, $i, 1;
}
}
}
# Now add the new entry to detected
push @$new_detected_ref, $datahash;
} else {
# No hard work here
push @$new_misdetected_ref, $datahash
unless $do_not_add;
}
}
# This adds a detection to the above structure. We also do alias detection
# here; so you should do ISA detections *after* all I2C detections.
# $_[0]: alias detection function
# $_[1]: chip driver
# $_[2]: reference to data hash
# Returns: 0 if it is not an alias, datahash reference if it is.
sub add_isa_to_chips_detected
{
my ($alias_detect,$chipdriver,$datahash) = @_;
my ($i,$new_detected_ref,$new_misdetected_ref,$detected_ref,$misdetected_ref,
$main_entry,$isalias);
# First determine where the hash has to be added.
$isalias=0;
for ($i = 0; $i < @chips_detected; $i++) {
last if ($chips_detected[$i]->{driver} eq $chipdriver);
}
if ($i == @chips_detected) {
push @chips_detected, { driver => $chipdriver,
detected => [],
misdetected => [] };
}
$new_detected_ref = $chips_detected[$i]->{detected};
$new_misdetected_ref = $chips_detected[$i]->{misdetected};
# Now, we are looking for aliases. An alias can only be the same chiptype.
# If an alias is found in the misdetected list, we add the new information
# and terminate this function. If it is found in the detected list, we
# still have to check whether another chip has claimed this ISA address.
# So we remove the old entry from the detected list and put it in datahash.
# Misdetected alias detection:
for ($i = 0; $i < @$new_misdetected_ref; $i++) {
if (exists $new_misdetected_ref->[$i]->{i2c_addr} and
not exists $new_misdetected_ref->[$i]->{isa_addr} and
defined $alias_detect and
$new_misdetected_ref->[$i]->{chipname} eq $datahash->{chipname}) {
open(local *FILE, "$dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}") or
print("Can't open $dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"),
next;
binmode FILE;
i2c_set_slave_addr \*FILE,$new_misdetected_ref->[$i]->{i2c_addr} or
print("Can't set I2C address for ",
"$dev_i2c$new_misdetected_ref->[$i]->{i2c_devnr}?!?\n"),
next;
if (&$alias_detect ($datahash->{isa_addr},\*FILE,
$new_misdetected_ref->[$i]->{i2c_addr})) {
$new_misdetected_ref->[$i]->{isa_addr} = $datahash->{isa_addr};
return $new_misdetected_ref->[$i];
}
}
}
# Detected alias detection:
for ($i = 0; $i < @$new_detected_ref; $i++) {
if (exists $new_detected_ref->[$i]->{i2c_addr} and
not exists $new_detected_ref->[$i]->{isa_addr} and
defined $alias_detect and
$new_detected_ref->[$i]->{chipname} eq $datahash->{chipname}) {
open(local *FILE, "$dev_i2c$new_detected_ref->[$i]->{i2c_devnr}") or
print("Can't open $dev_i2c$new_detected_ref->[$i]->{i2c_devnr}?!?\n"),
next;
binmode FILE;
i2c_set_slave_addr \*FILE,$new_detected_ref->[$i]->{i2c_addr} or
print("Can't set I2C address for ",
"$dev_i2c$new_detected_ref->[$i]->{i2c_devnr}?!?\n"),
next;
if (&$alias_detect ($datahash->{isa_addr},\*FILE,
$new_detected_ref->[$i]->{i2c_addr})) {
$new_detected_ref->[$i]->{isa_addr} = $datahash->{isa_addr};
($datahash) = splice (@$new_detected_ref, $i, 1);
$isalias=1;
last;
}
}
}
# Find out whether our new entry should go into the detected or the
# misdetected list. We only compare main isa_addr here, of course.
# (Khali 2004-05-12) If the driver is the same, the "misdetected"
# entry is simply deleted; same we do for I2C chips.
foreach $main_entry (@chips_detected) {
$detected_ref = $main_entry->{detected};
$misdetected_ref = $main_entry->{misdetected};
for ($i = 0; $i < @{$main_entry->{detected}}; $i++) {
if (exists $detected_ref->[$i]->{isa_addr} and
$detected_ref->[$i]->{isa_addr} == $datahash->{isa_addr}) {
if ($detected_ref->[$i]->{conf} >= $datahash->{conf}) {
push @$new_misdetected_ref, $datahash
unless $main_entry->{driver} eq $chipdriver;
} else {
push @$misdetected_ref,$detected_ref->[$i]
unless $main_entry->{driver} eq $chipdriver;
splice @$detected_ref, $i,1;
push @$new_detected_ref, $datahash;
}
if ($isalias) {
return $datahash;
} else {
return 0;
}
}
}
}
# Not found? OK, put it in the detected list
push @$new_detected_ref, $datahash;
if ($isalias) {
return $datahash;
} else {
return 0;
}
}
# $_[0]: The number of the adapter to scan
# $_[1]: The name of the adapter, as appearing in /proc/bus/i2c
# $_[2]: The driver of the adapter
# @_[3]: Addresses not to scan (array reference)
sub scan_adapter
{
my ($adapter_nr, $adapter_name, $adapter_driver, $not_to_scan) = @_;
my ($funcs, $chip, $addr, $conf, @chips, $new_hash, $other_addr);
# As we modify it, we need a copy
my @not_to_scan = @$not_to_scan;
open(local *FILE, "$dev_i2c$adapter_nr") or
(print "Can't open $dev_i2c$adapter_nr\n"), return;
binmode FILE;
# Can we probe this adapter?
$funcs = i2c_get_funcs(\*FILE);
if ($funcs < 0) {
print "Adapter failed to provide its functionalities, skipping.\n";
return;
}
if (!($funcs & (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_READ_BYTE))) {
print "Adapter cannot be probed, skipping.\n";
return;
}
if (~$funcs & (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_READ_BYTE)) {
print "Adapter doesn't support all probing functions.\n",
"Some addresses won't be probed.\n";
}
# Now scan each address in turn
foreach $addr (0x03..0x77) {
# As the not_to_scan list is sorted, we can check it fast
if (@not_to_scan and $not_to_scan[0] == $addr) {
shift @not_to_scan;
next;
}
if (!i2c_set_slave_addr(\*FILE, $addr)) {
# If the address is busy, in Linux 2.6 we can find out which driver
# is using it, and we assume it is the right one. In Linux 2.4 we
# just give up and warn the user.
my ($device, $driver);
if (defined($sysfs_root)) {
$device = sprintf("$sysfs_root/bus/i2c/devices/\%d-\%04x",
$adapter_nr, $addr);
$driver = sysfs_device_driver($device);
}
if (defined($driver)) {
$new_hash = {
conf => 6, # Arbitrary confidence
i2c_addr => $addr,
chipname => sysfs_device_attribute($device, "name") || "unknown",
i2c_adap => $adapter_name,
i2c_driver => $adapter_driver,
i2c_devnr => $adapter_nr,
};
printf "Client found at address 0x\%02x\n", $addr;
printf "Handled by driver `\%s' (already loaded), chip type `\%s'\n",
$driver, $new_hash->{chipname};
# Only add it to the list if this is something we would have
# detected, else we end up with random i2c chip drivers listed
# (for example media/video drivers.)
if (exists $modules_supported{$driver}) {
add_i2c_to_chips_detected($driver, $new_hash);
} else {
print " (note: this is probably NOT a sensor chip!)\n";
}
} else {
printf("Client at address 0x%02x can not be probed - ".
"unload all client drivers first!\n", $addr);
}
next;
}
next unless i2c_probe(\*FILE, $addr, $funcs);
printf "Client found at address 0x%02x\n",$addr;
foreach $chip (@chip_ids) {
if (exists $chip->{i2c_addrs} and contains $addr, @{$chip->{i2c_addrs}}) {
printf("\%-60s", sprintf("Probing for `\%s'... ", $chip->{name}));
if (($conf,@chips) = &{$chip->{i2c_detect}} (\*FILE ,$addr)) {
print "Success!\n",
" (confidence $conf, driver `$chip->{driver}')";
if (@chips) {
print ", other addresses:";
@chips = sort @chips;
foreach $other_addr (sort @chips) {
printf(" 0x%02x",$other_addr);
}
}
printf "\n";
$new_hash = { conf => $conf,
i2c_addr => $addr,
chipname => $chip->{name},
i2c_adap => $adapter_name,
i2c_driver => $adapter_driver,
i2c_devnr => $adapter_nr,
};
if (@chips) {
my @chips_copy = @chips;
$new_hash->{i2c_sub_addrs} = \@chips_copy;
}
add_i2c_to_chips_detected $chip->{driver}, $new_hash;
} else {
print "No\n";
}
}
}
}
}
sub scan_isa_bus
{
my ($chip,$addr,$conf);
foreach $chip (@chip_ids) {
next if not exists $chip->{isa_addrs} or not exists $chip->{isa_detect};
foreach $addr (@{$chip->{isa_addrs}}) {
printf("\%-60s", sprintf("Probing for `\%s'\%s... ", $chip->{name},
$addr ? sprintf(" at 0x\%x", $addr) : ''));
$conf = &{$chip->{isa_detect}} ($addr);
print("No\n"), next if not defined $conf;
print "Success!\n";
printf " (confidence %d, driver `%s')\n", $conf, $chip->{driver};
my $new_hash = { conf => $conf,
isa_addr => $addr,
chipname => $chip->{name}
};
$new_hash = add_isa_to_chips_detected $chip->{alias_detect},$chip->{driver},
$new_hash;
if ($new_hash) {
printf " Alias of the chip on I2C bus `%s', address 0x%04x\n",
$new_hash->{i2c_adap},$new_hash->{i2c_addr};
}
}
}
}
use vars qw(%superio);
%superio = (
devidreg => 0x20,
logdevreg => 0x07,
actreg => 0x30,
actmask => 0x01,
basereg => 0x60,
);
sub exit_superio
{
my ($addrreg, $datareg) = @_;
# Some chips (SMSC, Winbond) want this
outb($addrreg, 0xaa);
# Return to "Wait For Key" state (PNP-ISA spec)
outb($addrreg, 0x02);
outb($datareg, 0x02);
}
# Guess if an unknown Super-I/O chip has sensors
sub guess_superio_ld($$$)
{
my ($addrreg, $datareg, $typical_addr) = @_;
my ($oldldn, $ldn, $addr);
# Save logical device number
outb($addrreg, $superio{logdevreg});
$oldldn = inb($datareg);
for ($ldn = 0; $ldn < 16; $ldn++) {
# Select logical device
outb($addrreg, $superio{logdevreg});
outb($datareg, $ldn);
# Read base I/O address
outb($addrreg, $superio{basereg});
$addr = inb($datareg) << 8;
outb($addrreg, $superio{basereg} + 1);
$addr |= inb($datareg);
next unless ($addr & 0xfff8) == $typical_addr;
printf " (logical device \%X has address 0x\%x, could be sensors)\n",
$ldn, $addr;
last;
}
# Be nice, restore original logical device
outb($addrreg, $superio{logdevreg});
outb($datareg, $oldldn);
}
sub probe_superio($$$)
{
my ($addrreg, $datareg, $chip) = @_;
my ($val, $addr);
printf "\%-60s", "Found `$chip->{name}'";
# Does it have hardware monitoring capabilities?
if (!exists $chip->{driver}) {
print "\n (no information available)\n";
return;
}
if ($chip->{driver} eq "not-a-sensor") {
print "\n (no hardware monitoring capabilities)\n";
return;
}
# Switch to the sensor logical device
outb($addrreg, $superio{logdevreg});
outb($datareg, $chip->{logdev});
# Check the activation register
outb($addrreg, $superio{actreg});
$val = inb($datareg);
if (!($val & $superio{actmask})) {
print "\n (but not activated)\n";
return;
}
# Get the IO base register
outb($addrreg, $superio{basereg});
$addr = inb($datareg);
outb($addrreg, $superio{basereg} + 1);
$addr = ($addr << 8) | inb($datareg);
if ($addr == 0) {
print "\n (but no address specified)\n";
return;
}
print "Success!\n";
printf " (address 0x\%x, driver `%s')\n", $addr, $chip->{driver};
my $new_hash = { conf => 9,
isa_addr => $addr,
chipname => $chip->{name}
};
add_isa_to_chips_detected $chip->{alias_detect},$chip->{driver},
$new_hash;
}
# The following are taken from the PNP ISA spec (so it's supposed
# to be common to all Super I/0 chips):
# devidreg: The device ID register(s)
# logdevreg: The logical device register
# actreg: The activation register within the logical device
# actmask: The activation bit in the activation register
# basereg: The I/O base register within the logical device
sub scan_superio
{
my ($addrreg, $datareg) = @_;
my ($val, $found);
printf("Probing for Super-I/O at 0x\%x/0x\%x\n", $addrreg, $datareg);
FAMILY:
foreach my $family (@superio_ids) {
printf("\%-60s", "Trying family `$family->{family}'... ");
# write the password
foreach $val (@{$family->{enter}->{$addrreg}}) {
outb($addrreg, $val);
}
# did it work?
outb($addrreg, $superio{devidreg});
$val = inb($datareg);
outb($addrreg, $superio{devidreg} + 1);
$val = ($val << 8) | inb($datareg);
if ($val == 0x0000 || $val == 0xffff) {
print "No\n";
next FAMILY;
}
print "Yes\n";
$found = 0;
foreach my $chip (@{$family->{chips}}) {
if (($chip->{devid} > 0xff && ($val & ($chip->{devid_mask} || 0xffff)) == $chip->{devid})
|| ($chip->{devid} <= 0xff && ($val >> 8) == $chip->{devid})) {
probe_superio($addrreg, $datareg, $chip);
$found++;
}
}
if (!$found) {
printf("Found unknown chip with ID 0x%04x\n", $val);
# Guess if a logical device could correspond to sensors
guess_superio_ld($addrreg, $datareg, $family->{guess})
if defined $family->{guess};
}
exit_superio($addrreg, $datareg);
}
}
##################
# CHIP DETECTION #
##################
# This routine allows you to select which chips are optionally added to the
# chip detection list. The most common use is to allow for different chip
# detection/drivers based on different linux kernels
# This routine follows the pattern of the SiS adapter special cases
sub chip_special_cases
{
# Based on the kernel, add the appropriate chip structure to the
# chip_ids detection list
if (kernel_version_at_least(2, 6, 0)) {
push @chip_ids, $chip_kern26_w83791d;
} else {
push @chip_ids, $chip_kern24_w83791d;
}
}
# Each function returns a confidence value. The higher this value, the more
# sure we are about this chip. A Winbond W83781D, for example, will be
# detected as a LM78 too; but as the Winbond detection has a higher confidence
# factor, you should identify it as a Winbond.
# Each function returns a list. The first element is the confidence value;
# Each element after it is an SMBus address. In this way, we can detect
# chips with several SMBus addresses. The SMBus address for which the
# function was called is never returned.
# If there are devices which get confused if they are only read from, then
# this program will surely confuse them. But we guarantee never to write to
# any of these devices.
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, (7) if detected.
# Registers used: 0x58
sub mtp008_detect
{
my ($file,$addr) = @_;
return if (i2c_smbus_read_byte_data($file,0x58)) != 0xac;
return (8);
}
# $_[0]: Chip to detect (0 = LM78, 1 = LM78-J, 2 = LM79)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, (6) if detected.
# Registers used:
# 0x40: Configuration
# 0x48: Full I2C Address
# 0x49: Device ID
# Note that this function is always called through a closure, so the
# arguments are shifted by one place.
sub lm78_detect
{
my $reg;
my ($chip,$file,$addr) = @_;
return unless i2c_smbus_read_byte_data($file,0x48) == $addr;
return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00;
$reg = i2c_smbus_read_byte_data($file,0x49);
return unless ($chip == 0 and ($reg == 0x00 or $reg == 0x20)) or
($chip == 1 and $reg == 0x40) or
($chip == 2 and ($reg & 0xfe) == 0xc0);
return (6);
}
# $_[0]: Chip to detect (0 = LM78, 1 = LM78-J, 2 = LM79)
# $_[1]: Address
# Returns: undef if not detected, 6 if detected.
# Note: Only address 0x290 is scanned at this moment.
sub lm78_isa_detect
{
my ($chip,$addr) = @_ ;
my $val = inb ($addr + 1);
return if inb ($addr + 2) != $val or inb ($addr + 3) != $val or
inb ($addr + 7) != $val;
$val = inb($addr + 5) & 0x7f;
outb($addr + 5, ~$val & 0xff);
if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) {
outb($addr+5,$val);
return;
}
my $readproc = sub { isa_read_byte $addr + 5, $addr + 6, @_ };
return unless (&$readproc(0x40) & 0x80) == 0x00;
my $reg = &$readproc(0x49);
return unless ($chip == 0 and ($reg == 0x00 or $reg == 0x20)) or
($chip == 1 and $reg == 0x40) or
($chip == 2 and ($reg & 0xfe) == 0xc0);
# Explicitely prevent misdetection of Winbond chips
$reg = &$readproc(0x4f);
return if $reg == 0xa3 || $reg == 0x5c;
# Explicitely prevent misdetection of ITE chips
$reg = &$readproc(0x58);
return if $reg == 0x90;
return 6;
}
# $_[0]: Chip to detect (0 = LM78, 1 = LM78-J, 2 = LM79)
# $_[1]: ISA address
# $_[2]: I2C file handle
# $_[3]: I2C address
sub lm78_alias_detect
{
my ($chip,$isa_addr,$file,$i2c_addr) = @_;
my $i;
my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_ };
return 0 unless &$readproc(0x48) == $i2c_addr;
for ($i = 0x2b; $i <= 0x3d; $i ++) {
return 0 unless &$readproc($i) == i2c_smbus_read_byte_data($file,$i);
}
return 1;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, 3 or 6 if detected;
# 6 means that the temperatures make sense;
# 3 means that the temperatures look strange;
# Registers used:
# 0x00: Temperature
# 0x01: Configuration
# 0x02: Hysteresis
# 0x03: Overtemperature Shutdown
# 0x04-0x07: No registers
# The first detection step is based on the fact that the LM75 has only
# four registers, and cycles addresses over 8-byte boundaries. We use the
# 0x04-0x07 addresses (unused) to improve the reliability. These are not
# real registers and will always return the last returned value. This isn't
# documented.
# Note that register 0x00 may change, so we can't use the modulo trick on it.
sub lm75_detect
{
my $i;
my ($file,$addr) = @_;
my $cur = i2c_smbus_read_word_data($file,0x00);
my $cur_varies = 0;
my $conf = i2c_smbus_read_byte_data($file,0x01);
my $hyst = i2c_smbus_read_word_data($file,0x02);
return if i2c_smbus_read_word_data($file,0x04) != $hyst;
return if i2c_smbus_read_word_data($file,0x05) != $hyst;
return if i2c_smbus_read_word_data($file,0x06) != $hyst;
return if i2c_smbus_read_word_data($file,0x07) != $hyst;
my $os = i2c_smbus_read_word_data($file,0x03);
return if i2c_smbus_read_word_data($file,0x04) != $os;
return if i2c_smbus_read_word_data($file,0x05) != $os;
return if i2c_smbus_read_word_data($file,0x06) != $os;
return if i2c_smbus_read_word_data($file,0x07) != $os;
for ($i = 0x00; $i < 0xff; $i += 8) {
return if i2c_smbus_read_byte_data($file, $i + 0x01) != $conf;
return if i2c_smbus_read_word_data($file, $i + 0x02) != $hyst;
return if i2c_smbus_read_word_data($file, $i + 0x04) != $hyst;
return if i2c_smbus_read_word_data($file, $i + 0x05) != $hyst;
return if i2c_smbus_read_word_data($file, $i + 0x06) != $hyst;
return if i2c_smbus_read_word_data($file, $i + 0x07) != $hyst;
return if i2c_smbus_read_word_data($file, $i + 0x03) != $os;
return if i2c_smbus_read_word_data($file, $i + 0x04) != $os;
return if i2c_smbus_read_word_data($file, $i + 0x05) != $os;
return if i2c_smbus_read_word_data($file, $i + 0x06) != $os;
return if i2c_smbus_read_word_data($file, $i + 0x07) != $os;
$cur_varies = 1
if (! $cur_varies) and
i2c_smbus_read_word_data($file, $i) != $cur;
}
# All registers hold the same value, obviously a misdetection
return if (! $cur_varies) and $conf == ($cur & 0xff) and $cur == $hyst
and $cur == $os;
$cur = swap_bytes($cur);
$hyst = swap_bytes($hyst);
$os = swap_bytes($os);
# Unused bits
return if ($conf & 0xe0);
$cur = $cur >> 8;
$hyst = $hyst >> 8;
$os = $os >> 8;
# Most probable value ranges
return 6 if $cur <= 100 and ($hyst >= 10 && $hyst <= 125)
and ($os >= 20 && $os <= 127) and $hyst < $os;
return 3;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, 3 or 6 if detected;
# 6 means that the temperatures make sense;
# 3 means that the temperatures look strange;
# Registers used:
# 0x00: Temperature
# 0x01: Configuration
# 0x02: Hysteresis
# 0x03: Overtemperature Shutdown
# 0x04: Low limit
# 0x05: High limit
# 0x04-0x07: No registers
# The first detection step is based on the fact that the LM77 has only
# six registers, and cycles addresses over 8-byte boundaries. We use the
# 0x06-0x07 addresses (unused) to improve the reliability. These are not
# real registers and will always return the last returned value. This isn't
# documented.
# Note that register 0x00 may change, so we can't use the modulo trick on it.
sub lm77_detect
{
my $i;
my ($file,$addr) = @_;
my $cur = i2c_smbus_read_word_data($file,0x00);
my $cur_varies = 0;
my $conf = i2c_smbus_read_byte_data($file,0x01);
my $hyst = i2c_smbus_read_word_data($file,0x02);
my $os = i2c_smbus_read_word_data($file,0x03);
my $low = i2c_smbus_read_word_data($file,0x04);
return if i2c_smbus_read_word_data($file,0x06) != $low;
return if i2c_smbus_read_word_data($file,0x07) != $low;
my $high = i2c_smbus_read_word_data($file,0x05);
return if i2c_smbus_read_word_data($file,0x06) != $high;
return if i2c_smbus_read_word_data($file,0x07) != $high;
for ($i = 0x00; $i < 0xff; $i += 8) {
return if i2c_smbus_read_byte_data($file, $i + 0x01) != $conf;
return if i2c_smbus_read_word_data($file, $i + 0x02) != $hyst;
return if i2c_smbus_read_word_data($file, $i + 0x03) != $os;
return if i2c_smbus_read_word_data($file, $i + 0x04) != $low;
return if i2c_smbus_read_word_data($file, $i + 0x06) != $low;
return if i2c_smbus_read_word_data($file, $i + 0x07) != $low;
return if i2c_smbus_read_word_data($file, $i + 0x05) != $high;
return if i2c_smbus_read_word_data($file, $i + 0x06) != $high;
return if i2c_smbus_read_word_data($file, $i + 0x07) != $high;
$cur_varies = 1
if (! $cur_varies) and
i2c_smbus_read_word_data($file, $i) != $cur;
}
# All registers hold the same value, obviously a misdetection
return if (! $cur_varies) and $conf == ($cur & 0xff) and $cur == $hyst
and $cur == $os and $cur == $low and $cur == $high;
$cur = swap_bytes($cur);
$os = swap_bytes($os);
$hyst = swap_bytes($hyst);
$low = swap_bytes($low);
$high = swap_bytes($high);
# Unused bits
return if ($conf & 0xe0)
or (($cur >> 12) != 0 && ($cur >> 12) != 0xf)
or (($hyst >> 12) != 0 && ($hyst >> 12) != 0xf)
or (($os >> 12) != 0 && ($os >> 12) != 0xf)
or (($low >> 12) != 0 && ($low >> 12) != 0xf)
or (($high >> 12) != 0 && ($high >> 12) != 0xf);
$cur /= 16;
$hyst /= 16;
$os /= 16;
$high /= 16;
$low /= 16;
# Most probable value ranges
return 6 if $cur <= 100 and $hyst <= 40
and ($os >= 20 && $os <= 127) and ($high >= 20 && $high <= 127);
return 3;
}
# $_[0]: Chip to detect (0 = LM92, 1 = LM76, 2 = MAX6633/MAX6634/MAX6635)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, 2 or 4 if detected;
# Registers used:
# 0x01: Configuration (National Semiconductor only)
# 0x02: Hysteresis
# 0x03: Critical Temp
# 0x04: Low Limit
# 0x05: High Limit
# 0x07: Manufacturer ID (LM92 only)
# One detection step is based on the fact that the LM92 and clones have a
# limited number of registers, which cycle modulo 16 address values.
# Note that register 0x00 may change, so we can't use the modulo trick on it.
sub lm92_detect
{
my ($chip, $file, $addr) = @_;
my $conf = i2c_smbus_read_byte_data($file, 0x01);
my $hyst = i2c_smbus_read_word_data($file, 0x02);
my $crit = i2c_smbus_read_word_data($file, 0x03);
my $low = i2c_smbus_read_word_data($file, 0x04);
my $high = i2c_smbus_read_word_data($file, 0x05);
return if $chip == 0
and i2c_smbus_read_word_data($file, 0x07) != 0x0180;
return if ($chip == 0 || $chip == 1)
and ($conf & 0xE0);
for (my $i = 0; $i < 8; $i++) {
return if i2c_smbus_read_byte_data($file, $i*16+0x01) != $conf;
return if i2c_smbus_read_word_data($file, $i*16+0x02) != $hyst;
return if i2c_smbus_read_word_data($file, $i*16+0x03) != $crit;
return if i2c_smbus_read_word_data($file, $i*16+0x04) != $low;
return if i2c_smbus_read_word_data($file, $i*16+0x05) != $high;
}
foreach my $temp ($hyst, $crit, $low, $high) {
return if $chip == 2 and ($temp & 0x7F00);
return if $chip != 2 and ($temp & 0x0700);
}
return 4 if $chip == 0;
return 2;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, 3 if detected
# Registers used:
# 0xAA: Temperature
# 0xA1: High limit
# 0xA2: Low limit
# 0xAC: Configuration
# Detection is weak. We check if bit 4 (NVB) is clear, because it is
# unlikely to be set (would mean that EEPROM is currently being accessed).
# Temperature checkings will hopefully prevent LM75 or other chips from
# being detected as a DS1621.
sub ds1621_detect
{
my $i;
my ($file,$addr) = @_;
my $temp = i2c_smbus_read_word_data($file,0xAA);
my $high = i2c_smbus_read_word_data($file,0xA1);
my $low = i2c_smbus_read_word_data($file,0xA2);
return if ($temp | $high | $low) & 0x7F00;
my $conf = i2c_smbus_read_byte_data($file,0xAC);
return if ($temp == 0 && $high == 0 && $low == 0 && $conf == 0);
return 3 if ($conf & 0x10) == 0x00;
return;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, 1 to 3 if detected.
# Registers used:
# 0x00: Configuration register
# 0x02: Interrupt state register
# 0x2a-0x3d: Limits registers
# This one is easily misdetected since it doesn't provide identification
# registers. So we have to use some tricks:
# - 6-bit addressing, so limits readings modulo 0x40 should be unchanged
# - positive temperature limits
# - limits order correctness
# Hopefully this should limit the rate of false positives, without increasing
# the rate of false negatives.
# Thanks to Lennard Klein for testing on a non-LM80 chip, which was
# previously misdetected, and isn't anymore. For reference, it scored
# a final confidence of 0, and changing from strict limit comparisons
# to loose comparisons did not change the score.
sub lm80_detect
{
my ($i,$reg);
my ($file,$addr) = @_;
return if (i2c_smbus_read_byte_data($file,0x00) & 0x80) != 0;
return if (i2c_smbus_read_byte_data($file,0x02) & 0xc0) != 0;
for ($i = 0x2a; $i <= 0x3d; $i++) {
$reg = i2c_smbus_read_byte_data($file,$i);
return if i2c_smbus_read_byte_data($file,$i+0x40) != $reg;
return if i2c_smbus_read_byte_data($file,$i+0x80) != $reg;
return if i2c_smbus_read_byte_data($file,$i+0xc0) != $reg;
}
# Refine a bit by checking wether limits are in the correct order
# (min<max for voltages, hyst<max for temperature). Since it is still
# possible that the chip is an LM80 with limits not properly set,
# a few "errors" are tolerated.
my $confidence = 0;
for ($i = 0x2a; $i <= 0x3a; $i++) {
$confidence++
if i2c_smbus_read_byte_data($file,$i) < i2c_smbus_read_byte_data($file,$i+1);
}
# hot temp<OS temp
$confidence++
if i2c_smbus_read_byte_data($file,0x38) < i2c_smbus_read_byte_data($file,0x3a);
# Negative temperature limits are unlikely.
for ($i = 0x3a; $i <= 0x3d; $i++) {
$confidence++ if (i2c_smbus_read_byte_data($file,$i) & 0x80) == 0;
}
# $confidence is between 0 and 14
$confidence = ($confidence >> 1) - 4;
# $confidence is now between -4 and 3
return unless $confidence > 0;
return $confidence;
}
# $_[0]: Chip to detect
# (0 = LM82/LM83)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, 4 to 8 if detected.
# Registers used:
# 0x02: Status 1
# 0x03: Configuration
# 0x04: Company ID of LM84
# 0x35: Status 2
# 0xfe: Manufacturer ID
# 0xff: Chip ID / die revision
# We can use the LM84 Company ID register because the LM83 and the LM82 are
# compatible with the LM84.
# The LM83 chip ID is missing from the datasheet and was contributed by
# Magnus Forsstrom: 0x03.
# At least some revisions of the LM82 seem to be repackaged LM83, so they
# have the same chip ID, and temp2/temp4 will be stuck in "OPEN" state.
# For this reason, we don't even try to distinguish between both chips.
# Thanks to Ben Gardner for reporting.
sub lm83_detect
{
my ($chip, $file) = @_;
return if i2c_smbus_read_byte_data($file,0xfe) != 0x01;
my $chipid = i2c_smbus_read_byte_data($file,0xff);
return if $chipid != 0x01 && $chipid != 0x03;
my $confidence = 4;
$confidence++
if (i2c_smbus_read_byte_data($file,0x02) & 0xa8) == 0x00;
$confidence++
if (i2c_smbus_read_byte_data($file,0x03) & 0x41) == 0x00;
$confidence++
if i2c_smbus_read_byte_data($file,0x04) == 0x00;
$confidence++
if (i2c_smbus_read_byte_data($file,0x35) & 0x48) == 0x00;
return $confidence;
}
# $_[0]: Chip to detect
# (0 = LM90, 1=LM89/LM99, 2=LM86, 3=ADM1032, 4=MAX6657/MAX6658/MAX6659,
# 5 = ADT7461)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, 4, 6 or 8 if detected.
# The Maxim chips have a low confidence value (4)
# because they don't have a die revision register.
# Registers used:
# 0x03: Configuration
# 0x04: Conversion rate
# 0xfe: Manufacturer ID
# 0xff: Chip ID / die revision
sub lm90_detect
{
my ($chip, $file, $addr) = @_;
my $mid = i2c_smbus_read_byte_data($file, 0xfe);
my $cid = i2c_smbus_read_byte_data($file, 0xff);
my $conf = i2c_smbus_read_byte_data($file, 0x03);
my $rate = i2c_smbus_read_byte_data($file, 0x04);
if ($chip == 0) {
return if ($conf & 0x2a) != 0;
return if $rate > 0x09;
return if $mid != 0x01; # National Semiconductor
return 8 if $cid == 0x21; # LM90
return 6 if ($cid & 0x0f) == 0x20;
}
if ($chip == 1) {
return if ($conf & 0x2a) != 0;
return if $rate > 0x09;
return if $mid != 0x01; # National Semiconductor
return 8 if $addr == 0x4c and $cid == 0x31; # LM89/LM99
return 8 if $addr == 0x4d and $cid == 0x34; # LM89-1/LM99-1
return 6 if ($cid & 0x0f) == 0x30;
}
if ($chip == 2) {
return if ($conf & 0x2a) != 0;
return if $rate > 0x09;
return if $mid != 0x01; # National Semiconductor
return 8 if $cid == 0x11; # LM86
return 6 if ($cid & 0xf0) == 0x10;
}
if ($chip == 3) {
return if ($conf & 0x3f) != 0;
return if $rate > 0x0a;
return if $mid != 0x41; # Analog Devices
return 8 if ($cid & 0xf0) == 0x40; # ADM1032
}
if ($chip == 4) {
return if ($conf & 0x1f) != ($mid & 0x0f); # No low nibble,
# returns previous low nibble
return if $rate > 0x09;
return if $mid != 0x4d; # Maxim
return if $cid != 0x4d; # No register, returns previous value
return 4;
}
if ($chip == 5) {
return if ($conf & 0x1b) != 0;
return if $rate > 0x0a;
return if $mid != 0x41; # Analog Devices
return 8 if $cid == 0x61; # ADT7461
}
return;
}
# $_[0]: Chip to detect
# (1 = LM63, 2 = F75363SG)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address (unused)
# Returns: undef if not detected, 8 if detected.
# Registers used:
# 0xfe: Manufacturer ID
# 0xff: Chip ID / die revision
# 0x03: Configuration (two or three unused bits)
# 0x16: Alert mask (two or three unused bits)
# 0x03-0x0e: Mirrored registers (five pairs)
sub lm63_detect
{
my ($chip, $file, $addr) = @_;
my $mid = i2c_smbus_read_byte_data($file, 0xfe);
my $cid = i2c_smbus_read_byte_data($file, 0xff);
my $conf = i2c_smbus_read_byte_data($file, 0x03);
my $mask = i2c_smbus_read_byte_data($file, 0x16);
if ($chip == 1) {
return if $mid != 0x01 # National Semiconductor
|| $cid != 0x41; # LM63
return if ($conf & 0x18) != 0x00
|| ($mask & 0xa4) != 0xa4;
} elsif ($chip == 2) {
return if $mid != 0x23 # Fintek
|| $cid != 0x20; # F75363SG
return if ($conf & 0x1a) != 0x00
|| ($mask & 0x84) != 0x00;
}
# For compatibility with the LM86, some registers are mirrored
# to alternative locations
return if $conf != i2c_smbus_read_byte_data($file, 0x09);
foreach my $i (0x04, 0x05, 0x07, 0x08) {
return if i2c_smbus_read_byte_data($file, $i)
!= i2c_smbus_read_byte_data($file, $i+6);
}
return 8;
}
# $_[0]: Chip to detect
# (0 = ADM1029)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, 3 to 9 if detected.
# Registers used:
# 0x02, 0x03: Fan support
# 0x05: GPIO config
# 0x07, 0x08, 0x09: Fan config
# 0x0d: Manufacturer ID
# 0x0e: Chip ID / die revision
sub adm1029_detect
{
my ($chip, $file, $addr) = @_;
my $mid = i2c_smbus_read_byte_data($file, 0x0d);
my $cid = i2c_smbus_read_byte_data($file, 0x0e);
my $fansc = i2c_smbus_read_byte_data($file, 0x02);
my $fanss = i2c_smbus_read_byte_data($file, 0x03);
my $gpio = i2c_smbus_read_byte_data($file, 0x05);
my $fanas = i2c_smbus_read_byte_data($file, 0x07);
my $fanhps = i2c_smbus_read_byte_data($file, 0x08);
my $fanfs = i2c_smbus_read_byte_data($file, 0x09);
my $confidence = 3;
if ($chip == 0) {
return if $mid != 0x41; # Analog Devices
$confidence++ if ($cid & 0xF0) == 0x00; # ADM1029
$confidence+=2 if ($fansc & 0xFC) == 0x00
&& ($fanss & 0xFC) == 0x00;
$confidence+=2 if ($fanas & 0xFC) == 0x00
&& ($fanhps & 0xFC) == 0x00
&& ($fanfs & 0xFC) == 0x00;
$confidence++ if ($gpio & 0x80) == 0x00;
return $confidence;
}
return;
}
# $_[0]: Chip to detect
# (0 = ADM1030, 1=ADM1031)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, 3 to 7 (ADM1031) or 9 (ADM1030)
# if detected.
# Registers used:
# 0x01: Config 2
# 0x03: Status 2
# 0x0d, 0x0e, 0x0f: Temperature offsets
# 0x22: Fan speed config
# 0x3d: Chip ID
# 0x3e: Manufacturer ID
# 0x3f: Die revision
sub adm1031_detect
{
my ($chip, $file, $addr) = @_;
my $mid = i2c_smbus_read_byte_data($file, 0x3e);
my $cid = i2c_smbus_read_byte_data($file, 0x3d);
my $drev = i2c_smbus_read_byte_data($file, 0x3f);
my $conf2 = i2c_smbus_read_byte_data($file, 0x01);
my $stat2 = i2c_smbus_read_byte_data($file, 0x03);
my $fsc = i2c_smbus_read_byte_data($file, 0x22);
my $lto = i2c_smbus_read_byte_data($file, 0x0d);
my $r1to = i2c_smbus_read_byte_data($file, 0x0e);
my $r2to = i2c_smbus_read_byte_data($file, 0x0f);
my $confidence = 3;
if ($chip == 0) {
return if $mid != 0x41; # Analog Devices
return if $cid != 0x30; # ADM1030
$confidence++ if ($drev & 0x70) == 0x00;
$confidence++ if ($conf2 & 0x4A) == 0x00;
$confidence++ if ($stat2 & 0x3F) == 0x00;
$confidence++ if ($fsc & 0xF0) == 0x00;
$confidence++ if ($lto & 0x70) == 0x00;
$confidence++ if ($r1to & 0x70) == 0x00;
return $confidence;
}
if ($chip == 1) {
return if $mid != 0x41; # Analog Devices
return if $cid != 0x31; # ADM1031
$confidence++ if ($drev & 0x70) == 0x00;
$confidence++ if ($lto & 0x70) == 0x00;
$confidence++ if ($r1to & 0x70) == 0x00;
$confidence++ if ($r2to & 0x70) == 0x00;
return $confidence;
}
return;
}
# $_[0]: Chip to detect
# (0 = ADM1033, 1 = ADM1034)
# $_[1]: A reference to the file descriptor to access this chip.
# $_[2]: Address (unused)
# Returns: undef if not detected, 4 or 6 if detected.
# Registers used:
# 0x3d: Chip ID
# 0x3e: Manufacturer ID
# 0x3f: Die revision
sub adm1034_detect
{
my ($chip, $file, $addr) = @_;
my $mid = i2c_smbus_read_byte_data($file, 0x3e);
my $cid = i2c_smbus_read_byte_data($file, 0x3d);
my $drev = i2c_smbus_read_byte_data($file, 0x3f);
if ($chip == 0) {
return if $mid != 0x41; # Analog Devices
return if $cid != 0x33; # ADM1033
return if ($drev & 0xf8) != 0x00;
return 6 if $drev == 0x02;
return 4;
}
if ($chip == 1) {
return if $mid != 0x41; # Analog Devices
return if $cid != 0x34; # ADM1034
return if ($drev & 0xf8) != 0x00;
return 6 if $drev == 0x02;
return 4;
}
return
}
# $_[0]: Chip to detect
# (0 = ADT7467/ADT7468, 1 = ADT7476, 2 = ADT7462, 3 = ADT7466,
# 4 = ADT7470)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, 5 or 7 if detected.
# Registers used:
# 0x3d: Chip ID
# 0x3e: Manufacturer ID
# 0x3f: Die revision
sub adt7467_detect
{
my ($chip, $file, $addr) = @_;
my $mid = i2c_smbus_read_byte_data($file, 0x3e);
my $cid = i2c_smbus_read_byte_data($file, 0x3d);
my $drev = i2c_smbus_read_byte_data($file, 0x3f);
if ($chip == 0) {
return if $mid != 0x41; # Analog Devices
return if $cid != 0x68; # ADT7467
return if ($drev & 0xf0) != 0x70;
return 7 if ($drev == 0x71 || $drev == 0x72);
return 5;
}
if ($chip == 1) {
return if $mid != 0x41; # Analog Devices
return if $cid != 0x76; # ADT7476
return if ($drev & 0xf0) != 0x60;
return 7 if ($drev == 0x69);
return 5;
}
if ($chip == 2) {
return if $mid != 0x41; # Analog Devices
return if $cid != 0x62; # ADT7462
return if ($drev & 0xf0) != 0x00;
return 7 if ($drev == 0x04);
return 5;
}
if ($chip == 3) {
return if $mid != 0x41; # Analog Devices
return if $cid != 0x66; # ADT7466
return if ($drev & 0xf0) != 0x00;
return 7 if ($drev == 0x02);
return 5;
}
if ($chip == 4) {
return if $mid != 0x41; # Analog Devices
return if $cid != 0x70; # ADT7470
return if ($drev & 0xf0) != 0x00;
return 7 if ($drev == 0x00);
return 5;
}
return
}
# $_[0]: Chip to detect
# (0 = ADT7473, 1 = ADT7475)
# $_[1]: A reference to the file descriptor to access this chip.
# $_[2]: Address (unused)
# Returns: undef if not detected, 5 if detected.
# Registers used:
# 0x3d: Chip ID
# 0x3e: Manufacturer ID
sub adt7473_detect
{
my ($chip, $file, $addr) = @_;
my $mid = i2c_smbus_read_byte_data($file, 0x3e);
my $cid = i2c_smbus_read_byte_data($file, 0x3d);
if ($chip == 0) {
return if $mid != 0x41; # Analog Devices
return if $cid != 0x73; # ADT7473
return 5;
}
if ($chip == 1) {
return if $mid != 0x41; # Analog Devices
return if $cid != 0x75; # ADT7475
return 5;
}
return
}
# $_[0]: Vendor to check for
# (0x01 = National Semi, 0x41 = Analog Dev, 0x5c = SMSC)
# $_[1]: A reference to the file descriptor to access this chip.
# #_[2]: Base address.
# Returns: undef if not detected, (7) or (8) if detected.
# Registers used: 0x3e == Vendor register.
# 0x3d == Device ID register (Analog Devices only).
# 0x3f == Version/Stepping register.
# Constants used: 0x01 == National Semiconductor Vendor Id.
# 0x41 == Analog Devices Vendor Id.
# 0x5c == SMSC Vendor Id.
# 0x60 == Version number. The lower 4 stepping
# bits are masked and ignored.
sub lm85_detect
{
my ($vendor,$file,$addr) = @_;
return if (i2c_smbus_read_byte_data($file,0x3e)) != $vendor ;
return if (i2c_smbus_read_byte_data($file,0x3f) & 0xf0) != 0x60;
if ($vendor == 0x41) # Analog Devices
{
return if i2c_smbus_read_byte_data($file, 0x3d) != 0x27;
return (8);
}
return (7);
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, (7) if detected.
# Registers used: 0x3E, 0x3F
# Assume lower 2 bits of reg 0x3F are for revisions.
sub lm87_detect
{
my ($file,$addr) = @_;
return if (i2c_smbus_read_byte_data($file,0x3e)) != 0x02;
return if (i2c_smbus_read_byte_data($file,0x3f) & 0xfc) != 0x04;
return (7);
}
# $_[0]: Chip to detect (0 = W83781D, 1 = W83782D, 2 = W83783S,
# 3 = W83627HF, 4 = AS99127F (rev.1),
# 5 = AS99127F (rev.2), 6 = ASB100, 7 = W83791D,
# 8 = W83792D, 9 = W83627EHF 10 = W83627DHG)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, (8,addr1,addr2) if detected, but only
# if the LM75 chip emulation is enabled.
# Registers used:
# 0x48: Full I2C Address
# 0x4a: I2C addresses of emulated LM75 chips
# 0x4e: Vendor ID byte selection, and bank selection
# 0x4f: Vendor ID
# 0x58: Device ID (only when in bank 0)
# Note: Fails if the W8378xD is not in bank 0!
# Note: Detection overrules a previous LM78 detection
# Note: Asus chips do not have their I2C address at register 0x48?
# AS99127F rev.1 and ASB100 have 0x00, confirmation wanted for
# AS99127F rev.2.
sub w83781d_detect
{
my ($reg1,$reg2,@res);
my ($chip,$file,$addr) = @_;
return unless (i2c_smbus_read_byte_data($file,0x48) == $addr)
or ($chip >= 4 && $chip <= 6);
$reg1 = i2c_smbus_read_byte_data($file,0x4e);
$reg2 = i2c_smbus_read_byte_data($file,0x4f);
if ($chip == 4) { # Asus AS99127F (rev.1)
return unless (($reg1 & 0x80) == 0x00 and $reg2 == 0xc3) or
(($reg1 & 0x80) == 0x80 and $reg2 == 0x12);
} elsif ($chip == 6) { # Asus ASB100
return unless (($reg1 & 0x80) == 0x00 and $reg2 == 0x94) or
(($reg1 & 0x80) == 0x80 and $reg2 == 0x06);
} else { # Winbond and Asus AS99127F (rev.2)
return unless (($reg1 & 0x80) == 0x00 and $reg2 == 0xa3) or
(($reg1 & 0x80) == 0x80 and $reg2 == 0x5c);
}
return unless ($reg1 & 0x07) == 0x00;
$reg1 = i2c_smbus_read_byte_data($file,0x58);
return if $chip == 0 and ($reg1 != 0x10 && $reg1 != 0x11);
return if $chip == 1 and $reg1 != 0x30;
return if $chip == 2 and $reg1 != 0x40;
return if $chip == 3 and $reg1 != 0x21;
return if $chip == 4 and $reg1 != 0x31;
return if $chip == 5 and $reg1 != 0x31;
return if $chip == 6 and $reg1 != 0x31;
return if $chip == 7 and $reg1 != 0x71;
return if $chip == 8 and $reg1 != 0x7a;
return if $chip == 9 and $reg1 != 0xa1;
return if $chip == 10 and $reg1 != 0xa2;
$reg1 = i2c_smbus_read_byte_data($file,0x4a);
# Default address is 0x2d
@res = ($addr != 0x2d) ? (7) : (8);
return @res if $chip == 9; # No subclients
push @res, ($reg1 & 0x07) + 0x48 unless $reg1 & 0x08;
push @res, (($reg1 & 0x70) >> 4) + 0x48 unless ($reg1 & 0x80 or $chip == 2);
return @res;
}
# $_[0]: Chip to detect (0 = W83793)
# $_[1]: A reference to the file descriptor to access this chip.
# $_[2]: Address
# Returns: undef if not detected
# 6 if detected and bank different from 0
# (8,addr1,addr2) if detected, band is 0 and LM75 chip emulation
# is enabled
# Registers used:
# 0x0b: Full I2C Address
# 0x0c: I2C addresses of emulated LM75 chips
# 0x00: Vendor ID byte selection, and bank selection(Bank 0,1,2)
# 0x0d: Vendor ID(Bank 0,1,2)
# 0x0e: Device ID(Bank 0,1,2)
sub w83793_detect
{
my ($bank, $reg, @res);
my ($chip, $file, $addr) = @_;
$bank = i2c_smbus_read_byte_data($file, 0x00);
$reg = i2c_smbus_read_byte_data($file, 0x0d);
return unless (($bank & 0x80) == 0x00 and $reg == 0xa3) or
(($bank & 0x80) == 0x80 and $reg == 0x5c);
$reg = i2c_smbus_read_byte_data($file, 0x0e);
return if $chip == 0 and $reg != 0x7b;
# If bank 0 is selected, we can do more checks
return 6 unless ($bank & 0x07) == 0;
$reg = i2c_smbus_read_byte_data($file, 0x0b);
return unless ($reg == ($addr << 1));
$reg = i2c_smbus_read_byte_data($file, 0x0c);
@res = (8);
push @res, ($reg & 0x07) + 0x48 unless $reg & 0x08;
push @res, (($reg & 0x70) >> 4) + 0x48 unless $reg & 0x80;
return @res;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, 3 if detected
# Registers used:
# 0x48: Full I2C Address
# 0x4e: Vendor ID byte selection
# 0x4f: Vendor ID
# 0x58: Device ID
# Note that the datasheet was useless and this detection routine
# is based on dumps we received from users. Also, the W83781SD is *NOT*
# a hardware monitoring chip as far as we know, but we still want to
# detect it so that people won't keep reporting it as an unknown chip
# we should investigate about.
sub w83791sd_detect
{
my ($file, $addr) = @_;
my ($reg1, $reg2);
return unless (i2c_smbus_read_byte_data($file, 0x48) == $addr);
$reg1 = i2c_smbus_read_byte_data($file, 0x4e);
$reg2 = i2c_smbus_read_byte_data($file, 0x4f);
return unless (!($reg1 & 0x80) && $reg2 == 0xa3)
|| (($reg1 & 0x80) && $reg2 == 0x5c);
$reg1 = i2c_smbus_read_byte_data($file, 0x58);
return unless $reg1 == 0x72;
return 3;
}
# $_[0]: Chip to detect (0 = ASM58, 1 = AS2K129R, 2 = ???)
# $_[1]: A reference to the file descriptor to access this chip
# $_[2]: Address (unused)
# Returns: undef if not detected, 5 if detected
# Registers used:
# 0x4e: Vendor ID high byte
# 0x4f: Vendor ID low byte
# 0x58: Device ID
# Note: The values were given by Alex van Kaam, we don't have datasheets
# to confirm.
sub mozart_detect
{
my ($vid,$dev);
my ($chip,$file,$addr) = @_;
$vid = (i2c_smbus_read_byte_data($file,0x4e) << 8)
+ i2c_smbus_read_byte_data($file,0x4f);
$dev = i2c_smbus_read_byte_data($file,0x58);
return if ($chip == 0) and ($dev != 0x56 || $vid != 0x9436);
return if ($chip == 1) and ($dev != 0x56 || $vid != 0x9406);
return if ($chip == 2) and ($dev != 0x10 || $vid != 0x5ca3);
return 5;
}
# $_[0]: Chip to detect (0 = W83781D, 1 = W83782D, 3 = W83627HF,
# 9 = W83627EHF 10 = W83627DHG)
# $_[1]: ISA address
# $_[2]: I2C file handle
# $_[3]: I2C address
sub w83781d_alias_detect
{
my ($chip,$isa_addr,$file,$i2c_addr) = @_;
my $i;
my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_ };
return 0 unless &$readproc(0x48) == $i2c_addr;
for ($i = 0x2b; $i <= 0x3d; $i ++) {
return 0 unless &$readproc($i) == i2c_smbus_read_byte_data($file,$i);
}
return 1;
}
# $_[0]: Chip to detect (0 = W83781D, 1 = W83782D, 3 = W83627HF)
# $_[1]: Address
# Returns: undef if not detected, (8) if detected.
sub w83781d_isa_detect
{
my ($chip,$addr) = @_ ;
my ($reg1,$reg2);
my $val = inb ($addr + 1);
return if inb ($addr + 2) != $val or inb ($addr + 3) != $val or
inb ($addr + 7) != $val;
$val = inb($addr + 5) & 0x7f;
outb($addr+5, ~$val & 0xff);
if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) {
outb($addr+5,$val);
return;
}
my $read_proc = sub { isa_read_byte $addr + 5, $addr + 6, @_ };
$reg1 = &$read_proc(0x4e);
$reg2 = &$read_proc(0x4f);
return unless (($reg1 & 0x80) == 0x00 and $reg2 == 0xa3) or
(($reg1 & 0x80) == 0x80 and $reg2 == 0x5c);
return unless ($reg1 & 0x07) == 0x00;
$reg1 = &$read_proc(0x58);
return if $chip == 0 and ($reg1 & 0xfe) != 0x10;
return if $chip == 1 and ($reg1 & 0xfe) != 0x30;
return if $chip == 3 and ($reg1 & 0xfe) != 0x20;
return 8;
}
# $_[0]: Chip to detect (0 = Revision 0x00, 1 = Revision 0x80)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, (6) if detected.
# Registers used:
# 0x00: Device ID
# 0x01: Revision ID
# 0x03: Configuration
# Mediocre detection
sub gl518sm_detect
{
my $reg;
my ($chip,$file,$addr) = @_;
return unless i2c_smbus_read_byte_data($file,0x00) == 0x80;
return unless (i2c_smbus_read_byte_data($file,0x03) & 0x80) == 0x00;
$reg = i2c_smbus_read_byte_data($file,0x01);
return unless ($chip == 0 and $reg == 0x00) or
($chip == 1 and $reg == 0x80);
return (6);
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, (5) if detected.
# Registers used:
# 0x00: Device ID
# 0x01: Revision ID
# 0x03: Configuration
# Mediocre detection
sub gl520sm_detect
{
my ($file,$addr) = @_;
return unless i2c_smbus_read_byte_data($file,0x00) == 0x20;
return unless (i2c_smbus_read_byte_data($file,0x03) & 0x80) == 0x00;
# The line below must be better checked before I dare to use it.
# return unless i2c_smbus_read_byte_data($file,0x01) == 0x00;
return (5);
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, (5) if detected.
# Registers used:
# 0x00: Device ID
# Mediocre detection
sub gl525sm_detect
{
my ($file,$addr) = @_;
return unless i2c_smbus_read_byte_data($file,0x00) == 0x25;
return (5);
}
# $_[0]: Chip to detect (0 = ADM9240, 1 = DS1780, 2 = LM81)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, (7) if detected.
# Registers used:
# 0x3e: Company ID
# 0x40: Configuration
# 0x48: Full I2C Address
# Note: Detection overrules a previous LM78 detection
sub adm9240_detect
{
my $reg;
my ($chip, $file,$addr) = @_;
$reg = i2c_smbus_read_byte_data($file,0x3e);
return unless ($chip == 0 and $reg == 0x23) or
($chip == 1 and $reg == 0xda) or
($chip == 2 and $reg == 0x01);
return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00;
return unless i2c_smbus_read_byte_data($file,0x48) == $addr;
return (7);
}
# $_[0]: Chip to detect (0 = ADM1022, 1 = THMC50, 2 = ADM1028)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, (8) if detected.
# Registers used:
# 0x3e: Company ID
# 0x3f: Revision
# 0x40: Configuration
# Note: Detection overrules a previous LM78 or ADM9240 detection
sub adm1022_detect
{
my $reg;
my ($chip, $file,$addr) = @_;
$reg = i2c_smbus_read_byte_data($file,0x3e);
return unless ($chip == 0 and $reg == 0x41) or
($chip == 1 and $reg == 0x49) or
($chip == 2 and $reg == 0x41);
return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00;
$reg = i2c_smbus_read_byte_data($file, 0x3f);
return unless ($reg & 0xc0) == 0xc0;
return if $chip == 0 and ($reg & 0xc0) != 0xc0;
return if $chip == 2 and ($reg & 0xc0) == 0xc0;
return (8);
}
# $_[0]: Chip to detect (0 = ADM1025, 1 = NE1619)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, (8) if detected.
# Registers used:
# 0x3e: Company ID
# 0x3f: Revision
# 0x40: Configuration
# 0x41: Status 1
# 0x42: Status 2
# Note: Detection overrules a previous LM78 or ADM9240 detection
sub adm1025_detect
{
my $reg;
my ($chip, $file,$addr) = @_;
$reg = i2c_smbus_read_byte_data($file,0x3e);
return if ($chip == 0) and ($reg != 0x41);
return if ($chip == 1) and ($reg != 0xA1);
return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00;
return unless (i2c_smbus_read_byte_data($file,0x41) & 0xC0) == 0x00;
return unless (i2c_smbus_read_byte_data($file,0x42) & 0xBC) == 0x00;
return unless (i2c_smbus_read_byte_data($file,0x3f) & 0xf0) == 0x20;
return (8);
}
# $_[0]: Chip to detect (0 = ADM1026)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, (8) if detected.
# Registers used:
# 0x16: Company ID
# 0x17: Revision
sub adm1026_detect
{
my $reg;
my ($chip, $file,$addr) = @_;
$reg = i2c_smbus_read_byte_data($file,0x16);
return unless ($reg == 0x41);
return unless (i2c_smbus_read_byte_data($file,0x17) & 0xf0) == 0x40;
return (8);
}
# $_[0]: Chip to detect (0 = ADM1024)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, (8) if detected.
# Registers used:
# 0x3e: Company ID
# 0x3f: Revision
# 0x40: Configuration
sub adm1024_detect
{
my $reg;
my ($chip, $file,$addr) = @_;
$reg = i2c_smbus_read_byte_data($file,0x3e);
return unless ($reg == 0x41);
return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00;
return unless (i2c_smbus_read_byte_data($file,0x3f) & 0xf0) == 0x10;
return (8);
}
# $_[0]: Chip to detect
# (0 = ADM1021, 1 = ADM1021A/ADM1023, 2 = MAX1617, 3 = MAX1617A, 4 = THMC10,
# 5 = LM84, 6 = GL523, 7 = MC1066)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, 3 if simply detected, 5 if detected and
# manufacturer ID matches, 7 if detected and manufacturer ID and
# revision match
# Registers used:
# 0x04: Company ID (LM84 only)
# 0xfe: Company ID (all but LM84 and MAX1617)
# 0xff: Revision (ADM1021, ADM1021A/ADM1023 and MAX1617A)
# 0x02: Status
# 0x03: Configuration
# 0x04: Conversion rate
# 0x00-0x01, 0x05-0x08: Temperatures (MAX1617 and LM84)
# Note: Especially the MAX1617 has very bad detection; we give it a low
# confidence value.
sub adm1021_detect
{
my ($chip, $file, $addr) = @_;
my $man_id = i2c_smbus_read_byte_data($file, 0xfe);
my $rev = i2c_smbus_read_byte_data($file, 0xff);
my $conf = i2c_smbus_read_byte_data($file, 0x03);
my $status = i2c_smbus_read_byte_data($file, 0x02);
my $convrate = i2c_smbus_read_byte_data($file, 0x04);
# Check manufacturer IDs and product revisions when available
return if $chip == 0 and $man_id != 0x41 ||
($rev & 0xf0) != 0x00;
return if $chip == 1 and $man_id != 0x41 ||
($rev & 0xf0) != 0x30;
return if $chip == 3 and $man_id != 0x4d ||
$rev != 0x01;
return if $chip == 4 and $man_id != 0x49;
return if $chip == 5 and $convrate != 0x00;
return if $chip == 6 and $man_id != 0x23;
return if $chip == 7 and $man_id != 0x54;
# Check unused bits
if ($chip == 5) # LM84
{
return if ($status & 0xab) != 0;
return if ($conf & 0x7f) != 0;
}
else
{
return if ($status & 0x03) != 0;
return if ($conf & 0x3f) != 0;
return if ($convrate & 0xf8) != 0;
}
# Extra checks for MAX1617 and LM84, since those are often misdetected
# We verify several assertions (6 for the MAX1617, 4 for the LM84) and
# discard the chip if any fail. Note that these checks are not done
# by the adm1021 driver.
if ($chip == 2 || $chip == 5)
{
my $lte = i2c_smbus_read_byte_data($file, 0x00);
my $rte = i2c_smbus_read_byte_data($file, 0x01);
my $lhi = i2c_smbus_read_byte_data($file, 0x05);
my $rhi = i2c_smbus_read_byte_data($file, 0x07);
my $llo = i2c_smbus_read_byte_data($file, 0x06);
my $rlo = i2c_smbus_read_byte_data($file, 0x08);
# If all registers hold the same value, it has to be a misdetection
return if $lte == $rte and $lte == $lhi and $lte == $rhi
and $lte == $llo and $lte == $rlo;
# Negative temperatures
return if ($lte & 0x80) or ($rte & 0x80);
# Negative high limits
return if ($lhi & 0x80) or ($rhi & 0x80);
# Low limits over high limits
if ($chip != 5) # LM84 doesn't have low limits
{
$llo-=256 if ($llo & 0x80);
$rlo-=256 if ($rlo & 0x80);
return if ($llo > $lhi) or ($rlo > $rhi);
}
}
return 3 if ($chip == 2) or ($chip == 5);
return 7 if $chip <= 3;
return 5;
}
# $_[0]: Chip to detect
# (0 = MAX1619)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, 7 if detected
# Registers used:
# 0xfe: Company ID
# 0xff: Device ID
# 0x02: Status
# 0x03: Configuration
# 0x04: Conversion rate
sub max1619_detect
{
my ($chip, $file, $addr) = @_;
my $man_id = i2c_smbus_read_byte_data($file, 0xfe);
my $dev_id = i2c_smbus_read_byte_data($file, 0xff);
my $conf = i2c_smbus_read_byte_data($file, 0x03);
my $status = i2c_smbus_read_byte_data($file, 0x02);
my $convrate = i2c_smbus_read_byte_data($file, 0x04);
return if $man_id != 0x4D
or $dev_id != 0x04
or ($conf & 0x03)
or ($status & 0x61)
or $convrate >= 8;
return 7;
}
# $_[0]: A reference to the file descriptor to access this chip.
# $_[1]: Address (unused)
# Returns: undef if not detected, 6 if detected.
# Registers used:
# 0x28: User ID
# 0x29: User ID2
# 0x2A: Version ID
sub ite_overclock_detect
{
my ($file, $addr) = @_;
my $uid1 = i2c_smbus_read_byte_data($file, 0x28);
my $uid2 = i2c_smbus_read_byte_data($file, 0x29);
return if $uid1 != 0x83
|| $uid2 != 0x12;
return 6;
}
# $_[0]: Chip to detect (0 = IT8712F)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, 7 or 8 if detected (tops LM78).
# Registers used:
# 0x00: Configuration
# 0x48: Full I2C Address
# 0x58: Mfr ID
# 0x5b: Device ID (not on IT8705)
# Note that this function is always called through a closure, so the
# arguments are shifted by one place.
sub ite_detect
{
my $reg;
my ($chip,$file,$addr) = @_;
return unless i2c_smbus_read_byte_data($file,0x48) == $addr;
return unless (i2c_smbus_read_byte_data($file, 0x00) & 0x90) == 0x10;
return unless i2c_smbus_read_byte_data($file,0x58) == 0x90;
return if $chip == 0 and i2c_smbus_read_byte_data($file,0x5b) != 0x12;
return (7 + ($addr == 0x2d));
}
# $_[0]: Chip to detect (0 = IT8712F)
# $_[1]: ISA address
# $_[2]: I2C file handle
# $_[3]: I2C address
sub ite_alias_detect
{
my ($chip,$isa_addr,$file,$i2c_addr) = @_;
my $i;
my $readproc = sub { isa_read_byte $isa_addr + 5, $isa_addr + 6, @_ };
return 0 unless &$readproc(0x48) == $i2c_addr;
for ($i = 0x30; $i <= 0x45; $i++) {
return 0 unless &$readproc($i) == i2c_smbus_read_byte_data($file,$i);
}
return 1;
}
# $_[0]: Chip to detect (0 = SPD EEPROM, 1 = Sony Vaio EEPROM,
# 2 = SPD EEPROM with Software Write Protect)
# $_[1]: A reference to the file descriptor to access this chip
# $_[2]: Address
# Returns: 8 for a memory eeprom (9 if write-protect register found),
# 4 to 9 for a Sony Vaio eeprom,
# 1 for an unknown eeprom (2 if write-protect register found)
# Registers used:
# 0-63: SPD Data and Checksum
# 0x80-0x83: Sony Vaio Data ("PCG-")
# 0xe2, 0xe5, 0xe8, 0xeb, Oxee: Sony Vaio Timestamp constant bytes.
# 0x1a-0x1c: Sony Vaio MAC address
# This detection function is a bit tricky; this is to workaround
# wrong misdetection messages that would else arise.
sub eeprom_detect
{
my ($chip,$file,$addr) = @_;
my $checksum = 0;
# Check the checksum for validity (works for most DIMMs and RIMMs)
if ($chip != 1) {
for (my $i = 0; $i <= 62; $i ++) {
$checksum += i2c_smbus_read_byte_data($file,$i);
}
$checksum &= 255;
$checksum -= i2c_smbus_read_byte_data($file,63);
}
if ($chip == 0) {
if($checksum == 0) {
return 8;
} else {
return 1;
}
}
if ($chip == 2) {
# check for 'shadow' write-protect register at 0x30-0x37
# could be dangerous
i2c_set_slave_addr($file,$addr - 0x20);
if(i2c_smbus_write_quick($file, SMBUS_WRITE) >= 0 &&
i2c_smbus_read_byte_data($file,0x80) == -1) {
i2c_set_slave_addr($file,$addr);
if($checksum == 0) {
return (9, $addr - 0x20);
} else {
return (2, $addr - 0x20);
}
}
i2c_set_slave_addr($file,$addr);
return;
}
# Look for a Sony Vaio EEPROM ($chip == 1)
my $vaioconf = 1;
$vaioconf += 4
if i2c_smbus_read_byte_data($file,0x80) == 0x50
&& i2c_smbus_read_byte_data($file,0x81) == 0x43
&& i2c_smbus_read_byte_data($file,0x82) == 0x47
&& i2c_smbus_read_byte_data($file,0x83) == 0x2d;
$vaioconf += 5
if i2c_smbus_read_byte_data($file,0xe2) == 0x2f
&& i2c_smbus_read_byte_data($file,0xe5) == 0x2f
&& i2c_smbus_read_byte_data($file,0xe8) == 0x20
&& i2c_smbus_read_byte_data($file,0xeb) == 0x3a
&& i2c_smbus_read_byte_data($file,0xee) == 0x3a;
$vaioconf += 3
if i2c_smbus_read_byte_data($file,0x1a) == 0x08
&& i2c_smbus_read_byte_data($file,0x1b) == 0x00
&& i2c_smbus_read_byte_data($file,0x1c) == 0x46;
$vaioconf = 9
if $vaioconf > 9;
if ($vaioconf > 1) {
return $vaioconf;
}
return;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, (1) if detected.
# Registers used:
# 0x00..0x07: DDC signature
# 0x08..0x7E: checksumed area
# 0x7F: checksum
sub ddcmonitor_detect
{
my ($file,$addr) = @_;
my $i;
return unless
i2c_smbus_read_byte_data($file,0x00) == 0x00 and
i2c_smbus_read_byte_data($file,0x01) == 0xFF and
i2c_smbus_read_byte_data($file,0x02) == 0xFF and
i2c_smbus_read_byte_data($file,0x03) == 0xFF and
i2c_smbus_read_byte_data($file,0x04) == 0xFF and
i2c_smbus_read_byte_data($file,0x05) == 0xFF and
i2c_smbus_read_byte_data($file,0x06) == 0xFF and
i2c_smbus_read_byte_data($file,0x07) == 0x00;
# Check the checksum for validity.
my $checksum = 0;
for ($i = 0; $i <= 127; $i = $i + 1) {
$checksum = $checksum + i2c_smbus_read_byte_data($file,$i);
}
$checksum=$checksum & 255;
if ($checksum != 0) {
# I have one such monitor...
return (2,$addr+1,$addr+2,$addr+3,$addr+4,$addr+5,$addr+6,$addr+7);
}
return (8,$addr+1,$addr+2,$addr+3,$addr+4,$addr+5,$addr+6,$addr+7);
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, (8) if detected.
# Registers used:
# 0x00-0x02: Identification ('P','E','G' -> Pegasus ? :-)
sub fscpos_detect
{
my ($file,$addr) = @_;
# check the first 3 registers
if (i2c_smbus_read_byte_data($file,0x00) != 0x50) {
return;
}
if (i2c_smbus_read_byte_data($file,0x01) != 0x45) {
return;
}
if (i2c_smbus_read_byte_data($file,0x02) != 0x47) {
return;
}
return (8);
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, (8) if detected.
# Registers used:
# 0x00-0x02: Identification ('S','C','Y')
sub fscscy_detect
{
my ($file,$addr) = @_;
# check the first 3 registers
if (i2c_smbus_read_byte_data($file,0x00) != 0x53) {
return;
}
if (i2c_smbus_read_byte_data($file,0x01) != 0x43) {
return;
}
if (i2c_smbus_read_byte_data($file,0x02) != 0x59) {
return;
}
return (8);
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, (8) if detected.
# Registers used:
# 0x00-0x02: Identification ('H','E','R')
sub fscher_detect
{
my ($file,$addr) = @_;
# check the first 3 registers
if (i2c_smbus_read_byte_data($file,0x00) != 0x48) {
return;
}
if (i2c_smbus_read_byte_data($file,0x01) != 0x45) {
return;
}
if (i2c_smbus_read_byte_data($file,0x02) != 0x52) {
return;
}
return (8);
}
# $_[0]: A reference to the file descriptor to access this chip.
# We assume an i2c_set_slave_addr was already done.
# $_[1]: Address (unused)
# Returns: undef if not detected, 5 if detected.
# Registers used:
# 0x3E: Manufacturer ID
# 0x3F: Version/Stepping
sub lm93_detect
{
my $file = shift;
return unless i2c_smbus_read_byte_data($file, 0x3E) == 0x01
and i2c_smbus_read_byte_data($file, 0x3F) == 0x73;
return 5;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, (7) if detected.
# Registers used:
# 0x3F: Revision ID
# 0x48: Address
# 0x4A, 0x4B, 0x4F, 0x57, 0x58: Reserved bits.
# We do not use 0x49's reserved bits on purpose. The register is named
# "VID4/Device ID" so it is doubtful bits 7-1 are really unused.
sub m5879_detect
{
my ($file, $addr) = @_;
return
unless i2c_smbus_read_byte_data($file, 0x3F) == 0x01;
return
unless i2c_smbus_read_byte_data($file, 0x48) == $addr;
return
unless (i2c_smbus_read_byte_data($file, 0x4A) & 0x06) == 0
and (i2c_smbus_read_byte_data($file, 0x4B) & 0xFC) == 0
and (i2c_smbus_read_byte_data($file, 0x4F) & 0xFC) == 0
and (i2c_smbus_read_byte_data($file, 0x57) & 0xFE) == 0
and (i2c_smbus_read_byte_data($file, 0x58) & 0xEF) == 0;
return (7);
}
# $_[0]: A reference to the file descriptor to access this chip.
# We assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, 5 or 6 if detected.
# Registers used:
# 0x3E: Manufacturer ID
# 0x3F: Version/Stepping
# 0x47: VID (3 reserved bits)
# 0x49: VID4 (7 reserved bits)
sub smsc47m192_detect
{
my ($file, $addr) = @_;
return unless i2c_smbus_read_byte_data($file, 0x3E) == 0x55
and (i2c_smbus_read_byte_data($file, 0x3F) & 0xF0) == 0x20
and (i2c_smbus_read_byte_data($file, 0x47) & 0x70) == 0x00
and (i2c_smbus_read_byte_data($file, 0x49) & 0xFE) == 0x80;
return ($addr == 0x2d ? 6 : 5);
}
# $_[0]: Chip to detect
# (1 = F75111R/RG/N, 2 = F75121R/F75122R/RG, 3 = F75373S/SG,
# 4 = F75375S/SP, 5 = F75387SG/RG, 6 = F75383M/S/F75384M/S,
# 7 = custom power control IC)
# $_[1]: A reference to the file descriptor to access this chip.
# We assume an i2c_set_slave_addr was already done.
# $_[2]: Address (unused)
# Returns: undef if not detected, 7 if detected.
# Registers used:
# 0x5A-0x5B: Chip ID
# 0x5D-0x5E: Vendor ID
sub fintek_detect
{
my ($chip, $file, $addr) = @_;
my $chipid = (i2c_smbus_read_byte_data($file, 0x5A) << 8)
| i2c_smbus_read_byte_data($file, 0x5B);
my $vendid = (i2c_smbus_read_byte_data($file, 0x5D) << 8)
| i2c_smbus_read_byte_data($file, 0x5E);
return unless $vendid == 0x1934; # Fintek ID
if ($chip == 1) { # F75111R/RG/N
return unless $chipid == 0x0300;
} elsif ($chip == 2) { # F75121R/F75122R/RG
return unless $chipid == 0x0301;
} elsif ($chip == 3) { # F75373S/SG
return unless $chipid == 0x0204;
} elsif ($chip == 4) { # F75375S/SP
return unless $chipid == 0x0306;
} elsif ($chip == 5) { # F75387SG/RG
return unless $chipid == 0x0410;
} elsif ($chip == 6) { # F75383M/S/F75384M/S
# The datasheet has 0x0303, but Fintek say 0x0413 is also possible
return unless $chipid == 0x0303 || $chipid == 0x0413;
} elsif ($chip == 7) { # custom power control IC
return unless $chipid == 0x0302;
}
return 7;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, 4 or 7 if detected
# Detection is based on the fact that the SAA1064 has only one readable
# register, and thus ignores the read address. This register can have value
# 0x80 (first read since power-up) or 0x00.
sub saa1064_detect
{
my ($file,$addr) = @_;
my $status = i2c_smbus_read_byte_data ($file, 0x00);
return if ($status & 0x7f) != 0x00;
for (my $i=0 ; $i<256; $i++) {
return if i2c_smbus_read_byte_data ($file, $i) != 0x00;
}
return 7
if $status == 0x80;
return 4;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, 1 if detected
# Detection is rather difficult, since the PCA9540 has a single register.
# Fortunately, no other device is known to live at this address.
sub pca9540_detect
{
my ($file, $addr) = @_;
my $reg = i2c_smbus_read_byte($file);
return if ($reg & 0xfa);
return if $reg != i2c_smbus_read_byte($file);
return if $reg != i2c_smbus_read_byte($file);
return if $reg != i2c_smbus_read_byte($file);
return 1;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We assume an i2c_set_slave_addr was already done.
# $_[1]: Address (unused)
# Returns: undef if not detected, 1 if detected
# Detection is rather difficult, since the PCA9556 only has 4 registers
# and no unused bit. We use the fact that the registers cycle over
# 4 addresses boundaries, and the logic rules between registers.
sub pca9556_detect
{
my ($file, $addr) = @_;
my $input = i2c_smbus_read_byte_data($file, 0x00);
my $output = i2c_smbus_read_byte_data($file, 0x01);
my $invert = i2c_smbus_read_byte_data($file, 0x02);
my $config = i2c_smbus_read_byte_data($file, 0x03);
# Pins configured for output (config = 0) must obey the following
# rule: input = output ^ invert
return unless ($input & ~$config) == (($output ^ $invert) & ~$config);
for (my $i = 5; $i < 254 ; $i+=4) {
return unless i2c_smbus_read_byte_data($file, $i) == $output;
return unless i2c_smbus_read_byte_data($file, $i+1) == $invert;
return unless i2c_smbus_read_byte_data($file, $i+2) == $config;
}
return 1;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: undef if not detected, 3 if detected
sub max6900_detect
{
my ($file,$addr) = @_;
my $reg;
# SEC
$reg = i2c_smbus_read_byte_data ($file, 0x81);
return if
($reg & 0xF0) > 0x50 or
($reg & 0x0F) > 9;
# MIN
$reg = i2c_smbus_read_byte_data ($file, 0x83);
return if
($reg & 0xF0) > 0x50 or
($reg & 0x0F) > 9;
# HR
$reg = i2c_smbus_read_byte_data ($file, 0x85);
return if
($reg & 0x40) != 0x00 or
($reg & 0x0F) > 9;
# DATE
$reg = i2c_smbus_read_byte_data ($file, 0x87);
return if
$reg == 0x00 or
($reg & 0xF0) > 0x30 or
($reg & 0x0F) > 9;
# MONTH
$reg = i2c_smbus_read_byte_data ($file, 0x89);
return if
$reg == 0x00 or
($reg & 0xF0) > 0x10 or
($reg & 0x0F) > 9;
# DAY
$reg = i2c_smbus_read_byte_data ($file, 0x8B);
return if
$reg == 0 or
$reg > 7;
# YEAR
$reg = i2c_smbus_read_byte_data ($file, 0x8D);
return if
($reg & 0xF0) > 0x90 or
($reg & 0x0F) > 9;
# CONTROL
$reg = i2c_smbus_read_byte_data ($file, 0x8F);
return if
($reg & 0x7F) != 0x00;
# CENTURY
$reg = i2c_smbus_read_byte_data ($file, 0x93);
return if
($reg & 0xF0) > 0x90 or
($reg & 0x0F) > 9;
return 3;
}
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: 1
# This is a placeholder so we get a report if any device responds
# to the SMBus Device Default Address (0x61), which is used for
# ARP in SMBus 2.0.
sub arp_detect
{
return (1);
}
# This checks for non-FFFF values for SpecInfo and Status.
# The address (0x09) is specified by the SMBus standard so it's likely
# that this really is a smart battery charger.
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: 5
sub smartbatt_chgr_detect
{
my ($file,$addr) = @_;
# check some registers
if (i2c_smbus_read_word_data($file,0x11) == 0xffff) {
return;
}
if (i2c_smbus_read_word_data($file,0x13) == 0xffff) {
return;
}
return (5);
}
# This checks for non-FFFF values for State and Info.
# The address (0x0a) is specified by the SMBus standard so it's likely
# that this really is a smart battery manager/selector.
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: 5
sub smartbatt_mgr_detect
{
my ($file,$addr) = @_;
# check some registers
if (i2c_smbus_read_word_data($file,0x01) == 0xffff) {
return;
}
if (i2c_smbus_read_word_data($file,0x04) == 0xffff) {
return;
}
return (5);
}
# This checks for non-FFFF values for temperature, voltage, and current.
# The address (0x0b) is specified by the SMBus standard so it's likely
# that this really is a smart battery.
# $_[0]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[1]: Address
# Returns: 5
sub smartbatt_detect
{
my ($file,$addr) = @_;
# check some registers
if (i2c_smbus_read_word_data($file,0x08) == 0xffff) {
return;
}
if (i2c_smbus_read_word_data($file,0x09) == 0xffff) {
return;
}
if (i2c_smbus_read_word_data($file,0x0a) == 0xffff) {
return;
}
return (5);
}
# Returns: 4
# These are simple detectors that only look for a register at the
# standard location. No writes are performed.
# For KCS, use the STATUS register. For SMIC, use the FLAGS register.
sub ipmi_kcs_detect
{
return if inb (0x0ca3) == 0xff;
return (4);
}
sub ipmi_smic_detect
{
return if inb (0x0cab) == 0xff;
return (4);
}
# $_[0]: Chip to detect (0 = W83L784R/AR, 1 = W83L785R)
# $_[1]: A reference to the file descriptor to access this chip.
# $_[2]: Address
# Returns: undef if not detected, 6 or 8 if detected
# Registers used:
# 0x40: Configuration
# 0x4a: Full I2C Address (not W83L785R)
# 0x4b: I2C addresses of emulated LM75 chips (not W83L785R)
# 0x4c: Winbond Vendor ID (Low Byte)
# 0x4d: Winbond Vendor ID (High Byte)
# 0x4e: Chip ID
# Note that this function is always called through a closure, so the
# arguments are shifted by one place.
sub w83l784r_detect
{
my ($reg,@res);
my ($chip,$file,$addr) = @_;
return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00;
return if $chip == 0
and i2c_smbus_read_byte_data($file,0x4a) != $addr;
return unless i2c_smbus_read_byte_data($file,0x4c) == 0xa3;
return unless i2c_smbus_read_byte_data($file,0x4d) == 0x5c;
return if $chip == 0
and i2c_smbus_read_byte_data($file,0x4e) != 0x50;
return if $chip == 1
and i2c_smbus_read_byte_data($file,0x4e) != 0x60;
$reg = i2c_smbus_read_byte_data($file,0x4b);
return 6 if $chip == 1; # W83L785R doesn't have subclients
@res = (8);
push @res, ($reg & 0x07) + 0x48 unless $reg & 0x08 ;
push @res, (($reg & 0x70) >> 4) + 0x48 unless $reg & 0x80;
return @res;
}
# $_[0]: Chip to detect (0 = W83L785TS-S)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, 8 if detected
# Registers used:
# 0x4C-4E: Mfr and Chip ID
# Note that this function is always called through a closure, so the
# arguments are shifted by one place.
sub w83l785ts_detect
{
my ($chip,$file,$addr) = @_;
return unless i2c_smbus_read_byte_data($file,0x4c) == 0xa3;
return unless i2c_smbus_read_byte_data($file,0x4d) == 0x5c;
return unless i2c_smbus_read_byte_data($file,0x4e) == 0x70;
return (8);
}
# $_[0]: Chip to detect. Always zero for now, but available for future use
# if somebody finds a way to distinguish MAX6650 and MAX6651.
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
# Returns: undef if not detected, 4 if detected.
#
# The max6650 has no device ID register. However, a few registers have
# spare bits, which are documented as being always zero on read. We read
# all of these registers check the spare bits. Any non-zero means this
# is not a max6650/1.
#
# The always zero bits are:
# configuration byte register (0x02) - top 2 bits
# gpio status register (0x14) - top 3 bits
# alarm enable register (0x08) - top 3 bits
# alarm status register (0x0A) - top 3 bits
# tachometer count time register (0x16) - top 6 bits
# Additionally, not all values are possible for lower 3 bits of
# the configuration register.
sub max6650_detect
{
my ($chip, $file) = @_;
my $conf = i2c_smbus_read_byte_data($file,0x02);
return if i2c_smbus_read_byte_data($file,0x16) & 0xFC;
return if i2c_smbus_read_byte_data($file,0x0A) & 0xE0;
return if i2c_smbus_read_byte_data($file,0x08) & 0xE0;
return if i2c_smbus_read_byte_data($file,0x14) & 0xE0;
return if ($conf & 0xC0) or ($conf & 0x07) > 4;
return 4;
}
# $_[0]: Chip to detect (0 = VT1211)
# $_[1]: A reference to the file descriptor to access this chip.
# We may assume an i2c_set_slave_addr was already done.
# $_[2]: Address
#
# This isn't very good detection.
# Verify the i2c address, and the stepping ID (which is 0xb0 on
# my chip but could be different for others...
#
sub vt1211_i2c_detect
{
my ($chip,$file,$addr) = @_;
return unless (i2c_smbus_read_byte_data($file,0x48) & 0x7f) == $addr;
return unless i2c_smbus_read_byte_data($file,0x3f) == 0xb0;
return 2;
}
# $_[0]: Chip to detect (0 = VT1211)
# $_[1]: ISA address
# $_[2]: I2C file handle
# $_[3]: I2C address
sub vt1211_alias_detect
{
my ($chip,$isa_addr,$file,$i2c_addr) = @_;
my $i;
return 0 unless (inb($isa_addr + 0x48) & 0x7f) == $i2c_addr;
return 0 unless (i2c_smbus_read_byte_data($file,0x48) & 0x7f) == $i2c_addr;
for ($i = 0x2b; $i <= 0x3d; $i ++) {
return 0 unless inb($isa_addr + $i) == i2c_smbus_read_byte_data($file,$i);
}
return 1;
}
######################
# PCI CHIP DETECTION #
######################
# Returns: undef if not detected, (7) or (9) if detected.
# The address is encoded in PCI space. We could decode it and print it.
# For Linux 2.4 we should probably check for invalid matches (SiS645).
sub sis5595_pci_detect
{
return unless exists $pci_list{'1039:0008'};
return (kernel_version_at_least(2, 6, 0) ? 9 : 7);
}
# Returns: undef if not detected, (9) if detected.
# The address is encoded in PCI space. We could decode it and print it.
sub via686a_pci_detect
{
return unless exists $pci_list{'1106:3057'};
return 9;
}
# Returns: undef if not detected, (9) if detected.
# The address is encoded in PCI space. We could decode it and print it.
sub via8231_pci_detect
{
return unless exists $pci_list{'1106:8235'};
return 9;
}
# Returns: undef if not detected, (9) if detected.
sub k8temp_pci_detect
{
return unless exists $pci_list{'1022:1103'};
return 9;
}
################
# MAIN PROGRAM #
################
# $_[0]: reference to a list of chip hashes
sub print_chips_report
{
my ($listref) = @_;
my $data;
foreach $data (@$listref) {
my $is_i2c = exists $data->{i2c_addr};
my $is_isa = exists $data->{isa_addr};
print " * ";
if ($is_i2c) {
printf "Bus `%s'\n", $data->{i2c_adap};
printf " Busdriver `%s', I2C address 0x%02x",
$data->{i2c_driver}, $data->{i2c_addr};
if (exists $data->{i2c_sub_addrs}) {
print " (and";
my $sub_addr;
foreach $sub_addr (@{$data->{i2c_sub_addrs}}) {
printf " 0x%02x",$sub_addr;
}
print ")"
}
print "\n";
}
if ($is_isa) {
print " " if $is_i2c;
if ($data->{isa_addr}) {
printf "ISA bus address 0x%04x (Busdriver `i2c-isa')\n",
$data->{isa_addr};
} else {
print "ISA bus, undetermined address (Busdriver `i2c-isa')\n";
}
}
printf " Chip `%s' (confidence: %d)\n",
$data->{chipname}, $data->{conf};
}
}
# $_[0]: 1 if ISA bus is prefered, 0 for SMBus
# We build here an array adapters, indexed on the number the adapter has
# at this moment (we assume only loaded adapters are interesting at all;
# everything that got scanned also got loaded). Each entry is a reference
# to a hash containing:
# driver: Name of the adapter driver
# nr_now: Number of the bus now
# nr_later: Number of the bus when the modprobes are done (not included if the
# driver should not be loaded)
# A second array, called
sub generate_modprobes
{
my ($prefer_isa) = @_;
my ($chip,$detection,$nr,$i,@optionlist,@probelist,$driver,$isa,$adap);
my $bmcsensors = 0;
my @adapters;
my $modprobes = "";
my $configfile = "";
# These are always needed
$configfile .= "# I2C module options\n";
$configfile .= "alias char-major-89 i2c-dev\n";
# Collect all loaded adapters
# i2cdetect -l either cats /proc/bus/i2c or scans sysfs for the same information
open(local *INPUTFILE, "i2cdetect -l |") or die "Couldn't find i2cdetect program!!";
local $_;
while (<INPUTFILE>) {
my ($dev_nr, $type, $adap) = /^i2c-(\d+)\s+(\S+)\s+(.*?) *(\t|$)/;
next if ($type eq "dummy" || $type eq "isa");
$adapters[$dev_nr]->{driver} = find_adapter_driver($adap);
$adapters[$dev_nr]->{adapname} = $adap;
}
close INPUTFILE;
# Collect all adapters used
$nr = 0;
$isa = 0;
$modprobes .= "# I2C adapter drivers\n";
foreach $chip (@chips_detected) {
foreach $detection (@{$chip->{detected}}) {
# If there is more than one bus detected by a driver, they are
# still all added. So we number them in the correct order
if (exists $detection->{i2c_driver} and
not exists $adapters[$detection->{i2c_devnr}]->{nr_later} and
not (exists $detection->{isa_addr} and $prefer_isa)) {
foreach $adap (@adapters) {
next unless exists $adap->{driver};
$adap->{nr_later} = $nr++ if $adap->{driver} eq $detection->{i2c_driver};
}
}
if (exists $detection->{isa_addr} and
not (exists $detection->{i2c_driver} and not $prefer_isa)) {
$isa=1;
}
if ($chip->{driver} eq "bmcsensors") {
$bmcsensors=1;
}
}
}
for ($i = 0; $i < $nr; $i++) {
foreach $adap (@adapters) {
next unless exists $adap->{nr_later} and $adap->{nr_later} == $i;
if ($adap->{driver} eq "UNKNOWN") {
$modprobes .= "# modprobe unknown adapter ".$adap->{adapname}."\n";
} elsif ($adap->{driver} eq "DISABLED") {
$modprobes .= "# modprobe disabled adapter ".$adap->{adapname}."\n";
} elsif ($adap->{driver} eq "to-be-written") {
$modprobes .= "# no driver available for adapter ".$adap->{adapname}."\n";
} else {
$modprobes .= "$adap->{driver}\n"
unless $modprobes =~ /$adap->{driver}\n/;
}
last;
}
}
# i2c-isa is loaded automatically (as a dependency) since 2.6.14,
# and will soon be gone.
$modprobes .= "i2c-isa\n" if ($isa && !kernel_version_at_least(2, 6, 18));
if ($bmcsensors) {
$modprobes .= "# You must also install and load the IPMI modules\n";
$modprobes .= "i2c-ipmi\n";
}
# Now determine the chip probe lines
$modprobes .= "# Chip drivers\n";
foreach $chip (@chips_detected) {
next if not @{$chip->{detected}};
next if $chip->{driver} eq "not-a-sensor";
next if $chip->{driver} eq "use-isa-instead";
if ($chip->{driver} eq "to-be-written") {
$modprobes .= "# no driver for $chip->{detected}[0]{chipname} yet\n";
} else {
# need the * for 2.4 kernels, won't necessarily be an exact match
open(local *INPUTFILE, "modprobe -l $chip->{driver}\\* 2>/dev/null |");
local $_;
my $modulefound = 0;
while (<INPUTFILE>) {
if(m@/@) {
$modulefound = 1;
last;
}
}
close INPUTFILE;
#check return value from modprobe in case modprobe -l isn't supported
if((($? >> 8) == 0) && ! $modulefound) {
$modprobes .= "# Warning: the required module $chip->{driver} is not currently installed\n".
"# on your system. For status of 2.6 kernel ports check\n".
"# http://www.lm-sensors.org/wiki/Devices. If driver is built\n".
"# into the kernel, or unavailable, comment out the following line.\n";
}
$modprobes .= "$chip->{driver}\n";
}
# Handle misdetects
foreach $detection (@{$chip->{misdetected}}) {
push @optionlist, $adapters[$detection->{i2c_devnr}]->{nr_later},
$detection->{i2c_addr}
if exists $detection->{i2c_addr} and
exists $adapters[$detection->{i2c_devnr}]->{nr_later};
push @optionlist, -1, $detection->{isa_addr}
if exists $detection->{isa_addr} and $isa;
}
# Handle aliases
foreach $detection (@{$chip->{detected}}) {
if (exists $detection->{i2c_driver} and
exists $detection->{isa_addr} and
exists $adapters[$detection->{i2c_devnr}]->{nr_later} and
$isa) {
if ($prefer_isa) {
push @optionlist,$adapters[$detection->{i2c_devnr}]->{nr_later},
$detection->{i2c_addr};
} else {
push @optionlist, -1, $detection->{isa_addr}
}
}
}
next if not (@probelist or @optionlist);
$configfile .= "options $chip->{driver}";
$configfile .= sprintf " ignore=%d,0x%02x",shift @optionlist,
shift @optionlist
if @optionlist;
$configfile .= sprintf ",%d,0x%02x",shift @optionlist, shift @optionlist
while @optionlist;
$configfile .= sprintf " probe=%d,0x%02x",shift @probelist,
shift @probelist
if @probelist;
$configfile .= sprintf ",%d,0x%02x",shift @probelist, shift @probelist
while @probelist;
$configfile .= "\n";
}
return ($modprobes,$configfile);
}
sub main
{
my (@adapters,$res,$did_adapter_detection,$adapter);
# We won't go very far if not root
unless ($> == 0) {
print "You need to be root to run this script.\n";
exit -1;
}
initialize_conf;
initialize_proc_pci;
initialize_modules_list;
initialize_modules_supported;
initialize_kernel_version;
print "# sensors-detect revision $revision\n\n";
print "This program will help you determine which kernel modules you need\n",
"to load to use lm_sensors most effectively. It is generally safe\n",
"and recommended to accept the default answers to all questions,\n",
"unless you know what you're doing.\n";
print "You need to have i2c and lm_sensors installed before running this\n",
"program.\n"
unless kernel_version_at_least(2, 6, 0);
print "\n";
print "We can start with probing for (PCI) I2C or SMBus adapters.\n";
print "Do you want to probe now? (YES/no): ";
@adapters = adapter_pci_detection
if ($did_adapter_detection = not <STDIN> =~ /\s*[Nn]/);
print "\n";
if (not $did_adapter_detection) {
print "As you skipped adapter detection, we will only scan already loaded\n".
"adapter modules.\n";
} else {
print "We will now try to load each adapter module in turn.\n";
foreach $adapter (@adapters) {
next if $adapter eq "DISABLED";
next if $adapter eq "to-be-tested";
if (exists($modules_list{$adapter})) {
print "Module `$adapter' already loaded.\n";
} else {
print "Load `$adapter' (say NO if built into your kernel)? (YES/no): ";
unless (<STDIN> =~ /^\s*[Nn]/) {
if (system ("modprobe", $adapter)) {
print "Loading failed... skipping.\n";
} else {
print "Module loaded successfully.\n";
}
}
}
}
}
print "If you have undetectable or unsupported adapters, you can have them\n".
"scanned by manually loading the modules before running this script.\n\n";
if (!exists($modules_list{"i2c-dev"})
&& !(defined $sysfs_root && -e "$sysfs_root/class/i2c-dev")) {
print "To continue, we need module `i2c-dev' to be loaded.\n";
print "If it is built-in into your kernel, you can safely skip this.\n"
unless kernel_version_at_least(2, 6, 0);
print "Do you want to load `i2c-dev' now? (YES/no): ";
if (<STDIN> =~ /^\s*n/i) {
print "Well, you will know best.\n";
} elsif (system "modprobe", "i2c-dev") {
print "Loading failed, expect problems later on.\n";
} else {
print "Module loaded successfully.\n";
}
print "\n";
}
# Before looking for chips, make sure any special case chips are
# added to the chip_ids list
chip_special_cases();
print "We are now going to do the I2C/SMBus adapter probings. Some chips may\n",
"be double detected; we choose the one with the highest confidence\n",
"value in that case.\n",
"If you found that the adapter hung after probing a certain address,\n",
"you can specify that address to remain unprobed.\n";
my ($inp,@not_to_scan,$inp2);
# i2cdetect -l either cats /proc/bus/i2c or scans sysfs for the same information
open(local *INPUTFILE, "i2cdetect -l |") or die "Couldn't find i2cdetect program!!";
local $_;
while (<INPUTFILE>) {
my ($dev_nr, $type, $adap) = /^i2c-(\d+)\s+(\S+)\s+(.*?) *(\t|$)/;
next if ($type eq "dummy" || $type eq "isa");
print "\n";
print "Next adapter: $adap\n";
print "Do you want to scan it? (YES/no/selectively): ";
$inp = <STDIN>;
if ($inp =~ /^\s*[Ss]/) {
print "Please enter one or more addresses not to scan. Separate them ",
"with comma's.\n",
"You can specify a range by using dashes. Addresses may be ",
"decimal (like 54)\n",
"or hexadecimal (like 0x33).\n",
"Addresses: ";
$inp2 = <STDIN>;
chop $inp2;
@not_to_scan = parse_not_to_scan 0,0x7f,$inp2;
}
scan_adapter $dev_nr, $adap, find_adapter_driver($adap),
\@not_to_scan unless $inp =~ /^\s*[Nn]/;
}
print "\n";
print "Some chips are also accessible through the ISA I/O ports. We have to\n".
"write to arbitrary I/O ports to probe them. This is usually safe though.\n".
"Yes, you do have ISA I/O ports even if you do not have any ISA slots!\n";
print "Do you want to scan the ISA I/O ports? (YES/no): ";
unless (<STDIN> =~ /^\s*n/i) {
initialize_ioports();
scan_isa_bus();
close_ioports();
}
print "\n";
print "Some Super I/O chips may also contain sensors. We have to write to\n".
"standard I/O ports to probe them. This is usually safe.\n";
print "Do you want to scan for Super I/O sensors? (YES/no): ";
unless (<STDIN> =~ /^\s*n/i) {
initialize_ioports();
scan_superio(0x2e, 0x2f);
scan_superio(0x4e, 0x4f);
close_ioports();
}
print "\n";
if(! @chips_detected) {
print "Sorry, no sensors were detected.\n",
"Either your sensors are not supported, or they are connected to an\n",
"I2C or SMBus adapter that is not supported. See doc/FAQ,\n",
"doc/lm_sensors-FAQ.html or http://www.lm-sensors.org/wiki/FAQ\n",
"(FAQ #4.24.3) for further information.\n",
"If you find out what chips are on your board, check\n",
"http://www.lm-sensors.org/wiki/Devices for driver status.\n";
exit;
}
print "Now follows a summary of the probes I have just done.\n".
"Just press ENTER to continue: ";
<STDIN>;
my ($chip,$data);
foreach $chip (@chips_detected) {
next if $chip->{driver} eq "not-a-sensor";
next if $chip->{driver} eq "use-isa-instead";
print "\nDriver `$chip->{driver}' ";
if (@{$chip->{detected}}) {
if (@{$chip->{misdetected}}) {
print "(should be inserted but causes problems):\n";
} else {
print "(should be inserted):\n";
}
} else {
if (@{$chip->{misdetected}}) {
print "(may not be inserted):\n";
} else {
print "(should not be inserted, but is harmless):\n";
}
}
if (@{$chip->{detected}}) {
print " Detects correctly:\n";
print_chips_report $chip->{detected};
}
if (@{$chip->{misdetected}}) {
print " Misdetects:\n";
print_chips_report $chip->{misdetected};
}
# People are easily confused
if ($chip->{driver} eq "eeprom") {
print "\n EEPROMs are *NOT* sensors! They are data storage chips commonly\n",
" found on memory modules (SPD), in monitors (EDID), or in some\n",
" laptops, for example.\n";
}
}
print "\n";
print "I will now generate the commands needed to load the required modules.\n".
"Just press ENTER to continue: ";
<STDIN>;
print "\n";
my ($modprobes, $configfile) = generate_modprobes 1; # 1 == prefer ISA
print "To make the sensors modules behave correctly, add these lines to\n".
"/etc/modules:\n\n";
"$modules_conf:\n\n";
print "#----cut here----\n".
$modprobes.
"#----cut here----\n\n";
if ($modprobes =~ /i2c-viapro/ && $modprobes =~ /via686a/ && kernel_version_at_least(2,6,0)) {
print("\nWARNING: Please note that i2c-viapro and via686a may conflict which\n",
"each other. If you get 'sensors not found', try loading only one module\n",
"at the same time.\n");
}
print "\nDo you want to add these lines to /etc/modules automatically? (yes/NO)";
$_ = <STDIN>;
if (m/^\s*[Yy]/) {
open(MODULES, ">>/etc/modules")
or die "Sorry, can't create /etc/modules ($!)?!?";
print MODULES
"\n# Generated by sensors-detect on " . scalar localtime() . "\n";
print MODULES $modprobes;
close(MODULES);
}
}
main;
|