1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 #ifndef SJA1000_DEV_H
46 #define SJA1000_DEV_H
47
48 #include <linux/irqreturn.h>
49 #include <linux/can/dev.h>
50 #include <linux/can/platform/sja1000.h>
51
52 #define SJA1000_ECHO_SKB_MAX 1
53
54 #define SJA1000_MAX_IRQ 20
55
56
57 #define SJA1000_MOD 0x00
58 #define SJA1000_CMR 0x01
59 #define SJA1000_SR 0x02
60 #define SJA1000_IR 0x03
61 #define SJA1000_IER 0x04
62 #define SJA1000_ALC 0x0B
63 #define SJA1000_ECC 0x0C
64 #define SJA1000_EWL 0x0D
65 #define SJA1000_RXERR 0x0E
66 #define SJA1000_TXERR 0x0F
67 #define SJA1000_ACCC0 0x10
68 #define SJA1000_ACCC1 0x11
69 #define SJA1000_ACCC2 0x12
70 #define SJA1000_ACCC3 0x13
71 #define SJA1000_ACCM0 0x14
72 #define SJA1000_ACCM1 0x15
73 #define SJA1000_ACCM2 0x16
74 #define SJA1000_ACCM3 0x17
75 #define SJA1000_RMC 0x1D
76 #define SJA1000_RBSA 0x1E
77
78
79 #define SJA1000_BTR0 0x06
80 #define SJA1000_BTR1 0x07
81 #define SJA1000_OCR 0x08
82 #define SJA1000_CDR 0x1F
83
84 #define SJA1000_FI 0x10
85 #define SJA1000_SFF_BUF 0x13
86 #define SJA1000_EFF_BUF 0x15
87
88 #define SJA1000_FI_FF 0x80
89 #define SJA1000_FI_RTR 0x40
90
91 #define SJA1000_ID1 0x11
92 #define SJA1000_ID2 0x12
93 #define SJA1000_ID3 0x13
94 #define SJA1000_ID4 0x14
95
96 #define SJA1000_CAN_RAM 0x20
97
98
99 #define MOD_RM 0x01
100 #define MOD_LOM 0x02
101 #define MOD_STM 0x04
102 #define MOD_AFM 0x08
103 #define MOD_SM 0x10
104
105
106 #define CMD_SRR 0x10
107 #define CMD_CDO 0x08
108 #define CMD_RRB 0x04
109 #define CMD_AT 0x02
110 #define CMD_TR 0x01
111
112
113 #define IRQ_BEI 0x80
114 #define IRQ_ALI 0x40
115 #define IRQ_EPI 0x20
116 #define IRQ_WUI 0x10
117 #define IRQ_DOI 0x08
118 #define IRQ_EI 0x04
119 #define IRQ_TI 0x02
120 #define IRQ_RI 0x01
121 #define IRQ_ALL 0xFF
122 #define IRQ_OFF 0x00
123
124
125 #define SR_BS 0x80
126 #define SR_ES 0x40
127 #define SR_TS 0x20
128 #define SR_RS 0x10
129 #define SR_TCS 0x08
130 #define SR_TBS 0x04
131 #define SR_DOS 0x02
132 #define SR_RBS 0x01
133
134 #define SR_CRIT (SR_BS|SR_ES)
135
136
137 #define ECC_SEG 0x1F
138 #define ECC_DIR 0x20
139 #define ECC_ERR 6
140 #define ECC_BIT 0x00
141 #define ECC_FORM 0x40
142 #define ECC_STUFF 0x80
143 #define ECC_MASK 0xc0
144
145
146
147
148 #define SJA1000_CUSTOM_IRQ_HANDLER 0x1
149
150
151
152
153 struct sja1000_priv {
154 struct can_priv can;
155 struct sk_buff *echo_skb;
156
157
158 u8 (*read_reg) (const struct sja1000_priv *priv, int reg);
159 void (*write_reg) (const struct sja1000_priv *priv, int reg, u8 val);
160 void (*pre_irq) (const struct sja1000_priv *priv);
161 void (*post_irq) (const struct sja1000_priv *priv);
162
163 void *priv;
164 struct net_device *dev;
165
166 void __iomem *reg_base;
167 unsigned long irq_flags;
168 spinlock_t cmdreg_lock;
169
170 u16 flags;
171 u8 ocr;
172 u8 cdr;
173 };
174
175 struct net_device *alloc_sja1000dev(int sizeof_priv);
176 void free_sja1000dev(struct net_device *dev);
177 int register_sja1000dev(struct net_device *dev);
178 void unregister_sja1000dev(struct net_device *dev);
179
180 irqreturn_t sja1000_interrupt(int irq, void *dev_id);
181
182 #endif