sja1000.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. */
  44. #ifndef SJA1000_DEV_H
  45. #define SJA1000_DEV_H
  46. #include <linux/irqreturn.h>
  47. #include <linux/can/dev.h>
  48. #include <linux/can/platform/sja1000.h>
  49. #define SJA1000_ECHO_SKB_MAX 1 /* the SJA1000 has one TX buffer object */
  50. #define SJA1000_MAX_IRQ 20 /* max. number of interrupts handled in ISR */
  51. /* SJA1000 registers - manual section 6.4 (Pelican Mode) */
  52. #define SJA1000_MOD 0x00
  53. #define SJA1000_CMR 0x01
  54. #define SJA1000_SR 0x02
  55. #define SJA1000_IR 0x03
  56. #define SJA1000_IER 0x04
  57. #define SJA1000_ALC 0x0B
  58. #define SJA1000_ECC 0x0C
  59. #define SJA1000_EWL 0x0D
  60. #define SJA1000_RXERR 0x0E
  61. #define SJA1000_TXERR 0x0F
  62. #define SJA1000_ACCC0 0x10
  63. #define SJA1000_ACCC1 0x11
  64. #define SJA1000_ACCC2 0x12
  65. #define SJA1000_ACCC3 0x13
  66. #define SJA1000_ACCM0 0x14
  67. #define SJA1000_ACCM1 0x15
  68. #define SJA1000_ACCM2 0x16
  69. #define SJA1000_ACCM3 0x17
  70. #define SJA1000_RMC 0x1D
  71. #define SJA1000_RBSA 0x1E
  72. /* Common registers - manual section 6.5 */
  73. #define SJA1000_BTR0 0x06
  74. #define SJA1000_BTR1 0x07
  75. #define SJA1000_OCR 0x08
  76. #define SJA1000_CDR 0x1F
  77. #define SJA1000_FI 0x10
  78. #define SJA1000_SFF_BUF 0x13
  79. #define SJA1000_EFF_BUF 0x15
  80. #define SJA1000_FI_FF 0x80
  81. #define SJA1000_FI_RTR 0x40
  82. #define SJA1000_ID1 0x11
  83. #define SJA1000_ID2 0x12
  84. #define SJA1000_ID3 0x13
  85. #define SJA1000_ID4 0x14
  86. #define SJA1000_CAN_RAM 0x20
  87. /* mode register */
  88. #define MOD_RM 0x01
  89. #define MOD_LOM 0x02
  90. #define MOD_STM 0x04
  91. #define MOD_AFM 0x08
  92. #define MOD_SM 0x10
  93. /* commands */
  94. #define CMD_SRR 0x10
  95. #define CMD_CDO 0x08
  96. #define CMD_RRB 0x04
  97. #define CMD_AT 0x02
  98. #define CMD_TR 0x01
  99. /* interrupt sources */
  100. #define IRQ_BEI 0x80
  101. #define IRQ_ALI 0x40
  102. #define IRQ_EPI 0x20
  103. #define IRQ_WUI 0x10
  104. #define IRQ_DOI 0x08
  105. #define IRQ_EI 0x04
  106. #define IRQ_TI 0x02
  107. #define IRQ_RI 0x01
  108. #define IRQ_ALL 0xFF
  109. #define IRQ_OFF 0x00
  110. /* status register content */
  111. #define SR_BS 0x80
  112. #define SR_ES 0x40
  113. #define SR_TS 0x20
  114. #define SR_RS 0x10
  115. #define SR_TCS 0x08
  116. #define SR_TBS 0x04
  117. #define SR_DOS 0x02
  118. #define SR_RBS 0x01
  119. #define SR_CRIT (SR_BS|SR_ES)
  120. /* ECC register */
  121. #define ECC_SEG 0x1F
  122. #define ECC_DIR 0x20
  123. #define ECC_ERR 6
  124. #define ECC_BIT 0x00
  125. #define ECC_FORM 0x40
  126. #define ECC_STUFF 0x80
  127. #define ECC_MASK 0xc0
  128. /*
  129. * Flags for sja1000priv.flags
  130. */
  131. #define SJA1000_CUSTOM_IRQ_HANDLER 0x1
  132. /*
  133. * SJA1000 private data structure
  134. */
  135. struct sja1000_priv {
  136. struct can_priv can; /* must be the first member */
  137. struct sk_buff *echo_skb;
  138. /* the lower-layer is responsible for appropriate locking */
  139. u8 (*read_reg) (const struct sja1000_priv *priv, int reg);
  140. void (*write_reg) (const struct sja1000_priv *priv, int reg, u8 val);
  141. void (*pre_irq) (const struct sja1000_priv *priv);
  142. void (*post_irq) (const struct sja1000_priv *priv);
  143. void *priv; /* for board-specific data */
  144. struct net_device *dev;
  145. void __iomem *reg_base; /* ioremap'ed address to registers */
  146. unsigned long irq_flags; /* for request_irq() */
  147. spinlock_t cmdreg_lock; /* lock for concurrent cmd register writes */
  148. u16 flags; /* custom mode flags */
  149. u8 ocr; /* output control register */
  150. u8 cdr; /* clock divider register */
  151. };
  152. struct net_device *alloc_sja1000dev(int sizeof_priv);
  153. void free_sja1000dev(struct net_device *dev);
  154. int register_sja1000dev(struct net_device *dev);
  155. void unregister_sja1000dev(struct net_device *dev);
  156. irqreturn_t sja1000_interrupt(int irq, void *dev_id);
  157. #endif /* SJA1000_DEV_H */