aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/can/sja1000
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/can/sja1000')
-rw-r--r--drivers/net/can/sja1000/ems_pci.c36
-rw-r--r--drivers/net/can/sja1000/kvaser_pci.c21
-rw-r--r--drivers/net/can/sja1000/sja1000.c108
-rw-r--r--drivers/net/can/sja1000/sja1000.h9
-rw-r--r--drivers/net/can/sja1000/sja1000_platform.c19
5 files changed, 95 insertions, 98 deletions
diff --git a/drivers/net/can/sja1000/ems_pci.c b/drivers/net/can/sja1000/ems_pci.c
index 88a4649c2ced..121b64101d72 100644
--- a/drivers/net/can/sja1000/ems_pci.c
+++ b/drivers/net/can/sja1000/ems_pci.c
@@ -99,25 +99,21 @@ MODULE_DEVICE_TABLE(pci, ems_pci_tbl);
99 */ 99 */
100static u8 ems_pci_readb(struct ems_pci_card *card, unsigned int port) 100static u8 ems_pci_readb(struct ems_pci_card *card, unsigned int port)
101{ 101{
102 return readb((void __iomem *)card->base_addr 102 return readb(card->base_addr + (port * EMS_PCI_PORT_BYTES));
103 + (port * EMS_PCI_PORT_BYTES));
104} 103}
105 104
106static u8 ems_pci_read_reg(const struct net_device *dev, int port) 105static u8 ems_pci_read_reg(const struct sja1000_priv *priv, int port)
107{ 106{
108 return readb((void __iomem *)dev->base_addr 107 return readb(priv->reg_base + (port * EMS_PCI_PORT_BYTES));
109 + (port * EMS_PCI_PORT_BYTES));
110} 108}
111 109
112static void ems_pci_write_reg(const struct net_device *dev, int port, u8 val) 110static void ems_pci_write_reg(const struct sja1000_priv *priv, int port, u8 val)
113{ 111{
114 writeb(val, (void __iomem *)dev->base_addr 112 writeb(val, priv->reg_base + (port * EMS_PCI_PORT_BYTES));
115 + (port * EMS_PCI_PORT_BYTES));
116} 113}
117 114
118static void ems_pci_post_irq(const struct net_device *dev) 115static void ems_pci_post_irq(const struct sja1000_priv *priv)
119{ 116{
120 struct sja1000_priv *priv = netdev_priv(dev);
121 struct ems_pci_card *card = (struct ems_pci_card *)priv->priv; 117 struct ems_pci_card *card = (struct ems_pci_card *)priv->priv;
122 118
123 /* reset int flag of pita */ 119 /* reset int flag of pita */
@@ -129,17 +125,17 @@ static void ems_pci_post_irq(const struct net_device *dev)
129 * Check if a CAN controller is present at the specified location 125 * Check if a CAN controller is present at the specified location
130 * by trying to set 'em into the PeliCAN mode 126 * by trying to set 'em into the PeliCAN mode
131 */ 127 */
132static inline int ems_pci_check_chan(struct net_device *dev) 128static inline int ems_pci_check_chan(const struct sja1000_priv *priv)
133{ 129{
134 unsigned char res; 130 unsigned char res;
135 131
136 /* Make sure SJA1000 is in reset mode */ 132 /* Make sure SJA1000 is in reset mode */
137 ems_pci_write_reg(dev, REG_MOD, 1); 133 ems_pci_write_reg(priv, REG_MOD, 1);
138 134
139 ems_pci_write_reg(dev, REG_CDR, CDR_PELICAN); 135 ems_pci_write_reg(priv, REG_CDR, CDR_PELICAN);
140 136
141 /* read reset-values */ 137 /* read reset-values */
142 res = ems_pci_read_reg(dev, REG_CDR); 138 res = ems_pci_read_reg(priv, REG_CDR);
143 139
144 if (res == CDR_PELICAN) 140 if (res == CDR_PELICAN)
145 return 1; 141 return 1;
@@ -257,12 +253,11 @@ static int __devinit ems_pci_add_card(struct pci_dev *pdev,
257 priv->irq_flags = IRQF_SHARED; 253 priv->irq_flags = IRQF_SHARED;
258 254
259 dev->irq = pdev->irq; 255 dev->irq = pdev->irq;
260 dev->base_addr = (unsigned long)(card->base_addr 256 priv->reg_base = card->base_addr + EMS_PCI_CAN_BASE_OFFSET
261 + EMS_PCI_CAN_BASE_OFFSET 257 + (i * EMS_PCI_CAN_CTRL_SIZE);
262 + (i * EMS_PCI_CAN_CTRL_SIZE));
263 258
264 /* Check if channel is present */ 259 /* Check if channel is present */
265 if (ems_pci_check_chan(dev)) { 260 if (ems_pci_check_chan(priv)) {
266 priv->read_reg = ems_pci_read_reg; 261 priv->read_reg = ems_pci_read_reg;
267 priv->write_reg = ems_pci_write_reg; 262 priv->write_reg = ems_pci_write_reg;
268 priv->post_irq = ems_pci_post_irq; 263 priv->post_irq = ems_pci_post_irq;
@@ -286,9 +281,8 @@ static int __devinit ems_pci_add_card(struct pci_dev *pdev,
286 281
287 card->channels++; 282 card->channels++;
288 283
289 dev_info(&pdev->dev, "Channel #%d at %#lX, irq %d\n", 284 dev_info(&pdev->dev, "Channel #%d at 0x%p, irq %d\n",
290 i + 1, dev->base_addr, 285 i + 1, priv->reg_base, dev->irq);
291 dev->irq);
292 } else { 286 } else {
293 free_sja1000dev(dev); 287 free_sja1000dev(dev);
294 } 288 }
diff --git a/drivers/net/can/sja1000/kvaser_pci.c b/drivers/net/can/sja1000/kvaser_pci.c
index 00830b358c4f..7dd7769b9713 100644
--- a/drivers/net/can/sja1000/kvaser_pci.c
+++ b/drivers/net/can/sja1000/kvaser_pci.c
@@ -117,14 +117,15 @@ static struct pci_device_id kvaser_pci_tbl[] = {
117 117
118MODULE_DEVICE_TABLE(pci, kvaser_pci_tbl); 118MODULE_DEVICE_TABLE(pci, kvaser_pci_tbl);
119 119
120static u8 kvaser_pci_read_reg(const struct net_device *dev, int port) 120static u8 kvaser_pci_read_reg(const struct sja1000_priv *priv, int port)
121{ 121{
122 return ioread8((void __iomem *)(dev->base_addr + port)); 122 return ioread8(priv->reg_base + port);
123} 123}
124 124
125static void kvaser_pci_write_reg(const struct net_device *dev, int port, u8 val) 125static void kvaser_pci_write_reg(const struct sja1000_priv *priv,
126 int port, u8 val)
126{ 127{
127 iowrite8(val, (void __iomem *)(dev->base_addr + port)); 128 iowrite8(val, priv->reg_base + port);
128} 129}
129 130
130static void kvaser_pci_disable_irq(struct net_device *dev) 131static void kvaser_pci_disable_irq(struct net_device *dev)
@@ -199,7 +200,7 @@ static void kvaser_pci_del_chan(struct net_device *dev)
199 } 200 }
200 unregister_sja1000dev(dev); 201 unregister_sja1000dev(dev);
201 202
202 pci_iounmap(board->pci_dev, (void __iomem *)dev->base_addr); 203 pci_iounmap(board->pci_dev, priv->reg_base);
203 pci_iounmap(board->pci_dev, board->conf_addr); 204 pci_iounmap(board->pci_dev, board->conf_addr);
204 pci_iounmap(board->pci_dev, board->res_addr); 205 pci_iounmap(board->pci_dev, board->res_addr);
205 206
@@ -210,7 +211,7 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
210 struct net_device **master_dev, 211 struct net_device **master_dev,
211 void __iomem *conf_addr, 212 void __iomem *conf_addr,
212 void __iomem *res_addr, 213 void __iomem *res_addr,
213 unsigned long base_addr) 214 void __iomem *base_addr)
214{ 215{
215 struct net_device *dev; 216 struct net_device *dev;
216 struct sja1000_priv *priv; 217 struct sja1000_priv *priv;
@@ -252,7 +253,7 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
252 board->xilinx_ver = master_board->xilinx_ver; 253 board->xilinx_ver = master_board->xilinx_ver;
253 } 254 }
254 255
255 dev->base_addr = base_addr + channel * KVASER_PCI_PORT_BYTES; 256 priv->reg_base = base_addr + channel * KVASER_PCI_PORT_BYTES;
256 257
257 priv->read_reg = kvaser_pci_read_reg; 258 priv->read_reg = kvaser_pci_read_reg;
258 priv->write_reg = kvaser_pci_write_reg; 259 priv->write_reg = kvaser_pci_write_reg;
@@ -267,8 +268,8 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
267 268
268 init_step = 4; 269 init_step = 4;
269 270
270 dev_info(&pdev->dev, "base_addr=%#lx conf_addr=%p irq=%d\n", 271 dev_info(&pdev->dev, "reg_base=%p conf_addr=%p irq=%d\n",
271 dev->base_addr, board->conf_addr, dev->irq); 272 priv->reg_base, board->conf_addr, dev->irq);
272 273
273 SET_NETDEV_DEV(dev, &pdev->dev); 274 SET_NETDEV_DEV(dev, &pdev->dev);
274 275
@@ -343,7 +344,7 @@ static int __devinit kvaser_pci_init_one(struct pci_dev *pdev,
343 for (i = 0; i < no_channels; i++) { 344 for (i = 0; i < no_channels; i++) {
344 err = kvaser_pci_add_chan(pdev, i, &master_dev, 345 err = kvaser_pci_add_chan(pdev, i, &master_dev,
345 conf_addr, res_addr, 346 conf_addr, res_addr,
346 (unsigned long)base_addr); 347 base_addr);
347 if (err) 348 if (err)
348 goto failure_cleanup; 349 goto failure_cleanup;
349 } 350 }
diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index b689964f182c..571f133a8fec 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -89,7 +89,7 @@ static int sja1000_probe_chip(struct net_device *dev)
89{ 89{
90 struct sja1000_priv *priv = netdev_priv(dev); 90 struct sja1000_priv *priv = netdev_priv(dev);
91 91
92 if (dev->base_addr && (priv->read_reg(dev, 0) == 0xFF)) { 92 if (priv->reg_base && (priv->read_reg(priv, 0) == 0xFF)) {
93 printk(KERN_INFO "%s: probing @0x%lX failed\n", 93 printk(KERN_INFO "%s: probing @0x%lX failed\n",
94 DRV_NAME, dev->base_addr); 94 DRV_NAME, dev->base_addr);
95 return 0; 95 return 0;
@@ -100,11 +100,11 @@ static int sja1000_probe_chip(struct net_device *dev)
100static void set_reset_mode(struct net_device *dev) 100static void set_reset_mode(struct net_device *dev)
101{ 101{
102 struct sja1000_priv *priv = netdev_priv(dev); 102 struct sja1000_priv *priv = netdev_priv(dev);
103 unsigned char status = priv->read_reg(dev, REG_MOD); 103 unsigned char status = priv->read_reg(priv, REG_MOD);
104 int i; 104 int i;
105 105
106 /* disable interrupts */ 106 /* disable interrupts */
107 priv->write_reg(dev, REG_IER, IRQ_OFF); 107 priv->write_reg(priv, REG_IER, IRQ_OFF);
108 108
109 for (i = 0; i < 100; i++) { 109 for (i = 0; i < 100; i++) {
110 /* check reset bit */ 110 /* check reset bit */
@@ -113,9 +113,9 @@ static void set_reset_mode(struct net_device *dev)
113 return; 113 return;
114 } 114 }
115 115
116 priv->write_reg(dev, REG_MOD, MOD_RM); /* reset chip */ 116 priv->write_reg(priv, REG_MOD, MOD_RM); /* reset chip */
117 udelay(10); 117 udelay(10);
118 status = priv->read_reg(dev, REG_MOD); 118 status = priv->read_reg(priv, REG_MOD);
119 } 119 }
120 120
121 dev_err(dev->dev.parent, "setting SJA1000 into reset mode failed!\n"); 121 dev_err(dev->dev.parent, "setting SJA1000 into reset mode failed!\n");
@@ -124,7 +124,7 @@ static void set_reset_mode(struct net_device *dev)
124static void set_normal_mode(struct net_device *dev) 124static void set_normal_mode(struct net_device *dev)
125{ 125{
126 struct sja1000_priv *priv = netdev_priv(dev); 126 struct sja1000_priv *priv = netdev_priv(dev);
127 unsigned char status = priv->read_reg(dev, REG_MOD); 127 unsigned char status = priv->read_reg(priv, REG_MOD);
128 int i; 128 int i;
129 129
130 for (i = 0; i < 100; i++) { 130 for (i = 0; i < 100; i++) {
@@ -132,14 +132,14 @@ static void set_normal_mode(struct net_device *dev)
132 if ((status & MOD_RM) == 0) { 132 if ((status & MOD_RM) == 0) {
133 priv->can.state = CAN_STATE_ERROR_ACTIVE; 133 priv->can.state = CAN_STATE_ERROR_ACTIVE;
134 /* enable all interrupts */ 134 /* enable all interrupts */
135 priv->write_reg(dev, REG_IER, IRQ_ALL); 135 priv->write_reg(priv, REG_IER, IRQ_ALL);
136 return; 136 return;
137 } 137 }
138 138
139 /* set chip to normal mode */ 139 /* set chip to normal mode */
140 priv->write_reg(dev, REG_MOD, 0x00); 140 priv->write_reg(priv, REG_MOD, 0x00);
141 udelay(10); 141 udelay(10);
142 status = priv->read_reg(dev, REG_MOD); 142 status = priv->read_reg(priv, REG_MOD);
143 } 143 }
144 144
145 dev_err(dev->dev.parent, "setting SJA1000 into normal mode failed!\n"); 145 dev_err(dev->dev.parent, "setting SJA1000 into normal mode failed!\n");
@@ -154,9 +154,9 @@ static void sja1000_start(struct net_device *dev)
154 set_reset_mode(dev); 154 set_reset_mode(dev);
155 155
156 /* Clear error counters and error code capture */ 156 /* Clear error counters and error code capture */
157 priv->write_reg(dev, REG_TXERR, 0x0); 157 priv->write_reg(priv, REG_TXERR, 0x0);
158 priv->write_reg(dev, REG_RXERR, 0x0); 158 priv->write_reg(priv, REG_RXERR, 0x0);
159 priv->read_reg(dev, REG_ECC); 159 priv->read_reg(priv, REG_ECC);
160 160
161 /* leave reset mode */ 161 /* leave reset mode */
162 set_normal_mode(dev); 162 set_normal_mode(dev);
@@ -198,8 +198,8 @@ static int sja1000_set_bittiming(struct net_device *dev)
198 dev_info(dev->dev.parent, 198 dev_info(dev->dev.parent,
199 "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1); 199 "setting BTR0=0x%02x BTR1=0x%02x\n", btr0, btr1);
200 200
201 priv->write_reg(dev, REG_BTR0, btr0); 201 priv->write_reg(priv, REG_BTR0, btr0);
202 priv->write_reg(dev, REG_BTR1, btr1); 202 priv->write_reg(priv, REG_BTR1, btr1);
203 203
204 return 0; 204 return 0;
205} 205}
@@ -217,20 +217,20 @@ static void chipset_init(struct net_device *dev)
217 struct sja1000_priv *priv = netdev_priv(dev); 217 struct sja1000_priv *priv = netdev_priv(dev);
218 218
219 /* set clock divider and output control register */ 219 /* set clock divider and output control register */
220 priv->write_reg(dev, REG_CDR, priv->cdr | CDR_PELICAN); 220 priv->write_reg(priv, REG_CDR, priv->cdr | CDR_PELICAN);
221 221
222 /* set acceptance filter (accept all) */ 222 /* set acceptance filter (accept all) */
223 priv->write_reg(dev, REG_ACCC0, 0x00); 223 priv->write_reg(priv, REG_ACCC0, 0x00);
224 priv->write_reg(dev, REG_ACCC1, 0x00); 224 priv->write_reg(priv, REG_ACCC1, 0x00);
225 priv->write_reg(dev, REG_ACCC2, 0x00); 225 priv->write_reg(priv, REG_ACCC2, 0x00);
226 priv->write_reg(dev, REG_ACCC3, 0x00); 226 priv->write_reg(priv, REG_ACCC3, 0x00);
227 227
228 priv->write_reg(dev, REG_ACCM0, 0xFF); 228 priv->write_reg(priv, REG_ACCM0, 0xFF);
229 priv->write_reg(dev, REG_ACCM1, 0xFF); 229 priv->write_reg(priv, REG_ACCM1, 0xFF);
230 priv->write_reg(dev, REG_ACCM2, 0xFF); 230 priv->write_reg(priv, REG_ACCM2, 0xFF);
231 priv->write_reg(dev, REG_ACCM3, 0xFF); 231 priv->write_reg(priv, REG_ACCM3, 0xFF);
232 232
233 priv->write_reg(dev, REG_OCR, priv->ocr | OCR_MODE_NORMAL); 233 priv->write_reg(priv, REG_OCR, priv->ocr | OCR_MODE_NORMAL);
234} 234}
235 235
236/* 236/*
@@ -261,27 +261,27 @@ static int sja1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
261 if (id & CAN_EFF_FLAG) { 261 if (id & CAN_EFF_FLAG) {
262 fi |= FI_FF; 262 fi |= FI_FF;
263 dreg = EFF_BUF; 263 dreg = EFF_BUF;
264 priv->write_reg(dev, REG_FI, fi); 264 priv->write_reg(priv, REG_FI, fi);
265 priv->write_reg(dev, REG_ID1, (id & 0x1fe00000) >> (5 + 16)); 265 priv->write_reg(priv, REG_ID1, (id & 0x1fe00000) >> (5 + 16));
266 priv->write_reg(dev, REG_ID2, (id & 0x001fe000) >> (5 + 8)); 266 priv->write_reg(priv, REG_ID2, (id & 0x001fe000) >> (5 + 8));
267 priv->write_reg(dev, REG_ID3, (id & 0x00001fe0) >> 5); 267 priv->write_reg(priv, REG_ID3, (id & 0x00001fe0) >> 5);
268 priv->write_reg(dev, REG_ID4, (id & 0x0000001f) << 3); 268 priv->write_reg(priv, REG_ID4, (id & 0x0000001f) << 3);
269 } else { 269 } else {
270 dreg = SFF_BUF; 270 dreg = SFF_BUF;
271 priv->write_reg(dev, REG_FI, fi); 271 priv->write_reg(priv, REG_FI, fi);
272 priv->write_reg(dev, REG_ID1, (id & 0x000007f8) >> 3); 272 priv->write_reg(priv, REG_ID1, (id & 0x000007f8) >> 3);
273 priv->write_reg(dev, REG_ID2, (id & 0x00000007) << 5); 273 priv->write_reg(priv, REG_ID2, (id & 0x00000007) << 5);
274 } 274 }
275 275
276 for (i = 0; i < dlc; i++) 276 for (i = 0; i < dlc; i++)
277 priv->write_reg(dev, dreg++, cf->data[i]); 277 priv->write_reg(priv, dreg++, cf->data[i]);
278 278
279 stats->tx_bytes += dlc; 279 stats->tx_bytes += dlc;
280 dev->trans_start = jiffies; 280 dev->trans_start = jiffies;
281 281
282 can_put_echo_skb(skb, dev, 0); 282 can_put_echo_skb(skb, dev, 0);
283 283
284 priv->write_reg(dev, REG_CMR, CMD_TR); 284 priv->write_reg(priv, REG_CMR, CMD_TR);
285 285
286 return 0; 286 return 0;
287} 287}
@@ -304,22 +304,22 @@ static void sja1000_rx(struct net_device *dev)
304 skb->dev = dev; 304 skb->dev = dev;
305 skb->protocol = htons(ETH_P_CAN); 305 skb->protocol = htons(ETH_P_CAN);
306 306
307 fi = priv->read_reg(dev, REG_FI); 307 fi = priv->read_reg(priv, REG_FI);
308 dlc = fi & 0x0F; 308 dlc = fi & 0x0F;
309 309
310 if (fi & FI_FF) { 310 if (fi & FI_FF) {
311 /* extended frame format (EFF) */ 311 /* extended frame format (EFF) */
312 dreg = EFF_BUF; 312 dreg = EFF_BUF;
313 id = (priv->read_reg(dev, REG_ID1) << (5 + 16)) 313 id = (priv->read_reg(priv, REG_ID1) << (5 + 16))
314 | (priv->read_reg(dev, REG_ID2) << (5 + 8)) 314 | (priv->read_reg(priv, REG_ID2) << (5 + 8))
315 | (priv->read_reg(dev, REG_ID3) << 5) 315 | (priv->read_reg(priv, REG_ID3) << 5)
316 | (priv->read_reg(dev, REG_ID4) >> 3); 316 | (priv->read_reg(priv, REG_ID4) >> 3);
317 id |= CAN_EFF_FLAG; 317 id |= CAN_EFF_FLAG;
318 } else { 318 } else {
319 /* standard frame format (SFF) */ 319 /* standard frame format (SFF) */
320 dreg = SFF_BUF; 320 dreg = SFF_BUF;
321 id = (priv->read_reg(dev, REG_ID1) << 3) 321 id = (priv->read_reg(priv, REG_ID1) << 3)
322 | (priv->read_reg(dev, REG_ID2) >> 5); 322 | (priv->read_reg(priv, REG_ID2) >> 5);
323 } 323 }
324 324
325 if (fi & FI_RTR) 325 if (fi & FI_RTR)
@@ -330,13 +330,13 @@ static void sja1000_rx(struct net_device *dev)
330 cf->can_id = id; 330 cf->can_id = id;
331 cf->can_dlc = dlc; 331 cf->can_dlc = dlc;
332 for (i = 0; i < dlc; i++) 332 for (i = 0; i < dlc; i++)
333 cf->data[i] = priv->read_reg(dev, dreg++); 333 cf->data[i] = priv->read_reg(priv, dreg++);
334 334
335 while (i < 8) 335 while (i < 8)
336 cf->data[i++] = 0; 336 cf->data[i++] = 0;
337 337
338 /* release receive buffer */ 338 /* release receive buffer */
339 priv->write_reg(dev, REG_CMR, CMD_RRB); 339 priv->write_reg(priv, REG_CMR, CMD_RRB);
340 340
341 netif_rx(skb); 341 netif_rx(skb);
342 342
@@ -371,7 +371,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
371 cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; 371 cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
372 stats->rx_over_errors++; 372 stats->rx_over_errors++;
373 stats->rx_errors++; 373 stats->rx_errors++;
374 priv->write_reg(dev, REG_CMR, CMD_CDO); /* clear bit */ 374 priv->write_reg(priv, REG_CMR, CMD_CDO); /* clear bit */
375 } 375 }
376 376
377 if (isrc & IRQ_EI) { 377 if (isrc & IRQ_EI) {
@@ -392,7 +392,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
392 priv->can.can_stats.bus_error++; 392 priv->can.can_stats.bus_error++;
393 stats->rx_errors++; 393 stats->rx_errors++;
394 394
395 ecc = priv->read_reg(dev, REG_ECC); 395 ecc = priv->read_reg(priv, REG_ECC);
396 396
397 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; 397 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
398 398
@@ -426,7 +426,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
426 if (isrc & IRQ_ALI) { 426 if (isrc & IRQ_ALI) {
427 /* arbitration lost interrupt */ 427 /* arbitration lost interrupt */
428 dev_dbg(dev->dev.parent, "arbitration lost interrupt\n"); 428 dev_dbg(dev->dev.parent, "arbitration lost interrupt\n");
429 alc = priv->read_reg(dev, REG_ALC); 429 alc = priv->read_reg(priv, REG_ALC);
430 priv->can.can_stats.arbitration_lost++; 430 priv->can.can_stats.arbitration_lost++;
431 stats->rx_errors++; 431 stats->rx_errors++;
432 cf->can_id |= CAN_ERR_LOSTARB; 432 cf->can_id |= CAN_ERR_LOSTARB;
@@ -435,8 +435,8 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
435 435
436 if (state != priv->can.state && (state == CAN_STATE_ERROR_WARNING || 436 if (state != priv->can.state && (state == CAN_STATE_ERROR_WARNING ||
437 state == CAN_STATE_ERROR_PASSIVE)) { 437 state == CAN_STATE_ERROR_PASSIVE)) {
438 uint8_t rxerr = priv->read_reg(dev, REG_RXERR); 438 uint8_t rxerr = priv->read_reg(priv, REG_RXERR);
439 uint8_t txerr = priv->read_reg(dev, REG_TXERR); 439 uint8_t txerr = priv->read_reg(priv, REG_TXERR);
440 cf->can_id |= CAN_ERR_CRTL; 440 cf->can_id |= CAN_ERR_CRTL;
441 if (state == CAN_STATE_ERROR_WARNING) { 441 if (state == CAN_STATE_ERROR_WARNING) {
442 priv->can.can_stats.error_warning++; 442 priv->can.can_stats.error_warning++;
@@ -471,15 +471,15 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
471 int n = 0; 471 int n = 0;
472 472
473 /* Shared interrupts and IRQ off? */ 473 /* Shared interrupts and IRQ off? */
474 if (priv->read_reg(dev, REG_IER) == IRQ_OFF) 474 if (priv->read_reg(priv, REG_IER) == IRQ_OFF)
475 return IRQ_NONE; 475 return IRQ_NONE;
476 476
477 if (priv->pre_irq) 477 if (priv->pre_irq)
478 priv->pre_irq(dev); 478 priv->pre_irq(priv);
479 479
480 while ((isrc = priv->read_reg(dev, REG_IR)) && (n < SJA1000_MAX_IRQ)) { 480 while ((isrc = priv->read_reg(priv, REG_IR)) && (n < SJA1000_MAX_IRQ)) {
481 n++; 481 n++;
482 status = priv->read_reg(dev, REG_SR); 482 status = priv->read_reg(priv, REG_SR);
483 483
484 if (isrc & IRQ_WUI) 484 if (isrc & IRQ_WUI)
485 dev_warn(dev->dev.parent, "wakeup interrupt\n"); 485 dev_warn(dev->dev.parent, "wakeup interrupt\n");
@@ -494,7 +494,7 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
494 /* receive interrupt */ 494 /* receive interrupt */
495 while (status & SR_RBS) { 495 while (status & SR_RBS) {
496 sja1000_rx(dev); 496 sja1000_rx(dev);
497 status = priv->read_reg(dev, REG_SR); 497 status = priv->read_reg(priv, REG_SR);
498 } 498 }
499 } 499 }
500 if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) { 500 if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) {
@@ -505,7 +505,7 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
505 } 505 }
506 506
507 if (priv->post_irq) 507 if (priv->post_irq)
508 priv->post_irq(dev); 508 priv->post_irq(priv);
509 509
510 if (n >= SJA1000_MAX_IRQ) 510 if (n >= SJA1000_MAX_IRQ)
511 dev_dbg(dev->dev.parent, "%d messages handled in ISR", n); 511 dev_dbg(dev->dev.parent, "%d messages handled in ISR", n);
diff --git a/drivers/net/can/sja1000/sja1000.h b/drivers/net/can/sja1000/sja1000.h
index ccd302887964..302d2c763ad7 100644
--- a/drivers/net/can/sja1000/sja1000.h
+++ b/drivers/net/can/sja1000/sja1000.h
@@ -155,14 +155,15 @@ struct sja1000_priv {
155 struct sk_buff *echo_skb; 155 struct sk_buff *echo_skb;
156 156
157 /* the lower-layer is responsible for appropriate locking */ 157 /* the lower-layer is responsible for appropriate locking */
158 u8 (*read_reg) (const struct net_device *dev, int reg); 158 u8 (*read_reg) (const struct sja1000_priv *priv, int reg);
159 void (*write_reg) (const struct net_device *dev, int reg, u8 val); 159 void (*write_reg) (const struct sja1000_priv *priv, int reg, u8 val);
160 void (*pre_irq) (const struct net_device *dev); 160 void (*pre_irq) (const struct sja1000_priv *priv);
161 void (*post_irq) (const struct net_device *dev); 161 void (*post_irq) (const struct sja1000_priv *priv);
162 162
163 void *priv; /* for board-specific data */ 163 void *priv; /* for board-specific data */
164 struct net_device *dev; 164 struct net_device *dev;
165 165
166 void __iomem *reg_base; /* ioremap'ed address to registers */
166 unsigned long irq_flags; /* for request_irq() */ 167 unsigned long irq_flags; /* for request_irq() */
167 168
168 u16 flags; /* custom mode flags */ 169 u16 flags; /* custom mode flags */
diff --git a/drivers/net/can/sja1000/sja1000_platform.c b/drivers/net/can/sja1000/sja1000_platform.c
index 8017229d6fd6..628374c2a05f 100644
--- a/drivers/net/can/sja1000/sja1000_platform.c
+++ b/drivers/net/can/sja1000/sja1000_platform.c
@@ -37,14 +37,14 @@ MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
37MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the platform bus"); 37MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the platform bus");
38MODULE_LICENSE("GPL v2"); 38MODULE_LICENSE("GPL v2");
39 39
40static u8 sp_read_reg(const struct net_device *dev, int reg) 40static u8 sp_read_reg(const struct sja1000_priv *priv, int reg)
41{ 41{
42 return ioread8((void __iomem *)(dev->base_addr + reg)); 42 return ioread8(priv->reg_base + reg);
43} 43}
44 44
45static void sp_write_reg(const struct net_device *dev, int reg, u8 val) 45static void sp_write_reg(const struct sja1000_priv *priv, int reg, u8 val)
46{ 46{
47 iowrite8(val, (void __iomem *)(dev->base_addr + reg)); 47 iowrite8(val, priv->reg_base + reg);
48} 48}
49 49
50static int sp_probe(struct platform_device *pdev) 50static int sp_probe(struct platform_device *pdev)
@@ -89,9 +89,9 @@ static int sp_probe(struct platform_device *pdev)
89 } 89 }
90 priv = netdev_priv(dev); 90 priv = netdev_priv(dev);
91 91
92 dev->base_addr = (unsigned long)addr;
93 dev->irq = res_irq->start; 92 dev->irq = res_irq->start;
94 priv->irq_flags = res_irq->flags & IRQF_TRIGGER_MASK; 93 priv->irq_flags = res_irq->flags & IRQF_TRIGGER_MASK;
94 priv->reg_base = addr;
95 priv->read_reg = sp_read_reg; 95 priv->read_reg = sp_read_reg;
96 priv->write_reg = sp_write_reg; 96 priv->write_reg = sp_write_reg;
97 priv->can.clock.freq = pdata->clock; 97 priv->can.clock.freq = pdata->clock;
@@ -108,8 +108,8 @@ static int sp_probe(struct platform_device *pdev)
108 goto exit_free; 108 goto exit_free;
109 } 109 }
110 110
111 dev_info(&pdev->dev, "%s device registered (base_addr=%#lx, irq=%d)\n", 111 dev_info(&pdev->dev, "%s device registered (reg_base=%p, irq=%d)\n",
112 DRV_NAME, dev->base_addr, dev->irq); 112 DRV_NAME, priv->reg_base, dev->irq);
113 return 0; 113 return 0;
114 114
115 exit_free: 115 exit_free:
@@ -125,13 +125,14 @@ static int sp_probe(struct platform_device *pdev)
125static int sp_remove(struct platform_device *pdev) 125static int sp_remove(struct platform_device *pdev)
126{ 126{
127 struct net_device *dev = dev_get_drvdata(&pdev->dev); 127 struct net_device *dev = dev_get_drvdata(&pdev->dev);
128 struct sja1000_priv *priv = netdev_priv(dev);
128 struct resource *res; 129 struct resource *res;
129 130
130 unregister_sja1000dev(dev); 131 unregister_sja1000dev(dev);
131 dev_set_drvdata(&pdev->dev, NULL); 132 dev_set_drvdata(&pdev->dev, NULL);
132 133
133 if (dev->base_addr) 134 if (priv->reg_base)
134 iounmap((void __iomem *)dev->base_addr); 135 iounmap(priv->reg_base);
135 136
136 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 137 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
137 release_mem_region(res->start, resource_size(res)); 138 release_mem_region(res->start, resource_size(res));