aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/can/sja1000
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /drivers/net/can/sja1000
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'drivers/net/can/sja1000')
-rw-r--r--drivers/net/can/sja1000/Kconfig42
-rw-r--r--drivers/net/can/sja1000/Makefile3
-rw-r--r--drivers/net/can/sja1000/ems_pci.c18
-rw-r--r--drivers/net/can/sja1000/ems_pcmcia.c330
-rw-r--r--drivers/net/can/sja1000/kvaser_pci.c21
-rw-r--r--drivers/net/can/sja1000/peak_pci.c762
-rw-r--r--drivers/net/can/sja1000/peak_pcmcia.c755
-rw-r--r--drivers/net/can/sja1000/plx_pci.c72
-rw-r--r--drivers/net/can/sja1000/sja1000.c75
-rw-r--r--drivers/net/can/sja1000/sja1000.h3
-rw-r--r--drivers/net/can/sja1000/sja1000_isa.c124
-rw-r--r--drivers/net/can/sja1000/sja1000_of_platform.c30
-rw-r--r--drivers/net/can/sja1000/sja1000_platform.c18
-rw-r--r--drivers/net/can/sja1000/tscan1.c8
14 files changed, 168 insertions, 2093 deletions
diff --git a/drivers/net/can/sja1000/Kconfig b/drivers/net/can/sja1000/Kconfig
index 92f73c708a3..6fdc031daaa 100644
--- a/drivers/net/can/sja1000/Kconfig
+++ b/drivers/net/can/sja1000/Kconfig
@@ -6,6 +6,7 @@ if CAN_SJA1000
6 6
7config CAN_SJA1000_ISA 7config CAN_SJA1000_ISA
8 tristate "ISA Bus based legacy SJA1000 driver" 8 tristate "ISA Bus based legacy SJA1000 driver"
9 depends on ISA
9 ---help--- 10 ---help---
10 This driver adds legacy support for SJA1000 chips connected to 11 This driver adds legacy support for SJA1000 chips connected to
11 the ISA bus using I/O port, memory mapped or indirect access. 12 the ISA bus using I/O port, memory mapped or indirect access.
@@ -21,20 +22,13 @@ config CAN_SJA1000_PLATFORM
21 22
22config CAN_SJA1000_OF_PLATFORM 23config CAN_SJA1000_OF_PLATFORM
23 tristate "Generic OF Platform Bus based SJA1000 driver" 24 tristate "Generic OF Platform Bus based SJA1000 driver"
24 depends on OF 25 depends on PPC_OF
25 ---help--- 26 ---help---
26 This driver adds support for the SJA1000 chips connected to 27 This driver adds support for the SJA1000 chips connected to
27 the OpenFirmware "platform bus" found on embedded systems with 28 the OpenFirmware "platform bus" found on embedded systems with
28 OpenFirmware bindings, e.g. if you have a PowerPC based system 29 OpenFirmware bindings, e.g. if you have a PowerPC based system
29 you may want to enable this option. 30 you may want to enable this option.
30 31
31config CAN_EMS_PCMCIA
32 tristate "EMS CPC-CARD Card"
33 depends on PCMCIA
34 ---help---
35 This driver is for the one or two channel CPC-CARD cards from
36 EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de).
37
38config CAN_EMS_PCI 32config CAN_EMS_PCI
39 tristate "EMS CPC-PCI, CPC-PCIe and CPC-104P Card" 33 tristate "EMS CPC-PCI, CPC-PCIe and CPC-104P Card"
40 depends on PCI 34 depends on PCI
@@ -43,39 +37,11 @@ config CAN_EMS_PCI
43 CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche 37 CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche
44 (http://www.ems-wuensche.de). 38 (http://www.ems-wuensche.de).
45 39
46config CAN_PEAK_PCMCIA
47 tristate "PEAK PCAN-PC Card"
48 depends on PCMCIA
49 ---help---
50 This driver is for the PCAN-PC Card PCMCIA adapter (1 or 2 channels)
51 from PEAK-System (http://www.peak-system.com). To compile this
52 driver as a module, choose M here: the module will be called
53 peak_pcmcia.
54
55config CAN_PEAK_PCI
56 tristate "PEAK PCAN-PCI/PCIe/miniPCI Cards"
57 depends on PCI
58 ---help---
59 This driver is for the PCAN-PCI/PCIe/miniPCI cards
60 (1, 2, 3 or 4 channels) from PEAK-System Technik
61 (http://www.peak-system.com).
62
63config CAN_PEAK_PCIEC
64 bool "PEAK PCAN-ExpressCard Cards"
65 depends on CAN_PEAK_PCI
66 select I2C
67 select I2C_ALGOBIT
68 default y
69 ---help---
70 Say Y here if you want to use a PCAN-ExpressCard from PEAK-System
71 Technik. This will also automatically select I2C and I2C_ALGO
72 configuration options.
73
74config CAN_KVASER_PCI 40config CAN_KVASER_PCI
75 tristate "Kvaser PCIcanx and Kvaser PCIcan PCI Cards" 41 tristate "Kvaser PCIcanx and Kvaser PCIcan PCI Cards"
76 depends on PCI 42 depends on PCI
77 ---help--- 43 ---help---
78 This driver is for the PCIcanx and PCIcan cards (1, 2 or 44 This driver is for the the PCIcanx and PCIcan cards (1, 2 or
79 4 channel) from Kvaser (http://www.kvaser.com). 45 4 channel) from Kvaser (http://www.kvaser.com).
80 46
81config CAN_PLX_PCI 47config CAN_PLX_PCI
@@ -92,8 +58,6 @@ config CAN_PLX_PCI
92 - esd CAN-PCIe/2000 58 - esd CAN-PCIe/2000
93 - Marathon CAN-bus-PCI card (http://www.marathon.ru/) 59 - Marathon CAN-bus-PCI card (http://www.marathon.ru/)
94 - TEWS TECHNOLOGIES TPMC810 card (http://www.tews.com/) 60 - TEWS TECHNOLOGIES TPMC810 card (http://www.tews.com/)
95 - IXXAT Automation PC-I 04/PCI card (http://www.ixxat.com/)
96 - Connect Tech Inc. CANpro/104-Plus Opto (CRG001) card (http://www.connecttech.com)
97 61
98config CAN_TSCAN1 62config CAN_TSCAN1
99 tristate "TS-CAN1 PC104 boards" 63 tristate "TS-CAN1 PC104 boards"
diff --git a/drivers/net/can/sja1000/Makefile b/drivers/net/can/sja1000/Makefile
index b3d05cbfec3..2c591eb321c 100644
--- a/drivers/net/can/sja1000/Makefile
+++ b/drivers/net/can/sja1000/Makefile
@@ -6,11 +6,8 @@ obj-$(CONFIG_CAN_SJA1000) += sja1000.o
6obj-$(CONFIG_CAN_SJA1000_ISA) += sja1000_isa.o 6obj-$(CONFIG_CAN_SJA1000_ISA) += sja1000_isa.o
7obj-$(CONFIG_CAN_SJA1000_PLATFORM) += sja1000_platform.o 7obj-$(CONFIG_CAN_SJA1000_PLATFORM) += sja1000_platform.o
8obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o 8obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o
9obj-$(CONFIG_CAN_EMS_PCMCIA) += ems_pcmcia.o
10obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o 9obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o
11obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o 10obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o
12obj-$(CONFIG_CAN_PEAK_PCMCIA) += peak_pcmcia.o
13obj-$(CONFIG_CAN_PEAK_PCI) += peak_pci.o
14obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o 11obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o
15obj-$(CONFIG_CAN_TSCAN1) += tscan1.o 12obj-$(CONFIG_CAN_TSCAN1) += tscan1.o
16 13
diff --git a/drivers/net/can/sja1000/ems_pci.c b/drivers/net/can/sja1000/ems_pci.c
index 036a326836b..36f4f9780c3 100644
--- a/drivers/net/can/sja1000/ems_pci.c
+++ b/drivers/net/can/sja1000/ems_pci.c
@@ -220,8 +220,8 @@ static void ems_pci_card_reset(struct ems_pci_card *card)
220 * Probe PCI device for EMS CAN signature and register each available 220 * Probe PCI device for EMS CAN signature and register each available
221 * CAN channel to SJA1000 Socket-CAN subsystem. 221 * CAN channel to SJA1000 Socket-CAN subsystem.
222 */ 222 */
223static int ems_pci_add_card(struct pci_dev *pdev, 223static int __devinit ems_pci_add_card(struct pci_dev *pdev,
224 const struct pci_device_id *ent) 224 const struct pci_device_id *ent)
225{ 225{
226 struct sja1000_priv *priv; 226 struct sja1000_priv *priv;
227 struct net_device *dev; 227 struct net_device *dev;
@@ -371,4 +371,16 @@ static struct pci_driver ems_pci_driver = {
371 .remove = ems_pci_del_card, 371 .remove = ems_pci_del_card,
372}; 372};
373 373
374module_pci_driver(ems_pci_driver); 374static int __init ems_pci_init(void)
375{
376 return pci_register_driver(&ems_pci_driver);
377}
378
379static void __exit ems_pci_exit(void)
380{
381 pci_unregister_driver(&ems_pci_driver);
382}
383
384module_init(ems_pci_init);
385module_exit(ems_pci_exit);
386
diff --git a/drivers/net/can/sja1000/ems_pcmcia.c b/drivers/net/can/sja1000/ems_pcmcia.c
deleted file mode 100644
index 5c2f3fbbf5a..00000000000
--- a/drivers/net/can/sja1000/ems_pcmcia.c
+++ /dev/null
@@ -1,330 +0,0 @@
1/*
2 * Copyright (C) 2008 Sebastian Haas (initial chardev implementation)
3 * Copyright (C) 2010 Markus Plessing <plessing@ems-wuensche.com>
4 * Rework for mainline by Oliver Hartkopp <socketcan@hartkopp.net>
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
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/interrupt.h>
19#include <linux/netdevice.h>
20#include <linux/delay.h>
21#include <linux/io.h>
22#include <pcmcia/cistpl.h>
23#include <pcmcia/ds.h>
24#include <linux/can.h>
25#include <linux/can/dev.h>
26#include "sja1000.h"
27
28#define DRV_NAME "ems_pcmcia"
29
30MODULE_AUTHOR("Markus Plessing <plessing@ems-wuensche.com>");
31MODULE_DESCRIPTION("Socket-CAN driver for EMS CPC-CARD cards");
32MODULE_SUPPORTED_DEVICE("EMS CPC-CARD CAN card");
33MODULE_LICENSE("GPL v2");
34
35#define EMS_PCMCIA_MAX_CHAN 2
36
37struct ems_pcmcia_card {
38 int channels;
39 struct pcmcia_device *pcmcia_dev;
40 struct net_device *net_dev[EMS_PCMCIA_MAX_CHAN];
41 void __iomem *base_addr;
42};
43
44#define EMS_PCMCIA_CAN_CLOCK (16000000 / 2)
45
46/*
47 * The board configuration is probably following:
48 * RX1 is connected to ground.
49 * TX1 is not connected.
50 * CLKO is not connected.
51 * Setting the OCR register to 0xDA is a good idea.
52 * This means normal output mode , push-pull and the correct polarity.
53 */
54#define EMS_PCMCIA_OCR (OCR_TX0_PUSHPULL | OCR_TX1_PUSHPULL)
55
56/*
57 * In the CDR register, you should set CBP to 1.
58 * You will probably also want to set the clock divider value to 7
59 * (meaning direct oscillator output) because the second SJA1000 chip
60 * is driven by the first one CLKOUT output.
61 */
62#define EMS_PCMCIA_CDR (CDR_CBP | CDR_CLKOUT_MASK)
63#define EMS_PCMCIA_MEM_SIZE 4096 /* Size of the remapped io-memory */
64#define EMS_PCMCIA_CAN_BASE_OFFSET 0x100 /* Offset where controllers starts */
65#define EMS_PCMCIA_CAN_CTRL_SIZE 0x80 /* Memory size for each controller */
66
67#define EMS_CMD_RESET 0x00 /* Perform a reset of the card */
68#define EMS_CMD_MAP 0x03 /* Map CAN controllers into card' memory */
69#define EMS_CMD_UMAP 0x02 /* Unmap CAN controllers from card' memory */
70
71static struct pcmcia_device_id ems_pcmcia_tbl[] = {
72 PCMCIA_DEVICE_PROD_ID123("EMS_T_W", "CPC-Card", "V2.0", 0xeab1ea23,
73 0xa338573f, 0xe4575800),
74 PCMCIA_DEVICE_NULL,
75};
76
77MODULE_DEVICE_TABLE(pcmcia, ems_pcmcia_tbl);
78
79static u8 ems_pcmcia_read_reg(const struct sja1000_priv *priv, int port)
80{
81 return readb(priv->reg_base + port);
82}
83
84static void ems_pcmcia_write_reg(const struct sja1000_priv *priv, int port,
85 u8 val)
86{
87 writeb(val, priv->reg_base + port);
88}
89
90static irqreturn_t ems_pcmcia_interrupt(int irq, void *dev_id)
91{
92 struct ems_pcmcia_card *card = dev_id;
93 struct net_device *dev;
94 irqreturn_t retval = IRQ_NONE;
95 int i, again;
96
97 /* Card not present */
98 if (readw(card->base_addr) != 0xAA55)
99 return IRQ_HANDLED;
100
101 do {
102 again = 0;
103
104 /* Check interrupt for each channel */
105 for (i = 0; i < card->channels; i++) {
106 dev = card->net_dev[i];
107 if (!dev)
108 continue;
109
110 if (sja1000_interrupt(irq, dev) == IRQ_HANDLED)
111 again = 1;
112 }
113 /* At least one channel handled the interrupt */
114 if (again)
115 retval = IRQ_HANDLED;
116
117 } while (again);
118
119 return retval;
120}
121
122/*
123 * Check if a CAN controller is present at the specified location
124 * by trying to set 'em into the PeliCAN mode
125 */
126static inline int ems_pcmcia_check_chan(struct sja1000_priv *priv)
127{
128 /* Make sure SJA1000 is in reset mode */
129 ems_pcmcia_write_reg(priv, REG_MOD, 1);
130 ems_pcmcia_write_reg(priv, REG_CDR, CDR_PELICAN);
131
132 /* read reset-values */
133 if (ems_pcmcia_read_reg(priv, REG_CDR) == CDR_PELICAN)
134 return 1;
135
136 return 0;
137}
138
139static void ems_pcmcia_del_card(struct pcmcia_device *pdev)
140{
141 struct ems_pcmcia_card *card = pdev->priv;
142 struct net_device *dev;
143 int i;
144
145 free_irq(pdev->irq, card);
146
147 for (i = 0; i < card->channels; i++) {
148 dev = card->net_dev[i];
149 if (!dev)
150 continue;
151
152 printk(KERN_INFO "%s: removing %s on channel #%d\n",
153 DRV_NAME, dev->name, i);
154 unregister_sja1000dev(dev);
155 free_sja1000dev(dev);
156 }
157
158 writeb(EMS_CMD_UMAP, card->base_addr);
159 iounmap(card->base_addr);
160 kfree(card);
161
162 pdev->priv = NULL;
163}
164
165/*
166 * Probe PCI device for EMS CAN signature and register each available
167 * CAN channel to SJA1000 Socket-CAN subsystem.
168 */
169static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base)
170{
171 struct sja1000_priv *priv;
172 struct net_device *dev;
173 struct ems_pcmcia_card *card;
174 int err, i;
175
176 /* Allocating card structures to hold addresses, ... */
177 card = kzalloc(sizeof(struct ems_pcmcia_card), GFP_KERNEL);
178 if (!card)
179 return -ENOMEM;
180
181 pdev->priv = card;
182 card->channels = 0;
183
184 card->base_addr = ioremap(base, EMS_PCMCIA_MEM_SIZE);
185 if (!card->base_addr) {
186 err = -ENOMEM;
187 goto failure_cleanup;
188 }
189
190 /* Check for unique EMS CAN signature */
191 if (readw(card->base_addr) != 0xAA55) {
192 err = -ENODEV;
193 goto failure_cleanup;
194 }
195
196 /* Request board reset */
197 writeb(EMS_CMD_RESET, card->base_addr);
198
199 /* Make sure CAN controllers are mapped into card's memory space */
200 writeb(EMS_CMD_MAP, card->base_addr);
201
202 /* Detect available channels */
203 for (i = 0; i < EMS_PCMCIA_MAX_CHAN; i++) {
204 dev = alloc_sja1000dev(0);
205 if (!dev) {
206 err = -ENOMEM;
207 goto failure_cleanup;
208 }
209
210 card->net_dev[i] = dev;
211 priv = netdev_priv(dev);
212 priv->priv = card;
213 SET_NETDEV_DEV(dev, &pdev->dev);
214
215 priv->irq_flags = IRQF_SHARED;
216 dev->irq = pdev->irq;
217 priv->reg_base = card->base_addr + EMS_PCMCIA_CAN_BASE_OFFSET +
218 (i * EMS_PCMCIA_CAN_CTRL_SIZE);
219
220 /* Check if channel is present */
221 if (ems_pcmcia_check_chan(priv)) {
222 priv->read_reg = ems_pcmcia_read_reg;
223 priv->write_reg = ems_pcmcia_write_reg;
224 priv->can.clock.freq = EMS_PCMCIA_CAN_CLOCK;
225 priv->ocr = EMS_PCMCIA_OCR;
226 priv->cdr = EMS_PCMCIA_CDR;
227 priv->flags |= SJA1000_CUSTOM_IRQ_HANDLER;
228
229 /* Register SJA1000 device */
230 err = register_sja1000dev(dev);
231 if (err) {
232 free_sja1000dev(dev);
233 goto failure_cleanup;
234 }
235
236 card->channels++;
237
238 printk(KERN_INFO "%s: registered %s on channel "
239 "#%d at 0x%p, irq %d\n", DRV_NAME, dev->name,
240 i, priv->reg_base, dev->irq);
241 } else
242 free_sja1000dev(dev);
243 }
244
245 err = request_irq(dev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,
246 DRV_NAME, card);
247 if (!err)
248 return 0;
249
250failure_cleanup:
251 ems_pcmcia_del_card(pdev);
252 return err;
253}
254
255/*
256 * Setup PCMCIA socket and probe for EMS CPC-CARD
257 */
258static int ems_pcmcia_probe(struct pcmcia_device *dev)
259{
260 int csval;
261
262 /* General socket configuration */
263 dev->config_flags |= CONF_ENABLE_IRQ;
264 dev->config_index = 1;
265 dev->config_regs = PRESENT_OPTION;
266
267 /* The io structure describes IO port mapping */
268 dev->resource[0]->end = 16;
269 dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
270 dev->resource[1]->end = 16;
271 dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_16;
272 dev->io_lines = 5;
273
274 /* Allocate a memory window */
275 dev->resource[2]->flags =
276 (WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE);
277 dev->resource[2]->start = dev->resource[2]->end = 0;
278
279 csval = pcmcia_request_window(dev, dev->resource[2], 0);
280 if (csval) {
281 dev_err(&dev->dev, "pcmcia_request_window failed (err=%d)\n",
282 csval);
283 return 0;
284 }
285
286 csval = pcmcia_map_mem_page(dev, dev->resource[2], dev->config_base);
287 if (csval) {
288 dev_err(&dev->dev, "pcmcia_map_mem_page failed (err=%d)\n",
289 csval);
290 return 0;
291 }
292
293 csval = pcmcia_enable_device(dev);
294 if (csval) {
295 dev_err(&dev->dev, "pcmcia_enable_device failed (err=%d)\n",
296 csval);
297 return 0;
298 }
299
300 ems_pcmcia_add_card(dev, dev->resource[2]->start);
301 return 0;
302}
303
304/*
305 * Release claimed resources
306 */
307static void ems_pcmcia_remove(struct pcmcia_device *dev)
308{
309 ems_pcmcia_del_card(dev);
310 pcmcia_disable_device(dev);
311}
312
313static struct pcmcia_driver ems_pcmcia_driver = {
314 .name = DRV_NAME,
315 .probe = ems_pcmcia_probe,
316 .remove = ems_pcmcia_remove,
317 .id_table = ems_pcmcia_tbl,
318};
319
320static int __init ems_pcmcia_init(void)
321{
322 return pcmcia_register_driver(&ems_pcmcia_driver);
323}
324module_init(ems_pcmcia_init);
325
326static void __exit ems_pcmcia_exit(void)
327{
328 pcmcia_unregister_driver(&ems_pcmcia_driver);
329}
330module_exit(ems_pcmcia_exit);
diff --git a/drivers/net/can/sja1000/kvaser_pci.c b/drivers/net/can/sja1000/kvaser_pci.c
index 37b0381f532..ed004cebd31 100644
--- a/drivers/net/can/sja1000/kvaser_pci.c
+++ b/drivers/net/can/sja1000/kvaser_pci.c
@@ -290,8 +290,8 @@ failure:
290 return err; 290 return err;
291} 291}
292 292
293static int kvaser_pci_init_one(struct pci_dev *pdev, 293static int __devinit kvaser_pci_init_one(struct pci_dev *pdev,
294 const struct pci_device_id *ent) 294 const struct pci_device_id *ent)
295{ 295{
296 int err; 296 int err;
297 struct net_device *master_dev = NULL; 297 struct net_device *master_dev = NULL;
@@ -379,7 +379,7 @@ failure:
379 379
380} 380}
381 381
382static void kvaser_pci_remove_one(struct pci_dev *pdev) 382static void __devexit kvaser_pci_remove_one(struct pci_dev *pdev)
383{ 383{
384 struct net_device *dev = pci_get_drvdata(pdev); 384 struct net_device *dev = pci_get_drvdata(pdev);
385 385
@@ -394,7 +394,18 @@ static struct pci_driver kvaser_pci_driver = {
394 .name = DRV_NAME, 394 .name = DRV_NAME,
395 .id_table = kvaser_pci_tbl, 395 .id_table = kvaser_pci_tbl,
396 .probe = kvaser_pci_init_one, 396 .probe = kvaser_pci_init_one,
397 .remove = kvaser_pci_remove_one, 397 .remove = __devexit_p(kvaser_pci_remove_one),
398}; 398};
399 399
400module_pci_driver(kvaser_pci_driver); 400static int __init kvaser_pci_init(void)
401{
402 return pci_register_driver(&kvaser_pci_driver);
403}
404
405static void __exit kvaser_pci_exit(void)
406{
407 pci_unregister_driver(&kvaser_pci_driver);
408}
409
410module_init(kvaser_pci_init);
411module_exit(kvaser_pci_exit);
diff --git a/drivers/net/can/sja1000/peak_pci.c b/drivers/net/can/sja1000/peak_pci.c
deleted file mode 100644
index d84888f03d9..00000000000
--- a/drivers/net/can/sja1000/peak_pci.c
+++ /dev/null
@@ -1,762 +0,0 @@
1/*
2 * Copyright (C) 2007, 2011 Wolfgang Grandegger <wg@grandegger.com>
3 * Copyright (C) 2012 Stephane Grosjean <s.grosjean@peak-system.com>
4 *
5 * Derived from the PCAN project file driver/src/pcan_pci.c:
6 *
7 * Copyright (C) 2001-2006 PEAK System-Technik GmbH
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the version 2 of the GNU General Public License
11 * as published by the Free Software Foundation
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/interrupt.h>
22#include <linux/netdevice.h>
23#include <linux/delay.h>
24#include <linux/pci.h>
25#include <linux/io.h>
26#include <linux/i2c.h>
27#include <linux/i2c-algo-bit.h>
28#include <linux/can.h>
29#include <linux/can/dev.h>
30
31#include "sja1000.h"
32
33MODULE_AUTHOR("Stephane Grosjean <s.grosjean@peak-system.com>");
34MODULE_DESCRIPTION("Socket-CAN driver for PEAK PCAN PCI family cards");
35MODULE_SUPPORTED_DEVICE("PEAK PCAN PCI/PCIe/PCIeC miniPCI CAN cards");
36MODULE_SUPPORTED_DEVICE("PEAK PCAN miniPCIe/cPCI PC/104+ PCI/104e CAN Cards");
37MODULE_LICENSE("GPL v2");
38
39#define DRV_NAME "peak_pci"
40
41struct peak_pciec_card;
42struct peak_pci_chan {
43 void __iomem *cfg_base; /* Common for all channels */
44 struct net_device *prev_dev; /* Chain of network devices */
45 u16 icr_mask; /* Interrupt mask for fast ack */
46 struct peak_pciec_card *pciec_card; /* only for PCIeC LEDs */
47};
48
49#define PEAK_PCI_CAN_CLOCK (16000000 / 2)
50
51#define PEAK_PCI_CDR (CDR_CBP | CDR_CLKOUT_MASK)
52#define PEAK_PCI_OCR OCR_TX0_PUSHPULL
53
54/*
55 * Important PITA registers
56 */
57#define PITA_ICR 0x00 /* Interrupt control register */
58#define PITA_GPIOICR 0x18 /* GPIO interface control register */
59#define PITA_MISC 0x1C /* Miscellaneous register */
60
61#define PEAK_PCI_CFG_SIZE 0x1000 /* Size of the config PCI bar */
62#define PEAK_PCI_CHAN_SIZE 0x0400 /* Size used by the channel */
63
64#define PEAK_PCI_VENDOR_ID 0x001C /* The PCI device and vendor IDs */
65#define PEAK_PCI_DEVICE_ID 0x0001 /* for PCI/PCIe slot cards */
66#define PEAK_PCIEC_DEVICE_ID 0x0002 /* for ExpressCard slot cards */
67#define PEAK_PCIE_DEVICE_ID 0x0003 /* for nextgen PCIe slot cards */
68#define PEAK_CPCI_DEVICE_ID 0x0004 /* for nextgen cPCI slot cards */
69#define PEAK_MPCI_DEVICE_ID 0x0005 /* for nextgen miniPCI slot cards */
70#define PEAK_PC_104P_DEVICE_ID 0x0006 /* PCAN-PC/104+ cards */
71#define PEAK_PCI_104E_DEVICE_ID 0x0007 /* PCAN-PCI/104 Express cards */
72#define PEAK_MPCIE_DEVICE_ID 0x0008 /* The miniPCIe slot cards */
73
74#define PEAK_PCI_CHAN_MAX 4
75
76static const u16 peak_pci_icr_masks[PEAK_PCI_CHAN_MAX] = {
77 0x02, 0x01, 0x40, 0x80
78};
79
80static DEFINE_PCI_DEVICE_TABLE(peak_pci_tbl) = {
81 {PEAK_PCI_VENDOR_ID, PEAK_PCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
82 {PEAK_PCI_VENDOR_ID, PEAK_PCIE_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
83 {PEAK_PCI_VENDOR_ID, PEAK_MPCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
84 {PEAK_PCI_VENDOR_ID, PEAK_MPCIE_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
85 {PEAK_PCI_VENDOR_ID, PEAK_PC_104P_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
86 {PEAK_PCI_VENDOR_ID, PEAK_PCI_104E_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
87 {PEAK_PCI_VENDOR_ID, PEAK_CPCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
88#ifdef CONFIG_CAN_PEAK_PCIEC
89 {PEAK_PCI_VENDOR_ID, PEAK_PCIEC_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,},
90#endif
91 {0,}
92};
93
94MODULE_DEVICE_TABLE(pci, peak_pci_tbl);
95
96#ifdef CONFIG_CAN_PEAK_PCIEC
97/*
98 * PCAN-ExpressCard needs I2C bit-banging configuration option.
99 */
100
101/* GPIOICR byte access offsets */
102#define PITA_GPOUT 0x18 /* GPx output value */
103#define PITA_GPIN 0x19 /* GPx input value */
104#define PITA_GPOEN 0x1A /* configure GPx as ouput pin */
105
106/* I2C GP bits */
107#define PITA_GPIN_SCL 0x01 /* Serial Clock Line */
108#define PITA_GPIN_SDA 0x04 /* Serial DAta line */
109
110#define PCA9553_1_SLAVEADDR (0xC4 >> 1)
111
112/* PCA9553 LS0 fields values */
113enum {
114 PCA9553_LOW,
115 PCA9553_HIGHZ,
116 PCA9553_PWM0,
117 PCA9553_PWM1
118};
119
120/* LEDs control */
121#define PCA9553_ON PCA9553_LOW
122#define PCA9553_OFF PCA9553_HIGHZ
123#define PCA9553_SLOW PCA9553_PWM0
124#define PCA9553_FAST PCA9553_PWM1
125
126#define PCA9553_LED(c) (1 << (c))
127#define PCA9553_LED_STATE(s, c) ((s) << ((c) << 1))
128
129#define PCA9553_LED_ON(c) PCA9553_LED_STATE(PCA9553_ON, c)
130#define PCA9553_LED_OFF(c) PCA9553_LED_STATE(PCA9553_OFF, c)
131#define PCA9553_LED_SLOW(c) PCA9553_LED_STATE(PCA9553_SLOW, c)
132#define PCA9553_LED_FAST(c) PCA9553_LED_STATE(PCA9553_FAST, c)
133#define PCA9553_LED_MASK(c) PCA9553_LED_STATE(0x03, c)
134
135#define PCA9553_LED_OFF_ALL (PCA9553_LED_OFF(0) | PCA9553_LED_OFF(1))
136
137#define PCA9553_LS0_INIT 0x40 /* initial value (!= from 0x00) */
138
139struct peak_pciec_chan {
140 struct net_device *netdev;
141 unsigned long prev_rx_bytes;
142 unsigned long prev_tx_bytes;
143};
144
145struct peak_pciec_card {
146 void __iomem *cfg_base; /* Common for all channels */
147 void __iomem *reg_base; /* first channel base address */
148 u8 led_cache; /* leds state cache */
149
150 /* PCIExpressCard i2c data */
151 struct i2c_algo_bit_data i2c_bit;
152 struct i2c_adapter led_chip;
153 struct delayed_work led_work; /* led delayed work */
154 int chan_count;
155 struct peak_pciec_chan channel[PEAK_PCI_CHAN_MAX];
156};
157
158/* "normal" pci register write callback is overloaded for leds control */
159static void peak_pci_write_reg(const struct sja1000_priv *priv,
160 int port, u8 val);
161
162static inline void pita_set_scl_highz(struct peak_pciec_card *card)
163{
164 u8 gp_outen = readb(card->cfg_base + PITA_GPOEN) & ~PITA_GPIN_SCL;
165 writeb(gp_outen, card->cfg_base + PITA_GPOEN);
166}
167
168static inline void pita_set_sda_highz(struct peak_pciec_card *card)
169{
170 u8 gp_outen = readb(card->cfg_base + PITA_GPOEN) & ~PITA_GPIN_SDA;
171 writeb(gp_outen, card->cfg_base + PITA_GPOEN);
172}
173
174static void peak_pciec_init_pita_gpio(struct peak_pciec_card *card)
175{
176 /* raise SCL & SDA GPIOs to high-Z */
177 pita_set_scl_highz(card);
178 pita_set_sda_highz(card);
179}
180
181static void pita_setsda(void *data, int state)
182{
183 struct peak_pciec_card *card = (struct peak_pciec_card *)data;
184 u8 gp_out, gp_outen;
185
186 /* set output sda always to 0 */
187 gp_out = readb(card->cfg_base + PITA_GPOUT) & ~PITA_GPIN_SDA;
188 writeb(gp_out, card->cfg_base + PITA_GPOUT);
189
190 /* control output sda with GPOEN */
191 gp_outen = readb(card->cfg_base + PITA_GPOEN);
192 if (state)
193 gp_outen &= ~PITA_GPIN_SDA;
194 else
195 gp_outen |= PITA_GPIN_SDA;
196
197 writeb(gp_outen, card->cfg_base + PITA_GPOEN);
198}
199
200static void pita_setscl(void *data, int state)
201{
202 struct peak_pciec_card *card = (struct peak_pciec_card *)data;
203 u8 gp_out, gp_outen;
204
205 /* set output scl always to 0 */
206 gp_out = readb(card->cfg_base + PITA_GPOUT) & ~PITA_GPIN_SCL;
207 writeb(gp_out, card->cfg_base + PITA_GPOUT);
208
209 /* control output scl with GPOEN */
210 gp_outen = readb(card->cfg_base + PITA_GPOEN);
211 if (state)
212 gp_outen &= ~PITA_GPIN_SCL;
213 else
214 gp_outen |= PITA_GPIN_SCL;
215
216 writeb(gp_outen, card->cfg_base + PITA_GPOEN);
217}
218
219static int pita_getsda(void *data)
220{
221 struct peak_pciec_card *card = (struct peak_pciec_card *)data;
222
223 /* set tristate */
224 pita_set_sda_highz(card);
225
226 return (readb(card->cfg_base + PITA_GPIN) & PITA_GPIN_SDA) ? 1 : 0;
227}
228
229static int pita_getscl(void *data)
230{
231 struct peak_pciec_card *card = (struct peak_pciec_card *)data;
232
233 /* set tristate */
234 pita_set_scl_highz(card);
235
236 return (readb(card->cfg_base + PITA_GPIN) & PITA_GPIN_SCL) ? 1 : 0;
237}
238
239/*
240 * write commands to the LED chip though the I2C-bus of the PCAN-PCIeC
241 */
242static int peak_pciec_write_pca9553(struct peak_pciec_card *card,
243 u8 offset, u8 data)
244{
245 u8 buffer[2] = {
246 offset,
247 data
248 };
249 struct i2c_msg msg = {
250 .addr = PCA9553_1_SLAVEADDR,
251 .len = 2,
252 .buf = buffer,
253 };
254 int ret;
255
256 /* cache led mask */
257 if ((offset == 5) && (data == card->led_cache))
258 return 0;
259
260 ret = i2c_transfer(&card->led_chip, &msg, 1);
261 if (ret < 0)
262 return ret;
263
264 if (offset == 5)
265 card->led_cache = data;
266
267 return 0;
268}
269
270/*
271 * delayed work callback used to control the LEDs
272 */
273static void peak_pciec_led_work(struct work_struct *work)
274{
275 struct peak_pciec_card *card =
276 container_of(work, struct peak_pciec_card, led_work.work);
277 struct net_device *netdev;
278 u8 new_led = card->led_cache;
279 int i, up_count = 0;
280
281 /* first check what is to do */
282 for (i = 0; i < card->chan_count; i++) {
283 /* default is: not configured */
284 new_led &= ~PCA9553_LED_MASK(i);
285 new_led |= PCA9553_LED_ON(i);
286
287 netdev = card->channel[i].netdev;
288 if (!netdev || !(netdev->flags & IFF_UP))
289 continue;
290
291 up_count++;
292
293 /* no activity (but configured) */
294 new_led &= ~PCA9553_LED_MASK(i);
295 new_led |= PCA9553_LED_SLOW(i);
296
297 /* if bytes counters changed, set fast blinking led */
298 if (netdev->stats.rx_bytes != card->channel[i].prev_rx_bytes) {
299 card->channel[i].prev_rx_bytes = netdev->stats.rx_bytes;
300 new_led &= ~PCA9553_LED_MASK(i);
301 new_led |= PCA9553_LED_FAST(i);
302 }
303 if (netdev->stats.tx_bytes != card->channel[i].prev_tx_bytes) {
304 card->channel[i].prev_tx_bytes = netdev->stats.tx_bytes;
305 new_led &= ~PCA9553_LED_MASK(i);
306 new_led |= PCA9553_LED_FAST(i);
307 }
308 }
309
310 /* check if LS0 settings changed, only update i2c if so */
311 peak_pciec_write_pca9553(card, 5, new_led);
312
313 /* restart timer (except if no more configured channels) */
314 if (up_count)
315 schedule_delayed_work(&card->led_work, HZ);
316}
317
318/*
319 * set LEDs blinking state
320 */
321static void peak_pciec_set_leds(struct peak_pciec_card *card, u8 led_mask, u8 s)
322{
323 u8 new_led = card->led_cache;
324 int i;
325
326 /* first check what is to do */
327 for (i = 0; i < card->chan_count; i++)
328 if (led_mask & PCA9553_LED(i)) {
329 new_led &= ~PCA9553_LED_MASK(i);
330 new_led |= PCA9553_LED_STATE(s, i);
331 }
332
333 /* check if LS0 settings changed, only update i2c if so */
334 peak_pciec_write_pca9553(card, 5, new_led);
335}
336
337/*
338 * start one second delayed work to control LEDs
339 */
340static void peak_pciec_start_led_work(struct peak_pciec_card *card)
341{
342 if (!delayed_work_pending(&card->led_work))
343 schedule_delayed_work(&card->led_work, HZ);
344}
345
346/*
347 * stop LEDs delayed work
348 */
349static void peak_pciec_stop_led_work(struct peak_pciec_card *card)
350{
351 cancel_delayed_work_sync(&card->led_work);
352}
353
354/*
355 * initialize the PCA9553 4-bit I2C-bus LED chip
356 */
357static int peak_pciec_init_leds(struct peak_pciec_card *card)
358{
359 int err;
360
361 /* prescaler for frequency 0: "SLOW" = 1 Hz = "44" */
362 err = peak_pciec_write_pca9553(card, 1, 44 / 1);
363 if (err)
364 return err;
365
366 /* duty cycle 0: 50% */
367 err = peak_pciec_write_pca9553(card, 2, 0x80);
368 if (err)
369 return err;
370
371 /* prescaler for frequency 1: "FAST" = 5 Hz */
372 err = peak_pciec_write_pca9553(card, 3, 44 / 5);
373 if (err)
374 return err;
375
376 /* duty cycle 1: 50% */
377 err = peak_pciec_write_pca9553(card, 4, 0x80);
378 if (err)
379 return err;
380
381 /* switch LEDs to initial state */
382 return peak_pciec_write_pca9553(card, 5, PCA9553_LS0_INIT);
383}
384
385/*
386 * restore LEDs state to off peak_pciec_leds_exit
387 */
388static void peak_pciec_leds_exit(struct peak_pciec_card *card)
389{
390 /* switch LEDs to off */
391 peak_pciec_write_pca9553(card, 5, PCA9553_LED_OFF_ALL);
392}
393
394/*
395 * normal write sja1000 register method overloaded to catch when controller
396 * is started or stopped, to control leds
397 */
398static void peak_pciec_write_reg(const struct sja1000_priv *priv,
399 int port, u8 val)
400{
401 struct peak_pci_chan *chan = priv->priv;
402 struct peak_pciec_card *card = chan->pciec_card;
403 int c = (priv->reg_base - card->reg_base) / PEAK_PCI_CHAN_SIZE;
404
405 /* sja1000 register changes control the leds state */
406 if (port == REG_MOD)
407 switch (val) {
408 case MOD_RM:
409 /* Reset Mode: set led on */
410 peak_pciec_set_leds(card, PCA9553_LED(c), PCA9553_ON);
411 break;
412 case 0x00:
413 /* Normal Mode: led slow blinking and start led timer */
414 peak_pciec_set_leds(card, PCA9553_LED(c), PCA9553_SLOW);
415 peak_pciec_start_led_work(card);
416 break;
417 default:
418 break;
419 }
420
421 /* call base function */
422 peak_pci_write_reg(priv, port, val);
423}
424
425static struct i2c_algo_bit_data peak_pciec_i2c_bit_ops = {
426 .setsda = pita_setsda,
427 .setscl = pita_setscl,
428 .getsda = pita_getsda,
429 .getscl = pita_getscl,
430 .udelay = 10,
431 .timeout = HZ,
432};
433
434static int peak_pciec_probe(struct pci_dev *pdev, struct net_device *dev)
435{
436 struct sja1000_priv *priv = netdev_priv(dev);
437 struct peak_pci_chan *chan = priv->priv;
438 struct peak_pciec_card *card;
439 int err;
440
441 /* copy i2c object address from 1st channel */
442 if (chan->prev_dev) {
443 struct sja1000_priv *prev_priv = netdev_priv(chan->prev_dev);
444 struct peak_pci_chan *prev_chan = prev_priv->priv;
445
446 card = prev_chan->pciec_card;
447 if (!card)
448 return -ENODEV;
449
450 /* channel is the first one: do the init part */
451 } else {
452 /* create the bit banging I2C adapter structure */
453 card = kzalloc(sizeof(struct peak_pciec_card), GFP_KERNEL);
454 if (!card) {
455 dev_err(&pdev->dev,
456 "failed allocating memory for i2c chip\n");
457 return -ENOMEM;
458 }
459
460 card->cfg_base = chan->cfg_base;
461 card->reg_base = priv->reg_base;
462
463 card->led_chip.owner = THIS_MODULE;
464 card->led_chip.dev.parent = &pdev->dev;
465 card->led_chip.algo_data = &card->i2c_bit;
466 strncpy(card->led_chip.name, "peak_i2c",
467 sizeof(card->led_chip.name));
468
469 card->i2c_bit = peak_pciec_i2c_bit_ops;
470 card->i2c_bit.udelay = 10;
471 card->i2c_bit.timeout = HZ;
472 card->i2c_bit.data = card;
473
474 peak_pciec_init_pita_gpio(card);
475
476 err = i2c_bit_add_bus(&card->led_chip);
477 if (err) {
478 dev_err(&pdev->dev, "i2c init failed\n");
479 goto pciec_init_err_1;
480 }
481
482 err = peak_pciec_init_leds(card);
483 if (err) {
484 dev_err(&pdev->dev, "leds hardware init failed\n");
485 goto pciec_init_err_2;
486 }
487
488 INIT_DELAYED_WORK(&card->led_work, peak_pciec_led_work);
489 /* PCAN-ExpressCard needs its own callback for leds */
490 priv->write_reg = peak_pciec_write_reg;
491 }
492
493 chan->pciec_card = card;
494 card->channel[card->chan_count++].netdev = dev;
495
496 return 0;
497
498pciec_init_err_2:
499 i2c_del_adapter(&card->led_chip);
500
501pciec_init_err_1:
502 peak_pciec_init_pita_gpio(card);
503 kfree(card);
504
505 return err;
506}
507
508static void peak_pciec_remove(struct peak_pciec_card *card)
509{
510 peak_pciec_stop_led_work(card);
511 peak_pciec_leds_exit(card);
512 i2c_del_adapter(&card->led_chip);
513 peak_pciec_init_pita_gpio(card);
514 kfree(card);
515}
516
517#else /* CONFIG_CAN_PEAK_PCIEC */
518
519/*
520 * Placebo functions when PCAN-ExpressCard support is not selected
521 */
522static inline int peak_pciec_probe(struct pci_dev *pdev, struct net_device *dev)
523{
524 return -ENODEV;
525}
526
527static inline void peak_pciec_remove(struct peak_pciec_card *card)
528{
529}
530#endif /* CONFIG_CAN_PEAK_PCIEC */
531
532static u8 peak_pci_read_reg(const struct sja1000_priv *priv, int port)
533{
534 return readb(priv->reg_base + (port << 2));
535}
536
537static void peak_pci_write_reg(const struct sja1000_priv *priv,
538 int port, u8 val)
539{
540 writeb(val, priv->reg_base + (port << 2));
541}
542
543static void peak_pci_post_irq(const struct sja1000_priv *priv)
544{
545 struct peak_pci_chan *chan = priv->priv;
546 u16 icr;
547
548 /* Select and clear in PITA stored interrupt */
549 icr = readw(chan->cfg_base + PITA_ICR);
550 if (icr & chan->icr_mask)
551 writew(chan->icr_mask, chan->cfg_base + PITA_ICR);
552}
553
554static int peak_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
555{
556 struct sja1000_priv *priv;
557 struct peak_pci_chan *chan;
558 struct net_device *dev;
559 void __iomem *cfg_base, *reg_base;
560 u16 sub_sys_id, icr;
561 int i, err, channels;
562
563 err = pci_enable_device(pdev);
564 if (err)
565 return err;
566
567 err = pci_request_regions(pdev, DRV_NAME);
568 if (err)
569 goto failure_disable_pci;
570
571 err = pci_read_config_word(pdev, 0x2e, &sub_sys_id);
572 if (err)
573 goto failure_release_regions;
574
575 dev_dbg(&pdev->dev, "probing device %04x:%04x:%04x\n",
576 pdev->vendor, pdev->device, sub_sys_id);
577
578 err = pci_write_config_word(pdev, 0x44, 0);
579 if (err)
580 goto failure_release_regions;
581
582 if (sub_sys_id >= 12)
583 channels = 4;
584 else if (sub_sys_id >= 10)
585 channels = 3;
586 else if (sub_sys_id >= 4)
587 channels = 2;
588 else
589 channels = 1;
590
591 cfg_base = pci_iomap(pdev, 0, PEAK_PCI_CFG_SIZE);
592 if (!cfg_base) {
593 dev_err(&pdev->dev, "failed to map PCI resource #0\n");
594 err = -ENOMEM;
595 goto failure_release_regions;
596 }
597
598 reg_base = pci_iomap(pdev, 1, PEAK_PCI_CHAN_SIZE * channels);
599 if (!reg_base) {
600 dev_err(&pdev->dev, "failed to map PCI resource #1\n");
601 err = -ENOMEM;
602 goto failure_unmap_cfg_base;
603 }
604
605 /* Set GPIO control register */
606 writew(0x0005, cfg_base + PITA_GPIOICR + 2);
607 /* Enable all channels of this card */
608 writeb(0x00, cfg_base + PITA_GPIOICR);
609 /* Toggle reset */
610 writeb(0x05, cfg_base + PITA_MISC + 3);
611 mdelay(5);
612 /* Leave parport mux mode */
613 writeb(0x04, cfg_base + PITA_MISC + 3);
614
615 icr = readw(cfg_base + PITA_ICR + 2);
616
617 for (i = 0; i < channels; i++) {
618 dev = alloc_sja1000dev(sizeof(struct peak_pci_chan));
619 if (!dev) {
620 err = -ENOMEM;
621 goto failure_remove_channels;
622 }
623
624 priv = netdev_priv(dev);
625 chan = priv->priv;
626
627 chan->cfg_base = cfg_base;
628 priv->reg_base = reg_base + i * PEAK_PCI_CHAN_SIZE;
629
630 priv->read_reg = peak_pci_read_reg;
631 priv->write_reg = peak_pci_write_reg;
632 priv->post_irq = peak_pci_post_irq;
633
634 priv->can.clock.freq = PEAK_PCI_CAN_CLOCK;
635 priv->ocr = PEAK_PCI_OCR;
636 priv->cdr = PEAK_PCI_CDR;
637 /* Neither a slave nor a single device distributes the clock */
638 if (channels == 1 || i > 0)
639 priv->cdr |= CDR_CLK_OFF;
640
641 /* Setup interrupt handling */
642 priv->irq_flags = IRQF_SHARED;
643 dev->irq = pdev->irq;
644
645 chan->icr_mask = peak_pci_icr_masks[i];
646 icr |= chan->icr_mask;
647
648 SET_NETDEV_DEV(dev, &pdev->dev);
649
650 /* Create chain of SJA1000 devices */
651 chan->prev_dev = pci_get_drvdata(pdev);
652 pci_set_drvdata(pdev, dev);
653
654 /*
655 * PCAN-ExpressCard needs some additional i2c init.
656 * This must be done *before* register_sja1000dev() but
657 * *after* devices linkage
658 */
659 if (pdev->device == PEAK_PCIEC_DEVICE_ID) {
660 err = peak_pciec_probe(pdev, dev);
661 if (err) {
662 dev_err(&pdev->dev,
663 "failed to probe device (err %d)\n",
664 err);
665 goto failure_free_dev;
666 }
667 }
668
669 err = register_sja1000dev(dev);
670 if (err) {
671 dev_err(&pdev->dev, "failed to register device\n");
672 goto failure_free_dev;
673 }
674
675 dev_info(&pdev->dev,
676 "%s at reg_base=0x%p cfg_base=0x%p irq=%d\n",
677 dev->name, priv->reg_base, chan->cfg_base, dev->irq);
678 }
679
680 /* Enable interrupts */
681 writew(icr, cfg_base + PITA_ICR + 2);
682
683 return 0;
684
685failure_free_dev:
686 pci_set_drvdata(pdev, chan->prev_dev);
687 free_sja1000dev(dev);
688
689failure_remove_channels:
690 /* Disable interrupts */
691 writew(0x0, cfg_base + PITA_ICR + 2);
692
693 chan = NULL;
694 for (dev = pci_get_drvdata(pdev); dev; dev = chan->prev_dev) {
695 unregister_sja1000dev(dev);
696 free_sja1000dev(dev);
697 priv = netdev_priv(dev);
698 chan = priv->priv;
699 }
700
701 /* free any PCIeC resources too */
702 if (chan && chan->pciec_card)
703 peak_pciec_remove(chan->pciec_card);
704
705 pci_iounmap(pdev, reg_base);
706
707failure_unmap_cfg_base:
708 pci_iounmap(pdev, cfg_base);
709
710failure_release_regions:
711 pci_release_regions(pdev);
712
713failure_disable_pci:
714 pci_disable_device(pdev);
715
716 return err;
717}
718
719static void peak_pci_remove(struct pci_dev *pdev)
720{
721 struct net_device *dev = pci_get_drvdata(pdev); /* Last device */
722 struct sja1000_priv *priv = netdev_priv(dev);
723 struct peak_pci_chan *chan = priv->priv;
724 void __iomem *cfg_base = chan->cfg_base;
725 void __iomem *reg_base = priv->reg_base;
726
727 /* Disable interrupts */
728 writew(0x0, cfg_base + PITA_ICR + 2);
729
730 /* Loop over all registered devices */
731 while (1) {
732 dev_info(&pdev->dev, "removing device %s\n", dev->name);
733 unregister_sja1000dev(dev);
734 free_sja1000dev(dev);
735 dev = chan->prev_dev;
736
737 if (!dev) {
738 /* do that only for first channel */
739 if (chan->pciec_card)
740 peak_pciec_remove(chan->pciec_card);
741 break;
742 }
743 priv = netdev_priv(dev);
744 chan = priv->priv;
745 }
746
747 pci_iounmap(pdev, reg_base);
748 pci_iounmap(pdev, cfg_base);
749 pci_release_regions(pdev);
750 pci_disable_device(pdev);
751
752 pci_set_drvdata(pdev, NULL);
753}
754
755static struct pci_driver peak_pci_driver = {
756 .name = DRV_NAME,
757 .id_table = peak_pci_tbl,
758 .probe = peak_pci_probe,
759 .remove = peak_pci_remove,
760};
761
762module_pci_driver(peak_pci_driver);
diff --git a/drivers/net/can/sja1000/peak_pcmcia.c b/drivers/net/can/sja1000/peak_pcmcia.c
deleted file mode 100644
index f1175142b0a..00000000000
--- a/drivers/net/can/sja1000/peak_pcmcia.c
+++ /dev/null
@@ -1,755 +0,0 @@
1/*
2 * Copyright (C) 2010-2012 Stephane Grosjean <s.grosjean@peak-system.com>
3 *
4 * CAN driver for PEAK-System PCAN-PC Card
5 * Derived from the PCAN project file driver/src/pcan_pccard.c
6 * Copyright (C) 2006-2010 PEAK System-Technik GmbH
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the version 2 of the GNU General Public License
10 * as published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/interrupt.h>
20#include <linux/netdevice.h>
21#include <linux/delay.h>
22#include <linux/timer.h>
23#include <linux/io.h>
24#include <pcmcia/cistpl.h>
25#include <pcmcia/ds.h>
26#include <linux/can.h>
27#include <linux/can/dev.h>
28#include "sja1000.h"
29
30MODULE_AUTHOR("Stephane Grosjean <s.grosjean@peak-system.com>");
31MODULE_DESCRIPTION("CAN driver for PEAK-System PCAN-PC Cards");
32MODULE_LICENSE("GPL v2");
33MODULE_SUPPORTED_DEVICE("PEAK PCAN-PC Card");
34
35/* PEAK-System PCMCIA driver name */
36#define PCC_NAME "peak_pcmcia"
37
38#define PCC_CHAN_MAX 2
39
40#define PCC_CAN_CLOCK (16000000 / 2)
41
42#define PCC_MANF_ID 0x0377
43#define PCC_CARD_ID 0x0001
44
45#define PCC_CHAN_SIZE 0x20
46#define PCC_CHAN_OFF(c) ((c) * PCC_CHAN_SIZE)
47#define PCC_COMN_OFF (PCC_CHAN_OFF(PCC_CHAN_MAX))
48#define PCC_COMN_SIZE 0x40
49
50/* common area registers */
51#define PCC_CCR 0x00
52#define PCC_CSR 0x02
53#define PCC_CPR 0x04
54#define PCC_SPI_DIR 0x06
55#define PCC_SPI_DOR 0x08
56#define PCC_SPI_ADR 0x0a
57#define PCC_SPI_IR 0x0c
58#define PCC_FW_MAJOR 0x10
59#define PCC_FW_MINOR 0x12
60
61/* CCR bits */
62#define PCC_CCR_CLK_16 0x00
63#define PCC_CCR_CLK_10 0x01
64#define PCC_CCR_CLK_21 0x02
65#define PCC_CCR_CLK_8 0x03
66#define PCC_CCR_CLK_MASK PCC_CCR_CLK_8
67
68#define PCC_CCR_RST_CHAN(c) (0x01 << ((c) + 2))
69#define PCC_CCR_RST_ALL (PCC_CCR_RST_CHAN(0) | PCC_CCR_RST_CHAN(1))
70#define PCC_CCR_RST_MASK PCC_CCR_RST_ALL
71
72/* led selection bits */
73#define PCC_LED(c) (1 << (c))
74#define PCC_LED_ALL (PCC_LED(0) | PCC_LED(1))
75
76/* led state value */
77#define PCC_LED_ON 0x00
78#define PCC_LED_FAST 0x01
79#define PCC_LED_SLOW 0x02
80#define PCC_LED_OFF 0x03
81
82#define PCC_CCR_LED_CHAN(s, c) ((s) << (((c) + 2) << 1))
83
84#define PCC_CCR_LED_ON_CHAN(c) PCC_CCR_LED_CHAN(PCC_LED_ON, c)
85#define PCC_CCR_LED_FAST_CHAN(c) PCC_CCR_LED_CHAN(PCC_LED_FAST, c)
86#define PCC_CCR_LED_SLOW_CHAN(c) PCC_CCR_LED_CHAN(PCC_LED_SLOW, c)
87#define PCC_CCR_LED_OFF_CHAN(c) PCC_CCR_LED_CHAN(PCC_LED_OFF, c)
88#define PCC_CCR_LED_MASK_CHAN(c) PCC_CCR_LED_OFF_CHAN(c)
89#define PCC_CCR_LED_OFF_ALL (PCC_CCR_LED_OFF_CHAN(0) | \
90 PCC_CCR_LED_OFF_CHAN(1))
91#define PCC_CCR_LED_MASK PCC_CCR_LED_OFF_ALL
92
93#define PCC_CCR_INIT (PCC_CCR_CLK_16 | PCC_CCR_RST_ALL | PCC_CCR_LED_OFF_ALL)
94
95/* CSR bits */
96#define PCC_CSR_SPI_BUSY 0x04
97
98/* time waiting for SPI busy (prevent from infinite loop) */
99#define PCC_SPI_MAX_BUSY_WAIT_MS 3
100
101/* max count of reading the SPI status register waiting for a change */
102/* (prevent from infinite loop) */
103#define PCC_WRITE_MAX_LOOP 1000
104
105/* max nb of int handled by that isr in one shot (prevent from infinite loop) */
106#define PCC_ISR_MAX_LOOP 10
107
108/* EEPROM chip instruction set */
109/* note: EEPROM Read/Write instructions include A8 bit */
110#define PCC_EEP_WRITE(a) (0x02 | (((a) & 0x100) >> 5))
111#define PCC_EEP_READ(a) (0x03 | (((a) & 0x100) >> 5))
112#define PCC_EEP_WRDI 0x04 /* EEPROM Write Disable */
113#define PCC_EEP_RDSR 0x05 /* EEPROM Read Status Register */
114#define PCC_EEP_WREN 0x06 /* EEPROM Write Enable */
115
116/* EEPROM Status Register bits */
117#define PCC_EEP_SR_WEN 0x02 /* EEPROM SR Write Enable bit */
118#define PCC_EEP_SR_WIP 0x01 /* EEPROM SR Write In Progress bit */
119
120/*
121 * The board configuration is probably following:
122 * RX1 is connected to ground.
123 * TX1 is not connected.
124 * CLKO is not connected.
125 * Setting the OCR register to 0xDA is a good idea.
126 * This means normal output mode, push-pull and the correct polarity.
127 */
128#define PCC_OCR (OCR_TX0_PUSHPULL | OCR_TX1_PUSHPULL)
129
130/*
131 * In the CDR register, you should set CBP to 1.
132 * You will probably also want to set the clock divider value to 7
133 * (meaning direct oscillator output) because the second SJA1000 chip
134 * is driven by the first one CLKOUT output.
135 */
136#define PCC_CDR (CDR_CBP | CDR_CLKOUT_MASK)
137
138struct pcan_channel {
139 struct net_device *netdev;
140 unsigned long prev_rx_bytes;
141 unsigned long prev_tx_bytes;
142};
143
144/* PCAN-PC Card private structure */
145struct pcan_pccard {
146 struct pcmcia_device *pdev;
147 int chan_count;
148 struct pcan_channel channel[PCC_CHAN_MAX];
149 u8 ccr;
150 u8 fw_major;
151 u8 fw_minor;
152 void __iomem *ioport_addr;
153 struct timer_list led_timer;
154};
155
156static struct pcmcia_device_id pcan_table[] = {
157 PCMCIA_DEVICE_MANF_CARD(PCC_MANF_ID, PCC_CARD_ID),
158 PCMCIA_DEVICE_NULL,
159};
160
161MODULE_DEVICE_TABLE(pcmcia, pcan_table);
162
163static void pcan_set_leds(struct pcan_pccard *card, u8 mask, u8 state);
164
165/*
166 * start timer which controls leds state
167 */
168static void pcan_start_led_timer(struct pcan_pccard *card)
169{
170 if (!timer_pending(&card->led_timer))
171 mod_timer(&card->led_timer, jiffies + HZ);
172}
173
174/*
175 * stop the timer which controls leds state
176 */
177static void pcan_stop_led_timer(struct pcan_pccard *card)
178{
179 del_timer_sync(&card->led_timer);
180}
181
182/*
183 * read a sja1000 register
184 */
185static u8 pcan_read_canreg(const struct sja1000_priv *priv, int port)
186{
187 return ioread8(priv->reg_base + port);
188}
189
190/*
191 * write a sja1000 register
192 */
193static void pcan_write_canreg(const struct sja1000_priv *priv, int port, u8 v)
194{
195 struct pcan_pccard *card = priv->priv;
196 int c = (priv->reg_base - card->ioport_addr) / PCC_CHAN_SIZE;
197
198 /* sja1000 register changes control the leds state */
199 if (port == REG_MOD)
200 switch (v) {
201 case MOD_RM:
202 /* Reset Mode: set led on */
203 pcan_set_leds(card, PCC_LED(c), PCC_LED_ON);
204 break;
205 case 0x00:
206 /* Normal Mode: led slow blinking and start led timer */
207 pcan_set_leds(card, PCC_LED(c), PCC_LED_SLOW);
208 pcan_start_led_timer(card);
209 break;
210 default:
211 break;
212 }
213
214 iowrite8(v, priv->reg_base + port);
215}
216
217/*
218 * read a register from the common area
219 */
220static u8 pcan_read_reg(struct pcan_pccard *card, int port)
221{
222 return ioread8(card->ioport_addr + PCC_COMN_OFF + port);
223}
224
225/*
226 * write a register into the common area
227 */
228static void pcan_write_reg(struct pcan_pccard *card, int port, u8 v)
229{
230 /* cache ccr value */
231 if (port == PCC_CCR) {
232 if (card->ccr == v)
233 return;
234 card->ccr = v;
235 }
236
237 iowrite8(v, card->ioport_addr + PCC_COMN_OFF + port);
238}
239
240/*
241 * check whether the card is present by checking its fw version numbers
242 * against values read at probing time.
243 */
244static inline int pcan_pccard_present(struct pcan_pccard *card)
245{
246 return ((pcan_read_reg(card, PCC_FW_MAJOR) == card->fw_major) &&
247 (pcan_read_reg(card, PCC_FW_MINOR) == card->fw_minor));
248}
249
250/*
251 * wait for SPI engine while it is busy
252 */
253static int pcan_wait_spi_busy(struct pcan_pccard *card)
254{
255 unsigned long timeout = jiffies +
256 msecs_to_jiffies(PCC_SPI_MAX_BUSY_WAIT_MS) + 1;
257
258 /* be sure to read status at least once after sleeping */
259 while (pcan_read_reg(card, PCC_CSR) & PCC_CSR_SPI_BUSY) {
260 if (time_after(jiffies, timeout))
261 return -EBUSY;
262 schedule();
263 }
264
265 return 0;
266}
267
268/*
269 * write data in device eeprom
270 */
271static int pcan_write_eeprom(struct pcan_pccard *card, u16 addr, u8 v)
272{
273 u8 status;
274 int err, i;
275
276 /* write instruction enabling write */
277 pcan_write_reg(card, PCC_SPI_IR, PCC_EEP_WREN);
278 err = pcan_wait_spi_busy(card);
279 if (err)
280 goto we_spi_err;
281
282 /* wait until write enabled */
283 for (i = 0; i < PCC_WRITE_MAX_LOOP; i++) {
284 /* write instruction reading the status register */
285 pcan_write_reg(card, PCC_SPI_IR, PCC_EEP_RDSR);
286 err = pcan_wait_spi_busy(card);
287 if (err)
288 goto we_spi_err;
289
290 /* get status register value and check write enable bit */
291 status = pcan_read_reg(card, PCC_SPI_DIR);
292 if (status & PCC_EEP_SR_WEN)
293 break;
294 }
295
296 if (i >= PCC_WRITE_MAX_LOOP) {
297 dev_err(&card->pdev->dev,
298 "stop waiting to be allowed to write in eeprom\n");
299 return -EIO;
300 }
301
302 /* set address and data */
303 pcan_write_reg(card, PCC_SPI_ADR, addr & 0xff);
304 pcan_write_reg(card, PCC_SPI_DOR, v);
305
306 /*
307 * write instruction with bit[3] set according to address value:
308 * if addr refers to upper half of the memory array: bit[3] = 1
309 */
310 pcan_write_reg(card, PCC_SPI_IR, PCC_EEP_WRITE(addr));
311 err = pcan_wait_spi_busy(card);
312 if (err)
313 goto we_spi_err;
314
315 /* wait while write in progress */
316 for (i = 0; i < PCC_WRITE_MAX_LOOP; i++) {
317 /* write instruction reading the status register */
318 pcan_write_reg(card, PCC_SPI_IR, PCC_EEP_RDSR);
319 err = pcan_wait_spi_busy(card);
320 if (err)
321 goto we_spi_err;
322
323 /* get status register value and check write in progress bit */
324 status = pcan_read_reg(card, PCC_SPI_DIR);
325 if (!(status & PCC_EEP_SR_WIP))
326 break;
327 }
328
329 if (i >= PCC_WRITE_MAX_LOOP) {
330 dev_err(&card->pdev->dev,
331 "stop waiting for write in eeprom to complete\n");
332 return -EIO;
333 }
334
335 /* write instruction disabling write */
336 pcan_write_reg(card, PCC_SPI_IR, PCC_EEP_WRDI);
337 err = pcan_wait_spi_busy(card);
338 if (err)
339 goto we_spi_err;
340
341 return 0;
342
343we_spi_err:
344 dev_err(&card->pdev->dev,
345 "stop waiting (spi engine always busy) err %d\n", err);
346
347 return err;
348}
349
350static void pcan_set_leds(struct pcan_pccard *card, u8 led_mask, u8 state)
351{
352 u8 ccr = card->ccr;
353 int i;
354
355 for (i = 0; i < card->chan_count; i++)
356 if (led_mask & PCC_LED(i)) {
357 /* clear corresponding led bits in ccr */
358 ccr &= ~PCC_CCR_LED_MASK_CHAN(i);
359 /* then set new bits */
360 ccr |= PCC_CCR_LED_CHAN(state, i);
361 }
362
363 /* real write only if something has changed in ccr */
364 pcan_write_reg(card, PCC_CCR, ccr);
365}
366
367/*
368 * enable/disable CAN connectors power
369 */
370static inline void pcan_set_can_power(struct pcan_pccard *card, int onoff)
371{
372 int err;
373
374 err = pcan_write_eeprom(card, 0, !!onoff);
375 if (err)
376 dev_err(&card->pdev->dev,
377 "failed setting power %s to can connectors (err %d)\n",
378 (onoff) ? "on" : "off", err);
379}
380
381/*
382 * set leds state according to channel activity
383 */
384static void pcan_led_timer(unsigned long arg)
385{
386 struct pcan_pccard *card = (struct pcan_pccard *)arg;
387 struct net_device *netdev;
388 int i, up_count = 0;
389 u8 ccr;
390
391 ccr = card->ccr;
392 for (i = 0; i < card->chan_count; i++) {
393 /* default is: not configured */
394 ccr &= ~PCC_CCR_LED_MASK_CHAN(i);
395 ccr |= PCC_CCR_LED_ON_CHAN(i);
396
397 netdev = card->channel[i].netdev;
398 if (!netdev || !(netdev->flags & IFF_UP))
399 continue;
400
401 up_count++;
402
403 /* no activity (but configured) */
404 ccr &= ~PCC_CCR_LED_MASK_CHAN(i);
405 ccr |= PCC_CCR_LED_SLOW_CHAN(i);
406
407 /* if bytes counters changed, set fast blinking led */
408 if (netdev->stats.rx_bytes != card->channel[i].prev_rx_bytes) {
409 card->channel[i].prev_rx_bytes = netdev->stats.rx_bytes;
410 ccr &= ~PCC_CCR_LED_MASK_CHAN(i);
411 ccr |= PCC_CCR_LED_FAST_CHAN(i);
412 }
413 if (netdev->stats.tx_bytes != card->channel[i].prev_tx_bytes) {
414 card->channel[i].prev_tx_bytes = netdev->stats.tx_bytes;
415 ccr &= ~PCC_CCR_LED_MASK_CHAN(i);
416 ccr |= PCC_CCR_LED_FAST_CHAN(i);
417 }
418 }
419
420 /* write the new leds state */
421 pcan_write_reg(card, PCC_CCR, ccr);
422
423 /* restart timer (except if no more configured channels) */
424 if (up_count)
425 mod_timer(&card->led_timer, jiffies + HZ);
426}
427
428/*
429 * interrupt service routine
430 */
431static irqreturn_t pcan_isr(int irq, void *dev_id)
432{
433 struct pcan_pccard *card = dev_id;
434 int irq_handled;
435
436 /* prevent from infinite loop */
437 for (irq_handled = 0; irq_handled < PCC_ISR_MAX_LOOP; irq_handled++) {
438 /* handle shared interrupt and next loop */
439 int nothing_to_handle = 1;
440 int i;
441
442 /* check interrupt for each channel */
443 for (i = 0; i < card->chan_count; i++) {
444 struct net_device *netdev;
445
446 /*
447 * check whether the card is present before calling
448 * sja1000_interrupt() to speed up hotplug detection
449 */
450 if (!pcan_pccard_present(card)) {
451 /* card unplugged during isr */
452 return IRQ_NONE;
453 }
454
455 /*
456 * should check whether all or SJA1000_MAX_IRQ
457 * interrupts have been handled: loop again to be sure.
458 */
459 netdev = card->channel[i].netdev;
460 if (netdev &&
461 sja1000_interrupt(irq, netdev) == IRQ_HANDLED)
462 nothing_to_handle = 0;
463 }
464
465 if (nothing_to_handle)
466 break;
467 }
468
469 return (irq_handled) ? IRQ_HANDLED : IRQ_NONE;
470}
471
472/*
473 * free all resources used by the channels and switch off leds and can power
474 */
475static void pcan_free_channels(struct pcan_pccard *card)
476{
477 int i;
478 u8 led_mask = 0;
479
480 for (i = 0; i < card->chan_count; i++) {
481 struct net_device *netdev;
482 char name[IFNAMSIZ];
483
484 led_mask |= PCC_LED(i);
485
486 netdev = card->channel[i].netdev;
487 if (!netdev)
488 continue;
489
490 strncpy(name, netdev->name, IFNAMSIZ);
491
492 unregister_sja1000dev(netdev);
493
494 free_sja1000dev(netdev);
495
496 dev_info(&card->pdev->dev, "%s removed\n", name);
497 }
498
499 /* do it only if device not removed */
500 if (pcan_pccard_present(card)) {
501 pcan_set_leds(card, led_mask, PCC_LED_OFF);
502 pcan_set_can_power(card, 0);
503 }
504}
505
506/*
507 * check if a CAN controller is present at the specified location
508 */
509static inline int pcan_channel_present(struct sja1000_priv *priv)
510{
511 /* make sure SJA1000 is in reset mode */
512 pcan_write_canreg(priv, REG_MOD, 1);
513 pcan_write_canreg(priv, REG_CDR, CDR_PELICAN);
514
515 /* read reset-values */
516 if (pcan_read_canreg(priv, REG_CDR) == CDR_PELICAN)
517 return 1;
518
519 return 0;
520}
521
522static int pcan_add_channels(struct pcan_pccard *card)
523{
524 struct pcmcia_device *pdev = card->pdev;
525 int i, err = 0;
526 u8 ccr = PCC_CCR_INIT;
527
528 /* init common registers (reset channels and leds off) */
529 card->ccr = ~ccr;
530 pcan_write_reg(card, PCC_CCR, ccr);
531
532 /* wait 2ms before unresetting channels */
533 mdelay(2);
534
535 ccr &= ~PCC_CCR_RST_ALL;
536 pcan_write_reg(card, PCC_CCR, ccr);
537
538 /* create one network device per channel detected */
539 for (i = 0; i < ARRAY_SIZE(card->channel); i++) {
540 struct net_device *netdev;
541 struct sja1000_priv *priv;
542
543 netdev = alloc_sja1000dev(0);
544 if (!netdev) {
545 err = -ENOMEM;
546 break;
547 }
548
549 /* update linkages */
550 priv = netdev_priv(netdev);
551 priv->priv = card;
552 SET_NETDEV_DEV(netdev, &pdev->dev);
553
554 priv->irq_flags = IRQF_SHARED;
555 netdev->irq = pdev->irq;
556 priv->reg_base = card->ioport_addr + PCC_CHAN_OFF(i);
557
558 /* check if channel is present */
559 if (!pcan_channel_present(priv)) {
560 dev_err(&pdev->dev, "channel %d not present\n", i);
561 free_sja1000dev(netdev);
562 continue;
563 }
564
565 priv->read_reg = pcan_read_canreg;
566 priv->write_reg = pcan_write_canreg;
567 priv->can.clock.freq = PCC_CAN_CLOCK;
568 priv->ocr = PCC_OCR;
569 priv->cdr = PCC_CDR;
570
571 /* Neither a slave device distributes the clock */
572 if (i > 0)
573 priv->cdr |= CDR_CLK_OFF;
574
575 priv->flags |= SJA1000_CUSTOM_IRQ_HANDLER;
576
577 /* register SJA1000 device */
578 err = register_sja1000dev(netdev);
579 if (err) {
580 free_sja1000dev(netdev);
581 continue;
582 }
583
584 card->channel[i].netdev = netdev;
585 card->chan_count++;
586
587 /* set corresponding led on in the new ccr */
588 ccr &= ~PCC_CCR_LED_OFF_CHAN(i);
589
590 dev_info(&pdev->dev,
591 "%s on channel %d at 0x%p irq %d\n",
592 netdev->name, i, priv->reg_base, pdev->irq);
593 }
594
595 /* write new ccr (change leds state) */
596 pcan_write_reg(card, PCC_CCR, ccr);
597
598 return err;
599}
600
601static int pcan_conf_check(struct pcmcia_device *pdev, void *priv_data)
602{
603 pdev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
604 pdev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; /* only */
605 pdev->io_lines = 10;
606
607 /* This reserves IO space but doesn't actually enable it */
608 return pcmcia_request_io(pdev);
609}
610
611/*
612 * free all resources used by the device
613 */
614static void pcan_free(struct pcmcia_device *pdev)
615{
616 struct pcan_pccard *card = pdev->priv;
617
618 if (!card)
619 return;
620
621 free_irq(pdev->irq, card);
622 pcan_stop_led_timer(card);
623
624 pcan_free_channels(card);
625
626 ioport_unmap(card->ioport_addr);
627
628 kfree(card);
629 pdev->priv = NULL;
630}
631
632/*
633 * setup PCMCIA socket and probe for PEAK-System PC-CARD
634 */
635static int pcan_probe(struct pcmcia_device *pdev)
636{
637 struct pcan_pccard *card;
638 int err;
639
640 pdev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
641
642 err = pcmcia_loop_config(pdev, pcan_conf_check, NULL);
643 if (err) {
644 dev_err(&pdev->dev, "pcmcia_loop_config() error %d\n", err);
645 goto probe_err_1;
646 }
647
648 if (!pdev->irq) {
649 dev_err(&pdev->dev, "no irq assigned\n");
650 err = -ENODEV;
651 goto probe_err_1;
652 }
653
654 err = pcmcia_enable_device(pdev);
655 if (err) {
656 dev_err(&pdev->dev, "pcmcia_enable_device failed err=%d\n",
657 err);
658 goto probe_err_1;
659 }
660
661 card = kzalloc(sizeof(struct pcan_pccard), GFP_KERNEL);
662 if (!card) {
663 dev_err(&pdev->dev, "couldn't allocate card memory\n");
664 err = -ENOMEM;
665 goto probe_err_2;
666 }
667
668 card->pdev = pdev;
669 pdev->priv = card;
670
671 /* sja1000 api uses iomem */
672 card->ioport_addr = ioport_map(pdev->resource[0]->start,
673 resource_size(pdev->resource[0]));
674 if (!card->ioport_addr) {
675 dev_err(&pdev->dev, "couldn't map io port into io memory\n");
676 err = -ENOMEM;
677 goto probe_err_3;
678 }
679 card->fw_major = pcan_read_reg(card, PCC_FW_MAJOR);
680 card->fw_minor = pcan_read_reg(card, PCC_FW_MINOR);
681
682 /* display board name and firware version */
683 dev_info(&pdev->dev, "PEAK-System pcmcia card %s fw %d.%d\n",
684 pdev->prod_id[1] ? pdev->prod_id[1] : "PCAN-PC Card",
685 card->fw_major, card->fw_minor);
686
687 /* detect available channels */
688 pcan_add_channels(card);
689 if (!card->chan_count) {
690 err = -ENOMEM;
691 goto probe_err_4;
692 }
693
694 /* init the timer which controls the leds */
695 init_timer(&card->led_timer);
696 card->led_timer.function = pcan_led_timer;
697 card->led_timer.data = (unsigned long)card;
698
699 /* request the given irq */
700 err = request_irq(pdev->irq, &pcan_isr, IRQF_SHARED, PCC_NAME, card);
701 if (err) {
702 dev_err(&pdev->dev, "couldn't request irq%d\n", pdev->irq);
703 goto probe_err_5;
704 }
705
706 /* power on the connectors */
707 pcan_set_can_power(card, 1);
708
709 return 0;
710
711probe_err_5:
712 /* unregister can devices from network */
713 pcan_free_channels(card);
714
715probe_err_4:
716 ioport_unmap(card->ioport_addr);
717
718probe_err_3:
719 kfree(card);
720 pdev->priv = NULL;
721
722probe_err_2:
723 pcmcia_disable_device(pdev);
724
725probe_err_1:
726 return err;
727}
728
729/*
730 * release claimed resources
731 */
732static void pcan_remove(struct pcmcia_device *pdev)
733{
734 pcan_free(pdev);
735 pcmcia_disable_device(pdev);
736}
737
738static struct pcmcia_driver pcan_driver = {
739 .name = PCC_NAME,
740 .probe = pcan_probe,
741 .remove = pcan_remove,
742 .id_table = pcan_table,
743};
744
745static int __init pcan_init(void)
746{
747 return pcmcia_register_driver(&pcan_driver);
748}
749module_init(pcan_init);
750
751static void __exit pcan_exit(void)
752{
753 pcmcia_unregister_driver(&pcan_driver);
754}
755module_exit(pcan_exit);
diff --git a/drivers/net/can/sja1000/plx_pci.c b/drivers/net/can/sja1000/plx_pci.c
index 11d1062a944..c7f3d4ea116 100644
--- a/drivers/net/can/sja1000/plx_pci.c
+++ b/drivers/net/can/sja1000/plx_pci.c
@@ -43,9 +43,7 @@ MODULE_SUPPORTED_DEVICE("Adlink PCI-7841/cPCI-7841, "
43 "TEWS TECHNOLOGIES TPMC810, " 43 "TEWS TECHNOLOGIES TPMC810, "
44 "esd CAN-PCI/CPCI/PCI104/200, " 44 "esd CAN-PCI/CPCI/PCI104/200, "
45 "esd CAN-PCI/PMC/266, " 45 "esd CAN-PCI/PMC/266, "
46 "esd CAN-PCIe/2000, " 46 "esd CAN-PCIe/2000")
47 "Connect Tech Inc. CANpro/104-Plus Opto (CRG001), "
48 "IXXAT PC-I 04/PCI")
49MODULE_LICENSE("GPL v2"); 47MODULE_LICENSE("GPL v2");
50 48
51#define PLX_PCI_MAX_CHAN 2 49#define PLX_PCI_MAX_CHAN 2
@@ -123,18 +121,11 @@ struct plx_pci_card {
123#define ESD_PCI_SUB_SYS_ID_PCIE2000 0x0200 121#define ESD_PCI_SUB_SYS_ID_PCIE2000 0x0200
124#define ESD_PCI_SUB_SYS_ID_PCI104200 0x0501 122#define ESD_PCI_SUB_SYS_ID_PCI104200 0x0501
125 123
126#define IXXAT_PCI_VENDOR_ID 0x10b5
127#define IXXAT_PCI_DEVICE_ID 0x9050
128#define IXXAT_PCI_SUB_SYS_ID 0x2540
129
130#define MARATHON_PCI_DEVICE_ID 0x2715 124#define MARATHON_PCI_DEVICE_ID 0x2715
131 125
132#define TEWS_PCI_VENDOR_ID 0x1498 126#define TEWS_PCI_VENDOR_ID 0x1498
133#define TEWS_PCI_DEVICE_ID_TMPC810 0x032A 127#define TEWS_PCI_DEVICE_ID_TMPC810 0x032A
134 128
135#define CTI_PCI_VENDOR_ID 0x12c4
136#define CTI_PCI_DEVICE_ID_CRG001 0x0900
137
138static void plx_pci_reset_common(struct pci_dev *pdev); 129static void plx_pci_reset_common(struct pci_dev *pdev);
139static void plx_pci_reset_marathon(struct pci_dev *pdev); 130static void plx_pci_reset_marathon(struct pci_dev *pdev);
140static void plx9056_pci_reset_common(struct pci_dev *pdev); 131static void plx9056_pci_reset_common(struct pci_dev *pdev);
@@ -162,7 +153,7 @@ struct plx_pci_card_info {
162 void (*reset_func)(struct pci_dev *pdev); 153 void (*reset_func)(struct pci_dev *pdev);
163}; 154};
164 155
165static struct plx_pci_card_info plx_pci_card_info_adlink = { 156static struct plx_pci_card_info plx_pci_card_info_adlink __devinitdata = {
166 "Adlink PCI-7841/cPCI-7841", 2, 157 "Adlink PCI-7841/cPCI-7841", 2,
167 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR, 158 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
168 {1, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x80, 0x80} }, 159 {1, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x80, 0x80} },
@@ -170,7 +161,7 @@ static struct plx_pci_card_info plx_pci_card_info_adlink = {
170 /* based on PLX9052 */ 161 /* based on PLX9052 */
171}; 162};
172 163
173static struct plx_pci_card_info plx_pci_card_info_adlink_se = { 164static struct plx_pci_card_info plx_pci_card_info_adlink_se __devinitdata = {
174 "Adlink PCI-7841/cPCI-7841 SE", 2, 165 "Adlink PCI-7841/cPCI-7841 SE", 2,
175 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR, 166 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
176 {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x80, 0x80} }, 167 {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x80, 0x80} },
@@ -178,7 +169,7 @@ static struct plx_pci_card_info plx_pci_card_info_adlink_se = {
178 /* based on PLX9052 */ 169 /* based on PLX9052 */
179}; 170};
180 171
181static struct plx_pci_card_info plx_pci_card_info_esd200 = { 172static struct plx_pci_card_info plx_pci_card_info_esd200 __devinitdata = {
182 "esd CAN-PCI/CPCI/PCI104/200", 2, 173 "esd CAN-PCI/CPCI/PCI104/200", 2,
183 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR, 174 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
184 {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x100, 0x80} }, 175 {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x100, 0x80} },
@@ -186,7 +177,7 @@ static struct plx_pci_card_info plx_pci_card_info_esd200 = {
186 /* based on PLX9030/9050 */ 177 /* based on PLX9030/9050 */
187}; 178};
188 179
189static struct plx_pci_card_info plx_pci_card_info_esd266 = { 180static struct plx_pci_card_info plx_pci_card_info_esd266 __devinitdata = {
190 "esd CAN-PCI/PMC/266", 2, 181 "esd CAN-PCI/PMC/266", 2,
191 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR, 182 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
192 {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x100, 0x80} }, 183 {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x100, 0x80} },
@@ -194,7 +185,7 @@ static struct plx_pci_card_info plx_pci_card_info_esd266 = {
194 /* based on PLX9056 */ 185 /* based on PLX9056 */
195}; 186};
196 187
197static struct plx_pci_card_info plx_pci_card_info_esd2000 = { 188static struct plx_pci_card_info plx_pci_card_info_esd2000 __devinitdata = {
198 "esd CAN-PCIe/2000", 2, 189 "esd CAN-PCIe/2000", 2,
199 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR, 190 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
200 {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x100, 0x80} }, 191 {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x100, 0x80} },
@@ -202,15 +193,7 @@ static struct plx_pci_card_info plx_pci_card_info_esd2000 = {
202 /* based on PEX8311 */ 193 /* based on PEX8311 */
203}; 194};
204 195
205static struct plx_pci_card_info plx_pci_card_info_ixxat = { 196static struct plx_pci_card_info plx_pci_card_info_marathon __devinitdata = {
206 "IXXAT PC-I 04/PCI", 2,
207 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
208 {0, 0x00, 0x00}, { {2, 0x00, 0x80}, {2, 0x200, 0x80} },
209 &plx_pci_reset_common
210 /* based on PLX9050 */
211};
212
213static struct plx_pci_card_info plx_pci_card_info_marathon = {
214 "Marathon CAN-bus-PCI", 2, 197 "Marathon CAN-bus-PCI", 2,
215 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR, 198 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
216 {0, 0x00, 0x00}, { {2, 0x00, 0x00}, {4, 0x00, 0x00} }, 199 {0, 0x00, 0x00}, { {2, 0x00, 0x00}, {4, 0x00, 0x00} },
@@ -218,7 +201,7 @@ static struct plx_pci_card_info plx_pci_card_info_marathon = {
218 /* based on PLX9052 */ 201 /* based on PLX9052 */
219}; 202};
220 203
221static struct plx_pci_card_info plx_pci_card_info_tews = { 204static struct plx_pci_card_info plx_pci_card_info_tews __devinitdata = {
222 "TEWS TECHNOLOGIES TPMC810", 2, 205 "TEWS TECHNOLOGIES TPMC810", 2,
223 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR, 206 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
224 {0, 0x00, 0x00}, { {2, 0x000, 0x80}, {2, 0x100, 0x80} }, 207 {0, 0x00, 0x00}, { {2, 0x000, 0x80}, {2, 0x100, 0x80} },
@@ -226,14 +209,6 @@ static struct plx_pci_card_info plx_pci_card_info_tews = {
226 /* based on PLX9030 */ 209 /* based on PLX9030 */
227}; 210};
228 211
229static struct plx_pci_card_info plx_pci_card_info_cti = {
230 "Connect Tech Inc. CANpro/104-Plus Opto (CRG001)", 2,
231 PLX_PCI_CAN_CLOCK, PLX_PCI_OCR, PLX_PCI_CDR,
232 {0, 0x00, 0x00}, { {2, 0x000, 0x80}, {2, 0x100, 0x80} },
233 &plx_pci_reset_common
234 /* based on PLX9030 */
235};
236
237static DEFINE_PCI_DEVICE_TABLE(plx_pci_tbl) = { 212static DEFINE_PCI_DEVICE_TABLE(plx_pci_tbl) = {
238 { 213 {
239 /* Adlink PCI-7841/cPCI-7841 */ 214 /* Adlink PCI-7841/cPCI-7841 */
@@ -292,13 +267,6 @@ static DEFINE_PCI_DEVICE_TABLE(plx_pci_tbl) = {
292 (kernel_ulong_t)&plx_pci_card_info_esd2000 267 (kernel_ulong_t)&plx_pci_card_info_esd2000
293 }, 268 },
294 { 269 {
295 /* IXXAT PC-I 04/PCI card */
296 IXXAT_PCI_VENDOR_ID, IXXAT_PCI_DEVICE_ID,
297 PCI_ANY_ID, IXXAT_PCI_SUB_SYS_ID,
298 0, 0,
299 (kernel_ulong_t)&plx_pci_card_info_ixxat
300 },
301 {
302 /* Marathon CAN-bus-PCI card */ 270 /* Marathon CAN-bus-PCI card */
303 PCI_VENDOR_ID_PLX, MARATHON_PCI_DEVICE_ID, 271 PCI_VENDOR_ID_PLX, MARATHON_PCI_DEVICE_ID,
304 PCI_ANY_ID, PCI_ANY_ID, 272 PCI_ANY_ID, PCI_ANY_ID,
@@ -312,13 +280,6 @@ static DEFINE_PCI_DEVICE_TABLE(plx_pci_tbl) = {
312 0, 0, 280 0, 0,
313 (kernel_ulong_t)&plx_pci_card_info_tews 281 (kernel_ulong_t)&plx_pci_card_info_tews
314 }, 282 },
315 {
316 /* Connect Tech Inc. CANpro/104-Plus Opto (CRG001) card */
317 PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030,
318 CTI_PCI_VENDOR_ID, CTI_PCI_DEVICE_ID_CRG001,
319 0, 0,
320 (kernel_ulong_t)&plx_pci_card_info_cti
321 },
322 { 0,} 283 { 0,}
323}; 284};
324MODULE_DEVICE_TABLE(pci, plx_pci_tbl); 285MODULE_DEVICE_TABLE(pci, plx_pci_tbl);
@@ -484,8 +445,8 @@ static void plx_pci_del_card(struct pci_dev *pdev)
484 * Probe PLX90xx based device for the SJA1000 chips and register each 445 * Probe PLX90xx based device for the SJA1000 chips and register each
485 * available CAN channel to SJA1000 Socket-CAN subsystem. 446 * available CAN channel to SJA1000 Socket-CAN subsystem.
486 */ 447 */
487static int plx_pci_add_card(struct pci_dev *pdev, 448static int __devinit plx_pci_add_card(struct pci_dev *pdev,
488 const struct pci_device_id *ent) 449 const struct pci_device_id *ent)
489{ 450{
490 struct sja1000_priv *priv; 451 struct sja1000_priv *priv;
491 struct net_device *dev; 452 struct net_device *dev;
@@ -628,4 +589,15 @@ static struct pci_driver plx_pci_driver = {
628 .remove = plx_pci_del_card, 589 .remove = plx_pci_del_card,
629}; 590};
630 591
631module_pci_driver(plx_pci_driver); 592static int __init plx_pci_init(void)
593{
594 return pci_register_driver(&plx_pci_driver);
595}
596
597static void __exit plx_pci_exit(void)
598{
599 pci_unregister_driver(&plx_pci_driver);
600}
601
602module_init(plx_pci_init);
603module_exit(plx_pci_exit);
diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index 83ee11eca0e..f501bba1fc6 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -40,6 +40,8 @@
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
41 * DAMAGE. 41 * DAMAGE.
42 * 42 *
43 * Send feedback to <socketcan-users@lists.berlios.de>
44 *
43 */ 45 */
44 46
45#include <linux/module.h> 47#include <linux/module.h>
@@ -69,7 +71,7 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
69MODULE_LICENSE("Dual BSD/GPL"); 71MODULE_LICENSE("Dual BSD/GPL");
70MODULE_DESCRIPTION(DRV_NAME "CAN netdevice driver"); 72MODULE_DESCRIPTION(DRV_NAME "CAN netdevice driver");
71 73
72static const struct can_bittiming_const sja1000_bittiming_const = { 74static struct can_bittiming_const sja1000_bittiming_const = {
73 .name = DRV_NAME, 75 .name = DRV_NAME,
74 .tseg1_min = 1, 76 .tseg1_min = 1,
75 .tseg1_max = 16, 77 .tseg1_max = 16,
@@ -95,16 +97,11 @@ static void sja1000_write_cmdreg(struct sja1000_priv *priv, u8 val)
95 spin_unlock_irqrestore(&priv->cmdreg_lock, flags); 97 spin_unlock_irqrestore(&priv->cmdreg_lock, flags);
96} 98}
97 99
98static int sja1000_is_absent(struct sja1000_priv *priv)
99{
100 return (priv->read_reg(priv, REG_MOD) == 0xFF);
101}
102
103static int sja1000_probe_chip(struct net_device *dev) 100static int sja1000_probe_chip(struct net_device *dev)
104{ 101{
105 struct sja1000_priv *priv = netdev_priv(dev); 102 struct sja1000_priv *priv = netdev_priv(dev);
106 103
107 if (priv->reg_base && sja1000_is_absent(priv)) { 104 if (priv->reg_base && (priv->read_reg(priv, 0) == 0xFF)) {
108 printk(KERN_INFO "%s: probing @0x%lX failed\n", 105 printk(KERN_INFO "%s: probing @0x%lX failed\n",
109 DRV_NAME, dev->base_addr); 106 DRV_NAME, dev->base_addr);
110 return 0; 107 return 0;
@@ -133,7 +130,7 @@ static void set_reset_mode(struct net_device *dev)
133 status = priv->read_reg(priv, REG_MOD); 130 status = priv->read_reg(priv, REG_MOD);
134 } 131 }
135 132
136 netdev_err(dev, "setting SJA1000 into reset mode failed!\n"); 133 dev_err(dev->dev.parent, "setting SJA1000 into reset mode failed!\n");
137} 134}
138 135
139static void set_normal_mode(struct net_device *dev) 136static void set_normal_mode(struct net_device *dev)
@@ -156,17 +153,12 @@ static void set_normal_mode(struct net_device *dev)
156 } 153 }
157 154
158 /* set chip to normal mode */ 155 /* set chip to normal mode */
159 if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) 156 priv->write_reg(priv, REG_MOD, 0x00);
160 priv->write_reg(priv, REG_MOD, MOD_LOM);
161 else
162 priv->write_reg(priv, REG_MOD, 0x00);
163
164 udelay(10); 157 udelay(10);
165
166 status = priv->read_reg(priv, REG_MOD); 158 status = priv->read_reg(priv, REG_MOD);
167 } 159 }
168 160
169 netdev_err(dev, "setting SJA1000 into normal mode failed!\n"); 161 dev_err(dev->dev.parent, "setting SJA1000 into normal mode failed!\n");
170} 162}
171 163
172static void sja1000_start(struct net_device *dev) 164static void sja1000_start(struct net_device *dev)
@@ -188,6 +180,11 @@ static void sja1000_start(struct net_device *dev)
188 180
189static int sja1000_set_mode(struct net_device *dev, enum can_mode mode) 181static int sja1000_set_mode(struct net_device *dev, enum can_mode mode)
190{ 182{
183 struct sja1000_priv *priv = netdev_priv(dev);
184
185 if (!priv->open_time)
186 return -EINVAL;
187
191 switch (mode) { 188 switch (mode) {
192 case CAN_MODE_START: 189 case CAN_MODE_START:
193 sja1000_start(dev); 190 sja1000_start(dev);
@@ -214,7 +211,8 @@ static int sja1000_set_bittiming(struct net_device *dev)
214 if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) 211 if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
215 btr1 |= 0x80; 212 btr1 |= 0x80;
216 213
217 netdev_info(dev, "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1); 214 dev_info(dev->dev.parent,
215 "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
218 216
219 priv->write_reg(priv, REG_BTR0, btr0); 217 priv->write_reg(priv, REG_BTR0, btr0);
220 priv->write_reg(priv, REG_BTR1, btr1); 218 priv->write_reg(priv, REG_BTR1, btr1);
@@ -310,10 +308,7 @@ static netdev_tx_t sja1000_start_xmit(struct sk_buff *skb,
310 308
311 can_put_echo_skb(skb, dev, 0); 309 can_put_echo_skb(skb, dev, 0);
312 310
313 if (priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT) 311 sja1000_write_cmdreg(priv, CMD_TR);
314 sja1000_write_cmdreg(priv, CMD_TR | CMD_AT);
315 else
316 sja1000_write_cmdreg(priv, CMD_TR);
317 312
318 return NETDEV_TX_OK; 313 return NETDEV_TX_OK;
319} 314}
@@ -385,7 +380,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
385 380
386 if (isrc & IRQ_DOI) { 381 if (isrc & IRQ_DOI) {
387 /* data overrun interrupt */ 382 /* data overrun interrupt */
388 netdev_dbg(dev, "data overrun interrupt\n"); 383 dev_dbg(dev->dev.parent, "data overrun interrupt\n");
389 cf->can_id |= CAN_ERR_CRTL; 384 cf->can_id |= CAN_ERR_CRTL;
390 cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; 385 cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
391 stats->rx_over_errors++; 386 stats->rx_over_errors++;
@@ -395,7 +390,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
395 390
396 if (isrc & IRQ_EI) { 391 if (isrc & IRQ_EI) {
397 /* error warning interrupt */ 392 /* error warning interrupt */
398 netdev_dbg(dev, "error warning interrupt\n"); 393 dev_dbg(dev->dev.parent, "error warning interrupt\n");
399 394
400 if (status & SR_BS) { 395 if (status & SR_BS) {
401 state = CAN_STATE_BUS_OFF; 396 state = CAN_STATE_BUS_OFF;
@@ -436,7 +431,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
436 } 431 }
437 if (isrc & IRQ_EPI) { 432 if (isrc & IRQ_EPI) {
438 /* error passive interrupt */ 433 /* error passive interrupt */
439 netdev_dbg(dev, "error passive interrupt\n"); 434 dev_dbg(dev->dev.parent, "error passive interrupt\n");
440 if (status & SR_ES) 435 if (status & SR_ES)
441 state = CAN_STATE_ERROR_PASSIVE; 436 state = CAN_STATE_ERROR_PASSIVE;
442 else 437 else
@@ -444,7 +439,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
444 } 439 }
445 if (isrc & IRQ_ALI) { 440 if (isrc & IRQ_ALI) {
446 /* arbitration lost interrupt */ 441 /* arbitration lost interrupt */
447 netdev_dbg(dev, "arbitration lost interrupt\n"); 442 dev_dbg(dev->dev.parent, "arbitration lost interrupt\n");
448 alc = priv->read_reg(priv, REG_ALC); 443 alc = priv->read_reg(priv, REG_ALC);
449 priv->can.can_stats.arbitration_lost++; 444 priv->can.can_stats.arbitration_lost++;
450 stats->tx_errors++; 445 stats->tx_errors++;
@@ -500,26 +495,15 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
500 while ((isrc = priv->read_reg(priv, REG_IR)) && (n < SJA1000_MAX_IRQ)) { 495 while ((isrc = priv->read_reg(priv, REG_IR)) && (n < SJA1000_MAX_IRQ)) {
501 n++; 496 n++;
502 status = priv->read_reg(priv, REG_SR); 497 status = priv->read_reg(priv, REG_SR);
503 /* check for absent controller due to hw unplug */
504 if (status == 0xFF && sja1000_is_absent(priv))
505 return IRQ_NONE;
506 498
507 if (isrc & IRQ_WUI) 499 if (isrc & IRQ_WUI)
508 netdev_warn(dev, "wakeup interrupt\n"); 500 dev_warn(dev->dev.parent, "wakeup interrupt\n");
509 501
510 if (isrc & IRQ_TI) { 502 if (isrc & IRQ_TI) {
511 /* transmission buffer released */ 503 /* transmission complete interrupt */
512 if (priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT && 504 stats->tx_bytes += priv->read_reg(priv, REG_FI) & 0xf;
513 !(status & SR_TCS)) { 505 stats->tx_packets++;
514 stats->tx_errors++; 506 can_get_echo_skb(dev, 0);
515 can_free_echo_skb(dev, 0);
516 } else {
517 /* transmission complete */
518 stats->tx_bytes +=
519 priv->read_reg(priv, REG_FI) & 0xf;
520 stats->tx_packets++;
521 can_get_echo_skb(dev, 0);
522 }
523 netif_wake_queue(dev); 507 netif_wake_queue(dev);
524 } 508 }
525 if (isrc & IRQ_RI) { 509 if (isrc & IRQ_RI) {
@@ -527,9 +511,6 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
527 while (status & SR_RBS) { 511 while (status & SR_RBS) {
528 sja1000_rx(dev); 512 sja1000_rx(dev);
529 status = priv->read_reg(priv, REG_SR); 513 status = priv->read_reg(priv, REG_SR);
530 /* check for absent controller */
531 if (status == 0xFF && sja1000_is_absent(priv))
532 return IRQ_NONE;
533 } 514 }
534 } 515 }
535 if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) { 516 if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) {
@@ -543,7 +524,7 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
543 priv->post_irq(priv); 524 priv->post_irq(priv);
544 525
545 if (n >= SJA1000_MAX_IRQ) 526 if (n >= SJA1000_MAX_IRQ)
546 netdev_dbg(dev, "%d messages handled in ISR", n); 527 dev_dbg(dev->dev.parent, "%d messages handled in ISR", n);
547 528
548 return (n) ? IRQ_HANDLED : IRQ_NONE; 529 return (n) ? IRQ_HANDLED : IRQ_NONE;
549} 530}
@@ -574,6 +555,7 @@ static int sja1000_open(struct net_device *dev)
574 555
575 /* init and start chi */ 556 /* init and start chi */
576 sja1000_start(dev); 557 sja1000_start(dev);
558 priv->open_time = jiffies;
577 559
578 netif_start_queue(dev); 560 netif_start_queue(dev);
579 561
@@ -592,6 +574,8 @@ static int sja1000_close(struct net_device *dev)
592 574
593 close_candev(dev); 575 close_candev(dev);
594 576
577 priv->open_time = 0;
578
595 return 0; 579 return 0;
596} 580}
597 581
@@ -613,8 +597,7 @@ struct net_device *alloc_sja1000dev(int sizeof_priv)
613 priv->can.do_set_mode = sja1000_set_mode; 597 priv->can.do_set_mode = sja1000_set_mode;
614 priv->can.do_get_berr_counter = sja1000_get_berr_counter; 598 priv->can.do_get_berr_counter = sja1000_get_berr_counter;
615 priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES | 599 priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES |
616 CAN_CTRLMODE_BERR_REPORTING | CAN_CTRLMODE_LISTENONLY | 600 CAN_CTRLMODE_BERR_REPORTING;
617 CAN_CTRLMODE_ONE_SHOT;
618 601
619 spin_lock_init(&priv->cmdreg_lock); 602 spin_lock_init(&priv->cmdreg_lock);
620 603
diff --git a/drivers/net/can/sja1000/sja1000.h b/drivers/net/can/sja1000/sja1000.h
index afa99847a51..78bd4ecac14 100644
--- a/drivers/net/can/sja1000/sja1000.h
+++ b/drivers/net/can/sja1000/sja1000.h
@@ -40,6 +40,8 @@
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
41 * DAMAGE. 41 * DAMAGE.
42 * 42 *
43 * Send feedback to <socketcan-users@lists.berlios.de>
44 *
43 */ 45 */
44 46
45#ifndef SJA1000_DEV_H 47#ifndef SJA1000_DEV_H
@@ -152,6 +154,7 @@
152 */ 154 */
153struct sja1000_priv { 155struct sja1000_priv {
154 struct can_priv can; /* must be the first member */ 156 struct can_priv can; /* must be the first member */
157 int open_time;
155 struct sk_buff *echo_skb; 158 struct sk_buff *echo_skb;
156 159
157 /* the lower-layer is responsible for appropriate locking */ 160 /* the lower-layer is responsible for appropriate locking */
diff --git a/drivers/net/can/sja1000/sja1000_isa.c b/drivers/net/can/sja1000/sja1000_isa.c
index 5c8da466148..496223e9e2f 100644
--- a/drivers/net/can/sja1000/sja1000_isa.c
+++ b/drivers/net/can/sja1000/sja1000_isa.c
@@ -17,7 +17,7 @@
17 17
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/platform_device.h> 20#include <linux/isa.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/netdevice.h> 22#include <linux/netdevice.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
@@ -42,11 +42,11 @@ MODULE_LICENSE("GPL v2");
42 42
43static unsigned long port[MAXDEV]; 43static unsigned long port[MAXDEV];
44static unsigned long mem[MAXDEV]; 44static unsigned long mem[MAXDEV];
45static int irq[MAXDEV]; 45static int __devinitdata irq[MAXDEV];
46static int clk[MAXDEV]; 46static int __devinitdata clk[MAXDEV];
47static unsigned char cdr[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff}; 47static char __devinitdata cdr[MAXDEV] = {[0 ... (MAXDEV - 1)] = -1};
48static unsigned char ocr[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff}; 48static char __devinitdata ocr[MAXDEV] = {[0 ... (MAXDEV - 1)] = -1};
49static int indirect[MAXDEV] = {[0 ... (MAXDEV - 1)] = -1}; 49static char __devinitdata indirect[MAXDEV] = {[0 ... (MAXDEV - 1)] = -1};
50 50
51module_param_array(port, ulong, NULL, S_IRUGO); 51module_param_array(port, ulong, NULL, S_IRUGO);
52MODULE_PARM_DESC(port, "I/O port number"); 52MODULE_PARM_DESC(port, "I/O port number");
@@ -54,7 +54,7 @@ MODULE_PARM_DESC(port, "I/O port number");
54module_param_array(mem, ulong, NULL, S_IRUGO); 54module_param_array(mem, ulong, NULL, S_IRUGO);
55MODULE_PARM_DESC(mem, "I/O memory address"); 55MODULE_PARM_DESC(mem, "I/O memory address");
56 56
57module_param_array(indirect, int, NULL, S_IRUGO); 57module_param_array(indirect, byte, NULL, S_IRUGO);
58MODULE_PARM_DESC(indirect, "Indirect access via address and data port"); 58MODULE_PARM_DESC(indirect, "Indirect access via address and data port");
59 59
60module_param_array(irq, int, NULL, S_IRUGO); 60module_param_array(irq, int, NULL, S_IRUGO);
@@ -75,8 +75,6 @@ MODULE_PARM_DESC(ocr, "Output control register "
75#define SJA1000_IOSIZE 0x20 75#define SJA1000_IOSIZE 0x20
76#define SJA1000_IOSIZE_INDIRECT 0x02 76#define SJA1000_IOSIZE_INDIRECT 0x02
77 77
78static struct platform_device *sja1000_isa_devs[MAXDEV];
79
80static u8 sja1000_isa_mem_read_reg(const struct sja1000_priv *priv, int reg) 78static u8 sja1000_isa_mem_read_reg(const struct sja1000_priv *priv, int reg)
81{ 79{
82 return readb(priv->reg_base + reg); 80 return readb(priv->reg_base + reg);
@@ -117,18 +115,26 @@ static void sja1000_isa_port_write_reg_indirect(const struct sja1000_priv *priv,
117 outb(val, base + 1); 115 outb(val, base + 1);
118} 116}
119 117
120static int sja1000_isa_probe(struct platform_device *pdev) 118static int __devinit sja1000_isa_match(struct device *pdev, unsigned int idx)
119{
120 if (port[idx] || mem[idx]) {
121 if (irq[idx])
122 return 1;
123 } else if (idx)
124 return 0;
125
126 dev_err(pdev, "insufficient parameters supplied\n");
127 return 0;
128}
129
130static int __devinit sja1000_isa_probe(struct device *pdev, unsigned int idx)
121{ 131{
122 struct net_device *dev; 132 struct net_device *dev;
123 struct sja1000_priv *priv; 133 struct sja1000_priv *priv;
124 void __iomem *base = NULL; 134 void __iomem *base = NULL;
125 int iosize = SJA1000_IOSIZE; 135 int iosize = SJA1000_IOSIZE;
126 int idx = pdev->id;
127 int err; 136 int err;
128 137
129 dev_dbg(&pdev->dev, "probing idx=%d: port=%#lx, mem=%#lx, irq=%d\n",
130 idx, port[idx], mem[idx], irq[idx]);
131
132 if (mem[idx]) { 138 if (mem[idx]) {
133 if (!request_mem_region(mem[idx], iosize, DRV_NAME)) { 139 if (!request_mem_region(mem[idx], iosize, DRV_NAME)) {
134 err = -EBUSY; 140 err = -EBUSY;
@@ -183,31 +189,31 @@ static int sja1000_isa_probe(struct platform_device *pdev)
183 else 189 else
184 priv->can.clock.freq = CLK_DEFAULT / 2; 190 priv->can.clock.freq = CLK_DEFAULT / 2;
185 191
186 if (ocr[idx] != 0xff) 192 if (ocr[idx] != -1)
187 priv->ocr = ocr[idx]; 193 priv->ocr = ocr[idx] & 0xff;
188 else if (ocr[0] != 0xff) 194 else if (ocr[0] != -1)
189 priv->ocr = ocr[0]; 195 priv->ocr = ocr[0] & 0xff;
190 else 196 else
191 priv->ocr = OCR_DEFAULT; 197 priv->ocr = OCR_DEFAULT;
192 198
193 if (cdr[idx] != 0xff) 199 if (cdr[idx] != -1)
194 priv->cdr = cdr[idx]; 200 priv->cdr = cdr[idx] & 0xff;
195 else if (cdr[0] != 0xff) 201 else if (cdr[0] != -1)
196 priv->cdr = cdr[0]; 202 priv->cdr = cdr[0] & 0xff;
197 else 203 else
198 priv->cdr = CDR_DEFAULT; 204 priv->cdr = CDR_DEFAULT;
199 205
200 dev_set_drvdata(&pdev->dev, dev); 206 dev_set_drvdata(pdev, dev);
201 SET_NETDEV_DEV(dev, &pdev->dev); 207 SET_NETDEV_DEV(dev, pdev);
202 208
203 err = register_sja1000dev(dev); 209 err = register_sja1000dev(dev);
204 if (err) { 210 if (err) {
205 dev_err(&pdev->dev, "registering %s failed (err=%d)\n", 211 dev_err(pdev, "registering %s failed (err=%d)\n",
206 DRV_NAME, err); 212 DRV_NAME, err);
207 goto exit_unmap; 213 goto exit_unmap;
208 } 214 }
209 215
210 dev_info(&pdev->dev, "%s device registered (reg_base=0x%p, irq=%d)\n", 216 dev_info(pdev, "%s device registered (reg_base=0x%p, irq=%d)\n",
211 DRV_NAME, priv->reg_base, dev->irq); 217 DRV_NAME, priv->reg_base, dev->irq);
212 return 0; 218 return 0;
213 219
@@ -223,14 +229,13 @@ static int sja1000_isa_probe(struct platform_device *pdev)
223 return err; 229 return err;
224} 230}
225 231
226static int sja1000_isa_remove(struct platform_device *pdev) 232static int __devexit sja1000_isa_remove(struct device *pdev, unsigned int idx)
227{ 233{
228 struct net_device *dev = dev_get_drvdata(&pdev->dev); 234 struct net_device *dev = dev_get_drvdata(pdev);
229 struct sja1000_priv *priv = netdev_priv(dev); 235 struct sja1000_priv *priv = netdev_priv(dev);
230 int idx = pdev->id;
231 236
232 unregister_sja1000dev(dev); 237 unregister_sja1000dev(dev);
233 dev_set_drvdata(&pdev->dev, NULL); 238 dev_set_drvdata(pdev, NULL);
234 239
235 if (mem[idx]) { 240 if (mem[idx]) {
236 iounmap(priv->reg_base); 241 iounmap(priv->reg_base);
@@ -246,70 +251,29 @@ static int sja1000_isa_remove(struct platform_device *pdev)
246 return 0; 251 return 0;
247} 252}
248 253
249static struct platform_driver sja1000_isa_driver = { 254static struct isa_driver sja1000_isa_driver = {
255 .match = sja1000_isa_match,
250 .probe = sja1000_isa_probe, 256 .probe = sja1000_isa_probe,
251 .remove = sja1000_isa_remove, 257 .remove = __devexit_p(sja1000_isa_remove),
252 .driver = { 258 .driver = {
253 .name = DRV_NAME, 259 .name = DRV_NAME,
254 .owner = THIS_MODULE,
255 }, 260 },
256}; 261};
257 262
258static int __init sja1000_isa_init(void) 263static int __init sja1000_isa_init(void)
259{ 264{
260 int idx, err; 265 int err = isa_register_driver(&sja1000_isa_driver, MAXDEV);
261
262 for (idx = 0; idx < MAXDEV; idx++) {
263 if ((port[idx] || mem[idx]) && irq[idx]) {
264 sja1000_isa_devs[idx] =
265 platform_device_alloc(DRV_NAME, idx);
266 if (!sja1000_isa_devs[idx]) {
267 err = -ENOMEM;
268 goto exit_free_devices;
269 }
270 err = platform_device_add(sja1000_isa_devs[idx]);
271 if (err) {
272 platform_device_put(sja1000_isa_devs[idx]);
273 goto exit_free_devices;
274 }
275 pr_debug("%s: platform device %d: port=%#lx, mem=%#lx, "
276 "irq=%d\n",
277 DRV_NAME, idx, port[idx], mem[idx], irq[idx]);
278 } else if (idx == 0 || port[idx] || mem[idx]) {
279 pr_err("%s: insufficient parameters supplied\n",
280 DRV_NAME);
281 err = -EINVAL;
282 goto exit_free_devices;
283 }
284 }
285
286 err = platform_driver_register(&sja1000_isa_driver);
287 if (err)
288 goto exit_free_devices;
289
290 pr_info("Legacy %s driver for max. %d devices registered\n",
291 DRV_NAME, MAXDEV);
292
293 return 0;
294
295exit_free_devices:
296 while (--idx >= 0) {
297 if (sja1000_isa_devs[idx])
298 platform_device_unregister(sja1000_isa_devs[idx]);
299 }
300 266
267 if (!err)
268 printk(KERN_INFO
269 "Legacy %s driver for max. %d devices registered\n",
270 DRV_NAME, MAXDEV);
301 return err; 271 return err;
302} 272}
303 273
304static void __exit sja1000_isa_exit(void) 274static void __exit sja1000_isa_exit(void)
305{ 275{
306 int idx; 276 isa_unregister_driver(&sja1000_isa_driver);
307
308 platform_driver_unregister(&sja1000_isa_driver);
309 for (idx = 0; idx < MAXDEV; idx++) {
310 if (sja1000_isa_devs[idx])
311 platform_device_unregister(sja1000_isa_devs[idx]);
312 }
313} 277}
314 278
315module_init(sja1000_isa_init); 279module_init(sja1000_isa_init);
diff --git a/drivers/net/can/sja1000/sja1000_of_platform.c b/drivers/net/can/sja1000/sja1000_of_platform.c
index 6433b81256c..cee6ba2b8b5 100644
--- a/drivers/net/can/sja1000/sja1000_of_platform.c
+++ b/drivers/net/can/sja1000/sja1000_of_platform.c
@@ -29,7 +29,7 @@
29 * nxp,external-clock-frequency = <16000000>; 29 * nxp,external-clock-frequency = <16000000>;
30 * }; 30 * };
31 * 31 *
32 * See "Documentation/devicetree/bindings/net/can/sja1000.txt" for further 32 * See "Documentation/powerpc/dts-bindings/can/sja1000.txt" for further
33 * information. 33 * information.
34 */ 34 */
35 35
@@ -42,8 +42,6 @@
42#include <linux/can/dev.h> 42#include <linux/can/dev.h>
43 43
44#include <linux/of_platform.h> 44#include <linux/of_platform.h>
45#include <linux/of_address.h>
46#include <linux/of_irq.h>
47#include <asm/prom.h> 45#include <asm/prom.h>
48 46
49#include "sja1000.h" 47#include "sja1000.h"
@@ -61,16 +59,16 @@ MODULE_LICENSE("GPL v2");
61 59
62static u8 sja1000_ofp_read_reg(const struct sja1000_priv *priv, int reg) 60static u8 sja1000_ofp_read_reg(const struct sja1000_priv *priv, int reg)
63{ 61{
64 return ioread8(priv->reg_base + reg); 62 return in_8(priv->reg_base + reg);
65} 63}
66 64
67static void sja1000_ofp_write_reg(const struct sja1000_priv *priv, 65static void sja1000_ofp_write_reg(const struct sja1000_priv *priv,
68 int reg, u8 val) 66 int reg, u8 val)
69{ 67{
70 iowrite8(val, priv->reg_base + reg); 68 out_8(priv->reg_base + reg, val);
71} 69}
72 70
73static int sja1000_ofp_remove(struct platform_device *ofdev) 71static int __devexit sja1000_ofp_remove(struct platform_device *ofdev)
74{ 72{
75 struct net_device *dev = dev_get_drvdata(&ofdev->dev); 73 struct net_device *dev = dev_get_drvdata(&ofdev->dev);
76 struct sja1000_priv *priv = netdev_priv(dev); 74 struct sja1000_priv *priv = netdev_priv(dev);
@@ -90,7 +88,7 @@ static int sja1000_ofp_remove(struct platform_device *ofdev)
90 return 0; 88 return 0;
91} 89}
92 90
93static int sja1000_ofp_probe(struct platform_device *ofdev) 91static int __devinit sja1000_ofp_probe(struct platform_device *ofdev)
94{ 92{
95 struct device_node *np = ofdev->dev.of_node; 93 struct device_node *np = ofdev->dev.of_node;
96 struct net_device *dev; 94 struct net_device *dev;
@@ -121,7 +119,7 @@ static int sja1000_ofp_probe(struct platform_device *ofdev)
121 } 119 }
122 120
123 irq = irq_of_parse_and_map(np, 0); 121 irq = irq_of_parse_and_map(np, 0);
124 if (irq == 0) { 122 if (irq == NO_IRQ) {
125 dev_err(&ofdev->dev, "no irq found\n"); 123 dev_err(&ofdev->dev, "no irq found\n");
126 err = -ENODEV; 124 err = -ENODEV;
127 goto exit_unmap_mem; 125 goto exit_unmap_mem;
@@ -206,7 +204,7 @@ exit_release_mem:
206 return err; 204 return err;
207} 205}
208 206
209static struct of_device_id sja1000_ofp_table[] = { 207static struct of_device_id __devinitdata sja1000_ofp_table[] = {
210 {.compatible = "nxp,sja1000"}, 208 {.compatible = "nxp,sja1000"},
211 {}, 209 {},
212}; 210};
@@ -219,7 +217,17 @@ static struct platform_driver sja1000_ofp_driver = {
219 .of_match_table = sja1000_ofp_table, 217 .of_match_table = sja1000_ofp_table,
220 }, 218 },
221 .probe = sja1000_ofp_probe, 219 .probe = sja1000_ofp_probe,
222 .remove = sja1000_ofp_remove, 220 .remove = __devexit_p(sja1000_ofp_remove),
223}; 221};
224 222
225module_platform_driver(sja1000_ofp_driver); 223static int __init sja1000_ofp_init(void)
224{
225 return platform_driver_register(&sja1000_ofp_driver);
226}
227module_init(sja1000_ofp_init);
228
229static void __exit sja1000_ofp_exit(void)
230{
231 return platform_driver_unregister(&sja1000_ofp_driver);
232};
233module_exit(sja1000_ofp_exit);
diff --git a/drivers/net/can/sja1000/sja1000_platform.c b/drivers/net/can/sja1000/sja1000_platform.c
index 21619bb5b86..d9fadc489b3 100644
--- a/drivers/net/can/sja1000/sja1000_platform.c
+++ b/drivers/net/can/sja1000/sja1000_platform.c
@@ -34,7 +34,6 @@
34 34
35MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); 35MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
36MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the platform bus"); 36MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the platform bus");
37MODULE_ALIAS("platform:" DRV_NAME);
38MODULE_LICENSE("GPL v2"); 37MODULE_LICENSE("GPL v2");
39 38
40static u8 sp_read_reg8(const struct sja1000_priv *priv, int reg) 39static u8 sp_read_reg8(const struct sja1000_priv *priv, int reg)
@@ -110,9 +109,7 @@ static int sp_probe(struct platform_device *pdev)
110 priv = netdev_priv(dev); 109 priv = netdev_priv(dev);
111 110
112 dev->irq = res_irq->start; 111 dev->irq = res_irq->start;
113 priv->irq_flags = res_irq->flags & IRQF_TRIGGER_MASK; 112 priv->irq_flags = res_irq->flags & (IRQF_TRIGGER_MASK | IRQF_SHARED);
114 if (res_irq->flags & IORESOURCE_IRQ_SHAREABLE)
115 priv->irq_flags |= IRQF_SHARED;
116 priv->reg_base = addr; 113 priv->reg_base = addr;
117 /* The CAN clock frequency is half the oscillator clock frequency */ 114 /* The CAN clock frequency is half the oscillator clock frequency */
118 priv->can.clock.freq = pdata->osc_freq / 2; 115 priv->can.clock.freq = pdata->osc_freq / 2;
@@ -188,4 +185,15 @@ static struct platform_driver sp_driver = {
188 }, 185 },
189}; 186};
190 187
191module_platform_driver(sp_driver); 188static int __init sp_init(void)
189{
190 return platform_driver_register(&sp_driver);
191}
192
193static void __exit sp_exit(void)
194{
195 platform_driver_unregister(&sp_driver);
196}
197
198module_init(sp_init);
199module_exit(sp_exit);
diff --git a/drivers/net/can/sja1000/tscan1.c b/drivers/net/can/sja1000/tscan1.c
index 76513dd780c..9756099a883 100644
--- a/drivers/net/can/sja1000/tscan1.c
+++ b/drivers/net/can/sja1000/tscan1.c
@@ -71,7 +71,7 @@ MODULE_LICENSE("GPL");
71#define TSCAN1_SJA1000_XTAL 16000000 71#define TSCAN1_SJA1000_XTAL 16000000
72 72
73/* SJA1000 IO base addresses */ 73/* SJA1000 IO base addresses */
74static const unsigned short tscan1_sja1000_addresses[] = { 74static const unsigned short tscan1_sja1000_addresses[] __devinitconst = {
75 0x100, 0x120, 0x180, 0x1a0, 0x200, 0x240, 0x280, 0x320 75 0x100, 0x120, 0x180, 0x1a0, 0x200, 0x240, 0x280, 0x320
76}; 76};
77 77
@@ -88,7 +88,7 @@ static void tscan1_write(const struct sja1000_priv *priv, int reg, u8 val)
88} 88}
89 89
90/* Probe for a TS-CAN1 board with JP2:JP1 jumper setting ID */ 90/* Probe for a TS-CAN1 board with JP2:JP1 jumper setting ID */
91static int tscan1_probe(struct device *dev, unsigned id) 91static int __devinit tscan1_probe(struct device *dev, unsigned id)
92{ 92{
93 struct net_device *netdev; 93 struct net_device *netdev;
94 struct sja1000_priv *priv; 94 struct sja1000_priv *priv;
@@ -171,7 +171,7 @@ static int tscan1_probe(struct device *dev, unsigned id)
171 return -ENXIO; 171 return -ENXIO;
172} 172}
173 173
174static int tscan1_remove(struct device *dev, unsigned id /*unused*/) 174static int __devexit tscan1_remove(struct device *dev, unsigned id /*unused*/)
175{ 175{
176 struct net_device *netdev; 176 struct net_device *netdev;
177 struct sja1000_priv *priv; 177 struct sja1000_priv *priv;
@@ -197,7 +197,7 @@ static int tscan1_remove(struct device *dev, unsigned id /*unused*/)
197 197
198static struct isa_driver tscan1_isa_driver = { 198static struct isa_driver tscan1_isa_driver = {
199 .probe = tscan1_probe, 199 .probe = tscan1_probe,
200 .remove = tscan1_remove, 200 .remove = __devexit_p(tscan1_remove),
201 .driver = { 201 .driver = {
202 .name = "tscan1", 202 .name = "tscan1",
203 }, 203 },