tdmb_port_fc8050.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. *
  3. * drivers/media/tdmb/tdmb_port_fc8050.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_fc8050.h"
  36. static bool fc8050_on_air;
  37. static bool fc8050_pwr_on;
  38. static bool __get_ensemble_info(struct ensemble_info_type *e_info
  39. , unsigned long freq)
  40. {
  41. int i;
  42. int j;
  43. int sub_i = 0;
  44. int cnt;
  45. const char *ensembleName = NULL;
  46. struct sub_channel_info_type *fci_sub_info;
  47. DPRINTK("%s : freq(%ld)\n", __func__, freq);
  48. e_info->tot_sub_ch
  49. = dmb_drv_get_dmb_sub_ch_cnt() + dmb_drv_get_dab_sub_ch_cnt();
  50. DPRINTK("total subchannel number : %d\n", e_info->tot_sub_ch);
  51. if (e_info->tot_sub_ch > 0) {
  52. ensembleName = (char *)dmb_drv_get_ensemble_label();
  53. if (ensembleName)
  54. strncpy((char *)e_info->ensem_label,
  55. (char *)ensembleName,
  56. ENSEMBLE_LABEL_MAX);
  57. e_info->ensem_freq = freq;
  58. for (i = 0; i < 2; i++) {
  59. cnt = (i == 0)
  60. ? dmb_drv_get_dmb_sub_ch_cnt()
  61. : dmb_drv_get_dab_sub_ch_cnt();
  62. for (j = 0; j < cnt; j++, sub_i++) {
  63. fci_sub_info = (i == 0)
  64. ? dmb_drv_get_fic_dmb(j)
  65. : dmb_drv_get_fic_dab(j);
  66. e_info->ensem_id
  67. = fci_sub_info->uiEnsembleID;
  68. e_info->sub_ch[sub_i].sub_ch_id
  69. = fci_sub_info->ucSubchID;
  70. e_info->sub_ch[sub_i].start_addr
  71. = fci_sub_info->uiStartAddress;
  72. e_info->sub_ch[sub_i].tmid
  73. = fci_sub_info->ucTMId;
  74. e_info->sub_ch[sub_i].svc_type
  75. = fci_sub_info->ucServiceType;
  76. e_info->sub_ch[sub_i].svc_id
  77. = fci_sub_info->ulServiceID;
  78. e_info->sub_ch[sub_i].scids
  79. = fci_sub_info->scids;
  80. e_info->sub_ch[sub_i].ecc
  81. = fci_sub_info->ecc;
  82. if (i == 0)
  83. memcpy(
  84. e_info->sub_ch[sub_i].svc_label,
  85. dmb_drv_get_sub_ch_dmb_label(j),
  86. SVC_LABEL_MAX);
  87. else
  88. memcpy(e_info->sub_ch[sub_i].svc_label,
  89. dmb_drv_get_sub_ch_dab_label(j),
  90. SVC_LABEL_MAX);
  91. }
  92. }
  93. return true;
  94. } else {
  95. return false;
  96. }
  97. }
  98. static void fc8050_power_off(void)
  99. {
  100. DPRINTK("call TDMB_PowerOff !\n");
  101. if (fc8050_pwr_on) {
  102. fc8050_on_air = false;
  103. dmb_drv_deinit();
  104. tdmb_control_irq(false);
  105. tdmb_control_gpio(false);
  106. fc8050_pwr_on = false;
  107. }
  108. }
  109. static bool fc8050_power_on(void)
  110. {
  111. DPRINTK("fc8050_power_on\n");
  112. if (fc8050_pwr_on) {
  113. return true;
  114. } else {
  115. tdmb_control_gpio(true);
  116. if (dmb_drv_init(tdmb_get_if_handle()) == TDMB_FAIL) {
  117. tdmb_control_gpio(false);
  118. return false;
  119. } else {
  120. tdmb_control_irq(true);
  121. fc8050_pwr_on = true;
  122. return true;
  123. }
  124. }
  125. }
  126. static void fc8050_get_dm(struct tdmb_dm *info)
  127. {
  128. if (fc8050_pwr_on == true && fc8050_on_air == true) {
  129. info->rssi = dmb_drv_get_rssi();
  130. info->ber = dmb_drv_get_ber();
  131. info->antenna = dmb_drv_get_ant();
  132. info->per = 0;
  133. } else {
  134. info->rssi = 100;
  135. info->ber = 2000;
  136. info->per = 0;
  137. info->antenna = 0;
  138. }
  139. }
  140. static bool fc8050_set_ch(unsigned long freq,
  141. unsigned char sub_ch_id,
  142. bool factory_test)
  143. {
  144. unsigned long freq_temp = freq / 1000;
  145. unsigned char sub_ch_id_temp = sub_ch_id % 1000;
  146. unsigned char svc_type_temp = 0x0;
  147. if (sub_ch_id_temp >= 64) {
  148. sub_ch_id_temp -= 64;
  149. svc_type_temp = 0x18;
  150. }
  151. DPRINTK("fc8050_set_ch freq:%ld, sub_ch_id:%d, svc_type:%d\n",
  152. freq_temp, sub_ch_id_temp, svc_type_temp);
  153. fc8050_on_air = false;
  154. if (factory_test) {
  155. if (dmb_drv_set_ch_factory(freq_temp, sub_ch_id_temp, \
  156. svc_type_temp) == 1) {
  157. DPRINTK("dmb_drv_set_ch_factory Success\n");
  158. fc8050_on_air = true;
  159. return true;
  160. } else {
  161. DPRINTK("dmb_drv_set_ch_factory Fail\n");
  162. return false;
  163. }
  164. } else {
  165. if (dmb_drv_set_ch(freq_temp, sub_ch_id_temp, \
  166. svc_type_temp) == 1) {
  167. DPRINTK("dmb_drv_set_ch Success\n");
  168. fc8050_on_air = true;
  169. return true;
  170. } else {
  171. DPRINTK("dmb_drv_set_ch Fail\n");
  172. return false;
  173. }
  174. }
  175. }
  176. static bool fc8050_scan_ch(struct ensemble_info_type *e_info
  177. , unsigned long freq)
  178. {
  179. if (fc8050_pwr_on == false || e_info == NULL)
  180. return false;
  181. else if (dmb_drv_scan_ch((freq / 1000)) == TDMB_SUCCESS)
  182. return __get_ensemble_info(e_info, freq);
  183. else
  184. return false;
  185. }
  186. static unsigned long fc8050_int_size(void)
  187. {
  188. return 188*20;
  189. }
  190. static struct tdmb_drv_func fci_fc8050_drv_func = {
  191. .power_on = fc8050_power_on,
  192. .power_off = fc8050_power_off,
  193. .scan_ch = fc8050_scan_ch,
  194. .get_dm = fc8050_get_dm,
  195. .set_ch = fc8050_set_ch,
  196. .pull_data = dmb_drv_isr,
  197. .get_int_size = fc8050_int_size,
  198. };
  199. struct tdmb_drv_func *fc8050_drv_func(void)
  200. {
  201. DPRINTK("tdmb_get_drv_func : fc8050\n");
  202. return &fci_fc8050_drv_func;
  203. }