1/*
2 * Copyright (c) 1996-2002 Russell King.
3 */
4
5#include <linux/module.h>
6#include <linux/blkdev.h>
7#include <linux/errno.h>
8#include <linux/ide.h>
9#include <linux/init.h>
10
11#include <asm/ecard.h>
12
13static const struct ide_port_info rapide_port_info = {
14	.host_flags		= IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
15	.chipset		= ide_generic,
16};
17
18static void rapide_setup_ports(struct ide_hw *hw, void __iomem *base,
19			       void __iomem *ctrl, unsigned int sz, int irq)
20{
21	unsigned long port = (unsigned long)base;
22	int i;
23
24	for (i = 0; i <= 7; i++) {
25		hw->io_ports_array[i] = port;
26		port += sz;
27	}
28	hw->io_ports.ctl_addr = (unsigned long)ctrl;
29	hw->irq = irq;
30}
31
32static int rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
33{
34	void __iomem *base;
35	struct ide_host *host;
36	int ret;
37	struct ide_hw hw, *hws[] = { &hw };
38
39	ret = ecard_request_resources(ec);
40	if (ret)
41		goto out;
42
43	base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
44	if (!base) {
45		ret = -ENOMEM;
46		goto release;
47	}
48
49	memset(&hw, 0, sizeof(hw));
50	rapide_setup_ports(&hw, base, base + 0x818, 1 << 6, ec->irq);
51	hw.dev = &ec->dev;
52
53	ret = ide_host_add(&rapide_port_info, hws, 1, &host);
54	if (ret)
55		goto release;
56
57	ecard_set_drvdata(ec, host);
58	goto out;
59
60 release:
61	ecard_release_resources(ec);
62 out:
63	return ret;
64}
65
66static void rapide_remove(struct expansion_card *ec)
67{
68	struct ide_host *host = ecard_get_drvdata(ec);
69
70	ecard_set_drvdata(ec, NULL);
71
72	ide_host_remove(host);
73
74	ecard_release_resources(ec);
75}
76
77static struct ecard_id rapide_ids[] = {
78	{ MANU_YELLOWSTONE, PROD_YELLOWSTONE_RAPIDE32 },
79	{ 0xffff, 0xffff }
80};
81
82static struct ecard_driver rapide_driver = {
83	.probe		= rapide_probe,
84	.remove		= rapide_remove,
85	.id_table	= rapide_ids,
86	.drv = {
87		.name	= "rapide",
88	},
89};
90
91static int __init rapide_init(void)
92{
93	return ecard_register_driver(&rapide_driver);
94}
95
96static void __exit rapide_exit(void)
97{
98	ecard_remove_driver(&rapide_driver);
99}
100
101MODULE_LICENSE("GPL");
102MODULE_DESCRIPTION("Yellowstone RAPIDE driver");
103
104module_init(rapide_init);
105module_exit(rapide_exit);
106