4 * cc770.h - Bosch CC770 and Intel AN82527 network device driver
6 * Copyright (C) 2009 Wolfgang Grandegger <wg@grandegger.com>
8 * Derived from the old Socket-CAN i82527 driver:
10 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of Volkswagen nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * Alternatively, provided that this notice is retained in full, this
26 * software may be distributed under the terms of the GNU General
27 * Public License ("GPL") version 2, in which case the provisions of the
28 * GPL apply INSTEAD OF those given above.
30 * The provided data structures and external interfaces from this code
31 * are not restricted to be used by modules with a GPL compatible license.
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
37 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
40 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
41 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
46 * Send feedback to <socketcan-users@lists.berlios.de>
52 #include <socketcan/can/dev.h>
60 u8 dontuse; /* padding */
61 } __attribute__ ((packed));
65 struct cc770_msgobj msgobj[16]; /* Message object 1..15 */
67 u8 control; /* Control Register */
68 u8 status; /* Status Register */
69 u8 cpu_interface; /* CPU Interface Register */
71 u8 high_speed_read[2]; /* High Speed Read */
72 u8 global_mask_std[2]; /* Standard Global Mask */
73 u8 global_mask_ext[4]; /* Extended Global Mask */
74 u8 msg15_mask[4]; /* Message 15 Mask */
76 u8 clkout; /* Clock Out Register */
78 u8 bus_config; /* Bus Configuration Register */
80 u8 bit_timing_0; /* Bit Timing Register byte 0 */
82 u8 bit_timing_1; /* Bit Timing Register byte 1 */
84 u8 interrupt; /* Interrupt Register */
86 u8 rx_error_counter; /* Receive Error Counter */
88 u8 tx_error_counter; /* Transmit Error Counter */
102 u8 serial_reset_addr;
105 } __attribute__ ((packed));
107 /* Control Register (0x00) */
108 #define CTRL_INI 0x01 /* Initialization */
109 #define CTRL_IE 0x02 /* Interrupt Enable */
110 #define CTRL_SIE 0x04 /* Status Interrupt Enable */
111 #define CTRL_EIE 0x08 /* Error Interrupt Enable */
112 #define CTRL_EAF 0x20 /* Enable additional functions */
113 #define CTRL_CCE 0x40 /* Change Configuration Enable */
115 /* Status Register (0x01) */
116 #define STAT_LEC_STUFF 0x01 /* Stuff error */
117 #define STAT_LEC_FORM 0x02 /* Form error */
118 #define STAT_LEC_ACK 0x03 /* Acknowledgement error */
119 #define STAT_LEC_BIT1 0x04 /* Bit1 error */
120 #define STAT_LEC_BIT0 0x05 /* Bit0 error */
121 #define STAT_LEC_CRC 0x06 /* CRC error */
122 #define STAT_LEC_MASK 0x07 /* Last Error Code mask */
123 #define STAT_TXOK 0x08 /* Transmit Message Successfully */
124 #define STAT_RXOK 0x10 /* Receive Message Successfully */
125 #define STAT_WAKE 0x20 /* Wake Up Status */
126 #define STAT_WARN 0x40 /* Warning Status */
127 #define STAT_BOFF 0x80 /* Bus Off Status */
129 /* CPU Interface Register (0x02) */
130 #define CPUIF_CEN 0x01 /* Clock Out Enable */
131 #define CPUIF_MUX 0x04 /* Multiplex */
132 #define CPUIF_SLP 0x08 /* Sleep */
133 #define CPUIF_PWD 0x10 /* Power Down Mode */
134 #define CPUIF_DMC 0x20 /* Divide Memory Clock */
135 #define CPUIF_DSC 0x40 /* Divide System Clock */
136 #define CPUIF_RST 0x80 /* Hardware Reset Status */
138 /* Clock Out Register (0x1f) */
139 #define CLKOUT_CD_MASK 0x0f /* Clock Divider mask */
140 #define CLKOUT_SL_MASK 0x30 /* Slew Rate mask */
141 #define CLKOUT_SL_SHIFT 4
143 /* Bus Configuration Register (0x2f) */
144 #define BUSCFG_DR0 0x01 /* Disconnect RX0 Input / Select RX input */
145 #define BUSCFG_DR1 0x02 /* Disconnect RX1 Input / Silent mode */
146 #define BUSCFG_DT1 0x08 /* Disconnect TX1 Output */
147 #define BUSCFG_POL 0x20 /* Polarity dominant or recessive */
148 #define BUSCFG_CBY 0x40 /* Input Comparator Bypass */
150 /* Message Control Register 0 (Base Address + 0x0) */
151 #define INTPND_RES 0x01 /* No Interrupt pending */
152 #define INTPND_SET 0x02 /* Interrupt pending */
153 #define INTPND_UNC 0x03
154 #define RXIE_RES 0x04 /* Receive Interrupt Disable */
155 #define RXIE_SET 0x08 /* Receive Interrupt Enable */
156 #define RXIE_UNC 0x0c
157 #define TXIE_RES 0x10 /* Transmit Interrupt Disable */
158 #define TXIE_SET 0x20 /* Transmit Interrupt Enable */
159 #define TXIE_UNC 0x30
160 #define MSGVAL_RES 0x40 /* Message Invalid */
161 #define MSGVAL_SET 0x80 /* Message Valid */
162 #define MSGVAL_UNC 0xc0
164 /* Message Control Register 1 (Base Address + 0x01) */
165 #define NEWDAT_RES 0x01 /* No New Data */
166 #define NEWDAT_SET 0x02 /* New Data */
167 #define NEWDAT_UNC 0x03
168 #define MSGLST_RES 0x04 /* No Message Lost */
169 #define MSGLST_SET 0x08 /* Message Lost */
170 #define MSGLST_UNC 0x0c
171 #define CPUUPD_RES 0x04 /* No CPU Updating */
172 #define CPUUPD_SET 0x08 /* CPU Updating */
173 #define CPUUPD_UNC 0x0c
174 #define TXRQST_RES 0x10 /* No Transmission Request */
175 #define TXRQST_SET 0x20 /* Transmission Request */
176 #define TXRQST_UNC 0x30
177 #define RMTPND_RES 0x40 /* No Remote Request Pending */
178 #define RMTPND_SET 0x80 /* Remote Request Pending */
179 #define RMTPND_UNC 0xc0
181 /* Message Configuration Register (Base Address + 0x06) */
182 #define MSGCFG_XTD 0x04 /* Extended Identifier */
183 #define MSGCFG_DIR 0x08 /* Direction is Transmit */
185 #define MSGOBJ_FIRST 1
186 #define MSGOBJ_LAST 15
188 #define CC770_IO_SIZE 0x100
189 #define CC770_MAX_IRQ 20 /* max. number of interrupts handled in ISR */
191 #define cc770_read_reg(priv, member) \
192 priv->read_reg(priv, offsetof(struct cc770_regs, member))
194 #define cc770_write_reg(priv, member, value) \
195 priv->write_reg(priv, offsetof(struct cc770_regs, member), value)
198 * Message objects and flags used by this driver
200 #define CC770_OBJ_FLAG_RX 0x01
201 #define CC770_OBJ_FLAG_RTR 0x02
202 #define CC770_OBJ_FLAG_EFF 0x04
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 */
213 #define obj2msgobj(o) (MSGOBJ_LAST - (o)) /* message object 11..15 */
216 * CC770 private data structure
219 struct can_priv can; /* must be the first member */
221 struct sk_buff *echo_skb;
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);
229 void *priv; /* for board-specific data */
230 struct net_device *dev;
232 void __iomem *reg_base; /* ioremap'ed address to registers */
233 unsigned long irq_flags; /* for request_irq() */
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 */
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);
247 #endif /* CC770_DEV_H */