Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions
mcp251x.c File Reference
#include <linux/can/core.h>
#include <linux/can/dev.h>
#include <linux/can/platform/mcp251x.h>
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/freezer.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/spi/spi.h>
#include <linux/uaccess.h>

Go to the source code of this file.

Data Structures

struct  mcp251x_priv
 

Macros

#define INSTRUCTION_WRITE   0x02
 
#define INSTRUCTION_READ   0x03
 
#define INSTRUCTION_BIT_MODIFY   0x05
 
#define INSTRUCTION_LOAD_TXB(n)   (0x40 + 2 * (n))
 
#define INSTRUCTION_READ_RXB(n)   (((n) == 0) ? 0x90 : 0x94)
 
#define INSTRUCTION_RESET   0xC0
 
#define RTS_TXB0   0x01
 
#define RTS_TXB1   0x02
 
#define RTS_TXB2   0x04
 
#define INSTRUCTION_RTS(n)   (0x80 | ((n) & 0x07))
 
#define CANSTAT   0x0e
 
#define CANCTRL   0x0f
 
#define CANCTRL_REQOP_MASK   0xe0
 
#define CANCTRL_REQOP_CONF   0x80
 
#define CANCTRL_REQOP_LISTEN_ONLY   0x60
 
#define CANCTRL_REQOP_LOOPBACK   0x40
 
#define CANCTRL_REQOP_SLEEP   0x20
 
#define CANCTRL_REQOP_NORMAL   0x00
 
#define CANCTRL_OSM   0x08
 
#define CANCTRL_ABAT   0x10
 
#define TEC   0x1c
 
#define REC   0x1d
 
#define CNF1   0x2a
 
#define CNF1_SJW_SHIFT   6
 
#define CNF2   0x29
 
#define CNF2_BTLMODE   0x80
 
#define CNF2_SAM   0x40
 
#define CNF2_PS1_SHIFT   3
 
#define CNF3   0x28
 
#define CNF3_SOF   0x08
 
#define CNF3_WAKFIL   0x04
 
#define CNF3_PHSEG2_MASK   0x07
 
#define CANINTE   0x2b
 
#define CANINTE_MERRE   0x80
 
#define CANINTE_WAKIE   0x40
 
#define CANINTE_ERRIE   0x20
 
#define CANINTE_TX2IE   0x10
 
#define CANINTE_TX1IE   0x08
 
#define CANINTE_TX0IE   0x04
 
#define CANINTE_RX1IE   0x02
 
#define CANINTE_RX0IE   0x01
 
#define CANINTF   0x2c
 
#define CANINTF_MERRF   0x80
 
#define CANINTF_WAKIF   0x40
 
#define CANINTF_ERRIF   0x20
 
#define CANINTF_TX2IF   0x10
 
#define CANINTF_TX1IF   0x08
 
#define CANINTF_TX0IF   0x04
 
#define CANINTF_RX1IF   0x02
 
#define CANINTF_RX0IF   0x01
 
#define CANINTF_RX   (CANINTF_RX0IF | CANINTF_RX1IF)
 
#define CANINTF_TX   (CANINTF_TX2IF | CANINTF_TX1IF | CANINTF_TX0IF)
 
#define CANINTF_ERR   (CANINTF_ERRIF)
 
#define EFLG   0x2d
 
#define EFLG_EWARN   0x01
 
#define EFLG_RXWAR   0x02
 
#define EFLG_TXWAR   0x04
 
#define EFLG_RXEP   0x08
 
#define EFLG_TXEP   0x10
 
#define EFLG_TXBO   0x20
 
#define EFLG_RX0OVR   0x40
 
#define EFLG_RX1OVR   0x80
 
#define TXBCTRL(n)   (((n) * 0x10) + 0x30 + TXBCTRL_OFF)
 
#define TXBCTRL_ABTF   0x40
 
#define TXBCTRL_MLOA   0x20
 
#define TXBCTRL_TXERR   0x10
 
