isdbt_port_mtv23x.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /*
  2. *
  3. * drivers/media/tdmb/isdbt_port_mtv23x.h
  4. *
  5. * isdbt driver
  6. *
  7. * Copyright (C) (2014, Samsung Electronics)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation version 2.
  12. *
  13. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  14. * kind, whether express or implied; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #ifndef __ISDBT_PORT_MTV23x_H__
  20. #define __ISDBT_PORT_MTV23x_H__
  21. #include <linux/ioctl.h>
  22. #include "isdbt.h"
  23. #include "mtv23x.h"
  24. #include "mtv23x_internal.h"
  25. #define ISDBT_IOC_MAGIC 'R'
  26. /*
  27. */
  28. #define DMB_DEBUG_MSG_ENABLE
  29. #if defined(RTV_IF_SPI)
  30. /* Select debug options */
  31. //#define DEBUG_INTERRUPT
  32. //#define DEBUG_TSP_BUF
  33. #endif
  34. #define DMBERR(fmt, args...) \
  35. printk(KERN_ERR "MTV23x: %s(): " fmt, __func__, ## args)
  36. #ifdef DMB_DEBUG_MSG_ENABLE
  37. #define DMBMSG(fmt, args...) \
  38. printk(KERN_INFO "MTV23x: %s(): " fmt, __func__, ## args)
  39. #else
  40. #define DMBMSG(x...) do {} while (0)
  41. #endif
  42. /*############################################################################
  43. # File dump Configuration
  44. * TS dump filename: /data/local/isdbt_ts_FREQ.ts
  45. ############################################################################*/
  46. //#define _MTV_KERNEL_FILE_DUMP_ENABLE
  47. #ifdef _MTV_KERNEL_FILE_DUMP_ENABLE
  48. extern struct file *mtv_ts_filp;
  49. #endif
  50. #if defined(CONFIG_ISDBT_SPI)
  51. #define MAX_NUM_TSB_SEG 60
  52. /* TS Buffer Descriptor information. */
  53. struct TSB_DESC_INFO {
  54. /* Flag of operation enabled or not. */
  55. volatile int op_enabled; /* 0: disabled, 1: enabled */
  56. /* TSP buffer index which updated when read operation by App. */
  57. volatile int read_idx;
  58. /* TSP buffer index which update when write operation by Kernel. */
  59. volatile int write_idx;
  60. /* Mapping base address of TS buffer segments.
  61. The number of allocating elements was configured by application. */
  62. unsigned long seg_base[MAX_NUM_TSB_SEG];
  63. };
  64. /* TS Buffer control block. */
  65. struct TSB_CB_INFO {
  66. /* Index of available tsp segment to be write. */
  67. int avail_seg_idx;
  68. /* Index of available tsp buffer to be write. */
  69. int avail_write_tspb_idx;
  70. /* Index of tsp segment to be enqueued. */
  71. int enqueue_seg_idx;
  72. /* Number of buffering TSPs per segment configured by App. */
  73. int num_tsp_per_seg;
  74. /* Number of buffering TSPs in the kernel shared memory
  75. configured by App. */
  76. int num_total_tsp;
  77. /* Number of shared memory segments. */
  78. int num_total_seg;
  79. unsigned int desc_size;
  80. unsigned int seg_size;
  81. /* The pointer to the address of TSB descriptor
  82. which shared informations to be allocated. */
  83. struct TSB_DESC_INFO *tsbd;
  84. bool seg_bufs_allocated;
  85. bool mmap_completed;
  86. /* The pointer to the address of TS buffer segments to be allocated. */
  87. unsigned char *seg_buf[MAX_NUM_TSB_SEG];
  88. };
  89. #endif /* #if defined(CONFIG_ISDBT_SPI) */
  90. /* ISDBT drvier Control Block */
  91. struct MTV23x_CB {
  92. int pwr_en_pin_no; /* Pin number of POWER-EN */
  93. #if defined(RTV_IF_TSIF_0) || defined(RTV_IF_TSIF_1) || defined(RTV_IF_SPI_SLAVE)
  94. #ifdef CONFIG_ISDBT_CAMIF
  95. struct TSB_CB_INFO tsb_cb;
  96. unsigned int intr_size[MAX_NUM_RTV_SERVICE]; /* Interrupt size */
  97. unsigned int cfged_tsp_chunk_size; /* Configured TSP chunk size */
  98. #endif /* CONFIG_ISDBT_CAMIF */
  99. #endif
  100. #if defined(RTV_IF_SPI) || defined(RTV_IF_SPI_TSIFx)
  101. #ifndef RTV_IF_SPI_TSIFx
  102. int irq_pin_no; /* IRQ number */
  103. struct TSB_CB_INFO tsb_cb;
  104. unsigned int intr_size[MAX_NUM_RTV_SERVICE]; /* Interrupt size */
  105. unsigned int cfged_tsp_chunk_size; /* Configured TSP chunk size */
  106. #endif /* #ifndef RTV_IF_SPI_TSIFx */
  107. #endif
  108. struct mutex ioctl_lock;
  109. volatile bool is_power_on;
  110. unsigned int freq_khz;
  111. volatile bool tsout_enabled;
  112. enum E_RTV_SERVICE_TYPE cfged_svc; /* Configured service type */
  113. #ifdef DEBUG_INTERRUPT
  114. unsigned long invalid_intr_cnt;
  115. unsigned long level_intr_cnt;
  116. unsigned long ovf_intr_cnt;
  117. unsigned long udf_intr_cnt;
  118. #endif
  119. #ifdef DEBUG_TSP_BUF
  120. unsigned int max_alloc_seg_cnt;
  121. unsigned int max_enqueued_seg_cnt;
  122. unsigned int max_enqueued_tsp_cnt;
  123. unsigned long alloc_tspb_err_cnt;
  124. #endif
  125. };
  126. extern struct MTV23x_CB *mtv23x_cb_ptr;
  127. /* The size of TSB descriptor for mmap */
  128. #define MAX_TSB_DESC_SIZE PAGE_ALIGN(sizeof(struct TSB_DESC_INFO))
  129. /* The size of TSB segment for mmap */
  130. #define MAX_TSB_SEG_SIZE PAGE_ALIGN(188 * 16)
  131. #define TOTAL_TSB_MAPPING_SIZE\
  132. (MAX_TSB_DESC_SIZE + MAX_NUM_TSB_SEG*MAX_TSB_SEG_SIZE)
  133. static inline int mtv_ts_dump_kfile_write(char *buf, size_t len)
  134. {
  135. #ifdef _MTV_KERNEL_FILE_DUMP_ENABLE
  136. mm_segment_t oldfs;
  137. struct file *filp;
  138. int ret = 0;
  139. if (mtv_ts_filp != NULL) {
  140. filp = mtv_ts_filp;
  141. oldfs = get_fs();
  142. set_fs(KERNEL_DS);
  143. ret = filp->f_op->write(filp, buf, len, &filp->f_pos);
  144. set_fs(oldfs);
  145. if (!ret)
  146. DMBERR("File write error (%d)\n", ret);
  147. }
  148. return ret;
  149. #else
  150. return 0;
  151. #endif
  152. }
  153. static inline void mtv_ts_dump_kfile_close(void)
  154. {
  155. #ifdef _MTV_KERNEL_FILE_DUMP_ENABLE
  156. if (mtv_ts_filp != NULL) {
  157. filp_close(mtv_ts_filp, NULL);
  158. mtv_ts_filp = NULL;
  159. }
  160. #endif
  161. }
  162. static inline int mtv_ts_dump_kfile_open(unsigned int channel)
  163. {
  164. #ifdef _MTV_KERNEL_FILE_DUMP_ENABLE
  165. char fname[32];
  166. struct file *filp = NULL;
  167. if (mtv_ts_filp == NULL) {
  168. sprintf(fname, "/data/local/isdbt_ts_%u.ts", channel);
  169. filp = filp_open(fname, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR);
  170. if (IS_ERR(filp)) {
  171. filp = NULL;
  172. DMBERR("File open error: %s!\n", fname);
  173. return PTR_ERR(filp);
  174. }
  175. mtv_ts_filp = filp;
  176. DMBMSG("Kernel dump file opened(%s)\n", fname);
  177. } else {
  178. DMBERR("Already TS file opened! Should closed!\n");
  179. return -1;
  180. }
  181. #endif
  182. return 0;
  183. }
  184. #ifdef DEBUG_TSP_BUF
  185. static INLINE void reset_debug_tspb_stat(void)
  186. {
  187. mtv23x_cb_ptr->max_alloc_seg_cnt = 0;
  188. mtv23x_cb_ptr->max_enqueued_seg_cnt = 0;
  189. mtv23x_cb_ptr->max_enqueued_tsp_cnt = 0;
  190. mtv23x_cb_ptr->alloc_tspb_err_cnt = 0;
  191. }
  192. #define RESET_DEBUG_TSPB_STAT reset_debug_tspb_stat()
  193. #else
  194. #define RESET_DEBUG_TSPB_STAT do {} while (0)
  195. #endif /* #ifdef DEBUG_TSP_BUF*/
  196. #ifdef DEBUG_INTERRUPT
  197. static inline void reset_debug_interrupt_stat(void)
  198. {
  199. mtv23x_cb_ptr->invalid_intr_cnt = 0;
  200. mtv23x_cb_ptr->level_intr_cnt = 0;
  201. mtv23x_cb_ptr->ovf_intr_cnt = 0;
  202. mtv23x_cb_ptr->udf_intr_cnt = 0;
  203. }
  204. #define RESET_DEBUG_INTR_STAT reset_debug_interrupt_stat()
  205. #define DMB_LEVEL_INTR_INC mtv23x_cb_ptr->level_intr_cnt++;
  206. #define DMB_INV_INTR_INC mtv23x_cb_ptr->invalid_intr_cnt++;
  207. #define DMB_OVF_INTR_INC mtv23x_cb_ptr->ovf_intr_cnt++;
  208. #define DMB_UNF_INTR_INC mtv23x_cb_ptr->udf_intr_cnt++;
  209. #else
  210. #define RESET_DEBUG_INTR_STAT do {} while (0)
  211. #define DMB_LEVEL_INTR_INC do {} while (0)
  212. #define DMB_INV_INTR_INC do {} while (0)
  213. #define DMB_OVF_INTR_INC do {} while (0)
  214. #define DMB_UNF_INTR_INC do {} while (0)
  215. #endif /* #ifdef DEBUG_INTERRUPT*/
  216. #if defined(DEBUG_TSP_BUF) && defined(DEBUG_INTERRUPT)
  217. #define SHOW_ISDBT_DEBUG_STAT \
  218. do { \
  219. DMBMSG("ovf(%ld), unf(%ld), inv(%ld), level(%ld),\n\
  220. \t max_alloc_seg(%u), max_enqueued_seg(%u),\n\
  221. \t max_enqueued_tsp(%u), alloc_err(%ld)\n",\
  222. mtv23x_cb_ptr->ovf_intr_cnt, mtv23x_cb_ptr->udf_intr_cnt,\
  223. mtv23x_cb_ptr->invalid_intr_cnt, mtv23x_cb_ptr->level_intr_cnt,\
  224. mtv23x_cb_ptr->max_alloc_seg_cnt,\
  225. mtv23x_cb_ptr->max_enqueued_seg_cnt,\
  226. mtv23x_cb_ptr->max_enqueued_tsp_cnt,\
  227. mtv23x_cb_ptr->alloc_tspb_err_cnt);\
  228. } while (0)
  229. #elif !defined(DEBUG_TSP_BUF) && defined(DEBUG_INTERRUPT)
  230. #define SHOW_ISDBT_DEBUG_STAT \
  231. do { \
  232. DMBMSG("ovf(%ld), unf(%ld), inv(%ld), level(%ld)\n",\
  233. mtv23x_cb_ptr->ovf_intr_cnt, mtv23x_cb_ptr->udf_intr_cnt,\
  234. mtv23x_cb_ptr->invalid_intr_cnt, mtv23x_cb_ptr->level_intr_cnt);\
  235. } while (0)
  236. #elif defined(DEBUG_TSP_BUF) && !defined(DEBUG_INTERRUPT)
  237. #define SHOW_ISDBT_DEBUG_STAT \
  238. do { \
  239. DMBMSG("max_alloc_seg(%u), max_enqueued_seg(%u) max_enqueued_tsp(%u), alloc_err(%ld)\n",\
  240. mtv23x_cb_ptr->max_alloc_seg_cnt,\
  241. mtv23x_cb_ptr->max_enqueued_seg_cnt,\
  242. mtv23x_cb_ptr->max_enqueued_tsp_cnt,\
  243. mtv23x_cb_ptr->alloc_tspb_err_cnt);\
  244. } while (0)
  245. #elif !defined(DEBUG_TSP_BUF) && !defined(DEBUG_INTERRUPT)
  246. #define SHOW_ISDBT_DEBUG_STAT do {} while (0)
  247. #endif
  248. /*============================================================================
  249. * Test IO control commands(0~10)
  250. *==========================================================================*/
  251. #define IOCTL_TEST_MTV_POWER_ON _IO(ISDBT_IOC_MAGIC, 0)
  252. #define IOCTL_TEST_MTV_POWER_OFF _IO(ISDBT_IOC_MAGIC, 1)
  253. #define MAX_NUM_MTV_REG_READ_BUF (16 * 188)
  254. typedef struct {
  255. unsigned int page; /* page value */
  256. unsigned int addr; /* input */
  257. unsigned int write_data;
  258. unsigned long param1;
  259. unsigned int read_cnt;
  260. unsigned char read_data[MAX_NUM_MTV_REG_READ_BUF]; /* output */
  261. } IOCTL_REG_ACCESS_INFO;
  262. #define IOCTL_TEST_REG_SINGLE_READ _IOWR(ISDBT_IOC_MAGIC, 3, IOCTL_REG_ACCESS_INFO)
  263. #define IOCTL_TEST_REG_BURST_READ _IOWR(ISDBT_IOC_MAGIC, 4, IOCTL_REG_ACCESS_INFO)
  264. #define IOCTL_TEST_REG_WRITE _IOW(ISDBT_IOC_MAGIC, 5, IOCTL_REG_ACCESS_INFO)
  265. #define IOCTL_TEST_REG_SPI_MEM_READ _IOWR(ISDBT_IOC_MAGIC, 6, IOCTL_REG_ACCESS_INFO)
  266. #define IOCTL_TEST_REG_ONLY_SPI_MEM_READ _IOWR(ISDBT_IOC_MAGIC, 7, IOCTL_REG_ACCESS_INFO)
  267. typedef struct {
  268. unsigned int pin; /* input */
  269. unsigned int value; /* input for write. output for read. */
  270. } IOCTL_GPIO_ACCESS_INFO;
  271. #define IOCTL_TEST_GPIO_SET _IOW(ISDBT_IOC_MAGIC, 6, IOCTL_GPIO_ACCESS_INFO)
  272. #define IOCTL_TEST_GPIO_GET _IOWR(ISDBT_IOC_MAGIC, 7, IOCTL_GPIO_ACCESS_INFO)
  273. /*============================================================================
  274. * TDMB IO control commands(10 ~ 29)
  275. *===========================================================================*/
  276. typedef struct {
  277. int country_band_type; // for MTV222
  278. int bandwidth; // enum E_RTV_BANDWIDTH_TYPE
  279. unsigned int spi_intr_size[7]; // input
  280. int tuner_err_code; // ouput
  281. } IOCTL_ISDBT_POWER_ON_INFO;
  282. typedef struct {
  283. unsigned int freq_khz; // input
  284. unsigned int subch_id; // input
  285. int svc_type; // input: enum E_RTV_SERVICE_TYPE
  286. int bandwidth; // input: enum E_RTV_BANDWIDTH_TYPE
  287. int tuner_err_code; // ouput
  288. } IOCTL_ISDBT_SCAN_INFO;
  289. typedef struct {
  290. unsigned int freq_khz; // input
  291. unsigned int subch_id; // input
  292. int svc_type; // input: enum E_RTV_SERVICE_TYPE
  293. int bandwidth; // input: enum E_RTV_BANDWIDTH_TYPE
  294. int tuner_err_code; // ouput
  295. } IOCTL_ISDBT_SET_CH_INFO;
  296. typedef struct {
  297. unsigned int lock_mask;
  298. unsigned int ant_level;
  299. unsigned int ber; // output
  300. unsigned int cnr; // output
  301. unsigned int per; // output
  302. int rssi; // output
  303. } IOCTL_ISDBT_SIGNAL_INFO;
  304. typedef struct {
  305. unsigned int lock_mask;
  306. int rssi;
  307. unsigned int ber_layer_A;
  308. unsigned int ber_layer_B;
  309. unsigned int per_layer_A;
  310. unsigned int per_layer_B;
  311. unsigned int cnr_layer_A;
  312. unsigned int cnr_layer_B;
  313. unsigned int ant_level_layer_A;
  314. unsigned int ant_level_layer_B;
  315. } IOCTL_ISDBT_SIGNAL_QUAL_INFO;
  316. #define IOCTL_ISDBT_POWER_ON _IOWR(ISDBT_IOC_MAGIC, 10, IOCTL_ISDBT_POWER_ON_INFO)
  317. #define IOCTL_ISDBT_POWER_OFF _IO(ISDBT_IOC_MAGIC, 11)
  318. #define IOCTL_ISDBT_SCAN_CHANNEL _IOWR(ISDBT_IOC_MAGIC,12, IOCTL_ISDBT_SCAN_INFO)
  319. #define IOCTL_ISDBT_SET_CHANNEL _IOWR(ISDBT_IOC_MAGIC,13, IOCTL_ISDBT_SET_CH_INFO)
  320. #define IOCTL_ISDBT_START_TS _IO(ISDBT_IOC_MAGIC, 14)
  321. #define IOCTL_ISDBT_STOP_TS _IO(ISDBT_IOC_MAGIC, 15)
  322. #define IOCTL_ISDBT_GET_LOCK_STATUS _IOR(ISDBT_IOC_MAGIC,16, unsigned int)
  323. #define IOCTL_ISDBT_GET_SIGNAL_INFO _IOR(ISDBT_IOC_MAGIC,17, IOCTL_ISDBT_SIGNAL_INFO)
  324. #define IOCTL_ISDBT_SUSPEND _IO(ISDBT_IOC_MAGIC, 18)
  325. #define IOCTL_ISDBT_RESUME _IO(ISDBT_IOC_MAGIC, 19)
  326. typedef struct {
  327. unsigned int ber_layer_A;
  328. unsigned int ber_layer_B;
  329. unsigned int per_layer_A;
  330. unsigned int per_layer_B;
  331. } IOCTL_ISDBT_BER_PER_INFO;
  332. #define IOCTL_ISDBT_GET_BER_PER_INFO _IOR(ISDBT_IOC_MAGIC, 20, IOCTL_ISDBT_BER_PER_INFO)
  333. #define IOCTL_ISDBT_GET_RSSI _IOR(ISDBT_IOC_MAGIC, 21, int)
  334. #define IOCTL_ISDBT_GET_CNR _IOR(ISDBT_IOC_MAGIC, 22, int)
  335. #define IOCTL_ISDBT_GET_SIGNAL_QUAL_INFO _IOR(ISDBT_IOC_MAGIC, 23, IOCTL_ISDBT_SIGNAL_QUAL_INFO)
  336. #endif /* __ISDBT_PORT_MTV23x_H__*/