]> rtime.felk.cvut.cz Git - socketcan-devel.git/blob - kernel/2.6/drivers/net/can/cc770/cc770.h
merged branches/netlink in rev. 1037 back to trunk.
[socketcan-devel.git] / kernel / 2.6 / drivers / net / can / cc770 / cc770.h
1 /*
2  * $Id:  $
3  *
4  * cc770.h - Bosch CC770 and Intel AN82527 network device driver
5  *
6  * Copyright (C) 2009 Wolfgang Grandegger <wg@grandegger.com>
7  *
8  * Derived from the old Socket-CAN i82527 driver:
9  *
10  * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
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.
24  *
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.
29  *
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.
32  *
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
44  * DAMAGE.
45  *
46  * Send feedback to <socketcan-users@lists.berlios.de>
47  */
48
49 #ifndef CC770_DEV_H
50 #define CC770_DEV_H
51
52 #include <socketcan/can/dev.h>
53
54 struct cc770_msgobj {
55         u8 ctrl0;
56         u8 ctrl1;
57         u8 id[4];
58         u8 config;
59         u8 data[8];
60         u8 dontuse;             /* padding */
61 } __attribute__ ((packed));
62
63 struct cc770_regs {
64         union {
65                 struct cc770_msgobj msgobj[16]; /* Message object 1..15 */
66                 struct {
67                         u8 control;             /* Control Register */
68                         u8 status;              /* Status Register */
69                         u8 cpu_interface;       /* CPU Interface Register */
70                         u8 dontuse1;
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 */
75                         u8 dontuse2[15];
76                         u8 clkout;              /* Clock Out Register */
77                         u8 dontuse3[15];
78                         u8 bus_config;          /* Bus Configuration Register */
79                         u8 dontuse4[15];
80                         u8 bit_timing_0;        /* Bit Timing Register byte 0 */
81                         u8 dontuse5[15];
82                         u8 bit_timing_1;        /* Bit Timing Register byte 1 */
83                         u8 dontuse6[15];
84                         u8 interrupt;           /* Interrupt Register */
85                         u8 dontuse7[15];
86                         u8 rx_error_counter;    /* Receive Error Counter */
87                         u8 dontuse8[15];
88                         u8 tx_error_counter;    /* Transmit Error Counter */
89                         u8 dontuse9[31];
90                         u8 p1_conf;
91                         u8 dontuse10[15];
92                         u8 p2_conf;
93                         u8 dontuse11[15];
94                         u8 p1_in;
95                         u8 dontuse12[15];
96                         u8 p2_in;
97                         u8 dontuse13[15];
98                         u8 p1_out;
99                         u8 dontuse14[15];
100                         u8 p2_out;
101                         u8 dontuse15[15];
102                         u8 serial_reset_addr;
103                 };
104         };
105 } __attribute__ ((packed));
106
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 */
114
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 */
128
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 */
137
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
142
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 */
149
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
163
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
180
181 /* Message Configuration Register (Base Address + 0x06) */
182 #define MSGCFG_XTD      0x04    /* Extended Identifier */
183 #define MSGCFG_DIR      0x08    /* Direction is Transmit */
184
185 #define MSGOBJ_FIRST    1
186 #define MSGOBJ_LAST     15
187
188 #define CC770_IO_SIZE   0x100
189 #define CC770_MAX_IRQ   20      /* max. number of interrupts handled in ISR */
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 */