#define TXBCTRL_TXREQ   0x08
 
#define TXBSIDH(n)   (((n) * 0x10) + 0x30 + TXBSIDH_OFF)
 
#define SIDH_SHIFT   3
 
#define TXBSIDL(n)   (((n) * 0x10) + 0x30 + TXBSIDL_OFF)
 
#define SIDL_SID_MASK   7
 
#define SIDL_SID_SHIFT   5
 
#define SIDL_EXIDE_SHIFT   3
 
#define SIDL_EID_SHIFT   16
 
#define SIDL_EID_MASK   3
 
#define TXBEID8(n)   (((n) * 0x10) + 0x30 + TXBEID8_OFF)
 
#define TXBEID0(n)   (((n) * 0x10) + 0x30 + TXBEID0_OFF)
 
#define TXBDLC(n)   (((n) * 0x10) + 0x30 + TXBDLC_OFF)
 
#define DLC_RTR_SHIFT   6
 
#define TXBCTRL_OFF   0
 
#define TXBSIDH_OFF   1
 
#define TXBSIDL_OFF   2
 
#define TXBEID8_OFF   3
 
#define TXBEID0_OFF   4
 
#define TXBDLC_OFF   5
 
#define TXBDAT_OFF   6
 
#define RXBCTRL(n)   (((n) * 0x10) + 0x60 + RXBCTRL_OFF)
 
#define RXBCTRL_BUKT   0x04
 
#define RXBCTRL_RXM0   0x20
 
#define RXBCTRL_RXM1   0x40
 
#define RXBSIDH(n)   (((n) * 0x10) + 0x60 + RXBSIDH_OFF)
 
#define RXBSIDH_SHIFT   3
 
#define RXBSIDL(n)   (((n) * 0x10) + 0x60 + RXBSIDL_OFF)
 
#define RXBSIDL_IDE   0x08
 
#define RXBSIDL_SRR   0x10
 
#define RXBSIDL_EID   3
 
#define RXBSIDL_SHIFT   5
 
#define RXBEID8(n)   (((n) * 0x10) + 0x60 + RXBEID8_OFF)
 
#define RXBEID0(n)   (((n) * 0x10) + 0x60 + RXBEID0_OFF)
 
#define RXBDLC(n)   (((n) * 0x10) + 0x60 + RXBDLC_OFF)
 
#define RXBDLC_LEN_MASK   0x0f
 
#define RXBDLC_RTR   0x40
 
#define RXBCTRL_OFF   0
 
#define RXBSIDH_OFF   1
 
#define RXBSIDL_OFF   2
 
#define RXBEID8_OFF   3
 
#define RXBEID0_OFF   4
 
#define RXBDLC_OFF   5
 
#define RXBDAT_OFF   6
 
#define RXFSIDH(n)   ((n) * 4)
 
#define RXFSIDL(n)   ((n) * 4 + 1)
 
#define RXFEID8(n)   ((n) * 4 + 2)
 
#define RXFEID0(n)   ((n) * 4 + 3)
 
#define RXMSIDH(n)   ((n) * 4 + 0x20)
 
#define RXMSIDL(n)   ((n) * 4 + 0x21)
 
#define RXMEID8(n)   ((n) * 4 + 0x22)
 
#define RXMEID0(n)   ((n) * 4 + 0x23)
 
#define GET_BYTE(val, byte)   (((val) >> ((byte) * 8)) & 0xff)
 
#define SET_BYTE(val, byte)   (((val) & 0xff) << ((byte) * 8))
 
#define CAN_FRAME_MAX_DATA_LEN   8
 
#define SPI_TRANSFER_BUF_LEN   (6 + CAN_FRAME_MAX_DATA_LEN)
 
#define CAN_FRAME_MAX_BITS   128
 
#define TX_ECHO_SKB_MAX   1
 
#define DEVICE_NAME   "mcp251x"
 
#define AFTER_SUSPEND_UP   1
 
#define AFTER_SUSPEND_DOWN   2
 
