Merge commit 'v2.6.35-rc1' into amd-iommu/2.6.35
[deliverable/linux.git] / drivers / usb / host / sl811_cs.c
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
31 MODULE_AUTHOR("Botond Botyanszki");
32 MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6");
33 MODULE_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
46 static const char driver_name[DEV_NAME_LEN] = "sl811_cs";
47
48 typedef struct local_info_t {
49 struct pcmcia_device *p_dev;
50 } local_info_t;
51
52 static void sl811_cs_release(struct pcmcia_device * link);
53
54 /*====================================================================*/
55
56 static void release_platform_dev(struct device * dev)
57 {
58 dev_dbg(dev, "sl811_cs platform_dev release\n");
59 dev->parent = NULL;
60 }
61
62 static struct sl811_platform_data platform_data = {
63 .potpg = 100,
64 .power = 50, /* == 100mA */
65 // .reset = ... FIXME: invoke CF reset on the card
66 };
67
68 static struct resource resources[] = {
69 [0] = {
70 .flags = IORESOURCE_IRQ,
71 },
72 [1] = {
73 // .name = "address",
74 .flags = IORESOURCE_IO,
75 },
76 [2] = {
77 // .name = "data",
78 .flags = IORESOURCE_IO,
79 },
80 };
81
82 extern struct platform_driver sl811h_driver;
83
84 static struct platform_device platform_dev = {
85 .id = -1,
86 .dev = {
87 .platform_data = &platform_data,
88 .release = release_platform_dev,
89 },
90 .resource = resources,
91 .num_resources = ARRAY_SIZE(resources),
92 };
93
94 static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
95 int irq)
96 {
97 if (platform_dev.dev.parent)
98 return -EBUSY;
99 platform_dev.dev.parent = parent;
100
101 /* finish seting up the platform device */
102 resources[0].start = irq;
103
104 resources[1].start = base_addr;
105 resources[1].end = base_addr;
106
107 resources[2].start = base_addr + 1;
108 resources[2].end = base_addr + 1;
109
110 /* The driver core will probe for us. We know sl811-hcd has been
111 * initialized already because of the link order dependency created
112 * by referencing "sl811h_driver".
113 */
114 platform_dev.name = sl811h_driver.driver.name;
115 return platform_device_register(&platform_dev);
116 }
117
118 /*====================================================================*/
119
120 static void sl811_cs_detach(struct pcmcia_device *link)
121 {
122 dev_dbg(&link->dev, "sl811_cs_detach\n");
123
124 sl811_cs_release(link);
125
126 /* This points to the parent local_info_t struct */
127 kfree(link->priv);
128 }
129
130 static void sl811_cs_release(struct pcmcia_device * link)
131 {
132 dev_dbg(&link->dev, "sl811_cs_release\n");
133
134 pcmcia_disable_device(link);
135 platform_device_unregister(&platform_dev);
136 }
137
138 static int sl811_cs_config_check(struct pcmcia_device *p_dev,
139 cistpl_cftable_entry_t *cfg,
140 cistpl_cftable_entry_t *dflt,
141 unsigned int vcc,
142 void *priv_data)
143 {
144 if (cfg->index == 0)
145 return -ENODEV;
146
147 /* Use power settings for Vcc and Vpp if present */
148 /* Note that the CIS values need to be rescaled */
149 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
150 if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
151 return -ENODEV;
152 } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
153 if (dflt->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
154 return -ENODEV;
155 }
156
157 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
158 p_dev->conf.Vpp =
159 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
160 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
161 p_dev->conf.Vpp =
162 dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
163
164 /* we need an interrupt */
165 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
166
167 /* IO window settings */
168 p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
169 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
170 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
171
172 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
173 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
174 p_dev->io.BasePort1 = io->win[0].base;
175 p_dev->io.NumPorts1 = io->win[0].len;
176
177 return pcmcia_request_io(p_dev, &p_dev->io);
178 }
179 pcmcia_disable_device(p_dev);
180 return -ENODEV;
181 }
182
183
184 static int sl811_cs_config(struct pcmcia_device *link)
185 {
186 struct device *parent = &link->dev;
187 int ret;
188
189 dev_dbg(&link->dev, "sl811_cs_config\n");
190
191 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
192 goto failed;
193
194 /* require an IRQ and two registers */
195 if (!link->io.NumPorts1 || link->io.NumPorts1 < 2)
196 goto failed;
197
198 if (!link->irq)
199 goto failed;
200
201 ret = pcmcia_request_configuration(link, &link->conf);
202 if (ret)
203 goto failed;
204
205 dev_info(&link->dev, "index 0x%02x: ",
206 link->conf.ConfigIndex);
207 if (link->conf.Vpp)
208 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
209 printk(", irq %d", link->irq);
210 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
211 link->io.BasePort1+link->io.NumPorts1-1);
212 printk("\n");
213
214 if (sl811_hc_init(parent, link->io.BasePort1, link->irq)
215 < 0) {
216 failed:
217 printk(KERN_WARNING "sl811_cs_config failed\n");
218 sl811_cs_release(link);
219 return -ENODEV;
220 }
221 return 0;
222 }
223
224 static int sl811_cs_probe(struct pcmcia_device *link)
225 {
226 local_info_t *local;
227
228 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
229 if (!local)
230 return -ENOMEM;
231 local->p_dev = link;
232 link->priv = local;
233
234 link->conf.Attributes = 0;
235 link->conf.IntType = INT_MEMORY_AND_IO;
236
237 return sl811_cs_config(link);
238 }
239
240 static struct pcmcia_device_id sl811_ids[] = {
241 PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
242 PCMCIA_DEVICE_NULL,
243 };
244 MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
245
246 static struct pcmcia_driver sl811_cs_driver = {
247 .owner = THIS_MODULE,
248 .drv = {
249 .name = (char *)driver_name,
250 },
251 .probe = sl811_cs_probe,
252 .remove = sl811_cs_detach,
253 .id_table = sl811_ids,
254 };
255
256 /*====================================================================*/
257
258 static int __init init_sl811_cs(void)
259 {
260 return pcmcia_register_driver(&sl811_cs_driver);
261 }
262 module_init(init_sl811_cs);
263
264 static void __exit exit_sl811_cs(void)
265 {
266 pcmcia_unregister_driver(&sl811_cs_driver);
267 }
268 module_exit(exit_sl811_cs);
This page took 0.047649 seconds and 5 git commands to generate.