blob: 96cd3f5b9adc25f4d8acc8378c3b2c403850ab8c [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070016static ide_hwif_t *
17rapide_locate_hwif(void __iomem *base, void __iomem *ctrl, unsigned int sz, int irq)
18{
19 unsigned long port = (unsigned long)base;
Bartlomiej Zolnierkiewiczbaa8f3e2007-10-20 00:32:31 +020020 ide_hwif_t *hwif = ide_find_port(port);
21 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Bartlomiej Zolnierkiewiczbaa8f3e2007-10-20 00:32:31 +020023 if (hwif == NULL)
24 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 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;
Bartlomiej Zolnierkiewicz2ad1e552007-02-17 02:40:25 +010034 hwif->mmio = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 default_hwif_mmiops(hwif);
Bartlomiej Zolnierkiewiczbaa8f3e2007-10-20 00:32:31 +020036out:
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 return hwif;
38}
39
40static int __devinit
41rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
42{
43 ide_hwif_t *hwif;
44 void __iomem *base;
45 int ret;
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +020046 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48 ret = ecard_request_resources(ec);
49 if (ret)
50 goto out;
51
Russell King10bdaaa2007-05-10 18:40:51 +010052 base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 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;
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +020063
64 idx[0] = hwif->index;
65
66 ide_device_add(idx);
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 ecard_set_drvdata(ec, hwif);
69 goto out;
70 }
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 release:
73 ecard_release_resources(ec);
74 out:
75 return ret;
76}
77
78static 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 ecard_release_resources(ec);
87}
88
89static struct ecard_id rapide_ids[] = {
90 { MANU_YELLOWSTONE, PROD_YELLOWSTONE_RAPIDE32 },
91 { 0xffff, 0xffff }
92};
93
94static 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
103static int __init rapide_init(void)
104{
105 return ecard_register_driver(&rapide_driver);
106}
107
108MODULE_LICENSE("GPL");
109MODULE_DESCRIPTION("Yellowstone RAPIDE driver");
110
111module_init(rapide_init);