]> Pileus Git - ~andy/linux/blob - drivers/ide/arm/rapide.c
ide: add ide_find_port() helper
[~andy/linux] / drivers / ide / arm / rapide.c
1 /*
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 static ide_hwif_t *
17 rapide_locate_hwif(void __iomem *base, void __iomem *ctrl, unsigned int sz, int irq)
18 {
19         unsigned long port = (unsigned long)base;
20         ide_hwif_t *hwif = ide_find_port(port);
21         int i;
22
23         if (hwif == NULL)
24                 goto out;
25
26         for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
27                 hwif->hw.io_ports[i] = port;
28                 hwif->io_ports[i] = port;
29                 port += sz;
30         }
31         hwif->hw.io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl;
32         hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl;
33         hwif->hw.irq = hwif->irq = irq;
34         hwif->mmio = 1;
35         default_hwif_mmiops(hwif);
36 out:
37         return hwif;
38 }
39
40 static int __devinit
41 rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
42 {
43         ide_hwif_t *hwif;
44         void __iomem *base;
45         int ret;
46         u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
47
48         ret = ecard_request_resources(ec);
49         if (ret)
50                 goto out;
51
52         base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
53         if (!base) {
54                 ret = -ENOMEM;
55                 goto release;
56         }
57
58         hwif = rapide_locate_hwif(base, base + 0x818, 1 << 6, ec->irq);
59         if (hwif) {
60                 hwif->hwif_data = base;
61                 hwif->gendev.parent = &ec->dev;
62                 hwif->noprobe = 0;
63
64                 idx[0] = hwif->index;
65
66                 ide_device_add(idx);
67
68                 ecard_set_drvdata(ec, hwif);
69                 goto out;
70         }
71
72  release:
73         ecard_release_resources(ec);
74  out:
75         return ret;
76 }
77
78 static void __devexit rapide_remove(struct expansion_card *ec)
79 {
80         ide_hwif_t *hwif = ecard_get_drvdata(ec);
81
82         ecard_set_drvdata(ec, NULL);
83
84         /* there must be a better way */
85         ide_unregister(hwif - ide_hwifs);
86         ecard_release_resources(ec);
87 }
88
89 static struct ecard_id rapide_ids[] = {
90         { MANU_YELLOWSTONE, PROD_YELLOWSTONE_RAPIDE32 },
91         { 0xffff, 0xffff }
92 };
93
94 static struct ecard_driver rapide_driver = {
95         .probe          = rapide_probe,
96         .remove         = __devexit_p(rapide_remove),
97         .id_table       = rapide_ids,
98         .drv = {
99                 .name   = "rapide",
100         },
101 };
102
103 static int __init rapide_init(void)
104 {
105         return ecard_register_driver(&rapide_driver);
106 }
107
108 MODULE_LICENSE("GPL");
109 MODULE_DESCRIPTION("Yellowstone RAPIDE driver");
110
111 module_init(rapide_init);