tdmb_port_fc8080.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. *
  3. * drivers/media/tdmb/tdmb_port_fc8080.c
  4. *
  5. * tdmb driver
  6. *
  7. * Copyright (C) (2011, 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. #include <linux/kernel.h>
  20. #include <linux/errno.h>
  21. #include <linux/device.h>
  22. #include <linux/init.h>
  23. #include <linux/types.h>
  24. #include <linux/fcntl.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/irq.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/io.h>
  29. #include <linux/fs.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/time.h>
  32. #include <linux/timer.h>
  33. #include <linux/vmalloc.h>
  34. #include "tdmb.h"
  35. #include "dmbdrv_wrap_fc8080.h"
  36. static bool fc8080_on_air;
  37. static bool fc8080_pwr_on;
  38. #if defined(CONFIG_TDMB_TSIF_SLSI) || defined(CONFIG_TDMB_TSIF_QC)
  39. #define FIC_PACKET_COUNT 3
  40. #define MSC_PACKET_COUNT 16
  41. #endif
  42. /* #define TDMB_DEBUG_SCAN */
  43. #ifdef TDMB_DEBUG_SCAN
  44. static void __print_ensemble_info(struct ensemble_info_type *e_info)
  45. {
  46. int i = 0;
  47. DPRINTK("ensem_freq(%ld)\n", e_info->ensem_freq);
  48. DPRINTK("ensem_label(%s)\n", e_info->ensem_label);
  49. for (i = 0; i < e_info->tot_sub_ch; i++) {
  50. DPRINTK("sub_ch_id(0x%x)\n", e_info->sub_ch[i].sub_ch_id);
  51. DPRINTK("start_addr(0x%x)\n", e_info->sub_ch[i].start_addr);
  52. DPRINTK("tmid(0x%x)\n", e_info->sub_ch[i].tmid);
  53. DPRINTK("svc_type(0x%x)\n", e_info->sub_ch[i].svc_type);
  54. DPRINTK("svc_label(%s)\n", e_info->sub_ch[i].svc_label);
  55. DPRINTK("scids(0x%x)\n", e_info->sub_ch[i].scids);
  56. DPRINTK("ecc(0x%x)\n", e_info->sub_ch[i].ecc);
  57. }
  58. }
  59. #endif
  60. static bool __get_ensemble_info(struct ensemble_info_type *e_info
  61. , unsigned long freq)
  62. {
  63. struct sub_channel_info_type *fci_sub_info;
  64. DPRINTK("%s : freq(%ld)\n", __func__, freq);
  65. e_info->tot_sub_ch
  66. = dmb_drv_get_dmb_sub_ch_cnt() + dmb_drv_get_dab_sub_ch_cnt();
  67. DPRINTK("total subchannel number : %d\n", e_info->tot_sub_ch);
  68. if (e_info->tot_sub_ch > 0) {
  69. int i;
  70. int j;
  71. int sub_i = 0;
  72. const char *ensembleName = NULL;
  73. ensembleName = (char *)dmb_drv_get_ensemble_label();
  74. if (ensembleName)
  75. strncpy((char *)e_info->ensem_label,
  76. (char *)ensembleName,
  77. ENSEMBLE_LABEL_MAX);
  78. e_info->ensem_freq = freq;
  79. for (i = 0; i < 2; i++) {
  80. int cnt;
  81. cnt = (i == 0)
  82. ? dmb_drv_get_dmb_sub_ch_cnt()
  83. : dmb_drv_get_dab_sub_ch_cnt();
  84. for (j = 0; j < cnt; j++, sub_i++) {
  85. fci_sub_info = (i == 0)
  86. ? dmb_drv_get_fic_dmb(j)
  87. : dmb_drv_get_fic_dab(j);
  88. e_info->ensem_id
  89. = fci_sub_info->uiEnsembleID;
  90. e_info->sub_ch[sub_i].sub_ch_id
  91. = fci_sub_info->ucSubchID;
  92. e_info->sub_ch[sub_i].start_addr
  93. = fci_sub_info->uiStartAddress;
  94. e_info->sub_ch[sub_i].tmid
  95. = fci_sub_info->ucTMId;
  96. e_info->sub_ch[sub_i].svc_type
  97. = fci_sub_info->ucServiceType;
  98. e_info->sub_ch[sub_i].svc_id
  99. = fci_sub_info->ulServiceID;
  100. e_info->sub_ch[sub_i].scids
  101. = fci_sub_info->scids;
  102. e_info->sub_ch[sub_i].ecc
  103. = fci_sub_info->ecc;
  104. if (i == 0)
  105. memcpy(
  106. e_info->sub_ch[sub_i].svc_label,
  107. dmb_drv_get_sub_ch_dmb_label(j),
  108. SVC_LABEL_MAX);
  109. else
  110. memcpy(e_info->sub_ch[sub_i].svc_label,
  111. dmb_drv_get_sub_ch_dab_label(j),
  112. SVC_LABEL_MAX);
  113. }
  114. }
  115. #ifdef TDMB_DEBUG_SCAN
  116. __print_ensemble_info(e_info);
  117. #endif
  118. return true;
  119. } else {
  120. return false;
  121. }
  122. }
  123. static void fc8080_power_off(void)
  124. {
  125. DPRINTK("%s %d\n", __func__, fc8080_pwr_on);
  126. if (fc8080_pwr_on) {
  127. fc8080_on_air = false;
  128. dmb_drv_deinit();
  129. #if defined(CONFIG_TDMB_TSIF_SLSI) || defined(CONFIG_TDMB_TSIF_QC)
  130. tdmb_tsi_stop();
  131. #else
  132. tdmb_control_irq(false);
  133. #endif
  134. tdmb_control_gpio(false);
  135. fc8080_pwr_on = false;
  136. }
  137. }
  138. static bool fc8080_power_on(void)
  139. {
  140. DPRINTK("%s\n", __func__);
  141. if (fc8080_pwr_on) {
  142. return true;
  143. } else {
  144. tdmb_control_gpio(true);
  145. if (dmb_drv_init(tdmb_get_if_handle()) == TDMB_FAIL) {
  146. tdmb_control_gpio(false);
  147. return false;
  148. } else {
  149. #if !defined(CONFIG_TDMB_TSIF_SLSI) && !defined(CONFIG_TDMB_TSIF_QC)
  150. tdmb_control_irq(true);
  151. #endif
  152. fc8080_pwr_on = true;
  153. return true;
  154. }
  155. }
  156. }
  157. static void fc8080_get_dm(struct tdmb_dm *info)
  158. {
  159. if (fc8080_pwr_on == true && fc8080_on_air == true) {
  160. info->rssi = dmb_drv_get_rssi();
  161. info->antenna = dmb_drv_get_ant();
  162. info->ber = dmb_drv_get_ber();
  163. info->per = 0;
  164. } else {
  165. info->rssi = 100;
  166. info->ber = 2000;
  167. info->per = 0;
  168. info->antenna = 0;
  169. }
  170. }
  171. static bool fc8080_set_ch(unsigned long freq,
  172. unsigned char sub_ch_id,
  173. bool factory_test)
  174. {
  175. unsigned long freq_temp = freq / 1000;
  176. unsigned char sub_ch_id_temp = sub_ch_id % 1000;
  177. unsigned char svc_type_temp = 0x0;
  178. if (sub_ch_id_temp >= 64) {
  179. sub_ch_id_temp -= 64;
  180. svc_type_temp = 0x18;
  181. }
  182. DPRINTK("fc8080_set_ch freq:%ld, sub_ch_id:%d, svc_type:%d\n",
  183. freq_temp, sub_ch_id_temp, svc_type_temp);
  184. fc8080_on_air = false;
  185. #if defined(CONFIG_TDMB_TSIF_SLSI) || defined(CONFIG_TDMB_TSIF_QC)
  186. tdmb_tsi_stop();
  187. if (tdmb_tsi_start(dmb_drv_isr, MSC_PACKET_COUNT) != 0)
  188. return false;
  189. #endif
  190. if (factory_test) {
  191. if (dmb_drv_set_ch_factory(freq_temp, sub_ch_id_temp, \
  192. svc_type_temp) == 1) {
  193. DPRINTK("dmb_drv_set_ch_factory Success\n");
  194. fc8080_on_air = true;
  195. return true;
  196. } else {
  197. DPRINTK("dmb_drv_set_ch_factory Fail\n");
  198. return false;
  199. }
  200. } else {
  201. if (dmb_drv_set_ch(freq_temp, sub_ch_id_temp, \
  202. svc_type_temp) == 1) {
  203. DPRINTK("dmb_drv_set_ch Success\n");
  204. fc8080_on_air = true;
  205. return true;
  206. } else {
  207. DPRINTK("dmb_drv_set_ch Fail\n");
  208. return false;
  209. }
  210. }
  211. }
  212. static bool fc8080_scan_ch(struct ensemble_info_type *e_info
  213. , unsigned long freq)
  214. {
  215. bool ret = false;
  216. if (fc8080_pwr_on == false || e_info == NULL)
  217. return ret;
  218. else {
  219. #if defined(CONFIG_TDMB_TSIF_SLSI) || defined(CONFIG_TDMB_TSIF_QC)
  220. tdmb_tsi_stop();
  221. if (tdmb_tsi_start(dmb_drv_isr, FIC_PACKET_COUNT) != 0)
  222. return false;
  223. #endif
  224. if (dmb_drv_scan_ch((freq / 1000)) == TDMB_SUCCESS)
  225. ret = __get_ensemble_info(e_info, freq);
  226. else
  227. ret = false;
  228. return ret;
  229. }
  230. }
  231. static unsigned long fc8080_int_size(void)
  232. {
  233. #if defined(CONFIG_TDMB_TSIF_SLSI) || defined(CONFIG_TDMB_TSIF_QC)
  234. return 188*16;
  235. #else
  236. return 188*40;
  237. #endif
  238. }
  239. static struct tdmb_drv_func fci_fc8080_drv_func = {
  240. .power_on = fc8080_power_on,
  241. .power_off = fc8080_power_off,
  242. .scan_ch = fc8080_scan_ch,
  243. .get_dm = fc8080_get_dm,
  244. .set_ch = fc8080_set_ch,
  245. #if !defined(CONFIG_TDMB_TSIF_SLSI) && !defined(CONFIG_TDMB_TSIF_QC)
  246. .pull_data = dmb_drv_isr,
  247. #endif
  248. .get_int_size = fc8080_int_size,
  249. };
  250. struct tdmb_drv_func *fc8080_drv_func(void)
  251. {
  252. DPRINTK("tdmb_get_drv_func : fc8080\n");
  253. return &fci_fc8080_drv_func;
  254. }