aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorDave Airlie <airlied@starflyer.(none)>2006-01-03 02:18:01 -0500
committerDave Airlie <airlied@linux.ie>2006-01-03 02:18:01 -0500
commit97f2aab6698f3ab2552c41c1024a65ffd0763a6d (patch)
treebb6e3b2949459f54f884c710fc74d40eef00d834 /drivers/char
parentd985c1088146607532093d9eaaaf99758f6a4d21 (diff)
parent88026842b0a760145aa71d69e74fbc9ec118ca44 (diff)
drm: merge in Linus mainline
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/Kconfig22
-rw-r--r--drivers/char/agp/ali-agp.c1
-rw-r--r--drivers/char/agp/amd-k7-agp.c1
-rw-r--r--drivers/char/agp/amd64-agp.c22
-rw-r--r--drivers/char/agp/ati-agp.c1
-rw-r--r--drivers/char/agp/backend.c2
-rw-r--r--drivers/char/agp/efficeon-agp.c1
-rw-r--r--drivers/char/agp/i460-agp.c1
-rw-r--r--drivers/char/agp/intel-agp.c1
-rw-r--r--drivers/char/agp/nvidia-agp.c1
-rw-r--r--drivers/char/agp/sis-agp.c1
-rw-r--r--drivers/char/agp/sworks-agp.c1
-rw-r--r--drivers/char/agp/uninorth-agp.c5
-rw-r--r--drivers/char/agp/via-agp.c7
-rw-r--r--drivers/char/drm/drm_lock.c11
-rw-r--r--drivers/char/drm/drm_memory.c2
-rw-r--r--drivers/char/drm/drm_memory_debug.h2
-rw-r--r--drivers/char/drm/mga_drv.c2
-rw-r--r--drivers/char/drm/radeon_drv.h1
-rw-r--r--drivers/char/epca.c1
-rw-r--r--drivers/char/ftape/lowlevel/ftape-buffer.c1
-rw-r--r--drivers/char/i8k.c6
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c10
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c8
-rw-r--r--drivers/char/keyboard.c10
-rw-r--r--drivers/char/mwave/mwavepub.h2
-rw-r--r--drivers/char/pcmcia/Kconfig24
-rw-r--r--drivers/char/pcmcia/Makefile2
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c2079
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c841
-rw-r--r--drivers/char/pcmcia/cm4040_cs.h47
-rw-r--r--drivers/char/s3c2410-rtc.c50
-rw-r--r--drivers/char/sonypi.c19
-rw-r--r--drivers/char/synclink.c32
-rw-r--r--drivers/char/synclinkmp.c1
-rw-r--r--drivers/char/tb0219.c15
-rw-r--r--drivers/char/tpm/Kconfig2
-rw-r--r--drivers/char/tpm/tpm.c16
-rw-r--r--drivers/char/tpm/tpm.h7
-rw-r--r--drivers/char/tpm/tpm_atmel.c125
-rw-r--r--drivers/char/tpm/tpm_atmel.h131
-rw-r--r--drivers/char/vc_screen.c2
-rw-r--r--drivers/char/vr41xx_giu.c15
-rw-r--r--drivers/char/vr41xx_rtc.c17
-rw-r--r--drivers/char/watchdog/booke_wdt.c17
-rw-r--r--drivers/char/watchdog/mpcore_wdt.c34
-rw-r--r--drivers/char/watchdog/mv64x60_wdt.c20
-rw-r--r--drivers/char/watchdog/pcwd_pci.c1
-rw-r--r--drivers/char/watchdog/s3c2410_wdt.c30
-rw-r--r--drivers/char/watchdog/wdrtas.c2
-rw-r--r--drivers/char/watchdog/wdt_pci.c1
51 files changed, 3388 insertions, 265 deletions
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index fdf4370db994..84e68cdd451b 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -687,7 +687,7 @@ config NVRAM
687 687
688config RTC 688config RTC
689 tristate "Enhanced Real Time Clock Support" 689 tristate "Enhanced Real Time Clock Support"
690 depends on !PPC32 && !PARISC && !IA64 && !M68K 690 depends on !PPC32 && !PARISC && !IA64 && !M68K && (!SPARC || PCI)
691 ---help--- 691 ---help---
692 If you say Y here and create a character special file /dev/rtc with 692 If you say Y here and create a character special file /dev/rtc with
693 major number 10 and minor number 135 using mknod ("man mknod"), you 693 major number 10 and minor number 135 using mknod ("man mknod"), you
@@ -735,7 +735,7 @@ config SGI_IP27_RTC
735 735
736config GEN_RTC 736config GEN_RTC
737 tristate "Generic /dev/rtc emulation" 737 tristate "Generic /dev/rtc emulation"
738 depends on RTC!=y && !IA64 && !ARM && !PPC64 && !M32R && !SPARC32 && !SPARC64 738 depends on RTC!=y && !IA64 && !ARM && !M32R && !SPARC
739 ---help--- 739 ---help---
740 If you say Y here and create a character special file /dev/rtc with 740 If you say Y here and create a character special file /dev/rtc with
741 major number 10 and minor number 135 using mknod ("man mknod"), you 741 major number 10 and minor number 135 using mknod ("man mknod"), you
@@ -943,6 +943,15 @@ config RAW_DRIVER
943 Applications should simply open the device (eg /dev/hda1) 943 Applications should simply open the device (eg /dev/hda1)
944 with the O_DIRECT flag. 944 with the O_DIRECT flag.
945 945
946config MAX_RAW_DEVS
947 int "Maximum number of RAW devices to support (1-8192)"
948 depends on RAW_DRIVER
949 default "256"
950 help
951 The maximum number of RAW devices that are supported.
952 Default is 256. Increase this number in case you need lots of
953 raw devices.
954
946config HPET 955config HPET
947 bool "HPET - High Precision Event Timer" if (X86 || IA64) 956 bool "HPET - High Precision Event Timer" if (X86 || IA64)
948 default n 957 default n
@@ -974,15 +983,6 @@ config HPET_MMAP
974 exposed to the user. If this applies to your hardware, 983 exposed to the user. If this applies to your hardware,
975 say N here. 984 say N here.
976 985
977config MAX_RAW_DEVS
978 int "Maximum number of RAW devices to support (1-8192)"
979 depends on RAW_DRIVER
980 default "256"
981 help
982 The maximum number of RAW devices that are supported.
983 Default is 256. Increase this number in case you need lots of
984 raw devices.
985
986config HANGCHECK_TIMER 986config HANGCHECK_TIMER
987 tristate "Hangcheck timer" 987 tristate "Hangcheck timer"
988 depends on X86 || IA64 || PPC64 || ARCH_S390 988 depends on X86 || IA64 || PPC64 || ARCH_S390
diff --git a/drivers/char/agp/ali-agp.c b/drivers/char/agp/ali-agp.c
index ba54b5872578..b02fc2267159 100644
--- a/drivers/char/agp/ali-agp.c
+++ b/drivers/char/agp/ali-agp.c
@@ -389,7 +389,6 @@ static struct pci_device_id agp_ali_pci_table[] = {
389MODULE_DEVICE_TABLE(pci, agp_ali_pci_table); 389MODULE_DEVICE_TABLE(pci, agp_ali_pci_table);
390 390
391static struct pci_driver agp_ali_pci_driver = { 391static struct pci_driver agp_ali_pci_driver = {
392 .owner = THIS_MODULE,
393 .name = "agpgart-ali", 392 .name = "agpgart-ali",
394 .id_table = agp_ali_pci_table, 393 .id_table = agp_ali_pci_table,
395 .probe = agp_ali_probe, 394 .probe = agp_ali_probe,
diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c
index 40fcd88b2cea..1f776651ac64 100644
--- a/drivers/char/agp/amd-k7-agp.c
+++ b/drivers/char/agp/amd-k7-agp.c
@@ -515,7 +515,6 @@ static struct pci_device_id agp_amdk7_pci_table[] = {
515MODULE_DEVICE_TABLE(pci, agp_amdk7_pci_table); 515MODULE_DEVICE_TABLE(pci, agp_amdk7_pci_table);
516 516
517static struct pci_driver agp_amdk7_pci_driver = { 517static struct pci_driver agp_amdk7_pci_driver = {
518 .owner = THIS_MODULE,
519 .name = "agpgart-amdk7", 518 .name = "agpgart-amdk7",
520 .id_table = agp_amdk7_pci_table, 519 .id_table = agp_amdk7_pci_table,
521 .probe = agp_amdk7_probe, 520 .probe = agp_amdk7_probe,
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 8f748fddca94..810679dcbbb0 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -57,9 +57,8 @@ static int nr_garts;
57static struct pci_dev * hammers[MAX_HAMMER_GARTS]; 57static struct pci_dev * hammers[MAX_HAMMER_GARTS];
58 58
59static struct resource *aperture_resource; 59static struct resource *aperture_resource;
60static int __initdata agp_try_unsupported; 60static int __initdata agp_try_unsupported = 1;
61 61
62static int gart_iterator;
63#define for_each_nb() for(gart_iterator=0;gart_iterator<nr_garts;gart_iterator++) 62#define for_each_nb() for(gart_iterator=0;gart_iterator<nr_garts;gart_iterator++)
64 63
65static void flush_amd64_tlb(struct pci_dev *dev) 64static void flush_amd64_tlb(struct pci_dev *dev)
@@ -73,6 +72,7 @@ static void flush_amd64_tlb(struct pci_dev *dev)
73 72
74static void amd64_tlbflush(struct agp_memory *temp) 73static void amd64_tlbflush(struct agp_memory *temp)
75{ 74{
75 int gart_iterator;
76 for_each_nb() 76 for_each_nb()
77 flush_amd64_tlb(hammers[gart_iterator]); 77 flush_amd64_tlb(hammers[gart_iterator]);
78} 78}
@@ -222,6 +222,7 @@ static struct aper_size_info_32 amd_8151_sizes[7] =
222static int amd_8151_configure(void) 222static int amd_8151_configure(void)
223{ 223{
224 unsigned long gatt_bus = virt_to_gart(agp_bridge->gatt_table_real); 224 unsigned long gatt_bus = virt_to_gart(agp_bridge->gatt_table_real);
225 int gart_iterator;
225 226
226 /* Configure AGP regs in each x86-64 host bridge. */ 227 /* Configure AGP regs in each x86-64 host bridge. */
227 for_each_nb() { 228 for_each_nb() {
@@ -235,7 +236,7 @@ static int amd_8151_configure(void)
235static void amd64_cleanup(void) 236static void amd64_cleanup(void)
236{ 237{
237 u32 tmp; 238 u32 tmp;
238 239 int gart_iterator;
239 for_each_nb() { 240 for_each_nb() {
240 /* disable gart translation */ 241 /* disable gart translation */
241 pci_read_config_dword (hammers[gart_iterator], AMD64_GARTAPERTURECTL, &tmp); 242 pci_read_config_dword (hammers[gart_iterator], AMD64_GARTAPERTURECTL, &tmp);
@@ -415,7 +416,7 @@ static void __devinit amd8151_init(struct pci_dev *pdev, struct agp_bridge_data
415} 416}
416 417
417 418
418static struct aper_size_info_32 uli_sizes[7] = 419static const struct aper_size_info_32 uli_sizes[7] =
419{ 420{
420 {256, 65536, 6, 10}, 421 {256, 65536, 6, 10},
421 {128, 32768, 5, 9}, 422 {128, 32768, 5, 9},
@@ -469,7 +470,7 @@ static int __devinit uli_agp_init(struct pci_dev *pdev)
469} 470}
470 471
471 472
472static struct aper_size_info_32 nforce3_sizes[5] = 473static const struct aper_size_info_32 nforce3_sizes[5] =
473{ 474{
474 {512, 131072, 7, 0x00000000 }, 475 {512, 131072, 7, 0x00000000 },
475 {256, 65536, 6, 0x00000008 }, 476 {256, 65536, 6, 0x00000008 },
@@ -697,13 +698,22 @@ static struct pci_device_id agp_amd64_pci_table[] = {
697 .subvendor = PCI_ANY_ID, 698 .subvendor = PCI_ANY_ID,
698 .subdevice = PCI_ANY_ID, 699 .subdevice = PCI_ANY_ID,
699 }, 700 },
701 /* ALI/ULI M1695 */
702 {
703 .class = (PCI_CLASS_BRIDGE_HOST << 8),
704 .class_mask = ~0,
705 .vendor = PCI_VENDOR_ID_AL,
706 .device = 0x1689,
707 .subvendor = PCI_ANY_ID,
708 .subdevice = PCI_ANY_ID,
709 },
710
700 { } 711 { }
701}; 712};
702 713
703MODULE_DEVICE_TABLE(pci, agp_amd64_pci_table); 714MODULE_DEVICE_TABLE(pci, agp_amd64_pci_table);
704 715
705static struct pci_driver agp_amd64_pci_driver = { 716static struct pci_driver agp_amd64_pci_driver = {
706 .owner = THIS_MODULE,
707 .name = "agpgart-amd64", 717 .name = "agpgart-amd64",
708 .id_table = agp_amd64_pci_table, 718 .id_table = agp_amd64_pci_table,
709 .probe = agp_amd64_probe, 719 .probe = agp_amd64_probe,
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c
index fbd415565463..53372a83b675 100644
--- a/drivers/char/agp/ati-agp.c
+++ b/drivers/char/agp/ati-agp.c
@@ -521,7 +521,6 @@ static struct pci_device_id agp_ati_pci_table[] = {
521MODULE_DEVICE_TABLE(pci, agp_ati_pci_table); 521MODULE_DEVICE_TABLE(pci, agp_ati_pci_table);
522 522
523static struct pci_driver agp_ati_pci_driver = { 523static struct pci_driver agp_ati_pci_driver = {
524 .owner = THIS_MODULE,
525 .name = "agpgart-ati", 524 .name = "agpgart-ati",
526 .id_table = agp_ati_pci_table, 525 .id_table = agp_ati_pci_table,
527 .probe = agp_ati_probe, 526 .probe = agp_ati_probe,
diff --git a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
index 27bca34b4a65..80ee17a8fc23 100644
--- a/drivers/char/agp/backend.c
+++ b/drivers/char/agp/backend.c
@@ -97,7 +97,7 @@ void agp_backend_release(struct agp_bridge_data *bridge)
97EXPORT_SYMBOL(agp_backend_release); 97EXPORT_SYMBOL(agp_backend_release);
98 98
99 99
100static struct { int mem, agp; } maxes_table[] = { 100static const struct { int mem, agp; } maxes_table[] = {
101 {0, 0}, 101 {0, 0},
102 {32, 4}, 102 {32, 4},
103 {64, 28}, 103 {64, 28},
diff --git a/drivers/char/agp/efficeon-agp.c b/drivers/char/agp/efficeon-agp.c
index d41e0a62e32e..e7aea77a60f9 100644
--- a/drivers/char/agp/efficeon-agp.c
+++ b/drivers/char/agp/efficeon-agp.c
@@ -429,7 +429,6 @@ static struct pci_device_id agp_efficeon_pci_table[] = {
429MODULE_DEVICE_TABLE(pci, agp_efficeon_pci_table); 429MODULE_DEVICE_TABLE(pci, agp_efficeon_pci_table);
430 430
431static struct pci_driver agp_efficeon_pci_driver = { 431static struct pci_driver agp_efficeon_pci_driver = {
432 .owner = THIS_MODULE,
433 .name = "agpgart-efficeon", 432 .name = "agpgart-efficeon",
434 .id_table = agp_efficeon_pci_table, 433 .id_table = agp_efficeon_pci_table,
435 .probe = agp_efficeon_probe, 434 .probe = agp_efficeon_probe,
diff --git a/drivers/char/agp/i460-agp.c b/drivers/char/agp/i460-agp.c
index 34a444658ffe..8ee19a4a6bce 100644
--- a/drivers/char/agp/i460-agp.c
+++ b/drivers/char/agp/i460-agp.c
@@ -622,7 +622,6 @@ static struct pci_device_id agp_intel_i460_pci_table[] = {
622MODULE_DEVICE_TABLE(pci, agp_intel_i460_pci_table); 622MODULE_DEVICE_TABLE(pci, agp_intel_i460_pci_table);
623 623
624static struct pci_driver agp_intel_i460_pci_driver = { 624static struct pci_driver agp_intel_i460_pci_driver = {
625 .owner = THIS_MODULE,
626 .name = "agpgart-intel-i460", 625 .name = "agpgart-intel-i460",
627 .id_table = agp_intel_i460_pci_table, 626 .id_table = agp_intel_i460_pci_table,
628 .probe = agp_intel_i460_probe, 627 .probe = agp_intel_i460_probe,
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 027161ab88e9..e7bed5047dcc 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -1827,7 +1827,6 @@ static struct pci_device_id agp_intel_pci_table[] = {
1827MODULE_DEVICE_TABLE(pci, agp_intel_pci_table); 1827MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
1828 1828
1829static struct pci_driver agp_intel_pci_driver = { 1829static struct pci_driver agp_intel_pci_driver = {
1830 .owner = THIS_MODULE,
1831 .name = "agpgart-intel", 1830 .name = "agpgart-intel",
1832 .id_table = agp_intel_pci_table, 1831 .id_table = agp_intel_pci_table,
1833 .probe = agp_intel_probe, 1832 .probe = agp_intel_probe,
diff --git a/drivers/char/agp/nvidia-agp.c b/drivers/char/agp/nvidia-agp.c
index 3aed0c5e2f92..80dafa3030bd 100644
--- a/drivers/char/agp/nvidia-agp.c
+++ b/drivers/char/agp/nvidia-agp.c
@@ -398,7 +398,6 @@ static struct pci_device_id agp_nvidia_pci_table[] = {
398MODULE_DEVICE_TABLE(pci, agp_nvidia_pci_table); 398MODULE_DEVICE_TABLE(pci, agp_nvidia_pci_table);
399 399
400static struct pci_driver agp_nvidia_pci_driver = { 400static struct pci_driver agp_nvidia_pci_driver = {
401 .owner = THIS_MODULE,
402 .name = "agpgart-nvidia", 401 .name = "agpgart-nvidia",
403 .id_table = agp_nvidia_pci_table, 402 .id_table = agp_nvidia_pci_table,
404 .probe = agp_nvidia_probe, 403 .probe = agp_nvidia_probe,
diff --git a/drivers/char/agp/sis-agp.c b/drivers/char/agp/sis-agp.c
index a701361a8890..ebc05554045c 100644
--- a/drivers/char/agp/sis-agp.c
+++ b/drivers/char/agp/sis-agp.c
@@ -332,7 +332,6 @@ static struct pci_device_id agp_sis_pci_table[] = {
332MODULE_DEVICE_TABLE(pci, agp_sis_pci_table); 332MODULE_DEVICE_TABLE(pci, agp_sis_pci_table);
333 333
334static struct pci_driver agp_sis_pci_driver = { 334static struct pci_driver agp_sis_pci_driver = {
335 .owner = THIS_MODULE,
336 .name = "agpgart-sis", 335 .name = "agpgart-sis",
337 .id_table = agp_sis_pci_table, 336 .id_table = agp_sis_pci_table,
338 .probe = agp_sis_probe, 337 .probe = agp_sis_probe,
diff --git a/drivers/char/agp/sworks-agp.c b/drivers/char/agp/sworks-agp.c
index 5a5392dd1254..3f8f7fa6b0ff 100644
--- a/drivers/char/agp/sworks-agp.c
+++ b/drivers/char/agp/sworks-agp.c
@@ -545,7 +545,6 @@ static struct pci_device_id agp_serverworks_pci_table[] = {
545MODULE_DEVICE_TABLE(pci, agp_serverworks_pci_table); 545MODULE_DEVICE_TABLE(pci, agp_serverworks_pci_table);
546 546
547static struct pci_driver agp_serverworks_pci_driver = { 547static struct pci_driver agp_serverworks_pci_driver = {
548 .owner = THIS_MODULE,
549 .name = "agpgart-serverworks", 548 .name = "agpgart-serverworks",
550 .id_table = agp_serverworks_pci_table, 549 .id_table = agp_serverworks_pci_table,
551 .probe = agp_serverworks_probe, 550 .probe = agp_serverworks_probe,
diff --git a/drivers/char/agp/uninorth-agp.c b/drivers/char/agp/uninorth-agp.c
index 183c50acab27..50947e38501a 100644
--- a/drivers/char/agp/uninorth-agp.c
+++ b/drivers/char/agp/uninorth-agp.c
@@ -557,6 +557,10 @@ static struct agp_device_ids uninorth_agp_device_ids[] __devinitdata = {
557 .device_id = PCI_DEVICE_ID_APPLE_U3H_AGP, 557 .device_id = PCI_DEVICE_ID_APPLE_U3H_AGP,
558 .chipset_name = "U3H", 558 .chipset_name = "U3H",
559 }, 559 },
560 {
561 .device_id = PCI_DEVICE_ID_APPLE_IPID2_AGP,
562 .chipset_name = "UniNorth/Intrepid2",
563 },
560}; 564};
561 565
562static int __devinit agp_uninorth_probe(struct pci_dev *pdev, 566static int __devinit agp_uninorth_probe(struct pci_dev *pdev,
@@ -658,7 +662,6 @@ static struct pci_device_id agp_uninorth_pci_table[] = {
658MODULE_DEVICE_TABLE(pci, agp_uninorth_pci_table); 662MODULE_DEVICE_TABLE(pci, agp_uninorth_pci_table);
659 663
660static struct pci_driver agp_uninorth_pci_driver = { 664static struct pci_driver agp_uninorth_pci_driver = {
661 .owner = THIS_MODULE,
662 .name = "agpgart-uninorth", 665 .name = "agpgart-uninorth",
663 .id_table = agp_uninorth_pci_table, 666 .id_table = agp_uninorth_pci_table,
664 .probe = agp_uninorth_probe, 667 .probe = agp_uninorth_probe,
diff --git a/drivers/char/agp/via-agp.c b/drivers/char/agp/via-agp.c
index 5d9a13700074..97b0a890ba7f 100644
--- a/drivers/char/agp/via-agp.c
+++ b/drivers/char/agp/via-agp.c
@@ -371,6 +371,11 @@ static struct agp_device_ids via_agp_device_ids[] __devinitdata =
371 .device_id = PCI_DEVICE_ID_VIA_3296_0, 371 .device_id = PCI_DEVICE_ID_VIA_3296_0,
372 .chipset_name = "P4M800", 372 .chipset_name = "P4M800",
373 }, 373 },
374 /* P4M800CE */
375 {
376 .device_id = PCI_DEVICE_ID_VIA_P4M800CE,
377 .chipset_name = "P4M800CE",
378 },
374 379
375 { }, /* dummy final entry, always present */ 380 { }, /* dummy final entry, always present */
376}; 381};
@@ -511,6 +516,7 @@ static struct pci_device_id agp_via_pci_table[] = {
511 ID(PCI_DEVICE_ID_VIA_3269_0), 516 ID(PCI_DEVICE_ID_VIA_3269_0),
512 ID(PCI_DEVICE_ID_VIA_83_87XX_1), 517 ID(PCI_DEVICE_ID_VIA_83_87XX_1),
513 ID(PCI_DEVICE_ID_VIA_3296_0), 518 ID(PCI_DEVICE_ID_VIA_3296_0),
519 ID(PCI_DEVICE_ID_VIA_P4M800CE),
514 { } 520 { }
515}; 521};
516 522
@@ -518,7 +524,6 @@ MODULE_DEVICE_TABLE(pci, agp_via_pci_table);
518 524
519 525
520static struct pci_driver agp_via_pci_driver = { 526static struct pci_driver agp_via_pci_driver = {
521 .owner = THIS_MODULE,
522 .name = "agpgart-via", 527 .name = "agpgart-via",
523 .id_table = agp_via_pci_table, 528 .id_table = agp_via_pci_table,
524 .probe = agp_via_probe, 529 .probe = agp_via_probe,
diff --git a/drivers/char/drm/drm_lock.c b/drivers/char/drm/drm_lock.c
index f970dc36c18f..f9e45303498d 100644
--- a/drivers/char/drm/drm_lock.c
+++ b/drivers/char/drm/drm_lock.c
@@ -104,8 +104,9 @@ int drm_lock(struct inode *inode, struct file *filp,
104 __set_current_state(TASK_RUNNING); 104 __set_current_state(TASK_RUNNING);
105 remove_wait_queue(&dev->lock.lock_queue, &entry); 105 remove_wait_queue(&dev->lock.lock_queue, &entry);
106 106
107 DRM_DEBUG( "%d %s\n", lock.context, ret ? "interrupted" : "has lock" ); 107 DRM_DEBUG("%d %s\n", lock.context, ret ? "interrupted" : "has lock");
108 if (ret) return ret; 108 if (ret)
109 return ret;
109 110
110 sigemptyset(&dev->sigmask); 111 sigemptyset(&dev->sigmask);
111 sigaddset(&dev->sigmask, SIGSTOP); 112 sigaddset(&dev->sigmask, SIGSTOP);
@@ -121,17 +122,19 @@ int drm_lock(struct inode *inode, struct file *filp,
121 122
122 if (dev->driver->dma_quiescent && (lock.flags & _DRM_LOCK_QUIESCENT)) { 123 if (dev->driver->dma_quiescent && (lock.flags & _DRM_LOCK_QUIESCENT)) {
123 if (dev->driver->dma_quiescent(dev)) { 124 if (dev->driver->dma_quiescent(dev)) {
124 DRM_DEBUG( "%d waiting for DMA quiescent\n", lock.context); 125 DRM_DEBUG("%d waiting for DMA quiescent\n", lock.context);
125 return DRM_ERR(EBUSY); 126 return DRM_ERR(EBUSY);
126 } 127 }
127 } 128 }
128 129
130 /* dev->driver->kernel_context_switch isn't used by any of the x86
131 * drivers but is used by the Sparc driver.
132 */
129 if (dev->driver->kernel_context_switch && 133 if (dev->driver->kernel_context_switch &&
130 dev->last_context != lock.context) { 134 dev->last_context != lock.context) {
131 dev->driver->kernel_context_switch(dev, dev->last_context, 135 dev->driver->kernel_context_switch(dev, dev->last_context,
132 lock.context); 136 lock.context);
133 } 137 }
134
135 return 0; 138 return 0;
136} 139}
137 140
diff --git a/drivers/char/drm/drm_memory.c b/drivers/char/drm/drm_memory.c
index 7438741c29e9..8074771e348f 100644
--- a/drivers/char/drm/drm_memory.c
+++ b/drivers/char/drm/drm_memory.c
@@ -95,7 +95,7 @@ unsigned long drm_alloc_pages(int order, int area)
95 unsigned long addr; 95 unsigned long addr;
96 unsigned int sz; 96 unsigned int sz;
97 97
98 address = __get_free_pages(GFP_KERNEL, order); 98 address = __get_free_pages(GFP_KERNEL|__GFP_COMP, order);
99 if (!address) 99 if (!address)
100 return 0; 100 return 0;
101 101
diff --git a/drivers/char/drm/drm_memory_debug.h b/drivers/char/drm/drm_memory_debug.h
index 706b75251ea1..e84605fc54af 100644
--- a/drivers/char/drm/drm_memory_debug.h
+++ b/drivers/char/drm/drm_memory_debug.h
@@ -220,7 +220,7 @@ unsigned long drm_alloc_pages (int order, int area) {
220 } 220 }
221 spin_unlock(&drm_mem_lock); 221 spin_unlock(&drm_mem_lock);
222 222
223 address = __get_free_pages(GFP_KERNEL, order); 223 address = __get_free_pages(GFP_KERNEL|__GFP_COMP, order);
224 if (!address) { 224 if (!address) {
225 spin_lock(&drm_mem_lock); 225 spin_lock(&drm_mem_lock);
226 ++drm_mem_stats[area].fail_count; 226 ++drm_mem_stats[area].fail_count;
diff --git a/drivers/char/drm/mga_drv.c b/drivers/char/drm/mga_drv.c
index 93f171e634c0..9f7ed0e0351b 100644
--- a/drivers/char/drm/mga_drv.c
+++ b/drivers/char/drm/mga_drv.c
@@ -131,7 +131,7 @@ static int mga_driver_device_is_agp(drm_device_t * dev)
131 * device. 131 * device.
132 */ 132 */
133 133
134 if ((pdev->device == 0x0525) 134 if ((pdev->device == 0x0525) && pdev->bus->self
135 && (pdev->bus->self->vendor == 0x3388) 135 && (pdev->bus->self->vendor == 0x3388)
136 && (pdev->bus->self->device == 0x0021)) { 136 && (pdev->bus->self->device == 0x0021)) {
137 return 0; 137 return 0;
diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h
index 498b19b1d641..fac0d5196ce3 100644
--- a/drivers/char/drm/radeon_drv.h
+++ b/drivers/char/drm/radeon_drv.h
@@ -273,6 +273,7 @@ typedef struct drm_radeon_private {
273 273
274 /* starting from here on, data is preserved accross an open */ 274 /* starting from here on, data is preserved accross an open */
275 uint32_t flags; /* see radeon_chip_flags */ 275 uint32_t flags; /* see radeon_chip_flags */
276 int is_pci;
276} drm_radeon_private_t; 277} drm_radeon_private_t;
277 278
278typedef struct drm_radeon_buf_priv { 279typedef struct drm_radeon_buf_priv {
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index b7a0e4d6b934..407708a001e4 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -3113,7 +3113,6 @@ MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3113int __init init_PCI (void) 3113int __init init_PCI (void)
3114{ /* Begin init_PCI */ 3114{ /* Begin init_PCI */
3115 memset (&epca_driver, 0, sizeof (epca_driver)); 3115 memset (&epca_driver, 0, sizeof (epca_driver));
3116 epca_driver.owner = THIS_MODULE;
3117 epca_driver.name = "epca"; 3116 epca_driver.name = "epca";
3118 epca_driver.id_table = epca_pci_tbl; 3117 epca_driver.id_table = epca_pci_tbl;
3119 epca_driver.probe = epca_init_one; 3118 epca_driver.probe = epca_init_one;
diff --git a/drivers/char/ftape/lowlevel/ftape-buffer.c b/drivers/char/ftape/lowlevel/ftape-buffer.c
index 54af20cd9a2c..c706ff162771 100644
--- a/drivers/char/ftape/lowlevel/ftape-buffer.c
+++ b/drivers/char/ftape/lowlevel/ftape-buffer.c
@@ -33,6 +33,7 @@
33#include "../lowlevel/ftape-rw.h" 33#include "../lowlevel/ftape-rw.h"
34#include "../lowlevel/ftape-read.h" 34#include "../lowlevel/ftape-read.h"
35#include "../lowlevel/ftape-tracing.h" 35#include "../lowlevel/ftape-tracing.h"
36#include "../lowlevel/ftape-buffer.h"
36 37
37/* DMA'able memory allocation stuff. 38/* DMA'able memory allocation stuff.
38 */ 39 */
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index 6c4b3f986d0c..f3c3aaf4560e 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -99,7 +99,9 @@ struct smm_regs {
99 99
100static inline char *i8k_get_dmi_data(int field) 100static inline char *i8k_get_dmi_data(int field)
101{ 101{
102 return dmi_get_system_info(field) ? : "N/A"; 102 char *dmi_data = dmi_get_system_info(field);
103
104 return dmi_data && *dmi_data ? dmi_data : "?";
103} 105}
104 106
105/* 107/*
@@ -396,7 +398,7 @@ static int i8k_proc_show(struct seq_file *seq, void *offset)
396 return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n", 398 return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
397 I8K_PROC_FMT, 399 I8K_PROC_FMT,
398 bios_version, 400 bios_version,
399 dmi_get_system_info(DMI_PRODUCT_SERIAL) ? : "N/A", 401 i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
400 cpu_temp, 402 cpu_temp,
401 left_fan, right_fan, left_speed, right_speed, 403 left_fan, right_fan, left_speed, right_speed,
402 ac_power, fn_key); 404 ac_power, fn_key);
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index c1d06ba449b6..1f56b4cf0f58 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -48,7 +48,7 @@
48 48
49#define PFX "IPMI message handler: " 49#define PFX "IPMI message handler: "
50 50
51#define IPMI_DRIVER_VERSION "36.0" 51#define IPMI_DRIVER_VERSION "38.0"
52 52
53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); 53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void);
54static int ipmi_init_msghandler(void); 54static int ipmi_init_msghandler(void);
@@ -2648,7 +2648,7 @@ void ipmi_smi_msg_received(ipmi_smi_t intf,
2648 spin_lock_irqsave(&intf->waiting_msgs_lock, flags); 2648 spin_lock_irqsave(&intf->waiting_msgs_lock, flags);
2649 if (!list_empty(&intf->waiting_msgs)) { 2649 if (!list_empty(&intf->waiting_msgs)) {
2650 list_add_tail(&msg->link, &intf->waiting_msgs); 2650 list_add_tail(&msg->link, &intf->waiting_msgs);
2651 spin_unlock(&intf->waiting_msgs_lock); 2651 spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags);
2652 goto out; 2652 goto out;
2653 } 2653 }
2654 spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); 2654 spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags);
@@ -2657,9 +2657,9 @@ void ipmi_smi_msg_received(ipmi_smi_t intf,
2657 if (rv > 0) { 2657 if (rv > 0) {
2658 /* Could not handle the message now, just add it to a 2658 /* Could not handle the message now, just add it to a
2659 list to handle later. */ 2659 list to handle later. */
2660 spin_lock(&intf->waiting_msgs_lock); 2660 spin_lock_irqsave(&intf->waiting_msgs_lock, flags);
2661 list_add_tail(&msg->link, &intf->waiting_msgs); 2661 list_add_tail(&msg->link, &intf->waiting_msgs);
2662 spin_unlock(&intf->waiting_msgs_lock); 2662 spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags);
2663 } else if (rv == 0) { 2663 } else if (rv == 0) {
2664 ipmi_free_smi_msg(msg); 2664 ipmi_free_smi_msg(msg);
2665 } 2665 }
@@ -2986,7 +2986,7 @@ static void send_panic_events(char *str)
2986 msg.cmd = 2; /* Platform event command. */ 2986 msg.cmd = 2; /* Platform event command. */
2987 msg.data = data; 2987 msg.data = data;
2988 msg.data_len = 8; 2988 msg.data_len = 8;
2989 data[0] = 0x21; /* Kernel generator ID, IPMI table 5-4 */ 2989 data[0] = 0x41; /* Kernel generator ID, IPMI table 5-4 */
2990 data[1] = 0x03; /* This is for IPMI 1.0. */ 2990 data[1] = 0x03; /* This is for IPMI 1.0. */
2991 data[2] = 0x20; /* OS Critical Stop, IPMI table 36-3 */ 2991 data[2] = 0x20; /* OS Critical Stop, IPMI table 36-3 */
2992 data[4] = 0x6f; /* Sensor specific, IPMI table 36-1 */ 2992 data[4] = 0x6f; /* Sensor specific, IPMI table 36-1 */
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index ea89dca3dbb5..beea450ee4b2 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -2203,7 +2203,7 @@ static void setup_xaction_handlers(struct smi_info *smi_info)
2203 2203
2204static inline void wait_for_timer_and_thread(struct smi_info *smi_info) 2204static inline void wait_for_timer_and_thread(struct smi_info *smi_info)
2205{ 2205{
2206 if (smi_info->thread != ERR_PTR(-ENOMEM)) 2206 if (smi_info->thread != NULL && smi_info->thread != ERR_PTR(-ENOMEM))
2207 kthread_stop(smi_info->thread); 2207 kthread_stop(smi_info->thread);
2208 del_timer_sync(&smi_info->si_timer); 2208 del_timer_sync(&smi_info->si_timer);
2209} 2209}
@@ -2399,7 +2399,8 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2399 new_smi->handlers->cleanup(new_smi->si_sm); 2399 new_smi->handlers->cleanup(new_smi->si_sm);
2400 kfree(new_smi->si_sm); 2400 kfree(new_smi->si_sm);
2401 } 2401 }
2402 new_smi->io_cleanup(new_smi); 2402 if (new_smi->io_cleanup)
2403 new_smi->io_cleanup(new_smi);
2403 2404
2404 return rv; 2405 return rv;
2405} 2406}
@@ -2518,7 +2519,8 @@ static void __exit cleanup_one_si(struct smi_info *to_clean)
2518 2519
2519 kfree(to_clean->si_sm); 2520 kfree(to_clean->si_sm);
2520 2521
2521 to_clean->io_cleanup(to_clean); 2522 if (to_clean->io_cleanup)
2523 to_clean->io_cleanup(to_clean);
2522} 2524}
2523 2525
2524static __exit void cleanup_ipmi_si(void) 2526static __exit void cleanup_ipmi_si(void)
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 449d029ad4f4..8b603b2d1c42 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -930,8 +930,8 @@ static void kbd_refresh_leds(struct input_handle *handle)
930} 930}
931 931
932#if defined(CONFIG_X86) || defined(CONFIG_IA64) || defined(CONFIG_ALPHA) ||\ 932#if defined(CONFIG_X86) || defined(CONFIG_IA64) || defined(CONFIG_ALPHA) ||\
933 defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_SPARC32) ||\ 933 defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) ||\
934 defined(CONFIG_SPARC64) || defined(CONFIG_PARISC) || defined(CONFIG_SUPERH) ||\ 934 defined(CONFIG_PARISC) || defined(CONFIG_SUPERH) ||\
935 (defined(CONFIG_ARM) && defined(CONFIG_KEYBOARD_ATKBD) && !defined(CONFIG_ARCH_RPC)) 935 (defined(CONFIG_ARM) && defined(CONFIG_KEYBOARD_ATKBD) && !defined(CONFIG_ARCH_RPC))
936 936
937#define HW_RAW(dev) (test_bit(EV_MSC, dev->evbit) && test_bit(MSC_RAW, dev->mscbit) &&\ 937#define HW_RAW(dev) (test_bit(EV_MSC, dev->evbit) && test_bit(MSC_RAW, dev->mscbit) &&\
@@ -958,7 +958,7 @@ static unsigned short x86_keycodes[256] =
958extern int mac_hid_mouse_emulate_buttons(int, int, int); 958extern int mac_hid_mouse_emulate_buttons(int, int, int);
959#endif /* CONFIG_MAC_EMUMOUSEBTN */ 959#endif /* CONFIG_MAC_EMUMOUSEBTN */
960 960
961#if defined(CONFIG_SPARC32) || defined(CONFIG_SPARC64) 961#ifdef CONFIG_SPARC
962static int sparc_l1_a_state = 0; 962static int sparc_l1_a_state = 0;
963extern void sun_do_break(void); 963extern void sun_do_break(void);
964#endif 964#endif
@@ -1045,7 +1045,7 @@ static void kbd_keycode(unsigned int keycode, int down,
1045 1045
1046 if (keycode == KEY_LEFTALT || keycode == KEY_RIGHTALT) 1046 if (keycode == KEY_LEFTALT || keycode == KEY_RIGHTALT)
1047 sysrq_alt = down; 1047 sysrq_alt = down;
1048#if defined(CONFIG_SPARC32) || defined(CONFIG_SPARC64) 1048#ifdef CONFIG_SPARC
1049 if (keycode == KEY_STOP) 1049 if (keycode == KEY_STOP)
1050 sparc_l1_a_state = down; 1050 sparc_l1_a_state = down;
1051#endif 1051#endif
@@ -1072,7 +1072,7 @@ static void kbd_keycode(unsigned int keycode, int down,
1072 return; 1072 return;
1073 } 1073 }
1074#endif 1074#endif
1075#if defined(CONFIG_SPARC32) || defined(CONFIG_SPARC64) 1075#ifdef CONFIG_SPARC
1076 if (keycode == KEY_A && sparc_l1_a_state) { 1076 if (keycode == KEY_A && sparc_l1_a_state) {
1077 sparc_l1_a_state = 0; 1077 sparc_l1_a_state = 0;
1078 sun_do_break(); 1078 sun_do_break();
diff --git a/drivers/char/mwave/mwavepub.h b/drivers/char/mwave/mwavepub.h
index f1f9da7a65c1..60c961ae23b4 100644
--- a/drivers/char/mwave/mwavepub.h
+++ b/drivers/char/mwave/mwavepub.h
@@ -69,7 +69,7 @@ typedef struct _MW_ABILITIES {
69typedef struct _MW_READWRITE { 69typedef struct _MW_READWRITE {
70 unsigned short usDspAddress; /* The dsp address */ 70 unsigned short usDspAddress; /* The dsp address */
71 unsigned long ulDataLength; /* The size in bytes of the data or user buffer */ 71 unsigned long ulDataLength; /* The size in bytes of the data or user buffer */
72 void *pBuf; /* Input:variable sized buffer */ 72 void __user *pBuf; /* Input:variable sized buffer */
73} MW_READWRITE, *pMW_READWRITE; 73} MW_READWRITE, *pMW_READWRITE;
74 74
75#define IOCTL_MW_RESET _IO(MWAVE_MINOR,1) 75#define IOCTL_MW_RESET _IO(MWAVE_MINOR,1)
diff --git a/drivers/char/pcmcia/Kconfig b/drivers/char/pcmcia/Kconfig
index d22bfdc13563..27c1179ee527 100644
--- a/drivers/char/pcmcia/Kconfig
+++ b/drivers/char/pcmcia/Kconfig
@@ -18,5 +18,29 @@ config SYNCLINK_CS
18 The module will be called synclinkmp. If you want to do that, say M 18 The module will be called synclinkmp. If you want to do that, say M
19 here. 19 here.
20 20
21config CARDMAN_4000
22 tristate "Omnikey Cardman 4000 support"
23 depends on PCMCIA
24 help
25 Enable support for the Omnikey Cardman 4000 PCMCIA Smartcard
26 reader.
27
28 This kernel driver requires additional userspace support, either
29 by the vendor-provided PC/SC ifd_handler (http://www.omnikey.com/),
30 or via the cm4000 backend of OpenCT (http://www.opensc.com/).
31
32config CARDMAN_4040
33 tristate "Omnikey CardMan 4040 support"
34 depends on PCMCIA
35 help
36 Enable support for the Omnikey CardMan 4040 PCMCIA Smartcard
37 reader.
38
39 This card is basically a USB CCID device connected to a FIFO
40 in I/O space. To use the kernel driver, you will need either the
41 PC/SC ifdhandler provided from the Omnikey homepage
42 (http://www.omnikey.com/), or a current development version of OpenCT
43 (http://www.opensc.org/).
44
21endmenu 45endmenu
22 46
diff --git a/drivers/char/pcmcia/Makefile b/drivers/char/pcmcia/Makefile
index 1fcd4c591958..0aae20985d57 100644
--- a/drivers/char/pcmcia/Makefile
+++ b/drivers/char/pcmcia/Makefile
@@ -5,3 +5,5 @@
5# 5#
6 6
7obj-$(CONFIG_SYNCLINK_CS) += synclink_cs.o 7obj-$(CONFIG_SYNCLINK_CS) += synclink_cs.o
8obj-$(CONFIG_CARDMAN_4000) += cm4000_cs.o
9obj-$(CONFIG_CARDMAN_4040) += cm4040_cs.o
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
new file mode 100644
index 000000000000..61681c9f3f72
--- /dev/null
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -0,0 +1,2079 @@
1 /*
2 * A driver for the PCMCIA Smartcard Reader "Omnikey CardMan Mobile 4000"
3 *
4 * cm4000_cs.c support.linux@omnikey.com
5 *
6 * Tue Oct 23 11:32:43 GMT 2001 herp - cleaned up header files
7 * Sun Jan 20 10:11:15 MET 2002 herp - added modversion header files
8 * Thu Nov 14 16:34:11 GMT 2002 mh - added PPS functionality
9 * Tue Nov 19 16:36:27 GMT 2002 mh - added SUSPEND/RESUME functionailty
10 * Wed Jul 28 12:55:01 CEST 2004 mh - kernel 2.6 adjustments
11 *
12 * current version: 2.4.0gm4
13 *
14 * (C) 2000,2001,2002,2003,2004 Omnikey AG
15 *
16 * (C) 2005 Harald Welte <laforge@gnumonks.org>
17 * - Adhere to Kernel CodingStyle
18 * - Port to 2.6.13 "new" style PCMCIA
19 * - Check for copy_{from,to}_user return values
20 * - Use nonseekable_open()
21 *
22 * All rights reserved. Licensed under dual BSD/GPL license.
23 */
24
25/* #define PCMCIA_DEBUG 6 */
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/slab.h>
30#include <linux/init.h>
31#include <linux/fs.h>
32#include <linux/delay.h>
33#include <asm/uaccess.h>
34#include <asm/io.h>
35
36#include <pcmcia/cs_types.h>
37#include <pcmcia/cs.h>
38#include <pcmcia/cistpl.h>
39#include <pcmcia/cisreg.h>
40#include <pcmcia/ciscode.h>
41#include <pcmcia/ds.h>
42
43#include <linux/cm4000_cs.h>
44
45/* #define ATR_CSUM */
46
47#ifdef PCMCIA_DEBUG
48#define reader_to_dev(x) (&handle_to_dev(x->link.handle))
49static int pc_debug = PCMCIA_DEBUG;
50module_param(pc_debug, int, 0600);
51#define DEBUGP(n, rdr, x, args...) do { \
52 if (pc_debug >= (n)) \
53 dev_printk(KERN_DEBUG, reader_to_dev(rdr), "%s:" x, \
54 __FUNCTION__ , ## args); \
55 } while (0)
56#else
57#define DEBUGP(n, rdr, x, args...)
58#endif
59static char *version = "cm4000_cs.c v2.4.0gm5 - All bugs added by Harald Welte";
60
61#define T_1SEC (HZ)
62#define T_10MSEC msecs_to_jiffies(10)
63#define T_20MSEC msecs_to_jiffies(20)
64#define T_40MSEC msecs_to_jiffies(40)
65#define T_50MSEC msecs_to_jiffies(50)
66#define T_100MSEC msecs_to_jiffies(100)
67#define T_500MSEC msecs_to_jiffies(500)
68
69static void cm4000_detach(dev_link_t *link);
70static void cm4000_release(dev_link_t *link);
71
72static int major; /* major number we get from the kernel */
73
74/* note: the first state has to have number 0 always */
75
76#define M_FETCH_ATR 0
77#define M_TIMEOUT_WAIT 1
78#define M_READ_ATR_LEN 2
79#define M_READ_ATR 3
80#define M_ATR_PRESENT 4
81#define M_BAD_CARD 5
82#define M_CARDOFF 6
83
84#define LOCK_IO 0
85#define LOCK_MONITOR 1
86
87#define IS_AUTOPPS_ACT 6
88#define IS_PROCBYTE_PRESENT 7
89#define IS_INVREV 8
90#define IS_ANY_T0 9
91#define IS_ANY_T1 10
92#define IS_ATR_PRESENT 11
93#define IS_ATR_VALID 12
94#define IS_CMM_ABSENT 13
95#define IS_BAD_LENGTH 14
96#define IS_BAD_CSUM 15
97#define IS_BAD_CARD 16
98
99#define REG_FLAGS0(x) (x + 0)
100#define REG_FLAGS1(x) (x + 1)
101#define REG_NUM_BYTES(x) (x + 2)
102#define REG_BUF_ADDR(x) (x + 3)
103#define REG_BUF_DATA(x) (x + 4)
104#define REG_NUM_SEND(x) (x + 5)
105#define REG_BAUDRATE(x) (x + 6)
106#define REG_STOPBITS(x) (x + 7)
107
108struct cm4000_dev {
109 dev_link_t link; /* pcmcia link */
110 dev_node_t node; /* OS node (major,minor) */
111
112 unsigned char atr[MAX_ATR];
113 unsigned char rbuf[512];
114 unsigned char sbuf[512];
115
116 wait_queue_head_t devq; /* when removing cardman must not be
117 zeroed! */
118
119 wait_queue_head_t ioq; /* if IO is locked, wait on this Q */
120 wait_queue_head_t atrq; /* wait for ATR valid */
121 wait_queue_head_t readq; /* used by write to wake blk.read */
122
123 /* warning: do not move this fields.
124 * initialising to zero depends on it - see ZERO_DEV below. */
125 unsigned char atr_csum;
126 unsigned char atr_len_retry;
127 unsigned short atr_len;
128 unsigned short rlen; /* bytes avail. after write */
129 unsigned short rpos; /* latest read pos. write zeroes */
130 unsigned char procbyte; /* T=0 procedure byte */
131 unsigned char mstate; /* state of card monitor */
132 unsigned char cwarn; /* slow down warning */
133 unsigned char flags0; /* cardman IO-flags 0 */
134 unsigned char flags1; /* cardman IO-flags 1 */
135 unsigned int mdelay; /* variable monitor speeds, in jiffies */
136
137 unsigned int baudv; /* baud value for speed */
138 unsigned char ta1;
139 unsigned char proto; /* T=0, T=1, ... */
140 unsigned long flags; /* lock+flags (MONITOR,IO,ATR) * for concurrent
141 access */
142
143 unsigned char pts[4];
144
145 struct timer_list timer; /* used to keep monitor running */
146 int monitor_running;
147};
148
149#define ZERO_DEV(dev) \
150 memset(&dev->atr_csum,0, \
151 sizeof(struct cm4000_dev) - \
152 /*link*/ sizeof(dev_link_t) - \
153 /*node*/ sizeof(dev_node_t) - \
154 /*atr*/ MAX_ATR*sizeof(char) - \
155 /*rbuf*/ 512*sizeof(char) - \
156 /*sbuf*/ 512*sizeof(char) - \
157 /*queue*/ 4*sizeof(wait_queue_head_t))
158
159static dev_info_t dev_info = MODULE_NAME;
160static dev_link_t *dev_table[CM4000_MAX_DEV];
161
162/* This table doesn't use spaces after the comma between fields and thus
163 * violates CodingStyle. However, I don't really think wrapping it around will
164 * make it any clearer to read -HW */
165static unsigned char fi_di_table[10][14] = {
166/*FI 00 01 02 03 04 05 06 07 08 09 10 11 12 13 */
167/*DI */
168/* 0 */ {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
169/* 1 */ {0x01,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x91,0x11,0x11,0x11,0x11},
170/* 2 */ {0x02,0x12,0x22,0x32,0x11,0x11,0x11,0x11,0x11,0x92,0xA2,0xB2,0x11,0x11},
171/* 3 */ {0x03,0x13,0x23,0x33,0x43,0x53,0x63,0x11,0x11,0x93,0xA3,0xB3,0xC3,0xD3},
172/* 4 */ {0x04,0x14,0x24,0x34,0x44,0x54,0x64,0x11,0x11,0x94,0xA4,0xB4,0xC4,0xD4},
173/* 5 */ {0x00,0x15,0x25,0x35,0x45,0x55,0x65,0x11,0x11,0x95,0xA5,0xB5,0xC5,0xD5},
174/* 6 */ {0x06,0x16,0x26,0x36,0x46,0x56,0x66,0x11,0x11,0x96,0xA6,0xB6,0xC6,0xD6},
175/* 7 */ {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
176/* 8 */ {0x08,0x11,0x28,0x38,0x48,0x58,0x68,0x11,0x11,0x98,0xA8,0xB8,0xC8,0xD8},
177/* 9 */ {0x09,0x19,0x29,0x39,0x49,0x59,0x69,0x11,0x11,0x99,0xA9,0xB9,0xC9,0xD9}
178};
179
180#ifndef PCMCIA_DEBUG
181#define xoutb outb
182#define xinb inb
183#else
184static inline void xoutb(unsigned char val, unsigned short port)
185{
186 if (pc_debug >= 7)
187 printk(KERN_DEBUG "outb(val=%.2x,port=%.4x)\n", val, port);
188 outb(val, port);
189}
190static inline unsigned char xinb(unsigned short port)
191{
192 unsigned char val;
193
194 val = inb(port);
195 if (pc_debug >= 7)
196 printk(KERN_DEBUG "%.2x=inb(%.4x)\n", val, port);
197
198 return val;
199}
200#endif
201
202#define b_0000 15
203#define b_0001 14
204#define b_0010 13
205#define b_0011 12
206#define b_0100 11
207#define b_0101 10
208#define b_0110 9
209#define b_0111 8
210#define b_1000 7
211#define b_1001 6
212#define b_1010 5
213#define b_1011 4
214#define b_1100 3
215#define b_1101 2
216#define b_1110 1
217#define b_1111 0
218
219static unsigned char irtab[16] = {
220 b_0000, b_1000, b_0100, b_1100,
221 b_0010, b_1010, b_0110, b_1110,
222 b_0001, b_1001, b_0101, b_1101,
223 b_0011, b_1011, b_0111, b_1111
224};
225
226static void str_invert_revert(unsigned char *b, int len)
227{
228 int i;
229
230 for (i = 0; i < len; i++)
231 b[i] = (irtab[b[i] & 0x0f] << 4) | irtab[b[i] >> 4];
232}
233
234static unsigned char invert_revert(unsigned char ch)
235{
236 return (irtab[ch & 0x0f] << 4) | irtab[ch >> 4];
237}
238
239#define ATRLENCK(dev,pos) \
240 if (pos>=dev->atr_len || pos>=MAX_ATR) \
241 goto return_0;
242
243static unsigned int calc_baudv(unsigned char fidi)
244{
245 unsigned int wcrcf, wbrcf, fi_rfu, di_rfu;
246
247 fi_rfu = 372;
248 di_rfu = 1;
249
250 /* FI */
251 switch ((fidi >> 4) & 0x0F) {
252 case 0x00:
253 wcrcf = 372;
254 break;
255 case 0x01:
256 wcrcf = 372;
257 break;
258 case 0x02:
259 wcrcf = 558;
260 break;
261 case 0x03:
262 wcrcf = 744;
263 break;
264 case 0x04:
265 wcrcf = 1116;
266 break;
267 case 0x05:
268 wcrcf = 1488;
269 break;
270 case 0x06:
271 wcrcf = 1860;
272 break;
273 case 0x07:
274 wcrcf = fi_rfu;
275 break;
276 case 0x08:
277 wcrcf = fi_rfu;
278 break;
279 case 0x09:
280 wcrcf = 512;
281 break;
282 case 0x0A:
283 wcrcf = 768;
284 break;
285 case 0x0B:
286 wcrcf = 1024;
287 break;
288 case 0x0C:
289 wcrcf = 1536;
290 break;
291 case 0x0D:
292 wcrcf = 2048;
293 break;
294 default:
295 wcrcf = fi_rfu;
296 break;
297 }
298
299 /* DI */
300 switch (fidi & 0x0F) {
301 case 0x00:
302 wbrcf = di_rfu;
303 break;
304 case 0x01:
305 wbrcf = 1;
306 break;
307 case 0x02:
308 wbrcf = 2;
309 break;
310 case 0x03:
311 wbrcf = 4;
312 break;
313 case 0x04:
314 wbrcf = 8;
315 break;
316 case 0x05:
317 wbrcf = 16;
318 break;
319 case 0x06:
320 wbrcf = 32;
321 break;
322 case 0x07:
323 wbrcf = di_rfu;
324 break;
325 case 0x08:
326 wbrcf = 12;
327 break;
328 case 0x09:
329 wbrcf = 20;
330 break;
331 default:
332 wbrcf = di_rfu;
333 break;
334 }
335
336 return (wcrcf / wbrcf);
337}
338
339static unsigned short io_read_num_rec_bytes(ioaddr_t iobase, unsigned short *s)
340{
341 unsigned short tmp;
342
343 tmp = *s = 0;
344 do {
345 *s = tmp;
346 tmp = inb(REG_NUM_BYTES(iobase)) |
347 (inb(REG_FLAGS0(iobase)) & 4 ? 0x100 : 0);
348 } while (tmp != *s);
349
350 return *s;
351}
352
353static int parse_atr(struct cm4000_dev *dev)
354{
355 unsigned char any_t1, any_t0;
356 unsigned char ch, ifno;
357 int ix, done;
358
359 DEBUGP(3, dev, "-> parse_atr: dev->atr_len = %i\n", dev->atr_len);
360
361 if (dev->atr_len < 3) {
362 DEBUGP(5, dev, "parse_atr: atr_len < 3\n");
363 return 0;
364 }
365
366 if (dev->atr[0] == 0x3f)
367 set_bit(IS_INVREV, &dev->flags);
368 else
369 clear_bit(IS_INVREV, &dev->flags);
370 ix = 1;
371 ifno = 1;
372 ch = dev->atr[1];
373 dev->proto = 0; /* XXX PROTO */
374 any_t1 = any_t0 = done = 0;
375 dev->ta1 = 0x11; /* defaults to 9600 baud */
376 do {
377 if (ifno == 1 && (ch & 0x10)) {
378 /* read first interface byte and TA1 is present */
379 dev->ta1 = dev->atr[2];
380 DEBUGP(5, dev, "Card says FiDi is 0x%.2x\n", dev->ta1);
381 ifno++;
382 } else if ((ifno == 2) && (ch & 0x10)) { /* TA(2) */
383 dev->ta1 = 0x11;
384 ifno++;
385 }
386
387 DEBUGP(5, dev, "Yi=%.2x\n", ch & 0xf0);
388 ix += ((ch & 0x10) >> 4) /* no of int.face chars */
389 +((ch & 0x20) >> 5)
390 + ((ch & 0x40) >> 6)
391 + ((ch & 0x80) >> 7);
392 /* ATRLENCK(dev,ix); */
393 if (ch & 0x80) { /* TDi */
394 ch = dev->atr[ix];
395 if ((ch & 0x0f)) {
396 any_t1 = 1;
397 DEBUGP(5, dev, "card is capable of T=1\n");
398 } else {
399 any_t0 = 1;
400 DEBUGP(5, dev, "card is capable of T=0\n");
401 }
402 } else
403 done = 1;
404 } while (!done);
405
406 DEBUGP(5, dev, "ix=%d noHist=%d any_t1=%d\n",
407 ix, dev->atr[1] & 15, any_t1);
408 if (ix + 1 + (dev->atr[1] & 0x0f) + any_t1 != dev->atr_len) {
409 DEBUGP(5, dev, "length error\n");
410 return 0;
411 }
412 if (any_t0)
413 set_bit(IS_ANY_T0, &dev->flags);
414
415 if (any_t1) { /* compute csum */
416 dev->atr_csum = 0;
417#ifdef ATR_CSUM
418 for (i = 1; i < dev->atr_len; i++)
419 dev->atr_csum ^= dev->atr[i];
420 if (dev->atr_csum) {
421 set_bit(IS_BAD_CSUM, &dev->flags);
422 DEBUGP(5, dev, "bad checksum\n");
423 goto return_0;
424 }
425#endif
426 if (any_t0 == 0)
427 dev->proto = 1; /* XXX PROTO */
428 set_bit(IS_ANY_T1, &dev->flags);
429 }
430
431 return 1;
432}
433
434struct card_fixup {
435 char atr[12];
436 u_int8_t atr_len;
437 u_int8_t stopbits;
438};
439
440static struct card_fixup card_fixups[] = {
441 { /* ACOS */
442 .atr = { 0x3b, 0xb3, 0x11, 0x00, 0x00, 0x41, 0x01 },
443 .atr_len = 7,
444 .stopbits = 0x03,
445 },
446 { /* Motorola */
447 .atr = {0x3b, 0x76, 0x13, 0x00, 0x00, 0x80, 0x62, 0x07,
448 0x41, 0x81, 0x81 },
449 .atr_len = 11,
450 .stopbits = 0x04,
451 },
452};
453
454static void set_cardparameter(struct cm4000_dev *dev)
455{
456 int i;
457 ioaddr_t iobase = dev->link.io.BasePort1;
458 u_int8_t stopbits = 0x02; /* ISO default */
459
460 DEBUGP(3, dev, "-> set_cardparameter\n");
461
462 dev->flags1 = dev->flags1 | (((dev->baudv - 1) & 0x0100) >> 8);
463 xoutb(dev->flags1, REG_FLAGS1(iobase));
464 DEBUGP(5, dev, "flags1 = 0x%02x\n", dev->flags1);
465
466 /* set baudrate */
467 xoutb((unsigned char)((dev->baudv - 1) & 0xFF), REG_BAUDRATE(iobase));
468
469 DEBUGP(5, dev, "baudv = %i -> write 0x%02x\n", dev->baudv,
470 ((dev->baudv - 1) & 0xFF));
471
472 /* set stopbits */
473 for (i = 0; i < ARRAY_SIZE(card_fixups); i++) {
474 if (!memcmp(dev->atr, card_fixups[i].atr,
475 card_fixups[i].atr_len))
476 stopbits = card_fixups[i].stopbits;
477 }
478 xoutb(stopbits, REG_STOPBITS(iobase));
479
480 DEBUGP(3, dev, "<- set_cardparameter\n");
481}
482
483static int set_protocol(struct cm4000_dev *dev, struct ptsreq *ptsreq)
484{
485
486 unsigned long tmp, i;
487 unsigned short num_bytes_read;
488 unsigned char pts_reply[4];
489 ssize_t rc;
490 ioaddr_t iobase = dev->link.io.BasePort1;
491
492 rc = 0;
493
494 DEBUGP(3, dev, "-> set_protocol\n");
495 DEBUGP(5, dev, "ptsreq->Protocol = 0x%.8x, ptsreq->Flags=0x%.8x, "
496 "ptsreq->pts1=0x%.2x, ptsreq->pts2=0x%.2x, "
497 "ptsreq->pts3=0x%.2x\n", (unsigned int)ptsreq->protocol,
498 (unsigned int)ptsreq->flags, ptsreq->pts1, ptsreq->pts2,
499 ptsreq->pts3);
500
501 /* Fill PTS structure */
502 dev->pts[0] = 0xff;
503 dev->pts[1] = 0x00;
504 tmp = ptsreq->protocol;
505 while ((tmp = (tmp >> 1)) > 0)
506 dev->pts[1]++;
507 dev->proto = dev->pts[1]; /* Set new protocol */
508 dev->pts[1] = (0x01 << 4) | (dev->pts[1]);
509
510 /* Correct Fi/Di according to CM4000 Fi/Di table */
511 DEBUGP(5, dev, "Ta(1) from ATR is 0x%.2x\n", dev->ta1);
512 /* set Fi/Di according to ATR TA(1) */
513 dev->pts[2] = fi_di_table[dev->ta1 & 0x0F][(dev->ta1 >> 4) & 0x0F];
514
515 /* Calculate PCK character */
516 dev->pts[3] = dev->pts[0] ^ dev->pts[1] ^ dev->pts[2];
517
518 DEBUGP(5, dev, "pts0=%.2x, pts1=%.2x, pts2=%.2x, pts3=%.2x\n",
519 dev->pts[0], dev->pts[1], dev->pts[2], dev->pts[3]);
520
521 /* check card convention */
522 if (test_bit(IS_INVREV, &dev->flags))
523 str_invert_revert(dev->pts, 4);
524
525 /* reset SM */
526 xoutb(0x80, REG_FLAGS0(iobase));
527
528 /* Enable access to the message buffer */
529 DEBUGP(5, dev, "Enable access to the messages buffer\n");
530 dev->flags1 = 0x20 /* T_Active */
531 | (test_bit(IS_INVREV, &dev->flags) ? 0x02 : 0x00) /* inv parity */
532 | ((dev->baudv >> 8) & 0x01); /* MSB-baud */
533 xoutb(dev->flags1, REG_FLAGS1(iobase));
534
535 DEBUGP(5, dev, "Enable message buffer -> flags1 = 0x%.2x\n",
536 dev->flags1);
537
538 /* write challenge to the buffer */
539 DEBUGP(5, dev, "Write challenge to buffer: ");
540 for (i = 0; i < 4; i++) {
541 xoutb(i, REG_BUF_ADDR(iobase));
542 xoutb(dev->pts[i], REG_BUF_DATA(iobase)); /* buf data */
543#ifdef PCMCIA_DEBUG
544 if (pc_debug >= 5)
545 printk("0x%.2x ", dev->pts[i]);
546 }
547 if (pc_debug >= 5)
548 printk("\n");
549#else
550 }
551#endif
552
553 /* set number of bytes to write */
554 DEBUGP(5, dev, "Set number of bytes to write\n");
555 xoutb(0x04, REG_NUM_SEND(iobase));
556
557 /* Trigger CARDMAN CONTROLLER */
558 xoutb(0x50, REG_FLAGS0(iobase));
559
560 /* Monitor progress */
561 /* wait for xmit done */
562 DEBUGP(5, dev, "Waiting for NumRecBytes getting valid\n");
563
564 for (i = 0; i < 100; i++) {
565 if (inb(REG_FLAGS0(iobase)) & 0x08) {
566 DEBUGP(5, dev, "NumRecBytes is valid\n");
567 break;
568 }
569 mdelay(10);
570 }
571 if (i == 100) {
572 DEBUGP(5, dev, "Timeout waiting for NumRecBytes getting "
573 "valid\n");
574 rc = -EIO;
575 goto exit_setprotocol;
576 }
577
578 DEBUGP(5, dev, "Reading NumRecBytes\n");
579 for (i = 0; i < 100; i++) {
580 io_read_num_rec_bytes(iobase, &num_bytes_read);
581 if (num_bytes_read >= 4) {
582 DEBUGP(2, dev, "NumRecBytes = %i\n", num_bytes_read);
583 break;
584 }
585 mdelay(10);
586 }
587
588 /* check whether it is a short PTS reply? */
589 if (num_bytes_read == 3)
590 i = 0;
591
592 if (i == 100) {
593 DEBUGP(5, dev, "Timeout reading num_bytes_read\n");
594 rc = -EIO;
595 goto exit_setprotocol;
596 }
597
598 DEBUGP(5, dev, "Reset the CARDMAN CONTROLLER\n");
599 xoutb(0x80, REG_FLAGS0(iobase));
600
601 /* Read PPS reply */
602 DEBUGP(5, dev, "Read PPS reply\n");
603 for (i = 0; i < num_bytes_read; i++) {
604 xoutb(i, REG_BUF_ADDR(iobase));
605 pts_reply[i] = inb(REG_BUF_DATA(iobase));
606 }
607
608#ifdef PCMCIA_DEBUG
609 DEBUGP(2, dev, "PTSreply: ");
610 for (i = 0; i < num_bytes_read; i++) {
611 if (pc_debug >= 5)
612 printk("0x%.2x ", pts_reply[i]);
613 }
614 printk("\n");
615#endif /* PCMCIA_DEBUG */
616
617 DEBUGP(5, dev, "Clear Tactive in Flags1\n");
618 xoutb(0x20, REG_FLAGS1(iobase));
619
620 /* Compare ptsreq and ptsreply */
621 if ((dev->pts[0] == pts_reply[0]) &&
622 (dev->pts[1] == pts_reply[1]) &&
623 (dev->pts[2] == pts_reply[2]) && (dev->pts[3] == pts_reply[3])) {
624 /* setcardparameter according to PPS */
625 dev->baudv = calc_baudv(dev->pts[2]);
626 set_cardparameter(dev);
627 } else if ((dev->pts[0] == pts_reply[0]) &&
628 ((dev->pts[1] & 0xef) == pts_reply[1]) &&
629 ((pts_reply[0] ^ pts_reply[1]) == pts_reply[2])) {
630 /* short PTS reply, set card parameter to default values */
631 dev->baudv = calc_baudv(0x11);
632 set_cardparameter(dev);
633 } else
634 rc = -EIO;
635
636exit_setprotocol:
637 DEBUGP(3, dev, "<- set_protocol\n");
638 return rc;
639}
640
641static int io_detect_cm4000(ioaddr_t iobase, struct cm4000_dev *dev)
642{
643
644 /* note: statemachine is assumed to be reset */
645 if (inb(REG_FLAGS0(iobase)) & 8) {
646 clear_bit(IS_ATR_VALID, &dev->flags);
647 set_bit(IS_CMM_ABSENT, &dev->flags);
648 return 0; /* detect CMM = 1 -> failure */
649 }
650 /* xoutb(0x40, REG_FLAGS1(iobase)); detectCMM */
651 xoutb(dev->flags1 | 0x40, REG_FLAGS1(iobase));
652 if ((inb(REG_FLAGS0(iobase)) & 8) == 0) {
653 clear_bit(IS_ATR_VALID, &dev->flags);
654 set_bit(IS_CMM_ABSENT, &dev->flags);
655 return 0; /* detect CMM=0 -> failure */
656 }
657 /* clear detectCMM again by restoring original flags1 */
658 xoutb(dev->flags1, REG_FLAGS1(iobase));
659 return 1;
660}
661
662static void terminate_monitor(struct cm4000_dev *dev)
663{
664
665 /* tell the monitor to stop and wait until
666 * it terminates.
667 */
668 DEBUGP(3, dev, "-> terminate_monitor\n");
669 wait_event_interruptible(dev->devq,
670 test_and_set_bit(LOCK_MONITOR,
671 (void *)&dev->flags));
672
673 /* now, LOCK_MONITOR has been set.
674 * allow a last cycle in the monitor.
675 * the monitor will indicate that it has
676 * finished by clearing this bit.
677 */
678 DEBUGP(5, dev, "Now allow last cycle of monitor!\n");
679 while (test_bit(LOCK_MONITOR, (void *)&dev->flags))
680 msleep(25);
681
682 DEBUGP(5, dev, "Delete timer\n");
683 del_timer_sync(&dev->timer);
684#ifdef PCMCIA_DEBUG
685 dev->monitor_running = 0;
686#endif
687
688 DEBUGP(3, dev, "<- terminate_monitor\n");
689}
690
691/*
692 * monitor the card every 50msec. as a side-effect, retrieve the
693 * atr once a card is inserted. another side-effect of retrieving the
694 * atr is that the card will be powered on, so there is no need to
695 * power on the card explictely from the application: the driver
696 * is already doing that for you.
697 */
698
699static void monitor_card(unsigned long p)
700{
701 struct cm4000_dev *dev = (struct cm4000_dev *) p;
702 ioaddr_t iobase = dev->link.io.BasePort1;
703 unsigned short s;
704 struct ptsreq ptsreq;
705 int i, atrc;
706
707 DEBUGP(7, dev, "-> monitor_card\n");
708
709 /* if someone has set the lock for us: we're done! */
710 if (test_and_set_bit(LOCK_MONITOR, &dev->flags)) {
711 DEBUGP(4, dev, "About to stop monitor\n");
712 /* no */
713 dev->rlen =
714 dev->rpos =
715 dev->atr_csum = dev->atr_len_retry = dev->cwarn = 0;
716 dev->mstate = M_FETCH_ATR;
717 clear_bit(LOCK_MONITOR, &dev->flags);
718 /* close et al. are sleeping on devq, so wake it */
719 wake_up_interruptible(&dev->devq);
720 DEBUGP(2, dev, "<- monitor_card (we are done now)\n");
721 return;
722 }
723
724 /* try to lock io: if it is already locked, just add another timer */
725 if (test_and_set_bit(LOCK_IO, (void *)&dev->flags)) {
726 DEBUGP(4, dev, "Couldn't get IO lock\n");
727 goto return_with_timer;
728 }
729
730 /* is a card/a reader inserted at all ? */
731 dev->flags0 = xinb(REG_FLAGS0(iobase));
732 DEBUGP(7, dev, "dev->flags0 = 0x%2x\n", dev->flags0);
733 DEBUGP(7, dev, "smartcard present: %s\n",
734 dev->flags0 & 1 ? "yes" : "no");
735 DEBUGP(7, dev, "cardman present: %s\n",
736 dev->flags0 == 0xff ? "no" : "yes");
737
738 if ((dev->flags0 & 1) == 0 /* no smartcard inserted */
739 || dev->flags0 == 0xff) { /* no cardman inserted */
740 /* no */
741 dev->rlen =
742 dev->rpos =
743 dev->atr_csum = dev->atr_len_retry = dev->cwarn = 0;
744 dev->mstate = M_FETCH_ATR;
745
746 dev->flags &= 0x000000ff; /* only keep IO and MONITOR locks */
747
748 if (dev->flags0 == 0xff) {
749 DEBUGP(4, dev, "set IS_CMM_ABSENT bit\n");
750 set_bit(IS_CMM_ABSENT, &dev->flags);
751 } else if (test_bit(IS_CMM_ABSENT, &dev->flags)) {
752 DEBUGP(4, dev, "clear IS_CMM_ABSENT bit "
753 "(card is removed)\n");
754 clear_bit(IS_CMM_ABSENT, &dev->flags);
755 }
756
757 goto release_io;
758 } else if ((dev->flags0 & 1) && test_bit(IS_CMM_ABSENT, &dev->flags)) {
759 /* cardman and card present but cardman was absent before
760 * (after suspend with inserted card) */
761 DEBUGP(4, dev, "clear IS_CMM_ABSENT bit (card is inserted)\n");
762 clear_bit(IS_CMM_ABSENT, &dev->flags);
763 }
764
765 if (test_bit(IS_ATR_VALID, &dev->flags) == 1) {
766 DEBUGP(7, dev, "believe ATR is already valid (do nothing)\n");
767 goto release_io;
768 }
769
770 switch (dev->mstate) {
771 unsigned char flags0;
772 case M_CARDOFF:
773 DEBUGP(4, dev, "M_CARDOFF\n");
774 flags0 = inb(REG_FLAGS0(iobase));
775 if (flags0 & 0x02) {
776 /* wait until Flags0 indicate power is off */
777 dev->mdelay = T_10MSEC;
778 } else {
779 /* Flags0 indicate power off and no card inserted now;
780 * Reset CARDMAN CONTROLLER */
781 xoutb(0x80, REG_FLAGS0(iobase));
782
783 /* prepare for fetching ATR again: after card off ATR
784 * is read again automatically */
785 dev->rlen =
786 dev->rpos =
787 dev->atr_csum =
788 dev->atr_len_retry = dev->cwarn = 0;
789 dev->mstate = M_FETCH_ATR;
790
791 /* minimal gap between CARDOFF and read ATR is 50msec */
792 dev->mdelay = T_50MSEC;
793 }
794 break;
795 case M_FETCH_ATR:
796 DEBUGP(4, dev, "M_FETCH_ATR\n");
797 xoutb(0x80, REG_FLAGS0(iobase));
798 DEBUGP(4, dev, "Reset BAUDV to 9600\n");
799 dev->baudv = 0x173; /* 9600 */
800 xoutb(0x02, REG_STOPBITS(iobase)); /* stopbits=2 */
801 xoutb(0x73, REG_BAUDRATE(iobase)); /* baud value */
802 xoutb(0x21, REG_FLAGS1(iobase)); /* T_Active=1, baud
803 value */
804 /* warm start vs. power on: */
805 xoutb(dev->flags0 & 2 ? 0x46 : 0x44, REG_FLAGS0(iobase));
806 dev->mdelay = T_40MSEC;
807 dev->mstate = M_TIMEOUT_WAIT;
808 break;
809 case M_TIMEOUT_WAIT:
810 DEBUGP(4, dev, "M_TIMEOUT_WAIT\n");
811 /* numRecBytes */
812 io_read_num_rec_bytes(iobase, &dev->atr_len);
813 dev->mdelay = T_10MSEC;
814 dev->mstate = M_READ_ATR_LEN;
815 break;
816 case M_READ_ATR_LEN:
817 DEBUGP(4, dev, "M_READ_ATR_LEN\n");
818 /* infinite loop possible, since there is no timeout */
819
820#define MAX_ATR_LEN_RETRY 100
821
822 if (dev->atr_len == io_read_num_rec_bytes(iobase, &s)) {
823 if (dev->atr_len_retry++ >= MAX_ATR_LEN_RETRY) { /* + XX msec */
824 dev->mdelay = T_10MSEC;
825 dev->mstate = M_READ_ATR;
826 }
827 } else {
828 dev->atr_len = s;
829 dev->atr_len_retry = 0; /* set new timeout */
830 }
831
832 DEBUGP(4, dev, "Current ATR_LEN = %i\n", dev->atr_len);
833 break;
834 case M_READ_ATR:
835 DEBUGP(4, dev, "M_READ_ATR\n");
836 xoutb(0x80, REG_FLAGS0(iobase)); /* reset SM */
837 for (i = 0; i < dev->atr_len; i++) {
838 xoutb(i, REG_BUF_ADDR(iobase));
839 dev->atr[i] = inb(REG_BUF_DATA(iobase));
840 }
841 /* Deactivate T_Active flags */
842 DEBUGP(4, dev, "Deactivate T_Active flags\n");
843 dev->flags1 = 0x01;
844 xoutb(dev->flags1, REG_FLAGS1(iobase));
845
846 /* atr is present (which doesnt mean it's valid) */
847 set_bit(IS_ATR_PRESENT, &dev->flags);
848 if (dev->atr[0] == 0x03)
849 str_invert_revert(dev->atr, dev->atr_len);
850 atrc = parse_atr(dev);
851 if (atrc == 0) { /* atr invalid */
852 dev->mdelay = 0;
853 dev->mstate = M_BAD_CARD;
854 } else {
855 dev->mdelay = T_50MSEC;
856 dev->mstate = M_ATR_PRESENT;
857 set_bit(IS_ATR_VALID, &dev->flags);
858 }
859
860 if (test_bit(IS_ATR_VALID, &dev->flags) == 1) {
861 DEBUGP(4, dev, "monitor_card: ATR valid\n");
862 /* if ta1 == 0x11, no PPS necessary (default values) */
863 /* do not do PPS with multi protocol cards */
864 if ((test_bit(IS_AUTOPPS_ACT, &dev->flags) == 0) &&
865 (dev->ta1 != 0x11) &&
866 !(test_bit(IS_ANY_T0, &dev->flags) &&
867 test_bit(IS_ANY_T1, &dev->flags))) {
868 DEBUGP(4, dev, "Perform AUTOPPS\n");
869 set_bit(IS_AUTOPPS_ACT, &dev->flags);
870 ptsreq.protocol = ptsreq.protocol =
871 (0x01 << dev->proto);
872 ptsreq.flags = 0x01;
873 ptsreq.pts1 = 0x00;
874 ptsreq.pts2 = 0x00;
875 ptsreq.pts3 = 0x00;
876 if (set_protocol(dev, &ptsreq) == 0) {
877 DEBUGP(4, dev, "AUTOPPS ret SUCC\n");
878 clear_bit(IS_AUTOPPS_ACT, &dev->flags);
879 wake_up_interruptible(&dev->atrq);
880 } else {
881 DEBUGP(4, dev, "AUTOPPS failed: "
882 "repower using defaults\n");
883 /* prepare for repowering */
884 clear_bit(IS_ATR_PRESENT, &dev->flags);
885 clear_bit(IS_ATR_VALID, &dev->flags);
886 dev->rlen =
887 dev->rpos =
888 dev->atr_csum =
889 dev->atr_len_retry = dev->cwarn = 0;
890 dev->mstate = M_FETCH_ATR;
891
892 dev->mdelay = T_50MSEC;
893 }
894 } else {
895 /* for cards which use slightly different
896 * params (extra guard time) */
897 set_cardparameter(dev);
898 if (test_bit(IS_AUTOPPS_ACT, &dev->flags) == 1)
899 DEBUGP(4, dev, "AUTOPPS already active "
900 "2nd try:use default values\n");
901 if (dev->ta1 == 0x11)
902 DEBUGP(4, dev, "No AUTOPPS necessary "
903 "TA(1)==0x11\n");
904 if (test_bit(IS_ANY_T0, &dev->flags)
905 && test_bit(IS_ANY_T1, &dev->flags))
906 DEBUGP(4, dev, "Do NOT perform AUTOPPS "
907 "with multiprotocol cards\n");
908 clear_bit(IS_AUTOPPS_ACT, &dev->flags);
909 wake_up_interruptible(&dev->atrq);
910 }
911 } else {
912 DEBUGP(4, dev, "ATR invalid\n");
913 wake_up_interruptible(&dev->atrq);
914 }
915 break;
916 case M_BAD_CARD:
917 DEBUGP(4, dev, "M_BAD_CARD\n");
918 /* slow down warning, but prompt immediately after insertion */
919 if (dev->cwarn == 0 || dev->cwarn == 10) {
920 set_bit(IS_BAD_CARD, &dev->flags);
921 printk(KERN_WARNING MODULE_NAME ": device %s: ",
922 dev->node.dev_name);
923 if (test_bit(IS_BAD_CSUM, &dev->flags)) {
924 DEBUGP(4, dev, "ATR checksum (0x%.2x, should "
925 "be zero) failed\n", dev->atr_csum);
926 }
927#ifdef PCMCIA_DEBUG
928 else if (test_bit(IS_BAD_LENGTH, &dev->flags)) {
929 DEBUGP(4, dev, "ATR length error\n");
930 } else {
931 DEBUGP(4, dev, "card damaged or wrong way "
932 "inserted\n");
933 }
934#endif
935 dev->cwarn = 0;
936 wake_up_interruptible(&dev->atrq); /* wake open */
937 }
938 dev->cwarn++;
939 dev->mdelay = T_100MSEC;
940 dev->mstate = M_FETCH_ATR;
941 break;
942 default:
943 DEBUGP(7, dev, "Unknown action\n");
944 break; /* nothing */
945 }
946
947release_io:
948 DEBUGP(7, dev, "release_io\n");
949 clear_bit(LOCK_IO, &dev->flags);
950 wake_up_interruptible(&dev->ioq); /* whoever needs IO */
951
952return_with_timer:
953 DEBUGP(7, dev, "<- monitor_card (returns with timer)\n");
954 dev->timer.expires = jiffies + dev->mdelay;
955 add_timer(&dev->timer);
956 clear_bit(LOCK_MONITOR, &dev->flags);
957}
958
959/* Interface to userland (file_operations) */
960
961static ssize_t cmm_read(struct file *filp, __user char *buf, size_t count,
962 loff_t *ppos)
963{
964 struct cm4000_dev *dev = filp->private_data;
965 ioaddr_t iobase = dev->link.io.BasePort1;
966 ssize_t rc;
967 int i, j, k;
968
969 DEBUGP(2, dev, "-> cmm_read(%s,%d)\n", current->comm, current->pid);
970
971 if (count == 0) /* according to manpage */
972 return 0;
973
974 if ((dev->link.state & DEV_PRESENT) == 0 || /* socket removed */
975 test_bit(IS_CMM_ABSENT, &dev->flags))
976 return -ENODEV;
977
978 if (test_bit(IS_BAD_CSUM, &dev->flags))
979 return -EIO;
980
981 /* also see the note about this in cmm_write */
982 if (wait_event_interruptible
983 (dev->atrq,
984 ((filp->f_flags & O_NONBLOCK)
985 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags) != 0)))) {
986 if (filp->f_flags & O_NONBLOCK)
987 return -EAGAIN;
988 return -ERESTARTSYS;
989 }
990
991 if (test_bit(IS_ATR_VALID, &dev->flags) == 0)
992 return -EIO;
993
994 /* this one implements blocking IO */
995 if (wait_event_interruptible
996 (dev->readq,
997 ((filp->f_flags & O_NONBLOCK) || (dev->rpos < dev->rlen)))) {
998 if (filp->f_flags & O_NONBLOCK)
999 return -EAGAIN;
1000 return -ERESTARTSYS;
1001 }
1002
1003 /* lock io */
1004 if (wait_event_interruptible
1005 (dev->ioq,
1006 ((filp->f_flags & O_NONBLOCK)
1007 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags) == 0)))) {
1008 if (filp->f_flags & O_NONBLOCK)
1009 return -EAGAIN;
1010 return -ERESTARTSYS;
1011 }
1012
1013 rc = 0;
1014 dev->flags0 = inb(REG_FLAGS0(iobase));
1015 if ((dev->flags0 & 1) == 0 /* no smartcard inserted */
1016 || dev->flags0 == 0xff) { /* no cardman inserted */
1017 clear_bit(IS_ATR_VALID, &dev->flags);
1018 if (dev->flags0 & 1) {
1019 set_bit(IS_CMM_ABSENT, &dev->flags);
1020 rc = -ENODEV;
1021 }
1022 rc = -EIO;
1023 goto release_io;
1024 }
1025
1026 DEBUGP(4, dev, "begin read answer\n");
1027 j = min(count, (size_t)(dev->rlen - dev->rpos));
1028 k = dev->rpos;
1029 if (k + j > 255)
1030 j = 256 - k;
1031 DEBUGP(4, dev, "read1 j=%d\n", j);
1032 for (i = 0; i < j; i++) {
1033 xoutb(k++, REG_BUF_ADDR(iobase));
1034 dev->rbuf[i] = xinb(REG_BUF_DATA(iobase));
1035 }
1036 j = min(count, (size_t)(dev->rlen - dev->rpos));
1037 if (k + j > 255) {
1038 DEBUGP(4, dev, "read2 j=%d\n", j);
1039 dev->flags1 |= 0x10; /* MSB buf addr set */
1040 xoutb(dev->flags1, REG_FLAGS1(iobase));
1041 for (; i < j; i++) {
1042 xoutb(k++, REG_BUF_ADDR(iobase));
1043 dev->rbuf[i] = xinb(REG_BUF_DATA(iobase));
1044 }
1045 }
1046
1047 if (dev->proto == 0 && count > dev->rlen - dev->rpos) {
1048 DEBUGP(4, dev, "T=0 and count > buffer\n");
1049 dev->rbuf[i] = dev->rbuf[i - 1];
1050 dev->rbuf[i - 1] = dev->procbyte;
1051 j++;
1052 }
1053 count = j;
1054
1055 dev->rpos = dev->rlen + 1;
1056
1057 /* Clear T1Active */
1058 DEBUGP(4, dev, "Clear T1Active\n");
1059 dev->flags1 &= 0xdf;
1060 xoutb(dev->flags1, REG_FLAGS1(iobase));
1061
1062 xoutb(0, REG_FLAGS1(iobase)); /* clear detectCMM */
1063 /* last check before exit */
1064 if (!io_detect_cm4000(iobase, dev))
1065 count = -ENODEV;
1066
1067 if (test_bit(IS_INVREV, &dev->flags) && count > 0)
1068 str_invert_revert(dev->rbuf, count);
1069
1070 if (copy_to_user(buf, dev->rbuf, count))
1071 return -EFAULT;
1072
1073release_io:
1074 clear_bit(LOCK_IO, &dev->flags);
1075 wake_up_interruptible(&dev->ioq);
1076
1077 DEBUGP(2, dev, "<- cmm_read returns: rc = %Zi\n",
1078 (rc < 0 ? rc : count));
1079 return rc < 0 ? rc : count;
1080}
1081
1082static ssize_t cmm_write(struct file *filp, const char __user *buf,
1083 size_t count, loff_t *ppos)
1084{
1085 struct cm4000_dev *dev = (struct cm4000_dev *) filp->private_data;
1086 ioaddr_t iobase = dev->link.io.BasePort1;
1087 unsigned short s;
1088 unsigned char tmp;
1089 unsigned char infolen;
1090 unsigned char sendT0;
1091 unsigned short nsend;
1092 unsigned short nr;
1093 ssize_t rc;
1094 int i;
1095
1096 DEBUGP(2, dev, "-> cmm_write(%s,%d)\n", current->comm, current->pid);
1097
1098 if (count == 0) /* according to manpage */
1099 return 0;
1100
1101 if (dev->proto == 0 && count < 4) {
1102 /* T0 must have at least 4 bytes */
1103 DEBUGP(4, dev, "T0 short write\n");
1104 return -EIO;
1105 }
1106
1107 nr = count & 0x1ff; /* max bytes to write */
1108
1109 sendT0 = dev->proto ? 0 : nr > 5 ? 0x08 : 0;
1110
1111 if ((dev->link.state & DEV_PRESENT) == 0 || /* socket removed */
1112 test_bit(IS_CMM_ABSENT, &dev->flags))
1113 return -ENODEV;
1114
1115 if (test_bit(IS_BAD_CSUM, &dev->flags)) {
1116 DEBUGP(4, dev, "bad csum\n");
1117 return -EIO;
1118 }
1119
1120 /*
1121 * wait for atr to become valid.
1122 * note: it is important to lock this code. if we dont, the monitor
1123 * could be run between test_bit and the the call the sleep on the
1124 * atr-queue. if *then* the monitor detects atr valid, it will wake up
1125 * any process on the atr-queue, *but* since we have been interrupted,
1126 * we do not yet sleep on this queue. this would result in a missed
1127 * wake_up and the calling process would sleep forever (until
1128 * interrupted). also, do *not* restore_flags before sleep_on, because
1129 * this could result in the same situation!
1130 */
1131 if (wait_event_interruptible
1132 (dev->atrq,
1133 ((filp->f_flags & O_NONBLOCK)
1134 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags) != 0)))) {
1135 if (filp->f_flags & O_NONBLOCK)
1136 return -EAGAIN;
1137 return -ERESTARTSYS;
1138 }
1139
1140 if (test_bit(IS_ATR_VALID, &dev->flags) == 0) { /* invalid atr */
1141 DEBUGP(4, dev, "invalid ATR\n");
1142 return -EIO;
1143 }
1144
1145 /* lock io */
1146 if (wait_event_interruptible
1147 (dev->ioq,
1148 ((filp->f_flags & O_NONBLOCK)
1149 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags) == 0)))) {
1150 if (filp->f_flags & O_NONBLOCK)
1151 return -EAGAIN;
1152 return -ERESTARTSYS;
1153 }
1154
1155 if (copy_from_user(dev->sbuf, buf, ((count > 512) ? 512 : count)))
1156 return -EFAULT;
1157
1158 rc = 0;
1159 dev->flags0 = inb(REG_FLAGS0(iobase));
1160 if ((dev->flags0 & 1) == 0 /* no smartcard inserted */
1161 || dev->flags0 == 0xff) { /* no cardman inserted */
1162 clear_bit(IS_ATR_VALID, &dev->flags);
1163 if (dev->flags0 & 1) {
1164 set_bit(IS_CMM_ABSENT, &dev->flags);
1165 rc = -ENODEV;
1166 } else {
1167 DEBUGP(4, dev, "IO error\n");
1168 rc = -EIO;
1169 }
1170 goto release_io;
1171 }
1172
1173 xoutb(0x80, REG_FLAGS0(iobase)); /* reset SM */
1174
1175 if (!io_detect_cm4000(iobase, dev)) {
1176 rc = -ENODEV;
1177 goto release_io;
1178 }
1179
1180 /* reflect T=0 send/read mode in flags1 */
1181 dev->flags1 |= (sendT0);
1182
1183 set_cardparameter(dev);
1184
1185 /* dummy read, reset flag procedure received */
1186 tmp = inb(REG_FLAGS1(iobase));
1187
1188 dev->flags1 = 0x20 /* T_Active */
1189 | (sendT0)
1190 | (test_bit(IS_INVREV, &dev->flags) ? 2 : 0)/* inverse parity */
1191 | (((dev->baudv - 1) & 0x0100) >> 8); /* MSB-Baud */
1192 DEBUGP(1, dev, "set dev->flags1 = 0x%.2x\n", dev->flags1);
1193 xoutb(dev->flags1, REG_FLAGS1(iobase));
1194
1195 /* xmit data */
1196 DEBUGP(4, dev, "Xmit data\n");
1197 for (i = 0; i < nr; i++) {
1198 if (i >= 256) {
1199 dev->flags1 = 0x20 /* T_Active */
1200 | (sendT0) /* SendT0 */
1201 /* inverse parity: */
1202 | (test_bit(IS_INVREV, &dev->flags) ? 2 : 0)
1203 | (((dev->baudv - 1) & 0x0100) >> 8) /* MSB-Baud */
1204 | 0x10; /* set address high */
1205 DEBUGP(4, dev, "dev->flags = 0x%.2x - set address "
1206 "high\n", dev->flags1);
1207 xoutb(dev->flags1, REG_FLAGS1(iobase));
1208 }
1209 if (test_bit(IS_INVREV, &dev->flags)) {
1210 DEBUGP(4, dev, "Apply inverse convention for 0x%.2x "
1211 "-> 0x%.2x\n", (unsigned char)dev->sbuf[i],
1212 invert_revert(dev->sbuf[i]));
1213 xoutb(i, REG_BUF_ADDR(iobase));
1214 xoutb(invert_revert(dev->sbuf[i]),
1215 REG_BUF_DATA(iobase));
1216 } else {
1217 xoutb(i, REG_BUF_ADDR(iobase));
1218 xoutb(dev->sbuf[i], REG_BUF_DATA(iobase));
1219 }
1220 }
1221 DEBUGP(4, dev, "Xmit done\n");
1222
1223 if (dev->proto == 0) {
1224 /* T=0 proto: 0 byte reply */
1225 if (nr == 4) {
1226 DEBUGP(4, dev, "T=0 assumes 0 byte reply\n");
1227 xoutb(i, REG_BUF_ADDR(iobase));
1228 if (test_bit(IS_INVREV, &dev->flags))
1229 xoutb(0xff, REG_BUF_DATA(iobase));
1230 else
1231 xoutb(0x00, REG_BUF_DATA(iobase));
1232 }
1233
1234 /* numSendBytes */
1235 if (sendT0)
1236 nsend = nr;
1237 else {
1238 if (nr == 4)
1239 nsend = 5;
1240 else {
1241 nsend = 5 + (unsigned char)dev->sbuf[4];
1242 if (dev->sbuf[4] == 0)
1243 nsend += 0x100;
1244 }
1245 }
1246 } else
1247 nsend = nr;
1248
1249 /* T0: output procedure byte */
1250 if (test_bit(IS_INVREV, &dev->flags)) {
1251 DEBUGP(4, dev, "T=0 set Procedure byte (inverse-reverse) "
1252 "0x%.2x\n", invert_revert(dev->sbuf[1]));
1253 xoutb(invert_revert(dev->sbuf[1]), REG_NUM_BYTES(iobase));
1254 } else {
1255 DEBUGP(4, dev, "T=0 set Procedure byte 0x%.2x\n", dev->sbuf[1]);
1256 xoutb(dev->sbuf[1], REG_NUM_BYTES(iobase));
1257 }
1258
1259 DEBUGP(1, dev, "set NumSendBytes = 0x%.2x\n",
1260 (unsigned char)(nsend & 0xff));
1261 xoutb((unsigned char)(nsend & 0xff), REG_NUM_SEND(iobase));
1262
1263 DEBUGP(1, dev, "Trigger CARDMAN CONTROLLER (0x%.2x)\n",
1264 0x40 /* SM_Active */
1265 | (dev->flags0 & 2 ? 0 : 4) /* power on if needed */
1266 |(dev->proto ? 0x10 : 0x08) /* T=1/T=0 */
1267 |(nsend & 0x100) >> 8 /* MSB numSendBytes */ );
1268 xoutb(0x40 /* SM_Active */
1269 | (dev->flags0 & 2 ? 0 : 4) /* power on if needed */
1270 |(dev->proto ? 0x10 : 0x08) /* T=1/T=0 */
1271 |(nsend & 0x100) >> 8, /* MSB numSendBytes */
1272 REG_FLAGS0(iobase));
1273
1274 /* wait for xmit done */
1275 if (dev->proto == 1) {
1276 DEBUGP(4, dev, "Wait for xmit done\n");
1277 for (i = 0; i < 1000; i++) {
1278 if (inb(REG_FLAGS0(iobase)) & 0x08)
1279 break;
1280 msleep_interruptible(10);
1281 }
1282 if (i == 1000) {
1283 DEBUGP(4, dev, "timeout waiting for xmit done\n");
1284 rc = -EIO;
1285 goto release_io;
1286 }
1287 }
1288
1289 /* T=1: wait for infoLen */
1290
1291 infolen = 0;
1292 if (dev->proto) {
1293 /* wait until infoLen is valid */
1294 for (i = 0; i < 6000; i++) { /* max waiting time of 1 min */
1295 io_read_num_rec_bytes(iobase, &s);
1296 if (s >= 3) {
1297 infolen = inb(REG_FLAGS1(iobase));
1298 DEBUGP(4, dev, "infolen=%d\n", infolen);
1299 break;
1300 }
1301 msleep_interruptible(10);
1302 }
1303 if (i == 6000) {
1304 DEBUGP(4, dev, "timeout waiting for infoLen\n");
1305 rc = -EIO;
1306 goto release_io;
1307 }
1308 } else
1309 clear_bit(IS_PROCBYTE_PRESENT, &dev->flags);
1310
1311 /* numRecBytes | bit9 of numRecytes */
1312 io_read_num_rec_bytes(iobase, &dev->rlen);
1313 for (i = 0; i < 600; i++) { /* max waiting time of 2 sec */
1314 if (dev->proto) {
1315 if (dev->rlen >= infolen + 4)
1316 break;
1317 }
1318 msleep_interruptible(10);
1319 /* numRecBytes | bit9 of numRecytes */
1320 io_read_num_rec_bytes(iobase, &s);
1321 if (s > dev->rlen) {
1322 DEBUGP(1, dev, "NumRecBytes inc (reset timeout)\n");
1323 i = 0; /* reset timeout */
1324 dev->rlen = s;
1325 }
1326 /* T=0: we are done when numRecBytes doesn't
1327 * increment any more and NoProcedureByte
1328 * is set and numRecBytes == bytes sent + 6
1329 * (header bytes + data + 1 for sw2)
1330 * except when the card replies an error
1331 * which means, no data will be sent back.
1332 */
1333 else if (dev->proto == 0) {
1334 if ((inb(REG_BUF_ADDR(iobase)) & 0x80)) {
1335 /* no procedure byte received since last read */
1336 DEBUGP(1, dev, "NoProcedure byte set\n");
1337 /* i=0; */
1338 } else {
1339 /* procedure byte received since last read */
1340 DEBUGP(1, dev, "NoProcedure byte unset "
1341 "(reset timeout)\n");
1342 dev->procbyte = inb(REG_FLAGS1(iobase));
1343 DEBUGP(1, dev, "Read procedure byte 0x%.2x\n",
1344 dev->procbyte);
1345 i = 0; /* resettimeout */
1346 }
1347 if (inb(REG_FLAGS0(iobase)) & 0x08) {
1348 DEBUGP(1, dev, "T0Done flag (read reply)\n");
1349 break;
1350 }
1351 }
1352 if (dev->proto)
1353 infolen = inb(REG_FLAGS1(iobase));
1354 }
1355 if (i == 600) {
1356 DEBUGP(1, dev, "timeout waiting for numRecBytes\n");
1357 rc = -EIO;
1358 goto release_io;
1359 } else {
1360 if (dev->proto == 0) {
1361 DEBUGP(1, dev, "Wait for T0Done bit to be set\n");
1362 for (i = 0; i < 1000; i++) {
1363 if (inb(REG_FLAGS0(iobase)) & 0x08)
1364 break;
1365 msleep_interruptible(10);
1366 }
1367 if (i == 1000) {
1368 DEBUGP(1, dev, "timeout waiting for T0Done\n");
1369 rc = -EIO;
1370 goto release_io;
1371 }
1372
1373 dev->procbyte = inb(REG_FLAGS1(iobase));
1374 DEBUGP(4, dev, "Read procedure byte 0x%.2x\n",
1375 dev->procbyte);
1376
1377 io_read_num_rec_bytes(iobase, &dev->rlen);
1378 DEBUGP(4, dev, "Read NumRecBytes = %i\n", dev->rlen);
1379
1380 }
1381 }
1382 /* T=1: read offset=zero, T=0: read offset=after challenge */
1383 dev->rpos = dev->proto ? 0 : nr == 4 ? 5 : nr > dev->rlen ? 5 : nr;
1384 DEBUGP(4, dev, "dev->rlen = %i, dev->rpos = %i, nr = %i\n",
1385 dev->rlen, dev->rpos, nr);
1386
1387release_io:
1388 DEBUGP(4, dev, "Reset SM\n");
1389 xoutb(0x80, REG_FLAGS0(iobase)); /* reset SM */
1390
1391 if (rc < 0) {
1392 DEBUGP(4, dev, "Write failed but clear T_Active\n");
1393 dev->flags1 &= 0xdf;
1394 xoutb(dev->flags1, REG_FLAGS1(iobase));
1395 }
1396
1397 clear_bit(LOCK_IO, &dev->flags);
1398 wake_up_interruptible(&dev->ioq);
1399 wake_up_interruptible(&dev->readq); /* tell read we have data */
1400
1401 /* ITSEC E2: clear write buffer */
1402 memset((char *)dev->sbuf, 0, 512);
1403
1404 /* return error or actually written bytes */
1405 DEBUGP(2, dev, "<- cmm_write\n");
1406 return rc < 0 ? rc : nr;
1407}
1408
1409static void start_monitor(struct cm4000_dev *dev)
1410{
1411 DEBUGP(3, dev, "-> start_monitor\n");
1412 if (!dev->monitor_running) {
1413 DEBUGP(5, dev, "create, init and add timer\n");
1414 init_timer(&dev->timer);
1415 dev->monitor_running = 1;
1416 dev->timer.expires = jiffies;
1417 dev->timer.data = (unsigned long) dev;
1418 dev->timer.function = monitor_card;
1419 add_timer(&dev->timer);
1420 } else
1421 DEBUGP(5, dev, "monitor already running\n");
1422 DEBUGP(3, dev, "<- start_monitor\n");
1423}
1424
1425static void stop_monitor(struct cm4000_dev *dev)
1426{
1427 DEBUGP(3, dev, "-> stop_monitor\n");
1428 if (dev->monitor_running) {
1429 DEBUGP(5, dev, "stopping monitor\n");
1430 terminate_monitor(dev);
1431 /* reset monitor SM */
1432 clear_bit(IS_ATR_VALID, &dev->flags);
1433 clear_bit(IS_ATR_PRESENT, &dev->flags);
1434 } else
1435 DEBUGP(5, dev, "monitor already stopped\n");
1436 DEBUGP(3, dev, "<- stop_monitor\n");
1437}
1438
1439static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1440 unsigned long arg)
1441{
1442 struct cm4000_dev *dev = filp->private_data;
1443 ioaddr_t iobase = dev->link.io.BasePort1;
1444 dev_link_t *link;
1445 int size;
1446 int rc;
1447 void __user *argp = (void __user *)arg;
1448#ifdef PCMCIA_DEBUG
1449 char *ioctl_names[CM_IOC_MAXNR + 1] = {
1450 [_IOC_NR(CM_IOCGSTATUS)] "CM_IOCGSTATUS",
1451 [_IOC_NR(CM_IOCGATR)] "CM_IOCGATR",
1452 [_IOC_NR(CM_IOCARDOFF)] "CM_IOCARDOFF",
1453 [_IOC_NR(CM_IOCSPTS)] "CM_IOCSPTS",
1454 [_IOC_NR(CM_IOSDBGLVL)] "CM4000_DBGLVL",
1455 };
1456#endif
1457 DEBUGP(3, dev, "cmm_ioctl(device=%d.%d) %s\n", imajor(inode),
1458 iminor(inode), ioctl_names[_IOC_NR(cmd)]);
1459
1460 link = dev_table[iminor(inode)];
1461 if (!(DEV_OK(link))) {
1462 DEBUGP(4, dev, "DEV_OK false\n");
1463 return -ENODEV;
1464 }
1465
1466 if (test_bit(IS_CMM_ABSENT, &dev->flags)) {
1467 DEBUGP(4, dev, "CMM_ABSENT flag set\n");
1468 return -ENODEV;
1469 }
1470
1471 if (_IOC_TYPE(cmd) != CM_IOC_MAGIC) {
1472 DEBUGP(4, dev, "ioctype mismatch\n");
1473 return -EINVAL;
1474 }
1475 if (_IOC_NR(cmd) > CM_IOC_MAXNR) {
1476 DEBUGP(4, dev, "iocnr mismatch\n");
1477 return -EINVAL;
1478 }
1479 size = _IOC_SIZE(cmd);
1480 rc = 0;
1481 DEBUGP(4, dev, "iocdir=%.4x iocr=%.4x iocw=%.4x iocsize=%d cmd=%.4x\n",
1482 _IOC_DIR(cmd), _IOC_READ, _IOC_WRITE, size, cmd);
1483
1484 if (_IOC_DIR(cmd) & _IOC_READ) {
1485 if (!access_ok(VERIFY_WRITE, argp, size))
1486 return -EFAULT;
1487 }
1488 if (_IOC_DIR(cmd) & _IOC_WRITE) {
1489 if (!access_ok(VERIFY_READ, argp, size))
1490 return -EFAULT;
1491 }
1492
1493 switch (cmd) {
1494 case CM_IOCGSTATUS:
1495 DEBUGP(4, dev, " ... in CM_IOCGSTATUS\n");
1496 {
1497 int status;
1498
1499 /* clear other bits, but leave inserted & powered as
1500 * they are */
1501 status = dev->flags0 & 3;
1502 if (test_bit(IS_ATR_PRESENT, &dev->flags))
1503 status |= CM_ATR_PRESENT;
1504 if (test_bit(IS_ATR_VALID, &dev->flags))
1505 status |= CM_ATR_VALID;
1506 if (test_bit(IS_CMM_ABSENT, &dev->flags))
1507 status |= CM_NO_READER;
1508 if (test_bit(IS_BAD_CARD, &dev->flags))
1509 status |= CM_BAD_CARD;
1510 if (copy_to_user(argp, &status, sizeof(int)))
1511 return -EFAULT;
1512 }
1513 return 0;
1514 case CM_IOCGATR:
1515 DEBUGP(4, dev, "... in CM_IOCGATR\n");
1516 {
1517 struct atreq __user *atreq = argp;
1518 int tmp;
1519 /* allow nonblocking io and being interrupted */
1520 if (wait_event_interruptible
1521 (dev->atrq,
1522 ((filp->f_flags & O_NONBLOCK)
1523 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags)
1524 != 0)))) {
1525 if (filp->f_flags & O_NONBLOCK)
1526 return -EAGAIN;
1527 return -ERESTARTSYS;
1528 }
1529
1530 if (test_bit(IS_ATR_VALID, &dev->flags) == 0) {
1531 tmp = -1;
1532 if (copy_to_user(&(atreq->atr_len), &tmp,
1533 sizeof(int)))
1534 return -EFAULT;
1535 } else {
1536 if (copy_to_user(atreq->atr, dev->atr,
1537 dev->atr_len))
1538 return -EFAULT;
1539
1540 tmp = dev->atr_len;
1541 if (copy_to_user(&(atreq->atr_len), &tmp, sizeof(int)))
1542 return -EFAULT;
1543 }
1544 return 0;
1545 }
1546 case CM_IOCARDOFF:
1547
1548#ifdef PCMCIA_DEBUG
1549 DEBUGP(4, dev, "... in CM_IOCARDOFF\n");
1550 if (dev->flags0 & 0x01) {
1551 DEBUGP(4, dev, " Card inserted\n");
1552 } else {
1553 DEBUGP(2, dev, " No card inserted\n");
1554 }
1555 if (dev->flags0 & 0x02) {
1556 DEBUGP(4, dev, " Card powered\n");
1557 } else {
1558 DEBUGP(2, dev, " Card not powered\n");
1559 }
1560#endif
1561
1562 /* is a card inserted and powered? */
1563 if ((dev->flags0 & 0x01) && (dev->flags0 & 0x02)) {
1564
1565 /* get IO lock */
1566 if (wait_event_interruptible
1567 (dev->ioq,
1568 ((filp->f_flags & O_NONBLOCK)
1569 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags)
1570 == 0)))) {
1571 if (filp->f_flags & O_NONBLOCK)
1572 return -EAGAIN;
1573 return -ERESTARTSYS;
1574 }
1575 /* Set Flags0 = 0x42 */
1576 DEBUGP(4, dev, "Set Flags0=0x42 \n");
1577 xoutb(0x42, REG_FLAGS0(iobase));
1578 clear_bit(IS_ATR_PRESENT, &dev->flags);
1579 clear_bit(IS_ATR_VALID, &dev->flags);
1580 dev->mstate = M_CARDOFF;
1581 clear_bit(LOCK_IO, &dev->flags);
1582 if (wait_event_interruptible
1583 (dev->atrq,
1584 ((filp->f_flags & O_NONBLOCK)
1585 || (test_bit(IS_ATR_VALID, (void *)&dev->flags) !=
1586 0)))) {
1587 if (filp->f_flags & O_NONBLOCK)
1588 return -EAGAIN;
1589 return -ERESTARTSYS;
1590 }
1591 }
1592 /* release lock */
1593 clear_bit(LOCK_IO, &dev->flags);
1594 wake_up_interruptible(&dev->ioq);
1595
1596 return 0;
1597 case CM_IOCSPTS:
1598 {
1599 struct ptsreq krnptsreq;
1600
1601 if (copy_from_user(&krnptsreq, argp,
1602 sizeof(struct ptsreq)))
1603 return -EFAULT;
1604
1605 rc = 0;
1606 DEBUGP(4, dev, "... in CM_IOCSPTS\n");
1607 /* wait for ATR to get valid */
1608 if (wait_event_interruptible
1609 (dev->atrq,
1610 ((filp->f_flags & O_NONBLOCK)
1611 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags)
1612 != 0)))) {
1613 if (filp->f_flags & O_NONBLOCK)
1614 return -EAGAIN;
1615 return -ERESTARTSYS;
1616 }
1617 /* get IO lock */
1618 if (wait_event_interruptible
1619 (dev->ioq,
1620 ((filp->f_flags & O_NONBLOCK)
1621 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags)
1622 == 0)))) {
1623 if (filp->f_flags & O_NONBLOCK)
1624 return -EAGAIN;
1625 return -ERESTARTSYS;
1626 }
1627
1628 if ((rc = set_protocol(dev, &krnptsreq)) != 0) {
1629 /* auto power_on again */
1630 dev->mstate = M_FETCH_ATR;
1631 clear_bit(IS_ATR_VALID, &dev->flags);
1632 }
1633 /* release lock */
1634 clear_bit(LOCK_IO, &dev->flags);
1635 wake_up_interruptible(&dev->ioq);
1636
1637 }
1638 return rc;
1639#ifdef PCMCIA_DEBUG
1640 case CM_IOSDBGLVL: /* set debug log level */
1641 {
1642 int old_pc_debug = 0;
1643
1644 old_pc_debug = pc_debug;
1645 if (copy_from_user(&pc_debug, argp, sizeof(int)))
1646 return -EFAULT;
1647
1648 if (old_pc_debug != pc_debug)
1649 DEBUGP(0, dev, "Changed debug log level "
1650 "to %i\n", pc_debug);
1651 }
1652 return rc;
1653#endif
1654 default:
1655 DEBUGP(4, dev, "... in default (unknown IOCTL code)\n");
1656 return -EINVAL;
1657 }
1658}
1659
1660static int cmm_open(struct inode *inode, struct file *filp)
1661{
1662 struct cm4000_dev *dev;
1663 dev_link_t *link;
1664 int rc, minor = iminor(inode);
1665
1666 if (minor >= CM4000_MAX_DEV)
1667 return -ENODEV;
1668
1669 link = dev_table[minor];
1670 if (link == NULL || !(DEV_OK(link)))
1671 return -ENODEV;
1672
1673 if (link->open)
1674 return -EBUSY;
1675
1676 dev = link->priv;
1677 filp->private_data = dev;
1678
1679 DEBUGP(2, dev, "-> cmm_open(device=%d.%d process=%s,%d)\n",
1680 imajor(inode), minor, current->comm, current->pid);
1681
1682 /* init device variables, they may be "polluted" after close
1683 * or, the device may never have been closed (i.e. open failed)
1684 */
1685
1686 ZERO_DEV(dev);
1687
1688 /* opening will always block since the
1689 * monitor will be started by open, which
1690 * means we have to wait for ATR becoming
1691 * vaild = block until valid (or card
1692 * inserted)
1693 */
1694 if (filp->f_flags & O_NONBLOCK)
1695 return -EAGAIN;
1696
1697 dev->mdelay = T_50MSEC;
1698
1699 /* start monitoring the cardstatus */
1700 start_monitor(dev);
1701
1702 link->open = 1; /* only one open per device */
1703 rc = 0;
1704
1705 DEBUGP(2, dev, "<- cmm_open\n");
1706 return nonseekable_open(inode, filp);
1707}
1708
1709static int cmm_close(struct inode *inode, struct file *filp)
1710{
1711 struct cm4000_dev *dev;
1712 dev_link_t *link;
1713 int minor = iminor(inode);
1714
1715 if (minor >= CM4000_MAX_DEV)
1716 return -ENODEV;
1717
1718 link = dev_table[minor];
1719 if (link == NULL)
1720 return -ENODEV;
1721
1722 dev = link->priv;
1723
1724 DEBUGP(2, dev, "-> cmm_close(maj/min=%d.%d)\n",
1725 imajor(inode), minor);
1726
1727 stop_monitor(dev);
1728
1729 ZERO_DEV(dev);
1730
1731 link->open = 0; /* only one open per device */
1732 wake_up(&dev->devq); /* socket removed? */
1733
1734 DEBUGP(2, dev, "cmm_close\n");
1735 return 0;
1736}
1737
1738static void cmm_cm4000_release(dev_link_t * link)
1739{
1740 struct cm4000_dev *dev = link->priv;
1741
1742 /* dont terminate the monitor, rather rely on
1743 * close doing that for us.
1744 */
1745 DEBUGP(3, dev, "-> cmm_cm4000_release\n");
1746 while (link->open) {
1747 printk(KERN_INFO MODULE_NAME ": delaying release until "
1748 "process has terminated\n");
1749 /* note: don't interrupt us:
1750 * close the applications which own
1751 * the devices _first_ !
1752 */
1753 wait_event(dev->devq, (link->open == 0));
1754 }
1755 /* dev->devq=NULL; this cannot be zeroed earlier */
1756 DEBUGP(3, dev, "<- cmm_cm4000_release\n");
1757 return;
1758}
1759
1760/*==== Interface to PCMCIA Layer =======================================*/
1761
1762static void cm4000_config(dev_link_t * link, int devno)
1763{
1764 client_handle_t handle = link->handle;
1765 struct cm4000_dev *dev;
1766 tuple_t tuple;
1767 cisparse_t parse;
1768 config_info_t conf;
1769 u_char buf[64];
1770 int fail_fn, fail_rc;
1771 int rc;
1772
1773 /* read the config-tuples */
1774 tuple.DesiredTuple = CISTPL_CONFIG;
1775 tuple.Attributes = 0;
1776 tuple.TupleData = buf;
1777 tuple.TupleDataMax = sizeof(buf);
1778 tuple.TupleOffset = 0;
1779
1780 if ((fail_rc = pcmcia_get_first_tuple(handle, &tuple)) != CS_SUCCESS) {
1781 fail_fn = GetFirstTuple;
1782 goto cs_failed;
1783 }
1784 if ((fail_rc = pcmcia_get_tuple_data(handle, &tuple)) != CS_SUCCESS) {
1785 fail_fn = GetTupleData;
1786 goto cs_failed;
1787 }
1788 if ((fail_rc =
1789 pcmcia_parse_tuple(handle, &tuple, &parse)) != CS_SUCCESS) {
1790 fail_fn = ParseTuple;
1791 goto cs_failed;
1792 }
1793 if ((fail_rc =
1794 pcmcia_get_configuration_info(handle, &conf)) != CS_SUCCESS) {
1795 fail_fn = GetConfigurationInfo;
1796 goto cs_failed;
1797 }
1798
1799 link->state |= DEV_CONFIG;
1800 link->conf.ConfigBase = parse.config.base;
1801 link->conf.Present = parse.config.rmask[0];
1802 link->conf.Vcc = conf.Vcc;
1803
1804 link->io.BasePort2 = 0;
1805 link->io.NumPorts2 = 0;
1806 link->io.Attributes2 = 0;
1807 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
1808 for (rc = pcmcia_get_first_tuple(handle, &tuple);
1809 rc == CS_SUCCESS; rc = pcmcia_get_next_tuple(handle, &tuple)) {
1810
1811 rc = pcmcia_get_tuple_data(handle, &tuple);
1812 if (rc != CS_SUCCESS)
1813 continue;
1814 rc = pcmcia_parse_tuple(handle, &tuple, &parse);
1815 if (rc != CS_SUCCESS)
1816 continue;
1817
1818 link->conf.ConfigIndex = parse.cftable_entry.index;
1819
1820 if (!parse.cftable_entry.io.nwin)
1821 continue;
1822
1823 /* Get the IOaddr */
1824 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
1825 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
1826 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
1827 if (!(parse.cftable_entry.io.flags & CISTPL_IO_8BIT))
1828 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
1829 if (!(parse.cftable_entry.io.flags & CISTPL_IO_16BIT))
1830 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
1831 link->io.IOAddrLines = parse.cftable_entry.io.flags
1832 & CISTPL_IO_LINES_MASK;
1833
1834 rc = pcmcia_request_io(handle, &link->io);
1835 if (rc == CS_SUCCESS)
1836 break; /* we are done */
1837 }
1838 if (rc != CS_SUCCESS)
1839 goto cs_release;
1840
1841 link->conf.IntType = 00000002;
1842
1843 if ((fail_rc =
1844 pcmcia_request_configuration(handle, &link->conf)) != CS_SUCCESS) {
1845 fail_fn = RequestConfiguration;
1846 goto cs_release;
1847 }
1848
1849 dev = link->priv;
1850 sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno);
1851 dev->node.major = major;
1852 dev->node.minor = devno;
1853 dev->node.next = NULL;
1854 link->dev = &dev->node;
1855 link->state &= ~DEV_CONFIG_PENDING;
1856
1857 return;
1858
1859cs_failed:
1860 cs_error(handle, fail_fn, fail_rc);
1861cs_release:
1862 cm4000_release(link);
1863
1864 link->state &= ~DEV_CONFIG_PENDING;
1865}
1866
1867static int cm4000_event(event_t event, int priority,
1868 event_callback_args_t *args)
1869{
1870 dev_link_t *link;
1871 struct cm4000_dev *dev;
1872 int devno;
1873
1874 link = args->client_data;
1875 dev = link->priv;
1876
1877 DEBUGP(3, dev, "-> cm4000_event\n");
1878 for (devno = 0; devno < CM4000_MAX_DEV; devno++)
1879 if (dev_table[devno] == link)
1880 break;
1881
1882 if (devno == CM4000_MAX_DEV)
1883 return CS_BAD_ADAPTER;
1884
1885 switch (event) {
1886 case CS_EVENT_CARD_INSERTION:
1887 DEBUGP(5, dev, "CS_EVENT_CARD_INSERTION\n");
1888 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1889 cm4000_config(link, devno);
1890 break;
1891 case CS_EVENT_CARD_REMOVAL:
1892 DEBUGP(5, dev, "CS_EVENT_CARD_REMOVAL\n");
1893 link->state &= ~DEV_PRESENT;
1894 stop_monitor(dev);
1895 break;
1896 case CS_EVENT_PM_SUSPEND:
1897 DEBUGP(5, dev, "CS_EVENT_PM_SUSPEND "
1898 "(fall-through to CS_EVENT_RESET_PHYSICAL)\n");
1899 link->state |= DEV_SUSPEND;
1900 /* fall-through */
1901 case CS_EVENT_RESET_PHYSICAL:
1902 DEBUGP(5, dev, "CS_EVENT_RESET_PHYSICAL\n");
1903 if (link->state & DEV_CONFIG) {
1904 DEBUGP(5, dev, "ReleaseConfiguration\n");
1905 pcmcia_release_configuration(link->handle);
1906 }
1907 stop_monitor(dev);
1908 break;
1909 case CS_EVENT_PM_RESUME:
1910 DEBUGP(5, dev, "CS_EVENT_PM_RESUME "
1911 "(fall-through to CS_EVENT_CARD_RESET)\n");
1912 link->state &= ~DEV_SUSPEND;
1913 /* fall-through */
1914 case CS_EVENT_CARD_RESET:
1915 DEBUGP(5, dev, "CS_EVENT_CARD_RESET\n");
1916 if ((link->state & DEV_CONFIG)) {
1917 DEBUGP(5, dev, "RequestConfiguration\n");
1918 pcmcia_request_configuration(link->handle, &link->conf);
1919 }
1920 if (link->open)
1921 start_monitor(dev);
1922 break;
1923 default:
1924 DEBUGP(5, dev, "unknown event %.2x\n", event);
1925 break;
1926 }
1927 DEBUGP(3, dev, "<- cm4000_event\n");
1928 return CS_SUCCESS;
1929}
1930
1931static void cm4000_release(dev_link_t *link)
1932{
1933 cmm_cm4000_release(link->priv); /* delay release until device closed */
1934 pcmcia_release_configuration(link->handle);
1935 pcmcia_release_io(link->handle, &link->io);
1936}
1937
1938static dev_link_t *cm4000_attach(void)
1939{
1940 struct cm4000_dev *dev;
1941 dev_link_t *link;
1942 client_reg_t client_reg;
1943 int i;
1944
1945 for (i = 0; i < CM4000_MAX_DEV; i++)
1946 if (dev_table[i] == NULL)
1947 break;
1948
1949 if (i == CM4000_MAX_DEV) {
1950 printk(KERN_NOTICE MODULE_NAME ": all devices in use\n");
1951 return NULL;
1952 }
1953
1954 /* create a new cm4000_cs device */
1955 dev = kzalloc(sizeof(struct cm4000_dev), GFP_KERNEL);
1956 if (dev == NULL)
1957 return NULL;
1958
1959 link = &dev->link;
1960 link->priv = dev;
1961 link->conf.IntType = INT_MEMORY_AND_IO;
1962 dev_table[i] = link;
1963
1964 /* register with card services */
1965 client_reg.dev_info = &dev_info;
1966 client_reg.EventMask =
1967 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
1968 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
1969 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
1970 client_reg.Version = 0x0210;
1971 client_reg.event_callback_args.client_data = link;
1972
1973 i = pcmcia_register_client(&link->handle, &client_reg);
1974 if (i) {
1975 cs_error(link->handle, RegisterClient, i);
1976 cm4000_detach(link);
1977 return NULL;
1978 }
1979
1980 init_waitqueue_head(&dev->devq);
1981 init_waitqueue_head(&dev->ioq);
1982 init_waitqueue_head(&dev->atrq);
1983 init_waitqueue_head(&dev->readq);
1984
1985 return link;
1986}
1987
1988static void cm4000_detach_by_devno(int devno, dev_link_t * link)
1989{
1990 struct cm4000_dev *dev = link->priv;
1991
1992 DEBUGP(3, dev, "-> detach_by_devno(devno=%d)\n", devno);
1993
1994 if (link->state & DEV_CONFIG) {
1995 DEBUGP(5, dev, "device still configured (try to release it)\n");
1996 cm4000_release(link);
1997 }
1998
1999 if (link->handle) {
2000 pcmcia_deregister_client(link->handle);
2001 }
2002
2003 dev_table[devno] = NULL;
2004 kfree(dev);
2005 return;
2006}
2007
2008static void cm4000_detach(dev_link_t * link)
2009{
2010 int i;
2011
2012 /* find device */
2013 for (i = 0; i < CM4000_MAX_DEV; i++)
2014 if (dev_table[i] == link)
2015 break;
2016
2017 if (i == CM4000_MAX_DEV)
2018 return;
2019
2020 cm4000_detach_by_devno(i, link);
2021 return;
2022}
2023
2024static struct file_operations cm4000_fops = {
2025 .owner = THIS_MODULE,
2026 .read = cmm_read,
2027 .write = cmm_write,
2028 .ioctl = cmm_ioctl,
2029 .open = cmm_open,
2030 .release= cmm_close,
2031};
2032
2033static struct pcmcia_device_id cm4000_ids[] = {
2034 PCMCIA_DEVICE_MANF_CARD(0x0223, 0x0002),
2035 PCMCIA_DEVICE_PROD_ID12("CardMan", "4000", 0x2FB368CA, 0xA2BD8C39),
2036 PCMCIA_DEVICE_NULL,
2037};
2038MODULE_DEVICE_TABLE(pcmcia, cm4000_ids);
2039
2040static struct pcmcia_driver cm4000_driver = {
2041 .owner = THIS_MODULE,
2042 .drv = {
2043 .name = "cm4000_cs",
2044 },
2045 .attach = cm4000_attach,
2046 .detach = cm4000_detach,
2047 .event = cm4000_event,
2048 .id_table = cm4000_ids,
2049};
2050
2051static int __init cmm_init(void)
2052{
2053 printk(KERN_INFO "%s\n", version);
2054 pcmcia_register_driver(&cm4000_driver);
2055 major = register_chrdev(0, DEVICE_NAME, &cm4000_fops);
2056 if (major < 0) {
2057 printk(KERN_WARNING MODULE_NAME
2058 ": could not get major number\n");
2059 return -1;
2060 }
2061
2062 return 0;
2063}
2064
2065static void __exit cmm_exit(void)
2066{
2067 int i;
2068
2069 printk(KERN_INFO MODULE_NAME ": unloading\n");
2070 pcmcia_unregister_driver(&cm4000_driver);
2071 for (i = 0; i < CM4000_MAX_DEV; i++)
2072 if (dev_table[i])
2073 cm4000_detach_by_devno(i, dev_table[i]);
2074 unregister_chrdev(major, DEVICE_NAME);
2075};
2076
2077module_init(cmm_init);
2078module_exit(cmm_exit);
2079MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
new file mode 100644
index 000000000000..4c698d908ffa
--- /dev/null
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -0,0 +1,841 @@
1/*
2 * A driver for the Omnikey PCMCIA smartcard reader CardMan 4040
3 *
4 * (c) 2000-2004 Omnikey AG (http://www.omnikey.com/)
5 *
6 * (C) 2005 Harald Welte <laforge@gnumonks.org>
7 * - add support for poll()
8 * - driver cleanup
9 * - add waitqueues
10 * - adhere to linux kernel coding style and policies
11 * - support 2.6.13 "new style" pcmcia interface
12 *
13 * The device basically is a USB CCID compliant device that has been
14 * attached to an I/O-Mapped FIFO.
15 *
16 * All rights reserved, Dual BSD/GPL Licensed.
17 */
18
19/* #define PCMCIA_DEBUG 6 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/init.h>
25#include <linux/fs.h>
26#include <linux/delay.h>
27#include <linux/poll.h>
28#include <linux/wait.h>
29#include <asm/uaccess.h>
30#include <asm/io.h>
31
32#include <pcmcia/cs_types.h>
33#include <pcmcia/cs.h>
34#include <pcmcia/cistpl.h>
35#include <pcmcia/cisreg.h>
36#include <pcmcia/ciscode.h>
37#include <pcmcia/ds.h>
38
39#include "cm4040_cs.h"
40
41
42#ifdef PCMCIA_DEBUG
43#define reader_to_dev(x) (&handle_to_dev(x->link.handle))
44static int pc_debug = PCMCIA_DEBUG;
45module_param(pc_debug, int, 0600);
46#define DEBUGP(n, rdr, x, args...) do { \
47 if (pc_debug >= (n)) \
48 dev_printk(KERN_DEBUG, reader_to_dev(rdr), "%s:" x, \
49 __FUNCTION__ , ##args); \
50 } while (0)
51#else
52#define DEBUGP(n, rdr, x, args...)
53#endif
54
55static char *version =
56"OMNIKEY CardMan 4040 v1.1.0gm4 - All bugs added by Harald Welte";
57
58#define CCID_DRIVER_BULK_DEFAULT_TIMEOUT (150*HZ)
59#define CCID_DRIVER_ASYNC_POWERUP_TIMEOUT (35*HZ)
60#define CCID_DRIVER_MINIMUM_TIMEOUT (3*HZ)
61#define READ_WRITE_BUFFER_SIZE 512
62#define POLL_LOOP_COUNT 1000
63
64/* how often to poll for fifo status change */
65#define POLL_PERIOD msecs_to_jiffies(10)
66
67static void reader_release(dev_link_t *link);
68static void reader_detach(dev_link_t *link);
69
70static int major;
71
72#define BS_READABLE 0x01
73#define BS_WRITABLE 0x02
74
75struct reader_dev {
76 dev_link_t link;
77 dev_node_t node;
78 wait_queue_head_t devq;
79 wait_queue_head_t poll_wait;
80 wait_queue_head_t read_wait;
81 wait_queue_head_t write_wait;
82 unsigned long buffer_status;
83 unsigned long timeout;
84 unsigned char s_buf[READ_WRITE_BUFFER_SIZE];
85 unsigned char r_buf[READ_WRITE_BUFFER_SIZE];
86 struct timer_list poll_timer;
87};
88
89static dev_info_t dev_info = MODULE_NAME;
90static dev_link_t *dev_table[CM_MAX_DEV];
91
92#ifndef PCMCIA_DEBUG
93#define xoutb outb
94#define xinb inb
95#else
96static inline void xoutb(unsigned char val, unsigned short port)
97{
98 if (pc_debug >= 7)
99 printk(KERN_DEBUG "outb(val=%.2x,port=%.4x)\n", val, port);
100 outb(val, port);
101}
102
103static inline unsigned char xinb(unsigned short port)
104{
105 unsigned char val;
106
107 val = inb(port);
108 if (pc_debug >= 7)
109 printk(KERN_DEBUG "%.2x=inb(%.4x)\n", val, port);
110 return val;
111}
112#endif
113
114/* poll the device fifo status register. not to be confused with
115 * the poll syscall. */
116static void cm4040_do_poll(unsigned long dummy)
117{
118 struct reader_dev *dev = (struct reader_dev *) dummy;
119 unsigned int obs = xinb(dev->link.io.BasePort1
120 + REG_OFFSET_BUFFER_STATUS);
121
122 if ((obs & BSR_BULK_IN_FULL)) {
123 set_bit(BS_READABLE, &dev->buffer_status);
124 DEBUGP(4, dev, "waking up read_wait\n");
125 wake_up_interruptible(&dev->read_wait);
126 } else
127 clear_bit(BS_READABLE, &dev->buffer_status);
128
129 if (!(obs & BSR_BULK_OUT_FULL)) {
130 set_bit(BS_WRITABLE, &dev->buffer_status);
131 DEBUGP(4, dev, "waking up write_wait\n");
132 wake_up_interruptible(&dev->write_wait);
133 } else
134 clear_bit(BS_WRITABLE, &dev->buffer_status);
135
136 if (dev->buffer_status)
137 wake_up_interruptible(&dev->poll_wait);
138
139 mod_timer(&dev->poll_timer, jiffies + POLL_PERIOD);
140}
141
142static void cm4040_stop_poll(struct reader_dev *dev)
143{
144 del_timer_sync(&dev->poll_timer);
145}
146
147static int wait_for_bulk_out_ready(struct reader_dev *dev)
148{
149 int i, rc;
150 int iobase = dev->link.io.BasePort1;
151
152 for (i = 0; i < POLL_LOOP_COUNT; i++) {
153 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS)
154 & BSR_BULK_OUT_FULL) == 0) {
155 DEBUGP(4, dev, "BulkOut empty (i=%d)\n", i);
156 return 1;
157 }
158 }
159
160 DEBUGP(4, dev, "wait_event_interruptible_timeout(timeout=%ld\n",
161 dev->timeout);
162 rc = wait_event_interruptible_timeout(dev->write_wait,
163 test_and_clear_bit(BS_WRITABLE,
164 &dev->buffer_status),
165 dev->timeout);
166
167 if (rc > 0)
168 DEBUGP(4, dev, "woke up: BulkOut empty\n");
169 else if (rc == 0)
170 DEBUGP(4, dev, "woke up: BulkOut full, returning 0 :(\n");
171 else if (rc < 0)
172 DEBUGP(4, dev, "woke up: signal arrived\n");
173
174 return rc;
175}
176
177/* Write to Sync Control Register */
178static int write_sync_reg(unsigned char val, struct reader_dev *dev)
179{
180 int iobase = dev->link.io.BasePort1;
181 int rc;
182
183 rc = wait_for_bulk_out_ready(dev);
184 if (rc <= 0)
185 return rc;
186
187 xoutb(val, iobase + REG_OFFSET_SYNC_CONTROL);
188 rc = wait_for_bulk_out_ready(dev);
189 if (rc <= 0)
190 return rc;
191
192 return 1;
193}
194
195static int wait_for_bulk_in_ready(struct reader_dev *dev)
196{
197 int i, rc;
198 int iobase = dev->link.io.BasePort1;
199
200 for (i = 0; i < POLL_LOOP_COUNT; i++) {
201 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS)
202 & BSR_BULK_IN_FULL) == BSR_BULK_IN_FULL) {
203 DEBUGP(3, dev, "BulkIn full (i=%d)\n", i);
204 return 1;
205 }
206 }
207
208 DEBUGP(4, dev, "wait_event_interruptible_timeout(timeout=%ld\n",
209 dev->timeout);
210 rc = wait_event_interruptible_timeout(dev->read_wait,
211 test_and_clear_bit(BS_READABLE,
212 &dev->buffer_status),
213 dev->timeout);
214 if (rc > 0)
215 DEBUGP(4, dev, "woke up: BulkIn full\n");
216 else if (rc == 0)
217 DEBUGP(4, dev, "woke up: BulkIn not full, returning 0 :(\n");
218 else if (rc < 0)
219 DEBUGP(4, dev, "woke up: signal arrived\n");
220
221 return rc;
222}
223
224static ssize_t cm4040_read(struct file *filp, char __user *buf,
225 size_t count, loff_t *ppos)
226{
227 struct reader_dev *dev = filp->private_data;
228 int iobase = dev->link.io.BasePort1;
229 size_t bytes_to_read;
230 unsigned long i;
231 size_t min_bytes_to_read;
232 int rc;
233 unsigned char uc;
234
235 DEBUGP(2, dev, "-> cm4040_read(%s,%d)\n", current->comm, current->pid);
236
237 if (count == 0)
238 return 0;
239
240 if (count < 10)
241 return -EFAULT;
242
243 if (filp->f_flags & O_NONBLOCK) {
244 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n");
245 DEBUGP(2, dev, "<- cm4040_read (failure)\n");
246 return -EAGAIN;
247 }
248
249 if ((dev->link.state & DEV_PRESENT)==0)
250 return -ENODEV;
251
252 for (i = 0; i < 5; i++) {
253 rc = wait_for_bulk_in_ready(dev);
254 if (rc <= 0) {
255 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc);
256 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
257 if (rc == -ERESTARTSYS)
258 return rc;
259 return -EIO;
260 }
261 dev->r_buf[i] = xinb(iobase + REG_OFFSET_BULK_IN);
262#ifdef PCMCIA_DEBUG
263 if (pc_debug >= 6)
264 printk(KERN_DEBUG "%lu:%2x ", i, dev->r_buf[i]);
265 }
266 printk("\n");
267#else
268 }
269#endif
270
271 bytes_to_read = 5 + le32_to_cpu(*(__le32 *)&dev->r_buf[1]);
272
273 DEBUGP(6, dev, "BytesToRead=%lu\n", bytes_to_read);
274
275 min_bytes_to_read = min(count, bytes_to_read + 5);
276
277 DEBUGP(6, dev, "Min=%lu\n", min_bytes_to_read);
278
279 for (i = 0; i < (min_bytes_to_read-5); i++) {
280 rc = wait_for_bulk_in_ready(dev);
281 if (rc <= 0) {
282 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc);
283 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
284 if (rc == -ERESTARTSYS)
285 return rc;
286 return -EIO;
287 }
288 dev->r_buf[i+5] = xinb(iobase + REG_OFFSET_BULK_IN);
289#ifdef PCMCIA_DEBUG
290 if (pc_debug >= 6)
291 printk(KERN_DEBUG "%lu:%2x ", i, dev->r_buf[i]);
292 }
293 printk("\n");
294#else
295 }
296#endif
297
298 *ppos = min_bytes_to_read;
299 if (copy_to_user(buf, dev->r_buf, min_bytes_to_read))
300 return -EFAULT;
301
302 rc = wait_for_bulk_in_ready(dev);
303 if (rc <= 0) {
304 DEBUGP(5, dev, "wait_for_bulk_in_ready rc=%.2x\n", rc);
305 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
306 if (rc == -ERESTARTSYS)
307 return rc;
308 return -EIO;
309 }
310
311 rc = write_sync_reg(SCR_READER_TO_HOST_DONE, dev);
312 if (rc <= 0) {
313 DEBUGP(5, dev, "write_sync_reg c=%.2x\n", rc);
314 DEBUGP(2, dev, "<- cm4040_read (failed)\n");
315 if (rc == -ERESTARTSYS)
316 return rc;
317 else
318 return -EIO;
319 }
320
321 uc = xinb(iobase + REG_OFFSET_BULK_IN);
322
323 DEBUGP(2, dev, "<- cm4040_read (successfully)\n");
324 return min_bytes_to_read;
325}
326
327static ssize_t cm4040_write(struct file *filp, const char __user *buf,
328 size_t count, loff_t *ppos)
329{
330 struct reader_dev *dev = filp->private_data;
331 int iobase = dev->link.io.BasePort1;
332 ssize_t rc;
333 int i;
334 unsigned int bytes_to_write;
335
336 DEBUGP(2, dev, "-> cm4040_write(%s,%d)\n", current->comm, current->pid);
337
338 if (count == 0) {
339 DEBUGP(2, dev, "<- cm4040_write empty read (successfully)\n");
340 return 0;
341 }
342
343 if (count < 5) {
344 DEBUGP(2, dev, "<- cm4040_write buffersize=%Zd < 5\n", count);
345 return -EIO;
346 }
347
348 if (filp->f_flags & O_NONBLOCK) {
349 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n");
350 DEBUGP(4, dev, "<- cm4040_write (failure)\n");
351 return -EAGAIN;
352 }
353
354 if ((dev->link.state & DEV_PRESENT) == 0)
355 return -ENODEV;
356
357 bytes_to_write = count;
358 if (copy_from_user(dev->s_buf, buf, bytes_to_write))
359 return -EFAULT;
360
361 switch (dev->s_buf[0]) {
362 case CMD_PC_TO_RDR_XFRBLOCK:
363 case CMD_PC_TO_RDR_SECURE:
364 case CMD_PC_TO_RDR_TEST_SECURE:
365 case CMD_PC_TO_RDR_OK_SECURE:
366 dev->timeout = CCID_DRIVER_BULK_DEFAULT_TIMEOUT;
367 break;
368
369 case CMD_PC_TO_RDR_ICCPOWERON:
370 dev->timeout = CCID_DRIVER_ASYNC_POWERUP_TIMEOUT;
371 break;
372
373 case CMD_PC_TO_RDR_GETSLOTSTATUS:
374 case CMD_PC_TO_RDR_ICCPOWEROFF:
375 case CMD_PC_TO_RDR_GETPARAMETERS:
376 case CMD_PC_TO_RDR_RESETPARAMETERS:
377 case CMD_PC_TO_RDR_SETPARAMETERS:
378 case CMD_PC_TO_RDR_ESCAPE:
379 case CMD_PC_TO_RDR_ICCCLOCK:
380 default:
381 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
382 break;
383 }
384
385 rc = write_sync_reg(SCR_HOST_TO_READER_START, dev);
386 if (rc <= 0) {
387 DEBUGP(5, dev, "write_sync_reg c=%.2Zx\n", rc);
388 DEBUGP(2, dev, "<- cm4040_write (failed)\n");
389 if (rc == -ERESTARTSYS)
390 return rc;
391 else
392 return -EIO;
393 }
394
395 DEBUGP(4, dev, "start \n");
396
397 for (i = 0; i < bytes_to_write; i++) {
398 rc = wait_for_bulk_out_ready(dev);
399 if (rc <= 0) {
400 DEBUGP(5, dev, "wait_for_bulk_out_ready rc=%.2Zx\n",
401 rc);
402 DEBUGP(2, dev, "<- cm4040_write (failed)\n");
403 if (rc == -ERESTARTSYS)
404 return rc;
405 else
406 return -EIO;
407 }
408
409 xoutb(dev->s_buf[i],iobase + REG_OFFSET_BULK_OUT);
410 }
411 DEBUGP(4, dev, "end\n");
412
413 rc = write_sync_reg(SCR_HOST_TO_READER_DONE, dev);
414
415 if (rc <= 0) {
416 DEBUGP(5, dev, "write_sync_reg c=%.2Zx\n", rc);
417 DEBUGP(2, dev, "<- cm4040_write (failed)\n");
418 if (rc == -ERESTARTSYS)
419 return rc;
420 else
421 return -EIO;
422 }
423
424 DEBUGP(2, dev, "<- cm4040_write (successfully)\n");
425 return count;
426}
427
428static unsigned int cm4040_poll(struct file *filp, poll_table *wait)
429{
430 struct reader_dev *dev = filp->private_data;
431 unsigned int mask = 0;
432
433 poll_wait(filp, &dev->poll_wait, wait);
434
435 if (test_and_clear_bit(BS_READABLE, &dev->buffer_status))
436 mask |= POLLIN | POLLRDNORM;
437 if (test_and_clear_bit(BS_WRITABLE, &dev->buffer_status))
438 mask |= POLLOUT | POLLWRNORM;
439
440 DEBUGP(2, dev, "<- cm4040_poll(%u)\n", mask);
441
442 return mask;
443}
444
445static int cm4040_open(struct inode *inode, struct file *filp)
446{
447 struct reader_dev *dev;
448 dev_link_t *link;
449 int minor = iminor(inode);
450
451 if (minor >= CM_MAX_DEV)
452 return -ENODEV;
453
454 link = dev_table[minor];
455 if (link == NULL || !(DEV_OK(link)))
456 return -ENODEV;
457
458 if (link->open)
459 return -EBUSY;
460
461 dev = link->priv;
462 filp->private_data = dev;
463
464 if (filp->f_flags & O_NONBLOCK) {
465 DEBUGP(4, dev, "filep->f_flags O_NONBLOCK set\n");
466 return -EAGAIN;
467 }
468
469 link->open = 1;
470
471 dev->poll_timer.data = (unsigned long) dev;
472 mod_timer(&dev->poll_timer, jiffies + POLL_PERIOD);
473
474 DEBUGP(2, dev, "<- cm4040_open (successfully)\n");
475 return nonseekable_open(inode, filp);
476}
477
478static int cm4040_close(struct inode *inode, struct file *filp)
479{
480 struct reader_dev *dev = filp->private_data;
481 dev_link_t *link;
482 int minor = iminor(inode);
483
484 DEBUGP(2, dev, "-> cm4040_close(maj/min=%d.%d)\n", imajor(inode),
485 iminor(inode));
486
487 if (minor >= CM_MAX_DEV)
488 return -ENODEV;
489
490 link = dev_table[minor];
491 if (link == NULL)
492 return -ENODEV;
493
494 cm4040_stop_poll(dev);
495
496 link->open = 0;
497 wake_up(&dev->devq);
498
499 DEBUGP(2, dev, "<- cm4040_close\n");
500 return 0;
501}
502
503static void cm4040_reader_release(dev_link_t *link)
504{
505 struct reader_dev *dev = link->priv;
506
507 DEBUGP(3, dev, "-> cm4040_reader_release\n");
508 while (link->open) {
509 DEBUGP(3, dev, KERN_INFO MODULE_NAME ": delaying release "
510 "until process has terminated\n");
511 wait_event(dev->devq, (link->open == 0));
512 }
513 DEBUGP(3, dev, "<- cm4040_reader_release\n");
514 return;
515}
516
517static void reader_config(dev_link_t *link, int devno)
518{
519 client_handle_t handle;
520 struct reader_dev *dev;
521 tuple_t tuple;
522 cisparse_t parse;
523 config_info_t conf;
524 u_char buf[64];
525 int fail_fn, fail_rc;
526 int rc;
527
528 handle = link->handle;
529
530 tuple.DesiredTuple = CISTPL_CONFIG;
531 tuple.Attributes = 0;
532 tuple.TupleData = buf;
533 tuple.TupleDataMax = sizeof(buf);
534 tuple.TupleOffset = 0;
535
536 if ((fail_rc = pcmcia_get_first_tuple(handle, &tuple)) != CS_SUCCESS) {
537 fail_fn = GetFirstTuple;
538 goto cs_failed;
539 }
540 if ((fail_rc = pcmcia_get_tuple_data(handle, &tuple)) != CS_SUCCESS) {
541 fail_fn = GetTupleData;
542 goto cs_failed;
543 }
544 if ((fail_rc = pcmcia_parse_tuple(handle, &tuple, &parse))
545 != CS_SUCCESS) {
546 fail_fn = ParseTuple;
547 goto cs_failed;
548 }
549 if ((fail_rc = pcmcia_get_configuration_info(handle, &conf))
550 != CS_SUCCESS) {
551 fail_fn = GetConfigurationInfo;
552 goto cs_failed;
553 }
554
555 link->state |= DEV_CONFIG;
556 link->conf.ConfigBase = parse.config.base;
557 link->conf.Present = parse.config.rmask[0];
558 link->conf.Vcc = conf.Vcc;
559
560 link->io.BasePort2 = 0;
561 link->io.NumPorts2 = 0;
562 link->io.Attributes2 = 0;
563 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
564 for (rc = pcmcia_get_first_tuple(handle, &tuple);
565 rc == CS_SUCCESS;
566 rc = pcmcia_get_next_tuple(handle, &tuple)) {
567 rc = pcmcia_get_tuple_data(handle, &tuple);
568 if (rc != CS_SUCCESS)
569 continue;
570 rc = pcmcia_parse_tuple(handle, &tuple, &parse);
571 if (rc != CS_SUCCESS)
572 continue;
573
574 link->conf.ConfigIndex = parse.cftable_entry.index;
575
576 if (!parse.cftable_entry.io.nwin)
577 continue;
578
579 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
580 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
581 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
582 if (!(parse.cftable_entry.io.flags & CISTPL_IO_8BIT))
583 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
584 if (!(parse.cftable_entry.io.flags & CISTPL_IO_16BIT))
585 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
586 link->io.IOAddrLines = parse.cftable_entry.io.flags
587 & CISTPL_IO_LINES_MASK;
588 rc = pcmcia_request_io(handle, &link->io);
589
590 dev_printk(KERN_INFO, &handle_to_dev(handle), "foo");
591 if (rc == CS_SUCCESS)
592 break;
593 else
594 dev_printk(KERN_INFO, &handle_to_dev(handle),
595 "pcmcia_request_io failed 0x%x\n", rc);
596 }
597 if (rc != CS_SUCCESS)
598 goto cs_release;
599
600 link->conf.IntType = 00000002;
601
602 if ((fail_rc = pcmcia_request_configuration(handle,&link->conf))
603 !=CS_SUCCESS) {
604 fail_fn = RequestConfiguration;
605 dev_printk(KERN_INFO, &handle_to_dev(handle),
606 "pcmcia_request_configuration failed 0x%x\n",
607 fail_rc);
608 goto cs_release;
609 }
610
611 dev = link->priv;
612 sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno);
613 dev->node.major = major;
614 dev->node.minor = devno;
615 dev->node.next = NULL;
616 link->dev = &dev->node;
617 link->state &= ~DEV_CONFIG_PENDING;
618
619 DEBUGP(2, dev, "device " DEVICE_NAME "%d at 0x%.4x-0x%.4x\n", devno,
620 link->io.BasePort1, link->io.BasePort1+link->io.NumPorts1);
621 DEBUGP(2, dev, "<- reader_config (succ)\n");
622
623 return;
624
625cs_failed:
626 cs_error(handle, fail_fn, fail_rc);
627cs_release:
628 reader_release(link);
629 link->state &= ~DEV_CONFIG_PENDING;
630}
631
632static int reader_event(event_t event, int priority,
633 event_callback_args_t *args)
634{
635 dev_link_t *link;
636 struct reader_dev *dev;
637 int devno;
638
639 link = args->client_data;
640 dev = link->priv;
641 DEBUGP(3, dev, "-> reader_event\n");
642 for (devno = 0; devno < CM_MAX_DEV; devno++) {
643 if (dev_table[devno] == link)
644 break;
645 }
646 if (devno == CM_MAX_DEV)
647 return CS_BAD_ADAPTER;
648
649 switch (event) {
650 case CS_EVENT_CARD_INSERTION:
651 DEBUGP(5, dev, "CS_EVENT_CARD_INSERTION\n");
652 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
653 reader_config(link, devno);
654 break;
655 case CS_EVENT_CARD_REMOVAL:
656 DEBUGP(5, dev, "CS_EVENT_CARD_REMOVAL\n");
657 link->state &= ~DEV_PRESENT;
658 break;
659 case CS_EVENT_PM_SUSPEND:
660 DEBUGP(5, dev, "CS_EVENT_PM_SUSPEND "
661 "(fall-through to CS_EVENT_RESET_PHYSICAL)\n");
662 link->state |= DEV_SUSPEND;
663
664 case CS_EVENT_RESET_PHYSICAL:
665 DEBUGP(5, dev, "CS_EVENT_RESET_PHYSICAL\n");
666 if (link->state & DEV_CONFIG) {
667 DEBUGP(5, dev, "ReleaseConfiguration\n");
668 pcmcia_release_configuration(link->handle);
669 }
670 break;
671 case CS_EVENT_PM_RESUME:
672 DEBUGP(5, dev, "CS_EVENT_PM_RESUME "
673 "(fall-through to CS_EVENT_CARD_RESET)\n");
674 link->state &= ~DEV_SUSPEND;
675
676 case CS_EVENT_CARD_RESET:
677 DEBUGP(5, dev, "CS_EVENT_CARD_RESET\n");
678 if ((link->state & DEV_CONFIG)) {
679 DEBUGP(5, dev, "RequestConfiguration\n");
680 pcmcia_request_configuration(link->handle,
681 &link->conf);
682 }
683 break;
684 default:
685 DEBUGP(5, dev, "reader_event: unknown event %.2x\n",
686 event);
687 break;
688 }
689 DEBUGP(3, dev, "<- reader_event\n");
690 return CS_SUCCESS;
691}
692
693static void reader_release(dev_link_t *link)
694{
695 cm4040_reader_release(link->priv);
696 pcmcia_release_configuration(link->handle);
697 pcmcia_release_io(link->handle, &link->io);
698}
699
700static dev_link_t *reader_attach(void)
701{
702 struct reader_dev *dev;
703 dev_link_t *link;
704 client_reg_t client_reg;
705 int i;
706
707 for (i = 0; i < CM_MAX_DEV; i++) {
708 if (dev_table[i] == NULL)
709 break;
710 }
711
712 if (i == CM_MAX_DEV)
713 return NULL;
714
715 dev = kzalloc(sizeof(struct reader_dev), GFP_KERNEL);
716 if (dev == NULL)
717 return NULL;
718
719 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
720 dev->buffer_status = 0;
721
722 link = &dev->link;
723 link->priv = dev;
724
725 link->conf.IntType = INT_MEMORY_AND_IO;
726 dev_table[i] = link;
727
728 client_reg.dev_info = &dev_info;
729 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
730 client_reg.EventMask=
731 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
732 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
733 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
734 client_reg.Version = 0x0210;
735 client_reg.event_callback_args.client_data = link;
736 i = pcmcia_register_client(&link->handle, &client_reg);
737 if (i) {
738 cs_error(link->handle, RegisterClient, i);
739 reader_detach(link);
740 return NULL;
741 }
742 init_waitqueue_head(&dev->devq);
743 init_waitqueue_head(&dev->poll_wait);
744 init_waitqueue_head(&dev->read_wait);
745 init_waitqueue_head(&dev->write_wait);
746 init_timer(&dev->poll_timer);
747 dev->poll_timer.function = &cm4040_do_poll;
748
749 return link;
750}
751
752static void reader_detach_by_devno(int devno, dev_link_t *link)
753{
754 struct reader_dev *dev = link->priv;
755
756 if (link->state & DEV_CONFIG) {
757 DEBUGP(5, dev, "device still configured (try to release it)\n");
758 reader_release(link);
759 }
760
761 pcmcia_deregister_client(link->handle);
762 dev_table[devno] = NULL;
763 DEBUGP(5, dev, "freeing dev=%p\n", dev);
764 cm4040_stop_poll(dev);
765 kfree(dev);
766 return;
767}
768
769static void reader_detach(dev_link_t *link)
770{
771 int i;
772
773 /* find device */
774 for (i = 0; i < CM_MAX_DEV; i++) {
775 if (dev_table[i] == link)
776 break;
777 }
778 if (i == CM_MAX_DEV)
779 return;
780
781 reader_detach_by_devno(i, link);
782 return;
783}
784
785static struct file_operations reader_fops = {
786 .owner = THIS_MODULE,
787 .read = cm4040_read,
788 .write = cm4040_write,
789 .open = cm4040_open,
790 .release = cm4040_close,
791 .poll = cm4040_poll,
792};
793
794static struct pcmcia_device_id cm4040_ids[] = {
795 PCMCIA_DEVICE_MANF_CARD(0x0223, 0x0200),
796 PCMCIA_DEVICE_PROD_ID12("OMNIKEY", "CardMan 4040",
797 0xE32CDD8C, 0x8F23318B),
798 PCMCIA_DEVICE_NULL,
799};
800MODULE_DEVICE_TABLE(pcmcia, cm4040_ids);
801
802static struct pcmcia_driver reader_driver = {
803 .owner = THIS_MODULE,
804 .drv = {
805 .name = "cm4040_cs",
806 },
807 .attach = reader_attach,
808 .detach = reader_detach,
809 .event = reader_event,
810 .id_table = cm4040_ids,
811};
812
813static int __init cm4040_init(void)
814{
815 printk(KERN_INFO "%s\n", version);
816 pcmcia_register_driver(&reader_driver);
817 major = register_chrdev(0, DEVICE_NAME, &reader_fops);
818 if (major < 0) {
819 printk(KERN_WARNING MODULE_NAME
820 ": could not get major number\n");
821 return -1;
822 }
823 return 0;
824}
825
826static void __exit cm4040_exit(void)
827{
828 int i;
829
830 printk(KERN_INFO MODULE_NAME ": unloading\n");
831 pcmcia_unregister_driver(&reader_driver);
832 for (i = 0; i < CM_MAX_DEV; i++) {
833 if (dev_table[i])
834 reader_detach_by_devno(i, dev_table[i]);
835 }
836 unregister_chrdev(major, DEVICE_NAME);
837}
838
839module_init(cm4040_init);
840module_exit(cm4040_exit);
841MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/char/pcmcia/cm4040_cs.h b/drivers/char/pcmcia/cm4040_cs.h
new file mode 100644
index 000000000000..9a8b805c5095
--- /dev/null
+++ b/drivers/char/pcmcia/cm4040_cs.h
@@ -0,0 +1,47 @@
1#ifndef _CM4040_H_
2#define _CM4040_H_
3
4#define CM_MAX_DEV 4
5
6#define DEVICE_NAME "cmx"
7#define MODULE_NAME "cm4040_cs"
8
9#define REG_OFFSET_BULK_OUT 0
10#define REG_OFFSET_BULK_IN 0
11#define REG_OFFSET_BUFFER_STATUS 1
12#define REG_OFFSET_SYNC_CONTROL 2
13
14#define BSR_BULK_IN_FULL 0x02
15#define BSR_BULK_OUT_FULL 0x01
16
17#define SCR_HOST_TO_READER_START 0x80
18#define SCR_ABORT 0x40
19#define SCR_EN_NOTIFY 0x20
20#define SCR_ACK_NOTIFY 0x10
21#define SCR_READER_TO_HOST_DONE 0x08
22#define SCR_HOST_TO_READER_DONE 0x04
23#define SCR_PULSE_INTERRUPT 0x02
24#define SCR_POWER_DOWN 0x01
25
26
27#define CMD_PC_TO_RDR_ICCPOWERON 0x62
28#define CMD_PC_TO_RDR_GETSLOTSTATUS 0x65
29#define CMD_PC_TO_RDR_ICCPOWEROFF 0x63
30#define CMD_PC_TO_RDR_SECURE 0x69
31#define CMD_PC_TO_RDR_GETPARAMETERS 0x6C
32#define CMD_PC_TO_RDR_RESETPARAMETERS 0x6D
33#define CMD_PC_TO_RDR_SETPARAMETERS 0x61
34#define CMD_PC_TO_RDR_XFRBLOCK 0x6F
35#define CMD_PC_TO_RDR_ESCAPE 0x6B
36#define CMD_PC_TO_RDR_ICCCLOCK 0x6E
37#define CMD_PC_TO_RDR_TEST_SECURE 0x74
38#define CMD_PC_TO_RDR_OK_SECURE 0x89
39
40
41#define CMD_RDR_TO_PC_SLOTSTATUS 0x81
42#define CMD_RDR_TO_PC_DATABLOCK 0x80
43#define CMD_RDR_TO_PC_PARAMETERS 0x82
44#define CMD_RDR_TO_PC_ESCAPE 0x83
45#define CMD_RDR_TO_PC_OK_SECURE 0x89
46
47#endif /* _CM4040_H_ */
diff --git a/drivers/char/s3c2410-rtc.c b/drivers/char/s3c2410-rtc.c
index d724c0de4f28..3df7a574267b 100644
--- a/drivers/char/s3c2410-rtc.c
+++ b/drivers/char/s3c2410-rtc.c
@@ -382,7 +382,7 @@ static struct rtc_ops s3c2410_rtcops = {
382 .proc = s3c2410_rtc_proc, 382 .proc = s3c2410_rtc_proc,
383}; 383};
384 384
385static void s3c2410_rtc_enable(struct device *dev, int en) 385static void s3c2410_rtc_enable(struct platform_device *pdev, int en)
386{ 386{
387 unsigned int tmp; 387 unsigned int tmp;
388 388
@@ -399,21 +399,21 @@ static void s3c2410_rtc_enable(struct device *dev, int en)
399 /* re-enable the device, and check it is ok */ 399 /* re-enable the device, and check it is ok */
400 400
401 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_RTCEN) == 0){ 401 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_RTCEN) == 0){
402 dev_info(dev, "rtc disabled, re-enabling\n"); 402 dev_info(&pdev->dev, "rtc disabled, re-enabling\n");
403 403
404 tmp = readb(S3C2410_RTCCON); 404 tmp = readb(S3C2410_RTCCON);
405 writeb(tmp | S3C2410_RTCCON_RTCEN , S3C2410_RTCCON); 405 writeb(tmp | S3C2410_RTCCON_RTCEN , S3C2410_RTCCON);
406 } 406 }
407 407
408 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_CNTSEL)){ 408 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_CNTSEL)){
409 dev_info(dev, "removing S3C2410_RTCCON_CNTSEL\n"); 409 dev_info(&pdev->dev, "removing S3C2410_RTCCON_CNTSEL\n");
410 410
411 tmp = readb(S3C2410_RTCCON); 411 tmp = readb(S3C2410_RTCCON);
412 writeb(tmp& ~S3C2410_RTCCON_CNTSEL , S3C2410_RTCCON); 412 writeb(tmp& ~S3C2410_RTCCON_CNTSEL , S3C2410_RTCCON);
413 } 413 }
414 414
415 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_CLKRST)){ 415 if ((readb(S3C2410_RTCCON) & S3C2410_RTCCON_CLKRST)){
416 dev_info(dev, "removing S3C2410_RTCCON_CLKRST\n"); 416 dev_info(&pdev->dev, "removing S3C2410_RTCCON_CLKRST\n");
417 417
418 tmp = readb(S3C2410_RTCCON); 418 tmp = readb(S3C2410_RTCCON);
419 writeb(tmp & ~S3C2410_RTCCON_CLKRST, S3C2410_RTCCON); 419 writeb(tmp & ~S3C2410_RTCCON_CLKRST, S3C2410_RTCCON);
@@ -421,7 +421,7 @@ static void s3c2410_rtc_enable(struct device *dev, int en)
421 } 421 }
422} 422}
423 423
424static int s3c2410_rtc_remove(struct device *dev) 424static int s3c2410_rtc_remove(struct platform_device *dev)
425{ 425{
426 unregister_rtc(&s3c2410_rtcops); 426 unregister_rtc(&s3c2410_rtcops);
427 427
@@ -438,25 +438,24 @@ static int s3c2410_rtc_remove(struct device *dev)
438 return 0; 438 return 0;
439} 439}
440 440
441static int s3c2410_rtc_probe(struct device *dev) 441static int s3c2410_rtc_probe(struct platform_device *pdev)
442{ 442{
443 struct platform_device *pdev = to_platform_device(dev);
444 struct resource *res; 443 struct resource *res;
445 int ret; 444 int ret;
446 445
447 pr_debug("%s: probe=%p, device=%p\n", __FUNCTION__, pdev, dev); 446 pr_debug("%s: probe=%p\n", __FUNCTION__, pdev);
448 447
449 /* find the IRQs */ 448 /* find the IRQs */
450 449
451 s3c2410_rtc_tickno = platform_get_irq(pdev, 1); 450 s3c2410_rtc_tickno = platform_get_irq(pdev, 1);
452 if (s3c2410_rtc_tickno <= 0) { 451 if (s3c2410_rtc_tickno <= 0) {
453 dev_err(dev, "no irq for rtc tick\n"); 452 dev_err(&pdev->dev, "no irq for rtc tick\n");
454 return -ENOENT; 453 return -ENOENT;
455 } 454 }
456 455
457 s3c2410_rtc_alarmno = platform_get_irq(pdev, 0); 456 s3c2410_rtc_alarmno = platform_get_irq(pdev, 0);
458 if (s3c2410_rtc_alarmno <= 0) { 457 if (s3c2410_rtc_alarmno <= 0) {
459 dev_err(dev, "no irq for alarm\n"); 458 dev_err(&pdev->dev, "no irq for alarm\n");
460 return -ENOENT; 459 return -ENOENT;
461 } 460 }
462 461
@@ -467,7 +466,7 @@ static int s3c2410_rtc_probe(struct device *dev)
467 466
468 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 467 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
469 if (res == NULL) { 468 if (res == NULL) {
470 dev_err(dev, "failed to get memory region resource\n"); 469 dev_err(&pdev->dev, "failed to get memory region resource\n");
471 return -ENOENT; 470 return -ENOENT;
472 } 471 }
473 472
@@ -475,14 +474,14 @@ static int s3c2410_rtc_probe(struct device *dev)
475 pdev->name); 474 pdev->name);
476 475
477 if (s3c2410_rtc_mem == NULL) { 476 if (s3c2410_rtc_mem == NULL) {
478 dev_err(dev, "failed to reserve memory region\n"); 477 dev_err(&pdev->dev, "failed to reserve memory region\n");
479 ret = -ENOENT; 478 ret = -ENOENT;
480 goto exit_err; 479 goto exit_err;
481 } 480 }
482 481
483 s3c2410_rtc_base = ioremap(res->start, res->end - res->start + 1); 482 s3c2410_rtc_base = ioremap(res->start, res->end - res->start + 1);
484 if (s3c2410_rtc_base == NULL) { 483 if (s3c2410_rtc_base == NULL) {
485 dev_err(dev, "failed ioremap()\n"); 484 dev_err(&pdev->dev, "failed ioremap()\n");
486 ret = -EINVAL; 485 ret = -EINVAL;
487 goto exit_err; 486 goto exit_err;
488 } 487 }
@@ -494,7 +493,7 @@ static int s3c2410_rtc_probe(struct device *dev)
494 493
495 /* check to see if everything is setup correctly */ 494 /* check to see if everything is setup correctly */
496 495
497 s3c2410_rtc_enable(dev, 1); 496 s3c2410_rtc_enable(pdev, 1);
498 497
499 pr_debug("s3c2410_rtc: RTCCON=%02x\n", readb(S3C2410_RTCCON)); 498 pr_debug("s3c2410_rtc: RTCCON=%02x\n", readb(S3C2410_RTCCON));
500 499
@@ -506,7 +505,7 @@ static int s3c2410_rtc_probe(struct device *dev)
506 return 0; 505 return 0;
507 506
508 exit_err: 507 exit_err:
509 dev_err(dev, "error %d during initialisation\n", ret); 508 dev_err(&pdev->dev, "error %d during initialisation\n", ret);
510 509
511 return ret; 510 return ret;
512} 511}
@@ -519,7 +518,7 @@ static struct timespec s3c2410_rtc_delta;
519 518
520static int ticnt_save; 519static int ticnt_save;
521 520
522static int s3c2410_rtc_suspend(struct device *dev, pm_message_t state) 521static int s3c2410_rtc_suspend(struct platform_device *pdev, pm_message_t state)
523{ 522{
524 struct rtc_time tm; 523 struct rtc_time tm;
525 struct timespec time; 524 struct timespec time;
@@ -535,19 +534,19 @@ static int s3c2410_rtc_suspend(struct device *dev, pm_message_t state)
535 s3c2410_rtc_gettime(&tm); 534 s3c2410_rtc_gettime(&tm);
536 rtc_tm_to_time(&tm, &time.tv_sec); 535 rtc_tm_to_time(&tm, &time.tv_sec);
537 save_time_delta(&s3c2410_rtc_delta, &time); 536 save_time_delta(&s3c2410_rtc_delta, &time);
538 s3c2410_rtc_enable(dev, 0); 537 s3c2410_rtc_enable(pdev, 0);
539 538
540 return 0; 539 return 0;
541} 540}
542 541
543static int s3c2410_rtc_resume(struct device *dev) 542static int s3c2410_rtc_resume(struct platform_device *pdev)
544{ 543{
545 struct rtc_time tm; 544 struct rtc_time tm;
546 struct timespec time; 545 struct timespec time;
547 546
548 time.tv_nsec = 0; 547 time.tv_nsec = 0;
549 548
550 s3c2410_rtc_enable(dev, 1); 549 s3c2410_rtc_enable(pdev, 1);
551 s3c2410_rtc_gettime(&tm); 550 s3c2410_rtc_gettime(&tm);
552 rtc_tm_to_time(&tm, &time.tv_sec); 551 rtc_tm_to_time(&tm, &time.tv_sec);
553 restore_time_delta(&s3c2410_rtc_delta, &time); 552 restore_time_delta(&s3c2410_rtc_delta, &time);
@@ -560,14 +559,15 @@ static int s3c2410_rtc_resume(struct device *dev)
560#define s3c2410_rtc_resume NULL 559#define s3c2410_rtc_resume NULL
561#endif 560#endif
562 561
563static struct device_driver s3c2410_rtcdrv = { 562static struct platform_driver s3c2410_rtcdrv = {
564 .name = "s3c2410-rtc",
565 .owner = THIS_MODULE,
566 .bus = &platform_bus_type,
567 .probe = s3c2410_rtc_probe, 563 .probe = s3c2410_rtc_probe,
568 .remove = s3c2410_rtc_remove, 564 .remove = s3c2410_rtc_remove,
569 .suspend = s3c2410_rtc_suspend, 565 .suspend = s3c2410_rtc_suspend,
570 .resume = s3c2410_rtc_resume, 566 .resume = s3c2410_rtc_resume,
567 .driver = {
568 .name = "s3c2410-rtc",
569 .owner = THIS_MODULE,
570 },
571}; 571};
572 572
573static char __initdata banner[] = "S3C2410 RTC, (c) 2004 Simtec Electronics\n"; 573static char __initdata banner[] = "S3C2410 RTC, (c) 2004 Simtec Electronics\n";
@@ -575,12 +575,12 @@ static char __initdata banner[] = "S3C2410 RTC, (c) 2004 Simtec Electronics\n";
575static int __init s3c2410_rtc_init(void) 575static int __init s3c2410_rtc_init(void)
576{ 576{
577 printk(banner); 577 printk(banner);
578 return driver_register(&s3c2410_rtcdrv); 578 return platform_driver_register(&s3c2410_rtcdrv);
579} 579}
580 580
581static void __exit s3c2410_rtc_exit(void) 581static void __exit s3c2410_rtc_exit(void)
582{ 582{
583 driver_unregister(&s3c2410_rtcdrv); 583 platform_driver_unregister(&s3c2410_rtcdrv);
584} 584}
585 585
586module_init(s3c2410_rtc_init); 586module_init(s3c2410_rtc_init);
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index d05067dcea01..51a07370e636 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -1168,7 +1168,7 @@ static int sonypi_disable(void)
1168#ifdef CONFIG_PM 1168#ifdef CONFIG_PM
1169static int old_camera_power; 1169static int old_camera_power;
1170 1170
1171static int sonypi_suspend(struct device *dev, pm_message_t state) 1171static int sonypi_suspend(struct platform_device *dev, pm_message_t state)
1172{ 1172{
1173 old_camera_power = sonypi_device.camera_power; 1173 old_camera_power = sonypi_device.camera_power;
1174 sonypi_disable(); 1174 sonypi_disable();
@@ -1176,26 +1176,27 @@ static int sonypi_suspend(struct device *dev, pm_message_t state)
1176 return 0; 1176 return 0;
1177} 1177}
1178 1178
1179static int sonypi_resume(struct device *dev) 1179static int sonypi_resume(struct platform_device *dev)
1180{ 1180{
1181 sonypi_enable(old_camera_power); 1181 sonypi_enable(old_camera_power);
1182 return 0; 1182 return 0;
1183} 1183}
1184#endif 1184#endif
1185 1185
1186static void sonypi_shutdown(struct device *dev) 1186static void sonypi_shutdown(struct platform_device *dev)
1187{ 1187{
1188 sonypi_disable(); 1188 sonypi_disable();
1189} 1189}
1190 1190
1191static struct device_driver sonypi_driver = { 1191static struct platform_driver sonypi_driver = {
1192 .name = "sonypi",
1193 .bus = &platform_bus_type,
1194#ifdef CONFIG_PM 1192#ifdef CONFIG_PM
1195 .suspend = sonypi_suspend, 1193 .suspend = sonypi_suspend,
1196 .resume = sonypi_resume, 1194 .resume = sonypi_resume,
1197#endif 1195#endif
1198 .shutdown = sonypi_shutdown, 1196 .shutdown = sonypi_shutdown,
1197 .driver = {
1198 .name = "sonypi",
1199 },
1199}; 1200};
1200 1201
1201static int __devinit sonypi_create_input_devices(void) 1202static int __devinit sonypi_create_input_devices(void)
@@ -1455,20 +1456,20 @@ static int __init sonypi_init(void)
1455 if (!dmi_check_system(sonypi_dmi_table)) 1456 if (!dmi_check_system(sonypi_dmi_table))
1456 return -ENODEV; 1457 return -ENODEV;
1457 1458
1458 ret = driver_register(&sonypi_driver); 1459 ret = platform_driver_register(&sonypi_driver);
1459 if (ret) 1460 if (ret)
1460 return ret; 1461 return ret;
1461 1462
1462 ret = sonypi_probe(); 1463 ret = sonypi_probe();
1463 if (ret) 1464 if (ret)
1464 driver_unregister(&sonypi_driver); 1465 platform_driver_unregister(&sonypi_driver);
1465 1466
1466 return ret; 1467 return ret;
1467} 1468}
1468 1469
1469static void __exit sonypi_exit(void) 1470static void __exit sonypi_exit(void)
1470{ 1471{
1471 driver_unregister(&sonypi_driver); 1472 platform_driver_unregister(&sonypi_driver);
1472 sonypi_remove(); 1473 sonypi_remove();
1473} 1474}
1474 1475
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 5d1ffa3bd4c3..62aa0e534a6d 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * linux/drivers/char/synclink.c 2 * linux/drivers/char/synclink.c
3 * 3 *
4 * $Id: synclink.c,v 4.37 2005/09/07 13:13:19 paulkf Exp $ 4 * $Id: synclink.c,v 4.38 2005/11/07 16:30:34 paulkf Exp $
5 * 5 *
6 * Device driver for Microgate SyncLink ISA and PCI 6 * Device driver for Microgate SyncLink ISA and PCI
7 * high speed multiprotocol serial adapters. 7 * high speed multiprotocol serial adapters.
@@ -101,6 +101,7 @@
101#include <linux/termios.h> 101#include <linux/termios.h>
102#include <linux/workqueue.h> 102#include <linux/workqueue.h>
103#include <linux/hdlc.h> 103#include <linux/hdlc.h>
104#include <linux/dma-mapping.h>
104 105
105#ifdef CONFIG_HDLC_MODULE 106#ifdef CONFIG_HDLC_MODULE
106#define CONFIG_HDLC 1 107#define CONFIG_HDLC 1
@@ -148,6 +149,7 @@ typedef struct _DMABUFFERENTRY
148 u32 link; /* 32-bit flat link to next buffer entry */ 149 u32 link; /* 32-bit flat link to next buffer entry */
149 char *virt_addr; /* virtual address of data buffer */ 150 char *virt_addr; /* virtual address of data buffer */
150 u32 phys_entry; /* physical address of this buffer entry */ 151 u32 phys_entry; /* physical address of this buffer entry */
152 dma_addr_t dma_addr;
151} DMABUFFERENTRY, *DMAPBUFFERENTRY; 153} DMABUFFERENTRY, *DMAPBUFFERENTRY;
152 154
153/* The queue of BH actions to be performed */ 155/* The queue of BH actions to be performed */
@@ -233,7 +235,8 @@ struct mgsl_struct {
233 int ri_chkcount; 235 int ri_chkcount;
234 236
235 char *buffer_list; /* virtual address of Rx & Tx buffer lists */ 237 char *buffer_list; /* virtual address of Rx & Tx buffer lists */
236 unsigned long buffer_list_phys; 238 u32 buffer_list_phys;
239 dma_addr_t buffer_list_dma_addr;
237 240
238 unsigned int rx_buffer_count; /* count of total allocated Rx buffers */ 241 unsigned int rx_buffer_count; /* count of total allocated Rx buffers */
239 DMABUFFERENTRY *rx_buffer_list; /* list of receive buffer entries */ 242 DMABUFFERENTRY *rx_buffer_list; /* list of receive buffer entries */
@@ -896,7 +899,7 @@ module_param_array(txdmabufs, int, NULL, 0);
896module_param_array(txholdbufs, int, NULL, 0); 899module_param_array(txholdbufs, int, NULL, 0);
897 900
898static char *driver_name = "SyncLink serial driver"; 901static char *driver_name = "SyncLink serial driver";
899static char *driver_version = "$Revision: 4.37 $"; 902static char *driver_version = "$Revision: 4.38 $";
900 903
901static int synclink_init_one (struct pci_dev *dev, 904static int synclink_init_one (struct pci_dev *dev,
902 const struct pci_device_id *ent); 905 const struct pci_device_id *ent);
@@ -912,7 +915,6 @@ MODULE_DEVICE_TABLE(pci, synclink_pci_tbl);
912MODULE_LICENSE("GPL"); 915MODULE_LICENSE("GPL");
913 916
914static struct pci_driver synclink_pci_driver = { 917static struct pci_driver synclink_pci_driver = {
915 .owner = THIS_MODULE,
916 .name = "synclink", 918 .name = "synclink",
917 .id_table = synclink_pci_tbl, 919 .id_table = synclink_pci_tbl,
918 .probe = synclink_init_one, 920 .probe = synclink_init_one,
@@ -3812,11 +3814,10 @@ static int mgsl_alloc_buffer_list_memory( struct mgsl_struct *info )
3812 /* inspect portions of the buffer while other portions are being */ 3814 /* inspect portions of the buffer while other portions are being */
3813 /* updated by the adapter using Bus Master DMA. */ 3815 /* updated by the adapter using Bus Master DMA. */
3814 3816
3815 info->buffer_list = kmalloc(BUFFERLISTSIZE, GFP_KERNEL | GFP_DMA); 3817 info->buffer_list = dma_alloc_coherent(NULL, BUFFERLISTSIZE, &info->buffer_list_dma_addr, GFP_KERNEL);
3816 if ( info->buffer_list == NULL ) 3818 if (info->buffer_list == NULL)
3817 return -ENOMEM; 3819 return -ENOMEM;
3818 3820 info->buffer_list_phys = (u32)(info->buffer_list_dma_addr);
3819 info->buffer_list_phys = isa_virt_to_bus(info->buffer_list);
3820 } 3821 }
3821 3822
3822 /* We got the memory for the buffer entry lists. */ 3823 /* We got the memory for the buffer entry lists. */
@@ -3883,8 +3884,8 @@ static int mgsl_alloc_buffer_list_memory( struct mgsl_struct *info )
3883 */ 3884 */
3884static void mgsl_free_buffer_list_memory( struct mgsl_struct *info ) 3885static void mgsl_free_buffer_list_memory( struct mgsl_struct *info )
3885{ 3886{
3886 if ( info->buffer_list && info->bus_type != MGSL_BUS_TYPE_PCI ) 3887 if (info->buffer_list && info->bus_type != MGSL_BUS_TYPE_PCI)
3887 kfree(info->buffer_list); 3888 dma_free_coherent(NULL, BUFFERLISTSIZE, info->buffer_list, info->buffer_list_dma_addr);
3888 3889
3889 info->buffer_list = NULL; 3890 info->buffer_list = NULL;
3890 info->rx_buffer_list = NULL; 3891 info->rx_buffer_list = NULL;
@@ -3911,7 +3912,7 @@ static void mgsl_free_buffer_list_memory( struct mgsl_struct *info )
3911static int mgsl_alloc_frame_memory(struct mgsl_struct *info,DMABUFFERENTRY *BufferList,int Buffercount) 3912static int mgsl_alloc_frame_memory(struct mgsl_struct *info,DMABUFFERENTRY *BufferList,int Buffercount)
3912{ 3913{
3913 int i; 3914 int i;
3914 unsigned long phys_addr; 3915 u32 phys_addr;
3915 3916
3916 /* Allocate page sized buffers for the receive buffer list */ 3917 /* Allocate page sized buffers for the receive buffer list */
3917 3918
@@ -3923,11 +3924,10 @@ static int mgsl_alloc_frame_memory(struct mgsl_struct *info,DMABUFFERENTRY *Buff
3923 info->last_mem_alloc += DMABUFFERSIZE; 3924 info->last_mem_alloc += DMABUFFERSIZE;
3924 } else { 3925 } else {
3925 /* ISA adapter uses system memory. */ 3926 /* ISA adapter uses system memory. */
3926 BufferList[i].virt_addr = 3927 BufferList[i].virt_addr = dma_alloc_coherent(NULL, DMABUFFERSIZE, &BufferList[i].dma_addr, GFP_KERNEL);
3927 kmalloc(DMABUFFERSIZE, GFP_KERNEL | GFP_DMA); 3928 if (BufferList[i].virt_addr == NULL)
3928 if ( BufferList[i].virt_addr == NULL )
3929 return -ENOMEM; 3929 return -ENOMEM;
3930 phys_addr = isa_virt_to_bus(BufferList[i].virt_addr); 3930 phys_addr = (u32)(BufferList[i].dma_addr);
3931 } 3931 }
3932 BufferList[i].phys_addr = phys_addr; 3932 BufferList[i].phys_addr = phys_addr;
3933 } 3933 }
@@ -3958,7 +3958,7 @@ static void mgsl_free_frame_memory(struct mgsl_struct *info, DMABUFFERENTRY *Buf
3958 for ( i = 0 ; i < Buffercount ; i++ ) { 3958 for ( i = 0 ; i < Buffercount ; i++ ) {
3959 if ( BufferList[i].virt_addr ) { 3959 if ( BufferList[i].virt_addr ) {
3960 if ( info->bus_type != MGSL_BUS_TYPE_PCI ) 3960 if ( info->bus_type != MGSL_BUS_TYPE_PCI )
3961 kfree(BufferList[i].virt_addr); 3961 dma_free_coherent(NULL, DMABUFFERSIZE, BufferList[i].virt_addr, BufferList[i].dma_addr);
3962 BufferList[i].virt_addr = NULL; 3962 BufferList[i].virt_addr = NULL;
3963 } 3963 }
3964 } 3964 }
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 7c063c5abc55..ee5a40be9f99 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -500,7 +500,6 @@ MODULE_DEVICE_TABLE(pci, synclinkmp_pci_tbl);
500MODULE_LICENSE("GPL"); 500MODULE_LICENSE("GPL");
501 501
502static struct pci_driver synclinkmp_pci_driver = { 502static struct pci_driver synclinkmp_pci_driver = {
503 .owner = THIS_MODULE,
504 .name = "synclinkmp", 503 .name = "synclinkmp",
505 .id_table = synclinkmp_pci_tbl, 504 .id_table = synclinkmp_pci_tbl,
506 .probe = synclinkmp_init_one, 505 .probe = synclinkmp_init_one,
diff --git a/drivers/char/tb0219.c b/drivers/char/tb0219.c
index 24355b23b2ca..b3d411a756fe 100644
--- a/drivers/char/tb0219.c
+++ b/drivers/char/tb0219.c
@@ -283,7 +283,7 @@ static void tb0219_pci_irq_init(void)
283 vr41xx_set_irq_level(TB0219_PCI_SLOT3_PIN, IRQ_LEVEL_LOW); 283 vr41xx_set_irq_level(TB0219_PCI_SLOT3_PIN, IRQ_LEVEL_LOW);
284} 284}
285 285
286static int tb0219_probe(struct device *dev) 286static int tb0219_probe(struct platform_device *dev)
287{ 287{
288 int retval; 288 int retval;
289 289
@@ -319,7 +319,7 @@ static int tb0219_probe(struct device *dev)
319 return 0; 319 return 0;
320} 320}
321 321
322static int tb0219_remove(struct device *dev) 322static int tb0219_remove(struct platform_device *dev)
323{ 323{
324 _machine_restart = old_machine_restart; 324 _machine_restart = old_machine_restart;
325 325
@@ -333,11 +333,12 @@ static int tb0219_remove(struct device *dev)
333 333
334static struct platform_device *tb0219_platform_device; 334static struct platform_device *tb0219_platform_device;
335 335
336static struct device_driver tb0219_device_driver = { 336static struct platform_driver tb0219_device_driver = {
337 .name = "TB0219",
338 .bus = &platform_bus_type,
339 .probe = tb0219_probe, 337 .probe = tb0219_probe,
340 .remove = tb0219_remove, 338 .remove = tb0219_remove,
339 .driver = {
340 .name = "TB0219",
341 },
341}; 342};
342 343
343static int __devinit tanbac_tb0219_init(void) 344static int __devinit tanbac_tb0219_init(void)
@@ -348,7 +349,7 @@ static int __devinit tanbac_tb0219_init(void)
348 if (IS_ERR(tb0219_platform_device)) 349 if (IS_ERR(tb0219_platform_device))
349 return PTR_ERR(tb0219_platform_device); 350 return PTR_ERR(tb0219_platform_device);
350 351
351 retval = driver_register(&tb0219_device_driver); 352 retval = platform_driver_register(&tb0219_device_driver);
352 if (retval < 0) 353 if (retval < 0)
353 platform_device_unregister(tb0219_platform_device); 354 platform_device_unregister(tb0219_platform_device);
354 355
@@ -357,7 +358,7 @@ static int __devinit tanbac_tb0219_init(void)
357 358
358static void __devexit tanbac_tb0219_exit(void) 359static void __devexit tanbac_tb0219_exit(void)
359{ 360{
360 driver_unregister(&tb0219_device_driver); 361 platform_driver_unregister(&tb0219_device_driver);
361 362
362 platform_device_unregister(tb0219_platform_device); 363 platform_device_unregister(tb0219_platform_device);
363} 364}
diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
index b58adfe3ed19..a6873bf89ffa 100644
--- a/drivers/char/tpm/Kconfig
+++ b/drivers/char/tpm/Kconfig
@@ -6,7 +6,7 @@ menu "TPM devices"
6 6
7config TCG_TPM 7config TCG_TPM
8 tristate "TPM Hardware Support" 8 tristate "TPM Hardware Support"
9 depends on EXPERIMENTAL && PCI 9 depends on EXPERIMENTAL
10 ---help--- 10 ---help---
11 If you have a TPM security chip in your system, which 11 If you have a TPM security chip in your system, which
12 implements the Trusted Computing Group's specification, 12 implements the Trusted Computing Group's specification,
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 303f15880466..a9be0e8eaea5 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -43,6 +43,13 @@ static void user_reader_timeout(unsigned long ptr)
43{ 43{
44 struct tpm_chip *chip = (struct tpm_chip *) ptr; 44 struct tpm_chip *chip = (struct tpm_chip *) ptr;
45 45
46 schedule_work(&chip->work);
47}
48
49static void timeout_work(void * ptr)
50{
51 struct tpm_chip *chip = ptr;
52
46 down(&chip->buffer_mutex); 53 down(&chip->buffer_mutex);
47 atomic_set(&chip->data_pending, 0); 54 atomic_set(&chip->data_pending, 0);
48 memset(chip->data_buffer, 0, TPM_BUFSIZE); 55 memset(chip->data_buffer, 0, TPM_BUFSIZE);
@@ -370,6 +377,7 @@ int tpm_release(struct inode *inode, struct file *file)
370 file->private_data = NULL; 377 file->private_data = NULL;
371 chip->num_opens--; 378 chip->num_opens--;
372 del_singleshot_timer_sync(&chip->user_read_timer); 379 del_singleshot_timer_sync(&chip->user_read_timer);
380 flush_scheduled_work();
373 atomic_set(&chip->data_pending, 0); 381 atomic_set(&chip->data_pending, 0);
374 put_device(chip->dev); 382 put_device(chip->dev);
375 kfree(chip->data_buffer); 383 kfree(chip->data_buffer);
@@ -421,6 +429,7 @@ ssize_t tpm_read(struct file * file, char __user *buf,
421 int ret_size; 429 int ret_size;
422 430
423 del_singleshot_timer_sync(&chip->user_read_timer); 431 del_singleshot_timer_sync(&chip->user_read_timer);
432 flush_scheduled_work();
424 ret_size = atomic_read(&chip->data_pending); 433 ret_size = atomic_read(&chip->data_pending);
425 atomic_set(&chip->data_pending, 0); 434 atomic_set(&chip->data_pending, 0);
426 if (ret_size > 0) { /* relay data */ 435 if (ret_size > 0) { /* relay data */
@@ -428,8 +437,7 @@ ssize_t tpm_read(struct file * file, char __user *buf,
428 ret_size = size; 437 ret_size = size;
429 438
430 down(&chip->buffer_mutex); 439 down(&chip->buffer_mutex);
431 if (copy_to_user 440 if (copy_to_user(buf, chip->data_buffer, ret_size))
432 ((void __user *) buf, chip->data_buffer, ret_size))
433 ret_size = -EFAULT; 441 ret_size = -EFAULT;
434 up(&chip->buffer_mutex); 442 up(&chip->buffer_mutex);
435 } 443 }
@@ -460,7 +468,7 @@ void tpm_remove_hardware(struct device *dev)
460 sysfs_remove_group(&dev->kobj, chip->vendor->attr_group); 468 sysfs_remove_group(&dev->kobj, chip->vendor->attr_group);
461 469
462 dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= 470 dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &=
463 !(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES)); 471 ~(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
464 472
465 kfree(chip); 473 kfree(chip);
466 474
@@ -528,6 +536,8 @@ int tpm_register_hardware(struct device *dev, struct tpm_vendor_specific *entry)
528 init_MUTEX(&chip->tpm_mutex); 536 init_MUTEX(&chip->tpm_mutex);
529 INIT_LIST_HEAD(&chip->list); 537 INIT_LIST_HEAD(&chip->list);
530 538
539 INIT_WORK(&chip->work, timeout_work, chip);
540
531 init_timer(&chip->user_read_timer); 541 init_timer(&chip->user_read_timer);
532 chip->user_read_timer.function = user_reader_timeout; 542 chip->user_read_timer.function = user_reader_timeout;
533 chip->user_read_timer.data = (unsigned long) chip; 543 chip->user_read_timer.data = (unsigned long) chip;
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 9293bcc4dc62..159882ca69dd 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -50,7 +50,11 @@ struct tpm_vendor_specific {
50 u8 req_complete_mask; 50 u8 req_complete_mask;
51 u8 req_complete_val; 51 u8 req_complete_val;
52 u8 req_canceled; 52 u8 req_canceled;
53 u16 base; /* TPM base address */ 53 void __iomem *iobase; /* ioremapped address */
54 unsigned long base; /* TPM base address */
55
56 int region_size;
57 int have_region;
54 58
55 int (*recv) (struct tpm_chip *, u8 *, size_t); 59 int (*recv) (struct tpm_chip *, u8 *, size_t);
56 int (*send) (struct tpm_chip *, u8 *, size_t); 60 int (*send) (struct tpm_chip *, u8 *, size_t);
@@ -73,6 +77,7 @@ struct tpm_chip {
73 struct semaphore buffer_mutex; 77 struct semaphore buffer_mutex;
74 78
75 struct timer_list user_read_timer; /* user needs to claim result */ 79 struct timer_list user_read_timer; /* user needs to claim result */
80 struct work_struct work;
76 struct semaphore tpm_mutex; /* tpm is processing */ 81 struct semaphore tpm_mutex; /* tpm is processing */
77 82
78 struct tpm_vendor_specific *vendor; 83 struct tpm_vendor_specific *vendor;
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index 32e01450c425..ff3654964fe3 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -19,14 +19,8 @@
19 * 19 *
20 */ 20 */
21 21
22#include <linux/platform_device.h>
23#include "tpm.h" 22#include "tpm.h"
24 23#include "tpm_atmel.h"
25/* Atmel definitions */
26enum tpm_atmel_addr {
27 TPM_ATMEL_BASE_ADDR_LO = 0x08,
28 TPM_ATMEL_BASE_ADDR_HI = 0x09
29};
30 24
31/* write status bits */ 25/* write status bits */
32enum tpm_atmel_write_status { 26enum tpm_atmel_write_status {
@@ -53,13 +47,12 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
53 return -EIO; 47 return -EIO;
54 48
55 for (i = 0; i < 6; i++) { 49 for (i = 0; i < 6; i++) {
56 status = inb(chip->vendor->base + 1); 50 status = ioread8(chip->vendor->iobase + 1);
57 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 51 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
58 dev_err(chip->dev, 52 dev_err(chip->dev, "error reading header\n");
59 "error reading header\n");
60 return -EIO; 53 return -EIO;
61 } 54 }
62 *buf++ = inb(chip->vendor->base); 55 *buf++ = ioread8(chip->vendor->iobase);
63 } 56 }
64 57
65 /* size of the data received */ 58 /* size of the data received */
@@ -70,10 +63,9 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
70 dev_err(chip->dev, 63 dev_err(chip->dev,
71 "Recv size(%d) less than available space\n", size); 64 "Recv size(%d) less than available space\n", size);
72 for (; i < size; i++) { /* clear the waiting data anyway */ 65 for (; i < size; i++) { /* clear the waiting data anyway */
73 status = inb(chip->vendor->base + 1); 66 status = ioread8(chip->vendor->iobase + 1);
74 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 67 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
75 dev_err(chip->dev, 68 dev_err(chip->dev, "error reading data\n");
76 "error reading data\n");
77 return -EIO; 69 return -EIO;
78 } 70 }
79 } 71 }
@@ -82,17 +74,17 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
82 74
83 /* read all the data available */ 75 /* read all the data available */
84 for (; i < size; i++) { 76 for (; i < size; i++) {
85 status = inb(chip->vendor->base + 1); 77 status = ioread8(chip->vendor->iobase + 1);
86 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 78 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
87 dev_err(chip->dev, 79 dev_err(chip->dev, "error reading data\n");
88 "error reading data\n");
89 return -EIO; 80 return -EIO;
90 } 81 }
91 *buf++ = inb(chip->vendor->base); 82 *buf++ = ioread8(chip->vendor->iobase);
92 } 83 }
93 84
94 /* make sure data available is gone */ 85 /* make sure data available is gone */
95 status = inb(chip->vendor->base + 1); 86 status = ioread8(chip->vendor->iobase + 1);
87
96 if (status & ATML_STATUS_DATA_AVAIL) { 88 if (status & ATML_STATUS_DATA_AVAIL) {
97 dev_err(chip->dev, "data available is stuck\n"); 89 dev_err(chip->dev, "data available is stuck\n");
98 return -EIO; 90 return -EIO;
@@ -108,7 +100,7 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
108 dev_dbg(chip->dev, "tpm_atml_send:\n"); 100 dev_dbg(chip->dev, "tpm_atml_send:\n");
109 for (i = 0; i < count; i++) { 101 for (i = 0; i < count; i++) {
110 dev_dbg(chip->dev, "%d 0x%x(%d)\n", i, buf[i], buf[i]); 102 dev_dbg(chip->dev, "%d 0x%x(%d)\n", i, buf[i], buf[i]);
111 outb(buf[i], chip->vendor->base); 103 iowrite8(buf[i], chip->vendor->iobase);
112 } 104 }
113 105
114 return count; 106 return count;
@@ -116,12 +108,12 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
116 108
117static void tpm_atml_cancel(struct tpm_chip *chip) 109static void tpm_atml_cancel(struct tpm_chip *chip)
118{ 110{
119 outb(ATML_STATUS_ABORT, chip->vendor->base + 1); 111 iowrite8(ATML_STATUS_ABORT, chip->vendor->iobase + 1);
120} 112}
121 113
122static u8 tpm_atml_status(struct tpm_chip *chip) 114static u8 tpm_atml_status(struct tpm_chip *chip)
123{ 115{
124 return inb(chip->vendor->base + 1); 116 return ioread8(chip->vendor->iobase + 1);
125} 117}
126 118
127static struct file_operations atmel_ops = { 119static struct file_operations atmel_ops = {
@@ -162,12 +154,17 @@ static struct tpm_vendor_specific tpm_atmel = {
162 154
163static struct platform_device *pdev; 155static struct platform_device *pdev;
164 156
165static void __devexit tpm_atml_remove(struct device *dev) 157static void atml_plat_remove(void)
166{ 158{
167 struct tpm_chip *chip = dev_get_drvdata(dev); 159 struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
160
168 if (chip) { 161 if (chip) {
169 release_region(chip->vendor->base, 2); 162 if (chip->vendor->have_region)
163 atmel_release_region(chip->vendor->base,
164 chip->vendor->region_size);
165 atmel_put_base_addr(chip->vendor);
170 tpm_remove_hardware(chip->dev); 166 tpm_remove_hardware(chip->dev);
167 platform_device_unregister(pdev);
171 } 168 }
172} 169}
173 170
@@ -182,72 +179,46 @@ static struct device_driver atml_drv = {
182static int __init init_atmel(void) 179static int __init init_atmel(void)
183{ 180{
184 int rc = 0; 181 int rc = 0;
185 int lo, hi;
186 182
187 driver_register(&atml_drv); 183 driver_register(&atml_drv);
188 184
189 lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO); 185 if ((tpm_atmel.iobase = atmel_get_base_addr(&tpm_atmel)) == NULL) {
190 hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI); 186 rc = -ENODEV;
191 187 goto err_unreg_drv;
192 tpm_atmel.base = (hi<<8)|lo;
193
194 /* verify that it is an Atmel part */
195 if (tpm_read_index(TPM_ADDR, 4) != 'A' || tpm_read_index(TPM_ADDR, 5) != 'T'
196 || tpm_read_index(TPM_ADDR, 6) != 'M' || tpm_read_index(TPM_ADDR, 7) != 'L') {
197 return -ENODEV;
198 } 188 }
199 189
200 /* verify chip version number is 1.1 */ 190 tpm_atmel.have_region =
201 if ( (tpm_read_index(TPM_ADDR, 0x00) != 0x01) || 191 (atmel_request_region
202 (tpm_read_index(TPM_ADDR, 0x01) != 0x01 )) 192 (tpm_atmel.base, tpm_atmel.region_size,
203 return -ENODEV; 193 "tpm_atmel0") == NULL) ? 0 : 1;
204
205 pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
206 if ( !pdev )
207 return -ENOMEM;
208
209 pdev->name = "tpm_atmel0";
210 pdev->id = -1;
211 pdev->num_resources = 0;
212 pdev->dev.release = tpm_atml_remove;
213 pdev->dev.driver = &atml_drv;
214
215 if ((rc = platform_device_register(pdev)) < 0) {
216 kfree(pdev);
217 pdev = NULL;
218 return rc;
219 }
220 194
221 if (request_region(tpm_atmel.base, 2, "tpm_atmel0") == NULL ) { 195 if (IS_ERR
222 platform_device_unregister(pdev); 196 (pdev =
223 kfree(pdev); 197 platform_device_register_simple("tpm_atmel", -1, NULL, 0))) {
224 pdev = NULL; 198 rc = PTR_ERR(pdev);
225 return -EBUSY; 199 goto err_rel_reg;
226 } 200 }
227 201
228 if ((rc = tpm_register_hardware(&pdev->dev, &tpm_atmel)) < 0) { 202 if ((rc = tpm_register_hardware(&pdev->dev, &tpm_atmel)) < 0)
229 release_region(tpm_atmel.base, 2); 203 goto err_unreg_dev;
230 platform_device_unregister(pdev);
231 kfree(pdev);
232 pdev = NULL;
233 return rc;
234 }
235
236 dev_info(&pdev->dev, "Atmel TPM 1.1, Base Address: 0x%x\n",
237 tpm_atmel.base);
238 return 0; 204 return 0;
205
206err_unreg_dev:
207 platform_device_unregister(pdev);
208err_rel_reg:
209 atmel_put_base_addr(&tpm_atmel);
210 if (tpm_atmel.have_region)
211 atmel_release_region(tpm_atmel.base,
212 tpm_atmel.region_size);
213err_unreg_drv:
214 driver_unregister(&atml_drv);
215 return rc;
239} 216}
240 217
241static void __exit cleanup_atmel(void) 218static void __exit cleanup_atmel(void)
242{ 219{
243 if (pdev) {
244 tpm_atml_remove(&pdev->dev);
245 platform_device_unregister(pdev);
246 kfree(pdev);
247 pdev = NULL;
248 }
249
250 driver_unregister(&atml_drv); 220 driver_unregister(&atml_drv);
221 atml_plat_remove();
251} 222}
252 223
253module_init(init_atmel); 224module_init(init_atmel);
diff --git a/drivers/char/tpm/tpm_atmel.h b/drivers/char/tpm/tpm_atmel.h
new file mode 100644
index 000000000000..d3478aaadd77
--- /dev/null
+++ b/drivers/char/tpm/tpm_atmel.h
@@ -0,0 +1,131 @@
1/*
2 * Copyright (C) 2005 IBM Corporation
3 *
4 * Authors:
5 * Kylene Hall <kjhall@us.ibm.com>
6 *
7 * Maintained by: <tpmdd_devel@lists.sourceforge.net>
8 *
9 * Device driver for TCG/TCPA TPM (trusted platform module).
10 * Specifications at www.trustedcomputinggroup.org
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation, version 2 of the
15 * License.
16 *
17 * These difference are required on power because the device must be
18 * discovered through the device tree and iomap must be used to get
19 * around the need for holes in the io_page_mask. This does not happen
20 * automatically because the tpm is not a normal pci device and lives
21 * under the root node.
22 *
23 */
24
25#ifdef CONFIG_PPC64
26#define atmel_getb(chip, offset) readb(chip->vendor->iobase + offset);
27#define atmel_putb(val, chip, offset) writeb(val, chip->vendor->iobase + offset)
28#define atmel_request_region request_mem_region
29#define atmel_release_region release_mem_region
30
31static inline void atmel_put_base_addr(struct tpm_vendor_specific
32 *vendor)
33{
34 iounmap(vendor->iobase);
35}
36
37static void __iomem * atmel_get_base_addr(struct tpm_vendor_specific *vendor)
38{
39 struct device_node *dn;
40 unsigned long address, size;
41 unsigned int *reg;
42 int reglen;
43 int naddrc;
44 int nsizec;
45
46 dn = of_find_node_by_name(NULL, "tpm");
47
48 if (!dn)
49 return NULL;
50
51 if (!device_is_compatible(dn, "AT97SC3201")) {
52 of_node_put(dn);
53 return NULL;
54 }
55
56 reg = (unsigned int *) get_property(dn, "reg", &reglen);
57 naddrc = prom_n_addr_cells(dn);
58 nsizec = prom_n_size_cells(dn);
59
60 of_node_put(dn);
61
62
63 if (naddrc == 2)
64 address = ((unsigned long) reg[0] << 32) | reg[1];
65 else
66 address = reg[0];
67
68 if (nsizec == 2)
69 size =
70 ((unsigned long) reg[naddrc] << 32) | reg[naddrc + 1];
71 else
72 size = reg[naddrc];
73
74 vendor->base = address;
75 vendor->region_size = size;
76 return ioremap(vendor->base, vendor->region_size);
77}
78#else
79#define atmel_getb(chip, offset) inb(chip->vendor->base + offset)
80#define atmel_putb(val, chip, offset) outb(val, chip->vendor->base + offset)
81#define atmel_request_region request_region
82#define atmel_release_region release_region
83/* Atmel definitions */
84enum tpm_atmel_addr {
85 TPM_ATMEL_BASE_ADDR_LO = 0x08,
86 TPM_ATMEL_BASE_ADDR_HI = 0x09
87};
88
89/* Verify this is a 1.1 Atmel TPM */
90static int atmel_verify_tpm11(void)
91{
92
93 /* verify that it is an Atmel part */
94 if (tpm_read_index(TPM_ADDR, 4) != 'A' ||
95 tpm_read_index(TPM_ADDR, 5) != 'T' ||
96 tpm_read_index(TPM_ADDR, 6) != 'M' ||
97 tpm_read_index(TPM_ADDR, 7) != 'L')
98 return 1;
99
100 /* query chip for its version number */
101 if (tpm_read_index(TPM_ADDR, 0x00) != 1 ||
102 tpm_read_index(TPM_ADDR, 0x01) != 1)
103 return 1;
104
105 /* This is an atmel supported part */
106 return 0;
107}
108
109static inline void atmel_put_base_addr(struct tpm_vendor_specific
110 *vendor)
111{
112}
113
114/* Determine where to talk to device */
115static void __iomem * atmel_get_base_addr(struct tpm_vendor_specific
116 *vendor)
117{
118 int lo, hi;
119
120 if (atmel_verify_tpm11() != 0)
121 return NULL;
122
123 lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO);
124 hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI);
125
126 vendor->base = (hi << 8) | lo;
127 vendor->region_size = 2;
128
129 return ioport_map(vendor->base, vendor->region_size);
130}
131#endif
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index f66c7ad6fd38..3c1dafaa3441 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -419,7 +419,7 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
419 while (this_round > 1) { 419 while (this_round > 1) {
420 unsigned short w; 420 unsigned short w;
421 421
422 w = get_unaligned(((const unsigned short *)con_buf0)); 422 w = get_unaligned(((unsigned short *)con_buf0));
423 vcs_scr_writew(vc, w, org++); 423 vcs_scr_writew(vc, w, org++);
424 con_buf0 += 2; 424 con_buf0 += 2;
425 this_round -= 2; 425 this_round -= 2;
diff --git a/drivers/char/vr41xx_giu.c b/drivers/char/vr41xx_giu.c
index 94641085faf8..9ac6d43437b3 100644
--- a/drivers/char/vr41xx_giu.c
+++ b/drivers/char/vr41xx_giu.c
@@ -613,7 +613,7 @@ static struct file_operations gpio_fops = {
613 .release = gpio_release, 613 .release = gpio_release,
614}; 614};
615 615
616static int giu_probe(struct device *dev) 616static int giu_probe(struct platform_device *dev)
617{ 617{
618 unsigned long start, size, flags = 0; 618 unsigned long start, size, flags = 0;
619 unsigned int nr_pins = 0; 619 unsigned int nr_pins = 0;
@@ -697,7 +697,7 @@ static int giu_probe(struct device *dev)
697 return cascade_irq(GIUINT_IRQ, giu_get_irq); 697 return cascade_irq(GIUINT_IRQ, giu_get_irq);
698} 698}
699 699
700static int giu_remove(struct device *dev) 700static int giu_remove(struct platform_device *dev)
701{ 701{
702 iounmap(giu_base); 702 iounmap(giu_base);
703 703
@@ -710,11 +710,12 @@ static int giu_remove(struct device *dev)
710 710
711static struct platform_device *giu_platform_device; 711static struct platform_device *giu_platform_device;
712 712
713static struct device_driver giu_device_driver = { 713static struct platform_driver giu_device_driver = {
714 .name = "GIU",
715 .bus = &platform_bus_type,
716 .probe = giu_probe, 714 .probe = giu_probe,
717 .remove = giu_remove, 715 .remove = giu_remove,
716 .driver = {
717 .name = "GIU",
718 },
718}; 719};
719 720
720static int __devinit vr41xx_giu_init(void) 721static int __devinit vr41xx_giu_init(void)
@@ -725,7 +726,7 @@ static int __devinit vr41xx_giu_init(void)
725 if (IS_ERR(giu_platform_device)) 726 if (IS_ERR(giu_platform_device))
726 return PTR_ERR(giu_platform_device); 727 return PTR_ERR(giu_platform_device);
727 728
728 retval = driver_register(&giu_device_driver); 729 retval = platform_driver_register(&giu_device_driver);
729 if (retval < 0) 730 if (retval < 0)
730 platform_device_unregister(giu_platform_device); 731 platform_device_unregister(giu_platform_device);
731 732
@@ -734,7 +735,7 @@ static int __devinit vr41xx_giu_init(void)
734 735
735static void __devexit vr41xx_giu_exit(void) 736static void __devexit vr41xx_giu_exit(void)
736{ 737{
737 driver_unregister(&giu_device_driver); 738 platform_driver_unregister(&giu_device_driver);
738 739
739 platform_device_unregister(giu_platform_device); 740 platform_device_unregister(giu_platform_device);
740} 741}
diff --git a/drivers/char/vr41xx_rtc.c b/drivers/char/vr41xx_rtc.c
index 5e3292df69d8..435b30748e23 100644
--- a/drivers/char/vr41xx_rtc.c
+++ b/drivers/char/vr41xx_rtc.c
@@ -560,13 +560,11 @@ static struct miscdevice rtc_miscdevice = {
560 .fops = &rtc_fops, 560 .fops = &rtc_fops,
561}; 561};
562 562
563static int rtc_probe(struct device *dev) 563static int rtc_probe(struct platform_device *pdev)
564{ 564{
565 struct platform_device *pdev;
566 unsigned int irq; 565 unsigned int irq;
567 int retval; 566 int retval;
568 567
569 pdev = to_platform_device(dev);
570 if (pdev->num_resources != 2) 568 if (pdev->num_resources != 2)
571 return -EBUSY; 569 return -EBUSY;
572 570
@@ -635,7 +633,7 @@ static int rtc_probe(struct device *dev)
635 return 0; 633 return 0;
636} 634}
637 635
638static int rtc_remove(struct device *dev) 636static int rtc_remove(struct platform_device *dev)
639{ 637{
640 int retval; 638 int retval;
641 639
@@ -655,11 +653,12 @@ static int rtc_remove(struct device *dev)
655 653
656static struct platform_device *rtc_platform_device; 654static struct platform_device *rtc_platform_device;
657 655
658static struct device_driver rtc_device_driver = { 656static struct platform_driver rtc_device_driver = {
659 .name = rtc_name,
660 .bus = &platform_bus_type,
661 .probe = rtc_probe, 657 .probe = rtc_probe,
662 .remove = rtc_remove, 658 .remove = rtc_remove,
659 .driver = {
660 .name = rtc_name,
661 },
663}; 662};
664 663
665static int __devinit vr41xx_rtc_init(void) 664static int __devinit vr41xx_rtc_init(void)
@@ -691,7 +690,7 @@ static int __devinit vr41xx_rtc_init(void)
691 if (IS_ERR(rtc_platform_device)) 690 if (IS_ERR(rtc_platform_device))
692 return PTR_ERR(rtc_platform_device); 691 return PTR_ERR(rtc_platform_device);
693 692
694 retval = driver_register(&rtc_device_driver); 693 retval = platform_driver_register(&rtc_device_driver);
695 if (retval < 0) 694 if (retval < 0)
696 platform_device_unregister(rtc_platform_device); 695 platform_device_unregister(rtc_platform_device);
697 696
@@ -700,7 +699,7 @@ static int __devinit vr41xx_rtc_init(void)
700 699
701static void __devexit vr41xx_rtc_exit(void) 700static void __devexit vr41xx_rtc_exit(void)
702{ 701{
703 driver_unregister(&rtc_device_driver); 702 platform_driver_unregister(&rtc_device_driver);
704 703
705 platform_device_unregister(rtc_platform_device); 704 platform_device_unregister(rtc_platform_device);
706} 705}
diff --git a/drivers/char/watchdog/booke_wdt.c b/drivers/char/watchdog/booke_wdt.c
index abc30cca6645..b6640606b44d 100644
--- a/drivers/char/watchdog/booke_wdt.c
+++ b/drivers/char/watchdog/booke_wdt.c
@@ -4,7 +4,7 @@
4 * Watchdog timer for PowerPC Book-E systems 4 * Watchdog timer for PowerPC Book-E systems
5 * 5 *
6 * Author: Matthew McClintock 6 * Author: Matthew McClintock
7 * Maintainer: Kumar Gala <kumar.gala@freescale.com> 7 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
8 * 8 *
9 * Copyright 2005 Freescale Semiconductor Inc. 9 * Copyright 2005 Freescale Semiconductor Inc.
10 * 10 *
@@ -72,7 +72,7 @@ static __inline__ void booke_wdt_ping(void)
72/* 72/*
73 * booke_wdt_write: 73 * booke_wdt_write:
74 */ 74 */
75static ssize_t booke_wdt_write (struct file *file, const char *buf, 75static ssize_t booke_wdt_write (struct file *file, const char __user *buf,
76 size_t count, loff_t *ppos) 76 size_t count, loff_t *ppos)
77{ 77{
78 booke_wdt_ping(); 78 booke_wdt_ping();
@@ -92,14 +92,15 @@ static int booke_wdt_ioctl (struct inode *inode, struct file *file,
92 unsigned int cmd, unsigned long arg) 92 unsigned int cmd, unsigned long arg)
93{ 93{
94 u32 tmp = 0; 94 u32 tmp = 0;
95 u32 __user *p = (u32 __user *)arg;
95 96
96 switch (cmd) { 97 switch (cmd) {
97 case WDIOC_GETSUPPORT: 98 case WDIOC_GETSUPPORT:
98 if (copy_to_user ((struct watchdog_info *) arg, &ident, 99 if (copy_to_user ((struct watchdog_info __user *) arg, &ident,
99 sizeof(struct watchdog_info))) 100 sizeof(struct watchdog_info)))
100 return -EFAULT; 101 return -EFAULT;
101 case WDIOC_GETSTATUS: 102 case WDIOC_GETSTATUS:
102 return put_user(ident.options, (u32 *) arg); 103 return put_user(ident.options, p);
103 case WDIOC_GETBOOTSTATUS: 104 case WDIOC_GETBOOTSTATUS:
104 /* XXX: something is clearing TSR */ 105 /* XXX: something is clearing TSR */
105 tmp = mfspr(SPRN_TSR) & TSR_WRS(3); 106 tmp = mfspr(SPRN_TSR) & TSR_WRS(3);
@@ -109,14 +110,14 @@ static int booke_wdt_ioctl (struct inode *inode, struct file *file,
109 booke_wdt_ping(); 110 booke_wdt_ping();
110 return 0; 111 return 0;
111 case WDIOC_SETTIMEOUT: 112 case WDIOC_SETTIMEOUT:
112 if (get_user(booke_wdt_period, (u32 *) arg)) 113 if (get_user(booke_wdt_period, p))
113 return -EFAULT; 114 return -EFAULT;
114 mtspr(SPRN_TCR, (mfspr(SPRN_TCR)&~WDTP(0))|WDTP(booke_wdt_period)); 115 mtspr(SPRN_TCR, (mfspr(SPRN_TCR)&~WDTP(0))|WDTP(booke_wdt_period));
115 return 0; 116 return 0;
116 case WDIOC_GETTIMEOUT: 117 case WDIOC_GETTIMEOUT:
117 return put_user(booke_wdt_period, (u32 *) arg); 118 return put_user(booke_wdt_period, p);
118 case WDIOC_SETOPTIONS: 119 case WDIOC_SETOPTIONS:
119 if (get_user(tmp, (u32 *) arg)) 120 if (get_user(tmp, p))
120 return -EINVAL; 121 return -EINVAL;
121 if (tmp == WDIOS_ENABLECARD) { 122 if (tmp == WDIOS_ENABLECARD) {
122 booke_wdt_ping(); 123 booke_wdt_ping();
@@ -172,7 +173,7 @@ static int __init booke_wdt_init(void)
172 int ret = 0; 173 int ret = 0;
173 174
174 printk (KERN_INFO "PowerPC Book-E Watchdog Timer Loaded\n"); 175 printk (KERN_INFO "PowerPC Book-E Watchdog Timer Loaded\n");
175 ident.firmware_version = cpu_specs[0].pvr_value; 176 ident.firmware_version = cur_cpu_spec->pvr_value;
176 177
177 ret = misc_register(&booke_wdt_miscdev); 178 ret = misc_register(&booke_wdt_miscdev);
178 if (ret) { 179 if (ret) {
diff --git a/drivers/char/watchdog/mpcore_wdt.c b/drivers/char/watchdog/mpcore_wdt.c
index da631c114fd1..b4d843489881 100644
--- a/drivers/char/watchdog/mpcore_wdt.c
+++ b/drivers/char/watchdog/mpcore_wdt.c
@@ -139,7 +139,7 @@ static int mpcore_wdt_set_heartbeat(int t)
139 */ 139 */
140static int mpcore_wdt_open(struct inode *inode, struct file *file) 140static int mpcore_wdt_open(struct inode *inode, struct file *file)
141{ 141{
142 struct mpcore_wdt *wdt = dev_get_drvdata(&mpcore_wdt_dev->dev); 142 struct mpcore_wdt *wdt = platform_get_drvdata(mpcore_wdt_dev);
143 143
144 if (test_and_set_bit(0, &wdt->timer_alive)) 144 if (test_and_set_bit(0, &wdt->timer_alive))
145 return -EBUSY; 145 return -EBUSY;
@@ -180,10 +180,6 @@ static ssize_t mpcore_wdt_write(struct file *file, const char *data, size_t len,
180{ 180{
181 struct mpcore_wdt *wdt = file->private_data; 181 struct mpcore_wdt *wdt = file->private_data;
182 182
183 /* Can't seek (pwrite) on this device */
184 if (ppos != &file->f_pos)
185 return -ESPIPE;
186
187 /* 183 /*
188 * Refresh the timer. 184 * Refresh the timer.
189 */ 185 */
@@ -291,9 +287,9 @@ static int mpcore_wdt_ioctl(struct inode *inode, struct file *file,
291 * System shutdown handler. Turn off the watchdog if we're 287 * System shutdown handler. Turn off the watchdog if we're
292 * restarting or halting the system. 288 * restarting or halting the system.
293 */ 289 */
294static void mpcore_wdt_shutdown(struct device *_dev) 290static void mpcore_wdt_shutdown(struct platform_device *dev)
295{ 291{
296 struct mpcore_wdt *wdt = dev_get_drvdata(_dev); 292 struct mpcore_wdt *wdt = platform_get_drvdata(dev);
297 293
298 if (system_state == SYSTEM_RESTART || system_state == SYSTEM_HALT) 294 if (system_state == SYSTEM_RESTART || system_state == SYSTEM_HALT)
299 mpcore_wdt_stop(wdt); 295 mpcore_wdt_stop(wdt);
@@ -317,9 +313,8 @@ static struct miscdevice mpcore_wdt_miscdev = {
317 .fops = &mpcore_wdt_fops, 313 .fops = &mpcore_wdt_fops,
318}; 314};
319 315
320static int __devinit mpcore_wdt_probe(struct device *_dev) 316static int __devinit mpcore_wdt_probe(struct platform_device *dev)
321{ 317{
322 struct platform_device *dev = to_platform_device(_dev);
323 struct mpcore_wdt *wdt; 318 struct mpcore_wdt *wdt;
324 struct resource *res; 319 struct resource *res;
325 int ret; 320 int ret;
@@ -364,7 +359,7 @@ static int __devinit mpcore_wdt_probe(struct device *_dev)
364 } 359 }
365 360
366 mpcore_wdt_stop(wdt); 361 mpcore_wdt_stop(wdt);
367 dev_set_drvdata(&dev->dev, wdt); 362 platform_set_drvdata(&dev->dev, wdt);
368 mpcore_wdt_dev = dev; 363 mpcore_wdt_dev = dev;
369 364
370 return 0; 365 return 0;
@@ -379,11 +374,11 @@ static int __devinit mpcore_wdt_probe(struct device *_dev)
379 return ret; 374 return ret;
380} 375}
381 376
382static int __devexit mpcore_wdt_remove(struct device *dev) 377static int __devexit mpcore_wdt_remove(struct platform_device *dev)
383{ 378{
384 struct mpcore_wdt *wdt = dev_get_drvdata(dev); 379 struct mpcore_wdt *wdt = platform_get_drvdata(dev);
385 380
386 dev_set_drvdata(dev, NULL); 381 platform_set_drvdata(dev, NULL);
387 382
388 misc_deregister(&mpcore_wdt_miscdev); 383 misc_deregister(&mpcore_wdt_miscdev);
389 384
@@ -395,13 +390,14 @@ static int __devexit mpcore_wdt_remove(struct device *dev)
395 return 0; 390 return 0;
396} 391}
397 392
398static struct device_driver mpcore_wdt_driver = { 393static struct platform_driver mpcore_wdt_driver = {
399 .owner = THIS_MODULE,
400 .name = "mpcore_wdt",
401 .bus = &platform_bus_type,
402 .probe = mpcore_wdt_probe, 394 .probe = mpcore_wdt_probe,
403 .remove = __devexit_p(mpcore_wdt_remove), 395 .remove = __devexit_p(mpcore_wdt_remove),
404 .shutdown = mpcore_wdt_shutdown, 396 .shutdown = mpcore_wdt_shutdown,
397 .driver = {
398 .owner = THIS_MODULE,
399 .name = "mpcore_wdt",
400 },
405}; 401};
406 402
407static char banner[] __initdata = KERN_INFO "MPcore Watchdog Timer: 0.1. mpcore_noboot=%d mpcore_margin=%d sec (nowayout= %d)\n"; 403static char banner[] __initdata = KERN_INFO "MPcore Watchdog Timer: 0.1. mpcore_noboot=%d mpcore_margin=%d sec (nowayout= %d)\n";
@@ -420,12 +416,12 @@ static int __init mpcore_wdt_init(void)
420 416
421 printk(banner, mpcore_noboot, mpcore_margin, nowayout); 417 printk(banner, mpcore_noboot, mpcore_margin, nowayout);
422 418
423 return driver_register(&mpcore_wdt_driver); 419 return platform_driver_register(&mpcore_wdt_driver);
424} 420}
425 421
426static void __exit mpcore_wdt_exit(void) 422static void __exit mpcore_wdt_exit(void)
427{ 423{
428 driver_unregister(&mpcore_wdt_driver); 424 platform_driver_unregister(&mpcore_wdt_driver);
429} 425}
430 426
431module_init(mpcore_wdt_init); 427module_init(mpcore_wdt_init);
diff --git a/drivers/char/watchdog/mv64x60_wdt.c b/drivers/char/watchdog/mv64x60_wdt.c
index 119b3c541d95..00d9ef04a369 100644
--- a/drivers/char/watchdog/mv64x60_wdt.c
+++ b/drivers/char/watchdog/mv64x60_wdt.c
@@ -182,10 +182,9 @@ static struct miscdevice mv64x60_wdt_miscdev = {
182 .fops = &mv64x60_wdt_fops, 182 .fops = &mv64x60_wdt_fops,
183}; 183};
184 184
185static int __devinit mv64x60_wdt_probe(struct device *dev) 185static int __devinit mv64x60_wdt_probe(struct platform_device *dev)
186{ 186{
187 struct platform_device *pd = to_platform_device(dev); 187 struct mv64x60_wdt_pdata *pdata = dev->dev.platform_data;
188 struct mv64x60_wdt_pdata *pdata = pd->dev.platform_data;
189 int bus_clk = 133; 188 int bus_clk = 133;
190 189
191 mv64x60_wdt_timeout = 10; 190 mv64x60_wdt_timeout = 10;
@@ -202,7 +201,7 @@ static int __devinit mv64x60_wdt_probe(struct device *dev)
202 return misc_register(&mv64x60_wdt_miscdev); 201 return misc_register(&mv64x60_wdt_miscdev);
203} 202}
204 203
205static int __devexit mv64x60_wdt_remove(struct device *dev) 204static int __devexit mv64x60_wdt_remove(struct platform_device *dev)
206{ 205{
207 misc_deregister(&mv64x60_wdt_miscdev); 206 misc_deregister(&mv64x60_wdt_miscdev);
208 207
@@ -212,12 +211,13 @@ static int __devexit mv64x60_wdt_remove(struct device *dev)
212 return 0; 211 return 0;
213} 212}
214 213
215static struct device_driver mv64x60_wdt_driver = { 214static struct platform_driver mv64x60_wdt_driver = {
216 .owner = THIS_MODULE,
217 .name = MV64x60_WDT_NAME,
218 .bus = &platform_bus_type,
219 .probe = mv64x60_wdt_probe, 215 .probe = mv64x60_wdt_probe,
220 .remove = __devexit_p(mv64x60_wdt_remove), 216 .remove = __devexit_p(mv64x60_wdt_remove),
217 .driver = {
218 .owner = THIS_MODULE,
219 .name = MV64x60_WDT_NAME,
220 },
221}; 221};
222 222
223static struct platform_device *mv64x60_wdt_dev; 223static struct platform_device *mv64x60_wdt_dev;
@@ -235,14 +235,14 @@ static int __init mv64x60_wdt_init(void)
235 goto out; 235 goto out;
236 } 236 }
237 237
238 ret = driver_register(&mv64x60_wdt_driver); 238 ret = platform_driver_register(&mv64x60_wdt_driver);
239 out: 239 out:
240 return ret; 240 return ret;
241} 241}
242 242
243static void __exit mv64x60_wdt_exit(void) 243static void __exit mv64x60_wdt_exit(void)
244{ 244{
245 driver_unregister(&mv64x60_wdt_driver); 245 platform_driver_unregister(&mv64x60_wdt_driver);
246 platform_device_unregister(mv64x60_wdt_dev); 246 platform_device_unregister(mv64x60_wdt_dev);
247} 247}
248 248
diff --git a/drivers/char/watchdog/pcwd_pci.c b/drivers/char/watchdog/pcwd_pci.c
index d9ef55bdf88a..2451edbefece 100644
--- a/drivers/char/watchdog/pcwd_pci.c
+++ b/drivers/char/watchdog/pcwd_pci.c
@@ -755,7 +755,6 @@ static struct pci_device_id pcipcwd_pci_tbl[] = {
755MODULE_DEVICE_TABLE(pci, pcipcwd_pci_tbl); 755MODULE_DEVICE_TABLE(pci, pcipcwd_pci_tbl);
756 756
757static struct pci_driver pcipcwd_driver = { 757static struct pci_driver pcipcwd_driver = {
758 .owner = THIS_MODULE,
759 .name = WATCHDOG_NAME, 758 .name = WATCHDOG_NAME,
760 .id_table = pcipcwd_pci_tbl, 759 .id_table = pcipcwd_pci_tbl,
761 .probe = pcipcwd_card_init, 760 .probe = pcipcwd_card_init,
diff --git a/drivers/char/watchdog/s3c2410_wdt.c b/drivers/char/watchdog/s3c2410_wdt.c
index 751cb77b0715..eb667daee19b 100644
--- a/drivers/char/watchdog/s3c2410_wdt.c
+++ b/drivers/char/watchdog/s3c2410_wdt.c
@@ -347,15 +347,14 @@ static irqreturn_t s3c2410wdt_irq(int irqno, void *param,
347} 347}
348/* device interface */ 348/* device interface */
349 349
350static int s3c2410wdt_probe(struct device *dev) 350static int s3c2410wdt_probe(struct platform_device *pdev)
351{ 351{
352 struct platform_device *pdev = to_platform_device(dev);
353 struct resource *res; 352 struct resource *res;
354 int started = 0; 353 int started = 0;
355 int ret; 354 int ret;
356 int size; 355 int size;
357 356
358 DBG("%s: probe=%p, device=%p\n", __FUNCTION__, pdev, dev); 357 DBG("%s: probe=%p\n", __FUNCTION__, pdev);
359 358
360 /* get the memory region for the watchdog timer */ 359 /* get the memory region for the watchdog timer */
361 360
@@ -386,13 +385,13 @@ static int s3c2410wdt_probe(struct device *dev)
386 return -ENOENT; 385 return -ENOENT;
387 } 386 }
388 387
389 ret = request_irq(res->start, s3c2410wdt_irq, 0, pdev->name, dev); 388 ret = request_irq(res->start, s3c2410wdt_irq, 0, pdev->name, pdev);
390 if (ret != 0) { 389 if (ret != 0) {
391 printk(KERN_INFO PFX "failed to install irq (%d)\n", ret); 390 printk(KERN_INFO PFX "failed to install irq (%d)\n", ret);
392 return ret; 391 return ret;
393 } 392 }
394 393
395 wdt_clock = clk_get(dev, "watchdog"); 394 wdt_clock = clk_get(&pdev->dev, "watchdog");
396 if (wdt_clock == NULL) { 395 if (wdt_clock == NULL) {
397 printk(KERN_INFO PFX "failed to find watchdog clock source\n"); 396 printk(KERN_INFO PFX "failed to find watchdog clock source\n");
398 return -ENOENT; 397 return -ENOENT;
@@ -430,7 +429,7 @@ static int s3c2410wdt_probe(struct device *dev)
430 return 0; 429 return 0;
431} 430}
432 431
433static int s3c2410wdt_remove(struct device *dev) 432static int s3c2410wdt_remove(struct platform_device *dev)
434{ 433{
435 if (wdt_mem != NULL) { 434 if (wdt_mem != NULL) {
436 release_resource(wdt_mem); 435 release_resource(wdt_mem);
@@ -454,7 +453,7 @@ static int s3c2410wdt_remove(struct device *dev)
454 return 0; 453 return 0;
455} 454}
456 455
457static void s3c2410wdt_shutdown(struct device *dev) 456static void s3c2410wdt_shutdown(struct platform_device *dev)
458{ 457{
459 s3c2410wdt_stop(); 458 s3c2410wdt_stop();
460} 459}
@@ -464,7 +463,7 @@ static void s3c2410wdt_shutdown(struct device *dev)
464static unsigned long wtcon_save; 463static unsigned long wtcon_save;
465static unsigned long wtdat_save; 464static unsigned long wtdat_save;
466 465
467static int s3c2410wdt_suspend(struct device *dev, pm_message_t state) 466static int s3c2410wdt_suspend(struct platform_device *dev, pm_message_t state)
468{ 467{
469 /* Save watchdog state, and turn it off. */ 468 /* Save watchdog state, and turn it off. */
470 wtcon_save = readl(wdt_base + S3C2410_WTCON); 469 wtcon_save = readl(wdt_base + S3C2410_WTCON);
@@ -476,7 +475,7 @@ static int s3c2410wdt_suspend(struct device *dev, pm_message_t state)
476 return 0; 475 return 0;
477} 476}
478 477
479static int s3c2410wdt_resume(struct device *dev) 478static int s3c2410wdt_resume(struct platform_device *dev)
480{ 479{
481 /* Restore watchdog state. */ 480 /* Restore watchdog state. */
482 481
@@ -496,15 +495,16 @@ static int s3c2410wdt_resume(struct device *dev)
496#endif /* CONFIG_PM */ 495#endif /* CONFIG_PM */
497 496
498 497
499static struct device_driver s3c2410wdt_driver = { 498static struct platform_driver s3c2410wdt_driver = {
500 .owner = THIS_MODULE,
501 .name = "s3c2410-wdt",
502 .bus = &platform_bus_type,
503 .probe = s3c2410wdt_probe, 499 .probe = s3c2410wdt_probe,
504 .remove = s3c2410wdt_remove, 500 .remove = s3c2410wdt_remove,
505 .shutdown = s3c2410wdt_shutdown, 501 .shutdown = s3c2410wdt_shutdown,
506 .suspend = s3c2410wdt_suspend, 502 .suspend = s3c2410wdt_suspend,
507 .resume = s3c2410wdt_resume, 503 .resume = s3c2410wdt_resume,
504 .driver = {
505 .owner = THIS_MODULE,
506 .name = "s3c2410-wdt",
507 },
508}; 508};
509 509
510 510
@@ -513,12 +513,12 @@ static char banner[] __initdata = KERN_INFO "S3C2410 Watchdog Timer, (c) 2004 Si
513static int __init watchdog_init(void) 513static int __init watchdog_init(void)
514{ 514{
515 printk(banner); 515 printk(banner);
516 return driver_register(&s3c2410wdt_driver); 516 return platform_driver_register(&s3c2410wdt_driver);
517} 517}
518 518
519static void __exit watchdog_exit(void) 519static void __exit watchdog_exit(void)
520{ 520{
521 driver_unregister(&s3c2410wdt_driver); 521 platform_driver_unregister(&s3c2410wdt_driver);
522} 522}
523 523
524module_init(watchdog_init); 524module_init(watchdog_init);
diff --git a/drivers/char/watchdog/wdrtas.c b/drivers/char/watchdog/wdrtas.c
index 619e2ffca33f..dacfe31caccf 100644
--- a/drivers/char/watchdog/wdrtas.c
+++ b/drivers/char/watchdog/wdrtas.c
@@ -320,7 +320,7 @@ static int
320wdrtas_ioctl(struct inode *inode, struct file *file, 320wdrtas_ioctl(struct inode *inode, struct file *file,
321 unsigned int cmd, unsigned long arg) 321 unsigned int cmd, unsigned long arg)
322{ 322{
323 int __user *argp = (void *)arg; 323 int __user *argp = (void __user *)arg;
324 int i; 324 int i;
325 static struct watchdog_info wdinfo = { 325 static struct watchdog_info wdinfo = {
326 .options = WDRTAS_SUPPORTED_MASK, 326 .options = WDRTAS_SUPPORTED_MASK,
diff --git a/drivers/char/watchdog/wdt_pci.c b/drivers/char/watchdog/wdt_pci.c
index dc9370f6c348..4b3311993d48 100644
--- a/drivers/char/watchdog/wdt_pci.c
+++ b/drivers/char/watchdog/wdt_pci.c
@@ -711,7 +711,6 @@ MODULE_DEVICE_TABLE(pci, wdtpci_pci_tbl);
711 711
712 712
713static struct pci_driver wdtpci_driver = { 713static struct pci_driver wdtpci_driver = {
714 .owner = THIS_MODULE,
715 .name = "wdt_pci", 714 .name = "wdt_pci",
716 .id_table = wdtpci_pci_tbl, 715 .id_table = wdtpci_pci_tbl,
717 .probe = wdtpci_init_one, 716 .probe = wdtpci_init_one,