ttusbdecfe.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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)
  74. {
  75. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  76. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  77. u8 b[] = { 0x00, 0x00, 0x00, 0x03,
  78. 0x00, 0x00, 0x00, 0x00,
  79. 0x00, 0x00, 0x00, 0x01,
  80. 0x00, 0x00, 0x00, 0xff,
  81. 0x00, 0x00, 0x00, 0xff };
  82. __be32 freq = htonl(p->frequency / 1000);
  83. memcpy(&b[4], &freq, sizeof (u32));
  84. state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
  85. return 0;
  86. }
  87. static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
  88. struct dvb_frontend_tune_settings* fesettings)
  89. {
  90. fesettings->min_delay_ms = 1500;
  91. /* Drift compensation makes no sense for DVB-T */
  92. fesettings->step_size = 0;
  93. fesettings->max_drift = 0;
  94. return 0;
  95. }
  96. static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
  97. {
  98. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  99. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  100. u8 b[] = { 0x00, 0x00, 0x00, 0x01,
  101. 0x00, 0x00, 0x00, 0x00,
  102. 0x00, 0x00, 0x00, 0x01,
  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. 0x00, 0x00, 0x00, 0x00,
  109. 0x00, 0x00, 0x00, 0x00 };
  110. __be32 freq;
  111. __be32 sym_rate;
  112. __be32 band;
  113. __be32 lnb_voltage;
  114. freq = htonl(p->frequency +
  115. (state->hi_band ? LOF_HI : LOF_LO));
  116. memcpy(&b[4], &freq, sizeof(u32));
  117. sym_rate = htonl(p->symbol_rate);
  118. memcpy(&b[12], &sym_rate, sizeof(u32));
  119. band = htonl(state->hi_band ? LOF_HI : LOF_LO);
  120. memcpy(&b[24], &band, sizeof(u32));
  121. lnb_voltage = htonl(state->voltage);
  122. memcpy(&b[28], &lnb_voltage, sizeof(u32));
  123. state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
  124. return 0;
  125. }
  126. static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
  127. {
  128. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  129. u8 b[] = { 0x00, 0xff, 0x00, 0x00,
  130. 0x00, 0x00, 0x00, 0x00,
  131. 0x00, 0x00 };
  132. memcpy(&b[4], cmd->msg, cmd->msg_len);
  133. state->config->send_command(fe, 0x72,
  134. sizeof(b) - (6 - cmd->msg_len), b,
  135. NULL, NULL);
  136. return 0;
  137. }
  138. static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
  139. {
  140. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  141. state->hi_band = (SEC_TONE_ON == tone);
  142. return 0;
  143. }
  144. static int ttusbdecfe_dvbs_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
  145. {
  146. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  147. switch (voltage) {
  148. case SEC_VOLTAGE_13:
  149. state->voltage = 13;
  150. break;
  151. case SEC_VOLTAGE_18:
  152. state->voltage = 18;
  153. break;
  154. default:
  155. return -EINVAL;
  156. }
  157. return 0;
  158. }
  159. static void ttusbdecfe_release(struct dvb_frontend* fe)
  160. {
  161. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  162. kfree(state);
  163. }
  164. static struct dvb_frontend_ops ttusbdecfe_dvbt_ops;
  165. struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config)
  166. {
  167. struct ttusbdecfe_state* state = NULL;
  168. /* allocate memory for the internal state */
  169. state = kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
  170. if (state == NULL)
  171. return NULL;
  172. /* setup the state */
  173. state->config = config;
  174. /* create dvb_frontend */
  175. memcpy(&state->frontend.ops, &ttusbdecfe_dvbt_ops, sizeof(struct dvb_frontend_ops));
  176. state->frontend.demodulator_priv = state;
  177. return &state->frontend;
  178. }
  179. static struct dvb_frontend_ops ttusbdecfe_dvbs_ops;
  180. struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config)
  181. {
  182. struct ttusbdecfe_state* state = NULL;
  183. /* allocate memory for the internal state */
  184. state = kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
  185. if (state == NULL)
  186. return NULL;
  187. /* setup the state */
  188. state->config = config;
  189. state->voltage = 0;
  190. state->hi_band = 0;
  191. /* create dvb_frontend */
  192. memcpy(&state->frontend.ops, &ttusbdecfe_dvbs_ops, sizeof(struct dvb_frontend_ops));
  193. state->frontend.demodulator_priv = state;
  194. return &state->frontend;
  195. }
  196. static struct dvb_frontend_ops ttusbdecfe_dvbt_ops = {
  197. .delsys = { SYS_DVBT },
  198. .info = {
  199. .name = "TechnoTrend/Hauppauge DEC2000-t Frontend",
  200. .frequency_min = 51000000,
  201. .frequency_max = 858000000,
  202. .frequency_stepsize = 62500,
  203. .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  204. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  205. FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  206. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
  207. FE_CAN_HIERARCHY_AUTO,
  208. },
  209. .release = ttusbdecfe_release,
  210. .set_frontend = ttusbdecfe_dvbt_set_frontend,
  211. .get_tune_settings = ttusbdecfe_dvbt_get_tune_settings,
  212. .read_status = ttusbdecfe_dvbt_read_status,
  213. };
  214. static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
  215. .delsys = { SYS_DVBS },
  216. .info = {
  217. .name = "TechnoTrend/Hauppauge DEC3000-s Frontend",
  218. .frequency_min = 950000,
  219. .frequency_max = 2150000,
  220. .frequency_stepsize = 125,
  221. .symbol_rate_min = 1000000, /* guessed */
  222. .symbol_rate_max = 45000000, /* guessed */
  223. .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  224. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  225. FE_CAN_QPSK
  226. },
  227. .release = ttusbdecfe_release,
  228. .set_frontend = ttusbdecfe_dvbs_set_frontend,
  229. .read_status = ttusbdecfe_dvbs_read_status,
  230. .diseqc_send_master_cmd = ttusbdecfe_dvbs_diseqc_send_master_cmd,
  231. .set_voltage = ttusbdecfe_dvbs_set_voltage,
  232. .set_tone = ttusbdecfe_dvbs_set_tone,
  233. };
  234. MODULE_DESCRIPTION("TTUSB DEC DVB-T/S Demodulator driver");
  235. MODULE_AUTHOR("Alex Woods/Andrew de Quincey");
  236. MODULE_LICENSE("GPL");
  237. EXPORT_SYMBOL(ttusbdecfe_dvbt_attach);
  238. EXPORT_SYMBOL(ttusbdecfe_dvbs_attach);