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 | ||
00990e7c | 134 | static int sl811_cs_config_check(struct pcmcia_device *p_dev, void *priv_data) |
84e2d340 | 135 | { |
00990e7c DB |
136 | if (p_dev->config_index == 0) |
137 | return -EINVAL; | |
138 | ||
139 | return pcmcia_request_io(p_dev); | |
84e2d340 DB |
140 | } |
141 | ||
142 | ||
15b99ac1 | 143 | static int sl811_cs_config(struct pcmcia_device *link) |
c6de2b64 | 144 | { |
dd2e5a15 | 145 | struct device *parent = &link->dev; |
9b44de20 | 146 | int ret; |
c6de2b64 | 147 | |
9b44de20 | 148 | dev_dbg(&link->dev, "sl811_cs_config\n"); |
c6de2b64 | 149 | |
440eed43 | 150 | link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP | |
00990e7c | 151 | CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO; |
440eed43 | 152 | |
ad913c11 DB |
153 | if (pcmcia_loop_config(link, sl811_cs_config_check, NULL)) |
154 | goto failed; | |
c6de2b64 DB |
155 | |
156 | /* require an IRQ and two registers */ | |
9a017a91 | 157 | if (resource_size(link->resource[0]) < 2) |
ad913c11 | 158 | goto failed; |
eb14120f DB |
159 | |
160 | if (!link->irq) | |
ad913c11 | 161 | goto failed; |
c6de2b64 | 162 | |
1ac71e5a | 163 | ret = pcmcia_enable_device(link); |
9b44de20 DB |
164 | if (ret) |
165 | goto failed; | |
c6de2b64 | 166 | |
9a017a91 | 167 | if (sl811_hc_init(parent, link->resource[0]->start, link->irq) |
c6de2b64 | 168 | < 0) { |
ad913c11 DB |
169 | failed: |
170 | printk(KERN_WARNING "sl811_cs_config failed\n"); | |
c6de2b64 | 171 | sl811_cs_release(link); |
15b99ac1 | 172 | return -ENODEV; |
c6de2b64 | 173 | } |
15b99ac1 | 174 | return 0; |
c6de2b64 DB |
175 | } |
176 | ||
15b99ac1 | 177 | static int sl811_cs_probe(struct pcmcia_device *link) |
c6de2b64 DB |
178 | { |
179 | local_info_t *local; | |
c6de2b64 | 180 | |
dd00cc48 | 181 | local = kzalloc(sizeof(local_info_t), GFP_KERNEL); |
c6de2b64 | 182 | if (!local) |
f8cfa618 | 183 | return -ENOMEM; |
fba395ee | 184 | local->p_dev = link; |
c6de2b64 DB |
185 | link->priv = local; |
186 | ||
15b99ac1 | 187 | return sl811_cs_config(link); |
c6de2b64 DB |
188 | } |
189 | ||
25f8f54f | 190 | static const struct pcmcia_device_id sl811_ids[] = { |
22f3a8f5 DB |
191 | PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */ |
192 | PCMCIA_DEVICE_NULL, | |
193 | }; | |
194 | MODULE_DEVICE_TABLE(pcmcia, sl811_ids); | |
195 | ||
c6de2b64 DB |
196 | static struct pcmcia_driver sl811_cs_driver = { |
197 | .owner = THIS_MODULE, | |
2e9b981a | 198 | .name = "sl811_cs", |
15b99ac1 | 199 | .probe = sl811_cs_probe, |
cc3b4866 | 200 | .remove = sl811_cs_detach, |
22f3a8f5 | 201 | .id_table = sl811_ids, |
c6de2b64 | 202 | }; |
4c7a45fb | 203 | module_pcmcia_driver(sl811_cs_driver); |