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;
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 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", __func__, 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 static 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)
235 tuner_dbg("%s called\n", __func__);
240 for (i = 0; i < priv->firm_size; i++)
241 kfree(priv->firm[i].ptr);
248 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
251 static int load_all_firmwares(struct dvb_frontend *fe)
253 struct xc2028_data *priv = fe->tuner_priv;
254 const struct firmware *fw = NULL;
255 const unsigned char *p, *endp;
261 tuner_dbg("%s called\n", __func__);
263 if (!firmware_name[0])
264 fname = priv->ctrl.fname;
266 fname = firmware_name;
268 tuner_dbg("Reading firmware %s\n", fname);
269 rc = request_firmware(&fw, fname, &priv->i2c_props.adap->dev);
272 tuner_err("Error: firmware %s not found.\n",
275 tuner_err("Error %d while requesting firmware %s \n",
283 if (fw->size < sizeof(name) - 1 + 2 + 2) {
284 tuner_err("Error: firmware file %s has invalid size!\n",
289 memcpy(name, p, sizeof(name) - 1);
290 name[sizeof(name) - 1] = 0;
291 p += sizeof(name) - 1;
293 priv->firm_version = get_unaligned_le16(p);
296 n_array = get_unaligned_le16(p);
299 tuner_info("Loading %d firmware images from %s, type: %s, ver %d.%d\n",
300 n_array, fname, name,
301 priv->firm_version >> 8, priv->firm_version & 0xff);
303 priv->firm = kzalloc(sizeof(*priv->firm) * n_array, GFP_KERNEL);
304 if (priv->firm == NULL) {
305 tuner_err("Not enough memory to load firmware file.\n");
309 priv->firm_size = n_array;
319 tuner_err("More firmware images in file than "
324 /* Checks if there's enough bytes to read */
325 if (endp - p < sizeof(type) + sizeof(id) + sizeof(size))
328 type = get_unaligned_le32(p);
331 id = get_unaligned_le64(p);
335 int_freq = get_unaligned_le16(p);
336 p += sizeof(int_freq);
337 if (endp - p < sizeof(size))
341 size = get_unaligned_le32(p);
344 if (!size || size > endp - p) {
345 tuner_err("Firmware type ");
346 dump_firm_type(type);
347 printk("(%x), id %llx is corrupted "
348 "(size=%d, expected %d)\n",
349 type, (unsigned long long)id,
350 (unsigned)(endp - p), size);
354 priv->firm[n].ptr = kzalloc(size, GFP_KERNEL);
355 if (priv->firm[n].ptr == NULL) {
356 tuner_err("Not enough memory to load firmware file.\n");
360 tuner_dbg("Reading firmware type ");
362 dump_firm_type_and_int_freq(type, int_freq);
363 printk("(%x), id %llx, size=%d.\n",
364 type, (unsigned long long)id, size);
367 memcpy(priv->firm[n].ptr, p, size);
368 priv->firm[n].type = type;
369 priv->firm[n].id = id;
370 priv->firm[n].size = size;
371 priv->firm[n].int_freq = int_freq;
376 if (n + 1 != priv->firm_size) {
377 tuner_err("Firmware file is incomplete!\n");
384 tuner_err("Firmware header is incomplete!\n");
387 tuner_err("Error: firmware file is corrupted!\n");
390 tuner_info("Releasing partially loaded firmware file.\n");
394 release_firmware(fw);
396 tuner_dbg("Firmware files loaded.\n");
401 static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
404 struct xc2028_data *priv = fe->tuner_priv;
405 int i, best_i = -1, best_nr_matches = 0;
406 unsigned int type_mask = 0;
408 tuner_dbg("%s called, want type=", __func__);
410 dump_firm_type(type);
411 printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
415 tuner_err("Error! firmware not loaded\n");
419 if (((type & ~SCODE) == 0) && (*id == 0))
423 type_mask = BASE_TYPES;
424 else if (type & SCODE) {
426 type_mask = SCODE_TYPES & ~HAS_IF;
427 } else if (type & DTV_TYPES)
428 type_mask = DTV_TYPES;
429 else if (type & STD_SPECIFIC_TYPES)
430 type_mask = STD_SPECIFIC_TYPES;
437 /* Seek for exact match */
438 for (i = 0; i < priv->firm_size; i++) {
439 if ((type == (priv->firm[i].type & type_mask)) &&
440 (*id == priv->firm[i].id))
444 /* Seek for generic video standard match */
445 for (i = 0; i < priv->firm_size; i++) {
446 v4l2_std_id match_mask;
449 if (type != (priv->firm[i].type & type_mask))
452 match_mask = *id & priv->firm[i].id;
456 if ((*id & match_mask) == *id)
457 goto found; /* Supports all the requested standards */
459 nr_matches = hweight64(match_mask);
460 if (nr_matches > best_nr_matches) {
461 best_nr_matches = nr_matches;
466 if (best_nr_matches > 0) {
467 tuner_dbg("Selecting best matching firmware (%d bits) for "
468 "type=", best_nr_matches);
469 dump_firm_type(type);
470 printk("(%x), id %016llx:\n", type, (unsigned long long)*id);
475 /*FIXME: Would make sense to seek for type "hint" match ? */
481 *id = priv->firm[i].id;
484 tuner_dbg("%s firmware for type=", (i < 0) ? "Can't find" : "Found");
486 dump_firm_type(type);
487 printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
492 static inline int do_tuner_callback(struct dvb_frontend *fe, int cmd, int arg)
494 struct xc2028_data *priv = fe->tuner_priv;
496 /* analog side (tuner-core) uses i2c_adap->algo_data.
497 * digital side is not guaranteed to have algo_data defined.
499 * digital side will always have fe->dvb defined.
500 * analog side (tuner-core) doesn't (yet) define fe->dvb.
503 return (!fe->callback) ? -EINVAL :
504 fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
505 fe->dvb->priv : priv->i2c_props.adap->algo_data,
506 DVB_FRONTEND_COMPONENT_TUNER, cmd, arg);
509 static int load_firmware(struct dvb_frontend *fe, unsigned int type,
512 struct xc2028_data *priv = fe->tuner_priv;
514 unsigned char *p, *endp, buf[priv->ctrl.max_len];
516 tuner_dbg("%s called\n", __func__);
518 pos = seek_firmware(fe, type, id);
522 tuner_info("Loading firmware for type=");
523 dump_firm_type(priv->firm[pos].type);
524 printk("(%x), id %016llx.\n", priv->firm[pos].type,
525 (unsigned long long)*id);
527 p = priv->firm[pos].ptr;
528 endp = p + priv->firm[pos].size;
533 /* Checks if there's enough bytes to read */
534 if (p + sizeof(size) > endp) {
535 tuner_err("Firmware chunk size is wrong\n");
539 size = le16_to_cpu(*(__u16 *) p);
546 /* Special callback command received */
547 rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0);
549 tuner_err("Error at RESET code %d\n",
555 if (size >= 0xff00) {
558 rc = do_tuner_callback(fe, XC2028_RESET_CLK, 0);
560 tuner_err("Error at RESET code %d\n",
566 tuner_info("Invalid RESET code %d\n",
574 /* Checks for a sleep command */
576 msleep(size & 0x7fff);
580 if ((size + p > endp)) {
581 tuner_err("missing bytes: need %d, have %d\n",
582 size, (int)(endp - p));
590 /* Sends message chunks */
592 int len = (size < priv->ctrl.max_len - 1) ?
593 size : priv->ctrl.max_len - 1;
595 memcpy(buf + 1, p, len);
597 rc = i2c_send(priv, buf, len + 1);
599 tuner_err("%d returned from send\n", rc);
610 static int load_scode(struct dvb_frontend *fe, unsigned int type,
611 v4l2_std_id *id, __u16 int_freq, int scode)
613 struct xc2028_data *priv = fe->tuner_priv;
617 tuner_dbg("%s called\n", __func__);
620 pos = seek_firmware(fe, type, id);
624 for (pos = 0; pos < priv->firm_size; pos++) {
625 if ((priv->firm[pos].int_freq == int_freq) &&
626 (priv->firm[pos].type & HAS_IF))
629 if (pos == priv->firm_size)
633 p = priv->firm[pos].ptr;
635 if (priv->firm[pos].type & HAS_IF) {
636 if (priv->firm[pos].size != 12 * 16 || scode >= 16)
640 /* 16 SCODE entries per file; each SCODE entry is 12 bytes and
641 * has a 2-byte size header in the firmware format. */
642 if (priv->firm[pos].size != 14 * 16 || scode >= 16 ||
643 le16_to_cpu(*(__u16 *)(p + 14 * scode)) != 12)
648 tuner_info("Loading SCODE for type=");
649 dump_firm_type_and_int_freq(priv->firm[pos].type,
650 priv->firm[pos].int_freq);
651 printk("(%x), id %016llx.\n", priv->firm[pos].type,
652 (unsigned long long)*id);
654 if (priv->firm_version < 0x0202)
655 rc = send_seq(priv, {0x20, 0x00, 0x00, 0x00});
657 rc = send_seq(priv, {0xa0, 0x00, 0x00, 0x00});
661 rc = i2c_send(priv, p, 12);
665 rc = send_seq(priv, {0x00, 0x8c});
672 static int check_firmware(struct dvb_frontend *fe, unsigned int type,
673 v4l2_std_id std, __u16 int_freq)
675 struct xc2028_data *priv = fe->tuner_priv;
676 struct firmware_properties new_fw;
677 int rc = 0, is_retry = 0;
678 u16 version, hwmodel;
681 tuner_dbg("%s called\n", __func__);
684 if (!priv->ctrl.fname) {
685 tuner_info("xc2028/3028 firmware name not set!\n");
689 rc = load_all_firmwares(fe);
694 if (priv->ctrl.mts && !(type & FM))
700 new_fw.std_req = std;
701 new_fw.scode_table = SCODE | priv->ctrl.scode_table;
703 new_fw.int_freq = int_freq;
705 tuner_dbg("checking firmware, user requested type=");
707 dump_firm_type(new_fw.type);
708 printk("(%x), id %016llx, ", new_fw.type,
709 (unsigned long long)new_fw.std_req);
711 printk("scode_tbl ");
712 dump_firm_type(priv->ctrl.scode_table);
713 printk("(%x), ", priv->ctrl.scode_table);
715 printk("int_freq %d, ", new_fw.int_freq);
716 printk("scode_nr %d\n", new_fw.scode_nr);
719 /* No need to reload base firmware if it matches */
720 if (((BASE | new_fw.type) & BASE_TYPES) ==
721 (priv->cur_fw.type & BASE_TYPES)) {
722 tuner_dbg("BASE firmware not changed.\n");
726 /* Updating BASE - forget about all currently loaded firmware */
727 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
729 /* Reset is needed before loading firmware */
730 rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0);
734 /* BASE firmwares are all std0 */
736 rc = load_firmware(fe, BASE | new_fw.type, &std0);
738 tuner_err("Error %d while loading base firmware\n",
743 /* Load INIT1, if needed */
744 tuner_dbg("Load init1 firmware, if exists\n");
746 rc = load_firmware(fe, BASE | INIT1 | new_fw.type, &std0);
748 rc = load_firmware(fe, (BASE | INIT1 | new_fw.type) & ~F8MHZ,
750 if (rc < 0 && rc != -ENOENT) {
751 tuner_err("Error %d while loading init1 firmware\n",
758 * No need to reload standard specific firmware if base firmware
759 * was not reloaded and requested video standards have not changed.
761 if (priv->cur_fw.type == (BASE | new_fw.type) &&
762 priv->cur_fw.std_req == std) {
763 tuner_dbg("Std-specific firmware already loaded.\n");
764 goto skip_std_specific;
767 /* Reloading std-specific firmware forces a SCODE update */
768 priv->cur_fw.scode_table = 0;
770 rc = load_firmware(fe, new_fw.type, &new_fw.id);
772 rc = load_firmware(fe, new_fw.type & ~F8MHZ, &new_fw.id);
778 if (priv->cur_fw.scode_table == new_fw.scode_table &&
779 priv->cur_fw.scode_nr == new_fw.scode_nr) {
780 tuner_dbg("SCODE firmware already loaded.\n");
784 if (new_fw.type & FM)
787 /* Load SCODE firmware, if exists */
788 tuner_dbg("Trying to load scode %d\n", new_fw.scode_nr);
790 rc = load_scode(fe, new_fw.type | new_fw.scode_table, &new_fw.id,
791 new_fw.int_freq, new_fw.scode_nr);
794 if (xc2028_get_reg(priv, 0x0004, &version) < 0 ||
795 xc2028_get_reg(priv, 0x0008, &hwmodel) < 0) {
796 tuner_err("Unable to read tuner registers.\n");
800 tuner_dbg("Device is Xceive %d version %d.%d, "
801 "firmware version %d.%d\n",
802 hwmodel, (version & 0xf000) >> 12, (version & 0xf00) >> 8,
803 (version & 0xf0) >> 4, version & 0xf);
805 /* Check firmware version against what we downloaded. */
806 if (priv->firm_version != ((version & 0xf0) << 4 | (version & 0x0f))) {
807 tuner_err("Incorrect readback of firmware version.\n");
811 /* Check that the tuner hardware model remains consistent over time. */
812 if (priv->hwmodel == 0 && (hwmodel == 2028 || hwmodel == 3028)) {
813 priv->hwmodel = hwmodel;
814 priv->hwvers = version & 0xff00;
815 } else if (priv->hwmodel == 0 || priv->hwmodel != hwmodel ||
816 priv->hwvers != (version & 0xff00)) {
817 tuner_err("Read invalid device hardware information - tuner "
822 memcpy(&priv->cur_fw, &new_fw, sizeof(priv->cur_fw));
825 * By setting BASE in cur_fw.type only after successfully loading all
827 * 1. Identify that BASE firmware with type=0 has been loaded;
828 * 2. Tell whether BASE firmware was just changed the next time through.
830 priv->cur_fw.type |= BASE;
835 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
839 tuner_dbg("Retrying firmware load\n");
848 static int xc2028_signal(struct dvb_frontend *fe, u16 *strength)
850 struct xc2028_data *priv = fe->tuner_priv;
851 u16 frq_lock, signal = 0;
854 tuner_dbg("%s called\n", __func__);
856 mutex_lock(&priv->lock);
858 /* Sync Lock Indicator */
859 rc = xc2028_get_reg(priv, 0x0002, &frq_lock);
863 /* Frequency is locked */
867 /* Get SNR of the video signal */
868 rc = xc2028_get_reg(priv, 0x0040, &signal);
872 /* Use both frq_lock and signal to generate the result */
873 signal = signal || ((signal & 0x07) << 12);
876 mutex_unlock(&priv->lock);
880 tuner_dbg("signal strength is %d\n", signal);
887 static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
888 enum tuner_mode new_mode,
893 struct xc2028_data *priv = fe->tuner_priv;
895 unsigned char buf[4];
898 tuner_dbg("%s called\n", __func__);
900 mutex_lock(&priv->lock);
902 tuner_dbg("should set frequency %d kHz\n", freq / 1000);
904 if (check_firmware(fe, type, std, int_freq) < 0)
907 /* On some cases xc2028 can disable video output, if
908 * very weak signals are received. By sending a soft
909 * reset, this is re-enabled. So, it is better to always
910 * send a soft reset before changing channels, to be sure
911 * that xc2028 will be in a safe state.
912 * Maybe this might also be needed for DTV.
914 if (new_mode == T_ANALOG_TV) {
915 rc = send_seq(priv, {0x00, 0x00});
916 } else if (priv->cur_fw.type & ATSC) {
921 * We must adjust the offset by 500kHz in two cases in order
922 * to correctly center the IF output:
923 * 1) When the ZARLINK456 or DIBCOM52 tables were explicitly
924 * selected and a 7MHz channel is tuned;
925 * 2) When tuning a VHF channel with DTV78 firmware.
927 if (((priv->cur_fw.type & DTV7) &&
928 (priv->cur_fw.scode_table & (ZARLINK456 | DIBCOM52))) ||
929 ((priv->cur_fw.type & DTV78) && freq < 470000000))
933 div = (freq - offset + DIV / 2) / DIV;
935 /* CMD= Set frequency */
936 if (priv->firm_version < 0x0202)
937 rc = send_seq(priv, {0x00, 0x02, 0x00, 0x00});
939 rc = send_seq(priv, {0x80, 0x02, 0x00, 0x00});
943 /* Return code shouldn't be checked.
944 The reset CLK is needed only with tm6000.
945 Driver should work fine even if this fails.
947 do_tuner_callback(fe, XC2028_RESET_CLK, 1);
951 buf[0] = 0xff & (div >> 24);
952 buf[1] = 0xff & (div >> 16);
953 buf[2] = 0xff & (div >> 8);
954 buf[3] = 0xff & (div);
956 rc = i2c_send(priv, buf, sizeof(buf));
961 priv->frequency = freq;
963 tuner_dbg("divisor= %02x %02x %02x %02x (freq=%d.%03d)\n",
964 buf[0], buf[1], buf[2], buf[3],
965 freq / 1000000, (freq % 1000000) / 1000);
970 mutex_unlock(&priv->lock);
975 static int xc2028_set_analog_freq(struct dvb_frontend *fe,
976 struct analog_parameters *p)
978 struct xc2028_data *priv = fe->tuner_priv;
981 tuner_dbg("%s called\n", __func__);
983 if (p->mode == V4L2_TUNER_RADIO) {
985 if (priv->ctrl.input1)
987 return generic_set_freq(fe, (625l * p->frequency) / 10,
988 T_ANALOG_TV, type, 0, 0);
991 /* if std is not defined, choose one */
993 p->std = V4L2_STD_MN;
995 /* PAL/M, PAL/N, PAL/Nc and NTSC variants should use 6MHz firmware */
996 if (!(p->std & V4L2_STD_MN))
999 /* Add audio hack to std mask */
1000 p->std |= parse_audio_std_option();
1002 return generic_set_freq(fe, 62500l * p->frequency,
1003 T_ANALOG_TV, type, p->std, 0);
1006 static int xc2028_set_params(struct dvb_frontend *fe,
1007 struct dvb_frontend_parameters *p)
1009 struct xc2028_data *priv = fe->tuner_priv;
1010 unsigned int type=0;
1011 fe_bandwidth_t bw = BANDWIDTH_8_MHZ;
1014 tuner_dbg("%s called\n", __func__);
1016 switch(fe->ops.info.type) {
1018 bw = p->u.ofdm.bandwidth;
1021 tuner_info("WARN: There are some reports that "
1022 "QAM 6 MHz doesn't work.\n"
1023 "If this works for you, please report by "
1024 "e-mail to: v4l-dvb-maintainer@linuxtv.org\n");
1025 bw = BANDWIDTH_6_MHZ;
1029 bw = BANDWIDTH_6_MHZ;
1030 /* The only ATSC firmware (at least on v2.7) is D2633 */
1031 type |= ATSC | D2633;
1033 /* DVB-S is not supported */
1039 case BANDWIDTH_8_MHZ:
1040 if (p->frequency < 470000000)
1041 priv->ctrl.vhfbw7 = 0;
1043 priv->ctrl.uhfbw8 = 1;
1044 type |= (priv->ctrl.vhfbw7 && priv->ctrl.uhfbw8) ? DTV78 : DTV8;
1047 case BANDWIDTH_7_MHZ:
1048 if (p->frequency < 470000000)
1049 priv->ctrl.vhfbw7 = 1;
1051 priv->ctrl.uhfbw8 = 0;
1052 type |= (priv->ctrl.vhfbw7 && priv->ctrl.uhfbw8) ? DTV78 : DTV7;
1055 case BANDWIDTH_6_MHZ:
1057 priv->ctrl.vhfbw7 = 0;
1058 priv->ctrl.uhfbw8 = 0;
1061 tuner_err("error: bandwidth not supported.\n");
1065 Selects between D2633 or D2620 firmware.
1066 It doesn't make sense for ATSC, since it should be D2633 on all cases
1068 if (fe->ops.info.type != FE_ATSC) {
1069 switch (priv->ctrl.type) {
1078 /* Zarlink seems to need D2633 */
1079 if (priv->ctrl.demod == XC3028_FE_ZARLINK456)
1086 /* All S-code tables need a 200kHz shift */
1087 if (priv->ctrl.demod)
1088 demod = priv->ctrl.demod + 200;
1090 return generic_set_freq(fe, p->frequency,
1091 T_DIGITAL_TV, type, 0, demod);
1095 static int xc2028_dvb_release(struct dvb_frontend *fe)
1097 struct xc2028_data *priv = fe->tuner_priv;
1099 tuner_dbg("%s called\n", __func__);
1101 mutex_lock(&xc2028_list_mutex);
1103 /* only perform final cleanup if this is the last instance */
1104 if (hybrid_tuner_report_instance_count(priv) == 1) {
1105 kfree(priv->ctrl.fname);
1106 free_firmware(priv);
1110 hybrid_tuner_release_state(priv);
1112 mutex_unlock(&xc2028_list_mutex);
1114 fe->tuner_priv = NULL;
1119 static int xc2028_get_frequency(struct dvb_frontend *fe, u32 *frequency)
1121 struct xc2028_data *priv = fe->tuner_priv;
1123 tuner_dbg("%s called\n", __func__);
1125 *frequency = priv->frequency;
1130 static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg)
1132 struct xc2028_data *priv = fe->tuner_priv;
1133 struct xc2028_ctrl *p = priv_cfg;
1136 tuner_dbg("%s called\n", __func__);
1138 mutex_lock(&priv->lock);
1140 memcpy(&priv->ctrl, p, sizeof(priv->ctrl));
1141 if (priv->ctrl.max_len < 9)
1142 priv->ctrl.max_len = 13;
1145 if (priv->ctrl.fname && strcmp(p->fname, priv->ctrl.fname)) {
1146 kfree(priv->ctrl.fname);
1147 free_firmware(priv);
1150 priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL);
1151 if (priv->ctrl.fname == NULL)
1155 mutex_unlock(&priv->lock);
1160 static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = {
1162 .name = "Xceive XC3028",
1163 .frequency_min = 42000000,
1164 .frequency_max = 864000000,
1165 .frequency_step = 50000,
1168 .set_config = xc2028_set_config,
1169 .set_analog_params = xc2028_set_analog_freq,
1170 .release = xc2028_dvb_release,
1171 .get_frequency = xc2028_get_frequency,
1172 .get_rf_strength = xc2028_signal,
1173 .set_params = xc2028_set_params,
1176 struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
1177 struct xc2028_config *cfg)
1179 struct xc2028_data *priv;
1183 printk(KERN_DEBUG "xc2028: Xcv2028/3028 init called!\n");
1189 printk(KERN_ERR "xc2028: No frontend!\n");
1193 mutex_lock(&xc2028_list_mutex);
1195 instance = hybrid_tuner_request_state(struct xc2028_data, priv,
1196 hybrid_tuner_instance_list,
1197 cfg->i2c_adap, cfg->i2c_addr,
1201 /* memory allocation failure */
1205 /* new tuner instance */
1206 priv->ctrl.max_len = 13;
1208 mutex_init(&priv->lock);
1210 fe->tuner_priv = priv;
1213 /* existing tuner instance */
1214 fe->tuner_priv = priv;
1218 memcpy(&fe->ops.tuner_ops, &xc2028_dvb_tuner_ops,
1219 sizeof(xc2028_dvb_tuner_ops));
1221 tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner");
1224 xc2028_set_config(fe, cfg->ctrl);
1226 mutex_unlock(&xc2028_list_mutex);
1230 mutex_unlock(&xc2028_list_mutex);
1232 xc2028_dvb_release(fe);
1236 EXPORT_SYMBOL(xc2028_attach);
1238 MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver");
1239 MODULE_AUTHOR("Michel Ludwig <michel.ludwig@gmail.com>");
1240 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
1241 MODULE_LICENSE("GPL");