ddbridge-dummy-fe.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Driver for Dummy Frontend
  4. *
  5. * Written by Emard <[email protected]>
  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 "ddbridge-dummy-fe.h"
  13. struct ddbridge_dummy_fe_state {
  14. struct dvb_frontend frontend;
  15. };
  16. static int ddbridge_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 ddbridge_dummy_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
  27. {
  28. *ber = 0;
  29. return 0;
  30. }
  31. static int ddbridge_dummy_fe_read_signal_strength(struct dvb_frontend *fe,
  32. u16 *strength)
  33. {
  34. *strength = 0;
  35. return 0;
  36. }
  37. static int ddbridge_dummy_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
  38. {
  39. *snr = 0;
  40. return 0;
  41. }
  42. static int ddbridge_dummy_fe_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
  43. {
  44. *ucblocks = 0;
  45. return 0;
  46. }
  47. /*
  48. * Should only be implemented if it actually reads something from the hardware.
  49. * Also, it should check for the locks, in order to avoid report wrong data
  50. * to userspace.
  51. */
  52. static int ddbridge_dummy_fe_get_frontend(struct dvb_frontend *fe,
  53. struct dtv_frontend_properties *p)
  54. {
  55. return 0;
  56. }
  57. static int ddbridge_dummy_fe_set_frontend(struct dvb_frontend *fe)
  58. {
  59. if (fe->ops.tuner_ops.set_params) {
  60. fe->ops.tuner_ops.set_params(fe);
  61. if (fe->ops.i2c_gate_ctrl)
  62. fe->ops.i2c_gate_ctrl(fe, 0);
  63. }
  64. return 0;
  65. }
  66. static int ddbridge_dummy_fe_sleep(struct dvb_frontend *fe)
  67. {
  68. return 0;
  69. }
  70. static int ddbridge_dummy_fe_init(struct dvb_frontend *fe)
  71. {
  72. return 0;
  73. }
  74. static void ddbridge_dummy_fe_release(struct dvb_frontend *fe)
  75. {
  76. struct ddbridge_dummy_fe_state *state = fe->demodulator_priv;
  77. kfree(state);
  78. }
  79. static const struct dvb_frontend_ops ddbridge_dummy_fe_qam_ops;
  80. struct dvb_frontend *ddbridge_dummy_fe_qam_attach(void)
  81. {
  82. struct ddbridge_dummy_fe_state *state = NULL;
  83. /* allocate memory for the internal state */
  84. state = kzalloc(sizeof(struct ddbridge_dummy_fe_state), GFP_KERNEL);
  85. if (!state)
  86. return NULL;
  87. /* create dvb_frontend */
  88. memcpy(&state->frontend.ops,
  89. &ddbridge_dummy_fe_qam_ops,
  90. sizeof(struct dvb_frontend_ops));
  91. state->frontend.demodulator_priv = state;
  92. return &state->frontend;
  93. }
  94. EXPORT_SYMBOL_GPL(ddbridge_dummy_fe_qam_attach);
  95. static const struct dvb_frontend_ops ddbridge_dummy_fe_qam_ops = {
  96. .delsys = { SYS_DVBC_ANNEX_A },
  97. .info = {
  98. .name = "ddbridge dummy DVB-C",
  99. .frequency_min_hz = 51 * MHz,
  100. .frequency_max_hz = 858 * MHz,
  101. .frequency_stepsize_hz = 62500,
  102. /* symbol_rate_min: SACLK/64 == (XIN/2)/64 */
  103. .symbol_rate_min = (57840000 / 2) / 64,
  104. .symbol_rate_max = (57840000 / 2) / 4, /* SACLK/4 */
  105. .caps = FE_CAN_QAM_16 |
  106. FE_CAN_QAM_32 |
  107. FE_CAN_QAM_64 |
  108. FE_CAN_QAM_128 |
  109. FE_CAN_QAM_256 |
  110. FE_CAN_FEC_AUTO |
  111. FE_CAN_INVERSION_AUTO
  112. },
  113. .release = ddbridge_dummy_fe_release,
  114. .init = ddbridge_dummy_fe_init,
  115. .sleep = ddbridge_dummy_fe_sleep,
  116. .set_frontend = ddbridge_dummy_fe_set_frontend,
  117. .get_frontend = ddbridge_dummy_fe_get_frontend,
  118. .read_status = ddbridge_dummy_fe_read_status,
  119. .read_ber = ddbridge_dummy_fe_read_ber,
  120. .read_signal_strength = ddbridge_dummy_fe_read_signal_strength,
  121. .read_snr = ddbridge_dummy_fe_read_snr,
  122. .read_ucblocks = ddbridge_dummy_fe_read_ucblocks,
  123. };
  124. MODULE_DESCRIPTION("ddbridge dummy Frontend");
  125. MODULE_AUTHOR("Emard");
  126. MODULE_LICENSE("GPL");