3 * Copyright (c) 2007 Mauro Carvalho Chehab (mchehab@infradead.org)
5 * Copyright (c) 2007 Michel Ludwig (michel.ludwig@gmail.com)
8 * This code is placed under the terms of the GNU General Public License v2
11 #include <linux/i2c.h>
12 #include <asm/div64.h>
13 #include <linux/firmware.h>
14 #include <linux/videodev2.h>
15 #include <linux/delay.h>
16 #include <media/tuner.h>
17 #include <linux/mutex.h>
18 #include "tuner-i2c.h"
19 #include "tuner-xc2028.h"
20 #include "tuner-xc2028-types.h"
22 #include <linux/dvb/frontend.h>
23 #include "dvb_frontend.h"
26 #define PREFIX "xc2028"
29 module_param(debug
, int, 0644);
30 MODULE_PARM_DESC(debug
, "enable verbose debug messages");
32 static char audio_std
[8];
33 module_param_string(audio_std
, audio_std
, sizeof(audio_std
), 0);
34 MODULE_PARM_DESC(audio_std
,
35 "Audio standard. XC3028 audio decoder explicitly "
36 "needs to know what audio\n"
37 "standard is needed for some video standards with audio A2 or NICAM.\n"
38 "The valid values are:\n"
46 static LIST_HEAD(xc2028_list
);
47 static DEFINE_MUTEX(xc2028_list_mutex
);
49 /* struct for storing firmware table */
50 struct firmware_description
{
58 struct firmware_properties
{
63 unsigned int scode_table
;
68 struct list_head xc2028_list
;
69 struct tuner_i2c_props i2c_props
;
70 int (*tuner_callback
) (void *dev
,
71 int command
, int arg
);
76 struct firmware_description
*firm
;
83 struct xc2028_ctrl ctrl
;
85 struct firmware_properties cur_fw
;
90 #define i2c_send(priv, buf, size) ({ \
92 _rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size); \
94 tuner_info("i2c output error: rc = %d (should be %d)\n",\
99 #define i2c_rcv(priv, buf, size) ({ \
101 _rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size); \
103 tuner_err("i2c input error: rc = %d (should be %d)\n", \
108 #define i2c_send_recv(priv, obuf, osize, ibuf, isize) ({ \
110 _rc = tuner_i2c_xfer_send_recv(&priv->i2c_props, obuf, osize, \
113 tuner_err("i2c input error: rc = %d (should be %d)\n", \
118 #define send_seq(priv, data...) ({ \
119 static u8 _val[] = data; \
121 if (sizeof(_val) != \
122 (_rc = tuner_i2c_xfer_send(&priv->i2c_props, \
123 _val, sizeof(_val)))) { \
124 tuner_err("Error on line %d: %d\n", __LINE__, _rc); \
130 static unsigned int xc2028_get_reg(struct xc2028_data
*priv
, u16 reg
, u16
*val
)
132 unsigned char buf
[2];
133 unsigned char ibuf
[2];
135 tuner_dbg("%s %04x called\n", __FUNCTION__
, reg
);
138 buf
[1] = (unsigned char) reg
;
140 if (i2c_send_recv(priv
, buf
, 2, ibuf
, 2) != 2)
143 *val
= (ibuf
[1]) | (ibuf
[0] << 8);
147 #define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0)
148 void dump_firm_type_and_int_freq(unsigned int type
, u16 int_freq
)
194 if (type
& TOYOTA388
)
195 printk("TOYOTA388 ");
196 if (type
& TOYOTA794
)
197 printk("TOYOTA794 ");
200 if (type
& ZARLINK456
)
201 printk("ZARLINK456 ");
211 printk("HAS_IF_%d ", int_freq
);
214 static v4l2_std_id
parse_audio_std_option(void)
216 if (strcasecmp(audio_std
, "A2") == 0)
218 if (strcasecmp(audio_std
, "A2/A") == 0)
219 return V4L2_STD_A2_A
;
220 if (strcasecmp(audio_std
, "A2/B") == 0)
221 return V4L2_STD_A2_B
;
222 if (strcasecmp(audio_std
, "NICAM") == 0)
223 return V4L2_STD_NICAM
;
224 if (strcasecmp(audio_std
, "NICAM/A") == 0)
225 return V4L2_STD_NICAM_A
;
226 if (strcasecmp(audio_std
, "NICAM/B") == 0)
227 return V4L2_STD_NICAM_B
;
232 static void free_firmware(struct xc2028_data
*priv
)
239 for (i
= 0; i
< priv
->firm_size
; i
++)
240 kfree(priv
->firm
[i
].ptr
);
247 memset(&priv
->cur_fw
, 0, sizeof(priv
->cur_fw
));
250 static int load_all_firmwares(struct dvb_frontend
*fe
)
252 struct xc2028_data
*priv
= fe
->tuner_priv
;
253 const struct firmware
*fw
= NULL
;
254 unsigned char *p
, *endp
;
259 tuner_dbg("%s called\n", __FUNCTION__
);
261 tuner_dbg("Reading firmware %s\n", priv
->ctrl
.fname
);
262 rc
= request_firmware(&fw
, priv
->ctrl
.fname
,
263 &priv
->i2c_props
.adap
->dev
);
266 tuner_err("Error: firmware %s not found.\n",
269 tuner_err("Error %d while requesting firmware %s \n",
270 rc
, priv
->ctrl
.fname
);
277 if (fw
->size
< sizeof(name
) - 1 + 2 + 2) {
278 tuner_err("Error: firmware file %s has invalid size!\n",
283 memcpy(name
, p
, sizeof(name
) - 1);
284 name
[sizeof(name
) - 1] = 0;
285 p
+= sizeof(name
) - 1;
287 priv
->firm_version
= le16_to_cpu(*(__u16
*) p
);
290 n_array
= le16_to_cpu(*(__u16
*) p
);
293 tuner_info("Loading %d firmware images from %s, type: %s, ver %d.%d\n",
294 n_array
, priv
->ctrl
.fname
, name
,
295 priv
->firm_version
>> 8, priv
->firm_version
& 0xff);
297 priv
->firm
= kzalloc(sizeof(*priv
->firm
) * n_array
, GFP_KERNEL
);
298 if (priv
->firm
== NULL
) {
299 tuner_err("Not enough memory to load firmware file.\n");
303 priv
->firm_size
= n_array
;
313 tuner_err("More firmware images in file than "
318 /* Checks if there's enough bytes to read */
319 if (p
+ sizeof(type
) + sizeof(id
) + sizeof(size
) > endp
) {
320 tuner_err("Firmware header is incomplete!\n");
324 type
= le32_to_cpu(*(__u32
*) p
);
327 id
= le64_to_cpu(*(v4l2_std_id
*) p
);
331 int_freq
= le16_to_cpu(*(__u16
*) p
);
332 p
+= sizeof(int_freq
);
335 size
= le32_to_cpu(*(__u32
*) p
);
338 if ((!size
) || (size
+ p
> endp
)) {
339 tuner_err("Firmware type ");
340 dump_firm_type(type
);
341 printk("(%x), id %llx is corrupted "
342 "(size=%d, expected %d)\n",
343 type
, (unsigned long long)id
,
344 (unsigned)(endp
- p
), size
);
348 priv
->firm
[n
].ptr
= kzalloc(size
, GFP_KERNEL
);
349 if (priv
->firm
[n
].ptr
== NULL
) {
350 tuner_err("Not enough memory to load firmware file.\n");
354 tuner_dbg("Reading firmware type ");
356 dump_firm_type_and_int_freq(type
, int_freq
);
357 printk("(%x), id %llx, size=%d.\n",
358 type
, (unsigned long long)id
, size
);
361 memcpy(priv
->firm
[n
].ptr
, p
, size
);
362 priv
->firm
[n
].type
= type
;
363 priv
->firm
[n
].id
= id
;
364 priv
->firm
[n
].size
= size
;
365 priv
->firm
[n
].int_freq
= int_freq
;
370 if (n
+ 1 != priv
->firm_size
) {
371 tuner_err("Firmware file is incomplete!\n");
379 tuner_err("Error: firmware file is corrupted!\n");
382 tuner_info("Releasing partially loaded firmware file.\n");
386 release_firmware(fw
);
388 tuner_dbg("Firmware files loaded.\n");
393 static int seek_firmware(struct dvb_frontend
*fe
, unsigned int type
,
396 struct xc2028_data
*priv
= fe
->tuner_priv
;
397 int i
, best_i
= -1, best_nr_matches
= 0;
398 unsigned int ign_firm_type_mask
= 0;
400 tuner_dbg("%s called, want type=", __FUNCTION__
);
402 dump_firm_type(type
);
403 printk("(%x), id %016llx.\n", type
, (unsigned long long)*id
);
407 tuner_err("Error! firmware not loaded\n");
411 if (((type
& ~SCODE
) == 0) && (*id
== 0))
416 else if (type
& SCODE
) {
418 ign_firm_type_mask
= HAS_IF
;
419 } else if (type
& DTV_TYPES
)
421 else if (type
& STD_SPECIFIC_TYPES
)
422 type
&= STD_SPECIFIC_TYPES
;
424 /* Seek for exact match */
425 for (i
= 0; i
< priv
->firm_size
; i
++) {
426 if ((type
== (priv
->firm
[i
].type
& ~ign_firm_type_mask
)) &&
427 (*id
== priv
->firm
[i
].id
))
431 /* Seek for generic video standard match */
432 for (i
= 0; i
< priv
->firm_size
; i
++) {
433 v4l2_std_id match_mask
;
436 if (type
!= (priv
->firm
[i
].type
& ~ign_firm_type_mask
))
439 match_mask
= *id
& priv
->firm
[i
].id
;
443 if ((*id
& match_mask
) == *id
)
444 goto found
; /* Supports all the requested standards */
446 nr_matches
= hweight64(match_mask
);
447 if (nr_matches
> best_nr_matches
) {
448 best_nr_matches
= nr_matches
;
453 if (best_nr_matches
> 0) {
454 tuner_dbg("Selecting best matching firmware (%d bits) for "
455 "type=", best_nr_matches
);
456 dump_firm_type(type
);
457 printk("(%x), id %016llx:\n", type
, (unsigned long long)*id
);
462 /*FIXME: Would make sense to seek for type "hint" match ? */
468 *id
= priv
->firm
[i
].id
;
471 tuner_dbg("%s firmware for type=", (i
< 0) ? "Can't find" : "Found");
473 dump_firm_type(type
);
474 printk("(%x), id %016llx.\n", type
, (unsigned long long)*id
);
479 static int load_firmware(struct dvb_frontend
*fe
, unsigned int type
,
482 struct xc2028_data
*priv
= fe
->tuner_priv
;
484 unsigned char *p
, *endp
, buf
[priv
->ctrl
.max_len
];
486 tuner_dbg("%s called\n", __FUNCTION__
);
488 pos
= seek_firmware(fe
, type
, id
);
492 tuner_info("Loading firmware for type=");
493 dump_firm_type(priv
->firm
[pos
].type
);
494 printk("(%x), id %016llx.\n", priv
->firm
[pos
].type
,
495 (unsigned long long)*id
);
497 p
= priv
->firm
[pos
].ptr
;
498 endp
= p
+ priv
->firm
[pos
].size
;
503 /* Checks if there's enough bytes to read */
504 if (p
+ sizeof(size
) > endp
) {
505 tuner_err("Firmware chunk size is wrong\n");
509 size
= le16_to_cpu(*(__u16
*) p
);
516 /* Special callback command received */
517 rc
= priv
->tuner_callback(priv
->video_dev
,
518 XC2028_TUNER_RESET
, 0);
520 tuner_err("Error at RESET code %d\n",
526 if (size
>= 0xff00) {
529 rc
= priv
->tuner_callback(priv
->video_dev
,
530 XC2028_RESET_CLK
, 0);
532 tuner_err("Error at RESET code %d\n",
538 tuner_info("Invalid RESET code %d\n",
546 /* Checks for a sleep command */
548 msleep(size
& 0x7fff);
552 if ((size
+ p
> endp
)) {
553 tuner_err("missing bytes: need %d, have %d\n",
554 size
, (int)(endp
- p
));
562 /* Sends message chunks */
564 int len
= (size
< priv
->ctrl
.max_len
- 1) ?
565 size
: priv
->ctrl
.max_len
- 1;
567 memcpy(buf
+ 1, p
, len
);
569 rc
= i2c_send(priv
, buf
, len
+ 1);
571 tuner_err("%d returned from send\n", rc
);
582 static int load_scode(struct dvb_frontend
*fe
, unsigned int type
,
583 v4l2_std_id
*id
, __u16 int_freq
, int scode
)
585 struct xc2028_data
*priv
= fe
->tuner_priv
;
589 tuner_dbg("%s called\n", __FUNCTION__
);
592 pos
= seek_firmware(fe
, type
, id
);
596 for (pos
= 0; pos
< priv
->firm_size
; pos
++) {
597 if ((priv
->firm
[pos
].int_freq
== int_freq
) &&
598 (priv
->firm
[pos
].type
& HAS_IF
))
601 if (pos
== priv
->firm_size
)
605 p
= priv
->firm
[pos
].ptr
;
607 if (priv
->firm
[pos
].type
& HAS_IF
) {
608 if (priv
->firm
[pos
].size
!= 12 * 16 || scode
>= 16)
612 /* 16 SCODE entries per file; each SCODE entry is 12 bytes and
613 * has a 2-byte size header in the firmware format. */
614 if (priv
->firm
[pos
].size
!= 14 * 16 || scode
>= 16 ||
615 le16_to_cpu(*(__u16
*)(p
+ 14 * scode
)) != 12)
620 tuner_info("Loading SCODE for type=");
621 dump_firm_type_and_int_freq(priv
->firm
[pos
].type
,
622 priv
->firm
[pos
].int_freq
);
623 printk("(%x), id %016llx.\n", priv
->firm
[pos
].type
,
624 (unsigned long long)*id
);
626 if (priv
->firm_version
< 0x0202)
627 rc
= send_seq(priv
, {0x20, 0x00, 0x00, 0x00});
629 rc
= send_seq(priv
, {0xa0, 0x00, 0x00, 0x00});
633 rc
= i2c_send(priv
, p
, 12);
637 rc
= send_seq(priv
, {0x00, 0x8c});
644 static int check_firmware(struct dvb_frontend
*fe
, unsigned int type
,
645 v4l2_std_id std
, __u16 int_freq
)
647 struct xc2028_data
*priv
= fe
->tuner_priv
;
648 struct firmware_properties new_fw
;
649 int rc
= 0, is_retry
= 0;
650 u16 version
, hwmodel
;
653 tuner_dbg("%s called\n", __FUNCTION__
);
656 if (!priv
->ctrl
.fname
) {
657 tuner_info("xc2028/3028 firmware name not set!\n");
661 rc
= load_all_firmwares(fe
);
666 if (priv
->ctrl
.mts
&& !(type
& FM
))
672 new_fw
.std_req
= std
;
673 new_fw
.scode_table
= SCODE
| priv
->ctrl
.scode_table
;
675 new_fw
.int_freq
= int_freq
;
677 tuner_dbg("checking firmware, user requested type=");
679 dump_firm_type(new_fw
.type
);
680 printk("(%x), id %016llx, ", new_fw
.type
,
681 (unsigned long long)new_fw
.std_req
);
683 printk("scode_tbl ");
684 dump_firm_type(priv
->ctrl
.scode_table
);
685 printk("(%x), ", priv
->ctrl
.scode_table
);
687 printk("int_freq %d, ", new_fw
.int_freq
);
688 printk("scode_nr %d\n", new_fw
.scode_nr
);
691 /* No need to reload base firmware if it matches */
692 if (((BASE
| new_fw
.type
) & BASE_TYPES
) ==
693 (priv
->cur_fw
.type
& BASE_TYPES
)) {
694 tuner_dbg("BASE firmware not changed.\n");
698 /* Updating BASE - forget about all currently loaded firmware */
699 memset(&priv
->cur_fw
, 0, sizeof(priv
->cur_fw
));
701 /* Reset is needed before loading firmware */
702 rc
= priv
->tuner_callback(priv
->video_dev
,
703 XC2028_TUNER_RESET
, 0);
707 /* BASE firmwares are all std0 */
709 rc
= load_firmware(fe
, BASE
| new_fw
.type
, &std0
);
711 tuner_err("Error %d while loading base firmware\n",
716 /* Load INIT1, if needed */
717 tuner_dbg("Load init1 firmware, if exists\n");
719 rc
= load_firmware(fe
, BASE
| INIT1
| new_fw
.type
, &std0
);
721 rc
= load_firmware(fe
, (BASE
| INIT1
| new_fw
.type
) & ~F8MHZ
,
723 if (rc
< 0 && rc
!= -ENOENT
) {
724 tuner_err("Error %d while loading init1 firmware\n",
731 * No need to reload standard specific firmware if base firmware
732 * was not reloaded and requested video standards have not changed.
734 if (priv
->cur_fw
.type
== (BASE
| new_fw
.type
) &&
735 priv
->cur_fw
.std_req
== std
) {
736 tuner_dbg("Std-specific firmware already loaded.\n");
737 goto skip_std_specific
;
740 /* Reloading std-specific firmware forces a SCODE update */
741 priv
->cur_fw
.scode_table
= 0;
743 rc
= load_firmware(fe
, new_fw
.type
, &new_fw
.id
);
745 rc
= load_firmware(fe
, new_fw
.type
& ~F8MHZ
, &new_fw
.id
);
751 if (priv
->cur_fw
.scode_table
== new_fw
.scode_table
&&
752 priv
->cur_fw
.scode_nr
== new_fw
.scode_nr
) {
753 tuner_dbg("SCODE firmware already loaded.\n");
757 /* Load SCODE firmware, if exists */
758 tuner_dbg("Trying to load scode %d\n", new_fw
.scode_nr
);
760 rc
= load_scode(fe
, new_fw
.type
| new_fw
.scode_table
, &new_fw
.id
,
761 new_fw
.int_freq
, new_fw
.scode_nr
);
764 if (xc2028_get_reg(priv
, 0x0004, &version
) < 0 ||
765 xc2028_get_reg(priv
, 0x0008, &hwmodel
) < 0) {
766 tuner_err("Unable to read tuner registers.\n");
770 tuner_info("Device is Xceive %d version %d.%d, "
771 "firmware version %d.%d\n",
772 hwmodel
, (version
& 0xf000) >> 12, (version
& 0xf00) >> 8,
773 (version
& 0xf0) >> 4, version
& 0xf);
775 /* Check firmware version against what we downloaded. */
776 if (priv
->firm_version
!= ((version
& 0xf0) << 4 | (version
& 0x0f))) {
777 tuner_err("Incorrect readback of firmware version.\n");
781 /* Check that the tuner hardware model remains consistent over time. */
782 if (priv
->hwmodel
== 0 && (hwmodel
== 2028 || hwmodel
== 3028)) {
783 priv
->hwmodel
= hwmodel
;
784 priv
->hwvers
= version
& 0xff00;
785 } else if (priv
->hwmodel
== 0 || priv
->hwmodel
!= hwmodel
||
786 priv
->hwvers
!= (version
& 0xff00)) {
787 tuner_err("Read invalid device hardware information - tuner "
792 memcpy(&priv
->cur_fw
, &new_fw
, sizeof(priv
->cur_fw
));
795 * By setting BASE in cur_fw.type only after successfully loading all
797 * 1. Identify that BASE firmware with type=0 has been loaded;
798 * 2. Tell whether BASE firmware was just changed the next time through.
800 priv
->cur_fw
.type
|= BASE
;
805 memset(&priv
->cur_fw
, 0, sizeof(priv
->cur_fw
));
809 tuner_dbg("Retrying firmware load\n");
818 static int xc2028_signal(struct dvb_frontend
*fe
, u16
*strength
)
820 struct xc2028_data
*priv
= fe
->tuner_priv
;
821 u16 frq_lock
, signal
= 0;
824 tuner_dbg("%s called\n", __FUNCTION__
);
826 mutex_lock(&priv
->lock
);
828 /* Sync Lock Indicator */
829 rc
= xc2028_get_reg(priv
, 0x0002, &frq_lock
);
830 if (rc
< 0 || frq_lock
== 0)
833 /* Frequency is locked. Return signal quality */
835 /* Get SNR of the video signal */
836 rc
= xc2028_get_reg(priv
, 0x0040, &signal
);
841 mutex_unlock(&priv
->lock
);
850 static int generic_set_freq(struct dvb_frontend
*fe
, u32 freq
/* in HZ */,
851 enum tuner_mode new_mode
,
856 struct xc2028_data
*priv
= fe
->tuner_priv
;
858 unsigned char buf
[4];
861 tuner_dbg("%s called\n", __FUNCTION__
);
863 mutex_lock(&priv
->lock
);
865 tuner_dbg("should set frequency %d kHz\n", freq
/ 1000);
867 if (check_firmware(fe
, type
, std
, int_freq
) < 0)
870 /* On some cases xc2028 can disable video output, if
871 * very weak signals are received. By sending a soft
872 * reset, this is re-enabled. So, it is better to always
873 * send a soft reset before changing channels, to be sure
874 * that xc2028 will be in a safe state.
875 * Maybe this might also be needed for DTV.
877 if (new_mode
== T_ANALOG_TV
) {
878 rc
= send_seq(priv
, {0x00, 0x00});
879 } else if (priv
->cur_fw
.type
& ATSC
) {
884 * We must adjust the offset by 500kHz in two cases in order
885 * to correctly center the IF output:
886 * 1) When the ZARLINK456 or DIBCOM52 tables were explicitly
887 * selected and a 7MHz channel is tuned;
888 * 2) When tuning a VHF channel with DTV78 firmware.
890 if (((priv
->cur_fw
.type
& DTV7
) &&
891 (priv
->cur_fw
.scode_table
& (ZARLINK456
| DIBCOM52
))) ||
892 ((priv
->cur_fw
.type
& DTV78
) && freq
< 470000000))
896 div
= (freq
- offset
+ DIV
/ 2) / DIV
;
898 /* CMD= Set frequency */
899 if (priv
->firm_version
< 0x0202)
900 rc
= send_seq(priv
, {0x00, 0x02, 0x00, 0x00});
902 rc
= send_seq(priv
, {0x80, 0x02, 0x00, 0x00});
906 rc
= priv
->tuner_callback(priv
->video_dev
, XC2028_RESET_CLK
, 1);
912 buf
[0] = 0xff & (div
>> 24);
913 buf
[1] = 0xff & (div
>> 16);
914 buf
[2] = 0xff & (div
>> 8);
915 buf
[3] = 0xff & (div
);
917 rc
= i2c_send(priv
, buf
, sizeof(buf
));
922 priv
->frequency
= freq
;
924 tuner_dbg("divisor= %02x %02x %02x %02x (freq=%d.%03d)\n",
925 buf
[0], buf
[1], buf
[2], buf
[3],
926 freq
/ 1000000, (freq
% 1000000) / 1000);
931 mutex_unlock(&priv
->lock
);
936 static int xc2028_set_analog_freq(struct dvb_frontend
*fe
,
937 struct analog_parameters
*p
)
939 struct xc2028_data
*priv
= fe
->tuner_priv
;
942 tuner_dbg("%s called\n", __FUNCTION__
);
944 if (p
->mode
== V4L2_TUNER_RADIO
) {
946 if (priv
->ctrl
.input1
)
948 return generic_set_freq(fe
, (625l * p
->frequency
) / 10,
949 T_ANALOG_TV
, type
, 0, 0);
952 /* if std is not defined, choose one */
954 p
->std
= V4L2_STD_MN
;
956 /* PAL/M, PAL/N, PAL/Nc and NTSC variants should use 6MHz firmware */
957 if (!(p
->std
& V4L2_STD_MN
))
960 /* Add audio hack to std mask */
961 p
->std
|= parse_audio_std_option();
963 return generic_set_freq(fe
, 62500l * p
->frequency
,
964 T_ANALOG_TV
, type
, p
->std
, 0);
967 static int xc2028_set_params(struct dvb_frontend
*fe
,
968 struct dvb_frontend_parameters
*p
)
970 struct xc2028_data
*priv
= fe
->tuner_priv
;
972 fe_bandwidth_t bw
= BANDWIDTH_8_MHZ
;
975 tuner_dbg("%s called\n", __FUNCTION__
);
977 if (priv
->ctrl
.d2633
)
982 switch(fe
->ops
.info
.type
) {
984 bw
= p
->u
.ofdm
.bandwidth
;
987 tuner_info("WARN: There are some reports that "
988 "QAM 6 MHz doesn't work.\n"
989 "If this works for you, please report by "
990 "e-mail to: v4l-dvb-maintainer@linuxtv.org\n");
991 bw
= BANDWIDTH_6_MHZ
;
995 bw
= BANDWIDTH_6_MHZ
;
996 /* The only ATSC firmware (at least on v2.7) is D2633,
997 so overrides ctrl->d2633 */
1001 /* DVB-S is not supported */
1007 case BANDWIDTH_8_MHZ
:
1008 if (p
->frequency
< 470000000)
1009 priv
->ctrl
.vhfbw7
= 0;
1011 priv
->ctrl
.uhfbw8
= 1;
1012 type
|= (priv
->ctrl
.vhfbw7
&& priv
->ctrl
.uhfbw8
) ? DTV78
: DTV8
;
1015 case BANDWIDTH_7_MHZ
:
1016 if (p
->frequency
< 470000000)
1017 priv
->ctrl
.vhfbw7
= 1;
1019 priv
->ctrl
.uhfbw8
= 0;
1020 type
|= (priv
->ctrl
.vhfbw7
&& priv
->ctrl
.uhfbw8
) ? DTV78
: DTV7
;
1023 case BANDWIDTH_6_MHZ
:
1025 priv
->ctrl
.vhfbw7
= 0;
1026 priv
->ctrl
.uhfbw8
= 0;
1029 tuner_err("error: bandwidth not supported.\n");
1032 /* All S-code tables need a 200kHz shift */
1033 if (priv
->ctrl
.demod
)
1034 demod
= priv
->ctrl
.demod
+ 200;
1036 return generic_set_freq(fe
, p
->frequency
,
1037 T_DIGITAL_TV
, type
, 0, demod
);
1040 static int xc2028_sleep(struct dvb_frontend
*fe
)
1042 struct xc2028_data
*priv
= fe
->tuner_priv
;
1045 tuner_dbg("%s called\n", __FUNCTION__
);
1047 mutex_lock(&priv
->lock
);
1049 if (priv
->firm_version
< 0x0202)
1050 rc
= send_seq(priv
, {0x00, 0x08, 0x00, 0x00});
1052 rc
= send_seq(priv
, {0x80, 0x08, 0x00, 0x00});
1054 priv
->cur_fw
.type
= 0; /* need firmware reload */
1056 mutex_unlock(&priv
->lock
);
1062 static int xc2028_dvb_release(struct dvb_frontend
*fe
)
1064 struct xc2028_data
*priv
= fe
->tuner_priv
;
1066 tuner_dbg("%s called\n", __FUNCTION__
);
1068 mutex_lock(&xc2028_list_mutex
);
1073 list_del(&priv
->xc2028_list
);
1075 kfree(priv
->ctrl
.fname
);
1077 free_firmware(priv
);
1079 fe
->tuner_priv
= NULL
;
1082 mutex_unlock(&xc2028_list_mutex
);
1087 static int xc2028_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
1089 struct xc2028_data
*priv
= fe
->tuner_priv
;
1091 tuner_dbg("%s called\n", __FUNCTION__
);
1093 *frequency
= priv
->frequency
;
1098 static int xc2028_set_config(struct dvb_frontend
*fe
, void *priv_cfg
)
1100 struct xc2028_data
*priv
= fe
->tuner_priv
;
1101 struct xc2028_ctrl
*p
= priv_cfg
;
1104 tuner_dbg("%s called\n", __FUNCTION__
);
1106 mutex_lock(&priv
->lock
);
1108 kfree(priv
->ctrl
.fname
);
1109 free_firmware(priv
);
1111 memcpy(&priv
->ctrl
, p
, sizeof(priv
->ctrl
));
1112 priv
->ctrl
.fname
= NULL
;
1115 priv
->ctrl
.fname
= kstrdup(p
->fname
, GFP_KERNEL
);
1116 if (priv
->ctrl
.fname
== NULL
)
1120 if (priv
->ctrl
.max_len
< 9)
1121 priv
->ctrl
.max_len
= 13;
1123 mutex_unlock(&priv
->lock
);
1128 static const struct dvb_tuner_ops xc2028_dvb_tuner_ops
= {
1130 .name
= "Xceive XC3028",
1131 .frequency_min
= 42000000,
1132 .frequency_max
= 864000000,
1133 .frequency_step
= 50000,
1136 .set_config
= xc2028_set_config
,
1137 .set_analog_params
= xc2028_set_analog_freq
,
1138 .release
= xc2028_dvb_release
,
1139 .get_frequency
= xc2028_get_frequency
,
1140 .get_rf_strength
= xc2028_signal
,
1141 .set_params
= xc2028_set_params
,
1142 .sleep
= xc2028_sleep
,
1146 struct dvb_frontend
*xc2028_attach(struct dvb_frontend
*fe
,
1147 struct xc2028_config
*cfg
)
1149 struct xc2028_data
*priv
;
1153 printk(KERN_DEBUG PREFIX
": Xcv2028/3028 init called!\n");
1155 if (NULL
== cfg
|| NULL
== cfg
->video_dev
)
1159 printk(KERN_ERR PREFIX
": No frontend!\n");
1163 video_dev
= cfg
->video_dev
;
1165 mutex_lock(&xc2028_list_mutex
);
1167 list_for_each_entry(priv
, &xc2028_list
, xc2028_list
) {
1168 if (priv
->video_dev
== cfg
->video_dev
) {
1175 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
1177 mutex_unlock(&xc2028_list_mutex
);
1181 priv
->i2c_props
.addr
= cfg
->i2c_addr
;
1182 priv
->i2c_props
.adap
= cfg
->i2c_adap
;
1183 priv
->video_dev
= video_dev
;
1184 priv
->tuner_callback
= cfg
->callback
;
1185 priv
->ctrl
.max_len
= 13;
1187 mutex_init(&priv
->lock
);
1189 list_add_tail(&priv
->xc2028_list
, &xc2028_list
);
1192 fe
->tuner_priv
= priv
;
1195 memcpy(&fe
->ops
.tuner_ops
, &xc2028_dvb_tuner_ops
,
1196 sizeof(xc2028_dvb_tuner_ops
));
1198 tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner");
1201 xc2028_set_config(fe
, cfg
->ctrl
);
1203 mutex_unlock(&xc2028_list_mutex
);
1208 EXPORT_SYMBOL(xc2028_attach
);
1210 MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver");
1211 MODULE_AUTHOR("Michel Ludwig <michel.ludwig@gmail.com>");
1212 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
1213 MODULE_LICENSE("GPL");