blob: 80c0d69b83ace6a08c457dae6c77595d553aba08 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * generic/default IDE host driver
3 *
Bartlomiej Zolnierkiewicz52913ab2009-03-31 20:15:24 +02004 * Copyright (C) 2004, 2008-2009 Bartlomiej Zolnierkiewicz
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * This code was split off from ide.c. See it for original copyrights.
6 *
7 * May be copied or modified under the terms of the GNU General Public License.
8 */
9
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/module.h>
13#include <linux/ide.h>
Borislav Petkov20df4292008-10-10 22:39:35 +020014#include <linux/pci_ids.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Arnd Bergmanna687a532018-03-07 23:30:54 +010016/* FIXME: convert arm to use ide_platform host driver */
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +020017#ifdef CONFIG_ARM
18#include <asm/irq.h>
19#endif
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +020020
Bartlomiej Zolnierkiewiczf0298512008-04-18 00:46:23 +020021#define DRV_NAME "ide_generic"
22
Borislav Petkov20df4292008-10-10 22:39:35 +020023static int probe_mask;
Bartlomiej Zolnierkiewicz0cbccbc2008-06-15 21:00:24 +020024module_param(probe_mask, int, 0);
25MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports");
26
Bartlomiej Zolnierkiewicze518e582009-03-27 12:46:17 +010027static const struct ide_port_info ide_generic_port_info = {
28 .host_flags = IDE_HFLAG_NO_DMA,
Bartlomiej Zolnierkiewicz29e52cf2009-05-17 19:12:22 +020029 .chipset = ide_generic,
Bartlomiej Zolnierkiewicze518e582009-03-27 12:46:17 +010030};
31
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +020032#ifdef CONFIG_ARM
33static const u16 legacy_bases[] = { 0x1f0 };
34static const int legacy_irqs[] = { IRQ_HARDDISK };
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +020035#elif defined(CONFIG_ALPHA)
36static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168 };
37static const int legacy_irqs[] = { 14, 15, 11, 10 };
38#else
39static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
40static const int legacy_irqs[] = { 14, 15, 11, 10, 8, 12 };
41#endif
42
Borislav Petkov20df4292008-10-10 22:39:35 +020043static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
44{
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +020045#ifdef CONFIG_PCI
Borislav Petkov20df4292008-10-10 22:39:35 +020046 struct pci_dev *p = NULL;
47 u16 val;
48
49 for_each_pci_dev(p) {
Borislav Petkov20df4292008-10-10 22:39:35 +020050 if (pci_resource_start(p, 0) == 0x1f0)
51 *primary = 1;
52 if (pci_resource_start(p, 2) == 0x170)
53 *secondary = 1;
54
55 /* Cyrix CS55{1,2}0 pre SFF MWDMA ATA on the bridge */
56 if (p->vendor == PCI_VENDOR_ID_CYRIX &&
57 (p->device == PCI_DEVICE_ID_CYRIX_5510 ||
58 p->device == PCI_DEVICE_ID_CYRIX_5520))
59 *primary = *secondary = 1;
60
61 /* Intel MPIIX - PIO ATA on non PCI side of bridge */
62 if (p->vendor == PCI_VENDOR_ID_INTEL &&
63 p->device == PCI_DEVICE_ID_INTEL_82371MX) {
Borislav Petkov20df4292008-10-10 22:39:35 +020064 pci_read_config_word(p, 0x6C, &val);
65 if (val & 0x8000) {
66 /* ATA port enabled */
67 if (val & 0x4000)
68 *secondary = 1;
69 else
70 *primary = 1;
71 }
72 }
73 }
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +020074#endif
Borislav Petkov20df4292008-10-10 22:39:35 +020075}
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077static int __init ide_generic_init(void)
78{
Bartlomiej Zolnierkiewicz9f36d312009-05-17 19:12:25 +020079 struct ide_hw hw, *hws[] = { &hw };
Bartlomiej Zolnierkiewicz8a695802008-07-23 19:55:59 +020080 unsigned long io_addr;
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +020081 int i, rc = 0, primary = 0, secondary = 0;
Bartlomiej Zolnierkiewicz151575e2008-01-26 20:13:05 +010082
Borislav Petkov20df4292008-10-10 22:39:35 +020083 ide_generic_check_pci_legacy_iobases(&primary, &secondary);
84
85 if (!probe_mask) {
86 printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" "
87 "module parameter for probing all legacy ISA IDE ports\n");
88
89 if (primary == 0)
90 probe_mask |= 0x1;
91
92 if (secondary == 0)
93 probe_mask |= 0x2;
94 } else
95 printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
96 "upon user request\n");
Bartlomiej Zolnierkiewicz0cbccbc2008-06-15 21:00:24 +020097
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +020098 for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
99 io_addr = legacy_bases[i];
Bartlomiej Zolnierkiewiczb2a53bc2008-02-06 02:57:48 +0100100
Bartlomiej Zolnierkiewicz0cbccbc2008-06-15 21:00:24 +0200101 if ((probe_mask & (1 << i)) && io_addr) {
Bartlomiej Zolnierkiewicz16649492008-04-26 22:25:17 +0200102 if (!request_region(io_addr, 8, DRV_NAME)) {
103 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
104 "not free.\n",
105 DRV_NAME, io_addr, io_addr + 7);
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +0200106 rc = -EBUSY;
Bartlomiej Zolnierkiewicz16649492008-04-26 22:25:17 +0200107 continue;
108 }
109
110 if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
111 printk(KERN_ERR "%s: I/O resource 0x%lX "
112 "not free.\n",
113 DRV_NAME, io_addr + 0x206);
114 release_region(io_addr, 8);
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +0200115 rc = -EBUSY;
Bartlomiej Zolnierkiewicz16649492008-04-26 22:25:17 +0200116 continue;
117 }
118
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +0200119 memset(&hw, 0, sizeof(hw));
120 ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +0200121#ifdef CONFIG_IA64
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +0200122 hw.irq = isa_irq_to_vector(legacy_irqs[i]);
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +0200123#else
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +0200124 hw.irq = legacy_irqs[i];
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +0200125#endif
Bartlomiej Zolnierkiewiczdca39832009-05-17 19:12:24 +0200126 rc = ide_host_add(&ide_generic_port_info, hws, 1, NULL);
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +0200127 if (rc) {
128 release_region(io_addr + 0x206, 1);
129 release_region(io_addr, 8);
130 }
Bartlomiej Zolnierkiewicz16649492008-04-26 22:25:17 +0200131 }
Bartlomiej Zolnierkiewiczb2a53bc2008-02-06 02:57:48 +0100132 }
Bartlomiej Zolnierkiewicz151575e2008-01-26 20:13:05 +0100133
Bartlomiej Zolnierkiewicz8a695802008-07-23 19:55:59 +0200134 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
136
137module_init(ide_generic_init);
138
139MODULE_LICENSE("GPL");