firesat_fe.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * FireSAT DVB driver
  3. *
  4. * Copyright (c) ?
  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/init.h>
  13. #include <linux/slab.h>
  14. #include <linux/wait.h>
  15. #include <linux/module.h>
  16. #include <linux/delay.h>
  17. #include <linux/time.h>
  18. #include <linux/errno.h>
  19. #include <linux/interrupt.h>
  20. #include <ieee1394_hotplug.h>
  21. #include <nodemgr.h>
  22. #include <highlevel.h>
  23. #include <ohci1394.h>
  24. #include <hosts.h>
  25. #include <dvbdev.h>
  26. #include "firesat.h"
  27. #include "avc_api.h"
  28. #include "cmp.h"
  29. #include "firesat-rc.h"
  30. #include "firesat-ci.h"
  31. static int firesat_dvb_init(struct dvb_frontend *fe)
  32. {
  33. int result;
  34. struct firesat *firesat = fe->sec_priv;
  35. // printk("fdi: 1\n");
  36. firesat->isochannel = firesat->adapter->num; //<< 1 | (firesat->subunit & 0x1); // ### ask IRM
  37. // printk("fdi: 2\n");
  38. result = try_CMPEstablishPPconnection(firesat, firesat->subunit, firesat->isochannel);
  39. if (result != 0) {
  40. printk(KERN_ERR "Could not establish point to point "
  41. "connection.\n");
  42. return -1;
  43. }
  44. // printk("fdi: 3\n");
  45. result = setup_iso_channel(firesat);
  46. // printk("fdi: 4. Result was %d\n", result);
  47. return result;
  48. }
  49. static int firesat_sleep(struct dvb_frontend *fe)
  50. {
  51. struct firesat *firesat = fe->sec_priv;
  52. tear_down_iso_channel(firesat);
  53. try_CMPBreakPPconnection(firesat, firesat->subunit, firesat->isochannel);
  54. firesat->isochannel = -1;
  55. return 0;
  56. }
  57. static int firesat_diseqc_send_master_cmd(struct dvb_frontend *fe,
  58. struct dvb_diseqc_master_cmd *cmd)
  59. {
  60. struct firesat *firesat = fe->sec_priv;
  61. return AVCLNBControl(firesat, LNBCONTROL_DONTCARE, LNBCONTROL_DONTCARE,
  62. LNBCONTROL_DONTCARE, 1, cmd);
  63. }
  64. static int firesat_diseqc_send_burst(struct dvb_frontend *fe,
  65. fe_sec_mini_cmd_t minicmd)
  66. {
  67. return 0;
  68. }
  69. static int firesat_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
  70. {
  71. struct firesat *firesat = fe->sec_priv;
  72. firesat->tone = tone;
  73. return 0;
  74. }
  75. static int firesat_set_voltage(struct dvb_frontend *fe,
  76. fe_sec_voltage_t voltage)
  77. {
  78. struct firesat *firesat = fe->sec_priv;
  79. firesat->voltage = voltage;
  80. return 0;
  81. }
  82. static int firesat_read_status (struct dvb_frontend *fe, fe_status_t *status)
  83. {
  84. struct firesat *firesat = fe->sec_priv;
  85. ANTENNA_INPUT_INFO info;
  86. if (AVCTunerStatus(firesat, &info))
  87. return -EINVAL;
  88. if (info.NoRF) {
  89. *status = 0;
  90. } else {
  91. *status = FE_HAS_SIGNAL |
  92. FE_HAS_VITERBI |
  93. FE_HAS_SYNC |
  94. FE_HAS_CARRIER |
  95. FE_HAS_LOCK;
  96. }
  97. return 0;
  98. }
  99. static int firesat_read_ber(struct dvb_frontend *fe, u32 *ber)
  100. {
  101. struct firesat *firesat = fe->sec_priv;
  102. ANTENNA_INPUT_INFO info;
  103. if (AVCTunerStatus(firesat, &info))
  104. return -EINVAL;
  105. *ber = (info.BER[0] << 24) |
  106. (info.BER[1] << 16) |
  107. (info.BER[2] << 8) |
  108. info.BER[3];
  109. return 0;
  110. }
  111. static int firesat_read_signal_strength (struct dvb_frontend *fe, u16 *strength)
  112. {
  113. struct firesat *firesat = fe->sec_priv;
  114. ANTENNA_INPUT_INFO info;
  115. if (AVCTunerStatus(firesat, &info))
  116. return -EINVAL;
  117. *strength = info.SignalStrength << 8;
  118. return 0;
  119. }
  120. static int firesat_read_snr(struct dvb_frontend *fe, u16 *snr)
  121. {
  122. struct firesat *firesat = fe->sec_priv;
  123. ANTENNA_INPUT_INFO info;
  124. if (AVCTunerStatus(firesat, &info))
  125. return -EINVAL;
  126. *snr = (info.CarrierNoiseRatio[0] << 8) +
  127. info.CarrierNoiseRatio[1];
  128. *snr *= 257;
  129. // C/N[dB] = -10 * log10(snr / 65535)
  130. return 0;
  131. }
  132. static int firesat_read_uncorrected_blocks(struct dvb_frontend *fe, u32 *ucblocks)
  133. {
  134. return -EOPNOTSUPP;
  135. }
  136. static int firesat_set_frontend(struct dvb_frontend *fe,
  137. struct dvb_frontend_parameters *params)
  138. {
  139. struct firesat *firesat = fe->sec_priv;
  140. if (AVCTuner_DSD(firesat, params, NULL) != ACCEPTED)
  141. return -EINVAL;
  142. else
  143. return 0; //not sure of this...
  144. }
  145. static int firesat_get_frontend(struct dvb_frontend *fe,
  146. struct dvb_frontend_parameters *params)
  147. {
  148. return -EOPNOTSUPP;
  149. }
  150. static struct dvb_frontend_info firesat_S_frontend_info;
  151. static struct dvb_frontend_info firesat_C_frontend_info;
  152. static struct dvb_frontend_info firesat_T_frontend_info;
  153. static struct dvb_frontend_ops firesat_ops = {
  154. .init = firesat_dvb_init,
  155. .sleep = firesat_sleep,
  156. .set_frontend = firesat_set_frontend,
  157. .get_frontend = firesat_get_frontend,
  158. .read_status = firesat_read_status,
  159. .read_ber = firesat_read_ber,
  160. .read_signal_strength = firesat_read_signal_strength,
  161. .read_snr = firesat_read_snr,
  162. .read_ucblocks = firesat_read_uncorrected_blocks,
  163. .diseqc_send_master_cmd = firesat_diseqc_send_master_cmd,
  164. .diseqc_send_burst = firesat_diseqc_send_burst,
  165. .set_tone = firesat_set_tone,
  166. .set_voltage = firesat_set_voltage,
  167. };
  168. int firesat_frontend_attach(struct firesat *firesat, struct dvb_frontend *fe)
  169. {
  170. switch (firesat->type) {
  171. case FireSAT_DVB_S:
  172. firesat->model_name = "FireSAT DVB-S";
  173. firesat->frontend_info = &firesat_S_frontend_info;
  174. break;
  175. case FireSAT_DVB_C:
  176. firesat->model_name = "FireSAT DVB-C";
  177. firesat->frontend_info = &firesat_C_frontend_info;
  178. break;
  179. case FireSAT_DVB_T:
  180. firesat->model_name = "FireSAT DVB-T";
  181. firesat->frontend_info = &firesat_T_frontend_info;
  182. break;
  183. default:
  184. printk("%s: unknown model type 0x%x !\n",
  185. __func__, firesat->type);
  186. firesat->model_name = "Unknown";
  187. firesat->frontend_info = NULL;
  188. }
  189. fe->ops = firesat_ops;
  190. fe->ops.info = *(firesat->frontend_info);
  191. fe->dvb = firesat->adapter;
  192. return 0;
  193. }
  194. static struct dvb_frontend_info firesat_S_frontend_info = {
  195. .name = "FireSAT DVB-S Frontend",
  196. .type = FE_QPSK,
  197. .frequency_min = 950000,
  198. .frequency_max = 2150000,
  199. .frequency_stepsize = 125,
  200. .symbol_rate_min = 1000000,
  201. .symbol_rate_max = 40000000,
  202. .caps = FE_CAN_INVERSION_AUTO |
  203. FE_CAN_FEC_1_2 |
  204. FE_CAN_FEC_2_3 |
  205. FE_CAN_FEC_3_4 |
  206. FE_CAN_FEC_5_6 |
  207. FE_CAN_FEC_7_8 |
  208. FE_CAN_FEC_AUTO |
  209. FE_CAN_QPSK,
  210. };
  211. static struct dvb_frontend_info firesat_C_frontend_info = {
  212. .name = "FireSAT DVB-C Frontend",
  213. .type = FE_QAM,
  214. .frequency_min = 47000000,
  215. .frequency_max = 866000000,
  216. .frequency_stepsize = 62500,
  217. .symbol_rate_min = 870000,
  218. .symbol_rate_max = 6900000,
  219. .caps = FE_CAN_INVERSION_AUTO |
  220. FE_CAN_QAM_16 |
  221. FE_CAN_QAM_32 |
  222. FE_CAN_QAM_64 |
  223. FE_CAN_QAM_128 |
  224. FE_CAN_QAM_256 |
  225. FE_CAN_QAM_AUTO,
  226. };
  227. static struct dvb_frontend_info firesat_T_frontend_info = {
  228. .name = "FireSAT DVB-T Frontend",
  229. .type = FE_OFDM,
  230. .frequency_min = 49000000,
  231. .frequency_max = 861000000,
  232. .frequency_stepsize = 62500,
  233. .caps = FE_CAN_INVERSION_AUTO |
  234. FE_CAN_FEC_2_3 |
  235. FE_CAN_TRANSMISSION_MODE_AUTO |
  236. FE_CAN_GUARD_INTERVAL_AUTO |
  237. FE_CAN_HIERARCHY_AUTO,
  238. };