blob: 1e10eba62ceb7ba97568da89b24162e2b09da2d0 [file] [log] [blame]
Mark Lord78281c52007-02-07 18:19:32 +01001/*
Mark Lord78281c52007-02-07 18:19:32 +01002 * Created 20 Oct 2004 by Mark Lord
3 *
4 * Basic support for Delkin/ASKA/Workbit Cardbus CompactFlash adapter
5 *
6 * Modeled after the 16-bit PCMCIA driver: ide-cs.c
7 *
8 * This is slightly peculiar, in that it is a PCI driver,
9 * but is NOT an IDE PCI driver -- the IDE layer does not directly
10 * support hot insertion/removal of PCI interfaces, so this driver
11 * is unable to use the IDE PCI interfaces. Instead, it uses the
12 * same interfaces as the ide-cs (PCMCIA) driver uses.
13 * On the plus side, the driver is also smaller/simpler this way.
14 *
15 * This file is subject to the terms and conditions of the GNU General Public
16 * License. See the file COPYING in the main directory of this archive for
17 * more details.
18 */
Bartlomiej Zolnierkiewicz78829dd2008-02-02 19:56:33 +010019
Mark Lord78281c52007-02-07 18:19:32 +010020#include <linux/types.h>
21#include <linux/module.h>
Mark Lord78281c52007-02-07 18:19:32 +010022#include <linux/ide.h>
23#include <linux/init.h>
24#include <linux/pci.h>
Bartlomiej Zolnierkiewicz78829dd2008-02-02 19:56:33 +010025
Mark Lord78281c52007-02-07 18:19:32 +010026#include <asm/io.h>
27
28/*
29 * No chip documentation has yet been found,
30 * so these configuration values were pulled from
31 * a running Win98 system using "debug".
32 * This gives around 3MByte/second read performance,
33 * which is about 2/3 of what the chip is capable of.
34 *
35 * There is also a 4KByte mmio region on the card,
36 * but its purpose has yet to be reverse-engineered.
37 */
38static const u8 setup[] = {
39 0x00, 0x05, 0xbe, 0x01, 0x20, 0x8f, 0x00, 0x00,
40 0xa4, 0x1f, 0xb3, 0x1b, 0x00, 0x00, 0x00, 0x80,
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00, 0xa4, 0x83, 0x02, 0x13,
43};
44
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +020045static const struct ide_port_ops delkin_cb_port_ops = {
46 .quirkproc = ide_undecoded_slave,
47};
48
Bartlomiej Zolnierkiewicz2ed0ef52009-03-24 23:22:53 +010049static int delkin_cb_init_chipset(struct pci_dev *dev)
Bartlomiej Zolnierkiewicz8c061a42008-10-17 18:09:16 +020050{
51 unsigned long base = pci_resource_start(dev, 0);
52 int i;
53
54 outb(0x02, base + 0x1e); /* set nIEN to block interrupts */
55 inb(base + 0x17); /* read status to clear interrupts */
56
57 for (i = 0; i < sizeof(setup); ++i) {
58 if (setup[i])
59 outb(setup[i], base + i);
60 }
61
62 return 0;
63}
64
Bartlomiej Zolnierkiewicz1c4d4ad2008-06-10 20:56:37 +020065static const struct ide_port_info delkin_cb_port_info = {
66 .port_ops = &delkin_cb_port_ops,
67 .host_flags = IDE_HFLAG_IO_32BIT | IDE_HFLAG_UNMASK_IRQS |
68 IDE_HFLAG_NO_DMA,
Bartlomiej Zolnierkiewicz255115fb2009-03-27 12:46:27 +010069 .irq_flags = IRQF_SHARED,
Bartlomiej Zolnierkiewicz8c061a42008-10-17 18:09:16 +020070 .init_chipset = delkin_cb_init_chipset,
Bartlomiej Zolnierkiewicz29e52cf2009-05-17 19:12:22 +020071 .chipset = ide_pci,
Bartlomiej Zolnierkiewicz1c4d4ad2008-06-10 20:56:37 +020072};
73
Mark Lord78281c52007-02-07 18:19:32 +010074static int __devinit
75delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
76{
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +020077 struct ide_host *host;
Mark Lord78281c52007-02-07 18:19:32 +010078 unsigned long base;
Bartlomiej Zolnierkiewicz8c061a42008-10-17 18:09:16 +020079 int rc;
Bartlomiej Zolnierkiewicz9f36d312009-05-17 19:12:25 +020080 struct ide_hw hw, *hws[] = { &hw };
Mark Lord78281c52007-02-07 18:19:32 +010081
82 rc = pci_enable_device(dev);
83 if (rc) {
84 printk(KERN_ERR "delkin_cb: pci_enable_device failed (%d)\n", rc);
85 return rc;
86 }
87 rc = pci_request_regions(dev, "delkin_cb");
88 if (rc) {
89 printk(KERN_ERR "delkin_cb: pci_request_regions failed (%d)\n", rc);
90 pci_disable_device(dev);
91 return rc;
92 }
93 base = pci_resource_start(dev, 0);
Bartlomiej Zolnierkiewicz8c061a42008-10-17 18:09:16 +020094
95 delkin_cb_init_chipset(dev);
Mark Lord78281c52007-02-07 18:19:32 +010096
97 memset(&hw, 0, sizeof(hw));
98 ide_std_init_ports(&hw, base + 0x10, base + 0x1e);
99 hw.irq = dev->irq;
Bartlomiej Zolnierkiewicz8a7dbb92008-06-10 20:56:37 +0200100 hw.dev = &dev->dev;
Mark Lord78281c52007-02-07 18:19:32 +0100101
Bartlomiej Zolnierkiewiczdca39832009-05-17 19:12:24 +0200102 rc = ide_host_add(&delkin_cb_port_info, hws, 1, &host);
Bartlomiej Zolnierkiewicz6f904d02008-07-23 19:55:57 +0200103 if (rc)
Bartlomiej Zolnierkiewicz9e016a72008-02-02 19:56:39 +0100104 goto out_disable;
105
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +0200106 pci_set_drvdata(dev, host);
Bartlomiej Zolnierkiewicz8a7dbb92008-06-10 20:56:37 +0200107
Mark Lord78281c52007-02-07 18:19:32 +0100108 return 0;
Bartlomiej Zolnierkiewicz9e016a72008-02-02 19:56:39 +0100109
110out_disable:
Bartlomiej Zolnierkiewicz7f6f33c2008-04-26 17:36:38 +0200111 pci_release_regions(dev);
Bartlomiej Zolnierkiewicz9e016a72008-02-02 19:56:39 +0100112 pci_disable_device(dev);
Bartlomiej Zolnierkiewicz6f904d02008-07-23 19:55:57 +0200113 return rc;
Mark Lord78281c52007-02-07 18:19:32 +0100114}
115
116static void
117delkin_cb_remove (struct pci_dev *dev)
118{
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +0200119 struct ide_host *host = pci_get_drvdata(dev);
Mark Lord78281c52007-02-07 18:19:32 +0100120
Bartlomiej Zolnierkiewicz48c3c102008-07-23 19:55:57 +0200121 ide_host_remove(host);
Bartlomiej Zolnierkiewiczf82c2b12008-02-02 19:56:39 +0100122
Bartlomiej Zolnierkiewicz7f6f33c2008-04-26 17:36:38 +0200123 pci_release_regions(dev);
Mark Lord78281c52007-02-07 18:19:32 +0100124 pci_disable_device(dev);
125}
126
Bartlomiej Zolnierkiewicz8c061a42008-10-17 18:09:16 +0200127#ifdef CONFIG_PM
128static int delkin_cb_suspend(struct pci_dev *dev, pm_message_t state)
129{
130 pci_save_state(dev);
131 pci_disable_device(dev);
132 pci_set_power_state(dev, pci_choose_state(dev, state));
133
134 return 0;
135}
136
137static int delkin_cb_resume(struct pci_dev *dev)
138{
139 struct ide_host *host = pci_get_drvdata(dev);
140 int rc;
141
142 pci_set_power_state(dev, PCI_D0);
143
144 rc = pci_enable_device(dev);
145 if (rc)
146 return rc;
147
148 pci_restore_state(dev);
149 pci_set_master(dev);
150
151 if (host->init_chipset)
152 host->init_chipset(dev);
153
154 return 0;
155}
156#else
157#define delkin_cb_suspend NULL
158#define delkin_cb_resume NULL
159#endif
160
Mark Lord78281c52007-02-07 18:19:32 +0100161static struct pci_device_id delkin_cb_pci_tbl[] __devinitdata = {
162 { 0x1145, 0xf021, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Mark Lord2571b162007-04-20 22:16:58 +0200163 { 0x1145, 0xf024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Mark Lord78281c52007-02-07 18:19:32 +0100164 { 0, },
165};
166MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl);
167
Bartlomiej Zolnierkiewicza9ab09e22008-10-13 21:39:41 +0200168static struct pci_driver delkin_cb_pci_driver = {
Mark Lord78281c52007-02-07 18:19:32 +0100169 .name = "Delkin-ASKA-Workbit Cardbus IDE",
170 .id_table = delkin_cb_pci_tbl,
171 .probe = delkin_cb_probe,
172 .remove = delkin_cb_remove,
Bartlomiej Zolnierkiewicz8c061a42008-10-17 18:09:16 +0200173 .suspend = delkin_cb_suspend,
174 .resume = delkin_cb_resume,
Mark Lord78281c52007-02-07 18:19:32 +0100175};
176
Bartlomiej Zolnierkiewiczf4084a12008-06-10 20:56:38 +0200177static int __init delkin_cb_init(void)
Mark Lord78281c52007-02-07 18:19:32 +0100178{
Bartlomiej Zolnierkiewicza9ab09e22008-10-13 21:39:41 +0200179 return pci_register_driver(&delkin_cb_pci_driver);
Mark Lord78281c52007-02-07 18:19:32 +0100180}
181
Bartlomiej Zolnierkiewiczf4084a12008-06-10 20:56:38 +0200182static void __exit delkin_cb_exit(void)
Mark Lord78281c52007-02-07 18:19:32 +0100183{
Bartlomiej Zolnierkiewicza9ab09e22008-10-13 21:39:41 +0200184 pci_unregister_driver(&delkin_cb_pci_driver);
Mark Lord78281c52007-02-07 18:19:32 +0100185}
186
187module_init(delkin_cb_init);
188module_exit(delkin_cb_exit);
189
190MODULE_AUTHOR("Mark Lord");
191MODULE_DESCRIPTION("Basic support for Delkin/ASKA/Workbit Cardbus IDE");
192MODULE_LICENSE("GPL");
193