ttusbdecfe.c 7.6 KB

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