mtk_qmu.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #ifndef _MTK_QMU_H_
  2. #define _MTK_QMU_H_
  3. #ifdef MUSB_QMU_SUPPORT
  4. /* for musb_read/write api */
  5. #include "mtk_musb.h"
  6. #include "musb_debug.h"
  7. #include "musb_io.h"
  8. #include <linux/dmapool.h>
  9. /* CUSTOM SETTING */
  10. #define GPD_LEN_ALIGNED (64) /* > gpd len (16) and cache line size aligned */
  11. #define GPD_EXT_LEN (48) /* GPD_LEN_ALIGNED - 16(should be sizeof(TGPD) */
  12. #define GPD_SZ (16)
  13. #define MAX_GPD_NUM 36
  14. #define RXQ_NUM 8
  15. #define TXQ_NUM 8
  16. #define MAX_QMU_EP RXQ_NUM
  17. #define TXQ 0
  18. #define RXQ 1
  19. /* QMU SETTING */
  20. #define NO_ZLP 0
  21. #define HW_MODE 1
  22. #define GPD_MODE 2
  23. /* #define TXZLP GPD_MODE */
  24. /* #define TXZLP HW_MODE */
  25. #define TXZLP NO_ZLP
  26. /* #define CFG_RX_ZLP_EN */
  27. /* #define CFG_RX_COZ_EN */
  28. #define CFG_CS_CHECK
  29. /* #define CFG_EMPTY_CHECK */
  30. /* TGPD */
  31. typedef struct _TGPD {
  32. u8 flag;
  33. u8 chksum;
  34. u16 DataBufferLen; /*Rx Allow Length */
  35. /* address field, 32-bit long */
  36. u32 pNext;
  37. u32 pBuf;
  38. u16 bufLen;
  39. u8 ExtLength;
  40. u8 ZTepFlag;
  41. } TGPD, *PGPD;
  42. typedef struct _GPD_RANGE {
  43. PGPD pNext;
  44. PGPD pStart;
  45. PGPD pEnd;
  46. } GPD_R, *RGPD;
  47. extern int mtk_qmu_dbg_level; /* refer to musb_core.c */
  48. static inline int mtk_dbg_level(unsigned level)
  49. {
  50. return mtk_qmu_dbg_level >= level;
  51. }
  52. #define LOG_EMERG 0
  53. #define LOG_ALERT 1
  54. #define LOG_CRIT 2
  55. #define LOG_ERR 3
  56. #define LOG_WARN 4
  57. #define LOG_NOTICE 5
  58. #define LOG_INFO 6
  59. #define LOG_DBG 7
  60. #define QMU_DBG_ON
  61. #ifdef QMU_DBG_ON
  62. #define QMU_ERR(format, args...) do {if (mtk_dbg_level(LOG_ERR)) \
  63. pr_warn("QMU_ERR,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  64. while (0)
  65. #define QMU_WARN(format, args...) do {if (mtk_dbg_level(LOG_WARN)) \
  66. pr_warn("QMU_WARN,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  67. while (0)
  68. #define QMU_INFO(format, args...) do {if (mtk_dbg_level(LOG_INFO)) \
  69. pr_warn("QMU_INFO,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  70. while (0)
  71. #define QMU_DBG(format, args...) do {if (mtk_dbg_level(LOG_DBG)) \
  72. pr_warn("QMU_DBG,<%s %d>, " format , __func__, __LINE__ , ## args); } \
  73. while (0)
  74. #else
  75. #define QMU_ERR(format, args...) do {} while (0)
  76. #define QMU_WARN(format, args...) do {} while (0)
  77. #define QMU_INFO(format, args...) do {} while (0)
  78. #define QMU_DBG(format, args...) do {} while (0)
  79. #endif
  80. /* QMU macros */
  81. #define USB_HW_QMU_OFF 0x0000
  82. #define USB_HW_QUCS_OFF 0x0300
  83. #define USB_HW_QIRQ_OFF 0x0400
  84. #define USB_HW_QDBG_OFF 0x04F0
  85. #define MGC_O_QMU_QCR0 0x0000
  86. #define MGC_O_QMU_QCR2 0x0008
  87. #define MGC_O_QMU_QCR3 0x000C
  88. #define MGC_O_QMU_RQCSR0 0x0010
  89. #define MGC_O_QMU_RQSAR0 0x0014
  90. #define MGC_O_QMU_RQCPR0 0x0018
  91. #define MGC_O_QMU_RQCSR(n) (MGC_O_QMU_RQCSR0+0x0010*((n)-1))
  92. #define MGC_O_QMU_RQSAR(n) (MGC_O_QMU_RQSAR0+0x0010*((n)-1))
  93. #define MGC_O_QMU_RQCPR(n) (MGC_O_QMU_RQCPR0+0x0010*((n)-1))
  94. #define MGC_O_QMU_RQTR_BASE 0x0090
  95. #define MGC_O_QMU_RQTR(n) (MGC_O_QMU_RQTR_BASE+0x4*((n)-1))
  96. #define MGC_O_QMU_RQLDPR0 0x0100
  97. #define MGC_O_QMU_RQLDPR(n) (MGC_O_QMU_RQLDPR0+0x4*((n)-1))
  98. #define MGC_O_QMU_TQCSR0 0x0200
  99. #define MGC_O_QMU_TQSAR0 0x0204
  100. #define MGC_O_QMU_TQCPR0 0x0208
  101. #define MGC_O_QMU_TQCSR(n) (MGC_O_QMU_TQCSR0+0x0010*((n)-1))
  102. #define MGC_O_QMU_TQSAR(n) (MGC_O_QMU_TQSAR0+0x0010*((n)-1))
  103. #define MGC_O_QMU_TQCPR(n) (MGC_O_QMU_TQCPR0+0x0010*((n)-1))
  104. #define MGC_O_QMU_QAR 0x0300
  105. #define MGC_O_QUCS_USBGCSR 0x0000
  106. #define MGC_O_QIRQ_QISAR 0x0000
  107. #define MGC_O_QIRQ_QIMR 0x0004
  108. #define MGC_O_QIRQ_QIMCR 0x0008
  109. #define MGC_O_QIRQ_QIMSR 0x000C
  110. #define MGC_O_QIRQ_IOCDISR 0x0030
  111. #define MGC_O_QIRQ_TEPEMPR 0x0060
  112. #define MGC_O_QIRQ_TEPEMPMR 0x0064
  113. #define MGC_O_QIRQ_TEPEMPMCR 0x0068
  114. #define MGC_O_QIRQ_TEPEMPMSR 0x006C
  115. #define MGC_O_QIRQ_REPEMPR 0x0070
  116. #define MGC_O_QIRQ_REPEMPMR 0x0074
  117. #define MGC_O_QIRQ_REPEMPMCR 0x0078
  118. #define MGC_O_QIRQ_REPEMPMSR 0x007C
  119. #define MGC_O_QIRQ_RQEIR 0x0090
  120. #define MGC_O_QIRQ_RQEIMR 0x0094
  121. #define MGC_O_QIRQ_RQEIMCR 0x0098
  122. #define MGC_O_QIRQ_RQEIMSR 0x009C
  123. #define MGC_O_QIRQ_REPEIR 0x00A0
  124. #define MGC_O_QIRQ_REPEIMR 0x00A4
  125. #define MGC_O_QIRQ_REPEIMCR 0x00A8
  126. #define MGC_O_QIRQ_REPEIMSR 0x00AC
  127. #define MGC_O_QIRQ_TQEIR 0x00B0
  128. #define MGC_O_QIRQ_TQEIMR 0x00B4
  129. #define MGC_O_QIRQ_TQEIMCR 0x00B8
  130. #define MGC_O_QIRQ_TQEIMSR 0x00BC
  131. #define MGC_O_QIRQ_TEPEIR 0x00C0
  132. #define MGC_O_QIRQ_TEPEIMR 0x00C4
  133. #define MGC_O_QIRQ_TEPEIMCR 0x00C8
  134. #define MGC_O_QIRQ_TEPEIMSR 0x00CC
  135. #define MGC_O_QDBG_DFCR 0x0000
  136. #define MGC_O_QDBG_DFMR 0x0004
  137. /* brief Queue Control value Definition */
  138. #define DQMU_QUE_START 0x00000001
  139. #define DQMU_QUE_RESUME 0x00000002
  140. #define DQMU_QUE_STOP 0x00000004
  141. #define DQMU_QUE_ACTIVE 0x00008000
  142. /*brief USB QMU Special Control USBGCSR value Definition*/
  143. #define USB_QMU_Tx0_EN 0x00000001
  144. #define USB_QMU_Tx_EN(n) (USB_QMU_Tx0_EN<<((n)-1))
  145. #define USB_QMU_Rx0_EN 0x00010000
  146. #define USB_QMU_Rx_EN(n) (USB_QMU_Rx0_EN<<((n)-1))
  147. #define USB_QMU_HIFEVT_EN 0x00000100
  148. #define USB_QMU_HIFCMD_EN 0x01000000
  149. #define DQMU_SW_RESET 0x00010000
  150. #define DQMU_CS16B_EN 0x80000000
  151. #define DQMU_TQ0CS_EN 0x00010000
  152. #define DQMU_TQCS_EN(n) (DQMU_TQ0CS_EN<<((n)-1))
  153. #define DQMU_RQ0CS_EN 0x00000001
  154. #define DQMU_RQCS_EN(n) (DQMU_RQ0CS_EN<<((n)-1))
  155. #define DQMU_TX0_ZLP 0x01000000
  156. #define DQMU_TX_ZLP(n) (DQMU_TX0_ZLP<<((n)-1))
  157. #define DQMU_TX0_MULTIPLE 0x00010000
  158. #define DQMU_TX_MULTIPLE(n) (DQMU_TX0_MULTIPLE<<((n)-1))
  159. #define DQMU_RX0_MULTIPLE 0x00010000
  160. #define DQMU_RX_MULTIPLE(n) (DQMU_RX0_MULTIPLE<<((n)-1))
  161. #define DQMU_RX0_ZLP 0x01000000
  162. #define DQMU_RX_ZLP(n) (DQMU_RX0_ZLP<<((n)-1))
  163. #define DQMU_RX0_COZ 0x00000100
  164. #define DQMU_RX_COZ(n) (DQMU_RX0_COZ<<((n)-1))
  165. #define DQMU_M_TXEP_ERR 0x10000000
  166. #define DQMU_M_TXQ_ERR 0x08000000
  167. #define DQMU_M_RXEP_ERR 0x04000000
  168. #define DQMU_M_RXQ_ERR 0x02000000
  169. #define DQMU_M_RQ_EMPTY 0x00020000
  170. #define DQMU_M_TQ_EMPTY 0x00010000
  171. #define DQMU_M_RX0_EMPTY 0x00000001
  172. #define DQMU_M_RX_EMPTY(n) (DQMU_M_RX0_EMPTY<<((n)-1))
  173. #define DQMU_M_TX0_EMPTY 0x00000001
  174. #define DQMU_M_TX_EMPTY(n) (DQMU_M_TX0_EMPTY<<((n)-1))
  175. #define DQMU_M_RX0_DONE 0x00000100
  176. #define DQMU_M_RX_DONE(n) (DQMU_M_RX0_DONE<<((n)-1))
  177. #define DQMU_M_TX0_DONE 0x00000001
  178. #define DQMU_M_TX_DONE(n) (DQMU_M_TX0_DONE<<((n)-1))
  179. #define DQMU_M_RX0_ZLP_ERR 0x01000000
  180. #define DQMU_M_RX_ZLP_ERR(n) (DQMU_M_RX0_ZLP_ERR<<((n)-1))
  181. #define DQMU_M_RX0_LEN_ERR 0x00000100
  182. #define DQMU_M_RX_LEN_ERR(n) (DQMU_M_RX0_LEN_ERR<<((n)-1))
  183. #define DQMU_M_RX0_GPDCS_ERR 0x00000001
  184. #define DQMU_M_RX_GPDCS_ERR(n) (DQMU_M_RX0_GPDCS_ERR<<((n)-1))
  185. #define DQMU_M_TX0_LEN_ERR 0x00010000
  186. #define DQMU_M_TX_LEN_ERR(n) (DQMU_M_TX0_LEN_ERR<<((n)-1))
  187. #define DQMU_M_TX0_GPDCS_ERR 0x00000100
  188. #define DQMU_M_TX_GPDCS_ERR(n) (DQMU_M_TX0_GPDCS_ERR<<((n)-1))
  189. #define DQMU_M_TX0_BDCS_ERR 0x00000001
  190. #define DQMU_M_TX_BDCS_ERR(n) (DQMU_M_TX0_BDCS_ERR<<((n)-1))
  191. #define DQMU_M_TX0_EP_ERR 0x00000001
  192. #define DQMU_M_TX_EP_ERR(n) (DQMU_M_TX0_EP_ERR<<((n)-1))
  193. #define DQMU_M_RX0_EP_ERR 0x00000001
  194. #define DQMU_M_RX_EP_ERR(n) (DQMU_M_RX0_EP_ERR<<((n)-1))
  195. #define DQMU_M_RQ_DIS_IOC(n) (0x100<<((n)-1))
  196. #define MGC_ReadQMU8(base, _offset) \
  197. musb_readb(base, (USB_HW_QMU_OFF + _offset))
  198. #define MGC_ReadQUCS8(base, _offset) \
  199. musb_readb(base, (USB_HW_QUCS_OFF + _offset))
  200. #define MGC_ReadQIRQ8(base, _offset) \
  201. musb_readb(base, (USB_HW_QIRQ_OFF + _offset))
  202. #define MGC_ReadQMU16(base, _offset) \
  203. musb_readw(base, (USB_HW_QMU_OFF + _offset))
  204. #define MGC_ReadQUCS16(base, _offset) \
  205. musb_readw(base, (USB_HW_QUCS_OFF + _offset))
  206. #define MGC_ReadQIRQ16(base, _offset) \
  207. musb_readw(base, (USB_HW_QIRQ_OFF + _offset))
  208. #define MGC_ReadQMU32(base, _offset) \
  209. musb_readl(base, (USB_HW_QMU_OFF + _offset))
  210. #define MGC_ReadQUCS32(base, _offset) \
  211. musb_readl(base, (USB_HW_QUCS_OFF + _offset))
  212. #define MGC_ReadQIRQ32(base, _offset) \
  213. musb_readl(base, (USB_HW_QIRQ_OFF + _offset))
  214. #define MGC_WriteQMU32(base, _offset, _data) \
  215. musb_writel(base, (USB_HW_QMU_OFF + _offset), _data)
  216. #define MGC_WriteQUCS32(base, _offset, _data) \
  217. musb_writel(base, (USB_HW_QUCS_OFF + _offset), _data)
  218. #define MGC_WriteQIRQ32(base, _offset, _data) \
  219. musb_writel(base, (USB_HW_QIRQ_OFF + _offset), _data)
  220. u8 PDU_calcCksum(u8 *data, int len);
  221. /* brief Define DMAQ GPD format */
  222. #define TGPD_FLAGS_HWO 0x01
  223. #define TGPD_IS_FLAGS_HWO(_pd) (((TGPD *)_pd)->flag & TGPD_FLAGS_HWO)
  224. #define TGPD_SET_FLAGS_HWO(_pd) (((TGPD *)_pd)->flag |= TGPD_FLAGS_HWO)
  225. #define TGPD_CLR_FLAGS_HWO(_pd) (((TGPD *)_pd)->flag &= (~TGPD_FLAGS_HWO))
  226. #define TGPD_FORMAT_BDP 0x02
  227. #define TGPD_IS_FORMAT_BDP(_pd) (((TGPD *)_pd)->flag & TGPD_FORMAT_BDP)
  228. #define TGPD_SET_FORMAT_BDP(_pd) (((TGPD *)_pd)->flag |= TGPD_FORMAT_BDP)
  229. #define TGPD_CLR_FORMAT_BDP(_pd) (((TGPD *)_pd)->flag &= (~TGPD_FORMAT_BDP))
  230. #define TGPD_SET_FLAG(_pd, _flag) (((TGPD *)_pd)->flag = (((TGPD *)_pd)->flag&(~TGPD_FLAGS_HWO))|(_flag))
  231. #define TGPD_GET_FLAG(_pd) (((TGPD *)_pd)->flag & TGPD_FLAGS_HWO)
  232. #define TGPD_SET_CHKSUM(_pd, _n) (((TGPD *)_pd)->chksum = PDU_calcCksum((u8 *)_pd, _n))
  233. #define TGPD_SET_CHKSUM_HWO(_pd, _n) (((TGPD *)_pd)->chksum = PDU_calcCksum((u8 *)_pd, _n)-1)
  234. #define TGPD_GET_CHKSUM(_pd) (((TGPD *)_pd)->chksum)
  235. #define TGPD_SET_FORMAT(_pd, _fmt) (((TGPD *)_pd)->flag = (((TGPD *)_pd)->flag&(~TGPD_FORMAT_BDP))|(_fmt))
  236. #define TGPD_GET_FORMAT(_pd) (((((TGPD *)_pd)->flag & TGPD_FORMAT_BDP)>>1))
  237. #define TGPD_SET_DataBUF_LEN(_pd, _len) (((TGPD *)_pd)->DataBufferLen = _len)
  238. #define TGPD_ADD_DataBUF_LEN(_pd, _len) (((TGPD *)_pd)->DataBufferLen += _len)
  239. #define TGPD_GET_DataBUF_LEN(_pd) (((TGPD *)_pd)->DataBufferLen)
  240. #define TGPD_SET_NEXT(_pd, _next) (((TGPD *)_pd)->pNext = (u32)(unsigned long)((TGPD *)_next))
  241. #define TGPD_GET_NEXT(_pd) ((TGPD *)(unsigned long)((TGPD *)_pd)->pNext)
  242. #define TGPD_SET_DATA(_pd, _data) (((TGPD *)_pd)->pBuf = (u32)(unsigned long)_data)
  243. #define TGPD_GET_DATA(_pd) ((u8 *)(unsigned long)((TGPD *)_pd)->pBuf)
  244. #define TGPD_SET_BUF_LEN(_pd, _len) (((TGPD *)_pd)->bufLen = _len)
  245. #define TGPD_ADD_BUF_LEN(_pd, _len) (((TGPD *)_pd)->bufLen += _len)
  246. #define TGPD_GET_BUF_LEN(_pd) (((TGPD *)_pd)->bufLen)
  247. #define TGPD_SET_EXT_LEN(_pd, _len) (((TGPD *)_pd)->ExtLength = _len)
  248. #define TGPD_GET_EXT_LEN(_pd) (((TGPD *)_pd)->ExtLength)
  249. #define TGPD_SET_EPaddr(_pd, _EP) (((TGPD *)_pd)->ZTepFlag = (((TGPD *)_pd)->ZTepFlag&0xF0)|(_EP))
  250. #define TGPD_GET_EPaddr(_pd) (((TGPD *)_pd)->ZTepFlag & 0x0F)
  251. #define TGPD_FORMAT_TGL 0x10
  252. #define TGPD_IS_FORMAT_TGL(_pd) ((((TGPD *)_pd)->ZTepFlag & TGPD_FORMAT_TGL))
  253. #define TGPD_SET_FORMAT_TGL(_pd) ((((TGPD *)_pd)->ZTepFlag |= TGPD_FORMAT_TGL))
  254. #define TGPD_CLR_FORMAT_TGL(_pd) ((((TGPD *)_pd)->ZTepFlag &= (~TGPD_FORMAT_TGL)))
  255. #define TGPD_FORMAT_ZLP 0x20
  256. #define TGPD_IS_FORMAT_ZLP(_pd) ((((TGPD *)_pd)->ZTepFlag & TGPD_FORMAT_ZLP))
  257. #define TGPD_SET_FORMAT_ZLP(_pd) ((((TGPD *)_pd)->ZTepFlag |= TGPD_FORMAT_ZLP))
  258. #define TGPD_CLR_FORMAT_ZLP(_pd) ((((TGPD *)_pd)->ZTepFlag &= (~TGPD_FORMAT_ZLP)))
  259. #define TGPD_SET_TGL(_pd, _TGL) (((TGPD *)_pd)->ZTepFlag |= ((_TGL) ? 0x10 : 0x00))
  260. #define TGPD_GET_TGL(_pd) (((TGPD *)_pd)->ZTepFlag & 0x10 ? 1:0)
  261. #define TGPD_SET_ZLP(_pd, _ZLP) (((TGPD *)_pd)->ZTepFlag |= ((_ZLP) ? 0x20 : 0x00))
  262. #define TGPD_GET_ZLP(_pd) (((TGPD *)_pd)->ZTepFlag & 0x20 ? 1:0)
  263. #define TGPD_FLAG_IOC 0x80
  264. #define TGPD_SET_IOC(_pd) (((TGPD *)_pd)->flag |= TGPD_FLAG_IOC)
  265. extern void qmu_destroy_gpd_pool(struct device *dev);
  266. extern int qmu_init_gpd_pool(struct device *dev);
  267. extern void qmu_reset_gpd_pool(u32 ep_num, u8 isRx);
  268. extern bool mtk_is_qmu_enabled(u8 EP_Num, u8 isRx);
  269. extern void mtk_qmu_enable(struct musb *musb, u8 EP_Num, u8 isRx);
  270. extern void mtk_qmu_insert_task(u8 EP_Num, u8 isRx, u8 *buf, u32 length, u8 zlp);
  271. extern void mtk_qmu_resume(u8 EP_Num, u8 isRx);
  272. extern void qmu_done_rx(struct musb *musb, u8 ep_num);
  273. extern void qmu_done_tx(struct musb *musb, u8 ep_num);
  274. extern void mtk_disable_q(struct musb *musb, u8 ep_num, u8 isRx);
  275. extern void mtk_qmu_irq_err(struct musb *musb, u32 qisar);
  276. extern void flush_ep_csr(struct musb *musb, u8 ep_num, u8 isRx);
  277. extern void mtk_qmu_stop(u8 ep_num, u8 isRx);
  278. #endif
  279. #endif