#define AFTER_SUSPEND_POWER   4
 
#define AFTER_SUSPEND_RESTART   8
 
#define MCP251X_IS(_model)
 
#define mcp251x_can_suspend   NULL
 
#define mcp251x_can_resume   NULL
 

Enumerations

enum  mcp251x_model { CAN_MCP251X_MCP2510 = 0x2510, CAN_MCP251X_MCP2515 = 0x2515 }
 

Functions

 module_param (mcp251x_enable_dma, int, S_IRUGO)
 
 MODULE_PARM_DESC (mcp251x_enable_dma,"Enable SPI DMA. Default: 0 (Off)")
 
 MCP251X_IS (2510)
 
 MCP251X_IS (2515)
 
 MODULE_DEVICE_TABLE (spi, mcp251x_id_table)
 
 module_init (mcp251x_can_init)
 
 module_exit (mcp251x_can_exit)
 
 MODULE_AUTHOR ("Chris Elston <[email protected]>, ""Christian Pellegrin <[email protected]>")
 
 MODULE_DESCRIPTION ("Microchip 251x CAN driver")
 
 MODULE_LICENSE ("GPL v2")
 

Macro Definition Documentation

#define AFTER_SUSPEND_DOWN   2

Definition at line 262 of file mcp251x.c.

#define AFTER_SUSPEND_POWER   4

Definition at line 263 of file mcp251x.c.

#define AFTER_SUSPEND_RESTART   8

Definition at line 264 of file mcp251x.c.

#define AFTER_SUSPEND_UP   1

Definition at line 261 of file mcp251x.c.

#define CAN_FRAME_MAX_BITS   128

Definition at line 212 of file mcp251x.c.

#define CAN_FRAME_MAX_DATA_LEN   8

Definition at line 210 of file mcp251x.c.

#define CANCTRL   0x0f

Definition at line 94 of file mcp251x.c.

#define CANCTRL_ABAT   0x10

Definition at line 102 of file mcp251x.c.

#define CANCTRL_OSM   0x08

Definition at line 101 of file mcp251x.c.

#define CANCTRL_REQOP_CONF   0x80

Definition at line 96 of file mcp251x.c.

#define CANCTRL_REQOP_LISTEN_ONLY   0x60

Definition at line 97 of file mcp251x.c.

#define CANCTRL_REQOP_LOOPBACK   0x40

Definition at line 98 of file mcp251x.c.

#define CANCTRL_REQOP_MASK   0xe0

Definition at line 95 of file mcp251x.c.

#define CANCTRL_REQOP_NORMAL   0x00

Definition at line 100 of file mcp251x.c.

#define CANCTRL_REQOP_SLEEP   0x20

Definition at line 99 of file mcp251x.c.

#define CANINTE   0x2b

Definition at line 115 of file mcp251x.c.

#define CANINTE_ERRIE   0x20

Definition at line 118 of file mcp251x.c.

#define CANINTE_MERRE   0x80

Definition at line 116 of file mcp251x.c.

#define CANINTE_RX0IE   0x01

Definition at line 123 of file mcp251x.c.

#define CANINTE_RX1IE   0x02

Definition at line 122 of file mcp251x.c.

#define CANINTE_TX0IE   0x04

Definition at line 121 of file mcp251x.c.

#define CANINTE_TX1IE   0x08

Definition at line 120 of file mcp251x.c.

#define CANINTE_TX2IE   0x10

Definition at line 119 of file mcp251x.c.

#define CANINTE_WAKIE   0x40

Definition at line 117 of file mcp251x.c.

#define CANINTF   0x2c

Definition at line 124 of file mcp251x.c.

#define CANINTF_ERR   (CANINTF_ERRIF)

Definition at line 135 of file mcp251x.c.

#define CANINTF_ERRIF   0x20

Definition at line 127 of file mcp251x.c.

#define CANINTF_MERRF   0x80

Definition at line 125 of file mcp251x.c.

#define CANINTF_RX   (CANINTF_RX0IF | CANINTF_RX1IF)

