blob: 7812ca0be13beb1c5af1ba98ea8b29b4bd2cbf4b [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
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +020016/* FIXME: convert arm and m32r to use ide_platform host driver */
17#ifdef CONFIG_ARM
18#include <asm/irq.h>
19#endif
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +020020#ifdef CONFIG_M32R
21#include <asm/m32r.h>
22#endif
23
Bartlomiej Zolnierkiewiczf0298512008-04-18 00:46:23 +020024#define DRV_NAME "ide_generic"
25
Borislav Petkov20df4292008-10-10 22:39:35 +020026static int probe_mask;
Bartlomiej Zolnierkiewicz0cbccbc2008-06-15 21:00:24 +020027module_param(probe_mask, int, 0);
28MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports");
29
Bartlomiej Zolnierkiewicze518e582009-03-27 12:46:17 +010030static const struct ide_port_info ide_generic_port_info = {
31 .host_flags = IDE_HFLAG_NO_DMA,
32};
33
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +020034#ifdef CONFIG_ARM
35static const u16 legacy_bases[] = { 0x1f0 };
36static const int legacy_irqs[] = { IRQ_HARDDISK };
37#elif defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_MAPPI2) || \
38 defined(CONFIG_PLAT_OPSPUT)
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +020039static const u16 legacy_bases[] = { 0x1f0 };
40static const int legacy_irqs[] = { PLD_IRQ_CFIREQ };
41#elif defined(CONFIG_PLAT_MAPPI3)
42static const u16 legacy_bases[] = { 0x1f0, 0x170 };
43static const int legacy_irqs[] = { PLD_IRQ_CFIREQ, PLD_IRQ_IDEIREQ };
44#elif defined(CONFIG_ALPHA)
45static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168 };
46static const int legacy_irqs[] = { 14, 15, 11, 10 };
47#else
48static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
49static const int legacy_irqs[] = { 14, 15, 11, 10, 8, 12 };
50#endif
51
Borislav Petkov20df4292008-10-10 22:39:35 +020052static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
53{
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +020054#ifdef CONFIG_PCI
Borislav Petkov20df4292008-10-10 22:39:35 +020055 struct pci_dev *p = NULL;
56 u16 val;
57
58 for_each_pci_dev(p) {
Borislav Petkov20df4292008-10-10 22:39:35 +020059 if (pci_resource_start(p, 0) == 0x1f0)
60 *primary = 1;
61 if (pci_resource_start(p, 2) == 0x170)
62 *secondary = 1;
63
64 /* Cyrix CS55{1,2}0 pre SFF MWDMA ATA on the bridge */
65 if (p->vendor == PCI_VENDOR_ID_CYRIX &&
66 (p->device == PCI_DEVICE_ID_CYRIX_5510 ||
67 p->device == PCI_DEVICE_ID_CYRIX_5520))
68 *primary = *secondary = 1;
69
70 /* Intel MPIIX - PIO ATA on non PCI side of bridge */
71 if (p->vendor == PCI_VENDOR_ID_INTEL &&
72 p->device == PCI_DEVICE_ID_INTEL_82371MX) {
Borislav Petkov20df4292008-10-10 22:39:35 +020073 pci_read_config_word(p, 0x6C, &val);
74 if (val & 0x8000) {
75 /* ATA port enabled */
76 if (val & 0x4000)
77 *secondary = 1;
78 else
79 *primary = 1;
80 }
81 }
82 }
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +020083#endif
Borislav Petkov20df4292008-10-10 22:39:35 +020084}
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086static int __init ide_generic_init(void)
87{
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +020088 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
Bartlomiej Zolnierkiewicz8a695802008-07-23 19:55:59 +020089 unsigned long io_addr;
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +020090 int i, rc = 0, primary = 0, secondary = 0;
Bartlomiej Zolnierkiewicz151575e2008-01-26 20:13:05 +010091
Borislav Petkov20df4292008-10-10 22:39:35 +020092 ide_generic_check_pci_legacy_iobases(&primary, &secondary);
93
94 if (!probe_mask) {
95 printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" "
96 "module parameter for probing all legacy ISA IDE ports\n");
97
98 if (primary == 0)
99 probe_mask |= 0x1;
100
101 if (secondary == 0)
102 probe_mask |= 0x2;
103 } else
104 printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
105 "upon user request\n");
Bartlomiej Zolnierkiewicz0cbccbc2008-06-15 21:00:24 +0200106
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +0200107 for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
108 io_addr = legacy_bases[i];
Bartlomiej Zolnierkiewiczb2a53bc2008-02-06 02:57:48 +0100109
Bartlomiej Zolnierkiewicz0cbccbc2008-06-15 21:00:24 +0200110 if ((probe_mask & (1 << i)) && io_addr) {
Bartlomiej Zolnierkiewicz16649492008-04-26 22:25:17 +0200111 if (!request_region(io_addr, 8, DRV_NAME)) {
112 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
113 "not free.\n",
114 DRV_NAME, io_addr, io_addr + 7);
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +0200115 rc = -EBUSY;
Bartlomiej Zolnierkiewicz16649492008-04-26 22:25:17 +0200116 continue;
117 }
118
119 if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
120 printk(KERN_ERR "%s: I/O resource 0x%lX "
121 "not free.\n",
122 DRV_NAME, io_addr + 0x206);
123 release_region(io_addr, 8);
Bartlomiej Zolnierkiewicz44654612009-03-31 20:15:24 +0200124 rc = -EBUSY;
Bartlomiej Zolnierkiewicz16649492008-04-26 22:25:17 +0200125 continue;
126 }
127
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +0200128 memset(&hw, 0, sizeof(hw));
129 ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +0200130#ifdef CONFIG_IA64
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +0200131 hw.irq = isa_irq_to_vector(legacy_irqs[i]);
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +0200132#else
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +0200133 hw.irq = legacy_irqs[i];
Bartlomiej Zolnierkiewiczf01d35d2008-07-24 22:53:31 +0200134#endif
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +0200135 hw.chipset = ide_generic;
Bartlomiej Zolnierkiewiczc97c6ac2008-07-23 19:55:50 +0200136
Bartlomiej Zolnierkiewicze518e582009-03-27 12:46:17 +0100137 rc = ide_host_add(&ide_generic_port_info, hws, NULL);
Bartlomiej Zolnierkiewicz6ccc6d72008-10-13 21:39:42 +0200138 if (rc) {
139 release_region(io_addr + 0x206, 1);
140 release_region(io_addr, 8);
141 }
Bartlomiej Zolnierkiewicz16649492008-04-26 22:25:17 +0200142 }
Bartlomiej Zolnierkiewiczb2a53bc2008-02-06 02:57:48 +0100143 }
Bartlomiej Zolnierkiewicz151575e2008-01-26 20:13:05 +0100144
Bartlomiej Zolnierkiewicz8a695802008-07-23 19:55:59 +0200145 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
148module_init(ide_generic_init);
149
150MODULE_LICENSE("GPL");