diff options
author | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-02-02 13:56:39 -0500 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-02-02 13:56:39 -0500 |
commit | 9e016a719209d95338e314b46c3012cc7feaaeec (patch) | |
tree | cc19b160cfb6210385fbf29890351f9ca2ba73df /drivers | |
parent | f82c2b171905b6d5af92395d8159546351ab602f (diff) |
ide: add ide_deprecated_find_port() helper
* Factor out code for finding ide_hwifs[] slot from ide_register_hw()
to ide_deprecated_find_port().
* Convert bast-ide, ide-cs and delkin_cb host drivers to use ide_device_add()
instead of ide_register_hw() (while at it drop doing "ide_unregister()" loop
which tries to unregister _all_ IDE interfaces if useable ide_hwifs[] slot
cannot be find).
This patch leaves us with only two ide_register_hw() users:
- drivers/macintosh/mediabay.c
- drivers/ide/ide.c
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/ide/arm/bast-ide.c | 20 | ||||
-rw-r--r-- | drivers/ide/ide.c | 41 | ||||
-rw-r--r-- | drivers/ide/legacy/ide-cs.c | 25 | ||||
-rw-r--r-- | drivers/ide/pci/delkin_cb.c | 33 |
4 files changed, 99 insertions, 20 deletions
diff --git a/drivers/ide/arm/bast-ide.c b/drivers/ide/arm/bast-ide.c index 037300fa284c..2864f5aca3f1 100644 --- a/drivers/ide/arm/bast-ide.c +++ b/drivers/ide/arm/bast-ide.c | |||
@@ -28,8 +28,10 @@ static int __init | |||
28 | bastide_register(unsigned int base, unsigned int aux, int irq, | 28 | bastide_register(unsigned int base, unsigned int aux, int irq, |
29 | ide_hwif_t **hwif) | 29 | ide_hwif_t **hwif) |
30 | { | 30 | { |
31 | ide_hwif_t *hwif; | ||
31 | hw_regs_t hw; | 32 | hw_regs_t hw; |
32 | int i; | 33 | int i; |
34 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | ||
33 | 35 | ||
34 | memset(&hw, 0, sizeof(hw)); | 36 | memset(&hw, 0, sizeof(hw)); |
35 | 37 | ||
@@ -44,8 +46,24 @@ bastide_register(unsigned int base, unsigned int aux, int irq, | |||
44 | hw.io_ports[IDE_CONTROL_OFFSET] = aux + (6 * 0x20); | 46 | hw.io_ports[IDE_CONTROL_OFFSET] = aux + (6 * 0x20); |
45 | hw.irq = irq; | 47 | hw.irq = irq; |
46 | 48 | ||
47 | ide_register_hw(&hw, NULL, hwif); | 49 | hwif = ide_deprecated_find_port(hw.io_ports[IDE_DATA_OFFSET]); |
50 | if (hwif == NULL) | ||
51 | goto out; | ||
48 | 52 | ||
53 | i = hwif->index; | ||
54 | |||
55 | if (hwif->present) | ||
56 | ide_unregister(i, 0, 1); | ||
57 | else if (!hwif->hold) | ||
58 | ide_init_port_data(hwif, i); | ||
59 | |||
60 | ide_init_port_hw(hwif, &hw); | ||
61 | hwif->quirkproc = NULL; | ||
62 | |||
63 | idx[0] = i; | ||
64 | |||
65 | ide_device_add(idx, NULL); | ||
66 | out: | ||
49 | return 0; | 67 | return 0; |
50 | } | 68 | } |
51 | 69 | ||
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c index 166acd513d5b..d42216b52a7b 100644 --- a/drivers/ide/ide.c +++ b/drivers/ide/ide.c | |||
@@ -683,6 +683,31 @@ void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw) | |||
683 | } | 683 | } |
684 | EXPORT_SYMBOL_GPL(ide_init_port_hw); | 684 | EXPORT_SYMBOL_GPL(ide_init_port_hw); |
685 | 685 | ||
686 | ide_hwif_t *ide_deprecated_find_port(unsigned long base) | ||
687 | { | ||
688 | ide_hwif_t *hwif; | ||
689 | int i; | ||
690 | |||
691 | for (i = 0; i < MAX_HWIFS; i++) { | ||
692 | hwif = &ide_hwifs[i]; | ||
693 | if (hwif->io_ports[IDE_DATA_OFFSET] == base) | ||
694 | goto found; | ||
695 | } | ||
696 | |||
697 | for (i = 0; i < MAX_HWIFS; i++) { | ||
698 | hwif = &ide_hwifs[i]; | ||
699 | if (hwif->hold) | ||
700 | continue; | ||
701 | if (!hwif->present && hwif->mate == NULL) | ||
702 | goto found; | ||
703 | } | ||
704 | |||
705 | hwif = NULL; | ||
706 | found: | ||
707 | return hwif; | ||
708 | } | ||
709 | EXPORT_SYMBOL_GPL(ide_deprecated_find_port); | ||
710 | |||
686 | /** | 711 | /** |
687 | * ide_register_hw - register IDE interface | 712 | * ide_register_hw - register IDE interface |
688 | * @hw: hardware registers | 713 | * @hw: hardware registers |
@@ -702,18 +727,10 @@ int ide_register_hw(hw_regs_t *hw, void (*quirkproc)(ide_drive_t *), | |||
702 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | 727 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
703 | 728 | ||
704 | do { | 729 | do { |
705 | for (index = 0; index < MAX_HWIFS; ++index) { | 730 | hwif = ide_deprecated_find_port(hw->io_ports[IDE_DATA_OFFSET]); |
706 | hwif = &ide_hwifs[index]; | 731 | index = hwif->index; |
707 | if (hwif->io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET]) | 732 | if (hwif) |
708 | goto found; | 733 | goto found; |
709 | } | ||
710 | for (index = 0; index < MAX_HWIFS; ++index) { | ||
711 | hwif = &ide_hwifs[index]; | ||
712 | if (hwif->hold) | ||
713 | continue; | ||
714 | if (!hwif->present && hwif->mate == NULL) | ||
715 | goto found; | ||
716 | } | ||
717 | for (index = 0; index < MAX_HWIFS; index++) | 734 | for (index = 0; index < MAX_HWIFS; index++) |
718 | ide_unregister(index, 1, 1); | 735 | ide_unregister(index, 1, 1); |
719 | } while (retry--); | 736 | } while (retry--); |
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c index 2d772e2bebb3..38e87ad211e0 100644 --- a/drivers/ide/legacy/ide-cs.c +++ b/drivers/ide/legacy/ide-cs.c | |||
@@ -145,13 +145,36 @@ static void ide_detach(struct pcmcia_device *link) | |||
145 | 145 | ||
146 | static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq, struct pcmcia_device *handle) | 146 | static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq, struct pcmcia_device *handle) |
147 | { | 147 | { |
148 | ide_hwif_t *hwif; | ||
148 | hw_regs_t hw; | 149 | hw_regs_t hw; |
150 | int i; | ||
151 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | ||
152 | |||
149 | memset(&hw, 0, sizeof(hw)); | 153 | memset(&hw, 0, sizeof(hw)); |
150 | ide_init_hwif_ports(&hw, io, ctl, NULL); | 154 | ide_init_hwif_ports(&hw, io, ctl, NULL); |
151 | hw.irq = irq; | 155 | hw.irq = irq; |
152 | hw.chipset = ide_pci; | 156 | hw.chipset = ide_pci; |
153 | hw.dev = &handle->dev; | 157 | hw.dev = &handle->dev; |
154 | return ide_register_hw(&hw, &ide_undecoded_slave, NULL); | 158 | |
159 | hwif = ide_deprecated_find_port(hw.io_ports[IDE_DATA_OFFSET]); | ||
160 | if (hwif == NULL) | ||
161 | return -1; | ||
162 | |||
163 | i = hwif->index; | ||
164 | |||
165 | if (hwif->present) | ||
166 | ide_unregister(i, 0, 1); | ||
167 | else if (!hwif->hold) | ||
168 | ide_init_port_data(hwif, i); | ||
169 | |||
170 | ide_init_port_hw(hwif, &hw); | ||
171 | hwif->quirkproc = &ide_undecoded_slave; | ||
172 | |||
173 | idx[0] = i; | ||
174 | |||
175 | ide_device_add(idx, NULL); | ||
176 | |||
177 | return hwif->present ? i : -1; | ||
155 | } | 178 | } |
156 | 179 | ||
157 | /*====================================================================== | 180 | /*====================================================================== |
diff --git a/drivers/ide/pci/delkin_cb.c b/drivers/ide/pci/delkin_cb.c index 4e9ebaa79624..15670801a67f 100644 --- a/drivers/ide/pci/delkin_cb.c +++ b/drivers/ide/pci/delkin_cb.c | |||
@@ -51,6 +51,7 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id) | |||
51 | ide_hwif_t *hwif = NULL; | 51 | ide_hwif_t *hwif = NULL; |
52 | ide_drive_t *drive; | 52 | ide_drive_t *drive; |
53 | int i, rc; | 53 | int i, rc; |
54 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | ||
54 | 55 | ||
55 | rc = pci_enable_device(dev); | 56 | rc = pci_enable_device(dev); |
56 | if (rc) { | 57 | if (rc) { |
@@ -77,12 +78,27 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id) | |||
77 | hw.irq = dev->irq; | 78 | hw.irq = dev->irq; |
78 | hw.chipset = ide_pci; /* this enables IRQ sharing */ | 79 | hw.chipset = ide_pci; /* this enables IRQ sharing */ |
79 | 80 | ||
80 | rc = ide_register_hw(&hw, &ide_undecoded_slave, &hwif); | 81 | hwif = ide_deprecated_find_port(hw.io_ports[IDE_DATA_OFFSET]); |
81 | if (rc < 0) { | 82 | if (hwif == NULL) |
82 | printk(KERN_ERR "delkin_cb: ide_register_hw failed (%d)\n", rc); | 83 | goto out_disable; |
83 | pci_disable_device(dev); | 84 | |
84 | return -ENODEV; | 85 | i = hwif->index; |
85 | } | 86 | |
87 | if (hwif->present) | ||
88 | ide_unregister(i, 0, 1); | ||
89 | else if (!hwif->hold) | ||
90 | ide_init_port_data(hwif, i); | ||
91 | |||
92 | ide_init_port_hw(hwif, &hw); | ||
93 | hwif->quirkproc = &ide_undecoded_slave; | ||
94 | |||
95 | idx[0] = i; | ||
96 | |||
97 | ide_device_add(idx, NULL); | ||
98 | |||
99 | if (!hwif->present) | ||
100 | goto out_disable; | ||
101 | |||
86 | pci_set_drvdata(dev, hwif); | 102 | pci_set_drvdata(dev, hwif); |
87 | hwif->dev = &dev->dev; | 103 | hwif->dev = &dev->dev; |
88 | drive = &hwif->drives[0]; | 104 | drive = &hwif->drives[0]; |
@@ -91,6 +107,11 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id) | |||
91 | drive->unmask = 1; | 107 | drive->unmask = 1; |
92 | } | 108 | } |
93 | return 0; | 109 | return 0; |
110 | |||
111 | out_disable: | ||
112 | printk(KERN_ERR "delkin_cb: no IDE devices found\n"); | ||
113 | pci_disable_device(dev); | ||
114 | return -ENODEV; | ||
94 | } | 115 | } |
95 | 116 | ||
96 | static void | 117 | static void |