Definition at line 133 of file mcp251x.c.

#define CANINTF_RX0IF   0x01

Definition at line 132 of file mcp251x.c.

#define CANINTF_RX1IF   0x02

Definition at line 131 of file mcp251x.c.

#define CANINTF_TX   (CANINTF_TX2IF | CANINTF_TX1IF | CANINTF_TX0IF)

Definition at line 134 of file mcp251x.c.

#define CANINTF_TX0IF   0x04

Definition at line 130 of file mcp251x.c.

#define CANINTF_TX1IF   0x08

Definition at line 129 of file mcp251x.c.

#define CANINTF_TX2IF   0x10

Definition at line 128 of file mcp251x.c.

#define CANINTF_WAKIF   0x40

Definition at line 126 of file mcp251x.c.

#define CANSTAT   0x0e

Definition at line 93 of file mcp251x.c.

#define CNF1   0x2a

Definition at line 105 of file mcp251x.c.

#define CNF1_SJW_SHIFT   6

Definition at line 106 of file mcp251x.c.

#define CNF2   0x29

Definition at line 107 of file mcp251x.c.

#define CNF2_BTLMODE   0x80

Definition at line 108 of file mcp251x.c.

#define CNF2_PS1_SHIFT   3

Definition at line 110 of file mcp251x.c.

#define CNF2_SAM   0x40

Definition at line 109 of file mcp251x.c.

#define CNF3   0x28

Definition at line 111 of file mcp251x.c.

#define CNF3_PHSEG2_MASK   0x07

Definition at line 114 of file mcp251x.c.

#define CNF3_SOF   0x08

Definition at line 112 of file mcp251x.c.

#define CNF3_WAKFIL   0x04

Definition at line 113 of file mcp251x.c.

#define DEVICE_NAME   "mcp251x"

Definition at line 216 of file mcp251x.c.

#define DLC_RTR_SHIFT   6

Definition at line 161 of file mcp251x.c.

#define EFLG   0x2d

Definition at line 136 of file mcp251x.c.

#define EFLG_EWARN   0x01

Definition at line 137 of file mcp251x.c.

#define EFLG_RX0OVR   0x40

Definition at line 143 of file mcp251x.c.

#define EFLG_RX1OVR   0x80

Definition at line 144 of file mcp251x.c.

#define EFLG_RXEP   0x08

Definition at line 140 of file mcp251x.c.

#define EFLG_RXWAR   0x02

Definition at line 138 of file mcp251x.c.

#define EFLG_TXBO   0x20

Definition at line 142 of file mcp251x.c.

#define EFLG_TXEP   0x10

Definition at line 141 of file mcp251x.c.

#define EFLG_TXWAR   0x04

Definition at line 139 of file mcp251x.c.

#define GET_BYTE (   val,
  byte 
)    (((val) >> ((byte) * 8)) & 0xff)

Definition at line 201 of file mcp251x.c.

#define INSTRUCTION_BIT_MODIFY   0x05

Definition at line 82 of file mcp251x.c.

#define INSTRUCTION_LOAD_TXB (   n)    (0x40 + 2 * (n))

Definition at line 83 of file mcp251x.c.

#define INSTRUCTION_READ   0x03

Definition at line 81 of file mcp251x.c.

#define INSTRUCTION_READ_RXB (   n)    (((n) == 0) ? 0x90 : 0x94)

Definition at line 84 of file mcp251x.c.

#define INSTRUCTION_RESET   0xC0

Definition at line 85 of file mcp251x.c.

#define INSTRUCTION_RTS (   n)    (0x80 | ((n) & 0x07))

Definition at line 89 of file mcp251x.c.

#define INSTRUCTION_WRITE   0x02

Definition at line 80 of file mcp251x.c.

#define mcp251x_can_resume   NULL

Definition at line 1181 of file mcp251x.c.

#define mcp251x_can_suspend   NULL

Definition at line 1180 of file mcp251x.c.

