1 /*
2  *  linux/drivers/ide/pci/delkin_cb.c
3  *
4  *  Created 25 Oct 2004 by Mark Lord
5  *
6  *  Basic support for Delkin/ASKA/Workbit Cardbus CompactFlash adapter
7  *
8  *  Modeled after the 16-bit PCMCIA driver: ide-cs.c
9  *
10  *  This is slightly peculiar, in that it is a PCI driver,
11  *  but is NOT an IDE PCI driver -- the IDE layer does not directly
12  *  support hot insertion/removal of PCI interfaces, so this driver
13  *  is unable to use the IDE PCI interfaces.  Instead, it uses the
14  *  same interfaces as the ide-cs (PCMCIA) driver uses.
15  *  On the plus side, the driver is also smaller/simpler this way.
16  *
17  *  This file is subject to the terms and conditions of the GNU General Public
18  *  License.  See the file COPYING in the main directory of this archive for
19  *  more details.
20  */
21 #include <linux/config.h>
22 #include <linux/types.h>
23 #include <linux/module.h>
24 #include <linux/mm.h>
25 #include <linux/blkdev.h>
26 #include <linux/hdreg.h>
27 #include <linux/ide.h>
28 #include <linux/init.h>
29 #include <linux/pci.h>
30 #include <asm/io.h>
31 
32 /*
33  * No chip documentation has yet been found,
34  * so these configuration values were pulled from
35  * a running Win98 system using "debug".
36  * This gives around 3MByte/second read performance,
37  * which is about 2/3 of what the chip is capable of.
38  *
39  * There is also a 4KByte mmio region on the card,
40  * but its purpose has yet to be reverse-engineered.
41  */
42 static const u8 setup[] = {
43 	0x00, 0x05, 0xbe, 0x01, 0x20, 0x8f, 0x00, 0x00,
44 	0xa4, 0x1f, 0xb3, 0x1b, 0x00, 0x00, 0x00, 0x80,
45 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46 	0x00, 0x00, 0x00, 0x00, 0xa4, 0x83, 0x02, 0x13,
47 };
48 
49 static int __devinit
delkin_cb_probe(struct pci_dev * dev,const struct pci_device_id * id)50 delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
51 {
52 	unsigned long base;
53 	hw_regs_t hw;
54 	ide_hwif_t *hwif = NULL;
55 	ide_drive_t *drive;
56 	int i, rc;
57 
58 	rc = pci_enable_device(dev);
59 	if (rc) {
60 		printk(KERN_ERR "delkin_cb: pci_enable_device failed (%d)\n", rc);
61 		return rc;
62 	}
63 	rc = pci_request_regions(dev, "delkin_cb");
64 	if (rc) {
65 		printk(KERN_ERR "delkin_cb: pci_request_regions failed (%d)\n", rc);
66 		pci_disable_device(dev);
67 		return rc;
68 	}
69 	base = pci_resource_start(dev, 0);
70 	outb(0x02, base + 0x1e);	/* set nIEN to block interrupts */
71 	inb(base + 0x17);		/* read status to clear interrupts */
72 	for (i = 0; i < sizeof(setup); ++i) {
73 		if (setup[i])
74 			outb(setup[i], base + i);
75 	}
76 	pci_release_regions(dev);	/* IDE layer handles regions itself */
77 
78 	memset(&hw, 0, sizeof(hw));
79 	ide_init_hwif_ports(&hw, (ide_ioreg_t)(base + 0x10),
80 				 (ide_ioreg_t)(base + 0x1e), NULL);
81 	hw.irq = dev->irq;
82 	hw.chipset = ide_pci;		/* this enables IRQ sharing */
83 
84 	rc = ide_register_hw(&hw, &hwif);
85 	if (rc < 0)	/* ide_register_hw likes to be invoked twice (buggy) */
86 		rc = ide_register_hw(&hw, &hwif);
87 	if (rc < 0) {
88 		printk(KERN_ERR "delkin_cb: ide_register_hw failed (%d)\n", rc);
89 		pci_disable_device(dev);
90 		return -ENODEV;
91 	}
92 	MOD_INC_USE_COUNT;
93 	pci_set_drvdata(dev, hwif);
94 	hwif->pci_dev = dev;
95 	drive = &hwif->drives[0];
96 	if (drive->present) {
97 		drive->id->csfo = 0; /* workaround for idedisk_open bug */
98 		drive->io_32bit = 1;
99 		drive->unmask   = 1;
100 	}
101 	return 0;
102 }
103 
104 static void
delkin_cb_remove(struct pci_dev * dev)105 delkin_cb_remove (struct pci_dev *dev)
106 {
107 	ide_hwif_t *hwif = pci_get_drvdata(dev);
108 
109 	if (hwif) {
110 		ide_unregister(hwif->index);
111 		MOD_DEC_USE_COUNT;
112 	}
113 	pci_disable_device(dev);
114 }
115 
116 static struct pci_device_id delkin_cb_pci_tbl[] __devinitdata = {
117 	{ PCI_VENDOR_ID_WORKBIT, PCI_DEVICE_ID_WORKBIT_CB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
118 	{ 0, },
119 };
120 MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl);
121 
122 static struct pci_driver driver = {
123 	.name		= "Delkin/ASKA/Workbit Cardbus IDE",
124 	.id_table	= delkin_cb_pci_tbl,
125 	.probe		= delkin_cb_probe,
126 	.remove		= delkin_cb_remove,
127 };
128 
129 static int
delkin_cb_init(void)130 delkin_cb_init (void)
131 {
132 	return pci_module_init(&driver);
133 }
134 
135 static void
delkin_cb_exit(void)136 delkin_cb_exit (void)
137 {
138 	pci_unregister_driver(&driver);
139 }
140 
141 module_init(delkin_cb_init);
142 module_exit(delkin_cb_exit);
143 
144 MODULE_AUTHOR("Mark Lord");
145 MODULE_DESCRIPTION("Basic support for Delkin/ASKA/Workbit Cardbus IDE");
146 MODULE_LICENSE("GPL");
147 
148 EXPORT_NO_SYMBOLS;
149 
150