blob: 83811af11610d91a371825ca5e937af6ec327927 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/ide/arm/rapide.c
3 *
4 * Copyright (c) 1996-2002 Russell King.
5 */
6
7#include <linux/module.h>
8#include <linux/slab.h>
9#include <linux/blkdev.h>
10#include <linux/errno.h>
11#include <linux/ide.h>
12#include <linux/init.h>
13
14#include <asm/ecard.h>
15
16/*
17 * Something like this really should be in generic code, but isn't.
18 */
19static ide_hwif_t *
20rapide_locate_hwif(void __iomem *base, void __iomem *ctrl, unsigned int sz, int irq)
21{
22 unsigned long port = (unsigned long)base;
23 ide_hwif_t *hwif;
24 int index, i;
25
26 for (index = 0; index < MAX_HWIFS; ++index) {
27 hwif = ide_hwifs + index;
28 if (hwif->io_ports[IDE_DATA_OFFSET] == port)
29 goto found;
30 }
31
32 for (index = 0; index < MAX_HWIFS; ++index) {
33 hwif = ide_hwifs + index;
34 if (hwif->io_ports[IDE_DATA_OFFSET] == 0)
35 goto found;
36 }
37
38 return NULL;
39
40 found:
41 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
42 hwif->hw.io_ports[i] = port;
43 hwif->io_ports[i] = port;
44 port += sz;
45 }
46 hwif->hw.io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl;
47 hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl;
48 hwif->hw.irq = hwif->irq = irq;
Bartlomiej Zolnierkiewicz2ad1e552007-02-17 02:40:25 +010049 hwif->mmio = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 default_hwif_mmiops(hwif);
51
52 return hwif;
53}
54
55static int __devinit
56rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
57{
58 ide_hwif_t *hwif;
59 void __iomem *base;
60 int ret;
61
62 ret = ecard_request_resources(ec);
63 if (ret)
64 goto out;
65
Russell King10bdaaa2007-05-10 18:40:51 +010066 base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 if (!base) {
68 ret = -ENOMEM;
69 goto release;
70 }
71
72 hwif = rapide_locate_hwif(base, base + 0x818, 1 << 6, ec->irq);
73 if (hwif) {
74 hwif->hwif_data = base;
75 hwif->gendev.parent = &ec->dev;
76 hwif->noprobe = 0;
77 probe_hwif_init(hwif);
Bartlomiej Zolnierkiewicz5cbf79c2007-05-10 00:01:11 +020078 ide_proc_register_port(hwif);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 ecard_set_drvdata(ec, hwif);
80 goto out;
81 }
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 release:
84 ecard_release_resources(ec);
85 out:
86 return ret;
87}
88
89static void __devexit rapide_remove(struct expansion_card *ec)
90{
91 ide_hwif_t *hwif = ecard_get_drvdata(ec);
92
93 ecard_set_drvdata(ec, NULL);
94
95 /* there must be a better way */
96 ide_unregister(hwif - ide_hwifs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 ecard_release_resources(ec);
98}
99
100static struct ecard_id rapide_ids[] = {
101 { MANU_YELLOWSTONE, PROD_YELLOWSTONE_RAPIDE32 },
102 { 0xffff, 0xffff }
103};
104
105static struct ecard_driver rapide_driver = {
106 .probe = rapide_probe,
107 .remove = __devexit_p(rapide_remove),
108 .id_table = rapide_ids,
109 .drv = {
110 .name = "rapide",
111 },
112};
113
114static int __init rapide_init(void)
115{
116 return ecard_register_driver(&rapide_driver);
117}
118
119MODULE_LICENSE("GPL");
120MODULE_DESCRIPTION("Yellowstone RAPIDE driver");
121
122module_init(rapide_init);