aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2011-06-07 04:03:56 -0400
committerDavid S. Miller <davem@davemloft.net>2011-06-07 04:03:56 -0400
commitcb2bad862e66eafbc97c26011ab7ab6cedc82810 (patch)
treeb3c0d31062642421c3d5af17a61b6f89fa3d6816
parenta6b7a407865aab9f849dd99a71072b7cd1175116 (diff)
parentb9e379bccda6913f7baece42cd249824c0758b97 (diff)
Merge branch 'can/at91-sam9x5' of git://git.pengutronix.de/git/mkl/linux-2.6
-rw-r--r--drivers/net/can/Kconfig5
-rw-r--r--drivers/net/can/at91_can.c366
2 files changed, 259 insertions, 112 deletions
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index 1d699e3df547..bbf06f77ee8c 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -58,9 +58,10 @@ config CAN_CALC_BITTIMING
58 58
59config CAN_AT91 59config CAN_AT91
60 tristate "Atmel AT91 onchip CAN controller" 60 tristate "Atmel AT91 onchip CAN controller"
61 depends on CAN_DEV && ARCH_AT91SAM9263 61 depends on CAN_DEV && (ARCH_AT91SAM9263 || ARCH_AT91SAM9X5)
62 ---help--- 62 ---help---
63 This is a driver for the SoC CAN controller in Atmel's AT91SAM9263. 63 This is a driver for the SoC CAN controller in Atmel's AT91SAM9263
64 and AT91SAM9X5 processors.
64 65
65config CAN_TI_HECC 66config CAN_TI_HECC
66 depends on CAN_DEV && ARCH_OMAP3 67 depends on CAN_DEV && ARCH_OMAP3
diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c
index 74efb5a2ad41..121ede663e20 100644
--- a/drivers/net/can/at91_can.c
+++ b/drivers/net/can/at91_can.c
@@ -41,32 +41,7 @@
41 41
42#include <mach/board.h> 42#include <mach/board.h>
43 43
44#define AT91_NAPI_WEIGHT 11 44#define AT91_MB_MASK(i) ((1 << (i)) - 1)
45
46/*
47 * RX/TX Mailbox split
48 * don't dare to touch
49 */
50#define AT91_MB_RX_NUM 11
51#define AT91_MB_TX_SHIFT 2
52
53#define AT91_MB_RX_FIRST 1
54#define AT91_MB_RX_LAST (AT91_MB_RX_FIRST + AT91_MB_RX_NUM - 1)
55
56#define AT91_MB_RX_MASK(i) ((1 << (i)) - 1)
57#define AT91_MB_RX_SPLIT 8
58#define AT91_MB_RX_LOW_LAST (AT91_MB_RX_SPLIT - 1)
59#define AT91_MB_RX_LOW_MASK (AT91_MB_RX_MASK(AT91_MB_RX_SPLIT) & \
60 ~AT91_MB_RX_MASK(AT91_MB_RX_FIRST))
61
62#define AT91_MB_TX_NUM (1 << AT91_MB_TX_SHIFT)
63#define AT91_MB_TX_FIRST (AT91_MB_RX_LAST + 1)
64#define AT91_MB_TX_LAST (AT91_MB_TX_FIRST + AT91_MB_TX_NUM - 1)
65
66#define AT91_NEXT_PRIO_SHIFT (AT91_MB_TX_SHIFT)
67#define AT91_NEXT_PRIO_MASK (0xf << AT91_MB_TX_SHIFT)
68#define AT91_NEXT_MB_MASK (AT91_MB_TX_NUM - 1)
69#define AT91_NEXT_MASK ((AT91_MB_TX_NUM - 1) | AT91_NEXT_PRIO_MASK)
70 45
71/* Common registers */ 46/* Common registers */
72enum at91_reg { 47enum at91_reg {
@@ -128,12 +103,6 @@ enum at91_mb_mode {
128}; 103};
129 104
130/* Interrupt mask bits */ 105/* Interrupt mask bits */
131#define AT91_IRQ_MB_RX ((1 << (AT91_MB_RX_LAST + 1)) \
132 - (1 << AT91_MB_RX_FIRST))
133#define AT91_IRQ_MB_TX ((1 << (AT91_MB_TX_LAST + 1)) \
134 - (1 << AT91_MB_TX_FIRST))
135#define AT91_IRQ_MB_ALL (AT91_IRQ_MB_RX | AT91_IRQ_MB_TX)
136
137#define AT91_IRQ_ERRA (1 << 16) 106#define AT91_IRQ_ERRA (1 << 16)
138#define AT91_IRQ_WARN (1 << 17) 107#define AT91_IRQ_WARN (1 << 17)
139#define AT91_IRQ_ERRP (1 << 18) 108#define AT91_IRQ_ERRP (1 << 18)
@@ -156,22 +125,51 @@ enum at91_mb_mode {
156 125
157#define AT91_IRQ_ALL (0x1fffffff) 126#define AT91_IRQ_ALL (0x1fffffff)
158 127
128enum at91_devtype {
129 AT91_DEVTYPE_SAM9263,
130 AT91_DEVTYPE_SAM9X5,
131};
132
133struct at91_devtype_data {
134 unsigned int rx_first;
135 unsigned int rx_split;
136 unsigned int rx_last;
137 unsigned int tx_shift;
138 enum at91_devtype type;
139};
140
159struct at91_priv { 141struct at91_priv {
160 struct can_priv can; /* must be the first member! */ 142 struct can_priv can; /* must be the first member! */
161 struct net_device *dev; 143 struct net_device *dev;
162 struct napi_struct napi; 144 struct napi_struct napi;
163 145
164 void __iomem *reg_base; 146 void __iomem *reg_base;
165 147
166 u32 reg_sr; 148 u32 reg_sr;
167 unsigned int tx_next; 149 unsigned int tx_next;
168 unsigned int tx_echo; 150 unsigned int tx_echo;
169 unsigned int rx_next; 151 unsigned int rx_next;
152 struct at91_devtype_data devtype_data;
170 153
171 struct clk *clk; 154 struct clk *clk;
172 struct at91_can_data *pdata; 155 struct at91_can_data *pdata;
173 156
174 canid_t mb0_id; 157 canid_t mb0_id;
158};
159
160static const struct at91_devtype_data at91_devtype_data[] __devinitconst = {
161 [AT91_DEVTYPE_SAM9263] = {
162 .rx_first = 1,
163 .rx_split = 8,
164 .rx_last = 11,
165 .tx_shift = 2,
166 },
167 [AT91_DEVTYPE_SAM9X5] = {
168 .rx_first = 0,
169 .rx_split = 4,
170 .rx_last = 5,
171 .tx_shift = 1,
172 },
175}; 173};
176 174
177static struct can_bittiming_const at91_bittiming_const = { 175static struct can_bittiming_const at91_bittiming_const = {
@@ -186,19 +184,111 @@ static struct can_bittiming_const at91_bittiming_const = {
186 .brp_inc = 1, 184 .brp_inc = 1,
187}; 185};
188 186
189static inline int get_tx_next_mb(const struct at91_priv *priv) 187#define AT91_IS(_model) \
188static inline int at91_is_sam##_model(const struct at91_priv *priv) \
189{ \
190 return priv->devtype_data.type == AT91_DEVTYPE_SAM##_model; \
191}
192
193AT91_IS(9263);
194AT91_IS(9X5);
195
196static inline unsigned int get_mb_rx_first(const struct at91_priv *priv)
197{
198 return priv->devtype_data.rx_first;
199}
200
201static inline unsigned int get_mb_rx_last(const struct at91_priv *priv)
202{
203 return priv->devtype_data.rx_last;
204}
205
206static inline unsigned int get_mb_rx_split(const struct at91_priv *priv)
207{
208 return priv->devtype_data.rx_split;
209}
210
211static inline unsigned int get_mb_rx_num(const struct at91_priv *priv)
212{
213 return get_mb_rx_last(priv) - get_mb_rx_first(priv) + 1;
214}
215
216static inline unsigned int get_mb_rx_low_last(const struct at91_priv *priv)
217{
218 return get_mb_rx_split(priv) - 1;
219}
220
221static inline unsigned int get_mb_rx_low_mask(const struct at91_priv *priv)
222{
223 return AT91_MB_MASK(get_mb_rx_split(priv)) &
224 ~AT91_MB_MASK(get_mb_rx_first(priv));
225}
226
227static inline unsigned int get_mb_tx_shift(const struct at91_priv *priv)
228{
229 return priv->devtype_data.tx_shift;
230}
231
232static inline unsigned int get_mb_tx_num(const struct at91_priv *priv)
233{
234 return 1 << get_mb_tx_shift(priv);
235}
236
237static inline unsigned int get_mb_tx_first(const struct at91_priv *priv)
238{
239 return get_mb_rx_last(priv) + 1;
240}
241
242static inline unsigned int get_mb_tx_last(const struct at91_priv *priv)
243