1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2008-2010
5 * - Kurt Van Dijck, EIA Electronics
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/slab.h>
12 #include <pcmcia/cistpl.h>
13 #include <pcmcia/ds.h>
15 #include "softing_platform.h"
17 static int softingcs_index;
18 static DEFINE_SPINLOCK(softingcs_index_lock);
20 static int softingcs_reset(struct platform_device *pdev, int v);
21 static int softingcs_enable_irq(struct platform_device *pdev, int v);
24 * platform_data descriptions
26 #define MHZ (1000*1000)
27 static const struct softing_platform_data softingcs_platform_data[] = {
30 .manf = 0x0168, .prod = 0x001,
33 .freq = 16 * MHZ, .max_brp = 32, .max_sjw = 4,
35 .boot = {0x0000, 0x000000, fw_dir "bcard.bin",},
36 .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",},
37 .app = {0x0010, 0x0d0000, fw_dir "cancard.bin",},
38 .reset = softingcs_reset,
39 .enable_irq = softingcs_enable_irq,
41 .name = "CANcard-NEC",
42 .manf = 0x0168, .prod = 0x002,
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-SJA",
54 .manf = 0x0168, .prod = 0x004,
57 .freq = 20 * 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 "cansja.bin",},
62 .reset = softingcs_reset,
63 .enable_irq = softingcs_enable_irq,
66 .manf = 0x0168, .prod = 0x005,
69 .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4,
71 .boot = {0x0000, 0x000000, fw_dir "bcard2.bin",},
72 .load = {0x0120, 0x00f600, fw_dir "ldcard2.bin",},
73 .app = {0x0010, 0x0d0000, fw_dir "cancrd2.bin",},
74 .reset = softingcs_reset,
77 .name = "Vector-CANcard",
78 .manf = 0x0168, .prod = 0x081,
81 .freq = 16 * MHZ, .max_brp = 64, .max_sjw = 4,
83 .boot = {0x0000, 0x000000, fw_dir "bcard.bin",},
84 .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",},
85 .app = {0x0010, 0x0d0000, fw_dir "cancard.bin",},
86 .reset = softingcs_reset,
87 .enable_irq = softingcs_enable_irq,
89 .name = "Vector-CANcard-SJA",
90 .manf = 0x0168, .prod = 0x084,
93 .freq = 20 * MHZ, .max_brp = 32, .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 "cansja.bin",},
98 .reset = softingcs_reset,
99 .enable_irq = softingcs_enable_irq,
101 .name = "Vector-CANcard-2",
102 .manf = 0x0168, .prod = 0x085,
105 .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4,
106 .dpram_size = 0x1000,
107 .boot = {0x0000, 0x000000, fw_dir "bcard2.bin",},
108 .load = {0x0120, 0x00f600, fw_dir "ldcard2.bin",},
109 .app = {0x0010, 0x0d0000, fw_dir "cancrd2.bin",},
110 .reset = softingcs_reset,
113 .name = "EDICcard-NEC",
114 .manf = 0x0168, .prod = 0x102,
117 .freq = 16 * MHZ, .max_brp = 64, .max_sjw = 4,
118 .dpram_size = 0x0800,
119 .boot = {0x0000, 0x000000, fw_dir "bcard.bin",},
120 .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",},
121 .app = {0x0010, 0x0d0000, fw_dir "cancard.bin",},
122 .reset = softingcs_reset,
123 .enable_irq = softingcs_enable_irq,
125 .name = "EDICcard-2",
126 .manf = 0x0168, .prod = 0x105,
129 .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4,
130 .dpram_size = 0x1000,
131 .boot = {0x0000, 0x000000, fw_dir "bcard2.bin",},
132 .load = {0x0120, 0x00f600, fw_dir "ldcard2.bin",},
133 .app = {0x0010, 0x0d0000, fw_dir "cancrd2.bin",},
134 .reset = softingcs_reset,
141 MODULE_FIRMWARE(fw_dir "bcard.bin");
142 MODULE_FIRMWARE(fw_dir "ldcard.bin");
143 MODULE_FIRMWARE(fw_dir "cancard.bin");
144 MODULE_FIRMWARE(fw_dir "cansja.bin");
146 MODULE_FIRMWARE(fw_dir "bcard2.bin");
147 MODULE_FIRMWARE(fw_dir "ldcard2.bin");
148 MODULE_FIRMWARE(fw_dir "cancrd2.bin");
150 static const struct softing_platform_data
151 *softingcs_find_platform_data(unsigned int manf, unsigned int prod)
153 const struct softing_platform_data *lp;
155 for (lp = softingcs_platform_data; lp->manf; ++lp) {
156 if ((lp->manf == manf) && (lp->prod == prod))
163 * platformdata callbacks
165 static int softingcs_reset(struct platform_device *pdev, int v)
167 struct pcmcia_device *pcmcia = to_pcmcia_dev(pdev->dev.parent);
169 dev_dbg(&pdev->dev, "pcmcia config [2] %02x\n", v ? 0 : 0x20);
170 return pcmcia_write_config_byte(pcmcia, 2, v ? 0 : 0x20);
173 static int softingcs_enable_irq(struct platform_device *pdev, int v)
175 struct pcmcia_device *pcmcia = to_pcmcia_dev(pdev->dev.parent);
177 dev_dbg(&pdev->dev, "pcmcia config [0] %02x\n", v ? 0x60 : 0);
178 return pcmcia_write_config_byte(pcmcia, 0, v ? 0x60 : 0);
184 static int softingcs_probe_config(struct pcmcia_device *pcmcia, void *priv_data)
186 struct softing_platform_data *pdat = priv_data;
187 struct resource *pres;
191 pres = pcmcia->resource[PCMCIA_IOMEM_0];
192 if (resource_size(pres) < 0x1000)
195 pres->flags |= WIN_MEMORY_TYPE_CM | WIN_ENABLE;
196 if (pdat->generation < 2) {
197 pres->flags |= WIN_USE_WAIT | WIN_DATA_WIDTH_8;
200 pres->flags |= WIN_DATA_WIDTH_16;
202 return pcmcia_request_window(pcmcia, pres, memspeed);
205 static void softingcs_remove(struct pcmcia_device *pcmcia)
207 struct platform_device *pdev = pcmcia->priv;
210 platform_device_unregister(pdev);
211 /* release pcmcia stuff */
212 pcmcia_disable_device(pcmcia);
216 * platform_device wrapper
217 * pdev->resource has 2 entries: io & irq
219 static void softingcs_pdev_release(struct device *dev)
221 struct platform_device *pdev = to_platform_device(dev);
225 static int softingcs_probe(struct pcmcia_device *pcmcia)
228 struct platform_device *pdev;
229 const struct softing_platform_data *pdat;
230 struct resource *pres;
232 struct platform_device pdev;
233 struct resource res[2];
236 /* find matching platform_data */
237 pdat = softingcs_find_platform_data(pcmcia->manf_id, pcmcia->card_id);
241 /* setup pcmcia device */
242 pcmcia->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IOMEM |
243 CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC;
244 ret = pcmcia_loop_config(pcmcia, softingcs_probe_config, (void *)pdat);
248 ret = pcmcia_enable_device(pcmcia);
252 pres = pcmcia->resource[PCMCIA_IOMEM_0];
258 /* create softing platform device */
259 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
264 dev->pdev.resource = dev->res;
265 dev->pdev.num_resources = ARRAY_SIZE(dev->res);
266 dev->pdev.dev.release = softingcs_pdev_release;
269 pdev->dev.platform_data = (void *)pdat;
270 pdev->dev.parent = &pcmcia->dev;
273 /* platform device resources */
274 pdev->resource[0].flags = IORESOURCE_MEM;
275 pdev->resource[0].start = pres->start;
276 pdev->resource[0].end = pres->end;
278 pdev->resource[1].flags = IORESOURCE_IRQ;
279 pdev->resource[1].start = pcmcia->irq;
280 pdev->resource[1].end = pdev->resource[1].start;
282 /* platform device setup */
283 spin_lock(&softingcs_index_lock);
284 pdev->id = softingcs_index++;
285 spin_unlock(&softingcs_index_lock);
286 pdev->name = "softing";
287 dev_set_name(&pdev->dev, "softingcs.%i", pdev->id);
288 ret = platform_device_register(pdev);
290 goto platform_failed;
292 dev_info(&pcmcia->dev, "created %s\n", dev_name(&pdev->dev));
300 pcmcia_disable_device(pcmcia);
305 static const struct pcmcia_device_id softingcs_ids[] = {
307 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0001),
308 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0002),
309 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0004),
310 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0005),
311 /* vector, manufacturer? */
312 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0081),
313 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0084),
314 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0085),
316 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0102),
317 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0105),
321 MODULE_DEVICE_TABLE(pcmcia, softingcs_ids);
323 static struct pcmcia_driver softingcs_driver = {
324 .owner = THIS_MODULE,
326 .id_table = softingcs_ids,
327 .probe = softingcs_probe,
328 .remove = softingcs_remove,
331 module_pcmcia_driver(softingcs_driver);
333 MODULE_DESCRIPTION("softing CANcard driver"
334 ", links PCMCIA card to softing driver");
335 MODULE_LICENSE("GPL v2");