gp8psk-fe.c 9.3 KB

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