#define MCP251X_IS (   _model)
Value:
static inline int mcp251x_is_##_model(struct spi_device *spi) \
{ \
return priv->model == CAN_MCP251X_MCP##_model; \
}

Definition at line 268 of file mcp251x.c.

#define REC   0x1d

Definition at line 104 of file mcp251x.c.

#define RTS_TXB0   0x01

Definition at line 86 of file mcp251x.c.

#define RTS_TXB1   0x02

Definition at line 87 of file mcp251x.c.

#define RTS_TXB2   0x04

Definition at line 88 of file mcp251x.c.

#define RXBCTRL (   n)    (((n) * 0x10) + 0x60 + RXBCTRL_OFF)

Definition at line 169 of file mcp251x.c.

#define RXBCTRL_BUKT   0x04

Definition at line 170 of file mcp251x.c.

#define RXBCTRL_OFF   0

Definition at line 185 of file mcp251x.c.

#define RXBCTRL_RXM0   0x20

Definition at line 171 of file mcp251x.c.

#define RXBCTRL_RXM1   0x40

Definition at line 172 of file mcp251x.c.

#define RXBDAT_OFF   6

Definition at line 191 of file mcp251x.c.

#define RXBDLC (   n)    (((n) * 0x10) + 0x60 + RXBDLC_OFF)

Definition at line 182 of file mcp251x.c.

#define RXBDLC_LEN_MASK   0x0f

Definition at line 183 of file mcp251x.c.

#define RXBDLC_OFF   5

Definition at line 190 of file mcp251x.c.

#define RXBDLC_RTR   0x40

Definition at line 184 of file mcp251x.c.

#define RXBEID0 (   n)    (((n) * 0x10) + 0x60 + RXBEID0_OFF)

Definition at line 181 of file mcp251x.c.

#define RXBEID0_OFF   4

Definition at line 189 of file mcp251x.c.

#define RXBEID8 (   n)    (((n) * 0x10) + 0x60 + RXBEID8_OFF)

Definition at line 180 of file mcp251x.c.

#define RXBEID8_OFF   3

Definition at line 188 of file mcp251x.c.

#define RXBSIDH (   n)    (((n) * 0x10) + 0x60 + RXBSIDH_OFF)

Definition at line 173 of file mcp251x.c.

#define RXBSIDH_OFF   1

Definition at line 186 of file mcp251x.c.

#define RXBSIDH_SHIFT   3

Definition at line 174 of file mcp251x.c.

#define RXBSIDL (   n)    (((n) * 0x10) + 0x60 + RXBSIDL_OFF)

Definition at line 175 of file mcp251x.c.

#define RXBSIDL_EID   3

Definition at line 178 of file mcp251x.c.

#define RXBSIDL_IDE   0x08

Definition at line 176 of file mcp251x.c.

#define RXBSIDL_OFF   2

Definition at line 187 of file mcp251x.c.

#define RXBSIDL_SHIFT   5

Definition at line 179 of file mcp251x.c.

#define RXBSIDL_SRR   0x10

Definition at line 177 of file mcp251x.c.

#define RXFEID0 (   n)    ((n) * 4 + 3)

Definition at line 195 of file mcp251x.c.

#define RXFEID8 (   n)    ((n) * 4 + 2)

Definition at line 194 of file mcp251x.c.

#define RXFSIDH (   n)    ((n) * 4)

Definition at line 192 of file mcp251x.c.

#define RXFSIDL (   n)    ((n) * 4 + 1)

Definition at line 193 of file mcp251x.c.

#define RXMEID0 (   n)    ((n) * 4 + 0x23)

Definition at line 199 of file mcp251x.c.

#define RXMEID8 (   n)    ((n) * 4 + 0x22)

Definition at line 198 of file mcp251x.c.

#define RXMSIDH (   n)    ((n) * 4 + 0x20)

Definition at line 196 of file mcp251x.c.

#define RXMSIDL (   n)    ((n) * 4 + 0x21)

