blob: 0775a3afef4862d5e5b2b5646443cbcfdec1448c [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++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 hwif->io_ports[i] = port;
28 port += sz;
29 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl;
Bartlomiej Zolnierkiewicz9239b332007-10-20 00:32:33 +020031 hwif->irq = irq;
Bartlomiej Zolnierkiewicz2ad1e552007-02-17 02:40:25 +010032 hwif->mmio = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 default_hwif_mmiops(hwif);
Bartlomiej Zolnierkiewiczbaa8f3e2007-10-20 00:32:31 +020034out:
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 return hwif;
36}
37
38static int __devinit
39rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
40{
41 ide_hwif_t *hwif;
42 void __iomem *base;
43 int ret;
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +020044 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46 ret = ecard_request_resources(ec);
47 if (ret)
48 goto out;
49
Russell King10bdaaa2007-05-10 18:40:51 +010050 base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 if (!base) {
52 ret = -ENOMEM;
53 goto release;
54 }
55
56 hwif = rapide_locate_hwif(base, base + 0x818, 1 << 6, ec->irq);
57 if (hwif) {
58 hwif->hwif_data = base;
59 hwif->gendev.parent = &ec->dev;
60 hwif->noprobe = 0;
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +020061
62 idx[0] = hwif->index;
63
64 ide_device_add(idx);
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 ecard_set_drvdata(ec, hwif);
67 goto out;
68 }
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 release:
71 ecard_release_resources(ec);
72 out:
73 return ret;
74}
75
76static void __devexit rapide_remove(struct expansion_card *ec)
77{
78 ide_hwif_t *hwif = ecard_get_drvdata(ec);
79
80 ecard_set_drvdata(ec, NULL);
81
82 /* there must be a better way */
83 ide_unregister(hwif - ide_hwifs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 ecard_release_resources(ec);
85}
86
87static struct ecard_id rapide_ids[] = {
88 { MANU_YELLOWSTONE, PROD_YELLOWSTONE_RAPIDE32 },
89 { 0xffff, 0xffff }
90};
91
92static struct ecard_driver rapide_driver = {
93 .probe = rapide_probe,
94 .remove = __devexit_p(rapide_remove),
95 .id_table = rapide_ids,
96 .drv = {
97 .name = "rapide",
98 },
99};
100
101static int __init rapide_init(void)
102{
103 return ecard_register_driver(&rapide_driver);
104}
105
106MODULE_LICENSE("GPL");
107MODULE_DESCRIPTION("Yellowstone RAPIDE driver");
108
109module_init(rapide_init);