ttusbdecfe.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. *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_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
  40. {
  41. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  42. u8 b[] = { 0x00, 0x00, 0x00, 0x03,
  43. 0x00, 0x00, 0x00, 0x00,
  44. 0x00, 0x00, 0x00, 0x01,
  45. 0x00, 0x00, 0x00, 0xff,
  46. 0x00, 0x00, 0x00, 0xff };
  47. u32 freq = htonl(p->frequency / 1000);
  48. memcpy(&b[4], &freq, sizeof (u32));
  49. state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
  50. return 0;
  51. }
  52. static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
  53. {
  54. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  55. u8 b[] = { 0x00, 0x00, 0x00, 0x01,
  56. 0x00, 0x00, 0x00, 0x00,
  57. 0x00, 0x00, 0x00, 0x01,
  58. 0x00, 0x00, 0x00, 0x00,
  59. 0x00, 0x00, 0x00, 0x00,
  60. 0x00, 0x00, 0x00, 0x00,
  61. 0x00, 0x00, 0x00, 0x00,
  62. 0x00, 0x00, 0x00, 0x00,
  63. 0x00, 0x00, 0x00, 0x00,
  64. 0x00, 0x00, 0x00, 0x00 };
  65. u32 freq;
  66. u32 sym_rate;
  67. u32 band;
  68. u32 lnb_voltage;
  69. freq = htonl(p->frequency +
  70. (state->hi_band ? LOF_HI : LOF_LO));
  71. memcpy(&b[4], &freq, sizeof(u32));
  72. sym_rate = htonl(p->u.qam.symbol_rate);
  73. memcpy(&b[12], &sym_rate, sizeof(u32));
  74. band = htonl(state->hi_band ? LOF_HI : LOF_LO);
  75. memcpy(&b[24], &band, sizeof(u32));
  76. lnb_voltage = htonl(state->voltage);
  77. memcpy(&b[28], &lnb_voltage, sizeof(u32));
  78. state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
  79. return 0;
  80. }
  81. static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
  82. {
  83. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  84. u8 b[] = { 0x00, 0xff, 0x00, 0x00,
  85. 0x00, 0x00, 0x00, 0x00,
  86. 0x00, 0x00 };
  87. memcpy(&b[4], cmd->msg, cmd->msg_len);
  88. state->config->send_command(fe, 0x72,
  89. sizeof(b) - (6 - cmd->msg_len), b,
  90. NULL, NULL);
  91. return 0;
  92. }
  93. static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
  94. {
  95. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  96. state->hi_band = (SEC_TONE_ON == tone);
  97. return 0;
  98. }
  99. static int ttusbdecfe_dvbs_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
  100. {
  101. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  102. switch (voltage) {
  103. case SEC_VOLTAGE_13:
  104. state->voltage = 13;
  105. break;
  106. case SEC_VOLTAGE_18:
  107. state->voltage = 18;
  108. break;
  109. default:
  110. return -EINVAL;
  111. }
  112. return 0;
  113. }
  114. static void ttusbdecfe_release(struct dvb_frontend* fe)
  115. {
  116. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  117. kfree(state);
  118. }
  119. static struct dvb_frontend_ops ttusbdecfe_dvbt_ops;
  120. struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config)
  121. {
  122. struct ttusbdecfe_state* state = NULL;
  123. /* allocate memory for the internal state */
  124. state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
  125. if (state == NULL)
  126. return NULL;
  127. /* setup the state */
  128. state->config = config;
  129. memcpy(&state->ops, &ttusbdecfe_dvbt_ops, sizeof(struct dvb_frontend_ops));
  130. /* create dvb_frontend */
  131. state->frontend.ops = &state->ops;
  132. state->frontend.demodulator_priv = state;
  133. return &state->frontend;
  134. }
  135. static struct dvb_frontend_ops ttusbdecfe_dvbs_ops;
  136. struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config)
  137. {
  138. struct ttusbdecfe_state* state = NULL;
  139. /* allocate memory for the internal state */
  140. state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
  141. if (state == NULL)
  142. return NULL;
  143. /* setup the state */
  144. state->config = config;
  145. state->voltage = 0;
  146. state->hi_band = 0;
  147. memcpy(&state->ops, &ttusbdecfe_dvbs_ops, sizeof(struct dvb_frontend_ops));
  148. /* create dvb_frontend */
  149. state->frontend.ops = &state->ops;
  150. state->frontend.demodulator_priv = state;
  151. return &state->frontend;
  152. }
  153. static struct dvb_frontend_ops ttusbdecfe_dvbt_ops = {
  154. .info = {
  155. .name = "TechnoTrend/Hauppauge DEC2000-t Frontend",
  156. .type = FE_OFDM,
  157. .frequency_min = 51000000,
  158. .frequency_max = 858000000,
  159. .frequency_stepsize = 62500,
  160. .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  161. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  162. FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  163. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
  164. FE_CAN_HIERARCHY_AUTO,
  165. },
  166. .release = ttusbdecfe_release,
  167. .set_frontend = ttusbdecfe_dvbt_set_frontend,
  168. .read_status = ttusbdecfe_read_status,
  169. };
  170. static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
  171. .info = {
  172. .name = "TechnoTrend/Hauppauge DEC3000-s Frontend",
  173. .type = FE_QPSK,
  174. .frequency_min = 950000,
  175. .frequency_max = 2150000,
  176. .frequency_stepsize = 125,
  177. .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  178. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  179. FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  180. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
  181. FE_CAN_HIERARCHY_AUTO,
  182. },
  183. .release = ttusbdecfe_release,
  184. .set_frontend = ttusbdecfe_dvbs_set_frontend,
  185. .read_status = ttusbdecfe_read_status,
  186. .diseqc_send_master_cmd = ttusbdecfe_dvbs_diseqc_send_master_cmd,
  187. .set_voltage = ttusbdecfe_dvbs_set_voltage,
  188. .set_tone = ttusbdecfe_dvbs_set_tone,
  189. };
  190. MODULE_DESCRIPTION("TTUSB DEC DVB-T/S Demodulator driver");
  191. MODULE_AUTHOR("Alex Woods/Andrew de Quincey");
  192. MODULE_LICENSE("GPL");
  193. EXPORT_SYMBOL(ttusbdecfe_dvbt_attach);
  194. EXPORT_SYMBOL(ttusbdecfe_dvbs_attach);