mxl111sf-phy.c 8.5 KB

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