gp8psk-fe.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* DVB USB compliant Linux driver for the
  2. * - GENPIX 8pks/qpsk USB2.0 DVB-S module
  3. *
  4. * Copyright (C) 2006 Alan Nisota (alannisota@gmail.com)
  5. *
  6. * Thanks to GENPIX for the sample code used to implement this module.
  7. *
  8. * This module is based off the vp7045 and vp702x modules
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the Free
  12. * Software Foundation, version 2.
  13. *
  14. * see Documentation/dvb/README.dvb-usb for more information
  15. */
  16. #include "gp8psk.h"
  17. struct gp8psk_fe_state {
  18. struct dvb_frontend fe;
  19. struct dvb_usb_device *d;
  20. u16 snr;
  21. unsigned long next_snr_check;
  22. };
  23. static int gp8psk_fe_read_status(struct dvb_frontend* fe, fe_status_t *status)
  24. {
  25. struct gp8psk_fe_state *st = fe->demodulator_priv;
  26. u8 lock;
  27. if (gp8psk_usb_in_op(st->d, GET_SIGNAL_LOCK, 0, 0, &lock,1))
  28. return -EINVAL;
  29. if (lock)
  30. *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER;
  31. else
  32. *status = 0;
  33. return 0;
  34. }
  35. /* not supported by this Frontend */
  36. static int gp8psk_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
  37. {
  38. (void) fe;
  39. *ber = 0;
  40. return 0;
  41. }
  42. /* not supported by this Frontend */
  43. static int gp8psk_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
  44. {
  45. (void) fe;
  46. *unc = 0;
  47. return 0;
  48. }
  49. static int gp8psk_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
  50. {
  51. struct gp8psk_fe_state *st = fe->demodulator_priv;
  52. u8 buf[2];
  53. if (time_after(jiffies,st->next_snr_check)) {
  54. gp8psk_usb_in_op(st->d,GET_SIGNAL_STRENGTH,0,0,buf,2);
  55. *snr = (int)(buf[1]) << 8 | buf[0];
  56. /* snr is reported in dBu*256 */
  57. /* snr / 38.4 ~= 100% strength */
  58. /* snr * 17 returns 100% strength as 65535 */
  59. if (*snr <= 3855)
  60. *snr = (*snr<<4) + *snr; // snr * 17
  61. else
  62. *snr = 65535;
  63. st->next_snr_check = jiffies + (10*HZ)/1000;
  64. } else {
  65. *snr = st->snr;
  66. }
  67. return 0;
  68. }
  69. static int gp8psk_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
  70. {
  71. return gp8psk_fe_read_snr(fe, strength);
  72. }
  73. static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
  74. {
  75. tune->min_delay_ms = 800;
  76. return 0;
  77. }
  78. static int gp8psk_fe_set_frontend(struct dvb_frontend* fe,
  79. struct dvb_frontend_parameters *fep)
  80. {
  81. struct gp8psk_fe_state *state = fe->demodulator_priv;
  82. u8 cmd[10];
  83. u32 freq = fep->frequency * 1000;
  84. cmd[4] = freq & 0xff;
  85. cmd[5] = (freq >> 8) & 0xff;
  86. cmd[6] = (freq >> 16) & 0xff;
  87. cmd[7] = (freq >> 24) & 0xff;
  88. switch(fe->ops.info.type) {
  89. case FE_QPSK:
  90. cmd[0] = fep->u.qpsk.symbol_rate & 0xff;
  91. cmd[1] = (fep->u.qpsk.symbol_rate >> 8) & 0xff;
  92. cmd[2] = (fep->u.qpsk.symbol_rate >> 16) & 0xff;
  93. cmd[3] = (fep->u.qpsk.symbol_rate >> 24) & 0xff;
  94. cmd[8] = ADV_MOD_DVB_QPSK;
  95. cmd[9] = 0x03; /*ADV_MOD_FEC_XXX*/
  96. break;
  97. default:
  98. // other modes are unsuported right now
  99. cmd[0] = 0;
  100. cmd[1] = 0;
  101. cmd[2] = 0;
  102. cmd[3] = 0;
  103. cmd[8] = 0;
  104. cmd[9] = 0;
  105. break;
  106. }
  107. gp8psk_usb_out_op(state->d,TUNE_8PSK,0,0,cmd,10);
  108. state->next_snr_check = jiffies;
  109. return 0;
  110. }
  111. static int gp8psk_fe_get_frontend(struct dvb_frontend* fe,
  112. struct dvb_frontend_parameters *fep)
  113. {
  114. return 0;
  115. }
  116. static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
  117. struct dvb_diseqc_master_cmd *m)
  118. {
  119. struct gp8psk_fe_state *st = fe->demodulator_priv;
  120. deb_fe("%s\n",__FUNCTION__);
  121. if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, m->msg[0], 0,
  122. m->msg, m->msg_len)) {
  123. return -EINVAL;
  124. }
  125. return 0;
  126. }
  127. static int gp8psk_fe_send_diseqc_burst (struct dvb_frontend* fe,
  128. fe_sec_mini_cmd_t burst)
  129. {
  130. struct gp8psk_fe_state *st = fe->demodulator_priv;
  131. u8 cmd;
  132. deb_fe("%s\n",__FUNCTION__);
  133. /* These commands are certainly wrong */
  134. cmd = (burst == SEC_MINI_A) ? 0x00 : 0x01;
  135. if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, cmd, 0,
  136. &cmd, 0)) {
  137. return -EINVAL;
  138. }
  139. return 0;
  140. }
  141. static int gp8psk_fe_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
  142. {
  143. struct gp8psk_fe_state* state = fe->demodulator_priv;
  144. if (gp8psk_usb_out_op(state->d,SET_22KHZ_TONE,
  145. (tone == SEC_TONE_ON), 0, NULL, 0)) {
  146. return -EINVAL;
  147. }
  148. return 0;
  149. }
  150. static int gp8psk_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage)
  151. {
  152. struct gp8psk_fe_state* state = fe->demodulator_priv;
  153. if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE,
  154. voltage == SEC_VOLTAGE_18, 0, NULL, 0)) {
  155. return -EINVAL;
  156. }
  157. return 0;
  158. }
  159. static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long sw_cmd)
  160. {
  161. struct gp8psk_fe_state* state = fe->demodulator_priv;
  162. u8 cmd = sw_cmd & 0x7f;
  163. if (gp8psk_usb_out_op(state->d,SET_DN_SWITCH, cmd, 0,
  164. NULL, 0)) {
  165. return -EINVAL;
  166. }
  167. if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE, !!(sw_cmd & 0x80),
  168. 0, NULL, 0)) {
  169. return -EINVAL;
  170. }
  171. return 0;
  172. }
  173. static void gp8psk_fe_release(struct dvb_frontend* fe)
  174. {
  175. struct gp8psk_fe_state *state = fe->demodulator_priv;
  176. kfree(state);
  177. }
  178. static struct dvb_frontend_ops gp8psk_fe_ops;
  179. struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d)
  180. {
  181. struct gp8psk_fe_state *s = kzalloc(sizeof(struct gp8psk_fe_state), GFP_KERNEL);
  182. if (s == NULL)
  183. goto error;
  184. s->d = d;
  185. memcpy(&s->fe.ops, &gp8psk_fe_ops, sizeof(struct dvb_frontend_ops));
  186. s->fe.demodulator_priv = s;
  187. goto success;
  188. error:
  189. return NULL;
  190. success:
  191. return &s->fe;
  192. }
  193. static struct dvb_frontend_ops gp8psk_fe_ops = {
  194. .info = {
  195. .name = "Genpix 8psk-USB DVB-S",
  196. .type = FE_QPSK,
  197. .frequency_min = 950000,
  198. .frequency_max = 2150000,
  199. .frequency_stepsize = 100,
  200. .symbol_rate_min = 1000000,
  201. .symbol_rate_max = 45000000,
  202. .symbol_rate_tolerance = 500, /* ppm */
  203. .caps = FE_CAN_INVERSION_AUTO |
  204. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  205. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  206. FE_CAN_QPSK
  207. },
  208. .release = gp8psk_fe_release,
  209. .init = NULL,
  210. .sleep = NULL,
  211. .set_frontend = gp8psk_fe_set_frontend,
  212. .get_frontend = gp8psk_fe_get_frontend,
  213. .get_tune_settings = gp8psk_fe_get_tune_settings,
  214. .read_status = gp8psk_fe_read_status,
  215. .read_ber = gp8psk_fe_read_ber,
  216. .read_signal_strength = gp8psk_fe_read_signal_strength,
  217. .read_snr = gp8psk_fe_read_snr,
  218. .read_ucblocks = gp8psk_fe_read_unc_blocks,
  219. .diseqc_send_master_cmd = gp8psk_fe_send_diseqc_msg,
  220. .diseqc_send_burst = gp8psk_fe_send_diseqc_burst,
  221. .set_tone = gp8psk_fe_set_tone,
  222. .set_voltage = gp8psk_fe_set_voltage,
  223. .dishnetwork_send_legacy_command = gp8psk_fe_send_legacy_dish_cmd,
  224. };