modem_sdio.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. /*
  2. *drivers/mmc/card/modem_sdio.h
  3. *
  4. *VIA CBP SDIO driver for Linux
  5. *
  6. *Copyright (C) 2009 VIA TELECOM Corporation, Inc.
  7. *Author: VIA TELECOM Corporation, Inc.
  8. *
  9. *This package is free software; you can redistribute it and/or modify
  10. *it under the terms of the GNU General Public License version 2 as
  11. *published by the Free Software Foundation.
  12. *
  13. *THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14. *IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15. *WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16. */
  17. #ifndef MODEM_SDIO_H
  18. #define MODEM_SDIO_H
  19. #include <linux/tty.h>
  20. #include <linux/tty_flip.h>
  21. #include <linux/kfifo.h>
  22. #include <mt-plat/mt_ccci_common.h>
  23. #include "cbp_sdio.h"
  24. #ifdef CONFIG_MTK_C2K_DATA_PPP_SUPPORT
  25. #define ENABLE_CCMNI (0)
  26. #define ENABLE_CHAR_DEV (0)
  27. #else
  28. #define ENABLE_CCMNI (1)
  29. #define ENABLE_CHAR_DEV (1)
  30. #endif
  31. #define SDIO_TTY_CHAN_ID_BEGIN 1
  32. #define SDIO_TTY_CHAN_ID_END 13
  33. #define SDIO_TTY_NR 13 /*Number of UARTs this driver can handle */
  34. #ifdef CONFIG_EVDO_DT_VIA_SUPPORT
  35. #define CTRL_CH_ID 0
  36. #define DATA_CH_ID 1
  37. #define MD_LOG_CH_ID 2
  38. #define FLS_CH_ID 3 /*flashlessd channel id */
  39. #define SDIO_AT_CHANNEL_NUM (4)
  40. #define AGPS_CH_ID 6
  41. #define SDIO_AT2_CHANNEL_NUM (7)
  42. #define SDIO_AT3_CHANNEL_NUM (8)
  43. #define EXCP_CTRL_CH_ID 11
  44. #define EXCP_MSG_CH_ID 12
  45. #define EXCP_DATA_CH_ID 13
  46. #else
  47. #define CTRL_CH_ID 0
  48. #define DATA_CH_ID 2
  49. #define MD_LOG_CH_ID 3
  50. #define FLS_CH_ID 4 /*flashlessd channel id */
  51. #define SDIO_AT_CHANNEL_NUM (5)
  52. #define AGPS_CH_ID 6
  53. #define SDIO_AT2_CHANNEL_NUM (7)
  54. #define SDIO_AT3_CHANNEL_NUM (8)
  55. #define MD_LOG2_CH_ID 10
  56. #define EXCP_CTRL_CH_ID 11
  57. #define EXCP_MSG_CH_ID 12
  58. #define EXCP_DATA_CH_ID 13
  59. #define CCMNI_AP_LOOPBACK_CH (15)
  60. #endif
  61. #define HEART_BEAT_TIMEOUT (10000) /*ms */
  62. #define POLLING_INTERVAL (15000) /*ms */
  63. #define FORCE_ASSERT_TIMEOUT (5000) /*ms */
  64. /*
  65. *SDIO buffer-in lens.
  66. *when tty port is not opened by upper layer, we buffer some data from md, when opened, push to tty.
  67. *BUF_IN_MAX_NUM means the max packet number we will buffer for each service.
  68. */
  69. #define SDIO_PPP_BUF_IN_MAX_NUM 100
  70. #define SDIO_ETS_BUF_IN_MAX_NUM 500
  71. #define SDIO_IFS_BUF_IN_MAX_NUM 100
  72. #define SDIO_AT_BUF_IN_MAX_NUM 100
  73. #define SDIO_PCV_BUF_IN_MAX_NUM 100
  74. #define SDIO_DEF_BUF_IN_MAX_NUM 100
  75. #if ENABLE_CHAR_DEV
  76. #define SDIO_BUF_IN_MAX_SIZE (256*1024)
  77. #else
  78. #define SDIO_BUF_IN_MAX_SIZE 64512 /*max buffer-in size = 63K, for each port */
  79. #endif
  80. #define MODEM_FC_PRINT_MAX 3 /*for print flow control logs */
  81. #define SDIO_FUNC_1_IRQ (1<<1) /*for SDIO irq source check */
  82. #define SDIO_BUF_MAX 4096
  83. #define SDIO_ASSEMBLE_MAX (100*1024)
  84. #define ONE_PACKET_MAX_SIZE (5200)
  85. #ifndef CONFIG_EVDO_DT_VIA_SUPPORT
  86. #define SDIO_WRITE_ADDR SDIO_CTDR
  87. #else
  88. #define SDIO_WRITE_ADDR 0x00
  89. #endif
  90. #define MSG_START_FLAG 0xFE
  91. #define SDIO_MSG_MAX_LEN 4096
  92. #define MORE_DATA_FOLLOWING (0x20)
  93. #ifndef CONFIG_EVDO_DT_VIA_SUPPORT
  94. struct sdio_hw_head {
  95. unsigned char len_low;
  96. unsigned char len_hi;
  97. unsigned char reserved1;
  98. unsigned char reserved2;
  99. };
  100. #endif
  101. struct sdio_msg_head {
  102. #ifndef CONFIG_EVDO_DT_VIA_SUPPORT
  103. struct sdio_hw_head hw_head;
  104. #endif
  105. unsigned char start_flag; /*start flag(0xFE), little endian */
  106. unsigned char chanInfo; /*channel id */
  107. unsigned char tranHi; /*len High byte, little endian */
  108. unsigned char tranLow; /*len low byte, little endian */
  109. };
  110. struct sdio_msg {
  111. struct sdio_msg_head head;
  112. unsigned char buffer[SDIO_MSG_MAX_LEN];
  113. };
  114. enum sflow_ctrl_state {
  115. SFLOW_CTRL_DISABLE = 0, /*default disable */
  116. SFLOW_CTRL_ENABLE /*when md request, we set this */
  117. };
  118. enum ccmni_tx_state {
  119. CCMNI_TX_READY = 0, /*default is ready */
  120. CCMNI_TX_STOP, /*when tx busy, we set this */
  121. };
  122. struct sdio_modem_port {
  123. struct sdio_modem *modem; /*all port use one sdio_modem */
  124. struct sdio_func *func;
  125. #if ENABLE_CHAR_DEV
  126. struct cdev char_dev;
  127. atomic_t usage_cnt;
  128. wait_queue_head_t rx_wq;
  129. #else
  130. struct tty_port port;
  131. struct tty_struct *tty;
  132. #endif
  133. struct kref kref;
  134. spinlock_t write_lock;
  135. unsigned int index;
  136. struct kfifo transmit_fifo;
  137. const char *name;
  138. char work_name[64];
  139. struct workqueue_struct *write_q;
  140. struct work_struct write_work;
  141. #if ENABLE_CCMNI
  142. struct work_struct write_ccmni_work;
  143. enum ccmni_tx_state tx_state;
  144. spinlock_t tx_state_lock;
  145. #endif
  146. struct device dev;
  147. struct mutex sdio_buf_in_mutex;
  148. struct list_head sdio_buf_in_list;
  149. unsigned char sdio_buf_in;
  150. unsigned int sdio_buf_in_num; /*buffer in list num */
  151. unsigned int sdio_buf_in_max_num; /*buffer in list max num */
  152. unsigned int sdio_buf_in_size; /*buffer in size */
  153. #ifndef CONFIG_EVDO_DT_VIA_SUPPORT
  154. struct mutex sdio_assemble_mutex;
  155. struct list_head sdio_assemble_list;
  156. #endif
  157. wait_queue_head_t sflow_ctrl_wait_q;
  158. atomic_t sflow_ctrl_state;
  159. struct semaphore write_sem;
  160. unsigned int tx_count;
  161. unsigned int rx_count;
  162. /*Settings for the port */
  163. int rts_state; /*Handshaking pins (outputs) */
  164. int dtr_state;
  165. int cts_state; /*Handshaking pins (inputs) */
  166. int dsr_state;
  167. spinlock_t inception_lock;
  168. int inception;
  169. };
  170. struct sdio_buf_in_packet {
  171. struct list_head node;
  172. unsigned int size;
  173. #if ENABLE_CHAR_DEV
  174. unsigned int offset;
  175. unsigned int o_size;
  176. #endif
  177. unsigned char *buffer;
  178. };
  179. #ifndef CONFIG_EVDO_DT_VIA_SUPPORT
  180. struct sdio_assemble_packet {
  181. struct list_head node;
  182. unsigned int size;
  183. unsigned char *buffer;
  184. atomic_t occupied;
  185. };
  186. #endif
  187. struct ctrl_port_msg {
  188. struct sdio_msg_head head;
  189. unsigned char id_hi;
  190. unsigned char id_low;
  191. unsigned char chan_num;
  192. unsigned char option;
  193. };
  194. struct sdio_modem_ctrl_port {
  195. struct ctrl_port_msg chan_ctrl_msg;
  196. unsigned int chan_state;
  197. unsigned int msg_id;
  198. wait_queue_head_t sflow_ctrl_wait_q;
  199. atomic_t sflow_ctrl_state;
  200. };
  201. struct _ccci_msg {
  202. union {
  203. u32 magic; /*For mail box magic number */
  204. u32 addr; /*For stream start addr */
  205. u32 data0; /*For ccci common data[0] */
  206. };
  207. union {
  208. u32 id; /*For mail box message id */
  209. u32 len; /*For stream len */
  210. u32 data1; /*For ccci common data[1] */
  211. };
  212. u32 channel;
  213. u32 reserved;
  214. } __packed;
  215. #define CCCI_CONTROL_TX_CH 1
  216. #define EXCP_MSG_MAX_LEN (SDIO_MSG_MAX_LEN - sizeof(struct _ccci_msg))
  217. struct _exception_msg {
  218. struct _ccci_msg ccci_head;
  219. char buffer[EXCP_MSG_MAX_LEN];
  220. };
  221. /*MODEM MAUI Exception header (4 bytes)*/
  222. struct _exception_record_header_t {
  223. u8 ex_type;
  224. u8 ex_nvram;
  225. u16 ex_serial_num;
  226. } __packed;
  227. /*MODEM MAUI Environment information (164 bytes) */
  228. struct _ex_environment_info_t {
  229. u8 boot_mode;
  230. u8 reserved1[8];
  231. u8 execution_unit[8];
  232. u8 reserved2[147];
  233. } __packed;
  234. /*MODEM MAUI Special for fatal error (8 bytes)*/
  235. struct _ex_fatalerror_code_t {
  236. u32 code1;
  237. u32 code2;
  238. } __packed;
  239. /*MODEM MAUI fatal error (296 bytes)*/
  240. struct _ex_fatalerror_t {
  241. struct _ex_fatalerror_code_t error_code;
  242. u8 reserved1[288];
  243. } __packed;
  244. /*MODEM MAUI Assert fail (296 bytes)*/
  245. struct _ex_assert_fail_t {
  246. u8 filename[24];
  247. u32 linenumber;
  248. u32 parameters[3];
  249. u8 reserved1[256];
  250. } __packed;
  251. /*MODEM MAUI Globally exported data structure (300 bytes) */
  252. union ex_content_u {
  253. struct _ex_fatalerror_t fatalerr;
  254. struct _ex_assert_fail_t assert;
  255. } __packed;
  256. /*MODEM MAUI Standard structure of an exception log ( */
  257. struct _ex_exception_log_t {
  258. struct _exception_record_header_t header;
  259. u8 reserved1[12];
  260. struct _ex_environment_info_t envinfo;
  261. u8 reserved2[36];
  262. union ex_content_u content;
  263. } __packed;
  264. struct dump_debug_info {
  265. unsigned int type;
  266. char *name;
  267. unsigned int more_info;
  268. union {
  269. struct {
  270. char file_name[30];
  271. int line_num;
  272. unsigned int parameters[3];
  273. } assert;
  274. struct {
  275. int err_code1;
  276. int err_code2;
  277. char offender[9];
  278. } fatal_error;
  279. struct _ccci_msg data;
  280. struct {
  281. unsigned char execution_unit[9]; /*8+1 */
  282. char file_name[30];
  283. int line_num;
  284. unsigned int parameters[3];
  285. } dsp_assert;
  286. struct {
  287. unsigned char execution_unit[9];
  288. unsigned int code1;
  289. } dsp_exception;
  290. struct {
  291. unsigned char execution_unit[9];
  292. unsigned int err_code[2];
  293. } dsp_fatal_err;
  294. };
  295. void *ext_mem;
  296. size_t ext_size;
  297. void *md_image;
  298. size_t md_size;
  299. void *platform_data;
  300. void (*platform_call)(void *data);
  301. };
  302. enum {
  303. C2K_MD_EX = 0x4,
  304. C2K_MD_EX_REC_OK = 0x6,
  305. C2K_MD_EX_CHK_ID = 0x45584350,
  306. C2K_MD_EX_REC_OK_CHK_ID = 0x45524543,
  307. };
  308. enum {
  309. MD_EX_TYPE_INVALID = 0,
  310. MD_EX_TYPE_UNDEF = 1,
  311. MD_EX_TYPE_SWI = 2,
  312. MD_EX_TYPE_PREF_ABT = 3,
  313. MD_EX_TYPE_DATA_ABT = 4,
  314. MD_EX_TYPE_ASSERT = 5,
  315. MD_EX_TYPE_FATALERR_TASK = 6,
  316. MD_EX_TYPE_FATALERR_BUF = 7,
  317. MD_EX_TYPE_LOCKUP = 8,
  318. MD_EX_TYPE_ASSERT_DUMP = 9,
  319. MD_EX_TYPE_ASSERT_FAIL = 10,
  320. DSP_EX_TYPE_ASSERT = 11,
  321. DSP_EX_TYPE_EXCEPTION = 12,
  322. DSP_EX_FATAL_ERROR = 13,
  323. STACKACCESS_EXCEPTION = 14,
  324. /*cross core trigger exception */
  325. CC_MD1_EXCEPTION = 15,
  326. NUM_EXCEPTION,
  327. MD_EX_TYPE_EMI_CHECK = 99,
  328. MD_EX_LTE_FATAL_ERROR = 0x3000,
  329. };
  330. #define EE_BUF_LEN (256)
  331. #define AED_STR_LEN (512)
  332. #define CCCI_EXREC_OFFSET_OFFENDER 288
  333. /*=================================================================================*/
  334. /*Image type and header defination part*/
  335. /*=================================================================================*/
  336. #define C2K_IMG_PATH "/etc/firmware/modem_3_3g_n.img"
  337. enum {
  338. MD_BOOTING = 0,
  339. MD_READY,
  340. MD_EXCEPTION,
  341. MD_EXCEPTION_ONGOING,
  342. MD_RESET_ON_GOING,
  343. MD_OFF,
  344. };
  345. #ifndef CONFIG_EVDO_DT_VIA_SUPPORT
  346. union sdio_pio_int_sts_reg {
  347. struct {
  348. unsigned int fw_own_back:1;
  349. unsigned int rx_rdy:1;
  350. unsigned int tx_empty:1;
  351. unsigned int tx_under_thold:1;
  352. unsigned int tx_cmpl_cnt:3;
  353. unsigned int fw_int_indicator:1;
  354. unsigned int tx_overflow:1;
  355. unsigned int fw_int:7;
  356. unsigned int rx_pkt_len:16;
  357. } u;
  358. unsigned int raw_val;
  359. };
  360. union sdio_pio_int_mask_reg {
  361. struct {
  362. unsigned int fw_own_back_en:1;
  363. unsigned int rx_rdy_en:1;
  364. unsigned int tx_empty_en:1;
  365. unsigned int tx_under_thold_en:1;
  366. unsigned int resv0:3;
  367. unsigned int fw_int_indicator_en:1;
  368. unsigned int tx_overflow_en:1;
  369. unsigned int fw_int:7;
  370. unsigned int resv1:16;
  371. } u;
  372. unsigned int raw_val;
  373. };
  374. #define DEFAULT_BLK_SIZE 512
  375. #define RX_FIFO_SZ 2304 /*?? need to confirm. Haow */
  376. #define TX_FIFO_SZ 2080
  377. #define DEFAULT_TX_THOLD 4
  378. #define LOG_MD_DATA_READY_MSG 0xA0
  379. #define LOG_AP_DATA_DONE_MSG 0xA1
  380. struct smem_log_block {
  381. unsigned short id;
  382. unsigned int address;
  383. unsigned int length;
  384. unsigned short reserved[3];
  385. } __packed;
  386. #endif
  387. struct sdio_modem {
  388. struct sdio_modem_port *port[SDIO_TTY_NR];
  389. struct sdio_modem_ctrl_port *ctrl_port;
  390. struct sdio_func *func;
  391. struct sdio_msg *msg;
  392. unsigned char *trans_buffer;
  393. struct cbp_platform_data *cbp_data;
  394. struct semaphore sem;
  395. unsigned int data_length;
  396. unsigned int status;
  397. struct dump_debug_info debug_info;
  398. struct _ex_exception_log_t ex_info;
  399. spinlock_t status_lock;
  400. /*statistic */
  401. unsigned int tx_count;
  402. unsigned int rx_count;
  403. /*for USB rawbulk */
  404. struct work_struct dtr_work;
  405. struct work_struct dcd_query_work;
  406. struct kobject *c2k_kobj;
  407. #ifndef CONFIG_EVDO_DT_VIA_SUPPORT
  408. /*hw related settings */
  409. int fw_own;
  410. union sdio_pio_int_sts_reg int_sts;
  411. union sdio_pio_int_mask_reg int_mask;
  412. int int_clr_ctl;
  413. struct sdio_assemble_packet *as_packet;
  414. struct work_struct loopback_work;
  415. atomic_t tx_fifo_cnt;
  416. wait_queue_head_t wait_tx_done_q;
  417. /*because we use timer to send heart beat msg and force assert msg, so workqueue is needed. */
  418. struct work_struct poll_hb_work; /*used to send heart beat msg to c2k */
  419. struct work_struct force_assert_work; /*used to send force assert msg to c2k */
  420. struct work_struct smem_read_done_work; /*used to send smem-log-read-done msg to C2K */
  421. struct smem_log_block curr_log_blk;
  422. unsigned long long log_blk_stamp;
  423. struct timer_list heart_beat_timer; /*when this timer expired, we assume c2k md is dead, trigger EE */
  424. struct timer_list poll_timer; /*this timer is used to poll md's status every certain seconds */
  425. struct timer_list force_assert_timer; /*this timer is used to poll md's status every certain seconds */
  426. struct ccci_image_info img_info;
  427. #endif
  428. };
  429. #ifndef CONFIG_EVDO_DT_VIA_SUPPORT
  430. enum sdio_int_clr_ctl {
  431. SDIO_INT_CTL_RC = 0,
  432. SDIO_INT_CTL_W1C,
  433. };
  434. #endif
  435. extern int sdio_log_level;
  436. #define LOG_ERR 0
  437. #define LOG_INFO 1
  438. #define LOG_NOTICE 2
  439. #define LOG_NOTICE2 3
  440. #define LOG_DEBUG 4
  441. #define LOGPRT(lvl, x...) do { \
  442. if (lvl < (sdio_log_level + 1)) \
  443. pr_err("[C2K MODEM] " x); \
  444. } while (0)
  445. extern struct ccmni_dev_ops ccmni_ops;
  446. extern int modem_sdio_init(struct cbp_platform_data *pdata);
  447. extern void modem_sdio_exit(void);
  448. extern int modem_err_indication_usr(int revocery);
  449. extern int modem_ipoh_indication_usr(void);
  450. extern void dump_c2k_iram(void);
  451. extern void dump_c2k_iram_seg2(void);
  452. extern unsigned int get_c2k_reserve_mem_size(void);
  453. extern char *get_ap_platform(void);
  454. int sdio_modem_ccmni_send_pkt(int md_id, int tx_ch, void *data);
  455. /*
  456. int sdio_modem_get_ccmni_ch(int md_id, int ccmni_idx, struct ccmni_ch *channel);
  457. */
  458. extern void msdc_c2k_dump_int_register(void);
  459. /*use following function to push data to USB, for ETS*/
  460. extern int rawbulk_push_upstream_buffer(int transfer_id, const void *buffer,
  461. unsigned int length);
  462. /*use following function when modem attach success*/
  463. extern int rawbulk_bind_sdio_channel(int transfer_id);
  464. /*use following function when modem removed, after this, ETS will not receive any log*/
  465. extern void rawbulk_unbind_sdio_channel(int transfer_id);
  466. /*used by USB for ETS*/
  467. void modem_dtr_send(struct work_struct *work);
  468. #define USE_CCIF_INTR (0)
  469. #if USE_CCIF_INTR
  470. extern int ccif_notify_c2k(int ch_id);
  471. extern int dump_ccif(void);
  472. #endif
  473. extern phys_addr_t md3_mem_base;
  474. extern void mt_irq_dump_status(int irq);
  475. extern void mt_eint_dump_status(unsigned int eint);
  476. extern int c2k_modem_not_ready(void);
  477. #ifndef CONFIG_EVDO_DT_VIA_SUPPORT
  478. extern void c2k_sdio_install_eirq(void);
  479. extern void c2k_sdio_uninstall_eirq(void);
  480. #endif
  481. extern void SRC_trigger_signal(int i_on);
  482. #endif