]> rtime.felk.cvut.cz Git - socketcan-devel.git/blob - kernel/2.6/drivers/sja1000/sja1000.h
fix version code.
[socketcan-devel.git] / kernel / 2.6 / drivers / sja1000 / sja1000.h
1 /*
2  * $Id: sja1000.h,v 2.0 2006/04/13 10:37:21 ethuerm Exp $
3  *
4  * sja1000.h -  Philips SJA1000 network device driver
5  *
6  * Copyright (c) 2003 Matthias Brukner, Trajet Gmbh, Rebenring 33,
7  * 38106 Braunschweig, GERMANY
8  *
9  * Copyright (c) 2002-2005 Volkswagen Group Electronic Research
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions, the following disclaimer and
17  *    the referenced file 'COPYING'.
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 as distributed in the 'COPYING'
28  * file from the main directory of the linux kernel source.
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 <llcf@volkswagen.de>
47  *
48  */
49
50 #ifndef __SJA1000_H__
51 #define __SJA1000_H__
52
53 #define SJA1000_IO_SIZE_BASIC   0x20
54 #define SJA1000_IO_SIZE_PELICAN 0x80
55
56 #define SJA1000_IO_SIZE_ISA     0x20
57
58 #define DEFAULT_SPEED   100 /* kBit/s */
59
60 #define TX_TIMEOUT      (HZ/20) /* 50ms */ 
61 #define RESTART_MS      100     /* restart chip on persistent errors in 100ms */
62 #define MAX_BUS_ERRORS  200     /* prevent from flooding bus error interrupts */
63
64 /* SJA1000 registers - manual section 6.4 (Pelican Mode) */
65 #define REG_MOD         0x00
66 #define REG_CMR         0x01
67 #define REG_SR          0x02
68 #define REG_IR          0x03
69 #define REG_IER         0x04
70 #define REG_ALC         0x0B
71 #define REG_ECC         0x0C
72 #define REG_EWL         0x0D
73 #define REG_RXERR       0x0E
74 #define REG_TXERR       0x0F
75 #define REG_ACCC0       0x10
76 #define REG_ACCC1       0x11
77 #define REG_ACCC2       0x12
78 #define REG_ACCC3       0x13
79 #define REG_ACCM0       0x14
80 #define REG_ACCM1       0x15
81 #define REG_ACCM2       0x16
82 #define REG_ACCM3       0x17
83 #define REG_RMC         0x1D
84 #define REG_RBSA        0x1E
85
86 /* Common registers - manual section 6.5 */
87 #define REG_BTR0        0x06
88 #define REG_BTR1        0x07
89 #define REG_OCR         0x08
90 #define REG_CDR         0x1F
91
92 #define REG_FI          0x10
93 #define SFF_BUF         0x13
94 #define EFF_BUF         0x15
95
96 #define FI_FF           0x80
97 #define FI_RTR          0x40
98
99 #define REG_ID1         0x11
100 #define REG_ID2         0x12
101 #define REG_ID3         0x13
102 #define REG_ID4         0x14
103
104 #define CAN_RAM         0x20
105
106 /* mode register */
107 #define MOD_RM          0x01
108 #define MOD_LOM         0x02
109 #define MOD_STM         0x04
110 #define MOD_AFM         0x08
111 #define MOD_SM          0x10
112
113 /* commands */
114 #define CMD_SRR         0x10
115 #define CMD_CDO         0x08
116 #define CMD_RRB         0x04
117 #define CMD_AT          0x02
118 #define CMD_TR          0x01
119
120 /* interrupt sources */
121 #define IRQ_BEI         0x80
122 #define IRQ_ALI         0x40
123 #define IRQ_EPI         0x20
124 #define IRQ_WUI         0x10
125 #define IRQ_DOI         0x08
126 #define IRQ_EI          0x04
127 #define IRQ_TI          0x02
128 #define IRQ_RI          0x01
129 #define IRQ_ALL         0xFF
130 #define IRQ_OFF         0x00
131
132 /* status register content */
133 #define SR_BS           0x80
134 #define SR_ES           0x40
135 #define SR_TS           0x20
136 #define SR_RS           0x10
137 #define SR_TCS          0x08
138 #define SR_TBS          0x04
139 #define SR_DOS          0x02
140 #define SR_RBS          0x01
141
142 #define SR_CRIT (SR_BS|SR_ES)
143
144 /* ECC register */
145 #define ECC_DIR         0x20
146 #define ECC_SEG         0x1F
147 #define ECC_ERR         6
148
149 /* bus timing */
150 #define MAX_TSEG1       15
151 #define MAX_TSEG2        7
152 #define SAMPLE_POINT    75
153 #define JUMPWIDTH     0x40
154
155
156 #define REG_READ(addr)          ((struct can_priv*)netdev_priv(dev))->reg_read(dev,addr)
157 #define REG_WRITE(addr,data)    ((struct can_priv*)netdev_priv(dev))->reg_write(dev,addr,data)
158
159 #define SJA1000_CHIP_NAME "sja1000"
160 #define PROCBASE          "net/drivers" /* /proc/ ... */
161
162 /*
163  * private data structure:
164  * reg_read and reg_write are functions to access the sja1000 registers
165  */
166 struct can_priv {
167         struct net_device_stats stats;
168         long                    open_time;
169         int                     clock;
170         int                     restart_ms;
171         int                     debug;
172         int                     speed;
173         int                     btr;
174         int                     rx_probe;
175         struct timer_list       timer;
176         uint8_t                 (*reg_read)(struct net_device *dev, int reg);
177         void                    (*reg_write)(struct net_device *dev, int reg, uint8_t val);
178         struct can_device_stats can_stats;
179         int                     state;
180 };
181
182 #define STATE_UNINITIALIZED     0
183 #define STATE_PROBE             1
184 #define STATE_ACTIVE            2
185 #define STATE_ERROR_ACTIVE      3
186 #define STATE_ERROR_PASSIVE     4
187 #define STATE_BUS_OFF           5
188 #define STATE_RESET_MODE        6
189
190 void sja1000_setup(struct net_device *dev);
191 void sja1000_proc_init(const char *drv_name, struct net_device **dev, int max);
192 void sja1000_proc_delete(const char *drv_name);
193
194 #endif /* __SJA1000_H__ */