1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * sja1000.h - Philips SJA1000 network device driver 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Copyright (c) 2003 Matthias Brukner, Trajet Gmbh, Rebenring 33, 5*4882a593Smuzhiyun * 38106 Braunschweig, GERMANY 6*4882a593Smuzhiyun * 7*4882a593Smuzhiyun * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 8*4882a593Smuzhiyun * All rights reserved. 9*4882a593Smuzhiyun * 10*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without 11*4882a593Smuzhiyun * modification, are permitted provided that the following conditions 12*4882a593Smuzhiyun * are met: 13*4882a593Smuzhiyun * 1. Redistributions of source code must retain the above copyright 14*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer. 15*4882a593Smuzhiyun * 2. Redistributions in binary form must reproduce the above copyright 16*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in the 17*4882a593Smuzhiyun * documentation and/or other materials provided with the distribution. 18*4882a593Smuzhiyun * 3. Neither the name of Volkswagen nor the names of its contributors 19*4882a593Smuzhiyun * may be used to endorse or promote products derived from this software 20*4882a593Smuzhiyun * without specific prior written permission. 21*4882a593Smuzhiyun * 22*4882a593Smuzhiyun * Alternatively, provided that this notice is retained in full, this 23*4882a593Smuzhiyun * software may be distributed under the terms of the GNU General 24*4882a593Smuzhiyun * Public License ("GPL") version 2, in which case the provisions of the 25*4882a593Smuzhiyun * GPL apply INSTEAD OF those given above. 26*4882a593Smuzhiyun * 27*4882a593Smuzhiyun * The provided data structures and external interfaces from this code 28*4882a593Smuzhiyun * are not restricted to be used by modules with a GPL compatible license. 29*4882a593Smuzhiyun * 30*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 31*4882a593Smuzhiyun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 32*4882a593Smuzhiyun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 33*4882a593Smuzhiyun * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 34*4882a593Smuzhiyun * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35*4882a593Smuzhiyun * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 36*4882a593Smuzhiyun * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37*4882a593Smuzhiyun * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38*4882a593Smuzhiyun * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40*4882a593Smuzhiyun * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 41*4882a593Smuzhiyun * DAMAGE. 42*4882a593Smuzhiyun * 43*4882a593Smuzhiyun */ 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun #ifndef SJA1000_DEV_H 46*4882a593Smuzhiyun #define SJA1000_DEV_H 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun #include <linux/irqreturn.h> 49*4882a593Smuzhiyun #include <linux/can/dev.h> 50*4882a593Smuzhiyun #include <linux/can/platform/sja1000.h> 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun #define SJA1000_ECHO_SKB_MAX 1 /* the SJA1000 has one TX buffer object */ 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun #define SJA1000_MAX_IRQ 20 /* max. number of interrupts handled in ISR */ 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun /* SJA1000 registers - manual section 6.4 (Pelican Mode) */ 57*4882a593Smuzhiyun #define SJA1000_MOD 0x00 58*4882a593Smuzhiyun #define SJA1000_CMR 0x01 59*4882a593Smuzhiyun #define SJA1000_SR 0x02 60*4882a593Smuzhiyun #define SJA1000_IR 0x03 61*4882a593Smuzhiyun #define SJA1000_IER 0x04 62*4882a593Smuzhiyun #define SJA1000_ALC 0x0B 63*4882a593Smuzhiyun #define SJA1000_ECC 0x0C 64*4882a593Smuzhiyun #define SJA1000_EWL 0x0D 65*4882a593Smuzhiyun #define SJA1000_RXERR 0x0E 66*4882a593Smuzhiyun #define SJA1000_TXERR 0x0F 67*4882a593Smuzhiyun #define SJA1000_ACCC0 0x10 68*4882a593Smuzhiyun #define SJA1000_ACCC1 0x11 69*4882a593Smuzhiyun #define SJA1000_ACCC2 0x12 70*4882a593Smuzhiyun #define SJA1000_ACCC3 0x13 71*4882a593Smuzhiyun #define SJA1000_ACCM0 0x14 72*4882a593Smuzhiyun #define SJA1000_ACCM1 0x15 73*4882a593Smuzhiyun #define SJA1000_ACCM2 0x16 74*4882a593Smuzhiyun #define SJA1000_ACCM3 0x17 75*4882a593Smuzhiyun #define SJA1000_RMC 0x1D 76*4882a593Smuzhiyun #define SJA1000_RBSA 0x1E 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun /* Common registers - manual section 6.5 */ 79*4882a593Smuzhiyun #define SJA1000_BTR0 0x06 80*4882a593Smuzhiyun #define SJA1000_BTR1 0x07 81*4882a593Smuzhiyun #define SJA1000_OCR 0x08 82*4882a593Smuzhiyun #define SJA1000_CDR 0x1F 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun #define SJA1000_FI 0x10 85*4882a593Smuzhiyun #define SJA1000_SFF_BUF 0x13 86*4882a593Smuzhiyun #define SJA1000_EFF_BUF 0x15 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun #define SJA1000_FI_FF 0x80 89*4882a593Smuzhiyun #define SJA1000_FI_RTR 0x40 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun #define SJA1000_ID1 0x11 92*4882a593Smuzhiyun #define SJA1000_ID2 0x12 93*4882a593Smuzhiyun #define SJA1000_ID3 0x13 94*4882a593Smuzhiyun #define SJA1000_ID4 0x14 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun #define SJA1000_CAN_RAM 0x20 97*4882a593Smuzhiyun 98*4882a593Smuzhiyun /* mode register */ 99*4882a593Smuzhiyun #define MOD_RM 0x01 100*4882a593Smuzhiyun #define MOD_LOM 0x02 101*4882a593Smuzhiyun #define MOD_STM 0x04 102*4882a593Smuzhiyun #define MOD_AFM 0x08 103*4882a593Smuzhiyun #define MOD_SM 0x10 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun /* commands */ 106*4882a593Smuzhiyun #define CMD_SRR 0x10 107*4882a593Smuzhiyun #define CMD_CDO 0x08 108*4882a593Smuzhiyun #define CMD_RRB 0x04 109*4882a593Smuzhiyun #define CMD_AT 0x02 110*4882a593Smuzhiyun #define CMD_TR 0x01 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun /* interrupt sources */ 113*4882a593Smuzhiyun #define IRQ_BEI 0x80 114*4882a593Smuzhiyun #define IRQ_ALI 0x40 115*4882a593Smuzhiyun #define IRQ_EPI 0x20 116*4882a593Smuzhiyun #define IRQ_WUI 0x10 117*4882a593Smuzhiyun #define IRQ_DOI 0x08 118*4882a593Smuzhiyun #define IRQ_EI 0x04 119*4882a593Smuzhiyun #define IRQ_TI 0x02 120*4882a593Smuzhiyun #define IRQ_RI 0x01 121*4882a593Smuzhiyun #define IRQ_ALL 0xFF 122*4882a593Smuzhiyun #define IRQ_OFF 0x00 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun /* status register content */ 125*4882a593Smuzhiyun #define SR_BS 0x80 126*4882a593Smuzhiyun #define SR_ES 0x40 127*4882a593Smuzhiyun #define SR_TS 0x20 128*4882a593Smuzhiyun #define SR_RS 0x10 129*4882a593Smuzhiyun #define SR_TCS 0x08 130*4882a593Smuzhiyun #define SR_TBS 0x04 131*4882a593Smuzhiyun #define SR_DOS 0x02 132*4882a593Smuzhiyun #define SR_RBS 0x01 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun #define SR_CRIT (SR_BS|SR_ES) 135*4882a593Smuzhiyun 136*4882a593Smuzhiyun /* ECC register */ 137*4882a593Smuzhiyun #define ECC_SEG 0x1F 138*4882a593Smuzhiyun #define ECC_DIR 0x20 139*4882a593Smuzhiyun #define ECC_ERR 6 140*4882a593Smuzhiyun #define ECC_BIT 0x00 141*4882a593Smuzhiyun #define ECC_FORM 0x40 142*4882a593Smuzhiyun #define ECC_STUFF 0x80 143*4882a593Smuzhiyun #define ECC_MASK 0xc0 144*4882a593Smuzhiyun 145*4882a593Smuzhiyun /* 146*4882a593Smuzhiyun * Flags for sja1000priv.flags 147*4882a593Smuzhiyun */ 148*4882a593Smuzhiyun #define SJA1000_CUSTOM_IRQ_HANDLER 0x1 149*4882a593Smuzhiyun 150*4882a593Smuzhiyun /* 151*4882a593Smuzhiyun * SJA1000 private data structure 152*4882a593Smuzhiyun */ 153*4882a593Smuzhiyun struct sja1000_priv { 154*4882a593Smuzhiyun struct can_priv can; /* must be the first member */ 155*4882a593Smuzhiyun struct sk_buff *echo_skb; 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun /* the lower-layer is responsible for appropriate locking */ 158*4882a593Smuzhiyun u8 (*read_reg) (const struct sja1000_priv *priv, int reg); 159*4882a593Smuzhiyun void (*write_reg) (const struct sja1000_priv *priv, int reg, u8 val); 160*4882a593Smuzhiyun void (*pre_irq) (const struct sja1000_priv *priv); 161*4882a593Smuzhiyun void (*post_irq) (const struct sja1000_priv *priv); 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun void *priv; /* for board-specific data */ 164*4882a593Smuzhiyun struct net_device *dev; 165*4882a593Smuzhiyun 166*4882a593Smuzhiyun void __iomem *reg_base; /* ioremap'ed address to registers */ 167*4882a593Smuzhiyun unsigned long irq_flags; /* for request_irq() */ 168*4882a593Smuzhiyun spinlock_t cmdreg_lock; /* lock for concurrent cmd register writes */ 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun u16 flags; /* custom mode flags */ 171*4882a593Smuzhiyun u8 ocr; /* output control register */ 172*4882a593Smuzhiyun u8 cdr; /* clock divider register */ 173*4882a593Smuzhiyun }; 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun struct net_device *alloc_sja1000dev(int sizeof_priv); 176*4882a593Smuzhiyun void free_sja1000dev(struct net_device *dev); 177*4882a593Smuzhiyun int register_sja1000dev(struct net_device *dev); 178*4882a593Smuzhiyun void unregister_sja1000dev(struct net_device *dev); 179*4882a593Smuzhiyun 180*4882a593Smuzhiyun irqreturn_t sja1000_interrupt(int irq, void *dev_id); 181*4882a593Smuzhiyun 182*4882a593Smuzhiyun #endif /* SJA1000_DEV_H */ 183