Add linux-next specific files for 20110831
[linux-2.6/next.git] / drivers / net / can / sja1000 / sja1000.h
blob78bd4ecac1402e15dee2348abb5c2ce6ad754684
1 /*
2 * sja1000.h - Philips SJA1000 network device driver
4 * Copyright (c) 2003 Matthias Brukner, Trajet Gmbh, Rebenring 33,
5 * 38106 Braunschweig, GERMANY
7 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Volkswagen nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * Alternatively, provided that this notice is retained in full, this
23 * software may be distributed under the terms of the GNU General
24 * Public License ("GPL") version 2, in which case the provisions of the
25 * GPL apply INSTEAD OF those given above.
27 * The provided data structures and external interfaces from this code
28 * are not restricted to be used by modules with a GPL compatible license.
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
41 * DAMAGE.
43 * Send feedback to <socketcan-users@lists.berlios.de>
47 #ifndef SJA1000_DEV_H
48 #define SJA1000_DEV_H
50 #include <linux/irqreturn.h>
51 #include <linux/can/dev.h>
52 #include <linux/can/platform/sja1000.h>
54 #define SJA1000_ECHO_SKB_MAX 1 /* the SJA1000 has one TX buffer object */
56 #define SJA1000_MAX_IRQ 20 /* max. number of interrupts handled in ISR */
58 /* SJA1000 registers - manual section 6.4 (Pelican Mode) */
59 #define REG_MOD 0x00
60 #define REG_CMR 0x01
61 #define REG_SR 0x02
62 #define REG_IR 0x03
63 #define REG_IER 0x04
64 #define REG_ALC 0x0B
65 #define REG_ECC 0x0C
66 #define REG_EWL 0x0D
67 #define REG_RXERR 0x0E
68 #define REG_TXERR 0x0F
69 #define REG_ACCC0 0x10
70 #define REG_ACCC1 0x11
71 #define REG_ACCC2 0x12
72 #define REG_ACCC3 0x13
73 #define REG_ACCM0 0x14
74 #define REG_ACCM1 0x15
75 #define REG_ACCM2 0x16
76 #define REG_ACCM3 0x17
77 #define REG_RMC 0x1D
78 #define REG_RBSA 0x1E
80 /* Common registers - manual section 6.5 */
81 #define REG_BTR0 0x06
82 #define REG_BTR1 0x07
83 #define REG_OCR 0x08
84 #define REG_CDR 0x1F
86 #define REG_FI 0x10
87 #define SFF_BUF 0x13
88 #define EFF_BUF 0x15
90 #define FI_FF 0x80
91 #define FI_RTR 0x40
93 #define REG_ID1 0x11
94 #define REG_ID2 0x12
95 #define REG_ID3 0x13
96 #define REG_ID4 0x14
98 #define CAN_RAM 0x20
100 /* mode register */
101 #define MOD_RM 0x01
102 #define MOD_LOM 0x02
103 #define MOD_STM 0x04
104 #define MOD_AFM 0x08
105 #define MOD_SM 0x10
107 /* commands */
108 #define CMD_SRR 0x10
109 #define CMD_CDO 0x08
110 #define CMD_RRB 0x04
111 #define CMD_AT 0x02
112 #define CMD_TR 0x01
114 /* interrupt sources */
115 #define IRQ_BEI 0x80
116 #define IRQ_ALI 0x40
117 #define IRQ_EPI 0x20
118 #define IRQ_WUI 0x10
119 #define IRQ_DOI 0x08
120 #define IRQ_EI 0x04
121 #define IRQ_TI 0x02
122 #define IRQ_RI 0x01
123 #define IRQ_ALL 0xFF
124 #define IRQ_OFF 0x00
126 /* status register content */
127 #define SR_BS 0x80
128 #define SR_ES 0x40
129 #define SR_TS 0x20
130 #define SR_RS 0x10
131 #define SR_TCS 0x08
132 #define SR_TBS 0x04
133 #define SR_DOS 0x02
134 #define SR_RBS 0x01
136 #define SR_CRIT (SR_BS|SR_ES)
138 /* ECC register */
139 #define ECC_SEG 0x1F
140 #define ECC_DIR 0x20
141 #define ECC_ERR 6
142 #define ECC_BIT 0x00
143 #define ECC_FORM 0x40
144 #define ECC_STUFF 0x80
145 #define ECC_MASK 0xc0
148 * Flags for sja1000priv.flags
150 #define SJA1000_CUSTOM_IRQ_HANDLER 0x1
153 * SJA1000 private data structure
155 struct sja1000_priv {
156 struct can_priv can; /* must be the first member */
157 int open_time;
158 struct sk_buff *echo_skb;
160 /* the lower-layer is responsible for appropriate locking */
161 u8 (*read_reg) (const struct sja1000_priv *priv, int reg);
162 void (*write_reg) (const struct sja1000_priv *priv, int reg, u8 val);
163 void (*pre_irq) (const struct sja1000_priv *priv);
164 void (*post_irq) (const struct sja1000_priv *priv);
166 void *priv; /* for board-specific data */
167 struct net_device *dev;
169 void __iomem *reg_base; /* ioremap'ed address to registers */
170 unsigned long irq_flags; /* for request_irq() */
171 spinlock_t cmdreg_lock; /* lock for concurrent cmd register writes */
173 u16 flags; /* custom mode flags */
174 u8 ocr; /* output control register */
175 u8 cdr; /* clock divider register */
178 struct net_device *alloc_sja1000dev(int sizeof_priv);
179 void free_sja1000dev(struct net_device *dev);
180 int register_sja1000dev(struct net_device *dev);
181 void unregister_sja1000dev(struct net_device *dev);
183 irqreturn_t sja1000_interrupt(int irq, void *dev_id);
185 #endif /* SJA1000_DEV_H */