diff options
author | David S. Miller <davem@davemloft.net> | 2011-11-30 16:00:48 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-11-30 16:01:46 -0500 |
commit | de565664041d954b60f87e3d576a784cf25672d0 (patch) | |
tree | 09415cad71cd51359b259ffcd34dbcd1a27eb61f /drivers/net/can | |
parent | ec2a5466b3ce680c92e8e05617b020fd825854b9 (diff) |
can: Revert outdated cc770 driver patches.
Newer versions have been floating about, and I applied
to older variant unfortunately.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/can')
-rw-r--r-- | drivers/net/can/Kconfig | 2 | ||||
-rw-r--r-- | drivers/net/can/Makefile | 1 | ||||
-rw-r--r-- | drivers/net/can/cc770/Kconfig | 14 | ||||
-rw-r--r-- | drivers/net/can/cc770/Makefile | 8 | ||||
-rw-r--r-- | drivers/net/can/cc770/cc770.c | 895 | ||||
-rw-r--r-- | drivers/net/can/cc770/cc770.h | 247 | ||||
-rw-r--r-- | drivers/net/can/cc770/cc770_isa.c | 337 |
7 files changed, 0 insertions, 1504 deletions
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index ab45758c49a4..f6c98fb4a517 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig | |||
@@ -116,8 +116,6 @@ source "drivers/net/can/sja1000/Kconfig" | |||
116 | 116 | ||
117 | source "drivers/net/can/c_can/Kconfig" | 117 | source "drivers/net/can/c_can/Kconfig" |
118 | 118 | ||
119 | source "drivers/net/can/cc770/Kconfig" | ||
120 | |||
121 | source "drivers/net/can/usb/Kconfig" | 119 | source "drivers/net/can/usb/Kconfig" |
122 | 120 | ||
123 | source "drivers/net/can/softing/Kconfig" | 121 | source "drivers/net/can/softing/Kconfig" |
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile index 938be37b670c..24ebfe8d758a 100644 --- a/drivers/net/can/Makefile +++ b/drivers/net/can/Makefile | |||
@@ -14,7 +14,6 @@ obj-y += softing/ | |||
14 | obj-$(CONFIG_CAN_SJA1000) += sja1000/ | 14 | obj-$(CONFIG_CAN_SJA1000) += sja1000/ |
15 | obj-$(CONFIG_CAN_MSCAN) += mscan/ | 15 | obj-$(CONFIG_CAN_MSCAN) += mscan/ |
16 | obj-$(CONFIG_CAN_C_CAN) += c_can/ | 16 | obj-$(CONFIG_CAN_C_CAN) += c_can/ |
17 | obj-$(CONFIG_CAN_CC770) += cc770/ | ||
18 | obj-$(CONFIG_CAN_AT91) += at91_can.o | 17 | obj-$(CONFIG_CAN_AT91) += at91_can.o |
19 | obj-$(CONFIG_CAN_TI_HECC) += ti_hecc.o | 18 | obj-$(CONFIG_CAN_TI_HECC) += ti_hecc.o |
20 | obj-$(CONFIG_CAN_MCP251X) += mcp251x.o | 19 | obj-$(CONFIG_CAN_MCP251X) += mcp251x.o |
diff --git a/drivers/net/can/cc770/Kconfig b/drivers/net/can/cc770/Kconfig deleted file mode 100644 index 28e4d4810f44..000000000000 --- a/drivers/net/can/cc770/Kconfig +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | menuconfig CAN_CC770 | ||
2 | tristate "Bosch CC770 and Intel AN82527 devices" | ||
3 | depends on CAN_DEV && HAS_IOMEM | ||
4 | |||
5 | if CAN_CC770 | ||
6 | |||
7 | config CAN_CC770_ISA | ||
8 | tristate "ISA Bus based legacy CC770 driver" | ||
9 | ---help--- | ||
10 | This driver adds legacy support for CC770 and AN82527 chips | ||
11 | connected to the ISA bus using I/O port, memory mapped or | ||
12 | indirect access. | ||
13 | |||
14 | endif | ||
diff --git a/drivers/net/can/cc770/Makefile b/drivers/net/can/cc770/Makefile deleted file mode 100644 index 872ecffa80b7..000000000000 --- a/drivers/net/can/cc770/Makefile +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | # | ||
2 | # Makefile for the Bosch CC770 CAN controller drivers. | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_CAN_CC770) += cc770.o | ||
6 | obj-$(CONFIG_CAN_CC770_ISA) += cc770_isa.o | ||
7 | |||
8 | ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG | ||
diff --git a/drivers/net/can/cc770/cc770.c b/drivers/net/can/cc770/cc770.c deleted file mode 100644 index 81dc8306218b..000000000000 --- a/drivers/net/can/cc770/cc770.c +++ /dev/null | |||
@@ -1,895 +0,0 @@ | |||
1 | /* | ||
2 | * cc770.c - Bosch CC770 and Intel AN82527 network device driver | ||
3 | * | ||
4 | * Copyright (C) 2009, 2011 Wolfgang Grandegger <wg@grandegger.com> | ||
5 | * | ||
6 | * Derived from the old Socket-CAN i82527 driver: | ||
7 | * | ||
8 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * 3. Neither the name of Volkswagen nor the names of its contributors | ||
20 | * may be used to endorse or promote products derived from this software | ||
21 | * without specific prior written permission. | ||
22 | * | ||
23 | * Alternatively, provided that this notice is retained in full, this | ||
24 | * software may be distributed under the terms of the GNU General | ||
25 | * Public License ("GPL") version 2, in which case the provisions of the | ||
26 | * GPL apply INSTEAD OF those given above. | ||
27 | * | ||
28 | * The provided data structures and external interfaces from this code | ||
29 | * are not restricted to be used by modules with a GPL compatible license. | ||
30 | * | ||
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
35 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
36 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
37 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
38 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
39 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
40 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
41 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
42 | * DAMAGE. | ||
43 | * | ||
44 | * Send feedback to <socketcan-users@lists.berlios.de> | ||
45 | */ | ||
46 | |||
47 | #include <linux/module.h> | ||
48 | #include <linux/init.h> | ||
49 | #include <linux/kernel.h> | ||
50 | #include <linux/version.h> | ||
51 | #include <linux/sched.h> | ||
52 | #include <linux/types.h> | ||
53 | #include <linux/fcntl.h> | ||
54 | #include <linux/interrupt.h> | ||
55 | #include <linux/ptrace.h> | ||
56 | #include <linux/string.h> | ||
57 | #include <linux/errno.h> | ||
58 | #include <linux/netdevice.h> | ||
59 | #include <linux/if_arp.h> | ||
60 | #include <linux/if_ether.h> | ||
61 | #include <linux/skbuff.h> | ||
62 | #include <linux/delay.h> | ||
63 | |||
64 | #include <linux/can.h> | ||
65 | #include <linux/can/dev.h> | ||
66 | #include <linux/can/error.h> | ||
67 | #include <linux/can/dev.h> | ||
68 | |||
69 | #include "cc770.h" | ||
70 | |||
71 | #define DRV_NAME "cc770" | ||
72 | |||
73 | MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>"); | ||
74 | MODULE_LICENSE("GPL v2"); | ||
75 | MODULE_DESCRIPTION(DRV_NAME "CAN netdevice driver"); | ||
76 | |||
77 | /* | ||
78 | * The CC770 is a CAN controller from Bosch, which is 100% compatible | ||
79 | * with the AN82527 from Intel, but with "bugs" being fixed and some | ||
80 | * additional functionality, mainly: | ||
81 | * | ||
82 | * 1. RX and TX error counters are readable. | ||
83 | * 2. Support of silent (listen-only) mode. | ||
84 | * 3. Message object 15 can receive all types of frames, also RTR and EFF. | ||
85 | * | ||
86 | * Details are available from Bosch's "CC770_Product_Info_2007-01.pdf", | ||
87 | * which explains in detail the compatibility between the CC770 and the | ||
88 | * 82527. This driver use the additional functionality 3. on real CC770 | ||
89 | * devices. Unfortunately, the CC770 does still not store the message | ||
90 | * identifier of received remote transmission request frames and | ||
91 | * therefore it's set to 0. | ||
92 | * | ||
93 | * The message objects 1..14 can be used for TX and RX while the message | ||
94 | * objects 15 is optimized for RX. It has a shadow register for reliable | ||
95 | * data receiption under heavy bus load. Therefore it makes sense to use | ||
96 | * this message object for the needed use case. The frame type (EFF/SFF) | ||
97 | * for the message object 15 can be defined via kernel module parameter | ||
98 | * "msgobj15_eff". If not equal 0, it will receive 29-bit EFF frames, | ||
99 | * otherwise 11 bit SFF messages. | ||
100 | */ | ||
101 | static int msgobj15_eff; | ||
102 | module_param(msgobj15_eff, int, S_IRUGO); | ||
103 | MODULE_PARM_DESC(msgobj15_eff, "Extended 29-bit frames for message object 15 " | ||
104 | "(default: 11-bit standard frames)"); | ||
105 | |||
106 | static int i82527_compat; | ||
107 | module_param(i82527_compat, int, S_IRUGO); | ||
108 | MODULE_PARM_DESC(i82527_compat, "Strict Intel 82527 comptibility mode " | ||
109 | "without using additional functions"); | ||
110 | |||
111 | /* | ||
112 | * This driver uses the last 5 message objects 11..15. The definitions | ||
113 | * and structure below allows to configure and assign them to the real | ||
114 | * message object. | ||
115 | */ | ||
116 | static unsigned char cc770_obj_flags[CC770_OBJ_MAX] = { | ||
117 | [CC770_OBJ_RX0] = CC770_OBJ_FLAG_RX, | ||
118 | [CC770_OBJ_RX1] = CC770_OBJ_FLAG_RX | CC770_OBJ_FLAG_EFF, | ||
119 | [CC770_OBJ_RX_RTR0] = CC770_OBJ_FLAG_RX | CC770_OBJ_FLAG_RTR, | ||
120 | [CC770_OBJ_RX_RTR1] = CC770_OBJ_FLAG_RX | CC770_OBJ_FLAG_RTR | | ||
121 | CC770_OBJ_FLAG_EFF, | ||
122 | [CC770_OBJ_TX] = 0, | ||
123 | }; | ||
124 | |||
125 | static struct can_bittiming_const cc770_bittiming_const = { | ||
126 | .name = DRV_NAME, | ||
127 | .tseg1_min = 1, | ||
128 | .tseg1_max = 16, | ||
129 | .tseg2_min = 1, | ||
130 | .tseg2_max = 8, | ||
131 | .sjw_max = 4, | ||
132 | .brp_min = 1, | ||
133 | .brp_max = 64, | ||
134 | .brp_inc = 1, | ||
135 | }; | ||
136 | |||
137 | static inline int intid2obj(unsigned int intid) | ||
138 | { | ||
139 | if (intid == 2) | ||
140 | return 0; | ||
141 | else | ||
142 | return MSGOBJ_LAST + 2 - intid; | ||
143 | } | ||
144 | |||
145 | static void enable_all_objs(const struct net_device *dev) | ||
146 | { | ||
147 | struct cc770_priv *priv = netdev_priv(dev); | ||
148 | u8 msgcfg; | ||
149 | unsigned char obj_flags; | ||
150 | unsigned int o, mo; | ||
151 | |||
152 | for (o = 0; o < CC770_OBJ_MAX; o++) { | ||
153 | obj_flags = priv->obj_flags[o]; | ||
154 | mo = obj2msgobj(o); | ||
155 | |||
156 | if (obj_flags & CC770_OBJ_FLAG_RX) { | ||
157 | /* | ||
158 | * We don't need extra objects for RTR and EFF if | ||
159 | * the additional CC770 functions are enabled. | ||
160 | */ | ||
161 | if (priv->control_normal_mode & CTRL_EAF) { | ||
162 | if (o > 0) | ||
163 | continue; | ||
164 | netdev_dbg(dev, "Message object %d for " | ||
165 | "RX data, RTR, SFF and EFF\n", mo); | ||
166 | } else { | ||
167 | netdev_dbg(dev, | ||
168 | "Message object %d for RX %s %s\n", | ||
169 | mo, obj_flags & CC770_OBJ_FLAG_RTR ? | ||
170 | "RTR" : "data", | ||
171 | obj_flags & CC770_OBJ_FLAG_EFF ? | ||
172 | "EFF" : "SFF"); | ||
173 | } | ||
174 | |||
175 | if (obj_flags & CC770_OBJ_FLAG_EFF) | ||
176 | msgcfg = MSGCFG_XTD; | ||
177 | else | ||
178 | msgcfg = 0; | ||
179 | if (obj_flags & CC770_OBJ_FLAG_RTR) | ||
180 | msgcfg |= MSGCFG_DIR; | ||
181 | |||
182 | cc770_write_reg(priv, msgobj[mo].config, msgcfg); | ||
183 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
184 | MSGVAL_SET | TXIE_RES | | ||
185 | RXIE_SET | INTPND_RES); | ||
186 | |||
187 | if (obj_flags & CC770_OBJ_FLAG_RTR) | ||
188 | cc770_write_reg(priv, msgobj[mo].ctrl1, | ||
189 | NEWDAT_RES | CPUUPD_SET | | ||
190 | TXRQST_RES | RMTPND_RES); | ||
191 | else | ||
192 | cc770_write_reg(priv, msgobj[mo].ctrl1, | ||
193 | NEWDAT_RES | MSGLST_RES | | ||
194 | TXRQST_RES | RMTPND_RES); | ||
195 | } else { | ||
196 | netdev_dbg(dev, "Message object %d for " | ||
197 | "TX data, RTR, SFF and EFF\n", mo); | ||
198 | |||
199 | cc770_write_reg(priv, msgobj[mo].ctrl1, | ||
200 | RMTPND_RES | TXRQST_RES | | ||
201 | CPUUPD_RES | NEWDAT_RES); | ||
202 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
203 | MSGVAL_RES | TXIE_RES | | ||
204 | RXIE_RES | INTPND_RES); | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | |||
209 | static void disable_all_objs(const struct cc770_priv *priv) | ||
210 | { | ||
211 | int i, mo; | ||
212 | |||
213 | for (i = 0; i < CC770_OBJ_MAX; i++) { | ||
214 | mo = obj2msgobj(i); | ||
215 | |||
216 | if (priv->obj_flags[i] & CC770_OBJ_FLAG_RX) { | ||
217 | if (i > 0 && priv->control_normal_mode & CTRL_EAF) | ||
218 | continue; | ||
219 | |||
220 | cc770_write_reg(priv, msgobj[mo].ctrl1, | ||
221 | NEWDAT_RES | MSGLST_RES | | ||
222 | TXRQST_RES | RMTPND_RES); | ||
223 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
224 | MSGVAL_RES | TXIE_RES | | ||
225 | RXIE_RES | INTPND_RES); | ||
226 | } else { | ||
227 | /* Clear message object for send */ | ||
228 | cc770_write_reg(priv, msgobj[mo].ctrl1, | ||
229 | RMTPND_RES | TXRQST_RES | | ||
230 | CPUUPD_RES | NEWDAT_RES); | ||
231 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
232 | MSGVAL_RES | TXIE_RES | | ||
233 | RXIE_RES | INTPND_RES); | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | |||
238 | static void set_reset_mode(struct net_device *dev) | ||
239 | { | ||
240 | struct cc770_priv *priv = netdev_priv(dev); | ||
241 | |||
242 | /* Enable configuration and puts chip in bus-off, disable interrupts */ | ||
243 | cc770_write_reg(priv, control, CTRL_CCE | CTRL_INI); | ||
244 | |||
245 | priv->can.state = CAN_STATE_STOPPED; | ||
246 | |||
247 | /* Clear interrupts */ | ||
248 | cc770_read_reg(priv, interrupt); | ||
249 | |||
250 | /* Clear status register */ | ||
251 | cc770_write_reg(priv, status, 0); | ||
252 | |||
253 | /* Disable all used message objects */ | ||
254 | disable_all_objs(priv); | ||
255 | } | ||
256 | |||
257 | static void set_normal_mode(struct net_device *dev) | ||
258 | { | ||
259 | struct cc770_priv *priv = netdev_priv(dev); | ||
260 | |||
261 | /* Clear interrupts */ | ||
262 | cc770_read_reg(priv, interrupt); | ||
263 | |||
264 | /* Clear status register and pre-set last error code */ | ||
265 | cc770_write_reg(priv, status, STAT_LEC_MASK); | ||
266 | |||
267 | /* Enable all used message objects*/ | ||
268 | enable_all_objs(dev); | ||
269 | |||
270 | /* | ||
271 | * Clear bus-off, interrupts only for errors, | ||
272 | * not for status change | ||
273 | */ | ||
274 | cc770_write_reg(priv, control, priv->control_normal_mode); | ||
275 | |||
276 | priv->can.state = CAN_STATE_ERROR_ACTIVE; | ||
277 | } | ||
278 | |||
279 | static void chipset_init(struct cc770_priv *priv) | ||
280 | { | ||
281 | int mo, id, data; | ||
282 | |||
283 | /* Enable configuration and put chip in bus-off, disable interrupts */ | ||
284 | cc770_write_reg(priv, control, (CTRL_CCE | CTRL_INI)); | ||
285 | |||
286 | /* Set CLKOUT divider and slew rates */ | ||
287 | cc770_write_reg(priv, clkout, priv->clkout); | ||
288 | |||
289 | /* Configure CPU interface / CLKOUT enable */ | ||
290 | cc770_write_reg(priv, cpu_interface, priv->cpu_interface | CPUIF_CEN); | ||
291 | |||
292 | /* Set bus configuration */ | ||
293 | cc770_write_reg(priv, bus_config, priv->bus_config); | ||
294 | |||
295 | /* Clear interrupts */ | ||
296 | cc770_read_reg(priv, interrupt); | ||
297 | |||
298 | /* Clear status register */ | ||
299 | cc770_write_reg(priv, status, 0); | ||
300 | |||
301 | /* Clear and invalidate message objects */ | ||
302 | for (mo = MSGOBJ_FIRST; mo <= MSGOBJ_LAST; mo++) { | ||
303 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
304 | INTPND_UNC | RXIE_RES | | ||
305 | TXIE_RES | MSGVAL_RES); | ||
306 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
307 | INTPND_RES | RXIE_RES | | ||
308 | TXIE_RES | MSGVAL_RES); | ||
309 | cc770_write_reg(priv, msgobj[mo].ctrl1, | ||
310 | NEWDAT_RES | MSGLST_RES | | ||
311 | TXRQST_RES | RMTPND_RES); | ||
312 | for (data = 0; data < 8; data++) | ||
313 | cc770_write_reg(priv, msgobj[mo].data[data], 0); | ||
314 | for (id = 0; id < 4; id++) | ||
315 | cc770_write_reg(priv, msgobj[mo].id[id], 0); | ||
316 | cc770_write_reg(priv, msgobj[mo].config, 0); | ||
317 | } | ||
318 | |||
319 | /* Set all global ID masks to "don't care" */ | ||
320 | cc770_write_reg(priv, global_mask_std[0], 0); | ||
321 | cc770_write_reg(priv, global_mask_std[1], 0); | ||
322 | cc770_write_reg(priv, global_mask_ext[0], 0); | ||
323 | cc770_write_reg(priv, global_mask_ext[1], 0); | ||
324 | cc770_write_reg(priv, global_mask_ext[2], 0); | ||
325 | cc770_write_reg(priv, global_mask_ext[3], 0); | ||
326 | |||
327 | } | ||
328 | |||
329 | static int cc770_probe_chip(struct net_device *dev) | ||
330 | { | ||
331 | struct cc770_priv *priv = netdev_priv(dev); | ||
332 | |||
333 | /* Enable configuration, put chip in bus-off, disable ints */ | ||
334 | cc770_write_reg(priv, control, CTRL_CCE | CTRL_EAF | CTRL_INI); | ||
335 | /* Configure cpu interface / CLKOUT disable */ | ||
336 | cc770_write_reg(priv, cpu_interface, priv->cpu_interface); | ||
337 | |||
338 | /* | ||
339 | * Check if hardware reset is still inactive or maybe there | ||
340 | * is no chip in this address space | ||
341 | */ | ||
342 | if (cc770_read_reg(priv, cpu_interface) & CPUIF_RST) { | ||
343 | netdev_info(dev, "probing @0x%p failed (reset)\n", | ||
344 | priv->reg_base); | ||
345 | return 0; | ||
346 | } | ||
347 | |||
348 | /* Write and read back test pattern */ | ||
349 | cc770_write_reg(priv, msgobj[1].data[1], 0x25); | ||
350 | cc770_write_reg(priv, msgobj[2].data[3], 0x52); | ||
351 | cc770_write_reg(priv, msgobj[10].data[6], 0xc3); | ||
352 | if ((cc770_read_reg(priv, msgobj[1].data[1]) != 0x25) || | ||
353 | (cc770_read_reg(priv, msgobj[2].data[3]) != 0x52) || | ||
354 | (cc770_read_reg(priv, msgobj[10].data[6]) != 0xc3)) { | ||
355 | netdev_info(dev, "probing @0x%p failed (pattern)\n", | ||
356 | priv->reg_base); | ||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | /* Check if this chip is a CC770 supporting additional functions */ | ||
361 | if (cc770_read_reg(priv, control) & CTRL_EAF) | ||
362 | priv->control_normal_mode |= CTRL_EAF; | ||
363 | |||
364 | return 1; | ||
365 | } | ||
366 | |||
367 | static void cc770_start(struct net_device *dev) | ||
368 | { | ||
369 | struct cc770_priv *priv = netdev_priv(dev); | ||
370 | |||
371 | /* leave reset mode */ | ||
372 | if (priv->can.state != CAN_STATE_STOPPED) | ||
373 | set_reset_mode(dev); | ||
374 | |||
375 | /* leave reset mode */ | ||
376 | set_normal_mode(dev); | ||
377 | } | ||
378 | |||
379 | static int cc770_set_mode(struct net_device *dev, enum can_mode mode) | ||
380 | { | ||
381 | struct cc770_priv *priv = netdev_priv(dev); | ||
382 | |||
383 | if (!priv->open_time) | ||
384 | return -EINVAL; | ||
385 | |||
386 | switch (mode) { | ||
387 | case CAN_MODE_START: | ||
388 | cc770_start(dev); | ||
389 | if (netif_queue_stopped(dev)) | ||
390 | netif_wake_queue(dev); | ||
391 | break; | ||
392 | |||
393 | default: | ||
394 | return -EOPNOTSUPP; | ||
395 | } | ||
396 | |||
397 | return 0; | ||
398 | } | ||
399 | |||
400 | static int cc770_set_bittiming(struct net_device *dev) | ||
401 | { | ||
402 | struct cc770_priv *priv = netdev_priv(dev); | ||
403 | struct can_bittiming *bt = &priv->can.bittiming; | ||
404 | u8 btr0, btr1; | ||
405 | |||
406 | btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6); | ||
407 | btr1 = ((bt->prop_seg + bt->phase_seg1 - 1) & 0xf) | | ||
408 | (((bt->phase_seg2 - 1) & 0x7) << 4); | ||
409 | if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) | ||
410 | btr1 |= 0x80; | ||
411 | |||
412 | netdev_info(dev, "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1); | ||
413 | |||
414 | cc770_write_reg(priv, bit_timing_0, btr0); | ||
415 | cc770_write_reg(priv, bit_timing_1, btr1); | ||
416 | |||
417 | return 0; | ||
418 | } | ||
419 | |||
420 | static netdev_tx_t cc770_start_xmit(struct sk_buff *skb, struct net_device *dev) | ||
421 | { | ||
422 | struct cc770_priv *priv = netdev_priv(dev); | ||
423 | struct net_device_stats *stats = &dev->stats; | ||
424 | struct can_frame *cf = (struct can_frame *)skb->data; | ||
425 | unsigned int mo = obj2msgobj(CC770_OBJ_TX); | ||
426 | u8 dlc, rtr; | ||
427 | u32 id; | ||
428 | int i; | ||
429 | |||
430 | if (can_dropped_invalid_skb(dev, skb)) | ||
431 | return NETDEV_TX_OK; | ||
432 | |||
433 | if ((cc770_read_reg(priv, | ||
434 | msgobj[mo].ctrl1) & TXRQST_UNC) == TXRQST_SET) { | ||
435 | netdev_err(dev, "TX register is still occupied!\n"); | ||
436 | return NETDEV_TX_BUSY; | ||
437 | } | ||
438 | |||
439 | netif_stop_queue(dev); | ||
440 | |||
441 | dlc = cf->can_dlc; | ||
442 | id = cf->can_id; | ||
443 | if (cf->can_id & CAN_RTR_FLAG) | ||
444 | rtr = 0; | ||
445 | else | ||
446 | rtr = MSGCFG_DIR; | ||
447 | cc770_write_reg(priv, msgobj[mo].ctrl1, | ||
448 | RMTPND_RES | TXRQST_RES | CPUUPD_SET | NEWDAT_RES); | ||
449 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
450 | MSGVAL_SET | TXIE_SET | RXIE_RES | INTPND_RES); | ||
451 | if (id & CAN_EFF_FLAG) { | ||
452 | id &= CAN_EFF_MASK; | ||
453 | cc770_write_reg(priv, msgobj[mo].config, | ||
454 | (dlc << 4) + rtr + MSGCFG_XTD); | ||
455 | cc770_write_reg(priv, msgobj[mo].id[3], | ||
456 | (id << 3) & 0xFFU); | ||
457 | cc770_write_reg(priv, msgobj[mo].id[2], | ||
458 | (id >> 5) & 0xFFU); | ||
459 | cc770_write_reg(priv, msgobj[mo].id[1], | ||
460 | (id >> 13) & 0xFFU); | ||
461 | cc770_write_reg(priv, msgobj[mo].id[0], | ||
462 | (id >> 21) & 0xFFU); | ||
463 | } else { | ||
464 | id &= CAN_SFF_MASK; | ||
465 | cc770_write_reg(priv, msgobj[mo].config, | ||
466 | (dlc << 4) + rtr); | ||
467 | cc770_write_reg(priv, msgobj[mo].id[0], | ||
468 | (id >> 3) & 0xFFU); | ||
469 | cc770_write_reg(priv, msgobj[mo].id[1], | ||
470 | (id << 5) & 0xFFU); | ||
471 | } | ||
472 | |||
473 | dlc &= 0x0f; /* restore length only */ | ||
474 | for (i = 0; i < dlc; i++) | ||
475 | cc770_write_reg(priv, msgobj[mo].data[i], cf->data[i]); | ||
476 | |||
477 | cc770_write_reg(priv, msgobj[mo].ctrl1, | ||
478 | RMTPND_RES | TXRQST_SET | CPUUPD_RES | NEWDAT_UNC); | ||
479 | |||
480 | stats->tx_bytes += dlc; | ||
481 | |||
482 | can_put_echo_skb(skb, dev, 0); | ||
483 | |||
484 | /* | ||
485 | * HM: We had some cases of repeated IRQs so make sure the | ||
486 | * INT is acknowledged I know it's already further up, but | ||
487 | * doing again fixed the issue | ||
488 | */ | ||
489 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
490 | MSGVAL_UNC | TXIE_UNC | RXIE_UNC | INTPND_RES); | ||
491 | |||
492 | return NETDEV_TX_OK; | ||
493 | } | ||
494 | |||
495 | static void cc770_rx(struct net_device *dev, unsigned int mo, u8 ctrl1) | ||
496 | { | ||
497 | struct cc770_priv *priv = netdev_priv(dev); | ||
498 | struct net_device_stats *stats = &dev->stats; | ||
499 | struct can_frame *cf; | ||
500 | struct sk_buff *skb; | ||
501 | u8 config; | ||
502 | u32 id; | ||
503 | int i; | ||
504 | |||
505 | skb = alloc_can_skb(dev, &cf); | ||
506 | if (skb == NULL) | ||
507 | return; | ||
508 | |||
509 | config = cc770_read_reg(priv, msgobj[mo].config); | ||
510 | |||
511 | if (ctrl1 & RMTPND_SET) { | ||
512 | /* | ||
513 | * Unfortunately, the chip does not store the real message | ||
514 | * identifier of the received remote transmission request | ||
515 | * frame. Therefore we set it to 0. | ||
516 | */ | ||
517 | cf->can_id = CAN_RTR_FLAG; | ||
518 | if (config & MSGCFG_XTD) | ||
519 | cf->can_id |= CAN_EFF_FLAG; | ||
520 | cf->can_dlc = 0; | ||
521 | } else { | ||
522 | if (config & MSGCFG_XTD) { | ||
523 | id = cc770_read_reg(priv, msgobj[mo].id[3]); | ||
524 | id |= cc770_read_reg(priv, msgobj[mo].id[2]) << 8; | ||
525 | id |= cc770_read_reg(priv, msgobj[mo].id[1]) << 16; | ||
526 | id |= cc770_read_reg(priv, msgobj[mo].id[0]) << 24; | ||
527 | id >>= 3; | ||
528 | id |= CAN_EFF_FLAG; | ||
529 | } else { | ||
530 | id = cc770_read_reg(priv, msgobj[mo].id[1]); | ||
531 | id |= cc770_read_reg(priv, msgobj[mo].id[0]) << 8; | ||
532 | id >>= 5; | ||
533 | } | ||
534 | |||
535 | cf->can_id = id; | ||
536 | cf->can_dlc = get_can_dlc((config & 0xf0) >> 4); | ||
537 | for (i = 0; i < cf->can_dlc; i++) | ||
538 | cf->data[i] = cc770_read_reg(priv, msgobj[mo].data[i]); | ||
539 | } | ||
540 | netif_rx(skb); | ||
541 | |||
542 | stats->rx_packets++; | ||
543 | stats->rx_bytes += cf->can_dlc; | ||
544 | } | ||
545 | |||
546 | static int cc770_err(struct net_device *dev, u8 status) | ||
547 | { | ||
548 | struct cc770_priv *priv = netdev_priv(dev); | ||
549 | struct net_device_stats *stats = &dev->stats; | ||
550 | struct can_frame *cf; | ||
551 | struct sk_buff *skb; | ||
552 | u8 lec; | ||
553 | |||
554 | netdev_dbg(dev, "status interrupt (%#x)\n", status); | ||
555 | |||
556 | skb = alloc_can_err_skb(dev, &cf); | ||
557 | if (skb == NULL) | ||
558 | return -ENOMEM; | ||
559 | |||
560 | if (status & STAT_BOFF) { | ||
561 | /* Disable interrupts */ | ||
562 | cc770_write_reg(priv, control, CTRL_INI); | ||
563 | cf->can_id |= CAN_ERR_BUSOFF; | ||
564 | priv->can.state = CAN_STATE_BUS_OFF; | ||
565 | can_bus_off(dev); | ||
566 | } else if (status & STAT_WARN) { | ||
567 | cf->can_id |= CAN_ERR_CRTL; | ||
568 | cf->data[1] = CAN_ERR_CRTL_RX_WARNING | CAN_ERR_CRTL_TX_WARNING; | ||
569 | priv->can.state = CAN_STATE_ERROR_WARNING; | ||
570 | priv->can.can_stats.error_warning++; | ||
571 | } | ||
572 | |||
573 | lec = status & STAT_LEC_MASK; | ||
574 | if (lec < 7 && lec > 0) { | ||
575 | if (lec == STAT_LEC_ACK) { | ||
576 | cf->can_id |= CAN_ERR_ACK; | ||
577 | } else { | ||
578 | cf->can_id |= CAN_ERR_PROT; | ||
579 | switch (lec) { | ||
580 | case STAT_LEC_STUFF: | ||
581 | cf->data[2] |= CAN_ERR_PROT_STUFF; | ||
582 | break; | ||
583 | case STAT_LEC_FORM: | ||
584 | cf->data[2] |= CAN_ERR_PROT_FORM; | ||
585 | break; | ||
586 | case STAT_LEC_BIT1: | ||
587 | cf->data[2] |= CAN_ERR_PROT_BIT1; | ||
588 | break; | ||
589 | case STAT_LEC_BIT0: | ||
590 | cf->data[2] |= CAN_ERR_PROT_BIT0; | ||
591 | break; | ||
592 | case STAT_LEC_CRC: | ||
593 | cf->data[3] |= CAN_ERR_PROT_LOC_CRC_SEQ; | ||
594 | break; | ||
595 | } | ||
596 | } | ||
597 | } | ||
598 | |||
599 | netif_rx(skb); | ||
600 | |||
601 | stats->rx_packets++; | ||
602 | stats->rx_bytes += cf->can_dlc; | ||
603 | |||
604 | return 0; | ||
605 | } | ||
606 | |||
607 | static int cc770_status_interrupt(struct net_device *dev) | ||
608 | { | ||
609 | struct cc770_priv *priv = netdev_priv(dev); | ||
610 | u8 status; | ||
611 | |||
612 | status = cc770_read_reg(priv, status); | ||
613 | /* Reset the status register including RXOK and TXOK */ | ||
614 | cc770_write_reg(priv, status, STAT_LEC_MASK); | ||
615 | |||
616 | if (status & (STAT_WARN | STAT_BOFF) || | ||
617 | (status & STAT_LEC_MASK) != STAT_LEC_MASK) { | ||
618 | cc770_err(dev, status); | ||
619 | return status & STAT_BOFF; | ||
620 | } | ||
621 | |||
622 | return 0; | ||
623 | } | ||
624 | |||
625 | static void cc770_rx_interrupt(struct net_device *dev, unsigned int o) | ||
626 | { | ||
627 | struct cc770_priv *priv = netdev_priv(dev); | ||
628 | struct net_device_stats *stats = &dev->stats; | ||
629 | unsigned int mo = obj2msgobj(o); | ||
630 | u8 ctrl1; | ||
631 | |||
632 | while (1) { | ||
633 | ctrl1 = cc770_read_reg(priv, msgobj[mo].ctrl1); | ||
634 | |||
635 | if (!(ctrl1 & NEWDAT_SET)) { | ||
636 | /* Check for RTR if additional functions are enabled */ | ||
637 | if (priv->control_normal_mode & CTRL_EAF) { | ||
638 | if (!(cc770_read_reg(priv, msgobj[mo].ctrl0) & | ||
639 | INTPND_SET)) | ||
640 | break; | ||
641 | } else { | ||
642 | break; | ||
643 | } | ||
644 | } | ||
645 | |||
646 | if (ctrl1 & MSGLST_SET) { | ||
647 | stats->rx_over_errors++; | ||
648 | stats->rx_errors++; | ||
649 | } | ||
650 | if (mo < MSGOBJ_LAST) | ||
651 | cc770_write_reg(priv, msgobj[mo].ctrl1, | ||
652 | NEWDAT_RES | MSGLST_RES | | ||
653 | TXRQST_UNC | RMTPND_UNC); | ||
654 | cc770_rx(dev, mo, ctrl1); | ||
655 | |||
656 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
657 | MSGVAL_SET | TXIE_RES | | ||
658 | RXIE_SET | INTPND_RES); | ||
659 | cc770_write_reg(priv, msgobj[mo].ctrl1, | ||
660 | NEWDAT_RES | MSGLST_RES | | ||
661 | TXRQST_RES | RMTPND_RES); | ||
662 | } | ||
663 | } | ||
664 | |||
665 | static void cc770_rtr_interrupt(struct net_device *dev, unsigned int o) | ||
666 | { | ||
667 | struct cc770_priv *priv = netdev_priv(dev); | ||
668 | unsigned int mo = obj2msgobj(o); | ||
669 | u8 ctrl0, ctrl1; | ||
670 | |||
671 | while (1) { | ||
672 | ctrl0 = cc770_read_reg(priv, msgobj[mo].ctrl0); | ||
673 | if (!(ctrl0 & INTPND_SET)) | ||
674 | break; | ||
675 | |||
676 | ctrl1 = cc770_read_reg(priv, msgobj[mo].ctrl1); | ||
677 | cc770_rx(dev, mo, ctrl1); | ||
678 | |||
679 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
680 | MSGVAL_SET | TXIE_RES | | ||
681 | RXIE_SET | INTPND_RES); | ||
682 | cc770_write_reg(priv, msgobj[mo].ctrl1, | ||
683 | NEWDAT_RES | CPUUPD_SET | | ||
684 | TXRQST_RES | RMTPND_RES); | ||
685 | } | ||
686 | } | ||
687 | |||
688 | static void cc770_tx_interrupt(struct net_device *dev, unsigned int o) | ||
689 | { | ||
690 | struct cc770_priv *priv = netdev_priv(dev); | ||
691 | struct net_device_stats *stats = &dev->stats; | ||
692 | unsigned int mo = obj2msgobj(o); | ||
693 | |||
694 | /* Nothing more to send, switch off interrupts */ | ||
695 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
696 | MSGVAL_RES | TXIE_RES | RXIE_RES | INTPND_RES); | ||
697 | /* | ||
698 | * We had some cases of repeated IRQ so make sure the | ||
699 | * INT is acknowledged | ||
700 | */ | ||
701 | cc770_write_reg(priv, msgobj[mo].ctrl0, | ||
702 | MSGVAL_UNC | TXIE_UNC | RXIE_UNC | INTPND_RES); | ||
703 | |||
704 | stats->tx_packets++; | ||
705 | can_get_echo_skb(dev, 0); | ||
706 | netif_wake_queue(dev); | ||
707 | } | ||
708 | |||
709 | irqreturn_t cc770_interrupt(int irq, void *dev_id) | ||
710 | { | ||
711 | struct net_device *dev = (struct net_device *)dev_id; | ||
712 | struct cc770_priv *priv = netdev_priv(dev); | ||
713 | u8 intid; | ||
714 | int o, n = 0; | ||
715 | |||
716 | /* Shared interrupts and IRQ off? */ | ||
717 | if (priv->can.state == CAN_STATE_STOPPED) | ||
718 | return IRQ_NONE; | ||
719 | |||
720 | if (priv->pre_irq) | ||
721 | priv->pre_irq(priv); | ||
722 | |||
723 | while (n < CC770_MAX_IRQ) { | ||
724 | /* Read the highest pending interrupt request */ | ||
725 | intid = cc770_read_reg(priv, interrupt); | ||
726 | if (!intid) | ||
727 | break; | ||
728 | n++; | ||
729 | |||
730 | if (intid == 1) { | ||
731 | /* Exit in case of bus-off */ | ||
732 | if (cc770_status_interrupt(dev)) | ||
733 | break; | ||
734 | } else { | ||
735 | o = intid2obj(intid); | ||
736 | |||
737 | if (o >= CC770_OBJ_MAX) { | ||
738 | netdev_err(dev, "Unexpected interrupt id %d\n", | ||
739 | intid); | ||
740 | continue; | ||
741 | } | ||
742 | |||
743 | if (priv->obj_flags[o] & CC770_OBJ_FLAG_RTR) | ||
744 | cc770_rtr_interrupt(dev, o); | ||
745 | else if (priv->obj_flags[o] & CC770_OBJ_FLAG_RX) | ||
746 | cc770_rx_interrupt(dev, o); | ||
747 | else | ||
748 | cc770_tx_interrupt(dev, o); | ||
749 | } | ||
750 | } | ||
751 | |||
752 | if (priv->post_irq) | ||
753 | priv->post_irq(priv); | ||
754 | |||
755 | if (n >= CC770_MAX_IRQ) | ||
756 | netdev_dbg(dev, "%d messages handled in ISR", n); | ||
757 | |||
758 | return (n) ? IRQ_HANDLED : IRQ_NONE; | ||
759 | } | ||
760 | |||
761 | static int cc770_open(struct net_device *dev) | ||
762 | { | ||
763 | struct cc770_priv *priv = netdev_priv(dev); | ||
764 | int err; | ||
765 | |||
766 | /* set chip into reset mode */ | ||
767 | set_reset_mode(dev); | ||
768 | |||
769 | /* common open */ | ||
770 | err = open_candev(dev); | ||
771 | if (err) | ||
772 | return err; | ||
773 | |||
774 | err = request_irq(dev->irq, &cc770_interrupt, priv->irq_flags, | ||
775 | dev->name, (void *)dev); | ||
776 | if (err) { | ||
777 | close_candev(dev); | ||
778 | return -EAGAIN; | ||
779 | } | ||
780 | |||
781 | /* init and start chip */ | ||
782 | cc770_start(dev); | ||
783 | priv->open_time = jiffies; | ||
784 | |||
785 | netif_start_queue(dev); | ||
786 | |||
787 | return 0; | ||
788 | } | ||
789 | |||
790 | static int cc770_close(struct net_device *dev) | ||
791 | { | ||
792 | struct cc770_priv *priv = netdev_priv(dev); | ||
793 | |||
794 | netif_stop_queue(dev); | ||
795 | set_reset_mode(dev); | ||
796 | |||
797 | free_irq(dev->irq, (void *)dev); | ||
798 | close_candev(dev); | ||
799 | |||
800 | priv->open_time = 0; | ||
801 | |||
802 | return 0; | ||
803 | } | ||
804 | |||
805 | struct net_device *alloc_cc770dev(int sizeof_priv) | ||
806 | { | ||
807 | struct net_device *dev; | ||
808 | struct cc770_priv *priv; | ||
809 | |||
810 | dev = alloc_candev(sizeof(struct cc770_priv) + sizeof_priv, | ||
811 | CC770_ECHO_SKB_MAX); | ||
812 | if (!dev) | ||
813 | return NULL; | ||
814 | |||
815 | priv = netdev_priv(dev); | ||
816 | |||
817 | priv->dev = dev; | ||
818 | priv->can.bittiming_const = &cc770_bittiming_const; | ||
819 | priv->can.do_set_bittiming = cc770_set_bittiming; | ||
820 | priv->can.do_set_mode = cc770_set_mode; | ||
821 | priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES; | ||
822 | |||
823 | memcpy(priv->obj_flags, cc770_obj_flags, sizeof(cc770_obj_flags)); | ||
824 | |||
825 | if (sizeof_priv) | ||
826 | priv->priv = (void *)priv + sizeof(struct cc770_priv); | ||
827 | |||
828 | return dev; | ||
829 | } | ||
830 | EXPORT_SYMBOL_GPL(alloc_cc770dev); | ||
831 | |||
832 | void free_cc770dev(struct net_device *dev) | ||
833 | { | ||
834 | free_candev(dev); | ||
835 | } | ||
836 | EXPORT_SYMBOL_GPL(free_cc770dev); | ||
837 | |||
838 | static const struct net_device_ops cc770_netdev_ops = { | ||
839 | .ndo_open = cc770_open, | ||
840 | .ndo_stop = cc770_close, | ||
841 | .ndo_start_xmit = cc770_start_xmit, | ||
842 | }; | ||
843 | |||
844 | int register_cc770dev(struct net_device *dev) | ||
845 | { | ||
846 | struct cc770_priv *priv = netdev_priv(dev); | ||
847 | |||
848 | if (!cc770_probe_chip(dev)) | ||
849 | return -ENODEV; | ||
850 | |||
851 | dev->netdev_ops = &cc770_netdev_ops; | ||
852 | |||
853 | dev->flags |= IFF_ECHO; /* we support local echo */ | ||
854 | |||
855 | /* Should we use additional functions? */ | ||
856 | if (!i82527_compat && priv->control_normal_mode & CTRL_EAF) { | ||
857 | priv->control_normal_mode = CTRL_IE | CTRL_EAF | CTRL_EIE; | ||
858 | netdev_dbg(dev, "i82527 mode with additional functions\n"); | ||
859 | } else { | ||
860 | priv->control_normal_mode = CTRL_IE | CTRL_EIE; | ||
861 | netdev_dbg(dev, "strict i82527 compatibility mode\n"); | ||
862 | } | ||
863 | |||
864 | chipset_init(priv); | ||
865 | set_reset_mode(dev); | ||
866 | |||
867 | return register_candev(dev); | ||
868 | } | ||
869 | EXPORT_SYMBOL_GPL(register_cc770dev); | ||
870 | |||
871 | void unregister_cc770dev(struct net_device *dev) | ||
872 | { | ||
873 | set_reset_mode(dev); | ||
874 | unregister_candev(dev); | ||
875 | } | ||
876 | EXPORT_SYMBOL_GPL(unregister_cc770dev); | ||
877 | |||
878 | static __init int cc770_init(void) | ||
879 | { | ||
880 | if (msgobj15_eff) { | ||
881 | cc770_obj_flags[CC770_OBJ_RX0] |= CC770_OBJ_FLAG_EFF; | ||
882 | cc770_obj_flags[CC770_OBJ_RX1] &= ~CC770_OBJ_FLAG_EFF; | ||
883 | } | ||
884 | |||
885 | pr_info("%s CAN netdevice driver\n", DRV_NAME); | ||
886 | |||
887 | return 0; | ||
888 | } | ||
889 | module_init(cc770_init); | ||
890 | |||
891 | static __exit void cc770_exit(void) | ||
892 | { | ||
893 | pr_info("%s: driver removed\n", DRV_NAME); | ||
894 | } | ||
895 | module_exit(cc770_exit); | ||
diff --git a/drivers/net/can/cc770/cc770.h b/drivers/net/can/cc770/cc770.h deleted file mode 100644 index ca5b76866367..000000000000 --- a/drivers/net/can/cc770/cc770.h +++ /dev/null | |||
@@ -1,247 +0,0 @@ | |||
1 | /* | ||
2 | * cc770.h - Bosch CC770 and Intel AN82527 network device driver | ||
3 | * | ||
4 | * Copyright (C) 2009, 2011 Wolfgang Grandegger <wg@grandegger.com> | ||
5 | * | ||
6 | * Derived from the old Socket-CAN i82527 driver: | ||
7 | * | ||
8 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research | ||
9 | * All rights reserved. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * 3. Neither the name of Volkswagen nor the names of its contributors | ||
20 | * may be used to endorse or promote products derived from this software | ||
21 | * without specific prior written permission. | ||
22 | * | ||
23 | * Alternatively, provided that this notice is retained in full, this | ||
24 | * software may be distributed under the terms of the GNU General | ||
25 | * Public License ("GPL") version 2, in which case the provisions of the | ||
26 | * GPL apply INSTEAD OF those given above. | ||
27 | * | ||
28 | * The provided data structures and external interfaces from this code | ||
29 | * are not restricted to be used by modules with a GPL compatible license. | ||
30 | * | ||
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
35 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
36 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
37 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
38 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
39 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
40 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
41 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
42 | * DAMAGE. | ||
43 | * | ||
44 | * Send feedback to <socketcan-users@lists.berlios.de> | ||
45 | */ | ||
46 | |||
47 | #ifndef CC770_DEV_H | ||
48 | #define CC770_DEV_H | ||
49 | |||
50 | #include <linux/can/dev.h> | ||
51 | |||
52 | struct cc770_msgobj { | ||
53 | u8 ctrl0; | ||
54 | u8 ctrl1; | ||
55 | u8 id[4]; | ||
56 | u8 config; | ||
57 | u8 data[8]; | ||
58 | u8 dontuse; /* padding */ | ||
59 | } __attribute__ ((packed)); | ||
60 | |||
61 | struct cc770_regs { | ||
62 | union { | ||
63 | struct cc770_msgobj msgobj[16]; /* Message object 1..15 */ | ||
64 | struct { | ||
65 | u8 control; /* Control Register */ | ||
66 | u8 status; /* Status Register */ | ||
67 | u8 cpu_interface; /* CPU Interface Register */ | ||
68 | u8 dontuse1; | ||
69 | u8 high_speed_read[2]; /* High Speed Read */ | ||
70 | u8 global_mask_std[2]; /* Standard Global Mask */ | ||
71 | u8 global_mask_ext[4]; /* Extended Global Mask */ | ||
72 | u8 msg15_mask[4]; /* Message 15 Mask */ | ||
73 | u8 dontuse2[15]; | ||
74 | u8 clkout; /* Clock Out Register */ | ||
75 | u8 dontuse3[15]; | ||
76 | u8 bus_config; /* Bus Configuration Register */ | ||
77 | u8 dontuse4[15]; | ||
78 | u8 bit_timing_0; /* Bit Timing Register byte 0 */ | ||
79 | u8 dontuse5[15]; | ||
80 | u8 bit_timing_1; /* Bit Timing Register byte 1 */ | ||
81 | u8 dontuse6[15]; | ||
82 | u8 interrupt; /* Interrupt Register */ | ||
83 | u8 dontuse7[15]; | ||
84 | u8 rx_error_counter; /* Receive Error Counter */ | ||
85 | u8 dontuse8[15]; | ||
86 | u8 tx_error_counter; /* Transmit Error Counter */ | ||
87 | u8 dontuse9[31]; | ||
88 | u8 p1_conf; | ||
89 | u8 dontuse10[15]; | ||
90 | u8 p2_conf; | ||
91 | u8 dontuse11[15]; | ||
92 | u8 p1_in; | ||
93 | u8 dontuse12[15]; | ||
94 | u8 p2_in; | ||
95 | u8 dontuse13[15]; | ||
96 | u8 p1_out; | ||
97 | u8 dontuse14[15]; | ||
98 | u8 p2_out; | ||
99 | u8 dontuse15[15]; | ||
100 | u8 serial_reset_addr; | ||
101 | }; | ||
102 | }; | ||
103 | } __attribute__ ((packed)); | ||
104 | |||
105 | /* Control Register (0x00) */ | ||
106 | #define CTRL_INI 0x01 /* Initialization */ | ||
107 | #define CTRL_IE 0x02 /* Interrupt Enable */ | ||
108 | #define CTRL_SIE 0x04 /* Status Interrupt Enable */ | ||
109 | #define CTRL_EIE 0x08 /* Error Interrupt Enable */ | ||
110 | #define CTRL_EAF 0x20 /* Enable additional functions */ | ||
111 | #define CTRL_CCE 0x40 /* Change Configuration Enable */ | ||
112 | |||
113 | /* Status Register (0x01) */ | ||
114 | #define STAT_LEC_STUFF 0x01 /* Stuff error */ | ||
115 | #define STAT_LEC_FORM 0x02 /* Form error */ | ||
116 | #define STAT_LEC_ACK 0x03 /* Acknowledgement error */ | ||
117 | #define STAT_LEC_BIT1 0x04 /* Bit1 error */ | ||
118 | #define STAT_LEC_BIT0 0x05 /* Bit0 error */ | ||
119 | #define STAT_LEC_CRC 0x06 /* CRC error */ | ||
120 | #define STAT_LEC_MASK 0x07 /* Last Error Code mask */ | ||
121 | #define STAT_TXOK 0x08 /* Transmit Message Successfully */ | ||
122 | #define STAT_RXOK 0x10 /* Receive Message Successfully */ | ||
123 | #define STAT_WAKE 0x20 /* Wake Up Status */ | ||
124 | #define STAT_WARN 0x40 /* Warning Status */ | ||
125 | #define STAT_BOFF 0x80 /* Bus Off Status */ | ||
126 | |||
127 | /* CPU Interface Register (0x02) */ | ||
128 | #define CPUIF_CEN 0x01 /* Clock Out Enable */ | ||
129 | #define CPUIF_MUX 0x04 /* Multiplex */ | ||
130 | #define CPUIF_SLP 0x08 /* Sleep */ | ||
131 | #define CPUIF_PWD 0x10 /* Power Down Mode */ | ||
132 | #define CPUIF_DMC 0x20 /* Divide Memory Clock */ | ||
133 | #define CPUIF_DSC 0x40 /* Divide System Clock */ | ||
134 | #define CPUIF_RST 0x80 /* Hardware Reset Status */ | ||
135 | |||
136 | /* Clock Out Register (0x1f) */ | ||
137 | #define CLKOUT_CD_MASK 0x0f /* Clock Divider mask */ | ||
138 | #define CLKOUT_SL_MASK 0x30 /* Slew Rate mask */ | ||
139 | #define CLKOUT_SL_SHIFT 4 | ||
140 | |||
141 | /* Bus Configuration Register (0x2f) */ | ||
142 | #define BUSCFG_DR0 0x01 /* Disconnect RX0 Input / Select RX input */ | ||
143 | #define BUSCFG_DR1 0x02 /* Disconnect RX1 Input / Silent mode */ | ||
144 | #define BUSCFG_DT1 0x08 /* Disconnect TX1 Output */ | ||
145 | #define BUSCFG_POL 0x20 /* Polarity dominant or recessive */ | ||
146 | #define BUSCFG_CBY 0x40 /* Input Comparator Bypass */ | ||
147 | |||
148 | /* Message Control Register 0 (Base Address + 0x0) */ | ||
149 | #define INTPND_RES 0x01 /* No Interrupt pending */ | ||
150 | #define INTPND_SET 0x02 /* Interrupt pending */ | ||
151 | #define INTPND_UNC 0x03 | ||
152 | #define RXIE_RES 0x04 /* Receive Interrupt Disable */ | ||
153 | #define RXIE_SET 0x08 /* Receive Interrupt Enable */ | ||
154 | #define RXIE_UNC 0x0c | ||
155 | #define TXIE_RES 0x10 /* Transmit Interrupt Disable */ | ||
156 | #define TXIE_SET 0x20 /* Transmit Interrupt Enable */ | ||
157 | #define TXIE_UNC 0x30 | ||
158 | #define MSGVAL_RES 0x40 /* Message Invalid */ | ||
159 | #define MSGVAL_SET 0x80 /* Message Valid */ | ||
160 | #define MSGVAL_UNC 0xc0 | ||
161 | |||
162 | /* Message Control Register 1 (Base Address + 0x01) */ | ||
163 | #define NEWDAT_RES 0x01 /* No New Data */ | ||
164 | #define NEWDAT_SET 0x02 /* New Data */ | ||
165 | #define NEWDAT_UNC 0x03 | ||
166 | #define MSGLST_RES 0x04 /* No Message Lost */ | ||
167 | #define MSGLST_SET 0x08 /* Message Lost */ | ||
168 | #define MSGLST_UNC 0x0c | ||
169 | #define CPUUPD_RES 0x04 /* No CPU Updating */ | ||
170 | #define CPUUPD_SET 0x08 /* CPU Updating */ | ||
171 | #define CPUUPD_UNC 0x0c | ||
172 | #define TXRQST_RES 0x10 /* No Transmission Request */ | ||
173 | #define TXRQST_SET 0x20 /* Transmission Request */ | ||
174 | #define TXRQST_UNC 0x30 | ||
175 | #define RMTPND_RES 0x40 /* No Remote Request Pending */ | ||
176 | #define RMTPND_SET 0x80 /* Remote Request Pending */ | ||
177 | #define RMTPND_UNC 0xc0 | ||
178 | |||
179 | /* Message Configuration Register (Base Address + 0x06) */ | ||
180 | #define MSGCFG_XTD 0x04 /* Extended Identifier */ | ||
181 | #define MSGCFG_DIR 0x08 /* Direction is Transmit */ | ||
182 | |||
183 | #define MSGOBJ_FIRST 1 | ||
184 | #define MSGOBJ_LAST 15 | ||
185 | |||
186 | #define CC770_IO_SIZE 0x100 | ||
187 | #define CC770_MAX_IRQ 20 /* max. number of interrupts handled in ISR */ | ||
188 | |||
189 | #define CC770_ECHO_SKB_MAX 1 | ||
190 | |||
191 | #define cc770_read_reg(priv, member) \ | ||
192 | priv->read_reg(priv, offsetof(struct cc770_regs, member)) | ||
193 | |||
194 | #define cc770_write_reg(priv, member, value) \ | ||
195 | priv->write_reg(priv, offsetof(struct cc770_regs, member), value) | ||
196 | |||
197 | /* | ||
198 | * Message objects and flags used by this driver | ||
199 | */ | ||
200 | #define CC770_OBJ_FLAG_RX 0x01 | ||
201 | #define CC770_OBJ_FLAG_RTR 0x02 | ||
202 | #define CC770_OBJ_FLAG_EFF 0x04 | ||
203 | |||
204 | enum { | ||
205 | CC770_OBJ_RX0 = 0, /* for receiving normal messages */ | ||
206 | CC770_OBJ_RX1, /* for receiving normal messages */ | ||
207 | CC770_OBJ_RX_RTR0, /* for receiving remote transmission requests */ | ||
208 | CC770_OBJ_RX_RTR1, /* for receiving remote transmission requests */ | ||
209 | CC770_OBJ_TX, /* for sending messages */ | ||
210 | CC770_OBJ_MAX | ||
211 | }; | ||
212 | |||
213 | #define obj2msgobj(o) (MSGOBJ_LAST - (o)) /* message object 11..15 */ | ||
214 | |||
215 | /* | ||
216 | * CC770 private data structure | ||
217 | */ | ||
218 | struct cc770_priv { | ||
219 | struct can_priv can; /* must be the first member */ | ||
220 | int open_time; | ||
221 | struct sk_buff *echo_skb; | ||
222 | |||
223 | /* the lower-layer is responsible for appropriate locking */ | ||
224 | u8 (*read_reg)(const struct cc770_priv *priv, int reg); | ||
225 | void (*write_reg)(const struct cc770_priv *priv, int reg, u8 val); | ||
226 | void (*pre_irq)(const struct cc770_priv *priv); | ||
227 | void (*post_irq)(const struct cc770_priv *priv); | ||
228 | |||
229 | void *priv; /* for board-specific data */ | ||
230 | struct net_device *dev; | ||
231 | |||
232 | void __iomem *reg_base; /* ioremap'ed address to registers */ | ||
233 | unsigned long irq_flags; /* for request_irq() */ | ||
234 | |||
235 | unsigned char obj_flags[CC770_OBJ_MAX]; | ||
236 | u8 control_normal_mode; /* Control register for normal mode */ | ||
237 | u8 cpu_interface; /* CPU interface register */ | ||
238 | u8 clkout; /* Clock out register */ | ||
239 | u8 bus_config; /* Bus conffiguration register */ | ||
240 | }; | ||
241 | |||
242 | struct net_device *alloc_cc770dev(int sizeof_priv); | ||
243 | void free_cc770dev(struct net_device *dev); | ||
244 | int register_cc770dev(struct net_device *dev); | ||
245 | void unregister_cc770dev(struct net_device *dev); | ||
246 | |||
247 | #endif /* CC770_DEV_H */ | ||
diff --git a/drivers/net/can/cc770/cc770_isa.c b/drivers/net/can/cc770/cc770_isa.c deleted file mode 100644 index 455d79f534d0..000000000000 --- a/drivers/net/can/cc770/cc770_isa.c +++ /dev/null | |||
@@ -1,337 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009, 2011 Wolfgang Grandegger <wg@grandegger.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the version 2 of the GNU General Public License | ||
6 | * as published by the Free Software Foundation | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program; if not, write to the Free Software | ||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
16 | */ | ||
17 | |||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/version.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/interrupt.h> | ||
23 | #include <linux/netdevice.h> | ||
24 | #include <linux/delay.h> | ||
25 | #include <linux/irq.h> | ||
26 | #include <linux/io.h> | ||
27 | #include <linux/can.h> | ||
28 | #include <linux/can/dev.h> | ||
29 | |||
30 | #include "cc770.h" | ||
31 | |||
32 | #define DRV_NAME "cc770_isa" | ||
33 | |||
34 | #define MAXDEV 8 | ||
35 | |||
36 | MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>"); | ||
37 | MODULE_DESCRIPTION("Socket-CAN driver for CC770 on the ISA bus"); | ||
38 | MODULE_LICENSE("GPL v2"); | ||
39 | |||
40 | #define CLK_DEFAULT 16000000 /* 16 MHz */ | ||
41 | #define BCR_DEFAULT 0x00 | ||
42 | #define COR_DEFAULT 0x00 | ||
43 | |||
44 | static unsigned long port[MAXDEV]; | ||
45 | static unsigned long mem[MAXDEV]; | ||
46 | static int __devinitdata irq[MAXDEV]; | ||
47 | static int __devinitdata clk[MAXDEV]; | ||
48 | static u8 __devinitdata cir[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff}; | ||
49 | static u8 __devinitdata bcr[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff}; | ||
50 | static u8 __devinitdata cor[MAXDEV] = {[0 ... (MAXDEV - 1)] = 0xff}; | ||
51 | static int __devinitdata indirect[MAXDEV] = {[0 ... (MAXDEV - 1)] = -1}; | ||
52 | |||
53 | module_param_array(port, ulong, NULL, S_IRUGO); | ||
54 | MODULE_PARM_DESC(port, "I/O port number"); | ||
55 | |||
56 | module_param_array(mem, ulong, NULL, S_IRUGO); | ||
57 | MODULE_PARM_DESC(mem, "I/O memory address"); | ||
58 | |||
59 | module_param_array(indirect, int, NULL, S_IRUGO); | ||
60 | MODULE_PARM_DESC(indirect, "Indirect access via address and data port"); | ||
61 | |||
62 | module_param_array(irq, int, NULL, S_IRUGO); | ||
63 | MODULE_PARM_DESC(irq, "IRQ number"); | ||
64 | |||
65 | module_param_array(clk, int, NULL, S_IRUGO); | ||
66 | MODULE_PARM_DESC(clk, "External oscillator clock frequency " | ||
67 | "(default=16000000 [16 MHz])"); | ||
68 | |||
69 | module_param_array(cir, byte, NULL, S_IRUGO); | ||
70 | MODULE_PARM_DESC(cir, "CPU interface register (default=0x40 [CPU_DSC])"); | ||
71 | |||
72 | module_param_array(bcr, byte, NULL, S_IRUGO); | ||
73 | MODULE_PARM_DESC(ocr, "Bus configuration register (default=0x00)"); | ||
74 | |||
75 | module_param_array(cor, byte, NULL, S_IRUGO); | ||
76 | MODULE_PARM_DESC(cor, "Clockout register (default=0x00)"); | ||
77 | |||
78 | #define CC770_IOSIZE 0x20 | ||
79 | #define CC770_IOSIZE_INDIRECT 0x02 | ||
80 | |||
81 | static struct platform_device *cc770_isa_devs[MAXDEV]; | ||
82 | |||
83 | static u8 cc770_isa_mem_read_reg(const struct cc770_priv *priv, int reg) | ||
84 | { | ||
85 | return readb(priv->reg_base + reg); | ||
86 | } | ||
87 | |||
88 | static void cc770_isa_mem_write_reg(const struct cc770_priv *priv, | ||
89 | int reg, u8 val) | ||
90 | { | ||
91 | writeb(val, priv->reg_base + reg); | ||
92 | } | ||
93 | |||
94 | static u8 cc770_isa_port_read_reg(const struct cc770_priv *priv, int reg) | ||
95 | { | ||
96 | return inb((unsigned long)priv->reg_base + reg); | ||
97 | } | ||
98 | |||
99 | static void cc770_isa_port_write_reg(const struct cc770_priv *priv, | ||
100 | int reg, u8 val) | ||
101 | { | ||
102 | outb(val, (unsigned long)priv->reg_base + reg); | ||
103 | } | ||
104 | |||
105 | static u8 cc770_isa_port_read_reg_indirect(const struct cc770_priv *priv, | ||
106 | int reg) | ||
107 | { | ||
108 | unsigned long base = (unsigned long)priv->reg_base; | ||
109 | |||
110 | outb(reg, base); | ||
111 | return inb(base + 1); | ||
112 | } | ||
113 | |||
114 | static void cc770_isa_port_write_reg_indirect(const struct cc770_priv *priv, | ||
115 | int reg, u8 val) | ||
116 | { | ||
117 | unsigned long base = (unsigned long)priv->reg_base; | ||
118 | |||
119 | outb(reg, base); | ||
120 | outb(val, base + 1); | ||
121 | } | ||
122 | |||
123 | static int __devinit cc770_isa_probe(struct platform_device *pdev) | ||
124 | { | ||
125 | struct net_device *dev; | ||
126 | struct cc770_priv *priv; | ||
127 | void __iomem *base = NULL; | ||
128 | int iosize = CC770_IOSIZE; | ||
129 | int idx = pdev->id; | ||
130 | int err; | ||
131 | u32 clktmp; | ||
132 | |||
133 | dev_dbg(&pdev->dev, "probing idx=%d: port=%#lx, mem=%#lx, irq=%d\n", | ||
134 | idx, port[idx], mem[idx], irq[idx]); | ||
135 | if (mem[idx]) { | ||
136 | if (!request_mem_region(mem[idx], iosize, DRV_NAME)) { | ||
137 | err = -EBUSY; | ||
138 | goto exit; | ||
139 | } | ||
140 | base = ioremap_nocache(mem[idx], iosize); | ||
141 | if (!base) { | ||
142 | err = -ENOMEM; | ||
143 | goto exit_release; | ||
144 | } | ||
145 | } else { | ||
146 | if (indirect[idx] > 0 || | ||
147 | (indirect[idx] == -1 && indirect[0] > 0)) | ||
148 | iosize = CC770_IOSIZE_INDIRECT; | ||
149 | if (!request_region(port[idx], iosize, DRV_NAME)) { | ||
150 | err = -EBUSY; | ||
151 | goto exit; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | dev = alloc_cc770dev(0); | ||
156 | if (!dev) { | ||
157 | err = -ENOMEM; | ||
158 | goto exit_unmap; | ||
159 | } | ||
160 | priv = netdev_priv(dev); | ||
161 | |||
162 | dev->irq = irq[idx]; | ||
163 | priv->irq_flags = IRQF_SHARED; | ||
164 | if (mem[idx]) { | ||
165 | priv->reg_base = base; | ||
166 | dev->base_addr = mem[idx]; | ||
167 | priv->read_reg = cc770_isa_mem_read_reg; | ||
168 | priv->write_reg = cc770_isa_mem_write_reg; | ||
169 | } else { | ||
170 | priv->reg_base = (void __iomem *)port[idx]; | ||
171 | dev->base_addr = port[idx]; | ||
172 | |||
173 | if (iosize == CC770_IOSIZE_INDIRECT) { | ||
174 | priv->read_reg = cc770_isa_port_read_reg_indirect; | ||
175 | priv->write_reg = cc770_isa_port_write_reg_indirect; | ||
176 | } else { | ||
177 | priv->read_reg = cc770_isa_port_read_reg; | ||
178 | priv->write_reg = cc770_isa_port_write_reg; | ||
179 | } | ||
180 | } | ||
181 | |||
182 | if (clk[idx]) | ||
183 | clktmp = clk[idx]; | ||
184 | else if (clk[0]) | ||
185 | clktmp = clk[0]; | ||
186 | else | ||
187 | clktmp = CLK_DEFAULT; | ||
188 | priv->can.clock.freq = clktmp; | ||
189 | |||
190 | if (cir[idx] != 0xff) { | ||
191 | priv->cpu_interface = cir[idx] & 0xff; | ||
192 | } else if (cir[0] != 0xff) { | ||
193 | priv->cpu_interface = cir[0] & 0xff; | ||
194 | } else { | ||
195 | /* The system clock may not exceed 10 MHz */ | ||
196 | if (clktmp > 10000000) { | ||
197 | priv->cpu_interface |= CPUIF_DSC; | ||
198 | clktmp /= 2; | ||
199 | } | ||
200 | /* The memory clock may not exceed 8 MHz */ | ||
201 | if (clktmp > 8000000) | ||
202 | priv->cpu_interface |= CPUIF_DMC; | ||
203 | } | ||
204 | |||
205 | if (priv->cpu_interface & CPUIF_DSC) | ||
206 | priv->can.clock.freq /= 2; | ||
207 | |||
208 | if (bcr[idx] != 0xff) | ||
209 | priv->bus_config = bcr[idx] & 0xff; | ||
210 | else if (bcr[0] != 0xff) | ||
211 | priv->bus_config = bcr[0] & 0xff; | ||
212 | else | ||
213 | priv->bus_config = BCR_DEFAULT; | ||
214 | |||
215 | if (cor[idx] != 0xff) | ||
216 | priv->clkout = cor[idx]; | ||
217 | else if (cor[0] != 0xff) | ||
218 | priv->clkout = cor[0] & 0xff; | ||
219 | else | ||
220 | priv->clkout = COR_DEFAULT; | ||
221 | |||
222 | dev_set_drvdata(&pdev->dev, dev); | ||
223 | SET_NETDEV_DEV(dev, &pdev->dev); | ||
224 | |||
225 | err = register_cc770dev(dev); | ||
226 | if (err) { | ||
227 | dev_err(&pdev->dev, "registering %s failed (err=%d)\n", | ||
228 | DRV_NAME, err); | ||
229 | goto exit_unmap; | ||
230 | } | ||
231 | |||
232 | dev_info(&pdev->dev, "%s device registered (reg_base=0x%p, irq=%d)\n", | ||
233 | DRV_NAME, priv->reg_base, dev->irq); | ||
234 | return 0; | ||
235 | |||
236 | exit_unmap: | ||
237 | if (mem[idx]) | ||
238 | iounmap(base); | ||
239 | exit_release: | ||
240 | if (mem[idx]) | ||
241 | release_mem_region(mem[idx], iosize); | ||
242 | else | ||
243 | release_region(port[idx], iosize); | ||
244 | exit: | ||
245 | return err; | ||
246 | } | ||
247 | |||
248 | static int __devexit cc770_isa_remove(struct platform_device *pdev) | ||
249 | { | ||
250 | struct net_device *dev = dev_get_drvdata(&pdev->dev); | ||
251 | struct cc770_priv *priv = netdev_priv(dev); | ||
252 | int idx = pdev->id; | ||
253 | |||
254 | unregister_cc770dev(dev); | ||
255 | dev_set_drvdata(&pdev->dev, NULL); | ||
256 | |||
257 | if (mem[idx]) { | ||
258 | iounmap(priv->reg_base); | ||
259 | release_mem_region(mem[idx], CC770_IOSIZE); | ||
260 | } else { | ||
261 | if (priv->read_reg == cc770_isa_port_read_reg_indirect) | ||
262 | release_region(port[idx], CC770_IOSIZE_INDIRECT); | ||
263 | else | ||
264 | release_region(port[idx], CC770_IOSIZE); | ||
265 | } | ||
266 | free_cc770dev(dev); | ||
267 | |||
268 | return 0; | ||
269 | } | ||
270 | |||
271 | static struct platform_driver cc770_isa_driver = { | ||
272 | .probe = cc770_isa_probe, | ||
273 | .remove = __devexit_p(cc770_isa_remove), | ||
274 | .driver = { | ||
275 | .name = DRV_NAME, | ||
276 | .owner = THIS_MODULE, | ||
277 | }, | ||
278 | }; | ||
279 | |||
280 | static int __init cc770_isa_init(void) | ||
281 | { | ||
282 | int idx, err; | ||
283 | |||
284 | for (idx = 0; idx < MAXDEV; idx++) { | ||
285 | if ((port[idx] || mem[idx]) && irq[idx]) { | ||
286 | cc770_isa_devs[idx] = | ||
287 | platform_device_alloc(DRV_NAME, idx); | ||
288 | if (!cc770_isa_devs[idx]) { | ||
289 | err = -ENOMEM; | ||
290 | goto exit_free_devices; | ||
291 | } | ||
292 | err = platform_device_add(cc770_isa_devs[idx]); | ||
293 | if (err) { | ||
294 | platform_device_put(cc770_isa_devs[idx]); | ||
295 | goto exit_free_devices; | ||
296 | } | ||
297 | pr_debug("%s: platform device %d: port=%#lx, mem=%#lx, " | ||
298 | "irq=%d\n", | ||
299 | DRV_NAME, idx, port[idx], mem[idx], irq[idx]); | ||
300 | } else if (idx == 0 || port[idx] || mem[idx]) { | ||
301 | pr_err("%s: insufficient parameters supplied\n", | ||
302 | DRV_NAME); | ||
303 | err = -EINVAL; | ||
304 | goto exit_free_devices; | ||
305 | } | ||
306 | } | ||
307 | |||
308 | err = platform_driver_register(&cc770_isa_driver); | ||
309 | if (err) | ||
310 | goto exit_free_devices; | ||
311 | |||
312 | pr_info("Legacy %s driver for max. %d devices registered\n", | ||
313 | DRV_NAME, MAXDEV); | ||
314 | |||
315 | return 0; | ||
316 | |||
317 | exit_free_devices: | ||
318 | while (--idx >= 0) { | ||
319 | if (cc770_isa_devs[idx]) | ||
320 | platform_device_unregister(cc770_isa_devs[idx]); | ||
321 | } | ||
322 | |||
323 | return err; | ||
324 | } | ||
325 | module_init(cc770_isa_init); | ||
326 | |||
327 | static void __exit cc770_isa_exit(void) | ||
328 | { | ||
329 | int idx; | ||
330 | |||
331 | platform_driver_unregister(&cc770_isa_driver); | ||
332 | for (idx = 0; idx < MAXDEV; idx++) { | ||
333 | if (cc770_isa_devs[idx]) | ||
334 | platform_device_unregister(cc770_isa_devs[idx]); | ||
335 | } | ||
336 | } | ||
337 | module_exit(cc770_isa_exit); | ||