ddbridge-mci.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * ddbridge-mci.h: Digital Devices micro code interface
  4. *
  5. * Copyright (C) 2017-2018 Digital Devices GmbH
  6. * Marcus Metzler <mocm@metzlerbros.de>
  7. * Ralph Metzler <rjkm@metzlerbros.de>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 only, as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #ifndef _DDBRIDGE_MCI_H_
  19. #define _DDBRIDGE_MCI_H_
  20. #define MCI_DEMOD_MAX 8
  21. #define MCI_TUNER_MAX 4
  22. #define DEMOD_UNUSED (0xFF)
  23. #define MCI_CONTROL (0x500)
  24. #define MCI_COMMAND (0x600)
  25. #define MCI_RESULT (0x680)
  26. #define MCI_COMMAND_SIZE (0x80)
  27. #define MCI_RESULT_SIZE (0x80)
  28. #define MCI_CONTROL_START_COMMAND (0x00000001)
  29. #define MCI_CONTROL_ENABLE_DONE_INTERRUPT (0x00000002)
  30. #define MCI_CONTROL_RESET (0x00008000)
  31. #define MCI_CONTROL_READY (0x00010000)
  32. #define SX8_TSCONFIG (0x280)
  33. #define SX8_TSCONFIG_MODE_MASK (0x00000003)
  34. #define SX8_TSCONFIG_MODE_OFF (0x00000000)
  35. #define SX8_TSCONFIG_MODE_NORMAL (0x00000001)
  36. #define SX8_TSCONFIG_MODE_IQ (0x00000003)
  37. /*
  38. * IQMode is only available on MaxSX8 on a single tuner
  39. *
  40. * IQ_MODE_SAMPLES
  41. * sampling rate is 1550/24 MHz (64.583 MHz)
  42. * channel agc is frozen, to allow stitching the FFT results together
  43. *
  44. * IQ_MODE_VTM
  45. * sampling rate is the supplied symbolrate
  46. * channel agc is active
  47. *
  48. * in both cases down sampling is done with a RRC Filter (currently fixed to
  49. * alpha = 0.05) which causes some (ca 5%) aliasing at the edges from
  50. * outside the spectrum
  51. */
  52. #define SX8_TSCONFIG_TSHEADER (0x00000004)
  53. #define SX8_TSCONFIG_BURST (0x00000008)
  54. #define SX8_TSCONFIG_BURSTSIZE_MASK (0x00000030)
  55. #define SX8_TSCONFIG_BURSTSIZE_2K (0x00000000)
  56. #define SX8_TSCONFIG_BURSTSIZE_4K (0x00000010)
  57. #define SX8_TSCONFIG_BURSTSIZE_8K (0x00000020)
  58. #define SX8_TSCONFIG_BURSTSIZE_16K (0x00000030)
  59. #define SX8_DEMOD_STOPPED (0)
  60. #define SX8_DEMOD_IQ_MODE (1)
  61. #define SX8_DEMOD_WAIT_SIGNAL (2)
  62. #define SX8_DEMOD_WAIT_MATYPE (3)
  63. #define SX8_DEMOD_TIMEOUT (14)
  64. #define SX8_DEMOD_LOCKED (15)
  65. #define MCI_CMD_STOP (0x01)
  66. #define MCI_CMD_GETSTATUS (0x02)
  67. #define MCI_CMD_GETSIGNALINFO (0x03)
  68. #define MCI_CMD_RFPOWER (0x04)
  69. #define MCI_CMD_SEARCH_DVBS (0x10)
  70. #define MCI_CMD_GET_IQSYMBOL (0x30)
  71. #define SX8_CMD_INPUT_ENABLE (0x40)
  72. #define SX8_CMD_INPUT_DISABLE (0x41)
  73. #define SX8_CMD_START_IQ (0x42)
  74. #define SX8_CMD_STOP_IQ (0x43)
  75. #define SX8_CMD_ENABLE_IQOUTPUT (0x44)
  76. #define SX8_CMD_DISABLE_IQOUTPUT (0x45)
  77. #define MCI_STATUS_OK (0x00)
  78. #define MCI_STATUS_UNSUPPORTED (0x80)
  79. #define MCI_STATUS_RETRY (0xFD)
  80. #define MCI_STATUS_NOT_READY (0xFE)
  81. #define MCI_STATUS_ERROR (0xFF)
  82. #define MCI_SUCCESS(status) ((status & MCI_STATUS_UNSUPPORTED) == 0)
  83. struct mci_command {
  84. union {
  85. u32 command_word;
  86. struct {
  87. u8 command;
  88. u8 tuner;
  89. u8 demod;
  90. u8 output;
  91. };
  92. };
  93. union {
  94. u32 params[31];
  95. struct {
  96. /*
  97. * Bit 0: DVB-S Enabled
  98. * Bit 1: DVB-S2 Enabled
  99. * Bit 7: InputStreamID
  100. */
  101. u8 flags;
  102. /*
  103. * Bit 0: QPSK,
  104. * Bit 1: 8PSK/8APSK
  105. * Bit 2: 16APSK
  106. * Bit 3: 32APSK
  107. * Bit 4: 64APSK
  108. * Bit 5: 128APSK
  109. * Bit 6: 256APSK
  110. */
  111. u8 s2_modulation_mask;
  112. u8 rsvd1;
  113. u8 retry;
  114. u32 frequency;
  115. u32 symbol_rate;
  116. u8 input_stream_id;
  117. u8 rsvd2[3];
  118. u32 scrambling_sequence_index;
  119. u32 frequency_range;
  120. } dvbs2_search;
  121. struct {
  122. u8 tap;
  123. u8 rsvd;
  124. u16 point;
  125. } get_iq_symbol;
  126. struct {
  127. /*
  128. * Bit 0: 0=VTM/1=SCAN
  129. * Bit 1: Set Gain
  130. */
  131. u8 flags;
  132. u8 roll_off;
  133. u8 rsvd1;
  134. u8 rsvd2;
  135. u32 frequency;
  136. u32 symbol_rate; /* Only in VTM mode */
  137. u16 gain;
  138. } sx8_start_iq;
  139. struct {
  140. /*
  141. * Bit 1:0 = STVVGLNA Gain.
  142. * 0 = AGC, 1 = 0dB, 2 = Minimum, 3 = Maximum
  143. */
  144. u8 flags;
  145. } sx8_input_enable;
  146. };
  147. };
  148. struct mci_result {
  149. union {
  150. u32 status_word;
  151. struct {
  152. u8 status;
  153. u8 mode;
  154. u16 time;
  155. };
  156. };
  157. union {
  158. u32 result[27];
  159. struct {
  160. /* 1 = DVB-S, 2 = DVB-S2X */
  161. u8 standard;
  162. /* puncture rate for DVB-S */
  163. u8 pls_code;
  164. /* 2-0: rolloff */
  165. u8 roll_off;
  166. u8 rsvd;
  167. /* actual frequency in Hz */
  168. u32 frequency;
  169. /* actual symbolrate in Hz */
  170. u32 symbol_rate;
  171. /* channel power in dBm x 100 */
  172. s16 channel_power;
  173. /* band power in dBm x 100 */
  174. s16 band_power;
  175. /*
  176. * SNR in dB x 100
  177. * Note: negative values are valid in DVB-S2
  178. */
  179. s16 signal_to_noise;
  180. s16 rsvd2;
  181. /*
  182. * Counter for packet errors
  183. * (set to 0 on start command)
  184. */
  185. u32 packet_errors;
  186. /* Bit error rate: PreRS in DVB-S, PreBCH in DVB-S2X */
  187. u32 ber_numerator;
  188. u32 ber_denominator;
  189. } dvbs2_signal_info;
  190. struct {
  191. s16 i;
  192. s16 q;
  193. } iq_symbol;
  194. };
  195. u32 version[4];
  196. };
  197. struct mci_base {
  198. struct list_head mci_list;
  199. void *key;
  200. struct ddb_link *link;
  201. struct completion completion;
  202. struct device *dev;
  203. struct mutex tuner_lock; /* concurrent tuner access lock */
  204. struct mutex mci_lock; /* concurrent MCI access lock */
  205. int count;
  206. int type;
  207. };
  208. struct mci {
  209. struct mci_base *base;
  210. struct dvb_frontend fe;
  211. int nr;
  212. int demod;
  213. int tuner;
  214. };
  215. struct mci_cfg {
  216. int type;
  217. struct dvb_frontend_ops *fe_ops;
  218. u32 base_size;
  219. u32 state_size;
  220. int (*init)(struct mci *mci);
  221. int (*base_init)(struct mci_base *mci_base);
  222. int (*set_input)(struct dvb_frontend *fe, int input);
  223. };
  224. /* defined in ddbridge-sx8.c */
  225. extern const struct mci_cfg ddb_max_sx8_cfg;
  226. int ddb_mci_cmd(struct mci *state, struct mci_command *command,
  227. struct mci_result *result);
  228. int ddb_mci_config(struct mci *state, u32 config);
  229. struct dvb_frontend
  230. *ddb_mci_attach(struct ddb_input *input, struct mci_cfg *cfg, int nr,
  231. int (**fn_set_input)(struct dvb_frontend *fe, int input));
  232. #endif /* _DDBRIDGE_MCI_H_ */