2 * mxl111sf-phy.c - driver for the MaxLinear MXL111SF
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
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.
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.
21 #include "mxl111sf-phy.h"
22 #include "mxl111sf-reg.h"
24 int mxl111sf_init_tuner_demod(struct mxl111sf_state
*state
)
26 struct mxl111sf_reg_ctrl_info mxl_111_overwrite_default
[] = {
31 {0xc8, 0xff, 0x40}, /* ED_LE_WIN_OLD = 0 */
32 {0x8d, 0x01, 0x01}, /* NEGATE_Q */
33 {0x32, 0xff, 0xac}, /* DIG_RFREFSELECT = 12 */
34 {0x42, 0xff, 0x43}, /* DIG_REG_AMP = 4 */
35 {0x74, 0xff, 0xc4}, /* SSPUR_FS_PRIO = 4 */
36 {0x71, 0xff, 0xe6}, /* SPUR_ROT_PRIO_VAL = 1 */
37 {0x83, 0xff, 0x64}, /* INF_FILT1_THD_SC = 100 */
38 {0x85, 0xff, 0x64}, /* INF_FILT2_THD_SC = 100 */
39 {0x88, 0xff, 0xf0}, /* INF_THD = 240 */
40 {0x6f, 0xf0, 0xb0}, /* DFE_DLY = 11 */
41 {0x00, 0xff, 0x01}, /* Change to page 1 */
42 {0x81, 0xff, 0x11}, /* DSM_FERR_BYPASS = 1 */
43 {0xf4, 0xff, 0x07}, /* DIG_FREQ_CORR = 1 */
44 {0xd4, 0x1f, 0x0f}, /* SPUR_TEST_NOISE_TH = 15 */
45 {0xd6, 0xff, 0x0c}, /* SPUR_TEST_NOISE_PAPR = 12 */
46 {0x00, 0xff, 0x00}, /* Change to page 0 */
52 return mxl111sf_ctrl_program_regs(state
, mxl_111_overwrite_default
);
55 int mxl1x1sf_soft_reset(struct mxl111sf_state
*state
)
60 ret
= mxl111sf_write_reg(state
, 0xff, 0x00); /* AIC */
63 ret
= mxl111sf_write_reg(state
, 0x02, 0x01); /* get out of reset */
69 int mxl1x1sf_set_device_mode(struct mxl111sf_state
*state
, int mode
)
73 mxl_debug("(%s)", MXL_SOC_MODE
== mode
?
74 "MXL_SOC_MODE" : "MXL_TUNER_MODE");
77 ret
= mxl111sf_write_reg(state
, 0x03,
78 MXL_SOC_MODE
== mode
? 0x01 : 0x00);
82 ret
= mxl111sf_write_reg_mask(state
,
83 0x7d, 0x40, MXL_SOC_MODE
== mode
?
84 0x00 : /* enable impulse noise filter,
86 0x40); /* disable impulse noise filter,
91 state
->device_mode
= mode
;
97 int mxl1x1sf_top_master_ctrl(struct mxl111sf_state
*state
, int onoff
)
99 mxl_debug("(%d)", onoff
);
101 return mxl111sf_write_reg(state
, 0x01, onoff
? 0x01 : 0x00);
104 int mxl111sf_disable_656_port(struct mxl111sf_state
*state
)
108 return mxl111sf_write_reg_mask(state
, 0x12, 0x04, 0x00);
111 int mxl111sf_enable_usb_output(struct mxl111sf_state
*state
)
115 return mxl111sf_write_reg_mask(state
, 0x17, 0x40, 0x00);
118 /* initialize TSIF as input port of MxL1X1SF for MPEG2 data transfer */
119 int mxl111sf_config_mpeg_in(struct mxl111sf_state
*state
,
120 unsigned int parallel_serial
,
121 unsigned int msb_lsb_1st
,
122 unsigned int clock_phase
,
123 unsigned int mpeg_valid_pol
,
124 unsigned int mpeg_sync_pol
)
129 mxl_debug("(%u,%u,%u,%u,%u)", parallel_serial
, msb_lsb_1st
,
130 clock_phase
, mpeg_valid_pol
, mpeg_sync_pol
);
133 ret
= mxl111sf_write_reg(state
, V6_PIN_MUX_MODE_REG
, V6_ENABLE_PIN_MUX
);
136 /* Configure MPEG Clock phase */
137 mxl111sf_read_reg(state
, V6_MPEG_IN_CLK_INV_REG
, &mode
);
139 if (clock_phase
== TSIF_NORMAL
)
140 mode
&= ~V6_INVERTED_CLK_PHASE
;
142 mode
|= V6_INVERTED_CLK_PHASE
;
144 ret
= mxl111sf_write_reg(state
, V6_MPEG_IN_CLK_INV_REG
, mode
);
147 /* Configure data input mode, MPEG Valid polarity, MPEG Sync polarity
148 * Get current configuration */
149 ret
= mxl111sf_read_reg(state
, V6_MPEG_IN_CTRL_REG
, &mode
);
152 /* Data Input mode */
153 if (parallel_serial
== TSIF_INPUT_PARALLEL
) {
154 /* Disable serial mode */
155 mode
&= ~V6_MPEG_IN_DATA_SERIAL
;
157 /* Enable Parallel mode */
158 mode
|= V6_MPEG_IN_DATA_PARALLEL
;
160 /* Disable Parallel mode */
161 mode
&= ~V6_MPEG_IN_DATA_PARALLEL
;
163 /* Enable Serial Mode */
164 mode
|= V6_MPEG_IN_DATA_SERIAL
;
166 /* If serial interface is chosen, configure
167 MSB or LSB order in transmission */
168 ret
= mxl111sf_read_reg(state
,
169 V6_MPEG_INOUT_BIT_ORDER_CTRL_REG
,
173 if (msb_lsb_1st
== MPEG_SER_MSB_FIRST_ENABLED
)
174 tmp
|= V6_MPEG_SER_MSB_FIRST
;
176 tmp
&= ~V6_MPEG_SER_MSB_FIRST
;
178 ret
= mxl111sf_write_reg(state
,
179 V6_MPEG_INOUT_BIT_ORDER_CTRL_REG
,
184 /* MPEG Sync polarity */
185 if (mpeg_sync_pol
== TSIF_NORMAL
)
186 mode
&= ~V6_INVERTED_MPEG_SYNC
;
188 mode
|= V6_INVERTED_MPEG_SYNC
;
190 /* MPEG Valid polarity */
191 if (mpeg_valid_pol
== 0)
192 mode
&= ~V6_INVERTED_MPEG_VALID
;
194 mode
|= V6_INVERTED_MPEG_VALID
;
196 ret
= mxl111sf_write_reg(state
, V6_MPEG_IN_CTRL_REG
, mode
);
202 int mxl111sf_init_i2s_port(struct mxl111sf_state
*state
, u8 sample_size
)
204 static struct mxl111sf_reg_ctrl_info init_i2s
[] = {
205 {0x1b, 0xff, 0x1e}, /* pin mux mode, Choose 656/I2S input */
206 {0x15, 0x60, 0x60}, /* Enable I2S */
207 {0x17, 0xe0, 0x20}, /* Input, MPEG MODE USB,
208 Inverted 656 Clock, I2S_SOFT_RESET,
209 0 : Normal operation, 1 : Reset State */
211 {0x12, 0x01, 0x00}, /* AUDIO_IRQ_CLR (Overflow Indicator) */
213 {0x00, 0xff, 0x02}, /* Change to Control Page */
214 {0x26, 0x0d, 0x0d}, /* I2S_MODE & BT656_SRC_SEL for FPGA only */
220 mxl_debug("(0x%02x)", sample_size
);
222 ret
= mxl111sf_ctrl_program_regs(state
, init_i2s
);
226 ret
= mxl111sf_write_reg(state
, V6_I2S_NUM_SAMPLES_REG
, sample_size
);
232 int mxl111sf_disable_i2s_port(struct mxl111sf_state
*state
)
234 static struct mxl111sf_reg_ctrl_info disable_i2s
[] = {
241 return mxl111sf_ctrl_program_regs(state
, disable_i2s
);
244 int mxl111sf_config_i2s(struct mxl111sf_state
*state
,
245 u8 msb_start_pos
, u8 data_width
)
250 mxl_debug("(0x%02x, 0x%02x)", msb_start_pos
, data_width
);
252 ret
= mxl111sf_read_reg(state
, V6_I2S_STREAM_START_BIT_REG
, &tmp
);
257 tmp
|= msb_start_pos
;
258 ret
= mxl111sf_write_reg(state
, V6_I2S_STREAM_START_BIT_REG
, tmp
);
262 ret
= mxl111sf_read_reg(state
, V6_I2S_STREAM_END_BIT_REG
, &tmp
);
268 ret
= mxl111sf_write_reg(state
, V6_I2S_STREAM_END_BIT_REG
, tmp
);
274 int mxl111sf_config_spi(struct mxl111sf_state
*state
, int onoff
)
279 mxl_debug("(%d)", onoff
);
281 ret
= mxl111sf_write_reg(state
, 0x00, 0x02);
285 ret
= mxl111sf_read_reg(state
, V8_SPI_MODE_REG
, &val
);
294 ret
= mxl111sf_write_reg(state
, V8_SPI_MODE_REG
, val
);
298 ret
= mxl111sf_write_reg(state
, 0x00, 0x00);
304 int mxl111sf_idac_config(struct mxl111sf_state
*state
,
305 u8 control_mode
, u8 current_setting
,
306 u8 current_value
, u8 hysteresis_value
)
310 /* current value will be set for both automatic & manual IDAC control */
313 if (control_mode
== IDAC_MANUAL_CONTROL
) {
314 /* enable manual control of IDAC */
315 val
|= IDAC_MANUAL_CONTROL_BIT_MASK
;
317 if (current_setting
== IDAC_CURRENT_SINKING_ENABLE
)
318 /* enable current sinking in manual mode */
319 val
|= IDAC_CURRENT_SINKING_BIT_MASK
;
321 /* disable current sinking in manual mode */
322 val
&= ~IDAC_CURRENT_SINKING_BIT_MASK
;
324 /* disable manual control of IDAC */
325 val
&= ~IDAC_MANUAL_CONTROL_BIT_MASK
;
327 /* set hysteresis value reg: 0x0B<5:0> */
328 ret
= mxl111sf_write_reg(state
, V6_IDAC_HYSTERESIS_REG
,
329 (hysteresis_value
& 0x3F));
333 ret
= mxl111sf_write_reg(state
, V6_IDAC_SETTINGS_REG
, val
);