softing.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * softing common interfaces
  3. *
  4. * by Kurt Van Dijck, 2008-2010
  5. */
  6. #include <linux/atomic.h>
  7. #include <linux/netdevice.h>
  8. #include <linux/ktime.h>
  9. #include <linux/mutex.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/can.h>
  12. #include <linux/can/dev.h>
  13. #include "softing_platform.h"
  14. struct softing;
  15. struct softing_priv {
  16. struct can_priv can; /* must be the first member! */
  17. struct net_device *netdev;
  18. struct softing *card;
  19. struct {
  20. int pending;
  21. /* variables which hold the circular buffer */
  22. int echo_put;
  23. int echo_get;
  24. } tx;
  25. struct can_bittiming_const btr_const;
  26. int index;
  27. uint8_t output;
  28. uint16_t chip;
  29. };
  30. #define netdev2softing(netdev) ((struct softing_priv *)netdev_priv(netdev))
  31. struct softing {
  32. const struct softing_platform_data *pdat;
  33. struct platform_device *pdev;
  34. struct net_device *net[2];
  35. spinlock_t spin; /* protect this structure & DPRAM access */
  36. ktime_t ts_ref;
  37. ktime_t ts_overflow; /* timestamp overflow value, in ktime */
  38. struct {
  39. /* indication of firmware status */
  40. int up;
  41. /* protection of the 'up' variable */
  42. struct mutex lock;
  43. } fw;
  44. struct {
  45. int nr;
  46. int requested;
  47. int svc_count;
  48. unsigned int dpram_position;
  49. } irq;
  50. struct {
  51. int pending;
  52. int last_bus;
  53. /*
  54. * keep the bus that last tx'd a message,
  55. * in order to let every netdev queue resume
  56. */
  57. } tx;
  58. __iomem uint8_t *dpram;
  59. unsigned long dpram_phys;
  60. unsigned long dpram_size;
  61. struct {
  62. uint16_t fw_version, hw_version, license, serial;
  63. uint16_t chip[2];
  64. unsigned int freq; /* remote cpu's operating frequency */
  65. } id;
  66. };
  67. int softing_default_output(struct net_device *netdev);
  68. ktime_t softing_raw2ktime(struct softing *card, u32 raw);
  69. int softing_chip_poweron(struct softing *card);
  70. int softing_bootloader_command(struct softing *card, int16_t cmd,
  71. const char *msg);
  72. /* Load firmware after reset */
  73. int softing_load_fw(const char *file, struct softing *card,
  74. __iomem uint8_t *virt, unsigned int size, int offset);
  75. /* Load final application firmware after bootloader */
  76. int softing_load_app_fw(const char *file, struct softing *card);
  77. /*
  78. * enable or disable irq
  79. * only called with fw.lock locked
  80. */
  81. int softing_enable_irq(struct softing *card, int enable);
  82. /* start/stop 1 bus on card */
  83. int softing_startstop(struct net_device *netdev, int up);
  84. /* netif_rx() */
  85. int softing_netdev_rx(struct net_device *netdev, const struct can_frame *msg,
  86. ktime_t ktime);
  87. /* SOFTING DPRAM mappings */
  88. #define DPRAM_RX 0x0000
  89. #define DPRAM_RX_SIZE 32
  90. #define DPRAM_RX_CNT 16
  91. #define DPRAM_RX_RD 0x0201 /* uint8_t */
  92. #define DPRAM_RX_WR 0x0205 /* uint8_t */
  93. #define DPRAM_RX_LOST 0x0207 /* uint8_t */
  94. #define DPRAM_FCT_PARAM 0x0300 /* int16_t [20] */
  95. #define DPRAM_FCT_RESULT 0x0328 /* int16_t */
  96. #define DPRAM_FCT_HOST 0x032b /* uint16_t */
  97. #define DPRAM_INFO_BUSSTATE 0x0331 /* uint16_t */
  98. #define DPRAM_INFO_BUSSTATE2 0x0335 /* uint16_t */
  99. #define DPRAM_INFO_ERRSTATE 0x0339 /* uint16_t */
  100. #define DPRAM_INFO_ERRSTATE2 0x033d /* uint16_t */
  101. #define DPRAM_RESET 0x0341 /* uint16_t */
  102. #define DPRAM_CLR_RECV_FIFO 0x0345 /* uint16_t */
  103. #define DPRAM_RESET_TIME 0x034d /* uint16_t */
  104. #define DPRAM_TIME 0x0350 /* uint64_t */
  105. #define DPRAM_WR_START 0x0358 /* uint8_t */
  106. #define DPRAM_WR_END 0x0359 /* uint8_t */
  107. #define DPRAM_RESET_RX_FIFO 0x0361 /* uint16_t */
  108. #define DPRAM_RESET_TX_FIFO 0x0364 /* uint8_t */
  109. #define DPRAM_READ_FIFO_LEVEL 0x0365 /* uint8_t */
  110. #define DPRAM_RX_FIFO_LEVEL 0x0366 /* uint16_t */
  111. #define DPRAM_TX_FIFO_LEVEL 0x0366 /* uint16_t */
  112. #define DPRAM_TX 0x0400 /* uint16_t */
  113. #define DPRAM_TX_SIZE 16
  114. #define DPRAM_TX_CNT 32
  115. #define DPRAM_TX_RD 0x0601 /* uint8_t */
  116. #define DPRAM_TX_WR 0x0605 /* uint8_t */
  117. #define DPRAM_COMMAND 0x07e0 /* uint16_t */
  118. #define DPRAM_RECEIPT 0x07f0 /* uint16_t */
  119. #define DPRAM_IRQ_TOHOST 0x07fe /* uint8_t */
  120. #define DPRAM_IRQ_TOCARD 0x07ff /* uint8_t */
  121. #define DPRAM_V2_RESET 0x0e00 /* uint8_t */
  122. #define DPRAM_V2_IRQ_TOHOST 0x0e02 /* uint8_t */
  123. #define TXMAX (DPRAM_TX_CNT - 1)
  124. /* DPRAM return codes */
  125. #define RES_NONE 0
  126. #define RES_OK 1
  127. #define RES_NOK 2
  128. #define RES_UNKNOWN 3
  129. /* DPRAM flags */
  130. #define CMD_TX 0x01
  131. #define CMD_ACK 0x02
  132. #define CMD_XTD 0x04
  133. #define CMD_RTR 0x08
  134. #define CMD_ERR 0x10
  135. #define CMD_BUS2 0x80
  136. /* returned fifo entry bus state masks */
  137. #define SF_MASK_BUSOFF 0x80
  138. #define SF_MASK_EPASSIVE 0x60
  139. /* bus states */
  140. #define STATE_BUSOFF 2
  141. #define STATE_EPASSIVE 1
  142. #define STATE_EACTIVE 0