blob: 30fe3630734fce9ab06edfe7881fe82d86374428 [file] [log] [blame]
Bartlomiej Zolnierkiewicz7f92b112008-12-29 20:27:37 +01001#include <linux/kernel.h>
Paul Gortmaker38789fd2011-07-17 15:33:58 -04002#include <linux/export.h>
Bartlomiej Zolnierkiewicz7f92b112008-12-29 20:27:37 +01003#include <linux/ide.h>
4
Bartlomiej Zolnierkiewicz9f36d312009-05-17 19:12:25 +02005static void ide_legacy_init_one(struct ide_hw **hws, struct ide_hw *hw,
Bartlomiej Zolnierkiewicz7f92b112008-12-29 20:27:37 +01006 u8 port_no, const struct ide_port_info *d,
7 unsigned long config)
8{
9 unsigned long base, ctl;
10 int irq;
11
12 if (port_no == 0) {
13 base = 0x1f0;
14 ctl = 0x3f6;
15 irq = 14;
16 } else {
17 base = 0x170;
18 ctl = 0x376;
19 irq = 15;
20 }
21
22 if (!request_region(base, 8, d->name)) {
23 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
24 d->name, base, base + 7);
25 return;
26 }
27
28 if (!request_region(ctl, 1, d->name)) {
29 printk(KERN_ERR "%s: I/O resource 0x%lX not free.\n",
30 d->name, ctl);
31 release_region(base, 8);
32 return;
33 }
34
35 ide_std_init_ports(hw, base, ctl);
36 hw->irq = irq;
Bartlomiej Zolnierkiewicz7f92b112008-12-29 20:27:37 +010037 hw->config = config;
38
39 hws[port_no] = hw;
40}
41
42int ide_legacy_device_add(const struct ide_port_info *d, unsigned long config)
43{
Bartlomiej Zolnierkiewicz9f36d312009-05-17 19:12:25 +020044 struct ide_hw hw[2], *hws[] = { NULL, NULL };
Bartlomiej Zolnierkiewicz7f92b112008-12-29 20:27:37 +010045
46 memset(&hw, 0, sizeof(hw));
47
48 if ((d->host_flags & IDE_HFLAG_QD_2ND_PORT) == 0)
49 ide_legacy_init_one(hws, &hw[0], 0, d, config);
50 ide_legacy_init_one(hws, &hw[1], 1, d, config);
51
52 if (hws[0] == NULL && hws[1] == NULL &&
53 (d->host_flags & IDE_HFLAG_SINGLE))
54 return -ENOENT;
55
Bartlomiej Zolnierkiewiczdca39832009-05-17 19:12:24 +020056 return ide_host_add(d, hws, 2, NULL);
Bartlomiej Zolnierkiewicz7f92b112008-12-29 20:27:37 +010057}
58EXPORT_SYMBOL_GPL(ide_legacy_device_add);