1/* 2 * Flex CAN Memory Map 3 * 4 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc. 5 * TsiChung Liew (Tsi-Chung.Liew@freescale.com) 6 * 7 * See file CREDITS for list of people who contributed to this 8 * project. 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License as 12 * published by the Free Software Foundation; either version 2 of 13 * the License, or (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 23 * MA 02111-1307 USA 24 */ 25 26#ifndef __FLEXCAN_H__ 27#define __FLEXCAN_H__ 28 29/* FlexCan Message Buffer */ 30typedef struct can_msgbuf_ctrl { 31#ifdef CONFIG_M5282 32 u8 tmstamp; /* 0x00 Timestamp */ 33 u8 ctrl; /* 0x01 Control */ 34 u16 idh; /* 0x02 ID High */ 35 u16 idl; /* 0x04 ID High */ 36 u8 data[8]; /* 0x06 8 Byte Data Field */ 37 u16 res; /* 0x0E */ 38#else 39 u16 ctrl; /* 0x00 Control/Status */ 40 u16 tmstamp; /* 0x02 Timestamp */ 41 u32 id; /* 0x04 Identifier */ 42 u8 data[8]; /* 0x08 8 Byte Data Field */ 43#endif 44} can_msg_t; 45 46#ifdef CONFIG_M5282 47/* MSGBUF CTRL */ 48#define CAN_MSGBUF_CTRL_CODE(x) (((x) & 0x0F) << 4) 49#define CAN_MSGBUF_CTRL_CODE_MASK (0x0F) 50#define CAN_MSGBUF_CTRL_LEN(x) ((x) & 0x0F) 51#define CAN_MSGBUF_CTRL_LEN_MASK (0xF0) 52 53/* MSGBUF ID */ 54#define CAN_MSGBUF_IDH_STD(x) (((x) & 0x07FF) << 5) 55#define CAN_MSGBUF_IDH_STD_MASK (0xE003FFFF) 56#define CAN_MSGBUF_IDH_SRR (0x0010) 57#define CAN_MSGBUF_IDH_IDE (0x0080) 58#define CAN_MSGBUF_IDH_EXTH(x) ((x) & 0x07) 59#define CAN_MSGBUF_IDH_EXTH_MASK (0xFFF8) 60#define CAN_MSGBUF_IDL_EXTL(x) (((x) & 0x7FFF) << 1) 61#define CAN_MSGBUF_IDL_EXTL_MASK (0xFFFE) 62#define CAN_MSGBUF_IDL_RTR (0x0001) 63#else 64/* MSGBUF CTRL */ 65#define CAN_MSGBUF_CTRL_CODE(x) (((x) & 0x000F) << 8) 66#define CAN_MSGBUF_CTRL_CODE_MASK (0xF0FF) 67#define CAN_MSGBUF_CTRL_SRR (0x0040) 68#define CAN_MSGBUF_CTRL_IDE (0x0020) 69#define CAN_MSGBUF_CTRL_RTR (0x0010) 70#define CAN_MSGBUF_CTRL_LEN(x) ((x) & 0x000F) 71#define CAN_MSGBUF_CTRL_LEN_MASK (0xFFF0) 72 73/* MSGBUF ID */ 74#define CAN_MSGBUF_ID_STD(x) (((x) & 0x000007FF) << 18) 75#define CAN_MSGBUF_ID_STD_MASK (0xE003FFFF) 76#define CAN_MSGBUF_ID_EXT(x) ((x) & 0x0003FFFF) 77#define CAN_MSGBUF_ID_EXT_MASK (0xFFFC0000) 78#endif 79 80/* FlexCan module */ 81typedef struct can_ctrl { 82 u32 mcr; /* 0x00 Module Configuration */ 83 u32 ctrl; /* 0x04 Control */ 84 u32 timer; /* 0x08 Free Running Timer */ 85 u32 res1; /* 0x0C */ 86 u32 rxgmsk; /* 0x10 Rx Global Mask */ 87 u32 rx14msk; /* 0x14 RxBuffer 14 Mask */ 88 u32 rx15msk; /* 0x18 RxBuffer 15 Mask */ 89#ifdef CONFIG_M5282 90 u32 res2; /* 0x1C */ 91 u16 errstat; /* 0x20 Error and status */ 92 u16 imsk; /* 0x22 Interrupt Mask */ 93 u16 iflag; /* 0x24 Interrupt Flag */ 94 u16 errcnt; /* 0x26 Error Counter */ 95 u32 res3[3]; /* 0x28 - 0x33 */ 96#else 97 u16 res2; /* 0x1C */ 98 u16 errcnt; /* 0x1E Error Counter */ 99 u16 res3; /* 0x20 */ 100 u16 errstat; /* 0x22 Error and status */ 101 u32 res4; /* 0x24 */ 102 u32 imsk; /* 0x28 Interrupt Mask */ 103 u32 res5; /* 0x2C */ 104 u16 iflag; /* 0x30 Interrupt Flag */ 105#endif 106 u32 res6[19]; /* 0x34 - 0x7F */ 107 void *msgbuf; /* 0x80 Message Buffer 0-15 */ 108} can_t; 109 110/* MCR */ 111#define CAN_MCR_MDIS (0x80000000) 112#define CAN_MCR_FRZ (0x40000000) 113#define CAN_MCR_HALT (0x10000000) 114#define CAN_MCR_NORDY (0x08000000) 115#define CAN_MCF_WAKEMSK (0x04000000) /* 5282 */ 116#define CAN_MCR_SOFTRST (0x02000000) 117#define CAN_MCR_FRZACK (0x01000000) 118#define CAN_MCR_SUPV (0x00800000) 119#define CAN_MCR_SELFWAKE (0x00400000) /* 5282 */ 120#define CAN_MCR_APS (0x00200000) /* 5282 */ 121#define CAN_MCR_LPMACK (0x00100000) 122#define CAN_MCF_BCC (0x00010000) 123#define CAN_MCR_MAXMB(x) ((x) & 0x0F) 124#define CAN_MCR_MAXMB_MASK (0xFFFFFFF0) 125 126/* CTRL */ 127#define CAN_CTRL_PRESDIV(x) (((x) & 0xFF) << 24) 128#define CAN_CTRL_PRESDIV_MASK (0x00FFFFFF) 129#define CAN_CTRL_RJW(x) (((x) & 0x03) << 22) 130#define CAN_CTRL_RJW_MASK (0xFF3FFFFF) 131#define CAN_CTRL_PSEG1(x) (((x) & 0x07) << 19) 132#define CAN_CTRL_PSEG1_MASK (0xFFC7FFFF) 133#define CAN_CTRL_PSEG2(x) (((x) & 0x07) << 16) 134#define CAN_CTRL_PSEG2_MASK (0xFFF8FFFF) 135#define CAN_CTRL_BOFFMSK (0x00008000) 136#define CAN_CTRL_ERRMSK (0x00004000) 137#define CAN_CTRL_CLKSRC (0x00002000) 138#define CAN_CTRL_LPB (0x00001000) 139#define CAN_CTRL_RXMODE (0x00000400) /* 5282 */ 140#define CAN_CTRL_TXMODE(x) (((x) & 0x03) << 8) /* 5282 */ 141#define CAN_CTRL_TXMODE_MASK (0xFFFFFCFF) /* 5282 */ 142#define CAN_CTRL_TXMODE_CAN0 (0x00000000) /* 5282 */ 143#define CAN_CTRL_TXMODE_CAN1 (0x00000100) /* 5282 */ 144#define CAN_CTRL_TXMODE_OPEN (0x00000200) /* 5282 */ 145#define CAN_CTRL_SMP (0x00000080) 146#define CAN_CTRL_BOFFREC (0x00000040) 147#define CAN_CTRL_TSYNC (0x00000020) 148#define CAN_CTRL_LBUF (0x00000010) 149#define CAN_CTRL_LOM (0x00000008) 150#define CAN_CTRL_PROPSEG(x) ((x) & 0x07) 151#define CAN_CTRL_PROPSEG_MASK (0xFFFFFFF8) 152 153/* TIMER */ 154/* Note: PRESDIV, RJW, PSG1, and PSG2 are part of timer in 5282 */ 155#define CAN_TIMER(x) ((x) & 0xFFFF) 156#define CAN_TIMER_MASK (0xFFFF0000) 157 158/* RXGMASK */ 159#ifdef CONFIG_M5282 160#define CAN_RXGMSK_MI_STD(x) (((x) & 0x000007FF) << 21) 161#define CAN_RXGMSK_MI_STD_MASK (0x001FFFFF) 162#define CAN_RXGMSK_MI_EXT(x) (((x) & 0x0003FFFF) << 1) 163#define CAN_RXGMSK_MI_EXT_MASK (0xFFF80001) 164#else 165#define CAN_RXGMSK_MI_STD(x) (((x) & 0x000007FF) << 18) 166#define CAN_RXGMSK_MI_STD_MASK (0xE003FFFF) 167#define CAN_RXGMSK_MI_EXT(x) ((x) & 0x0003FFFF) 168#define CAN_RXGMSK_MI_EXT_MASK (0xFFFC0000) 169#endif 170 171/* ERRCNT */ 172#define CAN_ERRCNT_RXECTR(x) (((x) & 0xFF) << 8) 173#define CAN_ERRCNT_RXECTR_MASK (0x00FF) 174#define CAN_ERRCNT_TXECTR(x) ((x) & 0xFF) 175#define CAN_ERRCNT_TXECTR_MASK (0xFF00) 176 177/* ERRSTAT */ 178#define CAN_ERRSTAT_BITERR1 (0x8000) 179#define CAN_ERRSTAT_BITERR0 (0x4000) 180#define CAN_ERRSTAT_ACKERR (0x2000) 181#define CAN_ERRSTAT_CRCERR (0x1000) 182#define CAN_ERRSTAT_FRMERR (0x0800) 183#define CAN_ERRSTAT_STFERR (0x0400) 184#define CAN_ERRSTAT_TXWRN (0x0200) 185#define CAN_ERRSTAT_RXWRN (0x0100) 186#define CAN_ERRSTAT_IDLE (0x0080) 187#define CAN_ERRSTAT_TXRX (0x0040) 188#define CAN_ERRSTAT_FLT_MASK (0xFFCF) 189#define CAN_ERRSTAT_FLT_BUSOFF (0x0020) 190#define CAN_ERRSTAT_FLT_PASSIVE (0x0010) 191#define CAN_ERRSTAT_FLT_ACTIVE (0x0000) 192#ifdef CONFIG_M5282 193#define CAN_ERRSTAT_BOFFINT (0x0004) 194#define CAN_ERRSTAT_ERRINT (0x0002) 195#else 196#define CAN_ERRSTAT_ERRINT (0x0004) 197#define CAN_ERRSTAT_BOFFINT (0x0002) 198#define CAN_ERRSTAT_WAKEINT (0x0001) 199#endif 200 201/* IMASK */ 202#ifdef CONFIG_M5253 203#define CAN_IMASK_BUFnM(x) (1 << (x & 0xFFFFFFFF)) 204#define CAN_IMASK_BUFnM_MASKBIT(x) ~CAN_IMASK_BUFnM(x) 205#else 206#define CAN_IMASK_BUFnM(x) (1 << (x & 0xFFFF)) 207#define CAN_IMASK_BUFnM_MASKBIT(x) ~CAN_IMASK_BUFnM(x) 208#endif 209 210/* IFLAG */ 211#ifdef CONFIG_M5253 212#define CAN_IFLAG_BUFnM(x) (1 << (x & 0xFFFFFFFF)) 213#define CAN_IFLAG_BUFnM_MASKBIT(x) ~CAN_IFLAG_BUFnM(x) 214#else 215#define CAN_IFLAG_BUFnM(x) (1 << (x & 0xFFFF)) 216#define CAN_IFLAG_BUFnM_MASKBIT(x) ~CAN_IFLAG_BUFnM(x) 217#endif 218 219#endif /* __FLEXCAN_H__ */ 220