diff options
Diffstat (limited to 'drivers/net/can')
-rw-r--r-- | drivers/net/can/Kconfig | 9 | ||||
-rw-r--r-- | drivers/net/can/dev.c | 2 | ||||
-rw-r--r-- | drivers/net/can/sja1000/Makefile | 1 | ||||
-rw-r--r-- | drivers/net/can/sja1000/ems_pci.c | 39 | ||||
-rw-r--r-- | drivers/net/can/sja1000/kvaser_pci.c | 21 | ||||
-rw-r--r-- | drivers/net/can/sja1000/sja1000.c | 110 | ||||
-rw-r--r-- | drivers/net/can/sja1000/sja1000.h | 9 | ||||
-rw-r--r-- | drivers/net/can/sja1000/sja1000_of_platform.c | 235 | ||||
-rw-r--r-- | drivers/net/can/sja1000/sja1000_platform.c | 19 |
9 files changed, 342 insertions, 103 deletions
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index cfd6c5a285fa..d5e18812bf49 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig | |||
@@ -51,6 +51,15 @@ config CAN_SJA1000_PLATFORM | |||
51 | boards from Phytec (http://www.phytec.de) like the PCM027, | 51 | boards from Phytec (http://www.phytec.de) like the PCM027, |
52 | PCM038. | 52 | PCM038. |
53 | 53 | ||
54 | config CAN_SJA1000_OF_PLATFORM | ||
55 | depends on CAN_SJA1000 && PPC_OF | ||
56 | tristate "Generic OF Platform Bus based SJA1000 driver" | ||
57 | ---help--- | ||
58 | This driver adds support for the SJA1000 chips connected to | ||
59 | the OpenFirmware "platform bus" found on embedded systems with | ||
60 | OpenFirmware bindings, e.g. if you have a PowerPC based system | ||
61 | you may want to enable this option. | ||
62 | |||
54 | config CAN_EMS_PCI | 63 | config CAN_EMS_PCI |
55 | tristate "EMS CPC-PCI and CPC-PCIe Card" | 64 | tristate "EMS CPC-PCI and CPC-PCIe Card" |
56 | depends on PCI && CAN_SJA1000 | 65 | depends on PCI && CAN_SJA1000 |
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c index 52b0e7d8901d..574daddc21bf 100644 --- a/drivers/net/can/dev.c +++ b/drivers/net/can/dev.c | |||
@@ -477,7 +477,7 @@ int open_candev(struct net_device *dev) | |||
477 | 477 | ||
478 | return 0; | 478 | return 0; |
479 | } | 479 | } |
480 | EXPORT_SYMBOL(open_candev); | 480 | EXPORT_SYMBOL_GPL(open_candev); |
481 | 481 | ||
482 | /* | 482 | /* |
483 | * Common close function for cleanup before the device gets closed. | 483 | * Common close function for cleanup before the device gets closed. |
diff --git a/drivers/net/can/sja1000/Makefile b/drivers/net/can/sja1000/Makefile index d6c631f9e665..9d0c08da273c 100644 --- a/drivers/net/can/sja1000/Makefile +++ b/drivers/net/can/sja1000/Makefile | |||
@@ -4,6 +4,7 @@ | |||
4 | 4 | ||
5 | obj-$(CONFIG_CAN_SJA1000) += sja1000.o | 5 | obj-$(CONFIG_CAN_SJA1000) += sja1000.o |
6 | obj-$(CONFIG_CAN_SJA1000_PLATFORM) += sja1000_platform.o | 6 | obj-$(CONFIG_CAN_SJA1000_PLATFORM) += sja1000_platform.o |
7 | obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o | ||
7 | obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o | 8 | obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o |
8 | obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o | 9 | obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o |
9 | 10 | ||
diff --git a/drivers/net/can/sja1000/ems_pci.c b/drivers/net/can/sja1000/ems_pci.c index 3cd2ff9165e3..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 | */ |
100 | static u8 ems_pci_readb(struct ems_pci_card *card, unsigned int port) | 100 | static 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 | ||
106 | static u8 ems_pci_read_reg(const struct net_device *dev, int port) | 105 | static 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 | ||
112 | static void ems_pci_write_reg(const struct net_device *dev, int port, u8 val) | 110 | static 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 | ||
118 | static void ems_pci_post_irq(const struct net_device *dev) | 115 | static 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 | */ |
132 | static inline int ems_pci_check_chan(struct net_device *dev) | 128 | static 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; |
@@ -218,14 +214,12 @@ static int __devinit ems_pci_add_card(struct pci_dev *pdev, | |||
218 | card->conf_addr = pci_iomap(pdev, 0, EMS_PCI_MEM_SIZE); | 214 | card->conf_addr = pci_iomap(pdev, 0, EMS_PCI_MEM_SIZE); |
219 | if (card->conf_addr == NULL) { | 215 | if (card->conf_addr == NULL) { |
220 | err = -ENOMEM; | 216 | err = -ENOMEM; |
221 | |||
222 | goto failure_cleanup; | 217 | goto failure_cleanup; |
223 | } | 218 | } |
224 | 219 | ||
225 | card->base_addr = pci_iomap(pdev, 1, EMS_PCI_MEM_SIZE); | 220 | card->base_addr = pci_iomap(pdev, 1, EMS_PCI_MEM_SIZE); |
226 | if (card->base_addr == NULL) { | 221 | if (card->base_addr == NULL) { |
227 | err = -ENOMEM; | 222 | err = -ENOMEM; |
228 | |||
229 | goto failure_cleanup; | 223 | goto failure_cleanup; |
230 | } | 224 | } |
231 | 225 | ||
@@ -239,7 +233,6 @@ static int __devinit ems_pci_add_card(struct pci_dev *pdev, | |||
239 | ems_pci_readb(card, 3) != 0xCB || | 233 | ems_pci_readb(card, 3) != 0xCB || |
240 | ems_pci_readb(card, 4) != 0x11) { | 234 | ems_pci_readb(card, 4) != 0x11) { |
241 | dev_err(&pdev->dev, "Not EMS Dr. Thomas Wuensche interface\n"); | 235 | dev_err(&pdev->dev, "Not EMS Dr. Thomas Wuensche interface\n"); |
242 | |||
243 | err = -ENODEV; | 236 | err = -ENODEV; |
244 | goto failure_cleanup; | 237 | goto failure_cleanup; |
245 | } | 238 | } |
@@ -260,12 +253,11 @@ static int __devinit ems_pci_add_card(struct pci_dev *pdev, | |||
260 | priv->irq_flags = IRQF_SHARED; | 253 | priv->irq_flags = IRQF_SHARED; |
261 | 254 | ||
262 | dev->irq = pdev->irq; | 255 | dev->irq = pdev->irq; |
263 | dev->base_addr = (unsigned long)(card->base_addr | 256 | priv->reg_base = card->base_addr + EMS_PCI_CAN_BASE_OFFSET |
264 | + EMS_PCI_CAN_BASE_OFFSET | 257 | + (i * EMS_PCI_CAN_CTRL_SIZE); |
265 | + (i * EMS_PCI_CAN_CTRL_SIZE)); | ||
266 | 258 | ||
267 | /* Check if channel is present */ | 259 | /* Check if channel is present */ |
268 | if (ems_pci_check_chan(dev)) { | 260 | if (ems_pci_check_chan(priv)) { |
269 | priv->read_reg = ems_pci_read_reg; | 261 | priv->read_reg = ems_pci_read_reg; |
270 | priv->write_reg = ems_pci_write_reg; | 262 | priv->write_reg = ems_pci_write_reg; |
271 | priv->post_irq = ems_pci_post_irq; | 263 | priv->post_irq = ems_pci_post_irq; |
@@ -289,9 +281,8 @@ static int __devinit ems_pci_add_card(struct pci_dev *pdev, | |||
289 | 281 | ||
290 | card->channels++; | 282 | card->channels++; |
291 | 283 | ||
292 | dev_info(&pdev->dev, "Channel #%d at %#lX, irq %d\n", | 284 | dev_info(&pdev->dev, "Channel #%d at 0x%p, irq %d\n", |
293 | i + 1, dev->base_addr, | 285 | i + 1, priv->reg_base, dev->irq); |
294 | dev->irq); | ||
295 | } else { | 286 | } else { |
296 | free_sja1000dev(dev); | 287 | free_sja1000dev(dev); |
297 | } | 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 | ||
118 | MODULE_DEVICE_TABLE(pci, kvaser_pci_tbl); | 118 | MODULE_DEVICE_TABLE(pci, kvaser_pci_tbl); |
119 | 119 | ||
120 | static u8 kvaser_pci_read_reg(const struct net_device *dev, int port) | 120 | static 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 | ||
125 | static void kvaser_pci_write_reg(const struct net_device *dev, int port, u8 val) | 125 | static 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 | ||
130 | static void kvaser_pci_disable_irq(struct net_device *dev) | 131 | static 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 05b38dde648e..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) | |||
100 | static void set_reset_mode(struct net_device *dev) | 100 | static 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) | |||
124 | static void set_normal_mode(struct net_device *dev) | 124 | static 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); |
@@ -532,8 +532,8 @@ static int sja1000_open(struct net_device *dev) | |||
532 | err = request_irq(dev->irq, &sja1000_interrupt, priv->irq_flags, | 532 | err = request_irq(dev->irq, &sja1000_interrupt, priv->irq_flags, |
533 | dev->name, (void *)dev); | 533 | dev->name, (void *)dev); |
534 | if (err) { | 534 | if (err) { |
535 | return -EAGAIN; | ||
536 | close_candev(dev); | 535 | close_candev(dev); |
536 | return -EAGAIN; | ||
537 | } | 537 | } |
538 | } | 538 | } |
539 | 539 | ||
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_of_platform.c b/drivers/net/can/sja1000/sja1000_of_platform.c new file mode 100644 index 000000000000..3373560405ba --- /dev/null +++ b/drivers/net/can/sja1000/sja1000_of_platform.c | |||
@@ -0,0 +1,235 @@ | |||
1 | /* | ||
2 | * Driver for SJA1000 CAN controllers on the OpenFirmware platform bus | ||
3 | * | ||
4 | * Copyright (C) 2008-2009 Wolfgang Grandegger <wg@grandegger.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the version 2 of the GNU General Public License | ||
8 | * as published by the Free Software Foundation | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software Foundation, | ||
17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | /* This is a generic driver for SJA1000 chips on the OpenFirmware platform | ||
21 | * bus found on embedded PowerPC systems. You need a SJA1000 CAN node | ||
22 | * definition in your flattened device tree source (DTS) file similar to: | ||
23 | * | ||
24 | * can@3,100 { | ||
25 | * compatible = "nxp,sja1000"; | ||
26 | * reg = <3 0x100 0x80>; | ||
27 | * interrupts = <2 0>; | ||
28 | * interrupt-parent = <&mpic>; | ||
29 | * nxp,external-clock-frequency = <16000000>; | ||
30 | * }; | ||
31 | * | ||
32 | * See "Documentation/powerpc/dts-bindings/can/sja1000.txt" for further | ||
33 | * information. | ||
34 | */ | ||
35 | |||
36 | #include <linux/kernel.h> | ||
37 | #include <linux/module.h> | ||
38 | #include <linux/interrupt.h> | ||
39 | #include <linux/netdevice.h> | ||
40 | #include <linux/delay.h> | ||
41 | #include <linux/can.h> | ||
42 | #include <linux/can/dev.h> | ||
43 | |||
44 | #include <linux/of_platform.h> | ||
45 | #include <asm/prom.h> | ||
46 | |||
47 | #include "sja1000.h" | ||
48 | |||
49 | #define DRV_NAME "sja1000_of_platform" | ||
50 | |||
51 | MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>"); | ||
52 | MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the OF platform bus"); | ||
53 | MODULE_LICENSE("GPL v2"); | ||
54 | |||
55 | #define SJA1000_OFP_CAN_CLOCK (16000000 / 2) | ||
56 | |||
57 | #define SJA1000_OFP_OCR OCR_TX0_PULLDOWN | ||
58 | #define SJA1000_OFP_CDR (CDR_CBP | CDR_CLK_OFF) | ||
59 | |||
60 | static u8 sja1000_ofp_read_reg(const struct sja1000_priv *priv, int reg) | ||
61 | { | ||
62 | return in_8(priv->reg_base + reg); | ||
63 | } | ||
64 | |||
65 | static void sja1000_ofp_write_reg(const struct sja1000_priv *priv, | ||
66 | int reg, u8 val) | ||
67 | { | ||
68 | out_8(priv->reg_base + reg, val); | ||
69 | } | ||
70 | |||
71 | static int __devexit sja1000_ofp_remove(struct of_device *ofdev) | ||
72 | { | ||
73 | struct net_device *dev = dev_get_drvdata(&ofdev->dev); | ||
74 | struct sja1000_priv *priv = netdev_priv(dev); | ||
75 | struct device_node *np = ofdev->node; | ||
76 | struct resource res; | ||
77 | |||
78 | dev_set_drvdata(&ofdev->dev, NULL); | ||
79 | |||
80 | unregister_sja1000dev(dev); | ||
81 | free_sja1000dev(dev); | ||
82 | iounmap(priv->reg_base); | ||
83 | irq_dispose_mapping(dev->irq); | ||
84 | |||
85 | of_address_to_resource(np, 0, &res); | ||
86 | release_mem_region(res.start, resource_size(&res)); | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | static int __devinit sja1000_ofp_probe(struct of_device *ofdev, | ||
92 | const struct of_device_id *id) | ||
93 | { | ||
94 | struct device_node *np = ofdev->node; | ||
95 | struct net_device *dev; | ||
96 | struct sja1000_priv *priv; | ||
97 | struct resource res; | ||
98 | const u32 *prop; | ||
99 | int err, irq, res_size, prop_size; | ||
100 | void __iomem *base; | ||
101 | |||
102 | err = of_address_to_resource(np, 0, &res); | ||
103 | if (err) { | ||
104 | dev_err(&ofdev->dev, "invalid address\n"); | ||
105 | return err; | ||
106 | } | ||
107 | |||
108 | res_size = resource_size(&res); | ||
109 | |||
110 | if (!request_mem_region(res.start, res_size, DRV_NAME)) { | ||
111 | dev_err(&ofdev->dev, "couldn't request %#llx..%#llx\n", | ||
112 | (unsigned long long)res.start, | ||
113 | (unsigned long long)res.end); | ||
114 | return -EBUSY; | ||
115 | } | ||
116 | |||
117 | base = ioremap_nocache(res.start, res_size); | ||
118 | if (!base) { | ||
119 | dev_err(&ofdev->dev, "couldn't ioremap %#llx..%#llx\n", | ||
120 | (unsigned long long)res.start, | ||
121 | (unsigned long long)res.end); | ||
122 | err = -ENOMEM; | ||
123 | goto exit_release_mem; | ||
124 | } | ||
125 | |||
126 | irq = irq_of_parse_and_map(np, 0); | ||
127 | if (irq == NO_IRQ) { | ||
128 | dev_err(&ofdev->dev, "no irq found\n"); | ||
129 | err = -ENODEV; | ||
130 | goto exit_unmap_mem; | ||
131 | } | ||
132 | |||
133 | dev = alloc_sja1000dev(0); | ||
134 | if (!dev) { | ||
135 | err = -ENOMEM; | ||
136 | goto exit_dispose_irq; | ||
137 | } | ||
138 | |||
139 | priv = netdev_priv(dev); | ||
140 | |||
141 | priv->read_reg = sja1000_ofp_read_reg; | ||
142 | priv->write_reg = sja1000_ofp_write_reg; | ||
143 | |||
144 | prop = of_get_property(np, "nxp,external-clock-frequency", &prop_size); | ||
145 | if (prop && (prop_size == sizeof(u32))) | ||
146 | priv->can.clock.freq = *prop / 2; | ||
147 | else | ||
148 | priv->can.clock.freq = SJA1000_OFP_CAN_CLOCK; /* default */ | ||
149 | |||
150 | prop = of_get_property(np, "nxp,tx-output-mode", &prop_size); | ||
151 | if (prop && (prop_size == sizeof(u32))) | ||
152 | priv->ocr |= *prop & OCR_MODE_MASK; | ||
153 | else | ||
154 | priv->ocr |= OCR_MODE_NORMAL; /* default */ | ||
155 | |||
156 | prop = of_get_property(np, "nxp,tx-output-config", &prop_size); | ||
157 | if (prop && (prop_size == sizeof(u32))) | ||
158 | priv->ocr |= (*prop << OCR_TX_SHIFT) & OCR_TX_MASK; | ||
159 | else | ||
160 | priv->ocr |= OCR_TX0_PULLDOWN; /* default */ | ||
161 | |||
162 | prop = of_get_property(np, "nxp,clock-out-frequency", &prop_size); | ||
163 | if (prop && (prop_size == sizeof(u32)) && *prop) { | ||
164 | u32 divider = priv->can.clock.freq * 2 / *prop; | ||
165 | |||
166 | if (divider > 1) | ||
167 | priv->cdr |= divider / 2 - 1; | ||
168 | else | ||
169 | priv->cdr |= CDR_CLKOUT_MASK; | ||
170 | } else { | ||
171 | priv->cdr |= CDR_CLK_OFF; /* default */ | ||
172 | } | ||
173 | |||
174 | prop = of_get_property(np, "nxp,no-comparator-bypass", NULL); | ||
175 | if (!prop) | ||
176 | priv->cdr |= CDR_CBP; /* default */ | ||
177 | |||
178 | priv->irq_flags = IRQF_SHARED; | ||
179 | priv->reg_base = base; | ||
180 | |||
181 | dev->irq = irq; | ||
182 | |||
183 | dev_info(&ofdev->dev, | ||
184 | "reg_base=0x%p irq=%d clock=%d ocr=0x%02x cdr=0x%02x\n", | ||
185 | priv->reg_base, dev->irq, priv->can.clock.freq, | ||
186 | priv->ocr, priv->cdr); | ||
187 | |||
188 | dev_set_drvdata(&ofdev->dev, dev); | ||
189 | SET_NETDEV_DEV(dev, &ofdev->dev); | ||
190 | |||
191 | err = register_sja1000dev(dev); | ||
192 | if (err) { | ||
193 | dev_err(&ofdev->dev, "registering %s failed (err=%d)\n", | ||
194 | DRV_NAME, err); | ||
195 | goto exit_free_sja1000; | ||
196 | } | ||
197 | |||
198 | return 0; | ||
199 | |||
200 | exit_free_sja1000: | ||
201 | free_sja1000dev(dev); | ||
202 | exit_dispose_irq: | ||
203 | irq_dispose_mapping(irq); | ||
204 | exit_unmap_mem: | ||
205 | iounmap(base); | ||
206 | exit_release_mem: | ||
207 | release_mem_region(res.start, res_size); | ||
208 | |||
209 | return err; | ||
210 | } | ||
211 | |||
212 | static struct of_device_id __devinitdata sja1000_ofp_table[] = { | ||
213 | {.compatible = "nxp,sja1000"}, | ||
214 | {}, | ||
215 | }; | ||
216 | |||
217 | static struct of_platform_driver sja1000_ofp_driver = { | ||
218 | .owner = THIS_MODULE, | ||
219 | .name = DRV_NAME, | ||
220 | .probe = sja1000_ofp_probe, | ||
221 | .remove = __devexit_p(sja1000_ofp_remove), | ||
222 | .match_table = sja1000_ofp_table, | ||
223 | }; | ||
224 | |||
225 | static int __init sja1000_ofp_init(void) | ||
226 | { | ||
227 | return of_register_platform_driver(&sja1000_ofp_driver); | ||
228 | } | ||
229 | module_init(sja1000_ofp_init); | ||
230 | |||
231 | static void __exit sja1000_ofp_exit(void) | ||
232 | { | ||
233 | return of_unregister_platform_driver(&sja1000_ofp_driver); | ||
234 | }; | ||
235 | module_exit(sja1000_ofp_exit); | ||
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>"); | |||
37 | MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the platform bus"); | 37 | MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the platform bus"); |
38 | MODULE_LICENSE("GPL v2"); | 38 | MODULE_LICENSE("GPL v2"); |
39 | 39 | ||
40 | static u8 sp_read_reg(const struct net_device *dev, int reg) | 40 | static 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 | ||
45 | static void sp_write_reg(const struct net_device *dev, int reg, u8 val) | 45 | static 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 | ||
50 | static int sp_probe(struct platform_device *pdev) | 50 | static 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) | |||
125 | static int sp_remove(struct platform_device *pdev) | 125 | static 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)); |