mscan.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * Definitions of consts/structs to drive the Freescale MSCAN.
  3. *
  4. * Copyright (C) 2005-2006 Andrey Volkov <avolkov@varma-el.com>,
  5. * Varma Electronics Oy
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the version 2 of the GNU General Public License
  9. * as published by the Free Software Foundation
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __MSCAN_H__
  20. #define __MSCAN_H__
  21. #include <linux/clk.h>
  22. #include <linux/types.h>
  23. /* MSCAN control register 0 (CANCTL0) bits */
  24. #define MSCAN_RXFRM 0x80
  25. #define MSCAN_RXACT 0x40
  26. #define MSCAN_CSWAI 0x20
  27. #define MSCAN_SYNCH 0x10
  28. #define MSCAN_TIME 0x08
  29. #define MSCAN_WUPE 0x04
  30. #define MSCAN_SLPRQ 0x02
  31. #define MSCAN_INITRQ 0x01
  32. /* MSCAN control register 1 (CANCTL1) bits */
  33. #define MSCAN_CANE 0x80
  34. #define MSCAN_CLKSRC 0x40
  35. #define MSCAN_LOOPB 0x20
  36. #define MSCAN_LISTEN 0x10
  37. #define MSCAN_BORM 0x08
  38. #define MSCAN_WUPM 0x04
  39. #define MSCAN_SLPAK 0x02
  40. #define MSCAN_INITAK 0x01
  41. /* Use the MPC5XXX MSCAN variant? */
  42. #ifdef CONFIG_PPC
  43. #define MSCAN_FOR_MPC5XXX
  44. #endif
  45. #ifdef MSCAN_FOR_MPC5XXX
  46. #define MSCAN_CLKSRC_BUS 0
  47. #define MSCAN_CLKSRC_XTAL MSCAN_CLKSRC
  48. #define MSCAN_CLKSRC_IPS MSCAN_CLKSRC
  49. #else
  50. #define MSCAN_CLKSRC_BUS MSCAN_CLKSRC
  51. #define MSCAN_CLKSRC_XTAL 0
  52. #endif
  53. /* MSCAN receiver flag register (CANRFLG) bits */
  54. #define MSCAN_WUPIF 0x80
  55. #define MSCAN_CSCIF 0x40
  56. #define MSCAN_RSTAT1 0x20
  57. #define MSCAN_RSTAT0 0x10
  58. #define MSCAN_TSTAT1 0x08
  59. #define MSCAN_TSTAT0 0x04
  60. #define MSCAN_OVRIF 0x02
  61. #define MSCAN_RXF 0x01
  62. #define MSCAN_ERR_IF (MSCAN_OVRIF | MSCAN_CSCIF)
  63. #define MSCAN_RSTAT_MSK (MSCAN_RSTAT1 | MSCAN_RSTAT0)
  64. #define MSCAN_TSTAT_MSK (MSCAN_TSTAT1 | MSCAN_TSTAT0)
  65. #define MSCAN_STAT_MSK (MSCAN_RSTAT_MSK | MSCAN_TSTAT_MSK)
  66. #define MSCAN_STATE_BUS_OFF (MSCAN_RSTAT1 | MSCAN_RSTAT0 | \
  67. MSCAN_TSTAT1 | MSCAN_TSTAT0)
  68. #define MSCAN_STATE_TX(canrflg) (((canrflg)&MSCAN_TSTAT_MSK)>>2)
  69. #define MSCAN_STATE_RX(canrflg) (((canrflg)&MSCAN_RSTAT_MSK)>>4)
  70. #define MSCAN_STATE_ACTIVE 0
  71. #define MSCAN_STATE_WARNING 1
  72. #define MSCAN_STATE_PASSIVE 2
  73. #define MSCAN_STATE_BUSOFF 3
  74. /* MSCAN receiver interrupt enable register (CANRIER) bits */
  75. #define MSCAN_WUPIE 0x80
  76. #define MSCAN_CSCIE 0x40
  77. #define MSCAN_RSTATE1 0x20
  78. #define MSCAN_RSTATE0 0x10
  79. #define MSCAN_TSTATE1 0x08
  80. #define MSCAN_TSTATE0 0x04
  81. #define MSCAN_OVRIE 0x02
  82. #define MSCAN_RXFIE 0x01
  83. /* MSCAN transmitter flag register (CANTFLG) bits */
  84. #define MSCAN_TXE2 0x04
  85. #define MSCAN_TXE1 0x02
  86. #define MSCAN_TXE0 0x01
  87. #define MSCAN_TXE (MSCAN_TXE2 | MSCAN_TXE1 | MSCAN_TXE0)
  88. /* MSCAN transmitter interrupt enable register (CANTIER) bits */
  89. #define MSCAN_TXIE2 0x04
  90. #define MSCAN_TXIE1 0x02
  91. #define MSCAN_TXIE0 0x01
  92. #define MSCAN_TXIE (MSCAN_TXIE2 | MSCAN_TXIE1 | MSCAN_TXIE0)
  93. /* MSCAN transmitter message abort request (CANTARQ) bits */
  94. #define MSCAN_ABTRQ2 0x04
  95. #define MSCAN_ABTRQ1 0x02
  96. #define MSCAN_ABTRQ0 0x01
  97. /* MSCAN transmitter message abort ack (CANTAAK) bits */
  98. #define MSCAN_ABTAK2 0x04
  99. #define MSCAN_ABTAK1 0x02
  100. #define MSCAN_ABTAK0 0x01
  101. /* MSCAN transmit buffer selection (CANTBSEL) bits */
  102. #define MSCAN_TX2 0x04
  103. #define MSCAN_TX1 0x02
  104. #define MSCAN_TX0 0x01
  105. /* MSCAN ID acceptance control register (CANIDAC) bits */
  106. #define MSCAN_IDAM1 0x20
  107. #define MSCAN_IDAM0 0x10
  108. #define MSCAN_IDHIT2 0x04
  109. #define MSCAN_IDHIT1 0x02
  110. #define MSCAN_IDHIT0 0x01
  111. #define MSCAN_AF_32BIT 0x00
  112. #define MSCAN_AF_16BIT MSCAN_IDAM0
  113. #define MSCAN_AF_8BIT MSCAN_IDAM1
  114. #define MSCAN_AF_CLOSED (MSCAN_IDAM0|MSCAN_IDAM1)
  115. #define MSCAN_AF_MASK (~(MSCAN_IDAM0|MSCAN_IDAM1))
  116. /* MSCAN Miscellaneous Register (CANMISC) bits */
  117. #define MSCAN_BOHOLD 0x01
  118. /* MSCAN Identifier Register (IDR) bits */
  119. #define MSCAN_SFF_RTR_SHIFT 4
  120. #define MSCAN_EFF_RTR_SHIFT 0
  121. #define MSCAN_EFF_FLAGS 0x18 /* IDE + SRR */
  122. #ifdef MSCAN_FOR_MPC5XXX
  123. #define _MSCAN_RESERVED_(n, num) u8 _res##n[num]
  124. #define _MSCAN_RESERVED_DSR_SIZE 2
  125. #else
  126. #define _MSCAN_RESERVED_(n, num)
  127. #define _MSCAN_RESERVED_DSR_SIZE 0
  128. #endif
  129. /* Structure of the hardware registers */
  130. struct mscan_regs {
  131. /* (see doc S12MSCANV3/D) MPC5200 MSCAN */
  132. u8 canctl0; /* + 0x00 0x00 */
  133. u8 canctl1; /* + 0x01 0x01 */
  134. _MSCAN_RESERVED_(1, 2); /* + 0x02 */
  135. u8 canbtr0; /* + 0x04 0x02 */
  136. u8 canbtr1; /* + 0x05 0x03 */
  137. _MSCAN_RESERVED_(2, 2); /* + 0x06 */
  138. u8 canrflg; /* + 0x08 0x04 */
  139. u8 canrier; /* + 0x09 0x05 */
  140. _MSCAN_RESERVED_(3, 2); /* + 0x0a */
  141. u8 cantflg; /* + 0x0c 0x06 */
  142. u8 cantier; /* + 0x0d 0x07 */
  143. _MSCAN_RESERVED_(4, 2); /* + 0x0e */
  144. u8 cantarq; /* + 0x10 0x08 */
  145. u8 cantaak; /* + 0x11 0x09 */
  146. _MSCAN_RESERVED_(5, 2); /* + 0x12 */
  147. u8 cantbsel; /* + 0x14 0x0a */
  148. u8 canidac; /* + 0x15 0x0b */
  149. u8 reserved; /* + 0x16 0x0c */
  150. _MSCAN_RESERVED_(6, 2); /* + 0x17 */
  151. u8 canmisc; /* + 0x19 0x0d */
  152. _MSCAN_RESERVED_(7, 2); /* + 0x1a */
  153. u8 canrxerr; /* + 0x1c 0x0e */
  154. u8 cantxerr; /* + 0x1d 0x0f */
  155. _MSCAN_RESERVED_(8, 2); /* + 0x1e */
  156. u16 canidar1_0; /* + 0x20 0x10 */
  157. _MSCAN_RESERVED_(9, 2); /* + 0x22 */
  158. u16 canidar3_2; /* + 0x24 0x12 */
  159. _MSCAN_RESERVED_(10, 2); /* + 0x26 */
  160. u16 canidmr1_0; /* + 0x28 0x14 */
  161. _MSCAN_RESERVED_(11, 2); /* + 0x2a */
  162. u16 canidmr3_2; /* + 0x2c 0x16 */
  163. _MSCAN_RESERVED_(12, 2); /* + 0x2e */
  164. u16 canidar5_4; /* + 0x30 0x18 */
  165. _MSCAN_RESERVED_(13, 2); /* + 0x32 */
  166. u16 canidar7_6; /* + 0x34 0x1a */
  167. _MSCAN_RESERVED_(14, 2); /* + 0x36 */
  168. u16 canidmr5_4; /* + 0x38 0x1c */
  169. _MSCAN_RESERVED_(15, 2); /* + 0x3a */
  170. u16 canidmr7_6; /* + 0x3c 0x1e */
  171. _MSCAN_RESERVED_(16, 2); /* + 0x3e */
  172. struct {
  173. u16 idr1_0; /* + 0x40 0x20 */
  174. _MSCAN_RESERVED_(17, 2); /* + 0x42 */
  175. u16 idr3_2; /* + 0x44 0x22 */
  176. _MSCAN_RESERVED_(18, 2); /* + 0x46 */
  177. u16 dsr1_0; /* + 0x48 0x24 */
  178. _MSCAN_RESERVED_(19, 2); /* + 0x4a */
  179. u16 dsr3_2; /* + 0x4c 0x26 */
  180. _MSCAN_RESERVED_(20, 2); /* + 0x4e */
  181. u16 dsr5_4; /* + 0x50 0x28 */
  182. _MSCAN_RESERVED_(21, 2); /* + 0x52 */
  183. u16 dsr7_6; /* + 0x54 0x2a */
  184. _MSCAN_RESERVED_(22, 2); /* + 0x56 */
  185. u8 dlr; /* + 0x58 0x2c */
  186. u8 reserved; /* + 0x59 0x2d */
  187. _MSCAN_RESERVED_(23, 2); /* + 0x5a */
  188. u16 time; /* + 0x5c 0x2e */
  189. } rx;
  190. _MSCAN_RESERVED_(24, 2); /* + 0x5e */
  191. struct {
  192. u16 idr1_0; /* + 0x60 0x30 */
  193. _MSCAN_RESERVED_(25, 2); /* + 0x62 */
  194. u16 idr3_2; /* + 0x64 0x32 */
  195. _MSCAN_RESERVED_(26, 2); /* + 0x66 */
  196. u16 dsr1_0; /* + 0x68 0x34 */
  197. _MSCAN_RESERVED_(27, 2); /* + 0x6a */
  198. u16 dsr3_2; /* + 0x6c 0x36 */
  199. _MSCAN_RESERVED_(28, 2); /* + 0x6e */
  200. u16 dsr5_4; /* + 0x70 0x38 */
  201. _MSCAN_RESERVED_(29, 2); /* + 0x72 */
  202. u16 dsr7_6; /* + 0x74 0x3a */
  203. _MSCAN_RESERVED_(30, 2); /* + 0x76 */
  204. u8 dlr; /* + 0x78 0x3c */
  205. u8 tbpr; /* + 0x79 0x3d */
  206. _MSCAN_RESERVED_(31, 2); /* + 0x7a */
  207. u16 time; /* + 0x7c 0x3e */
  208. } tx;
  209. _MSCAN_RESERVED_(32, 2); /* + 0x7e */
  210. } __packed;
  211. #undef _MSCAN_RESERVED_
  212. #define MSCAN_REGION sizeof(struct mscan)
  213. #define MSCAN_NORMAL_MODE 0
  214. #define MSCAN_SLEEP_MODE MSCAN_SLPRQ
  215. #define MSCAN_INIT_MODE (MSCAN_INITRQ | MSCAN_SLPRQ)
  216. #define MSCAN_POWEROFF_MODE (MSCAN_CSWAI | MSCAN_SLPRQ)
  217. #define MSCAN_SET_MODE_RETRIES 255
  218. #define MSCAN_ECHO_SKB_MAX 3
  219. #define MSCAN_RX_INTS_ENABLE (MSCAN_OVRIE | MSCAN_RXFIE | MSCAN_CSCIE | \
  220. MSCAN_RSTATE1 | MSCAN_RSTATE0 | \
  221. MSCAN_TSTATE1 | MSCAN_TSTATE0)
  222. /* MSCAN type variants */
  223. enum {
  224. MSCAN_TYPE_MPC5200,
  225. MSCAN_TYPE_MPC5121
  226. };
  227. #define BTR0_BRP_MASK 0x3f
  228. #define BTR0_SJW_SHIFT 6
  229. #define BTR0_SJW_MASK (0x3 << BTR0_SJW_SHIFT)
  230. #define BTR1_TSEG1_MASK 0xf
  231. #define BTR1_TSEG2_SHIFT 4
  232. #define BTR1_TSEG2_MASK (0x7 << BTR1_TSEG2_SHIFT)
  233. #define BTR1_SAM_SHIFT 7
  234. #define BTR0_SET_BRP(brp) (((brp) - 1) & BTR0_BRP_MASK)
  235. #define BTR0_SET_SJW(sjw) ((((sjw) - 1) << BTR0_SJW_SHIFT) & \
  236. BTR0_SJW_MASK)
  237. #define BTR1_SET_TSEG1(tseg1) (((tseg1) - 1) & BTR1_TSEG1_MASK)
  238. #define BTR1_SET_TSEG2(tseg2) ((((tseg2) - 1) << BTR1_TSEG2_SHIFT) & \
  239. BTR1_TSEG2_MASK)
  240. #define BTR1_SET_SAM(sam) ((sam) ? 1 << BTR1_SAM_SHIFT : 0)
  241. #define F_RX_PROGRESS 0
  242. #define F_TX_PROGRESS 1
  243. #define F_TX_WAIT_ALL 2
  244. #define TX_QUEUE_SIZE 3
  245. struct tx_queue_entry {
  246. struct list_head list;
  247. u8 mask;
  248. u8 id;
  249. };
  250. struct mscan_priv {
  251. struct can_priv can; /* must be the first member */
  252. unsigned int type; /* MSCAN type variants */
  253. unsigned long flags;
  254. void __iomem *reg_base; /* ioremap'ed address to registers */
  255. struct clk *clk_ipg; /* clock for registers */
  256. struct clk *clk_can; /* clock for bitrates */
  257. u8 shadow_statflg;
  258. u8 shadow_canrier;
  259. u8 cur_pri;
  260. u8 prev_buf_id;
  261. u8 tx_active;
  262. struct list_head tx_head;
  263. struct tx_queue_entry tx_queue[TX_QUEUE_SIZE];
  264. struct napi_struct napi;
  265. };
  266. struct net_device *alloc_mscandev(void);
  267. int register_mscandev(struct net_device *dev, int mscan_clksrc);
  268. void unregister_mscandev(struct net_device *dev);
  269. #endif /* __MSCAN_H__ */