Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/*
2 * PCMCIA driver for SL811HS (as found in REX-CFU1U)
3 * Filename: sl811_cs.c
4 * Author: Yukio Yamamoto
5 *
6 * Port to sl811-hcd and 2.6.x by
7 * Botond Botyanszki <boti@rocketmail.com>
8 * Simon Pickering
9 *
10 * Last update: 2005-05-12
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/ptrace.h>
17#include <linux/slab.h>
18#include <linux/string.h>
19#include <linux/timer.h>
20#include <linux/ioport.h>
21#include <linux/platform_device.h>
22
23#include <pcmcia/cs_types.h>
24#include <pcmcia/cs.h>
25#include <pcmcia/cistpl.h>
26#include <pcmcia/cisreg.h>
27#include <pcmcia/ds.h>
28
29#include <linux/usb/sl811.h>
30
31MODULE_AUTHOR("Botond Botyanszki");
32MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6");
33MODULE_LICENSE("GPL");
34
35
36/*====================================================================*/
37/* MACROS */
38/*====================================================================*/
39
40#define INFO(args...) printk(KERN_INFO "sl811_cs: " args)
41
42/*====================================================================*/
43/* VARIABLES */
44/*====================================================================*/
45
46static const char driver_name[DEV_NAME_LEN] = "sl811_cs";
47
48typedef struct local_info_t {
49 struct pcmcia_device *p_dev;
50 dev_node_t node;
51} local_info_t;
52
53static void sl811_cs_release(struct pcmcia_device * link);
54
55/*====================================================================*/
56
57static void release_platform_dev(struct device * dev)
58{
59 dev_dbg(dev, "sl811_cs platform_dev release\n");
60 dev->parent = NULL;
61}
62
63static struct sl811_platform_data platform_data = {
64 .potpg = 100,
65 .power = 50, /* == 100mA */
66 // .reset = ... FIXME: invoke CF reset on the card
67};
68
69static struct resource resources[] = {
70 [0] = {
71 .flags = IORESOURCE_IRQ,
72 },
73 [1] = {
74 // .name = "address",
75 .flags = IORESOURCE_IO,
76 },
77 [2] = {
78 // .name = "data",
79 .flags = IORESOURCE_IO,
80 },
81};
82
83extern struct platform_driver sl811h_driver;
84
85static struct platform_device platform_dev = {
86 .id = -1,
87 .dev = {
88 .platform_data = &platform_data,
89 .release = release_platform_dev,
90 },
91 .resource = resources,
92 .num_resources = ARRAY_SIZE(resources),
93};
94
95static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
96 int irq)
97{
98 if (platform_dev.dev.parent)
99 return -EBUSY;
100 platform_dev.dev.parent = parent;
101
102 /* finish seting up the platform device */
103 resources[0].start = irq;
104
105 resources[1].start = base_addr;
106 resources[1].end = base_addr;
107
108 resources[2].start = base_addr + 1;
109 resources[2].end = base_addr + 1;
110
111 /* The driver core will probe for us. We know sl811-hcd has been
112 * initialized already because of the link order dependency created
113 * by referencing "sl811h_driver".
114 */
115 platform_dev.name = sl811h_driver.driver.name;
116 return platform_device_register(&platform_dev);
117}
118
119/*====================================================================*/
120
121static void sl811_cs_detach(struct pcmcia_device *link)
122{
123 dev_dbg(&link->dev, "sl811_cs_detach\n");
124
125 sl811_cs_release(link);
126
127 /* This points to the parent local_info_t struct */
128 kfree(link->priv);
129}
130
131static void sl811_cs_release(struct pcmcia_device * link)
132{
133 dev_dbg(&link->dev, "sl811_cs_release\n");
134
135 pcmcia_disable_device(link);
136 platform_device_unregister(&platform_dev);
137}
138
139static int sl811_cs_config_check(struct pcmcia_device *p_dev,
140 cistpl_cftable_entry_t *cfg,
141 cistpl_cftable_entry_t *dflt,
142 unsigned int vcc,
143 void *priv_data)
144{
145 if (cfg->index == 0)
146 return -ENODEV;
147
148 /* Use power settings for Vcc and Vpp if present */
149 /* Note that the CIS values need to be rescaled */
150 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
151 if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
152 return -ENODEV;
153 } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
154 if (dflt->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
155 return -ENODEV;
156 }
157
158 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
159 p_dev->conf.Vpp =
160 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
161 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
162 p_dev->conf.Vpp =
163 dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
164
165 /* we need an interrupt */
166 if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
167 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
168
169 /* IO window settings */
170 p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
171 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
172 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
173
174 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
175 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
176 p_dev->io.BasePort1 = io->win[0].base;
177 p_dev->io.NumPorts1 = io->win[0].len;
178
179 return pcmcia_request_io(p_dev, &p_dev->io);
180 }
181 pcmcia_disable_device(p_dev);
182 return -ENODEV;
183}
184
185
186static int sl811_cs_config(struct pcmcia_device *link)
187{
188 struct device *parent = &link->dev;
189 local_info_t *dev = link->priv;
190 int ret;
191
192 dev_dbg(&link->dev, "sl811_cs_config\n");
193
194 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
195 goto failed;
196
197 /* require an IRQ and two registers */
198 if (!link->io.NumPorts1 || link->io.NumPorts1 < 2)
199 goto failed;
200 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
201 ret = pcmcia_request_irq(link, &link->irq);
202 if (ret)
203 goto failed;
204 } else
205 goto failed;
206
207 ret = pcmcia_request_configuration(link, &link->conf);
208 if (ret)
209 goto failed;
210
211 sprintf(dev->node.dev_name, driver_name);
212 dev->node.major = dev->node.minor = 0;
213 link->dev_node = &dev->node;
214
215 printk(KERN_INFO "%s: index 0x%02x: ",
216 dev->node.dev_name, link->conf.ConfigIndex);
217 if (link->conf.Vpp)
218 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
219 printk(", irq %d", link->irq.AssignedIRQ);
220 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
221 link->io.BasePort1+link->io.NumPorts1-1);
222 printk("\n");
223
224 if (sl811_hc_init(parent, link->io.BasePort1, link->irq.AssignedIRQ)
225 < 0) {
226failed:
227 printk(KERN_WARNING "sl811_cs_config failed\n");
228 sl811_cs_release(link);
229 return -ENODEV;
230 }
231 return 0;
232}
233
234static int sl811_cs_probe(struct pcmcia_device *link)
235{
236 local_info_t *local;
237
238 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
239 if (!local)
240 return -ENOMEM;
241 local->p_dev = link;
242 link->priv = local;
243
244 /* Initialize */
245 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
246 link->irq.Handler = NULL;
247
248 link->conf.Attributes = 0;
249 link->conf.IntType = INT_MEMORY_AND_IO;
250
251 return sl811_cs_config(link);
252}
253
254static struct pcmcia_device_id sl811_ids[] = {
255 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
256 PCMCIA_DEVICE_NULL,
257};
258MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
259
260static struct pcmcia_driver sl811_cs_driver = {
261 .owner = THIS_MODULE,
262 .drv = {
263 .name = (char *)driver_name,
264 },
265 .probe = sl811_cs_probe,
266 .remove = sl811_cs_detach,
267 .id_table = sl811_ids,
268};
269
270/*====================================================================*/
271
272static int __init init_sl811_cs(void)
273{
274 return pcmcia_register_driver(&sl811_cs_driver);
275}
276module_init(init_sl811_cs);
277
278static void __exit exit_sl811_cs(void)
279{
280 pcmcia_unregister_driver(&sl811_cs_driver);
281}
282module_exit(exit_sl811_cs);