gp8psk-fe.c 7.1 KB

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