cc770.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Core driver for the CC770 and AN82527 CAN controllers
  4. *
  5. * Copyright (C) 2009, 2011 Wolfgang Grandegger <wg@grandegger.com>
  6. */
  7. #ifndef CC770_DEV_H
  8. #define CC770_DEV_H
  9. #include <linux/can/dev.h>
  10. struct cc770_msgobj {
  11. u8 ctrl0;
  12. u8 ctrl1;
  13. u8 id[4];
  14. u8 config;
  15. u8 data[8];
  16. u8 dontuse; /* padding */
  17. } __packed;
  18. struct cc770_regs {
  19. union {
  20. struct cc770_msgobj msgobj[16]; /* Message object 1..15 */
  21. struct {
  22. u8 control; /* Control Register */
  23. u8 status; /* Status Register */
  24. u8 cpu_interface; /* CPU Interface Register */
  25. u8 dontuse1;
  26. u8 high_speed_read[2]; /* High Speed Read */
  27. u8 global_mask_std[2]; /* Standard Global Mask */
  28. u8 global_mask_ext[4]; /* Extended Global Mask */
  29. u8 msg15_mask[4]; /* Message 15 Mask */
  30. u8 dontuse2[15];
  31. u8 clkout; /* Clock Out Register */
  32. u8 dontuse3[15];
  33. u8 bus_config; /* Bus Configuration Register */
  34. u8 dontuse4[15];
  35. u8 bit_timing_0; /* Bit Timing Register byte 0 */
  36. u8 dontuse5[15];
  37. u8 bit_timing_1; /* Bit Timing Register byte 1 */
  38. u8 dontuse6[15];
  39. u8 interrupt; /* Interrupt Register */
  40. u8 dontuse7[15];
  41. u8 rx_error_counter; /* Receive Error Counter */
  42. u8 dontuse8[15];
  43. u8 tx_error_counter; /* Transmit Error Counter */
  44. u8 dontuse9[31];
  45. u8 p1_conf;
  46. u8 dontuse10[15];
  47. u8 p2_conf;
  48. u8 dontuse11[15];
  49. u8 p1_in;
  50. u8 dontuse12[15];
  51. u8 p2_in;
  52. u8 dontuse13[15];
  53. u8 p1_out;
  54. u8 dontuse14[15];
  55. u8 p2_out;
  56. u8 dontuse15[15];
  57. u8 serial_reset_addr;
  58. };
  59. };
  60. } __packed;
  61. /* Control Register (0x00) */
  62. #define CTRL_INI 0x01 /* Initialization */
  63. #define CTRL_IE 0x02 /* Interrupt Enable */
  64. #define CTRL_SIE 0x04 /* Status Interrupt Enable */
  65. #define CTRL_EIE 0x08 /* Error Interrupt Enable */
  66. #define CTRL_EAF 0x20 /* Enable additional functions */
  67. #define CTRL_CCE 0x40 /* Change Configuration Enable */
  68. /* Status Register (0x01) */
  69. #define STAT_LEC_STUFF 0x01 /* Stuff error */
  70. #define STAT_LEC_FORM 0x02 /* Form error */
  71. #define STAT_LEC_ACK 0x03 /* Acknowledgement error */
  72. #define STAT_LEC_BIT1 0x04 /* Bit1 error */
  73. #define STAT_LEC_BIT0 0x05 /* Bit0 error */
  74. #define STAT_LEC_CRC 0x06 /* CRC error */
  75. #define STAT_LEC_MASK 0x07 /* Last Error Code mask */
  76. #define STAT_TXOK 0x08 /* Transmit Message Successfully */
  77. #define STAT_RXOK 0x10 /* Receive Message Successfully */
  78. #define STAT_WAKE 0x20 /* Wake Up Status */
  79. #define STAT_WARN 0x40 /* Warning Status */
  80. #define STAT_BOFF 0x80 /* Bus Off Status */
  81. /*
  82. * CPU Interface Register (0x02)
  83. * Clock Out Register (0x1f)
  84. * Bus Configuration Register (0x2f)
  85. *
  86. * see include/linux/can/platform/cc770.h
  87. */
  88. /* Message Control Register 0 (Base Address + 0x0) */
  89. #define INTPND_RES 0x01 /* No Interrupt pending */
  90. #define INTPND_SET 0x02 /* Interrupt pending */
  91. #define INTPND_UNC 0x03
  92. #define RXIE_RES 0x04 /* Receive Interrupt Disable */
  93. #define RXIE_SET 0x08 /* Receive Interrupt Enable */
  94. #define RXIE_UNC 0x0c
  95. #define TXIE_RES 0x10 /* Transmit Interrupt Disable */
  96. #define TXIE_SET 0x20 /* Transmit Interrupt Enable */
  97. #define TXIE_UNC 0x30
  98. #define MSGVAL_RES 0x40 /* Message Invalid */
  99. #define MSGVAL_SET 0x80 /* Message Valid */
  100. #define MSGVAL_UNC 0xc0
  101. /* Message Control Register 1 (Base Address + 0x01) */
  102. #define NEWDAT_RES 0x01 /* No New Data */
  103. #define NEWDAT_SET 0x02 /* New Data */
  104. #define NEWDAT_UNC 0x03
  105. #define MSGLST_RES 0x04 /* No Message Lost */
  106. #define MSGLST_SET 0x08 /* Message Lost */
  107. #define MSGLST_UNC 0x0c
  108. #define CPUUPD_RES 0x04 /* No CPU Updating */
  109. #define CPUUPD_SET 0x08 /* CPU Updating */
  110. #define CPUUPD_UNC 0x0c
  111. #define TXRQST_RES 0x10 /* No Transmission Request */
  112. #define TXRQST_SET 0x20 /* Transmission Request */
  113. #define TXRQST_UNC 0x30
  114. #define RMTPND_RES 0x40 /* No Remote Request Pending */
  115. #define RMTPND_SET 0x80 /* Remote Request Pending */
  116. #define RMTPND_UNC 0xc0
  117. /* Message Configuration Register (Base Address + 0x06) */
  118. #define MSGCFG_XTD 0x04 /* Extended Identifier */
  119. #define MSGCFG_DIR 0x08 /* Direction is Transmit */
  120. #define MSGOBJ_FIRST 1
  121. #define MSGOBJ_LAST 15
  122. #define CC770_IO_SIZE 0x100
  123. #define CC770_MAX_IRQ 20 /* max. number of interrupts handled in ISR */
  124. #define CC770_MAX_MSG 4 /* max. number of messages handled in ISR */
  125. #define CC770_ECHO_SKB_MAX 1
  126. #define cc770_read_reg(priv, member) \
  127. priv->read_reg(priv, offsetof(struct cc770_regs, member))
  128. #define cc770_write_reg(priv, member, value) \
  129. priv->write_reg(priv, offsetof(struct cc770_regs, member), value)
  130. /*
  131. * Message objects and flags used by this driver
  132. */
  133. #define CC770_OBJ_FLAG_RX 0x01
  134. #define CC770_OBJ_FLAG_RTR 0x02
  135. #define CC770_OBJ_FLAG_EFF 0x04
  136. enum {
  137. CC770_OBJ_RX0 = 0, /* for receiving normal messages */
  138. CC770_OBJ_RX1, /* for receiving normal messages */
  139. CC770_OBJ_RX_RTR0, /* for receiving remote transmission requests */
  140. CC770_OBJ_RX_RTR1, /* for receiving remote transmission requests */
  141. CC770_OBJ_TX, /* for sending messages */
  142. CC770_OBJ_MAX
  143. };
  144. #define obj2msgobj(o) (MSGOBJ_LAST - (o)) /* message object 11..15 */
  145. /*
  146. * CC770 private data structure
  147. */
  148. struct cc770_priv {
  149. struct can_priv can; /* must be the first member */
  150. struct sk_buff *echo_skb;
  151. /* the lower-layer is responsible for appropriate locking */
  152. u8 (*read_reg)(const struct cc770_priv *priv, int reg);
  153. void (*write_reg)(const struct cc770_priv *priv, int reg, u8 val);
  154. void (*pre_irq)(const struct cc770_priv *priv);
  155. void (*post_irq)(const struct cc770_priv *priv);
  156. void *priv; /* for board-specific data */
  157. struct net_device *dev;
  158. void __iomem *reg_base; /* ioremap'ed address to registers */
  159. unsigned long irq_flags; /* for request_irq() */
  160. unsigned char obj_flags[CC770_OBJ_MAX];
  161. u8 control_normal_mode; /* Control register for normal mode */
  162. u8 cpu_interface; /* CPU interface register */
  163. u8 clkout; /* Clock out register */
  164. u8 bus_config; /* Bus conffiguration register */
  165. struct sk_buff *tx_skb;
  166. };
  167. struct net_device *alloc_cc770dev(int sizeof_priv);
  168. void free_cc770dev(struct net_device *dev);
  169. int register_cc770dev(struct net_device *dev);
  170. void unregister_cc770dev(struct net_device *dev);
  171. #endif /* CC770_DEV_H */