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 "/*(DEBLOBBED)*/",},
36 .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
37 .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
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 "/*(DEBLOBBED)*/",},
48 .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
49 .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
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 "/*(DEBLOBBED)*/",},
60 .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
61 .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
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 "/*(DEBLOBBED)*/",},
72 .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
73 .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
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 "/*(DEBLOBBED)*/",},
84 .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
85 .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
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 "/*(DEBLOBBED)*/",},
96 .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
97 .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
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 "/*(DEBLOBBED)*/",},
108 .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
109 .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
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 "/*(DEBLOBBED)*/",},
120 .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
121 .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
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 "/*(DEBLOBBED)*/",},
132 .load = {0x0120, 0x00f600, fw_dir "/*(DEBLOBBED)*/",},
133 .app = {0x0010, 0x0d0000, fw_dir "/*(DEBLOBBED)*/",},
134 .reset = softingcs_reset,
143 static const struct softing_platform_data
144 *softingcs_find_platform_data(unsigned int manf, unsigned int prod)
146 const struct softing_platform_data *lp;
148 for (lp = softingcs_platform_data; lp->manf; ++lp) {
149 if ((lp->manf == manf) && (lp->prod == prod))
156 * platformdata callbacks
158 static int softingcs_reset(struct platform_device *pdev, int v)
160 struct pcmcia_device *pcmcia = to_pcmcia_dev(pdev->dev.parent);
162 dev_dbg(&pdev->dev, "pcmcia config [2] %02x\n", v ? 0 : 0x20);
163 return pcmcia_write_config_byte(pcmcia, 2, v ? 0 : 0x20);
166 static int softingcs_enable_irq(struct platform_device *pdev, int v)
168 struct pcmcia_device *pcmcia = to_pcmcia_dev(pdev->dev.parent);
170 dev_dbg(&pdev->dev, "pcmcia config [0] %02x\n", v ? 0x60 : 0);
171 return pcmcia_write_config_byte(pcmcia, 0, v ? 0x60 : 0);
177 static int softingcs_probe_config(struct pcmcia_device *pcmcia, void *priv_data)
179 struct softing_platform_data *pdat = priv_data;
180 struct resource *pres;
184 pres = pcmcia->resource[PCMCIA_IOMEM_0];
185 if (resource_size(pres) < 0x1000)
188 pres->flags |= WIN_MEMORY_TYPE_CM | WIN_ENABLE;
189 if (pdat->generation < 2) {
190 pres->flags |= WIN_USE_WAIT | WIN_DATA_WIDTH_8;
193 pres->flags |= WIN_DATA_WIDTH_16;
195 return pcmcia_request_window(pcmcia, pres, memspeed);
198 static void softingcs_remove(struct pcmcia_device *pcmcia)
200 struct platform_device *pdev = pcmcia->priv;
203 platform_device_unregister(pdev);
204 /* release pcmcia stuff */
205 pcmcia_disable_device(pcmcia);
209 * platform_device wrapper
210 * pdev->resource has 2 entries: io & irq
212 static void softingcs_pdev_release(struct device *dev)
214 struct platform_device *pdev = to_platform_device(dev);
218 static int softingcs_probe(struct pcmcia_device *pcmcia)
221 struct platform_device *pdev;
222 const struct softing_platform_data *pdat;
223 struct resource *pres;
225 struct platform_device pdev;
226 struct resource res[2];
229 /* find matching platform_data */
230 pdat = softingcs_find_platform_data(pcmcia->manf_id, pcmcia->card_id);
234 /* setup pcmcia device */
235 pcmcia->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IOMEM |
236 CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC;
237 ret = pcmcia_loop_config(pcmcia, softingcs_probe_config, (void *)pdat);
241 ret = pcmcia_enable_device(pcmcia);
245 pres = pcmcia->resource[PCMCIA_IOMEM_0];
251 /* create softing platform device */
252 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
257 dev->pdev.resource = dev->res;
258 dev->pdev.num_resources = ARRAY_SIZE(dev->res);
259 dev->pdev.dev.release = softingcs_pdev_release;
262 pdev->dev.platform_data = (void *)pdat;
263 pdev->dev.parent = &pcmcia->dev;
266 /* platform device resources */
267 pdev->resource[0].flags = IORESOURCE_MEM;
268 pdev->resource[0].start = pres->start;
269 pdev->resource[0].end = pres->end;
271 pdev->resource[1].flags = IORESOURCE_IRQ;
272 pdev->resource[1].start = pcmcia->irq;
273 pdev->resource[1].end = pdev->resource[1].start;
275 /* platform device setup */
276 spin_lock(&softingcs_index_lock);
277 pdev->id = softingcs_index++;
278 spin_unlock(&softingcs_index_lock);
279 pdev->name = "softing";
280 dev_set_name(&pdev->dev, "softingcs.%i", pdev->id);
281 ret = platform_device_register(pdev);
283 goto platform_failed;
285 dev_info(&pcmcia->dev, "created %s\n", dev_name(&pdev->dev));
289 platform_device_put(pdev);
293 pcmcia_disable_device(pcmcia);
298 static const struct pcmcia_device_id softingcs_ids[] = {
300 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0001),
301 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0002),
302 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0004),
303 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0005),
304 /* vector, manufacturer? */
305 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0081),
306 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0084),
307 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0085),
309 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0102),
310 PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0105),
314 MODULE_DEVICE_TABLE(pcmcia, softingcs_ids);
316 static struct pcmcia_driver softingcs_driver = {
317 .owner = THIS_MODULE,
319 .id_table = softingcs_ids,
320 .probe = softingcs_probe,
321 .remove = softingcs_remove,
324 module_pcmcia_driver(softingcs_driver);
326 MODULE_DESCRIPTION("softing CANcard driver"
327 ", links PCMCIA card to softing driver");
328 MODULE_LICENSE("GPL v2");