Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * generic/default IDE host driver |
| 3 | * |
Bartlomiej Zolnierkiewicz | 52913ab | 2009-03-31 20:15:24 +0200 | [diff] [blame^] | 4 | * Copyright (C) 2004, 2008-2009 Bartlomiej Zolnierkiewicz |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * 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 Petkov | 20df429 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 14 | #include <linux/pci_ids.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Bartlomiej Zolnierkiewicz | f01d35d | 2008-07-24 22:53:31 +0200 | [diff] [blame] | 16 | /* FIXME: convert m32r to use ide_platform host driver */ |
| 17 | #ifdef CONFIG_M32R |
| 18 | #include <asm/m32r.h> |
| 19 | #endif |
| 20 | |
Bartlomiej Zolnierkiewicz | f029851 | 2008-04-18 00:46:23 +0200 | [diff] [blame] | 21 | #define DRV_NAME "ide_generic" |
| 22 | |
Borislav Petkov | 20df429 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 23 | static int probe_mask; |
Bartlomiej Zolnierkiewicz | 0cbccbc | 2008-06-15 21:00:24 +0200 | [diff] [blame] | 24 | module_param(probe_mask, int, 0); |
| 25 | MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports"); |
| 26 | |
Bartlomiej Zolnierkiewicz | e518e58 | 2009-03-27 12:46:17 +0100 | [diff] [blame] | 27 | static const struct ide_port_info ide_generic_port_info = { |
| 28 | .host_flags = IDE_HFLAG_NO_DMA, |
| 29 | }; |
| 30 | |
Bartlomiej Zolnierkiewicz | f01d35d | 2008-07-24 22:53:31 +0200 | [diff] [blame] | 31 | #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_MAPPI2) \ |
| 32 | || defined(CONFIG_PLAT_OPSPUT) |
| 33 | static const u16 legacy_bases[] = { 0x1f0 }; |
| 34 | static const int legacy_irqs[] = { PLD_IRQ_CFIREQ }; |
| 35 | #elif defined(CONFIG_PLAT_MAPPI3) |
| 36 | static const u16 legacy_bases[] = { 0x1f0, 0x170 }; |
| 37 | static const int legacy_irqs[] = { PLD_IRQ_CFIREQ, PLD_IRQ_IDEIREQ }; |
| 38 | #elif defined(CONFIG_ALPHA) |
| 39 | static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168 }; |
| 40 | static const int legacy_irqs[] = { 14, 15, 11, 10 }; |
| 41 | #else |
| 42 | static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 }; |
| 43 | static const int legacy_irqs[] = { 14, 15, 11, 10, 8, 12 }; |
| 44 | #endif |
| 45 | |
Borislav Petkov | 20df429 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 46 | static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary) |
| 47 | { |
| 48 | struct pci_dev *p = NULL; |
| 49 | u16 val; |
| 50 | |
| 51 | for_each_pci_dev(p) { |
| 52 | |
| 53 | if (pci_resource_start(p, 0) == 0x1f0) |
| 54 | *primary = 1; |
| 55 | if (pci_resource_start(p, 2) == 0x170) |
| 56 | *secondary = 1; |
| 57 | |
| 58 | /* Cyrix CS55{1,2}0 pre SFF MWDMA ATA on the bridge */ |
| 59 | if (p->vendor == PCI_VENDOR_ID_CYRIX && |
| 60 | (p->device == PCI_DEVICE_ID_CYRIX_5510 || |
| 61 | p->device == PCI_DEVICE_ID_CYRIX_5520)) |
| 62 | *primary = *secondary = 1; |
| 63 | |
| 64 | /* Intel MPIIX - PIO ATA on non PCI side of bridge */ |
| 65 | if (p->vendor == PCI_VENDOR_ID_INTEL && |
| 66 | p->device == PCI_DEVICE_ID_INTEL_82371MX) { |
| 67 | |
| 68 | pci_read_config_word(p, 0x6C, &val); |
| 69 | if (val & 0x8000) { |
| 70 | /* ATA port enabled */ |
| 71 | if (val & 0x4000) |
| 72 | *secondary = 1; |
| 73 | else |
| 74 | *primary = 1; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static int __init ide_generic_init(void) |
| 81 | { |
Bartlomiej Zolnierkiewicz | 6ccc6d7 | 2008-10-13 21:39:42 +0200 | [diff] [blame] | 82 | hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; |
Bartlomiej Zolnierkiewicz | 8a69580 | 2008-07-23 19:55:59 +0200 | [diff] [blame] | 83 | unsigned long io_addr; |
Bartlomiej Zolnierkiewicz | 6ccc6d7 | 2008-10-13 21:39:42 +0200 | [diff] [blame] | 84 | int i, rc = 0, primary = 0, secondary = 0; |
Bartlomiej Zolnierkiewicz | 151575e | 2008-01-26 20:13:05 +0100 | [diff] [blame] | 85 | |
Borislav Petkov | 20df429 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 86 | ide_generic_check_pci_legacy_iobases(&primary, &secondary); |
| 87 | |
| 88 | if (!probe_mask) { |
| 89 | printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" " |
| 90 | "module parameter for probing all legacy ISA IDE ports\n"); |
| 91 | |
| 92 | if (primary == 0) |
| 93 | probe_mask |= 0x1; |
| 94 | |
| 95 | if (secondary == 0) |
| 96 | probe_mask |= 0x2; |
| 97 | } else |
| 98 | printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports " |
| 99 | "upon user request\n"); |
Bartlomiej Zolnierkiewicz | 0cbccbc | 2008-06-15 21:00:24 +0200 | [diff] [blame] | 100 | |
Bartlomiej Zolnierkiewicz | f01d35d | 2008-07-24 22:53:31 +0200 | [diff] [blame] | 101 | for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) { |
| 102 | io_addr = legacy_bases[i]; |
Bartlomiej Zolnierkiewicz | b2a53bc | 2008-02-06 02:57:48 +0100 | [diff] [blame] | 103 | |
Bartlomiej Zolnierkiewicz | 0cbccbc | 2008-06-15 21:00:24 +0200 | [diff] [blame] | 104 | if ((probe_mask & (1 << i)) && io_addr) { |
Bartlomiej Zolnierkiewicz | 1664949 | 2008-04-26 22:25:17 +0200 | [diff] [blame] | 105 | if (!request_region(io_addr, 8, DRV_NAME)) { |
| 106 | printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX " |
| 107 | "not free.\n", |
| 108 | DRV_NAME, io_addr, io_addr + 7); |
| 109 | continue; |
| 110 | } |
| 111 | |
| 112 | if (!request_region(io_addr + 0x206, 1, DRV_NAME)) { |
| 113 | printk(KERN_ERR "%s: I/O resource 0x%lX " |
| 114 | "not free.\n", |
| 115 | DRV_NAME, io_addr + 0x206); |
| 116 | release_region(io_addr, 8); |
| 117 | continue; |
| 118 | } |
| 119 | |
Bartlomiej Zolnierkiewicz | 6ccc6d7 | 2008-10-13 21:39:42 +0200 | [diff] [blame] | 120 | memset(&hw, 0, sizeof(hw)); |
| 121 | ide_std_init_ports(&hw, io_addr, io_addr + 0x206); |
Bartlomiej Zolnierkiewicz | f01d35d | 2008-07-24 22:53:31 +0200 | [diff] [blame] | 122 | #ifdef CONFIG_IA64 |
Bartlomiej Zolnierkiewicz | 6ccc6d7 | 2008-10-13 21:39:42 +0200 | [diff] [blame] | 123 | hw.irq = isa_irq_to_vector(legacy_irqs[i]); |
Bartlomiej Zolnierkiewicz | f01d35d | 2008-07-24 22:53:31 +0200 | [diff] [blame] | 124 | #else |
Bartlomiej Zolnierkiewicz | 6ccc6d7 | 2008-10-13 21:39:42 +0200 | [diff] [blame] | 125 | hw.irq = legacy_irqs[i]; |
Bartlomiej Zolnierkiewicz | f01d35d | 2008-07-24 22:53:31 +0200 | [diff] [blame] | 126 | #endif |
Bartlomiej Zolnierkiewicz | 6ccc6d7 | 2008-10-13 21:39:42 +0200 | [diff] [blame] | 127 | hw.chipset = ide_generic; |
Bartlomiej Zolnierkiewicz | c97c6ac | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 128 | |
Bartlomiej Zolnierkiewicz | e518e58 | 2009-03-27 12:46:17 +0100 | [diff] [blame] | 129 | rc = ide_host_add(&ide_generic_port_info, hws, NULL); |
Bartlomiej Zolnierkiewicz | 6ccc6d7 | 2008-10-13 21:39:42 +0200 | [diff] [blame] | 130 | if (rc) { |
| 131 | release_region(io_addr + 0x206, 1); |
| 132 | release_region(io_addr, 8); |
| 133 | } |
Bartlomiej Zolnierkiewicz | 1664949 | 2008-04-26 22:25:17 +0200 | [diff] [blame] | 134 | } |
Bartlomiej Zolnierkiewicz | b2a53bc | 2008-02-06 02:57:48 +0100 | [diff] [blame] | 135 | } |
Bartlomiej Zolnierkiewicz | 151575e | 2008-01-26 20:13:05 +0100 | [diff] [blame] | 136 | |
Bartlomiej Zolnierkiewicz | 8a69580 | 2008-07-23 19:55:59 +0200 | [diff] [blame] | 137 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | module_init(ide_generic_init); |
| 141 | |
| 142 | MODULE_LICENSE("GPL"); |