185 lines · c
1/*2 * sja1000.h - Philips SJA1000 network device driver3 *4 * Copyright (c) 2003 Matthias Brukner, Trajet Gmbh, Rebenring 33,5 * 38106 Braunschweig, GERMANY6 *7 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research8 * All rights reserved.9 *10 * Redistribution and use in source and binary forms, with or without11 * modification, are permitted provided that the following conditions12 * are met:13 * 1. Redistributions of source code must retain the above copyright14 * notice, this list of conditions and the following disclaimer.15 * 2. Redistributions in binary form must reproduce the above copyright16 * notice, this list of conditions and the following disclaimer in the17 * documentation and/or other materials provided with the distribution.18 * 3. Neither the name of Volkswagen nor the names of its contributors19 * may be used to endorse or promote products derived from this software20 * without specific prior written permission.21 *22 * Alternatively, provided that this notice is retained in full, this23 * software may be distributed under the terms of the GNU General24 * Public License ("GPL") version 2, in which case the provisions of the25 * GPL apply INSTEAD OF those given above.26 *27 * The provided data structures and external interfaces from this code28 * are not restricted to be used by modules with a GPL compatible license.29 *30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH41 * DAMAGE.42 *43 */44 45#ifndef SJA1000_DEV_H46#define SJA1000_DEV_H47 48#include <linux/irqreturn.h>49#include <linux/can/dev.h>50#include <linux/can/platform/sja1000.h>51 52#define SJA1000_ECHO_SKB_MAX 1 /* the SJA1000 has one TX buffer object */53 54#define SJA1000_MAX_IRQ 20 /* max. number of interrupts handled in ISR */55 56/* SJA1000 registers - manual section 6.4 (Pelican Mode) */57#define SJA1000_MOD 0x0058#define SJA1000_CMR 0x0159#define SJA1000_SR 0x0260#define SJA1000_IR 0x0361#define SJA1000_IER 0x0462#define SJA1000_ALC 0x0B63#define SJA1000_ECC 0x0C64#define SJA1000_EWL 0x0D65#define SJA1000_RXERR 0x0E66#define SJA1000_TXERR 0x0F67#define SJA1000_ACCC0 0x1068#define SJA1000_ACCC1 0x1169#define SJA1000_ACCC2 0x1270#define SJA1000_ACCC3 0x1371#define SJA1000_ACCM0 0x1472#define SJA1000_ACCM1 0x1573#define SJA1000_ACCM2 0x1674#define SJA1000_ACCM3 0x1775#define SJA1000_RMC 0x1D76#define SJA1000_RBSA 0x1E77 78/* Common registers - manual section 6.5 */79#define SJA1000_BTR0 0x0680#define SJA1000_BTR1 0x0781#define SJA1000_OCR 0x0882#define SJA1000_CDR 0x1F83 84#define SJA1000_FI 0x1085#define SJA1000_SFF_BUF 0x1386#define SJA1000_EFF_BUF 0x1587 88#define SJA1000_FI_FF 0x8089#define SJA1000_FI_RTR 0x4090 91#define SJA1000_ID1 0x1192#define SJA1000_ID2 0x1293#define SJA1000_ID3 0x1394#define SJA1000_ID4 0x1495 96#define SJA1000_CAN_RAM 0x2097 98/* mode register */99#define MOD_RM 0x01100#define MOD_LOM 0x02101#define MOD_STM 0x04102#define MOD_AFM 0x08103#define MOD_SM 0x10104 105/* commands */106#define CMD_SRR 0x10107#define CMD_CDO 0x08108#define CMD_RRB 0x04109#define CMD_AT 0x02110#define CMD_TR 0x01111 112/* interrupt sources */113#define IRQ_BEI 0x80114#define IRQ_ALI 0x40115#define IRQ_EPI 0x20116#define IRQ_WUI 0x10117#define IRQ_DOI 0x08118#define IRQ_EI 0x04119#define IRQ_TI 0x02120#define IRQ_RI 0x01121#define IRQ_ALL 0xFF122#define IRQ_OFF 0x00123 124/* status register content */125#define SR_BS 0x80126#define SR_ES 0x40127#define SR_TS 0x20128#define SR_RS 0x10129#define SR_TCS 0x08130#define SR_TBS 0x04131#define SR_DOS 0x02132#define SR_RBS 0x01133 134#define SR_CRIT (SR_BS|SR_ES)135 136/* ECC register */137#define ECC_SEG 0x1F138#define ECC_DIR 0x20139#define ECC_ERR 6140#define ECC_BIT 0x00141#define ECC_FORM 0x40142#define ECC_STUFF 0x80143#define ECC_MASK 0xc0144 145/*146 * Flags for sja1000priv.flags147 */148#define SJA1000_CUSTOM_IRQ_HANDLER BIT(0)149#define SJA1000_QUIRK_NO_CDR_REG BIT(1)150#define SJA1000_QUIRK_RESET_ON_OVERRUN BIT(2)151 152/*153 * SJA1000 private data structure154 */155struct sja1000_priv {156 struct can_priv can; /* must be the first member */157 struct sk_buff *echo_skb;158 159 /* the lower-layer is responsible for appropriate locking */160 u8 (*read_reg) (const struct sja1000_priv *priv, int reg);161 void (*write_reg) (const struct sja1000_priv *priv, int reg, u8 val);162 void (*pre_irq) (const struct sja1000_priv *priv);163 void (*post_irq) (const struct sja1000_priv *priv);164 165 void *priv; /* for board-specific data */166 struct net_device *dev;167 168 void __iomem *reg_base; /* ioremap'ed address to registers */169 unsigned long irq_flags; /* for request_irq() */170 spinlock_t cmdreg_lock; /* lock for concurrent cmd register writes */171 172 u16 flags; /* custom mode flags */173 u8 ocr; /* output control register */174 u8 cdr; /* clock divider register */175};176 177struct net_device *alloc_sja1000dev(int sizeof_priv);178void free_sja1000dev(struct net_device *dev);179int register_sja1000dev(struct net_device *dev);180void unregister_sja1000dev(struct net_device *dev);181 182irqreturn_t sja1000_interrupt(int irq, void *dev_id);183 184#endif /* SJA1000_DEV_H */185