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 void dump_firm_type(unsigned int type
)
193 if (type
& TOYOTA388
)
194 printk("TOYOTA388 ");
195 if (type
& TOYOTA794
)
196 printk("TOYOTA794 ");
199 if (type
& ZARLINK456
)
200 printk("ZARLINK456 ");
211 static v4l2_std_id
parse_audio_std_option(void)
213 if (strcasecmp(audio_std
, "A2") == 0)
215 if (strcasecmp(audio_std
, "A2/A") == 0)
216 return V4L2_STD_A2_A
;
217 if (strcasecmp(audio_std
, "A2/B") == 0)
218 return V4L2_STD_A2_B
;
219 if (strcasecmp(audio_std
, "NICAM") == 0)
220 return V4L2_STD_NICAM
;
221 if (strcasecmp(audio_std
, "NICAM/A") == 0)
222 return V4L2_STD_NICAM_A
;
223 if (strcasecmp(audio_std
, "NICAM/B") == 0)
224 return V4L2_STD_NICAM_B
;
229 static void free_firmware(struct xc2028_data
*priv
)
236 for (i
= 0; i
< priv
->firm_size
; i
++)
237 kfree(priv
->firm
[i
].ptr
);
244 memset(&priv
->cur_fw
, 0, sizeof(priv
->cur_fw
));
247 static int load_all_firmwares(struct dvb_frontend
*fe
)
249 struct xc2028_data
*priv
= fe
->tuner_priv
;
250 const struct firmware
*fw
= NULL
;
251 unsigned char *p
, *endp
;
256 tuner_dbg("%s called\n", __FUNCTION__
);
258 tuner_dbg("Reading firmware %s\n", priv
->ctrl
.fname
);
259 rc
= request_firmware(&fw
, priv
->ctrl
.fname
,
260 &priv
->i2c_props
.adap
->dev
);
263 tuner_err("Error: firmware %s not found.\n",
266 tuner_err("Error %d while requesting firmware %s \n",
267 rc
, priv
->ctrl
.fname
);
274 if (fw
->size
< sizeof(name
) - 1 + 2 + 2) {
275 tuner_err("Error: firmware file %s has invalid size!\n",
280 memcpy(name
, p
, sizeof(name
) - 1);
281 name
[sizeof(name
) - 1] = 0;
282 p
+= sizeof(name
) - 1;
284 priv
->firm_version
= le16_to_cpu(*(__u16
*) p
);
287 n_array
= le16_to_cpu(*(__u16
*) p
);
290 tuner_info("Loading %d firmware images from %s, type: %s, ver %d.%d\n",
291 n_array
, priv
->ctrl
.fname
, name
,
292 priv
->firm_version
>> 8, priv
->firm_version
& 0xff);
294 priv
->firm
= kzalloc(sizeof(*priv
->firm
) * n_array
, GFP_KERNEL
);
295 if (priv
->firm
== NULL
) {
296 tuner_err("Not enough memory to load firmware file.\n");
300 priv
->firm_size
= n_array
;
310 tuner_err("More firmware images in file than "
315 /* Checks if there's enough bytes to read */
316 if (p
+ sizeof(type
) + sizeof(id
) + sizeof(size
) > endp
) {
317 tuner_err("Firmware header is incomplete!\n");
321 type
= le32_to_cpu(*(__u32
*) p
);
324 id
= le64_to_cpu(*(v4l2_std_id
*) p
);
328 int_freq
= le16_to_cpu(*(__u16
*) p
);
329 p
+= sizeof(int_freq
);
332 size
= le32_to_cpu(*(__u32
*) p
);
335 if ((!size
) || (size
+ p
> endp
)) {
336 tuner_err("Firmware type ");
337 dump_firm_type(type
);
338 printk("(%x), id %llx is corrupted "
339 "(size=%d, expected %d)\n",
340 type
, (unsigned long long)id
,
341 (unsigned)(endp
- p
), size
);
345 priv
->firm
[n
].ptr
= kzalloc(size
, GFP_KERNEL
);
346 if (priv
->firm
[n
].ptr
== NULL
) {
347 tuner_err("Not enough memory to load firmware file.\n");
351 tuner_dbg("Reading firmware type ");
353 dump_firm_type(type
);
354 printk("(%x), id %llx, size=%d.\n",
355 type
, (unsigned long long)id
, size
);
358 memcpy(priv
->firm
[n
].ptr
, p
, size
);
359 priv
->firm
[n
].type
= type
;
360 priv
->firm
[n
].id
= id
;
361 priv
->firm
[n
].size
= size
;
362 priv
->firm
[n
].int_freq
= int_freq
;
367 if (n
+ 1 != priv
->firm_size
) {
368 tuner_err("Firmware file is incomplete!\n");
376 tuner_err("Error: firmware file is corrupted!\n");
379 tuner_info("Releasing partially loaded firmware file.\n");
383 release_firmware(fw
);
385 tuner_dbg("Firmware files loaded.\n");
390 static int seek_firmware(struct dvb_frontend
*fe
, unsigned int type
,
393 struct xc2028_data
*priv
= fe
->tuner_priv
;
394 int i
, best_i
= -1, best_nr_matches
= 0;
396 tuner_dbg("%s called, want type=", __FUNCTION__
);
398 dump_firm_type(type
);
399 printk("(%x), id %016llx.\n", type
, (unsigned long long)*id
);
403 tuner_err("Error! firmware not loaded\n");
407 if (((type
& ~SCODE
) == 0) && (*id
== 0))
412 else if (type
& SCODE
)
414 else if (type
& DTV_TYPES
)
416 else if (type
& STD_SPECIFIC_TYPES
)
417 type
&= STD_SPECIFIC_TYPES
;
419 /* Seek for exact match */
420 for (i
= 0; i
< priv
->firm_size
; i
++) {
421 if ((type
== priv
->firm
[i
].type
) && (*id
== priv
->firm
[i
].id
))
425 /* Seek for generic video standard match */
426 for (i
= 0; i
< priv
->firm_size
; i
++) {
427 v4l2_std_id match_mask
;
430 if (type
!= priv
->firm
[i
].type
)
433 match_mask
= *id
& priv
->firm
[i
].id
;
437 if ((*id
& match_mask
) == *id
)
438 goto found
; /* Supports all the requested standards */
440 nr_matches
= hweight64(match_mask
);
441 if (nr_matches
> best_nr_matches
) {
442 best_nr_matches
= nr_matches
;
447 if (best_nr_matches
> 0) {
448 tuner_dbg("Selecting best matching firmware (%d bits) for "
449 "type=", best_nr_matches
);
450 dump_firm_type(type
);
451 printk("(%x), id %016llx:\n", type
, (unsigned long long)*id
);
456 /*FIXME: Would make sense to seek for type "hint" match ? */
462 *id
= priv
->firm
[i
].id
;
465 tuner_dbg("%s firmware for type=", (i
< 0) ? "Can't find" : "Found");
467 dump_firm_type(type
);
468 printk("(%x), id %016llx.\n", type
, (unsigned long long)*id
);
473 static int load_firmware(struct dvb_frontend
*fe
, unsigned int type
,
476 struct xc2028_data
*priv
= fe
->tuner_priv
;
478 unsigned char *p
, *endp
, buf
[priv
->ctrl
.max_len
];
480 tuner_dbg("%s called\n", __FUNCTION__
);
482 pos
= seek_firmware(fe
, type
, id
);
486 tuner_info("Loading firmware for type=");
487 dump_firm_type(priv
->firm
[pos
].type
);
488 printk("(%x), id %016llx.\n", priv
->firm
[pos
].type
,
489 (unsigned long long)*id
);
491 p
= priv
->firm
[pos
].ptr
;
492 endp
= p
+ priv
->firm
[pos
].size
;
497 /* Checks if there's enough bytes to read */
498 if (p
+ sizeof(size
) > endp
) {
499 tuner_err("Firmware chunk size is wrong\n");
503 size
= le16_to_cpu(*(__u16
*) p
);
510 /* Special callback command received */
511 rc
= priv
->tuner_callback(priv
->video_dev
,
512 XC2028_TUNER_RESET
, 0);
514 tuner_err("Error at RESET code %d\n",
520 if (size
>= 0xff00) {
523 rc
= priv
->tuner_callback(priv
->video_dev
,
524 XC2028_RESET_CLK
, 0);
526 tuner_err("Error at RESET code %d\n",
532 tuner_info("Invalid RESET code %d\n",
540 /* Checks for a sleep command */
542 msleep(size
& 0x7fff);
546 if ((size
+ p
> endp
)) {
547 tuner_err("missing bytes: need %d, have %d\n",
548 size
, (int)(endp
- p
));
556 /* Sends message chunks */
558 int len
= (size
< priv
->ctrl
.max_len
- 1) ?
559 size
: priv
->ctrl
.max_len
- 1;
561 memcpy(buf
+ 1, p
, len
);
563 rc
= i2c_send(priv
, buf
, len
+ 1);
565 tuner_err("%d returned from send\n", rc
);
576 static int load_scode(struct dvb_frontend
*fe
, unsigned int type
,
577 v4l2_std_id
*id
, __u16 int_freq
, int scode
)
579 struct xc2028_data
*priv
= fe
->tuner_priv
;
583 tuner_dbg("%s called\n", __FUNCTION__
);
586 pos
= seek_firmware(fe
, type
, id
);
590 for (pos
= 0; pos
< priv
->firm_size
; pos
++) {
591 if ((priv
->firm
[pos
].int_freq
== int_freq
) &&
595 if (pos
== priv
->firm_size
)
599 p
= priv
->firm
[pos
].ptr
;
602 if (priv
->firm
[pos
].size
!= 12 * 16 || scode
>= 16)
606 /* 16 SCODE entries per file; each SCODE entry is 12 bytes and
607 * has a 2-byte size header in the firmware format. */
608 if (priv
->firm
[pos
].size
!= 14 * 16 || scode
>= 16 ||
609 le16_to_cpu(*(__u16
*)(p
+ 14 * scode
)) != 12)
614 tuner_info("Loading SCODE for type=");
615 dump_firm_type(priv
->firm
[pos
].type
);
616 printk("(%x), id %016llx.\n", priv
->firm
[pos
].type
,
617 (unsigned long long)*id
);
619 if (priv
->firm_version
< 0x0202)
620 rc
= send_seq(priv
, {0x20, 0x00, 0x00, 0x00});
622 rc
= send_seq(priv
, {0xa0, 0x00, 0x00, 0x00});
626 rc
= i2c_send(priv
, p
, 12);
630 rc
= send_seq(priv
, {0x00, 0x8c});
637 static int check_firmware(struct dvb_frontend
*fe
, unsigned int type
,
638 v4l2_std_id std
, __u16 int_freq
)
640 struct xc2028_data
*priv
= fe
->tuner_priv
;
641 struct firmware_properties new_fw
;
642 int rc
= 0, is_retry
= 0;
643 u16 version
, hwmodel
;
646 tuner_dbg("%s called\n", __FUNCTION__
);
649 if (!priv
->ctrl
.fname
) {
650 tuner_info("xc2028/3028 firmware name not set!\n");
654 rc
= load_all_firmwares(fe
);
665 new_fw
.std_req
= std
;
666 new_fw
.scode_table
= SCODE
| priv
->ctrl
.scode_table
;
668 new_fw
.int_freq
= int_freq
;
670 tuner_dbg("checking firmware, user requested type=");
672 dump_firm_type(new_fw
.type
);
673 printk("(%x), id %016llx, scode_tbl ", new_fw
.type
,
674 (unsigned long long)new_fw
.std_req
);
675 dump_firm_type(priv
->ctrl
.scode_table
);
676 printk("(%x), scode_nr %d\n", priv
->ctrl
.scode_table
,
680 /* No need to reload base firmware if it matches */
681 if (((BASE
| new_fw
.type
) & BASE_TYPES
) ==
682 (priv
->cur_fw
.type
& BASE_TYPES
)) {
683 tuner_dbg("BASE firmware not changed.\n");
687 /* Updating BASE - forget about all currently loaded firmware */
688 memset(&priv
->cur_fw
, 0, sizeof(priv
->cur_fw
));
690 /* Reset is needed before loading firmware */
691 rc
= priv
->tuner_callback(priv
->video_dev
,
692 XC2028_TUNER_RESET
, 0);
696 /* BASE firmwares are all std0 */
698 rc
= load_firmware(fe
, BASE
| new_fw
.type
, &std0
);
700 tuner_err("Error %d while loading base firmware\n",
705 /* Load INIT1, if needed */
706 tuner_dbg("Load init1 firmware, if exists\n");
708 rc
= load_firmware(fe
, BASE
| INIT1
| new_fw
.type
, &std0
);
710 rc
= load_firmware(fe
, (BASE
| INIT1
| new_fw
.type
) & ~F8MHZ
,
712 if (rc
< 0 && rc
!= -ENOENT
) {
713 tuner_err("Error %d while loading init1 firmware\n",
720 * No need to reload standard specific firmware if base firmware
721 * was not reloaded and requested video standards have not changed.
723 if (priv
->cur_fw
.type
== (BASE
| new_fw
.type
) &&
724 priv
->cur_fw
.std_req
== std
) {
725 tuner_dbg("Std-specific firmware already loaded.\n");
726 goto skip_std_specific
;
729 /* Reloading std-specific firmware forces a SCODE update */
730 priv
->cur_fw
.scode_table
= 0;
732 rc
= load_firmware(fe
, new_fw
.type
, &new_fw
.id
);
734 rc
= load_firmware(fe
, new_fw
.type
& ~F8MHZ
, &new_fw
.id
);
740 if (priv
->cur_fw
.scode_table
== new_fw
.scode_table
&&
741 priv
->cur_fw
.scode_nr
== new_fw
.scode_nr
) {
742 tuner_dbg("SCODE firmware already loaded.\n");
746 /* Load SCODE firmware, if exists */
747 tuner_dbg("Trying to load scode %d\n", new_fw
.scode_nr
);
749 rc
= load_scode(fe
, new_fw
.type
| new_fw
.scode_table
, &new_fw
.id
,
750 new_fw
.int_freq
, new_fw
.scode_nr
);
753 if (xc2028_get_reg(priv
, 0x0004, &version
) < 0 ||
754 xc2028_get_reg(priv
, 0x0008, &hwmodel
) < 0) {
755 tuner_err("Unable to read tuner registers.\n");
759 tuner_info("Device is Xceive %d version %d.%d, "
760 "firmware version %d.%d\n",
761 hwmodel
, (version
& 0xf000) >> 12, (version
& 0xf00) >> 8,
762 (version
& 0xf0) >> 4, version
& 0xf);
764 /* Check firmware version against what we downloaded. */
765 if (priv
->firm_version
!= ((version
& 0xf0) << 4 | (version
& 0x0f))) {
766 tuner_err("Incorrect readback of firmware version.\n");
770 /* Check that the tuner hardware model remains consistent over time. */
771 if (priv
->hwmodel
== 0 && (hwmodel
== 2028 || hwmodel
== 3028)) {
772 priv
->hwmodel
= hwmodel
;
773 priv
->hwvers
= version
& 0xff00;
774 } else if (priv
->hwmodel
== 0 || priv
->hwmodel
!= hwmodel
||
775 priv
->hwvers
!= (version
& 0xff00)) {
776 tuner_err("Read invalid device hardware information - tuner "
781 memcpy(&priv
->cur_fw
, &new_fw
, sizeof(priv
->cur_fw
));
784 * By setting BASE in cur_fw.type only after successfully loading all
786 * 1. Identify that BASE firmware with type=0 has been loaded;
787 * 2. Tell whether BASE firmware was just changed the next time through.
789 priv
->cur_fw
.type
|= BASE
;
794 memset(&priv
->cur_fw
, 0, sizeof(priv
->cur_fw
));
798 tuner_dbg("Retrying firmware load\n");
807 static int xc2028_signal(struct dvb_frontend
*fe
, u16
*strength
)
809 struct xc2028_data
*priv
= fe
->tuner_priv
;
810 u16 frq_lock
, signal
= 0;
813 tuner_dbg("%s called\n", __FUNCTION__
);
815 mutex_lock(&priv
->lock
);
817 /* Sync Lock Indicator */
818 rc
= xc2028_get_reg(priv
, 0x0002, &frq_lock
);
819 if (rc
< 0 || frq_lock
== 0)
822 /* Frequency is locked. Return signal quality */
824 /* Get SNR of the video signal */
825 rc
= xc2028_get_reg(priv
, 0x0040, &signal
);
830 mutex_unlock(&priv
->lock
);
839 static int generic_set_freq(struct dvb_frontend
*fe
, u32 freq
/* in HZ */,
840 enum tuner_mode new_mode
,
845 struct xc2028_data
*priv
= fe
->tuner_priv
;
847 unsigned char buf
[4];
850 tuner_dbg("%s called\n", __FUNCTION__
);
852 mutex_lock(&priv
->lock
);
854 tuner_dbg("should set frequency %d kHz\n", freq
/ 1000);
856 if (check_firmware(fe
, type
, std
, int_freq
) < 0)
859 /* On some cases xc2028 can disable video output, if
860 * very weak signals are received. By sending a soft
861 * reset, this is re-enabled. So, it is better to always
862 * send a soft reset before changing channels, to be sure
863 * that xc2028 will be in a safe state.
864 * Maybe this might also be needed for DTV.
866 if (new_mode
== T_ANALOG_TV
) {
867 rc
= send_seq(priv
, {0x00, 0x00});
870 if (priv
->cur_fw
.type
& DTV7
)
874 div
= (freq
- offset
+ DIV
/ 2) / DIV
;
876 /* CMD= Set frequency */
877 if (priv
->firm_version
< 0x0202)
878 rc
= send_seq(priv
, {0x00, 0x02, 0x00, 0x00});
880 rc
= send_seq(priv
, {0x80, 0x02, 0x00, 0x00});
884 rc
= priv
->tuner_callback(priv
->video_dev
, XC2028_RESET_CLK
, 1);
890 buf
[0] = 0xff & (div
>> 24);
891 buf
[1] = 0xff & (div
>> 16);
892 buf
[2] = 0xff & (div
>> 8);
893 buf
[3] = 0xff & (div
);
895 rc
= i2c_send(priv
, buf
, sizeof(buf
));
900 priv
->frequency
= freq
;
902 tuner_dbg("divisor= %02x %02x %02x %02x (freq=%d.%03d)\n",
903 buf
[0], buf
[1], buf
[2], buf
[3],
904 freq
/ 1000000, (freq
% 1000000) / 1000);
909 mutex_unlock(&priv
->lock
);
914 static int xc2028_set_analog_freq(struct dvb_frontend
*fe
,
915 struct analog_parameters
*p
)
917 struct xc2028_data
*priv
= fe
->tuner_priv
;
920 tuner_dbg("%s called\n", __FUNCTION__
);
922 if (p
->mode
== V4L2_TUNER_RADIO
) {
924 if (priv
->ctrl
.input1
)
926 return generic_set_freq(fe
, (625l * p
->frequency
) / 10,
927 T_ANALOG_TV
, type
, 0, 0);
930 /* if std is not defined, choose one */
932 p
->std
= V4L2_STD_MN
;
934 /* PAL/M, PAL/N, PAL/Nc and NTSC variants should use 6MHz firmware */
935 if (!(p
->std
& V4L2_STD_MN
))
938 /* Add audio hack to std mask */
939 p
->std
|= parse_audio_std_option();
941 return generic_set_freq(fe
, 62500l * p
->frequency
,
942 T_ANALOG_TV
, type
, p
->std
, 0);
945 static int xc2028_set_params(struct dvb_frontend
*fe
,
946 struct dvb_frontend_parameters
*p
)
948 struct xc2028_data
*priv
= fe
->tuner_priv
;
950 fe_bandwidth_t bw
= BANDWIDTH_8_MHZ
;
952 tuner_dbg("%s called\n", __FUNCTION__
);
954 if (priv
->ctrl
.d2633
)
959 switch(fe
->ops
.info
.type
) {
961 bw
= p
->u
.ofdm
.bandwidth
;
964 tuner_info("WARN: There are some reports that "
965 "QAM 6 MHz doesn't work.\n"
966 "If this works for you, please report by "
967 "e-mail to: v4l-dvb-maintainer@linuxtv.org\n");
968 bw
= BANDWIDTH_6_MHZ
;
972 bw
= BANDWIDTH_6_MHZ
;
975 /* DVB-S is not supported */
981 There are two Scodes that will never be selected:
982 DTV78 ZARLINK456, DTV78 DIBCOM52
983 When it should opt for DTV78 instead of DTV7 or DTV8?
986 case BANDWIDTH_8_MHZ
:
987 type
|= DTV8
| F8MHZ
;
989 case BANDWIDTH_7_MHZ
:
990 type
|= DTV7
| F8MHZ
;
992 case BANDWIDTH_6_MHZ
:
996 tuner_err("error: bandwidth not supported.\n");
999 /* All S-code tables need a 200kHz shift */
1000 if (priv
->ctrl
.demod
)
1001 priv
->ctrl
.demod
+= 200;
1003 return generic_set_freq(fe
, p
->frequency
,
1004 T_DIGITAL_TV
, type
, 0, priv
->ctrl
.demod
);
1007 static int xc2028_sleep(struct dvb_frontend
*fe
)
1009 struct xc2028_data
*priv
= fe
->tuner_priv
;
1012 tuner_dbg("%s called\n", __FUNCTION__
);
1014 mutex_lock(&priv
->lock
);
1016 if (priv
->firm_version
< 0x0202)
1017 rc
= send_seq(priv
, {0x00, 0x08, 0x00, 0x00});
1019 rc
= send_seq(priv
, {0x80, 0x08, 0x00, 0x00});
1021 priv
->cur_fw
.type
= 0; /* need firmware reload */
1023 mutex_unlock(&priv
->lock
);
1029 static int xc2028_dvb_release(struct dvb_frontend
*fe
)
1031 struct xc2028_data
*priv
= fe
->tuner_priv
;
1033 tuner_dbg("%s called\n", __FUNCTION__
);
1035 mutex_lock(&xc2028_list_mutex
);
1040 list_del(&priv
->xc2028_list
);
1042 kfree(priv
->ctrl
.fname
);
1044 free_firmware(priv
);
1046 fe
->tuner_priv
= NULL
;
1049 mutex_unlock(&xc2028_list_mutex
);
1054 static int xc2028_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
1056 struct xc2028_data
*priv
= fe
->tuner_priv
;
1058 tuner_dbg("%s called\n", __FUNCTION__
);
1060 *frequency
= priv
->frequency
;
1065 static int xc2028_set_config(struct dvb_frontend
*fe
, void *priv_cfg
)
1067 struct xc2028_data
*priv
= fe
->tuner_priv
;
1068 struct xc2028_ctrl
*p
= priv_cfg
;
1071 tuner_dbg("%s called\n", __FUNCTION__
);
1073 mutex_lock(&priv
->lock
);
1075 kfree(priv
->ctrl
.fname
);
1076 free_firmware(priv
);
1078 memcpy(&priv
->ctrl
, p
, sizeof(priv
->ctrl
));
1079 priv
->ctrl
.fname
= NULL
;
1082 priv
->ctrl
.fname
= kstrdup(p
->fname
, GFP_KERNEL
);
1083 if (priv
->ctrl
.fname
== NULL
)
1087 if (priv
->ctrl
.max_len
< 9)
1088 priv
->ctrl
.max_len
= 13;
1090 mutex_unlock(&priv
->lock
);
1095 static const struct dvb_tuner_ops xc2028_dvb_tuner_ops
= {
1097 .name
= "Xceive XC3028",
1098 .frequency_min
= 42000000,
1099 .frequency_max
= 864000000,
1100 .frequency_step
= 50000,
1103 .set_config
= xc2028_set_config
,
1104 .set_analog_params
= xc2028_set_analog_freq
,
1105 .release
= xc2028_dvb_release
,
1106 .get_frequency
= xc2028_get_frequency
,
1107 .get_rf_strength
= xc2028_signal
,
1108 .set_params
= xc2028_set_params
,
1109 .sleep
= xc2028_sleep
,
1113 void *xc2028_attach(struct dvb_frontend
*fe
, struct xc2028_config
*cfg
)
1115 struct xc2028_data
*priv
;
1119 printk(KERN_DEBUG PREFIX
": Xcv2028/3028 init called!\n");
1121 if (NULL
== cfg
|| NULL
== cfg
->video_dev
)
1125 printk(KERN_ERR PREFIX
": No frontend!\n");
1129 video_dev
= cfg
->video_dev
;
1131 mutex_lock(&xc2028_list_mutex
);
1133 list_for_each_entry(priv
, &xc2028_list
, xc2028_list
) {
1134 if (priv
->video_dev
== cfg
->video_dev
) {
1141 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
1143 mutex_unlock(&xc2028_list_mutex
);
1147 priv
->i2c_props
.addr
= cfg
->i2c_addr
;
1148 priv
->i2c_props
.adap
= cfg
->i2c_adap
;
1149 priv
->video_dev
= video_dev
;
1150 priv
->tuner_callback
= cfg
->callback
;
1151 priv
->ctrl
.max_len
= 13;
1153 mutex_init(&priv
->lock
);
1155 list_add_tail(&priv
->xc2028_list
, &xc2028_list
);
1158 fe
->tuner_priv
= priv
;
1161 memcpy(&fe
->ops
.tuner_ops
, &xc2028_dvb_tuner_ops
,
1162 sizeof(xc2028_dvb_tuner_ops
));
1164 tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner");
1167 xc2028_set_config(fe
, cfg
->ctrl
);
1169 mutex_unlock(&xc2028_list_mutex
);
1174 EXPORT_SYMBOL(xc2028_attach
);
1176 MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver");
1177 MODULE_AUTHOR("Michel Ludwig <michel.ludwig@gmail.com>");
1178 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
1179 MODULE_LICENSE("GPL");