Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Bartlomiej Zolnierkiewicz | 7f92b11 | 2008-12-29 20:27:37 +0100 | [diff] [blame] | 2 | #include <linux/kernel.h> |
Paul Gortmaker | 38789fd | 2011-07-17 15:33:58 -0400 | [diff] [blame] | 3 | #include <linux/export.h> |
Bartlomiej Zolnierkiewicz | 7f92b11 | 2008-12-29 20:27:37 +0100 | [diff] [blame] | 4 | #include <linux/ide.h> |
| 5 | |
Bartlomiej Zolnierkiewicz | 9f36d31 | 2009-05-17 19:12:25 +0200 | [diff] [blame] | 6 | static void ide_legacy_init_one(struct ide_hw **hws, struct ide_hw *hw, |
Bartlomiej Zolnierkiewicz | 7f92b11 | 2008-12-29 20:27:37 +0100 | [diff] [blame] | 7 | u8 port_no, const struct ide_port_info *d, |
| 8 | unsigned long config) |
| 9 | { |
| 10 | unsigned long base, ctl; |
| 11 | int irq; |
| 12 | |
| 13 | if (port_no == 0) { |
| 14 | base = 0x1f0; |
| 15 | ctl = 0x3f6; |
| 16 | irq = 14; |
| 17 | } else { |
| 18 | base = 0x170; |
| 19 | ctl = 0x376; |
| 20 | irq = 15; |
| 21 | } |
| 22 | |
| 23 | if (!request_region(base, 8, d->name)) { |
| 24 | printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n", |
| 25 | d->name, base, base + 7); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | if (!request_region(ctl, 1, d->name)) { |
| 30 | printk(KERN_ERR "%s: I/O resource 0x%lX not free.\n", |
| 31 | d->name, ctl); |
| 32 | release_region(base, 8); |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | ide_std_init_ports(hw, base, ctl); |
| 37 | hw->irq = irq; |
Bartlomiej Zolnierkiewicz | 7f92b11 | 2008-12-29 20:27:37 +0100 | [diff] [blame] | 38 | hw->config = config; |
| 39 | |
| 40 | hws[port_no] = hw; |
| 41 | } |
| 42 | |
| 43 | int ide_legacy_device_add(const struct ide_port_info *d, unsigned long config) |
| 44 | { |
Bartlomiej Zolnierkiewicz | 9f36d31 | 2009-05-17 19:12:25 +0200 | [diff] [blame] | 45 | struct ide_hw hw[2], *hws[] = { NULL, NULL }; |
Bartlomiej Zolnierkiewicz | 7f92b11 | 2008-12-29 20:27:37 +0100 | [diff] [blame] | 46 | |
| 47 | memset(&hw, 0, sizeof(hw)); |
| 48 | |
| 49 | if ((d->host_flags & IDE_HFLAG_QD_2ND_PORT) == 0) |
| 50 | ide_legacy_init_one(hws, &hw[0], 0, d, config); |
| 51 | ide_legacy_init_one(hws, &hw[1], 1, d, config); |
| 52 | |
| 53 | if (hws[0] == NULL && hws[1] == NULL && |
| 54 | (d->host_flags & IDE_HFLAG_SINGLE)) |
| 55 | return -ENOENT; |
| 56 | |
Bartlomiej Zolnierkiewicz | dca3983 | 2009-05-17 19:12:24 +0200 | [diff] [blame] | 57 | return ide_host_add(d, hws, 2, NULL); |
Bartlomiej Zolnierkiewicz | 7f92b11 | 2008-12-29 20:27:37 +0100 | [diff] [blame] | 58 | } |
| 59 | EXPORT_SYMBOL_GPL(ide_legacy_device_add); |