3 * Copyright (c) 2007-2008 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 <asm/unaligned.h>
19 #include "tuner-i2c.h"
20 #include "tuner-xc2028.h"
21 #include "tuner-xc2028-types.h"
23 #include <linux/dvb/frontend.h>
24 #include "dvb_frontend.h"
28 module_param(debug
, int, 0644);
29 MODULE_PARM_DESC(debug
, "enable verbose debug messages");
31 static char audio_std
[8];
32 module_param_string(audio_std
, audio_std
, sizeof(audio_std
), 0);
33 MODULE_PARM_DESC(audio_std
,
34 "Audio standard. XC3028 audio decoder explicitly "
35 "needs to know what audio\n"
36 "standard is needed for some video standards with audio A2 or NICAM.\n"
37 "The valid values are:\n"
45 static char firmware_name
[FIRMWARE_NAME_MAX
];
46 module_param_string(firmware_name
, firmware_name
, sizeof(firmware_name
), 0);
47 MODULE_PARM_DESC(firmware_name
, "Firmware file name. Allows overriding the "
48 "default firmware name\n");
50 static LIST_HEAD(hybrid_tuner_instance_list
);
51 static DEFINE_MUTEX(xc2028_list_mutex
);
53 /* struct for storing firmware table */
54 struct firmware_description
{
62 struct firmware_properties
{
67 unsigned int scode_table
;
72 struct list_head hybrid_tuner_instance_list
;
73 struct tuner_i2c_props i2c_props
;
74 int (*tuner_callback
) (void *dev
,
75 int command
, int arg
);
79 struct firmware_description
*firm
;
86 struct xc2028_ctrl ctrl
;
88 struct firmware_properties cur_fw
;
93 #define i2c_send(priv, buf, size) ({ \
95 _rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size); \
97 tuner_info("i2c output error: rc = %d (should be %d)\n",\
102 #define i2c_rcv(priv, buf, size) ({ \
104 _rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size); \
106 tuner_err("i2c input error: rc = %d (should be %d)\n", \
111 #define i2c_send_recv(priv, obuf, osize, ibuf, isize) ({ \
113 _rc = tuner_i2c_xfer_send_recv(&priv->i2c_props, obuf, osize, \
116 tuner_err("i2c input error: rc = %d (should be %d)\n", \
121 #define send_seq(priv, data...) ({ \
122 static u8 _val[] = data; \
124 if (sizeof(_val) != \
125 (_rc = tuner_i2c_xfer_send(&priv->i2c_props, \
126 _val, sizeof(_val)))) { \
127 tuner_err("Error on line %d: %d\n", __LINE__, _rc); \
133 static int xc2028_get_reg(struct xc2028_data
*priv
, u16 reg
, u16
*val
)
135 unsigned char buf
[2];
136 unsigned char ibuf
[2];
138 tuner_dbg("%s %04x called\n", __func__
, reg
);
141 buf
[1] = (unsigned char) reg
;
143 if (i2c_send_recv(priv
, buf
, 2, ibuf
, 2) != 2)
146 *val
= (ibuf
[1]) | (ibuf
[0] << 8);
150 #define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0)
151 static void dump_firm_type_and_int_freq(unsigned int type
, u16 int_freq
)
197 if (type
& TOYOTA388
)
198 printk("TOYOTA388 ");
199 if (type
& TOYOTA794
)
200 printk("TOYOTA794 ");
203 if (type
& ZARLINK456
)
204 printk("ZARLINK456 ");
214 printk("HAS_IF_%d ", int_freq
);
217 static v4l2_std_id
parse_audio_std_option(void)
219 if (strcasecmp(audio_std
, "A2") == 0)
221 if (strcasecmp(audio_std
, "A2/A") == 0)
222 return V4L2_STD_A2_A
;
223 if (strcasecmp(audio_std
, "A2/B") == 0)
224 return V4L2_STD_A2_B
;
225 if (strcasecmp(audio_std
, "NICAM") == 0)
226 return V4L2_STD_NICAM
;
227 if (strcasecmp(audio_std
, "NICAM/A") == 0)
228 return V4L2_STD_NICAM_A
;
229 if (strcasecmp(audio_std
, "NICAM/B") == 0)
230 return V4L2_STD_NICAM_B
;
235 static void free_firmware(struct xc2028_data
*priv
)
238 tuner_dbg("%s called\n", __func__
);
243 for (i
= 0; i
< priv
->firm_size
; i
++)
244 kfree(priv
->firm
[i
].ptr
);
251 memset(&priv
->cur_fw
, 0, sizeof(priv
->cur_fw
));
254 static int load_all_firmwares(struct dvb_frontend
*fe
)
256 struct xc2028_data
*priv
= fe
->tuner_priv
;
257 const struct firmware
*fw
= NULL
;
258 const unsigned char *p
, *endp
;
264 tuner_dbg("%s called\n", __func__
);
266 if (!firmware_name
[0])
267 fname
= priv
->ctrl
.fname
;
269 fname
= firmware_name
;
271 tuner_dbg("Reading firmware %s\n", fname
);
272 rc
= request_firmware(&fw
, fname
, &priv
->i2c_props
.adap
->dev
);
275 tuner_err("Error: firmware %s not found.\n",
278 tuner_err("Error %d while requesting firmware %s \n",
286 if (fw
->size
< sizeof(name
) - 1 + 2 + 2) {
287 tuner_err("Error: firmware file %s has invalid size!\n",
292 memcpy(name
, p
, sizeof(name
) - 1);
293 name
[sizeof(name
) - 1] = 0;
294 p
+= sizeof(name
) - 1;
296 priv
->firm_version
= get_unaligned_le16(p
);
299 n_array
= get_unaligned_le16(p
);
302 tuner_info("Loading %d firmware images from %s, type: %s, ver %d.%d\n",
303 n_array
, fname
, name
,
304 priv
->firm_version
>> 8, priv
->firm_version
& 0xff);
306 priv
->firm
= kzalloc(sizeof(*priv
->firm
) * n_array
, GFP_KERNEL
);
307 if (priv
->firm
== NULL
) {
308 tuner_err("Not enough memory to load firmware file.\n");
312 priv
->firm_size
= n_array
;
322 tuner_err("More firmware images in file than "
327 /* Checks if there's enough bytes to read */
328 if (endp
- p
< sizeof(type
) + sizeof(id
) + sizeof(size
))
331 type
= get_unaligned_le32(p
);
334 id
= get_unaligned_le64(p
);
338 int_freq
= get_unaligned_le16(p
);
339 p
+= sizeof(int_freq
);
340 if (endp
- p
< sizeof(size
))
344 size
= get_unaligned_le32(p
);
347 if (!size
|| size
> endp
- p
) {
348 tuner_err("Firmware type ");
349 dump_firm_type(type
);
350 printk("(%x), id %llx is corrupted "
351 "(size=%d, expected %d)\n",
352 type
, (unsigned long long)id
,
353 (unsigned)(endp
- p
), size
);
357 priv
->firm
[n
].ptr
= kzalloc(size
, GFP_KERNEL
);
358 if (priv
->firm
[n
].ptr
== NULL
) {
359 tuner_err("Not enough memory to load firmware file.\n");
363 tuner_dbg("Reading firmware type ");
365 dump_firm_type_and_int_freq(type
, int_freq
);
366 printk("(%x), id %llx, size=%d.\n",
367 type
, (unsigned long long)id
, size
);
370 memcpy(priv
->firm
[n
].ptr
, p
, size
);
371 priv
->firm
[n
].type
= type
;
372 priv
->firm
[n
].id
= id
;
373 priv
->firm
[n
].size
= size
;
374 priv
->firm
[n
].int_freq
= int_freq
;
379 if (n
+ 1 != priv
->firm_size
) {
380 tuner_err("Firmware file is incomplete!\n");
387 tuner_err("Firmware header is incomplete!\n");
390 tuner_err("Error: firmware file is corrupted!\n");
393 tuner_info("Releasing partially loaded firmware file.\n");
397 release_firmware(fw
);
399 tuner_dbg("Firmware files loaded.\n");
404 static int seek_firmware(struct dvb_frontend
*fe
, unsigned int type
,
407 struct xc2028_data
*priv
= fe
->tuner_priv
;
408 int i
, best_i
= -1, best_nr_matches
= 0;
409 unsigned int type_mask
= 0;
411 tuner_dbg("%s called, want type=", __func__
);
413 dump_firm_type(type
);
414 printk("(%x), id %016llx.\n", type
, (unsigned long long)*id
);
418 tuner_err("Error! firmware not loaded\n");
422 if (((type
& ~SCODE
) == 0) && (*id
== 0))
426 type_mask
= BASE_TYPES
;
427 else if (type
& SCODE
) {
429 type_mask
= SCODE_TYPES
& ~HAS_IF
;
430 } else if (type
& DTV_TYPES
)
431 type_mask
= DTV_TYPES
;
432 else if (type
& STD_SPECIFIC_TYPES
)
433 type_mask
= STD_SPECIFIC_TYPES
;
440 /* Seek for exact match */
441 for (i
= 0; i
< priv
->firm_size
; i
++) {
442 if ((type
== (priv
->firm
[i
].type
& type_mask
)) &&
443 (*id
== priv
->firm
[i
].id
))
447 /* Seek for generic video standard match */
448 for (i
= 0; i
< priv
->firm_size
; i
++) {
449 v4l2_std_id match_mask
;
452 if (type
!= (priv
->firm
[i
].type
& type_mask
))
455 match_mask
= *id
& priv
->firm
[i
].id
;
459 if ((*id
& match_mask
) == *id
)
460 goto found
; /* Supports all the requested standards */
462 nr_matches
= hweight64(match_mask
);
463 if (nr_matches
> best_nr_matches
) {
464 best_nr_matches
= nr_matches
;
469 if (best_nr_matches
> 0) {
470 tuner_dbg("Selecting best matching firmware (%d bits) for "
471 "type=", best_nr_matches
);
472 dump_firm_type(type
);
473 printk("(%x), id %016llx:\n", type
, (unsigned long long)*id
);
478 /*FIXME: Would make sense to seek for type "hint" match ? */
484 *id
= priv
->firm
[i
].id
;
487 tuner_dbg("%s firmware for type=", (i
< 0) ? "Can't find" : "Found");
489 dump_firm_type(type
);
490 printk("(%x), id %016llx.\n", type
, (unsigned long long)*id
);
495 static int load_firmware(struct dvb_frontend
*fe
, unsigned int type
,
498 struct xc2028_data
*priv
= fe
->tuner_priv
;
500 unsigned char *p
, *endp
, buf
[priv
->ctrl
.max_len
];
502 tuner_dbg("%s called\n", __func__
);
504 pos
= seek_firmware(fe
, type
, id
);
508 tuner_info("Loading firmware for type=");
509 dump_firm_type(priv
->firm
[pos
].type
);
510 printk("(%x), id %016llx.\n", priv
->firm
[pos
].type
,
511 (unsigned long long)*id
);
513 p
= priv
->firm
[pos
].ptr
;
514 endp
= p
+ priv
->firm
[pos
].size
;
519 /* Checks if there's enough bytes to read */
520 if (p
+ sizeof(size
) > endp
) {
521 tuner_err("Firmware chunk size is wrong\n");
525 size
= le16_to_cpu(*(__u16
*) p
);
532 /* Special callback command received */
533 rc
= priv
->tuner_callback(priv
->video_dev
,
534 XC2028_TUNER_RESET
, 0);
536 tuner_err("Error at RESET code %d\n",
542 if (size
>= 0xff00) {
545 rc
= priv
->tuner_callback(priv
->video_dev
,
546 XC2028_RESET_CLK
, 0);
548 tuner_err("Error at RESET code %d\n",
554 tuner_info("Invalid RESET code %d\n",
562 /* Checks for a sleep command */
564 msleep(size
& 0x7fff);
568 if ((size
+ p
> endp
)) {
569 tuner_err("missing bytes: need %d, have %d\n",
570 size
, (int)(endp
- p
));
578 /* Sends message chunks */
580 int len
= (size
< priv
->ctrl
.max_len
- 1) ?
581 size
: priv
->ctrl
.max_len
- 1;
583 memcpy(buf
+ 1, p
, len
);
585 rc
= i2c_send(priv
, buf
, len
+ 1);
587 tuner_err("%d returned from send\n", rc
);
598 static int load_scode(struct dvb_frontend
*fe
, unsigned int type
,
599 v4l2_std_id
*id
, __u16 int_freq
, int scode
)
601 struct xc2028_data
*priv
= fe
->tuner_priv
;
605 tuner_dbg("%s called\n", __func__
);
608 pos
= seek_firmware(fe
, type
, id
);
612 for (pos
= 0; pos
< priv
->firm_size
; pos
++) {
613 if ((priv
->firm
[pos
].int_freq
== int_freq
) &&
614 (priv
->firm
[pos
].type
& HAS_IF
))
617 if (pos
== priv
->firm_size
)
621 p
= priv
->firm
[pos
].ptr
;
623 if (priv
->firm
[pos
].type
& HAS_IF
) {
624 if (priv
->firm
[pos
].size
!= 12 * 16 || scode
>= 16)
628 /* 16 SCODE entries per file; each SCODE entry is 12 bytes and
629 * has a 2-byte size header in the firmware format. */
630 if (priv
->firm
[pos
].size
!= 14 * 16 || scode
>= 16 ||
631 le16_to_cpu(*(__u16
*)(p
+ 14 * scode
)) != 12)
636 tuner_info("Loading SCODE for type=");
637 dump_firm_type_and_int_freq(priv
->firm
[pos
].type
,
638 priv
->firm
[pos
].int_freq
);
639 printk("(%x), id %016llx.\n", priv
->firm
[pos
].type
,
640 (unsigned long long)*id
);
642 if (priv
->firm_version
< 0x0202)
643 rc
= send_seq(priv
, {0x20, 0x00, 0x00, 0x00});
645 rc
= send_seq(priv
, {0xa0, 0x00, 0x00, 0x00});
649 rc
= i2c_send(priv
, p
, 12);
653 rc
= send_seq(priv
, {0x00, 0x8c});
660 static int check_firmware(struct dvb_frontend
*fe
, unsigned int type
,
661 v4l2_std_id std
, __u16 int_freq
)
663 struct xc2028_data
*priv
= fe
->tuner_priv
;
664 struct firmware_properties new_fw
;
665 int rc
= 0, is_retry
= 0;
666 u16 version
, hwmodel
;
669 tuner_dbg("%s called\n", __func__
);
672 if (!priv
->ctrl
.fname
) {
673 tuner_info("xc2028/3028 firmware name not set!\n");
677 rc
= load_all_firmwares(fe
);
682 if (priv
->ctrl
.mts
&& !(type
& FM
))
688 new_fw
.std_req
= std
;
689 new_fw
.scode_table
= SCODE
| priv
->ctrl
.scode_table
;
691 new_fw
.int_freq
= int_freq
;
693 tuner_dbg("checking firmware, user requested type=");
695 dump_firm_type(new_fw
.type
);
696 printk("(%x), id %016llx, ", new_fw
.type
,
697 (unsigned long long)new_fw
.std_req
);
699 printk("scode_tbl ");
700 dump_firm_type(priv
->ctrl
.scode_table
);
701 printk("(%x), ", priv
->ctrl
.scode_table
);
703 printk("int_freq %d, ", new_fw
.int_freq
);
704 printk("scode_nr %d\n", new_fw
.scode_nr
);
707 /* No need to reload base firmware if it matches */
708 if (((BASE
| new_fw
.type
) & BASE_TYPES
) ==
709 (priv
->cur_fw
.type
& BASE_TYPES
)) {
710 tuner_dbg("BASE firmware not changed.\n");
714 /* Updating BASE - forget about all currently loaded firmware */
715 memset(&priv
->cur_fw
, 0, sizeof(priv
->cur_fw
));
717 /* Reset is needed before loading firmware */
718 rc
= priv
->tuner_callback(priv
->video_dev
,
719 XC2028_TUNER_RESET
, 0);
723 /* BASE firmwares are all std0 */
725 rc
= load_firmware(fe
, BASE
| new_fw
.type
, &std0
);
727 tuner_err("Error %d while loading base firmware\n",
732 /* Load INIT1, if needed */
733 tuner_dbg("Load init1 firmware, if exists\n");
735 rc
= load_firmware(fe
, BASE
| INIT1
| new_fw
.type
, &std0
);
737 rc
= load_firmware(fe
, (BASE
| INIT1
| new_fw
.type
) & ~F8MHZ
,
739 if (rc
< 0 && rc
!= -ENOENT
) {
740 tuner_err("Error %d while loading init1 firmware\n",
747 * No need to reload standard specific firmware if base firmware
748 * was not reloaded and requested video standards have not changed.
750 if (priv
->cur_fw
.type
== (BASE
| new_fw
.type
) &&
751 priv
->cur_fw
.std_req
== std
) {
752 tuner_dbg("Std-specific firmware already loaded.\n");
753 goto skip_std_specific
;
756 /* Reloading std-specific firmware forces a SCODE update */
757 priv
->cur_fw
.scode_table
= 0;
759 rc
= load_firmware(fe
, new_fw
.type
, &new_fw
.id
);
761 rc
= load_firmware(fe
, new_fw
.type
& ~F8MHZ
, &new_fw
.id
);
767 if (priv
->cur_fw
.scode_table
== new_fw
.scode_table
&&
768 priv
->cur_fw
.scode_nr
== new_fw
.scode_nr
) {
769 tuner_dbg("SCODE firmware already loaded.\n");
773 if (new_fw
.type
& FM
)
776 /* Load SCODE firmware, if exists */
777 tuner_dbg("Trying to load scode %d\n", new_fw
.scode_nr
);
779 rc
= load_scode(fe
, new_fw
.type
| new_fw
.scode_table
, &new_fw
.id
,
780 new_fw
.int_freq
, new_fw
.scode_nr
);
783 if (xc2028_get_reg(priv
, 0x0004, &version
) < 0 ||
784 xc2028_get_reg(priv
, 0x0008, &hwmodel
) < 0) {
785 tuner_err("Unable to read tuner registers.\n");
789 tuner_dbg("Device is Xceive %d version %d.%d, "
790 "firmware version %d.%d\n",
791 hwmodel
, (version
& 0xf000) >> 12, (version
& 0xf00) >> 8,
792 (version
& 0xf0) >> 4, version
& 0xf);
794 /* Check firmware version against what we downloaded. */
795 if (priv
->firm_version
!= ((version
& 0xf0) << 4 | (version
& 0x0f))) {
796 tuner_err("Incorrect readback of firmware version.\n");
800 /* Check that the tuner hardware model remains consistent over time. */
801 if (priv
->hwmodel
== 0 && (hwmodel
== 2028 || hwmodel
== 3028)) {
802 priv
->hwmodel
= hwmodel
;
803 priv
->hwvers
= version
& 0xff00;
804 } else if (priv
->hwmodel
== 0 || priv
->hwmodel
!= hwmodel
||
805 priv
->hwvers
!= (version
& 0xff00)) {
806 tuner_err("Read invalid device hardware information - tuner "
811 memcpy(&priv
->cur_fw
, &new_fw
, sizeof(priv
->cur_fw
));
814 * By setting BASE in cur_fw.type only after successfully loading all
816 * 1. Identify that BASE firmware with type=0 has been loaded;
817 * 2. Tell whether BASE firmware was just changed the next time through.
819 priv
->cur_fw
.type
|= BASE
;
824 memset(&priv
->cur_fw
, 0, sizeof(priv
->cur_fw
));
828 tuner_dbg("Retrying firmware load\n");
837 static int xc2028_signal(struct dvb_frontend
*fe
, u16
*strength
)
839 struct xc2028_data
*priv
= fe
->tuner_priv
;
840 u16 frq_lock
, signal
= 0;
843 tuner_dbg("%s called\n", __func__
);
845 mutex_lock(&priv
->lock
);
847 /* Sync Lock Indicator */
848 rc
= xc2028_get_reg(priv
, 0x0002, &frq_lock
);
852 /* Frequency is locked */
856 /* Get SNR of the video signal */
857 rc
= xc2028_get_reg(priv
, 0x0040, &signal
);
861 /* Use both frq_lock and signal to generate the result */
862 signal
= signal
|| ((signal
& 0x07) << 12);
865 mutex_unlock(&priv
->lock
);
869 tuner_dbg("signal strength is %d\n", signal
);
876 static int generic_set_freq(struct dvb_frontend
*fe
, u32 freq
/* in HZ */,
877 enum tuner_mode new_mode
,
882 struct xc2028_data
*priv
= fe
->tuner_priv
;
884 unsigned char buf
[4];
887 tuner_dbg("%s called\n", __func__
);
889 mutex_lock(&priv
->lock
);
891 tuner_dbg("should set frequency %d kHz\n", freq
/ 1000);
893 if (check_firmware(fe
, type
, std
, int_freq
) < 0)
896 /* On some cases xc2028 can disable video output, if
897 * very weak signals are received. By sending a soft
898 * reset, this is re-enabled. So, it is better to always
899 * send a soft reset before changing channels, to be sure
900 * that xc2028 will be in a safe state.
901 * Maybe this might also be needed for DTV.
903 if (new_mode
== T_ANALOG_TV
) {
904 rc
= send_seq(priv
, {0x00, 0x00});
905 } else if (priv
->cur_fw
.type
& ATSC
) {
910 * We must adjust the offset by 500kHz in two cases in order
911 * to correctly center the IF output:
912 * 1) When the ZARLINK456 or DIBCOM52 tables were explicitly
913 * selected and a 7MHz channel is tuned;
914 * 2) When tuning a VHF channel with DTV78 firmware.
916 if (((priv
->cur_fw
.type
& DTV7
) &&
917 (priv
->cur_fw
.scode_table
& (ZARLINK456
| DIBCOM52
))) ||
918 ((priv
->cur_fw
.type
& DTV78
) && freq
< 470000000))
922 div
= (freq
- offset
+ DIV
/ 2) / DIV
;
924 /* CMD= Set frequency */
925 if (priv
->firm_version
< 0x0202)
926 rc
= send_seq(priv
, {0x00, 0x02, 0x00, 0x00});
928 rc
= send_seq(priv
, {0x80, 0x02, 0x00, 0x00});
932 /* Return code shouldn't be checked.
933 The reset CLK is needed only with tm6000.
934 Driver should work fine even if this fails.
936 priv
->tuner_callback(priv
->video_dev
, XC2028_RESET_CLK
, 1);
940 buf
[0] = 0xff & (div
>> 24);
941 buf
[1] = 0xff & (div
>> 16);
942 buf
[2] = 0xff & (div
>> 8);
943 buf
[3] = 0xff & (div
);
945 rc
= i2c_send(priv
, buf
, sizeof(buf
));
950 priv
->frequency
= freq
;
952 tuner_dbg("divisor= %02x %02x %02x %02x (freq=%d.%03d)\n",
953 buf
[0], buf
[1], buf
[2], buf
[3],
954 freq
/ 1000000, (freq
% 1000000) / 1000);
959 mutex_unlock(&priv
->lock
);
964 static int xc2028_set_analog_freq(struct dvb_frontend
*fe
,
965 struct analog_parameters
*p
)
967 struct xc2028_data
*priv
= fe
->tuner_priv
;
970 tuner_dbg("%s called\n", __func__
);
972 if (p
->mode
== V4L2_TUNER_RADIO
) {
974 if (priv
->ctrl
.input1
)
976 return generic_set_freq(fe
, (625l * p
->frequency
) / 10,
977 T_ANALOG_TV
, type
, 0, 0);
980 /* if std is not defined, choose one */
982 p
->std
= V4L2_STD_MN
;
984 /* PAL/M, PAL/N, PAL/Nc and NTSC variants should use 6MHz firmware */
985 if (!(p
->std
& V4L2_STD_MN
))
988 /* Add audio hack to std mask */
989 p
->std
|= parse_audio_std_option();
991 return generic_set_freq(fe
, 62500l * p
->frequency
,
992 T_ANALOG_TV
, type
, p
->std
, 0);
995 static int xc2028_set_params(struct dvb_frontend
*fe
,
996 struct dvb_frontend_parameters
*p
)
998 struct xc2028_data
*priv
= fe
->tuner_priv
;
1000 fe_bandwidth_t bw
= BANDWIDTH_8_MHZ
;
1003 tuner_dbg("%s called\n", __func__
);
1005 if (priv
->ctrl
.d2633
)
1010 switch(fe
->ops
.info
.type
) {
1012 bw
= p
->u
.ofdm
.bandwidth
;
1015 tuner_info("WARN: There are some reports that "
1016 "QAM 6 MHz doesn't work.\n"
1017 "If this works for you, please report by "
1018 "e-mail to: v4l-dvb-maintainer@linuxtv.org\n");
1019 bw
= BANDWIDTH_6_MHZ
;
1023 bw
= BANDWIDTH_6_MHZ
;
1024 /* The only ATSC firmware (at least on v2.7) is D2633,
1025 so overrides ctrl->d2633 */
1026 type
|= ATSC
| D2633
;
1029 /* DVB-S is not supported */
1035 case BANDWIDTH_8_MHZ
:
1036 if (p
->frequency
< 470000000)
1037 priv
->ctrl
.vhfbw7
= 0;
1039 priv
->ctrl
.uhfbw8
= 1;
1040 type
|= (priv
->ctrl
.vhfbw7
&& priv
->ctrl
.uhfbw8
) ? DTV78
: DTV8
;
1043 case BANDWIDTH_7_MHZ
:
1044 if (p
->frequency
< 470000000)
1045 priv
->ctrl
.vhfbw7
= 1;
1047 priv
->ctrl
.uhfbw8
= 0;
1048 type
|= (priv
->ctrl
.vhfbw7
&& priv
->ctrl
.uhfbw8
) ? DTV78
: DTV7
;
1051 case BANDWIDTH_6_MHZ
:
1053 priv
->ctrl
.vhfbw7
= 0;
1054 priv
->ctrl
.uhfbw8
= 0;
1057 tuner_err("error: bandwidth not supported.\n");
1060 /* All S-code tables need a 200kHz shift */
1061 if (priv
->ctrl
.demod
)
1062 demod
= priv
->ctrl
.demod
+ 200;
1064 return generic_set_freq(fe
, p
->frequency
,
1065 T_DIGITAL_TV
, type
, 0, demod
);
1069 static int xc2028_dvb_release(struct dvb_frontend
*fe
)
1071 struct xc2028_data
*priv
= fe
->tuner_priv
;
1073 tuner_dbg("%s called\n", __func__
);
1075 mutex_lock(&xc2028_list_mutex
);
1077 /* only perform final cleanup if this is the last instance */
1078 if (hybrid_tuner_report_instance_count(priv
) == 1) {
1079 kfree(priv
->ctrl
.fname
);
1080 free_firmware(priv
);
1084 hybrid_tuner_release_state(priv
);
1086 mutex_unlock(&xc2028_list_mutex
);
1088 fe
->tuner_priv
= NULL
;
1093 static int xc2028_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
1095 struct xc2028_data
*priv
= fe
->tuner_priv
;
1097 tuner_dbg("%s called\n", __func__
);
1099 *frequency
= priv
->frequency
;
1104 static int xc2028_set_config(struct dvb_frontend
*fe
, void *priv_cfg
)
1106 struct xc2028_data
*priv
= fe
->tuner_priv
;
1107 struct xc2028_ctrl
*p
= priv_cfg
;
1110 tuner_dbg("%s called\n", __func__
);
1112 mutex_lock(&priv
->lock
);
1114 memcpy(&priv
->ctrl
, p
, sizeof(priv
->ctrl
));
1115 if (priv
->ctrl
.max_len
< 9)
1116 priv
->ctrl
.max_len
= 13;
1119 if (priv
->ctrl
.fname
&& strcmp(p
->fname
, priv
->ctrl
.fname
)) {
1120 kfree(priv
->ctrl
.fname
);
1121 free_firmware(priv
);
1124 priv
->ctrl
.fname
= kstrdup(p
->fname
, GFP_KERNEL
);
1125 if (priv
->ctrl
.fname
== NULL
)
1129 mutex_unlock(&priv
->lock
);
1134 static const struct dvb_tuner_ops xc2028_dvb_tuner_ops
= {
1136 .name
= "Xceive XC3028",
1137 .frequency_min
= 42000000,
1138 .frequency_max
= 864000000,
1139 .frequency_step
= 50000,
1142 .set_config
= xc2028_set_config
,
1143 .set_analog_params
= xc2028_set_analog_freq
,
1144 .release
= xc2028_dvb_release
,
1145 .get_frequency
= xc2028_get_frequency
,
1146 .get_rf_strength
= xc2028_signal
,
1147 .set_params
= xc2028_set_params
,
1150 struct dvb_frontend
*xc2028_attach(struct dvb_frontend
*fe
,
1151 struct xc2028_config
*cfg
)
1153 struct xc2028_data
*priv
;
1157 printk(KERN_DEBUG
"xc2028: Xcv2028/3028 init called!\n");
1163 printk(KERN_ERR
"xc2028: No frontend!\n");
1167 mutex_lock(&xc2028_list_mutex
);
1169 instance
= hybrid_tuner_request_state(struct xc2028_data
, priv
,
1170 hybrid_tuner_instance_list
,
1171 cfg
->i2c_adap
, cfg
->i2c_addr
,
1175 /* memory allocation failure */
1179 /* new tuner instance */
1180 priv
->tuner_callback
= cfg
->callback
;
1181 priv
->ctrl
.max_len
= 13;
1183 mutex_init(&priv
->lock
);
1185 /* analog side (tuner-core) uses i2c_adap->algo_data.
1186 * digital side is not guaranteed to have algo_data defined.
1188 * digital side will always have fe->dvb defined.
1189 * analog side (tuner-core) doesn't (yet) define fe->dvb.
1191 priv
->video_dev
= ((fe
->dvb
) && (fe
->dvb
->priv
)) ?
1192 fe
->dvb
->priv
: cfg
->i2c_adap
->algo_data
;
1194 fe
->tuner_priv
= priv
;
1197 /* existing tuner instance */
1198 fe
->tuner_priv
= priv
;
1202 memcpy(&fe
->ops
.tuner_ops
, &xc2028_dvb_tuner_ops
,
1203 sizeof(xc2028_dvb_tuner_ops
));
1205 tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner");
1208 xc2028_set_config(fe
, cfg
->ctrl
);
1210 mutex_unlock(&xc2028_list_mutex
);
1214 mutex_unlock(&xc2028_list_mutex
);
1216 xc2028_dvb_release(fe
);
1220 EXPORT_SYMBOL(xc2028_attach
);
1222 MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver");
1223 MODULE_AUTHOR("Michel Ludwig <michel.ludwig@gmail.com>");
1224 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
1225 MODULE_LICENSE("GPL");