diff options
author | Michael Krufky <mkrufky@linuxtv.org> | 2007-12-24 22:39:37 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-01-25 16:04:25 -0500 |
commit | 2f27dfc98cc0a183be9e3c2fc0da0450b85e5fde (patch) | |
tree | e47034d3d6b0c09c34de248e18a01a880d485abc /drivers/media | |
parent | d37142102a2adaa3391a384ea6a780afb5804789 (diff) |
V4L/DVB (6926): tda18271: consolidate table lookup functions
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/dvb/frontends/tda18271-fe.c | 28 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/tda18271-priv.h | 26 | ||||
-rw-r--r-- | drivers/media/dvb/frontends/tda18271-tables.c | 126 |
3 files changed, 106 insertions, 74 deletions
diff --git a/drivers/media/dvb/frontends/tda18271-fe.c b/drivers/media/dvb/frontends/tda18271-fe.c index 4526def2d42f..72e256ebeb0f 100644 --- a/drivers/media/dvb/frontends/tda18271-fe.c +++ b/drivers/media/dvb/frontends/tda18271-fe.c | |||
@@ -360,7 +360,9 @@ static int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq) | |||
360 | u8 d, pd; | 360 | u8 d, pd; |
361 | u32 div; | 361 | u32 div; |
362 | 362 | ||
363 | tda18271_lookup_main_pll(&freq, &pd, &d); | 363 | int ret = tda18271_lookup_pll_map(MAIN_PLL, &freq, &pd, &d); |
364 | if (ret < 0) | ||
365 | goto fail; | ||
364 | 366 | ||
365 | regs[R_MPD] = (0x77 & pd); | 367 | regs[R_MPD] = (0x77 & pd); |
366 | 368 | ||
@@ -378,8 +380,8 @@ static int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq) | |||
378 | regs[R_MD1] = 0x7f & (div >> 16); | 380 | regs[R_MD1] = 0x7f & (div >> 16); |
379 | regs[R_MD2] = 0xff & (div >> 8); | 381 | regs[R_MD2] = 0xff & (div >> 8); |
380 | regs[R_MD3] = 0xff & div; | 382 | regs[R_MD3] = 0xff & div; |
381 | 383 | fail: | |
382 | return 0; | 384 | return ret; |
383 | } | 385 | } |
384 | 386 | ||
385 | static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq) | 387 | static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq) |
@@ -390,7 +392,9 @@ static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq) | |||
390 | u8 d, pd; | 392 | u8 d, pd; |
391 | u32 div; | 393 | u32 div; |
392 | 394 | ||
393 | tda18271_lookup_cal_pll(&freq, &pd, &d); | 395 | int ret = tda18271_lookup_pll_map(CAL_PLL, &freq, &pd, &d); |
396 | if (ret < 0) | ||
397 | goto fail; | ||
394 | 398 | ||
395 | regs[R_CPD] = pd; | 399 | regs[R_CPD] = pd; |
396 | 400 | ||
@@ -399,8 +403,8 @@ static int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq) | |||
399 | regs[R_CD1] = 0x7f & (div >> 16); | 403 | regs[R_CD1] = 0x7f & (div >> 16); |
400 | regs[R_CD2] = 0xff & (div >> 8); | 404 | regs[R_CD2] = 0xff & (div >> 8); |
401 | regs[R_CD3] = 0xff & div; | 405 | regs[R_CD3] = 0xff & div; |
402 | 406 | fail: | |
403 | return 0; | 407 | return ret; |
404 | } | 408 | } |
405 | 409 | ||
406 | static int tda18271_tune(struct dvb_frontend *fe, | 410 | static int tda18271_tune(struct dvb_frontend *fe, |
@@ -418,7 +422,7 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
418 | /* RF tracking filter calibration */ | 422 | /* RF tracking filter calibration */ |
419 | 423 | ||
420 | /* calculate BP_Filter */ | 424 | /* calculate BP_Filter */ |
421 | tda18271_lookup_bp_filter(&freq, &val); | 425 | tda18271_lookup_map(BP_FILTER, &freq, &val); |
422 | 426 | ||
423 | regs[R_EP1] &= ~0x07; /* clear bp filter bits */ | 427 | regs[R_EP1] &= ~0x07; /* clear bp filter bits */ |
424 | regs[R_EP1] |= val; | 428 | regs[R_EP1] |= val; |
@@ -470,20 +474,20 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
470 | msleep(5); /* RF tracking filter calibration initialization */ | 474 | msleep(5); /* RF tracking filter calibration initialization */ |
471 | 475 | ||
472 | /* search for K,M,CO for RF Calibration */ | 476 | /* search for K,M,CO for RF Calibration */ |
473 | tda18271_lookup_km(&freq, &val); | 477 | tda18271_lookup_map(RF_CAL_KMCO, &freq, &val); |
474 | 478 | ||
475 | regs[R_EB13] &= 0x83; | 479 | regs[R_EB13] &= 0x83; |
476 | regs[R_EB13] |= val; | 480 | regs[R_EB13] |= val; |
477 | tda18271_write_regs(fe, R_EB13, 1); | 481 | tda18271_write_regs(fe, R_EB13, 1); |
478 | 482 | ||
479 | /* search for RF_BAND */ | 483 | /* search for RF_BAND */ |
480 | tda18271_lookup_rf_band(&freq, &val); | 484 | tda18271_lookup_map(RF_BAND, &freq, &val); |
481 | 485 | ||
482 | regs[R_EP2] &= ~0xe0; /* clear rf band bits */ | 486 | regs[R_EP2] &= ~0xe0; /* clear rf band bits */ |
483 | regs[R_EP2] |= (val << 5); | 487 | regs[R_EP2] |= (val << 5); |
484 | 488 | ||
485 | /* search for Gain_Taper */ | 489 | /* search for Gain_Taper */ |
486 | tda18271_lookup_gain_taper(&freq, &val); | 490 | tda18271_lookup_map(GAIN_TAPER, &freq, &val); |
487 | 491 | ||
488 | regs[R_EP2] &= ~0x1f; /* clear gain taper bits */ | 492 | regs[R_EP2] &= ~0x1f; /* clear gain taper bits */ |
489 | regs[R_EP2] |= val; | 493 | regs[R_EP2] |= val; |
@@ -511,7 +515,7 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
511 | tda18271_write_regs(fe, R_EP1, 1); | 515 | tda18271_write_regs(fe, R_EP1, 1); |
512 | 516 | ||
513 | /* RF tracking filer correction for VHF_Low band */ | 517 | /* RF tracking filer correction for VHF_Low band */ |
514 | tda18271_lookup_rf_cal(&freq, &val); | 518 | tda18271_lookup_map(RF_CAL, &freq, &val); |
515 | 519 | ||
516 | /* VHF_Low band only */ | 520 | /* VHF_Low band only */ |
517 | if (val != 0) { | 521 | if (val != 0) { |
@@ -555,7 +559,7 @@ static int tda18271_tune(struct dvb_frontend *fe, | |||
555 | regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */ | 559 | regs[R_EP4] &= ~0x80; /* turn this bit on only for fm */ |
556 | 560 | ||
557 | /* image rejection validity EP5[2:0] */ | 561 | /* image rejection validity EP5[2:0] */ |
558 | tda18271_lookup_ir_measure(&freq, &val); | 562 | tda18271_lookup_map(IR_MEASURE, &freq, &val); |
559 | 563 | ||
560 | regs[R_EP5] &= ~0x07; | 564 | regs[R_EP5] &= ~0x07; |
561 | regs[R_EP5] |= val; | 565 | regs[R_EP5] |= val; |
diff --git a/drivers/media/dvb/frontends/tda18271-priv.h b/drivers/media/dvb/frontends/tda18271-priv.h index 7b9aa9ad53fe..b08bf08aa88f 100644 --- a/drivers/media/dvb/frontends/tda18271-priv.h +++ b/drivers/media/dvb/frontends/tda18271-priv.h | |||
@@ -104,15 +104,23 @@ extern int tda18271_debug; | |||
104 | 104 | ||
105 | /*---------------------------------------------------------------------*/ | 105 | /*---------------------------------------------------------------------*/ |
106 | 106 | ||
107 | extern void tda18271_lookup_cal_pll(u32 *freq, u8 *post_div, u8 *div); | 107 | enum tda18271_map_type { |
108 | extern void tda18271_lookup_main_pll(u32 *freq, u8 *post_div, u8 *div); | 108 | /* tda18271_pll_map */ |
109 | 109 | MAIN_PLL, | |
110 | extern void tda18271_lookup_bp_filter(u32 *freq, u8 *val); | 110 | CAL_PLL, |
111 | extern void tda18271_lookup_km(u32 *freq, u8 *val); | 111 | /* tda18271_map */ |
112 | extern void tda18271_lookup_rf_band(u32 *freq, u8 *val); | 112 | RF_CAL, |
113 | extern void tda18271_lookup_gain_taper(u32 *freq, u8 *val); | 113 | RF_CAL_KMCO, |
114 | extern void tda18271_lookup_rf_cal(u32 *freq, u8 *val); | 114 | BP_FILTER, |
115 | extern void tda18271_lookup_ir_measure(u32 *freq, u8 *val); | 115 | RF_BAND, |
116 | GAIN_TAPER, | ||
117 | IR_MEASURE, | ||
118 | }; | ||
119 | |||
120 | extern int tda18271_lookup_pll_map(enum tda18271_map_type map_type, | ||
121 | u32 *freq, u8 *post_div, u8 *div); | ||
122 | extern int tda18271_lookup_map(enum tda18271_map_type map_type, | ||
123 | u32 *freq, u8 *val); | ||
116 | 124 | ||
117 | #endif /* __TDA18271_PRIV_H__ */ | 125 | #endif /* __TDA18271_PRIV_H__ */ |
118 | 126 | ||
diff --git a/drivers/media/dvb/frontends/tda18271-tables.c b/drivers/media/dvb/frontends/tda18271-tables.c index 02b6d2cb9570..8990bef0cf7e 100644 --- a/drivers/media/dvb/frontends/tda18271-tables.c +++ b/drivers/media/dvb/frontends/tda18271-tables.c | |||
@@ -267,22 +267,33 @@ static struct tda18271_map tda18271_ir_measure[] = { | |||
267 | 267 | ||
268 | /*---------------------------------------------------------------------*/ | 268 | /*---------------------------------------------------------------------*/ |
269 | 269 | ||
270 | static void tda18271_lookup_map(struct tda18271_map *map, | 270 | int tda18271_lookup_pll_map(enum tda18271_map_type map_type, |
271 | u32 *freq, u8 *val) | 271 | u32 *freq, u8 *post_div, u8 *div) |
272 | { | 272 | { |
273 | int i = 0; | 273 | struct tda18271_pll_map *map = NULL; |
274 | while ((map[i].rfmax * 1000) < *freq) { | 274 | unsigned int i = 0; |
275 | if (map[i + 1].rfmax == 0) | 275 | char *map_name; |
276 | break; | 276 | |
277 | i++; | 277 | switch (map_type) { |
278 | case MAIN_PLL: | ||
279 | map = tda18271_main_pll; | ||
280 | map_name = "main_pll"; | ||
281 | break; | ||
282 | case CAL_PLL: | ||
283 | map = tda18271_cal_pll; | ||
284 | map_name = "cal_pll"; | ||
285 | break; | ||
286 | default: | ||
287 | /* we should never get here */ | ||
288 | map_name = "undefined"; | ||
289 | break; | ||
290 | } | ||
291 | |||
292 | if (!map) { | ||
293 | dbg_info("%s map is not set!\n", map_name); | ||
294 | return -EINVAL; | ||
278 | } | 295 | } |
279 | *val = map[i].val; | ||
280 | } | ||
281 | 296 | ||
282 | static void tda18271_lookup_pll_map(struct tda18271_pll_map *map, | ||
283 | u32 *freq, u8 *post_div, u8 *div) | ||
284 | { | ||
285 | int i = 0; | ||
286 | while ((map[i].lomax * 1000) < *freq) { | 297 | while ((map[i].lomax * 1000) < *freq) { |
287 | if (map[i + 1].lomax == 0) | 298 | if (map[i + 1].lomax == 0) |
288 | break; | 299 | break; |
@@ -290,56 +301,65 @@ static void tda18271_lookup_pll_map(struct tda18271_pll_map *map, | |||
290 | } | 301 | } |
291 | *post_div = map[i].pd; | 302 | *post_div = map[i].pd; |
292 | *div = map[i].d; | 303 | *div = map[i].d; |
293 | } | ||
294 | |||
295 | /*---------------------------------------------------------------------*/ | ||
296 | 304 | ||
297 | void tda18271_lookup_cal_pll(u32 *freq, u8 *post_div, u8 *div) | 305 | dbg_map("%s: post div = 0x%02x, div = 0x%02x\n", |
298 | { | 306 | map_name, *post_div, *div); |
299 | tda18271_lookup_pll_map(tda18271_cal_pll, freq, post_div, div); | ||
300 | dbg_map("post div = 0x%02x, div = 0x%02x\n", *post_div, *div); | ||
301 | } | ||
302 | 307 | ||
303 | void tda18271_lookup_main_pll(u32 *freq, u8 *post_div, u8 *div) | 308 | return 0; |
304 | { | ||
305 | tda18271_lookup_pll_map(tda18271_main_pll, freq, post_div, div); | ||
306 | dbg_map("post div = 0x%02x, div = 0x%02x\n", *post_div, *div); | ||
307 | } | 309 | } |
308 | 310 | ||
309 | void tda18271_lookup_bp_filter(u32 *freq, u8 *val) | 311 | int tda18271_lookup_map(enum tda18271_map_type map_type, u32 *freq, u8 *val) |
310 | { | 312 | { |
311 | tda18271_lookup_map(tda18271_bp_filter, freq, val); | 313 | struct tda18271_map *map = NULL; |
312 | dbg_map("0x%02x\n", *val); | 314 | unsigned int i = 0; |
313 | } | 315 | char *map_name; |
314 | 316 | ||
315 | void tda18271_lookup_km(u32 *freq, u8 *val) | 317 | switch (map_type) { |
316 | { | 318 | case BP_FILTER: |
317 | tda18271_lookup_map(tda18271_km, freq, val); | 319 | map = tda18271_bp_filter; |
318 | dbg_map("0x%02x\n", *val); | 320 | map_name = "bp_filter"; |
319 | } | 321 | break; |
322 | case RF_CAL_KMCO: | ||
323 | map = tda18271_km; | ||
324 | map_name = "km"; | ||
325 | break; | ||
326 | case RF_BAND: | ||
327 | map = tda18271_rf_band; | ||
328 | map_name = "rf_band"; | ||
329 | break; | ||
330 | case GAIN_TAPER: | ||
331 | map = tda18271_gain_taper; | ||
332 | map_name = "gain_taper"; | ||
333 | break; | ||
334 | case RF_CAL: | ||
335 | map = tda18271_rf_cal; | ||
336 | map_name = "rf_cal"; | ||
337 | break; | ||
338 | case IR_MEASURE: | ||
339 | map = tda18271_ir_measure; | ||
340 | map_name = "ir_measure"; | ||
341 | break; | ||
342 | default: | ||
343 | /* we should never get here */ | ||
344 | map_name = "undefined"; | ||
345 | break; | ||
346 | } | ||
320 | 347 | ||
321 | void tda18271_lookup_rf_band(u32 *freq, u8 *val) | 348 | if (!map) { |
322 | { | 349 | dbg_info("%s map is not set!\n", map_name); |
323 | tda18271_lookup_map(tda18271_rf_band, freq, val); | 350 | return -EINVAL; |
324 | dbg_map("0x%02x\n", *val); | 351 | } |
325 | } | ||
326 | 352 | ||
327 | void tda18271_lookup_gain_taper(u32 *freq, u8 *val) | 353 | while ((map[i].rfmax * 1000) < *freq) { |
328 | { | 354 | if (map[i + 1].rfmax == 0) |
329 | tda18271_lookup_map(tda18271_gain_taper, freq, val); | 355 | break; |
330 | dbg_map("0x%02x\n", *val); | 356 | i++; |
331 | } | 357 | } |
358 | *val = map[i].val; | ||
332 | 359 | ||
333 | void tda18271_lookup_rf_cal(u32 *freq, u8 *val) | 360 | dbg_map("%s: 0x%02x\n", map_name, *val); |
334 | { | ||
335 | tda18271_lookup_map(tda18271_rf_cal, freq, val); | ||
336 | dbg_map("0x%02x\n", *val); | ||
337 | } | ||
338 | 361 | ||
339 | void tda18271_lookup_ir_measure(u32 *freq, u8 *val) | 362 | return 0; |
340 | { | ||
341 | tda18271_lookup_map(tda18271_ir_measure, freq, val); | ||
342 | dbg_map("0x%02x\n", *val); | ||
343 | } | 363 | } |
344 | 364 | ||
345 | /* | 365 | /* |