├── Documentation ├── networking │ ├── can.txt │ └── can │ │ ├── can-bcm.txt │ │ ├── can-core.txt │ │ ├── can-drivers.txt │ │ ├── can-raw.txt │ │ ├── can-sockets.txt │ │ └── overview.txt └── powerpc │ └── dts-bindings │ └── fsl │ └── can.txt ├── Makefile ├── Makefile.common ├── README.isotp ├── README.known-issues ├── drivers └── net │ └── can │ ├── Kconfig │ ├── Kconfig.kernel │ ├── Makefile │ ├── Makefile.kernel │ ├── at91_can.c │ ├── cc770 │ ├── Kconfig │ ├── Makefile │ ├── cc770.c │ ├── cc770.h │ ├── cc770_isa.c │ └── cc770_of_platform.c │ ├── dev.c │ ├── esd_pci331.c │ ├── mcp251x.c │ ├── mscan │ ├── Kconfig │ ├── Makefile │ ├── mpc52xx_can.c │ ├── mpc5xxx_can.c │ ├── mscan.c │ └── mscan.h │ ├── old │ ├── Kconfig │ ├── ccan │ │ ├── Makefile │ │ ├── ccan.c │ │ ├── ccan.h │ │ └── h7202_can.c │ ├── hal │ │ ├── c200.c │ │ ├── esdio.c │ │ ├── gw2.c │ │ ├── hal.h │ │ ├── io.c │ │ ├── iomem.c │ │ ├── iomux.c │ │ └── pc7io.c │ ├── i82527 │ │ ├── Makefile │ │ ├── i82527.c │ │ ├── i82527.h │ │ └── proc.c │ ├── mscan │ │ ├── Makefile │ │ ├── mpc52xx_can.c │ │ ├── mscan.c │ │ └── mscan.h │ └── sja1000 │ │ ├── Makefile │ │ ├── proc.c │ │ ├── sja1000.c │ │ └── sja1000.h │ ├── sja1000 │ ├── Kconfig │ ├── Makefile │ ├── ems_104m.c │ ├── ems_pci.c │ ├── ems_pcmcia.c │ ├── esd_pci.c │ ├── ixxat_pci.c │ ├── kvaser_pci.c │ ├── peak_pci.c │ ├── pipcan.c │ ├── plx_pci.c │ ├── sja1000.c │ ├── sja1000.h │ ├── sja1000_isa.c │ ├── sja1000_of_platform.c │ └── sja1000_platform.c │ ├── slcan.c │ ├── softing │ ├── Makefile │ ├── softing.h │ ├── softing_cs.c │ ├── softing_fw.c │ ├── softing_main.c │ └── softing_sysfs.c │ ├── sysfs.c │ ├── sysfs.h │ ├── usb │ ├── Kconfig │ ├── Makefile │ ├── ems_usb.c │ └── esd_usb2.c │ └── vcan.c ├── include ├── linux │ ├── can.h │ └── can │ │ ├── bcm.h │ │ ├── core.h │ │ ├── dev.h │ │ ├── error.h │ │ ├── gw.h │ │ ├── isotp.h │ │ ├── netlink.h │ │ └── raw.h └── socketcan │ ├── can.h │ └── can │ ├── bcm.h │ ├── core.h │ ├── dev.h │ ├── error.h │ ├── gw.h │ ├── ioctl.h │ ├── isotp.h │ ├── netlink.h │ ├── platform │ ├── mcp251x.h │ └── sja1000.h │ ├── raw.h │ └── version.h └── net └── can ├── Kconfig ├── Makefile ├── Makefile.kernel ├── af_can.c ├── af_can.h ├── bcm-prior-2-6-22.c ├── bcm.c ├── compat.h ├── gw.c ├── isotp.c ├── make_isotp.sh ├── proc.c └── raw.c /Documentation/networking/can/can-bcm.txt: -------------------------------------------------------------------------------- 1 | ============================================================================ 2 | 3 | can-bcm.txt : Broadcast Manager API 4 | 5 | Part of the documentation for the socketCAN subsystem 6 | 7 | This file contains: 8 | 9 | B. Broadcast Manager protocol sockets (SOCK_DGRAM) 10 | B.1 Opening BCM sockets 11 | B.2 BCM messages (struct bcm_msg_head) 12 | B.3 TX_SETUP opcode 13 | B.4 TX_DELETE opcode 14 | B.5 TX_READ opcode 15 | B.6 TX_SEND opcode 16 | B.7 RX_SETUP opcode 17 | B.8 RX_DELETE opcode 18 | B.9 RX_READ opcode 19 | 20 | ============================================================================ 21 | 22 | B. Broadcast Manager protocol sockets (SOCK_DGRAM) 23 | -------------------------------------------------- 24 | 25 | The Broadcast Manager (BCM) provides functions to send CAN frames 26 | once or periodically, as well as notify applications of changes in 27 | received CAN frames, recognizing specific CAN IDs. 28 | 29 | Capabilities on the trasmission side: 30 | - Cyclic transmission of a CAN frame with a given interval 31 | - Modification of message content and intervals at runtime (e.g. 32 | switching to a new interval with or without immediate restart of 33 | the timer) 34 | - Automatically switching to a second interval after a certain number 35 | of frames has been sent 36 | - Instant transmission of changed frames, without influencing the 37 | interval cycle 38 | - One-time transmission of CAN messages 39 | 40 | Capabilities on the receiving side: 41 | - Receive filter to detect changes in frame ID, data or length (DLC) 42 | - Receive filter for multiplex frames (e.g. with packet counters in 43 | the data field) 44 | - RTR replies to messages 45 | - Time-out monitoring of frames 46 | - Frequency reduction of messages (throttle function) to the user 47 | application 48 | 49 | B.1 Opening BCM sockets 50 | 51 | To use the referenced definitions for CAN_BCM sockets, include 52 | . 53 | 54 | A socket for the Broadcast-Manager is created with: 55 | 56 | s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM); 57 | 58 | The CAN interface is assigned with a call to connect() on the socket. 59 | 60 | addr.can_family = AF_CAN; 61 | strcpy(ifr.ifr_name, "can0"); 62 | ioctl(s, SIOCGIFINDEX, &ifr); 63 | addr.can_ifindex = ifr.ifr_ifindex; 64 | 65 | connect(s, (struct sockaddr *)&addr, sizeof(addr)); 66 | 67 | If a process must operate on multiple CAN buses, it can open several 68 | sockets. It is also possible for a process to open multiple sockets 69 | on a single CAN-bus, if it makes sense for the application programmer 70 | to structure different data flows. 71 | Every single instance of Broadcast-Manager is able to manage any number of 72 | filter and/or send requests. 73 | 74 | B.2 BCM messages (struct bcm_msg_head) 75 | 76 | All messages from the (user) process to Broadcast-Manager have the same 77 | structure. It consists of a message header with the command (opcode), 78 | several options and zero or more CAN frames, depending on the command 79 | used and the action requested: 80 | 81 | struct bcm_msg_head { 82 | int opcode; /* command */ 83 | int flags; /* special flags */ 84 | int count; /* run 'count' times ival1 then ival2 */ 85 | struct timeval ival1, ival2; /* intervals */ 86 | canid_t can_id; /* 32 Bit SFF/EFF. MSB set at EFF */ 87 | int nframes; /* num of can_frame's in the next field */ 88 | struct can_frame frames[0]; 89 | }; 90 | 91 | The value of nframes indicates how many user data frames follow the 92 | message header. The user data frames are used to describe the actual 93 | content of a CAN message: 94 | 95 | struct can_frame { 96 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR flags */ 97 | __u8 can_dlc; /* data length code: 0 .. 8 */ 98 | __u8 data[8] __attribute__ ((aligned(8))); 99 | }; 100 | 101 | The opcode defines the type of message. Messages from the user to 102 | BCM control the operations of the BCM, replies from the BCM indicate 103 | certain changes to the user, such as timeouts, etc. 104 | 105 | The transmit and receive path of the BCM are two independent functional 106 | blocks. 107 | 108 | For the transmit path the following opcodes exist: 109 | 110 | TX_SETUP: for setting up and modifying transmission requests 111 | TX_DELETE: to remove send requests 112 | TX_READ: to read out the current broadcasting commands 113 | (for debugging purposes) 114 | TX_SEND: for sending a single CAN message 115 | 116 | For the receive path the following opcodes exist: 117 | 118 | RX_SETUP: for setting and modifying receive filters 119 | RX_DELETE: for deleting receive filters 120 | RX_READ: to read out the current receive filter (for debugging purposes) 121 | 122 | The Broadcast-Manager sends response messages in the same form. The 123 | BCM sends these opcodes: 124 | 125 | TX_STATUS: in response to TX_READ 126 | TX_EXPIRED: is sent when the counter count reaches ival1 (only if 127 | flag TX_COUNTEVT is set, see below) 128 | 129 | RX_STATUS: in response to RX_READ 130 | RX_TIMEOUT: sent if the time-controlled reception of a message failed 131 | RX_CHANGED: sent if the first or a revised CAN message was received 132 | 133 | Each of these opcode needs CAN ID specified either in the "can_id" field or 134 | in the first can_frame structure attached to the command. 135 | 136 | In addition, there are optional flags which can influence the BCM behavior: 137 | 138 | SETTIMER: set the value of ival1, ival2 and count 139 | STARTTIMER: start the timer with the actual value of ival1, ival2 and count. 140 | Starting the timer leads simultaneously to the transmission of a 141 | can_frame 142 | TX_COUNTEVT: create the message TX_EXPIRED when count is reached 143 | TX_ANNOUNCE: a change of data by the process is emitted with a new frame, 144 | regardless of the timer status 145 | TX_CP_CAN_ID: copies the can_id from the message header attached to each 146 | of can_frame. This is intended only as usage simplification 147 | TX_RESET_MULTI_IDX: forces a reset of the index counter from the update 148 | to be sent by multiplex message even if it would not be necessary 149 | because of the length 150 | RX_FILTER_ID: there is no filtering of the user data. A match with the 151 | received message can_id automatically leads to a RX_CHANGED. Use 152 | caution in cyclic messages. If RX_FILTER_ID flag is set, the CAN frame 153 | in RX_SETUP can be ignored (i.e., nframes = 0) 154 | RX_RTR_FRAME: the filter passed is used as CAN message to be sent when 155 | receiving an RTR frame 156 | RX_CHECK_DLC: a change of the DLC leads to an RX_CHANGED message to the user 157 | application 158 | RX_NO_AUTOTIMER: if the timer ival1 in the RX_SETUP has been set equal to 159 | zero, on receipt of the CAN message the timer for the timeout 160 | monitoring is automatically started. Setting this flag prevents the 161 | automatic reset of the start timer 162 | RX_ANNOUNCE_RESUME: refers also to the time-out supervision of RX_SETUP. By 163 | setting this flag, when an RX-outs occours, a RX_CHANGED will be 164 | generated when the (cyclic) receive restarts. This will happen even 165 | if the user data have not changed 166 | 167 | B.3 TX_SETUP opcode 168 | B.4 TX_DELETE opcode 169 | 170 | This opcode will delete the entry for transmission of the CAN frame with 171 | the specified can_id CAN identifier. The message length for the command 172 | TX_DELETE is sizeof(bcm_msg_head) (only the header). 173 | 174 | B.5 TX_READ opcode 175 | B.6 TX_SEND opcode 176 | B.7 RX_SETUP opcode 177 | B.8 RX_DELETE opcode 178 | B.9 RX_READ opcode 179 | 180 | -------------------------------------------------------------------------------- /Documentation/networking/can/can-core.txt: -------------------------------------------------------------------------------- 1 | ============================================================================ 2 | 3 | can-core.txt : core module description 4 | 5 | Part of the documentation for the socketCAN subsystem 6 | 7 | This file contains: 8 | 9 | C. Socket CAN core module 10 | C.1 can.ko module params 11 | C.2 procfs content 12 | C.3 writing own CAN protocol modules 13 | 14 | ============================================================================ 15 | 16 | C. Socket CAN core module 17 | ------------------------- 18 | 19 | The Socket CAN core module implements the protocol family 20 | PF_CAN. CAN protocol modules are loaded by the core module at 21 | runtime. The core module provides an interface for CAN protocol 22 | modules to subscribe needed CAN IDs (see overview.txt, chapter 3.1). 23 | 24 | C.1 can.ko module params 25 | 26 | - stats_timer: To calculate the Socket CAN core statistics 27 | (e.g. current/maximum frames per second) this 1 second timer is 28 | invoked at can.ko module start time by default. This timer can be 29 | disabled by using stattimer=0 on the module commandline. 30 | 31 | - debug: (removed since SocketCAN SVN r546) 32 | 33 | C.2 procfs content 34 | 35 | As described in overview.txt, chapter 3.1 the Socket CAN core uses 36 | several filter lists to deliver received CAN frames to CAN protocol 37 | modules. These receive lists, their filters and the count of filter 38 | matches can be checked in the appropriate receive list. All entries 39 | contain the device and a protocol module identifier: 40 | 41 | foo@bar:~$ cat /proc/net/can/rcvlist_all 42 | 43 | receive list 'rx_all': 44 | (vcan3: no entry) 45 | (vcan2: no entry) 46 | (vcan1: no entry) 47 | device can_id can_mask function userdata matches ident 48 | vcan0 000 00000000 f88e6370 f6c6f400 0 raw 49 | (any: no entry) 50 | 51 | In this example an application requests any CAN traffic from vcan0. 52 | 53 | rcvlist_all - list for unfiltered entries (no filter operations) 54 | rcvlist_eff - list for single extended frame (EFF) entries 55 | rcvlist_err - list for error frames masks 56 | rcvlist_fil - list for mask/value filters 57 | rcvlist_inv - list for mask/value filters (inverse semantic) 58 | rcvlist_sff - list for single standard frame (SFF) entries 59 | 60 | Additional procfs files in /proc/net/can 61 | 62 | stats - Socket CAN core statistics (rx/tx frames, match ratios, ...) 63 | reset_stats - manual statistic reset 64 | version - prints the Socket CAN core version and the ABI version 65 | 66 | C.3 writing own CAN protocol modules 67 | 68 | To implement a new protocol in the protocol family PF_CAN a new 69 | protocol has to be defined in include/linux/can.h . 70 | The prototypes and definitions to use the Socket CAN core can be 71 | accessed by including include/linux/can/core.h . 72 | In addition to functions that register the CAN protocol and the 73 | CAN device notifier chain there are functions to subscribe CAN 74 | frames received by CAN interfaces and to send CAN frames: 75 | 76 | can_rx_register - subscribe CAN frames from a specific interface 77 | can_rx_unregister - unsubscribe CAN frames from a specific interface 78 | can_send - transmit a CAN frame (optional with local loopback) 79 | 80 | For details see the kerneldoc documentation in net/can/af_can.c or 81 | the source code of net/can/raw.c or net/can/bcm.c . 82 | 83 | 84 | -------------------------------------------------------------------------------- /Documentation/networking/can/can-raw.txt: -------------------------------------------------------------------------------- 1 | ============================================================================ 2 | 3 | can-raw.txt : Raw CAN sockets 4 | 5 | Part of the documentation for the socketCAN subsystem 6 | 7 | This file contains 8 | 9 | R. RAW protocol sockets with can_filters (SOCK_RAW) 10 | R.1 RAW socket option CAN_RAW_FILTER 11 | R.2 RAW socket option CAN_RAW_ERR_FILTER 12 | R.3 RAW socket option CAN_RAW_LOOPBACK 13 | R.4 RAW socket option CAN_RAW_RECV_OWN_MSGS 14 | R.5 RAW socket returned message flags 15 | 16 | ============================================================================ 17 | 18 | R. RAW protocol sockets with can_filters (SOCK_RAW) 19 | --------------------------------------------------- 20 | 21 | Using CAN_RAW sockets is extensively comparable to the commonly 22 | known access to CAN character devices. To meet the new possibilities 23 | provided by the multi user SocketCAN approach, some reasonable 24 | defaults are set at RAW socket binding time: 25 | 26 | - The filters are set to exactly one filter receiving everything 27 | - The socket only receives valid data frames (=> no error frames) 28 | - The loopback of sent CAN frames is enabled (see overview.txt, chapter 3.2) 29 | - The socket does not receive its own sent frames (in loopback mode) 30 | 31 | These default settings may be changed before or after binding the socket. 32 | To use the referenced definitions of the socket options for CAN_RAW 33 | sockets, include . 34 | 35 | R.1 RAW socket option CAN_RAW_FILTER 36 | 37 | The reception of CAN frames using CAN_RAW sockets can be controlled 38 | by defining 0 .. n filters with the CAN_RAW_FILTER socket option. 39 | 40 | The CAN filter structure is defined in include/linux/can.h: 41 | 42 | struct can_filter { 43 | canid_t can_id; 44 | canid_t can_mask; 45 | }; 46 | 47 | A filter matches, when 48 | 49 | & mask == can_id & mask 50 | 51 | which is analogous to known CAN controllers hardware filter semantics. 52 | The filter can be inverted in this semantic, when the CAN_INV_FILTER 53 | bit is set in can_id element of the can_filter structure. In 54 | contrast to CAN controller hardware filters the user may set 0 .. n 55 | receive filters for each open socket separately: 56 | 57 | struct can_filter rfilter[2]; 58 | 59 | rfilter[0].can_id = 0x123; 60 | rfilter[0].can_mask = CAN_SFF_MASK; 61 | rfilter[1].can_id = 0x200; 62 | rfilter[1].can_mask = 0x700; 63 | 64 | setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter)); 65 | 66 | To disable the reception of CAN frames on the selected CAN_RAW socket: 67 | 68 | setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0); 69 | 70 | To set the filters to zero filters is quite obsolete as not read 71 | data causes the raw socket to discard the received CAN frames. But 72 | having this 'send only' use-case we may remove the receive list in the 73 | Kernel to save a little (really a very little!) CPU usage. 74 | 75 | R.2 RAW socket option CAN_RAW_ERR_FILTER 76 | 77 | As described in overview.txt (chapter 3.4) the CAN interface driver 78 | can generate so called Error Frames that can optionally be passed 79 | to the user application in the same way as other CAN frames. The possible 80 | errors are divided into different error classes that may be filtered 81 | using the appropriate error mask. To register for every possible 82 | error condition CAN_ERR_MASK can be used as value for the error mask. 83 | The values for the error mask are defined in linux/can/error.h . 84 | 85 | can_err_mask_t err_mask = ( CAN_ERR_TX_TIMEOUT | CAN_ERR_BUSOFF ); 86 | 87 | setsockopt(s, SOL_CAN_RAW, CAN_RAW_ERR_FILTER, 88 | &err_mask, sizeof(err_mask)); 89 | 90 | R.3 RAW socket option CAN_RAW_LOOPBACK 91 | 92 | To meet multi user needs the local loopback is enabled by default 93 | (see overview.txt, chapter 3.2, for details). But in some embedded 94 | use-cases (e.g. when only one application uses the CAN bus) this 95 | loopback functionality can be disabled (separately for each socket): 96 | 97 | int loopback = 0; /* 0 = disabled, 1 = enabled (default) */ 98 | 99 | setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK, &loopback, sizeof(loopback)); 100 | 101 | R.4 RAW socket option CAN_RAW_RECV_OWN_MSGS 102 | 103 | When the local loopback is enabled, all the sent CAN frames are 104 | looped back to the open CAN sockets that registered for the CAN 105 | frames' CAN-ID on this given interface to meet the multi user 106 | needs. The reception of the CAN frames on the same socket that was 107 | sending the CAN frame is assumed to be unwanted and therefore 108 | disabled by default. This default behaviour may be changed on 109 | demand: 110 | 111 | int recv_own_msgs = 1; /* 0 = disabled (default), 1 = enabled */ 112 | 113 | setsockopt(s, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, 114 | &recv_own_msgs, sizeof(recv_own_msgs)); 115 | 116 | R.5 RAW socket returned message flags 117 | 118 | When using recvmsg() call, the msg->msg_flags may contain following flags: 119 | 120 | MSG_DONTROUTE: set when the received frame was created on the local host. 121 | 122 | MSG_CONFIRM: set when the frame was sent via the socket it is received on. 123 | This flag can be interpreted as a 'transmission confirmation' when the 124 | CAN driver supports the echo of frames on driver level, see 3.2 and 6.2. 125 | In order to receive such messages, CAN_RAW_RECV_OWN_MSGS must be set. 126 | 127 | -------------------------------------------------------------------------------- /Documentation/networking/can/can-sockets.txt: -------------------------------------------------------------------------------- 1 | ============================================================================ 2 | 3 | can-sockets.txt : general socketCAN API documentation 4 | 5 | See can-raw.txt and can-bcm.txt for in-depth documentation 6 | on RAW and BCM sockets. 7 | 8 | Part of the documentation for the socketCAN subsystem 9 | 10 | This file contains: 11 | 12 | S. How to use Socket CAN 13 | S.1 Timestamps 14 | 15 | ============================================================================ 16 | 17 | S. How to use Socket CAN 18 | ------------------------ 19 | 20 | Like TCP/IP, you first need to open a socket for communicating over a 21 | CAN network. Since Socket CAN implements a new protocol family, you 22 | need to pass PF_CAN as the first argument to the socket(2) system 23 | call. Currently, there are two CAN protocols to choose from, the raw 24 | socket protocol and the broadcast manager (BCM). So to open a socket, 25 | you would write 26 | 27 | s = socket(PF_CAN, SOCK_RAW, CAN_RAW); 28 | 29 | and 30 | 31 | s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM); 32 | 33 | respectively. After the successful creation of the socket, you would 34 | normally use the bind(2) system call to bind the socket to a CAN 35 | interface (which is different from TCP/IP due to different addressing 36 | - see overview.txt, chapter 3). After binding (CAN_RAW) or connecting 37 | (CAN_BCM) the socket, you can read(2) and write(2) from/to the socket 38 | or use send(2), sendto(2), sendmsg(2) and the recv* counterpart operations 39 | on the socket as usual. There are also CAN specific socket options 40 | described below. 41 | 42 | The basic CAN frame structure and the sockaddr structure are defined 43 | in include/linux/can.h: 44 | 45 | struct can_frame { 46 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ 47 | __u8 can_dlc; /* data length code: 0 .. 8 */ 48 | __u8 data[8] __attribute__((aligned(8))); 49 | }; 50 | 51 | The alignment of the (linear) payload data[] to a 64bit boundary 52 | allows the user to define own structs and unions to easily access the 53 | CAN payload. There is no given byteorder on the CAN bus by 54 | default. A read(2) system call on a CAN_RAW socket transfers a 55 | struct can_frame to the user space. 56 | 57 | The sockaddr_can structure has an interface index like the 58 | PF_PACKET socket, that also binds to a specific interface: 59 | 60 | struct sockaddr_can { 61 | sa_family_t can_family; 62 | int can_ifindex; 63 | union { 64 | /* transport protocol class address info (e.g. ISOTP) */ 65 | struct { canid_t rx_id, tx_id; } tp; 66 | 67 | /* reserved for future CAN protocols address information */ 68 | } can_addr; 69 | }; 70 | 71 | To determine the interface index an appropriate ioctl() has to 72 | be used (example for CAN_RAW sockets without error checking): 73 | 74 | int s; 75 | struct sockaddr_can addr; 76 | struct ifreq ifr; 77 | 78 | s = socket(PF_CAN, SOCK_RAW, CAN_RAW); 79 | 80 | strcpy(ifr.ifr_name, "can0" ); 81 | ioctl(s, SIOCGIFINDEX, &ifr); 82 | 83 | addr.can_family = AF_CAN; 84 | addr.can_ifindex = ifr.ifr_ifindex; 85 | 86 | bind(s, (struct sockaddr *)&addr, sizeof(addr)); 87 | 88 | (..) 89 | 90 | To bind a socket to all(!) CAN interfaces the interface index must 91 | be 0 (zero). In this case the socket receives CAN frames from every 92 | enabled CAN interface. To determine the originating CAN interface 93 | the system call recvfrom(2) may be used instead of read(2). To send 94 | on a socket that is bound to 'any' interface sendto(2) is needed to 95 | specify the outgoing interface. 96 | 97 | Reading CAN frames from a bound CAN_RAW socket (see above) consists 98 | of reading a struct can_frame: 99 | 100 | struct can_frame frame; 101 | 102 | nbytes = read(s, &frame, sizeof(struct can_frame)); 103 | 104 | if (nbytes < 0) { 105 | perror("can raw socket read"); 106 | return 1; 107 | } 108 | 109 | /* paranoid check ... */ 110 | if (nbytes < sizeof(struct can_frame)) { 111 | fprintf(stderr, "read: incomplete CAN frame\n"); 112 | return 1; 113 | } 114 | 115 | /* do something with the received CAN frame */ 116 | 117 | Writing CAN frames can be done similarly, with the write(2) system call: 118 | 119 | nbytes = write(s, &frame, sizeof(struct can_frame)); 120 | 121 | When the CAN interface is bound to 'any' existing CAN interface 122 | (addr.can_ifindex = 0) it is recommended to use recvfrom(2) if the 123 | information about the originating CAN interface is needed: 124 | 125 | struct sockaddr_can addr; 126 | struct ifreq ifr; 127 | socklen_t len = sizeof(addr); 128 | struct can_frame frame; 129 | 130 | nbytes = recvfrom(s, &frame, sizeof(struct can_frame), 131 | 0, (struct sockaddr*)&addr, &len); 132 | 133 | /* get interface name of the received CAN frame */ 134 | ifr.ifr_ifindex = addr.can_ifindex; 135 | ioctl(s, SIOCGIFNAME, &ifr); 136 | printf("Received a CAN frame from interface %s", ifr.ifr_name); 137 | 138 | To write CAN frames on sockets bound to 'any' CAN interface the 139 | outgoing interface has to be defined certainly. 140 | 141 | strcpy(ifr.ifr_name, "can0"); 142 | ioctl(s, SIOCGIFINDEX, &ifr); 143 | addr.can_ifindex = ifr.ifr_ifindex; 144 | addr.can_family = AF_CAN; 145 | 146 | nbytes = sendto(s, &frame, sizeof(struct can_frame), 147 | 0, (struct sockaddr*)&addr, sizeof(addr)); 148 | 149 | S.1 Timestamps 150 | 151 | For applications in the CAN environment it is often of interest an 152 | accurate timestamp of the instant a message from CAN bus has been received. 153 | Such a timestamp can be read with ioctl(2) after reading a message from 154 | the socket. Example: 155 | 156 | struct timeval tv; 157 | ioctl(s, SIOCGSTAMP, &tv); 158 | 159 | The timestamp on Linux has a resolution of one microsecond and it is set 160 | automatically at the reception of a CAN frame. 161 | 162 | Alternatively the timestamp can be obtained as a control message (cmsg) using 163 | the recvmsg() system call. After enabling the timestamps in the cmsg's by 164 | 165 | const int timestamp = 1; 166 | setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, ×tamp, sizeof(timestamp)); 167 | 168 | the data structures filled by recvmsg() need to be parsed for 169 | cmsg->cmsg_type == SO_TIMESTAMP to get the timestamp. See cmsg() manpage. 170 | 171 | -------------------------------------------------------------------------------- /Documentation/powerpc/dts-bindings/fsl/can.txt: -------------------------------------------------------------------------------- 1 | CAN Device Tree Bindings 2 | ------------------------ 3 | 4 | (c) 2006-2009 Secret Lab Technologies Ltd 5 | Grant Likely 6 | 7 | fsl,mpc5200-mscan nodes 8 | ----------------------- 9 | In addition to the required compatible-, reg- and interrupt-properties, you can 10 | also specify which clock source shall be used for the controller: 11 | 12 | - fsl,mscan-clock-source : a string describing the clock source. Valid values 13 | are: "ip" for ip bus clock 14 | "ref" for reference clock (XTAL) 15 | "ref" is default in case this property is not 16 | present. 17 | 18 | fsl,mpc5121-mscan nodes 19 | ----------------------- 20 | In addition to the required compatible-, reg- and interrupt-properties, you can 21 | also specify which clock source and divider shall be used for the controller: 22 | 23 | - fsl,mscan-clock-source : a string describing the clock source. Valid values 24 | are: "ip" for ip bus clock 25 | "ref" for reference clock 26 | "sys" for system clock 27 | If this property is not present, an optimal CAN 28 | clock source and frequency based on the system 29 | clock will be selected. If this is not possible, 30 | the reference clock will be used. 31 | 32 | - fsl,mscan-clock-divider: for the reference and system clock, an additional 33 | clock divider can be specified. By default, a 34 | value of 1 is used. 35 | 36 | Note that the MPC5121 Rev. 1 processor is not supported. 37 | 38 | Examples: 39 | can@1300 { 40 | compatible = "fsl,mpc5121-mscan"; 41 | interrupts = <12 0x8>; 42 | interrupt-parent = <&ipic>; 43 | reg = <0x1300 0x80>; 44 | }; 45 | 46 | can@1380 { 47 | compatible = "fsl,mpc5121-mscan"; 48 | interrupts = <13 0x8>; 49 | interrupt-parent = <&ipic>; 50 | reg = <0x1380 0x80>; 51 | fsl,mscan-clock-source = "ref"; 52 | fsl,mscan-clock-divider = <3>; 53 | }; 54 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(KERNELRELEASE),) 2 | 3 | KERNELDIR := /lib/modules/$(shell uname -r)/build 4 | PWD := $(shell pwd) 5 | TOPDIR := $(PWD) 6 | 7 | export CONFIG_CAN_VCAN=m 8 | export CONFIG_CAN_SLCAN=m 9 | export CONFIG_CAN_DEV=m 10 | export CONFIG_CAN_CALC_BITTIMING=y 11 | #export CONFIG_CAN_DEV_SYSFS=y 12 | #export CONFIG_CAN_SJA1000_OLD=m 13 | #export CONFIG_CAN_I82527_OLD=m 14 | export CONFIG_CAN_CC770=m 15 | export CONFIG_CAN_CC770_ISA=m 16 | #export CONFIG_CAN_CC770_OF_PLATFORM=m 17 | export CONFIG_CAN_SJA1000=m 18 | export CONFIG_CAN_SJA1000_PLATFORM=m 19 | #export CONFIG_CAN_SJA1000_OF_PLATFORM=m 20 | export CONFIG_CAN_IXXAT_PCI=m 21 | export CONFIG_CAN_PLX_PCI=m 22 | export CONFIG_CAN_PEAK_PCI=m 23 | export CONFIG_CAN_KVASER_PCI=m 24 | export CONFIG_CAN_EMS_PCI=m 25 | #export CONFIG_CAN_EMS_USB=m 26 | #export CONFIG_CAN_EMS_PCMCIA=m 27 | export CONFIG_CAN_EMS_104M=m 28 | export CONFIG_CAN_ESD_PCI=m 29 | export CONFIG_CAN_ESD_PCI331=m 30 | #export CONFIG_CAN_ESD_USB2=m 31 | export CONFIG_CAN_PIPCAN=m 32 | #export CONFIG_CAN_SOFTING=m 33 | #export CONFIG_CAN_SOFTING_CS=m 34 | export CONFIG_CAN_MCP251X=m 35 | 36 | export CONFIG_CAN=m 37 | export CONFIG_CAN_RAW=m 38 | export CONFIG_CAN_BCM=m 39 | export CONFIG_CAN_ISOTP=m 40 | 41 | modules modules_install clean: 42 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 43 | 44 | else 45 | 46 | obj-m += drivers/net/can/ 47 | obj-m += net/can/ 48 | 49 | endif 50 | -------------------------------------------------------------------------------- /Makefile.common: -------------------------------------------------------------------------------- 1 | ifneq ($(KBUILD_EXTMOD),) 2 | 3 | EXTRA_CFLAGS += \ 4 | -I$(TOPDIR)/include \ 5 | -I$(TOPDIR)/drivers/net/can/hal \ 6 | \ 7 | -DETH_P_CAN=0x000C \ 8 | -DARPHRD_CAN=280 9 | 10 | ifneq ($(CONFIG_CAN_CALC_BITTIMING),n) 11 | EXTRA_CFLAGS += -DCONFIG_CAN_CALC_BITTIMING 12 | endif 13 | 14 | ifeq ($(CONFIG_CAN_DEBUG_DEVICES),y) 15 | EXTRA_CFLAGS += -DCONFIG_CAN_DEBUG_DEVICES 16 | endif 17 | 18 | endif 19 | -------------------------------------------------------------------------------- /README.known-issues: -------------------------------------------------------------------------------- 1 | This is a list of knwon driver issues: 2 | 3 | drivers/net/can/mcp251x.c: 4 | 5 | FIXME: echo support missing (requilred for IFF_ECHO) 6 | FIXME: increment can_stats in case of state changes 7 | FIXME: state changes by interrupt 8 | FIXME: do_set_mode not implemented (required for restart) 9 | FIXME: remove tx timeout callback 10 | FIXME: to be tested 11 | 12 | drivers/net/can/softing/softing_main.c: 13 | 14 | FIXME: coding style issues! 15 | FIXME: check softing_flush_echo_skb and bus_off handling. 16 | FIXME: to be tested 17 | 18 | -------------------------------------------------------------------------------- /drivers/net/can/Kconfig: -------------------------------------------------------------------------------- 1 | menu "CAN Device Drivers" 2 | depends on CAN 3 | 4 | config CAN_VCAN 5 | tristate "Virtual Local CAN Interface (vcan)" 6 | depends on CAN 7 | default N 8 | ---help--- 9 | Similar to the network loopback devices, vcan offers a 10 | virtual local CAN interface. 11 | 12 | This driver can also be built as a module. If so, the module 13 | will be called vcan. 14 | 15 | config CAN_SLCAN 16 | tristate "Serial / USB serial CAN Adaptors (slcan)" 17 | depends on CAN 18 | default N 19 | ---help--- 20 | CAN driver for several 'low cost' CAN interfaces that are attached 21 | via serial lines or via USB-to-serial adapters using the LAWICEL 22 | ASCII protocol. The driver implements the tty linediscipline N_SLCAN. 23 | 24 | As only the sending and receiving of CAN frames is implemented, this 25 | driver should work with the (serial/USB) CAN hardware from: 26 | www.canusb.com / www.can232.com / www.mictronics.de / www.canhack.de 27 | 28 | Userspace tools to attach the SLCAN line discipline (slcan_attach, 29 | slcand) can be found in the can-utils at the SocketCAN SVN, see 30 | http://developer.berlios.de/projects/socketcan for details. 31 | 32 | The slcan driver supports up to 10 CAN netdevices by default which 33 | can be changed by the 'maxdev=xx' module option. This driver can 34 | also be built as a module. If so, the module will be called slcan. 35 | 36 | config CAN_OLD_DRIVERS 37 | tristate "Prompt for old CAN drivers (e.g. no sysfs support)" 38 | depends on CAN 39 | default N 40 | ---help--- 41 | The old drivers do not support sysfs nor proper platform device 42 | support. Some of the old drivers might only be configured by 43 | module commandline options. 44 | 45 | if CAN_OLD_DRIVERS 46 | source "drivers/net/can/old/Kconfig" 47 | endif 48 | 49 | config CAN_DEV 50 | tristate "Platform CAN drivers with Netlink support" 51 | depends on CAN 52 | default y 53 | ---help--- 54 | Enables the common framework for platform CAN drivers with Netlink 55 | support. This is the standard library for CAN drivers. 56 | If unsure, say Y. 57 | 58 | config CAN_DEV_SYSFS 59 | bool "Support for sysfs interface (deprecated)" 60 | depends on CAN_DEV && SYSFS 61 | default N 62 | ---help--- 63 | Adds support for the legacy sysfs interface to configure CAN 64 | devices. If possible, please use the new netlink interface 65 | instead. 66 | If unsure, say N. 67 | 68 | config CAN_CALC_BITTIMING 69 | bool "CAN bit-timing calculation" 70 | depends on CAN_DEV 71 | default y 72 | ---help--- 73 | If enabled, CAN bit-timing parameters will be calculated for the 74 | bit-rate specified via Netlink argument "bitrate" when the device 75 | get started. This works fine for the most common CAN controllers 76 | with standard bit-rates but may fail for exotic bit-rates or CAN 77 | source clock frequencies. Disabling saves some space, but then the 78 | bit-timing parameters must be specified directly using the Netlink 79 | arguments "tq", "prop_seg", "phase_seg1", "phase_seg2" and "sjw". 80 | If unsure, say Y. 81 | 82 | config CAN_ESD_PCI331 83 | tristate "ESD CAN 331 Cards" 84 | depends on PCI && CAN_DEV 85 | ---help--- 86 | This driver supports the PCI/331, CPCI/331 and PMC/331 CAN cards 87 | from the esd system design gmbh (http://www.esd.eu). 88 | 89 | config CAN_SOFTING 90 | tristate "Softing Gmbh CAN generic support" 91 | depends on CAN_DEV 92 | ---help--- 93 | generic softing CAN cards 94 | Sofing CAN cards come with 1 or 2 physical busses. 95 | The API of the card does not allow fine control per bus, but 96 | controls the 2 busses on the card together. 97 | As such, some actions (start/stop/busoff recovery) on 1 bus 98 | must bring down the other bus too temporarily. 99 | You have been warned. 100 | This driver is written on safe on 64bit, but not on big endian. 101 | 102 | config CAN_SOFTING_CS 103 | tristate "Softing CAN pcmcia cards" 104 | depends on CAN_SOFTING && PCMCIA 105 | ---help--- 106 | Support for PCMCIA cards from Softing Gmbh & some cards 107 | from Vector Gmbh. 108 | You need firmware for these, which you can get at 109 | http://developer.berlios.de/projects/socketcan/ 110 | This version of the driver is written against 111 | firmware version 4.6 112 | 113 | config CAN_AT91 114 | tristate "Atmel AT91 onchip CAN controller" 115 | depends on CAN_DEV && ARCH_AT91SAM9263 116 | default N 117 | ---help--- 118 | This is a driver for the SoC CAN controller in Atmel's AT91SAM9263. 119 | 120 | config CAN_MCP251X 121 | tristate "Microchip MCP251x SPI CAN controllers" 122 | depends on CAN_DEV && SPI 123 | ---help--- 124 | Driver for the Microchip MCP251x SPI CAN controllers. 125 | 126 | source "drivers/net/can/cc770/Kconfig" 127 | 128 | source "drivers/net/can/mscan/Kconfig" 129 | 130 | source "drivers/net/can/sja1000/Kconfig" 131 | 132 | source "drivers/net/can/usb/Kconfig" 133 | 134 | config CAN_DEBUG_DEVICES 135 | bool "CAN devices debugging messages" 136 | depends on CAN 137 | default N 138 | ---help--- 139 | Say Y here if you want the CAN device drivers to produce a bunch of 140 | debug messages to the system log. Select this if you are having 141 | a problem with CAN support and want to see more of what is going 142 | on. 143 | 144 | endmenu 145 | -------------------------------------------------------------------------------- /drivers/net/can/Kconfig.kernel: -------------------------------------------------------------------------------- 1 | menu "CAN Device Drivers" 2 | depends on CAN 3 | 4 | config CAN_VCAN 5 | tristate "Virtual Local CAN Interface (vcan)" 6 | depends on CAN 7 | default N 8 | ---help--- 9 | Similar to the network loopback devices, vcan offers a 10 | virtual local CAN interface. 11 | 12 | This driver can also be built as a module. If so, the module 13 | will be called vcan. 14 | 15 | config CAN_DEV 16 | tristate "Platform CAN drivers with Netlink support" 17 | depends on CAN 18 | default Y 19 | ---help--- 20 | Enables the common framework for platform CAN drivers with Netlink 21 | support. This is the standard library for CAN drivers. 22 | If unsure, say Y. 23 | 24 | config CAN_CALC_BITTIMING 25 | bool "CAN bit-timing calculation" 26 | depends on CAN_DEV 27 | default Y 28 | ---help--- 29 | If enabled, CAN bit-timing parameters will be calculated for the 30 | bit-rate specified via Netlink argument "bitrate" when the device 31 | get started. This works fine for the most common CAN controllers 32 | with standard bit-rates but may fail for exotic bit-rates or CAN 33 | source clock frequencies. Disabling saves some space, but then the 34 | bit-timing parameters must be specified directly using the Netlink 35 | arguments "tq", "prop_seg", "phase_seg1", "phase_seg2" and "sjw". 36 | If unsure, say Y. 37 | 38 | config CAN_SJA1000 39 | depends on CAN_DEV && HAS_IOMEM 40 | tristate "Philips SJA1000" 41 | ---help--- 42 | Driver for the SJA1000 CAN controllers from Philips or NXP 43 | 44 | config CAN_SJA1000_PLATFORM 45 | depends on CAN_SJA1000 46 | tristate "Generic Platform Bus based SJA1000 driver" 47 | ---help--- 48 | This driver adds support for the SJA1000 chips connected to 49 | the "platform bus" (Linux abstraction for directly to the 50 | processor attached devices). Which can be found on various 51 | boards from Phytec (http://www.phytec.de) like the PCM027, 52 | PCM038. 53 | 54 | config CAN_SJA1000_OF_PLATFORM 55 | depends on CAN_SJA1000 && PPC_OF 56 | tristate "Generic OF Platform Bus based SJA1000 driver" 57 | ---help--- 58 | This driver adds support for the SJA1000 chips connected to 59 | the OpenFirmware "platform bus" found on embedded systems with 60 | OpenFirmware bindings, e.g. if you have a PowerPC based system 61 | you may want to enable this option. 62 | 63 | config CAN_EMS_PCI 64 | tristate "EMS CPC-PCI, CPC-PCIe and CPC-104P Card" 65 | depends on PCI && CAN_SJA1000 66 | ---help--- 67 | This driver is for the one, two or four channel CPC-PCI, 68 | CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche 69 | (http://www.ems-wuensche.de). 70 | 71 | config CAN_KVASER_PCI 72 | tristate "Kvaser PCIcanx and Kvaser PCIcan PCI Cards" 73 | depends on PCI && CAN_SJA1000 74 | ---help--- 75 | This driver is for the the PCIcanx and PCIcan cards (1, 2 or 76 | 4 channel) from Kvaser (http://www.kvaser.com). 77 | 78 | config CAN_DEBUG_DEVICES 79 | bool "CAN devices debugging messages" 80 | depends on CAN 81 | default N 82 | ---help--- 83 | Say Y here if you want the CAN device drivers to produce a bunch of 84 | debug messages to the system log. Select this if you are having 85 | a problem with CAN support and want to see more of what is going 86 | on. 87 | 88 | endmenu 89 | -------------------------------------------------------------------------------- /drivers/net/can/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | 5 | 6 | ifeq ($(KERNELRELEASE),) 7 | 8 | KERNELDIR := /lib/modules/$(shell uname -r)/build 9 | PWD := $(shell pwd) 10 | TOPDIR := $(PWD)/../../.. 11 | 12 | export CONFIG_CAN_VCAN=m 13 | export CONFIG_CAN_SLCAN=m 14 | export CONFIG_CAN_DEV=m 15 | export CONFIG_CAN_CALC_BITTIMING=y 16 | #export CONFIG_CAN_DEV_SYSFS=y 17 | #export CONFIG_CAN_SJA1000_OLD=m 18 | #export CONFIG_CAN_I82527_OLD=m 19 | export CONFIG_CAN_CC770=m 20 | export CONFIG_CAN_CC770_ISA=m 21 | #export CONFIG_CAN_CC770_OF_PLATFORM=m 22 | export CONFIG_CAN_SJA1000=m 23 | export CONFIG_CAN_SJA1000_PLATFORM=m 24 | #export CONFIG_CAN_SJA1000_OF_PLATFORM=m 25 | export CONFIG_CAN_IXXAT_PCI=m 26 | export CONFIG_CAN_PLX_PCI=m 27 | export CONFIG_CAN_PEAK_PCI=m 28 | export CONFIG_CAN_KVASER_PCI=m 29 | export CONFIG_CAN_EMS_PCI=m 30 | #export CONFIG_CAN_EMS_USB=m 31 | #export CONFIG_CAN_EMS_PCMCIA=m 32 | export CONFIG_CAN_EMS_104M=m 33 | export CONFIG_CAN_ESD_PCI=m 34 | export CONFIG_CAN_ESD_PCI331=m 35 | #export CONFIG_CAN_ESD_USB2=m 36 | export CONFIG_CAN_PIPCAN=m 37 | #export CONFIG_CAN_SOFTING=m 38 | #export CONFIG_CAN_SOFTING_CS=m 39 | export CONFIG_CAN_MCP251X=m 40 | 41 | modules modules_install clean: 42 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 43 | 44 | else 45 | 46 | -include $(TOPDIR)/Makefile.common 47 | 48 | obj-$(CONFIG_CAN_VCAN) += vcan.o 49 | obj-$(CONFIG_CAN_SLCAN) += slcan.o 50 | 51 | obj-$(CONFIG_CAN_DEV) += can-dev.o 52 | can-dev-y := dev.o 53 | can-dev-$(CONFIG_CAN_DEV_SYSFS) += sysfs.o 54 | 55 | obj-$(CONFIG_CAN_CC770) += cc770/ 56 | obj-$(CONFIG_CAN_SJA1000) += sja1000/ 57 | obj-$(CONFIG_CAN_SOFTING) += softing/ 58 | obj-$(CONFIG_CAN_MSCAN) += mscan/ 59 | obj-$(CONFIG_USB) += usb/ 60 | obj-$(CONFIG_CAN_AT91) += at91_can.o 61 | obj-$(CONFIG_CAN_ESD_PCI331) += esd_pci331.o 62 | obj-$(CONFIG_CAN_SJA1000_OLD) += old/sja1000/ 63 | obj-$(CONFIG_CAN_I82527_OLD) += old/i82527/ 64 | obj-$(CONFIG_CAN_MSCAN_OLD) += old/mscan/ 65 | obj-$(CONFIG_CAN_CCAN_OLD) += old/ccan/ 66 | obj-$(CONFIG_CAN_MCP251X) += mcp251x.o 67 | 68 | ifeq ($(CONFIG_CAN_DEBUG_DEVICES),y) 69 | EXTRA_CFLAGS += -DDEBUG 70 | endif 71 | ifeq ($(CONFIG_CAN_DEV_SYSFS),y) 72 | EXTRA_CFLAGS += -DCONFIG_CAN_DEV_SYSFS 73 | endif 74 | ifneq ($(CONFIG_CAN_CALC_BITTIMING),n) 75 | EXTRA_CFLAGS += -DCONFIG_CAN_CALC_BITTIMING 76 | endif 77 | 78 | endif 79 | -------------------------------------------------------------------------------- /drivers/net/can/Makefile.kernel: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for the Linux Controller Area Network drivers. 3 | # 4 | 5 | obj-$(CONFIG_CAN_VCAN) += vcan.o 6 | -------------------------------------------------------------------------------- /drivers/net/can/cc770/Kconfig: -------------------------------------------------------------------------------- 1 | menuconfig CAN_CC770 2 | tristate "Bosch CC770 and Intel AN82527 devices" 3 | depends on CAN_DEV && HAS_IOMEM 4 | 5 | if CAN_CC770 6 | 7 | config CAN_CC770_ISA 8 | depends on ISA 9 | tristate "ISA Bus based legacy CC770 driver" 10 | ---help--- 11 | This driver adds legacy support for CC770 and AN82527 chips 12 | connected to the ISA bus using I/O port, memory mapped or 13 | indirect access. 14 | 15 | config CAN_CC770_OF_PLATFORM 16 | depends on PPC_OF 17 | tristate "Generic OF Platform Bus based CC770 driver" 18 | ---help--- 19 | This driver adds support for the CC770 and other AN82527 20 | compatible chips connected to the OpenFirmware "platform bus" 21 | found on embedded systems with OpenFirmware bindings, e.g. if 22 | you have a PowerPC based system you may want to enable this 23 | option. 24 | 25 | endif 26 | -------------------------------------------------------------------------------- /drivers/net/can/cc770/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: Makefile 443 2007-07-25 11:41:27Z hartkopp $ 3 | # 4 | 5 | ifeq ($(KERNELRELEASE),) 6 | 7 | KERNELDIR := /lib/modules/$(shell uname -r)/build 8 | PWD := $(shell pwd) 9 | TOPDIR := $(PWD)/../../../.. 10 | 11 | modules modules_install clean: 12 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 13 | 14 | else 15 | 16 | -include $(TOPDIR)/Makefile.common 17 | 18 | obj-$(CONFIG_CAN_CC770) += cc770.o 19 | obj-$(CONFIG_CAN_CC770_ISA) += cc770_isa.o 20 | obj-$(CONFIG_CAN_CC770_OF_PLATFORM) += cc770_of_platform.o 21 | 22 | ifeq ($(CONFIG_CAN_DEBUG_DEVICES),y) 23 | EXTRA_CFLAGS += -DDEBUG 24 | endif 25 | 26 | endif 27 | -------------------------------------------------------------------------------- /drivers/net/can/mscan/Kconfig: -------------------------------------------------------------------------------- 1 | config CAN_MSCAN 2 | depends on CAN_DEV && (PPC || M68K || M68KNOMMU) 3 | tristate "Support for Freescale MSCAN based chips" 4 | ---help--- 5 | The Motorola Scalable Controller Area Network (MSCAN) definition 6 | is based on the MSCAN12 definition which is the specific 7 | implementation of the Motorola Scalable CAN concept targeted for 8 | the Motorola MC68HC12 Microcontroller Family. 9 | 10 | if CAN_MSCAN 11 | 12 | config CAN_MPC5XXX 13 | tristate "Freescale MPC5xxx onboard CAN controller" 14 | depends on (PPC_MPC52xx || PPC_MPC512x) 15 | ---help--- 16 | If you say yes here you get support for Freescale's MPC5xxx 17 | onboard CAN controller. Currently, the MPC5200, MPC5200B and 18 | MPC5121 (Rev. 2 and later) are supported. 19 | 20 | This driver can also be built as a module. If so, the module 21 | will be called mscan-mpc5xxx.ko. 22 | 23 | config CAN_MPC52XX 24 | tristate "Freescale MPC5200 onboard CAN controller (old)" 25 | depends on CAN_MSCAN && (PPC_MPC52xx || PPC_52xx) 26 | default LITE5200 27 | ---help--- 28 | If you say yes here you get support for Freescale MPC5200 29 | onboard dualCAN controller. This selects the old driver 30 | still available for backward compatibility. If possible, 31 | please use the new CAN_MPC5XXX driver. 32 | 33 | This driver can also be built as a module. If so, the module 34 | will be called mscan-mpc52xx.ko. 35 | 36 | endif 37 | 38 | -------------------------------------------------------------------------------- /drivers/net/can/mscan/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | 5 | ifeq ($(KERNELRELEASE),) 6 | 7 | KERNELDIR := /lib/modules/$(shell uname -r)/build 8 | PWD := $(shell pwd) 9 | TOPDIR := $(PWD)/../../../.. 10 | 11 | modules modules_install clean: 12 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 13 | 14 | else 15 | 16 | -include $(TOPDIR)/Makefile.common 17 | 18 | obj-$(CONFIG_CAN_MPC52XX) += mscan-mpc52xx.o 19 | mscan-mpc52xx-objs := mscan.o mpc52xx_can.o 20 | 21 | obj-$(CONFIG_CAN_MPC5XXX) += mscan-mpc5xxx.o 22 | mscan-mpc5xxx-objs := mscan.o mpc5xxx_can.o 23 | 24 | ifeq ($(CONFIG_CAN_DEBUG_DEVICES),y) 25 | EXTRA_CFLAGS += -DDEBUG 26 | endif 27 | 28 | endif 29 | -------------------------------------------------------------------------------- /drivers/net/can/old/Kconfig: -------------------------------------------------------------------------------- 1 | 2 | config CAN_SJA1000_OLD 3 | depends on CAN_OLD_DRIVERS 4 | tristate "Philips SJA1000 (old)" 5 | ---help--- 6 | The SJA1000 is one of the top CAN controllers out there. As it 7 | has a multiplexed interface it fits directly to 8051 8 | microcontrollers or into the PC I/O port space. The SJA1000 9 | is a full CAN controller, with shadow registers for RX and TX. 10 | It can send and receive any kinds of CAN frames (SFF/EFF/RTR) 11 | with a single (simple) filter setup. 12 | REMARK: This is the 'old' driver originally written by Matthias 13 | Brukner and Oliver Hartkopp which uses a non-standard hardware 14 | abstaction layer (HAL) inspired by the OCAN driver. 15 | 16 | config CAN_I82527_OLD 17 | depends on CAN_OLD_DRIVERS 18 | tristate "Intel 82527 (old)" 19 | ---help--- 20 | The i82527 is a complex CAN controller that can handle RTR 21 | frame replies on it's own. This feature (and diffent RX filters) 22 | lead to an amount of 15 message objects (for RX & TX). Message 23 | object 15 has (as only) a shadow register for a reliable 24 | receiption of EFF or(!) SFF frames at high CAN traffic. 25 | This driver can send each type of CAN frames (SFF/EFF/RTR). 26 | Using 4 message objects it can also receive each type of CAN 27 | frames. But due to the onchip filter matching trigger method 28 | it is not possible to determine the received RTR CAN-ID. 29 | The reliable message object 15 receives SFF frames by default. 30 | This message object 15 usage maybe changed with the mo15 param. 31 | REMARK: This is the 'old' driver originally written by Oliver 32 | Hartkopp which uses a non-standard hardware abstaction layer (HAL) 33 | inspired by the OCAN driver. http://ar.linux.it/software/#ocan 34 | 35 | config CAN_MSCAN_OLD 36 | depends on CAN_OLD_DRIVERS && (PPC || M68K || M68KNOMMU) 37 | tristate "Support for a Freescale MSCAN based chips (old)" 38 | ---help--- 39 | The Motorola Scalable Controller Area Network (MSCAN) definition 40 | is based on the MSCAN12 definition which is the specific 41 | implementation of the Motorola Scalable CAN concept targeted for 42 | the Motorola MC68HC12 Microcontroller Family. 43 | 44 | config CAN_MPC52XX_OLD 45 | tristate "Freescale MPC5200 onboard CAN controller (old)" 46 | depends on CAN_MSCAN_OLD && (PPC_MPC52xx || PPC_52xx) 47 | default LITE5200 48 | ---help--- 49 | If you say yes here you get support for Freescale MPC5200 50 | onboard dualCAN controller. 51 | 52 | This driver can also be built as a module. If so, the module 53 | will be called mpc52xx_can. 54 | 55 | config CAN_CCAN_OLD 56 | depends on CAN_OLD_DRIVERS 57 | tristate "Bosch CCAN driver (old)" 58 | ---help--- 59 | This is a driver for the Bosch CCAN controller found for example 60 | on the hynix h7202 chip. 61 | 62 | config CAN_H7202_OLD 63 | tristate "Hynix H7202 onboard CAN controller (old)" 64 | depends on CAN_CCAN_OLD 65 | ---help--- 66 | This is a driver for the hynix h7202 can controller. 67 | 68 | -------------------------------------------------------------------------------- /drivers/net/can/old/ccan/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: Makefile 438 2007-07-21 17:53:09Z hartkopp $ 3 | # 4 | 5 | ifeq ($(KERNELRELEASE),) 6 | 7 | KERNELDIR := /lib/modules/$(shell uname -r)/build 8 | PWD := $(shell pwd) 9 | TOPDIR := $(PWD)/../../../.. 10 | 11 | modules modules_install clean: 12 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 13 | 14 | else 15 | 16 | -include $(TOPDIR)/Makefile.common 17 | 18 | obj-$(CONFIG_CAN_CCAN_OLD) += ccan.o 19 | obj-$(CONFIG_CAN_H7202_OLD) += h7202_can.o 20 | 21 | endif 22 | -------------------------------------------------------------------------------- /drivers/net/can/old/ccan/ccan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * drivers/can/c_can.h 3 | * 4 | * Copyright (C) 2007 5 | * 6 | * - Sascha Hauer, Marc Kleine-Budde, Pengutronix 7 | * - Simon Kallweit, intefo AG 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the version 2 of the GNU General Public License 11 | * as published by the Free Software Foundation 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #ifndef __CCAN_H__ 24 | #define __CCAN_H__ 25 | 26 | #include 27 | #include 28 | 29 | #undef CCAN_DEBUG 30 | 31 | enum c_regs { 32 | CAN_CONTROL = 0x00, 33 | CAN_STATUS = 0x02, 34 | CAN_ERROR = 0x04, 35 | CAN_BTR = 0x06, 36 | CAN_IR = 0x08, 37 | CAN_TEST = 0x0a, 38 | CAN_BRP_EXT = 0x0c, 39 | CAN_IF1 = 0x10, 40 | CAN_IF2 = 0x40, 41 | CAN_TXRQST = 0x80, /* 32bit */ 42 | CAN_NEWDAT = 0x90, /* 32bit */ 43 | CAN_INTPND = 0xa0, /* 32bit */ 44 | CAN_MSGVAL = 0xb0, /* 32bit */ 45 | }; 46 | 47 | #define CAN_IF_COMR(x) (CAN_IF1 + (x) * 0x30 + 0x00) 48 | #define CAN_IF_COMM(x) (CAN_IF1 + (x) * 0x30 + 0x02) 49 | #define CAN_IF_MASK(x) (CAN_IF1 + (x) * 0x30 + 0x04) /* 32bit */ 50 | #define CAN_IF_ARB(x) (CAN_IF1 + (x) * 0x30 + 0x08) /* 32bit */ 51 | #define CAN_IF_MCONT(x) (CAN_IF1 + (x) * 0x30 + 0x0c) 52 | #define CAN_IF_DATAA(x) (CAN_IF1 + (x) * 0x30 + 0x0e) /* 32bit */ 53 | #define CAN_IF_DATAB(x) (CAN_IF1 + (x) * 0x30 + 0x12) /* 32bit */ 54 | 55 | #define CONTROL_TEST (1<<7) 56 | #define CONTROL_CCE (1<<6) 57 | #define CONTROL_DAR (1<<5) 58 | #define CONTROL_EIE (1<<3) 59 | #define CONTROL_SIE (1<<2) 60 | #define CONTROL_IE (1<<1) 61 | #define CONTROL_INIT (1<<0) 62 | 63 | #define TEST_RX (1<<7) 64 | #define TEST_TX1 (1<<6) 65 | #define TEST_TX2 (1<<5) 66 | #define TEST_LBACK (1<<4) 67 | #define TEST_SILENT (1<<3) 68 | #define TEST_BASIC (1<<2) 69 | 70 | #define STATUS_BOFF (1<<7) 71 | #define STATUS_EWARN (1<<6) 72 | #define STATUS_EPASS (1<<5) 73 | #define STATUS_RXOK (1<<4) 74 | #define STATUS_TXOK (1<<3) 75 | #define STATUS_LEC_MASK (1<<2) 76 | #define LEC_STUFF_ERROR 1 77 | #define LEC_FORM_ERROR 2 78 | #define LEC_ACK_ERROR 3 79 | #define LEC_BIT1_ERROR 4 80 | 81 | #define BTR_BRP_MASK 0x3f 82 | #define BTR_BRP_SHIFT 0 83 | #define BTR_SJW_SHIFT 6 84 | #define BTR_SJW_MASK (0x3 << BTR_SJW_SHIFT) 85 | #define BTR_TSEG1_SHIFT 8 86 | #define BTR_TSEG1_MASK (0xf << BTR_TSEG1_SHIFT) 87 | #define BTR_TSEG2_SHIFT 12 88 | #define BTR_TSEG2_MASK (0x7 << BTR_TSEG2_SHIFT) 89 | 90 | #define IF_COMR_BUSY (1<<15) 91 | 92 | #define IF_COMM_WR (1<<7) 93 | #define IF_COMM_MASK (1<<6) 94 | #define IF_COMM_ARB (1<<5) 95 | #define IF_COMM_CONTROL (1<<4) 96 | #define IF_COMM_CLR_INT_PND (1<<3) 97 | #define IF_COMM_TXRQST (1<<2) 98 | #define IF_COMM_DATAA (1<<1) 99 | #define IF_COMM_DATAB (1<<0) 100 | 101 | #define IF_COMM_ALL (IF_COMM_MASK | IF_COMM_ARB | IF_COMM_CONTROL | \ 102 | IF_COMM_TXRQST | IF_COMM_DATAA | IF_COMM_DATAB) 103 | 104 | #define IF_ARB_MSGVAL (1<<31) 105 | #define IF_ARB_MSGXTD (1<<30) 106 | #define IF_ARB_TRANSMIT (1<<29) 107 | 108 | #define IF_MCONT_NEWDAT (1<<15) 109 | #define IF_MCONT_MSGLST (1<<14) 110 | #define IF_MCONT_INTPND (1<<13) 111 | #define IF_MCONT_UMASK (1<<12) 112 | #define IF_MCONT_TXIE (1<<11) 113 | #define IF_MCONT_RXIE (1<<10) 114 | #define IF_MCONT_RMTEN (1<<9) 115 | #define IF_MCONT_TXRQST (1<<8) 116 | #define IF_MCONT_EOB (1<<7) 117 | 118 | #define MAX_OBJECT 31 119 | #define MAX_TRANSMIT_OBJECT 15 120 | #define RECEIVE_OBJECT_BITS 0xffff0000 121 | 122 | struct ccan_priv { 123 | struct can_priv can; 124 | struct net_device *dev; 125 | int tx_object; 126 | int last_status; 127 | struct delayed_work work; 128 | u16 (*read_reg)(struct net_device *dev, enum c_regs reg); 129 | void (*write_reg)(struct net_device *dev, enum c_regs reg, u16 val); 130 | #ifdef CCAN_DEBUG 131 | unsigned int bufstat[MAX_OBJECT + 1]; 132 | #endif 133 | }; 134 | 135 | extern struct net_device *alloc_ccandev(int sizeof_priv); 136 | extern void free_ccandev(struct net_device *dev); 137 | extern int register_ccandev(struct net_device *dev); 138 | extern void unregister_ccandev(struct net_device *dev); 139 | 140 | #endif /* __CCAN_H__ */ 141 | -------------------------------------------------------------------------------- /drivers/net/can/old/ccan/h7202_can.c: -------------------------------------------------------------------------------- 1 | /* 2 | * drivers/can/h7202_can.c 3 | * 4 | * Copyright (C) 2007 5 | * 6 | * - Sascha Hauer, Marc Kleine-Budde, Pengutronix 7 | * - Simon Kallweit, intefo AG 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the version 2 of the GNU General Public License 11 | * as published by the Free Software Foundation 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) 31 | #include 32 | #else 33 | #include 34 | #endif 35 | #include 36 | 37 | #include "ccan.h" 38 | 39 | #define DRV_NAME "h7202can" 40 | #define DELAY 5 41 | #define CAN_ENABLE 0x0e 42 | 43 | static u16 h7202can_read_reg(struct net_device *dev, enum c_regs reg) 44 | { 45 | u16 val; 46 | volatile int i; 47 | 48 | /* The big kernel lock is used to prevent any other AMBA devices from 49 | * interfering with the current register read operation. The register 50 | * is read twice because of braindamaged hynix cpu. 51 | */ 52 | lock_kernel(); 53 | val = inw(dev->base_addr + (reg<<1)); 54 | for (i = 0; i < DELAY; i++); 55 | val = inw(dev->base_addr + (reg<<1)); 56 | for (i = 0; i < DELAY; i++); 57 | unlock_kernel(); 58 | 59 | return val; 60 | } 61 | 62 | static void h7202can_write_reg(struct net_device *dev, enum c_regs reg, u16 val) 63 | { 64 | volatile int i; 65 | 66 | lock_kernel(); 67 | outw(val, dev->base_addr + (reg<<1)); 68 | for (i = 0; i < DELAY; i++); 69 | unlock_kernel(); 70 | } 71 | 72 | static int h7202can_drv_probe(struct platform_device *pdev) 73 | { 74 | struct net_device *dev; 75 | struct ccan_priv *priv; 76 | struct resource *mem; 77 | u32 mem_size; 78 | int ret = -ENODEV; 79 | 80 | dev = alloc_ccandev(sizeof(struct ccan_priv)); 81 | if (!dev) 82 | return -ENOMEM; 83 | 84 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 85 | dev->irq = platform_get_irq(pdev, 0); 86 | if (!mem || !dev->irq) 87 | goto req_error; 88 | 89 | mem_size = mem->end - mem->start + 1; 90 | if (!request_mem_region(mem->start, mem_size, pdev->dev.driver->name)) { 91 | dev_err(&pdev->dev, "resource unavailable\n"); 92 | goto req_error; 93 | } 94 | 95 | SET_NETDEV_DEV(dev, &pdev->dev); 96 | 97 | dev->base_addr = (unsigned long)ioremap_nocache(mem->start, mem_size); 98 | 99 | if (!dev->base_addr) { 100 | dev_err(&pdev->dev, "failed to map can port\n"); 101 | ret = -ENOMEM; 102 | goto fail_map; 103 | } 104 | 105 | priv = netdev_priv(dev); 106 | priv->can.can_sys_clock = 8000000; 107 | priv->read_reg = h7202can_read_reg; 108 | priv->write_reg = h7202can_write_reg; 109 | 110 | platform_set_drvdata(pdev, dev); 111 | 112 | /* configure ports */ 113 | switch (mem->start) { 114 | case CAN0_PHYS: 115 | CPU_REG(GPIO_C_VIRT, GPIO_EN) &= ~(3<<1); 116 | CPU_REG(GPIO_C_VIRT, GPIO_DIR) &= ~(1<<1); 117 | CPU_REG(GPIO_C_VIRT, GPIO_DIR) |= (1<<2); 118 | break; 119 | case CAN1_PHYS: 120 | CPU_REG(GPIO_E_VIRT, GPIO_EN) &= ~(3<<16); 121 | CPU_REG(GPIO_E_VIRT, GPIO_DIR) |= (1<<16); 122 | CPU_REG(GPIO_E_VIRT, GPIO_DIR) &= ~(1<<17); 123 | break; 124 | } 125 | 126 | /* enable can */ 127 | h7202can_write_reg(dev, CAN_ENABLE, 1); 128 | 129 | ret = register_ccandev(dev); 130 | if (ret >= 0) { 131 | dev_info(&pdev->dev, "probe for a port 0x%lX done\n", 132 | dev->base_addr); 133 | return ret; 134 | } 135 | 136 | iounmap((unsigned long *)dev->base_addr); 137 | fail_map: 138 | release_mem_region(mem->start, mem_size); 139 | req_error: 140 | free_ccandev(dev); 141 | dev_err(&pdev->dev, "probe failed\n"); 142 | return ret; 143 | } 144 | 145 | static int h7202can_drv_remove(struct platform_device *pdev) 146 | { 147 | struct net_device *dev = platform_get_drvdata(pdev); 148 | struct resource *mem; 149 | 150 | platform_set_drvdata(pdev, NULL); 151 | unregister_ccandev(dev); 152 | 153 | iounmap((volatile void __iomem *)(dev->base_addr)); 154 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 155 | release_mem_region(mem->start, mem->end - mem->start + 1); 156 | free_ccandev(dev); 157 | return 0; 158 | } 159 | 160 | #ifdef CONFIG_PM 161 | static int h7202can_drv_suspend(struct platform_device *pdev, 162 | pm_message_t state) 163 | { 164 | return 0; 165 | } 166 | 167 | static int h7202can_drv_resume(struct platform_device *pdev) 168 | { 169 | return 0; 170 | } 171 | #endif /* CONFIG_PM */ 172 | 173 | static struct platform_driver h7202can_driver = { 174 | .driver = { 175 | .name = DRV_NAME, 176 | }, 177 | .probe = h7202can_drv_probe, 178 | .remove = h7202can_drv_remove, 179 | #ifdef CONFIG_PM 180 | .suspend = h7202can_drv_suspend, 181 | .resume = h7202can_drv_resume, 182 | #endif /* CONFIG_PM */ 183 | }; 184 | 185 | static int __init h7202can_init(void) 186 | { 187 | printk(KERN_INFO "%s initializing\n", h7202can_driver.driver.name); 188 | return platform_driver_register(&h7202can_driver); 189 | } 190 | 191 | static void __exit h7202can_cleanup(void) 192 | { 193 | platform_driver_unregister(&h7202can_driver); 194 | printk(KERN_INFO "%s unloaded\n", h7202can_driver.driver.name); 195 | } 196 | 197 | module_init(h7202can_init); 198 | module_exit(h7202can_cleanup); 199 | 200 | MODULE_AUTHOR("Sascha Hauer "); 201 | MODULE_AUTHOR("Simon Kallweit "); 202 | MODULE_LICENSE("GPL v2"); 203 | MODULE_DESCRIPTION("CAN port driver Hynix H7202 processor"); 204 | -------------------------------------------------------------------------------- /drivers/net/can/old/hal/c200.c: -------------------------------------------------------------------------------- 1 | /* 2 | * c200.c - low cost parallelport CAN adaptor hardware abstraction layer 3 | * ( direct register access without parport subsystem support ) 4 | * 5 | * CAN200 project homepage http://private.addcom.de/horo/can200 6 | * 7 | * This hal is based on a patch from Uwe Bonnes. 8 | * 9 | * $Id$ 10 | * 11 | * Inspired by the OCAN driver http://ar.linux.it/software/#ocan 12 | * 13 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions 18 | * are met: 19 | * 1. Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright 22 | * notice, this list of conditions and the following disclaimer in the 23 | * documentation and/or other materials provided with the distribution. 24 | * 3. Neither the name of Volkswagen nor the names of its contributors 25 | * may be used to endorse or promote products derived from this software 26 | * without specific prior written permission. 27 | * 28 | * Alternatively, provided that this notice is retained in full, this 29 | * software may be distributed under the terms of the GNU General 30 | * Public License ("GPL") version 2, in which case the provisions of the 31 | * GPL apply INSTEAD OF those given above. 32 | * 33 | * The provided data structures and external interfaces from this code 34 | * are not restricted to be used by modules with a GPL compatible license. 35 | * 36 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 37 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 39 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 40 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 43 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 44 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 45 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 46 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 47 | * DAMAGE. 48 | * 49 | * Send feedback to 50 | * 51 | */ 52 | 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include "hal.h" 58 | 59 | /* init the HAL - call at driver module init */ 60 | int hal_init(void) { return 0; } 61 | 62 | /* exit the HAL - call at driver module exit */ 63 | int hal_exit(void) { return 0; } 64 | 65 | /* get name of this CAN HAL */ 66 | char *hal_name(void) { return "c200"; } 67 | 68 | /* fill arrays base[] and irq[] with HAL specific defaults */ 69 | void hal_use_defaults(void) 70 | { 71 | extern unsigned long base[]; 72 | extern unsigned int irq[]; 73 | 74 | base[0] = 0x378UL; 75 | irq[0] = 7; 76 | } 77 | 78 | #define ECR_REGS_OFFSET 0x400 79 | #define ECR_CTRL_OFFSET (ECR_REGS_OFFSET + 2) 80 | 81 | static u8 ecr_crtl_save; 82 | 83 | /* request controller register access space */ 84 | int hal_request_region(int dev_num, 85 | unsigned int num_regs, 86 | char *drv_name) 87 | { 88 | extern unsigned long base[]; 89 | extern unsigned long rbase[]; 90 | 91 | /* set for device base_addr */ 92 | rbase[dev_num] = base[dev_num]; 93 | 94 | /* grab ECR control registers and set parport to 'byte mode' */ 95 | if (request_region(rbase[dev_num] + ECR_REGS_OFFSET, 3, drv_name)) { 96 | 97 | ecr_crtl_save = inb(rbase[dev_num] + ECR_CTRL_OFFSET); 98 | 99 | outb((ecr_crtl_save & 0x1F) | 0x20, 100 | rbase[dev_num] + ECR_CTRL_OFFSET); 101 | } else 102 | return 0; 103 | 104 | if (request_region(rbase[dev_num], 4, drv_name)) 105 | return 1; 106 | 107 | release_region(rbase[dev_num] + ECR_REGS_OFFSET, 3); 108 | 109 | return 0; 110 | } 111 | 112 | /* release controller register access space */ 113 | void hal_release_region(int dev_num, 114 | unsigned int num_regs) 115 | { 116 | extern unsigned long base[]; 117 | 118 | release_region(base[dev_num], 4); 119 | 120 | /* restore original ECR control register value */ 121 | outb(ecr_crtl_save, base[dev_num] + ECR_CTRL_OFFSET); 122 | release_region(base[dev_num] + ECR_REGS_OFFSET, 3); 123 | } 124 | 125 | /* enable non controller hardware (e.g. irq routing, etc.) */ 126 | int hw_attach(int dev_num) 127 | { 128 | extern unsigned long rbase[]; 129 | unsigned long pc = rbase[dev_num] + 2; 130 | 131 | /* enable irq */ 132 | outb(inb(pc) | 0x10, pc); 133 | 134 | return 0; 135 | } 136 | 137 | /* disable non controller hardware (e.g. irq routing, etc.) */ 138 | int hw_detach(int dev_num) 139 | { 140 | extern unsigned long rbase[]; 141 | unsigned long pc = rbase[dev_num] + 2; 142 | 143 | /* disable irq */ 144 | outb(inb(pc) & ~0x10, pc); 145 | 146 | return 0; 147 | } 148 | 149 | /* reset controller hardware (with specific non controller hardware) */ 150 | int hw_reset_dev(int dev_num) { return 0; } 151 | 152 | #define WRITEP 0x01 /* inverted at port */ 153 | #define DATASTB 0x02 /* inverted at port and at device*/ 154 | #define ADDRSTB 0x08 /* inverted at port and at device*/ 155 | #define PORTREAD 0x20 156 | 157 | static DEFINE_SPINLOCK(c200_lock); 158 | 159 | /* read from controller register */ 160 | u8 hw_readreg(unsigned long base, int reg) 161 | { 162 | unsigned long pa = base; 163 | unsigned long pc = pa + 2; 164 | unsigned long flags; 165 | u8 irqstatus = (inb(pc) & 0x10) | 0x04; 166 | u8 val; 167 | 168 | spin_lock_irqsave(&c200_lock, flags); 169 | 170 | outb(irqstatus | ADDRSTB, pc); 171 | outb((reg & 0x1F) | 0x80, pa); 172 | outb(irqstatus, pc); 173 | outb(irqstatus | PORTREAD, pc); 174 | outb(irqstatus | DATASTB | PORTREAD, pc); 175 | val = inb(pa); 176 | outb(irqstatus, pc); 177 | 178 | spin_unlock_irqrestore(&c200_lock, flags); 179 | 180 | return val; 181 | } 182 | 183 | /* write to controller register */ 184 | void hw_writereg(unsigned long base, int reg, u8 val) 185 | { 186 | unsigned long pa = base; 187 | unsigned long pc = pa + 2; 188 | unsigned long flags; 189 | u8 irqstatus = (inb(pc) & 0x10) | 0x04; 190 | 191 | spin_lock_irqsave(&c200_lock, flags); 192 | 193 | outb(irqstatus | ADDRSTB, pc); 194 | outb(reg & 0x1F, pa); 195 | outb(irqstatus, pc); 196 | outb(irqstatus | WRITEP, pc); 197 | outb(irqstatus | DATASTB | WRITEP, pc); 198 | outb(val, pa); 199 | outb(irqstatus, pc); 200 | 201 | spin_unlock_irqrestore(&c200_lock, flags); 202 | } 203 | 204 | /* hardware specific work to do at start of irq handler */ 205 | void hw_preirq(struct net_device *dev) { return; } 206 | 207 | /* hardware specific work to do at end of irq handler */ 208 | void hw_postirq(struct net_device *dev) { return; } 209 | -------------------------------------------------------------------------------- /drivers/net/can/old/hal/esdio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * esdio.c - multiplex register access CAN hardware abstraction layer 3 | * for the esd 3xCAN pc104 board 4 | * http://www.esd-electronics.de/products/CAN/can-pc104-200_e.htm 5 | * 6 | * $Id$ 7 | * 8 | * Inspired by the OCAN driver http://ar.linux.it/software/#ocan 9 | * 10 | * Copyright (c) 2007 Fraunhofer FOKUS 11 | * 12 | * Provided that this notice is retained in full, this 13 | * software may be distributed under the terms of the GNU General 14 | * Public License ("GPL") version 2, in which case the provisions of the 15 | * GPL apply INSTEAD OF those given above. 16 | * 17 | * The provided data structures and external interfaces from this code 18 | * are not restricted to be used by modules with a GPL compatible license. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 31 | * DAMAGE. 32 | * 33 | * Send feedback to 34 | * 35 | * History: 36 | * 2007-05-22 Bjoern Riemer: initial release 37 | */ 38 | 39 | #include 40 | #include 41 | #include 42 | #include "hal.h" 43 | 44 | #ifdef CONFIG_CAN_DEBUG_DEVICES 45 | #define DBG(args...) printk(args) 46 | #else 47 | #define DBG(args...) 48 | #endif 49 | 50 | //#define DBG(args...) printk(args) 51 | 52 | int esd_ale_offset = 1; //default for the sja1000 chip 53 | int esd_cs_offset = 0; //default for the sja1000 chip 54 | 55 | /* init the HAL - call at driver module init */ 56 | int hal_init(void) { return 0; } 57 | 58 | /* exit the HAL - call at driver module exit */ 59 | int hal_exit(void) { return 0; } 60 | 61 | /* get name of this CAN HAL */ 62 | char *hal_name(void) { return "esdio"; } 63 | 64 | /* fill arrays base[] and irq[] with HAL specific defaults */ 65 | void hal_use_defaults(void) 66 | { 67 | extern unsigned long base[]; 68 | extern unsigned int irq[]; 69 | 70 | base[0] = 0x1e8UL; 71 | irq[0] = 5; 72 | } 73 | 74 | /* request controller register access space */ 75 | int hal_request_region(int dev_num, 76 | unsigned int num_regs, 77 | char *drv_name) 78 | { 79 | extern unsigned long base[]; 80 | extern unsigned long rbase[]; 81 | 82 | if (!memcmp(drv_name,"i82527-esdio",sizeof("i82527-esdio"))){ 83 | esd_ale_offset = 7; 84 | esd_cs_offset = 4; 85 | } else if (!memcmp(drv_name,"sja1000-esdio",sizeof("sja1000-esdio"))){ 86 | esd_ale_offset = 1; 87 | esd_cs_offset = 0; 88 | } 89 | 90 | /* set for device base_addr */ 91 | rbase[dev_num] = base[dev_num]; 92 | 93 | /* ignore num_regs and create the 2 register region: */ 94 | /* address register = base + esd_ale_offset */ 95 | /* data register = base + esd_cs_offset */ 96 | if (request_region(base[dev_num] + esd_ale_offset, 1, drv_name)){ 97 | if (request_region(base[dev_num] + esd_cs_offset, 1,drv_name)){ 98 | return 1; 99 | } else { 100 | release_region(base[dev_num]+esd_ale_offset, 1); 101 | return 0; // error 102 | } 103 | } 104 | 105 | return 0; // error 106 | } 107 | 108 | /* release controller register access space */ 109 | void hal_release_region(int dev_num, 110 | unsigned int num_regs) 111 | { 112 | extern unsigned long base[]; 113 | 114 | /* ignore num_regs and create the 2 register region: */ 115 | /* address register = base + esd_ale_offset */ 116 | /* data register = base + esd_cs_offset */ 117 | release_region(base[dev_num] + esd_cs_offset, 1); 118 | release_region(base[dev_num] + esd_ale_offset, 1); 119 | } 120 | 121 | /* enable non controller hardware (e.g. irq routing, etc.) */ 122 | int hw_attach(int dev_num) 123 | { 124 | int i, stat, i1; 125 | extern unsigned long base[]; 126 | extern unsigned int irq[]; 127 | 128 | i1 = irq[dev_num]; //get IRQ number 129 | DBG(KERN_INFO "esdio.c: enabling IRQ %d for dev_num %d\n",i1,dev_num); 130 | 131 | for (i=0; i<4; i++){ 132 | stat=i; // bit 0,1 selects the latch bit to write 133 | if (i1 & 0x01){ 134 | stat |= 0x80; //bit7 carrys the value of the latch bit 135 | } 136 | outb(stat,base[dev_num]+3); 137 | i1 = i1>>1; 138 | } 139 | 140 | outb(0x87,base[dev_num]+3); //enable irq selection 141 | outb(0x86,base[dev_num]+3); //enable irq tristate buffer 142 | 143 | return 1; 144 | } 145 | 146 | /* disable non controller hardware (e.g. irq routing, etc.) */ 147 | int hw_detach(int dev_num) 148 | { 149 | int i; 150 | extern unsigned long base[]; 151 | 152 | DBG(KERN_INFO "esdio.c: diabling IRQ for dev_num %d\n",dev_num); 153 | 154 | outb(0x07,base[dev_num]+3); //disable irq selection 155 | outb(0x06,base[dev_num]+3); //disable irq tristate buffer 156 | 157 | for (i=0; i<4; i++) 158 | outb(i,base[dev_num]+3); 159 | 160 | return 1; 161 | } 162 | 163 | /* reset controller hardware (with specific non controller hardware) */ 164 | int hw_reset_dev(int dev_num) { return 0; } 165 | 166 | /* read from controller register */ 167 | u8 hw_readreg(unsigned long base, int reg) { 168 | 169 | outb(reg, base + esd_ale_offset); /* address */ 170 | return inb(base + esd_cs_offset); /* data */ 171 | } 172 | 173 | /* write to controller register */ 174 | void hw_writereg(unsigned long base, int reg, u8 val) { 175 | 176 | outb(reg, base + esd_ale_offset); /* address */ 177 | outb(val, base + esd_cs_offset); /* data */ 178 | } 179 | 180 | /* hardware specific work to do at start of irq handler */ 181 | void hw_preirq(struct net_device *dev) { return; } 182 | 183 | /* hardware specific work to do at end of irq handler */ 184 | void hw_postirq(struct net_device *dev) { 185 | 186 | outb(0x86,dev->base_addr+3); //enable irq tristate buffer 187 | return; 188 | } 189 | -------------------------------------------------------------------------------- /drivers/net/can/old/hal/gw2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * gw2.c - Trajet GW2 register access CAN hardware abstraction layer 3 | * 4 | * $Id$ 5 | * 6 | * Inspired by the OCAN driver http://ar.linux.it/software/#ocan 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 45 | * 46 | */ 47 | 48 | #include 49 | #include 50 | #include 51 | #include "hal.h" 52 | 53 | #define ADDR_GAP 1 54 | 55 | /* init the HAL - call at driver module init */ 56 | int hal_init(void) { return 0; } 57 | 58 | /* exit the HAL - call at driver module exit */ 59 | int hal_exit(void) { return 0; } 60 | 61 | /* get name of this CAN HAL */ 62 | char *hal_name(void) { return "gw2"; } 63 | 64 | /* fill arrays base[] and irq[] with HAL specific defaults */ 65 | void hal_use_defaults(void) 66 | { 67 | extern unsigned long base[]; 68 | extern unsigned int irq[]; 69 | extern unsigned int speed[]; 70 | 71 | base[0] = 0xF0100200UL; 72 | irq[0] = 26; 73 | speed[0] = 500; 74 | 75 | base[1] = 0xF0100300UL; 76 | irq[1] = 26; 77 | speed[1] = 100; 78 | 79 | base[2] = 0xF0100400UL; 80 | irq[2] = 26; 81 | speed[2] = 100; 82 | 83 | base[3] = 0xF0100500UL; 84 | irq[3] = 26; 85 | speed[3] = 500; 86 | } 87 | 88 | /* request controller register access space */ 89 | int hal_request_region(int dev_num, 90 | unsigned int num_regs, 91 | char *drv_name) 92 | { 93 | extern unsigned long base[]; 94 | extern unsigned long rbase[]; 95 | 96 | unsigned int gw2_regs = num_regs * (ADDR_GAP + 1); 97 | 98 | /* creating the region for IOMEM is pretty easy */ 99 | if (!request_mem_region(base[dev_num], gw2_regs, drv_name)) 100 | return 0; /* failed */ 101 | 102 | /* set device base_addr */ 103 | rbase[dev_num] = (unsigned long)ioremap(base[dev_num], gw2_regs); 104 | 105 | if (rbase[dev_num]) 106 | return 1; /* success */ 107 | 108 | /* cleanup due to failed ioremap() */ 109 | release_mem_region(base[dev_num], gw2_regs); 110 | return 0; /* failed */ 111 | } 112 | 113 | /* release controller register access space */ 114 | void hal_release_region(int dev_num, 115 | unsigned int num_regs) 116 | { 117 | extern unsigned long base[]; 118 | extern unsigned long rbase[]; 119 | 120 | unsigned int gw2_regs = num_regs * (ADDR_GAP + 1); 121 | 122 | iounmap((void *)rbase[dev_num]); 123 | release_mem_region(base[dev_num], gw2_regs); 124 | } 125 | 126 | /* enable non controller hardware (e.g. irq routing, etc.) */ 127 | int hw_attach(int dev_num) { return 0; } 128 | 129 | /* disable non controller hardware (e.g. irq routing, etc.) */ 130 | int hw_detach(int dev_num) { return 0; } 131 | 132 | /* reset controller hardware (with specific non controller hardware) */ 133 | int hw_reset_dev(int dev_num) { return 0; } 134 | 135 | /* read from controller register */ 136 | u8 hw_readreg(unsigned long base, int reg) { 137 | 138 | static u8 val; 139 | void __iomem *addr = (void __iomem *)base + 140 | reg * (ADDR_GAP + 1) + ADDR_GAP; 141 | 142 | val = (u8)readw(addr); 143 | rmb(); 144 | 145 | return val; 146 | } 147 | 148 | /* write to controller register */ 149 | void hw_writereg(unsigned long base, int reg, u8 val) { 150 | 151 | void __iomem *addr = (void __iomem *)base + 152 | reg * (ADDR_GAP + 1) + ADDR_GAP; 153 | 154 | writew(val, addr); 155 | wmb(); 156 | } 157 | 158 | /* hardware specific work to do at start of irq handler */ 159 | void hw_preirq(struct net_device *dev) { return; } 160 | 161 | /* hardware specific work to do at end of irq handler */ 162 | void hw_postirq(struct net_device *dev) { return; } 163 | 164 | -------------------------------------------------------------------------------- /drivers/net/can/old/hal/hal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * hal.h - definitions for CAN controller hardware abstraction layer 3 | * 4 | * Inspired by the OCAN driver http://ar.linux.it/software/#ocan 5 | * 6 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. Neither the name of Volkswagen nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * Alternatively, provided that this notice is retained in full, this 22 | * software may be distributed under the terms of the GNU General 23 | * Public License ("GPL") version 2, in which case the provisions of the 24 | * GPL apply INSTEAD OF those given above. 25 | * 26 | * The provided data structures and external interfaces from this code 27 | * are not restricted to be used by modules with a GPL compatible license. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 40 | * DAMAGE. 41 | * 42 | * Send feedback to 43 | * 44 | */ 45 | 46 | #ifndef CAN_HAL_H 47 | #define CAN_HAL_H 48 | 49 | #include 50 | #include 51 | 52 | /* Number of supported CAN devices for each HAL (default) */ 53 | #define MAXDEV 8 54 | 55 | /* general function prototypes for CAN HAL */ 56 | 57 | /* init the HAL - call at driver module init */ 58 | int hal_init(void); 59 | 60 | /* exit the HAL - call at driver module exit */ 61 | int hal_exit(void); 62 | 63 | /* get name of this CAN HAL */ 64 | char *hal_name(void); 65 | 66 | /* fill arrays base[] and irq[] with HAL specific defaults */ 67 | void hal_use_defaults(void); 68 | 69 | /* request controller register access space */ 70 | int hal_request_region(int dev_num, 71 | unsigned int num_regs, 72 | char *drv_name); 73 | 74 | /* release controller register access space */ 75 | void hal_release_region(int dev_num, 76 | unsigned int num_regs); 77 | 78 | /* enable non controller hardware (e.g. irq routing, etc.) */ 79 | int hw_attach(int dev_num); 80 | 81 | /* disable non controller hardware (e.g. irq routing, etc.) */ 82 | int hw_detach(int dev_num); 83 | 84 | /* reset controller hardware (with specific non controller hardware) */ 85 | int hw_reset_dev(int dev_num); 86 | 87 | /* read from controller register */ 88 | u8 hw_readreg(unsigned long base, int reg); 89 | 90 | /* write to controller register */ 91 | void hw_writereg(unsigned long base, int reg, u8 val); 92 | 93 | /* hardware specific work to do at start of irq handler */ 94 | void hw_preirq(struct net_device *dev); 95 | 96 | /* hardware specific work to do at end of irq handler */ 97 | void hw_postirq(struct net_device *dev); 98 | 99 | #endif /* CAN_HAL_H */ 100 | -------------------------------------------------------------------------------- /drivers/net/can/old/hal/io.c: -------------------------------------------------------------------------------- 1 | /* 2 | * io.c - linear register access CAN hardware abstraction layer 3 | * 4 | * $Id$ 5 | * 6 | * Inspired by the OCAN driver http://ar.linux.it/software/#ocan 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 45 | * 46 | */ 47 | 48 | #include 49 | #include 50 | #include 51 | #include "hal.h" 52 | 53 | /* init the HAL - call at driver module init */ 54 | int hal_init(void) { return 0; } 55 | 56 | /* exit the HAL - call at driver module exit */ 57 | int hal_exit(void) { return 0; } 58 | 59 | /* get name of this CAN HAL */ 60 | char *hal_name(void) { return "io"; } 61 | 62 | /* fill arrays base[] and irq[] with HAL specific defaults */ 63 | void hal_use_defaults(void) 64 | { 65 | extern unsigned long base[]; 66 | extern unsigned int irq[]; 67 | 68 | base[0] = 0x2C0UL; 69 | irq[0] = 10; 70 | 71 | base[1] = 0x320UL; 72 | irq[1] = 5; 73 | } 74 | 75 | /* request controller register access space */ 76 | int hal_request_region(int dev_num, 77 | unsigned int num_regs, 78 | char *drv_name) 79 | { 80 | extern unsigned long base[]; 81 | extern unsigned long rbase[]; 82 | 83 | /* set for device base_addr */ 84 | rbase[dev_num] = base[dev_num]; 85 | 86 | /* creating the region for IO is pretty easy */ 87 | return (request_region(base[dev_num], num_regs, drv_name))? 1 : 0; 88 | } 89 | 90 | /* release controller register access space */ 91 | void hal_release_region(int dev_num, 92 | unsigned int num_regs) 93 | { 94 | extern unsigned long base[]; 95 | 96 | release_region(base[dev_num], num_regs); 97 | } 98 | 99 | /* enable non controller hardware (e.g. irq routing, etc.) */ 100 | int hw_attach(int dev_num) { return 0; } 101 | 102 | /* disable non controller hardware (e.g. irq routing, etc.) */ 103 | int hw_detach(int dev_num) { return 0; } 104 | 105 | /* reset controller hardware (with specific non controller hardware) */ 106 | int hw_reset_dev(int dev_num) { return 0; } 107 | 108 | /* read from controller register */ 109 | u8 hw_readreg(unsigned long base, int reg) { 110 | 111 | return inb(base + reg); 112 | } 113 | 114 | /* write to controller register */ 115 | void hw_writereg(unsigned long base, int reg, u8 val) { 116 | 117 | outb(val, base + reg); 118 | } 119 | 120 | /* hardware specific work to do at start of irq handler */ 121 | void hw_preirq(struct net_device *dev) { return; } 122 | 123 | /* hardware specific work to do at end of irq handler */ 124 | void hw_postirq(struct net_device *dev) { return; } 125 | 126 | -------------------------------------------------------------------------------- /drivers/net/can/old/hal/iomem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * iomem.c - linear register access CAN hardware abstraction layer 3 | * 4 | * $Id$ 5 | * 6 | * Inspired by the OCAN driver http://ar.linux.it/software/#ocan 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 45 | * 46 | */ 47 | 48 | #include 49 | #include 50 | #include 51 | #include "hal.h" 52 | 53 | /* init the HAL - call at driver module init */ 54 | int hal_init(void) { return 0; } 55 | 56 | /* exit the HAL - call at driver module exit */ 57 | int hal_exit(void) { return 0; } 58 | 59 | /* get name of this CAN HAL */ 60 | char *hal_name(void) { return "iomem"; } 61 | 62 | /* fill arrays base[] and irq[] with HAL specific defaults */ 63 | void hal_use_defaults(void) 64 | { 65 | extern unsigned long base[]; 66 | extern unsigned int irq[]; 67 | 68 | base[0] = 0xd8000UL; 69 | irq[0] = 5; 70 | 71 | base[1] = 0xd8100UL; 72 | irq[1] = 15; 73 | } 74 | 75 | /* request controller register access space */ 76 | int hal_request_region(int dev_num, 77 | unsigned int num_regs, 78 | char *drv_name) 79 | { 80 | extern unsigned long base[]; 81 | extern unsigned long rbase[]; 82 | 83 | /* creating the region for IOMEM is pretty easy */ 84 | if (!request_mem_region(base[dev_num], num_regs, drv_name)) 85 | return 0; /* failed */ 86 | 87 | /* set device base_addr */ 88 | rbase[dev_num] = (unsigned long)ioremap(base[dev_num], num_regs); 89 | 90 | if (rbase[dev_num]) 91 | return 1; /* success */ 92 | 93 | /* cleanup due to failed ioremap() */ 94 | release_mem_region(base[dev_num], num_regs); 95 | return 0; /* failed */ 96 | } 97 | 98 | /* release controller register access space */ 99 | void hal_release_region(int dev_num, 100 | unsigned int num_regs) 101 | { 102 | extern unsigned long base[]; 103 | extern unsigned long rbase[]; 104 | 105 | iounmap((void *)rbase[dev_num]); 106 | release_mem_region(base[dev_num], num_regs); 107 | } 108 | 109 | /* enable non controller hardware (e.g. irq routing, etc.) */ 110 | int hw_attach(int dev_num) { return 0; } 111 | 112 | /* disable non controller hardware (e.g. irq routing, etc.) */ 113 | int hw_detach(int dev_num) { return 0; } 114 | 115 | /* reset controller hardware (with specific non controller hardware) */ 116 | int hw_reset_dev(int dev_num) { return 0; } 117 | 118 | /* read from controller register */ 119 | u8 hw_readreg(unsigned long base, int reg) { 120 | 121 | static u8 val; 122 | void __iomem *addr = (void __iomem *)base + reg; 123 | 124 | val = (u8)readb(addr); 125 | rmb(); 126 | 127 | return val; 128 | } 129 | 130 | /* write to controller register */ 131 | void hw_writereg(unsigned long base, int reg, u8 val) { 132 | 133 | void __iomem *addr = (void __iomem *)base + reg; 134 | 135 | writeb(val, addr); 136 | wmb(); 137 | } 138 | 139 | /* hardware specific work to do at start of irq handler */ 140 | void hw_preirq(struct net_device *dev) { return; } 141 | 142 | /* hardware specific work to do at end of irq handler */ 143 | void hw_postirq(struct net_device *dev) { return; } 144 | 145 | -------------------------------------------------------------------------------- /drivers/net/can/old/hal/iomux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * iomux.c - multiplex register access CAN hardware abstraction layer 3 | * 4 | * $Id$ 5 | * 6 | * Inspired by the OCAN driver http://ar.linux.it/software/#ocan 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 45 | * 46 | */ 47 | 48 | #include 49 | #include 50 | #include 51 | #include "hal.h" 52 | 53 | /* init the HAL - call at driver module init */ 54 | int hal_init(void) { return 0; } 55 | 56 | /* exit the HAL - call at driver module exit */ 57 | int hal_exit(void) { return 0; } 58 | 59 | /* get name of this CAN HAL */ 60 | char *hal_name(void) { return "iomux"; } 61 | 62 | /* fill arrays base[] and irq[] with HAL specific defaults */ 63 | void hal_use_defaults(void) 64 | { 65 | extern unsigned long base[]; 66 | extern unsigned int irq[]; 67 | 68 | base[0] = 0x300UL; 69 | irq[0] = 5; 70 | } 71 | 72 | /* request controller register access space */ 73 | int hal_request_region(int dev_num, 74 | unsigned int num_regs, 75 | char *drv_name) 76 | { 77 | extern unsigned long base[]; 78 | extern unsigned long rbase[]; 79 | 80 | /* set for device base_addr */ 81 | rbase[dev_num] = base[dev_num]; 82 | 83 | /* ignore num_regs and create the 2 register region: */ 84 | /* address register = base / data register = base + 1 */ 85 | return (request_region(base[dev_num], 2, drv_name))? 1 : 0; 86 | } 87 | 88 | /* release controller register access space */ 89 | void hal_release_region(int dev_num, 90 | unsigned int num_regs) 91 | { 92 | extern unsigned long base[]; 93 | 94 | /* ignore num_regs and create the 2 register region: */ 95 | /* address register = base / data register = base + 1 */ 96 | release_region(base[dev_num], 2); 97 | } 98 | 99 | /* enable non controller hardware (e.g. irq routing, etc.) */ 100 | int hw_attach(int dev_num) { return 0; } 101 | 102 | /* disable non controller hardware (e.g. irq routing, etc.) */ 103 | int hw_detach(int dev_num) { return 0; } 104 | 105 | /* reset controller hardware (with specific non controller hardware) */ 106 | int hw_reset_dev(int dev_num) { return 0; } 107 | 108 | /* read from controller register */ 109 | u8 hw_readreg(unsigned long base, int reg) { 110 | 111 | outb(reg, base); /* address */ 112 | return inb(base + 1); /* data */ 113 | } 114 | 115 | /* write to controller register */ 116 | void hw_writereg(unsigned long base, int reg, u8 val) { 117 | 118 | outb(reg, base); /* address */ 119 | outb(val, base + 1); /* data */ 120 | } 121 | 122 | /* hardware specific work to do at start of irq handler */ 123 | void hw_preirq(struct net_device *dev) { return; } 124 | 125 | /* hardware specific work to do at end of irq handler */ 126 | void hw_postirq(struct net_device *dev) { return; } 127 | 128 | -------------------------------------------------------------------------------- /drivers/net/can/old/hal/pc7io.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pc7io.c - linear register access CAN hardware abstraction layer 3 | * 4 | * $Id$ 5 | * 6 | * Inspired by the OCAN driver http://ar.linux.it/software/#ocan 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 45 | * 46 | */ 47 | 48 | #include 49 | #include 50 | #include 51 | #include "hal.h" 52 | 53 | /* init the HAL - call at driver module init */ 54 | int hal_init(void) { return 0; } 55 | 56 | /* exit the HAL - call at driver module exit */ 57 | int hal_exit(void) { return 0; } 58 | 59 | /* get name of this CAN HAL */ 60 | char *hal_name(void) { return "pc7io"; } 61 | 62 | /* fill arrays base[] and irq[] with HAL specific defaults */ 63 | void hal_use_defaults(void) 64 | { 65 | extern unsigned long base[]; 66 | extern unsigned int irq[]; 67 | 68 | base[0] = 0x1000UL; 69 | irq[0] = 9; 70 | } 71 | 72 | /* request controller register access space */ 73 | int hal_request_region(int dev_num, 74 | unsigned int num_regs, 75 | char *drv_name) 76 | { 77 | extern unsigned long base[]; 78 | extern unsigned long rbase[]; 79 | 80 | /* set for device base_addr */ 81 | rbase[dev_num] = base[dev_num]; 82 | 83 | /* creating the region for IO is pretty easy */ 84 | return (request_region(base[dev_num], num_regs, drv_name))? 1 : 0; 85 | } 86 | 87 | /* release controller register access space */ 88 | void hal_release_region(int dev_num, 89 | unsigned int num_regs) 90 | { 91 | extern unsigned long base[]; 92 | 93 | release_region(base[dev_num], num_regs); 94 | } 95 | 96 | /* enable non controller hardware (e.g. irq routing, etc.) */ 97 | int hw_attach(int dev_num) { 98 | 99 | /* Unlock special function register */ 100 | outb(5, 0x169); 101 | 102 | return 0; 103 | } 104 | 105 | /* disable non controller hardware (e.g. irq routing, etc.) */ 106 | int hw_detach(int dev_num) { return 0; } 107 | 108 | /* reset controller hardware (with specific non controller hardware) */ 109 | int hw_reset_dev(int dev_num) { return 0; } 110 | 111 | /* read from controller register */ 112 | u8 hw_readreg(unsigned long base, int reg) { 113 | 114 | return inb(base + reg); 115 | } 116 | 117 | /* write to controller register */ 118 | void hw_writereg(unsigned long base, int reg, u8 val) { 119 | 120 | outb(val, base + reg); 121 | } 122 | 123 | /* hardware specific work to do at start of irq handler */ 124 | void hw_preirq(struct net_device *dev) { return; } 125 | 126 | /* hardware specific work to do at end of irq handler */ 127 | void hw_postirq(struct net_device *dev) { return; } 128 | 129 | -------------------------------------------------------------------------------- /drivers/net/can/old/i82527/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | 5 | ifeq ($(KERNELRELEASE),) 6 | 7 | KERNELDIR := /lib/modules/$(shell uname -r)/build 8 | PWD := $(shell pwd) 9 | TOPDIR := $(PWD)/../../../../.. 10 | 11 | modules modules_install clean: 12 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 13 | 14 | else 15 | 16 | -include $(TOPDIR)/Makefile.common 17 | EXTRA_CFLAGS += -I$(TOPDIR)/drivers/net/can/old/hal 18 | 19 | obj-m := i82527-pc7io.o i82527-iomem.o i82527-esdio.o 20 | 21 | i82527-pc7io-objs := i82527.o proc.o ../hal/pc7io.o 22 | i82527-iomem-objs := i82527.o proc.o ../hal/iomem.o 23 | i82527-esdio-objs := i82527.o proc.o ../hal/esdio.o 24 | 25 | endif 26 | -------------------------------------------------------------------------------- /drivers/net/can/old/i82527/proc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * proc.c - proc file system functions for I82527 CAN driver. 3 | * 4 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of Volkswagen nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * Alternatively, provided that this notice is retained in full, this 20 | * software may be distributed under the terms of the GNU General 21 | * Public License ("GPL") version 2, in which case the provisions of the 22 | * GPL apply INSTEAD OF those given above. 23 | * 24 | * The provided data structures and external interfaces from this code 25 | * are not restricted to be used by modules with a GPL compatible license. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 38 | * DAMAGE. 39 | * 40 | * Send feedback to 41 | * 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include 51 | #include 52 | #include "i82527.h" 53 | #include "hal.h" 54 | 55 | #include /* for RCSID. Removed by mkpatch script */ 56 | RCSID("$Id$"); 57 | 58 | extern struct net_device *can_dev[]; 59 | 60 | static struct proc_dir_entry *pde = NULL; 61 | static struct proc_dir_entry *pde_regs = NULL; 62 | static struct proc_dir_entry *pde_reset = NULL; 63 | 64 | static int can_proc_read_stats(char *page, char **start, off_t off, 65 | int count, int *eof, void *data) 66 | { 67 | int len = 0; 68 | int i; 69 | 70 | len += snprintf(page + len, PAGE_SIZE - len, 71 | "CAN bus device statistics:\n"); 72 | len += snprintf(page + len, PAGE_SIZE - len, 73 | " errwarn overrun wakeup buserr " 74 | "errpass arbitr restarts clock baud\n"); 75 | for (i = 0; (i < MAXDEV) && (len < PAGE_SIZE - 200); i++) { 76 | if (can_dev[i]) { 77 | struct net_device *dev = can_dev[i]; 78 | struct can_priv *priv = netdev_priv(dev); 79 | len += snprintf(page + len, PAGE_SIZE - len, 80 | "%s: %8d %8d %8d %8d %8d " 81 | "%8d %8d %10d %8d\n", dev->name, 82 | priv->can_stats.error_warning, 83 | priv->can_stats.data_overrun, 84 | priv->can_stats.wakeup, 85 | priv->can_stats.bus_error, 86 | priv->can_stats.error_passive, 87 | priv->can_stats.arbitration_lost, 88 | priv->can_stats.restarts, 89 | priv->clock, 90 | priv->speed 91 | ); 92 | 93 | } 94 | } 95 | 96 | *eof = 1; 97 | return len; 98 | } 99 | 100 | 101 | static int can_proc_dump_regs(char *page, int len, struct net_device *dev) 102 | { 103 | int r,s; 104 | struct can_priv *priv = netdev_priv(dev); 105 | int regs = priv->hw_regs; 106 | 107 | len += snprintf(page + len, PAGE_SIZE - len, 108 | "%s registers:\n", dev->name); 109 | 110 | for (r = 0; r < regs; r += 0x10) { 111 | len += snprintf(page + len, PAGE_SIZE - len, "%02X: ", r); 112 | for (s = 0; s < 0x10; s++) { 113 | if (r+s < regs) 114 | len += snprintf(page + len, PAGE_SIZE-len, 115 | "%02X ", 116 | hw_readreg(dev->base_addr, 117 | r+s)); 118 | } 119 | len += snprintf(page + len, PAGE_SIZE - len, "\n"); 120 | } 121 | 122 | return len; 123 | } 124 | 125 | static int can_proc_read_regs(char *page, char **start, off_t off, 126 | int count, int *eof, void *data) 127 | { 128 | int len = 0; 129 | int i; 130 | 131 | for (i = 0; (i < MAXDEV) && (len < PAGE_SIZE - 200); i++) { 132 | if (can_dev[i]) 133 | len = can_proc_dump_regs(page, len, can_dev[i]); 134 | } 135 | 136 | *eof = 1; 137 | return len; 138 | } 139 | 140 | static int can_proc_read_reset(char *page, char **start, off_t off, 141 | int count, int *eof, void *data) 142 | { 143 | int len = 0; 144 | struct net_device *dev; 145 | int i; 146 | struct can_priv *priv; 147 | 148 | len += snprintf(page + len, PAGE_SIZE - len, "resetting "); 149 | for (i = 0; (i < MAXDEV) && (len < PAGE_SIZE - 200); i++) { 150 | if (can_dev[i]) { 151 | dev = can_dev[i]; 152 | priv = netdev_priv(can_dev[i]); 153 | if ((priv->state != STATE_UNINITIALIZED) 154 | && (priv->state != STATE_RESET_MODE)) { 155 | len += snprintf(page + len, PAGE_SIZE - len, 156 | "%s ", dev->name); 157 | #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,28) 158 | dev->netdev_ops->ndo_stop(dev); 159 | dev->netdev_ops->ndo_open(dev); 160 | #else 161 | dev->stop(dev); 162 | dev->open(dev); 163 | #endif 164 | /* count number of restarts */ 165 | priv->can_stats.restarts++; 166 | 167 | } else { 168 | len += snprintf(page + len, PAGE_SIZE - len, 169 | "(%s|%d) ", dev->name, 170 | priv->state); 171 | } 172 | } 173 | } 174 | 175 | len += snprintf(page + len, PAGE_SIZE - len, "done\n"); 176 | 177 | *eof = 1; 178 | return len; 179 | } 180 | 181 | void can_proc_create(const char *drv_name) 182 | { 183 | char fname[256]; 184 | 185 | if (pde == NULL) { 186 | sprintf(fname, PROCBASE "/%s_stats", drv_name); 187 | pde = create_proc_read_entry(fname, 0644, NULL, 188 | can_proc_read_stats, NULL); 189 | } 190 | if (pde_regs == NULL) { 191 | sprintf(fname, PROCBASE "/%s_regs", drv_name); 192 | pde_regs = create_proc_read_entry(fname, 0644, NULL, 193 | can_proc_read_regs, NULL); 194 | } 195 | if (pde_reset == NULL) { 196 | sprintf(fname, PROCBASE "/%s_reset", drv_name); 197 | pde_reset = create_proc_read_entry(fname, 0644, NULL, 198 | can_proc_read_reset, NULL); 199 | } 200 | } 201 | 202 | void can_proc_remove(const char *drv_name) 203 | { 204 | char fname[256]; 205 | 206 | if (pde) { 207 | sprintf(fname, PROCBASE "/%s_stats", drv_name); 208 | remove_proc_entry(fname, NULL); 209 | } 210 | if (pde_regs) { 211 | sprintf(fname, PROCBASE "/%s_regs", drv_name); 212 | remove_proc_entry(fname, NULL); 213 | } 214 | if (pde_reset) { 215 | sprintf(fname, PROCBASE "/%s_reset", drv_name); 216 | remove_proc_entry(fname, NULL); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /drivers/net/can/old/mscan/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | 5 | ifeq ($(KERNELRELEASE),) 6 | 7 | KERNELDIR := /lib/modules/$(shell uname -r)/build 8 | PWD := $(shell pwd) 9 | TOPDIR := $(PWD)/../../../.. 10 | 11 | modules modules_install clean: 12 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 13 | 14 | else 15 | 16 | -include $(TOPDIR)/Makefile.common 17 | 18 | obj-$(CONFIG_CAN_MPC52XX_OLD) += mscan-mpc52xx-old.o 19 | 20 | mscan-mpc52xx-old-objs := mscan.o mpc52xx_can.o 21 | 22 | endif 23 | -------------------------------------------------------------------------------- /drivers/net/can/old/mscan/mpc52xx_can.c: -------------------------------------------------------------------------------- 1 | /* 2 | * DESCRIPTION: 3 | * CAN bus driver for the Freescale MPC52xx embedded CPU. 4 | * 5 | * AUTHOR: 6 | * Andrey Volkov 7 | * 8 | * COPYRIGHT: 9 | * 2004-2005, Varma Electronics Oy 10 | * 11 | * LICENCE: 12 | * This program is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation; either version 2 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program; if not, write to the Free Software 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | * 26 | * HISTORY: 27 | * 2005-02-03 created 28 | * 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "mscan.h" 42 | 43 | #include /* for RCSID. Removed by mkpatch script */ 44 | 45 | RCSID("$Id$"); 46 | 47 | #define PDEV_MAX 2 48 | 49 | struct platform_device *pdev[PDEV_MAX]; 50 | 51 | static int __devinit mpc52xx_can_probe(struct platform_device *pdev) 52 | { 53 | struct resource *mem; 54 | struct net_device *dev; 55 | struct mscan_platform_data *pdata = pdev->dev.platform_data; 56 | struct can_priv *can; 57 | u32 mem_size; 58 | int ret = -ENODEV; 59 | 60 | if (!pdata) 61 | return ret; 62 | 63 | dev = alloc_mscandev(); 64 | if (!dev) 65 | return -ENOMEM; 66 | can = netdev_priv(dev); 67 | 68 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 69 | dev->irq = platform_get_irq(pdev, 0); 70 | if (!mem || !dev->irq) 71 | goto req_error; 72 | 73 | mem_size = mem->end - mem->start + 1; 74 | if (!request_mem_region(mem->start, mem_size, pdev->dev.driver->name)) { 75 | dev_err(&pdev->dev, "resource unavailable\n"); 76 | goto req_error; 77 | } 78 | 79 | SET_NETDEV_DEV(dev, &pdev->dev); 80 | 81 | dev->base_addr = (unsigned long)ioremap_nocache(mem->start, mem_size); 82 | 83 | if (!dev->base_addr) { 84 | dev_err(&pdev->dev, "failed to map can port\n"); 85 | ret = -ENOMEM; 86 | goto fail_map; 87 | } 88 | 89 | can->can_sys_clock = pdata->clock_frq; 90 | 91 | platform_set_drvdata(pdev, dev); 92 | 93 | ret = register_mscandev(dev, pdata->clock_src); 94 | if (ret >= 0) { 95 | dev_info(&pdev->dev, "probe for a port 0x%lX done\n", 96 | dev->base_addr); 97 | return ret; 98 | } 99 | 100 | iounmap((unsigned long *)dev->base_addr); 101 | fail_map: 102 | release_mem_region(mem->start, mem_size); 103 | req_error: 104 | free_candev(dev); 105 | dev_err(&pdev->dev, "probe failed\n"); 106 | return ret; 107 | } 108 | 109 | static int __devexit mpc52xx_can_remove(struct platform_device *pdev) 110 | { 111 | struct net_device *dev = platform_get_drvdata(pdev); 112 | struct resource *mem; 113 | 114 | platform_set_drvdata(pdev, NULL); 115 | unregister_mscandev(dev); 116 | 117 | iounmap((volatile void __iomem *)dev->base_addr); 118 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 119 | release_mem_region(mem->start, mem->end - mem->start + 1); 120 | free_candev(dev); 121 | return 0; 122 | } 123 | 124 | #ifdef CONFIG_PM 125 | static struct mscan_regs saved_regs; 126 | static int mpc52xx_can_suspend(struct platform_device *pdev, pm_message_t state) 127 | { 128 | struct net_device *dev = platform_get_drvdata(pdev); 129 | struct mscan_regs *regs = (struct mscan_regs *)dev->base_addr; 130 | 131 | _memcpy_fromio(&saved_regs, regs, sizeof(*regs)); 132 | 133 | return 0; 134 | } 135 | 136 | static int mpc52xx_can_resume(struct platform_device *pdev) 137 | { 138 | struct net_device *dev = platform_get_drvdata(pdev); 139 | struct mscan_regs *regs = (struct mscan_regs *)dev->base_addr; 140 | 141 | regs->canctl0 |= MSCAN_INITRQ; 142 | while ((regs->canctl1 & MSCAN_INITAK) == 0) 143 | udelay(10); 144 | 145 | regs->canctl1 = saved_regs.canctl1; 146 | regs->canbtr0 = saved_regs.canbtr0; 147 | regs->canbtr1 = saved_regs.canbtr1; 148 | regs->canidac = saved_regs.canidac; 149 | 150 | /* restore masks, buffers etc. */ 151 | _memcpy_toio(®s->canidar1_0, (void *)&saved_regs.canidar1_0, 152 | sizeof(*regs) - offsetof(struct mscan_regs, canidar1_0)); 153 | 154 | regs->canctl0 &= ~MSCAN_INITRQ; 155 | regs->cantbsel = saved_regs.cantbsel; 156 | regs->canrier = saved_regs.canrier; 157 | regs->cantier = saved_regs.cantier; 158 | regs->canctl0 = saved_regs.canctl0; 159 | 160 | return 0; 161 | } 162 | #endif 163 | 164 | static struct platform_driver mpc52xx_can_driver = { 165 | .driver = { 166 | .name = "mpc52xx-mscan", 167 | }, 168 | .probe = mpc52xx_can_probe, 169 | .remove = __devexit_p(mpc52xx_can_remove), 170 | #ifdef CONFIG_PM 171 | .suspend = mpc52xx_can_suspend, 172 | .resume = mpc52xx_can_resume, 173 | #endif 174 | }; 175 | 176 | #ifdef CONFIG_PPC_MERGE 177 | static int __init mpc52xx_of_to_pdev(void) 178 | { 179 | struct device_node *np = NULL; 180 | unsigned int i; 181 | int err = -ENODEV; 182 | 183 | for (i = 0; 184 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) 185 | (np = of_find_compatible_node(np, "mscan", "mpc5200-mscan")); 186 | #else 187 | (np = of_find_compatible_node(np, NULL, "fsl,mpc5200-mscan")); 188 | #endif 189 | i++) { 190 | struct resource r[2] = { }; 191 | struct mscan_platform_data pdata; 192 | 193 | if (i >= PDEV_MAX) { 194 | printk(KERN_WARNING "%s: increase PDEV_MAX for more " 195 | "than %i devices\n", __func__, PDEV_MAX); 196 | break; 197 | } 198 | 199 | err = of_address_to_resource(np, 0, &r[0]); 200 | if (err) 201 | break; 202 | 203 | of_irq_to_resource(np, 0, &r[1]); 204 | 205 | pdev[i] = 206 | platform_device_register_simple("mpc52xx-mscan", i, r, 2); 207 | if (IS_ERR(pdev[i])) { 208 | err = PTR_ERR(pdev[i]); 209 | break; 210 | } 211 | 212 | pdata.clock_src = MSCAN_CLKSRC_BUS; 213 | pdata.clock_frq = mpc52xx_find_ipb_freq(np); 214 | err = platform_device_add_data(pdev[i], &pdata, sizeof(pdata)); 215 | if (err) 216 | break; 217 | } 218 | return err; 219 | } 220 | #else 221 | #define mscan_of_to_pdev() 222 | #endif 223 | 224 | int __init mpc52xx_can_init(void) 225 | { 226 | printk(KERN_WARNING 227 | "This %s driver is DEPRECATED, please switch!\n", 228 | mpc52xx_can_driver.driver.name); 229 | #ifdef CONFIG_PPC_MERGE 230 | int err = mpc52xx_of_to_pdev(); 231 | 232 | if (err) { 233 | printk(KERN_ERR "%s init failed with err=%d\n", 234 | mpc52xx_can_driver.driver.name, err); 235 | return err; 236 | } 237 | #endif 238 | return platform_driver_register(&mpc52xx_can_driver); 239 | } 240 | 241 | void __exit mpc52xx_can_exit(void) 242 | { 243 | int i; 244 | platform_driver_unregister(&mpc52xx_can_driver); 245 | for (i = 0; i < PDEV_MAX; i++) 246 | platform_device_unregister(pdev[i]); 247 | printk(KERN_INFO "%s unloaded\n", mpc52xx_can_driver.driver.name); 248 | } 249 | 250 | module_init(mpc52xx_can_init); 251 | module_exit(mpc52xx_can_exit); 252 | 253 | MODULE_AUTHOR("Andrey Volkov "); 254 | MODULE_DESCRIPTION("Freescale MPC5200 CAN driver"); 255 | MODULE_LICENSE("GPL v2"); 256 | -------------------------------------------------------------------------------- /drivers/net/can/old/sja1000/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | 5 | ifeq ($(KERNELRELEASE),) 6 | 7 | KERNELDIR := /lib/modules/$(shell uname -r)/build 8 | PWD := $(shell pwd) 9 | TOPDIR := $(PWD)/../../../../.. 10 | 11 | modules modules_install clean: 12 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 13 | 14 | else 15 | 16 | -include $(TOPDIR)/Makefile.common 17 | EXTRA_CFLAGS += -I$(TOPDIR)/drivers/net/can/old/hal 18 | 19 | obj-m := sja1000-io.o sja1000-iomem.o sja1000-iomux.o sja1000-gw2.o sja1000-esdio.o sja1000-c200.o 20 | 21 | sja1000-io-objs := sja1000.o proc.o ../hal/io.o 22 | sja1000-iomem-objs := sja1000.o proc.o ../hal/iomem.o 23 | sja1000-iomux-objs := sja1000.o proc.o ../hal/iomux.o 24 | sja1000-gw2-objs := sja1000.o proc.o ../hal/gw2.o 25 | sja1000-esdio-objs := sja1000.o proc.o ../hal/esdio.o 26 | sja1000-c200-objs := sja1000.o proc.o ../hal/c200.o 27 | 28 | endif 29 | -------------------------------------------------------------------------------- /drivers/net/can/old/sja1000/sja1000.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | * 4 | * sja1000.h - Philips SJA1000 network device driver 5 | * 6 | * Copyright (c) 2003 Matthias Brukner, Trajet Gmbh, Rebenring 33, 7 | * 38106 Braunschweig, GERMANY 8 | * 9 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 10 | * All rights reserved. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions 14 | * are met: 15 | * 1. Redistributions of source code must retain the above copyright 16 | * notice, this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in the 19 | * documentation and/or other materials provided with the distribution. 20 | * 3. Neither the name of Volkswagen nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * Alternatively, provided that this notice is retained in full, this 25 | * software may be distributed under the terms of the GNU General 26 | * Public License ("GPL") version 2, in which case the provisions of the 27 | * GPL apply INSTEAD OF those given above. 28 | * 29 | * The provided data structures and external interfaces from this code 30 | * are not restricted to be used by modules with a GPL compatible license. 31 | * 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 37 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 38 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 39 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 40 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 41 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 42 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 43 | * DAMAGE. 44 | * 45 | * Send feedback to 46 | * 47 | */ 48 | 49 | #ifndef SJA1000_H 50 | #define SJA1000_H 51 | 52 | #define SJA1000_IO_SIZE_BASIC 0x20 53 | #define SJA1000_IO_SIZE_PELICAN 0x80 /* unused */ 54 | 55 | #define CHIP_NAME "sja1000" 56 | 57 | #define DRV_NAME_LEN 30 /* for "-" */ 58 | 59 | #define PROCBASE "driver" /* /proc/ ... */ 60 | 61 | #define DEFAULT_HW_CLK 16000000 62 | #define DEFAULT_SPEED 500 /* kBit/s */ 63 | 64 | #define CAN_NETDEV_NAME "can%d" 65 | 66 | #define TX_TIMEOUT (50*HZ/1000) /* 50ms */ 67 | #define RESTART_MS 100 /* restart chip on persistent errors in 100ms */ 68 | #define MAX_BUS_ERRORS 200 /* prevent from flooding bus error interrupts */ 69 | 70 | /* SJA1000 registers - manual section 6.4 (Pelican Mode) */ 71 | #define REG_MOD 0x00 72 | #define REG_CMR 0x01 73 | #define REG_SR 0x02 74 | #define REG_IR 0x03 75 | #define REG_IER 0x04 76 | #define REG_ALC 0x0B 77 | #define REG_ECC 0x0C 78 | #define REG_EWL 0x0D 79 | #define REG_RXERR 0x0E 80 | #define REG_TXERR 0x0F 81 | #define REG_ACCC0 0x10 82 | #define REG_ACCC1 0x11 83 | #define REG_ACCC2 0x12 84 | #define REG_ACCC3 0x13 85 | #define REG_ACCM0 0x14 86 | #define REG_ACCM1 0x15 87 | #define REG_ACCM2 0x16 88 | #define REG_ACCM3 0x17 89 | #define REG_RMC 0x1D 90 | #define REG_RBSA 0x1E 91 | 92 | /* Common registers - manual section 6.5 */ 93 | #define REG_BTR0 0x06 94 | #define REG_BTR1 0x07 95 | #define REG_OCR 0x08 96 | #define REG_CDR 0x1F 97 | 98 | #define REG_FI 0x10 99 | #define SFF_BUF 0x13 100 | #define EFF_BUF 0x15 101 | 102 | #define FI_FF 0x80 103 | #define FI_RTR 0x40 104 | 105 | #define REG_ID1 0x11 106 | #define REG_ID2 0x12 107 | #define REG_ID3 0x13 108 | #define REG_ID4 0x14 109 | 110 | #define CAN_RAM 0x20 111 | 112 | /* mode register */ 113 | #define MOD_RM 0x01 114 | #define MOD_LOM 0x02 115 | #define MOD_STM 0x04 116 | #define MOD_AFM 0x08 117 | #define MOD_SM 0x10 118 | 119 | /* commands */ 120 | #define CMD_SRR 0x10 121 | #define CMD_CDO 0x08 122 | #define CMD_RRB 0x04 123 | #define CMD_AT 0x02 124 | #define CMD_TR 0x01 125 | 126 | /* interrupt sources */ 127 | #define IRQ_BEI 0x80 128 | #define IRQ_ALI 0x40 129 | #define IRQ_EPI 0x20 130 | #define IRQ_WUI 0x10 131 | #define IRQ_DOI 0x08 132 | #define IRQ_EI 0x04 133 | #define IRQ_TI 0x02 134 | #define IRQ_RI 0x01 135 | #define IRQ_ALL 0xFF 136 | #define IRQ_OFF 0x00 137 | 138 | /* status register content */ 139 | #define SR_BS 0x80 140 | #define SR_ES 0x40 141 | #define SR_TS 0x20 142 | #define SR_RS 0x10 143 | #define SR_TCS 0x08 144 | #define SR_TBS 0x04 145 | #define SR_DOS 0x02 146 | #define SR_RBS 0x01 147 | 148 | #define SR_CRIT (SR_BS|SR_ES) 149 | 150 | /* ECC register */ 151 | #define ECC_DIR 0x20 152 | #define ECC_SEG 0x1F 153 | #define ECC_ERR 6 154 | 155 | /* bus timing */ 156 | #define MAX_TSEG1 15 157 | #define MAX_TSEG2 7 158 | #define SAMPLE_POINT 75 159 | #define JUMPWIDTH 0x40 160 | 161 | /* CAN private data structure */ 162 | 163 | struct can_priv { 164 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) 165 | struct net_device_stats stats; 166 | #endif 167 | struct can_device_stats can_stats; 168 | long open_time; 169 | int clock; 170 | int hw_regs; 171 | int restart_ms; 172 | int debug; 173 | int speed; 174 | int btr; 175 | int rx_probe; 176 | struct timer_list timer; 177 | int state; 178 | struct sk_buff *echo_skb; 179 | }; 180 | 181 | #define STATE_UNINITIALIZED 0 182 | #define STATE_PROBE 1 183 | #define STATE_ACTIVE 2 184 | #define STATE_ERROR_ACTIVE 3 185 | #define STATE_ERROR_PASSIVE 4 186 | #define STATE_BUS_OFF 5 187 | #define STATE_RESET_MODE 6 188 | 189 | void can_proc_create(const char *drv_name); 190 | void can_proc_remove(const char *drv_name); 191 | 192 | #endif /* SJA1000_H */ 193 | -------------------------------------------------------------------------------- /drivers/net/can/sja1000/Kconfig: -------------------------------------------------------------------------------- 1 | menuconfig CAN_SJA1000 2 | tristate "Philips/NXP SJA1000 devices" 3 | depends on CAN_DEV && HAS_IOMEM 4 | 5 | if CAN_SJA1000 6 | 7 | config CAN_SJA1000_ISA 8 | tristate "ISA Bus based legacy SJA1000 driver" 9 | depends on ISA 10 | ---help--- 11 | This driver adds legacy support for SJA1000 chips connected to 12 | the ISA bus using I/O port, memory mapped or indirect access. 13 | 14 | config CAN_SJA1000_PLATFORM 15 | tristate "Generic Platform Bus based SJA1000 driver" 16 | ---help--- 17 | This driver adds support for the SJA1000 chips connected to 18 | the "platform bus" (Linux abstraction for directly to the 19 | processor attached devices). Which can be found on various 20 | boards from Phytec (http://www.phytec.de) like the PCM027, 21 | PCM038. 22 | 23 | config CAN_SJA1000_OF_PLATFORM 24 | tristate "Generic OF Platform Bus based SJA1000 driver" 25 | depends on PPC_OF 26 | ---help--- 27 | This driver adds support for the SJA1000 chips connected to 28 | the OpenFirmware "platform bus" found on embedded systems with 29 | OpenFirmware bindings, e.g. if you have a PowerPC based system 30 | you may want to enable this option. 31 | 32 | config CAN_EMS_PCI 33 | tristate "EMS CPC-PCI, CPC-PCIe and CPC-104P Card" 34 | depends on PCI 35 | ---help--- 36 | This driver is for the one, two or four channel CPC-PCI, 37 | CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche 38 | (http://www.ems-wuensche.de). 39 | 40 | config CAN_EMS_PCMCIA 41 | tristate "EMS CPC-CARD Card" 42 | depends on PCMCIA && CAN_SJA1000 43 | ---help--- 44 | This driver is for the one or two channel CPC-CARD cards from 45 | EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de). 46 | 47 | config CAN_EMS_104M 48 | tristate "EMS CPC-104M Card" 49 | depends on ISA && CAN_SJA1000 50 | ---help--- 51 | This driver is for the one, two or four channel CPC-104M cards 52 | from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de). 53 | 54 | config CAN_ESD_PCI 55 | tristate "ESD PCI Cards" 56 | depends on PCI && CAN_SJA1000 57 | ---help--- 58 | This driver supports the esd PCI CAN cards CAN-PCI/200, 59 | CAN-PCI/266, CAN-PMC/266 (PMC), CAN-CPCI/200 (CompactPCI), 60 | CAN-PCIe2000 (PCI Express) and CAN-PCI104/200 (PCI104) 61 | from the esd electronic system design gmbh (http://www.esd.eu). 62 | 63 | config CAN_IXXAT_PCI 64 | tristate "IXXAT PCI Card" 65 | depends on PCI && CAN_SJA1000 66 | ---help--- 67 | This driver is for the IXXAT PC-I 04/PCI card (1 or 2 channel) 68 | from the IXXAT Automation GmbH (http://www.ixxat.de). 69 | 70 | config CAN_KVASER_PCI 71 | tristate "Kvaser PCIcanx and Kvaser PCIcan PCI Cards" 72 | depends on PCI 73 | ---help--- 74 | This driver is for the the PCIcanx and PCIcan cards (1, 2 or 75 | 4 channel) from Kvaser (http://www.kvaser.com). 76 | 77 | config CAN_PEAK_PCI 78 | tristate "PEAK PCAN PCI Card" 79 | depends on PCI && CAN_SJA1000 80 | ---help--- 81 | This driver is for the PCAN PCI, the PC-PCI CAN plug-in card (1 or 82 | 2 channel) from PEAK Systems (http://www.peak-system.com). 83 | 84 | config CAN_PLX_PCI 85 | tristate "PLX90xx PCI-bridge based Cards" 86 | depends on PCI 87 | ---help--- 88 | This driver is for CAN interface cards based on 89 | the PLX90xx PCI bridge. 90 | Driver supports now: 91 | - Adlink PCI-7841/cPCI-7841 card (http://www.adlinktech.com/) 92 | - Adlink PCI-7841/cPCI-7841 SE card 93 | - Marathon CAN-bus-PCI card (http://www.marathon.ru/) 94 | - TEWS TECHNOLOGIES TPMC810 card (http://www.tews.com/) 95 | 96 | config CAN_PIPCAN 97 | depends on CAN_SJA1000 98 | tristate "MPL PIPCAN CAN module driver (SJA1000)" 99 | ---help--- 100 | This driver adds support for the PIPCAN module used on some SBC 101 | boards from MPL AG (http://www.mpl.ch). 102 | 103 | endif 104 | -------------------------------------------------------------------------------- /drivers/net/can/sja1000/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: Makefile 443 2007-07-25 11:41:27Z hartkopp $ 3 | # 4 | 5 | ifeq ($(KERNELRELEASE),) 6 | 7 | KERNELDIR := /lib/modules/$(shell uname -r)/build 8 | PWD := $(shell pwd) 9 | TOPDIR := $(PWD)/../../../.. 10 | 11 | modules modules_install clean: 12 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 13 | 14 | else 15 | 16 | -include $(TOPDIR)/Makefile.common 17 | 18 | obj-$(CONFIG_CAN_SJA1000) += sja1000.o 19 | obj-$(CONFIG_CAN_SJA1000_ISA) += sja1000_isa.o 20 | obj-$(CONFIG_CAN_SJA1000_PLATFORM) += sja1000_platform.o 21 | obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o 22 | obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o 23 | obj-$(CONFIG_CAN_EMS_PCMCIA) += ems_pcmcia.o 24 | obj-$(CONFIG_CAN_EMS_104M) += ems_104m.o 25 | obj-$(CONFIG_CAN_ESD_PCI) += esd_pci.o 26 | obj-$(CONFIG_CAN_IXXAT_PCI) += ixxat_pci.o 27 | obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o 28 | obj-$(CONFIG_CAN_PEAK_PCI) += peak_pci.o 29 | obj-$(CONFIG_CAN_PIPCAN) += pipcan.o 30 | obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o 31 | 32 | ifeq ($(CONFIG_CAN_DEBUG_DEVICES),y) 33 | EXTRA_CFLAGS += -DDEBUG 34 | endif 35 | 36 | endif 37 | -------------------------------------------------------------------------------- /drivers/net/can/sja1000/pipcan.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 David Müller, 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the version 2 of the GNU General Public License 6 | * as published by the Free Software Foundation 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program; if not, write to the Free Software 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "sja1000.h" 30 | 31 | #define DRV_NAME "pipcan" 32 | 33 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) 34 | #error This driver does not support Kernel versions < 2.6.20 35 | #endif 36 | 37 | MODULE_AUTHOR("David Müller "); 38 | MODULE_DESCRIPTION("Socket-CAN driver for MPL PIPCAN module"); 39 | MODULE_SUPPORTED_DEVICE("MPL PIPCAN module"); 40 | MODULE_LICENSE("GPL v2"); 41 | 42 | #define PIPCAN_CAN_CLOCK (16000000 / 2) 43 | 44 | #define PIPCAN_OCR (OCR_TX1_PUSHPULL) 45 | #define PIPCAN_CDR (CDR_CBP | CDR_CLK_OFF) 46 | 47 | #define PIPCAN_IOSIZE (0x100) 48 | 49 | #define PIPCAN_RES (0x804) 50 | #define PIPCAN_RST (0x805) 51 | 52 | static u8 pc_read_reg(const struct sja1000_priv *priv, int reg) 53 | { 54 | return inb((unsigned long)priv->reg_base + reg); 55 | } 56 | 57 | static void pc_write_reg(const struct sja1000_priv *priv, int reg, u8 val) 58 | { 59 | outb(val, (unsigned long)priv->reg_base + reg); 60 | } 61 | 62 | static int __init pc_probe(struct platform_device *pdev) 63 | { 64 | struct net_device *dev; 65 | struct sja1000_priv *priv; 66 | struct resource *res; 67 | int rc, irq; 68 | 69 | rc = -ENODEV; 70 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); 71 | irq = platform_get_irq(pdev, 0); 72 | if (!res || !irq) 73 | goto exit; 74 | 75 | rc = -EBUSY; 76 | if (!request_region(res->start, res->end - res->start + 1, DRV_NAME)) 77 | goto exit; 78 | 79 | rc = -ENOMEM; 80 | dev = alloc_sja1000dev(0); 81 | if (!dev) 82 | goto exit_release; 83 | 84 | priv = netdev_priv(dev); 85 | 86 | priv->read_reg = pc_read_reg; 87 | priv->write_reg = pc_write_reg; 88 | priv->can.clock.freq = PIPCAN_CAN_CLOCK; 89 | priv->ocr = PIPCAN_OCR; 90 | priv->cdr = PIPCAN_CDR; 91 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) 92 | priv->irq_flags = SA_SHIRQ; 93 | #else 94 | priv->irq_flags = IRQF_SHARED; 95 | #endif 96 | 97 | dev->irq = irq; 98 | dev->base_addr = res->start; 99 | priv->reg_base = (void __iomem *)res->start; 100 | 101 | dev_set_drvdata(&pdev->dev, dev); 102 | SET_NETDEV_DEV(dev, &pdev->dev); 103 | 104 | /* deactivate RST */ 105 | outb(inb(PIPCAN_RST) & ~0x01, PIPCAN_RST); 106 | 107 | rc = register_sja1000dev(dev); 108 | if (rc) { 109 | dev_err(&pdev->dev, "registering %s failed (err=%d)\n", 110 | DRV_NAME, rc); 111 | goto exit_free; 112 | } 113 | 114 | dev_info(&pdev->dev, "device registered (base_addr=%#lx, irq=%d)\n", 115 | dev->base_addr, dev->irq); 116 | return 0; 117 | 118 | exit_free: 119 | free_sja1000dev(dev); 120 | 121 | exit_release: 122 | release_region(res->start, res->end - res->start + 1); 123 | 124 | exit: 125 | return rc; 126 | } 127 | 128 | static int __exit pc_remove(struct platform_device *pdev) 129 | { 130 | struct net_device *dev = dev_get_drvdata(&pdev->dev); 131 | struct resource *res; 132 | 133 | dev_set_drvdata(&pdev->dev, NULL); 134 | unregister_sja1000dev(dev); 135 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); 136 | 137 | free_sja1000dev(dev); 138 | 139 | release_region(res->start, res->end - res->start + 1); 140 | 141 | /* activate RST */ 142 | outb(inb(PIPCAN_RST) | 0x01, PIPCAN_RST); 143 | 144 | return 0; 145 | } 146 | 147 | static struct platform_driver pc_driver = { 148 | .remove = __exit_p(pc_remove), 149 | .driver = { 150 | .name = DRV_NAME, 151 | .owner = THIS_MODULE, 152 | }, 153 | }; 154 | 155 | static struct platform_device *pc_pdev; 156 | static const u16 pipcan_ioport[] = {0x1000, 0x8000, 0xE000}; 157 | 158 | static int __init pc_init(void) 159 | { 160 | struct resource r[2]; 161 | int rc, addr, irq, idx; 162 | u8 pc_res; 163 | 164 | /* get PIPCAN resources from EPLD */ 165 | pc_res = inb(PIPCAN_RES); 166 | 167 | idx = (pc_res & 0x0F); 168 | if ((idx <= 0) || (idx > ARRAY_SIZE(pipcan_ioport))) { 169 | printk(KERN_ERR DRV_NAME " invalid base address\n"); 170 | return -EINVAL; 171 | } 172 | addr = pipcan_ioport[idx-1]; 173 | 174 | irq = (pc_res >> 4) & 0x0F; 175 | if ((irq < 3) || (irq == 8) || (irq == 13)) { 176 | printk(KERN_ERR DRV_NAME " invalid IRQ\n"); 177 | return -EINVAL; 178 | } 179 | 180 | /* fill in resources */ 181 | memset(&r, 0, sizeof(r)); 182 | r[0].start = addr; 183 | r[0].end = addr + PIPCAN_IOSIZE - 1; 184 | r[0].name = DRV_NAME; 185 | r[0].flags = IORESOURCE_IO; 186 | r[1].start = r[1].end = irq; 187 | r[1].name = DRV_NAME; 188 | r[1].flags = IORESOURCE_IRQ; 189 | 190 | pc_pdev = platform_device_register_simple(DRV_NAME, 0, r, 191 | ARRAY_SIZE(r)); 192 | if (IS_ERR(pc_pdev)) 193 | return PTR_ERR(pc_pdev); 194 | 195 | rc = platform_driver_probe(&pc_driver, pc_probe); 196 | if (rc) { 197 | platform_device_unregister(pc_pdev); 198 | printk(KERN_ERR DRV_NAME 199 | " platform_driver_probe() failed (%d)\n", rc); 200 | } 201 | 202 | return rc; 203 | } 204 | 205 | static void __exit pc_exit(void) 206 | { 207 | platform_driver_unregister(&pc_driver); 208 | platform_device_unregister(pc_pdev); 209 | } 210 | 211 | module_init(pc_init); 212 | module_exit(pc_exit); 213 | -------------------------------------------------------------------------------- /drivers/net/can/sja1000/sja1000.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sja1000.h - Philips SJA1000 network device driver 3 | * 4 | * Copyright (c) 2003 Matthias Brukner, Trajet Gmbh, Rebenring 33, 5 | * 38106 Braunschweig, GERMANY 6 | * 7 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Volkswagen nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * Alternatively, provided that this notice is retained in full, this 23 | * software may be distributed under the terms of the GNU General 24 | * Public License ("GPL") version 2, in which case the provisions of the 25 | * GPL apply INSTEAD OF those given above. 26 | * 27 | * The provided data structures and external interfaces from this code 28 | * are not restricted to be used by modules with a GPL compatible license. 29 | * 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 33 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 34 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 36 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 41 | * DAMAGE. 42 | * 43 | * Send feedback to 44 | * 45 | */ 46 | 47 | #ifndef SJA1000_DEV_H 48 | #define SJA1000_DEV_H 49 | 50 | #include 51 | #include 52 | 53 | #define SJA1000_ECHO_SKB_MAX 1 /* the SJA1000 has one TX buffer object */ 54 | 55 | #define SJA1000_MAX_IRQ 20 /* max. number of interrupts handled in ISR */ 56 | 57 | /* SJA1000 registers - manual section 6.4 (Pelican Mode) */ 58 | #define REG_MOD 0x00 59 | #define REG_CMR 0x01 60 | #define REG_SR 0x02 61 | #define REG_IR 0x03 62 | #define REG_IER 0x04 63 | #define REG_ALC 0x0B 64 | #define REG_ECC 0x0C 65 | #define REG_EWL 0x0D 66 | #define REG_RXERR 0x0E 67 | #define REG_TXERR 0x0F 68 | #define REG_ACCC0 0x10 69 | #define REG_ACCC1 0x11 70 | #define REG_ACCC2 0x12 71 | #define REG_ACCC3 0x13 72 | #define REG_ACCM0 0x14 73 | #define REG_ACCM1 0x15 74 | #define REG_ACCM2 0x16 75 | #define REG_ACCM3 0x17 76 | #define REG_RMC 0x1D 77 | #define REG_RBSA 0x1E 78 | 79 | /* Common registers - manual section 6.5 */ 80 | #define REG_BTR0 0x06 81 | #define REG_BTR1 0x07 82 | #define REG_OCR 0x08 83 | #define REG_CDR 0x1F 84 | 85 | #define REG_FI 0x10 86 | #define SFF_BUF 0x13 87 | #define EFF_BUF 0x15 88 | 89 | #define FI_FF 0x80 90 | #define FI_RTR 0x40 91 | 92 | #define REG_ID1 0x11 93 | #define REG_ID2 0x12 94 | #define REG_ID3 0x13 95 | #define REG_ID4 0x14 96 | 97 | #define CAN_RAM 0x20 98 | 99 | /* mode register */ 100 | #define MOD_RM 0x01 101 | #define MOD_LOM 0x02 102 | #define MOD_STM 0x04 103 | #define MOD_AFM 0x08 104 | #define MOD_SM 0x10 105 | 106 | /* commands */ 107 | #define CMD_SRR 0x10 108 | #define CMD_CDO 0x08 109 | #define CMD_RRB 0x04 110 | #define CMD_AT 0x02 111 | #define CMD_TR 0x01 112 | 113 | /* interrupt sources */ 114 | #define IRQ_BEI 0x80 115 | #define IRQ_ALI 0x40 116 | #define IRQ_EPI 0x20 117 | #define IRQ_WUI 0x10 118 | #define IRQ_DOI 0x08 119 | #define IRQ_EI 0x04 120 | #define IRQ_TI 0x02 121 | #define IRQ_RI 0x01 122 | #define IRQ_ALL 0xFF 123 | #define IRQ_OFF 0x00 124 | 125 | /* status register content */ 126 | #define SR_BS 0x80 127 | #define SR_ES 0x40 128 | #define SR_TS 0x20 129 | #define SR_RS 0x10 130 | #define SR_TCS 0x08 131 | #define SR_TBS 0x04 132 | #define SR_DOS 0x02 133 | #define SR_RBS 0x01 134 | 135 | #define SR_CRIT (SR_BS|SR_ES) 136 | 137 | /* ECC register */ 138 | #define ECC_SEG 0x1F 139 | #define ECC_DIR 0x20 140 | #define ECC_ERR 6 141 | #define ECC_BIT 0x00 142 | #define ECC_FORM 0x40 143 | #define ECC_STUFF 0x80 144 | #define ECC_MASK 0xc0 145 | 146 | /* 147 | * Flags for sja1000priv.flags 148 | */ 149 | #define SJA1000_CUSTOM_IRQ_HANDLER 0x1 150 | 151 | /* 152 | * SJA1000 private data structure 153 | */ 154 | struct sja1000_priv { 155 | struct can_priv can; /* must be the first member */ 156 | int open_time; 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 | 173 | u16 flags; /* custom mode flags */ 174 | u8 ocr; /* output control register */ 175 | u8 cdr; /* clock divider register */ 176 | }; 177 | 178 | struct net_device *alloc_sja1000dev(int sizeof_priv); 179 | void free_sja1000dev(struct net_device *dev); 180 | int register_sja1000dev(struct net_device *dev); 181 | void unregister_sja1000dev(struct net_device *dev); 182 | 183 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) 184 | irqreturn_t sja1000_interrupt(int irq, void *dev_id, struct pt_regs *regs); 185 | #else 186 | irqreturn_t sja1000_interrupt(int irq, void *dev_id); 187 | #endif 188 | 189 | #endif /* SJA1000_DEV_H */ 190 | -------------------------------------------------------------------------------- /drivers/net/can/sja1000/sja1000_of_platform.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Driver for SJA1000 CAN controllers on the OpenFirmware platform bus 3 | * 4 | * Copyright (C) 2008-2009 Wolfgang Grandegger 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the version 2 of the GNU General Public License 8 | * as published by the Free Software Foundation 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | /* This is a generic driver for SJA1000 chips on the OpenFirmware platform 21 | * bus found on embedded PowerPC systems. You need a SJA1000 CAN node 22 | * definition in your flattened device tree source (DTS) file similar to: 23 | * 24 | * can@3,100 { 25 | * compatible = "nxp,sja1000"; 26 | * reg = <3 0x100 0x80>; 27 | * interrupts = <2 0>; 28 | * interrupt-parent = <&mpic>; 29 | * nxp,external-clock-frequency = <16000000>; 30 | * }; 31 | * 32 | * See "Documentation/powerpc/dts-bindings/can/sja1000.txt" for further 33 | * information. 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include 46 | #include 47 | 48 | #include "sja1000.h" 49 | 50 | #define DRV_NAME "sja1000_of_platform" 51 | 52 | MODULE_AUTHOR("Wolfgang Grandegger "); 53 | MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the OF platform bus"); 54 | MODULE_LICENSE("GPL v2"); 55 | 56 | #define SJA1000_OFP_CAN_CLOCK (16000000 / 2) 57 | 58 | #define SJA1000_OFP_OCR OCR_TX0_PULLDOWN 59 | #define SJA1000_OFP_CDR (CDR_CBP | CDR_CLK_OFF) 60 | 61 | static u8 sja1000_ofp_read_reg(const struct sja1000_priv *priv, int reg) 62 | { 63 | return in_8(priv->reg_base + reg); 64 | } 65 | 66 | static void sja1000_ofp_write_reg(const struct sja1000_priv *priv, 67 | int reg, u8 val) 68 | { 69 | out_8(priv->reg_base + reg, val); 70 | } 71 | 72 | static int __devexit sja1000_ofp_remove(struct of_device *ofdev) 73 | { 74 | struct net_device *dev = dev_get_drvdata(&ofdev->dev); 75 | struct sja1000_priv *priv = netdev_priv(dev); 76 | struct device_node *np = ofdev->node; 77 | struct resource res; 78 | 79 | dev_set_drvdata(&ofdev->dev, NULL); 80 | 81 | unregister_sja1000dev(dev); 82 | free_sja1000dev(dev); 83 | iounmap(priv->reg_base); 84 | irq_dispose_mapping(dev->irq); 85 | 86 | of_address_to_resource(np, 0, &res); 87 | release_mem_region(res.start, resource_size(&res)); 88 | 89 | return 0; 90 | } 91 | 92 | static int __devinit sja1000_ofp_probe(struct of_device *ofdev, 93 | const struct of_device_id *id) 94 | { 95 | struct device_node *np = ofdev->node; 96 | struct net_device *dev; 97 | struct sja1000_priv *priv; 98 | struct resource res; 99 | const u32 *prop; 100 | int err, irq, res_size, prop_size; 101 | void __iomem *base; 102 | 103 | err = of_address_to_resource(np, 0, &res); 104 | if (err) { 105 | dev_err(&ofdev->dev, "invalid address\n"); 106 | return err; 107 | } 108 | 109 | res_size = resource_size(&res); 110 | 111 | if (!request_mem_region(res.start, res_size, DRV_NAME)) { 112 | dev_err(&ofdev->dev, "couldn't request %#llx..%#llx\n", 113 | (unsigned long long)res.start, 114 | (unsigned long long)res.end); 115 | return -EBUSY; 116 | } 117 | 118 | base = ioremap_nocache(res.start, res_size); 119 | if (!base) { 120 | dev_err(&ofdev->dev, "couldn't ioremap %#llx..%#llx\n", 121 | (unsigned long long)res.start, 122 | (unsigned long long)res.end); 123 | err = -ENOMEM; 124 | goto exit_release_mem; 125 | } 126 | 127 | irq = irq_of_parse_and_map(np, 0); 128 | if (irq == NO_IRQ) { 129 | dev_err(&ofdev->dev, "no irq found\n"); 130 | err = -ENODEV; 131 | goto exit_unmap_mem; 132 | } 133 | 134 | dev = alloc_sja1000dev(0); 135 | if (!dev) { 136 | err = -ENOMEM; 137 | goto exit_dispose_irq; 138 | } 139 | 140 | priv = netdev_priv(dev); 141 | 142 | priv->read_reg = sja1000_ofp_read_reg; 143 | priv->write_reg = sja1000_ofp_write_reg; 144 | 145 | /* backward compatibility */ 146 | prop = of_get_property(np, "clock-frequency", &prop_size); 147 | if (!prop) 148 | prop = of_get_property(np, "nxp,external-clock-frequency", 149 | &prop_size); 150 | 151 | if (prop && (prop_size == sizeof(u32))) 152 | priv->can.clock.freq = *prop / 2; 153 | else 154 | priv->can.clock.freq = SJA1000_OFP_CAN_CLOCK; /* default */ 155 | 156 | /* backward compatibility */ 157 | prop = of_get_property(np, "ocr-reg", &prop_size); 158 | if (prop && (prop_size == sizeof(u32))) { 159 | priv->ocr = (u8)*prop; 160 | } else { 161 | 162 | prop = of_get_property(np, "nxp,tx-output-mode", &prop_size); 163 | if (prop && (prop_size == sizeof(u32))) 164 | priv->ocr |= *prop & OCR_MODE_MASK; 165 | else 166 | priv->ocr |= OCR_MODE_NORMAL; /* default */ 167 | 168 | prop = of_get_property(np, "nxp,tx-output-config", &prop_size); 169 | if (prop && (prop_size == sizeof(u32))) 170 | priv->ocr |= (*prop << OCR_TX_SHIFT) & OCR_TX_MASK; 171 | else 172 | priv->ocr |= OCR_TX0_PULLDOWN; /* default */ 173 | } 174 | 175 | /* backward compatibility */ 176 | prop = of_get_property(np, "cdr-reg", &prop_size); 177 | if (prop && (prop_size == sizeof(u32))) { 178 | priv->cdr = (u8)*prop; 179 | } else { 180 | prop = of_get_property(np, "nxp,clock-out-frequency", 181 | &prop_size); 182 | if (prop && (prop_size == sizeof(u32)) && *prop) { 183 | u32 divider = priv->can.clock.freq * 2 / *prop; 184 | 185 | if (divider > 1) 186 | priv->cdr |= divider / 2 - 1; 187 | else 188 | priv->cdr |= CDR_CLKOUT_MASK; 189 | } else { 190 | priv->cdr |= CDR_CLK_OFF; /* default */ 191 | } 192 | 193 | prop = of_get_property(np, "nxp,no-comparator-bypass", NULL); 194 | if (!prop) 195 | priv->cdr |= CDR_CBP; /* default */ 196 | } 197 | 198 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) 199 | priv->irq_flags = SA_SHIRQ; 200 | #else 201 | priv->irq_flags = IRQF_SHARED; 202 | #endif 203 | priv->reg_base = base; 204 | 205 | dev->irq = irq; 206 | 207 | dev_info(&ofdev->dev, 208 | "reg_base=0x%p irq=%d clock=%d ocr=0x%02x cdr=0x%02x\n", 209 | priv->reg_base, dev->irq, priv->can.clock.freq, 210 | priv->ocr, priv->cdr); 211 | 212 | dev_set_drvdata(&ofdev->dev, dev); 213 | SET_NETDEV_DEV(dev, &ofdev->dev); 214 | 215 | err = register_sja1000dev(dev); 216 | if (err) { 217 | dev_err(&ofdev->dev, "registering %s failed (err=%d)\n", 218 | DRV_NAME, err); 219 | goto exit_free_sja1000; 220 | } 221 | 222 | return 0; 223 | 224 | exit_free_sja1000: 225 | free_sja1000dev(dev); 226 | exit_dispose_irq: 227 | irq_dispose_mapping(irq); 228 | exit_unmap_mem: 229 | iounmap(base); 230 | exit_release_mem: 231 | release_mem_region(res.start, res_size); 232 | 233 | return err; 234 | } 235 | 236 | static struct of_device_id __devinitdata sja1000_ofp_table[] = { 237 | {.compatible = "philips,sja1000"}, 238 | {.compatible = "nxp,sja1000"}, 239 | {}, 240 | }; 241 | 242 | static struct of_platform_driver sja1000_ofp_driver = { 243 | .owner = THIS_MODULE, 244 | .name = DRV_NAME, 245 | .probe = sja1000_ofp_probe, 246 | .remove = __devexit_p(sja1000_ofp_remove), 247 | .match_table = sja1000_ofp_table, 248 | }; 249 | 250 | static int __init sja1000_ofp_init(void) 251 | { 252 | return of_register_platform_driver(&sja1000_ofp_driver); 253 | } 254 | module_init(sja1000_ofp_init); 255 | 256 | static void __exit sja1000_ofp_exit(void) 257 | { 258 | return of_unregister_platform_driver(&sja1000_ofp_driver); 259 | }; 260 | module_exit(sja1000_ofp_exit); 261 | -------------------------------------------------------------------------------- /drivers/net/can/sja1000/sja1000_platform.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 Sascha Hauer, Pengutronix 3 | * Copyright (C) 2007 Wolfgang Grandegger 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the version 2 of the GNU General Public License 7 | * as published by the Free Software Foundation 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "sja1000.h" 34 | 35 | #define DRV_NAME "sja1000_platform" 36 | 37 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) 38 | #error This driver does not support Kernel versions < 2.6.27 39 | #endif 40 | 41 | MODULE_AUTHOR("Sascha Hauer "); 42 | MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the platform bus"); 43 | MODULE_LICENSE("GPL v2"); 44 | 45 | static u8 sp_read_reg(const struct sja1000_priv *priv, int reg) 46 | { 47 | return ioread8(priv->reg_base + reg); 48 | } 49 | 50 | static void sp_write_reg(const struct sja1000_priv *priv, int reg, u8 val) 51 | { 52 | iowrite8(val, priv->reg_base + reg); 53 | } 54 | 55 | static int sp_probe(struct platform_device *pdev) 56 | { 57 | int err; 58 | void __iomem *addr; 59 | struct net_device *dev; 60 | struct sja1000_priv *priv; 61 | struct resource *res_mem, *res_irq; 62 | struct sja1000_platform_data *pdata; 63 | 64 | pdata = pdev->dev.platform_data; 65 | if (!pdata) { 66 | dev_err(&pdev->dev, "No platform data provided!\n"); 67 | err = -ENODEV; 68 | goto exit; 69 | } 70 | 71 | res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 72 | res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 73 | if (!res_mem || !res_irq) { 74 | err = -ENODEV; 75 | goto exit; 76 | } 77 | 78 | if (!request_mem_region(res_mem->start, resource_size(res_mem), 79 | DRV_NAME)) { 80 | err = -EBUSY; 81 | goto exit; 82 | } 83 | 84 | addr = ioremap_nocache(res_mem->start, resource_size(res_mem)); 85 | if (!addr) { 86 | err = -ENOMEM; 87 | goto exit_release; 88 | } 89 | 90 | dev = alloc_sja1000dev(0); 91 | if (!dev) { 92 | err = -ENOMEM; 93 | goto exit_iounmap; 94 | } 95 | priv = netdev_priv(dev); 96 | 97 | dev->irq = res_irq->start; 98 | priv->irq_flags = res_irq->flags & IRQF_TRIGGER_MASK; 99 | priv->reg_base = addr; 100 | priv->read_reg = sp_read_reg; 101 | priv->write_reg = sp_write_reg; 102 | priv->can.clock.freq = pdata->clock; 103 | priv->ocr = pdata->ocr; 104 | priv->cdr = pdata->cdr; 105 | 106 | dev_set_drvdata(&pdev->dev, dev); 107 | SET_NETDEV_DEV(dev, &pdev->dev); 108 | 109 | err = register_sja1000dev(dev); 110 | if (err) { 111 | dev_err(&pdev->dev, "registering %s failed (err=%d)\n", 112 | DRV_NAME, err); 113 | goto exit_free; 114 | } 115 | 116 | dev_info(&pdev->dev, "%s device registered (reg_base=%p, irq=%d)\n", 117 | DRV_NAME, priv->reg_base, dev->irq); 118 | return 0; 119 | 120 | exit_free: 121 | free_sja1000dev(dev); 122 | exit_iounmap: 123 | iounmap(addr); 124 | exit_release: 125 | release_mem_region(res_mem->start, resource_size(res_mem)); 126 | exit: 127 | return err; 128 | } 129 | 130 | static int sp_remove(struct platform_device *pdev) 131 | { 132 | struct net_device *dev = dev_get_drvdata(&pdev->dev); 133 | struct sja1000_priv *priv = netdev_priv(dev); 134 | struct resource *res; 135 | 136 | unregister_sja1000dev(dev); 137 | dev_set_drvdata(&pdev->dev, NULL); 138 | 139 | if (priv->reg_base) 140 | iounmap(priv->reg_base); 141 | 142 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 143 | release_mem_region(res->start, resource_size(res)); 144 | 145 | free_sja1000dev(dev); 146 | 147 | return 0; 148 | } 149 | 150 | static struct platform_driver sp_driver = { 151 | .probe = sp_probe, 152 | .remove = sp_remove, 153 | .driver = { 154 | .name = DRV_NAME, 155 | .owner = THIS_MODULE, 156 | }, 157 | }; 158 | 159 | static int __init sp_init(void) 160 | { 161 | return platform_driver_register(&sp_driver); 162 | } 163 | 164 | static void __exit sp_exit(void) 165 | { 166 | platform_driver_unregister(&sp_driver); 167 | } 168 | 169 | module_init(sp_init); 170 | module_exit(sp_exit); 171 | -------------------------------------------------------------------------------- /drivers/net/can/softing/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for softing CAN driver 2 | 3 | ifeq ($(KERNELRELEASE),) 4 | # necessary when used outside kernel 5 | KERNELDIR := /lib/modules/$(shell uname -r)/build 6 | PWD := $(shell pwd) 7 | TOPDIR := $(PWD)/../../../.. 8 | 9 | modules modules_install clean: 10 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 11 | 12 | else 13 | 14 | -include $(TOPDIR)/Makefile.common 15 | 16 | softing-y := softing_main.o softing_fw.o softing_sysfs.o 17 | obj-$(CONFIG_CAN_SOFTING) += softing.o 18 | obj-$(CONFIG_CAN_SOFTING_CS) += softing_cs.o 19 | 20 | endif 21 | -------------------------------------------------------------------------------- /drivers/net/can/softing/softing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * softing common interfaces 3 | * 4 | * by Kurt Van Dijck, 06-2008 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | struct softing; 14 | struct sofing_desc; 15 | 16 | /* softing firmware directory prefix */ 17 | #define fw_dir "softing-4.6/" 18 | 19 | /* special attribute, so we should not rely on the ->priv pointers 20 | * before knowing how to interpret these 21 | */ 22 | struct softing_attribute; 23 | 24 | struct softing_priv { 25 | struct can_priv can; /* must be the first member! */ 26 | struct net_device *netdev; 27 | struct softing *card; 28 | struct { 29 | int pending; 30 | /* variables which hold the circular buffer */ 31 | int echo_put; 32 | int echo_get; 33 | } tx; 34 | struct can_bittiming_const btr_const; 35 | int index; 36 | u8 output; 37 | u16 chip; 38 | struct attribute_group sysfs; 39 | }; 40 | #define netdev2softing(netdev) ((struct softing_priv *)netdev_priv(netdev)) 41 | 42 | struct softing_desc { 43 | unsigned int manf; 44 | unsigned int prod; 45 | /* generation 46 | * 1st with NEC or SJA1000 47 | * 8bit, exclusive interrupt, ... 48 | * 2nd only SJA11000 49 | * 16bit, shared interrupt 50 | */ 51 | int generation; 52 | unsigned int freq; /*crystal in MHz */ 53 | unsigned int max_brp; 54 | unsigned int max_sjw; 55 | unsigned long dpram_size; 56 | char name[32]; 57 | struct { 58 | unsigned long offs; 59 | unsigned long addr; 60 | char fw[32]; 61 | } boot, load, app; 62 | }; 63 | 64 | struct softing { 65 | int nbus; 66 | struct softing_priv *bus[2]; 67 | spinlock_t spin; /* protect this structure & DPRAM access */ 68 | ktime_t ts_ref; 69 | ktime_t ts_overflow; /* timestamp overflow value, in ktime */ 70 | 71 | struct { 72 | /* indication of firmware status */ 73 | int up; 74 | int failed; /* firmware has failed */ 75 | /* protection of the 'up' variable */ 76 | struct mutex lock; 77 | } fw; 78 | struct { 79 | int nr; 80 | int requested; 81 | struct tasklet_struct bh; 82 | int svc_count; 83 | } irq; 84 | struct { 85 | int pending; 86 | int last_bus; 87 | /* keep the bus that last tx'd a message, 88 | * in order to let every netdev queue resume 89 | */ 90 | } tx; 91 | struct { 92 | unsigned long phys; 93 | unsigned long size; 94 | unsigned char *virt; 95 | unsigned char *end; 96 | struct softing_fct *fct; 97 | struct softing_info *info; 98 | struct softing_rx *rx; 99 | struct softing_tx *tx; 100 | struct softing_irq *irq; 101 | unsigned short *command; 102 | unsigned short *receipt; 103 | } dpram; 104 | struct { 105 | unsigned short manf; 106 | unsigned short prod; 107 | u32 serial, fw, hw, lic; 108 | u16 chip[2]; 109 | u32 freq; 110 | const char *name; 111 | } id; 112 | const struct softing_desc *desc; 113 | struct { 114 | int (*reset) (struct softing *, int); 115 | int (*enable_irq)(struct softing *, int); 116 | } fn; 117 | struct device *dev; 118 | /* sysfs */ 119 | struct attribute_group sysfs; 120 | struct softing_attribute *attr; 121 | struct attribute **grp; 122 | }; 123 | 124 | extern int mk_softing(struct softing *); 125 | /* fields that must be set already are : 126 | * ncan 127 | * id.manf 128 | * id.prod 129 | * fn.reset 130 | * fn.enable_irq 131 | */ 132 | extern void rm_softing(struct softing *); 133 | /* usefull functions during operation */ 134 | 135 | extern int softing_default_output(struct softing *card 136 | , struct softing_priv *priv); 137 | extern ktime_t softing_raw2ktime(struct softing *card, u32 raw); 138 | 139 | extern int softing_fct_cmd(struct softing *card 140 | , int cmd, int vector, const char *msg); 141 | 142 | extern int softing_bootloader_command(struct softing *card 143 | , int command, const char *msg); 144 | 145 | /* Load firmware after reset */ 146 | extern int softing_load_fw(const char *file, struct softing *card, 147 | unsigned char *virt, unsigned int size, int offset); 148 | 149 | /* Load final application firmware after bootloader */ 150 | extern int softing_load_app_fw(const char *file, struct softing *card); 151 | 152 | extern int softing_reset_chip(struct softing *card); 153 | 154 | /* enable or disable irq 155 | * only called with fw.lock locked 156 | */ 157 | extern int softing_card_irq(struct softing *card, int enable); 158 | 159 | /* start/stop 1 bus on cardr*/ 160 | extern int softing_cycle( 161 | struct softing *card, struct softing_priv *priv, int up); 162 | 163 | /* netif_rx() */ 164 | extern int softing_rx(struct net_device *netdev, const struct can_frame *msg, 165 | ktime_t ktime); 166 | 167 | /* create/remove the per-card associated sysfs entries */ 168 | extern int softing_card_sysfs_create(struct softing *card); 169 | extern void softing_card_sysfs_remove(struct softing *card); 170 | /* create/remove the per-bus associated sysfs entries */ 171 | extern int softing_bus_sysfs_create(struct softing_priv *bus); 172 | extern void softing_bus_sysfs_remove(struct softing_priv *bus); 173 | 174 | /* SOFTING DPRAM mappings */ 175 | struct softing_rx { 176 | u8 fifo[16][32]; 177 | u8 dummy1; 178 | u16 rd; 179 | u16 dummy2; 180 | u16 wr; 181 | u16 dummy3; 182 | u16 lost_msg; 183 | } __attribute__((packed)); 184 | 185 | #define TXMAX 31 186 | struct softing_tx { 187 | u8 fifo[32][16]; 188 | u8 dummy1; 189 | u16 rd; 190 | u16 dummy2; 191 | u16 wr; 192 | u8 dummy3; 193 | } __attribute__((packed)); 194 | 195 | struct softing_irq { 196 | u8 to_host; 197 | u8 to_card; 198 | } __attribute__((packed)); 199 | 200 | struct softing_fct { 201 | s16 param[20]; /* 0 is index */ 202 | s16 returned; 203 | u8 dummy; 204 | u16 host_access; 205 | } __attribute__((packed)); 206 | 207 | struct softing_info { 208 | u8 dummy1; 209 | u16 bus_state; 210 | u16 dummy2; 211 | u16 bus_state2; 212 | u16 dummy3; 213 | u16 error_state; 214 | u16 dummy4; 215 | u16 error_state2; 216 | u16 dummy5; 217 | u16 reset; 218 | u16 dummy6; 219 | u16 clear_rcv_fifo; 220 | u16 dummy7; 221 | u16 dummyxx; 222 | u16 dummy8; 223 | u16 time_reset; 224 | u8 dummy9; 225 | u32 time; 226 | u32 time_wrap; 227 | u8 wr_start; 228 | u8 wr_end; 229 | u8 dummy10; 230 | u16 dummy12; 231 | u16 dummy12x; 232 | u16 dummy13; 233 | u16 reset_rcv_fifo; 234 | u8 dummy14; 235 | u8 reset_xmt_fifo; 236 | u8 read_fifo_levels; 237 | u16 rcv_fifo_level; 238 | u16 xmt_fifo_level; 239 | } __attribute__((packed)); 240 | 241 | /* DPRAM return codes */ 242 | #define RES_NONE 0 243 | #define RES_OK 1 244 | #define RES_NOK 2 245 | #define RES_UNKNOWN 3 246 | /* DPRAM flags */ 247 | #define CMD_TX 0x01 248 | #define CMD_ACK 0x02 249 | #define CMD_XTD 0x04 250 | #define CMD_RTR 0x08 251 | #define CMD_ERR 0x10 252 | #define CMD_BUS2 0x80 253 | 254 | /* debug */ 255 | extern int softing_debug; 256 | 257 | -------------------------------------------------------------------------------- /drivers/net/can/softing/softing_sysfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * drivers/net/can/softing/softing_sysfs.c 3 | * 4 | * Copyright (C) 2009 5 | * 6 | * - Kurt Van Dijck, EIA Electronics 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the version 2 of the GNU General Public License 10 | * as published by the Free Software Foundation 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "softing.h" 28 | 29 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) 30 | #error This driver does not support Kernel versions < 2.6.23 31 | #endif 32 | 33 | /*sysfs stuff*/ 34 | 35 | /* Because the struct softing may be used by pcmcia devices 36 | * as well as pci devices, * we have no clue how to get 37 | * from a struct device * towards the struct softing *. 38 | * It may go over a pci_device->priv or over a pcmcia_device->priv. 39 | * Therefore, provide the struct softing pointer within the attribute. 40 | * Then we don't need driver/bus specific things in these attributes 41 | */ 42 | struct softing_attribute { 43 | struct device_attribute dev; 44 | ssize_t (*show) (struct softing *card, char *buf); 45 | ssize_t (*store)(struct softing *card, const char *buf, size_t count); 46 | struct softing *card; 47 | }; 48 | 49 | static ssize_t rd_card_attr(struct device *dev, struct device_attribute *attr 50 | , char *buf) { 51 | struct softing_attribute *cattr 52 | = container_of(attr, struct softing_attribute, dev); 53 | return cattr->show ? cattr->show(cattr->card, buf) : 0; 54 | } 55 | static ssize_t wr_card_attr(struct device *dev, struct device_attribute *attr 56 | , const char *buf, size_t count) { 57 | struct softing_attribute *cattr 58 | = container_of(attr, struct softing_attribute, dev); 59 | return cattr->store ? cattr->store(cattr->card, buf, count) : 0; 60 | } 61 | 62 | #define declare_attr(_name, _mode, _show, _store) { \ 63 | .dev = { \ 64 | .attr = { \ 65 | .name = __stringify(_name), \ 66 | .mode = _mode, \ 67 | }, \ 68 | .show = rd_card_attr, \ 69 | .store = wr_card_attr, \ 70 | }, \ 71 | .show = _show, \ 72 | .store = _store, \ 73 | } 74 | 75 | #define CARD_SHOW(name, member) \ 76 | static ssize_t show_##name(struct softing *card, char *buf) { \ 77 | return sprintf(buf, "%u\n", card->member); \ 78 | } 79 | CARD_SHOW(serial , id.serial); 80 | CARD_SHOW(firmware , id.fw); 81 | CARD_SHOW(hardware , id.hw); 82 | CARD_SHOW(license , id.lic); 83 | CARD_SHOW(freq , id.freq); 84 | CARD_SHOW(txpending , tx.pending); 85 | 86 | static const struct softing_attribute card_attr_proto[] = { 87 | declare_attr(serial , 0444, show_serial , 0), 88 | declare_attr(firmware , 0444, show_firmware , 0), 89 | declare_attr(hardware , 0444, show_hardware , 0), 90 | declare_attr(license , 0444, show_license , 0), 91 | declare_attr(freq , 0444, show_freq , 0), 92 | declare_attr(txpending , 0644, show_txpending , 0), 93 | }; 94 | 95 | int softing_card_sysfs_create(struct softing *card) 96 | { 97 | int size; 98 | int j; 99 | 100 | size = sizeof(card_attr_proto)/sizeof(card_attr_proto[0]); 101 | card->attr = kmalloc((size+1)*sizeof(card->attr[0]), GFP_KERNEL); 102 | if (!card->attr) 103 | goto attr_mem_failed; 104 | memcpy(card->attr, card_attr_proto, size * sizeof(card->attr[0])); 105 | memset(&card->attr[size], 0, sizeof(card->attr[0])); 106 | 107 | card->grp = kmalloc((size+1)*sizeof(card->grp[0]), GFP_KERNEL); 108 | if (!card->grp) 109 | goto grp_mem_failed; 110 | 111 | for (j = 0; j < size; ++j) { 112 | card->attr[j].card = card; 113 | card->grp[j] = &card->attr[j].dev.attr; 114 | if (!card->attr[j].show) 115 | card->attr[j].dev.attr.mode &= ~(S_IRUGO); 116 | if (!card->attr[j].store) 117 | card->attr[j].dev.attr.mode &= ~(S_IWUGO); 118 | } 119 | card->grp[size] = 0; 120 | card->sysfs.name = "softing"; 121 | card->sysfs.attrs = card->grp; 122 | if (sysfs_create_group(&card->dev->kobj, &card->sysfs) < 0) 123 | goto sysfs_failed; 124 | 125 | return 0; 126 | 127 | sysfs_failed: 128 | kfree(card->grp); 129 | grp_mem_failed: 130 | kfree(card->attr); 131 | attr_mem_failed: 132 | return -1; 133 | } 134 | void softing_card_sysfs_remove(struct softing *card) 135 | { 136 | sysfs_remove_group(&card->dev->kobj, &card->sysfs); 137 | kfree(card->grp); 138 | kfree(card->attr); 139 | } 140 | 141 | static ssize_t show_channel(struct device *dev 142 | , struct device_attribute *attr, char *buf) 143 | { 144 | struct net_device *ndev = to_net_dev(dev); 145 | struct softing_priv *priv = netdev2softing(ndev); 146 | return sprintf(buf, "%i\n", priv->index); 147 | } 148 | 149 | static ssize_t show_chip(struct device *dev 150 | , struct device_attribute *attr, char *buf) 151 | { 152 | struct net_device *ndev = to_net_dev(dev); 153 | struct softing_priv *priv = netdev2softing(ndev); 154 | return sprintf(buf, "%i\n", priv->chip); 155 | } 156 | 157 | static ssize_t show_output(struct device *dev 158 | , struct device_attribute *attr, char *buf) 159 | { 160 | struct net_device *ndev = to_net_dev(dev); 161 | struct softing_priv *priv = netdev2softing(ndev); 162 | return sprintf(buf, "0x%02x\n", priv->output); 163 | } 164 | 165 | static ssize_t store_output(struct device *dev 166 | , struct device_attribute *attr 167 | , const char *buf, size_t count) 168 | { 169 | struct net_device *ndev = to_net_dev(dev); 170 | struct softing_priv *priv = netdev2softing(ndev); 171 | struct softing *card = priv->card; 172 | unsigned long val; 173 | int ret; 174 | 175 | ret = strict_strtoul(buf, 0, &val); 176 | if (ret < 0) 177 | return ret; 178 | val &= 0xFF; 179 | 180 | ret = mutex_lock_interruptible(&card->fw.lock); 181 | if (ret) 182 | return -ERESTARTSYS; 183 | if (netif_running(ndev)) { 184 | mutex_unlock(&card->fw.lock); 185 | return -EBUSY; 186 | } 187 | priv->output = val; 188 | mutex_unlock(&card->fw.lock); 189 | return count; 190 | } 191 | /* TODO 192 | * the latest softing cards support sleep mode too 193 | */ 194 | 195 | static const DEVICE_ATTR(channel, S_IRUGO, show_channel, 0); 196 | static const DEVICE_ATTR(chip, S_IRUGO, show_chip, 0); 197 | static const DEVICE_ATTR(output, S_IRUGO | S_IWUSR, show_output, store_output); 198 | 199 | static const struct attribute *const netdev_sysfs_entries[] = { 200 | &dev_attr_channel .attr, 201 | &dev_attr_chip .attr, 202 | &dev_attr_output .attr, 203 | 0, 204 | }; 205 | static const struct attribute_group netdev_sysfs = { 206 | .name = 0, 207 | .attrs = (struct attribute **)netdev_sysfs_entries, 208 | }; 209 | 210 | int softing_bus_sysfs_create(struct softing_priv *priv) 211 | { 212 | if (!priv->netdev->dev.kobj.sd) { 213 | dev_alert(priv->card->dev, "sysfs_create_group would fail\n"); 214 | return ENODEV; 215 | } 216 | return sysfs_create_group(&priv->netdev->dev.kobj, &netdev_sysfs); 217 | } 218 | void softing_bus_sysfs_remove(struct softing_priv *priv) 219 | { 220 | sysfs_remove_group(&priv->netdev->dev.kobj, &netdev_sysfs); 221 | } 222 | 223 | -------------------------------------------------------------------------------- /drivers/net/can/sysfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: dev.c 542 2007-11-07 13:57:16Z thuermann $ 3 | * 4 | * Copyright (C) 2007 Wolfgang Grandegger 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the version 2 of the GNU General Public License 8 | * as published by the Free Software Foundation 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef CAN_SYSFS_H 21 | #define CAN_SYSFS_H 22 | 23 | void can_create_sysfs(struct net_device *dev); 24 | void can_remove_sysfs(struct net_device *dev); 25 | int can_sample_point(struct can_bittiming *bt); 26 | 27 | #endif /* CAN_SYSFS_H */ 28 | -------------------------------------------------------------------------------- /drivers/net/can/usb/Kconfig: -------------------------------------------------------------------------------- 1 | menu "CAN USB interfaces" 2 | depends on USB && CAN_DEV 3 | 4 | config CAN_EMS_USB 5 | tristate "EMS CPC-USB/ARM7 CAN/USB interface" 6 | ---help--- 7 | This driver is for the one channel CPC-USB/ARM7 CAN/USB interface 8 | from from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de). 9 | 10 | config CAN_ESD_USB2 11 | tristate "ESD USB/2 CAN/USB interface" 12 | ---help--- 13 | This driver supports the CAN-USB/2 interface 14 | from esd electronic system design gmbh (http://www.esd.eu). 15 | 16 | endmenu 17 | -------------------------------------------------------------------------------- /drivers/net/can/usb/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for the Linux Controller Area Network USB drivers. 3 | # 4 | 5 | ifeq ($(KERNELRELEASE),) 6 | 7 | KERNELDIR := /lib/modules/$(shell uname -r)/build 8 | PWD := $(shell pwd) 9 | TOPDIR := $(PWD)/../../../.. 10 | 11 | modules modules_install clean: 12 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 13 | 14 | else 15 | 16 | -include $(TOPDIR)/Makefile.common 17 | 18 | obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o 19 | obj-$(CONFIG_CAN_ESD_USB2) += esd_usb2.o 20 | 21 | ifeq ($(CONFIG_CAN_DEBUG_DEVICES),y) 22 | EXTRA_CFLAGS += -DDEBUG 23 | endif 24 | 25 | endif 26 | -------------------------------------------------------------------------------- /include/linux/can.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/linux/can/bcm.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/linux/can/core.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/linux/can/dev.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/linux/can/error.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/linux/can/gw.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/linux/can/isotp.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/linux/can/netlink.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/linux/can/raw.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/socketcan/can.h: -------------------------------------------------------------------------------- 1 | /* 2 | * socketcan/can.h 3 | * 4 | * Definitions for CAN network layer (socket addr / CAN frame / CAN filter) 5 | * 6 | * Authors: Oliver Hartkopp 7 | * Urs Thuermann 8 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 9 | * All rights reserved. 10 | * 11 | */ 12 | 13 | #ifndef CAN_H 14 | #define CAN_H 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | /* controller area network (CAN) kernel definitions */ 21 | 22 | /* special address description flags for the CAN_ID */ 23 | #define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */ 24 | #define CAN_RTR_FLAG 0x40000000U /* remote transmission request */ 25 | #define CAN_ERR_FLAG 0x20000000U /* error message frame */ 26 | 27 | /* valid bits in CAN ID for frame formats */ 28 | #define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */ 29 | #define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */ 30 | #define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */ 31 | 32 | /* 33 | * Controller Area Network Identifier structure 34 | * 35 | * bit 0-28 : CAN identifier (11/29 bit) 36 | * bit 29 : error message frame flag (0 = data frame, 1 = error message) 37 | * bit 30 : remote transmission request flag (1 = rtr frame) 38 | * bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit) 39 | */ 40 | typedef __u32 canid_t; 41 | 42 | #define CAN_SFF_ID_BITS 11 43 | #define CAN_EFF_ID_BITS 29 44 | 45 | /* 46 | * Controller Area Network Error Message Frame Mask structure 47 | * 48 | * bit 0-28 : error class mask (see include/socketcan/can/error.h) 49 | * bit 29-31 : set to zero 50 | */ 51 | typedef __u32 can_err_mask_t; 52 | 53 | /* CAN payload length and DLC definitions according to ISO 11898-1 */ 54 | #define CAN_MAX_DLC 8 55 | #define CAN_MAX_DLEN 8 56 | 57 | /* CAN FD payload length and DLC definitions according to ISO 11898-7 */ 58 | #define CANFD_MAX_DLC 15 59 | #define CANFD_MAX_DLEN 64 60 | 61 | /** 62 | * struct can_frame - basic CAN frame structure 63 | * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition 64 | * @can_dlc: frame payload length in byte (0 .. 8) aka data length code 65 | * N.B. the DLC field from ISO 11898-1 Chapter 8.4.2.3 has a 1:1 66 | * mapping of the 'data length code' to the real payload length 67 | * @data: CAN frame payload (up to 8 byte) 68 | */ 69 | struct can_frame { 70 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ 71 | __u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */ 72 | __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8))); 73 | }; 74 | 75 | /* 76 | * defined bits for canfd_frame.flags 77 | * 78 | * The use of struct canfd_frame implies the Extended Data Length (EDL) bit to 79 | * be set in the CAN frame bitstream on the wire. The EDL bit switch turns 80 | * the CAN controllers bitstream processor into the CAN FD mode which creates 81 | * two new options within the CAN FD frame specification: 82 | * 83 | * Bit Rate Switch - to indicate a second bitrate is/was used for the payload 84 | * Error State Indicator - represents the error state of the transmitting node 85 | * 86 | * As the CANFD_ESI bit is internally generated by the transmitting CAN 87 | * controller only the CANFD_BRS bit is relevant for real CAN controllers when 88 | * building a CAN FD frame for transmission. Setting the CANFD_ESI bit can make 89 | * sense for virtual CAN interfaces to test applications with echoed frames. 90 | */ 91 | #define CANFD_BRS 0x01 /* bit rate switch (second bitrate for payload data) */ 92 | #define CANFD_ESI 0x02 /* error state indicator of the transmitting node */ 93 | 94 | /** 95 | * struct canfd_frame - CAN flexible data rate frame structure 96 | * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition 97 | * @len: frame payload length in byte (0 .. CANFD_MAX_DLEN) 98 | * @flags: additional flags for CAN FD 99 | * @__res0: reserved / padding 100 | * @__res1: reserved / padding 101 | * @data: CAN FD frame payload (up to CANFD_MAX_DLEN byte) 102 | */ 103 | struct canfd_frame { 104 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ 105 | __u8 len; /* frame payload length in byte */ 106 | __u8 flags; /* additional flags for CAN FD */ 107 | __u8 __res0; /* reserved / padding */ 108 | __u8 __res1; /* reserved / padding */ 109 | __u8 data[CANFD_MAX_DLEN] __attribute__((aligned(8))); 110 | }; 111 | 112 | #define CAN_MTU (sizeof(struct can_frame)) 113 | #define CANFD_MTU (sizeof(struct canfd_frame)) 114 | 115 | /* particular protocols of the protocol family PF_CAN */ 116 | #define CAN_RAW 1 /* RAW sockets */ 117 | #define CAN_BCM 2 /* Broadcast Manager */ 118 | #define CAN_TP16 3 /* VAG Transport Protocol v1.6 */ 119 | #define CAN_TP20 4 /* VAG Transport Protocol v2.0 */ 120 | #define CAN_MCNET 5 /* Bosch MCNet */ 121 | #define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */ 122 | #define CAN_NPROTO 7 123 | 124 | #define SOL_CAN_BASE 100 125 | 126 | // typedef unsigned short __kernel_sa_family_t; 127 | // introduced in Linux 3.2 commit 6602a4baf4d1a73cc4685a39ef859e1c5ddf654c 128 | 129 | /** 130 | * struct sockaddr_can - the sockaddr structure for CAN sockets 131 | * @can_family: address family number AF_CAN. 132 | * @can_ifindex: CAN network interface index. 133 | * @can_addr: protocol specific address information 134 | */ 135 | struct sockaddr_can { 136 | sa_family_t can_family; 137 | // __kernel_sa_family_t can_family; 138 | int can_ifindex; 139 | union { 140 | /* transport protocol class address information (e.g. ISOTP) */ 141 | struct { canid_t rx_id, tx_id; } tp; 142 | 143 | /* reserved for future CAN protocols address information */ 144 | } can_addr; 145 | }; 146 | 147 | /** 148 | * struct can_filter - CAN ID based filter in can_register(). 149 | * @can_id: relevant bits of CAN ID which are not masked out. 150 | * @can_mask: CAN mask (see description) 151 | * 152 | * Description: 153 | * A filter matches, when 154 | * 155 | * & mask == can_id & mask 156 | * 157 | * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can 158 | * filter for error message frames (CAN_ERR_FLAG bit set in mask). 159 | */ 160 | struct can_filter { 161 | canid_t can_id; 162 | canid_t can_mask; 163 | }; 164 | 165 | #define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */ 166 | 167 | #endif /* CAN_H */ 168 | -------------------------------------------------------------------------------- /include/socketcan/can/bcm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * socketcan/can/bcm.h 3 | * 4 | * Definitions for CAN Broadcast Manager (BCM) 5 | * 6 | * $Id$ 7 | * 8 | * Author: Oliver Hartkopp 9 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 10 | * All rights reserved. 11 | * 12 | * Send feedback to 13 | * 14 | */ 15 | 16 | #ifndef CAN_BCM_H 17 | #define CAN_BCM_H 18 | 19 | /** 20 | * struct bcm_msg_head - head of messages to/from the broadcast manager 21 | * @opcode: opcode, see enum below. 22 | * @flags: special flags, see below. 23 | * @count: number of frames to send before changing interval. 24 | * @ival1: interval for the first @count frames. 25 | * @ival2: interval for the following frames. 26 | * @can_id: CAN ID of frames to be sent or received. 27 | * @nframes: number of frames appended to the message head. 28 | * @frames: array of CAN frames. 29 | */ 30 | struct bcm_msg_head { 31 | __u32 opcode; 32 | __u32 flags; 33 | __u32 count; 34 | struct timeval ival1, ival2; 35 | canid_t can_id; 36 | __u32 nframes; 37 | struct can_frame frames[0]; 38 | }; 39 | 40 | enum { 41 | TX_SETUP = 1, /* create (cyclic) transmission task */ 42 | TX_DELETE, /* remove (cyclic) transmission task */ 43 | TX_READ, /* read properties of (cyclic) transmission task */ 44 | TX_SEND, /* send one CAN frame */ 45 | RX_SETUP, /* create RX content filter subscription */ 46 | RX_DELETE, /* remove RX content filter subscription */ 47 | RX_READ, /* read properties of RX content filter subscription */ 48 | TX_STATUS, /* reply to TX_READ request */ 49 | TX_EXPIRED, /* notification on performed transmissions (count=0) */ 50 | RX_STATUS, /* reply to RX_READ request */ 51 | RX_TIMEOUT, /* cyclic message is absent */ 52 | RX_CHANGED /* updated CAN frame (detected content change) */ 53 | }; 54 | 55 | #define SETTIMER 0x0001 56 | #define STARTTIMER 0x0002 57 | #define TX_COUNTEVT 0x0004 58 | #define TX_ANNOUNCE 0x0008 59 | #define TX_CP_CAN_ID 0x0010 60 | #define RX_FILTER_ID 0x0020 61 | #define RX_CHECK_DLC 0x0040 62 | #define RX_NO_AUTOTIMER 0x0080 63 | #define RX_ANNOUNCE_RESUME 0x0100 64 | #define TX_RESET_MULTI_IDX 0x0200 65 | #define RX_RTR_FRAME 0x0400 66 | 67 | #endif /* CAN_BCM_H */ 68 | -------------------------------------------------------------------------------- /include/socketcan/can/core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * socketcan/can/core.h 3 | * 4 | * Protoypes and definitions for CAN protocol modules using the PF_CAN core 5 | * 6 | * $Id$ 7 | * 8 | * Authors: Oliver Hartkopp 9 | * Urs Thuermann 10 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 11 | * All rights reserved. 12 | * 13 | * Send feedback to 14 | * 15 | */ 16 | 17 | #ifndef CAN_CORE_H 18 | #define CAN_CORE_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #define CAN_VERSION "20090105" 25 | 26 | /* increment this number each time you change some user-space interface */ 27 | #define CAN_ABI_VERSION "8" 28 | 29 | #define CAN_VERSION_STRING "rev " CAN_VERSION " abi " CAN_ABI_VERSION 30 | 31 | #define DNAME(dev) ((dev) ? (dev)->name : "any") 32 | 33 | /** 34 | * struct can_proto - CAN protocol structure 35 | * @type: type argument in socket() syscall, e.g. SOCK_DGRAM. 36 | * @protocol: protocol number in socket() syscall. 37 | * @capability: capability needed to open the socket, or -1 for no restriction. 38 | * @ops: pointer to struct proto_ops for sock->ops. 39 | * @prot: pointer to struct proto structure. 40 | */ 41 | struct can_proto { 42 | int type; 43 | int protocol; 44 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) 45 | int capability; 46 | #endif 47 | const struct proto_ops *ops; 48 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12) 49 | struct proto *prot; 50 | #else 51 | struct module *owner; 52 | int (*init)(struct sock *sk); 53 | size_t obj_size; 54 | #endif 55 | }; 56 | 57 | /* function prototypes for the CAN networklayer core (af_can.c) */ 58 | 59 | extern int can_proto_register(const struct can_proto *cp); 60 | extern void can_proto_unregister(const struct can_proto *cp); 61 | 62 | extern int can_rx_register(struct net_device *dev, canid_t can_id, 63 | canid_t mask, 64 | void (*func)(struct sk_buff *, void *), 65 | void *data, char *ident); 66 | 67 | extern void can_rx_unregister(struct net_device *dev, canid_t can_id, 68 | canid_t mask, 69 | void (*func)(struct sk_buff *, void *), 70 | void *data); 71 | 72 | extern int can_send(struct sk_buff *skb, int loop); 73 | extern int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 74 | 75 | #endif /* CAN_CORE_H */ 76 | -------------------------------------------------------------------------------- /include/socketcan/can/dev.h: -------------------------------------------------------------------------------- 1 | /* 2 | * socketcan/can/dev.h 3 | * 4 | * Definitions for the CAN network device driver interface 5 | * 6 | * $Id$ 7 | * 8 | * Copyright (C) 2006 Andrey Volkov 9 | * Varma Electronics Oy 10 | * 11 | * Copyright (C) 2008 Wolfgang Grandegger 12 | * 13 | * Send feedback to 14 | */ 15 | 16 | #ifndef CAN_DEV_H 17 | #define CAN_DEV_H 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | /* 24 | * CAN mode 25 | */ 26 | enum can_mode { 27 | CAN_MODE_STOP = 0, 28 | CAN_MODE_START, 29 | CAN_MODE_SLEEP 30 | }; 31 | 32 | /* 33 | * CAN common private data 34 | */ 35 | struct can_priv { 36 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) 37 | struct net_device_stats net_stats; 38 | #endif 39 | struct can_device_stats can_stats; 40 | 41 | struct can_bittiming bittiming; 42 | struct can_bittiming_const *bittiming_const; 43 | struct can_clock clock; 44 | 45 | enum can_state state; 46 | u32 ctrlmode; 47 | u32 ctrlmode_supported; 48 | 49 | int restart_ms; 50 | struct timer_list restart_timer; 51 | 52 | int (*do_set_bittiming)(struct net_device *dev); 53 | int (*do_set_mode)(struct net_device *dev, enum can_mode mode); 54 | int (*do_get_state)(const struct net_device *dev, 55 | enum can_state *state); 56 | int (*do_get_berr_counter)(const struct net_device *dev, 57 | struct can_berr_counter *bec); 58 | 59 | unsigned int echo_skb_max; 60 | struct sk_buff **echo_skb; 61 | }; 62 | 63 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) 64 | #define ND2D(_ndev) (_ndev->class_dev.dev) 65 | #else 66 | #define ND2D(_ndev) (_ndev->dev.parent) 67 | #endif 68 | 69 | /* 70 | * get_can_dlc(value) - helper macro to cast a given data length code (dlc) 71 | * to __u8 and ensure the dlc value to be max. 8 bytes. 72 | * 73 | * To be used in the CAN netdriver receive path to ensure conformance with 74 | * ISO 11898-1 Chapter 8.4.2.3 (DLC field) 75 | */ 76 | #define get_can_dlc(i) (min_t(__u8, (i), 8)) 77 | 78 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) 79 | #define IFF_ECHO IFF_LOOPBACK 80 | #endif 81 | 82 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) 83 | struct net_device_stats *can_get_stats(struct net_device *dev); 84 | #endif 85 | 86 | /* Drop a given socketbuffer if it does not contain a valid CAN frame. */ 87 | static inline int can_dropped_invalid_skb(struct net_device *dev, 88 | struct sk_buff *skb) 89 | { 90 | const struct can_frame *cf = (struct can_frame *)skb->data; 91 | 92 | if (unlikely(skb->len != sizeof(*cf) || cf->can_dlc > 8)) { 93 | kfree_skb(skb); 94 | dev->stats.tx_dropped++; 95 | return 1; 96 | } 97 | 98 | return 0; 99 | } 100 | 101 | struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max); 102 | void free_candev(struct net_device *dev); 103 | 104 | int open_candev(struct net_device *dev); 105 | void close_candev(struct net_device *dev); 106 | 107 | int register_candev(struct net_device *dev); 108 | void unregister_candev(struct net_device *dev); 109 | 110 | int can_restart_now(struct net_device *dev); 111 | void can_bus_off(struct net_device *dev); 112 | 113 | void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, 114 | unsigned int idx); 115 | void can_get_echo_skb(struct net_device *dev, unsigned int idx); 116 | void can_free_echo_skb(struct net_device *dev, unsigned int idx); 117 | 118 | struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf); 119 | struct sk_buff *alloc_can_err_skb(struct net_device *dev, 120 | struct can_frame **cf); 121 | 122 | #endif /* CAN_DEV_H */ 123 | -------------------------------------------------------------------------------- /include/socketcan/can/error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * socketcan/can/error.h 3 | * 4 | * Definitions of the CAN error frame to be filtered and passed to the user. 5 | * 6 | * $Id$ 7 | * 8 | * Author: Oliver Hartkopp 9 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 10 | * All rights reserved. 11 | * 12 | * Send feedback to 13 | * 14 | */ 15 | 16 | #ifndef CAN_ERROR_H 17 | #define CAN_ERROR_H 18 | 19 | #define CAN_ERR_DLC 8 /* dlc for error frames */ 20 | 21 | /* error class (mask) in can_id */ 22 | #define CAN_ERR_TX_TIMEOUT 0x00000001U /* TX timeout (by netdevice driver) */ 23 | #define CAN_ERR_LOSTARB 0x00000002U /* lost arbitration / data[0] */ 24 | #define CAN_ERR_CRTL 0x00000004U /* controller problems / data[1] */ 25 | #define CAN_ERR_PROT 0x00000008U /* protocol violations / data[2..3] */ 26 | #define CAN_ERR_TRX 0x00000010U /* transceiver status / data[4] */ 27 | #define CAN_ERR_ACK 0x00000020U /* received no ACK on transmission */ 28 | #define CAN_ERR_BUSOFF 0x00000040U /* bus off */ 29 | #define CAN_ERR_BUSERROR 0x00000080U /* bus error (may flood!) */ 30 | #define CAN_ERR_RESTARTED 0x00000100U /* controller restarted */ 31 | 32 | /* arbitration lost in bit ... / data[0] */ 33 | #define CAN_ERR_LOSTARB_UNSPEC 0x00 /* unspecified */ 34 | /* else bit number in bitstream */ 35 | 36 | /* error status of CAN-controller / data[1] */ 37 | #define CAN_ERR_CRTL_UNSPEC 0x00 /* unspecified */ 38 | #define CAN_ERR_CRTL_RX_OVERFLOW 0x01 /* RX buffer overflow */ 39 | #define CAN_ERR_CRTL_TX_OVERFLOW 0x02 /* TX buffer overflow */ 40 | #define CAN_ERR_CRTL_RX_WARNING 0x04 /* reached warning level for RX errors */ 41 | #define CAN_ERR_CRTL_TX_WARNING 0x08 /* reached warning level for TX errors */ 42 | #define CAN_ERR_CRTL_RX_PASSIVE 0x10 /* reached error passive status RX */ 43 | #define CAN_ERR_CRTL_TX_PASSIVE 0x20 /* reached error passive status TX */ 44 | /* (at least one error counter exceeds */ 45 | /* the protocol-defined level of 127) */ 46 | 47 | /* error in CAN protocol (type) / data[2] */ 48 | #define CAN_ERR_PROT_UNSPEC 0x00 /* unspecified */ 49 | #define CAN_ERR_PROT_BIT 0x01 /* single bit error */ 50 | #define CAN_ERR_PROT_FORM 0x02 /* frame format error */ 51 | #define CAN_ERR_PROT_STUFF 0x04 /* bit stuffing error */ 52 | #define CAN_ERR_PROT_BIT0 0x08 /* unable to send dominant bit */ 53 | #define CAN_ERR_PROT_BIT1 0x10 /* unable to send recessive bit */ 54 | #define CAN_ERR_PROT_OVERLOAD 0x20 /* bus overload */ 55 | #define CAN_ERR_PROT_ACTIVE 0x40 /* active error announcement */ 56 | #define CAN_ERR_PROT_TX 0x80 /* error occurred on transmission */ 57 | 58 | /* error in CAN protocol (location) / data[3] */ 59 | #define CAN_ERR_PROT_LOC_UNSPEC 0x00 /* unspecified */ 60 | #define CAN_ERR_PROT_LOC_SOF 0x03 /* start of frame */ 61 | #define CAN_ERR_PROT_LOC_ID28_21 0x02 /* ID bits 28 - 21 (SFF: 10 - 3) */ 62 | #define CAN_ERR_PROT_LOC_ID20_18 0x06 /* ID bits 20 - 18 (SFF: 2 - 0 )*/ 63 | #define CAN_ERR_PROT_LOC_SRTR 0x04 /* substitute RTR (SFF: RTR) */ 64 | #define CAN_ERR_PROT_LOC_IDE 0x05 /* identifier extension */ 65 | #define CAN_ERR_PROT_LOC_ID17_13 0x07 /* ID bits 17-13 */ 66 | #define CAN_ERR_PROT_LOC_ID12_05 0x0F /* ID bits 12-5 */ 67 | #define CAN_ERR_PROT_LOC_ID04_00 0x0E /* ID bits 4-0 */ 68 | #define CAN_ERR_PROT_LOC_RTR 0x0C /* RTR */ 69 | #define CAN_ERR_PROT_LOC_RES1 0x0D /* reserved bit 1 */ 70 | #define CAN_ERR_PROT_LOC_RES0 0x09 /* reserved bit 0 */ 71 | #define CAN_ERR_PROT_LOC_DLC 0x0B /* data length code */ 72 | #define CAN_ERR_PROT_LOC_DATA 0x0A /* data section */ 73 | #define CAN_ERR_PROT_LOC_CRC_SEQ 0x08 /* CRC sequence */ 74 | #define CAN_ERR_PROT_LOC_CRC_DEL 0x18 /* CRC delimiter */ 75 | #define CAN_ERR_PROT_LOC_ACK 0x19 /* ACK slot */ 76 | #define CAN_ERR_PROT_LOC_ACK_DEL 0x1B /* ACK delimiter */ 77 | #define CAN_ERR_PROT_LOC_EOF 0x1A /* end of frame */ 78 | #define CAN_ERR_PROT_LOC_INTERM 0x12 /* intermission */ 79 | 80 | /* error status of CAN-transceiver / data[4] */ 81 | /* CANH CANL */ 82 | #define CAN_ERR_TRX_UNSPEC 0x00 /* 0000 0000 */ 83 | #define CAN_ERR_TRX_CANH_NO_WIRE 0x04 /* 0000 0100 */ 84 | #define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05 /* 0000 0101 */ 85 | #define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06 /* 0000 0110 */ 86 | #define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07 /* 0000 0111 */ 87 | #define CAN_ERR_TRX_CANL_NO_WIRE 0x40 /* 0100 0000 */ 88 | #define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50 /* 0101 0000 */ 89 | #define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60 /* 0110 0000 */ 90 | #define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70 /* 0111 0000 */ 91 | #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80 /* 1000 0000 */ 92 | 93 | /* controller specific additional information / data[5..7] */ 94 | 95 | #endif /* CAN_ERROR_H */ 96 | -------------------------------------------------------------------------------- /include/socketcan/can/gw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * socketcan/can/gw.h 3 | * 4 | * Definitions for CAN frame Gateway/Router/Bridge 5 | * 6 | * $Id$ 7 | * 8 | * Author: Oliver Hartkopp 9 | * Copyright (c) 2011 Volkswagen Group Electronic Research 10 | * All rights reserved. 11 | * 12 | * Send feedback to 13 | * 14 | */ 15 | 16 | #ifndef CAN_GW_H 17 | #define CAN_GW_H 18 | 19 | #include 20 | #include 21 | 22 | struct rtcanmsg { 23 | __u8 can_family; 24 | __u8 gwtype; 25 | __u16 flags; 26 | }; 27 | 28 | /* CAN gateway types */ 29 | enum { 30 | CGW_TYPE_UNSPEC, 31 | CGW_TYPE_CAN_CAN, /* CAN->CAN routing */ 32 | __CGW_TYPE_MAX 33 | }; 34 | 35 | #define CGW_TYPE_MAX (__CGW_TYPE_MAX - 1) 36 | 37 | /* CAN rtnetlink attribute definitions */ 38 | enum { 39 | CGW_UNSPEC, 40 | CGW_MOD_AND, /* CAN frame modification binary AND */ 41 | CGW_MOD_OR, /* CAN frame modification binary OR */ 42 | CGW_MOD_XOR, /* CAN frame modification binary XOR */ 43 | CGW_MOD_SET, /* CAN frame modification set alternate values */ 44 | CGW_CS_XOR, /* set data[] XOR checksum into data[index] */ 45 | CGW_CS_CRC8, /* set data[] CRC8 checksum into data[index] */ 46 | CGW_HANDLED, /* number of handled CAN frames */ 47 | CGW_DROPPED, /* number of dropped CAN frames */ 48 | CGW_SRC_IF, /* ifindex of source network interface */ 49 | CGW_DST_IF, /* ifindex of destination network interface */ 50 | CGW_FILTER, /* specify struct can_filter on source CAN device */ 51 | __CGW_MAX 52 | }; 53 | 54 | #define CGW_MAX (__CGW_MAX - 1) 55 | 56 | #define CGW_FLAGS_CAN_ECHO 0x01 57 | #define CGW_FLAGS_CAN_SRC_TSTAMP 0x02 58 | 59 | #define CGW_MOD_FUNCS 4 /* AND OR XOR SET */ 60 | 61 | /* CAN frame elements that are affected by curr. 3 CAN frame modifications */ 62 | #define CGW_MOD_ID 0x01 63 | #define CGW_MOD_DLC 0x02 64 | #define CGW_MOD_DATA 0x04 65 | 66 | #define CGW_FRAME_MODS 3 /* ID DLC DATA */ 67 | 68 | #define MAX_MODFUNCTIONS (CGW_MOD_FUNCS * CGW_FRAME_MODS) 69 | 70 | struct cgw_frame_mod { 71 | struct can_frame cf; 72 | __u8 modtype; 73 | } __attribute__((packed)); 74 | 75 | #define CGW_MODATTR_LEN sizeof(struct cgw_frame_mod) 76 | 77 | struct cgw_csum_xor { 78 | __s8 from_idx; 79 | __s8 to_idx; 80 | __s8 result_idx; 81 | __u8 init_xor_val; 82 | } __attribute__((packed)); 83 | 84 | struct cgw_csum_crc8 { 85 | __s8 from_idx; 86 | __s8 to_idx; 87 | __s8 result_idx; 88 | __u8 init_crc_val; 89 | __u8 final_xor_val; 90 | __u8 crctab[256]; 91 | __u8 profile; 92 | __u8 profile_data[20]; 93 | } __attribute__((packed)); 94 | 95 | /* length of checksum operation parameters. idx = index in CAN frame data[] */ 96 | #define CGW_CS_XOR_LEN sizeof(struct cgw_csum_xor) 97 | #define CGW_CS_CRC8_LEN sizeof(struct cgw_csum_crc8) 98 | 99 | /* CRC8 profiles (compute CRC for additional data elements - see below) */ 100 | enum { 101 | CGW_CRC8PRF_UNSPEC, 102 | CGW_CRC8PRF_1U8, /* compute one additional u8 value */ 103 | CGW_CRC8PRF_16U8, /* u8 value table indexed by data[1] & 0xF */ 104 | CGW_CRC8PRF_SFFID_XOR, /* (can_id & 0xFF) ^ (can_id >> 8 & 0xFF) */ 105 | __CGW_CRC8PRF_MAX 106 | }; 107 | 108 | #define CGW_CRC8PRF_MAX (__CGW_CRC8PRF_MAX - 1) 109 | 110 | /* 111 | * CAN rtnetlink attribute contents in detail 112 | * 113 | * CGW_XXX_IF (length 4 bytes): 114 | * Sets an interface index for source/destination network interfaces. 115 | * For the CAN->CAN gwtype the indices of _two_ CAN interfaces are mandatory. 116 | * 117 | * CGW_FILTER (length 8 bytes): 118 | * Sets a CAN receive filter for the gateway job specified by the 119 | * struct can_filter described in include/linux/can.h 120 | * 121 | * CGW_MOD_XXX (length 17 bytes): 122 | * Specifies a modification that's done to a received CAN frame before it is 123 | * send out to the destination interface. 124 | * 125 | * data used as operator 126 | * affected CAN frame elements 127 | * 128 | * CGW_CS_XOR (length 4 bytes): 129 | * Set a simple XOR checksum starting with an initial value into 130 | * data[result-idx] using data[start-idx] .. data[end-idx] 131 | * 132 | * The XOR checksum is calculated like this: 133 | * 134 | * xor = init_xor_val 135 | * 136 | * for (i = from_idx .. to_idx) 137 | * xor ^= can_frame.data[i] 138 | * 139 | * can_frame.data[ result_idx ] = xor 140 | * 141 | * CGW_CS_CRC8 (length 282 bytes): 142 | * Set a CRC8 value into data[result-idx] using a given 256 byte CRC8 table, 143 | * a given initial value and a defined input data[start-idx] .. data[end-idx]. 144 | * Finally the result value is XOR'ed with the final_xor_val. 145 | * 146 | * The CRC8 checksum is calculated like this: 147 | * 148 | * crc = init_crc_val 149 | * 150 | * for (i = from_idx .. to_idx) 151 | * crc = crctab[ crc ^ can_frame.data[i] ] 152 | * 153 | * can_frame.data[ result_idx ] = crc ^ final_xor_val 154 | * 155 | * The calculated CRC may contain additional source data elements that can be 156 | * defined in the handling of 'checksum profiles' e.g. shown in AUTOSAR specs 157 | * like http://www.autosar.org/download/R4.0/AUTOSAR_SWS_E2ELibrary.pdf 158 | * E.g. the profile_data[] may contain additional u8 values (called DATA_IDs) 159 | * that are used depending on counter values inside the CAN frame data[]. 160 | * So far only three profiles have been implemented for illustration. 161 | * 162 | * Remark: In general the attribute data is a linear buffer. 163 | * Beware of sending unpacked or aligned structs! 164 | */ 165 | 166 | #endif 167 | -------------------------------------------------------------------------------- /include/socketcan/can/ioctl.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * socketcan/can/ioctl.h 4 | * 5 | * Definitions for CAN controller setup (work in progress) 6 | * 7 | * $Id$ 8 | * 9 | * Send feedback to 10 | * 11 | */ 12 | 13 | #ifndef CAN_IOCTL_H 14 | #define CAN_IOCTL_H 15 | 16 | #include 17 | 18 | /* 19 | * CAN bitrate 20 | */ 21 | #define CAN_BITRATE_UNCONFIGURED ((__u32) 0xFFFFFFFFU) 22 | #define CAN_BITRATE_UNKNOWN 0 23 | #define CAN_BITRATE_DEFAULT 500000 24 | 25 | /* 26 | * CAN custom bit time 27 | */ 28 | enum can_bittimes { 29 | CAN_BITTIME_STD, 30 | CAN_BITTIME_BTR 31 | }; 32 | 33 | /* TSEG1 of controllers usually is a sum of synch_seg (always 1), 34 | * prop_seg and phase_seg1, TSEG2 = phase_seg2 */ 35 | 36 | struct can_bittime_std { 37 | __u32 brp; /* baud rate prescaler */ 38 | __u8 prop_seg; /* from 1 to 8 */ 39 | __u8 phase_seg1; /* from 1 to 8 */ 40 | __u8 phase_seg2; /* from 1 to 8 */ 41 | __u8 sjw:7; /* from 1 to 4 */ 42 | __u8 sam:1; /* 1 - enable triple sampling */ 43 | }; 44 | 45 | struct can_bittime_btr { 46 | __u8 btr0; 47 | __u8 btr1; 48 | }; 49 | 50 | struct can_bittime { 51 | enum can_bittimes type; 52 | union { 53 | struct can_bittime_std std; 54 | struct can_bittime_btr btr; 55 | }; 56 | }; 57 | 58 | /* 59 | * CAN mode 60 | */ 61 | enum can_mode { 62 | CAN_MODE_STOP = 0, 63 | CAN_MODE_START, 64 | CAN_MODE_SLEEP 65 | }; 66 | 67 | /* 68 | * CAN controller mode 69 | */ 70 | #define CAN_CTRLMODE_LOOPBACK 0x1 71 | #define CAN_CTRLMODE_LISTENONLY 0x2 72 | 73 | /* 74 | * CAN operational and error states 75 | */ 76 | enum can_state { 77 | CAN_STATE_ACTIVE = 0, 78 | CAN_STATE_BUS_WARNING, 79 | CAN_STATE_BUS_PASSIVE, 80 | CAN_STATE_BUS_OFF, 81 | CAN_STATE_STOPPED, 82 | CAN_STATE_SLEEPING 83 | }; 84 | 85 | /* 86 | * CAN device statistics 87 | */ 88 | struct can_device_stats { 89 | int error_warning; 90 | int data_overrun; 91 | int wakeup; 92 | int bus_error; 93 | int error_passive; 94 | int arbitration_lost; 95 | int restarts; 96 | int bus_error_at_init; 97 | }; 98 | 99 | #endif /* CAN_IOCTL_H */ 100 | -------------------------------------------------------------------------------- /include/socketcan/can/isotp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * socketcan/can/isotp.h 3 | * 4 | * Definitions for isotp CAN sockets 5 | * 6 | * $Id$ 7 | * 8 | * Author: Oliver Hartkopp 9 | * Copyright (c) 2008 Volkswagen Group Electronic Research 10 | * All rights reserved. 11 | * 12 | * Send feedback to 13 | * 14 | */ 15 | 16 | #ifndef CAN_ISOTP_H 17 | #define CAN_ISOTP_H 18 | 19 | #include 20 | 21 | #define SOL_CAN_ISOTP (SOL_CAN_BASE + CAN_ISOTP) 22 | 23 | /* for socket options affecting the socket (not the global system) */ 24 | 25 | #define CAN_ISOTP_OPTS 1 /* pass struct can_isotp_options */ 26 | 27 | #define CAN_ISOTP_RECV_FC 2 /* pass struct can_isotp_fc_options */ 28 | 29 | /* sockopts to force stmin timer values for protocol regression tests */ 30 | 31 | #define CAN_ISOTP_TX_STMIN 3 /* pass __u32 value in nano secs */ 32 | /* use this time instead of value */ 33 | /* provided in FC from the receiver */ 34 | 35 | #define CAN_ISOTP_RX_STMIN 4 /* pass __u32 value in nano secs */ 36 | /* ignore received CF frames which */ 37 | /* timestamps differ less than val */ 38 | 39 | #define CAN_ISOTP_LL_OPTS 5 /* pass struct can_isotp_ll_options */ 40 | 41 | struct can_isotp_options { 42 | 43 | __u32 flags; /* set flags for isotp behaviour. */ 44 | /* __u32 value : flags see below */ 45 | 46 | __u32 frame_txtime; /* frame transmission time (N_As/N_Ar) */ 47 | /* __u32 value : time in nano secs */ 48 | 49 | __u8 ext_address; /* set address for extended addressing */ 50 | /* __u8 value : extended address */ 51 | 52 | __u8 txpad_content; /* set content of padding byte (tx) */ 53 | /* __u8 value : content on tx path */ 54 | 55 | __u8 rxpad_content; /* set content of padding byte (rx) */ 56 | /* __u8 value : content on rx path */ 57 | 58 | __u8 rx_ext_address; /* set address for extended addressing */ 59 | /* __u8 value : extended address (rx) */ 60 | }; 61 | 62 | struct can_isotp_fc_options { 63 | 64 | __u8 bs; /* blocksize provided in FC frame */ 65 | /* __u8 value : blocksize. 0 = off */ 66 | 67 | __u8 stmin; /* separation time provided in FC frame */ 68 | /* __u8 value : */ 69 | /* 0x00 - 0x7F : 0 - 127 ms */ 70 | /* 0x80 - 0xF0 : reserved */ 71 | /* 0xF1 - 0xF9 : 100 us - 900 us */ 72 | /* 0xFA - 0xFF : reserved */ 73 | 74 | __u8 wftmax; /* max. number of wait frame transmiss. */ 75 | /* __u8 value : 0 = omit FC N_PDU WT */ 76 | }; 77 | 78 | struct can_isotp_ll_options { 79 | 80 | __u8 mtu; /* generated & accepted CAN frame type */ 81 | /* __u8 value : */ 82 | /* CAN_MTU (16) -> standard CAN 2.0 */ 83 | /* CANFD_MTU (72) -> CAN FD frame */ 84 | 85 | __u8 tx_dl; /* tx link layer data length in bytes */ 86 | /* (configured maximum payload length) */ 87 | /* __u8 value : 8,12,16,20,24,32,48,64 */ 88 | /* => rx path supports all LL_DL values */ 89 | 90 | __u8 tx_flags; /* set into struct canfd_frame.flags */ 91 | /* at frame creation: e.g. CANFD_BRS */ 92 | /* Obsolete when the BRS flag is fixed */ 93 | /* by the CAN netdriver configuration */ 94 | }; 95 | 96 | 97 | /* flags for isotp behaviour */ 98 | 99 | #define CAN_ISOTP_LISTEN_MODE 0x001 /* listen only (do not send FC) */ 100 | #define CAN_ISOTP_EXTEND_ADDR 0x002 /* enable extended addressing */ 101 | #define CAN_ISOTP_TX_PADDING 0x004 /* enable CAN frame padding tx path */ 102 | #define CAN_ISOTP_RX_PADDING 0x008 /* enable CAN frame padding rx path */ 103 | #define CAN_ISOTP_CHK_PAD_LEN 0x010 /* check received CAN frame padding */ 104 | #define CAN_ISOTP_CHK_PAD_DATA 0x020 /* check received CAN frame padding */ 105 | #define CAN_ISOTP_HALF_DUPLEX 0x040 /* half duplex error state handling */ 106 | #define CAN_ISOTP_FORCE_TXSTMIN 0x080 /* ignore stmin from received FC */ 107 | #define CAN_ISOTP_FORCE_RXSTMIN 0x100 /* ignore CFs depending on rx stmin */ 108 | #define CAN_ISOTP_RX_EXT_ADDR 0x200 /* different rx extended addressing */ 109 | 110 | 111 | /* default values */ 112 | 113 | #define CAN_ISOTP_DEFAULT_FLAGS 0 114 | #define CAN_ISOTP_DEFAULT_EXT_ADDRESS 0x00 115 | #define CAN_ISOTP_DEFAULT_PAD_CONTENT 0xCC /* prevent bit-stuffing */ 116 | #define CAN_ISOTP_DEFAULT_FRAME_TXTIME 0 117 | #define CAN_ISOTP_DEFAULT_RECV_BS 0 118 | #define CAN_ISOTP_DEFAULT_RECV_STMIN 0x00 119 | #define CAN_ISOTP_DEFAULT_RECV_WFTMAX 0 120 | 121 | #define CAN_ISOTP_DEFAULT_LL_MTU CAN_MTU 122 | #define CAN_ISOTP_DEFAULT_LL_TX_DL CAN_MAX_DLEN 123 | #define CAN_ISOTP_DEFAULT_LL_TX_FLAGS 0 124 | 125 | /* 126 | * Remark on CAN_ISOTP_DEFAULT_RECV_* values: 127 | * 128 | * We can strongly assume, that the Linux Kernel implementation of 129 | * CAN_ISOTP is capable to run with BS=0, STmin=0 and WFTmax=0. 130 | * But as we like to be able to behave as a commonly available ECU, 131 | * these default settings can be changed via sockopts. 132 | * For that reason the STmin value is intentionally _not_ checked for 133 | * consistency and copied directly into the flow control (FC) frame. 134 | * 135 | */ 136 | 137 | #endif 138 | -------------------------------------------------------------------------------- /include/socketcan/can/netlink.h: -------------------------------------------------------------------------------- 1 | /* 2 | * socketcan/can/netlink.h 3 | * 4 | * Definitions for the CAN netlink interface 5 | * 6 | * $Id: dev.h 939 2009-02-14 14:30:19Z wolf $ 7 | * 8 | * Copyright (c) 2009 Wolfgang Grandegger 9 | * 10 | * Send feedback to 11 | * 12 | */ 13 | 14 | #ifndef CAN_NETLINK_H 15 | #define CAN_NETLINK_H 16 | 17 | #include 18 | 19 | /* 20 | * CAN bit-timing parameters 21 | * 22 | * For further information, please read chapter "8 BIT TIMING 23 | * REQUIREMENTS" of the "Bosch CAN Specification version 2.0" 24 | * at http://www.semiconductors.bosch.de/pdf/can2spec.pdf. 25 | */ 26 | struct can_bittiming { 27 | __u32 bitrate; /* Bit-rate in bits/second */ 28 | __u32 sample_point; /* Sample point in one-tenth of a percent */ 29 | __u32 tq; /* Time quanta (TQ) in nanoseconds */ 30 | __u32 prop_seg; /* Propagation segment in TQs */ 31 | __u32 phase_seg1; /* Phase buffer segment 1 in TQs */ 32 | __u32 phase_seg2; /* Phase buffer segment 2 in TQs */ 33 | __u32 sjw; /* Synchronisation jump width in TQs */ 34 | __u32 brp; /* Bit-rate prescaler */ 35 | }; 36 | 37 | /* 38 | * CAN harware-dependent bit-timing constant 39 | * 40 | * Used for calculating and checking bit-timing parameters 41 | */ 42 | struct can_bittiming_const { 43 | char name[16]; /* Name of the CAN controller hardware */ 44 | __u32 tseg1_min; /* Time segement 1 = prop_seg + phase_seg1 */ 45 | __u32 tseg1_max; 46 | __u32 tseg2_min; /* Time segement 2 = phase_seg2 */ 47 | __u32 tseg2_max; 48 | __u32 sjw_max; /* Synchronisation jump width */ 49 | __u32 brp_min; /* Bit-rate prescaler */ 50 | __u32 brp_max; 51 | __u32 brp_inc; 52 | }; 53 | 54 | /* 55 | * CAN clock parameters 56 | */ 57 | struct can_clock { 58 | __u32 freq; /* CAN system clock frequency in Hz */ 59 | }; 60 | 61 | /* 62 | * CAN operational and error states 63 | */ 64 | enum can_state { 65 | CAN_STATE_ERROR_ACTIVE = 0, /* RX/TX error count < 96 */ 66 | CAN_STATE_ERROR_WARNING, /* RX/TX error count < 128 */ 67 | CAN_STATE_ERROR_PASSIVE, /* RX/TX error count < 256 */ 68 | CAN_STATE_BUS_OFF, /* RX/TX error count >= 256 */ 69 | CAN_STATE_STOPPED, /* Device is stopped */ 70 | CAN_STATE_SLEEPING, /* Device is sleeping */ 71 | CAN_STATE_MAX 72 | }; 73 | 74 | /* 75 | * CAN bus error counters 76 | */ 77 | struct can_berr_counter { 78 | __u16 txerr; 79 | __u16 rxerr; 80 | }; 81 | 82 | /* 83 | * CAN controller mode 84 | */ 85 | struct can_ctrlmode { 86 | __u32 mask; 87 | __u32 flags; 88 | }; 89 | 90 | #define CAN_CTRLMODE_LOOPBACK 0x01 /* Loopback mode */ 91 | #define CAN_CTRLMODE_LISTENONLY 0x02 /* Listen-only mode */ 92 | #define CAN_CTRLMODE_3_SAMPLES 0x04 /* Triple sampling mode */ 93 | #define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */ 94 | #define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */ 95 | 96 | /* 97 | * CAN device statistics 98 | */ 99 | struct can_device_stats { 100 | __u32 bus_error; /* Bus errors */ 101 | __u32 error_warning; /* Changes to error warning state */ 102 | __u32 error_passive; /* Changes to error passive state */ 103 | __u32 bus_off; /* Changes to bus off state */ 104 | __u32 arbitration_lost; /* Arbitration lost errors */ 105 | __u32 restarts; /* CAN controller re-starts */ 106 | }; 107 | 108 | /* 109 | * CAN netlink interface 110 | */ 111 | enum { 112 | IFLA_CAN_UNSPEC, 113 | IFLA_CAN_BITTIMING, 114 | IFLA_CAN_BITTIMING_CONST, 115 | IFLA_CAN_CLOCK, 116 | IFLA_CAN_STATE, 117 | IFLA_CAN_CTRLMODE, 118 | IFLA_CAN_RESTART_MS, 119 | IFLA_CAN_RESTART, 120 | IFLA_CAN_BERR_COUNTER, 121 | __IFLA_CAN_MAX 122 | }; 123 | 124 | #define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) 125 | 126 | #endif /* CAN_NETLINK_H */ 127 | -------------------------------------------------------------------------------- /include/socketcan/can/platform/mcp251x.h: -------------------------------------------------------------------------------- 1 | #ifndef __CAN_PLATFORM_MCP251X_H__ 2 | #define __CAN_PLATFORM_MCP251X_H__ 3 | 4 | /* 5 | * 6 | * CAN bus driver for Microchip 251x CAN Controller with SPI Interface 7 | * 8 | */ 9 | 10 | #include 11 | 12 | /** 13 | * struct mcp251x_platform_data - MCP251X SPI CAN controller platform data 14 | * @oscillator_frequency: - oscillator frequency in Hz 15 | * @model: - actual type of chip 16 | * @board_specific_setup: - called before probing the chip (power,reset) 17 | * @transceiver_enable: - called to power on/off the transceiver 18 | * @power_enable: - called to power on/off the mcp *and* the 19 | * transceiver 20 | * 21 | * Please note that you should define power_enable or transceiver_enable or 22 | * none of them. Defining both of them is no use. 23 | * 24 | */ 25 | 26 | struct mcp251x_platform_data { 27 | unsigned long oscillator_frequency; 28 | int model; 29 | #define CAN_MCP251X_MCP2510 0 30 | #define CAN_MCP251X_MCP2515 1 31 | int (*board_specific_setup)(struct spi_device *spi); 32 | int (*transceiver_enable)(int enable); 33 | int (*power_enable) (int enable); 34 | }; 35 | 36 | #endif /* __CAN_PLATFORM_MCP251X_H__ */ 37 | -------------------------------------------------------------------------------- /include/socketcan/can/platform/sja1000.h: -------------------------------------------------------------------------------- 1 | #ifndef _CAN_PLATFORM_SJA1000_H_ 2 | #define _CAN_PLATFORM_SJA1000_H_ 3 | 4 | /* clock divider register */ 5 | #define CDR_CLKOUT_MASK 0x07 6 | #define CDR_CLK_OFF 0x08 /* Clock off (CLKOUT pin) */ 7 | #define CDR_RXINPEN 0x20 /* TX1 output is RX irq output */ 8 | #define CDR_CBP 0x40 /* CAN input comparator bypass */ 9 | #define CDR_PELICAN 0x80 /* PeliCAN mode */ 10 | 11 | /* output control register */ 12 | #define OCR_MODE_BIPHASE 0x00 13 | #define OCR_MODE_TEST 0x01 14 | #define OCR_MODE_NORMAL 0x02 15 | #define OCR_MODE_CLOCK 0x03 16 | #define OCR_MODE_MASK 0x07 17 | #define OCR_TX0_INVERT 0x04 18 | #define OCR_TX0_PULLDOWN 0x08 19 | #define OCR_TX0_PULLUP 0x10 20 | #define OCR_TX0_PUSHPULL 0x18 21 | #define OCR_TX1_INVERT 0x20 22 | #define OCR_TX1_PULLDOWN 0x40 23 | #define OCR_TX1_PULLUP 0x80 24 | #define OCR_TX1_PUSHPULL 0xc0 25 | #define OCR_TX_MASK 0xfc 26 | #define OCR_TX_SHIFT 2 27 | 28 | struct sja1000_platform_data { 29 | u32 clock; /* CAN bus oscillator frequency in Hz */ 30 | 31 | u8 ocr; /* output control register */ 32 | u8 cdr; /* clock divider register */ 33 | }; 34 | 35 | #endif /* !_CAN_PLATFORM_SJA1000_H_ */ 36 | -------------------------------------------------------------------------------- /include/socketcan/can/raw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * socketcan/can/raw.h 3 | * 4 | * Definitions for raw CAN sockets 5 | * 6 | * $Id$ 7 | * 8 | * Authors: Oliver Hartkopp 9 | * Urs Thuermann 10 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 11 | * All rights reserved. 12 | * 13 | * Send feedback to 14 | * 15 | */ 16 | 17 | #ifndef CAN_RAW_H 18 | #define CAN_RAW_H 19 | 20 | #include 21 | 22 | #define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW) 23 | 24 | /* for socket options affecting the socket (not the global system) */ 25 | 26 | enum { 27 | CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s) */ 28 | CAN_RAW_ERR_FILTER, /* set filter for error frames */ 29 | CAN_RAW_LOOPBACK, /* local loopback (default:on) */ 30 | CAN_RAW_RECV_OWN_MSGS /* receive my own msgs (default:off) */ 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/socketcan/can/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * socketcan/can/version.h 3 | * 4 | * Version information for the CAN network layer implementation 5 | 6 | * Author: Urs Thuermann 7 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 8 | * All rights reserved. 9 | * 10 | * Send feedback to 11 | * 12 | */ 13 | 14 | #ifndef CAN_VERSION_H 15 | #define CAN_VERSION_H 16 | 17 | #define RCSID(s) asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t" \ 18 | ".string \"" s "\"\n\t.previous\n") 19 | 20 | RCSID("$Id$"); 21 | 22 | #endif /* CAN_VERSION_H */ 23 | -------------------------------------------------------------------------------- /net/can/Kconfig: -------------------------------------------------------------------------------- 1 | # 2 | # Controller Area Network (CAN) network layer core configuration 3 | # 4 | 5 | menuconfig CAN 6 | depends on NET 7 | tristate "CAN bus subsystem support" 8 | ---help--- 9 | Controller Area Network (CAN) is a slow (up to 1Mbit/s) serial 10 | communications protocol which was developed by Bosch in 11 | 1991, mainly for automotive, but now widely used in marine 12 | (NMEA2000), industrial, and medical applications. 13 | More information on the CAN network protocol family PF_CAN 14 | is contained in . 15 | 16 | If you want CAN support you should say Y here and also to the 17 | specific driver for your controller(s) below. 18 | 19 | config CAN_RAW 20 | tristate "Raw CAN Protocol (raw access with CAN-ID filtering)" 21 | depends on CAN 22 | default N 23 | ---help--- 24 | The raw CAN protocol option offers access to the CAN bus via 25 | the BSD socket API. You probably want to use the raw socket in 26 | most cases where no higher level protocol is being used. The raw 27 | socket has several filter options e.g. ID masking / error frames. 28 | To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW. 29 | 30 | config CAN_BCM 31 | tristate "Broadcast Manager CAN Protocol (with content filtering)" 32 | depends on CAN 33 | default N 34 | ---help--- 35 | The Broadcast Manager offers content filtering, timeout monitoring, 36 | sending of RTR frames, and cyclic CAN messages without permanent user 37 | interaction. The BCM can be 'programmed' via the BSD socket API and 38 | informs you on demand e.g. only on content updates / timeouts. 39 | You probably want to use the bcm socket in most cases where cyclic 40 | CAN messages are used on the bus (e.g. in automotive environments). 41 | To use the Broadcast Manager, use AF_CAN with protocol CAN_BCM. 42 | 43 | config CAN_GW 44 | tristate "CAN Gateway/Router (with netlink configuration)" 45 | depends on CAN 46 | default N 47 | ---help--- 48 | The CAN Gateway/Router is used to route (and modify) CAN frames. 49 | It is based on the PF_CAN core infrastructure for msg filtering and 50 | msg sending and can optionally modify routed CAN frames on the fly. 51 | CAN frames can be routed between CAN network interfaces (one hop). 52 | They can be modified with AND/OR/XOR/SET operations as configured 53 | by the netlink configuration interface known e.g. from iptables. 54 | 55 | config CAN_ISOTP 56 | tristate "ISO 15765-2 CAN transport protocol" 57 | depends on CAN && EXPERIMENTAL 58 | default N 59 | ---help--- 60 | CAN Transport Protocols offer support for segmented Point-to-Point 61 | communication between CAN nodes via two defined CAN Identifiers. 62 | This protocol driver implements data transfers according ISO 15765-2. 63 | WARNING: This is ALPHA code for discussions and first tests that 64 | should not be used in production environments. 65 | In the discussion the Socket-API to the userspace or the ISO-TP 66 | socket options or the return values may change! Current behaviour: 67 | - no ISO-TP specific return values are provided to the userspace 68 | - no support for sending wait frames to the data source in rx path 69 | - when a transfer (tx) is on the run the next write() blocks 70 | until the running transfer is done 71 | 72 | source "drivers/net/can/Kconfig" 73 | -------------------------------------------------------------------------------- /net/can/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # $Id$ 3 | # 4 | 5 | ifeq ($(KERNELRELEASE),) 6 | 7 | KERNELDIR := /lib/modules/$(shell uname -r)/build 8 | PWD := $(shell pwd) 9 | TOPDIR := $(PWD)/../.. 10 | 11 | modules modules_install clean: 12 | $(MAKE) -C $(KERNELDIR) M=$(PWD) $@ TOPDIR=$(TOPDIR) 13 | 14 | export CONFIG_CAN=m 15 | export CONFIG_CAN_RAW=m 16 | export CONFIG_CAN_BCM=m 17 | export CONFIG_CAN_ISOTP=m 18 | export CONFIG_CAN_GW=m 19 | 20 | else 21 | 22 | -include $(TOPDIR)/Makefile.common 23 | 24 | obj-$(CONFIG_CAN) += can.o 25 | can-objs := af_can.o proc.o 26 | 27 | obj-$(CONFIG_CAN_RAW) += can-raw.o 28 | can-raw-objs := raw.o 29 | 30 | obj-$(CONFIG_CAN_BCM) += can-bcm.o 31 | can-bcm-objs := bcm.o 32 | 33 | obj-$(CONFIG_CAN_ISOTP) += can-isotp.o 34 | can-isotp-objs := isotp.o 35 | 36 | obj-$(CONFIG_CAN_GW) += can-gw.o 37 | can-gw-objs := gw.o 38 | 39 | endif 40 | -------------------------------------------------------------------------------- /net/can/Makefile.kernel: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for the Linux Controller Area Network core. 3 | # 4 | 5 | obj-$(CONFIG_CAN) += can.o 6 | can-objs := af_can.o proc.o 7 | 8 | obj-$(CONFIG_CAN_RAW) += can-raw.o 9 | can-raw-objs := raw.o 10 | 11 | obj-$(CONFIG_CAN_BCM) += can-bcm.o 12 | can-bcm-objs := bcm.o 13 | -------------------------------------------------------------------------------- /net/can/af_can.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | * 4 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of Volkswagen nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * Alternatively, provided that this notice is retained in full, this 20 | * software may be distributed under the terms of the GNU General 21 | * Public License ("GPL") version 2, in which case the provisions of the 22 | * GPL apply INSTEAD OF those given above. 23 | * 24 | * The provided data structures and external interfaces from this code 25 | * are not restricted to be used by modules with a GPL compatible license. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 38 | * DAMAGE. 39 | * 40 | * Send feedback to 41 | * 42 | */ 43 | 44 | #ifndef AF_CAN_H 45 | #define AF_CAN_H 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | /* af_can rx dispatcher structures */ 54 | 55 | struct receiver { 56 | struct hlist_node list; 57 | struct rcu_head rcu; 58 | canid_t can_id; 59 | canid_t mask; 60 | unsigned long matches; 61 | void (*func)(struct sk_buff *, void *); 62 | void *data; 63 | char *ident; 64 | }; 65 | 66 | enum { RX_ERR, RX_ALL, RX_FIL, RX_INV, RX_EFF, RX_MAX }; 67 | 68 | struct dev_rcv_lists { 69 | struct hlist_node list; 70 | struct rcu_head rcu; 71 | struct net_device *dev; 72 | struct hlist_head rx[RX_MAX]; 73 | struct hlist_head rx_sff[0x800]; 74 | int remove_on_zero_entries; 75 | int entries; 76 | }; 77 | 78 | /* statistic structures */ 79 | 80 | /* can be reset e.g. by can_init_stats() */ 81 | struct s_stats { 82 | unsigned long jiffies_init; 83 | 84 | unsigned long rx_frames; 85 | unsigned long tx_frames; 86 | unsigned long matches; 87 | 88 | unsigned long total_rx_rate; 89 | unsigned long total_tx_rate; 90 | unsigned long total_rx_match_ratio; 91 | 92 | unsigned long current_rx_rate; 93 | unsigned long current_tx_rate; 94 | unsigned long current_rx_match_ratio; 95 | 96 | unsigned long max_rx_rate; 97 | unsigned long max_tx_rate; 98 | unsigned long max_rx_match_ratio; 99 | 100 | unsigned long rx_frames_delta; 101 | unsigned long tx_frames_delta; 102 | unsigned long matches_delta; 103 | }; 104 | 105 | /* persistent statistics */ 106 | struct s_pstats { 107 | unsigned long stats_reset; 108 | unsigned long user_reset; 109 | unsigned long rcv_entries; 110 | unsigned long rcv_entries_max; 111 | }; 112 | 113 | /* function prototypes for the CAN networklayer procfs (proc.c) */ 114 | extern void can_init_proc(void); 115 | extern void can_remove_proc(void); 116 | extern void can_stat_update(unsigned long data); 117 | 118 | /* structures and variables from af_can.c needed in proc.c for reading */ 119 | extern struct timer_list can_stattimer; /* timer for statistics update */ 120 | extern struct s_stats can_stats; /* packet statistics */ 121 | extern struct s_pstats can_pstats; /* receive list statistics */ 122 | extern struct hlist_head can_rx_dev_list; /* rx dispatcher structures */ 123 | 124 | #endif /* AF_CAN_H */ 125 | -------------------------------------------------------------------------------- /net/can/compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | #ifndef CAN_COMPAT_H 6 | #define CAN_COMPAT_H 7 | 8 | #ifndef PF_CAN 9 | #define PF_CAN 29 10 | #endif 11 | 12 | #ifndef AF_CAN 13 | #define AF_CAN PF_CAN 14 | #endif 15 | 16 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) 17 | static inline void *kzalloc(size_t size, unsigned int __nocast flags) 18 | { 19 | void *ret = kmalloc(size, flags); 20 | if (ret) 21 | memset(ret, 0, size); 22 | return ret; 23 | } 24 | 25 | static inline void skb_get_timestamp(const struct sk_buff *skb, 26 | struct timeval *stamp) 27 | { 28 | stamp->tv_sec = skb->stamp.tv_sec; 29 | stamp->tv_usec = skb->stamp.tv_usec; 30 | } 31 | 32 | static inline void skb_set_timestamp(struct sk_buff *skb, 33 | const struct timeval *stamp) 34 | { 35 | skb->stamp.tv_sec = stamp->tv_sec; 36 | skb->stamp.tv_usec = stamp->tv_usec; 37 | } 38 | #endif 39 | 40 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) 41 | static inline void setup_timer(struct timer_list * timer, 42 | void (*function)(unsigned long), 43 | unsigned long data) 44 | { 45 | timer->function = function; 46 | timer->data = data; 47 | init_timer(timer); 48 | } 49 | #endif 50 | 51 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) 52 | #define round_jiffies(j) (j) 53 | #endif 54 | 55 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 56 | #define dev_get_by_index(ns, ifindex) dev_get_by_index(ifindex) 57 | #define __dev_get_by_index(ns, ifindex) __dev_get_by_index(ifindex) 58 | #endif 59 | 60 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) 61 | #include 62 | static inline int hrtimer_callback_running(struct hrtimer *timer) 63 | { 64 | return timer->state & HRTIMER_STATE_CALLBACK; 65 | } 66 | #endif 67 | #endif 68 | -------------------------------------------------------------------------------- /net/can/make_isotp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo "CAN ISO-TP has moved to https://github.com/hartkopp/can-isotp.git" 3 | echo "This repository is not maintained anymore." 4 | echo "Are you sure you want to continue the build? (if so press ENTER)" 5 | read NONONEVER 6 | make CONFIG_CAN_ISOTP=m CONFIG_CAN=n CONFIG_CAN_RAW=n CONFIG_CAN_BCM=n CONFIG_CAN_GW=n $@ 7 | --------------------------------------------------------------------------------