2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19 #include <linux/interrupt.h>
20 #include <linux/delay.h>
22 #include <linux/module.h>
23 #include <linux/sched.h>
24 #include <linux/pci.h>
25 #include <linux/init.h>
26 #include <linux/kernel.h>
27 #include <linux/types.h>
28 #include <linux/errno.h>
29 #include <linux/netdevice.h>
30 #include <linux/skbuff.h>
31 #include <linux/can.h>
32 #include <linux/can/dev.h>
33 #include <linux/can/error.h>
35 #define PCH_MAX_MSG_OBJ 32
36 #define PCH_MSG_OBJ_RX 0 /* The receive message object flag. */
37 #define PCH_MSG_OBJ_TX 1 /* The transmit message object flag. */
39 #define PCH_ENABLE 1 /* The enable flag */
40 #define PCH_DISABLE 0 /* The disable flag */
41 #define PCH_CTRL_INIT BIT(0) /* The INIT bit of CANCONT register. */
42 #define PCH_CTRL_IE BIT(1) /* The IE bit of CAN control register */
43 #define PCH_CTRL_IE_SIE_EIE (BIT(3) | BIT(2) | BIT(1))
44 #define PCH_CTRL_CCE BIT(6)
45 #define PCH_CTRL_OPT BIT(7) /* The OPT bit of CANCONT register. */
46 #define PCH_OPT_SILENT BIT(3) /* The Silent bit of CANOPT reg. */
47 #define PCH_OPT_LBACK BIT(4) /* The LoopBack bit of CANOPT reg. */
49 #define PCH_CMASK_RX_TX_SET 0x00f3
50 #define PCH_CMASK_RX_TX_GET 0x0073
51 #define PCH_CMASK_ALL 0xff
52 #define PCH_CMASK_NEWDAT BIT(2)
53 #define PCH_CMASK_CLRINTPND BIT(3)
54 #define PCH_CMASK_CTRL BIT(4)
55 #define PCH_CMASK_ARB BIT(5)
56 #define PCH_CMASK_MASK BIT(6)
57 #define PCH_CMASK_RDWR BIT(7)
58 #define PCH_IF_MCONT_NEWDAT BIT(15)
59 #define PCH_IF_MCONT_MSGLOST BIT(14)
60 #define PCH_IF_MCONT_INTPND BIT(13)
61 #define PCH_IF_MCONT_UMASK BIT(12)
62 #define PCH_IF_MCONT_TXIE BIT(11)
63 #define PCH_IF_MCONT_RXIE BIT(10)
64 #define PCH_IF_MCONT_RMTEN BIT(9)
65 #define PCH_IF_MCONT_TXRQXT BIT(8)
66 #define PCH_IF_MCONT_EOB BIT(7)
67 #define PCH_IF_MCONT_DLC (BIT(0) | BIT(1) | BIT(2) | BIT(3))
68 #define PCH_MASK2_MDIR_MXTD (BIT(14) | BIT(15))
69 #define PCH_ID2_DIR BIT(13)
70 #define PCH_ID2_XTD BIT(14)
71 #define PCH_ID_MSGVAL BIT(15)
72 #define PCH_IF_CREQ_BUSY BIT(15)
74 #define PCH_STATUS_INT 0x8000
75 #define PCH_REC 0x00007f00
76 #define PCH_TEC 0x000000ff
78 #define PCH_TX_OK BIT(3)
79 #define PCH_RX_OK BIT(4)
80 #define PCH_EPASSIV BIT(5)
81 #define PCH_EWARN BIT(6)
82 #define PCH_BUS_OFF BIT(7)
83 #define PCH_LEC0 BIT(0)
84 #define PCH_LEC1 BIT(1)
85 #define PCH_LEC2 BIT(2)
86 #define PCH_LEC_ALL (PCH_LEC0 | PCH_LEC1 | PCH_LEC2)
87 #define PCH_STUF_ERR PCH_LEC0
88 #define PCH_FORM_ERR PCH_LEC1
89 #define PCH_ACK_ERR (PCH_LEC0 | PCH_LEC1)
90 #define PCH_BIT1_ERR PCH_LEC2
91 #define PCH_BIT0_ERR (PCH_LEC0 | PCH_LEC2)
92 #define PCH_CRC_ERR (PCH_LEC1 | PCH_LEC2)
94 /* bit position of certain controller bits. */
97 #define PCH_BIT_TSEG1 8
98 #define PCH_BIT_TSEG2 12
99 #define PCH_BIT_BRPE_BRPE 6
100 #define PCH_MSK_BITT_BRP 0x3f
101 #define PCH_MSK_BRPE_BRPE 0x3c0
102 #define PCH_MSK_CTRL_IE_SIE_EIE 0x07
103 #define PCH_COUNTER_LIMIT 10
105 #define PCH_CAN_CLK 50000000 /* 50MHz */
107 /* Define the number of message object.
108 * PCH CAN communications are done via Message RAM.
109 * The Message RAM consists of 32 message objects. */
110 #define PCH_RX_OBJ_NUM 26 /* 1~ PCH_RX_OBJ_NUM is Rx*/
111 #define PCH_TX_OBJ_NUM 6 /* PCH_RX_OBJ_NUM is RX ~ Tx*/
112 #define PCH_OBJ_NUM (PCH_TX_OBJ_NUM + PCH_RX_OBJ_NUM)
114 #define PCH_FIFO_THRESH 16
125 struct pch_can_regs {
168 struct pch_can_priv {
170 unsigned int can_num;
172 unsigned int tx_enable[PCH_MAX_MSG_OBJ];
173 unsigned int rx_enable[PCH_MAX_MSG_OBJ];
174 unsigned int rx_link[PCH_MAX_MSG_OBJ];
175 unsigned int int_enables;
176 unsigned int int_stat;
177 struct net_device *ndev;
178 spinlock_t msgif_reg_lock; /* Message Interface Registers Access Lock*/
179 unsigned int msg_obj[PCH_MAX_MSG_OBJ];
180 struct pch_can_regs __iomem *regs;
181 struct napi_struct napi;
182 unsigned int tx_obj; /* Point next Tx Obj index */
183 unsigned int use_msi;
186 static struct can_bittiming_const pch_can_bittiming_const = {
187 .name = KBUILD_MODNAME,
194 .brp_max = 1024, /* 6bit + extended 4bit */
198 static DEFINE_PCI_DEVICE_TABLE(pch_pci_tbl) = {
199 {PCI_VENDOR_ID_INTEL, 0x8818, PCI_ANY_ID, PCI_ANY_ID,},
202 MODULE_DEVICE_TABLE(pci, pch_pci_tbl);
204 static inline void pch_can_bit_set(void __iomem *addr, u32 mask)
206 iowrite32(ioread32(addr) | mask, addr);
209 static inline void pch_can_bit_clear(void __iomem *addr, u32 mask)
211 iowrite32(ioread32(addr) & ~mask, addr);
214 static void pch_can_set_run_mode(struct pch_can_priv *priv,
215 enum pch_can_mode mode)
219 pch_can_bit_clear(&priv->regs->cont, PCH_CTRL_INIT);
223 pch_can_bit_set(&priv->regs->cont, PCH_CTRL_INIT);
227 dev_err(&priv->ndev->dev, "%s -> Invalid Mode.\n", __func__);
232 static void pch_can_set_optmode(struct pch_can_priv *priv)
234 u32 reg_val = ioread32(&priv->regs->opt);
236 if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
237 reg_val |= PCH_OPT_SILENT;
239 if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK)
240 reg_val |= PCH_OPT_LBACK;
242 pch_can_bit_set(&priv->regs->cont, PCH_CTRL_OPT);
243 iowrite32(reg_val, &priv->regs->opt);
246 static void pch_can_set_int_custom(struct pch_can_priv *priv)
248 /* Clearing the IE, SIE and EIE bits of Can control register. */
249 pch_can_bit_clear(&priv->regs->cont, PCH_CTRL_IE_SIE_EIE);
251 /* Appropriately setting them. */
252 pch_can_bit_set(&priv->regs->cont,
253 ((priv->int_enables & PCH_MSK_CTRL_IE_SIE_EIE) << 1));
256 /* This function retrieves interrupt enabled for the CAN device. */
257 static void pch_can_get_int_enables(struct pch_can_priv *priv, u32 *enables)
259 /* Obtaining the status of IE, SIE and EIE interrupt bits. */
260 *enables = ((ioread32(&priv->regs->cont) & PCH_CTRL_IE_SIE_EIE) >> 1);
263 static void pch_can_set_int_enables(struct pch_can_priv *priv,
264 enum pch_can_mode interrupt_no)
266 switch (interrupt_no) {
268 pch_can_bit_set(&priv->regs->cont, PCH_CTRL_IE);
271 case PCH_CAN_DISABLE:
272 pch_can_bit_clear(&priv->regs->cont, PCH_CTRL_IE);
276 pch_can_bit_set(&priv->regs->cont, PCH_CTRL_IE_SIE_EIE);
280 pch_can_bit_clear(&priv->regs->cont, PCH_CTRL_IE_SIE_EIE);
284 dev_err(&priv->ndev->dev, "Invalid interrupt number.\n");
289 static void pch_can_check_if_busy(u32 __iomem *creq_addr, u32 num)
291 u32 counter = PCH_COUNTER_LIMIT;
294 iowrite32(num, creq_addr);
296 ifx_creq = ioread32(creq_addr) & PCH_IF_CREQ_BUSY;
303 pr_err("%s:IF1 BUSY Flag is set forever.\n", __func__);
306 static void pch_can_set_rx_enable(struct pch_can_priv *priv, u32 buff_num,
311 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
312 /* Reading the receive buffer data from RAM to Interface1 registers */
313 iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
314 pch_can_check_if_busy(&priv->regs->if1_creq, buff_num);
316 /* Setting the IF1MASK1 register to access MsgVal and RxIE bits */
317 iowrite32(PCH_CMASK_RDWR | PCH_CMASK_ARB | PCH_CMASK_CTRL,
318 &priv->regs->if1_cmask);
320 if (set == PCH_ENABLE) {
321 /* Setting the MsgVal and RxIE bits */
322 pch_can_bit_set(&priv->regs->if1_mcont, PCH_IF_MCONT_RXIE);
323 pch_can_bit_set(&priv->regs->if1_id2, PCH_ID_MSGVAL);
325 } else if (set == PCH_DISABLE) {
326 /* Resetting the MsgVal and RxIE bits */
327 pch_can_bit_clear(&priv->regs->if1_mcont, PCH_IF_MCONT_RXIE);
328 pch_can_bit_clear(&priv->regs->if1_id2, PCH_ID_MSGVAL);
331 pch_can_check_if_busy(&priv->regs->if1_creq, buff_num);
332 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
335 static void pch_can_rx_enable_all(struct pch_can_priv *priv)
339 /* Traversing to obtain the object configured as receivers. */
340 for (i = 0; i < PCH_OBJ_NUM; i++) {
341 if (priv->msg_obj[i] == PCH_MSG_OBJ_RX)
342 pch_can_set_rx_enable(priv, i + 1, PCH_ENABLE);
346 static void pch_can_rx_disable_all(struct pch_can_priv *priv)
350 /* Traversing to obtain the object configured as receivers. */
351 for (i = 0; i < PCH_OBJ_NUM; i++) {
352 if (priv->msg_obj[i] == PCH_MSG_OBJ_RX)
353 pch_can_set_rx_enable(priv, i + 1, PCH_DISABLE);
357 static void pch_can_set_tx_enable(struct pch_can_priv *priv, u32 buff_num,
362 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
363 /* Reading the Msg buffer from Message RAM to Interface2 registers. */
364 iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
365 pch_can_check_if_busy(&priv->regs->if2_creq, buff_num);
367 /* Setting the IF2CMASK register for accessing the
368 MsgVal and TxIE bits */
369 iowrite32(PCH_CMASK_RDWR | PCH_CMASK_ARB | PCH_CMASK_CTRL,
370 &priv->regs->if2_cmask);
372 if (set == PCH_ENABLE) {
373 /* Setting the MsgVal and TxIE bits */
374 pch_can_bit_set(&priv->regs->if2_mcont, PCH_IF_MCONT_TXIE);
375 pch_can_bit_set(&priv->regs->if2_id2, PCH_ID_MSGVAL);
376 } else if (set == PCH_DISABLE) {
377 /* Resetting the MsgVal and TxIE bits. */
378 pch_can_bit_clear(&priv->regs->if2_mcont, PCH_IF_MCONT_TXIE);
379 pch_can_bit_clear(&priv->regs->if2_id2, PCH_ID_MSGVAL);
382 pch_can_check_if_busy(&priv->regs->if2_creq, buff_num);
383 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
386 static void pch_can_tx_enable_all(struct pch_can_priv *priv)
390 /* Traversing to obtain the object configured as transmit object. */
391 for (i = 0; i < PCH_OBJ_NUM; i++) {
392 if (priv->msg_obj[i] == PCH_MSG_OBJ_TX)
393 pch_can_set_tx_enable(priv, i + 1, PCH_ENABLE);
397 static void pch_can_tx_disable_all(struct pch_can_priv *priv)
401 /* Traversing to obtain the object configured as transmit object. */
402 for (i = 0; i < PCH_OBJ_NUM; i++) {
403 if (priv->msg_obj[i] == PCH_MSG_OBJ_TX)
404 pch_can_set_tx_enable(priv, i + 1, PCH_DISABLE);
408 static void pch_can_get_rx_enable(struct pch_can_priv *priv, u32 buff_num,
413 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
414 iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
415 pch_can_check_if_busy(&priv->regs->if1_creq, buff_num);
417 if (((ioread32(&priv->regs->if1_id2)) & PCH_ID_MSGVAL) &&
418 ((ioread32(&priv->regs->if1_mcont)) &
420 *enable = PCH_ENABLE;
422 *enable = PCH_DISABLE;
423 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
426 static void pch_can_get_tx_enable(struct pch_can_priv *priv, u32 buff_num,
431 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
432 iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
433 pch_can_check_if_busy(&priv->regs->if2_creq, buff_num);
435 if (((ioread32(&priv->regs->if2_id2)) & PCH_ID_MSGVAL) &&
436 ((ioread32(&priv->regs->if2_mcont)) &
437 PCH_IF_MCONT_TXIE)) {
438 *enable = PCH_ENABLE;
440 *enable = PCH_DISABLE;
442 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
445 static int pch_can_int_pending(struct pch_can_priv *priv)
447 return ioread32(&priv->regs->intr) & 0xffff;
450 static void pch_can_set_rx_buffer_link(struct pch_can_priv *priv,
451 u32 buffer_num, u32 set)
455 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
456 iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
457 pch_can_check_if_busy(&priv->regs->if1_creq, buffer_num);
458 iowrite32(PCH_CMASK_RDWR | PCH_CMASK_CTRL, &priv->regs->if1_cmask);
459 if (set == PCH_ENABLE)
460 pch_can_bit_clear(&priv->regs->if1_mcont, PCH_IF_MCONT_EOB);
462 pch_can_bit_set(&priv->regs->if1_mcont, PCH_IF_MCONT_EOB);
464 pch_can_check_if_busy(&priv->regs->if1_creq, buffer_num);
465 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
468 static void pch_can_get_rx_buffer_link(struct pch_can_priv *priv,
469 u32 buffer_num, u32 *link)
473 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
474 iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
475 pch_can_check_if_busy(&priv->regs->if1_creq, buffer_num);
477 if (ioread32(&priv->regs->if1_mcont) & PCH_IF_MCONT_EOB)
481 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
484 static void pch_can_clear_buffers(struct pch_can_priv *priv)
488 for (i = 0; i < PCH_RX_OBJ_NUM; i++) {
489 iowrite32(PCH_CMASK_RX_TX_SET, &priv->regs->if1_cmask);
490 iowrite32(0xffff, &priv->regs->if1_mask1);
491 iowrite32(0xffff, &priv->regs->if1_mask2);
492 iowrite32(0x0, &priv->regs->if1_id1);
493 iowrite32(0x0, &priv->regs->if1_id2);
494 iowrite32(0x0, &priv->regs->if1_mcont);
495 iowrite32(0x0, &priv->regs->if1_dataa1);
496 iowrite32(0x0, &priv->regs->if1_dataa2);
497 iowrite32(0x0, &priv->regs->if1_datab1);
498 iowrite32(0x0, &priv->regs->if1_datab2);
499 iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK |
500 PCH_CMASK_ARB | PCH_CMASK_CTRL,
501 &priv->regs->if1_cmask);
502 pch_can_check_if_busy(&priv->regs->if1_creq, i+1);
505 for (i = i; i < PCH_OBJ_NUM; i++) {
506 iowrite32(PCH_CMASK_RX_TX_SET, &priv->regs->if2_cmask);
507 iowrite32(0xffff, &priv->regs->if2_mask1);
508 iowrite32(0xffff, &priv->regs->if2_mask2);
509 iowrite32(0x0, &priv->regs->if2_id1);
510 iowrite32(0x0, &priv->regs->if2_id2);
511 iowrite32(0x0, &priv->regs->if2_mcont);
512 iowrite32(0x0, &priv->regs->if2_dataa1);
513 iowrite32(0x0, &priv->regs->if2_dataa2);
514 iowrite32(0x0, &priv->regs->if2_datab1);
515 iowrite32(0x0, &priv->regs->if2_datab2);
516 iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK |
517 PCH_CMASK_ARB | PCH_CMASK_CTRL,
518 &priv->regs->if2_cmask);
519 pch_can_check_if_busy(&priv->regs->if2_creq, i+1);
523 static void pch_can_config_rx_tx_buffers(struct pch_can_priv *priv)
528 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
530 for (i = 0; i < PCH_OBJ_NUM; i++) {
531 if (priv->msg_obj[i] == PCH_MSG_OBJ_RX) {
532 iowrite32(PCH_CMASK_RX_TX_GET,
533 &priv->regs->if1_cmask);
534 pch_can_check_if_busy(&priv->regs->if1_creq, i+1);
536 iowrite32(0x0, &priv->regs->if1_id1);
537 iowrite32(0x0, &priv->regs->if1_id2);
539 pch_can_bit_set(&priv->regs->if1_mcont,
542 /* Set FIFO mode set to 0 except last Rx Obj*/
543 pch_can_bit_clear(&priv->regs->if1_mcont,
545 /* In case FIFO mode, Last EoB of Rx Obj must be 1 */
546 if (i == (PCH_RX_OBJ_NUM - 1))
547 pch_can_bit_set(&priv->regs->if1_mcont,
550 iowrite32(0, &priv->regs->if1_mask1);
551 pch_can_bit_clear(&priv->regs->if1_mask2,
552 0x1fff | PCH_MASK2_MDIR_MXTD);
554 /* Setting CMASK for writing */
555 iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK |
556 PCH_CMASK_ARB | PCH_CMASK_CTRL,
557 &priv->regs->if1_cmask);
559 pch_can_check_if_busy(&priv->regs->if1_creq, i+1);
560 } else if (priv->msg_obj[i] == PCH_MSG_OBJ_TX) {
561 iowrite32(PCH_CMASK_RX_TX_GET,
562 &priv->regs->if2_cmask);
563 pch_can_check_if_busy(&priv->regs->if2_creq, i+1);
565 /* Resetting DIR bit for reception */
566 iowrite32(0x0, &priv->regs->if2_id1);
567 iowrite32(0x0, &priv->regs->if2_id2);
568 pch_can_bit_set(&priv->regs->if2_id2, PCH_ID2_DIR);
570 /* Setting EOB bit for transmitter */
571 iowrite32(PCH_IF_MCONT_EOB, &priv->regs->if2_mcont);
573 pch_can_bit_set(&priv->regs->if2_mcont,
576 iowrite32(0, &priv->regs->if2_mask1);
577 pch_can_bit_clear(&priv->regs->if2_mask2, 0x1fff);
579 /* Setting CMASK for writing */
580 iowrite32(PCH_CMASK_RDWR | PCH_CMASK_MASK |
581 PCH_CMASK_ARB | PCH_CMASK_CTRL,
582 &priv->regs->if2_cmask);
584 pch_can_check_if_busy(&priv->regs->if2_creq, i+1);
587 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
590 static void pch_can_init(struct pch_can_priv *priv)
592 /* Stopping the Can device. */
593 pch_can_set_run_mode(priv, PCH_CAN_STOP);
595 /* Clearing all the message object buffers. */
596 pch_can_clear_buffers(priv);
598 /* Configuring the respective message object as either rx/tx object. */
599 pch_can_config_rx_tx_buffers(priv);
601 /* Enabling the interrupts. */
602 pch_can_set_int_enables(priv, PCH_CAN_ALL);
605 static void pch_can_release(struct pch_can_priv *priv)
607 /* Stooping the CAN device. */
608 pch_can_set_run_mode(priv, PCH_CAN_STOP);
610 /* Disabling the interrupts. */
611 pch_can_set_int_enables(priv, PCH_CAN_NONE);
613 /* Disabling all the receive object. */
614 pch_can_rx_disable_all(priv);
616 /* Disabling all the transmit object. */
617 pch_can_tx_disable_all(priv);
620 /* This function clears interrupt(s) from the CAN device. */
621 static void pch_can_int_clr(struct pch_can_priv *priv, u32 mask)
623 if (mask == PCH_STATUS_INT) {
624 ioread32(&priv->regs->stat);
628 /* Clear interrupt for transmit object */
629 if (priv->msg_obj[mask - 1] == PCH_MSG_OBJ_TX) {
630 /* Setting CMASK for clearing interrupts for
631 frame transmission. */
632 iowrite32(PCH_CMASK_RDWR | PCH_CMASK_CTRL | PCH_CMASK_ARB,
633 &priv->regs->if2_cmask);
635 /* Resetting the ID registers. */
636 pch_can_bit_set(&priv->regs->if2_id2,
637 PCH_ID2_DIR | (0x7ff << 2));
638 iowrite32(0x0, &priv->regs->if2_id1);
640 /* Claring NewDat, TxRqst & IntPnd */
641 pch_can_bit_clear(&priv->regs->if2_mcont,
642 PCH_IF_MCONT_NEWDAT | PCH_IF_MCONT_INTPND |
643 PCH_IF_MCONT_TXRQXT);
644 pch_can_check_if_busy(&priv->regs->if2_creq, mask);
645 } else if (priv->msg_obj[mask - 1] == PCH_MSG_OBJ_RX) {
646 /* Setting CMASK for clearing the reception interrupts. */
647 iowrite32(PCH_CMASK_RDWR | PCH_CMASK_CTRL | PCH_CMASK_ARB,
648 &priv->regs->if1_cmask);
650 /* Clearing the Dir bit. */
651 pch_can_bit_clear(&priv->regs->if1_id2, PCH_ID2_DIR);
653 /* Clearing NewDat & IntPnd */
654 pch_can_bit_clear(&priv->regs->if1_mcont,
655 PCH_IF_MCONT_NEWDAT | PCH_IF_MCONT_INTPND);
657 pch_can_check_if_busy(&priv->regs->if1_creq, mask);
661 static int pch_can_get_buffer_status(struct pch_can_priv *priv)
663 return (ioread32(&priv->regs->treq1) & 0xffff) |
664 ((ioread32(&priv->regs->treq2) & 0xffff) << 16);
667 static void pch_can_reset(struct pch_can_priv *priv)
669 /* write to sw reset register */
670 iowrite32(1, &priv->regs->srst);
671 iowrite32(0, &priv->regs->srst);
674 static void pch_can_error(struct net_device *ndev, u32 status)
677 struct pch_can_priv *priv = netdev_priv(ndev);
678 struct can_frame *cf;
680 struct net_device_stats *stats = &(priv->ndev->stats);
681 enum can_state state = priv->can.state;
683 skb = alloc_can_err_skb(ndev, &cf);
687 if (status & PCH_BUS_OFF) {
688 pch_can_tx_disable_all(priv);
689 pch_can_rx_disable_all(priv);
690 state = CAN_STATE_BUS_OFF;
691 cf->can_id |= CAN_ERR_BUSOFF;
693 pch_can_set_run_mode(priv, PCH_CAN_RUN);
694 dev_err(&ndev->dev, "%s -> Bus Off occurres.\n", __func__);
697 /* Warning interrupt. */
698 if (status & PCH_EWARN) {
699 state = CAN_STATE_ERROR_WARNING;
700 priv->can.can_stats.error_warning++;
701 cf->can_id |= CAN_ERR_CRTL;
702 errc = ioread32(&priv->regs->errc);
703 if (((errc & PCH_REC) >> 8) > 96)
704 cf->data[1] |= CAN_ERR_CRTL_RX_WARNING;
705 if ((errc & PCH_TEC) > 96)
706 cf->data[1] |= CAN_ERR_CRTL_TX_WARNING;
708 "%s -> Error Counter is more than 96.\n", __func__);
710 /* Error passive interrupt. */
711 if (status & PCH_EPASSIV) {
712 priv->can.can_stats.error_passive++;
713 state = CAN_STATE_ERROR_PASSIVE;
714 cf->can_id |= CAN_ERR_CRTL;
715 errc = ioread32(&priv->regs->errc);
716 if (((errc & PCH_REC) >> 8) > 127)
717 cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
718 if ((errc & PCH_TEC) > 127)
719 cf->data[1] |= CAN_ERR_CRTL_TX_PASSIVE;
721 "%s -> CAN controller is ERROR PASSIVE .\n", __func__);
724 if (status & PCH_LEC_ALL) {
725 priv->can.can_stats.bus_error++;
727 switch (status & PCH_LEC_ALL) {
729 cf->data[2] |= CAN_ERR_PROT_STUFF;
732 cf->data[2] |= CAN_ERR_PROT_FORM;
735 cf->data[2] |= CAN_ERR_PROT_LOC_ACK |
736 CAN_ERR_PROT_LOC_ACK_DEL;
740 cf->data[2] |= CAN_ERR_PROT_BIT;
743 cf->data[2] |= CAN_ERR_PROT_LOC_CRC_SEQ |
744 CAN_ERR_PROT_LOC_CRC_DEL;
747 iowrite32(status | PCH_LEC_ALL, &priv->regs->stat);
753 priv->can.state = state;
757 stats->rx_bytes += cf->can_dlc;
760 static irqreturn_t pch_can_interrupt(int irq, void *dev_id)
762 struct net_device *ndev = (struct net_device *)dev_id;
763 struct pch_can_priv *priv = netdev_priv(ndev);
765 pch_can_set_int_enables(priv, PCH_CAN_NONE);
767 napi_schedule(&priv->napi);
772 static int pch_can_rx_normal(struct net_device *ndev, u32 int_stat)
781 struct can_frame *cf;
782 struct pch_can_priv *priv = netdev_priv(ndev);
783 struct net_device_stats *stats = &(priv->ndev->stats);
785 /* Reading the messsage object from the Message RAM */
786 iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
787 pch_can_check_if_busy(&priv->regs->if1_creq, int_stat);
789 /* Reading the MCONT register. */
790 reg = ioread32(&priv->regs->if1_mcont);
793 for (k = int_stat; !(reg & PCH_IF_MCONT_EOB); k++) {
794 /* If MsgLost bit set. */
795 if (reg & PCH_IF_MCONT_MSGLOST) {
796 dev_err(&priv->ndev->dev, "Msg Obj is overwritten.\n");
797 pch_can_bit_clear(&priv->regs->if1_mcont,
798 PCH_IF_MCONT_MSGLOST);
799 iowrite32(PCH_CMASK_RDWR | PCH_CMASK_CTRL,
800 &priv->regs->if1_cmask);
801 pch_can_check_if_busy(&priv->regs->if1_creq, k);
803 skb = alloc_can_err_skb(ndev, &cf);
807 priv->can.can_stats.error_passive++;
808 priv->can.state = CAN_STATE_ERROR_PASSIVE;
809 cf->can_id |= CAN_ERR_CRTL;
810 cf->data[1] |= CAN_ERR_CRTL_RX_OVERFLOW;
811 cf->data[2] |= CAN_ERR_PROT_OVERLOAD;
813 stats->rx_bytes += cf->can_dlc;
815 netif_receive_skb(skb);
819 if (!(reg & PCH_IF_MCONT_NEWDAT))
822 skb = alloc_can_skb(priv->ndev, &cf);
826 /* Get Received data */
827 ide = ((ioread32(&priv->regs->if1_id2)) & PCH_ID2_XTD) >> 14;
829 id = (ioread32(&priv->regs->if1_id1) & 0xffff);
830 id |= (((ioread32(&priv->regs->if1_id2)) &
832 cf->can_id = (id & CAN_EFF_MASK) | CAN_EFF_FLAG;
834 id = (((ioread32(&priv->regs->if1_id2)) &
835 (CAN_SFF_MASK << 2)) >> 2);
836 cf->can_id = (id & CAN_SFF_MASK);
839 rtr = (ioread32(&priv->regs->if1_id2) & PCH_ID2_DIR);
842 cf->can_id |= CAN_RTR_FLAG;
844 cf->can_dlc = ((ioread32(&priv->regs->if1_mcont)) &
848 for (i = 0, j = 0; i < cf->can_dlc; j++) {
849 reg = ioread32(&priv->regs->if1_dataa1 + j*4);
850 cf->data[i++] = cpu_to_le32(reg & 0xff);
851 if (i == cf->can_dlc)
853 cf->data[i++] = cpu_to_le32((reg >> 8) & 0xff);
856 netif_receive_skb(skb);
859 stats->rx_bytes += cf->can_dlc;
861 if (k < PCH_FIFO_THRESH) {
862 iowrite32(PCH_CMASK_RDWR | PCH_CMASK_CTRL |
863 PCH_CMASK_ARB, &priv->regs->if1_cmask);
865 /* Clearing the Dir bit. */
866 pch_can_bit_clear(&priv->regs->if1_id2, PCH_ID2_DIR);
868 /* Clearing NewDat & IntPnd */
869 pch_can_bit_clear(&priv->regs->if1_mcont,
870 PCH_IF_MCONT_INTPND);
871 pch_can_check_if_busy(&priv->regs->if1_creq, k);
872 } else if (k > PCH_FIFO_THRESH) {
873 pch_can_int_clr(priv, k);
874 } else if (k == PCH_FIFO_THRESH) {
876 for (cnt = 0; cnt < PCH_FIFO_THRESH; cnt++)
877 pch_can_int_clr(priv, cnt+1);
880 /* Reading the messsage object from the Message RAM */
881 iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->if1_cmask);
882 pch_can_check_if_busy(&priv->regs->if1_creq, k + 1);
883 reg = ioread32(&priv->regs->if1_mcont);
888 static int pch_can_rx_poll(struct napi_struct *napi, int quota)
890 struct net_device *ndev = napi->dev;
891 struct pch_can_priv *priv = netdev_priv(ndev);
892 struct net_device_stats *stats = &(priv->ndev->stats);
899 int_stat = pch_can_int_pending(priv);
904 if (int_stat == PCH_STATUS_INT) {
905 reg_stat = ioread32(&priv->regs->stat);
906 if (reg_stat & (PCH_BUS_OFF | PCH_LEC_ALL)) {
907 if ((reg_stat & PCH_LEC_ALL) != PCH_LEC_ALL)
908 pch_can_error(ndev, reg_stat);
911 if (reg_stat & PCH_TX_OK) {
912 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
913 iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
914 pch_can_check_if_busy(&priv->regs->if2_creq,
915 ioread32(&priv->regs->intr));
916 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
917 pch_can_bit_clear(&priv->regs->stat, PCH_TX_OK);
920 if (reg_stat & PCH_RX_OK)
921 pch_can_bit_clear(&priv->regs->stat, PCH_RX_OK);
923 int_stat = pch_can_int_pending(priv);
924 if (int_stat == PCH_STATUS_INT)
929 if ((int_stat >= 1) && (int_stat <= PCH_RX_OBJ_NUM)) {
930 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
931 rcv_pkts = pch_can_rx_normal(ndev, int_stat);
932 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
935 } else if ((int_stat > PCH_RX_OBJ_NUM) && (int_stat <= PCH_OBJ_NUM)) {
936 if (priv->msg_obj[int_stat - 1] == PCH_MSG_OBJ_TX) {
937 /* Handle transmission interrupt */
938 can_get_echo_skb(ndev, int_stat - PCH_RX_OBJ_NUM - 1);
939 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
940 iowrite32(PCH_CMASK_RX_TX_GET | PCH_CMASK_CLRINTPND,
941 &priv->regs->if2_cmask);
942 dlc = ioread32(&priv->regs->if2_mcont) &
944 pch_can_check_if_busy(&priv->regs->if2_creq, int_stat);
945 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
948 stats->tx_bytes += dlc;
953 int_stat = pch_can_int_pending(priv);
954 if (int_stat == PCH_STATUS_INT)
956 else if (int_stat >= 1 && int_stat <= 32)
960 pch_can_set_int_enables(priv, PCH_CAN_ALL);
965 static int pch_set_bittiming(struct net_device *ndev)
967 struct pch_can_priv *priv = netdev_priv(ndev);
968 const struct can_bittiming *bt = &priv->can.bittiming;
973 /* Setting the CCE bit for accessing the Can Timing register. */
974 pch_can_bit_set(&priv->regs->cont, PCH_CTRL_CCE);
976 brp = (bt->tq) / (1000000000/PCH_CAN_CLK) - 1;
977 canbit = brp & PCH_MSK_BITT_BRP;
978 canbit |= (bt->sjw - 1) << PCH_BIT_SJW;
979 canbit |= (bt->phase_seg1 + bt->prop_seg - 1) << PCH_BIT_TSEG1;
980 canbit |= (bt->phase_seg2 - 1) << PCH_BIT_TSEG2;
981 bepe = (brp & PCH_MSK_BRPE_BRPE) >> PCH_BIT_BRPE_BRPE;
982 iowrite32(canbit, &priv->regs->bitt);
983 iowrite32(bepe, &priv->regs->brpe);
984 pch_can_bit_clear(&priv->regs->cont, PCH_CTRL_CCE);
989 static void pch_can_start(struct net_device *ndev)
991 struct pch_can_priv *priv = netdev_priv(ndev);
993 if (priv->can.state != CAN_STATE_STOPPED)
996 pch_set_bittiming(ndev);
997 pch_can_set_optmode(priv);
999 pch_can_tx_enable_all(priv);
1000 pch_can_rx_enable_all(priv);
1002 /* Setting the CAN to run mode. */
1003 pch_can_set_run_mode(priv, PCH_CAN_RUN);
1005 priv->can.state = CAN_STATE_ERROR_ACTIVE;
1010 static int pch_can_do_set_mode(struct net_device *ndev, enum can_mode mode)
1015 case CAN_MODE_START:
1016 pch_can_start(ndev);
1017 netif_wake_queue(ndev);
1027 static int pch_can_open(struct net_device *ndev)
1029 struct pch_can_priv *priv = netdev_priv(ndev);
1032 retval = pci_enable_msi(priv->dev);
1034 dev_info(&ndev->dev, "PCH CAN opened without MSI\n");
1037 dev_info(&ndev->dev, "PCH CAN opened with MSI\n");
1041 /* Regsitering the interrupt. */
1042 retval = request_irq(priv->dev->irq, pch_can_interrupt, IRQF_SHARED,
1045 dev_err(&ndev->dev, "request_irq failed.\n");
1049 /* Open common can device */
1050 retval = open_candev(ndev);
1052 dev_err(ndev->dev.parent, "open_candev() failed %d\n", retval);
1053 goto err_open_candev;
1057 pch_can_start(ndev);
1058 napi_enable(&priv->napi);
1059 netif_start_queue(ndev);
1064 free_irq(priv->dev->irq, ndev);
1067 pci_disable_msi(priv->dev);
1069 pch_can_release(priv);
1074 static int pch_close(struct net_device *ndev)
1076 struct pch_can_priv *priv = netdev_priv(ndev);
1078 netif_stop_queue(ndev);
1079 napi_disable(&priv->napi);
1080 pch_can_release(priv);
1081 free_irq(priv->dev->irq, ndev);
1083 pci_disable_msi(priv->dev);
1085 priv->can.state = CAN_STATE_STOPPED;
1089 static int pch_get_msg_obj_sts(struct net_device *ndev, u32 obj_id)
1091 u32 buffer_status = 0;
1092 struct pch_can_priv *priv = netdev_priv(ndev);
1094 /* Getting the message object status. */
1095 buffer_status = (u32) pch_can_get_buffer_status(priv);
1097 return buffer_status & obj_id;
1101 static netdev_tx_t pch_xmit(struct sk_buff *skb, struct net_device *ndev)
1104 unsigned long flags;
1105 struct pch_can_priv *priv = netdev_priv(ndev);
1106 struct can_frame *cf = (struct can_frame *)skb->data;
1107 int tx_buffer_avail = 0;
1109 if (can_dropped_invalid_skb(ndev, skb))
1110 return NETDEV_TX_OK;
1112 if (priv->tx_obj == (PCH_OBJ_NUM + 1)) { /* Point tail Obj */
1113 while (pch_get_msg_obj_sts(ndev, (((1 << PCH_TX_OBJ_NUM)-1) <<
1117 priv->tx_obj = PCH_RX_OBJ_NUM + 1; /* Point head of Tx Obj ID */
1118 tx_buffer_avail = priv->tx_obj; /* Point Tail of Tx Obj */
1120 tx_buffer_avail = priv->tx_obj;
1124 /* Attaining the lock. */
1125 spin_lock_irqsave(&priv->msgif_reg_lock, flags);
1127 /* Reading the Msg Obj from the Msg RAM to the Interface register. */
1128 iowrite32(PCH_CMASK_RX_TX_GET, &priv->regs->if2_cmask);
1129 pch_can_check_if_busy(&priv->regs->if2_creq, tx_buffer_avail);
1131 /* Setting the CMASK register. */
1132 pch_can_bit_set(&priv->regs->if2_cmask, PCH_CMASK_ALL);
1134 /* If ID extended is set. */
1135 pch_can_bit_clear(&priv->regs->if2_id1, 0xffff);
1136 pch_can_bit_clear(&priv->regs->if2_id2, 0x1fff | PCH_ID2_XTD);
1137 if (cf->can_id & CAN_EFF_FLAG) {
1138 pch_can_bit_set(&priv->regs->if2_id1, cf->can_id & 0xffff);
1139 pch_can_bit_set(&priv->regs->if2_id2,
1140 ((cf->can_id >> 16) & 0x1fff) | PCH_ID2_XTD);
1142 pch_can_bit_set(&priv->regs->if2_id1, 0);
1143 pch_can_bit_set(&priv->regs->if2_id2,
1144 (cf->can_id & CAN_SFF_MASK) << 2);
1147 /* If remote frame has to be transmitted.. */
1148 if (cf->can_id & CAN_RTR_FLAG)
1149 pch_can_bit_clear(&priv->regs->if2_id2, PCH_ID2_DIR);
1151 for (i = 0, j = 0; i < cf->can_dlc; j++) {
1152 iowrite32(le32_to_cpu(cf->data[i++]),
1153 (&priv->regs->if2_dataa1) + j*4);
1154 if (i == cf->can_dlc)
1156 iowrite32(le32_to_cpu(cf->data[i++] << 8),
1157 (&priv->regs->if2_dataa1) + j*4);
1160 can_put_echo_skb(skb, ndev, tx_buffer_avail - PCH_RX_OBJ_NUM - 1);
1162 /* Updating the size of the data. */
1163 pch_can_bit_clear(&priv->regs->if2_mcont, 0x0f);
1164 pch_can_bit_set(&priv->regs->if2_mcont, cf->can_dlc);
1166 /* Clearing IntPend, NewDat & TxRqst */
1167 pch_can_bit_clear(&priv->regs->if2_mcont,
1168 PCH_IF_MCONT_NEWDAT | PCH_IF_MCONT_INTPND |
1169 PCH_IF_MCONT_TXRQXT);
1171 /* Setting NewDat, TxRqst bits */
1172 pch_can_bit_set(&priv->regs->if2_mcont,
1173 PCH_IF_MCONT_NEWDAT | PCH_IF_MCONT_TXRQXT);
1175 pch_can_check_if_busy(&priv->regs->if2_creq, tx_buffer_avail);
1177 spin_unlock_irqrestore(&priv->msgif_reg_lock, flags);
1179 return NETDEV_TX_OK;
1182 static const struct net_device_ops pch_can_netdev_ops = {
1183 .ndo_open = pch_can_open,
1184 .ndo_stop = pch_close,
1185 .ndo_start_xmit = pch_xmit,
1188 static void __devexit pch_can_remove(struct pci_dev *pdev)
1190 struct net_device *ndev = pci_get_drvdata(pdev);
1191 struct pch_can_priv *priv = netdev_priv(ndev);
1193 unregister_candev(priv->ndev);
1194 free_candev(priv->ndev);
1195 pci_iounmap(pdev, priv->regs);
1196 pci_release_regions(pdev);
1197 pci_disable_device(pdev);
1198 pci_set_drvdata(pdev, NULL);
1199 pch_can_reset(priv);
1203 static int pch_can_suspend(struct pci_dev *pdev, pm_message_t state)
1205 int i; /* Counter variable. */
1206 int retval; /* Return value. */
1207 u32 buf_stat; /* Variable for reading the transmit buffer status. */
1208 u32 counter = 0xFFFFFF;
1210 struct net_device *dev = pci_get_drvdata(pdev);
1211 struct pch_can_priv *priv = netdev_priv(dev);
1213 /* Stop the CAN controller */
1214 pch_can_set_run_mode(priv, PCH_CAN_STOP);
1216 /* Indicate that we are aboutto/in suspend */
1217 priv->can.state = CAN_STATE_SLEEPING;
1219 /* Waiting for all transmission to complete. */
1221 buf_stat = pch_can_get_buffer_status(priv);
1228 dev_err(&pdev->dev, "%s -> Transmission time out.\n", __func__);
1230 /* Save interrupt configuration and then disable them */
1231 pch_can_get_int_enables(priv, &(priv->int_enables));
1232 pch_can_set_int_enables(priv, PCH_CAN_DISABLE);
1234 /* Save Tx buffer enable state */
1235 for (i = 0; i < PCH_OBJ_NUM; i++) {
1236 if (priv->msg_obj[i] == PCH_MSG_OBJ_TX)
1237 pch_can_get_tx_enable(priv, i + 1,
1238 &(priv->tx_enable[i]));
1241 /* Disable all Transmit buffers */
1242 pch_can_tx_disable_all(priv);
1244 /* Save Rx buffer enable state */
1245 for (i = 0; i < PCH_OBJ_NUM; i++) {
1246 if (priv->msg_obj[i] == PCH_MSG_OBJ_RX) {
1247 pch_can_get_rx_enable(priv, i + 1,
1248 &(priv->rx_enable[i]));
1249 pch_can_get_rx_buffer_link(priv, i + 1,
1250 &(priv->rx_link[i]));
1254 /* Disable all Receive buffers */
1255 pch_can_rx_disable_all(priv);
1256 retval = pci_save_state(pdev);
1258 dev_err(&pdev->dev, "pci_save_state failed.\n");
1260 pci_enable_wake(pdev, PCI_D3hot, 0);
1261 pci_disable_device(pdev);
1262 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1268 static int pch_can_resume(struct pci_dev *pdev)
1270 int i; /* Counter variable. */
1271 int retval; /* Return variable. */
1272 struct net_device *dev = pci_get_drvdata(pdev);
1273 struct pch_can_priv *priv = netdev_priv(dev);
1275 pci_set_power_state(pdev, PCI_D0);
1276 pci_restore_state(pdev);
1277 retval = pci_enable_device(pdev);
1279 dev_err(&pdev->dev, "pci_enable_device failed.\n");
1283 pci_enable_wake(pdev, PCI_D3hot, 0);
1285 priv->can.state = CAN_STATE_ERROR_ACTIVE;
1287 /* Disabling all interrupts. */
1288 pch_can_set_int_enables(priv, PCH_CAN_DISABLE);
1290 /* Setting the CAN device in Stop Mode. */
1291 pch_can_set_run_mode(priv, PCH_CAN_STOP);
1293 /* Configuring the transmit and receive buffers. */
1294 pch_can_config_rx_tx_buffers(priv);
1296 /* Restore the CAN state */
1297 pch_set_bittiming(dev);
1300 pch_can_set_optmode(priv);
1302 /* Enabling the transmit buffer. */
1303 for (i = 0; i < PCH_OBJ_NUM; i++) {
1304 if (priv->msg_obj[i] == PCH_MSG_OBJ_TX) {
1305 pch_can_set_tx_enable(priv, i + 1,
1306 priv->tx_enable[i]);
1310 /* Configuring the receive buffer and enabling them. */
1311 for (i = 0; i < PCH_OBJ_NUM; i++) {
1312 if (priv->msg_obj[i] == PCH_MSG_OBJ_RX) {
1313 /* Restore buffer link */
1314 pch_can_set_rx_buffer_link(priv, i + 1,
1317 /* Restore buffer enables */
1318 pch_can_set_rx_enable(priv, i + 1, priv->rx_enable[i]);
1322 /* Enable CAN Interrupts */
1323 pch_can_set_int_custom(priv);
1325 /* Restore Run Mode */
1326 pch_can_set_run_mode(priv, PCH_CAN_RUN);
1331 #define pch_can_suspend NULL
1332 #define pch_can_resume NULL
1335 static int pch_can_get_berr_counter(const struct net_device *dev,
1336 struct can_berr_counter *bec)
1338 struct pch_can_priv *priv = netdev_priv(dev);
1340 bec->txerr = ioread32(&priv->regs->errc) & PCH_TEC;
1341 bec->rxerr = (ioread32(&priv->regs->errc) & PCH_REC) >> 8;
1346 static int __devinit pch_can_probe(struct pci_dev *pdev,
1347 const struct pci_device_id *id)
1349 struct net_device *ndev;
1350 struct pch_can_priv *priv;
1355 rc = pci_enable_device(pdev);
1357 dev_err(&pdev->dev, "Failed pci_enable_device %d\n", rc);
1358 goto probe_exit_endev;
1361 rc = pci_request_regions(pdev, KBUILD_MODNAME);
1363 dev_err(&pdev->dev, "Failed pci_request_regions %d\n", rc);
1364 goto probe_exit_pcireq;
1367 addr = pci_iomap(pdev, 1, 0);
1370 dev_err(&pdev->dev, "Failed pci_iomap\n");
1371 goto probe_exit_ipmap;
1374 ndev = alloc_candev(sizeof(struct pch_can_priv), PCH_TX_OBJ_NUM);
1377 dev_err(&pdev->dev, "Failed alloc_candev\n");
1378 goto probe_exit_alloc_candev;
1381 priv = netdev_priv(ndev);
1385 priv->can.bittiming_const = &pch_can_bittiming_const;
1386 priv->can.do_set_mode = pch_can_do_set_mode;
1387 priv->can.do_get_berr_counter = pch_can_get_berr_counter;
1388 priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY |
1389 CAN_CTRLMODE_LOOPBACK;
1390 priv->tx_obj = PCH_RX_OBJ_NUM + 1; /* Point head of Tx Obj */
1392 ndev->irq = pdev->irq;
1393 ndev->flags |= IFF_ECHO;
1395 pci_set_drvdata(pdev, ndev);
1396 SET_NETDEV_DEV(ndev, &pdev->dev);
1397 ndev->netdev_ops = &pch_can_netdev_ops;
1399 priv->can.clock.freq = PCH_CAN_CLK; /* Hz */
1400 for (index = 0; index < PCH_RX_OBJ_NUM;)
1401 priv->msg_obj[index++] = PCH_MSG_OBJ_RX;
1403 for (index = index; index < PCH_OBJ_NUM;)
1404 priv->msg_obj[index++] = PCH_MSG_OBJ_TX;
1406 netif_napi_add(ndev, &priv->napi, pch_can_rx_poll, PCH_RX_OBJ_NUM);
1408 rc = register_candev(ndev);
1410 dev_err(&pdev->dev, "Failed register_candev %d\n", rc);
1411 goto probe_exit_reg_candev;
1416 probe_exit_reg_candev:
1418 probe_exit_alloc_candev:
1419 pci_iounmap(pdev, addr);
1421 pci_release_regions(pdev);
1423 pci_disable_device(pdev);
1428 static struct pci_driver pch_can_pci_driver = {
1430 .id_table = pch_pci_tbl,
1431 .probe = pch_can_probe,
1432 .remove = __devexit_p(pch_can_remove),
1433 .suspend = pch_can_suspend,
1434 .resume = pch_can_resume,
1437 static int __init pch_can_pci_init(void)
1439 return pci_register_driver(&pch_can_pci_driver);
1441 module_init(pch_can_pci_init);
1443 static void __exit pch_can_pci_exit(void)
1445 pci_unregister_driver(&pch_can_pci_driver);
1447 module_exit(pch_can_pci_exit);
1449 MODULE_DESCRIPTION("Controller Area Network Driver");
1450 MODULE_LICENSE("GPL v2");
1451 MODULE_VERSION("0.94");