firedtv-fe.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * FireDTV driver (formerly known as FireSAT)
  3. *
  4. * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
  5. * Copyright (C) 2008 Henrik Kurelid <henrik@kurelid.se>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. */
  12. #include <linux/device.h>
  13. #include <linux/errno.h>
  14. #include <linux/kernel.h>
  15. #include <linux/string.h>
  16. #include <linux/types.h>
  17. #include <media/dvb_frontend.h>
  18. #include "firedtv.h"
  19. static int fdtv_dvb_init(struct dvb_frontend *fe)
  20. {
  21. struct firedtv *fdtv = fe->sec_priv;
  22. int err;
  23. /* FIXME - allocate free channel at IRM */
  24. fdtv->isochannel = fdtv->adapter.num;
  25. err = cmp_establish_pp_connection(fdtv, fdtv->subunit,
  26. fdtv->isochannel);
  27. if (err) {
  28. dev_err(fdtv->device,
  29. "could not establish point to point connection\n");
  30. return err;
  31. }
  32. return fdtv_start_iso(fdtv);
  33. }
  34. static int fdtv_sleep(struct dvb_frontend *fe)
  35. {
  36. struct firedtv *fdtv = fe->sec_priv;
  37. fdtv_stop_iso(fdtv);
  38. cmp_break_pp_connection(fdtv, fdtv->subunit, fdtv->isochannel);
  39. fdtv->isochannel = -1;
  40. return 0;
  41. }
  42. #define LNBCONTROL_DONTCARE 0xff
  43. static int fdtv_diseqc_send_master_cmd(struct dvb_frontend *fe,
  44. struct dvb_diseqc_master_cmd *cmd)
  45. {
  46. struct firedtv *fdtv = fe->sec_priv;
  47. return avc_lnb_control(fdtv, LNBCONTROL_DONTCARE, LNBCONTROL_DONTCARE,
  48. LNBCONTROL_DONTCARE, 1, cmd);
  49. }
  50. static int fdtv_diseqc_send_burst(struct dvb_frontend *fe,
  51. enum fe_sec_mini_cmd minicmd)
  52. {
  53. return 0;
  54. }
  55. static int fdtv_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
  56. {
  57. struct firedtv *fdtv = fe->sec_priv;
  58. fdtv->tone = tone;
  59. return 0;
  60. }
  61. static int fdtv_set_voltage(struct dvb_frontend *fe,
  62. enum fe_sec_voltage voltage)
  63. {
  64. struct firedtv *fdtv = fe->sec_priv;
  65. fdtv->voltage = voltage;
  66. return 0;
  67. }
  68. static int fdtv_read_status(struct dvb_frontend *fe, enum fe_status *status)
  69. {
  70. struct firedtv *fdtv = fe->sec_priv;
  71. struct firedtv_tuner_status stat;
  72. if (avc_tuner_status(fdtv, &stat))
  73. return -EINVAL;
  74. if (stat.no_rf)
  75. *status = 0;
  76. else
  77. *status = FE_HAS_SIGNAL | FE_HAS_VITERBI | FE_HAS_SYNC |
  78. FE_HAS_CARRIER | FE_HAS_LOCK;
  79. return 0;
  80. }
  81. static int fdtv_read_ber(struct dvb_frontend *fe, u32 *ber)
  82. {
  83. struct firedtv *fdtv = fe->sec_priv;
  84. struct firedtv_tuner_status stat;
  85. if (avc_tuner_status(fdtv, &stat))
  86. return -EINVAL;
  87. *ber = stat.ber;
  88. return 0;
  89. }
  90. static int fdtv_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  91. {
  92. struct firedtv *fdtv = fe->sec_priv;
  93. struct firedtv_tuner_status stat;
  94. if (avc_tuner_status(fdtv, &stat))
  95. return -EINVAL;
  96. *strength = stat.signal_strength << 8;
  97. return 0;
  98. }
  99. static int fdtv_read_snr(struct dvb_frontend *fe, u16 *snr)
  100. {
  101. struct firedtv *fdtv = fe->sec_priv;
  102. struct firedtv_tuner_status stat;
  103. if (avc_tuner_status(fdtv, &stat))
  104. return -EINVAL;
  105. /* C/N[dB] = -10 * log10(snr / 65535) */
  106. *snr = stat.carrier_noise_ratio * 257;
  107. return 0;
  108. }
  109. static int fdtv_read_uncorrected_blocks(struct dvb_frontend *fe, u32 *ucblocks)
  110. {
  111. return -EOPNOTSUPP;
  112. }
  113. static int fdtv_set_frontend(struct dvb_frontend *fe)
  114. {
  115. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  116. struct firedtv *fdtv = fe->sec_priv;
  117. return avc_tuner_dsd(fdtv, p);
  118. }
  119. void fdtv_frontend_init(struct firedtv *fdtv, const char *name)
  120. {
  121. struct dvb_frontend_ops *ops = &fdtv->fe.ops;
  122. struct dvb_frontend_internal_info *fi = &ops->info;
  123. ops->init = fdtv_dvb_init;
  124. ops->sleep = fdtv_sleep;
  125. ops->set_frontend = fdtv_set_frontend;
  126. ops->read_status = fdtv_read_status;
  127. ops->read_ber = fdtv_read_ber;
  128. ops->read_signal_strength = fdtv_read_signal_strength;
  129. ops->read_snr = fdtv_read_snr;
  130. ops->read_ucblocks = fdtv_read_uncorrected_blocks;
  131. ops->diseqc_send_master_cmd = fdtv_diseqc_send_master_cmd;
  132. ops->diseqc_send_burst = fdtv_diseqc_send_burst;
  133. ops->set_tone = fdtv_set_tone;
  134. ops->set_voltage = fdtv_set_voltage;
  135. switch (fdtv->type) {
  136. case FIREDTV_DVB_S:
  137. ops->delsys[0] = SYS_DVBS;
  138. fi->frequency_min_hz = 950 * MHz;
  139. fi->frequency_max_hz = 2150 * MHz;
  140. fi->frequency_stepsize_hz = 125 * kHz;
  141. fi->symbol_rate_min = 1000000;
  142. fi->symbol_rate_max = 40000000;
  143. fi->caps = FE_CAN_INVERSION_AUTO |
  144. FE_CAN_FEC_1_2 |
  145. FE_CAN_FEC_2_3 |
  146. FE_CAN_FEC_3_4 |
  147. FE_CAN_FEC_5_6 |
  148. FE_CAN_FEC_7_8 |
  149. FE_CAN_FEC_AUTO |
  150. FE_CAN_QPSK;
  151. break;
  152. case FIREDTV_DVB_S2:
  153. ops->delsys[0] = SYS_DVBS;
  154. ops->delsys[1] = SYS_DVBS2;
  155. fi->frequency_min_hz = 950 * MHz;
  156. fi->frequency_max_hz = 2150 * MHz;
  157. fi->frequency_stepsize_hz = 125 * kHz;
  158. fi->symbol_rate_min = 1000000;
  159. fi->symbol_rate_max = 40000000;
  160. fi->caps = FE_CAN_INVERSION_AUTO |
  161. FE_CAN_FEC_1_2 |
  162. FE_CAN_FEC_2_3 |
  163. FE_CAN_FEC_3_4 |
  164. FE_CAN_FEC_5_6 |
  165. FE_CAN_FEC_7_8 |
  166. FE_CAN_FEC_AUTO |
  167. FE_CAN_QPSK |
  168. FE_CAN_2G_MODULATION;
  169. break;
  170. case FIREDTV_DVB_C:
  171. ops->delsys[0] = SYS_DVBC_ANNEX_A;
  172. fi->frequency_min_hz = 47 * MHz;
  173. fi->frequency_max_hz = 866 * MHz;
  174. fi->frequency_stepsize_hz = 62500;
  175. fi->symbol_rate_min = 870000;
  176. fi->symbol_rate_max = 6900000;
  177. fi->caps = FE_CAN_INVERSION_AUTO |
  178. FE_CAN_QAM_16 |
  179. FE_CAN_QAM_32 |
  180. FE_CAN_QAM_64 |
  181. FE_CAN_QAM_128 |
  182. FE_CAN_QAM_256 |
  183. FE_CAN_QAM_AUTO;
  184. break;
  185. case FIREDTV_DVB_T:
  186. ops->delsys[0] = SYS_DVBT;
  187. fi->frequency_min_hz = 49 * MHz;
  188. fi->frequency_max_hz = 861 * MHz;
  189. fi->frequency_stepsize_hz = 62500;
  190. fi->caps = FE_CAN_INVERSION_AUTO |
  191. FE_CAN_FEC_2_3 |
  192. FE_CAN_TRANSMISSION_MODE_AUTO |
  193. FE_CAN_GUARD_INTERVAL_AUTO |
  194. FE_CAN_HIERARCHY_AUTO;
  195. break;
  196. default:
  197. dev_err(fdtv->device, "no frontend for model type %d\n",
  198. fdtv->type);
  199. }
  200. strcpy(fi->name, name);
  201. fdtv->fe.dvb = &fdtv->adapter;
  202. fdtv->fe.sec_priv = fdtv;
  203. }