dvb_dummy_fe.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Driver for Dummy Frontend
  4. *
  5. * Written by Emard <emard@softhome.net>
  6. */
  7. #include <linux/module.h>
  8. #include <linux/init.h>
  9. #include <linux/string.h>
  10. #include <linux/slab.h>
  11. #include <media/dvb_frontend.h>
  12. #include "dvb_dummy_fe.h"
  13. struct dvb_dummy_fe_state {
  14. struct dvb_frontend frontend;
  15. };
  16. static int dvb_dummy_fe_read_status(struct dvb_frontend *fe,
  17. enum fe_status *status)
  18. {
  19. *status = FE_HAS_SIGNAL
  20. | FE_HAS_CARRIER
  21. | FE_HAS_VITERBI
  22. | FE_HAS_SYNC
  23. | FE_HAS_LOCK;
  24. return 0;
  25. }
  26. static int dvb_dummy_fe_read_ber(struct dvb_frontend* fe, u32* ber)
  27. {
  28. *ber = 0;
  29. return 0;
  30. }
  31. static int dvb_dummy_fe_read_signal_strength(struct dvb_frontend* fe, u16* strength)
  32. {
  33. *strength = 0;
  34. return 0;
  35. }
  36. static int dvb_dummy_fe_read_snr(struct dvb_frontend* fe, u16* snr)
  37. {
  38. *snr = 0;
  39. return 0;
  40. }
  41. static int dvb_dummy_fe_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
  42. {
  43. *ucblocks = 0;
  44. return 0;
  45. }
  46. /*
  47. * Should only be implemented if it actually reads something from the hardware.
  48. * Also, it should check for the locks, in order to avoid report wrong data
  49. * to userspace.
  50. */
  51. static int dvb_dummy_fe_get_frontend(struct dvb_frontend *fe,
  52. struct dtv_frontend_properties *p)
  53. {
  54. return 0;
  55. }
  56. static int dvb_dummy_fe_set_frontend(struct dvb_frontend *fe)
  57. {
  58. if (fe->ops.tuner_ops.set_params) {
  59. fe->ops.tuner_ops.set_params(fe);
  60. if (fe->ops.i2c_gate_ctrl)
  61. fe->ops.i2c_gate_ctrl(fe, 0);
  62. }
  63. return 0;
  64. }
  65. static int dvb_dummy_fe_sleep(struct dvb_frontend* fe)
  66. {
  67. return 0;
  68. }
  69. static int dvb_dummy_fe_init(struct dvb_frontend* fe)
  70. {
  71. return 0;
  72. }
  73. static int dvb_dummy_fe_set_tone(struct dvb_frontend *fe,
  74. enum fe_sec_tone_mode tone)
  75. {
  76. return 0;
  77. }
  78. static int dvb_dummy_fe_set_voltage(struct dvb_frontend *fe,
  79. enum fe_sec_voltage voltage)
  80. {
  81. return 0;
  82. }
  83. static void dvb_dummy_fe_release(struct dvb_frontend* fe)
  84. {
  85. struct dvb_dummy_fe_state* state = fe->demodulator_priv;
  86. kfree(state);
  87. }
  88. static const struct dvb_frontend_ops dvb_dummy_fe_ofdm_ops;
  89. struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void)
  90. {
  91. struct dvb_dummy_fe_state* state = NULL;
  92. /* allocate memory for the internal state */
  93. state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
  94. if (!state)
  95. return NULL;
  96. /* create dvb_frontend */
  97. memcpy(&state->frontend.ops, &dvb_dummy_fe_ofdm_ops, sizeof(struct dvb_frontend_ops));
  98. state->frontend.demodulator_priv = state;
  99. return &state->frontend;
  100. }
  101. static const struct dvb_frontend_ops dvb_dummy_fe_qpsk_ops;
  102. struct dvb_frontend *dvb_dummy_fe_qpsk_attach(void)
  103. {
  104. struct dvb_dummy_fe_state* state = NULL;
  105. /* allocate memory for the internal state */
  106. state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
  107. if (!state)
  108. return NULL;
  109. /* create dvb_frontend */
  110. memcpy(&state->frontend.ops, &dvb_dummy_fe_qpsk_ops, sizeof(struct dvb_frontend_ops));
  111. state->frontend.demodulator_priv = state;
  112. return &state->frontend;
  113. }
  114. static const struct dvb_frontend_ops dvb_dummy_fe_qam_ops;
  115. struct dvb_frontend *dvb_dummy_fe_qam_attach(void)
  116. {
  117. struct dvb_dummy_fe_state* state = NULL;
  118. /* allocate memory for the internal state */
  119. state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
  120. if (!state)
  121. return NULL;
  122. /* create dvb_frontend */
  123. memcpy(&state->frontend.ops, &dvb_dummy_fe_qam_ops, sizeof(struct dvb_frontend_ops));
  124. state->frontend.demodulator_priv = state;
  125. return &state->frontend;
  126. }
  127. static const struct dvb_frontend_ops dvb_dummy_fe_ofdm_ops = {
  128. .delsys = { SYS_DVBT },
  129. .info = {
  130. .name = "Dummy DVB-T",
  131. .frequency_min_hz = 0,
  132. .frequency_max_hz = 863250 * kHz,
  133. .frequency_stepsize_hz = 62500,
  134. .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  135. FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
  136. FE_CAN_FEC_7_8 | FE_CAN_FEC_8_9 | FE_CAN_FEC_AUTO |
  137. FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  138. FE_CAN_TRANSMISSION_MODE_AUTO |
  139. FE_CAN_GUARD_INTERVAL_AUTO |
  140. FE_CAN_HIERARCHY_AUTO,
  141. },
  142. .release = dvb_dummy_fe_release,
  143. .init = dvb_dummy_fe_init,
  144. .sleep = dvb_dummy_fe_sleep,
  145. .set_frontend = dvb_dummy_fe_set_frontend,
  146. .get_frontend = dvb_dummy_fe_get_frontend,
  147. .read_status = dvb_dummy_fe_read_status,
  148. .read_ber = dvb_dummy_fe_read_ber,
  149. .read_signal_strength = dvb_dummy_fe_read_signal_strength,
  150. .read_snr = dvb_dummy_fe_read_snr,
  151. .read_ucblocks = dvb_dummy_fe_read_ucblocks,
  152. };
  153. static const struct dvb_frontend_ops dvb_dummy_fe_qam_ops = {
  154. .delsys = { SYS_DVBC_ANNEX_A },
  155. .info = {
  156. .name = "Dummy DVB-C",
  157. .frequency_min_hz = 51 * MHz,
  158. .frequency_max_hz = 858 * MHz,
  159. .frequency_stepsize_hz = 62500,
  160. .symbol_rate_min = (57840000 / 2) / 64, /* SACLK/64 == (XIN/2)/64 */
  161. .symbol_rate_max = (57840000 / 2) / 4, /* SACLK/4 */
  162. .caps = FE_CAN_QAM_16 | FE_CAN_QAM_32 | FE_CAN_QAM_64 |
  163. FE_CAN_QAM_128 | FE_CAN_QAM_256 |
  164. FE_CAN_FEC_AUTO | FE_CAN_INVERSION_AUTO
  165. },
  166. .release = dvb_dummy_fe_release,
  167. .init = dvb_dummy_fe_init,
  168. .sleep = dvb_dummy_fe_sleep,
  169. .set_frontend = dvb_dummy_fe_set_frontend,
  170. .get_frontend = dvb_dummy_fe_get_frontend,
  171. .read_status = dvb_dummy_fe_read_status,
  172. .read_ber = dvb_dummy_fe_read_ber,
  173. .read_signal_strength = dvb_dummy_fe_read_signal_strength,
  174. .read_snr = dvb_dummy_fe_read_snr,
  175. .read_ucblocks = dvb_dummy_fe_read_ucblocks,
  176. };
  177. static const struct dvb_frontend_ops dvb_dummy_fe_qpsk_ops = {
  178. .delsys = { SYS_DVBS },
  179. .info = {
  180. .name = "Dummy DVB-S",
  181. .frequency_min_hz = 950 * MHz,
  182. .frequency_max_hz = 2150 * MHz,
  183. .frequency_stepsize_hz = 250 * kHz,
  184. .frequency_tolerance_hz = 29500 * kHz,
  185. .symbol_rate_min = 1000000,
  186. .symbol_rate_max = 45000000,
  187. .caps = FE_CAN_INVERSION_AUTO |
  188. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  189. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  190. FE_CAN_QPSK
  191. },
  192. .release = dvb_dummy_fe_release,
  193. .init = dvb_dummy_fe_init,
  194. .sleep = dvb_dummy_fe_sleep,
  195. .set_frontend = dvb_dummy_fe_set_frontend,
  196. .get_frontend = dvb_dummy_fe_get_frontend,
  197. .read_status = dvb_dummy_fe_read_status,
  198. .read_ber = dvb_dummy_fe_read_ber,
  199. .read_signal_strength = dvb_dummy_fe_read_signal_strength,
  200. .read_snr = dvb_dummy_fe_read_snr,
  201. .read_ucblocks = dvb_dummy_fe_read_ucblocks,
  202. .set_voltage = dvb_dummy_fe_set_voltage,
  203. .set_tone = dvb_dummy_fe_set_tone,
  204. };
  205. MODULE_DESCRIPTION("DVB DUMMY Frontend");
  206. MODULE_AUTHOR("Emard");
  207. MODULE_LICENSE("GPL");
  208. EXPORT_SYMBOL(dvb_dummy_fe_ofdm_attach);
  209. EXPORT_SYMBOL(dvb_dummy_fe_qam_attach);
  210. EXPORT_SYMBOL(dvb_dummy_fe_qpsk_attach);