Definition at line 197 of file mcp251x.c.

#define SET_BYTE (   val,
  byte 
)    (((val) & 0xff) << ((byte) * 8))

Definition at line 203 of file mcp251x.c.

#define SIDH_SHIFT   3

Definition at line 151 of file mcp251x.c.

#define SIDL_EID_MASK   3

Definition at line 157 of file mcp251x.c.

#define SIDL_EID_SHIFT   16

Definition at line 156 of file mcp251x.c.

#define SIDL_EXIDE_SHIFT   3

Definition at line 155 of file mcp251x.c.

#define SIDL_SID_MASK   7

Definition at line 153 of file mcp251x.c.

#define SIDL_SID_SHIFT   5

Definition at line 154 of file mcp251x.c.

#define SPI_TRANSFER_BUF_LEN   (6 + CAN_FRAME_MAX_DATA_LEN)

Definition at line 211 of file mcp251x.c.

#define TEC   0x1c

Definition at line 103 of file mcp251x.c.

#define TX_ECHO_SKB_MAX   1

Definition at line 214 of file mcp251x.c.

#define TXBCTRL (   n)    (((n) * 0x10) + 0x30 + TXBCTRL_OFF)

Definition at line 145 of file mcp251x.c.

#define TXBCTRL_ABTF   0x40

Definition at line 146 of file mcp251x.c.

#define TXBCTRL_MLOA   0x20

Definition at line 147 of file mcp251x.c.

#define TXBCTRL_OFF   0

Definition at line 162 of file mcp251x.c.

#define TXBCTRL_TXERR   0x10

Definition at line 148 of file mcp251x.c.

#define TXBCTRL_TXREQ   0x08

Definition at line 149 of file mcp251x.c.

#define TXBDAT_OFF   6

Definition at line 168 of file mcp251x.c.

#define TXBDLC (   n)    (((n) * 0x10) + 0x30 + TXBDLC_OFF)

Definition at line 160 of file mcp251x.c.

#define TXBDLC_OFF   5

Definition at line 167 of file mcp251x.c.

#define TXBEID0 (   n)    (((n) * 0x10) + 0x30 + TXBEID0_OFF)

Definition at line 159 of file mcp251x.c.

#define TXBEID0_OFF   4

Definition at line 166 of file mcp251x.c.

#define TXBEID8 (   n)    (((n) * 0x10) + 0x30 + TXBEID8_OFF)

Definition at line 158 of file mcp251x.c.

#define TXBEID8_OFF   3

Definition at line 165 of file mcp251x.c.

#define TXBSIDH (   n)    (((n) * 0x10) + 0x30 + TXBSIDH_OFF)

Definition at line 150 of file mcp251x.c.

#define TXBSIDH_OFF   1

Definition at line 163 of file mcp251x.c.

#define TXBSIDL (   n)    (((n) * 0x10) + 0x30 + TXBSIDL_OFF)

Definition at line 152 of file mcp251x.c.

#define TXBSIDL_OFF   2

Definition at line 164 of file mcp251x.c.

Enumeration Type Documentation

Enumerator:
CAN_MCP251X_MCP2510 
CAN_MCP251X_MCP2515 

Definition at line 234 of file mcp251x.c.

Function Documentation

MCP251X_IS ( 2510  )
MCP251X_IS ( 2515  )
MODULE_AUTHOR ( "Chris Elston <[email protected] ,
""Christian Pellegrin< chripell @evolware.org >"   
)
MODULE_DESCRIPTION ( "Microchip 251x CAN driver"  )
MODULE_DEVICE_TABLE ( spi  ,
mcp251x_id_table   
)
module_exit ( mcp251x_can_exit  )
module_init ( mcp251x_can_init  )
MODULE_LICENSE ( "GPL v2 )
module_param ( mcp251x_enable_dma  ,
int  ,
S_IRUGO   
)
MODULE_PARM_DESC ( mcp251x_enable_dma  ,
"Enable SPI DMA. Default: 0 (Off)"   
)