gp8psk-fe.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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_frontend(struct dvb_frontend *fe)
  104. {
  105. struct gp8psk_fe_state *state = fe->demodulator_priv;
  106. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  107. u8 cmd[10];
  108. u32 freq = c->frequency * 1000;
  109. int gp_product_id = le16_to_cpu(state->d->udev->descriptor.idProduct);
  110. deb_fe("%s()\n", __func__);
  111. cmd[4] = freq & 0xff;
  112. cmd[5] = (freq >> 8) & 0xff;
  113. cmd[6] = (freq >> 16) & 0xff;
  114. cmd[7] = (freq >> 24) & 0xff;
  115. /* backwards compatibility: DVB-S + 8-PSK were used for Turbo-FEC */
  116. if (c->delivery_system == SYS_DVBS && c->modulation == PSK_8)
  117. c->delivery_system = SYS_TURBO;
  118. switch (c->delivery_system) {
  119. case SYS_DVBS:
  120. if (c->modulation != QPSK) {
  121. deb_fe("%s: unsupported modulation selected (%d)\n",
  122. __func__, c->modulation);
  123. return -EOPNOTSUPP;
  124. }
  125. c->fec_inner = FEC_AUTO;
  126. break;
  127. case SYS_DVBS2: /* kept for backwards compatibility */
  128. deb_fe("%s: DVB-S2 delivery system selected\n", __func__);
  129. break;
  130. case SYS_TURBO:
  131. deb_fe("%s: Turbo-FEC delivery system selected\n", __func__);
  132. break;
  133. default:
  134. deb_fe("%s: unsupported delivery system selected (%d)\n",
  135. __func__, c->delivery_system);
  136. return -EOPNOTSUPP;
  137. }
  138. cmd[0] = c->symbol_rate & 0xff;
  139. cmd[1] = (c->symbol_rate >> 8) & 0xff;
  140. cmd[2] = (c->symbol_rate >> 16) & 0xff;
  141. cmd[3] = (c->symbol_rate >> 24) & 0xff;
  142. switch (c->modulation) {
  143. case QPSK:
  144. if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
  145. if (gp8psk_tuned_to_DCII(fe))
  146. gp8psk_bcm4500_reload(state->d);
  147. switch (c->fec_inner) {
  148. case FEC_1_2:
  149. cmd[9] = 0; break;
  150. case FEC_2_3:
  151. cmd[9] = 1; break;
  152. case FEC_3_4:
  153. cmd[9] = 2; break;
  154. case FEC_5_6:
  155. cmd[9] = 3; break;
  156. case FEC_7_8:
  157. cmd[9] = 4; break;
  158. case FEC_AUTO:
  159. cmd[9] = 5; break;
  160. default:
  161. cmd[9] = 5; break;
  162. }
  163. if (c->delivery_system == SYS_TURBO)
  164. cmd[8] = ADV_MOD_TURBO_QPSK;
  165. else
  166. cmd[8] = ADV_MOD_DVB_QPSK;
  167. break;
  168. case PSK_8: /* PSK_8 is for compatibility with DN */
  169. cmd[8] = ADV_MOD_TURBO_8PSK;
  170. switch (c->fec_inner) {
  171. case FEC_2_3:
  172. cmd[9] = 0; break;
  173. case FEC_3_4:
  174. cmd[9] = 1; break;
  175. case FEC_3_5:
  176. cmd[9] = 2; break;
  177. case FEC_5_6:
  178. cmd[9] = 3; break;
  179. case FEC_8_9:
  180. cmd[9] = 4; break;
  181. default:
  182. cmd[9] = 0; break;
  183. }
  184. break;
  185. case QAM_16: /* QAM_16 is for compatibility with DN */
  186. cmd[8] = ADV_MOD_TURBO_16QAM;
  187. cmd[9] = 0;
  188. break;
  189. default: /* Unknown modulation */
  190. deb_fe("%s: unsupported modulation selected (%d)\n",
  191. __func__, c->modulation);
  192. return -EOPNOTSUPP;
  193. }
  194. if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
  195. gp8psk_set_tuner_mode(fe, 0);
  196. gp8psk_usb_out_op(state->d, TUNE_8PSK, 0, 0, cmd, 10);
  197. state->lock = 0;
  198. state->next_status_check = jiffies;
  199. state->status_check_interval = 200;
  200. return 0;
  201. }
  202. static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
  203. struct dvb_diseqc_master_cmd *m)
  204. {
  205. struct gp8psk_fe_state *st = fe->demodulator_priv;
  206. deb_fe("%s\n",__func__);
  207. if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, m->msg[0], 0,
  208. m->msg, m->msg_len)) {
  209. return -EINVAL;
  210. }
  211. return 0;
  212. }
  213. static int gp8psk_fe_send_diseqc_burst (struct dvb_frontend* fe,
  214. fe_sec_mini_cmd_t burst)
  215. {
  216. struct gp8psk_fe_state *st = fe->demodulator_priv;
  217. u8 cmd;
  218. deb_fe("%s\n",__func__);
  219. /* These commands are certainly wrong */
  220. cmd = (burst == SEC_MINI_A) ? 0x00 : 0x01;
  221. if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, cmd, 0,
  222. &cmd, 0)) {
  223. return -EINVAL;
  224. }
  225. return 0;
  226. }
  227. static int gp8psk_fe_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
  228. {
  229. struct gp8psk_fe_state* state = fe->demodulator_priv;
  230. if (gp8psk_usb_out_op(state->d,SET_22KHZ_TONE,
  231. (tone == SEC_TONE_ON), 0, NULL, 0)) {
  232. return -EINVAL;
  233. }
  234. return 0;
  235. }
  236. static int gp8psk_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage)
  237. {
  238. struct gp8psk_fe_state* state = fe->demodulator_priv;
  239. if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE,
  240. voltage == SEC_VOLTAGE_18, 0, NULL, 0)) {
  241. return -EINVAL;
  242. }
  243. return 0;
  244. }
  245. static int gp8psk_fe_enable_high_lnb_voltage(struct dvb_frontend* fe, long onoff)
  246. {
  247. struct gp8psk_fe_state* state = fe->demodulator_priv;
  248. return gp8psk_usb_out_op(state->d, USE_EXTRA_VOLT, onoff, 0,NULL,0);
  249. }
  250. static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long sw_cmd)
  251. {
  252. struct gp8psk_fe_state* state = fe->demodulator_priv;
  253. u8 cmd = sw_cmd & 0x7f;
  254. if (gp8psk_usb_out_op(state->d,SET_DN_SWITCH, cmd, 0,
  255. NULL, 0)) {
  256. return -EINVAL;
  257. }
  258. if (gp8psk_usb_out_op(state->d,SET_LNB_VOLTAGE, !!(sw_cmd & 0x80),
  259. 0, NULL, 0)) {
  260. return -EINVAL;
  261. }
  262. return 0;
  263. }
  264. static void gp8psk_fe_release(struct dvb_frontend* fe)
  265. {
  266. struct gp8psk_fe_state *state = fe->demodulator_priv;
  267. kfree(state);
  268. }
  269. static struct dvb_frontend_ops gp8psk_fe_ops;
  270. struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d)
  271. {
  272. struct gp8psk_fe_state *s = kzalloc(sizeof(struct gp8psk_fe_state), GFP_KERNEL);
  273. if (s == NULL)
  274. goto error;
  275. s->d = d;
  276. memcpy(&s->fe.ops, &gp8psk_fe_ops, sizeof(struct dvb_frontend_ops));
  277. s->fe.demodulator_priv = s;
  278. goto success;
  279. error:
  280. return NULL;
  281. success:
  282. return &s->fe;
  283. }
  284. static struct dvb_frontend_ops gp8psk_fe_ops = {
  285. .delsys = { SYS_DVBS },
  286. .info = {
  287. .name = "Genpix DVB-S",
  288. .frequency_min = 800000,
  289. .frequency_max = 2250000,
  290. .frequency_stepsize = 100,
  291. .symbol_rate_min = 1000000,
  292. .symbol_rate_max = 45000000,
  293. .symbol_rate_tolerance = 500, /* ppm */
  294. .caps = FE_CAN_INVERSION_AUTO |
  295. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  296. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  297. /*
  298. * FE_CAN_QAM_16 is for compatibility
  299. * (Myth incorrectly detects Turbo-QPSK as plain QAM-16)
  300. */
  301. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_TURBO_FEC
  302. },
  303. .release = gp8psk_fe_release,
  304. .init = NULL,
  305. .sleep = NULL,
  306. .set_frontend = gp8psk_fe_set_frontend,
  307. .get_tune_settings = gp8psk_fe_get_tune_settings,
  308. .read_status = gp8psk_fe_read_status,
  309. .read_ber = gp8psk_fe_read_ber,
  310. .read_signal_strength = gp8psk_fe_read_signal_strength,
  311. .read_snr = gp8psk_fe_read_snr,
  312. .read_ucblocks = gp8psk_fe_read_unc_blocks,
  313. .diseqc_send_master_cmd = gp8psk_fe_send_diseqc_msg,
  314. .diseqc_send_burst = gp8psk_fe_send_diseqc_burst,
  315. .set_tone = gp8psk_fe_set_tone,
  316. .set_voltage = gp8psk_fe_set_voltage,
  317. .dishnetwork_send_legacy_command = gp8psk_fe_send_legacy_dish_cmd,
  318. .enable_high_lnb_voltage = gp8psk_fe_enable_high_lnb_voltage
  319. };