summaryrefslogtreecommitdiff
path: root/linux
diff options
context:
space:
mode:
Diffstat (limited to 'linux')
-rw-r--r--linux/Documentation/video4linux/CARDLIST.em28xx8
-rw-r--r--linux/drivers/media/dvb/dvb-usb/cxusb.c431
-rw-r--r--linux/drivers/media/dvb/dvb-usb/cxusb.h2
-rw-r--r--linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h3
-rw-r--r--linux/drivers/media/dvb/frontends/mt352.c8
-rw-r--r--linux/drivers/media/dvb/frontends/zl10353.c85
-rw-r--r--linux/drivers/media/dvb/frontends/zl10353.h9
-rw-r--r--linux/drivers/media/dvb/frontends/zl10353_priv.h8
-rw-r--r--linux/drivers/media/video/em28xx/em28xx-cards.c207
-rw-r--r--linux/drivers/media/video/em28xx/em28xx.h2
-rw-r--r--linux/drivers/media/video/saa7134/saa7134-alsa.c13
-rw-r--r--linux/drivers/media/video/saa7134/saa7134-core.c25
-rw-r--r--linux/drivers/media/video/saa7134/saa7134-tvaudio.c79
-rw-r--r--linux/drivers/media/video/saa7134/saa7134.h1
-rw-r--r--linux/drivers/media/video/tuner-i2c.h13
-rw-r--r--linux/drivers/media/video/tuner-xc2028-types.h13
-rw-r--r--linux/drivers/media/video/tuner-xc2028.c763
-rw-r--r--linux/drivers/media/video/tuner-xc2028.h22
18 files changed, 1205 insertions, 487 deletions
diff --git a/linux/Documentation/video4linux/CARDLIST.em28xx b/linux/Documentation/video4linux/CARDLIST.em28xx
index 94b53bd71..ceb277543 100644
--- a/linux/Documentation/video4linux/CARDLIST.em28xx
+++ b/linux/Documentation/video4linux/CARDLIST.em28xx
@@ -8,10 +8,10 @@
7 -> Leadtek Winfast USB II (em2800)
8 -> Kworld USB2800 (em2800)
9 -> Pinnacle Dazzle DVC 90 (em2820/em2840) [2304:0207]
- 10 -> Hauppauge WinTV HVR 900 (em2880)
- 11 -> Terratec Hybrid XS (em2880)
+ 10 -> Hauppauge WinTV HVR 900 (em2880) [2040:6500]
+ 11 -> Terratec Hybrid XS (em2880) [0ccd:0042]
12 -> Kworld PVR TV 2800 RF (em2820/em2840)
- 13 -> Terratec Prodigy XS (em2880)
+ 13 -> Terratec Prodigy XS (em2880) [0ccd:0047]
14 -> Pixelview Prolink PlayTV USB 2.0 (em2820/em2840)
15 -> V-Gear PocketTV (em2800)
- 16 -> Hauppauge WinTV HVR 950 (em2880)
+ 16 -> Hauppauge WinTV HVR 950 (em2880) [2040:6513]
diff --git a/linux/drivers/media/dvb/dvb-usb/cxusb.c b/linux/drivers/media/dvb/dvb-usb/cxusb.c
index fb2cd9c75..56cdcb782 100644
--- a/linux/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/linux/drivers/media/dvb/dvb-usb/cxusb.c
@@ -15,7 +15,7 @@
*
* Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de)
* Copyright (C) 2006 Michael Krufky (mkrufky@linuxtv.org)
- * Copyright (C) 2006 Chris Pascoe (c.pascoe@itee.uq.edu.au)
+ * Copyright (C) 2006, 2007 Chris Pascoe (c.pascoe@itee.uq.edu.au)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@@ -30,6 +30,8 @@
#include "mt352.h"
#include "mt352_priv.h"
#include "zl10353.h"
+#include "tuner-xc2028.h"
+#include "tuner-xc2028-types.h"
/* debug */
static int dvb_usb_cxusb_debug;
@@ -49,11 +51,9 @@ static int cxusb_ctrl_msg(struct dvb_usb_device *d,
sndbuf[0] = cmd;
memcpy(&sndbuf[1], wbuf, wlen);
if (wo)
- dvb_usb_generic_write(d, sndbuf, 1+wlen);
+ return dvb_usb_generic_write(d, sndbuf, 1+wlen);
else
- dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);
-
- return 0;
+ return dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);
}
/* GPIO */
@@ -75,6 +75,34 @@ static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
st->gpio_write_state[GPIO_TUNER] = onoff;
}
+static int cxusb_bluebird_gpio_rw(struct dvb_usb_device *d, u8 changemask,
+ u8 newval)
+{
+ u8 o[2], gpio_state;
+ int rc;
+
+ o[0] = 0xff & ~changemask; /* mask of bits to keep */
+ o[1] = newval & changemask; /* new values for bits */
+
+ rc = cxusb_ctrl_msg(d, CMD_BLUEBIRD_GPIO_RW, o, 2, &gpio_state, 1);
+ if (rc < 0 || (gpio_state & changemask) != (newval & changemask))
+ deb_info("bluebird_gpio_write failed.\n");
+
+ return rc < 0 ? rc : gpio_state;
+}
+
+static void cxusb_bluebird_gpio_pulse(struct dvb_usb_device *d, u8 pin, int low)
+{
+ cxusb_bluebird_gpio_rw(d, pin, low ? 0 : pin);
+ msleep(5);
+ cxusb_bluebird_gpio_rw(d, pin, low ? pin : 0);
+}
+
+static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)
+{
+ cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);
+}
+
/* I2C */
static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
int num)
@@ -85,9 +113,6 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
return -EAGAIN;
- if (num > 2)
- warn("more than two i2c messages at a time is not handled yet. TODO.");
-
for (i = 0; i < num; i++) {
if (d->udev->descriptor.idVendor == USB_VID_MEDION)
@@ -100,8 +125,22 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
break;
}
- /* read request */
- if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
+ if (msg[i].flags & I2C_M_RD) {
+ /* read only */
+ u8 obuf[3], ibuf[1+msg[i].len];
+ obuf[0] = 0;
+ obuf[1] = msg[i].len;
+ obuf[2] = msg[i].addr;
+ if (cxusb_ctrl_msg(d, CMD_I2C_READ,
+ obuf, 3,
+ ibuf, 1+msg[i].len) < 0) {
+ warn("i2c read failed");
+ break;
+ }
+ memcpy(msg[i].buf, &ibuf[1], msg[i].len);
+ } else if (i+1 < num && (msg[i+1].flags & I2C_M_RD) &&
+ msg[i].addr == msg[i+1].addr) {
+ /* write to then read from same address */
u8 obuf[3+msg[i].len], ibuf[1+msg[i+1].len];
obuf[0] = msg[i].len;
obuf[1] = msg[i+1].len;
@@ -119,7 +158,8 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
i++;
- } else { /* write */
+ } else {
+ /* write only */
u8 obuf[2+msg[i].len], ibuf;
obuf[0] = msg[i].addr;
obuf[1] = msg[i].len;
@@ -134,7 +174,7 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
}
mutex_unlock(&d->i2c_mutex);
- return i;
+ return i == num ? num : -EREMOTEIO;
}
static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
@@ -165,6 +205,17 @@ static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff)
return 0;
}
+static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)
+{
+ int rc = 0;
+
+ rc = cxusb_power_ctrl(d, onoff);
+ if (!onoff)
+ cxusb_nano2_led(d, 0);
+
+ return rc;
+}
+
static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
{
u8 buf[2] = { 0x03, 0x00 };
@@ -200,6 +251,34 @@ static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
return 0;
}
+static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
+ int *state)
+{
+ struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
+ u8 ircode[4];
+ int i;
+ struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
+ .buf = ircode, .len = 4 };
+
+ *event = 0;
+ *state = REMOTE_NO_KEY_PRESSED;
+
+ if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
+ return 0;
+
+ for (i = 0; i < d->props.rc_key_map_size; i++) {
+ if (keymap[i].custom == ircode[1] &&
+ keymap[i].data == ircode[2]) {
+ *event = keymap[i].event;
+ *state = REMOTE_KEY_PRESSED;
+
+ return 0;
+ }
+ }
+
+ return 0;
+}
+
static struct dvb_usb_rc_key dvico_mce_rc_keys[] = {
{ 0xfe, 0x02, KEY_TV },
{ 0xfe, 0x0e, KEY_MP3 },
@@ -354,6 +433,20 @@ static struct mt352_config cxusb_mt352_config = {
.demod_init = cxusb_mt352_demod_init,
};
+static struct zl10353_config cxusb_zl10353_xc3028_config = {
+ .demod_address = 0x0f,
+ .if2 = 45600,
+ .no_tuner = 1,
+ .parallel_ts = 1,
+};
+
+static struct mt352_config cxusb_mt352_xc3028_config = {
+ .demod_address = 0x0f,
+ .if2 = 4560,
+ .no_tuner = 1,
+ .demod_init = cxusb_mt352_demod_init,
+};
+
/* Callbacks for DVB USB */
static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
{
@@ -389,6 +482,51 @@ static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
return 0;
}
+static int dvico_bluebird_xc2028_callback(void *ptr, int command, int arg)
+{
+ struct dvb_usb_device *d = ptr;
+
+ switch (command) {
+ case XC2028_TUNER_RESET:
+ deb_info("%s: XC2028_TUNER_RESET %d\n", __FUNCTION__, arg);
+ cxusb_bluebird_gpio_pulse(d, 0x01, 1);
+ break;
+ case XC2028_RESET_CLK:
+ deb_info("%s: XC2028_RESET_CLK %d\n", __FUNCTION__, arg);
+ break;
+ default:
+ deb_info("%s: unknown command %d, arg %d\n", __FUNCTION__,
+ command, arg);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
+{
+ struct dvb_frontend *fe;
+ struct xc2028_config cfg = {
+ .i2c_adap = &adap->dev->i2c_adap,
+ .i2c_addr = 0x61,
+ .video_dev = adap->dev,
+ .callback = dvico_bluebird_xc2028_callback,
+ };
+ static struct xc2028_ctrl ctl = {
+ .fname = "xc3028-dvico-au-01.fw",
+ .max_len = 64,
+ .scode_table = ZARLINK456,
+ };
+
+ fe = dvb_attach(xc2028_attach, adap->fe, &cfg);
+ if (fe == NULL || fe->ops.tuner_ops.set_config == NULL)
+ return -EIO;
+
+ fe->ops.tuner_ops.set_config(fe, &ctl);
+
+ return 0;
+}
+
static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
{
u8 b;
@@ -450,27 +588,120 @@ static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
return -EIO;
}
+static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
+{
+ u8 ircode[4];
+ int i;
+ struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
+ .buf = ircode, .len = 4 };
+
+ if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
+ err("set interface failed");
+
+ cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
+
+ /* reset the tuner and demodulator */
+ cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
+ cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
+ cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
+
+ if ((adap->fe = dvb_attach(zl10353_attach,
+ &cxusb_zl10353_xc3028_config,
+ &adap->dev->i2c_adap)) == NULL)
+ return -EIO;
+
+ /* try to determine if there is no IR decoder on the I2C bus */
+ for (i = 0; adap->dev->props.rc_key_map != NULL && i < 5; i++) {
+ msleep(20);
+ if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1)
+ goto no_IR;
+ if (ircode[0] == 0 && ircode[1] == 0)
+ continue;
+ if (ircode[2] + ircode[3] != 0xff) {
+no_IR:
+ adap->dev->props.rc_key_map = NULL;
+ info("No IR receiver detected on this device.");
+ break;
+ }
+ }
+
+ return 0;
+}
+
+static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
+{
+ if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
+ err("set interface failed");
+
+ cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
+
+ /* reset the tuner and demodulator */
+ cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
+ cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
+ cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
+
+ if ((adap->fe = dvb_attach(zl10353_attach,
+ &cxusb_zl10353_xc3028_config,
+ &adap->dev->i2c_adap)) != NULL)
+ return 0;
+
+ if ((adap->fe = dvb_attach(mt352_attach,
+ &cxusb_mt352_xc3028_config,
+ &adap->dev->i2c_adap)) != NULL)
+ return 0;
+
+ return -EIO;
+}
+
+/*
+ * DViCO has shipped two devices with the same USB ID, but only one of them
+ * needs a firmware download. Check the device class details to see if they
+ * have non-default values to decide whether the device is actually cold or
+ * not, and forget a match if it turns out we selected the wrong device.
+ */
+static int bluebird_fx2_identify_state(struct usb_device *udev,
+ struct dvb_usb_device_properties *props,
+ struct dvb_usb_device_description **desc,
+ int *cold)
+{
+ int wascold = *cold;
+
+ *cold = udev->descriptor.bDeviceClass == 0xff &&
+ udev->descriptor.bDeviceSubClass == 0xff &&
+ udev->descriptor.bDeviceProtocol == 0xff;
+
+ if (*cold && !wascold)
+ *desc = NULL;
+
+ return 0;
+}
+
/*
* DViCO bluebird firmware needs the "warm" product ID to be patched into the
* firmware file before download.
*/
-#define BLUEBIRD_01_ID_OFFSET 6638
+static const int dvico_firmware_id_offsets[] = { 6638, 3204 };
static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,
const struct firmware *fw)
{
- if (fw->size < BLUEBIRD_01_ID_OFFSET + 4)
- return -EINVAL;
+ int pos;
+
+ for (pos = 0; pos < ARRAY_SIZE(dvico_firmware_id_offsets); pos++) {
+ int idoff = dvico_firmware_id_offsets[pos];
- if (fw->data[BLUEBIRD_01_ID_OFFSET] == (USB_VID_DVICO & 0xff) &&
- fw->data[BLUEBIRD_01_ID_OFFSET + 1] == USB_VID_DVICO >> 8) {
+ if (fw->size < idoff + 4)
+ continue;
- fw->data[BLUEBIRD_01_ID_OFFSET + 2] =
- le16_to_cpu(udev->descriptor.idProduct) + 1;
- fw->data[BLUEBIRD_01_ID_OFFSET + 3] =
- le16_to_cpu(udev->descriptor.idProduct) >> 8;
+ if (fw->data[idoff] == (USB_VID_DVICO & 0xff) &&
+ fw->data[idoff + 1] == USB_VID_DVICO >> 8) {
+ fw->data[idoff + 2] =
+ le16_to_cpu(udev->descriptor.idProduct) + 1;
+ fw->data[idoff + 3] =
+ le16_to_cpu(udev->descriptor.idProduct) >> 8;
- return usb_cypress_load_firmware(udev, fw, CYPRESS_FX2);
+ return usb_cypress_load_firmware(udev, fw, CYPRESS_FX2);
+ }
}
return -EINVAL;
@@ -482,6 +713,9 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;
static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
+static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;
+static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
+static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
static int cxusb_probe(struct usb_interface *intf,
const struct usb_device_id *id)
@@ -490,7 +724,10 @@ static int cxusb_probe(struct usb_interface *intf,
dvb_usb_device_init(intf,&cxusb_bluebird_lgh064f_properties,THIS_MODULE,NULL) == 0 ||
dvb_usb_device_init(intf,&cxusb_bluebird_dee1601_properties,THIS_MODULE,NULL) == 0 ||
dvb_usb_device_init(intf,&cxusb_bluebird_lgz201_properties,THIS_MODULE,NULL) == 0 ||
- dvb_usb_device_init(intf,&cxusb_bluebird_dtt7579_properties,THIS_MODULE,NULL) == 0) {
+ dvb_usb_device_init(intf,&cxusb_bluebird_dtt7579_properties,THIS_MODULE,NULL) == 0 ||
+ dvb_usb_device_init(intf,&cxusb_bluebird_dualdig4_properties,THIS_MODULE,NULL) == 0 ||
+ dvb_usb_device_init(intf,&cxusb_bluebird_nano2_properties,THIS_MODULE,NULL) == 0 ||
+ dvb_usb_device_init(intf,&cxusb_bluebird_nano2_needsfirmware_properties,THIS_MODULE,NULL) == 0) {
return 0;
}
@@ -511,6 +748,9 @@ static struct usb_device_id cxusb_table [] = {
{ USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM) },
{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD) },
{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM) },
+ { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4) },
+ { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2) },
+ { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM) },
{} /* Terminating entry */
};
MODULE_DEVICE_TABLE (usb, cxusb_table);
@@ -769,6 +1009,151 @@ static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
}
};
+static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
+ .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+
+ .usb_ctrl = CYPRESS_FX2,
+
+ .size_of_priv = sizeof(struct cxusb_state),
+
+ .num_adapters = 1,
+ .adapter = {
+ {
+ .streaming_ctrl = cxusb_streaming_ctrl,
+ .frontend_attach = cxusb_dualdig4_frontend_attach,
+ .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
+ /* parameter for the MPEG2-data transfer */
+ .stream = {
+ .type = USB_BULK,
+ .count = 5,
+ .endpoint = 0x02,
+ .u = {
+ .bulk = {
+ .buffersize = 8192,
+ }
+ }
+ },
+ },
+ },
+
+ .power_ctrl = cxusb_power_ctrl,
+
+ .i2c_algo = &cxusb_i2c_algo,
+
+ .generic_bulk_ctrl_endpoint = 0x01,
+
+ .rc_interval = 100,
+ .rc_key_map = dvico_mce_rc_keys,
+ .rc_key_map_size = ARRAY_SIZE(dvico_mce_rc_keys),
+ .rc_query = cxusb_bluebird2_rc_query,
+
+ .num_device_descs = 1,
+ .devices = {
+ { "DViCO FusionHDTV DVB-T Dual Digital 4",
+ { NULL },
+ { &cxusb_table[13], NULL },
+ },
+ }
+};
+
+static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
+ .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+
+ .usb_ctrl = CYPRESS_FX2,
+ .identify_state = bluebird_fx2_identify_state,
+
+ .size_of_priv = sizeof(struct cxusb_state),
+
+ .num_adapters = 1,
+ .adapter = {
+ {
+ .streaming_ctrl = cxusb_streaming_ctrl,
+ .frontend_attach = cxusb_nano2_frontend_attach,
+ .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
+ /* parameter for the MPEG2-data transfer */
+ .stream = {
+ .type = USB_BULK,
+ .count = 5,
+ .endpoint = 0x02,
+ .u = {
+ .bulk = {
+ .buffersize = 8192,
+ }
+ }
+ },
+ },
+ },
+
+ .power_ctrl = cxusb_nano2_power_ctrl,
+
+ .i2c_algo = &cxusb_i2c_algo,
+
+ .generic_bulk_ctrl_endpoint = 0x01,
+
+ .rc_interval = 100,
+ .rc_key_map = dvico_portable_rc_keys,
+ .rc_key_map_size = ARRAY_SIZE(dvico_portable_rc_keys),
+ .rc_query = cxusb_bluebird2_rc_query,
+
+ .num_device_descs = 1,
+ .devices = {
+ { "DViCO FusionHDTV DVB-T NANO2",
+ { NULL },
+ { &cxusb_table[14], NULL },
+ },
+ }
+};
+
+static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties = {
+ .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+
+ .usb_ctrl = DEVICE_SPECIFIC,
+ .firmware = "dvb-usb-bluebird-02.fw",
+ .download_firmware = bluebird_patch_dvico_firmware_download,
+ .identify_state = bluebird_fx2_identify_state,
+
+ .size_of_priv = sizeof(struct cxusb_state),
+
+ .num_adapters = 1,
+ .adapter = {
+ {
+ .streaming_ctrl = cxusb_streaming_ctrl,
+ .frontend_attach = cxusb_nano2_frontend_attach,
+ .tuner_attach = cxusb_dvico_xc3028_tuner_attach,
+ /* parameter for the MPEG2-data transfer */
+ .stream = {
+ .type = USB_BULK,
+ .count = 5,
+ .endpoint = 0x02,
+ .u = {
+ .bulk = {
+ .buffersize = 8192,
+ }
+ }
+ },
+ },
+ },
+
+ .power_ctrl = cxusb_nano2_power_ctrl,
+
+ .i2c_algo = &cxusb_i2c_algo,
+
+ .generic_bulk_ctrl_endpoint = 0x01,
+
+ .rc_interval = 100,
+ .rc_key_map = dvico_portable_rc_keys,
+ .rc_key_map_size = ARRAY_SIZE(dvico_portable_rc_keys),
+ .rc_query = cxusb_rc_query,
+
+ .num_device_descs = 1,
+ .devices = {
+ { "DViCO FusionHDTV DVB-T NANO2 w/o firmware",
+ { &cxusb_table[14], NULL },
+ { &cxusb_table[15], NULL },
+ },
+ }
+};
+
static struct usb_driver cxusb_driver = {
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,15)
.owner = THIS_MODULE,
diff --git a/linux/drivers/media/dvb/dvb-usb/cxusb.h b/linux/drivers/media/dvb/dvb-usb/cxusb.h
index 79ca7abb8..4768a2c35 100644
--- a/linux/drivers/media/dvb/dvb-usb/cxusb.h
+++ b/linux/drivers/media/dvb/dvb-usb/cxusb.h
@@ -5,6 +5,8 @@
#include "dvb-usb.h"
/* usb commands - some of it are guesses, don't have a reference yet */
+#define CMD_BLUEBIRD_GPIO_RW 0x05
+
#define CMD_I2C_WRITE 0x08
#define CMD_I2C_READ 0x09
diff --git a/linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index d6d96308c..c94d993a6 100644
--- a/linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -147,6 +147,9 @@
#define USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM 0xdb51
#define USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD 0xdb58
#define USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM 0xdb59
+#define USB_PID_DVICO_BLUEBIRD_DUAL_4 0xdb78
+#define USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2 0xdb70
+#define USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM 0xdb71
#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD 0xdb54
#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM 0xdb55
#define USB_PID_MEDION_MD95700 0x0932
diff --git a/linux/drivers/media/dvb/frontends/mt352.c b/linux/drivers/media/dvb/frontends/mt352.c
index c9500f58a..f9eb120c0 100644
--- a/linux/drivers/media/dvb/frontends/mt352.c
+++ b/linux/drivers/media/dvb/frontends/mt352.c
@@ -153,7 +153,13 @@ static void mt352_calc_input_freq(struct mt352_state* state,
if (state->config.if2)
if2 = state->config.if2;
- ife = (2*adc_clock - if2);
+ if (adc_clock >= if2 * 2)
+ ife = if2;
+ else {
+ ife = adc_clock - (if2 % adc_clock);
+ if (ife > adc_clock / 2)
+ ife = adc_clock - ife;
+ }
value = -16374 * ife / adc_clock;
dprintk("%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n",
__FUNCTION__, if2, ife, adc_clock, value, value & 0x3fff);
diff --git a/linux/drivers/media/dvb/frontends/zl10353.c b/linux/drivers/media/dvb/frontends/zl10353.c
index 6340c6858..276612e00 100644
--- a/linux/drivers/media/dvb/frontends/zl10353.c
+++ b/linux/drivers/media/dvb/frontends/zl10353.c
@@ -1,7 +1,7 @@
/*
* Driver for Zarlink DVB-T ZL10353 demodulator
*
- * Copyright (C) 2006 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
+ * Copyright (C) 2006, 2007 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <linux/kernel.h>
@@ -26,6 +26,7 @@
#include <linux/string.h>
#include <linux/slab.h>
#include "compat.h"
+#include <asm/div64.h>
#include "dvb_frontend.h"
#include "zl10353_priv.h"
@@ -127,9 +128,10 @@ static void zl10353_calc_nominal_rate(struct dvb_frontend *fe,
enum fe_bandwidth bandwidth,
u16 *nominal_rate)
{
- u32 adc_clock = 22528; /* 20.480 MHz on the board(!?) */
- u8 bw;
struct zl10353_state *state = fe->demodulator_priv;
+ u32 adc_clock = 450560; /* 45.056 MHz */
+ u64 value;
+ u8 bw;
if (state->config.adc_clock)
adc_clock = state->config.adc_clock;
@@ -147,12 +149,43 @@ static void zl10353_calc_nominal_rate(struct dvb_frontend *fe,
break;
}
- *nominal_rate = (64 * bw * (1<<16) / (7 * 8) * 4000 / adc_clock + 2) / 4;
+ value = (bw * (u64)10 * (1 << 23) / 7 * 125 + adc_clock / 2);
+ do_div(value, adc_clock);
+ *nominal_rate = value;
dprintk("%s: bw %d, adc_clock %d => 0x%x\n",
__FUNCTION__, bw, adc_clock, *nominal_rate);
}
+static void zl10353_calc_input_freq(struct dvb_frontend *fe,
+ u16 *input_freq)
+{
+ struct zl10353_state *state = fe->demodulator_priv;
+ u32 adc_clock = 450560; /* 45.056 MHz */
+ int if2 = 361667; /* 36.1667 MHz */
+ int ife;
+ u64 value;
+
+ if (state->config.adc_clock)
+ adc_clock = state->config.adc_clock;
+ if (state->config.if2)
+ if2 = state->config.if2;
+
+ if (adc_clock >= if2 * 2)
+ ife = if2;
+ else {
+ ife = adc_clock - (if2 % adc_clock);
+ if (ife > adc_clock / 2)
+ ife = adc_clock - ife;
+ }
+ value = (u64)65536 * ife + adc_clock / 2;
+ do_div(value, adc_clock);
+ *input_freq = -value;
+
+ dprintk("%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n",
+ __FUNCTION__, if2, ife, adc_clock, -(int)value, *input_freq);
+}
+
static int zl10353_sleep(struct dvb_frontend *fe)
{
static u8 zl10353_softdown[] = { 0x50, 0x0C, 0x44 };
@@ -165,7 +198,7 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
struct dvb_frontend_parameters *param)
{
struct zl10353_state *state = fe->demodulator_priv;
- u16 nominal_rate;
+ u16 nominal_rate, input_freq;
u8 pllbuf[6] = { 0x67 };
/* These settings set "auto-everything" and start the FSM. */
@@ -183,40 +216,38 @@ static int zl10353_set_parameters(struct dvb_frontend *fe,
zl10353_single_write(fe, TRL_NOMINAL_RATE_1, msb(nominal_rate));
zl10353_single_write(fe, TRL_NOMINAL_RATE_0, lsb(nominal_rate));
- zl10353_single_write(fe, 0x6C, 0xCD);
- zl10353_single_write(fe, 0x6D, 0x7E);
+ zl10353_calc_input_freq(fe, &input_freq);
+ zl10353_single_write(fe, INPUT_FREQ_1, msb(input_freq));
+ zl10353_single_write(fe, INPUT_FREQ_0, lsb(input_freq));
+
if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 0);
- // if there is no attached secondary tuner, we call set_params to program
- // a potential tuner attached somewhere else
+ /*
+ * If there is no tuner attached to the secondary I2C bus, we call
+ * set_params to program a potential tuner attached somewhere else.
+ * Otherwise, we update the PLL registers via calc_regs.
+ */
if (state->config.no_tuner) {
if (fe->ops.tuner_ops.set_params) {
fe->ops.tuner_ops.set_params(fe, param);
if (fe->ops.i2c_gate_ctrl)
fe->ops.i2c_gate_ctrl(fe, 0);
}
- }
-
- // if pllbuf is defined, retrieve the settings
- if (fe->ops.tuner_ops.calc_regs) {
- fe->ops.tuner_ops.calc_regs(fe, param, pllbuf+1, 5);
+ } else if (fe->ops.tuner_ops.calc_regs) {
+ fe->ops.tuner_ops.calc_regs(fe, param, pllbuf + 1, 5);
pllbuf[1] <<= 1;
- } else {
- // fake pllbuf settings
- pllbuf[1] = 0x61 << 1;
- pllbuf[2] = 0;
- pllbuf[3] = 0;
- pllbuf[3] = 0;
- pllbuf[4] = 0;
+ zl10353_write(fe, pllbuf, sizeof(pllbuf));
}
- // there is no call to _just_ start decoding, so we send the pllbuf anyway
- // even if there isn't a PLL attached to the secondary bus
- zl10353_write(fe, pllbuf, sizeof(pllbuf));
-
zl10353_single_write(fe, 0x5F, 0x13);
- zl10353_single_write(fe, 0x70, 0x01);
+
+ /* If no attached tuner or invalid PLL registers, just start the FSM. */
+ if (state->config.no_tuner || fe->ops.tuner_ops.calc_regs == NULL)
+ zl10353_single_write(fe, FSM_GO, 0x01);
+ else
+ zl10353_single_write(fe, TUNER_GO, 0x01);
+
udelay(250);
zl10353_single_write(fe, 0xE4, 0x00);
zl10353_single_write(fe, 0xE5, 0x2A);
diff --git a/linux/drivers/media/dvb/frontends/zl10353.h b/linux/drivers/media/dvb/frontends/zl10353.h
index cb274dc12..fc734c22b 100644
--- a/linux/drivers/media/dvb/frontends/zl10353.h
+++ b/linux/drivers/media/dvb/frontends/zl10353.h
@@ -1,7 +1,7 @@
/*
* Driver for Zarlink DVB-T ZL10353 demodulator
*
- * Copyright (C) 2006 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
+ * Copyright (C) 2006, 2007 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,8 +29,9 @@ struct zl10353_config
/* demodulator's I2C address */
u8 demod_address;
- /* frequencies in kHz */
- int adc_clock; // default: 22528
+ /* frequencies in units of 0.1kHz */
+ int adc_clock; /* default: 450560 (45.056 MHz) */
+ int if2; /* default: 361667 (36.1667 MHz) */
/* set if no pll is connected to the secondary i2c bus */
int no_tuner;
@@ -49,6 +50,6 @@ static inline struct dvb_frontend* zl10353_attach(const struct zl10353_config *c
printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
return NULL;
}
-#endif // CONFIG_DVB_ZL10353
+#endif /* CONFIG_DVB_ZL10353 */
#endif /* ZL10353_H */
diff --git a/linux/drivers/media/dvb/frontends/zl10353_priv.h b/linux/drivers/media/dvb/frontends/zl10353_priv.h
index 4962434b3..fcad92219 100644
--- a/linux/drivers/media/dvb/frontends/zl10353_priv.h
+++ b/linux/drivers/media/dvb/frontends/zl10353_priv.h
@@ -1,7 +1,7 @@
/*
* Driver for Zarlink DVB-T ZL10353 demodulator
*
- * Copyright (C) 2006 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
+ * Copyright (C) 2006, 2007 Christopher Pascoe <c.pascoe@itee.uq.edu.au>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _ZL10353_PRIV_
@@ -48,6 +48,10 @@ enum zl10353_reg_addr {
RS_UBC_0 = 0x15,
TRL_NOMINAL_RATE_1 = 0x65,
TRL_NOMINAL_RATE_0 = 0x66,
+ INPUT_FREQ_1 = 0x6C,
+ INPUT_FREQ_0 = 0x6D,
+ TUNER_GO = 0x70,
+ FSM_GO = 0x71,
CHIP_ID = 0x7F,
};
diff --git a/linux/drivers/media/video/em28xx/em28xx-cards.c b/linux/drivers/media/video/em28xx/em28xx-cards.c
index aa51a833b..7bca01008 100644
--- a/linux/drivers/media/video/em28xx/em28xx-cards.c
+++ b/linux/drivers/media/video/em28xx/em28xx-cards.c
@@ -1,5 +1,6 @@
/*
- em28xx-cards.c - driver for Empia EM2800/EM2820/2840 USB video capture devices
+ em28xx-cards.c - driver for Empia EM2800/EM2820/2840 USB
+ video capture devices
Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
Markus Rechberger <mrechberger@gmail.com>
@@ -56,15 +57,15 @@ struct em28xx_board em28xx_boards[] = {
.tda9887_conf = TDA9887_PRESENT,
.has_tuner = 1,
.decoder = EM28XX_SAA7113,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = SAA7115_COMPOSITE0,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = SAA7115_SVIDEO3,
.amux = 1,
- }},
+ } },
},
[EM2820_BOARD_UNKNOWN] = {
.name = "Unknown EM2750/28xx video grabber",
@@ -77,15 +78,15 @@ struct em28xx_board em28xx_boards[] = {
.tda9887_conf = TDA9887_PRESENT,
.has_tuner = 1,
.decoder = EM28XX_SAA7113,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = SAA7115_COMPOSITE0,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = SAA7115_SVIDEO3,
.amux = 1,
- }},
+ } },
},
[EM2820_BOARD_TERRATEC_CINERGY_250] = {
.name = "Terratec Cinergy 250 USB",
@@ -94,19 +95,19 @@ struct em28xx_board em28xx_boards[] = {
.tda9887_conf = TDA9887_PRESENT,
.has_tuner = 1,
.decoder = EM28XX_SAA7113,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = SAA7115_COMPOSITE2,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = SAA7115_COMPOSITE0,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = SAA7115_SVIDEO3,
.amux = 1,
- }},
+ } },
},
[EM2820_BOARD_PINNACLE_USB_2] = {
.name = "Pinnacle PCTV USB 2",
@@ -115,39 +116,41 @@ struct em28xx_board em28xx_boards[] = {
.tda9887_conf = TDA9887_PRESENT,
.has_tuner = 1,
.decoder = EM28XX_SAA7113,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = SAA7115_COMPOSITE2,
.amux = 0,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = SAA7115_COMPOSITE0,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = SAA7115_SVIDEO3,
.amux = 1,
- }},
+ } },
},
[EM2820_BOARD_HAUPPAUGE_WINTV_USB_2] = {
.name = "Hauppauge WinTV USB 2",
.vchannels = 3,
.tuner_type = TUNER_PHILIPS_FM1236_MK3,
- .tda9887_conf = TDA9887_PRESENT|TDA9887_PORT1_ACTIVE|TDA9887_PORT2_ACTIVE,
+ .tda9887_conf = TDA9887_PRESENT |
+ TDA9887_PORT1_ACTIVE|
+ TDA9887_PORT2_ACTIVE,
.has_tuner = 1,
.decoder = EM28XX_TVP5150,
.has_msp34xx = 1,
/*FIXME: S-Video not tested */
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = TVP5150_COMPOSITE0,
.amux = MSP_INPUT_DEFAULT,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = TVP5150_SVIDEO,
.amux = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
- }},
+ } },
},
[EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = {
.name = "Hauppauge WinTV HVR 900",
@@ -155,21 +158,21 @@ struct em28xx_board em28xx_boards[] = {
.tda9887_conf = TDA9887_PRESENT,
.tuner_type = TUNER_XC2028,
.has_tuner = 1,
- .xc2028_type = XC2028_FIRM_MTS,
+ .mts_firmware = 1,
.decoder = EM28XX_TVP5150,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = TVP5150_COMPOSITE0,
.amux = 0,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = TVP5150_COMPOSITE1,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = TVP5150_SVIDEO,
.amux = 1,
- }},
+ } },
},
[EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950] = {
.name = "Hauppauge WinTV HVR 950",
@@ -178,19 +181,19 @@ struct em28xx_board em28xx_boards[] = {
.tuner_type = TUNER_XC2028,
.has_tuner = 1,
.decoder = EM28XX_TVP5150,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = TVP5150_COMPOSITE0,
.amux = 0,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = TVP5150_COMPOSITE1,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = TVP5150_SVIDEO,
.amux = 1,
- }},
+ } },
},
[EM2880_BOARD_TERRATEC_HYBRID_XS] = {
.name = "Terratec Hybrid XS",
@@ -199,22 +202,23 @@ struct em28xx_board em28xx_boards[] = {
.has_tuner = 1,
.tuner_type = TUNER_XC2028,
.decoder = EM28XX_TVP5150,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = TVP5150_COMPOSITE0,
.amux = 0,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = TVP5150_COMPOSITE1,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = TVP5150_SVIDEO,
.amux = 1,
- }},
+ } },
},
- /* maybe there's a reason behind it why Terratec sells the Hybrid XS as Prodigy XS with a
- * different PID, let's keep it separated for now maybe we'll need it lateron */
+ /* maybe there's a reason behind it why Terratec sells the Hybrid XS
+ as Prodigy XS with a different PID, let's keep it separated for now
+ maybe we'll need it lateron */
[EM2880_BOARD_TERRATEC_PRODIGY_XS] = {
.name = "Terratec Prodigy XS",
.vchannels = 3,
@@ -222,40 +226,42 @@ struct em28xx_board em28xx_boards[] = {
.has_tuner = 1,
.tuner_type = TUNER_XC2028,
.decoder = EM28XX_TVP5150,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = TVP5150_COMPOSITE0,
.amux = 0,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = TVP5150_COMPOSITE1,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = TVP5150_SVIDEO,
.amux = 1,
- }},
+ } },
},
[EM2820_BOARD_MSI_VOX_USB_2] = {
.name = "MSI VOX USB 2.0",
.vchannels = 3,
.tuner_type = TUNER_LG_PAL_NEW_TAPC,
- .tda9887_conf = TDA9887_PRESENT|TDA9887_PORT1_ACTIVE|TDA9887_PORT2_ACTIVE,
+ .tda9887_conf = TDA9887_PRESENT |
+ TDA9887_PORT1_ACTIVE |
+ TDA9887_PORT2_ACTIVE,
.has_tuner = 1,
.decoder = EM28XX_SAA7114,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = SAA7115_COMPOSITE4,
.amux = 0,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = SAA7115_COMPOSITE0,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = SAA7115_SVIDEO3,
.amux = 1,
- }},
+ } },
},
[EM2800_BOARD_TERRATEC_CINERGY_200] = {
.name = "Terratec Cinergy 200 USB",
@@ -265,19 +271,19 @@ struct em28xx_board em28xx_boards[] = {
.tda9887_conf = TDA9887_PRESENT,
.has_tuner = 1,
.decoder = EM28XX_SAA7113,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = SAA7115_COMPOSITE2,
.amux = 0,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = SAA7115_COMPOSITE0,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = SAA7115_SVIDEO3,
.amux = 1,
- }},
+ } },
},
[EM2800_BOARD_LEADTEK_WINFAST_USBII] = {
.name = "Leadtek Winfast USB II",
@@ -287,19 +293,19 @@ struct em28xx_board em28xx_boards[] = {
.tda9887_conf = TDA9887_PRESENT,
.has_tuner = 1,
.decoder = EM28XX_SAA7113,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = SAA7115_COMPOSITE2,
.amux = 0,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = SAA7115_COMPOSITE0,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = SAA7115_SVIDEO3,
.amux = 1,
- }},
+ } },
},
[EM2800_BOARD_KWORLD_USB2800] = {
.name = "Kworld USB2800",
@@ -309,34 +315,34 @@ struct em28xx_board em28xx_boards[] = {
.tda9887_conf = TDA9887_PRESENT,
.has_tuner = 1,
.decoder = EM28XX_SAA7113,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = SAA7115_COMPOSITE2,
.amux = 0,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = SAA7115_COMPOSITE0,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = SAA7115_SVIDEO3,
.amux = 1,
- }},
+ } },
},
[EM2820_BOARD_PINNACLE_DVC_90] = {
.name = "Pinnacle Dazzle DVC 90",
.vchannels = 3,
.has_tuner = 0,
.decoder = EM28XX_SAA7113,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = SAA7115_COMPOSITE0,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = SAA7115_SVIDEO3,
.amux = 1,
- }},
+ } },
},
[EM2800_BOARD_VGEAR_POCKETTV] = {
.name = "V-Gear PocketTV",
@@ -346,19 +352,19 @@ struct em28xx_board em28xx_boards[] = {
.tda9887_conf = TDA9887_PRESENT,
.has_tuner = 1,
.decoder = EM28XX_SAA7113,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = SAA7115_COMPOSITE2,
.amux = 0,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = SAA7115_COMPOSITE0,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = SAA7115_SVIDEO3,
.amux = 1,
- }},
+ } },
},
[EM2820_BOARD_PROLINK_PLAYTV_USB2] = {
.name = "Pixelview Prolink PlayTV USB 2.0",
@@ -366,56 +372,73 @@ struct em28xx_board em28xx_boards[] = {
.tda9887_conf = TDA9887_PRESENT,
.has_tuner = 1,
.decoder = EM28XX_SAA7113,
- .input = {{
+ .input = { {
.type = EM28XX_VMUX_TELEVISION,
.vmux = SAA7115_COMPOSITE2,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_COMPOSITE1,
.vmux = SAA7115_COMPOSITE0,
.amux = 1,
- },{
+ }, {
.type = EM28XX_VMUX_SVIDEO,
.vmux = SAA7115_SVIDEO3,
.amux = 1,
- }},
+ } },
},
};
const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
/* table of devices that work with this driver */
struct usb_device_id em28xx_id_table [] = {
- { USB_DEVICE(0xeb1a, 0x2750), .driver_info = EM2820_BOARD_UNKNOWN },
- { USB_DEVICE(0xeb1a, 0x2800), .driver_info = EM2800_BOARD_UNKNOWN },
- { USB_DEVICE(0xeb1a, 0x2820), .driver_info = EM2820_BOARD_UNKNOWN },
- { USB_DEVICE(0xeb1a, 0x2821), .driver_info = EM2820_BOARD_UNKNOWN },
- { USB_DEVICE(0xeb1a, 0x2860), .driver_info = EM2820_BOARD_UNKNOWN },
- { USB_DEVICE(0xeb1a, 0x2861), .driver_info = EM2820_BOARD_UNKNOWN },
- { USB_DEVICE(0xeb1a, 0x2870), .driver_info = EM2820_BOARD_UNKNOWN },
- { USB_DEVICE(0xeb1a, 0x2881), .driver_info = EM2820_BOARD_UNKNOWN },
- { USB_DEVICE(0xeb1a, 0x2883), .driver_info = EM2820_BOARD_UNKNOWN },
- { USB_DEVICE(0x0ccd, 0x0036), .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
- { USB_DEVICE(0x2304, 0x0208), .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
- { USB_DEVICE(0x2040, 0x4200), .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
- { USB_DEVICE(0x2304, 0x0207), .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
- { USB_DEVICE(0x2040, 0x6500), .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
- { USB_DEVICE(0x2040, 0x6513), .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 },
- { USB_DEVICE(0x0ccd, 0x0042), .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS },
- { USB_DEVICE(0x0ccd, 0x0047), .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS },
+ { USB_DEVICE(0xeb1a, 0x2750),
+ .driver_info = EM2820_BOARD_UNKNOWN },
+ { USB_DEVICE(0xeb1a, 0x2800),
+ .driver_info = EM2800_BOARD_UNKNOWN },
+ { USB_DEVICE(0xeb1a, 0x2820),
+ .driver_info = EM2820_BOARD_UNKNOWN },
+ { USB_DEVICE(0xeb1a, 0x2821),
+ .driver_info = EM2820_BOARD_UNKNOWN },
+ { USB_DEVICE(0xeb1a, 0x2860),
+ .driver_info = EM2820_BOARD_UNKNOWN },
+ { USB_DEVICE(0xeb1a, 0x2861),
+ .driver_info = EM2820_BOARD_UNKNOWN },
+ { USB_DEVICE(0xeb1a, 0x2870),
+ .driver_info = EM2820_BOARD_UNKNOWN },
+ { USB_DEVICE(0xeb1a, 0x2881),
+ .driver_info = EM2820_BOARD_UNKNOWN },
+ { USB_DEVICE(0xeb1a, 0x2883),
+ .driver_info = EM2820_BOARD_UNKNOWN },
+ { USB_DEVICE(0x0ccd, 0x0036),
+ .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
+ { USB_DEVICE(0x2304, 0x0208),
+ .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
+ { USB_DEVICE(0x2040, 0x4200),
+ .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
+ { USB_DEVICE(0x2304, 0x0207),
+ .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
+ { USB_DEVICE(0x2040, 0x6500),
+ .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
+ { USB_DEVICE(0x2040, 0x6513),
+ .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 },
+ { USB_DEVICE(0x0ccd, 0x0042),
+ .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS },
+ { USB_DEVICE(0x0ccd, 0x0047),
+ .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS },
{ },
};
-MODULE_DEVICE_TABLE (usb, em28xx_id_table);
+MODULE_DEVICE_TABLE(usb, em28xx_id_table);
/* EEPROM hash table for devices with generic USB IDs */
static struct em28xx_hash_table em28xx_eeprom_hash [] = {
/* P/N: SA 60002070465 Tuner: TVF7533-MF */
- { 0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF },
+ {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF},
};
/* I2C devicelist hash table for devices with generic USB IDs */
static struct em28xx_hash_table em28xx_i2c_hash[] = {
- { 0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC },
- { 0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC },
+ {0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC},
+ {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
};
/* Since em28xx_pre_card_setup() requires a proper dev->model,
@@ -424,7 +447,7 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
void em28xx_pre_card_setup(struct em28xx *dev)
{
/* request some modules */
- switch(dev->model){
+ switch (dev->model) {
case EM2880_BOARD_TERRATEC_PRODIGY_XS:
case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
@@ -455,7 +478,7 @@ static int em28xx_tuner_callback(void *ptr, int command, int arg)
return rc;
}
-static void em28xx_config_tuner (struct em28xx *dev)
+static void em28xx_config_tuner(struct em28xx *dev)
{
struct v4l2_priv_tun_config xc2028_cfg;
struct xc2028_ctrl ctl;
@@ -473,11 +496,11 @@ static void em28xx_config_tuner (struct em28xx *dev)
em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
if (dev->tuner_type == TUNER_XC2028) {
- memset (&ctl, 0, sizeof(ctl));
+ memset(&ctl, 0, sizeof(ctl));
ctl.fname = XC2028_DEFAULT_FIRMWARE;
ctl.max_len = 64;
- ctl.type = em28xx_boards[dev->model].xc2028_type;
+ ctl.mts = em28xx_boards[dev->model].mts_firmware;
xc2028_cfg.tuner = TUNER_XC2028;
xc2028_cfg.priv = &ctl;
@@ -649,5 +672,5 @@ void em28xx_card_setup(struct em28xx *dev)
request_module("tuner");
#endif
- em28xx_config_tuner (dev);
+ em28xx_config_tuner(dev);
}
diff --git a/linux/drivers/media/video/em28xx/em28xx.h b/linux/drivers/media/video/em28xx/em28xx.h
index efc7d25c3..5e5f4e7a9 100644
--- a/linux/drivers/media/video/em28xx/em28xx.h
+++ b/linux/drivers/media/video/em28xx/em28xx.h
@@ -179,9 +179,9 @@ struct em28xx_board {
unsigned int has_tuner:1;
unsigned int has_msp34xx:1;
+ unsigned int mts_firmware:1;
enum em28xx_decoder decoder;
- int xc2028_type;
struct em28xx_input input[MAX_EM28XX_INPUT];
};
diff --git a/linux/drivers/media/video/saa7134/saa7134-alsa.c b/linux/drivers/media/video/saa7134/saa7134-alsa.c
index 456f74eb7..c6715b054 100644
--- a/linux/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/linux/drivers/media/video/saa7134/saa7134-alsa.c
@@ -471,7 +471,7 @@ static struct snd_pcm_hardware snd_card_saa7134_capture =
.buffer_bytes_max = (256*1024),
.period_bytes_min = 64,
.period_bytes_max = (256*1024),
- .periods_min = 2,
+ .periods_min = 4,
.periods_max = 1024,
};
@@ -505,7 +505,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
snd_assert(period_size >= 0x100 && period_size <= 0x10000,
return -EINVAL);
- snd_assert(periods >= 2, return -EINVAL);
+ snd_assert(periods >= 4, return -EINVAL);
snd_assert(period_size * periods <= 1024 * 1024, return -EINVAL);
dev = saa7134->dev;
@@ -661,7 +661,14 @@ static int snd_card_saa7134_capture_open(struct snd_pcm_substream * substream)
saa7134_tvaudio_setmute(dev);
}
- if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
+ err = snd_pcm_hw_constraint_integer(runtime,
+ SNDRV_PCM_HW_PARAM_PERIODS);
+ if (err < 0)
+ return err;
+
+ err = snd_pcm_hw_constraint_step(runtime, 0,
+ SNDRV_PCM_HW_PARAM_PERIODS, 2);
+ if (err < 0)
return err;
return 0;
diff --git a/linux/drivers/media/video/saa7134/saa7134-core.c b/linux/drivers/media/video/saa7134/saa7134-core.c
index b8b8977fe..adc194c22 100644
--- a/linux/drivers/media/video/saa7134/saa7134-core.c
+++ b/linux/drivers/media/video/saa7134/saa7134-core.c
@@ -649,6 +649,10 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id)
unsigned long report,status;
int loop, handled = 0;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 23)
+ /* To make sure we see correct value of dev->insuspend */
+ smp_rmb();
+#endif
if (dev->insuspend)
goto out;
@@ -1275,8 +1279,16 @@ static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state)
saa_writel(SAA7134_IRQ2, 0);
saa_writel(SAA7134_MAIN_CTRL, 0);
- synchronize_irq(pci_dev->irq);
dev->insuspend = 1;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 23)
+ smp_wmb();
+#endif
+ synchronize_irq(pci_dev->irq);
+
+ /* ACK interrupts once more, just in case,
+ since the IRQ handler won't ack them anymore*/
+
+ saa_writel(SAA7134_IRQ_REPORT, saa_readl(SAA7134_IRQ_REPORT));
/* Disable timeout timers - if we have active buffers, we will
fill them on resume*/
@@ -1288,10 +1300,10 @@ static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state)
if (dev->remote)
saa7134_ir_stop(dev);
- pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
pci_save_state(pci_dev);
+ pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
- return 0;
+ return 0;
}
static int saa7134_resume(struct pci_dev *pci_dev)
@@ -1300,8 +1312,8 @@ static int saa7134_resume(struct pci_dev *pci_dev)
struct saa7134_dev *dev = pci_get_drvdata(pci_dev);
unsigned int flags;
- pci_restore_state(pci_dev);
pci_set_power_state(pci_dev, PCI_D0);
+ pci_restore_state(pci_dev);
/* Do things that are done in saa7134_initdev ,
except of initializing memory structures.*/
@@ -1317,6 +1329,7 @@ static int saa7134_resume(struct pci_dev *pci_dev)
saa7134_ir_start(dev, dev->remote);
saa7134_hw_enable1(dev);
+ msleep(100);
saa7134_board_init2(dev);
@@ -1324,10 +1337,13 @@ static int saa7134_resume(struct pci_dev *pci_dev)
saa7134_set_tvnorm_hw(dev);
saa7134_tvaudio_setmute(dev);
saa7134_tvaudio_setvolume(dev, dev->ctl_volume);
+ saa7134_tvaudio_init(dev);
saa7134_tvaudio_do_scan(dev);
saa7134_enable_i2s(dev);
saa7134_hw_enable2(dev);
+ saa7134_irq_video_signalchange(dev);
+
/*resume unfinished buffer(s)*/
spin_lock_irqsave(&dev->slock, flags);
saa7134_buffer_requeue(dev, &dev->video_q);
@@ -1341,6 +1357,7 @@ static int saa7134_resume(struct pci_dev *pci_dev)
/* start DMA now*/
dev->insuspend = 0;
+ smp_wmb();
saa7134_set_dmabits(dev);
spin_unlock_irqrestore(&dev->slock, flags);
diff --git a/linux/drivers/media/video/saa7134/saa7134-tvaudio.c b/linux/drivers/media/video/saa7134/saa7134-tvaudio.c
index 5832d552f..3ec368172 100644
--- a/linux/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/linux/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -165,32 +165,6 @@ static struct saa7134_tvaudio tvaudio[] = {
/* ------------------------------------------------------------------ */
-static void tvaudio_init(struct saa7134_dev *dev)
-{
- int clock = saa7134_boards[dev->board].audio_clock;
-
- if (UNSET != audio_clock_override)
- clock = audio_clock_override;
-
- /* init all audio registers */
- saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x00);
- if (need_resched())
- schedule();
- else
- udelay(10);
-
- saa_writeb(SAA7134_AUDIO_CLOCK0, clock & 0xff);
- saa_writeb(SAA7134_AUDIO_CLOCK1, (clock >> 8) & 0xff);
- saa_writeb(SAA7134_AUDIO_CLOCK2, (clock >> 16) & 0xff);
- /* frame locked audio is mandatory for NICAM */
- saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x01);
-
- saa_writeb(SAA7134_NICAM_ERROR_LOW, 0x14);
- saa_writeb(SAA7134_NICAM_ERROR_HIGH, 0x50);
- saa_writeb(SAA7134_MONITOR_SELECT, 0xa0);
- saa_writeb(SAA7134_FM_DEMATRIX, 0x80);
-}
-
static u32 tvaudio_carr2reg(u32 carrier)
{
u64 a = carrier;
@@ -545,9 +519,13 @@ static int tvaudio_thread(void *data)
dev->thread.scan1 = dev->thread.scan2;
dprintk("tvaudio thread scan start [%d]\n",dev->thread.scan1);
dev->tvaudio = NULL;
- tvaudio_init(dev);
+
+ saa_writeb(SAA7134_MONITOR_SELECT, 0xa0);
+ saa_writeb(SAA7134_FM_DEMATRIX, 0x80);
+
if (dev->ctl_automute)
dev->automute = 1;
+
mute_input_7134(dev);
/* give the tuner some time */
@@ -830,7 +808,7 @@ static int mute_input_7133(struct saa7134_dev *dev)
static int tvaudio_thread_ddep(void *data)
{
struct saa7134_dev *dev = data;
- u32 value, norms, clock;
+ u32 value, norms;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,61)
lock_kernel();
@@ -843,23 +821,11 @@ static int tvaudio_thread_ddep(void *data)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23)
set_freezable();
#endif
-
- clock = saa7134_boards[dev->board].audio_clock;
- if (UNSET != audio_clock_override)
- clock = audio_clock_override;
- saa_writel(0x598 >> 2, clock);
-
- /* unmute */
- saa_dsp_writel(dev, 0x474 >> 2, 0x00);
- saa_dsp_writel(dev, 0x450 >> 2, 0x00);
-
for (;;) {
tvaudio_sleep(dev,-1);
if (kthread_should_stop())
goto done;
-
restart:
-
try_to_freeze();
dev->thread.scan1 = dev->thread.scan2;
@@ -1033,6 +999,38 @@ int saa7134_tvaudio_getstereo(struct saa7134_dev *dev)
return retval;
}
+void saa7134_tvaudio_init(struct saa7134_dev *dev)
+{
+ int clock = saa7134_boards[dev->board].audio_clock;
+
+ if (UNSET != audio_clock_override)
+ clock = audio_clock_override;
+
+ switch (dev->pci->device) {
+ case PCI_DEVICE_ID_PHILIPS_SAA7134:
+ /* init all audio registers */
+ saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x00);
+ if (need_resched())
+ schedule();
+ else
+ udelay(10);
+
+ saa_writeb(SAA7134_AUDIO_CLOCK0, clock & 0xff);
+ saa_writeb(SAA7134_AUDIO_CLOCK1, (clock >> 8) & 0xff);
+ saa_writeb(SAA7134_AUDIO_CLOCK2, (clock >> 16) & 0xff);
+ /* frame locked audio is mandatory for NICAM */
+ saa_writeb(SAA7134_AUDIO_PLL_CTRL, 0x01);
+ saa_writeb(SAA7134_NICAM_ERROR_LOW, 0x14);
+ saa_writeb(SAA7134_NICAM_ERROR_HIGH, 0x50);
+ break;
+ case PCI_DEVICE_ID_PHILIPS_SAA7133:
+ case PCI_DEVICE_ID_PHILIPS_SAA7135:
+ saa_writel(0x598 >> 2, clock);
+ saa_dsp_writel(dev, 0x474 >> 2, 0x00);
+ saa_dsp_writel(dev, 0x450 >> 2, 0x00);
+ }
+}
+
int saa7134_tvaudio_init2(struct saa7134_dev *dev)
{
int (*my_thread)(void *data) = NULL;
@@ -1049,6 +1047,7 @@ int saa7134_tvaudio_init2(struct saa7134_dev *dev)
dev->thread.thread = NULL;
if (my_thread) {
+ saa7134_tvaudio_init(dev);
/* start tvaudio thread */
dev->thread.thread = kthread_run(my_thread, dev, "%s", dev->name);
if (IS_ERR(dev->thread.thread)) {
diff --git a/linux/drivers/media/video/saa7134/saa7134.h b/linux/drivers/media/video/saa7134/saa7134.h
index 510e424e2..0df575366 100644
--- a/linux/drivers/media/video/saa7134/saa7134.h
+++ b/linux/drivers/media/video/saa7134/saa7134.h
@@ -699,6 +699,7 @@ void saa7134_tvaudio_setinput(struct saa7134_dev *dev,
void saa7134_tvaudio_setvolume(struct saa7134_dev *dev, int level);
int saa7134_tvaudio_getstereo(struct saa7134_dev *dev);
+void saa7134_tvaudio_init(struct saa7134_dev *dev);
int saa7134_tvaudio_init2(struct saa7134_dev *dev);
int saa7134_tvaudio_fini(struct saa7134_dev *dev);
int saa7134_tvaudio_do_scan(struct saa7134_dev *dev);
diff --git a/linux/drivers/media/video/tuner-i2c.h b/linux/drivers/media/video/tuner-i2c.h
index b5ac189ba..d7cf72c3f 100644
--- a/linux/drivers/media/video/tuner-i2c.h
+++ b/linux/drivers/media/video/tuner-i2c.h
@@ -46,6 +46,19 @@ static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf,
return (ret == 1) ? len : ret;
}
+static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props,
+ char *obuf, int olen,
+ char *ibuf, int ilen)
+{
+ struct i2c_msg msg[2] = { { .addr = props->addr, .flags = 0,
+ .buf = obuf, .len = olen },
+ { .addr = props->addr, .flags = I2C_M_RD,
+ .buf = ibuf, .len = ilen } };
+ int ret = i2c_transfer(props->adap, msg, 2);
+
+ return (ret == 2) ? ilen : ret;
+}
+
#ifndef __TUNER_DRIVER_H__
#define tuner_warn(fmt, arg...) do { \
printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX, \
diff --git a/linux/drivers/media/video/tuner-xc2028-types.h b/linux/drivers/media/video/tuner-xc2028-types.h
index a9e2e0562..d0057fbf0 100644
--- a/linux/drivers/media/video/tuner-xc2028-types.h
+++ b/linux/drivers/media/video/tuner-xc2028-types.h
@@ -8,6 +8,7 @@
/* BASE firmware should be loaded before any other firmware */
#define BASE (1<<0)
+#define BASE_TYPES (BASE|F8MHZ|MTS|FM|INPUT1|INPUT2|INIT1)
/* F8MHZ marks BASE firmwares for 8 MHz Bandwidth */
#define F8MHZ (1<<1)
@@ -37,9 +38,13 @@
#define DTV78 (1<<8)
#define DTV8 (1<<9)
+#define DTV_TYPES (D2620|D2633|DTV6|QAM|DTV7|DTV78|DTV8|ATSC)
+
/* There's a FM | BASE firmware + FM specific firmware (std=0) */
#define FM (1<<10)
+#define STD_SPECIFIC_TYPES (MTS|FM|LCD|NOGD)
+
/* Applies only for FM firmware
Makes it use RF input 1 (pin #2) instead of input 2 (pin #4)
*/
@@ -60,6 +65,7 @@
/* Old firmwares were broken into init0 and init1 */
#define INIT1 (1<<14)
+/* SCODE firmware selects particular behaviours */
#define MONO (1 << 15)
#define ATSC (1 << 16)
#define IF (1 << 17)
@@ -76,6 +82,13 @@
#define INPUT2 (1 << 28)
#define SCODE (1 << 29)
+/* This flag identifies that the scode table has a new format */
+#define HAS_IF (1 << 30)
+
+#define SCODE_TYPES (MTS|DTV6|QAM|DTV7|DTV78|DTV8|LCD|NOGD|MONO|ATSC|IF| \
+ LG60|ATI638|OREN538|OREN36|TOYOTA388|TOYOTA794| \
+ DIBCOM52|ZARLINK456|CHINA|F6MHZ|SCODE)
+
/* Newer types to be moved to videodev2.h */
#define V4L2_STD_SECAM_K3 (0x04000000)
diff --git a/linux/drivers/media/video/tuner-xc2028.c b/linux/drivers/media/video/tuner-xc2028.c
index d8d960e7b..0689e1d58 100644
--- a/linux/drivers/media/video/tuner-xc2028.c
+++ b/linux/drivers/media/video/tuner-xc2028.c
@@ -55,14 +55,26 @@ MODULE_PARM_DESC(audio_std,
"NICAM/B\n");
static LIST_HEAD(xc2028_list);
+static DEFINE_MUTEX(xc2028_list_mutex);
+
/* struct for storing firmware table */
struct firmware_description {
unsigned int type;
v4l2_std_id id;
+ __u16 int_freq;
unsigned char *ptr;
unsigned int size;
};
+struct firmware_properties {
+ unsigned int type;
+ v4l2_std_id id;
+ v4l2_std_id std_req;
+ __u16 int_freq;
+ unsigned int scode_table;
+ int scode_nr;
+};
+
struct xc2028_data {
struct list_head xc2028_list;
struct tuner_i2c_props i2c_props;
@@ -74,22 +86,14 @@ struct xc2028_data {
struct firmware_description *firm;
int firm_size;
+ __u16 firm_version;
- __u16 version;
+ __u16 hwmodel;
+ __u16 hwvers;
struct xc2028_ctrl ctrl;
- v4l2_std_id firm_type; /* video stds supported
- by current firmware */
- fe_bandwidth_t bandwidth; /* Firmware bandwidth:
- 6M, 7M or 8M */
- int need_load_generic; /* The generic firmware
- were loaded? */
-
- int max_len; /* Max firmware chunk */
-
- enum tuner_mode mode;
- struct i2c_client *i2c_client;
+ struct firmware_properties cur_fw;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 16)
struct mutex lock;
@@ -98,51 +102,61 @@ struct xc2028_data {
#endif
};
-#define i2c_send(rc, priv, buf, size) do { \
- rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size); \
- if (size != rc) \
- tuner_err("i2c output error: rc = %d (should be %d)\n", \
- rc, (int)size); \
-} while (0)
-
-#define i2c_rcv(rc, priv, buf, size) do { \
- rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size); \
- if (size != rc) \
+#define i2c_send(priv, buf, size) ({ \
+ int _rc; \
+ _rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size); \
+ if (size != _rc) \
+ tuner_info("i2c output error: rc = %d (should be %d)\n",\
+ _rc, (int)size); \
+ _rc; \
+})
+
+#define i2c_rcv(priv, buf, size) ({ \
+ int _rc; \
+ _rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size); \
+ if (size != _rc) \
tuner_err("i2c input error: rc = %d (should be %d)\n", \
- rc, (int)size); \
-} while (0)
+ _rc, (int)size); \
+ _rc; \
+})
+
+#define i2c_send_recv(priv, obuf, osize, ibuf, isize) ({ \
+ int _rc; \
+ _rc = tuner_i2c_xfer_send_recv(&priv->i2c_props, obuf, osize, \
+ ibuf, isize); \
+ if (isize != _rc) \
+ tuner_err("i2c input error: rc = %d (should be %d)\n", \
+ _rc, (int)isize); \
+ _rc; \
+})
-#define send_seq(priv, data...) do { \
- int rc; \
+#define send_seq(priv, data...) ({ \
static u8 _val[] = data; \
+ int _rc; \
if (sizeof(_val) != \
- (rc = tuner_i2c_xfer_send(&priv->i2c_props, \
+ (_rc = tuner_i2c_xfer_send(&priv->i2c_props, \
_val, sizeof(_val)))) { \
- tuner_err("Error on line %d: %d\n", __LINE__, rc); \
- return -EINVAL; \
- } \
- msleep(10); \
-} while (0)
+ tuner_err("Error on line %d: %d\n", __LINE__, _rc); \
+ } else \
+ msleep(10); \
+ _rc; \
+})
-static unsigned int xc2028_get_reg(struct xc2028_data *priv, u16 reg)
+static unsigned int xc2028_get_reg(struct xc2028_data *priv, u16 reg, u16 *val)
{
- int rc;
unsigned char buf[2];
+ unsigned char ibuf[2];
- tuner_dbg("%s called\n", __FUNCTION__);
+ tuner_dbg("%s %04x called\n", __FUNCTION__, reg);
- buf[0] = reg>>8;
+ buf[0] = reg >> 8;
buf[1] = (unsigned char) reg;
- i2c_send(rc, priv, buf, 2);
- if (rc < 0)
- return rc;
+ if (i2c_send_recv(priv, buf, 2, ibuf, 2) != 2)
+ return -EIO;
- i2c_rcv(rc, priv, buf, 2);
- if (rc < 0)
- return rc;
-
- return (buf[1]) | (buf[0] << 8);
+ *val = (ibuf[1]) | (ibuf[0] << 8);
+ return 0;
}
void dump_firm_type(unsigned int type)
@@ -211,17 +225,17 @@ void dump_firm_type(unsigned int type)
static v4l2_std_id parse_audio_std_option(void)
{
- if (strcasecmp(audio_std, "A2"))
+ if (strcasecmp(audio_std, "A2") == 0)
return V4L2_STD_A2;
- if (strcasecmp(audio_std, "A2/A"))
+ if (strcasecmp(audio_std, "A2/A") == 0)
return V4L2_STD_A2_A;
- if (strcasecmp(audio_std, "A2/B"))
+ if (strcasecmp(audio_std, "A2/B") == 0)
return V4L2_STD_A2_B;
- if (strcasecmp(audio_std, "NICAM"))
+ if (strcasecmp(audio_std, "NICAM") == 0)
return V4L2_STD_NICAM;
- if (strcasecmp(audio_std, "NICAM/A"))
+ if (strcasecmp(audio_std, "NICAM/A") == 0)
return V4L2_STD_NICAM_A;
- if (strcasecmp(audio_std, "NICAM/B"))
+ if (strcasecmp(audio_std, "NICAM/B") == 0)
return V4L2_STD_NICAM_B;
return 0;
@@ -240,7 +254,9 @@ static void free_firmware(struct xc2028_data *priv)
kfree(priv->firm);
priv->firm = NULL;
- priv->need_load_generic = 1;
+ priv->firm_size = 0;
+
+ memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
}
static int load_all_firmwares(struct dvb_frontend *fe)
@@ -254,7 +270,7 @@ static int load_all_firmwares(struct dvb_frontend *fe)
tuner_dbg("%s called\n", __FUNCTION__);
- tuner_info("Reading firmware %s\n", priv->ctrl.fname);
+ tuner_dbg("Reading firmware %s\n", priv->ctrl.fname);
rc = request_firmware(&fw, priv->ctrl.fname,
&priv->i2c_props.adap->dev);
if (rc < 0) {
@@ -270,48 +286,44 @@ static int load_all_firmwares(struct dvb_frontend *fe)
p = fw->data;
endp = p + fw->size;
- if (fw->size < sizeof(name) - 1 + 2) {
- tuner_err("Error: firmware size is zero!\n");
- rc = -EINVAL;
- goto done;
+ if (fw->size < sizeof(name) - 1 + 2 + 2) {
+ tuner_err("Error: firmware file %s has invalid size!\n",
+ priv->ctrl.fname);
+ goto corrupt;
}
memcpy(name, p, sizeof(name) - 1);
name[sizeof(name) - 1] = 0;
p += sizeof(name) - 1;
- priv->version = le16_to_cpu(*(__u16 *) p);
+ priv->firm_version = le16_to_cpu(*(__u16 *) p);
p += 2;
- tuner_info("Firmware: %s, ver %d.%d\n", name,
- priv->version >> 8, priv->version & 0xff);
-
- if (p + 2 > endp)
- goto corrupt;
-
n_array = le16_to_cpu(*(__u16 *) p);
p += 2;
- tuner_info("There are %d firmwares at %s\n",
- n_array, priv->ctrl.fname);
+ tuner_info("Loading %d firmware images from %s, type: %s, ver %d.%d\n",
+ n_array, priv->ctrl.fname, name,
+ priv->firm_version >> 8, priv->firm_version & 0xff);
priv->firm = kzalloc(sizeof(*priv->firm) * n_array, GFP_KERNEL);
-
- if (!fw) {
- tuner_err("Not enough memory for reading firmware.\n");
+ if (priv->firm == NULL) {
+ tuner_err("Not enough memory to load firmware file.\n");
rc = -ENOMEM;
- goto done;
+ goto err;
}
-
priv->firm_size = n_array;
+
n = -1;
while (p < endp) {
__u32 type, size;
v4l2_std_id id;
+ __u16 int_freq = 0;
n++;
if (n >= n_array) {
- tuner_err("Too much firmwares at the file\n");
+ tuner_err("More firmware images in file than "
+ "were expected!\n");
goto corrupt;
}
@@ -327,6 +339,11 @@ static int load_all_firmwares(struct dvb_frontend *fe)
id = le64_to_cpu(*(v4l2_std_id *) p);
p += sizeof(id);
+ if (type & HAS_IF) {
+ int_freq = le16_to_cpu(*(__u16 *) p);
+ p += sizeof(int_freq);
+ }
+
size = le32_to_cpu(*(__u32 *) p);
p += sizeof(size);
@@ -335,26 +352,29 @@ static int load_all_firmwares(struct dvb_frontend *fe)
dump_firm_type(type);
printk("(%x), id %llx is corrupted "
"(size=%d, expected %d)\n",
- type, id,
+ type, (unsigned long long)id,
(unsigned)(endp - p), size);
goto corrupt;
}
priv->firm[n].ptr = kzalloc(size, GFP_KERNEL);
- if (!priv->firm[n].ptr) {
- tuner_err("Not enough memory.\n");
+ if (priv->firm[n].ptr == NULL) {
+ tuner_err("Not enough memory to load firmware file.\n");
rc = -ENOMEM;
goto err;
}
- tuner_info("Reading firmware type ");
- dump_firm_type(type);
- printk("(%x), id %lx, size=%d.\n",
- type, (unsigned long)id, size);
+ tuner_dbg("Reading firmware type ");
+ if (debug) {
+ dump_firm_type(type);
+ printk("(%x), id %llx, size=%d.\n",
+ type, (unsigned long long)id, size);
+ }
memcpy(priv->firm[n].ptr, p, size);
priv->firm[n].type = type;
priv->firm[n].id = id;
priv->firm[n].size = size;
+ priv->firm[n].int_freq = int_freq;
p += size;
}
@@ -371,13 +391,13 @@ corrupt:
tuner_err("Error: firmware file is corrupted!\n");
err:
- tuner_info("Releasing loaded firmware file.\n");
-
+ tuner_info("Releasing partially loaded firmware file.\n");
free_firmware(priv);
done:
release_firmware(fw);
- tuner_dbg("Firmware files loaded.\n");
+ if (rc == 0)
+ tuner_dbg("Firmware files loaded.\n");
return rc;
}
@@ -386,9 +406,13 @@ static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
v4l2_std_id *id)
{
struct xc2028_data *priv = fe->tuner_priv;
- int i;
+ int i, best_i = -1, best_nr_matches = 0;
- tuner_dbg("%s called\n", __FUNCTION__);
+ tuner_dbg("%s called, want type=", __FUNCTION__);
+ if (debug) {
+ dump_firm_type(type);
+ printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
+ }
if (!priv->firm) {
tuner_err("Error! firmware not loaded\n");
@@ -398,6 +422,15 @@ static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
if (((type & ~SCODE) == 0) && (*id == 0))
*id = V4L2_STD_PAL;
+ if (type & BASE)
+ type &= BASE_TYPES;
+ else if (type & SCODE)
+ type &= SCODE_TYPES;
+ else if (type & DTV_TYPES)
+ type &= DTV_TYPES;
+ else if (type & STD_SPECIFIC_TYPES)
+ type &= STD_SPECIFIC_TYPES;
+
/* Seek for exact match */
for (i = 0; i < priv->firm_size; i++) {
if ((type == priv->firm[i].type) && (*id == priv->firm[i].id))
@@ -406,23 +439,48 @@ static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
/* Seek for generic video standard match */
for (i = 0; i < priv->firm_size; i++) {
- if ((type == priv->firm[i].type) && (*id & priv->firm[i].id))
- goto found;
+ v4l2_std_id match_mask;
+ int nr_matches;
+
+ if (type != priv->firm[i].type)
+ continue;
+
+ match_mask = *id & priv->firm[i].id;
+ if (!match_mask)
+ continue;
+
+ if ((*id & match_mask) == *id)
+ goto found; /* Supports all the requested standards */
+
+ nr_matches = hweight64(match_mask);
+ if (nr_matches > best_nr_matches) {
+ best_nr_matches = nr_matches;
+ best_i = i;
+ }
+ }
+
+ if (best_nr_matches > 0) {
+ tuner_dbg("Selecting best matching firmware (%d bits) for "
+ "type=", best_nr_matches);
+ dump_firm_type(type);
+ printk("(%x), id %016llx:\n", type, (unsigned long long)*id);
+ i = best_i;
+ goto found;
}
/*FIXME: Would make sense to seek for type "hint" match ? */
- i = -EINVAL;
+ i = -ENOENT;
goto ret;
found:
*id = priv->firm[i].id;
ret:
- tuner_dbg("%s firmware for type=", (i < 0)? "Can't find": "Found");
+ tuner_dbg("%s firmware for type=", (i < 0) ? "Can't find" : "Found");
if (debug) {
dump_firm_type(type);
- printk("(%x), id %08lx.\n", type, (unsigned long)*id);
+ printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
}
return i;
}
@@ -432,7 +490,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
{
struct xc2028_data *priv = fe->tuner_priv;
int pos, rc;
- unsigned char *p, *endp, buf[priv->max_len];
+ unsigned char *p, *endp, buf[priv->ctrl.max_len];
tuner_dbg("%s called\n", __FUNCTION__);
@@ -441,15 +499,11 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
return pos;
tuner_info("Loading firmware for type=");
- dump_firm_type(type);
- printk("(%x), id %08lx.\n", type, (unsigned long)*id);
+ dump_firm_type(priv->firm[pos].type);
+ printk("(%x), id %016llx.\n", priv->firm[pos].type,
+ (unsigned long long)*id);
p = priv->firm[pos].ptr;
-
- if (!p) {
- tuner_err("Firmware pointer were freed!");
- return -EINVAL;
- }
endp = p + priv->firm[pos].size;
while (p < endp) {
@@ -488,6 +542,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
(*p) & 0x7f);
return -EINVAL;
}
+ break;
default:
tuner_info("Invalid RESET code %d\n",
size & 0x7f);
@@ -515,12 +570,12 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
/* Sends message chunks */
while (size > 0) {
- int len = (size < priv->max_len - 1) ?
- size : priv->max_len - 1;
+ int len = (size < priv->ctrl.max_len - 1) ?
+ size : priv->ctrl.max_len - 1;
memcpy(buf + 1, p, len);
- i2c_send(rc, priv, buf, len + 1);
+ rc = i2c_send(priv, buf, len + 1);
if (rc < 0) {
tuner_err("%d returned from send\n", rc);
return -EINVAL;
@@ -534,7 +589,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
}
static int load_scode(struct dvb_frontend *fe, unsigned int type,
- v4l2_std_id *id, int scode)
+ v4l2_std_id *id, __u16 int_freq, int scode)
{
struct xc2028_data *priv = fe->tuner_priv;
int pos, rc;
@@ -542,41 +597,66 @@ static int load_scode(struct dvb_frontend *fe, unsigned int type,
tuner_dbg("%s called\n", __FUNCTION__);
- pos = seek_firmware(fe, type, id);
- if (pos < 0)
- return pos;
+ if (!int_freq) {
+ pos = seek_firmware(fe, type, id);
+ if (pos < 0)
+ return pos;
+ } else {
+ for (pos = 0; pos < priv->firm_size; pos++) {
+ if ((priv->firm[pos].int_freq == int_freq) &&
+ (type & HAS_IF))
+ break;
+ }
+ if (pos == priv->firm_size)
+ return -ENOENT;
+ }
p = priv->firm[pos].ptr;
- if (!p) {
- tuner_err("Firmware pointer were freed!");
- return -EINVAL;
+ if (type & HAS_IF) {
+ if (priv->firm[pos].size != 12 * 16 || scode >= 16)
+ return -EINVAL;
+ p += 12 * scode;
+ } else {
+ /* 16 SCODE entries per file; each SCODE entry is 12 bytes and
+ * has a 2-byte size header in the firmware format. */
+ if (priv->firm[pos].size != 14 * 16 || scode >= 16 ||
+ le16_to_cpu(*(__u16 *)(p + 14 * scode)) != 12)
+ return -EINVAL;
+ p += 14 * scode + 2;
}
- if ((priv->firm[pos].size != 12 * 16) || (scode >= 16))
- return -EINVAL;
+ tuner_info("Loading SCODE for type=");
+ dump_firm_type(priv->firm[pos].type);
+ printk("(%x), id %016llx.\n", priv->firm[pos].type,
+ (unsigned long long)*id);
- if (priv->version < 0x0202) {
- send_seq(priv, {0x20, 0x00, 0x00, 0x00});
- } else {
- send_seq(priv, {0xa0, 0x00, 0x00, 0x00});
- }
+ if (priv->firm_version < 0x0202)
+ rc = send_seq(priv, {0x20, 0x00, 0x00, 0x00});
+ else
+ rc = send_seq(priv, {0xa0, 0x00, 0x00, 0x00});
+ if (rc < 0)
+ return -EIO;
- i2c_send(rc, priv, p + 12 * scode, 12);
+ rc = i2c_send(priv, p, 12);
+ if (rc < 0)
+ return -EIO;
- send_seq(priv, {0x00, 0x8c});
+ rc = send_seq(priv, {0x00, 0x8c});
+ if (rc < 0)
+ return -EIO;
return 0;
}
-static int check_firmware(struct dvb_frontend *fe, enum tuner_mode new_mode,
- v4l2_std_id std, fe_bandwidth_t bandwidth)
+static int check_firmware(struct dvb_frontend *fe, unsigned int type,
+ v4l2_std_id std, __u16 int_freq)
{
- struct xc2028_data *priv = fe->tuner_priv;
- int rc, version, hwmodel;
- v4l2_std_id std0 = 0;
- unsigned int type0 = 0, type = 0;
- int change_digital_bandwidth;
+ struct xc2028_data *priv = fe->tuner_priv;
+ struct firmware_properties new_fw;
+ int rc = 0, is_retry = 0;
+ u16 version, hwmodel;
+ v4l2_std_id std0;
tuner_dbg("%s called\n", __FUNCTION__);
@@ -591,203 +671,230 @@ static int check_firmware(struct dvb_frontend *fe, enum tuner_mode new_mode,
return rc;
}
- tuner_dbg("I am in mode %u and I should switch to mode %i\n",
- priv->mode, new_mode);
-
- /* first of all, determine whether we have switched the mode */
- if (new_mode != priv->mode) {
- priv->mode = new_mode;
- priv->need_load_generic = 1;
- }
-
- change_digital_bandwidth = (priv->mode == T_DIGITAL_TV
- && bandwidth != priv->bandwidth) ? 1 : 0;
- tuner_dbg("old bandwidth %u, new bandwidth %u\n", priv->bandwidth,
- bandwidth);
-
- if (priv->need_load_generic) {
- /* Reset is needed before loading firmware */
- rc = priv->tuner_callback(priv->video_dev,
- XC2028_TUNER_RESET, 0);
- if (rc < 0)
- return rc;
-
- type0 = BASE;
-
- if (priv->ctrl.type == XC2028_FIRM_MTS)
- type0 |= MTS;
-
- if (priv->bandwidth == 8)
- type0 |= F8MHZ;
-
- /* FIXME: How to load FM and FM|INPUT1 firmwares? */
+ if (priv->ctrl.mts)
+ type |= MTS;
- rc = load_firmware(fe, type0, &std0);
- if (rc < 0) {
- tuner_err("Error %d while loading generic firmware\n",
- rc);
- return rc;
- }
+retry:
+ new_fw.type = type;
+ new_fw.id = std;
+ new_fw.std_req = std;
+ new_fw.scode_table = SCODE | priv->ctrl.scode_table;
+ new_fw.scode_nr = 0;
+ new_fw.int_freq = int_freq;
- priv->need_load_generic = 0;
- priv->firm_type = 0;
- if (priv->mode == T_DIGITAL_TV)
- change_digital_bandwidth = 1;
+ tuner_dbg("checking firmware, user requested type=");
+ if (debug) {
+ dump_firm_type(new_fw.type);
+ printk("(%x), id %016llx, scode_tbl ", new_fw.type,
+ (unsigned long long)new_fw.std_req);
+ dump_firm_type(priv->ctrl.scode_table);
+ printk("(%x), scode_nr %d\n", priv->ctrl.scode_table,
+ new_fw.scode_nr);
}
- tuner_dbg("I should change bandwidth %u\n", change_digital_bandwidth);
-
- if (change_digital_bandwidth) {
+ /* No need to reload base firmware if it matches */
+ if (((BASE | new_fw.type) & BASE_TYPES) ==
+ (priv->cur_fw.type & BASE_TYPES)) {
+ tuner_dbg("BASE firmware not changed.\n");
+ goto skip_base;
+ }
- /*FIXME: Should allow selecting between D2620 and D2633 */
- type |= D2620;
+ /* Updating BASE - forget about all currently loaded firmware */
+ memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
- /* FIXME: When should select a DTV78 firmware?
- */
- switch (bandwidth) {
- case BANDWIDTH_8_MHZ:
- type |= DTV8;
- break;
- case BANDWIDTH_7_MHZ:
- type |= DTV7;
- break;
- case BANDWIDTH_6_MHZ:
- /* FIXME: Should allow select also ATSC */
- type |= DTV6 | QAM;
- break;
+ /* Reset is needed before loading firmware */
+ rc = priv->tuner_callback(priv->video_dev,
+ XC2028_TUNER_RESET, 0);
+ if (rc < 0)
+ goto fail;
- default:
- tuner_err("error: bandwidth not supported.\n");
- };
- priv->bandwidth = bandwidth;
+ /* BASE firmwares are all std0 */
+ std0 = 0;
+ rc = load_firmware(fe, BASE | new_fw.type, &std0);
+ if (rc < 0) {
+ tuner_err("Error %d while loading base firmware\n",
+ rc);
+ goto fail;
}
- if (!change_digital_bandwidth && priv->mode == T_DIGITAL_TV)
- return 0;
-
/* Load INIT1, if needed */
tuner_dbg("Load init1 firmware, if exists\n");
- type0 = BASE | INIT1;
- if (priv->ctrl.type == XC2028_FIRM_MTS)
- type0 |= MTS;
- /* FIXME: Should handle errors - if INIT1 found */
- rc = load_firmware(fe, type0, &std0);
+ rc = load_firmware(fe, BASE | INIT1 | new_fw.type, &std0);
+ if (rc == -ENOENT)
+ rc = load_firmware(fe, (BASE | INIT1 | new_fw.type) & ~F8MHZ,
+ &std0);
+ if (rc < 0 && rc != -ENOENT) {
+ tuner_err("Error %d while loading init1 firmware\n",
+ rc);
+ goto fail;
+ }
- /* FIXME: Should add support for FM radio
+skip_base:
+ /*
+ * No need to reload standard specific firmware if base firmware
+ * was not reloaded and requested video standards have not changed.
*/
-
- if (priv->ctrl.type == XC2028_FIRM_MTS)
- type |= MTS;
-
- if (priv->firm_type & std) {
+ if (priv->cur_fw.type == (BASE | new_fw.type) &&
+ priv->cur_fw.std_req == std) {
tuner_dbg("Std-specific firmware already loaded.\n");
- return 0;
+ goto skip_std_specific;
}
- /* Add audio hack to std mask */
- std |= parse_audio_std_option();
+ /* Reloading std-specific firmware forces a SCODE update */
+ priv->cur_fw.scode_table = 0;
+
+ rc = load_firmware(fe, new_fw.type, &new_fw.id);
+ if (rc == -ENOENT)
+ rc = load_firmware(fe, new_fw.type & ~F8MHZ, &new_fw.id);
- rc = load_firmware(fe, type, &std);
if (rc < 0)
- return rc;
+ goto fail;
+
+skip_std_specific:
+ if (priv->cur_fw.scode_table == new_fw.scode_table &&
+ priv->cur_fw.scode_nr == new_fw.scode_nr) {
+ tuner_dbg("SCODE firmware already loaded.\n");
+ goto check_device;
+ }
/* Load SCODE firmware, if exists */
- tuner_dbg("Trying to load scode 0\n");
- type |= SCODE;
+ tuner_dbg("Trying to load scode %d\n", new_fw.scode_nr);
- rc = load_scode(fe, type, &std, 0);
+ rc = load_scode(fe, new_fw.type | new_fw.scode_table, &new_fw.id,
+ new_fw.int_freq, new_fw.scode_nr);
- version = xc2028_get_reg(priv, 0x0004);
- hwmodel = xc2028_get_reg(priv, 0x0008);
+check_device:
+ if (xc2028_get_reg(priv, 0x0004, &version) < 0 ||
+ xc2028_get_reg(priv, 0x0008, &hwmodel) < 0) {
+ tuner_err("Unable to read tuner registers.\n");
+ goto fail;
+ }
tuner_info("Device is Xceive %d version %d.%d, "
"firmware version %d.%d\n",
hwmodel, (version & 0xf000) >> 12, (version & 0xf00) >> 8,
(version & 0xf0) >> 4, version & 0xf);
- priv->firm_type = std;
+ /* Check firmware version against what we downloaded. */
+ if (priv->firm_version != ((version & 0xf0) << 4 | (version & 0x0f))) {
+ tuner_err("Incorrect readback of firmware version.\n");
+ goto fail;
+ }
+
+ /* Check that the tuner hardware model remains consistent over time. */
+ if (priv->hwmodel == 0 && (hwmodel == 2028 || hwmodel == 3028)) {
+ priv->hwmodel = hwmodel;
+ priv->hwvers = version & 0xff00;
+ } else if (priv->hwmodel == 0 || priv->hwmodel != hwmodel ||
+ priv->hwvers != (version & 0xff00)) {
+ tuner_err("Read invalid device hardware information - tuner "
+ "hung?\n");
+ goto fail;
+ }
+
+ memcpy(&priv->cur_fw, &new_fw, sizeof(priv->cur_fw));
+
+ /*
+ * By setting BASE in cur_fw.type only after successfully loading all
+ * firmwares, we can:
+ * 1. Identify that BASE firmware with type=0 has been loaded;
+ * 2. Tell whether BASE firmware was just changed the next time through.
+ */
+ priv->cur_fw.type |= BASE;
return 0;
+
+fail:
+ memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
+ if (!is_retry) {
+ msleep(50);
+ is_retry = 1;
+ tuner_dbg("Retrying firmware load\n");
+ goto retry;
+ }
+
+ if (rc == -ENOENT)
+ rc = -EINVAL;
+ return rc;
}
static int xc2028_signal(struct dvb_frontend *fe, u16 *strength)
{
struct xc2028_data *priv = fe->tuner_priv;
- int frq_lock, signal = 0;
+ u16 frq_lock, signal = 0;
+ int rc;
tuner_dbg("%s called\n", __FUNCTION__);
mutex_lock(&priv->lock);
- *strength = 0;
-
/* Sync Lock Indicator */
- frq_lock = xc2028_get_reg(priv, 0x0002);
- if (frq_lock <= 0)
+ rc = xc2028_get_reg(priv, 0x0002, &frq_lock);
+ if (rc < 0 || frq_lock == 0)
goto ret;
/* Frequency is locked. Return signal quality */
/* Get SNR of the video signal */
- signal = xc2028_get_reg(priv, 0x0040);
-
- if (signal <= 0)
- signal = frq_lock;
+ rc = xc2028_get_reg(priv, 0x0040, &signal);
+ if (rc < 0)
+ signal = -frq_lock;
ret:
mutex_unlock(&priv->lock);
*strength = signal;
- return 0;
+ return rc;
}
#define DIV 15625
-static int generic_set_tv_freq(struct dvb_frontend *fe, u32 freq /* in Hz */ ,
- enum tuner_mode new_mode,
- v4l2_std_id std, fe_bandwidth_t bandwidth)
+static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
+ enum tuner_mode new_mode,
+ unsigned int type,
+ v4l2_std_id std,
+ u16 int_freq)
{
struct xc2028_data *priv = fe->tuner_priv;
int rc = -EINVAL;
- unsigned char buf[5];
+ unsigned char buf[4];
u32 div, offset = 0;
tuner_dbg("%s called\n", __FUNCTION__);
mutex_lock(&priv->lock);
-#if 1
- /* HACK: It seems that specific firmware need to be reloaded
- when freq is changed */
-
- priv->firm_type = 0;
+ tuner_dbg("should set frequency %d kHz\n", freq / 1000);
- /* Reset GPIO 1 */
- rc = priv->tuner_callback(priv->video_dev, XC2028_TUNER_RESET, 0);
- if (rc < 0)
+ if (check_firmware(fe, type, std, int_freq) < 0)
goto ret;
- msleep(10);
-#endif
- tuner_dbg("should set frequency %d kHz)\n", freq / 1000);
-
- if (check_firmware(fe, new_mode, std, bandwidth) < 0)
- goto ret;
-
- if (new_mode == T_DIGITAL_TV)
+ /* On some cases xc2028 can disable video output, if
+ * very weak signals are received. By sending a soft
+ * reset, this is re-enabled. So, it is better to always
+ * send a soft reset before changing channels, to be sure
+ * that xc2028 will be in a safe state.
+ * Maybe this might also be needed for DTV.
+ */
+ if (new_mode == T_ANALOG_TV) {
+ rc = send_seq(priv, {0x00, 0x00});
+ } else {
offset = 2750000;
+ if (priv->cur_fw.type & DTV7)
+ offset -= 500000;
+ }
div = (freq - offset + DIV / 2) / DIV;
/* CMD= Set frequency */
-
- if (priv->version < 0x0202) {
- send_seq(priv, {0x00, 0x02, 0x00, 0x00});
- } else {
- send_seq(priv, {0x80, 0x02, 0x00, 0x00});
- }
+ if (priv->firm_version < 0x0202)
+ rc = send_seq(priv, {0x00, 0x02, 0x00, 0x00});
+ else
+ rc = send_seq(priv, {0x80, 0x02, 0x00, 0x00});
+ if (rc < 0)
+ goto ret;
rc = priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1);
if (rc < 0)
@@ -799,18 +906,17 @@ static int generic_set_tv_freq(struct dvb_frontend *fe, u32 freq /* in Hz */ ,
buf[1] = 0xff & (div >> 16);
buf[2] = 0xff & (div >> 8);
buf[3] = 0xff & (div);
- buf[4] = 0;
- i2c_send(rc, priv, buf, sizeof(buf));
+ rc = i2c_send(priv, buf, sizeof(buf));
if (rc < 0)
goto ret;
msleep(100);
priv->frequency = freq;
- tuner_dbg("divider= %02x %02x %02x %02x (freq=%d.%02d)\n",
- buf[1], buf[2], buf[3], buf[4],
- freq / 1000000, (freq % 1000000) / 10000);
+ tuner_dbg("divisor= %02x %02x %02x %02x (freq=%d.%03d)\n",
+ buf[0], buf[1], buf[2], buf[3],
+ freq / 1000000, (freq % 1000000) / 1000);
rc = 0;
@@ -820,42 +926,124 @@ ret:
return rc;
}
-static int xc2028_set_tv_freq(struct dvb_frontend *fe,
+static int xc2028_set_analog_freq(struct dvb_frontend *fe,
struct analog_parameters *p)
{
struct xc2028_data *priv = fe->tuner_priv;
+ unsigned int type=0;
tuner_dbg("%s called\n", __FUNCTION__);
- return generic_set_tv_freq(fe, 62500l * p->frequency, T_ANALOG_TV,
- p->std, BANDWIDTH_8_MHZ /* NOT USED */);
+ if (p->mode == V4L2_TUNER_RADIO) {
+ type |= FM;
+ if (priv->ctrl.input1)
+ type |= INPUT1;
+ return generic_set_freq(fe, (625l * p->frequency) / 10,
+ T_ANALOG_TV, type, 0, 0);
+ }
+
+ /* if std is not defined, choose one */
+ if (!p->std)
+ p->std = V4L2_STD_MN;
+
+ /* PAL/M, PAL/N, PAL/Nc and NTSC variants should use 6MHz firmware */
+ if (!(p->std & V4L2_STD_MN))
+ type |= F8MHZ;
+
+ /* Add audio hack to std mask */
+ p->std |= parse_audio_std_option();
+
+ return generic_set_freq(fe, 62500l * p->frequency,
+ T_ANALOG_TV, type, p->std, 0);
}
static int xc2028_set_params(struct dvb_frontend *fe,
struct dvb_frontend_parameters *p)
{
struct xc2028_data *priv = fe->tuner_priv;
+ unsigned int type=0;
+ fe_bandwidth_t bw = BANDWIDTH_8_MHZ;
tuner_dbg("%s called\n", __FUNCTION__);
- /* FIXME: Only OFDM implemented */
- if (fe->ops.info.type != FE_OFDM) {
- tuner_err("DTV type not implemented.\n");
- return -EINVAL;
+ if (priv->ctrl.d2633)
+ type |= D2633;
+ else
+ type |= D2620;
+
+ switch(fe->ops.info.type) {
+ case FE_QPSK:
+ break;
+ case FE_OFDM:
+ bw = p->u.ofdm.bandwidth;
+ break;
+ case FE_QAM:
+ bw = BANDWIDTH_6_MHZ;
+ type |= QAM;
+ break;
+ case FE_ATSC:
+ bw = BANDWIDTH_6_MHZ;
+ type |= ATSC| D2633;
+ break;
}
- return generic_set_tv_freq(fe, p->frequency, T_DIGITAL_TV,
- 0 /* NOT USED */,
- p->u.ofdm.bandwidth);
+ /* FIXME:
+ There are two Scodes that will never be selected:
+ DTV78 ZARLINK456, DTV78 DIBCOM52
+ When it should opt for DTV78 instead of DTV7 or DTV8?
+ */
+ switch (bw) {
+ case BANDWIDTH_8_MHZ:
+ type |= DTV8 | F8MHZ;
+ break;
+ case BANDWIDTH_7_MHZ:
+ type |= DTV7 | F8MHZ;
+ break;
+ case BANDWIDTH_6_MHZ:
+ type |= DTV6 ;
+ break;
+ default:
+ tuner_err("error: bandwidth not supported.\n");
+ };
+
+ /* All S-code tables need a 200kHz shift */
+ if (priv->ctrl.demod)
+ priv->ctrl.demod += 200;
+
+ return generic_set_freq(fe, p->frequency,
+ T_DIGITAL_TV, type, 0, priv->ctrl.demod);
+}
+
+static int xc2028_sleep(struct dvb_frontend *fe)
+{
+ struct xc2028_data *priv = fe->tuner_priv;
+ int rc = 0;
+
+ tuner_dbg("%s called\n", __FUNCTION__);
+
+ mutex_lock(&priv->lock);
+
+ if (priv->firm_version < 0x0202)
+ rc = send_seq(priv, {0x00, 0x08, 0x00, 0x00});
+ else
+ rc = send_seq(priv, {0x80, 0x08, 0x00, 0x00});
+
+ priv->cur_fw.type = 0; /* need firmware reload */
+ mutex_unlock(&priv->lock);
+
+ return rc;
}
+
static int xc2028_dvb_release(struct dvb_frontend *fe)
{
struct xc2028_data *priv = fe->tuner_priv;
tuner_dbg("%s called\n", __FUNCTION__);
+ mutex_lock(&xc2028_list_mutex);
+
priv->count--;
if (!priv->count) {
@@ -865,8 +1053,11 @@ static int xc2028_dvb_release(struct dvb_frontend *fe)
free_firmware(priv);
kfree(priv);
+ fe->tuner_priv = NULL;
}
+ mutex_unlock(&xc2028_list_mutex);
+
return 0;
}
@@ -885,26 +1076,30 @@ static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg)
{
struct xc2028_data *priv = fe->tuner_priv;
struct xc2028_ctrl *p = priv_cfg;
+ int rc = 0;
tuner_dbg("%s called\n", __FUNCTION__);
- priv->ctrl.type = p->type;
+ mutex_lock(&priv->lock);
- if (p->fname) {
- kfree(priv->ctrl.fname);
+ kfree(priv->ctrl.fname);
+ free_firmware(priv);
- priv->ctrl.fname = kmalloc(strlen(p->fname) + 1, GFP_KERNEL);
- if (!priv->ctrl.fname)
- return -ENOMEM;
+ memcpy(&priv->ctrl, p, sizeof(priv->ctrl));
+ priv->ctrl.fname = NULL;
- free_firmware(priv);
- strcpy(priv->ctrl.fname, p->fname);
+ if (p->fname) {
+ priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL);
+ if (priv->ctrl.fname == NULL)
+ rc = -ENOMEM;
}
- if (p->max_len > 0)
- priv->max_len = p->max_len;
+ if (priv->ctrl.max_len < 9)
+ priv->ctrl.max_len = 13;
- return 0;
+ mutex_unlock(&priv->lock);
+
+ return rc;
}
static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = {
@@ -916,14 +1111,14 @@ static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = {
},
.set_config = xc2028_set_config,
- .set_analog_params = xc2028_set_tv_freq,
+ .set_analog_params = xc2028_set_analog_freq,
.release = xc2028_dvb_release,
.get_frequency = xc2028_get_frequency,
.get_rf_strength = xc2028_signal,
.set_params = xc2028_set_params,
+ .sleep = xc2028_sleep,
#if 0
- int (*sleep)(struct dvb_frontend *fe);
int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth);
int (*get_status)(struct dvb_frontend *fe, u32 *status);
#endif
@@ -935,18 +1130,20 @@ void *xc2028_attach(struct dvb_frontend *fe, struct xc2028_config *cfg)
void *video_dev;
if (debug)
- printk(KERN_DEBUG PREFIX "Xcv2028/3028 init called!\n");
+ printk(KERN_DEBUG PREFIX ": Xcv2028/3028 init called!\n");
- if (NULL == cfg->video_dev)
+ if (NULL == cfg || NULL == cfg->video_dev)
return NULL;
if (!fe) {
- printk(KERN_ERR PREFIX "No frontend!\n");
+ printk(KERN_ERR PREFIX ": No frontend!\n");
return NULL;
}
video_dev = cfg->video_dev;
+ mutex_lock(&xc2028_list_mutex);
+
list_for_each_entry(priv, &xc2028_list, xc2028_list) {
if (priv->video_dev == cfg->video_dev) {
video_dev = NULL;
@@ -956,17 +1153,16 @@ void *xc2028_attach(struct dvb_frontend *fe, struct xc2028_config *cfg)
if (video_dev) {
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
- if (priv == NULL)
+ if (priv == NULL) {
+ mutex_unlock(&xc2028_list_mutex);
return NULL;
+ }
- priv->bandwidth = BANDWIDTH_6_MHZ;
- priv->need_load_generic = 1;
- priv->mode = T_UNINITIALIZED;
priv->i2c_props.addr = cfg->i2c_addr;
priv->i2c_props.adap = cfg->i2c_adap;
priv->video_dev = video_dev;
priv->tuner_callback = cfg->callback;
- priv->max_len = 13;
+ priv->ctrl.max_len = 13;
mutex_init(&priv->lock);
@@ -981,6 +1177,11 @@ void *xc2028_attach(struct dvb_frontend *fe, struct xc2028_config *cfg)
tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner");
+ if (cfg->ctrl)
+ xc2028_set_config(fe, cfg->ctrl);
+
+ mutex_unlock(&xc2028_list_mutex);
+
return fe;
}
diff --git a/linux/drivers/media/video/tuner-xc2028.h b/linux/drivers/media/video/tuner-xc2028.h
index a20eeb493..1fe8b1959 100644
--- a/linux/drivers/media/video/tuner-xc2028.h
+++ b/linux/drivers/media/video/tuner-xc2028.h
@@ -11,21 +11,33 @@
#define XC2028_DEFAULT_FIRMWARE "xc3028-v27.fw"
-enum xc2028_firm_type {
- XC2028_FIRM_NORMAL,
- XC2028_FIRM_MTS,
-};
+/* Dmoduler IF (kHz) */
+#define XC3028_FE_DEFAULT 0
+#define XC3028_FE_LG60 6000
+#define XC3028_FE_ATI638 6380
+#define XC3028_FE_OREN538 5380
+#define XC3028_FE_OREN36 3600
+#define XC3028_FE_TOYOTA388 3880
+#define XC3028_FE_TOYOTA794 7940
+#define XC3028_FE_DIBCOM52 5200
+#define XC3028_FE_ZARLINK456 4560
+#define XC3028_FE_CHINA 5200
struct xc2028_ctrl {
- enum xc2028_firm_type type;
char *fname;
int max_len;
+ unsigned int scode_table;
+ unsigned int mts :1;
+ unsigned int d2633 :1;
+ unsigned int input1:1;
+ unsigned int demod;
};
struct xc2028_config {
struct i2c_adapter *i2c_adap;
u8 i2c_addr;
void *video_dev;
+ struct xc2028_ctrl *ctrl;
int (*callback) (void *dev, int command, int arg);
};