/*
* Copyright (C) 1999 - 2010 Intel Corporation.
* Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/can.h>
#include <linux/can/dev.h>
#include <linux/can/error.h>
#define MAX_MSG_OBJ 32
#define MSG_OBJ_RX 0 /* The receive message object flag. */
#define MSG_OBJ_TX 1 /* The transmit message object flag. */
#define ENABLE 1 /* The enable flag */
#define DISABLE 0 /* The disable flag */
#define CAN_CTRL_INIT 0x0001 /* The INIT bit of CANCONT register. */
#define CAN_CTRL_IE 0x0002 /* The IE bit of CAN control register */
#define CAN_CTRL_IE_SIE_EIE 0x000e
#define CAN_CTRL_CCE 0x0040
#define CAN_CTRL_OPT 0x0080 /* The OPT bit of CANCONT register. */
#define CAN_OPT_SILENT 0x0008 /* The Silent bit of CANOPT reg. */
#define CAN_OPT_LBACK 0x0010 /* The LoopBack bit of CANOPT reg. */
#define CAN_CMASK_RX_TX_SET 0x00f3
#define CAN_CMASK_RX_TX_GET 0x0073
#define CAN_CMASK_ALL 0xff
#define CAN_CMASK_RDWR 0x80
#define CAN_CMASK_ARB 0x20
#define CAN_CMASK_CTRL 0x10
#define CAN_CMASK_MASK 0x40
#define CAN_CMASK_NEWDAT 0x04
#define CAN_CMASK_CLRINTPND 0x08
#define CAN_IF_MCONT_NEWDAT 0x8000
#define CAN_IF_MCONT_INTPND 0x2000
#define CAN_IF_MCONT_UMASK 0x1000
#define CAN_IF_MCONT_TXIE 0x0800
#define CAN_IF_MCONT_RXIE 0x0400
#define CAN_IF_MCONT_RMTEN 0x0200
#define CAN_IF_MCONT_TXRQXT 0x0100
#define CAN_IF_MCONT_EOB 0x0080
#define CAN_IF_MCONT_DLC 0x000f
#define CAN_IF_MCONT_MSGLOST 0x4000
#define CAN_MASK2_MDIR_MXTD 0xc000
#define CAN_ID2_DIR 0x2000
#define CAN_ID_MSGVAL 0x8000
#define CAN_STATUS_INT 0x8000
#define CAN_IF_CREQ_BUSY 0x8000
#define CAN_ID2_XTD 0x4000
#define CAN_REC 0x00007f00
#define CAN_TEC 0x000000ff
#define PCH_RX_OK 0x00000010
#define PCH_TX_OK 0x00000008
#define PCH_BUS_OFF 0x00000080
#define PCH_EWARN 0x00000040
#define PCH_EPASSIV 0x00000020
#define PCH_LEC0 0x00000001
#define PCH_LEC1 0x00000002
#define PCH_LEC2 0x00000004
#define PCH_LEC_ALL (PCH_LEC0 | PCH_LEC1 | PCH_LEC2)
#define PCH_STUF_ERR PCH_LEC0
#define PCH_FORM_ERR PCH_LEC1
#define PCH_ACK_ERR (PCH_LEC0 | PCH_LEC1)
#define PCH_BIT1_ERR PCH_LEC2
#define PCH_BIT0_ERR (PCH_LEC0 |