ttusbdecfe.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. */
  17. #include <media/dvb_frontend.h>
  18. #include "ttusbdecfe.h"
  19. #define LOF_HI 10600000
  20. #define LOF_LO 9750000
  21. struct ttusbdecfe_state {
  22. /* configuration settings */
  23. const struct ttusbdecfe_config* config;
  24. struct dvb_frontend frontend;
  25. u8 hi_band;
  26. u8 voltage;
  27. };
  28. static int ttusbdecfe_dvbs_read_status(struct dvb_frontend *fe,
  29. enum fe_status *status)
  30. {
  31. *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
  32. FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
  33. return 0;
  34. }
  35. static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
  36. enum fe_status *status)
  37. {
  38. struct ttusbdecfe_state* state = fe->demodulator_priv;
  39. u8 b[] = { 0x00, 0x00, 0x00, 0x00,
  40. 0x00, 0x00, 0x00, 0x00 };
  41. u8 result[4];
  42. int len, ret;
  43. *status=0;
  44. ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
  45. if(ret)
  46. return ret;
  47. if(len != 4) {
  48. printk(KERN_ERR "%s: unexpected reply\n", __func__);
  49. return -EIO;
  50. }
  51. switch(result[3]) {
  52. case 1: /* not tuned yet */
  53. case 2: /* no signal/no lock*/
  54. break;
  55. case 3: /* signal found and locked*/
  56. *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
  57. FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
  58. break;
  59. case 4:
  60. *status = FE_TIMEDOUT;
  61. break;
  62. default:
  63. pr_info("%s: returned unknown value: %d\n",
  64. __func__, result[3]);
  65. return -EIO;
  66. }
  67. return 0;
  68. }
  69. static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
  70. {
  71. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  72. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  73. u8 b[] = { 0x00, 0x00, 0x00, 0x03,
  74. 0x00, 0x00, 0x00, 0x00,
  75. 0x00, 0x00, 0x00, 0x01,
  76. 0x00, 0x00, 0x00, 0xff,
  77. 0x00, 0x00, 0x00, 0xff };
  78. __be32 freq = htonl(p->frequency / 1000);
  79. memcpy(&b[4], &freq, sizeof (u32));
  80. state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
  81. return 0;
  82. }
  83. static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
  84. struct dvb_frontend_tune_settings* fesettings)
  85. {
  86. fesettings->min_delay_ms = 1500;
  87. /* Drift compensation makes no sense for DVB-T */
  88. fesettings->step_size = 0;
  89. fesettings->max_drift = 0;
  90. return 0;
  91. }
  92. static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
  93. {
  94. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  95. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  96. u8 b[] = { 0x00, 0x00, 0x00, 0x01,
  97. 0x00, 0x00, 0x00, 0x00,
  98. 0x00, 0x00, 0x00, 0x01,
  99. 0x00, 0x00, 0x00, 0x00,
  100. 0x00, 0x00, 0x00, 0x00,
  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. __be32 freq;
  107. __be32 sym_rate;
  108. __be32 band;
  109. __be32 lnb_voltage;
  110. freq = htonl(p->frequency +
  111. (state->hi_band ? LOF_HI : LOF_LO));
  112. memcpy(&b[4], &freq, sizeof(u32));
  113. sym_rate = htonl(p->symbol_rate);
  114. memcpy(&b[12], &sym_rate, sizeof(u32));
  115. band = htonl(state->hi_band ? LOF_HI : LOF_LO);
  116. memcpy(&b[24], &band, sizeof(u32));
  117. lnb_voltage = htonl(state->voltage);
  118. memcpy(&b[28], &lnb_voltage, sizeof(u32));
  119. state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
  120. return 0;
  121. }
  122. static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
  123. {
  124. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  125. u8 b[] = { 0x00, 0xff, 0x00, 0x00,
  126. 0x00, 0x00, 0x00, 0x00,
  127. 0x00, 0x00 };
  128. if (cmd->msg_len > sizeof(b) - 4)
  129. return -EINVAL;
  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,
  137. enum fe_sec_tone_mode tone)
  138. {
  139. struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
  140. state->hi_band = (SEC_TONE_ON == tone);
  141. return 0;
  142. }
  143. static int ttusbdecfe_dvbs_set_voltage(struct dvb_frontend *fe,
  144. enum fe_sec_voltage 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 const 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 const 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 const struct dvb_frontend_ops ttusbdecfe_dvbt_ops = {
  197. .delsys = { SYS_DVBT },
  198. .info = {
  199. .name = "TechnoTrend/Hauppauge DEC2000-t Frontend",
  200. .frequency_min_hz = 51 * MHz,
  201. .frequency_max_hz = 858 * MHz,
  202. .frequency_stepsize_hz = 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 const struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
  215. .delsys = { SYS_DVBS },
  216. .info = {
  217. .name = "TechnoTrend/Hauppauge DEC3000-s Frontend",
  218. .frequency_min_hz = 950 * MHz,
  219. .frequency_max_hz = 2150 * MHz,
  220. .frequency_stepsize_hz = 125 * kHz,
  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);