ttusbdecfe.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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_dvbs_read_status(struct dvb_frontend *fe,
  33. fe_status_t *status)
  34. {
  35. *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
  36. FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
  37. return 0;
  38. }
  39. static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
  40. fe_status_t *status)
  41. {
  42. struct ttusbdecfe_state* state = fe->demodulator_priv;
  43. u8 b[] = { 0x00, 0x00, 0x00, 0x00,
  44. 0x00, 0x00, 0x00, 0x00 };
  45. u8 result[4];
  46. int len, ret;
  47. *status=0;
  48. ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
  49. if(ret)
  50. return ret;
  51. if(len != 4) {
  52. printk(KERN_ERR "%s: unexpected reply\n", __func__);
  53. return -EIO;
  54. }
  55. switch(result[3]) {
  56. case 1: /* not tuned yet */
  57. case 2: /* no signal/no lock*/
  58. break;
  59. case 3: /* signal found and locked*/
  60. *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
  61. FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
  62. break;
  63. case 4:
  64. *status = FE_TIMEDOUT;
  65. break;
  66. default:
  67. pr_info("%s: returned unknown value: %d\n",
  68. __func__, result[3]);
  69. return -EIO;
  70. }
  71. return 0;
  72. }
  73. static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
  74. {
  75. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  76. u8 b[] = { 0x00, 0x00, 0x00, 0x03,
  77. 0x00, 0x00, 0x00, 0x00,
  78. 0x00, 0x00, 0x00, 0x01,
  79. 0x00, 0x00, 0x00, 0xff,
  80. 0x00, 0x00, 0x00, 0xff };
  81. __be32 freq = htonl(p->frequency / 1000);
  82. memcpy(&b[4], &freq, sizeof (u32));
  83. state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
  84. return 0;
  85. }
  86. static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
  87. struct dvb_frontend_tune_settings* fesettings)
  88. {
  89. fesettings->min_delay_ms = 1500;
  90. /* Drift compensation makes no sense for DVB-T */
  91. fesettings->step_size = 0;
  92. fesettings->max_drift = 0;
  93. return 0;
  94. }
  95. static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
  96. {
  97. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  98. u8 b[] = { 0x00, 0x00, 0x00, 0x01,
  99. 0x00, 0x00, 0x00, 0x00,
  100. 0x00, 0x00, 0x00, 0x01,
  101. 0x00, 0x00, 0x00, 0x00,
  102. 0x00, 0x00, 0x00, 0x00,
  103. 0x00, 0x00, 0x00, 0x00,
  104. 0x00, 0x00, 0x00, 0x00,
  105. 0x00, 0x00, 0x00, 0x00,
  106. 0x00, 0x00, 0x00, 0x00,
  107. 0x00, 0x00, 0x00, 0x00 };
  108. __be32 freq;
  109. __be32 sym_rate;
  110. __be32 band;
  111. __be32 lnb_voltage;
  112. freq = htonl(p->frequency +
  113. (state->hi_band ? LOF_HI : LOF_LO));
  114. memcpy(&b[4], &freq, sizeof(u32));
  115. sym_rate = htonl(p->u.qam.symbol_rate);
  116. memcpy(&b[12], &sym_rate, sizeof(u32));
  117. band = htonl(state->hi_band ? LOF_HI : LOF_LO);
  118. memcpy(&b[24], &band, sizeof(u32));
  119. lnb_voltage = htonl(state->voltage);
  120. memcpy(&b[28], &lnb_voltage, sizeof(u32));
  121. state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
  122. return 0;
  123. }
  124. static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
  125. {
  126. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  127. u8 b[] = { 0x00, 0xff, 0x00, 0x00,
  128. 0x00, 0x00, 0x00, 0x00,
  129. 0x00, 0x00 };
  130. memcpy(&b[4], cmd->msg, cmd->msg_len);
  131. state->config->send_command(fe, 0x72,
  132. sizeof(b) - (6 - cmd->msg_len), b,
  133. NULL, NULL);
  134. return 0;
  135. }
  136. static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
  137. {
  138. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  139. state->hi_band = (SEC_TONE_ON == tone);
  140. return 0;
  141. }
  142. static int ttusbdecfe_dvbs_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
  143. {
  144. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  145. switch (voltage) {
  146. case SEC_VOLTAGE_13:
  147. state->voltage = 13;
  148. break;
  149. case SEC_VOLTAGE_18:
  150. state->voltage = 18;
  151. break;
  152. default:
  153. return -EINVAL;
  154. }
  155. return 0;
  156. }
  157. static void ttusbdecfe_release(struct dvb_frontend* fe)
  158. {
  159. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  160. kfree(state);
  161. }
  162. static struct dvb_frontend_ops ttusbdecfe_dvbt_ops;
  163. struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config)
  164. {
  165. struct ttusbdecfe_state* state = NULL;
  166. /* allocate memory for the internal state */
  167. state = kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
  168. if (state == NULL)
  169. return NULL;
  170. /* setup the state */
  171. state->config = config;
  172. /* create dvb_frontend */
  173. memcpy(&state->frontend.ops, &ttusbdecfe_dvbt_ops, sizeof(struct dvb_frontend_ops));
  174. state->frontend.demodulator_priv = state;
  175. return &state->frontend;
  176. }
  177. static struct dvb_frontend_ops ttusbdecfe_dvbs_ops;
  178. struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config)
  179. {
  180. struct ttusbdecfe_state* state = NULL;
  181. /* allocate memory for the internal state */
  182. state = kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
  183. if (state == NULL)
  184. return NULL;
  185. /* setup the state */
  186. state->config = config;
  187. state->voltage = 0;
  188. state->hi_band = 0;
  189. /* create dvb_frontend */
  190. memcpy(&state->frontend.ops, &ttusbdecfe_dvbs_ops, sizeof(struct dvb_frontend_ops));
  191. state->frontend.demodulator_priv = state;
  192. return &state->frontend;
  193. }
  194. static struct dvb_frontend_ops ttusbdecfe_dvbt_ops = {
  195. .info = {
  196. .name = "TechnoTrend/Hauppauge DEC2000-t Frontend",
  197. .type = FE_OFDM,
  198. .frequency_min = 51000000,
  199. .frequency_max = 858000000,
  200. .frequency_stepsize = 62500,
  201. .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  202. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  203. FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  204. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
  205. FE_CAN_HIERARCHY_AUTO,
  206. },
  207. .release = ttusbdecfe_release,
  208. .set_frontend = ttusbdecfe_dvbt_set_frontend,
  209. .get_tune_settings = ttusbdecfe_dvbt_get_tune_settings,
  210. .read_status = ttusbdecfe_dvbt_read_status,
  211. };
  212. static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
  213. .info = {
  214. .name = "TechnoTrend/Hauppauge DEC3000-s Frontend",
  215. .type = FE_QPSK,
  216. .frequency_min = 950000,
  217. .frequency_max = 2150000,
  218. .frequency_stepsize = 125,
  219. .symbol_rate_min = 1000000, /* guessed */
  220. .symbol_rate_max = 45000000, /* guessed */
  221. .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  222. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  223. FE_CAN_QPSK
  224. },
  225. .release = ttusbdecfe_release,
  226. .set_frontend = ttusbdecfe_dvbs_set_frontend,
  227. .read_status = ttusbdecfe_dvbs_read_status,
  228. .diseqc_send_master_cmd = ttusbdecfe_dvbs_diseqc_send_master_cmd,
  229. .set_voltage = ttusbdecfe_dvbs_set_voltage,
  230. .set_tone = ttusbdecfe_dvbs_set_tone,
  231. };
  232. MODULE_DESCRIPTION("TTUSB DEC DVB-T/S Demodulator driver");
  233. MODULE_AUTHOR("Alex Woods/Andrew de Quincey");
  234. MODULE_LICENSE("GPL");
  235. EXPORT_SYMBOL(ttusbdecfe_dvbt_attach);
  236. EXPORT_SYMBOL(ttusbdecfe_dvbs_attach);