ccci_layer.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*****************************************************************************
  2. *
  3. * Filename:
  4. * ---------
  5. * ccci_layer.h
  6. *
  7. * Project:
  8. * --------
  9. * ALPS
  10. *
  11. * Description:
  12. * ------------
  13. * MT65XX CCCI header file
  14. *
  15. ****************************************************************************/
  16. #ifndef __CCCI_LAYER_H__
  17. #define __CCCI_LAYER_H__
  18. #include <linux/kfifo.h>
  19. #include <linux/slab.h>
  20. #include <linux/module.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/mm.h>
  24. #include <linux/kfifo.h>
  25. #include <linux/io.h>
  26. #include <linux/atomic.h>
  27. #include <linux/rwlock.h>
  28. #include <linux/bitops.h>
  29. #include <linux/sched.h>
  30. #include <linux/wakelock.h>
  31. #include <ccci_ch.h>
  32. #include <ccif.h>
  33. #define CCCI_DEV_NAME "ccci"
  34. /* #define CCCI_DEV_MAJOR 184 move to platform.h */
  35. #define CCCI_SYSFS_INFO "info"
  36. #define CCCI_FIFO_MAX_LEN 8 /* 8 = max of physical channel */
  37. /* --------------logical channel attribute define-------------------*/
  38. #define L_CH_ATTR_TX (1<<0) /* This logic channel is a TX channel */
  39. #define L_CH_ATTR_PRVLG0 (1<<1) /* This logic channel can send data even if runtime data not send */
  40. #define L_CH_ATTR_PRVLG1 (1<<2) /* This logic channel can send data even if modem not boot ready */
  41. #define L_CH_ATTR_PRVLG2 (1<<3) /* This logic channel can send data even if modem has exception */
  42. #define L_CH_ATTR_DUMMY_WRITE (1<<4) /* This logic channel using dummy write if modem has exception */
  43. #define L_CH_ATTR_OPEN_CLEAR (1<<5) /* Clear all fifo data when open */
  44. #define L_CH_DROP_TOLERATED (1<<6) /* Drop message is tolerated for this channel */
  45. #define L_CH_MUST_RDY_FOR_BOOT (1<<7) /* During modem boot up, the channel must be ready */
  46. /* Not set runtime data to MD */
  47. /* #define MD_BOOT_STAGE_0 (1) */
  48. /* Has set runtime data to MD, but MD not ready yet */
  49. /* #define MD_BOOT_STAGE_1 (2) */
  50. /* Modem is ready */
  51. /* #define MD_BOOT_STAGE_2 (3) */
  52. /* --------------TX transfer function define-------------------*/
  53. #define CCCI_INIT_MAILBOX(buff, mailbox_id) \
  54. do { \
  55. ((struct ccci_msg_t *)buff)->magic = 0xFFFFFFFF; \
  56. ((struct ccci_msg_t *)buff)->id = (mailbox_id); \
  57. ((struct ccci_msg_t *)buff)->channel = CCCI_INVALID_CH_ID; \
  58. ((struct ccci_msg_t *)buff)->reserved = 0; \
  59. } while (0)
  60. /* initialize a CCCI stream buffer */
  61. #define CCCI_INIT_STREAM(buff, stream_addr, stream_len)\
  62. do { \
  63. ((struct ccci_msg_t *)buff)->addr = (stream_addr);\
  64. ((struct ccci_msg_t *)buff)->len = (stream_len);\
  65. ((struct ccci_msg_t *)buff)->channel = CCCI_INVALID_CH_ID;\
  66. ((struct ccci_msg_t *)buff)->reserved = 0;\
  67. } while (0)
  68. /* -----------------data structure define-------------------------*/
  69. /* CCCI API return value */
  70. enum CCCI_RETURNVAL_T {
  71. CCCI_SUCCESS = 0,
  72. CCCI_FAIL = -EIO,
  73. CCCI_IN_USE = -EEXIST,
  74. CCCI_NOT_OWNER = -EPERM,
  75. CCCI_INVALID_PARAM = -EINVAL,
  76. CCCI_NO_PHY_CHANNEL = -ENXIO,
  77. CCCI_IN_INTERRUPT = -EACCES,
  78. CCCI_IN_IRQ = -EINTR,
  79. CCCI_MD_NOT_READY = -EBUSY,
  80. CCCI_MD_IN_RESET = -ESRCH,
  81. CCCI_RESET_NOT_READY = -ENODEV
  82. };
  83. /* CCCI mailbox channel structure */
  84. struct CCCI_MAILBOX_T {
  85. unsigned int magic; /* 0xFFFFFFFF */
  86. unsigned int id;
  87. };
  88. /* CCCI stream channel structure */
  89. struct CCCI_STREAM_T {
  90. unsigned int addr;
  91. unsigned int len;
  92. };
  93. /* CCCI channel buffer structure */
  94. struct CCCI_BUFF_T {
  95. unsigned int data[2];
  96. unsigned int channel;
  97. unsigned int reserved;
  98. };
  99. /* CCCI callback function prototype */
  100. typedef void (*CCCI_CALLBACK) (struct CCCI_BUFF_T *buff, void *private_data);
  101. enum CCCI_STATE_T {
  102. CCCI_ENABLED = 0x0,
  103. CCCI_RUNNING = 0x1,
  104. };
  105. struct CCCI_LOG_T {
  106. unsigned long sec;
  107. unsigned long nanosec;
  108. struct CCCI_BUFF_T buff;
  109. short rx;
  110. };
  111. /* CCCI mailbox channel structure */
  112. struct ccci_mail_box_t {
  113. unsigned int magic; /* 0xFFFFFFFF */
  114. unsigned int id;
  115. };
  116. /* CCCI stream channel structure */
  117. struct ccci_stream_msg_t {
  118. unsigned int addr;
  119. unsigned int len;
  120. };
  121. /* CCCI common channel structure */
  122. struct ccci_common_msg_t {
  123. unsigned int data[2];
  124. };
  125. struct ccci_msg_t {
  126. union {
  127. unsigned int magic; /* For mail box magic number */
  128. unsigned int addr; /* For stream start addr */
  129. unsigned int data0; /* For ccci common data[0] */
  130. };
  131. union {
  132. unsigned int id; /* For mail box message id */
  133. unsigned int len; /* For stream len */
  134. unsigned int data1; /* For ccci common data[1] */
  135. };
  136. unsigned int channel;
  137. unsigned int reserved;
  138. };
  139. struct DEBUG_INFO_T {
  140. unsigned int type;
  141. char *name;
  142. unsigned int more_info;
  143. union {
  144. struct {
  145. char file_name[30];
  146. int line_num;
  147. unsigned int parameters[3];
  148. } assert;
  149. struct {
  150. int err_code1;
  151. int err_code2;
  152. } fatal_error;
  153. struct ccci_msg_t data;
  154. struct {
  155. unsigned char execution_unit[9]; /* 8+1 */
  156. char file_name[30];
  157. int line_num;
  158. unsigned int parameters[3];
  159. } dsp_assert;
  160. struct {
  161. unsigned char execution_unit[9];
  162. unsigned int code1;
  163. } dsp_exception;
  164. struct {
  165. unsigned char execution_unit[9];
  166. unsigned int err_code[2];
  167. } dsp_fatal_err;
  168. };
  169. int *ext_mem;
  170. size_t ext_size;
  171. int *md_image;
  172. size_t md_size;
  173. void *platform_data;
  174. void (*platform_call)(void *data);
  175. };
  176. struct logic_channel_info_t {
  177. unsigned int m_ch_id;
  178. unsigned int m_attrs;
  179. struct kfifo m_kfifo;
  180. unsigned int m_kfifo_ready;
  181. char *m_ch_name;
  182. char *m_owner_name;
  183. void *m_owner;
  184. void (*m_call_back)(void *);
  185. spinlock_t m_lock;
  186. unsigned int m_register;
  187. int m_md_id;
  188. };
  189. struct logic_channel_static_info_t {
  190. unsigned int m_ch_id;
  191. unsigned int m_kfifo_size;
  192. char *m_ch_name;
  193. unsigned int m_attrs;
  194. };
  195. struct logic_dispatch_ctl_block_t {
  196. struct logic_channel_info_t m_logic_ch_table[CCCI_MAX_CH_NUM];
  197. struct ccif_t *m_ccif;
  198. struct tasklet_struct m_dispatch_tasklet;
  199. unsigned char m_has_pending_data;
  200. unsigned char m_freezed;
  201. unsigned char m_running;
  202. unsigned int m_md_id;
  203. struct wake_lock m_wakeup_wake_lock;
  204. char m_wakelock_name[16];
  205. void (*m_send_notify_cb)(int, unsigned int);
  206. u64 m_last_send_ref_jiffies;
  207. unsigned long m_status_flag;
  208. spinlock_t m_lock;
  209. };
  210. /* -----------------function define-------------------------*/
  211. int register_to_logic_ch(int md_id, int ch, void (*func) (void *), void *owner);
  212. int un_register_to_logic_ch(int md_id, int ch);
  213. int logic_layer_reset(int);
  214. int cal_ring_buffer_free_space(int read_idx, int write_idx, int ring_buf_len);
  215. int cal_ring_buffer_valid_data_size(int read_idx, int write_idx,
  216. int ring_buf_len);
  217. int ccci_logic_ctlb_init(int);
  218. void ccci_logic_ctlb_deinit(int);
  219. int get_logic_ch_data(struct logic_channel_info_t *ch_info, struct ccci_msg_t *msg);
  220. int get_logic_ch_data_len(struct logic_channel_info_t *ch_info);
  221. struct logic_channel_info_t *get_logic_ch_info(int md_id, int ch_id);
  222. void freeze_logic_layer_tx(int);
  223. void freeze_all_logic_layer(int);
  224. /* void set_curr_md_state(int md_id, int state); */
  225. void *get_dispatch_ctl_block(int md_sys);
  226. int ccci_message_send(int md_id, struct ccci_msg_t *msg, int retry_en);
  227. void ccci_system_message(int md_id, unsigned int msg, unsigned int resv);
  228. void ccci_disable_md_intr(int md_id);
  229. void ccci_enable_md_intr(int md_id);
  230. void ccci_hal_reset(int md_id);
  231. void ccci_hal_irq_register(int md_id);
  232. void set_md_sys_max_num(unsigned int max_num);
  233. void update_active_md_sys_state(int md_id, int active);
  234. void set_md_enable(int md_id, int en);
  235. int ccci_logic_layer_init(int);
  236. void ccci_logic_layer_exit(int);
  237. int ccci_write_runtime_data(int md_id, unsigned char buf[], int len);
  238. extern int __init ccif_module_init(void);
  239. extern void __exit ccif_module_exit(void);
  240. #endif /* __CCCI_LAYER_H__ */