aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-19 17:24:57 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-19 17:24:57 -0400
commit40b42f1ebf653cd72c32eb1a1a0b9fea2dfbfd7d (patch)
tree6a2adfcd8412189932a372ce25def8611e287b5c /drivers/i2c
parent5a021e9ffd56c22700133ebc37d607f95be8f7bd (diff)
parente24b8cb4fa2bb779bdf48656152366b6f52f748f (diff)
Merge branch 'release' of git://lm-sensors.org/kernel/mhoffman/hwmon-2.6
* 'release' of git://lm-sensors.org/kernel/mhoffman/hwmon-2.6: (44 commits) i2c: Delete the i2c-isa pseudo bus driver hwmon: refuse to load abituguru driver on non-Abit boards hwmon: fix Abit Uguru3 driver detection on some motherboards hwmon/w83627ehf: Be quiet when no chip is found hwmon/w83627ehf: No need to initialize fan_min hwmon/w83627ehf: Export the thermal sensor types hwmon/w83627ehf: Enable VBAT monitoring hwmon/w83627ehf: Add support for the VID inputs hwmon/w83627ehf: Fix timing issues hwmon/w83627ehf: Add error messages for two error cases hwmon/w83627ehf: Convert to a platform driver hwmon/w83627ehf: Update the Kconfig entry make coretemp_device_remove() static hwmon: Add LM93 support hwmon: Improve the pwmN_enable documentation hwmon/smsc47b397: Don't report missing fans as spinning at 82 RPM hwmon: Add support for newer uGuru's hwmon/f71805f: Add temperature-tracking fan control mode hwmon/w83627ehf: Preserve speed reading when changing fan min hwmon: fix detection of abituguru volt inputs ... Manual fixup of trivial conflict in MAINTAINERS file
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/Kconfig3
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-isa.c192
-rw-r--r--drivers/i2c/i2c-core.c2
4 files changed, 0 insertions, 198 deletions
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 1c77e14480dc..da1647869f91 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -237,9 +237,6 @@ config I2C_IOP3XX
237 This driver can also be built as a module. If so, the module 237 This driver can also be built as a module. If so, the module
238 will be called i2c-iop3xx. 238 will be called i2c-iop3xx.
239 239
240config I2C_ISA
241 tristate
242
243config I2C_IXP4XX 240config I2C_IXP4XX
244 tristate "IXP4xx GPIO-Based I2C Interface (DEPRECATED)" 241 tristate "IXP4xx GPIO-Based I2C Interface (DEPRECATED)"
245 depends on ARCH_IXP4XX 242 depends on ARCH_IXP4XX
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index a6db4e38bda8..5b752e4e1918 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -18,7 +18,6 @@ obj-$(CONFIG_I2C_I801) += i2c-i801.o
18obj-$(CONFIG_I2C_I810) += i2c-i810.o 18obj-$(CONFIG_I2C_I810) += i2c-i810.o
19obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o 19obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o
20obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o 20obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o
21obj-$(CONFIG_I2C_ISA) += i2c-isa.o
22obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o 21obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o
23obj-$(CONFIG_I2C_IXP4XX) += i2c-ixp4xx.o 22obj-$(CONFIG_I2C_IXP4XX) += i2c-ixp4xx.o
24obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o 23obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
deleted file mode 100644
index b0e1370075de..000000000000
--- a/drivers/i2c/busses/i2c-isa.c
+++ /dev/null
@@ -1,192 +0,0 @@
1/*
2 i2c-isa.c - an i2c-core-like thing for ISA hardware monitoring chips
3 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
4
5 Based on the i2c-isa pseudo-adapter from the lm_sensors project
6 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23/* This implements an i2c-core-like thing for ISA hardware monitoring
24 chips. Such chips are linked to the i2c subsystem for historical
25 reasons (because the early ISA hardware monitoring chips such as the
26 LM78 had both an I2C and an ISA interface). They used to be
27 registered with the main i2c-core, but as a first step in the
28 direction of a clean separation between I2C and ISA chip drivers,
29 we now have this separate core for ISA ones. It is significantly
30 more simple than the real one, of course, because we don't have to
31 handle multiple busses: there is only one (fake) ISA adapter.
32 It is worth noting that we still rely on i2c-core for some things
33 at the moment - but hopefully this won't last. */
34
35#include <linux/init.h>
36#include <linux/module.h>
37#include <linux/kernel.h>
38#include <linux/errno.h>
39#include <linux/i2c.h>
40#include <linux/i2c-isa.h>
41#include <linux/platform_device.h>
42#include <linux/completion.h>
43
44/* Exported by i2c-core for i2c-isa only */
45extern void i2c_adapter_dev_release(struct device *dev);
46extern struct class i2c_adapter_class;
47
48static u32 isa_func(struct i2c_adapter *adapter);
49
50/* This is the actual algorithm we define */
51static const struct i2c_algorithm isa_algorithm = {
52 .functionality = isa_func,
53};
54
55/* There can only be one... */
56static struct i2c_adapter isa_adapter = {
57 .owner = THIS_MODULE,
58 .id = I2C_HW_ISA,
59 .class = I2C_CLASS_HWMON,
60 .algo = &isa_algorithm,
61 .name = "ISA main adapter",
62};
63
64/* We can't do a thing... */
65static u32 isa_func(struct i2c_adapter *adapter)
66{
67 return 0;
68}
69
70
71/* We implement an interface which resembles i2c_{add,del}_driver,
72 but for i2c-isa drivers. We don't have to remember and handle lists
73 of drivers and adapters so this is much more simple, of course. */
74
75int i2c_isa_add_driver(struct i2c_driver *driver)
76{
77 int res;
78
79 /* Add the driver to the list of i2c drivers in the driver core */
80 driver->driver.bus = &i2c_bus_type;
81 res = driver_register(&driver->driver);
82 if (res)
83 return res;
84 dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->driver.name);
85
86 /* Now look for clients */
87 res = driver->attach_adapter(&isa_adapter);
88 if (res) {
89 dev_dbg(&isa_adapter.dev,
90 "Driver %s failed to attach adapter, unregistering\n",
91 driver->driver.name);
92 driver_unregister(&driver->driver);
93 }
94 return res;
95}
96
97int i2c_isa_del_driver(struct i2c_driver *driver)
98{
99 struct list_head *item, *_n;
100 struct i2c_client *client;
101 int res;
102
103 /* Detach all clients belonging to this one driver */
104 list_for_each_safe(item, _n, &isa_adapter.clients) {
105 client = list_entry(item, struct i2c_client, list);
106 if (client->driver != driver)
107 continue;
108 dev_dbg(&isa_adapter.dev, "Detaching client %s at 0x%x\n",
109 client->name, client->addr);
110 if ((res = driver->detach_client(client))) {
111 dev_err(&isa_adapter.dev, "Failed, driver "
112 "%s not unregistered!\n",
113 driver->driver.name);
114 return res;
115 }
116 }
117
118 /* Get the driver off the core list */
119 driver_unregister(&driver->driver);
120 dev_dbg(&isa_adapter.dev, "Driver %s unregistered\n", driver->driver.name);
121
122 return 0;
123}
124
125
126static int __init i2c_isa_init(void)
127{
128 int err;
129
130 mutex_init(&isa_adapter.clist_lock);
131 INIT_LIST_HEAD(&isa_adapter.clients);
132
133 isa_adapter.nr = ANY_I2C_ISA_BUS;
134 isa_adapter.dev.parent = &platform_bus;
135 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr);
136 isa_adapter.dev.release = &i2c_adapter_dev_release;
137 isa_adapter.dev.class = &i2c_adapter_class;
138 err = device_register(&isa_adapter.dev);
139 if (err) {
140 printk(KERN_ERR "i2c-isa: Failed to register device\n");
141 goto exit;
142 }
143
144 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
145
146 return 0;
147
148exit:
149 return err;
150}
151
152static void __exit i2c_isa_exit(void)
153{
154#ifdef DEBUG
155 struct list_head *item, *_n;
156 struct i2c_client *client = NULL;
157#endif
158
159 /* There should be no more active client */
160#ifdef DEBUG
161 dev_dbg(&isa_adapter.dev, "Looking for clients\n");
162 list_for_each_safe(item, _n, &isa_adapter.clients) {
163 client = list_entry(item, struct i2c_client, list);
164 dev_err(&isa_adapter.dev, "Driver %s still has an active "
165 "ISA client at 0x%x\n", client->driver->driver.name,
166 client->addr);
167 }
168 if (client != NULL)
169 return;
170#endif
171
172 /* Clean up the sysfs representation */
173 dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n");
174 init_completion(&isa_adapter.dev_released);
175 device_unregister(&isa_adapter.dev);
176
177 /* Wait for sysfs to drop all references */
178 dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n");
179 wait_for_completion(&isa_adapter.dev_released);
180
181 dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name);
182}
183
184EXPORT_SYMBOL(i2c_isa_add_driver);
185EXPORT_SYMBOL(i2c_isa_del_driver);
186
187MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
188MODULE_DESCRIPTION("ISA bus access through i2c");
189MODULE_LICENSE("GPL");
190
191module_init(i2c_isa_init);
192module_exit(i2c_isa_exit);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 6971a62397db..d663e6960d93 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -288,7 +288,6 @@ void i2c_adapter_dev_release(struct device *dev)
288 struct i2c_adapter *adap = to_i2c_adapter(dev); 288 struct i2c_adapter *adap = to_i2c_adapter(dev);
289 complete(&adap->dev_released); 289 complete(&adap->dev_released);
290} 290}
291EXPORT_SYMBOL_GPL(i2c_adapter_dev_release); /* exported to i2c-isa */
292 291
293static ssize_t 292static ssize_t
294show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) 293show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
@@ -307,7 +306,6 @@ struct class i2c_adapter_class = {
307 .name = "i2c-adapter", 306 .name = "i2c-adapter",
308 .dev_attrs = i2c_adapter_attrs, 307 .dev_attrs = i2c_adapter_attrs,
309}; 308};
310EXPORT_SYMBOL_GPL(i2c_adapter_class); /* exported to i2c-isa */
311 309
312static void i2c_scan_static_board_info(struct i2c_adapter *adapter) 310static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
313{ 311{
9' href='#n629'>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

















































































                                                                                   


















                            
                          

                         
                              


















































































                                                                                                    
                                                            





























                                                                                                           
                                    

         
                                         





                                                      
                                                                                                 
































                                                                             






                                                                                                                    
                                              
                                              
                                                                                                     









                                                                                      
                         
               













                                                          
                                      








                                                                                                                                                                                                        
                                                    


















































                                                                                                                           
                                                           












                                                                                                     
                                                    











































                                                                                                             

                                                         
                 



                                                                       

      








                                                                              
                                                              



                                                                      
                             




                                          
                                                                                     








































































                                                                                                                                                               
                                                             














































                                                                                                                              

                                                                                     
































































































































                                                                                                                                                                                                               










                                                                                                     




                                                                                            



                                                                                                       


























                                                                              
                                                              

























































                                                                                                                                              






























                                                                                                                                          


                                                                                                                                   















                                                                                                                                         


                                                                                                                                   





























                                                                                                                                            
                                                              




























                                                                                                                 
                                                            

                                                            
                                                              


















































































































                                                                                                                                                                                                                                                                                                                                                       
                                                              





























                                                                                                                               
                                                              
























                                                                        
                                                          










































                                                                                                                   
                                                                


































































                                                                                            
                                                                
















































































































































                                                                                                                                                                                                         
                                      





                                                                         
                                                                



















                                                                                                                     
                                                                



















































                                                                                                                                                                                                                                                      

                                                                    
                                                             


                                                                                             
                                                    



                                                                             
                 
                                    


























































































































                                                                                                                                
                                                                






































                                                                                                                        
                                                                




















                                                                                                        
                                                              





                                                                                                





                              




                                                                                                        



                                                                                               
                     

                                         








                                                                                                                                     






                                                                                                               




                                                                            

                                 






                                                                                                                               


                                                                                                                
                    
                               









                                                                                                                   


                                                                                                                


                                                                                        
                               




















                                                                               
                                                              


                                                     
                                              
                                             
                                                               

















                                                          
                                                     











                                                 
/*
 *   olympic.c (c) 1999 Peter De Schrijver All Rights Reserved
 *		   1999/2000 Mike Phillips (mikep@linuxtr.net)
 *
 *  Linux driver for IBM PCI tokenring cards based on the Pit/Pit-Phy/Olympic
 *  chipset. 
 *
 *  Base Driver Skeleton:
 *      Written 1993-94 by Donald Becker.
 *
 *      Copyright 1993 United States Government as represented by the
 *      Director, National Security Agency.
 *
 *  Thanks to Erik De Cock, Adrian Bridgett and Frank Fiene for their 
 *  assistance and perserverance with the testing of this driver.
 *
 *  This software may be used and distributed according to the terms
 *  of the GNU General Public License, incorporated herein by reference.
 * 
 *  4/27/99 - Alpha Release 0.1.0
 *            First release to the public
 *
 *  6/8/99  - Official Release 0.2.0   
 *            Merged into the kernel code 
 *  8/18/99 - Updated driver for 2.3.13 kernel to use new pci
 *	      resource. Driver also reports the card name returned by
 *            the pci resource.
 *  1/11/00 - Added spinlocks for smp
 *  2/23/00 - Updated to dev_kfree_irq 
 *  3/10/00 - Fixed FDX enable which triggered other bugs also 
 *            squashed.
 *  5/20/00 - Changes to handle Olympic on LinuxPPC. Endian changes.
 *            The odd thing about the changes is that the fix for
 *            endian issues with the big-endian data in the arb, asb...
 *            was to always swab() the bytes, no matter what CPU.
 *            That's because the read[wl]() functions always swap the
 *            bytes on the way in on PPC.
 *            Fixing the hardware descriptors was another matter,
 *            because they weren't going through read[wl](), there all
 *            the results had to be in memory in le32 values. kdaaker
 *
 * 12/23/00 - Added minimal Cardbus support (Thanks Donald).
 *
 * 03/09/01 - Add new pci api, dev_base_lock, general clean up. 
 *
 * 03/27/01 - Add new dma pci (Thanks to Kyle Lucke) and alloc_trdev
 *	      Change proc_fs behaviour, now one entry per adapter.
 *
 * 04/09/01 - Couple of bug fixes to the dma unmaps and ejecting the
 *	      adapter when live does not take the system down with it.
 * 
 * 06/02/01 - Clean up, copy skb for small packets
 * 
 * 06/22/01 - Add EISR error handling routines 
 *
 * 07/19/01 - Improve bad LAA reporting, strip out freemem
 *	      into a separate function, its called from 3 
 *	      different places now. 
 * 02/09/02 - Replaced sleep_on. 
 * 03/01/02 - Replace access to several registers from 32 bit to 
 * 	      16 bit. Fixes alignment errors on PPC 64 bit machines.
 * 	      Thanks to Al Trautman for this one.
 * 03/10/02 - Fix BUG in arb_cmd. Bug was there all along but was
 * 	      silently ignored until the error checking code 
 * 	      went into version 1.0.0 
 * 06/04/02 - Add correct start up sequence for the cardbus adapters.
 * 	      Required for strict compliance with pci power mgmt specs.
 *  To Do:
 *
 *	     Wake on lan	
 * 
 *  If Problems do Occur
 *  Most problems can be rectified by either closing and opening the interface
 *  (ifconfig down and up) or rmmod and insmod'ing the driver (a bit difficult
 *  if compiled into the kernel).
 */

/* Change OLYMPIC_DEBUG to 1 to get verbose, and I mean really verbose, messages */

#define OLYMPIC_DEBUG 0


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/timer.h>
#include <linux/in.h>
#include <linux/ioport.h>
#include <linux/string.h>
#include <linux/proc_fs.h>
#include <linux/ptrace.h>
#include <linux/skbuff.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/trdevice.h>
#include <linux/stddef.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/spinlock.h>
#include <linux/bitops.h>
#include <linux/jiffies.h>

#include <net/checksum.h>
#include <net/net_namespace.h>

#include <asm/io.h>
#include <asm/system.h>

#include "olympic.h"

/* I've got to put some intelligence into the version number so that Peter and I know
 * which version of the code somebody has got. 
 * Version Number = a.b.c.d  where a.b.c is the level of code and d is the latest author.
 * So 0.0.1.pds = Peter, 0.0.1.mlp = Mike
 * 
 * Official releases will only have an a.b.c version number format. 
 */

static char version[] __devinitdata = 
"Olympic.c v1.0.5 6/04/02 - Peter De Schrijver & Mike Phillips" ; 

static char *open_maj_error[]  = {"No error", "Lobe Media Test", "Physical Insertion",
				   "Address Verification", "Neighbor Notification (Ring Poll)",
				   "Request Parameters","FDX Registration Request",
				   "FDX Duplicate Address Check", "Station registration Query Wait",
				   "Unknown stage"};

static char *open_min_error[] = {"No error", "Function Failure", "Signal Lost", "Wire Fault",
				   "Ring Speed Mismatch", "Timeout","Ring Failure","Ring Beaconing",
				   "Duplicate Node Address","Request Parameters","Remove Received",
				   "Reserved", "Reserved", "No Monitor Detected for RPL", 
				   "Monitor Contention failer for RPL", "FDX Protocol Error"};

/* Module paramters */

MODULE_AUTHOR("Mike Phillips <mikep@linuxtr.net>") ; 
MODULE_DESCRIPTION("Olympic PCI/Cardbus Chipset Driver") ; 

/* Ring Speed 0,4,16,100 
 * 0 = Autosense         
 * 4,16 = Selected speed only, no autosense
 * This allows the card to be the first on the ring
 * and become the active monitor.
 * 100 = Nothing at present, 100mbps is autodetected
 * if FDX is turned on. May be implemented in the future to 
 * fail if 100mpbs is not detected.
 *
 * WARNING: Some hubs will allow you to insert
 * at the wrong speed
 */

static int ringspeed[OLYMPIC_MAX_ADAPTERS] = {0,} ;
module_param_array(ringspeed, int, NULL, 0);

/* Packet buffer size */

static int pkt_buf_sz[OLYMPIC_MAX_ADAPTERS] = {0,} ;
module_param_array(pkt_buf_sz, int, NULL, 0) ;

/* Message Level */

static int message_level[OLYMPIC_MAX_ADAPTERS] = {0,} ; 
module_param_array(message_level, int, NULL, 0) ;

/* Change network_monitor to receive mac frames through the arb channel.
 * Will also create a /proc/net/olympic_tr%d entry, where %d is the tr
 * device, i.e. tr0, tr1 etc. 
 * Intended to be used to create a ring-error reporting network module 
 * i.e. it will give you the source address of beaconers on the ring 
 */
static int network_monitor[OLYMPIC_MAX_ADAPTERS] = {0,};
module_param_array(network_monitor, int, NULL, 0);

static struct pci_device_id olympic_pci_tbl[] = {
	{PCI_VENDOR_ID_IBM,PCI_DEVICE_ID_IBM_TR_WAKE,PCI_ANY_ID,PCI_ANY_ID,},
	{ } 	/* Terminating Entry */
};
MODULE_DEVICE_TABLE(pci,olympic_pci_tbl) ; 


static int olympic_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 
static int olympic_init(struct net_device *dev);
static int olympic_open(struct net_device *dev);
static int olympic_xmit(struct sk_buff *skb, struct net_device *dev);
static int olympic_close(struct net_device *dev);
static void olympic_set_rx_mode(struct net_device *dev);
static void olympic_freemem(struct net_device *dev) ;  
static irqreturn_t olympic_interrupt(int irq, void *dev_id);
static struct net_device_stats * olympic_get_stats(struct net_device *dev);
static int olympic_set_mac_address(struct net_device *dev, void *addr) ; 
static void olympic_arb_cmd(struct net_device *dev);
static int olympic_change_mtu(struct net_device *dev, int mtu);
static void olympic_srb_bh(struct net_device *dev) ; 
static void olympic_asb_bh(struct net_device *dev) ; 
static int olympic_proc_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data) ; 

static int __devinit olympic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
{
	struct net_device *dev ; 
	struct olympic_private *olympic_priv;
	static int card_no = -1 ;
	int i ; 

	card_no++ ; 

	if ((i = pci_enable_device(pdev))) {
		return i ; 
	}

	pci_set_master(pdev);

	if ((i = pci_request_regions(pdev,"olympic"))) { 
		goto op_disable_dev;
	}
 
	dev = alloc_trdev(sizeof(struct olympic_private)) ; 
	if (!dev) {
		i = -ENOMEM; 
		goto op_release_dev;
	}

	olympic_priv = netdev_priv(dev) ;
	
	spin_lock_init(&olympic_priv->olympic_lock) ; 

	init_waitqueue_head(&olympic_priv->srb_wait);
	init_waitqueue_head(&olympic_priv->trb_wait);
#if OLYMPIC_DEBUG  
	printk(KERN_INFO "pci_device: %p, dev:%p, dev->priv: %p\n", pdev, dev, netdev_priv(dev));
#endif
	dev->irq=pdev->irq;
	dev->base_addr=pci_resource_start(pdev, 0);
	olympic_priv->olympic_card_name = pci_name(pdev);
	olympic_priv->pdev = pdev; 
	olympic_priv->olympic_mmio = ioremap(pci_resource_start(pdev,1),256);
	olympic_priv->olympic_lap = ioremap(pci_resource_start(pdev,2),2048);
	if (!olympic_priv->olympic_mmio || !olympic_priv->olympic_lap) {
		goto op_free_iomap;
	}
				
	if ((pkt_buf_sz[card_no] < 100) || (pkt_buf_sz[card_no] > 18000) )
		olympic_priv->pkt_buf_sz = PKT_BUF_SZ ; 
	else
		olympic_priv->pkt_buf_sz = pkt_buf_sz[card_no] ; 

	dev->mtu = olympic_priv->pkt_buf_sz - TR_HLEN ; 
	olympic_priv->olympic_ring_speed = ringspeed[card_no] ; 
	olympic_priv->olympic_message_level = message_level[card_no] ; 
	olympic_priv->olympic_network_monitor = network_monitor[card_no];
	
	if ((i = olympic_init(dev))) {
		goto op_free_iomap;
	}				

	dev->open=&olympic_open;
	dev->hard_start_xmit=&olympic_xmit;
	dev->change_mtu=&olympic_change_mtu;
	dev->stop=&olympic_close;
	dev->do_ioctl=NULL;
	dev->set_multicast_list=&olympic_set_rx_mode;
	dev->get_stats=&olympic_get_stats ;
	dev->set_mac_address=&olympic_set_mac_address ;  
	SET_NETDEV_DEV(dev, &pdev->dev);

	pci_set_drvdata(pdev,dev) ; 
	register_netdev(dev) ; 
	printk("Olympic: %s registered as: %s\n",olympic_priv->olympic_card_name,dev->name);
	if (olympic_priv->olympic_network_monitor) { /* Must go after register_netdev as we need the device name */ 
		char proc_name[20] ; 
		strcpy(proc_name,"olympic_") ;
		strcat(proc_name,dev->name) ; 
		create_proc_read_entry(proc_name,0,init_net.proc_net,olympic_proc_info,(void *)dev) ;
		printk("Olympic: Network Monitor information: /proc/%s\n",proc_name); 
	}
	return  0 ;

op_free_iomap:
	if (olympic_priv->olympic_mmio)
		iounmap(olympic_priv->olympic_mmio); 
	if (olympic_priv->olympic_lap)
		iounmap(olympic_priv->olympic_lap);

	free_netdev(dev);
op_release_dev:
	pci_release_regions(pdev); 

op_disable_dev:
	pci_disable_device(pdev);
	return i;
}

static int __devinit olympic_init(struct net_device *dev)
{
    	struct olympic_private *olympic_priv;
	u8 __iomem *olympic_mmio, *init_srb,*adapter_addr;
	unsigned long t; 
	unsigned int uaa_addr;

	olympic_priv=netdev_priv(dev);
	olympic_mmio=olympic_priv->olympic_mmio;

	printk("%s \n", version);
	printk("%s. I/O at %hx, MMIO at %p, LAP at %p, using irq %d\n", olympic_priv->olympic_card_name, (unsigned int) dev->base_addr,olympic_priv->olympic_mmio, olympic_priv->olympic_lap, dev->irq);

	writel(readl(olympic_mmio+BCTL) | BCTL_SOFTRESET,olympic_mmio+BCTL);
	t=jiffies;
	while((readl(olympic_mmio+BCTL)) & BCTL_SOFTRESET) {
		schedule();		
		if(time_after(jiffies, t + 40*HZ)) {
			printk(KERN_ERR "IBM PCI tokenring card not responding.\n");
			return -ENODEV;
		}
	}


	/* Needed for cardbus */
	if(!(readl(olympic_mmio+BCTL) & BCTL_MODE_INDICATOR)) {
		writel(readl(olympic_priv->olympic_mmio+FERMASK)|FERMASK_INT_BIT, olympic_mmio+FERMASK);
	}
	
#if OLYMPIC_DEBUG
	printk("BCTL: %x\n",readl(olympic_mmio+BCTL));
	printk("GPR: %x\n",readw(olympic_mmio+GPR));
	printk("SISRMASK: %x\n",readl(olympic_mmio+SISR_MASK));
#endif
	/* Aaaahhh, You have got to be real careful setting GPR, the card
	   holds the previous values from flash memory, including autosense 
           and ring speed */

	writel(readl(olympic_mmio+BCTL)|BCTL_MIMREB,olympic_mmio+BCTL);
	
	if (olympic_priv->olympic_ring_speed  == 0) { /* Autosense */
		writew(readw(olympic_mmio+GPR)|GPR_AUTOSENSE,olympic_mmio+GPR);
		if (olympic_priv->olympic_message_level) 
			printk(KERN_INFO "%s: Ringspeed autosense mode on\n",olympic_priv->olympic_card_name);
	} else if (olympic_priv->olympic_ring_speed == 16) {
		if (olympic_priv->olympic_message_level) 
			printk(KERN_INFO "%s: Trying to open at 16 Mbps as requested\n", olympic_priv->olympic_card_name);
		writew(GPR_16MBPS, olympic_mmio+GPR);
	} else if (olympic_priv->olympic_ring_speed == 4) {
		if (olympic_priv->olympic_message_level) 
			printk(KERN_INFO "%s: Trying to open at 4 Mbps as requested\n", olympic_priv->olympic_card_name) ; 
		writew(0, olympic_mmio+GPR);
	} 
	
	writew(readw(olympic_mmio+GPR)|GPR_NEPTUNE_BF,olympic_mmio+GPR);

#if OLYMPIC_DEBUG
	printk("GPR = %x\n",readw(olympic_mmio + GPR) ) ; 
#endif
	/* Solo has been paused to meet the Cardbus power
	 * specs if the adapter is cardbus. Check to 
	 * see its been paused and then restart solo. The
	 * adapter should set the pause bit within 1 second.
	 */

	if(!(readl(olympic_mmio+BCTL) & BCTL_MODE_INDICATOR)) { 
		t=jiffies;
		while (!readl(olympic_mmio+CLKCTL) & CLKCTL_PAUSE) { 
			schedule() ; 
			if(time_after(jiffies, t + 2*HZ)) {
				printk(KERN_ERR "IBM Cardbus tokenring adapter not responsing.\n") ; 
				return -ENODEV;
			}
		}
		writel(readl(olympic_mmio+CLKCTL) & ~CLKCTL_PAUSE, olympic_mmio+CLKCTL) ; 
	}
	
	/* start solo init */
	writel((1<<15),olympic_mmio+SISR_MASK_SUM);

	t=jiffies;
	while(!((readl(olympic_mmio+SISR_RR)) & SISR_SRB_REPLY)) {
		schedule();		
		if(time_after(jiffies, t + 15*HZ)) {
			printk(KERN_ERR "IBM PCI tokenring card not responding.\n");
			return -ENODEV;
		}
	}
	
	writel(readw(olympic_mmio+LAPWWO),olympic_mmio+LAPA);

#if OLYMPIC_DEBUG
	printk("LAPWWO: %x, LAPA: %x\n",readl(olympic_mmio+LAPWWO), readl(olympic_mmio+LAPA));
#endif

	init_srb=olympic_priv->olympic_lap + ((readw(olympic_mmio+LAPWWO)) & (~0xf800));

#if OLYMPIC_DEBUG		
{
	int i;
	printk("init_srb(%p): ",init_srb);
	for(i=0;i<20;i++)
		printk("%x ",readb(init_srb+i));
	printk("\n");
}
#endif	
	if(readw(init_srb+6)) {
		printk(KERN_INFO "tokenring card initialization failed. errorcode : %x\n",readw(init_srb+6));
		return -ENODEV;
	}

	if (olympic_priv->olympic_message_level) {
		if ( readb(init_srb +2) & 0x40) { 
			printk(KERN_INFO "Olympic: Adapter is FDX capable.\n") ;
		} else { 
			printk(KERN_INFO "Olympic: Adapter cannot do FDX.\n");
		}
	}
  
	uaa_addr=swab16(readw(init_srb+8));

#if OLYMPIC_DEBUG
	printk("UAA resides at %x\n",uaa_addr);
#endif

	writel(uaa_addr,olympic_mmio+LAPA);
	adapter_addr=olympic_priv->olympic_lap + (uaa_addr & (~0xf800));

	memcpy_fromio(&dev->dev_addr[0], adapter_addr,6);

#if OLYMPIC_DEBUG
 {
	DECLARE_MAC_BUF(mac);
	printk("adapter address: %s\n", print_mac(mac, dev->dev_addr));
 }
#endif

	olympic_priv->olympic_addr_table_addr = swab16(readw(init_srb + 12)); 
	olympic_priv->olympic_parms_addr = swab16(readw(init_srb + 14)); 

	return 0;

}

static int olympic_open(struct net_device *dev) 
{
	struct olympic_private *olympic_priv=netdev_priv(dev);
	u8 __iomem *olympic_mmio=olympic_priv->olympic_mmio,*init_srb;
	unsigned long flags, t;
	int i, open_finished = 1 ;
	u8 resp, err;
	DECLARE_MAC_BUF(mac);

	DECLARE_WAITQUEUE(wait,current) ; 

	olympic_init(dev);

	if(request_irq(dev->irq, &olympic_interrupt, IRQF_SHARED , "olympic", dev)) {
		return -EAGAIN;
	}

#if OLYMPIC_DEBUG
	printk("BMCTL: %x\n",readl(olympic_mmio+BMCTL_SUM));
	printk("pending ints: %x\n",readl(olympic_mmio+SISR_RR));
#endif

	writel(SISR_MI,olympic_mmio+SISR_MASK_SUM);

	writel(SISR_MI | SISR_SRB_REPLY, olympic_mmio+SISR_MASK); /* more ints later, doesn't stop arb cmd interrupt */

	writel(LISR_LIE,olympic_mmio+LISR); /* more ints later */

	/* adapter is closed, so SRB is pointed to by LAPWWO */

	writel(readw(olympic_mmio+LAPWWO),olympic_mmio+LAPA);
	init_srb=olympic_priv->olympic_lap + ((readw(olympic_mmio+LAPWWO)) & (~0xf800));
	
#if OLYMPIC_DEBUG
	printk("LAPWWO: %x, LAPA: %x\n",readw(olympic_mmio+LAPWWO), readl(olympic_mmio+LAPA));
	printk("SISR Mask = %04x\n", readl(olympic_mmio+SISR_MASK));
	printk("Before the open command \n");
#endif	
	do {