plat_common.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #ifndef __HAL_PUB_H_
  2. #define __HAL_PUB_H_
  3. #include <linux/kernel.h>
  4. #include <linux/version.h>
  5. #include <linux/types.h>
  6. #include <linux/delay.h>
  7. #include <linux/irq.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/kfifo.h>
  10. #include <linux/vmalloc.h>
  11. #include <linux/slab.h>
  12. #include <linux/sched.h>
  13. #include <linux/sched/rt.h>
  14. #include <mt_io.h>
  15. #ifdef CONFIG_OF
  16. #include <linux/of_irq.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of.h>
  19. #else
  20. #include <mach/mt_reg_base.h>
  21. #include <mach/mt_irq.h>
  22. #endif
  23. #if defined(CONFIG_MTK_CLKMGR)
  24. #include <mach/mt_clkmgr.h>
  25. #else
  26. #include <linux/clk.h>
  27. #include <linux/platform_device.h>
  28. #endif /* defined(CONFIG_MTK_CLKMGR) */
  29. #include <sync_write.h>
  30. extern int mtk_btif_hal_get_log_lvl(void);
  31. #define MTK_BTIF_MARK_UNUSED_API
  32. typedef irq_handler_t mtk_btif_irq_handler;
  33. #define MTK_BTIF_ENABLE_CLK_CTL 1
  34. #define MTK_BTIF_ENABLE_CLK_REF_COUNTER 1
  35. #define DBG_LOG_STR_SIZE 384
  36. /*Log defination*/
  37. static int hal_log_print(const char *str, ...)
  38. {
  39. va_list args;
  40. char temp_sring[DBG_LOG_STR_SIZE];
  41. va_start(args, str);
  42. vsnprintf(temp_sring, DBG_LOG_STR_SIZE, str, args);
  43. va_end(args);
  44. pr_err("%s", temp_sring);
  45. return 0;
  46. }
  47. #define BTIF_LOG_LOUD 4
  48. #define BTIF_LOG_DBG 3
  49. #define BTIF_LOG_INFO 2
  50. #define BTIF_LOG_WARN 1
  51. #define BTIF_LOG_ERR 0
  52. #ifndef DFT_TAG
  53. #define DFT_TAG "[BTIF-DFT]"
  54. #endif
  55. #define BTIF_LOUD_FUNC(fmt, arg ...) \
  56. do { \
  57. if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_LOUD) \
  58. hal_log_print(DFT_TAG "[L]%s:" fmt, \
  59. __func__, ## arg); \
  60. } while (0)
  61. #define BTIF_INFO_FUNC(fmt, arg ...) \
  62. do { \
  63. if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_INFO)\
  64. hal_log_print(DFT_TAG "[I]%s:" fmt, \
  65. __func__, ## arg); \
  66. } while (0)
  67. #define BTIF_WARN_FUNC(fmt, arg ...) \
  68. do { \
  69. if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_WARN)\
  70. hal_log_print(DFT_TAG "[W]%s:" fmt, \
  71. __func__, ## arg); \
  72. } while (0)
  73. #define BTIF_ERR_FUNC(fmt, arg ...)\
  74. do {\
  75. if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_ERR)\
  76. hal_log_print(DFT_TAG "[E]%s(%d):" fmt,\
  77. __func__, __LINE__, ## arg);\
  78. } while (0)
  79. #define BTIF_DBG_FUNC(fmt, arg ...) \
  80. do { \
  81. if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_DBG) \
  82. hal_log_print(DFT_TAG "[D]%s:" fmt, \
  83. __func__, ## arg); \
  84. } while (0)
  85. #define BTIF_TRC_FUNC(f) \
  86. do { \
  87. if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_DBG) \
  88. hal_log_print(DFT_TAG "<%s> <%d>\n", \
  89. __func__, __LINE__); \
  90. } while (0)
  91. /*-----------------------------------Enum Defination--------------------------------*/
  92. /*IRQ sensetive type */
  93. typedef enum _ENUM_IRQ_SENS_TYPE_ {
  94. IRQ_SENS_EDGE = 0,
  95. IRQ_SENS_LVL = IRQ_SENS_EDGE + 1,
  96. IRQ_SENS_TYPE_MAX
  97. } ENUM_IRQ_SENS_TYPE;
  98. /*IRQ level trigger type */
  99. typedef enum _ENUM_IRQ_LVL_TYPE_ {
  100. IRQ_LVL_LOW = 0,
  101. IRQ_LVL_HIGH = IRQ_LVL_LOW + 1,
  102. IRQ_LVL_MAX
  103. } ENUM_IRQ_LVL;
  104. /*IRQ edge trigger type */
  105. typedef enum _ENUM_IRQ_EDGE_TYPE_ {
  106. IRQ_EDGE_FALL = 0,
  107. IRQ_EDGE_RAISE = IRQ_EDGE_FALL + 1,
  108. IRQ_EDGE_BOTH = IRQ_EDGE_RAISE + 1,
  109. IRQ_EDGE_MAX
  110. } ENUM_IRQ_EDGE;
  111. typedef enum _ENUM_CLOCK_CTRL_ {
  112. CLK_OUT_DISABLE = 0,
  113. CLK_OUT_ENABLE = CLK_OUT_DISABLE + 1,
  114. CLK_OUT_MAX
  115. } ENUM_CLOCK_CTRL;
  116. /*Error No. table */
  117. typedef enum _ENUM_ERROR_CODE_ {
  118. ERR_NO_ERROR = 0,
  119. ERR_INVALID_PAR = ERR_NO_ERROR - 1,
  120. ERR_MAX = ERR_INVALID_PAR - 1,
  121. } ENUM_ERROR_CODE;
  122. typedef enum _ENUM_BTIF_DIR_ {
  123. BTIF_TX = 0,
  124. BTIF_RX = BTIF_TX + 1,
  125. BTIF_DIR_MAX,
  126. } ENUM_BTIF_DIR;
  127. typedef enum _ENUM_DMA_DIR_ {
  128. DMA_DIR_RX = 0,
  129. DMA_DIR_TX = DMA_DIR_RX + 1,
  130. DMA_DIR_BOTH,
  131. } ENUM_DMA_DIR;
  132. typedef enum _ENUM_BTIF_REG_ID_ {
  133. REG_IIR = 0, /*Interrupt Identification Register */
  134. REG_LSR = 1, /*Line Status Register */
  135. REG_FAKE_LCR = 2, /*Fake Lcr Regiseter */
  136. REG_FIFO_CTRL = 3, /*FIFO Control Register */
  137. REG_IER = 4, /*Interrupt Enable Register */
  138. REG_SLEEP_EN = 5, /*Sleep Enable Register */
  139. REG_RTO_COUNTER = 6, /*Rx Timeout Counter Register */
  140. REG_DMA_EN = 7, /*DMA Enalbe Register */
  141. REG_TRIG_LVL = 8, /*Tx/Rx Trigger Level Register */
  142. REG_WAT_TIME = 9, /*Async Wait Time Register */
  143. REG_HANDSHAKE = 10, /*New HandShake Mode Register */
  144. REG_SLP_WAK = 11, /*Sleep Wakeup Reigster */
  145. REG_BTIF_ALL = 12, /*all btif controller's registers */
  146. REG_TX_DMA_ALL = 13,
  147. REG_RX_DMA_ALL = 14,
  148. REG_MAX
  149. } ENUM_BTIF_REG_ID;
  150. typedef enum _MTK_BTIF_PM_OPID_ {
  151. BTIF_PM_DPIDLE_EN,
  152. BTIF_PM_DPIDLE_DIS,
  153. BTIF_PM_SUSPEND,
  154. BTIF_PM_RESUME,
  155. BTIF_PM_RESTORE_NOIRQ,
  156. } MTK_BTIF_PM_OPID;
  157. #define BTIF_HAL_TX_FIFO_SIZE (1024 * 4)
  158. /*-----------------------------------Enum Defination End--------------------------------*/
  159. /*****************************structure definition***************************/
  160. /*IRQ related information*/
  161. typedef struct _MTK_BTIF_IRQ_STR_ {
  162. const char *name;
  163. bool is_irq_sup;
  164. unsigned int irq_id;
  165. #ifdef CONFIG_OF
  166. unsigned int irq_flags;
  167. #else
  168. ENUM_IRQ_SENS_TYPE sens_type;
  169. union {
  170. ENUM_IRQ_LVL lvl_type;
  171. ENUM_IRQ_EDGE edge_type;
  172. };
  173. #endif
  174. bool reg_flag;
  175. irq_handler_t p_irq_handler;
  176. } MTK_BTIF_IRQ_STR, *P_MTK_BTIF_IRQ_STR;
  177. typedef struct _DMA_VFIFO_ {
  178. /*[Driver Access] vFIFO memory'svirtual address */
  179. unsigned char *p_vir_addr;
  180. /*[HW Access] dma handle , physically address, set to DMA's HW Register */
  181. dma_addr_t phy_addr;
  182. /*DMA's vFIFO size */
  183. unsigned int vfifo_size;
  184. /*DMA's threshold value */
  185. unsigned int thre;
  186. } DMA_VFIFO, *P_DMA_VFIFO;
  187. typedef unsigned int (*dma_rx_buf_write) (void *p_dma_info,
  188. unsigned char *p_buf,
  189. unsigned int buf_len);
  190. typedef unsigned int (*btif_rx_buf_write) (void *p_btif_info,
  191. unsigned char *p_buf,
  192. unsigned int buf_len);
  193. /*DMA related information*/
  194. typedef struct _MTK_DMA_INFO_STR_ {
  195. unsigned long base;
  196. ENUM_DMA_DIR dir;
  197. P_MTK_BTIF_IRQ_STR p_irq;
  198. dma_rx_buf_write rx_cb;
  199. P_DMA_VFIFO p_vfifo;
  200. } MTK_DMA_INFO_STR, *P_MTK_DMA_INFO_STR;
  201. /*DMA related information*/
  202. typedef struct _MTK_BTIF_INFO_STR_ {
  203. unsigned long base; /*base address */
  204. P_MTK_BTIF_IRQ_STR p_irq; /*irq related information */
  205. unsigned int tx_fifo_size; /*BTIF tx FIFO size */
  206. unsigned int rx_fifo_size; /*BTIF rx FIFO size */
  207. unsigned int tx_tri_lvl; /*BTIFtx trigger level in FIFO mode */
  208. unsigned int rx_tri_lvl; /*BTIFrx trigger level in FIFO mode */
  209. unsigned int clk_gat_addr; /*clock gating address */
  210. unsigned int set_bit; /*enable clock gating bit */
  211. unsigned int clr_bit; /*clear clock gating bit */
  212. unsigned int rx_data_len; /*rx data length */
  213. btif_rx_buf_write rx_cb;
  214. struct kfifo *p_tx_fifo; /*tx fifo */
  215. spinlock_t tx_fifo_spinlock; /*tx fifo spinlock */
  216. } MTK_BTIF_INFO_STR, *P_MTK_BTIF_INFO_STR;
  217. /**********End of Structure Definition***********/
  218. /***********register operation***********/
  219. #ifdef __KERNEL__
  220. /*byte write <1 byte> */
  221. #define btif_reg_sync_writeb(v, a) mt_reg_sync_writeb(v, a)
  222. /*word write <2 byte> */
  223. #define btif_reg_sync_writew(v, a) mt_reg_sync_writew(v, a)
  224. /*long write <4 byte> */
  225. #define btif_reg_sync_writel(v, a) mt_reg_sync_writel(v, a)
  226. #else
  227. /*byte write <1 byte> */
  228. #define btif_reg_sync_writeb(v, a) mt65xx_reg_sync_writeb(v, a)
  229. /*word write <2 byte> */
  230. #define btif_reg_sync_writew(v, a) mt65xx_reg_sync_writew(v, a)
  231. /*long write <4 byte> */
  232. #define btif_reg_sync_writel(v, a) mt65xx_reg_sync_writel(v, a)
  233. #endif
  234. #define BTIF_READ8(REG) __raw_readb((unsigned char *)(REG))
  235. #define BTIF_READ16(REG) __raw_readw((unsigned short *)(REG))
  236. #define BTIF_READ32(REG) __raw_readl((unsigned int *)(REG))
  237. #define BTIF_SET_BIT(REG, BITVAL) do { \
  238. *((volatile unsigned int *)(REG)) |= ((unsigned int)(BITVAL)); \
  239. mb(); /**/ \
  240. } \
  241. while (0)
  242. #define BTIF_CLR_BIT(REG, BITVAL) do { \
  243. (*(volatile unsigned int *)(REG)) &= ~((unsigned int)(BITVAL)); \
  244. mb(); /**/\
  245. } \
  246. while (0)
  247. /***********end of register operation *********/
  248. #endif /*__HAL_PUB_H_*/