diff options
| -rw-r--r-- | drivers/net/can/softing/Kconfig | 14 | ||||
| -rw-r--r-- | drivers/net/can/softing/Makefile | 1 | ||||
| -rw-r--r-- | drivers/net/can/softing/softing_cs.c | 359 |
3 files changed, 374 insertions, 0 deletions
diff --git a/drivers/net/can/softing/Kconfig b/drivers/net/can/softing/Kconfig index 072f337f42e3..92bd6bdde5e3 100644 --- a/drivers/net/can/softing/Kconfig +++ b/drivers/net/can/softing/Kconfig | |||
| @@ -14,3 +14,17 @@ config CAN_SOFTING | |||
| 14 | controls the 2 busses on the card together. | 14 | controls the 2 busses on the card together. |
| 15 | As such, some actions (start/stop/busoff recovery) on 1 bus | 15 | As such, some actions (start/stop/busoff recovery) on 1 bus |
| 16 | must bring down the other bus too temporarily. | 16 | must bring down the other bus too temporarily. |
| 17 | |||
| 18 | config CAN_SOFTING_CS | ||
| 19 | tristate "Softing Gmbh CAN pcmcia cards" | ||
| 20 | depends on PCMCIA | ||
| 21 | select CAN_SOFTING | ||
| 22 | ---help--- | ||
| 23 | Support for PCMCIA cards from Softing Gmbh & some cards | ||
| 24 | from Vector Gmbh. | ||
| 25 | You need firmware for these, which you can get at | ||
| 26 | http://developer.berlios.de/projects/socketcan/ | ||
| 27 | This version of the driver is written against | ||
| 28 | firmware version 4.6 (softing-fw-4.6-binaries.tar.gz) | ||
| 29 | In order to use the card as CAN device, you need the Softing generic | ||
| 30 | support too. | ||
diff --git a/drivers/net/can/softing/Makefile b/drivers/net/can/softing/Makefile index 7db04452deb6..c5e5016c742e 100644 --- a/drivers/net/can/softing/Makefile +++ b/drivers/net/can/softing/Makefile | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | 1 | ||
| 2 | softing-y := softing_main.o softing_fw.o | 2 | softing-y := softing_main.o softing_fw.o |
| 3 | obj-$(CONFIG_CAN_SOFTING) += softing.o | 3 | obj-$(CONFIG_CAN_SOFTING) += softing.o |
| 4 | obj-$(CONFIG_CAN_SOFTING_CS) += softing_cs.o | ||
| 4 | 5 | ||
| 5 | ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG | 6 | ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG |
diff --git a/drivers/net/can/softing/softing_cs.c b/drivers/net/can/softing/softing_cs.c new file mode 100644 index 000000000000..300fe75dd1a7 --- /dev/null +++ b/drivers/net/can/softing/softing_cs.c | |||
| @@ -0,0 +1,359 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2008-2010 | ||
| 3 | * | ||
| 4 | * - Kurt Van Dijck, EIA Electronics | ||
| 5 | * | ||
| 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 | ||
| 9 | * | ||
| 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. | ||
| 14 | * | ||
| 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 | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <linux/module.h> | ||
| 21 | #include <linux/kernel.h> | ||
| 22 | |||
| 23 | #include <pcmcia/cistpl.h> | ||
| 24 | #include <pcmcia/ds.h> | ||
| 25 | |||
| 26 | #include "softing_platform.h" | ||
| 27 | |||
| 28 | static int softingcs_index; | ||
| 29 | static spinlock_t softingcs_index_lock; | ||
| 30 | |||
| 31 | static int softingcs_reset(struct platform_device *pdev, int v); | ||
| 32 | static int softingcs_enable_irq(struct platform_device *pdev, int v); | ||
| 33 | |||
| 34 | /* | ||
| 35 | * platform_data descriptions | ||
| 36 | */ | ||
| 37 | #define MHZ (1000*1000) | ||
| 38 | static const struct softing_platform_data softingcs_platform_data[] = { | ||
| 39 | { | ||
| 40 | .name = "CANcard", | ||
| 41 | .manf = 0x0168, .prod = 0x001, | ||
| 42 | .generation = 1, | ||
| 43 | .nbus = 2, | ||
| 44 | .freq = 16 * MHZ, .max_brp = 32, .max_sjw = 4, | ||
| 45 | .dpram_size = 0x0800, | ||
| 46 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
| 47 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
| 48 | .app = {0x0010, 0x0d0000, fw_dir "cancard.bin",}, | ||
| 49 | .reset = softingcs_reset, | ||
| 50 | .enable_irq = softingcs_enable_irq, | ||
| 51 | }, { | ||
| 52 | .name = "CANcard-NEC", | ||
| 53 | .manf = 0x0168, .prod = 0x002, | ||
| 54 | .generation = 1, | ||
| 55 | .nbus = 2, | ||
| 56 | .freq = 16 * MHZ, .max_brp = 32, .max_sjw = 4, | ||
| 57 | .dpram_size = 0x0800, | ||
| 58 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
| 59 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
| 60 | .app = {0x0010, 0x0d0000, fw_dir "cancard.bin",}, | ||
| 61 | .reset = softingcs_reset, | ||
| 62 | .enable_irq = softingcs_enable_irq, | ||
| 63 | }, { | ||
| 64 | .name = "CANcard-SJA", | ||
| 65 | .manf = 0x0168, .prod = 0x004, | ||
| 66 | .generation = 1, | ||
| 67 | .nbus = 2, | ||
| 68 | .freq = 20 * MHZ, .max_brp = 32, .max_sjw = 4, | ||
| 69 | .dpram_size = 0x0800, | ||
| 70 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
| 71 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
| 72 | .app = {0x0010, 0x0d0000, fw_dir "cansja.bin",}, | ||
| 73 | .reset = softingcs_reset, | ||
| 74 | .enable_irq = softingcs_enable_irq, | ||
| 75 | }, { | ||
| 76 | .name = "CANcard-2", | ||
| 77 | .manf = 0x0168, .prod = 0x005, | ||
| 78 | .generation = 2, | ||
| 79 | .nbus = 2, | ||
| 80 | .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4, | ||
| 81 | .dpram_size = 0x1000, | ||
| 82 | .boot = {0x0000, 0x000000, fw_dir "bcard2.bin",}, | ||
| 83 | .load = {0x0120, 0x00f600, fw_dir "ldcard2.bin",}, | ||
| 84 | .app = {0x0010, 0x0d0000, fw_dir "cancrd2.bin",}, | ||
| 85 | .reset = softingcs_reset, | ||
| 86 | .enable_irq = NULL, | ||
| 87 | }, { | ||
| 88 | .name = "Vector-CANcard", | ||
| 89 | .manf = 0x0168, .prod = 0x081, | ||
| 90 | .generation = 1, | ||
| 91 | .nbus = 2, | ||
| 92 | .freq = 16 * MHZ, .max_brp = 64, .max_sjw = 4, | ||
| 93 | .dpram_size = 0x0800, | ||
| 94 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
| 95 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
| 96 | .app = {0x0010, 0x0d0000, fw_dir "cancard.bin",}, | ||
| 97 | .reset = softingcs_reset, | ||
| 98 | .enable_irq = softingcs_enable_irq, | ||
| 99 | }, { | ||
| 100 | .name = "Vector-CANcard-SJA", | ||
| 101 | .manf = 0x0168, .prod = 0x084, | ||
| 102 | .generation = 1, | ||
| 103 | .nbus = 2, | ||
| 104 | .freq = 20 * MHZ, .max_brp = 32, .max_sjw = 4, | ||
| 105 | .dpram_size = 0x0800, | ||
| 106 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
| 107 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
| 108 | .app = {0x0010, 0x0d0000, fw_dir "cansja.bin",}, | ||
| 109 | .reset = softingcs_reset, | ||
| 110 | .enable_irq = softingcs_enable_irq, | ||
| 111 | }, { | ||
| 112 | .name = "Vector-CANcard-2", | ||
| 113 | .manf = 0x0168, .prod = 0x085, | ||
| 114 | .generation = 2, | ||
| 115 | .nbus = 2, | ||
| 116 | .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4, | ||
| 117 | .dpram_size = 0x1000, | ||
| 118 | .boot = {0x0000, 0x000000, fw_dir "bcard2.bin",}, | ||
| 119 | .load = {0x0120, 0x00f600, fw_dir "ldcard2.bin",}, | ||
| 120 | .app = {0x0010, 0x0d0000, fw_dir "cancrd2.bin",}, | ||
| 121 | .reset = softingcs_reset, | ||
| 122 | .enable_irq = NULL, | ||
| 123 | }, { | ||
| 124 | .name = "EDICcard-NEC", | ||
| 125 | .manf = 0x0168, .prod = 0x102, | ||
| 126 | .generation = 1, | ||
| 127 | .nbus = 2, | ||
| 128 | .freq = 16 * MHZ, .max_brp = 64, .max_sjw = 4, | ||
| 129 | .dpram_size = 0x0800, | ||
| 130 | .boot = {0x0000, 0x000000, fw_dir "bcard.bin",}, | ||
| 131 | .load = {0x0120, 0x00f600, fw_dir "ldcard.bin",}, | ||
| 132 | .app = {0x0010, 0x0d0000, fw_dir "cancard.bin",}, | ||
| 133 | .reset = softingcs_reset, | ||
| 134 | .enable_irq = softingcs_enable_irq, | ||
| 135 | }, { | ||
| 136 | .name = "EDICcard-2", | ||
| 137 | .manf = 0x0168, .prod = 0x105, | ||
| 138 | .generation = 2, | ||
| 139 | .nbus = 2, | ||
| 140 | .freq = 24 * MHZ, .max_brp = 64, .max_sjw = 4, | ||
| 141 | .dpram_size = 0x1000, | ||
| 142 | .boot = {0x0000, 0x000000, fw_dir "bcard2.bin",}, | ||
| 143 | .load = {0x0120, 0x00f600, fw_dir "ldcard2.bin",}, | ||
| 144 | .app = {0x0010, 0x0d0000, fw_dir "cancrd2.bin",}, | ||
| 145 | .reset = softingcs_reset, | ||
| 146 | .enable_irq = NULL, | ||
| 147 | }, { | ||
| 148 | 0, 0, | ||
| 149 | }, | ||
| 150 | }; | ||
| 151 | |||
| 152 | MODULE_FIRMWARE(fw_dir "bcard.bin"); | ||
| 153 | MODULE_FIRMWARE(fw_dir "ldcard.bin"); | ||
| 154 | MODULE_FIRMWARE(fw_dir "cancard.bin"); | ||
| 155 | MODULE_FIRMWARE(fw_dir "cansja.bin"); | ||
| 156 | |||
| 157 | MODULE_FIRMWARE(fw_dir "bcard2.bin"); | ||
| 158 | MODULE_FIRMWARE(fw_dir "ldcard2.bin"); | ||
| 159 | MODULE_FIRMWARE(fw_dir "cancrd2.bin"); | ||
| 160 | |||
| 161 | static __devinit const struct softing_platform_data | ||
| 162 | *softingcs_find_platform_data(unsigned int manf, unsigned int prod) | ||
| 163 | { | ||
| 164 | const struct softing_platform_data *lp; | ||
| 165 | |||
| 166 | for (lp = softingcs_platform_data; lp->manf; ++lp) { | ||
| 167 | if ((lp->manf == manf) && (lp->prod == prod)) | ||
| 168 | return lp; | ||
| 169 | } | ||
| 170 | return NULL; | ||
| 171 | } | ||
| 172 | |||
| 173 | /* | ||
| 174 | * platformdata callbacks | ||
| 175 | */ | ||
| 176 | static int softingcs_reset(struct platform_device *pdev, int v) | ||
| 177 | { | ||
| 178 | struct pcmcia_device *pcmcia = to_pcmcia_dev(pdev->dev.parent); | ||
| 179 | |||
| 180 | dev_dbg(&pdev->dev, "pcmcia config [2] %02x\n", v ? 0 : 0x20); | ||
| 181 | return pcmcia_write_config_byte(pcmcia, 2, v ? 0 : 0x20); | ||
| 182 | } | ||
| 183 | |||
| 184 | static int softingcs_enable_irq(struct platform_device *pdev, int v) | ||
| 185 | { | ||
| 186 | struct pcmcia_device *pcmcia = to_pcmcia_dev(pdev->dev.parent); | ||
| 187 | |||
| 188 | dev_dbg(&pdev->dev, "pcmcia config [0] %02x\n", v ? 0x60 : 0); | ||
| 189 | return pcmcia_write_config_byte(pcmcia, 0, v ? 0x60 : 0); | ||
| 190 | } | ||
| 191 | |||
| 192 | /* | ||
| 193 | * pcmcia check | ||
| 194 | */ | ||
| 195 | static __devinit int softingcs_probe_config(struct pcmcia_device *pcmcia, | ||
| 196 | void *priv_data) | ||
| 197 | { | ||
| 198 | struct softing_platform_data *pdat = priv_data; | ||
| 199 | struct resource *pres; | ||
| 200 | int memspeed = 0; | ||
| 201 | |||
| 202 | WARN_ON(!pdat); | ||
| 203 | pres = pcmcia->resource[PCMCIA_IOMEM_0]; | ||
| 204 | if (resource_size(pres) < 0x1000) | ||
| 205 | return -ERANGE; | ||
| 206 | |||
| 207 | pres->flags |= WIN_MEMORY_TYPE_CM | WIN_ENABLE; | ||
| 208 | if (pdat->generation < 2) { | ||
| 209 | pres->flags |= WIN_USE_WAIT | WIN_DATA_WIDTH_8; | ||
| 210 | memspeed = 3; | ||
| 211 | } else { | ||
| 212 | pres->flags |= WIN_DATA_WIDTH_16; | ||
| 213 | } | ||
| 214 | return pcmcia_request_window(pcmcia, pres, memspeed); | ||
| 215 | } | ||
| 216 | |||
| 217 | static __devexit void softingcs_remove(struct pcmcia_device *pcmcia) | ||
| 218 | { | ||
| 219 | struct platform_device *pdev = pcmcia->priv; | ||
| 220 | |||
| 221 | /* free bits */ | ||
| 222 | platform_device_unregister(pdev); | ||
| 223 | /* release pcmcia stuff */ | ||
| 224 | pcmcia_disable_device(pcmcia); | ||
| 225 | } | ||
| 226 | |||
| 227 | /* | ||
| 228 | * platform_device wrapper | ||
| 229 | * pdev->resource has 2 entries: io & irq | ||
| 230 | */ | ||
| 231 | static void softingcs_pdev_release(struct device *dev) | ||
| 232 | { | ||
| 233 | struct platform_device *pdev = to_platform_device(dev); | ||
| 234 | kfree(pdev); | ||
| 235 | } | ||
| 236 | |||
| 237 | static __devinit int softingcs_probe(struct pcmcia_device *pcmcia) | ||
| 238 | { | ||
| 239 | int ret; | ||
| 240 | struct platform_device *pdev; | ||
| 241 | const struct softing_platform_data *pdat; | ||
| 242 | struct resource *pres; | ||
| 243 | struct dev { | ||
| 244 | struct platform_device pdev; | ||
| 245 | struct resource res[2]; | ||
| 246 | } *dev; | ||
| 247 | |||
| 248 | /* find matching platform_data */ | ||
| 249 | pdat = softingcs_find_platform_data(pcmcia->manf_id, pcmcia->card_id); | ||
| 250 | if (!pdat) | ||
| 251 | return -ENOTTY; | ||
| 252 | |||
| 253 | /* setup pcmcia device */ | ||
| 254 | pcmcia->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IOMEM | | ||
| 255 | CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC; | ||
| 256 | ret = pcmcia_loop_config(pcmcia, softingcs_probe_config, (void *)pdat); | ||
| 257 | if (ret) | ||
| 258 | goto pcmcia_failed; | ||
| 259 | |||
| 260 | ret = pcmcia_enable_device(pcmcia); | ||
| 261 | if (ret < 0) | ||
| 262 | goto pcmcia_failed; | ||
| 263 | |||
| 264 | pres = pcmcia->resource[PCMCIA_IOMEM_0]; | ||
| 265 | if (!pres) { | ||
| 266 | ret = -EBADF; | ||
| 267 | goto pcmcia_bad; | ||
| 268 | } | ||
| 269 | |||
| 270 | /* create softing platform device */ | ||
| 271 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
| 272 | if (!dev) { | ||
| 273 | ret = -ENOMEM; | ||
| 274 | goto mem_failed; | ||
| 275 | } | ||
| 276 | dev->pdev.resource = dev->res; | ||
| 277 | dev->pdev.num_resources = ARRAY_SIZE(dev->res); | ||
| 278 | dev->pdev.dev.release = softingcs_pdev_release; | ||
| 279 | |||
| 280 | pdev = &dev->pdev; | ||
| 281 | pdev->dev.platform_data = (void *)pdat; | ||
| 282 | pdev->dev.parent = &pcmcia->dev; | ||
| 283 | pcmcia->priv = pdev; | ||
| 284 | |||
| 285 | /* platform device resources */ | ||
| 286 | pdev->resource[0].flags = IORESOURCE_MEM; | ||
| 287 | pdev->resource[0].start = pres->start; | ||
| 288 | pdev->resource[0].end = pres->end; | ||
| 289 | |||
| 290 | pdev->resource[1].flags = IORESOURCE_IRQ; | ||
| 291 | pdev->resource[1].start = pcmcia->irq; | ||
| 292 | pdev->resource[1].end = pdev->resource[1].start; | ||
| 293 | |||
| 294 | /* platform device setup */ | ||
| 295 | spin_lock(&softingcs_index_lock); | ||
| 296 | pdev->id = softingcs_index++; | ||
| 297 | spin_unlock(&softingcs_index_lock); | ||
| 298 | pdev->name = "softing"; | ||
| 299 | dev_set_name(&pdev->dev, "softingcs.%i", pdev->id); | ||
| 300 | ret = platform_device_register(pdev); | ||
| 301 | if (ret < 0) | ||
| 302 | goto platform_failed; | ||
| 303 | |||
| 304 | dev_info(&pcmcia->dev, "created %s\n", dev_name(&pdev->dev)); | ||
| 305 | return 0; | ||
| 306 | |||
| 307 | platform_failed: | ||
| 308 | kfree(dev); | ||
| 309 | mem_failed: | ||
| 310 | pcmcia_bad: | ||
| 311 | pcmcia_failed: | ||
| 312 | pcmcia_disable_device(pcmcia); | ||
| 313 | pcmcia->priv = NULL; | ||
| 314 | return ret ?: -ENODEV; | ||
| 315 | } | ||
| 316 | |||
| 317 | static /*const*/ struct pcmcia_device_id softingcs_ids[] = { | ||
| 318 | /* softing */ | ||
| 319 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0001), | ||
| 320 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0002), | ||
| 321 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0004), | ||
| 322 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0005), | ||
| 323 | /* vector, manufacturer? */ | ||
| 324 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0081), | ||
| 325 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0084), | ||
| 326 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0085), | ||
| 327 | /* EDIC */ | ||
| 328 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0102), | ||
| 329 | PCMCIA_DEVICE_MANF_CARD(0x0168, 0x0105), | ||
| 330 | PCMCIA_DEVICE_NULL, | ||
| 331 | }; | ||
| 332 | |||
| 333 | MODULE_DEVICE_TABLE(pcmcia, softingcs_ids); | ||
| 334 | |||
| 335 | static struct pcmcia_driver softingcs_driver = { | ||
| 336 | .owner = THIS_MODULE, | ||
| 337 | .name = "softingcs", | ||
| 338 | .id_table = softingcs_ids, | ||
| 339 | .probe = softingcs_probe, | ||
| 340 | .remove = __devexit_p(softingcs_remove), | ||
| 341 | }; | ||
| 342 | |||
| 343 | static int __init softingcs_start(void) | ||
| 344 | { | ||
| 345 | spin_lock_init(&softingcs_index_lock); | ||
| 346 | return pcmcia_register_driver(&softingcs_driver); | ||
| 347 | } | ||
| 348 | |||
| 349 | static void __exit softingcs_stop(void) | ||
| 350 | { | ||
| 351 | pcmcia_unregister_driver(&softingcs_driver); | ||
| 352 | } | ||
| 353 | |||
| 354 | module_init(softingcs_start); | ||
| 355 | module_exit(softingcs_stop); | ||
| 356 | |||
| 357 | MODULE_DESCRIPTION("softing CANcard driver" | ||
| 358 | ", links PCMCIA card to softing driver"); | ||
| 359 | MODULE_LICENSE("GPL v2"); | ||
