]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/media/common/tuners/xc4000.c
[media] xc4000: remove xc5000 firmware loading routine
[mirror_ubuntu-artful-kernel.git] / drivers / media / common / tuners / xc4000.c
CommitLineData
8d009a0c
DF
1/*
2 * Driver for Xceive XC4000 "QAM/8VSB single chip tuner"
3 *
4 * Copyright (c) 2007 Xceive Corporation
5 * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
6 * Copyright (c) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
7 * Copyright (c) 2009 Davide Ferri <d.ferri@zero11.it>
8 *
9 * 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 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 *
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/videodev2.h>
28#include <linux/delay.h>
29#include <linux/dvb/frontend.h>
30#include <linux/i2c.h>
11091a31 31#include <asm/unaligned.h>
8d009a0c
DF
32
33#include "dvb_frontend.h"
34
35#include "xc4000.h"
36#include "tuner-i2c.h"
11091a31 37#include "tuner-xc2028-types.h"
8d009a0c
DF
38
39static int debug;
40module_param(debug, int, 0644);
41MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
42
43static int no_poweroff;
44module_param(no_poweroff, int, 0644);
45MODULE_PARM_DESC(no_poweroff, "0 (default) powers device off when not used.\n"
46 "\t\t1 keep device energized and with tuner ready all the times.\n"
47 "\t\tFaster, but consumes more power and keeps the device hotter");
48
49static DEFINE_MUTEX(xc4000_list_mutex);
50static LIST_HEAD(hybrid_tuner_instance_list);
51
52#define dprintk(level, fmt, arg...) if (debug >= level) \
53 printk(KERN_INFO "%s: " fmt, "xc4000", ## arg)
54
11091a31
DH
55#define XC4000_DEFAULT_FIRMWARE "xc4000-01.fw"
56#define XC4000_DEFAULT_FIRMWARE_SIZE 8434
57
58
59/* struct for storing firmware table */
60struct firmware_description {
61 unsigned int type;
62 v4l2_std_id id;
63 __u16 int_freq;
64 unsigned char *ptr;
65 unsigned int size;
66};
67
68struct firmware_properties {
69 unsigned int type;
70 v4l2_std_id id;
71 v4l2_std_id std_req;
72 __u16 int_freq;
73 unsigned int scode_table;
74 int scode_nr;
75};
8d009a0c
DF
76
77struct xc4000_priv {
78 struct tuner_i2c_props i2c_props;
79 struct list_head hybrid_tuner_instance_list;
11091a31
DH
80 struct firmware_description *firm;
81 int firm_size;
82 __u16 firm_version;
8d009a0c
DF
83 u32 if_khz;
84 u32 freq_hz;
85 u32 bandwidth;
86 u8 video_standard;
87 u8 rf_mode;
88};
89
90/* Misc Defines */
91#define MAX_TV_STANDARD 23
92#define XC_MAX_I2C_WRITE_LENGTH 64
93
94/* Signal Types */
95#define XC_RF_MODE_AIR 0
96#define XC_RF_MODE_CABLE 1
97
98/* Result codes */
99#define XC_RESULT_SUCCESS 0
100#define XC_RESULT_RESET_FAILURE 1
101#define XC_RESULT_I2C_WRITE_FAILURE 2
102#define XC_RESULT_I2C_READ_FAILURE 3
103#define XC_RESULT_OUT_OF_RANGE 5
104
105/* Product id */
106#define XC_PRODUCT_ID_FW_NOT_LOADED 0x2000
107#define XC_PRODUCT_ID_FW_LOADED 0x0FA0 /* WAS: 0x1388*/
108
109/* Registers */
110#define XREG_INIT 0x00
111#define XREG_VIDEO_MODE 0x01
112#define XREG_AUDIO_MODE 0x02
113#define XREG_RF_FREQ 0x03
114#define XREG_D_CODE 0x04
115#define XREG_IF_OUT 0x05 /* ?? */
116#define XREG_SEEK_MODE 0x07 /* WAS: 0x06 */
117#define XREG_POWER_DOWN 0x08 /* WAS: 0x0A Obsolete */
118#define XREG_SIGNALSOURCE 0x0A /* WAS: 0x0D 0=Air, 1=Cable */
119//#define XREG_SMOOTHEDCVBS 0x0E
120//#define XREG_XTALFREQ 0x0F
121//#define XREG_FINERFREQ 0x10
122//#define XREG_DDIMODE 0x11
123
124#define XREG_ADC_ENV 0x00
125#define XREG_QUALITY 0x01
126#define XREG_FRAME_LINES 0x02
127#define XREG_HSYNC_FREQ 0x03
128#define XREG_LOCK 0x04
129#define XREG_FREQ_ERROR 0x05
130#define XREG_SNR 0x06
131#define XREG_VERSION 0x07
132#define XREG_PRODUCT_ID 0x08
8d009a0c
DF
133//#define XREG_BUILD 0x0D
134
135/*
136 Basic firmware description. This will remain with
137 the driver for documentation purposes.
138
139 This represents an I2C firmware file encoded as a
140 string of unsigned char. Format is as follows:
141
142 char[0 ]=len0_MSB -> len = len_MSB * 256 + len_LSB
143 char[1 ]=len0_LSB -> length of first write transaction
144 char[2 ]=data0 -> first byte to be sent
145 char[3 ]=data1
146 char[4 ]=data2
147 char[ ]=...
148 char[M ]=dataN -> last byte to be sent
149 char[M+1]=len1_MSB -> len = len_MSB * 256 + len_LSB
150 char[M+2]=len1_LSB -> length of second write transaction
151 char[M+3]=data0
152 char[M+4]=data1
153 ...
154 etc.
155
156 The [len] value should be interpreted as follows:
157
158 len= len_MSB _ len_LSB
159 len=1111_1111_1111_1111 : End of I2C_SEQUENCE
160 len=0000_0000_0000_0000 : Reset command: Do hardware reset
161 len=0NNN_NNNN_NNNN_NNNN : Normal transaction: number of bytes = {1:32767)
162 len=1WWW_WWWW_WWWW_WWWW : Wait command: wait for {1:32767} ms
163
164 For the RESET and WAIT commands, the two following bytes will contain
165 immediately the length of the following transaction.
166
167*/
168struct XC_TV_STANDARD {
169 char *Name;
170 u16 AudioMode;
171 u16 VideoMode;
172};
173
174/* Tuner standards */
175#define MN_NTSC_PAL_BTSC 0
176#define MN_NTSC_PAL_A2 1
177#define MN_NTSC_PAL_EIAJ 2
178#define MN_NTSC_PAL_Mono 3
179#define BG_PAL_A2 4
180#define BG_PAL_NICAM 5
181#define BG_PAL_MONO 6
182#define I_PAL_NICAM 7
183#define I_PAL_NICAM_MONO 8
184#define DK_PAL_A2 9
185#define DK_PAL_NICAM 10
186#define DK_PAL_MONO 11
187#define DK_SECAM_A2DK1 12
188#define DK_SECAM_A2LDK3 13
189#define DK_SECAM_A2MONO 14
190#define L_SECAM_NICAM 15
191#define LC_SECAM_NICAM 16
8d009a0c
DF
192#define FM_Radio_INPUT2 21
193#define FM_Radio_INPUT1 22
194
195/* WAS :
196static struct XC_TV_STANDARD XC4000_Standard[MAX_TV_STANDARD] = {
197 {"M/N-NTSC/PAL-BTSC", 0x0400, 0x8020},
198 {"M/N-NTSC/PAL-A2", 0x0600, 0x8020},
199 {"M/N-NTSC/PAL-EIAJ", 0x0440, 0x8020},
200 {"M/N-NTSC/PAL-Mono", 0x0478, 0x8020},
201 {"B/G-PAL-A2", 0x0A00, 0x8049},
202 {"B/G-PAL-NICAM", 0x0C04, 0x8049},
203 {"B/G-PAL-MONO", 0x0878, 0x8059},
204 {"I-PAL-NICAM", 0x1080, 0x8009},
205 {"I-PAL-NICAM-MONO", 0x0E78, 0x8009},
206 {"D/K-PAL-A2", 0x1600, 0x8009},
207 {"D/K-PAL-NICAM", 0x0E80, 0x8009},
208 {"D/K-PAL-MONO", 0x1478, 0x8009},
209 {"D/K-SECAM-A2 DK1", 0x1200, 0x8009},
210 {"D/K-SECAM-A2 L/DK3", 0x0E00, 0x8009},
211 {"D/K-SECAM-A2 MONO", 0x1478, 0x8009},
212 {"L-SECAM-NICAM", 0x8E82, 0x0009},
213 {"L'-SECAM-NICAM", 0x8E82, 0x4009},
214 {"DTV6", 0x00C0, 0x8002},
215 {"DTV8", 0x00C0, 0x800B},
216 {"DTV7/8", 0x00C0, 0x801B},
217 {"DTV7", 0x00C0, 0x8007},
218 {"FM Radio-INPUT2", 0x9802, 0x9002},
219 {"FM Radio-INPUT1", 0x0208, 0x9002}
220};*/
221
222static struct XC_TV_STANDARD XC4000_Standard[MAX_TV_STANDARD] = {
223 {"M/N-NTSC/PAL-BTSC", 0x0000, 0x8020},
224 {"M/N-NTSC/PAL-A2", 0x0000, 0x8020},
225 {"M/N-NTSC/PAL-EIAJ", 0x0040, 0x8020},
226 {"M/N-NTSC/PAL-Mono", 0x0078, 0x8020},
227 {"B/G-PAL-A2", 0x0000, 0x8059},
228 {"B/G-PAL-NICAM", 0x0004, 0x8059},
229 {"B/G-PAL-MONO", 0x0078, 0x8059},
230 {"I-PAL-NICAM", 0x0080, 0x8049},
231 {"I-PAL-NICAM-MONO", 0x0078, 0x8049},
232 {"D/K-PAL-A2", 0x0000, 0x8049},
233 {"D/K-PAL-NICAM", 0x0080, 0x8049},
234 {"D/K-PAL-MONO", 0x0078, 0x8049},
235 {"D/K-SECAM-A2 DK1", 0x0000, 0x8049},
236 {"D/K-SECAM-A2 L/DK3", 0x0000, 0x8049},
237 {"D/K-SECAM-A2 MONO", 0x0078, 0x8049},
238 {"L-SECAM-NICAM", 0x8080, 0x0009},
239 {"L'-SECAM-NICAM", 0x8080, 0x4009},
240 {"DTV6", 0x00C0, 0x8002},
241 {"DTV8", 0x00C0, 0x800B},
242 {"DTV7/8", 0x00C0, 0x801B},
243 {"DTV7", 0x00C0, 0x8007},
244 {"FM Radio-INPUT2", 0x0008, 0x9800},
245 {"FM Radio-INPUT1", 0x0008, 0x9000}
246};
247
248static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe);
249static int xc4000_is_firmware_loaded(struct dvb_frontend *fe);
250static int xc4000_readreg(struct xc4000_priv *priv, u16 reg, u16 *val);
251static int xc4000_TunerReset(struct dvb_frontend *fe);
252
253static int xc_send_i2c_data(struct xc4000_priv *priv, u8 *buf, int len)
254{
255 struct i2c_msg msg = { .addr = priv->i2c_props.addr,
256 .flags = 0, .buf = buf, .len = len };
257
258 if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
259 printk(KERN_ERR "xc4000: I2C write failed (len=%i)\n", len);
260 return XC_RESULT_I2C_WRITE_FAILURE;
261 }
262 return XC_RESULT_SUCCESS;
263}
264
265/* This routine is never used because the only time we read data from the
266 i2c bus is when we read registers, and we want that to be an atomic i2c
267 transaction in case we are on a multi-master bus */
268static int xc_read_i2c_data(struct xc4000_priv *priv, u8 *buf, int len)
269{
270 struct i2c_msg msg = { .addr = priv->i2c_props.addr,
271 .flags = I2C_M_RD, .buf = buf, .len = len };
272
273 if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
274 printk(KERN_ERR "xc4000 I2C read failed (len=%i)\n", len);
275 return -EREMOTEIO;
276 }
277 return 0;
278}
279
280static void xc_wait(int wait_ms)
281{
282 msleep(wait_ms);
283}
284
285static int xc4000_TunerReset(struct dvb_frontend *fe)
286{
287 struct xc4000_priv *priv = fe->tuner_priv;
288 int ret;
289
290 dprintk(1, "%s()\n", __func__);
291
292 if (fe->callback) {
293 ret = fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
294 fe->dvb->priv :
295 priv->i2c_props.adap->algo_data,
296 DVB_FRONTEND_COMPONENT_TUNER,
297 XC4000_TUNER_RESET, 0);
298 if (ret) {
299 printk(KERN_ERR "xc4000: reset failed\n");
300 return XC_RESULT_RESET_FAILURE;
301 }
302 } else {
303 printk(KERN_ERR "xc4000: no tuner reset callback function, fatal\n");
304 return XC_RESULT_RESET_FAILURE;
305 }
306 return XC_RESULT_SUCCESS;
307}
308
309static int xc_write_reg(struct xc4000_priv *priv, u16 regAddr, u16 i2cData)
310{
311 u8 buf[4];
8d009a0c
DF
312 int result;
313
314 buf[0] = (regAddr >> 8) & 0xFF;
315 buf[1] = regAddr & 0xFF;
316 buf[2] = (i2cData >> 8) & 0xFF;
317 buf[3] = i2cData & 0xFF;
318 result = xc_send_i2c_data(priv, buf, 4);
8d009a0c
DF
319
320 return result;
321}
322
323static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
324{
325 struct xc4000_priv *priv = fe->tuner_priv;
326
327 int i, nbytes_to_send, result;
328 unsigned int len, pos, index;
329 u8 buf[XC_MAX_I2C_WRITE_LENGTH];
330
331 index = 0;
332 while ((i2c_sequence[index] != 0xFF) ||
333 (i2c_sequence[index + 1] != 0xFF)) {
334 len = i2c_sequence[index] * 256 + i2c_sequence[index+1];
335 if (len == 0x0000) {
336 /* RESET command */
337 result = xc4000_TunerReset(fe);
338 index += 2;
339 if (result != XC_RESULT_SUCCESS)
340 return result;
341 } else if (len & 0x8000) {
342 /* WAIT command */
343 xc_wait(len & 0x7FFF);
344 index += 2;
345 } else {
346 /* Send i2c data whilst ensuring individual transactions
347 * do not exceed XC_MAX_I2C_WRITE_LENGTH bytes.
348 */
349 index += 2;
350 buf[0] = i2c_sequence[index];
351 buf[1] = i2c_sequence[index + 1];
352 pos = 2;
353 while (pos < len) {
354 if ((len - pos) > XC_MAX_I2C_WRITE_LENGTH - 2)
355 nbytes_to_send =
356 XC_MAX_I2C_WRITE_LENGTH;
357 else
358 nbytes_to_send = (len - pos + 2);
359 for (i = 2; i < nbytes_to_send; i++) {
360 buf[i] = i2c_sequence[index + pos +
361 i - 2];
362 }
363 result = xc_send_i2c_data(priv, buf,
364 nbytes_to_send);
365
366 if (result != XC_RESULT_SUCCESS)
367 return result;
368
369 pos += nbytes_to_send - 2;
370 }
371 index += len;
372 }
373 }
374 return XC_RESULT_SUCCESS;
375}
376
377static int xc_initialize(struct xc4000_priv *priv)
378{
379 dprintk(1, "%s()\n", __func__);
380 return xc_write_reg(priv, XREG_INIT, 0);
381}
382
383static int xc_SetTVStandard(struct xc4000_priv *priv,
384 u16 VideoMode, u16 AudioMode)
385{
386 int ret;
387 dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, VideoMode, AudioMode);
388 dprintk(1, "%s() Standard = %s\n",
389 __func__,
390 XC4000_Standard[priv->video_standard].Name);
391
392 ret = xc_write_reg(priv, XREG_VIDEO_MODE, VideoMode);
393 if (ret == XC_RESULT_SUCCESS)
394 ret = xc_write_reg(priv, XREG_AUDIO_MODE, AudioMode);
395
396 return ret;
397}
398
399static int xc_SetSignalSource(struct xc4000_priv *priv, u16 rf_mode)
400{
401 dprintk(1, "%s(%d) Source = %s\n", __func__, rf_mode,
402 rf_mode == XC_RF_MODE_AIR ? "ANTENNA" : "CABLE");
403
404 if ((rf_mode != XC_RF_MODE_AIR) && (rf_mode != XC_RF_MODE_CABLE)) {
405 rf_mode = XC_RF_MODE_CABLE;
406 printk(KERN_ERR
407 "%s(), Invalid mode, defaulting to CABLE",
408 __func__);
409 }
410 return xc_write_reg(priv, XREG_SIGNALSOURCE, rf_mode);
411}
412
413static const struct dvb_tuner_ops xc4000_tuner_ops;
414
415static int xc_set_RF_frequency(struct xc4000_priv *priv, u32 freq_hz)
416{
417 u16 freq_code;
418
419 dprintk(1, "%s(%u)\n", __func__, freq_hz);
420
421 if ((freq_hz > xc4000_tuner_ops.info.frequency_max) ||
422 (freq_hz < xc4000_tuner_ops.info.frequency_min))
423 return XC_RESULT_OUT_OF_RANGE;
424
425 freq_code = (u16)(freq_hz / 15625);
426
427 /* WAS: Starting in firmware version 1.1.44, Xceive recommends using the
428 FINERFREQ for all normal tuning (the doc indicates reg 0x03 should
429 only be used for fast scanning for channel lock) */
430 return xc_write_reg(priv, XREG_RF_FREQ, freq_code); /* WAS: XREG_FINERFREQ */
431}
432
433
434static int xc_set_IF_frequency(struct xc4000_priv *priv, u32 freq_khz)
435{
436 u32 freq_code = (freq_khz * 1024)/1000;
437 dprintk(1, "%s(freq_khz = %d) freq_code = 0x%x\n",
438 __func__, freq_khz, freq_code);
439
440 return xc_write_reg(priv, XREG_IF_OUT, freq_code);
441}
442
443
444static int xc_get_ADC_Envelope(struct xc4000_priv *priv, u16 *adc_envelope)
445{
446 return xc4000_readreg(priv, XREG_ADC_ENV, adc_envelope);
447}
448
449static int xc_get_frequency_error(struct xc4000_priv *priv, u32 *freq_error_hz)
450{
451 int result;
452 u16 regData;
453 u32 tmp;
454
455 result = xc4000_readreg(priv, XREG_FREQ_ERROR, &regData);
456 if (result != XC_RESULT_SUCCESS)
457 return result;
458
459 tmp = (u32)regData;
460 (*freq_error_hz) = (tmp * 15625) / 1000;
461 return result;
462}
463
464static int xc_get_lock_status(struct xc4000_priv *priv, u16 *lock_status)
465{
466 return xc4000_readreg(priv, XREG_LOCK, lock_status);
467}
468
469static int xc_get_version(struct xc4000_priv *priv,
470 u8 *hw_majorversion, u8 *hw_minorversion,
471 u8 *fw_majorversion, u8 *fw_minorversion)
472{
473 u16 data;
474 int result;
475
476 result = xc4000_readreg(priv, XREG_VERSION, &data);
477 if (result != XC_RESULT_SUCCESS)
478 return result;
479
480 (*hw_majorversion) = (data >> 12) & 0x0F;
481 (*hw_minorversion) = (data >> 8) & 0x0F;
482 (*fw_majorversion) = (data >> 4) & 0x0F;
483 (*fw_minorversion) = data & 0x0F;
484
485 return 0;
486}
487
488/* WAS THERE
489static int xc_get_buildversion(struct xc4000_priv *priv, u16 *buildrev)
490{
491 return xc4000_readreg(priv, XREG_BUILD, buildrev);
492}*/
493
494static int xc_get_hsync_freq(struct xc4000_priv *priv, u32 *hsync_freq_hz)
495{
496 u16 regData;
497 int result;
498
499 result = xc4000_readreg(priv, XREG_HSYNC_FREQ, &regData);
500 if (result != XC_RESULT_SUCCESS)
501 return result;
502
503 (*hsync_freq_hz) = ((regData & 0x0fff) * 763)/100;
504 return result;
505}
506
507static int xc_get_frame_lines(struct xc4000_priv *priv, u16 *frame_lines)
508{
509 return xc4000_readreg(priv, XREG_FRAME_LINES, frame_lines);
510}
511
512static int xc_get_quality(struct xc4000_priv *priv, u16 *quality)
513{
514 return xc4000_readreg(priv, XREG_QUALITY, quality);
515}
516
517static u16 WaitForLock(struct xc4000_priv *priv)
518{
519 u16 lockState = 0;
520 int watchDogCount = 40;
521
522 while ((lockState == 0) && (watchDogCount > 0)) {
523 xc_get_lock_status(priv, &lockState);
524 if (lockState != 1) {
525 xc_wait(5);
526 watchDogCount--;
527 }
528 }
529 return lockState;
530}
531
532#define XC_TUNE_ANALOG 0
533#define XC_TUNE_DIGITAL 1
534static int xc_tune_channel(struct xc4000_priv *priv, u32 freq_hz, int mode)
535{
536 int found = 0;
537
538 dprintk(1, "%s(%u)\n", __func__, freq_hz);
539
540 if (xc_set_RF_frequency(priv, freq_hz) != XC_RESULT_SUCCESS)
541 return 0;
542
543 if (mode == XC_TUNE_ANALOG) {
544 if (WaitForLock(priv) == 1)
545 found = 1;
546 }
547
548 return found;
549}
550
551static int xc4000_readreg(struct xc4000_priv *priv, u16 reg, u16 *val)
552{
553 u8 buf[2] = { reg >> 8, reg & 0xff };
554 u8 bval[2] = { 0, 0 };
555 struct i2c_msg msg[2] = {
556 { .addr = priv->i2c_props.addr,
557 .flags = 0, .buf = &buf[0], .len = 2 },
558 { .addr = priv->i2c_props.addr,
559 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
560 };
561
562 if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
563 printk(KERN_WARNING "xc4000: I2C read failed\n");
564 return -EREMOTEIO;
565 }
566
567 *val = (bval[0] << 8) | bval[1];
568 return XC_RESULT_SUCCESS;
569}
570
11091a31
DH
571static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
572 v4l2_std_id *id)
573{
574 struct xc4000_priv *priv = fe->tuner_priv;
575 int i, best_i = -1, best_nr_matches = 0;
576 unsigned int type_mask = 0;
577
578 printk("%s called, want type=", __func__);
579 if (debug) {
580// dump_firm_type(type);
581 printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
582 }
583
584 if (!priv->firm) {
585 printk("Error! firmware not loaded\n");
586 return -EINVAL;
587 }
588
589 if (((type & ~SCODE) == 0) && (*id == 0))
590 *id = V4L2_STD_PAL;
591
592 if (type & BASE)
593 type_mask = BASE_TYPES;
594 else if (type & SCODE) {
595 type &= SCODE_TYPES;
596 type_mask = SCODE_TYPES & ~HAS_IF;
597 } else if (type & DTV_TYPES)
598 type_mask = DTV_TYPES;
599 else if (type & STD_SPECIFIC_TYPES)
600 type_mask = STD_SPECIFIC_TYPES;
601
602 type &= type_mask;
603
604 if (!(type & SCODE))
605 type_mask = ~0;
606
607 /* Seek for exact match */
608 for (i = 0; i < priv->firm_size; i++) {
609 if ((type == (priv->firm[i].type & type_mask)) &&
610 (*id == priv->firm[i].id))
611 goto found;
612 }
613
614 /* Seek for generic video standard match */
615 for (i = 0; i < priv->firm_size; i++) {
616 v4l2_std_id match_mask;
617 int nr_matches;
618
619 if (type != (priv->firm[i].type & type_mask))
620 continue;
621
622 match_mask = *id & priv->firm[i].id;
623 if (!match_mask)
624 continue;
625
626 if ((*id & match_mask) == *id)
627 goto found; /* Supports all the requested standards */
628
629 nr_matches = hweight64(match_mask);
630 if (nr_matches > best_nr_matches) {
631 best_nr_matches = nr_matches;
632 best_i = i;
633 }
634 }
635
636 if (best_nr_matches > 0) {
637 printk("Selecting best matching firmware (%d bits) for "
638 "type=", best_nr_matches);
639// dump_firm_type(type);
640 printk("(%x), id %016llx:\n", type, (unsigned long long)*id);
641 i = best_i;
642 goto found;
643 }
644
645 /*FIXME: Would make sense to seek for type "hint" match ? */
646
647 i = -ENOENT;
648 goto ret;
649
650found:
651 *id = priv->firm[i].id;
652
653ret:
654 printk("%s firmware for type=", (i < 0) ? "Can't find" : "Found");
655 if (debug) {
656// dump_firm_type(type);
657 printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
658 }
659 return i;
660}
661
662static int load_firmware(struct dvb_frontend *fe, unsigned int type,
663 v4l2_std_id *id)
664{
665 struct xc4000_priv *priv = fe->tuner_priv;
666 int pos, rc;
31f880e2 667 unsigned char *p;
11091a31
DH
668
669 printk("%s called\n", __func__);
670
671 pos = seek_firmware(fe, type, id);
672 if (pos < 0)
673 return pos;
674
675 printk("Loading firmware for type=");
676// dump_firm_type(priv->firm[pos].type);
677 printk("(%x), id %016llx.\n", priv->firm[pos].type,
678 (unsigned long long)*id);
679
680 p = priv->firm[pos].ptr;
11091a31 681
31f880e2
DH
682 rc = xc_load_i2c_sequence(fe, p);
683 printk("load i2c sequence result=%d\n", rc);
11091a31 684
31f880e2 685 return rc;
11091a31
DH
686}
687
8d009a0c
DF
688static int xc4000_fwupload(struct dvb_frontend *fe)
689{
690 struct xc4000_priv *priv = fe->tuner_priv;
11091a31
DH
691 const struct firmware *fw = NULL;
692 const unsigned char *p, *endp;
693 int rc = 0;
694 int n, n_array;
695 char name[33];
696 char *fname;
697
698 printk("%s called\n", __func__);
699
700 fname = XC4000_DEFAULT_FIRMWARE;
701
702 printk("Reading firmware %s\n", fname);
703 rc = request_firmware(&fw, fname, priv->i2c_props.adap->dev.parent);
704 if (rc < 0) {
705 if (rc == -ENOENT)
706 printk("Error: firmware %s not found.\n",
707 fname);
708 else
709 printk("Error %d while requesting firmware %s \n",
710 rc, fname);
8d009a0c 711
11091a31
DH
712 return rc;
713 }
714 p = fw->data;
715 endp = p + fw->size;
8d009a0c 716
11091a31
DH
717 if (fw->size < sizeof(name) - 1 + 2 + 2) {
718 printk("Error: firmware file %s has invalid size!\n",
719 fname);
720 goto corrupt;
8d009a0c
DF
721 }
722
11091a31
DH
723 memcpy(name, p, sizeof(name) - 1);
724 name[sizeof(name) - 1] = 0;
725 p += sizeof(name) - 1;
726
727 priv->firm_version = get_unaligned_le16(p);
728 p += 2;
729
730 n_array = get_unaligned_le16(p);
731 p += 2;
732
733 printk("Loading %d firmware images from %s, type: %s, ver %d.%d\n",
734 n_array, fname, name,
735 priv->firm_version >> 8, priv->firm_version & 0xff);
736
737 priv->firm = kzalloc(sizeof(*priv->firm) * n_array, GFP_KERNEL);
738 if (priv->firm == NULL) {
739 printk("Not enough memory to load firmware file.\n");
740 rc = -ENOMEM;
741 goto err;
742 }
743 priv->firm_size = n_array;
744
745 n = -1;
746 while (p < endp) {
747 __u32 type, size;
748 v4l2_std_id id;
749 __u16 int_freq = 0;
750
751 n++;
752 if (n >= n_array) {
753 printk("More firmware images in file than "
754 "were expected!\n");
755 goto corrupt;
756 }
757
758 /* Checks if there's enough bytes to read */
759 if (endp - p < sizeof(type) + sizeof(id) + sizeof(size))
760 goto header;
761
762 type = get_unaligned_le32(p);
763 p += sizeof(type);
764
765 id = get_unaligned_le64(p);
766 p += sizeof(id);
767
768 if (type & HAS_IF) {
769 int_freq = get_unaligned_le16(p);
770 p += sizeof(int_freq);
771 if (endp - p < sizeof(size))
772 goto header;
773 }
774
775 size = get_unaligned_le32(p);
776 p += sizeof(size);
777
778 if (!size || size > endp - p) {
779 printk("Firmware type ");
780// dump_firm_type(type);
781 printk("(%x), id %llx is corrupted "
782 "(size=%d, expected %d)\n",
783 type, (unsigned long long)id,
784 (unsigned)(endp - p), size);
785 goto corrupt;
786 }
787
788 priv->firm[n].ptr = kzalloc(size, GFP_KERNEL);
789 if (priv->firm[n].ptr == NULL) {
790 printk("Not enough memory to load firmware file.\n");
791 rc = -ENOMEM;
792 goto err;
793 }
794 printk("Reading firmware type ");
795 if (debug) {
796// dump_firm_type_and_int_freq(type, int_freq);
797 printk("(%x), id %llx, size=%d.\n",
798 type, (unsigned long long)id, size);
799 }
800
801 memcpy(priv->firm[n].ptr, p, size);
802 priv->firm[n].type = type;
803 priv->firm[n].id = id;
804 priv->firm[n].size = size;
805 priv->firm[n].int_freq = int_freq;
806
807 p += size;
8d009a0c
DF
808 }
809
11091a31
DH
810 if (n + 1 != priv->firm_size) {
811 printk("Firmware file is incomplete!\n");
812 goto corrupt;
813 }
814
815 goto done;
816
817header:
818 printk("Firmware header is incomplete!\n");
819corrupt:
820 rc = -EINVAL;
821 printk("Error: firmware file is corrupted!\n");
822
823err:
824 printk("Releasing partially loaded firmware file.\n");
825// free_firmware(priv);
826
827done:
8d009a0c 828 release_firmware(fw);
11091a31
DH
829 if (rc == 0)
830 printk("Firmware files loaded.\n");
831
832 return rc;
8d009a0c
DF
833}
834
11091a31 835
8d009a0c
DF
836static void xc_debug_dump(struct xc4000_priv *priv)
837{
838 u16 adc_envelope;
839 u32 freq_error_hz = 0;
840 u16 lock_status;
841 u32 hsync_freq_hz = 0;
842 u16 frame_lines;
843 u16 quality;
844 u8 hw_majorversion = 0, hw_minorversion = 0;
845 u8 fw_majorversion = 0, fw_minorversion = 0;
846// u16 fw_buildversion = 0;
847
848 /* Wait for stats to stabilize.
849 * Frame Lines needs two frame times after initial lock
850 * before it is valid.
851 */
852 xc_wait(100);
853
854 xc_get_ADC_Envelope(priv, &adc_envelope);
855 dprintk(1, "*** ADC envelope (0-1023) = %d\n", adc_envelope);
856
857 xc_get_frequency_error(priv, &freq_error_hz);
858 dprintk(1, "*** Frequency error = %d Hz\n", freq_error_hz);
859
860 xc_get_lock_status(priv, &lock_status);
861 dprintk(1, "*** Lock status (0-Wait, 1-Locked, 2-No-signal) = %d\n",
862 lock_status);
863
864 xc_get_version(priv, &hw_majorversion, &hw_minorversion,
865 &fw_majorversion, &fw_minorversion);
866// WAS:
867// xc_get_buildversion(priv, &fw_buildversion);
868// dprintk(1, "*** HW: V%02x.%02x, FW: V%02x.%02x.%04x\n",
869// hw_majorversion, hw_minorversion,
870// fw_majorversion, fw_minorversion, fw_buildversion);
871// NOW:
872 dprintk(1, "*** HW: V%02x.%02x, FW: V%02x.%02x\n",
873 hw_majorversion, hw_minorversion,
874 fw_majorversion, fw_minorversion);
875
876 xc_get_hsync_freq(priv, &hsync_freq_hz);
877 dprintk(1, "*** Horizontal sync frequency = %d Hz\n", hsync_freq_hz);
878
879 xc_get_frame_lines(priv, &frame_lines);
880 dprintk(1, "*** Frame lines = %d\n", frame_lines);
881
882 xc_get_quality(priv, &quality);
883 dprintk(1, "*** Quality (0:<8dB, 7:>56dB) = %d\n", quality);
884}
885
886static int xc4000_set_params(struct dvb_frontend *fe,
887 struct dvb_frontend_parameters *params)
888{
889 struct xc4000_priv *priv = fe->tuner_priv;
890 int ret;
891
892 if (xc4000_is_firmware_loaded(fe) != XC_RESULT_SUCCESS)
893 xc_load_fw_and_init_tuner(fe);
894
895 dprintk(1, "%s() frequency=%d (Hz)\n", __func__, params->frequency);
896
897 if (fe->ops.info.type == FE_ATSC) {
898 dprintk(1, "%s() ATSC\n", __func__);
899 switch (params->u.vsb.modulation) {
900 case VSB_8:
901 case VSB_16:
902 dprintk(1, "%s() VSB modulation\n", __func__);
903 priv->rf_mode = XC_RF_MODE_AIR;
904 priv->freq_hz = params->frequency - 1750000;
905 priv->bandwidth = BANDWIDTH_6_MHZ;
906 priv->video_standard = DTV6;
907 break;
908 case QAM_64:
909 case QAM_256:
910 case QAM_AUTO:
911 dprintk(1, "%s() QAM modulation\n", __func__);
912 priv->rf_mode = XC_RF_MODE_CABLE;
913 priv->freq_hz = params->frequency - 1750000;
914 priv->bandwidth = BANDWIDTH_6_MHZ;
915 priv->video_standard = DTV6;
916 break;
917 default:
918 return -EINVAL;
919 }
920 } else if (fe->ops.info.type == FE_OFDM) {
921 dprintk(1, "%s() OFDM\n", __func__);
922 switch (params->u.ofdm.bandwidth) {
923 case BANDWIDTH_6_MHZ:
924 priv->bandwidth = BANDWIDTH_6_MHZ;
925 priv->video_standard = DTV6;
926 priv->freq_hz = params->frequency - 1750000;
927 break;
928 case BANDWIDTH_7_MHZ:
929 printk(KERN_ERR "xc4000 bandwidth 7MHz not supported\n");
930 return -EINVAL;
931 case BANDWIDTH_8_MHZ:
932 priv->bandwidth = BANDWIDTH_8_MHZ;
933 priv->video_standard = DTV8;
934 priv->freq_hz = params->frequency - 2750000;
935 break;
936 default:
937 printk(KERN_ERR "xc4000 bandwidth not set!\n");
938 return -EINVAL;
939 }
940 priv->rf_mode = XC_RF_MODE_AIR;
941 } else {
942 printk(KERN_ERR "xc4000 modulation type not supported!\n");
943 return -EINVAL;
944 }
945
946 dprintk(1, "%s() frequency=%d (compensated)\n",
947 __func__, priv->freq_hz);
948
949 ret = xc_SetSignalSource(priv, priv->rf_mode);
950 if (ret != XC_RESULT_SUCCESS) {
951 printk(KERN_ERR
952 "xc4000: xc_SetSignalSource(%d) failed\n",
953 priv->rf_mode);
954 return -EREMOTEIO;
955 }
956
957 ret = xc_SetTVStandard(priv,
958 XC4000_Standard[priv->video_standard].VideoMode,
959 XC4000_Standard[priv->video_standard].AudioMode);
960 if (ret != XC_RESULT_SUCCESS) {
961 printk(KERN_ERR "xc4000: xc_SetTVStandard failed\n");
962 return -EREMOTEIO;
963 }
964
965 ret = xc_set_IF_frequency(priv, priv->if_khz);
966 if (ret != XC_RESULT_SUCCESS) {
967 printk(KERN_ERR "xc4000: xc_Set_IF_frequency(%d) failed\n",
968 priv->if_khz);
969 return -EIO;
970 }
971
972 xc_tune_channel(priv, priv->freq_hz, XC_TUNE_DIGITAL);
973
974 if (debug)
975 xc_debug_dump(priv);
976
977 return 0;
978}
979
980static int xc4000_is_firmware_loaded(struct dvb_frontend *fe)
981{
982 struct xc4000_priv *priv = fe->tuner_priv;
983 int ret;
984 u16 id;
985
986 ret = xc4000_readreg(priv, XREG_PRODUCT_ID, &id);
987 if (ret == XC_RESULT_SUCCESS) {
988 if (id == XC_PRODUCT_ID_FW_NOT_LOADED)
989 ret = XC_RESULT_RESET_FAILURE;
990 else
991 ret = XC_RESULT_SUCCESS;
992 }
993
994 dprintk(1, "%s() returns %s id = 0x%x\n", __func__,
995 ret == XC_RESULT_SUCCESS ? "True" : "False", id);
996 return ret;
997}
998
999static int xc4000_set_analog_params(struct dvb_frontend *fe,
1000 struct analog_parameters *params)
1001{
1002 struct xc4000_priv *priv = fe->tuner_priv;
1003 int ret;
1004
1005 if (xc4000_is_firmware_loaded(fe) != XC_RESULT_SUCCESS)
1006 xc_load_fw_and_init_tuner(fe);
1007
1008 dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n",
1009 __func__, params->frequency);
1010
1011 /* Fix me: it could be air. */
1012 priv->rf_mode = params->mode;
1013 if (params->mode > XC_RF_MODE_CABLE)
1014 priv->rf_mode = XC_RF_MODE_CABLE;
1015
1016 /* params->frequency is in units of 62.5khz */
1017 priv->freq_hz = params->frequency * 62500;
1018
1019 /* FIX ME: Some video standards may have several possible audio
1020 standards. We simply default to one of them here.
1021 */
1022 if (params->std & V4L2_STD_MN) {
1023 /* default to BTSC audio standard */
1024 priv->video_standard = MN_NTSC_PAL_BTSC;
1025 goto tune_channel;
1026 }
1027
1028 if (params->std & V4L2_STD_PAL_BG) {
1029 /* default to NICAM audio standard */
1030 priv->video_standard = BG_PAL_NICAM;
1031 goto tune_channel;
1032 }
1033
1034 if (params->std & V4L2_STD_PAL_I) {
1035 /* default to NICAM audio standard */
1036 priv->video_standard = I_PAL_NICAM;
1037 goto tune_channel;
1038 }
1039
1040 if (params->std & V4L2_STD_PAL_DK) {
1041 /* default to NICAM audio standard */
1042 priv->video_standard = DK_PAL_NICAM;
1043 goto tune_channel;
1044 }
1045
1046 if (params->std & V4L2_STD_SECAM_DK) {
1047 /* default to A2 DK1 audio standard */
1048 priv->video_standard = DK_SECAM_A2DK1;
1049 goto tune_channel;
1050 }
1051
1052 if (params->std & V4L2_STD_SECAM_L) {
1053 priv->video_standard = L_SECAM_NICAM;
1054 goto tune_channel;
1055 }
1056
1057 if (params->std & V4L2_STD_SECAM_LC) {
1058 priv->video_standard = LC_SECAM_NICAM;
1059 goto tune_channel;
1060 }
1061
1062tune_channel:
1063 ret = xc_SetSignalSource(priv, priv->rf_mode);
1064 if (ret != XC_RESULT_SUCCESS) {
1065 printk(KERN_ERR
1066 "xc4000: xc_SetSignalSource(%d) failed\n",
1067 priv->rf_mode);
1068 return -EREMOTEIO;
1069 }
1070
1071 ret = xc_SetTVStandard(priv,
1072 XC4000_Standard[priv->video_standard].VideoMode,
1073 XC4000_Standard[priv->video_standard].AudioMode);
1074 if (ret != XC_RESULT_SUCCESS) {
1075 printk(KERN_ERR "xc4000: xc_SetTVStandard failed\n");
1076 return -EREMOTEIO;
1077 }
1078
1079 xc_tune_channel(priv, priv->freq_hz, XC_TUNE_ANALOG);
1080
1081 if (debug)
1082 xc_debug_dump(priv);
1083
1084 return 0;
1085}
1086
1087static int xc4000_get_frequency(struct dvb_frontend *fe, u32 *freq)
1088{
1089 struct xc4000_priv *priv = fe->tuner_priv;
1090 dprintk(1, "%s()\n", __func__);
1091 *freq = priv->freq_hz;
1092 return 0;
1093}
1094
1095static int xc4000_get_bandwidth(struct dvb_frontend *fe, u32 *bw)
1096{
1097 struct xc4000_priv *priv = fe->tuner_priv;
1098 dprintk(1, "%s()\n", __func__);
1099
1100 *bw = priv->bandwidth;
1101 return 0;
1102}
1103
1104static int xc4000_get_status(struct dvb_frontend *fe, u32 *status)
1105{
1106 struct xc4000_priv *priv = fe->tuner_priv;
1107 u16 lock_status = 0;
1108
1109 xc_get_lock_status(priv, &lock_status);
1110
1111 dprintk(1, "%s() lock_status = 0x%08x\n", __func__, lock_status);
1112
1113 *status = lock_status;
1114
1115 return 0;
1116}
1117
1118static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe)
1119{
1120 struct xc4000_priv *priv = fe->tuner_priv;
1121 int ret = 0;
1122
1123 if (xc4000_is_firmware_loaded(fe) != XC_RESULT_SUCCESS) {
1124 ret = xc4000_fwupload(fe);
1125 if (ret != XC_RESULT_SUCCESS)
1126 return ret;
1127 }
1128
1129 /* Start the tuner self-calibration process */
1130 ret |= xc_initialize(priv);
1131
1132 /* Wait for calibration to complete.
1133 * We could continue but XC4000 will clock stretch subsequent
1134 * I2C transactions until calibration is complete. This way we
1135 * don't have to rely on clock stretching working.
1136 */
1137 xc_wait(100);
1138
1139 /* Default to "CABLE" mode */
1140 ret |= xc_write_reg(priv, XREG_SIGNALSOURCE, XC_RF_MODE_CABLE);
1141
1142 return ret;
1143}
1144
1145static int xc4000_sleep(struct dvb_frontend *fe)
1146{
1147 int ret;
1148
1149 dprintk(1, "%s()\n", __func__);
1150
1151 /* Avoid firmware reload on slow devices */
1152 if (no_poweroff)
1153 return 0;
1154
1155 /* According to Xceive technical support, the "powerdown" register
1156 was removed in newer versions of the firmware. The "supported"
1157 way to sleep the tuner is to pull the reset pin low for 10ms */
1158 ret = xc4000_TunerReset(fe);
1159 if (ret != XC_RESULT_SUCCESS) {
1160 printk(KERN_ERR
1161 "xc4000: %s() unable to shutdown tuner\n",
1162 __func__);
1163 return -EREMOTEIO;
1164 } else
1165 return XC_RESULT_SUCCESS;
1166}
1167
1168static int xc4000_init(struct dvb_frontend *fe)
1169{
1170 struct xc4000_priv *priv = fe->tuner_priv;
1171 dprintk(1, "%s()\n", __func__);
1172
1173 if (xc_load_fw_and_init_tuner(fe) != XC_RESULT_SUCCESS) {
1174 printk(KERN_ERR "xc4000: Unable to initialise tuner\n");
1175 return -EREMOTEIO;
1176 }
1177
1178 if (debug)
1179 xc_debug_dump(priv);
1180
1181 return 0;
1182}
1183
1184static int xc4000_release(struct dvb_frontend *fe)
1185{
1186 struct xc4000_priv *priv = fe->tuner_priv;
1187
1188 dprintk(1, "%s()\n", __func__);
1189
1190 mutex_lock(&xc4000_list_mutex);
1191
1192 if (priv)
1193 hybrid_tuner_release_state(priv);
1194
1195 mutex_unlock(&xc4000_list_mutex);
1196
1197 fe->tuner_priv = NULL;
1198
1199 return 0;
1200}
1201
1202static const struct dvb_tuner_ops xc4000_tuner_ops = {
1203 .info = {
1204 .name = "Xceive XC4000",
1205 .frequency_min = 1000000,
1206 .frequency_max = 1023000000,
1207 .frequency_step = 50000,
1208 },
1209
1210 .release = xc4000_release,
1211 .init = xc4000_init,
1212 .sleep = xc4000_sleep,
1213
1214 .set_params = xc4000_set_params,
1215 .set_analog_params = xc4000_set_analog_params,
1216 .get_frequency = xc4000_get_frequency,
1217 .get_bandwidth = xc4000_get_bandwidth,
1218 .get_status = xc4000_get_status
1219};
1220
1221struct dvb_frontend *xc4000_attach(struct dvb_frontend *fe,
1222 struct i2c_adapter *i2c,
1223 struct xc4000_config *cfg)
1224{
1225 struct xc4000_priv *priv = NULL;
1226 int instance;
11091a31 1227 v4l2_std_id std0;
8d009a0c 1228 u16 id = 0;
11091a31 1229 int rc;
8d009a0c
DF
1230
1231 dprintk(1, "%s(%d-%04x)\n", __func__,
1232 i2c ? i2c_adapter_id(i2c) : -1,
1233 cfg ? cfg->i2c_address : -1);
1234
1235 mutex_lock(&xc4000_list_mutex);
1236
1237 instance = hybrid_tuner_request_state(struct xc4000_priv, priv,
1238 hybrid_tuner_instance_list,
1239 i2c, cfg->i2c_address, "xc4000");
1240 switch (instance) {
1241 case 0:
1242 goto fail;
1243 break;
1244 case 1:
1245 /* new tuner instance */
1246 priv->bandwidth = BANDWIDTH_6_MHZ;
1247 fe->tuner_priv = priv;
1248 break;
1249 default:
1250 /* existing tuner instance */
1251 fe->tuner_priv = priv;
1252 break;
1253 }
1254
1255 if (priv->if_khz == 0) {
1256 /* If the IF hasn't been set yet, use the value provided by
1257 the caller (occurs in hybrid devices where the analog
1258 call to xc4000_attach occurs before the digital side) */
1259 priv->if_khz = cfg->if_khz;
1260 }
1261
1262 /* Check if firmware has been loaded. It is possible that another
1263 instance of the driver has loaded the firmware.
1264 */
1265
1266 if (xc4000_readreg(priv, XREG_PRODUCT_ID, &id) != XC_RESULT_SUCCESS)
1267 goto fail;
1268
1269 switch (id) {
1270 case XC_PRODUCT_ID_FW_LOADED:
1271 printk(KERN_INFO
1272 "xc4000: Successfully identified at address 0x%02x\n",
1273 cfg->i2c_address);
1274 printk(KERN_INFO
1275 "xc4000: Firmware has been loaded previously\n");
1276 break;
1277 case XC_PRODUCT_ID_FW_NOT_LOADED:
1278 printk(KERN_INFO
1279 "xc4000: Successfully identified at address 0x%02x\n",
1280 cfg->i2c_address);
1281 printk(KERN_INFO
1282 "xc4000: Firmware has not been loaded previously\n");
1283 break;
1284 default:
1285 printk(KERN_ERR
1286 "xc4000: Device not found at addr 0x%02x (0x%x)\n",
1287 cfg->i2c_address, id);
1288 goto fail;
1289 }
1290
1291 mutex_unlock(&xc4000_list_mutex);
1292
1293 memcpy(&fe->ops.tuner_ops, &xc4000_tuner_ops,
1294 sizeof(struct dvb_tuner_ops));
1295
11091a31
DH
1296 /* FIXME: For now, load the firmware at startup. We will remove this
1297 before the code goes to production... */
1298 xc4000_fwupload(fe);
1299 printk("xc4000_fwupload done\n");
1300
1301 std0 = 0;
1302// rc = load_firmware(fe, BASE | new_fw.type, &std0);
1303 rc = load_firmware(fe, BASE, &std0);
31f880e2 1304 if (rc != XC_RESULT_SUCCESS) {
11091a31
DH
1305 tuner_err("Error %d while loading base firmware\n",
1306 rc);
1307 goto fail;
1308 }
1309
1310 /* Load INIT1, if needed */
1311 tuner_dbg("Load init1 firmware, if exists\n");
1312
1313// rc = load_firmware(fe, BASE | INIT1 | new_fw.type, &std0);
6bf60d56 1314 rc = load_firmware(fe, BASE | INIT1, &std0);
11091a31
DH
1315 printk("init1 load result %x\n", rc);
1316
1317 if (xc4000_readreg(priv, XREG_PRODUCT_ID, &id) != XC_RESULT_SUCCESS)
1318 goto fail;
1319 printk("djh id is now %x\n", id);
1320
8d009a0c
DF
1321 return fe;
1322fail:
1323 mutex_unlock(&xc4000_list_mutex);
1324
1325 xc4000_release(fe);
1326 return NULL;
1327}
1328EXPORT_SYMBOL(xc4000_attach);
1329
1330MODULE_AUTHOR("Steven Toth, Davide Ferri");
1331MODULE_DESCRIPTION("Xceive xc4000 silicon tuner driver");
1332MODULE_LICENSE("GPL");