aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/frontends/l64781.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb/frontends/l64781.c')
-rw-r--r--drivers/media/dvb/frontends/l64781.c117
1 files changed, 62 insertions, 55 deletions
diff --git a/drivers/media/dvb/frontends/l64781.c b/drivers/media/dvb/frontends/l64781.c
index 445fa1068064..36fcf559e361 100644
--- a/drivers/media/dvb/frontends/l64781.c
+++ b/drivers/media/dvb/frontends/l64781.c
@@ -117,18 +117,17 @@ static int reset_and_configure (struct l64781_state* state)
117 return (i2c_transfer(state->i2c, &msg, 1) == 1) ? 0 : -ENODEV; 117 return (i2c_transfer(state->i2c, &msg, 1) == 1) ? 0 : -ENODEV;
118} 118}
119 119
120static int apply_frontend_param (struct dvb_frontend* fe, struct dvb_frontend_parameters *param) 120static int apply_frontend_param(struct dvb_frontend *fe)
121{ 121{
122 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
122 struct l64781_state* state = fe->demodulator_priv; 123 struct l64781_state* state = fe->demodulator_priv;
123 /* The coderates for FEC_NONE, FEC_4_5 and FEC_FEC_6_7 are arbitrary */ 124 /* The coderates for FEC_NONE, FEC_4_5 and FEC_FEC_6_7 are arbitrary */
124 static const u8 fec_tab[] = { 7, 0, 1, 2, 9, 3, 10, 4 }; 125 static const u8 fec_tab[] = { 7, 0, 1, 2, 9, 3, 10, 4 };
125 /* QPSK, QAM_16, QAM_64 */ 126 /* QPSK, QAM_16, QAM_64 */
126 static const u8 qam_tab [] = { 2, 4, 0, 6 }; 127 static const u8 qam_tab [] = { 2, 4, 0, 6 };
127 static const u8 bw_tab [] = { 8, 7, 6 }; /* 8Mhz, 7MHz, 6MHz */
128 static const u8 guard_tab [] = { 1, 2, 4, 8 }; 128 static const u8 guard_tab [] = { 1, 2, 4, 8 };
129 /* The Grundig 29504-401.04 Tuner comes with 18.432MHz crystal. */ 129 /* The Grundig 29504-401.04 Tuner comes with 18.432MHz crystal. */
130 static const u32 ppm = 8000; 130 static const u32 ppm = 8000;
131 struct dvb_ofdm_parameters *p = &param->u.ofdm;
132 u32 ddfs_offset_fixed; 131 u32 ddfs_offset_fixed;
133/* u32 ddfs_offset_variable = 0x6000-((1000000UL+ppm)/ */ 132/* u32 ddfs_offset_variable = 0x6000-((1000000UL+ppm)/ */
134/* bw_tab[p->bandWidth]<<10)/15625; */ 133/* bw_tab[p->bandWidth]<<10)/15625; */
@@ -137,18 +136,29 @@ static int apply_frontend_param (struct dvb_frontend* fe, struct dvb_frontend_pa
137 u8 val0x04; 136 u8 val0x04;
138 u8 val0x05; 137 u8 val0x05;
139 u8 val0x06; 138 u8 val0x06;
140 int bw = p->bandwidth - BANDWIDTH_8_MHZ; 139 int bw;
140
141 switch (p->bandwidth_hz) {
142 case 8000000:
143 bw = 8;
144 break;
145 case 7000000:
146 bw = 7;
147 break;
148 case 6000000:
149 bw = 6;
150 break;
151 default:
152 return -EINVAL;
153 }
141 154
142 if (fe->ops.tuner_ops.set_params) { 155 if (fe->ops.tuner_ops.set_params) {
143 fe->ops.tuner_ops.set_params(fe, param); 156 fe->ops.tuner_ops.set_params(fe);
144 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); 157 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0);
145 } 158 }
146 159
147 if (param->inversion != INVERSION_ON && 160 if (p->inversion != INVERSION_ON &&
148 param->inversion != INVERSION_OFF) 161 p->inversion != INVERSION_OFF)
149 return -EINVAL;
150
151 if (bw < 0 || bw > 2)
152 return -EINVAL; 162 return -EINVAL;
153 163
154 if (p->code_rate_HP != FEC_1_2 && p->code_rate_HP != FEC_2_3 && 164 if (p->code_rate_HP != FEC_1_2 && p->code_rate_HP != FEC_2_3 &&
@@ -156,14 +166,14 @@ static int apply_frontend_param (struct dvb_frontend* fe, struct dvb_frontend_pa
156 p->code_rate_HP != FEC_7_8) 166 p->code_rate_HP != FEC_7_8)
157 return -EINVAL; 167 return -EINVAL;
158 168
159 if (p->hierarchy_information != HIERARCHY_NONE && 169 if (p->hierarchy != HIERARCHY_NONE &&
160 (p->code_rate_LP != FEC_1_2 && p->code_rate_LP != FEC_2_3 && 170 (p->code_rate_LP != FEC_1_2 && p->code_rate_LP != FEC_2_3 &&
161 p->code_rate_LP != FEC_3_4 && p->code_rate_LP != FEC_5_6 && 171 p->code_rate_LP != FEC_3_4 && p->code_rate_LP != FEC_5_6 &&
162 p->code_rate_LP != FEC_7_8)) 172 p->code_rate_LP != FEC_7_8))
163 return -EINVAL; 173 return -EINVAL;
164 174
165 if (p->constellation != QPSK && p->constellation != QAM_16 && 175 if (p->modulation != QPSK && p->modulation != QAM_16 &&
166 p->constellation != QAM_64) 176 p->modulation != QAM_64)
167 return -EINVAL; 177 return -EINVAL;
168 178
169 if (p->transmission_mode != TRANSMISSION_MODE_2K && 179 if (p->transmission_mode != TRANSMISSION_MODE_2K &&
@@ -174,22 +184,22 @@ static int apply_frontend_param (struct dvb_frontend* fe, struct dvb_frontend_pa
174 p->guard_interval > GUARD_INTERVAL_1_4) 184 p->guard_interval > GUARD_INTERVAL_1_4)
175 return -EINVAL; 185 return -EINVAL;
176 186
177 if (p->hierarchy_information < HIERARCHY_NONE || 187 if (p->hierarchy < HIERARCHY_NONE ||
178 p->hierarchy_information > HIERARCHY_4) 188 p->hierarchy > HIERARCHY_4)
179 return -EINVAL; 189 return -EINVAL;
180 190
181 ddfs_offset_fixed = 0x4000-(ppm<<16)/bw_tab[p->bandwidth]/1000000; 191 ddfs_offset_fixed = 0x4000-(ppm<<16)/bw/1000000;
182 192
183 /* This works up to 20000 ppm, it overflows if too large ppm! */ 193 /* This works up to 20000 ppm, it overflows if too large ppm! */
184 init_freq = (((8UL<<25) + (8UL<<19) / 25*ppm / (15625/25)) / 194 init_freq = (((8UL<<25) + (8UL<<19) / 25*ppm / (15625/25)) /
185 bw_tab[p->bandwidth] & 0xFFFFFF); 195 bw & 0xFFFFFF);
186 196
187 /* SPI bias calculation is slightly modified to fit in 32bit */ 197 /* SPI bias calculation is slightly modified to fit in 32bit */
188 /* will work for high ppm only... */ 198 /* will work for high ppm only... */
189 spi_bias = 378 * (1 << 10); 199 spi_bias = 378 * (1 << 10);
190 spi_bias *= 16; 200 spi_bias *= 16;
191 spi_bias *= bw_tab[p->bandwidth]; 201 spi_bias *= bw;
192 spi_bias *= qam_tab[p->constellation]; 202 spi_bias *= qam_tab[p->modulation];
193 spi_bias /= p->code_rate_HP + 1; 203 spi_bias /= p->code_rate_HP + 1;
194 spi_bias /= (guard_tab[p->guard_interval] + 32); 204 spi_bias /= (guard_tab[p->guard_interval] + 32);
195 spi_bias *= 1000; 205 spi_bias *= 1000;
@@ -199,10 +209,10 @@ static int apply_frontend_param (struct dvb_frontend* fe, struct dvb_frontend_pa
199 val0x04 = (p->transmission_mode << 2) | p->guard_interval; 209 val0x04 = (p->transmission_mode << 2) | p->guard_interval;
200 val0x05 = fec_tab[p->code_rate_HP]; 210 val0x05 = fec_tab[p->code_rate_HP];
201 211
202 if (p->hierarchy_information != HIERARCHY_NONE) 212 if (p->hierarchy != HIERARCHY_NONE)
203 val0x05 |= (p->code_rate_LP - FEC_1_2) << 3; 213 val0x05 |= (p->code_rate_LP - FEC_1_2) << 3;
204 214
205 val0x06 = (p->hierarchy_information << 2) | p->constellation; 215 val0x06 = (p->hierarchy << 2) | p->modulation;
206 216
207 l64781_writereg (state, 0x04, val0x04); 217 l64781_writereg (state, 0x04, val0x04);
208 l64781_writereg (state, 0x05, val0x05); 218 l64781_writereg (state, 0x05, val0x05);
@@ -220,7 +230,7 @@ static int apply_frontend_param (struct dvb_frontend* fe, struct dvb_frontend_pa
220 l64781_writereg (state, 0x1b, spi_bias & 0xff); 230 l64781_writereg (state, 0x1b, spi_bias & 0xff);
221 l64781_writereg (state, 0x1c, (spi_bias >> 8) & 0xff); 231 l64781_writereg (state, 0x1c, (spi_bias >> 8) & 0xff);
222 l64781_writereg (state, 0x1d, ((spi_bias >> 16) & 0x7f) | 232 l64781_writereg (state, 0x1d, ((spi_bias >> 16) & 0x7f) |
223 (param->inversion == INVERSION_ON ? 0x80 : 0x00)); 233 (p->inversion == INVERSION_ON ? 0x80 : 0x00));
224 234
225 l64781_writereg (state, 0x22, ddfs_offset_fixed & 0xff); 235 l64781_writereg (state, 0x22, ddfs_offset_fixed & 0xff);
226 l64781_writereg (state, 0x23, (ddfs_offset_fixed >> 8) & 0x3f); 236 l64781_writereg (state, 0x23, (ddfs_offset_fixed >> 8) & 0x3f);
@@ -233,8 +243,9 @@ static int apply_frontend_param (struct dvb_frontend* fe, struct dvb_frontend_pa
233 return 0; 243 return 0;
234} 244}
235 245
236static int get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters* param) 246static int get_frontend(struct dvb_frontend *fe)
237{ 247{
248 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
238 struct l64781_state* state = fe->demodulator_priv; 249 struct l64781_state* state = fe->demodulator_priv;
239 int tmp; 250 int tmp;
240 251
@@ -242,98 +253,95 @@ static int get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters*
242 tmp = l64781_readreg(state, 0x04); 253 tmp = l64781_readreg(state, 0x04);
243 switch(tmp & 3) { 254 switch(tmp & 3) {
244 case 0: 255 case 0:
245 param->u.ofdm.guard_interval = GUARD_INTERVAL_1_32; 256 p->guard_interval = GUARD_INTERVAL_1_32;
246 break; 257 break;
247 case 1: 258 case 1:
248 param->u.ofdm.guard_interval = GUARD_INTERVAL_1_16; 259 p->guard_interval = GUARD_INTERVAL_1_16;
249 break; 260 break;
250 case 2: 261 case 2:
251 param->u.ofdm.guard_interval = GUARD_INTERVAL_1_8; 262 p->guard_interval = GUARD_INTERVAL_1_8;
252 break; 263 break;
253 case 3: 264 case 3:
254 param->u.ofdm.guard_interval = GUARD_INTERVAL_1_4; 265 p->guard_interval = GUARD_INTERVAL_1_4;
255 break; 266 break;
256 } 267 }
257 switch((tmp >> 2) & 3) { 268 switch((tmp >> 2) & 3) {
258 case 0: 269 case 0:
259 param->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K; 270 p->transmission_mode = TRANSMISSION_MODE_2K;
260 break; 271 break;
261 case 1: 272 case 1:
262 param->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K; 273 p->transmission_mode = TRANSMISSION_MODE_8K;
263 break; 274 break;
264 default: 275 default:
265 printk("Unexpected value for transmission_mode\n"); 276 printk(KERN_WARNING "Unexpected value for transmission_mode\n");
266 } 277 }
267 278
268
269
270 tmp = l64781_readreg(state, 0x05); 279 tmp = l64781_readreg(state, 0x05);
271 switch(tmp & 7) { 280 switch(tmp & 7) {
272 case 0: 281 case 0:
273 param->u.ofdm.code_rate_HP = FEC_1_2; 282 p->code_rate_HP = FEC_1_2;
274 break; 283 break;
275 case 1: 284 case 1:
276 param->u.ofdm.code_rate_HP = FEC_2_3; 285 p->code_rate_HP = FEC_2_3;
277 break; 286 break;
278 case 2: 287 case 2:
279 param->u.ofdm.code_rate_HP = FEC_3_4; 288 p->code_rate_HP = FEC_3_4;
280 break; 289 break;
281 case 3: 290 case 3:
282 param->u.ofdm.code_rate_HP = FEC_5_6; 291 p->code_rate_HP = FEC_5_6;
283 break; 292 break;
284 case 4: 293 case 4:
285 param->u.ofdm.code_rate_HP = FEC_7_8; 294 p->code_rate_HP = FEC_7_8;
286 break; 295 break;
287 default: 296 default:
288 printk("Unexpected value for code_rate_HP\n"); 297 printk("Unexpected value for code_rate_HP\n");
289 } 298 }
290 switch((tmp >> 3) & 7) { 299 switch((tmp >> 3) & 7) {
291 case 0: 300 case 0:
292 param->u.ofdm.code_rate_LP = FEC_1_2; 301 p->code_rate_LP = FEC_1_2;
293 break; 302 break;
294 case 1: 303 case 1:
295 param->u.ofdm.code_rate_LP = FEC_2_3; 304 p->code_rate_LP = FEC_2_3;
296 break; 305 break;
297 case 2: 306 case 2:
298 param->u.ofdm.code_rate_LP = FEC_3_4; 307 p->code_rate_LP = FEC_3_4;
299 break; 308 break;
300 case 3: 309 case 3:
301 param->u.ofdm.code_rate_LP = FEC_5_6; 310 p->code_rate_LP = FEC_5_6;
302 break; 311 break;
303 case 4: 312 case 4:
304 param->u.ofdm.code_rate_LP = FEC_7_8; 313 p->code_rate_LP = FEC_7_8;
305 break; 314 break;
306 default: 315 default:
307 printk("Unexpected value for code_rate_LP\n"); 316 printk("Unexpected value for code_rate_LP\n");
308 } 317 }
309 318
310
311 tmp = l64781_readreg(state, 0x06); 319 tmp = l64781_readreg(state, 0x06);
312 switch(tmp & 3) { 320 switch(tmp & 3) {
313 case 0: 321 case 0:
314 param->u.ofdm.constellation = QPSK; 322 p->modulation = QPSK;
315 break; 323 break;
316 case 1: 324 case 1:
317 param->u.ofdm.constellation = QAM_16; 325 p->modulation = QAM_16;
318 break; 326 break;
319 case 2: 327 case 2:
320 param->u.ofdm.constellation = QAM_64; 328 p->modulation = QAM_64;
321 break; 329 break;
322 default: 330 default:
323 printk("Unexpected value for constellation\n"); 331 printk(KERN_WARNING "Unexpected value for modulation\n");
324 } 332 }
325 switch((tmp >> 2) & 7) { 333 switch((tmp >> 2) & 7) {
326 case 0: 334 case 0:
327 param->u.ofdm.hierarchy_information = HIERARCHY_NONE; 335 p->hierarchy = HIERARCHY_NONE;
328 break; 336 break;
329 case 1: 337 case 1:
330 param->u.ofdm.hierarchy_information = HIERARCHY_1; 338 p->hierarchy = HIERARCHY_1;
331 break; 339 break;
332 case 2: 340 case 2:
333 param->u.ofdm.hierarchy_information = HIERARCHY_2; 341 p->hierarchy = HIERARCHY_2;
334 break; 342 break;
335 case 3: 343 case 3:
336 param->u.ofdm.hierarchy_information = HIERARCHY_4; 344 p->hierarchy = HIERARCHY_4;
337 break; 345 break;
338 default: 346 default:
339 printk("Unexpected value for hierarchy\n"); 347 printk("Unexpected value for hierarchy\n");
@@ -341,12 +349,12 @@ static int get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters*
341 349
342 350
343 tmp = l64781_readreg (state, 0x1d); 351 tmp = l64781_readreg (state, 0x1d);
344 param->inversion = (tmp & 0x80) ? INVERSION_ON : INVERSION_OFF; 352 p->inversion = (tmp & 0x80) ? INVERSION_ON : INVERSION_OFF;
345 353
346 tmp = (int) (l64781_readreg (state, 0x08) | 354 tmp = (int) (l64781_readreg (state, 0x08) |
347 (l64781_readreg (state, 0x09) << 8) | 355 (l64781_readreg (state, 0x09) << 8) |
348 (l64781_readreg (state, 0x0a) << 16)); 356 (l64781_readreg (state, 0x0a) << 16));
349 param->frequency += tmp; 357 p->frequency += tmp;
350 358
351 return 0; 359 return 0;
352} 360}
@@ -564,10 +572,9 @@ error:
564} 572}
565 573
566static struct dvb_frontend_ops l64781_ops = { 574static struct dvb_frontend_ops l64781_ops = {
567 575 .delsys = { SYS_DVBT },
568 .info = { 576 .info = {
569 .name = "LSI L64781 DVB-T", 577 .name = "LSI L64781 DVB-T",
570 .type = FE_OFDM,
571 /* .frequency_min = ???,*/ 578 /* .frequency_min = ???,*/
572 /* .frequency_max = ???,*/ 579 /* .frequency_max = ???,*/
573 .frequency_stepsize = 166666, 580 .frequency_stepsize = 166666,