aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/common/tuners/tda18212.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/common/tuners/tda18212.c')
-rw-r--r--drivers/media/common/tuners/tda18212.c72
1 files changed, 59 insertions, 13 deletions
diff --git a/drivers/media/common/tuners/tda18212.c b/drivers/media/common/tuners/tda18212.c
index e29cc2bc113..602c2e392b1 100644
--- a/drivers/media/common/tuners/tda18212.c
+++ b/drivers/media/common/tuners/tda18212.c
@@ -25,6 +25,8 @@
25struct tda18212_priv { 25struct tda18212_priv {
26 struct tda18212_config *cfg; 26 struct tda18212_config *cfg;
27 struct i2c_adapter *i2c; 27 struct i2c_adapter *i2c;
28
29 u32 if_frequency;
28}; 30};
29 31
30#define dbg(fmt, arg...) \ 32#define dbg(fmt, arg...) \
@@ -128,20 +130,31 @@ static void tda18212_dump_regs(struct tda18212_priv *priv)
128} 130}
129#endif 131#endif
130 132
131static int tda18212_set_params(struct dvb_frontend *fe, 133static int tda18212_set_params(struct dvb_frontend *fe)
132 struct dvb_frontend_parameters *p)
133{ 134{
134 struct tda18212_priv *priv = fe->tuner_priv; 135 struct tda18212_priv *priv = fe->tuner_priv;
135 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 136 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
136 int ret, i; 137 int ret, i;
137 u32 if_khz; 138 u32 if_khz;
138 u8 buf[9]; 139 u8 buf[9];
140 #define DVBT_6 0
141 #define DVBT_7 1
142 #define DVBT_8 2
143 #define DVBT2_6 3
144 #define DVBT2_7 4
145 #define DVBT2_8 5
146 #define DVBC_6 6
147 #define DVBC_8 7
139 static const u8 bw_params[][3] = { 148 static const u8 bw_params[][3] = {
140 /* 0f 13 23 */ 149 /* reg: 0f 13 23 */
141 { 0xb3, 0x20, 0x03 }, /* DVB-T 6 MHz */ 150 [DVBT_6] = { 0xb3, 0x20, 0x03 },
142 { 0xb3, 0x31, 0x01 }, /* DVB-T 7 MHz */ 151 [DVBT_7] = { 0xb3, 0x31, 0x01 },
143 { 0xb3, 0x22, 0x01 }, /* DVB-T 8 MHz */ 152 [DVBT_8] = { 0xb3, 0x22, 0x01 },
144 { 0x92, 0x53, 0x03 }, /* DVB-C */ 153 [DVBT2_6] = { 0xbc, 0x20, 0x03 },
154 [DVBT2_7] = { 0xbc, 0x72, 0x03 },
155 [DVBT2_8] = { 0xbc, 0x22, 0x01 },
156 [DVBC_6] = { 0x92, 0x50, 0x03 },
157 [DVBC_8] = { 0x92, 0x53, 0x03 },
145 }; 158 };
146 159
147 dbg("delsys=%d RF=%d BW=%d\n", 160 dbg("delsys=%d RF=%d BW=%d\n",
@@ -155,24 +168,44 @@ static int tda18212_set_params(struct dvb_frontend *fe,
155 switch (c->bandwidth_hz) { 168 switch (c->bandwidth_hz) {
156 case 6000000: 169 case 6000000:
157 if_khz = priv->cfg->if_dvbt_6; 170 if_khz = priv->cfg->if_dvbt_6;
158 i = 0; 171 i = DVBT_6;
159 break; 172 break;
160 case 7000000: 173 case 7000000:
161 if_khz = priv->cfg->if_dvbt_7; 174 if_khz = priv->cfg->if_dvbt_7;
162 i = 1; 175 i = DVBT_7;
163 break; 176 break;
164 case 8000000: 177 case 8000000:
165 if_khz = priv->cfg->if_dvbt_8; 178 if_khz = priv->cfg->if_dvbt_8;
166 i = 2; 179 i = DVBT_8;
167 break; 180 break;
168 default: 181 default:
169 ret = -EINVAL; 182 ret = -EINVAL;
170 goto error; 183 goto error;
171 } 184 }
172 break; 185 break;
173 case SYS_DVBC_ANNEX_AC: 186 case SYS_DVBT2:
187 switch (c->bandwidth_hz) {
188 case 6000000:
189 if_khz = priv->cfg->if_dvbt2_6;
190 i = DVBT2_6;
191 break;
192 case 7000000:
193 if_khz = priv->cfg->if_dvbt2_7;
194 i = DVBT2_7;
195 break;
196 case 8000000:
197 if_khz = priv->cfg->if_dvbt2_8;
198 i = DVBT2_8;
199 break;
200 default:
201 ret = -EINVAL;
202 goto error;
203 }
204 break;
205 case SYS_DVBC_ANNEX_A:
206 case SYS_DVBC_ANNEX_C:
174 if_khz = priv->cfg->if_dvbc; 207 if_khz = priv->cfg->if_dvbc;
175 i = 3; 208 i = DVBC_8;
176 break; 209 break;
177 default: 210 default:
178 ret = -EINVAL; 211 ret = -EINVAL;
@@ -194,7 +227,7 @@ static int tda18212_set_params(struct dvb_frontend *fe,
194 buf[0] = 0x02; 227 buf[0] = 0x02;
195 buf[1] = bw_params[i][1]; 228 buf[1] = bw_params[i][1];
196 buf[2] = 0x03; /* default value */ 229 buf[2] = 0x03; /* default value */
197 buf[3] = if_khz / 50; 230 buf[3] = DIV_ROUND_CLOSEST(if_khz, 50);
198 buf[4] = ((c->frequency / 1000) >> 16) & 0xff; 231 buf[4] = ((c->frequency / 1000) >> 16) & 0xff;
199 buf[5] = ((c->frequency / 1000) >> 8) & 0xff; 232 buf[5] = ((c->frequency / 1000) >> 8) & 0xff;
200 buf[6] = ((c->frequency / 1000) >> 0) & 0xff; 233 buf[6] = ((c->frequency / 1000) >> 0) & 0xff;
@@ -204,6 +237,9 @@ static int tda18212_set_params(struct dvb_frontend *fe,
204 if (ret) 237 if (ret)
205 goto error; 238 goto error;
206 239
240 /* actual IF rounded as it is on register */
241 priv->if_frequency = buf[3] * 50 * 1000;
242
207exit: 243exit:
208 if (fe->ops.i2c_gate_ctrl) 244 if (fe->ops.i2c_gate_ctrl)
209 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ 245 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
@@ -215,6 +251,15 @@ error:
215 goto exit; 251 goto exit;
216} 252}
217 253
254static int tda18212_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
255{
256 struct tda18212_priv *priv = fe->tuner_priv;
257
258 *frequency = priv->if_frequency;
259
260 return 0;
261}
262
218static int tda18212_release(struct dvb_frontend *fe) 263static int tda18212_release(struct dvb_frontend *fe)
219{ 264{
220 kfree(fe->tuner_priv); 265 kfree(fe->tuner_priv);
@@ -234,6 +279,7 @@ static const struct dvb_tuner_ops tda18212_tuner_ops = {
234 .release = tda18212_release, 279 .release = tda18212_release,
235 280
236 .set_params = tda18212_set_params, 281 .set_params = tda18212_set_params,
282 .get_if_frequency = tda18212_get_if_frequency,
237}; 283};
238 284
239struct dvb_frontend *tda18212_attach(struct dvb_frontend *fe, 285struct dvb_frontend *tda18212_attach(struct dvb_frontend *fe,