mxl111sf-phy.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * mxl111sf-phy.c - driver for the MaxLinear MXL111SF
  4. *
  5. * Copyright (C) 2010-2014 Michael Krufky <[email protected]>
  6. */
  7. #include "mxl111sf-phy.h"
  8. #include "mxl111sf-reg.h"
  9. int mxl111sf_init_tuner_demod(struct mxl111sf_state *state)
  10. {
  11. struct mxl111sf_reg_ctrl_info mxl_111_overwrite_default[] = {
  12. {0x07, 0xff, 0x0c},
  13. {0x58, 0xff, 0x9d},
  14. {0x09, 0xff, 0x00},
  15. {0x06, 0xff, 0x06},
  16. {0xc8, 0xff, 0x40}, /* ED_LE_WIN_OLD = 0 */
  17. {0x8d, 0x01, 0x01}, /* NEGATE_Q */
  18. {0x32, 0xff, 0xac}, /* DIG_RFREFSELECT = 12 */
  19. {0x42, 0xff, 0x43}, /* DIG_REG_AMP = 4 */
  20. {0x74, 0xff, 0xc4}, /* SSPUR_FS_PRIO = 4 */
  21. {0x71, 0xff, 0xe6}, /* SPUR_ROT_PRIO_VAL = 1 */
  22. {0x83, 0xff, 0x64}, /* INF_FILT1_THD_SC = 100 */
  23. {0x85, 0xff, 0x64}, /* INF_FILT2_THD_SC = 100 */
  24. {0x88, 0xff, 0xf0}, /* INF_THD = 240 */
  25. {0x6f, 0xf0, 0xb0}, /* DFE_DLY = 11 */
  26. {0x00, 0xff, 0x01}, /* Change to page 1 */
  27. {0x81, 0xff, 0x11}, /* DSM_FERR_BYPASS = 1 */
  28. {0xf4, 0xff, 0x07}, /* DIG_FREQ_CORR = 1 */
  29. {0xd4, 0x1f, 0x0f}, /* SPUR_TEST_NOISE_TH = 15 */
  30. {0xd6, 0xff, 0x0c}, /* SPUR_TEST_NOISE_PAPR = 12 */
  31. {0x00, 0xff, 0x00}, /* Change to page 0 */
  32. {0, 0, 0}
  33. };
  34. mxl_debug("()");
  35. return mxl111sf_ctrl_program_regs(state, mxl_111_overwrite_default);
  36. }
  37. int mxl1x1sf_soft_reset(struct mxl111sf_state *state)
  38. {
  39. int ret;
  40. mxl_debug("()");
  41. ret = mxl111sf_write_reg(state, 0xff, 0x00); /* AIC */
  42. if (mxl_fail(ret))
  43. goto fail;
  44. ret = mxl111sf_write_reg(state, 0x02, 0x01); /* get out of reset */
  45. mxl_fail(ret);
  46. fail:
  47. return ret;
  48. }
  49. int mxl1x1sf_set_device_mode(struct mxl111sf_state *state, int mode)
  50. {
  51. int ret;
  52. mxl_debug("(%s)", MXL_SOC_MODE == mode ?
  53. "MXL_SOC_MODE" : "MXL_TUNER_MODE");
  54. /* set device mode */
  55. ret = mxl111sf_write_reg(state, 0x03,
  56. MXL_SOC_MODE == mode ? 0x01 : 0x00);
  57. if (mxl_fail(ret))
  58. goto fail;
  59. ret = mxl111sf_write_reg_mask(state,
  60. 0x7d, 0x40, MXL_SOC_MODE == mode ?
  61. 0x00 : /* enable impulse noise filter,
  62. INF_BYP = 0 */
  63. 0x40); /* disable impulse noise filter,
  64. INF_BYP = 1 */
  65. if (mxl_fail(ret))
  66. goto fail;
  67. state->device_mode = mode;
  68. fail:
  69. return ret;
  70. }
  71. /* power up tuner */
  72. int mxl1x1sf_top_master_ctrl(struct mxl111sf_state *state, int onoff)
  73. {
  74. mxl_debug("(%d)", onoff);
  75. return mxl111sf_write_reg(state, 0x01, onoff ? 0x01 : 0x00);
  76. }
  77. int mxl111sf_disable_656_port(struct mxl111sf_state *state)
  78. {
  79. mxl_debug("()");
  80. return mxl111sf_write_reg_mask(state, 0x12, 0x04, 0x00);
  81. }
  82. int mxl111sf_enable_usb_output(struct mxl111sf_state *state)
  83. {
  84. mxl_debug("()");
  85. return mxl111sf_write_reg_mask(state, 0x17, 0x40, 0x00);
  86. }
  87. /* initialize TSIF as input port of MxL1X1SF for MPEG2 data transfer */
  88. int mxl111sf_config_mpeg_in(struct mxl111sf_state *state,
  89. unsigned int parallel_serial,
  90. unsigned int msb_lsb_1st,
  91. unsigned int clock_phase,
  92. unsigned int mpeg_valid_pol,
  93. unsigned int mpeg_sync_pol)
  94. {
  95. int ret;
  96. u8 mode, tmp;
  97. mxl_debug("(%u,%u,%u,%u,%u)", parallel_serial, msb_lsb_1st,
  98. clock_phase, mpeg_valid_pol, mpeg_sync_pol);
  99. /* Enable PIN MUX */
  100. ret = mxl111sf_write_reg(state, V6_PIN_MUX_MODE_REG, V6_ENABLE_PIN_MUX);
  101. mxl_fail(ret);
  102. /* Configure MPEG Clock phase */
  103. mxl111sf_read_reg(state, V6_MPEG_IN_CLK_INV_REG, &mode);
  104. if (clock_phase == TSIF_NORMAL)
  105. mode &= ~V6_INVERTED_CLK_PHASE;
  106. else
  107. mode |= V6_INVERTED_CLK_PHASE;
  108. ret = mxl111sf_write_reg(state, V6_MPEG_IN_CLK_INV_REG, mode);
  109. mxl_fail(ret);
  110. /* Configure data input mode, MPEG Valid polarity, MPEG Sync polarity
  111. * Get current configuration */
  112. ret = mxl111sf_read_reg(state, V6_MPEG_IN_CTRL_REG, &mode);
  113. mxl_fail(ret);
  114. /* Data Input mode */
  115. if (parallel_serial == TSIF_INPUT_PARALLEL) {
  116. /* Disable serial mode */
  117. mode &= ~V6_MPEG_IN_DATA_SERIAL;
  118. /* Enable Parallel mode */
  119. mode |= V6_MPEG_IN_DATA_PARALLEL;
  120. } else {
  121. /* Disable Parallel mode */
  122. mode &= ~V6_MPEG_IN_DATA_PARALLEL;
  123. /* Enable Serial Mode */
  124. mode |= V6_MPEG_IN_DATA_SERIAL;
  125. /* If serial interface is chosen, configure
  126. MSB or LSB order in transmission */
  127. ret = mxl111sf_read_reg(state,
  128. V6_MPEG_INOUT_BIT_ORDER_CTRL_REG,
  129. &tmp);
  130. mxl_fail(ret);
  131. if (msb_lsb_1st == MPEG_SER_MSB_FIRST_ENABLED)
  132. tmp |= V6_MPEG_SER_MSB_FIRST;
  133. else
  134. tmp &= ~V6_MPEG_SER_MSB_FIRST;
  135. ret = mxl111sf_write_reg(state,
  136. V6_MPEG_INOUT_BIT_ORDER_CTRL_REG,
  137. tmp);
  138. mxl_fail(ret);
  139. }
  140. /* MPEG Sync polarity */
  141. if (mpeg_sync_pol == TSIF_NORMAL)
  142. mode &= ~V6_INVERTED_MPEG_SYNC;
  143. else
  144. mode |= V6_INVERTED_MPEG_SYNC;
  145. /* MPEG Valid polarity */
  146. if (mpeg_valid_pol == 0)
  147. mode &= ~V6_INVERTED_MPEG_VALID;
  148. else
  149. mode |= V6_INVERTED_MPEG_VALID;
  150. ret = mxl111sf_write_reg(state, V6_MPEG_IN_CTRL_REG, mode);
  151. mxl_fail(ret);
  152. return ret;
  153. }
  154. int mxl111sf_init_i2s_port(struct mxl111sf_state *state, u8 sample_size)
  155. {
  156. static struct mxl111sf_reg_ctrl_info init_i2s[] = {
  157. {0x1b, 0xff, 0x1e}, /* pin mux mode, Choose 656/I2S input */
  158. {0x15, 0x60, 0x60}, /* Enable I2S */
  159. {0x17, 0xe0, 0x20}, /* Input, MPEG MODE USB,
  160. Inverted 656 Clock, I2S_SOFT_RESET,
  161. 0 : Normal operation, 1 : Reset State */
  162. #if 0
  163. {0x12, 0x01, 0x00}, /* AUDIO_IRQ_CLR (Overflow Indicator) */
  164. #endif
  165. {0x00, 0xff, 0x02}, /* Change to Control Page */
  166. {0x26, 0x0d, 0x0d}, /* I2S_MODE & BT656_SRC_SEL for FPGA only */
  167. {0x00, 0xff, 0x00},
  168. {0, 0, 0}
  169. };
  170. int ret;
  171. mxl_debug("(0x%02x)", sample_size);
  172. ret = mxl111sf_ctrl_program_regs(state, init_i2s);
  173. if (mxl_fail(ret))
  174. goto fail;
  175. ret = mxl111sf_write_reg(state, V6_I2S_NUM_SAMPLES_REG, sample_size);
  176. mxl_fail(ret);
  177. fail:
  178. return ret;
  179. }
  180. int mxl111sf_disable_i2s_port(struct mxl111sf_state *state)
  181. {
  182. static struct mxl111sf_reg_ctrl_info disable_i2s[] = {
  183. {0x15, 0x40, 0x00},
  184. {0, 0, 0}
  185. };
  186. mxl_debug("()");
  187. return mxl111sf_ctrl_program_regs(state, disable_i2s);
  188. }
  189. int mxl111sf_config_i2s(struct mxl111sf_state *state,
  190. u8 msb_start_pos, u8 data_width)
  191. {
  192. int ret;
  193. u8 tmp;
  194. mxl_debug("(0x%02x, 0x%02x)", msb_start_pos, data_width);
  195. ret = mxl111sf_read_reg(state, V6_I2S_STREAM_START_BIT_REG, &tmp);
  196. if (mxl_fail(ret))
  197. goto fail;
  198. tmp &= 0xe0;
  199. tmp |= msb_start_pos;
  200. ret = mxl111sf_write_reg(state, V6_I2S_STREAM_START_BIT_REG, tmp);
  201. if (mxl_fail(ret))
  202. goto fail;
  203. ret = mxl111sf_read_reg(state, V6_I2S_STREAM_END_BIT_REG, &tmp);
  204. if (mxl_fail(ret))
  205. goto fail;
  206. tmp &= 0xe0;
  207. tmp |= data_width;
  208. ret = mxl111sf_write_reg(state, V6_I2S_STREAM_END_BIT_REG, tmp);
  209. mxl_fail(ret);
  210. fail:
  211. return ret;
  212. }
  213. int mxl111sf_config_spi(struct mxl111sf_state *state, int onoff)
  214. {
  215. u8 val;
  216. int ret;
  217. mxl_debug("(%d)", onoff);
  218. ret = mxl111sf_write_reg(state, 0x00, 0x02);
  219. if (mxl_fail(ret))
  220. goto fail;
  221. ret = mxl111sf_read_reg(state, V8_SPI_MODE_REG, &val);
  222. if (mxl_fail(ret))
  223. goto fail;
  224. if (onoff)
  225. val |= 0x04;
  226. else
  227. val &= ~0x04;
  228. ret = mxl111sf_write_reg(state, V8_SPI_MODE_REG, val);
  229. if (mxl_fail(ret))
  230. goto fail;
  231. ret = mxl111sf_write_reg(state, 0x00, 0x00);
  232. mxl_fail(ret);
  233. fail:
  234. return ret;
  235. }
  236. int mxl111sf_idac_config(struct mxl111sf_state *state,
  237. u8 control_mode, u8 current_setting,
  238. u8 current_value, u8 hysteresis_value)
  239. {
  240. int ret;
  241. u8 val;
  242. /* current value will be set for both automatic & manual IDAC control */
  243. val = current_value;
  244. if (control_mode == IDAC_MANUAL_CONTROL) {
  245. /* enable manual control of IDAC */
  246. val |= IDAC_MANUAL_CONTROL_BIT_MASK;
  247. if (current_setting == IDAC_CURRENT_SINKING_ENABLE)
  248. /* enable current sinking in manual mode */
  249. val |= IDAC_CURRENT_SINKING_BIT_MASK;
  250. else
  251. /* disable current sinking in manual mode */
  252. val &= ~IDAC_CURRENT_SINKING_BIT_MASK;
  253. } else {
  254. /* disable manual control of IDAC */
  255. val &= ~IDAC_MANUAL_CONTROL_BIT_MASK;
  256. /* set hysteresis value reg: 0x0B<5:0> */
  257. ret = mxl111sf_write_reg(state, V6_IDAC_HYSTERESIS_REG,
  258. (hysteresis_value & 0x3F));
  259. mxl_fail(ret);
  260. }
  261. ret = mxl111sf_write_reg(state, V6_IDAC_SETTINGS_REG, val);
  262. mxl_fail(ret);
  263. return ret;
  264. }