]>
Commit | Line | Data |
---|---|---|
c6de2b64 DB |
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> | |
c6de2b64 DB |
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> | |
d052d1be | 21 | #include <linux/platform_device.h> |
c6de2b64 | 22 | |
c6de2b64 DB |
23 | #include <pcmcia/cistpl.h> |
24 | #include <pcmcia/cisreg.h> | |
25 | #include <pcmcia/ds.h> | |
26 | ||
325a4af6 | 27 | #include <linux/usb/sl811.h> |
c6de2b64 DB |
28 | |
29 | MODULE_AUTHOR("Botond Botyanszki"); | |
30 | MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6"); | |
31 | MODULE_LICENSE("GPL"); | |
32 | ||
33 | ||
34 | /*====================================================================*/ | |
35 | /* MACROS */ | |
36 | /*====================================================================*/ | |
37 | ||
c6de2b64 DB |
38 | #define INFO(args...) printk(KERN_INFO "sl811_cs: " args) |
39 | ||
c6de2b64 DB |
40 | /*====================================================================*/ |
41 | /* VARIABLES */ | |
42 | /*====================================================================*/ | |
43 | ||
c6de2b64 | 44 | typedef struct local_info_t { |
fd238232 | 45 | struct pcmcia_device *p_dev; |
c6de2b64 DB |
46 | } local_info_t; |
47 | ||
fba395ee | 48 | static void sl811_cs_release(struct pcmcia_device * link); |
cc3b4866 | 49 | |
c6de2b64 DB |
50 | /*====================================================================*/ |
51 | ||
52 | static void release_platform_dev(struct device * dev) | |
53 | { | |
9b44de20 | 54 | dev_dbg(dev, "sl811_cs platform_dev release\n"); |
c6de2b64 DB |
55 | dev->parent = NULL; |
56 | } | |
57 | ||
58 | static struct sl811_platform_data platform_data = { | |
59 | .potpg = 100, | |
60 | .power = 50, /* == 100mA */ | |
61 | // .reset = ... FIXME: invoke CF reset on the card | |
62 | }; | |
63 | ||
64 | static struct resource resources[] = { | |
65 | [0] = { | |
66 | .flags = IORESOURCE_IRQ, | |
67 | }, | |
68 | [1] = { | |
69 | // .name = "address", | |
70 | .flags = IORESOURCE_IO, | |
71 | }, | |
72 | [2] = { | |
73 | // .name = "data", | |
74 | .flags = IORESOURCE_IO, | |
75 | }, | |
76 | }; | |
77 | ||
a0c53f1d | 78 | extern struct platform_driver sl811h_driver; |
c6de2b64 DB |
79 | |
80 | static struct platform_device platform_dev = { | |
81 | .id = -1, | |
82 | .dev = { | |
83 | .platform_data = &platform_data, | |
84 | .release = release_platform_dev, | |
85 | }, | |
86 | .resource = resources, | |
87 | .num_resources = ARRAY_SIZE(resources), | |
88 | }; | |
89 | ||
d39bd564 DB |
90 | static int sl811_hc_init(struct device *parent, resource_size_t base_addr, |
91 | int irq) | |
c6de2b64 DB |
92 | { |
93 | if (platform_dev.dev.parent) | |
94 | return -EBUSY; | |
95 | platform_dev.dev.parent = parent; | |
96 | ||
97 | /* finish seting up the platform device */ | |
98 | resources[0].start = irq; | |
99 | ||
100 | resources[1].start = base_addr; | |
101 | resources[1].end = base_addr; | |
102 | ||
103 | resources[2].start = base_addr + 1; | |
104 | resources[2].end = base_addr + 1; | |
105 | ||
106 | /* The driver core will probe for us. We know sl811-hcd has been | |
c9a50cc9 DB |
107 | * initialized already because of the link order dependency created |
108 | * by referencing "sl811h_driver". | |
c6de2b64 | 109 | */ |
a0c53f1d | 110 | platform_dev.name = sl811h_driver.driver.name; |
c6de2b64 DB |
111 | return platform_device_register(&platform_dev); |
112 | } | |
113 | ||
114 | /*====================================================================*/ | |
115 | ||
fba395ee | 116 | static void sl811_cs_detach(struct pcmcia_device *link) |
c6de2b64 | 117 | { |
9b44de20 | 118 | dev_dbg(&link->dev, "sl811_cs_detach\n"); |
c6de2b64 | 119 | |
e2d40963 | 120 | sl811_cs_release(link); |
c6de2b64 | 121 | |
c6de2b64 DB |
122 | /* This points to the parent local_info_t struct */ |
123 | kfree(link->priv); | |
124 | } | |
125 | ||
fba395ee | 126 | static void sl811_cs_release(struct pcmcia_device * link) |
c6de2b64 | 127 | { |
9b44de20 | 128 | dev_dbg(&link->dev, "sl811_cs_release\n"); |
c6de2b64 | 129 | |
fba395ee | 130 | pcmcia_disable_device(link); |
c6de2b64 | 131 | platform_device_unregister(&platform_dev); |
c6de2b64 DB |
132 | } |
133 | ||
84e2d340 DB |
134 | static int sl811_cs_config_check(struct pcmcia_device *p_dev, |
135 | cistpl_cftable_entry_t *cfg, | |
8e2fc39d | 136 | cistpl_cftable_entry_t *dflt, |
ad913c11 | 137 | unsigned int vcc, |
84e2d340 DB |
138 | void *priv_data) |
139 | { | |
84e2d340 DB |
140 | if (cfg->index == 0) |
141 | return -ENODEV; | |
142 | ||
84e2d340 DB |
143 | /* Use power settings for Vcc and Vpp if present */ |
144 | /* Note that the CIS values need to be rescaled */ | |
145 | if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) { | |
ad913c11 | 146 | if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc) |
84e2d340 | 147 | return -ENODEV; |
8e2fc39d | 148 | } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) { |
ad913c11 | 149 | if (dflt->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc) |
84e2d340 DB |
150 | return -ENODEV; |
151 | } | |
152 | ||
153 | if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) | |
e8405f0f | 154 | p_dev->vpp = |
84e2d340 | 155 | cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; |
8e2fc39d | 156 | else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM)) |
e8405f0f | 157 | p_dev->vpp = |
8e2fc39d | 158 | dflt->vpp1.param[CISTPL_POWER_VNOM]/10000; |
84e2d340 DB |
159 | |
160 | /* we need an interrupt */ | |
1ac71e5a | 161 | p_dev->config_flags |= CONF_ENABLE_IRQ; |
84e2d340 DB |
162 | |
163 | /* IO window settings */ | |
90abdc3b | 164 | p_dev->resource[0]->end = p_dev->resource[1]->end = 0; |
8e2fc39d DB |
165 | if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) { |
166 | cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io; | |
90abdc3b | 167 | p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK; |
84e2d340 | 168 | |
90abdc3b DB |
169 | p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; |
170 | p_dev->resource[0]->start = io->win[0].base; | |
171 | p_dev->resource[0]->end = io->win[0].len; | |
84e2d340 | 172 | |
90abdc3b | 173 | return pcmcia_request_io(p_dev); |
84e2d340 DB |
174 | } |
175 | pcmcia_disable_device(p_dev); | |
176 | return -ENODEV; | |
177 | } | |
178 | ||
179 | ||
15b99ac1 | 180 | static int sl811_cs_config(struct pcmcia_device *link) |
c6de2b64 | 181 | { |
dd2e5a15 | 182 | struct device *parent = &link->dev; |
9b44de20 | 183 | int ret; |
c6de2b64 | 184 | |
9b44de20 | 185 | dev_dbg(&link->dev, "sl811_cs_config\n"); |
c6de2b64 | 186 | |
ad913c11 DB |
187 | if (pcmcia_loop_config(link, sl811_cs_config_check, NULL)) |
188 | goto failed; | |
c6de2b64 DB |
189 | |
190 | /* require an IRQ and two registers */ | |
9a017a91 | 191 | if (resource_size(link->resource[0]) < 2) |
ad913c11 | 192 | goto failed; |
eb14120f DB |
193 | |
194 | if (!link->irq) | |
ad913c11 | 195 | goto failed; |
c6de2b64 | 196 | |
1ac71e5a | 197 | ret = pcmcia_enable_device(link); |
9b44de20 DB |
198 | if (ret) |
199 | goto failed; | |
c6de2b64 | 200 | |
ded6a1a3 | 201 | dev_info(&link->dev, "index 0x%02x: ", |
7feabb64 | 202 | link->config_index); |
e8405f0f DB |
203 | if (link->vpp) |
204 | printk(", Vpp %d.%d", link->vpp/10, link->vpp%10); | |
eb14120f | 205 | printk(", irq %d", link->irq); |
9a017a91 | 206 | printk(", io %pR", link->resource[0]); |
c6de2b64 DB |
207 | printk("\n"); |
208 | ||
9a017a91 | 209 | if (sl811_hc_init(parent, link->resource[0]->start, link->irq) |
c6de2b64 | 210 | < 0) { |
ad913c11 DB |
211 | failed: |
212 | printk(KERN_WARNING "sl811_cs_config failed\n"); | |
c6de2b64 | 213 | sl811_cs_release(link); |
15b99ac1 | 214 | return -ENODEV; |
c6de2b64 | 215 | } |
15b99ac1 | 216 | return 0; |
c6de2b64 DB |
217 | } |
218 | ||
15b99ac1 | 219 | static int sl811_cs_probe(struct pcmcia_device *link) |
c6de2b64 DB |
220 | { |
221 | local_info_t *local; | |
c6de2b64 | 222 | |
dd00cc48 | 223 | local = kzalloc(sizeof(local_info_t), GFP_KERNEL); |
c6de2b64 | 224 | if (!local) |
f8cfa618 | 225 | return -ENOMEM; |
fba395ee | 226 | local->p_dev = link; |
c6de2b64 DB |
227 | link->priv = local; |
228 | ||
15b99ac1 | 229 | return sl811_cs_config(link); |
c6de2b64 DB |
230 | } |
231 | ||
22f3a8f5 DB |
232 | static struct pcmcia_device_id sl811_ids[] = { |
233 | PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */ | |
234 | PCMCIA_DEVICE_NULL, | |
235 | }; | |
236 | MODULE_DEVICE_TABLE(pcmcia, sl811_ids); | |
237 | ||
c6de2b64 DB |
238 | static struct pcmcia_driver sl811_cs_driver = { |
239 | .owner = THIS_MODULE, | |
240 | .drv = { | |
ac8b4228 | 241 | .name = "sl811_cs", |
c6de2b64 | 242 | }, |
15b99ac1 | 243 | .probe = sl811_cs_probe, |
cc3b4866 | 244 | .remove = sl811_cs_detach, |
22f3a8f5 | 245 | .id_table = sl811_ids, |
c6de2b64 DB |
246 | }; |
247 | ||
248 | /*====================================================================*/ | |
249 | ||
250 | static int __init init_sl811_cs(void) | |
251 | { | |
252 | return pcmcia_register_driver(&sl811_cs_driver); | |
253 | } | |
254 | module_init(init_sl811_cs); | |
255 | ||
256 | static void __exit exit_sl811_cs(void) | |
257 | { | |
258 | pcmcia_unregister_driver(&sl811_cs_driver); | |
259 | } | |
260 | module_exit(exit_sl811_cs); |