c8sectpfe-dvb.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * c8sectpfe-dvb.c - C8SECTPFE STi DVB driver
  4. *
  5. * Copyright (c) STMicroelectronics 2015
  6. *
  7. * Author Peter Griffin <peter.griffin@linaro.org>
  8. *
  9. */
  10. #include <linux/completion.h>
  11. #include <linux/delay.h>
  12. #include <linux/i2c.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/version.h>
  15. #include <dt-bindings/media/c8sectpfe.h>
  16. #include "c8sectpfe-common.h"
  17. #include "c8sectpfe-core.h"
  18. #include "c8sectpfe-dvb.h"
  19. #include "dvb-pll.h"
  20. #include "lnbh24.h"
  21. #include "stv0367.h"
  22. #include "stv0367_priv.h"
  23. #include "stv6110x.h"
  24. #include "stv090x.h"
  25. #include "tda18212.h"
  26. static inline const char *dvb_card_str(unsigned int c)
  27. {
  28. switch (c) {
  29. case STV0367_TDA18212_NIMA_1: return "STV0367_TDA18212_NIMA_1";
  30. case STV0367_TDA18212_NIMA_2: return "STV0367_TDA18212_NIMA_2";
  31. case STV0367_TDA18212_NIMB_1: return "STV0367_TDA18212_NIMB_1";
  32. case STV0367_TDA18212_NIMB_2: return "STV0367_TDA18212_NIMB_2";
  33. case STV0903_6110_LNB24_NIMA: return "STV0903_6110_LNB24_NIMA";
  34. case STV0903_6110_LNB24_NIMB: return "STV0903_6110_LNB24_NIMB";
  35. default: return "unknown dvb frontend card";
  36. }
  37. }
  38. static struct stv090x_config stv090x_config = {
  39. .device = STV0903,
  40. .demod_mode = STV090x_SINGLE,
  41. .clk_mode = STV090x_CLK_EXT,
  42. .xtal = 16000000,
  43. .address = 0x69,
  44. .ts1_mode = STV090x_TSMODE_SERIAL_CONTINUOUS,
  45. .ts2_mode = STV090x_TSMODE_SERIAL_CONTINUOUS,
  46. .repeater_level = STV090x_RPTLEVEL_64,
  47. .tuner_init = NULL,
  48. .tuner_set_mode = NULL,
  49. .tuner_set_frequency = NULL,
  50. .tuner_get_frequency = NULL,
  51. .tuner_set_bandwidth = NULL,
  52. .tuner_get_bandwidth = NULL,
  53. .tuner_set_bbgain = NULL,
  54. .tuner_get_bbgain = NULL,
  55. .tuner_set_refclk = NULL,
  56. .tuner_get_status = NULL,
  57. };
  58. static struct stv6110x_config stv6110x_config = {
  59. .addr = 0x60,
  60. .refclk = 16000000,
  61. };
  62. #define NIMA 0
  63. #define NIMB 1
  64. static struct stv0367_config stv0367_tda18212_config[] = {
  65. {
  66. .demod_address = 0x1c,
  67. .xtal = 16000000,
  68. .if_khz = 4500,
  69. .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
  70. .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
  71. .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
  72. }, {
  73. .demod_address = 0x1d,
  74. .xtal = 16000000,
  75. .if_khz = 4500,
  76. .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
  77. .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
  78. .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
  79. }, {
  80. .demod_address = 0x1e,
  81. .xtal = 16000000,
  82. .if_khz = 4500,
  83. .if_iq_mode = FE_TER_NORMAL_IF_TUNER,
  84. .ts_mode = STV0367_SERIAL_PUNCT_CLOCK,
  85. .clk_pol = STV0367_CLOCKPOLARITY_DEFAULT,
  86. },
  87. };
  88. static struct tda18212_config tda18212_conf = {
  89. .if_dvbt_6 = 4150,
  90. .if_dvbt_7 = 4150,
  91. .if_dvbt_8 = 4500,
  92. .if_dvbc = 5000,
  93. };
  94. int c8sectpfe_frontend_attach(struct dvb_frontend **fe,
  95. struct c8sectpfe *c8sectpfe,
  96. struct channel_info *tsin, int chan_num)
  97. {
  98. struct tda18212_config *tda18212;
  99. const struct stv6110x_devctl *fe2;
  100. struct i2c_client *client;
  101. struct i2c_board_info tda18212_info = {
  102. .type = "tda18212",
  103. .addr = 0x60,
  104. };
  105. if (!tsin)
  106. return -EINVAL;
  107. switch (tsin->dvb_card) {
  108. case STV0367_TDA18212_NIMA_1:
  109. case STV0367_TDA18212_NIMA_2:
  110. case STV0367_TDA18212_NIMB_1:
  111. case STV0367_TDA18212_NIMB_2:
  112. if (tsin->dvb_card == STV0367_TDA18212_NIMA_1)
  113. *fe = dvb_attach(stv0367ter_attach,
  114. &stv0367_tda18212_config[0],
  115. tsin->i2c_adapter);
  116. else if (tsin->dvb_card == STV0367_TDA18212_NIMB_1)
  117. *fe = dvb_attach(stv0367ter_attach,
  118. &stv0367_tda18212_config[1],
  119. tsin->i2c_adapter);
  120. else
  121. *fe = dvb_attach(stv0367ter_attach,
  122. &stv0367_tda18212_config[2],
  123. tsin->i2c_adapter);
  124. if (!*fe) {
  125. dev_err(c8sectpfe->device,
  126. "%s: stv0367ter_attach failed for NIM card %s\n"
  127. , __func__, dvb_card_str(tsin->dvb_card));
  128. return -ENODEV;
  129. };
  130. /*
  131. * init the demod so that i2c gate_ctrl
  132. * to the tuner works correctly
  133. */
  134. (*fe)->ops.init(*fe);
  135. /* Allocate the tda18212 structure */
  136. tda18212 = devm_kzalloc(c8sectpfe->device,
  137. sizeof(struct tda18212_config),
  138. GFP_KERNEL);
  139. if (!tda18212) {
  140. dev_err(c8sectpfe->device,
  141. "%s: devm_kzalloc failed\n", __func__);
  142. return -ENOMEM;
  143. }
  144. memcpy(tda18212, &tda18212_conf,
  145. sizeof(struct tda18212_config));
  146. tda18212->fe = (*fe);
  147. tda18212_info.platform_data = tda18212;
  148. /* attach tuner */
  149. request_module("tda18212");
  150. client = i2c_new_device(tsin->i2c_adapter, &tda18212_info);
  151. if (!client || !client->dev.driver) {
  152. dvb_frontend_detach(*fe);
  153. return -ENODEV;
  154. }
  155. if (!try_module_get(client->dev.driver->owner)) {
  156. i2c_unregister_device(client);
  157. dvb_frontend_detach(*fe);
  158. return -ENODEV;
  159. }
  160. tsin->i2c_client = client;
  161. break;
  162. case STV0903_6110_LNB24_NIMA:
  163. *fe = dvb_attach(stv090x_attach, &stv090x_config,
  164. tsin->i2c_adapter, STV090x_DEMODULATOR_0);
  165. if (!*fe) {
  166. dev_err(c8sectpfe->device, "%s: stv090x_attach failed\n"
  167. "\tfor NIM card %s\n",
  168. __func__, dvb_card_str(tsin->dvb_card));
  169. return -ENODEV;
  170. }
  171. fe2 = dvb_attach(stv6110x_attach, *fe,
  172. &stv6110x_config, tsin->i2c_adapter);
  173. if (!fe2) {
  174. dev_err(c8sectpfe->device,
  175. "%s: stv6110x_attach failed for NIM card %s\n"
  176. , __func__, dvb_card_str(tsin->dvb_card));
  177. return -ENODEV;
  178. };
  179. stv090x_config.tuner_init = fe2->tuner_init;
  180. stv090x_config.tuner_set_mode = fe2->tuner_set_mode;
  181. stv090x_config.tuner_set_frequency = fe2->tuner_set_frequency;
  182. stv090x_config.tuner_get_frequency = fe2->tuner_get_frequency;
  183. stv090x_config.tuner_set_bandwidth = fe2->tuner_set_bandwidth;
  184. stv090x_config.tuner_get_bandwidth = fe2->tuner_get_bandwidth;
  185. stv090x_config.tuner_set_bbgain = fe2->tuner_set_bbgain;
  186. stv090x_config.tuner_get_bbgain = fe2->tuner_get_bbgain;
  187. stv090x_config.tuner_set_refclk = fe2->tuner_set_refclk;
  188. stv090x_config.tuner_get_status = fe2->tuner_get_status;
  189. dvb_attach(lnbh24_attach, *fe, tsin->i2c_adapter, 0, 0, 0x9);
  190. break;
  191. default:
  192. dev_err(c8sectpfe->device,
  193. "%s: DVB frontend card %s not yet supported\n",
  194. __func__, dvb_card_str(tsin->dvb_card));
  195. return -ENODEV;
  196. }
  197. (*fe)->id = chan_num;
  198. dev_info(c8sectpfe->device,
  199. "DVB frontend card %s successfully attached",
  200. dvb_card_str(tsin->dvb_card));
  201. return 0;
  202. }