sl811_cs.c 5.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * PCMCIA driver for SL811HS (as found in REX-CFU1U)
 * Filename: sl811_cs.c
 * Author:   Yukio Yamamoto
 *
 *  Port to sl811-hcd and 2.6.x by
 *    Botond Botyanszki <boti@rocketmail.com>
 *    Simon Pickering
 *
 *  Last update: 2005-05-12
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/ptrace.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/ioport.h>
21
#include <linux/platform_device.h>
22 23 24 25 26

#include <pcmcia/cistpl.h>
#include <pcmcia/cisreg.h>
#include <pcmcia/ds.h>

27
#include <linux/usb/sl811.h>
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

MODULE_AUTHOR("Botond Botyanszki");
MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6");
MODULE_LICENSE("GPL");


/*====================================================================*/
/* MACROS                                                             */
/*====================================================================*/

#define INFO(args...) printk(KERN_INFO "sl811_cs: " args)

/*====================================================================*/
/* VARIABLES                                                          */
/*====================================================================*/

typedef struct local_info_t {
45
	struct pcmcia_device	*p_dev;
46 47
} local_info_t;

48
static void sl811_cs_release(struct pcmcia_device * link);
49

50 51 52 53
/*====================================================================*/

static void release_platform_dev(struct device * dev)
{
54
	dev_dbg(dev, "sl811_cs platform_dev release\n");
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
	dev->parent = NULL;
}

static struct sl811_platform_data platform_data = {
	.potpg		= 100,
	.power		= 50,		/* == 100mA */
	// .reset	= ... FIXME:  invoke CF reset on the card
};

static struct resource resources[] = {
	[0] = {
		.flags	= IORESOURCE_IRQ,
	},
	[1] = {
		// .name   = "address",
		.flags	= IORESOURCE_IO,
	},
	[2] = {
		// .name   = "data",
		.flags	= IORESOURCE_IO,
	},
};

78
extern struct platform_driver sl811h_driver;
79 80 81 82 83 84 85 86 87 88 89

static struct platform_device platform_dev = {
	.id			= -1,
	.dev = {
		.platform_data = &platform_data,
		.release       = release_platform_dev,
	},
	.resource		= resources,
	.num_resources		= ARRAY_SIZE(resources),
};

D
Dominik Brodowski 已提交
90 91
static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
			 int irq)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
{
	if (platform_dev.dev.parent)
		return -EBUSY;
	platform_dev.dev.parent = parent;

	/* finish seting up the platform device */
	resources[0].start = irq;

	resources[1].start = base_addr;
	resources[1].end = base_addr;

	resources[2].start = base_addr + 1;
	resources[2].end   = base_addr + 1;

	/* The driver core will probe for us.  We know sl811-hcd has been
107 108
	 * initialized already because of the link order dependency created
	 * by referencing "sl811h_driver".
109
	 */
110
	platform_dev.name = sl811h_driver.driver.name;
111 112 113 114 115
	return platform_device_register(&platform_dev);
}

/*====================================================================*/

116
static void sl811_cs_detach(struct pcmcia_device *link)
117
{
118
	dev_dbg(&link->dev, "sl811_cs_detach\n");
119

120
	sl811_cs_release(link);
121 122 123 124 125

	/* This points to the parent local_info_t struct */
	kfree(link->priv);
}

126
static void sl811_cs_release(struct pcmcia_device * link)
127
{
128
	dev_dbg(&link->dev, "sl811_cs_release\n");
129

130
	pcmcia_disable_device(link);
131 132 133
	platform_device_unregister(&platform_dev);
}

134
static int sl811_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
135
{
136 137 138 139
	if (p_dev->config_index == 0)
		return -EINVAL;

	return pcmcia_request_io(p_dev);
140 141 142
}


143
static int sl811_cs_config(struct pcmcia_device *link)
144
{
145
	struct device		*parent = &link->dev;
146
	int			ret;
147

148
	dev_dbg(&link->dev, "sl811_cs_config\n");
149

150
	link->config_flags |= CONF_ENABLE_IRQ |	CONF_AUTO_SET_VPP |
151
		CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO;
152

153 154
	if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
		goto failed;
155 156

	/* require an IRQ and two registers */
157
	if (resource_size(link->resource[0]) < 2)
158
		goto failed;
159 160

	if (!link->irq)
161
		goto failed;
162

163
	ret = pcmcia_enable_device(link);
164 165
	if (ret)
		goto failed;
166

167
	if (sl811_hc_init(parent, link->resource[0]->start, link->irq)
168
			< 0) {
169 170
failed:
		printk(KERN_WARNING "sl811_cs_config failed\n");
171
		sl811_cs_release(link);
172
		return  -ENODEV;
173
	}
174
	return 0;
175 176
}

177
static int sl811_cs_probe(struct pcmcia_device *link)
178 179 180
{
	local_info_t *local;

181
	local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
182
	if (!local)
183
		return -ENOMEM;
184
	local->p_dev = link;
185 186
	link->priv = local;

187
	return sl811_cs_config(link);
188 189
}

190 191 192 193 194 195
static struct pcmcia_device_id sl811_ids[] = {
	PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
	PCMCIA_DEVICE_NULL,
};
MODULE_DEVICE_TABLE(pcmcia, sl811_ids);

196 197 198
static struct pcmcia_driver sl811_cs_driver = {
	.owner		= THIS_MODULE,
	.drv		= {
D
Dominik Brodowski 已提交
199
		.name	= "sl811_cs",
200
	},
201
	.probe		= sl811_cs_probe,
202
	.remove		= sl811_cs_detach,
203
	.id_table	= sl811_ids,
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
};

/*====================================================================*/

static int __init init_sl811_cs(void)
{
	return pcmcia_register_driver(&sl811_cs_driver);
}
module_init(init_sl811_cs);

static void __exit exit_sl811_cs(void)
{
	pcmcia_unregister_driver(&sl811_cs_driver);
}
module_exit(exit_sl811_cs);