gp8psk-fe.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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_tuned_to_DCII(struct dvb_frontend *fe)
  27. {
  28. struct gp8psk_fe_state *st = fe->demodulator_priv;
  29. u8 status;
  30. gp8psk_usb_in_op(st->d, GET_8PSK_CONFIG, 0, 0, &status, 1);
  31. return status & bmDCtuned;
  32. }
  33. static int gp8psk_set_tuner_mode(struct dvb_frontend *fe, int mode)
  34. {
  35. struct gp8psk_fe_state *state = fe->demodulator_priv;
  36. return gp8psk_usb_out_op(state->d, SET_8PSK_CONFIG, mode, 0, NULL, 0);
  37. }
  38. static int gp8psk_fe_update_status(struct gp8psk_fe_state *st)
  39. {
  40. u8 buf[6];
  41. if (time_after(jiffies,st->next_status_check)) {
  42. gp8psk_usb_in_op(st->d, GET_SIGNAL_LOCK, 0,0,&st->lock,1);
  43. gp8psk_usb_in_op(st->d, GET_SIGNAL_STRENGTH, 0,0,buf,6);
  44. st->snr = (buf[1]) << 8 | buf[0];
  45. st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
  46. }
  47. return 0;
  48. }
  49. static int gp8psk_fe_read_status(struct dvb_frontend* fe, fe_status_t *status)
  50. {
  51. struct gp8psk_fe_state *st = fe->demodulator_priv;
  52. gp8psk_fe_update_status(st);
  53. if (st->lock)
  54. *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER;
  55. else
  56. *status = 0;
  57. if (*status & FE_HAS_LOCK)
  58. st->status_check_interval = 1000;
  59. else
  60. st->status_check_interval = 100;
  61. return 0;
  62. }
  63. /* not supported by this Frontend */
  64. static int gp8psk_fe_read_ber(struct dvb_frontend* fe, u32 *ber)
  65. {
  66. (void) fe;
  67. *ber = 0;
  68. return 0;
  69. }
  70. /* not supported by this Frontend */
  71. static int gp8psk_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
  72. {
  73. (void) fe;
  74. *unc = 0;
  75. return 0;
  76. }
  77. static int gp8psk_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
  78. {
  79. struct gp8psk_fe_state *st = fe->demodulator_priv;
  80. gp8psk_fe_update_status(st);
  81. /* snr is reported in dBu*256 */
  82. *snr = st->snr;
  83. return 0;
  84. }
  85. static int gp8psk_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
  86. {
  87. struct gp8psk_fe_state *st = fe->demodulator_priv;
  88. gp8psk_fe_update_status(st);
  89. /* snr is reported in dBu*256 */
  90. /* snr / 38.4 ~= 100% strength */
  91. /* snr * 17 returns 100% strength as 65535 */
  92. if (st->snr > 0xf00)
  93. *strength = 0xffff;
  94. else
  95. *strength = (st->snr << 4) + st->snr; /* snr*17 */
  96. return 0;
  97. }
  98. static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
  99. {
  100. tune->min_delay_ms = 800;
  101. return 0;
  102. }
  103. static int gp8psk_fe_set_property(struct dvb_frontend *fe,
  104. struct dtv_property *tvp)
  105. {
  106. deb_fe("%s(..)\n", __func__);
  107. return 0;
  108. }
  109. static int gp8psk_fe_get_property(struct dvb_frontend *fe,
  110. struct dtv_property *tvp)
  111. {
  112. deb_fe("%s(..)\n", __func__);
  113. return 0;
  114. }
  115. static int gp8psk_fe_set_frontend(struct dvb_frontend* fe,
  116. struct dvb_frontend_parameters *fep)
  117. {
  118. struct gp8psk_fe_state *state = fe->demodulator_priv;
  119. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  120. u8 cmd[10];
  121. u32 freq = fep->frequency * 1000;
  122. int gp_product_id = le16_to_cpu(state->d->udev->descriptor.idProduct);
  123. deb_fe("%s()\n", __func__);
  124. cmd[4] = freq & 0xff;
  125. cmd[5] = (freq >> 8) & 0xff;
  126. cmd[6] = (freq >> 16) & 0xff;
  127. cmd[7] = (freq >> 24) & 0xff;
  128. switch (c->delivery_system) {
  129. case SYS_DVBS:
  130. /* Allow QPSK and 8PSK (even for DVB-S) */
  131. if (c->modulation != QPSK && c->modulation != PSK_8) {
  132. deb_fe("%s: unsupported modulation selected (%d)\n",
  133. __func__, c->modulation);
  134. return -EOPNOTSUPP;
  135. }
  136. c->fec_inner = FEC_AUTO;
  137. break;
  138. case SYS_DVBS2:
  139. deb_fe("%s: DVB-S2 delivery system selected\n", __func__);
  140. break;
  141. default:
  142. deb_fe("%s: unsupported delivery system selected (%d)\n",
  143. __func__, c->delivery_system);
  144. return -EOPNOTSUPP;
  145. }
  146. cmd[0] = c->symbol_rate & 0xff;
  147. cmd[1] = (c->symbol_rate >> 8) & 0xff;
  148. cmd[2] = (c->symbol_rate >> 16) & 0xff;
  149. cmd[3] = (c->symbol_rate >> 24) & 0xff;
  150. switch (c->modulation) {
  151. case QPSK:
  152. if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
  153. if (gp8psk_tuned_to_DCII(fe))
  154. gp8psk_bcm4500_reload(state->d);
  155. switch (c->fec_inner) {
  156. case FEC_1_2:
  157. cmd[9] = 0; break;
  158. case FEC_2_3:
  159. cmd[9] = 1; break;
  160. case FEC_3_4:
  161. cmd[9] = 2; break;
  162. case FEC_5_6:
  163. cmd[9] = 3; break;
  164. case FEC_7_8:
  165. cmd[9] = 4; break;
  166. case FEC_AUTO:
  167. cmd[9] = 5; break;
  168. default:
  169. cmd[9] = 5; break;
  170. }
  171. cmd[8] = ADV_MOD_DVB_QPSK;
  172. break;
  173. case PSK_8: /* PSK_8 is for compatibility with DN */
  174. cmd[8] = ADV_MOD_TURBO_8PSK;
  175. switch (c->fec_inner) {
  176. case FEC_2_3:
  177. cmd[9] = 0; break;
  178. case FEC_3_4:
  179. cmd[9] = 1; break;
  180. case FEC_3_5:
  181. cmd[9] = 2; break;
  182. case FEC_5_6:
  183. cmd[9] = 3; break;
  184. case FEC_8_9:
  185. cmd[9] = 4; break;
  186. default:
  187. cmd[9] = 0; break;
  188. }
  189. break;
  190. case QAM_16: /* QAM_16 is for compatibility with DN */
  191. cmd[8] = ADV_MOD_TURBO_16QAM;
  192. cmd[9] = 0;
  193. break;
  194. default: /* Unknown modulation */
  195. deb_fe("%s: unsupported modulation selected (%d)\n",
  196. __func__, c->modulation);
  197. return -EOPNOTSUPP;
  198. }
  199. if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
  200. gp8psk_set_tuner_mode(fe, 0);
  201. gp8psk_usb_out_op(state->d, TUNE_8PSK, 0, 0, cmd, 10);
  202. state->lock = 0;
  203. state->next_status_check = jiffies;
  204. state->status_check_interval = 200;
  205. return 0;
  206. }
  207. static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
  208. struct dvb_diseqc_master_cmd *m)
  209. {
  210. struct gp8psk_fe_state *st = fe->demodulator_priv;
  211. deb_fe("%s\n",__func__);
  212. if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, m->msg[0], 0,
  213. m->msg, m->msg_len)) {
  214. return -EINVAL;
  215. }
  216. return 0;
  217. }
  218. static int gp8psk_fe_send_diseqc_burst (struct dvb_frontend* fe,
  219. fe_sec_mini_cmd_t burst)
  220. {
  221. struct gp8psk_fe_state *st = fe->demodulator_priv;
  222. u8 cmd;
  223. deb_fe("%s\n",__func__);
  224. /* These commands are certainly wrong */
  225. cmd = (burst == SEC_MINI_A) ? 0x00 : 0x01;
  226. if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, cmd, 0,
  227. &cmd, 0)) {
  228. return -EINVAL;
  229. }
  230. return 0;
  231. }
  232. static int gp8psk_fe_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
  233. {
  234. struct gp8psk_fe_state* state = fe->demodulator_priv;
  235. if (gp8psk_usb_out_op(state->d,SET_22KHZ_TONE,
  236. (tone == SEC_TONE_ON), 0, NULL, 0)) {
  237. return -EINVAL;
  238. }
  239. return 0;
  240. }
  241. static int gp8psk_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage)
  242. {
  243. struct gp8psk_fe_state* state = fe->demodulator_priv;
  244. if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE,
  245. voltage == SEC_VOLTAGE_18, 0, NULL, 0)) {
  246. return -EINVAL;
  247. }
  248. return 0;
  249. }
  250. static int gp8psk_fe_enable_high_lnb_voltage(struct dvb_frontend* fe, long onoff)
  251. {
  252. struct gp8psk_fe_state* state = fe->demodulator_priv;
  253. return gp8psk_usb_out_op(state->d, USE_EXTRA_VOLT, onoff, 0,NULL,0);
  254. }
  255. static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long sw_cmd)
  256. {
  257. struct gp8psk_fe_state* state = fe->demodulator_priv;
  258. u8 cmd = sw_cmd & 0x7f;
  259. if (gp8psk_usb_out_op(state->d,SET_DN_SWITCH, cmd, 0,
  260. NULL, 0)) {
  261. return -EINVAL;
  262. }
  263. if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE, !!(sw_cmd & 0x80),
  264. 0, NULL, 0)) {
  265. return -EINVAL;
  266. }
  267. return 0;
  268. }
  269. static void gp8psk_fe_release(struct dvb_frontend* fe)
  270. {
  271. struct gp8psk_fe_state *state = fe->demodulator_priv;
  272. kfree(state);
  273. }
  274. static struct dvb_frontend_ops gp8psk_fe_ops;
  275. struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d)
  276. {
  277. struct gp8psk_fe_state *s = kzalloc(sizeof(struct gp8psk_fe_state), GFP_KERNEL);
  278. if (s == NULL)
  279. goto error;
  280. s->d = d;
  281. memcpy(&s->fe.ops, &gp8psk_fe_ops, sizeof(struct dvb_frontend_ops));
  282. s->fe.demodulator_priv = s;
  283. goto success;
  284. error:
  285. return NULL;
  286. success:
  287. return &s->fe;
  288. }
  289. static struct dvb_frontend_ops gp8psk_fe_ops = {
  290. .info = {
  291. .name = "Genpix DVB-S",
  292. .type = FE_QPSK,
  293. .frequency_min = 800000,
  294. .frequency_max = 2250000,
  295. .frequency_stepsize = 100,
  296. .symbol_rate_min = 1000000,
  297. .symbol_rate_max = 45000000,
  298. .symbol_rate_tolerance = 500, /* ppm */
  299. .caps = FE_CAN_INVERSION_AUTO |
  300. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  301. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  302. /*
  303. * FE_CAN_QAM_16 is for compatibility
  304. * (Myth incorrectly detects Turbo-QPSK as plain QAM-16)
  305. */
  306. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_TURBO_FEC
  307. },
  308. .release = gp8psk_fe_release,
  309. .init = NULL,
  310. .sleep = NULL,
  311. .set_property = gp8psk_fe_set_property,
  312. .get_property = gp8psk_fe_get_property,
  313. .set_frontend = gp8psk_fe_set_frontend,
  314. .get_tune_settings = gp8psk_fe_get_tune_settings,
  315. .read_status = gp8psk_fe_read_status,
  316. .read_ber = gp8psk_fe_read_ber,
  317. .read_signal_strength = gp8psk_fe_read_signal_strength,
  318. .read_snr = gp8psk_fe_read_snr,
  319. .read_ucblocks = gp8psk_fe_read_unc_blocks,
  320. .diseqc_send_master_cmd = gp8psk_fe_send_diseqc_msg,
  321. .diseqc_send_burst = gp8psk_fe_send_diseqc_burst,
  322. .set_tone = gp8psk_fe_set_tone,
  323. .set_voltage = gp8psk_fe_set_voltage,
  324. .dishnetwork_send_legacy_command = gp8psk_fe_send_legacy_dish_cmd,
  325. .enable_high_lnb_voltage = gp8psk_fe_enable_high_lnb_voltage
  326. };