1*c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2786baecfSMauro Carvalho Chehab /*
3786baecfSMauro Carvalho Chehab * mxl111sf-phy.c - driver for the MaxLinear MXL111SF
4786baecfSMauro Carvalho Chehab *
508e10972SMichael Krufky * Copyright (C) 2010-2014 Michael Krufky <mkrufky@linuxtv.org>
6786baecfSMauro Carvalho Chehab */
7786baecfSMauro Carvalho Chehab
8786baecfSMauro Carvalho Chehab #include "mxl111sf-phy.h"
9786baecfSMauro Carvalho Chehab #include "mxl111sf-reg.h"
10786baecfSMauro Carvalho Chehab
mxl111sf_init_tuner_demod(struct mxl111sf_state * state)11786baecfSMauro Carvalho Chehab int mxl111sf_init_tuner_demod(struct mxl111sf_state *state)
12786baecfSMauro Carvalho Chehab {
13786baecfSMauro Carvalho Chehab struct mxl111sf_reg_ctrl_info mxl_111_overwrite_default[] = {
14786baecfSMauro Carvalho Chehab {0x07, 0xff, 0x0c},
15786baecfSMauro Carvalho Chehab {0x58, 0xff, 0x9d},
16786baecfSMauro Carvalho Chehab {0x09, 0xff, 0x00},
17786baecfSMauro Carvalho Chehab {0x06, 0xff, 0x06},
18786baecfSMauro Carvalho Chehab {0xc8, 0xff, 0x40}, /* ED_LE_WIN_OLD = 0 */
19786baecfSMauro Carvalho Chehab {0x8d, 0x01, 0x01}, /* NEGATE_Q */
20786baecfSMauro Carvalho Chehab {0x32, 0xff, 0xac}, /* DIG_RFREFSELECT = 12 */
21786baecfSMauro Carvalho Chehab {0x42, 0xff, 0x43}, /* DIG_REG_AMP = 4 */
22786baecfSMauro Carvalho Chehab {0x74, 0xff, 0xc4}, /* SSPUR_FS_PRIO = 4 */
23786baecfSMauro Carvalho Chehab {0x71, 0xff, 0xe6}, /* SPUR_ROT_PRIO_VAL = 1 */
24786baecfSMauro Carvalho Chehab {0x83, 0xff, 0x64}, /* INF_FILT1_THD_SC = 100 */
25786baecfSMauro Carvalho Chehab {0x85, 0xff, 0x64}, /* INF_FILT2_THD_SC = 100 */
26786baecfSMauro Carvalho Chehab {0x88, 0xff, 0xf0}, /* INF_THD = 240 */
27786baecfSMauro Carvalho Chehab {0x6f, 0xf0, 0xb0}, /* DFE_DLY = 11 */
28786baecfSMauro Carvalho Chehab {0x00, 0xff, 0x01}, /* Change to page 1 */
29786baecfSMauro Carvalho Chehab {0x81, 0xff, 0x11}, /* DSM_FERR_BYPASS = 1 */
30786baecfSMauro Carvalho Chehab {0xf4, 0xff, 0x07}, /* DIG_FREQ_CORR = 1 */
31786baecfSMauro Carvalho Chehab {0xd4, 0x1f, 0x0f}, /* SPUR_TEST_NOISE_TH = 15 */
32786baecfSMauro Carvalho Chehab {0xd6, 0xff, 0x0c}, /* SPUR_TEST_NOISE_PAPR = 12 */
33786baecfSMauro Carvalho Chehab {0x00, 0xff, 0x00}, /* Change to page 0 */
34786baecfSMauro Carvalho Chehab {0, 0, 0}
35786baecfSMauro Carvalho Chehab };
36786baecfSMauro Carvalho Chehab
37786baecfSMauro Carvalho Chehab mxl_debug("()");
38786baecfSMauro Carvalho Chehab
39786baecfSMauro Carvalho Chehab return mxl111sf_ctrl_program_regs(state, mxl_111_overwrite_default);
40786baecfSMauro Carvalho Chehab }
41786baecfSMauro Carvalho Chehab
mxl1x1sf_soft_reset(struct mxl111sf_state * state)42786baecfSMauro Carvalho Chehab int mxl1x1sf_soft_reset(struct mxl111sf_state *state)
43786baecfSMauro Carvalho Chehab {
44786baecfSMauro Carvalho Chehab int ret;
45786baecfSMauro Carvalho Chehab mxl_debug("()");
46786baecfSMauro Carvalho Chehab
47786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, 0xff, 0x00); /* AIC */
48786baecfSMauro Carvalho Chehab if (mxl_fail(ret))
49786baecfSMauro Carvalho Chehab goto fail;
50786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, 0x02, 0x01); /* get out of reset */
51786baecfSMauro Carvalho Chehab mxl_fail(ret);
52786baecfSMauro Carvalho Chehab fail:
53786baecfSMauro Carvalho Chehab return ret;
54786baecfSMauro Carvalho Chehab }
55786baecfSMauro Carvalho Chehab
mxl1x1sf_set_device_mode(struct mxl111sf_state * state,int mode)56786baecfSMauro Carvalho Chehab int mxl1x1sf_set_device_mode(struct mxl111sf_state *state, int mode)
57786baecfSMauro Carvalho Chehab {
58786baecfSMauro Carvalho Chehab int ret;
59786baecfSMauro Carvalho Chehab
60786baecfSMauro Carvalho Chehab mxl_debug("(%s)", MXL_SOC_MODE == mode ?
61786baecfSMauro Carvalho Chehab "MXL_SOC_MODE" : "MXL_TUNER_MODE");
62786baecfSMauro Carvalho Chehab
63786baecfSMauro Carvalho Chehab /* set device mode */
64786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, 0x03,
65786baecfSMauro Carvalho Chehab MXL_SOC_MODE == mode ? 0x01 : 0x00);
66786baecfSMauro Carvalho Chehab if (mxl_fail(ret))
67786baecfSMauro Carvalho Chehab goto fail;
68786baecfSMauro Carvalho Chehab
69786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg_mask(state,
70786baecfSMauro Carvalho Chehab 0x7d, 0x40, MXL_SOC_MODE == mode ?
71786baecfSMauro Carvalho Chehab 0x00 : /* enable impulse noise filter,
72786baecfSMauro Carvalho Chehab INF_BYP = 0 */
73786baecfSMauro Carvalho Chehab 0x40); /* disable impulse noise filter,
74786baecfSMauro Carvalho Chehab INF_BYP = 1 */
75786baecfSMauro Carvalho Chehab if (mxl_fail(ret))
76786baecfSMauro Carvalho Chehab goto fail;
77786baecfSMauro Carvalho Chehab
78786baecfSMauro Carvalho Chehab state->device_mode = mode;
79786baecfSMauro Carvalho Chehab fail:
80786baecfSMauro Carvalho Chehab return ret;
81786baecfSMauro Carvalho Chehab }
82786baecfSMauro Carvalho Chehab
83786baecfSMauro Carvalho Chehab /* power up tuner */
mxl1x1sf_top_master_ctrl(struct mxl111sf_state * state,int onoff)84786baecfSMauro Carvalho Chehab int mxl1x1sf_top_master_ctrl(struct mxl111sf_state *state, int onoff)
85786baecfSMauro Carvalho Chehab {
86786baecfSMauro Carvalho Chehab mxl_debug("(%d)", onoff);
87786baecfSMauro Carvalho Chehab
88786baecfSMauro Carvalho Chehab return mxl111sf_write_reg(state, 0x01, onoff ? 0x01 : 0x00);
89786baecfSMauro Carvalho Chehab }
90786baecfSMauro Carvalho Chehab
mxl111sf_disable_656_port(struct mxl111sf_state * state)91786baecfSMauro Carvalho Chehab int mxl111sf_disable_656_port(struct mxl111sf_state *state)
92786baecfSMauro Carvalho Chehab {
93786baecfSMauro Carvalho Chehab mxl_debug("()");
94786baecfSMauro Carvalho Chehab
95786baecfSMauro Carvalho Chehab return mxl111sf_write_reg_mask(state, 0x12, 0x04, 0x00);
96786baecfSMauro Carvalho Chehab }
97786baecfSMauro Carvalho Chehab
mxl111sf_enable_usb_output(struct mxl111sf_state * state)98786baecfSMauro Carvalho Chehab int mxl111sf_enable_usb_output(struct mxl111sf_state *state)
99786baecfSMauro Carvalho Chehab {
100786baecfSMauro Carvalho Chehab mxl_debug("()");
101786baecfSMauro Carvalho Chehab
102786baecfSMauro Carvalho Chehab return mxl111sf_write_reg_mask(state, 0x17, 0x40, 0x00);
103786baecfSMauro Carvalho Chehab }
104786baecfSMauro Carvalho Chehab
105786baecfSMauro Carvalho Chehab /* initialize TSIF as input port of MxL1X1SF for MPEG2 data transfer */
mxl111sf_config_mpeg_in(struct mxl111sf_state * state,unsigned int parallel_serial,unsigned int msb_lsb_1st,unsigned int clock_phase,unsigned int mpeg_valid_pol,unsigned int mpeg_sync_pol)106786baecfSMauro Carvalho Chehab int mxl111sf_config_mpeg_in(struct mxl111sf_state *state,
107786baecfSMauro Carvalho Chehab unsigned int parallel_serial,
108786baecfSMauro Carvalho Chehab unsigned int msb_lsb_1st,
109786baecfSMauro Carvalho Chehab unsigned int clock_phase,
110786baecfSMauro Carvalho Chehab unsigned int mpeg_valid_pol,
111786baecfSMauro Carvalho Chehab unsigned int mpeg_sync_pol)
112786baecfSMauro Carvalho Chehab {
113786baecfSMauro Carvalho Chehab int ret;
114786baecfSMauro Carvalho Chehab u8 mode, tmp;
115786baecfSMauro Carvalho Chehab
116786baecfSMauro Carvalho Chehab mxl_debug("(%u,%u,%u,%u,%u)", parallel_serial, msb_lsb_1st,
117786baecfSMauro Carvalho Chehab clock_phase, mpeg_valid_pol, mpeg_sync_pol);
118786baecfSMauro Carvalho Chehab
119786baecfSMauro Carvalho Chehab /* Enable PIN MUX */
120786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, V6_PIN_MUX_MODE_REG, V6_ENABLE_PIN_MUX);
121786baecfSMauro Carvalho Chehab mxl_fail(ret);
122786baecfSMauro Carvalho Chehab
123786baecfSMauro Carvalho Chehab /* Configure MPEG Clock phase */
124786baecfSMauro Carvalho Chehab mxl111sf_read_reg(state, V6_MPEG_IN_CLK_INV_REG, &mode);
125786baecfSMauro Carvalho Chehab
126786baecfSMauro Carvalho Chehab if (clock_phase == TSIF_NORMAL)
127786baecfSMauro Carvalho Chehab mode &= ~V6_INVERTED_CLK_PHASE;
128786baecfSMauro Carvalho Chehab else
129786baecfSMauro Carvalho Chehab mode |= V6_INVERTED_CLK_PHASE;
130786baecfSMauro Carvalho Chehab
131786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, V6_MPEG_IN_CLK_INV_REG, mode);
132786baecfSMauro Carvalho Chehab mxl_fail(ret);
133786baecfSMauro Carvalho Chehab
134786baecfSMauro Carvalho Chehab /* Configure data input mode, MPEG Valid polarity, MPEG Sync polarity
135786baecfSMauro Carvalho Chehab * Get current configuration */
136786baecfSMauro Carvalho Chehab ret = mxl111sf_read_reg(state, V6_MPEG_IN_CTRL_REG, &mode);
137786baecfSMauro Carvalho Chehab mxl_fail(ret);
138786baecfSMauro Carvalho Chehab
139786baecfSMauro Carvalho Chehab /* Data Input mode */
140786baecfSMauro Carvalho Chehab if (parallel_serial == TSIF_INPUT_PARALLEL) {
141786baecfSMauro Carvalho Chehab /* Disable serial mode */
142786baecfSMauro Carvalho Chehab mode &= ~V6_MPEG_IN_DATA_SERIAL;
143786baecfSMauro Carvalho Chehab
144786baecfSMauro Carvalho Chehab /* Enable Parallel mode */
145786baecfSMauro Carvalho Chehab mode |= V6_MPEG_IN_DATA_PARALLEL;
146786baecfSMauro Carvalho Chehab } else {
147786baecfSMauro Carvalho Chehab /* Disable Parallel mode */
148786baecfSMauro Carvalho Chehab mode &= ~V6_MPEG_IN_DATA_PARALLEL;
149786baecfSMauro Carvalho Chehab
150786baecfSMauro Carvalho Chehab /* Enable Serial Mode */
151786baecfSMauro Carvalho Chehab mode |= V6_MPEG_IN_DATA_SERIAL;
152786baecfSMauro Carvalho Chehab
153786baecfSMauro Carvalho Chehab /* If serial interface is chosen, configure
154786baecfSMauro Carvalho Chehab MSB or LSB order in transmission */
155786baecfSMauro Carvalho Chehab ret = mxl111sf_read_reg(state,
156786baecfSMauro Carvalho Chehab V6_MPEG_INOUT_BIT_ORDER_CTRL_REG,
157786baecfSMauro Carvalho Chehab &tmp);
158786baecfSMauro Carvalho Chehab mxl_fail(ret);
159786baecfSMauro Carvalho Chehab
160786baecfSMauro Carvalho Chehab if (msb_lsb_1st == MPEG_SER_MSB_FIRST_ENABLED)
161786baecfSMauro Carvalho Chehab tmp |= V6_MPEG_SER_MSB_FIRST;
162786baecfSMauro Carvalho Chehab else
163786baecfSMauro Carvalho Chehab tmp &= ~V6_MPEG_SER_MSB_FIRST;
164786baecfSMauro Carvalho Chehab
165786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state,
166786baecfSMauro Carvalho Chehab V6_MPEG_INOUT_BIT_ORDER_CTRL_REG,
167786baecfSMauro Carvalho Chehab tmp);
168786baecfSMauro Carvalho Chehab mxl_fail(ret);
169786baecfSMauro Carvalho Chehab }
170786baecfSMauro Carvalho Chehab
171786baecfSMauro Carvalho Chehab /* MPEG Sync polarity */
172786baecfSMauro Carvalho Chehab if (mpeg_sync_pol == TSIF_NORMAL)
173786baecfSMauro Carvalho Chehab mode &= ~V6_INVERTED_MPEG_SYNC;
174786baecfSMauro Carvalho Chehab else
175786baecfSMauro Carvalho Chehab mode |= V6_INVERTED_MPEG_SYNC;
176786baecfSMauro Carvalho Chehab
177786baecfSMauro Carvalho Chehab /* MPEG Valid polarity */
178786baecfSMauro Carvalho Chehab if (mpeg_valid_pol == 0)
179786baecfSMauro Carvalho Chehab mode &= ~V6_INVERTED_MPEG_VALID;
180786baecfSMauro Carvalho Chehab else
181786baecfSMauro Carvalho Chehab mode |= V6_INVERTED_MPEG_VALID;
182786baecfSMauro Carvalho Chehab
183786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, V6_MPEG_IN_CTRL_REG, mode);
184786baecfSMauro Carvalho Chehab mxl_fail(ret);
185786baecfSMauro Carvalho Chehab
186786baecfSMauro Carvalho Chehab return ret;
187786baecfSMauro Carvalho Chehab }
188786baecfSMauro Carvalho Chehab
mxl111sf_init_i2s_port(struct mxl111sf_state * state,u8 sample_size)189786baecfSMauro Carvalho Chehab int mxl111sf_init_i2s_port(struct mxl111sf_state *state, u8 sample_size)
190786baecfSMauro Carvalho Chehab {
191786baecfSMauro Carvalho Chehab static struct mxl111sf_reg_ctrl_info init_i2s[] = {
192786baecfSMauro Carvalho Chehab {0x1b, 0xff, 0x1e}, /* pin mux mode, Choose 656/I2S input */
193786baecfSMauro Carvalho Chehab {0x15, 0x60, 0x60}, /* Enable I2S */
194786baecfSMauro Carvalho Chehab {0x17, 0xe0, 0x20}, /* Input, MPEG MODE USB,
195786baecfSMauro Carvalho Chehab Inverted 656 Clock, I2S_SOFT_RESET,
196786baecfSMauro Carvalho Chehab 0 : Normal operation, 1 : Reset State */
197786baecfSMauro Carvalho Chehab #if 0
198786baecfSMauro Carvalho Chehab {0x12, 0x01, 0x00}, /* AUDIO_IRQ_CLR (Overflow Indicator) */
199786baecfSMauro Carvalho Chehab #endif
200786baecfSMauro Carvalho Chehab {0x00, 0xff, 0x02}, /* Change to Control Page */
201786baecfSMauro Carvalho Chehab {0x26, 0x0d, 0x0d}, /* I2S_MODE & BT656_SRC_SEL for FPGA only */
202786baecfSMauro Carvalho Chehab {0x00, 0xff, 0x00},
203786baecfSMauro Carvalho Chehab {0, 0, 0}
204786baecfSMauro Carvalho Chehab };
205786baecfSMauro Carvalho Chehab int ret;
206786baecfSMauro Carvalho Chehab
207786baecfSMauro Carvalho Chehab mxl_debug("(0x%02x)", sample_size);
208786baecfSMauro Carvalho Chehab
209786baecfSMauro Carvalho Chehab ret = mxl111sf_ctrl_program_regs(state, init_i2s);
210786baecfSMauro Carvalho Chehab if (mxl_fail(ret))
211786baecfSMauro Carvalho Chehab goto fail;
212786baecfSMauro Carvalho Chehab
213786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, V6_I2S_NUM_SAMPLES_REG, sample_size);
214786baecfSMauro Carvalho Chehab mxl_fail(ret);
215786baecfSMauro Carvalho Chehab fail:
216786baecfSMauro Carvalho Chehab return ret;
217786baecfSMauro Carvalho Chehab }
218786baecfSMauro Carvalho Chehab
mxl111sf_disable_i2s_port(struct mxl111sf_state * state)219786baecfSMauro Carvalho Chehab int mxl111sf_disable_i2s_port(struct mxl111sf_state *state)
220786baecfSMauro Carvalho Chehab {
221786baecfSMauro Carvalho Chehab static struct mxl111sf_reg_ctrl_info disable_i2s[] = {
222786baecfSMauro Carvalho Chehab {0x15, 0x40, 0x00},
223786baecfSMauro Carvalho Chehab {0, 0, 0}
224786baecfSMauro Carvalho Chehab };
225786baecfSMauro Carvalho Chehab
226786baecfSMauro Carvalho Chehab mxl_debug("()");
227786baecfSMauro Carvalho Chehab
228786baecfSMauro Carvalho Chehab return mxl111sf_ctrl_program_regs(state, disable_i2s);
229786baecfSMauro Carvalho Chehab }
230786baecfSMauro Carvalho Chehab
mxl111sf_config_i2s(struct mxl111sf_state * state,u8 msb_start_pos,u8 data_width)231786baecfSMauro Carvalho Chehab int mxl111sf_config_i2s(struct mxl111sf_state *state,
232786baecfSMauro Carvalho Chehab u8 msb_start_pos, u8 data_width)
233786baecfSMauro Carvalho Chehab {
234786baecfSMauro Carvalho Chehab int ret;
235786baecfSMauro Carvalho Chehab u8 tmp;
236786baecfSMauro Carvalho Chehab
237786baecfSMauro Carvalho Chehab mxl_debug("(0x%02x, 0x%02x)", msb_start_pos, data_width);
238786baecfSMauro Carvalho Chehab
239786baecfSMauro Carvalho Chehab ret = mxl111sf_read_reg(state, V6_I2S_STREAM_START_BIT_REG, &tmp);
240786baecfSMauro Carvalho Chehab if (mxl_fail(ret))
241786baecfSMauro Carvalho Chehab goto fail;
242786baecfSMauro Carvalho Chehab
243786baecfSMauro Carvalho Chehab tmp &= 0xe0;
244786baecfSMauro Carvalho Chehab tmp |= msb_start_pos;
245786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, V6_I2S_STREAM_START_BIT_REG, tmp);
246786baecfSMauro Carvalho Chehab if (mxl_fail(ret))
247786baecfSMauro Carvalho Chehab goto fail;
248786baecfSMauro Carvalho Chehab
249786baecfSMauro Carvalho Chehab ret = mxl111sf_read_reg(state, V6_I2S_STREAM_END_BIT_REG, &tmp);
250786baecfSMauro Carvalho Chehab if (mxl_fail(ret))
251786baecfSMauro Carvalho Chehab goto fail;
252786baecfSMauro Carvalho Chehab
253786baecfSMauro Carvalho Chehab tmp &= 0xe0;
254786baecfSMauro Carvalho Chehab tmp |= data_width;
255786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, V6_I2S_STREAM_END_BIT_REG, tmp);
256786baecfSMauro Carvalho Chehab mxl_fail(ret);
257786baecfSMauro Carvalho Chehab fail:
258786baecfSMauro Carvalho Chehab return ret;
259786baecfSMauro Carvalho Chehab }
260786baecfSMauro Carvalho Chehab
mxl111sf_config_spi(struct mxl111sf_state * state,int onoff)261786baecfSMauro Carvalho Chehab int mxl111sf_config_spi(struct mxl111sf_state *state, int onoff)
262786baecfSMauro Carvalho Chehab {
263786baecfSMauro Carvalho Chehab u8 val;
264786baecfSMauro Carvalho Chehab int ret;
265786baecfSMauro Carvalho Chehab
266786baecfSMauro Carvalho Chehab mxl_debug("(%d)", onoff);
267786baecfSMauro Carvalho Chehab
268786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, 0x00, 0x02);
269786baecfSMauro Carvalho Chehab if (mxl_fail(ret))
270786baecfSMauro Carvalho Chehab goto fail;
271786baecfSMauro Carvalho Chehab
272786baecfSMauro Carvalho Chehab ret = mxl111sf_read_reg(state, V8_SPI_MODE_REG, &val);
273786baecfSMauro Carvalho Chehab if (mxl_fail(ret))
274786baecfSMauro Carvalho Chehab goto fail;
275786baecfSMauro Carvalho Chehab
276786baecfSMauro Carvalho Chehab if (onoff)
277786baecfSMauro Carvalho Chehab val |= 0x04;
278786baecfSMauro Carvalho Chehab else
279786baecfSMauro Carvalho Chehab val &= ~0x04;
280786baecfSMauro Carvalho Chehab
281786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, V8_SPI_MODE_REG, val);
282786baecfSMauro Carvalho Chehab if (mxl_fail(ret))
283786baecfSMauro Carvalho Chehab goto fail;
284786baecfSMauro Carvalho Chehab
285786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, 0x00, 0x00);
286786baecfSMauro Carvalho Chehab mxl_fail(ret);
287786baecfSMauro Carvalho Chehab fail:
288786baecfSMauro Carvalho Chehab return ret;
289786baecfSMauro Carvalho Chehab }
290786baecfSMauro Carvalho Chehab
mxl111sf_idac_config(struct mxl111sf_state * state,u8 control_mode,u8 current_setting,u8 current_value,u8 hysteresis_value)291786baecfSMauro Carvalho Chehab int mxl111sf_idac_config(struct mxl111sf_state *state,
292786baecfSMauro Carvalho Chehab u8 control_mode, u8 current_setting,
293786baecfSMauro Carvalho Chehab u8 current_value, u8 hysteresis_value)
294786baecfSMauro Carvalho Chehab {
295786baecfSMauro Carvalho Chehab int ret;
296786baecfSMauro Carvalho Chehab u8 val;
297786baecfSMauro Carvalho Chehab /* current value will be set for both automatic & manual IDAC control */
298786baecfSMauro Carvalho Chehab val = current_value;
299786baecfSMauro Carvalho Chehab
300786baecfSMauro Carvalho Chehab if (control_mode == IDAC_MANUAL_CONTROL) {
301786baecfSMauro Carvalho Chehab /* enable manual control of IDAC */
302786baecfSMauro Carvalho Chehab val |= IDAC_MANUAL_CONTROL_BIT_MASK;
303786baecfSMauro Carvalho Chehab
304786baecfSMauro Carvalho Chehab if (current_setting == IDAC_CURRENT_SINKING_ENABLE)
305786baecfSMauro Carvalho Chehab /* enable current sinking in manual mode */
306786baecfSMauro Carvalho Chehab val |= IDAC_CURRENT_SINKING_BIT_MASK;
307786baecfSMauro Carvalho Chehab else
308786baecfSMauro Carvalho Chehab /* disable current sinking in manual mode */
309786baecfSMauro Carvalho Chehab val &= ~IDAC_CURRENT_SINKING_BIT_MASK;
310786baecfSMauro Carvalho Chehab } else {
311786baecfSMauro Carvalho Chehab /* disable manual control of IDAC */
312786baecfSMauro Carvalho Chehab val &= ~IDAC_MANUAL_CONTROL_BIT_MASK;
313786baecfSMauro Carvalho Chehab
314786baecfSMauro Carvalho Chehab /* set hysteresis value reg: 0x0B<5:0> */
315786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, V6_IDAC_HYSTERESIS_REG,
316786baecfSMauro Carvalho Chehab (hysteresis_value & 0x3F));
317786baecfSMauro Carvalho Chehab mxl_fail(ret);
318786baecfSMauro Carvalho Chehab }
319786baecfSMauro Carvalho Chehab
320786baecfSMauro Carvalho Chehab ret = mxl111sf_write_reg(state, V6_IDAC_SETTINGS_REG, val);
321786baecfSMauro Carvalho Chehab mxl_fail(ret);
322786baecfSMauro Carvalho Chehab
323786baecfSMauro Carvalho Chehab return ret;
324786baecfSMauro Carvalho Chehab }
325