aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoristvan_v@mailbox.hu <istvan_v@mailbox.hu>2011-06-06 11:54:54 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-07-27 16:52:40 -0400
commit341747bef5dd2e2f56647ba30ea2180752905fa0 (patch)
treefee2cebfc9fc42496d5621e8608ef4a5a87cbd23
parent7db98fe66be035494912b6b2c4e9c1e3abfedfe5 (diff)
[media] xc4000: code cleanup
Various coding style changes: - removed unused / commented out code - changed C++ style comments to C format - renamed functions and variables that included upper case letters in the name - removed tabs from module parameter descriptions - replaced the use of XC_RESULT_* with standard error codes Signed-off-by: Istvan Varga <istvan_v@mailbox.hu> Cc: Patrick Boettcher <pboettcher@kernellabs.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/common/tuners/xc4000.c272
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c15
2 files changed, 126 insertions, 161 deletions
diff --git a/drivers/media/common/tuners/xc4000.c b/drivers/media/common/tuners/xc4000.c
index 160ca26286cc..ebc84269b5e6 100644
--- a/drivers/media/common/tuners/xc4000.c
+++ b/drivers/media/common/tuners/xc4000.c
@@ -5,6 +5,7 @@
5 * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org> 5 * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
6 * Copyright (c) 2009 Devin Heitmueller <dheitmueller@kernellabs.com> 6 * Copyright (c) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
7 * Copyright (c) 2009 Davide Ferri <d.ferri@zero11.it> 7 * Copyright (c) 2009 Davide Ferri <d.ferri@zero11.it>
8 * Copyright (c) 2010 Istvan Varga <istvan_v@mailbox.hu>
8 * 9 *
9 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
@@ -14,7 +15,6 @@
14 * This program is distributed in the hope that it will be useful, 15 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 *
18 * GNU General Public License for more details. 18 * GNU General Public License for more details.
19 * 19 *
20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
@@ -39,44 +39,29 @@
39 39
40static int debug; 40static int debug;
41module_param(debug, int, 0644); 41module_param(debug, int, 0644);
42MODULE_PARM_DESC(debug, "\n\t\tDebugging level (0 to 2, default: 0 (off))."); 42MODULE_PARM_DESC(debug, "Debugging level (0 to 2, default: 0 (off)).");
43 43
44static int no_poweroff; 44static int no_poweroff;
45module_param(no_poweroff, int, 0644); 45module_param(no_poweroff, int, 0644);
46MODULE_PARM_DESC(no_poweroff, "\n\t\t1: keep device energized and with tuner " 46MODULE_PARM_DESC(no_poweroff, "Power management (1: disabled, 2: enabled, "
47 "ready all the times.\n" 47 "0 (default): use device-specific default mode).");
48 "\t\tFaster, but consumes more power and keeps the device hotter.\n"
49 "\t\t2: powers device off when not used.\n"
50 "\t\t0 (default): use device-specific default mode.");
51
52#define XC4000_AUDIO_STD_B 1
53#define XC4000_AUDIO_STD_A2 2
54#define XC4000_AUDIO_STD_K3 4
55#define XC4000_AUDIO_STD_L 8
56#define XC4000_AUDIO_STD_INPUT1 16
57#define XC4000_AUDIO_STD_MONO 32
58 48
59static int audio_std; 49static int audio_std;
60module_param(audio_std, int, 0644); 50module_param(audio_std, int, 0644);
61MODULE_PARM_DESC(audio_std, "\n\t\tAudio standard. XC4000 audio decoder " 51MODULE_PARM_DESC(audio_std, "Audio standard. XC4000 audio decoder explicitly "
62 "explicitly needs to know\n" 52 "needs to know what audio standard is needed for some video standards "
63 "\t\twhat audio standard is needed for some video standards with\n" 53 "with audio A2 or NICAM. The valid settings are a sum of:\n"
64 "\t\taudio A2 or NICAM.\n" 54 " 1: use NICAM/B or A2/B instead of NICAM/A or A2/A\n"
65 "\t\tThe valid settings are a sum of:\n" 55 " 2: use A2 instead of NICAM or BTSC\n"
66 "\t\t 1: use NICAM/B or A2/B instead of NICAM/A or A2/A\n" 56 " 4: use SECAM/K3 instead of K1\n"
67 "\t\t 2: use A2 instead of NICAM or BTSC\n" 57 " 8: use PAL-D/K audio for SECAM-D/K\n"
68 "\t\t 4: use SECAM/K3 instead of K1\n" 58 "16: use FM radio input 1 instead of input 2\n"
69 "\t\t 8: use PAL-D/K audio for SECAM-D/K\n" 59 "32: use mono audio (the lower three bits are ignored)");
70 "\t\t16: use FM radio input 1 instead of input 2\n"
71 "\t\t32: use mono audio (the lower three bits are ignored)");
72
73#define XC4000_DEFAULT_FIRMWARE "xc4000.fw"
74 60
75static char firmware_name[30]; 61static char firmware_name[30];
76module_param_string(firmware_name, firmware_name, sizeof(firmware_name), 0); 62module_param_string(firmware_name, firmware_name, sizeof(firmware_name), 0);
77MODULE_PARM_DESC(firmware_name, "\n\t\tFirmware file name. Allows overriding " 63MODULE_PARM_DESC(firmware_name, "Firmware file name. Allows overriding the "
78 "the default firmware\n" 64 "default firmware name.");
79 "\t\tname.");
80 65
81static DEFINE_MUTEX(xc4000_list_mutex); 66static DEFINE_MUTEX(xc4000_list_mutex);
82static LIST_HEAD(hybrid_tuner_instance_list); 67static LIST_HEAD(hybrid_tuner_instance_list);
@@ -115,13 +100,21 @@ struct xc4000_priv {
115 u8 rf_mode; 100 u8 rf_mode;
116 u8 card_type; 101 u8 card_type;
117 u8 ignore_i2c_write_errors; 102 u8 ignore_i2c_write_errors;
118 /* struct xc2028_ctrl ctrl; */
119 struct firmware_properties cur_fw; 103 struct firmware_properties cur_fw;
120 __u16 hwmodel; 104 __u16 hwmodel;
121 __u16 hwvers; 105 __u16 hwvers;
122 struct mutex lock; 106 struct mutex lock;
123}; 107};
124 108
109#define XC4000_AUDIO_STD_B 1
110#define XC4000_AUDIO_STD_A2 2
111#define XC4000_AUDIO_STD_K3 4
112#define XC4000_AUDIO_STD_L 8
113#define XC4000_AUDIO_STD_INPUT1 16
114#define XC4000_AUDIO_STD_MONO 32
115
116#define XC4000_DEFAULT_FIRMWARE "dvb-fe-xc4000-1.4.fw"
117
125/* Misc Defines */ 118/* Misc Defines */
126#define MAX_TV_STANDARD 24 119#define MAX_TV_STANDARD 24
127#define XC_MAX_I2C_WRITE_LENGTH 64 120#define XC_MAX_I2C_WRITE_LENGTH 64
@@ -131,13 +124,6 @@ struct xc4000_priv {
131#define XC_RF_MODE_AIR 0 124#define XC_RF_MODE_AIR 0
132#define XC_RF_MODE_CABLE 1 125#define XC_RF_MODE_CABLE 1
133 126
134/* Result codes */
135#define XC_RESULT_SUCCESS 0
136#define XC_RESULT_RESET_FAILURE 1
137#define XC_RESULT_I2C_WRITE_FAILURE 2
138#define XC_RESULT_I2C_READ_FAILURE 3
139#define XC_RESULT_OUT_OF_RANGE 5
140
141/* Product id */ 127/* Product id */
142#define XC_PRODUCT_ID_FW_NOT_LOADED 0x2000 128#define XC_PRODUCT_ID_FW_NOT_LOADED 0x2000
143#define XC_PRODUCT_ID_XC4000 0x0FA0 129#define XC_PRODUCT_ID_XC4000 0x0FA0
@@ -202,8 +188,8 @@ struct xc4000_priv {
202 188
203struct XC_TV_STANDARD { 189struct XC_TV_STANDARD {
204 const char *Name; 190 const char *Name;
205 u16 AudioMode; 191 u16 audio_mode;
206 u16 VideoMode; 192 u16 video_mode;
207 u16 int_freq; 193 u16 int_freq;
208}; 194};
209 195
@@ -233,7 +219,7 @@ struct XC_TV_STANDARD {
233#define XC4000_FM_Radio_INPUT2 22 219#define XC4000_FM_Radio_INPUT2 22
234#define XC4000_FM_Radio_INPUT1 23 220#define XC4000_FM_Radio_INPUT1 23
235 221
236static struct XC_TV_STANDARD XC4000_Standard[MAX_TV_STANDARD] = { 222static struct XC_TV_STANDARD xc4000_standard[MAX_TV_STANDARD] = {
237 {"M/N-NTSC/PAL-BTSC", 0x0000, 0x80A0, 4500}, 223 {"M/N-NTSC/PAL-BTSC", 0x0000, 0x80A0, 4500},
238 {"M/N-NTSC/PAL-A2", 0x0000, 0x80A0, 4600}, 224 {"M/N-NTSC/PAL-A2", 0x0000, 0x80A0, 4600},
239 {"M/N-NTSC/PAL-EIAJ", 0x0040, 0x80A0, 4500}, 225 {"M/N-NTSC/PAL-EIAJ", 0x0040, 0x80A0, 4500},
@@ -261,7 +247,7 @@ static struct XC_TV_STANDARD XC4000_Standard[MAX_TV_STANDARD] = {
261}; 247};
262 248
263static int xc4000_readreg(struct xc4000_priv *priv, u16 reg, u16 *val); 249static int xc4000_readreg(struct xc4000_priv *priv, u16 reg, u16 *val);
264static int xc4000_TunerReset(struct dvb_frontend *fe); 250static int xc4000_tuner_reset(struct dvb_frontend *fe);
265static void xc_debug_dump(struct xc4000_priv *priv); 251static void xc_debug_dump(struct xc4000_priv *priv);
266 252
267static int xc_send_i2c_data(struct xc4000_priv *priv, u8 *buf, int len) 253static int xc_send_i2c_data(struct xc4000_priv *priv, u8 *buf, int len)
@@ -276,18 +262,13 @@ static int xc_send_i2c_data(struct xc4000_priv *priv, u8 *buf, int len)
276 printk("bytes %02x %02x %02x %02x\n", buf[0], 262 printk("bytes %02x %02x %02x %02x\n", buf[0],
277 buf[1], buf[2], buf[3]); 263 buf[1], buf[2], buf[3]);
278 } 264 }
279 return XC_RESULT_I2C_WRITE_FAILURE; 265 return -EREMOTEIO;
280 } 266 }
281 } 267 }
282 return XC_RESULT_SUCCESS; 268 return 0;
283}
284
285static void xc_wait(int wait_ms)
286{
287 msleep(wait_ms);
288} 269}
289 270
290static int xc4000_TunerReset(struct dvb_frontend *fe) 271static int xc4000_tuner_reset(struct dvb_frontend *fe)
291{ 272{
292 struct xc4000_priv *priv = fe->tuner_priv; 273 struct xc4000_priv *priv = fe->tuner_priv;
293 int ret; 274 int ret;
@@ -302,13 +283,14 @@ static int xc4000_TunerReset(struct dvb_frontend *fe)
302 XC4000_TUNER_RESET, 0); 283 XC4000_TUNER_RESET, 0);
303 if (ret) { 284 if (ret) {
304 printk(KERN_ERR "xc4000: reset failed\n"); 285 printk(KERN_ERR "xc4000: reset failed\n");
305 return XC_RESULT_RESET_FAILURE; 286 return -EREMOTEIO;
306 } 287 }
307 } else { 288 } else {
308 printk(KERN_ERR "xc4000: no tuner reset callback function, fatal\n"); 289 printk(KERN_ERR "xc4000: no tuner reset callback function, "
309 return XC_RESULT_RESET_FAILURE; 290 "fatal\n");
291 return -EINVAL;
310 } 292 }
311 return XC_RESULT_SUCCESS; 293 return 0;
312} 294}
313 295
314static int xc_write_reg(struct xc4000_priv *priv, u16 regAddr, u16 i2cData) 296static int xc_write_reg(struct xc4000_priv *priv, u16 regAddr, u16 i2cData)
@@ -339,15 +321,12 @@ static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
339 len = i2c_sequence[index] * 256 + i2c_sequence[index+1]; 321 len = i2c_sequence[index] * 256 + i2c_sequence[index+1];
340 if (len == 0x0000) { 322 if (len == 0x0000) {
341 /* RESET command */ 323 /* RESET command */
324 /* NOTE: this is ignored, as the reset callback was */
325 /* already called by check_firmware() */
342 index += 2; 326 index += 2;
343#if 0 /* not needed, as already called by check_firmware() */
344 result = xc4000_TunerReset(fe);
345 if (result != XC_RESULT_SUCCESS)
346 return result;
347#endif
348 } else if (len & 0x8000) { 327 } else if (len & 0x8000) {
349 /* WAIT command */ 328 /* WAIT command */
350 xc_wait(len & 0x7FFF); 329 msleep(len & 0x7FFF);
351 index += 2; 330 index += 2;
352 } else { 331 } else {
353 /* Send i2c data whilst ensuring individual transactions 332 /* Send i2c data whilst ensuring individual transactions
@@ -370,7 +349,7 @@ static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
370 result = xc_send_i2c_data(priv, buf, 349 result = xc_send_i2c_data(priv, buf,
371 nbytes_to_send); 350 nbytes_to_send);
372 351
373 if (result != XC_RESULT_SUCCESS) 352 if (result != 0)
374 return result; 353 return result;
375 354
376 pos += nbytes_to_send - 2; 355 pos += nbytes_to_send - 2;
@@ -378,31 +357,31 @@ static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
378 index += len; 357 index += len;
379 } 358 }
380 } 359 }
381 return XC_RESULT_SUCCESS; 360 return 0;
382} 361}
383 362
384static int xc_SetTVStandard(struct xc4000_priv *priv, 363static int xc_set_tv_standard(struct xc4000_priv *priv,
385 u16 VideoMode, u16 AudioMode) 364 u16 video_mode, u16 audio_mode)
386{ 365{
387 int ret; 366 int ret;
388 dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, VideoMode, AudioMode); 367 dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, video_mode, audio_mode);
389 dprintk(1, "%s() Standard = %s\n", 368 dprintk(1, "%s() Standard = %s\n",
390 __func__, 369 __func__,
391 XC4000_Standard[priv->video_standard].Name); 370 xc4000_standard[priv->video_standard].Name);
392 371
393 /* Don't complain when the request fails because of i2c stretching */ 372 /* Don't complain when the request fails because of i2c stretching */
394 priv->ignore_i2c_write_errors = 1; 373 priv->ignore_i2c_write_errors = 1;
395 374
396 ret = xc_write_reg(priv, XREG_VIDEO_MODE, VideoMode); 375 ret = xc_write_reg(priv, XREG_VIDEO_MODE, video_mode);
397 if (ret == XC_RESULT_SUCCESS) 376 if (ret == 0)
398 ret = xc_write_reg(priv, XREG_AUDIO_MODE, AudioMode); 377 ret = xc_write_reg(priv, XREG_AUDIO_MODE, audio_mode);
399 378
400 priv->ignore_i2c_write_errors = 0; 379 priv->ignore_i2c_write_errors = 0;
401 380
402 return ret; 381 return ret;
403} 382}
404 383
405static int xc_SetSignalSource(struct xc4000_priv *priv, u16 rf_mode) 384static int xc_set_signal_source(struct xc4000_priv *priv, u16 rf_mode)
406{ 385{
407 dprintk(1, "%s(%d) Source = %s\n", __func__, rf_mode, 386 dprintk(1, "%s(%d) Source = %s\n", __func__, rf_mode,
408 rf_mode == XC_RF_MODE_AIR ? "ANTENNA" : "CABLE"); 387 rf_mode == XC_RF_MODE_AIR ? "ANTENNA" : "CABLE");
@@ -418,25 +397,26 @@ static int xc_SetSignalSource(struct xc4000_priv *priv, u16 rf_mode)
418 397
419static const struct dvb_tuner_ops xc4000_tuner_ops; 398static const struct dvb_tuner_ops xc4000_tuner_ops;
420 399
421static int xc_set_RF_frequency(struct xc4000_priv *priv, u32 freq_hz) 400static int xc_set_rf_frequency(struct xc4000_priv *priv, u32 freq_hz)
422{ 401{
423 u16 freq_code; 402 u16 freq_code;
424 403
425 dprintk(1, "%s(%u)\n", __func__, freq_hz); 404 dprintk(1, "%s(%u)\n", __func__, freq_hz);
426 405
427 if ((freq_hz > xc4000_tuner_ops.info.frequency_max) || 406 if ((freq_hz > xc4000_tuner_ops.info.frequency_max) ||
428 (freq_hz < xc4000_tuner_ops.info.frequency_min)) 407 (freq_hz < xc4000_tuner_ops.info.frequency_min))
429 return XC_RESULT_OUT_OF_RANGE; 408 return -EINVAL;
430 409
431 freq_code = (u16)(freq_hz / 15625); 410 freq_code = (u16)(freq_hz / 15625);
432 411
433 /* WAS: Starting in firmware version 1.1.44, Xceive recommends using the 412 /* WAS: Starting in firmware version 1.1.44, Xceive recommends using the
434 FINERFREQ for all normal tuning (the doc indicates reg 0x03 should 413 FINERFREQ for all normal tuning (the doc indicates reg 0x03 should
435 only be used for fast scanning for channel lock) */ 414 only be used for fast scanning for channel lock) */
436 return xc_write_reg(priv, XREG_RF_FREQ, freq_code); /* WAS: XREG_FINERFREQ */ 415 /* WAS: XREG_FINERFREQ */
416 return xc_write_reg(priv, XREG_RF_FREQ, freq_code);
437} 417}
438 418
439static int xc_get_ADC_Envelope(struct xc4000_priv *priv, u16 *adc_envelope) 419static int xc_get_adc_envelope(struct xc4000_priv *priv, u16 *adc_envelope)
440{ 420{
441 return xc4000_readreg(priv, XREG_ADC_ENV, adc_envelope); 421 return xc4000_readreg(priv, XREG_ADC_ENV, adc_envelope);
442} 422}
@@ -448,7 +428,7 @@ static int xc_get_frequency_error(struct xc4000_priv *priv, u32 *freq_error_hz)
448 u32 tmp; 428 u32 tmp;
449 429
450 result = xc4000_readreg(priv, XREG_FREQ_ERROR, &regData); 430 result = xc4000_readreg(priv, XREG_FREQ_ERROR, &regData);
451 if (result != XC_RESULT_SUCCESS) 431 if (result != 0)
452 return result; 432 return result;
453 433
454 tmp = (u32)regData & 0xFFFFU; 434 tmp = (u32)regData & 0xFFFFU;
@@ -470,7 +450,7 @@ static int xc_get_version(struct xc4000_priv *priv,
470 int result; 450 int result;
471 451
472 result = xc4000_readreg(priv, XREG_VERSION, &data); 452 result = xc4000_readreg(priv, XREG_VERSION, &data);
473 if (result != XC_RESULT_SUCCESS) 453 if (result != 0)
474 return result; 454 return result;
475 455
476 (*hw_majorversion) = (data >> 12) & 0x0F; 456 (*hw_majorversion) = (data >> 12) & 0x0F;
@@ -487,7 +467,7 @@ static int xc_get_hsync_freq(struct xc4000_priv *priv, u32 *hsync_freq_hz)
487 int result; 467 int result;
488 468
489 result = xc4000_readreg(priv, XREG_HSYNC_FREQ, &regData); 469 result = xc4000_readreg(priv, XREG_HSYNC_FREQ, &regData);
490 if (result != XC_RESULT_SUCCESS) 470 if (result != 0)
491 return result; 471 return result;
492 472
493 (*hsync_freq_hz) = ((regData & 0x0fff) * 763)/100; 473 (*hsync_freq_hz) = ((regData & 0x0fff) * 763)/100;
@@ -504,19 +484,19 @@ static int xc_get_quality(struct xc4000_priv *priv, u16 *quality)
504 return xc4000_readreg(priv, XREG_QUALITY, quality); 484 return xc4000_readreg(priv, XREG_QUALITY, quality);
505} 485}
506 486
507static u16 WaitForLock(struct xc4000_priv *priv) 487static u16 xc_wait_for_lock(struct xc4000_priv *priv)
508{ 488{
509 u16 lockState = 0; 489 u16 lock_state = 0;
510 int watchDogCount = 40; 490 int watchdog_count = 40;
511 491
512 while ((lockState == 0) && (watchDogCount > 0)) { 492 while ((lock_state == 0) && (watchdog_count > 0)) {
513 xc_get_lock_status(priv, &lockState); 493 xc_get_lock_status(priv, &lock_state);
514 if (lockState != 1) { 494 if (lock_state != 1) {
515 xc_wait(5); 495 msleep(5);
516 watchDogCount--; 496 watchdog_count--;
517 } 497 }
518 } 498 }
519 return lockState; 499 return lock_state;
520} 500}
521 501
522static int xc_tune_channel(struct xc4000_priv *priv, u32 freq_hz) 502static int xc_tune_channel(struct xc4000_priv *priv, u32 freq_hz)
@@ -528,15 +508,15 @@ static int xc_tune_channel(struct xc4000_priv *priv, u32 freq_hz)
528 508
529 /* Don't complain when the request fails because of i2c stretching */ 509 /* Don't complain when the request fails because of i2c stretching */
530 priv->ignore_i2c_write_errors = 1; 510 priv->ignore_i2c_write_errors = 1;
531 result = xc_set_RF_frequency(priv, freq_hz); 511 result = xc_set_rf_frequency(priv, freq_hz);
532 priv->ignore_i2c_write_errors = 0; 512 priv->ignore_i2c_write_errors = 0;
533 513
534 if (result != XC_RESULT_SUCCESS) 514 if (result != 0)
535 return 0; 515 return 0;
536 516
537 /* wait for lock only in analog TV mode */ 517 /* wait for lock only in analog TV mode */
538 if ((priv->cur_fw.type & (FM | DTV6 | DTV7 | DTV78 | DTV8)) == 0) { 518 if ((priv->cur_fw.type & (FM | DTV6 | DTV7 | DTV78 | DTV8)) == 0) {
539 if (WaitForLock(priv) != 1) 519 if (xc_wait_for_lock(priv) != 1)
540 found = 0; 520 found = 0;
541 } 521 }
542 522
@@ -544,7 +524,7 @@ static int xc_tune_channel(struct xc4000_priv *priv, u32 freq_hz)
544 * Frame Lines needs two frame times after initial lock 524 * Frame Lines needs two frame times after initial lock
545 * before it is valid. 525 * before it is valid.
546 */ 526 */
547 xc_wait(debug ? 100 : 10); 527 msleep(debug ? 100 : 10);
548 528
549 if (debug) 529 if (debug)
550 xc_debug_dump(priv); 530 xc_debug_dump(priv);
@@ -569,7 +549,7 @@ static int xc4000_readreg(struct xc4000_priv *priv, u16 reg, u16 *val)
569 } 549 }
570 550
571 *val = (bval[0] << 8) | bval[1]; 551 *val = (bval[0] << 8) | bval[1];
572 return XC_RESULT_SUCCESS; 552 return 0;
573} 553}
574 554
575#define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0) 555#define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0)
@@ -647,7 +627,7 @@ static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
647 unsigned int best_nr_diffs = 255U; 627 unsigned int best_nr_diffs = 255U;
648 628
649 if (!priv->firm) { 629 if (!priv->firm) {
650 printk("Error! firmware not loaded\n"); 630 printk(KERN_ERR "Error! firmware not loaded\n");
651 return -EINVAL; 631 return -EINVAL;
652 } 632 }
653 633
@@ -685,8 +665,8 @@ static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
685 665
686 if (best_nr_diffs > 0U) { 666 if (best_nr_diffs > 0U) {
687 printk("Selecting best matching firmware (%u bits differ) for " 667 printk("Selecting best matching firmware (%u bits differ) for "
688 "type=", best_nr_diffs); 668 "type=(%x), id %016llx:\n",
689 printk("(%x), id %016llx:\n", type, (unsigned long long)*id); 669 best_nr_diffs, type, (unsigned long long)*id);
690 i = best_i; 670 i = best_i;
691 } 671 }
692 672
@@ -695,8 +675,8 @@ found:
695 675
696ret: 676ret:
697 if (debug) { 677 if (debug) {
698 printk("%s firmware for type=", (i < 0) ? "Can't find" : 678 printk("%s firmware for type=",
699 "Found"); 679 (i < 0) ? "Can't find" : "Found");
700 dump_firm_type(type); 680 dump_firm_type(type);
701 printk("(%x), id %016llx.\n", type, (unsigned long long)*id); 681 printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
702 } 682 }
@@ -745,11 +725,10 @@ static int xc4000_fwupload(struct dvb_frontend *fe)
745 rc = request_firmware(&fw, fname, priv->i2c_props.adap->dev.parent); 725 rc = request_firmware(&fw, fname, priv->i2c_props.adap->dev.parent);
746 if (rc < 0) { 726 if (rc < 0) {
747 if (rc == -ENOENT) 727 if (rc == -ENOENT)
748 printk("Error: firmware %s not found.\n", 728 printk("Error: firmware %s not found.\n", fname);
749 fname);
750 else 729 else
751 printk("Error %d while requesting firmware %s \n", 730 printk("Error %d while requesting firmware %s \n",
752 rc, fname); 731 rc, fname);
753 732
754 return rc; 733 return rc;
755 } 734 }
@@ -757,13 +736,12 @@ static int xc4000_fwupload(struct dvb_frontend *fe)
757 endp = p + fw->size; 736 endp = p + fw->size;
758 737
759 if (fw->size < sizeof(name) - 1 + 2 + 2) { 738 if (fw->size < sizeof(name) - 1 + 2 + 2) {
760 printk("Error: firmware file %s has invalid size!\n", 739 printk("Error: firmware file %s has invalid size!\n", fname);
761 fname);
762 goto corrupt; 740 goto corrupt;
763 } 741 }
764 742
765 memcpy(name, p, sizeof(name) - 1); 743 memcpy(name, p, sizeof(name) - 1);
766 name[sizeof(name) - 1] = 0; 744 name[sizeof(name) - 1] = '\0';
767 p += sizeof(name) - 1; 745 p += sizeof(name) - 1;
768 746
769 priv->firm_version = get_unaligned_le16(p); 747 priv->firm_version = get_unaligned_le16(p);
@@ -920,7 +898,7 @@ static int load_scode(struct dvb_frontend *fe, unsigned int type,
920 } 898 }
921 899
922 rc = xc_send_i2c_data(priv, scode_buf, 13); 900 rc = xc_send_i2c_data(priv, scode_buf, 13);
923 if (rc != XC_RESULT_SUCCESS) { 901 if (rc != 0) {
924 /* Even if the send failed, make sure we set back to indirect 902 /* Even if the send failed, make sure we set back to indirect
925 mode */ 903 mode */
926 printk("Failed to set scode %d\n", rc); 904 printk("Failed to set scode %d\n", rc);
@@ -953,16 +931,11 @@ static int check_firmware(struct dvb_frontend *fe, unsigned int type,
953 return rc; 931 return rc;
954 } 932 }
955 933
956#ifdef DJH_DEBUG
957 if (priv->ctrl.mts && !(type & FM))
958 type |= MTS;
959#endif
960
961retry: 934retry:
962 new_fw.type = type; 935 new_fw.type = type;
963 new_fw.id = std; 936 new_fw.id = std;
964 new_fw.std_req = std; 937 new_fw.std_req = std;
965 new_fw.scode_table = SCODE /* | priv->ctrl.scode_table */; 938 new_fw.scode_table = SCODE;
966 new_fw.scode_nr = 0; 939 new_fw.scode_nr = 0;
967 new_fw.int_freq = int_freq; 940 new_fw.int_freq = int_freq;
968 941
@@ -971,15 +944,11 @@ retry:
971 dump_firm_type(new_fw.type); 944 dump_firm_type(new_fw.type);
972 printk("(%x), id %016llx, ", new_fw.type, 945 printk("(%x), id %016llx, ", new_fw.type,
973 (unsigned long long)new_fw.std_req); 946 (unsigned long long)new_fw.std_req);
974 if (!int_freq) { 947 if (!int_freq)
975 printk("scode_tbl "); 948 printk(KERN_CONT "scode_tbl ");
976#ifdef DJH_DEBUG 949 else
977 dump_firm_type(priv->ctrl.scode_table); 950 printk(KERN_CONT "int_freq %d, ", new_fw.int_freq);
978 printk("(%x), ", priv->ctrl.scode_table); 951 printk(KERN_CONT "scode_nr %d\n", new_fw.scode_nr);
979#endif
980 } else
981 printk("int_freq %d, ", new_fw.int_freq);
982 printk("scode_nr %d\n", new_fw.scode_nr);
983 } 952 }
984 953
985 /* No need to reload base firmware if it matches */ 954 /* No need to reload base firmware if it matches */
@@ -992,7 +961,7 @@ retry:
992 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw)); 961 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
993 962
994 /* Reset is needed before loading firmware */ 963 /* Reset is needed before loading firmware */
995 rc = xc4000_TunerReset(fe); 964 rc = xc4000_tuner_reset(fe);
996 if (rc < 0) 965 if (rc < 0)
997 goto fail; 966 goto fail;
998 967
@@ -1046,14 +1015,14 @@ skip_std_specific:
1046 /* Load SCODE firmware, if exists */ 1015 /* Load SCODE firmware, if exists */
1047 rc = load_scode(fe, new_fw.type | new_fw.scode_table, &new_fw.id, 1016 rc = load_scode(fe, new_fw.type | new_fw.scode_table, &new_fw.id,
1048 new_fw.int_freq, new_fw.scode_nr); 1017 new_fw.int_freq, new_fw.scode_nr);
1049 if (rc != XC_RESULT_SUCCESS) 1018 if (rc != 0)
1050 dprintk(1, "load scode failed %d\n", rc); 1019 dprintk(1, "load scode failed %d\n", rc);
1051 1020
1052check_device: 1021check_device:
1053 rc = xc4000_readreg(priv, XREG_PRODUCT_ID, &hwmodel); 1022 rc = xc4000_readreg(priv, XREG_PRODUCT_ID, &hwmodel);
1054 1023
1055 if (xc_get_version(priv, &hw_major, &hw_minor, &fw_major, 1024 if (xc_get_version(priv, &hw_major, &hw_minor, &fw_major,
1056 &fw_minor) != XC_RESULT_SUCCESS) { 1025 &fw_minor) != 0) {
1057 printk("Unable to read tuner registers.\n"); 1026 printk("Unable to read tuner registers.\n");
1058 goto fail; 1027 goto fail;
1059 } 1028 }
@@ -1121,7 +1090,7 @@ static void xc_debug_dump(struct xc4000_priv *priv)
1121 u8 hw_majorversion = 0, hw_minorversion = 0; 1090 u8 hw_majorversion = 0, hw_minorversion = 0;
1122 u8 fw_majorversion = 0, fw_minorversion = 0; 1091 u8 fw_majorversion = 0, fw_minorversion = 0;
1123 1092
1124 xc_get_ADC_Envelope(priv, &adc_envelope); 1093 xc_get_adc_envelope(priv, &adc_envelope);
1125 dprintk(1, "*** ADC envelope (0-1023) = %d\n", adc_envelope); 1094 dprintk(1, "*** ADC envelope (0-1023) = %d\n", adc_envelope);
1126 1095
1127 xc_get_frequency_error(priv, &freq_error_hz); 1096 xc_get_frequency_error(priv, &freq_error_hz);
@@ -1235,24 +1204,23 @@ static int xc4000_set_params(struct dvb_frontend *fe,
1235 __func__, priv->freq_hz); 1204 __func__, priv->freq_hz);
1236 1205
1237 /* Make sure the correct firmware type is loaded */ 1206 /* Make sure the correct firmware type is loaded */
1238 if (check_firmware(fe, type, 0, priv->if_khz) != XC_RESULT_SUCCESS) 1207 if (check_firmware(fe, type, 0, priv->if_khz) != 0)
1239 goto fail; 1208 goto fail;
1240 1209
1241 ret = xc_SetSignalSource(priv, priv->rf_mode); 1210 ret = xc_set_signal_source(priv, priv->rf_mode);
1242 if (ret != XC_RESULT_SUCCESS) { 1211 if (ret != 0) {
1243 printk(KERN_ERR 1212 printk(KERN_ERR "xc4000: xc_set_signal_source(%d) failed\n",
1244 "xc4000: xc_SetSignalSource(%d) failed\n",
1245 priv->rf_mode); 1213 priv->rf_mode);
1246 goto fail; 1214 goto fail;
1247 } else { 1215 } else {
1248 u16 video_mode, audio_mode; 1216 u16 video_mode, audio_mode;
1249 video_mode = XC4000_Standard[priv->video_standard].VideoMode; 1217 video_mode = xc4000_standard[priv->video_standard].video_mode;
1250 audio_mode = XC4000_Standard[priv->video_standard].AudioMode; 1218 audio_mode = xc4000_standard[priv->video_standard].audio_mode;
1251 if (type == DTV6 && priv->firm_version != 0x0102) 1219 if (type == DTV6 && priv->firm_version != 0x0102)
1252 video_mode |= 0x0001; 1220 video_mode |= 0x0001;
1253 ret = xc_SetTVStandard(priv, video_mode, audio_mode); 1221 ret = xc_set_tv_standard(priv, video_mode, audio_mode);
1254 if (ret != XC_RESULT_SUCCESS) { 1222 if (ret != 0) {
1255 printk(KERN_ERR "xc4000: xc_SetTVStandard failed\n"); 1223 printk(KERN_ERR "xc4000: xc_set_tv_standard failed\n");
1256 /* DJH - do not return when it fails... */ 1224 /* DJH - do not return when it fails... */
1257 /* goto fail; */ 1225 /* goto fail; */
1258 } 1226 }
@@ -1423,27 +1391,25 @@ static int xc4000_set_analog_params(struct dvb_frontend *fe,
1423 } 1391 }
1424 1392
1425tune_channel: 1393tune_channel:
1426 /* Fix me: it could be air. */ 1394 /* FIXME: it could be air. */
1427 priv->rf_mode = XC_RF_MODE_CABLE; 1395 priv->rf_mode = XC_RF_MODE_CABLE;
1428 1396
1429 if (check_firmware(fe, type, params->std, 1397 if (check_firmware(fe, type, params->std,
1430 XC4000_Standard[priv->video_standard].int_freq) 1398 xc4000_standard[priv->video_standard].int_freq) != 0)
1431 != XC_RESULT_SUCCESS) {
1432 goto fail; 1399 goto fail;
1433 }
1434 1400
1435 ret = xc_SetSignalSource(priv, priv->rf_mode); 1401 ret = xc_set_signal_source(priv, priv->rf_mode);
1436 if (ret != XC_RESULT_SUCCESS) { 1402 if (ret != 0) {
1437 printk(KERN_ERR 1403 printk(KERN_ERR
1438 "xc4000: xc_SetSignalSource(%d) failed\n", 1404 "xc4000: xc_set_signal_source(%d) failed\n",
1439 priv->rf_mode); 1405 priv->rf_mode);
1440 goto fail; 1406 goto fail;
1441 } else { 1407 } else {
1442 u16 video_mode, audio_mode; 1408 u16 video_mode, audio_mode;
1443 video_mode = XC4000_Standard[priv->video_standard].VideoMode; 1409 video_mode = xc4000_standard[priv->video_standard].video_mode;
1444 audio_mode = XC4000_Standard[priv->video_standard].AudioMode; 1410 audio_mode = xc4000_standard[priv->video_standard].audio_mode;
1445 if (priv->video_standard < XC4000_BG_PAL_A2) { 1411 if (priv->video_standard < XC4000_BG_PAL_A2) {
1446 if (0 /*type & NOGD*/) 1412 if (type & NOGD)
1447 video_mode &= 0xFF7F; 1413 video_mode &= 0xFF7F;
1448 } else if (priv->video_standard < XC4000_I_PAL_NICAM) { 1414 } else if (priv->video_standard < XC4000_I_PAL_NICAM) {
1449 if (priv->card_type == XC4000_CARD_WINFAST_CX88 && 1415 if (priv->card_type == XC4000_CARD_WINFAST_CX88 &&
@@ -1452,9 +1418,9 @@ tune_channel:
1452 if (audio_std & XC4000_AUDIO_STD_B) 1418 if (audio_std & XC4000_AUDIO_STD_B)
1453 video_mode |= 0x0080; 1419 video_mode |= 0x0080;
1454 } 1420 }
1455 ret = xc_SetTVStandard(priv, video_mode, audio_mode); 1421 ret = xc_set_tv_standard(priv, video_mode, audio_mode);
1456 if (ret != XC_RESULT_SUCCESS) { 1422 if (ret != 0) {
1457 printk(KERN_ERR "xc4000: xc_SetTVStandard failed\n"); 1423 printk(KERN_ERR "xc4000: xc_set_tv_standard failed\n");
1458 goto fail; 1424 goto fail;
1459 } 1425 }
1460 } 1426 }
@@ -1542,7 +1508,7 @@ static int xc4000_get_status(struct dvb_frontend *fe, u32 *status)
1542static int xc4000_sleep(struct dvb_frontend *fe) 1508static int xc4000_sleep(struct dvb_frontend *fe)
1543{ 1509{
1544 struct xc4000_priv *priv = fe->tuner_priv; 1510 struct xc4000_priv *priv = fe->tuner_priv;
1545 int ret = XC_RESULT_SUCCESS; 1511 int ret = 0;
1546 1512
1547 dprintk(1, "%s()\n", __func__); 1513 dprintk(1, "%s()\n", __func__);
1548 1514
@@ -1556,14 +1522,13 @@ static int xc4000_sleep(struct dvb_frontend *fe)
1556 /* force reset and firmware reload */ 1522 /* force reset and firmware reload */
1557 priv->cur_fw.type = XC_POWERED_DOWN; 1523 priv->cur_fw.type = XC_POWERED_DOWN;
1558 1524
1559 if (xc_write_reg(priv, XREG_POWER_DOWN, 0) 1525 if (xc_write_reg(priv, XREG_POWER_DOWN, 0) != 0) {
1560 != XC_RESULT_SUCCESS) {
1561 printk(KERN_ERR 1526 printk(KERN_ERR
1562 "xc4000: %s() unable to shutdown tuner\n", 1527 "xc4000: %s() unable to shutdown tuner\n",
1563 __func__); 1528 __func__);
1564 ret = -EREMOTEIO; 1529 ret = -EREMOTEIO;
1565 } 1530 }
1566 xc_wait(20); 1531 msleep(20);
1567 } 1532 }
1568 1533
1569 mutex_unlock(&priv->lock); 1534 mutex_unlock(&priv->lock);
@@ -1672,8 +1637,7 @@ struct dvb_frontend *xc4000_attach(struct dvb_frontend *fe,
1672 */ 1637 */
1673 1638
1674 if (instance == 1) { 1639 if (instance == 1) {
1675 if (xc4000_readreg(priv, XREG_PRODUCT_ID, &id) 1640 if (xc4000_readreg(priv, XREG_PRODUCT_ID, &id) != 0)
1676 != XC_RESULT_SUCCESS)
1677 goto fail; 1641 goto fail;
1678 } else { 1642 } else {
1679 id = ((priv->cur_fw.type & BASE) != 0 ? 1643 id = ((priv->cur_fw.type & BASE) != 0 ?
@@ -1713,7 +1677,7 @@ struct dvb_frontend *xc4000_attach(struct dvb_frontend *fe,
1713 mutex_lock(&priv->lock); 1677 mutex_lock(&priv->lock);
1714 ret = xc4000_fwupload(fe); 1678 ret = xc4000_fwupload(fe);
1715 mutex_unlock(&priv->lock); 1679 mutex_unlock(&priv->lock);
1716 if (ret != XC_RESULT_SUCCESS) 1680 if (ret != 0)
1717 goto fail2; 1681 goto fail2;
1718 } 1682 }
1719 1683
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index a5212a5c2b48..d546270d3f5d 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -2706,13 +2706,14 @@ static struct dibx000_agc_config stk7700p_7000p_xc4000_agc_config = {
2706}; 2706};
2707 2707
2708static struct dibx000_bandwidth_config stk7700p_xc4000_pll_config = { 2708static struct dibx000_bandwidth_config stk7700p_xc4000_pll_config = {
2709 60000, 30000, // internal, sampling 2709 60000, 30000, /* internal, sampling */
2710 1, 8, 3, 1, 0, // pll_cfg: prediv, ratio, range, reset, bypass 2710 1, 8, 3, 1, 0, /* pll_cfg: prediv, ratio, range, reset, bypass */
2711 0, 0, 1, 1, 0, // misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc, modulo 2711 0, 0, 1, 1, 0, /* misc: refdiv, bypclk_div, IO_CLK_en_core, */
2712 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k 2712 /* ADClkSrc, modulo */
2713 39370534, // ifreq 2713 (3 << 14) | (1 << 12) | 524, /* sad_cfg: refsel, sel, freq_15k */
2714 20452225, // timf 2714 39370534, /* ifreq */
2715 30000000, // xtal 2715 20452225, /* timf */
2716 30000000 /* xtal */
2716}; 2717};
2717 2718
2718/* FIXME: none of these inputs are validated yet */ 2719/* FIXME: none of these inputs are validated yet */