2 * Copyright (C) 2008-2010
4 * - Kurt Van Dijck, EIA Electronics
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the version 2 of the GNU General Public License
8 * as published by the Free Software Foundation
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/slab.h>
24 #include <pcmcia/cistpl.h>
25 #include <pcmcia/ds.h>
27 #include "softing_platform.h"
29 static int softingcs_index
;
30 static spinlock_t softingcs_index_lock
;
32 static int softingcs_reset(struct platform_device
*pdev
, int v
);
33 static int softingcs_enable_irq(struct platform_device
*pdev
, int v
);
36 * platform_data descriptions
38 #define MHZ (1000*1000)
39 static const struct softing_platform_data softingcs_platform_data
[] = {
42 .manf
= 0x0168, .prod
= 0x001,
45 .freq
= 16 * MHZ
, .max_brp
= 32, .max_sjw
= 4,
47 .boot
= {0x0000, 0x000000, fw_dir
"bcard.bin",},
48 .load
= {0x0120, 0x00f600, fw_dir
"ldcard.bin",},
49 .app
= {0x0010, 0x0d0000, fw_dir
"cancard.bin",},
50 .reset
= softingcs_reset
,
51 .enable_irq
= softingcs_enable_irq
,
53 .name
= "CANcard-NEC",
54 .manf
= 0x0168, .prod
= 0x002,
57 .freq
= 16 * MHZ
, .max_brp
= 32, .max_sjw
= 4,
59 .boot
= {0x0000, 0x000000, fw_dir
"bcard.bin",},
60 .load
= {0x0120, 0x00f600, fw_dir
"ldcard.bin",},
61 .app
= {0x0010, 0x0d0000, fw_dir
"cancard.bin",},
62 .reset
= softingcs_reset
,
63 .enable_irq
= softingcs_enable_irq
,
65 .name
= "CANcard-SJA",
66 .manf
= 0x0168, .prod
= 0x004,
69 .freq
= 20 * MHZ
, .max_brp
= 32, .max_sjw
= 4,
71 .boot
= {0x0000, 0x000000, fw_dir
"bcard.bin",},
72 .load
= {0x0120, 0x00f600, fw_dir
"ldcard.bin",},
73 .app
= {0x0010, 0x0d0000, fw_dir
"cansja.bin",},
74 .reset
= softingcs_reset
,
75 .enable_irq
= softingcs_enable_irq
,
78 .manf
= 0x0168, .prod
= 0x005,
81 .freq
= 24 * MHZ
, .max_brp
= 64, .max_sjw
= 4,
83 .boot
= {0x0000, 0x000000, fw_dir
"bcard2.bin",},
84 .load
= {0x0120, 0x00f600, fw_dir
"ldcard2.bin",},
85 .app
= {0x0010, 0x0d0000, fw_dir
"cancrd2.bin",},
86 .reset
= softingcs_reset
,
89 .name
= "Vector-CANcard",
90 .manf
= 0x0168, .prod
= 0x081,
93 .freq
= 16 * MHZ
, .max_brp
= 64, .max_sjw
= 4,
95 .boot
= {0x0000, 0x000000, fw_dir
"bcard.bin",},
96 .load
= {0x0120, 0x00f600, fw_dir
"ldcard.bin",},
97 .app
= {0x0010, 0x0d0000, fw_dir
"cancard.bin",},
98 .reset
= softingcs_reset
,
99 .enable_irq
= softingcs_enable_irq
,
101 .name
= "Vector-CANcard-SJA",
102 .manf
= 0x0168, .prod
= 0x084,
105 .freq
= 20 * MHZ
, .max_brp
= 32, .max_sjw
= 4,
106 .dpram_size
= 0x0800,
107 .boot
= {0x0000, 0x000000, fw_dir
"bcard.bin",},
108 .load
= {0x0120, 0x00f600, fw_dir
"ldcard.bin",},
109 .app
= {0x0010, 0x0d0000, fw_dir
"cansja.bin",},
110 .reset
= softingcs_reset
,
111 .enable_irq
= softingcs_enable_irq
,
113 .name
= "Vector-CANcard-2",
114 .manf
= 0x0168, .prod
= 0x085,
117 .freq
= 24 * MHZ
, .max_brp
= 64, .max_sjw
= 4,
118 .dpram_size
= 0x1000,
119 .boot
= {0x0000, 0x000000, fw_dir
"bcard2.bin",},
120 .load
= {0x0120, 0x00f600, fw_dir
"ldcard2.bin",},
121 .app
= {0x0010, 0x0d0000, fw_dir
"cancrd2.bin",},
122 .reset
= softingcs_reset
,
125 .name
= "EDICcard-NEC",
126 .manf
= 0x0168, .prod
= 0x102,
129 .freq
= 16 * MHZ
, .max_brp
= 64, .max_sjw
= 4,
130 .dpram_size
= 0x0800,
131 .boot
= {0x0000, 0x000000, fw_dir
"bcard.bin",},
132 .load
= {0x0120, 0x00f600, fw_dir
"ldcard.bin",},
133 .app
= {0x0010, 0x0d0000, fw_dir
"cancard.bin",},
134 .reset
= softingcs_reset
,
135 .enable_irq
= softingcs_enable_irq
,
137 .name
= "EDICcard-2",
138 .manf
= 0x0168, .prod
= 0x105,
141 .freq
= 24 * MHZ
, .max_brp
= 64, .max_sjw
= 4,
142 .dpram_size
= 0x1000,
143 .boot
= {0x0000, 0x000000, fw_dir
"bcard2.bin",},
144 .load
= {0x0120, 0x00f600, fw_dir
"ldcard2.bin",},
145 .app
= {0x0010, 0x0d0000, fw_dir
"cancrd2.bin",},
146 .reset
= softingcs_reset
,
153 MODULE_FIRMWARE(fw_dir
"bcard.bin");
154 MODULE_FIRMWARE(fw_dir
"ldcard.bin");
155 MODULE_FIRMWARE(fw_dir
"cancard.bin");
156 MODULE_FIRMWARE(fw_dir
"cansja.bin");
158 MODULE_FIRMWARE(fw_dir
"bcard2.bin");
159 MODULE_FIRMWARE(fw_dir
"ldcard2.bin");
160 MODULE_FIRMWARE(fw_dir
"cancrd2.bin");
162 static __devinit
const struct softing_platform_data
163 *softingcs_find_platform_data(unsigned int manf
, unsigned int prod
)
165 const struct softing_platform_data
*lp
;
167 for (lp
= softingcs_platform_data
; lp
->manf
; ++lp
) {
168 if ((lp
->manf
== manf
) && (lp
->prod
== prod
))
175 * platformdata callbacks
177 static int softingcs_reset(struct platform_device
*pdev
, int v
)
179 struct pcmcia_device
*pcmcia
= to_pcmcia_dev(pdev
->dev
.parent
);
181 dev_dbg(&pdev
->dev
, "pcmcia config [2] %02x\n", v
? 0 : 0x20);
182 return pcmcia_write_config_byte(pcmcia
, 2, v
? 0 : 0x20);
185 static int softingcs_enable_irq(struct platform_device
*pdev
, int v
)
187 struct pcmcia_device
*pcmcia
= to_pcmcia_dev(pdev
->dev
.parent
);
189 dev_dbg(&pdev
->dev
, "pcmcia config [0] %02x\n", v
? 0x60 : 0);
190 return pcmcia_write_config_byte(pcmcia
, 0, v
? 0x60 : 0);
196 static __devinit
int softingcs_probe_config(struct pcmcia_device
*pcmcia
,
199 struct softing_platform_data
*pdat
= priv_data
;
200 struct resource
*pres
;
204 pres
= pcmcia
->resource
[PCMCIA_IOMEM_0
];
205 if (resource_size(pres
) < 0x1000)
208 pres
->flags
|= WIN_MEMORY_TYPE_CM
| WIN_ENABLE
;
209 if (pdat
->generation
< 2) {
210 pres
->flags
|= WIN_USE_WAIT
| WIN_DATA_WIDTH_8
;
213 pres
->flags
|= WIN_DATA_WIDTH_16
;
215 return pcmcia_request_window(pcmcia
, pres
, memspeed
);
218 static __devexit
void softingcs_remove(struct pcmcia_device
*pcmcia
)
220 struct platform_device
*pdev
= pcmcia
->priv
;
223 platform_device_unregister(pdev
);
224 /* release pcmcia stuff */
225 pcmcia_disable_device(pcmcia
);
229 * platform_device wrapper
230 * pdev->resource has 2 entries: io & irq
232 static void softingcs_pdev_release(struct device
*dev
)
234 struct platform_device
*pdev
= to_platform_device(dev
);
238 static __devinit
int softingcs_probe(struct pcmcia_device
*pcmcia
)
241 struct platform_device
*pdev
;
242 const struct softing_platform_data
*pdat
;
243 struct resource
*pres
;
245 struct platform_device pdev
;
246 struct resource res
[2];
249 /* find matching platform_data */
250 pdat
= softingcs_find_platform_data(pcmcia
->manf_id
, pcmcia
->card_id
);
254 /* setup pcmcia device */
255 pcmcia
->config_flags
|= CONF_ENABLE_IRQ
| CONF_AUTO_SET_IOMEM
|
256 CONF_AUTO_SET_VPP
| CONF_AUTO_CHECK_VCC
;
257 ret
= pcmcia_loop_config(pcmcia
, softingcs_probe_config
, (void *)pdat
);
261 ret
= pcmcia_enable_device(pcmcia
);
265 pres
= pcmcia
->resource
[PCMCIA_IOMEM_0
];
271 /* create softing platform device */
272 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
277 dev
->pdev
.resource
= dev
->res
;
278 dev
->pdev
.num_resources
= ARRAY_SIZE(dev
->res
);
279 dev
->pdev
.dev
.release
= softingcs_pdev_release
;
282 pdev
->dev
.platform_data
= (void *)pdat
;
283 pdev
->dev
.parent
= &pcmcia
->dev
;
286 /* platform device resources */
287 pdev
->resource
[0].flags
= IORESOURCE_MEM
;
288 pdev
->resource
[0].start
= pres
->start
;
289 pdev
->resource
[0].end
= pres
->end
;
291 pdev
->resource
[1].flags
= IORESOURCE_IRQ
;
292 pdev
->resource
[1].start
= pcmcia
->irq
;
293 pdev
->resource
[1].end
= pdev
->resource
[1].start
;
295 /* platform device setup */
296 spin_lock(&softingcs_index_lock
);
297 pdev
->id
= softingcs_index
++;
298 spin_unlock(&softingcs_index_lock
);
299 pdev
->name
= "softing";
300 dev_set_name(&pdev
->dev
, "softingcs.%i", pdev
->id
);
301 ret
= platform_device_register(pdev
);
303 goto platform_failed
;
305 dev_info(&pcmcia
->dev
, "created %s\n", dev_name(&pdev
->dev
));
313 pcmcia_disable_device(pcmcia
);
315 return ret
?: -ENODEV
;
318 static const struct pcmcia_device_id softingcs_ids
[] = {
320 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0001),
321 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0002),
322 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0004),
323 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0005),
324 /* vector, manufacturer? */
325 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0081),
326 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0084),
327 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0085),
329 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0102),
330 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0105),
334 MODULE_DEVICE_TABLE(pcmcia
, softingcs_ids
);
336 static struct pcmcia_driver softingcs_driver
= {
337 .owner
= THIS_MODULE
,
339 .id_table
= softingcs_ids
,
340 .probe
= softingcs_probe
,
341 .remove
= __devexit_p(softingcs_remove
),
344 static int __init
softingcs_start(void)
346 spin_lock_init(&softingcs_index_lock
);
347 return pcmcia_register_driver(&softingcs_driver
);
350 static void __exit
softingcs_stop(void)
352 pcmcia_unregister_driver(&softingcs_driver
);
355 module_init(softingcs_start
);
356 module_exit(softingcs_stop
);
358 MODULE_DESCRIPTION("softing CANcard driver"
359 ", links PCMCIA card to softing driver");
360 MODULE_LICENSE("GPL v2");