xref: /netbsd-src/sys/arch/arm/sunxi/sunxi_can.h (revision 6bdb7968c2a5f6966f7e79d3f23c23c92bb797a1)
1 /*	$NetBSD: sunxi_can.h,v 1.1 2018/03/07 20:55:31 bouyer Exp $	*/
2 
3 /*-
4  * Copyright (c) 2017,2018 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Manuel Bouyer.
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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /* CAN mode select register */
33 #define SUNXI_CAN_MODSEL_REG		0x00
34 #define SUNXI_CAN_MODSEL_SLEEP		__BIT(4)
35 #define SUNXI_CAN_MODSEL_ACP_FLT_MOD	__BIT(3)
36 #define SUNXI_CAN_MODSEL_LB_MOD		__BIT(2)
37 #define SUNXI_CAN_MODSEL_LST_ONLY	__BIT(1)
38 #define SUNXI_CAN_MODSEL_RST		__BIT(0)
39 
40 /* CAN command register */
41 #define SUNXI_CAN_CMD_REG	0x04
42 #define SUNXI_CAN_CMD_BUS_OFF		__BIT(5)
43 #define SUNXI_CAN_CMD_SELF_REQ		__BIT(4)
44 #define SUNXI_CAN_CMD_CLR_OR		__BIT(3)
45 #define SUNXI_CAN_CMD_REL_RX_BUF		__BIT(2)
46 #define SUNXI_CAN_CMD_ABT_REQ		__BIT(1)
47 #define SUNXI_CAN_CMD_TANS_REQ		__BIT(0)
48 
49 /* CAN status register */
50 #define SUNXI_CAN_STA_REG	0x08
51 #define SUNXI_CAN_STA_ERR_CODE		__BITS(23,22)
52 #define SUNXI_CAN_STA_ERR_CODE_BIT		0
53 #define SUNXI_CAN_STA_ERR_CODE_FORM		1
54 #define SUNXI_CAN_STA_ERR_CODE_STUFF		2
55 #define SUNXI_CAN_STA_ERR_CODE_OTHER		3
56 #define SUNXI_CAN_STA_ERR_DIR		_BIT(21)
57 #define SUNXI_CAN_STA_ERR_SEG_CODE	__BITS(20,16)
58 #define SUNXI_CAN_STA_ARB_LOST		__BITS(12,8)
59 #define SUNXI_CAN_STA_BUS		__BIT(7)
60 #define SUNXI_CAN_STA_ERR		__BIT(6)
61 #define SUNXI_CAN_STA_TX 		__BIT(5)
62 #define SUNXI_CAN_STA_RX 		__BIT(4)
63 #define SUNXI_CAN_STA_TX_OVER		__BIT(3)
64 #define SUNXI_CAN_STA_TX_RDY		__BIT(2)
65 #define SUNXI_CAN_STA_DATA_OR		__BIT(1)
66 #define SUNXI_CAN_STA_RX_RDY		__BIT(0)
67 
68 /* CAN interrupt register */
69 #define SUNXI_CAN_INT_REG	0x0c
70 #define SUNXI_CAN_INT_BERR		__BIT(7)
71 #define SUNXI_CAN_INT_ARB_LOST		__BIT(6)
72 #define SUNXI_CAN_INT_ERR_PASSIVE	__BIT(5)
73 #define SUNXI_CAN_INT_WAKEUP		__BIT(4)
74 #define SUNXI_CAN_INT_DATA_OR		__BIT(3)
75 #define SUNXI_CAN_INT_ERR		__BIT(2)
76 #define SUNXI_CAN_INT_TX_FLAG		__BIT(1)
77 #define SUNXI_CAN_INT_RX_FLAG		__BIT(0)
78 
79 /* CAN interrupt enable register */
80 #define SUNXI_CAN_INTE_REG	0x10
81 
82 /* CAN bus timing register */
83 #define SUNXI_CAN_BUS_TIME_REG	0x14
84 #define SUNXI_CAN_BUS_TIME_SAM		__BIT(23)
85 #define SUNXI_CAN_BUS_TIME_PHSEG2	__BITS(22,20)
86 #define SUNXI_CAN_BUS_TIME_PHSEG1	__BITS(19,16)
87 #define SUNXI_CAN_BUS_TIME_SJW		__BITS(15,14)
88 #define SUNXI_CAN_BUS_TIME_TQ_BRP	__BITS(9,0)
89 
90 /* CAN tx error warning limit register */
91 #define SUNXI_CAN_EWL_REG	0x18
92 #define SUNXI_CAN_EWL_ERR_WRN_LMT	__BITS(7,0)
93 
94 /* CAN error counter register */
95 #define SUNXI_CAN_REC_REG	0x1c
96 #define SUNXI_CAN_REC_RX_ERR_CNT		__BITS(23,16)
97 #define SUNXI_CAN_REC_TX_ERR_CNT		__BITS(7,0)
98 
99 /* CAN receive message register */
100 #define SUNXI_CAN_RMSGC_REG	0x20
101 #define SUNXI_CAN_RMSGC_RX_MSG_CNT	__BITS(7,0)
102 
103 /* CAN receive buffer start address register */
104 #define SUNXI_CAN_RSADDR_REG	0x24
105 #define SUNXI_CAN_RSADDR_RX_BUF_SADDR	__BITS(5,0)
106 
107 /* CAN rx/tx message buffer 0 register */
108 #define SUNXI_CAN_TXBUF0_REG	0x40
109 #define SUNXI_CAN_TXBUF0_EFF		__BIT(7)
110 #define SUNXI_CAN_TXBUF0_RTR		__BIT(6)
111 #define SUNXI_CAN_TXBUF0_DL		__BITS(3,0)
112 
113 /* CAN rx/tx message buffer registers */
114 #define SUNXI_CAN_TXBUF1_REG	0x44
115 #define SUNXI_CAN_TXBUF2_REG	0x48
116 #define SUNXI_CAN_TXBUF3_REG	0x4c
117 #define SUNXI_CAN_TXBUF4_REG	0x50
118 #define SUNXI_CAN_TXBUF5_REG	0x54
119 #define SUNXI_CAN_TXBUF6_REG	0x58
120 #define SUNXI_CAN_TXBUF7_REG	0x5c
121 #define SUNXI_CAN_TXBUF8_REG	0x60
122 #define SUNXI_CAN_TXBUF9_REG	0x64
123 #define SUNXI_CAN_TXBUF10_REG	0x68
124 #define SUNXI_CAN_TXBUF11_REG	0x6c
125 #define SUNXI_CAN_TXBUF12_REG	0x70
126 
127 /* CAN acceptance code 0 register */
128 #define SUNXI_CAN_ACPC		0x40
129 
130 /* CAN acceptance mask 0 register */
131 #define SUNXI_CAN_ACPM		0x44
132 
133 /* CAN transmit buffer for read back registers */
134 #define SUNXI_CAN_RBUF_RBACK0	0x180
135 #define SUNXI_CAN_RBUF_RBACK1	0x184
136 #define SUNXI_CAN_RBUF_RBACK2	0x188
137 #define SUNXI_CAN_RBUF_RBACK3	0x18c
138 #define SUNXI_CAN_RBUF_RBACK4	0x190
139 #define SUNXI_CAN_RBUF_RBACK5	0x194
140 #define SUNXI_CAN_RBUF_RBACK6	0x198
141 #define SUNXI_CAN_RBUF_RBACK7	0x19c
142 #define SUNXI_CAN_RBUF_RBACK8	0x1a0
143 #define SUNXI_CAN_RBUF_RBACK9	0x1a4
144 #define SUNXI_CAN_RBUF_RBACK10	0x1a8
145 #define SUNXI_CAN_RBUF_RBACK11	0x1ac
146 #define SUNXI_CAN_RBUF_RBACK12	0x1b0
147