cc770.h revision b440752d5dc9255195bb15152facef093c30fbac
1/* 2 * cc770.h - Bosch CC770 and Intel AN82527 network device driver 3 * 4 * Copyright (C) 2009, 2011 Wolfgang Grandegger <wg@grandegger.com> 5 * 6 * Derived from the old Socket-CAN i82527 driver: 7 * 8 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of Volkswagen nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * Alternatively, provided that this notice is retained in full, this 24 * software may be distributed under the terms of the GNU General 25 * Public License ("GPL") version 2, in which case the provisions of the 26 * GPL apply INSTEAD OF those given above. 27 * 28 * The provided data structures and external interfaces from this code 29 * are not restricted to be used by modules with a GPL compatible license. 30 * 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 42 * DAMAGE. 43 * 44 * Send feedback to <socketcan-users@lists.berlios.de> 45 */ 46 47#ifndef CC770_DEV_H 48#define CC770_DEV_H 49 50#include <linux/can/dev.h> 51 52struct cc770_msgobj { 53 u8 ctrl0; 54 u8 ctrl1; 55 u8 id[4]; 56 u8 config; 57 u8 data[8]; 58 u8 dontuse; /* padding */ 59} __attribute__ ((packed)); 60 61struct cc770_regs { 62 union { 63 struct cc770_msgobj msgobj[16]; /* Message object 1..15 */ 64 struct { 65 u8 control; /* Control Register */ 66 u8 status; /* Status Register */ 67 u8 cpu_interface; /* CPU Interface Register */ 68 u8 dontuse1; 69 u8 high_speed_read[2]; /* High Speed Read */ 70 u8 global_mask_std[2]; /* Standard Global Mask */ 71 u8 global_mask_ext[4]; /* Extended Global Mask */ 72 u8 msg15_mask[4]; /* Message 15 Mask */ 73 u8 dontuse2[15]; 74 u8 clkout; /* Clock Out Register */ 75 u8 dontuse3[15]; 76 u8 bus_config; /* Bus Configuration Register */ 77 u8 dontuse4[15]; 78 u8 bit_timing_0; /* Bit Timing Register byte 0 */ 79 u8 dontuse5[15]; 80 u8 bit_timing_1; /* Bit Timing Register byte 1 */ 81 u8 dontuse6[15]; 82 u8 interrupt; /* Interrupt Register */ 83 u8 dontuse7[15]; 84 u8 rx_error_counter; /* Receive Error Counter */ 85 u8 dontuse8[15]; 86 u8 tx_error_counter; /* Transmit Error Counter */ 87 u8 dontuse9[31]; 88 u8 p1_conf; 89 u8 dontuse10[15]; 90 u8 p2_conf; 91 u8 dontuse11[15]; 92 u8 p1_in; 93 u8 dontuse12[15]; 94 u8 p2_in; 95 u8 dontuse13[15]; 96 u8 p1_out; 97 u8 dontuse14[15]; 98 u8 p2_out; 99 u8 dontuse15[15]; 100 u8 serial_reset_addr; 101 }; 102 }; 103} __attribute__ ((packed)); 104 105/* Control Register (0x00) */ 106#define CTRL_INI 0x01 /* Initialization */ 107#define CTRL_IE 0x02 /* Interrupt Enable */ 108#define CTRL_SIE 0x04 /* Status Interrupt Enable */ 109#define CTRL_EIE 0x08 /* Error Interrupt Enable */ 110#define CTRL_EAF 0x20 /* Enable additional functions */ 111#define CTRL_CCE 0x40 /* Change Configuration Enable */ 112 113/* Status Register (0x01) */ 114#define STAT_LEC_STUFF 0x01 /* Stuff error */ 115#define STAT_LEC_FORM 0x02 /* Form error */ 116#define STAT_LEC_ACK 0x03 /* Acknowledgement error */ 117#define STAT_LEC_BIT1 0x04 /* Bit1 error */ 118#define STAT_LEC_BIT0 0x05 /* Bit0 error */ 119#define STAT_LEC_CRC 0x06 /* CRC error */ 120#define STAT_LEC_MASK 0x07 /* Last Error Code mask */ 121#define STAT_TXOK 0x08 /* Transmit Message Successfully */ 122#define STAT_RXOK 0x10 /* Receive Message Successfully */ 123#define STAT_WAKE 0x20 /* Wake Up Status */ 124#define STAT_WARN 0x40 /* Warning Status */ 125#define STAT_BOFF 0x80 /* Bus Off Status */ 126 127/* CPU Interface Register (0x02) */ 128#define CPUIF_CEN 0x01 /* Clock Out Enable */ 129#define CPUIF_MUX 0x04 /* Multiplex */ 130#define CPUIF_SLP 0x08 /* Sleep */ 131#define CPUIF_PWD 0x10 /* Power Down Mode */ 132#define CPUIF_DMC 0x20 /* Divide Memory Clock */ 133#define CPUIF_DSC 0x40 /* Divide System Clock */ 134#define CPUIF_RST 0x80 /* Hardware Reset Status */ 135 136/* Clock Out Register (0x1f) */ 137#define CLKOUT_CD_MASK 0x0f /* Clock Divider mask */ 138#define CLKOUT_SL_MASK 0x30 /* Slew Rate mask */ 139#define CLKOUT_SL_SHIFT 4 140 141/* Bus Configuration Register (0x2f) */ 142#define BUSCFG_DR0 0x01 /* Disconnect RX0 Input / Select RX input */ 143#define BUSCFG_DR1 0x02 /* Disconnect RX1 Input / Silent mode */ 144#define BUSCFG_DT1 0x08 /* Disconnect TX1 Output */ 145#define BUSCFG_POL 0x20 /* Polarity dominant or recessive */ 146#define BUSCFG_CBY 0x40 /* Input Comparator Bypass */ 147 148/* Message Control Register 0 (Base Address + 0x0) */ 149#define INTPND_RES 0x01 /* No Interrupt pending */ 150#define INTPND_SET 0x02 /* Interrupt pending */ 151#define INTPND_UNC 0x03 152#define RXIE_RES 0x04 /* Receive Interrupt Disable */ 153#define RXIE_SET 0x08 /* Receive Interrupt Enable */ 154#define RXIE_UNC 0x0c 155#define TXIE_RES 0x10 /* Transmit Interrupt Disable */ 156#define TXIE_SET 0x20 /* Transmit Interrupt Enable */ 157#define TXIE_UNC 0x30 158#define MSGVAL_RES 0x40 /* Message Invalid */ 159#define MSGVAL_SET 0x80 /* Message Valid */ 160#define MSGVAL_UNC 0xc0 161 162/* Message Control Register 1 (Base Address + 0x01) */ 163#define NEWDAT_RES 0x01 /* No New Data */ 164#define NEWDAT_SET 0x02 /* New Data */ 165#define NEWDAT_UNC 0x03 166#define MSGLST_RES 0x04 /* No Message Lost */ 167#define MSGLST_SET 0x08 /* Message Lost */ 168#define MSGLST_UNC 0x0c 169#define CPUUPD_RES 0x04 /* No CPU Updating */ 170#define CPUUPD_SET 0x08 /* CPU Updating */ 171#define CPUUPD_UNC 0x0c 172#define TXRQST_RES 0x10 /* No Transmission Request */ 173#define TXRQST_SET 0x20 /* Transmission Request */ 174#define TXRQST_UNC 0x30 175#define RMTPND_RES 0x40 /* No Remote Request Pending */ 176#define RMTPND_SET 0x80 /* Remote Request Pending */ 177#define RMTPND_UNC 0xc0 178 179/* Message Configuration Register (Base Address + 0x06) */ 180#define MSGCFG_XTD 0x04 /* Extended Identifier */ 181#define MSGCFG_DIR 0x08 /* Direction is Transmit */ 182 183#define MSGOBJ_FIRST 1 184#define MSGOBJ_LAST 15 185 186#define CC770_IO_SIZE 0x100 187#define CC770_MAX_IRQ 20 /* max. number of interrupts handled in ISR */ 188 189#define CC770_ECHO_SKB_MAX 1 190 191#define cc770_read_reg(priv, member) \ 192 priv->read_reg(priv, offsetof(struct cc770_regs, member)) 193 194#define cc770_write_reg(priv, member, value) \ 195 priv->write_reg(priv, offsetof(struct cc770_regs, member), value) 196 197/* 198 * Message objects and flags used by this driver 199 */ 200#define CC770_OBJ_FLAG_RX 0x01 201#define CC770_OBJ_FLAG_RTR 0x02 202#define CC770_OBJ_FLAG_EFF 0x04 203 204enum { 205 CC770_OBJ_RX0 = 0, /* for receiving normal messages */ 206 CC770_OBJ_RX1, /* for receiving normal messages */ 207 CC770_OBJ_RX_RTR0, /* for receiving remote transmission requests */ 208 CC770_OBJ_RX_RTR1, /* for receiving remote transmission requests */ 209 CC770_OBJ_TX, /* for sending messages */ 210 CC770_OBJ_MAX 211}; 212 213#define obj2msgobj(o) (MSGOBJ_LAST - (o)) /* message object 11..15 */ 214 215/* 216 * CC770 private data structure 217 */ 218struct cc770_priv { 219 struct can_priv can; /* must be the first member */ 220 int open_time; 221 struct sk_buff *echo_skb; 222 223 /* the lower-layer is responsible for appropriate locking */ 224 u8 (*read_reg)(const struct cc770_priv *priv, int reg); 225 void (*write_reg)(const struct cc770_priv *priv, int reg, u8 val); 226 void (*pre_irq)(const struct cc770_priv *priv); 227 void (*post_irq)(const struct cc770_priv *priv); 228 229 void *priv; /* for board-specific data */ 230 struct net_device *dev; 231 232 void __iomem *reg_base; /* ioremap'ed address to registers */ 233 unsigned long irq_flags; /* for request_irq() */ 234 235 unsigned char obj_flags[CC770_OBJ_MAX]; 236 u8 control_normal_mode; /* Control register for normal mode */ 237 u8 cpu_interface; /* CPU interface register */ 238 u8 clkout; /* Clock out register */ 239 u8 bus_config; /* Bus conffiguration register */ 240}; 241 242struct net_device *alloc_cc770dev(int sizeof_priv); 243void free_cc770dev(struct net_device *dev); 244int register_cc770dev(struct net_device *dev); 245void unregister_cc770dev(struct net_device *dev); 246 247#endif /* CC770_DEV_H */ 248