diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-25 07:25:22 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-10-25 07:25:22 -0400 |
commit | 8a9ea3237e7eb5c25f09e429ad242ae5a3d5ea22 (patch) | |
tree | a0a63398a9983667d52cbbbf4e2405b4f22b1d83 /drivers/net/can/sja1000 | |
parent | 1be025d3cb40cd295123af2c394f7229ef9b30ca (diff) | |
parent | 8b3408f8ee994973869d8ba32c5bf482bc4ddca4 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1745 commits)
dp83640: free packet queues on remove
dp83640: use proper function to free transmit time stamping packets
ipv6: Do not use routes from locally generated RAs
|PATCH net-next] tg3: add tx_dropped counter
be2net: don't create multiple RX/TX rings in multi channel mode
be2net: don't create multiple TXQs in BE2
be2net: refactor VF setup/teardown code into be_vf_setup/clear()
be2net: add vlan/rx-mode/flow-control config to be_setup()
net_sched: cls_flow: use skb_header_pointer()
ipv4: avoid useless call of the function check_peer_pmtu
TCP: remove TCP_DEBUG
net: Fix driver name for mdio-gpio.c
ipv4: tcp: fix TOS value in ACK messages sent from TIME_WAIT
rtnetlink: Add missing manual netlink notification in dev_change_net_namespaces
ipv4: fix ipsec forward performance regression
jme: fix irq storm after suspend/resume
route: fix ICMP redirect validation
net: hold sock reference while processing tx timestamps
tcp: md5: add more const attributes
Add ethtool -g support to virtio_net
...
Fix up conflicts in:
- drivers/net/Kconfig:
The split-up generated a trivial conflict with removal of a
stale reference to Documentation/networking/net-modules.txt.
Remove it from the new location instead.
- fs/sysfs/dir.c:
Fairly nasty conflicts with the sysfs rb-tree usage, conflicting
with Eric Biederman's changes for tagged directories.
Diffstat (limited to 'drivers/net/can/sja1000')
-rw-r--r-- | drivers/net/can/sja1000/Kconfig | 14 | ||||
-rw-r--r-- | drivers/net/can/sja1000/Makefile | 2 | ||||
-rw-r--r-- | drivers/net/can/sja1000/ems_pcmcia.c | 331 | ||||
-rw-r--r-- | drivers/net/can/sja1000/peak_pci.c | 291 | ||||
-rw-r--r-- | drivers/net/can/sja1000/sja1000.c | 2 | ||||
-rw-r--r-- | drivers/net/can/sja1000/sja1000.h | 2 |
6 files changed, 638 insertions, 4 deletions
diff --git a/drivers/net/can/sja1000/Kconfig b/drivers/net/can/sja1000/Kconfig index 6fdc031daaa..fe9e64d476e 100644 --- a/drivers/net/can/sja1000/Kconfig +++ b/drivers/net/can/sja1000/Kconfig | |||
@@ -29,6 +29,13 @@ config CAN_SJA1000_OF_PLATFORM | |||
29 | OpenFirmware bindings, e.g. if you have a PowerPC based system | 29 | OpenFirmware bindings, e.g. if you have a PowerPC based system |
30 | you may want to enable this option. | 30 | you may want to enable this option. |
31 | 31 | ||
32 | config CAN_EMS_PCMCIA | ||
33 | tristate "EMS CPC-CARD Card" | ||
34 | depends on PCMCIA | ||
35 | ---help--- | ||
36 | This driver is for the one or two channel CPC-CARD cards from | ||
37 | EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de). | ||
38 | |||
32 | config CAN_EMS_PCI | 39 | config CAN_EMS_PCI |
33 | tristate "EMS CPC-PCI, CPC-PCIe and CPC-104P Card" | 40 | tristate "EMS CPC-PCI, CPC-PCIe and CPC-104P Card" |
34 | depends on PCI | 41 | depends on PCI |
@@ -37,6 +44,13 @@ config CAN_EMS_PCI | |||
37 | CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche | 44 | CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche |
38 | (http://www.ems-wuensche.de). | 45 | (http://www.ems-wuensche.de). |
39 | 46 | ||
47 | config CAN_PEAK_PCI | ||
48 | tristate "PEAK PCAN PCI/PCIe Cards" | ||
49 | depends on PCI | ||
50 | ---help--- | ||
51 | This driver is for the PCAN PCI/PCIe cards (1, 2, 3 or 4 channels) | ||
52 | from PEAK Systems (http://www.peak-system.com). | ||
53 | |||
40 | config CAN_KVASER_PCI | 54 | config CAN_KVASER_PCI |
41 | tristate "Kvaser PCIcanx and Kvaser PCIcan PCI Cards" | 55 | tristate "Kvaser PCIcanx and Kvaser PCIcan PCI Cards" |
42 | depends on PCI | 56 | depends on PCI |
diff --git a/drivers/net/can/sja1000/Makefile b/drivers/net/can/sja1000/Makefile index 2c591eb321c..0604f240c8b 100644 --- a/drivers/net/can/sja1000/Makefile +++ b/drivers/net/can/sja1000/Makefile | |||
@@ -6,8 +6,10 @@ obj-$(CONFIG_CAN_SJA1000) += sja1000.o | |||
6 | obj-$(CONFIG_CAN_SJA1000_ISA) += sja1000_isa.o | 6 | obj-$(CONFIG_CAN_SJA1000_ISA) += sja1000_isa.o |
7 | obj-$(CONFIG_CAN_SJA1000_PLATFORM) += sja1000_platform.o | 7 | obj-$(CONFIG_CAN_SJA1000_PLATFORM) += sja1000_platform.o |
8 | obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o | 8 | obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o |
9 | obj-$(CONFIG_CAN_EMS_PCMCIA) += ems_pcmcia.o | ||
9 | obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o | 10 | obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o |
10 | obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o | 11 | obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o |
12 | obj-$(CONFIG_CAN_PEAK_PCI) += peak_pci.o | ||
11 | obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o | 13 | obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o |
12 | obj-$(CONFIG_CAN_TSCAN1) += tscan1.o | 14 | obj-$(CONFIG_CAN_TSCAN1) += tscan1.o |
13 | 15 | ||
diff --git a/drivers/net/can/sja1000/ems_pcmcia.c b/drivers/net/can/sja1000/ems_pcmcia.c new file mode 100644 index 00000000000..075a5457a19 --- /dev/null +++ b/drivers/net/can/sja1000/ems_pcmcia.c | |||
@@ -0,0 +1,331 @@ | |||
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 | |||
30 | MODULE_AUTHOR("Markus Plessing <plessing@ems-wuensche.com>"); | ||
31 | MODULE_DESCRIPTION("Socket-CAN driver for EMS CPC-CARD cards"); | ||
32 | MODULE_SUPPORTED_DEVICE("EMS CPC-CARD CAN card"); | ||
33 | MODULE_LICENSE("GPL v2"); | ||
34 | |||
35 | #define EMS_PCMCIA_MAX_CHAN 2 | ||
36 | |||
37 | struct 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 | |||
71 | static 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 | |||
77 | MODULE_DEVICE_TABLE(pcmcia, ems_pcmcia_tbl); | ||
78 | |||
79 | static u8 ems_pcmcia_read_reg(const struct sja1000_priv *priv, int port) | ||
80 | { | ||
81 | return readb(priv->reg_base + port); | ||
82 | } | ||
83 | |||
84 | static 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 | |||
90 | static 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 | */ | ||
126 | static 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 | |||
139 | static 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 | */ | ||
169 | static int __devinit ems_pcmcia_add_card(struct pcmcia_device *pdev, | ||
170 | unsigned long base) | ||
171 | { | ||
172 | struct sja1000_priv *priv; | ||
173 | struct net_device *dev; | ||
174 | struct ems_pcmcia_card *card; | ||
175 | int err, i; | ||
176 | |||
177 | /* Allocating card structures to hold addresses, ... */ | ||
178 | card = kzalloc(sizeof(struct ems_pcmcia_card), GFP_KERNEL); | ||
179 | if (!card) | ||
180 | return -ENOMEM; | ||
181 | |||
182 | pdev->priv = card; | ||
183 | card->channels = 0; | ||
184 | |||
185 | card->base_addr = ioremap(base, EMS_PCMCIA_MEM_SIZE); | ||
186 | if (!card->base_addr) { | ||
187 | err = -ENOMEM; | ||
188 | goto failure_cleanup; | ||
189 | } | ||
190 | |||
191 | /* Check for unique EMS CAN signature */ | ||
192 | if (readw(card->base_addr) != 0xAA55) { | ||
193 | err = -ENODEV; | ||
194 | goto failure_cleanup; | ||
195 | } | ||
196 | |||
197 | /* Request board reset */ | ||
198 | writeb(EMS_CMD_RESET, card->base_addr); | ||
199 | |||
200 | /* Make sure CAN controllers are mapped into card's memory space */ | ||
201 | writeb(EMS_CMD_MAP, card->base_addr); | ||
202 | |||
203 | /* Detect available channels */ | ||
204 | for (i = 0; i < EMS_PCMCIA_MAX_CHAN; i++) { | ||
205 | dev = alloc_sja1000dev(0); | ||
206 | if (!dev) { | ||
207 | err = -ENOMEM; | ||
208 | goto failure_cleanup; | ||
209 | } | ||
210 | |||
211 | card->net_dev[i] = dev; | ||
212 | priv = netdev_priv(dev); | ||
213 | priv->priv = card; | ||
214 | SET_NETDEV_DEV(dev, &pdev->dev); | ||
215 | |||
216 | priv->irq_flags = IRQF_SHARED; | ||
217 | dev->irq = pdev->irq; | ||
218 | priv->reg_base = card->base_addr + EMS_PCMCIA_CAN_BASE_OFFSET + | ||
219 | (i * EMS_PCMCIA_CAN_CTRL_SIZE); | ||
220 | |||
221 | /* Check if channel is present */ | ||
222 | if (ems_pcmcia_check_chan(priv)) { | ||
223 | priv->read_reg = ems_pcmcia_read_reg; | ||
224 | priv->write_reg = ems_pcmcia_write_reg; | ||
225 | priv->can.clock.freq = EMS_PCMCIA_CAN_CLOCK; | ||
226 | priv->ocr = EMS_PCMCIA_OCR; | ||
227 | priv->cdr = EMS_PCMCIA_CDR; | ||
228 | priv->flags |= SJA1000_CUSTOM_IRQ_HANDLER; | ||
229 | |||
230 | /* Register SJA1000 device */ | ||
231 | err = register_sja1000dev(dev); | ||
232 | if (err) { | ||
233 | free_sja1000dev(dev); | ||
234 | goto failure_cleanup; | ||
235 | } | ||
236 | |||
237 | card->channels++; | ||
238 | |||
239 | printk(KERN_INFO "%s: registered %s on channel " | ||
240 | "#%d at 0x%p, irq %d\n", DRV_NAME, dev->name, | ||
241 | i, priv->reg_base, dev->irq); | ||
242 | } else | ||
243 | free_sja1000dev(dev); | ||
244 | } | ||
245 | |||
246 | err = request_irq(dev->irq, &ems_pcmcia_interrupt, IRQF_SHARED, | ||
247 | DRV_NAME, card); | ||
248 | if (!err) | ||
249 | return 0; | ||
250 | |||
251 | failure_cleanup: | ||
252 | ems_pcmcia_del_card(pdev); | ||
253 | return err; | ||
254 | } | ||
255 | |||
256 | /* | ||
257 | * Setup PCMCIA socket and probe for EMS CPC-CARD | ||
258 | */ | ||
259 | static int __devinit ems_pcmcia_probe(struct pcmcia_device *dev) | ||
260 | { | ||
261 | int csval; | ||
262 | |||
263 | /* General socket configuration */ | ||
264 | dev->config_flags |= CONF_ENABLE_IRQ; | ||
265 | dev->config_index = 1; | ||
266 | dev->config_regs = PRESENT_OPTION; | ||
267 | |||
268 | /* The io structure describes IO port mapping */ | ||
269 | dev->resource[0]->end = 16; | ||
270 | dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; | ||
271 | dev->resource[1]->end = 16; | ||
272 | dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_16; | ||
273 | dev->io_lines = 5; | ||
274 | |||
275 | /* Allocate a memory window */ | ||
276 | dev->resource[2]->flags = | ||
277 | (WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE); | ||
278 | dev->resource[2]->start = dev->resource[2]->end = 0; | ||
279 | |||
280 | csval = pcmcia_request_window(dev, dev->resource[2], 0); | ||
281 | if (csval) { | ||
282 | dev_err(&dev->dev, "pcmcia_request_window failed (err=%d)\n", | ||
283 | csval); | ||
284 | return 0; | ||
285 | } | ||
286 | |||
287 | csval = pcmcia_map_mem_page(dev, dev->resource[2], dev->config_base); | ||
288 | if (csval) { | ||
289 | dev_err(&dev->dev, "pcmcia_map_mem_page failed (err=%d)\n", | ||
290 | csval); | ||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | csval = pcmcia_enable_device(dev); | ||
295 | if (csval) { | ||
296 | dev_err(&dev->dev, "pcmcia_enable_device failed (err=%d)\n", | ||
297 | csval); | ||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | ems_pcmcia_add_card(dev, dev->resource[2]->start); | ||
302 | return 0; | ||
303 | } | ||
304 | |||
305 | /* | ||
306 | * Release claimed resources | ||
307 | */ | ||
308 | static void ems_pcmcia_remove(struct pcmcia_device *dev) | ||
309 | { | ||
310 | ems_pcmcia_del_card(dev); | ||
311 | pcmcia_disable_device(dev); | ||
312 | } | ||
313 | |||
314 | static struct pcmcia_driver ems_pcmcia_driver = { | ||
315 | .name = DRV_NAME, | ||
316 | .probe = ems_pcmcia_probe, | ||
317 | .remove = ems_pcmcia_remove, | ||
318 | .id_table = ems_pcmcia_tbl, | ||
319 | }; | ||
320 | |||
321 | static int __init ems_pcmcia_init(void) | ||
322 | { | ||
323 | return pcmcia_register_driver(&ems_pcmcia_driver); | ||
324 | } | ||
325 | module_init(ems_pcmcia_init); | ||
326 | |||
327 | static void __exit ems_pcmcia_exit(void) | ||
328 | { | ||
329 | pcmcia_unregister_driver(&ems_pcmcia_driver); | ||
330 | } | ||
331 | module_exit(ems_pcmcia_exit); | ||
diff --git a/drivers/net/can/sja1000/peak_pci.c b/drivers/net/can/sja1000/peak_pci.c new file mode 100644 index 00000000000..905bce0b3a4 --- /dev/null +++ b/drivers/net/can/sja1000/peak_pci.c | |||
@@ -0,0 +1,291 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007, 2011 Wolfgang Grandegger <wg@grandegger.com> | ||
3 | * | ||
4 | * Derived from the PCAN project file driver/src/pcan_pci.c: | ||
5 | * | ||
6 | * Copyright (C) 2001-2006 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 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software Foundation, | ||
19 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/version.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/interrupt.h> | ||
26 | #include <linux/netdevice.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/pci.h> | ||
29 | #include <linux/io.h> | ||
30 | #include <linux/can.h> | ||
31 | #include <linux/can/dev.h> | ||
32 | |||
33 | #include "sja1000.h" | ||
34 | |||
35 | MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>"); | ||
36 | MODULE_DESCRIPTION("Socket-CAN driver for PEAK PCAN PCI/PCIe cards"); | ||
37 | MODULE_SUPPORTED_DEVICE("PEAK PCAN PCI/PCIe CAN card"); | ||
38 | MODULE_LICENSE("GPL v2"); | ||
39 | |||
40 | #define DRV_NAME "peak_pci" | ||
41 | |||
42 | struct peak_pci_chan { | ||
43 | void __iomem *cfg_base; /* Common for all channels */ | ||
44 | struct net_device *next_dev; /* Chain of network devices */ | ||
45 | u16 icr_mask; /* Interrupt mask for fast ack */ | ||
46 | }; | ||
47 | |||
48 | #define PEAK_PCI_CAN_CLOCK (16000000 / 2) | ||
49 | |||
50 | #define PEAK_PCI_CDR (CDR_CBP | CDR_CLKOUT_MASK) | ||
51 | #define PEAK_PCI_OCR OCR_TX0_PUSHPULL | ||
52 | |||
53 | /* | ||
54 | * Important PITA registers | ||
55 | */ | ||
56 | #define PITA_ICR 0x00 /* Interrupt control register */ | ||
57 | #define PITA_GPIOICR 0x18 /* GPIO interface control register */ | ||
58 | #define PITA_MISC 0x1C /* Miscellaneous register */ | ||
59 | |||
60 | #define PEAK_PCI_CFG_SIZE 0x1000 /* Size of the config PCI bar */ | ||
61 | #define PEAK_PCI_CHAN_SIZE 0x0400 /* Size used by the channel */ | ||
62 | |||
63 | #define PEAK_PCI_VENDOR_ID 0x001C /* The PCI device and vendor IDs */ | ||
64 | #define PEAK_PCI_DEVICE_ID 0x0001 /* for PCI/PCIe slot cards */ | ||
65 | |||
66 | static const u16 peak_pci_icr_masks[] = {0x02, 0x01, 0x40, 0x80}; | ||
67 | |||
68 | static DEFINE_PCI_DEVICE_TABLE(peak_pci_tbl) = { | ||
69 | {PEAK_PCI_VENDOR_ID, PEAK_PCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,}, | ||
70 | {0,} | ||
71 | }; | ||
72 | |||
73 | MODULE_DEVICE_TABLE(pci, peak_pci_tbl); | ||
74 | |||
75 | static u8 peak_pci_read_reg(const struct sja1000_priv *priv, int port) | ||
76 | { | ||
77 | return readb(priv->reg_base + (port << 2)); | ||
78 | } | ||
79 | |||
80 | static void peak_pci_write_reg(const struct sja1000_priv *priv, | ||
81 | int port, u8 val) | ||
82 | { | ||
83 | writeb(val, priv->reg_base + (port << 2)); | ||
84 | } | ||
85 | |||
86 | static void peak_pci_post_irq(const struct sja1000_priv *priv) | ||
87 | { | ||
88 | struct peak_pci_chan *chan = priv->priv; | ||
89 | u16 icr; | ||
90 | |||
91 | /* Select and clear in PITA stored interrupt */ | ||
92 | icr = readw(chan->cfg_base + PITA_ICR); | ||
93 | if (icr & chan->icr_mask) | ||
94 | writew(chan->icr_mask, chan->cfg_base + PITA_ICR); | ||
95 | } | ||
96 | |||
97 | static int __devinit peak_pci_probe(struct pci_dev *pdev, | ||
98 | const struct pci_device_id *ent) | ||
99 | { | ||
100 | struct sja1000_priv *priv; | ||
101 | struct peak_pci_chan *chan; | ||
102 | struct net_device *dev, *dev0 = NULL; | ||
103 | void __iomem *cfg_base, *reg_base; | ||
104 | u16 sub_sys_id, icr; | ||
105 | int i, err, channels; | ||
106 | |||
107 | err = pci_enable_device(pdev); | ||
108 | if (err) | ||
109 | return err; | ||
110 | |||
111 | err = pci_request_regions(pdev, DRV_NAME); | ||
112 | if (err) | ||
113 | goto failure_disable_pci; | ||
114 | |||
115 | err = pci_read_config_word(pdev, 0x2e, &sub_sys_id); | ||
116 | if (err) | ||
117 | goto failure_release_regions; | ||
118 | |||
119 | dev_dbg(&pdev->dev, "probing device %04x:%04x:%04x\n", | ||
120 | pdev->vendor, pdev->device, sub_sys_id); | ||
121 | |||
122 | err = pci_write_config_word(pdev, 0x44, 0); | ||
123 | if (err) | ||
124 | goto failure_release_regions; | ||
125 | |||
126 | if (sub_sys_id >= 12) | ||
127 | channels = 4; | ||
128 | else if (sub_sys_id >= 10) | ||
129 | channels = 3; | ||
130 | else if (sub_sys_id >= 4) | ||
131 | channels = 2; | ||
132 | else | ||
133 | channels = 1; | ||
134 | |||
135 | cfg_base = pci_iomap(pdev, 0, PEAK_PCI_CFG_SIZE); | ||
136 | if (!cfg_base) { | ||
137 | dev_err(&pdev->dev, "failed to map PCI resource #0\n"); | ||
138 | goto failure_release_regions; | ||
139 | } | ||
140 | |||
141 | reg_base = pci_iomap(pdev, 1, PEAK_PCI_CHAN_SIZE * channels); | ||
142 | if (!reg_base) { | ||
143 | dev_err(&pdev->dev, "failed to map PCI resource #1\n"); | ||
144 | goto failure_unmap_cfg_base; | ||
145 | } | ||
146 | |||
147 | /* Set GPIO control register */ | ||
148 | writew(0x0005, cfg_base + PITA_GPIOICR + 2); | ||
149 | /* Enable all channels of this card */ | ||
150 | writeb(0x00, cfg_base + PITA_GPIOICR); | ||
151 | /* Toggle reset */ | ||
152 | writeb(0x05, cfg_base + PITA_MISC + 3); | ||
153 | mdelay(5); | ||
154 | /* Leave parport mux mode */ | ||
155 | writeb(0x04, cfg_base + PITA_MISC + 3); | ||
156 | |||
157 | icr = readw(cfg_base + PITA_ICR + 2); | ||
158 | |||
159 | for (i = 0; i < channels; i++) { | ||
160 | dev = alloc_sja1000dev(sizeof(struct peak_pci_chan)); | ||
161 | if (!dev) { | ||
162 | err = -ENOMEM; | ||
163 | goto failure_remove_channels; | ||
164 | } | ||
165 | |||
166 | priv = netdev_priv(dev); | ||
167 | chan = priv->priv; | ||
168 | |||
169 | chan->cfg_base = cfg_base; | ||
170 | priv->reg_base = reg_base + i * PEAK_PCI_CHAN_SIZE; | ||
171 | |||
172 | priv->read_reg = peak_pci_read_reg; | ||
173 | priv->write_reg = peak_pci_write_reg; | ||
174 | priv->post_irq = peak_pci_post_irq; | ||
175 | |||
176 | priv->can.clock.freq = PEAK_PCI_CAN_CLOCK; | ||
177 | priv->ocr = PEAK_PCI_OCR; | ||
178 | priv->cdr = PEAK_PCI_CDR; | ||
179 | /* Neither a slave nor a single device distributes the clock */ | ||
180 | if (channels == 1 || i > 0) | ||
181 | priv->cdr |= CDR_CLK_OFF; | ||
182 | |||
183 | /* Setup interrupt handling */ | ||
184 | priv->irq_flags = IRQF_SHARED; | ||
185 | dev->irq = pdev->irq; | ||
186 | |||
187 | chan->icr_mask = peak_pci_icr_masks[i]; | ||
188 | icr |= chan->icr_mask; | ||
189 | |||
190 | SET_NETDEV_DEV(dev, &pdev->dev); | ||
191 | |||
192 | err = register_sja1000dev(dev); | ||
193 | if (err) { | ||
194 | dev_err(&pdev->dev, "failed to register device\n"); | ||
195 | free_sja1000dev(dev); | ||
196 | goto failure_remove_channels; | ||
197 | } | ||
198 | |||
199 | /* Create chain of SJA1000 devices */ | ||
200 | if (i == 0) | ||
201 | dev0 = dev; | ||
202 | else | ||
203 | chan->next_dev = dev; | ||
204 | |||
205 | dev_info(&pdev->dev, | ||
206 | "%s at reg_base=0x%p cfg_base=0x%p irq=%d\n", | ||
207 | dev->name, priv->reg_base, chan->cfg_base, dev->irq); | ||
208 | } | ||
209 | |||
210 | pci_set_drvdata(pdev, dev0); | ||
211 | |||
212 | /* Enable interrupts */ | ||
213 | writew(icr, cfg_base + PITA_ICR + 2); | ||
214 | |||
215 | return 0; | ||
216 | |||
217 | failure_remove_channels: | ||
218 | /* Disable interrupts */ | ||
219 | writew(0x0, cfg_base + PITA_ICR + 2); | ||
220 | |||
221 | for (dev = dev0; dev; dev = chan->next_dev) { | ||
222 | unregister_sja1000dev(dev); | ||
223 | free_sja1000dev(dev); | ||
224 | priv = netdev_priv(dev); | ||
225 | chan = priv->priv; | ||
226 | dev = chan->next_dev; | ||
227 | } | ||
228 | |||
229 | pci_iounmap(pdev, reg_base); | ||
230 | |||
231 | failure_unmap_cfg_base: | ||
232 | pci_iounmap(pdev, cfg_base); | ||
233 | |||
234 | failure_release_regions: | ||
235 | pci_release_regions(pdev); | ||
236 | |||
237 | failure_disable_pci: | ||
238 | pci_disable_device(pdev); | ||
239 | |||
240 | return err; | ||
241 | } | ||
242 | |||
243 | static void __devexit peak_pci_remove(struct pci_dev *pdev) | ||
244 | { | ||
245 | struct net_device *dev = pci_get_drvdata(pdev); /* First device */ | ||
246 | struct sja1000_priv *priv = netdev_priv(dev); | ||
247 | struct peak_pci_chan *chan = priv->priv; | ||
248 | void __iomem *cfg_base = chan->cfg_base; | ||
249 | void __iomem *reg_base = priv->reg_base; | ||
250 | |||
251 | /* Disable interrupts */ | ||
252 | writew(0x0, cfg_base + PITA_ICR + 2); | ||
253 | |||
254 | /* Loop over all registered devices */ | ||
255 | while (1) { | ||
256 | dev_info(&pdev->dev, "removing device %s\n", dev->name); | ||
257 | unregister_sja1000dev(dev); | ||
258 | free_sja1000dev(dev); | ||
259 | dev = chan->next_dev; | ||
260 | if (!dev) | ||
261 | break; | ||
262 | priv = netdev_priv(dev); | ||
263 | chan = priv->priv; | ||
264 | } | ||
265 | |||
266 | pci_iounmap(pdev, reg_base); | ||
267 | pci_iounmap(pdev, cfg_base); | ||
268 | pci_release_regions(pdev); | ||
269 | pci_disable_device(pdev); | ||
270 | |||
271 | pci_set_drvdata(pdev, NULL); | ||
272 | } | ||
273 | |||
274 | static struct pci_driver peak_pci_driver = { | ||
275 | .name = DRV_NAME, | ||
276 | .id_table = peak_pci_tbl, | ||
277 | .probe = peak_pci_probe, | ||
278 | .remove = __devexit_p(peak_pci_remove), | ||
279 | }; | ||
280 | |||
281 | static int __init peak_pci_init(void) | ||
282 | { | ||
283 | return pci_register_driver(&peak_pci_driver); | ||
284 | } | ||
285 | module_init(peak_pci_init); | ||
286 | |||
287 | static void __exit peak_pci_exit(void) | ||
288 | { | ||
289 | pci_unregister_driver(&peak_pci_driver); | ||
290 | } | ||
291 | module_exit(peak_pci_exit); | ||
diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c index f501bba1fc6..04a3f1b756a 100644 --- a/drivers/net/can/sja1000/sja1000.c +++ b/drivers/net/can/sja1000/sja1000.c | |||
@@ -40,8 +40,6 @@ | |||
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 | * | ||
45 | */ | 43 | */ |
46 | 44 | ||
47 | #include <linux/module.h> | 45 | #include <linux/module.h> |
diff --git a/drivers/net/can/sja1000/sja1000.h b/drivers/net/can/sja1000/sja1000.h index 78bd4ecac14..23fff06875f 100644 --- a/drivers/net/can/sja1000/sja1000.h +++ b/drivers/net/can/sja1000/sja1000.h | |||
@@ -40,8 +40,6 @@ | |||
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 | * | ||
45 | */ | 43 | */ |
46 | 44 | ||
47 | #ifndef SJA1000_DEV_H | 45 | #ifndef SJA1000_DEV_H |