ttusbdecfe.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * TTUSB DEC Frontend Driver
  3. *
  4. * Copyright (C) 2003-2004 Alex Woods <linux-dvb@giblets.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. */
  21. #include "dvb_frontend.h"
  22. #include "ttusbdecfe.h"
  23. #define LOF_HI 10600000
  24. #define LOF_LO 9750000
  25. struct ttusbdecfe_state {
  26. /* configuration settings */
  27. const struct ttusbdecfe_config* config;
  28. struct dvb_frontend frontend;
  29. u8 hi_band;
  30. u8 voltage;
  31. };
  32. static int ttusbdecfe_read_status(struct dvb_frontend* fe, fe_status_t* status)
  33. {
  34. struct ttusbdecfe_state* state = fe->demodulator_priv;
  35. u8 b[] = { 0x00, 0x00, 0x00, 0x00,
  36. 0x00, 0x00, 0x00, 0x00 };
  37. u8 result[4];
  38. int len, ret;
  39. *status=0;
  40. ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
  41. if(ret)
  42. return ret;
  43. if(len != 4) {
  44. printk(KERN_ERR "%s: unexpected reply\n", __FUNCTION__);
  45. return -EIO;
  46. }
  47. switch(result[3]) {
  48. case 1: /* not tuned yet */
  49. case 2: /* no signal/no lock*/
  50. break;
  51. case 3: /* signal found and locked*/
  52. *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
  53. FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
  54. break;
  55. case 4:
  56. *status = FE_TIMEDOUT;
  57. break;
  58. default:
  59. pr_info("%s: returned unknown value: %d\n",
  60. __FUNCTION__, result[3]);
  61. return -EIO;
  62. }
  63. return 0;
  64. }
  65. static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
  66. {
  67. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  68. u8 b[] = { 0x00, 0x00, 0x00, 0x03,
  69. 0x00, 0x00, 0x00, 0x00,
  70. 0x00, 0x00, 0x00, 0x01,
  71. 0x00, 0x00, 0x00, 0xff,
  72. 0x00, 0x00, 0x00, 0xff };
  73. u32 freq = htonl(p->frequency / 1000);
  74. memcpy(&b[4], &freq, sizeof (u32));
  75. state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
  76. return 0;
  77. }
  78. static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
  79. struct dvb_frontend_tune_settings* fesettings)
  80. {
  81. fesettings->min_delay_ms = 1500;
  82. /* Drift compensation makes no sense for DVB-T */
  83. fesettings->step_size = 0;
  84. fesettings->max_drift = 0;
  85. return 0;
  86. }
  87. static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
  88. {
  89. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  90. u8 b[] = { 0x00, 0x00, 0x00, 0x01,
  91. 0x00, 0x00, 0x00, 0x00,
  92. 0x00, 0x00, 0x00, 0x01,
  93. 0x00, 0x00, 0x00, 0x00,
  94. 0x00, 0x00, 0x00, 0x00,
  95. 0x00, 0x00, 0x00, 0x00,
  96. 0x00, 0x00, 0x00, 0x00,
  97. 0x00, 0x00, 0x00, 0x00,
  98. 0x00, 0x00, 0x00, 0x00,
  99. 0x00, 0x00, 0x00, 0x00 };
  100. u32 freq;
  101. u32 sym_rate;
  102. u32 band;
  103. u32 lnb_voltage;
  104. freq = htonl(p->frequency +
  105. (state->hi_band ? LOF_HI : LOF_LO));
  106. memcpy(&b[4], &freq, sizeof(u32));
  107. sym_rate = htonl(p->u.qam.symbol_rate);
  108. memcpy(&b[12], &sym_rate, sizeof(u32));
  109. band = htonl(state->hi_band ? LOF_HI : LOF_LO);
  110. memcpy(&b[24], &band, sizeof(u32));
  111. lnb_voltage = htonl(state->voltage);
  112. memcpy(&b[28], &lnb_voltage, sizeof(u32));
  113. state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
  114. return 0;
  115. }
  116. static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
  117. {
  118. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  119. u8 b[] = { 0x00, 0xff, 0x00, 0x00,
  120. 0x00, 0x00, 0x00, 0x00,
  121. 0x00, 0x00 };
  122. memcpy(&b[4], cmd->msg, cmd->msg_len);
  123. state->config->send_command(fe, 0x72,
  124. sizeof(b) - (6 - cmd->msg_len), b,
  125. NULL, NULL);
  126. return 0;
  127. }
  128. static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
  129. {
  130. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  131. state->hi_band = (SEC_TONE_ON == tone);
  132. return 0;
  133. }
  134. static int ttusbdecfe_dvbs_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
  135. {
  136. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  137. switch (voltage) {
  138. case SEC_VOLTAGE_13:
  139. state->voltage = 13;
  140. break;
  141. case SEC_VOLTAGE_18:
  142. state->voltage = 18;
  143. break;
  144. default:
  145. return -EINVAL;
  146. }
  147. return 0;
  148. }
  149. static void ttusbdecfe_release(struct dvb_frontend* fe)
  150. {
  151. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  152. kfree(state);
  153. }
  154. static struct dvb_frontend_ops ttusbdecfe_dvbt_ops;
  155. struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config)
  156. {
  157. struct ttusbdecfe_state* state = NULL;
  158. /* allocate memory for the internal state */
  159. state = kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
  160. if (state == NULL)
  161. return NULL;
  162. /* setup the state */
  163. state->config = config;
  164. /* create dvb_frontend */
  165. memcpy(&state->frontend.ops, &ttusbdecfe_dvbt_ops, sizeof(struct dvb_frontend_ops));
  166. state->frontend.demodulator_priv = state;
  167. return &state->frontend;
  168. }
  169. static struct dvb_frontend_ops ttusbdecfe_dvbs_ops;
  170. struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config)
  171. {
  172. struct ttusbdecfe_state* state = NULL;
  173. /* allocate memory for the internal state */
  174. state = kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
  175. if (state == NULL)
  176. return NULL;
  177. /* setup the state */
  178. state->config = config;
  179. state->voltage = 0;
  180. state->hi_band = 0;
  181. /* create dvb_frontend */
  182. memcpy(&state->frontend.ops, &ttusbdecfe_dvbs_ops, sizeof(struct dvb_frontend_ops));
  183. state->frontend.demodulator_priv = state;
  184. return &state->frontend;
  185. }
  186. static struct dvb_frontend_ops ttusbdecfe_dvbt_ops = {
  187. .info = {
  188. .name = "TechnoTrend/Hauppauge DEC2000-t Frontend",
  189. .type = FE_OFDM,
  190. .frequency_min = 51000000,
  191. .frequency_max = 858000000,
  192. .frequency_stepsize = 62500,
  193. .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  194. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  195. FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  196. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
  197. FE_CAN_HIERARCHY_AUTO,
  198. },
  199. .release = ttusbdecfe_release,
  200. .set_frontend = ttusbdecfe_dvbt_set_frontend,
  201. .get_tune_settings = ttusbdecfe_dvbt_get_tune_settings,
  202. .read_status = ttusbdecfe_read_status,
  203. };
  204. static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
  205. .info = {
  206. .name = "TechnoTrend/Hauppauge DEC3000-s Frontend",
  207. .type = FE_QPSK,
  208. .frequency_min = 950000,
  209. .frequency_max = 2150000,
  210. .frequency_stepsize = 125,
  211. .symbol_rate_min = 1000000, /* guessed */
  212. .symbol_rate_max = 45000000, /* guessed */
  213. .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  214. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  215. FE_CAN_QPSK
  216. },
  217. .release = ttusbdecfe_release,
  218. .set_frontend = ttusbdecfe_dvbs_set_frontend,
  219. .read_status = ttusbdecfe_read_status,
  220. .diseqc_send_master_cmd = ttusbdecfe_dvbs_diseqc_send_master_cmd,
  221. .set_voltage = ttusbdecfe_dvbs_set_voltage,
  222. .set_tone = ttusbdecfe_dvbs_set_tone,
  223. };
  224. MODULE_DESCRIPTION("TTUSB DEC DVB-T/S Demodulator driver");
  225. MODULE_AUTHOR("Alex Woods/Andrew de Quincey");
  226. MODULE_LICENSE("GPL");
  227. EXPORT_SYMBOL(ttusbdecfe_dvbt_attach);
  228. EXPORT_SYMBOL(ttusbdecfe_dvbs_attach);