2 * mxl111sf-phy.c - driver for the MaxLinear MXL111SF
4 * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
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.
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.
17 #include "mxl111sf-phy.h"
18 #include "mxl111sf-reg.h"
20 int mxl111sf_init_tuner_demod(struct mxl111sf_state
*state
)
22 struct mxl111sf_reg_ctrl_info mxl_111_overwrite_default
[] = {
27 {0xc8, 0xff, 0x40}, /* ED_LE_WIN_OLD = 0 */
28 {0x8d, 0x01, 0x01}, /* NEGATE_Q */
29 {0x32, 0xff, 0xac}, /* DIG_RFREFSELECT = 12 */
30 {0x42, 0xff, 0x43}, /* DIG_REG_AMP = 4 */
31 {0x74, 0xff, 0xc4}, /* SSPUR_FS_PRIO = 4 */
32 {0x71, 0xff, 0xe6}, /* SPUR_ROT_PRIO_VAL = 1 */
33 {0x83, 0xff, 0x64}, /* INF_FILT1_THD_SC = 100 */
34 {0x85, 0xff, 0x64}, /* INF_FILT2_THD_SC = 100 */
35 {0x88, 0xff, 0xf0}, /* INF_THD = 240 */
36 {0x6f, 0xf0, 0xb0}, /* DFE_DLY = 11 */
37 {0x00, 0xff, 0x01}, /* Change to page 1 */
38 {0x81, 0xff, 0x11}, /* DSM_FERR_BYPASS = 1 */
39 {0xf4, 0xff, 0x07}, /* DIG_FREQ_CORR = 1 */
40 {0xd4, 0x1f, 0x0f}, /* SPUR_TEST_NOISE_TH = 15 */
41 {0xd6, 0xff, 0x0c}, /* SPUR_TEST_NOISE_PAPR = 12 */
42 {0x00, 0xff, 0x00}, /* Change to page 0 */
48 return mxl111sf_ctrl_program_regs(state
, mxl_111_overwrite_default
);
51 int mxl1x1sf_soft_reset(struct mxl111sf_state
*state
)
56 ret
= mxl111sf_write_reg(state
, 0xff, 0x00); /* AIC */
59 ret
= mxl111sf_write_reg(state
, 0x02, 0x01); /* get out of reset */
65 int mxl1x1sf_set_device_mode(struct mxl111sf_state
*state
, int mode
)
69 mxl_debug("(%s)", MXL_SOC_MODE
== mode
?
70 "MXL_SOC_MODE" : "MXL_TUNER_MODE");
73 ret
= mxl111sf_write_reg(state
, 0x03,
74 MXL_SOC_MODE
== mode
? 0x01 : 0x00);
78 ret
= mxl111sf_write_reg_mask(state
,
79 0x7d, 0x40, MXL_SOC_MODE
== mode
?
80 0x00 : /* enable impulse noise filter,
82 0x40); /* disable impulse noise filter,
87 state
->device_mode
= mode
;
93 int mxl1x1sf_top_master_ctrl(struct mxl111sf_state
*state
, int onoff
)
95 mxl_debug("(%d)", onoff
);
97 return mxl111sf_write_reg(state
, 0x01, onoff
? 0x01 : 0x00);
100 int mxl111sf_disable_656_port(struct mxl111sf_state
*state
)
104 return mxl111sf_write_reg_mask(state
, 0x12, 0x04, 0x00);
107 int mxl111sf_enable_usb_output(struct mxl111sf_state
*state
)
111 return mxl111sf_write_reg_mask(state
, 0x17, 0x40, 0x00);
114 /* initialize TSIF as input port of MxL1X1SF for MPEG2 data transfer */
115 int mxl111sf_config_mpeg_in(struct mxl111sf_state
*state
,
116 unsigned int parallel_serial
,
117 unsigned int msb_lsb_1st
,
118 unsigned int clock_phase
,
119 unsigned int mpeg_valid_pol
,
120 unsigned int mpeg_sync_pol
)
125 mxl_debug("(%u,%u,%u,%u,%u)", parallel_serial
, msb_lsb_1st
,
126 clock_phase
, mpeg_valid_pol
, mpeg_sync_pol
);
129 ret
= mxl111sf_write_reg(state
, V6_PIN_MUX_MODE_REG
, V6_ENABLE_PIN_MUX
);
132 /* Configure MPEG Clock phase */
133 mxl111sf_read_reg(state
, V6_MPEG_IN_CLK_INV_REG
, &mode
);
135 if (clock_phase
== TSIF_NORMAL
)
136 mode
&= ~V6_INVERTED_CLK_PHASE
;
138 mode
|= V6_INVERTED_CLK_PHASE
;
140 ret
= mxl111sf_write_reg(state
, V6_MPEG_IN_CLK_INV_REG
, mode
);
143 /* Configure data input mode, MPEG Valid polarity, MPEG Sync polarity
144 * Get current configuration */
145 ret
= mxl111sf_read_reg(state
, V6_MPEG_IN_CTRL_REG
, &mode
);
148 /* Data Input mode */
149 if (parallel_serial
== TSIF_INPUT_PARALLEL
) {
150 /* Disable serial mode */
151 mode
&= ~V6_MPEG_IN_DATA_SERIAL
;
153 /* Enable Parallel mode */
154 mode
|= V6_MPEG_IN_DATA_PARALLEL
;
156 /* Disable Parallel mode */
157 mode
&= ~V6_MPEG_IN_DATA_PARALLEL
;
159 /* Enable Serial Mode */
160 mode
|= V6_MPEG_IN_DATA_SERIAL
;
162 /* If serial interface is chosen, configure
163 MSB or LSB order in transmission */
164 ret
= mxl111sf_read_reg(state
,
165 V6_MPEG_INOUT_BIT_ORDER_CTRL_REG
,
169 if (msb_lsb_1st
== MPEG_SER_MSB_FIRST_ENABLED
)
170 tmp
|= V6_MPEG_SER_MSB_FIRST
;
172 tmp
&= ~V6_MPEG_SER_MSB_FIRST
;
174 ret
= mxl111sf_write_reg(state
,
175 V6_MPEG_INOUT_BIT_ORDER_CTRL_REG
,
180 /* MPEG Sync polarity */
181 if (mpeg_sync_pol
== TSIF_NORMAL
)
182 mode
&= ~V6_INVERTED_MPEG_SYNC
;
184 mode
|= V6_INVERTED_MPEG_SYNC
;
186 /* MPEG Valid polarity */
187 if (mpeg_valid_pol
== 0)
188 mode
&= ~V6_INVERTED_MPEG_VALID
;
190 mode
|= V6_INVERTED_MPEG_VALID
;
192 ret
= mxl111sf_write_reg(state
, V6_MPEG_IN_CTRL_REG
, mode
);
198 int mxl111sf_init_i2s_port(struct mxl111sf_state
*state
, u8 sample_size
)
200 static struct mxl111sf_reg_ctrl_info init_i2s
[] = {
201 {0x1b, 0xff, 0x1e}, /* pin mux mode, Choose 656/I2S input */
202 {0x15, 0x60, 0x60}, /* Enable I2S */
203 {0x17, 0xe0, 0x20}, /* Input, MPEG MODE USB,
204 Inverted 656 Clock, I2S_SOFT_RESET,
205 0 : Normal operation, 1 : Reset State */
207 {0x12, 0x01, 0x00}, /* AUDIO_IRQ_CLR (Overflow Indicator) */
209 {0x00, 0xff, 0x02}, /* Change to Control Page */
210 {0x26, 0x0d, 0x0d}, /* I2S_MODE & BT656_SRC_SEL for FPGA only */
216 mxl_debug("(0x%02x)", sample_size
);
218 ret
= mxl111sf_ctrl_program_regs(state
, init_i2s
);
222 ret
= mxl111sf_write_reg(state
, V6_I2S_NUM_SAMPLES_REG
, sample_size
);
228 int mxl111sf_disable_i2s_port(struct mxl111sf_state
*state
)
230 static struct mxl111sf_reg_ctrl_info disable_i2s
[] = {
237 return mxl111sf_ctrl_program_regs(state
, disable_i2s
);
240 int mxl111sf_config_i2s(struct mxl111sf_state
*state
,
241 u8 msb_start_pos
, u8 data_width
)
246 mxl_debug("(0x%02x, 0x%02x)", msb_start_pos
, data_width
);
248 ret
= mxl111sf_read_reg(state
, V6_I2S_STREAM_START_BIT_REG
, &tmp
);
253 tmp
|= msb_start_pos
;
254 ret
= mxl111sf_write_reg(state
, V6_I2S_STREAM_START_BIT_REG
, tmp
);
258 ret
= mxl111sf_read_reg(state
, V6_I2S_STREAM_END_BIT_REG
, &tmp
);
264 ret
= mxl111sf_write_reg(state
, V6_I2S_STREAM_END_BIT_REG
, tmp
);
270 int mxl111sf_config_spi(struct mxl111sf_state
*state
, int onoff
)
275 mxl_debug("(%d)", onoff
);
277 ret
= mxl111sf_write_reg(state
, 0x00, 0x02);
281 ret
= mxl111sf_read_reg(state
, V8_SPI_MODE_REG
, &val
);
290 ret
= mxl111sf_write_reg(state
, V8_SPI_MODE_REG
, val
);
294 ret
= mxl111sf_write_reg(state
, 0x00, 0x00);
300 int mxl111sf_idac_config(struct mxl111sf_state
*state
,
301 u8 control_mode
, u8 current_setting
,
302 u8 current_value
, u8 hysteresis_value
)
306 /* current value will be set for both automatic & manual IDAC control */
309 if (control_mode
== IDAC_MANUAL_CONTROL
) {
310 /* enable manual control of IDAC */
311 val
|= IDAC_MANUAL_CONTROL_BIT_MASK
;
313 if (current_setting
== IDAC_CURRENT_SINKING_ENABLE
)
314 /* enable current sinking in manual mode */
315 val
|= IDAC_CURRENT_SINKING_BIT_MASK
;
317 /* disable current sinking in manual mode */
318 val
&= ~IDAC_CURRENT_SINKING_BIT_MASK
;
320 /* disable manual control of IDAC */
321 val
&= ~IDAC_MANUAL_CONTROL_BIT_MASK
;
323 /* set hysteresis value reg: 0x0B<5:0> */
324 ret
= mxl111sf_write_reg(state
, V6_IDAC_HYSTERESIS_REG
,
325 (hysteresis_value
& 0x3F));
329 ret
= mxl111sf_write_reg(state
, V6_IDAC_SETTINGS_REG
, val
);