aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb')
-rw-r--r--drivers/media/dvb/Kconfig2
-rw-r--r--drivers/media/dvb/b2c2/flexcop-i2c.c3
-rw-r--r--drivers/media/dvb/b2c2/flexcop-pci.c8
-rw-r--r--drivers/media/dvb/bt8xx/bt878.c2
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.c10
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.c4
-rw-r--r--drivers/media/dvb/dm1105/Kconfig3
-rw-r--r--drivers/media/dvb/dm1105/dm1105.c317
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c23
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ca_en50221.c10
-rw-r--r--drivers/media/dvb/dvb-core/dvb_demux.c117
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c385
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.h6
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c13
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c18
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig29
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile6
-rw-r--r--drivers/media/dvb/dvb-usb/a800.c31
-rw-r--r--drivers/media/dvb/dvb-usb/af9005-fe.c8
-rw-r--r--drivers/media/dvb/dvb-usb/af9005-remote.c16
-rw-r--r--drivers/media/dvb/dvb-usb/af9005.c16
-rw-r--r--drivers/media/dvb/dvb-usb/af9005.h4
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.c433
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.h736
-rw-r--r--drivers/media/dvb/dvb-usb/anysee.c726
-rw-r--r--drivers/media/dvb/dvb-usb/anysee.h23
-rw-r--r--drivers/media/dvb/dvb-usb/au6610.c22
-rw-r--r--drivers/media/dvb/dvb-usb/az6027.c13
-rw-r--r--drivers/media/dvb/dvb-usb/ce6230.c11
-rw-r--r--drivers/media/dvb/dvb-usb/cinergyT2-core.c6
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c62
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700.h9
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c271
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c1550
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-common.c6
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mb.c16
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mc.c4
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb.h2
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c16
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c18
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-dvb.c31
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-i2c.c1
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h15
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c207
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h30
-rw-r--r--drivers/media/dvb/dvb-usb/dw2102.c648
-rw-r--r--drivers/media/dvb/dvb-usb/ec168.c18
-rw-r--r--drivers/media/dvb/dvb-usb/friio-fe.c2
-rw-r--r--drivers/media/dvb/dvb-usb/friio.c23
-rw-r--r--drivers/media/dvb/dvb-usb/friio.h2
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk-fe.c4
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk.c37
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk.h8
-rw-r--r--drivers/media/dvb/dvb-usb/lmedm04.c1310
-rw-r--r--drivers/media/dvb/dvb-usb/lmedm04.h174
-rw-r--r--drivers/media/dvb/dvb-usb/m920x.c73
-rw-r--r--drivers/media/dvb/dvb-usb/nova-t-usb2.c20
-rw-r--r--drivers/media/dvb/dvb-usb/opera1.c82
-rw-r--r--drivers/media/dvb/dvb-usb/technisat-usb2.c807
-rw-r--r--drivers/media/dvb/dvb-usb/ttusb2.c35
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x-fe.c80
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.c225
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.h7
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c59
-rw-r--r--drivers/media/dvb/firewire/Kconfig8
-rw-r--r--drivers/media/dvb/firewire/Makefile5
-rw-r--r--drivers/media/dvb/firewire/firedtv-1394.c300
-rw-r--r--drivers/media/dvb/firewire/firedtv-avc.c89
-rw-r--r--drivers/media/dvb/firewire/firedtv-ci.c1
-rw-r--r--drivers/media/dvb/firewire/firedtv-dvb.c135
-rw-r--r--drivers/media/dvb/firewire/firedtv-fe.c44
-rw-r--r--drivers/media/dvb/firewire/firedtv-fw.c147
-rw-r--r--drivers/media/dvb/firewire/firedtv-rc.c9
-rw-r--r--drivers/media/dvb/firewire/firedtv.h45
-rw-r--r--drivers/media/dvb/frontends/Kconfig75
-rw-r--r--drivers/media/dvb/frontends/Makefile13
-rw-r--r--drivers/media/dvb/frontends/af9013.c312
-rw-r--r--drivers/media/dvb/frontends/af9013.h1
-rw-r--r--drivers/media/dvb/frontends/af9013_priv.h60
-rw-r--r--drivers/media/dvb/frontends/atbm8830.c8
-rw-r--r--drivers/media/dvb/frontends/atbm8830.h2
-rw-r--r--drivers/media/dvb/frontends/au8522_decoder.c78
-rw-r--r--drivers/media/dvb/frontends/au8522_dig.c6
-rw-r--r--drivers/media/dvb/frontends/au8522_priv.h2
-rw-r--r--drivers/media/dvb/frontends/bcm3510.c6
-rw-r--r--drivers/media/dvb/frontends/bsbe1-d01a.h146
-rw-r--r--drivers/media/dvb/frontends/bsru6.h2
-rw-r--r--drivers/media/dvb/frontends/cx22700.c2
-rw-r--r--drivers/media/dvb/frontends/cx22702.c129
-rw-r--r--drivers/media/dvb/frontends/cx24110.c4
-rw-r--r--drivers/media/dvb/frontends/cx24113.h2
-rw-r--r--drivers/media/dvb/frontends/cx24116.c21
-rw-r--r--drivers/media/dvb/frontends/cx24116.h3
-rw-r--r--drivers/media/dvb/frontends/cx24123.c3
-rw-r--r--drivers/media/dvb/frontends/cxd2820r.h118
-rw-r--r--drivers/media/dvb/frontends/cxd2820r_c.c338
-rw-r--r--drivers/media/dvb/frontends/cxd2820r_core.c915
-rw-r--r--drivers/media/dvb/frontends/cxd2820r_priv.h166
-rw-r--r--drivers/media/dvb/frontends/cxd2820r_t.c449
-rw-r--r--drivers/media/dvb/frontends/cxd2820r_t2.c423
-rw-r--r--drivers/media/dvb/frontends/dib0070.c40
-rw-r--r--drivers/media/dvb/frontends/dib0090.c1640
-rw-r--r--drivers/media/dvb/frontends/dib0090.h31
-rw-r--r--drivers/media/dvb/frontends/dib7000m.c78
-rw-r--r--drivers/media/dvb/frontends/dib7000m.h15
-rw-r--r--drivers/media/dvb/frontends/dib7000p.c2013
-rw-r--r--drivers/media/dvb/frontends/dib7000p.h96
-rw-r--r--drivers/media/dvb/frontends/dib8000.c947
-rw-r--r--drivers/media/dvb/frontends/dib8000.h20
-rw-r--r--drivers/media/dvb/frontends/dib9000.c2403
-rw-r--r--drivers/media/dvb/frontends/dib9000.h131
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.c344
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.h157
-rw-r--r--drivers/media/dvb/frontends/drx397xD.c1511
-rw-r--r--drivers/media/dvb/frontends/drx397xD.h130
-rw-r--r--drivers/media/dvb/frontends/drx397xD_fw.h40
-rw-r--r--drivers/media/dvb/frontends/drxd.h61
-rw-r--r--drivers/media/dvb/frontends/drxd_firm.c929
-rw-r--r--drivers/media/dvb/frontends/drxd_firm.h115
-rw-r--r--drivers/media/dvb/frontends/drxd_hard.c3001
-rw-r--r--drivers/media/dvb/frontends/drxd_map_firm.h1013
-rw-r--r--drivers/media/dvb/frontends/ds3000.c645
-rw-r--r--drivers/media/dvb/frontends/ds3000.h3
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.c79
-rw-r--r--drivers/media/dvb/frontends/eds1547.h2
-rw-r--r--drivers/media/dvb/frontends/ix2505v.c325
-rw-r--r--drivers/media/dvb/frontends/ix2505v.h64
-rw-r--r--drivers/media/dvb/frontends/lgdt3304.c380
-rw-r--r--drivers/media/dvb/frontends/lgdt3304.h45
-rw-r--r--drivers/media/dvb/frontends/lgs8gxx.c13
-rw-r--r--drivers/media/dvb/frontends/mb86a16.c2
-rw-r--r--drivers/media/dvb/frontends/mb86a20s.c639
-rw-r--r--drivers/media/dvb/frontends/mb86a20s.h52
-rw-r--r--drivers/media/dvb/frontends/mt312.c2
-rw-r--r--drivers/media/dvb/frontends/mt352.c2
-rw-r--r--drivers/media/dvb/frontends/mt352.h2
-rw-r--r--drivers/media/dvb/frontends/s5h1420.c3
-rw-r--r--drivers/media/dvb/frontends/s5h1432.c415
-rw-r--r--drivers/media/dvb/frontends/s5h1432.h91
-rw-r--r--drivers/media/dvb/frontends/s921.c548
-rw-r--r--drivers/media/dvb/frontends/s921.h47
-rw-r--r--drivers/media/dvb/frontends/s921_core.c216
-rw-r--r--drivers/media/dvb/frontends/s921_core.h114
-rw-r--r--drivers/media/dvb/frontends/s921_module.c192
-rw-r--r--drivers/media/dvb/frontends/s921_module.h49
-rw-r--r--drivers/media/dvb/frontends/si21xx.c2
-rw-r--r--drivers/media/dvb/frontends/stb0899_algo.c2
-rw-r--r--drivers/media/dvb/frontends/stb0899_drv.c2
-rw-r--r--drivers/media/dvb/frontends/stb6100.c200
-rw-r--r--drivers/media/dvb/frontends/stb6100.h4
-rw-r--r--drivers/media/dvb/frontends/stv0288.c34
-rw-r--r--drivers/media/dvb/frontends/stv0297.c2
-rw-r--r--drivers/media/dvb/frontends/stv0299.c12
-rw-r--r--drivers/media/dvb/frontends/stv0299.h2
-rw-r--r--drivers/media/dvb/frontends/stv0367.c3459
-rw-r--r--drivers/media/dvb/frontends/stv0367.h66
-rw-r--r--drivers/media/dvb/frontends/stv0367_priv.h212
-rw-r--r--drivers/media/dvb/frontends/stv0367_regs.h3614
-rw-r--r--drivers/media/dvb/frontends/stv0900.h2
-rw-r--r--drivers/media/dvb/frontends/stv0900_core.c27
-rw-r--r--drivers/media/dvb/frontends/stv0900_priv.h2
-rw-r--r--drivers/media/dvb/frontends/stv090x.c313
-rw-r--r--drivers/media/dvb/frontends/stv090x.h16
-rw-r--r--drivers/media/dvb/frontends/stv090x_reg.h16
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c2
-rw-r--r--drivers/media/dvb/frontends/tda8261.c1
-rw-r--r--drivers/media/dvb/frontends/z0194a.h2
-rw-r--r--drivers/media/dvb/frontends/zl10036.c10
-rw-r--r--drivers/media/dvb/frontends/zl10353.c2
-rw-r--r--drivers/media/dvb/mantis/Kconfig2
-rw-r--r--drivers/media/dvb/mantis/hopper_cards.c4
-rw-r--r--drivers/media/dvb/mantis/hopper_vp3028.c6
-rw-r--r--drivers/media/dvb/mantis/mantis_cards.c4
-rw-r--r--drivers/media/dvb/mantis/mantis_common.h4
-rw-r--r--drivers/media/dvb/mantis/mantis_core.c5
-rw-r--r--drivers/media/dvb/mantis/mantis_dvb.c17
-rw-r--r--drivers/media/dvb/mantis/mantis_evm.c2
-rw-r--r--drivers/media/dvb/mantis/mantis_i2c.c1
-rw-r--r--drivers/media/dvb/mantis/mantis_input.c76
-rw-r--r--drivers/media/dvb/mantis/mantis_ioc.c13
-rw-r--r--drivers/media/dvb/mantis/mantis_ioc.h2
-rw-r--r--drivers/media/dvb/mantis/mantis_pci.c6
-rw-r--r--drivers/media/dvb/mantis/mantis_uart.c3
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1033.c4
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1034.c10
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1041.c6
-rw-r--r--drivers/media/dvb/mantis/mantis_vp2033.c4
-rw-r--r--drivers/media/dvb/mantis/mantis_vp2040.c4
-rw-r--r--drivers/media/dvb/mantis/mantis_vp3030.c8
-rw-r--r--drivers/media/dvb/ngene/Makefile3
-rw-r--r--drivers/media/dvb/ngene/ngene-cards.c179
-rw-r--r--drivers/media/dvb/ngene/ngene-core.c250
-rw-r--r--drivers/media/dvb/ngene/ngene-dvb.c72
-rw-r--r--drivers/media/dvb/ngene/ngene-i2c.c2
-rw-r--r--drivers/media/dvb/ngene/ngene.h24
-rw-r--r--drivers/media/dvb/pluto2/pluto2.c11
-rw-r--r--drivers/media/dvb/pt1/pt1.c6
-rw-r--r--drivers/media/dvb/siano/Kconfig2
-rw-r--r--drivers/media/dvb/siano/sms-cards.c2
-rw-r--r--drivers/media/dvb/siano/smscoreapi.c5
-rw-r--r--drivers/media/dvb/siano/smsdvb.c2
-rw-r--r--drivers/media/dvb/siano/smsir.c54
-rw-r--r--drivers/media/dvb/siano/smsir.h5
-rw-r--r--drivers/media/dvb/siano/smsusb.c12
-rw-r--r--drivers/media/dvb/ttpci/Kconfig5
-rw-r--r--drivers/media/dvb/ttpci/av7110.c15
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.c9
-rw-r--r--drivers/media/dvb/ttpci/av7110_ca.c5
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.c2
-rw-r--r--drivers/media/dvb/ttpci/av7110_ir.c1
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c6
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c8
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c88
-rw-r--r--drivers/media/dvb/ttpci/budget-core.c4
-rw-r--r--drivers/media/dvb/ttpci/budget-patch.c4
-rw-r--r--drivers/media/dvb/ttpci/budget.c2
-rw-r--r--drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c62
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c2
218 files changed, 32493 insertions, 8099 deletions
diff --git a/drivers/media/dvb/Kconfig b/drivers/media/dvb/Kconfig
index 161ccfd471cb..ee214c3b63d7 100644
--- a/drivers/media/dvb/Kconfig
+++ b/drivers/media/dvb/Kconfig
@@ -65,7 +65,7 @@ comment "Supported SDMC DM1105 Adapters"
65source "drivers/media/dvb/dm1105/Kconfig" 65source "drivers/media/dvb/dm1105/Kconfig"
66 66
67comment "Supported FireWire (IEEE 1394) Adapters" 67comment "Supported FireWire (IEEE 1394) Adapters"
68 depends on DVB_CORE && IEEE1394 68 depends on DVB_CORE && FIREWIRE
69source "drivers/media/dvb/firewire/Kconfig" 69source "drivers/media/dvb/firewire/Kconfig"
70 70
71comment "Supported Earthsoft PT1 Adapters" 71comment "Supported Earthsoft PT1 Adapters"
diff --git a/drivers/media/dvb/b2c2/flexcop-i2c.c b/drivers/media/dvb/b2c2/flexcop-i2c.c
index fd1df2352764..965d5eb33752 100644
--- a/drivers/media/dvb/b2c2/flexcop-i2c.c
+++ b/drivers/media/dvb/b2c2/flexcop-i2c.c
@@ -245,9 +245,6 @@ int flexcop_i2c_init(struct flexcop_device *fc)
245 i2c_set_adapdata(&fc->fc_i2c_adap[1].i2c_adap, &fc->fc_i2c_adap[1]); 245 i2c_set_adapdata(&fc->fc_i2c_adap[1].i2c_adap, &fc->fc_i2c_adap[1]);
246 i2c_set_adapdata(&fc->fc_i2c_adap[2].i2c_adap, &fc->fc_i2c_adap[2]); 246 i2c_set_adapdata(&fc->fc_i2c_adap[2].i2c_adap, &fc->fc_i2c_adap[2]);
247 247
248 fc->fc_i2c_adap[0].i2c_adap.class =
249 fc->fc_i2c_adap[1].i2c_adap.class =
250 fc->fc_i2c_adap[2].i2c_adap.class = I2C_CLASS_TV_DIGITAL;
251 fc->fc_i2c_adap[0].i2c_adap.algo = 248 fc->fc_i2c_adap[0].i2c_adap.algo =
252 fc->fc_i2c_adap[1].i2c_adap.algo = 249 fc->fc_i2c_adap[1].i2c_adap.algo =
253 fc->fc_i2c_adap[2].i2c_adap.algo = &flexcop_algo; 250 fc->fc_i2c_adap[2].i2c_adap.algo = &flexcop_algo;
diff --git a/drivers/media/dvb/b2c2/flexcop-pci.c b/drivers/media/dvb/b2c2/flexcop-pci.c
index 227c0200b70a..44f8fb5f17ff 100644
--- a/drivers/media/dvb/b2c2/flexcop-pci.c
+++ b/drivers/media/dvb/b2c2/flexcop-pci.c
@@ -38,7 +38,7 @@ MODULE_PARM_DESC(debug,
38 DEBSTATUS); 38 DEBSTATUS);
39 39
40#define DRIVER_VERSION "0.1" 40#define DRIVER_VERSION "0.1"
41#define DRIVER_NAME "Technisat/B2C2 FlexCop II/IIb/III Digital TV PCI Driver" 41#define DRIVER_NAME "flexcop-pci"
42#define DRIVER_AUTHOR "Patrick Boettcher <patrick.boettcher@desy.de>" 42#define DRIVER_AUTHOR "Patrick Boettcher <patrick.boettcher@desy.de>"
43 43
44struct flexcop_pci { 44struct flexcop_pci {
@@ -58,7 +58,7 @@ struct flexcop_pci {
58 58
59 int active_dma1_addr; /* 0 = addr0 of dma1; 1 = addr1 of dma1 */ 59 int active_dma1_addr; /* 0 = addr0 of dma1; 1 = addr1 of dma1 */
60 u32 last_dma1_cur_pos; 60 u32 last_dma1_cur_pos;
61 /* position of the pointer last time the timer/packet irq occured */ 61 /* position of the pointer last time the timer/packet irq occurred */
62 int count; 62 int count;
63 int count_prev; 63 int count_prev;
64 int stream_problem; 64 int stream_problem;
@@ -290,10 +290,8 @@ static void flexcop_pci_dma_exit(struct flexcop_pci *fc_pci)
290static int flexcop_pci_init(struct flexcop_pci *fc_pci) 290static int flexcop_pci_init(struct flexcop_pci *fc_pci)
291{ 291{
292 int ret; 292 int ret;
293 u8 card_rev;
294 293
295 pci_read_config_byte(fc_pci->pdev, PCI_CLASS_REVISION, &card_rev); 294 info("card revision %x", fc_pci->pdev->revision);
296 info("card revision %x", card_rev);
297 295
298 if ((ret = pci_enable_device(fc_pci->pdev)) != 0) 296 if ((ret = pci_enable_device(fc_pci->pdev)) != 0)
299 return ret; 297 return ret;
diff --git a/drivers/media/dvb/bt8xx/bt878.c b/drivers/media/dvb/bt8xx/bt878.c
index 99d62094f908..b34fa95185e4 100644
--- a/drivers/media/dvb/bt8xx/bt878.c
+++ b/drivers/media/dvb/bt8xx/bt878.c
@@ -460,7 +460,7 @@ static int __devinit bt878_probe(struct pci_dev *dev,
460 goto fail0; 460 goto fail0;
461 } 461 }
462 462
463 pci_read_config_byte(dev, PCI_CLASS_REVISION, &bt->revision); 463 bt->revision = dev->revision;
464 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat); 464 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
465 465
466 466
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c
index cf8705162845..48e48e8af55a 100644
--- a/drivers/media/dvb/bt8xx/dst_ca.c
+++ b/drivers/media/dvb/bt8xx/dst_ca.c
@@ -22,7 +22,7 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/smp_lock.h> 25#include <linux/mutex.h>
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/dvb/ca.h> 27#include <linux/dvb/ca.h>
28#include "dvbdev.h" 28#include "dvbdev.h"
@@ -52,6 +52,7 @@
52} while(0) 52} while(0)
53 53
54 54
55static DEFINE_MUTEX(dst_ca_mutex);
55static unsigned int verbose = 5; 56static unsigned int verbose = 5;
56module_param(verbose, int, 0644); 57module_param(verbose, int, 0644);
57MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); 58MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
@@ -564,7 +565,7 @@ static long dst_ca_ioctl(struct file *file, unsigned int cmd, unsigned long ioct
564 void __user *arg = (void __user *)ioctl_arg; 565 void __user *arg = (void __user *)ioctl_arg;
565 int result = 0; 566 int result = 0;
566 567
567 lock_kernel(); 568 mutex_lock(&dst_ca_mutex);
568 dvbdev = file->private_data; 569 dvbdev = file->private_data;
569 state = (struct dst_state *)dvbdev->priv; 570 state = (struct dst_state *)dvbdev->priv;
570 p_ca_message = kmalloc(sizeof (struct ca_msg), GFP_KERNEL); 571 p_ca_message = kmalloc(sizeof (struct ca_msg), GFP_KERNEL);
@@ -652,7 +653,7 @@ static long dst_ca_ioctl(struct file *file, unsigned int cmd, unsigned long ioct
652 kfree (p_ca_slot_info); 653 kfree (p_ca_slot_info);
653 kfree (p_ca_caps); 654 kfree (p_ca_caps);
654 655
655 unlock_kernel(); 656 mutex_unlock(&dst_ca_mutex);
656 return result; 657 return result;
657} 658}
658 659
@@ -694,7 +695,8 @@ static const struct file_operations dst_ca_fops = {
694 .open = dst_ca_open, 695 .open = dst_ca_open,
695 .release = dst_ca_release, 696 .release = dst_ca_release,
696 .read = dst_ca_read, 697 .read = dst_ca_read,
697 .write = dst_ca_write 698 .write = dst_ca_write,
699 .llseek = noop_llseek,
698}; 700};
699 701
700static struct dvb_device dvbdev_ca = { 702static struct dvb_device dvbdev_ca = {
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index 78fc469f0f69..1e1106dcd063 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -427,10 +427,10 @@ static void or51211_reset(struct dvb_frontend * fe)
427 struct dvb_bt8xx_card *bt = fe->dvb->priv; 427 struct dvb_bt8xx_card *bt = fe->dvb->priv;
428 428
429 /* RESET DEVICE 429 /* RESET DEVICE
430 * reset is controled by GPIO-0 430 * reset is controlled by GPIO-0
431 * when set to 0 causes reset and when to 1 for normal op 431 * when set to 0 causes reset and when to 1 for normal op
432 * must remain reset for 128 clock cycles on a 50Mhz clock 432 * must remain reset for 128 clock cycles on a 50Mhz clock
433 * also PRM1 PRM2 & PRM4 are controled by GPIO-1,GPIO-2 & GPIO-4 433 * also PRM1 PRM2 & PRM4 are controlled by GPIO-1,GPIO-2 & GPIO-4
434 * We assume that the reset has be held low long enough or we 434 * We assume that the reset has be held low long enough or we
435 * have been reset by a power on. When the driver is unloaded 435 * have been reset by a power on. When the driver is unloaded
436 * reset set to 0 so if reloaded we have been reset. 436 * reset set to 0 so if reloaded we have been reset.
diff --git a/drivers/media/dvb/dm1105/Kconfig b/drivers/media/dvb/dm1105/Kconfig
index a6ceb08f1183..f3de0a4d63f2 100644
--- a/drivers/media/dvb/dm1105/Kconfig
+++ b/drivers/media/dvb/dm1105/Kconfig
@@ -1,7 +1,6 @@
1config DVB_DM1105 1config DVB_DM1105
2 tristate "SDMC DM1105 based PCI cards" 2 tristate "SDMC DM1105 based PCI cards"
3 depends on DVB_CORE && PCI && I2C 3 depends on DVB_CORE && PCI && I2C
4 depends on INPUT
5 select DVB_PLL if !DVB_FE_CUSTOMISE 4 select DVB_PLL if !DVB_FE_CUSTOMISE
6 select DVB_STV0299 if !DVB_FE_CUSTOMISE 5 select DVB_STV0299 if !DVB_FE_CUSTOMISE
7 select DVB_STV0288 if !DVB_FE_CUSTOMISE 6 select DVB_STV0288 if !DVB_FE_CUSTOMISE
@@ -9,7 +8,7 @@ config DVB_DM1105
9 select DVB_CX24116 if !DVB_FE_CUSTOMISE 8 select DVB_CX24116 if !DVB_FE_CUSTOMISE
10 select DVB_SI21XX if !DVB_FE_CUSTOMISE 9 select DVB_SI21XX if !DVB_FE_CUSTOMISE
11 select DVB_DS3000 if !DVB_FE_CUSTOMISE 10 select DVB_DS3000 if !DVB_FE_CUSTOMISE
12 depends on VIDEO_IR 11 depends on RC_CORE
13 help 12 help
14 Support for cards based on the SDMC DM1105 PCI chip like 13 Support for cards based on the SDMC DM1105 PCI chip like
15 DvbWorld 2002 14 DvbWorld 2002
diff --git a/drivers/media/dvb/dm1105/dm1105.c b/drivers/media/dvb/dm1105/dm1105.c
index bca07c0bcd01..b2b0c45f32a9 100644
--- a/drivers/media/dvb/dm1105/dm1105.c
+++ b/drivers/media/dvb/dm1105/dm1105.c
@@ -20,15 +20,15 @@
20 */ 20 */
21 21
22#include <linux/i2c.h> 22#include <linux/i2c.h>
23#include <linux/i2c-algo-bit.h>
23#include <linux/init.h> 24#include <linux/init.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
25#include <linux/module.h> 26#include <linux/module.h>
26#include <linux/proc_fs.h> 27#include <linux/proc_fs.h>
27#include <linux/pci.h> 28#include <linux/pci.h>
28#include <linux/dma-mapping.h> 29#include <linux/dma-mapping.h>
29#include <linux/input.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <media/ir-core.h> 31#include <media/rc-core.h>
32 32
33#include "demux.h" 33#include "demux.h"
34#include "dmxdev.h" 34#include "dmxdev.h"
@@ -50,11 +50,12 @@
50 50
51#define UNSET (-1U) 51#define UNSET (-1U)
52 52
53#define DM1105_BOARD_NOAUTO UNSET 53#define DM1105_BOARD_NOAUTO UNSET
54#define DM1105_BOARD_UNKNOWN 0 54#define DM1105_BOARD_UNKNOWN 0
55#define DM1105_BOARD_DVBWORLD_2002 1 55#define DM1105_BOARD_DVBWORLD_2002 1
56#define DM1105_BOARD_DVBWORLD_2004 2 56#define DM1105_BOARD_DVBWORLD_2004 2
57#define DM1105_BOARD_AXESS_DM05 3 57#define DM1105_BOARD_AXESS_DM05 3
58#define DM1105_BOARD_UNBRANDED_I2C_ON_GPIO 4
58 59
59/* ----------------------------------------------- */ 60/* ----------------------------------------------- */
60/* 61/*
@@ -158,22 +159,38 @@
158#define DM1105_MAX 0x04 159#define DM1105_MAX 0x04
159 160
160#define DRIVER_NAME "dm1105" 161#define DRIVER_NAME "dm1105"
162#define DM1105_I2C_GPIO_NAME "dm1105-gpio"
161 163
162#define DM1105_DMA_PACKETS 47 164#define DM1105_DMA_PACKETS 47
163#define DM1105_DMA_PACKET_LENGTH (128*4) 165#define DM1105_DMA_PACKET_LENGTH (128*4)
164#define DM1105_DMA_BYTES (128 * 4 * DM1105_DMA_PACKETS) 166#define DM1105_DMA_BYTES (128 * 4 * DM1105_DMA_PACKETS)
165 167
168/* */
169#define GPIO08 (1 << 8)
170#define GPIO13 (1 << 13)
171#define GPIO14 (1 << 14)
172#define GPIO15 (1 << 15)
173#define GPIO16 (1 << 16)
174#define GPIO17 (1 << 17)
175#define GPIO_ALL 0x03ffff
176
166/* GPIO's for LNB power control */ 177/* GPIO's for LNB power control */
167#define DM1105_LNB_MASK 0x00000000 178#define DM1105_LNB_MASK (GPIO_ALL & ~(GPIO14 | GPIO13))
168#define DM1105_LNB_OFF 0x00020000 179#define DM1105_LNB_OFF GPIO17
169#define DM1105_LNB_13V 0x00010100 180#define DM1105_LNB_13V (GPIO16 | GPIO08)
170#define DM1105_LNB_18V 0x00000100 181#define DM1105_LNB_18V GPIO08
171 182
172/* GPIO's for LNB power control for Axess DM05 */ 183/* GPIO's for LNB power control for Axess DM05 */
173#define DM05_LNB_MASK 0x00000000 184#define DM05_LNB_MASK (GPIO_ALL & ~(GPIO14 | GPIO13))
174#define DM05_LNB_OFF 0x00020000/* actually 13v */ 185#define DM05_LNB_OFF GPIO17/* actually 13v */
175#define DM05_LNB_13V 0x00020000 186#define DM05_LNB_13V GPIO17
176#define DM05_LNB_18V 0x00030000 187#define DM05_LNB_18V (GPIO17 | GPIO16)
188
189/* GPIO's for LNB power control for unbranded with I2C on GPIO */
190#define UNBR_LNB_MASK (GPIO17 | GPIO16)
191#define UNBR_LNB_OFF 0
192#define UNBR_LNB_13V GPIO17
193#define UNBR_LNB_18V (GPIO17 | GPIO16)
177 194
178static unsigned int card[] = {[0 ... 3] = UNSET }; 195static unsigned int card[] = {[0 ... 3] = UNSET };
179module_param_array(card, int, NULL, 0444); 196module_param_array(card, int, NULL, 0444);
@@ -188,7 +205,11 @@ static unsigned int dm1105_devcount;
188DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 205DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
189 206
190struct dm1105_board { 207struct dm1105_board {
191 char *name; 208 char *name;
209 struct {
210 u32 mask, off, v13, v18;
211 } lnb;
212 u32 gpio_scl, gpio_sda;
192}; 213};
193 214
194struct dm1105_subid { 215struct dm1105_subid {
@@ -200,15 +221,50 @@ struct dm1105_subid {
200static const struct dm1105_board dm1105_boards[] = { 221static const struct dm1105_board dm1105_boards[] = {
201 [DM1105_BOARD_UNKNOWN] = { 222 [DM1105_BOARD_UNKNOWN] = {
202 .name = "UNKNOWN/GENERIC", 223 .name = "UNKNOWN/GENERIC",
224 .lnb = {
225 .mask = DM1105_LNB_MASK,
226 .off = DM1105_LNB_OFF,
227 .v13 = DM1105_LNB_13V,
228 .v18 = DM1105_LNB_18V,
229 },
203 }, 230 },
204 [DM1105_BOARD_DVBWORLD_2002] = { 231 [DM1105_BOARD_DVBWORLD_2002] = {
205 .name = "DVBWorld PCI 2002", 232 .name = "DVBWorld PCI 2002",
233 .lnb = {
234 .mask = DM1105_LNB_MASK,
235 .off = DM1105_LNB_OFF,
236 .v13 = DM1105_LNB_13V,
237 .v18 = DM1105_LNB_18V,
238 },
206 }, 239 },
207 [DM1105_BOARD_DVBWORLD_2004] = { 240 [DM1105_BOARD_DVBWORLD_2004] = {
208 .name = "DVBWorld PCI 2004", 241 .name = "DVBWorld PCI 2004",
242 .lnb = {
243 .mask = DM1105_LNB_MASK,
244 .off = DM1105_LNB_OFF,
245 .v13 = DM1105_LNB_13V,
246 .v18 = DM1105_LNB_18V,
247 },
209 }, 248 },
210 [DM1105_BOARD_AXESS_DM05] = { 249 [DM1105_BOARD_AXESS_DM05] = {
211 .name = "Axess/EasyTv DM05", 250 .name = "Axess/EasyTv DM05",
251 .lnb = {
252 .mask = DM05_LNB_MASK,
253 .off = DM05_LNB_OFF,
254 .v13 = DM05_LNB_13V,
255 .v18 = DM05_LNB_18V,
256 },
257 },
258 [DM1105_BOARD_UNBRANDED_I2C_ON_GPIO] = {
259 .name = "Unbranded DM1105 with i2c on GPIOs",
260 .lnb = {
261 .mask = UNBR_LNB_MASK,
262 .off = UNBR_LNB_OFF,
263 .v13 = UNBR_LNB_13V,
264 .v18 = UNBR_LNB_18V,
265 },
266 .gpio_scl = GPIO14,
267 .gpio_sda = GPIO13,
212 }, 268 },
213}; 269};
214 270
@@ -266,7 +322,7 @@ static void dm1105_card_list(struct pci_dev *pci)
266 322
267/* infrared remote control */ 323/* infrared remote control */
268struct infrared { 324struct infrared {
269 struct input_dev *input_dev; 325 struct rc_dev *dev;
270 char input_phys[32]; 326 char input_phys[32];
271 struct work_struct work; 327 struct work_struct work;
272 u32 ir_command; 328 u32 ir_command;
@@ -294,6 +350,8 @@ struct dm1105_dev {
294 350
295 /* i2c */ 351 /* i2c */
296 struct i2c_adapter i2c_adap; 352 struct i2c_adapter i2c_adap;
353 struct i2c_adapter i2c_bb_adap;
354 struct i2c_algo_bit_data i2c_bit;
297 355
298 /* irq */ 356 /* irq */
299 struct work_struct work; 357 struct work_struct work;
@@ -329,6 +387,103 @@ struct dm1105_dev {
329#define dm_setl(reg, bit) dm_andorl((reg), (bit), (bit)) 387#define dm_setl(reg, bit) dm_andorl((reg), (bit), (bit))
330#define dm_clearl(reg, bit) dm_andorl((reg), (bit), 0) 388#define dm_clearl(reg, bit) dm_andorl((reg), (bit), 0)
331 389
390/* The chip has 18 GPIOs. In HOST mode GPIO's used as 15 bit address lines,
391 so we can use only 3 GPIO's from GPIO15 to GPIO17.
392 Here I don't check whether HOST is enebled as it is not implemented yet.
393 */
394static void dm1105_gpio_set(struct dm1105_dev *dev, u32 mask)
395{
396 if (mask & 0xfffc0000)
397 printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__);
398
399 if (mask & 0x0003ffff)
400 dm_setl(DM1105_GPIOVAL, mask & 0x0003ffff);
401
402}
403
404static void dm1105_gpio_clear(struct dm1105_dev *dev, u32 mask)
405{
406 if (mask & 0xfffc0000)
407 printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__);
408
409 if (mask & 0x0003ffff)
410 dm_clearl(DM1105_GPIOVAL, mask & 0x0003ffff);
411
412}
413
414static void dm1105_gpio_andor(struct dm1105_dev *dev, u32 mask, u32 val)
415{
416 if (mask & 0xfffc0000)
417 printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__);
418
419 if (mask & 0x0003ffff)
420 dm_andorl(DM1105_GPIOVAL, mask & 0x0003ffff, val);
421
422}
423
424static u32 dm1105_gpio_get(struct dm1105_dev *dev, u32 mask)
425{
426 if (mask & 0xfffc0000)
427 printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__);
428
429 if (mask & 0x0003ffff)
430 return dm_readl(DM1105_GPIOVAL) & mask & 0x0003ffff;
431
432 return 0;
433}
434
435static void dm1105_gpio_enable(struct dm1105_dev *dev, u32 mask, int asoutput)
436{
437 if (mask & 0xfffc0000)
438 printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__);
439
440 if ((mask & 0x0003ffff) && asoutput)
441 dm_clearl(DM1105_GPIOCTR, mask & 0x0003ffff);
442 else if ((mask & 0x0003ffff) && !asoutput)
443 dm_setl(DM1105_GPIOCTR, mask & 0x0003ffff);
444
445}
446
447static void dm1105_setline(struct dm1105_dev *dev, u32 line, int state)
448{
449 if (state)
450 dm1105_gpio_enable(dev, line, 0);
451 else {
452 dm1105_gpio_enable(dev, line, 1);
453 dm1105_gpio_clear(dev, line);
454 }
455}
456
457static void dm1105_setsda(void *data, int state)
458{
459 struct dm1105_dev *dev = data;
460
461 dm1105_setline(dev, dm1105_boards[dev->boardnr].gpio_sda, state);
462}
463
464static void dm1105_setscl(void *data, int state)
465{
466 struct dm1105_dev *dev = data;
467
468 dm1105_setline(dev, dm1105_boards[dev->boardnr].gpio_scl, state);
469}
470
471static int dm1105_getsda(void *data)
472{
473 struct dm1105_dev *dev = data;
474
475 return dm1105_gpio_get(dev, dm1105_boards[dev->boardnr].gpio_sda)
476 ? 1 : 0;
477}
478
479static int dm1105_getscl(void *data)
480{
481 struct dm1105_dev *dev = data;
482
483 return dm1105_gpio_get(dev, dm1105_boards[dev->boardnr].gpio_scl)
484 ? 1 : 0;
485}
486
332static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap, 487static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap,
333 struct i2c_msg *msgs, int num) 488 struct i2c_msg *msgs, int num)
334{ 489{
@@ -437,31 +592,20 @@ static inline struct dm1105_dev *frontend_to_dm1105_dev(struct dvb_frontend *fe)
437static int dm1105_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 592static int dm1105_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
438{ 593{
439 struct dm1105_dev *dev = frontend_to_dm1105_dev(fe); 594 struct dm1105_dev *dev = frontend_to_dm1105_dev(fe);
440 u32 lnb_mask, lnb_13v, lnb_18v, lnb_off;
441 595
442 switch (dev->boardnr) { 596 dm1105_gpio_enable(dev, dm1105_boards[dev->boardnr].lnb.mask, 1);
443 case DM1105_BOARD_AXESS_DM05:
444 lnb_mask = DM05_LNB_MASK;
445 lnb_off = DM05_LNB_OFF;
446 lnb_13v = DM05_LNB_13V;
447 lnb_18v = DM05_LNB_18V;
448 break;
449 case DM1105_BOARD_DVBWORLD_2002:
450 case DM1105_BOARD_DVBWORLD_2004:
451 default:
452 lnb_mask = DM1105_LNB_MASK;
453 lnb_off = DM1105_LNB_OFF;
454 lnb_13v = DM1105_LNB_13V;
455 lnb_18v = DM1105_LNB_18V;
456 }
457
458 dm_writel(DM1105_GPIOCTR, lnb_mask);
459 if (voltage == SEC_VOLTAGE_18) 597 if (voltage == SEC_VOLTAGE_18)
460 dm_writel(DM1105_GPIOVAL, lnb_18v); 598 dm1105_gpio_andor(dev,
599 dm1105_boards[dev->boardnr].lnb.mask,
600 dm1105_boards[dev->boardnr].lnb.v18);
461 else if (voltage == SEC_VOLTAGE_13) 601 else if (voltage == SEC_VOLTAGE_13)
462 dm_writel(DM1105_GPIOVAL, lnb_13v); 602 dm1105_gpio_andor(dev,
603 dm1105_boards[dev->boardnr].lnb.mask,
604 dm1105_boards[dev->boardnr].lnb.v13);
463 else 605 else
464 dm_writel(DM1105_GPIOVAL, lnb_off); 606 dm1105_gpio_andor(dev,
607 dm1105_boards[dev->boardnr].lnb.mask,
608 dm1105_boards[dev->boardnr].lnb.off);
465 609
466 return 0; 610 return 0;
467} 611}
@@ -532,7 +676,7 @@ static void dm1105_emit_key(struct work_struct *work)
532 676
533 data = (ircom >> 8) & 0x7f; 677 data = (ircom >> 8) & 0x7f;
534 678
535 ir_keydown(ir->input_dev, data, 0); 679 rc_keydown(ir->dev, data, 0);
536} 680}
537 681
538/* work handler */ 682/* work handler */
@@ -593,46 +737,47 @@ static irqreturn_t dm1105_irq(int irq, void *dev_id)
593 737
594int __devinit dm1105_ir_init(struct dm1105_dev *dm1105) 738int __devinit dm1105_ir_init(struct dm1105_dev *dm1105)
595{ 739{
596 struct input_dev *input_dev; 740 struct rc_dev *dev;
597 char *ir_codes = RC_MAP_DM1105_NEC;
598 int err = -ENOMEM; 741 int err = -ENOMEM;
599 742
600 input_dev = input_allocate_device(); 743 dev = rc_allocate_device();
601 if (!input_dev) 744 if (!dev)
602 return -ENOMEM; 745 return -ENOMEM;
603 746
604 dm1105->ir.input_dev = input_dev;
605 snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys), 747 snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys),
606 "pci-%s/ir0", pci_name(dm1105->pdev)); 748 "pci-%s/ir0", pci_name(dm1105->pdev));
607 749
608 input_dev->name = "DVB on-card IR receiver"; 750 dev->driver_name = MODULE_NAME;
609 input_dev->phys = dm1105->ir.input_phys; 751 dev->map_name = RC_MAP_DM1105_NEC;
610 input_dev->id.bustype = BUS_PCI; 752 dev->driver_type = RC_DRIVER_SCANCODE;
611 input_dev->id.version = 1; 753 dev->input_name = "DVB on-card IR receiver";
754 dev->input_phys = dm1105->ir.input_phys;
755 dev->input_id.bustype = BUS_PCI;
756 dev->input_id.version = 1;
612 if (dm1105->pdev->subsystem_vendor) { 757 if (dm1105->pdev->subsystem_vendor) {
613 input_dev->id.vendor = dm1105->pdev->subsystem_vendor; 758 dev->input_id.vendor = dm1105->pdev->subsystem_vendor;
614 input_dev->id.product = dm1105->pdev->subsystem_device; 759 dev->input_id.product = dm1105->pdev->subsystem_device;
615 } else { 760 } else {
616 input_dev->id.vendor = dm1105->pdev->vendor; 761 dev->input_id.vendor = dm1105->pdev->vendor;
617 input_dev->id.product = dm1105->pdev->device; 762 dev->input_id.product = dm1105->pdev->device;
618 } 763 }
619 764 dev->dev.parent = &dm1105->pdev->dev;
620 input_dev->dev.parent = &dm1105->pdev->dev;
621 765
622 INIT_WORK(&dm1105->ir.work, dm1105_emit_key); 766 INIT_WORK(&dm1105->ir.work, dm1105_emit_key);
623 767
624 err = ir_input_register(input_dev, ir_codes, NULL, MODULE_NAME); 768 err = rc_register_device(dev);
625 if (err < 0) { 769 if (err < 0) {
626 input_free_device(input_dev); 770 rc_free_device(dev);
627 return err; 771 return err;
628 } 772 }
629 773
774 dm1105->ir.dev = dev;
630 return 0; 775 return 0;
631} 776}
632 777
633void __devexit dm1105_ir_exit(struct dm1105_dev *dm1105) 778void __devexit dm1105_ir_exit(struct dm1105_dev *dm1105)
634{ 779{
635 ir_input_unregister(dm1105->ir.input_dev); 780 rc_unregister_device(dm1105->ir.dev);
636} 781}
637 782
638static int __devinit dm1105_hw_init(struct dm1105_dev *dev) 783static int __devinit dm1105_hw_init(struct dm1105_dev *dev)
@@ -708,6 +853,38 @@ static int __devinit frontend_init(struct dm1105_dev *dev)
708 int ret; 853 int ret;
709 854
710 switch (dev->boardnr) { 855 switch (dev->boardnr) {
856 case DM1105_BOARD_UNBRANDED_I2C_ON_GPIO:
857 dm1105_gpio_enable(dev, GPIO15, 1);
858 dm1105_gpio_clear(dev, GPIO15);
859 msleep(100);
860 dm1105_gpio_set(dev, GPIO15);
861 msleep(200);
862 dev->fe = dvb_attach(
863 stv0299_attach, &sharp_z0194a_config,
864 &dev->i2c_bb_adap);
865 if (dev->fe) {
866 dev->fe->ops.set_voltage = dm1105_set_voltage;
867 dvb_attach(dvb_pll_attach, dev->fe, 0x60,
868 &dev->i2c_bb_adap, DVB_PLL_OPERA1);
869 break;
870 }
871
872 dev->fe = dvb_attach(
873 stv0288_attach, &earda_config,
874 &dev->i2c_bb_adap);
875 if (dev->fe) {
876 dev->fe->ops.set_voltage = dm1105_set_voltage;
877 dvb_attach(stb6000_attach, dev->fe, 0x61,
878 &dev->i2c_bb_adap);
879 break;
880 }
881
882 dev->fe = dvb_attach(
883 si21xx_attach, &serit_config,
884 &dev->i2c_bb_adap);
885 if (dev->fe)
886 dev->fe->ops.set_voltage = dm1105_set_voltage;
887 break;
711 case DM1105_BOARD_DVBWORLD_2004: 888 case DM1105_BOARD_DVBWORLD_2004:
712 dev->fe = dvb_attach( 889 dev->fe = dvb_attach(
713 cx24116_attach, &serit_sp2633_config, 890 cx24116_attach, &serit_sp2633_config,
@@ -862,7 +1039,6 @@ static int __devinit dm1105_probe(struct pci_dev *pdev,
862 i2c_set_adapdata(&dev->i2c_adap, dev); 1039 i2c_set_adapdata(&dev->i2c_adap, dev);
863 strcpy(dev->i2c_adap.name, DRIVER_NAME); 1040 strcpy(dev->i2c_adap.name, DRIVER_NAME);
864 dev->i2c_adap.owner = THIS_MODULE; 1041 dev->i2c_adap.owner = THIS_MODULE;
865 dev->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
866 dev->i2c_adap.dev.parent = &pdev->dev; 1042 dev->i2c_adap.dev.parent = &pdev->dev;
867 dev->i2c_adap.algo = &dm1105_algo; 1043 dev->i2c_adap.algo = &dm1105_algo;
868 dev->i2c_adap.algo_data = dev; 1044 dev->i2c_adap.algo_data = dev;
@@ -871,11 +1047,32 @@ static int __devinit dm1105_probe(struct pci_dev *pdev,
871 if (ret < 0) 1047 if (ret < 0)
872 goto err_dm1105_hw_exit; 1048 goto err_dm1105_hw_exit;
873 1049
1050 i2c_set_adapdata(&dev->i2c_bb_adap, dev);
1051 strcpy(dev->i2c_bb_adap.name, DM1105_I2C_GPIO_NAME);
1052 dev->i2c_bb_adap.owner = THIS_MODULE;
1053 dev->i2c_bb_adap.dev.parent = &pdev->dev;
1054 dev->i2c_bb_adap.algo_data = &dev->i2c_bit;
1055 dev->i2c_bit.data = dev;
1056 dev->i2c_bit.setsda = dm1105_setsda;
1057 dev->i2c_bit.setscl = dm1105_setscl;
1058 dev->i2c_bit.getsda = dm1105_getsda;
1059 dev->i2c_bit.getscl = dm1105_getscl;
1060 dev->i2c_bit.udelay = 10;
1061 dev->i2c_bit.timeout = 10;
1062
1063 /* Raise SCL and SDA */
1064 dm1105_setsda(dev, 1);
1065 dm1105_setscl(dev, 1);
1066
1067 ret = i2c_bit_add_bus(&dev->i2c_bb_adap);
1068 if (ret < 0)
1069 goto err_i2c_del_adapter;
1070
874 /* dvb */ 1071 /* dvb */
875 ret = dvb_register_adapter(&dev->dvb_adapter, DRIVER_NAME, 1072 ret = dvb_register_adapter(&dev->dvb_adapter, DRIVER_NAME,
876 THIS_MODULE, &pdev->dev, adapter_nr); 1073 THIS_MODULE, &pdev->dev, adapter_nr);
877 if (ret < 0) 1074 if (ret < 0)
878 goto err_i2c_del_adapter; 1075 goto err_i2c_del_adapters;
879 1076
880 dvb_adapter = &dev->dvb_adapter; 1077 dvb_adapter = &dev->dvb_adapter;
881 1078
@@ -953,6 +1150,8 @@ err_dvb_dmx_release:
953 dvb_dmx_release(dvbdemux); 1150 dvb_dmx_release(dvbdemux);
954err_dvb_unregister_adapter: 1151err_dvb_unregister_adapter:
955 dvb_unregister_adapter(dvb_adapter); 1152 dvb_unregister_adapter(dvb_adapter);
1153err_i2c_del_adapters:
1154 i2c_del_adapter(&dev->i2c_bb_adap);
956err_i2c_del_adapter: 1155err_i2c_del_adapter:
957 i2c_del_adapter(&dev->i2c_adap); 1156 i2c_del_adapter(&dev->i2c_adap);
958err_dm1105_hw_exit: 1157err_dm1105_hw_exit:
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index 0042306ea11b..e4b5c03ae516 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -25,7 +25,6 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/smp_lock.h>
29#include <linux/poll.h> 28#include <linux/poll.h>
30#include <linux/ioctl.h> 29#include <linux/ioctl.h>
31#include <linux/wait.h> 30#include <linux/wait.h>
@@ -573,13 +572,13 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev,
573 dmx_output_t otype; 572 dmx_output_t otype;
574 int ret; 573 int ret;
575 int ts_type; 574 int ts_type;
576 enum dmx_ts_pes ts_pes; 575 dmx_pes_type_t ts_pes;
577 struct dmx_ts_feed *tsfeed; 576 struct dmx_ts_feed *tsfeed;
578 577
579 feed->ts = NULL; 578 feed->ts = NULL;
580 otype = para->output; 579 otype = para->output;
581 580
582 ts_pes = (enum dmx_ts_pes)para->pes_type; 581 ts_pes = para->pes_type;
583 582
584 if (ts_pes < DMX_PES_OTHER) 583 if (ts_pes < DMX_PES_OTHER)
585 ts_type = TS_DECODER; 584 ts_type = TS_DECODER;
@@ -1088,13 +1087,7 @@ static int dvb_demux_do_ioctl(struct file *file,
1088static long dvb_demux_ioctl(struct file *file, unsigned int cmd, 1087static long dvb_demux_ioctl(struct file *file, unsigned int cmd,
1089 unsigned long arg) 1088 unsigned long arg)
1090{ 1089{
1091 int ret; 1090 return dvb_usercopy(file, cmd, arg, dvb_demux_do_ioctl);
1092
1093 lock_kernel();
1094 ret = dvb_usercopy(file, cmd, arg, dvb_demux_do_ioctl);
1095 unlock_kernel();
1096
1097 return ret;
1098} 1091}
1099 1092
1100static unsigned int dvb_demux_poll(struct file *file, poll_table *wait) 1093static unsigned int dvb_demux_poll(struct file *file, poll_table *wait)
@@ -1150,6 +1143,7 @@ static const struct file_operations dvb_demux_fops = {
1150 .open = dvb_demux_open, 1143 .open = dvb_demux_open,
1151 .release = dvb_demux_release, 1144 .release = dvb_demux_release,
1152 .poll = dvb_demux_poll, 1145 .poll = dvb_demux_poll,
1146 .llseek = default_llseek,
1153}; 1147};
1154 1148
1155static struct dvb_device dvbdev_demux = { 1149static struct dvb_device dvbdev_demux = {
@@ -1186,13 +1180,7 @@ static int dvb_dvr_do_ioctl(struct file *file,
1186static long dvb_dvr_ioctl(struct file *file, 1180static long dvb_dvr_ioctl(struct file *file,
1187 unsigned int cmd, unsigned long arg) 1181 unsigned int cmd, unsigned long arg)
1188{ 1182{
1189 int ret; 1183 return dvb_usercopy(file, cmd, arg, dvb_dvr_do_ioctl);
1190
1191 lock_kernel();
1192 ret = dvb_usercopy(file, cmd, arg, dvb_dvr_do_ioctl);
1193 unlock_kernel();
1194
1195 return ret;
1196} 1184}
1197 1185
1198static unsigned int dvb_dvr_poll(struct file *file, poll_table *wait) 1186static unsigned int dvb_dvr_poll(struct file *file, poll_table *wait)
@@ -1225,6 +1213,7 @@ static const struct file_operations dvb_dvr_fops = {
1225 .open = dvb_dvr_open, 1213 .open = dvb_dvr_open,
1226 .release = dvb_dvr_release, 1214 .release = dvb_dvr_release,
1227 .poll = dvb_dvr_poll, 1215 .poll = dvb_dvr_poll,
1216 .llseek = default_llseek,
1228}; 1217};
1229 1218
1230static struct dvb_device dvbdev_dvr = { 1219static struct dvb_device dvbdev_dvr = {
diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index cb97e6b85432..7ea517b7e186 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -36,7 +36,6 @@
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <linux/spinlock.h> 37#include <linux/spinlock.h>
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/smp_lock.h>
40#include <linux/kthread.h> 39#include <linux/kthread.h>
41 40
42#include "dvb_ca_en50221.h" 41#include "dvb_ca_en50221.h"
@@ -1259,13 +1258,7 @@ static int dvb_ca_en50221_io_do_ioctl(struct file *file,
1259static long dvb_ca_en50221_io_ioctl(struct file *file, 1258static long dvb_ca_en50221_io_ioctl(struct file *file,
1260 unsigned int cmd, unsigned long arg) 1259 unsigned int cmd, unsigned long arg)
1261{ 1260{
1262 int ret; 1261 return dvb_usercopy(file, cmd, arg, dvb_ca_en50221_io_do_ioctl);
1263
1264 lock_kernel();
1265 ret = dvb_usercopy(file, cmd, arg, dvb_ca_en50221_io_do_ioctl);
1266 unlock_kernel();
1267
1268 return ret;
1269} 1262}
1270 1263
1271 1264
@@ -1628,6 +1621,7 @@ static const struct file_operations dvb_ca_fops = {
1628 .open = dvb_ca_en50221_io_open, 1621 .open = dvb_ca_en50221_io_open,
1629 .release = dvb_ca_en50221_io_release, 1622 .release = dvb_ca_en50221_io_release,
1630 .poll = dvb_ca_en50221_io_poll, 1623 .poll = dvb_ca_en50221_io_poll,
1624 .llseek = noop_llseek,
1631}; 1625};
1632 1626
1633static struct dvb_device dvbdev_ca = { 1627static struct dvb_device dvbdev_ca = {
diff --git a/drivers/media/dvb/dvb-core/dvb_demux.c b/drivers/media/dvb/dvb-core/dvb_demux.c
index 4a88a3e4db2b..faa3671b649e 100644
--- a/drivers/media/dvb/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb/dvb-core/dvb_demux.c
@@ -478,97 +478,94 @@ void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,
478 478
479EXPORT_SYMBOL(dvb_dmx_swfilter_packets); 479EXPORT_SYMBOL(dvb_dmx_swfilter_packets);
480 480
481void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count) 481static inline int find_next_packet(const u8 *buf, int pos, size_t count,
482 const int pktsize)
482{ 483{
483 int p = 0, i, j; 484 int start = pos, lost;
484 485
485 spin_lock(&demux->lock); 486 while (pos < count) {
486 487 if (buf[pos] == 0x47 ||
487 if (demux->tsbufp) { 488 (pktsize == 204 && buf[pos] == 0xB8))
488 i = demux->tsbufp; 489 break;
489 j = 188 - i; 490 pos++;
490 if (count < j) {
491 memcpy(&demux->tsbuf[i], buf, count);
492 demux->tsbufp += count;
493 goto bailout;
494 }
495 memcpy(&demux->tsbuf[i], buf, j);
496 if (demux->tsbuf[0] == 0x47)
497 dvb_dmx_swfilter_packet(demux, demux->tsbuf);
498 demux->tsbufp = 0;
499 p += j;
500 } 491 }
501 492
502 while (p < count) { 493 lost = pos - start;
503 if (buf[p] == 0x47) { 494 if (lost) {
504 if (count - p >= 188) { 495 /* This garbage is part of a valid packet? */
505 dvb_dmx_swfilter_packet(demux, &buf[p]); 496 int backtrack = pos - pktsize;
506 p += 188; 497 if (backtrack >= 0 && (buf[backtrack] == 0x47 ||
507 } else { 498 (pktsize == 204 && buf[backtrack] == 0xB8)))
508 i = count - p; 499 return backtrack;
509 memcpy(demux->tsbuf, &buf[p], i);
510 demux->tsbufp = i;
511 goto bailout;
512 }
513 } else
514 p++;
515 } 500 }
516 501
517bailout: 502 return pos;
518 spin_unlock(&demux->lock);
519} 503}
520 504
521EXPORT_SYMBOL(dvb_dmx_swfilter); 505/* Filter all pktsize= 188 or 204 sized packets and skip garbage. */
522 506static inline void _dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf,
523void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count) 507 size_t count, const int pktsize)
524{ 508{
525 int p = 0, i, j; 509 int p = 0, i, j;
526 u8 tmppack[188]; 510 const u8 *q;
527 511
528 spin_lock(&demux->lock); 512 spin_lock(&demux->lock);
529 513
530 if (demux->tsbufp) { 514 if (demux->tsbufp) { /* tsbuf[0] is now 0x47. */
531 i = demux->tsbufp; 515 i = demux->tsbufp;
532 j = 204 - i; 516 j = pktsize - i;
533 if (count < j) { 517 if (count < j) {
534 memcpy(&demux->tsbuf[i], buf, count); 518 memcpy(&demux->tsbuf[i], buf, count);
535 demux->tsbufp += count; 519 demux->tsbufp += count;
536 goto bailout; 520 goto bailout;
537 } 521 }
538 memcpy(&demux->tsbuf[i], buf, j); 522 memcpy(&demux->tsbuf[i], buf, j);
539 if ((demux->tsbuf[0] == 0x47) || (demux->tsbuf[0] == 0xB8)) { 523 if (demux->tsbuf[0] == 0x47) /* double check */
540 memcpy(tmppack, demux->tsbuf, 188); 524 dvb_dmx_swfilter_packet(demux, demux->tsbuf);
541 if (tmppack[0] == 0xB8)
542 tmppack[0] = 0x47;
543 dvb_dmx_swfilter_packet(demux, tmppack);
544 }
545 demux->tsbufp = 0; 525 demux->tsbufp = 0;
546 p += j; 526 p += j;
547 } 527 }
548 528
549 while (p < count) { 529 while (1) {
550 if ((buf[p] == 0x47) || (buf[p] == 0xB8)) { 530 p = find_next_packet(buf, p, count, pktsize);
551 if (count - p >= 204) { 531 if (p >= count)
552 memcpy(tmppack, &buf[p], 188); 532 break;
553 if (tmppack[0] == 0xB8) 533 if (count - p < pktsize)
554 tmppack[0] = 0x47; 534 break;
555 dvb_dmx_swfilter_packet(demux, tmppack); 535
556 p += 204; 536 q = &buf[p];
557 } else { 537
558 i = count - p; 538 if (pktsize == 204 && (*q == 0xB8)) {
559 memcpy(demux->tsbuf, &buf[p], i); 539 memcpy(demux->tsbuf, q, 188);
560 demux->tsbufp = i; 540 demux->tsbuf[0] = 0x47;
561 goto bailout; 541 q = demux->tsbuf;
562 }
563 } else {
564 p++;
565 } 542 }
543 dvb_dmx_swfilter_packet(demux, q);
544 p += pktsize;
545 }
546
547 i = count - p;
548 if (i) {
549 memcpy(demux->tsbuf, &buf[p], i);
550 demux->tsbufp = i;
551 if (pktsize == 204 && demux->tsbuf[0] == 0xB8)
552 demux->tsbuf[0] = 0x47;
566 } 553 }
567 554
568bailout: 555bailout:
569 spin_unlock(&demux->lock); 556 spin_unlock(&demux->lock);
570} 557}
571 558
559void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count)
560{
561 _dvb_dmx_swfilter(demux, buf, count, 188);
562}
563EXPORT_SYMBOL(dvb_dmx_swfilter);
564
565void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf, size_t count)
566{
567 _dvb_dmx_swfilter(demux, buf, count, 204);
568}
572EXPORT_SYMBOL(dvb_dmx_swfilter_204); 569EXPORT_SYMBOL(dvb_dmx_swfilter_204);
573 570
574static struct dvb_demux_filter *dvb_dmx_filter_alloc(struct dvb_demux *demux) 571static struct dvb_demux_filter *dvb_dmx_filter_alloc(struct dvb_demux *demux)
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 4d45b7d6b3fb..5b6b451d4694 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -36,7 +36,6 @@
36#include <linux/list.h> 36#include <linux/list.h>
37#include <linux/freezer.h> 37#include <linux/freezer.h>
38#include <linux/jiffies.h> 38#include <linux/jiffies.h>
39#include <linux/smp_lock.h>
40#include <linux/kthread.h> 39#include <linux/kthread.h>
41#include <asm/processor.h> 40#include <asm/processor.h>
42 41
@@ -106,7 +105,8 @@ struct dvb_frontend_private {
106 105
107 /* thread/frontend values */ 106 /* thread/frontend values */
108 struct dvb_device *dvbdev; 107 struct dvb_device *dvbdev;
109 struct dvb_frontend_parameters parameters; 108 struct dvb_frontend_parameters parameters_in;
109 struct dvb_frontend_parameters parameters_out;
110 struct dvb_fe_events events; 110 struct dvb_fe_events events;
111 struct semaphore sem; 111 struct semaphore sem;
112 struct list_head list_head; 112 struct list_head list_head;
@@ -161,12 +161,11 @@ static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status)
161 161
162 e = &events->events[events->eventw]; 162 e = &events->events[events->eventw];
163 163
164 memcpy (&e->parameters, &fepriv->parameters,
165 sizeof (struct dvb_frontend_parameters));
166
167 if (status & FE_HAS_LOCK) 164 if (status & FE_HAS_LOCK)
168 if (fe->ops.get_frontend) 165 if (fe->ops.get_frontend)
169 fe->ops.get_frontend(fe, &e->parameters); 166 fe->ops.get_frontend(fe, &fepriv->parameters_out);
167
168 e->parameters = fepriv->parameters_out;
170 169
171 events->eventw = wp; 170 events->eventw = wp;
172 171
@@ -278,12 +277,12 @@ static int dvb_frontend_swzigzag_autotune(struct dvb_frontend *fe, int check_wra
278 int ready = 0; 277 int ready = 0;
279 int fe_set_err = 0; 278 int fe_set_err = 0;
280 struct dvb_frontend_private *fepriv = fe->frontend_priv; 279 struct dvb_frontend_private *fepriv = fe->frontend_priv;
281 int original_inversion = fepriv->parameters.inversion; 280 int original_inversion = fepriv->parameters_in.inversion;
282 u32 original_frequency = fepriv->parameters.frequency; 281 u32 original_frequency = fepriv->parameters_in.frequency;
283 282
284 /* are we using autoinversion? */ 283 /* are we using autoinversion? */
285 autoinversion = ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) && 284 autoinversion = ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
286 (fepriv->parameters.inversion == INVERSION_AUTO)); 285 (fepriv->parameters_in.inversion == INVERSION_AUTO));
287 286
288 /* setup parameters correctly */ 287 /* setup parameters correctly */
289 while(!ready) { 288 while(!ready) {
@@ -349,18 +348,19 @@ static int dvb_frontend_swzigzag_autotune(struct dvb_frontend *fe, int check_wra
349 fepriv->auto_step, fepriv->auto_sub_step, fepriv->started_auto_step); 348 fepriv->auto_step, fepriv->auto_sub_step, fepriv->started_auto_step);
350 349
351 /* set the frontend itself */ 350 /* set the frontend itself */
352 fepriv->parameters.frequency += fepriv->lnb_drift; 351 fepriv->parameters_in.frequency += fepriv->lnb_drift;
353 if (autoinversion) 352 if (autoinversion)
354 fepriv->parameters.inversion = fepriv->inversion; 353 fepriv->parameters_in.inversion = fepriv->inversion;
355 if (fe->ops.set_frontend) 354 if (fe->ops.set_frontend)
356 fe_set_err = fe->ops.set_frontend(fe, &fepriv->parameters); 355 fe_set_err = fe->ops.set_frontend(fe, &fepriv->parameters_in);
356 fepriv->parameters_out = fepriv->parameters_in;
357 if (fe_set_err < 0) { 357 if (fe_set_err < 0) {
358 fepriv->state = FESTATE_ERROR; 358 fepriv->state = FESTATE_ERROR;
359 return fe_set_err; 359 return fe_set_err;
360 } 360 }
361 361
362 fepriv->parameters.frequency = original_frequency; 362 fepriv->parameters_in.frequency = original_frequency;
363 fepriv->parameters.inversion = original_inversion; 363 fepriv->parameters_in.inversion = original_inversion;
364 364
365 fepriv->auto_sub_step++; 365 fepriv->auto_sub_step++;
366 return 0; 366 return 0;
@@ -384,7 +384,8 @@ static void dvb_frontend_swzigzag(struct dvb_frontend *fe)
384 if (fepriv->state & FESTATE_RETUNE) { 384 if (fepriv->state & FESTATE_RETUNE) {
385 if (fe->ops.set_frontend) 385 if (fe->ops.set_frontend)
386 retval = fe->ops.set_frontend(fe, 386 retval = fe->ops.set_frontend(fe,
387 &fepriv->parameters); 387 &fepriv->parameters_in);
388 fepriv->parameters_out = fepriv->parameters_in;
388 if (retval < 0) 389 if (retval < 0)
389 fepriv->state = FESTATE_ERROR; 390 fepriv->state = FESTATE_ERROR;
390 else 391 else
@@ -414,8 +415,8 @@ static void dvb_frontend_swzigzag(struct dvb_frontend *fe)
414 415
415 /* if we're tuned, then we have determined the correct inversion */ 416 /* if we're tuned, then we have determined the correct inversion */
416 if ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) && 417 if ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
417 (fepriv->parameters.inversion == INVERSION_AUTO)) { 418 (fepriv->parameters_in.inversion == INVERSION_AUTO)) {
418 fepriv->parameters.inversion = fepriv->inversion; 419 fepriv->parameters_in.inversion = fepriv->inversion;
419 } 420 }
420 return; 421 return;
421 } 422 }
@@ -595,12 +596,14 @@ restart:
595 596
596 if (fepriv->state & FESTATE_RETUNE) { 597 if (fepriv->state & FESTATE_RETUNE) {
597 dprintk("%s: Retune requested, FESTATE_RETUNE\n", __func__); 598 dprintk("%s: Retune requested, FESTATE_RETUNE\n", __func__);
598 params = &fepriv->parameters; 599 params = &fepriv->parameters_in;
599 fepriv->state = FESTATE_TUNED; 600 fepriv->state = FESTATE_TUNED;
600 } 601 }
601 602
602 if (fe->ops.tune) 603 if (fe->ops.tune)
603 fe->ops.tune(fe, params, fepriv->tune_mode_flags, &fepriv->delay, &s); 604 fe->ops.tune(fe, params, fepriv->tune_mode_flags, &fepriv->delay, &s);
605 if (params)
606 fepriv->parameters_out = *params;
604 607
605 if (s != fepriv->status && !(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) { 608 if (s != fepriv->status && !(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) {
606 dprintk("%s: state changed, adding current state\n", __func__); 609 dprintk("%s: state changed, adding current state\n", __func__);
@@ -613,11 +616,9 @@ restart:
613 dvb_frontend_swzigzag(fe); 616 dvb_frontend_swzigzag(fe);
614 break; 617 break;
615 case DVBFE_ALGO_CUSTOM: 618 case DVBFE_ALGO_CUSTOM:
616 params = NULL; /* have we been asked to RETUNE ? */
617 dprintk("%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__, fepriv->state); 619 dprintk("%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__, fepriv->state);
618 if (fepriv->state & FESTATE_RETUNE) { 620 if (fepriv->state & FESTATE_RETUNE) {
619 dprintk("%s: Retune requested, FESTAT_RETUNE\n", __func__); 621 dprintk("%s: Retune requested, FESTAT_RETUNE\n", __func__);
620 params = &fepriv->parameters;
621 fepriv->state = FESTATE_TUNED; 622 fepriv->state = FESTATE_TUNED;
622 } 623 }
623 /* Case where we are going to search for a carrier 624 /* Case where we are going to search for a carrier
@@ -626,7 +627,7 @@ restart:
626 */ 627 */
627 if (fepriv->algo_status & DVBFE_ALGO_SEARCH_AGAIN) { 628 if (fepriv->algo_status & DVBFE_ALGO_SEARCH_AGAIN) {
628 if (fe->ops.search) { 629 if (fe->ops.search) {
629 fepriv->algo_status = fe->ops.search(fe, &fepriv->parameters); 630 fepriv->algo_status = fe->ops.search(fe, &fepriv->parameters_in);
630 /* We did do a search as was requested, the flags are 631 /* We did do a search as was requested, the flags are
631 * now unset as well and has the flags wrt to search. 632 * now unset as well and has the flags wrt to search.
632 */ 633 */
@@ -637,11 +638,12 @@ restart:
637 /* Track the carrier if the search was successful */ 638 /* Track the carrier if the search was successful */
638 if (fepriv->algo_status == DVBFE_ALGO_SEARCH_SUCCESS) { 639 if (fepriv->algo_status == DVBFE_ALGO_SEARCH_SUCCESS) {
639 if (fe->ops.track) 640 if (fe->ops.track)
640 fe->ops.track(fe, &fepriv->parameters); 641 fe->ops.track(fe, &fepriv->parameters_in);
641 } else { 642 } else {
642 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; 643 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
643 fepriv->delay = HZ / 2; 644 fepriv->delay = HZ / 2;
644 } 645 }
646 fepriv->parameters_out = fepriv->parameters_in;
645 fe->ops.read_status(fe, &s); 647 fe->ops.read_status(fe, &s);
646 if (s != fepriv->status) { 648 if (s != fepriv->status) {
647 dvb_frontend_add_event(fe, s); /* update event list */ 649 dvb_frontend_add_event(fe, s); /* update event list */
@@ -702,7 +704,7 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
702 704
703 kthread_stop(fepriv->thread); 705 kthread_stop(fepriv->thread);
704 706
705 init_MUTEX (&fepriv->sem); 707 sema_init(&fepriv->sem, 1);
706 fepriv->state = FESTATE_IDLE; 708 fepriv->state = FESTATE_IDLE;
707 709
708 /* paranoia check in case a signal arrived */ 710 /* paranoia check in case a signal arrived */
@@ -861,34 +863,34 @@ static int dvb_frontend_check_parameters(struct dvb_frontend *fe,
861 863
862static int dvb_frontend_clear_cache(struct dvb_frontend *fe) 864static int dvb_frontend_clear_cache(struct dvb_frontend *fe)
863{ 865{
866 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
864 int i; 867 int i;
865 868
866 memset(&(fe->dtv_property_cache), 0, 869 memset(c, 0, sizeof(struct dtv_frontend_properties));
867 sizeof(struct dtv_frontend_properties)); 870
868 871 c->state = DTV_CLEAR;
869 fe->dtv_property_cache.state = DTV_CLEAR; 872 c->delivery_system = SYS_UNDEFINED;
870 fe->dtv_property_cache.delivery_system = SYS_UNDEFINED; 873 c->inversion = INVERSION_AUTO;
871 fe->dtv_property_cache.inversion = INVERSION_AUTO; 874 c->fec_inner = FEC_AUTO;
872 fe->dtv_property_cache.fec_inner = FEC_AUTO; 875 c->transmission_mode = TRANSMISSION_MODE_AUTO;
873 fe->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_AUTO; 876 c->bandwidth_hz = BANDWIDTH_AUTO;
874 fe->dtv_property_cache.bandwidth_hz = BANDWIDTH_AUTO; 877 c->guard_interval = GUARD_INTERVAL_AUTO;
875 fe->dtv_property_cache.guard_interval = GUARD_INTERVAL_AUTO; 878 c->hierarchy = HIERARCHY_AUTO;
876 fe->dtv_property_cache.hierarchy = HIERARCHY_AUTO; 879 c->symbol_rate = QAM_AUTO;
877 fe->dtv_property_cache.symbol_rate = QAM_AUTO; 880 c->code_rate_HP = FEC_AUTO;
878 fe->dtv_property_cache.code_rate_HP = FEC_AUTO; 881 c->code_rate_LP = FEC_AUTO;
879 fe->dtv_property_cache.code_rate_LP = FEC_AUTO; 882
880 883 c->isdbt_partial_reception = -1;
881 fe->dtv_property_cache.isdbt_partial_reception = -1; 884 c->isdbt_sb_mode = -1;
882 fe->dtv_property_cache.isdbt_sb_mode = -1; 885 c->isdbt_sb_subchannel = -1;
883 fe->dtv_property_cache.isdbt_sb_subchannel = -1; 886 c->isdbt_sb_segment_idx = -1;
884 fe->dtv_property_cache.isdbt_sb_segment_idx = -1; 887 c->isdbt_sb_segment_count = -1;
885 fe->dtv_property_cache.isdbt_sb_segment_count = -1; 888 c->isdbt_layer_enabled = 0x7;
886 fe->dtv_property_cache.isdbt_layer_enabled = 0x7;
887 for (i = 0; i < 3; i++) { 889 for (i = 0; i < 3; i++) {
888 fe->dtv_property_cache.layer[i].fec = FEC_AUTO; 890 c->layer[i].fec = FEC_AUTO;
889 fe->dtv_property_cache.layer[i].modulation = QAM_AUTO; 891 c->layer[i].modulation = QAM_AUTO;
890 fe->dtv_property_cache.layer[i].interleaving = -1; 892 c->layer[i].interleaving = -1;
891 fe->dtv_property_cache.layer[i].segment_count = -1; 893 c->layer[i].segment_count = -1;
892 } 894 }
893 895
894 return 0; 896 return 0;
@@ -1021,10 +1023,9 @@ static int is_legacy_delivery_system(fe_delivery_system_t s)
1021 * it's being used for the legacy or new API, reducing code and complexity. 1023 * it's being used for the legacy or new API, reducing code and complexity.
1022 */ 1024 */
1023static void dtv_property_cache_sync(struct dvb_frontend *fe, 1025static void dtv_property_cache_sync(struct dvb_frontend *fe,
1024 struct dvb_frontend_parameters *p) 1026 struct dtv_frontend_properties *c,
1027 const struct dvb_frontend_parameters *p)
1025{ 1028{
1026 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1027
1028 c->frequency = p->frequency; 1029 c->frequency = p->frequency;
1029 c->inversion = p->inversion; 1030 c->inversion = p->inversion;
1030 1031
@@ -1075,9 +1076,9 @@ static void dtv_property_cache_sync(struct dvb_frontend *fe,
1075 */ 1076 */
1076static void dtv_property_legacy_params_sync(struct dvb_frontend *fe) 1077static void dtv_property_legacy_params_sync(struct dvb_frontend *fe)
1077{ 1078{
1078 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1079 const struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1079 struct dvb_frontend_private *fepriv = fe->frontend_priv; 1080 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1080 struct dvb_frontend_parameters *p = &fepriv->parameters; 1081 struct dvb_frontend_parameters *p = &fepriv->parameters_in;
1081 1082
1082 p->frequency = c->frequency; 1083 p->frequency = c->frequency;
1083 p->inversion = c->inversion; 1084 p->inversion = c->inversion;
@@ -1087,14 +1088,12 @@ static void dtv_property_legacy_params_sync(struct dvb_frontend *fe)
1087 dprintk("%s() Preparing QPSK req\n", __func__); 1088 dprintk("%s() Preparing QPSK req\n", __func__);
1088 p->u.qpsk.symbol_rate = c->symbol_rate; 1089 p->u.qpsk.symbol_rate = c->symbol_rate;
1089 p->u.qpsk.fec_inner = c->fec_inner; 1090 p->u.qpsk.fec_inner = c->fec_inner;
1090 c->delivery_system = SYS_DVBS;
1091 break; 1091 break;
1092 case FE_QAM: 1092 case FE_QAM:
1093 dprintk("%s() Preparing QAM req\n", __func__); 1093 dprintk("%s() Preparing QAM req\n", __func__);
1094 p->u.qam.symbol_rate = c->symbol_rate; 1094 p->u.qam.symbol_rate = c->symbol_rate;
1095 p->u.qam.fec_inner = c->fec_inner; 1095 p->u.qam.fec_inner = c->fec_inner;
1096 p->u.qam.modulation = c->modulation; 1096 p->u.qam.modulation = c->modulation;
1097 c->delivery_system = SYS_DVBC_ANNEX_AC;
1098 break; 1097 break;
1099 case FE_OFDM: 1098 case FE_OFDM:
1100 dprintk("%s() Preparing OFDM req\n", __func__); 1099 dprintk("%s() Preparing OFDM req\n", __func__);
@@ -1112,15 +1111,10 @@ static void dtv_property_legacy_params_sync(struct dvb_frontend *fe)
1112 p->u.ofdm.transmission_mode = c->transmission_mode; 1111 p->u.ofdm.transmission_mode = c->transmission_mode;
1113 p->u.ofdm.guard_interval = c->guard_interval; 1112 p->u.ofdm.guard_interval = c->guard_interval;
1114 p->u.ofdm.hierarchy_information = c->hierarchy; 1113 p->u.ofdm.hierarchy_information = c->hierarchy;
1115 c->delivery_system = SYS_DVBT;
1116 break; 1114 break;
1117 case FE_ATSC: 1115 case FE_ATSC:
1118 dprintk("%s() Preparing VSB req\n", __func__); 1116 dprintk("%s() Preparing VSB req\n", __func__);
1119 p->u.vsb.modulation = c->modulation; 1117 p->u.vsb.modulation = c->modulation;
1120 if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
1121 c->delivery_system = SYS_ATSC;
1122 else
1123 c->delivery_system = SYS_DVBC_ANNEX_B;
1124 break; 1118 break;
1125 } 1119 }
1126} 1120}
@@ -1130,9 +1124,9 @@ static void dtv_property_legacy_params_sync(struct dvb_frontend *fe)
1130 */ 1124 */
1131static void dtv_property_adv_params_sync(struct dvb_frontend *fe) 1125static void dtv_property_adv_params_sync(struct dvb_frontend *fe)
1132{ 1126{
1133 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1127 const struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1134 struct dvb_frontend_private *fepriv = fe->frontend_priv; 1128 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1135 struct dvb_frontend_parameters *p = &fepriv->parameters; 1129 struct dvb_frontend_parameters *p = &fepriv->parameters_in;
1136 1130
1137 p->frequency = c->frequency; 1131 p->frequency = c->frequency;
1138 p->inversion = c->inversion; 1132 p->inversion = c->inversion;
@@ -1149,10 +1143,9 @@ static void dtv_property_adv_params_sync(struct dvb_frontend *fe)
1149 break; 1143 break;
1150 } 1144 }
1151 1145
1152 if(c->delivery_system == SYS_ISDBT) { 1146 /* Fake out a generic DVB-T request so we pass validation in the ioctl */
1153 /* Fake out a generic DVB-T request so we pass validation in the ioctl */ 1147 if ((c->delivery_system == SYS_ISDBT) ||
1154 p->frequency = c->frequency; 1148 (c->delivery_system == SYS_DVBT2)) {
1155 p->inversion = c->inversion;
1156 p->u.ofdm.constellation = QAM_AUTO; 1149 p->u.ofdm.constellation = QAM_AUTO;
1157 p->u.ofdm.code_rate_HP = FEC_AUTO; 1150 p->u.ofdm.code_rate_HP = FEC_AUTO;
1158 p->u.ofdm.code_rate_LP = FEC_AUTO; 1151 p->u.ofdm.code_rate_LP = FEC_AUTO;
@@ -1172,7 +1165,7 @@ static void dtv_property_adv_params_sync(struct dvb_frontend *fe)
1172 1165
1173static void dtv_property_cache_submit(struct dvb_frontend *fe) 1166static void dtv_property_cache_submit(struct dvb_frontend *fe)
1174{ 1167{
1175 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1168 const struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1176 1169
1177 /* For legacy delivery systems we don't need the delivery_system to 1170 /* For legacy delivery systems we don't need the delivery_system to
1178 * be specified, but we populate the older structures from the cache 1171 * be specified, but we populate the older structures from the cache
@@ -1205,133 +1198,149 @@ static int dtv_property_process_get(struct dvb_frontend *fe,
1205 struct dtv_property *tvp, 1198 struct dtv_property *tvp,
1206 struct file *file) 1199 struct file *file)
1207{ 1200{
1208 int r = 0; 1201 const struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1209 1202 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1210 /* Allow the frontend to validate incoming properties */ 1203 struct dtv_frontend_properties cdetected;
1211 if (fe->ops.get_property) 1204 int r;
1212 r = fe->ops.get_property(fe, tvp);
1213 1205
1214 if (r < 0) 1206 /*
1215 return r; 1207 * If the driver implements a get_frontend function, then convert
1208 * detected parameters to S2API properties.
1209 */
1210 if (fe->ops.get_frontend) {
1211 cdetected = *c;
1212 dtv_property_cache_sync(fe, &cdetected, &fepriv->parameters_out);
1213 c = &cdetected;
1214 }
1216 1215
1217 switch(tvp->cmd) { 1216 switch(tvp->cmd) {
1218 case DTV_FREQUENCY: 1217 case DTV_FREQUENCY:
1219 tvp->u.data = fe->dtv_property_cache.frequency; 1218 tvp->u.data = c->frequency;
1220 break; 1219 break;
1221 case DTV_MODULATION: 1220 case DTV_MODULATION:
1222 tvp->u.data = fe->dtv_property_cache.modulation; 1221 tvp->u.data = c->modulation;
1223 break; 1222 break;
1224 case DTV_BANDWIDTH_HZ: 1223 case DTV_BANDWIDTH_HZ:
1225 tvp->u.data = fe->dtv_property_cache.bandwidth_hz; 1224 tvp->u.data = c->bandwidth_hz;
1226 break; 1225 break;
1227 case DTV_INVERSION: 1226 case DTV_INVERSION:
1228 tvp->u.data = fe->dtv_property_cache.inversion; 1227 tvp->u.data = c->inversion;
1229 break; 1228 break;
1230 case DTV_SYMBOL_RATE: 1229 case DTV_SYMBOL_RATE:
1231 tvp->u.data = fe->dtv_property_cache.symbol_rate; 1230 tvp->u.data = c->symbol_rate;
1232 break; 1231 break;
1233 case DTV_INNER_FEC: 1232 case DTV_INNER_FEC:
1234 tvp->u.data = fe->dtv_property_cache.fec_inner; 1233 tvp->u.data = c->fec_inner;
1235 break; 1234 break;
1236 case DTV_PILOT: 1235 case DTV_PILOT:
1237 tvp->u.data = fe->dtv_property_cache.pilot; 1236 tvp->u.data = c->pilot;
1238 break; 1237 break;
1239 case DTV_ROLLOFF: 1238 case DTV_ROLLOFF:
1240 tvp->u.data = fe->dtv_property_cache.rolloff; 1239 tvp->u.data = c->rolloff;
1241 break; 1240 break;
1242 case DTV_DELIVERY_SYSTEM: 1241 case DTV_DELIVERY_SYSTEM:
1243 tvp->u.data = fe->dtv_property_cache.delivery_system; 1242 tvp->u.data = c->delivery_system;
1244 break; 1243 break;
1245 case DTV_VOLTAGE: 1244 case DTV_VOLTAGE:
1246 tvp->u.data = fe->dtv_property_cache.voltage; 1245 tvp->u.data = c->voltage;
1247 break; 1246 break;
1248 case DTV_TONE: 1247 case DTV_TONE:
1249 tvp->u.data = fe->dtv_property_cache.sectone; 1248 tvp->u.data = c->sectone;
1250 break; 1249 break;
1251 case DTV_API_VERSION: 1250 case DTV_API_VERSION:
1252 tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR; 1251 tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR;
1253 break; 1252 break;
1254 case DTV_CODE_RATE_HP: 1253 case DTV_CODE_RATE_HP:
1255 tvp->u.data = fe->dtv_property_cache.code_rate_HP; 1254 tvp->u.data = c->code_rate_HP;
1256 break; 1255 break;
1257 case DTV_CODE_RATE_LP: 1256 case DTV_CODE_RATE_LP:
1258 tvp->u.data = fe->dtv_property_cache.code_rate_LP; 1257 tvp->u.data = c->code_rate_LP;
1259 break; 1258 break;
1260 case DTV_GUARD_INTERVAL: 1259 case DTV_GUARD_INTERVAL:
1261 tvp->u.data = fe->dtv_property_cache.guard_interval; 1260 tvp->u.data = c->guard_interval;
1262 break; 1261 break;
1263 case DTV_TRANSMISSION_MODE: 1262 case DTV_TRANSMISSION_MODE:
1264 tvp->u.data = fe->dtv_property_cache.transmission_mode; 1263 tvp->u.data = c->transmission_mode;
1265 break; 1264 break;
1266 case DTV_HIERARCHY: 1265 case DTV_HIERARCHY:
1267 tvp->u.data = fe->dtv_property_cache.hierarchy; 1266 tvp->u.data = c->hierarchy;
1268 break; 1267 break;
1269 1268
1270 /* ISDB-T Support here */ 1269 /* ISDB-T Support here */
1271 case DTV_ISDBT_PARTIAL_RECEPTION: 1270 case DTV_ISDBT_PARTIAL_RECEPTION:
1272 tvp->u.data = fe->dtv_property_cache.isdbt_partial_reception; 1271 tvp->u.data = c->isdbt_partial_reception;
1273 break; 1272 break;
1274 case DTV_ISDBT_SOUND_BROADCASTING: 1273 case DTV_ISDBT_SOUND_BROADCASTING:
1275 tvp->u.data = fe->dtv_property_cache.isdbt_sb_mode; 1274 tvp->u.data = c->isdbt_sb_mode;
1276 break; 1275 break;
1277 case DTV_ISDBT_SB_SUBCHANNEL_ID: 1276 case DTV_ISDBT_SB_SUBCHANNEL_ID:
1278 tvp->u.data = fe->dtv_property_cache.isdbt_sb_subchannel; 1277 tvp->u.data = c->isdbt_sb_subchannel;
1279 break; 1278 break;
1280 case DTV_ISDBT_SB_SEGMENT_IDX: 1279 case DTV_ISDBT_SB_SEGMENT_IDX:
1281 tvp->u.data = fe->dtv_property_cache.isdbt_sb_segment_idx; 1280 tvp->u.data = c->isdbt_sb_segment_idx;
1282 break; 1281 break;
1283 case DTV_ISDBT_SB_SEGMENT_COUNT: 1282 case DTV_ISDBT_SB_SEGMENT_COUNT:
1284 tvp->u.data = fe->dtv_property_cache.isdbt_sb_segment_count; 1283 tvp->u.data = c->isdbt_sb_segment_count;
1285 break; 1284 break;
1286 case DTV_ISDBT_LAYER_ENABLED: 1285 case DTV_ISDBT_LAYER_ENABLED:
1287 tvp->u.data = fe->dtv_property_cache.isdbt_layer_enabled; 1286 tvp->u.data = c->isdbt_layer_enabled;
1288 break; 1287 break;
1289 case DTV_ISDBT_LAYERA_FEC: 1288 case DTV_ISDBT_LAYERA_FEC:
1290 tvp->u.data = fe->dtv_property_cache.layer[0].fec; 1289 tvp->u.data = c->layer[0].fec;
1291 break; 1290 break;
1292 case DTV_ISDBT_LAYERA_MODULATION: 1291 case DTV_ISDBT_LAYERA_MODULATION:
1293 tvp->u.data = fe->dtv_property_cache.layer[0].modulation; 1292 tvp->u.data = c->layer[0].modulation;
1294 break; 1293 break;
1295 case DTV_ISDBT_LAYERA_SEGMENT_COUNT: 1294 case DTV_ISDBT_LAYERA_SEGMENT_COUNT:
1296 tvp->u.data = fe->dtv_property_cache.layer[0].segment_count; 1295 tvp->u.data = c->layer[0].segment_count;
1297 break; 1296 break;
1298 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING: 1297 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING:
1299 tvp->u.data = fe->dtv_property_cache.layer[0].interleaving; 1298 tvp->u.data = c->layer[0].interleaving;
1300 break; 1299 break;
1301 case DTV_ISDBT_LAYERB_FEC: 1300 case DTV_ISDBT_LAYERB_FEC:
1302 tvp->u.data = fe->dtv_property_cache.layer[1].fec; 1301 tvp->u.data = c->layer[1].fec;
1303 break; 1302 break;
1304 case DTV_ISDBT_LAYERB_MODULATION: 1303 case DTV_ISDBT_LAYERB_MODULATION:
1305 tvp->u.data = fe->dtv_property_cache.layer[1].modulation; 1304 tvp->u.data = c->layer[1].modulation;
1306 break; 1305 break;
1307 case DTV_ISDBT_LAYERB_SEGMENT_COUNT: 1306 case DTV_ISDBT_LAYERB_SEGMENT_COUNT:
1308 tvp->u.data = fe->dtv_property_cache.layer[1].segment_count; 1307 tvp->u.data = c->layer[1].segment_count;
1309 break; 1308 break;
1310 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING: 1309 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING:
1311 tvp->u.data = fe->dtv_property_cache.layer[1].interleaving; 1310 tvp->u.data = c->layer[1].interleaving;
1312 break; 1311 break;
1313 case DTV_ISDBT_LAYERC_FEC: 1312 case DTV_ISDBT_LAYERC_FEC:
1314 tvp->u.data = fe->dtv_property_cache.layer[2].fec; 1313 tvp->u.data = c->layer[2].fec;
1315 break; 1314 break;
1316 case DTV_ISDBT_LAYERC_MODULATION: 1315 case DTV_ISDBT_LAYERC_MODULATION:
1317 tvp->u.data = fe->dtv_property_cache.layer[2].modulation; 1316 tvp->u.data = c->layer[2].modulation;
1318 break; 1317 break;
1319 case DTV_ISDBT_LAYERC_SEGMENT_COUNT: 1318 case DTV_ISDBT_LAYERC_SEGMENT_COUNT:
1320 tvp->u.data = fe->dtv_property_cache.layer[2].segment_count; 1319 tvp->u.data = c->layer[2].segment_count;
1321 break; 1320 break;
1322 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING: 1321 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING:
1323 tvp->u.data = fe->dtv_property_cache.layer[2].interleaving; 1322 tvp->u.data = c->layer[2].interleaving;
1324 break; 1323 break;
1325 case DTV_ISDBS_TS_ID: 1324 case DTV_ISDBS_TS_ID:
1326 tvp->u.data = fe->dtv_property_cache.isdbs_ts_id; 1325 tvp->u.data = c->isdbs_ts_id;
1326 break;
1327 case DTV_DVBT2_PLP_ID:
1328 tvp->u.data = c->dvbt2_plp_id;
1327 break; 1329 break;
1328 default: 1330 default:
1329 r = -1; 1331 return -EINVAL;
1332 }
1333
1334 /* Allow the frontend to override outgoing properties */
1335 if (fe->ops.get_property) {
1336 r = fe->ops.get_property(fe, tvp);
1337 if (r < 0)
1338 return r;
1330 } 1339 }
1331 1340
1332 dtv_property_dump(tvp); 1341 dtv_property_dump(tvp);
1333 1342
1334 return r; 1343 return 0;
1335} 1344}
1336 1345
1337static int dtv_property_process_set(struct dvb_frontend *fe, 1346static int dtv_property_process_set(struct dvb_frontend *fe,
@@ -1339,15 +1348,16 @@ static int dtv_property_process_set(struct dvb_frontend *fe,
1339 struct file *file) 1348 struct file *file)
1340{ 1349{
1341 int r = 0; 1350 int r = 0;
1351 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1342 struct dvb_frontend_private *fepriv = fe->frontend_priv; 1352 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1343 dtv_property_dump(tvp); 1353 dtv_property_dump(tvp);
1344 1354
1345 /* Allow the frontend to validate incoming properties */ 1355 /* Allow the frontend to validate incoming properties */
1346 if (fe->ops.set_property) 1356 if (fe->ops.set_property) {
1347 r = fe->ops.set_property(fe, tvp); 1357 r = fe->ops.set_property(fe, tvp);
1348 1358 if (r < 0)
1349 if (r < 0) 1359 return r;
1350 return r; 1360 }
1351 1361
1352 switch(tvp->cmd) { 1362 switch(tvp->cmd) {
1353 case DTV_CLEAR: 1363 case DTV_CLEAR:
@@ -1362,126 +1372,129 @@ static int dtv_property_process_set(struct dvb_frontend *fe,
1362 * tunerequest so we can pass validation in the FE_SET_FRONTEND 1372 * tunerequest so we can pass validation in the FE_SET_FRONTEND
1363 * ioctl. 1373 * ioctl.
1364 */ 1374 */
1365 fe->dtv_property_cache.state = tvp->cmd; 1375 c->state = tvp->cmd;
1366 dprintk("%s() Finalised property cache\n", __func__); 1376 dprintk("%s() Finalised property cache\n", __func__);
1367 dtv_property_cache_submit(fe); 1377 dtv_property_cache_submit(fe);
1368 1378
1369 r |= dvb_frontend_ioctl_legacy(file, FE_SET_FRONTEND, 1379 r = dvb_frontend_ioctl_legacy(file, FE_SET_FRONTEND,
1370 &fepriv->parameters); 1380 &fepriv->parameters_in);
1371 break; 1381 break;
1372 case DTV_FREQUENCY: 1382 case DTV_FREQUENCY:
1373 fe->dtv_property_cache.frequency = tvp->u.data; 1383 c->frequency = tvp->u.data;
1374 break; 1384 break;
1375 case DTV_MODULATION: 1385 case DTV_MODULATION:
1376 fe->dtv_property_cache.modulation = tvp->u.data; 1386 c->modulation = tvp->u.data;
1377 break; 1387 break;
1378 case DTV_BANDWIDTH_HZ: 1388 case DTV_BANDWIDTH_HZ:
1379 fe->dtv_property_cache.bandwidth_hz = tvp->u.data; 1389 c->bandwidth_hz = tvp->u.data;
1380 break; 1390 break;
1381 case DTV_INVERSION: 1391 case DTV_INVERSION:
1382 fe->dtv_property_cache.inversion = tvp->u.data; 1392 c->inversion = tvp->u.data;
1383 break; 1393 break;
1384 case DTV_SYMBOL_RATE: 1394 case DTV_SYMBOL_RATE:
1385 fe->dtv_property_cache.symbol_rate = tvp->u.data; 1395 c->symbol_rate = tvp->u.data;
1386 break; 1396 break;
1387 case DTV_INNER_FEC: 1397 case DTV_INNER_FEC:
1388 fe->dtv_property_cache.fec_inner = tvp->u.data; 1398 c->fec_inner = tvp->u.data;
1389 break; 1399 break;
1390 case DTV_PILOT: 1400 case DTV_PILOT:
1391 fe->dtv_property_cache.pilot = tvp->u.data; 1401 c->pilot = tvp->u.data;
1392 break; 1402 break;
1393 case DTV_ROLLOFF: 1403 case DTV_ROLLOFF:
1394 fe->dtv_property_cache.rolloff = tvp->u.data; 1404 c->rolloff = tvp->u.data;
1395 break; 1405 break;
1396 case DTV_DELIVERY_SYSTEM: 1406 case DTV_DELIVERY_SYSTEM:
1397 fe->dtv_property_cache.delivery_system = tvp->u.data; 1407 c->delivery_system = tvp->u.data;
1398 break; 1408 break;
1399 case DTV_VOLTAGE: 1409 case DTV_VOLTAGE:
1400 fe->dtv_property_cache.voltage = tvp->u.data; 1410 c->voltage = tvp->u.data;
1401 r = dvb_frontend_ioctl_legacy(file, FE_SET_VOLTAGE, 1411 r = dvb_frontend_ioctl_legacy(file, FE_SET_VOLTAGE,
1402 (void *)fe->dtv_property_cache.voltage); 1412 (void *)c->voltage);
1403 break; 1413 break;
1404 case DTV_TONE: 1414 case DTV_TONE:
1405 fe->dtv_property_cache.sectone = tvp->u.data; 1415 c->sectone = tvp->u.data;
1406 r = dvb_frontend_ioctl_legacy(file, FE_SET_TONE, 1416 r = dvb_frontend_ioctl_legacy(file, FE_SET_TONE,
1407 (void *)fe->dtv_property_cache.sectone); 1417 (void *)c->sectone);
1408 break; 1418 break;
1409 case DTV_CODE_RATE_HP: 1419 case DTV_CODE_RATE_HP:
1410 fe->dtv_property_cache.code_rate_HP = tvp->u.data; 1420 c->code_rate_HP = tvp->u.data;
1411 break; 1421 break;
1412 case DTV_CODE_RATE_LP: 1422 case DTV_CODE_RATE_LP:
1413 fe->dtv_property_cache.code_rate_LP = tvp->u.data; 1423 c->code_rate_LP = tvp->u.data;
1414 break; 1424 break;
1415 case DTV_GUARD_INTERVAL: 1425 case DTV_GUARD_INTERVAL:
1416 fe->dtv_property_cache.guard_interval = tvp->u.data; 1426 c->guard_interval = tvp->u.data;
1417 break; 1427 break;
1418 case DTV_TRANSMISSION_MODE: 1428 case DTV_TRANSMISSION_MODE:
1419 fe->dtv_property_cache.transmission_mode = tvp->u.data; 1429 c->transmission_mode = tvp->u.data;
1420 break; 1430 break;
1421 case DTV_HIERARCHY: 1431 case DTV_HIERARCHY:
1422 fe->dtv_property_cache.hierarchy = tvp->u.data; 1432 c->hierarchy = tvp->u.data;
1423 break; 1433 break;
1424 1434
1425 /* ISDB-T Support here */ 1435 /* ISDB-T Support here */
1426 case DTV_ISDBT_PARTIAL_RECEPTION: 1436 case DTV_ISDBT_PARTIAL_RECEPTION:
1427 fe->dtv_property_cache.isdbt_partial_reception = tvp->u.data; 1437 c->isdbt_partial_reception = tvp->u.data;
1428 break; 1438 break;
1429 case DTV_ISDBT_SOUND_BROADCASTING: 1439 case DTV_ISDBT_SOUND_BROADCASTING:
1430 fe->dtv_property_cache.isdbt_sb_mode = tvp->u.data; 1440 c->isdbt_sb_mode = tvp->u.data;
1431 break; 1441 break;
1432 case DTV_ISDBT_SB_SUBCHANNEL_ID: 1442 case DTV_ISDBT_SB_SUBCHANNEL_ID:
1433 fe->dtv_property_cache.isdbt_sb_subchannel = tvp->u.data; 1443 c->isdbt_sb_subchannel = tvp->u.data;
1434 break; 1444 break;
1435 case DTV_ISDBT_SB_SEGMENT_IDX: 1445 case DTV_ISDBT_SB_SEGMENT_IDX:
1436 fe->dtv_property_cache.isdbt_sb_segment_idx = tvp->u.data; 1446 c->isdbt_sb_segment_idx = tvp->u.data;
1437 break; 1447 break;
1438 case DTV_ISDBT_SB_SEGMENT_COUNT: 1448 case DTV_ISDBT_SB_SEGMENT_COUNT:
1439 fe->dtv_property_cache.isdbt_sb_segment_count = tvp->u.data; 1449 c->isdbt_sb_segment_count = tvp->u.data;
1440 break; 1450 break;
1441 case DTV_ISDBT_LAYER_ENABLED: 1451 case DTV_ISDBT_LAYER_ENABLED:
1442 fe->dtv_property_cache.isdbt_layer_enabled = tvp->u.data; 1452 c->isdbt_layer_enabled = tvp->u.data;
1443 break; 1453 break;
1444 case DTV_ISDBT_LAYERA_FEC: 1454 case DTV_ISDBT_LAYERA_FEC:
1445 fe->dtv_property_cache.layer[0].fec = tvp->u.data; 1455 c->layer[0].fec = tvp->u.data;
1446 break; 1456 break;
1447 case DTV_ISDBT_LAYERA_MODULATION: 1457 case DTV_ISDBT_LAYERA_MODULATION:
1448 fe->dtv_property_cache.layer[0].modulation = tvp->u.data; 1458 c->layer[0].modulation = tvp->u.data;
1449 break; 1459 break;
1450 case DTV_ISDBT_LAYERA_SEGMENT_COUNT: 1460 case DTV_ISDBT_LAYERA_SEGMENT_COUNT:
1451 fe->dtv_property_cache.layer[0].segment_count = tvp->u.data; 1461 c->layer[0].segment_count = tvp->u.data;
1452 break; 1462 break;
1453 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING: 1463 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING:
1454 fe->dtv_property_cache.layer[0].interleaving = tvp->u.data; 1464 c->layer[0].interleaving = tvp->u.data;
1455 break; 1465 break;
1456 case DTV_ISDBT_LAYERB_FEC: 1466 case DTV_ISDBT_LAYERB_FEC:
1457 fe->dtv_property_cache.layer[1].fec = tvp->u.data; 1467 c->layer[1].fec = tvp->u.data;
1458 break; 1468 break;
1459 case DTV_ISDBT_LAYERB_MODULATION: 1469 case DTV_ISDBT_LAYERB_MODULATION:
1460 fe->dtv_property_cache.layer[1].modulation = tvp->u.data; 1470 c->layer[1].modulation = tvp->u.data;
1461 break; 1471 break;
1462 case DTV_ISDBT_LAYERB_SEGMENT_COUNT: 1472 case DTV_ISDBT_LAYERB_SEGMENT_COUNT:
1463 fe->dtv_property_cache.layer[1].segment_count = tvp->u.data; 1473 c->layer[1].segment_count = tvp->u.data;
1464 break; 1474 break;
1465 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING: 1475 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING:
1466 fe->dtv_property_cache.layer[1].interleaving = tvp->u.data; 1476 c->layer[1].interleaving = tvp->u.data;
1467 break; 1477 break;
1468 case DTV_ISDBT_LAYERC_FEC: 1478 case DTV_ISDBT_LAYERC_FEC:
1469 fe->dtv_property_cache.layer[2].fec = tvp->u.data; 1479 c->layer[2].fec = tvp->u.data;
1470 break; 1480 break;
1471 case DTV_ISDBT_LAYERC_MODULATION: 1481 case DTV_ISDBT_LAYERC_MODULATION:
1472 fe->dtv_property_cache.layer[2].modulation = tvp->u.data; 1482 c->layer[2].modulation = tvp->u.data;
1473 break; 1483 break;
1474 case DTV_ISDBT_LAYERC_SEGMENT_COUNT: 1484 case DTV_ISDBT_LAYERC_SEGMENT_COUNT:
1475 fe->dtv_property_cache.layer[2].segment_count = tvp->u.data; 1485 c->layer[2].segment_count = tvp->u.data;
1476 break; 1486 break;
1477 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING: 1487 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING:
1478 fe->dtv_property_cache.layer[2].interleaving = tvp->u.data; 1488 c->layer[2].interleaving = tvp->u.data;
1479 break; 1489 break;
1480 case DTV_ISDBS_TS_ID: 1490 case DTV_ISDBS_TS_ID:
1481 fe->dtv_property_cache.isdbs_ts_id = tvp->u.data; 1491 c->isdbs_ts_id = tvp->u.data;
1492 break;
1493 case DTV_DVBT2_PLP_ID:
1494 c->dvbt2_plp_id = tvp->u.data;
1482 break; 1495 break;
1483 default: 1496 default:
1484 r = -1; 1497 return -EINVAL;
1485 } 1498 }
1486 1499
1487 return r; 1500 return r;
@@ -1492,6 +1505,7 @@ static int dvb_frontend_ioctl(struct file *file,
1492{ 1505{
1493 struct dvb_device *dvbdev = file->private_data; 1506 struct dvb_device *dvbdev = file->private_data;
1494 struct dvb_frontend *fe = dvbdev->priv; 1507 struct dvb_frontend *fe = dvbdev->priv;
1508 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1495 struct dvb_frontend_private *fepriv = fe->frontend_priv; 1509 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1496 int err = -EOPNOTSUPP; 1510 int err = -EOPNOTSUPP;
1497 1511
@@ -1511,7 +1525,7 @@ static int dvb_frontend_ioctl(struct file *file,
1511 if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY)) 1525 if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY))
1512 err = dvb_frontend_ioctl_properties(file, cmd, parg); 1526 err = dvb_frontend_ioctl_properties(file, cmd, parg);
1513 else { 1527 else {
1514 fe->dtv_property_cache.state = DTV_UNDEFINED; 1528 c->state = DTV_UNDEFINED;
1515 err = dvb_frontend_ioctl_legacy(file, cmd, parg); 1529 err = dvb_frontend_ioctl_legacy(file, cmd, parg);
1516 } 1530 }
1517 1531
@@ -1524,6 +1538,7 @@ static int dvb_frontend_ioctl_properties(struct file *file,
1524{ 1538{
1525 struct dvb_device *dvbdev = file->private_data; 1539 struct dvb_device *dvbdev = file->private_data;
1526 struct dvb_frontend *fe = dvbdev->priv; 1540 struct dvb_frontend *fe = dvbdev->priv;
1541 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1527 int err = 0; 1542 int err = 0;
1528 1543
1529 struct dtv_properties *tvps = NULL; 1544 struct dtv_properties *tvps = NULL;
@@ -1555,11 +1570,13 @@ static int dvb_frontend_ioctl_properties(struct file *file,
1555 } 1570 }
1556 1571
1557 for (i = 0; i < tvps->num; i++) { 1572 for (i = 0; i < tvps->num; i++) {
1558 (tvp + i)->result = dtv_property_process_set(fe, tvp + i, file); 1573 err = dtv_property_process_set(fe, tvp + i, file);
1559 err |= (tvp + i)->result; 1574 if (err < 0)
1575 goto out;
1576 (tvp + i)->result = err;
1560 } 1577 }
1561 1578
1562 if(fe->dtv_property_cache.state == DTV_TUNE) 1579 if (c->state == DTV_TUNE)
1563 dprintk("%s() Property cache is full, tuning\n", __func__); 1580 dprintk("%s() Property cache is full, tuning\n", __func__);
1564 1581
1565 } else 1582 } else
@@ -1587,8 +1604,10 @@ static int dvb_frontend_ioctl_properties(struct file *file,
1587 } 1604 }
1588 1605
1589 for (i = 0; i < tvps->num; i++) { 1606 for (i = 0; i < tvps->num; i++) {
1590 (tvp + i)->result = dtv_property_process_get(fe, tvp + i, file); 1607 err = dtv_property_process_get(fe, tvp + i, file);
1591 err |= (tvp + i)->result; 1608 if (err < 0)
1609 goto out;
1610 (tvp + i)->result = err;
1592 } 1611 }
1593 1612
1594 if (copy_to_user(tvps->props, tvp, tvps->num * sizeof(struct dtv_property))) { 1613 if (copy_to_user(tvps->props, tvp, tvps->num * sizeof(struct dtv_property))) {
@@ -1639,7 +1658,7 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
1639 case FE_READ_STATUS: { 1658 case FE_READ_STATUS: {
1640 fe_status_t* status = parg; 1659 fe_status_t* status = parg;
1641 1660
1642 /* if retune was requested but hasn't occured yet, prevent 1661 /* if retune was requested but hasn't occurred yet, prevent
1643 * that user get signal state from previous tuning */ 1662 * that user get signal state from previous tuning */
1644 if (fepriv->state == FESTATE_RETUNE || 1663 if (fepriv->state == FESTATE_RETUNE ||
1645 fepriv->state == FESTATE_ERROR) { 1664 fepriv->state == FESTATE_ERROR) {
@@ -1730,7 +1749,7 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
1730 * Dish network legacy switches (as used by Dish500) 1749 * Dish network legacy switches (as used by Dish500)
1731 * are controlled by sending 9-bit command words 1750 * are controlled by sending 9-bit command words
1732 * spaced 8msec apart. 1751 * spaced 8msec apart.
1733 * the actual command word is switch/port dependant 1752 * the actual command word is switch/port dependent
1734 * so it is up to the userspace application to send 1753 * so it is up to the userspace application to send
1735 * the right command. 1754 * the right command.
1736 * The command must always start with a '0' after 1755 * The command must always start with a '0' after
@@ -1788,10 +1807,11 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
1788 break; 1807 break;
1789 1808
1790 case FE_SET_FRONTEND: { 1809 case FE_SET_FRONTEND: {
1810 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1791 struct dvb_frontend_tune_settings fetunesettings; 1811 struct dvb_frontend_tune_settings fetunesettings;
1792 1812
1793 if(fe->dtv_property_cache.state == DTV_TUNE) { 1813 if (c->state == DTV_TUNE) {
1794 if (dvb_frontend_check_parameters(fe, &fepriv->parameters) < 0) { 1814 if (dvb_frontend_check_parameters(fe, &fepriv->parameters_in) < 0) {
1795 err = -EINVAL; 1815 err = -EINVAL;
1796 break; 1816 break;
1797 } 1817 }
@@ -1801,9 +1821,9 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
1801 break; 1821 break;
1802 } 1822 }
1803 1823
1804 memcpy (&fepriv->parameters, parg, 1824 memcpy (&fepriv->parameters_in, parg,
1805 sizeof (struct dvb_frontend_parameters)); 1825 sizeof (struct dvb_frontend_parameters));
1806 dtv_property_cache_sync(fe, &fepriv->parameters); 1826 dtv_property_cache_sync(fe, c, &fepriv->parameters_in);
1807 } 1827 }
1808 1828
1809 memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings)); 1829 memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings));
@@ -1812,15 +1832,15 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
1812 1832
1813 /* force auto frequency inversion if requested */ 1833 /* force auto frequency inversion if requested */
1814 if (dvb_force_auto_inversion) { 1834 if (dvb_force_auto_inversion) {
1815 fepriv->parameters.inversion = INVERSION_AUTO; 1835 fepriv->parameters_in.inversion = INVERSION_AUTO;
1816 fetunesettings.parameters.inversion = INVERSION_AUTO; 1836 fetunesettings.parameters.inversion = INVERSION_AUTO;
1817 } 1837 }
1818 if (fe->ops.info.type == FE_OFDM) { 1838 if (fe->ops.info.type == FE_OFDM) {
1819 /* without hierarchical coding code_rate_LP is irrelevant, 1839 /* without hierarchical coding code_rate_LP is irrelevant,
1820 * so we tolerate the otherwise invalid FEC_NONE setting */ 1840 * so we tolerate the otherwise invalid FEC_NONE setting */
1821 if (fepriv->parameters.u.ofdm.hierarchy_information == HIERARCHY_NONE && 1841 if (fepriv->parameters_in.u.ofdm.hierarchy_information == HIERARCHY_NONE &&
1822 fepriv->parameters.u.ofdm.code_rate_LP == FEC_NONE) 1842 fepriv->parameters_in.u.ofdm.code_rate_LP == FEC_NONE)
1823 fepriv->parameters.u.ofdm.code_rate_LP = FEC_AUTO; 1843 fepriv->parameters_in.u.ofdm.code_rate_LP = FEC_AUTO;
1824 } 1844 }
1825 1845
1826 /* get frontend-specific tuning settings */ 1846 /* get frontend-specific tuning settings */
@@ -1833,8 +1853,8 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
1833 switch(fe->ops.info.type) { 1853 switch(fe->ops.info.type) {
1834 case FE_QPSK: 1854 case FE_QPSK:
1835 fepriv->min_delay = HZ/20; 1855 fepriv->min_delay = HZ/20;
1836 fepriv->step_size = fepriv->parameters.u.qpsk.symbol_rate / 16000; 1856 fepriv->step_size = fepriv->parameters_in.u.qpsk.symbol_rate / 16000;
1837 fepriv->max_drift = fepriv->parameters.u.qpsk.symbol_rate / 2000; 1857 fepriv->max_drift = fepriv->parameters_in.u.qpsk.symbol_rate / 2000;
1838 break; 1858 break;
1839 1859
1840 case FE_QAM: 1860 case FE_QAM:
@@ -1876,8 +1896,8 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
1876 1896
1877 case FE_GET_FRONTEND: 1897 case FE_GET_FRONTEND:
1878 if (fe->ops.get_frontend) { 1898 if (fe->ops.get_frontend) {
1879 memcpy (parg, &fepriv->parameters, sizeof (struct dvb_frontend_parameters)); 1899 err = fe->ops.get_frontend(fe, &fepriv->parameters_out);
1880 err = fe->ops.get_frontend(fe, (struct dvb_frontend_parameters*) parg); 1900 memcpy(parg, &fepriv->parameters_out, sizeof(struct dvb_frontend_parameters));
1881 } 1901 }
1882 break; 1902 break;
1883 1903
@@ -1968,6 +1988,14 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
1968 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) { 1988 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) {
1969 if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0) 1989 if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0)
1970 goto err0; 1990 goto err0;
1991
1992 /* If we took control of the bus, we need to force
1993 reinitialization. This is because many ts_bus_ctrl()
1994 functions strobe the RESET pin on the demod, and if the
1995 frontend thread already exists then the dvb_init() routine
1996 won't get called (which is what usually does initial
1997 register configuration). */
1998 fepriv->reinitialise = 1;
1971 } 1999 }
1972 2000
1973 if ((ret = dvb_generic_open (inode, file)) < 0) 2001 if ((ret = dvb_generic_open (inode, file)) < 0)
@@ -2034,7 +2062,8 @@ static const struct file_operations dvb_frontend_fops = {
2034 .unlocked_ioctl = dvb_generic_ioctl, 2062 .unlocked_ioctl = dvb_generic_ioctl,
2035 .poll = dvb_frontend_poll, 2063 .poll = dvb_frontend_poll,
2036 .open = dvb_frontend_open, 2064 .open = dvb_frontend_open,
2037 .release = dvb_frontend_release 2065 .release = dvb_frontend_release,
2066 .llseek = noop_llseek,
2038}; 2067};
2039 2068
2040int dvb_register_frontend(struct dvb_adapter* dvb, 2069int dvb_register_frontend(struct dvb_adapter* dvb,
@@ -2061,7 +2090,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
2061 } 2090 }
2062 fepriv = fe->frontend_priv; 2091 fepriv = fe->frontend_priv;
2063 2092
2064 init_MUTEX (&fepriv->sem); 2093 sema_init(&fepriv->sem, 1);
2065 init_waitqueue_head (&fepriv->wait_queue); 2094 init_waitqueue_head (&fepriv->wait_queue);
2066 init_waitqueue_head (&fepriv->events.wait_queue); 2095 init_waitqueue_head (&fepriv->events.wait_queue);
2067 mutex_init(&fepriv->events.mtx); 2096 mutex_init(&fepriv->events.mtx);
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.h b/drivers/media/dvb/dvb-core/dvb_frontend.h
index bf0e6bed28dd..5590eb6eb408 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.h
@@ -239,7 +239,6 @@ struct analog_demod_ops {
239 void (*set_params)(struct dvb_frontend *fe, 239 void (*set_params)(struct dvb_frontend *fe,
240 struct analog_parameters *params); 240 struct analog_parameters *params);
241 int (*has_signal)(struct dvb_frontend *fe); 241 int (*has_signal)(struct dvb_frontend *fe);
242 int (*is_stereo)(struct dvb_frontend *fe);
243 int (*get_afc)(struct dvb_frontend *fe); 242 int (*get_afc)(struct dvb_frontend *fe);
244 void (*tuner_status)(struct dvb_frontend *fe); 243 void (*tuner_status)(struct dvb_frontend *fe);
245 void (*standby)(struct dvb_frontend *fe); 244 void (*standby)(struct dvb_frontend *fe);
@@ -260,7 +259,7 @@ struct dvb_frontend_ops {
260 int (*init)(struct dvb_frontend* fe); 259 int (*init)(struct dvb_frontend* fe);
261 int (*sleep)(struct dvb_frontend* fe); 260 int (*sleep)(struct dvb_frontend* fe);
262 261
263 int (*write)(struct dvb_frontend* fe, u8* buf, int len); 262 int (*write)(struct dvb_frontend* fe, const u8 buf[], int len);
264 263
265 /* if this is set, it overrides the default swzigzag */ 264 /* if this is set, it overrides the default swzigzag */
266 int (*tune)(struct dvb_frontend* fe, 265 int (*tune)(struct dvb_frontend* fe,
@@ -359,6 +358,9 @@ struct dtv_frontend_properties {
359 358
360 /* ISDB-T specifics */ 359 /* ISDB-T specifics */
361 u32 isdbs_ts_id; 360 u32 isdbs_ts_id;
361
362 /* DVB-T2 specifics */
363 u32 dvbt2_plp_id;
362}; 364};
363 365
364struct dvb_frontend { 366struct dvb_frontend {
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index 6c3a8a06ccab..51752a9ef7a4 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -59,7 +59,6 @@
59#include <linux/netdevice.h> 59#include <linux/netdevice.h>
60#include <linux/etherdevice.h> 60#include <linux/etherdevice.h>
61#include <linux/dvb/net.h> 61#include <linux/dvb/net.h>
62#include <linux/smp_lock.h>
63#include <linux/uio.h> 62#include <linux/uio.h>
64#include <asm/uaccess.h> 63#include <asm/uaccess.h>
65#include <linux/crc32.h> 64#include <linux/crc32.h>
@@ -1330,7 +1329,8 @@ static int dvb_net_remove_if(struct dvb_net *dvbnet, unsigned long num)
1330 return -EBUSY; 1329 return -EBUSY;
1331 1330
1332 dvb_net_stop(net); 1331 dvb_net_stop(net);
1333 flush_scheduled_work(); 1332 flush_work_sync(&priv->set_multicast_list_wq);
1333 flush_work_sync(&priv->restart_net_feed_wq);
1334 printk("dvb_net: removed network interface %s\n", net->name); 1334 printk("dvb_net: removed network interface %s\n", net->name);
1335 unregister_netdev(net); 1335 unregister_netdev(net);
1336 dvbnet->state[num]=0; 1336 dvbnet->state[num]=0;
@@ -1445,13 +1445,7 @@ static int dvb_net_do_ioctl(struct file *file,
1445static long dvb_net_ioctl(struct file *file, 1445static long dvb_net_ioctl(struct file *file,
1446 unsigned int cmd, unsigned long arg) 1446 unsigned int cmd, unsigned long arg)
1447{ 1447{
1448 int ret; 1448 return dvb_usercopy(file, cmd, arg, dvb_net_do_ioctl);
1449
1450 lock_kernel();
1451 ret = dvb_usercopy(file, cmd, arg, dvb_net_do_ioctl);
1452 unlock_kernel();
1453
1454 return ret;
1455} 1449}
1456 1450
1457static int dvb_net_close(struct inode *inode, struct file *file) 1451static int dvb_net_close(struct inode *inode, struct file *file)
@@ -1475,6 +1469,7 @@ static const struct file_operations dvb_net_fops = {
1475 .unlocked_ioctl = dvb_net_ioctl, 1469 .unlocked_ioctl = dvb_net_ioctl,
1476 .open = dvb_generic_open, 1470 .open = dvb_generic_open,
1477 .release = dvb_net_close, 1471 .release = dvb_net_close,
1472 .llseek = noop_llseek,
1478}; 1473};
1479 1474
1480static struct dvb_device dvbdev_net = { 1475static struct dvb_device dvbdev_net = {
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index b915c39d782f..f73287775953 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -32,9 +32,9 @@
32#include <linux/fs.h> 32#include <linux/fs.h>
33#include <linux/cdev.h> 33#include <linux/cdev.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/smp_lock.h>
36#include "dvbdev.h" 35#include "dvbdev.h"
37 36
37static DEFINE_MUTEX(dvbdev_mutex);
38static int dvbdev_debug; 38static int dvbdev_debug;
39 39
40module_param(dvbdev_debug, int, 0644); 40module_param(dvbdev_debug, int, 0644);
@@ -68,7 +68,7 @@ static int dvb_device_open(struct inode *inode, struct file *file)
68{ 68{
69 struct dvb_device *dvbdev; 69 struct dvb_device *dvbdev;
70 70
71 lock_kernel(); 71 mutex_lock(&dvbdev_mutex);
72 down_read(&minor_rwsem); 72 down_read(&minor_rwsem);
73 dvbdev = dvb_minors[iminor(inode)]; 73 dvbdev = dvb_minors[iminor(inode)];
74 74
@@ -91,12 +91,12 @@ static int dvb_device_open(struct inode *inode, struct file *file)
91 } 91 }
92 fops_put(old_fops); 92 fops_put(old_fops);
93 up_read(&minor_rwsem); 93 up_read(&minor_rwsem);
94 unlock_kernel(); 94 mutex_unlock(&dvbdev_mutex);
95 return err; 95 return err;
96 } 96 }
97fail: 97fail:
98 up_read(&minor_rwsem); 98 up_read(&minor_rwsem);
99 unlock_kernel(); 99 mutex_unlock(&dvbdev_mutex);
100 return -ENODEV; 100 return -ENODEV;
101} 101}
102 102
@@ -105,6 +105,7 @@ static const struct file_operations dvb_device_fops =
105{ 105{
106 .owner = THIS_MODULE, 106 .owner = THIS_MODULE,
107 .open = dvb_device_open, 107 .open = dvb_device_open,
108 .llseek = noop_llseek,
108}; 109};
109 110
110static struct cdev dvb_device_cdev; 111static struct cdev dvb_device_cdev;
@@ -158,7 +159,6 @@ long dvb_generic_ioctl(struct file *file,
158 unsigned int cmd, unsigned long arg) 159 unsigned int cmd, unsigned long arg)
159{ 160{
160 struct dvb_device *dvbdev = file->private_data; 161 struct dvb_device *dvbdev = file->private_data;
161 int ret;
162 162
163 if (!dvbdev) 163 if (!dvbdev)
164 return -ENODEV; 164 return -ENODEV;
@@ -166,11 +166,7 @@ long dvb_generic_ioctl(struct file *file,
166 if (!dvbdev->kernel_ioctl) 166 if (!dvbdev->kernel_ioctl)
167 return -EINVAL; 167 return -EINVAL;
168 168
169 lock_kernel(); 169 return dvb_usercopy(file, cmd, arg, dvbdev->kernel_ioctl);
170 ret = dvb_usercopy(file, cmd, arg, dvbdev->kernel_ioctl);
171 unlock_kernel();
172
173 return ret;
174} 170}
175EXPORT_SYMBOL(dvb_generic_ioctl); 171EXPORT_SYMBOL(dvb_generic_ioctl);
176 172
@@ -421,8 +417,10 @@ int dvb_usercopy(struct file *file,
421 } 417 }
422 418
423 /* call driver */ 419 /* call driver */
420 mutex_lock(&dvbdev_mutex);
424 if ((err = func(file, cmd, parg)) == -ENOIOCTLCMD) 421 if ((err = func(file, cmd, parg)) == -ENOIOCTLCMD)
425 err = -EINVAL; 422 err = -EINVAL;
423 mutex_unlock(&dvbdev_mutex);
426 424
427 if (err < 0) 425 if (err < 0)
428 goto out; 426 goto out;
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index fdc19bba2128..e85304c59a2b 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -1,6 +1,6 @@
1config DVB_USB 1config DVB_USB
2 tristate "Support for various USB DVB devices" 2 tristate "Support for various USB DVB devices"
3 depends on DVB_CORE && USB && I2C && IR_CORE 3 depends on DVB_CORE && USB && I2C && RC_CORE
4 help 4 help
5 By enabling this you will be able to choose the various supported 5 By enabling this you will be able to choose the various supported
6 USB1.1 and USB2.0 DVB devices. 6 USB1.1 and USB2.0 DVB devices.
@@ -292,6 +292,11 @@ config DVB_USB_ANYSEE
292 select DVB_MT352 if !DVB_FE_CUSTOMISE 292 select DVB_MT352 if !DVB_FE_CUSTOMISE
293 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 293 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
294 select DVB_TDA10023 if !DVB_FE_CUSTOMISE 294 select DVB_TDA10023 if !DVB_FE_CUSTOMISE
295 select MEDIA_TUNER_TDA18212 if !MEDIA_TUNER_CUSTOMISE
296 select DVB_CX24116 if !DVB_FE_CUSTOMISE
297 select DVB_STV0900 if !DVB_FE_CUSTOMISE
298 select DVB_STV6110 if !DVB_FE_CUSTOMISE
299 select DVB_ISL6423 if !DVB_FE_CUSTOMISE
295 help 300 help
296 Say Y here to support the Anysee E30, Anysee E30 Plus or 301 Say Y here to support the Anysee E30, Anysee E30 Plus or
297 Anysee E30 C Plus DVB USB2.0 receiver. 302 Anysee E30 C Plus DVB USB2.0 receiver.
@@ -314,6 +319,8 @@ config DVB_USB_AF9015
314 select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE 319 select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE
315 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE 320 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE
316 select MEDIA_TUNER_MC44S803 if !MEDIA_TUNER_CUSTOMISE 321 select MEDIA_TUNER_MC44S803 if !MEDIA_TUNER_CUSTOMISE
322 select MEDIA_TUNER_TDA18218 if !MEDIA_TUNER_CUSTOMISE
323 select MEDIA_TUNER_MXL5007T if !MEDIA_TUNER_CUSTOMISE
317 help 324 help
318 Say Y here to support the Afatech AF9015 based DVB-T USB2.0 receiver 325 Say Y here to support the Afatech AF9015 based DVB-T USB2.0 receiver
319 326
@@ -346,3 +353,23 @@ config DVB_USB_AZ6027
346 select DVB_STB6100 if !DVB_FE_CUSTOMISE 353 select DVB_STB6100 if !DVB_FE_CUSTOMISE
347 help 354 help
348 Say Y here to support the AZ6027 device 355 Say Y here to support the AZ6027 device
356
357config DVB_USB_LME2510
358 tristate "LME DM04/QQBOX DVB-S USB2.0 support"
359 depends on DVB_USB
360 select DVB_TDA10086 if !DVB_FE_CUSTOMISE
361 select DVB_TDA826X if !DVB_FE_CUSTOMISE
362 select DVB_STV0288 if !DVB_FE_CUSTOMISE
363 select DVB_IX2505V if !DVB_FE_CUSTOMISE
364 select DVB_STV0299 if !DVB_FE_CUSTOMISE
365 select DVB_PLL if !DVB_FE_CUSTOMISE
366 help
367 Say Y here to support the LME DM04/QQBOX DVB-S USB2.0 .
368
369config DVB_USB_TECHNISAT_USB2
370 tristate "Technisat DVB-S/S2 USB2.0 support"
371 depends on DVB_USB
372 select DVB_STV090x if !DVB_FE_CUSTOMISE
373 select DVB_STV6110x if !DVB_FE_CUSTOMISE
374 help
375 Say Y here to support the Technisat USB2 DVB-S/S2 device
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index 1a192453b0e7..4bac13da0c39 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -88,6 +88,12 @@ obj-$(CONFIG_DVB_USB_EC168) += dvb-usb-ec168.o
88dvb-usb-az6027-objs = az6027.o 88dvb-usb-az6027-objs = az6027.o
89obj-$(CONFIG_DVB_USB_AZ6027) += dvb-usb-az6027.o 89obj-$(CONFIG_DVB_USB_AZ6027) += dvb-usb-az6027.o
90 90
91dvb-usb-lmedm04-objs = lmedm04.o
92obj-$(CONFIG_DVB_USB_LME2510) += dvb-usb-lmedm04.o
93
94dvb-usb-technisat-usb2-objs = technisat-usb2.o
95obj-$(CONFIG_DVB_USB_TECHNISAT_USB2) += dvb-usb-technisat-usb2.o
96
91EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 97EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
92# due to tuner-xc3028 98# due to tuner-xc3028
93EXTRA_CFLAGS += -Idrivers/media/common/tuners 99EXTRA_CFLAGS += -Idrivers/media/common/tuners
diff --git a/drivers/media/dvb/dvb-usb/a800.c b/drivers/media/dvb/dvb-usb/a800.c
index a5c363727133..b95a95e17840 100644
--- a/drivers/media/dvb/dvb-usb/a800.c
+++ b/drivers/media/dvb/dvb-usb/a800.c
@@ -37,9 +37,9 @@ static int a800_identify_state(struct usb_device *udev, struct dvb_usb_device_pr
37 return 0; 37 return 0;
38} 38}
39 39
40static struct ir_scancode ir_codes_a800_table[] = { 40static struct rc_map_table rc_map_a800_table[] = {
41 { 0x0201, KEY_PROG1 }, /* SOURCE */ 41 { 0x0201, KEY_MODE }, /* SOURCE */
42 { 0x0200, KEY_POWER }, /* POWER */ 42 { 0x0200, KEY_POWER2 }, /* POWER */
43 { 0x0205, KEY_1 }, /* 1 */ 43 { 0x0205, KEY_1 }, /* 1 */
44 { 0x0206, KEY_2 }, /* 2 */ 44 { 0x0206, KEY_2 }, /* 2 */
45 { 0x0207, KEY_3 }, /* 3 */ 45 { 0x0207, KEY_3 }, /* 3 */
@@ -52,8 +52,8 @@ static struct ir_scancode ir_codes_a800_table[] = {
52 { 0x0212, KEY_LEFT }, /* L / DISPLAY */ 52 { 0x0212, KEY_LEFT }, /* L / DISPLAY */
53 { 0x0211, KEY_0 }, /* 0 */ 53 { 0x0211, KEY_0 }, /* 0 */
54 { 0x0213, KEY_RIGHT }, /* R / CH RTN */ 54 { 0x0213, KEY_RIGHT }, /* R / CH RTN */
55 { 0x0217, KEY_PROG2 }, /* SNAP SHOT */ 55 { 0x0217, KEY_CAMERA }, /* SNAP SHOT */
56 { 0x0210, KEY_PROG3 }, /* 16-CH PREV */ 56 { 0x0210, KEY_LAST }, /* 16-CH PREV */
57 { 0x021e, KEY_VOLUMEDOWN }, /* VOL DOWN */ 57 { 0x021e, KEY_VOLUMEDOWN }, /* VOL DOWN */
58 { 0x020c, KEY_ZOOM }, /* FULL SCREEN */ 58 { 0x020c, KEY_ZOOM }, /* FULL SCREEN */
59 { 0x021f, KEY_VOLUMEUP }, /* VOL UP */ 59 { 0x021f, KEY_VOLUMEUP }, /* VOL UP */
@@ -78,17 +78,26 @@ static struct ir_scancode ir_codes_a800_table[] = {
78 78
79static int a800_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 79static int a800_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
80{ 80{
81 u8 key[5]; 81 int ret;
82 u8 *key = kmalloc(5, GFP_KERNEL);
83 if (!key)
84 return -ENOMEM;
85
82 if (usb_control_msg(d->udev,usb_rcvctrlpipe(d->udev,0), 86 if (usb_control_msg(d->udev,usb_rcvctrlpipe(d->udev,0),
83 0x04, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, key, 5, 87 0x04, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, key, 5,
84 2000) != 5) 88 2000) != 5) {
85 return -ENODEV; 89 ret = -ENODEV;
90 goto out;
91 }
86 92
87 /* call the universal NEC remote processor, to find out the key's state and event */ 93 /* call the universal NEC remote processor, to find out the key's state and event */
88 dvb_usb_nec_rc_key_to_event(d,key,event,state); 94 dvb_usb_nec_rc_key_to_event(d,key,event,state);
89 if (key[0] != 0) 95 if (key[0] != 0)
90 deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]); 96 deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]);
91 return 0; 97 ret = 0;
98out:
99 kfree(key);
100 return ret;
92} 101}
93 102
94/* USB Driver stuff */ 103/* USB Driver stuff */
@@ -148,8 +157,8 @@ static struct dvb_usb_device_properties a800_properties = {
148 157
149 .rc.legacy = { 158 .rc.legacy = {
150 .rc_interval = DEFAULT_RC_INTERVAL, 159 .rc_interval = DEFAULT_RC_INTERVAL,
151 .rc_key_map = ir_codes_a800_table, 160 .rc_map_table = rc_map_a800_table,
152 .rc_key_map_size = ARRAY_SIZE(ir_codes_a800_table), 161 .rc_map_size = ARRAY_SIZE(rc_map_a800_table),
153 .rc_query = a800_rc_query, 162 .rc_query = a800_rc_query,
154 }, 163 },
155 164
diff --git a/drivers/media/dvb/dvb-usb/af9005-fe.c b/drivers/media/dvb/dvb-usb/af9005-fe.c
index 199ece0d4883..6ad94745bbdd 100644
--- a/drivers/media/dvb/dvb-usb/af9005-fe.c
+++ b/drivers/media/dvb/dvb-usb/af9005-fe.c
@@ -580,7 +580,7 @@ static int af9005_fe_program_cfoe(struct dvb_usb_device *d, fe_bandwidth_t bw)
580 NS_coeff2_8k = 0x724925; 580 NS_coeff2_8k = 0x724925;
581 break; 581 break;
582 default: 582 default:
583 err("Invalid bandwith %d.", bw); 583 err("Invalid bandwidth %d.", bw);
584 return -EINVAL; 584 return -EINVAL;
585 } 585 }
586 586
@@ -789,7 +789,7 @@ static int af9005_fe_select_bw(struct dvb_usb_device *d, fe_bandwidth_t bw)
789 temp = 2; 789 temp = 2;
790 break; 790 break;
791 default: 791 default:
792 err("Invalid bandwith %d.", bw); 792 err("Invalid bandwidth %d.", bw);
793 return -EINVAL; 793 return -EINVAL;
794 } 794 }
795 return af9005_write_register_bits(d, xd_g_reg_bw, reg_bw_pos, 795 return af9005_write_register_bits(d, xd_g_reg_bw, reg_bw_pos,
@@ -930,7 +930,7 @@ static int af9005_fe_init(struct dvb_frontend *fe)
930 if (ret) 930 if (ret)
931 return ret; 931 return ret;
932 932
933 /* init other parameters: program cfoe and select bandwith */ 933 /* init other parameters: program cfoe and select bandwidth */
934 deb_info("program cfoe\n"); 934 deb_info("program cfoe\n");
935 if ((ret = af9005_fe_program_cfoe(state->d, BANDWIDTH_6_MHZ))) 935 if ((ret = af9005_fe_program_cfoe(state->d, BANDWIDTH_6_MHZ)))
936 return ret; 936 return ret;
@@ -1167,7 +1167,7 @@ static int af9005_fe_set_frontend(struct dvb_frontend *fe,
1167 if (ret) 1167 if (ret)
1168 return ret; 1168 return ret;
1169 1169
1170 /* select bandwith */ 1170 /* select bandwidth */
1171 deb_info("select bandwidth"); 1171 deb_info("select bandwidth");
1172 ret = af9005_fe_select_bw(state->d, fep->u.ofdm.bandwidth); 1172 ret = af9005_fe_select_bw(state->d, fep->u.ofdm.bandwidth);
1173 if (ret) 1173 if (ret)
diff --git a/drivers/media/dvb/dvb-usb/af9005-remote.c b/drivers/media/dvb/dvb-usb/af9005-remote.c
index 696207fe37ec..c3bc64ed405c 100644
--- a/drivers/media/dvb/dvb-usb/af9005-remote.c
+++ b/drivers/media/dvb/dvb-usb/af9005-remote.c
@@ -33,7 +33,7 @@ MODULE_PARM_DESC(debug,
33 33
34#define deb_decode(args...) dprintk(dvb_usb_af9005_remote_debug,0x01,args) 34#define deb_decode(args...) dprintk(dvb_usb_af9005_remote_debug,0x01,args)
35 35
36struct ir_scancode ir_codes_af9005_table[] = { 36struct rc_map_table rc_map_af9005_table[] = {
37 37
38 {0x01b7, KEY_POWER}, 38 {0x01b7, KEY_POWER},
39 {0x01a7, KEY_VOLUMEUP}, 39 {0x01a7, KEY_VOLUMEUP},
@@ -74,7 +74,7 @@ struct ir_scancode ir_codes_af9005_table[] = {
74 {0x00d5, KEY_GOTO}, /* marked jump on the remote */ 74 {0x00d5, KEY_GOTO}, /* marked jump on the remote */
75}; 75};
76 76
77int ir_codes_af9005_table_size = ARRAY_SIZE(ir_codes_af9005_table); 77int rc_map_af9005_table_size = ARRAY_SIZE(rc_map_af9005_table);
78 78
79static int repeatable_keys[] = { 79static int repeatable_keys[] = {
80 KEY_VOLUMEUP, 80 KEY_VOLUMEUP,
@@ -130,10 +130,10 @@ int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, u32 * event,
130 deb_decode("code != inverted code\n"); 130 deb_decode("code != inverted code\n");
131 return 0; 131 return 0;
132 } 132 }
133 for (i = 0; i < ir_codes_af9005_table_size; i++) { 133 for (i = 0; i < rc_map_af9005_table_size; i++) {
134 if (rc5_custom(&ir_codes_af9005_table[i]) == cust 134 if (rc5_custom(&rc_map_af9005_table[i]) == cust
135 && rc5_data(&ir_codes_af9005_table[i]) == dat) { 135 && rc5_data(&rc_map_af9005_table[i]) == dat) {
136 *event = ir_codes_af9005_table[i].keycode; 136 *event = rc_map_af9005_table[i].keycode;
137 *state = REMOTE_KEY_PRESSED; 137 *state = REMOTE_KEY_PRESSED;
138 deb_decode 138 deb_decode
139 ("key pressed, event %x\n", *event); 139 ("key pressed, event %x\n", *event);
@@ -146,8 +146,8 @@ int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, u32 * event,
146 return 0; 146 return 0;
147} 147}
148 148
149EXPORT_SYMBOL(ir_codes_af9005_table); 149EXPORT_SYMBOL(rc_map_af9005_table);
150EXPORT_SYMBOL(ir_codes_af9005_table_size); 150EXPORT_SYMBOL(rc_map_af9005_table_size);
151EXPORT_SYMBOL(af9005_rc_decode); 151EXPORT_SYMBOL(af9005_rc_decode);
152 152
153MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>"); 153MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
diff --git a/drivers/media/dvb/dvb-usb/af9005.c b/drivers/media/dvb/dvb-usb/af9005.c
index 8ecba8848bcf..51f6439dcfd5 100644
--- a/drivers/media/dvb/dvb-usb/af9005.c
+++ b/drivers/media/dvb/dvb-usb/af9005.c
@@ -1027,8 +1027,8 @@ static struct dvb_usb_device_properties af9005_properties = {
1027 1027
1028 .rc.legacy = { 1028 .rc.legacy = {
1029 .rc_interval = 200, 1029 .rc_interval = 200,
1030 .rc_key_map = NULL, 1030 .rc_map_table = NULL,
1031 .rc_key_map_size = 0, 1031 .rc_map_size = 0,
1032 .rc_query = af9005_rc_query, 1032 .rc_query = af9005_rc_query,
1033 }, 1033 },
1034 1034
@@ -1070,14 +1070,14 @@ static int __init af9005_usb_module_init(void)
1070 return result; 1070 return result;
1071 } 1071 }
1072 rc_decode = symbol_request(af9005_rc_decode); 1072 rc_decode = symbol_request(af9005_rc_decode);
1073 rc_keys = symbol_request(ir_codes_af9005_table); 1073 rc_keys = symbol_request(rc_map_af9005_table);
1074 rc_keys_size = symbol_request(ir_codes_af9005_table_size); 1074 rc_keys_size = symbol_request(rc_map_af9005_table_size);
1075 if (rc_decode == NULL || rc_keys == NULL || rc_keys_size == NULL) { 1075 if (rc_decode == NULL || rc_keys == NULL || rc_keys_size == NULL) {
1076 err("af9005_rc_decode function not found, disabling remote"); 1076 err("af9005_rc_decode function not found, disabling remote");
1077 af9005_properties.rc.legacy.rc_query = NULL; 1077 af9005_properties.rc.legacy.rc_query = NULL;
1078 } else { 1078 } else {
1079 af9005_properties.rc.legacy.rc_key_map = rc_keys; 1079 af9005_properties.rc.legacy.rc_map_table = rc_keys;
1080 af9005_properties.rc.legacy.rc_key_map_size = *rc_keys_size; 1080 af9005_properties.rc.legacy.rc_map_size = *rc_keys_size;
1081 } 1081 }
1082 1082
1083 return 0; 1083 return 0;
@@ -1089,9 +1089,9 @@ static void __exit af9005_usb_module_exit(void)
1089 if (rc_decode != NULL) 1089 if (rc_decode != NULL)
1090 symbol_put(af9005_rc_decode); 1090 symbol_put(af9005_rc_decode);
1091 if (rc_keys != NULL) 1091 if (rc_keys != NULL)
1092 symbol_put(ir_codes_af9005_table); 1092 symbol_put(rc_map_af9005_table);
1093 if (rc_keys_size != NULL) 1093 if (rc_keys_size != NULL)
1094 symbol_put(ir_codes_af9005_table_size); 1094 symbol_put(rc_map_af9005_table_size);
1095 /* deregister this driver from the USB subsystem */ 1095 /* deregister this driver from the USB subsystem */
1096 usb_deregister(&af9005_usb_driver); 1096 usb_deregister(&af9005_usb_driver);
1097} 1097}
diff --git a/drivers/media/dvb/dvb-usb/af9005.h b/drivers/media/dvb/dvb-usb/af9005.h
index 3c1fbd1c5d60..c71c77bd7f4b 100644
--- a/drivers/media/dvb/dvb-usb/af9005.h
+++ b/drivers/media/dvb/dvb-usb/af9005.h
@@ -3490,7 +3490,7 @@ extern u8 regmask[8];
3490/* remote control decoder */ 3490/* remote control decoder */
3491extern int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, 3491extern int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len,
3492 u32 * event, int *state); 3492 u32 * event, int *state);
3493extern struct ir_scancode ir_codes_af9005_table[]; 3493extern struct rc_map_table rc_map_af9005_table[];
3494extern int ir_codes_af9005_table_size; 3494extern int rc_map_af9005_table_size;
3495 3495
3496#endif 3496#endif
diff --git a/drivers/media/dvb/dvb-usb/af9015.c b/drivers/media/dvb/dvb-usb/af9015.c
index ea1ed3b4592a..100ebc37e99e 100644
--- a/drivers/media/dvb/dvb-usb/af9015.c
+++ b/drivers/media/dvb/dvb-usb/af9015.c
@@ -31,6 +31,8 @@
31#include "tda18271.h" 31#include "tda18271.h"
32#include "mxl5005s.h" 32#include "mxl5005s.h"
33#include "mc44s803.h" 33#include "mc44s803.h"
34#include "tda18218.h"
35#include "mxl5007t.h"
34 36
35static int dvb_usb_af9015_debug; 37static int dvb_usb_af9015_debug;
36module_param_named(debug, dvb_usb_af9015_debug, int, 0644); 38module_param_named(debug, dvb_usb_af9015_debug, int, 0644);
@@ -205,12 +207,18 @@ static int af9015_write_reg(struct dvb_usb_device *d, u16 addr, u8 val)
205 return af9015_write_regs(d, addr, &val, 1); 207 return af9015_write_regs(d, addr, &val, 1);
206} 208}
207 209
208static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val) 210static int af9015_read_regs(struct dvb_usb_device *d, u16 addr, u8 *val, u8 len)
209{ 211{
210 struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, 1, val}; 212 struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,
213 val};
211 return af9015_ctrl_msg(d, &req); 214 return af9015_ctrl_msg(d, &req);
212} 215}
213 216
217static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val)
218{
219 return af9015_read_regs(d, addr, val, 1);
220}
221
214static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg, 222static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
215 u8 val) 223 u8 val)
216{ 224{
@@ -241,7 +249,7 @@ static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
241 struct dvb_usb_device *d = i2c_get_adapdata(adap); 249 struct dvb_usb_device *d = i2c_get_adapdata(adap);
242 int ret = 0, i = 0; 250 int ret = 0, i = 0;
243 u16 addr; 251 u16 addr;
244 u8 mbox, addr_len; 252 u8 uninitialized_var(mbox), addr_len;
245 struct req_t req; 253 struct req_t req;
246 254
247/* TODO: implement bus lock 255/* TODO: implement bus lock
@@ -280,7 +288,7 @@ Due to that the only way to select correct tuner is use demodulator I2C-gate.
280 } else { 288 } else {
281 addr = msg[i].buf[0]; 289 addr = msg[i].buf[0];
282 addr_len = 1; 290 addr_len = 1;
283 mbox = 0; 291 /* mbox is don't care in that case */
284 } 292 }
285 293
286 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) { 294 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
@@ -471,6 +479,7 @@ static int af9015_init_endpoint(struct dvb_usb_device *d)
471 ret = af9015_set_reg_bit(d, 0xd50b, 0); 479 ret = af9015_set_reg_bit(d, 0xd50b, 0);
472 else 480 else
473 ret = af9015_clear_reg_bit(d, 0xd50b, 0); 481 ret = af9015_clear_reg_bit(d, 0xd50b, 0);
482
474error: 483error:
475 if (ret) 484 if (ret)
476 err("endpoint init failed:%d", ret); 485 err("endpoint init failed:%d", ret);
@@ -494,7 +503,8 @@ static int af9015_copy_firmware(struct dvb_usb_device *d)
494 /* wait 2nd demodulator ready */ 503 /* wait 2nd demodulator ready */
495 msleep(100); 504 msleep(100);
496 505
497 ret = af9015_read_reg_i2c(d, 0x3a, 0x98be, &val); 506 ret = af9015_read_reg_i2c(d,
507 af9015_af9013_config[1].demod_address, 0x98be, &val);
498 if (ret) 508 if (ret)
499 goto error; 509 goto error;
500 else 510 else
@@ -597,47 +607,17 @@ free:
597 return ret; 607 return ret;
598} 608}
599 609
600static int af9015_download_ir_table(struct dvb_usb_device *d)
601{
602 int i, packets = 0, ret;
603 u16 addr = 0x9a56; /* ir-table start address */
604 struct req_t req = {WRITE_MEMORY, 0, 0, 0, 0, 1, NULL};
605 u8 *data = NULL;
606 deb_info("%s:\n", __func__);
607
608 data = af9015_config.ir_table;
609 packets = af9015_config.ir_table_size;
610
611 /* no remote */
612 if (!packets)
613 goto exit;
614
615 /* load remote ir-table */
616 for (i = 0; i < packets; i++) {
617 req.addr = addr + i;
618 req.data = &data[i];
619 ret = af9015_ctrl_msg(d, &req);
620 if (ret) {
621 err("ir-table download failed at packet %d with " \
622 "code %d", i, ret);
623 return ret;
624 }
625 }
626
627exit:
628 return 0;
629}
630
631static int af9015_init(struct dvb_usb_device *d) 610static int af9015_init(struct dvb_usb_device *d)
632{ 611{
633 int ret; 612 int ret;
634 deb_info("%s:\n", __func__); 613 deb_info("%s:\n", __func__);
635 614
636 ret = af9015_init_endpoint(d); 615 /* init RC canary */
616 ret = af9015_write_reg(d, 0x98e9, 0xff);
637 if (ret) 617 if (ret)
638 goto error; 618 goto error;
639 619
640 ret = af9015_download_ir_table(d); 620 ret = af9015_init_endpoint(d);
641 if (ret) 621 if (ret)
642 goto error; 622 goto error;
643 623
@@ -685,9 +665,8 @@ error:
685static int af9015_download_firmware(struct usb_device *udev, 665static int af9015_download_firmware(struct usb_device *udev,
686 const struct firmware *fw) 666 const struct firmware *fw)
687{ 667{
688 int i, len, packets, remainder, ret; 668 int i, len, remaining, ret;
689 struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL}; 669 struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL};
690 u16 addr = 0x5100; /* firmware start address */
691 u16 checksum = 0; 670 u16 checksum = 0;
692 671
693 deb_info("%s:\n", __func__); 672 deb_info("%s:\n", __func__);
@@ -699,24 +678,20 @@ static int af9015_download_firmware(struct usb_device *udev,
699 af9015_config.firmware_size = fw->size; 678 af9015_config.firmware_size = fw->size;
700 af9015_config.firmware_checksum = checksum; 679 af9015_config.firmware_checksum = checksum;
701 680
702 #define FW_PACKET_MAX_DATA 55 681 #define FW_ADDR 0x5100 /* firmware start address */
703 682 #define LEN_MAX 55 /* max packet size */
704 packets = fw->size / FW_PACKET_MAX_DATA; 683 for (remaining = fw->size; remaining > 0; remaining -= LEN_MAX) {
705 remainder = fw->size % FW_PACKET_MAX_DATA; 684 len = remaining;
706 len = FW_PACKET_MAX_DATA; 685 if (len > LEN_MAX)
707 for (i = 0; i <= packets; i++) { 686 len = LEN_MAX;
708 if (i == packets) /* set size of the last packet */
709 len = remainder;
710 687
711 req.data_len = len; 688 req.data_len = len;
712 req.data = (u8 *)(fw->data + i * FW_PACKET_MAX_DATA); 689 req.data = (u8 *) &fw->data[fw->size - remaining];
713 req.addr = addr; 690 req.addr = FW_ADDR + fw->size - remaining;
714 addr += FW_PACKET_MAX_DATA;
715 691
716 ret = af9015_rw_udev(udev, &req); 692 ret = af9015_rw_udev(udev, &req);
717 if (ret) { 693 if (ret) {
718 err("firmware download failed at packet %d with " \ 694 err("firmware download failed:%d", ret);
719 "code %d", i, ret);
720 goto error; 695 goto error;
721 } 696 }
722 } 697 }
@@ -733,125 +708,104 @@ error:
733 return ret; 708 return ret;
734} 709}
735 710
736struct af9015_setup { 711struct af9015_rc_setup {
737 unsigned int id; 712 unsigned int id;
738 struct ir_scancode *rc_key_map; 713 char *rc_codes;
739 unsigned int rc_key_map_size;
740 u8 *ir_table;
741 unsigned int ir_table_size;
742}; 714};
743 715
744static const struct af9015_setup *af9015_setup_match(unsigned int id, 716static char *af9015_rc_setup_match(unsigned int id,
745 const struct af9015_setup *table) 717 const struct af9015_rc_setup *table)
746{ 718{
747 for (; table->rc_key_map; table++) 719 for (; table->rc_codes; table++)
748 if (table->id == id) 720 if (table->id == id)
749 return table; 721 return table->rc_codes;
750 return NULL; 722 return NULL;
751} 723}
752 724
753static const struct af9015_setup af9015_setup_modparam[] = { 725static const struct af9015_rc_setup af9015_rc_setup_modparam[] = {
754 { AF9015_REMOTE_A_LINK_DTU_M, 726 { AF9015_REMOTE_A_LINK_DTU_M, RC_MAP_ALINK_DTU_M },
755 ir_codes_af9015_table_a_link, ARRAY_SIZE(ir_codes_af9015_table_a_link), 727 { AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, RC_MAP_MSI_DIGIVOX_II },
756 af9015_ir_table_a_link, ARRAY_SIZE(af9015_ir_table_a_link) }, 728 { AF9015_REMOTE_MYGICTV_U718, RC_MAP_TOTAL_MEDIA_IN_HAND },
757 { AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, 729 { AF9015_REMOTE_DIGITTRADE_DVB_T, RC_MAP_DIGITTRADE },
758 ir_codes_af9015_table_msi, ARRAY_SIZE(ir_codes_af9015_table_msi), 730 { AF9015_REMOTE_AVERMEDIA_KS, RC_MAP_AVERMEDIA_RM_KS },
759 af9015_ir_table_msi, ARRAY_SIZE(af9015_ir_table_msi) },
760 { AF9015_REMOTE_MYGICTV_U718,
761 ir_codes_af9015_table_mygictv, ARRAY_SIZE(ir_codes_af9015_table_mygictv),
762 af9015_ir_table_mygictv, ARRAY_SIZE(af9015_ir_table_mygictv) },
763 { AF9015_REMOTE_DIGITTRADE_DVB_T,
764 ir_codes_af9015_table_digittrade, ARRAY_SIZE(ir_codes_af9015_table_digittrade),
765 af9015_ir_table_digittrade, ARRAY_SIZE(af9015_ir_table_digittrade) },
766 { AF9015_REMOTE_AVERMEDIA_KS,
767 ir_codes_af9015_table_avermedia, ARRAY_SIZE(ir_codes_af9015_table_avermedia),
768 af9015_ir_table_avermedia_ks, ARRAY_SIZE(af9015_ir_table_avermedia_ks) },
769 { } 731 { }
770}; 732};
771 733
772/* don't add new entries here anymore, use hashes instead */ 734static const struct af9015_rc_setup af9015_rc_setup_hashes[] = {
773static const struct af9015_setup af9015_setup_usbids[] = { 735 { 0xb8feb708, RC_MAP_MSI_DIGIVOX_II },
774 { USB_VID_LEADTEK, 736 { 0xa3703d00, RC_MAP_ALINK_DTU_M },
775 ir_codes_af9015_table_leadtek, ARRAY_SIZE(ir_codes_af9015_table_leadtek), 737 { 0x9b7dc64e, RC_MAP_TOTAL_MEDIA_IN_HAND }, /* MYGICTV U718 */
776 af9015_ir_table_leadtek, ARRAY_SIZE(af9015_ir_table_leadtek) },
777 { USB_VID_VISIONPLUS,
778 ir_codes_af9015_table_twinhan, ARRAY_SIZE(ir_codes_af9015_table_twinhan),
779 af9015_ir_table_twinhan, ARRAY_SIZE(af9015_ir_table_twinhan) },
780 { USB_VID_KWORLD_2, /* TODO: use correct rc keys */
781 ir_codes_af9015_table_twinhan, ARRAY_SIZE(ir_codes_af9015_table_twinhan),
782 af9015_ir_table_kworld, ARRAY_SIZE(af9015_ir_table_kworld) },
783 { USB_VID_AVERMEDIA,
784 ir_codes_af9015_table_avermedia, ARRAY_SIZE(ir_codes_af9015_table_avermedia),
785 af9015_ir_table_avermedia, ARRAY_SIZE(af9015_ir_table_avermedia) },
786 { USB_VID_MSI_2,
787 ir_codes_af9015_table_msi_digivox_iii, ARRAY_SIZE(ir_codes_af9015_table_msi_digivox_iii),
788 af9015_ir_table_msi_digivox_iii, ARRAY_SIZE(af9015_ir_table_msi_digivox_iii) },
789 { } 738 { }
790}; 739};
791 740
792static const struct af9015_setup af9015_setup_hashes[] = { 741static const struct af9015_rc_setup af9015_rc_setup_usbids[] = {
793 { 0xb8feb708, 742 { (USB_VID_TERRATEC << 16) + USB_PID_TERRATEC_CINERGY_T_STICK_RC,
794 ir_codes_af9015_table_msi, ARRAY_SIZE(ir_codes_af9015_table_msi), 743 RC_MAP_TERRATEC_SLIM_2 },
795 af9015_ir_table_msi, ARRAY_SIZE(af9015_ir_table_msi) }, 744 { (USB_VID_TERRATEC << 16) + USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC,
796 { 0xa3703d00, 745 RC_MAP_TERRATEC_SLIM },
797 ir_codes_af9015_table_a_link, ARRAY_SIZE(ir_codes_af9015_table_a_link), 746 { (USB_VID_VISIONPLUS << 16) + USB_PID_AZUREWAVE_AD_TU700,
798 af9015_ir_table_a_link, ARRAY_SIZE(af9015_ir_table_a_link) }, 747 RC_MAP_AZUREWAVE_AD_TU700 },
799 { 0x9b7dc64e, 748 { (USB_VID_VISIONPLUS << 16) + USB_PID_TINYTWIN,
800 ir_codes_af9015_table_mygictv, ARRAY_SIZE(ir_codes_af9015_table_mygictv), 749 RC_MAP_AZUREWAVE_AD_TU700 },
801 af9015_ir_table_mygictv, ARRAY_SIZE(af9015_ir_table_mygictv) }, 750 { (USB_VID_MSI_2 << 16) + USB_PID_MSI_DIGI_VOX_MINI_III,
751 RC_MAP_MSI_DIGIVOX_III },
752 { (USB_VID_LEADTEK << 16) + USB_PID_WINFAST_DTV_DONGLE_GOLD,
753 RC_MAP_LEADTEK_Y04G0051 },
754 { (USB_VID_AVERMEDIA << 16) + USB_PID_AVERMEDIA_VOLAR_X,
755 RC_MAP_AVERMEDIA_M135A },
756 { (USB_VID_AFATECH << 16) + USB_PID_TREKSTOR_DVBT,
757 RC_MAP_TREKSTOR },
758 { (USB_VID_KWORLD_2 << 16) + USB_PID_TINYTWIN_2,
759 RC_MAP_DIGITALNOW_TINYTWIN },
760 { (USB_VID_GTEK << 16) + USB_PID_TINYTWIN_3,
761 RC_MAP_DIGITALNOW_TINYTWIN },
802 { } 762 { }
803}; 763};
804 764
805static void af9015_set_remote_config(struct usb_device *udev, 765static void af9015_set_remote_config(struct usb_device *udev,
806 struct dvb_usb_device_properties *props) 766 struct dvb_usb_device_properties *props)
807{ 767{
808 const struct af9015_setup *table = NULL; 768 u16 vid = le16_to_cpu(udev->descriptor.idVendor);
809 769 u16 pid = le16_to_cpu(udev->descriptor.idProduct);
810 if (dvb_usb_af9015_remote) { 770
811 /* load remote defined as module param */ 771 /* try to load remote based module param */
812 table = af9015_setup_match(dvb_usb_af9015_remote, 772 props->rc.core.rc_codes = af9015_rc_setup_match(
813 af9015_setup_modparam); 773 dvb_usb_af9015_remote, af9015_rc_setup_modparam);
814 } else { 774
815 u16 vendor = le16_to_cpu(udev->descriptor.idVendor); 775 /* try to load remote based eeprom hash */
816 776 if (!props->rc.core.rc_codes)
817 table = af9015_setup_match(af9015_config.eeprom_sum, 777 props->rc.core.rc_codes = af9015_rc_setup_match(
818 af9015_setup_hashes); 778 af9015_config.eeprom_sum, af9015_rc_setup_hashes);
819 779
820 if (!table && vendor == USB_VID_AFATECH) { 780 /* try to load remote based USB ID */
821 /* Check USB manufacturer and product strings and try 781 if (!props->rc.core.rc_codes)
822 to determine correct remote in case of chip vendor 782 props->rc.core.rc_codes = af9015_rc_setup_match(
823 reference IDs are used. 783 (vid << 16) + pid, af9015_rc_setup_usbids);
824 DO NOT ADD ANYTHING NEW HERE. Use hashes instead. 784
825 */ 785 /* try to load remote based USB iManufacturer string */
826 char manufacturer[10]; 786 if (!props->rc.core.rc_codes && vid == USB_VID_AFATECH) {
827 memset(manufacturer, 0, sizeof(manufacturer)); 787 /* Check USB manufacturer and product strings and try
828 usb_string(udev, udev->descriptor.iManufacturer, 788 to determine correct remote in case of chip vendor
829 manufacturer, sizeof(manufacturer)); 789 reference IDs are used.
830 if (!strcmp("MSI", manufacturer)) { 790 DO NOT ADD ANYTHING NEW HERE. Use hashes instead. */
831 /* iManufacturer 1 MSI 791 char manufacturer[10];
832 iProduct 2 MSI K-VOX */ 792 memset(manufacturer, 0, sizeof(manufacturer));
833 table = af9015_setup_match( 793 usb_string(udev, udev->descriptor.iManufacturer,
834 AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, 794 manufacturer, sizeof(manufacturer));
835 af9015_setup_modparam); 795 if (!strcmp("MSI", manufacturer)) {
836 } else if (udev->descriptor.idProduct == 796 /* iManufacturer 1 MSI
837 cpu_to_le16(USB_PID_TREKSTOR_DVBT)) { 797 iProduct 2 MSI K-VOX */
838 table = &(const struct af9015_setup){ 0, 798 props->rc.core.rc_codes = af9015_rc_setup_match(
839 ir_codes_af9015_table_trekstor, 799 AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
840 ARRAY_SIZE(ir_codes_af9015_table_trekstor), 800 af9015_rc_setup_modparam);
841 af9015_ir_table_trekstor, 801 }
842 ARRAY_SIZE(af9015_ir_table_trekstor)
843 };
844 }
845 } else if (!table)
846 table = af9015_setup_match(vendor, af9015_setup_usbids);
847 } 802 }
848 803
849 if (table) { 804 /* finally load "empty" just for leaving IR receiver enabled */
850 props->rc.legacy.rc_key_map = table->rc_key_map; 805 if (!props->rc.core.rc_codes)
851 props->rc.legacy.rc_key_map_size = table->rc_key_map_size; 806 props->rc.core.rc_codes = RC_MAP_EMPTY;
852 af9015_config.ir_table = table->ir_table; 807
853 af9015_config.ir_table_size = table->ir_table_size; 808 return;
854 }
855} 809}
856 810
857static int af9015_read_config(struct usb_device *udev) 811static int af9015_read_config(struct usb_device *udev)
@@ -877,10 +831,9 @@ static int af9015_read_config(struct usb_device *udev)
877 831
878 deb_info("%s: IR mode:%d\n", __func__, val); 832 deb_info("%s: IR mode:%d\n", __func__, val);
879 for (i = 0; i < af9015_properties_count; i++) { 833 for (i = 0; i < af9015_properties_count; i++) {
880 if (val == AF9015_IR_MODE_DISABLED) { 834 if (val == AF9015_IR_MODE_DISABLED)
881 af9015_properties[i].rc.legacy.rc_key_map = NULL; 835 af9015_properties[i].rc.core.rc_codes = NULL;
882 af9015_properties[i].rc.legacy.rc_key_map_size = 0; 836 else
883 } else
884 af9015_set_remote_config(udev, &af9015_properties[i]); 837 af9015_set_remote_config(udev, &af9015_properties[i]);
885 } 838 }
886 839
@@ -992,20 +945,19 @@ static int af9015_read_config(struct usb_device *udev)
992 case AF9013_TUNER_MT2060_2: 945 case AF9013_TUNER_MT2060_2:
993 case AF9013_TUNER_TDA18271: 946 case AF9013_TUNER_TDA18271:
994 case AF9013_TUNER_QT1010A: 947 case AF9013_TUNER_QT1010A:
948 case AF9013_TUNER_TDA18218:
995 af9015_af9013_config[i].rf_spec_inv = 1; 949 af9015_af9013_config[i].rf_spec_inv = 1;
996 break; 950 break;
997 case AF9013_TUNER_MXL5003D: 951 case AF9013_TUNER_MXL5003D:
998 case AF9013_TUNER_MXL5005D: 952 case AF9013_TUNER_MXL5005D:
999 case AF9013_TUNER_MXL5005R: 953 case AF9013_TUNER_MXL5005R:
954 case AF9013_TUNER_MXL5007T:
1000 af9015_af9013_config[i].rf_spec_inv = 0; 955 af9015_af9013_config[i].rf_spec_inv = 0;
1001 break; 956 break;
1002 case AF9013_TUNER_MC44S803: 957 case AF9013_TUNER_MC44S803:
1003 af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO; 958 af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO;
1004 af9015_af9013_config[i].rf_spec_inv = 1; 959 af9015_af9013_config[i].rf_spec_inv = 1;
1005 break; 960 break;
1006 case AF9013_TUNER_TDA18218:
1007 warn("tuner NXP TDA18218 not supported yet");
1008 return -ENODEV;
1009 default: 961 default:
1010 warn("tuner id:%d not supported, please report!", val); 962 warn("tuner id:%d not supported, please report!", val);
1011 return -ENODEV; 963 return -ENODEV;
@@ -1020,9 +972,13 @@ error:
1020 err("eeprom read failed:%d", ret); 972 err("eeprom read failed:%d", ret);
1021 973
1022 /* AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM 974 /* AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM
1023 content :-( Override some wrong values here. */ 975 content :-( Override some wrong values here. Ditto for the
976 AVerTV Red HD+ (A850T) device. */
1024 if (le16_to_cpu(udev->descriptor.idVendor) == USB_VID_AVERMEDIA && 977 if (le16_to_cpu(udev->descriptor.idVendor) == USB_VID_AVERMEDIA &&
1025 le16_to_cpu(udev->descriptor.idProduct) == USB_PID_AVERMEDIA_A850) { 978 ((le16_to_cpu(udev->descriptor.idProduct) ==
979 USB_PID_AVERMEDIA_A850) ||
980 (le16_to_cpu(udev->descriptor.idProduct) ==
981 USB_PID_AVERMEDIA_A850T))) {
1026 deb_info("%s: AverMedia A850: overriding config\n", __func__); 982 deb_info("%s: AverMedia A850: overriding config\n", __func__);
1027 /* disable dual mode */ 983 /* disable dual mode */
1028 af9015_config.dual_mode = 0; 984 af9015_config.dual_mode = 0;
@@ -1059,36 +1015,71 @@ static int af9015_identify_state(struct usb_device *udev,
1059 return ret; 1015 return ret;
1060} 1016}
1061 1017
1062static int af9015_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 1018static int af9015_rc_query(struct dvb_usb_device *d)
1063{ 1019{
1064 u8 buf[8]; 1020 struct af9015_state *priv = d->priv;
1065 struct req_t req = {GET_IR_CODE, 0, 0, 0, 0, sizeof(buf), buf}; 1021 int ret;
1066 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 1022 u8 buf[17];
1067 int i, ret;
1068
1069 memset(buf, 0, sizeof(buf));
1070 1023
1071 ret = af9015_ctrl_msg(d, &req); 1024 /* read registers needed to detect remote controller code */
1025 ret = af9015_read_regs(d, 0x98d9, buf, sizeof(buf));
1072 if (ret) 1026 if (ret)
1027 goto error;
1028
1029 /* If any of these are non-zero, assume invalid data */
1030 if (buf[1] || buf[2] || buf[3])
1073 return ret; 1031 return ret;
1074 1032
1075 *event = 0; 1033 /* Check for repeat of previous code */
1076 *state = REMOTE_NO_KEY_PRESSED; 1034 if ((priv->rc_repeat != buf[6] || buf[0]) &&
1035 !memcmp(&buf[12], priv->rc_last, 4)) {
1036 deb_rc("%s: key repeated\n", __func__);
1037 rc_keydown(d->rc_dev, priv->rc_keycode, 0);
1038 priv->rc_repeat = buf[6];
1039 return ret;
1040 }
1077 1041
1078 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { 1042 /* Only process key if canary killed */
1079 if (!buf[1] && rc5_custom(&keymap[i]) == buf[0] && 1043 if (buf[16] != 0xff && buf[0] != 0x01) {
1080 rc5_data(&keymap[i]) == buf[2]) { 1044 deb_rc("%s: key pressed %02x %02x %02x %02x\n", __func__,
1081 *event = keymap[i].keycode; 1045 buf[12], buf[13], buf[14], buf[15]);
1082 *state = REMOTE_KEY_PRESSED; 1046
1083 break; 1047 /* Reset the canary */
1048 ret = af9015_write_reg(d, 0x98e9, 0xff);
1049 if (ret)
1050 goto error;
1051
1052 /* Remember this key */
1053 memcpy(priv->rc_last, &buf[12], 4);
1054 if (buf[14] == (u8) ~buf[15]) {
1055 if (buf[12] == (u8) ~buf[13]) {
1056 /* NEC */
1057 priv->rc_keycode = buf[12] << 8 | buf[14];
1058 } else {
1059 /* NEC extended*/
1060 priv->rc_keycode = buf[12] << 16 |
1061 buf[13] << 8 | buf[14];
1062 }
1063 } else {
1064 /* 32 bit NEC */
1065 priv->rc_keycode = buf[12] << 24 | buf[13] << 16 |
1066 buf[14] << 8 | buf[15];
1084 } 1067 }
1068 rc_keydown(d->rc_dev, priv->rc_keycode, 0);
1069 } else {
1070 deb_rc("%s: no key press\n", __func__);
1071 /* Invalidate last keypress */
1072 /* Not really needed, but helps with debug */
1073 priv->rc_last[2] = priv->rc_last[3];
1085 } 1074 }
1086 if (!buf[1])
1087 deb_rc("%s: %02x %02x %02x %02x %02x %02x %02x %02x\n",
1088 __func__, buf[0], buf[1], buf[2], buf[3], buf[4],
1089 buf[5], buf[6], buf[7]);
1090 1075
1091 return 0; 1076 priv->rc_repeat = buf[6];
1077
1078error:
1079 if (ret)
1080 err("%s: failed:%d", __func__, ret);
1081
1082 return ret;
1092} 1083}
1093 1084
1094/* init 2nd I2C adapter */ 1085/* init 2nd I2C adapter */
@@ -1100,11 +1091,6 @@ static int af9015_i2c_init(struct dvb_usb_device *d)
1100 1091
1101 strncpy(state->i2c_adap.name, d->desc->name, 1092 strncpy(state->i2c_adap.name, d->desc->name,
1102 sizeof(state->i2c_adap.name)); 1093 sizeof(state->i2c_adap.name));
1103#ifdef I2C_ADAP_CLASS_TV_DIGITAL
1104 state->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL,
1105#else
1106 state->i2c_adap.class = I2C_CLASS_TV_DIGITAL,
1107#endif
1108 state->i2c_adap.algo = d->props.i2c_algo; 1094 state->i2c_adap.algo = d->props.i2c_algo;
1109 state->i2c_adap.algo_data = NULL; 1095 state->i2c_adap.algo_data = NULL;
1110 state->i2c_adap.dev.parent = &d->udev->dev; 1096 state->i2c_adap.dev.parent = &d->udev->dev;
@@ -1166,7 +1152,7 @@ static struct qt1010_config af9015_qt1010_config = {
1166 1152
1167static struct tda18271_config af9015_tda18271_config = { 1153static struct tda18271_config af9015_tda18271_config = {
1168 .gate = TDA18271_GATE_DIGITAL, 1154 .gate = TDA18271_GATE_DIGITAL,
1169 .small_i2c = 1, 1155 .small_i2c = TDA18271_16_BYTE_CHUNK_INIT,
1170}; 1156};
1171 1157
1172static struct mxl5005s_config af9015_mxl5003_config = { 1158static struct mxl5005s_config af9015_mxl5003_config = {
@@ -1208,12 +1194,22 @@ static struct mc44s803_config af9015_mc44s803_config = {
1208 .dig_out = 1, 1194 .dig_out = 1,
1209}; 1195};
1210 1196
1197static struct tda18218_config af9015_tda18218_config = {
1198 .i2c_address = 0xc0,
1199 .i2c_wr_max = 21, /* max wr bytes AF9015 I2C adap can handle at once */
1200};
1201
1202static struct mxl5007t_config af9015_mxl5007t_config = {
1203 .xtal_freq_hz = MxL_XTAL_24_MHZ,
1204 .if_freq_hz = MxL_IF_4_57_MHZ,
1205};
1206
1211static int af9015_tuner_attach(struct dvb_usb_adapter *adap) 1207static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
1212{ 1208{
1213 struct af9015_state *state = adap->dev->priv; 1209 struct af9015_state *state = adap->dev->priv;
1214 struct i2c_adapter *i2c_adap; 1210 struct i2c_adapter *i2c_adap;
1215 int ret; 1211 int ret;
1216 deb_info("%s: \n", __func__); 1212 deb_info("%s:\n", __func__);
1217 1213
1218 /* select I2C adapter */ 1214 /* select I2C adapter */
1219 if (adap->id == 0) 1215 if (adap->id == 0)
@@ -1238,6 +1234,10 @@ static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
1238 ret = dvb_attach(tda18271_attach, adap->fe, 0xc0, i2c_adap, 1234 ret = dvb_attach(tda18271_attach, adap->fe, 0xc0, i2c_adap,
1239 &af9015_tda18271_config) == NULL ? -ENODEV : 0; 1235 &af9015_tda18271_config) == NULL ? -ENODEV : 0;
1240 break; 1236 break;
1237 case AF9013_TUNER_TDA18218:
1238 ret = dvb_attach(tda18218_attach, adap->fe, i2c_adap,
1239 &af9015_tda18218_config) == NULL ? -ENODEV : 0;
1240 break;
1241 case AF9013_TUNER_MXL5003D: 1241 case AF9013_TUNER_MXL5003D:
1242 ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap, 1242 ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap,
1243 &af9015_mxl5003_config) == NULL ? -ENODEV : 0; 1243 &af9015_mxl5003_config) == NULL ? -ENODEV : 0;
@@ -1255,6 +1255,10 @@ static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
1255 ret = dvb_attach(mc44s803_attach, adap->fe, i2c_adap, 1255 ret = dvb_attach(mc44s803_attach, adap->fe, i2c_adap,
1256 &af9015_mc44s803_config) == NULL ? -ENODEV : 0; 1256 &af9015_mc44s803_config) == NULL ? -ENODEV : 0;
1257 break; 1257 break;
1258 case AF9013_TUNER_MXL5007T:
1259 ret = dvb_attach(mxl5007t_attach, adap->fe, i2c_adap,
1260 0xc0, &af9015_mxl5007t_config) == NULL ? -ENODEV : 0;
1261 break;
1258 case AF9013_TUNER_UNKNOWN: 1262 case AF9013_TUNER_UNKNOWN:
1259 default: 1263 default:
1260 ret = -ENODEV; 1264 ret = -ENODEV;
@@ -1300,10 +1304,16 @@ static struct usb_device_id af9015_usb_table[] = {
1300/* 30 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB383_T)}, 1304/* 30 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB383_T)},
1301 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_4)}, 1305 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_4)},
1302 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A815M)}, 1306 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A815M)},
1307 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_RC)},
1308 {USB_DEVICE(USB_VID_TERRATEC,
1309 USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC)},
1310/* 35 */{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850T)},
1311 {USB_DEVICE(USB_VID_GTEK, USB_PID_TINYTWIN_3)},
1303 {0}, 1312 {0},
1304}; 1313};
1305MODULE_DEVICE_TABLE(usb, af9015_usb_table); 1314MODULE_DEVICE_TABLE(usb, af9015_usb_table);
1306 1315
1316#define AF9015_RC_INTERVAL 500
1307static struct dvb_usb_device_properties af9015_properties[] = { 1317static struct dvb_usb_device_properties af9015_properties[] = {
1308 { 1318 {
1309 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1319 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
@@ -1354,14 +1364,17 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1354 1364
1355 .identify_state = af9015_identify_state, 1365 .identify_state = af9015_identify_state,
1356 1366
1357 .rc.legacy = { 1367 .rc.core = {
1368 .protocol = RC_TYPE_NEC,
1369 .module_name = "af9015",
1358 .rc_query = af9015_rc_query, 1370 .rc_query = af9015_rc_query,
1359 .rc_interval = 150, 1371 .rc_interval = AF9015_RC_INTERVAL,
1372 .allowed_protos = RC_TYPE_NEC,
1360 }, 1373 },
1361 1374
1362 .i2c_algo = &af9015_i2c_algo, 1375 .i2c_algo = &af9015_i2c_algo,
1363 1376
1364 .num_device_descs = 9, /* max 9 */ 1377 .num_device_descs = 12, /* check max from dvb-usb.h */
1365 .devices = { 1378 .devices = {
1366 { 1379 {
1367 .name = "Afatech AF9015 DVB-T USB2.0 stick", 1380 .name = "Afatech AF9015 DVB-T USB2.0 stick",
@@ -1389,7 +1402,8 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1389 { 1402 {
1390 .name = "DigitalNow TinyTwin DVB-T Receiver", 1403 .name = "DigitalNow TinyTwin DVB-T Receiver",
1391 .cold_ids = {&af9015_usb_table[5], 1404 .cold_ids = {&af9015_usb_table[5],
1392 &af9015_usb_table[28], NULL}, 1405 &af9015_usb_table[28],
1406 &af9015_usb_table[36], NULL},
1393 .warm_ids = {NULL}, 1407 .warm_ids = {NULL},
1394 }, 1408 },
1395 { 1409 {
@@ -1413,6 +1427,21 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1413 .cold_ids = {&af9015_usb_table[9], NULL}, 1427 .cold_ids = {&af9015_usb_table[9], NULL},
1414 .warm_ids = {NULL}, 1428 .warm_ids = {NULL},
1415 }, 1429 },
1430 {
1431 .name = "TerraTec Cinergy T Stick RC",
1432 .cold_ids = {&af9015_usb_table[33], NULL},
1433 .warm_ids = {NULL},
1434 },
1435 {
1436 .name = "TerraTec Cinergy T Stick Dual RC",
1437 .cold_ids = {&af9015_usb_table[34], NULL},
1438 .warm_ids = {NULL},
1439 },
1440 {
1441 .name = "AverMedia AVerTV Red HD+ (A850T)",
1442 .cold_ids = {&af9015_usb_table[35], NULL},
1443 .warm_ids = {NULL},
1444 },
1416 } 1445 }
1417 }, { 1446 }, {
1418 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1447 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
@@ -1463,14 +1492,17 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1463 1492
1464 .identify_state = af9015_identify_state, 1493 .identify_state = af9015_identify_state,
1465 1494
1466 .rc.legacy = { 1495 .rc.core = {
1496 .protocol = RC_TYPE_NEC,
1497 .module_name = "af9015",
1467 .rc_query = af9015_rc_query, 1498 .rc_query = af9015_rc_query,
1468 .rc_interval = 150, 1499 .rc_interval = AF9015_RC_INTERVAL,
1500 .allowed_protos = RC_TYPE_NEC,
1469 }, 1501 },
1470 1502
1471 .i2c_algo = &af9015_i2c_algo, 1503 .i2c_algo = &af9015_i2c_algo,
1472 1504
1473 .num_device_descs = 9, /* max 9 */ 1505 .num_device_descs = 9, /* check max from dvb-usb.h */
1474 .devices = { 1506 .devices = {
1475 { 1507 {
1476 .name = "Xtensions XD-380", 1508 .name = "Xtensions XD-380",
@@ -1572,14 +1604,17 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1572 1604
1573 .identify_state = af9015_identify_state, 1605 .identify_state = af9015_identify_state,
1574 1606
1575 .rc.legacy = { 1607 .rc.core = {
1608 .protocol = RC_TYPE_NEC,
1609 .module_name = "af9015",
1576 .rc_query = af9015_rc_query, 1610 .rc_query = af9015_rc_query,
1577 .rc_interval = 150, 1611 .rc_interval = AF9015_RC_INTERVAL,
1612 .allowed_protos = RC_TYPE_NEC,
1578 }, 1613 },
1579 1614
1580 .i2c_algo = &af9015_i2c_algo, 1615 .i2c_algo = &af9015_i2c_algo,
1581 1616
1582 .num_device_descs = 9, /* max 9 */ 1617 .num_device_descs = 9, /* check max from dvb-usb.h */
1583 .devices = { 1618 .devices = {
1584 { 1619 {
1585 .name = "AverMedia AVerTV Volar GPS 805 (A805)", 1620 .name = "AverMedia AVerTV Volar GPS 805 (A805)",
@@ -1672,7 +1707,7 @@ static int af9015_usb_probe(struct usb_interface *intf,
1672static void af9015_i2c_exit(struct dvb_usb_device *d) 1707static void af9015_i2c_exit(struct dvb_usb_device *d)
1673{ 1708{
1674 struct af9015_state *state = d->priv; 1709 struct af9015_state *state = d->priv;
1675 deb_info("%s: \n", __func__); 1710 deb_info("%s:\n", __func__);
1676 1711
1677 /* remove 2nd I2C adapter */ 1712 /* remove 2nd I2C adapter */
1678 if (d->state & DVB_USB_STATE_I2C) 1713 if (d->state & DVB_USB_STATE_I2C)
@@ -1682,7 +1717,7 @@ static void af9015_i2c_exit(struct dvb_usb_device *d)
1682static void af9015_usb_device_exit(struct usb_interface *intf) 1717static void af9015_usb_device_exit(struct usb_interface *intf)
1683{ 1718{
1684 struct dvb_usb_device *d = usb_get_intfdata(intf); 1719 struct dvb_usb_device *d = usb_get_intfdata(intf);
1685 deb_info("%s: \n", __func__); 1720 deb_info("%s:\n", __func__);
1686 1721
1687 /* remove 2nd I2C adapter */ 1722 /* remove 2nd I2C adapter */
1688 if (d != NULL && d->desc != NULL) 1723 if (d != NULL && d->desc != NULL)
diff --git a/drivers/media/dvb/dvb-usb/af9015.h b/drivers/media/dvb/dvb-usb/af9015.h
index c8e9349742ee..beb3004f00ba 100644
--- a/drivers/media/dvb/dvb-usb/af9015.h
+++ b/drivers/media/dvb/dvb-usb/af9015.h
@@ -100,6 +100,9 @@ enum af9015_ir_mode {
100 100
101struct af9015_state { 101struct af9015_state {
102 struct i2c_adapter i2c_adap; /* I2C adapter for 2nd FE */ 102 struct i2c_adapter i2c_adap; /* I2C adapter for 2nd FE */
103 u8 rc_repeat;
104 u32 rc_keycode;
105 u8 rc_last[4];
103}; 106};
104 107
105struct af9015_config { 108struct af9015_config {
@@ -108,8 +111,6 @@ struct af9015_config {
108 u16 firmware_size; 111 u16 firmware_size;
109 u16 firmware_checksum; 112 u16 firmware_checksum;
110 u32 eeprom_sum; 113 u32 eeprom_sum;
111 u8 *ir_table;
112 u16 ir_table_size;
113}; 114};
114 115
115enum af9015_remote { 116enum af9015_remote {
@@ -121,735 +122,4 @@ enum af9015_remote {
121/* 5 */ AF9015_REMOTE_AVERMEDIA_KS, 122/* 5 */ AF9015_REMOTE_AVERMEDIA_KS,
122}; 123};
123 124
124/* LeadTek - Y04G0051 */
125/* Leadtek WinFast DTV Dongle Gold */
126static struct ir_scancode ir_codes_af9015_table_leadtek[] = {
127 { 0x001e, KEY_1 },
128 { 0x001f, KEY_2 },
129 { 0x0020, KEY_3 },
130 { 0x0021, KEY_4 },
131 { 0x0022, KEY_5 },
132 { 0x0023, KEY_6 },
133 { 0x0024, KEY_7 },
134 { 0x0025, KEY_8 },
135 { 0x0026, KEY_9 },
136 { 0x0027, KEY_0 },
137 { 0x0028, KEY_OK },
138 { 0x004f, KEY_RIGHT },
139 { 0x0050, KEY_LEFT },
140 { 0x0051, KEY_DOWN },
141 { 0x0052, KEY_UP },
142 { 0x011a, KEY_POWER2 },
143 { 0x04b4, KEY_TV },
144 { 0x04b3, KEY_RED },
145 { 0x04b2, KEY_GREEN },
146 { 0x04b1, KEY_YELLOW },
147 { 0x04b0, KEY_BLUE },
148 { 0x003d, KEY_TEXT },
149 { 0x0113, KEY_SLEEP },
150 { 0x0010, KEY_MUTE },
151 { 0x0105, KEY_ESC },
152 { 0x0009, KEY_SCREEN },
153 { 0x010f, KEY_MENU },
154 { 0x003f, KEY_CHANNEL },
155 { 0x0013, KEY_REWIND },
156 { 0x0012, KEY_PLAY },
157 { 0x0011, KEY_FASTFORWARD },
158 { 0x0005, KEY_PREVIOUS },
159 { 0x0029, KEY_STOP },
160 { 0x002b, KEY_NEXT },
161 { 0x0041, KEY_EPG },
162 { 0x0019, KEY_VIDEO },
163 { 0x0016, KEY_AUDIO },
164 { 0x0037, KEY_DOT },
165 { 0x002a, KEY_AGAIN },
166 { 0x002c, KEY_CAMERA },
167 { 0x003c, KEY_NEW },
168 { 0x0115, KEY_RECORD },
169 { 0x010b, KEY_TIME },
170 { 0x0043, KEY_VOLUMEUP },
171 { 0x0042, KEY_VOLUMEDOWN },
172 { 0x004b, KEY_CHANNELUP },
173 { 0x004e, KEY_CHANNELDOWN },
174};
175
176static u8 af9015_ir_table_leadtek[] = {
177 0x03, 0xfc, 0x00, 0xff, 0x1a, 0x01, 0x00, /* KEY_POWER2 */
178 0x03, 0xfc, 0x56, 0xa9, 0xb4, 0x04, 0x00, /* KEY_TV */
179 0x03, 0xfc, 0x4b, 0xb4, 0xb3, 0x04, 0x00, /* KEY_RED */
180 0x03, 0xfc, 0x4c, 0xb3, 0xb2, 0x04, 0x00, /* KEY_GREEN */
181 0x03, 0xfc, 0x4d, 0xb2, 0xb1, 0x04, 0x00, /* KEY_YELLOW */
182 0x03, 0xfc, 0x4e, 0xb1, 0xb0, 0x04, 0x00, /* KEY_BLUE */
183 0x03, 0xfc, 0x1f, 0xe0, 0x3d, 0x00, 0x00, /* KEY_TEXT */
184 0x03, 0xfc, 0x40, 0xbf, 0x13, 0x01, 0x00, /* KEY_SLEEP */
185 0x03, 0xfc, 0x14, 0xeb, 0x10, 0x00, 0x00, /* KEY_MUTE */
186 0x03, 0xfc, 0x49, 0xb6, 0x05, 0x01, 0x00, /* KEY_ESC */
187 0x03, 0xfc, 0x50, 0xaf, 0x29, 0x00, 0x00, /* KEY_STOP (1)*/
188 0x03, 0xfc, 0x0c, 0xf3, 0x52, 0x00, 0x00, /* KEY_UP */
189 0x03, 0xfc, 0x03, 0xfc, 0x09, 0x00, 0x00, /* KEY_SCREEN */
190 0x03, 0xfc, 0x08, 0xf7, 0x50, 0x00, 0x00, /* KEY_LEFT */
191 0x03, 0xfc, 0x13, 0xec, 0x28, 0x00, 0x00, /* KEY_OK (1) */
192 0x03, 0xfc, 0x04, 0xfb, 0x4f, 0x00, 0x00, /* KEY_RIGHT */
193 0x03, 0xfc, 0x4f, 0xb0, 0x0f, 0x01, 0x00, /* KEY_MENU */
194 0x03, 0xfc, 0x10, 0xef, 0x51, 0x00, 0x00, /* KEY_DOWN */
195 0x03, 0xfc, 0x51, 0xae, 0x3f, 0x00, 0x00, /* KEY_CHANNEL */
196 0x03, 0xfc, 0x42, 0xbd, 0x13, 0x00, 0x00, /* KEY_REWIND */
197 0x03, 0xfc, 0x43, 0xbc, 0x12, 0x00, 0x00, /* KEY_PLAY */
198 0x03, 0xfc, 0x44, 0xbb, 0x11, 0x00, 0x00, /* KEY_FASTFORWARD */
199 0x03, 0xfc, 0x52, 0xad, 0x19, 0x00, 0x00, /* KEY_VIDEO (1) */
200 0x03, 0xfc, 0x54, 0xab, 0x05, 0x00, 0x00, /* KEY_PREVIOUS */
201 0x03, 0xfc, 0x46, 0xb9, 0x29, 0x00, 0x00, /* KEY_STOP (2) */
202 0x03, 0xfc, 0x55, 0xaa, 0x2b, 0x00, 0x00, /* KEY_NEXT */
203 0x03, 0xfc, 0x53, 0xac, 0x41, 0x00, 0x00, /* KEY_EPG */
204 0x03, 0xfc, 0x05, 0xfa, 0x1e, 0x00, 0x00, /* KEY_1 */
205 0x03, 0xfc, 0x06, 0xf9, 0x1f, 0x00, 0x00, /* KEY_2 */
206 0x03, 0xfc, 0x07, 0xf8, 0x20, 0x00, 0x00, /* KEY_3 */
207 0x03, 0xfc, 0x1e, 0xe1, 0x19, 0x00, 0x00, /* KEY_VIDEO (2) */
208 0x03, 0xfc, 0x09, 0xf6, 0x21, 0x00, 0x00, /* KEY_4 */
209 0x03, 0xfc, 0x0a, 0xf5, 0x22, 0x00, 0x00, /* KEY_5 */
210 0x03, 0xfc, 0x0b, 0xf4, 0x23, 0x00, 0x00, /* KEY_6 */
211 0x03, 0xfc, 0x1b, 0xe4, 0x16, 0x00, 0x00, /* KEY_AUDIO */
212 0x03, 0xfc, 0x0d, 0xf2, 0x24, 0x00, 0x00, /* KEY_7 */
213 0x03, 0xfc, 0x0e, 0xf1, 0x25, 0x00, 0x00, /* KEY_8 */
214 0x03, 0xfc, 0x0f, 0xf0, 0x26, 0x00, 0x00, /* KEY_9 */
215 0x03, 0xfc, 0x16, 0xe9, 0x28, 0x00, 0x00, /* KEY_OK (2) */
216 0x03, 0xfc, 0x41, 0xbe, 0x37, 0x00, 0x00, /* KEY_DOT */
217 0x03, 0xfc, 0x12, 0xed, 0x27, 0x00, 0x00, /* KEY_0 */
218 0x03, 0xfc, 0x11, 0xee, 0x2a, 0x00, 0x00, /* KEY_AGAIN */
219 0x03, 0xfc, 0x48, 0xb7, 0x2c, 0x00, 0x00, /* KEY_CAMERA */
220 0x03, 0xfc, 0x4a, 0xb5, 0x3c, 0x00, 0x00, /* KEY_NEW */
221 0x03, 0xfc, 0x47, 0xb8, 0x15, 0x01, 0x00, /* KEY_RECORD */
222 0x03, 0xfc, 0x45, 0xba, 0x0b, 0x01, 0x00, /* KEY_TIME */
223 0x03, 0xfc, 0x5e, 0xa1, 0x43, 0x00, 0x00, /* KEY_VOLUMEUP */
224 0x03, 0xfc, 0x5a, 0xa5, 0x42, 0x00, 0x00, /* KEY_VOLUMEDOWN */
225 0x03, 0xfc, 0x5b, 0xa4, 0x4b, 0x00, 0x00, /* KEY_CHANNELUP */
226 0x03, 0xfc, 0x5f, 0xa0, 0x4e, 0x00, 0x00, /* KEY_CHANNELDOWN */
227};
228
229/* TwinHan AzureWave AD-TU700(704J) */
230static struct ir_scancode ir_codes_af9015_table_twinhan[] = {
231 { 0x053f, KEY_POWER },
232 { 0x0019, KEY_FAVORITES }, /* Favorite List */
233 { 0x0004, KEY_TEXT }, /* Teletext */
234 { 0x000e, KEY_POWER },
235 { 0x000e, KEY_INFO }, /* Preview */
236 { 0x0008, KEY_EPG }, /* Info/EPG */
237 { 0x000f, KEY_LIST }, /* Record List */
238 { 0x001e, KEY_1 },
239 { 0x001f, KEY_2 },
240 { 0x0020, KEY_3 },
241 { 0x0021, KEY_4 },
242 { 0x0022, KEY_5 },
243 { 0x0023, KEY_6 },
244 { 0x0024, KEY_7 },
245 { 0x0025, KEY_8 },
246 { 0x0026, KEY_9 },
247 { 0x0027, KEY_0 },
248 { 0x0029, KEY_CANCEL }, /* Cancel */
249 { 0x004c, KEY_CLEAR }, /* Clear */
250 { 0x002a, KEY_BACK }, /* Back */
251 { 0x002b, KEY_TAB }, /* Tab */
252 { 0x0052, KEY_UP }, /* up arrow */
253 { 0x0051, KEY_DOWN }, /* down arrow */
254 { 0x004f, KEY_RIGHT }, /* right arrow */
255 { 0x0050, KEY_LEFT }, /* left arrow */
256 { 0x0028, KEY_ENTER }, /* Enter / ok */
257 { 0x0252, KEY_VOLUMEUP },
258 { 0x0251, KEY_VOLUMEDOWN },
259 { 0x004e, KEY_CHANNELDOWN },
260 { 0x004b, KEY_CHANNELUP },
261 { 0x004a, KEY_RECORD },
262 { 0x0111, KEY_PLAY },
263 { 0x0017, KEY_PAUSE },
264 { 0x000c, KEY_REWIND }, /* FR << */
265 { 0x0011, KEY_FASTFORWARD }, /* FF >> */
266 { 0x0115, KEY_PREVIOUS }, /* Replay */
267 { 0x010e, KEY_NEXT }, /* Skip */
268 { 0x0013, KEY_CAMERA }, /* Capture */
269 { 0x010f, KEY_LANGUAGE }, /* SAP */
270 { 0x0113, KEY_TV2 }, /* PIP */
271 { 0x001d, KEY_ZOOM }, /* Full Screen */
272 { 0x0117, KEY_SUBTITLE }, /* Subtitle / CC */
273 { 0x0010, KEY_MUTE },
274 { 0x0119, KEY_AUDIO }, /* L/R */ /* TODO better event */
275 { 0x0116, KEY_SLEEP }, /* Hibernate */
276 { 0x0116, KEY_SWITCHVIDEOMODE },
277 /* A/V */ /* TODO does not work */
278 { 0x0006, KEY_AGAIN }, /* Recall */
279 { 0x0116, KEY_KPPLUS }, /* Zoom+ */ /* TODO does not work */
280 { 0x0116, KEY_KPMINUS }, /* Zoom- */ /* TODO does not work */
281 { 0x0215, KEY_RED },
282 { 0x020a, KEY_GREEN },
283 { 0x021c, KEY_YELLOW },
284 { 0x0205, KEY_BLUE },
285};
286
287static u8 af9015_ir_table_twinhan[] = {
288 0x00, 0xff, 0x16, 0xe9, 0x3f, 0x05, 0x00,
289 0x00, 0xff, 0x07, 0xf8, 0x16, 0x01, 0x00,
290 0x00, 0xff, 0x14, 0xeb, 0x11, 0x01, 0x00,
291 0x00, 0xff, 0x1a, 0xe5, 0x4d, 0x00, 0x00,
292 0x00, 0xff, 0x4c, 0xb3, 0x17, 0x00, 0x00,
293 0x00, 0xff, 0x12, 0xed, 0x11, 0x00, 0x00,
294 0x00, 0xff, 0x40, 0xbf, 0x0c, 0x00, 0x00,
295 0x00, 0xff, 0x11, 0xee, 0x4a, 0x00, 0x00,
296 0x00, 0xff, 0x54, 0xab, 0x13, 0x00, 0x00,
297 0x00, 0xff, 0x41, 0xbe, 0x15, 0x01, 0x00,
298 0x00, 0xff, 0x42, 0xbd, 0x0e, 0x01, 0x00,
299 0x00, 0xff, 0x43, 0xbc, 0x17, 0x01, 0x00,
300 0x00, 0xff, 0x50, 0xaf, 0x0f, 0x01, 0x00,
301 0x00, 0xff, 0x4d, 0xb2, 0x1d, 0x00, 0x00,
302 0x00, 0xff, 0x47, 0xb8, 0x13, 0x01, 0x00,
303 0x00, 0xff, 0x05, 0xfa, 0x4b, 0x00, 0x00,
304 0x00, 0xff, 0x02, 0xfd, 0x4e, 0x00, 0x00,
305 0x00, 0xff, 0x0e, 0xf1, 0x06, 0x00, 0x00,
306 0x00, 0xff, 0x1e, 0xe1, 0x52, 0x02, 0x00,
307 0x00, 0xff, 0x0a, 0xf5, 0x51, 0x02, 0x00,
308 0x00, 0xff, 0x10, 0xef, 0x10, 0x00, 0x00,
309 0x00, 0xff, 0x49, 0xb6, 0x19, 0x01, 0x00,
310 0x00, 0xff, 0x15, 0xea, 0x27, 0x00, 0x00,
311 0x00, 0xff, 0x03, 0xfc, 0x1e, 0x00, 0x00,
312 0x00, 0xff, 0x01, 0xfe, 0x1f, 0x00, 0x00,
313 0x00, 0xff, 0x06, 0xf9, 0x20, 0x00, 0x00,
314 0x00, 0xff, 0x09, 0xf6, 0x21, 0x00, 0x00,
315 0x00, 0xff, 0x1d, 0xe2, 0x22, 0x00, 0x00,
316 0x00, 0xff, 0x1f, 0xe0, 0x23, 0x00, 0x00,
317 0x00, 0xff, 0x0d, 0xf2, 0x24, 0x00, 0x00,
318 0x00, 0xff, 0x19, 0xe6, 0x25, 0x00, 0x00,
319 0x00, 0xff, 0x1b, 0xe4, 0x26, 0x00, 0x00,
320 0x00, 0xff, 0x00, 0xff, 0x2b, 0x00, 0x00,
321 0x00, 0xff, 0x4a, 0xb5, 0x4c, 0x00, 0x00,
322 0x00, 0xff, 0x4b, 0xb4, 0x52, 0x00, 0x00,
323 0x00, 0xff, 0x51, 0xae, 0x51, 0x00, 0x00,
324 0x00, 0xff, 0x52, 0xad, 0x4f, 0x00, 0x00,
325 0x00, 0xff, 0x4e, 0xb1, 0x50, 0x00, 0x00,
326 0x00, 0xff, 0x0c, 0xf3, 0x29, 0x00, 0x00,
327 0x00, 0xff, 0x4f, 0xb0, 0x28, 0x00, 0x00,
328 0x00, 0xff, 0x13, 0xec, 0x2a, 0x00, 0x00,
329 0x00, 0xff, 0x17, 0xe8, 0x19, 0x00, 0x00,
330 0x00, 0xff, 0x04, 0xfb, 0x0f, 0x00, 0x00,
331 0x00, 0xff, 0x48, 0xb7, 0x0e, 0x00, 0x00,
332 0x00, 0xff, 0x0f, 0xf0, 0x04, 0x00, 0x00,
333 0x00, 0xff, 0x1c, 0xe3, 0x08, 0x00, 0x00,
334 0x00, 0xff, 0x18, 0xe7, 0x15, 0x02, 0x00,
335 0x00, 0xff, 0x53, 0xac, 0x0a, 0x02, 0x00,
336 0x00, 0xff, 0x5e, 0xa1, 0x1c, 0x02, 0x00,
337 0x00, 0xff, 0x5f, 0xa0, 0x05, 0x02, 0x00,
338};
339
340/* A-Link DTU(m) */
341static struct ir_scancode ir_codes_af9015_table_a_link[] = {
342 { 0x001e, KEY_1 },
343 { 0x001f, KEY_2 },
344 { 0x0020, KEY_3 },
345 { 0x0021, KEY_4 },
346 { 0x0022, KEY_5 },
347 { 0x0023, KEY_6 },
348 { 0x0024, KEY_7 },
349 { 0x0025, KEY_8 },
350 { 0x0026, KEY_9 },
351 { 0x0027, KEY_0 },
352 { 0x002e, KEY_CHANNELUP },
353 { 0x002d, KEY_CHANNELDOWN },
354 { 0x0428, KEY_ZOOM },
355 { 0x0041, KEY_MUTE },
356 { 0x0042, KEY_VOLUMEDOWN },
357 { 0x0043, KEY_VOLUMEUP },
358 { 0x0044, KEY_GOTO }, /* jump */
359 { 0x0545, KEY_POWER },
360};
361
362static u8 af9015_ir_table_a_link[] = {
363 0x08, 0xf7, 0x12, 0xed, 0x45, 0x05, 0x00, /* power */
364 0x08, 0xf7, 0x1a, 0xe5, 0x41, 0x00, 0x00, /* mute */
365 0x08, 0xf7, 0x01, 0xfe, 0x1e, 0x00, 0x00, /* 1 */
366 0x08, 0xf7, 0x1c, 0xe3, 0x21, 0x00, 0x00, /* 4 */
367 0x08, 0xf7, 0x03, 0xfc, 0x24, 0x00, 0x00, /* 7 */
368 0x08, 0xf7, 0x05, 0xfa, 0x28, 0x04, 0x00, /* zoom */
369 0x08, 0xf7, 0x00, 0xff, 0x43, 0x00, 0x00, /* volume up */
370 0x08, 0xf7, 0x16, 0xe9, 0x42, 0x00, 0x00, /* volume down */
371 0x08, 0xf7, 0x0f, 0xf0, 0x1f, 0x00, 0x00, /* 2 */
372 0x08, 0xf7, 0x0d, 0xf2, 0x22, 0x00, 0x00, /* 5 */
373 0x08, 0xf7, 0x1b, 0xe4, 0x25, 0x00, 0x00, /* 8 */
374 0x08, 0xf7, 0x06, 0xf9, 0x27, 0x00, 0x00, /* 0 */
375 0x08, 0xf7, 0x14, 0xeb, 0x2e, 0x00, 0x00, /* channel up */
376 0x08, 0xf7, 0x1d, 0xe2, 0x2d, 0x00, 0x00, /* channel down */
377 0x08, 0xf7, 0x02, 0xfd, 0x20, 0x00, 0x00, /* 3 */
378 0x08, 0xf7, 0x18, 0xe7, 0x23, 0x00, 0x00, /* 6 */
379 0x08, 0xf7, 0x04, 0xfb, 0x26, 0x00, 0x00, /* 9 */
380 0x08, 0xf7, 0x07, 0xf8, 0x44, 0x00, 0x00, /* jump */
381};
382
383/* MSI DIGIVOX mini II V3.0 */
384static struct ir_scancode ir_codes_af9015_table_msi[] = {
385 { 0x001e, KEY_1 },
386 { 0x001f, KEY_2 },
387 { 0x0020, KEY_3 },
388 { 0x0021, KEY_4 },
389 { 0x0022, KEY_5 },
390 { 0x0023, KEY_6 },
391 { 0x0024, KEY_7 },
392 { 0x0025, KEY_8 },
393 { 0x0026, KEY_9 },
394 { 0x0027, KEY_0 },
395 { 0x030f, KEY_CHANNELUP },
396 { 0x030e, KEY_CHANNELDOWN },
397 { 0x0042, KEY_VOLUMEDOWN },
398 { 0x0043, KEY_VOLUMEUP },
399 { 0x0545, KEY_POWER },
400 { 0x0052, KEY_UP }, /* up */
401 { 0x0051, KEY_DOWN }, /* down */
402 { 0x0028, KEY_ENTER },
403};
404
405static u8 af9015_ir_table_msi[] = {
406 0x03, 0xfc, 0x17, 0xe8, 0x45, 0x05, 0x00, /* power */
407 0x03, 0xfc, 0x0d, 0xf2, 0x51, 0x00, 0x00, /* down */
408 0x03, 0xfc, 0x03, 0xfc, 0x52, 0x00, 0x00, /* up */
409 0x03, 0xfc, 0x1a, 0xe5, 0x1e, 0x00, 0x00, /* 1 */
410 0x03, 0xfc, 0x02, 0xfd, 0x1f, 0x00, 0x00, /* 2 */
411 0x03, 0xfc, 0x04, 0xfb, 0x20, 0x00, 0x00, /* 3 */
412 0x03, 0xfc, 0x1c, 0xe3, 0x21, 0x00, 0x00, /* 4 */
413 0x03, 0xfc, 0x08, 0xf7, 0x22, 0x00, 0x00, /* 5 */
414 0x03, 0xfc, 0x1d, 0xe2, 0x23, 0x00, 0x00, /* 6 */
415 0x03, 0xfc, 0x11, 0xee, 0x24, 0x00, 0x00, /* 7 */
416 0x03, 0xfc, 0x0b, 0xf4, 0x25, 0x00, 0x00, /* 8 */
417 0x03, 0xfc, 0x10, 0xef, 0x26, 0x00, 0x00, /* 9 */
418 0x03, 0xfc, 0x09, 0xf6, 0x27, 0x00, 0x00, /* 0 */
419 0x03, 0xfc, 0x14, 0xeb, 0x43, 0x00, 0x00, /* volume up */
420 0x03, 0xfc, 0x1f, 0xe0, 0x42, 0x00, 0x00, /* volume down */
421 0x03, 0xfc, 0x15, 0xea, 0x0f, 0x03, 0x00, /* channel up */
422 0x03, 0xfc, 0x05, 0xfa, 0x0e, 0x03, 0x00, /* channel down */
423 0x03, 0xfc, 0x16, 0xe9, 0x28, 0x00, 0x00, /* enter */
424};
425
426/* MYGICTV U718 */
427static struct ir_scancode ir_codes_af9015_table_mygictv[] = {
428 { 0x003d, KEY_SWITCHVIDEOMODE },
429 /* TV / AV */
430 { 0x0545, KEY_POWER },
431 { 0x001e, KEY_1 },
432 { 0x001f, KEY_2 },
433 { 0x0020, KEY_3 },
434 { 0x0021, KEY_4 },
435 { 0x0022, KEY_5 },
436 { 0x0023, KEY_6 },
437 { 0x0024, KEY_7 },
438 { 0x0025, KEY_8 },
439 { 0x0026, KEY_9 },
440 { 0x0027, KEY_0 },
441 { 0x0041, KEY_MUTE },
442 { 0x002a, KEY_ESC }, /* Esc */
443 { 0x002e, KEY_CHANNELUP },
444 { 0x002d, KEY_CHANNELDOWN },
445 { 0x0042, KEY_VOLUMEDOWN },
446 { 0x0043, KEY_VOLUMEUP },
447 { 0x0052, KEY_UP }, /* up arrow */
448 { 0x0051, KEY_DOWN }, /* down arrow */
449 { 0x004f, KEY_RIGHT }, /* right arrow */
450 { 0x0050, KEY_LEFT }, /* left arrow */
451 { 0x0028, KEY_ENTER }, /* ok */
452 { 0x0115, KEY_RECORD },
453 { 0x0313, KEY_PLAY },
454 { 0x0113, KEY_PAUSE },
455 { 0x0116, KEY_STOP },
456 { 0x0307, KEY_REWIND }, /* FR << */
457 { 0x0309, KEY_FASTFORWARD }, /* FF >> */
458 { 0x003b, KEY_TIME }, /* TimeShift */
459 { 0x003e, KEY_CAMERA }, /* Snapshot */
460 { 0x0316, KEY_CYCLEWINDOWS }, /* yellow, min / max */
461 { 0x0000, KEY_ZOOM }, /* 'select' (?) */
462 { 0x0316, KEY_SHUFFLE }, /* Shuffle */
463 { 0x0345, KEY_POWER },
464};
465
466static u8 af9015_ir_table_mygictv[] = {
467 0x02, 0xbd, 0x0c, 0xf3, 0x3d, 0x00, 0x00, /* TV / AV */
468 0x02, 0xbd, 0x14, 0xeb, 0x45, 0x05, 0x00, /* power */
469 0x02, 0xbd, 0x00, 0xff, 0x1e, 0x00, 0x00, /* 1 */
470 0x02, 0xbd, 0x01, 0xfe, 0x1f, 0x00, 0x00, /* 2 */
471 0x02, 0xbd, 0x02, 0xfd, 0x20, 0x00, 0x00, /* 3 */
472 0x02, 0xbd, 0x03, 0xfc, 0x21, 0x00, 0x00, /* 4 */
473 0x02, 0xbd, 0x04, 0xfb, 0x22, 0x00, 0x00, /* 5 */
474 0x02, 0xbd, 0x05, 0xfa, 0x23, 0x00, 0x00, /* 6 */
475 0x02, 0xbd, 0x06, 0xf9, 0x24, 0x00, 0x00, /* 7 */
476 0x02, 0xbd, 0x07, 0xf8, 0x25, 0x00, 0x00, /* 8 */
477 0x02, 0xbd, 0x08, 0xf7, 0x26, 0x00, 0x00, /* 9 */
478 0x02, 0xbd, 0x09, 0xf6, 0x27, 0x00, 0x00, /* 0 */
479 0x02, 0xbd, 0x0a, 0xf5, 0x41, 0x00, 0x00, /* mute */
480 0x02, 0xbd, 0x1c, 0xe3, 0x2a, 0x00, 0x00, /* esc */
481 0x02, 0xbd, 0x1f, 0xe0, 0x43, 0x00, 0x00, /* volume up */
482 0x02, 0xbd, 0x12, 0xed, 0x52, 0x00, 0x00, /* up arrow */
483 0x02, 0xbd, 0x11, 0xee, 0x50, 0x00, 0x00, /* left arrow */
484 0x02, 0xbd, 0x15, 0xea, 0x28, 0x00, 0x00, /* ok */
485 0x02, 0xbd, 0x10, 0xef, 0x4f, 0x00, 0x00, /* right arrow */
486 0x02, 0xbd, 0x13, 0xec, 0x51, 0x00, 0x00, /* down arrow */
487 0x02, 0xbd, 0x0e, 0xf1, 0x42, 0x00, 0x00, /* volume down */
488 0x02, 0xbd, 0x19, 0xe6, 0x15, 0x01, 0x00, /* record */
489 0x02, 0xbd, 0x1e, 0xe1, 0x13, 0x03, 0x00, /* play */
490 0x02, 0xbd, 0x16, 0xe9, 0x16, 0x01, 0x00, /* stop */
491 0x02, 0xbd, 0x0b, 0xf4, 0x28, 0x04, 0x00, /* yellow, min / max */
492 0x02, 0xbd, 0x0f, 0xf0, 0x3b, 0x00, 0x00, /* time shift */
493 0x02, 0xbd, 0x18, 0xe7, 0x2e, 0x00, 0x00, /* channel up */
494 0x02, 0xbd, 0x1a, 0xe5, 0x2d, 0x00, 0x00, /* channel down */
495 0x02, 0xbd, 0x17, 0xe8, 0x3e, 0x00, 0x00, /* snapshot */
496 0x02, 0xbd, 0x40, 0xbf, 0x13, 0x01, 0x00, /* pause */
497 0x02, 0xbd, 0x41, 0xbe, 0x09, 0x03, 0x00, /* FF >> */
498 0x02, 0xbd, 0x42, 0xbd, 0x07, 0x03, 0x00, /* FR << */
499 0x02, 0xbd, 0x43, 0xbc, 0x00, 0x00, 0x00, /* 'select' (?) */
500 0x02, 0xbd, 0x44, 0xbb, 0x16, 0x03, 0x00, /* shuffle */
501 0x02, 0xbd, 0x45, 0xba, 0x45, 0x03, 0x00, /* power */
502};
503
504/* KWorld PlusTV Dual DVB-T Stick (DVB-T 399U) */
505static u8 af9015_ir_table_kworld[] = {
506 0x86, 0x6b, 0x0c, 0xf3, 0x2e, 0x07, 0x00,
507 0x86, 0x6b, 0x16, 0xe9, 0x2d, 0x07, 0x00,
508 0x86, 0x6b, 0x1d, 0xe2, 0x37, 0x07, 0x00,
509 0x86, 0x6b, 0x00, 0xff, 0x1e, 0x07, 0x00,
510 0x86, 0x6b, 0x01, 0xfe, 0x1f, 0x07, 0x00,
511 0x86, 0x6b, 0x02, 0xfd, 0x20, 0x07, 0x00,
512 0x86, 0x6b, 0x03, 0xfc, 0x21, 0x07, 0x00,
513 0x86, 0x6b, 0x04, 0xfb, 0x22, 0x07, 0x00,
514 0x86, 0x6b, 0x05, 0xfa, 0x23, 0x07, 0x00,
515 0x86, 0x6b, 0x06, 0xf9, 0x24, 0x07, 0x00,
516 0x86, 0x6b, 0x07, 0xf8, 0x25, 0x07, 0x00,
517 0x86, 0x6b, 0x08, 0xf7, 0x26, 0x07, 0x00,
518 0x86, 0x6b, 0x09, 0xf6, 0x4d, 0x07, 0x00,
519 0x86, 0x6b, 0x0a, 0xf5, 0x4e, 0x07, 0x00,
520 0x86, 0x6b, 0x14, 0xeb, 0x4f, 0x07, 0x00,
521 0x86, 0x6b, 0x1e, 0xe1, 0x50, 0x07, 0x00,
522 0x86, 0x6b, 0x17, 0xe8, 0x52, 0x07, 0x00,
523 0x86, 0x6b, 0x1f, 0xe0, 0x51, 0x07, 0x00,
524 0x86, 0x6b, 0x0e, 0xf1, 0x0b, 0x07, 0x00,
525 0x86, 0x6b, 0x20, 0xdf, 0x0c, 0x07, 0x00,
526 0x86, 0x6b, 0x42, 0xbd, 0x0d, 0x07, 0x00,
527 0x86, 0x6b, 0x0b, 0xf4, 0x0e, 0x07, 0x00,
528 0x86, 0x6b, 0x43, 0xbc, 0x0f, 0x07, 0x00,
529 0x86, 0x6b, 0x10, 0xef, 0x10, 0x07, 0x00,
530 0x86, 0x6b, 0x21, 0xde, 0x11, 0x07, 0x00,
531 0x86, 0x6b, 0x13, 0xec, 0x12, 0x07, 0x00,
532 0x86, 0x6b, 0x11, 0xee, 0x13, 0x07, 0x00,
533 0x86, 0x6b, 0x12, 0xed, 0x14, 0x07, 0x00,
534 0x86, 0x6b, 0x19, 0xe6, 0x15, 0x07, 0x00,
535 0x86, 0x6b, 0x1a, 0xe5, 0x16, 0x07, 0x00,
536 0x86, 0x6b, 0x1b, 0xe4, 0x17, 0x07, 0x00,
537 0x86, 0x6b, 0x4b, 0xb4, 0x18, 0x07, 0x00,
538 0x86, 0x6b, 0x40, 0xbf, 0x19, 0x07, 0x00,
539 0x86, 0x6b, 0x44, 0xbb, 0x1a, 0x07, 0x00,
540 0x86, 0x6b, 0x41, 0xbe, 0x1b, 0x07, 0x00,
541 0x86, 0x6b, 0x22, 0xdd, 0x1c, 0x07, 0x00,
542 0x86, 0x6b, 0x15, 0xea, 0x1d, 0x07, 0x00,
543 0x86, 0x6b, 0x0f, 0xf0, 0x3f, 0x07, 0x00,
544 0x86, 0x6b, 0x1c, 0xe3, 0x40, 0x07, 0x00,
545 0x86, 0x6b, 0x4a, 0xb5, 0x41, 0x07, 0x00,
546 0x86, 0x6b, 0x48, 0xb7, 0x42, 0x07, 0x00,
547 0x86, 0x6b, 0x49, 0xb6, 0x43, 0x07, 0x00,
548 0x86, 0x6b, 0x18, 0xe7, 0x44, 0x07, 0x00,
549 0x86, 0x6b, 0x23, 0xdc, 0x45, 0x07, 0x00,
550};
551
552/* AverMedia Volar X */
553static struct ir_scancode ir_codes_af9015_table_avermedia[] = {
554 { 0x053d, KEY_PROG1 }, /* SOURCE */
555 { 0x0512, KEY_POWER }, /* POWER */
556 { 0x051e, KEY_1 }, /* 1 */
557 { 0x051f, KEY_2 }, /* 2 */
558 { 0x0520, KEY_3 }, /* 3 */
559 { 0x0521, KEY_4 }, /* 4 */
560 { 0x0522, KEY_5 }, /* 5 */
561 { 0x0523, KEY_6 }, /* 6 */
562 { 0x0524, KEY_7 }, /* 7 */
563 { 0x0525, KEY_8 }, /* 8 */
564 { 0x0526, KEY_9 }, /* 9 */
565 { 0x053f, KEY_LEFT }, /* L / DISPLAY */
566 { 0x0527, KEY_0 }, /* 0 */
567 { 0x050f, KEY_RIGHT }, /* R / CH RTN */
568 { 0x0518, KEY_PROG2 }, /* SNAP SHOT */
569 { 0x051c, KEY_PROG3 }, /* 16-CH PREV */
570 { 0x052d, KEY_VOLUMEDOWN }, /* VOL DOWN */
571 { 0x053e, KEY_ZOOM }, /* FULL SCREEN */
572 { 0x052e, KEY_VOLUMEUP }, /* VOL UP */
573 { 0x0510, KEY_MUTE }, /* MUTE */
574 { 0x0504, KEY_AUDIO }, /* AUDIO */
575 { 0x0515, KEY_RECORD }, /* RECORD */
576 { 0x0511, KEY_PLAY }, /* PLAY */
577 { 0x0516, KEY_STOP }, /* STOP */
578 { 0x050c, KEY_PLAYPAUSE }, /* TIMESHIFT / PAUSE */
579 { 0x0505, KEY_BACK }, /* << / RED */
580 { 0x0509, KEY_FORWARD }, /* >> / YELLOW */
581 { 0x0517, KEY_TEXT }, /* TELETEXT */
582 { 0x050a, KEY_EPG }, /* EPG */
583 { 0x0513, KEY_MENU }, /* MENU */
584
585 { 0x050e, KEY_CHANNELUP }, /* CH UP */
586 { 0x050d, KEY_CHANNELDOWN }, /* CH DOWN */
587 { 0x0519, KEY_FIRST }, /* |<< / GREEN */
588 { 0x0508, KEY_LAST }, /* >>| / BLUE */
589};
590
591static u8 af9015_ir_table_avermedia[] = {
592 0x02, 0xfd, 0x00, 0xff, 0x12, 0x05, 0x00,
593 0x02, 0xfd, 0x01, 0xfe, 0x3d, 0x05, 0x00,
594 0x02, 0xfd, 0x03, 0xfc, 0x17, 0x05, 0x00,
595 0x02, 0xfd, 0x04, 0xfb, 0x0a, 0x05, 0x00,
596 0x02, 0xfd, 0x05, 0xfa, 0x1e, 0x05, 0x00,
597 0x02, 0xfd, 0x06, 0xf9, 0x1f, 0x05, 0x00,
598 0x02, 0xfd, 0x07, 0xf8, 0x20, 0x05, 0x00,
599 0x02, 0xfd, 0x09, 0xf6, 0x21, 0x05, 0x00,
600 0x02, 0xfd, 0x0a, 0xf5, 0x22, 0x05, 0x00,
601 0x02, 0xfd, 0x0b, 0xf4, 0x23, 0x05, 0x00,
602 0x02, 0xfd, 0x0d, 0xf2, 0x24, 0x05, 0x00,
603 0x02, 0xfd, 0x0e, 0xf1, 0x25, 0x05, 0x00,
604 0x02, 0xfd, 0x0f, 0xf0, 0x26, 0x05, 0x00,
605 0x02, 0xfd, 0x11, 0xee, 0x27, 0x05, 0x00,
606 0x02, 0xfd, 0x08, 0xf7, 0x04, 0x05, 0x00,
607 0x02, 0xfd, 0x0c, 0xf3, 0x3e, 0x05, 0x00,
608 0x02, 0xfd, 0x10, 0xef, 0x1c, 0x05, 0x00,
609 0x02, 0xfd, 0x12, 0xed, 0x3f, 0x05, 0x00,
610 0x02, 0xfd, 0x13, 0xec, 0x0f, 0x05, 0x00,
611 0x02, 0xfd, 0x14, 0xeb, 0x10, 0x05, 0x00,
612 0x02, 0xfd, 0x15, 0xea, 0x13, 0x05, 0x00,
613 0x02, 0xfd, 0x17, 0xe8, 0x18, 0x05, 0x00,
614 0x02, 0xfd, 0x18, 0xe7, 0x11, 0x05, 0x00,
615 0x02, 0xfd, 0x19, 0xe6, 0x15, 0x05, 0x00,
616 0x02, 0xfd, 0x1a, 0xe5, 0x0c, 0x05, 0x00,
617 0x02, 0xfd, 0x1b, 0xe4, 0x16, 0x05, 0x00,
618 0x02, 0xfd, 0x1c, 0xe3, 0x09, 0x05, 0x00,
619 0x02, 0xfd, 0x1d, 0xe2, 0x05, 0x05, 0x00,
620 0x02, 0xfd, 0x1e, 0xe1, 0x2d, 0x05, 0x00,
621 0x02, 0xfd, 0x1f, 0xe0, 0x2e, 0x05, 0x00,
622 0x03, 0xfc, 0x00, 0xff, 0x08, 0x05, 0x00,
623 0x03, 0xfc, 0x01, 0xfe, 0x19, 0x05, 0x00,
624 0x03, 0xfc, 0x02, 0xfd, 0x0d, 0x05, 0x00,
625 0x03, 0xfc, 0x03, 0xfc, 0x0e, 0x05, 0x00,
626};
627
628static u8 af9015_ir_table_avermedia_ks[] = {
629 0x05, 0xfa, 0x01, 0xfe, 0x12, 0x05, 0x00,
630 0x05, 0xfa, 0x02, 0xfd, 0x0e, 0x05, 0x00,
631 0x05, 0xfa, 0x03, 0xfc, 0x0d, 0x05, 0x00,
632 0x05, 0xfa, 0x04, 0xfb, 0x2e, 0x05, 0x00,
633 0x05, 0xfa, 0x05, 0xfa, 0x2d, 0x05, 0x00,
634 0x05, 0xfa, 0x06, 0xf9, 0x10, 0x05, 0x00,
635 0x05, 0xfa, 0x07, 0xf8, 0x0f, 0x05, 0x00,
636 0x05, 0xfa, 0x08, 0xf7, 0x3d, 0x05, 0x00,
637 0x05, 0xfa, 0x09, 0xf6, 0x1e, 0x05, 0x00,
638 0x05, 0xfa, 0x0a, 0xf5, 0x1f, 0x05, 0x00,
639 0x05, 0xfa, 0x0b, 0xf4, 0x20, 0x05, 0x00,
640 0x05, 0xfa, 0x0c, 0xf3, 0x21, 0x05, 0x00,
641 0x05, 0xfa, 0x0d, 0xf2, 0x22, 0x05, 0x00,
642 0x05, 0xfa, 0x0e, 0xf1, 0x23, 0x05, 0x00,
643 0x05, 0xfa, 0x0f, 0xf0, 0x24, 0x05, 0x00,
644 0x05, 0xfa, 0x10, 0xef, 0x25, 0x05, 0x00,
645 0x05, 0xfa, 0x11, 0xee, 0x26, 0x05, 0x00,
646 0x05, 0xfa, 0x12, 0xed, 0x27, 0x05, 0x00,
647 0x05, 0xfa, 0x13, 0xec, 0x04, 0x05, 0x00,
648 0x05, 0xfa, 0x15, 0xea, 0x0a, 0x05, 0x00,
649 0x05, 0xfa, 0x16, 0xe9, 0x11, 0x05, 0x00,
650 0x05, 0xfa, 0x17, 0xe8, 0x15, 0x05, 0x00,
651 0x05, 0xfa, 0x18, 0xe7, 0x16, 0x05, 0x00,
652 0x05, 0xfa, 0x1c, 0xe3, 0x05, 0x05, 0x00,
653 0x05, 0xfa, 0x1d, 0xe2, 0x09, 0x05, 0x00,
654 0x05, 0xfa, 0x4d, 0xb2, 0x3f, 0x05, 0x00,
655 0x05, 0xfa, 0x56, 0xa9, 0x3e, 0x05, 0x00
656};
657
658/* Digittrade DVB-T USB Stick */
659static struct ir_scancode ir_codes_af9015_table_digittrade[] = {
660 { 0x010f, KEY_LAST }, /* RETURN */
661 { 0x0517, KEY_TEXT }, /* TELETEXT */
662 { 0x0108, KEY_EPG }, /* EPG */
663 { 0x0513, KEY_POWER }, /* POWER */
664 { 0x0109, KEY_ZOOM }, /* FULLSCREEN */
665 { 0x0040, KEY_AUDIO }, /* DUAL SOUND */
666 { 0x002c, KEY_PRINT }, /* SNAPSHOT */
667 { 0x0516, KEY_SUBTITLE }, /* SUBTITLE */
668 { 0x0052, KEY_CHANNELUP }, /* CH Up */
669 { 0x0051, KEY_CHANNELDOWN },/* Ch Dn */
670 { 0x0057, KEY_VOLUMEUP }, /* Vol Up */
671 { 0x0056, KEY_VOLUMEDOWN }, /* Vol Dn */
672 { 0x0110, KEY_MUTE }, /* MUTE */
673 { 0x0027, KEY_0 },
674 { 0x001e, KEY_1 },
675 { 0x001f, KEY_2 },
676 { 0x0020, KEY_3 },
677 { 0x0021, KEY_4 },
678 { 0x0022, KEY_5 },
679 { 0x0023, KEY_6 },
680 { 0x0024, KEY_7 },
681 { 0x0025, KEY_8 },
682 { 0x0026, KEY_9 },
683 { 0x0117, KEY_PLAYPAUSE }, /* TIMESHIFT */
684 { 0x0115, KEY_RECORD }, /* RECORD */
685 { 0x0313, KEY_PLAY }, /* PLAY */
686 { 0x0116, KEY_STOP }, /* STOP */
687 { 0x0113, KEY_PAUSE }, /* PAUSE */
688};
689
690static u8 af9015_ir_table_digittrade[] = {
691 0x00, 0xff, 0x06, 0xf9, 0x13, 0x05, 0x00,
692 0x00, 0xff, 0x4d, 0xb2, 0x17, 0x01, 0x00,
693 0x00, 0xff, 0x1f, 0xe0, 0x2c, 0x00, 0x00,
694 0x00, 0xff, 0x0a, 0xf5, 0x15, 0x01, 0x00,
695 0x00, 0xff, 0x0e, 0xf1, 0x16, 0x01, 0x00,
696 0x00, 0xff, 0x09, 0xf6, 0x09, 0x01, 0x00,
697 0x00, 0xff, 0x01, 0xfe, 0x08, 0x01, 0x00,
698 0x00, 0xff, 0x05, 0xfa, 0x10, 0x01, 0x00,
699 0x00, 0xff, 0x02, 0xfd, 0x56, 0x00, 0x00,
700 0x00, 0xff, 0x40, 0xbf, 0x57, 0x00, 0x00,
701 0x00, 0xff, 0x19, 0xe6, 0x52, 0x00, 0x00,
702 0x00, 0xff, 0x17, 0xe8, 0x51, 0x00, 0x00,
703 0x00, 0xff, 0x10, 0xef, 0x0f, 0x01, 0x00,
704 0x00, 0xff, 0x54, 0xab, 0x27, 0x00, 0x00,
705 0x00, 0xff, 0x1b, 0xe4, 0x1e, 0x00, 0x00,
706 0x00, 0xff, 0x11, 0xee, 0x1f, 0x00, 0x00,
707 0x00, 0xff, 0x15, 0xea, 0x20, 0x00, 0x00,
708 0x00, 0xff, 0x12, 0xed, 0x21, 0x00, 0x00,
709 0x00, 0xff, 0x16, 0xe9, 0x22, 0x00, 0x00,
710 0x00, 0xff, 0x4c, 0xb3, 0x23, 0x00, 0x00,
711 0x00, 0xff, 0x48, 0xb7, 0x24, 0x00, 0x00,
712 0x00, 0xff, 0x04, 0xfb, 0x25, 0x00, 0x00,
713 0x00, 0xff, 0x00, 0xff, 0x26, 0x00, 0x00,
714 0x00, 0xff, 0x1e, 0xe1, 0x13, 0x03, 0x00,
715 0x00, 0xff, 0x1a, 0xe5, 0x13, 0x01, 0x00,
716 0x00, 0xff, 0x03, 0xfc, 0x17, 0x05, 0x00,
717 0x00, 0xff, 0x0d, 0xf2, 0x16, 0x05, 0x00,
718 0x00, 0xff, 0x1d, 0xe2, 0x40, 0x00, 0x00,
719};
720
721/* TREKSTOR DVB-T USB Stick */
722static struct ir_scancode ir_codes_af9015_table_trekstor[] = {
723 { 0x0704, KEY_AGAIN }, /* Home */
724 { 0x0705, KEY_MUTE }, /* Mute */
725 { 0x0706, KEY_UP }, /* Up */
726 { 0x0707, KEY_DOWN }, /* Down */
727 { 0x0709, KEY_RIGHT }, /* Right */
728 { 0x070a, KEY_ENTER }, /* OK */
729 { 0x070b, KEY_FASTFORWARD }, /* Fast forward */
730 { 0x070c, KEY_REWIND }, /* Rewind */
731 { 0x070d, KEY_PLAY }, /* Play/Pause */
732 { 0x070e, KEY_VOLUMEUP }, /* Volume + */
733 { 0x070f, KEY_VOLUMEDOWN }, /* Volume - */
734 { 0x0710, KEY_RECORD }, /* Record */
735 { 0x0711, KEY_STOP }, /* Stop */
736 { 0x0712, KEY_ZOOM }, /* TV */
737 { 0x0713, KEY_EPG }, /* Info/EPG */
738 { 0x0714, KEY_CHANNELDOWN }, /* Channel - */
739 { 0x0715, KEY_CHANNELUP }, /* Channel + */
740 { 0x071e, KEY_1 },
741 { 0x071f, KEY_2 },
742 { 0x0720, KEY_3 },
743 { 0x0721, KEY_4 },
744 { 0x0722, KEY_5 },
745 { 0x0723, KEY_6 },
746 { 0x0724, KEY_7 },
747 { 0x0725, KEY_8 },
748 { 0x0726, KEY_9 },
749 { 0x0708, KEY_LEFT }, /* LEFT */
750 { 0x0727, KEY_0 },
751};
752
753static u8 af9015_ir_table_trekstor[] = {
754 0x00, 0xff, 0x86, 0x79, 0x04, 0x07, 0x00,
755 0x00, 0xff, 0x85, 0x7a, 0x05, 0x07, 0x00,
756 0x00, 0xff, 0x87, 0x78, 0x06, 0x07, 0x00,
757 0x00, 0xff, 0x8c, 0x73, 0x07, 0x07, 0x00,
758 0x00, 0xff, 0x89, 0x76, 0x09, 0x07, 0x00,
759 0x00, 0xff, 0x88, 0x77, 0x0a, 0x07, 0x00,
760 0x00, 0xff, 0x8a, 0x75, 0x0b, 0x07, 0x00,
761 0x00, 0xff, 0x9e, 0x61, 0x0c, 0x07, 0x00,
762 0x00, 0xff, 0x8d, 0x72, 0x0d, 0x07, 0x00,
763 0x00, 0xff, 0x8b, 0x74, 0x0e, 0x07, 0x00,
764 0x00, 0xff, 0x9b, 0x64, 0x0f, 0x07, 0x00,
765 0x00, 0xff, 0x9d, 0x62, 0x10, 0x07, 0x00,
766 0x00, 0xff, 0x8e, 0x71, 0x11, 0x07, 0x00,
767 0x00, 0xff, 0x9c, 0x63, 0x12, 0x07, 0x00,
768 0x00, 0xff, 0x8f, 0x70, 0x13, 0x07, 0x00,
769 0x00, 0xff, 0x93, 0x6c, 0x14, 0x07, 0x00,
770 0x00, 0xff, 0x97, 0x68, 0x15, 0x07, 0x00,
771 0x00, 0xff, 0x92, 0x6d, 0x1e, 0x07, 0x00,
772 0x00, 0xff, 0x96, 0x69, 0x1f, 0x07, 0x00,
773 0x00, 0xff, 0x9a, 0x65, 0x20, 0x07, 0x00,
774 0x00, 0xff, 0x91, 0x6e, 0x21, 0x07, 0x00,
775 0x00, 0xff, 0x95, 0x6a, 0x22, 0x07, 0x00,
776 0x00, 0xff, 0x99, 0x66, 0x23, 0x07, 0x00,
777 0x00, 0xff, 0x90, 0x6f, 0x24, 0x07, 0x00,
778 0x00, 0xff, 0x94, 0x6b, 0x25, 0x07, 0x00,
779 0x00, 0xff, 0x98, 0x67, 0x26, 0x07, 0x00,
780 0x00, 0xff, 0x9f, 0x60, 0x08, 0x07, 0x00,
781 0x00, 0xff, 0x84, 0x7b, 0x27, 0x07, 0x00,
782};
783
784/* MSI DIGIVOX mini III */
785static struct ir_scancode ir_codes_af9015_table_msi_digivox_iii[] = {
786 { 0x0713, KEY_POWER }, /* [red power button] */
787 { 0x073b, KEY_VIDEO }, /* Source */
788 { 0x073e, KEY_ZOOM }, /* Zoom */
789 { 0x070b, KEY_POWER2 }, /* ShutDown */
790 { 0x071e, KEY_1 },
791 { 0x071f, KEY_2 },
792 { 0x0720, KEY_3 },
793 { 0x0721, KEY_4 },
794 { 0x0722, KEY_5 },
795 { 0x0723, KEY_6 },
796 { 0x0724, KEY_7 },
797 { 0x0725, KEY_8 },
798 { 0x0726, KEY_9 },
799 { 0x0727, KEY_0 },
800 { 0x0752, KEY_CHANNELUP }, /* CH+ */
801 { 0x0751, KEY_CHANNELDOWN }, /* CH- */
802 { 0x0750, KEY_VOLUMEUP }, /* Vol+ */
803 { 0x074f, KEY_VOLUMEDOWN }, /* Vol- */
804 { 0x0705, KEY_ESC }, /* [back up arrow] */
805 { 0x0708, KEY_OK }, /* [enter arrow] */
806 { 0x073f, KEY_RECORD }, /* Rec */
807 { 0x0716, KEY_STOP }, /* Stop */
808 { 0x072a, KEY_PLAY }, /* Play */
809 { 0x073c, KEY_MUTE }, /* Mute */
810 { 0x0718, KEY_UP },
811 { 0x0707, KEY_DOWN },
812 { 0x070f, KEY_LEFT },
813 { 0x0715, KEY_RIGHT },
814 { 0x0736, KEY_RED },
815 { 0x0737, KEY_GREEN },
816 { 0x072d, KEY_YELLOW },
817 { 0x072e, KEY_BLUE },
818};
819
820static u8 af9015_ir_table_msi_digivox_iii[] = {
821 0x61, 0xd6, 0x43, 0xbc, 0x13, 0x07, 0x00, /* KEY_POWER */
822 0x61, 0xd6, 0x01, 0xfe, 0x3b, 0x07, 0x00, /* KEY_VIDEO */
823 0x61, 0xd6, 0x0b, 0xf4, 0x3e, 0x07, 0x00, /* KEY_ZOOM */
824 0x61, 0xd6, 0x03, 0xfc, 0x0b, 0x07, 0x00, /* KEY_POWER2 */
825 0x61, 0xd6, 0x04, 0xfb, 0x1e, 0x07, 0x00, /* KEY_1 */
826 0x61, 0xd6, 0x08, 0xf7, 0x1f, 0x07, 0x00, /* KEY_2 */
827 0x61, 0xd6, 0x02, 0xfd, 0x20, 0x07, 0x00, /* KEY_3 */
828 0x61, 0xd6, 0x0f, 0xf0, 0x21, 0x07, 0x00, /* KEY_4 */
829 0x61, 0xd6, 0x05, 0xfa, 0x22, 0x07, 0x00, /* KEY_5 */
830 0x61, 0xd6, 0x06, 0xf9, 0x23, 0x07, 0x00, /* KEY_6 */
831 0x61, 0xd6, 0x0c, 0xf3, 0x24, 0x07, 0x00, /* KEY_7 */
832 0x61, 0xd6, 0x0d, 0xf2, 0x25, 0x07, 0x00, /* KEY_8 */
833 0x61, 0xd6, 0x0a, 0xf5, 0x26, 0x07, 0x00, /* KEY_9 */
834 0x61, 0xd6, 0x11, 0xee, 0x27, 0x07, 0x00, /* KEY_0 */
835 0x61, 0xd6, 0x09, 0xf6, 0x52, 0x07, 0x00, /* KEY_CHANNELUP */
836 0x61, 0xd6, 0x07, 0xf8, 0x51, 0x07, 0x00, /* KEY_CHANNELDOWN */
837 0x61, 0xd6, 0x0e, 0xf1, 0x50, 0x07, 0x00, /* KEY_VOLUMEUP */
838 0x61, 0xd6, 0x13, 0xec, 0x4f, 0x07, 0x00, /* KEY_VOLUMEDOWN */
839 0x61, 0xd6, 0x10, 0xef, 0x05, 0x07, 0x00, /* KEY_ESC */
840 0x61, 0xd6, 0x12, 0xed, 0x08, 0x07, 0x00, /* KEY_OK */
841 0x61, 0xd6, 0x14, 0xeb, 0x3f, 0x07, 0x00, /* KEY_RECORD */
842 0x61, 0xd6, 0x15, 0xea, 0x16, 0x07, 0x00, /* KEY_STOP */
843 0x61, 0xd6, 0x16, 0xe9, 0x2a, 0x07, 0x00, /* KEY_PLAY */
844 0x61, 0xd6, 0x17, 0xe8, 0x3c, 0x07, 0x00, /* KEY_MUTE */
845 0x61, 0xd6, 0x18, 0xe7, 0x18, 0x07, 0x00, /* KEY_UP */
846 0x61, 0xd6, 0x19, 0xe6, 0x07, 0x07, 0x00, /* KEY_DOWN */
847 0x61, 0xd6, 0x1a, 0xe5, 0x0f, 0x07, 0x00, /* KEY_LEFT */
848 0x61, 0xd6, 0x1b, 0xe4, 0x15, 0x07, 0x00, /* KEY_RIGHT */
849 0x61, 0xd6, 0x1c, 0xe3, 0x36, 0x07, 0x00, /* KEY_RED */
850 0x61, 0xd6, 0x1d, 0xe2, 0x37, 0x07, 0x00, /* KEY_GREEN */
851 0x61, 0xd6, 0x1e, 0xe1, 0x2d, 0x07, 0x00, /* KEY_YELLOW */
852 0x61, 0xd6, 0x1f, 0xe0, 0x2e, 0x07, 0x00, /* KEY_BLUE */
853};
854
855#endif 125#endif
diff --git a/drivers/media/dvb/dvb-usb/anysee.c b/drivers/media/dvb/dvb-usb/anysee.c
index 4685259e1614..7c327b54308e 100644
--- a/drivers/media/dvb/dvb-usb/anysee.c
+++ b/drivers/media/dvb/dvb-usb/anysee.c
@@ -36,6 +36,11 @@
36#include "mt352.h" 36#include "mt352.h"
37#include "mt352_priv.h" 37#include "mt352_priv.h"
38#include "zl10353.h" 38#include "zl10353.h"
39#include "tda18212.h"
40#include "cx24116.h"
41#include "stv0900.h"
42#include "stv6110.h"
43#include "isl6423.h"
39 44
40/* debug */ 45/* debug */
41static int dvb_usb_anysee_debug; 46static int dvb_usb_anysee_debug;
@@ -55,8 +60,6 @@ static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
55 int act_len, ret; 60 int act_len, ret;
56 u8 buf[64]; 61 u8 buf[64];
57 62
58 if (slen > sizeof(buf))
59 slen = sizeof(buf);
60 memcpy(&buf[0], sbuf, slen); 63 memcpy(&buf[0], sbuf, slen);
61 buf[60] = state->seq++; 64 buf[60] = state->seq++;
62 65
@@ -105,6 +108,27 @@ static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
105 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); 108 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
106} 109}
107 110
111/* write single register with mask */
112static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
113 u8 mask)
114{
115 int ret;
116 u8 tmp;
117
118 /* no need for read if whole reg is written */
119 if (mask != 0xff) {
120 ret = anysee_read_reg(d, reg, &tmp);
121 if (ret)
122 return ret;
123
124 val &= mask;
125 tmp &= ~mask;
126 val |= tmp;
127 }
128
129 return anysee_write_reg(d, reg, val);
130}
131
108static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id) 132static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
109{ 133{
110 u8 buf[] = {CMD_GET_HW_INFO}; 134 u8 buf[] = {CMD_GET_HW_INFO};
@@ -154,30 +178,37 @@ static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
154{ 178{
155 struct dvb_usb_device *d = i2c_get_adapdata(adap); 179 struct dvb_usb_device *d = i2c_get_adapdata(adap);
156 int ret = 0, inc, i = 0; 180 int ret = 0, inc, i = 0;
181 u8 buf[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
157 182
158 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 183 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
159 return -EAGAIN; 184 return -EAGAIN;
160 185
161 while (i < num) { 186 while (i < num) {
162 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) { 187 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
163 u8 buf[6]; 188 if (msg[i].len > 2 || msg[i+1].len > 60) {
189 ret = -EOPNOTSUPP;
190 break;
191 }
164 buf[0] = CMD_I2C_READ; 192 buf[0] = CMD_I2C_READ;
165 buf[1] = msg[i].addr + 1; 193 buf[1] = (msg[i].addr << 1) | 0x01;
166 buf[2] = msg[i].buf[0]; 194 buf[2] = msg[i].buf[0];
167 buf[3] = 0x00; 195 buf[3] = msg[i].buf[1];
168 buf[4] = 0x00; 196 buf[4] = msg[i].len-1;
169 buf[5] = 0x01; 197 buf[5] = msg[i+1].len;
170 ret = anysee_ctrl_msg(d, buf, sizeof(buf), msg[i+1].buf, 198 ret = anysee_ctrl_msg(d, buf, 6, msg[i+1].buf,
171 msg[i+1].len); 199 msg[i+1].len);
172 inc = 2; 200 inc = 2;
173 } else { 201 } else {
174 u8 buf[4+msg[i].len]; 202 if (msg[i].len > 48) {
203 ret = -EOPNOTSUPP;
204 break;
205 }
175 buf[0] = CMD_I2C_WRITE; 206 buf[0] = CMD_I2C_WRITE;
176 buf[1] = msg[i].addr; 207 buf[1] = (msg[i].addr << 1);
177 buf[2] = msg[i].len; 208 buf[2] = msg[i].len;
178 buf[3] = 0x01; 209 buf[3] = 0x01;
179 memcpy(&buf[4], msg[i].buf, msg[i].len); 210 memcpy(&buf[4], msg[i].buf, msg[i].len);
180 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); 211 ret = anysee_ctrl_msg(d, buf, 4 + msg[i].len, NULL, 0);
181 inc = 1; 212 inc = 1;
182 } 213 }
183 if (ret) 214 if (ret)
@@ -224,7 +255,7 @@ static int anysee_mt352_demod_init(struct dvb_frontend *fe)
224 255
225/* Callbacks for DVB USB */ 256/* Callbacks for DVB USB */
226static struct tda10023_config anysee_tda10023_config = { 257static struct tda10023_config anysee_tda10023_config = {
227 .demod_address = 0x1a, 258 .demod_address = (0x1a >> 1),
228 .invert = 0, 259 .invert = 0,
229 .xtal = 16000000, 260 .xtal = 16000000,
230 .pll_m = 11, 261 .pll_m = 11,
@@ -235,217 +266,567 @@ static struct tda10023_config anysee_tda10023_config = {
235}; 266};
236 267
237static struct mt352_config anysee_mt352_config = { 268static struct mt352_config anysee_mt352_config = {
238 .demod_address = 0x1e, 269 .demod_address = (0x1e >> 1),
239 .demod_init = anysee_mt352_demod_init, 270 .demod_init = anysee_mt352_demod_init,
240}; 271};
241 272
242static struct zl10353_config anysee_zl10353_config = { 273static struct zl10353_config anysee_zl10353_config = {
243 .demod_address = 0x1e, 274 .demod_address = (0x1e >> 1),
244 .parallel_ts = 1, 275 .parallel_ts = 1,
245}; 276};
246 277
278static struct zl10353_config anysee_zl10353_tda18212_config2 = {
279 .demod_address = (0x1e >> 1),
280 .parallel_ts = 1,
281 .disable_i2c_gate_ctrl = 1,
282 .no_tuner = 1,
283 .if2 = 41500,
284};
285
286static struct zl10353_config anysee_zl10353_tda18212_config = {
287 .demod_address = (0x18 >> 1),
288 .parallel_ts = 1,
289 .disable_i2c_gate_ctrl = 1,
290 .no_tuner = 1,
291 .if2 = 41500,
292};
293
294static struct tda10023_config anysee_tda10023_tda18212_config = {
295 .demod_address = (0x1a >> 1),
296 .xtal = 16000000,
297 .pll_m = 12,
298 .pll_p = 3,
299 .pll_n = 1,
300 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
301 .deltaf = 0xba02,
302};
303
304static struct tda18212_config anysee_tda18212_config = {
305 .i2c_address = (0xc0 >> 1),
306 .if_dvbt_6 = 4150,
307 .if_dvbt_7 = 4150,
308 .if_dvbt_8 = 4150,
309 .if_dvbc = 5000,
310};
311
312static struct cx24116_config anysee_cx24116_config = {
313 .demod_address = (0xaa >> 1),
314 .mpg_clk_pos_pol = 0x00,
315 .i2c_wr_max = 48,
316};
317
318static struct stv0900_config anysee_stv0900_config = {
319 .demod_address = (0xd0 >> 1),
320 .demod_mode = 0,
321 .xtal = 8000000,
322 .clkmode = 3,
323 .diseqc_mode = 2,
324 .tun1_maddress = 0,
325 .tun1_adc = 1, /* 1 Vpp */
326 .path1_mode = 3,
327};
328
329static struct stv6110_config anysee_stv6110_config = {
330 .i2c_address = (0xc0 >> 1),
331 .mclk = 16000000,
332 .clk_div = 1,
333};
334
335static struct isl6423_config anysee_isl6423_config = {
336 .current_max = SEC_CURRENT_800m,
337 .curlim = SEC_CURRENT_LIM_OFF,
338 .mod_extern = 1,
339 .addr = (0x10 >> 1),
340};
341
342/*
343 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
344 * Manufacturer: AMT.CO.KR
345 *
346 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
347 * PCB: ?
348 * parts: DNOS404ZH102A(MT352, DTT7579(?))
349 *
350 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
351 * PCB: ?
352 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
353 *
354 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
355 * PCB: 507CD (rev1.1)
356 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
357 * OEA=80 OEB=00 OEC=00 OED=ff OEF=fe
358 * IOA=4f IOB=ff IOC=00 IOD=06 IOF=01
359 * IOD[0] ZL10353 1=enabled
360 * IOA[7] TS 0=enabled
361 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
362 *
363 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
364 * PCB: 507DC (rev0.2)
365 * parts: TDA10023, DTOS403IH102B TM, CST56I01
366 * OEA=80 OEB=00 OEC=00 OED=ff OEF=fe
367 * IOA=4f IOB=ff IOC=00 IOD=26 IOF=01
368 * IOD[0] TDA10023 1=enabled
369 *
370 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
371 * PCB: 507SI (rev2.1)
372 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
373 * OEA=80 OEB=00 OEC=ff OED=ff OEF=fe
374 * IOA=4d IOB=ff IOC=00 IOD=26 IOF=01
375 * IOD[0] CX24116 1=enabled
376 *
377 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
378 * PCB: 507FA (rev0.4)
379 * parts: TDA10023, DTOS403IH102B TM, TDA8024
380 * OEA=80 OEB=00 OEC=ff OED=ff OEF=ff
381 * IOA=4d IOB=ff IOC=00 IOD=00 IOF=c0
382 * IOD[5] TDA10023 1=enabled
383 * IOE[0] tuner 1=enabled
384 *
385 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
386 * PCB: 507FA (rev1.1)
387 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
388 * OEA=80 OEB=00 OEC=ff OED=ff OEF=ff
389 * IOA=4d IOB=ff IOC=00 IOD=00 IOF=c0
390 * DVB-C:
391 * IOD[5] TDA10023 1=enabled
392 * IOE[0] tuner 1=enabled
393 * DVB-T:
394 * IOD[0] ZL10353 1=enabled
395 * IOE[0] tuner 0=enabled
396 * tuner is behind ZL10353 I2C-gate
397 *
398 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
399 * PCB: 508TC (rev0.6)
400 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
401 * OEA=80 OEB=00 OEC=03 OED=f7 OEF=ff
402 * IOA=4d IOB=00 IOC=cc IOD=48 IOF=e4
403 * IOA[7] TS 1=enabled
404 * IOE[4] TDA18212 1=enabled
405 * DVB-C:
406 * IOD[6] ZL10353 0=disabled
407 * IOD[5] TDA10023 1=enabled
408 * IOE[0] IF 1=enabled
409 * DVB-T:
410 * IOD[5] TDA10023 0=disabled
411 * IOD[6] ZL10353 1=enabled
412 * IOE[0] IF 0=enabled
413 *
414 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
415 * PCB: 508S2 (rev0.7)
416 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
417 * OEA=80 OEB=00 OEC=03 OED=f7 OEF=ff
418 * IOA=4d IOB=00 IOC=c4 IOD=08 IOF=e4
419 * IOA[7] TS 1=enabled
420 * IOE[5] STV0903 1=enabled
421 *
422 */
423
247static int anysee_frontend_attach(struct dvb_usb_adapter *adap) 424static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
248{ 425{
249 int ret; 426 int ret;
250 struct anysee_state *state = adap->dev->priv; 427 struct anysee_state *state = adap->dev->priv;
251 u8 hw_info[3]; 428 u8 hw_info[3];
252 u8 io_d; /* IO port D */ 429 u8 tmp;
430 struct i2c_msg msg[2] = {
431 {
432 .addr = anysee_tda18212_config.i2c_address,
433 .flags = 0,
434 .len = 1,
435 .buf = "\x00",
436 }, {
437 .addr = anysee_tda18212_config.i2c_address,
438 .flags = I2C_M_RD,
439 .len = 1,
440 .buf = &tmp,
441 }
442 };
253 443
254 /* check which hardware we have 444 /* Check which hardware we have.
255 We must do this call two times to get reliable values (hw bug). */ 445 * We must do this call two times to get reliable values (hw bug).
446 */
256 ret = anysee_get_hw_info(adap->dev, hw_info); 447 ret = anysee_get_hw_info(adap->dev, hw_info);
257 if (ret) 448 if (ret)
258 return ret; 449 goto error;
450
259 ret = anysee_get_hw_info(adap->dev, hw_info); 451 ret = anysee_get_hw_info(adap->dev, hw_info);
260 if (ret) 452 if (ret)
261 return ret; 453 goto error;
262 454
263 /* Meaning of these info bytes are guessed. */ 455 /* Meaning of these info bytes are guessed. */
264 info("firmware version:%d.%d.%d hardware id:%d", 456 info("firmware version:%d.%d hardware id:%d",
265 0, hw_info[1], hw_info[2], hw_info[0]); 457 hw_info[1], hw_info[2], hw_info[0]);
266 458
267 ret = anysee_read_reg(adap->dev, 0xb0, &io_d); /* IO port D */ 459 state->hw = hw_info[0];
268 if (ret)
269 return ret;
270 deb_info("%s: IO port D:%02x\n", __func__, io_d);
271
272 /* Select demod using trial and error method. */
273
274 /* Try to attach demodulator in following order:
275 model demod hw firmware
276 1. E30 MT352 02 0.2.1
277 2. E30 ZL10353 02 0.2.1
278 3. E30 Combo ZL10353 0f 0.1.2 DVB-T/C combo
279 4. E30 Plus ZL10353 06 0.1.0
280 5. E30C Plus TDA10023 0a 0.1.0 rev 0.2
281 E30C Plus TDA10023 0f 0.1.2 rev 0.4
282 E30 Combo TDA10023 0f 0.1.2 DVB-T/C combo
283 */
284
285 /* Zarlink MT352 DVB-T demod inside of Samsung DNOS404ZH102A NIM */
286 adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config,
287 &adap->dev->i2c_adap);
288 if (adap->fe != NULL) {
289 state->tuner = DVB_PLL_THOMSON_DTT7579;
290 return 0;
291 }
292 460
293 /* Zarlink ZL10353 DVB-T demod inside of Samsung DNOS404ZH103A NIM */ 461 switch (state->hw) {
294 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config, 462 case ANYSEE_HW_02: /* 2 */
295 &adap->dev->i2c_adap); 463 /* E30 */
296 if (adap->fe != NULL) {
297 state->tuner = DVB_PLL_THOMSON_DTT7579;
298 return 0;
299 }
300 464
301 /* for E30 Combo Plus DVB-T demodulator */ 465 /* attach demod */
302 if (dvb_usb_anysee_delsys) { 466 adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config,
303 ret = anysee_write_reg(adap->dev, 0xb0, 0x01); 467 &adap->dev->i2c_adap);
468 if (adap->fe)
469 break;
470
471 /* attach demod */
472 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
473 &adap->dev->i2c_adap);
474
475 break;
476 case ANYSEE_HW_507CD: /* 6 */
477 /* E30 Plus */
478
479 /* enable DVB-T demod on IOD[0] */
480 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
304 if (ret) 481 if (ret)
305 return ret; 482 goto error;
483
484 /* enable transport stream on IOA[7] */
485 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (0 << 7), 0x80);
486 if (ret)
487 goto error;
306 488
307 /* Zarlink ZL10353 DVB-T demod */ 489 /* attach demod */
308 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config, 490 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
309 &adap->dev->i2c_adap); 491 &adap->dev->i2c_adap);
310 if (adap->fe != NULL) { 492
311 state->tuner = DVB_PLL_SAMSUNG_DTOS403IH102A; 493 break;
312 return 0; 494 case ANYSEE_HW_507DC: /* 10 */
495 /* E30 C Plus */
496
497 /* enable DVB-C demod on IOD[0] */
498 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
499 if (ret)
500 goto error;
501
502 /* attach demod */
503 adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config,
504 &adap->dev->i2c_adap, 0x48);
505
506 break;
507 case ANYSEE_HW_507SI: /* 11 */
508 /* E30 S2 Plus */
509
510 /* enable DVB-S/S2 demod on IOD[0] */
511 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
512 if (ret)
513 goto error;
514
515 /* attach demod */
516 adap->fe = dvb_attach(cx24116_attach, &anysee_cx24116_config,
517 &adap->dev->i2c_adap);
518
519 break;
520 case ANYSEE_HW_507FA: /* 15 */
521 /* E30 Combo Plus */
522 /* E30 C Plus */
523
524 /* enable tuner on IOE[4] */
525 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
526 if (ret)
527 goto error;
528
529 /* probe TDA18212 */
530 tmp = 0;
531 ret = i2c_transfer(&adap->dev->i2c_adap, msg, 2);
532 if (ret == 2 && tmp == 0xc7)
533 deb_info("%s: TDA18212 found\n", __func__);
534 else
535 tmp = 0;
536
537 /* disable tuner on IOE[4] */
538 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
539 if (ret)
540 goto error;
541
542 if (dvb_usb_anysee_delsys) {
543 /* disable DVB-C demod on IOD[5] */
544 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
545 0x20);
546 if (ret)
547 goto error;
548
549 /* enable DVB-T demod on IOD[0] */
550 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
551 0x01);
552 if (ret)
553 goto error;
554
555 /* attach demod */
556 if (tmp == 0xc7) {
557 /* TDA18212 config */
558 adap->fe = dvb_attach(zl10353_attach,
559 &anysee_zl10353_tda18212_config2,
560 &adap->dev->i2c_adap);
561 } else {
562 /* PLL config */
563 adap->fe = dvb_attach(zl10353_attach,
564 &anysee_zl10353_config,
565 &adap->dev->i2c_adap);
566 }
567 } else {
568 /* disable DVB-T demod on IOD[0] */
569 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),
570 0x01);
571 if (ret)
572 goto error;
573
574 /* enable DVB-C demod on IOD[5] */
575 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
576 0x20);
577 if (ret)
578 goto error;
579
580 /* attach demod */
581 if (tmp == 0xc7) {
582 /* TDA18212 config */
583 adap->fe = dvb_attach(tda10023_attach,
584 &anysee_tda10023_tda18212_config,
585 &adap->dev->i2c_adap, 0x48);
586 } else {
587 /* PLL config */
588 adap->fe = dvb_attach(tda10023_attach,
589 &anysee_tda10023_config,
590 &adap->dev->i2c_adap, 0x48);
591 }
313 } 592 }
314 }
315 593
316 /* connect demod on IO port D for TDA10023 & ZL10353 */ 594 break;
317 ret = anysee_write_reg(adap->dev, 0xb0, 0x25); 595 case ANYSEE_HW_508TC: /* 18 */
318 if (ret) 596 /* E7 TC */
319 return ret;
320 597
321 /* Zarlink ZL10353 DVB-T demod inside of Samsung DNOS404ZH103A NIM */ 598 /* enable transport stream on IOA[7] */
322 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config, 599 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
323 &adap->dev->i2c_adap); 600 if (ret)
324 if (adap->fe != NULL) { 601 goto error;
325 state->tuner = DVB_PLL_THOMSON_DTT7579; 602
326 return 0; 603 if (dvb_usb_anysee_delsys) {
327 } 604 /* disable DVB-C demod on IOD[5] */
605 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
606 0x20);
607 if (ret)
608 goto error;
609
610 /* enable DVB-T demod on IOD[6] */
611 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),
612 0x40);
613 if (ret)
614 goto error;
615
616 /* enable IF route on IOE[0] */
617 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
618 0x01);
619 if (ret)
620 goto error;
621
622 /* attach demod */
623 adap->fe = dvb_attach(zl10353_attach,
624 &anysee_zl10353_tda18212_config,
625 &adap->dev->i2c_adap);
626 } else {
627 /* disable DVB-T demod on IOD[6] */
628 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
629 0x40);
630 if (ret)
631 goto error;
632
633 /* enable DVB-C demod on IOD[5] */
634 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
635 0x20);
636 if (ret)
637 goto error;
638
639 /* enable IF route on IOE[0] */
640 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
641 0x01);
642 if (ret)
643 goto error;
644
645 /* attach demod */
646 adap->fe = dvb_attach(tda10023_attach,
647 &anysee_tda10023_tda18212_config,
648 &adap->dev->i2c_adap, 0x48);
649 }
328 650
329 /* IO port E - E30C rev 0.4 board requires this */ 651 break;
330 ret = anysee_write_reg(adap->dev, 0xb1, 0xa7); 652 case ANYSEE_HW_508S2: /* 19 */
331 if (ret) 653 /* E7 S2 */
332 return ret;
333 654
334 /* Philips TDA10023 DVB-C demod */ 655 /* enable transport stream on IOA[7] */
335 adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config, 656 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
336 &adap->dev->i2c_adap, 0x48); 657 if (ret)
337 if (adap->fe != NULL) { 658 goto error;
338 state->tuner = DVB_PLL_SAMSUNG_DTOS403IH102A;
339 return 0;
340 }
341 659
342 /* return IO port D to init value for safe */ 660 /* enable DVB-S/S2 demod on IOE[5] */
343 ret = anysee_write_reg(adap->dev, 0xb0, io_d); 661 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);
344 if (ret) 662 if (ret)
345 return ret; 663 goto error;
346 664
347 err("Unknown Anysee version: %02x %02x %02x. "\ 665 /* attach demod */
348 "Please report the <linux-dvb@linuxtv.org>.", 666 adap->fe = dvb_attach(stv0900_attach, &anysee_stv0900_config,
349 hw_info[0], hw_info[1], hw_info[2]); 667 &adap->dev->i2c_adap, 0);
350 668
351 return -ENODEV; 669 break;
670 }
671
672 if (!adap->fe) {
673 /* we have no frontend :-( */
674 ret = -ENODEV;
675 err("Unsupported Anysee version. " \
676 "Please report the <linux-media@vger.kernel.org>.");
677 }
678error:
679 return ret;
352} 680}
353 681
354static int anysee_tuner_attach(struct dvb_usb_adapter *adap) 682static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
355{ 683{
356 struct anysee_state *state = adap->dev->priv; 684 struct anysee_state *state = adap->dev->priv;
357 deb_info("%s: \n", __func__); 685 struct dvb_frontend *fe;
358 686 int ret;
359 switch (state->tuner) { 687 deb_info("%s:\n", __func__);
360 case DVB_PLL_THOMSON_DTT7579: 688
361 /* Thomson dtt7579 (not sure) PLL inside of: 689 switch (state->hw) {
362 Samsung DNOS404ZH102A NIM 690 case ANYSEE_HW_02: /* 2 */
363 Samsung DNOS404ZH103A NIM */ 691 /* E30 */
364 dvb_attach(dvb_pll_attach, adap->fe, 0x61, 692
365 NULL, DVB_PLL_THOMSON_DTT7579); 693 /* attach tuner */
694 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),
695 NULL, DVB_PLL_THOMSON_DTT7579);
696
697 break;
698 case ANYSEE_HW_507CD: /* 6 */
699 /* E30 Plus */
700
701 /* attach tuner */
702 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),
703 &adap->dev->i2c_adap, DVB_PLL_THOMSON_DTT7579);
704
705 break;
706 case ANYSEE_HW_507DC: /* 10 */
707 /* E30 C Plus */
708
709 /* attach tuner */
710 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),
711 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
712
713 break;
714 case ANYSEE_HW_507SI: /* 11 */
715 /* E30 S2 Plus */
716
717 /* attach LNB controller */
718 fe = dvb_attach(isl6423_attach, adap->fe, &adap->dev->i2c_adap,
719 &anysee_isl6423_config);
720
721 break;
722 case ANYSEE_HW_507FA: /* 15 */
723 /* E30 Combo Plus */
724 /* E30 C Plus */
725
726 if (dvb_usb_anysee_delsys) {
727 /* enable DVB-T tuner on IOE[0] */
728 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
729 0x01);
730 if (ret)
731 goto error;
732 } else {
733 /* enable DVB-C tuner on IOE[0] */
734 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
735 0x01);
736 if (ret)
737 goto error;
738 }
739
740 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
741 * fails attach old simple PLL. */
742
743 /* enable tuner on IOE[4] */
744 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
745 if (ret)
746 goto error;
747
748 /* attach tuner */
749 fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,
750 &anysee_tda18212_config);
751 if (fe)
752 break;
753
754 /* disable tuner on IOE[4] */
755 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
756 if (ret)
757 goto error;
758
759 /* attach tuner */
760 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),
761 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
762
763 break;
764 case ANYSEE_HW_508TC: /* 18 */
765 /* E7 TC */
766
767 /* enable tuner on IOE[4] */
768 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
769 if (ret)
770 goto error;
771
772 /* attach tuner */
773 fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,
774 &anysee_tda18212_config);
775
366 break; 776 break;
367 case DVB_PLL_SAMSUNG_DTOS403IH102A: 777 case ANYSEE_HW_508S2: /* 19 */
368 /* Unknown PLL inside of Samsung DTOS403IH102A tuner module */ 778 /* E7 S2 */
369 dvb_attach(dvb_pll_attach, adap->fe, 0xc0, 779
370 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A); 780 /* attach tuner */
781 fe = dvb_attach(stv6110_attach, adap->fe,
782 &anysee_stv6110_config, &adap->dev->i2c_adap);
783
784 if (fe) {
785 /* attach LNB controller */
786 fe = dvb_attach(isl6423_attach, adap->fe,
787 &adap->dev->i2c_adap, &anysee_isl6423_config);
788 }
789
371 break; 790 break;
791 default:
792 fe = NULL;
372 } 793 }
373 794
374 return 0; 795 if (fe)
796 ret = 0;
797 else
798 ret = -ENODEV;
799
800error:
801 return ret;
375} 802}
376 803
377static int anysee_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 804static int anysee_rc_query(struct dvb_usb_device *d)
378{ 805{
379 u8 buf[] = {CMD_GET_IR_CODE}; 806 u8 buf[] = {CMD_GET_IR_CODE};
380 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map;
381 u8 ircode[2]; 807 u8 ircode[2];
382 int i, ret; 808 int ret;
383 809
384 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &ircode[0], 2); 810 /* Remote controller is basic NEC using address byte 0x08.
811 Anysee device RC query returns only two bytes, status and code,
812 address byte is dropped. Also it does not return any value for
813 NEC RCs having address byte other than 0x08. Due to that, we
814 cannot use that device as standard NEC receiver.
815 It could be possible make hack which reads whole code directly
816 from device memory... */
817
818 ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));
385 if (ret) 819 if (ret)
386 return ret; 820 return ret;
387 821
388 *event = 0; 822 if (ircode[0]) {
389 *state = REMOTE_NO_KEY_PRESSED; 823 deb_rc("%s: key pressed %02x\n", __func__, ircode[1]);
390 824 rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0);
391 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) {
392 if (rc5_custom(&keymap[i]) == ircode[0] &&
393 rc5_data(&keymap[i]) == ircode[1]) {
394 *event = keymap[i].keycode;
395 *state = REMOTE_KEY_PRESSED;
396 return 0;
397 }
398 } 825 }
826
399 return 0; 827 return 0;
400} 828}
401 829
402static struct ir_scancode ir_codes_anysee_table[] = {
403 { 0x0100, KEY_0 },
404 { 0x0101, KEY_1 },
405 { 0x0102, KEY_2 },
406 { 0x0103, KEY_3 },
407 { 0x0104, KEY_4 },
408 { 0x0105, KEY_5 },
409 { 0x0106, KEY_6 },
410 { 0x0107, KEY_7 },
411 { 0x0108, KEY_8 },
412 { 0x0109, KEY_9 },
413 { 0x010a, KEY_POWER },
414 { 0x010b, KEY_DOCUMENTS }, /* * */
415 { 0x0119, KEY_FAVORITES },
416 { 0x0120, KEY_SLEEP },
417 { 0x0121, KEY_MODE }, /* 4:3 / 16:9 select */
418 { 0x0122, KEY_ZOOM },
419 { 0x0147, KEY_TEXT },
420 { 0x0116, KEY_TV }, /* TV / radio select */
421 { 0x011e, KEY_LANGUAGE }, /* Second Audio Program */
422 { 0x011a, KEY_SUBTITLE },
423 { 0x011b, KEY_CAMERA }, /* screenshot */
424 { 0x0142, KEY_MUTE },
425 { 0x010e, KEY_MENU },
426 { 0x010f, KEY_EPG },
427 { 0x0117, KEY_INFO },
428 { 0x0110, KEY_EXIT },
429 { 0x0113, KEY_VOLUMEUP },
430 { 0x0112, KEY_VOLUMEDOWN },
431 { 0x0111, KEY_CHANNELUP },
432 { 0x0114, KEY_CHANNELDOWN },
433 { 0x0115, KEY_OK },
434 { 0x011d, KEY_RED },
435 { 0x011f, KEY_GREEN },
436 { 0x011c, KEY_YELLOW },
437 { 0x0144, KEY_BLUE },
438 { 0x010c, KEY_SHUFFLE }, /* snapshot */
439 { 0x0148, KEY_STOP },
440 { 0x0150, KEY_PLAY },
441 { 0x0151, KEY_PAUSE },
442 { 0x0149, KEY_RECORD },
443 { 0x0118, KEY_PREVIOUS }, /* |<< */
444 { 0x010d, KEY_NEXT }, /* >>| */
445 { 0x0124, KEY_PROG1 }, /* F1 */
446 { 0x0125, KEY_PROG2 }, /* F2 */
447};
448
449/* DVB USB Driver stuff */ 830/* DVB USB Driver stuff */
450static struct dvb_usb_device_properties anysee_properties; 831static struct dvb_usb_device_properties anysee_properties;
451 832
@@ -520,11 +901,12 @@ static struct dvb_usb_device_properties anysee_properties = {
520 } 901 }
521 }, 902 },
522 903
523 .rc.legacy = { 904 .rc.core = {
524 .rc_key_map = ir_codes_anysee_table, 905 .rc_codes = RC_MAP_ANYSEE,
525 .rc_key_map_size = ARRAY_SIZE(ir_codes_anysee_table), 906 .protocol = RC_TYPE_OTHER,
907 .module_name = "anysee",
526 .rc_query = anysee_rc_query, 908 .rc_query = anysee_rc_query,
527 .rc_interval = 200, /* windows driver uses 500ms */ 909 .rc_interval = 250, /* windows driver uses 500ms */
528 }, 910 },
529 911
530 .i2c_algo = &anysee_i2c_algo, 912 .i2c_algo = &anysee_i2c_algo,
diff --git a/drivers/media/dvb/dvb-usb/anysee.h b/drivers/media/dvb/dvb-usb/anysee.h
index 7ca01ff6e13c..a7673aa1e007 100644
--- a/drivers/media/dvb/dvb-usb/anysee.h
+++ b/drivers/media/dvb/dvb-usb/anysee.h
@@ -57,10 +57,29 @@ enum cmd {
57}; 57};
58 58
59struct anysee_state { 59struct anysee_state {
60 u8 tuner; 60 u8 hw; /* PCB ID */
61 u8 seq; 61 u8 seq;
62}; 62};
63 63
64#define ANYSEE_HW_02 2 /* E30 */
65#define ANYSEE_HW_507CD 6 /* E30 Plus */
66#define ANYSEE_HW_507DC 10 /* E30 C Plus */
67#define ANYSEE_HW_507SI 11 /* E30 S2 Plus */
68#define ANYSEE_HW_507FA 15 /* E30 Combo Plus / E30 C Plus */
69#define ANYSEE_HW_508TC 18 /* E7 TC */
70#define ANYSEE_HW_508S2 19 /* E7 S2 */
71
72#define REG_IOA 0x80 /* Port A (bit addressable) */
73#define REG_IOB 0x90 /* Port B (bit addressable) */
74#define REG_IOC 0xa0 /* Port C (bit addressable) */
75#define REG_IOD 0xb0 /* Port D (bit addressable) */
76#define REG_IOE 0xb1 /* Port E (NOT bit addressable) */
77#define REG_OEA 0xb2 /* Port A Output Enable */
78#define REG_OEB 0xb3 /* Port B Output Enable */
79#define REG_OEC 0xb4 /* Port C Output Enable */
80#define REG_OED 0xb5 /* Port D Output Enable */
81#define REG_OEE 0xb6 /* Port E Output Enable */
82
64#endif 83#endif
65 84
66/*************************************************************************** 85/***************************************************************************
@@ -136,7 +155,7 @@ General reply packet(s) are always used if not own reply defined.
136---------------------------------------------------------------------------- 155----------------------------------------------------------------------------
137| 04 | 0x00 156| 04 | 0x00
138---------------------------------------------------------------------------- 157----------------------------------------------------------------------------
139| 05 | 0x01 158| 05 | data length
140---------------------------------------------------------------------------- 159----------------------------------------------------------------------------
141| 06-59 | don't care 160| 06-59 | don't care
142---------------------------------------------------------------------------- 161----------------------------------------------------------------------------
diff --git a/drivers/media/dvb/dvb-usb/au6610.c b/drivers/media/dvb/dvb-usb/au6610.c
index eb34cc3894e0..2351077ff2b3 100644
--- a/drivers/media/dvb/dvb-usb/au6610.c
+++ b/drivers/media/dvb/dvb-usb/au6610.c
@@ -33,8 +33,16 @@ static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr,
33{ 33{
34 int ret; 34 int ret;
35 u16 index; 35 u16 index;
36 u8 usb_buf[6]; /* enough for all known requests, 36 u8 *usb_buf;
37 read returns 5 and write 6 bytes */ 37
38 /*
39 * allocate enough for all known requests,
40 * read returns 5 and write 6 bytes
41 */
42 usb_buf = kmalloc(6, GFP_KERNEL);
43 if (!usb_buf)
44 return -ENOMEM;
45
38 switch (wlen) { 46 switch (wlen) {
39 case 1: 47 case 1:
40 index = wbuf[0] << 8; 48 index = wbuf[0] << 8;
@@ -45,14 +53,15 @@ static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr,
45 break; 53 break;
46 default: 54 default:
47 warn("wlen = %x, aborting.", wlen); 55 warn("wlen = %x, aborting.", wlen);
48 return -EINVAL; 56 ret = -EINVAL;
57 goto error;
49 } 58 }
50 59
51 ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), operation, 60 ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), operation,
52 USB_TYPE_VENDOR|USB_DIR_IN, addr << 1, index, 61 USB_TYPE_VENDOR|USB_DIR_IN, addr << 1, index,
53 usb_buf, sizeof(usb_buf), AU6610_USB_TIMEOUT); 62 usb_buf, 6, AU6610_USB_TIMEOUT);
54 if (ret < 0) 63 if (ret < 0)
55 return ret; 64 goto error;
56 65
57 switch (operation) { 66 switch (operation) {
58 case AU6610_REQ_I2C_READ: 67 case AU6610_REQ_I2C_READ:
@@ -60,7 +69,8 @@ static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr,
60 /* requested value is always 5th byte in buffer */ 69 /* requested value is always 5th byte in buffer */
61 rbuf[0] = usb_buf[4]; 70 rbuf[0] = usb_buf[4];
62 } 71 }
63 72error:
73 kfree(usb_buf);
64 return ret; 74 return ret;
65} 75}
66 76
diff --git a/drivers/media/dvb/dvb-usb/az6027.c b/drivers/media/dvb/dvb-usb/az6027.c
index 62c58288469f..57e2444d51ab 100644
--- a/drivers/media/dvb/dvb-usb/az6027.c
+++ b/drivers/media/dvb/dvb-usb/az6027.c
@@ -386,7 +386,7 @@ static int az6027_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
386} 386}
387 387
388/* keys for the enclosed remote control */ 388/* keys for the enclosed remote control */
389static struct ir_scancode ir_codes_az6027_table[] = { 389static struct rc_map_table rc_map_az6027_table[] = {
390 { 0x01, KEY_1 }, 390 { 0x01, KEY_1 },
391 { 0x02, KEY_2 }, 391 { 0x02, KEY_2 },
392}; 392};
@@ -1089,6 +1089,7 @@ static struct usb_device_id az6027_usb_table[] = {
1089 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_DVBS2CI_V2) }, 1089 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_DVBS2CI_V2) },
1090 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V1) }, 1090 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V1) },
1091 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V2) }, 1091 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V2) },
1092 { USB_DEVICE(USB_VID_ELGATO, USB_PID_ELGATO_EYETV_SAT) },
1092 { }, 1093 { },
1093}; 1094};
1094 1095
@@ -1126,15 +1127,15 @@ static struct dvb_usb_device_properties az6027_properties = {
1126 .read_mac_address = az6027_read_mac_addr, 1127 .read_mac_address = az6027_read_mac_addr,
1127 */ 1128 */
1128 .rc.legacy = { 1129 .rc.legacy = {
1129 .rc_key_map = ir_codes_az6027_table, 1130 .rc_map_table = rc_map_az6027_table,
1130 .rc_key_map_size = ARRAY_SIZE(ir_codes_az6027_table), 1131 .rc_map_size = ARRAY_SIZE(rc_map_az6027_table),
1131 .rc_interval = 400, 1132 .rc_interval = 400,
1132 .rc_query = az6027_rc_query, 1133 .rc_query = az6027_rc_query,
1133 }, 1134 },
1134 1135
1135 .i2c_algo = &az6027_i2c_algo, 1136 .i2c_algo = &az6027_i2c_algo,
1136 1137
1137 .num_device_descs = 5, 1138 .num_device_descs = 6,
1138 .devices = { 1139 .devices = {
1139 { 1140 {
1140 .name = "AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)", 1141 .name = "AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)",
@@ -1156,6 +1157,10 @@ static struct dvb_usb_device_properties az6027_properties = {
1156 .name = "Technisat SkyStar USB 2 HD CI", 1157 .name = "Technisat SkyStar USB 2 HD CI",
1157 .cold_ids = { &az6027_usb_table[4], NULL }, 1158 .cold_ids = { &az6027_usb_table[4], NULL },
1158 .warm_ids = { NULL }, 1159 .warm_ids = { NULL },
1160 }, {
1161 .name = "Elgato EyeTV Sat",
1162 .cold_ids = { &az6027_usb_table[5], NULL },
1163 .warm_ids = { NULL },
1159 }, 1164 },
1160 { NULL }, 1165 { NULL },
1161 } 1166 }
diff --git a/drivers/media/dvb/dvb-usb/ce6230.c b/drivers/media/dvb/dvb-usb/ce6230.c
index 3df2045b7d2d..6d1a3041540d 100644
--- a/drivers/media/dvb/dvb-usb/ce6230.c
+++ b/drivers/media/dvb/dvb-usb/ce6230.c
@@ -39,7 +39,7 @@ static int ce6230_rw_udev(struct usb_device *udev, struct req_t *req)
39 u8 requesttype; 39 u8 requesttype;
40 u16 value; 40 u16 value;
41 u16 index; 41 u16 index;
42 u8 buf[req->data_len]; 42 u8 *buf;
43 43
44 request = req->cmd; 44 request = req->cmd;
45 value = req->value; 45 value = req->value;
@@ -62,6 +62,12 @@ static int ce6230_rw_udev(struct usb_device *udev, struct req_t *req)
62 goto error; 62 goto error;
63 } 63 }
64 64
65 buf = kmalloc(req->data_len, GFP_KERNEL);
66 if (!buf) {
67 ret = -ENOMEM;
68 goto error;
69 }
70
65 if (requesttype == (USB_TYPE_VENDOR | USB_DIR_OUT)) { 71 if (requesttype == (USB_TYPE_VENDOR | USB_DIR_OUT)) {
66 /* write */ 72 /* write */
67 memcpy(buf, req->data, req->data_len); 73 memcpy(buf, req->data, req->data_len);
@@ -74,7 +80,7 @@ static int ce6230_rw_udev(struct usb_device *udev, struct req_t *req)
74 msleep(1); /* avoid I2C errors */ 80 msleep(1); /* avoid I2C errors */
75 81
76 ret = usb_control_msg(udev, pipe, request, requesttype, value, index, 82 ret = usb_control_msg(udev, pipe, request, requesttype, value, index,
77 buf, sizeof(buf), CE6230_USB_TIMEOUT); 83 buf, req->data_len, CE6230_USB_TIMEOUT);
78 84
79 ce6230_debug_dump(request, requesttype, value, index, buf, 85 ce6230_debug_dump(request, requesttype, value, index, buf,
80 req->data_len, deb_xfer); 86 req->data_len, deb_xfer);
@@ -88,6 +94,7 @@ static int ce6230_rw_udev(struct usb_device *udev, struct req_t *req)
88 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN)) 94 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
89 memcpy(req->data, buf, req->data_len); 95 memcpy(req->data, buf, req->data_len);
90 96
97 kfree(buf);
91error: 98error:
92 return ret; 99 return ret;
93} 100}
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2-core.c b/drivers/media/dvb/dvb-usb/cinergyT2-core.c
index 4f5aa83fc1fc..16f2ce2bc15a 100644
--- a/drivers/media/dvb/dvb-usb/cinergyT2-core.c
+++ b/drivers/media/dvb/dvb-usb/cinergyT2-core.c
@@ -84,7 +84,7 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
84 return 0; 84 return 0;
85} 85}
86 86
87static struct ir_scancode ir_codes_cinergyt2_table[] = { 87static struct rc_map_table rc_map_cinergyt2_table[] = {
88 { 0x0401, KEY_POWER }, 88 { 0x0401, KEY_POWER },
89 { 0x0402, KEY_1 }, 89 { 0x0402, KEY_1 },
90 { 0x0403, KEY_2 }, 90 { 0x0403, KEY_2 },
@@ -219,8 +219,8 @@ static struct dvb_usb_device_properties cinergyt2_properties = {
219 219
220 .rc.legacy = { 220 .rc.legacy = {
221 .rc_interval = 50, 221 .rc_interval = 50,
222 .rc_key_map = ir_codes_cinergyt2_table, 222 .rc_map_table = rc_map_cinergyt2_table,
223 .rc_key_map_size = ARRAY_SIZE(ir_codes_cinergyt2_table), 223 .rc_map_size = ARRAY_SIZE(rc_map_cinergyt2_table),
224 .rc_query = cinergyt2_rc_query, 224 .rc_query = cinergyt2_rc_query,
225 }, 225 },
226 226
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index cd9f362c37b2..acb5fb2d2e73 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -385,7 +385,7 @@ static int cxusb_d680_dmb_streaming_ctrl(
385 385
386static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 386static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
387{ 387{
388 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 388 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
389 u8 ircode[4]; 389 u8 ircode[4];
390 int i; 390 int i;
391 391
@@ -394,7 +394,7 @@ static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
394 *event = 0; 394 *event = 0;
395 *state = REMOTE_NO_KEY_PRESSED; 395 *state = REMOTE_NO_KEY_PRESSED;
396 396
397 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { 397 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
398 if (rc5_custom(&keymap[i]) == ircode[2] && 398 if (rc5_custom(&keymap[i]) == ircode[2] &&
399 rc5_data(&keymap[i]) == ircode[3]) { 399 rc5_data(&keymap[i]) == ircode[3]) {
400 *event = keymap[i].keycode; 400 *event = keymap[i].keycode;
@@ -410,7 +410,7 @@ static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
410static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event, 410static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
411 int *state) 411 int *state)
412{ 412{
413 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 413 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
414 u8 ircode[4]; 414 u8 ircode[4];
415 int i; 415 int i;
416 struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD, 416 struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
@@ -422,7 +422,7 @@ static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
422 if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1) 422 if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
423 return 0; 423 return 0;
424 424
425 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { 425 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
426 if (rc5_custom(&keymap[i]) == ircode[1] && 426 if (rc5_custom(&keymap[i]) == ircode[1] &&
427 rc5_data(&keymap[i]) == ircode[2]) { 427 rc5_data(&keymap[i]) == ircode[2]) {
428 *event = keymap[i].keycode; 428 *event = keymap[i].keycode;
@@ -438,7 +438,7 @@ static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
438static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event, 438static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
439 int *state) 439 int *state)
440{ 440{
441 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 441 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
442 u8 ircode[2]; 442 u8 ircode[2];
443 int i; 443 int i;
444 444
@@ -448,7 +448,7 @@ static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
448 if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0) 448 if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
449 return 0; 449 return 0;
450 450
451 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { 451 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
452 if (rc5_custom(&keymap[i]) == ircode[0] && 452 if (rc5_custom(&keymap[i]) == ircode[0] &&
453 rc5_data(&keymap[i]) == ircode[1]) { 453 rc5_data(&keymap[i]) == ircode[1]) {
454 *event = keymap[i].keycode; 454 *event = keymap[i].keycode;
@@ -461,7 +461,7 @@ static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
461 return 0; 461 return 0;
462} 462}
463 463
464static struct ir_scancode ir_codes_dvico_mce_table[] = { 464static struct rc_map_table rc_map_dvico_mce_table[] = {
465 { 0xfe02, KEY_TV }, 465 { 0xfe02, KEY_TV },
466 { 0xfe0e, KEY_MP3 }, 466 { 0xfe0e, KEY_MP3 },
467 { 0xfe1a, KEY_DVD }, 467 { 0xfe1a, KEY_DVD },
@@ -509,7 +509,7 @@ static struct ir_scancode ir_codes_dvico_mce_table[] = {
509 { 0xfe4e, KEY_POWER }, 509 { 0xfe4e, KEY_POWER },
510}; 510};
511 511
512static struct ir_scancode ir_codes_dvico_portable_table[] = { 512static struct rc_map_table rc_map_dvico_portable_table[] = {
513 { 0xfc02, KEY_SETUP }, /* Profile */ 513 { 0xfc02, KEY_SETUP }, /* Profile */
514 { 0xfc43, KEY_POWER2 }, 514 { 0xfc43, KEY_POWER2 },
515 { 0xfc06, KEY_EPG }, 515 { 0xfc06, KEY_EPG },
@@ -548,7 +548,7 @@ static struct ir_scancode ir_codes_dvico_portable_table[] = {
548 { 0xfc00, KEY_UNKNOWN }, /* HD */ 548 { 0xfc00, KEY_UNKNOWN }, /* HD */
549}; 549};
550 550
551static struct ir_scancode ir_codes_d680_dmb_table[] = { 551static struct rc_map_table rc_map_d680_dmb_table[] = {
552 { 0x0038, KEY_UNKNOWN }, /* TV/AV */ 552 { 0x0038, KEY_UNKNOWN }, /* TV/AV */
553 { 0x080c, KEY_ZOOM }, 553 { 0x080c, KEY_ZOOM },
554 { 0x0800, KEY_0 }, 554 { 0x0800, KEY_0 },
@@ -923,7 +923,7 @@ static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
923 return -EIO; 923 return -EIO;
924 924
925 /* try to determine if there is no IR decoder on the I2C bus */ 925 /* try to determine if there is no IR decoder on the I2C bus */
926 for (i = 0; adap->dev->props.rc.legacy.rc_key_map != NULL && i < 5; i++) { 926 for (i = 0; adap->dev->props.rc.legacy.rc_map_table != NULL && i < 5; i++) {
927 msleep(20); 927 msleep(20);
928 if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1) 928 if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1)
929 goto no_IR; 929 goto no_IR;
@@ -931,7 +931,7 @@ static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
931 continue; 931 continue;
932 if (ircode[2] + ircode[3] != 0xff) { 932 if (ircode[2] + ircode[3] != 0xff) {
933no_IR: 933no_IR:
934 adap->dev->props.rc.legacy.rc_key_map = NULL; 934 adap->dev->props.rc.legacy.rc_map_table = NULL;
935 info("No IR receiver detected on this device."); 935 info("No IR receiver detected on this device.");
936 break; 936 break;
937 } 937 }
@@ -1453,8 +1453,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
1453 1453
1454 .rc.legacy = { 1454 .rc.legacy = {
1455 .rc_interval = 100, 1455 .rc_interval = 100,
1456 .rc_key_map = ir_codes_dvico_portable_table, 1456 .rc_map_table = rc_map_dvico_portable_table,
1457 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1457 .rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),
1458 .rc_query = cxusb_rc_query, 1458 .rc_query = cxusb_rc_query,
1459 }, 1459 },
1460 1460
@@ -1506,8 +1506,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
1506 1506
1507 .rc.legacy = { 1507 .rc.legacy = {
1508 .rc_interval = 150, 1508 .rc_interval = 150,
1509 .rc_key_map = ir_codes_dvico_mce_table, 1509 .rc_map_table = rc_map_dvico_mce_table,
1510 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table), 1510 .rc_map_size = ARRAY_SIZE(rc_map_dvico_mce_table),
1511 .rc_query = cxusb_rc_query, 1511 .rc_query = cxusb_rc_query,
1512 }, 1512 },
1513 1513
@@ -1567,8 +1567,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
1567 1567
1568 .rc.legacy = { 1568 .rc.legacy = {
1569 .rc_interval = 100, 1569 .rc_interval = 100,
1570 .rc_key_map = ir_codes_dvico_portable_table, 1570 .rc_map_table = rc_map_dvico_portable_table,
1571 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1571 .rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),
1572 .rc_query = cxusb_rc_query, 1572 .rc_query = cxusb_rc_query,
1573 }, 1573 },
1574 1574
@@ -1619,8 +1619,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
1619 1619
1620 .rc.legacy = { 1620 .rc.legacy = {
1621 .rc_interval = 100, 1621 .rc_interval = 100,
1622 .rc_key_map = ir_codes_dvico_portable_table, 1622 .rc_map_table = rc_map_dvico_portable_table,
1623 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1623 .rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),
1624 .rc_query = cxusb_rc_query, 1624 .rc_query = cxusb_rc_query,
1625 }, 1625 },
1626 1626
@@ -1670,8 +1670,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
1670 1670
1671 .rc.legacy = { 1671 .rc.legacy = {
1672 .rc_interval = 100, 1672 .rc_interval = 100,
1673 .rc_key_map = ir_codes_dvico_mce_table, 1673 .rc_map_table = rc_map_dvico_mce_table,
1674 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table), 1674 .rc_map_size = ARRAY_SIZE(rc_map_dvico_mce_table),
1675 .rc_query = cxusb_bluebird2_rc_query, 1675 .rc_query = cxusb_bluebird2_rc_query,
1676 }, 1676 },
1677 1677
@@ -1720,8 +1720,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
1720 1720
1721 .rc.legacy = { 1721 .rc.legacy = {
1722 .rc_interval = 100, 1722 .rc_interval = 100,
1723 .rc_key_map = ir_codes_dvico_portable_table, 1723 .rc_map_table = rc_map_dvico_portable_table,
1724 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1724 .rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),
1725 .rc_query = cxusb_bluebird2_rc_query, 1725 .rc_query = cxusb_bluebird2_rc_query,
1726 }, 1726 },
1727 1727
@@ -1772,8 +1772,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_prope
1772 1772
1773 .rc.legacy = { 1773 .rc.legacy = {
1774 .rc_interval = 100, 1774 .rc_interval = 100,
1775 .rc_key_map = ir_codes_dvico_portable_table, 1775 .rc_map_table = rc_map_dvico_portable_table,
1776 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1776 .rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),
1777 .rc_query = cxusb_rc_query, 1777 .rc_query = cxusb_rc_query,
1778 }, 1778 },
1779 1779
@@ -1865,8 +1865,8 @@ struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
1865 1865
1866 .rc.legacy = { 1866 .rc.legacy = {
1867 .rc_interval = 100, 1867 .rc_interval = 100,
1868 .rc_key_map = ir_codes_dvico_mce_table, 1868 .rc_map_table = rc_map_dvico_mce_table,
1869 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table), 1869 .rc_map_size = ARRAY_SIZE(rc_map_dvico_mce_table),
1870 .rc_query = cxusb_rc_query, 1870 .rc_query = cxusb_rc_query,
1871 }, 1871 },
1872 1872
@@ -1915,8 +1915,8 @@ static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
1915 1915
1916 .rc.legacy = { 1916 .rc.legacy = {
1917 .rc_interval = 100, 1917 .rc_interval = 100,
1918 .rc_key_map = ir_codes_d680_dmb_table, 1918 .rc_map_table = rc_map_d680_dmb_table,
1919 .rc_key_map_size = ARRAY_SIZE(ir_codes_d680_dmb_table), 1919 .rc_map_size = ARRAY_SIZE(rc_map_d680_dmb_table),
1920 .rc_query = cxusb_d680_dmb_rc_query, 1920 .rc_query = cxusb_d680_dmb_rc_query,
1921 }, 1921 },
1922 1922
@@ -1966,8 +1966,8 @@ static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
1966 1966
1967 .rc.legacy = { 1967 .rc.legacy = {
1968 .rc_interval = 100, 1968 .rc_interval = 100,
1969 .rc_key_map = ir_codes_d680_dmb_table, 1969 .rc_map_table = rc_map_d680_dmb_table,
1970 .rc_key_map_size = ARRAY_SIZE(ir_codes_d680_dmb_table), 1970 .rc_map_size = ARRAY_SIZE(rc_map_d680_dmb_table),
1971 .rc_query = cxusb_d680_dmb_rc_query, 1971 .rc_query = cxusb_d680_dmb_rc_query,
1972 }, 1972 },
1973 1973
diff --git a/drivers/media/dvb/dvb-usb/dib0700.h b/drivers/media/dvb/dvb-usb/dib0700.h
index c2c9d236ec7e..9bd6d51b3b93 100644
--- a/drivers/media/dvb/dvb-usb/dib0700.h
+++ b/drivers/media/dvb/dvb-usb/dib0700.h
@@ -32,6 +32,7 @@ extern int dvb_usb_dib0700_debug;
32 // 1 Byte: 4MSB(1 = enable streaming, 0 = disable streaming) 4LSB(Video Mode: 0 = MPEG2 188Bytes, 1 = Analog) 32 // 1 Byte: 4MSB(1 = enable streaming, 0 = disable streaming) 4LSB(Video Mode: 0 = MPEG2 188Bytes, 1 = Analog)
33 // 2 Byte: MPEG2 mode: 4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1) 33 // 2 Byte: MPEG2 mode: 4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1)
34 // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines) 4LSB( " " ) 34 // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines) 4LSB( " " )
35#define REQUEST_SET_I2C_PARAM 0x10
35#define REQUEST_SET_RC 0x11 36#define REQUEST_SET_RC 0x11
36#define REQUEST_NEW_I2C_READ 0x12 37#define REQUEST_NEW_I2C_READ 0x12
37#define REQUEST_NEW_I2C_WRITE 0x13 38#define REQUEST_NEW_I2C_WRITE 0x13
@@ -45,8 +46,9 @@ struct dib0700_state {
45 u8 is_dib7000pc; 46 u8 is_dib7000pc;
46 u8 fw_use_new_i2c_api; 47 u8 fw_use_new_i2c_api;
47 u8 disable_streaming_master_mode; 48 u8 disable_streaming_master_mode;
48 u32 fw_version; 49 u32 fw_version;
49 u32 nb_packet_buffer_size; 50 u32 nb_packet_buffer_size;
51 u8 buf[255];
50}; 52};
51 53
52extern int dib0700_get_version(struct dvb_usb_device *d, u32 *hwversion, 54extern int dib0700_get_version(struct dvb_usb_device *d, u32 *hwversion,
@@ -60,7 +62,8 @@ extern int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff);
60extern struct i2c_algorithm dib0700_i2c_algo; 62extern struct i2c_algorithm dib0700_i2c_algo;
61extern int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props, 63extern int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props,
62 struct dvb_usb_device_description **desc, int *cold); 64 struct dvb_usb_device_description **desc, int *cold);
63extern int dib0700_change_protocol(void *priv, u64 ir_type); 65extern int dib0700_change_protocol(struct rc_dev *dev, u64 rc_type);
66extern int dib0700_set_i2c_speed(struct dvb_usb_device *d, u16 scl_kHz);
64 67
65extern int dib0700_device_count; 68extern int dib0700_device_count;
66extern int dvb_usb_dib0700_ir_proto; 69extern int dvb_usb_dib0700_ir_proto;
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
index 48397f103d32..5eb91b4f8fd0 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -27,19 +27,25 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
27int dib0700_get_version(struct dvb_usb_device *d, u32 *hwversion, 27int dib0700_get_version(struct dvb_usb_device *d, u32 *hwversion,
28 u32 *romversion, u32 *ramversion, u32 *fwtype) 28 u32 *romversion, u32 *ramversion, u32 *fwtype)
29{ 29{
30 u8 b[16]; 30 struct dib0700_state *st = d->priv;
31 int ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), 31 int ret;
32
33 ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
32 REQUEST_GET_VERSION, 34 REQUEST_GET_VERSION,
33 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, 35 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
34 b, sizeof(b), USB_CTRL_GET_TIMEOUT); 36 st->buf, 16, USB_CTRL_GET_TIMEOUT);
35 if (hwversion != NULL) 37 if (hwversion != NULL)
36 *hwversion = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]; 38 *hwversion = (st->buf[0] << 24) | (st->buf[1] << 16) |
39 (st->buf[2] << 8) | st->buf[3];
37 if (romversion != NULL) 40 if (romversion != NULL)
38 *romversion = (b[4] << 24) | (b[5] << 16) | (b[6] << 8) | b[7]; 41 *romversion = (st->buf[4] << 24) | (st->buf[5] << 16) |
42 (st->buf[6] << 8) | st->buf[7];
39 if (ramversion != NULL) 43 if (ramversion != NULL)
40 *ramversion = (b[8] << 24) | (b[9] << 16) | (b[10] << 8) | b[11]; 44 *ramversion = (st->buf[8] << 24) | (st->buf[9] << 16) |
45 (st->buf[10] << 8) | st->buf[11];
41 if (fwtype != NULL) 46 if (fwtype != NULL)
42 *fwtype = (b[12] << 24) | (b[13] << 16) | (b[14] << 8) | b[15]; 47 *fwtype = (st->buf[12] << 24) | (st->buf[13] << 16) |
48 (st->buf[14] << 8) | st->buf[15];
43 return ret; 49 return ret;
44} 50}
45 51
@@ -101,24 +107,31 @@ int dib0700_ctrl_rd(struct dvb_usb_device *d, u8 *tx, u8 txlen, u8 *rx, u8 rxlen
101 107
102int dib0700_set_gpio(struct dvb_usb_device *d, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val) 108int dib0700_set_gpio(struct dvb_usb_device *d, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val)
103{ 109{
104 u8 buf[3] = { REQUEST_SET_GPIO, gpio, ((gpio_dir & 0x01) << 7) | ((gpio_val & 0x01) << 6) }; 110 struct dib0700_state *st = d->priv;
105 return dib0700_ctrl_wr(d, buf, sizeof(buf)); 111 s16 ret;
112
113 st->buf[0] = REQUEST_SET_GPIO;
114 st->buf[1] = gpio;
115 st->buf[2] = ((gpio_dir & 0x01) << 7) | ((gpio_val & 0x01) << 6);
116
117 ret = dib0700_ctrl_wr(d, st->buf, 3);
118
119 return ret;
106} 120}
107 121
108static int dib0700_set_usb_xfer_len(struct dvb_usb_device *d, u16 nb_ts_packets) 122static int dib0700_set_usb_xfer_len(struct dvb_usb_device *d, u16 nb_ts_packets)
109{ 123{
110 struct dib0700_state *st = d->priv; 124 struct dib0700_state *st = d->priv;
111 u8 b[3];
112 int ret; 125 int ret;
113 126
114 if (st->fw_version >= 0x10201) { 127 if (st->fw_version >= 0x10201) {
115 b[0] = REQUEST_SET_USB_XFER_LEN; 128 st->buf[0] = REQUEST_SET_USB_XFER_LEN;
116 b[1] = (nb_ts_packets >> 8) & 0xff; 129 st->buf[1] = (nb_ts_packets >> 8) & 0xff;
117 b[2] = nb_ts_packets & 0xff; 130 st->buf[2] = nb_ts_packets & 0xff;
118 131
119 deb_info("set the USB xfer len to %i Ts packet\n", nb_ts_packets); 132 deb_info("set the USB xfer len to %i Ts packet\n", nb_ts_packets);
120 133
121 ret = dib0700_ctrl_wr(d, b, sizeof(b)); 134 ret = dib0700_ctrl_wr(d, st->buf, 3);
122 } else { 135 } else {
123 deb_info("this firmware does not allow to change the USB xfer len\n"); 136 deb_info("this firmware does not allow to change the USB xfer len\n");
124 ret = -EIO; 137 ret = -EIO;
@@ -137,11 +150,11 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
137 properly support i2c read calls not preceded by a write */ 150 properly support i2c read calls not preceded by a write */
138 151
139 struct dvb_usb_device *d = i2c_get_adapdata(adap); 152 struct dvb_usb_device *d = i2c_get_adapdata(adap);
153 struct dib0700_state *st = d->priv;
140 uint8_t bus_mode = 1; /* 0=eeprom bus, 1=frontend bus */ 154 uint8_t bus_mode = 1; /* 0=eeprom bus, 1=frontend bus */
141 uint8_t gen_mode = 0; /* 0=master i2c, 1=gpio i2c */ 155 uint8_t gen_mode = 0; /* 0=master i2c, 1=gpio i2c */
142 uint8_t en_start = 0; 156 uint8_t en_start = 0;
143 uint8_t en_stop = 0; 157 uint8_t en_stop = 0;
144 uint8_t buf[255]; /* TBV: malloc ? */
145 int result, i; 158 int result, i;
146 159
147 /* Ensure nobody else hits the i2c bus while we're sending our 160 /* Ensure nobody else hits the i2c bus while we're sending our
@@ -186,7 +199,7 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
186 msg[i].len, 199 msg[i].len,
187 USB_CTRL_GET_TIMEOUT); 200 USB_CTRL_GET_TIMEOUT);
188 if (result < 0) { 201 if (result < 0) {
189 err("i2c read error (status = %d)\n", result); 202 deb_info("i2c read error (status = %d)\n", result);
190 break; 203 break;
191 } 204 }
192 205
@@ -195,27 +208,27 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
195 208
196 } else { 209 } else {
197 /* Write request */ 210 /* Write request */
198 buf[0] = REQUEST_NEW_I2C_WRITE; 211 st->buf[0] = REQUEST_NEW_I2C_WRITE;
199 buf[1] = msg[i].addr << 1; 212 st->buf[1] = msg[i].addr << 1;
200 buf[2] = (en_start << 7) | (en_stop << 6) | 213 st->buf[2] = (en_start << 7) | (en_stop << 6) |
201 (msg[i].len & 0x3F); 214 (msg[i].len & 0x3F);
202 /* I2C ctrl + FE bus; */ 215 /* I2C ctrl + FE bus; */
203 buf[3] = ((gen_mode << 6) & 0xC0) | 216 st->buf[3] = ((gen_mode << 6) & 0xC0) |
204 ((bus_mode << 4) & 0x30); 217 ((bus_mode << 4) & 0x30);
205 /* The Actual i2c payload */ 218 /* The Actual i2c payload */
206 memcpy(&buf[4], msg[i].buf, msg[i].len); 219 memcpy(&st->buf[4], msg[i].buf, msg[i].len);
207 220
208 deb_data(">>> "); 221 deb_data(">>> ");
209 debug_dump(buf, msg[i].len + 4, deb_data); 222 debug_dump(st->buf, msg[i].len + 4, deb_data);
210 223
211 result = usb_control_msg(d->udev, 224 result = usb_control_msg(d->udev,
212 usb_sndctrlpipe(d->udev, 0), 225 usb_sndctrlpipe(d->udev, 0),
213 REQUEST_NEW_I2C_WRITE, 226 REQUEST_NEW_I2C_WRITE,
214 USB_TYPE_VENDOR | USB_DIR_OUT, 227 USB_TYPE_VENDOR | USB_DIR_OUT,
215 0, 0, buf, msg[i].len + 4, 228 0, 0, st->buf, msg[i].len + 4,
216 USB_CTRL_GET_TIMEOUT); 229 USB_CTRL_GET_TIMEOUT);
217 if (result < 0) { 230 if (result < 0) {
218 err("i2c write error (status = %d)\n", result); 231 deb_info("i2c write error (status = %d)\n", result);
219 break; 232 break;
220 } 233 }
221 } 234 }
@@ -231,27 +244,29 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
231 struct i2c_msg *msg, int num) 244 struct i2c_msg *msg, int num)
232{ 245{
233 struct dvb_usb_device *d = i2c_get_adapdata(adap); 246 struct dvb_usb_device *d = i2c_get_adapdata(adap);
247 struct dib0700_state *st = d->priv;
234 int i,len; 248 int i,len;
235 u8 buf[255];
236 249
237 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 250 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
238 return -EAGAIN; 251 return -EAGAIN;
239 252
240 for (i = 0; i < num; i++) { 253 for (i = 0; i < num; i++) {
241 /* fill in the address */ 254 /* fill in the address */
242 buf[1] = msg[i].addr << 1; 255 st->buf[1] = msg[i].addr << 1;
243 /* fill the buffer */ 256 /* fill the buffer */
244 memcpy(&buf[2], msg[i].buf, msg[i].len); 257 memcpy(&st->buf[2], msg[i].buf, msg[i].len);
245 258
246 /* write/read request */ 259 /* write/read request */
247 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { 260 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
248 buf[0] = REQUEST_I2C_READ; 261 st->buf[0] = REQUEST_I2C_READ;
249 buf[1] |= 1; 262 st->buf[1] |= 1;
250 263
251 /* special thing in the current firmware: when length is zero the read-failed */ 264 /* special thing in the current firmware: when length is zero the read-failed */
252 if ((len = dib0700_ctrl_rd(d, buf, msg[i].len + 2, msg[i+1].buf, msg[i+1].len)) <= 0) { 265 len = dib0700_ctrl_rd(d, st->buf, msg[i].len + 2,
266 msg[i+1].buf, msg[i+1].len);
267 if (len <= 0) {
253 deb_info("I2C read failed on address 0x%02x\n", 268 deb_info("I2C read failed on address 0x%02x\n",
254 msg[i].addr); 269 msg[i].addr);
255 break; 270 break;
256 } 271 }
257 272
@@ -259,13 +274,13 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
259 274
260 i++; 275 i++;
261 } else { 276 } else {
262 buf[0] = REQUEST_I2C_WRITE; 277 st->buf[0] = REQUEST_I2C_WRITE;
263 if (dib0700_ctrl_wr(d, buf, msg[i].len + 2) < 0) 278 if (dib0700_ctrl_wr(d, st->buf, msg[i].len + 2) < 0)
264 break; 279 break;
265 } 280 }
266 } 281 }
267
268 mutex_unlock(&d->i2c_mutex); 282 mutex_unlock(&d->i2c_mutex);
283
269 return i; 284 return i;
270} 285}
271 286
@@ -297,15 +312,23 @@ struct i2c_algorithm dib0700_i2c_algo = {
297int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props, 312int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props,
298 struct dvb_usb_device_description **desc, int *cold) 313 struct dvb_usb_device_description **desc, int *cold)
299{ 314{
300 u8 b[16]; 315 s16 ret;
301 s16 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev,0), 316 u8 *b;
317
318 b = kmalloc(16, GFP_KERNEL);
319 if (!b)
320 return -ENOMEM;
321
322
323 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
302 REQUEST_GET_VERSION, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, b, 16, USB_CTRL_GET_TIMEOUT); 324 REQUEST_GET_VERSION, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, b, 16, USB_CTRL_GET_TIMEOUT);
303 325
304 deb_info("FW GET_VERSION length: %d\n",ret); 326 deb_info("FW GET_VERSION length: %d\n",ret);
305 327
306 *cold = ret <= 0; 328 *cold = ret <= 0;
307
308 deb_info("cold: %d\n", *cold); 329 deb_info("cold: %d\n", *cold);
330
331 kfree(b);
309 return 0; 332 return 0;
310} 333}
311 334
@@ -313,21 +336,53 @@ static int dib0700_set_clock(struct dvb_usb_device *d, u8 en_pll,
313 u8 pll_src, u8 pll_range, u8 clock_gpio3, u16 pll_prediv, 336 u8 pll_src, u8 pll_range, u8 clock_gpio3, u16 pll_prediv,
314 u16 pll_loopdiv, u16 free_div, u16 dsuScaler) 337 u16 pll_loopdiv, u16 free_div, u16 dsuScaler)
315{ 338{
316 u8 b[10]; 339 struct dib0700_state *st = d->priv;
317 b[0] = REQUEST_SET_CLOCK; 340 s16 ret;
318 b[1] = (en_pll << 7) | (pll_src << 6) | (pll_range << 5) | (clock_gpio3 << 4); 341
319 b[2] = (pll_prediv >> 8) & 0xff; // MSB 342 st->buf[0] = REQUEST_SET_CLOCK;
320 b[3] = pll_prediv & 0xff; // LSB 343 st->buf[1] = (en_pll << 7) | (pll_src << 6) |
321 b[4] = (pll_loopdiv >> 8) & 0xff; // MSB 344 (pll_range << 5) | (clock_gpio3 << 4);
322 b[5] = pll_loopdiv & 0xff; // LSB 345 st->buf[2] = (pll_prediv >> 8) & 0xff; /* MSB */
323 b[6] = (free_div >> 8) & 0xff; // MSB 346 st->buf[3] = pll_prediv & 0xff; /* LSB */
324 b[7] = free_div & 0xff; // LSB 347 st->buf[4] = (pll_loopdiv >> 8) & 0xff; /* MSB */
325 b[8] = (dsuScaler >> 8) & 0xff; // MSB 348 st->buf[5] = pll_loopdiv & 0xff; /* LSB */
326 b[9] = dsuScaler & 0xff; // LSB 349 st->buf[6] = (free_div >> 8) & 0xff; /* MSB */
327 350 st->buf[7] = free_div & 0xff; /* LSB */
328 return dib0700_ctrl_wr(d, b, 10); 351 st->buf[8] = (dsuScaler >> 8) & 0xff; /* MSB */
352 st->buf[9] = dsuScaler & 0xff; /* LSB */
353
354 ret = dib0700_ctrl_wr(d, st->buf, 10);
355
356 return ret;
329} 357}
330 358
359int dib0700_set_i2c_speed(struct dvb_usb_device *d, u16 scl_kHz)
360{
361 struct dib0700_state *st = d->priv;
362 u16 divider;
363
364 if (scl_kHz == 0)
365 return -EINVAL;
366
367 st->buf[0] = REQUEST_SET_I2C_PARAM;
368 divider = (u16) (30000 / scl_kHz);
369 st->buf[1] = 0;
370 st->buf[2] = (u8) (divider >> 8);
371 st->buf[3] = (u8) (divider & 0xff);
372 divider = (u16) (72000 / scl_kHz);
373 st->buf[4] = (u8) (divider >> 8);
374 st->buf[5] = (u8) (divider & 0xff);
375 divider = (u16) (72000 / scl_kHz); /* clock: 72MHz */
376 st->buf[6] = (u8) (divider >> 8);
377 st->buf[7] = (u8) (divider & 0xff);
378
379 deb_info("setting I2C speed: %04x %04x %04x (%d kHz).",
380 (st->buf[2] << 8) | (st->buf[3]), (st->buf[4] << 8) |
381 st->buf[5], (st->buf[6] << 8) | st->buf[7], scl_kHz);
382 return dib0700_ctrl_wr(d, st->buf, 8);
383}
384
385
331int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3) 386int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3)
332{ 387{
333 switch (clk_MHz) { 388 switch (clk_MHz) {
@@ -339,32 +394,45 @@ int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3)
339 394
340static int dib0700_jumpram(struct usb_device *udev, u32 address) 395static int dib0700_jumpram(struct usb_device *udev, u32 address)
341{ 396{
342 int ret, actlen; 397 int ret = 0, actlen;
343 u8 buf[8] = { REQUEST_JUMPRAM, 0, 0, 0, 398 u8 *buf;
344 (address >> 24) & 0xff, 399
345 (address >> 16) & 0xff, 400 buf = kmalloc(8, GFP_KERNEL);
346 (address >> 8) & 0xff, 401 if (!buf)
347 address & 0xff }; 402 return -ENOMEM;
403 buf[0] = REQUEST_JUMPRAM;
404 buf[1] = 0;
405 buf[2] = 0;
406 buf[3] = 0;
407 buf[4] = (address >> 24) & 0xff;
408 buf[5] = (address >> 16) & 0xff;
409 buf[6] = (address >> 8) & 0xff;
410 buf[7] = address & 0xff;
348 411
349 if ((ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x01),buf,8,&actlen,1000)) < 0) { 412 if ((ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x01),buf,8,&actlen,1000)) < 0) {
350 deb_fw("jumpram to 0x%x failed\n",address); 413 deb_fw("jumpram to 0x%x failed\n",address);
351 return ret; 414 goto out;
352 } 415 }
353 if (actlen != 8) { 416 if (actlen != 8) {
354 deb_fw("jumpram to 0x%x failed\n",address); 417 deb_fw("jumpram to 0x%x failed\n",address);
355 return -EIO; 418 ret = -EIO;
419 goto out;
356 } 420 }
357 return 0; 421out:
422 kfree(buf);
423 return ret;
358} 424}
359 425
360int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw) 426int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw)
361{ 427{
362 struct hexline hx; 428 struct hexline hx;
363 int pos = 0, ret, act_len, i, adap_num; 429 int pos = 0, ret, act_len, i, adap_num;
364 u8 b[16]; 430 u8 *buf;
365 u32 fw_version; 431 u32 fw_version;
366 432
367 u8 buf[260]; 433 buf = kmalloc(260, GFP_KERNEL);
434 if (!buf)
435 return -ENOMEM;
368 436
369 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) { 437 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
370 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n", 438 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",
@@ -386,7 +454,7 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
386 454
387 if (ret < 0) { 455 if (ret < 0) {
388 err("firmware download failed at %d with %d",pos,ret); 456 err("firmware download failed at %d with %d",pos,ret);
389 return ret; 457 goto out;
390 } 458 }
391 } 459 }
392 460
@@ -407,8 +475,8 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
407 usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 475 usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
408 REQUEST_GET_VERSION, 476 REQUEST_GET_VERSION,
409 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, 477 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
410 b, sizeof(b), USB_CTRL_GET_TIMEOUT); 478 buf, 16, USB_CTRL_GET_TIMEOUT);
411 fw_version = (b[8] << 24) | (b[9] << 16) | (b[10] << 8) | b[11]; 479 fw_version = (buf[8] << 24) | (buf[9] << 16) | (buf[10] << 8) | buf[11];
412 480
413 /* set the buffer size - DVB-USB is allocating URB buffers 481 /* set the buffer size - DVB-USB is allocating URB buffers
414 * only after the firwmare download was successful */ 482 * only after the firwmare download was successful */
@@ -426,14 +494,14 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
426 } 494 }
427 } 495 }
428 } 496 }
429 497out:
498 kfree(buf);
430 return ret; 499 return ret;
431} 500}
432 501
433int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) 502int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
434{ 503{
435 struct dib0700_state *st = adap->dev->priv; 504 struct dib0700_state *st = adap->dev->priv;
436 u8 b[4];
437 int ret; 505 int ret;
438 506
439 if ((onoff != 0) && (st->fw_version >= 0x10201)) { 507 if ((onoff != 0) && (st->fw_version >= 0x10201)) {
@@ -447,43 +515,58 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
447 } 515 }
448 } 516 }
449 517
450 b[0] = REQUEST_ENABLE_VIDEO; 518 st->buf[0] = REQUEST_ENABLE_VIDEO;
451 b[1] = (onoff << 4) | 0x00; /* this bit gives a kind of command, rather than enabling something or not */ 519 /* this bit gives a kind of command,
520 * rather than enabling something or not */
521 st->buf[1] = (onoff << 4) | 0x00;
452 522
453 if (st->disable_streaming_master_mode == 1) 523 if (st->disable_streaming_master_mode == 1)
454 b[2] = 0x00; 524 st->buf[2] = 0x00;
455 else 525 else
456 b[2] = 0x01 << 4; /* Master mode */ 526 st->buf[2] = 0x01 << 4; /* Master mode */
457 527
458 b[3] = 0x00; 528 st->buf[3] = 0x00;
459 529
460 deb_info("modifying (%d) streaming state for %d\n", onoff, adap->id); 530 deb_info("modifying (%d) streaming state for %d\n", onoff, adap->id);
461 531
462 if (onoff) 532 st->channel_state &= ~0x3;
463 st->channel_state |= 1 << adap->id; 533 if ((adap->stream.props.endpoint != 2)
464 else 534 && (adap->stream.props.endpoint != 3)) {
465 st->channel_state &= ~(1 << adap->id); 535 deb_info("the endpoint number (%i) is not correct, use the adapter id instead", adap->stream.props.endpoint);
536 if (onoff)
537 st->channel_state |= 1 << (adap->id);
538 else
539 st->channel_state |= 1 << ~(adap->id);
540 } else {
541 if (onoff)
542 st->channel_state |= 1 << (adap->stream.props.endpoint-2);
543 else
544 st->channel_state |= 1 << (3-adap->stream.props.endpoint);
545 }
466 546
467 b[2] |= st->channel_state; 547 st->buf[2] |= st->channel_state;
468 548
469 deb_info("data for streaming: %x %x\n", b[1], b[2]); 549 deb_info("data for streaming: %x %x\n", st->buf[1], st->buf[2]);
470 550
471 return dib0700_ctrl_wr(adap->dev, b, 4); 551 return dib0700_ctrl_wr(adap->dev, st->buf, 4);
472} 552}
473 553
474int dib0700_change_protocol(void *priv, u64 ir_type) 554int dib0700_change_protocol(struct rc_dev *rc, u64 rc_type)
475{ 555{
476 struct dvb_usb_device *d = priv; 556 struct dvb_usb_device *d = rc->priv;
477 struct dib0700_state *st = d->priv; 557 struct dib0700_state *st = d->priv;
478 u8 rc_setup[3] = { REQUEST_SET_RC, 0, 0 };
479 int new_proto, ret; 558 int new_proto, ret;
480 559
560 st->buf[0] = REQUEST_SET_RC;
561 st->buf[1] = 0;
562 st->buf[2] = 0;
563
481 /* Set the IR mode */ 564 /* Set the IR mode */
482 if (ir_type == IR_TYPE_RC5) 565 if (rc_type == RC_TYPE_RC5)
483 new_proto = 1; 566 new_proto = 1;
484 else if (ir_type == IR_TYPE_NEC) 567 else if (rc_type == RC_TYPE_NEC)
485 new_proto = 0; 568 new_proto = 0;
486 else if (ir_type == IR_TYPE_RC6) { 569 else if (rc_type == RC_TYPE_RC6) {
487 if (st->fw_version < 0x10200) 570 if (st->fw_version < 0x10200)
488 return -EINVAL; 571 return -EINVAL;
489 572
@@ -491,15 +574,15 @@ int dib0700_change_protocol(void *priv, u64 ir_type)
491 } else 574 } else
492 return -EINVAL; 575 return -EINVAL;
493 576
494 rc_setup[1] = new_proto; 577 st->buf[1] = new_proto;
495 578
496 ret = dib0700_ctrl_wr(d, rc_setup, sizeof(rc_setup)); 579 ret = dib0700_ctrl_wr(d, st->buf, 3);
497 if (ret < 0) { 580 if (ret < 0) {
498 err("ir protocol setup failed"); 581 err("ir protocol setup failed");
499 return ret; 582 return ret;
500 } 583 }
501 584
502 d->props.rc.core.protocol = ir_type; 585 d->props.rc.core.protocol = rc_type;
503 586
504 return ret; 587 return ret;
505} 588}
@@ -514,8 +597,8 @@ struct dib0700_rc_response {
514 union { 597 union {
515 u16 system16; 598 u16 system16;
516 struct { 599 struct {
517 u8 system;
518 u8 not_system; 600 u8 not_system;
601 u8 system;
519 }; 602 };
520 }; 603 };
521 u8 data; 604 u8 data;
@@ -526,7 +609,6 @@ struct dib0700_rc_response {
526static void dib0700_rc_urb_completion(struct urb *purb) 609static void dib0700_rc_urb_completion(struct urb *purb)
527{ 610{
528 struct dvb_usb_device *d = purb->context; 611 struct dvb_usb_device *d = purb->context;
529 struct dib0700_state *st;
530 struct dib0700_rc_response *poll_reply; 612 struct dib0700_rc_response *poll_reply;
531 u32 uninitialized_var(keycode); 613 u32 uninitialized_var(keycode);
532 u8 toggle; 614 u8 toggle;
@@ -535,13 +617,12 @@ static void dib0700_rc_urb_completion(struct urb *purb)
535 if (d == NULL) 617 if (d == NULL)
536 return; 618 return;
537 619
538 if (d->rc_input_dev == NULL) { 620 if (d->rc_dev == NULL) {
539 /* This will occur if disable_rc_polling=1 */ 621 /* This will occur if disable_rc_polling=1 */
540 usb_free_urb(purb); 622 usb_free_urb(purb);
541 return; 623 return;
542 } 624 }
543 625
544 st = d->priv;
545 poll_reply = purb->transfer_buffer; 626 poll_reply = purb->transfer_buffer;
546 627
547 if (purb->status < 0) { 628 if (purb->status < 0) {
@@ -562,7 +643,7 @@ static void dib0700_rc_urb_completion(struct urb *purb)
562 purb->actual_length); 643 purb->actual_length);
563 644
564 switch (d->props.rc.core.protocol) { 645 switch (d->props.rc.core.protocol) {
565 case IR_TYPE_NEC: 646 case RC_TYPE_NEC:
566 toggle = 0; 647 toggle = 0;
567 648
568 /* NEC protocol sends repeat code as 0 0 0 FF */ 649 /* NEC protocol sends repeat code as 0 0 0 FF */
@@ -575,7 +656,7 @@ static void dib0700_rc_urb_completion(struct urb *purb)
575 if ((poll_reply->system ^ poll_reply->not_system) != 0xff) { 656 if ((poll_reply->system ^ poll_reply->not_system) != 0xff) {
576 deb_data("NEC extended protocol\n"); 657 deb_data("NEC extended protocol\n");
577 /* NEC extended code - 24 bits */ 658 /* NEC extended code - 24 bits */
578 keycode = poll_reply->system16 << 8 | poll_reply->data; 659 keycode = be16_to_cpu(poll_reply->system16) << 8 | poll_reply->data;
579 } else { 660 } else {
580 deb_data("NEC normal protocol\n"); 661 deb_data("NEC normal protocol\n");
581 /* normal NEC code - 16 bits */ 662 /* normal NEC code - 16 bits */
@@ -587,7 +668,7 @@ static void dib0700_rc_urb_completion(struct urb *purb)
587 deb_data("RC5 protocol\n"); 668 deb_data("RC5 protocol\n");
588 /* RC5 Protocol */ 669 /* RC5 Protocol */
589 toggle = poll_reply->report_id; 670 toggle = poll_reply->report_id;
590 keycode = poll_reply->system16 << 8 | poll_reply->data; 671 keycode = poll_reply->system << 8 | poll_reply->data;
591 672
592 break; 673 break;
593 } 674 }
@@ -600,7 +681,7 @@ static void dib0700_rc_urb_completion(struct urb *purb)
600 goto resubmit; 681 goto resubmit;
601 } 682 }
602 683
603 ir_keydown(d->rc_input_dev, keycode, toggle); 684 rc_keydown(d->rc_dev, keycode, toggle);
604 685
605resubmit: 686resubmit:
606 /* Clean the buffer before we requeue */ 687 /* Clean the buffer before we requeue */
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index e06acd1fecb6..c519ad5eb731 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -12,6 +12,7 @@
12#include "dib7000m.h" 12#include "dib7000m.h"
13#include "dib7000p.h" 13#include "dib7000p.h"
14#include "dib8000.h" 14#include "dib8000.h"
15#include "dib9000.h"
15#include "mt2060.h" 16#include "mt2060.h"
16#include "mt2266.h" 17#include "mt2266.h"
17#include "tuner-xc2028.h" 18#include "tuner-xc2028.h"
@@ -29,6 +30,7 @@ MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplif
29 30
30struct dib0700_adapter_state { 31struct dib0700_adapter_state {
31 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *); 32 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *);
33 const struct firmware *frontend_firmware;
32}; 34};
33 35
34/* Hauppauge Nova-T 500 (aka Bristol) 36/* Hauppauge Nova-T 500 (aka Bristol)
@@ -510,7 +512,7 @@ static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d)
510 512
511 d->last_event = 0; 513 d->last_event = 0;
512 switch (d->props.rc.core.protocol) { 514 switch (d->props.rc.core.protocol) {
513 case IR_TYPE_NEC: 515 case RC_TYPE_NEC:
514 /* NEC protocol sends repeat code as 0 0 0 FF */ 516 /* NEC protocol sends repeat code as 0 0 0 FF */
515 if ((key[3-2] == 0x00) && (key[3-3] == 0x00) && 517 if ((key[3-2] == 0x00) && (key[3-3] == 0x00) &&
516 (key[3] == 0xff)) 518 (key[3] == 0xff))
@@ -520,13 +522,13 @@ static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d)
520 d->last_event = keycode; 522 d->last_event = keycode;
521 } 523 }
522 524
523 ir_keydown(d->rc_input_dev, keycode, 0); 525 rc_keydown(d->rc_dev, keycode, 0);
524 break; 526 break;
525 default: 527 default:
526 /* RC-5 protocol changes toggle bit on new keypress */ 528 /* RC-5 protocol changes toggle bit on new keypress */
527 keycode = key[3-2] << 8 | key[3-3]; 529 keycode = key[3-2] << 8 | key[3-3];
528 toggle = key[3-1]; 530 toggle = key[3-1];
529 ir_keydown(d->rc_input_dev, keycode, toggle); 531 rc_keydown(d->rc_dev, keycode, toggle);
530 532
531 break; 533 break;
532 } 534 }
@@ -870,6 +872,23 @@ static int dib7070p_tuner_attach(struct dvb_usb_adapter *adap)
870 return 0; 872 return 0;
871} 873}
872 874
875static int stk7700p_pid_filter(struct dvb_usb_adapter *adapter, int index,
876 u16 pid, int onoff)
877{
878 struct dib0700_state *st = adapter->dev->priv;
879 if (st->is_dib7000pc)
880 return dib7000p_pid_filter(adapter->fe, index, pid, onoff);
881 return dib7000m_pid_filter(adapter->fe, index, pid, onoff);
882}
883
884static int stk7700p_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
885{
886 struct dib0700_state *st = adapter->dev->priv;
887 if (st->is_dib7000pc)
888 return dib7000p_pid_filter_ctrl(adapter->fe, onoff);
889 return dib7000m_pid_filter_ctrl(adapter->fe, onoff);
890}
891
873static int stk70x0p_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff) 892static int stk70x0p_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff)
874{ 893{
875 return dib7000p_pid_filter(adapter->fe, index, pid, onoff); 894 return dib7000p_pid_filter(adapter->fe, index, pid, onoff);
@@ -1226,13 +1245,13 @@ static int dib807x_tuner_attach(struct dvb_usb_adapter *adap)
1226static int stk80xx_pid_filter(struct dvb_usb_adapter *adapter, int index, 1245static int stk80xx_pid_filter(struct dvb_usb_adapter *adapter, int index,
1227 u16 pid, int onoff) 1246 u16 pid, int onoff)
1228{ 1247{
1229 return dib8000_pid_filter(adapter->fe, index, pid, onoff); 1248 return dib8000_pid_filter(adapter->fe, index, pid, onoff);
1230} 1249}
1231 1250
1232static int stk80xx_pid_filter_ctrl(struct dvb_usb_adapter *adapter, 1251static int stk80xx_pid_filter_ctrl(struct dvb_usb_adapter *adapter,
1233 int onoff) 1252 int onoff)
1234{ 1253{
1235 return dib8000_pid_filter_ctrl(adapter->fe, onoff); 1254 return dib8000_pid_filter_ctrl(adapter->fe, onoff);
1236} 1255}
1237 1256
1238/* STK807x */ 1257/* STK807x */
@@ -1304,11 +1323,11 @@ static int stk807xpvr_frontend_attach1(struct dvb_usb_adapter *adap)
1304 1323
1305/* STK8096GP */ 1324/* STK8096GP */
1306struct dibx000_agc_config dib8090_agc_config[2] = { 1325struct dibx000_agc_config dib8090_agc_config[2] = {
1307 { 1326 {
1308 BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND, 1327 BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
1309 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, 1328 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1,
1310 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0, 1329 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1311 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */ 1330 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
1312 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) 1331 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
1313 | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0), 1332 | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
1314 1333
@@ -1345,12 +1364,12 @@ struct dibx000_agc_config dib8090_agc_config[2] = {
1345 51, 1364 51,
1346 1365
1347 0, 1366 0,
1348 }, 1367 },
1349 { 1368 {
1350 BAND_CBAND, 1369 BAND_CBAND,
1351 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, 1370 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1,
1352 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0, 1371 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
1353 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */ 1372 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
1354 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) 1373 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8)
1355 | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0), 1374 | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
1356 1375
@@ -1387,135 +1406,153 @@ struct dibx000_agc_config dib8090_agc_config[2] = {
1387 51, 1406 51,
1388 1407
1389 0, 1408 0,
1390 } 1409 }
1391}; 1410};
1392 1411
1393static struct dibx000_bandwidth_config dib8090_pll_config_12mhz = { 1412static struct dibx000_bandwidth_config dib8090_pll_config_12mhz = {
1394 54000, 13500, 1413 54000, 13500,
1395 1, 18, 3, 1, 0, 1414 1, 18, 3, 1, 0,
1396 0, 0, 1, 1, 2, 1415 0, 0, 1, 1, 2,
1397 (3 << 14) | (1 << 12) | (599 << 0), 1416 (3 << 14) | (1 << 12) | (599 << 0),
1398 (0 << 25) | 0, 1417 (0 << 25) | 0,
1399 20199727, 1418 20199727,
1400 12000000, 1419 12000000,
1401}; 1420};
1402 1421
1403static int dib8090_get_adc_power(struct dvb_frontend *fe) 1422static int dib8090_get_adc_power(struct dvb_frontend *fe)
1404{ 1423{
1405 return dib8000_get_adc_power(fe, 1); 1424 return dib8000_get_adc_power(fe, 1);
1406} 1425}
1407 1426
1408static struct dib8000_config dib809x_dib8000_config = { 1427static struct dib8000_config dib809x_dib8000_config[2] = {
1409 .output_mpeg2_in_188_bytes = 1, 1428 {
1410 1429 .output_mpeg2_in_188_bytes = 1,
1411 .agc_config_count = 2, 1430
1412 .agc = dib8090_agc_config, 1431 .agc_config_count = 2,
1413 .agc_control = dib0090_dcc_freq, 1432 .agc = dib8090_agc_config,
1414 .pll = &dib8090_pll_config_12mhz, 1433 .agc_control = dib0090_dcc_freq,
1415 .tuner_is_baseband = 1, 1434 .pll = &dib8090_pll_config_12mhz,
1416 1435 .tuner_is_baseband = 1,
1417 .gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS, 1436
1418 .gpio_val = DIB8000_GPIO_DEFAULT_VALUES, 1437 .gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
1419 .gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS, 1438 .gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
1420 1439 .gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,
1421 .hostbus_diversity = 1, 1440
1422 .div_cfg = 0x31, 1441 .hostbus_diversity = 1,
1423 .output_mode = OUTMODE_MPEG2_FIFO, 1442 .div_cfg = 0x31,
1424 .drives = 0x2d98, 1443 .output_mode = OUTMODE_MPEG2_FIFO,
1425 .diversity_delay = 144, 1444 .drives = 0x2d98,
1426 .refclksel = 3, 1445 .diversity_delay = 48,
1446 .refclksel = 3,
1447 }, {
1448 .output_mpeg2_in_188_bytes = 1,
1449
1450 .agc_config_count = 2,
1451 .agc = dib8090_agc_config,
1452 .agc_control = dib0090_dcc_freq,
1453 .pll = &dib8090_pll_config_12mhz,
1454 .tuner_is_baseband = 1,
1455
1456 .gpio_dir = DIB8000_GPIO_DEFAULT_DIRECTIONS,
1457 .gpio_val = DIB8000_GPIO_DEFAULT_VALUES,
1458 .gpio_pwm_pos = DIB8000_GPIO_DEFAULT_PWM_POS,
1459
1460 .hostbus_diversity = 1,
1461 .div_cfg = 0x31,
1462 .output_mode = OUTMODE_DIVERSITY,
1463 .drives = 0x2d08,
1464 .diversity_delay = 1,
1465 .refclksel = 3,
1466 }
1467};
1468
1469static struct dib0090_wbd_slope dib8090_wbd_table[] = {
1470 /* max freq ; cold slope ; cold offset ; warm slope ; warm offset ; wbd gain */
1471 { 120, 0, 500, 0, 500, 4 }, /* CBAND */
1472 { 170, 0, 450, 0, 450, 4 }, /* CBAND */
1473 { 380, 48, 373, 28, 259, 6 }, /* VHF */
1474 { 860, 34, 700, 36, 616, 6 }, /* high UHF */
1475 { 0xFFFF, 34, 700, 36, 616, 6 }, /* default */
1427}; 1476};
1428 1477
1429static struct dib0090_config dib809x_dib0090_config = { 1478static struct dib0090_config dib809x_dib0090_config = {
1430 .io.pll_bypass = 1, 1479 .io.pll_bypass = 1,
1431 .io.pll_range = 1, 1480 .io.pll_range = 1,
1432 .io.pll_prediv = 1, 1481 .io.pll_prediv = 1,
1433 .io.pll_loopdiv = 20, 1482 .io.pll_loopdiv = 20,
1434 .io.adc_clock_ratio = 8, 1483 .io.adc_clock_ratio = 8,
1435 .io.pll_int_loop_filt = 0, 1484 .io.pll_int_loop_filt = 0,
1436 .io.clock_khz = 12000, 1485 .io.clock_khz = 12000,
1437 .reset = dib80xx_tuner_reset, 1486 .reset = dib80xx_tuner_reset,
1438 .sleep = dib80xx_tuner_sleep, 1487 .sleep = dib80xx_tuner_sleep,
1439 .clkouttobamse = 1, 1488 .clkouttobamse = 1,
1440 .analog_output = 1, 1489 .analog_output = 1,
1441 .i2c_address = DEFAULT_DIB0090_I2C_ADDRESS, 1490 .i2c_address = DEFAULT_DIB0090_I2C_ADDRESS,
1442 .wbd_vhf_offset = 100, 1491 .use_pwm_agc = 1,
1443 .wbd_cband_offset = 450, 1492 .clkoutdrive = 1,
1444 .use_pwm_agc = 1, 1493 .get_adc_power = dib8090_get_adc_power,
1445 .clkoutdrive = 1, 1494 .freq_offset_khz_uhf = -63,
1446 .get_adc_power = dib8090_get_adc_power,
1447 .freq_offset_khz_uhf = 0,
1448 .freq_offset_khz_vhf = -143, 1495 .freq_offset_khz_vhf = -143,
1496 .wbd = dib8090_wbd_table,
1497 .fref_clock_ratio = 6,
1449}; 1498};
1450 1499
1451static int dib8096_set_param_override(struct dvb_frontend *fe, 1500static int dib8096_set_param_override(struct dvb_frontend *fe,
1452 struct dvb_frontend_parameters *fep) 1501 struct dvb_frontend_parameters *fep)
1453{ 1502{
1454 struct dvb_usb_adapter *adap = fe->dvb->priv; 1503 struct dvb_usb_adapter *adap = fe->dvb->priv;
1455 struct dib0700_adapter_state *state = adap->priv; 1504 struct dib0700_adapter_state *state = adap->priv;
1456 u8 band = BAND_OF_FREQUENCY(fep->frequency/1000); 1505 u8 band = BAND_OF_FREQUENCY(fep->frequency/1000);
1457 u16 offset; 1506 u16 target;
1458 int ret = 0; 1507 int ret = 0;
1459 enum frontend_tune_state tune_state = CT_SHUTDOWN; 1508 enum frontend_tune_state tune_state = CT_SHUTDOWN;
1460 u16 ltgain, rf_gain_limit; 1509 u16 ltgain, rf_gain_limit;
1461 1510
1462 ret = state->set_param_save(fe, fep); 1511 ret = state->set_param_save(fe, fep);
1463 if (ret < 0) 1512 if (ret < 0)
1464 return ret; 1513 return ret;
1465 1514
1466 switch (band) { 1515 target = (dib0090_get_wbd_offset(fe) * 8 * 18 / 33 + 1) / 2;
1467 case BAND_VHF: 1516 dib8000_set_wbd_ref(fe, target);
1468 offset = 100; 1517
1469 break; 1518
1470 case BAND_UHF: 1519 if (band == BAND_CBAND) {
1471 offset = 550; 1520 deb_info("tuning in CBAND - soft-AGC startup\n");
1472 break; 1521 dib0090_set_tune_state(fe, CT_AGC_START);
1473 default: 1522 do {
1474 offset = 0; 1523 ret = dib0090_gain_control(fe);
1475 break; 1524 msleep(ret);
1476 } 1525 tune_state = dib0090_get_tune_state(fe);
1477 offset += (dib0090_get_wbd_offset(fe) * 8 * 18 / 33 + 1) / 2; 1526 if (tune_state == CT_AGC_STEP_0)
1478 dib8000_set_wbd_ref(fe, offset); 1527 dib8000_set_gpio(fe, 6, 0, 1);
1479 1528 else if (tune_state == CT_AGC_STEP_1) {
1480 1529 dib0090_get_current_gain(fe, NULL, NULL, &rf_gain_limit, &ltgain);
1481 if (band == BAND_CBAND) { 1530 if (rf_gain_limit == 0)
1482 deb_info("tuning in CBAND - soft-AGC startup\n"); 1531 dib8000_set_gpio(fe, 6, 0, 0);
1483 /* TODO specific wbd target for dib0090 - needed for startup ? */ 1532 }
1484 dib0090_set_tune_state(fe, CT_AGC_START); 1533 } while (tune_state < CT_AGC_STOP);
1485 do { 1534 dib0090_pwm_gain_reset(fe);
1486 ret = dib0090_gain_control(fe); 1535 dib8000_pwm_agc_reset(fe);
1487 msleep(ret); 1536 dib8000_set_tune_state(fe, CT_DEMOD_START);
1488 tune_state = dib0090_get_tune_state(fe); 1537 } else {
1489 if (tune_state == CT_AGC_STEP_0) 1538 deb_info("not tuning in CBAND - standard AGC startup\n");
1490 dib8000_set_gpio(fe, 6, 0, 1); 1539 dib0090_pwm_gain_reset(fe);
1491 else if (tune_state == CT_AGC_STEP_1) { 1540 }
1492 dib0090_get_current_gain(fe, NULL, NULL, &rf_gain_limit, &ltgain);
1493 if (rf_gain_limit == 0)
1494 dib8000_set_gpio(fe, 6, 0, 0);
1495 }
1496 } while (tune_state < CT_AGC_STOP);
1497 dib0090_pwm_gain_reset(fe);
1498 dib8000_pwm_agc_reset(fe);
1499 dib8000_set_tune_state(fe, CT_DEMOD_START);
1500 } else {
1501 deb_info("not tuning in CBAND - standard AGC startup\n");
1502 dib0090_pwm_gain_reset(fe);
1503 }
1504 1541
1505 return 0; 1542 return 0;
1506} 1543}
1507 1544
1508static int dib809x_tuner_attach(struct dvb_usb_adapter *adap) 1545static int dib809x_tuner_attach(struct dvb_usb_adapter *adap)
1509{ 1546{
1510 struct dib0700_adapter_state *st = adap->priv; 1547 struct dib0700_adapter_state *st = adap->priv;
1511 struct i2c_adapter *tun_i2c = dib8000_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1); 1548 struct i2c_adapter *tun_i2c = dib8000_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
1512 1549
1513 if (dvb_attach(dib0090_register, adap->fe, tun_i2c, &dib809x_dib0090_config) == NULL) 1550 if (dvb_attach(dib0090_register, adap->fe, tun_i2c, &dib809x_dib0090_config) == NULL)
1514 return -ENODEV; 1551 return -ENODEV;
1515 1552
1516 st->set_param_save = adap->fe->ops.tuner_ops.set_params; 1553 st->set_param_save = adap->fe->ops.tuner_ops.set_params;
1517 adap->fe->ops.tuner_ops.set_params = dib8096_set_param_override; 1554 adap->fe->ops.tuner_ops.set_params = dib8096_set_param_override;
1518 return 0; 1555 return 0;
1519} 1556}
1520 1557
1521static int stk809x_frontend_attach(struct dvb_usb_adapter *adap) 1558static int stk809x_frontend_attach(struct dvb_usb_adapter *adap)
@@ -1537,11 +1574,930 @@ static int stk809x_frontend_attach(struct dvb_usb_adapter *adap)
1537 1574
1538 dib8000_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 0x80); 1575 dib8000_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 0x80);
1539 1576
1540 adap->fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config); 1577 adap->fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
1578
1579 return adap->fe == NULL ? -ENODEV : 0;
1580}
1581
1582static int nim8096md_tuner_attach(struct dvb_usb_adapter *adap)
1583{
1584 struct dib0700_adapter_state *st = adap->priv;
1585 struct i2c_adapter *tun_i2c;
1586 struct dvb_frontend *fe_slave = dib8000_get_slave_frontend(adap->fe, 1);
1587
1588 if (fe_slave) {
1589 tun_i2c = dib8000_get_i2c_master(fe_slave, DIBX000_I2C_INTERFACE_TUNER, 1);
1590 if (dvb_attach(dib0090_register, fe_slave, tun_i2c, &dib809x_dib0090_config) == NULL)
1591 return -ENODEV;
1592 fe_slave->dvb = adap->fe->dvb;
1593 fe_slave->ops.tuner_ops.set_params = dib8096_set_param_override;
1594 }
1595 tun_i2c = dib8000_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
1596 if (dvb_attach(dib0090_register, adap->fe, tun_i2c, &dib809x_dib0090_config) == NULL)
1597 return -ENODEV;
1598
1599 st->set_param_save = adap->fe->ops.tuner_ops.set_params;
1600 adap->fe->ops.tuner_ops.set_params = dib8096_set_param_override;
1601
1602 return 0;
1603}
1604
1605static int nim8096md_frontend_attach(struct dvb_usb_adapter *adap)
1606{
1607 struct dvb_frontend *fe_slave;
1608
1609 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
1610 msleep(20);
1611 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1612 msleep(1000);
1613 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1614 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1615 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1616
1617 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1618
1619 dib0700_ctrl_clock(adap->dev, 72, 1);
1620
1621 msleep(20);
1622 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1623 msleep(20);
1624 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1625
1626 dib8000_i2c_enumeration(&adap->dev->i2c_adap, 2, 18, 0x80);
1627
1628 adap->fe = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x80, &dib809x_dib8000_config[0]);
1629 if (adap->fe == NULL)
1630 return -ENODEV;
1631
1632 fe_slave = dvb_attach(dib8000_attach, &adap->dev->i2c_adap, 0x82, &dib809x_dib8000_config[1]);
1633 dib8000_set_slave_frontend(adap->fe, fe_slave);
1634
1635 return fe_slave == NULL ? -ENODEV : 0;
1636}
1637
1638/* STK9090M */
1639static int dib90x0_pid_filter(struct dvb_usb_adapter *adapter, int index, u16 pid, int onoff)
1640{
1641 return dib9000_fw_pid_filter(adapter->fe, index, pid, onoff);
1642}
1643
1644static int dib90x0_pid_filter_ctrl(struct dvb_usb_adapter *adapter, int onoff)
1645{
1646 return dib9000_fw_pid_filter_ctrl(adapter->fe, onoff);
1647}
1648
1649static int dib90x0_tuner_reset(struct dvb_frontend *fe, int onoff)
1650{
1651 return dib9000_set_gpio(fe, 5, 0, !onoff);
1652}
1653
1654static int dib90x0_tuner_sleep(struct dvb_frontend *fe, int onoff)
1655{
1656 return dib9000_set_gpio(fe, 0, 0, onoff);
1657}
1658
1659static int dib01x0_pmu_update(struct i2c_adapter *i2c, u16 *data, u8 len)
1660{
1661 u8 wb[4] = { 0xc >> 8, 0xc & 0xff, 0, 0 };
1662 u8 rb[2];
1663 struct i2c_msg msg[2] = {
1664 {.addr = 0x1e >> 1, .flags = 0, .buf = wb, .len = 2},
1665 {.addr = 0x1e >> 1, .flags = I2C_M_RD, .buf = rb, .len = 2},
1666 };
1667 u8 index_data;
1668
1669 dibx000_i2c_set_speed(i2c, 250);
1670
1671 if (i2c_transfer(i2c, msg, 2) != 2)
1672 return -EIO;
1673
1674 switch (rb[0] << 8 | rb[1]) {
1675 case 0:
1676 deb_info("Found DiB0170 rev1: This version of DiB0170 is not supported any longer.\n");
1677 return -EIO;
1678 case 1:
1679 deb_info("Found DiB0170 rev2");
1680 break;
1681 case 2:
1682 deb_info("Found DiB0190 rev2");
1683 break;
1684 default:
1685 deb_info("DiB01x0 not found");
1686 return -EIO;
1687 }
1688
1689 for (index_data = 0; index_data < len; index_data += 2) {
1690 wb[2] = (data[index_data + 1] >> 8) & 0xff;
1691 wb[3] = (data[index_data + 1]) & 0xff;
1692
1693 if (data[index_data] == 0) {
1694 wb[0] = (data[index_data] >> 8) & 0xff;
1695 wb[1] = (data[index_data]) & 0xff;
1696 msg[0].len = 2;
1697 if (i2c_transfer(i2c, msg, 2) != 2)
1698 return -EIO;
1699 wb[2] |= rb[0];
1700 wb[3] |= rb[1] & ~(3 << 4);
1701 }
1702
1703 wb[0] = (data[index_data] >> 8)&0xff;
1704 wb[1] = (data[index_data])&0xff;
1705 msg[0].len = 4;
1706 if (i2c_transfer(i2c, &msg[0], 1) != 1)
1707 return -EIO;
1708 }
1709 return 0;
1710}
1711
1712static struct dib9000_config stk9090m_config = {
1713 .output_mpeg2_in_188_bytes = 1,
1714 .output_mode = OUTMODE_MPEG2_FIFO,
1715 .vcxo_timer = 279620,
1716 .timing_frequency = 20452225,
1717 .demod_clock_khz = 60000,
1718 .xtal_clock_khz = 30000,
1719 .if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
1720 .subband = {
1721 2,
1722 {
1723 { 240, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0008, 0x0000, 0x0008 } }, /* GPIO 3 to 1 for VHF */
1724 { 890, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0008, 0x0000, 0x0000 } }, /* GPIO 3 to 0 for UHF */
1725 { 0 },
1726 },
1727 },
1728 .gpio_function = {
1729 { .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_ON, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = (0x10 & ~0x1) | 0x20 },
1730 { .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_OFF, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = 0 | 0x21 },
1731 },
1732};
1733
1734static struct dib9000_config nim9090md_config[2] = {
1735 {
1736 .output_mpeg2_in_188_bytes = 1,
1737 .output_mode = OUTMODE_MPEG2_FIFO,
1738 .vcxo_timer = 279620,
1739 .timing_frequency = 20452225,
1740 .demod_clock_khz = 60000,
1741 .xtal_clock_khz = 30000,
1742 .if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
1743 }, {
1744 .output_mpeg2_in_188_bytes = 1,
1745 .output_mode = OUTMODE_DIVERSITY,
1746 .vcxo_timer = 279620,
1747 .timing_frequency = 20452225,
1748 .demod_clock_khz = 60000,
1749 .xtal_clock_khz = 30000,
1750 .if_drives = (0 << 15) | (1 << 13) | (0 << 12) | (3 << 10) | (0 << 9) | (1 << 7) | (0 << 6) | (0 << 4) | (1 << 3) | (1 << 1) | (0),
1751 .subband = {
1752 2,
1753 {
1754 { 240, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0006, 0x0000, 0x0006 } }, /* GPIO 1 and 2 to 1 for VHF */
1755 { 890, { BOARD_GPIO_COMPONENT_DEMOD, BOARD_GPIO_FUNCTION_SUBBAND_GPIO, 0x0006, 0x0000, 0x0000 } }, /* GPIO 1 and 2 to 0 for UHF */
1756 { 0 },
1757 },
1758 },
1759 .gpio_function = {
1760 { .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_ON, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = (0x10 & ~0x1) | 0x20 },
1761 { .component = BOARD_GPIO_COMPONENT_DEMOD, .function = BOARD_GPIO_FUNCTION_COMPONENT_OFF, .mask = 0x10 | 0x21, .direction = 0 & ~0x21, .value = 0 | 0x21 },
1762 },
1763 }
1764};
1765
1766static struct dib0090_config dib9090_dib0090_config = {
1767 .io.pll_bypass = 0,
1768 .io.pll_range = 1,
1769 .io.pll_prediv = 1,
1770 .io.pll_loopdiv = 8,
1771 .io.adc_clock_ratio = 8,
1772 .io.pll_int_loop_filt = 0,
1773 .io.clock_khz = 30000,
1774 .reset = dib90x0_tuner_reset,
1775 .sleep = dib90x0_tuner_sleep,
1776 .clkouttobamse = 0,
1777 .analog_output = 0,
1778 .use_pwm_agc = 0,
1779 .clkoutdrive = 0,
1780 .freq_offset_khz_uhf = 0,
1781 .freq_offset_khz_vhf = 0,
1782};
1783
1784static struct dib0090_config nim9090md_dib0090_config[2] = {
1785 {
1786 .io.pll_bypass = 0,
1787 .io.pll_range = 1,
1788 .io.pll_prediv = 1,
1789 .io.pll_loopdiv = 8,
1790 .io.adc_clock_ratio = 8,
1791 .io.pll_int_loop_filt = 0,
1792 .io.clock_khz = 30000,
1793 .reset = dib90x0_tuner_reset,
1794 .sleep = dib90x0_tuner_sleep,
1795 .clkouttobamse = 1,
1796 .analog_output = 0,
1797 .use_pwm_agc = 0,
1798 .clkoutdrive = 0,
1799 .freq_offset_khz_uhf = 0,
1800 .freq_offset_khz_vhf = 0,
1801 }, {
1802 .io.pll_bypass = 0,
1803 .io.pll_range = 1,
1804 .io.pll_prediv = 1,
1805 .io.pll_loopdiv = 8,
1806 .io.adc_clock_ratio = 8,
1807 .io.pll_int_loop_filt = 0,
1808 .io.clock_khz = 30000,
1809 .reset = dib90x0_tuner_reset,
1810 .sleep = dib90x0_tuner_sleep,
1811 .clkouttobamse = 0,
1812 .analog_output = 0,
1813 .use_pwm_agc = 0,
1814 .clkoutdrive = 0,
1815 .freq_offset_khz_uhf = 0,
1816 .freq_offset_khz_vhf = 0,
1817 }
1818};
1819
1820
1821static int stk9090m_frontend_attach(struct dvb_usb_adapter *adap)
1822{
1823 struct dib0700_adapter_state *state = adap->priv;
1824 struct dib0700_state *st = adap->dev->priv;
1825 u32 fw_version;
1826
1827 /* Make use of the new i2c functions from FW 1.20 */
1828 dib0700_get_version(adap->dev, NULL, NULL, &fw_version, NULL);
1829 if (fw_version >= 0x10200)
1830 st->fw_use_new_i2c_api = 1;
1831 dib0700_set_i2c_speed(adap->dev, 340);
1832
1833 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1834 msleep(20);
1835 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1836 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1837 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1838 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1839
1840 dib0700_ctrl_clock(adap->dev, 72, 1);
1841
1842 msleep(20);
1843 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1844 msleep(20);
1845 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1846
1847 dib9000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, 0x80);
1848
1849 if (request_firmware(&state->frontend_firmware, "dib9090.fw", &adap->dev->udev->dev)) {
1850 deb_info("%s: Upload failed. (file not found?)\n", __func__);
1851 return -ENODEV;
1852 } else {
1853 deb_info("%s: firmware read %Zu bytes.\n", __func__, state->frontend_firmware->size);
1854 }
1855 stk9090m_config.microcode_B_fe_size = state->frontend_firmware->size;
1856 stk9090m_config.microcode_B_fe_buffer = state->frontend_firmware->data;
1857
1858 adap->fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &stk9090m_config);
1859
1860 return adap->fe == NULL ? -ENODEV : 0;
1861}
1862
1863static int dib9090_tuner_attach(struct dvb_usb_adapter *adap)
1864{
1865 struct dib0700_adapter_state *state = adap->priv;
1866 struct i2c_adapter *i2c = dib9000_get_tuner_interface(adap->fe);
1867 u16 data_dib190[10] = {
1868 1, 0x1374,
1869 2, 0x01a2,
1870 7, 0x0020,
1871 0, 0x00ef,
1872 8, 0x0486,
1873 };
1874
1875 if (dvb_attach(dib0090_fw_register, adap->fe, i2c, &dib9090_dib0090_config) == NULL)
1876 return -ENODEV;
1877 i2c = dib9000_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
1878 if (dib01x0_pmu_update(i2c, data_dib190, 10) != 0)
1879 return -ENODEV;
1880 dib0700_set_i2c_speed(adap->dev, 2000);
1881 if (dib9000_firmware_post_pll_init(adap->fe) < 0)
1882 return -ENODEV;
1883 release_firmware(state->frontend_firmware);
1884 return 0;
1885}
1886
1887static int nim9090md_frontend_attach(struct dvb_usb_adapter *adap)
1888{
1889 struct dib0700_adapter_state *state = adap->priv;
1890 struct dib0700_state *st = adap->dev->priv;
1891 struct i2c_adapter *i2c;
1892 struct dvb_frontend *fe_slave;
1893 u32 fw_version;
1894
1895 /* Make use of the new i2c functions from FW 1.20 */
1896 dib0700_get_version(adap->dev, NULL, NULL, &fw_version, NULL);
1897 if (fw_version >= 0x10200)
1898 st->fw_use_new_i2c_api = 1;
1899 dib0700_set_i2c_speed(adap->dev, 340);
1900
1901 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1902 msleep(20);
1903 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1904 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1905 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1906 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1907
1908 dib0700_ctrl_clock(adap->dev, 72, 1);
1909
1910 msleep(20);
1911 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1912 msleep(20);
1913 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1914
1915 if (request_firmware(&state->frontend_firmware, "dib9090.fw", &adap->dev->udev->dev)) {
1916 deb_info("%s: Upload failed. (file not found?)\n", __func__);
1917 return -EIO;
1918 } else {
1919 deb_info("%s: firmware read %Zu bytes.\n", __func__, state->frontend_firmware->size);
1920 }
1921 nim9090md_config[0].microcode_B_fe_size = state->frontend_firmware->size;
1922 nim9090md_config[0].microcode_B_fe_buffer = state->frontend_firmware->data;
1923 nim9090md_config[1].microcode_B_fe_size = state->frontend_firmware->size;
1924 nim9090md_config[1].microcode_B_fe_buffer = state->frontend_firmware->data;
1925
1926 dib9000_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x20, 0x80);
1927 adap->fe = dvb_attach(dib9000_attach, &adap->dev->i2c_adap, 0x80, &nim9090md_config[0]);
1928
1929 if (adap->fe == NULL)
1930 return -ENODEV;
1931
1932 i2c = dib9000_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_GPIO_3_4, 0);
1933 dib9000_i2c_enumeration(i2c, 1, 0x12, 0x82);
1934
1935 fe_slave = dvb_attach(dib9000_attach, i2c, 0x82, &nim9090md_config[1]);
1936 dib9000_set_slave_frontend(adap->fe, fe_slave);
1937
1938 return fe_slave == NULL ? -ENODEV : 0;
1939}
1940
1941static int nim9090md_tuner_attach(struct dvb_usb_adapter *adap)
1942{
1943 struct dib0700_adapter_state *state = adap->priv;
1944 struct i2c_adapter *i2c;
1945 struct dvb_frontend *fe_slave;
1946 u16 data_dib190[10] = {
1947 1, 0x5374,
1948 2, 0x01ae,
1949 7, 0x0020,
1950 0, 0x00ef,
1951 8, 0x0406,
1952 };
1953 i2c = dib9000_get_tuner_interface(adap->fe);
1954 if (dvb_attach(dib0090_fw_register, adap->fe, i2c, &nim9090md_dib0090_config[0]) == NULL)
1955 return -ENODEV;
1956 i2c = dib9000_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_GPIO_1_2, 0);
1957 if (dib01x0_pmu_update(i2c, data_dib190, 10) < 0)
1958 return -ENODEV;
1959 dib0700_set_i2c_speed(adap->dev, 2000);
1960 if (dib9000_firmware_post_pll_init(adap->fe) < 0)
1961 return -ENODEV;
1962
1963 fe_slave = dib9000_get_slave_frontend(adap->fe, 1);
1964 if (fe_slave != NULL) {
1965 i2c = dib9000_get_component_bus_interface(adap->fe);
1966 dib9000_set_i2c_adapter(fe_slave, i2c);
1967
1968 i2c = dib9000_get_tuner_interface(fe_slave);
1969 if (dvb_attach(dib0090_fw_register, fe_slave, i2c, &nim9090md_dib0090_config[1]) == NULL)
1970 return -ENODEV;
1971 fe_slave->dvb = adap->fe->dvb;
1972 dib9000_fw_set_component_bus_speed(adap->fe, 2000);
1973 if (dib9000_firmware_post_pll_init(fe_slave) < 0)
1974 return -ENODEV;
1975 }
1976 release_firmware(state->frontend_firmware);
1977
1978 return 0;
1979}
1980
1981/* NIM7090 */
1982struct dib7090p_best_adc {
1983 u32 timf;
1984 u32 pll_loopdiv;
1985 u32 pll_prediv;
1986};
1987
1988static int dib7090p_get_best_sampling(struct dvb_frontend *fe , struct dib7090p_best_adc *adc)
1989{
1990 u8 spur = 0, prediv = 0, loopdiv = 0, min_prediv = 1, max_prediv = 1;
1991
1992 u16 xtal = 12000;
1993 u32 fcp_min = 1900; /* PLL Minimum Frequency comparator KHz */
1994 u32 fcp_max = 20000; /* PLL Maximum Frequency comparator KHz */
1995 u32 fdem_max = 76000;
1996 u32 fdem_min = 69500;
1997 u32 fcp = 0, fs = 0, fdem = 0;
1998 u32 harmonic_id = 0;
1999
2000 adc->pll_loopdiv = loopdiv;
2001 adc->pll_prediv = prediv;
2002 adc->timf = 0;
2003
2004 deb_info("bandwidth = %d fdem_min =%d", fe->dtv_property_cache.bandwidth_hz, fdem_min);
2005
2006 /* Find Min and Max prediv */
2007 while ((xtal/max_prediv) >= fcp_min)
2008 max_prediv++;
2009
2010 max_prediv--;
2011 min_prediv = max_prediv;
2012 while ((xtal/min_prediv) <= fcp_max) {
2013 min_prediv--;
2014 if (min_prediv == 1)
2015 break;
2016 }
2017 deb_info("MIN prediv = %d : MAX prediv = %d", min_prediv, max_prediv);
2018
2019 min_prediv = 2;
2020
2021 for (prediv = min_prediv ; prediv < max_prediv; prediv++) {
2022 fcp = xtal / prediv;
2023 if (fcp > fcp_min && fcp < fcp_max) {
2024 for (loopdiv = 1 ; loopdiv < 64 ; loopdiv++) {
2025 fdem = ((xtal/prediv) * loopdiv);
2026 fs = fdem / 4;
2027 /* test min/max system restrictions */
2028
2029 if ((fdem >= fdem_min) && (fdem <= fdem_max) && (fs >= fe->dtv_property_cache.bandwidth_hz/1000)) {
2030 spur = 0;
2031 /* test fs harmonics positions */
2032 for (harmonic_id = (fe->dtv_property_cache.frequency / (1000*fs)) ; harmonic_id <= ((fe->dtv_property_cache.frequency / (1000*fs))+1) ; harmonic_id++) {
2033 if (((fs*harmonic_id) >= ((fe->dtv_property_cache.frequency/1000) - (fe->dtv_property_cache.bandwidth_hz/2000))) && ((fs*harmonic_id) <= ((fe->dtv_property_cache.frequency/1000) + (fe->dtv_property_cache.bandwidth_hz/2000)))) {
2034 spur = 1;
2035 break;
2036 }
2037 }
2038
2039 if (!spur) {
2040 adc->pll_loopdiv = loopdiv;
2041 adc->pll_prediv = prediv;
2042 adc->timf = 2396745143UL/fdem*(1 << 9);
2043 adc->timf += ((2396745143UL%fdem) << 9)/fdem;
2044 deb_info("loopdiv=%i prediv=%i timf=%i", loopdiv, prediv, adc->timf);
2045 break;
2046 }
2047 }
2048 }
2049 }
2050 if (!spur)
2051 break;
2052 }
2053
2054
2055 if (adc->pll_loopdiv == 0 && adc->pll_prediv == 0)
2056 return -EINVAL;
2057 else
2058 return 0;
2059}
2060
2061static int dib7090_agc_startup(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
2062{
2063 struct dvb_usb_adapter *adap = fe->dvb->priv;
2064 struct dib0700_adapter_state *state = adap->priv;
2065 struct dibx000_bandwidth_config pll;
2066 u16 target;
2067 struct dib7090p_best_adc adc;
2068 int ret;
2069
2070 ret = state->set_param_save(fe, fep);
2071 if (ret < 0)
2072 return ret;
2073
2074 memset(&pll, 0, sizeof(struct dibx000_bandwidth_config));
2075 dib0090_pwm_gain_reset(fe);
2076 target = (dib0090_get_wbd_offset(fe) * 8 + 1) / 2;
2077 dib7000p_set_wbd_ref(fe, target);
2078
2079 if (dib7090p_get_best_sampling(fe, &adc) == 0) {
2080 pll.pll_ratio = adc.pll_loopdiv;
2081 pll.pll_prediv = adc.pll_prediv;
2082
2083 dib7000p_update_pll(fe, &pll);
2084 dib7000p_ctrl_timf(fe, DEMOD_TIMF_SET, adc.timf);
2085 }
2086 return 0;
2087}
2088
2089static struct dib0090_wbd_slope dib7090_wbd_table[] = {
2090 { 380, 81, 850, 64, 540, 4},
2091 { 860, 51, 866, 21, 375, 4},
2092 {1700, 0, 250, 0, 100, 6},
2093 {2600, 0, 250, 0, 100, 6},
2094 { 0xFFFF, 0, 0, 0, 0, 0},
2095};
2096
2097struct dibx000_agc_config dib7090_agc_config[2] = {
2098 {
2099 .band_caps = BAND_UHF,
2100 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
2101 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
2102 .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
2103
2104 .inv_gain = 687,
2105 .time_stabiliz = 10,
2106
2107 .alpha_level = 0,
2108 .thlock = 118,
2109
2110 .wbd_inv = 0,
2111 .wbd_ref = 1200,
2112 .wbd_sel = 3,
2113 .wbd_alpha = 5,
2114
2115 .agc1_max = 65535,
2116 .agc1_min = 0,
2117
2118 .agc2_max = 65535,
2119 .agc2_min = 0,
2120
2121 .agc1_pt1 = 0,
2122 .agc1_pt2 = 32,
2123 .agc1_pt3 = 114,
2124 .agc1_slope1 = 143,
2125 .agc1_slope2 = 144,
2126 .agc2_pt1 = 114,
2127 .agc2_pt2 = 227,
2128 .agc2_slope1 = 116,
2129 .agc2_slope2 = 117,
2130
2131 .alpha_mant = 18,
2132 .alpha_exp = 0,
2133 .beta_mant = 20,
2134 .beta_exp = 59,
2135
2136 .perform_agc_softsplit = 0,
2137 } , {
2138 .band_caps = BAND_FM | BAND_VHF | BAND_CBAND,
2139 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
2140 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
2141 .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
2142
2143 .inv_gain = 732,
2144 .time_stabiliz = 10,
2145
2146 .alpha_level = 0,
2147 .thlock = 118,
2148
2149 .wbd_inv = 0,
2150 .wbd_ref = 1200,
2151 .wbd_sel = 3,
2152 .wbd_alpha = 5,
2153
2154 .agc1_max = 65535,
2155 .agc1_min = 0,
2156
2157 .agc2_max = 65535,
2158 .agc2_min = 0,
2159
2160 .agc1_pt1 = 0,
2161 .agc1_pt2 = 0,
2162 .agc1_pt3 = 98,
2163 .agc1_slope1 = 0,
2164 .agc1_slope2 = 167,
2165 .agc2_pt1 = 98,
2166 .agc2_pt2 = 255,
2167 .agc2_slope1 = 104,
2168 .agc2_slope2 = 0,
2169
2170 .alpha_mant = 18,
2171 .alpha_exp = 0,
2172 .beta_mant = 20,
2173 .beta_exp = 59,
2174
2175 .perform_agc_softsplit = 0,
2176 }
2177};
2178
2179static struct dibx000_bandwidth_config dib7090_clock_config_12_mhz = {
2180 60000, 15000,
2181 1, 5, 0, 0, 0,
2182 0, 0, 1, 1, 2,
2183 (3 << 14) | (1 << 12) | (524 << 0),
2184 (0 << 25) | 0,
2185 20452225,
2186 15000000,
2187};
2188
2189static struct dib7000p_config nim7090_dib7000p_config = {
2190 .output_mpeg2_in_188_bytes = 1,
2191 .hostbus_diversity = 1,
2192 .tuner_is_baseband = 1,
2193 .update_lna = NULL,
2194
2195 .agc_config_count = 2,
2196 .agc = dib7090_agc_config,
2197
2198 .bw = &dib7090_clock_config_12_mhz,
2199
2200 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2201 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
2202 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
2203
2204 .pwm_freq_div = 0,
2205
2206 .agc_control = dib7090_agc_restart,
2207
2208 .spur_protect = 0,
2209 .disable_sample_and_hold = 0,
2210 .enable_current_mirror = 0,
2211 .diversity_delay = 0,
2212
2213 .output_mode = OUTMODE_MPEG2_FIFO,
2214 .enMpegOutput = 1,
2215};
2216
2217static struct dib7000p_config tfe7090pvr_dib7000p_config[2] = {
2218 {
2219 .output_mpeg2_in_188_bytes = 1,
2220 .hostbus_diversity = 1,
2221 .tuner_is_baseband = 1,
2222 .update_lna = NULL,
2223
2224 .agc_config_count = 2,
2225 .agc = dib7090_agc_config,
2226
2227 .bw = &dib7090_clock_config_12_mhz,
2228
2229 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2230 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
2231 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
2232
2233 .pwm_freq_div = 0,
2234
2235 .agc_control = dib7090_agc_restart,
2236
2237 .spur_protect = 0,
2238 .disable_sample_and_hold = 0,
2239 .enable_current_mirror = 0,
2240 .diversity_delay = 0,
2241
2242 .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,
2243 .default_i2c_addr = 0x90,
2244 .enMpegOutput = 1,
2245 }, {
2246 .output_mpeg2_in_188_bytes = 1,
2247 .hostbus_diversity = 1,
2248 .tuner_is_baseband = 1,
2249 .update_lna = NULL,
2250
2251 .agc_config_count = 2,
2252 .agc = dib7090_agc_config,
2253
2254 .bw = &dib7090_clock_config_12_mhz,
2255
2256 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
2257 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
2258 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
2259
2260 .pwm_freq_div = 0,
2261
2262 .agc_control = dib7090_agc_restart,
2263
2264 .spur_protect = 0,
2265 .disable_sample_and_hold = 0,
2266 .enable_current_mirror = 0,
2267 .diversity_delay = 0,
2268
2269 .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,
2270 .default_i2c_addr = 0x92,
2271 .enMpegOutput = 0,
2272 }
2273};
2274
2275static const struct dib0090_config nim7090_dib0090_config = {
2276 .io.clock_khz = 12000,
2277 .io.pll_bypass = 0,
2278 .io.pll_range = 0,
2279 .io.pll_prediv = 3,
2280 .io.pll_loopdiv = 6,
2281 .io.adc_clock_ratio = 0,
2282 .io.pll_int_loop_filt = 0,
2283 .reset = dib7090_tuner_sleep,
2284 .sleep = dib7090_tuner_sleep,
2285
2286 .freq_offset_khz_uhf = 0,
2287 .freq_offset_khz_vhf = 0,
2288
2289 .get_adc_power = dib7090_get_adc_power,
2290
2291 .clkouttobamse = 1,
2292 .analog_output = 0,
2293
2294 .wbd_vhf_offset = 0,
2295 .wbd_cband_offset = 0,
2296 .use_pwm_agc = 1,
2297 .clkoutdrive = 0,
2298
2299 .fref_clock_ratio = 0,
2300
2301 .wbd = dib7090_wbd_table,
2302
2303 .ls_cfg_pad_drv = 0,
2304 .data_tx_drv = 0,
2305 .low_if = NULL,
2306 .in_soc = 1,
2307};
2308
2309static const struct dib0090_config tfe7090pvr_dib0090_config[2] = {
2310 {
2311 .io.clock_khz = 12000,
2312 .io.pll_bypass = 0,
2313 .io.pll_range = 0,
2314 .io.pll_prediv = 3,
2315 .io.pll_loopdiv = 6,
2316 .io.adc_clock_ratio = 0,
2317 .io.pll_int_loop_filt = 0,
2318 .reset = dib7090_tuner_sleep,
2319 .sleep = dib7090_tuner_sleep,
2320
2321 .freq_offset_khz_uhf = 50,
2322 .freq_offset_khz_vhf = 70,
2323
2324 .get_adc_power = dib7090_get_adc_power,
2325
2326 .clkouttobamse = 1,
2327 .analog_output = 0,
2328
2329 .wbd_vhf_offset = 0,
2330 .wbd_cband_offset = 0,
2331 .use_pwm_agc = 1,
2332 .clkoutdrive = 0,
2333
2334 .fref_clock_ratio = 0,
2335
2336 .wbd = dib7090_wbd_table,
2337
2338 .ls_cfg_pad_drv = 0,
2339 .data_tx_drv = 0,
2340 .low_if = NULL,
2341 .in_soc = 1,
2342 }, {
2343 .io.clock_khz = 12000,
2344 .io.pll_bypass = 0,
2345 .io.pll_range = 0,
2346 .io.pll_prediv = 3,
2347 .io.pll_loopdiv = 6,
2348 .io.adc_clock_ratio = 0,
2349 .io.pll_int_loop_filt = 0,
2350 .reset = dib7090_tuner_sleep,
2351 .sleep = dib7090_tuner_sleep,
2352
2353 .freq_offset_khz_uhf = -50,
2354 .freq_offset_khz_vhf = -70,
2355
2356 .get_adc_power = dib7090_get_adc_power,
2357
2358 .clkouttobamse = 1,
2359 .analog_output = 0,
2360
2361 .wbd_vhf_offset = 0,
2362 .wbd_cband_offset = 0,
2363 .use_pwm_agc = 1,
2364 .clkoutdrive = 0,
2365
2366 .fref_clock_ratio = 0,
2367
2368 .wbd = dib7090_wbd_table,
2369
2370 .ls_cfg_pad_drv = 0,
2371 .data_tx_drv = 0,
2372 .low_if = NULL,
2373 .in_soc = 1,
2374 }
2375};
2376
2377static int nim7090_frontend_attach(struct dvb_usb_adapter *adap)
2378{
2379 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2380 msleep(20);
2381 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
2382 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
2383 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
2384 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
2385
2386 msleep(20);
2387 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2388 msleep(20);
2389 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2390
2391 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x10, &nim7090_dib7000p_config) != 0) {
2392 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", __func__);
2393 return -ENODEV;
2394 }
2395 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &nim7090_dib7000p_config);
1541 2396
1542 return adap->fe == NULL ? -ENODEV : 0; 2397 return adap->fe == NULL ? -ENODEV : 0;
1543} 2398}
1544 2399
2400static int nim7090_tuner_attach(struct dvb_usb_adapter *adap)
2401{
2402 struct dib0700_adapter_state *st = adap->priv;
2403 struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe);
2404
2405 if (dvb_attach(dib0090_register, adap->fe, tun_i2c, &nim7090_dib0090_config) == NULL)
2406 return -ENODEV;
2407
2408 dib7000p_set_gpio(adap->fe, 8, 0, 1);
2409
2410 st->set_param_save = adap->fe->ops.tuner_ops.set_params;
2411 adap->fe->ops.tuner_ops.set_params = dib7090_agc_startup;
2412 return 0;
2413}
2414
2415static int tfe7090pvr_frontend0_attach(struct dvb_usb_adapter *adap)
2416{
2417 struct dib0700_state *st = adap->dev->priv;
2418
2419 /* The TFE7090 requires the dib0700 to not be in master mode */
2420 st->disable_streaming_master_mode = 1;
2421
2422 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
2423 msleep(20);
2424 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
2425 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
2426 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
2427 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
2428
2429 msleep(20);
2430 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
2431 msleep(20);
2432 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
2433
2434 /* initialize IC 0 */
2435 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 0x20, &tfe7090pvr_dib7000p_config[0]) != 0) {
2436 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", __func__);
2437 return -ENODEV;
2438 }
2439
2440 dib0700_set_i2c_speed(adap->dev, 340);
2441 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x90, &tfe7090pvr_dib7000p_config[0]);
2442 if (adap->fe == NULL)
2443 return -ENODEV;
2444
2445 dib7090_slave_reset(adap->fe);
2446
2447 return 0;
2448}
2449
2450static int tfe7090pvr_frontend1_attach(struct dvb_usb_adapter *adap)
2451{
2452 struct i2c_adapter *i2c;
2453
2454 if (adap->dev->adapter[0].fe == NULL) {
2455 err("the master dib7090 has to be initialized first");
2456 return -ENODEV; /* the master device has not been initialized */
2457 }
2458
2459 i2c = dib7000p_get_i2c_master(adap->dev->adapter[0].fe, DIBX000_I2C_INTERFACE_GPIO_6_7, 1);
2460 if (dib7000p_i2c_enumeration(i2c, 1, 0x10, &tfe7090pvr_dib7000p_config[1]) != 0) {
2461 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", __func__);
2462 return -ENODEV;
2463 }
2464
2465 adap->fe = dvb_attach(dib7000p_attach, i2c, 0x92, &tfe7090pvr_dib7000p_config[1]);
2466 dib0700_set_i2c_speed(adap->dev, 200);
2467
2468 return adap->fe == NULL ? -ENODEV : 0;
2469}
2470
2471static int tfe7090pvr_tuner0_attach(struct dvb_usb_adapter *adap)
2472{
2473 struct dib0700_adapter_state *st = adap->priv;
2474 struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe);
2475
2476 if (dvb_attach(dib0090_register, adap->fe, tun_i2c, &tfe7090pvr_dib0090_config[0]) == NULL)
2477 return -ENODEV;
2478
2479 dib7000p_set_gpio(adap->fe, 8, 0, 1);
2480
2481 st->set_param_save = adap->fe->ops.tuner_ops.set_params;
2482 adap->fe->ops.tuner_ops.set_params = dib7090_agc_startup;
2483 return 0;
2484}
2485
2486static int tfe7090pvr_tuner1_attach(struct dvb_usb_adapter *adap)
2487{
2488 struct dib0700_adapter_state *st = adap->priv;
2489 struct i2c_adapter *tun_i2c = dib7090_get_i2c_tuner(adap->fe);
2490
2491 if (dvb_attach(dib0090_register, adap->fe, tun_i2c, &tfe7090pvr_dib0090_config[1]) == NULL)
2492 return -ENODEV;
2493
2494 dib7000p_set_gpio(adap->fe, 8, 0, 1);
2495
2496 st->set_param_save = adap->fe->ops.tuner_ops.set_params;
2497 adap->fe->ops.tuner_ops.set_params = dib7090_agc_startup;
2498 return 0;
2499}
2500
1545/* STK7070PD */ 2501/* STK7070PD */
1546static struct dib7000p_config stk7070pd_dib7000p_config[2] = { 2502static struct dib7000p_config stk7070pd_dib7000p_config[2] = {
1547 { 2503 {
@@ -1839,6 +2795,13 @@ struct usb_device_id dib0700_usb_id_table[] = {
1839 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV282E) }, 2795 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV282E) },
1840 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK8096GP) }, 2796 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK8096GP) },
1841 { USB_DEVICE(USB_VID_ELGATO, USB_PID_ELGATO_EYETV_DIVERSITY) }, 2797 { USB_DEVICE(USB_VID_ELGATO, USB_PID_ELGATO_EYETV_DIVERSITY) },
2798 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_NIM9090M) },
2799/* 70 */{ USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_NIM8096MD) },
2800 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_NIM9090MD) },
2801 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_NIM7090) },
2802 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_TFE7090PVR) },
2803 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2) },
2804/* 75 */{ USB_DEVICE(USB_VID_MEDION, USB_PID_CREATIX_CTX1921) },
1842 { 0 } /* Terminating entry */ 2805 { 0 } /* Terminating entry */
1843}; 2806};
1844MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table); 2807MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
@@ -1875,8 +2838,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1875 { 2838 {
1876 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 2839 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1877 .pid_filter_count = 32, 2840 .pid_filter_count = 32,
1878 .pid_filter = stk70x0p_pid_filter, 2841 .pid_filter = stk7700p_pid_filter,
1879 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl, 2842 .pid_filter_ctrl = stk7700p_pid_filter_ctrl,
1880 .frontend_attach = stk7700p_frontend_attach, 2843 .frontend_attach = stk7700p_frontend_attach,
1881 .tuner_attach = stk7700p_tuner_attach, 2844 .tuner_attach = stk7700p_tuner_attach,
1882 2845
@@ -1924,12 +2887,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1924 .rc_interval = DEFAULT_RC_INTERVAL, 2887 .rc_interval = DEFAULT_RC_INTERVAL,
1925 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2888 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
1926 .rc_query = dib0700_rc_query_old_firmware, 2889 .rc_query = dib0700_rc_query_old_firmware,
1927 .rc_props = { 2890 .allowed_protos = RC_TYPE_RC5 |
1928 .allowed_protos = IR_TYPE_RC5 | 2891 RC_TYPE_RC6 |
1929 IR_TYPE_RC6 | 2892 RC_TYPE_NEC,
1930 IR_TYPE_NEC, 2893 .change_protocol = dib0700_change_protocol,
1931 .change_protocol = dib0700_change_protocol,
1932 },
1933 }, 2894 },
1934 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2895 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
1935 2896
@@ -1960,12 +2921,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1960 .rc_interval = DEFAULT_RC_INTERVAL, 2921 .rc_interval = DEFAULT_RC_INTERVAL,
1961 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2922 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
1962 .rc_query = dib0700_rc_query_old_firmware, 2923 .rc_query = dib0700_rc_query_old_firmware,
1963 .rc_props = { 2924 .allowed_protos = RC_TYPE_RC5 |
1964 .allowed_protos = IR_TYPE_RC5 | 2925 RC_TYPE_RC6 |
1965 IR_TYPE_RC6 | 2926 RC_TYPE_NEC,
1966 IR_TYPE_NEC, 2927 .change_protocol = dib0700_change_protocol,
1967 .change_protocol = dib0700_change_protocol,
1968 },
1969 }, 2928 },
1970 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2929 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
1971 2930
@@ -2021,12 +2980,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2021 .rc_interval = DEFAULT_RC_INTERVAL, 2980 .rc_interval = DEFAULT_RC_INTERVAL,
2022 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2981 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2023 .rc_query = dib0700_rc_query_old_firmware, 2982 .rc_query = dib0700_rc_query_old_firmware,
2024 .rc_props = { 2983 .allowed_protos = RC_TYPE_RC5 |
2025 .allowed_protos = IR_TYPE_RC5 | 2984 RC_TYPE_RC6 |
2026 IR_TYPE_RC6 | 2985 RC_TYPE_NEC,
2027 IR_TYPE_NEC, 2986 .change_protocol = dib0700_change_protocol,
2028 .change_protocol = dib0700_change_protocol,
2029 },
2030 }, 2987 },
2031 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2988 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2032 2989
@@ -2065,12 +3022,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2065 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 3022 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2066 .module_name = "dib0700", 3023 .module_name = "dib0700",
2067 .rc_query = dib0700_rc_query_old_firmware, 3024 .rc_query = dib0700_rc_query_old_firmware,
2068 .rc_props = { 3025 .allowed_protos = RC_TYPE_RC5 |
2069 .allowed_protos = IR_TYPE_RC5 | 3026 RC_TYPE_RC6 |
2070 IR_TYPE_RC6 | 3027 RC_TYPE_NEC,
2071 IR_TYPE_NEC, 3028 .change_protocol = dib0700_change_protocol,
2072 .change_protocol = dib0700_change_protocol,
2073 },
2074 }, 3029 },
2075 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 3030 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2076 3031
@@ -2143,12 +3098,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2143 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 3098 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2144 .module_name = "dib0700", 3099 .module_name = "dib0700",
2145 .rc_query = dib0700_rc_query_old_firmware, 3100 .rc_query = dib0700_rc_query_old_firmware,
2146 .rc_props = { 3101 .allowed_protos = RC_TYPE_RC5 |
2147 .allowed_protos = IR_TYPE_RC5 | 3102 RC_TYPE_RC6 |
2148 IR_TYPE_RC6 | 3103 RC_TYPE_NEC,
2149 IR_TYPE_NEC, 3104 .change_protocol = dib0700_change_protocol,
2150 .change_protocol = dib0700_change_protocol,
2151 },
2152 }, 3105 },
2153 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 3106 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2154 3107
@@ -2189,12 +3142,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2189 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 3142 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2190 .module_name = "dib0700", 3143 .module_name = "dib0700",
2191 .rc_query = dib0700_rc_query_old_firmware, 3144 .rc_query = dib0700_rc_query_old_firmware,
2192 .rc_props = { 3145 .allowed_protos = RC_TYPE_RC5 |
2193 .allowed_protos = IR_TYPE_RC5 | 3146 RC_TYPE_RC6 |
2194 IR_TYPE_RC6 | 3147 RC_TYPE_NEC,
2195 IR_TYPE_NEC, 3148 .change_protocol = dib0700_change_protocol,
2196 .change_protocol = dib0700_change_protocol,
2197 },
2198 }, 3149 },
2199 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 3150 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2200 3151
@@ -2259,12 +3210,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2259 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 3210 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2260 .module_name = "dib0700", 3211 .module_name = "dib0700",
2261 .rc_query = dib0700_rc_query_old_firmware, 3212 .rc_query = dib0700_rc_query_old_firmware,
2262 .rc_props = { 3213 .allowed_protos = RC_TYPE_RC5 |
2263 .allowed_protos = IR_TYPE_RC5 | 3214 RC_TYPE_RC6 |
2264 IR_TYPE_RC6 | 3215 RC_TYPE_NEC,
2265 IR_TYPE_NEC, 3216 .change_protocol = dib0700_change_protocol,
2266 .change_protocol = dib0700_change_protocol,
2267 },
2268 }, 3217 },
2269 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 3218 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2270 3219
@@ -2308,12 +3257,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2308 .rc_codes = RC_MAP_DIB0700_NEC_TABLE, 3257 .rc_codes = RC_MAP_DIB0700_NEC_TABLE,
2309 .module_name = "dib0700", 3258 .module_name = "dib0700",
2310 .rc_query = dib0700_rc_query_old_firmware, 3259 .rc_query = dib0700_rc_query_old_firmware,
2311 .rc_props = { 3260 .allowed_protos = RC_TYPE_RC5 |
2312 .allowed_protos = IR_TYPE_RC5 | 3261 RC_TYPE_RC6 |
2313 IR_TYPE_RC6 | 3262 RC_TYPE_NEC,
2314 IR_TYPE_NEC, 3263 .change_protocol = dib0700_change_protocol,
2315 .change_protocol = dib0700_change_protocol,
2316 },
2317 }, 3264 },
2318 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 3265 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2319 3266
@@ -2379,12 +3326,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2379 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 3326 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2380 .module_name = "dib0700", 3327 .module_name = "dib0700",
2381 .rc_query = dib0700_rc_query_old_firmware, 3328 .rc_query = dib0700_rc_query_old_firmware,
2382 .rc_props = { 3329 .allowed_protos = RC_TYPE_RC5 |
2383 .allowed_protos = IR_TYPE_RC5 | 3330 RC_TYPE_RC6 |
2384 IR_TYPE_RC6 | 3331 RC_TYPE_NEC,
2385 IR_TYPE_NEC, 3332 .change_protocol = dib0700_change_protocol,
2386 .change_protocol = dib0700_change_protocol,
2387 },
2388 }, 3333 },
2389 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 3334 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2390 .num_adapters = 1, 3335 .num_adapters = 1,
@@ -2417,12 +3362,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2417 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 3362 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2418 .module_name = "dib0700", 3363 .module_name = "dib0700",
2419 .rc_query = dib0700_rc_query_old_firmware, 3364 .rc_query = dib0700_rc_query_old_firmware,
2420 .rc_props = { 3365 .allowed_protos = RC_TYPE_RC5 |
2421 .allowed_protos = IR_TYPE_RC5 | 3366 RC_TYPE_RC6 |
2422 IR_TYPE_RC6 | 3367 RC_TYPE_NEC,
2423 IR_TYPE_NEC, 3368 .change_protocol = dib0700_change_protocol,
2424 .change_protocol = dib0700_change_protocol,
2425 },
2426 }, 3369 },
2427 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 3370 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2428 .num_adapters = 1, 3371 .num_adapters = 1,
@@ -2468,7 +3411,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2468 }, 3411 },
2469 }, 3412 },
2470 3413
2471 .num_device_descs = 2, 3414 .num_device_descs = 4,
2472 .devices = { 3415 .devices = {
2473 { "DiBcom STK7770P reference design", 3416 { "DiBcom STK7770P reference design",
2474 { &dib0700_usb_id_table[59], NULL }, 3417 { &dib0700_usb_id_table[59], NULL },
@@ -2480,6 +3423,14 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2480 &dib0700_usb_id_table[60], NULL}, 3423 &dib0700_usb_id_table[60], NULL},
2481 { NULL }, 3424 { NULL },
2482 }, 3425 },
3426 { "TechniSat AirStar TeleStick 2",
3427 { &dib0700_usb_id_table[74], NULL },
3428 { NULL },
3429 },
3430 { "Medion CTX1921 DVB-T USB",
3431 { &dib0700_usb_id_table[75], NULL },
3432 { NULL },
3433 },
2483 }, 3434 },
2484 3435
2485 .rc.core = { 3436 .rc.core = {
@@ -2487,12 +3438,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2487 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 3438 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2488 .module_name = "dib0700", 3439 .module_name = "dib0700",
2489 .rc_query = dib0700_rc_query_old_firmware, 3440 .rc_query = dib0700_rc_query_old_firmware,
2490 .rc_props = { 3441 .allowed_protos = RC_TYPE_RC5 |
2491 .allowed_protos = IR_TYPE_RC5 | 3442 RC_TYPE_RC6 |
2492 IR_TYPE_RC6 | 3443 RC_TYPE_NEC,
2493 IR_TYPE_NEC, 3444 .change_protocol = dib0700_change_protocol,
2494 .change_protocol = dib0700_change_protocol,
2495 },
2496 }, 3445 },
2497 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 3446 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2498 .num_adapters = 1, 3447 .num_adapters = 1,
@@ -2533,12 +3482,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2533 .rc_codes = RC_MAP_DIB0700_NEC_TABLE, 3482 .rc_codes = RC_MAP_DIB0700_NEC_TABLE,
2534 .module_name = "dib0700", 3483 .module_name = "dib0700",
2535 .rc_query = dib0700_rc_query_old_firmware, 3484 .rc_query = dib0700_rc_query_old_firmware,
2536 .rc_props = { 3485 .allowed_protos = RC_TYPE_RC5 |
2537 .allowed_protos = IR_TYPE_RC5 | 3486 RC_TYPE_RC6 |
2538 IR_TYPE_RC6 | 3487 RC_TYPE_NEC,
2539 IR_TYPE_NEC, 3488 .change_protocol = dib0700_change_protocol,
2540 .change_protocol = dib0700_change_protocol,
2541 },
2542 }, 3489 },
2543 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 3490 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2544 .num_adapters = 2, 3491 .num_adapters = 2,
@@ -2584,12 +3531,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2584 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 3531 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2585 .module_name = "dib0700", 3532 .module_name = "dib0700",
2586 .rc_query = dib0700_rc_query_old_firmware, 3533 .rc_query = dib0700_rc_query_old_firmware,
2587 .rc_props = { 3534 .allowed_protos = RC_TYPE_RC5 |
2588 .allowed_protos = IR_TYPE_RC5 | 3535 RC_TYPE_RC6 |
2589 IR_TYPE_RC6 | 3536 RC_TYPE_NEC,
2590 IR_TYPE_NEC, 3537 .change_protocol = dib0700_change_protocol,
2591 .change_protocol = dib0700_change_protocol,
2592 },
2593 }, 3538 },
2594 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 3539 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2595 .num_adapters = 1, 3540 .num_adapters = 1,
@@ -2623,13 +3568,210 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2623 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 3568 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2624 .module_name = "dib0700", 3569 .module_name = "dib0700",
2625 .rc_query = dib0700_rc_query_old_firmware, 3570 .rc_query = dib0700_rc_query_old_firmware,
2626 .rc_props = { 3571 .allowed_protos = RC_TYPE_RC5 |
2627 .allowed_protos = IR_TYPE_RC5 | 3572 RC_TYPE_RC6 |
2628 IR_TYPE_RC6 | 3573 RC_TYPE_NEC,
2629 IR_TYPE_NEC, 3574 .change_protocol = dib0700_change_protocol,
2630 .change_protocol = dib0700_change_protocol, 3575 },
3576 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3577 .num_adapters = 1,
3578 .adapter = {
3579 {
3580 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
3581 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3582 .pid_filter_count = 32,
3583 .pid_filter = dib90x0_pid_filter,
3584 .pid_filter_ctrl = dib90x0_pid_filter_ctrl,
3585 .frontend_attach = stk9090m_frontend_attach,
3586 .tuner_attach = dib9090_tuner_attach,
3587
3588 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3589
3590 .size_of_priv =
3591 sizeof(struct dib0700_adapter_state),
3592 },
3593 },
3594
3595 .num_device_descs = 1,
3596 .devices = {
3597 { "DiBcom STK9090M reference design",
3598 { &dib0700_usb_id_table[69], NULL },
3599 { NULL },
3600 },
3601 },
3602
3603 .rc.core = {
3604 .rc_interval = DEFAULT_RC_INTERVAL,
3605 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
3606 .module_name = "dib0700",
3607 .rc_query = dib0700_rc_query_old_firmware,
3608 .allowed_protos = RC_TYPE_RC5 |
3609 RC_TYPE_RC6 |
3610 RC_TYPE_NEC,
3611 .change_protocol = dib0700_change_protocol,
3612 },
3613 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3614 .num_adapters = 1,
3615 .adapter = {
3616 {
3617 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
3618 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3619 .pid_filter_count = 32,
3620 .pid_filter = stk80xx_pid_filter,
3621 .pid_filter_ctrl = stk80xx_pid_filter_ctrl,
3622 .frontend_attach = nim8096md_frontend_attach,
3623 .tuner_attach = nim8096md_tuner_attach,
3624
3625 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3626
3627 .size_of_priv =
3628 sizeof(struct dib0700_adapter_state),
3629 },
3630 },
3631
3632 .num_device_descs = 1,
3633 .devices = {
3634 { "DiBcom NIM8096MD reference design",
3635 { &dib0700_usb_id_table[70], NULL },
3636 { NULL },
3637 },
3638 },
3639
3640 .rc.core = {
3641 .rc_interval = DEFAULT_RC_INTERVAL,
3642 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
3643 .module_name = "dib0700",
3644 .rc_query = dib0700_rc_query_old_firmware,
3645 .allowed_protos = RC_TYPE_RC5 |
3646 RC_TYPE_RC6 |
3647 RC_TYPE_NEC,
3648 .change_protocol = dib0700_change_protocol,
3649 },
3650 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3651 .num_adapters = 1,
3652 .adapter = {
3653 {
3654 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
3655 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3656 .pid_filter_count = 32,
3657 .pid_filter = dib90x0_pid_filter,
3658 .pid_filter_ctrl = dib90x0_pid_filter_ctrl,
3659 .frontend_attach = nim9090md_frontend_attach,
3660 .tuner_attach = nim9090md_tuner_attach,
3661
3662 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3663
3664 .size_of_priv =
3665 sizeof(struct dib0700_adapter_state),
3666 },
3667 },
3668
3669 .num_device_descs = 1,
3670 .devices = {
3671 { "DiBcom NIM9090MD reference design",
3672 { &dib0700_usb_id_table[71], NULL },
3673 { NULL },
2631 }, 3674 },
2632 }, 3675 },
3676
3677 .rc.core = {
3678 .rc_interval = DEFAULT_RC_INTERVAL,
3679 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
3680 .module_name = "dib0700",
3681 .rc_query = dib0700_rc_query_old_firmware,
3682 .allowed_protos = RC_TYPE_RC5 |
3683 RC_TYPE_RC6 |
3684 RC_TYPE_NEC,
3685 .change_protocol = dib0700_change_protocol,
3686 },
3687 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3688 .num_adapters = 1,
3689 .adapter = {
3690 {
3691 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
3692 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3693 .pid_filter_count = 32,
3694 .pid_filter = stk70x0p_pid_filter,
3695 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
3696 .frontend_attach = nim7090_frontend_attach,
3697 .tuner_attach = nim7090_tuner_attach,
3698
3699 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3700
3701 .size_of_priv =
3702 sizeof(struct dib0700_adapter_state),
3703 },
3704 },
3705
3706 .num_device_descs = 1,
3707 .devices = {
3708 { "DiBcom NIM7090 reference design",
3709 { &dib0700_usb_id_table[72], NULL },
3710 { NULL },
3711 },
3712 },
3713
3714 .rc.core = {
3715 .rc_interval = DEFAULT_RC_INTERVAL,
3716 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
3717 .module_name = "dib0700",
3718 .rc_query = dib0700_rc_query_old_firmware,
3719 .allowed_protos = RC_TYPE_RC5 |
3720 RC_TYPE_RC6 |
3721 RC_TYPE_NEC,
3722 .change_protocol = dib0700_change_protocol,
3723 },
3724 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
3725 .num_adapters = 2,
3726 .adapter = {
3727 {
3728 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
3729 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3730 .pid_filter_count = 32,
3731 .pid_filter = stk70x0p_pid_filter,
3732 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
3733 .frontend_attach = tfe7090pvr_frontend0_attach,
3734 .tuner_attach = tfe7090pvr_tuner0_attach,
3735
3736 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
3737
3738 .size_of_priv =
3739 sizeof(struct dib0700_adapter_state),
3740 },
3741 {
3742 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
3743 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
3744 .pid_filter_count = 32,
3745 .pid_filter = stk70x0p_pid_filter,
3746 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
3747 .frontend_attach = tfe7090pvr_frontend1_attach,
3748 .tuner_attach = tfe7090pvr_tuner1_attach,
3749
3750 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
3751
3752 .size_of_priv =
3753 sizeof(struct dib0700_adapter_state),
3754 },
3755 },
3756
3757 .num_device_descs = 1,
3758 .devices = {
3759 { "DiBcom TFE7090PVR reference design",
3760 { &dib0700_usb_id_table[73], NULL },
3761 { NULL },
3762 },
3763 },
3764
3765 .rc.core = {
3766 .rc_interval = DEFAULT_RC_INTERVAL,
3767 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
3768 .module_name = "dib0700",
3769 .rc_query = dib0700_rc_query_old_firmware,
3770 .allowed_protos = RC_TYPE_RC5 |
3771 RC_TYPE_RC6 |
3772 RC_TYPE_NEC,
3773 .change_protocol = dib0700_change_protocol,
3774 },
2633 }, 3775 },
2634}; 3776};
2635 3777
diff --git a/drivers/media/dvb/dvb-usb/dibusb-common.c b/drivers/media/dvb/dvb-usb/dibusb-common.c
index ba991aa21aff..4c2a689c820e 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-common.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-common.c
@@ -327,7 +327,7 @@ EXPORT_SYMBOL(dibusb_dib3000mc_tuner_attach);
327/* 327/*
328 * common remote control stuff 328 * common remote control stuff
329 */ 329 */
330struct ir_scancode ir_codes_dibusb_table[] = { 330struct rc_map_table rc_map_dibusb_table[] = {
331 /* Key codes for the little Artec T1/Twinhan/HAMA/ remote. */ 331 /* Key codes for the little Artec T1/Twinhan/HAMA/ remote. */
332 { 0x0016, KEY_POWER }, 332 { 0x0016, KEY_POWER },
333 { 0x0010, KEY_MUTE }, 333 { 0x0010, KEY_MUTE },
@@ -408,7 +408,7 @@ struct ir_scancode ir_codes_dibusb_table[] = {
408 408
409 { 0x8008, KEY_DVD }, 409 { 0x8008, KEY_DVD },
410 { 0x8009, KEY_AUDIO }, 410 { 0x8009, KEY_AUDIO },
411 { 0x800a, KEY_MEDIA }, /* Pictures */ 411 { 0x800a, KEY_IMAGES }, /* Pictures */
412 { 0x800b, KEY_VIDEO }, 412 { 0x800b, KEY_VIDEO },
413 413
414 { 0x800c, KEY_BACK }, 414 { 0x800c, KEY_BACK },
@@ -456,7 +456,7 @@ struct ir_scancode ir_codes_dibusb_table[] = {
456 { 0x804e, KEY_ENTER }, 456 { 0x804e, KEY_ENTER },
457 { 0x804f, KEY_VOLUMEDOWN }, 457 { 0x804f, KEY_VOLUMEDOWN },
458}; 458};
459EXPORT_SYMBOL(ir_codes_dibusb_table); 459EXPORT_SYMBOL(rc_map_dibusb_table);
460 460
461int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 461int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
462{ 462{
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mb.c b/drivers/media/dvb/dvb-usb/dibusb-mb.c
index 8e3c0d2cce16..04d91bdd3562 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mb.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mb.c
@@ -213,8 +213,8 @@ static struct dvb_usb_device_properties dibusb1_1_properties = {
213 213
214 .rc.legacy = { 214 .rc.legacy = {
215 .rc_interval = DEFAULT_RC_INTERVAL, 215 .rc_interval = DEFAULT_RC_INTERVAL,
216 .rc_key_map = ir_codes_dibusb_table, 216 .rc_map_table = rc_map_dibusb_table,
217 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 217 .rc_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
218 .rc_query = dibusb_rc_query, 218 .rc_query = dibusb_rc_query,
219 }, 219 },
220 220
@@ -299,8 +299,8 @@ static struct dvb_usb_device_properties dibusb1_1_an2235_properties = {
299 299
300 .rc.legacy = { 300 .rc.legacy = {
301 .rc_interval = DEFAULT_RC_INTERVAL, 301 .rc_interval = DEFAULT_RC_INTERVAL,
302 .rc_key_map = ir_codes_dibusb_table, 302 .rc_map_table = rc_map_dibusb_table,
303 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 303 .rc_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
304 .rc_query = dibusb_rc_query, 304 .rc_query = dibusb_rc_query,
305 }, 305 },
306 306
@@ -365,8 +365,8 @@ static struct dvb_usb_device_properties dibusb2_0b_properties = {
365 365
366 .rc.legacy = { 366 .rc.legacy = {
367 .rc_interval = DEFAULT_RC_INTERVAL, 367 .rc_interval = DEFAULT_RC_INTERVAL,
368 .rc_key_map = ir_codes_dibusb_table, 368 .rc_map_table = rc_map_dibusb_table,
369 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 369 .rc_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
370 .rc_query = dibusb_rc_query, 370 .rc_query = dibusb_rc_query,
371 }, 371 },
372 372
@@ -424,8 +424,8 @@ static struct dvb_usb_device_properties artec_t1_usb2_properties = {
424 424
425 .rc.legacy = { 425 .rc.legacy = {
426 .rc_interval = DEFAULT_RC_INTERVAL, 426 .rc_interval = DEFAULT_RC_INTERVAL,
427 .rc_key_map = ir_codes_dibusb_table, 427 .rc_map_table = rc_map_dibusb_table,
428 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 428 .rc_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
429 .rc_query = dibusb_rc_query, 429 .rc_query = dibusb_rc_query,
430 }, 430 },
431 431
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mc.c b/drivers/media/dvb/dvb-usb/dibusb-mc.c
index 1cbc41cb4e8f..c1d9094b61e5 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mc.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mc.c
@@ -83,8 +83,8 @@ static struct dvb_usb_device_properties dibusb_mc_properties = {
83 83
84 .rc.legacy = { 84 .rc.legacy = {
85 .rc_interval = DEFAULT_RC_INTERVAL, 85 .rc_interval = DEFAULT_RC_INTERVAL,
86 .rc_key_map = ir_codes_dibusb_table, 86 .rc_map_table = rc_map_dibusb_table,
87 .rc_key_map_size = 111, /* FIXME */ 87 .rc_map_size = 111, /* FIXME */
88 .rc_query = dibusb_rc_query, 88 .rc_query = dibusb_rc_query,
89 }, 89 },
90 90
diff --git a/drivers/media/dvb/dvb-usb/dibusb.h b/drivers/media/dvb/dvb-usb/dibusb.h
index 61a6bf389472..e47c321b3ffc 100644
--- a/drivers/media/dvb/dvb-usb/dibusb.h
+++ b/drivers/media/dvb/dvb-usb/dibusb.h
@@ -124,7 +124,7 @@ extern int dibusb2_0_power_ctrl(struct dvb_usb_device *, int);
124#define DEFAULT_RC_INTERVAL 150 124#define DEFAULT_RC_INTERVAL 150
125//#define DEFAULT_RC_INTERVAL 100000 125//#define DEFAULT_RC_INTERVAL 100000
126 126
127extern struct ir_scancode ir_codes_dibusb_table[]; 127extern struct rc_map_table rc_map_dibusb_table[];
128extern int dibusb_rc_query(struct dvb_usb_device *, u32 *, int *); 128extern int dibusb_rc_query(struct dvb_usb_device *, u32 *, int *);
129extern int dibusb_read_eeprom_byte(struct dvb_usb_device *, u8, u8 *); 129extern int dibusb_read_eeprom_byte(struct dvb_usb_device *, u8, u8 *);
130 130
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
index 13d006bb19db..f6344cdd360f 100644
--- a/drivers/media/dvb/dvb-usb/digitv.c
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -161,7 +161,7 @@ static int digitv_tuner_attach(struct dvb_usb_adapter *adap)
161 return 0; 161 return 0;
162} 162}
163 163
164static struct ir_scancode ir_codes_digitv_table[] = { 164static struct rc_map_table rc_map_digitv_table[] = {
165 { 0x5f55, KEY_0 }, 165 { 0x5f55, KEY_0 },
166 { 0x6f55, KEY_1 }, 166 { 0x6f55, KEY_1 },
167 { 0x9f55, KEY_2 }, 167 { 0x9f55, KEY_2 },
@@ -176,7 +176,7 @@ static struct ir_scancode ir_codes_digitv_table[] = {
176 { 0xaf59, KEY_AUX }, 176 { 0xaf59, KEY_AUX },
177 { 0x5f5a, KEY_DVD }, 177 { 0x5f5a, KEY_DVD },
178 { 0x6f5a, KEY_POWER }, 178 { 0x6f5a, KEY_POWER },
179 { 0x9f5a, KEY_MHP }, /* labelled 'Picture' */ 179 { 0x9f5a, KEY_CAMERA }, /* labelled 'Picture' */
180 { 0xaf5a, KEY_AUDIO }, 180 { 0xaf5a, KEY_AUDIO },
181 { 0x5f65, KEY_INFO }, 181 { 0x5f65, KEY_INFO },
182 { 0x6f65, KEY_F13 }, /* 16:9 */ 182 { 0x6f65, KEY_F13 }, /* 16:9 */
@@ -237,10 +237,10 @@ static int digitv_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
237 /* if something is inside the buffer, simulate key press */ 237 /* if something is inside the buffer, simulate key press */
238 if (key[1] != 0) 238 if (key[1] != 0)
239 { 239 {
240 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { 240 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
241 if (rc5_custom(&d->props.rc.legacy.rc_key_map[i]) == key[1] && 241 if (rc5_custom(&d->props.rc.legacy.rc_map_table[i]) == key[1] &&
242 rc5_data(&d->props.rc.legacy.rc_key_map[i]) == key[2]) { 242 rc5_data(&d->props.rc.legacy.rc_map_table[i]) == key[2]) {
243 *event = d->props.rc.legacy.rc_key_map[i].keycode; 243 *event = d->props.rc.legacy.rc_map_table[i].keycode;
244 *state = REMOTE_KEY_PRESSED; 244 *state = REMOTE_KEY_PRESSED;
245 return 0; 245 return 0;
246 } 246 }
@@ -312,8 +312,8 @@ static struct dvb_usb_device_properties digitv_properties = {
312 312
313 .rc.legacy = { 313 .rc.legacy = {
314 .rc_interval = 1000, 314 .rc_interval = 1000,
315 .rc_key_map = ir_codes_digitv_table, 315 .rc_map_table = rc_map_digitv_table,
316 .rc_key_map_size = ARRAY_SIZE(ir_codes_digitv_table), 316 .rc_map_size = ARRAY_SIZE(rc_map_digitv_table),
317 .rc_query = digitv_rc_query, 317 .rc_query = digitv_rc_query,
318 }, 318 },
319 319
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
index ca495e07f35c..ecd86eca2548 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u.c
@@ -57,7 +57,7 @@ static int dtt200u_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
57 57
58/* remote control */ 58/* remote control */
59/* key list for the tiny remote control (Yakumo, don't know about the others) */ 59/* key list for the tiny remote control (Yakumo, don't know about the others) */
60static struct ir_scancode ir_codes_dtt200u_table[] = { 60static struct rc_map_table rc_map_dtt200u_table[] = {
61 { 0x8001, KEY_MUTE }, 61 { 0x8001, KEY_MUTE },
62 { 0x8002, KEY_CHANNELDOWN }, 62 { 0x8002, KEY_CHANNELDOWN },
63 { 0x8003, KEY_VOLUMEDOWN }, 63 { 0x8003, KEY_VOLUMEDOWN },
@@ -163,8 +163,8 @@ static struct dvb_usb_device_properties dtt200u_properties = {
163 163
164 .rc.legacy = { 164 .rc.legacy = {
165 .rc_interval = 300, 165 .rc_interval = 300,
166 .rc_key_map = ir_codes_dtt200u_table, 166 .rc_map_table = rc_map_dtt200u_table,
167 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 167 .rc_map_size = ARRAY_SIZE(rc_map_dtt200u_table),
168 .rc_query = dtt200u_rc_query, 168 .rc_query = dtt200u_rc_query,
169 }, 169 },
170 170
@@ -210,8 +210,8 @@ static struct dvb_usb_device_properties wt220u_properties = {
210 210
211 .rc.legacy = { 211 .rc.legacy = {
212 .rc_interval = 300, 212 .rc_interval = 300,
213 .rc_key_map = ir_codes_dtt200u_table, 213 .rc_map_table = rc_map_dtt200u_table,
214 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 214 .rc_map_size = ARRAY_SIZE(rc_map_dtt200u_table),
215 .rc_query = dtt200u_rc_query, 215 .rc_query = dtt200u_rc_query,
216 }, 216 },
217 217
@@ -257,8 +257,8 @@ static struct dvb_usb_device_properties wt220u_fc_properties = {
257 257
258 .rc.legacy = { 258 .rc.legacy = {
259 .rc_interval = 300, 259 .rc_interval = 300,
260 .rc_key_map = ir_codes_dtt200u_table, 260 .rc_map_table = rc_map_dtt200u_table,
261 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 261 .rc_map_size = ARRAY_SIZE(rc_map_dtt200u_table),
262 .rc_query = dtt200u_rc_query, 262 .rc_query = dtt200u_rc_query,
263 }, 263 },
264 264
@@ -304,8 +304,8 @@ static struct dvb_usb_device_properties wt220u_zl0353_properties = {
304 304
305 .rc.legacy = { 305 .rc.legacy = {
306 .rc_interval = 300, 306 .rc_interval = 300,
307 .rc_key_map = ir_codes_dtt200u_table, 307 .rc_map_table = rc_map_dtt200u_table,
308 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 308 .rc_map_size = ARRAY_SIZE(rc_map_dtt200u_table),
309 .rc_query = dtt200u_rc_query, 309 .rc_query = dtt200u_rc_query,
310 }, 310 },
311 311
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
index df1ec3e69f4a..b3cb626ed56e 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
@@ -12,7 +12,7 @@
12static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff) 12static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
13{ 13{
14 struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv; 14 struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv;
15 int newfeedcount,ret; 15 int newfeedcount, ret;
16 16
17 if (adap == NULL) 17 if (adap == NULL)
18 return -ENODEV; 18 return -ENODEV;
@@ -24,9 +24,13 @@ static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
24 deb_ts("stop feeding\n"); 24 deb_ts("stop feeding\n");
25 usb_urb_kill(&adap->stream); 25 usb_urb_kill(&adap->stream);
26 26
27 if (adap->props.streaming_ctrl != NULL) 27 if (adap->props.streaming_ctrl != NULL) {
28 if ((ret = adap->props.streaming_ctrl(adap,0))) 28 ret = adap->props.streaming_ctrl(adap, 0);
29 if (ret < 0) {
29 err("error while stopping stream."); 30 err("error while stopping stream.");
31 return ret;
32 }
33 }
30 } 34 }
31 35
32 adap->feedcount = newfeedcount; 36 adap->feedcount = newfeedcount;
@@ -49,17 +53,24 @@ static int dvb_usb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
49 53
50 deb_ts("controlling pid parser\n"); 54 deb_ts("controlling pid parser\n");
51 if (adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER && 55 if (adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER &&
52 adap->props.caps & DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF && 56 adap->props.caps &
53 adap->props.pid_filter_ctrl != NULL) 57 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF &&
54 if (adap->props.pid_filter_ctrl(adap,adap->pid_filtering) < 0) 58 adap->props.pid_filter_ctrl != NULL) {
59 ret = adap->props.pid_filter_ctrl(adap,
60 adap->pid_filtering);
61 if (ret < 0) {
55 err("could not handle pid_parser"); 62 err("could not handle pid_parser");
56 63 return ret;
64 }
65 }
57 deb_ts("start feeding\n"); 66 deb_ts("start feeding\n");
58 if (adap->props.streaming_ctrl != NULL) 67 if (adap->props.streaming_ctrl != NULL) {
59 if (adap->props.streaming_ctrl(adap,1)) { 68 ret = adap->props.streaming_ctrl(adap, 1);
69 if (ret < 0) {
60 err("error while enabling fifo."); 70 err("error while enabling fifo.");
61 return -ENODEV; 71 return ret;
62 } 72 }
73 }
63 74
64 } 75 }
65 return 0; 76 return 0;
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
index cead089bbb4f..88e4a62abc44 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
@@ -20,7 +20,6 @@ int dvb_usb_i2c_init(struct dvb_usb_device *d)
20 } 20 }
21 21
22 strlcpy(d->i2c_adap.name, d->desc->name, sizeof(d->i2c_adap.name)); 22 strlcpy(d->i2c_adap.name, d->desc->name, sizeof(d->i2c_adap.name));
23 d->i2c_adap.class = I2C_CLASS_TV_DIGITAL,
24 d->i2c_adap.algo = d->props.i2c_algo; 23 d->i2c_adap.algo = d->props.i2c_algo;
25 d->i2c_adap.algo_data = NULL; 24 d->i2c_adap.algo_data = NULL;
26 d->i2c_adap.dev.parent = &d->udev->dev; 25 d->i2c_adap.dev.parent = &d->udev->dev;
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 1a774d58d664..21b15495d2d7 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -32,6 +32,7 @@
32#define USB_VID_EMPIA 0xeb1a 32#define USB_VID_EMPIA 0xeb1a
33#define USB_VID_GENPIX 0x09c0 33#define USB_VID_GENPIX 0x09c0
34#define USB_VID_GRANDTEC 0x5032 34#define USB_VID_GRANDTEC 0x5032
35#define USB_VID_GTEK 0x1f4d
35#define USB_VID_HANFTEK 0x15f4 36#define USB_VID_HANFTEK 0x15f4
36#define USB_VID_HAUPPAUGE 0x2040 37#define USB_VID_HAUPPAUGE 0x2040
37#define USB_VID_HYPER_PALTEK 0x1025 38#define USB_VID_HYPER_PALTEK 0x1025
@@ -90,6 +91,7 @@
90#define USB_PID_COMPRO_VIDEOMATE_U500_PC 0x1e80 91#define USB_PID_COMPRO_VIDEOMATE_U500_PC 0x1e80
91#define USB_PID_CONCEPTRONIC_CTVDIGRCU 0xe397 92#define USB_PID_CONCEPTRONIC_CTVDIGRCU 0xe397
92#define USB_PID_CONEXANT_D680_DMB 0x86d6 93#define USB_PID_CONEXANT_D680_DMB 0x86d6
94#define USB_PID_CREATIX_CTX1921 0x1921
93#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064 95#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064
94#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065 96#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065
95#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8 97#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8
@@ -105,8 +107,13 @@
105#define USB_PID_DIBCOM_STK807XP 0x1f90 107#define USB_PID_DIBCOM_STK807XP 0x1f90
106#define USB_PID_DIBCOM_STK807XPVR 0x1f98 108#define USB_PID_DIBCOM_STK807XPVR 0x1f98
107#define USB_PID_DIBCOM_STK8096GP 0x1fa0 109#define USB_PID_DIBCOM_STK8096GP 0x1fa0
110#define USB_PID_DIBCOM_NIM8096MD 0x1fa8
108#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131 111#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131
109#define USB_PID_DIBCOM_STK7770P 0x1e80 112#define USB_PID_DIBCOM_STK7770P 0x1e80
113#define USB_PID_DIBCOM_NIM7090 0x1bb2
114#define USB_PID_DIBCOM_TFE7090PVR 0x1bb4
115#define USB_PID_DIBCOM_NIM9090M 0x2383
116#define USB_PID_DIBCOM_NIM9090MD 0x2384
110#define USB_PID_DPOSH_M9206_COLD 0x9206 117#define USB_PID_DPOSH_M9206_COLD 0x9206
111#define USB_PID_DPOSH_M9206_WARM 0xa090 118#define USB_PID_DPOSH_M9206_WARM 0xa090
112#define USB_PID_E3C_EC168 0x1689 119#define USB_PID_E3C_EC168 0x1689
@@ -133,6 +140,8 @@
133#define USB_PID_KWORLD_VSTREAM_WARM 0x17df 140#define USB_PID_KWORLD_VSTREAM_WARM 0x17df
134#define USB_PID_TERRATEC_CINERGY_T_USB_XE 0x0055 141#define USB_PID_TERRATEC_CINERGY_T_USB_XE 0x0055
135#define USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2 0x0069 142#define USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2 0x0069
143#define USB_PID_TERRATEC_CINERGY_T_STICK_RC 0x0097
144#define USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC 0x0099
136#define USB_PID_TWINHAN_VP7041_COLD 0x3201 145#define USB_PID_TWINHAN_VP7041_COLD 0x3201
137#define USB_PID_TWINHAN_VP7041_WARM 0x3202 146#define USB_PID_TWINHAN_VP7041_WARM 0x3202
138#define USB_PID_TWINHAN_VP7020_COLD 0x3203 147#define USB_PID_TWINHAN_VP7020_COLD 0x3203
@@ -143,6 +152,7 @@
143#define USB_PID_TWINHAN_VP7021_WARM 0x3208 152#define USB_PID_TWINHAN_VP7021_WARM 0x3208
144#define USB_PID_TINYTWIN 0x3226 153#define USB_PID_TINYTWIN 0x3226
145#define USB_PID_TINYTWIN_2 0xe402 154#define USB_PID_TINYTWIN_2 0xe402
155#define USB_PID_TINYTWIN_3 0x9016
146#define USB_PID_DNTV_TINYUSB2_COLD 0x3223 156#define USB_PID_DNTV_TINYUSB2_COLD 0x3223
147#define USB_PID_DNTV_TINYUSB2_WARM 0x3224 157#define USB_PID_DNTV_TINYUSB2_WARM 0x3224
148#define USB_PID_ULTIMA_TVBOX_COLD 0x8105 158#define USB_PID_ULTIMA_TVBOX_COLD 0x8105
@@ -196,6 +206,7 @@
196#define USB_PID_AVERMEDIA_A309 0xa309 206#define USB_PID_AVERMEDIA_A309 0xa309
197#define USB_PID_AVERMEDIA_A310 0xa310 207#define USB_PID_AVERMEDIA_A310 0xa310
198#define USB_PID_AVERMEDIA_A850 0x850a 208#define USB_PID_AVERMEDIA_A850 0x850a
209#define USB_PID_AVERMEDIA_A850T 0x850b
199#define USB_PID_AVERMEDIA_A805 0xa805 210#define USB_PID_AVERMEDIA_A805 0xa805
200#define USB_PID_AVERMEDIA_A815M 0x815a 211#define USB_PID_AVERMEDIA_A815M 0x815a
201#define USB_PID_TECHNOTREND_CONNECT_S2400 0x3006 212#define USB_PID_TECHNOTREND_CONNECT_S2400 0x3006
@@ -268,6 +279,7 @@
268#define USB_PID_GENPIX_8PSK_REV_2 0x0202 279#define USB_PID_GENPIX_8PSK_REV_2 0x0202
269#define USB_PID_GENPIX_SKYWALKER_1 0x0203 280#define USB_PID_GENPIX_SKYWALKER_1 0x0203
270#define USB_PID_GENPIX_SKYWALKER_CW3K 0x0204 281#define USB_PID_GENPIX_SKYWALKER_CW3K 0x0204
282#define USB_PID_GENPIX_SKYWALKER_2 0x0206
271#define USB_PID_SIGMATEK_DVB_110 0x6610 283#define USB_PID_SIGMATEK_DVB_110 0x6610
272#define USB_PID_MSI_DIGI_VOX_MINI_II 0x1513 284#define USB_PID_MSI_DIGI_VOX_MINI_II 0x1513
273#define USB_PID_MSI_DIGIVOX_DUO 0x8801 285#define USB_PID_MSI_DIGIVOX_DUO 0x8801
@@ -295,6 +307,7 @@
295#define USB_PID_ELGATO_EYETV_DIVERSITY 0x0011 307#define USB_PID_ELGATO_EYETV_DIVERSITY 0x0011
296#define USB_PID_ELGATO_EYETV_DTT 0x0021 308#define USB_PID_ELGATO_EYETV_DTT 0x0021
297#define USB_PID_ELGATO_EYETV_DTT_Dlx 0x0020 309#define USB_PID_ELGATO_EYETV_DTT_Dlx 0x0020
310#define USB_PID_ELGATO_EYETV_SAT 0x002a
298#define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_COLD 0x5000 311#define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_COLD 0x5000
299#define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_WARM 0x5001 312#define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_WARM 0x5001
300#define USB_PID_FRIIO_WHITE 0x0001 313#define USB_PID_FRIIO_WHITE 0x0001
@@ -305,4 +318,6 @@
305#define USB_PID_TERRATEC_DVBS2CI_V2 0x10ac 318#define USB_PID_TERRATEC_DVBS2CI_V2 0x10ac
306#define USB_PID_TECHNISAT_USB2_HDCI_V1 0x0001 319#define USB_PID_TECHNISAT_USB2_HDCI_V1 0x0001
307#define USB_PID_TECHNISAT_USB2_HDCI_V2 0x0002 320#define USB_PID_TECHNISAT_USB2_HDCI_V2 0x0002
321#define USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2 0x0004
322#define USB_PID_TECHNISAT_USB2_DVB_S2 0x0500
308#endif 323#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index b579fed3ab3f..41bacff24960 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -8,60 +8,71 @@
8#include "dvb-usb-common.h" 8#include "dvb-usb-common.h"
9#include <linux/usb/input.h> 9#include <linux/usb/input.h>
10 10
11static int legacy_dvb_usb_getkeycode(struct input_dev *dev, 11static unsigned int
12 unsigned int scancode, unsigned int *keycode) 12legacy_dvb_usb_get_keymap_index(const struct input_keymap_entry *ke,
13 struct rc_map_table *keymap,
14 unsigned int keymap_size)
13{ 15{
14 struct dvb_usb_device *d = input_get_drvdata(dev); 16 unsigned int index;
15 17 unsigned int scancode;
16 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 18
17 int i; 19 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
18 20 index = ke->index;
19 /* See if we can match the raw key code. */ 21 } else {
20 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 22 if (input_scancode_to_scalar(ke, &scancode))
21 if (keymap[i].scancode == scancode) { 23 return keymap_size;
22 *keycode = keymap[i].keycode; 24
23 return 0; 25 /* See if we can match the raw key code. */
24 } 26 for (index = 0; index < keymap_size; index++)
27 if (keymap[index].scancode == scancode)
28 break;
25 29
26 /* 30 /* See if there is an unused hole in the map */
27 * If is there extra space, returns KEY_RESERVED, 31 if (index >= keymap_size) {
28 * otherwise, input core won't let legacy_dvb_usb_setkeycode 32 for (index = 0; index < keymap_size; index++) {
29 * to work 33 if (keymap[index].keycode == KEY_RESERVED ||
30 */ 34 keymap[index].keycode == KEY_UNKNOWN) {
31 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 35 break;
32 if (keymap[i].keycode == KEY_RESERVED || 36 }
33 keymap[i].keycode == KEY_UNKNOWN) { 37 }
34 *keycode = KEY_RESERVED;
35 return 0;
36 } 38 }
39 }
37 40
38 return -EINVAL; 41 return index;
39} 42}
40 43
41static int legacy_dvb_usb_setkeycode(struct input_dev *dev, 44static int legacy_dvb_usb_getkeycode(struct input_dev *dev,
42 unsigned int scancode, unsigned int keycode) 45 struct input_keymap_entry *ke)
43{ 46{
44 struct dvb_usb_device *d = input_get_drvdata(dev); 47 struct dvb_usb_device *d = input_get_drvdata(dev);
48 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
49 unsigned int keymap_size = d->props.rc.legacy.rc_map_size;
50 unsigned int index;
45 51
46 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 52 index = legacy_dvb_usb_get_keymap_index(ke, keymap, keymap_size);
47 int i; 53 if (index >= keymap_size)
54 return -EINVAL;
48 55
49 /* Search if it is replacing an existing keycode */ 56 ke->keycode = keymap[index].keycode;
50 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 57 if (ke->keycode == KEY_UNKNOWN)
51 if (keymap[i].scancode == scancode) { 58 ke->keycode = KEY_RESERVED;
52 keymap[i].keycode = keycode; 59 ke->len = sizeof(keymap[index].scancode);
53 return 0; 60 memcpy(&ke->scancode, &keymap[index].scancode, ke->len);
54 } 61 ke->index = index;
55 62
56 /* Search if is there a clean entry. If so, use it */ 63 return 0;
57 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 64}
58 if (keymap[i].keycode == KEY_RESERVED || 65
59 keymap[i].keycode == KEY_UNKNOWN) { 66static int legacy_dvb_usb_setkeycode(struct input_dev *dev,
60 keymap[i].scancode = scancode; 67 const struct input_keymap_entry *ke,
61 keymap[i].keycode = keycode; 68 unsigned int *old_keycode)
62 return 0; 69{
63 } 70 struct dvb_usb_device *d = input_get_drvdata(dev);
71 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
72 unsigned int keymap_size = d->props.rc.legacy.rc_map_size;
73 unsigned int index;
64 74
75 index = legacy_dvb_usb_get_keymap_index(ke, keymap, keymap_size);
65 /* 76 /*
66 * FIXME: Currently, it is not possible to increase the size of 77 * FIXME: Currently, it is not possible to increase the size of
67 * scancode table. For it to happen, one possibility 78 * scancode table. For it to happen, one possibility
@@ -69,8 +80,24 @@ static int legacy_dvb_usb_setkeycode(struct input_dev *dev,
69 * copying data, appending the new key on it, and freeing 80 * copying data, appending the new key on it, and freeing
70 * the old one - or maybe just allocating some spare space 81 * the old one - or maybe just allocating some spare space
71 */ 82 */
83 if (index >= keymap_size)
84 return -EINVAL;
85
86 *old_keycode = keymap[index].keycode;
87 keymap->keycode = ke->keycode;
88 __set_bit(ke->keycode, dev->keybit);
89
90 if (*old_keycode != KEY_RESERVED) {
91 __clear_bit(*old_keycode, dev->keybit);
92 for (index = 0; index < keymap_size; index++) {
93 if (keymap[index].keycode == *old_keycode) {
94 __set_bit(*old_keycode, dev->keybit);
95 break;
96 }
97 }
98 }
72 99
73 return -EINVAL; 100 return 0;
74} 101}
75 102
76/* Remote-control poll function - called every dib->rc_query_interval ms to see 103/* Remote-control poll function - called every dib->rc_query_interval ms to see
@@ -106,10 +133,10 @@ static void legacy_dvb_usb_read_remote_control(struct work_struct *work)
106 d->last_event = event; 133 d->last_event = event;
107 case REMOTE_KEY_REPEAT: 134 case REMOTE_KEY_REPEAT:
108 deb_rc("key repeated\n"); 135 deb_rc("key repeated\n");
109 input_event(d->rc_input_dev, EV_KEY, event, 1); 136 input_event(d->input_dev, EV_KEY, event, 1);
110 input_sync(d->rc_input_dev); 137 input_sync(d->input_dev);
111 input_event(d->rc_input_dev, EV_KEY, d->last_event, 0); 138 input_event(d->input_dev, EV_KEY, d->last_event, 0);
112 input_sync(d->rc_input_dev); 139 input_sync(d->input_dev);
113 break; 140 break;
114 default: 141 default:
115 break; 142 break;
@@ -154,20 +181,32 @@ schedule:
154 schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc.legacy.rc_interval)); 181 schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc.legacy.rc_interval));
155} 182}
156 183
157static int legacy_dvb_usb_remote_init(struct dvb_usb_device *d, 184static int legacy_dvb_usb_remote_init(struct dvb_usb_device *d)
158 struct input_dev *input_dev)
159{ 185{
160 int i, err, rc_interval; 186 int i, err, rc_interval;
187 struct input_dev *input_dev;
188
189 input_dev = input_allocate_device();
190 if (!input_dev)
191 return -ENOMEM;
192
193 input_dev->evbit[0] = BIT_MASK(EV_KEY);
194 input_dev->name = "IR-receiver inside an USB DVB receiver";
195 input_dev->phys = d->rc_phys;
196 usb_to_input_id(d->udev, &input_dev->id);
197 input_dev->dev.parent = &d->udev->dev;
198 d->input_dev = input_dev;
199 d->rc_dev = NULL;
161 200
162 input_dev->getkeycode = legacy_dvb_usb_getkeycode; 201 input_dev->getkeycode = legacy_dvb_usb_getkeycode;
163 input_dev->setkeycode = legacy_dvb_usb_setkeycode; 202 input_dev->setkeycode = legacy_dvb_usb_setkeycode;
164 203
165 /* set the bits for the keys */ 204 /* set the bits for the keys */
166 deb_rc("key map size: %d\n", d->props.rc.legacy.rc_key_map_size); 205 deb_rc("key map size: %d\n", d->props.rc.legacy.rc_map_size);
167 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { 206 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
168 deb_rc("setting bit for event %d item %d\n", 207 deb_rc("setting bit for event %d item %d\n",
169 d->props.rc.legacy.rc_key_map[i].keycode, i); 208 d->props.rc.legacy.rc_map_table[i].keycode, i);
170 set_bit(d->props.rc.legacy.rc_key_map[i].keycode, input_dev->keybit); 209 set_bit(d->props.rc.legacy.rc_map_table[i].keycode, input_dev->keybit);
171 } 210 }
172 211
173 /* setting these two values to non-zero, we have to manage key repeats */ 212 /* setting these two values to non-zero, we have to manage key repeats */
@@ -221,18 +260,34 @@ static void dvb_usb_read_remote_control(struct work_struct *work)
221 msecs_to_jiffies(d->props.rc.core.rc_interval)); 260 msecs_to_jiffies(d->props.rc.core.rc_interval));
222} 261}
223 262
224static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d, 263static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d)
225 struct input_dev *input_dev)
226{ 264{
227 int err, rc_interval; 265 int err, rc_interval;
266 struct rc_dev *dev;
267
268 dev = rc_allocate_device();
269 if (!dev)
270 return -ENOMEM;
228 271
229 d->props.rc.core.rc_props.priv = d; 272 dev->driver_name = d->props.rc.core.module_name;
230 err = ir_input_register(input_dev, 273 dev->map_name = d->props.rc.core.rc_codes;
231 d->props.rc.core.rc_codes, 274 dev->change_protocol = d->props.rc.core.change_protocol;
232 &d->props.rc.core.rc_props, 275 dev->allowed_protos = d->props.rc.core.allowed_protos;
233 d->props.rc.core.module_name); 276 dev->driver_type = d->props.rc.core.driver_type;
234 if (err < 0) 277 usb_to_input_id(d->udev, &dev->input_id);
278 dev->input_name = "IR-receiver inside an USB DVB receiver";
279 dev->input_phys = d->rc_phys;
280 dev->dev.parent = &d->udev->dev;
281 dev->priv = d;
282
283 err = rc_register_device(dev);
284 if (err < 0) {
285 rc_free_device(dev);
235 return err; 286 return err;
287 }
288
289 d->input_dev = NULL;
290 d->rc_dev = dev;
236 291
237 if (!d->props.rc.core.rc_query || d->props.rc.core.bulk_mode) 292 if (!d->props.rc.core.rc_query || d->props.rc.core.bulk_mode)
238 return 0; 293 return 0;
@@ -251,13 +306,12 @@ static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d,
251 306
252int dvb_usb_remote_init(struct dvb_usb_device *d) 307int dvb_usb_remote_init(struct dvb_usb_device *d)
253{ 308{
254 struct input_dev *input_dev;
255 int err; 309 int err;
256 310
257 if (dvb_usb_disable_rc_polling) 311 if (dvb_usb_disable_rc_polling)
258 return 0; 312 return 0;
259 313
260 if (d->props.rc.legacy.rc_key_map && d->props.rc.legacy.rc_query) 314 if (d->props.rc.legacy.rc_map_table && d->props.rc.legacy.rc_query)
261 d->props.rc.mode = DVB_RC_LEGACY; 315 d->props.rc.mode = DVB_RC_LEGACY;
262 else if (d->props.rc.core.rc_codes) 316 else if (d->props.rc.core.rc_codes)
263 d->props.rc.mode = DVB_RC_CORE; 317 d->props.rc.mode = DVB_RC_CORE;
@@ -267,26 +321,14 @@ int dvb_usb_remote_init(struct dvb_usb_device *d)
267 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); 321 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys));
268 strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys)); 322 strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys));
269 323
270 input_dev = input_allocate_device();
271 if (!input_dev)
272 return -ENOMEM;
273
274 input_dev->evbit[0] = BIT_MASK(EV_KEY);
275 input_dev->name = "IR-receiver inside an USB DVB receiver";
276 input_dev->phys = d->rc_phys;
277 usb_to_input_id(d->udev, &input_dev->id);
278 input_dev->dev.parent = &d->udev->dev;
279
280 /* Start the remote-control polling. */ 324 /* Start the remote-control polling. */
281 if (d->props.rc.legacy.rc_interval < 40) 325 if (d->props.rc.legacy.rc_interval < 40)
282 d->props.rc.legacy.rc_interval = 100; /* default */ 326 d->props.rc.legacy.rc_interval = 100; /* default */
283 327
284 d->rc_input_dev = input_dev;
285
286 if (d->props.rc.mode == DVB_RC_LEGACY) 328 if (d->props.rc.mode == DVB_RC_LEGACY)
287 err = legacy_dvb_usb_remote_init(d, input_dev); 329 err = legacy_dvb_usb_remote_init(d);
288 else 330 else
289 err = rc_core_dvb_usb_remote_init(d, input_dev); 331 err = rc_core_dvb_usb_remote_init(d);
290 if (err) 332 if (err)
291 return err; 333 return err;
292 334
@@ -298,12 +340,11 @@ int dvb_usb_remote_init(struct dvb_usb_device *d)
298int dvb_usb_remote_exit(struct dvb_usb_device *d) 340int dvb_usb_remote_exit(struct dvb_usb_device *d)
299{ 341{
300 if (d->state & DVB_USB_STATE_REMOTE) { 342 if (d->state & DVB_USB_STATE_REMOTE) {
301 cancel_rearming_delayed_work(&d->rc_query_work); 343 cancel_delayed_work_sync(&d->rc_query_work);
302 flush_scheduled_work();
303 if (d->props.rc.mode == DVB_RC_LEGACY) 344 if (d->props.rc.mode == DVB_RC_LEGACY)
304 input_unregister_device(d->rc_input_dev); 345 input_unregister_device(d->input_dev);
305 else 346 else
306 ir_input_unregister(d->rc_input_dev); 347 rc_unregister_device(d->rc_dev);
307 } 348 }
308 d->state &= ~DVB_USB_STATE_REMOTE; 349 d->state &= ~DVB_USB_STATE_REMOTE;
309 return 0; 350 return 0;
@@ -316,7 +357,7 @@ int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *d,
316 u8 keybuf[5], u32 *event, int *state) 357 u8 keybuf[5], u32 *event, int *state)
317{ 358{
318 int i; 359 int i;
319 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 360 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
320 *event = 0; 361 *event = 0;
321 *state = REMOTE_NO_KEY_PRESSED; 362 *state = REMOTE_NO_KEY_PRESSED;
322 switch (keybuf[0]) { 363 switch (keybuf[0]) {
@@ -329,7 +370,7 @@ int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *d,
329 break; 370 break;
330 } 371 }
331 /* See if we can match the raw key code. */ 372 /* See if we can match the raw key code. */
332 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 373 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
333 if (rc5_custom(&keymap[i]) == keybuf[1] && 374 if (rc5_custom(&keymap[i]) == keybuf[1] &&
334 rc5_data(&keymap[i]) == keybuf[3]) { 375 rc5_data(&keymap[i]) == keybuf[3]) {
335 *event = keymap[i].keycode; 376 *event = keymap[i].keycode;
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index 34f7b3ba8cc7..76a80968482a 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -14,7 +14,7 @@
14#include <linux/usb.h> 14#include <linux/usb.h>
15#include <linux/firmware.h> 15#include <linux/firmware.h>
16#include <linux/mutex.h> 16#include <linux/mutex.h>
17#include <media/ir-core.h> 17#include <media/rc-core.h>
18 18
19#include "dvb_frontend.h" 19#include "dvb_frontend.h"
20#include "dvb_demux.h" 20#include "dvb_demux.h"
@@ -75,17 +75,17 @@ struct dvb_usb_device_description {
75 struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM]; 75 struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
76}; 76};
77 77
78static inline u8 rc5_custom(struct ir_scancode *key) 78static inline u8 rc5_custom(struct rc_map_table *key)
79{ 79{
80 return (key->scancode >> 8) & 0xff; 80 return (key->scancode >> 8) & 0xff;
81} 81}
82 82
83static inline u8 rc5_data(struct ir_scancode *key) 83static inline u8 rc5_data(struct rc_map_table *key)
84{ 84{
85 return key->scancode & 0xff; 85 return key->scancode & 0xff;
86} 86}
87 87
88static inline u8 rc5_scan(struct ir_scancode *key) 88static inline u8 rc5_scan(struct rc_map_table *key)
89{ 89{
90 return key->scancode & 0xffff; 90 return key->scancode & 0xffff;
91} 91}
@@ -159,9 +159,9 @@ struct dvb_usb_adapter_properties {
159 159
160/** 160/**
161 * struct dvb_rc_legacy - old properties of remote controller 161 * struct dvb_rc_legacy - old properties of remote controller
162 * @rc_key_map: a hard-wired array of struct ir_scancode (NULL to disable 162 * @rc_map_table: a hard-wired array of struct rc_map_table (NULL to disable
163 * remote control handling). 163 * remote control handling).
164 * @rc_key_map_size: number of items in @rc_key_map. 164 * @rc_map_size: number of items in @rc_map_table.
165 * @rc_query: called to query an event event. 165 * @rc_query: called to query an event event.
166 * @rc_interval: time in ms between two queries. 166 * @rc_interval: time in ms between two queries.
167 */ 167 */
@@ -170,8 +170,8 @@ struct dvb_rc_legacy {
170#define REMOTE_NO_KEY_PRESSED 0x00 170#define REMOTE_NO_KEY_PRESSED 0x00
171#define REMOTE_KEY_PRESSED 0x01 171#define REMOTE_KEY_PRESSED 0x01
172#define REMOTE_KEY_REPEAT 0x02 172#define REMOTE_KEY_REPEAT 0x02
173 struct ir_scancode *rc_key_map; 173 struct rc_map_table *rc_map_table;
174 int rc_key_map_size; 174 int rc_map_size;
175 int (*rc_query) (struct dvb_usb_device *, u32 *, int *); 175 int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
176 int rc_interval; 176 int rc_interval;
177}; 177};
@@ -180,18 +180,22 @@ struct dvb_rc_legacy {
180 * struct dvb_rc properties of remote controller, using rc-core 180 * struct dvb_rc properties of remote controller, using rc-core
181 * @rc_codes: name of rc codes table 181 * @rc_codes: name of rc codes table
182 * @protocol: type of protocol(s) currently used by the driver 182 * @protocol: type of protocol(s) currently used by the driver
183 * @allowed_protos: protocol(s) supported by the driver
184 * @driver_type: Used to point if a device supports raw mode
185 * @change_protocol: callback to change protocol
183 * @rc_query: called to query an event event. 186 * @rc_query: called to query an event event.
184 * @rc_interval: time in ms between two queries. 187 * @rc_interval: time in ms between two queries.
185 * @rc_props: remote controller properties
186 * @bulk_mode: device supports bulk mode for RC (disable polling mode) 188 * @bulk_mode: device supports bulk mode for RC (disable polling mode)
187 */ 189 */
188struct dvb_rc { 190struct dvb_rc {
189 char *rc_codes; 191 char *rc_codes;
190 u64 protocol; 192 u64 protocol;
193 u64 allowed_protos;
194 enum rc_driver_type driver_type;
195 int (*change_protocol)(struct rc_dev *dev, u64 rc_type);
191 char *module_name; 196 char *module_name;
192 int (*rc_query) (struct dvb_usb_device *d); 197 int (*rc_query) (struct dvb_usb_device *d);
193 int rc_interval; 198 int rc_interval;
194 struct ir_dev_props rc_props;
195 bool bulk_mode; /* uses bulk mode */ 199 bool bulk_mode; /* uses bulk mode */
196}; 200};
197 201
@@ -385,7 +389,8 @@ struct dvb_usb_adapter {
385 * 389 *
386 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB 390 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
387 * 391 *
388 * @rc_input_dev: input device for the remote control. 392 * @rc_dev: rc device for the remote control (rc-core mode)
393 * @input_dev: input device for the remote control (legacy mode)
389 * @rc_query_work: struct work_struct frequent rc queries 394 * @rc_query_work: struct work_struct frequent rc queries
390 * @last_event: last triggered event 395 * @last_event: last triggered event
391 * @last_state: last state (no, pressed, repeat) 396 * @last_state: last state (no, pressed, repeat)
@@ -418,7 +423,8 @@ struct dvb_usb_device {
418 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE]; 423 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
419 424
420 /* remote control */ 425 /* remote control */
421 struct input_dev *rc_input_dev; 426 struct rc_dev *rc_dev;
427 struct input_dev *input_dev;
422 char rc_phys[64]; 428 char rc_phys[64];
423 struct delayed_work rc_query_work; 429 struct delayed_work rc_query_work;
424 u32 last_event; 430 u32 last_event;
diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
index 774df88dc6e3..058b2318abed 100644
--- a/drivers/media/dvb/dvb-usb/dw2102.c
+++ b/drivers/media/dvb/dvb-usb/dw2102.c
@@ -1,15 +1,16 @@
1/* DVB USB framework compliant Linux driver for the 1/* DVB USB framework compliant Linux driver for the
2* DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101, 2 * DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101,
3* TeVii S600, S630, S650, 3 * TeVii S600, S630, S650, S660, S480,
4* Prof 1100, 7500 Cards 4 * Prof 1100, 7500,
5* Copyright (C) 2008,2009 Igor M. Liplianin (liplianin@me.by) 5 * Geniatech SU3000 Cards
6* 6 * Copyright (C) 2008-2011 Igor M. Liplianin (liplianin@me.by)
7* This program is free software; you can redistribute it and/or modify it 7 *
8* under the terms of the GNU General Public License as published by the 8 * This program is free software; you can redistribute it and/or modify it
9* Free Software Foundation, version 2. 9 * under the terms of the GNU General Public License as published by the
10* 10 * Free Software Foundation, version 2.
11* see Documentation/dvb/README.dvb-usb for more information 11 *
12*/ 12 * see Documentation/dvb/README.dvb-usb for more information
13 */
13#include "dw2102.h" 14#include "dw2102.h"
14#include "si21xx.h" 15#include "si21xx.h"
15#include "stv0299.h" 16#include "stv0299.h"
@@ -55,6 +56,14 @@
55#define USB_PID_TEVII_S660 0xd660 56#define USB_PID_TEVII_S660 0xd660
56#endif 57#endif
57 58
59#ifndef USB_PID_TEVII_S480_1
60#define USB_PID_TEVII_S480_1 0xd481
61#endif
62
63#ifndef USB_PID_TEVII_S480_2
64#define USB_PID_TEVII_S480_2 0xd482
65#endif
66
58#ifndef USB_PID_PROF_1100 67#ifndef USB_PID_PROF_1100
59#define USB_PID_PROF_1100 0xb012 68#define USB_PID_PROF_1100 0xb012
60#endif 69#endif
@@ -67,17 +76,27 @@
67#define REG_21_SYMBOLRATE_BYTE2 0x21 76#define REG_21_SYMBOLRATE_BYTE2 0x21
68/* on my own*/ 77/* on my own*/
69#define DW2102_VOLTAGE_CTRL (0x1800) 78#define DW2102_VOLTAGE_CTRL (0x1800)
79#define SU3000_STREAM_CTRL (0x1900)
70#define DW2102_RC_QUERY (0x1a00) 80#define DW2102_RC_QUERY (0x1a00)
81#define DW2102_LED_CTRL (0x1b00)
71 82
72#define err_str "did not find the firmware file. (%s) " \ 83#define err_str "did not find the firmware file. (%s) " \
73 "Please see linux/Documentation/dvb/ for more details " \ 84 "Please see linux/Documentation/dvb/ for more details " \
74 "on firmware-problems." 85 "on firmware-problems."
75 86
76struct ir_codes_dvb_usb_table_table { 87struct rc_map_dvb_usb_table_table {
77 struct ir_scancode *rc_keys; 88 struct rc_map_table *rc_keys;
78 int rc_keys_size; 89 int rc_keys_size;
79}; 90};
80 91
92struct su3000_state {
93 u8 initialized;
94};
95
96struct s6x0_state {
97 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
98};
99
81/* debug */ 100/* debug */
82static int dvb_usb_dw2102_debug; 101static int dvb_usb_dw2102_debug;
83module_param_named(debug, dvb_usb_dw2102_debug, int, 0644); 102module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
@@ -87,7 +106,8 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
87/* keymaps */ 106/* keymaps */
88static int ir_keymap; 107static int ir_keymap;
89module_param_named(keymap, ir_keymap, int, 0644); 108module_param_named(keymap, ir_keymap, int, 0644);
90MODULE_PARM_DESC(keymap, "set keymap 0=default 1=dvbworld 2=tevii 3=tbs ..."); 109MODULE_PARM_DESC(keymap, "set keymap 0=default 1=dvbworld 2=tevii 3=tbs ..."
110 " 256=none");
91 111
92/* demod probe */ 112/* demod probe */
93static int demod_probe = 1; 113static int demod_probe = 1;
@@ -101,12 +121,16 @@ static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
101 u16 index, u8 * data, u16 len, int flags) 121 u16 index, u8 * data, u16 len, int flags)
102{ 122{
103 int ret; 123 int ret;
104 u8 u8buf[len]; 124 u8 *u8buf;
105
106 unsigned int pipe = (flags == DW210X_READ_MSG) ? 125 unsigned int pipe = (flags == DW210X_READ_MSG) ?
107 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0); 126 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
108 u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT; 127 u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
109 128
129 u8buf = kmalloc(len, GFP_KERNEL);
130 if (!u8buf)
131 return -ENOMEM;
132
133
110 if (flags == DW210X_WRITE_MSG) 134 if (flags == DW210X_WRITE_MSG)
111 memcpy(u8buf, data, len); 135 memcpy(u8buf, data, len);
112 ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR, 136 ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
@@ -114,6 +138,8 @@ static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
114 138
115 if (flags == DW210X_READ_MSG) 139 if (flags == DW210X_READ_MSG)
116 memcpy(data, u8buf, len); 140 memcpy(data, u8buf, len);
141
142 kfree(u8buf);
117 return ret; 143 return ret;
118} 144}
119 145
@@ -136,8 +162,7 @@ static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
136 /* read stv0299 register */ 162 /* read stv0299 register */
137 value = msg[0].buf[0];/* register */ 163 value = msg[0].buf[0];/* register */
138 for (i = 0; i < msg[1].len; i++) { 164 for (i = 0; i < msg[1].len; i++) {
139 value = value + i; 165 ret = dw210x_op_rw(d->udev, 0xb5, value + i, 0,
140 ret = dw210x_op_rw(d->udev, 0xb5, value, 0,
141 buf6, 2, DW210X_READ_MSG); 166 buf6, 2, DW210X_READ_MSG);
142 msg[1].buf[i] = buf6[0]; 167 msg[1].buf[i] = buf6[0];
143 } 168 }
@@ -483,10 +508,10 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
483 for (j = 0; j < num; j++) { 508 for (j = 0; j < num; j++) {
484 switch (msg[j].addr) { 509 switch (msg[j].addr) {
485 case (DW2102_RC_QUERY): { 510 case (DW2102_RC_QUERY): {
486 u8 ibuf[4]; 511 u8 ibuf[5];
487 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0, 512 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
488 ibuf, 4, DW210X_READ_MSG); 513 ibuf, 5, DW210X_READ_MSG);
489 memcpy(msg[j].buf, ibuf + 1, 2); 514 memcpy(msg[j].buf, ibuf + 3, 2);
490 break; 515 break;
491 } 516 }
492 case (DW2102_VOLTAGE_CTRL): { 517 case (DW2102_VOLTAGE_CTRL): {
@@ -502,6 +527,15 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
502 obuf, 2, DW210X_WRITE_MSG); 527 obuf, 2, DW210X_WRITE_MSG);
503 break; 528 break;
504 } 529 }
530 case (DW2102_LED_CTRL): {
531 u8 obuf[2];
532
533 obuf[0] = 5;
534 obuf[1] = msg[j].buf[0];
535 ret = dw210x_op_rw(d->udev, 0x8a, 0, 0,
536 obuf, 2, DW210X_WRITE_MSG);
537 break;
538 }
505 /*case 0x55: cx24116 539 /*case 0x55: cx24116
506 case 0x6a: stv0903 540 case 0x6a: stv0903
507 case 0x68: ds3000, stv0903 541 case 0x68: ds3000, stv0903
@@ -535,14 +569,15 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
535 i += 16; 569 i += 16;
536 len -= 16; 570 len -= 16;
537 } while (len > 0); 571 } while (len > 0);
538 } else if ((udev->descriptor.idProduct == 0x7500) 572 } else if (j < (num - 1)) {
539 && (j < (num - 1))) {
540 /* write register addr before read */ 573 /* write register addr before read */
541 u8 obuf[msg[j].len + 2]; 574 u8 obuf[msg[j].len + 2];
542 obuf[0] = msg[j + 1].len; 575 obuf[0] = msg[j + 1].len;
543 obuf[1] = (msg[j].addr << 1); 576 obuf[1] = (msg[j].addr << 1);
544 memcpy(obuf + 2, msg[j].buf, msg[j].len); 577 memcpy(obuf + 2, msg[j].buf, msg[j].len);
545 ret = dw210x_op_rw(d->udev, 0x92, 0, 0, 578 ret = dw210x_op_rw(d->udev,
579 udev->descriptor.idProduct ==
580 0x7500 ? 0x92 : 0x90, 0, 0,
546 obuf, msg[j].len + 2, 581 obuf, msg[j].len + 2,
547 DW210X_WRITE_MSG); 582 DW210X_WRITE_MSG);
548 break; 583 break;
@@ -552,8 +587,7 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
552 obuf[0] = msg[j].len + 1; 587 obuf[0] = msg[j].len + 1;
553 obuf[1] = (msg[j].addr << 1); 588 obuf[1] = (msg[j].addr << 1);
554 memcpy(obuf + 2, msg[j].buf, msg[j].len); 589 memcpy(obuf + 2, msg[j].buf, msg[j].len);
555 ret = dw210x_op_rw(d->udev, 590 ret = dw210x_op_rw(d->udev, 0x80, 0, 0,
556 (num > 1 ? 0x90 : 0x80), 0, 0,
557 obuf, msg[j].len + 2, 591 obuf, msg[j].len + 2,
558 DW210X_WRITE_MSG); 592 DW210X_WRITE_MSG);
559 break; 593 break;
@@ -561,14 +595,76 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
561 break; 595 break;
562 } 596 }
563 } 597 }
564
565 msleep(3);
566 } 598 }
567 599
568 mutex_unlock(&d->i2c_mutex); 600 mutex_unlock(&d->i2c_mutex);
569 return num; 601 return num;
570} 602}
571 603
604static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
605 int num)
606{
607 struct dvb_usb_device *d = i2c_get_adapdata(adap);
608 u8 obuf[0x40], ibuf[0x40];
609
610 if (!d)
611 return -ENODEV;
612 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
613 return -EAGAIN;
614
615 switch (num) {
616 case 1:
617 switch (msg[0].addr) {
618 case SU3000_STREAM_CTRL:
619 obuf[0] = msg[0].buf[0] + 0x36;
620 obuf[1] = 3;
621 obuf[2] = 0;
622 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 0, 0) < 0)
623 err("i2c transfer failed.");
624 break;
625 case DW2102_RC_QUERY:
626 obuf[0] = 0x10;
627 if (dvb_usb_generic_rw(d, obuf, 1, ibuf, 2, 0) < 0)
628 err("i2c transfer failed.");
629 msg[0].buf[1] = ibuf[0];
630 msg[0].buf[0] = ibuf[1];
631 break;
632 default:
633 /* always i2c write*/
634 obuf[0] = 0x08;
635 obuf[1] = msg[0].addr;
636 obuf[2] = msg[0].len;
637
638 memcpy(&obuf[3], msg[0].buf, msg[0].len);
639
640 if (dvb_usb_generic_rw(d, obuf, msg[0].len + 3,
641 ibuf, 1, 0) < 0)
642 err("i2c transfer failed.");
643
644 }
645 break;
646 case 2:
647 /* always i2c read */
648 obuf[0] = 0x09;
649 obuf[1] = msg[0].len;
650 obuf[2] = msg[1].len;
651 obuf[3] = msg[0].addr;
652 memcpy(&obuf[4], msg[0].buf, msg[0].len);
653
654 if (dvb_usb_generic_rw(d, obuf, msg[0].len + 4,
655 ibuf, msg[1].len + 1, 0) < 0)
656 err("i2c transfer failed.");
657
658 memcpy(msg[1].buf, &ibuf[1], msg[1].len);
659 break;
660 default:
661 warn("more than 2 i2c messages at a time is not handled yet.");
662 break;
663 }
664 mutex_unlock(&d->i2c_mutex);
665 return num;
666}
667
572static u32 dw210x_i2c_func(struct i2c_adapter *adapter) 668static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
573{ 669{
574 return I2C_FUNC_I2C; 670 return I2C_FUNC_I2C;
@@ -604,6 +700,11 @@ static struct i2c_algorithm s6x0_i2c_algo = {
604 .functionality = dw210x_i2c_func, 700 .functionality = dw210x_i2c_func,
605}; 701};
606 702
703static struct i2c_algorithm su3000_i2c_algo = {
704 .master_xfer = su3000_i2c_transfer,
705 .functionality = dw210x_i2c_func,
706};
707
607static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6]) 708static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
608{ 709{
609 int i; 710 int i;
@@ -668,6 +769,82 @@ static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
668 return 0; 769 return 0;
669}; 770};
670 771
772static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
773{
774 static u8 command_start[] = {0x00};
775 static u8 command_stop[] = {0x01};
776 struct i2c_msg msg = {
777 .addr = SU3000_STREAM_CTRL,
778 .flags = 0,
779 .buf = onoff ? command_start : command_stop,
780 .len = 1
781 };
782
783 i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
784
785 return 0;
786}
787
788static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
789{
790 struct su3000_state *state = (struct su3000_state *)d->priv;
791 u8 obuf[] = {0xde, 0};
792
793 info("%s: %d, initialized %d\n", __func__, i, state->initialized);
794
795 if (i && !state->initialized) {
796 state->initialized = 1;
797 /* reset board */
798 dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
799 }
800
801 return 0;
802}
803
804static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
805{
806 int i;
807 u8 obuf[] = { 0x1f, 0xf0 };
808 u8 ibuf[] = { 0 };
809 struct i2c_msg msg[] = {
810 {
811 .addr = 0x51,
812 .flags = 0,
813 .buf = obuf,
814 .len = 2,
815 }, {
816 .addr = 0x51,
817 .flags = I2C_M_RD,
818 .buf = ibuf,
819 .len = 1,
820
821 }
822 };
823
824 for (i = 0; i < 6; i++) {
825 obuf[1] = 0xf0 + i;
826 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
827 break;
828 else
829 mac[i] = ibuf[0];
830
831 debug_dump(mac, 6, printk);
832 }
833
834 return 0;
835}
836
837static int su3000_identify_state(struct usb_device *udev,
838 struct dvb_usb_device_properties *props,
839 struct dvb_usb_device_description **desc,
840 int *cold)
841{
842 info("%s\n", __func__);
843
844 *cold = 0;
845 return 0;
846}
847
671static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 848static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
672{ 849{
673 static u8 command_13v[] = {0x00, 0x01}; 850 static u8 command_13v[] = {0x00, 0x01};
@@ -692,6 +869,37 @@ static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
692 return 0; 869 return 0;
693} 870}
694 871
872static int s660_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
873{
874 struct dvb_usb_adapter *d =
875 (struct dvb_usb_adapter *)(fe->dvb->priv);
876 struct s6x0_state *st = (struct s6x0_state *)d->dev->priv;
877
878 dw210x_set_voltage(fe, voltage);
879 if (st->old_set_voltage)
880 st->old_set_voltage(fe, voltage);
881
882 return 0;
883}
884
885static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
886{
887 static u8 led_off[] = { 0 };
888 static u8 led_on[] = { 1 };
889 struct i2c_msg msg = {
890 .addr = DW2102_LED_CTRL,
891 .flags = 0,
892 .buf = led_off,
893 .len = 1
894 };
895 struct dvb_usb_adapter *udev_adap =
896 (struct dvb_usb_adapter *)(fe->dvb->priv);
897
898 if (offon)
899 msg.buf = led_on;
900 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
901}
902
695static struct stv0299_config sharp_z0194a_config = { 903static struct stv0299_config sharp_z0194a_config = {
696 .demod_address = 0x68, 904 .demod_address = 0x68,
697 .inittab = sharp_z0194a_inittab, 905 .inittab = sharp_z0194a_inittab,
@@ -771,6 +979,12 @@ static struct stv0900_config prof_7500_stv0900_config = {
771 .tun1_adc = 0,/* 2 Vpp */ 979 .tun1_adc = 0,/* 2 Vpp */
772 .path1_mode = 3, 980 .path1_mode = 3,
773 .tun1_type = 3, 981 .tun1_type = 3,
982 .set_lock_led = dw210x_led_ctrl,
983};
984
985static struct ds3000_config su3000_ds3000_config = {
986 .demod_address = 0x68,
987 .ci_mode = 1,
774}; 988};
775 989
776static int dw2104_frontend_attach(struct dvb_usb_adapter *d) 990static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
@@ -885,7 +1099,7 @@ static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
885 return -EIO; 1099 return -EIO;
886} 1100}
887 1101
888static int s6x0_frontend_attach(struct dvb_usb_adapter *d) 1102static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
889{ 1103{
890 d->fe = dvb_attach(mt312_attach, &zl313_config, 1104 d->fe = dvb_attach(mt312_attach, &zl313_config,
891 &d->dev->i2c_adap); 1105 &d->dev->i2c_adap);
@@ -898,41 +1112,108 @@ static int s6x0_frontend_attach(struct dvb_usb_adapter *d)
898 } 1112 }
899 } 1113 }
900 1114
1115 return -EIO;
1116}
1117
1118static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1119{
1120 u8 obuf[] = {7, 1};
1121
901 d->fe = dvb_attach(stv0288_attach, &earda_config, 1122 d->fe = dvb_attach(stv0288_attach, &earda_config,
902 &d->dev->i2c_adap); 1123 &d->dev->i2c_adap);
903 if (d->fe != NULL) { 1124
904 if (dvb_attach(stb6000_attach, d->fe, 0x61, 1125 if (d->fe == NULL)
905 &d->dev->i2c_adap)) { 1126 return -EIO;
906 d->fe->ops.set_voltage = dw210x_set_voltage; 1127
907 info("Attached stv0288+stb6000!\n"); 1128 if (NULL == dvb_attach(stb6000_attach, d->fe, 0x61, &d->dev->i2c_adap))
908 return 0; 1129 return -EIO;
909 } 1130
910 } 1131 d->fe->ops.set_voltage = dw210x_set_voltage;
1132
1133 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1134
1135 info("Attached stv0288+stb6000!\n");
1136
1137 return 0;
1138
1139}
1140
1141static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1142{
1143 struct s6x0_state *st = (struct s6x0_state *)d->dev->priv;
1144 u8 obuf[] = {7, 1};
911 1145
912 d->fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config, 1146 d->fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
913 &d->dev->i2c_adap); 1147 &d->dev->i2c_adap);
914 if (d->fe != NULL) {
915 d->fe->ops.set_voltage = dw210x_set_voltage;
916 info("Attached ds3000+ds2020!\n");
917 return 0;
918 }
919 1148
920 return -EIO; 1149 if (d->fe == NULL)
1150 return -EIO;
1151
1152 st->old_set_voltage = d->fe->ops.set_voltage;
1153 d->fe->ops.set_voltage = s660_set_voltage;
1154
1155 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1156
1157 info("Attached ds3000+ds2020!\n");
1158
1159 return 0;
921} 1160}
922 1161
923static int prof_7500_frontend_attach(struct dvb_usb_adapter *d) 1162static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
924{ 1163{
1164 u8 obuf[] = {7, 1};
1165
925 d->fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config, 1166 d->fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
926 &d->dev->i2c_adap, 0); 1167 &d->dev->i2c_adap, 0);
927 if (d->fe == NULL) 1168 if (d->fe == NULL)
928 return -EIO; 1169 return -EIO;
1170
929 d->fe->ops.set_voltage = dw210x_set_voltage; 1171 d->fe->ops.set_voltage = dw210x_set_voltage;
930 1172
1173 dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1174
931 info("Attached STV0900+STB6100A!\n"); 1175 info("Attached STV0900+STB6100A!\n");
932 1176
933 return 0; 1177 return 0;
934} 1178}
935 1179
1180static int su3000_frontend_attach(struct dvb_usb_adapter *d)
1181{
1182 u8 obuf[3] = { 0xe, 0x80, 0 };
1183 u8 ibuf[] = { 0 };
1184
1185 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1186 err("command 0x0e transfer failed.");
1187
1188 obuf[0] = 0xe;
1189 obuf[1] = 0x83;
1190 obuf[2] = 0;
1191
1192 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1193 err("command 0x0e transfer failed.");
1194
1195 obuf[0] = 0xe;
1196 obuf[1] = 0x83;
1197 obuf[2] = 1;
1198
1199 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1200 err("command 0x0e transfer failed.");
1201
1202 obuf[0] = 0x51;
1203
1204 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1205 err("command 0x51 transfer failed.");
1206
1207 d->fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1208 &d->dev->i2c_adap);
1209 if (d->fe == NULL)
1210 return -EIO;
1211
1212 info("Attached DS3000!\n");
1213
1214 return 0;
1215}
1216
936static int dw2102_tuner_attach(struct dvb_usb_adapter *adap) 1217static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
937{ 1218{
938 dvb_attach(dvb_pll_attach, adap->fe, 0x60, 1219 dvb_attach(dvb_pll_attach, adap->fe, 0x60,
@@ -948,9 +1229,9 @@ static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
948 return 0; 1229 return 0;
949} 1230}
950 1231
951static struct ir_scancode ir_codes_dw210x_table[] = { 1232static struct rc_map_table rc_map_dw210x_table[] = {
952 { 0xf80a, KEY_Q }, /*power*/ 1233 { 0xf80a, KEY_POWER2 }, /*power*/
953 { 0xf80c, KEY_M }, /*mute*/ 1234 { 0xf80c, KEY_MUTE }, /*mute*/
954 { 0xf811, KEY_1 }, 1235 { 0xf811, KEY_1 },
955 { 0xf812, KEY_2 }, 1236 { 0xf812, KEY_2 },
956 { 0xf813, KEY_3 }, 1237 { 0xf813, KEY_3 },
@@ -961,28 +1242,28 @@ static struct ir_scancode ir_codes_dw210x_table[] = {
961 { 0xf818, KEY_8 }, 1242 { 0xf818, KEY_8 },
962 { 0xf819, KEY_9 }, 1243 { 0xf819, KEY_9 },
963 { 0xf810, KEY_0 }, 1244 { 0xf810, KEY_0 },
964 { 0xf81c, KEY_PAGEUP }, /*ch+*/ 1245 { 0xf81c, KEY_CHANNELUP }, /*ch+*/
965 { 0xf80f, KEY_PAGEDOWN }, /*ch-*/ 1246 { 0xf80f, KEY_CHANNELDOWN }, /*ch-*/
966 { 0xf81a, KEY_O }, /*vol+*/ 1247 { 0xf81a, KEY_VOLUMEUP }, /*vol+*/
967 { 0xf80e, KEY_Z }, /*vol-*/ 1248 { 0xf80e, KEY_VOLUMEDOWN }, /*vol-*/
968 { 0xf804, KEY_R }, /*rec*/ 1249 { 0xf804, KEY_RECORD }, /*rec*/
969 { 0xf809, KEY_D }, /*fav*/ 1250 { 0xf809, KEY_FAVORITES }, /*fav*/
970 { 0xf808, KEY_BACKSPACE }, /*rewind*/ 1251 { 0xf808, KEY_REWIND }, /*rewind*/
971 { 0xf807, KEY_A }, /*fast*/ 1252 { 0xf807, KEY_FASTFORWARD }, /*fast*/
972 { 0xf80b, KEY_P }, /*pause*/ 1253 { 0xf80b, KEY_PAUSE }, /*pause*/
973 { 0xf802, KEY_ESC }, /*cancel*/ 1254 { 0xf802, KEY_ESC }, /*cancel*/
974 { 0xf803, KEY_G }, /*tab*/ 1255 { 0xf803, KEY_TAB }, /*tab*/
975 { 0xf800, KEY_UP }, /*up*/ 1256 { 0xf800, KEY_UP }, /*up*/
976 { 0xf81f, KEY_ENTER }, /*ok*/ 1257 { 0xf81f, KEY_OK }, /*ok*/
977 { 0xf801, KEY_DOWN }, /*down*/ 1258 { 0xf801, KEY_DOWN }, /*down*/
978 { 0xf805, KEY_C }, /*cap*/ 1259 { 0xf805, KEY_CAMERA }, /*cap*/
979 { 0xf806, KEY_S }, /*stop*/ 1260 { 0xf806, KEY_STOP }, /*stop*/
980 { 0xf840, KEY_F }, /*full*/ 1261 { 0xf840, KEY_ZOOM }, /*full*/
981 { 0xf81e, KEY_W }, /*tvmode*/ 1262 { 0xf81e, KEY_TV }, /*tvmode*/
982 { 0xf81b, KEY_B }, /*recall*/ 1263 { 0xf81b, KEY_LAST }, /*recall*/
983}; 1264};
984 1265
985static struct ir_scancode ir_codes_tevii_table[] = { 1266static struct rc_map_table rc_map_tevii_table[] = {
986 { 0xf80a, KEY_POWER }, 1267 { 0xf80a, KEY_POWER },
987 { 0xf80c, KEY_MUTE }, 1268 { 0xf80c, KEY_MUTE },
988 { 0xf811, KEY_1 }, 1269 { 0xf811, KEY_1 },
@@ -1032,7 +1313,7 @@ static struct ir_scancode ir_codes_tevii_table[] = {
1032 { 0xf858, KEY_SWITCHVIDEOMODE }, 1313 { 0xf858, KEY_SWITCHVIDEOMODE },
1033}; 1314};
1034 1315
1035static struct ir_scancode ir_codes_tbs_table[] = { 1316static struct rc_map_table rc_map_tbs_table[] = {
1036 { 0xf884, KEY_POWER }, 1317 { 0xf884, KEY_POWER },
1037 { 0xf894, KEY_MUTE }, 1318 { 0xf894, KEY_MUTE },
1038 { 0xf887, KEY_1 }, 1319 { 0xf887, KEY_1 },
@@ -1067,16 +1348,55 @@ static struct ir_scancode ir_codes_tbs_table[] = {
1067 { 0xf89b, KEY_MODE } 1348 { 0xf89b, KEY_MODE }
1068}; 1349};
1069 1350
1070static struct ir_codes_dvb_usb_table_table keys_tables[] = { 1351static struct rc_map_table rc_map_su3000_table[] = {
1071 { ir_codes_dw210x_table, ARRAY_SIZE(ir_codes_dw210x_table) }, 1352 { 0x25, KEY_POWER }, /* right-bottom Red */
1072 { ir_codes_tevii_table, ARRAY_SIZE(ir_codes_tevii_table) }, 1353 { 0x0a, KEY_MUTE }, /* -/-- */
1073 { ir_codes_tbs_table, ARRAY_SIZE(ir_codes_tbs_table) }, 1354 { 0x01, KEY_1 },
1355 { 0x02, KEY_2 },
1356 { 0x03, KEY_3 },
1357 { 0x04, KEY_4 },
1358 { 0x05, KEY_5 },
1359 { 0x06, KEY_6 },
1360 { 0x07, KEY_7 },
1361 { 0x08, KEY_8 },
1362 { 0x09, KEY_9 },
1363 { 0x00, KEY_0 },
1364 { 0x20, KEY_UP }, /* CH+ */
1365 { 0x21, KEY_DOWN }, /* CH+ */
1366 { 0x12, KEY_VOLUMEUP }, /* Brightness Up */
1367 { 0x13, KEY_VOLUMEDOWN },/* Brightness Down */
1368 { 0x1f, KEY_RECORD },
1369 { 0x17, KEY_PLAY },
1370 { 0x16, KEY_PAUSE },
1371 { 0x0b, KEY_STOP },
1372 { 0x27, KEY_FASTFORWARD },/* >> */
1373 { 0x26, KEY_REWIND }, /* << */
1374 { 0x0d, KEY_OK }, /* Mute */
1375 { 0x11, KEY_LEFT }, /* VOL- */
1376 { 0x10, KEY_RIGHT }, /* VOL+ */
1377 { 0x29, KEY_BACK }, /* button under 9 */
1378 { 0x2c, KEY_MENU }, /* TTX */
1379 { 0x2b, KEY_EPG }, /* EPG */
1380 { 0x1e, KEY_RED }, /* OSD */
1381 { 0x0e, KEY_GREEN }, /* Window */
1382 { 0x2d, KEY_YELLOW }, /* button under << */
1383 { 0x0f, KEY_BLUE }, /* bottom yellow button */
1384 { 0x14, KEY_AUDIO }, /* Snapshot */
1385 { 0x38, KEY_TV }, /* TV/Radio */
1386 { 0x0c, KEY_ESC } /* upper Red button */
1387};
1388
1389static struct rc_map_dvb_usb_table_table keys_tables[] = {
1390 { rc_map_dw210x_table, ARRAY_SIZE(rc_map_dw210x_table) },
1391 { rc_map_tevii_table, ARRAY_SIZE(rc_map_tevii_table) },
1392 { rc_map_tbs_table, ARRAY_SIZE(rc_map_tbs_table) },
1393 { rc_map_su3000_table, ARRAY_SIZE(rc_map_su3000_table) },
1074}; 1394};
1075 1395
1076static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 1396static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
1077{ 1397{
1078 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 1398 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
1079 int keymap_size = d->props.rc.legacy.rc_key_map_size; 1399 int keymap_size = d->props.rc.legacy.rc_map_size;
1080 u8 key[2]; 1400 u8 key[2];
1081 struct i2c_msg msg = { 1401 struct i2c_msg msg = {
1082 .addr = DW2102_RC_QUERY, 1402 .addr = DW2102_RC_QUERY,
@@ -1089,7 +1409,8 @@ static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
1089 if ((ir_keymap > 0) && (ir_keymap <= ARRAY_SIZE(keys_tables))) { 1409 if ((ir_keymap > 0) && (ir_keymap <= ARRAY_SIZE(keys_tables))) {
1090 keymap = keys_tables[ir_keymap - 1].rc_keys ; 1410 keymap = keys_tables[ir_keymap - 1].rc_keys ;
1091 keymap_size = keys_tables[ir_keymap - 1].rc_keys_size; 1411 keymap_size = keys_tables[ir_keymap - 1].rc_keys_size;
1092 } 1412 } else if (ir_keymap > ARRAY_SIZE(keys_tables))
1413 return 0; /* none */
1093 1414
1094 *state = REMOTE_NO_KEY_PRESSED; 1415 *state = REMOTE_NO_KEY_PRESSED;
1095 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) { 1416 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
@@ -1125,6 +1446,11 @@ static struct usb_device_id dw2102_table[] = {
1125 {USB_DEVICE(0x3011, USB_PID_PROF_1100)}, 1446 {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1126 {USB_DEVICE(0x9022, USB_PID_TEVII_S660)}, 1447 {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1127 {USB_DEVICE(0x3034, 0x7500)}, 1448 {USB_DEVICE(0x3034, 0x7500)},
1449 {USB_DEVICE(0x1f4d, 0x3000)},
1450 {USB_DEVICE(USB_VID_TERRATEC, 0x00a8)},
1451 {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1452 {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1453 {USB_DEVICE(0x1f4d, 0x3100)},
1128 { } 1454 { }
1129}; 1455};
1130 1456
@@ -1184,15 +1510,10 @@ static int dw2102_load_firmware(struct usb_device *dev,
1184 } 1510 }
1185 /* init registers */ 1511 /* init registers */
1186 switch (dev->descriptor.idProduct) { 1512 switch (dev->descriptor.idProduct) {
1187 case USB_PID_PROF_1100:
1188 s6x0_properties.rc.legacy.rc_key_map = ir_codes_tbs_table;
1189 s6x0_properties.rc.legacy.rc_key_map_size =
1190 ARRAY_SIZE(ir_codes_tbs_table);
1191 break;
1192 case USB_PID_TEVII_S650: 1513 case USB_PID_TEVII_S650:
1193 dw2104_properties.rc.legacy.rc_key_map = ir_codes_tevii_table; 1514 dw2104_properties.rc.legacy.rc_map_table = rc_map_tevii_table;
1194 dw2104_properties.rc.legacy.rc_key_map_size = 1515 dw2104_properties.rc.legacy.rc_map_size =
1195 ARRAY_SIZE(ir_codes_tevii_table); 1516 ARRAY_SIZE(rc_map_tevii_table);
1196 case USB_PID_DW2104: 1517 case USB_PID_DW2104:
1197 reset = 1; 1518 reset = 1;
1198 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1, 1519 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
@@ -1257,8 +1578,8 @@ static struct dvb_usb_device_properties dw2102_properties = {
1257 .i2c_algo = &dw2102_serit_i2c_algo, 1578 .i2c_algo = &dw2102_serit_i2c_algo,
1258 1579
1259 .rc.legacy = { 1580 .rc.legacy = {
1260 .rc_key_map = ir_codes_dw210x_table, 1581 .rc_map_table = rc_map_dw210x_table,
1261 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table), 1582 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1262 .rc_interval = 150, 1583 .rc_interval = 150,
1263 .rc_query = dw2102_rc_query, 1584 .rc_query = dw2102_rc_query,
1264 }, 1585 },
@@ -1271,8 +1592,6 @@ static struct dvb_usb_device_properties dw2102_properties = {
1271 .adapter = { 1592 .adapter = {
1272 { 1593 {
1273 .frontend_attach = dw2102_frontend_attach, 1594 .frontend_attach = dw2102_frontend_attach,
1274 .streaming_ctrl = NULL,
1275 .tuner_attach = NULL,
1276 .stream = { 1595 .stream = {
1277 .type = USB_BULK, 1596 .type = USB_BULK,
1278 .count = 8, 1597 .count = 8,
@@ -1310,8 +1629,8 @@ static struct dvb_usb_device_properties dw2104_properties = {
1310 1629
1311 .i2c_algo = &dw2104_i2c_algo, 1630 .i2c_algo = &dw2104_i2c_algo,
1312 .rc.legacy = { 1631 .rc.legacy = {
1313 .rc_key_map = ir_codes_dw210x_table, 1632 .rc_map_table = rc_map_dw210x_table,
1314 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table), 1633 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1315 .rc_interval = 150, 1634 .rc_interval = 150,
1316 .rc_query = dw2102_rc_query, 1635 .rc_query = dw2102_rc_query,
1317 }, 1636 },
@@ -1324,8 +1643,6 @@ static struct dvb_usb_device_properties dw2104_properties = {
1324 .adapter = { 1643 .adapter = {
1325 { 1644 {
1326 .frontend_attach = dw2104_frontend_attach, 1645 .frontend_attach = dw2104_frontend_attach,
1327 .streaming_ctrl = NULL,
1328 /*.tuner_attach = dw2104_tuner_attach,*/
1329 .stream = { 1646 .stream = {
1330 .type = USB_BULK, 1647 .type = USB_BULK,
1331 .count = 8, 1648 .count = 8,
@@ -1359,8 +1676,8 @@ static struct dvb_usb_device_properties dw3101_properties = {
1359 1676
1360 .i2c_algo = &dw3101_i2c_algo, 1677 .i2c_algo = &dw3101_i2c_algo,
1361 .rc.legacy = { 1678 .rc.legacy = {
1362 .rc_key_map = ir_codes_dw210x_table, 1679 .rc_map_table = rc_map_dw210x_table,
1363 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table), 1680 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1364 .rc_interval = 150, 1681 .rc_interval = 150,
1365 .rc_query = dw2102_rc_query, 1682 .rc_query = dw2102_rc_query,
1366 }, 1683 },
@@ -1373,7 +1690,6 @@ static struct dvb_usb_device_properties dw3101_properties = {
1373 .adapter = { 1690 .adapter = {
1374 { 1691 {
1375 .frontend_attach = dw3101_frontend_attach, 1692 .frontend_attach = dw3101_frontend_attach,
1376 .streaming_ctrl = NULL,
1377 .tuner_attach = dw3101_tuner_attach, 1693 .tuner_attach = dw3101_tuner_attach,
1378 .stream = { 1694 .stream = {
1379 .type = USB_BULK, 1695 .type = USB_BULK,
@@ -1399,13 +1715,14 @@ static struct dvb_usb_device_properties dw3101_properties = {
1399static struct dvb_usb_device_properties s6x0_properties = { 1715static struct dvb_usb_device_properties s6x0_properties = {
1400 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1716 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1401 .usb_ctrl = DEVICE_SPECIFIC, 1717 .usb_ctrl = DEVICE_SPECIFIC,
1718 .size_of_priv = sizeof(struct s6x0_state),
1402 .firmware = "dvb-usb-s630.fw", 1719 .firmware = "dvb-usb-s630.fw",
1403 .no_reconnect = 1, 1720 .no_reconnect = 1,
1404 1721
1405 .i2c_algo = &s6x0_i2c_algo, 1722 .i2c_algo = &s6x0_i2c_algo,
1406 .rc.legacy = { 1723 .rc.legacy = {
1407 .rc_key_map = ir_codes_tevii_table, 1724 .rc_map_table = rc_map_tevii_table,
1408 .rc_key_map_size = ARRAY_SIZE(ir_codes_tevii_table), 1725 .rc_map_size = ARRAY_SIZE(rc_map_tevii_table),
1409 .rc_interval = 150, 1726 .rc_interval = 150,
1410 .rc_query = dw2102_rc_query, 1727 .rc_query = dw2102_rc_query,
1411 }, 1728 },
@@ -1416,9 +1733,7 @@ static struct dvb_usb_device_properties s6x0_properties = {
1416 .read_mac_address = s6x0_read_mac_address, 1733 .read_mac_address = s6x0_read_mac_address,
1417 .adapter = { 1734 .adapter = {
1418 { 1735 {
1419 .frontend_attach = s6x0_frontend_attach, 1736 .frontend_attach = zl100313_frontend_attach,
1420 .streaming_ctrl = NULL,
1421 .tuner_attach = NULL,
1422 .stream = { 1737 .stream = {
1423 .type = USB_BULK, 1738 .type = USB_BULK,
1424 .count = 8, 1739 .count = 8,
@@ -1431,23 +1746,41 @@ static struct dvb_usb_device_properties s6x0_properties = {
1431 }, 1746 },
1432 } 1747 }
1433 }, 1748 },
1434 .num_device_descs = 3, 1749 .num_device_descs = 1,
1435 .devices = { 1750 .devices = {
1436 {"TeVii S630 USB", 1751 {"TeVii S630 USB",
1437 {&dw2102_table[6], NULL}, 1752 {&dw2102_table[6], NULL},
1438 {NULL}, 1753 {NULL},
1439 }, 1754 },
1440 {"Prof 1100 USB ",
1441 {&dw2102_table[7], NULL},
1442 {NULL},
1443 },
1444 {"TeVii S660 USB",
1445 {&dw2102_table[8], NULL},
1446 {NULL},
1447 },
1448 } 1755 }
1449}; 1756};
1450 1757
1758struct dvb_usb_device_properties *p1100;
1759static struct dvb_usb_device_description d1100 = {
1760 "Prof 1100 USB ",
1761 {&dw2102_table[7], NULL},
1762 {NULL},
1763};
1764
1765struct dvb_usb_device_properties *s660;
1766static struct dvb_usb_device_description d660 = {
1767 "TeVii S660 USB",
1768 {&dw2102_table[8], NULL},
1769 {NULL},
1770};
1771
1772static struct dvb_usb_device_description d480_1 = {
1773 "TeVii S480.1 USB",
1774 {&dw2102_table[12], NULL},
1775 {NULL},
1776};
1777
1778static struct dvb_usb_device_description d480_2 = {
1779 "TeVii S480.2 USB",
1780 {&dw2102_table[13], NULL},
1781 {NULL},
1782};
1783
1451struct dvb_usb_device_properties *p7500; 1784struct dvb_usb_device_properties *p7500;
1452static struct dvb_usb_device_description d7500 = { 1785static struct dvb_usb_device_description d7500 = {
1453 "Prof 7500 USB DVB-S2", 1786 "Prof 7500 USB DVB-S2",
@@ -1455,21 +1788,101 @@ static struct dvb_usb_device_description d7500 = {
1455 {NULL}, 1788 {NULL},
1456}; 1789};
1457 1790
1791static struct dvb_usb_device_properties su3000_properties = {
1792 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1793 .usb_ctrl = DEVICE_SPECIFIC,
1794 .size_of_priv = sizeof(struct su3000_state),
1795 .power_ctrl = su3000_power_ctrl,
1796 .num_adapters = 1,
1797 .identify_state = su3000_identify_state,
1798 .i2c_algo = &su3000_i2c_algo,
1799
1800 .rc.legacy = {
1801 .rc_map_table = rc_map_su3000_table,
1802 .rc_map_size = ARRAY_SIZE(rc_map_su3000_table),
1803 .rc_interval = 150,
1804 .rc_query = dw2102_rc_query,
1805 },
1806
1807 .read_mac_address = su3000_read_mac_address,
1808
1809 .generic_bulk_ctrl_endpoint = 0x01,
1810
1811 .adapter = {
1812 {
1813 .streaming_ctrl = su3000_streaming_ctrl,
1814 .frontend_attach = su3000_frontend_attach,
1815 .stream = {
1816 .type = USB_BULK,
1817 .count = 8,
1818 .endpoint = 0x82,
1819 .u = {
1820 .bulk = {
1821 .buffersize = 4096,
1822 }
1823 }
1824 }
1825 }
1826 },
1827 .num_device_descs = 3,
1828 .devices = {
1829 { "SU3000HD DVB-S USB2.0",
1830 { &dw2102_table[10], NULL },
1831 { NULL },
1832 },
1833 { "Terratec Cinergy S2 USB HD",
1834 { &dw2102_table[11], NULL },
1835 { NULL },
1836 },
1837 { "X3M TV SPC1400HD PCI",
1838 { &dw2102_table[14], NULL },
1839 { NULL },
1840 },
1841 }
1842};
1843
1458static int dw2102_probe(struct usb_interface *intf, 1844static int dw2102_probe(struct usb_interface *intf,
1459 const struct usb_device_id *id) 1845 const struct usb_device_id *id)
1460{ 1846{
1847 p1100 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1848 if (!p1100)
1849 return -ENOMEM;
1850 /* copy default structure */
1851 memcpy(p1100, &s6x0_properties,
1852 sizeof(struct dvb_usb_device_properties));
1853 /* fill only different fields */
1854 p1100->firmware = "dvb-usb-p1100.fw";
1855 p1100->devices[0] = d1100;
1856 p1100->rc.legacy.rc_map_table = rc_map_tbs_table;
1857 p1100->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
1858 p1100->adapter->frontend_attach = stv0288_frontend_attach;
1859
1860 s660 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1861 if (!s660) {
1862 kfree(p1100);
1863 return -ENOMEM;
1864 }
1865 memcpy(s660, &s6x0_properties,
1866 sizeof(struct dvb_usb_device_properties));
1867 s660->firmware = "dvb-usb-s660.fw";
1868 s660->num_device_descs = 3;
1869 s660->devices[0] = d660;
1870 s660->devices[1] = d480_1;
1871 s660->devices[2] = d480_2;
1872 s660->adapter->frontend_attach = ds3000_frontend_attach;
1461 1873
1462 p7500 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL); 1874 p7500 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1463 if (!p7500) 1875 if (!p7500) {
1876 kfree(p1100);
1877 kfree(s660);
1464 return -ENOMEM; 1878 return -ENOMEM;
1465 /* copy default structure */ 1879 }
1466 memcpy(p7500, &s6x0_properties, 1880 memcpy(p7500, &s6x0_properties,
1467 sizeof(struct dvb_usb_device_properties)); 1881 sizeof(struct dvb_usb_device_properties));
1468 /* fill only different fields */
1469 p7500->firmware = "dvb-usb-p7500.fw"; 1882 p7500->firmware = "dvb-usb-p7500.fw";
1470 p7500->devices[0] = d7500; 1883 p7500->devices[0] = d7500;
1471 p7500->rc.legacy.rc_key_map = ir_codes_tbs_table; 1884 p7500->rc.legacy.rc_map_table = rc_map_tbs_table;
1472 p7500->rc.legacy.rc_key_map_size = ARRAY_SIZE(ir_codes_tbs_table); 1885 p7500->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
1473 p7500->adapter->frontend_attach = prof_7500_frontend_attach; 1886 p7500->adapter->frontend_attach = prof_7500_frontend_attach;
1474 1887
1475 if (0 == dvb_usb_device_init(intf, &dw2102_properties, 1888 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
@@ -1480,8 +1893,14 @@ static int dw2102_probe(struct usb_interface *intf,
1480 THIS_MODULE, NULL, adapter_nr) || 1893 THIS_MODULE, NULL, adapter_nr) ||
1481 0 == dvb_usb_device_init(intf, &s6x0_properties, 1894 0 == dvb_usb_device_init(intf, &s6x0_properties,
1482 THIS_MODULE, NULL, adapter_nr) || 1895 THIS_MODULE, NULL, adapter_nr) ||
1896 0 == dvb_usb_device_init(intf, p1100,
1897 THIS_MODULE, NULL, adapter_nr) ||
1898 0 == dvb_usb_device_init(intf, s660,
1899 THIS_MODULE, NULL, adapter_nr) ||
1483 0 == dvb_usb_device_init(intf, p7500, 1900 0 == dvb_usb_device_init(intf, p7500,
1484 THIS_MODULE, NULL, adapter_nr)) 1901 THIS_MODULE, NULL, adapter_nr) ||
1902 0 == dvb_usb_device_init(intf, &su3000_properties,
1903 THIS_MODULE, NULL, adapter_nr))
1485 return 0; 1904 return 0;
1486 1905
1487 return -ENODEV; 1906 return -ENODEV;
@@ -1514,7 +1933,8 @@ module_exit(dw2102_module_exit);
1514MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by"); 1933MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
1515MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104," 1934MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
1516 " DVB-C 3101 USB2.0," 1935 " DVB-C 3101 USB2.0,"
1517 " TeVii S600, S630, S650, S660 USB2.0," 1936 " TeVii S600, S630, S650, S660, S480,"
1518 " Prof 1100, 7500 USB2.0 devices"); 1937 " Prof 1100, 7500 USB2.0,"
1938 " Geniatech SU3000 devices");
1519MODULE_VERSION("0.1"); 1939MODULE_VERSION("0.1");
1520MODULE_LICENSE("GPL"); 1940MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/ec168.c b/drivers/media/dvb/dvb-usb/ec168.c
index 52f5d4f0f230..1ba3e5dbee10 100644
--- a/drivers/media/dvb/dvb-usb/ec168.c
+++ b/drivers/media/dvb/dvb-usb/ec168.c
@@ -36,7 +36,9 @@ static int ec168_rw_udev(struct usb_device *udev, struct ec168_req *req)
36 int ret; 36 int ret;
37 unsigned int pipe; 37 unsigned int pipe;
38 u8 request, requesttype; 38 u8 request, requesttype;
39 u8 buf[req->size]; 39 u8 *buf;
40
41
40 42
41 switch (req->cmd) { 43 switch (req->cmd) {
42 case DOWNLOAD_FIRMWARE: 44 case DOWNLOAD_FIRMWARE:
@@ -72,6 +74,12 @@ static int ec168_rw_udev(struct usb_device *udev, struct ec168_req *req)
72 goto error; 74 goto error;
73 } 75 }
74 76
77 buf = kmalloc(req->size, GFP_KERNEL);
78 if (!buf) {
79 ret = -ENOMEM;
80 goto error;
81 }
82
75 if (requesttype == (USB_TYPE_VENDOR | USB_DIR_OUT)) { 83 if (requesttype == (USB_TYPE_VENDOR | USB_DIR_OUT)) {
76 /* write */ 84 /* write */
77 memcpy(buf, req->data, req->size); 85 memcpy(buf, req->data, req->size);
@@ -84,13 +92,13 @@ static int ec168_rw_udev(struct usb_device *udev, struct ec168_req *req)
84 msleep(1); /* avoid I2C errors */ 92 msleep(1); /* avoid I2C errors */
85 93
86 ret = usb_control_msg(udev, pipe, request, requesttype, req->value, 94 ret = usb_control_msg(udev, pipe, request, requesttype, req->value,
87 req->index, buf, sizeof(buf), EC168_USB_TIMEOUT); 95 req->index, buf, req->size, EC168_USB_TIMEOUT);
88 96
89 ec168_debug_dump(request, requesttype, req->value, req->index, buf, 97 ec168_debug_dump(request, requesttype, req->value, req->index, buf,
90 req->size, deb_xfer); 98 req->size, deb_xfer);
91 99
92 if (ret < 0) 100 if (ret < 0)
93 goto error; 101 goto err_dealloc;
94 else 102 else
95 ret = 0; 103 ret = 0;
96 104
@@ -98,7 +106,11 @@ static int ec168_rw_udev(struct usb_device *udev, struct ec168_req *req)
98 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN)) 106 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
99 memcpy(req->data, buf, req->size); 107 memcpy(req->data, buf, req->size);
100 108
109 kfree(buf);
101 return ret; 110 return ret;
111
112err_dealloc:
113 kfree(buf);
102error: 114error:
103 deb_info("%s: failed:%d\n", __func__, ret); 115 deb_info("%s: failed:%d\n", __func__, ret);
104 return ret; 116 return ret;
diff --git a/drivers/media/dvb/dvb-usb/friio-fe.c b/drivers/media/dvb/dvb-usb/friio-fe.c
index 93c21ddd0b77..015b4e8af1a5 100644
--- a/drivers/media/dvb/dvb-usb/friio-fe.c
+++ b/drivers/media/dvb/dvb-usb/friio-fe.c
@@ -75,7 +75,7 @@ static int jdvbt90502_single_reg_write(struct jdvbt90502_state *state,
75 return 0; 75 return 0;
76} 76}
77 77
78static int _jdvbt90502_write(struct dvb_frontend *fe, u8 *buf, int len) 78static int _jdvbt90502_write(struct dvb_frontend *fe, const u8 buf[], int len)
79{ 79{
80 struct jdvbt90502_state *state = fe->demodulator_priv; 80 struct jdvbt90502_state *state = fe->demodulator_priv;
81 int err, i; 81 int err, i;
diff --git a/drivers/media/dvb/dvb-usb/friio.c b/drivers/media/dvb/dvb-usb/friio.c
index 14a65b4aec07..76159aed9bb0 100644
--- a/drivers/media/dvb/dvb-usb/friio.c
+++ b/drivers/media/dvb/dvb-usb/friio.c
@@ -142,17 +142,20 @@ static u32 gl861_i2c_func(struct i2c_adapter *adapter)
142 return I2C_FUNC_I2C; 142 return I2C_FUNC_I2C;
143} 143}
144 144
145
146static int friio_ext_ctl(struct dvb_usb_adapter *adap, 145static int friio_ext_ctl(struct dvb_usb_adapter *adap,
147 u32 sat_color, int lnb_on) 146 u32 sat_color, int lnb_on)
148{ 147{
149 int i; 148 int i;
150 int ret; 149 int ret;
151 struct i2c_msg msg; 150 struct i2c_msg msg;
152 u8 buf[2]; 151 u8 *buf;
153 u32 mask; 152 u32 mask;
154 u8 lnb = (lnb_on) ? FRIIO_CTL_LNB : 0; 153 u8 lnb = (lnb_on) ? FRIIO_CTL_LNB : 0;
155 154
155 buf = kmalloc(2, GFP_KERNEL);
156 if (!buf)
157 return -ENOMEM;
158
156 msg.addr = 0x00; 159 msg.addr = 0x00;
157 msg.flags = 0; 160 msg.flags = 0;
158 msg.len = 2; 161 msg.len = 2;
@@ -189,6 +192,7 @@ static int friio_ext_ctl(struct dvb_usb_adapter *adap,
189 buf[1] |= FRIIO_CTL_CLK; 192 buf[1] |= FRIIO_CTL_CLK;
190 ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1); 193 ret += gl861_i2c_xfer(&adap->dev->i2c_adap, &msg, 1);
191 194
195 kfree(buf);
192 return (ret == 70); 196 return (ret == 70);
193} 197}
194 198
@@ -219,11 +223,20 @@ static int friio_initialize(struct dvb_usb_device *d)
219 int ret; 223 int ret;
220 int i; 224 int i;
221 int retry = 0; 225 int retry = 0;
222 u8 rbuf[2]; 226 u8 *rbuf, *wbuf;
223 u8 wbuf[3];
224 227
225 deb_info("%s called.\n", __func__); 228 deb_info("%s called.\n", __func__);
226 229
230 wbuf = kmalloc(3, GFP_KERNEL);
231 if (!wbuf)
232 return -ENOMEM;
233
234 rbuf = kmalloc(2, GFP_KERNEL);
235 if (!rbuf) {
236 kfree(wbuf);
237 return -ENOMEM;
238 }
239
227 /* use gl861_i2c_msg instead of gl861_i2c_xfer(), */ 240 /* use gl861_i2c_msg instead of gl861_i2c_xfer(), */
228 /* because the i2c device is not set up yet. */ 241 /* because the i2c device is not set up yet. */
229 wbuf[0] = 0x11; 242 wbuf[0] = 0x11;
@@ -358,6 +371,8 @@ restart:
358 return 0; 371 return 0;
359 372
360error: 373error:
374 kfree(wbuf);
375 kfree(rbuf);
361 deb_info("%s:ret == %d\n", __func__, ret); 376 deb_info("%s:ret == %d\n", __func__, ret);
362 return -EIO; 377 return -EIO;
363} 378}
diff --git a/drivers/media/dvb/dvb-usb/friio.h b/drivers/media/dvb/dvb-usb/friio.h
index af8d55e390fb..0f461ca10cb9 100644
--- a/drivers/media/dvb/dvb-usb/friio.h
+++ b/drivers/media/dvb/dvb-usb/friio.h
@@ -20,7 +20,7 @@
20 * Frontend: comtech JDVBT-90502 20 * Frontend: comtech JDVBT-90502
21 * (tuner PLL: tua6034, I2C addr:(0xC0 >> 1)) 21 * (tuner PLL: tua6034, I2C addr:(0xC0 >> 1))
22 * (OFDM demodulator: TC90502, I2C addr:(0x30 >> 1)) 22 * (OFDM demodulator: TC90502, I2C addr:(0x30 >> 1))
23 * LED x3 (+LNB) controll: PIC 16F676 23 * LED x3 (+LNB) control: PIC 16F676
24 * EEPROM: 24C08 24 * EEPROM: 24C08
25 * 25 *
26 * (USB smart card reader: AU9522) 26 * (USB smart card reader: AU9522)
diff --git a/drivers/media/dvb/dvb-usb/gp8psk-fe.c b/drivers/media/dvb/dvb-usb/gp8psk-fe.c
index dbdb5347b2a8..60d11e57e7d0 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk-fe.c
+++ b/drivers/media/dvb/dvb-usb/gp8psk-fe.c
@@ -109,7 +109,7 @@ static int gp8psk_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength
109 109
110static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune) 110static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
111{ 111{
112 tune->min_delay_ms = 200; 112 tune->min_delay_ms = 800;
113 return 0; 113 return 0;
114} 114}
115 115
@@ -334,7 +334,7 @@ success:
334 334
335static struct dvb_frontend_ops gp8psk_fe_ops = { 335static struct dvb_frontend_ops gp8psk_fe_ops = {
336 .info = { 336 .info = {
337 .name = "Genpix 8psk-to-USB2 DVB-S", 337 .name = "Genpix DVB-S",
338 .type = FE_QPSK, 338 .type = FE_QPSK,
339 .frequency_min = 800000, 339 .frequency_min = 800000,
340 .frequency_max = 2250000, 340 .frequency_max = 2250000,
diff --git a/drivers/media/dvb/dvb-usb/gp8psk.c b/drivers/media/dvb/dvb-usb/gp8psk.c
index 45106ac49674..1cb3d9a66e02 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk.c
+++ b/drivers/media/dvb/dvb-usb/gp8psk.c
@@ -24,6 +24,33 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DV
24 24
25DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 25DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
26 26
27static int gp8psk_get_fw_version(struct dvb_usb_device *d, u8 *fw_vers)
28{
29 return (gp8psk_usb_in_op(d, GET_FW_VERS, 0, 0, fw_vers, 6));
30}
31
32static int gp8psk_get_fpga_version(struct dvb_usb_device *d, u8 *fpga_vers)
33{
34 return (gp8psk_usb_in_op(d, GET_FPGA_VERS, 0, 0, fpga_vers, 1));
35}
36
37static void gp8psk_info(struct dvb_usb_device *d)
38{
39 u8 fpga_vers, fw_vers[6];
40
41 if (!gp8psk_get_fw_version(d, fw_vers))
42 info("FW Version = %i.%02i.%i (0x%x) Build %4i/%02i/%02i",
43 fw_vers[2], fw_vers[1], fw_vers[0], GP8PSK_FW_VERS(fw_vers),
44 2000 + fw_vers[5], fw_vers[4], fw_vers[3]);
45 else
46 info("failed to get FW version");
47
48 if (!gp8psk_get_fpga_version(d, &fpga_vers))
49 info("FPGA Version = %i", fpga_vers);
50 else
51 info("failed to get FPGA version");
52}
53
27int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen) 54int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen)
28{ 55{
29 int ret = 0,try = 0; 56 int ret = 0,try = 0;
@@ -146,6 +173,7 @@ static int gp8psk_power_ctrl(struct dvb_usb_device *d, int onoff)
146 gp8psk_usb_out_op(d, CW3K_INIT, 1, 0, NULL, 0); 173 gp8psk_usb_out_op(d, CW3K_INIT, 1, 0, NULL, 0);
147 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1)) 174 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
148 return -EINVAL; 175 return -EINVAL;
176 gp8psk_info(d);
149 } 177 }
150 178
151 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM) 179 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
@@ -227,6 +255,7 @@ static struct usb_device_id gp8psk_usb_table [] = {
227 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_1_WARM) }, 255 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_1_WARM) },
228 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_2) }, 256 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_2) },
229 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_1) }, 257 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_1) },
258 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_2) },
230/* { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_CW3K) }, */ 259/* { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_CW3K) }, */
231 { 0 }, 260 { 0 },
232}; 261};
@@ -258,7 +287,7 @@ static struct dvb_usb_device_properties gp8psk_properties = {
258 287
259 .generic_bulk_ctrl_endpoint = 0x01, 288 .generic_bulk_ctrl_endpoint = 0x01,
260 289
261 .num_device_descs = 3, 290 .num_device_descs = 4,
262 .devices = { 291 .devices = {
263 { .name = "Genpix 8PSK-to-USB2 Rev.1 DVB-S receiver", 292 { .name = "Genpix 8PSK-to-USB2 Rev.1 DVB-S receiver",
264 .cold_ids = { &gp8psk_usb_table[0], NULL }, 293 .cold_ids = { &gp8psk_usb_table[0], NULL },
@@ -272,6 +301,10 @@ static struct dvb_usb_device_properties gp8psk_properties = {
272 .cold_ids = { NULL }, 301 .cold_ids = { NULL },
273 .warm_ids = { &gp8psk_usb_table[3], NULL }, 302 .warm_ids = { &gp8psk_usb_table[3], NULL },
274 }, 303 },
304 { .name = "Genpix SkyWalker-2 DVB-S receiver",
305 .cold_ids = { NULL },
306 .warm_ids = { &gp8psk_usb_table[4], NULL },
307 },
275 { NULL }, 308 { NULL },
276 } 309 }
277}; 310};
@@ -306,6 +339,6 @@ module_init(gp8psk_usb_module_init);
306module_exit(gp8psk_usb_module_exit); 339module_exit(gp8psk_usb_module_exit);
307 340
308MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>"); 341MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>");
309MODULE_DESCRIPTION("Driver for Genpix 8psk-to-USB2 DVB-S"); 342MODULE_DESCRIPTION("Driver for Genpix DVB-S");
310MODULE_VERSION("1.1"); 343MODULE_VERSION("1.1");
311MODULE_LICENSE("GPL"); 344MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/gp8psk.h b/drivers/media/dvb/dvb-usb/gp8psk.h
index e83a57506cfa..831749a518cb 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk.h
+++ b/drivers/media/dvb/dvb-usb/gp8psk.h
@@ -25,7 +25,6 @@ extern int dvb_usb_gp8psk_debug;
25#define deb_xfer(args...) dprintk(dvb_usb_gp8psk_debug,0x02,args) 25#define deb_xfer(args...) dprintk(dvb_usb_gp8psk_debug,0x02,args)
26#define deb_rc(args...) dprintk(dvb_usb_gp8psk_debug,0x04,args) 26#define deb_rc(args...) dprintk(dvb_usb_gp8psk_debug,0x04,args)
27#define deb_fe(args...) dprintk(dvb_usb_gp8psk_debug,0x08,args) 27#define deb_fe(args...) dprintk(dvb_usb_gp8psk_debug,0x08,args)
28/* gp8psk commands */
29 28
30/* Twinhan Vendor requests */ 29/* Twinhan Vendor requests */
31#define TH_COMMAND_IN 0xC0 30#define TH_COMMAND_IN 0xC0
@@ -49,8 +48,10 @@ extern int dvb_usb_gp8psk_debug;
49#define SET_DVB_MODE 0x8E 48#define SET_DVB_MODE 0x8E
50#define SET_DN_SWITCH 0x8F 49#define SET_DN_SWITCH 0x8F
51#define GET_SIGNAL_LOCK 0x90 /* in */ 50#define GET_SIGNAL_LOCK 0x90 /* in */
51#define GET_FW_VERS 0x92
52#define GET_SERIAL_NUMBER 0x93 /* in */ 52#define GET_SERIAL_NUMBER 0x93 /* in */
53#define USE_EXTRA_VOLT 0x94 53#define USE_EXTRA_VOLT 0x94
54#define GET_FPGA_VERS 0x95
54#define CW3K_INIT 0x9d 55#define CW3K_INIT 0x9d
55 56
56/* PSK_configuration bits */ 57/* PSK_configuration bits */
@@ -88,6 +89,11 @@ extern int dvb_usb_gp8psk_debug;
88#define PRODUCT_STRING_READ 0x0D 89#define PRODUCT_STRING_READ 0x0D
89#define FW_BCD_VERSION_READ 0x14 90#define FW_BCD_VERSION_READ 0x14
90 91
92/* firmware revision id's */
93#define GP8PSK_FW_REV1 0x020604
94#define GP8PSK_FW_REV2 0x020704
95#define GP8PSK_FW_VERS(_fw_vers) ((_fw_vers)[2]<<0x10 | (_fw_vers)[1]<<0x08 | (_fw_vers)[0])
96
91extern struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d); 97extern struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d);
92extern int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen); 98extern int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen);
93extern int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value, 99extern int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
diff --git a/drivers/media/dvb/dvb-usb/lmedm04.c b/drivers/media/dvb/dvb-usb/lmedm04.c
new file mode 100644
index 000000000000..37b146961ae2
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/lmedm04.c
@@ -0,0 +1,1310 @@
1/* DVB USB compliant linux driver for
2 *
3 * DM04/QQBOX DVB-S USB BOX LME2510C + SHARP:BS2F7HZ7395
4 * LME2510C + LG TDQY-P001F
5 * LME2510C + BS2F7HZ0194
6 * LME2510 + LG TDQY-P001F
7 * LME2510 + BS2F7HZ0194
8 *
9 * MVB7395 (LME2510C+SHARP:BS2F7HZ7395)
10 * SHARP:BS2F7HZ7395 = (STV0288+Sharp IX2505V)
11 *
12 * MV001F (LME2510+LGTDQY-P001F)
13 * LG TDQY - P001F =(TDA8263 + TDA10086H)
14 *
15 * MVB0001F (LME2510C+LGTDQT-P001F)
16 *
17 * MV0194 (LME2510+SHARP:BS2F7HZ0194)
18 * SHARP:BS2F7HZ0194 = (STV0299+IX2410)
19 *
20 * MVB0194 (LME2510C+SHARP0194)
21 *
22 * For firmware see Documentation/dvb/lmedm04.txt
23 *
24 * I2C addresses:
25 * 0xd0 - STV0288 - Demodulator
26 * 0xc0 - Sharp IX2505V - Tuner
27 * --
28 * 0x1c - TDA10086 - Demodulator
29 * 0xc0 - TDA8263 - Tuner
30 * --
31 * 0xd0 - STV0299 - Demodulator
32 * 0xc0 - IX2410 - Tuner
33 *
34 *
35 * VID = 3344 PID LME2510=1122 LME2510C=1120
36 *
37 * Copyright (C) 2010 Malcolm Priestley (tvboxspy@gmail.com)
38 * LME2510(C)(C) Leaguerme (Shenzhen) MicroElectronics Co., Ltd.
39 *
40 * This program is free software; you can redistribute it and/or modify
41 * it under the terms of the GNU General Public License Version 2, as
42 * published by the Free Software Foundation.
43 *
44 * This program is distributed in the hope that it will be useful,
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47 * GNU General Public License for more details.
48 *
49 * You should have received a copy of the GNU General Public License
50 * along with this program; if not, write to the Free Software
51 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
52 *
53 *
54 * see Documentation/dvb/README.dvb-usb for more information
55 *
56 * Known Issues :
57 * LME2510: Non Intel USB chipsets fail to maintain High Speed on
58 * Boot or Hot Plug.
59 *
60 * QQbox suffers from noise on LNB voltage.
61 *
62 * LME2510: SHARP:BS2F7HZ0194(MV0194) cannot cold reset and share system
63 * with other tuners. After a cold reset streaming will not start.
64 *
65 */
66#define DVB_USB_LOG_PREFIX "LME2510(C)"
67#include <linux/usb.h>
68#include <linux/usb/input.h>
69#include <media/rc-core.h>
70
71#include "dvb-usb.h"
72#include "lmedm04.h"
73#include "tda826x.h"
74#include "tda10086.h"
75#include "stv0288.h"
76#include "ix2505v.h"
77#include "stv0299.h"
78#include "dvb-pll.h"
79#include "z0194a.h"
80
81
82
83/* debug */
84static int dvb_usb_lme2510_debug;
85#define l_dprintk(var, level, args...) do { \
86 if ((var >= level)) \
87 printk(KERN_DEBUG DVB_USB_LOG_PREFIX ": " args); \
88} while (0)
89
90#define deb_info(level, args...) l_dprintk(dvb_usb_lme2510_debug, level, args)
91#define debug_data_snipet(level, name, p) \
92 deb_info(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \
93 *p, *(p+1), *(p+2), *(p+3), *(p+4), \
94 *(p+5), *(p+6), *(p+7));
95
96
97module_param_named(debug, dvb_usb_lme2510_debug, int, 0644);
98MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))."
99 DVB_USB_DEBUG_STATUS);
100
101static int dvb_usb_lme2510_firmware;
102module_param_named(firmware, dvb_usb_lme2510_firmware, int, 0644);
103MODULE_PARM_DESC(firmware, "set default firmware 0=Sharp7395 1=LG");
104
105static int pid_filter;
106module_param_named(pid, pid_filter, int, 0644);
107MODULE_PARM_DESC(pid, "set default 0=on 1=off");
108
109
110DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
111
112#define TUNER_DEFAULT 0x0
113#define TUNER_LG 0x1
114#define TUNER_S7395 0x2
115#define TUNER_S0194 0x3
116
117struct lme2510_state {
118 u8 id;
119 u8 tuner_config;
120 u8 signal_lock;
121 u8 signal_level;
122 u8 signal_sn;
123 u8 time_key;
124 u8 i2c_talk_onoff;
125 u8 i2c_gate;
126 u8 i2c_tuner_gate_w;
127 u8 i2c_tuner_gate_r;
128 u8 i2c_tuner_addr;
129 u8 stream_on;
130 u8 pid_size;
131 void *buffer;
132 struct urb *lme_urb;
133 void *usb_buffer;
134
135};
136
137static int lme2510_bulk_write(struct usb_device *dev,
138 u8 *snd, int len, u8 pipe)
139{
140 int ret, actual_l;
141
142 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe),
143 snd, len , &actual_l, 100);
144 return ret;
145}
146
147static int lme2510_bulk_read(struct usb_device *dev,
148 u8 *rev, int len, u8 pipe)
149{
150 int ret, actual_l;
151
152 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe),
153 rev, len , &actual_l, 200);
154 return ret;
155}
156
157static int lme2510_usb_talk(struct dvb_usb_device *d,
158 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
159{
160 struct lme2510_state *st = d->priv;
161 u8 *buff;
162 int ret = 0;
163
164 if (st->usb_buffer == NULL) {
165 st->usb_buffer = kmalloc(512, GFP_KERNEL);
166 if (st->usb_buffer == NULL) {
167 info("MEM Error no memory");
168 return -ENOMEM;
169 }
170 }
171 buff = st->usb_buffer;
172
173 ret = mutex_lock_interruptible(&d->usb_mutex);
174
175 if (ret < 0)
176 return -EAGAIN;
177
178 /* the read/write capped at 512 */
179 memcpy(buff, wbuf, (wlen > 512) ? 512 : wlen);
180
181 ret |= usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, 0x01));
182
183 ret |= lme2510_bulk_write(d->udev, buff, wlen , 0x01);
184
185 msleep(10);
186
187 ret |= usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x01));
188
189 ret |= lme2510_bulk_read(d->udev, buff, (rlen > 512) ?
190 512 : rlen , 0x01);
191
192 if (rlen > 0)
193 memcpy(rbuf, buff, rlen);
194
195 mutex_unlock(&d->usb_mutex);
196
197 return (ret < 0) ? -ENODEV : 0;
198}
199
200static int lme2510_stream_restart(struct dvb_usb_device *d)
201{
202 static u8 stream_on[] = LME_ST_ON_W;
203 int ret;
204 u8 rbuff[10];
205 /*Restart Stream Command*/
206 ret = lme2510_usb_talk(d, stream_on, sizeof(stream_on),
207 rbuff, sizeof(rbuff));
208 return ret;
209}
210
211static int lme2510_enable_pid(struct dvb_usb_device *d, u8 index, u16 pid_out)
212{
213 struct lme2510_state *st = d->priv;
214 static u8 pid_buff[] = LME_ZERO_PID;
215 static u8 rbuf[1];
216 u8 pid_no = index * 2;
217 u8 pid_len = pid_no + 2;
218 int ret = 0;
219 deb_info(1, "PID Setting Pid %04x", pid_out);
220
221 if (st->pid_size == 0)
222 ret |= lme2510_stream_restart(d);
223
224 pid_buff[2] = pid_no;
225 pid_buff[3] = (u8)pid_out & 0xff;
226 pid_buff[4] = pid_no + 1;
227 pid_buff[5] = (u8)(pid_out >> 8);
228
229 if (pid_len > st->pid_size)
230 st->pid_size = pid_len;
231 pid_buff[7] = 0x80 + st->pid_size;
232
233 ret |= lme2510_usb_talk(d, pid_buff ,
234 sizeof(pid_buff) , rbuf, sizeof(rbuf));
235
236 if (st->stream_on)
237 ret |= lme2510_stream_restart(d);
238
239 return ret;
240}
241
242static void lme2510_int_response(struct urb *lme_urb)
243{
244 struct dvb_usb_adapter *adap = lme_urb->context;
245 struct lme2510_state *st = adap->dev->priv;
246 static u8 *ibuf, *rbuf;
247 int i = 0, offset;
248 u32 key;
249
250 switch (lme_urb->status) {
251 case 0:
252 case -ETIMEDOUT:
253 break;
254 case -ECONNRESET:
255 case -ENOENT:
256 case -ESHUTDOWN:
257 return;
258 default:
259 info("Error %x", lme_urb->status);
260 break;
261 }
262
263 rbuf = (u8 *) lme_urb->transfer_buffer;
264
265 offset = ((lme_urb->actual_length/8) > 4)
266 ? 4 : (lme_urb->actual_length/8) ;
267
268 for (i = 0; i < offset; ++i) {
269 ibuf = (u8 *)&rbuf[i*8];
270 deb_info(5, "INT O/S C =%02x C/O=%02x Type =%02x%02x",
271 offset, i, ibuf[0], ibuf[1]);
272
273 switch (ibuf[0]) {
274 case 0xaa:
275 debug_data_snipet(1, "INT Remote data snipet", ibuf);
276 if ((ibuf[4] + ibuf[5]) == 0xff) {
277 key = ibuf[5];
278 key += (ibuf[3] > 0)
279 ? (ibuf[3] ^ 0xff) << 8 : 0;
280 key += (ibuf[2] ^ 0xff) << 16;
281 deb_info(1, "INT Key =%08x", key);
282 if (adap->dev->rc_dev != NULL)
283 rc_keydown(adap->dev->rc_dev, key, 0);
284 }
285 break;
286 case 0xbb:
287 switch (st->tuner_config) {
288 case TUNER_LG:
289 if (ibuf[2] > 0)
290 st->signal_lock = ibuf[2];
291 st->signal_level = ibuf[4];
292 st->signal_sn = ibuf[3];
293 st->time_key = ibuf[7];
294 break;
295 case TUNER_S7395:
296 case TUNER_S0194:
297 /* Tweak for earlier firmware*/
298 if (ibuf[1] == 0x03) {
299 if (ibuf[2] > 1)
300 st->signal_lock = ibuf[2];
301 st->signal_level = ibuf[3];
302 st->signal_sn = ibuf[4];
303 } else {
304 st->signal_level = ibuf[4];
305 st->signal_sn = ibuf[5];
306 st->signal_lock =
307 (st->signal_lock & 0xf7) +
308 ((ibuf[2] & 0x01) << 0x03);
309 }
310 break;
311 default:
312 break;
313 }
314 debug_data_snipet(5, "INT Remote data snipet in", ibuf);
315 break;
316 case 0xcc:
317 debug_data_snipet(1, "INT Control data snipet", ibuf);
318 break;
319 default:
320 debug_data_snipet(1, "INT Unknown data snipet", ibuf);
321 break;
322 }
323 }
324 usb_submit_urb(lme_urb, GFP_ATOMIC);
325}
326
327static int lme2510_int_read(struct dvb_usb_adapter *adap)
328{
329 struct lme2510_state *lme_int = adap->dev->priv;
330
331 lme_int->lme_urb = usb_alloc_urb(0, GFP_ATOMIC);
332
333 if (lme_int->lme_urb == NULL)
334 return -ENOMEM;
335
336 lme_int->buffer = usb_alloc_coherent(adap->dev->udev, 5000, GFP_ATOMIC,
337 &lme_int->lme_urb->transfer_dma);
338
339 if (lme_int->buffer == NULL)
340 return -ENOMEM;
341
342 usb_fill_int_urb(lme_int->lme_urb,
343 adap->dev->udev,
344 usb_rcvintpipe(adap->dev->udev, 0xa),
345 lme_int->buffer,
346 4096,
347 lme2510_int_response,
348 adap,
349 11);
350
351 lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
352
353 usb_submit_urb(lme_int->lme_urb, GFP_ATOMIC);
354 info("INT Interrupt Service Started");
355
356 return 0;
357}
358
359static int lme2510_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
360{
361 struct lme2510_state *st = adap->dev->priv;
362 static u8 clear_pid_reg[] = LME_CLEAR_PID;
363 static u8 rbuf[1];
364 int ret;
365
366 deb_info(1, "PID Clearing Filter");
367
368 ret = mutex_lock_interruptible(&adap->dev->i2c_mutex);
369 if (ret < 0)
370 return -EAGAIN;
371
372 if (!onoff)
373 ret |= lme2510_usb_talk(adap->dev, clear_pid_reg,
374 sizeof(clear_pid_reg), rbuf, sizeof(rbuf));
375
376 st->pid_size = 0;
377
378 mutex_unlock(&adap->dev->i2c_mutex);
379
380 return 0;
381}
382
383static int lme2510_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
384 int onoff)
385{
386 int ret = 0;
387
388 deb_info(3, "%s PID=%04x Index=%04x onoff=%02x", __func__,
389 pid, index, onoff);
390
391 if (onoff)
392 if (!pid_filter) {
393 ret = mutex_lock_interruptible(&adap->dev->i2c_mutex);
394 if (ret < 0)
395 return -EAGAIN;
396 ret |= lme2510_enable_pid(adap->dev, index, pid);
397 mutex_unlock(&adap->dev->i2c_mutex);
398 }
399
400
401 return ret;
402}
403
404
405static int lme2510_return_status(struct usb_device *dev)
406{
407 int ret = 0;
408 u8 *data;
409
410 data = kzalloc(10, GFP_KERNEL);
411 if (!data)
412 return -ENOMEM;
413
414 ret |= usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
415 0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200);
416 info("Firmware Status: %x (%x)", ret , data[2]);
417
418 ret = (ret < 0) ? -ENODEV : data[2];
419 kfree(data);
420 return ret;
421}
422
423static int lme2510_msg(struct dvb_usb_device *d,
424 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
425{
426 int ret = 0;
427 struct lme2510_state *st = d->priv;
428
429 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
430 return -EAGAIN;
431
432 if (st->i2c_talk_onoff == 1) {
433
434 ret = lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
435
436 switch (st->tuner_config) {
437 case TUNER_LG:
438 if (wbuf[2] == 0x1c) {
439 if (wbuf[3] == 0x0e) {
440 st->signal_lock = rbuf[1];
441 if ((st->stream_on & 1) &&
442 (st->signal_lock & 0x10)) {
443 lme2510_stream_restart(d);
444 st->i2c_talk_onoff = 0;
445 }
446 msleep(80);
447 }
448 }
449 break;
450 case TUNER_S7395:
451 if (wbuf[2] == 0xd0) {
452 if (wbuf[3] == 0x24) {
453 st->signal_lock = rbuf[1];
454 if ((st->stream_on & 1) &&
455 (st->signal_lock & 0x8)) {
456 lme2510_stream_restart(d);
457 st->i2c_talk_onoff = 0;
458 }
459 }
460 if ((wbuf[3] != 0x6) & (wbuf[3] != 0x5))
461 msleep(5);
462 }
463 break;
464 case TUNER_S0194:
465 if (wbuf[2] == 0xd0) {
466 if (wbuf[3] == 0x1b) {
467 st->signal_lock = rbuf[1];
468 if ((st->stream_on & 1) &&
469 (st->signal_lock & 0x8)) {
470 lme2510_stream_restart(d);
471 st->i2c_talk_onoff = 0;
472 }
473 }
474 }
475 break;
476 default:
477 break;
478 }
479 } else {
480 switch (st->tuner_config) {
481 case TUNER_LG:
482 switch (wbuf[3]) {
483 case 0x0e:
484 rbuf[0] = 0x55;
485 rbuf[1] = st->signal_lock;
486 break;
487 case 0x43:
488 rbuf[0] = 0x55;
489 rbuf[1] = st->signal_level;
490 break;
491 case 0x1c:
492 rbuf[0] = 0x55;
493 rbuf[1] = st->signal_sn;
494 break;
495 case 0x15:
496 case 0x16:
497 case 0x17:
498 case 0x18:
499 rbuf[0] = 0x55;
500 rbuf[1] = 0x00;
501 break;
502 default:
503 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
504 st->i2c_talk_onoff = 1;
505 break;
506 }
507 break;
508 case TUNER_S7395:
509 switch (wbuf[3]) {
510 case 0x10:
511 rbuf[0] = 0x55;
512 rbuf[1] = (st->signal_level & 0x80)
513 ? 0 : (st->signal_level * 2);
514 break;
515 case 0x2d:
516 rbuf[0] = 0x55;
517 rbuf[1] = st->signal_sn;
518 break;
519 case 0x24:
520 rbuf[0] = 0x55;
521 rbuf[1] = st->signal_lock;
522 break;
523 case 0x2e:
524 case 0x26:
525 case 0x27:
526 rbuf[0] = 0x55;
527 rbuf[1] = 0x00;
528 break;
529 default:
530 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
531 st->i2c_talk_onoff = 1;
532 break;
533 }
534 break;
535 case TUNER_S0194:
536 switch (wbuf[3]) {
537 case 0x18:
538 rbuf[0] = 0x55;
539 rbuf[1] = (st->signal_level & 0x80)
540 ? 0 : (st->signal_level * 2);
541 break;
542 case 0x24:
543 rbuf[0] = 0x55;
544 rbuf[1] = st->signal_sn;
545 break;
546 case 0x1b:
547 rbuf[0] = 0x55;
548 rbuf[1] = st->signal_lock;
549 break;
550 case 0x19:
551 case 0x25:
552 case 0x1e:
553 case 0x1d:
554 rbuf[0] = 0x55;
555 rbuf[1] = 0x00;
556 break;
557 default:
558 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
559 st->i2c_talk_onoff = 1;
560 break;
561 }
562 break;
563 default:
564 break;
565 }
566
567 deb_info(4, "I2C From Interrupt Message out(%02x) in(%02x)",
568 wbuf[3], rbuf[1]);
569
570 }
571
572 mutex_unlock(&d->i2c_mutex);
573
574 return ret;
575}
576
577
578static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
579 int num)
580{
581 struct dvb_usb_device *d = i2c_get_adapdata(adap);
582 struct lme2510_state *st = d->priv;
583 static u8 obuf[64], ibuf[512];
584 int i, read, read_o;
585 u16 len;
586 u8 gate = st->i2c_gate;
587
588 if (gate == 0)
589 gate = 5;
590
591 if (num > 2)
592 warn("more than 2 i2c messages"
593 "at a time is not handled yet. TODO.");
594
595 for (i = 0; i < num; i++) {
596 read_o = 1 & (msg[i].flags & I2C_M_RD);
597 read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
598 read |= read_o;
599 gate = (msg[i].addr == st->i2c_tuner_addr)
600 ? (read) ? st->i2c_tuner_gate_r
601 : st->i2c_tuner_gate_w
602 : st->i2c_gate;
603 obuf[0] = gate | (read << 7);
604
605 if (gate == 5)
606 obuf[1] = (read) ? 2 : msg[i].len + 1;
607 else
608 obuf[1] = msg[i].len + read + 1;
609
610 obuf[2] = msg[i].addr;
611 if (read) {
612 if (read_o)
613 len = 3;
614 else {
615 memcpy(&obuf[3], msg[i].buf, msg[i].len);
616 obuf[msg[i].len+3] = msg[i+1].len;
617 len = msg[i].len+4;
618 }
619 } else {
620 memcpy(&obuf[3], msg[i].buf, msg[i].len);
621 len = msg[i].len+3;
622 }
623
624 if (lme2510_msg(d, obuf, len, ibuf, 512) < 0) {
625 deb_info(1, "i2c transfer failed.");
626 return -EAGAIN;
627 }
628
629 if (read) {
630 if (read_o)
631 memcpy(msg[i].buf, &ibuf[1], msg[i].len);
632 else {
633 memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
634 i++;
635 }
636 }
637 }
638 return i;
639}
640
641static u32 lme2510_i2c_func(struct i2c_adapter *adapter)
642{
643 return I2C_FUNC_I2C;
644}
645
646static struct i2c_algorithm lme2510_i2c_algo = {
647 .master_xfer = lme2510_i2c_xfer,
648 .functionality = lme2510_i2c_func,
649};
650
651/* Callbacks for DVB USB */
652static int lme2510_identify_state(struct usb_device *udev,
653 struct dvb_usb_device_properties *props,
654 struct dvb_usb_device_description **desc,
655 int *cold)
656{
657 *cold = 0;
658 return 0;
659}
660
661static int lme2510_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
662{
663 struct lme2510_state *st = adap->dev->priv;
664 static u8 clear_reg_3[] = LME_CLEAR_PID;
665 static u8 rbuf[1];
666 int ret = 0, rlen = sizeof(rbuf);
667
668 deb_info(1, "STM (%02x)", onoff);
669
670 /* Streaming is started by FE_HAS_LOCK */
671 if (onoff == 1)
672 st->stream_on = 1;
673 else {
674 deb_info(1, "STM Steam Off");
675 /* mutex is here only to avoid collision with I2C */
676 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
677 return -EAGAIN;
678
679 ret = lme2510_usb_talk(adap->dev, clear_reg_3,
680 sizeof(clear_reg_3), rbuf, rlen);
681 st->stream_on = 0;
682 st->i2c_talk_onoff = 1;
683
684 mutex_unlock(&adap->dev->i2c_mutex);
685 }
686
687 return (ret < 0) ? -ENODEV : 0;
688}
689
690static u8 check_sum(u8 *p, u8 len)
691{
692 u8 sum = 0;
693 while (len--)
694 sum += *p++;
695 return sum;
696}
697
698static int lme2510_download_firmware(struct usb_device *dev,
699 const struct firmware *fw)
700{
701 int ret = 0;
702 u8 *data;
703 u16 j, wlen, len_in, start, end;
704 u8 packet_size, dlen, i;
705 u8 *fw_data;
706
707 packet_size = 0x31;
708 len_in = 1;
709
710 data = kzalloc(512, GFP_KERNEL);
711 if (!data) {
712 info("FRM Could not start Firmware Download (Buffer allocation failed)");
713 return -ENOMEM;
714 }
715
716 info("FRM Starting Firmware Download");
717
718 for (i = 1; i < 3; i++) {
719 start = (i == 1) ? 0 : 512;
720 end = (i == 1) ? 512 : fw->size;
721 for (j = start; j < end; j += (packet_size+1)) {
722 fw_data = (u8 *)(fw->data + j);
723 if ((end - j) > packet_size) {
724 data[0] = i;
725 dlen = packet_size;
726 } else {
727 data[0] = i | 0x80;
728 dlen = (u8)(end - j)-1;
729 }
730 data[1] = dlen;
731 memcpy(&data[2], fw_data, dlen+1);
732 wlen = (u8) dlen + 4;
733 data[wlen-1] = check_sum(fw_data, dlen+1);
734 deb_info(1, "Data S=%02x:E=%02x CS= %02x", data[3],
735 data[dlen+2], data[dlen+3]);
736 ret |= lme2510_bulk_write(dev, data, wlen, 1);
737 ret |= lme2510_bulk_read(dev, data, len_in , 1);
738 ret |= (data[0] == 0x88) ? 0 : -1;
739 }
740 }
741
742 usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
743 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000);
744
745
746 data[0] = 0x8a;
747 len_in = 1;
748 msleep(2000);
749 ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Resetting*/
750 ret |= lme2510_bulk_read(dev, data, len_in, 1);
751 msleep(400);
752
753 if (ret < 0)
754 info("FRM Firmware Download Failed (%04x)" , ret);
755 else
756 info("FRM Firmware Download Completed - Resetting Device");
757
758 kfree(data);
759 return (ret < 0) ? -ENODEV : 0;
760}
761
762static void lme_coldreset(struct usb_device *dev)
763{
764 int ret = 0, len_in;
765 u8 data[512] = {0};
766
767 data[0] = 0x0a;
768 len_in = 1;
769 info("FRM Firmware Cold Reset");
770 ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Cold Resetting*/
771 ret |= lme2510_bulk_read(dev, data, len_in, 1);
772
773 return;
774}
775
776static int lme_firmware_switch(struct usb_device *udev, int cold)
777{
778 const struct firmware *fw = NULL;
779 const char fw_c_s7395[] = "dvb-usb-lme2510c-s7395.fw";
780 const char fw_c_lg[] = "dvb-usb-lme2510c-lg.fw";
781 const char fw_c_s0194[] = "dvb-usb-lme2510c-s0194.fw";
782 const char fw_lg[] = "dvb-usb-lme2510-lg.fw";
783 const char fw_s0194[] = "dvb-usb-lme2510-s0194.fw";
784 const char *fw_lme;
785 int ret, cold_fw;
786
787 cold = (cold > 0) ? (cold & 1) : 0;
788
789 cold_fw = !cold;
790
791 if (le16_to_cpu(udev->descriptor.idProduct) == 0x1122) {
792 switch (dvb_usb_lme2510_firmware) {
793 default:
794 dvb_usb_lme2510_firmware = TUNER_S0194;
795 case TUNER_S0194:
796 fw_lme = fw_s0194;
797 ret = request_firmware(&fw, fw_lme, &udev->dev);
798 if (ret == 0) {
799 cold = 0;
800 break;
801 }
802 dvb_usb_lme2510_firmware = TUNER_LG;
803 case TUNER_LG:
804 fw_lme = fw_lg;
805 ret = request_firmware(&fw, fw_lme, &udev->dev);
806 if (ret == 0)
807 break;
808 info("FRM No Firmware Found - please install");
809 dvb_usb_lme2510_firmware = TUNER_DEFAULT;
810 cold = 0;
811 cold_fw = 0;
812 break;
813 }
814 } else {
815 switch (dvb_usb_lme2510_firmware) {
816 default:
817 dvb_usb_lme2510_firmware = TUNER_S7395;
818 case TUNER_S7395:
819 fw_lme = fw_c_s7395;
820 ret = request_firmware(&fw, fw_lme, &udev->dev);
821 if (ret == 0) {
822 cold = 0;
823 break;
824 }
825 dvb_usb_lme2510_firmware = TUNER_LG;
826 case TUNER_LG:
827 fw_lme = fw_c_lg;
828 ret = request_firmware(&fw, fw_lme, &udev->dev);
829 if (ret == 0)
830 break;
831 dvb_usb_lme2510_firmware = TUNER_S0194;
832 case TUNER_S0194:
833 fw_lme = fw_c_s0194;
834 ret = request_firmware(&fw, fw_lme, &udev->dev);
835 if (ret == 0)
836 break;
837 info("FRM No Firmware Found - please install");
838 dvb_usb_lme2510_firmware = TUNER_DEFAULT;
839 cold = 0;
840 cold_fw = 0;
841 break;
842 }
843 }
844
845 if (cold_fw) {
846 info("FRM Loading %s file", fw_lme);
847 ret = lme2510_download_firmware(udev, fw);
848 }
849
850 release_firmware(fw);
851
852 if (cold) {
853 info("FRM Changing to %s firmware", fw_lme);
854 lme_coldreset(udev);
855 return -ENODEV;
856 }
857
858 return ret;
859}
860
861static int lme2510_kill_urb(struct usb_data_stream *stream)
862{
863 int i;
864
865 for (i = 0; i < stream->urbs_submitted; i++) {
866 deb_info(3, "killing URB no. %d.", i);
867 /* stop the URB */
868 usb_kill_urb(stream->urb_list[i]);
869 }
870 stream->urbs_submitted = 0;
871
872 return 0;
873}
874
875static struct tda10086_config tda10086_config = {
876 .demod_address = 0x1c,
877 .invert = 0,
878 .diseqc_tone = 1,
879 .xtal_freq = TDA10086_XTAL_16M,
880};
881
882static struct stv0288_config lme_config = {
883 .demod_address = 0xd0,
884 .min_delay_ms = 15,
885 .inittab = s7395_inittab,
886};
887
888static struct ix2505v_config lme_tuner = {
889 .tuner_address = 0xc0,
890 .min_delay_ms = 100,
891 .tuner_gain = 0x0,
892 .tuner_chargepump = 0x3,
893};
894
895static struct stv0299_config sharp_z0194_config = {
896 .demod_address = 0xd0,
897 .inittab = sharp_z0194a_inittab,
898 .mclk = 88000000UL,
899 .invert = 0,
900 .skip_reinit = 0,
901 .lock_output = STV0299_LOCKOUTPUT_1,
902 .volt13_op0_op1 = STV0299_VOLT13_OP1,
903 .min_delay_ms = 100,
904 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
905};
906
907static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
908 fe_sec_voltage_t voltage)
909{
910 struct dvb_usb_adapter *adap = fe->dvb->priv;
911 static u8 voltage_low[] = LME_VOLTAGE_L;
912 static u8 voltage_high[] = LME_VOLTAGE_H;
913 static u8 rbuf[1];
914 int ret = 0, len = 3, rlen = 1;
915
916 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
917 return -EAGAIN;
918
919 switch (voltage) {
920 case SEC_VOLTAGE_18:
921 ret |= lme2510_usb_talk(adap->dev,
922 voltage_high, len, rbuf, rlen);
923 break;
924
925 case SEC_VOLTAGE_OFF:
926 case SEC_VOLTAGE_13:
927 default:
928 ret |= lme2510_usb_talk(adap->dev,
929 voltage_low, len, rbuf, rlen);
930 break;
931 }
932
933 mutex_unlock(&adap->dev->i2c_mutex);
934
935 return (ret < 0) ? -ENODEV : 0;
936}
937
938static int lme_name(struct dvb_usb_adapter *adap)
939{
940 struct lme2510_state *st = adap->dev->priv;
941 const char *desc = adap->dev->desc->name;
942 char *fe_name[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395",
943 " SHARP:BS2F7HZ0194"};
944 char *name = adap->fe->ops.info.name;
945
946 strlcpy(name, desc, 128);
947 strlcat(name, fe_name[st->tuner_config], 128);
948
949 return 0;
950}
951
952static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
953{
954 struct lme2510_state *st = adap->dev->priv;
955
956 int ret = 0;
957
958 st->i2c_talk_onoff = 1;
959
960 st->i2c_gate = 4;
961 adap->fe = dvb_attach(tda10086_attach, &tda10086_config,
962 &adap->dev->i2c_adap);
963
964 if (adap->fe) {
965 info("TUN Found Frontend TDA10086");
966 st->i2c_tuner_gate_w = 4;
967 st->i2c_tuner_gate_r = 4;
968 st->i2c_tuner_addr = 0xc0;
969 st->tuner_config = TUNER_LG;
970 if (dvb_usb_lme2510_firmware != TUNER_LG) {
971 dvb_usb_lme2510_firmware = TUNER_LG;
972 ret = lme_firmware_switch(adap->dev->udev, 1);
973 }
974 goto end;
975 }
976
977 st->i2c_gate = 4;
978 adap->fe = dvb_attach(stv0299_attach, &sharp_z0194_config,
979 &adap->dev->i2c_adap);
980 if (adap->fe) {
981 info("FE Found Stv0299");
982 st->i2c_tuner_gate_w = 4;
983 st->i2c_tuner_gate_r = 5;
984 st->i2c_tuner_addr = 0xc0;
985 st->tuner_config = TUNER_S0194;
986 if (dvb_usb_lme2510_firmware != TUNER_S0194) {
987 dvb_usb_lme2510_firmware = TUNER_S0194;
988 ret = lme_firmware_switch(adap->dev->udev, 1);
989 }
990 goto end;
991 }
992
993 st->i2c_gate = 5;
994 adap->fe = dvb_attach(stv0288_attach, &lme_config,
995 &adap->dev->i2c_adap);
996 if (adap->fe) {
997 info("FE Found Stv0288");
998 st->i2c_tuner_gate_w = 4;
999 st->i2c_tuner_gate_r = 5;
1000 st->i2c_tuner_addr = 0xc0;
1001 st->tuner_config = TUNER_S7395;
1002 if (dvb_usb_lme2510_firmware != TUNER_S7395) {
1003 dvb_usb_lme2510_firmware = TUNER_S7395;
1004 ret = lme_firmware_switch(adap->dev->udev, 1);
1005 }
1006 } else {
1007 info("DM04 Not Supported");
1008 return -ENODEV;
1009 }
1010
1011
1012end: if (ret) {
1013 if (adap->fe) {
1014 dvb_frontend_detach(adap->fe);
1015 adap->fe = NULL;
1016 }
1017 adap->dev->props.rc.core.rc_codes = NULL;
1018 return -ENODEV;
1019 }
1020
1021 adap->fe->ops.set_voltage = dm04_lme2510_set_voltage;
1022 ret = lme_name(adap);
1023 return ret;
1024}
1025
1026static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
1027{
1028 struct lme2510_state *st = adap->dev->priv;
1029 char *tun_msg[] = {"", "TDA8263", "IX2505V", "DVB_PLL_OPERA"};
1030 int ret = 0;
1031
1032 switch (st->tuner_config) {
1033 case TUNER_LG:
1034 if (dvb_attach(tda826x_attach, adap->fe, 0xc0,
1035 &adap->dev->i2c_adap, 1))
1036 ret = st->tuner_config;
1037 break;
1038 case TUNER_S7395:
1039 if (dvb_attach(ix2505v_attach , adap->fe, &lme_tuner,
1040 &adap->dev->i2c_adap))
1041 ret = st->tuner_config;
1042 break;
1043 case TUNER_S0194:
1044 if (dvb_attach(dvb_pll_attach , adap->fe, 0xc0,
1045 &adap->dev->i2c_adap, DVB_PLL_OPERA1))
1046 ret = st->tuner_config;
1047 break;
1048 default:
1049 break;
1050 }
1051
1052 if (ret)
1053 info("TUN Found %s tuner", tun_msg[ret]);
1054 else {
1055 info("TUN No tuner found --- reseting device");
1056 lme_coldreset(adap->dev->udev);
1057 return -ENODEV;
1058 }
1059
1060 /* Start the Interrupt*/
1061 ret = lme2510_int_read(adap);
1062 if (ret < 0) {
1063 info("INT Unable to start Interrupt Service");
1064 return -ENODEV;
1065 }
1066
1067 return ret;
1068}
1069
1070static int lme2510_powerup(struct dvb_usb_device *d, int onoff)
1071{
1072 struct lme2510_state *st = d->priv;
1073 static u8 lnb_on[] = LNB_ON;
1074 static u8 lnb_off[] = LNB_OFF;
1075 static u8 rbuf[1];
1076 int ret, len = 3, rlen = 1;
1077
1078 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
1079 return -EAGAIN;
1080
1081 if (onoff)
1082 ret = lme2510_usb_talk(d, lnb_on, len, rbuf, rlen);
1083 else
1084 ret = lme2510_usb_talk(d, lnb_off, len, rbuf, rlen);
1085
1086 st->i2c_talk_onoff = 1;
1087
1088 mutex_unlock(&d->i2c_mutex);
1089
1090 return ret;
1091}
1092
1093/* DVB USB Driver stuff */
1094static struct dvb_usb_device_properties lme2510_properties;
1095static struct dvb_usb_device_properties lme2510c_properties;
1096
1097static int lme2510_probe(struct usb_interface *intf,
1098 const struct usb_device_id *id)
1099{
1100 struct usb_device *udev = interface_to_usbdev(intf);
1101 int ret = 0;
1102
1103 usb_reset_configuration(udev);
1104
1105 usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 1);
1106
1107 if (udev->speed != USB_SPEED_HIGH) {
1108 ret = usb_reset_device(udev);
1109 info("DEV Failed to connect in HIGH SPEED mode");
1110 return -ENODEV;
1111 }
1112
1113 if (lme2510_return_status(udev) == 0x44) {
1114 lme_firmware_switch(udev, 0);
1115 return -ENODEV;
1116 }
1117
1118 if (0 == dvb_usb_device_init(intf, &lme2510_properties,
1119 THIS_MODULE, NULL, adapter_nr)) {
1120 info("DEV registering device driver");
1121 return 0;
1122 }
1123 if (0 == dvb_usb_device_init(intf, &lme2510c_properties,
1124 THIS_MODULE, NULL, adapter_nr)) {
1125 info("DEV registering device driver");
1126 return 0;
1127 }
1128
1129 info("DEV lme2510 Error");
1130 return -ENODEV;
1131
1132}
1133
1134static struct usb_device_id lme2510_table[] = {
1135 { USB_DEVICE(0x3344, 0x1122) }, /* LME2510 */
1136 { USB_DEVICE(0x3344, 0x1120) }, /* LME2510C */
1137 {} /* Terminating entry */
1138};
1139
1140MODULE_DEVICE_TABLE(usb, lme2510_table);
1141
1142static struct dvb_usb_device_properties lme2510_properties = {
1143 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1144 .size_of_priv = sizeof(struct lme2510_state),
1145 .num_adapters = 1,
1146 .adapter = {
1147 {
1148 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
1149 DVB_USB_ADAP_NEED_PID_FILTERING|
1150 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1151 .streaming_ctrl = lme2510_streaming_ctrl,
1152 .pid_filter_count = 15,
1153 .pid_filter = lme2510_pid_filter,
1154 .pid_filter_ctrl = lme2510_pid_filter_ctrl,
1155 .frontend_attach = dm04_lme2510_frontend_attach,
1156 .tuner_attach = dm04_lme2510_tuner,
1157 /* parameter for the MPEG2-data transfer */
1158 .stream = {
1159 .type = USB_BULK,
1160 .count = 10,
1161 .endpoint = 0x06,
1162 .u = {
1163 .bulk = {
1164 .buffersize = 4096,
1165
1166 }
1167 }
1168 }
1169 }
1170 },
1171 .rc.core = {
1172 .protocol = RC_TYPE_NEC,
1173 .module_name = "LME2510 Remote Control",
1174 .allowed_protos = RC_TYPE_NEC,
1175 .rc_codes = RC_MAP_LME2510,
1176 },
1177 .power_ctrl = lme2510_powerup,
1178 .identify_state = lme2510_identify_state,
1179 .i2c_algo = &lme2510_i2c_algo,
1180 .generic_bulk_ctrl_endpoint = 0,
1181 .num_device_descs = 1,
1182 .devices = {
1183 { "DM04_LME2510_DVB-S",
1184 { &lme2510_table[0], NULL },
1185 },
1186
1187 }
1188};
1189
1190static struct dvb_usb_device_properties lme2510c_properties = {
1191 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1192 .size_of_priv = sizeof(struct lme2510_state),
1193 .num_adapters = 1,
1194 .adapter = {
1195 {
1196 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
1197 DVB_USB_ADAP_NEED_PID_FILTERING|
1198 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1199 .streaming_ctrl = lme2510_streaming_ctrl,
1200 .pid_filter_count = 15,
1201 .pid_filter = lme2510_pid_filter,
1202 .pid_filter_ctrl = lme2510_pid_filter_ctrl,
1203 .frontend_attach = dm04_lme2510_frontend_attach,
1204 .tuner_attach = dm04_lme2510_tuner,
1205 /* parameter for the MPEG2-data transfer */
1206 .stream = {
1207 .type = USB_BULK,
1208 .count = 10,
1209 .endpoint = 0x8,
1210 .u = {
1211 .bulk = {
1212 .buffersize = 4096,
1213
1214 }
1215 }
1216 }
1217 }
1218 },
1219 .rc.core = {
1220 .protocol = RC_TYPE_NEC,
1221 .module_name = "LME2510 Remote Control",
1222 .allowed_protos = RC_TYPE_NEC,
1223 .rc_codes = RC_MAP_LME2510,
1224 },
1225 .power_ctrl = lme2510_powerup,
1226 .identify_state = lme2510_identify_state,
1227 .i2c_algo = &lme2510_i2c_algo,
1228 .generic_bulk_ctrl_endpoint = 0,
1229 .num_device_descs = 1,
1230 .devices = {
1231 { "DM04_LME2510C_DVB-S",
1232 { &lme2510_table[1], NULL },
1233 },
1234 }
1235};
1236
1237static void *lme2510_exit_int(struct dvb_usb_device *d)
1238{
1239 struct lme2510_state *st = d->priv;
1240 struct dvb_usb_adapter *adap = &d->adapter[0];
1241 void *buffer = NULL;
1242
1243 if (adap != NULL) {
1244 lme2510_kill_urb(&adap->stream);
1245 adap->feedcount = 0;
1246 }
1247
1248 if (st->usb_buffer != NULL) {
1249 st->i2c_talk_onoff = 1;
1250 st->signal_lock = 0;
1251 st->signal_level = 0;
1252 st->signal_sn = 0;
1253 buffer = st->usb_buffer;
1254 }
1255
1256 if (st->lme_urb != NULL) {
1257 usb_kill_urb(st->lme_urb);
1258 usb_free_coherent(d->udev, 5000, st->buffer,
1259 st->lme_urb->transfer_dma);
1260 info("Interrupt Service Stopped");
1261 }
1262
1263 return buffer;
1264}
1265
1266static void lme2510_exit(struct usb_interface *intf)
1267{
1268 struct dvb_usb_device *d = usb_get_intfdata(intf);
1269 void *usb_buffer;
1270
1271 if (d != NULL) {
1272 usb_buffer = lme2510_exit_int(d);
1273 dvb_usb_device_exit(intf);
1274 if (usb_buffer != NULL)
1275 kfree(usb_buffer);
1276 }
1277}
1278
1279static struct usb_driver lme2510_driver = {
1280 .name = "LME2510C_DVB-S",
1281 .probe = lme2510_probe,
1282 .disconnect = lme2510_exit,
1283 .id_table = lme2510_table,
1284};
1285
1286/* module stuff */
1287static int __init lme2510_module_init(void)
1288{
1289 int result = usb_register(&lme2510_driver);
1290 if (result) {
1291 err("usb_register failed. Error number %d", result);
1292 return result;
1293 }
1294
1295 return 0;
1296}
1297
1298static void __exit lme2510_module_exit(void)
1299{
1300 /* deregister this driver from the USB subsystem */
1301 usb_deregister(&lme2510_driver);
1302}
1303
1304module_init(lme2510_module_init);
1305module_exit(lme2510_module_exit);
1306
1307MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1308MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1309MODULE_VERSION("1.88");
1310MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/lmedm04.h b/drivers/media/dvb/dvb-usb/lmedm04.h
new file mode 100644
index 000000000000..ab21e2ef53fa
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/lmedm04.h
@@ -0,0 +1,174 @@
1/* DVB USB compliant linux driver for
2 *
3 * DM04/QQBOX DVB-S USB BOX LME2510C + SHARP:BS2F7HZ7395
4 * LME2510C + LG TDQY-P001F
5 * LME2510 + LG TDQY-P001F
6 *
7 * MVB7395 (LME2510C+SHARP:BS2F7HZ7395)
8 * SHARP:BS2F7HZ7395 = (STV0288+Sharp IX2505V)
9 *
10 * MVB001F (LME2510+LGTDQT-P001F)
11 * LG TDQY - P001F =(TDA8263 + TDA10086H)
12 *
13 * MVB0001F (LME2510C+LGTDQT-P001F)
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the Free
17 * Software Foundation, version 2.
18 * *
19 * see Documentation/dvb/README.dvb-usb for more information
20 */
21#ifndef _DVB_USB_LME2510_H_
22#define _DVB_USB_LME2510_H_
23
24/* Streamer & PID
25 *
26 * Note: These commands do not actually stop the streaming
27 * but form some kind of packet filtering/stream count
28 * or tuning related functions.
29 * 06 XX
30 * offset 1 = 00 Enable Streaming
31 *
32 *
33 * PID
34 * 03 XX XX ----> reg number ---> setting....20 XX
35 * offset 1 = length
36 * offset 2 = start of data
37 * end byte -1 = 20
38 * end byte = clear pid always a0, other wise 9c, 9a ??
39 *
40*/
41#define LME_ST_ON_W {0x06, 0x00}
42#define LME_CLEAR_PID {0x03, 0x02, 0x20, 0xa0}
43#define LME_ZERO_PID {0x03, 0x06, 0x00, 0x00, 0x01, 0x00, 0x20, 0x9c}
44
45/* LNB Voltage
46 * 07 XX XX
47 * offset 1 = 01
48 * offset 2 = 00=Voltage low 01=Voltage high
49 *
50 * LNB Power
51 * 03 01 XX
52 * offset 2 = 00=ON 01=OFF
53 */
54
55#define LME_VOLTAGE_L {0x07, 0x01, 0x00}
56#define LME_VOLTAGE_H {0x07, 0x01, 0x01}
57#define LNB_ON {0x3a, 0x01, 0x00}
58#define LNB_OFF {0x3a, 0x01, 0x01}
59
60/* Initial stv0288 settings for 7395 Frontend */
61static u8 s7395_inittab[] = {
62 0x01, 0x15,
63 0x02, 0x20,
64 0x03, 0xa0,
65 0x04, 0xa0,
66 0x05, 0x12,
67 0x06, 0x00,
68 0x09, 0x00,
69 0x0a, 0x04,
70 0x0b, 0x00,
71 0x0c, 0x00,
72 0x0d, 0x00,
73 0x0e, 0xc1,
74 0x0f, 0x54,
75 0x11, 0x7a,
76 0x12, 0x03,
77 0x13, 0x48,
78 0x14, 0x84,
79 0x15, 0xc5,
80 0x16, 0xb8,
81 0x17, 0x9c,
82 0x18, 0x00,
83 0x19, 0xa6,
84 0x1a, 0x88,
85 0x1b, 0x8f,
86 0x1c, 0xf0,
87 0x20, 0x0b,
88 0x21, 0x54,
89 0x22, 0xff,
90 0x23, 0x01,
91 0x28, 0x46,
92 0x29, 0x66,
93 0x2a, 0x90,
94 0x2b, 0xfa,
95 0x2c, 0xd9,
96 0x30, 0x0,
97 0x31, 0x1e,
98 0x32, 0x14,
99 0x33, 0x0f,
100 0x34, 0x09,
101 0x35, 0x0c,
102 0x36, 0x05,
103 0x37, 0x2f,
104 0x38, 0x16,
105 0x39, 0xbd,
106 0x3a, 0x0,
107 0x3b, 0x13,
108 0x3c, 0x11,
109 0x3d, 0x30,
110 0x40, 0x63,
111 0x41, 0x04,
112 0x42, 0x20,
113 0x43, 0x00,
114 0x44, 0x00,
115 0x45, 0x00,
116 0x46, 0x00,
117 0x47, 0x00,
118 0x4a, 0x00,
119 0x50, 0x10,
120 0x51, 0x36,
121 0x52, 0x21,
122 0x53, 0x94,
123 0x54, 0xb2,
124 0x55, 0x29,
125 0x56, 0x64,
126 0x57, 0x2b,
127 0x58, 0x54,
128 0x59, 0x86,
129 0x5a, 0x00,
130 0x5b, 0x9b,
131 0x5c, 0x08,
132 0x5d, 0x7f,
133 0x5e, 0xff,
134 0x5f, 0x8d,
135 0x70, 0x0,
136 0x71, 0x0,
137 0x72, 0x0,
138 0x74, 0x0,
139 0x75, 0x0,
140 0x76, 0x0,
141 0x81, 0x0,
142 0x82, 0x3f,
143 0x83, 0x3f,
144 0x84, 0x0,
145 0x85, 0x0,
146 0x88, 0x0,
147 0x89, 0x0,
148 0x8a, 0x0,
149 0x8b, 0x0,
150 0x8c, 0x0,
151 0x90, 0x0,
152 0x91, 0x0,
153 0x92, 0x0,
154 0x93, 0x0,
155 0x94, 0x1c,
156 0x97, 0x0,
157 0xa0, 0x48,
158 0xa1, 0x0,
159 0xb0, 0xb8,
160 0xb1, 0x3a,
161 0xb2, 0x10,
162 0xb3, 0x82,
163 0xb4, 0x80,
164 0xb5, 0x82,
165 0xb6, 0x82,
166 0xb7, 0x82,
167 0xb8, 0x20,
168 0xb9, 0x0,
169 0xf0, 0x0,
170 0xf1, 0x0,
171 0xf2, 0xc0,
172 0xff, 0xff,
173};
174#endif
diff --git a/drivers/media/dvb/dvb-usb/m920x.c b/drivers/media/dvb/dvb-usb/m920x.c
index bdef1a18b664..9456792f219b 100644
--- a/drivers/media/dvb/dvb-usb/m920x.c
+++ b/drivers/media/dvb/dvb-usb/m920x.c
@@ -134,22 +134,26 @@ static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
134{ 134{
135 struct m920x_state *m = d->priv; 135 struct m920x_state *m = d->priv;
136 int i, ret = 0; 136 int i, ret = 0;
137 u8 rc_state[2]; 137 u8 *rc_state;
138
139 rc_state = kmalloc(2, GFP_KERNEL);
140 if (!rc_state)
141 return -ENOMEM;
138 142
139 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0) 143 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0)
140 goto unlock; 144 goto out;
141 145
142 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0) 146 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0)
143 goto unlock; 147 goto out;
144 148
145 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 149 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
146 if (rc5_data(&d->props.rc.legacy.rc_key_map[i]) == rc_state[1]) { 150 if (rc5_data(&d->props.rc.legacy.rc_map_table[i]) == rc_state[1]) {
147 *event = d->props.rc.legacy.rc_key_map[i].keycode; 151 *event = d->props.rc.legacy.rc_map_table[i].keycode;
148 152
149 switch(rc_state[0]) { 153 switch(rc_state[0]) {
150 case 0x80: 154 case 0x80:
151 *state = REMOTE_NO_KEY_PRESSED; 155 *state = REMOTE_NO_KEY_PRESSED;
152 goto unlock; 156 goto out;
153 157
154 case 0x88: /* framing error or "invalid code" */ 158 case 0x88: /* framing error or "invalid code" */
155 case 0x99: 159 case 0x99:
@@ -157,7 +161,7 @@ static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
157 case 0xd8: 161 case 0xd8:
158 *state = REMOTE_NO_KEY_PRESSED; 162 *state = REMOTE_NO_KEY_PRESSED;
159 m->rep_count = 0; 163 m->rep_count = 0;
160 goto unlock; 164 goto out;
161 165
162 case 0x93: 166 case 0x93:
163 case 0x92: 167 case 0x92:
@@ -165,7 +169,7 @@ static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
165 case 0x82: 169 case 0x82:
166 m->rep_count = 0; 170 m->rep_count = 0;
167 *state = REMOTE_KEY_PRESSED; 171 *state = REMOTE_KEY_PRESSED;
168 goto unlock; 172 goto out;
169 173
170 case 0x91: 174 case 0x91:
171 case 0x81: /* pinnacle PCTV310e */ 175 case 0x81: /* pinnacle PCTV310e */
@@ -174,12 +178,12 @@ static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
174 *state = REMOTE_KEY_REPEAT; 178 *state = REMOTE_KEY_REPEAT;
175 else 179 else
176 *state = REMOTE_NO_KEY_PRESSED; 180 *state = REMOTE_NO_KEY_PRESSED;
177 goto unlock; 181 goto out;
178 182
179 default: 183 default:
180 deb("Unexpected rc state %02x\n", rc_state[0]); 184 deb("Unexpected rc state %02x\n", rc_state[0]);
181 *state = REMOTE_NO_KEY_PRESSED; 185 *state = REMOTE_NO_KEY_PRESSED;
182 goto unlock; 186 goto out;
183 } 187 }
184 } 188 }
185 189
@@ -188,8 +192,8 @@ static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
188 192
189 *state = REMOTE_NO_KEY_PRESSED; 193 *state = REMOTE_NO_KEY_PRESSED;
190 194
191 unlock: 195 out:
192 196 kfree(rc_state);
193 return ret; 197 return ret;
194} 198}
195 199
@@ -339,13 +343,19 @@ static int m920x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, in
339static int m920x_firmware_download(struct usb_device *udev, const struct firmware *fw) 343static int m920x_firmware_download(struct usb_device *udev, const struct firmware *fw)
340{ 344{
341 u16 value, index, size; 345 u16 value, index, size;
342 u8 read[4], *buff; 346 u8 *read, *buff;
343 int i, pass, ret = 0; 347 int i, pass, ret = 0;
344 348
345 buff = kmalloc(65536, GFP_KERNEL); 349 buff = kmalloc(65536, GFP_KERNEL);
346 if (buff == NULL) 350 if (buff == NULL)
347 return -ENOMEM; 351 return -ENOMEM;
348 352
353 read = kmalloc(4, GFP_KERNEL);
354 if (!read) {
355 kfree(buff);
356 return -ENOMEM;
357 }
358
349 if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0) 359 if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
350 goto done; 360 goto done;
351 deb("%x %x %x %x\n", read[0], read[1], read[2], read[3]); 361 deb("%x %x %x %x\n", read[0], read[1], read[2], read[3]);
@@ -396,6 +406,7 @@ static int m920x_firmware_download(struct usb_device *udev, const struct firmwar
396 deb("firmware uploaded!\n"); 406 deb("firmware uploaded!\n");
397 407
398 done: 408 done:
409 kfree(read);
399 kfree(buff); 410 kfree(buff);
400 411
401 return ret; 412 return ret;
@@ -589,7 +600,7 @@ static struct m920x_inits pinnacle310e_init[] = {
589}; 600};
590 601
591/* ir keymaps */ 602/* ir keymaps */
592static struct ir_scancode ir_codes_megasky_table[] = { 603static struct rc_map_table rc_map_megasky_table[] = {
593 { 0x0012, KEY_POWER }, 604 { 0x0012, KEY_POWER },
594 { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */ 605 { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */
595 { 0x0002, KEY_CHANNELUP }, 606 { 0x0002, KEY_CHANNELUP },
@@ -608,7 +619,7 @@ static struct ir_scancode ir_codes_megasky_table[] = {
608 { 0x000e, KEY_COFFEE }, /* "MTS" */ 619 { 0x000e, KEY_COFFEE }, /* "MTS" */
609}; 620};
610 621
611static struct ir_scancode ir_codes_tvwalkertwin_table[] = { 622static struct rc_map_table rc_map_tvwalkertwin_table[] = {
612 { 0x0001, KEY_ZOOM }, /* Full Screen */ 623 { 0x0001, KEY_ZOOM }, /* Full Screen */
613 { 0x0002, KEY_CAMERA }, /* snapshot */ 624 { 0x0002, KEY_CAMERA }, /* snapshot */
614 { 0x0003, KEY_MUTE }, 625 { 0x0003, KEY_MUTE },
@@ -628,13 +639,13 @@ static struct ir_scancode ir_codes_tvwalkertwin_table[] = {
628 { 0x001e, KEY_VOLUMEUP }, 639 { 0x001e, KEY_VOLUMEUP },
629}; 640};
630 641
631static struct ir_scancode ir_codes_pinnacle310e_table[] = { 642static struct rc_map_table rc_map_pinnacle310e_table[] = {
632 { 0x16, KEY_POWER }, 643 { 0x16, KEY_POWER },
633 { 0x17, KEY_FAVORITES }, 644 { 0x17, KEY_FAVORITES },
634 { 0x0f, KEY_TEXT }, 645 { 0x0f, KEY_TEXT },
635 { 0x48, KEY_MEDIA }, /* preview */ 646 { 0x48, KEY_PROGRAM }, /* preview */
636 { 0x1c, KEY_EPG }, 647 { 0x1c, KEY_EPG },
637 { 0x04, KEY_LIST }, /* record list */ 648 { 0x04, KEY_LIST }, /* record list */
638 { 0x03, KEY_1 }, 649 { 0x03, KEY_1 },
639 { 0x01, KEY_2 }, 650 { 0x01, KEY_2 },
640 { 0x06, KEY_3 }, 651 { 0x06, KEY_3 },
@@ -674,14 +685,14 @@ static struct ir_scancode ir_codes_pinnacle310e_table[] = {
674 { 0x0e, KEY_MUTE }, 685 { 0x0e, KEY_MUTE },
675/* { 0x49, KEY_LR }, */ /* L/R */ 686/* { 0x49, KEY_LR }, */ /* L/R */
676 { 0x07, KEY_SLEEP }, /* Hibernate */ 687 { 0x07, KEY_SLEEP }, /* Hibernate */
677 { 0x08, KEY_MEDIA }, /* A/V */ 688 { 0x08, KEY_VIDEO }, /* A/V */
678 { 0x0e, KEY_MENU }, /* Recall */ 689 { 0x0e, KEY_MENU }, /* Recall */
679 { 0x45, KEY_ZOOMIN }, 690 { 0x45, KEY_ZOOMIN },
680 { 0x46, KEY_ZOOMOUT }, 691 { 0x46, KEY_ZOOMOUT },
681 { 0x18, KEY_TV }, /* Red */ 692 { 0x18, KEY_RED }, /* Red */
682 { 0x53, KEY_VCR }, /* Green */ 693 { 0x53, KEY_GREEN }, /* Green */
683 { 0x5e, KEY_SAT }, /* Yellow */ 694 { 0x5e, KEY_YELLOW }, /* Yellow */
684 { 0x5f, KEY_PLAYER }, /* Blue */ 695 { 0x5f, KEY_BLUE }, /* Blue */
685}; 696};
686 697
687/* DVB USB Driver stuff */ 698/* DVB USB Driver stuff */
@@ -786,8 +797,8 @@ static struct dvb_usb_device_properties megasky_properties = {
786 797
787 .rc.legacy = { 798 .rc.legacy = {
788 .rc_interval = 100, 799 .rc_interval = 100,
789 .rc_key_map = ir_codes_megasky_table, 800 .rc_map_table = rc_map_megasky_table,
790 .rc_key_map_size = ARRAY_SIZE(ir_codes_megasky_table), 801 .rc_map_size = ARRAY_SIZE(rc_map_megasky_table),
791 .rc_query = m920x_rc_query, 802 .rc_query = m920x_rc_query,
792 }, 803 },
793 804
@@ -889,8 +900,8 @@ static struct dvb_usb_device_properties tvwalkertwin_properties = {
889 900
890 .rc.legacy = { 901 .rc.legacy = {
891 .rc_interval = 100, 902 .rc_interval = 100,
892 .rc_key_map = ir_codes_tvwalkertwin_table, 903 .rc_map_table = rc_map_tvwalkertwin_table,
893 .rc_key_map_size = ARRAY_SIZE(ir_codes_tvwalkertwin_table), 904 .rc_map_size = ARRAY_SIZE(rc_map_tvwalkertwin_table),
894 .rc_query = m920x_rc_query, 905 .rc_query = m920x_rc_query,
895 }, 906 },
896 907
@@ -998,8 +1009,8 @@ static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
998 1009
999 .rc.legacy = { 1010 .rc.legacy = {
1000 .rc_interval = 100, 1011 .rc_interval = 100,
1001 .rc_key_map = ir_codes_pinnacle310e_table, 1012 .rc_map_table = rc_map_pinnacle310e_table,
1002 .rc_key_map_size = ARRAY_SIZE(ir_codes_pinnacle310e_table), 1013 .rc_map_size = ARRAY_SIZE(rc_map_pinnacle310e_table),
1003 .rc_query = m920x_rc_query, 1014 .rc_query = m920x_rc_query,
1004 }, 1015 },
1005 1016
diff --git a/drivers/media/dvb/dvb-usb/nova-t-usb2.c b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
index 181f36a12e2a..bc350e982b72 100644
--- a/drivers/media/dvb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
@@ -21,7 +21,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
21#define deb_ee(args...) dprintk(debug,0x02,args) 21#define deb_ee(args...) dprintk(debug,0x02,args)
22 22
23/* Hauppauge NOVA-T USB2 keys */ 23/* Hauppauge NOVA-T USB2 keys */
24static struct ir_scancode ir_codes_haupp_table[] = { 24static struct rc_map_table rc_map_haupp_table[] = {
25 { 0x1e00, KEY_0 }, 25 { 0x1e00, KEY_0 },
26 { 0x1e01, KEY_1 }, 26 { 0x1e01, KEY_1 },
27 { 0x1e02, KEY_2 }, 27 { 0x1e02, KEY_2 },
@@ -47,7 +47,7 @@ static struct ir_scancode ir_codes_haupp_table[] = {
47 { 0x1e17, KEY_RIGHT }, 47 { 0x1e17, KEY_RIGHT },
48 { 0x1e18, KEY_VIDEO }, 48 { 0x1e18, KEY_VIDEO },
49 { 0x1e19, KEY_AUDIO }, 49 { 0x1e19, KEY_AUDIO },
50 { 0x1e1a, KEY_MEDIA }, 50 { 0x1e1a, KEY_IMAGES },
51 { 0x1e1b, KEY_EPG }, 51 { 0x1e1b, KEY_EPG },
52 { 0x1e1c, KEY_TV }, 52 { 0x1e1c, KEY_TV },
53 { 0x1e1e, KEY_NEXT }, 53 { 0x1e1e, KEY_NEXT },
@@ -91,14 +91,14 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
91 91
92 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle); 92 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle);
93 93
94 for (i = 0; i < ARRAY_SIZE(ir_codes_haupp_table); i++) { 94 for (i = 0; i < ARRAY_SIZE(rc_map_haupp_table); i++) {
95 if (rc5_data(&ir_codes_haupp_table[i]) == data && 95 if (rc5_data(&rc_map_haupp_table[i]) == data &&
96 rc5_custom(&ir_codes_haupp_table[i]) == custom) { 96 rc5_custom(&rc_map_haupp_table[i]) == custom) {
97 97
98 deb_rc("c: %x, d: %x\n", rc5_data(&ir_codes_haupp_table[i]), 98 deb_rc("c: %x, d: %x\n", rc5_data(&rc_map_haupp_table[i]),
99 rc5_custom(&ir_codes_haupp_table[i])); 99 rc5_custom(&rc_map_haupp_table[i]));
100 100
101 *event = ir_codes_haupp_table[i].keycode; 101 *event = rc_map_haupp_table[i].keycode;
102 *state = REMOTE_KEY_PRESSED; 102 *state = REMOTE_KEY_PRESSED;
103 if (st->old_toggle == toggle) { 103 if (st->old_toggle == toggle) {
104 if (st->last_repeat_count++ < 2) 104 if (st->last_repeat_count++ < 2)
@@ -197,8 +197,8 @@ static struct dvb_usb_device_properties nova_t_properties = {
197 197
198 .rc.legacy = { 198 .rc.legacy = {
199 .rc_interval = 100, 199 .rc_interval = 100,
200 .rc_key_map = ir_codes_haupp_table, 200 .rc_map_table = rc_map_haupp_table,
201 .rc_key_map_size = ARRAY_SIZE(ir_codes_haupp_table), 201 .rc_map_size = ARRAY_SIZE(rc_map_haupp_table),
202 .rc_query = nova_t_rc_query, 202 .rc_query = nova_t_rc_query,
203 }, 203 },
204 204
diff --git a/drivers/media/dvb/dvb-usb/opera1.c b/drivers/media/dvb/dvb-usb/opera1.c
index f896337b4535..2e4fab7215f5 100644
--- a/drivers/media/dvb/dvb-usb/opera1.c
+++ b/drivers/media/dvb/dvb-usb/opera1.c
@@ -35,7 +35,7 @@
35struct opera1_state { 35struct opera1_state {
36 u32 last_key_pressed; 36 u32 last_key_pressed;
37}; 37};
38struct ir_codes_opera_table { 38struct rc_map_opera_table {
39 u32 keycode; 39 u32 keycode;
40 u32 event; 40 u32 event;
41}; 41};
@@ -53,27 +53,36 @@ static int opera1_xilinx_rw(struct usb_device *dev, u8 request, u16 value,
53 u8 * data, u16 len, int flags) 53 u8 * data, u16 len, int flags)
54{ 54{
55 int ret; 55 int ret;
56 u8 r; 56 u8 tmp;
57 u8 u8buf[len]; 57 u8 *buf;
58
59 unsigned int pipe = (flags == OPERA_READ_MSG) ? 58 unsigned int pipe = (flags == OPERA_READ_MSG) ?
60 usb_rcvctrlpipe(dev,0) : usb_sndctrlpipe(dev, 0); 59 usb_rcvctrlpipe(dev,0) : usb_sndctrlpipe(dev, 0);
61 u8 request_type = (flags == OPERA_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT; 60 u8 request_type = (flags == OPERA_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
62 61
62 buf = kmalloc(len, GFP_KERNEL);
63 if (!buf)
64 return -ENOMEM;
65
63 if (flags == OPERA_WRITE_MSG) 66 if (flags == OPERA_WRITE_MSG)
64 memcpy(u8buf, data, len); 67 memcpy(buf, data, len);
65 ret = 68 ret = usb_control_msg(dev, pipe, request,
66 usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR, 69 request_type | USB_TYPE_VENDOR, value, 0x0,
67 value, 0x0, u8buf, len, 2000); 70 buf, len, 2000);
68 71
69 if (request == OPERA_TUNER_REQ) { 72 if (request == OPERA_TUNER_REQ) {
73 tmp = buf[0];
70 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 74 if (usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
71 OPERA_TUNER_REQ, USB_DIR_IN | USB_TYPE_VENDOR, 75 OPERA_TUNER_REQ, USB_DIR_IN | USB_TYPE_VENDOR,
72 0x01, 0x0, &r, 1, 2000)<1 || r!=0x08) 76 0x01, 0x0, buf, 1, 2000) < 1 || buf[0] != 0x08) {
73 return 0; 77 ret = 0;
78 goto out;
79 }
80 buf[0] = tmp;
74 } 81 }
75 if (flags == OPERA_READ_MSG) 82 if (flags == OPERA_READ_MSG)
76 memcpy(data, u8buf, len); 83 memcpy(data, buf, len);
84out:
85 kfree(buf);
77 return ret; 86 return ret;
78} 87}
79 88
@@ -189,7 +198,7 @@ static int opera1_stv0299_set_symbol_rate(struct dvb_frontend *fe, u32 srate,
189static u8 opera1_inittab[] = { 198static u8 opera1_inittab[] = {
190 0x00, 0xa1, 199 0x00, 0xa1,
191 0x01, 0x15, 200 0x01, 0x15,
192 0x02, 0x00, 201 0x02, 0x30,
193 0x03, 0x00, 202 0x03, 0x00,
194 0x04, 0x7d, 203 0x04, 0x7d,
195 0x05, 0x05, 204 0x05, 0x05,
@@ -331,7 +340,7 @@ static int opera1_pid_filter_control(struct dvb_usb_adapter *adap, int onoff)
331 return 0; 340 return 0;
332} 341}
333 342
334static struct ir_scancode ir_codes_opera1_table[] = { 343static struct rc_map_table rc_map_opera1_table[] = {
335 {0x5fa0, KEY_1}, 344 {0x5fa0, KEY_1},
336 {0x51af, KEY_2}, 345 {0x51af, KEY_2},
337 {0x5da2, KEY_3}, 346 {0x5da2, KEY_3},
@@ -342,23 +351,22 @@ static struct ir_scancode ir_codes_opera1_table[] = {
342 {0x49b6, KEY_8}, 351 {0x49b6, KEY_8},
343 {0x05fa, KEY_9}, 352 {0x05fa, KEY_9},
344 {0x45ba, KEY_0}, 353 {0x45ba, KEY_0},
345 {0x09f6, KEY_UP}, /*chanup */ 354 {0x09f6, KEY_CHANNELUP}, /*chanup */
346 {0x1be5, KEY_DOWN}, /*chandown */ 355 {0x1be5, KEY_CHANNELDOWN}, /*chandown */
347 {0x5da3, KEY_LEFT}, /*voldown */ 356 {0x5da3, KEY_VOLUMEDOWN}, /*voldown */
348 {0x5fa1, KEY_RIGHT}, /*volup */ 357 {0x5fa1, KEY_VOLUMEUP}, /*volup */
349 {0x07f8, KEY_SPACE}, /*tab */ 358 {0x07f8, KEY_SPACE}, /*tab */
350 {0x1fe1, KEY_ENTER}, /*play ok */ 359 {0x1fe1, KEY_OK}, /*play ok */
351 {0x1be4, KEY_Z}, /*zoom */ 360 {0x1be4, KEY_ZOOM}, /*zoom */
352 {0x59a6, KEY_M}, /*mute */ 361 {0x59a6, KEY_MUTE}, /*mute */
353 {0x5ba5, KEY_F}, /*tv/f */ 362 {0x5ba5, KEY_RADIO}, /*tv/f */
354 {0x19e7, KEY_R}, /*rec */ 363 {0x19e7, KEY_RECORD}, /*rec */
355 {0x01fe, KEY_S}, /*Stop */ 364 {0x01fe, KEY_STOP}, /*Stop */
356 {0x03fd, KEY_P}, /*pause */ 365 {0x03fd, KEY_PAUSE}, /*pause */
357 {0x03fc, KEY_W}, /*<- -> */ 366 {0x03fc, KEY_SCREEN}, /*<- -> */
358 {0x07f9, KEY_C}, /*capture */ 367 {0x07f9, KEY_CAMERA}, /*capture */
359 {0x47b9, KEY_Q}, /*exit */ 368 {0x47b9, KEY_ESC}, /*exit */
360 {0x43bc, KEY_O}, /*power */ 369 {0x43bc, KEY_POWER2}, /*power */
361
362}; 370};
363 371
364static int opera1_rc_query(struct dvb_usb_device *dev, u32 * event, int *state) 372static int opera1_rc_query(struct dvb_usb_device *dev, u32 * event, int *state)
@@ -404,12 +412,12 @@ static int opera1_rc_query(struct dvb_usb_device *dev, u32 * event, int *state)
404 412
405 send_key = (send_key & 0xffff) | 0x0100; 413 send_key = (send_key & 0xffff) | 0x0100;
406 414
407 for (i = 0; i < ARRAY_SIZE(ir_codes_opera1_table); i++) { 415 for (i = 0; i < ARRAY_SIZE(rc_map_opera1_table); i++) {
408 if (rc5_scan(&ir_codes_opera1_table[i]) == (send_key & 0xffff)) { 416 if (rc5_scan(&rc_map_opera1_table[i]) == (send_key & 0xffff)) {
409 *state = REMOTE_KEY_PRESSED; 417 *state = REMOTE_KEY_PRESSED;
410 *event = ir_codes_opera1_table[i].keycode; 418 *event = rc_map_opera1_table[i].keycode;
411 opst->last_key_pressed = 419 opst->last_key_pressed =
412 ir_codes_opera1_table[i].keycode; 420 rc_map_opera1_table[i].keycode;
413 break; 421 break;
414 } 422 }
415 opst->last_key_pressed = 0; 423 opst->last_key_pressed = 0;
@@ -497,8 +505,8 @@ static struct dvb_usb_device_properties opera1_properties = {
497 .i2c_algo = &opera1_i2c_algo, 505 .i2c_algo = &opera1_i2c_algo,
498 506
499 .rc.legacy = { 507 .rc.legacy = {
500 .rc_key_map = ir_codes_opera1_table, 508 .rc_map_table = rc_map_opera1_table,
501 .rc_key_map_size = ARRAY_SIZE(ir_codes_opera1_table), 509 .rc_map_size = ARRAY_SIZE(rc_map_opera1_table),
502 .rc_interval = 200, 510 .rc_interval = 200,
503 .rc_query = opera1_rc_query, 511 .rc_query = opera1_rc_query,
504 }, 512 },
diff --git a/drivers/media/dvb/dvb-usb/technisat-usb2.c b/drivers/media/dvb/dvb-usb/technisat-usb2.c
new file mode 100644
index 000000000000..08f8842ad280
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/technisat-usb2.c
@@ -0,0 +1,807 @@
1/*
2 * Linux driver for Technisat DVB-S/S2 USB 2.0 device
3 *
4 * Copyright (C) 2010 Patrick Boettcher,
5 * Kernel Labs Inc. PO Box 745, St James, NY 11780
6 *
7 * Development was sponsored by Technisat Digital UK Limited, whose
8 * registered office is Witan Gate House 500 - 600 Witan Gate West,
9 * Milton Keynes, MK9 1SH
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or (at your option) any later version.
15 *
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * THIS PROGRAM IS PROVIDED "AS IS" AND BOTH THE COPYRIGHT HOLDER AND
22 * TECHNISAT DIGITAL UK LTD DISCLAIM ALL WARRANTIES WITH REGARD TO
23 * THIS PROGRAM INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY OR
24 * FITNESS FOR A PARTICULAR PURPOSE. NEITHER THE COPYRIGHT HOLDER
25 * NOR TECHNISAT DIGITAL UK LIMITED SHALL BE LIABLE FOR ANY SPECIAL,
26 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
27 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
28 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
29 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS PROGRAM. See the
30 * GNU General Public License for more details.
31 */
32
33#define DVB_USB_LOG_PREFIX "technisat-usb2"
34#include "dvb-usb.h"
35
36#include "stv6110x.h"
37#include "stv090x.h"
38
39/* module parameters */
40DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
41
42static int debug;
43module_param(debug, int, 0644);
44MODULE_PARM_DESC(debug,
45 "set debugging level (bit-mask: 1=info,2=eeprom,4=i2c,8=rc)." \
46 DVB_USB_DEBUG_STATUS);
47
48/* disables all LED control command and
49 * also does not start the signal polling thread */
50static int disable_led_control;
51module_param(disable_led_control, int, 0444);
52MODULE_PARM_DESC(disable_led_control,
53 "disable LED control of the device "
54 "(default: 0 - LED control is active).");
55
56/* device private data */
57struct technisat_usb2_state {
58 struct dvb_usb_device *dev;
59 struct delayed_work green_led_work;
60 u8 power_state;
61
62 u16 last_scan_code;
63};
64
65/* debug print helpers */
66#define deb_info(args...) dprintk(debug, 0x01, args)
67#define deb_eeprom(args...) dprintk(debug, 0x02, args)
68#define deb_i2c(args...) dprintk(debug, 0x04, args)
69#define deb_rc(args...) dprintk(debug, 0x08, args)
70
71/* vendor requests */
72#define SET_IFCLK_TO_EXTERNAL_TSCLK_VENDOR_REQUEST 0xB3
73#define SET_FRONT_END_RESET_VENDOR_REQUEST 0xB4
74#define GET_VERSION_INFO_VENDOR_REQUEST 0xB5
75#define SET_GREEN_LED_VENDOR_REQUEST 0xB6
76#define SET_RED_LED_VENDOR_REQUEST 0xB7
77#define GET_IR_DATA_VENDOR_REQUEST 0xB8
78#define SET_LED_TIMER_DIVIDER_VENDOR_REQUEST 0xB9
79#define SET_USB_REENUMERATION 0xBA
80
81/* i2c-access methods */
82#define I2C_SPEED_100KHZ_BIT 0x40
83
84#define I2C_STATUS_NAK 7
85#define I2C_STATUS_OK 8
86
87static int technisat_usb2_i2c_access(struct usb_device *udev,
88 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
89{
90 u8 b[64];
91 int ret, actual_length;
92
93 deb_i2c("i2c-access: %02x, tx: ", device_addr);
94 debug_dump(tx, txlen, deb_i2c);
95 deb_i2c(" ");
96
97 if (txlen > 62) {
98 err("i2c TX buffer can't exceed 62 bytes (dev 0x%02x)",
99 device_addr);
100 txlen = 62;
101 }
102 if (rxlen > 62) {
103 err("i2c RX buffer can't exceed 62 bytes (dev 0x%02x)",
104 device_addr);
105 txlen = 62;
106 }
107
108 b[0] = I2C_SPEED_100KHZ_BIT;
109 b[1] = device_addr << 1;
110
111 if (rx != NULL) {
112 b[0] |= rxlen;
113 b[1] |= 1;
114 }
115
116 memcpy(&b[2], tx, txlen);
117 ret = usb_bulk_msg(udev,
118 usb_sndbulkpipe(udev, 0x01),
119 b, 2 + txlen,
120 NULL, 1000);
121
122 if (ret < 0) {
123 err("i2c-error: out failed %02x = %d", device_addr, ret);
124 return -ENODEV;
125 }
126
127 ret = usb_bulk_msg(udev,
128 usb_rcvbulkpipe(udev, 0x01),
129 b, 64, &actual_length, 1000);
130 if (ret < 0) {
131 err("i2c-error: in failed %02x = %d", device_addr, ret);
132 return -ENODEV;
133 }
134
135 if (b[0] != I2C_STATUS_OK) {
136 err("i2c-error: %02x = %d", device_addr, b[0]);
137 /* handle tuner-i2c-nak */
138 if (!(b[0] == I2C_STATUS_NAK &&
139 device_addr == 0x60
140 /* && device_is_technisat_usb2 */))
141 return -ENODEV;
142 }
143
144 deb_i2c("status: %d, ", b[0]);
145
146 if (rx != NULL) {
147 memcpy(rx, &b[2], rxlen);
148
149 deb_i2c("rx (%d): ", rxlen);
150 debug_dump(rx, rxlen, deb_i2c);
151 }
152
153 deb_i2c("\n");
154
155 return 0;
156}
157
158static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
159 int num)
160{
161 int ret = 0, i;
162 struct dvb_usb_device *d = i2c_get_adapdata(adap);
163
164 /* Ensure nobody else hits the i2c bus while we're sending our
165 sequence of messages, (such as the remote control thread) */
166 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
167 return -EAGAIN;
168
169 for (i = 0; i < num; i++) {
170 if (i+1 < num && msg[i+1].flags & I2C_M_RD) {
171 ret = technisat_usb2_i2c_access(d->udev, msg[i+1].addr,
172 msg[i].buf, msg[i].len,
173 msg[i+1].buf, msg[i+1].len);
174 if (ret != 0)
175 break;
176 i++;
177 } else {
178 ret = technisat_usb2_i2c_access(d->udev, msg[i].addr,
179 msg[i].buf, msg[i].len,
180 NULL, 0);
181 if (ret != 0)
182 break;
183 }
184 }
185
186 if (ret == 0)
187 ret = i;
188
189 mutex_unlock(&d->i2c_mutex);
190
191 return ret;
192}
193
194static u32 technisat_usb2_i2c_func(struct i2c_adapter *adapter)
195{
196 return I2C_FUNC_I2C;
197}
198
199static struct i2c_algorithm technisat_usb2_i2c_algo = {
200 .master_xfer = technisat_usb2_i2c_xfer,
201 .functionality = technisat_usb2_i2c_func,
202};
203
204#if 0
205static void technisat_usb2_frontend_reset(struct usb_device *udev)
206{
207 usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
208 SET_FRONT_END_RESET_VENDOR_REQUEST,
209 USB_TYPE_VENDOR | USB_DIR_OUT,
210 10, 0,
211 NULL, 0, 500);
212}
213#endif
214
215/* LED control */
216enum technisat_usb2_led_state {
217 LED_OFF,
218 LED_BLINK,
219 LED_ON,
220 LED_UNDEFINED
221};
222
223static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum technisat_usb2_led_state state)
224{
225 int ret;
226
227 u8 led[8] = {
228 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
229 0
230 };
231
232 if (disable_led_control && state != LED_OFF)
233 return 0;
234
235 switch (state) {
236 case LED_ON:
237 led[1] = 0x82;
238 break;
239 case LED_BLINK:
240 led[1] = 0x82;
241 if (red) {
242 led[2] = 0x02;
243 led[3] = 10;
244 led[4] = 10;
245 } else {
246 led[2] = 0xff;
247 led[3] = 50;
248 led[4] = 50;
249 }
250 led[5] = 1;
251 break;
252
253 default:
254 case LED_OFF:
255 led[1] = 0x80;
256 break;
257 }
258
259 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
260 return -EAGAIN;
261
262 ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0),
263 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
264 USB_TYPE_VENDOR | USB_DIR_OUT,
265 0, 0,
266 led, sizeof(led), 500);
267
268 mutex_unlock(&d->i2c_mutex);
269 return ret;
270}
271
272static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
273{
274 int ret;
275 u8 b = 0;
276
277 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
278 return -EAGAIN;
279
280 ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0),
281 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
282 USB_TYPE_VENDOR | USB_DIR_OUT,
283 (red << 8) | green, 0,
284 &b, 1, 500);
285
286 mutex_unlock(&d->i2c_mutex);
287
288 return ret;
289}
290
291static void technisat_usb2_green_led_control(struct work_struct *work)
292{
293 struct technisat_usb2_state *state =
294 container_of(work, struct technisat_usb2_state, green_led_work.work);
295 struct dvb_frontend *fe = state->dev->adapter[0].fe;
296
297 if (state->power_state == 0)
298 goto schedule;
299
300 if (fe != NULL) {
301 enum fe_status status;
302
303 if (fe->ops.read_status(fe, &status) != 0)
304 goto schedule;
305
306 if (status & FE_HAS_LOCK) {
307 u32 ber;
308
309 if (fe->ops.read_ber(fe, &ber) != 0)
310 goto schedule;
311
312 if (ber > 1000)
313 technisat_usb2_set_led(state->dev, 0, LED_BLINK);
314 else
315 technisat_usb2_set_led(state->dev, 0, LED_ON);
316 } else
317 technisat_usb2_set_led(state->dev, 0, LED_OFF);
318 }
319
320schedule:
321 schedule_delayed_work(&state->green_led_work,
322 msecs_to_jiffies(500));
323}
324
325/* method to find out whether the firmware has to be downloaded or not */
326static int technisat_usb2_identify_state(struct usb_device *udev,
327 struct dvb_usb_device_properties *props,
328 struct dvb_usb_device_description **desc, int *cold)
329{
330 int ret;
331 u8 version[3];
332
333 /* first select the interface */
334 if (usb_set_interface(udev, 0, 1) != 0)
335 err("could not set alternate setting to 0");
336 else
337 info("set alternate setting");
338
339 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
340
341 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
342 GET_VERSION_INFO_VENDOR_REQUEST,
343 USB_TYPE_VENDOR | USB_DIR_IN,
344 0, 0,
345 version, sizeof(version), 500);
346
347 if (ret < 0)
348 *cold = 1;
349 else {
350 info("firmware version: %d.%d", version[1], version[2]);
351 *cold = 0;
352 }
353
354 return 0;
355}
356
357/* power control */
358static int technisat_usb2_power_ctrl(struct dvb_usb_device *d, int level)
359{
360 struct technisat_usb2_state *state = d->priv;
361
362 state->power_state = level;
363
364 if (disable_led_control)
365 return 0;
366
367 /* green led is turned off in any case - will be turned on when tuning */
368 technisat_usb2_set_led(d, 0, LED_OFF);
369 /* red led is turned on all the time */
370 technisat_usb2_set_led(d, 1, LED_ON);
371 return 0;
372}
373
374/* mac address reading - from the eeprom */
375#if 0
376static void technisat_usb2_eeprom_dump(struct dvb_usb_device *d)
377{
378 u8 reg;
379 u8 b[16];
380 int i, j;
381
382 /* full EEPROM dump */
383 for (j = 0; j < 256 * 4; j += 16) {
384 reg = j;
385 if (technisat_usb2_i2c_access(d->udev, 0x50 + j / 256, &reg, 1, b, 16) != 0)
386 break;
387
388 deb_eeprom("EEPROM: %01x%02x: ", j / 256, reg);
389 for (i = 0; i < 16; i++)
390 deb_eeprom("%02x ", b[i]);
391 deb_eeprom("\n");
392 }
393}
394#endif
395
396static u8 technisat_usb2_calc_lrc(const u8 *b, u16 length)
397{
398 u8 lrc = 0;
399 while (--length)
400 lrc ^= *b++;
401 return lrc;
402}
403
404static int technisat_usb2_eeprom_lrc_read(struct dvb_usb_device *d,
405 u16 offset, u8 *b, u16 length, u8 tries)
406{
407 u8 bo = offset & 0xff;
408 struct i2c_msg msg[] = {
409 {
410 .addr = 0x50 | ((offset >> 8) & 0x3),
411 .buf = &bo,
412 .len = 1
413 }, {
414 .addr = 0x50 | ((offset >> 8) & 0x3),
415 .flags = I2C_M_RD,
416 .buf = b,
417 .len = length
418 }
419 };
420
421 while (tries--) {
422 int status;
423
424 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
425 break;
426
427 status =
428 technisat_usb2_calc_lrc(b, length - 1) == b[length - 1];
429
430 if (status)
431 return 0;
432 }
433
434 return -EREMOTEIO;
435}
436
437#define EEPROM_MAC_START 0x3f8
438#define EEPROM_MAC_TOTAL 8
439static int technisat_usb2_read_mac_address(struct dvb_usb_device *d,
440 u8 mac[])
441{
442 u8 buf[EEPROM_MAC_TOTAL];
443
444 if (technisat_usb2_eeprom_lrc_read(d, EEPROM_MAC_START,
445 buf, EEPROM_MAC_TOTAL, 4) != 0)
446 return -ENODEV;
447
448 memcpy(mac, buf, 6);
449 return 0;
450}
451
452/* frontend attach */
453static int technisat_usb2_set_voltage(struct dvb_frontend *fe,
454 fe_sec_voltage_t voltage)
455{
456 int i;
457 u8 gpio[3] = { 0 }; /* 0 = 2, 1 = 3, 2 = 4 */
458
459 gpio[2] = 1; /* high - voltage ? */
460
461 switch (voltage) {
462 case SEC_VOLTAGE_13:
463 gpio[0] = 1;
464 break;
465 case SEC_VOLTAGE_18:
466 gpio[0] = 1;
467 gpio[1] = 1;
468 break;
469 default:
470 case SEC_VOLTAGE_OFF:
471 break;
472 }
473
474 for (i = 0; i < 3; i++)
475 if (stv090x_set_gpio(fe, i+2, 0, gpio[i], 0) != 0)
476 return -EREMOTEIO;
477 return 0;
478}
479
480static struct stv090x_config technisat_usb2_stv090x_config = {
481 .device = STV0903,
482 .demod_mode = STV090x_SINGLE,
483 .clk_mode = STV090x_CLK_EXT,
484
485 .xtal = 8000000,
486 .address = 0x68,
487
488 .ts1_mode = STV090x_TSMODE_DVBCI,
489 .ts1_clk = 13400000,
490 .ts1_tei = 1,
491
492 .repeater_level = STV090x_RPTLEVEL_64,
493
494 .tuner_bbgain = 6,
495};
496
497static struct stv6110x_config technisat_usb2_stv6110x_config = {
498 .addr = 0x60,
499 .refclk = 16000000,
500 .clk_div = 2,
501};
502
503static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
504{
505 struct usb_device *udev = a->dev->udev;
506 int ret;
507
508 a->fe = dvb_attach(stv090x_attach, &technisat_usb2_stv090x_config,
509 &a->dev->i2c_adap, STV090x_DEMODULATOR_0);
510
511 if (a->fe) {
512 struct stv6110x_devctl *ctl;
513
514 ctl = dvb_attach(stv6110x_attach,
515 a->fe,
516 &technisat_usb2_stv6110x_config,
517 &a->dev->i2c_adap);
518
519 if (ctl) {
520 technisat_usb2_stv090x_config.tuner_init = ctl->tuner_init;
521 technisat_usb2_stv090x_config.tuner_sleep = ctl->tuner_sleep;
522 technisat_usb2_stv090x_config.tuner_set_mode = ctl->tuner_set_mode;
523 technisat_usb2_stv090x_config.tuner_set_frequency = ctl->tuner_set_frequency;
524 technisat_usb2_stv090x_config.tuner_get_frequency = ctl->tuner_get_frequency;
525 technisat_usb2_stv090x_config.tuner_set_bandwidth = ctl->tuner_set_bandwidth;
526 technisat_usb2_stv090x_config.tuner_get_bandwidth = ctl->tuner_get_bandwidth;
527 technisat_usb2_stv090x_config.tuner_set_bbgain = ctl->tuner_set_bbgain;
528 technisat_usb2_stv090x_config.tuner_get_bbgain = ctl->tuner_get_bbgain;
529 technisat_usb2_stv090x_config.tuner_set_refclk = ctl->tuner_set_refclk;
530 technisat_usb2_stv090x_config.tuner_get_status = ctl->tuner_get_status;
531
532 /* call the init function once to initialize
533 tuner's clock output divider and demod's
534 master clock */
535 if (a->fe->ops.init)
536 a->fe->ops.init(a->fe);
537
538 if (mutex_lock_interruptible(&a->dev->i2c_mutex) < 0)
539 return -EAGAIN;
540
541 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
542 SET_IFCLK_TO_EXTERNAL_TSCLK_VENDOR_REQUEST,
543 USB_TYPE_VENDOR | USB_DIR_OUT,
544 0, 0,
545 NULL, 0, 500);
546 mutex_unlock(&a->dev->i2c_mutex);
547
548 if (ret != 0)
549 err("could not set IF_CLK to external");
550
551 a->fe->ops.set_voltage = technisat_usb2_set_voltage;
552
553 /* if everything was successful assign a nice name to the frontend */
554 strlcpy(a->fe->ops.info.name, a->dev->desc->name,
555 sizeof(a->fe->ops.info.name));
556 } else {
557 dvb_frontend_detach(a->fe);
558 a->fe = NULL;
559 }
560 }
561
562 technisat_usb2_set_led_timer(a->dev, 1, 1);
563
564 return a->fe == NULL ? -ENODEV : 0;
565}
566
567/* Remote control */
568
569/* the device is giving providing raw IR-signals to the host mapping
570 * it only to one remote control is just the default implementation
571 */
572#define NOMINAL_IR_BIT_TRANSITION_TIME_US 889
573#define NOMINAL_IR_BIT_TIME_US (2 * NOMINAL_IR_BIT_TRANSITION_TIME_US)
574
575#define FIRMWARE_CLOCK_TICK 83333
576#define FIRMWARE_CLOCK_DIVISOR 256
577
578#define IR_PERCENT_TOLERANCE 15
579
580#define NOMINAL_IR_BIT_TRANSITION_TICKS ((NOMINAL_IR_BIT_TRANSITION_TIME_US * 1000 * 1000) / FIRMWARE_CLOCK_TICK)
581#define NOMINAL_IR_BIT_TRANSITION_TICK_COUNT (NOMINAL_IR_BIT_TRANSITION_TICKS / FIRMWARE_CLOCK_DIVISOR)
582
583#define NOMINAL_IR_BIT_TIME_TICKS ((NOMINAL_IR_BIT_TIME_US * 1000 * 1000) / FIRMWARE_CLOCK_TICK)
584#define NOMINAL_IR_BIT_TIME_TICK_COUNT (NOMINAL_IR_BIT_TIME_TICKS / FIRMWARE_CLOCK_DIVISOR)
585
586#define MINIMUM_IR_BIT_TRANSITION_TICK_COUNT (NOMINAL_IR_BIT_TRANSITION_TICK_COUNT - ((NOMINAL_IR_BIT_TRANSITION_TICK_COUNT * IR_PERCENT_TOLERANCE) / 100))
587#define MAXIMUM_IR_BIT_TRANSITION_TICK_COUNT (NOMINAL_IR_BIT_TRANSITION_TICK_COUNT + ((NOMINAL_IR_BIT_TRANSITION_TICK_COUNT * IR_PERCENT_TOLERANCE) / 100))
588
589#define MINIMUM_IR_BIT_TIME_TICK_COUNT (NOMINAL_IR_BIT_TIME_TICK_COUNT - ((NOMINAL_IR_BIT_TIME_TICK_COUNT * IR_PERCENT_TOLERANCE) / 100))
590#define MAXIMUM_IR_BIT_TIME_TICK_COUNT (NOMINAL_IR_BIT_TIME_TICK_COUNT + ((NOMINAL_IR_BIT_TIME_TICK_COUNT * IR_PERCENT_TOLERANCE) / 100))
591
592static int technisat_usb2_get_ir(struct dvb_usb_device *d)
593{
594 u8 buf[62], *b;
595 int ret;
596 struct ir_raw_event ev;
597
598 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
599 buf[1] = 0x08;
600 buf[2] = 0x8f;
601 buf[3] = MINIMUM_IR_BIT_TRANSITION_TICK_COUNT;
602 buf[4] = MAXIMUM_IR_BIT_TIME_TICK_COUNT;
603
604 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
605 return -EAGAIN;
606 ret = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev, 0),
607 GET_IR_DATA_VENDOR_REQUEST,
608 USB_TYPE_VENDOR | USB_DIR_OUT,
609 0, 0,
610 buf, 5, 500);
611 if (ret < 0)
612 goto unlock;
613
614 buf[1] = 0;
615 buf[2] = 0;
616 ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
617 GET_IR_DATA_VENDOR_REQUEST,
618 USB_TYPE_VENDOR | USB_DIR_IN,
619 0x8080, 0,
620 buf, sizeof(buf), 500);
621
622unlock:
623 mutex_unlock(&d->i2c_mutex);
624
625 if (ret < 0)
626 return ret;
627
628 if (ret == 1)
629 return 0; /* no key pressed */
630
631 /* decoding */
632 b = buf+1;
633
634#if 0
635 deb_rc("RC: %d ", ret);
636 debug_dump(b, ret, deb_rc);
637#endif
638
639 ev.pulse = 0;
640 while (1) {
641 ev.pulse = !ev.pulse;
642 ev.duration = (*b * FIRMWARE_CLOCK_DIVISOR * FIRMWARE_CLOCK_TICK) / 1000;
643 ir_raw_event_store(d->rc_dev, &ev);
644
645 b++;
646 if (*b == 0xff) {
647 ev.pulse = 0;
648 ev.duration = 888888*2;
649 ir_raw_event_store(d->rc_dev, &ev);
650 break;
651 }
652 }
653
654 ir_raw_event_handle(d->rc_dev);
655
656 return 1;
657}
658
659static int technisat_usb2_rc_query(struct dvb_usb_device *d)
660{
661 int ret = technisat_usb2_get_ir(d);
662
663 if (ret < 0)
664 return ret;
665
666 if (ret == 0)
667 return 0;
668
669 if (!disable_led_control)
670 technisat_usb2_set_led(d, 1, LED_BLINK);
671
672 return 0;
673}
674
675/* DVB-USB and USB stuff follows */
676static struct usb_device_id technisat_usb2_id_table[] = {
677 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_DVB_S2) },
678 { 0 } /* Terminating entry */
679};
680
681/* device description */
682static struct dvb_usb_device_properties technisat_usb2_devices = {
683 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
684
685 .usb_ctrl = CYPRESS_FX2,
686
687 .identify_state = technisat_usb2_identify_state,
688 .firmware = "dvb-usb-SkyStar_USB_HD_FW_v17_63.HEX.fw",
689
690 .size_of_priv = sizeof(struct technisat_usb2_state),
691
692 .i2c_algo = &technisat_usb2_i2c_algo,
693
694 .power_ctrl = technisat_usb2_power_ctrl,
695 .read_mac_address = technisat_usb2_read_mac_address,
696
697 .num_adapters = 1,
698 .adapter = {
699 {
700 .frontend_attach = technisat_usb2_frontend_attach,
701
702 .stream = {
703 .type = USB_ISOC,
704 .count = 8,
705 .endpoint = 0x2,
706 .u = {
707 .isoc = {
708 .framesperurb = 32,
709 .framesize = 2048,
710 .interval = 3,
711 }
712 }
713 },
714
715 .size_of_priv = 0,
716 },
717 },
718
719 .num_device_descs = 1,
720 .devices = {
721 { "Technisat SkyStar USB HD (DVB-S/S2)",
722 { &technisat_usb2_id_table[0], NULL },
723 { NULL },
724 },
725 },
726
727 .rc.core = {
728 .rc_interval = 100,
729 .rc_codes = RC_MAP_TECHNISAT_USB2,
730 .module_name = "technisat-usb2",
731 .rc_query = technisat_usb2_rc_query,
732 .allowed_protos = RC_TYPE_ALL,
733 .driver_type = RC_DRIVER_IR_RAW,
734 }
735};
736
737static int technisat_usb2_probe(struct usb_interface *intf,
738 const struct usb_device_id *id)
739{
740 struct dvb_usb_device *dev;
741
742 if (dvb_usb_device_init(intf, &technisat_usb2_devices, THIS_MODULE,
743 &dev, adapter_nr) != 0)
744 return -ENODEV;
745
746 if (dev) {
747 struct technisat_usb2_state *state = dev->priv;
748 state->dev = dev;
749
750 if (!disable_led_control) {
751 INIT_DELAYED_WORK(&state->green_led_work,
752 technisat_usb2_green_led_control);
753 schedule_delayed_work(&state->green_led_work,
754 msecs_to_jiffies(500));
755 }
756 }
757
758 return 0;
759}
760
761static void technisat_usb2_disconnect(struct usb_interface *intf)
762{
763 struct dvb_usb_device *dev = usb_get_intfdata(intf);
764
765 /* work and stuff was only created when the device is is hot-state */
766 if (dev != NULL) {
767 struct technisat_usb2_state *state = dev->priv;
768 if (state != NULL) {
769 cancel_delayed_work_sync(&state->green_led_work);
770 flush_scheduled_work();
771 }
772 }
773
774 dvb_usb_device_exit(intf);
775}
776
777static struct usb_driver technisat_usb2_driver = {
778 .name = "dvb_usb_technisat_usb2",
779 .probe = technisat_usb2_probe,
780 .disconnect = technisat_usb2_disconnect,
781 .id_table = technisat_usb2_id_table,
782};
783
784/* module stuff */
785static int __init technisat_usb2_module_init(void)
786{
787 int result = usb_register(&technisat_usb2_driver);
788 if (result) {
789 err("usb_register failed. Code %d", result);
790 return result;
791 }
792
793 return 0;
794}
795
796static void __exit technisat_usb2_module_exit(void)
797{
798 usb_deregister(&technisat_usb2_driver);
799}
800
801module_init(technisat_usb2_module_init);
802module_exit(technisat_usb2_module_exit);
803
804MODULE_AUTHOR("Patrick Boettcher <pboettcher@kernellabs.com>");
805MODULE_DESCRIPTION("Driver for Technisat DVB-S/S2 USB 2.0 device");
806MODULE_VERSION("1.0");
807MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/ttusb2.c b/drivers/media/dvb/dvb-usb/ttusb2.c
index a6de489a6a39..0d4709ff9cbb 100644
--- a/drivers/media/dvb/dvb-usb/ttusb2.c
+++ b/drivers/media/dvb/dvb-usb/ttusb2.c
@@ -43,6 +43,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
43 43
44struct ttusb2_state { 44struct ttusb2_state {
45 u8 id; 45 u8 id;
46 u16 last_rc_key;
46}; 47};
47 48
48static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd, 49static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd,
@@ -128,6 +129,33 @@ static struct i2c_algorithm ttusb2_i2c_algo = {
128 .functionality = ttusb2_i2c_func, 129 .functionality = ttusb2_i2c_func,
129}; 130};
130 131
132/* command to poll IR receiver (copied from pctv452e.c) */
133#define CMD_GET_IR_CODE 0x1b
134
135/* IR */
136static int tt3650_rc_query(struct dvb_usb_device *d)
137{
138 int ret;
139 u8 rx[9]; /* A CMD_GET_IR_CODE reply is 9 bytes long */
140 struct ttusb2_state *st = d->priv;
141 ret = ttusb2_msg(d, CMD_GET_IR_CODE, NULL, 0, rx, sizeof(rx));
142 if (ret != 0)
143 return ret;
144
145 if (rx[8] & 0x01) {
146 /* got a "press" event */
147 st->last_rc_key = (rx[3] << 8) | rx[2];
148 deb_info("%s: cmd=0x%02x sys=0x%02x\n", __func__, rx[2], rx[3]);
149 rc_keydown(d->rc_dev, st->last_rc_key, 0);
150 } else if (st->last_rc_key) {
151 rc_keyup(d->rc_dev);
152 st->last_rc_key = 0;
153 }
154
155 return 0;
156}
157
158
131/* Callbacks for DVB USB */ 159/* Callbacks for DVB USB */
132static int ttusb2_identify_state (struct usb_device *udev, struct 160static int ttusb2_identify_state (struct usb_device *udev, struct
133 dvb_usb_device_properties *props, struct dvb_usb_device_description **desc, 161 dvb_usb_device_properties *props, struct dvb_usb_device_description **desc,
@@ -345,6 +373,13 @@ static struct dvb_usb_device_properties ttusb2_properties_ct3650 = {
345 373
346 .size_of_priv = sizeof(struct ttusb2_state), 374 .size_of_priv = sizeof(struct ttusb2_state),
347 375
376 .rc.core = {
377 .rc_interval = 150, /* Less than IR_KEYPRESS_TIMEOUT */
378 .rc_codes = RC_MAP_TT_1500,
379 .rc_query = tt3650_rc_query,
380 .allowed_protos = RC_TYPE_UNKNOWN,
381 },
382
348 .num_adapters = 1, 383 .num_adapters = 1,
349 .adapter = { 384 .adapter = {
350 { 385 {
diff --git a/drivers/media/dvb/dvb-usb/vp702x-fe.c b/drivers/media/dvb/dvb-usb/vp702x-fe.c
index ccc7e4452664..2bb8d4cc8d88 100644
--- a/drivers/media/dvb/dvb-usb/vp702x-fe.c
+++ b/drivers/media/dvb/dvb-usb/vp702x-fe.c
@@ -41,14 +41,23 @@ struct vp702x_fe_state {
41 41
42static int vp702x_fe_refresh_state(struct vp702x_fe_state *st) 42static int vp702x_fe_refresh_state(struct vp702x_fe_state *st)
43{ 43{
44 u8 buf[10]; 44 struct vp702x_device_state *dst = st->d->priv;
45 if (time_after(jiffies,st->next_status_check)) { 45 u8 *buf;
46 vp702x_usb_in_op(st->d,READ_STATUS,0,0,buf,10);
47 46
47 if (time_after(jiffies, st->next_status_check)) {
48 mutex_lock(&dst->buf_mutex);
49 buf = dst->buf;
50
51 vp702x_usb_in_op(st->d, READ_STATUS, 0, 0, buf, 10);
48 st->lock = buf[4]; 52 st->lock = buf[4];
49 vp702x_usb_in_op(st->d,READ_TUNER_REG_REQ,0x11,0,&st->snr,1);
50 vp702x_usb_in_op(st->d,READ_TUNER_REG_REQ,0x15,0,&st->sig,1);
51 53
54 vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x11, 0, buf, 1);
55 st->snr = buf[0];
56
57 vp702x_usb_in_op(st->d, READ_TUNER_REG_REQ, 0x15, 0, buf, 1);
58 st->sig = buf[0];
59
60 mutex_unlock(&dst->buf_mutex);
52 st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000; 61 st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
53 } 62 }
54 return 0; 63 return 0;
@@ -130,11 +139,17 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe,
130 struct dvb_frontend_parameters *fep) 139 struct dvb_frontend_parameters *fep)
131{ 140{
132 struct vp702x_fe_state *st = fe->demodulator_priv; 141 struct vp702x_fe_state *st = fe->demodulator_priv;
142 struct vp702x_device_state *dst = st->d->priv;
133 u32 freq = fep->frequency/1000; 143 u32 freq = fep->frequency/1000;
134 /*CalFrequency*/ 144 /*CalFrequency*/
135/* u16 frequencyRef[16] = { 2, 4, 8, 16, 32, 64, 128, 256, 24, 5, 10, 20, 40, 80, 160, 320 }; */ 145/* u16 frequencyRef[16] = { 2, 4, 8, 16, 32, 64, 128, 256, 24, 5, 10, 20, 40, 80, 160, 320 }; */
136 u64 sr; 146 u64 sr;
137 u8 cmd[8] = { 0 },ibuf[10]; 147 u8 *cmd;
148
149 mutex_lock(&dst->buf_mutex);
150
151 cmd = dst->buf;
152 memset(cmd, 0, 10);
138 153
139 cmd[0] = (freq >> 8) & 0x7f; 154 cmd[0] = (freq >> 8) & 0x7f;
140 cmd[1] = freq & 0xff; 155 cmd[1] = freq & 0xff;
@@ -170,13 +185,15 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe,
170 st->status_check_interval = 250; 185 st->status_check_interval = 250;
171 st->next_status_check = jiffies; 186 st->next_status_check = jiffies;
172 187
173 vp702x_usb_inout_op(st->d,cmd,8,ibuf,10,100); 188 vp702x_usb_inout_op(st->d, cmd, 8, cmd, 10, 100);
174 189
175 if (ibuf[2] == 0 && ibuf[3] == 0) 190 if (cmd[2] == 0 && cmd[3] == 0)
176 deb_fe("tuning failed.\n"); 191 deb_fe("tuning failed.\n");
177 else 192 else
178 deb_fe("tuning succeeded.\n"); 193 deb_fe("tuning succeeded.\n");
179 194
195 mutex_unlock(&dst->buf_mutex);
196
180 return 0; 197 return 0;
181} 198}
182 199
@@ -204,27 +221,32 @@ static int vp702x_fe_get_frontend(struct dvb_frontend* fe,
204static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe, 221static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
205 struct dvb_diseqc_master_cmd *m) 222 struct dvb_diseqc_master_cmd *m)
206{ 223{
224 u8 *cmd;
207 struct vp702x_fe_state *st = fe->demodulator_priv; 225 struct vp702x_fe_state *st = fe->demodulator_priv;
208 u8 cmd[8],ibuf[10]; 226 struct vp702x_device_state *dst = st->d->priv;
209 memset(cmd,0,8);
210 227
211 deb_fe("%s\n",__func__); 228 deb_fe("%s\n",__func__);
212 229
213 if (m->msg_len > 4) 230 if (m->msg_len > 4)
214 return -EINVAL; 231 return -EINVAL;
215 232
233 mutex_lock(&dst->buf_mutex);
234
235 cmd = dst->buf;
216 cmd[1] = SET_DISEQC_CMD; 236 cmd[1] = SET_DISEQC_CMD;
217 cmd[2] = m->msg_len; 237 cmd[2] = m->msg_len;
218 memcpy(&cmd[3], m->msg, m->msg_len); 238 memcpy(&cmd[3], m->msg, m->msg_len);
219 cmd[7] = vp702x_chksum(cmd,0,7); 239 cmd[7] = vp702x_chksum(cmd, 0, 7);
220 240
221 vp702x_usb_inout_op(st->d,cmd,8,ibuf,10,100); 241 vp702x_usb_inout_op(st->d, cmd, 8, cmd, 10, 100);
222 242
223 if (ibuf[2] == 0 && ibuf[3] == 0) 243 if (cmd[2] == 0 && cmd[3] == 0)
224 deb_fe("diseqc cmd failed.\n"); 244 deb_fe("diseqc cmd failed.\n");
225 else 245 else
226 deb_fe("diseqc cmd succeeded.\n"); 246 deb_fe("diseqc cmd succeeded.\n");
227 247
248 mutex_unlock(&dst->buf_mutex);
249
228 return 0; 250 return 0;
229} 251}
230 252
@@ -237,7 +259,9 @@ static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd
237static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) 259static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
238{ 260{
239 struct vp702x_fe_state *st = fe->demodulator_priv; 261 struct vp702x_fe_state *st = fe->demodulator_priv;
240 u8 ibuf[10]; 262 struct vp702x_device_state *dst = st->d->priv;
263 u8 *buf;
264
241 deb_fe("%s\n",__func__); 265 deb_fe("%s\n",__func__);
242 266
243 st->tone_mode = tone; 267 st->tone_mode = tone;
@@ -247,14 +271,21 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
247 else 271 else
248 st->lnb_buf[2] = 0x00; 272 st->lnb_buf[2] = 0x00;
249 273
250 st->lnb_buf[7] = vp702x_chksum(st->lnb_buf,0,7); 274 st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7);
275
276 mutex_lock(&dst->buf_mutex);
277
278 buf = dst->buf;
279 memcpy(buf, st->lnb_buf, 8);
251 280
252 vp702x_usb_inout_op(st->d,st->lnb_buf,8,ibuf,10,100); 281 vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100);
253 if (ibuf[2] == 0 && ibuf[3] == 0) 282 if (buf[2] == 0 && buf[3] == 0)
254 deb_fe("set_tone cmd failed.\n"); 283 deb_fe("set_tone cmd failed.\n");
255 else 284 else
256 deb_fe("set_tone cmd succeeded.\n"); 285 deb_fe("set_tone cmd succeeded.\n");
257 286
287 mutex_unlock(&dst->buf_mutex);
288
258 return 0; 289 return 0;
259} 290}
260 291
@@ -262,7 +293,8 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
262 voltage) 293 voltage)
263{ 294{
264 struct vp702x_fe_state *st = fe->demodulator_priv; 295 struct vp702x_fe_state *st = fe->demodulator_priv;
265 u8 ibuf[10]; 296 struct vp702x_device_state *dst = st->d->priv;
297 u8 *buf;
266 deb_fe("%s\n",__func__); 298 deb_fe("%s\n",__func__);
267 299
268 st->voltage = voltage; 300 st->voltage = voltage;
@@ -272,14 +304,20 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
272 else 304 else
273 st->lnb_buf[4] = 0x00; 305 st->lnb_buf[4] = 0x00;
274 306
275 st->lnb_buf[7] = vp702x_chksum(st->lnb_buf,0,7); 307 st->lnb_buf[7] = vp702x_chksum(st->lnb_buf, 0, 7);
308
309 mutex_lock(&dst->buf_mutex);
310
311 buf = dst->buf;
312 memcpy(buf, st->lnb_buf, 8);
276 313
277 vp702x_usb_inout_op(st->d,st->lnb_buf,8,ibuf,10,100); 314 vp702x_usb_inout_op(st->d, buf, 8, buf, 10, 100);
278 if (ibuf[2] == 0 && ibuf[3] == 0) 315 if (buf[2] == 0 && buf[3] == 0)
279 deb_fe("set_voltage cmd failed.\n"); 316 deb_fe("set_voltage cmd failed.\n");
280 else 317 else
281 deb_fe("set_voltage cmd succeeded.\n"); 318 deb_fe("set_voltage cmd succeeded.\n");
282 319
320 mutex_unlock(&dst->buf_mutex);
283 return 0; 321 return 0;
284} 322}
285 323
diff --git a/drivers/media/dvb/dvb-usb/vp702x.c b/drivers/media/dvb/dvb-usb/vp702x.c
index 5c9f3275aaa0..54355f84a98f 100644
--- a/drivers/media/dvb/dvb-usb/vp702x.c
+++ b/drivers/media/dvb/dvb-usb/vp702x.c
@@ -15,6 +15,7 @@
15 * see Documentation/dvb/README.dvb-usb for more information 15 * see Documentation/dvb/README.dvb-usb for more information
16 */ 16 */
17#include "vp702x.h" 17#include "vp702x.h"
18#include <linux/mutex.h>
18 19
19/* debug */ 20/* debug */
20int dvb_usb_vp702x_debug; 21int dvb_usb_vp702x_debug;
@@ -23,27 +24,23 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DV
23 24
24DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 25DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
25 26
26struct vp702x_state { 27struct vp702x_adapter_state {
27 int pid_filter_count; 28 int pid_filter_count;
28 int pid_filter_can_bypass; 29 int pid_filter_can_bypass;
29 u8 pid_filter_state; 30 u8 pid_filter_state;
30}; 31};
31 32
32struct vp702x_device_state { 33static int vp702x_usb_in_op_unlocked(struct dvb_usb_device *d, u8 req,
33 u8 power_state; 34 u16 value, u16 index, u8 *b, int blen)
34};
35
36/* check for mutex FIXME */
37int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen)
38{ 35{
39 int ret = -1; 36 int ret;
40 37
41 ret = usb_control_msg(d->udev, 38 ret = usb_control_msg(d->udev,
42 usb_rcvctrlpipe(d->udev,0), 39 usb_rcvctrlpipe(d->udev, 0),
43 req, 40 req,
44 USB_TYPE_VENDOR | USB_DIR_IN, 41 USB_TYPE_VENDOR | USB_DIR_IN,
45 value,index,b,blen, 42 value, index, b, blen,
46 2000); 43 2000);
47 44
48 if (ret < 0) { 45 if (ret < 0) {
49 warn("usb in operation failed. (%d)", ret); 46 warn("usb in operation failed. (%d)", ret);
@@ -58,8 +55,20 @@ int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8
58 return ret; 55 return ret;
59} 56}
60 57
61static int vp702x_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value, 58int vp702x_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value,
62 u16 index, u8 *b, int blen) 59 u16 index, u8 *b, int blen)
60{
61 int ret;
62
63 mutex_lock(&d->usb_mutex);
64 ret = vp702x_usb_in_op_unlocked(d, req, value, index, b, blen);
65 mutex_unlock(&d->usb_mutex);
66
67 return ret;
68}
69
70int vp702x_usb_out_op_unlocked(struct dvb_usb_device *d, u8 req, u16 value,
71 u16 index, u8 *b, int blen)
63{ 72{
64 int ret; 73 int ret;
65 deb_xfer("out: req. %02x, val: %04x, ind: %04x, buffer: ",req,value,index); 74 deb_xfer("out: req. %02x, val: %04x, ind: %04x, buffer: ",req,value,index);
@@ -77,6 +86,18 @@ static int vp702x_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
77 return 0; 86 return 0;
78} 87}
79 88
89int vp702x_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
90 u16 index, u8 *b, int blen)
91{
92 int ret;
93
94 mutex_lock(&d->usb_mutex);
95 ret = vp702x_usb_out_op_unlocked(d, req, value, index, b, blen);
96 mutex_unlock(&d->usb_mutex);
97
98 return ret;
99}
100
80int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int ilen, int msec) 101int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int ilen, int msec)
81{ 102{
82 int ret; 103 int ret;
@@ -84,50 +105,93 @@ int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int il
84 if ((ret = mutex_lock_interruptible(&d->usb_mutex))) 105 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
85 return ret; 106 return ret;
86 107
87 ret = vp702x_usb_out_op(d,REQUEST_OUT,0,0,o,olen); 108 ret = vp702x_usb_out_op_unlocked(d, REQUEST_OUT, 0, 0, o, olen);
88 msleep(msec); 109 msleep(msec);
89 ret = vp702x_usb_in_op(d,REQUEST_IN,0,0,i,ilen); 110 ret = vp702x_usb_in_op_unlocked(d, REQUEST_IN, 0, 0, i, ilen);
90 111
91 mutex_unlock(&d->usb_mutex); 112 mutex_unlock(&d->usb_mutex);
92
93 return ret; 113 return ret;
94} 114}
95 115
96static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o, 116static int vp702x_usb_inout_cmd(struct dvb_usb_device *d, u8 cmd, u8 *o,
97 int olen, u8 *i, int ilen, int msec) 117 int olen, u8 *i, int ilen, int msec)
98{ 118{
99 u8 bout[olen+2]; 119 struct vp702x_device_state *st = d->priv;
100 u8 bin[ilen+1];
101 int ret = 0; 120 int ret = 0;
121 u8 *buf;
122 int buflen = max(olen + 2, ilen + 1);
123
124 ret = mutex_lock_interruptible(&st->buf_mutex);
125 if (ret < 0)
126 return ret;
127
128 if (buflen > st->buf_len) {
129 buf = kmalloc(buflen, GFP_KERNEL);
130 if (!buf) {
131 mutex_unlock(&st->buf_mutex);
132 return -ENOMEM;
133 }
134 info("successfully reallocated a bigger buffer");
135 kfree(st->buf);
136 st->buf = buf;
137 st->buf_len = buflen;
138 } else {
139 buf = st->buf;
140 }
102 141
103 bout[0] = 0x00; 142 buf[0] = 0x00;
104 bout[1] = cmd; 143 buf[1] = cmd;
105 memcpy(&bout[2],o,olen); 144 memcpy(&buf[2], o, olen);
106 145
107 ret = vp702x_usb_inout_op(d, bout, olen+2, bin, ilen+1,msec); 146 ret = vp702x_usb_inout_op(d, buf, olen+2, buf, ilen+1, msec);
108 147
109 if (ret == 0) 148 if (ret == 0)
110 memcpy(i,&bin[1],ilen); 149 memcpy(i, &buf[1], ilen);
150 mutex_unlock(&st->buf_mutex);
111 151
112 return ret; 152 return ret;
113} 153}
114 154
115static int vp702x_set_pld_mode(struct dvb_usb_adapter *adap, u8 bypass) 155static int vp702x_set_pld_mode(struct dvb_usb_adapter *adap, u8 bypass)
116{ 156{
117 u8 buf[16] = { 0 }; 157 int ret;
118 return vp702x_usb_in_op(adap->dev, 0xe0, (bypass << 8) | 0x0e, 0, buf, 16); 158 struct vp702x_device_state *st = adap->dev->priv;
159 u8 *buf;
160
161 mutex_lock(&st->buf_mutex);
162
163 buf = st->buf;
164 memset(buf, 0, 16);
165
166 ret = vp702x_usb_in_op(adap->dev, 0xe0, (bypass << 8) | 0x0e,
167 0, buf, 16);
168 mutex_unlock(&st->buf_mutex);
169 return ret;
119} 170}
120 171
121static int vp702x_set_pld_state(struct dvb_usb_adapter *adap, u8 state) 172static int vp702x_set_pld_state(struct dvb_usb_adapter *adap, u8 state)
122{ 173{
123 u8 buf[16] = { 0 }; 174 int ret;
124 return vp702x_usb_in_op(adap->dev, 0xe0, (state << 8) | 0x0f, 0, buf, 16); 175 struct vp702x_device_state *st = adap->dev->priv;
176 u8 *buf;
177
178 mutex_lock(&st->buf_mutex);
179
180 buf = st->buf;
181 memset(buf, 0, 16);
182 ret = vp702x_usb_in_op(adap->dev, 0xe0, (state << 8) | 0x0f,
183 0, buf, 16);
184
185 mutex_unlock(&st->buf_mutex);
186
187 return ret;
125} 188}
126 189
127static int vp702x_set_pid(struct dvb_usb_adapter *adap, u16 pid, u8 id, int onoff) 190static int vp702x_set_pid(struct dvb_usb_adapter *adap, u16 pid, u8 id, int onoff)
128{ 191{
129 struct vp702x_state *st = adap->priv; 192 struct vp702x_adapter_state *st = adap->priv;
130 u8 buf[16] = { 0 }; 193 struct vp702x_device_state *dst = adap->dev->priv;
194 u8 *buf;
131 195
132 if (onoff) 196 if (onoff)
133 st->pid_filter_state |= (1 << id); 197 st->pid_filter_state |= (1 << id);
@@ -139,32 +203,45 @@ static int vp702x_set_pid(struct dvb_usb_adapter *adap, u16 pid, u8 id, int onof
139 id = 0x10 + id*2; 203 id = 0x10 + id*2;
140 204
141 vp702x_set_pld_state(adap, st->pid_filter_state); 205 vp702x_set_pld_state(adap, st->pid_filter_state);
206
207 mutex_lock(&dst->buf_mutex);
208
209 buf = dst->buf;
210 memset(buf, 0, 16);
142 vp702x_usb_in_op(adap->dev, 0xe0, (((pid >> 8) & 0xff) << 8) | (id), 0, buf, 16); 211 vp702x_usb_in_op(adap->dev, 0xe0, (((pid >> 8) & 0xff) << 8) | (id), 0, buf, 16);
143 vp702x_usb_in_op(adap->dev, 0xe0, (((pid ) & 0xff) << 8) | (id+1), 0, buf, 16); 212 vp702x_usb_in_op(adap->dev, 0xe0, (((pid ) & 0xff) << 8) | (id+1), 0, buf, 16);
213
214 mutex_unlock(&dst->buf_mutex);
215
144 return 0; 216 return 0;
145} 217}
146 218
147 219
148static int vp702x_init_pid_filter(struct dvb_usb_adapter *adap) 220static int vp702x_init_pid_filter(struct dvb_usb_adapter *adap)
149{ 221{
150 struct vp702x_state *st = adap->priv; 222 struct vp702x_adapter_state *st = adap->priv;
223 struct vp702x_device_state *dst = adap->dev->priv;
151 int i; 224 int i;
152 u8 b[10] = { 0 }; 225 u8 *b;
153 226
154 st->pid_filter_count = 8; 227 st->pid_filter_count = 8;
155 st->pid_filter_can_bypass = 1; 228 st->pid_filter_can_bypass = 1;
156 st->pid_filter_state = 0x00; 229 st->pid_filter_state = 0x00;
157 230
158 vp702x_set_pld_mode(adap, 1); // bypass 231 vp702x_set_pld_mode(adap, 1); /* bypass */
159 232
160 for (i = 0; i < st->pid_filter_count; i++) 233 for (i = 0; i < st->pid_filter_count; i++)
161 vp702x_set_pid(adap, 0xffff, i, 1); 234 vp702x_set_pid(adap, 0xffff, i, 1);
162 235
236 mutex_lock(&dst->buf_mutex);
237 b = dst->buf;
238 memset(b, 0, 10);
163 vp702x_usb_in_op(adap->dev, 0xb5, 3, 0, b, 10); 239 vp702x_usb_in_op(adap->dev, 0xb5, 3, 0, b, 10);
164 vp702x_usb_in_op(adap->dev, 0xb5, 0, 0, b, 10); 240 vp702x_usb_in_op(adap->dev, 0xb5, 0, 0, b, 10);
165 vp702x_usb_in_op(adap->dev, 0xb5, 1, 0, b, 10); 241 vp702x_usb_in_op(adap->dev, 0xb5, 1, 0, b, 10);
242 mutex_unlock(&dst->buf_mutex);
243 /*vp702x_set_pld_mode(d, 0); // filter */
166 244
167 //vp702x_set_pld_mode(d, 0); // filter
168 return 0; 245 return 0;
169} 246}
170 247
@@ -174,7 +251,7 @@ static int vp702x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
174} 251}
175 252
176/* keys for the enclosed remote control */ 253/* keys for the enclosed remote control */
177static struct ir_scancode ir_codes_vp702x_table[] = { 254static struct rc_map_table rc_map_vp702x_table[] = {
178 { 0x0001, KEY_1 }, 255 { 0x0001, KEY_1 },
179 { 0x0002, KEY_2 }, 256 { 0x0002, KEY_2 },
180}; 257};
@@ -182,36 +259,49 @@ static struct ir_scancode ir_codes_vp702x_table[] = {
182/* remote control stuff (does not work with my box) */ 259/* remote control stuff (does not work with my box) */
183static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 260static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
184{ 261{
185 u8 key[10]; 262 u8 *key;
186 int i; 263 int i;
187 264
188/* remove the following return to enabled remote querying */ 265/* remove the following return to enabled remote querying */
189 return 0; 266 return 0;
190 267
268 key = kmalloc(10, GFP_KERNEL);
269 if (!key)
270 return -ENOMEM;
271
191 vp702x_usb_in_op(d,READ_REMOTE_REQ,0,0,key,10); 272 vp702x_usb_in_op(d,READ_REMOTE_REQ,0,0,key,10);
192 273
193 deb_rc("remote query key: %x %d\n",key[1],key[1]); 274 deb_rc("remote query key: %x %d\n",key[1],key[1]);
194 275
195 if (key[1] == 0x44) { 276 if (key[1] == 0x44) {
196 *state = REMOTE_NO_KEY_PRESSED; 277 *state = REMOTE_NO_KEY_PRESSED;
278 kfree(key);
197 return 0; 279 return 0;
198 } 280 }
199 281
200 for (i = 0; i < ARRAY_SIZE(ir_codes_vp702x_table); i++) 282 for (i = 0; i < ARRAY_SIZE(rc_map_vp702x_table); i++)
201 if (rc5_custom(&ir_codes_vp702x_table[i]) == key[1]) { 283 if (rc5_custom(&rc_map_vp702x_table[i]) == key[1]) {
202 *state = REMOTE_KEY_PRESSED; 284 *state = REMOTE_KEY_PRESSED;
203 *event = ir_codes_vp702x_table[i].keycode; 285 *event = rc_map_vp702x_table[i].keycode;
204 break; 286 break;
205 } 287 }
288 kfree(key);
206 return 0; 289 return 0;
207} 290}
208 291
209 292
210static int vp702x_read_mac_addr(struct dvb_usb_device *d,u8 mac[6]) 293static int vp702x_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
211{ 294{
212 u8 i; 295 u8 i, *buf;
296 struct vp702x_device_state *st = d->priv;
297
298 mutex_lock(&st->buf_mutex);
299 buf = st->buf;
213 for (i = 6; i < 12; i++) 300 for (i = 6; i < 12; i++)
214 vp702x_usb_in_op(d, READ_EEPROM_REQ, i, 1, &mac[i - 6], 1); 301 vp702x_usb_in_op(d, READ_EEPROM_REQ, i, 1, &buf[i - 6], 1);
302
303 memcpy(mac, buf, 6);
304 mutex_unlock(&st->buf_mutex);
215 return 0; 305 return 0;
216} 306}
217 307
@@ -221,7 +311,8 @@ static int vp702x_frontend_attach(struct dvb_usb_adapter *adap)
221 311
222 vp702x_usb_out_op(adap->dev, SET_TUNER_POWER_REQ, 0, 7, NULL, 0); 312 vp702x_usb_out_op(adap->dev, SET_TUNER_POWER_REQ, 0, 7, NULL, 0);
223 313
224 if (vp702x_usb_inout_cmd(adap->dev, GET_SYSTEM_STRING, NULL, 0, buf, 10, 10)) 314 if (vp702x_usb_inout_cmd(adap->dev, GET_SYSTEM_STRING, NULL, 0,
315 buf, 10, 10))
225 return -EIO; 316 return -EIO;
226 317
227 buf[9] = '\0'; 318 buf[9] = '\0';
@@ -240,8 +331,38 @@ static struct dvb_usb_device_properties vp702x_properties;
240static int vp702x_usb_probe(struct usb_interface *intf, 331static int vp702x_usb_probe(struct usb_interface *intf,
241 const struct usb_device_id *id) 332 const struct usb_device_id *id)
242{ 333{
243 return dvb_usb_device_init(intf, &vp702x_properties, 334 struct dvb_usb_device *d;
244 THIS_MODULE, NULL, adapter_nr); 335 struct vp702x_device_state *st;
336 int ret;
337
338 ret = dvb_usb_device_init(intf, &vp702x_properties,
339 THIS_MODULE, &d, adapter_nr);
340 if (ret)
341 goto out;
342
343 st = d->priv;
344 st->buf_len = 16;
345 st->buf = kmalloc(st->buf_len, GFP_KERNEL);
346 if (!st->buf) {
347 ret = -ENOMEM;
348 dvb_usb_device_exit(intf);
349 goto out;
350 }
351 mutex_init(&st->buf_mutex);
352
353out:
354 return ret;
355
356}
357
358static void vp702x_usb_disconnect(struct usb_interface *intf)
359{
360 struct dvb_usb_device *d = usb_get_intfdata(intf);
361 struct vp702x_device_state *st = d->priv;
362 mutex_lock(&st->buf_mutex);
363 kfree(st->buf);
364 mutex_unlock(&st->buf_mutex);
365 dvb_usb_device_exit(intf);
245} 366}
246 367
247static struct usb_device_id vp702x_usb_table [] = { 368static struct usb_device_id vp702x_usb_table [] = {
@@ -278,14 +399,14 @@ static struct dvb_usb_device_properties vp702x_properties = {
278 } 399 }
279 } 400 }
280 }, 401 },
281 .size_of_priv = sizeof(struct vp702x_state), 402 .size_of_priv = sizeof(struct vp702x_adapter_state),
282 } 403 }
283 }, 404 },
284 .read_mac_address = vp702x_read_mac_addr, 405 .read_mac_address = vp702x_read_mac_addr,
285 406
286 .rc.legacy = { 407 .rc.legacy = {
287 .rc_key_map = ir_codes_vp702x_table, 408 .rc_map_table = rc_map_vp702x_table,
288 .rc_key_map_size = ARRAY_SIZE(ir_codes_vp702x_table), 409 .rc_map_size = ARRAY_SIZE(rc_map_vp702x_table),
289 .rc_interval = 400, 410 .rc_interval = 400,
290 .rc_query = vp702x_rc_query, 411 .rc_query = vp702x_rc_query,
291 }, 412 },
@@ -307,9 +428,9 @@ static struct dvb_usb_device_properties vp702x_properties = {
307/* usb specific object needed to register this driver with the usb subsystem */ 428/* usb specific object needed to register this driver with the usb subsystem */
308static struct usb_driver vp702x_usb_driver = { 429static struct usb_driver vp702x_usb_driver = {
309 .name = "dvb_usb_vp702x", 430 .name = "dvb_usb_vp702x",
310 .probe = vp702x_usb_probe, 431 .probe = vp702x_usb_probe,
311 .disconnect = dvb_usb_device_exit, 432 .disconnect = vp702x_usb_disconnect,
312 .id_table = vp702x_usb_table, 433 .id_table = vp702x_usb_table,
313}; 434};
314 435
315/* module stuff */ 436/* module stuff */
diff --git a/drivers/media/dvb/dvb-usb/vp702x.h b/drivers/media/dvb/dvb-usb/vp702x.h
index c2f97f96c21f..20b90055e7ac 100644
--- a/drivers/media/dvb/dvb-usb/vp702x.h
+++ b/drivers/media/dvb/dvb-usb/vp702x.h
@@ -98,6 +98,13 @@ extern int dvb_usb_vp702x_debug;
98#define RESET_TUNER 0xBE 98#define RESET_TUNER 0xBE
99/* IN i: 0, v: 0, no extra buffer */ 99/* IN i: 0, v: 0, no extra buffer */
100 100
101struct vp702x_device_state {
102 struct mutex buf_mutex;
103 int buf_len;
104 u8 *buf;
105};
106
107
101extern struct dvb_frontend * vp702x_fe_attach(struct dvb_usb_device *d); 108extern struct dvb_frontend * vp702x_fe_attach(struct dvb_usb_device *d);
102 109
103extern int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int ilen, int msec); 110extern int vp702x_usb_inout_op(struct dvb_usb_device *d, u8 *o, int olen, u8 *i, int ilen, int msec);
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index f13791ca5994..3db89e3cb0bb 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -28,9 +28,9 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
28int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in, int inlen, int msec) 28int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in, int inlen, int msec)
29{ 29{
30 int ret = 0; 30 int ret = 0;
31 u8 inbuf[12] = { 0 }, outbuf[20] = { 0 }; 31 u8 *buf = d->priv;
32 32
33 outbuf[0] = cmd; 33 buf[0] = cmd;
34 34
35 if (outlen > 19) 35 if (outlen > 19)
36 outlen = 19; 36 outlen = 19;
@@ -38,19 +38,21 @@ int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in,
38 if (inlen > 11) 38 if (inlen > 11)
39 inlen = 11; 39 inlen = 11;
40 40
41 ret = mutex_lock_interruptible(&d->usb_mutex);
42 if (ret)
43 return ret;
44
41 if (out != NULL && outlen > 0) 45 if (out != NULL && outlen > 0)
42 memcpy(&outbuf[1], out, outlen); 46 memcpy(&buf[1], out, outlen);
43 47
44 deb_xfer("out buffer: "); 48 deb_xfer("out buffer: ");
45 debug_dump(outbuf,outlen+1,deb_xfer); 49 debug_dump(buf, outlen+1, deb_xfer);
46 50
47 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
48 return ret;
49 51
50 if (usb_control_msg(d->udev, 52 if (usb_control_msg(d->udev,
51 usb_sndctrlpipe(d->udev,0), 53 usb_sndctrlpipe(d->udev,0),
52 TH_COMMAND_OUT, USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0, 54 TH_COMMAND_OUT, USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0,
53 outbuf, 20, 2000) != 20) { 55 buf, 20, 2000) != 20) {
54 err("USB control message 'out' went wrong."); 56 err("USB control message 'out' went wrong.");
55 ret = -EIO; 57 ret = -EIO;
56 goto unlock; 58 goto unlock;
@@ -61,17 +63,17 @@ int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in,
61 if (usb_control_msg(d->udev, 63 if (usb_control_msg(d->udev,
62 usb_rcvctrlpipe(d->udev,0), 64 usb_rcvctrlpipe(d->udev,0),
63 TH_COMMAND_IN, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, 65 TH_COMMAND_IN, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
64 inbuf, 12, 2000) != 12) { 66 buf, 12, 2000) != 12) {
65 err("USB control message 'in' went wrong."); 67 err("USB control message 'in' went wrong.");
66 ret = -EIO; 68 ret = -EIO;
67 goto unlock; 69 goto unlock;
68 } 70 }
69 71
70 deb_xfer("in buffer: "); 72 deb_xfer("in buffer: ");
71 debug_dump(inbuf,12,deb_xfer); 73 debug_dump(buf, 12, deb_xfer);
72 74
73 if (in != NULL && inlen > 0) 75 if (in != NULL && inlen > 0)
74 memcpy(in,&inbuf[1],inlen); 76 memcpy(in, &buf[1], inlen);
75 77
76unlock: 78unlock:
77 mutex_unlock(&d->usb_mutex); 79 mutex_unlock(&d->usb_mutex);
@@ -99,7 +101,7 @@ static int vp7045_power_ctrl(struct dvb_usb_device *d, int onoff)
99 101
100/* The keymapping struct. Somehow this should be loaded to the driver, but 102/* The keymapping struct. Somehow this should be loaded to the driver, but
101 * currently it is hardcoded. */ 103 * currently it is hardcoded. */
102static struct ir_scancode ir_codes_vp7045_table[] = { 104static struct rc_map_table rc_map_vp7045_table[] = {
103 { 0x0016, KEY_POWER }, 105 { 0x0016, KEY_POWER },
104 { 0x0010, KEY_MUTE }, 106 { 0x0010, KEY_MUTE },
105 { 0x0003, KEY_1 }, 107 { 0x0003, KEY_1 },
@@ -165,10 +167,10 @@ static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
165 return 0; 167 return 0;
166 } 168 }
167 169
168 for (i = 0; i < ARRAY_SIZE(ir_codes_vp7045_table); i++) 170 for (i = 0; i < ARRAY_SIZE(rc_map_vp7045_table); i++)
169 if (rc5_data(&ir_codes_vp7045_table[i]) == key) { 171 if (rc5_data(&rc_map_vp7045_table[i]) == key) {
170 *state = REMOTE_KEY_PRESSED; 172 *state = REMOTE_KEY_PRESSED;
171 *event = ir_codes_vp7045_table[i].keycode; 173 *event = rc_map_vp7045_table[i].keycode;
172 break; 174 break;
173 } 175 }
174 return 0; 176 return 0;
@@ -222,8 +224,26 @@ static struct dvb_usb_device_properties vp7045_properties;
222static int vp7045_usb_probe(struct usb_interface *intf, 224static int vp7045_usb_probe(struct usb_interface *intf,
223 const struct usb_device_id *id) 225 const struct usb_device_id *id)
224{ 226{
225 return dvb_usb_device_init(intf, &vp7045_properties, 227 struct dvb_usb_device *d;
226 THIS_MODULE, NULL, adapter_nr); 228 int ret = dvb_usb_device_init(intf, &vp7045_properties,
229 THIS_MODULE, &d, adapter_nr);
230 if (ret)
231 return ret;
232
233 d->priv = kmalloc(20, GFP_KERNEL);
234 if (!d->priv) {
235 dvb_usb_device_exit(intf);
236 return -ENOMEM;
237 }
238
239 return ret;
240}
241
242static void vp7045_usb_disconnect(struct usb_interface *intf)
243{
244 struct dvb_usb_device *d = usb_get_intfdata(intf);
245 kfree(d->priv);
246 dvb_usb_device_exit(intf);
227} 247}
228 248
229static struct usb_device_id vp7045_usb_table [] = { 249static struct usb_device_id vp7045_usb_table [] = {
@@ -238,6 +258,7 @@ MODULE_DEVICE_TABLE(usb, vp7045_usb_table);
238static struct dvb_usb_device_properties vp7045_properties = { 258static struct dvb_usb_device_properties vp7045_properties = {
239 .usb_ctrl = CYPRESS_FX2, 259 .usb_ctrl = CYPRESS_FX2,
240 .firmware = "dvb-usb-vp7045-01.fw", 260 .firmware = "dvb-usb-vp7045-01.fw",
261 .size_of_priv = sizeof(u8 *),
241 262
242 .num_adapters = 1, 263 .num_adapters = 1,
243 .adapter = { 264 .adapter = {
@@ -261,8 +282,8 @@ static struct dvb_usb_device_properties vp7045_properties = {
261 282
262 .rc.legacy = { 283 .rc.legacy = {
263 .rc_interval = 400, 284 .rc_interval = 400,
264 .rc_key_map = ir_codes_vp7045_table, 285 .rc_map_table = rc_map_vp7045_table,
265 .rc_key_map_size = ARRAY_SIZE(ir_codes_vp7045_table), 286 .rc_map_size = ARRAY_SIZE(rc_map_vp7045_table),
266 .rc_query = vp7045_rc_query, 287 .rc_query = vp7045_rc_query,
267 }, 288 },
268 289
@@ -284,7 +305,7 @@ static struct dvb_usb_device_properties vp7045_properties = {
284static struct usb_driver vp7045_usb_driver = { 305static struct usb_driver vp7045_usb_driver = {
285 .name = "dvb_usb_vp7045", 306 .name = "dvb_usb_vp7045",
286 .probe = vp7045_usb_probe, 307 .probe = vp7045_usb_probe,
287 .disconnect = dvb_usb_device_exit, 308 .disconnect = vp7045_usb_disconnect,
288 .id_table = vp7045_usb_table, 309 .id_table = vp7045_usb_table,
289}; 310};
290 311
diff --git a/drivers/media/dvb/firewire/Kconfig b/drivers/media/dvb/firewire/Kconfig
index 4afa29256df1..f3e9448c3955 100644
--- a/drivers/media/dvb/firewire/Kconfig
+++ b/drivers/media/dvb/firewire/Kconfig
@@ -1,6 +1,6 @@
1config DVB_FIREDTV 1config DVB_FIREDTV
2 tristate "FireDTV and FloppyDTV" 2 tristate "FireDTV and FloppyDTV"
3 depends on DVB_CORE && (FIREWIRE || IEEE1394) 3 depends on DVB_CORE && FIREWIRE
4 help 4 help
5 Support for DVB receivers from Digital Everywhere 5 Support for DVB receivers from Digital Everywhere
6 which are connected via IEEE 1394 (FireWire). 6 which are connected via IEEE 1394 (FireWire).
@@ -13,12 +13,6 @@ config DVB_FIREDTV
13 13
14if DVB_FIREDTV 14if DVB_FIREDTV
15 15
16config DVB_FIREDTV_FIREWIRE
17 def_bool FIREWIRE = y || (FIREWIRE = m && DVB_FIREDTV = m)
18
19config DVB_FIREDTV_IEEE1394
20 def_bool IEEE1394 = y || (IEEE1394 = m && DVB_FIREDTV = m)
21
22config DVB_FIREDTV_INPUT 16config DVB_FIREDTV_INPUT
23 def_bool INPUT = y || (INPUT = m && DVB_FIREDTV = m) 17 def_bool INPUT = y || (INPUT = m && DVB_FIREDTV = m)
24 18
diff --git a/drivers/media/dvb/firewire/Makefile b/drivers/media/dvb/firewire/Makefile
index da84203d51c6..357b3aab186b 100644
--- a/drivers/media/dvb/firewire/Makefile
+++ b/drivers/media/dvb/firewire/Makefile
@@ -1,9 +1,6 @@
1obj-$(CONFIG_DVB_FIREDTV) += firedtv.o 1obj-$(CONFIG_DVB_FIREDTV) += firedtv.o
2 2
3firedtv-y := firedtv-avc.o firedtv-ci.o firedtv-dvb.o firedtv-fe.o 3firedtv-y := firedtv-avc.o firedtv-ci.o firedtv-dvb.o firedtv-fe.o firedtv-fw.o
4firedtv-$(CONFIG_DVB_FIREDTV_FIREWIRE) += firedtv-fw.o
5firedtv-$(CONFIG_DVB_FIREDTV_IEEE1394) += firedtv-1394.o
6firedtv-$(CONFIG_DVB_FIREDTV_INPUT) += firedtv-rc.o 4firedtv-$(CONFIG_DVB_FIREDTV_INPUT) += firedtv-rc.o
7 5
8ccflags-y += -Idrivers/media/dvb/dvb-core 6ccflags-y += -Idrivers/media/dvb/dvb-core
9ccflags-$(CONFIG_DVB_FIREDTV_IEEE1394) += -Idrivers/ieee1394
diff --git a/drivers/media/dvb/firewire/firedtv-1394.c b/drivers/media/dvb/firewire/firedtv-1394.c
deleted file mode 100644
index b34ca7afb0e6..000000000000
--- a/drivers/media/dvb/firewire/firedtv-1394.c
+++ /dev/null
@@ -1,300 +0,0 @@
1/*
2 * FireDTV driver -- ieee1394 I/O backend
3 *
4 * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
5 * Copyright (C) 2007-2008 Ben Backx <ben@bbackx.com>
6 * Copyright (C) 2008 Henrik Kurelid <henrik@kurelid.se>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 */
13
14#include <linux/device.h>
15#include <linux/errno.h>
16#include <linux/kernel.h>
17#include <linux/list.h>
18#include <linux/slab.h>
19#include <linux/spinlock.h>
20#include <linux/types.h>
21
22#include <dma.h>
23#include <csr1212.h>
24#include <highlevel.h>
25#include <hosts.h>
26#include <ieee1394.h>
27#include <iso.h>
28#include <nodemgr.h>
29
30#include <dvb_demux.h>
31
32#include "firedtv.h"
33
34static LIST_HEAD(node_list);
35static DEFINE_SPINLOCK(node_list_lock);
36
37#define CIP_HEADER_SIZE 8
38#define MPEG2_TS_HEADER_SIZE 4
39#define MPEG2_TS_SOURCE_PACKET_SIZE (4 + 188)
40
41static void rawiso_activity_cb(struct hpsb_iso *iso)
42{
43 struct firedtv *f, *fdtv = NULL;
44 unsigned int i, num, packet;
45 unsigned char *buf;
46 unsigned long flags;
47 int count;
48
49 spin_lock_irqsave(&node_list_lock, flags);
50 list_for_each_entry(f, &node_list, list)
51 if (f->backend_data == iso) {
52 fdtv = f;
53 break;
54 }
55 spin_unlock_irqrestore(&node_list_lock, flags);
56
57 packet = iso->first_packet;
58 num = hpsb_iso_n_ready(iso);
59
60 if (!fdtv) {
61 pr_err("received at unknown iso channel\n");
62 goto out;
63 }
64
65 for (i = 0; i < num; i++, packet = (packet + 1) % iso->buf_packets) {
66 buf = dma_region_i(&iso->data_buf, unsigned char,
67 iso->infos[packet].offset + CIP_HEADER_SIZE);
68 count = (iso->infos[packet].len - CIP_HEADER_SIZE) /
69 MPEG2_TS_SOURCE_PACKET_SIZE;
70
71 /* ignore empty packet */
72 if (iso->infos[packet].len <= CIP_HEADER_SIZE)
73 continue;
74
75 while (count--) {
76 if (buf[MPEG2_TS_HEADER_SIZE] == 0x47)
77 dvb_dmx_swfilter_packets(&fdtv->demux,
78 &buf[MPEG2_TS_HEADER_SIZE], 1);
79 else
80 dev_err(fdtv->device,
81 "skipping invalid packet\n");
82 buf += MPEG2_TS_SOURCE_PACKET_SIZE;
83 }
84 }
85out:
86 hpsb_iso_recv_release_packets(iso, num);
87}
88
89static inline struct node_entry *node_of(struct firedtv *fdtv)
90{
91 return container_of(fdtv->device, struct unit_directory, device)->ne;
92}
93
94static int node_lock(struct firedtv *fdtv, u64 addr, void *data)
95{
96 quadlet_t *d = data;
97 int ret;
98
99 ret = hpsb_node_lock(node_of(fdtv), addr,
100 EXTCODE_COMPARE_SWAP, &d[1], d[0]);
101 d[0] = d[1];
102
103 return ret;
104}
105
106static int node_read(struct firedtv *fdtv, u64 addr, void *data)
107{
108 return hpsb_node_read(node_of(fdtv), addr, data, 4);
109}
110
111static int node_write(struct firedtv *fdtv, u64 addr, void *data, size_t len)
112{
113 return hpsb_node_write(node_of(fdtv), addr, data, len);
114}
115
116#define FDTV_ISO_BUFFER_PACKETS 256
117#define FDTV_ISO_BUFFER_SIZE (FDTV_ISO_BUFFER_PACKETS * 200)
118
119static int start_iso(struct firedtv *fdtv)
120{
121 struct hpsb_iso *iso_handle;
122 int ret;
123
124 iso_handle = hpsb_iso_recv_init(node_of(fdtv)->host,
125 FDTV_ISO_BUFFER_SIZE, FDTV_ISO_BUFFER_PACKETS,
126 fdtv->isochannel, HPSB_ISO_DMA_DEFAULT,
127 -1, /* stat.config.irq_interval */
128 rawiso_activity_cb);
129 if (iso_handle == NULL) {
130 dev_err(fdtv->device, "cannot initialize iso receive\n");
131 return -ENOMEM;
132 }
133 fdtv->backend_data = iso_handle;
134
135 ret = hpsb_iso_recv_start(iso_handle, -1, -1, 0);
136 if (ret != 0) {
137 dev_err(fdtv->device, "cannot start iso receive\n");
138 hpsb_iso_shutdown(iso_handle);
139 fdtv->backend_data = NULL;
140 }
141 return ret;
142}
143
144static void stop_iso(struct firedtv *fdtv)
145{
146 struct hpsb_iso *iso_handle = fdtv->backend_data;
147
148 if (iso_handle != NULL) {
149 hpsb_iso_stop(iso_handle);
150 hpsb_iso_shutdown(iso_handle);
151 }
152 fdtv->backend_data = NULL;
153}
154
155static const struct firedtv_backend fdtv_1394_backend = {
156 .lock = node_lock,
157 .read = node_read,
158 .write = node_write,
159 .start_iso = start_iso,
160 .stop_iso = stop_iso,
161};
162
163static void fcp_request(struct hpsb_host *host, int nodeid, int direction,
164 int cts, u8 *data, size_t length)
165{
166 struct firedtv *f, *fdtv = NULL;
167 unsigned long flags;
168 int su;
169
170 if (length == 0 || (data[0] & 0xf0) != 0)
171 return;
172
173 su = data[1] & 0x7;
174
175 spin_lock_irqsave(&node_list_lock, flags);
176 list_for_each_entry(f, &node_list, list)
177 if (node_of(f)->host == host &&
178 node_of(f)->nodeid == nodeid &&
179 (f->subunit == su || (f->subunit == 0 && su == 0x7))) {
180 fdtv = f;
181 break;
182 }
183 spin_unlock_irqrestore(&node_list_lock, flags);
184
185 if (fdtv)
186 avc_recv(fdtv, data, length);
187}
188
189static int node_probe(struct device *dev)
190{
191 struct unit_directory *ud =
192 container_of(dev, struct unit_directory, device);
193 struct firedtv *fdtv;
194 int kv_len, err;
195 void *kv_str;
196
197 if (ud->model_name_kv) {
198 kv_len = (ud->model_name_kv->value.leaf.len - 2) * 4;
199 kv_str = CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(ud->model_name_kv);
200 } else {
201 kv_len = 0;
202 kv_str = NULL;
203 }
204 fdtv = fdtv_alloc(dev, &fdtv_1394_backend, kv_str, kv_len);
205 if (!fdtv)
206 return -ENOMEM;
207
208 /*
209 * Work around a bug in udev's path_id script: Use the fw-host's dev
210 * instead of the unit directory's dev as parent of the input device.
211 */
212 err = fdtv_register_rc(fdtv, dev->parent->parent);
213 if (err)
214 goto fail_free;
215
216 spin_lock_irq(&node_list_lock);
217 list_add_tail(&fdtv->list, &node_list);
218 spin_unlock_irq(&node_list_lock);
219
220 err = avc_identify_subunit(fdtv);
221 if (err)
222 goto fail;
223
224 err = fdtv_dvb_register(fdtv);
225 if (err)
226 goto fail;
227
228 avc_register_remote_control(fdtv);
229
230 return 0;
231fail:
232 spin_lock_irq(&node_list_lock);
233 list_del(&fdtv->list);
234 spin_unlock_irq(&node_list_lock);
235 fdtv_unregister_rc(fdtv);
236fail_free:
237 kfree(fdtv);
238
239 return err;
240}
241
242static int node_remove(struct device *dev)
243{
244 struct firedtv *fdtv = dev_get_drvdata(dev);
245
246 fdtv_dvb_unregister(fdtv);
247
248 spin_lock_irq(&node_list_lock);
249 list_del(&fdtv->list);
250 spin_unlock_irq(&node_list_lock);
251
252 fdtv_unregister_rc(fdtv);
253 kfree(fdtv);
254
255 return 0;
256}
257
258static int node_update(struct unit_directory *ud)
259{
260 struct firedtv *fdtv = dev_get_drvdata(&ud->device);
261
262 if (fdtv->isochannel >= 0)
263 cmp_establish_pp_connection(fdtv, fdtv->subunit,
264 fdtv->isochannel);
265 return 0;
266}
267
268static struct hpsb_protocol_driver fdtv_driver = {
269 .name = "firedtv",
270 .id_table = fdtv_id_table,
271 .update = node_update,
272 .driver = {
273 .probe = node_probe,
274 .remove = node_remove,
275 },
276};
277
278static struct hpsb_highlevel fdtv_highlevel = {
279 .name = "firedtv",
280 .fcp_request = fcp_request,
281};
282
283int __init fdtv_1394_init(void)
284{
285 int ret;
286
287 hpsb_register_highlevel(&fdtv_highlevel);
288 ret = hpsb_register_protocol(&fdtv_driver);
289 if (ret) {
290 printk(KERN_ERR "firedtv: failed to register protocol\n");
291 hpsb_unregister_highlevel(&fdtv_highlevel);
292 }
293 return ret;
294}
295
296void __exit fdtv_1394_exit(void)
297{
298 hpsb_unregister_protocol(&fdtv_driver);
299 hpsb_unregister_highlevel(&fdtv_highlevel);
300}
diff --git a/drivers/media/dvb/firewire/firedtv-avc.c b/drivers/media/dvb/firewire/firedtv-avc.c
index 28294af752db..21c52e3b522e 100644
--- a/drivers/media/dvb/firewire/firedtv-avc.c
+++ b/drivers/media/dvb/firewire/firedtv-avc.c
@@ -24,6 +24,8 @@
24#include <linux/wait.h> 24#include <linux/wait.h>
25#include <linux/workqueue.h> 25#include <linux/workqueue.h>
26 26
27#include <dvb_frontend.h>
28
27#include "firedtv.h" 29#include "firedtv.h"
28 30
29#define FCP_COMMAND_REGISTER 0xfffff0000b00ULL 31#define FCP_COMMAND_REGISTER 0xfffff0000b00ULL
@@ -130,6 +132,20 @@ MODULE_PARM_DESC(debug, "Verbose logging (none = 0"
130 ", FCP payloads = " __stringify(AVC_DEBUG_FCP_PAYLOADS) 132 ", FCP payloads = " __stringify(AVC_DEBUG_FCP_PAYLOADS)
131 ", or a combination, or all = -1)"); 133 ", or a combination, or all = -1)");
132 134
135/*
136 * This is a workaround since there is no vendor specific command to retrieve
137 * ca_info using AVC. If this parameter is not used, ca_system_id will be
138 * filled with application_manufacturer from ca_app_info.
139 * Digital Everywhere have said that adding ca_info is on their TODO list.
140 */
141static unsigned int num_fake_ca_system_ids;
142static int fake_ca_system_ids[4] = { -1, -1, -1, -1 };
143module_param_array(fake_ca_system_ids, int, &num_fake_ca_system_ids, 0644);
144MODULE_PARM_DESC(fake_ca_system_ids, "If your CAM application manufacturer "
145 "does not have the same ca_system_id as your CAS, you can "
146 "override what ca_system_ids are presented to the "
147 "application by setting this field to an array of ids.");
148
133static const char *debug_fcp_ctype(unsigned int ctype) 149static const char *debug_fcp_ctype(unsigned int ctype)
134{ 150{
135 static const char *ctypes[] = { 151 static const char *ctypes[] = {
@@ -225,8 +241,8 @@ static int avc_write(struct firedtv *fdtv)
225 if (unlikely(avc_debug)) 241 if (unlikely(avc_debug))
226 debug_fcp(fdtv->avc_data, fdtv->avc_data_length); 242 debug_fcp(fdtv->avc_data, fdtv->avc_data_length);
227 243
228 err = fdtv->backend->write(fdtv, FCP_COMMAND_REGISTER, 244 err = fdtv_write(fdtv, FCP_COMMAND_REGISTER,
229 fdtv->avc_data, fdtv->avc_data_length); 245 fdtv->avc_data, fdtv->avc_data_length);
230 if (err) { 246 if (err) {
231 dev_err(fdtv->device, "FCP command write failed\n"); 247 dev_err(fdtv->device, "FCP command write failed\n");
232 248
@@ -368,10 +384,30 @@ static int avc_tuner_tuneqpsk(struct firedtv *fdtv,
368 c->operand[12] = 0; 384 c->operand[12] = 0;
369 385
370 if (fdtv->type == FIREDTV_DVB_S2) { 386 if (fdtv->type == FIREDTV_DVB_S2) {
371 c->operand[13] = 0x1; 387 if (fdtv->fe.dtv_property_cache.delivery_system == SYS_DVBS2) {
372 c->operand[14] = 0xff; 388 switch (fdtv->fe.dtv_property_cache.modulation) {
373 c->operand[15] = 0xff; 389 case QAM_16: c->operand[13] = 0x1; break;
374 390 case QPSK: c->operand[13] = 0x2; break;
391 case PSK_8: c->operand[13] = 0x3; break;
392 default: c->operand[13] = 0x2; break;
393 }
394 switch (fdtv->fe.dtv_property_cache.rolloff) {
395 case ROLLOFF_AUTO: c->operand[14] = 0x2; break;
396 case ROLLOFF_35: c->operand[14] = 0x2; break;
397 case ROLLOFF_20: c->operand[14] = 0x0; break;
398 case ROLLOFF_25: c->operand[14] = 0x1; break;
399 /* case ROLLOFF_NONE: c->operand[14] = 0xff; break; */
400 }
401 switch (fdtv->fe.dtv_property_cache.pilot) {
402 case PILOT_AUTO: c->operand[15] = 0x0; break;
403 case PILOT_OFF: c->operand[15] = 0x0; break;
404 case PILOT_ON: c->operand[15] = 0x1; break;
405 }
406 } else {
407 c->operand[13] = 0x1; /* auto modulation */
408 c->operand[14] = 0xff; /* disable rolloff */
409 c->operand[15] = 0xff; /* disable pilot */
410 }
375 return 16; 411 return 16;
376 } else { 412 } else {
377 return 13; 413 return 13;
@@ -977,7 +1013,7 @@ int avc_ca_info(struct firedtv *fdtv, char *app_info, unsigned int *len)
977{ 1013{
978 struct avc_command_frame *c = (void *)fdtv->avc_data; 1014 struct avc_command_frame *c = (void *)fdtv->avc_data;
979 struct avc_response_frame *r = (void *)fdtv->avc_data; 1015 struct avc_response_frame *r = (void *)fdtv->avc_data;
980 int pos, ret; 1016 int i, pos, ret;
981 1017
982 mutex_lock(&fdtv->avc_mutex); 1018 mutex_lock(&fdtv->avc_mutex);
983 1019
@@ -1004,9 +1040,18 @@ int avc_ca_info(struct firedtv *fdtv, char *app_info, unsigned int *len)
1004 app_info[0] = (EN50221_TAG_CA_INFO >> 16) & 0xff; 1040 app_info[0] = (EN50221_TAG_CA_INFO >> 16) & 0xff;
1005 app_info[1] = (EN50221_TAG_CA_INFO >> 8) & 0xff; 1041 app_info[1] = (EN50221_TAG_CA_INFO >> 8) & 0xff;
1006 app_info[2] = (EN50221_TAG_CA_INFO >> 0) & 0xff; 1042 app_info[2] = (EN50221_TAG_CA_INFO >> 0) & 0xff;
1007 app_info[3] = 2; 1043 if (num_fake_ca_system_ids == 0) {
1008 app_info[4] = r->operand[pos + 0]; 1044 app_info[3] = 2;
1009 app_info[5] = r->operand[pos + 1]; 1045 app_info[4] = r->operand[pos + 0];
1046 app_info[5] = r->operand[pos + 1];
1047 } else {
1048 app_info[3] = num_fake_ca_system_ids * 2;
1049 for (i = 0; i < num_fake_ca_system_ids; i++) {
1050 app_info[4 + i * 2] =
1051 (fake_ca_system_ids[i] >> 8) & 0xff;
1052 app_info[5 + i * 2] = fake_ca_system_ids[i] & 0xff;
1053 }
1054 }
1010 *len = app_info[3] + 4; 1055 *len = app_info[3] + 4;
1011out: 1056out:
1012 mutex_unlock(&fdtv->avc_mutex); 1057 mutex_unlock(&fdtv->avc_mutex);
@@ -1275,14 +1320,10 @@ static int cmp_read(struct firedtv *fdtv, u64 addr, __be32 *data)
1275{ 1320{
1276 int ret; 1321 int ret;
1277 1322
1278 mutex_lock(&fdtv->avc_mutex); 1323 ret = fdtv_read(fdtv, addr, data);
1279
1280 ret = fdtv->backend->read(fdtv, addr, data);
1281 if (ret < 0) 1324 if (ret < 0)
1282 dev_err(fdtv->device, "CMP: read I/O error\n"); 1325 dev_err(fdtv->device, "CMP: read I/O error\n");
1283 1326
1284 mutex_unlock(&fdtv->avc_mutex);
1285
1286 return ret; 1327 return ret;
1287} 1328}
1288 1329
@@ -1290,18 +1331,9 @@ static int cmp_lock(struct firedtv *fdtv, u64 addr, __be32 data[])
1290{ 1331{
1291 int ret; 1332 int ret;
1292 1333
1293 mutex_lock(&fdtv->avc_mutex); 1334 ret = fdtv_lock(fdtv, addr, data);
1294
1295 /* data[] is stack-allocated and should not be DMA-mapped. */
1296 memcpy(fdtv->avc_data, data, 8);
1297
1298 ret = fdtv->backend->lock(fdtv, addr, fdtv->avc_data);
1299 if (ret < 0) 1335 if (ret < 0)
1300 dev_err(fdtv->device, "CMP: lock I/O error\n"); 1336 dev_err(fdtv->device, "CMP: lock I/O error\n");
1301 else
1302 memcpy(data, fdtv->avc_data, 8);
1303
1304 mutex_unlock(&fdtv->avc_mutex);
1305 1337
1306 return ret; 1338 return ret;
1307} 1339}
@@ -1360,10 +1392,7 @@ repeat:
1360 /* FIXME: this is for the worst case - optimize */ 1392 /* FIXME: this is for the worst case - optimize */
1361 set_opcr_overhead_id(opcr, 0); 1393 set_opcr_overhead_id(opcr, 0);
1362 1394
1363 /* 1395 /* FIXME: allocate isochronous channel and bandwidth at IRM */
1364 * FIXME: allocate isochronous channel and bandwidth at IRM
1365 * fdtv->backend->alloc_resources(fdtv, channels_mask, bw);
1366 */
1367 } 1396 }
1368 1397
1369 set_opcr_p2p_connections(opcr, get_opcr_p2p_connections(*opcr) + 1); 1398 set_opcr_p2p_connections(opcr, get_opcr_p2p_connections(*opcr) + 1);
@@ -1379,8 +1408,6 @@ repeat:
1379 /* 1408 /*
1380 * FIXME: if old_opcr.P2P_Connections > 0, 1409 * FIXME: if old_opcr.P2P_Connections > 0,
1381 * deallocate isochronous channel and bandwidth at IRM 1410 * deallocate isochronous channel and bandwidth at IRM
1382 * if (...)
1383 * fdtv->backend->dealloc_resources(fdtv, channel, bw);
1384 */ 1411 */
1385 1412
1386 if (++attempts < 6) /* arbitrary limit */ 1413 if (++attempts < 6) /* arbitrary limit */
diff --git a/drivers/media/dvb/firewire/firedtv-ci.c b/drivers/media/dvb/firewire/firedtv-ci.c
index d3c2cf60de76..8ffb565f0704 100644
--- a/drivers/media/dvb/firewire/firedtv-ci.c
+++ b/drivers/media/dvb/firewire/firedtv-ci.c
@@ -220,6 +220,7 @@ static const struct file_operations fdtv_ca_fops = {
220 .open = dvb_generic_open, 220 .open = dvb_generic_open,
221 .release = dvb_generic_release, 221 .release = dvb_generic_release,
222 .poll = fdtv_ca_io_poll, 222 .poll = fdtv_ca_io_poll,
223 .llseek = noop_llseek,
223}; 224};
224 225
225static struct dvb_device fdtv_ca = { 226static struct dvb_device fdtv_ca = {
diff --git a/drivers/media/dvb/firewire/firedtv-dvb.c b/drivers/media/dvb/firewire/firedtv-dvb.c
index 079e8c5b0475..fd8bbbfa5c59 100644
--- a/drivers/media/dvb/firewire/firedtv-dvb.c
+++ b/drivers/media/dvb/firewire/firedtv-dvb.c
@@ -14,14 +14,9 @@
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/mod_devicetable.h>
18#include <linux/module.h> 17#include <linux/module.h>
19#include <linux/mutex.h> 18#include <linux/mutex.h>
20#include <linux/slab.h>
21#include <linux/string.h>
22#include <linux/types.h> 19#include <linux/types.h>
23#include <linux/wait.h>
24#include <linux/workqueue.h>
25 20
26#include <dmxdev.h> 21#include <dmxdev.h>
27#include <dvb_demux.h> 22#include <dvb_demux.h>
@@ -166,11 +161,11 @@ int fdtv_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
166 161
167DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 162DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
168 163
169int fdtv_dvb_register(struct firedtv *fdtv) 164int fdtv_dvb_register(struct firedtv *fdtv, const char *name)
170{ 165{
171 int err; 166 int err;
172 167
173 err = dvb_register_adapter(&fdtv->adapter, fdtv_model_names[fdtv->type], 168 err = dvb_register_adapter(&fdtv->adapter, name,
174 THIS_MODULE, fdtv->device, adapter_nr); 169 THIS_MODULE, fdtv->device, adapter_nr);
175 if (err < 0) 170 if (err < 0)
176 goto fail_log; 171 goto fail_log;
@@ -210,7 +205,7 @@ int fdtv_dvb_register(struct firedtv *fdtv)
210 205
211 dvb_net_init(&fdtv->adapter, &fdtv->dvbnet, &fdtv->demux.dmx); 206 dvb_net_init(&fdtv->adapter, &fdtv->dvbnet, &fdtv->demux.dmx);
212 207
213 fdtv_frontend_init(fdtv); 208 fdtv_frontend_init(fdtv, name);
214 err = dvb_register_frontend(&fdtv->adapter, &fdtv->fe); 209 err = dvb_register_frontend(&fdtv->adapter, &fdtv->fe);
215 if (err) 210 if (err)
216 goto fail_net_release; 211 goto fail_net_release;
@@ -248,127 +243,3 @@ void fdtv_dvb_unregister(struct firedtv *fdtv)
248 dvb_dmx_release(&fdtv->demux); 243 dvb_dmx_release(&fdtv->demux);
249 dvb_unregister_adapter(&fdtv->adapter); 244 dvb_unregister_adapter(&fdtv->adapter);
250} 245}
251
252const char *fdtv_model_names[] = {
253 [FIREDTV_UNKNOWN] = "unknown type",
254 [FIREDTV_DVB_S] = "FireDTV S/CI",
255 [FIREDTV_DVB_C] = "FireDTV C/CI",
256 [FIREDTV_DVB_T] = "FireDTV T/CI",
257 [FIREDTV_DVB_S2] = "FireDTV S2 ",
258};
259
260struct firedtv *fdtv_alloc(struct device *dev,
261 const struct firedtv_backend *backend,
262 const char *name, size_t name_len)
263{
264 struct firedtv *fdtv;
265 int i;
266
267 fdtv = kzalloc(sizeof(*fdtv), GFP_KERNEL);
268 if (!fdtv)
269 return NULL;
270
271 dev_set_drvdata(dev, fdtv);
272 fdtv->device = dev;
273 fdtv->isochannel = -1;
274 fdtv->voltage = 0xff;
275 fdtv->tone = 0xff;
276 fdtv->backend = backend;
277
278 mutex_init(&fdtv->avc_mutex);
279 init_waitqueue_head(&fdtv->avc_wait);
280 mutex_init(&fdtv->demux_mutex);
281 INIT_WORK(&fdtv->remote_ctrl_work, avc_remote_ctrl_work);
282
283 for (i = ARRAY_SIZE(fdtv_model_names); --i; )
284 if (strlen(fdtv_model_names[i]) <= name_len &&
285 strncmp(name, fdtv_model_names[i], name_len) == 0)
286 break;
287 fdtv->type = i;
288
289 return fdtv;
290}
291
292#define MATCH_FLAGS (IEEE1394_MATCH_VENDOR_ID | IEEE1394_MATCH_MODEL_ID | \
293 IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION)
294
295#define DIGITAL_EVERYWHERE_OUI 0x001287
296#define AVC_UNIT_SPEC_ID_ENTRY 0x00a02d
297#define AVC_SW_VERSION_ENTRY 0x010001
298
299const struct ieee1394_device_id fdtv_id_table[] = {
300 {
301 /* FloppyDTV S/CI and FloppyDTV S2 */
302 .match_flags = MATCH_FLAGS,
303 .vendor_id = DIGITAL_EVERYWHERE_OUI,
304 .model_id = 0x000024,
305 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
306 .version = AVC_SW_VERSION_ENTRY,
307 }, {
308 /* FloppyDTV T/CI */
309 .match_flags = MATCH_FLAGS,
310 .vendor_id = DIGITAL_EVERYWHERE_OUI,
311 .model_id = 0x000025,
312 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
313 .version = AVC_SW_VERSION_ENTRY,
314 }, {
315 /* FloppyDTV C/CI */
316 .match_flags = MATCH_FLAGS,
317 .vendor_id = DIGITAL_EVERYWHERE_OUI,
318 .model_id = 0x000026,
319 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
320 .version = AVC_SW_VERSION_ENTRY,
321 }, {
322 /* FireDTV S/CI and FloppyDTV S2 */
323 .match_flags = MATCH_FLAGS,
324 .vendor_id = DIGITAL_EVERYWHERE_OUI,
325 .model_id = 0x000034,
326 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
327 .version = AVC_SW_VERSION_ENTRY,
328 }, {
329 /* FireDTV T/CI */
330 .match_flags = MATCH_FLAGS,
331 .vendor_id = DIGITAL_EVERYWHERE_OUI,
332 .model_id = 0x000035,
333 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
334 .version = AVC_SW_VERSION_ENTRY,
335 }, {
336 /* FireDTV C/CI */
337 .match_flags = MATCH_FLAGS,
338 .vendor_id = DIGITAL_EVERYWHERE_OUI,
339 .model_id = 0x000036,
340 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
341 .version = AVC_SW_VERSION_ENTRY,
342 }, {}
343};
344MODULE_DEVICE_TABLE(ieee1394, fdtv_id_table);
345
346static int __init fdtv_init(void)
347{
348 int ret;
349
350 ret = fdtv_fw_init();
351 if (ret < 0)
352 return ret;
353
354 ret = fdtv_1394_init();
355 if (ret < 0)
356 fdtv_fw_exit();
357
358 return ret;
359}
360
361static void __exit fdtv_exit(void)
362{
363 fdtv_1394_exit();
364 fdtv_fw_exit();
365}
366
367module_init(fdtv_init);
368module_exit(fdtv_exit);
369
370MODULE_AUTHOR("Andreas Monitzer <andy@monitzer.com>");
371MODULE_AUTHOR("Ben Backx <ben@bbackx.com>");
372MODULE_DESCRIPTION("FireDTV DVB Driver");
373MODULE_LICENSE("GPL");
374MODULE_SUPPORTED_DEVICE("FireDTV DVB");
diff --git a/drivers/media/dvb/firewire/firedtv-fe.c b/drivers/media/dvb/firewire/firedtv-fe.c
index e49cdc88b0c7..8748a61be73d 100644
--- a/drivers/media/dvb/firewire/firedtv-fe.c
+++ b/drivers/media/dvb/firewire/firedtv-fe.c
@@ -36,14 +36,14 @@ static int fdtv_dvb_init(struct dvb_frontend *fe)
36 return err; 36 return err;
37 } 37 }
38 38
39 return fdtv->backend->start_iso(fdtv); 39 return fdtv_start_iso(fdtv);
40} 40}
41 41
42static int fdtv_sleep(struct dvb_frontend *fe) 42static int fdtv_sleep(struct dvb_frontend *fe)
43{ 43{
44 struct firedtv *fdtv = fe->sec_priv; 44 struct firedtv *fdtv = fe->sec_priv;
45 45
46 fdtv->backend->stop_iso(fdtv); 46 fdtv_stop_iso(fdtv);
47 cmp_break_pp_connection(fdtv, fdtv->subunit, fdtv->isochannel); 47 cmp_break_pp_connection(fdtv, fdtv->subunit, fdtv->isochannel);
48 fdtv->isochannel = -1; 48 fdtv->isochannel = -1;
49 return 0; 49 return 0;
@@ -155,7 +155,17 @@ static int fdtv_get_frontend(struct dvb_frontend *fe,
155 return -EOPNOTSUPP; 155 return -EOPNOTSUPP;
156} 156}
157 157
158void fdtv_frontend_init(struct firedtv *fdtv) 158static int fdtv_get_property(struct dvb_frontend *fe, struct dtv_property *tvp)
159{
160 return 0;
161}
162
163static int fdtv_set_property(struct dvb_frontend *fe, struct dtv_property *tvp)
164{
165 return 0;
166}
167
168void fdtv_frontend_init(struct firedtv *fdtv, const char *name)
159{ 169{
160 struct dvb_frontend_ops *ops = &fdtv->fe.ops; 170 struct dvb_frontend_ops *ops = &fdtv->fe.ops;
161 struct dvb_frontend_info *fi = &ops->info; 171 struct dvb_frontend_info *fi = &ops->info;
@@ -166,6 +176,9 @@ void fdtv_frontend_init(struct firedtv *fdtv)
166 ops->set_frontend = fdtv_set_frontend; 176 ops->set_frontend = fdtv_set_frontend;
167 ops->get_frontend = fdtv_get_frontend; 177 ops->get_frontend = fdtv_get_frontend;
168 178
179 ops->get_property = fdtv_get_property;
180 ops->set_property = fdtv_set_property;
181
169 ops->read_status = fdtv_read_status; 182 ops->read_status = fdtv_read_status;
170 ops->read_ber = fdtv_read_ber; 183 ops->read_ber = fdtv_read_ber;
171 ops->read_signal_strength = fdtv_read_signal_strength; 184 ops->read_signal_strength = fdtv_read_signal_strength;
@@ -179,7 +192,6 @@ void fdtv_frontend_init(struct firedtv *fdtv)
179 192
180 switch (fdtv->type) { 193 switch (fdtv->type) {
181 case FIREDTV_DVB_S: 194 case FIREDTV_DVB_S:
182 case FIREDTV_DVB_S2:
183 fi->type = FE_QPSK; 195 fi->type = FE_QPSK;
184 196
185 fi->frequency_min = 950000; 197 fi->frequency_min = 950000;
@@ -188,7 +200,7 @@ void fdtv_frontend_init(struct firedtv *fdtv)
188 fi->symbol_rate_min = 1000000; 200 fi->symbol_rate_min = 1000000;
189 fi->symbol_rate_max = 40000000; 201 fi->symbol_rate_max = 40000000;
190 202
191 fi->caps = FE_CAN_INVERSION_AUTO | 203 fi->caps = FE_CAN_INVERSION_AUTO |
192 FE_CAN_FEC_1_2 | 204 FE_CAN_FEC_1_2 |
193 FE_CAN_FEC_2_3 | 205 FE_CAN_FEC_2_3 |
194 FE_CAN_FEC_3_4 | 206 FE_CAN_FEC_3_4 |
@@ -198,6 +210,26 @@ void fdtv_frontend_init(struct firedtv *fdtv)
198 FE_CAN_QPSK; 210 FE_CAN_QPSK;
199 break; 211 break;
200 212
213 case FIREDTV_DVB_S2:
214 fi->type = FE_QPSK;
215
216 fi->frequency_min = 950000;
217 fi->frequency_max = 2150000;
218 fi->frequency_stepsize = 125;
219 fi->symbol_rate_min = 1000000;
220 fi->symbol_rate_max = 40000000;
221
222 fi->caps = FE_CAN_INVERSION_AUTO |
223 FE_CAN_FEC_1_2 |
224 FE_CAN_FEC_2_3 |
225 FE_CAN_FEC_3_4 |
226 FE_CAN_FEC_5_6 |
227 FE_CAN_FEC_7_8 |
228 FE_CAN_FEC_AUTO |
229 FE_CAN_QPSK |
230 FE_CAN_2G_MODULATION;
231 break;
232
201 case FIREDTV_DVB_C: 233 case FIREDTV_DVB_C:
202 fi->type = FE_QAM; 234 fi->type = FE_QAM;
203 235
@@ -234,7 +266,7 @@ void fdtv_frontend_init(struct firedtv *fdtv)
234 dev_err(fdtv->device, "no frontend for model type %d\n", 266 dev_err(fdtv->device, "no frontend for model type %d\n",
235 fdtv->type); 267 fdtv->type);
236 } 268 }
237 strcpy(fi->name, fdtv_model_names[fdtv->type]); 269 strcpy(fi->name, name);
238 270
239 fdtv->fe.dvb = &fdtv->adapter; 271 fdtv->fe.dvb = &fdtv->adapter;
240 fdtv->fe.sec_priv = fdtv; 272 fdtv->fe.sec_priv = fdtv;
diff --git a/drivers/media/dvb/firewire/firedtv-fw.c b/drivers/media/dvb/firewire/firedtv-fw.c
index 7424b0493f9d..864b6274c729 100644
--- a/drivers/media/dvb/firewire/firedtv-fw.c
+++ b/drivers/media/dvb/firewire/firedtv-fw.c
@@ -9,11 +9,18 @@
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/list.h> 10#include <linux/list.h>
11#include <linux/mm.h> 11#include <linux/mm.h>
12#include <linux/mod_devicetable.h>
13#include <linux/module.h>
14#include <linux/mutex.h>
12#include <linux/slab.h> 15#include <linux/slab.h>
13#include <linux/spinlock.h> 16#include <linux/spinlock.h>
17#include <linux/string.h>
14#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/wait.h>
20#include <linux/workqueue.h>
15 21
16#include <asm/page.h> 22#include <asm/page.h>
23#include <asm/system.h>
17 24
18#include <dvb_demux.h> 25#include <dvb_demux.h>
19 26
@@ -41,17 +48,17 @@ static int node_req(struct firedtv *fdtv, u64 addr, void *data, size_t len,
41 return rcode != RCODE_COMPLETE ? -EIO : 0; 48 return rcode != RCODE_COMPLETE ? -EIO : 0;
42} 49}
43 50
44static int node_lock(struct firedtv *fdtv, u64 addr, void *data) 51int fdtv_lock(struct firedtv *fdtv, u64 addr, void *data)
45{ 52{
46 return node_req(fdtv, addr, data, 8, TCODE_LOCK_COMPARE_SWAP); 53 return node_req(fdtv, addr, data, 8, TCODE_LOCK_COMPARE_SWAP);
47} 54}
48 55
49static int node_read(struct firedtv *fdtv, u64 addr, void *data) 56int fdtv_read(struct firedtv *fdtv, u64 addr, void *data)
50{ 57{
51 return node_req(fdtv, addr, data, 4, TCODE_READ_QUADLET_REQUEST); 58 return node_req(fdtv, addr, data, 4, TCODE_READ_QUADLET_REQUEST);
52} 59}
53 60
54static int node_write(struct firedtv *fdtv, u64 addr, void *data, size_t len) 61int fdtv_write(struct firedtv *fdtv, u64 addr, void *data, size_t len)
55{ 62{
56 return node_req(fdtv, addr, data, len, TCODE_WRITE_BLOCK_REQUEST); 63 return node_req(fdtv, addr, data, len, TCODE_WRITE_BLOCK_REQUEST);
57} 64}
@@ -67,7 +74,7 @@ static int node_write(struct firedtv *fdtv, u64 addr, void *data, size_t len)
67#define N_PAGES DIV_ROUND_UP(N_PACKETS, PACKETS_PER_PAGE) 74#define N_PAGES DIV_ROUND_UP(N_PACKETS, PACKETS_PER_PAGE)
68#define IRQ_INTERVAL 16 75#define IRQ_INTERVAL 16
69 76
70struct firedtv_receive_context { 77struct fdtv_ir_context {
71 struct fw_iso_context *context; 78 struct fw_iso_context *context;
72 struct fw_iso_buffer buffer; 79 struct fw_iso_buffer buffer;
73 int interrupt_packet; 80 int interrupt_packet;
@@ -75,7 +82,7 @@ struct firedtv_receive_context {
75 char *pages[N_PAGES]; 82 char *pages[N_PAGES];
76}; 83};
77 84
78static int queue_iso(struct firedtv_receive_context *ctx, int index) 85static int queue_iso(struct fdtv_ir_context *ctx, int index)
79{ 86{
80 struct fw_iso_packet p; 87 struct fw_iso_packet p;
81 88
@@ -92,7 +99,7 @@ static void handle_iso(struct fw_iso_context *context, u32 cycle,
92 size_t header_length, void *header, void *data) 99 size_t header_length, void *header, void *data)
93{ 100{
94 struct firedtv *fdtv = data; 101 struct firedtv *fdtv = data;
95 struct firedtv_receive_context *ctx = fdtv->backend_data; 102 struct fdtv_ir_context *ctx = fdtv->ir_context;
96 __be32 *h, *h_end; 103 __be32 *h, *h_end;
97 int length, err, i = ctx->current_packet; 104 int length, err, i = ctx->current_packet;
98 char *p, *p_end; 105 char *p, *p_end;
@@ -118,12 +125,13 @@ static void handle_iso(struct fw_iso_context *context, u32 cycle,
118 125
119 i = (i + 1) & (N_PACKETS - 1); 126 i = (i + 1) & (N_PACKETS - 1);
120 } 127 }
128 fw_iso_context_queue_flush(ctx->context);
121 ctx->current_packet = i; 129 ctx->current_packet = i;
122} 130}
123 131
124static int start_iso(struct firedtv *fdtv) 132int fdtv_start_iso(struct firedtv *fdtv)
125{ 133{
126 struct firedtv_receive_context *ctx; 134 struct fdtv_ir_context *ctx;
127 struct fw_device *device = device_of(fdtv); 135 struct fw_device *device = device_of(fdtv);
128 int i, err; 136 int i, err;
129 137
@@ -161,7 +169,7 @@ static int start_iso(struct firedtv *fdtv)
161 if (err) 169 if (err)
162 goto fail; 170 goto fail;
163 171
164 fdtv->backend_data = ctx; 172 fdtv->ir_context = ctx;
165 173
166 return 0; 174 return 0;
167fail: 175fail:
@@ -174,9 +182,9 @@ fail_free:
174 return err; 182 return err;
175} 183}
176 184
177static void stop_iso(struct firedtv *fdtv) 185void fdtv_stop_iso(struct firedtv *fdtv)
178{ 186{
179 struct firedtv_receive_context *ctx = fdtv->backend_data; 187 struct fdtv_ir_context *ctx = fdtv->ir_context;
180 188
181 fw_iso_context_stop(ctx->context); 189 fw_iso_context_stop(ctx->context);
182 fw_iso_buffer_destroy(&ctx->buffer, device_of(fdtv)->card); 190 fw_iso_buffer_destroy(&ctx->buffer, device_of(fdtv)->card);
@@ -184,14 +192,6 @@ static void stop_iso(struct firedtv *fdtv)
184 kfree(ctx); 192 kfree(ctx);
185} 193}
186 194
187static const struct firedtv_backend backend = {
188 .lock = node_lock,
189 .read = node_read,
190 .write = node_write,
191 .start_iso = start_iso,
192 .stop_iso = stop_iso,
193};
194
195static void handle_fcp(struct fw_card *card, struct fw_request *request, 195static void handle_fcp(struct fw_card *card, struct fw_request *request,
196 int tcode, int destination, int source, int generation, 196 int tcode, int destination, int source, int generation,
197 unsigned long long offset, void *payload, size_t length, 197 unsigned long long offset, void *payload, size_t length,
@@ -238,6 +238,14 @@ static const struct fw_address_region fcp_region = {
238 .end = CSR_REGISTER_BASE + CSR_FCP_END, 238 .end = CSR_REGISTER_BASE + CSR_FCP_END,
239}; 239};
240 240
241static const char * const model_names[] = {
242 [FIREDTV_UNKNOWN] = "unknown type",
243 [FIREDTV_DVB_S] = "FireDTV S/CI",
244 [FIREDTV_DVB_C] = "FireDTV C/CI",
245 [FIREDTV_DVB_T] = "FireDTV T/CI",
246 [FIREDTV_DVB_S2] = "FireDTV S2 ",
247};
248
241/* Adjust the template string if models with longer names appear. */ 249/* Adjust the template string if models with longer names appear. */
242#define MAX_MODEL_NAME_LEN sizeof("FireDTV ????") 250#define MAX_MODEL_NAME_LEN sizeof("FireDTV ????")
243 251
@@ -245,15 +253,31 @@ static int node_probe(struct device *dev)
245{ 253{
246 struct firedtv *fdtv; 254 struct firedtv *fdtv;
247 char name[MAX_MODEL_NAME_LEN]; 255 char name[MAX_MODEL_NAME_LEN];
248 int name_len, err; 256 int name_len, i, err;
249
250 name_len = fw_csr_string(fw_unit(dev)->directory, CSR_MODEL,
251 name, sizeof(name));
252 257
253 fdtv = fdtv_alloc(dev, &backend, name, name_len >= 0 ? name_len : 0); 258 fdtv = kzalloc(sizeof(*fdtv), GFP_KERNEL);
254 if (!fdtv) 259 if (!fdtv)
255 return -ENOMEM; 260 return -ENOMEM;
256 261
262 dev_set_drvdata(dev, fdtv);
263 fdtv->device = dev;
264 fdtv->isochannel = -1;
265 fdtv->voltage = 0xff;
266 fdtv->tone = 0xff;
267
268 mutex_init(&fdtv->avc_mutex);
269 init_waitqueue_head(&fdtv->avc_wait);
270 mutex_init(&fdtv->demux_mutex);
271 INIT_WORK(&fdtv->remote_ctrl_work, avc_remote_ctrl_work);
272
273 name_len = fw_csr_string(fw_unit(dev)->directory, CSR_MODEL,
274 name, sizeof(name));
275 for (i = ARRAY_SIZE(model_names); --i; )
276 if (strlen(model_names[i]) <= name_len &&
277 strncmp(name, model_names[i], name_len) == 0)
278 break;
279 fdtv->type = i;
280
257 err = fdtv_register_rc(fdtv, dev); 281 err = fdtv_register_rc(fdtv, dev);
258 if (err) 282 if (err)
259 goto fail_free; 283 goto fail_free;
@@ -266,7 +290,7 @@ static int node_probe(struct device *dev)
266 if (err) 290 if (err)
267 goto fail; 291 goto fail;
268 292
269 err = fdtv_dvb_register(fdtv); 293 err = fdtv_dvb_register(fdtv, model_names[fdtv->type]);
270 if (err) 294 if (err)
271 goto fail; 295 goto fail;
272 296
@@ -309,6 +333,60 @@ static void node_update(struct fw_unit *unit)
309 fdtv->isochannel); 333 fdtv->isochannel);
310} 334}
311 335
336#define MATCH_FLAGS (IEEE1394_MATCH_VENDOR_ID | IEEE1394_MATCH_MODEL_ID | \
337 IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION)
338
339#define DIGITAL_EVERYWHERE_OUI 0x001287
340#define AVC_UNIT_SPEC_ID_ENTRY 0x00a02d
341#define AVC_SW_VERSION_ENTRY 0x010001
342
343static const struct ieee1394_device_id fdtv_id_table[] = {
344 {
345 /* FloppyDTV S/CI and FloppyDTV S2 */
346 .match_flags = MATCH_FLAGS,
347 .vendor_id = DIGITAL_EVERYWHERE_OUI,
348 .model_id = 0x000024,
349 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
350 .version = AVC_SW_VERSION_ENTRY,
351 }, {
352 /* FloppyDTV T/CI */
353 .match_flags = MATCH_FLAGS,
354 .vendor_id = DIGITAL_EVERYWHERE_OUI,
355 .model_id = 0x000025,
356 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
357 .version = AVC_SW_VERSION_ENTRY,
358 }, {
359 /* FloppyDTV C/CI */
360 .match_flags = MATCH_FLAGS,
361 .vendor_id = DIGITAL_EVERYWHERE_OUI,
362 .model_id = 0x000026,
363 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
364 .version = AVC_SW_VERSION_ENTRY,
365 }, {
366 /* FireDTV S/CI and FloppyDTV S2 */
367 .match_flags = MATCH_FLAGS,
368 .vendor_id = DIGITAL_EVERYWHERE_OUI,
369 .model_id = 0x000034,
370 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
371 .version = AVC_SW_VERSION_ENTRY,
372 }, {
373 /* FireDTV T/CI */
374 .match_flags = MATCH_FLAGS,
375 .vendor_id = DIGITAL_EVERYWHERE_OUI,
376 .model_id = 0x000035,
377 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
378 .version = AVC_SW_VERSION_ENTRY,
379 }, {
380 /* FireDTV C/CI */
381 .match_flags = MATCH_FLAGS,
382 .vendor_id = DIGITAL_EVERYWHERE_OUI,
383 .model_id = 0x000036,
384 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY,
385 .version = AVC_SW_VERSION_ENTRY,
386 }, {}
387};
388MODULE_DEVICE_TABLE(ieee1394, fdtv_id_table);
389
312static struct fw_driver fdtv_driver = { 390static struct fw_driver fdtv_driver = {
313 .driver = { 391 .driver = {
314 .owner = THIS_MODULE, 392 .owner = THIS_MODULE,
@@ -321,7 +399,7 @@ static struct fw_driver fdtv_driver = {
321 .id_table = fdtv_id_table, 399 .id_table = fdtv_id_table,
322}; 400};
323 401
324int __init fdtv_fw_init(void) 402static int __init fdtv_init(void)
325{ 403{
326 int ret; 404 int ret;
327 405
@@ -329,11 +407,24 @@ int __init fdtv_fw_init(void)
329 if (ret < 0) 407 if (ret < 0)
330 return ret; 408 return ret;
331 409
332 return driver_register(&fdtv_driver.driver); 410 ret = driver_register(&fdtv_driver.driver);
411 if (ret < 0)
412 fw_core_remove_address_handler(&fcp_handler);
413
414 return ret;
333} 415}
334 416
335void fdtv_fw_exit(void) 417static void __exit fdtv_exit(void)
336{ 418{
337 driver_unregister(&fdtv_driver.driver); 419 driver_unregister(&fdtv_driver.driver);
338 fw_core_remove_address_handler(&fcp_handler); 420 fw_core_remove_address_handler(&fcp_handler);
339} 421}
422
423module_init(fdtv_init);
424module_exit(fdtv_exit);
425
426MODULE_AUTHOR("Andreas Monitzer <andy@monitzer.com>");
427MODULE_AUTHOR("Ben Backx <ben@bbackx.com>");
428MODULE_DESCRIPTION("FireDTV DVB Driver");
429MODULE_LICENSE("GPL");
430MODULE_SUPPORTED_DEVICE("FireDTV DVB");
diff --git a/drivers/media/dvb/firewire/firedtv-rc.c b/drivers/media/dvb/firewire/firedtv-rc.c
index fcf3828472b8..f82d4a93feb3 100644
--- a/drivers/media/dvb/firewire/firedtv-rc.c
+++ b/drivers/media/dvb/firewire/firedtv-rc.c
@@ -172,7 +172,8 @@ void fdtv_unregister_rc(struct firedtv *fdtv)
172 172
173void fdtv_handle_rc(struct firedtv *fdtv, unsigned int code) 173void fdtv_handle_rc(struct firedtv *fdtv, unsigned int code)
174{ 174{
175 u16 *keycode = fdtv->remote_ctrl_dev->keycode; 175 struct input_dev *idev = fdtv->remote_ctrl_dev;
176 u16 *keycode = idev->keycode;
176 177
177 if (code >= 0x0300 && code <= 0x031f) 178 if (code >= 0x0300 && code <= 0x031f)
178 code = keycode[code - 0x0300]; 179 code = keycode[code - 0x0300];
@@ -188,6 +189,8 @@ void fdtv_handle_rc(struct firedtv *fdtv, unsigned int code)
188 return; 189 return;
189 } 190 }
190 191
191 input_report_key(fdtv->remote_ctrl_dev, code, 1); 192 input_report_key(idev, code, 1);
192 input_report_key(fdtv->remote_ctrl_dev, code, 0); 193 input_sync(idev);
194 input_report_key(idev, code, 0);
195 input_sync(idev);
193} 196}
diff --git a/drivers/media/dvb/firewire/firedtv.h b/drivers/media/dvb/firewire/firedtv.h
index 78cc28f36914..bd00b04e079d 100644
--- a/drivers/media/dvb/firewire/firedtv.h
+++ b/drivers/media/dvb/firewire/firedtv.h
@@ -70,15 +70,7 @@ enum model_type {
70 70
71struct device; 71struct device;
72struct input_dev; 72struct input_dev;
73struct firedtv; 73struct fdtv_ir_context;
74
75struct firedtv_backend {
76 int (*lock)(struct firedtv *fdtv, u64 addr, void *data);
77 int (*read)(struct firedtv *fdtv, u64 addr, void *data);
78 int (*write)(struct firedtv *fdtv, u64 addr, void *data, size_t len);
79 int (*start_iso)(struct firedtv *fdtv);
80 void (*stop_iso)(struct firedtv *fdtv);
81};
82 74
83struct firedtv { 75struct firedtv {
84 struct device *device; 76 struct device *device;
@@ -104,12 +96,11 @@ struct firedtv {
104 enum model_type type; 96 enum model_type type;
105 char subunit; 97 char subunit;
106 char isochannel; 98 char isochannel;
99 struct fdtv_ir_context *ir_context;
100
107 fe_sec_voltage_t voltage; 101 fe_sec_voltage_t voltage;
108 fe_sec_tone_mode_t tone; 102 fe_sec_tone_mode_t tone;
109 103
110 const struct firedtv_backend *backend;
111 void *backend_data;
112
113 struct mutex demux_mutex; 104 struct mutex demux_mutex;
114 unsigned long channel_active; 105 unsigned long channel_active;
115 u16 channel_pid[16]; 106 u16 channel_pid[16];
@@ -118,15 +109,6 @@ struct firedtv {
118 u8 avc_data[512]; 109 u8 avc_data[512];
119}; 110};
120 111
121/* firedtv-1394.c */
122#ifdef CONFIG_DVB_FIREDTV_IEEE1394
123int fdtv_1394_init(void);
124void fdtv_1394_exit(void);
125#else
126static inline int fdtv_1394_init(void) { return 0; }
127static inline void fdtv_1394_exit(void) {}
128#endif
129
130/* firedtv-avc.c */ 112/* firedtv-avc.c */
131int avc_recv(struct firedtv *fdtv, void *data, size_t length); 113int avc_recv(struct firedtv *fdtv, void *data, size_t length);
132int avc_tuner_status(struct firedtv *fdtv, struct firedtv_tuner_status *stat); 114int avc_tuner_status(struct firedtv *fdtv, struct firedtv_tuner_status *stat);
@@ -158,25 +140,18 @@ void fdtv_ca_release(struct firedtv *fdtv);
158/* firedtv-dvb.c */ 140/* firedtv-dvb.c */
159int fdtv_start_feed(struct dvb_demux_feed *dvbdmxfeed); 141int fdtv_start_feed(struct dvb_demux_feed *dvbdmxfeed);
160int fdtv_stop_feed(struct dvb_demux_feed *dvbdmxfeed); 142int fdtv_stop_feed(struct dvb_demux_feed *dvbdmxfeed);
161int fdtv_dvb_register(struct firedtv *fdtv); 143int fdtv_dvb_register(struct firedtv *fdtv, const char *name);
162void fdtv_dvb_unregister(struct firedtv *fdtv); 144void fdtv_dvb_unregister(struct firedtv *fdtv);
163struct firedtv *fdtv_alloc(struct device *dev,
164 const struct firedtv_backend *backend,
165 const char *name, size_t name_len);
166extern const char *fdtv_model_names[];
167extern const struct ieee1394_device_id fdtv_id_table[];
168 145
169/* firedtv-fe.c */ 146/* firedtv-fe.c */
170void fdtv_frontend_init(struct firedtv *fdtv); 147void fdtv_frontend_init(struct firedtv *fdtv, const char *name);
171 148
172/* firedtv-fw.c */ 149/* firedtv-fw.c */
173#ifdef CONFIG_DVB_FIREDTV_FIREWIRE 150int fdtv_lock(struct firedtv *fdtv, u64 addr, void *data);
174int fdtv_fw_init(void); 151int fdtv_read(struct firedtv *fdtv, u64 addr, void *data);
175void fdtv_fw_exit(void); 152int fdtv_write(struct firedtv *fdtv, u64 addr, void *data, size_t len);
176#else 153int fdtv_start_iso(struct firedtv *fdtv);
177static inline int fdtv_fw_init(void) { return 0; } 154void fdtv_stop_iso(struct firedtv *fdtv);
178static inline void fdtv_fw_exit(void) {}
179#endif
180 155
181/* firedtv-rc.c */ 156/* firedtv-rc.c */
182#ifdef CONFIG_DVB_FIREDTV_INPUT 157#ifdef CONFIG_DVB_FIREDTV_INPUT
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index b5f6a04f9c12..44b816f2601e 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -1,7 +1,7 @@
1config DVB_FE_CUSTOMISE 1config DVB_FE_CUSTOMISE
2 bool "Customise the frontend modules to build" 2 bool "Customise the frontend modules to build"
3 depends on DVB_CORE 3 depends on DVB_CORE
4 default y if EMBEDDED 4 default y if EXPERT
5 help 5 help
6 This allows the user to select/deselect frontend drivers for their 6 This allows the user to select/deselect frontend drivers for their
7 hardware from the build. 7 hardware from the build.
@@ -12,9 +12,8 @@ config DVB_FE_CUSTOMISE
12 12
13 If unsure say N. 13 If unsure say N.
14 14
15if DVB_FE_CUSTOMISE
16
17menu "Customise DVB Frontends" 15menu "Customise DVB Frontends"
16 visible if DVB_FE_CUSTOMISE
18 17
19comment "Multistandard (satellite) frontends" 18comment "Multistandard (satellite) frontends"
20 depends on DVB_CORE 19 depends on DVB_CORE
@@ -257,18 +256,23 @@ config DVB_CX22702
257 help 256 help
258 A DVB-T tuner module. Say Y when you want to support this frontend. 257 A DVB-T tuner module. Say Y when you want to support this frontend.
259 258
260config DVB_DRX397XD 259config DVB_S5H1432
261 tristate "Micronas DRX3975D/DRX3977D based" 260 tristate "Samsung s5h1432 demodulator (OFDM)"
262 depends on DVB_CORE && I2C 261 depends on DVB_CORE && I2C
263 default m if DVB_FE_CUSTOMISE 262 default m if DVB_FE_CUSTOMISE
264 help 263 help
265 A DVB-T tuner module. Say Y when you want to support this frontend. 264 A DVB-T tuner module. Say Y when you want to support this frontend.
266 265
267 TODO: 266config DVB_DRXD
268 This driver needs external firmware. Please use the command 267 tristate "Micronas DRXD driver"
269 "<kerneldir>/Documentation/dvb/get_dvb_firmware drx397xD" to 268 depends on DVB_CORE && I2C
270 download/extract them, and then copy them to /usr/lib/hotplug/firmware 269 default m if DVB_FE_CUSTOMISE
271 or /lib/firmware (depending on configuration of firmware hotplug). 270 help
271 A DVB-T tuner module. Say Y when you want to support this frontend.
272
273 Note: this driver was based on vendor driver reference code (released
274 under the GPL) as opposed to the existing drx397xd driver, which
275 was written via reverse engineering.
272 276
273config DVB_L64781 277config DVB_L64781
274 tristate "LSI L64781" 278 tristate "LSI L64781"
@@ -343,6 +347,14 @@ config DVB_DIB7000P
343 A DVB-T tuner module. Designed for mobile usage. Say Y when you want 347 A DVB-T tuner module. Designed for mobile usage. Say Y when you want
344 to support this frontend. 348 to support this frontend.
345 349
350config DVB_DIB9000
351 tristate "DiBcom 9000"
352 depends on DVB_CORE && I2C
353 default m if DVB_FE_CUSTOMISE
354 help
355 A DVB-T tuner module. Designed for mobile usage. Say Y when you want
356 to support this frontend.
357
346config DVB_TDA10048 358config DVB_TDA10048
347 tristate "Philips TDA10048HN based" 359 tristate "Philips TDA10048HN based"
348 depends on DVB_CORE && I2C 360 depends on DVB_CORE && I2C
@@ -364,6 +376,20 @@ config DVB_EC100
364 help 376 help
365 Say Y when you want to support this frontend. 377 Say Y when you want to support this frontend.
366 378
379config DVB_STV0367
380 tristate "ST STV0367 based"
381 depends on DVB_CORE && I2C
382 default m if DVB_FE_CUSTOMISE
383 help
384 A DVB-T/C tuner module. Say Y when you want to support this frontend.
385
386config DVB_CXD2820R
387 tristate "Sony CXD2820R"
388 depends on DVB_CORE && I2C
389 default m if DVB_FE_CUSTOMISE
390 help
391 Say Y when you want to support this frontend.
392
367comment "DVB-C (cable) frontends" 393comment "DVB-C (cable) frontends"
368 depends on DVB_CORE 394 depends on DVB_CORE
369 395
@@ -455,16 +481,8 @@ config DVB_LGDT330X
455 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 481 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
456 to support this frontend. 482 to support this frontend.
457 483
458config DVB_LGDT3304
459 tristate "LG Electronics LGDT3304"
460 depends on DVB_CORE && I2C
461 default m if DVB_FE_CUSTOMISE
462 help
463 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
464 to support this frontend.
465
466config DVB_LGDT3305 484config DVB_LGDT3305
467 tristate "LG Electronics LGDT3305 based" 485 tristate "LG Electronics LGDT3304 and LGDT3305 based"
468 depends on DVB_CORE && I2C 486 depends on DVB_CORE && I2C
469 default m if DVB_FE_CUSTOMISE 487 default m if DVB_FE_CUSTOMISE
470 help 488 help
@@ -499,7 +517,7 @@ comment "ISDB-T (terrestrial) frontends"
499 depends on DVB_CORE 517 depends on DVB_CORE
500 518
501config DVB_S921 519config DVB_S921
502 tristate "Sharp S921 tuner" 520 tristate "Sharp S921 frontend"
503 depends on DVB_CORE && I2C 521 depends on DVB_CORE && I2C
504 default m if DVB_FE_CUSTOMISE 522 default m if DVB_FE_CUSTOMISE
505 help 523 help
@@ -514,6 +532,14 @@ config DVB_DIB8000
514 A driver for DiBcom's DiB8000 ISDB-T/ISDB-Tsb demodulator. 532 A driver for DiBcom's DiB8000 ISDB-T/ISDB-Tsb demodulator.
515 Say Y when you want to support this frontend. 533 Say Y when you want to support this frontend.
516 534
535config DVB_MB86A20S
536 tristate "Fujitsu mb86a20s"
537 depends on DVB_CORE && I2C
538 default m if DVB_FE_CUSTOMISE
539 help
540 A driver for Fujitsu mb86a20s ISDB-T/ISDB-Tsb demodulator.
541 Say Y when you want to support this frontend.
542
517comment "Digital terrestrial only tuners/PLL" 543comment "Digital terrestrial only tuners/PLL"
518 depends on DVB_CORE 544 depends on DVB_CORE
519 545
@@ -607,11 +633,16 @@ config DVB_TDA665x
607 Currently supported tuners: 633 Currently supported tuners:
608 * Panasonic ENV57H12D5 (ET-50DT) 634 * Panasonic ENV57H12D5 (ET-50DT)
609 635
636config DVB_IX2505V
637 tristate "Sharp IX2505V silicon tuner"
638 depends on DVB_CORE && I2C
639 default m if DVB_FE_CUSTOMISE
640 help
641 A DVB-S tuner module. Say Y when you want to support this frontend.
642
610comment "Tools to develop new frontends" 643comment "Tools to develop new frontends"
611 644
612config DVB_DUMMY_FE 645config DVB_DUMMY_FE
613 tristate "Dummy frontend driver" 646 tristate "Dummy frontend driver"
614 default n 647 default n
615endmenu 648endmenu
616
617endif
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 874e8ada4d1d..2f3a6f736d64 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -5,10 +5,11 @@
5EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ 5EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
6EXTRA_CFLAGS += -Idrivers/media/common/tuners/ 6EXTRA_CFLAGS += -Idrivers/media/common/tuners/
7 7
8s921-objs := s921_module.o s921_core.o
9stb0899-objs = stb0899_drv.o stb0899_algo.o 8stb0899-objs = stb0899_drv.o stb0899_algo.o
10stv0900-objs = stv0900_core.o stv0900_sw.o 9stv0900-objs = stv0900_core.o stv0900_sw.o
11au8522-objs = au8522_dig.o au8522_decoder.o 10au8522-objs = au8522_dig.o au8522_decoder.o
11drxd-objs = drxd_firm.o drxd_hard.o
12cxd2820r-objs = cxd2820r_core.o cxd2820r_c.o cxd2820r_t.o cxd2820r_t2.o
12 13
13obj-$(CONFIG_DVB_PLL) += dvb-pll.o 14obj-$(CONFIG_DVB_PLL) += dvb-pll.o
14obj-$(CONFIG_DVB_STV0299) += stv0299.o 15obj-$(CONFIG_DVB_STV0299) += stv0299.o
@@ -16,6 +17,7 @@ obj-$(CONFIG_DVB_STB0899) += stb0899.o
16obj-$(CONFIG_DVB_STB6100) += stb6100.o 17obj-$(CONFIG_DVB_STB6100) += stb6100.o
17obj-$(CONFIG_DVB_SP8870) += sp8870.o 18obj-$(CONFIG_DVB_SP8870) += sp8870.o
18obj-$(CONFIG_DVB_CX22700) += cx22700.o 19obj-$(CONFIG_DVB_CX22700) += cx22700.o
20obj-$(CONFIG_DVB_S5H1432) += s5h1432.o
19obj-$(CONFIG_DVB_CX24110) += cx24110.o 21obj-$(CONFIG_DVB_CX24110) += cx24110.o
20obj-$(CONFIG_DVB_TDA8083) += tda8083.o 22obj-$(CONFIG_DVB_TDA8083) += tda8083.o
21obj-$(CONFIG_DVB_L64781) += l64781.o 23obj-$(CONFIG_DVB_L64781) += l64781.o
@@ -24,6 +26,7 @@ obj-$(CONFIG_DVB_DIB3000MC) += dib3000mc.o dibx000_common.o
24obj-$(CONFIG_DVB_DIB7000M) += dib7000m.o dibx000_common.o 26obj-$(CONFIG_DVB_DIB7000M) += dib7000m.o dibx000_common.o
25obj-$(CONFIG_DVB_DIB7000P) += dib7000p.o dibx000_common.o 27obj-$(CONFIG_DVB_DIB7000P) += dib7000p.o dibx000_common.o
26obj-$(CONFIG_DVB_DIB8000) += dib8000.o dibx000_common.o 28obj-$(CONFIG_DVB_DIB8000) += dib8000.o dibx000_common.o
29obj-$(CONFIG_DVB_DIB9000) += dib9000.o dibx000_common.o
27obj-$(CONFIG_DVB_MT312) += mt312.o 30obj-$(CONFIG_DVB_MT312) += mt312.o
28obj-$(CONFIG_DVB_VES1820) += ves1820.o 31obj-$(CONFIG_DVB_VES1820) += ves1820.o
29obj-$(CONFIG_DVB_VES1X93) += ves1x93.o 32obj-$(CONFIG_DVB_VES1X93) += ves1x93.o
@@ -35,7 +38,7 @@ obj-$(CONFIG_DVB_ZL10036) += zl10036.o
35obj-$(CONFIG_DVB_ZL10039) += zl10039.o 38obj-$(CONFIG_DVB_ZL10039) += zl10039.o
36obj-$(CONFIG_DVB_ZL10353) += zl10353.o 39obj-$(CONFIG_DVB_ZL10353) += zl10353.o
37obj-$(CONFIG_DVB_CX22702) += cx22702.o 40obj-$(CONFIG_DVB_CX22702) += cx22702.o
38obj-$(CONFIG_DVB_DRX397XD) += drx397xD.o 41obj-$(CONFIG_DVB_DRXD) += drxd.o
39obj-$(CONFIG_DVB_TDA10021) += tda10021.o 42obj-$(CONFIG_DVB_TDA10021) += tda10021.o
40obj-$(CONFIG_DVB_TDA10023) += tda10023.o 43obj-$(CONFIG_DVB_TDA10023) += tda10023.o
41obj-$(CONFIG_DVB_STV0297) += stv0297.o 44obj-$(CONFIG_DVB_STV0297) += stv0297.o
@@ -45,7 +48,6 @@ obj-$(CONFIG_DVB_OR51132) += or51132.o
45obj-$(CONFIG_DVB_BCM3510) += bcm3510.o 48obj-$(CONFIG_DVB_BCM3510) += bcm3510.o
46obj-$(CONFIG_DVB_S5H1420) += s5h1420.o 49obj-$(CONFIG_DVB_S5H1420) += s5h1420.o
47obj-$(CONFIG_DVB_LGDT330X) += lgdt330x.o 50obj-$(CONFIG_DVB_LGDT330X) += lgdt330x.o
48obj-$(CONFIG_DVB_LGDT3304) += lgdt3304.o
49obj-$(CONFIG_DVB_LGDT3305) += lgdt3305.o 51obj-$(CONFIG_DVB_LGDT3305) += lgdt3305.o
50obj-$(CONFIG_DVB_CX24123) += cx24123.o 52obj-$(CONFIG_DVB_CX24123) += cx24123.o
51obj-$(CONFIG_DVB_LNBP21) += lnbp21.o 53obj-$(CONFIG_DVB_LNBP21) += lnbp21.o
@@ -82,3 +84,8 @@ obj-$(CONFIG_DVB_ISL6423) += isl6423.o
82obj-$(CONFIG_DVB_EC100) += ec100.o 84obj-$(CONFIG_DVB_EC100) += ec100.o
83obj-$(CONFIG_DVB_DS3000) += ds3000.o 85obj-$(CONFIG_DVB_DS3000) += ds3000.o
84obj-$(CONFIG_DVB_MB86A16) += mb86a16.o 86obj-$(CONFIG_DVB_MB86A16) += mb86a16.o
87obj-$(CONFIG_DVB_MB86A20S) += mb86a20s.o
88obj-$(CONFIG_DVB_IX2505V) += ix2505v.o
89obj-$(CONFIG_DVB_STV0367) += stv0367.o
90obj-$(CONFIG_DVB_CXD2820R) += cxd2820r.o
91
diff --git a/drivers/media/dvb/frontends/af9013.c b/drivers/media/dvb/frontends/af9013.c
index dac917f7bb7f..345311c33383 100644
--- a/drivers/media/dvb/frontends/af9013.c
+++ b/drivers/media/dvb/frontends/af9013.c
@@ -42,6 +42,8 @@ struct af9013_state {
42 42
43 struct af9013_config config; 43 struct af9013_config config;
44 44
45 /* tuner/demod RF and IF AGC limits used for signal strength calc */
46 u8 signal_strength_en, rf_50, rf_80, if_50, if_80;
45 u16 signal_strength; 47 u16 signal_strength;
46 u32 ber; 48 u32 ber;
47 u32 ucblocks; 49 u32 ucblocks;
@@ -220,184 +222,37 @@ static u32 af913_div(u32 a, u32 b, u32 x)
220 222
221static int af9013_set_coeff(struct af9013_state *state, fe_bandwidth_t bw) 223static int af9013_set_coeff(struct af9013_state *state, fe_bandwidth_t bw)
222{ 224{
223 int ret = 0; 225 int ret, i, j, found;
224 u8 i = 0;
225 u8 buf[24];
226 u32 uninitialized_var(ns_coeff1_2048nu);
227 u32 uninitialized_var(ns_coeff1_8191nu);
228 u32 uninitialized_var(ns_coeff1_8192nu);
229 u32 uninitialized_var(ns_coeff1_8193nu);
230 u32 uninitialized_var(ns_coeff2_2k);
231 u32 uninitialized_var(ns_coeff2_8k);
232
233 deb_info("%s: adc_clock:%d bw:%d\n", __func__, 226 deb_info("%s: adc_clock:%d bw:%d\n", __func__,
234 state->config.adc_clock, bw); 227 state->config.adc_clock, bw);
235 228
236 switch (state->config.adc_clock) { 229 /* lookup coeff from table */
237 case 28800: /* 28.800 MHz */ 230 for (i = 0, found = 0; i < ARRAY_SIZE(coeff_table); i++) {
238 switch (bw) { 231 if (coeff_table[i].adc_clock == state->config.adc_clock &&
239 case BANDWIDTH_6_MHZ: 232 coeff_table[i].bw == bw) {
240 ns_coeff1_2048nu = 0x01e79e7a; 233 found = 1;
241 ns_coeff1_8191nu = 0x0079eb6e;
242 ns_coeff1_8192nu = 0x0079e79e;
243 ns_coeff1_8193nu = 0x0079e3cf;
244 ns_coeff2_2k = 0x00f3cf3d;
245 ns_coeff2_8k = 0x003cf3cf;
246 break;
247 case BANDWIDTH_7_MHZ:
248 ns_coeff1_2048nu = 0x0238e38e;
249 ns_coeff1_8191nu = 0x008e3d55;
250 ns_coeff1_8192nu = 0x008e38e4;
251 ns_coeff1_8193nu = 0x008e3472;
252 ns_coeff2_2k = 0x011c71c7;
253 ns_coeff2_8k = 0x00471c72;
254 break;
255 case BANDWIDTH_8_MHZ:
256 ns_coeff1_2048nu = 0x028a28a3;
257 ns_coeff1_8191nu = 0x00a28f3d;
258 ns_coeff1_8192nu = 0x00a28a29;
259 ns_coeff1_8193nu = 0x00a28514;
260 ns_coeff2_2k = 0x01451451;
261 ns_coeff2_8k = 0x00514514;
262 break;
263 default:
264 ret = -EINVAL;
265 }
266 break;
267 case 20480: /* 20.480 MHz */
268 switch (bw) {
269 case BANDWIDTH_6_MHZ:
270 ns_coeff1_2048nu = 0x02adb6dc;
271 ns_coeff1_8191nu = 0x00ab7313;
272 ns_coeff1_8192nu = 0x00ab6db7;
273 ns_coeff1_8193nu = 0x00ab685c;
274 ns_coeff2_2k = 0x0156db6e;
275 ns_coeff2_8k = 0x0055b6dc;
276 break; 234 break;
277 case BANDWIDTH_7_MHZ:
278 ns_coeff1_2048nu = 0x03200001;
279 ns_coeff1_8191nu = 0x00c80640;
280 ns_coeff1_8192nu = 0x00c80000;
281 ns_coeff1_8193nu = 0x00c7f9c0;
282 ns_coeff2_2k = 0x01900000;
283 ns_coeff2_8k = 0x00640000;
284 break;
285 case BANDWIDTH_8_MHZ:
286 ns_coeff1_2048nu = 0x03924926;
287 ns_coeff1_8191nu = 0x00e4996e;
288 ns_coeff1_8192nu = 0x00e49249;
289 ns_coeff1_8193nu = 0x00e48b25;
290 ns_coeff2_2k = 0x01c92493;
291 ns_coeff2_8k = 0x00724925;
292 break;
293 default:
294 ret = -EINVAL;
295 } 235 }
296 break;
297 case 28000: /* 28.000 MHz */
298 switch (bw) {
299 case BANDWIDTH_6_MHZ:
300 ns_coeff1_2048nu = 0x01f58d10;
301 ns_coeff1_8191nu = 0x007d672f;
302 ns_coeff1_8192nu = 0x007d6344;
303 ns_coeff1_8193nu = 0x007d5f59;
304 ns_coeff2_2k = 0x00fac688;
305 ns_coeff2_8k = 0x003eb1a2;
306 break;
307 case BANDWIDTH_7_MHZ:
308 ns_coeff1_2048nu = 0x02492492;
309 ns_coeff1_8191nu = 0x00924db7;
310 ns_coeff1_8192nu = 0x00924925;
311 ns_coeff1_8193nu = 0x00924492;
312 ns_coeff2_2k = 0x01249249;
313 ns_coeff2_8k = 0x00492492;
314 break;
315 case BANDWIDTH_8_MHZ:
316 ns_coeff1_2048nu = 0x029cbc15;
317 ns_coeff1_8191nu = 0x00a7343f;
318 ns_coeff1_8192nu = 0x00a72f05;
319 ns_coeff1_8193nu = 0x00a729cc;
320 ns_coeff2_2k = 0x014e5e0a;
321 ns_coeff2_8k = 0x00539783;
322 break;
323 default:
324 ret = -EINVAL;
325 }
326 break;
327 case 25000: /* 25.000 MHz */
328 switch (bw) {
329 case BANDWIDTH_6_MHZ:
330 ns_coeff1_2048nu = 0x0231bcb5;
331 ns_coeff1_8191nu = 0x008c7391;
332 ns_coeff1_8192nu = 0x008c6f2d;
333 ns_coeff1_8193nu = 0x008c6aca;
334 ns_coeff2_2k = 0x0118de5b;
335 ns_coeff2_8k = 0x00463797;
336 break;
337 case BANDWIDTH_7_MHZ:
338 ns_coeff1_2048nu = 0x028f5c29;
339 ns_coeff1_8191nu = 0x00a3dc29;
340 ns_coeff1_8192nu = 0x00a3d70a;
341 ns_coeff1_8193nu = 0x00a3d1ec;
342 ns_coeff2_2k = 0x0147ae14;
343 ns_coeff2_8k = 0x0051eb85;
344 break;
345 case BANDWIDTH_8_MHZ:
346 ns_coeff1_2048nu = 0x02ecfb9d;
347 ns_coeff1_8191nu = 0x00bb44c1;
348 ns_coeff1_8192nu = 0x00bb3ee7;
349 ns_coeff1_8193nu = 0x00bb390d;
350 ns_coeff2_2k = 0x01767dce;
351 ns_coeff2_8k = 0x005d9f74;
352 break;
353 default:
354 ret = -EINVAL;
355 }
356 break;
357 default:
358 err("invalid xtal");
359 return -EINVAL;
360 } 236 }
361 if (ret) { 237
362 err("invalid bandwidth"); 238 if (!found) {
363 return ret; 239 err("invalid bw or clock");
240 ret = -EINVAL;
241 goto error;
364 } 242 }
365 243
366 buf[i++] = (u8) ((ns_coeff1_2048nu & 0x03000000) >> 24); 244 deb_info("%s: coeff: ", __func__);
367 buf[i++] = (u8) ((ns_coeff1_2048nu & 0x00ff0000) >> 16); 245 debug_dump(coeff_table[i].val, sizeof(coeff_table[i].val), deb_info);
368 buf[i++] = (u8) ((ns_coeff1_2048nu & 0x0000ff00) >> 8);
369 buf[i++] = (u8) ((ns_coeff1_2048nu & 0x000000ff));
370 buf[i++] = (u8) ((ns_coeff2_2k & 0x01c00000) >> 22);
371 buf[i++] = (u8) ((ns_coeff2_2k & 0x003fc000) >> 14);
372 buf[i++] = (u8) ((ns_coeff2_2k & 0x00003fc0) >> 6);
373 buf[i++] = (u8) ((ns_coeff2_2k & 0x0000003f));
374 buf[i++] = (u8) ((ns_coeff1_8191nu & 0x03000000) >> 24);
375 buf[i++] = (u8) ((ns_coeff1_8191nu & 0x00ffc000) >> 16);
376 buf[i++] = (u8) ((ns_coeff1_8191nu & 0x0000ff00) >> 8);
377 buf[i++] = (u8) ((ns_coeff1_8191nu & 0x000000ff));
378 buf[i++] = (u8) ((ns_coeff1_8192nu & 0x03000000) >> 24);
379 buf[i++] = (u8) ((ns_coeff1_8192nu & 0x00ffc000) >> 16);
380 buf[i++] = (u8) ((ns_coeff1_8192nu & 0x0000ff00) >> 8);
381 buf[i++] = (u8) ((ns_coeff1_8192nu & 0x000000ff));
382 buf[i++] = (u8) ((ns_coeff1_8193nu & 0x03000000) >> 24);
383 buf[i++] = (u8) ((ns_coeff1_8193nu & 0x00ffc000) >> 16);
384 buf[i++] = (u8) ((ns_coeff1_8193nu & 0x0000ff00) >> 8);
385 buf[i++] = (u8) ((ns_coeff1_8193nu & 0x000000ff));
386 buf[i++] = (u8) ((ns_coeff2_8k & 0x01c00000) >> 22);
387 buf[i++] = (u8) ((ns_coeff2_8k & 0x003fc000) >> 14);
388 buf[i++] = (u8) ((ns_coeff2_8k & 0x00003fc0) >> 6);
389 buf[i++] = (u8) ((ns_coeff2_8k & 0x0000003f));
390
391 deb_info("%s: coeff:", __func__);
392 debug_dump(buf, sizeof(buf), deb_info);
393 246
394 /* program */ 247 /* program */
395 for (i = 0; i < sizeof(buf); i++) { 248 for (j = 0; j < sizeof(coeff_table[i].val); j++) {
396 ret = af9013_write_reg(state, 0xae00 + i, buf[i]); 249 ret = af9013_write_reg(state, 0xae00 + j,
250 coeff_table[i].val[j]);
397 if (ret) 251 if (ret)
398 break; 252 break;
399 } 253 }
400 254
255error:
401 return ret; 256 return ret;
402} 257}
403 258
@@ -479,11 +334,24 @@ static int af9013_set_freq_ctrl(struct af9013_state *state, fe_bandwidth_t bw)
479 if_sample_freq = 3300000; /* 3.3 MHz */ 334 if_sample_freq = 3300000; /* 3.3 MHz */
480 break; 335 break;
481 case BANDWIDTH_7_MHZ: 336 case BANDWIDTH_7_MHZ:
482 if_sample_freq = 3800000; /* 3.8 MHz */ 337 if_sample_freq = 3500000; /* 3.5 MHz */
483 break; 338 break;
484 case BANDWIDTH_8_MHZ: 339 case BANDWIDTH_8_MHZ:
485 default: 340 default:
486 if_sample_freq = 4300000; /* 4.3 MHz */ 341 if_sample_freq = 4000000; /* 4.0 MHz */
342 break;
343 }
344 } else if (state->config.tuner == AF9013_TUNER_TDA18218) {
345 switch (bw) {
346 case BANDWIDTH_6_MHZ:
347 if_sample_freq = 3000000; /* 3 MHz */
348 break;
349 case BANDWIDTH_7_MHZ:
350 if_sample_freq = 3500000; /* 3.5 MHz */
351 break;
352 case BANDWIDTH_8_MHZ:
353 default:
354 if_sample_freq = 4000000; /* 4 MHz */
487 break; 355 break;
488 } 356 }
489 } 357 }
@@ -1096,46 +964,32 @@ error:
1096static int af9013_update_signal_strength(struct dvb_frontend *fe) 964static int af9013_update_signal_strength(struct dvb_frontend *fe)
1097{ 965{
1098 struct af9013_state *state = fe->demodulator_priv; 966 struct af9013_state *state = fe->demodulator_priv;
1099 int ret; 967 int ret = 0;
1100 u8 tmp0; 968 u8 rf_gain, if_gain;
1101 u8 rf_gain, rf_50, rf_80, if_gain, if_50, if_80;
1102 int signal_strength; 969 int signal_strength;
1103 970
1104 deb_info("%s\n", __func__); 971 deb_info("%s\n", __func__);
1105 972
1106 state->signal_strength = 0; 973 if (state->signal_strength_en) {
1107
1108 ret = af9013_read_reg_bits(state, 0x9bee, 0, 1, &tmp0);
1109 if (ret)
1110 goto error;
1111 if (tmp0) {
1112 ret = af9013_read_reg(state, 0x9bbd, &rf_50);
1113 if (ret)
1114 goto error;
1115 ret = af9013_read_reg(state, 0x9bd0, &rf_80);
1116 if (ret)
1117 goto error;
1118 ret = af9013_read_reg(state, 0x9be2, &if_50);
1119 if (ret)
1120 goto error;
1121 ret = af9013_read_reg(state, 0x9be4, &if_80);
1122 if (ret)
1123 goto error;
1124 ret = af9013_read_reg(state, 0xd07c, &rf_gain); 974 ret = af9013_read_reg(state, 0xd07c, &rf_gain);
1125 if (ret) 975 if (ret)
1126 goto error; 976 goto error;
1127 ret = af9013_read_reg(state, 0xd07d, &if_gain); 977 ret = af9013_read_reg(state, 0xd07d, &if_gain);
1128 if (ret) 978 if (ret)
1129 goto error; 979 goto error;
1130 signal_strength = (0xffff / (9 * (rf_50 + if_50) - \ 980 signal_strength = (0xffff / \
1131 11 * (rf_80 + if_80))) * (10 * (rf_gain + if_gain) - \ 981 (9 * (state->rf_50 + state->if_50) - \
1132 11 * (rf_80 + if_80)); 982 11 * (state->rf_80 + state->if_80))) * \
983 (10 * (rf_gain + if_gain) - \
984 11 * (state->rf_80 + state->if_80));
1133 if (signal_strength < 0) 985 if (signal_strength < 0)
1134 signal_strength = 0; 986 signal_strength = 0;
1135 else if (signal_strength > 0xffff) 987 else if (signal_strength > 0xffff)
1136 signal_strength = 0xffff; 988 signal_strength = 0xffff;
1137 989
1138 state->signal_strength = signal_strength; 990 state->signal_strength = signal_strength;
991 } else {
992 state->signal_strength = 0;
1139 } 993 }
1140 994
1141error: 995error:
@@ -1368,6 +1222,7 @@ static int af9013_init(struct dvb_frontend *fe)
1368 break; 1222 break;
1369 case AF9013_TUNER_MXL5005D: 1223 case AF9013_TUNER_MXL5005D:
1370 case AF9013_TUNER_MXL5005R: 1224 case AF9013_TUNER_MXL5005R:
1225 case AF9013_TUNER_MXL5007T:
1371 len = ARRAY_SIZE(tuner_init_mxl5005); 1226 len = ARRAY_SIZE(tuner_init_mxl5005);
1372 init = tuner_init_mxl5005; 1227 init = tuner_init_mxl5005;
1373 break; 1228 break;
@@ -1393,6 +1248,7 @@ static int af9013_init(struct dvb_frontend *fe)
1393 init = tuner_init_mt2060_2; 1248 init = tuner_init_mt2060_2;
1394 break; 1249 break;
1395 case AF9013_TUNER_TDA18271: 1250 case AF9013_TUNER_TDA18271:
1251 case AF9013_TUNER_TDA18218:
1396 len = ARRAY_SIZE(tuner_init_tda18271); 1252 len = ARRAY_SIZE(tuner_init_tda18271);
1397 init = tuner_init_tda18271; 1253 init = tuner_init_tda18271;
1398 break; 1254 break;
@@ -1438,6 +1294,27 @@ static int af9013_init(struct dvb_frontend *fe)
1438 if (ret) 1294 if (ret)
1439 goto error; 1295 goto error;
1440 1296
1297 /* read values needed for signal strength calculation */
1298 ret = af9013_read_reg_bits(state, 0x9bee, 0, 1,
1299 &state->signal_strength_en);
1300 if (ret)
1301 goto error;
1302
1303 if (state->signal_strength_en) {
1304 ret = af9013_read_reg(state, 0x9bbd, &state->rf_50);
1305 if (ret)
1306 goto error;
1307 ret = af9013_read_reg(state, 0x9bd0, &state->rf_80);
1308 if (ret)
1309 goto error;
1310 ret = af9013_read_reg(state, 0x9be2, &state->if_50);
1311 if (ret)
1312 goto error;
1313 ret = af9013_read_reg(state, 0x9be4, &state->if_80);
1314 if (ret)
1315 goto error;
1316 }
1317
1441error: 1318error:
1442 return ret; 1319 return ret;
1443} 1320}
@@ -1446,13 +1323,11 @@ static struct dvb_frontend_ops af9013_ops;
1446 1323
1447static int af9013_download_firmware(struct af9013_state *state) 1324static int af9013_download_firmware(struct af9013_state *state)
1448{ 1325{
1449 int i, len, packets, remainder, ret; 1326 int i, len, remaining, ret;
1450 const struct firmware *fw; 1327 const struct firmware *fw;
1451 u16 addr = 0x5100; /* firmware start address */
1452 u16 checksum = 0; 1328 u16 checksum = 0;
1453 u8 val; 1329 u8 val;
1454 u8 fw_params[4]; 1330 u8 fw_params[4];
1455 u8 *data;
1456 u8 *fw_file = AF9013_DEFAULT_FIRMWARE; 1331 u8 *fw_file = AF9013_DEFAULT_FIRMWARE;
1457 1332
1458 msleep(100); 1333 msleep(100);
@@ -1496,21 +1371,18 @@ static int af9013_download_firmware(struct af9013_state *state)
1496 if (ret) 1371 if (ret)
1497 goto error_release; 1372 goto error_release;
1498 1373
1499 #define FW_PACKET_MAX_DATA 16 1374 #define FW_ADDR 0x5100 /* firmware start address */
1500 1375 #define LEN_MAX 16 /* max packet size */
1501 packets = fw->size / FW_PACKET_MAX_DATA; 1376 for (remaining = fw->size; remaining > 0; remaining -= LEN_MAX) {
1502 remainder = fw->size % FW_PACKET_MAX_DATA; 1377 len = remaining;
1503 len = FW_PACKET_MAX_DATA; 1378 if (len > LEN_MAX)
1504 for (i = 0; i <= packets; i++) { 1379 len = LEN_MAX;
1505 if (i == packets) /* set size of the last packet */
1506 len = remainder;
1507
1508 data = (u8 *)(fw->data + i * FW_PACKET_MAX_DATA);
1509 ret = af9013_write_ofsm_regs(state, addr, data, len);
1510 addr += FW_PACKET_MAX_DATA;
1511 1380
1381 ret = af9013_write_ofsm_regs(state,
1382 FW_ADDR + fw->size - remaining,
1383 (u8 *) &fw->data[fw->size - remaining], len);
1512 if (ret) { 1384 if (ret) {
1513 err("firmware download failed at %d with %d", i, ret); 1385 err("firmware download failed:%d", ret);
1514 goto error_release; 1386 goto error_release;
1515 } 1387 }
1516 } 1388 }
@@ -1589,20 +1461,6 @@ struct dvb_frontend *af9013_attach(const struct af9013_config *config,
1589 state->i2c = i2c; 1461 state->i2c = i2c;
1590 memcpy(&state->config, config, sizeof(struct af9013_config)); 1462 memcpy(&state->config, config, sizeof(struct af9013_config));
1591 1463
1592 /* chip version */
1593 ret = af9013_read_reg_bits(state, 0xd733, 4, 4, &buf[2]);
1594 if (ret)
1595 goto error;
1596
1597 /* ROM version */
1598 for (i = 0; i < 2; i++) {
1599 ret = af9013_read_reg(state, 0x116b + i, &buf[i]);
1600 if (ret)
1601 goto error;
1602 }
1603 deb_info("%s: chip version:%d ROM version:%d.%d\n", __func__,
1604 buf[2], buf[0], buf[1]);
1605
1606 /* download firmware */ 1464 /* download firmware */
1607 if (state->config.output_mode != AF9013_OUTPUT_MODE_USB) { 1465 if (state->config.output_mode != AF9013_OUTPUT_MODE_USB) {
1608 ret = af9013_download_firmware(state); 1466 ret = af9013_download_firmware(state);
@@ -1618,6 +1476,20 @@ struct dvb_frontend *af9013_attach(const struct af9013_config *config,
1618 } 1476 }
1619 info("firmware version:%d.%d.%d.%d", buf[0], buf[1], buf[2], buf[3]); 1477 info("firmware version:%d.%d.%d.%d", buf[0], buf[1], buf[2], buf[3]);
1620 1478
1479 /* chip version */
1480 ret = af9013_read_reg_bits(state, 0xd733, 4, 4, &buf[2]);
1481 if (ret)
1482 goto error;
1483
1484 /* ROM version */
1485 for (i = 0; i < 2; i++) {
1486 ret = af9013_read_reg(state, 0x116b + i, &buf[i]);
1487 if (ret)
1488 goto error;
1489 }
1490 deb_info("%s: chip version:%d ROM version:%d.%d\n", __func__,
1491 buf[2], buf[0], buf[1]);
1492
1621 /* settings for mp2if */ 1493 /* settings for mp2if */
1622 if (state->config.output_mode == AF9013_OUTPUT_MODE_USB) { 1494 if (state->config.output_mode == AF9013_OUTPUT_MODE_USB) {
1623 /* AF9015 split PSB to 1.5k + 0.5k */ 1495 /* AF9015 split PSB to 1.5k + 0.5k */
diff --git a/drivers/media/dvb/frontends/af9013.h b/drivers/media/dvb/frontends/af9013.h
index 72c71bb5d117..e53d873f7555 100644
--- a/drivers/media/dvb/frontends/af9013.h
+++ b/drivers/media/dvb/frontends/af9013.h
@@ -44,6 +44,7 @@ enum af9013_tuner {
44 AF9013_TUNER_MT2060_2 = 147, /* Microtune */ 44 AF9013_TUNER_MT2060_2 = 147, /* Microtune */
45 AF9013_TUNER_TDA18271 = 156, /* NXP */ 45 AF9013_TUNER_TDA18271 = 156, /* NXP */
46 AF9013_TUNER_QT1010A = 162, /* Quantek */ 46 AF9013_TUNER_QT1010A = 162, /* Quantek */
47 AF9013_TUNER_MXL5007T = 177, /* MaxLinear */
47 AF9013_TUNER_TDA18218 = 179, /* NXP */ 48 AF9013_TUNER_TDA18218 = 179, /* NXP */
48}; 49};
49 50
diff --git a/drivers/media/dvb/frontends/af9013_priv.h b/drivers/media/dvb/frontends/af9013_priv.h
index 0fd42b7e248e..e00b2a4a2db6 100644
--- a/drivers/media/dvb/frontends/af9013_priv.h
+++ b/drivers/media/dvb/frontends/af9013_priv.h
@@ -60,6 +60,56 @@ struct snr_table {
60 u8 snr; 60 u8 snr;
61}; 61};
62 62
63struct coeff {
64 u32 adc_clock;
65 fe_bandwidth_t bw;
66 u8 val[24];
67};
68
69/* pre-calculated coeff lookup table */
70static struct coeff coeff_table[] = {
71 /* 28.800 MHz */
72 { 28800, BANDWIDTH_8_MHZ, { 0x02, 0x8a, 0x28, 0xa3, 0x05, 0x14,
73 0x51, 0x11, 0x00, 0xa2, 0x8f, 0x3d, 0x00, 0xa2, 0x8a,
74 0x29, 0x00, 0xa2, 0x85, 0x14, 0x01, 0x45, 0x14, 0x14 } },
75 { 28800, BANDWIDTH_7_MHZ, { 0x02, 0x38, 0xe3, 0x8e, 0x04, 0x71,
76 0xc7, 0x07, 0x00, 0x8e, 0x3d, 0x55, 0x00, 0x8e, 0x38,
77 0xe4, 0x00, 0x8e, 0x34, 0x72, 0x01, 0x1c, 0x71, 0x32 } },
78 { 28800, BANDWIDTH_6_MHZ, { 0x01, 0xe7, 0x9e, 0x7a, 0x03, 0xcf,
79 0x3c, 0x3d, 0x00, 0x79, 0xeb, 0x6e, 0x00, 0x79, 0xe7,
80 0x9e, 0x00, 0x79, 0xe3, 0xcf, 0x00, 0xf3, 0xcf, 0x0f } },
81 /* 20.480 MHz */
82 { 20480, BANDWIDTH_8_MHZ, { 0x03, 0x92, 0x49, 0x26, 0x07, 0x24,
83 0x92, 0x13, 0x00, 0xe4, 0x99, 0x6e, 0x00, 0xe4, 0x92,
84 0x49, 0x00, 0xe4, 0x8b, 0x25, 0x01, 0xc9, 0x24, 0x25 } },
85 { 20480, BANDWIDTH_7_MHZ, { 0x03, 0x20, 0x00, 0x01, 0x06, 0x40,
86 0x00, 0x00, 0x00, 0xc8, 0x06, 0x40, 0x00, 0xc8, 0x00,
87 0x00, 0x00, 0xc7, 0xf9, 0xc0, 0x01, 0x90, 0x00, 0x00 } },
88 { 20480, BANDWIDTH_6_MHZ, { 0x02, 0xad, 0xb6, 0xdc, 0x05, 0x5b,
89 0x6d, 0x2e, 0x00, 0xab, 0x73, 0x13, 0x00, 0xab, 0x6d,
90 0xb7, 0x00, 0xab, 0x68, 0x5c, 0x01, 0x56, 0xdb, 0x1c } },
91 /* 28.000 MHz */
92 { 28000, BANDWIDTH_8_MHZ, { 0x02, 0x9c, 0xbc, 0x15, 0x05, 0x39,
93 0x78, 0x0a, 0x00, 0xa7, 0x34, 0x3f, 0x00, 0xa7, 0x2f,
94 0x05, 0x00, 0xa7, 0x29, 0xcc, 0x01, 0x4e, 0x5e, 0x03 } },
95 { 28000, BANDWIDTH_7_MHZ, { 0x02, 0x49, 0x24, 0x92, 0x04, 0x92,
96 0x49, 0x09, 0x00, 0x92, 0x4d, 0xb7, 0x00, 0x92, 0x49,
97 0x25, 0x00, 0x92, 0x44, 0x92, 0x01, 0x24, 0x92, 0x12 } },
98 { 28000, BANDWIDTH_6_MHZ, { 0x01, 0xf5, 0x8d, 0x10, 0x03, 0xeb,
99 0x1a, 0x08, 0x00, 0x7d, 0x67, 0x2f, 0x00, 0x7d, 0x63,
100 0x44, 0x00, 0x7d, 0x5f, 0x59, 0x00, 0xfa, 0xc6, 0x22 } },
101 /* 25.000 MHz */
102 { 25000, BANDWIDTH_8_MHZ, { 0x02, 0xec, 0xfb, 0x9d, 0x05, 0xd9,
103 0xf7, 0x0e, 0x00, 0xbb, 0x44, 0xc1, 0x00, 0xbb, 0x3e,
104 0xe7, 0x00, 0xbb, 0x39, 0x0d, 0x01, 0x76, 0x7d, 0x34 } },
105 { 25000, BANDWIDTH_7_MHZ, { 0x02, 0x8f, 0x5c, 0x29, 0x05, 0x1e,
106 0xb8, 0x14, 0x00, 0xa3, 0xdc, 0x29, 0x00, 0xa3, 0xd7,
107 0x0a, 0x00, 0xa3, 0xd1, 0xec, 0x01, 0x47, 0xae, 0x05 } },
108 { 25000, BANDWIDTH_6_MHZ, { 0x02, 0x31, 0xbc, 0xb5, 0x04, 0x63,
109 0x79, 0x1b, 0x00, 0x8c, 0x73, 0x91, 0x00, 0x8c, 0x6f,
110 0x2d, 0x00, 0x8c, 0x6a, 0xca, 0x01, 0x18, 0xde, 0x17 } },
111};
112
63/* QPSK SNR lookup table */ 113/* QPSK SNR lookup table */
64static struct snr_table qpsk_snr_table[] = { 114static struct snr_table qpsk_snr_table[] = {
65 { 0x0b4771, 0 }, 115 { 0x0b4771, 0 },
@@ -480,9 +530,10 @@ static struct regdesc tuner_init_mxl5003d[] = {
480 { 0x9bd9, 0, 8, 0x08 }, 530 { 0x9bd9, 0, 8, 0x08 },
481}; 531};
482 532
483/* MaxLinear MXL5005 tuner init 533/* MaxLinear MXL5005S & MXL5007T tuner init
484 AF9013_TUNER_MXL5005D = 13 534 AF9013_TUNER_MXL5005D = 13
485 AF9013_TUNER_MXL5005R = 30 */ 535 AF9013_TUNER_MXL5005R = 30
536 AF9013_TUNER_MXL5007T = 177 */
486static struct regdesc tuner_init_mxl5005[] = { 537static struct regdesc tuner_init_mxl5005[] = {
487 { 0x9bd5, 0, 8, 0x01 }, 538 { 0x9bd5, 0, 8, 0x01 },
488 { 0x9bd6, 0, 8, 0x07 }, 539 { 0x9bd6, 0, 8, 0x07 },
@@ -791,8 +842,9 @@ static struct regdesc tuner_init_unknown[] = {
791 { 0x9bd9, 0, 8, 0x08 }, 842 { 0x9bd9, 0, 8, 0x08 },
792}; 843};
793 844
794/* NXP TDA18271 tuner init 845/* NXP TDA18271 & TDA18218 tuner init
795 AF9013_TUNER_TDA18271 = 156 */ 846 AF9013_TUNER_TDA18271 = 156
847 AF9013_TUNER_TDA18218 = 179 */
796static struct regdesc tuner_init_tda18271[] = { 848static struct regdesc tuner_init_tda18271[] = {
797 { 0x9bd5, 0, 8, 0x01 }, 849 { 0x9bd5, 0, 8, 0x01 },
798 { 0x9bd6, 0, 8, 0x04 }, 850 { 0x9bd6, 0, 8, 0x04 },
diff --git a/drivers/media/dvb/frontends/atbm8830.c b/drivers/media/dvb/frontends/atbm8830.c
index 43aac2f85c2e..1539ea1f81ac 100644
--- a/drivers/media/dvb/frontends/atbm8830.c
+++ b/drivers/media/dvb/frontends/atbm8830.c
@@ -50,8 +50,7 @@ static int atbm8830_write_reg(struct atbm_state *priv, u16 reg, u8 data)
50 msg2.addr = dev_addr; 50 msg2.addr = dev_addr;
51 51
52 if (debug >= 2) 52 if (debug >= 2)
53 printk(KERN_DEBUG "%s: reg=0x%04X, data=0x%02X\n", 53 dprintk("%s: reg=0x%04X, data=0x%02X\n", __func__, reg, data);
54 __func__, reg, data);
55 54
56 ret = i2c_transfer(priv->i2c, &msg1, 1); 55 ret = i2c_transfer(priv->i2c, &msg1, 1);
57 if (ret != 1) 56 if (ret != 1)
@@ -77,8 +76,7 @@ static int atbm8830_read_reg(struct atbm_state *priv, u16 reg, u8 *p_data)
77 76
78 ret = i2c_transfer(priv->i2c, &msg1, 1); 77 ret = i2c_transfer(priv->i2c, &msg1, 1);
79 if (ret != 1) { 78 if (ret != 1) {
80 dprintk(KERN_DEBUG "%s: error reg=0x%04x, ret=%i\n", 79 dprintk("%s: error reg=0x%04x, ret=%i\n", __func__, reg, ret);
81 __func__, reg, ret);
82 return -EIO; 80 return -EIO;
83 } 81 }
84 82
@@ -88,7 +86,7 @@ static int atbm8830_read_reg(struct atbm_state *priv, u16 reg, u8 *p_data)
88 86
89 *p_data = buf2[0]; 87 *p_data = buf2[0];
90 if (debug >= 2) 88 if (debug >= 2)
91 printk(KERN_DEBUG "%s: reg=0x%04X, data=0x%02X\n", 89 dprintk("%s: reg=0x%04X, data=0x%02X\n",
92 __func__, reg, buf2[0]); 90 __func__, reg, buf2[0]);
93 91
94 return 0; 92 return 0;
diff --git a/drivers/media/dvb/frontends/atbm8830.h b/drivers/media/dvb/frontends/atbm8830.h
index e8149f393300..024273374bd8 100644
--- a/drivers/media/dvb/frontends/atbm8830.h
+++ b/drivers/media/dvb/frontends/atbm8830.h
@@ -39,7 +39,7 @@ struct atbm8830_config {
39 /* parallel or serial transport stream */ 39 /* parallel or serial transport stream */
40 u8 serial_ts; 40 u8 serial_ts;
41 41
42 /* transport stream clock output only when receving valid stream */ 42 /* transport stream clock output only when receiving valid stream */
43 u8 ts_clk_gated; 43 u8 ts_clk_gated;
44 44
45 /* Decoder sample TS data at rising edge of clock */ 45 /* Decoder sample TS data at rising edge of clock */
diff --git a/drivers/media/dvb/frontends/au8522_decoder.c b/drivers/media/dvb/frontends/au8522_decoder.c
index 29cdbfe36852..b537891a4cc9 100644
--- a/drivers/media/dvb/frontends/au8522_decoder.c
+++ b/drivers/media/dvb/frontends/au8522_decoder.c
@@ -36,7 +36,6 @@
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <media/v4l2-common.h> 37#include <media/v4l2-common.h>
38#include <media/v4l2-chip-ident.h> 38#include <media/v4l2-chip-ident.h>
39#include <media/v4l2-i2c-drv.h>
40#include <media/v4l2-device.h> 39#include <media/v4l2-device.h>
41#include "au8522.h" 40#include "au8522.h"
42#include "au8522_priv.h" 41#include "au8522_priv.h"
@@ -279,10 +278,18 @@ static void setup_decoder_defaults(struct au8522_state *state, u8 input_mode)
279 AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS); 278 AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS);
280 au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR3_REG06BH, 279 au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR3_REG06BH,
281 AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS); 280 AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS);
282 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH, 281 if (input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13 ||
283 AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS); 282 input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24) {
284 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH, 283 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
285 AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS); 284 AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_SVIDEO);
285 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
286 AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_SVIDEO);
287 } else {
288 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
289 AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS);
290 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
291 AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS);
292 }
286 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH, 293 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH,
287 AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS); 294 AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS);
288 au8522_writereg(state, AU8522_TVDEC_UV_SEP_THR_REG06FH, 295 au8522_writereg(state, AU8522_TVDEC_UV_SEP_THR_REG06FH,
@@ -348,9 +355,11 @@ static void au8522_setup_cvbs_mode(struct au8522_state *state)
348 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H, 355 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
349 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS); 356 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
350 357
358 /* PGA in automatic mode */
351 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00); 359 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
352 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e); 360
353 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10); 361 /* Enable clamping control */
362 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
354 363
355 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, 364 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
356 AU8522_INPUT_CONTROL_REG081H_CVBS_CH1); 365 AU8522_INPUT_CONTROL_REG081H_CVBS_CH1);
@@ -367,14 +376,14 @@ static void au8522_setup_cvbs_tuner_mode(struct au8522_state *state)
367 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H, 376 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
368 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS); 377 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
369 378
370 /* It's not clear why they turn off the PGA before enabling the clamp 379 /* It's not clear why we have to have the PGA in automatic mode while
371 control, but the Windows trace does it so we will too... */ 380 enabling clamp control, but it's what Windows does */
372 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00); 381 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
373 382
374 /* Enable clamping control */ 383 /* Enable clamping control */
375 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e); 384 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e);
376 385
377 /* Turn on the PGA */ 386 /* Disable automatic PGA (since the CVBS is coming from the tuner) */
378 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10); 387 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10);
379 388
380 /* Set input mode to CVBS on channel 4 with SIF audio input enabled */ 389 /* Set input mode to CVBS on channel 4 with SIF audio input enabled */
@@ -397,7 +406,10 @@ static void au8522_setup_svideo_mode(struct au8522_state *state)
397 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, 406 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
398 AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13); 407 AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13);
399 408
400 /* Disable clamping control (required for S-video) */ 409 /* PGA in automatic mode */
410 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
411
412 /* Enable clamping control */
401 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00); 413 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
402 414
403 setup_decoder_defaults(state, 415 setup_decoder_defaults(state,
@@ -411,29 +423,15 @@ static void au8522_setup_svideo_mode(struct au8522_state *state)
411 423
412static void disable_audio_input(struct au8522_state *state) 424static void disable_audio_input(struct au8522_state *state)
413{ 425{
414 /* This can probably be optimized */
415 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00); 426 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00);
416 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00); 427 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00);
417 au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0x00); 428 au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0x00);
418 au8522_writereg(state, AU8522_I2C_CONTROL_REG1_REG091H, 0x80);
419 au8522_writereg(state, AU8522_I2C_CONTROL_REG0_REG090H, 0x84);
420
421 au8522_writereg(state, AU8522_ENA_USB_REG101H, 0x00);
422 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F);
423 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F);
424 au8522_writereg(state, AU8522_REG0F9H, AU8522_REG0F9H_AUDIO);
425 au8522_writereg(state, AU8522_AUDIO_MODE_REG0F1H, 0x40);
426
427 au8522_writereg(state, AU8522_GPIO_DATA_REG0E2H, 0x11);
428 msleep(5);
429 au8522_writereg(state, AU8522_GPIO_DATA_REG0E2H, 0x00);
430 429
431 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0x04); 430 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0x04);
432 au8522_writereg(state, AU8522_AUDIOFREQ_REG606H, 0x03);
433 au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0x02); 431 au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0x02);
434 432
435 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 433 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
436 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS); 434 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_SVIDEO);
437} 435}
438 436
439/* 0=disable, 1=SIF */ 437/* 0=disable, 1=SIF */
@@ -623,7 +621,7 @@ static int au8522_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
623 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 621 return v4l2_ctrl_query_fill(qc, 0, 255, 1,
624 AU8522_TVDEC_CONTRAST_REG00BH_CVBS); 622 AU8522_TVDEC_CONTRAST_REG00BH_CVBS);
625 case V4L2_CID_BRIGHTNESS: 623 case V4L2_CID_BRIGHTNESS:
626 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128); 624 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 109);
627 case V4L2_CID_SATURATION: 625 case V4L2_CID_SATURATION:
628 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128); 626 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
629 case V4L2_CID_HUE: 627 case V4L2_CID_HUE:
@@ -831,9 +829,25 @@ static const struct i2c_device_id au8522_id[] = {
831 829
832MODULE_DEVICE_TABLE(i2c, au8522_id); 830MODULE_DEVICE_TABLE(i2c, au8522_id);
833 831
834static struct v4l2_i2c_driver_data v4l2_i2c_data = { 832static struct i2c_driver au8522_driver = {
835 .name = "au8522", 833 .driver = {
836 .probe = au8522_probe, 834 .owner = THIS_MODULE,
837 .remove = au8522_remove, 835 .name = "au8522",
838 .id_table = au8522_id, 836 },
837 .probe = au8522_probe,
838 .remove = au8522_remove,
839 .id_table = au8522_id,
839}; 840};
841
842static __init int init_au8522(void)
843{
844 return i2c_add_driver(&au8522_driver);
845}
846
847static __exit void exit_au8522(void)
848{
849 i2c_del_driver(&au8522_driver);
850}
851
852module_init(init_au8522);
853module_exit(exit_au8522);
diff --git a/drivers/media/dvb/frontends/au8522_dig.c b/drivers/media/dvb/frontends/au8522_dig.c
index 65f6a36dfb21..1d572940e243 100644
--- a/drivers/media/dvb/frontends/au8522_dig.c
+++ b/drivers/media/dvb/frontends/au8522_dig.c
@@ -635,7 +635,7 @@ static int au8522_led_gpio_enable(struct au8522_state *state, int onoff)
635 struct au8522_led_config *led_config = state->config->led_cfg; 635 struct au8522_led_config *led_config = state->config->led_cfg;
636 u8 val; 636 u8 val;
637 637
638 /* bail out if we cant control an LED */ 638 /* bail out if we can't control an LED */
639 if (!led_config || !led_config->gpio_output || 639 if (!led_config || !led_config->gpio_output ||
640 !led_config->gpio_output_enable || !led_config->gpio_output_disable) 640 !led_config->gpio_output_enable || !led_config->gpio_output_disable)
641 return 0; 641 return 0;
@@ -665,7 +665,7 @@ static int au8522_led_ctrl(struct au8522_state *state, int led)
665 struct au8522_led_config *led_config = state->config->led_cfg; 665 struct au8522_led_config *led_config = state->config->led_cfg;
666 int i, ret = 0; 666 int i, ret = 0;
667 667
668 /* bail out if we cant control an LED */ 668 /* bail out if we can't control an LED */
669 if (!led_config || !led_config->gpio_leds || 669 if (!led_config || !led_config->gpio_leds ||
670 !led_config->num_led_states || !led_config->led_states) 670 !led_config->num_led_states || !led_config->led_states)
671 return 0; 671 return 0;
@@ -803,7 +803,7 @@ static int au8522_led_status(struct au8522_state *state, const u16 *snr)
803 int led; 803 int led;
804 u16 strong; 804 u16 strong;
805 805
806 /* bail out if we cant control an LED */ 806 /* bail out if we can't control an LED */
807 if (!led_config) 807 if (!led_config)
808 return 0; 808 return 0;
809 809
diff --git a/drivers/media/dvb/frontends/au8522_priv.h b/drivers/media/dvb/frontends/au8522_priv.h
index 609cf04bc312..751e17d692a9 100644
--- a/drivers/media/dvb/frontends/au8522_priv.h
+++ b/drivers/media/dvb/frontends/au8522_priv.h
@@ -397,7 +397,9 @@ void au8522_release_state(struct au8522_state *state);
397#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS 0x0A 397#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS 0x0A
398#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS 0x32 398#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS 0x32
399#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS 0x34 399#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS 0x34
400#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_SVIDEO 0x2a
400#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS 0x05 401#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS 0x05
402#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_SVIDEO 0x15
401#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS 0x6E 403#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS 0x6E
402#define AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS 0x0F 404#define AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS 0x0F
403#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS 0x80 405#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS 0x80
diff --git a/drivers/media/dvb/frontends/bcm3510.c b/drivers/media/dvb/frontends/bcm3510.c
index cf5e576dfdcf..8aff5868a5e1 100644
--- a/drivers/media/dvb/frontends/bcm3510.c
+++ b/drivers/media/dvb/frontends/bcm3510.c
@@ -155,7 +155,7 @@ static int bcm3510_hab_send_request(struct bcm3510_state *st, u8 *buf, int len)
155 unsigned long t; 155 unsigned long t;
156 156
157/* Check if any previous HAB request still needs to be serviced by the 157/* Check if any previous HAB request still needs to be serviced by the
158 * Aquisition Processor before sending new request */ 158 * Acquisition Processor before sending new request */
159 if ((ret = bcm3510_readB(st,0xa8,&v)) < 0) 159 if ((ret = bcm3510_readB(st,0xa8,&v)) < 0)
160 return ret; 160 return ret;
161 if (v.HABSTAT_a8.HABR) { 161 if (v.HABSTAT_a8.HABR) {
@@ -361,7 +361,7 @@ static int bcm3510_tuner_cmd(struct bcm3510_state* st,u8 bc, u16 n, u8 a)
361/* Set duration of the initial state of TUNCTL = 3.34 micro Sec */ 361/* Set duration of the initial state of TUNCTL = 3.34 micro Sec */
362 c.TUNCTL_state = 0x40; 362 c.TUNCTL_state = 0x40;
363 363
364/* PRESCALER DEVIDE RATIO | BC1_2_3_4; (band switch), 1stosc REFERENCE COUNTER REF_S12 and REF_S11 */ 364/* PRESCALER DIVIDE RATIO | BC1_2_3_4; (band switch), 1stosc REFERENCE COUNTER REF_S12 and REF_S11 */
365 c.ctl_dat[0].ctrl.size = BITS_8; 365 c.ctl_dat[0].ctrl.size = BITS_8;
366 c.ctl_dat[0].data = 0x80 | bc; 366 c.ctl_dat[0].data = 0x80 | bc;
367 367
@@ -397,7 +397,7 @@ static int bcm3510_tuner_cmd(struct bcm3510_state* st,u8 bc, u16 n, u8 a)
397 c.ctl_dat[7].ctrl.cs0 = 1; 397 c.ctl_dat[7].ctrl.cs0 = 1;
398 c.ctl_dat[7].data = 0x40; 398 c.ctl_dat[7].data = 0x40;
399 399
400/* PRESCALER DEVIDE RATIO, 2ndosc REFERENCE COUNTER REF_S12 and REF_S11 */ 400/* PRESCALER DIVIDE RATIO, 2ndosc REFERENCE COUNTER REF_S12 and REF_S11 */
401 c.ctl_dat[8].ctrl.size = BITS_8; 401 c.ctl_dat[8].ctrl.size = BITS_8;
402 c.ctl_dat[8].data = 0x80; 402 c.ctl_dat[8].data = 0x80;
403 403
diff --git a/drivers/media/dvb/frontends/bsbe1-d01a.h b/drivers/media/dvb/frontends/bsbe1-d01a.h
new file mode 100644
index 000000000000..7ed3c424178c
--- /dev/null
+++ b/drivers/media/dvb/frontends/bsbe1-d01a.h
@@ -0,0 +1,146 @@
1/*
2 * bsbe1-d01a.h - ALPS BSBE1-D01A tuner support
3 *
4 * Copyright (C) 2011 Oliver Endriss <o.endriss@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
22 *
23 *
24 * the project's page is at http://www.linuxtv.org
25 */
26
27#ifndef BSBE1_D01A_H
28#define BSBE1_D01A_H
29
30#include "stb6000.h"
31#include "stv0288.h"
32
33static u8 stv0288_bsbe1_d01a_inittab[] = {
34 0x01, 0x15,
35 0x02, 0x20,
36 0x09, 0x0,
37 0x0a, 0x4,
38 0x0b, 0x0,
39 0x0c, 0x0,
40 0x0d, 0x0,
41 0x0e, 0xd4,
42 0x0f, 0x30,
43 0x11, 0x80,
44 0x12, 0x03,
45 0x13, 0x48,
46 0x14, 0x84,
47 0x15, 0x45,
48 0x16, 0xb7,
49 0x17, 0x9c,
50 0x18, 0x0,
51 0x19, 0xa6,
52 0x1a, 0x88,
53 0x1b, 0x8f,
54 0x1c, 0xf0,
55 0x20, 0x0b,
56 0x21, 0x54,
57 0x22, 0x0,
58 0x23, 0x0,
59 0x2b, 0xff,
60 0x2c, 0xf7,
61 0x30, 0x0,
62 0x31, 0x1e,
63 0x32, 0x14,
64 0x33, 0x0f,
65 0x34, 0x09,
66 0x35, 0x0c,
67 0x36, 0x05,
68 0x37, 0x2f,
69 0x38, 0x16,
70 0x39, 0xbd,
71 0x3a, 0x03,
72 0x3b, 0x13,
73 0x3c, 0x11,
74 0x3d, 0x30,
75 0x40, 0x63,
76 0x41, 0x04,
77 0x42, 0x60,
78 0x43, 0x00,
79 0x44, 0x00,
80 0x45, 0x00,
81 0x46, 0x00,
82 0x47, 0x00,
83 0x4a, 0x00,
84 0x50, 0x10,
85 0x51, 0x36,
86 0x52, 0x09,
87 0x53, 0x94,
88 0x54, 0x62,
89 0x55, 0x29,
90 0x56, 0x64,
91 0x57, 0x2b,
92 0x58, 0x54,
93 0x59, 0x86,
94 0x5a, 0x0,
95 0x5b, 0x9b,
96 0x5c, 0x08,
97 0x5d, 0x7f,
98 0x5e, 0x0,
99 0x5f, 0xff,
100 0x70, 0x0,
101 0x71, 0x0,
102 0x72, 0x0,
103 0x74, 0x0,
104 0x75, 0x0,
105 0x76, 0x0,
106 0x81, 0x0,
107 0x82, 0x3f,
108 0x83, 0x3f,
109 0x84, 0x0,
110 0x85, 0x0,
111 0x88, 0x0,
112 0x89, 0x0,
113 0x8a, 0x0,
114 0x8b, 0x0,
115 0x8c, 0x0,
116 0x90, 0x0,
117 0x91, 0x0,
118 0x92, 0x0,
119 0x93, 0x0,
120 0x94, 0x1c,
121 0x97, 0x0,
122 0xa0, 0x48,
123 0xa1, 0x0,
124 0xb0, 0xb8,
125 0xb1, 0x3a,
126 0xb2, 0x10,
127 0xb3, 0x82,
128 0xb4, 0x80,
129 0xb5, 0x82,
130 0xb6, 0x82,
131 0xb7, 0x82,
132 0xb8, 0x20,
133 0xb9, 0x0,
134 0xf0, 0x0,
135 0xf1, 0x0,
136 0xf2, 0xc0,
137 0xff, 0xff,
138};
139
140static struct stv0288_config stv0288_bsbe1_d01a_config = {
141 .demod_address = 0x68,
142 .min_delay_ms = 100,
143 .inittab = stv0288_bsbe1_d01a_inittab,
144};
145
146#endif
diff --git a/drivers/media/dvb/frontends/bsru6.h b/drivers/media/dvb/frontends/bsru6.h
index 45a6dfd8ebb5..c480c839b302 100644
--- a/drivers/media/dvb/frontends/bsru6.h
+++ b/drivers/media/dvb/frontends/bsru6.h
@@ -27,7 +27,7 @@
27 27
28static u8 alps_bsru6_inittab[] = { 28static u8 alps_bsru6_inittab[] = {
29 0x01, 0x15, 29 0x01, 0x15,
30 0x02, 0x00, 30 0x02, 0x30,
31 0x03, 0x00, 31 0x03, 0x00,
32 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */ 32 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
33 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */ 33 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
diff --git a/drivers/media/dvb/frontends/cx22700.c b/drivers/media/dvb/frontends/cx22700.c
index 5fbc0fc37ecd..0142214b0133 100644
--- a/drivers/media/dvb/frontends/cx22700.c
+++ b/drivers/media/dvb/frontends/cx22700.c
@@ -179,7 +179,7 @@ static int cx22700_set_tps (struct cx22700_state *state, struct dvb_ofdm_paramet
179 cx22700_writereg (state, 0x06, val); 179 cx22700_writereg (state, 0x06, val);
180 180
181 cx22700_writereg (state, 0x08, 0x04 | 0x02); /* use user tps parameters */ 181 cx22700_writereg (state, 0x08, 0x04 | 0x02); /* use user tps parameters */
182 cx22700_writereg (state, 0x08, 0x04); /* restart aquisition */ 182 cx22700_writereg (state, 0x08, 0x04); /* restart acquisition */
183 183
184 return 0; 184 return 0;
185} 185}
diff --git a/drivers/media/dvb/frontends/cx22702.c b/drivers/media/dvb/frontends/cx22702.c
index 00b5c7e91d5d..3139558148ba 100644
--- a/drivers/media/dvb/frontends/cx22702.c
+++ b/drivers/media/dvb/frontends/cx22702.c
@@ -54,8 +54,8 @@ MODULE_PARM_DESC(debug, "Enable verbose debug messages");
54#define dprintk if (debug) printk 54#define dprintk if (debug) printk
55 55
56/* Register values to initialise the demod */ 56/* Register values to initialise the demod */
57static u8 init_tab[] = { 57static const u8 init_tab[] = {
58 0x00, 0x00, /* Stop aquisition */ 58 0x00, 0x00, /* Stop acquisition */
59 0x0B, 0x06, 59 0x0B, 0x06,
60 0x09, 0x01, 60 0x09, 0x01,
61 0x0D, 0x41, 61 0x0D, 0x41,
@@ -92,52 +92,56 @@ static int cx22702_writereg(struct cx22702_state *state, u8 reg, u8 data)
92 92
93 ret = i2c_transfer(state->i2c, &msg, 1); 93 ret = i2c_transfer(state->i2c, &msg, 1);
94 94
95 if (ret != 1) 95 if (unlikely(ret != 1)) {
96 printk(KERN_ERR 96 printk(KERN_ERR
97 "%s: error (reg == 0x%02x, val == 0x%02x, ret == %i)\n", 97 "%s: error (reg == 0x%02x, val == 0x%02x, ret == %i)\n",
98 __func__, reg, data, ret); 98 __func__, reg, data, ret);
99 return -1;
100 }
99 101
100 return (ret != 1) ? -1 : 0; 102 return 0;
101} 103}
102 104
103static u8 cx22702_readreg(struct cx22702_state *state, u8 reg) 105static u8 cx22702_readreg(struct cx22702_state *state, u8 reg)
104{ 106{
105 int ret; 107 int ret;
106 u8 b0[] = { reg }; 108 u8 data;
107 u8 b1[] = { 0 };
108 109
109 struct i2c_msg msg[] = { 110 struct i2c_msg msg[] = {
110 { .addr = state->config->demod_address, .flags = 0, 111 { .addr = state->config->demod_address, .flags = 0,
111 .buf = b0, .len = 1 }, 112 .buf = &reg, .len = 1 },
112 { .addr = state->config->demod_address, .flags = I2C_M_RD, 113 { .addr = state->config->demod_address, .flags = I2C_M_RD,
113 .buf = b1, .len = 1 } }; 114 .buf = &data, .len = 1 } };
114 115
115 ret = i2c_transfer(state->i2c, msg, 2); 116 ret = i2c_transfer(state->i2c, msg, 2);
116 117
117 if (ret != 2) 118 if (unlikely(ret != 2)) {
118 printk(KERN_ERR "%s: readreg error (ret == %i)\n", 119 printk(KERN_ERR "%s: error (reg == 0x%02x, ret == %i)\n",
119 __func__, ret); 120 __func__, reg, ret);
121 return 0;
122 }
120 123
121 return b1[0]; 124 return data;
122} 125}
123 126
124static int cx22702_set_inversion(struct cx22702_state *state, int inversion) 127static int cx22702_set_inversion(struct cx22702_state *state, int inversion)
125{ 128{
126 u8 val; 129 u8 val;
127 130
131 val = cx22702_readreg(state, 0x0C);
128 switch (inversion) { 132 switch (inversion) {
129 case INVERSION_AUTO: 133 case INVERSION_AUTO:
130 return -EOPNOTSUPP; 134 return -EOPNOTSUPP;
131 case INVERSION_ON: 135 case INVERSION_ON:
132 val = cx22702_readreg(state, 0x0C); 136 val |= 0x01;
133 return cx22702_writereg(state, 0x0C, val | 0x01); 137 break;
134 case INVERSION_OFF: 138 case INVERSION_OFF:
135 val = cx22702_readreg(state, 0x0C); 139 val &= 0xfe;
136 return cx22702_writereg(state, 0x0C, val & 0xfe); 140 break;
137 default: 141 default:
138 return -EINVAL; 142 return -EINVAL;
139 } 143 }
140 144 return cx22702_writereg(state, 0x0C, val);
141} 145}
142 146
143/* Retrieve the demod settings */ 147/* Retrieve the demod settings */
@@ -244,13 +248,15 @@ static int cx22702_get_tps(struct cx22702_state *state,
244static int cx22702_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) 248static int cx22702_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
245{ 249{
246 struct cx22702_state *state = fe->demodulator_priv; 250 struct cx22702_state *state = fe->demodulator_priv;
251 u8 val;
252
247 dprintk("%s(%d)\n", __func__, enable); 253 dprintk("%s(%d)\n", __func__, enable);
254 val = cx22702_readreg(state, 0x0D);
248 if (enable) 255 if (enable)
249 return cx22702_writereg(state, 0x0D, 256 val &= 0xfe;
250 cx22702_readreg(state, 0x0D) & 0xfe);
251 else 257 else
252 return cx22702_writereg(state, 0x0D, 258 val |= 0x01;
253 cx22702_readreg(state, 0x0D) | 1); 259 return cx22702_writereg(state, 0x0D, val);
254} 260}
255 261
256/* Talk to the demod, set the FEC, GUARD, QAM settings etc */ 262/* Talk to the demod, set the FEC, GUARD, QAM settings etc */
@@ -270,23 +276,21 @@ static int cx22702_set_tps(struct dvb_frontend *fe,
270 cx22702_set_inversion(state, p->inversion); 276 cx22702_set_inversion(state, p->inversion);
271 277
272 /* set bandwidth */ 278 /* set bandwidth */
279 val = cx22702_readreg(state, 0x0C) & 0xcf;
273 switch (p->u.ofdm.bandwidth) { 280 switch (p->u.ofdm.bandwidth) {
274 case BANDWIDTH_6_MHZ: 281 case BANDWIDTH_6_MHZ:
275 cx22702_writereg(state, 0x0C, 282 val |= 0x20;
276 (cx22702_readreg(state, 0x0C) & 0xcf) | 0x20);
277 break; 283 break;
278 case BANDWIDTH_7_MHZ: 284 case BANDWIDTH_7_MHZ:
279 cx22702_writereg(state, 0x0C, 285 val |= 0x10;
280 (cx22702_readreg(state, 0x0C) & 0xcf) | 0x10);
281 break; 286 break;
282 case BANDWIDTH_8_MHZ: 287 case BANDWIDTH_8_MHZ:
283 cx22702_writereg(state, 0x0C,
284 cx22702_readreg(state, 0x0C) & 0xcf);
285 break; 288 break;
286 default: 289 default:
287 dprintk("%s: invalid bandwidth\n", __func__); 290 dprintk("%s: invalid bandwidth\n", __func__);
288 return -EINVAL; 291 return -EINVAL;
289 } 292 }
293 cx22702_writereg(state, 0x0C, val);
290 294
291 p->u.ofdm.code_rate_LP = FEC_AUTO; /* temp hack as manual not working */ 295 p->u.ofdm.code_rate_LP = FEC_AUTO; /* temp hack as manual not working */
292 296
@@ -306,39 +310,37 @@ static int cx22702_set_tps(struct dvb_frontend *fe,
306 & 0xfc); 310 & 0xfc);
307 cx22702_writereg(state, 0x0C, 311 cx22702_writereg(state, 0x0C,
308 (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40); 312 (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40);
309 cx22702_writereg(state, 0x00, 0x01); /* Begin aquisition */ 313 cx22702_writereg(state, 0x00, 0x01); /* Begin acquisition */
310 dprintk("%s: Autodetecting\n", __func__); 314 dprintk("%s: Autodetecting\n", __func__);
311 return 0; 315 return 0;
312 } 316 }
313 317
314 /* manually programmed values */ 318 /* manually programmed values */
315 val = 0; 319 switch (p->u.ofdm.constellation) { /* mask 0x18 */
316 switch (p->u.ofdm.constellation) {
317 case QPSK: 320 case QPSK:
318 val = (val & 0xe7); 321 val = 0x00;
319 break; 322 break;
320 case QAM_16: 323 case QAM_16:
321 val = (val & 0xe7) | 0x08; 324 val = 0x08;
322 break; 325 break;
323 case QAM_64: 326 case QAM_64:
324 val = (val & 0xe7) | 0x10; 327 val = 0x10;
325 break; 328 break;
326 default: 329 default:
327 dprintk("%s: invalid constellation\n", __func__); 330 dprintk("%s: invalid constellation\n", __func__);
328 return -EINVAL; 331 return -EINVAL;
329 } 332 }
330 switch (p->u.ofdm.hierarchy_information) { 333 switch (p->u.ofdm.hierarchy_information) { /* mask 0x07 */
331 case HIERARCHY_NONE: 334 case HIERARCHY_NONE:
332 val = (val & 0xf8);
333 break; 335 break;
334 case HIERARCHY_1: 336 case HIERARCHY_1:
335 val = (val & 0xf8) | 1; 337 val |= 0x01;
336 break; 338 break;
337 case HIERARCHY_2: 339 case HIERARCHY_2:
338 val = (val & 0xf8) | 2; 340 val |= 0x02;
339 break; 341 break;
340 case HIERARCHY_4: 342 case HIERARCHY_4:
341 val = (val & 0xf8) | 3; 343 val |= 0x03;
342 break; 344 break;
343 default: 345 default:
344 dprintk("%s: invalid hierarchy\n", __func__); 346 dprintk("%s: invalid hierarchy\n", __func__);
@@ -346,44 +348,42 @@ static int cx22702_set_tps(struct dvb_frontend *fe,
346 } 348 }
347 cx22702_writereg(state, 0x06, val); 349 cx22702_writereg(state, 0x06, val);
348 350
349 val = 0; 351 switch (p->u.ofdm.code_rate_HP) { /* mask 0x38 */
350 switch (p->u.ofdm.code_rate_HP) {
351 case FEC_NONE: 352 case FEC_NONE:
352 case FEC_1_2: 353 case FEC_1_2:
353 val = (val & 0xc7); 354 val = 0x00;
354 break; 355 break;
355 case FEC_2_3: 356 case FEC_2_3:
356 val = (val & 0xc7) | 0x08; 357 val = 0x08;
357 break; 358 break;
358 case FEC_3_4: 359 case FEC_3_4:
359 val = (val & 0xc7) | 0x10; 360 val = 0x10;
360 break; 361 break;
361 case FEC_5_6: 362 case FEC_5_6:
362 val = (val & 0xc7) | 0x18; 363 val = 0x18;
363 break; 364 break;
364 case FEC_7_8: 365 case FEC_7_8:
365 val = (val & 0xc7) | 0x20; 366 val = 0x20;
366 break; 367 break;
367 default: 368 default:
368 dprintk("%s: invalid code_rate_HP\n", __func__); 369 dprintk("%s: invalid code_rate_HP\n", __func__);
369 return -EINVAL; 370 return -EINVAL;
370 } 371 }
371 switch (p->u.ofdm.code_rate_LP) { 372 switch (p->u.ofdm.code_rate_LP) { /* mask 0x07 */
372 case FEC_NONE: 373 case FEC_NONE:
373 case FEC_1_2: 374 case FEC_1_2:
374 val = (val & 0xf8);
375 break; 375 break;
376 case FEC_2_3: 376 case FEC_2_3:
377 val = (val & 0xf8) | 1; 377 val |= 0x01;
378 break; 378 break;
379 case FEC_3_4: 379 case FEC_3_4:
380 val = (val & 0xf8) | 2; 380 val |= 0x02;
381 break; 381 break;
382 case FEC_5_6: 382 case FEC_5_6:
383 val = (val & 0xf8) | 3; 383 val |= 0x03;
384 break; 384 break;
385 case FEC_7_8: 385 case FEC_7_8:
386 val = (val & 0xf8) | 4; 386 val |= 0x04;
387 break; 387 break;
388 default: 388 default:
389 dprintk("%s: invalid code_rate_LP\n", __func__); 389 dprintk("%s: invalid code_rate_LP\n", __func__);
@@ -391,30 +391,28 @@ static int cx22702_set_tps(struct dvb_frontend *fe,
391 } 391 }
392 cx22702_writereg(state, 0x07, val); 392 cx22702_writereg(state, 0x07, val);
393 393
394 val = 0; 394 switch (p->u.ofdm.guard_interval) { /* mask 0x0c */
395 switch (p->u.ofdm.guard_interval) {
396 case GUARD_INTERVAL_1_32: 395 case GUARD_INTERVAL_1_32:
397 val = (val & 0xf3); 396 val = 0x00;
398 break; 397 break;
399 case GUARD_INTERVAL_1_16: 398 case GUARD_INTERVAL_1_16:
400 val = (val & 0xf3) | 0x04; 399 val = 0x04;
401 break; 400 break;
402 case GUARD_INTERVAL_1_8: 401 case GUARD_INTERVAL_1_8:
403 val = (val & 0xf3) | 0x08; 402 val = 0x08;
404 break; 403 break;
405 case GUARD_INTERVAL_1_4: 404 case GUARD_INTERVAL_1_4:
406 val = (val & 0xf3) | 0x0c; 405 val = 0x0c;
407 break; 406 break;
408 default: 407 default:
409 dprintk("%s: invalid guard_interval\n", __func__); 408 dprintk("%s: invalid guard_interval\n", __func__);
410 return -EINVAL; 409 return -EINVAL;
411 } 410 }
412 switch (p->u.ofdm.transmission_mode) { 411 switch (p->u.ofdm.transmission_mode) { /* mask 0x03 */
413 case TRANSMISSION_MODE_2K: 412 case TRANSMISSION_MODE_2K:
414 val = (val & 0xfc);
415 break; 413 break;
416 case TRANSMISSION_MODE_8K: 414 case TRANSMISSION_MODE_8K:
417 val = (val & 0xfc) | 1; 415 val |= 0x1;
418 break; 416 break;
419 default: 417 default:
420 dprintk("%s: invalid transmission_mode\n", __func__); 418 dprintk("%s: invalid transmission_mode\n", __func__);
@@ -426,7 +424,7 @@ static int cx22702_set_tps(struct dvb_frontend *fe,
426 cx22702_writereg(state, 0x0C, 424 cx22702_writereg(state, 0x0C,
427 (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40); 425 (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40);
428 426
429 /* Begin channel aquisition */ 427 /* Begin channel acquisition */
430 cx22702_writereg(state, 0x00, 0x01); 428 cx22702_writereg(state, 0x00, 0x01);
431 429
432 return 0; 430 return 0;
@@ -505,7 +503,7 @@ static int cx22702_read_signal_strength(struct dvb_frontend *fe,
505{ 503{
506 struct cx22702_state *state = fe->demodulator_priv; 504 struct cx22702_state *state = fe->demodulator_priv;
507 505
508 u16 rs_ber = 0; 506 u16 rs_ber;
509 rs_ber = cx22702_readreg(state, 0x23); 507 rs_ber = cx22702_readreg(state, 0x23);
510 *signal_strength = (rs_ber << 8) | rs_ber; 508 *signal_strength = (rs_ber << 8) | rs_ber;
511 509
@@ -516,7 +514,7 @@ static int cx22702_read_snr(struct dvb_frontend *fe, u16 *snr)
516{ 514{
517 struct cx22702_state *state = fe->demodulator_priv; 515 struct cx22702_state *state = fe->demodulator_priv;
518 516
519 u16 rs_ber = 0; 517 u16 rs_ber;
520 if (cx22702_readreg(state, 0xE4) & 0x02) { 518 if (cx22702_readreg(state, 0xE4) & 0x02) {
521 /* Realtime statistics */ 519 /* Realtime statistics */
522 rs_ber = (cx22702_readreg(state, 0xDE) & 0x7F) << 7 520 rs_ber = (cx22702_readreg(state, 0xDE) & 0x7F) << 7
@@ -572,7 +570,7 @@ static void cx22702_release(struct dvb_frontend *fe)
572 kfree(state); 570 kfree(state);
573} 571}
574 572
575static struct dvb_frontend_ops cx22702_ops; 573static const struct dvb_frontend_ops cx22702_ops;
576 574
577struct dvb_frontend *cx22702_attach(const struct cx22702_config *config, 575struct dvb_frontend *cx22702_attach(const struct cx22702_config *config,
578 struct i2c_adapter *i2c) 576 struct i2c_adapter *i2c)
@@ -587,7 +585,6 @@ struct dvb_frontend *cx22702_attach(const struct cx22702_config *config,
587 /* setup the state */ 585 /* setup the state */
588 state->config = config; 586 state->config = config;
589 state->i2c = i2c; 587 state->i2c = i2c;
590 state->prevUCBlocks = 0;
591 588
592 /* check if the demod is there */ 589 /* check if the demod is there */
593 if (cx22702_readreg(state, 0x1f) != 0x3) 590 if (cx22702_readreg(state, 0x1f) != 0x3)
@@ -605,7 +602,7 @@ error:
605} 602}
606EXPORT_SYMBOL(cx22702_attach); 603EXPORT_SYMBOL(cx22702_attach);
607 604
608static struct dvb_frontend_ops cx22702_ops = { 605static const struct dvb_frontend_ops cx22702_ops = {
609 606
610 .info = { 607 .info = {
611 .name = "Conexant CX22702 DVB-T", 608 .name = "Conexant CX22702 DVB-T",
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index 00a4e8f03304..bf9c999aa470 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -310,7 +310,7 @@ static int cx24110_set_symbolrate (struct cx24110_state* state, u32 srate)
310 310
311} 311}
312 312
313static int _cx24110_pll_write (struct dvb_frontend* fe, u8 *buf, int len) 313static int _cx24110_pll_write (struct dvb_frontend* fe, const u8 buf[], int len)
314{ 314{
315 struct cx24110_state *state = fe->demodulator_priv; 315 struct cx24110_state *state = fe->demodulator_priv;
316 316
@@ -544,7 +544,7 @@ static int cx24110_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
544 cx24110_set_inversion (state, p->inversion); 544 cx24110_set_inversion (state, p->inversion);
545 cx24110_set_fec (state, p->u.qpsk.fec_inner); 545 cx24110_set_fec (state, p->u.qpsk.fec_inner);
546 cx24110_set_symbolrate (state, p->u.qpsk.symbol_rate); 546 cx24110_set_symbolrate (state, p->u.qpsk.symbol_rate);
547 cx24110_writereg(state,0x04,0x05); /* start aquisition */ 547 cx24110_writereg(state,0x04,0x05); /* start acquisition */
548 548
549 return 0; 549 return 0;
550} 550}
diff --git a/drivers/media/dvb/frontends/cx24113.h b/drivers/media/dvb/frontends/cx24113.h
index 5de0f7ffd8d2..01eb7b9c28f4 100644
--- a/drivers/media/dvb/frontends/cx24113.h
+++ b/drivers/media/dvb/frontends/cx24113.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Driver for Conexant CX24113/CX24128 Tuner (Satelite) 2 * Driver for Conexant CX24113/CX24128 Tuner (Satellite)
3 * 3 *
4 * Copyright (C) 2007-8 Patrick Boettcher <pb@linuxtv.org> 4 * Copyright (C) 2007-8 Patrick Boettcher <pb@linuxtv.org>
5 * 5 *
diff --git a/drivers/media/dvb/frontends/cx24116.c b/drivers/media/dvb/frontends/cx24116.c
index 2410d8b59b6b..95c6465b87a1 100644
--- a/drivers/media/dvb/frontends/cx24116.c
+++ b/drivers/media/dvb/frontends/cx24116.c
@@ -137,7 +137,7 @@ MODULE_PARM_DESC(toneburst, "DiSEqC toneburst 0=OFF, 1=TONE CACHE, "\
137/* SNR measurements */ 137/* SNR measurements */
138static int esno_snr; 138static int esno_snr;
139module_param(esno_snr, int, 0644); 139module_param(esno_snr, int, 0644);
140MODULE_PARM_DESC(debug, "SNR return units, 0=PERCENTAGE 0-100, "\ 140MODULE_PARM_DESC(esno_snr, "SNR return units, 0=PERCENTAGE 0-100, "\
141 "1=ESNO(db * 10) (default:0)"); 141 "1=ESNO(db * 10) (default:0)");
142 142
143enum cmds { 143enum cmds {
@@ -566,7 +566,7 @@ static int cx24116_load_firmware(struct dvb_frontend *fe,
566{ 566{
567 struct cx24116_state *state = fe->demodulator_priv; 567 struct cx24116_state *state = fe->demodulator_priv;
568 struct cx24116_cmd cmd; 568 struct cx24116_cmd cmd;
569 int i, ret; 569 int i, ret, len, max, remaining;
570 unsigned char vers[4]; 570 unsigned char vers[4];
571 571
572 dprintk("%s\n", __func__); 572 dprintk("%s\n", __func__);
@@ -603,8 +603,21 @@ static int cx24116_load_firmware(struct dvb_frontend *fe,
603 cx24116_writereg(state, 0xF5, 0x00); 603 cx24116_writereg(state, 0xF5, 0x00);
604 cx24116_writereg(state, 0xF6, 0x00); 604 cx24116_writereg(state, 0xF6, 0x00);
605 605
606 /* write the entire firmware as one transaction */ 606 /* Split firmware to the max I2C write len and write.
607 cx24116_writeregN(state, 0xF7, fw->data, fw->size); 607 * Writes whole firmware as one write when i2c_wr_max is set to 0. */
608 if (state->config->i2c_wr_max)
609 max = state->config->i2c_wr_max;
610 else
611 max = INT_MAX; /* enough for 32k firmware */
612
613 for (remaining = fw->size; remaining > 0; remaining -= max - 1) {
614 len = remaining;
615 if (len > max - 1)
616 len = max - 1;
617
618 cx24116_writeregN(state, 0xF7, &fw->data[fw->size - remaining],
619 len);
620 }
608 621
609 cx24116_writereg(state, 0xF4, 0x10); 622 cx24116_writereg(state, 0xF4, 0x10);
610 cx24116_writereg(state, 0xF0, 0x00); 623 cx24116_writereg(state, 0xF0, 0x00);
diff --git a/drivers/media/dvb/frontends/cx24116.h b/drivers/media/dvb/frontends/cx24116.h
index b1b76b47a14c..7d90ab949c03 100644
--- a/drivers/media/dvb/frontends/cx24116.h
+++ b/drivers/media/dvb/frontends/cx24116.h
@@ -35,6 +35,9 @@ struct cx24116_config {
35 35
36 /* Need to set MPEG parameters */ 36 /* Need to set MPEG parameters */
37 u8 mpg_clk_pos_pol:0x02; 37 u8 mpg_clk_pos_pol:0x02;
38
39 /* max bytes I2C provider can write at once */
40 u16 i2c_wr_max;
38}; 41};
39 42
40#if defined(CONFIG_DVB_CX24116) || \ 43#if defined(CONFIG_DVB_CX24116) || \
diff --git a/drivers/media/dvb/frontends/cx24123.c b/drivers/media/dvb/frontends/cx24123.c
index d8f921b6fafd..b1dd8acc607a 100644
--- a/drivers/media/dvb/frontends/cx24123.c
+++ b/drivers/media/dvb/frontends/cx24123.c
@@ -949,7 +949,7 @@ static int cx24123_set_frontend(struct dvb_frontend *fe,
949 else 949 else
950 err("it seems I don't have a tuner..."); 950 err("it seems I don't have a tuner...");
951 951
952 /* Enable automatic aquisition and reset cycle */ 952 /* Enable automatic acquisition and reset cycle */
953 cx24123_writereg(state, 0x03, (cx24123_readreg(state, 0x03) | 0x07)); 953 cx24123_writereg(state, 0x03, (cx24123_readreg(state, 0x03) | 0x07));
954 cx24123_writereg(state, 0x00, 0x10); 954 cx24123_writereg(state, 0x00, 0x10);
955 cx24123_writereg(state, 0x00, 0); 955 cx24123_writereg(state, 0x00, 0);
@@ -1108,7 +1108,6 @@ struct dvb_frontend *cx24123_attach(const struct cx24123_config *config,
1108 1108
1109 strlcpy(state->tuner_i2c_adapter.name, "CX24123 tuner I2C bus", 1109 strlcpy(state->tuner_i2c_adapter.name, "CX24123 tuner I2C bus",
1110 sizeof(state->tuner_i2c_adapter.name)); 1110 sizeof(state->tuner_i2c_adapter.name));
1111 state->tuner_i2c_adapter.class = I2C_CLASS_TV_DIGITAL,
1112 state->tuner_i2c_adapter.algo = &cx24123_tuner_i2c_algo; 1111 state->tuner_i2c_adapter.algo = &cx24123_tuner_i2c_algo;
1113 state->tuner_i2c_adapter.algo_data = NULL; 1112 state->tuner_i2c_adapter.algo_data = NULL;
1114 i2c_set_adapdata(&state->tuner_i2c_adapter, state); 1113 i2c_set_adapdata(&state->tuner_i2c_adapter, state);
diff --git a/drivers/media/dvb/frontends/cxd2820r.h b/drivers/media/dvb/frontends/cxd2820r.h
new file mode 100644
index 000000000000..ad17845123d9
--- /dev/null
+++ b/drivers/media/dvb/frontends/cxd2820r.h
@@ -0,0 +1,118 @@
1/*
2 * Sony CXD2820R demodulator driver
3 *
4 * Copyright (C) 2010 Antti Palosaari <crope@iki.fi>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21
22#ifndef CXD2820R_H
23#define CXD2820R_H
24
25#include <linux/dvb/frontend.h>
26
27#define CXD2820R_GPIO_D (0 << 0) /* disable */
28#define CXD2820R_GPIO_E (1 << 0) /* enable */
29#define CXD2820R_GPIO_O (0 << 1) /* output */
30#define CXD2820R_GPIO_I (1 << 1) /* input */
31#define CXD2820R_GPIO_L (0 << 2) /* output low */
32#define CXD2820R_GPIO_H (1 << 2) /* output high */
33
34#define CXD2820R_TS_SERIAL 0x08
35#define CXD2820R_TS_SERIAL_MSB 0x28
36#define CXD2820R_TS_PARALLEL 0x30
37#define CXD2820R_TS_PARALLEL_MSB 0x70
38
39struct cxd2820r_config {
40 /* Demodulator I2C address.
41 * Driver determines DVB-C slave I2C address automatically from master
42 * address.
43 * Default: none, must set
44 * Values: 0x6c, 0x6d
45 */
46 u8 i2c_address;
47
48 /* TS output mode.
49 * Default: none, must set.
50 * Values:
51 */
52 u8 ts_mode;
53
54 /* IF AGC polarity.
55 * Default: 0
56 * Values: 0, 1
57 */
58 int if_agc_polarity:1;
59
60 /* Spectrum inversion.
61 * Default: 0
62 * Values: 0, 1
63 */
64 int spec_inv:1;
65
66 /* IFs for all used modes.
67 * Default: none, must set
68 * Values: <kHz>
69 */
70 u16 if_dvbt_6;
71 u16 if_dvbt_7;
72 u16 if_dvbt_8;
73 u16 if_dvbt2_5;
74 u16 if_dvbt2_6;
75 u16 if_dvbt2_7;
76 u16 if_dvbt2_8;
77 u16 if_dvbc;
78
79 /* GPIOs for all used modes.
80 * Default: none, disabled
81 * Values: <see above>
82 */
83 u8 gpio_dvbt[3];
84 u8 gpio_dvbt2[3];
85 u8 gpio_dvbc[3];
86};
87
88
89#if defined(CONFIG_DVB_CXD2820R) || \
90 (defined(CONFIG_DVB_CXD2820R_MODULE) && defined(MODULE))
91extern struct dvb_frontend *cxd2820r_attach(
92 const struct cxd2820r_config *config,
93 struct i2c_adapter *i2c,
94 struct dvb_frontend *fe
95);
96extern struct i2c_adapter *cxd2820r_get_tuner_i2c_adapter(
97 struct dvb_frontend *fe
98);
99#else
100static inline struct dvb_frontend *cxd2820r_attach(
101 const struct cxd2820r_config *config,
102 struct i2c_adapter *i2c,
103 struct dvb_frontend *fe
104)
105{
106 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
107 return NULL;
108}
109static inline struct i2c_adapter *cxd2820r_get_tuner_i2c_adapter(
110 struct dvb_frontend *fe
111)
112{
113 return NULL;
114}
115
116#endif
117
118#endif /* CXD2820R_H */
diff --git a/drivers/media/dvb/frontends/cxd2820r_c.c b/drivers/media/dvb/frontends/cxd2820r_c.c
new file mode 100644
index 000000000000..3c07d400731d
--- /dev/null
+++ b/drivers/media/dvb/frontends/cxd2820r_c.c
@@ -0,0 +1,338 @@
1/*
2 * Sony CXD2820R demodulator driver
3 *
4 * Copyright (C) 2010 Antti Palosaari <crope@iki.fi>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21
22#include "cxd2820r_priv.h"
23
24int cxd2820r_set_frontend_c(struct dvb_frontend *fe,
25 struct dvb_frontend_parameters *params)
26{
27 struct cxd2820r_priv *priv = fe->demodulator_priv;
28 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
29 int ret, i;
30 u8 buf[2];
31 u16 if_ctl;
32 u64 num;
33 struct reg_val_mask tab[] = {
34 { 0x00080, 0x01, 0xff },
35 { 0x00081, 0x05, 0xff },
36 { 0x00085, 0x07, 0xff },
37 { 0x00088, 0x01, 0xff },
38
39 { 0x00082, 0x20, 0x60 },
40 { 0x1016a, 0x48, 0xff },
41 { 0x100a5, 0x00, 0x01 },
42 { 0x10020, 0x06, 0x07 },
43 { 0x10059, 0x50, 0xff },
44 { 0x10087, 0x0c, 0x3c },
45 { 0x1008b, 0x07, 0xff },
46 { 0x1001f, priv->cfg.if_agc_polarity << 7, 0x80 },
47 { 0x10070, priv->cfg.ts_mode, 0xff },
48 };
49
50 dbg("%s: RF=%d SR=%d", __func__, c->frequency, c->symbol_rate);
51
52 /* update GPIOs */
53 ret = cxd2820r_gpio(fe);
54 if (ret)
55 goto error;
56
57 /* program tuner */
58 if (fe->ops.tuner_ops.set_params)
59 fe->ops.tuner_ops.set_params(fe, params);
60
61 if (priv->delivery_system != SYS_DVBC_ANNEX_AC) {
62 for (i = 0; i < ARRAY_SIZE(tab); i++) {
63 ret = cxd2820r_wr_reg_mask(priv, tab[i].reg,
64 tab[i].val, tab[i].mask);
65 if (ret)
66 goto error;
67 }
68 }
69
70 priv->delivery_system = SYS_DVBC_ANNEX_AC;
71 priv->ber_running = 0; /* tune stops BER counter */
72
73 num = priv->cfg.if_dvbc;
74 num *= 0x4000;
75 if_ctl = cxd2820r_div_u64_round_closest(num, 41000);
76 buf[0] = (if_ctl >> 8) & 0x3f;
77 buf[1] = (if_ctl >> 0) & 0xff;
78
79 ret = cxd2820r_wr_regs(priv, 0x10042, buf, 2);
80 if (ret)
81 goto error;
82
83 ret = cxd2820r_wr_reg(priv, 0x000ff, 0x08);
84 if (ret)
85 goto error;
86
87 ret = cxd2820r_wr_reg(priv, 0x000fe, 0x01);
88 if (ret)
89 goto error;
90
91 return ret;
92error:
93 dbg("%s: failed:%d", __func__, ret);
94 return ret;
95}
96
97int cxd2820r_get_frontend_c(struct dvb_frontend *fe,
98 struct dvb_frontend_parameters *p)
99{
100 struct cxd2820r_priv *priv = fe->demodulator_priv;
101 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
102 int ret;
103 u8 buf[2];
104
105 ret = cxd2820r_rd_regs(priv, 0x1001a, buf, 2);
106 if (ret)
107 goto error;
108
109 c->symbol_rate = 2500 * ((buf[0] & 0x0f) << 8 | buf[1]);
110
111 ret = cxd2820r_rd_reg(priv, 0x10019, &buf[0]);
112 if (ret)
113 goto error;
114
115 switch ((buf[0] >> 0) & 0x03) {
116 case 0:
117 c->modulation = QAM_16;
118 break;
119 case 1:
120 c->modulation = QAM_32;
121 break;
122 case 2:
123 c->modulation = QAM_64;
124 break;
125 case 3:
126 c->modulation = QAM_128;
127 break;
128 case 4:
129 c->modulation = QAM_256;
130 break;
131 }
132
133 switch ((buf[0] >> 7) & 0x01) {
134 case 0:
135 c->inversion = INVERSION_OFF;
136 break;
137 case 1:
138 c->inversion = INVERSION_ON;
139 break;
140 }
141
142 return ret;
143error:
144 dbg("%s: failed:%d", __func__, ret);
145 return ret;
146}
147
148int cxd2820r_read_ber_c(struct dvb_frontend *fe, u32 *ber)
149{
150 struct cxd2820r_priv *priv = fe->demodulator_priv;
151 int ret;
152 u8 buf[3], start_ber = 0;
153 *ber = 0;
154
155 if (priv->ber_running) {
156 ret = cxd2820r_rd_regs(priv, 0x10076, buf, sizeof(buf));
157 if (ret)
158 goto error;
159
160 if ((buf[2] >> 7) & 0x01 || (buf[2] >> 4) & 0x01) {
161 *ber = (buf[2] & 0x0f) << 16 | buf[1] << 8 | buf[0];
162 start_ber = 1;
163 }
164 } else {
165 priv->ber_running = 1;
166 start_ber = 1;
167 }
168
169 if (start_ber) {
170 /* (re)start BER */
171 ret = cxd2820r_wr_reg(priv, 0x10079, 0x01);
172 if (ret)
173 goto error;
174 }
175
176 return ret;
177error:
178 dbg("%s: failed:%d", __func__, ret);
179 return ret;
180}
181
182int cxd2820r_read_signal_strength_c(struct dvb_frontend *fe,
183 u16 *strength)
184{
185 struct cxd2820r_priv *priv = fe->demodulator_priv;
186 int ret;
187 u8 buf[2];
188 u16 tmp;
189
190 ret = cxd2820r_rd_regs(priv, 0x10049, buf, sizeof(buf));
191 if (ret)
192 goto error;
193
194 tmp = (buf[0] & 0x03) << 8 | buf[1];
195 tmp = (~tmp & 0x03ff);
196
197 if (tmp == 512)
198 /* ~no signal */
199 tmp = 0;
200 else if (tmp > 350)
201 tmp = 350;
202
203 /* scale value to 0x0000-0xffff */
204 *strength = tmp * 0xffff / (350-0);
205
206 return ret;
207error:
208 dbg("%s: failed:%d", __func__, ret);
209 return ret;
210}
211
212int cxd2820r_read_snr_c(struct dvb_frontend *fe, u16 *snr)
213{
214 struct cxd2820r_priv *priv = fe->demodulator_priv;
215 int ret;
216 u8 tmp;
217 unsigned int A, B;
218 /* report SNR in dB * 10 */
219
220 ret = cxd2820r_rd_reg(priv, 0x10019, &tmp);
221 if (ret)
222 goto error;
223
224 if (((tmp >> 0) & 0x03) % 2) {
225 A = 875;
226 B = 650;
227 } else {
228 A = 950;
229 B = 760;
230 }
231
232 ret = cxd2820r_rd_reg(priv, 0x1004d, &tmp);
233 if (ret)
234 goto error;
235
236 #define CXD2820R_LOG2_E_24 24204406 /* log2(e) << 24 */
237 if (tmp)
238 *snr = A * (intlog2(B / tmp) >> 5) / (CXD2820R_LOG2_E_24 >> 5)
239 / 10;
240 else
241 *snr = 0;
242
243 return ret;
244error:
245 dbg("%s: failed:%d", __func__, ret);
246 return ret;
247}
248
249int cxd2820r_read_ucblocks_c(struct dvb_frontend *fe, u32 *ucblocks)
250{
251 *ucblocks = 0;
252 /* no way to read ? */
253 return 0;
254}
255
256int cxd2820r_read_status_c(struct dvb_frontend *fe, fe_status_t *status)
257{
258 struct cxd2820r_priv *priv = fe->demodulator_priv;
259 int ret;
260 u8 buf[2];
261 *status = 0;
262
263 ret = cxd2820r_rd_regs(priv, 0x10088, buf, sizeof(buf));
264 if (ret)
265 goto error;
266
267 if (((buf[0] >> 0) & 0x01) == 1) {
268 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
269 FE_HAS_VITERBI | FE_HAS_SYNC;
270
271 if (((buf[1] >> 3) & 0x01) == 1) {
272 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
273 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
274 }
275 }
276
277 dbg("%s: lock=%02x %02x", __func__, buf[0], buf[1]);
278
279 return ret;
280error:
281 dbg("%s: failed:%d", __func__, ret);
282 return ret;
283}
284
285int cxd2820r_init_c(struct dvb_frontend *fe)
286{
287 struct cxd2820r_priv *priv = fe->demodulator_priv;
288 int ret;
289
290 ret = cxd2820r_wr_reg(priv, 0x00085, 0x07);
291 if (ret)
292 goto error;
293
294 return ret;
295error:
296 dbg("%s: failed:%d", __func__, ret);
297 return ret;
298}
299
300int cxd2820r_sleep_c(struct dvb_frontend *fe)
301{
302 struct cxd2820r_priv *priv = fe->demodulator_priv;
303 int ret, i;
304 struct reg_val_mask tab[] = {
305 { 0x000ff, 0x1f, 0xff },
306 { 0x00085, 0x00, 0xff },
307 { 0x00088, 0x01, 0xff },
308 { 0x00081, 0x00, 0xff },
309 { 0x00080, 0x00, 0xff },
310 };
311
312 dbg("%s", __func__);
313
314 priv->delivery_system = SYS_UNDEFINED;
315
316 for (i = 0; i < ARRAY_SIZE(tab); i++) {
317 ret = cxd2820r_wr_reg_mask(priv, tab[i].reg, tab[i].val,
318 tab[i].mask);
319 if (ret)
320 goto error;
321 }
322
323 return ret;
324error:
325 dbg("%s: failed:%d", __func__, ret);
326 return ret;
327}
328
329int cxd2820r_get_tune_settings_c(struct dvb_frontend *fe,
330 struct dvb_frontend_tune_settings *s)
331{
332 s->min_delay_ms = 500;
333 s->step_size = 0; /* no zigzag */
334 s->max_drift = 0;
335
336 return 0;
337}
338
diff --git a/drivers/media/dvb/frontends/cxd2820r_core.c b/drivers/media/dvb/frontends/cxd2820r_core.c
new file mode 100644
index 000000000000..0779f69db793
--- /dev/null
+++ b/drivers/media/dvb/frontends/cxd2820r_core.c
@@ -0,0 +1,915 @@
1/*
2 * Sony CXD2820R demodulator driver
3 *
4 * Copyright (C) 2010 Antti Palosaari <crope@iki.fi>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21
22#include "cxd2820r_priv.h"
23
24int cxd2820r_debug;
25module_param_named(debug, cxd2820r_debug, int, 0644);
26MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
27
28/* write multiple registers */
29static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
30 u8 *val, int len)
31{
32 int ret;
33 u8 buf[len+1];
34 struct i2c_msg msg[1] = {
35 {
36 .addr = i2c,
37 .flags = 0,
38 .len = sizeof(buf),
39 .buf = buf,
40 }
41 };
42
43 buf[0] = reg;
44 memcpy(&buf[1], val, len);
45
46 ret = i2c_transfer(priv->i2c, msg, 1);
47 if (ret == 1) {
48 ret = 0;
49 } else {
50 warn("i2c wr failed ret:%d reg:%02x len:%d", ret, reg, len);
51 ret = -EREMOTEIO;
52 }
53 return ret;
54}
55
56/* read multiple registers */
57static int cxd2820r_rd_regs_i2c(struct cxd2820r_priv *priv, u8 i2c, u8 reg,
58 u8 *val, int len)
59{
60 int ret;
61 u8 buf[len];
62 struct i2c_msg msg[2] = {
63 {
64 .addr = i2c,
65 .flags = 0,
66 .len = 1,
67 .buf = &reg,
68 }, {
69 .addr = i2c,
70 .flags = I2C_M_RD,
71 .len = sizeof(buf),
72 .buf = buf,
73 }
74 };
75
76 ret = i2c_transfer(priv->i2c, msg, 2);
77 if (ret == 2) {
78 memcpy(val, buf, len);
79 ret = 0;
80 } else {
81 warn("i2c rd failed ret:%d reg:%02x len:%d", ret, reg, len);
82 ret = -EREMOTEIO;
83 }
84
85 return ret;
86}
87
88/* write multiple registers */
89int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val,
90 int len)
91{
92 int ret;
93 u8 i2c_addr;
94 u8 reg = (reginfo >> 0) & 0xff;
95 u8 bank = (reginfo >> 8) & 0xff;
96 u8 i2c = (reginfo >> 16) & 0x01;
97
98 /* select I2C */
99 if (i2c)
100 i2c_addr = priv->cfg.i2c_address | (1 << 1); /* DVB-C */
101 else
102 i2c_addr = priv->cfg.i2c_address; /* DVB-T/T2 */
103
104 /* switch bank if needed */
105 if (bank != priv->bank[i2c]) {
106 ret = cxd2820r_wr_regs_i2c(priv, i2c_addr, 0x00, &bank, 1);
107 if (ret)
108 return ret;
109 priv->bank[i2c] = bank;
110 }
111 return cxd2820r_wr_regs_i2c(priv, i2c_addr, reg, val, len);
112}
113
114/* read multiple registers */
115int cxd2820r_rd_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val,
116 int len)
117{
118 int ret;
119 u8 i2c_addr;
120 u8 reg = (reginfo >> 0) & 0xff;
121 u8 bank = (reginfo >> 8) & 0xff;
122 u8 i2c = (reginfo >> 16) & 0x01;
123
124 /* select I2C */
125 if (i2c)
126 i2c_addr = priv->cfg.i2c_address | (1 << 1); /* DVB-C */
127 else
128 i2c_addr = priv->cfg.i2c_address; /* DVB-T/T2 */
129
130 /* switch bank if needed */
131 if (bank != priv->bank[i2c]) {
132 ret = cxd2820r_wr_regs_i2c(priv, i2c_addr, 0x00, &bank, 1);
133 if (ret)
134 return ret;
135 priv->bank[i2c] = bank;
136 }
137 return cxd2820r_rd_regs_i2c(priv, i2c_addr, reg, val, len);
138}
139
140/* write single register */
141int cxd2820r_wr_reg(struct cxd2820r_priv *priv, u32 reg, u8 val)
142{
143 return cxd2820r_wr_regs(priv, reg, &val, 1);
144}
145
146/* read single register */
147int cxd2820r_rd_reg(struct cxd2820r_priv *priv, u32 reg, u8 *val)
148{
149 return cxd2820r_rd_regs(priv, reg, val, 1);
150}
151
152/* write single register with mask */
153int cxd2820r_wr_reg_mask(struct cxd2820r_priv *priv, u32 reg, u8 val,
154 u8 mask)
155{
156 int ret;
157 u8 tmp;
158
159 /* no need for read if whole reg is written */
160 if (mask != 0xff) {
161 ret = cxd2820r_rd_reg(priv, reg, &tmp);
162 if (ret)
163 return ret;
164
165 val &= mask;
166 tmp &= ~mask;
167 val |= tmp;
168 }
169
170 return cxd2820r_wr_reg(priv, reg, val);
171}
172
173int cxd2820r_gpio(struct dvb_frontend *fe)
174{
175 struct cxd2820r_priv *priv = fe->demodulator_priv;
176 int ret, i;
177 u8 *gpio, tmp0, tmp1;
178 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
179
180 switch (fe->dtv_property_cache.delivery_system) {
181 case SYS_DVBT:
182 gpio = priv->cfg.gpio_dvbt;
183 break;
184 case SYS_DVBT2:
185 gpio = priv->cfg.gpio_dvbt2;
186 break;
187 case SYS_DVBC_ANNEX_AC:
188 gpio = priv->cfg.gpio_dvbc;
189 break;
190 default:
191 ret = -EINVAL;
192 goto error;
193 }
194
195 /* update GPIOs only when needed */
196 if (!memcmp(gpio, priv->gpio, sizeof(priv->gpio)))
197 return 0;
198
199 tmp0 = 0x00;
200 tmp1 = 0x00;
201 for (i = 0; i < sizeof(priv->gpio); i++) {
202 /* enable / disable */
203 if (gpio[i] & CXD2820R_GPIO_E)
204 tmp0 |= (2 << 6) >> (2 * i);
205 else
206 tmp0 |= (1 << 6) >> (2 * i);
207
208 /* input / output */
209 if (gpio[i] & CXD2820R_GPIO_I)
210 tmp1 |= (1 << (3 + i));
211 else
212 tmp1 |= (0 << (3 + i));
213
214 /* high / low */
215 if (gpio[i] & CXD2820R_GPIO_H)
216 tmp1 |= (1 << (0 + i));
217 else
218 tmp1 |= (0 << (0 + i));
219
220 dbg("%s: GPIO i=%d %02x %02x", __func__, i, tmp0, tmp1);
221 }
222
223 dbg("%s: wr gpio=%02x %02x", __func__, tmp0, tmp1);
224
225 /* write bits [7:2] */
226 ret = cxd2820r_wr_reg_mask(priv, 0x00089, tmp0, 0xfc);
227 if (ret)
228 goto error;
229
230 /* write bits [5:0] */
231 ret = cxd2820r_wr_reg_mask(priv, 0x0008e, tmp1, 0x3f);
232 if (ret)
233 goto error;
234
235 memcpy(priv->gpio, gpio, sizeof(priv->gpio));
236
237 return ret;
238error:
239 dbg("%s: failed:%d", __func__, ret);
240 return ret;
241}
242
243/* lock FE */
244static int cxd2820r_lock(struct cxd2820r_priv *priv, int active_fe)
245{
246 int ret = 0;
247 dbg("%s: active_fe=%d", __func__, active_fe);
248
249 mutex_lock(&priv->fe_lock);
250
251 /* -1=NONE, 0=DVB-T/T2, 1=DVB-C */
252 if (priv->active_fe == active_fe)
253 ;
254 else if (priv->active_fe == -1)
255 priv->active_fe = active_fe;
256 else
257 ret = -EBUSY;
258
259 mutex_unlock(&priv->fe_lock);
260
261 return ret;
262}
263
264/* unlock FE */
265static void cxd2820r_unlock(struct cxd2820r_priv *priv, int active_fe)
266{
267 dbg("%s: active_fe=%d", __func__, active_fe);
268
269 mutex_lock(&priv->fe_lock);
270
271 /* -1=NONE, 0=DVB-T/T2, 1=DVB-C */
272 if (priv->active_fe == active_fe)
273 priv->active_fe = -1;
274
275 mutex_unlock(&priv->fe_lock);
276
277 return;
278}
279
280/* 64 bit div with round closest, like DIV_ROUND_CLOSEST but 64 bit */
281u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor)
282{
283 return div_u64(dividend + (divisor / 2), divisor);
284}
285
286static int cxd2820r_set_frontend(struct dvb_frontend *fe,
287 struct dvb_frontend_parameters *p)
288{
289 struct cxd2820r_priv *priv = fe->demodulator_priv;
290 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
291 int ret;
292 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
293
294 if (fe->ops.info.type == FE_OFDM) {
295 /* DVB-T/T2 */
296 ret = cxd2820r_lock(priv, 0);
297 if (ret)
298 return ret;
299
300 switch (priv->delivery_system) {
301 case SYS_UNDEFINED:
302 if (c->delivery_system == SYS_DVBT) {
303 /* SLEEP => DVB-T */
304 ret = cxd2820r_set_frontend_t(fe, p);
305 } else {
306 /* SLEEP => DVB-T2 */
307 ret = cxd2820r_set_frontend_t2(fe, p);
308 }
309 break;
310 case SYS_DVBT:
311 if (c->delivery_system == SYS_DVBT) {
312 /* DVB-T => DVB-T */
313 ret = cxd2820r_set_frontend_t(fe, p);
314 } else if (c->delivery_system == SYS_DVBT2) {
315 /* DVB-T => DVB-T2 */
316 ret = cxd2820r_sleep_t(fe);
317 ret = cxd2820r_set_frontend_t2(fe, p);
318 }
319 break;
320 case SYS_DVBT2:
321 if (c->delivery_system == SYS_DVBT2) {
322 /* DVB-T2 => DVB-T2 */
323 ret = cxd2820r_set_frontend_t2(fe, p);
324 } else if (c->delivery_system == SYS_DVBT) {
325 /* DVB-T2 => DVB-T */
326 ret = cxd2820r_sleep_t2(fe);
327 ret = cxd2820r_set_frontend_t(fe, p);
328 }
329 break;
330 default:
331 dbg("%s: error state=%d", __func__,
332 priv->delivery_system);
333 ret = -EINVAL;
334 }
335 } else {
336 /* DVB-C */
337 ret = cxd2820r_lock(priv, 1);
338 if (ret)
339 return ret;
340
341 ret = cxd2820r_set_frontend_c(fe, p);
342 }
343
344 return ret;
345}
346
347static int cxd2820r_read_status(struct dvb_frontend *fe, fe_status_t *status)
348{
349 struct cxd2820r_priv *priv = fe->demodulator_priv;
350 int ret;
351 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
352
353 if (fe->ops.info.type == FE_OFDM) {
354 /* DVB-T/T2 */
355 ret = cxd2820r_lock(priv, 0);
356 if (ret)
357 return ret;
358
359 switch (fe->dtv_property_cache.delivery_system) {
360 case SYS_DVBT:
361 ret = cxd2820r_read_status_t(fe, status);
362 break;
363 case SYS_DVBT2:
364 ret = cxd2820r_read_status_t2(fe, status);
365 break;
366 default:
367 ret = -EINVAL;
368 }
369 } else {
370 /* DVB-C */
371 ret = cxd2820r_lock(priv, 1);
372 if (ret)
373 return ret;
374
375 ret = cxd2820r_read_status_c(fe, status);
376 }
377
378 return ret;
379}
380
381static int cxd2820r_get_frontend(struct dvb_frontend *fe,
382 struct dvb_frontend_parameters *p)
383{
384 struct cxd2820r_priv *priv = fe->demodulator_priv;
385 int ret;
386 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
387
388 if (fe->ops.info.type == FE_OFDM) {
389 /* DVB-T/T2 */
390 ret = cxd2820r_lock(priv, 0);
391 if (ret)
392 return ret;
393
394 switch (fe->dtv_property_cache.delivery_system) {
395 case SYS_DVBT:
396 ret = cxd2820r_get_frontend_t(fe, p);
397 break;
398 case SYS_DVBT2:
399 ret = cxd2820r_get_frontend_t2(fe, p);
400 break;
401 default:
402 ret = -EINVAL;
403 }
404 } else {
405 /* DVB-C */
406 ret = cxd2820r_lock(priv, 1);
407 if (ret)
408 return ret;
409
410 ret = cxd2820r_get_frontend_c(fe, p);
411 }
412
413 return ret;
414}
415
416static int cxd2820r_read_ber(struct dvb_frontend *fe, u32 *ber)
417{
418 struct cxd2820r_priv *priv = fe->demodulator_priv;
419 int ret;
420 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
421
422 if (fe->ops.info.type == FE_OFDM) {
423 /* DVB-T/T2 */
424 ret = cxd2820r_lock(priv, 0);
425 if (ret)
426 return ret;
427
428 switch (fe->dtv_property_cache.delivery_system) {
429 case SYS_DVBT:
430 ret = cxd2820r_read_ber_t(fe, ber);
431 break;
432 case SYS_DVBT2:
433 ret = cxd2820r_read_ber_t2(fe, ber);
434 break;
435 default:
436 ret = -EINVAL;
437 }
438 } else {
439 /* DVB-C */
440 ret = cxd2820r_lock(priv, 1);
441 if (ret)
442 return ret;
443
444 ret = cxd2820r_read_ber_c(fe, ber);
445 }
446
447 return ret;
448}
449
450static int cxd2820r_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
451{
452 struct cxd2820r_priv *priv = fe->demodulator_priv;
453 int ret;
454 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
455
456 if (fe->ops.info.type == FE_OFDM) {
457 /* DVB-T/T2 */
458 ret = cxd2820r_lock(priv, 0);
459 if (ret)
460 return ret;
461
462 switch (fe->dtv_property_cache.delivery_system) {
463 case SYS_DVBT:
464 ret = cxd2820r_read_signal_strength_t(fe, strength);
465 break;
466 case SYS_DVBT2:
467 ret = cxd2820r_read_signal_strength_t2(fe, strength);
468 break;
469 default:
470 ret = -EINVAL;
471 }
472 } else {
473 /* DVB-C */
474 ret = cxd2820r_lock(priv, 1);
475 if (ret)
476 return ret;
477
478 ret = cxd2820r_read_signal_strength_c(fe, strength);
479 }
480
481 return ret;
482}
483
484static int cxd2820r_read_snr(struct dvb_frontend *fe, u16 *snr)
485{
486 struct cxd2820r_priv *priv = fe->demodulator_priv;
487 int ret;
488 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
489
490 if (fe->ops.info.type == FE_OFDM) {
491 /* DVB-T/T2 */
492 ret = cxd2820r_lock(priv, 0);
493 if (ret)
494 return ret;
495
496 switch (fe->dtv_property_cache.delivery_system) {
497 case SYS_DVBT:
498 ret = cxd2820r_read_snr_t(fe, snr);
499 break;
500 case SYS_DVBT2:
501 ret = cxd2820r_read_snr_t2(fe, snr);
502 break;
503 default:
504 ret = -EINVAL;
505 }
506 } else {
507 /* DVB-C */
508 ret = cxd2820r_lock(priv, 1);
509 if (ret)
510 return ret;
511
512 ret = cxd2820r_read_snr_c(fe, snr);
513 }
514
515 return ret;
516}
517
518static int cxd2820r_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
519{
520 struct cxd2820r_priv *priv = fe->demodulator_priv;
521 int ret;
522 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
523
524 if (fe->ops.info.type == FE_OFDM) {
525 /* DVB-T/T2 */
526 ret = cxd2820r_lock(priv, 0);
527 if (ret)
528 return ret;
529
530 switch (fe->dtv_property_cache.delivery_system) {
531 case SYS_DVBT:
532 ret = cxd2820r_read_ucblocks_t(fe, ucblocks);
533 break;
534 case SYS_DVBT2:
535 ret = cxd2820r_read_ucblocks_t2(fe, ucblocks);
536 break;
537 default:
538 ret = -EINVAL;
539 }
540 } else {
541 /* DVB-C */
542 ret = cxd2820r_lock(priv, 1);
543 if (ret)
544 return ret;
545
546 ret = cxd2820r_read_ucblocks_c(fe, ucblocks);
547 }
548
549 return ret;
550}
551
552static int cxd2820r_init(struct dvb_frontend *fe)
553{
554 struct cxd2820r_priv *priv = fe->demodulator_priv;
555 int ret;
556 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
557
558 priv->delivery_system = SYS_UNDEFINED;
559 /* delivery system is unknown at that (init) phase */
560
561 if (fe->ops.info.type == FE_OFDM) {
562 /* DVB-T/T2 */
563 ret = cxd2820r_lock(priv, 0);
564 if (ret)
565 return ret;
566
567 ret = cxd2820r_init_t(fe);
568 } else {
569 /* DVB-C */
570 ret = cxd2820r_lock(priv, 1);
571 if (ret)
572 return ret;
573
574 ret = cxd2820r_init_c(fe);
575 }
576
577 return ret;
578}
579
580static int cxd2820r_sleep(struct dvb_frontend *fe)
581{
582 struct cxd2820r_priv *priv = fe->demodulator_priv;
583 int ret;
584 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
585
586 if (fe->ops.info.type == FE_OFDM) {
587 /* DVB-T/T2 */
588 ret = cxd2820r_lock(priv, 0);
589 if (ret)
590 return ret;
591
592 switch (fe->dtv_property_cache.delivery_system) {
593 case SYS_DVBT:
594 ret = cxd2820r_sleep_t(fe);
595 break;
596 case SYS_DVBT2:
597 ret = cxd2820r_sleep_t2(fe);
598 break;
599 default:
600 ret = -EINVAL;
601 }
602
603 cxd2820r_unlock(priv, 0);
604 } else {
605 /* DVB-C */
606 ret = cxd2820r_lock(priv, 1);
607 if (ret)
608 return ret;
609
610 ret = cxd2820r_sleep_c(fe);
611
612 cxd2820r_unlock(priv, 1);
613 }
614
615 return ret;
616}
617
618static int cxd2820r_get_tune_settings(struct dvb_frontend *fe,
619 struct dvb_frontend_tune_settings *s)
620{
621 struct cxd2820r_priv *priv = fe->demodulator_priv;
622 int ret;
623 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
624
625 if (fe->ops.info.type == FE_OFDM) {
626 /* DVB-T/T2 */
627 ret = cxd2820r_lock(priv, 0);
628 if (ret)
629 return ret;
630
631 switch (fe->dtv_property_cache.delivery_system) {
632 case SYS_DVBT:
633 ret = cxd2820r_get_tune_settings_t(fe, s);
634 break;
635 case SYS_DVBT2:
636 ret = cxd2820r_get_tune_settings_t2(fe, s);
637 break;
638 default:
639 ret = -EINVAL;
640 }
641 } else {
642 /* DVB-C */
643 ret = cxd2820r_lock(priv, 1);
644 if (ret)
645 return ret;
646
647 ret = cxd2820r_get_tune_settings_c(fe, s);
648 }
649
650 return ret;
651}
652
653static enum dvbfe_search cxd2820r_search(struct dvb_frontend *fe,
654 struct dvb_frontend_parameters *p)
655{
656 struct cxd2820r_priv *priv = fe->demodulator_priv;
657 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
658 int ret, i;
659 fe_status_t status = 0;
660 dbg("%s: delsys=%d", __func__, fe->dtv_property_cache.delivery_system);
661
662 /* switch between DVB-T and DVB-T2 when tune fails */
663 if (priv->last_tune_failed) {
664 if (priv->delivery_system == SYS_DVBT)
665 c->delivery_system = SYS_DVBT2;
666 else
667 c->delivery_system = SYS_DVBT;
668 }
669
670 /* set frontend */
671 ret = cxd2820r_set_frontend(fe, p);
672 if (ret)
673 goto error;
674
675
676 /* frontend lock wait loop count */
677 switch (priv->delivery_system) {
678 case SYS_DVBT:
679 i = 20;
680 break;
681 case SYS_DVBT2:
682 i = 40;
683 break;
684 case SYS_UNDEFINED:
685 default:
686 i = 0;
687 break;
688 }
689
690 /* wait frontend lock */
691 for (; i > 0; i--) {
692 dbg("%s: LOOP=%d", __func__, i);
693 msleep(50);
694 ret = cxd2820r_read_status(fe, &status);
695 if (ret)
696 goto error;
697
698 if (status & FE_HAS_SIGNAL)
699 break;
700 }
701
702 /* check if we have a valid signal */
703 if (status) {
704 priv->last_tune_failed = 0;
705 return DVBFE_ALGO_SEARCH_SUCCESS;
706 } else {
707 priv->last_tune_failed = 1;
708 return DVBFE_ALGO_SEARCH_AGAIN;
709 }
710
711error:
712 dbg("%s: failed:%d", __func__, ret);
713 return DVBFE_ALGO_SEARCH_ERROR;
714}
715
716static int cxd2820r_get_frontend_algo(struct dvb_frontend *fe)
717{
718 return DVBFE_ALGO_CUSTOM;
719}
720
721static void cxd2820r_release(struct dvb_frontend *fe)
722{
723 struct cxd2820r_priv *priv = fe->demodulator_priv;
724 dbg("%s", __func__);
725
726 if (fe->ops.info.type == FE_OFDM) {
727 i2c_del_adapter(&priv->tuner_i2c_adapter);
728 kfree(priv);
729 }
730
731 return;
732}
733
734static u32 cxd2820r_tuner_i2c_func(struct i2c_adapter *adapter)
735{
736 return I2C_FUNC_I2C;
737}
738
739static int cxd2820r_tuner_i2c_xfer(struct i2c_adapter *i2c_adap,
740 struct i2c_msg msg[], int num)
741{
742 struct cxd2820r_priv *priv = i2c_get_adapdata(i2c_adap);
743 u8 obuf[msg[0].len + 2];
744 struct i2c_msg msg2[2] = {
745 {
746 .addr = priv->cfg.i2c_address,
747 .flags = 0,
748 .len = sizeof(obuf),
749 .buf = obuf,
750 }, {
751 .addr = priv->cfg.i2c_address,
752 .flags = I2C_M_RD,
753 .len = msg[1].len,
754 .buf = msg[1].buf,
755 }
756 };
757
758 obuf[0] = 0x09;
759 obuf[1] = (msg[0].addr << 1);
760 if (num == 2) { /* I2C read */
761 obuf[1] = (msg[0].addr << 1) | I2C_M_RD; /* I2C RD flag */
762 msg2[0].len = sizeof(obuf) - 1; /* maybe HW bug ? */
763 }
764 memcpy(&obuf[2], msg[0].buf, msg[0].len);
765
766 return i2c_transfer(priv->i2c, msg2, num);
767}
768
769static struct i2c_algorithm cxd2820r_tuner_i2c_algo = {
770 .master_xfer = cxd2820r_tuner_i2c_xfer,
771 .functionality = cxd2820r_tuner_i2c_func,
772};
773
774struct i2c_adapter *cxd2820r_get_tuner_i2c_adapter(struct dvb_frontend *fe)
775{
776 struct cxd2820r_priv *priv = fe->demodulator_priv;
777 return &priv->tuner_i2c_adapter;
778}
779EXPORT_SYMBOL(cxd2820r_get_tuner_i2c_adapter);
780
781static struct dvb_frontend_ops cxd2820r_ops[2];
782
783struct dvb_frontend *cxd2820r_attach(const struct cxd2820r_config *cfg,
784 struct i2c_adapter *i2c, struct dvb_frontend *fe)
785{
786 int ret;
787 struct cxd2820r_priv *priv = NULL;
788 u8 tmp;
789
790 if (fe == NULL) {
791 /* FE0 */
792 /* allocate memory for the internal priv */
793 priv = kzalloc(sizeof(struct cxd2820r_priv), GFP_KERNEL);
794 if (priv == NULL)
795 goto error;
796
797 /* setup the priv */
798 priv->i2c = i2c;
799 memcpy(&priv->cfg, cfg, sizeof(struct cxd2820r_config));
800 mutex_init(&priv->fe_lock);
801
802 priv->active_fe = -1; /* NONE */
803
804 /* check if the demod is there */
805 priv->bank[0] = priv->bank[1] = 0xff;
806 ret = cxd2820r_rd_reg(priv, 0x000fd, &tmp);
807 dbg("%s: chip id=%02x", __func__, tmp);
808 if (ret || tmp != 0xe1)
809 goto error;
810
811 /* create frontends */
812 memcpy(&priv->fe[0].ops, &cxd2820r_ops[0],
813 sizeof(struct dvb_frontend_ops));
814 memcpy(&priv->fe[1].ops, &cxd2820r_ops[1],
815 sizeof(struct dvb_frontend_ops));
816
817 priv->fe[0].demodulator_priv = priv;
818 priv->fe[1].demodulator_priv = priv;
819
820 /* create tuner i2c adapter */
821 strlcpy(priv->tuner_i2c_adapter.name,
822 "CXD2820R tuner I2C adapter",
823 sizeof(priv->tuner_i2c_adapter.name));
824 priv->tuner_i2c_adapter.algo = &cxd2820r_tuner_i2c_algo;
825 priv->tuner_i2c_adapter.algo_data = NULL;
826 i2c_set_adapdata(&priv->tuner_i2c_adapter, priv);
827 if (i2c_add_adapter(&priv->tuner_i2c_adapter) < 0) {
828 err("tuner I2C bus could not be initialized");
829 goto error;
830 }
831
832 return &priv->fe[0];
833
834 } else {
835 /* FE1: FE0 given as pointer, just return FE1 we have
836 * already created */
837 priv = fe->demodulator_priv;
838 return &priv->fe[1];
839 }
840
841error:
842 kfree(priv);
843 return NULL;
844}
845EXPORT_SYMBOL(cxd2820r_attach);
846
847static struct dvb_frontend_ops cxd2820r_ops[2] = {
848 {
849 /* DVB-T/T2 */
850 .info = {
851 .name = "Sony CXD2820R (DVB-T/T2)",
852 .type = FE_OFDM,
853 .caps =
854 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
855 FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 |
856 FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
857 FE_CAN_QPSK | FE_CAN_QAM_16 |
858 FE_CAN_QAM_64 | FE_CAN_QAM_256 |
859 FE_CAN_QAM_AUTO |
860 FE_CAN_TRANSMISSION_MODE_AUTO |
861 FE_CAN_GUARD_INTERVAL_AUTO |
862 FE_CAN_HIERARCHY_AUTO |
863 FE_CAN_MUTE_TS |
864 FE_CAN_2G_MODULATION
865 },
866
867 .release = cxd2820r_release,
868 .init = cxd2820r_init,
869 .sleep = cxd2820r_sleep,
870
871 .get_tune_settings = cxd2820r_get_tune_settings,
872
873 .get_frontend = cxd2820r_get_frontend,
874
875 .get_frontend_algo = cxd2820r_get_frontend_algo,
876 .search = cxd2820r_search,
877
878 .read_status = cxd2820r_read_status,
879 .read_snr = cxd2820r_read_snr,
880 .read_ber = cxd2820r_read_ber,
881 .read_ucblocks = cxd2820r_read_ucblocks,
882 .read_signal_strength = cxd2820r_read_signal_strength,
883 },
884 {
885 /* DVB-C */
886 .info = {
887 .name = "Sony CXD2820R (DVB-C)",
888 .type = FE_QAM,
889 .caps =
890 FE_CAN_QAM_16 | FE_CAN_QAM_32 | FE_CAN_QAM_64 |
891 FE_CAN_QAM_128 | FE_CAN_QAM_256 |
892 FE_CAN_FEC_AUTO
893 },
894
895 .release = cxd2820r_release,
896 .init = cxd2820r_init,
897 .sleep = cxd2820r_sleep,
898
899 .get_tune_settings = cxd2820r_get_tune_settings,
900
901 .set_frontend = cxd2820r_set_frontend,
902 .get_frontend = cxd2820r_get_frontend,
903
904 .read_status = cxd2820r_read_status,
905 .read_snr = cxd2820r_read_snr,
906 .read_ber = cxd2820r_read_ber,
907 .read_ucblocks = cxd2820r_read_ucblocks,
908 .read_signal_strength = cxd2820r_read_signal_strength,
909 },
910};
911
912
913MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
914MODULE_DESCRIPTION("Sony CXD2820R demodulator driver");
915MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/cxd2820r_priv.h b/drivers/media/dvb/frontends/cxd2820r_priv.h
new file mode 100644
index 000000000000..25adbeefa6d3
--- /dev/null
+++ b/drivers/media/dvb/frontends/cxd2820r_priv.h
@@ -0,0 +1,166 @@
1/*
2 * Sony CXD2820R demodulator driver
3 *
4 * Copyright (C) 2010 Antti Palosaari <crope@iki.fi>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21
22#ifndef CXD2820R_PRIV_H
23#define CXD2820R_PRIV_H
24
25#include <linux/dvb/version.h>
26#include "dvb_frontend.h"
27#include "dvb_math.h"
28#include "cxd2820r.h"
29
30#define LOG_PREFIX "cxd2820r"
31
32#undef dbg
33#define dbg(f, arg...) \
34 if (cxd2820r_debug) \
35 printk(KERN_INFO LOG_PREFIX": " f "\n" , ## arg)
36#undef err
37#define err(f, arg...) printk(KERN_ERR LOG_PREFIX": " f "\n" , ## arg)
38#undef info
39#define info(f, arg...) printk(KERN_INFO LOG_PREFIX": " f "\n" , ## arg)
40#undef warn
41#define warn(f, arg...) printk(KERN_WARNING LOG_PREFIX": " f "\n" , ## arg)
42
43struct reg_val_mask {
44 u32 reg;
45 u8 val;
46 u8 mask;
47};
48
49struct cxd2820r_priv {
50 struct i2c_adapter *i2c;
51 struct dvb_frontend fe[2];
52 struct cxd2820r_config cfg;
53 struct i2c_adapter tuner_i2c_adapter;
54
55 struct mutex fe_lock; /* FE lock */
56 int active_fe:2; /* FE lock, -1=NONE, 0=DVB-T/T2, 1=DVB-C */
57
58 int ber_running:1;
59
60 u8 bank[2];
61 u8 gpio[3];
62
63 fe_delivery_system_t delivery_system;
64 int last_tune_failed:1; /* for switch between T and T2 tune */
65};
66
67/* cxd2820r_core.c */
68
69extern int cxd2820r_debug;
70
71int cxd2820r_gpio(struct dvb_frontend *fe);
72
73int cxd2820r_wr_reg_mask(struct cxd2820r_priv *priv, u32 reg, u8 val,
74 u8 mask);
75
76int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val,
77 int len);
78
79u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor);
80
81int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val,
82 int len);
83
84int cxd2820r_rd_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val,
85 int len);
86
87int cxd2820r_wr_reg(struct cxd2820r_priv *priv, u32 reg, u8 val);
88
89int cxd2820r_rd_reg(struct cxd2820r_priv *priv, u32 reg, u8 *val);
90
91/* cxd2820r_c.c */
92
93int cxd2820r_get_frontend_c(struct dvb_frontend *fe,
94 struct dvb_frontend_parameters *p);
95
96int cxd2820r_set_frontend_c(struct dvb_frontend *fe,
97 struct dvb_frontend_parameters *params);
98
99int cxd2820r_read_status_c(struct dvb_frontend *fe, fe_status_t *status);
100
101int cxd2820r_read_ber_c(struct dvb_frontend *fe, u32 *ber);
102
103int cxd2820r_read_signal_strength_c(struct dvb_frontend *fe, u16 *strength);
104
105int cxd2820r_read_snr_c(struct dvb_frontend *fe, u16 *snr);
106
107int cxd2820r_read_ucblocks_c(struct dvb_frontend *fe, u32 *ucblocks);
108
109int cxd2820r_init_c(struct dvb_frontend *fe);
110
111int cxd2820r_sleep_c(struct dvb_frontend *fe);
112
113int cxd2820r_get_tune_settings_c(struct dvb_frontend *fe,
114 struct dvb_frontend_tune_settings *s);
115
116/* cxd2820r_t.c */
117
118int cxd2820r_get_frontend_t(struct dvb_frontend *fe,
119 struct dvb_frontend_parameters *p);
120
121int cxd2820r_set_frontend_t(struct dvb_frontend *fe,
122 struct dvb_frontend_parameters *params);
123
124int cxd2820r_read_status_t(struct dvb_frontend *fe, fe_status_t *status);
125
126int cxd2820r_read_ber_t(struct dvb_frontend *fe, u32 *ber);
127
128int cxd2820r_read_signal_strength_t(struct dvb_frontend *fe, u16 *strength);
129
130int cxd2820r_read_snr_t(struct dvb_frontend *fe, u16 *snr);
131
132int cxd2820r_read_ucblocks_t(struct dvb_frontend *fe, u32 *ucblocks);
133
134int cxd2820r_init_t(struct dvb_frontend *fe);
135
136int cxd2820r_sleep_t(struct dvb_frontend *fe);
137
138int cxd2820r_get_tune_settings_t(struct dvb_frontend *fe,
139 struct dvb_frontend_tune_settings *s);
140
141/* cxd2820r_t2.c */
142
143int cxd2820r_get_frontend_t2(struct dvb_frontend *fe,
144 struct dvb_frontend_parameters *p);
145
146int cxd2820r_set_frontend_t2(struct dvb_frontend *fe,
147 struct dvb_frontend_parameters *params);
148
149int cxd2820r_read_status_t2(struct dvb_frontend *fe, fe_status_t *status);
150
151int cxd2820r_read_ber_t2(struct dvb_frontend *fe, u32 *ber);
152
153int cxd2820r_read_signal_strength_t2(struct dvb_frontend *fe, u16 *strength);
154
155int cxd2820r_read_snr_t2(struct dvb_frontend *fe, u16 *snr);
156
157int cxd2820r_read_ucblocks_t2(struct dvb_frontend *fe, u32 *ucblocks);
158
159int cxd2820r_init_t2(struct dvb_frontend *fe);
160
161int cxd2820r_sleep_t2(struct dvb_frontend *fe);
162
163int cxd2820r_get_tune_settings_t2(struct dvb_frontend *fe,
164 struct dvb_frontend_tune_settings *s);
165
166#endif /* CXD2820R_PRIV_H */
diff --git a/drivers/media/dvb/frontends/cxd2820r_t.c b/drivers/media/dvb/frontends/cxd2820r_t.c
new file mode 100644
index 000000000000..6582564c930c
--- /dev/null
+++ b/drivers/media/dvb/frontends/cxd2820r_t.c
@@ -0,0 +1,449 @@
1/*
2 * Sony CXD2820R demodulator driver
3 *
4 * Copyright (C) 2010 Antti Palosaari <crope@iki.fi>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21
22#include "cxd2820r_priv.h"
23
24int cxd2820r_set_frontend_t(struct dvb_frontend *fe,
25 struct dvb_frontend_parameters *p)
26{
27 struct cxd2820r_priv *priv = fe->demodulator_priv;
28 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
29 int ret, i;
30 u32 if_khz, if_ctl;
31 u64 num;
32 u8 buf[3], bw_param;
33 u8 bw_params1[][5] = {
34 { 0x17, 0xea, 0xaa, 0xaa, 0xaa }, /* 6 MHz */
35 { 0x14, 0x80, 0x00, 0x00, 0x00 }, /* 7 MHz */
36 { 0x11, 0xf0, 0x00, 0x00, 0x00 }, /* 8 MHz */
37 };
38 u8 bw_params2[][2] = {
39 { 0x1f, 0xdc }, /* 6 MHz */
40 { 0x12, 0xf8 }, /* 7 MHz */
41 { 0x01, 0xe0 }, /* 8 MHz */
42 };
43 struct reg_val_mask tab[] = {
44 { 0x00080, 0x00, 0xff },
45 { 0x00081, 0x03, 0xff },
46 { 0x00085, 0x07, 0xff },
47 { 0x00088, 0x01, 0xff },
48
49 { 0x00070, priv->cfg.ts_mode, 0xff },
50 { 0x000cb, priv->cfg.if_agc_polarity << 6, 0x40 },
51 { 0x000a5, 0x00, 0x01 },
52 { 0x00082, 0x20, 0x60 },
53 { 0x000c2, 0xc3, 0xff },
54 { 0x0016a, 0x50, 0xff },
55 { 0x00427, 0x41, 0xff },
56 };
57
58 dbg("%s: RF=%d BW=%d", __func__, c->frequency, c->bandwidth_hz);
59
60 /* update GPIOs */
61 ret = cxd2820r_gpio(fe);
62 if (ret)
63 goto error;
64
65 /* program tuner */
66 if (fe->ops.tuner_ops.set_params)
67 fe->ops.tuner_ops.set_params(fe, p);
68
69 if (priv->delivery_system != SYS_DVBT) {
70 for (i = 0; i < ARRAY_SIZE(tab); i++) {
71 ret = cxd2820r_wr_reg_mask(priv, tab[i].reg,
72 tab[i].val, tab[i].mask);
73 if (ret)
74 goto error;
75 }
76 }
77
78 priv->delivery_system = SYS_DVBT;
79 priv->ber_running = 0; /* tune stops BER counter */
80
81 switch (c->bandwidth_hz) {
82 case 6000000:
83 if_khz = priv->cfg.if_dvbt_6;
84 i = 0;
85 bw_param = 2;
86 break;
87 case 7000000:
88 if_khz = priv->cfg.if_dvbt_7;
89 i = 1;
90 bw_param = 1;
91 break;
92 case 8000000:
93 if_khz = priv->cfg.if_dvbt_8;
94 i = 2;
95 bw_param = 0;
96 break;
97 default:
98 return -EINVAL;
99 }
100
101 num = if_khz;
102 num *= 0x1000000;
103 if_ctl = cxd2820r_div_u64_round_closest(num, 41000);
104 buf[0] = ((if_ctl >> 16) & 0xff);
105 buf[1] = ((if_ctl >> 8) & 0xff);
106 buf[2] = ((if_ctl >> 0) & 0xff);
107
108 ret = cxd2820r_wr_regs(priv, 0x000b6, buf, 3);
109 if (ret)
110 goto error;
111
112 ret = cxd2820r_wr_regs(priv, 0x0009f, bw_params1[i], 5);
113 if (ret)
114 goto error;
115
116 ret = cxd2820r_wr_reg_mask(priv, 0x000d7, bw_param << 6, 0xc0);
117 if (ret)
118 goto error;
119
120 ret = cxd2820r_wr_regs(priv, 0x000d9, bw_params2[i], 2);
121 if (ret)
122 goto error;
123
124 ret = cxd2820r_wr_reg(priv, 0x000ff, 0x08);
125 if (ret)
126 goto error;
127
128 ret = cxd2820r_wr_reg(priv, 0x000fe, 0x01);
129 if (ret)
130 goto error;
131
132 return ret;
133error:
134 dbg("%s: failed:%d", __func__, ret);
135 return ret;
136}
137
138int cxd2820r_get_frontend_t(struct dvb_frontend *fe,
139 struct dvb_frontend_parameters *p)
140{
141 struct cxd2820r_priv *priv = fe->demodulator_priv;
142 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
143 int ret;
144 u8 buf[2];
145
146 ret = cxd2820r_rd_regs(priv, 0x0002f, buf, sizeof(buf));
147 if (ret)
148 goto error;
149
150 switch ((buf[0] >> 6) & 0x03) {
151 case 0:
152 c->modulation = QPSK;
153 break;
154 case 1:
155 c->modulation = QAM_16;
156 break;
157 case 2:
158 c->modulation = QAM_64;
159 break;
160 }
161
162 switch ((buf[1] >> 1) & 0x03) {
163 case 0:
164 c->transmission_mode = TRANSMISSION_MODE_2K;
165 break;
166 case 1:
167 c->transmission_mode = TRANSMISSION_MODE_8K;
168 break;
169 }
170
171 switch ((buf[1] >> 3) & 0x03) {
172 case 0:
173 c->guard_interval = GUARD_INTERVAL_1_32;
174 break;
175 case 1:
176 c->guard_interval = GUARD_INTERVAL_1_16;
177 break;
178 case 2:
179 c->guard_interval = GUARD_INTERVAL_1_8;
180 break;
181 case 3:
182 c->guard_interval = GUARD_INTERVAL_1_4;
183 break;
184 }
185
186 switch ((buf[0] >> 3) & 0x07) {
187 case 0:
188 c->hierarchy = HIERARCHY_NONE;
189 break;
190 case 1:
191 c->hierarchy = HIERARCHY_1;
192 break;
193 case 2:
194 c->hierarchy = HIERARCHY_2;
195 break;
196 case 3:
197 c->hierarchy = HIERARCHY_4;
198 break;
199 }
200
201 switch ((buf[0] >> 0) & 0x07) {
202 case 0:
203 c->code_rate_HP = FEC_1_2;
204 break;
205 case 1:
206 c->code_rate_HP = FEC_2_3;
207 break;
208 case 2:
209 c->code_rate_HP = FEC_3_4;
210 break;
211 case 3:
212 c->code_rate_HP = FEC_5_6;
213 break;
214 case 4:
215 c->code_rate_HP = FEC_7_8;
216 break;
217 }
218
219 switch ((buf[1] >> 5) & 0x07) {
220 case 0:
221 c->code_rate_LP = FEC_1_2;
222 break;
223 case 1:
224 c->code_rate_LP = FEC_2_3;
225 break;
226 case 2:
227 c->code_rate_LP = FEC_3_4;
228 break;
229 case 3:
230 c->code_rate_LP = FEC_5_6;
231 break;
232 case 4:
233 c->code_rate_LP = FEC_7_8;
234 break;
235 }
236
237 ret = cxd2820r_rd_reg(priv, 0x007c6, &buf[0]);
238 if (ret)
239 goto error;
240
241 switch ((buf[0] >> 0) & 0x01) {
242 case 0:
243 c->inversion = INVERSION_OFF;
244 break;
245 case 1:
246 c->inversion = INVERSION_ON;
247 break;
248 }
249
250 return ret;
251error:
252 dbg("%s: failed:%d", __func__, ret);
253 return ret;
254}
255
256int cxd2820r_read_ber_t(struct dvb_frontend *fe, u32 *ber)
257{
258 struct cxd2820r_priv *priv = fe->demodulator_priv;
259 int ret;
260 u8 buf[3], start_ber = 0;
261 *ber = 0;
262
263 if (priv->ber_running) {
264 ret = cxd2820r_rd_regs(priv, 0x00076, buf, sizeof(buf));
265 if (ret)
266 goto error;
267
268 if ((buf[2] >> 7) & 0x01 || (buf[2] >> 4) & 0x01) {
269 *ber = (buf[2] & 0x0f) << 16 | buf[1] << 8 | buf[0];
270 start_ber = 1;
271 }
272 } else {
273 priv->ber_running = 1;
274 start_ber = 1;
275 }
276
277 if (start_ber) {
278 /* (re)start BER */
279 ret = cxd2820r_wr_reg(priv, 0x00079, 0x01);
280 if (ret)
281 goto error;
282 }
283
284 return ret;
285error:
286 dbg("%s: failed:%d", __func__, ret);
287 return ret;
288}
289
290int cxd2820r_read_signal_strength_t(struct dvb_frontend *fe,
291 u16 *strength)
292{
293 struct cxd2820r_priv *priv = fe->demodulator_priv;
294 int ret;
295 u8 buf[2];
296 u16 tmp;
297
298 ret = cxd2820r_rd_regs(priv, 0x00026, buf, sizeof(buf));
299 if (ret)
300 goto error;
301
302 tmp = (buf[0] & 0x0f) << 8 | buf[1];
303 tmp = ~tmp & 0x0fff;
304
305 /* scale value to 0x0000-0xffff from 0x0000-0x0fff */
306 *strength = tmp * 0xffff / 0x0fff;
307
308 return ret;
309error:
310 dbg("%s: failed:%d", __func__, ret);
311 return ret;
312}
313
314int cxd2820r_read_snr_t(struct dvb_frontend *fe, u16 *snr)
315{
316 struct cxd2820r_priv *priv = fe->demodulator_priv;
317 int ret;
318 u8 buf[2];
319 u16 tmp;
320 /* report SNR in dB * 10 */
321
322 ret = cxd2820r_rd_regs(priv, 0x00028, buf, sizeof(buf));
323 if (ret)
324 goto error;
325
326 tmp = (buf[0] & 0x1f) << 8 | buf[1];
327 #define CXD2820R_LOG10_8_24 15151336 /* log10(8) << 24 */
328 if (tmp)
329 *snr = (intlog10(tmp) - CXD2820R_LOG10_8_24) / ((1 << 24)
330 / 100);
331 else
332 *snr = 0;
333
334 dbg("%s: dBx10=%d val=%04x", __func__, *snr, tmp);
335
336 return ret;
337error:
338 dbg("%s: failed:%d", __func__, ret);
339 return ret;
340}
341
342int cxd2820r_read_ucblocks_t(struct dvb_frontend *fe, u32 *ucblocks)
343{
344 *ucblocks = 0;
345 /* no way to read ? */
346 return 0;
347}
348
349int cxd2820r_read_status_t(struct dvb_frontend *fe, fe_status_t *status)
350{
351 struct cxd2820r_priv *priv = fe->demodulator_priv;
352 int ret;
353 u8 buf[4];
354 *status = 0;
355
356 ret = cxd2820r_rd_reg(priv, 0x00010, &buf[0]);
357 if (ret)
358 goto error;
359
360 if ((buf[0] & 0x07) == 6) {
361 ret = cxd2820r_rd_reg(priv, 0x00073, &buf[1]);
362 if (ret)
363 goto error;
364
365 if (((buf[1] >> 3) & 0x01) == 1) {
366 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
367 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
368 } else {
369 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
370 FE_HAS_VITERBI | FE_HAS_SYNC;
371 }
372 } else {
373 ret = cxd2820r_rd_reg(priv, 0x00014, &buf[2]);
374 if (ret)
375 goto error;
376
377 if ((buf[2] & 0x0f) >= 4) {
378 ret = cxd2820r_rd_reg(priv, 0x00a14, &buf[3]);
379 if (ret)
380 goto error;
381
382 if (((buf[3] >> 4) & 0x01) == 1)
383 *status |= FE_HAS_SIGNAL;
384 }
385 }
386
387 dbg("%s: lock=%02x %02x %02x %02x", __func__,
388 buf[0], buf[1], buf[2], buf[3]);
389
390 return ret;
391error:
392 dbg("%s: failed:%d", __func__, ret);
393 return ret;
394}
395
396int cxd2820r_init_t(struct dvb_frontend *fe)
397{
398 struct cxd2820r_priv *priv = fe->demodulator_priv;
399 int ret;
400
401 ret = cxd2820r_wr_reg(priv, 0x00085, 0x07);
402 if (ret)
403 goto error;
404
405 return ret;
406error:
407 dbg("%s: failed:%d", __func__, ret);
408 return ret;
409}
410
411int cxd2820r_sleep_t(struct dvb_frontend *fe)
412{
413 struct cxd2820r_priv *priv = fe->demodulator_priv;
414 int ret, i;
415 struct reg_val_mask tab[] = {
416 { 0x000ff, 0x1f, 0xff },
417 { 0x00085, 0x00, 0xff },
418 { 0x00088, 0x01, 0xff },
419 { 0x00081, 0x00, 0xff },
420 { 0x00080, 0x00, 0xff },
421 };
422
423 dbg("%s", __func__);
424
425 priv->delivery_system = SYS_UNDEFINED;
426
427 for (i = 0; i < ARRAY_SIZE(tab); i++) {
428 ret = cxd2820r_wr_reg_mask(priv, tab[i].reg, tab[i].val,
429 tab[i].mask);
430 if (ret)
431 goto error;
432 }
433
434 return ret;
435error:
436 dbg("%s: failed:%d", __func__, ret);
437 return ret;
438}
439
440int cxd2820r_get_tune_settings_t(struct dvb_frontend *fe,
441 struct dvb_frontend_tune_settings *s)
442{
443 s->min_delay_ms = 500;
444 s->step_size = fe->ops.info.frequency_stepsize * 2;
445 s->max_drift = (fe->ops.info.frequency_stepsize * 2) + 1;
446
447 return 0;
448}
449
diff --git a/drivers/media/dvb/frontends/cxd2820r_t2.c b/drivers/media/dvb/frontends/cxd2820r_t2.c
new file mode 100644
index 000000000000..c47b35c8acf1
--- /dev/null
+++ b/drivers/media/dvb/frontends/cxd2820r_t2.c
@@ -0,0 +1,423 @@
1/*
2 * Sony CXD2820R demodulator driver
3 *
4 * Copyright (C) 2010 Antti Palosaari <crope@iki.fi>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21
22#include "cxd2820r_priv.h"
23
24int cxd2820r_set_frontend_t2(struct dvb_frontend *fe,
25 struct dvb_frontend_parameters *params)
26{
27 struct cxd2820r_priv *priv = fe->demodulator_priv;
28 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
29 int ret, i;
30 u32 if_khz, if_ctl;
31 u64 num;
32 u8 buf[3], bw_param;
33 u8 bw_params1[][5] = {
34 { 0x1c, 0xb3, 0x33, 0x33, 0x33 }, /* 5 MHz */
35 { 0x17, 0xea, 0xaa, 0xaa, 0xaa }, /* 6 MHz */
36 { 0x14, 0x80, 0x00, 0x00, 0x00 }, /* 7 MHz */
37 { 0x11, 0xf0, 0x00, 0x00, 0x00 }, /* 8 MHz */
38 };
39 struct reg_val_mask tab[] = {
40 { 0x00080, 0x02, 0xff },
41 { 0x00081, 0x20, 0xff },
42 { 0x00085, 0x07, 0xff },
43 { 0x00088, 0x01, 0xff },
44 { 0x02069, 0x01, 0xff },
45
46 { 0x0207f, 0x2a, 0xff },
47 { 0x02082, 0x0a, 0xff },
48 { 0x02083, 0x0a, 0xff },
49 { 0x020cb, priv->cfg.if_agc_polarity << 6, 0x40 },
50 { 0x02070, priv->cfg.ts_mode, 0xff },
51 { 0x020b5, priv->cfg.spec_inv << 4, 0x10 },
52 { 0x02567, 0x07, 0x0f },
53 { 0x02569, 0x03, 0x03 },
54 { 0x02595, 0x1a, 0xff },
55 { 0x02596, 0x50, 0xff },
56 { 0x02a8c, 0x00, 0xff },
57 { 0x02a8d, 0x34, 0xff },
58 { 0x02a45, 0x06, 0x07 },
59 { 0x03f10, 0x0d, 0xff },
60 { 0x03f11, 0x02, 0xff },
61 { 0x03f12, 0x01, 0xff },
62 { 0x03f23, 0x2c, 0xff },
63 { 0x03f51, 0x13, 0xff },
64 { 0x03f52, 0x01, 0xff },
65 { 0x03f53, 0x00, 0xff },
66 { 0x027e6, 0x14, 0xff },
67 { 0x02786, 0x02, 0x07 },
68 { 0x02787, 0x40, 0xe0 },
69 { 0x027ef, 0x10, 0x18 },
70 };
71
72 dbg("%s: RF=%d BW=%d", __func__, c->frequency, c->bandwidth_hz);
73
74 /* update GPIOs */
75 ret = cxd2820r_gpio(fe);
76 if (ret)
77 goto error;
78
79 /* program tuner */
80 if (fe->ops.tuner_ops.set_params)
81 fe->ops.tuner_ops.set_params(fe, params);
82
83 if (priv->delivery_system != SYS_DVBT2) {
84 for (i = 0; i < ARRAY_SIZE(tab); i++) {
85 ret = cxd2820r_wr_reg_mask(priv, tab[i].reg,
86 tab[i].val, tab[i].mask);
87 if (ret)
88 goto error;
89 }
90 }
91
92 priv->delivery_system = SYS_DVBT2;
93
94 switch (c->bandwidth_hz) {
95 case 5000000:
96 if_khz = priv->cfg.if_dvbt2_5;
97 i = 0;
98 bw_param = 3;
99 break;
100 case 6000000:
101 if_khz = priv->cfg.if_dvbt2_6;
102 i = 1;
103 bw_param = 2;
104 break;
105 case 7000000:
106 if_khz = priv->cfg.if_dvbt2_7;
107 i = 2;
108 bw_param = 1;
109 break;
110 case 8000000:
111 if_khz = priv->cfg.if_dvbt2_8;
112 i = 3;
113 bw_param = 0;
114 break;
115 default:
116 return -EINVAL;
117 }
118
119 num = if_khz;
120 num *= 0x1000000;
121 if_ctl = cxd2820r_div_u64_round_closest(num, 41000);
122 buf[0] = ((if_ctl >> 16) & 0xff);
123 buf[1] = ((if_ctl >> 8) & 0xff);
124 buf[2] = ((if_ctl >> 0) & 0xff);
125
126 ret = cxd2820r_wr_regs(priv, 0x020b6, buf, 3);
127 if (ret)
128 goto error;
129
130 ret = cxd2820r_wr_regs(priv, 0x0209f, bw_params1[i], 5);
131 if (ret)
132 goto error;
133
134 ret = cxd2820r_wr_reg_mask(priv, 0x020d7, bw_param << 6, 0xc0);
135 if (ret)
136 goto error;
137
138 ret = cxd2820r_wr_reg(priv, 0x000ff, 0x08);
139 if (ret)
140 goto error;
141
142 ret = cxd2820r_wr_reg(priv, 0x000fe, 0x01);
143 if (ret)
144 goto error;
145
146 return ret;
147error:
148 dbg("%s: failed:%d", __func__, ret);
149 return ret;
150
151}
152
153int cxd2820r_get_frontend_t2(struct dvb_frontend *fe,
154 struct dvb_frontend_parameters *p)
155{
156 struct cxd2820r_priv *priv = fe->demodulator_priv;
157 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
158 int ret;
159 u8 buf[2];
160
161 ret = cxd2820r_rd_regs(priv, 0x0205c, buf, 2);
162 if (ret)
163 goto error;
164
165 switch ((buf[0] >> 0) & 0x07) {
166 case 0:
167 c->transmission_mode = TRANSMISSION_MODE_2K;
168 break;
169 case 1:
170 c->transmission_mode = TRANSMISSION_MODE_8K;
171 break;
172 case 2:
173 c->transmission_mode = TRANSMISSION_MODE_4K;
174 break;
175 case 3:
176 c->transmission_mode = TRANSMISSION_MODE_1K;
177 break;
178 case 4:
179 c->transmission_mode = TRANSMISSION_MODE_16K;
180 break;
181 case 5:
182 c->transmission_mode = TRANSMISSION_MODE_32K;
183 break;
184 }
185
186 switch ((buf[1] >> 4) & 0x07) {
187 case 0:
188 c->guard_interval = GUARD_INTERVAL_1_32;
189 break;
190 case 1:
191 c->guard_interval = GUARD_INTERVAL_1_16;
192 break;
193 case 2:
194 c->guard_interval = GUARD_INTERVAL_1_8;
195 break;
196 case 3:
197 c->guard_interval = GUARD_INTERVAL_1_4;
198 break;
199 case 4:
200 c->guard_interval = GUARD_INTERVAL_1_128;
201 break;
202 case 5:
203 c->guard_interval = GUARD_INTERVAL_19_128;
204 break;
205 case 6:
206 c->guard_interval = GUARD_INTERVAL_19_256;
207 break;
208 }
209
210 ret = cxd2820r_rd_regs(priv, 0x0225b, buf, 2);
211 if (ret)
212 goto error;
213
214 switch ((buf[0] >> 0) & 0x07) {
215 case 0:
216 c->fec_inner = FEC_1_2;
217 break;
218 case 1:
219 c->fec_inner = FEC_3_5;
220 break;
221 case 2:
222 c->fec_inner = FEC_2_3;
223 break;
224 case 3:
225 c->fec_inner = FEC_3_4;
226 break;
227 case 4:
228 c->fec_inner = FEC_4_5;
229 break;
230 case 5:
231 c->fec_inner = FEC_5_6;
232 break;
233 }
234
235 switch ((buf[1] >> 0) & 0x07) {
236 case 0:
237 c->modulation = QPSK;
238 break;
239 case 1:
240 c->modulation = QAM_16;
241 break;
242 case 2:
243 c->modulation = QAM_64;
244 break;
245 case 3:
246 c->modulation = QAM_256;
247 break;
248 }
249
250 ret = cxd2820r_rd_reg(priv, 0x020b5, &buf[0]);
251 if (ret)
252 goto error;
253
254 switch ((buf[0] >> 4) & 0x01) {
255 case 0:
256 c->inversion = INVERSION_OFF;
257 break;
258 case 1:
259 c->inversion = INVERSION_ON;
260 break;
261 }
262
263 return ret;
264error:
265 dbg("%s: failed:%d", __func__, ret);
266 return ret;
267}
268
269int cxd2820r_read_status_t2(struct dvb_frontend *fe, fe_status_t *status)
270{
271 struct cxd2820r_priv *priv = fe->demodulator_priv;
272 int ret;
273 u8 buf[1];
274 *status = 0;
275
276 ret = cxd2820r_rd_reg(priv, 0x02010 , &buf[0]);
277 if (ret)
278 goto error;
279
280 if ((buf[0] & 0x07) == 6) {
281 if (((buf[0] >> 5) & 0x01) == 1) {
282 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
283 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
284 } else {
285 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
286 FE_HAS_VITERBI | FE_HAS_SYNC;
287 }
288 }
289
290 dbg("%s: lock=%02x", __func__, buf[0]);
291
292 return ret;
293error:
294 dbg("%s: failed:%d", __func__, ret);
295 return ret;
296}
297
298int cxd2820r_read_ber_t2(struct dvb_frontend *fe, u32 *ber)
299{
300 struct cxd2820r_priv *priv = fe->demodulator_priv;
301 int ret;
302 u8 buf[4];
303 unsigned int errbits;
304 *ber = 0;
305 /* FIXME: correct calculation */
306
307 ret = cxd2820r_rd_regs(priv, 0x02039, buf, sizeof(buf));
308 if (ret)
309 goto error;
310
311 if ((buf[0] >> 4) & 0x01) {
312 errbits = (buf[0] & 0x0f) << 24 | buf[1] << 16 |
313 buf[2] << 8 | buf[3];
314
315 if (errbits)
316 *ber = errbits * 64 / 16588800;
317 }
318
319 return ret;
320error:
321 dbg("%s: failed:%d", __func__, ret);
322 return ret;
323}
324
325int cxd2820r_read_signal_strength_t2(struct dvb_frontend *fe,
326 u16 *strength)
327{
328 struct cxd2820r_priv *priv = fe->demodulator_priv;
329 int ret;
330 u8 buf[2];
331 u16 tmp;
332
333 ret = cxd2820r_rd_regs(priv, 0x02026, buf, sizeof(buf));
334 if (ret)
335 goto error;
336
337 tmp = (buf[0] & 0x0f) << 8 | buf[1];
338 tmp = ~tmp & 0x0fff;
339
340 /* scale value to 0x0000-0xffff from 0x0000-0x0fff */
341 *strength = tmp * 0xffff / 0x0fff;
342
343 return ret;
344error:
345 dbg("%s: failed:%d", __func__, ret);
346 return ret;
347}
348
349int cxd2820r_read_snr_t2(struct dvb_frontend *fe, u16 *snr)
350{
351 struct cxd2820r_priv *priv = fe->demodulator_priv;
352 int ret;
353 u8 buf[2];
354 u16 tmp;
355 /* report SNR in dB * 10 */
356
357 ret = cxd2820r_rd_regs(priv, 0x02028, buf, sizeof(buf));
358 if (ret)
359 goto error;
360
361 tmp = (buf[0] & 0x0f) << 8 | buf[1];
362 #define CXD2820R_LOG10_8_24 15151336 /* log10(8) << 24 */
363 if (tmp)
364 *snr = (intlog10(tmp) - CXD2820R_LOG10_8_24) / ((1 << 24)
365 / 100);
366 else
367 *snr = 0;
368
369 dbg("%s: dBx10=%d val=%04x", __func__, *snr, tmp);
370
371 return ret;
372error:
373 dbg("%s: failed:%d", __func__, ret);
374 return ret;
375}
376
377int cxd2820r_read_ucblocks_t2(struct dvb_frontend *fe, u32 *ucblocks)
378{
379 *ucblocks = 0;
380 /* no way to read ? */
381 return 0;
382}
383
384int cxd2820r_sleep_t2(struct dvb_frontend *fe)
385{
386 struct cxd2820r_priv *priv = fe->demodulator_priv;
387 int ret, i;
388 struct reg_val_mask tab[] = {
389 { 0x000ff, 0x1f, 0xff },
390 { 0x00085, 0x00, 0xff },
391 { 0x00088, 0x01, 0xff },
392 { 0x02069, 0x00, 0xff },
393 { 0x00081, 0x00, 0xff },
394 { 0x00080, 0x00, 0xff },
395 };
396
397 dbg("%s", __func__);
398
399 for (i = 0; i < ARRAY_SIZE(tab); i++) {
400 ret = cxd2820r_wr_reg_mask(priv, tab[i].reg, tab[i].val,
401 tab[i].mask);
402 if (ret)
403 goto error;
404 }
405
406 priv->delivery_system = SYS_UNDEFINED;
407
408 return ret;
409error:
410 dbg("%s: failed:%d", __func__, ret);
411 return ret;
412}
413
414int cxd2820r_get_tune_settings_t2(struct dvb_frontend *fe,
415 struct dvb_frontend_tune_settings *s)
416{
417 s->min_delay_ms = 1500;
418 s->step_size = fe->ops.info.frequency_stepsize * 2;
419 s->max_drift = (fe->ops.info.frequency_stepsize * 2) + 1;
420
421 return 0;
422}
423
diff --git a/drivers/media/dvb/frontends/dib0070.c b/drivers/media/dvb/frontends/dib0070.c
index d4e466a90e43..1d47d4da7d4c 100644
--- a/drivers/media/dvb/frontends/dib0070.c
+++ b/drivers/media/dvb/frontends/dib0070.c
@@ -73,27 +73,47 @@ struct dib0070_state {
73 73
74 u8 wbd_gain_current; 74 u8 wbd_gain_current;
75 u16 wbd_offset_3_3[2]; 75 u16 wbd_offset_3_3[2];
76
77 /* for the I2C transfer */
78 struct i2c_msg msg[2];
79 u8 i2c_write_buffer[3];
80 u8 i2c_read_buffer[2];
76}; 81};
77 82
78static uint16_t dib0070_read_reg(struct dib0070_state *state, u8 reg) 83static uint16_t dib0070_read_reg(struct dib0070_state *state, u8 reg)
79{ 84{
80 u8 b[2]; 85 state->i2c_write_buffer[0] = reg;
81 struct i2c_msg msg[2] = { 86
82 { .addr = state->cfg->i2c_address, .flags = 0, .buf = &reg, .len = 1 }, 87 memset(state->msg, 0, 2 * sizeof(struct i2c_msg));
83 { .addr = state->cfg->i2c_address, .flags = I2C_M_RD, .buf = b, .len = 2 }, 88 state->msg[0].addr = state->cfg->i2c_address;
84 }; 89 state->msg[0].flags = 0;
85 if (i2c_transfer(state->i2c, msg, 2) != 2) { 90 state->msg[0].buf = state->i2c_write_buffer;
91 state->msg[0].len = 1;
92 state->msg[1].addr = state->cfg->i2c_address;
93 state->msg[1].flags = I2C_M_RD;
94 state->msg[1].buf = state->i2c_read_buffer;
95 state->msg[1].len = 2;
96
97 if (i2c_transfer(state->i2c, state->msg, 2) != 2) {
86 printk(KERN_WARNING "DiB0070 I2C read failed\n"); 98 printk(KERN_WARNING "DiB0070 I2C read failed\n");
87 return 0; 99 return 0;
88 } 100 }
89 return (b[0] << 8) | b[1]; 101 return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
90} 102}
91 103
92static int dib0070_write_reg(struct dib0070_state *state, u8 reg, u16 val) 104static int dib0070_write_reg(struct dib0070_state *state, u8 reg, u16 val)
93{ 105{
94 u8 b[3] = { reg, val >> 8, val & 0xff }; 106 state->i2c_write_buffer[0] = reg;
95 struct i2c_msg msg = { .addr = state->cfg->i2c_address, .flags = 0, .buf = b, .len = 3 }; 107 state->i2c_write_buffer[1] = val >> 8;
96 if (i2c_transfer(state->i2c, &msg, 1) != 1) { 108 state->i2c_write_buffer[2] = val & 0xff;
109
110 memset(state->msg, 0, sizeof(struct i2c_msg));
111 state->msg[0].addr = state->cfg->i2c_address;
112 state->msg[0].flags = 0;
113 state->msg[0].buf = state->i2c_write_buffer;
114 state->msg[0].len = 3;
115
116 if (i2c_transfer(state->i2c, state->msg, 1) != 1) {
97 printk(KERN_WARNING "DiB0070 I2C write failed\n"); 117 printk(KERN_WARNING "DiB0070 I2C write failed\n");
98 return -EREMOTEIO; 118 return -EREMOTEIO;
99 } 119 }
diff --git a/drivers/media/dvb/frontends/dib0090.c b/drivers/media/dvb/frontends/dib0090.c
index 65240b7801e8..c9c935ae41e4 100644
--- a/drivers/media/dvb/frontends/dib0090.c
+++ b/drivers/media/dvb/frontends/dib0090.c
@@ -45,6 +45,7 @@ MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
45 } \ 45 } \
46} while (0) 46} while (0)
47 47
48#define CONFIG_SYS_DVBT
48#define CONFIG_SYS_ISDBT 49#define CONFIG_SYS_ISDBT
49#define CONFIG_BAND_CBAND 50#define CONFIG_BAND_CBAND
50#define CONFIG_BAND_VHF 51#define CONFIG_BAND_VHF
@@ -76,6 +77,34 @@ MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
76#define EN_SBD 0x44E9 77#define EN_SBD 0x44E9
77#define EN_CAB 0x88E9 78#define EN_CAB 0x88E9
78 79
80/* Calibration defines */
81#define DC_CAL 0x1
82#define WBD_CAL 0x2
83#define TEMP_CAL 0x4
84#define CAPTRIM_CAL 0x8
85
86#define KROSUS_PLL_LOCKED 0x800
87#define KROSUS 0x2
88
89/* Use those defines to identify SOC version */
90#define SOC 0x02
91#define SOC_7090_P1G_11R1 0x82
92#define SOC_7090_P1G_21R1 0x8a
93#define SOC_8090_P1G_11R1 0x86
94#define SOC_8090_P1G_21R1 0x8e
95
96/* else use thos ones to check */
97#define P1A_B 0x0
98#define P1C 0x1
99#define P1D_E_F 0x3
100#define P1G 0x7
101#define P1G_21R2 0xf
102
103#define MP001 0x1 /* Single 9090/8096 */
104#define MP005 0x4 /* Single Sband */
105#define MP008 0x6 /* Dual diversity VHF-UHF-LBAND */
106#define MP009 0x7 /* Dual diversity 29098 CBAND-UHF-LBAND-SBAND */
107
79#define pgm_read_word(w) (*w) 108#define pgm_read_word(w) (*w)
80 109
81struct dc_calibration; 110struct dc_calibration;
@@ -84,7 +113,7 @@ struct dib0090_tuning {
84 u32 max_freq; /* for every frequency less than or equal to that field: this information is correct */ 113 u32 max_freq; /* for every frequency less than or equal to that field: this information is correct */
85 u8 switch_trim; 114 u8 switch_trim;
86 u8 lna_tune; 115 u8 lna_tune;
87 u8 lna_bias; 116 u16 lna_bias;
88 u16 v2i; 117 u16 v2i;
89 u16 mix; 118 u16 mix;
90 u16 load; 119 u16 load;
@@ -99,13 +128,19 @@ struct dib0090_pll {
99 u8 topresc; 128 u8 topresc;
100}; 129};
101 130
131struct dib0090_identity {
132 u8 version;
133 u8 product;
134 u8 p1g;
135 u8 in_soc;
136};
137
102struct dib0090_state { 138struct dib0090_state {
103 struct i2c_adapter *i2c; 139 struct i2c_adapter *i2c;
104 struct dvb_frontend *fe; 140 struct dvb_frontend *fe;
105 const struct dib0090_config *config; 141 const struct dib0090_config *config;
106 142
107 u8 current_band; 143 u8 current_band;
108 u16 revision;
109 enum frontend_tune_state tune_state; 144 enum frontend_tune_state tune_state;
110 u32 current_rf; 145 u32 current_rf;
111 146
@@ -143,28 +178,106 @@ struct dib0090_state {
143 u8 tuner_is_tuned; 178 u8 tuner_is_tuned;
144 u8 agc_freeze; 179 u8 agc_freeze;
145 180
146 u8 reset; 181 struct dib0090_identity identity;
182
183 u32 rf_request;
184 u8 current_standard;
185
186 u8 calibrate;
187 u32 rest;
188 u16 bias;
189 s16 temperature;
190
191 u8 wbd_calibration_gain;
192 const struct dib0090_wbd_slope *current_wbd_table;
193 u16 wbdmux;
194
195 /* for the I2C transfer */
196 struct i2c_msg msg[2];
197 u8 i2c_write_buffer[3];
198 u8 i2c_read_buffer[2];
199};
200
201struct dib0090_fw_state {
202 struct i2c_adapter *i2c;
203 struct dvb_frontend *fe;
204 struct dib0090_identity identity;
205 const struct dib0090_config *config;
206
207 /* for the I2C transfer */
208 struct i2c_msg msg;
209 u8 i2c_write_buffer[2];
210 u8 i2c_read_buffer[2];
147}; 211};
148 212
149static u16 dib0090_read_reg(struct dib0090_state *state, u8 reg) 213static u16 dib0090_read_reg(struct dib0090_state *state, u8 reg)
150{ 214{
151 u8 b[2]; 215 state->i2c_write_buffer[0] = reg;
152 struct i2c_msg msg[2] = { 216
153 {.addr = state->config->i2c_address, .flags = 0, .buf = &reg, .len = 1}, 217 memset(state->msg, 0, 2 * sizeof(struct i2c_msg));
154 {.addr = state->config->i2c_address, .flags = I2C_M_RD, .buf = b, .len = 2}, 218 state->msg[0].addr = state->config->i2c_address;
155 }; 219 state->msg[0].flags = 0;
156 if (i2c_transfer(state->i2c, msg, 2) != 2) { 220 state->msg[0].buf = state->i2c_write_buffer;
221 state->msg[0].len = 1;
222 state->msg[1].addr = state->config->i2c_address;
223 state->msg[1].flags = I2C_M_RD;
224 state->msg[1].buf = state->i2c_read_buffer;
225 state->msg[1].len = 2;
226
227 if (i2c_transfer(state->i2c, state->msg, 2) != 2) {
157 printk(KERN_WARNING "DiB0090 I2C read failed\n"); 228 printk(KERN_WARNING "DiB0090 I2C read failed\n");
158 return 0; 229 return 0;
159 } 230 }
160 return (b[0] << 8) | b[1]; 231
232 return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
161} 233}
162 234
163static int dib0090_write_reg(struct dib0090_state *state, u32 reg, u16 val) 235static int dib0090_write_reg(struct dib0090_state *state, u32 reg, u16 val)
164{ 236{
165 u8 b[3] = { reg & 0xff, val >> 8, val & 0xff }; 237 state->i2c_write_buffer[0] = reg & 0xff;
166 struct i2c_msg msg = {.addr = state->config->i2c_address, .flags = 0, .buf = b, .len = 3 }; 238 state->i2c_write_buffer[1] = val >> 8;
167 if (i2c_transfer(state->i2c, &msg, 1) != 1) { 239 state->i2c_write_buffer[2] = val & 0xff;
240
241 memset(state->msg, 0, sizeof(struct i2c_msg));
242 state->msg[0].addr = state->config->i2c_address;
243 state->msg[0].flags = 0;
244 state->msg[0].buf = state->i2c_write_buffer;
245 state->msg[0].len = 3;
246
247 if (i2c_transfer(state->i2c, state->msg, 1) != 1) {
248 printk(KERN_WARNING "DiB0090 I2C write failed\n");
249 return -EREMOTEIO;
250 }
251 return 0;
252}
253
254static u16 dib0090_fw_read_reg(struct dib0090_fw_state *state, u8 reg)
255{
256 state->i2c_write_buffer[0] = reg;
257
258 memset(&state->msg, 0, sizeof(struct i2c_msg));
259 state->msg.addr = reg;
260 state->msg.flags = I2C_M_RD;
261 state->msg.buf = state->i2c_read_buffer;
262 state->msg.len = 2;
263 if (i2c_transfer(state->i2c, &state->msg, 1) != 1) {
264 printk(KERN_WARNING "DiB0090 I2C read failed\n");
265 return 0;
266 }
267 return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
268}
269
270static int dib0090_fw_write_reg(struct dib0090_fw_state *state, u8 reg, u16 val)
271{
272 state->i2c_write_buffer[0] = val >> 8;
273 state->i2c_write_buffer[1] = val & 0xff;
274
275 memset(&state->msg, 0, sizeof(struct i2c_msg));
276 state->msg.addr = reg;
277 state->msg.flags = 0;
278 state->msg.buf = state->i2c_write_buffer;
279 state->msg.len = 2;
280 if (i2c_transfer(state->i2c, &state->msg, 1) != 1) {
168 printk(KERN_WARNING "DiB0090 I2C write failed\n"); 281 printk(KERN_WARNING "DiB0090 I2C write failed\n");
169 return -EREMOTEIO; 282 return -EREMOTEIO;
170 } 283 }
@@ -183,89 +296,327 @@ static void dib0090_write_regs(struct dib0090_state *state, u8 r, const u16 * b,
183 } while (--c); 296 } while (--c);
184} 297}
185 298
186static u16 dib0090_identify(struct dvb_frontend *fe) 299static int dib0090_identify(struct dvb_frontend *fe)
187{ 300{
188 struct dib0090_state *state = fe->tuner_priv; 301 struct dib0090_state *state = fe->tuner_priv;
189 u16 v; 302 u16 v;
303 struct dib0090_identity *identity = &state->identity;
190 304
191 v = dib0090_read_reg(state, 0x1a); 305 v = dib0090_read_reg(state, 0x1a);
192 306
193#ifdef FIRMWARE_FIREFLY 307 identity->p1g = 0;
194 /* pll is not locked locked */ 308 identity->in_soc = 0;
195 if (!(v & 0x800)) 309
196 dprintk("FE%d : Identification : pll is not yet locked", fe->id); 310 dprintk("Tuner identification (Version = 0x%04x)", v);
197#endif
198 311
199 /* without PLL lock info */ 312 /* without PLL lock info */
200 v &= 0x3ff; 313 v &= ~KROSUS_PLL_LOCKED;
201 dprintk("P/V: %04x:", v);
202 314
203 if ((v >> 8) & 0xf) 315 identity->version = v & 0xff;
204 dprintk("FE%d : Product ID = 0x%x : KROSUS", fe->id, (v >> 8) & 0xf); 316 identity->product = (v >> 8) & 0xf;
205 else 317
206 return 0xff; 318 if (identity->product != KROSUS)
207 319 goto identification_error;
208 v &= 0xff; 320
209 if (((v >> 5) & 0x7) == 0x1) 321 if ((identity->version & 0x3) == SOC) {
210 dprintk("FE%d : MP001 : 9090/8096", fe->id); 322 identity->in_soc = 1;
211 else if (((v >> 5) & 0x7) == 0x4) 323 switch (identity->version) {
212 dprintk("FE%d : MP005 : Single Sband", fe->id); 324 case SOC_8090_P1G_11R1:
213 else if (((v >> 5) & 0x7) == 0x6) 325 dprintk("SOC 8090 P1-G11R1 Has been detected");
214 dprintk("FE%d : MP008 : diversity VHF-UHF-LBAND", fe->id); 326 identity->p1g = 1;
215 else if (((v >> 5) & 0x7) == 0x7) 327 break;
216 dprintk("FE%d : MP009 : diversity 29098 CBAND-UHF-LBAND-SBAND", fe->id); 328 case SOC_8090_P1G_21R1:
217 else 329 dprintk("SOC 8090 P1-G21R1 Has been detected");
218 return 0xff; 330 identity->p1g = 1;
219 331 break;
220 /* revision only */ 332 case SOC_7090_P1G_11R1:
221 if ((v & 0x1f) == 0x3) 333 dprintk("SOC 7090 P1-G11R1 Has been detected");
222 dprintk("FE%d : P1-D/E/F detected", fe->id); 334 identity->p1g = 1;
223 else if ((v & 0x1f) == 0x1) 335 break;
224 dprintk("FE%d : P1C detected", fe->id); 336 case SOC_7090_P1G_21R1:
225 else if ((v & 0x1f) == 0x0) { 337 dprintk("SOC 7090 P1-G21R1 Has been detected");
226#ifdef CONFIG_TUNER_DIB0090_P1B_SUPPORT 338 identity->p1g = 1;
227 dprintk("FE%d : P1-A/B detected: using previous driver - support will be removed soon", fe->id); 339 break;
228 dib0090_p1b_register(fe); 340 default:
229#else 341 goto identification_error;
230 dprintk("FE%d : P1-A/B detected: driver is deactivated - not available", fe->id); 342 }
231 return 0xff; 343 } else {
232#endif 344 switch ((identity->version >> 5) & 0x7) {
345 case MP001:
346 dprintk("MP001 : 9090/8096");
347 break;
348 case MP005:
349 dprintk("MP005 : Single Sband");
350 break;
351 case MP008:
352 dprintk("MP008 : diversity VHF-UHF-LBAND");
353 break;
354 case MP009:
355 dprintk("MP009 : diversity 29098 CBAND-UHF-LBAND-SBAND");
356 break;
357 default:
358 goto identification_error;
359 }
360
361 switch (identity->version & 0x1f) {
362 case P1G_21R2:
363 dprintk("P1G_21R2 detected");
364 identity->p1g = 1;
365 break;
366 case P1G:
367 dprintk("P1G detected");
368 identity->p1g = 1;
369 break;
370 case P1D_E_F:
371 dprintk("P1D/E/F detected");
372 break;
373 case P1C:
374 dprintk("P1C detected");
375 break;
376 case P1A_B:
377 dprintk("P1-A/B detected: driver is deactivated - not available");
378 goto identification_error;
379 break;
380 default:
381 goto identification_error;
382 }
233 } 383 }
234 384
235 return v; 385 return 0;
386
387identification_error:
388 return -EIO;
389}
390
391static int dib0090_fw_identify(struct dvb_frontend *fe)
392{
393 struct dib0090_fw_state *state = fe->tuner_priv;
394 struct dib0090_identity *identity = &state->identity;
395
396 u16 v = dib0090_fw_read_reg(state, 0x1a);
397 identity->p1g = 0;
398 identity->in_soc = 0;
399
400 dprintk("FE: Tuner identification (Version = 0x%04x)", v);
401
402 /* without PLL lock info */
403 v &= ~KROSUS_PLL_LOCKED;
404
405 identity->version = v & 0xff;
406 identity->product = (v >> 8) & 0xf;
407
408 if (identity->product != KROSUS)
409 goto identification_error;
410
411 if ((identity->version & 0x3) == SOC) {
412 identity->in_soc = 1;
413 switch (identity->version) {
414 case SOC_8090_P1G_11R1:
415 dprintk("SOC 8090 P1-G11R1 Has been detected");
416 identity->p1g = 1;
417 break;
418 case SOC_8090_P1G_21R1:
419 dprintk("SOC 8090 P1-G21R1 Has been detected");
420 identity->p1g = 1;
421 break;
422 case SOC_7090_P1G_11R1:
423 dprintk("SOC 7090 P1-G11R1 Has been detected");
424 identity->p1g = 1;
425 break;
426 case SOC_7090_P1G_21R1:
427 dprintk("SOC 7090 P1-G21R1 Has been detected");
428 identity->p1g = 1;
429 break;
430 default:
431 goto identification_error;
432 }
433 } else {
434 switch ((identity->version >> 5) & 0x7) {
435 case MP001:
436 dprintk("MP001 : 9090/8096");
437 break;
438 case MP005:
439 dprintk("MP005 : Single Sband");
440 break;
441 case MP008:
442 dprintk("MP008 : diversity VHF-UHF-LBAND");
443 break;
444 case MP009:
445 dprintk("MP009 : diversity 29098 CBAND-UHF-LBAND-SBAND");
446 break;
447 default:
448 goto identification_error;
449 }
450
451 switch (identity->version & 0x1f) {
452 case P1G_21R2:
453 dprintk("P1G_21R2 detected");
454 identity->p1g = 1;
455 break;
456 case P1G:
457 dprintk("P1G detected");
458 identity->p1g = 1;
459 break;
460 case P1D_E_F:
461 dprintk("P1D/E/F detected");
462 break;
463 case P1C:
464 dprintk("P1C detected");
465 break;
466 case P1A_B:
467 dprintk("P1-A/B detected: driver is deactivated - not available");
468 goto identification_error;
469 break;
470 default:
471 goto identification_error;
472 }
473 }
474
475 return 0;
476
477identification_error:
478 return -EIO;;
236} 479}
237 480
238static void dib0090_reset_digital(struct dvb_frontend *fe, const struct dib0090_config *cfg) 481static void dib0090_reset_digital(struct dvb_frontend *fe, const struct dib0090_config *cfg)
239{ 482{
240 struct dib0090_state *state = fe->tuner_priv; 483 struct dib0090_state *state = fe->tuner_priv;
484 u16 PllCfg, i, v;
241 485
242 HARD_RESET(state); 486 HARD_RESET(state);
243 487
244 dib0090_write_reg(state, 0x24, EN_PLL); 488 dib0090_write_reg(state, 0x24, EN_PLL | EN_CRYSTAL);
245 dib0090_write_reg(state, 0x1b, EN_DIGCLK | EN_PLL | EN_CRYSTAL); /* PLL, DIG_CLK and CRYSTAL remain */ 489 dib0090_write_reg(state, 0x1b, EN_DIGCLK | EN_PLL | EN_CRYSTAL); /* PLL, DIG_CLK and CRYSTAL remain */
246 490
247 /* adcClkOutRatio=8->7, release reset */ 491 if (!cfg->in_soc) {
248 dib0090_write_reg(state, 0x20, ((cfg->io.adc_clock_ratio - 1) << 11) | (0 << 10) | (1 << 9) | (1 << 8) | (0 << 4) | 0); 492 /* adcClkOutRatio=8->7, release reset */
493 dib0090_write_reg(state, 0x20, ((cfg->io.adc_clock_ratio - 1) << 11) | (0 << 10) | (1 << 9) | (1 << 8) | (0 << 4) | 0);
494 if (cfg->clkoutdrive != 0)
495 dib0090_write_reg(state, 0x23, (0 << 15) | ((!cfg->analog_output) << 14) | (2 << 10) | (1 << 9) | (0 << 8)
496 | (cfg->clkoutdrive << 5) | (cfg->clkouttobamse << 4) | (0 << 2) | (0));
497 else
498 dib0090_write_reg(state, 0x23, (0 << 15) | ((!cfg->analog_output) << 14) | (2 << 10) | (1 << 9) | (0 << 8)
499 | (7 << 5) | (cfg->clkouttobamse << 4) | (0 << 2) | (0));
500 }
501
502 /* Read Pll current config * */
503 PllCfg = dib0090_read_reg(state, 0x21);
504
505 /** Reconfigure PLL if current setting is different from default setting **/
506 if ((PllCfg & 0x1FFF) != ((cfg->io.pll_range << 12) | (cfg->io.pll_loopdiv << 6) | (cfg->io.pll_prediv)) && (!cfg->in_soc)
507 && !cfg->io.pll_bypass) {
508
509 /* Set Bypass mode */
510 PllCfg |= (1 << 15);
511 dib0090_write_reg(state, 0x21, PllCfg);
512
513 /* Set Reset Pll */
514 PllCfg &= ~(1 << 13);
515 dib0090_write_reg(state, 0x21, PllCfg);
516
517 /*** Set new Pll configuration in bypass and reset state ***/
518 PllCfg = (1 << 15) | (0 << 13) | (cfg->io.pll_range << 12) | (cfg->io.pll_loopdiv << 6) | (cfg->io.pll_prediv);
519 dib0090_write_reg(state, 0x21, PllCfg);
520
521 /* Remove Reset Pll */
522 PllCfg |= (1 << 13);
523 dib0090_write_reg(state, 0x21, PllCfg);
524
525 /*** Wait for PLL lock ***/
526 i = 100;
527 do {
528 v = !!(dib0090_read_reg(state, 0x1a) & 0x800);
529 if (v)
530 break;
531 } while (--i);
532
533 if (i == 0) {
534 dprintk("Pll: Unable to lock Pll");
535 return;
536 }
537
538 /* Finally Remove Bypass mode */
539 PllCfg &= ~(1 << 15);
540 dib0090_write_reg(state, 0x21, PllCfg);
541 }
542
543 if (cfg->io.pll_bypass) {
544 PllCfg |= (cfg->io.pll_bypass << 15);
545 dib0090_write_reg(state, 0x21, PllCfg);
546 }
547}
548
549static int dib0090_fw_reset_digital(struct dvb_frontend *fe, const struct dib0090_config *cfg)
550{
551 struct dib0090_fw_state *state = fe->tuner_priv;
552 u16 PllCfg;
553 u16 v;
554 int i;
555
556 dprintk("fw reset digital");
557 HARD_RESET(state);
558
559 dib0090_fw_write_reg(state, 0x24, EN_PLL | EN_CRYSTAL);
560 dib0090_fw_write_reg(state, 0x1b, EN_DIGCLK | EN_PLL | EN_CRYSTAL); /* PLL, DIG_CLK and CRYSTAL remain */
561
562 dib0090_fw_write_reg(state, 0x20,
563 ((cfg->io.adc_clock_ratio - 1) << 11) | (0 << 10) | (1 << 9) | (1 << 8) | (cfg->data_tx_drv << 4) | cfg->ls_cfg_pad_drv);
564
565 v = (0 << 15) | ((!cfg->analog_output) << 14) | (1 << 9) | (0 << 8) | (cfg->clkouttobamse << 4) | (0 << 2) | (0);
249 if (cfg->clkoutdrive != 0) 566 if (cfg->clkoutdrive != 0)
250 dib0090_write_reg(state, 0x23, 567 v |= cfg->clkoutdrive << 5;
251 (0 << 15) | ((!cfg->analog_output) << 14) | (1 << 10) | (1 << 9) | (0 << 8) | (cfg->clkoutdrive << 5) | (cfg->
252 clkouttobamse
253 << 4) | (0
254 <<
255 2)
256 | (0));
257 else 568 else
258 dib0090_write_reg(state, 0x23, 569 v |= 7 << 5;
259 (0 << 15) | ((!cfg->analog_output) << 14) | (1 << 10) | (1 << 9) | (0 << 8) | (7 << 5) | (cfg-> 570
260 clkouttobamse << 4) | (0 571 v |= 2 << 10;
261 << 572 dib0090_fw_write_reg(state, 0x23, v);
262 2) 573
263 | (0)); 574 /* Read Pll current config * */
575 PllCfg = dib0090_fw_read_reg(state, 0x21);
576
577 /** Reconfigure PLL if current setting is different from default setting **/
578 if ((PllCfg & 0x1FFF) != ((cfg->io.pll_range << 12) | (cfg->io.pll_loopdiv << 6) | (cfg->io.pll_prediv)) && !cfg->io.pll_bypass) {
579
580 /* Set Bypass mode */
581 PllCfg |= (1 << 15);
582 dib0090_fw_write_reg(state, 0x21, PllCfg);
583
584 /* Set Reset Pll */
585 PllCfg &= ~(1 << 13);
586 dib0090_fw_write_reg(state, 0x21, PllCfg);
587
588 /*** Set new Pll configuration in bypass and reset state ***/
589 PllCfg = (1 << 15) | (0 << 13) | (cfg->io.pll_range << 12) | (cfg->io.pll_loopdiv << 6) | (cfg->io.pll_prediv);
590 dib0090_fw_write_reg(state, 0x21, PllCfg);
264 591
265 /* enable pll, de-activate reset, ratio: 2/1 = 60MHz */ 592 /* Remove Reset Pll */
266 dib0090_write_reg(state, 0x21, 593 PllCfg |= (1 << 13);
267 (cfg->io.pll_bypass << 15) | (1 << 13) | (cfg->io.pll_range << 12) | (cfg->io.pll_loopdiv << 6) | (cfg->io.pll_prediv)); 594 dib0090_fw_write_reg(state, 0x21, PllCfg);
268 595
596 /*** Wait for PLL lock ***/
597 i = 100;
598 do {
599 v = !!(dib0090_fw_read_reg(state, 0x1a) & 0x800);
600 if (v)
601 break;
602 } while (--i);
603
604 if (i == 0) {
605 dprintk("Pll: Unable to lock Pll");
606 return -EIO;
607 }
608
609 /* Finally Remove Bypass mode */
610 PllCfg &= ~(1 << 15);
611 dib0090_fw_write_reg(state, 0x21, PllCfg);
612 }
613
614 if (cfg->io.pll_bypass) {
615 PllCfg |= (cfg->io.pll_bypass << 15);
616 dib0090_fw_write_reg(state, 0x21, PllCfg);
617 }
618
619 return dib0090_fw_identify(fe);
269} 620}
270 621
271static int dib0090_wakeup(struct dvb_frontend *fe) 622static int dib0090_wakeup(struct dvb_frontend *fe)
@@ -273,6 +624,9 @@ static int dib0090_wakeup(struct dvb_frontend *fe)
273 struct dib0090_state *state = fe->tuner_priv; 624 struct dib0090_state *state = fe->tuner_priv;
274 if (state->config->sleep) 625 if (state->config->sleep)
275 state->config->sleep(fe, 0); 626 state->config->sleep(fe, 0);
627
628 /* enable dataTX in case we have been restarted in the wrong moment */
629 dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) | (1 << 14));
276 return 0; 630 return 0;
277} 631}
278 632
@@ -292,8 +646,75 @@ void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast)
292 else 646 else
293 dib0090_write_reg(state, 0x04, 1); 647 dib0090_write_reg(state, 0x04, 1);
294} 648}
649
295EXPORT_SYMBOL(dib0090_dcc_freq); 650EXPORT_SYMBOL(dib0090_dcc_freq);
296 651
652static const u16 bb_ramp_pwm_normal_socs[] = {
653 550, /* max BB gain in 10th of dB */
654 (1 << 9) | 8, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> BB_RAMP2 */
655 440,
656 (4 << 9) | 0, /* BB_RAMP3 = 26dB */
657 (0 << 9) | 208, /* BB_RAMP4 */
658 (4 << 9) | 208, /* BB_RAMP5 = 29dB */
659 (0 << 9) | 440, /* BB_RAMP6 */
660};
661
662static const u16 rf_ramp_pwm_cband_7090[] = {
663 280, /* max RF gain in 10th of dB */
664 18, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
665 504, /* ramp_max = maximum X used on the ramp */
666 (29 << 10) | 364, /* RF_RAMP5, LNA 1 = 8dB */
667 (0 << 10) | 504, /* RF_RAMP6, LNA 1 */
668 (60 << 10) | 228, /* RF_RAMP7, LNA 2 = 7.7dB */
669 (0 << 10) | 364, /* RF_RAMP8, LNA 2 */
670 (34 << 10) | 109, /* GAIN_4_1, LNA 3 = 6.8dB */
671 (0 << 10) | 228, /* GAIN_4_2, LNA 3 */
672 (37 << 10) | 0, /* RF_RAMP3, LNA 4 = 6.2dB */
673 (0 << 10) | 109, /* RF_RAMP4, LNA 4 */
674};
675
676static const u16 rf_ramp_pwm_cband_8090[] = {
677 345, /* max RF gain in 10th of dB */
678 29, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
679 1000, /* ramp_max = maximum X used on the ramp */
680 (35 << 10) | 772, /* RF_RAMP3, LNA 1 = 8dB */
681 (0 << 10) | 1000, /* RF_RAMP4, LNA 1 */
682 (58 << 10) | 496, /* RF_RAMP5, LNA 2 = 9.5dB */
683 (0 << 10) | 772, /* RF_RAMP6, LNA 2 */
684 (27 << 10) | 200, /* RF_RAMP7, LNA 3 = 10.5dB */
685 (0 << 10) | 496, /* RF_RAMP8, LNA 3 */
686 (40 << 10) | 0, /* GAIN_4_1, LNA 4 = 7dB */
687 (0 << 10) | 200, /* GAIN_4_2, LNA 4 */
688};
689
690static const u16 rf_ramp_pwm_uhf_7090[] = {
691 407, /* max RF gain in 10th of dB */
692 13, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
693 529, /* ramp_max = maximum X used on the ramp */
694 (23 << 10) | 0, /* RF_RAMP3, LNA 1 = 14.7dB */
695 (0 << 10) | 176, /* RF_RAMP4, LNA 1 */
696 (63 << 10) | 400, /* RF_RAMP5, LNA 2 = 8dB */
697 (0 << 10) | 529, /* RF_RAMP6, LNA 2 */
698 (48 << 10) | 316, /* RF_RAMP7, LNA 3 = 6.8dB */
699 (0 << 10) | 400, /* RF_RAMP8, LNA 3 */
700 (29 << 10) | 176, /* GAIN_4_1, LNA 4 = 11.5dB */
701 (0 << 10) | 316, /* GAIN_4_2, LNA 4 */
702};
703
704static const u16 rf_ramp_pwm_uhf_8090[] = {
705 388, /* max RF gain in 10th of dB */
706 26, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> RF_RAMP2 */
707 1008, /* ramp_max = maximum X used on the ramp */
708 (11 << 10) | 0, /* RF_RAMP3, LNA 1 = 14.7dB */
709 (0 << 10) | 369, /* RF_RAMP4, LNA 1 */
710 (41 << 10) | 809, /* RF_RAMP5, LNA 2 = 8dB */
711 (0 << 10) | 1008, /* RF_RAMP6, LNA 2 */
712 (27 << 10) | 659, /* RF_RAMP7, LNA 3 = 6dB */
713 (0 << 10) | 809, /* RF_RAMP8, LNA 3 */
714 (14 << 10) | 369, /* GAIN_4_1, LNA 4 = 11.5dB */
715 (0 << 10) | 659, /* GAIN_4_2, LNA 4 */
716};
717
297static const u16 rf_ramp_pwm_cband[] = { 718static const u16 rf_ramp_pwm_cband[] = {
298 0, /* max RF gain in 10th of dB */ 719 0, /* max RF gain in 10th of dB */
299 0, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> 0x2b */ 720 0, /* ramp_slope = 1dB of gain -> clock_ticks_per_db = clk_khz / ramp_slope -> 0x2b */
@@ -326,6 +747,16 @@ static const u16 rf_ramp_uhf[] = {
326 0, 0, 127, /* CBAND : 0.0 dB */ 747 0, 0, 127, /* CBAND : 0.0 dB */
327}; 748};
328 749
750static const u16 rf_ramp_cband_broadmatching[] = /* for p1G only */
751{
752 314, /* Calibrated at 200MHz order has been changed g4-g3-g2-g1 */
753 84, 314, 127, /* LNA1 */
754 80, 230, 255, /* LNA2 */
755 80, 150, 127, /* LNA3 It was measured 12dB, do not lock if 120 */
756 70, 70, 127, /* LNA4 */
757 0, 0, 127, /* CBAND */
758};
759
329static const u16 rf_ramp_cband[] = { 760static const u16 rf_ramp_cband[] = {
330 332, /* max RF gain in 10th of dB */ 761 332, /* max RF gain in 10th of dB */
331 132, 252, 127, /* LNA1, dB */ 762 132, 252, 127, /* LNA1, dB */
@@ -380,8 +811,8 @@ static const u16 bb_ramp_pwm_normal[] = {
380}; 811};
381 812
382struct slope { 813struct slope {
383 int16_t range; 814 s16 range;
384 int16_t slope; 815 s16 slope;
385}; 816};
386static u16 slopes_to_scale(const struct slope *slopes, u8 num, s16 val) 817static u16 slopes_to_scale(const struct slope *slopes, u8 num, s16 val)
387{ 818{
@@ -597,19 +1028,39 @@ void dib0090_pwm_gain_reset(struct dvb_frontend *fe)
597#endif 1028#endif
598#ifdef CONFIG_BAND_CBAND 1029#ifdef CONFIG_BAND_CBAND
599 if (state->current_band == BAND_CBAND) { 1030 if (state->current_band == BAND_CBAND) {
600 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband); 1031 if (state->identity.in_soc) {
601 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal); 1032 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs);
1033 if (state->identity.version == SOC_8090_P1G_11R1 || state->identity.version == SOC_8090_P1G_21R1)
1034 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband_8090);
1035 else if (state->identity.version == SOC_7090_P1G_11R1 || state->identity.version == SOC_7090_P1G_21R1)
1036 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband_7090);
1037 } else {
1038 dib0090_set_rframp_pwm(state, rf_ramp_pwm_cband);
1039 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal);
1040 }
602 } else 1041 } else
603#endif 1042#endif
604#ifdef CONFIG_BAND_VHF 1043#ifdef CONFIG_BAND_VHF
605 if (state->current_band == BAND_VHF) { 1044 if (state->current_band == BAND_VHF) {
606 dib0090_set_rframp_pwm(state, rf_ramp_pwm_vhf); 1045 if (state->identity.in_soc) {
607 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal); 1046 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs);
1047 } else {
1048 dib0090_set_rframp_pwm(state, rf_ramp_pwm_vhf);
1049 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal);
1050 }
608 } else 1051 } else
609#endif 1052#endif
610 { 1053 {
611 dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf); 1054 if (state->identity.in_soc) {
612 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal); 1055 if (state->identity.version == SOC_8090_P1G_11R1 || state->identity.version == SOC_8090_P1G_21R1)
1056 dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf_8090);
1057 else if (state->identity.version == SOC_7090_P1G_11R1 || state->identity.version == SOC_7090_P1G_21R1)
1058 dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf_7090);
1059 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal_socs);
1060 } else {
1061 dib0090_set_rframp_pwm(state, rf_ramp_pwm_uhf);
1062 dib0090_set_bbramp_pwm(state, bb_ramp_pwm_normal);
1063 }
613 } 1064 }
614 1065
615 if (state->rf_ramp[0] != 0) 1066 if (state->rf_ramp[0] != 0)
@@ -617,11 +1068,21 @@ void dib0090_pwm_gain_reset(struct dvb_frontend *fe)
617 else 1068 else
618 dib0090_write_reg(state, 0x32, (0 << 11)); 1069 dib0090_write_reg(state, 0x32, (0 << 11));
619 1070
1071 dib0090_write_reg(state, 0x04, 0x01);
620 dib0090_write_reg(state, 0x39, (1 << 10)); 1072 dib0090_write_reg(state, 0x39, (1 << 10));
621 } 1073 }
622} 1074}
1075
623EXPORT_SYMBOL(dib0090_pwm_gain_reset); 1076EXPORT_SYMBOL(dib0090_pwm_gain_reset);
624 1077
1078static u32 dib0090_get_slow_adc_val(struct dib0090_state *state)
1079{
1080 u16 adc_val = dib0090_read_reg(state, 0x1d);
1081 if (state->identity.in_soc)
1082 adc_val >>= 2;
1083 return adc_val;
1084}
1085
625int dib0090_gain_control(struct dvb_frontend *fe) 1086int dib0090_gain_control(struct dvb_frontend *fe)
626{ 1087{
627 struct dib0090_state *state = fe->tuner_priv; 1088 struct dib0090_state *state = fe->tuner_priv;
@@ -643,18 +1104,21 @@ int dib0090_gain_control(struct dvb_frontend *fe)
643 } else 1104 } else
644#endif 1105#endif
645#ifdef CONFIG_BAND_VHF 1106#ifdef CONFIG_BAND_VHF
646 if (state->current_band == BAND_VHF) { 1107 if (state->current_band == BAND_VHF && !state->identity.p1g) {
647 dib0090_set_rframp(state, rf_ramp_vhf); 1108 dib0090_set_rframp(state, rf_ramp_vhf);
648 dib0090_set_bbramp(state, bb_ramp_boost); 1109 dib0090_set_bbramp(state, bb_ramp_boost);
649 } else 1110 } else
650#endif 1111#endif
651#ifdef CONFIG_BAND_CBAND 1112#ifdef CONFIG_BAND_CBAND
652 if (state->current_band == BAND_CBAND) { 1113 if (state->current_band == BAND_CBAND && !state->identity.p1g) {
653 dib0090_set_rframp(state, rf_ramp_cband); 1114 dib0090_set_rframp(state, rf_ramp_cband);
654 dib0090_set_bbramp(state, bb_ramp_boost); 1115 dib0090_set_bbramp(state, bb_ramp_boost);
655 } else 1116 } else
656#endif 1117#endif
657 { 1118 if ((state->current_band == BAND_CBAND || state->current_band == BAND_VHF) && state->identity.p1g) {
1119 dib0090_set_rframp(state, rf_ramp_cband_broadmatching);
1120 dib0090_set_bbramp(state, bb_ramp_boost);
1121 } else {
658 dib0090_set_rframp(state, rf_ramp_uhf); 1122 dib0090_set_rframp(state, rf_ramp_uhf);
659 dib0090_set_bbramp(state, bb_ramp_boost); 1123 dib0090_set_bbramp(state, bb_ramp_boost);
660 } 1124 }
@@ -669,17 +1133,25 @@ int dib0090_gain_control(struct dvb_frontend *fe)
669 1133
670 *tune_state = CT_AGC_STEP_0; 1134 *tune_state = CT_AGC_STEP_0;
671 } else if (!state->agc_freeze) { 1135 } else if (!state->agc_freeze) {
672 s16 wbd; 1136 s16 wbd = 0, i, cnt;
673 1137
674 int adc; 1138 int adc;
675 wbd_val = dib0090_read_reg(state, 0x1d); 1139 wbd_val = dib0090_get_slow_adc_val(state);
676 1140
677 /* read and calc the wbd power */ 1141 if (*tune_state == CT_AGC_STEP_0)
678 wbd = dib0090_wbd_to_db(state, wbd_val); 1142 cnt = 5;
1143 else
1144 cnt = 1;
1145
1146 for (i = 0; i < cnt; i++) {
1147 wbd_val = dib0090_get_slow_adc_val(state);
1148 wbd += dib0090_wbd_to_db(state, wbd_val);
1149 }
1150 wbd /= cnt;
679 wbd_error = state->wbd_target - wbd; 1151 wbd_error = state->wbd_target - wbd;
680 1152
681 if (*tune_state == CT_AGC_STEP_0) { 1153 if (*tune_state == CT_AGC_STEP_0) {
682 if (wbd_error < 0 && state->rf_gain_limit > 0) { 1154 if (wbd_error < 0 && state->rf_gain_limit > 0 && !state->identity.p1g) {
683#ifdef CONFIG_BAND_CBAND 1155#ifdef CONFIG_BAND_CBAND
684 /* in case of CBAND tune reduce first the lt_gain2 before adjusting the RF gain */ 1156 /* in case of CBAND tune reduce first the lt_gain2 before adjusting the RF gain */
685 u8 ltg2 = (state->rf_lt_def >> 10) & 0x7; 1157 u8 ltg2 = (state->rf_lt_def >> 10) & 0x7;
@@ -700,39 +1172,39 @@ int dib0090_gain_control(struct dvb_frontend *fe)
700 adc_error = (s16) (((s32) ADC_TARGET) - adc); 1172 adc_error = (s16) (((s32) ADC_TARGET) - adc);
701#ifdef CONFIG_STANDARD_DAB 1173#ifdef CONFIG_STANDARD_DAB
702 if (state->fe->dtv_property_cache.delivery_system == STANDARD_DAB) 1174 if (state->fe->dtv_property_cache.delivery_system == STANDARD_DAB)
703 adc_error += 130; 1175 adc_error -= 10;
704#endif 1176#endif
705#ifdef CONFIG_STANDARD_DVBT 1177#ifdef CONFIG_STANDARD_DVBT
706 if (state->fe->dtv_property_cache.delivery_system == STANDARD_DVBT && 1178 if (state->fe->dtv_property_cache.delivery_system == STANDARD_DVBT &&
707 (state->fe->dtv_property_cache.modulation == QAM_64 || state->fe->dtv_property_cache.modulation == QAM_16)) 1179 (state->fe->dtv_property_cache.modulation == QAM_64 || state->fe->dtv_property_cache.modulation == QAM_16))
708 adc_error += 60; 1180 adc_error += 60;
709#endif 1181#endif
710#ifdef CONFIG_SYS_ISDBT 1182#ifdef CONFIG_SYS_ISDBT
711 if ((state->fe->dtv_property_cache.delivery_system == SYS_ISDBT) && (((state->fe->dtv_property_cache.layer[0].segment_count > 1183 if ((state->fe->dtv_property_cache.delivery_system == SYS_ISDBT) && (((state->fe->dtv_property_cache.layer[0].segment_count >
712 0) 1184 0)
713 && 1185 &&
714 ((state->fe->dtv_property_cache.layer[0].modulation == 1186 ((state->fe->dtv_property_cache.layer[0].modulation ==
715 QAM_64) 1187 QAM_64)
716 || (state->fe->dtv_property_cache.layer[0]. 1188 || (state->fe->dtv_property_cache.
717 modulation == QAM_16))) 1189 layer[0].modulation == QAM_16)))
718 || 1190 ||
719 ((state->fe->dtv_property_cache.layer[1].segment_count > 1191 ((state->fe->dtv_property_cache.layer[1].segment_count >
720 0) 1192 0)
721 && 1193 &&
722 ((state->fe->dtv_property_cache.layer[1].modulation == 1194 ((state->fe->dtv_property_cache.layer[1].modulation ==
723 QAM_64) 1195 QAM_64)
724 || (state->fe->dtv_property_cache.layer[1]. 1196 || (state->fe->dtv_property_cache.
725 modulation == QAM_16))) 1197 layer[1].modulation == QAM_16)))
726 || 1198 ||
727 ((state->fe->dtv_property_cache.layer[2].segment_count > 1199 ((state->fe->dtv_property_cache.layer[2].segment_count >
728 0) 1200 0)
729 && 1201 &&
730 ((state->fe->dtv_property_cache.layer[2].modulation == 1202 ((state->fe->dtv_property_cache.layer[2].modulation ==
731 QAM_64) 1203 QAM_64)
732 || (state->fe->dtv_property_cache.layer[2]. 1204 || (state->fe->dtv_property_cache.
733 modulation == QAM_16))) 1205 layer[2].modulation == QAM_16)))
734 ) 1206 )
735 ) 1207 )
736 adc_error += 60; 1208 adc_error += 60;
737#endif 1209#endif
738 1210
@@ -760,9 +1232,9 @@ int dib0090_gain_control(struct dvb_frontend *fe)
760 } 1232 }
761#ifdef DEBUG_AGC 1233#ifdef DEBUG_AGC
762 dprintk 1234 dprintk
763 ("FE: %d, tune state %d, ADC = %3ddB (ADC err %3d) WBD %3ddB (WBD err %3d, WBD val SADC: %4d), RFGainLimit (TOP): %3d, signal: %3ddBm", 1235 ("tune state %d, ADC = %3ddB (ADC err %3d) WBD %3ddB (WBD err %3d, WBD val SADC: %4d), RFGainLimit (TOP): %3d, signal: %3ddBm",
764 (u32) fe->id, (u32) *tune_state, (u32) adc, (u32) adc_error, (u32) wbd, (u32) wbd_error, (u32) wbd_val, 1236 (u32) *tune_state, (u32) adc, (u32) adc_error, (u32) wbd, (u32) wbd_error, (u32) wbd_val,
765 (u32) state->rf_gain_limit >> WBD_ALPHA, (s32) 200 + adc - (state->current_gain >> GAIN_ALPHA)); 1237 (u32) state->rf_gain_limit >> WBD_ALPHA, (s32) 200 + adc - (state->current_gain >> GAIN_ALPHA));
766#endif 1238#endif
767 } 1239 }
768 1240
@@ -771,6 +1243,7 @@ int dib0090_gain_control(struct dvb_frontend *fe)
771 dib0090_gain_apply(state, adc_error, wbd_error, apply_gain_immediatly); 1243 dib0090_gain_apply(state, adc_error, wbd_error, apply_gain_immediatly);
772 return ret; 1244 return ret;
773} 1245}
1246
774EXPORT_SYMBOL(dib0090_gain_control); 1247EXPORT_SYMBOL(dib0090_gain_control);
775 1248
776void dib0090_get_current_gain(struct dvb_frontend *fe, u16 * rf, u16 * bb, u16 * rf_gain_limit, u16 * rflt) 1249void dib0090_get_current_gain(struct dvb_frontend *fe, u16 * rf, u16 * bb, u16 * rf_gain_limit, u16 * rflt)
@@ -785,13 +1258,47 @@ void dib0090_get_current_gain(struct dvb_frontend *fe, u16 * rf, u16 * bb, u16 *
785 if (rflt) 1258 if (rflt)
786 *rflt = (state->rf_lt_def >> 10) & 0x7; 1259 *rflt = (state->rf_lt_def >> 10) & 0x7;
787} 1260}
1261
788EXPORT_SYMBOL(dib0090_get_current_gain); 1262EXPORT_SYMBOL(dib0090_get_current_gain);
789 1263
790u16 dib0090_get_wbd_offset(struct dvb_frontend *tuner) 1264u16 dib0090_get_wbd_offset(struct dvb_frontend *fe)
791{ 1265{
792 struct dib0090_state *st = tuner->tuner_priv; 1266 struct dib0090_state *state = fe->tuner_priv;
793 return st->wbd_offset; 1267 u32 f_MHz = state->fe->dtv_property_cache.frequency / 1000000;
1268 s32 current_temp = state->temperature;
1269 s32 wbd_thot, wbd_tcold;
1270 const struct dib0090_wbd_slope *wbd = state->current_wbd_table;
1271
1272 while (f_MHz > wbd->max_freq)
1273 wbd++;
1274
1275 dprintk("using wbd-table-entry with max freq %d", wbd->max_freq);
1276
1277 if (current_temp < 0)
1278 current_temp = 0;
1279 if (current_temp > 128)
1280 current_temp = 128;
1281
1282 state->wbdmux &= ~(7 << 13);
1283 if (wbd->wbd_gain != 0)
1284 state->wbdmux |= (wbd->wbd_gain << 13);
1285 else
1286 state->wbdmux |= (4 << 13);
1287
1288 dib0090_write_reg(state, 0x10, state->wbdmux);
1289
1290 wbd_thot = wbd->offset_hot - (((u32) wbd->slope_hot * f_MHz) >> 6);
1291 wbd_tcold = wbd->offset_cold - (((u32) wbd->slope_cold * f_MHz) >> 6);
1292
1293 wbd_tcold += ((wbd_thot - wbd_tcold) * current_temp) >> 7;
1294
1295 state->wbd_target = dib0090_wbd_to_db(state, state->wbd_offset + wbd_tcold);
1296 dprintk("wbd-target: %d dB", (u32) state->wbd_target);
1297 dprintk("wbd offset applied is %d", wbd_tcold);
1298
1299 return state->wbd_offset + wbd_tcold;
794} 1300}
1301
795EXPORT_SYMBOL(dib0090_get_wbd_offset); 1302EXPORT_SYMBOL(dib0090_get_wbd_offset);
796 1303
797static const u16 dib0090_defaults[] = { 1304static const u16 dib0090_defaults[] = {
@@ -801,7 +1308,7 @@ static const u16 dib0090_defaults[] = {
801 0x99a0, 1308 0x99a0,
802 0x6008, 1309 0x6008,
803 0x0000, 1310 0x0000,
804 0x8acb, 1311 0x8bcb,
805 0x0000, 1312 0x0000,
806 0x0405, 1313 0x0405,
807 0x0000, 1314 0x0000,
@@ -829,8 +1336,6 @@ static const u16 dib0090_defaults[] = {
829 1, 0x39, 1336 1, 0x39,
830 0x0000, 1337 0x0000,
831 1338
832 1, 0x1b,
833 EN_IQADC | EN_BB | EN_BIAS | EN_DIGCLK | EN_PLL | EN_CRYSTAL,
834 2, 0x1e, 1339 2, 0x1e,
835 0x07FF, 1340 0x07FF,
836 0x0007, 1341 0x0007,
@@ -844,50 +1349,125 @@ static const u16 dib0090_defaults[] = {
844 0 1349 0
845}; 1350};
846 1351
847static int dib0090_reset(struct dvb_frontend *fe) 1352static const u16 dib0090_p1g_additionnal_defaults[] = {
848{ 1353 1, 0x05,
849 struct dib0090_state *state = fe->tuner_priv; 1354 0xabcd,
850 u16 l, r, *n;
851 1355
852 dib0090_reset_digital(fe, state->config); 1356 1, 0x11,
853 state->revision = dib0090_identify(fe); 1357 0x00b4,
854 1358
855 /* Revision definition */ 1359 1, 0x1c,
856 if (state->revision == 0xff) 1360 0xfffd,
857 return -EINVAL;
858#ifdef EFUSE
859 else if ((state->revision & 0x1f) >= 3) /* Update the efuse : Only available for KROSUS > P1C */
860 dib0090_set_EFUSE(state);
861#endif
862 1361
863#ifdef CONFIG_TUNER_DIB0090_P1B_SUPPORT 1362 1, 0x40,
864 if (!(state->revision & 0x1)) /* it is P1B - reset is already done */ 1363 0x108,
865 return 0; 1364 0
866#endif 1365};
1366
1367static void dib0090_set_default_config(struct dib0090_state *state, const u16 * n)
1368{
1369 u16 l, r;
867 1370
868 /* Upload the default values */
869 n = (u16 *) dib0090_defaults;
870 l = pgm_read_word(n++); 1371 l = pgm_read_word(n++);
871 while (l) { 1372 while (l) {
872 r = pgm_read_word(n++); 1373 r = pgm_read_word(n++);
873 do { 1374 do {
874 /* DEBUG_TUNER */
875 /* dprintk("%d, %d, %d", l, r, pgm_read_word(n)); */
876 dib0090_write_reg(state, r, pgm_read_word(n++)); 1375 dib0090_write_reg(state, r, pgm_read_word(n++));
877 r++; 1376 r++;
878 } while (--l); 1377 } while (--l);
879 l = pgm_read_word(n++); 1378 l = pgm_read_word(n++);
880 } 1379 }
1380}
1381
1382#define CAP_VALUE_MIN (u8) 9
1383#define CAP_VALUE_MAX (u8) 40
1384#define HR_MIN (u8) 25
1385#define HR_MAX (u8) 40
1386#define POLY_MIN (u8) 0
1387#define POLY_MAX (u8) 8
1388
1389void dib0090_set_EFUSE(struct dib0090_state *state)
1390{
1391 u8 c, h, n;
1392 u16 e2, e4;
1393 u16 cal;
1394
1395 e2 = dib0090_read_reg(state, 0x26);
1396 e4 = dib0090_read_reg(state, 0x28);
1397
1398 if ((state->identity.version == P1D_E_F) ||
1399 (state->identity.version == P1G) || (e2 == 0xffff)) {
1400
1401 dib0090_write_reg(state, 0x22, 0x10);
1402 cal = (dib0090_read_reg(state, 0x22) >> 6) & 0x3ff;
1403
1404 if ((cal < 670) || (cal == 1023))
1405 cal = 850;
1406 n = 165 - ((cal * 10)>>6) ;
1407 e2 = e4 = (3<<12) | (34<<6) | (n);
1408 }
1409
1410 if (e2 != e4)
1411 e2 &= e4; /* Remove the redundancy */
1412
1413 if (e2 != 0xffff) {
1414 c = e2 & 0x3f;
1415 n = (e2 >> 12) & 0xf;
1416 h = (e2 >> 6) & 0x3f;
1417
1418 if ((c >= CAP_VALUE_MAX) || (c <= CAP_VALUE_MIN))
1419 c = 32;
1420 if ((h >= HR_MAX) || (h <= HR_MIN))
1421 h = 34;
1422 if ((n >= POLY_MAX) || (n <= POLY_MIN))
1423 n = 3;
1424
1425 dib0090_write_reg(state, 0x13, (h << 10)) ;
1426 e2 = (n<<11) | ((h>>2)<<6) | (c);
1427 dib0090_write_reg(state, 0x2, e2) ; /* Load the BB_2 */
1428 }
1429}
1430
1431static int dib0090_reset(struct dvb_frontend *fe)
1432{
1433 struct dib0090_state *state = fe->tuner_priv;
1434
1435 dib0090_reset_digital(fe, state->config);
1436 if (dib0090_identify(fe) < 0)
1437 return -EIO;
1438
1439#ifdef CONFIG_TUNER_DIB0090_P1B_SUPPORT
1440 if (!(state->identity.version & 0x1)) /* it is P1B - reset is already done */
1441 return 0;
1442#endif
1443
1444 if (!state->identity.in_soc) {
1445 if ((dib0090_read_reg(state, 0x1a) >> 5) & 0x2)
1446 dib0090_write_reg(state, 0x1b, (EN_IQADC | EN_BB | EN_BIAS | EN_DIGCLK | EN_PLL | EN_CRYSTAL));
1447 else
1448 dib0090_write_reg(state, 0x1b, (EN_DIGCLK | EN_PLL | EN_CRYSTAL));
1449 }
1450
1451 dib0090_set_default_config(state, dib0090_defaults);
1452
1453 if (state->identity.in_soc)
1454 dib0090_write_reg(state, 0x18, 0x2910); /* charge pump current = 0 */
1455
1456 if (state->identity.p1g)
1457 dib0090_set_default_config(state, dib0090_p1g_additionnal_defaults);
1458
1459 /* Update the efuse : Only available for KROSUS > P1C and SOC as well*/
1460 if (((state->identity.version & 0x1f) >= P1D_E_F) || (state->identity.in_soc))
1461 dib0090_set_EFUSE(state);
881 1462
882 /* Congigure in function of the crystal */ 1463 /* Congigure in function of the crystal */
883 if (state->config->io.clock_khz >= 24000) 1464 if (state->config->io.clock_khz >= 24000)
884 l = 1; 1465 dib0090_write_reg(state, 0x14, 1);
885 else 1466 else
886 l = 2; 1467 dib0090_write_reg(state, 0x14, 2);
887 dib0090_write_reg(state, 0x14, l);
888 dprintk("Pll lock : %d", (dib0090_read_reg(state, 0x1a) >> 11) & 0x1); 1468 dprintk("Pll lock : %d", (dib0090_read_reg(state, 0x1a) >> 11) & 0x1);
889 1469
890 state->reset = 3; /* enable iq-offset-calibration and wbd-calibration when tuning next time */ 1470 state->calibrate = DC_CAL | WBD_CAL | TEMP_CAL; /* enable iq-offset-calibration and wbd-calibration when tuning next time */
891 1471
892 return 0; 1472 return 0;
893} 1473}
@@ -927,11 +1507,11 @@ static int dib0090_get_offset(struct dib0090_state *state, enum frontend_tune_st
927} 1507}
928 1508
929struct dc_calibration { 1509struct dc_calibration {
930 uint8_t addr; 1510 u8 addr;
931 uint8_t offset; 1511 u8 offset;
932 uint8_t pga:1; 1512 u8 pga:1;
933 uint16_t bb1; 1513 u16 bb1;
934 uint8_t i:1; 1514 u8 i:1;
935}; 1515};
936 1516
937static const struct dc_calibration dc_table[] = { 1517static const struct dc_calibration dc_table[] = {
@@ -944,6 +1524,17 @@ static const struct dc_calibration dc_table[] = {
944 {0}, 1524 {0},
945}; 1525};
946 1526
1527static const struct dc_calibration dc_p1g_table[] = {
1528 /* Step1 BB gain1= 26 with boost 1, gain 2 = 0 */
1529 /* addr ; trim reg offset ; pga ; CTRL_BB1 value ; i or q */
1530 {0x06, 5, 1, (1 << 13) | (0 << 8) | (15 << 3), 1},
1531 {0x07, 11, 1, (1 << 13) | (0 << 8) | (15 << 3), 0},
1532 /* Step 2 BB gain 1 = 26 with boost = 1 & gain 2 = 29 */
1533 {0x06, 0, 0, (1 << 13) | (29 << 8) | (15 << 3), 1},
1534 {0x06, 10, 0, (1 << 13) | (29 << 8) | (15 << 3), 0},
1535 {0},
1536};
1537
947static void dib0090_set_trim(struct dib0090_state *state) 1538static void dib0090_set_trim(struct dib0090_state *state)
948{ 1539{
949 u16 *val; 1540 u16 *val;
@@ -962,41 +1553,45 @@ static void dib0090_set_trim(struct dib0090_state *state)
962static int dib0090_dc_offset_calibration(struct dib0090_state *state, enum frontend_tune_state *tune_state) 1553static int dib0090_dc_offset_calibration(struct dib0090_state *state, enum frontend_tune_state *tune_state)
963{ 1554{
964 int ret = 0; 1555 int ret = 0;
1556 u16 reg;
965 1557
966 switch (*tune_state) { 1558 switch (*tune_state) {
967
968 case CT_TUNER_START: 1559 case CT_TUNER_START:
969 /* init */ 1560 dprintk("Start DC offset calibration");
970 dprintk("Internal DC calibration");
971
972 /* the LNA is off */
973 dib0090_write_reg(state, 0x24, 0x02ed);
974 1561
975 /* force vcm2 = 0.8V */ 1562 /* force vcm2 = 0.8V */
976 state->bb6 = 0; 1563 state->bb6 = 0;
977 state->bb7 = 0x040d; 1564 state->bb7 = 0x040d;
978 1565
1566 /* the LNA AND LO are off */
1567 reg = dib0090_read_reg(state, 0x24) & 0x0ffb; /* shutdown lna and lo */
1568 dib0090_write_reg(state, 0x24, reg);
1569
1570 state->wbdmux = dib0090_read_reg(state, 0x10);
1571 dib0090_write_reg(state, 0x10, (state->wbdmux & ~(0xff << 3)) | (0x7 << 3) | 0x3);
1572 dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) & ~(1 << 14));
1573
979 state->dc = dc_table; 1574 state->dc = dc_table;
980 1575
1576 if (state->identity.p1g)
1577 state->dc = dc_p1g_table;
981 *tune_state = CT_TUNER_STEP_0; 1578 *tune_state = CT_TUNER_STEP_0;
982 1579
983 /* fall through */ 1580 /* fall through */
984 1581
985 case CT_TUNER_STEP_0: 1582 case CT_TUNER_STEP_0:
1583 dprintk("Sart/continue DC calibration for %s path", (state->dc->i == 1) ? "I" : "Q");
986 dib0090_write_reg(state, 0x01, state->dc->bb1); 1584 dib0090_write_reg(state, 0x01, state->dc->bb1);
987 dib0090_write_reg(state, 0x07, state->bb7 | (state->dc->i << 7)); 1585 dib0090_write_reg(state, 0x07, state->bb7 | (state->dc->i << 7));
988 1586
989 state->step = 0; 1587 state->step = 0;
990
991 state->min_adc_diff = 1023; 1588 state->min_adc_diff = 1023;
992
993 *tune_state = CT_TUNER_STEP_1; 1589 *tune_state = CT_TUNER_STEP_1;
994 ret = 50; 1590 ret = 50;
995 break; 1591 break;
996 1592
997 case CT_TUNER_STEP_1: 1593 case CT_TUNER_STEP_1:
998 dib0090_set_trim(state); 1594 dib0090_set_trim(state);
999
1000 *tune_state = CT_TUNER_STEP_2; 1595 *tune_state = CT_TUNER_STEP_2;
1001 break; 1596 break;
1002 1597
@@ -1007,7 +1602,13 @@ static int dib0090_dc_offset_calibration(struct dib0090_state *state, enum front
1007 break; 1602 break;
1008 1603
1009 case CT_TUNER_STEP_5: /* found an offset */ 1604 case CT_TUNER_STEP_5: /* found an offset */
1010 dprintk("FE%d: IQC read=%d, current=%x", state->fe->id, (u32) state->adc_diff, state->step); 1605 dprintk("adc_diff = %d, current step= %d", (u32) state->adc_diff, state->step);
1606 if (state->step == 0 && state->adc_diff < 0) {
1607 state->min_adc_diff = -1023;
1608 dprintk("Change of sign of the minimum adc diff");
1609 }
1610
1611 dprintk("adc_diff = %d, min_adc_diff = %d current_step = %d", state->adc_diff, state->min_adc_diff, state->step);
1011 1612
1012 /* first turn for this frequency */ 1613 /* first turn for this frequency */
1013 if (state->step == 0) { 1614 if (state->step == 0) {
@@ -1017,20 +1618,21 @@ static int dib0090_dc_offset_calibration(struct dib0090_state *state, enum front
1017 state->step = 0x10; 1618 state->step = 0x10;
1018 } 1619 }
1019 1620
1020 state->adc_diff = ABS(state->adc_diff); 1621 /* Look for a change of Sign in the Adc_diff.min_adc_diff is used to STORE the setp N-1 */
1021 1622 if ((state->adc_diff & 0x8000) == (state->min_adc_diff & 0x8000) && steps(state->step) < 15) {
1022 if (state->adc_diff < state->min_adc_diff && steps(state->step) < 15) { /* stop search when the delta to 0 is increasing */ 1623 /* stop search when the delta the sign is changing and Steps =15 and Step=0 is force for continuance */
1023 state->step++; 1624 state->step++;
1024 state->min_adc_diff = state->adc_diff; 1625 state->min_adc_diff = state->adc_diff;
1025 *tune_state = CT_TUNER_STEP_1; 1626 *tune_state = CT_TUNER_STEP_1;
1026 } else { 1627 } else {
1027
1028 /* the minimum was what we have seen in the step before */ 1628 /* the minimum was what we have seen in the step before */
1029 state->step--; 1629 if (ABS(state->adc_diff) > ABS(state->min_adc_diff)) {
1030 dib0090_set_trim(state); 1630 dprintk("Since adc_diff N = %d > adc_diff step N-1 = %d, Come back one step", state->adc_diff, state->min_adc_diff);
1631 state->step--;
1632 }
1031 1633
1032 dprintk("FE%d: BB Offset Cal, BBreg=%hd,Offset=%hd,Value Set=%hd", state->fe->id, state->dc->addr, state->adc_diff, 1634 dib0090_set_trim(state);
1033 state->step); 1635 dprintk("BB Offset Cal, BBreg=%hd,Offset=%hd,Value Set=%hd", state->dc->addr, state->adc_diff, state->step);
1034 1636
1035 state->dc++; 1637 state->dc++;
1036 if (state->dc->addr == 0) /* done */ 1638 if (state->dc->addr == 0) /* done */
@@ -1045,7 +1647,7 @@ static int dib0090_dc_offset_calibration(struct dib0090_state *state, enum front
1045 dib0090_write_reg(state, 0x07, state->bb7 & ~0x0008); 1647 dib0090_write_reg(state, 0x07, state->bb7 & ~0x0008);
1046 dib0090_write_reg(state, 0x1f, 0x7); 1648 dib0090_write_reg(state, 0x1f, 0x7);
1047 *tune_state = CT_TUNER_START; /* reset done -> real tuning can now begin */ 1649 *tune_state = CT_TUNER_START; /* reset done -> real tuning can now begin */
1048 state->reset &= ~0x1; 1650 state->calibrate &= ~DC_CAL;
1049 default: 1651 default:
1050 break; 1652 break;
1051 } 1653 }
@@ -1054,21 +1656,43 @@ static int dib0090_dc_offset_calibration(struct dib0090_state *state, enum front
1054 1656
1055static int dib0090_wbd_calibration(struct dib0090_state *state, enum frontend_tune_state *tune_state) 1657static int dib0090_wbd_calibration(struct dib0090_state *state, enum frontend_tune_state *tune_state)
1056{ 1658{
1659 u8 wbd_gain;
1660 const struct dib0090_wbd_slope *wbd = state->current_wbd_table;
1661
1057 switch (*tune_state) { 1662 switch (*tune_state) {
1058 case CT_TUNER_START: 1663 case CT_TUNER_START:
1059 /* WBD-mode=log, Bias=2, Gain=6, Testmode=1, en=1, WBDMUX=1 */ 1664 while (state->current_rf / 1000 > wbd->max_freq)
1060 dib0090_write_reg(state, 0x10, 0xdb09 | (1 << 10)); 1665 wbd++;
1061 dib0090_write_reg(state, 0x24, EN_UHF & 0x0fff); 1666 if (wbd->wbd_gain != 0)
1667 wbd_gain = wbd->wbd_gain;
1668 else {
1669 wbd_gain = 4;
1670#if defined(CONFIG_BAND_LBAND) || defined(CONFIG_BAND_SBAND)
1671 if ((state->current_band == BAND_LBAND) || (state->current_band == BAND_SBAND))
1672 wbd_gain = 2;
1673#endif
1674 }
1675
1676 if (wbd_gain == state->wbd_calibration_gain) { /* the WBD calibration has already been done */
1677 *tune_state = CT_TUNER_START;
1678 state->calibrate &= ~WBD_CAL;
1679 return 0;
1680 }
1681
1682 dib0090_write_reg(state, 0x10, 0x1b81 | (1 << 10) | (wbd_gain << 13) | (1 << 3));
1062 1683
1684 dib0090_write_reg(state, 0x24, ((EN_UHF & 0x0fff) | (1 << 1)));
1063 *tune_state = CT_TUNER_STEP_0; 1685 *tune_state = CT_TUNER_STEP_0;
1686 state->wbd_calibration_gain = wbd_gain;
1064 return 90; /* wait for the WBDMUX to switch and for the ADC to sample */ 1687 return 90; /* wait for the WBDMUX to switch and for the ADC to sample */
1688
1065 case CT_TUNER_STEP_0: 1689 case CT_TUNER_STEP_0:
1066 state->wbd_offset = dib0090_read_reg(state, 0x1d); 1690 state->wbd_offset = dib0090_get_slow_adc_val(state);
1067 dprintk("WBD calibration offset = %d", state->wbd_offset); 1691 dprintk("WBD calibration offset = %d", state->wbd_offset);
1068
1069 *tune_state = CT_TUNER_START; /* reset done -> real tuning can now begin */ 1692 *tune_state = CT_TUNER_START; /* reset done -> real tuning can now begin */
1070 state->reset &= ~0x2; 1693 state->calibrate &= ~WBD_CAL;
1071 break; 1694 break;
1695
1072 default: 1696 default:
1073 break; 1697 break;
1074 } 1698 }
@@ -1092,6 +1716,15 @@ static void dib0090_set_bandwidth(struct dib0090_state *state)
1092 state->bb_1_def |= tmp; 1716 state->bb_1_def |= tmp;
1093 1717
1094 dib0090_write_reg(state, 0x01, state->bb_1_def); /* be sure that we have the right bb-filter */ 1718 dib0090_write_reg(state, 0x01, state->bb_1_def); /* be sure that we have the right bb-filter */
1719
1720 dib0090_write_reg(state, 0x03, 0x6008); /* = 0x6008 : vcm3_trim = 1 ; filter2_gm1_trim = 8 ; filter2_cutoff_freq = 0 */
1721 dib0090_write_reg(state, 0x04, 0x1); /* 0 = 1KHz ; 1 = 50Hz ; 2 = 150Hz ; 3 = 50KHz ; 4 = servo fast */
1722 if (state->identity.in_soc) {
1723 dib0090_write_reg(state, 0x05, 0x9bcf); /* attenuator_ibias_tri = 2 ; input_stage_ibias_tr = 1 ; nc = 11 ; ext_gm_trim = 1 ; obuf_ibias_trim = 4 ; filter13_gm2_ibias_t = 15 */
1724 } else {
1725 dib0090_write_reg(state, 0x02, (5 << 11) | (8 << 6) | (22 & 0x3f)); /* 22 = cap_value */
1726 dib0090_write_reg(state, 0x05, 0xabcd); /* = 0xabcd : attenuator_ibias_tri = 2 ; input_stage_ibias_tr = 2 ; nc = 11 ; ext_gm_trim = 1 ; obuf_ibias_trim = 4 ; filter13_gm2_ibias_t = 13 */
1727 }
1095} 1728}
1096 1729
1097static const struct dib0090_pll dib0090_pll_table[] = { 1730static const struct dib0090_pll dib0090_pll_table[] = {
@@ -1180,6 +1813,255 @@ static const struct dib0090_tuning dib0090_tuning_table[] = {
1180#endif 1813#endif
1181}; 1814};
1182 1815
1816static const struct dib0090_tuning dib0090_p1g_tuning_table[] = {
1817#ifdef CONFIG_BAND_CBAND
1818 {170000, 4, 1, 0x820f, 0x300, 0x2d22, 0x82cb, EN_CAB},
1819#endif
1820#ifdef CONFIG_BAND_VHF
1821 {184000, 1, 1, 15, 0x300, 0x4d12, 0xb94e, EN_VHF},
1822 {227000, 1, 3, 15, 0x300, 0x4d12, 0xb94e, EN_VHF},
1823 {380000, 1, 7, 15, 0x300, 0x4d12, 0xb94e, EN_VHF},
1824#endif
1825#ifdef CONFIG_BAND_UHF
1826 {510000, 2, 0, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1827 {540000, 2, 1, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1828 {600000, 2, 3, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1829 {630000, 2, 4, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1830 {680000, 2, 5, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1831 {720000, 2, 6, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1832 {900000, 2, 7, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1833#endif
1834#ifdef CONFIG_BAND_LBAND
1835 {1500000, 4, 0, 20, 0x300, 0x1912, 0x82c9, EN_LBD},
1836 {1600000, 4, 1, 20, 0x300, 0x1912, 0x82c9, EN_LBD},
1837 {1800000, 4, 3, 20, 0x300, 0x1912, 0x82c9, EN_LBD},
1838#endif
1839#ifdef CONFIG_BAND_SBAND
1840 {2300000, 1, 4, 20, 0x300, 0x2d2A, 0x82c7, EN_SBD},
1841 {2900000, 1, 7, 20, 0x280, 0x2deb, 0x8347, EN_SBD},
1842#endif
1843};
1844
1845static const struct dib0090_pll dib0090_p1g_pll_table[] = {
1846#ifdef CONFIG_BAND_CBAND
1847 {57000, 0, 11, 48, 6},
1848 {70000, 1, 11, 48, 6},
1849 {86000, 0, 10, 32, 4},
1850 {105000, 1, 10, 32, 4},
1851 {115000, 0, 9, 24, 6},
1852 {140000, 1, 9, 24, 6},
1853 {170000, 0, 8, 16, 4},
1854#endif
1855#ifdef CONFIG_BAND_VHF
1856 {200000, 1, 8, 16, 4},
1857 {230000, 0, 7, 12, 6},
1858 {280000, 1, 7, 12, 6},
1859 {340000, 0, 6, 8, 4},
1860 {380000, 1, 6, 8, 4},
1861 {455000, 0, 5, 6, 6},
1862#endif
1863#ifdef CONFIG_BAND_UHF
1864 {580000, 1, 5, 6, 6},
1865 {680000, 0, 4, 4, 4},
1866 {860000, 1, 4, 4, 4},
1867#endif
1868#ifdef CONFIG_BAND_LBAND
1869 {1800000, 1, 2, 2, 4},
1870#endif
1871#ifdef CONFIG_BAND_SBAND
1872 {2900000, 0, 1, 1, 6},
1873#endif
1874};
1875
1876static const struct dib0090_tuning dib0090_p1g_tuning_table_fm_vhf_on_cband[] = {
1877#ifdef CONFIG_BAND_CBAND
1878 {184000, 4, 3, 0x4187, 0x2c0, 0x2d22, 0x81cb, EN_CAB},
1879 {227000, 4, 3, 0x4187, 0x2c0, 0x2d22, 0x81cb, EN_CAB},
1880 {380000, 4, 3, 0x4187, 0x2c0, 0x2d22, 0x81cb, EN_CAB},
1881#endif
1882#ifdef CONFIG_BAND_UHF
1883 {520000, 2, 0, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1884 {550000, 2, 2, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1885 {650000, 2, 3, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1886 {750000, 2, 5, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1887 {850000, 2, 6, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1888 {900000, 2, 7, 15, 0x300, 0x1d12, 0xb9ce, EN_UHF},
1889#endif
1890#ifdef CONFIG_BAND_LBAND
1891 {1500000, 4, 0, 20, 0x300, 0x1912, 0x82c9, EN_LBD},
1892 {1600000, 4, 1, 20, 0x300, 0x1912, 0x82c9, EN_LBD},
1893 {1800000, 4, 3, 20, 0x300, 0x1912, 0x82c9, EN_LBD},
1894#endif
1895#ifdef CONFIG_BAND_SBAND
1896 {2300000, 1, 4, 20, 0x300, 0x2d2A, 0x82c7, EN_SBD},
1897 {2900000, 1, 7, 20, 0x280, 0x2deb, 0x8347, EN_SBD},
1898#endif
1899};
1900
1901static const struct dib0090_tuning dib0090_tuning_table_cband_7090[] = {
1902#ifdef CONFIG_BAND_CBAND
1903 {300000, 4, 3, 0x018F, 0x2c0, 0x2d22, 0xb9ce, EN_CAB},
1904 {380000, 4, 10, 0x018F, 0x2c0, 0x2d22, 0xb9ce, EN_CAB},
1905 {570000, 4, 10, 0x8190, 0x2c0, 0x2d22, 0xb9ce, EN_CAB},
1906 {858000, 4, 5, 0x8190, 0x2c0, 0x2d22, 0xb9ce, EN_CAB},
1907#endif
1908};
1909
1910static int dib0090_captrim_search(struct dib0090_state *state, enum frontend_tune_state *tune_state)
1911{
1912 int ret = 0;
1913 u16 lo4 = 0xe900;
1914
1915 s16 adc_target;
1916 u16 adc;
1917 s8 step_sign;
1918 u8 force_soft_search = 0;
1919
1920 if (state->identity.version == SOC_8090_P1G_11R1 || state->identity.version == SOC_8090_P1G_21R1)
1921 force_soft_search = 1;
1922
1923 if (*tune_state == CT_TUNER_START) {
1924 dprintk("Start Captrim search : %s", (force_soft_search == 1) ? "FORCE SOFT SEARCH" : "AUTO");
1925 dib0090_write_reg(state, 0x10, 0x2B1);
1926 dib0090_write_reg(state, 0x1e, 0x0032);
1927
1928 if (!state->tuner_is_tuned) {
1929 /* prepare a complete captrim */
1930 if (!state->identity.p1g || force_soft_search)
1931 state->step = state->captrim = state->fcaptrim = 64;
1932
1933 state->current_rf = state->rf_request;
1934 } else { /* we are already tuned to this frequency - the configuration is correct */
1935 if (!state->identity.p1g || force_soft_search) {
1936 /* do a minimal captrim even if the frequency has not changed */
1937 state->step = 4;
1938 state->captrim = state->fcaptrim = dib0090_read_reg(state, 0x18) & 0x7f;
1939 }
1940 }
1941 state->adc_diff = 3000;
1942 *tune_state = CT_TUNER_STEP_0;
1943
1944 } else if (*tune_state == CT_TUNER_STEP_0) {
1945 if (state->identity.p1g && !force_soft_search) {
1946 u8 ratio = 31;
1947
1948 dib0090_write_reg(state, 0x40, (3 << 7) | (ratio << 2) | (1 << 1) | 1);
1949 dib0090_read_reg(state, 0x40);
1950 ret = 50;
1951 } else {
1952 state->step /= 2;
1953 dib0090_write_reg(state, 0x18, lo4 | state->captrim);
1954
1955 if (state->identity.in_soc)
1956 ret = 25;
1957 }
1958 *tune_state = CT_TUNER_STEP_1;
1959
1960 } else if (*tune_state == CT_TUNER_STEP_1) {
1961 if (state->identity.p1g && !force_soft_search) {
1962 dib0090_write_reg(state, 0x40, 0x18c | (0 << 1) | 0);
1963 dib0090_read_reg(state, 0x40);
1964
1965 state->fcaptrim = dib0090_read_reg(state, 0x18) & 0x7F;
1966 dprintk("***Final Captrim= 0x%x", state->fcaptrim);
1967 *tune_state = CT_TUNER_STEP_3;
1968
1969 } else {
1970 /* MERGE for all krosus before P1G */
1971 adc = dib0090_get_slow_adc_val(state);
1972 dprintk("CAPTRIM=%d; ADC = %d (ADC) & %dmV", (u32) state->captrim, (u32) adc, (u32) (adc) * (u32) 1800 / (u32) 1024);
1973
1974 if (state->rest == 0 || state->identity.in_soc) { /* Just for 8090P SOCS where auto captrim HW bug : TO CHECK IN ACI for SOCS !!! if 400 for 8090p SOC => tune issue !!! */
1975 adc_target = 200;
1976 } else
1977 adc_target = 400;
1978
1979 if (adc >= adc_target) {
1980 adc -= adc_target;
1981 step_sign = -1;
1982 } else {
1983 adc = adc_target - adc;
1984 step_sign = 1;
1985 }
1986
1987 if (adc < state->adc_diff) {
1988 dprintk("CAPTRIM=%d is closer to target (%d/%d)", (u32) state->captrim, (u32) adc, (u32) state->adc_diff);
1989 state->adc_diff = adc;
1990 state->fcaptrim = state->captrim;
1991 }
1992
1993 state->captrim += step_sign * state->step;
1994 if (state->step >= 1)
1995 *tune_state = CT_TUNER_STEP_0;
1996 else
1997 *tune_state = CT_TUNER_STEP_2;
1998
1999 ret = 25;
2000 }
2001 } else if (*tune_state == CT_TUNER_STEP_2) { /* this step is only used by krosus < P1G */
2002 /*write the final cptrim config */
2003 dib0090_write_reg(state, 0x18, lo4 | state->fcaptrim);
2004
2005 *tune_state = CT_TUNER_STEP_3;
2006
2007 } else if (*tune_state == CT_TUNER_STEP_3) {
2008 state->calibrate &= ~CAPTRIM_CAL;
2009 *tune_state = CT_TUNER_STEP_0;
2010 }
2011
2012 return ret;
2013}
2014
2015static int dib0090_get_temperature(struct dib0090_state *state, enum frontend_tune_state *tune_state)
2016{
2017 int ret = 15;
2018 s16 val;
2019
2020 switch (*tune_state) {
2021 case CT_TUNER_START:
2022 state->wbdmux = dib0090_read_reg(state, 0x10);
2023 dib0090_write_reg(state, 0x10, (state->wbdmux & ~(0xff << 3)) | (0x8 << 3));
2024
2025 state->bias = dib0090_read_reg(state, 0x13);
2026 dib0090_write_reg(state, 0x13, state->bias | (0x3 << 8));
2027
2028 *tune_state = CT_TUNER_STEP_0;
2029 /* wait for the WBDMUX to switch and for the ADC to sample */
2030 break;
2031
2032 case CT_TUNER_STEP_0:
2033 state->adc_diff = dib0090_get_slow_adc_val(state);
2034 dib0090_write_reg(state, 0x13, (state->bias & ~(0x3 << 8)) | (0x2 << 8));
2035 *tune_state = CT_TUNER_STEP_1;
2036 break;
2037
2038 case CT_TUNER_STEP_1:
2039 val = dib0090_get_slow_adc_val(state);
2040 state->temperature = ((s16) ((val - state->adc_diff) * 180) >> 8) + 55;
2041
2042 dprintk("temperature: %d C", state->temperature - 30);
2043
2044 *tune_state = CT_TUNER_STEP_2;
2045 break;
2046
2047 case CT_TUNER_STEP_2:
2048 dib0090_write_reg(state, 0x13, state->bias);
2049 dib0090_write_reg(state, 0x10, state->wbdmux); /* write back original WBDMUX */
2050
2051 *tune_state = CT_TUNER_START;
2052 state->calibrate &= ~TEMP_CAL;
2053 if (state->config->analog_output == 0)
2054 dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) | (1 << 14));
2055
2056 break;
2057
2058 default:
2059 ret = 0;
2060 break;
2061 }
2062 return ret;
2063}
2064
1183#define WBD 0x781 /* 1 1 1 1 0000 0 0 1 */ 2065#define WBD 0x781 /* 1 1 1 1 0000 0 0 1 */
1184static int dib0090_tune(struct dvb_frontend *fe) 2066static int dib0090_tune(struct dvb_frontend *fe)
1185{ 2067{
@@ -1188,87 +2070,131 @@ static int dib0090_tune(struct dvb_frontend *fe)
1188 const struct dib0090_pll *pll = state->current_pll_table_index; 2070 const struct dib0090_pll *pll = state->current_pll_table_index;
1189 enum frontend_tune_state *tune_state = &state->tune_state; 2071 enum frontend_tune_state *tune_state = &state->tune_state;
1190 2072
1191 u32 rf; 2073 u16 lo5, lo6, Den, tmp;
1192 u16 lo4 = 0xe900, lo5, lo6, Den;
1193 u32 FBDiv, Rest, FREF, VCOF_kHz = 0; 2074 u32 FBDiv, Rest, FREF, VCOF_kHz = 0;
1194 u16 tmp, adc;
1195 int8_t step_sign;
1196 int ret = 10; /* 1ms is the default delay most of the time */ 2075 int ret = 10; /* 1ms is the default delay most of the time */
1197 u8 c, i; 2076 u8 c, i;
1198 2077
1199 state->current_band = (u8) BAND_OF_FREQUENCY(fe->dtv_property_cache.frequency / 1000); 2078 /************************* VCO ***************************/
1200 rf = fe->dtv_property_cache.frequency / 1000 + (state->current_band ==
1201 BAND_UHF ? state->config->freq_offset_khz_uhf : state->config->freq_offset_khz_vhf);
1202 /* in any case we first need to do a reset if needed */
1203 if (state->reset & 0x1)
1204 return dib0090_dc_offset_calibration(state, tune_state);
1205 else if (state->reset & 0x2)
1206 return dib0090_wbd_calibration(state, tune_state);
1207
1208 /************************* VCO ***************************/
1209 /* Default values for FG */ 2079 /* Default values for FG */
1210 /* from these are needed : */ 2080 /* from these are needed : */
1211 /* Cp,HFdiv,VCOband,SD,Num,Den,FB and REFDiv */ 2081 /* Cp,HFdiv,VCOband,SD,Num,Den,FB and REFDiv */
1212 2082
1213#ifdef CONFIG_SYS_ISDBT 2083 /* in any case we first need to do a calibration if needed */
1214 if (state->fe->dtv_property_cache.delivery_system == SYS_ISDBT && state->fe->dtv_property_cache.isdbt_sb_mode == 1) 2084 if (*tune_state == CT_TUNER_START) {
1215 rf += 850; 2085 /* deactivate DataTX before some calibrations */
1216#endif 2086 if (state->calibrate & (DC_CAL | TEMP_CAL | WBD_CAL))
2087 dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) & ~(1 << 14));
2088 else
2089 /* Activate DataTX in case a calibration has been done before */
2090 if (state->config->analog_output == 0)
2091 dib0090_write_reg(state, 0x23, dib0090_read_reg(state, 0x23) | (1 << 14));
2092 }
1217 2093
1218 if (state->current_rf != rf) { 2094 if (state->calibrate & DC_CAL)
1219 state->tuner_is_tuned = 0; 2095 return dib0090_dc_offset_calibration(state, tune_state);
2096 else if (state->calibrate & WBD_CAL) {
2097 if (state->current_rf == 0)
2098 state->current_rf = state->fe->dtv_property_cache.frequency / 1000;
2099 return dib0090_wbd_calibration(state, tune_state);
2100 } else if (state->calibrate & TEMP_CAL)
2101 return dib0090_get_temperature(state, tune_state);
2102 else if (state->calibrate & CAPTRIM_CAL)
2103 return dib0090_captrim_search(state, tune_state);
1220 2104
1221 tune = dib0090_tuning_table; 2105 if (*tune_state == CT_TUNER_START) {
2106 /* if soc and AGC pwm control, disengage mux to be able to R/W access to 0x01 register to set the right filter (cutoff_freq_select) during the tune sequence, otherwise, SOC SERPAR error when accessing to 0x01 */
2107 if (state->config->use_pwm_agc && state->identity.in_soc) {
2108 tmp = dib0090_read_reg(state, 0x39);
2109 if ((tmp >> 10) & 0x1)
2110 dib0090_write_reg(state, 0x39, tmp & ~(1 << 10));
2111 }
1222 2112
1223 tmp = (state->revision >> 5) & 0x7; 2113 state->current_band = (u8) BAND_OF_FREQUENCY(state->fe->dtv_property_cache.frequency / 1000);
1224 if (tmp == 0x4 || tmp == 0x7) { 2114 state->rf_request =
1225 /* CBAND tuner version for VHF */ 2115 state->fe->dtv_property_cache.frequency / 1000 + (state->current_band ==
1226 if (state->current_band == BAND_FM || state->current_band == BAND_VHF) { 2116 BAND_UHF ? state->config->freq_offset_khz_uhf : state->config->
1227 /* Force CBAND */ 2117 freq_offset_khz_vhf);
1228 state->current_band = BAND_CBAND; 2118
1229 tune = dib0090_tuning_table_fm_vhf_on_cband; 2119 /* in ISDB-T 1seg we shift tuning frequency */
2120 if ((state->fe->dtv_property_cache.delivery_system == SYS_ISDBT && state->fe->dtv_property_cache.isdbt_sb_mode == 1
2121 && state->fe->dtv_property_cache.isdbt_partial_reception == 0)) {
2122 const struct dib0090_low_if_offset_table *LUT_offset = state->config->low_if;
2123 u8 found_offset = 0;
2124 u32 margin_khz = 100;
2125
2126 if (LUT_offset != NULL) {
2127 while (LUT_offset->RF_freq != 0xffff) {
2128 if (((state->rf_request > (LUT_offset->RF_freq - margin_khz))
2129 && (state->rf_request < (LUT_offset->RF_freq + margin_khz)))
2130 && LUT_offset->std == state->fe->dtv_property_cache.delivery_system) {
2131 state->rf_request += LUT_offset->offset_khz;
2132 found_offset = 1;
2133 break;
2134 }
2135 LUT_offset++;
2136 }
1230 } 2137 }
2138
2139 if (found_offset == 0)
2140 state->rf_request += 400;
1231 } 2141 }
2142 if (state->current_rf != state->rf_request || (state->current_standard != state->fe->dtv_property_cache.delivery_system)) {
2143 state->tuner_is_tuned = 0;
2144 state->current_rf = 0;
2145 state->current_standard = 0;
1232 2146
1233 pll = dib0090_pll_table; 2147 tune = dib0090_tuning_table;
1234 /* Look for the interval */ 2148 if (state->identity.p1g)
1235 while (rf > tune->max_freq) 2149 tune = dib0090_p1g_tuning_table;
1236 tune++;
1237 while (rf > pll->max_freq)
1238 pll++;
1239 state->current_tune_table_index = tune;
1240 state->current_pll_table_index = pll;
1241 }
1242 2150
1243 if (*tune_state == CT_TUNER_START) { 2151 tmp = (state->identity.version >> 5) & 0x7;
1244 2152
1245 if (state->tuner_is_tuned == 0) 2153 if (state->identity.in_soc) {
1246 state->current_rf = 0; 2154 if (state->config->force_cband_input) { /* Use the CBAND input for all band */
2155 if (state->current_band & BAND_CBAND || state->current_band & BAND_FM || state->current_band & BAND_VHF
2156 || state->current_band & BAND_UHF) {
2157 state->current_band = BAND_CBAND;
2158 tune = dib0090_tuning_table_cband_7090;
2159 }
2160 } else { /* Use the CBAND input for all band under UHF */
2161 if (state->current_band & BAND_CBAND || state->current_band & BAND_FM || state->current_band & BAND_VHF) {
2162 state->current_band = BAND_CBAND;
2163 tune = dib0090_tuning_table_cband_7090;
2164 }
2165 }
2166 } else
2167 if (tmp == 0x4 || tmp == 0x7) {
2168 /* CBAND tuner version for VHF */
2169 if (state->current_band == BAND_FM || state->current_band == BAND_CBAND || state->current_band == BAND_VHF) {
2170 state->current_band = BAND_CBAND; /* Force CBAND */
2171
2172 tune = dib0090_tuning_table_fm_vhf_on_cband;
2173 if (state->identity.p1g)
2174 tune = dib0090_p1g_tuning_table_fm_vhf_on_cband;
2175 }
2176 }
1247 2177
1248 if (state->current_rf != rf) { 2178 pll = dib0090_pll_table;
2179 if (state->identity.p1g)
2180 pll = dib0090_p1g_pll_table;
1249 2181
1250 dib0090_write_reg(state, 0x0b, 0xb800 | (tune->switch_trim)); 2182 /* Look for the interval */
2183 while (state->rf_request > tune->max_freq)
2184 tune++;
2185 while (state->rf_request > pll->max_freq)
2186 pll++;
1251 2187
1252 /* external loop filter, otherwise: 2188 state->current_tune_table_index = tune;
1253 * lo5 = (0 << 15) | (0 << 12) | (0 << 11) | (3 << 9) | (4 << 6) | (3 << 4) | 4; 2189 state->current_pll_table_index = pll;
1254 * lo6 = 0x0e34 */
1255 if (pll->vco_band)
1256 lo5 = 0x049e;
1257 else if (state->config->analog_output)
1258 lo5 = 0x041d;
1259 else
1260 lo5 = 0x041c;
1261
1262 lo5 |= (pll->hfdiv_code << 11) | (pll->vco_band << 7); /* bit 15 is the split to the slave, we do not do it here */
1263 2190
1264 if (!state->config->io.pll_int_loop_filt) 2191 dib0090_write_reg(state, 0x0b, 0xb800 | (tune->switch_trim));
1265 lo6 = 0xff28;
1266 else
1267 lo6 = (state->config->io.pll_int_loop_filt << 3);
1268 2192
1269 VCOF_kHz = (pll->hfdiv * rf) * 2; 2193 VCOF_kHz = (pll->hfdiv * state->rf_request) * 2;
1270 2194
1271 FREF = state->config->io.clock_khz; 2195 FREF = state->config->io.clock_khz;
2196 if (state->config->fref_clock_ratio != 0)
2197 FREF /= state->config->fref_clock_ratio;
1272 2198
1273 FBDiv = (VCOF_kHz / pll->topresc / FREF); 2199 FBDiv = (VCOF_kHz / pll->topresc / FREF);
1274 Rest = (VCOF_kHz / pll->topresc) - FBDiv * FREF; 2200 Rest = (VCOF_kHz / pll->topresc) - FBDiv * FREF;
@@ -1283,144 +2209,132 @@ static int dib0090_tune(struct dvb_frontend *fe)
1283 } else if (Rest > (FREF - 2 * LPF)) 2209 } else if (Rest > (FREF - 2 * LPF))
1284 Rest = FREF - 2 * LPF; 2210 Rest = FREF - 2 * LPF;
1285 Rest = (Rest * 6528) / (FREF / 10); 2211 Rest = (Rest * 6528) / (FREF / 10);
2212 state->rest = Rest;
1286 2213
1287 Den = 1; 2214 /* external loop filter, otherwise:
2215 * lo5 = (0 << 15) | (0 << 12) | (0 << 11) | (3 << 9) | (4 << 6) | (3 << 4) | 4;
2216 * lo6 = 0x0e34 */
2217
2218 if (Rest == 0) {
2219 if (pll->vco_band)
2220 lo5 = 0x049f;
2221 else
2222 lo5 = 0x041f;
2223 } else {
2224 if (pll->vco_band)
2225 lo5 = 0x049e;
2226 else if (state->config->analog_output)
2227 lo5 = 0x041d;
2228 else
2229 lo5 = 0x041c;
2230 }
2231
2232 if (state->identity.p1g) { /* Bias is done automatically in P1G */
2233 if (state->identity.in_soc) {
2234 if (state->identity.version == SOC_8090_P1G_11R1)
2235 lo5 = 0x46f;
2236 else
2237 lo5 = 0x42f;
2238 } else
2239 lo5 = 0x42c;
2240 }
2241
2242 lo5 |= (pll->hfdiv_code << 11) | (pll->vco_band << 7); /* bit 15 is the split to the slave, we do not do it here */
1288 2243
1289 dprintk(" ***** ******* Rest value = %d", Rest); 2244 if (!state->config->io.pll_int_loop_filt) {
2245 if (state->identity.in_soc)
2246 lo6 = 0xff98;
2247 else if (state->identity.p1g || (Rest == 0))
2248 lo6 = 0xfff8;
2249 else
2250 lo6 = 0xff28;
2251 } else
2252 lo6 = (state->config->io.pll_int_loop_filt << 3);
2253
2254 Den = 1;
1290 2255
1291 if (Rest > 0) { 2256 if (Rest > 0) {
1292 if (state->config->analog_output) 2257 if (state->config->analog_output)
1293 lo6 |= (1 << 2) | 2; 2258 lo6 |= (1 << 2) | 2;
1294 else 2259 else {
1295 lo6 |= (1 << 2) | 1; 2260 if (state->identity.in_soc)
2261 lo6 |= (1 << 2) | 2;
2262 else
2263 lo6 |= (1 << 2) | 2;
2264 }
1296 Den = 255; 2265 Den = 255;
1297 } 2266 }
1298#ifdef CONFIG_BAND_SBAND
1299 if (state->current_band == BAND_SBAND)
1300 lo6 &= 0xfffb;
1301#endif
1302
1303 dib0090_write_reg(state, 0x15, (u16) FBDiv); 2267 dib0090_write_reg(state, 0x15, (u16) FBDiv);
1304 2268 if (state->config->fref_clock_ratio != 0)
1305 dib0090_write_reg(state, 0x16, (Den << 8) | 1); 2269 dib0090_write_reg(state, 0x16, (Den << 8) | state->config->fref_clock_ratio);
1306 2270 else
2271 dib0090_write_reg(state, 0x16, (Den << 8) | 1);
1307 dib0090_write_reg(state, 0x17, (u16) Rest); 2272 dib0090_write_reg(state, 0x17, (u16) Rest);
1308
1309 dib0090_write_reg(state, 0x19, lo5); 2273 dib0090_write_reg(state, 0x19, lo5);
1310
1311 dib0090_write_reg(state, 0x1c, lo6); 2274 dib0090_write_reg(state, 0x1c, lo6);
1312 2275
1313 lo6 = tune->tuner_enable; 2276 lo6 = tune->tuner_enable;
1314 if (state->config->analog_output) 2277 if (state->config->analog_output)
1315 lo6 = (lo6 & 0xff9f) | 0x2; 2278 lo6 = (lo6 & 0xff9f) | 0x2;
1316 2279
1317 dib0090_write_reg(state, 0x24, lo6 | EN_LO 2280 dib0090_write_reg(state, 0x24, lo6 | EN_LO | state->config->use_pwm_agc * EN_CRYSTAL);
1318#ifdef CONFIG_DIB0090_USE_PWM_AGC
1319 | state->config->use_pwm_agc * EN_CRYSTAL
1320#endif
1321 );
1322
1323 state->current_rf = rf;
1324
1325 /* prepare a complete captrim */
1326 state->step = state->captrim = state->fcaptrim = 64;
1327
1328 } else { /* we are already tuned to this frequency - the configuration is correct */
1329 2281
1330 /* do a minimal captrim even if the frequency has not changed */
1331 state->step = 4;
1332 state->captrim = state->fcaptrim = dib0090_read_reg(state, 0x18) & 0x7f;
1333 } 2282 }
1334 state->adc_diff = 3000;
1335
1336 dib0090_write_reg(state, 0x10, 0x2B1);
1337 2283
1338 dib0090_write_reg(state, 0x1e, 0x0032); 2284 state->current_rf = state->rf_request;
2285 state->current_standard = state->fe->dtv_property_cache.delivery_system;
1339 2286
1340 ret = 20; 2287 ret = 20;
1341 *tune_state = CT_TUNER_STEP_1; 2288 state->calibrate = CAPTRIM_CAL; /* captrim serach now */
1342 } else if (*tune_state == CT_TUNER_STEP_0) { 2289 }
1343 /* nothing */
1344 } else if (*tune_state == CT_TUNER_STEP_1) {
1345 state->step /= 2;
1346 dib0090_write_reg(state, 0x18, lo4 | state->captrim);
1347 *tune_state = CT_TUNER_STEP_2;
1348 } else if (*tune_state == CT_TUNER_STEP_2) {
1349 2290
1350 adc = dib0090_read_reg(state, 0x1d); 2291 else if (*tune_state == CT_TUNER_STEP_0) { /* Warning : because of captrim cal, if you change this step, change it also in _cal.c file because it is the step following captrim cal state machine */
1351 dprintk("FE %d CAPTRIM=%d; ADC = %d (ADC) & %dmV", (u32) fe->id, (u32) state->captrim, (u32) adc, 2292 const struct dib0090_wbd_slope *wbd = state->current_wbd_table;
1352 (u32) (adc) * (u32) 1800 / (u32) 1024);
1353 2293
1354 if (adc >= 400) { 2294 while (state->current_rf / 1000 > wbd->max_freq)
1355 adc -= 400; 2295 wbd++;
1356 step_sign = -1;
1357 } else {
1358 adc = 400 - adc;
1359 step_sign = 1;
1360 }
1361 2296
1362 if (adc < state->adc_diff) { 2297 dib0090_write_reg(state, 0x1e, 0x07ff);
1363 dprintk("FE %d CAPTRIM=%d is closer to target (%d/%d)", (u32) fe->id, (u32) state->captrim, (u32) adc, (u32) state->adc_diff); 2298 dprintk("Final Captrim: %d", (u32) state->fcaptrim);
1364 state->adc_diff = adc; 2299 dprintk("HFDIV code: %d", (u32) pll->hfdiv_code);
1365 state->fcaptrim = state->captrim; 2300 dprintk("VCO = %d", (u32) pll->vco_band);
1366 2301 dprintk("VCOF in kHz: %d ((%d*%d) << 1))", (u32) ((pll->hfdiv * state->rf_request) * 2), (u32) pll->hfdiv, (u32) state->rf_request);
1367 } 2302 dprintk("REFDIV: %d, FREF: %d", (u32) 1, (u32) state->config->io.clock_khz);
2303 dprintk("FBDIV: %d, Rest: %d", (u32) dib0090_read_reg(state, 0x15), (u32) dib0090_read_reg(state, 0x17));
2304 dprintk("Num: %d, Den: %d, SD: %d", (u32) dib0090_read_reg(state, 0x17), (u32) (dib0090_read_reg(state, 0x16) >> 8),
2305 (u32) dib0090_read_reg(state, 0x1c) & 0x3);
1368 2306
1369 state->captrim += step_sign * state->step; 2307#define WBD 0x781 /* 1 1 1 1 0000 0 0 1 */
1370 if (state->step >= 1) 2308 c = 4;
1371 *tune_state = CT_TUNER_STEP_1; 2309 i = 3;
1372 else
1373 *tune_state = CT_TUNER_STEP_3;
1374 2310
1375 ret = 15; 2311 if (wbd->wbd_gain != 0)
1376 } else if (*tune_state == CT_TUNER_STEP_3) { 2312 c = wbd->wbd_gain;
1377 /*write the final cptrim config */
1378 dib0090_write_reg(state, 0x18, lo4 | state->fcaptrim);
1379 2313
1380#ifdef CONFIG_TUNER_DIB0090_CAPTRIM_MEMORY 2314 state->wbdmux = (c << 13) | (i << 11) | (WBD | (state->config->use_pwm_agc << 1));
1381 state->memory[state->memory_index].cap = state->fcaptrim; 2315 dib0090_write_reg(state, 0x10, state->wbdmux);
1382#endif
1383 2316
1384 *tune_state = CT_TUNER_STEP_4; 2317 if ((tune->tuner_enable == EN_CAB) && state->identity.p1g) {
1385 } else if (*tune_state == CT_TUNER_STEP_4) { 2318 dprintk("P1G : The cable band is selected and lna_tune = %d", tune->lna_tune);
1386 dib0090_write_reg(state, 0x1e, 0x07ff); 2319 dib0090_write_reg(state, 0x09, tune->lna_bias);
1387 2320 dib0090_write_reg(state, 0x0b, 0xb800 | (tune->lna_tune << 6) | (tune->switch_trim));
1388 dprintk("FE %d Final Captrim: %d", (u32) fe->id, (u32) state->fcaptrim); 2321 } else
1389 dprintk("FE %d HFDIV code: %d", (u32) fe->id, (u32) pll->hfdiv_code); 2322 dib0090_write_reg(state, 0x09, (tune->lna_tune << 5) | tune->lna_bias);
1390 dprintk("FE %d VCO = %d", (u32) fe->id, (u32) pll->vco_band);
1391 dprintk("FE %d VCOF in kHz: %d ((%d*%d) << 1))", (u32) fe->id, (u32) ((pll->hfdiv * rf) * 2), (u32) pll->hfdiv, (u32) rf);
1392 dprintk("FE %d REFDIV: %d, FREF: %d", (u32) fe->id, (u32) 1, (u32) state->config->io.clock_khz);
1393 dprintk("FE %d FBDIV: %d, Rest: %d", (u32) fe->id, (u32) dib0090_read_reg(state, 0x15), (u32) dib0090_read_reg(state, 0x17));
1394 dprintk("FE %d Num: %d, Den: %d, SD: %d", (u32) fe->id, (u32) dib0090_read_reg(state, 0x17),
1395 (u32) (dib0090_read_reg(state, 0x16) >> 8), (u32) dib0090_read_reg(state, 0x1c) & 0x3);
1396 2323
1397 c = 4;
1398 i = 3;
1399#if defined(CONFIG_BAND_LBAND) || defined(CONFIG_BAND_SBAND)
1400 if ((state->current_band == BAND_LBAND) || (state->current_band == BAND_SBAND)) {
1401 c = 2;
1402 i = 2;
1403 }
1404#endif
1405 dib0090_write_reg(state, 0x10, (c << 13) | (i << 11) | (WBD
1406#ifdef CONFIG_DIB0090_USE_PWM_AGC
1407 | (state->config->use_pwm_agc << 1)
1408#endif
1409 ));
1410 dib0090_write_reg(state, 0x09, (tune->lna_tune << 5) | (tune->lna_bias << 0));
1411 dib0090_write_reg(state, 0x0c, tune->v2i); 2324 dib0090_write_reg(state, 0x0c, tune->v2i);
1412 dib0090_write_reg(state, 0x0d, tune->mix); 2325 dib0090_write_reg(state, 0x0d, tune->mix);
1413 dib0090_write_reg(state, 0x0e, tune->load); 2326 dib0090_write_reg(state, 0x0e, tune->load);
2327 *tune_state = CT_TUNER_STEP_1;
1414 2328
1415 *tune_state = CT_TUNER_STEP_5; 2329 } else if (*tune_state == CT_TUNER_STEP_1) {
1416 } else if (*tune_state == CT_TUNER_STEP_5) {
1417
1418 /* initialize the lt gain register */ 2330 /* initialize the lt gain register */
1419 state->rf_lt_def = 0x7c00; 2331 state->rf_lt_def = 0x7c00;
1420 dib0090_write_reg(state, 0x0f, state->rf_lt_def);
1421 2332
1422 dib0090_set_bandwidth(state); 2333 dib0090_set_bandwidth(state);
1423 state->tuner_is_tuned = 1; 2334 state->tuner_is_tuned = 1;
2335
2336 state->calibrate |= WBD_CAL;
2337 state->calibrate |= TEMP_CAL;
1424 *tune_state = CT_TUNER_STOP; 2338 *tune_state = CT_TUNER_STOP;
1425 } else 2339 } else
1426 ret = FE_CALLBACK_TIME_NEVER; 2340 ret = FE_CALLBACK_TIME_NEVER;
@@ -1440,6 +2354,7 @@ enum frontend_tune_state dib0090_get_tune_state(struct dvb_frontend *fe)
1440 2354
1441 return state->tune_state; 2355 return state->tune_state;
1442} 2356}
2357
1443EXPORT_SYMBOL(dib0090_get_tune_state); 2358EXPORT_SYMBOL(dib0090_get_tune_state);
1444 2359
1445int dib0090_set_tune_state(struct dvb_frontend *fe, enum frontend_tune_state tune_state) 2360int dib0090_set_tune_state(struct dvb_frontend *fe, enum frontend_tune_state tune_state)
@@ -1449,6 +2364,7 @@ int dib0090_set_tune_state(struct dvb_frontend *fe, enum frontend_tune_state tun
1449 state->tune_state = tune_state; 2364 state->tune_state = tune_state;
1450 return 0; 2365 return 0;
1451} 2366}
2367
1452EXPORT_SYMBOL(dib0090_set_tune_state); 2368EXPORT_SYMBOL(dib0090_set_tune_state);
1453 2369
1454static int dib0090_get_frequency(struct dvb_frontend *fe, u32 * frequency) 2370static int dib0090_get_frequency(struct dvb_frontend *fe, u32 * frequency)
@@ -1462,7 +2378,7 @@ static int dib0090_get_frequency(struct dvb_frontend *fe, u32 * frequency)
1462static int dib0090_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *p) 2378static int dib0090_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
1463{ 2379{
1464 struct dib0090_state *state = fe->tuner_priv; 2380 struct dib0090_state *state = fe->tuner_priv;
1465 uint32_t ret; 2381 u32 ret;
1466 2382
1467 state->tune_state = CT_TUNER_START; 2383 state->tune_state = CT_TUNER_START;
1468 2384
@@ -1492,6 +2408,29 @@ static const struct dvb_tuner_ops dib0090_ops = {
1492 .get_frequency = dib0090_get_frequency, 2408 .get_frequency = dib0090_get_frequency,
1493}; 2409};
1494 2410
2411static const struct dvb_tuner_ops dib0090_fw_ops = {
2412 .info = {
2413 .name = "DiBcom DiB0090",
2414 .frequency_min = 45000000,
2415 .frequency_max = 860000000,
2416 .frequency_step = 1000,
2417 },
2418 .release = dib0090_release,
2419
2420 .init = NULL,
2421 .sleep = NULL,
2422 .set_params = NULL,
2423 .get_frequency = NULL,
2424};
2425
2426static const struct dib0090_wbd_slope dib0090_wbd_table_default[] = {
2427 {470, 0, 250, 0, 100, 4},
2428 {860, 51, 866, 21, 375, 4},
2429 {1700, 0, 800, 0, 850, 4},
2430 {2900, 0, 250, 0, 100, 6},
2431 {0xFFFF, 0, 0, 0, 0, 0},
2432};
2433
1495struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config) 2434struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config)
1496{ 2435{
1497 struct dib0090_state *st = kzalloc(sizeof(struct dib0090_state), GFP_KERNEL); 2436 struct dib0090_state *st = kzalloc(sizeof(struct dib0090_state), GFP_KERNEL);
@@ -1503,6 +2442,11 @@ struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapte
1503 st->fe = fe; 2442 st->fe = fe;
1504 fe->tuner_priv = st; 2443 fe->tuner_priv = st;
1505 2444
2445 if (config->wbd == NULL)
2446 st->current_wbd_table = dib0090_wbd_table_default;
2447 else
2448 st->current_wbd_table = config->wbd;
2449
1506 if (dib0090_reset(fe) != 0) 2450 if (dib0090_reset(fe) != 0)
1507 goto free_mem; 2451 goto free_mem;
1508 2452
@@ -1515,8 +2459,34 @@ struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapte
1515 fe->tuner_priv = NULL; 2459 fe->tuner_priv = NULL;
1516 return NULL; 2460 return NULL;
1517} 2461}
2462
1518EXPORT_SYMBOL(dib0090_register); 2463EXPORT_SYMBOL(dib0090_register);
1519 2464
2465struct dvb_frontend *dib0090_fw_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config)
2466{
2467 struct dib0090_fw_state *st = kzalloc(sizeof(struct dib0090_fw_state), GFP_KERNEL);
2468 if (st == NULL)
2469 return NULL;
2470
2471 st->config = config;
2472 st->i2c = i2c;
2473 st->fe = fe;
2474 fe->tuner_priv = st;
2475
2476 if (dib0090_fw_reset_digital(fe, st->config) != 0)
2477 goto free_mem;
2478
2479 dprintk("DiB0090 FW: successfully identified");
2480 memcpy(&fe->ops.tuner_ops, &dib0090_fw_ops, sizeof(struct dvb_tuner_ops));
2481
2482 return fe;
2483free_mem:
2484 kfree(st);
2485 fe->tuner_priv = NULL;
2486 return NULL;
2487}
2488EXPORT_SYMBOL(dib0090_fw_register);
2489
1520MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>"); 2490MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>");
1521MODULE_AUTHOR("Olivier Grenie <olivier.grenie@dibcom.fr>"); 2491MODULE_AUTHOR("Olivier Grenie <olivier.grenie@dibcom.fr>");
1522MODULE_DESCRIPTION("Driver for the DiBcom 0090 base-band RF Tuner"); 2492MODULE_DESCRIPTION("Driver for the DiBcom 0090 base-band RF Tuner");
diff --git a/drivers/media/dvb/frontends/dib0090.h b/drivers/media/dvb/frontends/dib0090.h
index aa7711e88776..13d85244ec16 100644
--- a/drivers/media/dvb/frontends/dib0090.h
+++ b/drivers/media/dvb/frontends/dib0090.h
@@ -27,6 +27,21 @@ struct dib0090_io_config {
27 u16 pll_int_loop_filt; 27 u16 pll_int_loop_filt;
28}; 28};
29 29
30struct dib0090_wbd_slope {
31 u16 max_freq; /* for every frequency less than or equal to that field: this information is correct */
32 u16 slope_cold;
33 u16 offset_cold;
34 u16 slope_hot;
35 u16 offset_hot;
36 u8 wbd_gain;
37};
38
39struct dib0090_low_if_offset_table {
40 int std;
41 u32 RF_freq;
42 s32 offset_khz;
43};
44
30struct dib0090_config { 45struct dib0090_config {
31 struct dib0090_io_config io; 46 struct dib0090_io_config io;
32 int (*reset) (struct dvb_frontend *, int); 47 int (*reset) (struct dvb_frontend *, int);
@@ -47,10 +62,20 @@ struct dib0090_config {
47 u16 wbd_cband_offset; 62 u16 wbd_cband_offset;
48 u8 use_pwm_agc; 63 u8 use_pwm_agc;
49 u8 clkoutdrive; 64 u8 clkoutdrive;
65
66 u8 ls_cfg_pad_drv;
67 u8 data_tx_drv;
68
69 u8 in_soc;
70 const struct dib0090_low_if_offset_table *low_if;
71 u8 fref_clock_ratio;
72 u16 force_cband_input;
73 struct dib0090_wbd_slope *wbd;
50}; 74};
51 75
52#if defined(CONFIG_DVB_TUNER_DIB0090) || (defined(CONFIG_DVB_TUNER_DIB0090_MODULE) && defined(MODULE)) 76#if defined(CONFIG_DVB_TUNER_DIB0090) || (defined(CONFIG_DVB_TUNER_DIB0090_MODULE) && defined(MODULE))
53extern struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config); 77extern struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config);
78extern struct dvb_frontend *dib0090_fw_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config);
54extern void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast); 79extern void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast);
55extern void dib0090_pwm_gain_reset(struct dvb_frontend *fe); 80extern void dib0090_pwm_gain_reset(struct dvb_frontend *fe);
56extern u16 dib0090_get_wbd_offset(struct dvb_frontend *tuner); 81extern u16 dib0090_get_wbd_offset(struct dvb_frontend *tuner);
@@ -65,6 +90,12 @@ static inline struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, str
65 return NULL; 90 return NULL;
66} 91}
67 92
93static inline struct dvb_frontend *dib0090_fw_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dib0090_config *config)
94{
95 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
96 return NULL;
97}
98
68static inline void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast) 99static inline void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast)
69{ 100{
70 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 101 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
diff --git a/drivers/media/dvb/frontends/dib7000m.c b/drivers/media/dvb/frontends/dib7000m.c
index 0f09fd31cb29..79cb1c20df24 100644
--- a/drivers/media/dvb/frontends/dib7000m.c
+++ b/drivers/media/dvb/frontends/dib7000m.c
@@ -50,6 +50,11 @@ struct dib7000m_state {
50 u16 revision; 50 u16 revision;
51 51
52 u8 agc_state; 52 u8 agc_state;
53
54 /* for the I2C transfer */
55 struct i2c_msg msg[2];
56 u8 i2c_write_buffer[4];
57 u8 i2c_read_buffer[2];
53}; 58};
54 59
55enum dib7000m_power_mode { 60enum dib7000m_power_mode {
@@ -64,29 +69,39 @@ enum dib7000m_power_mode {
64 69
65static u16 dib7000m_read_word(struct dib7000m_state *state, u16 reg) 70static u16 dib7000m_read_word(struct dib7000m_state *state, u16 reg)
66{ 71{
67 u8 wb[2] = { (reg >> 8) | 0x80, reg & 0xff }; 72 state->i2c_write_buffer[0] = (reg >> 8) | 0x80;
68 u8 rb[2]; 73 state->i2c_write_buffer[1] = reg & 0xff;
69 struct i2c_msg msg[2] = { 74
70 { .addr = state->i2c_addr >> 1, .flags = 0, .buf = wb, .len = 2 }, 75 memset(state->msg, 0, 2 * sizeof(struct i2c_msg));
71 { .addr = state->i2c_addr >> 1, .flags = I2C_M_RD, .buf = rb, .len = 2 }, 76 state->msg[0].addr = state->i2c_addr >> 1;
72 }; 77 state->msg[0].flags = 0;
73 78 state->msg[0].buf = state->i2c_write_buffer;
74 if (i2c_transfer(state->i2c_adap, msg, 2) != 2) 79 state->msg[0].len = 2;
80 state->msg[1].addr = state->i2c_addr >> 1;
81 state->msg[1].flags = I2C_M_RD;
82 state->msg[1].buf = state->i2c_read_buffer;
83 state->msg[1].len = 2;
84
85 if (i2c_transfer(state->i2c_adap, state->msg, 2) != 2)
75 dprintk("i2c read error on %d",reg); 86 dprintk("i2c read error on %d",reg);
76 87
77 return (rb[0] << 8) | rb[1]; 88 return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
78} 89}
79 90
80static int dib7000m_write_word(struct dib7000m_state *state, u16 reg, u16 val) 91static int dib7000m_write_word(struct dib7000m_state *state, u16 reg, u16 val)
81{ 92{
82 u8 b[4] = { 93 state->i2c_write_buffer[0] = (reg >> 8) & 0xff;
83 (reg >> 8) & 0xff, reg & 0xff, 94 state->i2c_write_buffer[1] = reg & 0xff;
84 (val >> 8) & 0xff, val & 0xff, 95 state->i2c_write_buffer[2] = (val >> 8) & 0xff;
85 }; 96 state->i2c_write_buffer[3] = val & 0xff;
86 struct i2c_msg msg = { 97
87 .addr = state->i2c_addr >> 1, .flags = 0, .buf = b, .len = 4 98 memset(&state->msg[0], 0, sizeof(struct i2c_msg));
88 }; 99 state->msg[0].addr = state->i2c_addr >> 1;
89 return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0; 100 state->msg[0].flags = 0;
101 state->msg[0].buf = state->i2c_write_buffer;
102 state->msg[0].len = 4;
103
104 return i2c_transfer(state->i2c_adap, state->msg, 1) != 1 ? -EREMOTEIO : 0;
90} 105}
91static void dib7000m_write_tab(struct dib7000m_state *state, u16 *buf) 106static void dib7000m_write_tab(struct dib7000m_state *state, u16 *buf)
92{ 107{
@@ -805,7 +820,7 @@ static void dib7000m_set_channel(struct dib7000m_state *state, struct dvb_fronte
805 value = 0; 820 value = 0;
806 switch (ch->u.ofdm.transmission_mode) { 821 switch (ch->u.ofdm.transmission_mode) {
807 case TRANSMISSION_MODE_2K: value |= (0 << 7); break; 822 case TRANSMISSION_MODE_2K: value |= (0 << 7); break;
808 case /* 4K MODE */ 255: value |= (2 << 7); break; 823 case TRANSMISSION_MODE_4K: value |= (2 << 7); break;
809 default: 824 default:
810 case TRANSMISSION_MODE_8K: value |= (1 << 7); break; 825 case TRANSMISSION_MODE_8K: value |= (1 << 7); break;
811 } 826 }
@@ -866,7 +881,7 @@ static void dib7000m_set_channel(struct dib7000m_state *state, struct dvb_fronte
866 /* P_dvsy_sync_wait */ 881 /* P_dvsy_sync_wait */
867 switch (ch->u.ofdm.transmission_mode) { 882 switch (ch->u.ofdm.transmission_mode) {
868 case TRANSMISSION_MODE_8K: value = 256; break; 883 case TRANSMISSION_MODE_8K: value = 256; break;
869 case /* 4K MODE */ 255: value = 128; break; 884 case TRANSMISSION_MODE_4K: value = 128; break;
870 case TRANSMISSION_MODE_2K: 885 case TRANSMISSION_MODE_2K:
871 default: value = 64; break; 886 default: value = 64; break;
872 } 887 }
@@ -1020,7 +1035,7 @@ static int dib7000m_tune(struct dvb_frontend *demod, struct dvb_frontend_paramet
1020 value = (6 << 8) | 0x80; 1035 value = (6 << 8) | 0x80;
1021 switch (ch->u.ofdm.transmission_mode) { 1036 switch (ch->u.ofdm.transmission_mode) {
1022 case TRANSMISSION_MODE_2K: value |= (7 << 12); break; 1037 case TRANSMISSION_MODE_2K: value |= (7 << 12); break;
1023 case /* 4K MODE */ 255: value |= (8 << 12); break; 1038 case TRANSMISSION_MODE_4K: value |= (8 << 12); break;
1024 default: 1039 default:
1025 case TRANSMISSION_MODE_8K: value |= (9 << 12); break; 1040 case TRANSMISSION_MODE_8K: value |= (9 << 12); break;
1026 } 1041 }
@@ -1030,7 +1045,7 @@ static int dib7000m_tune(struct dvb_frontend *demod, struct dvb_frontend_paramet
1030 value = (0 << 4); 1045 value = (0 << 4);
1031 switch (ch->u.ofdm.transmission_mode) { 1046 switch (ch->u.ofdm.transmission_mode) {
1032 case TRANSMISSION_MODE_2K: value |= 0x6; break; 1047 case TRANSMISSION_MODE_2K: value |= 0x6; break;
1033 case /* 4K MODE */ 255: value |= 0x7; break; 1048 case TRANSMISSION_MODE_4K: value |= 0x7; break;
1034 default: 1049 default:
1035 case TRANSMISSION_MODE_8K: value |= 0x8; break; 1050 case TRANSMISSION_MODE_8K: value |= 0x8; break;
1036 } 1051 }
@@ -1040,7 +1055,7 @@ static int dib7000m_tune(struct dvb_frontend *demod, struct dvb_frontend_paramet
1040 value = (0 << 4); 1055 value = (0 << 4);
1041 switch (ch->u.ofdm.transmission_mode) { 1056 switch (ch->u.ofdm.transmission_mode) {
1042 case TRANSMISSION_MODE_2K: value |= 0x6; break; 1057 case TRANSMISSION_MODE_2K: value |= 0x6; break;
1043 case /* 4K MODE */ 255: value |= 0x7; break; 1058 case TRANSMISSION_MODE_4K: value |= 0x7; break;
1044 default: 1059 default:
1045 case TRANSMISSION_MODE_8K: value |= 0x8; break; 1060 case TRANSMISSION_MODE_8K: value |= 0x8; break;
1046 } 1061 }
@@ -1285,6 +1300,25 @@ struct i2c_adapter * dib7000m_get_i2c_master(struct dvb_frontend *demod, enum di
1285} 1300}
1286EXPORT_SYMBOL(dib7000m_get_i2c_master); 1301EXPORT_SYMBOL(dib7000m_get_i2c_master);
1287 1302
1303int dib7000m_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff)
1304{
1305 struct dib7000m_state *state = fe->demodulator_priv;
1306 u16 val = dib7000m_read_word(state, 294 + state->reg_offs) & 0xffef;
1307 val |= (onoff & 0x1) << 4;
1308 dprintk("PID filter enabled %d", onoff);
1309 return dib7000m_write_word(state, 294 + state->reg_offs, val);
1310}
1311EXPORT_SYMBOL(dib7000m_pid_filter_ctrl);
1312
1313int dib7000m_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff)
1314{
1315 struct dib7000m_state *state = fe->demodulator_priv;
1316 dprintk("PID filter: index %x, PID %d, OnOff %d", id, pid, onoff);
1317 return dib7000m_write_word(state, 300 + state->reg_offs + id,
1318 onoff ? (1 << 13) | pid : 0);
1319}
1320EXPORT_SYMBOL(dib7000m_pid_filter);
1321
1288#if 0 1322#if 0
1289/* used with some prototype boards */ 1323/* used with some prototype boards */
1290int dib7000m_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, 1324int dib7000m_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods,
diff --git a/drivers/media/dvb/frontends/dib7000m.h b/drivers/media/dvb/frontends/dib7000m.h
index 113819ce9f0d..81fcf2241c64 100644
--- a/drivers/media/dvb/frontends/dib7000m.h
+++ b/drivers/media/dvb/frontends/dib7000m.h
@@ -46,6 +46,8 @@ extern struct dvb_frontend *dib7000m_attach(struct i2c_adapter *i2c_adap,
46extern struct i2c_adapter *dib7000m_get_i2c_master(struct dvb_frontend *, 46extern struct i2c_adapter *dib7000m_get_i2c_master(struct dvb_frontend *,
47 enum dibx000_i2c_interface, 47 enum dibx000_i2c_interface,
48 int); 48 int);
49extern int dib7000m_pid_filter(struct dvb_frontend *, u8 id, u16 pid, u8 onoff);
50extern int dib7000m_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff);
49#else 51#else
50static inline 52static inline
51struct dvb_frontend *dib7000m_attach(struct i2c_adapter *i2c_adap, 53struct dvb_frontend *dib7000m_attach(struct i2c_adapter *i2c_adap,
@@ -63,6 +65,19 @@ struct i2c_adapter *dib7000m_get_i2c_master(struct dvb_frontend *demod,
63 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 65 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
64 return NULL; 66 return NULL;
65} 67}
68static inline int dib7000m_pid_filter(struct dvb_frontend *fe, u8 id,
69 u16 pid, u8 onoff)
70{
71 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
72 return -ENODEV;
73}
74
75static inline int dib7000m_pid_filter_ctrl(struct dvb_frontend *fe,
76 uint8_t onoff)
77{
78 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
79 return -ENODEV;
80}
66#endif 81#endif
67 82
68/* TODO 83/* TODO
diff --git a/drivers/media/dvb/frontends/dib7000p.c b/drivers/media/dvb/frontends/dib7000p.c
index 3aed0d433921..0c9f40c2a251 100644
--- a/drivers/media/dvb/frontends/dib7000p.c
+++ b/drivers/media/dvb/frontends/dib7000p.c
@@ -26,24 +26,29 @@ MODULE_PARM_DESC(buggy_sfn_workaround, "Enable work-around for buggy SFNs (defau
26 26
27#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB7000P: "); printk(args); printk("\n"); } } while (0) 27#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB7000P: "); printk(args); printk("\n"); } } while (0)
28 28
29struct i2c_device {
30 struct i2c_adapter *i2c_adap;
31 u8 i2c_addr;
32};
33
29struct dib7000p_state { 34struct dib7000p_state {
30 struct dvb_frontend demod; 35 struct dvb_frontend demod;
31 struct dib7000p_config cfg; 36 struct dib7000p_config cfg;
32 37
33 u8 i2c_addr; 38 u8 i2c_addr;
34 struct i2c_adapter *i2c_adap; 39 struct i2c_adapter *i2c_adap;
35 40
36 struct dibx000_i2c_master i2c_master; 41 struct dibx000_i2c_master i2c_master;
37 42
38 u16 wbd_ref; 43 u16 wbd_ref;
39 44
40 u8 current_band; 45 u8 current_band;
41 u32 current_bandwidth; 46 u32 current_bandwidth;
42 struct dibx000_agc_config *current_agc; 47 struct dibx000_agc_config *current_agc;
43 u32 timf; 48 u32 timf;
44 49
45 u8 div_force_off : 1; 50 u8 div_force_off:1;
46 u8 div_state : 1; 51 u8 div_state:1;
47 u16 div_sync_wait; 52 u16 div_sync_wait;
48 53
49 u8 agc_state; 54 u8 agc_state;
@@ -51,7 +56,18 @@ struct dib7000p_state {
51 u16 gpio_dir; 56 u16 gpio_dir;
52 u16 gpio_val; 57 u16 gpio_val;
53 58
54 u8 sfn_workaround_active :1; 59 u8 sfn_workaround_active:1;
60
61#define SOC7090 0x7090
62 u16 version;
63
64 u16 tuner_enable;
65 struct i2c_adapter dib7090_tuner_adap;
66
67 /* for the I2C transfer */
68 struct i2c_msg msg[2];
69 u8 i2c_write_buffer[4];
70 u8 i2c_read_buffer[2];
55}; 71};
56 72
57enum dib7000p_power_mode { 73enum dib7000p_power_mode {
@@ -60,33 +76,47 @@ enum dib7000p_power_mode {
60 DIB7000P_POWER_INTERFACE_ONLY, 76 DIB7000P_POWER_INTERFACE_ONLY,
61}; 77};
62 78
79static int dib7090_set_output_mode(struct dvb_frontend *fe, int mode);
80static int dib7090_set_diversity_in(struct dvb_frontend *fe, int onoff);
81
63static u16 dib7000p_read_word(struct dib7000p_state *state, u16 reg) 82static u16 dib7000p_read_word(struct dib7000p_state *state, u16 reg)
64{ 83{
65 u8 wb[2] = { reg >> 8, reg & 0xff }; 84 state->i2c_write_buffer[0] = reg >> 8;
66 u8 rb[2]; 85 state->i2c_write_buffer[1] = reg & 0xff;
67 struct i2c_msg msg[2] = { 86
68 { .addr = state->i2c_addr >> 1, .flags = 0, .buf = wb, .len = 2 }, 87 memset(state->msg, 0, 2 * sizeof(struct i2c_msg));
69 { .addr = state->i2c_addr >> 1, .flags = I2C_M_RD, .buf = rb, .len = 2 }, 88 state->msg[0].addr = state->i2c_addr >> 1;
70 }; 89 state->msg[0].flags = 0;
71 90 state->msg[0].buf = state->i2c_write_buffer;
72 if (i2c_transfer(state->i2c_adap, msg, 2) != 2) 91 state->msg[0].len = 2;
73 dprintk("i2c read error on %d",reg); 92 state->msg[1].addr = state->i2c_addr >> 1;
74 93 state->msg[1].flags = I2C_M_RD;
75 return (rb[0] << 8) | rb[1]; 94 state->msg[1].buf = state->i2c_read_buffer;
95 state->msg[1].len = 2;
96
97 if (i2c_transfer(state->i2c_adap, state->msg, 2) != 2)
98 dprintk("i2c read error on %d", reg);
99
100 return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
76} 101}
77 102
78static int dib7000p_write_word(struct dib7000p_state *state, u16 reg, u16 val) 103static int dib7000p_write_word(struct dib7000p_state *state, u16 reg, u16 val)
79{ 104{
80 u8 b[4] = { 105 state->i2c_write_buffer[0] = (reg >> 8) & 0xff;
81 (reg >> 8) & 0xff, reg & 0xff, 106 state->i2c_write_buffer[1] = reg & 0xff;
82 (val >> 8) & 0xff, val & 0xff, 107 state->i2c_write_buffer[2] = (val >> 8) & 0xff;
83 }; 108 state->i2c_write_buffer[3] = val & 0xff;
84 struct i2c_msg msg = { 109
85 .addr = state->i2c_addr >> 1, .flags = 0, .buf = b, .len = 4 110 memset(&state->msg[0], 0, sizeof(struct i2c_msg));
86 }; 111 state->msg[0].addr = state->i2c_addr >> 1;
87 return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0; 112 state->msg[0].flags = 0;
113 state->msg[0].buf = state->i2c_write_buffer;
114 state->msg[0].len = 4;
115
116 return i2c_transfer(state->i2c_adap, state->msg, 1) != 1 ? -EREMOTEIO : 0;
88} 117}
89static void dib7000p_write_tab(struct dib7000p_state *state, u16 *buf) 118
119static void dib7000p_write_tab(struct dib7000p_state *state, u16 * buf)
90{ 120{
91 u16 l = 0, r, *n; 121 u16 l = 0, r, *n;
92 n = buf; 122 n = buf;
@@ -104,54 +134,54 @@ static void dib7000p_write_tab(struct dib7000p_state *state, u16 *buf)
104 134
105static int dib7000p_set_output_mode(struct dib7000p_state *state, int mode) 135static int dib7000p_set_output_mode(struct dib7000p_state *state, int mode)
106{ 136{
107 int ret = 0; 137 int ret = 0;
108 u16 outreg, fifo_threshold, smo_mode; 138 u16 outreg, fifo_threshold, smo_mode;
109 139
110 outreg = 0; 140 outreg = 0;
111 fifo_threshold = 1792; 141 fifo_threshold = 1792;
112 smo_mode = (dib7000p_read_word(state, 235) & 0x0050) | (1 << 1); 142 smo_mode = (dib7000p_read_word(state, 235) & 0x0050) | (1 << 1);
113 143
114 dprintk( "setting output mode for demod %p to %d", 144 dprintk("setting output mode for demod %p to %d", &state->demod, mode);
115 &state->demod, mode);
116 145
117 switch (mode) { 146 switch (mode) {
118 case OUTMODE_MPEG2_PAR_GATED_CLK: // STBs with parallel gated clock 147 case OUTMODE_MPEG2_PAR_GATED_CLK:
119 outreg = (1 << 10); /* 0x0400 */ 148 outreg = (1 << 10); /* 0x0400 */
120 break; 149 break;
121 case OUTMODE_MPEG2_PAR_CONT_CLK: // STBs with parallel continues clock 150 case OUTMODE_MPEG2_PAR_CONT_CLK:
122 outreg = (1 << 10) | (1 << 6); /* 0x0440 */ 151 outreg = (1 << 10) | (1 << 6); /* 0x0440 */
123 break; 152 break;
124 case OUTMODE_MPEG2_SERIAL: // STBs with serial input 153 case OUTMODE_MPEG2_SERIAL:
125 outreg = (1 << 10) | (2 << 6) | (0 << 1); /* 0x0480 */ 154 outreg = (1 << 10) | (2 << 6) | (0 << 1); /* 0x0480 */
126 break; 155 break;
127 case OUTMODE_DIVERSITY: 156 case OUTMODE_DIVERSITY:
128 if (state->cfg.hostbus_diversity) 157 if (state->cfg.hostbus_diversity)
129 outreg = (1 << 10) | (4 << 6); /* 0x0500 */ 158 outreg = (1 << 10) | (4 << 6); /* 0x0500 */
130 else 159 else
131 outreg = (1 << 11); 160 outreg = (1 << 11);
132 break; 161 break;
133 case OUTMODE_MPEG2_FIFO: // e.g. USB feeding 162 case OUTMODE_MPEG2_FIFO:
134 smo_mode |= (3 << 1); 163 smo_mode |= (3 << 1);
135 fifo_threshold = 512; 164 fifo_threshold = 512;
136 outreg = (1 << 10) | (5 << 6); 165 outreg = (1 << 10) | (5 << 6);
137 break; 166 break;
138 case OUTMODE_ANALOG_ADC: 167 case OUTMODE_ANALOG_ADC:
139 outreg = (1 << 10) | (3 << 6); 168 outreg = (1 << 10) | (3 << 6);
140 break; 169 break;
141 case OUTMODE_HIGH_Z: // disable 170 case OUTMODE_HIGH_Z:
142 outreg = 0; 171 outreg = 0;
143 break; 172 break;
144 default: 173 default:
145 dprintk( "Unhandled output_mode passed to be set for demod %p",&state->demod); 174 dprintk("Unhandled output_mode passed to be set for demod %p", &state->demod);
146 break; 175 break;
147 } 176 }
148 177
149 if (state->cfg.output_mpeg2_in_188_bytes) 178 if (state->cfg.output_mpeg2_in_188_bytes)
150 smo_mode |= (1 << 5) ; 179 smo_mode |= (1 << 5);
151 180
152 ret |= dib7000p_write_word(state, 235, smo_mode); 181 ret |= dib7000p_write_word(state, 235, smo_mode);
153 ret |= dib7000p_write_word(state, 236, fifo_threshold); /* synchronous fread */ 182 ret |= dib7000p_write_word(state, 236, fifo_threshold); /* synchronous fread */
154 ret |= dib7000p_write_word(state, 1286, outreg); /* P_Div_active */ 183 if (state->version != SOC7090)
184 ret |= dib7000p_write_word(state, 1286, outreg); /* P_Div_active */
155 185
156 return ret; 186 return ret;
157} 187}
@@ -161,13 +191,13 @@ static int dib7000p_set_diversity_in(struct dvb_frontend *demod, int onoff)
161 struct dib7000p_state *state = demod->demodulator_priv; 191 struct dib7000p_state *state = demod->demodulator_priv;
162 192
163 if (state->div_force_off) { 193 if (state->div_force_off) {
164 dprintk( "diversity combination deactivated - forced by COFDM parameters"); 194 dprintk("diversity combination deactivated - forced by COFDM parameters");
165 onoff = 0; 195 onoff = 0;
166 dib7000p_write_word(state, 207, 0); 196 dib7000p_write_word(state, 207, 0);
167 } else 197 } else
168 dib7000p_write_word(state, 207, (state->div_sync_wait << 4) | (1 << 2) | (2 << 0)); 198 dib7000p_write_word(state, 207, (state->div_sync_wait << 4) | (1 << 2) | (2 << 0));
169 199
170 state->div_state = (u8)onoff; 200 state->div_state = (u8) onoff;
171 201
172 if (onoff) { 202 if (onoff) {
173 dib7000p_write_word(state, 204, 6); 203 dib7000p_write_word(state, 204, 6);
@@ -184,37 +214,48 @@ static int dib7000p_set_diversity_in(struct dvb_frontend *demod, int onoff)
184static int dib7000p_set_power_mode(struct dib7000p_state *state, enum dib7000p_power_mode mode) 214static int dib7000p_set_power_mode(struct dib7000p_state *state, enum dib7000p_power_mode mode)
185{ 215{
186 /* by default everything is powered off */ 216 /* by default everything is powered off */
187 u16 reg_774 = 0xffff, reg_775 = 0xffff, reg_776 = 0x0007, reg_899 = 0x0003, 217 u16 reg_774 = 0x3fff, reg_775 = 0xffff, reg_776 = 0x0007, reg_899 = 0x0003, reg_1280 = (0xfe00) | (dib7000p_read_word(state, 1280) & 0x01ff);
188 reg_1280 = (0xfe00) | (dib7000p_read_word(state, 1280) & 0x01ff);
189 218
190 /* now, depending on the requested mode, we power on */ 219 /* now, depending on the requested mode, we power on */
191 switch (mode) { 220 switch (mode) {
192 /* power up everything in the demod */ 221 /* power up everything in the demod */
193 case DIB7000P_POWER_ALL: 222 case DIB7000P_POWER_ALL:
194 reg_774 = 0x0000; reg_775 = 0x0000; reg_776 = 0x0; reg_899 = 0x0; reg_1280 &= 0x01ff; 223 reg_774 = 0x0000;
195 break; 224 reg_775 = 0x0000;
196 225 reg_776 = 0x0;
197 case DIB7000P_POWER_ANALOG_ADC: 226 reg_899 = 0x0;
198 /* dem, cfg, iqc, sad, agc */ 227 if (state->version == SOC7090)
199 reg_774 &= ~((1 << 15) | (1 << 14) | (1 << 11) | (1 << 10) | (1 << 9)); 228 reg_1280 &= 0x001f;
200 /* nud */ 229 else
201 reg_776 &= ~((1 << 0)); 230 reg_1280 &= 0x01ff;
202 /* Dout */ 231 break;
232
233 case DIB7000P_POWER_ANALOG_ADC:
234 /* dem, cfg, iqc, sad, agc */
235 reg_774 &= ~((1 << 15) | (1 << 14) | (1 << 11) | (1 << 10) | (1 << 9));
236 /* nud */
237 reg_776 &= ~((1 << 0));
238 /* Dout */
239 if (state->version != SOC7090)
203 reg_1280 &= ~((1 << 11)); 240 reg_1280 &= ~((1 << 11));
204 /* fall through wanted to enable the interfaces */ 241 reg_1280 &= ~(1 << 6);
242 /* fall through wanted to enable the interfaces */
205 243
206 /* just leave power on the control-interfaces: GPIO and (I2C or SDIO) */ 244 /* just leave power on the control-interfaces: GPIO and (I2C or SDIO) */
207 case DIB7000P_POWER_INTERFACE_ONLY: /* TODO power up either SDIO or I2C */ 245 case DIB7000P_POWER_INTERFACE_ONLY: /* TODO power up either SDIO or I2C */
246 if (state->version == SOC7090)
247 reg_1280 &= ~((1 << 7) | (1 << 5));
248 else
208 reg_1280 &= ~((1 << 14) | (1 << 13) | (1 << 12) | (1 << 10)); 249 reg_1280 &= ~((1 << 14) | (1 << 13) | (1 << 12) | (1 << 10));
209 break; 250 break;
210 251
211/* TODO following stuff is just converted from the dib7000-driver - check when is used what */ 252/* TODO following stuff is just converted from the dib7000-driver - check when is used what */
212 } 253 }
213 254
214 dib7000p_write_word(state, 774, reg_774); 255 dib7000p_write_word(state, 774, reg_774);
215 dib7000p_write_word(state, 775, reg_775); 256 dib7000p_write_word(state, 775, reg_775);
216 dib7000p_write_word(state, 776, reg_776); 257 dib7000p_write_word(state, 776, reg_776);
217 dib7000p_write_word(state, 899, reg_899); 258 dib7000p_write_word(state, 899, reg_899);
218 dib7000p_write_word(state, 1280, reg_1280); 259 dib7000p_write_word(state, 1280, reg_1280);
219 260
220 return 0; 261 return 0;
@@ -222,40 +263,57 @@ static int dib7000p_set_power_mode(struct dib7000p_state *state, enum dib7000p_p
222 263
223static void dib7000p_set_adc_state(struct dib7000p_state *state, enum dibx000_adc_states no) 264static void dib7000p_set_adc_state(struct dib7000p_state *state, enum dibx000_adc_states no)
224{ 265{
225 u16 reg_908 = dib7000p_read_word(state, 908), 266 u16 reg_908 = dib7000p_read_word(state, 908), reg_909 = dib7000p_read_word(state, 909);
226 reg_909 = dib7000p_read_word(state, 909); 267 u16 reg;
227 268
228 switch (no) { 269 switch (no) {
229 case DIBX000_SLOW_ADC_ON: 270 case DIBX000_SLOW_ADC_ON:
271 if (state->version == SOC7090) {
272 reg = dib7000p_read_word(state, 1925);
273
274 dib7000p_write_word(state, 1925, reg | (1 << 4) | (1 << 2)); /* en_slowAdc = 1 & reset_sladc = 1 */
275
276 reg = dib7000p_read_word(state, 1925); /* read acces to make it works... strange ... */
277 msleep(200);
278 dib7000p_write_word(state, 1925, reg & ~(1 << 4)); /* en_slowAdc = 1 & reset_sladc = 0 */
279
280 reg = dib7000p_read_word(state, 72) & ~((0x3 << 14) | (0x3 << 12));
281 dib7000p_write_word(state, 72, reg | (1 << 14) | (3 << 12) | 524); /* ref = Vin1 => Vbg ; sel = Vin0 or Vin3 ; (Vin2 = Vcm) */
282 } else {
230 reg_909 |= (1 << 1) | (1 << 0); 283 reg_909 |= (1 << 1) | (1 << 0);
231 dib7000p_write_word(state, 909, reg_909); 284 dib7000p_write_word(state, 909, reg_909);
232 reg_909 &= ~(1 << 1); 285 reg_909 &= ~(1 << 1);
233 break; 286 }
287 break;
234 288
235 case DIBX000_SLOW_ADC_OFF: 289 case DIBX000_SLOW_ADC_OFF:
236 reg_909 |= (1 << 1) | (1 << 0); 290 if (state->version == SOC7090) {
237 break; 291 reg = dib7000p_read_word(state, 1925);
292 dib7000p_write_word(state, 1925, (reg & ~(1 << 2)) | (1 << 4)); /* reset_sladc = 1 en_slowAdc = 0 */
293 } else
294 reg_909 |= (1 << 1) | (1 << 0);
295 break;
238 296
239 case DIBX000_ADC_ON: 297 case DIBX000_ADC_ON:
240 reg_908 &= 0x0fff; 298 reg_908 &= 0x0fff;
241 reg_909 &= 0x0003; 299 reg_909 &= 0x0003;
242 break; 300 break;
243 301
244 case DIBX000_ADC_OFF: // leave the VBG voltage on 302 case DIBX000_ADC_OFF:
245 reg_908 |= (1 << 14) | (1 << 13) | (1 << 12); 303 reg_908 |= (1 << 14) | (1 << 13) | (1 << 12);
246 reg_909 |= (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2); 304 reg_909 |= (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
247 break; 305 break;
248 306
249 case DIBX000_VBG_ENABLE: 307 case DIBX000_VBG_ENABLE:
250 reg_908 &= ~(1 << 15); 308 reg_908 &= ~(1 << 15);
251 break; 309 break;
252 310
253 case DIBX000_VBG_DISABLE: 311 case DIBX000_VBG_DISABLE:
254 reg_908 |= (1 << 15); 312 reg_908 |= (1 << 15);
255 break; 313 break;
256 314
257 default: 315 default:
258 break; 316 break;
259 } 317 }
260 318
261// dprintk( "908: %x, 909: %x\n", reg_908, reg_909); 319// dprintk( "908: %x, 909: %x\n", reg_908, reg_909);
@@ -275,17 +333,17 @@ static int dib7000p_set_bandwidth(struct dib7000p_state *state, u32 bw)
275 state->current_bandwidth = bw; 333 state->current_bandwidth = bw;
276 334
277 if (state->timf == 0) { 335 if (state->timf == 0) {
278 dprintk( "using default timf"); 336 dprintk("using default timf");
279 timf = state->cfg.bw->timf; 337 timf = state->cfg.bw->timf;
280 } else { 338 } else {
281 dprintk( "using updated timf"); 339 dprintk("using updated timf");
282 timf = state->timf; 340 timf = state->timf;
283 } 341 }
284 342
285 timf = timf * (bw / 50) / 160; 343 timf = timf * (bw / 50) / 160;
286 344
287 dib7000p_write_word(state, 23, (u16) ((timf >> 16) & 0xffff)); 345 dib7000p_write_word(state, 23, (u16) ((timf >> 16) & 0xffff));
288 dib7000p_write_word(state, 24, (u16) ((timf ) & 0xffff)); 346 dib7000p_write_word(state, 24, (u16) ((timf) & 0xffff));
289 347
290 return 0; 348 return 0;
291} 349}
@@ -293,9 +351,12 @@ static int dib7000p_set_bandwidth(struct dib7000p_state *state, u32 bw)
293static int dib7000p_sad_calib(struct dib7000p_state *state) 351static int dib7000p_sad_calib(struct dib7000p_state *state)
294{ 352{
295/* internal */ 353/* internal */
296// dib7000p_write_word(state, 72, (3 << 14) | (1 << 12) | (524 << 0)); // sampling clock of the SAD is writting in set_bandwidth
297 dib7000p_write_word(state, 73, (0 << 1) | (0 << 0)); 354 dib7000p_write_word(state, 73, (0 << 1) | (0 << 0));
298 dib7000p_write_word(state, 74, 776); // 0.625*3.3 / 4096 355
356 if (state->version == SOC7090)
357 dib7000p_write_word(state, 74, 2048);
358 else
359 dib7000p_write_word(state, 74, 776);
299 360
300 /* do the calibration */ 361 /* do the calibration */
301 dib7000p_write_word(state, 73, (1 << 0)); 362 dib7000p_write_word(state, 73, (1 << 0));
@@ -314,37 +375,91 @@ int dib7000p_set_wbd_ref(struct dvb_frontend *demod, u16 value)
314 state->wbd_ref = value; 375 state->wbd_ref = value;
315 return dib7000p_write_word(state, 105, (dib7000p_read_word(state, 105) & 0xf000) | value); 376 return dib7000p_write_word(state, 105, (dib7000p_read_word(state, 105) & 0xf000) | value);
316} 377}
317
318EXPORT_SYMBOL(dib7000p_set_wbd_ref); 378EXPORT_SYMBOL(dib7000p_set_wbd_ref);
379
319static void dib7000p_reset_pll(struct dib7000p_state *state) 380static void dib7000p_reset_pll(struct dib7000p_state *state)
320{ 381{
321 struct dibx000_bandwidth_config *bw = &state->cfg.bw[0]; 382 struct dibx000_bandwidth_config *bw = &state->cfg.bw[0];
322 u16 clk_cfg0; 383 u16 clk_cfg0;
323 384
324 /* force PLL bypass */ 385 if (state->version == SOC7090) {
325 clk_cfg0 = (1 << 15) | ((bw->pll_ratio & 0x3f) << 9) | 386 dib7000p_write_word(state, 1856, (!bw->pll_reset << 13) | (bw->pll_range << 12) | (bw->pll_ratio << 6) | (bw->pll_prediv));
326 (bw->modulo << 7) | (bw->ADClkSrc << 6) | (bw->IO_CLK_en_core << 5) |
327 (bw->bypclk_div << 2) | (bw->enable_refdiv << 1) | (0 << 0);
328 387
329 dib7000p_write_word(state, 900, clk_cfg0); 388 while (((dib7000p_read_word(state, 1856) >> 15) & 0x1) != 1)
389 ;
330 390
331 /* P_pll_cfg */ 391 dib7000p_write_word(state, 1857, dib7000p_read_word(state, 1857) | (!bw->pll_bypass << 15));
332 dib7000p_write_word(state, 903, (bw->pll_prediv << 5) | (((bw->pll_ratio >> 6) & 0x3) << 3) | (bw->pll_range << 1) | bw->pll_reset); 392 } else {
333 clk_cfg0 = (bw->pll_bypass << 15) | (clk_cfg0 & 0x7fff); 393 /* force PLL bypass */
334 dib7000p_write_word(state, 900, clk_cfg0); 394 clk_cfg0 = (1 << 15) | ((bw->pll_ratio & 0x3f) << 9) |
395 (bw->modulo << 7) | (bw->ADClkSrc << 6) | (bw->IO_CLK_en_core << 5) | (bw->bypclk_div << 2) | (bw->enable_refdiv << 1) | (0 << 0);
335 396
336 dib7000p_write_word(state, 18, (u16) (((bw->internal*1000) >> 16) & 0xffff)); 397 dib7000p_write_word(state, 900, clk_cfg0);
337 dib7000p_write_word(state, 19, (u16) ( (bw->internal*1000 ) & 0xffff)); 398
338 dib7000p_write_word(state, 21, (u16) ( (bw->ifreq >> 16) & 0xffff)); 399 /* P_pll_cfg */
339 dib7000p_write_word(state, 22, (u16) ( (bw->ifreq ) & 0xffff)); 400 dib7000p_write_word(state, 903, (bw->pll_prediv << 5) | (((bw->pll_ratio >> 6) & 0x3) << 3) | (bw->pll_range << 1) | bw->pll_reset);
401 clk_cfg0 = (bw->pll_bypass << 15) | (clk_cfg0 & 0x7fff);
402 dib7000p_write_word(state, 900, clk_cfg0);
403 }
404
405 dib7000p_write_word(state, 18, (u16) (((bw->internal * 1000) >> 16) & 0xffff));
406 dib7000p_write_word(state, 19, (u16) ((bw->internal * 1000) & 0xffff));
407 dib7000p_write_word(state, 21, (u16) ((bw->ifreq >> 16) & 0xffff));
408 dib7000p_write_word(state, 22, (u16) ((bw->ifreq) & 0xffff));
340 409
341 dib7000p_write_word(state, 72, bw->sad_cfg); 410 dib7000p_write_word(state, 72, bw->sad_cfg);
342} 411}
343 412
413static u32 dib7000p_get_internal_freq(struct dib7000p_state *state)
414{
415 u32 internal = (u32) dib7000p_read_word(state, 18) << 16;
416 internal |= (u32) dib7000p_read_word(state, 19);
417 internal /= 1000;
418
419 return internal;
420}
421
422int dib7000p_update_pll(struct dvb_frontend *fe, struct dibx000_bandwidth_config *bw)
423{
424 struct dib7000p_state *state = fe->demodulator_priv;
425 u16 reg_1857, reg_1856 = dib7000p_read_word(state, 1856);
426 u8 loopdiv, prediv;
427 u32 internal, xtal;
428
429 /* get back old values */
430 prediv = reg_1856 & 0x3f;
431 loopdiv = (reg_1856 >> 6) & 0x3f;
432
433 if ((bw != NULL) && (bw->pll_prediv != prediv || bw->pll_ratio != loopdiv)) {
434 dprintk("Updating pll (prediv: old = %d new = %d ; loopdiv : old = %d new = %d)", prediv, bw->pll_prediv, loopdiv, bw->pll_ratio);
435 reg_1856 &= 0xf000;
436 reg_1857 = dib7000p_read_word(state, 1857);
437 dib7000p_write_word(state, 1857, reg_1857 & ~(1 << 15));
438
439 dib7000p_write_word(state, 1856, reg_1856 | ((bw->pll_ratio & 0x3f) << 6) | (bw->pll_prediv & 0x3f));
440
441 /* write new system clk into P_sec_len */
442 internal = dib7000p_get_internal_freq(state);
443 xtal = (internal / loopdiv) * prediv;
444 internal = 1000 * (xtal / bw->pll_prediv) * bw->pll_ratio; /* new internal */
445 dib7000p_write_word(state, 18, (u16) ((internal >> 16) & 0xffff));
446 dib7000p_write_word(state, 19, (u16) (internal & 0xffff));
447
448 dib7000p_write_word(state, 1857, reg_1857 | (1 << 15));
449
450 while (((dib7000p_read_word(state, 1856) >> 15) & 0x1) != 1)
451 dprintk("Waiting for PLL to lock");
452
453 return 0;
454 }
455 return -EIO;
456}
457EXPORT_SYMBOL(dib7000p_update_pll);
458
344static int dib7000p_reset_gpio(struct dib7000p_state *st) 459static int dib7000p_reset_gpio(struct dib7000p_state *st)
345{ 460{
346 /* reset the GPIOs */ 461 /* reset the GPIOs */
347 dprintk( "gpio dir: %x: val: %x, pwm_pos: %x",st->gpio_dir, st->gpio_val,st->cfg.gpio_pwm_pos); 462 dprintk("gpio dir: %x: val: %x, pwm_pos: %x", st->gpio_dir, st->gpio_val, st->cfg.gpio_pwm_pos);
348 463
349 dib7000p_write_word(st, 1029, st->gpio_dir); 464 dib7000p_write_word(st, 1029, st->gpio_dir);
350 dib7000p_write_word(st, 1030, st->gpio_val); 465 dib7000p_write_word(st, 1030, st->gpio_val);
@@ -360,13 +475,13 @@ static int dib7000p_reset_gpio(struct dib7000p_state *st)
360static int dib7000p_cfg_gpio(struct dib7000p_state *st, u8 num, u8 dir, u8 val) 475static int dib7000p_cfg_gpio(struct dib7000p_state *st, u8 num, u8 dir, u8 val)
361{ 476{
362 st->gpio_dir = dib7000p_read_word(st, 1029); 477 st->gpio_dir = dib7000p_read_word(st, 1029);
363 st->gpio_dir &= ~(1 << num); /* reset the direction bit */ 478 st->gpio_dir &= ~(1 << num); /* reset the direction bit */
364 st->gpio_dir |= (dir & 0x1) << num; /* set the new direction */ 479 st->gpio_dir |= (dir & 0x1) << num; /* set the new direction */
365 dib7000p_write_word(st, 1029, st->gpio_dir); 480 dib7000p_write_word(st, 1029, st->gpio_dir);
366 481
367 st->gpio_val = dib7000p_read_word(st, 1030); 482 st->gpio_val = dib7000p_read_word(st, 1030);
368 st->gpio_val &= ~(1 << num); /* reset the direction bit */ 483 st->gpio_val &= ~(1 << num); /* reset the direction bit */
369 st->gpio_val |= (val & 0x01) << num; /* set the new value */ 484 st->gpio_val |= (val & 0x01) << num; /* set the new value */
370 dib7000p_write_word(st, 1030, st->gpio_val); 485 dib7000p_write_word(st, 1030, st->gpio_val);
371 486
372 return 0; 487 return 0;
@@ -377,96 +492,94 @@ int dib7000p_set_gpio(struct dvb_frontend *demod, u8 num, u8 dir, u8 val)
377 struct dib7000p_state *state = demod->demodulator_priv; 492 struct dib7000p_state *state = demod->demodulator_priv;
378 return dib7000p_cfg_gpio(state, num, dir, val); 493 return dib7000p_cfg_gpio(state, num, dir, val);
379} 494}
380
381EXPORT_SYMBOL(dib7000p_set_gpio); 495EXPORT_SYMBOL(dib7000p_set_gpio);
382static u16 dib7000p_defaults[] =
383 496
384{ 497static u16 dib7000p_defaults[] = {
385 // auto search configuration 498 // auto search configuration
386 3, 2, 499 3, 2,
387 0x0004, 500 0x0004,
388 0x1000, 501 0x1000,
389 0x0814, /* Equal Lock */ 502 0x0814, /* Equal Lock */
390 503
391 12, 6, 504 12, 6,
392 0x001b, 505 0x001b,
393 0x7740, 506 0x7740,
394 0x005b, 507 0x005b,
395 0x8d80, 508 0x8d80,
396 0x01c9, 509 0x01c9,
397 0xc380, 510 0xc380,
398 0x0000, 511 0x0000,
399 0x0080, 512 0x0080,
400 0x0000, 513 0x0000,
401 0x0090, 514 0x0090,
402 0x0001, 515 0x0001,
403 0xd4c0, 516 0xd4c0,
404 517
405 1, 26, 518 1, 26,
406 0x6680, // P_timf_alpha=6, P_corm_alpha=6, P_corm_thres=128 default: 6,4,26 519 0x6680,
407 520
408 /* set ADC level to -16 */ 521 /* set ADC level to -16 */
409 11, 79, 522 11, 79,
410 (1 << 13) - 825 - 117, 523 (1 << 13) - 825 - 117,
411 (1 << 13) - 837 - 117, 524 (1 << 13) - 837 - 117,
412 (1 << 13) - 811 - 117, 525 (1 << 13) - 811 - 117,
413 (1 << 13) - 766 - 117, 526 (1 << 13) - 766 - 117,
414 (1 << 13) - 737 - 117, 527 (1 << 13) - 737 - 117,
415 (1 << 13) - 693 - 117, 528 (1 << 13) - 693 - 117,
416 (1 << 13) - 648 - 117, 529 (1 << 13) - 648 - 117,
417 (1 << 13) - 619 - 117, 530 (1 << 13) - 619 - 117,
418 (1 << 13) - 575 - 117, 531 (1 << 13) - 575 - 117,
419 (1 << 13) - 531 - 117, 532 (1 << 13) - 531 - 117,
420 (1 << 13) - 501 - 117, 533 (1 << 13) - 501 - 117,
421 534
422 1, 142, 535 1, 142,
423 0x0410, // P_palf_filter_on=1, P_palf_filter_freeze=0, P_palf_alpha_regul=16 536 0x0410,
424 537
425 /* disable power smoothing */ 538 /* disable power smoothing */
426 8, 145, 539 8, 145,
427 0, 540 0,
428 0, 541 0,
429 0, 542 0,
430 0, 543 0,
431 0, 544 0,
432 0, 545 0,
433 0, 546 0,
434 0, 547 0,
435 548
436 1, 154, 549 1, 154,
437 1 << 13, // P_fft_freq_dir=1, P_fft_nb_to_cut=0 550 1 << 13,
438 551
439 1, 168, 552 1, 168,
440 0x0ccd, // P_pha3_thres, default 0x3000 553 0x0ccd,
441
442// 1, 169,
443// 0x0010, // P_cti_use_cpe=0, P_cti_use_prog=0, P_cti_win_len=16, default: 0x0010
444 554
445 1, 183, 555 1, 183,
446 0x200f, // P_cspu_regul=512, P_cspu_win_cut=15, default: 0x2005 556 0x200f,
557
558 1, 212,
559 0x169,
447 560
448 5, 187, 561 5, 187,
449 0x023d, // P_adp_regul_cnt=573, default: 410 562 0x023d,
450 0x00a4, // P_adp_noise_cnt= 563 0x00a4,
451 0x00a4, // P_adp_regul_ext 564 0x00a4,
452 0x7ff0, // P_adp_noise_ext 565 0x7ff0,
453 0x3ccc, // P_adp_fil 566 0x3ccc,
454 567
455 1, 198, 568 1, 198,
456 0x800, // P_equal_thres_wgn 569 0x800,
457 570
458 1, 222, 571 1, 222,
459 0x0010, // P_fec_ber_rs_len=2 572 0x0010,
460 573
461 1, 235, 574 1, 235,
462 0x0062, // P_smo_mode, P_smo_rs_discard, P_smo_fifo_flush, P_smo_pid_parse, P_smo_error_discard 575 0x0062,
463 576
464 2, 901, 577 2, 901,
465 0x0006, // P_clk_cfg1 578 0x0006,
466 (3 << 10) | (1 << 6), // P_divclksel=3 P_divbitsel=1 579 (3 << 10) | (1 << 6),
467 580
468 1, 905, 581 1, 905,
469 0x2c8e, // Tuner IO bank: max drive (14mA) + divout pads max drive 582 0x2c8e,
470 583
471 0, 584 0,
472}; 585};
@@ -475,51 +588,64 @@ static int dib7000p_demod_reset(struct dib7000p_state *state)
475{ 588{
476 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL); 589 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
477 590
591 if (state->version == SOC7090)
592 dibx000_reset_i2c_master(&state->i2c_master);
593
478 dib7000p_set_adc_state(state, DIBX000_VBG_ENABLE); 594 dib7000p_set_adc_state(state, DIBX000_VBG_ENABLE);
479 595
480 /* restart all parts */ 596 /* restart all parts */
481 dib7000p_write_word(state, 770, 0xffff); 597 dib7000p_write_word(state, 770, 0xffff);
482 dib7000p_write_word(state, 771, 0xffff); 598 dib7000p_write_word(state, 771, 0xffff);
483 dib7000p_write_word(state, 772, 0x001f); 599 dib7000p_write_word(state, 772, 0x001f);
484 dib7000p_write_word(state, 898, 0x0003); 600 dib7000p_write_word(state, 898, 0x0003);
485 /* except i2c, sdio, gpio - control interfaces */ 601 dib7000p_write_word(state, 1280, 0x001f - ((1 << 4) | (1 << 3)));
486 dib7000p_write_word(state, 1280, 0x01fc - ((1 << 7) | (1 << 6) | (1 << 5)) ); 602
487 603 dib7000p_write_word(state, 770, 0);
488 dib7000p_write_word(state, 770, 0); 604 dib7000p_write_word(state, 771, 0);
489 dib7000p_write_word(state, 771, 0); 605 dib7000p_write_word(state, 772, 0);
490 dib7000p_write_word(state, 772, 0); 606 dib7000p_write_word(state, 898, 0);
491 dib7000p_write_word(state, 898, 0);
492 dib7000p_write_word(state, 1280, 0); 607 dib7000p_write_word(state, 1280, 0);
493 608
494 /* default */ 609 /* default */
495 dib7000p_reset_pll(state); 610 dib7000p_reset_pll(state);
496 611
497 if (dib7000p_reset_gpio(state) != 0) 612 if (dib7000p_reset_gpio(state) != 0)
498 dprintk( "GPIO reset was not successful."); 613 dprintk("GPIO reset was not successful.");
499 614
500 if (dib7000p_set_output_mode(state, OUTMODE_HIGH_Z) != 0) 615 if (state->version == SOC7090) {
501 dprintk( "OUTPUT_MODE could not be reset."); 616 dib7000p_write_word(state, 899, 0);
502 617
503 /* unforce divstr regardless whether i2c enumeration was done or not */ 618 /* impulse noise */
504 dib7000p_write_word(state, 1285, dib7000p_read_word(state, 1285) & ~(1 << 1) ); 619 dib7000p_write_word(state, 42, (1<<5) | 3); /* P_iqc_thsat_ipc = 1 ; P_iqc_win2 = 3 */
505 620 dib7000p_write_word(state, 43, 0x2d4); /*-300 fag P_iqc_dect_min = -280 */
506 dib7000p_set_bandwidth(state, 8000); 621 dib7000p_write_word(state, 44, 300); /* 300 fag P_iqc_dect_min = +280 */
622 dib7000p_write_word(state, 273, (1<<6) | 30);
623 }
624 if (dib7000p_set_output_mode(state, OUTMODE_HIGH_Z) != 0)
625 dprintk("OUTPUT_MODE could not be reset.");
507 626
508 dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_ON); 627 dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_ON);
509 dib7000p_sad_calib(state); 628 dib7000p_sad_calib(state);
510 dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_OFF); 629 dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_OFF);
511 630
512 // P_iqc_alpha_pha, P_iqc_alpha_amp_dcc_alpha, ... 631 /* unforce divstr regardless whether i2c enumeration was done or not */
513 if(state->cfg.tuner_is_baseband) 632 dib7000p_write_word(state, 1285, dib7000p_read_word(state, 1285) & ~(1 << 1));
514 dib7000p_write_word(state, 36,0x0755); 633
515 else 634 dib7000p_set_bandwidth(state, 8000);
516 dib7000p_write_word(state, 36,0x1f55); 635
636 if (state->version == SOC7090) {
637 dib7000p_write_word(state, 36, 0x5755);/* P_iqc_impnc_on =1 & P_iqc_corr_inh = 1 for impulsive noise */
638 } else {
639 if (state->cfg.tuner_is_baseband)
640 dib7000p_write_word(state, 36, 0x0755);
641 else
642 dib7000p_write_word(state, 36, 0x1f55);
643 }
517 644
518 dib7000p_write_tab(state, dib7000p_defaults); 645 dib7000p_write_tab(state, dib7000p_defaults);
519 646
520 dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY); 647 dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY);
521 648
522
523 return 0; 649 return 0;
524} 650}
525 651
@@ -527,9 +653,9 @@ static void dib7000p_pll_clk_cfg(struct dib7000p_state *state)
527{ 653{
528 u16 tmp = 0; 654 u16 tmp = 0;
529 tmp = dib7000p_read_word(state, 903); 655 tmp = dib7000p_read_word(state, 903);
530 dib7000p_write_word(state, 903, (tmp | 0x1)); //pwr-up pll 656 dib7000p_write_word(state, 903, (tmp | 0x1));
531 tmp = dib7000p_read_word(state, 900); 657 tmp = dib7000p_read_word(state, 900);
532 dib7000p_write_word(state, 900, (tmp & 0x7fff) | (1 << 6)); //use High freq clock 658 dib7000p_write_word(state, 900, (tmp & 0x7fff) | (1 << 6));
533} 659}
534 660
535static void dib7000p_restart_agc(struct dib7000p_state *state) 661static void dib7000p_restart_agc(struct dib7000p_state *state)
@@ -543,11 +669,9 @@ static int dib7000p_update_lna(struct dib7000p_state *state)
543{ 669{
544 u16 dyn_gain; 670 u16 dyn_gain;
545 671
546 // when there is no LNA to program return immediatly
547 if (state->cfg.update_lna) { 672 if (state->cfg.update_lna) {
548 // read dyn_gain here (because it is demod-dependent and not fe)
549 dyn_gain = dib7000p_read_word(state, 394); 673 dyn_gain = dib7000p_read_word(state, 394);
550 if (state->cfg.update_lna(&state->demod,dyn_gain)) { // LNA has changed 674 if (state->cfg.update_lna(&state->demod, dyn_gain)) {
551 dib7000p_restart_agc(state); 675 dib7000p_restart_agc(state);
552 return 1; 676 return 1;
553 } 677 }
@@ -571,24 +695,24 @@ static int dib7000p_set_agc_config(struct dib7000p_state *state, u8 band)
571 } 695 }
572 696
573 if (agc == NULL) { 697 if (agc == NULL) {
574 dprintk( "no valid AGC configuration found for band 0x%02x",band); 698 dprintk("no valid AGC configuration found for band 0x%02x", band);
575 return -EINVAL; 699 return -EINVAL;
576 } 700 }
577 701
578 state->current_agc = agc; 702 state->current_agc = agc;
579 703
580 /* AGC */ 704 /* AGC */
581 dib7000p_write_word(state, 75 , agc->setup ); 705 dib7000p_write_word(state, 75, agc->setup);
582 dib7000p_write_word(state, 76 , agc->inv_gain ); 706 dib7000p_write_word(state, 76, agc->inv_gain);
583 dib7000p_write_word(state, 77 , agc->time_stabiliz ); 707 dib7000p_write_word(state, 77, agc->time_stabiliz);
584 dib7000p_write_word(state, 100, (agc->alpha_level << 12) | agc->thlock); 708 dib7000p_write_word(state, 100, (agc->alpha_level << 12) | agc->thlock);
585 709
586 // Demod AGC loop configuration 710 // Demod AGC loop configuration
587 dib7000p_write_word(state, 101, (agc->alpha_mant << 5) | agc->alpha_exp); 711 dib7000p_write_word(state, 101, (agc->alpha_mant << 5) | agc->alpha_exp);
588 dib7000p_write_word(state, 102, (agc->beta_mant << 6) | agc->beta_exp); 712 dib7000p_write_word(state, 102, (agc->beta_mant << 6) | agc->beta_exp);
589 713
590 /* AGC continued */ 714 /* AGC continued */
591 dprintk( "WBD: ref: %d, sel: %d, active: %d, alpha: %d", 715 dprintk("WBD: ref: %d, sel: %d, active: %d, alpha: %d",
592 state->wbd_ref != 0 ? state->wbd_ref : agc->wbd_ref, agc->wbd_sel, !agc->perform_agc_softsplit, agc->wbd_sel); 716 state->wbd_ref != 0 ? state->wbd_ref : agc->wbd_ref, agc->wbd_sel, !agc->perform_agc_softsplit, agc->wbd_sel);
593 717
594 if (state->wbd_ref != 0) 718 if (state->wbd_ref != 0)
@@ -598,101 +722,135 @@ static int dib7000p_set_agc_config(struct dib7000p_state *state, u8 band)
598 722
599 dib7000p_write_word(state, 106, (agc->wbd_sel << 13) | (agc->wbd_alpha << 9) | (agc->perform_agc_softsplit << 8)); 723 dib7000p_write_word(state, 106, (agc->wbd_sel << 13) | (agc->wbd_alpha << 9) | (agc->perform_agc_softsplit << 8));
600 724
601 dib7000p_write_word(state, 107, agc->agc1_max); 725 dib7000p_write_word(state, 107, agc->agc1_max);
602 dib7000p_write_word(state, 108, agc->agc1_min); 726 dib7000p_write_word(state, 108, agc->agc1_min);
603 dib7000p_write_word(state, 109, agc->agc2_max); 727 dib7000p_write_word(state, 109, agc->agc2_max);
604 dib7000p_write_word(state, 110, agc->agc2_min); 728 dib7000p_write_word(state, 110, agc->agc2_min);
605 dib7000p_write_word(state, 111, (agc->agc1_pt1 << 8) | agc->agc1_pt2); 729 dib7000p_write_word(state, 111, (agc->agc1_pt1 << 8) | agc->agc1_pt2);
606 dib7000p_write_word(state, 112, agc->agc1_pt3); 730 dib7000p_write_word(state, 112, agc->agc1_pt3);
607 dib7000p_write_word(state, 113, (agc->agc1_slope1 << 8) | agc->agc1_slope2); 731 dib7000p_write_word(state, 113, (agc->agc1_slope1 << 8) | agc->agc1_slope2);
608 dib7000p_write_word(state, 114, (agc->agc2_pt1 << 8) | agc->agc2_pt2); 732 dib7000p_write_word(state, 114, (agc->agc2_pt1 << 8) | agc->agc2_pt2);
609 dib7000p_write_word(state, 115, (agc->agc2_slope1 << 8) | agc->agc2_slope2); 733 dib7000p_write_word(state, 115, (agc->agc2_slope1 << 8) | agc->agc2_slope2);
610 return 0; 734 return 0;
611} 735}
612 736
737static void dib7000p_set_dds(struct dib7000p_state *state, s32 offset_khz)
738{
739 u32 internal = dib7000p_get_internal_freq(state);
740 s32 unit_khz_dds_val = 67108864 / (internal); /* 2**26 / Fsampling is the unit 1KHz offset */
741 u32 abs_offset_khz = ABS(offset_khz);
742 u32 dds = state->cfg.bw->ifreq & 0x1ffffff;
743 u8 invert = !!(state->cfg.bw->ifreq & (1 << 25));
744
745 dprintk("setting a frequency offset of %dkHz internal freq = %d invert = %d", offset_khz, internal, invert);
746
747 if (offset_khz < 0)
748 unit_khz_dds_val *= -1;
749
750 /* IF tuner */
751 if (invert)
752 dds -= (abs_offset_khz * unit_khz_dds_val); /* /100 because of /100 on the unit_khz_dds_val line calc for better accuracy */
753 else
754 dds += (abs_offset_khz * unit_khz_dds_val);
755
756 if (abs_offset_khz <= (internal / 2)) { /* Max dds offset is the half of the demod freq */
757 dib7000p_write_word(state, 21, (u16) (((dds >> 16) & 0x1ff) | (0 << 10) | (invert << 9)));
758 dib7000p_write_word(state, 22, (u16) (dds & 0xffff));
759 }
760}
761
613static int dib7000p_agc_startup(struct dvb_frontend *demod, struct dvb_frontend_parameters *ch) 762static int dib7000p_agc_startup(struct dvb_frontend *demod, struct dvb_frontend_parameters *ch)
614{ 763{
615 struct dib7000p_state *state = demod->demodulator_priv; 764 struct dib7000p_state *state = demod->demodulator_priv;
616 int ret = -1; 765 int ret = -1;
617 u8 *agc_state = &state->agc_state; 766 u8 *agc_state = &state->agc_state;
618 u8 agc_split; 767 u8 agc_split;
768 u16 reg;
769 u32 upd_demod_gain_period = 0x1000;
619 770
620 switch (state->agc_state) { 771 switch (state->agc_state) {
621 case 0: 772 case 0:
622 // set power-up level: interf+analog+AGC 773 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
623 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL); 774 if (state->version == SOC7090) {
775 reg = dib7000p_read_word(state, 0x79b) & 0xff00;
776 dib7000p_write_word(state, 0x79a, upd_demod_gain_period & 0xFFFF); /* lsb */
777 dib7000p_write_word(state, 0x79b, reg | (1 << 14) | ((upd_demod_gain_period >> 16) & 0xFF));
778
779 /* enable adc i & q */
780 reg = dib7000p_read_word(state, 0x780);
781 dib7000p_write_word(state, 0x780, (reg | (0x3)) & (~(1 << 7)));
782 } else {
624 dib7000p_set_adc_state(state, DIBX000_ADC_ON); 783 dib7000p_set_adc_state(state, DIBX000_ADC_ON);
625 dib7000p_pll_clk_cfg(state); 784 dib7000p_pll_clk_cfg(state);
785 }
626 786
627 if (dib7000p_set_agc_config(state, BAND_OF_FREQUENCY(ch->frequency/1000)) != 0) 787 if (dib7000p_set_agc_config(state, BAND_OF_FREQUENCY(ch->frequency / 1000)) != 0)
628 return -1; 788 return -1;
629
630 ret = 7;
631 (*agc_state)++;
632 break;
633 789
634 case 1: 790 dib7000p_set_dds(state, 0);
635 // AGC initialization 791 ret = 7;
636 if (state->cfg.agc_control) 792 (*agc_state)++;
637 state->cfg.agc_control(&state->demod, 1); 793 break;
638
639 dib7000p_write_word(state, 78, 32768);
640 if (!state->current_agc->perform_agc_softsplit) {
641 /* we are using the wbd - so slow AGC startup */
642 /* force 0 split on WBD and restart AGC */
643 dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (state->current_agc->wbd_alpha << 9) | (1 << 8));
644 (*agc_state)++;
645 ret = 5;
646 } else {
647 /* default AGC startup */
648 (*agc_state) = 4;
649 /* wait AGC rough lock time */
650 ret = 7;
651 }
652 794
653 dib7000p_restart_agc(state); 795 case 1:
654 break; 796 if (state->cfg.agc_control)
797 state->cfg.agc_control(&state->demod, 1);
655 798
656 case 2: /* fast split search path after 5sec */ 799 dib7000p_write_word(state, 78, 32768);
657 dib7000p_write_word(state, 75, state->current_agc->setup | (1 << 4)); /* freeze AGC loop */ 800 if (!state->current_agc->perform_agc_softsplit) {
658 dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (2 << 9) | (0 << 8)); /* fast split search 0.25kHz */ 801 /* we are using the wbd - so slow AGC startup */
802 /* force 0 split on WBD and restart AGC */
803 dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (state->current_agc->wbd_alpha << 9) | (1 << 8));
659 (*agc_state)++; 804 (*agc_state)++;
660 ret = 14; 805 ret = 5;
661 break; 806 } else {
807 /* default AGC startup */
808 (*agc_state) = 4;
809 /* wait AGC rough lock time */
810 ret = 7;
811 }
662 812
663 case 3: /* split search ended */ 813 dib7000p_restart_agc(state);
664 agc_split = (u8)dib7000p_read_word(state, 396); /* store the split value for the next time */ 814 break;
665 dib7000p_write_word(state, 78, dib7000p_read_word(state, 394)); /* set AGC gain start value */
666 815
667 dib7000p_write_word(state, 75, state->current_agc->setup); /* std AGC loop */ 816 case 2: /* fast split search path after 5sec */
668 dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (state->current_agc->wbd_alpha << 9) | agc_split); /* standard split search */ 817 dib7000p_write_word(state, 75, state->current_agc->setup | (1 << 4)); /* freeze AGC loop */
818 dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (2 << 9) | (0 << 8)); /* fast split search 0.25kHz */
819 (*agc_state)++;
820 ret = 14;
821 break;
669 822
670 dib7000p_restart_agc(state); 823 case 3: /* split search ended */
824 agc_split = (u8) dib7000p_read_word(state, 396); /* store the split value for the next time */
825 dib7000p_write_word(state, 78, dib7000p_read_word(state, 394)); /* set AGC gain start value */
671 826
672 dprintk( "SPLIT %p: %hd", demod, agc_split); 827 dib7000p_write_word(state, 75, state->current_agc->setup); /* std AGC loop */
828 dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (state->current_agc->wbd_alpha << 9) | agc_split); /* standard split search */
673 829
674 (*agc_state)++; 830 dib7000p_restart_agc(state);
675 ret = 5;
676 break;
677 831
678 case 4: /* LNA startup */ 832 dprintk("SPLIT %p: %hd", demod, agc_split);
679 // wait AGC accurate lock time
680 ret = 7;
681 833
682 if (dib7000p_update_lna(state)) 834 (*agc_state)++;
683 // wait only AGC rough lock time 835 ret = 5;
684 ret = 5; 836 break;
685 else // nothing was done, go to the next state 837
686 (*agc_state)++; 838 case 4: /* LNA startup */
687 break; 839 ret = 7;
688 840
689 case 5: 841 if (dib7000p_update_lna(state))
690 if (state->cfg.agc_control) 842 ret = 5;
691 state->cfg.agc_control(&state->demod, 0); 843 else
692 (*agc_state)++; 844 (*agc_state)++;
693 break; 845 break;
694 default: 846
695 break; 847 case 5:
848 if (state->cfg.agc_control)
849 state->cfg.agc_control(&state->demod, 0);
850 (*agc_state)++;
851 break;
852 default:
853 break;
696 } 854 }
697 return ret; 855 return ret;
698} 856}
@@ -703,45 +861,89 @@ static void dib7000p_update_timf(struct dib7000p_state *state)
703 state->timf = timf * 160 / (state->current_bandwidth / 50); 861 state->timf = timf * 160 / (state->current_bandwidth / 50);
704 dib7000p_write_word(state, 23, (u16) (timf >> 16)); 862 dib7000p_write_word(state, 23, (u16) (timf >> 16));
705 dib7000p_write_word(state, 24, (u16) (timf & 0xffff)); 863 dib7000p_write_word(state, 24, (u16) (timf & 0xffff));
706 dprintk( "updated timf_frequency: %d (default: %d)",state->timf, state->cfg.bw->timf); 864 dprintk("updated timf_frequency: %d (default: %d)", state->timf, state->cfg.bw->timf);
865
866}
707 867
868u32 dib7000p_ctrl_timf(struct dvb_frontend *fe, u8 op, u32 timf)
869{
870 struct dib7000p_state *state = fe->demodulator_priv;
871 switch (op) {
872 case DEMOD_TIMF_SET:
873 state->timf = timf;
874 break;
875 case DEMOD_TIMF_UPDATE:
876 dib7000p_update_timf(state);
877 break;
878 case DEMOD_TIMF_GET:
879 break;
880 }
881 dib7000p_set_bandwidth(state, state->current_bandwidth);
882 return state->timf;
708} 883}
884EXPORT_SYMBOL(dib7000p_ctrl_timf);
709 885
710static void dib7000p_set_channel(struct dib7000p_state *state, struct dvb_frontend_parameters *ch, u8 seq) 886static void dib7000p_set_channel(struct dib7000p_state *state, struct dvb_frontend_parameters *ch, u8 seq)
711{ 887{
712 u16 value, est[4]; 888 u16 value, est[4];
713 889
714 dib7000p_set_bandwidth(state, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth)); 890 dib7000p_set_bandwidth(state, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth));
715 891
716 /* nfft, guard, qam, alpha */ 892 /* nfft, guard, qam, alpha */
717 value = 0; 893 value = 0;
718 switch (ch->u.ofdm.transmission_mode) { 894 switch (ch->u.ofdm.transmission_mode) {
719 case TRANSMISSION_MODE_2K: value |= (0 << 7); break; 895 case TRANSMISSION_MODE_2K:
720 case /* 4K MODE */ 255: value |= (2 << 7); break; 896 value |= (0 << 7);
721 default: 897 break;
722 case TRANSMISSION_MODE_8K: value |= (1 << 7); break; 898 case TRANSMISSION_MODE_4K:
899 value |= (2 << 7);
900 break;
901 default:
902 case TRANSMISSION_MODE_8K:
903 value |= (1 << 7);
904 break;
723 } 905 }
724 switch (ch->u.ofdm.guard_interval) { 906 switch (ch->u.ofdm.guard_interval) {
725 case GUARD_INTERVAL_1_32: value |= (0 << 5); break; 907 case GUARD_INTERVAL_1_32:
726 case GUARD_INTERVAL_1_16: value |= (1 << 5); break; 908 value |= (0 << 5);
727 case GUARD_INTERVAL_1_4: value |= (3 << 5); break; 909 break;
728 default: 910 case GUARD_INTERVAL_1_16:
729 case GUARD_INTERVAL_1_8: value |= (2 << 5); break; 911 value |= (1 << 5);
912 break;
913 case GUARD_INTERVAL_1_4:
914 value |= (3 << 5);
915 break;
916 default:
917 case GUARD_INTERVAL_1_8:
918 value |= (2 << 5);
919 break;
730 } 920 }
731 switch (ch->u.ofdm.constellation) { 921 switch (ch->u.ofdm.constellation) {
732 case QPSK: value |= (0 << 3); break; 922 case QPSK:
733 case QAM_16: value |= (1 << 3); break; 923 value |= (0 << 3);
734 default: 924 break;
735 case QAM_64: value |= (2 << 3); break; 925 case QAM_16:
926 value |= (1 << 3);
927 break;
928 default:
929 case QAM_64:
930 value |= (2 << 3);
931 break;
736 } 932 }
737 switch (HIERARCHY_1) { 933 switch (HIERARCHY_1) {
738 case HIERARCHY_2: value |= 2; break; 934 case HIERARCHY_2:
739 case HIERARCHY_4: value |= 4; break; 935 value |= 2;
740 default: 936 break;
741 case HIERARCHY_1: value |= 1; break; 937 case HIERARCHY_4:
938 value |= 4;
939 break;
940 default:
941 case HIERARCHY_1:
942 value |= 1;
943 break;
742 } 944 }
743 dib7000p_write_word(state, 0, value); 945 dib7000p_write_word(state, 0, value);
744 dib7000p_write_word(state, 5, (seq << 4) | 1); /* do not force tps, search list 0 */ 946 dib7000p_write_word(state, 5, (seq << 4) | 1); /* do not force tps, search list 0 */
745 947
746 /* P_dintl_native, P_dintlv_inv, P_hrch, P_code_rate, P_select_hp */ 948 /* P_dintl_native, P_dintlv_inv, P_hrch, P_code_rate, P_select_hp */
747 value = 0; 949 value = 0;
@@ -752,39 +954,63 @@ static void dib7000p_set_channel(struct dib7000p_state *state, struct dvb_fronte
752 if (1 == 1) 954 if (1 == 1)
753 value |= 1; 955 value |= 1;
754 switch ((ch->u.ofdm.hierarchy_information == 0 || 1 == 1) ? ch->u.ofdm.code_rate_HP : ch->u.ofdm.code_rate_LP) { 956 switch ((ch->u.ofdm.hierarchy_information == 0 || 1 == 1) ? ch->u.ofdm.code_rate_HP : ch->u.ofdm.code_rate_LP) {
755 case FEC_2_3: value |= (2 << 1); break; 957 case FEC_2_3:
756 case FEC_3_4: value |= (3 << 1); break; 958 value |= (2 << 1);
757 case FEC_5_6: value |= (5 << 1); break; 959 break;
758 case FEC_7_8: value |= (7 << 1); break; 960 case FEC_3_4:
759 default: 961 value |= (3 << 1);
760 case FEC_1_2: value |= (1 << 1); break; 962 break;
963 case FEC_5_6:
964 value |= (5 << 1);
965 break;
966 case FEC_7_8:
967 value |= (7 << 1);
968 break;
969 default:
970 case FEC_1_2:
971 value |= (1 << 1);
972 break;
761 } 973 }
762 dib7000p_write_word(state, 208, value); 974 dib7000p_write_word(state, 208, value);
763 975
764 /* offset loop parameters */ 976 /* offset loop parameters */
765 dib7000p_write_word(state, 26, 0x6680); // timf(6xxx) 977 dib7000p_write_word(state, 26, 0x6680);
766 dib7000p_write_word(state, 32, 0x0003); // pha_off_max(xxx3) 978 dib7000p_write_word(state, 32, 0x0003);
767 dib7000p_write_word(state, 29, 0x1273); // isi 979 dib7000p_write_word(state, 29, 0x1273);
768 dib7000p_write_word(state, 33, 0x0005); // sfreq(xxx5) 980 dib7000p_write_word(state, 33, 0x0005);
769 981
770 /* P_dvsy_sync_wait */ 982 /* P_dvsy_sync_wait */
771 switch (ch->u.ofdm.transmission_mode) { 983 switch (ch->u.ofdm.transmission_mode) {
772 case TRANSMISSION_MODE_8K: value = 256; break; 984 case TRANSMISSION_MODE_8K:
773 case /* 4K MODE */ 255: value = 128; break; 985 value = 256;
774 case TRANSMISSION_MODE_2K: 986 break;
775 default: value = 64; break; 987 case TRANSMISSION_MODE_4K:
988 value = 128;
989 break;
990 case TRANSMISSION_MODE_2K:
991 default:
992 value = 64;
993 break;
776 } 994 }
777 switch (ch->u.ofdm.guard_interval) { 995 switch (ch->u.ofdm.guard_interval) {
778 case GUARD_INTERVAL_1_16: value *= 2; break; 996 case GUARD_INTERVAL_1_16:
779 case GUARD_INTERVAL_1_8: value *= 4; break; 997 value *= 2;
780 case GUARD_INTERVAL_1_4: value *= 8; break; 998 break;
781 default: 999 case GUARD_INTERVAL_1_8:
782 case GUARD_INTERVAL_1_32: value *= 1; break; 1000 value *= 4;
1001 break;
1002 case GUARD_INTERVAL_1_4:
1003 value *= 8;
1004 break;
1005 default:
1006 case GUARD_INTERVAL_1_32:
1007 value *= 1;
1008 break;
783 } 1009 }
784 if (state->cfg.diversity_delay == 0) 1010 if (state->cfg.diversity_delay == 0)
785 state->div_sync_wait = (value * 3) / 2 + 48; // add 50% SFN margin + compensate for one DVSY-fifo 1011 state->div_sync_wait = (value * 3) / 2 + 48;
786 else 1012 else
787 state->div_sync_wait = (value * 3) / 2 + state->cfg.diversity_delay; // add 50% SFN margin + compensate for one DVSY-fifo 1013 state->div_sync_wait = (value * 3) / 2 + state->cfg.diversity_delay;
788 1014
789 /* deactive the possibility of diversity reception if extended interleaver */ 1015 /* deactive the possibility of diversity reception if extended interleaver */
790 state->div_force_off = !1 && ch->u.ofdm.transmission_mode != TRANSMISSION_MODE_8K; 1016 state->div_force_off = !1 && ch->u.ofdm.transmission_mode != TRANSMISSION_MODE_8K;
@@ -792,24 +1018,24 @@ static void dib7000p_set_channel(struct dib7000p_state *state, struct dvb_fronte
792 1018
793 /* channel estimation fine configuration */ 1019 /* channel estimation fine configuration */
794 switch (ch->u.ofdm.constellation) { 1020 switch (ch->u.ofdm.constellation) {
795 case QAM_64: 1021 case QAM_64:
796 est[0] = 0x0148; /* P_adp_regul_cnt 0.04 */ 1022 est[0] = 0x0148; /* P_adp_regul_cnt 0.04 */
797 est[1] = 0xfff0; /* P_adp_noise_cnt -0.002 */ 1023 est[1] = 0xfff0; /* P_adp_noise_cnt -0.002 */
798 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */ 1024 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
799 est[3] = 0xfff8; /* P_adp_noise_ext -0.001 */ 1025 est[3] = 0xfff8; /* P_adp_noise_ext -0.001 */
800 break; 1026 break;
801 case QAM_16: 1027 case QAM_16:
802 est[0] = 0x023d; /* P_adp_regul_cnt 0.07 */ 1028 est[0] = 0x023d; /* P_adp_regul_cnt 0.07 */
803 est[1] = 0xffdf; /* P_adp_noise_cnt -0.004 */ 1029 est[1] = 0xffdf; /* P_adp_noise_cnt -0.004 */
804 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */ 1030 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
805 est[3] = 0xfff0; /* P_adp_noise_ext -0.002 */ 1031 est[3] = 0xfff0; /* P_adp_noise_ext -0.002 */
806 break; 1032 break;
807 default: 1033 default:
808 est[0] = 0x099a; /* P_adp_regul_cnt 0.3 */ 1034 est[0] = 0x099a; /* P_adp_regul_cnt 0.3 */
809 est[1] = 0xffae; /* P_adp_noise_cnt -0.01 */ 1035 est[1] = 0xffae; /* P_adp_noise_cnt -0.01 */
810 est[2] = 0x0333; /* P_adp_regul_ext 0.1 */ 1036 est[2] = 0x0333; /* P_adp_regul_ext 0.1 */
811 est[3] = 0xfff8; /* P_adp_noise_ext -0.002 */ 1037 est[3] = 0xfff8; /* P_adp_noise_ext -0.002 */
812 break; 1038 break;
813 } 1039 }
814 for (value = 0; value < 4; value++) 1040 for (value = 0; value < 4; value++)
815 dib7000p_write_word(state, 187 + value, est[value]); 1041 dib7000p_write_word(state, 187 + value, est[value]);
@@ -820,14 +1046,15 @@ static int dib7000p_autosearch_start(struct dvb_frontend *demod, struct dvb_fron
820 struct dib7000p_state *state = demod->demodulator_priv; 1046 struct dib7000p_state *state = demod->demodulator_priv;
821 struct dvb_frontend_parameters schan; 1047 struct dvb_frontend_parameters schan;
822 u32 value, factor; 1048 u32 value, factor;
1049 u32 internal = dib7000p_get_internal_freq(state);
823 1050
824 schan = *ch; 1051 schan = *ch;
825 schan.u.ofdm.constellation = QAM_64; 1052 schan.u.ofdm.constellation = QAM_64;
826 schan.u.ofdm.guard_interval = GUARD_INTERVAL_1_32; 1053 schan.u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
827 schan.u.ofdm.transmission_mode = TRANSMISSION_MODE_8K; 1054 schan.u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
828 schan.u.ofdm.code_rate_HP = FEC_2_3; 1055 schan.u.ofdm.code_rate_HP = FEC_2_3;
829 schan.u.ofdm.code_rate_LP = FEC_3_4; 1056 schan.u.ofdm.code_rate_LP = FEC_3_4;
830 schan.u.ofdm.hierarchy_information = 0; 1057 schan.u.ofdm.hierarchy_information = 0;
831 1058
832 dib7000p_set_channel(state, &schan, 7); 1059 dib7000p_set_channel(state, &schan, 7);
833 1060
@@ -837,16 +1064,15 @@ static int dib7000p_autosearch_start(struct dvb_frontend *demod, struct dvb_fron
837 else 1064 else
838 factor = 6; 1065 factor = 6;
839 1066
840 // always use the setting for 8MHz here lock_time for 7,6 MHz are longer 1067 value = 30 * internal * factor;
841 value = 30 * state->cfg.bw->internal * factor; 1068 dib7000p_write_word(state, 6, (u16) ((value >> 16) & 0xffff));
842 dib7000p_write_word(state, 6, (u16) ((value >> 16) & 0xffff)); // lock0 wait time 1069 dib7000p_write_word(state, 7, (u16) (value & 0xffff));
843 dib7000p_write_word(state, 7, (u16) (value & 0xffff)); // lock0 wait time 1070 value = 100 * internal * factor;
844 value = 100 * state->cfg.bw->internal * factor; 1071 dib7000p_write_word(state, 8, (u16) ((value >> 16) & 0xffff));
845 dib7000p_write_word(state, 8, (u16) ((value >> 16) & 0xffff)); // lock1 wait time 1072 dib7000p_write_word(state, 9, (u16) (value & 0xffff));
846 dib7000p_write_word(state, 9, (u16) (value & 0xffff)); // lock1 wait time 1073 value = 500 * internal * factor;
847 value = 500 * state->cfg.bw->internal * factor; 1074 dib7000p_write_word(state, 10, (u16) ((value >> 16) & 0xffff));
848 dib7000p_write_word(state, 10, (u16) ((value >> 16) & 0xffff)); // lock2 wait time 1075 dib7000p_write_word(state, 11, (u16) (value & 0xffff));
849 dib7000p_write_word(state, 11, (u16) (value & 0xffff)); // lock2 wait time
850 1076
851 value = dib7000p_read_word(state, 0); 1077 value = dib7000p_read_word(state, 0);
852 dib7000p_write_word(state, 0, (u16) ((1 << 9) | value)); 1078 dib7000p_write_word(state, 0, (u16) ((1 << 9) | value));
@@ -861,101 +1087,101 @@ static int dib7000p_autosearch_is_irq(struct dvb_frontend *demod)
861 struct dib7000p_state *state = demod->demodulator_priv; 1087 struct dib7000p_state *state = demod->demodulator_priv;
862 u16 irq_pending = dib7000p_read_word(state, 1284); 1088 u16 irq_pending = dib7000p_read_word(state, 1284);
863 1089
864 if (irq_pending & 0x1) // failed 1090 if (irq_pending & 0x1)
865 return 1; 1091 return 1;
866 1092
867 if (irq_pending & 0x2) // succeeded 1093 if (irq_pending & 0x2)
868 return 2; 1094 return 2;
869 1095
870 return 0; // still pending 1096 return 0;
871} 1097}
872 1098
873static void dib7000p_spur_protect(struct dib7000p_state *state, u32 rf_khz, u32 bw) 1099static void dib7000p_spur_protect(struct dib7000p_state *state, u32 rf_khz, u32 bw)
874{ 1100{
875 static s16 notch[]={16143, 14402, 12238, 9713, 6902, 3888, 759, -2392}; 1101 static s16 notch[] = { 16143, 14402, 12238, 9713, 6902, 3888, 759, -2392 };
876 static u8 sine [] ={0, 2, 3, 5, 6, 8, 9, 11, 13, 14, 16, 17, 19, 20, 22, 1102 static u8 sine[] = { 0, 2, 3, 5, 6, 8, 9, 11, 13, 14, 16, 17, 19, 20, 22,
877 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 42, 44, 45, 47, 48, 50, 51, 1103 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 42, 44, 45, 47, 48, 50, 51,
878 53, 55, 56, 58, 59, 61, 62, 64, 65, 67, 68, 70, 71, 73, 74, 76, 77, 79, 80, 1104 53, 55, 56, 58, 59, 61, 62, 64, 65, 67, 68, 70, 71, 73, 74, 76, 77, 79, 80,
879 82, 83, 85, 86, 88, 89, 91, 92, 94, 95, 97, 98, 99, 101, 102, 104, 105, 1105 82, 83, 85, 86, 88, 89, 91, 92, 94, 95, 97, 98, 99, 101, 102, 104, 105,
880 107, 108, 109, 111, 112, 114, 115, 117, 118, 119, 121, 122, 123, 125, 126, 1106 107, 108, 109, 111, 112, 114, 115, 117, 118, 119, 121, 122, 123, 125, 126,
881 128, 129, 130, 132, 133, 134, 136, 137, 138, 140, 141, 142, 144, 145, 146, 1107 128, 129, 130, 132, 133, 134, 136, 137, 138, 140, 141, 142, 144, 145, 146,
882 147, 149, 150, 151, 152, 154, 155, 156, 157, 159, 160, 161, 162, 164, 165, 1108 147, 149, 150, 151, 152, 154, 155, 156, 157, 159, 160, 161, 162, 164, 165,
883 166, 167, 168, 170, 171, 172, 173, 174, 175, 177, 178, 179, 180, 181, 182, 1109 166, 167, 168, 170, 171, 172, 173, 174, 175, 177, 178, 179, 180, 181, 182,
884 183, 184, 185, 186, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 1110 183, 184, 185, 186, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198,
885 199, 200, 201, 202, 203, 204, 205, 206, 207, 207, 208, 209, 210, 211, 212, 1111 199, 200, 201, 202, 203, 204, 205, 206, 207, 207, 208, 209, 210, 211, 212,
886 213, 214, 215, 215, 216, 217, 218, 219, 220, 220, 221, 222, 223, 224, 224, 1112 213, 214, 215, 215, 216, 217, 218, 219, 220, 220, 221, 222, 223, 224, 224,
887 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 235, 1113 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 235,
888 235, 236, 237, 237, 238, 238, 239, 239, 240, 241, 241, 242, 242, 243, 243, 1114 235, 236, 237, 237, 238, 238, 239, 239, 240, 241, 241, 242, 242, 243, 243,
889 244, 244, 245, 245, 245, 246, 246, 247, 247, 248, 248, 248, 249, 249, 249, 1115 244, 244, 245, 245, 245, 246, 246, 247, 247, 248, 248, 248, 249, 249, 249,
890 250, 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 254, 1116 250, 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 254,
891 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1117 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
892 255, 255, 255, 255, 255, 255}; 1118 255, 255, 255, 255, 255, 255
1119 };
893 1120
894 u32 xtal = state->cfg.bw->xtal_hz / 1000; 1121 u32 xtal = state->cfg.bw->xtal_hz / 1000;
895 int f_rel = DIV_ROUND_CLOSEST(rf_khz, xtal) * xtal - rf_khz; 1122 int f_rel = DIV_ROUND_CLOSEST(rf_khz, xtal) * xtal - rf_khz;
896 int k; 1123 int k;
897 int coef_re[8],coef_im[8]; 1124 int coef_re[8], coef_im[8];
898 int bw_khz = bw; 1125 int bw_khz = bw;
899 u32 pha; 1126 u32 pha;
900 1127
901 dprintk( "relative position of the Spur: %dk (RF: %dk, XTAL: %dk)", f_rel, rf_khz, xtal); 1128 dprintk("relative position of the Spur: %dk (RF: %dk, XTAL: %dk)", f_rel, rf_khz, xtal);
902
903 1129
904 if (f_rel < -bw_khz/2 || f_rel > bw_khz/2) 1130 if (f_rel < -bw_khz / 2 || f_rel > bw_khz / 2)
905 return; 1131 return;
906 1132
907 bw_khz /= 100; 1133 bw_khz /= 100;
908 1134
909 dib7000p_write_word(state, 142 ,0x0610); 1135 dib7000p_write_word(state, 142, 0x0610);
910 1136
911 for (k = 0; k < 8; k++) { 1137 for (k = 0; k < 8; k++) {
912 pha = ((f_rel * (k+1) * 112 * 80/bw_khz) /1000) & 0x3ff; 1138 pha = ((f_rel * (k + 1) * 112 * 80 / bw_khz) / 1000) & 0x3ff;
913 1139
914 if (pha==0) { 1140 if (pha == 0) {
915 coef_re[k] = 256; 1141 coef_re[k] = 256;
916 coef_im[k] = 0; 1142 coef_im[k] = 0;
917 } else if(pha < 256) { 1143 } else if (pha < 256) {
918 coef_re[k] = sine[256-(pha&0xff)]; 1144 coef_re[k] = sine[256 - (pha & 0xff)];
919 coef_im[k] = sine[pha&0xff]; 1145 coef_im[k] = sine[pha & 0xff];
920 } else if (pha == 256) { 1146 } else if (pha == 256) {
921 coef_re[k] = 0; 1147 coef_re[k] = 0;
922 coef_im[k] = 256; 1148 coef_im[k] = 256;
923 } else if (pha < 512) { 1149 } else if (pha < 512) {
924 coef_re[k] = -sine[pha&0xff]; 1150 coef_re[k] = -sine[pha & 0xff];
925 coef_im[k] = sine[256 - (pha&0xff)]; 1151 coef_im[k] = sine[256 - (pha & 0xff)];
926 } else if (pha == 512) { 1152 } else if (pha == 512) {
927 coef_re[k] = -256; 1153 coef_re[k] = -256;
928 coef_im[k] = 0; 1154 coef_im[k] = 0;
929 } else if (pha < 768) { 1155 } else if (pha < 768) {
930 coef_re[k] = -sine[256-(pha&0xff)]; 1156 coef_re[k] = -sine[256 - (pha & 0xff)];
931 coef_im[k] = -sine[pha&0xff]; 1157 coef_im[k] = -sine[pha & 0xff];
932 } else if (pha == 768) { 1158 } else if (pha == 768) {
933 coef_re[k] = 0; 1159 coef_re[k] = 0;
934 coef_im[k] = -256; 1160 coef_im[k] = -256;
935 } else { 1161 } else {
936 coef_re[k] = sine[pha&0xff]; 1162 coef_re[k] = sine[pha & 0xff];
937 coef_im[k] = -sine[256 - (pha&0xff)]; 1163 coef_im[k] = -sine[256 - (pha & 0xff)];
938 } 1164 }
939 1165
940 coef_re[k] *= notch[k]; 1166 coef_re[k] *= notch[k];
941 coef_re[k] += (1<<14); 1167 coef_re[k] += (1 << 14);
942 if (coef_re[k] >= (1<<24)) 1168 if (coef_re[k] >= (1 << 24))
943 coef_re[k] = (1<<24) - 1; 1169 coef_re[k] = (1 << 24) - 1;
944 coef_re[k] /= (1<<15); 1170 coef_re[k] /= (1 << 15);
945 1171
946 coef_im[k] *= notch[k]; 1172 coef_im[k] *= notch[k];
947 coef_im[k] += (1<<14); 1173 coef_im[k] += (1 << 14);
948 if (coef_im[k] >= (1<<24)) 1174 if (coef_im[k] >= (1 << 24))
949 coef_im[k] = (1<<24)-1; 1175 coef_im[k] = (1 << 24) - 1;
950 coef_im[k] /= (1<<15); 1176 coef_im[k] /= (1 << 15);
951 1177
952 dprintk( "PALF COEF: %d re: %d im: %d", k, coef_re[k], coef_im[k]); 1178 dprintk("PALF COEF: %d re: %d im: %d", k, coef_re[k], coef_im[k]);
953 1179
954 dib7000p_write_word(state, 143, (0 << 14) | (k << 10) | (coef_re[k] & 0x3ff)); 1180 dib7000p_write_word(state, 143, (0 << 14) | (k << 10) | (coef_re[k] & 0x3ff));
955 dib7000p_write_word(state, 144, coef_im[k] & 0x3ff); 1181 dib7000p_write_word(state, 144, coef_im[k] & 0x3ff);
956 dib7000p_write_word(state, 143, (1 << 14) | (k << 10) | (coef_re[k] & 0x3ff)); 1182 dib7000p_write_word(state, 143, (1 << 14) | (k << 10) | (coef_re[k] & 0x3ff));
957 } 1183 }
958 dib7000p_write_word(state,143 ,0); 1184 dib7000p_write_word(state, 143, 0);
959} 1185}
960 1186
961static int dib7000p_tune(struct dvb_frontend *demod, struct dvb_frontend_parameters *ch) 1187static int dib7000p_tune(struct dvb_frontend *demod, struct dvb_frontend_parameters *ch)
@@ -976,11 +1202,11 @@ static int dib7000p_tune(struct dvb_frontend *demod, struct dvb_frontend_paramet
976 /* P_ctrl_inh_cor=0, P_ctrl_alpha_cor=4, P_ctrl_inh_isi=0, P_ctrl_alpha_isi=3, P_ctrl_inh_cor4=1, P_ctrl_alpha_cor4=3 */ 1202 /* P_ctrl_inh_cor=0, P_ctrl_alpha_cor=4, P_ctrl_inh_isi=0, P_ctrl_alpha_isi=3, P_ctrl_inh_cor4=1, P_ctrl_alpha_cor4=3 */
977 tmp = (0 << 14) | (4 << 10) | (0 << 9) | (3 << 5) | (1 << 4) | (0x3); 1203 tmp = (0 << 14) | (4 << 10) | (0 << 9) | (3 << 5) | (1 << 4) | (0x3);
978 if (state->sfn_workaround_active) { 1204 if (state->sfn_workaround_active) {
979 dprintk( "SFN workaround is active"); 1205 dprintk("SFN workaround is active");
980 tmp |= (1 << 9); 1206 tmp |= (1 << 9);
981 dib7000p_write_word(state, 166, 0x4000); // P_pha3_force_pha_shift 1207 dib7000p_write_word(state, 166, 0x4000);
982 } else { 1208 } else {
983 dib7000p_write_word(state, 166, 0x0000); // P_pha3_force_pha_shift 1209 dib7000p_write_word(state, 166, 0x0000);
984 } 1210 }
985 dib7000p_write_word(state, 29, tmp); 1211 dib7000p_write_word(state, 29, tmp);
986 1212
@@ -993,51 +1219,72 @@ static int dib7000p_tune(struct dvb_frontend *demod, struct dvb_frontend_paramet
993 /* P_timf_alpha, P_corm_alpha=6, P_corm_thres=0x80 */ 1219 /* P_timf_alpha, P_corm_alpha=6, P_corm_thres=0x80 */
994 tmp = (6 << 8) | 0x80; 1220 tmp = (6 << 8) | 0x80;
995 switch (ch->u.ofdm.transmission_mode) { 1221 switch (ch->u.ofdm.transmission_mode) {
996 case TRANSMISSION_MODE_2K: tmp |= (7 << 12); break; 1222 case TRANSMISSION_MODE_2K:
997 case /* 4K MODE */ 255: tmp |= (8 << 12); break; 1223 tmp |= (2 << 12);
998 default: 1224 break;
999 case TRANSMISSION_MODE_8K: tmp |= (9 << 12); break; 1225 case TRANSMISSION_MODE_4K:
1226 tmp |= (3 << 12);
1227 break;
1228 default:
1229 case TRANSMISSION_MODE_8K:
1230 tmp |= (4 << 12);
1231 break;
1000 } 1232 }
1001 dib7000p_write_word(state, 26, tmp); /* timf_a(6xxx) */ 1233 dib7000p_write_word(state, 26, tmp); /* timf_a(6xxx) */
1002 1234
1003 /* P_ctrl_freeze_pha_shift=0, P_ctrl_pha_off_max */ 1235 /* P_ctrl_freeze_pha_shift=0, P_ctrl_pha_off_max */
1004 tmp = (0 << 4); 1236 tmp = (0 << 4);
1005 switch (ch->u.ofdm.transmission_mode) { 1237 switch (ch->u.ofdm.transmission_mode) {
1006 case TRANSMISSION_MODE_2K: tmp |= 0x6; break; 1238 case TRANSMISSION_MODE_2K:
1007 case /* 4K MODE */ 255: tmp |= 0x7; break; 1239 tmp |= 0x6;
1008 default: 1240 break;
1009 case TRANSMISSION_MODE_8K: tmp |= 0x8; break; 1241 case TRANSMISSION_MODE_4K:
1242 tmp |= 0x7;
1243 break;
1244 default:
1245 case TRANSMISSION_MODE_8K:
1246 tmp |= 0x8;
1247 break;
1010 } 1248 }
1011 dib7000p_write_word(state, 32, tmp); 1249 dib7000p_write_word(state, 32, tmp);
1012 1250
1013 /* P_ctrl_sfreq_inh=0, P_ctrl_sfreq_step */ 1251 /* P_ctrl_sfreq_inh=0, P_ctrl_sfreq_step */
1014 tmp = (0 << 4); 1252 tmp = (0 << 4);
1015 switch (ch->u.ofdm.transmission_mode) { 1253 switch (ch->u.ofdm.transmission_mode) {
1016 case TRANSMISSION_MODE_2K: tmp |= 0x6; break; 1254 case TRANSMISSION_MODE_2K:
1017 case /* 4K MODE */ 255: tmp |= 0x7; break; 1255 tmp |= 0x6;
1018 default: 1256 break;
1019 case TRANSMISSION_MODE_8K: tmp |= 0x8; break; 1257 case TRANSMISSION_MODE_4K:
1258 tmp |= 0x7;
1259 break;
1260 default:
1261 case TRANSMISSION_MODE_8K:
1262 tmp |= 0x8;
1263 break;
1020 } 1264 }
1021 dib7000p_write_word(state, 33, tmp); 1265 dib7000p_write_word(state, 33, tmp);
1022 1266
1023 tmp = dib7000p_read_word(state,509); 1267 tmp = dib7000p_read_word(state, 509);
1024 if (!((tmp >> 6) & 0x1)) { 1268 if (!((tmp >> 6) & 0x1)) {
1025 /* restart the fec */ 1269 /* restart the fec */
1026 tmp = dib7000p_read_word(state,771); 1270 tmp = dib7000p_read_word(state, 771);
1027 dib7000p_write_word(state, 771, tmp | (1 << 1)); 1271 dib7000p_write_word(state, 771, tmp | (1 << 1));
1028 dib7000p_write_word(state, 771, tmp); 1272 dib7000p_write_word(state, 771, tmp);
1029 msleep(10); 1273 msleep(40);
1030 tmp = dib7000p_read_word(state,509); 1274 tmp = dib7000p_read_word(state, 509);
1031 } 1275 }
1032
1033 // we achieved a lock - it's time to update the osc freq 1276 // we achieved a lock - it's time to update the osc freq
1034 if ((tmp >> 6) & 0x1) 1277 if ((tmp >> 6) & 0x1) {
1035 dib7000p_update_timf(state); 1278 dib7000p_update_timf(state);
1279 /* P_timf_alpha += 2 */
1280 tmp = dib7000p_read_word(state, 26);
1281 dib7000p_write_word(state, 26, (tmp & ~(0xf << 12)) | ((((tmp >> 12) & 0xf) + 5) << 12));
1282 }
1036 1283
1037 if (state->cfg.spur_protect) 1284 if (state->cfg.spur_protect)
1038 dib7000p_spur_protect(state, ch->frequency/1000, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth)); 1285 dib7000p_spur_protect(state, ch->frequency / 1000, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth));
1039 1286
1040 dib7000p_set_bandwidth(state, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth)); 1287 dib7000p_set_bandwidth(state, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth));
1041 return 0; 1288 return 0;
1042} 1289}
1043 1290
@@ -1046,63 +1293,82 @@ static int dib7000p_wakeup(struct dvb_frontend *demod)
1046 struct dib7000p_state *state = demod->demodulator_priv; 1293 struct dib7000p_state *state = demod->demodulator_priv;
1047 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL); 1294 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
1048 dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_ON); 1295 dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_ON);
1296 if (state->version == SOC7090)
1297 dib7000p_sad_calib(state);
1049 return 0; 1298 return 0;
1050} 1299}
1051 1300
1052static int dib7000p_sleep(struct dvb_frontend *demod) 1301static int dib7000p_sleep(struct dvb_frontend *demod)
1053{ 1302{
1054 struct dib7000p_state *state = demod->demodulator_priv; 1303 struct dib7000p_state *state = demod->demodulator_priv;
1304 if (state->version == SOC7090)
1305 return dib7090_set_output_mode(demod, OUTMODE_HIGH_Z) | dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY);
1055 return dib7000p_set_output_mode(state, OUTMODE_HIGH_Z) | dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY); 1306 return dib7000p_set_output_mode(state, OUTMODE_HIGH_Z) | dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY);
1056} 1307}
1057 1308
1058static int dib7000p_identify(struct dib7000p_state *st) 1309static int dib7000p_identify(struct dib7000p_state *st)
1059{ 1310{
1060 u16 value; 1311 u16 value;
1061 dprintk( "checking demod on I2C address: %d (%x)", 1312 dprintk("checking demod on I2C address: %d (%x)", st->i2c_addr, st->i2c_addr);
1062 st->i2c_addr, st->i2c_addr);
1063 1313
1064 if ((value = dib7000p_read_word(st, 768)) != 0x01b3) { 1314 if ((value = dib7000p_read_word(st, 768)) != 0x01b3) {
1065 dprintk( "wrong Vendor ID (read=0x%x)",value); 1315 dprintk("wrong Vendor ID (read=0x%x)", value);
1066 return -EREMOTEIO; 1316 return -EREMOTEIO;
1067 } 1317 }
1068 1318
1069 if ((value = dib7000p_read_word(st, 769)) != 0x4000) { 1319 if ((value = dib7000p_read_word(st, 769)) != 0x4000) {
1070 dprintk( "wrong Device ID (%x)",value); 1320 dprintk("wrong Device ID (%x)", value);
1071 return -EREMOTEIO; 1321 return -EREMOTEIO;
1072 } 1322 }
1073 1323
1074 return 0; 1324 return 0;
1075} 1325}
1076 1326
1077 1327static int dib7000p_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
1078static int dib7000p_get_frontend(struct dvb_frontend* fe,
1079 struct dvb_frontend_parameters *fep)
1080{ 1328{
1081 struct dib7000p_state *state = fe->demodulator_priv; 1329 struct dib7000p_state *state = fe->demodulator_priv;
1082 u16 tps = dib7000p_read_word(state,463); 1330 u16 tps = dib7000p_read_word(state, 463);
1083 1331
1084 fep->inversion = INVERSION_AUTO; 1332 fep->inversion = INVERSION_AUTO;
1085 1333
1086 fep->u.ofdm.bandwidth = BANDWIDTH_TO_INDEX(state->current_bandwidth); 1334 fep->u.ofdm.bandwidth = BANDWIDTH_TO_INDEX(state->current_bandwidth);
1087 1335
1088 switch ((tps >> 8) & 0x3) { 1336 switch ((tps >> 8) & 0x3) {
1089 case 0: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K; break; 1337 case 0:
1090 case 1: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K; break; 1338 fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K;
1091 /* case 2: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_4K; break; */ 1339 break;
1340 case 1:
1341 fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
1342 break;
1343 /* case 2: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_4K; break; */
1092 } 1344 }
1093 1345
1094 switch (tps & 0x3) { 1346 switch (tps & 0x3) {
1095 case 0: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_32; break; 1347 case 0:
1096 case 1: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_16; break; 1348 fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
1097 case 2: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_8; break; 1349 break;
1098 case 3: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_4; break; 1350 case 1:
1351 fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_16;
1352 break;
1353 case 2:
1354 fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_8;
1355 break;
1356 case 3:
1357 fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_4;
1358 break;
1099 } 1359 }
1100 1360
1101 switch ((tps >> 14) & 0x3) { 1361 switch ((tps >> 14) & 0x3) {
1102 case 0: fep->u.ofdm.constellation = QPSK; break; 1362 case 0:
1103 case 1: fep->u.ofdm.constellation = QAM_16; break; 1363 fep->u.ofdm.constellation = QPSK;
1104 case 2: 1364 break;
1105 default: fep->u.ofdm.constellation = QAM_64; break; 1365 case 1:
1366 fep->u.ofdm.constellation = QAM_16;
1367 break;
1368 case 2:
1369 default:
1370 fep->u.ofdm.constellation = QAM_64;
1371 break;
1106 } 1372 }
1107 1373
1108 /* as long as the frontend_param structure is fixed for hierarchical transmission I refuse to use it */ 1374 /* as long as the frontend_param structure is fixed for hierarchical transmission I refuse to use it */
@@ -1110,22 +1376,42 @@ static int dib7000p_get_frontend(struct dvb_frontend* fe,
1110 1376
1111 fep->u.ofdm.hierarchy_information = HIERARCHY_NONE; 1377 fep->u.ofdm.hierarchy_information = HIERARCHY_NONE;
1112 switch ((tps >> 5) & 0x7) { 1378 switch ((tps >> 5) & 0x7) {
1113 case 1: fep->u.ofdm.code_rate_HP = FEC_1_2; break; 1379 case 1:
1114 case 2: fep->u.ofdm.code_rate_HP = FEC_2_3; break; 1380 fep->u.ofdm.code_rate_HP = FEC_1_2;
1115 case 3: fep->u.ofdm.code_rate_HP = FEC_3_4; break; 1381 break;
1116 case 5: fep->u.ofdm.code_rate_HP = FEC_5_6; break; 1382 case 2:
1117 case 7: 1383 fep->u.ofdm.code_rate_HP = FEC_2_3;
1118 default: fep->u.ofdm.code_rate_HP = FEC_7_8; break; 1384 break;
1385 case 3:
1386 fep->u.ofdm.code_rate_HP = FEC_3_4;
1387 break;
1388 case 5:
1389 fep->u.ofdm.code_rate_HP = FEC_5_6;
1390 break;
1391 case 7:
1392 default:
1393 fep->u.ofdm.code_rate_HP = FEC_7_8;
1394 break;
1119 1395
1120 } 1396 }
1121 1397
1122 switch ((tps >> 2) & 0x7) { 1398 switch ((tps >> 2) & 0x7) {
1123 case 1: fep->u.ofdm.code_rate_LP = FEC_1_2; break; 1399 case 1:
1124 case 2: fep->u.ofdm.code_rate_LP = FEC_2_3; break; 1400 fep->u.ofdm.code_rate_LP = FEC_1_2;
1125 case 3: fep->u.ofdm.code_rate_LP = FEC_3_4; break; 1401 break;
1126 case 5: fep->u.ofdm.code_rate_LP = FEC_5_6; break; 1402 case 2:
1127 case 7: 1403 fep->u.ofdm.code_rate_LP = FEC_2_3;
1128 default: fep->u.ofdm.code_rate_LP = FEC_7_8; break; 1404 break;
1405 case 3:
1406 fep->u.ofdm.code_rate_LP = FEC_3_4;
1407 break;
1408 case 5:
1409 fep->u.ofdm.code_rate_LP = FEC_5_6;
1410 break;
1411 case 7:
1412 default:
1413 fep->u.ofdm.code_rate_LP = FEC_7_8;
1414 break;
1129 } 1415 }
1130 1416
1131 /* native interleaver: (dib7000p_read_word(state, 464) >> 5) & 0x1 */ 1417 /* native interleaver: (dib7000p_read_word(state, 464) >> 5) & 0x1 */
@@ -1133,15 +1419,18 @@ static int dib7000p_get_frontend(struct dvb_frontend* fe,
1133 return 0; 1419 return 0;
1134} 1420}
1135 1421
1136static int dib7000p_set_frontend(struct dvb_frontend* fe, 1422static int dib7000p_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
1137 struct dvb_frontend_parameters *fep)
1138{ 1423{
1139 struct dib7000p_state *state = fe->demodulator_priv; 1424 struct dib7000p_state *state = fe->demodulator_priv;
1140 int time, ret; 1425 int time, ret;
1141 1426
1142 dib7000p_set_output_mode(state, OUTMODE_HIGH_Z); 1427 if (state->version == SOC7090) {
1428 dib7090_set_diversity_in(fe, 0);
1429 dib7090_set_output_mode(fe, OUTMODE_HIGH_Z);
1430 } else
1431 dib7000p_set_output_mode(state, OUTMODE_HIGH_Z);
1143 1432
1144 /* maybe the parameter has been changed */ 1433 /* maybe the parameter has been changed */
1145 state->sfn_workaround_active = buggy_sfn_workaround; 1434 state->sfn_workaround_active = buggy_sfn_workaround;
1146 1435
1147 if (fe->ops.tuner_ops.set_params) 1436 if (fe->ops.tuner_ops.set_params)
@@ -1156,9 +1445,7 @@ static int dib7000p_set_frontend(struct dvb_frontend* fe,
1156 } while (time != -1); 1445 } while (time != -1);
1157 1446
1158 if (fep->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO || 1447 if (fep->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO ||
1159 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO || 1448 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO || fep->u.ofdm.constellation == QAM_AUTO || fep->u.ofdm.code_rate_HP == FEC_AUTO) {
1160 fep->u.ofdm.constellation == QAM_AUTO ||
1161 fep->u.ofdm.code_rate_HP == FEC_AUTO) {
1162 int i = 800, found; 1449 int i = 800, found;
1163 1450
1164 dib7000p_autosearch_start(fe, fep); 1451 dib7000p_autosearch_start(fe, fep);
@@ -1167,9 +1454,9 @@ static int dib7000p_set_frontend(struct dvb_frontend* fe,
1167 found = dib7000p_autosearch_is_irq(fe); 1454 found = dib7000p_autosearch_is_irq(fe);
1168 } while (found == 0 && i--); 1455 } while (found == 0 && i--);
1169 1456
1170 dprintk("autosearch returns: %d",found); 1457 dprintk("autosearch returns: %d", found);
1171 if (found == 0 || found == 1) 1458 if (found == 0 || found == 1)
1172 return 0; // no channel found 1459 return 0;
1173 1460
1174 dib7000p_get_frontend(fe, fep); 1461 dib7000p_get_frontend(fe, fep);
1175 } 1462 }
@@ -1177,11 +1464,15 @@ static int dib7000p_set_frontend(struct dvb_frontend* fe,
1177 ret = dib7000p_tune(fe, fep); 1464 ret = dib7000p_tune(fe, fep);
1178 1465
1179 /* make this a config parameter */ 1466 /* make this a config parameter */
1180 dib7000p_set_output_mode(state, state->cfg.output_mode); 1467 if (state->version == SOC7090)
1181 return ret; 1468 dib7090_set_output_mode(fe, state->cfg.output_mode);
1469 else
1470 dib7000p_set_output_mode(state, state->cfg.output_mode);
1471
1472 return ret;
1182} 1473}
1183 1474
1184static int dib7000p_read_status(struct dvb_frontend *fe, fe_status_t *stat) 1475static int dib7000p_read_status(struct dvb_frontend *fe, fe_status_t * stat)
1185{ 1476{
1186 struct dib7000p_state *state = fe->demodulator_priv; 1477 struct dib7000p_state *state = fe->demodulator_priv;
1187 u16 lock = dib7000p_read_word(state, 509); 1478 u16 lock = dib7000p_read_word(state, 509);
@@ -1196,27 +1487,27 @@ static int dib7000p_read_status(struct dvb_frontend *fe, fe_status_t *stat)
1196 *stat |= FE_HAS_VITERBI; 1487 *stat |= FE_HAS_VITERBI;
1197 if (lock & 0x0010) 1488 if (lock & 0x0010)
1198 *stat |= FE_HAS_SYNC; 1489 *stat |= FE_HAS_SYNC;
1199 if ((lock & 0x0038) == 0x38) 1490 if ((lock & 0x0038) == 0x38)
1200 *stat |= FE_HAS_LOCK; 1491 *stat |= FE_HAS_LOCK;
1201 1492
1202 return 0; 1493 return 0;
1203} 1494}
1204 1495
1205static int dib7000p_read_ber(struct dvb_frontend *fe, u32 *ber) 1496static int dib7000p_read_ber(struct dvb_frontend *fe, u32 * ber)
1206{ 1497{
1207 struct dib7000p_state *state = fe->demodulator_priv; 1498 struct dib7000p_state *state = fe->demodulator_priv;
1208 *ber = (dib7000p_read_word(state, 500) << 16) | dib7000p_read_word(state, 501); 1499 *ber = (dib7000p_read_word(state, 500) << 16) | dib7000p_read_word(state, 501);
1209 return 0; 1500 return 0;
1210} 1501}
1211 1502
1212static int dib7000p_read_unc_blocks(struct dvb_frontend *fe, u32 *unc) 1503static int dib7000p_read_unc_blocks(struct dvb_frontend *fe, u32 * unc)
1213{ 1504{
1214 struct dib7000p_state *state = fe->demodulator_priv; 1505 struct dib7000p_state *state = fe->demodulator_priv;
1215 *unc = dib7000p_read_word(state, 506); 1506 *unc = dib7000p_read_word(state, 506);
1216 return 0; 1507 return 0;
1217} 1508}
1218 1509
1219static int dib7000p_read_signal_strength(struct dvb_frontend *fe, u16 *strength) 1510static int dib7000p_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
1220{ 1511{
1221 struct dib7000p_state *state = fe->demodulator_priv; 1512 struct dib7000p_state *state = fe->demodulator_priv;
1222 u16 val = dib7000p_read_word(state, 394); 1513 u16 val = dib7000p_read_word(state, 394);
@@ -1224,7 +1515,7 @@ static int dib7000p_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
1224 return 0; 1515 return 0;
1225} 1516}
1226 1517
1227static int dib7000p_read_snr(struct dvb_frontend* fe, u16 *snr) 1518static int dib7000p_read_snr(struct dvb_frontend *fe, u16 * snr)
1228{ 1519{
1229 struct dib7000p_state *state = fe->demodulator_priv; 1520 struct dib7000p_state *state = fe->demodulator_priv;
1230 u16 val; 1521 u16 val;
@@ -1240,19 +1531,17 @@ static int dib7000p_read_snr(struct dvb_frontend* fe, u16 *snr)
1240 noise_exp -= 0x40; 1531 noise_exp -= 0x40;
1241 1532
1242 signal_mant = (val >> 6) & 0xFF; 1533 signal_mant = (val >> 6) & 0xFF;
1243 signal_exp = (val & 0x3F); 1534 signal_exp = (val & 0x3F);
1244 if ((signal_exp & 0x20) != 0) 1535 if ((signal_exp & 0x20) != 0)
1245 signal_exp -= 0x40; 1536 signal_exp -= 0x40;
1246 1537
1247 if (signal_mant != 0) 1538 if (signal_mant != 0)
1248 result = intlog10(2) * 10 * signal_exp + 10 * 1539 result = intlog10(2) * 10 * signal_exp + 10 * intlog10(signal_mant);
1249 intlog10(signal_mant);
1250 else 1540 else
1251 result = intlog10(2) * 10 * signal_exp - 100; 1541 result = intlog10(2) * 10 * signal_exp - 100;
1252 1542
1253 if (noise_mant != 0) 1543 if (noise_mant != 0)
1254 result -= intlog10(2) * 10 * noise_exp + 10 * 1544 result -= intlog10(2) * 10 * noise_exp + 10 * intlog10(noise_mant);
1255 intlog10(noise_mant);
1256 else 1545 else
1257 result -= intlog10(2) * 10 * noise_exp - 100; 1546 result -= intlog10(2) * 10 * noise_exp - 100;
1258 1547
@@ -1260,7 +1549,7 @@ static int dib7000p_read_snr(struct dvb_frontend* fe, u16 *snr)
1260 return 0; 1549 return 0;
1261} 1550}
1262 1551
1263static int dib7000p_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune) 1552static int dib7000p_fe_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings *tune)
1264{ 1553{
1265 tune->min_delay_ms = 1000; 1554 tune->min_delay_ms = 1000;
1266 return 0; 1555 return 0;
@@ -1270,16 +1559,30 @@ static void dib7000p_release(struct dvb_frontend *demod)
1270{ 1559{
1271 struct dib7000p_state *st = demod->demodulator_priv; 1560 struct dib7000p_state *st = demod->demodulator_priv;
1272 dibx000_exit_i2c_master(&st->i2c_master); 1561 dibx000_exit_i2c_master(&st->i2c_master);
1562 i2c_del_adapter(&st->dib7090_tuner_adap);
1273 kfree(st); 1563 kfree(st);
1274} 1564}
1275 1565
1276int dib7000pc_detection(struct i2c_adapter *i2c_adap) 1566int dib7000pc_detection(struct i2c_adapter *i2c_adap)
1277{ 1567{
1278 u8 tx[2], rx[2]; 1568 u8 *tx, *rx;
1279 struct i2c_msg msg[2] = { 1569 struct i2c_msg msg[2] = {
1280 { .addr = 18 >> 1, .flags = 0, .buf = tx, .len = 2 }, 1570 {.addr = 18 >> 1, .flags = 0, .len = 2},
1281 { .addr = 18 >> 1, .flags = I2C_M_RD, .buf = rx, .len = 2 }, 1571 {.addr = 18 >> 1, .flags = I2C_M_RD, .len = 2},
1282 }; 1572 };
1573 int ret = 0;
1574
1575 tx = kzalloc(2*sizeof(u8), GFP_KERNEL);
1576 if (!tx)
1577 return -ENOMEM;
1578 rx = kzalloc(2*sizeof(u8), GFP_KERNEL);
1579 if (!rx) {
1580 goto rx_memory_error;
1581 ret = -ENOMEM;
1582 }
1583
1584 msg[0].buf = tx;
1585 msg[1].buf = rx;
1283 1586
1284 tx[0] = 0x03; 1587 tx[0] = 0x03;
1285 tx[1] = 0x00; 1588 tx[1] = 0x00;
@@ -1299,11 +1602,15 @@ int dib7000pc_detection(struct i2c_adapter *i2c_adap)
1299 } 1602 }
1300 1603
1301 dprintk("-D- DiB7000PC not detected"); 1604 dprintk("-D- DiB7000PC not detected");
1302 return 0; 1605
1606 kfree(rx);
1607rx_memory_error:
1608 kfree(tx);
1609 return ret;
1303} 1610}
1304EXPORT_SYMBOL(dib7000pc_detection); 1611EXPORT_SYMBOL(dib7000pc_detection);
1305 1612
1306struct i2c_adapter * dib7000p_get_i2c_master(struct dvb_frontend *demod, enum dibx000_i2c_interface intf, int gating) 1613struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *demod, enum dibx000_i2c_interface intf, int gating)
1307{ 1614{
1308 struct dib7000p_state *st = demod->demodulator_priv; 1615 struct dib7000p_state *st = demod->demodulator_priv;
1309 return dibx000_get_i2c_adapter(&st->i2c_master, intf, gating); 1616 return dibx000_get_i2c_adapter(&st->i2c_master, intf, gating);
@@ -1312,19 +1619,19 @@ EXPORT_SYMBOL(dib7000p_get_i2c_master);
1312 1619
1313int dib7000p_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff) 1620int dib7000p_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff)
1314{ 1621{
1315 struct dib7000p_state *state = fe->demodulator_priv; 1622 struct dib7000p_state *state = fe->demodulator_priv;
1316 u16 val = dib7000p_read_word(state, 235) & 0xffef; 1623 u16 val = dib7000p_read_word(state, 235) & 0xffef;
1317 val |= (onoff & 0x1) << 4; 1624 val |= (onoff & 0x1) << 4;
1318 dprintk("PID filter enabled %d", onoff); 1625 dprintk("PID filter enabled %d", onoff);
1319 return dib7000p_write_word(state, 235, val); 1626 return dib7000p_write_word(state, 235, val);
1320} 1627}
1321EXPORT_SYMBOL(dib7000p_pid_filter_ctrl); 1628EXPORT_SYMBOL(dib7000p_pid_filter_ctrl);
1322 1629
1323int dib7000p_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff) 1630int dib7000p_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff)
1324{ 1631{
1325 struct dib7000p_state *state = fe->demodulator_priv; 1632 struct dib7000p_state *state = fe->demodulator_priv;
1326 dprintk("PID filter: index %x, PID %d, OnOff %d", id, pid, onoff); 1633 dprintk("PID filter: index %x, PID %d, OnOff %d", id, pid, onoff);
1327 return dib7000p_write_word(state, 241 + id, onoff ? (1 << 13) | pid : 0); 1634 return dib7000p_write_word(state, 241 + id, onoff ? (1 << 13) | pid : 0);
1328} 1635}
1329EXPORT_SYMBOL(dib7000p_pid_filter); 1636EXPORT_SYMBOL(dib7000p_pid_filter);
1330 1637
@@ -1340,16 +1647,19 @@ int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 defau
1340 1647
1341 dpst->i2c_adap = i2c; 1648 dpst->i2c_adap = i2c;
1342 1649
1343 for (k = no_of_demods-1; k >= 0; k--) { 1650 for (k = no_of_demods - 1; k >= 0; k--) {
1344 dpst->cfg = cfg[k]; 1651 dpst->cfg = cfg[k];
1345 1652
1346 /* designated i2c address */ 1653 /* designated i2c address */
1347 new_addr = (0x40 + k) << 1; 1654 if (cfg[k].default_i2c_addr != 0)
1655 new_addr = cfg[k].default_i2c_addr + (k << 1);
1656 else
1657 new_addr = (0x40 + k) << 1;
1348 dpst->i2c_addr = new_addr; 1658 dpst->i2c_addr = new_addr;
1349 dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */ 1659 dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */
1350 if (dib7000p_identify(dpst) != 0) { 1660 if (dib7000p_identify(dpst) != 0) {
1351 dpst->i2c_addr = default_addr; 1661 dpst->i2c_addr = default_addr;
1352 dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */ 1662 dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */
1353 if (dib7000p_identify(dpst) != 0) { 1663 if (dib7000p_identify(dpst) != 0) {
1354 dprintk("DiB7000P #%d: not identified\n", k); 1664 dprintk("DiB7000P #%d: not identified\n", k);
1355 kfree(dpst); 1665 kfree(dpst);
@@ -1368,7 +1678,10 @@ int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 defau
1368 1678
1369 for (k = 0; k < no_of_demods; k++) { 1679 for (k = 0; k < no_of_demods; k++) {
1370 dpst->cfg = cfg[k]; 1680 dpst->cfg = cfg[k];
1371 dpst->i2c_addr = (0x40 + k) << 1; 1681 if (cfg[k].default_i2c_addr != 0)
1682 dpst->i2c_addr = (cfg[k].default_i2c_addr + k) << 1;
1683 else
1684 dpst->i2c_addr = (0x40 + k) << 1;
1372 1685
1373 // unforce divstr 1686 // unforce divstr
1374 dib7000p_write_word(dpst, 1285, dpst->i2c_addr << 2); 1687 dib7000p_write_word(dpst, 1285, dpst->i2c_addr << 2);
@@ -1382,8 +1695,613 @@ int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 defau
1382} 1695}
1383EXPORT_SYMBOL(dib7000p_i2c_enumeration); 1696EXPORT_SYMBOL(dib7000p_i2c_enumeration);
1384 1697
1698static const s32 lut_1000ln_mant[] = {
1699 6908, 6956, 7003, 7047, 7090, 7131, 7170, 7208, 7244, 7279, 7313, 7346, 7377, 7408, 7438, 7467, 7495, 7523, 7549, 7575, 7600
1700};
1701
1702static s32 dib7000p_get_adc_power(struct dvb_frontend *fe)
1703{
1704 struct dib7000p_state *state = fe->demodulator_priv;
1705 u32 tmp_val = 0, exp = 0, mant = 0;
1706 s32 pow_i;
1707 u16 buf[2];
1708 u8 ix = 0;
1709
1710 buf[0] = dib7000p_read_word(state, 0x184);
1711 buf[1] = dib7000p_read_word(state, 0x185);
1712 pow_i = (buf[0] << 16) | buf[1];
1713 dprintk("raw pow_i = %d", pow_i);
1714
1715 tmp_val = pow_i;
1716 while (tmp_val >>= 1)
1717 exp++;
1718
1719 mant = (pow_i * 1000 / (1 << exp));
1720 dprintk(" mant = %d exp = %d", mant / 1000, exp);
1721
1722 ix = (u8) ((mant - 1000) / 100); /* index of the LUT */
1723 dprintk(" ix = %d", ix);
1724
1725 pow_i = (lut_1000ln_mant[ix] + 693 * (exp - 20) - 6908);
1726 pow_i = (pow_i << 8) / 1000;
1727 dprintk(" pow_i = %d", pow_i);
1728
1729 return pow_i;
1730}
1731
1732static int map_addr_to_serpar_number(struct i2c_msg *msg)
1733{
1734 if ((msg->buf[0] <= 15))
1735 msg->buf[0] -= 1;
1736 else if (msg->buf[0] == 17)
1737 msg->buf[0] = 15;
1738 else if (msg->buf[0] == 16)
1739 msg->buf[0] = 17;
1740 else if (msg->buf[0] == 19)
1741 msg->buf[0] = 16;
1742 else if (msg->buf[0] >= 21 && msg->buf[0] <= 25)
1743 msg->buf[0] -= 3;
1744 else if (msg->buf[0] == 28)
1745 msg->buf[0] = 23;
1746 else
1747 return -EINVAL;
1748 return 0;
1749}
1750
1751static int w7090p_tuner_write_serpar(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
1752{
1753 struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
1754 u8 n_overflow = 1;
1755 u16 i = 1000;
1756 u16 serpar_num = msg[0].buf[0];
1757
1758 while (n_overflow == 1 && i) {
1759 n_overflow = (dib7000p_read_word(state, 1984) >> 1) & 0x1;
1760 i--;
1761 if (i == 0)
1762 dprintk("Tuner ITF: write busy (overflow)");
1763 }
1764 dib7000p_write_word(state, 1985, (1 << 6) | (serpar_num & 0x3f));
1765 dib7000p_write_word(state, 1986, (msg[0].buf[1] << 8) | msg[0].buf[2]);
1766
1767 return num;
1768}
1769
1770static int w7090p_tuner_read_serpar(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
1771{
1772 struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
1773 u8 n_overflow = 1, n_empty = 1;
1774 u16 i = 1000;
1775 u16 serpar_num = msg[0].buf[0];
1776 u16 read_word;
1777
1778 while (n_overflow == 1 && i) {
1779 n_overflow = (dib7000p_read_word(state, 1984) >> 1) & 0x1;
1780 i--;
1781 if (i == 0)
1782 dprintk("TunerITF: read busy (overflow)");
1783 }
1784 dib7000p_write_word(state, 1985, (0 << 6) | (serpar_num & 0x3f));
1785
1786 i = 1000;
1787 while (n_empty == 1 && i) {
1788 n_empty = dib7000p_read_word(state, 1984) & 0x1;
1789 i--;
1790 if (i == 0)
1791 dprintk("TunerITF: read busy (empty)");
1792 }
1793 read_word = dib7000p_read_word(state, 1987);
1794 msg[1].buf[0] = (read_word >> 8) & 0xff;
1795 msg[1].buf[1] = (read_word) & 0xff;
1796
1797 return num;
1798}
1799
1800static int w7090p_tuner_rw_serpar(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
1801{
1802 if (map_addr_to_serpar_number(&msg[0]) == 0) { /* else = Tuner regs to ignore : DIG_CFG, CTRL_RF_LT, PLL_CFG, PWM1_REG, ADCCLK, DIG_CFG_3; SLEEP_EN... */
1803 if (num == 1) { /* write */
1804 return w7090p_tuner_write_serpar(i2c_adap, msg, 1);
1805 } else { /* read */
1806 return w7090p_tuner_read_serpar(i2c_adap, msg, 2);
1807 }
1808 }
1809 return num;
1810}
1811
1812int dib7090p_rw_on_apb(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num, u16 apb_address)
1813{
1814 struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
1815 u16 word;
1816
1817 if (num == 1) { /* write */
1818 dib7000p_write_word(state, apb_address, ((msg[0].buf[1] << 8) | (msg[0].buf[2])));
1819 } else {
1820 word = dib7000p_read_word(state, apb_address);
1821 msg[1].buf[0] = (word >> 8) & 0xff;
1822 msg[1].buf[1] = (word) & 0xff;
1823 }
1824
1825 return num;
1826}
1827
1828static int dib7090_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
1829{
1830 struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
1831
1832 u16 apb_address = 0, word;
1833 int i = 0;
1834 switch (msg[0].buf[0]) {
1835 case 0x12:
1836 apb_address = 1920;
1837 break;
1838 case 0x14:
1839 apb_address = 1921;
1840 break;
1841 case 0x24:
1842 apb_address = 1922;
1843 break;
1844 case 0x1a:
1845 apb_address = 1923;
1846 break;
1847 case 0x22:
1848 apb_address = 1924;
1849 break;
1850 case 0x33:
1851 apb_address = 1926;
1852 break;
1853 case 0x34:
1854 apb_address = 1927;
1855 break;
1856 case 0x35:
1857 apb_address = 1928;
1858 break;
1859 case 0x36:
1860 apb_address = 1929;
1861 break;
1862 case 0x37:
1863 apb_address = 1930;
1864 break;
1865 case 0x38:
1866 apb_address = 1931;
1867 break;
1868 case 0x39:
1869 apb_address = 1932;
1870 break;
1871 case 0x2a:
1872 apb_address = 1935;
1873 break;
1874 case 0x2b:
1875 apb_address = 1936;
1876 break;
1877 case 0x2c:
1878 apb_address = 1937;
1879 break;
1880 case 0x2d:
1881 apb_address = 1938;
1882 break;
1883 case 0x2e:
1884 apb_address = 1939;
1885 break;
1886 case 0x2f:
1887 apb_address = 1940;
1888 break;
1889 case 0x30:
1890 apb_address = 1941;
1891 break;
1892 case 0x31:
1893 apb_address = 1942;
1894 break;
1895 case 0x32:
1896 apb_address = 1943;
1897 break;
1898 case 0x3e:
1899 apb_address = 1944;
1900 break;
1901 case 0x3f:
1902 apb_address = 1945;
1903 break;
1904 case 0x40:
1905 apb_address = 1948;
1906 break;
1907 case 0x25:
1908 apb_address = 914;
1909 break;
1910 case 0x26:
1911 apb_address = 915;
1912 break;
1913 case 0x27:
1914 apb_address = 916;
1915 break;
1916 case 0x28:
1917 apb_address = 917;
1918 break;
1919 case 0x1d:
1920 i = ((dib7000p_read_word(state, 72) >> 12) & 0x3);
1921 word = dib7000p_read_word(state, 384 + i);
1922 msg[1].buf[0] = (word >> 8) & 0xff;
1923 msg[1].buf[1] = (word) & 0xff;
1924 return num;
1925 case 0x1f:
1926 if (num == 1) { /* write */
1927 word = (u16) ((msg[0].buf[1] << 8) | msg[0].buf[2]);
1928 word &= 0x3;
1929 word = (dib7000p_read_word(state, 72) & ~(3 << 12)) | (word << 12);
1930 dib7000p_write_word(state, 72, word); /* Set the proper input */
1931 return num;
1932 }
1933 }
1934
1935 if (apb_address != 0) /* R/W acces via APB */
1936 return dib7090p_rw_on_apb(i2c_adap, msg, num, apb_address);
1937 else /* R/W access via SERPAR */
1938 return w7090p_tuner_rw_serpar(i2c_adap, msg, num);
1939
1940 return 0;
1941}
1942
1943static u32 dib7000p_i2c_func(struct i2c_adapter *adapter)
1944{
1945 return I2C_FUNC_I2C;
1946}
1947
1948static struct i2c_algorithm dib7090_tuner_xfer_algo = {
1949 .master_xfer = dib7090_tuner_xfer,
1950 .functionality = dib7000p_i2c_func,
1951};
1952
1953struct i2c_adapter *dib7090_get_i2c_tuner(struct dvb_frontend *fe)
1954{
1955 struct dib7000p_state *st = fe->demodulator_priv;
1956 return &st->dib7090_tuner_adap;
1957}
1958EXPORT_SYMBOL(dib7090_get_i2c_tuner);
1959
1960static int dib7090_host_bus_drive(struct dib7000p_state *state, u8 drive)
1961{
1962 u16 reg;
1963
1964 /* drive host bus 2, 3, 4 */
1965 reg = dib7000p_read_word(state, 1798) & ~((0x7) | (0x7 << 6) | (0x7 << 12));
1966 reg |= (drive << 12) | (drive << 6) | drive;
1967 dib7000p_write_word(state, 1798, reg);
1968
1969 /* drive host bus 5,6 */
1970 reg = dib7000p_read_word(state, 1799) & ~((0x7 << 2) | (0x7 << 8));
1971 reg |= (drive << 8) | (drive << 2);
1972 dib7000p_write_word(state, 1799, reg);
1973
1974 /* drive host bus 7, 8, 9 */
1975 reg = dib7000p_read_word(state, 1800) & ~((0x7) | (0x7 << 6) | (0x7 << 12));
1976 reg |= (drive << 12) | (drive << 6) | drive;
1977 dib7000p_write_word(state, 1800, reg);
1978
1979 /* drive host bus 10, 11 */
1980 reg = dib7000p_read_word(state, 1801) & ~((0x7 << 2) | (0x7 << 8));
1981 reg |= (drive << 8) | (drive << 2);
1982 dib7000p_write_word(state, 1801, reg);
1983
1984 /* drive host bus 12, 13, 14 */
1985 reg = dib7000p_read_word(state, 1802) & ~((0x7) | (0x7 << 6) | (0x7 << 12));
1986 reg |= (drive << 12) | (drive << 6) | drive;
1987 dib7000p_write_word(state, 1802, reg);
1988
1989 return 0;
1990}
1991
1992static u32 dib7090_calcSyncFreq(u32 P_Kin, u32 P_Kout, u32 insertExtSynchro, u32 syncSize)
1993{
1994 u32 quantif = 3;
1995 u32 nom = (insertExtSynchro * P_Kin + syncSize);
1996 u32 denom = P_Kout;
1997 u32 syncFreq = ((nom << quantif) / denom);
1998
1999 if ((syncFreq & ((1 << quantif) - 1)) != 0)
2000 syncFreq = (syncFreq >> quantif) + 1;
2001 else
2002 syncFreq = (syncFreq >> quantif);
2003
2004 if (syncFreq != 0)
2005 syncFreq = syncFreq - 1;
2006
2007 return syncFreq;
2008}
2009
2010static int dib7090_cfg_DibTx(struct dib7000p_state *state, u32 P_Kin, u32 P_Kout, u32 insertExtSynchro, u32 synchroMode, u32 syncWord, u32 syncSize)
2011{
2012 u8 index_buf;
2013 u16 rx_copy_buf[22];
2014
2015 dprintk("Configure DibStream Tx");
2016 for (index_buf = 0; index_buf < 22; index_buf++)
2017 rx_copy_buf[index_buf] = dib7000p_read_word(state, 1536+index_buf);
2018
2019 dib7000p_write_word(state, 1615, 1);
2020 dib7000p_write_word(state, 1603, P_Kin);
2021 dib7000p_write_word(state, 1605, P_Kout);
2022 dib7000p_write_word(state, 1606, insertExtSynchro);
2023 dib7000p_write_word(state, 1608, synchroMode);
2024 dib7000p_write_word(state, 1609, (syncWord >> 16) & 0xffff);
2025 dib7000p_write_word(state, 1610, syncWord & 0xffff);
2026 dib7000p_write_word(state, 1612, syncSize);
2027 dib7000p_write_word(state, 1615, 0);
2028
2029 for (index_buf = 0; index_buf < 22; index_buf++)
2030 dib7000p_write_word(state, 1536+index_buf, rx_copy_buf[index_buf]);
2031
2032 return 0;
2033}
2034
2035static int dib7090_cfg_DibRx(struct dib7000p_state *state, u32 P_Kin, u32 P_Kout, u32 synchroMode, u32 insertExtSynchro, u32 syncWord, u32 syncSize,
2036 u32 dataOutRate)
2037{
2038 u32 syncFreq;
2039
2040 dprintk("Configure DibStream Rx");
2041 if ((P_Kin != 0) && (P_Kout != 0)) {
2042 syncFreq = dib7090_calcSyncFreq(P_Kin, P_Kout, insertExtSynchro, syncSize);
2043 dib7000p_write_word(state, 1542, syncFreq);
2044 }
2045 dib7000p_write_word(state, 1554, 1);
2046 dib7000p_write_word(state, 1536, P_Kin);
2047 dib7000p_write_word(state, 1537, P_Kout);
2048 dib7000p_write_word(state, 1539, synchroMode);
2049 dib7000p_write_word(state, 1540, (syncWord >> 16) & 0xffff);
2050 dib7000p_write_word(state, 1541, syncWord & 0xffff);
2051 dib7000p_write_word(state, 1543, syncSize);
2052 dib7000p_write_word(state, 1544, dataOutRate);
2053 dib7000p_write_word(state, 1554, 0);
2054
2055 return 0;
2056}
2057
2058static int dib7090_enDivOnHostBus(struct dib7000p_state *state)
2059{
2060 u16 reg;
2061
2062 dprintk("Enable Diversity on host bus");
2063 reg = (1 << 8) | (1 << 5);
2064 dib7000p_write_word(state, 1288, reg);
2065
2066 return dib7090_cfg_DibTx(state, 5, 5, 0, 0, 0, 0);
2067}
2068
2069static int dib7090_enAdcOnHostBus(struct dib7000p_state *state)
2070{
2071 u16 reg;
2072
2073 dprintk("Enable ADC on host bus");
2074 reg = (1 << 7) | (1 << 5);
2075 dib7000p_write_word(state, 1288, reg);
2076
2077 return dib7090_cfg_DibTx(state, 20, 5, 10, 0, 0, 0);
2078}
2079
2080static int dib7090_enMpegOnHostBus(struct dib7000p_state *state)
2081{
2082 u16 reg;
2083
2084 dprintk("Enable Mpeg on host bus");
2085 reg = (1 << 9) | (1 << 5);
2086 dib7000p_write_word(state, 1288, reg);
2087
2088 return dib7090_cfg_DibTx(state, 8, 5, 0, 0, 0, 0);
2089}
2090
2091static int dib7090_enMpegInput(struct dib7000p_state *state)
2092{
2093 dprintk("Enable Mpeg input");
2094 return dib7090_cfg_DibRx(state, 8, 5, 0, 0, 0, 8, 0); /*outputRate = 8 */
2095}
2096
2097static int dib7090_enMpegMux(struct dib7000p_state *state, u16 pulseWidth, u16 enSerialMode, u16 enSerialClkDiv2)
2098{
2099 u16 reg = (1 << 7) | ((pulseWidth & 0x1f) << 2) | ((enSerialMode & 0x1) << 1) | (enSerialClkDiv2 & 0x1);
2100
2101 dprintk("Enable Mpeg mux");
2102 dib7000p_write_word(state, 1287, reg);
2103
2104 reg &= ~(1 << 7);
2105 dib7000p_write_word(state, 1287, reg);
2106
2107 reg = (1 << 4);
2108 dib7000p_write_word(state, 1288, reg);
2109
2110 return 0;
2111}
2112
2113static int dib7090_disableMpegMux(struct dib7000p_state *state)
2114{
2115 u16 reg;
2116
2117 dprintk("Disable Mpeg mux");
2118 dib7000p_write_word(state, 1288, 0);
2119
2120 reg = dib7000p_read_word(state, 1287);
2121 reg &= ~(1 << 7);
2122 dib7000p_write_word(state, 1287, reg);
2123
2124 return 0;
2125}
2126
2127static int dib7090_set_input_mode(struct dvb_frontend *fe, int mode)
2128{
2129 struct dib7000p_state *state = fe->demodulator_priv;
2130
2131 switch (mode) {
2132 case INPUT_MODE_DIVERSITY:
2133 dprintk("Enable diversity INPUT");
2134 dib7090_cfg_DibRx(state, 5, 5, 0, 0, 0, 0, 0);
2135 break;
2136 case INPUT_MODE_MPEG:
2137 dprintk("Enable Mpeg INPUT");
2138 dib7090_cfg_DibRx(state, 8, 5, 0, 0, 0, 8, 0); /*outputRate = 8 */
2139 break;
2140 case INPUT_MODE_OFF:
2141 default:
2142 dprintk("Disable INPUT");
2143 dib7090_cfg_DibRx(state, 0, 0, 0, 0, 0, 0, 0);
2144 break;
2145 }
2146 return 0;
2147}
2148
2149static int dib7090_set_diversity_in(struct dvb_frontend *fe, int onoff)
2150{
2151 switch (onoff) {
2152 case 0: /* only use the internal way - not the diversity input */
2153 dib7090_set_input_mode(fe, INPUT_MODE_MPEG);
2154 break;
2155 case 1: /* both ways */
2156 case 2: /* only the diversity input */
2157 dib7090_set_input_mode(fe, INPUT_MODE_DIVERSITY);
2158 break;
2159 }
2160
2161 return 0;
2162}
2163
2164static int dib7090_set_output_mode(struct dvb_frontend *fe, int mode)
2165{
2166 struct dib7000p_state *state = fe->demodulator_priv;
2167
2168 u16 outreg, smo_mode, fifo_threshold;
2169 u8 prefer_mpeg_mux_use = 1;
2170 int ret = 0;
2171
2172 dib7090_host_bus_drive(state, 1);
2173
2174 fifo_threshold = 1792;
2175 smo_mode = (dib7000p_read_word(state, 235) & 0x0050) | (1 << 1);
2176 outreg = dib7000p_read_word(state, 1286) & ~((1 << 10) | (0x7 << 6) | (1 << 1));
2177
2178 switch (mode) {
2179 case OUTMODE_HIGH_Z:
2180 outreg = 0;
2181 break;
2182
2183 case OUTMODE_MPEG2_SERIAL:
2184 if (prefer_mpeg_mux_use) {
2185 dprintk("Sip 7090P setting output mode TS_SERIAL using Mpeg Mux");
2186 dib7090_enMpegOnHostBus(state);
2187 dib7090_enMpegInput(state);
2188 if (state->cfg.enMpegOutput == 1)
2189 dib7090_enMpegMux(state, 3, 1, 1);
2190
2191 } else { /* Use Smooth block */
2192 dprintk("Sip 7090P setting output mode TS_SERIAL using Smooth bloc");
2193 dib7090_disableMpegMux(state);
2194 dib7000p_write_word(state, 1288, (1 << 6));
2195 outreg |= (2 << 6) | (0 << 1);
2196 }
2197 break;
2198
2199 case OUTMODE_MPEG2_PAR_GATED_CLK:
2200 if (prefer_mpeg_mux_use) {
2201 dprintk("Sip 7090P setting output mode TS_PARALLEL_GATED using Mpeg Mux");
2202 dib7090_enMpegOnHostBus(state);
2203 dib7090_enMpegInput(state);
2204 if (state->cfg.enMpegOutput == 1)
2205 dib7090_enMpegMux(state, 2, 0, 0);
2206 } else { /* Use Smooth block */
2207 dprintk("Sip 7090P setting output mode TS_PARALLEL_GATED using Smooth block");
2208 dib7090_disableMpegMux(state);
2209 dib7000p_write_word(state, 1288, (1 << 6));
2210 outreg |= (0 << 6);
2211 }
2212 break;
2213
2214 case OUTMODE_MPEG2_PAR_CONT_CLK: /* Using Smooth block only */
2215 dprintk("Sip 7090P setting output mode TS_PARALLEL_CONT using Smooth block");
2216 dib7090_disableMpegMux(state);
2217 dib7000p_write_word(state, 1288, (1 << 6));
2218 outreg |= (1 << 6);
2219 break;
2220
2221 case OUTMODE_MPEG2_FIFO: /* Using Smooth block because not supported by new Mpeg Mux bloc */
2222 dprintk("Sip 7090P setting output mode TS_FIFO using Smooth block");
2223 dib7090_disableMpegMux(state);
2224 dib7000p_write_word(state, 1288, (1 << 6));
2225 outreg |= (5 << 6);
2226 smo_mode |= (3 << 1);
2227 fifo_threshold = 512;
2228 break;
2229
2230 case OUTMODE_DIVERSITY:
2231 dprintk("Sip 7090P setting output mode MODE_DIVERSITY");
2232 dib7090_disableMpegMux(state);
2233 dib7090_enDivOnHostBus(state);
2234 break;
2235
2236 case OUTMODE_ANALOG_ADC:
2237 dprintk("Sip 7090P setting output mode MODE_ANALOG_ADC");
2238 dib7090_enAdcOnHostBus(state);
2239 break;
2240 }
2241
2242 if (state->cfg.output_mpeg2_in_188_bytes)
2243 smo_mode |= (1 << 5);
2244
2245 ret |= dib7000p_write_word(state, 235, smo_mode);
2246 ret |= dib7000p_write_word(state, 236, fifo_threshold); /* synchronous fread */
2247 ret |= dib7000p_write_word(state, 1286, outreg | (1 << 10)); /* allways set Dout active = 1 !!! */
2248
2249 return ret;
2250}
2251
2252int dib7090_tuner_sleep(struct dvb_frontend *fe, int onoff)
2253{
2254 struct dib7000p_state *state = fe->demodulator_priv;
2255 u16 en_cur_state;
2256
2257 dprintk("sleep dib7090: %d", onoff);
2258
2259 en_cur_state = dib7000p_read_word(state, 1922);
2260
2261 if (en_cur_state > 0xff)
2262 state->tuner_enable = en_cur_state;
2263
2264 if (onoff)
2265 en_cur_state &= 0x00ff;
2266 else {
2267 if (state->tuner_enable != 0)
2268 en_cur_state = state->tuner_enable;
2269 }
2270
2271 dib7000p_write_word(state, 1922, en_cur_state);
2272
2273 return 0;
2274}
2275EXPORT_SYMBOL(dib7090_tuner_sleep);
2276
2277int dib7090_agc_restart(struct dvb_frontend *fe, u8 restart)
2278{
2279 dprintk("AGC restart callback: %d", restart);
2280 return 0;
2281}
2282EXPORT_SYMBOL(dib7090_agc_restart);
2283
2284int dib7090_get_adc_power(struct dvb_frontend *fe)
2285{
2286 return dib7000p_get_adc_power(fe);
2287}
2288EXPORT_SYMBOL(dib7090_get_adc_power);
2289
2290int dib7090_slave_reset(struct dvb_frontend *fe)
2291{
2292 struct dib7000p_state *state = fe->demodulator_priv;
2293 u16 reg;
2294
2295 reg = dib7000p_read_word(state, 1794);
2296 dib7000p_write_word(state, 1794, reg | (4 << 12));
2297
2298 dib7000p_write_word(state, 1032, 0xffff);
2299 return 0;
2300}
2301EXPORT_SYMBOL(dib7090_slave_reset);
2302
1385static struct dvb_frontend_ops dib7000p_ops; 2303static struct dvb_frontend_ops dib7000p_ops;
1386struct dvb_frontend * dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg) 2304struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg)
1387{ 2305{
1388 struct dvb_frontend *demod; 2306 struct dvb_frontend *demod;
1389 struct dib7000p_state *st; 2307 struct dib7000p_state *st;
@@ -1400,28 +2318,41 @@ struct dvb_frontend * dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr,
1400 /* Ensure the output mode remains at the previous default if it's 2318 /* Ensure the output mode remains at the previous default if it's
1401 * not specifically set by the caller. 2319 * not specifically set by the caller.
1402 */ 2320 */
1403 if ((st->cfg.output_mode != OUTMODE_MPEG2_SERIAL) && 2321 if ((st->cfg.output_mode != OUTMODE_MPEG2_SERIAL) && (st->cfg.output_mode != OUTMODE_MPEG2_PAR_GATED_CLK))
1404 (st->cfg.output_mode != OUTMODE_MPEG2_PAR_GATED_CLK))
1405 st->cfg.output_mode = OUTMODE_MPEG2_FIFO; 2322 st->cfg.output_mode = OUTMODE_MPEG2_FIFO;
1406 2323
1407 demod = &st->demod; 2324 demod = &st->demod;
1408 demod->demodulator_priv = st; 2325 demod->demodulator_priv = st;
1409 memcpy(&st->demod.ops, &dib7000p_ops, sizeof(struct dvb_frontend_ops)); 2326 memcpy(&st->demod.ops, &dib7000p_ops, sizeof(struct dvb_frontend_ops));
1410 2327
1411 dib7000p_write_word(st, 1287, 0x0003); /* sram lead in, rdy */ 2328 dib7000p_write_word(st, 1287, 0x0003); /* sram lead in, rdy */
1412 2329
1413 if (dib7000p_identify(st) != 0) 2330 if (dib7000p_identify(st) != 0)
1414 goto error; 2331 goto error;
1415 2332
2333 st->version = dib7000p_read_word(st, 897);
2334
1416 /* FIXME: make sure the dev.parent field is initialized, or else 2335 /* FIXME: make sure the dev.parent field is initialized, or else
1417 request_firmware() will hit an OOPS (this should be moved somewhere 2336 request_firmware() will hit an OOPS (this should be moved somewhere
1418 more common) */ 2337 more common) */
1419 st->i2c_master.gated_tuner_i2c_adap.dev.parent = i2c_adap->dev.parent;
1420 2338
1421 dibx000_init_i2c_master(&st->i2c_master, DIB7000P, st->i2c_adap, st->i2c_addr); 2339 dibx000_init_i2c_master(&st->i2c_master, DIB7000P, st->i2c_adap, st->i2c_addr);
1422 2340
2341 /* init 7090 tuner adapter */
2342 strncpy(st->dib7090_tuner_adap.name, "DiB7090 tuner interface", sizeof(st->dib7090_tuner_adap.name));
2343 st->dib7090_tuner_adap.algo = &dib7090_tuner_xfer_algo;
2344 st->dib7090_tuner_adap.algo_data = NULL;
2345 st->dib7090_tuner_adap.dev.parent = st->i2c_adap->dev.parent;
2346 i2c_set_adapdata(&st->dib7090_tuner_adap, st);
2347 i2c_add_adapter(&st->dib7090_tuner_adap);
2348
1423 dib7000p_demod_reset(st); 2349 dib7000p_demod_reset(st);
1424 2350
2351 if (st->version == SOC7090) {
2352 dib7090_set_output_mode(demod, st->cfg.output_mode);
2353 dib7090_set_diversity_in(demod, 0);
2354 }
2355
1425 return demod; 2356 return demod;
1426 2357
1427error: 2358error:
@@ -1432,37 +2363,35 @@ EXPORT_SYMBOL(dib7000p_attach);
1432 2363
1433static struct dvb_frontend_ops dib7000p_ops = { 2364static struct dvb_frontend_ops dib7000p_ops = {
1434 .info = { 2365 .info = {
1435 .name = "DiBcom 7000PC", 2366 .name = "DiBcom 7000PC",
1436 .type = FE_OFDM, 2367 .type = FE_OFDM,
1437 .frequency_min = 44250000, 2368 .frequency_min = 44250000,
1438 .frequency_max = 867250000, 2369 .frequency_max = 867250000,
1439 .frequency_stepsize = 62500, 2370 .frequency_stepsize = 62500,
1440 .caps = FE_CAN_INVERSION_AUTO | 2371 .caps = FE_CAN_INVERSION_AUTO |
1441 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | 2372 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
1442 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | 2373 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
1443 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | 2374 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
1444 FE_CAN_TRANSMISSION_MODE_AUTO | 2375 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_RECOVER | FE_CAN_HIERARCHY_AUTO,
1445 FE_CAN_GUARD_INTERVAL_AUTO | 2376 },
1446 FE_CAN_RECOVER | 2377
1447 FE_CAN_HIERARCHY_AUTO, 2378 .release = dib7000p_release,
1448 }, 2379
1449 2380 .init = dib7000p_wakeup,
1450 .release = dib7000p_release, 2381 .sleep = dib7000p_sleep,
1451 2382
1452 .init = dib7000p_wakeup, 2383 .set_frontend = dib7000p_set_frontend,
1453 .sleep = dib7000p_sleep, 2384 .get_tune_settings = dib7000p_fe_get_tune_settings,
1454 2385 .get_frontend = dib7000p_get_frontend,
1455 .set_frontend = dib7000p_set_frontend, 2386
1456 .get_tune_settings = dib7000p_fe_get_tune_settings, 2387 .read_status = dib7000p_read_status,
1457 .get_frontend = dib7000p_get_frontend, 2388 .read_ber = dib7000p_read_ber,
1458
1459 .read_status = dib7000p_read_status,
1460 .read_ber = dib7000p_read_ber,
1461 .read_signal_strength = dib7000p_read_signal_strength, 2389 .read_signal_strength = dib7000p_read_signal_strength,
1462 .read_snr = dib7000p_read_snr, 2390 .read_snr = dib7000p_read_snr,
1463 .read_ucblocks = dib7000p_read_unc_blocks, 2391 .read_ucblocks = dib7000p_read_unc_blocks,
1464}; 2392};
1465 2393
2394MODULE_AUTHOR("Olivier Grenie <ogrenie@dibcom.fr>");
1466MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>"); 2395MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>");
1467MODULE_DESCRIPTION("Driver for the DiBcom 7000PC COFDM demodulator"); 2396MODULE_DESCRIPTION("Driver for the DiBcom 7000PC COFDM demodulator");
1468MODULE_LICENSE("GPL"); 2397MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/dib7000p.h b/drivers/media/dvb/frontends/dib7000p.h
index da17345bf5bd..0179f9474bac 100644
--- a/drivers/media/dvb/frontends/dib7000p.h
+++ b/drivers/media/dvb/frontends/dib7000p.h
@@ -33,59 +33,54 @@ struct dib7000p_config {
33 int (*agc_control) (struct dvb_frontend *, u8 before); 33 int (*agc_control) (struct dvb_frontend *, u8 before);
34 34
35 u8 output_mode; 35 u8 output_mode;
36 u8 disable_sample_and_hold : 1; 36 u8 disable_sample_and_hold:1;
37 37
38 u8 enable_current_mirror : 1; 38 u8 enable_current_mirror:1;
39 u8 diversity_delay; 39 u16 diversity_delay;
40 40
41 u8 default_i2c_addr;
42 u8 enMpegOutput:1;
41}; 43};
42 44
43#define DEFAULT_DIB7000P_I2C_ADDRESS 18 45#define DEFAULT_DIB7000P_I2C_ADDRESS 18
44 46
45#if defined(CONFIG_DVB_DIB7000P) || (defined(CONFIG_DVB_DIB7000P_MODULE) && \ 47#if defined(CONFIG_DVB_DIB7000P) || (defined(CONFIG_DVB_DIB7000P_MODULE) && \
46 defined(MODULE)) 48 defined(MODULE))
47extern struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, 49extern struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
48 u8 i2c_addr, 50extern struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int);
49 struct dib7000p_config *cfg); 51extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[]);
50extern struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *,
51 enum dibx000_i2c_interface,
52 int);
53extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c,
54 int no_of_demods, u8 default_addr,
55 struct dib7000p_config cfg[]);
56extern int dib7000p_set_gpio(struct dvb_frontend *, u8 num, u8 dir, u8 val); 52extern int dib7000p_set_gpio(struct dvb_frontend *, u8 num, u8 dir, u8 val);
57extern int dib7000p_set_wbd_ref(struct dvb_frontend *, u16 value); 53extern int dib7000p_set_wbd_ref(struct dvb_frontend *, u16 value);
58extern int dib7000pc_detection(struct i2c_adapter *i2c_adap); 54extern int dib7000pc_detection(struct i2c_adapter *i2c_adap);
59extern int dib7000p_pid_filter(struct dvb_frontend *, u8 id, u16 pid, u8 onoff); 55extern int dib7000p_pid_filter(struct dvb_frontend *, u8 id, u16 pid, u8 onoff);
60extern int dib7000p_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff); 56extern int dib7000p_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff);
57extern int dib7000p_update_pll(struct dvb_frontend *fe, struct dibx000_bandwidth_config *bw);
58extern u32 dib7000p_ctrl_timf(struct dvb_frontend *fe, u8 op, u32 timf);
59extern int dib7090_agc_restart(struct dvb_frontend *fe, u8 restart);
60extern int dib7090_tuner_sleep(struct dvb_frontend *fe, int onoff);
61extern int dib7090_get_adc_power(struct dvb_frontend *fe);
62extern struct i2c_adapter *dib7090_get_i2c_tuner(struct dvb_frontend *fe);
63extern int dib7090_slave_reset(struct dvb_frontend *fe);
61#else 64#else
62static inline 65static inline struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg)
63struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr,
64 struct dib7000p_config *cfg)
65{ 66{
66 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 67 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
67 return NULL; 68 return NULL;
68} 69}
69 70
70static inline 71static inline struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *fe, enum dibx000_i2c_interface i, int x)
71struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *fe,
72 enum dibx000_i2c_interface i,
73 int x)
74{ 72{
75 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 73 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
76 return NULL; 74 return NULL;
77} 75}
78 76
79static inline int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, 77static inline int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[])
80 int no_of_demods, u8 default_addr,
81 struct dib7000p_config cfg[])
82{ 78{
83 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 79 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
84 return -ENODEV; 80 return -ENODEV;
85} 81}
86 82
87static inline int dib7000p_set_gpio(struct dvb_frontend *fe, 83static inline int dib7000p_set_gpio(struct dvb_frontend *fe, u8 num, u8 dir, u8 val)
88 u8 num, u8 dir, u8 val)
89{ 84{
90 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 85 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
91 return -ENODEV; 86 return -ENODEV;
@@ -102,16 +97,59 @@ static inline int dib7000pc_detection(struct i2c_adapter *i2c_adap)
102 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 97 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
103 return -ENODEV; 98 return -ENODEV;
104} 99}
100
105static inline int dib7000p_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff) 101static inline int dib7000p_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff)
106{ 102{
107 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 103 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
108 return -ENODEV; 104 return -ENODEV;
109} 105}
110 106
111static inline int dib7000p_pid_filter_ctrl(struct dvb_frontend *fe, uint8_t onoff) 107static inline int dib7000p_pid_filter_ctrl(struct dvb_frontend *fe, uint8_t onoff)
112{ 108{
113 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 109 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
114 return -ENODEV; 110 return -ENODEV;
111}
112
113static inline int dib7000p_update_pll(struct dvb_frontend *fe, struct dibx000_bandwidth_config *bw)
114{
115 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
116 return -ENODEV;
117}
118
119static inline u32 dib7000p_ctrl_timf(struct dvb_frontend *fe, u8 op, u32 timf)
120{
121 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
122 return 0;
123}
124
125static inline int dib7090_agc_restart(struct dvb_frontend *fe, u8 restart)
126{
127 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
128 return -ENODEV;
129}
130
131static inline int dib7090_tuner_sleep(struct dvb_frontend *fe, int onoff)
132{
133 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
134 return -ENODEV;
135}
136
137static inline int dib7090_get_adc_power(struct dvb_frontend *fe)
138{
139 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
140 return -ENODEV;
141}
142
143static inline struct i2c_adapter *dib7090_get_i2c_tuner(struct dvb_frontend *fe)
144{
145 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
146 return NULL;
147}
148
149static inline int dib7090_slave_reset(struct dvb_frontend *fe)
150{
151 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
152 return -ENODEV;
115} 153}
116#endif 154#endif
117 155
diff --git a/drivers/media/dvb/frontends/dib8000.c b/drivers/media/dvb/frontends/dib8000.c
index df17b91b3250..7d2ea112ae2b 100644
--- a/drivers/media/dvb/frontends/dib8000.c
+++ b/drivers/media/dvb/frontends/dib8000.c
@@ -22,6 +22,7 @@
22#define LAYER_C 3 22#define LAYER_C 3
23 23
24#define FE_CALLBACK_TIME_NEVER 0xffffffff 24#define FE_CALLBACK_TIME_NEVER 0xffffffff
25#define MAX_NUMBER_OF_FRONTENDS 6
25 26
26static int debug; 27static int debug;
27module_param(debug, int, 0644); 28module_param(debug, int, 0644);
@@ -34,10 +35,11 @@ MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
34struct i2c_device { 35struct i2c_device {
35 struct i2c_adapter *adap; 36 struct i2c_adapter *adap;
36 u8 addr; 37 u8 addr;
38 u8 *i2c_write_buffer;
39 u8 *i2c_read_buffer;
37}; 40};
38 41
39struct dib8000_state { 42struct dib8000_state {
40 struct dvb_frontend fe;
41 struct dib8000_config cfg; 43 struct dib8000_config cfg;
42 44
43 struct i2c_device i2c; 45 struct i2c_device i2c;
@@ -68,6 +70,13 @@ struct dib8000_state {
68 u8 isdbt_cfg_loaded; 70 u8 isdbt_cfg_loaded;
69 enum frontend_tune_state tune_state; 71 enum frontend_tune_state tune_state;
70 u32 status; 72 u32 status;
73
74 struct dvb_frontend *fe[MAX_NUMBER_OF_FRONTENDS];
75
76 /* for the I2C transfer */
77 struct i2c_msg msg[2];
78 u8 i2c_write_buffer[4];
79 u8 i2c_read_buffer[2];
71}; 80};
72 81
73enum dib8000_power_mode { 82enum dib8000_power_mode {
@@ -77,22 +86,41 @@ enum dib8000_power_mode {
77 86
78static u16 dib8000_i2c_read16(struct i2c_device *i2c, u16 reg) 87static u16 dib8000_i2c_read16(struct i2c_device *i2c, u16 reg)
79{ 88{
80 u8 wb[2] = { reg >> 8, reg & 0xff };
81 u8 rb[2];
82 struct i2c_msg msg[2] = { 89 struct i2c_msg msg[2] = {
83 {.addr = i2c->addr >> 1,.flags = 0,.buf = wb,.len = 2}, 90 {.addr = i2c->addr >> 1, .flags = 0,
84 {.addr = i2c->addr >> 1,.flags = I2C_M_RD,.buf = rb,.len = 2}, 91 .buf = i2c->i2c_write_buffer, .len = 2},
92 {.addr = i2c->addr >> 1, .flags = I2C_M_RD,
93 .buf = i2c->i2c_read_buffer, .len = 2},
85 }; 94 };
86 95
96 msg[0].buf[0] = reg >> 8;
97 msg[0].buf[1] = reg & 0xff;
98
87 if (i2c_transfer(i2c->adap, msg, 2) != 2) 99 if (i2c_transfer(i2c->adap, msg, 2) != 2)
88 dprintk("i2c read error on %d", reg); 100 dprintk("i2c read error on %d", reg);
89 101
90 return (rb[0] << 8) | rb[1]; 102 return (msg[1].buf[0] << 8) | msg[1].buf[1];
91} 103}
92 104
93static u16 dib8000_read_word(struct dib8000_state *state, u16 reg) 105static u16 dib8000_read_word(struct dib8000_state *state, u16 reg)
94{ 106{
95 return dib8000_i2c_read16(&state->i2c, reg); 107 state->i2c_write_buffer[0] = reg >> 8;
108 state->i2c_write_buffer[1] = reg & 0xff;
109
110 memset(state->msg, 0, 2 * sizeof(struct i2c_msg));
111 state->msg[0].addr = state->i2c.addr >> 1;
112 state->msg[0].flags = 0;
113 state->msg[0].buf = state->i2c_write_buffer;
114 state->msg[0].len = 2;
115 state->msg[1].addr = state->i2c.addr >> 1;
116 state->msg[1].flags = I2C_M_RD;
117 state->msg[1].buf = state->i2c_read_buffer;
118 state->msg[1].len = 2;
119
120 if (i2c_transfer(state->i2c.adap, state->msg, 2) != 2)
121 dprintk("i2c read error on %d", reg);
122
123 return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
96} 124}
97 125
98static u32 dib8000_read32(struct dib8000_state *state, u16 reg) 126static u32 dib8000_read32(struct dib8000_state *state, u16 reg)
@@ -107,126 +135,141 @@ static u32 dib8000_read32(struct dib8000_state *state, u16 reg)
107 135
108static int dib8000_i2c_write16(struct i2c_device *i2c, u16 reg, u16 val) 136static int dib8000_i2c_write16(struct i2c_device *i2c, u16 reg, u16 val)
109{ 137{
110 u8 b[4] = { 138 struct i2c_msg msg = {.addr = i2c->addr >> 1, .flags = 0,
111 (reg >> 8) & 0xff, reg & 0xff, 139 .buf = i2c->i2c_write_buffer, .len = 4};
112 (val >> 8) & 0xff, val & 0xff, 140 int ret = 0;
113 }; 141
114 struct i2c_msg msg = { 142 msg.buf[0] = (reg >> 8) & 0xff;
115 .addr = i2c->addr >> 1,.flags = 0,.buf = b,.len = 4 143 msg.buf[1] = reg & 0xff;
116 }; 144 msg.buf[2] = (val >> 8) & 0xff;
117 return i2c_transfer(i2c->adap, &msg, 1) != 1 ? -EREMOTEIO : 0; 145 msg.buf[3] = val & 0xff;
146
147 ret = i2c_transfer(i2c->adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
148
149 return ret;
118} 150}
119 151
120static int dib8000_write_word(struct dib8000_state *state, u16 reg, u16 val) 152static int dib8000_write_word(struct dib8000_state *state, u16 reg, u16 val)
121{ 153{
122 return dib8000_i2c_write16(&state->i2c, reg, val); 154 state->i2c_write_buffer[0] = (reg >> 8) & 0xff;
155 state->i2c_write_buffer[1] = reg & 0xff;
156 state->i2c_write_buffer[2] = (val >> 8) & 0xff;
157 state->i2c_write_buffer[3] = val & 0xff;
158
159 memset(&state->msg[0], 0, sizeof(struct i2c_msg));
160 state->msg[0].addr = state->i2c.addr >> 1;
161 state->msg[0].flags = 0;
162 state->msg[0].buf = state->i2c_write_buffer;
163 state->msg[0].len = 4;
164
165 return i2c_transfer(state->i2c.adap, state->msg, 1) != 1 ? -EREMOTEIO : 0;
123} 166}
124 167
125static const int16_t coeff_2k_sb_1seg_dqpsk[8] = { 168static const s16 coeff_2k_sb_1seg_dqpsk[8] = {
126 (769 << 5) | 0x0a, (745 << 5) | 0x03, (595 << 5) | 0x0d, (769 << 5) | 0x0a, (920 << 5) | 0x09, (784 << 5) | 0x02, (519 << 5) | 0x0c, 169 (769 << 5) | 0x0a, (745 << 5) | 0x03, (595 << 5) | 0x0d, (769 << 5) | 0x0a, (920 << 5) | 0x09, (784 << 5) | 0x02, (519 << 5) | 0x0c,
127 (920 << 5) | 0x09 170 (920 << 5) | 0x09
128}; 171};
129 172
130static const int16_t coeff_2k_sb_1seg[8] = { 173static const s16 coeff_2k_sb_1seg[8] = {
131 (692 << 5) | 0x0b, (683 << 5) | 0x01, (519 << 5) | 0x09, (692 << 5) | 0x0b, 0 | 0x1f, 0 | 0x1f, 0 | 0x1f, 0 | 0x1f 174 (692 << 5) | 0x0b, (683 << 5) | 0x01, (519 << 5) | 0x09, (692 << 5) | 0x0b, 0 | 0x1f, 0 | 0x1f, 0 | 0x1f, 0 | 0x1f
132}; 175};
133 176
134static const int16_t coeff_2k_sb_3seg_0dqpsk_1dqpsk[8] = { 177static const s16 coeff_2k_sb_3seg_0dqpsk_1dqpsk[8] = {
135 (832 << 5) | 0x10, (912 << 5) | 0x05, (900 << 5) | 0x12, (832 << 5) | 0x10, (-931 << 5) | 0x0f, (912 << 5) | 0x04, (807 << 5) | 0x11, 178 (832 << 5) | 0x10, (912 << 5) | 0x05, (900 << 5) | 0x12, (832 << 5) | 0x10, (-931 << 5) | 0x0f, (912 << 5) | 0x04, (807 << 5) | 0x11,
136 (-931 << 5) | 0x0f 179 (-931 << 5) | 0x0f
137}; 180};
138 181
139static const int16_t coeff_2k_sb_3seg_0dqpsk[8] = { 182static const s16 coeff_2k_sb_3seg_0dqpsk[8] = {
140 (622 << 5) | 0x0c, (941 << 5) | 0x04, (796 << 5) | 0x10, (622 << 5) | 0x0c, (982 << 5) | 0x0c, (519 << 5) | 0x02, (572 << 5) | 0x0e, 183 (622 << 5) | 0x0c, (941 << 5) | 0x04, (796 << 5) | 0x10, (622 << 5) | 0x0c, (982 << 5) | 0x0c, (519 << 5) | 0x02, (572 << 5) | 0x0e,
141 (982 << 5) | 0x0c 184 (982 << 5) | 0x0c
142}; 185};
143 186
144static const int16_t coeff_2k_sb_3seg_1dqpsk[8] = { 187static const s16 coeff_2k_sb_3seg_1dqpsk[8] = {
145 (699 << 5) | 0x14, (607 << 5) | 0x04, (944 << 5) | 0x13, (699 << 5) | 0x14, (-720 << 5) | 0x0d, (640 << 5) | 0x03, (866 << 5) | 0x12, 188 (699 << 5) | 0x14, (607 << 5) | 0x04, (944 << 5) | 0x13, (699 << 5) | 0x14, (-720 << 5) | 0x0d, (640 << 5) | 0x03, (866 << 5) | 0x12,
146 (-720 << 5) | 0x0d 189 (-720 << 5) | 0x0d
147}; 190};
148 191
149static const int16_t coeff_2k_sb_3seg[8] = { 192static const s16 coeff_2k_sb_3seg[8] = {
150 (664 << 5) | 0x0c, (925 << 5) | 0x03, (937 << 5) | 0x10, (664 << 5) | 0x0c, (-610 << 5) | 0x0a, (697 << 5) | 0x01, (836 << 5) | 0x0e, 193 (664 << 5) | 0x0c, (925 << 5) | 0x03, (937 << 5) | 0x10, (664 << 5) | 0x0c, (-610 << 5) | 0x0a, (697 << 5) | 0x01, (836 << 5) | 0x0e,
151 (-610 << 5) | 0x0a 194 (-610 << 5) | 0x0a
152}; 195};
153 196
154static const int16_t coeff_4k_sb_1seg_dqpsk[8] = { 197static const s16 coeff_4k_sb_1seg_dqpsk[8] = {
155 (-955 << 5) | 0x0e, (687 << 5) | 0x04, (818 << 5) | 0x10, (-955 << 5) | 0x0e, (-922 << 5) | 0x0d, (750 << 5) | 0x03, (665 << 5) | 0x0f, 198 (-955 << 5) | 0x0e, (687 << 5) | 0x04, (818 << 5) | 0x10, (-955 << 5) | 0x0e, (-922 << 5) | 0x0d, (750 << 5) | 0x03, (665 << 5) | 0x0f,
156 (-922 << 5) | 0x0d 199 (-922 << 5) | 0x0d
157}; 200};
158 201
159static const int16_t coeff_4k_sb_1seg[8] = { 202static const s16 coeff_4k_sb_1seg[8] = {
160 (638 << 5) | 0x0d, (683 << 5) | 0x02, (638 << 5) | 0x0d, (638 << 5) | 0x0d, (-655 << 5) | 0x0a, (517 << 5) | 0x00, (698 << 5) | 0x0d, 203 (638 << 5) | 0x0d, (683 << 5) | 0x02, (638 << 5) | 0x0d, (638 << 5) | 0x0d, (-655 << 5) | 0x0a, (517 << 5) | 0x00, (698 << 5) | 0x0d,
161 (-655 << 5) | 0x0a 204 (-655 << 5) | 0x0a
162}; 205};
163 206
164static const int16_t coeff_4k_sb_3seg_0dqpsk_1dqpsk[8] = { 207static const s16 coeff_4k_sb_3seg_0dqpsk_1dqpsk[8] = {
165 (-707 << 5) | 0x14, (910 << 5) | 0x06, (889 << 5) | 0x16, (-707 << 5) | 0x14, (-958 << 5) | 0x13, (993 << 5) | 0x05, (523 << 5) | 0x14, 208 (-707 << 5) | 0x14, (910 << 5) | 0x06, (889 << 5) | 0x16, (-707 << 5) | 0x14, (-958 << 5) | 0x13, (993 << 5) | 0x05, (523 << 5) | 0x14,
166 (-958 << 5) | 0x13 209 (-958 << 5) | 0x13
167}; 210};
168 211
169static const int16_t coeff_4k_sb_3seg_0dqpsk[8] = { 212static const s16 coeff_4k_sb_3seg_0dqpsk[8] = {
170 (-723 << 5) | 0x13, (910 << 5) | 0x05, (777 << 5) | 0x14, (-723 << 5) | 0x13, (-568 << 5) | 0x0f, (547 << 5) | 0x03, (696 << 5) | 0x12, 213 (-723 << 5) | 0x13, (910 << 5) | 0x05, (777 << 5) | 0x14, (-723 << 5) | 0x13, (-568 << 5) | 0x0f, (547 << 5) | 0x03, (696 << 5) | 0x12,
171 (-568 << 5) | 0x0f 214 (-568 << 5) | 0x0f
172}; 215};
173 216
174static const int16_t coeff_4k_sb_3seg_1dqpsk[8] = { 217static const s16 coeff_4k_sb_3seg_1dqpsk[8] = {
175 (-940 << 5) | 0x15, (607 << 5) | 0x05, (915 << 5) | 0x16, (-940 << 5) | 0x15, (-848 << 5) | 0x13, (683 << 5) | 0x04, (543 << 5) | 0x14, 218 (-940 << 5) | 0x15, (607 << 5) | 0x05, (915 << 5) | 0x16, (-940 << 5) | 0x15, (-848 << 5) | 0x13, (683 << 5) | 0x04, (543 << 5) | 0x14,
176 (-848 << 5) | 0x13 219 (-848 << 5) | 0x13
177}; 220};
178 221
179static const int16_t coeff_4k_sb_3seg[8] = { 222static const s16 coeff_4k_sb_3seg[8] = {
180 (612 << 5) | 0x12, (910 << 5) | 0x04, (864 << 5) | 0x14, (612 << 5) | 0x12, (-869 << 5) | 0x13, (683 << 5) | 0x02, (869 << 5) | 0x12, 223 (612 << 5) | 0x12, (910 << 5) | 0x04, (864 << 5) | 0x14, (612 << 5) | 0x12, (-869 << 5) | 0x13, (683 << 5) | 0x02, (869 << 5) | 0x12,
181 (-869 << 5) | 0x13 224 (-869 << 5) | 0x13
182}; 225};
183 226
184static const int16_t coeff_8k_sb_1seg_dqpsk[8] = { 227static const s16 coeff_8k_sb_1seg_dqpsk[8] = {
185 (-835 << 5) | 0x12, (684 << 5) | 0x05, (735 << 5) | 0x14, (-835 << 5) | 0x12, (-598 << 5) | 0x10, (781 << 5) | 0x04, (739 << 5) | 0x13, 228 (-835 << 5) | 0x12, (684 << 5) | 0x05, (735 << 5) | 0x14, (-835 << 5) | 0x12, (-598 << 5) | 0x10, (781 << 5) | 0x04, (739 << 5) | 0x13,
186 (-598 << 5) | 0x10 229 (-598 << 5) | 0x10
187}; 230};
188 231
189static const int16_t coeff_8k_sb_1seg[8] = { 232static const s16 coeff_8k_sb_1seg[8] = {
190 (673 << 5) | 0x0f, (683 << 5) | 0x03, (808 << 5) | 0x12, (673 << 5) | 0x0f, (585 << 5) | 0x0f, (512 << 5) | 0x01, (780 << 5) | 0x0f, 233 (673 << 5) | 0x0f, (683 << 5) | 0x03, (808 << 5) | 0x12, (673 << 5) | 0x0f, (585 << 5) | 0x0f, (512 << 5) | 0x01, (780 << 5) | 0x0f,
191 (585 << 5) | 0x0f 234 (585 << 5) | 0x0f
192}; 235};
193 236
194static const int16_t coeff_8k_sb_3seg_0dqpsk_1dqpsk[8] = { 237static const s16 coeff_8k_sb_3seg_0dqpsk_1dqpsk[8] = {
195 (863 << 5) | 0x17, (930 << 5) | 0x07, (878 << 5) | 0x19, (863 << 5) | 0x17, (0 << 5) | 0x14, (521 << 5) | 0x05, (980 << 5) | 0x18, 238 (863 << 5) | 0x17, (930 << 5) | 0x07, (878 << 5) | 0x19, (863 << 5) | 0x17, (0 << 5) | 0x14, (521 << 5) | 0x05, (980 << 5) | 0x18,
196 (0 << 5) | 0x14 239 (0 << 5) | 0x14
197}; 240};
198 241
199static const int16_t coeff_8k_sb_3seg_0dqpsk[8] = { 242static const s16 coeff_8k_sb_3seg_0dqpsk[8] = {
200 (-924 << 5) | 0x17, (910 << 5) | 0x06, (774 << 5) | 0x17, (-924 << 5) | 0x17, (-877 << 5) | 0x15, (565 << 5) | 0x04, (553 << 5) | 0x15, 243 (-924 << 5) | 0x17, (910 << 5) | 0x06, (774 << 5) | 0x17, (-924 << 5) | 0x17, (-877 << 5) | 0x15, (565 << 5) | 0x04, (553 << 5) | 0x15,
201 (-877 << 5) | 0x15 244 (-877 << 5) | 0x15
202}; 245};
203 246
204static const int16_t coeff_8k_sb_3seg_1dqpsk[8] = { 247static const s16 coeff_8k_sb_3seg_1dqpsk[8] = {
205 (-921 << 5) | 0x19, (607 << 5) | 0x06, (881 << 5) | 0x19, (-921 << 5) | 0x19, (-921 << 5) | 0x14, (713 << 5) | 0x05, (1018 << 5) | 0x18, 248 (-921 << 5) | 0x19, (607 << 5) | 0x06, (881 << 5) | 0x19, (-921 << 5) | 0x19, (-921 << 5) | 0x14, (713 << 5) | 0x05, (1018 << 5) | 0x18,
206 (-921 << 5) | 0x14 249 (-921 << 5) | 0x14
207}; 250};
208 251
209static const int16_t coeff_8k_sb_3seg[8] = { 252static const s16 coeff_8k_sb_3seg[8] = {
210 (514 << 5) | 0x14, (910 << 5) | 0x05, (861 << 5) | 0x17, (514 << 5) | 0x14, (690 << 5) | 0x14, (683 << 5) | 0x03, (662 << 5) | 0x15, 253 (514 << 5) | 0x14, (910 << 5) | 0x05, (861 << 5) | 0x17, (514 << 5) | 0x14, (690 << 5) | 0x14, (683 << 5) | 0x03, (662 << 5) | 0x15,
211 (690 << 5) | 0x14 254 (690 << 5) | 0x14
212}; 255};
213 256
214static const int16_t ana_fe_coeff_3seg[24] = { 257static const s16 ana_fe_coeff_3seg[24] = {
215 81, 80, 78, 74, 68, 61, 54, 45, 37, 28, 19, 11, 4, 1022, 1017, 1013, 1010, 1008, 1008, 1008, 1008, 1010, 1014, 1017 258 81, 80, 78, 74, 68, 61, 54, 45, 37, 28, 19, 11, 4, 1022, 1017, 1013, 1010, 1008, 1008, 1008, 1008, 1010, 1014, 1017
216}; 259};
217 260
218static const int16_t ana_fe_coeff_1seg[24] = { 261static const s16 ana_fe_coeff_1seg[24] = {
219 249, 226, 164, 82, 5, 981, 970, 988, 1018, 20, 31, 26, 8, 1012, 1000, 1018, 1012, 8, 15, 14, 9, 3, 1017, 1003 262 249, 226, 164, 82, 5, 981, 970, 988, 1018, 20, 31, 26, 8, 1012, 1000, 1018, 1012, 8, 15, 14, 9, 3, 1017, 1003
220}; 263};
221 264
222static const int16_t ana_fe_coeff_13seg[24] = { 265static const s16 ana_fe_coeff_13seg[24] = {
223 396, 305, 105, -51, -77, -12, 41, 31, -11, -30, -11, 14, 15, -2, -13, -7, 5, 8, 1, -6, -7, -3, 0, 1 266 396, 305, 105, -51, -77, -12, 41, 31, -11, -30, -11, 14, 15, -2, -13, -7, 5, 8, 1, -6, -7, -3, 0, 1
224}; 267};
225 268
226static u16 fft_to_mode(struct dib8000_state *state) 269static u16 fft_to_mode(struct dib8000_state *state)
227{ 270{
228 u16 mode; 271 u16 mode;
229 switch (state->fe.dtv_property_cache.transmission_mode) { 272 switch (state->fe[0]->dtv_property_cache.transmission_mode) {
230 case TRANSMISSION_MODE_2K: 273 case TRANSMISSION_MODE_2K:
231 mode = 1; 274 mode = 1;
232 break; 275 break;
@@ -249,16 +292,18 @@ static void dib8000_set_acquisition_mode(struct dib8000_state *state)
249 dprintk("acquisition mode activated"); 292 dprintk("acquisition mode activated");
250 dib8000_write_word(state, 298, nud); 293 dib8000_write_word(state, 298, nud);
251} 294}
252 295static int dib8000_set_output_mode(struct dvb_frontend *fe, int mode)
253static int dib8000_set_output_mode(struct dib8000_state *state, int mode)
254{ 296{
297 struct dib8000_state *state = fe->demodulator_priv;
298
255 u16 outreg, fifo_threshold, smo_mode, sram = 0x0205; /* by default SDRAM deintlv is enabled */ 299 u16 outreg, fifo_threshold, smo_mode, sram = 0x0205; /* by default SDRAM deintlv is enabled */
256 300
257 outreg = 0; 301 outreg = 0;
258 fifo_threshold = 1792; 302 fifo_threshold = 1792;
259 smo_mode = (dib8000_read_word(state, 299) & 0x0050) | (1 << 1); 303 smo_mode = (dib8000_read_word(state, 299) & 0x0050) | (1 << 1);
260 304
261 dprintk("-I- Setting output mode for demod %p to %d", &state->fe, mode); 305 dprintk("-I- Setting output mode for demod %p to %d",
306 &state->fe[0], mode);
262 307
263 switch (mode) { 308 switch (mode) {
264 case OUTMODE_MPEG2_PAR_GATED_CLK: // STBs with parallel gated clock 309 case OUTMODE_MPEG2_PAR_GATED_CLK: // STBs with parallel gated clock
@@ -292,7 +337,8 @@ static int dib8000_set_output_mode(struct dib8000_state *state, int mode)
292 break; 337 break;
293 338
294 default: 339 default:
295 dprintk("Unhandled output_mode passed to be set for demod %p", &state->fe); 340 dprintk("Unhandled output_mode passed to be set for demod %p",
341 &state->fe[0]);
296 return -EINVAL; 342 return -EINVAL;
297 } 343 }
298 344
@@ -342,7 +388,8 @@ static void dib8000_set_power_mode(struct dib8000_state *state, enum dib8000_pow
342{ 388{
343 /* by default everything is going to be powered off */ 389 /* by default everything is going to be powered off */
344 u16 reg_774 = 0x3fff, reg_775 = 0xffff, reg_776 = 0xffff, 390 u16 reg_774 = 0x3fff, reg_775 = 0xffff, reg_776 = 0xffff,
345 reg_900 = (dib8000_read_word(state, 900) & 0xfffc) | 0x3, reg_1280 = (dib8000_read_word(state, 1280) & 0x00ff) | 0xff00; 391 reg_900 = (dib8000_read_word(state, 900) & 0xfffc) | 0x3,
392 reg_1280 = (dib8000_read_word(state, 1280) & 0x00ff) | 0xff00;
346 393
347 /* now, depending on the requested mode, we power on */ 394 /* now, depending on the requested mode, we power on */
348 switch (mode) { 395 switch (mode) {
@@ -411,8 +458,9 @@ static int dib8000_set_adc_state(struct dib8000_state *state, enum dibx000_adc_s
411 return ret; 458 return ret;
412} 459}
413 460
414static int dib8000_set_bandwidth(struct dib8000_state *state, u32 bw) 461static int dib8000_set_bandwidth(struct dvb_frontend *fe, u32 bw)
415{ 462{
463 struct dib8000_state *state = fe->demodulator_priv;
416 u32 timf; 464 u32 timf;
417 465
418 if (bw == 0) 466 if (bw == 0)
@@ -478,7 +526,8 @@ static void dib8000_reset_pll(struct dib8000_state *state)
478 526
479 // clk_cfg1 527 // clk_cfg1
480 clk_cfg1 = (1 << 10) | (0 << 9) | (pll->IO_CLK_en_core << 8) | 528 clk_cfg1 = (1 << 10) | (0 << 9) | (pll->IO_CLK_en_core << 8) |
481 (pll->bypclk_div << 5) | (pll->enable_refdiv << 4) | (1 << 3) | (pll->pll_range << 1) | (pll->pll_reset << 0); 529 (pll->bypclk_div << 5) | (pll->enable_refdiv << 4) | (1 << 3) |
530 (pll->pll_range << 1) | (pll->pll_reset << 0);
482 531
483 dib8000_write_word(state, 902, clk_cfg1); 532 dib8000_write_word(state, 902, clk_cfg1);
484 clk_cfg1 = (clk_cfg1 & 0xfff7) | (pll->pll_bypass << 3); 533 clk_cfg1 = (clk_cfg1 & 0xfff7) | (pll->pll_bypass << 3);
@@ -488,11 +537,12 @@ static void dib8000_reset_pll(struct dib8000_state *state)
488 537
489 /* smpl_cfg: P_refclksel=2, P_ensmplsel=1 nodivsmpl=1 */ 538 /* smpl_cfg: P_refclksel=2, P_ensmplsel=1 nodivsmpl=1 */
490 if (state->cfg.pll->ADClkSrc == 0) 539 if (state->cfg.pll->ADClkSrc == 0)
491 dib8000_write_word(state, 904, (0 << 15) | (0 << 12) | (0 << 10) | (pll->modulo << 8) | (pll->ADClkSrc << 7) | (0 << 1)); 540 dib8000_write_word(state, 904, (0 << 15) | (0 << 12) | (0 << 10) |
541 (pll->modulo << 8) | (pll->ADClkSrc << 7) | (0 << 1));
492 else if (state->cfg.refclksel != 0) 542 else if (state->cfg.refclksel != 0)
493 dib8000_write_word(state, 904, 543 dib8000_write_word(state, 904, (0 << 15) | (1 << 12) |
494 (0 << 15) | (1 << 12) | ((state->cfg.refclksel & 0x3) << 10) | (pll->modulo << 8) | (pll-> 544 ((state->cfg.refclksel & 0x3) << 10) | (pll->modulo << 8) |
495 ADClkSrc << 7) | (0 << 1)); 545 (pll->ADClkSrc << 7) | (0 << 1));
496 else 546 else
497 dib8000_write_word(state, 904, (0 << 15) | (1 << 12) | (3 << 10) | (pll->modulo << 8) | (pll->ADClkSrc << 7) | (0 << 1)); 547 dib8000_write_word(state, 904, (0 << 15) | (1 << 12) | (3 << 10) | (pll->modulo << 8) | (pll->ADClkSrc << 7) | (0 << 1));
498 548
@@ -560,7 +610,7 @@ static const u16 dib8000_defaults[] = {
560 0xd4c0, 610 0xd4c0,
561 611
562 /*1, 32, 612 /*1, 32,
563 0x6680 // P_corm_thres Lock algorithms configuration */ 613 0x6680 // P_corm_thres Lock algorithms configuration */
564 614
565 11, 80, /* set ADC level to -16 */ 615 11, 80, /* set ADC level to -16 */
566 (1 << 13) - 825 - 117, 616 (1 << 13) - 825 - 117,
@@ -623,14 +673,14 @@ static const u16 dib8000_defaults[] = {
623 1, 285, 673 1, 285,
624 0x0020, //p_fec_ 674 0x0020, //p_fec_
625 1, 299, 675 1, 299,
626 0x0062, // P_smo_mode, P_smo_rs_discard, P_smo_fifo_flush, P_smo_pid_parse, P_smo_error_discard 676 0x0062, /* P_smo_mode, P_smo_rs_discard, P_smo_fifo_flush, P_smo_pid_parse, P_smo_error_discard */
627 677
628 1, 338, 678 1, 338,
629 (1 << 12) | // P_ctrl_corm_thres4pre_freq_inh=1 679 (1 << 12) | // P_ctrl_corm_thres4pre_freq_inh=1
630 (1 << 10) | // P_ctrl_pre_freq_mode_sat=1 680 (1 << 10) |
631 (0 << 9) | // P_ctrl_pre_freq_inh=0 681 (0 << 9) | /* P_ctrl_pre_freq_inh=0 */
632 (3 << 5) | // P_ctrl_pre_freq_step=3 682 (3 << 5) | /* P_ctrl_pre_freq_step=3 */
633 (1 << 0), // P_pre_freq_win_len=1 683 (1 << 0), /* P_pre_freq_win_len=1 */
634 684
635 1, 903, 685 1, 903,
636 (0 << 4) | 2, // P_divclksel=0 P_divbitsel=2 (was clk=3,bit=1 for MPW) 686 (0 << 4) | 2, // P_divclksel=0 P_divbitsel=2 (was clk=3,bit=1 for MPW)
@@ -717,7 +767,7 @@ static int dib8000_reset(struct dvb_frontend *fe)
717 if (dib8000_reset_gpio(state) != 0) 767 if (dib8000_reset_gpio(state) != 0)
718 dprintk("GPIO reset was not successful."); 768 dprintk("GPIO reset was not successful.");
719 769
720 if (dib8000_set_output_mode(state, OUTMODE_HIGH_Z) != 0) 770 if (dib8000_set_output_mode(fe, OUTMODE_HIGH_Z) != 0)
721 dprintk("OUTPUT_MODE could not be resetted."); 771 dprintk("OUTPUT_MODE could not be resetted.");
722 772
723 state->current_agc = NULL; 773 state->current_agc = NULL;
@@ -752,7 +802,7 @@ static int dib8000_reset(struct dvb_frontend *fe)
752 /* unforce divstr regardless whether i2c enumeration was done or not */ 802 /* unforce divstr regardless whether i2c enumeration was done or not */
753 dib8000_write_word(state, 1285, dib8000_read_word(state, 1285) & ~(1 << 1)); 803 dib8000_write_word(state, 1285, dib8000_read_word(state, 1285) & ~(1 << 1));
754 804
755 dib8000_set_bandwidth(state, 6000); 805 dib8000_set_bandwidth(fe, 6000);
756 806
757 dib8000_set_adc_state(state, DIBX000_SLOW_ADC_ON); 807 dib8000_set_adc_state(state, DIBX000_SLOW_ADC_ON);
758 dib8000_sad_calib(state); 808 dib8000_sad_calib(state);
@@ -778,7 +828,7 @@ static int dib8000_update_lna(struct dib8000_state *state)
778 // read dyn_gain here (because it is demod-dependent and not tuner) 828 // read dyn_gain here (because it is demod-dependent and not tuner)
779 dyn_gain = dib8000_read_word(state, 390); 829 dyn_gain = dib8000_read_word(state, 390);
780 830
781 if (state->cfg.update_lna(&state->fe, dyn_gain)) { // LNA has changed 831 if (state->cfg.update_lna(state->fe[0], dyn_gain)) {
782 dib8000_restart_agc(state); 832 dib8000_restart_agc(state);
783 return 1; 833 return 1;
784 } 834 }
@@ -865,7 +915,8 @@ static int dib8000_agc_soft_split(struct dib8000_state *state)
865 split_offset = state->current_agc->split.max; 915 split_offset = state->current_agc->split.max;
866 else 916 else
867 split_offset = state->current_agc->split.max * 917 split_offset = state->current_agc->split.max *
868 (agc - state->current_agc->split.min_thres) / (state->current_agc->split.max_thres - state->current_agc->split.min_thres); 918 (agc - state->current_agc->split.min_thres) /
919 (state->current_agc->split.max_thres - state->current_agc->split.min_thres);
869 920
870 dprintk("AGC split_offset: %d", split_offset); 921 dprintk("AGC split_offset: %d", split_offset);
871 922
@@ -900,7 +951,7 @@ static int dib8000_agc_startup(struct dvb_frontend *fe)
900 case CT_AGC_STEP_0: 951 case CT_AGC_STEP_0:
901 //AGC initialization 952 //AGC initialization
902 if (state->cfg.agc_control) 953 if (state->cfg.agc_control)
903 state->cfg.agc_control(&state->fe, 1); 954 state->cfg.agc_control(fe, 1);
904 955
905 dib8000_restart_agc(state); 956 dib8000_restart_agc(state);
906 957
@@ -924,7 +975,7 @@ static int dib8000_agc_startup(struct dvb_frontend *fe)
924 dib8000_agc_soft_split(state); 975 dib8000_agc_soft_split(state);
925 976
926 if (state->cfg.agc_control) 977 if (state->cfg.agc_control)
927 state->cfg.agc_control(&state->fe, 0); 978 state->cfg.agc_control(fe, 0);
928 979
929 *tune_state = CT_AGC_STOP; 980 *tune_state = CT_AGC_STOP;
930 break; 981 break;
@@ -936,29 +987,28 @@ static int dib8000_agc_startup(struct dvb_frontend *fe)
936 987
937} 988}
938 989
939static const int32_t lut_1000ln_mant[] = 990static const s32 lut_1000ln_mant[] =
940{ 991{
941 908, 7003, 7090, 7170, 7244, 7313, 7377, 7438, 7495, 7549, 7600 992 908, 7003, 7090, 7170, 7244, 7313, 7377, 7438, 7495, 7549, 7600
942}; 993};
943 994
944int32_t dib8000_get_adc_power(struct dvb_frontend *fe, uint8_t mode) 995s32 dib8000_get_adc_power(struct dvb_frontend *fe, u8 mode)
945{ 996{
946 struct dib8000_state *state = fe->demodulator_priv; 997 struct dib8000_state *state = fe->demodulator_priv;
947 uint32_t ix = 0, tmp_val = 0, exp = 0, mant = 0; 998 u32 ix = 0, tmp_val = 0, exp = 0, mant = 0;
948 int32_t val; 999 s32 val;
949 1000
950 val = dib8000_read32(state, 384); 1001 val = dib8000_read32(state, 384);
951 /* mode = 1 : ln_agcpower calc using mant-exp conversion and mantis look up table */ 1002 if (mode) {
952 if (mode) { 1003 tmp_val = val;
953 tmp_val = val; 1004 while (tmp_val >>= 1)
954 while (tmp_val >>= 1) 1005 exp++;
955 exp++; 1006 mant = (val * 1000 / (1<<exp));
956 mant = (val * 1000 / (1<<exp)); 1007 ix = (u8)((mant-1000)/100); /* index of the LUT */
957 ix = (uint8_t)((mant-1000)/100); /* index of the LUT */ 1008 val = (lut_1000ln_mant[ix] + 693*(exp-20) - 6908);
958 val = (lut_1000ln_mant[ix] + 693*(exp-20) - 6908); /* 1000 * ln(adcpower_real) ; 693 = 1000ln(2) ; 6908 = 1000*ln(1000) ; 20 comes from adc_real = adc_pow_int / 2**20 */ 1009 val = (val*256)/1000;
959 val = (val*256)/1000; 1010 }
960 } 1011 return val;
961 return val;
962} 1012}
963EXPORT_SYMBOL(dib8000_get_adc_power); 1013EXPORT_SYMBOL(dib8000_get_adc_power);
964 1014
@@ -971,30 +1021,31 @@ static void dib8000_update_timf(struct dib8000_state *state)
971 dprintk("Updated timing frequency: %d (default: %d)", state->timf, state->timf_default); 1021 dprintk("Updated timing frequency: %d (default: %d)", state->timf, state->timf_default);
972} 1022}
973 1023
1024static const u16 adc_target_16dB[11] = {
1025 (1 << 13) - 825 - 117,
1026 (1 << 13) - 837 - 117,
1027 (1 << 13) - 811 - 117,
1028 (1 << 13) - 766 - 117,
1029 (1 << 13) - 737 - 117,
1030 (1 << 13) - 693 - 117,
1031 (1 << 13) - 648 - 117,
1032 (1 << 13) - 619 - 117,
1033 (1 << 13) - 575 - 117,
1034 (1 << 13) - 531 - 117,
1035 (1 << 13) - 501 - 117
1036};
1037static const u8 permu_seg[] = { 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12 };
1038
974static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosearching) 1039static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosearching)
975{ 1040{
976 u16 mode, max_constellation, seg_diff_mask = 0, nbseg_diff = 0; 1041 u16 mode, max_constellation, seg_diff_mask = 0, nbseg_diff = 0;
977 u8 guard, crate, constellation, timeI; 1042 u8 guard, crate, constellation, timeI;
978 u8 permu_seg[] = { 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12 };
979 u16 i, coeff[4], P_cfr_left_edge = 0, P_cfr_right_edge = 0, seg_mask13 = 0x1fff; // All 13 segments enabled 1043 u16 i, coeff[4], P_cfr_left_edge = 0, P_cfr_right_edge = 0, seg_mask13 = 0x1fff; // All 13 segments enabled
980 const s16 *ncoeff = NULL, *ana_fe; 1044 const s16 *ncoeff = NULL, *ana_fe;
981 u16 tmcc_pow = 0; 1045 u16 tmcc_pow = 0;
982 u16 coff_pow = 0x2800; 1046 u16 coff_pow = 0x2800;
983 u16 init_prbs = 0xfff; 1047 u16 init_prbs = 0xfff;
984 u16 ana_gain = 0; 1048 u16 ana_gain = 0;
985 u16 adc_target_16dB[11] = {
986 (1 << 13) - 825 - 117,
987 (1 << 13) - 837 - 117,
988 (1 << 13) - 811 - 117,
989 (1 << 13) - 766 - 117,
990 (1 << 13) - 737 - 117,
991 (1 << 13) - 693 - 117,
992 (1 << 13) - 648 - 117,
993 (1 << 13) - 619 - 117,
994 (1 << 13) - 575 - 117,
995 (1 << 13) - 531 - 117,
996 (1 << 13) - 501 - 117
997 };
998 1049
999 if (state->ber_monitored_layer != LAYER_ALL) 1050 if (state->ber_monitored_layer != LAYER_ALL)
1000 dib8000_write_word(state, 285, (dib8000_read_word(state, 285) & 0x60) | state->ber_monitored_layer); 1051 dib8000_write_word(state, 285, (dib8000_read_word(state, 285) & 0x60) | state->ber_monitored_layer);
@@ -1002,22 +1053,23 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1002 dib8000_write_word(state, 285, dib8000_read_word(state, 285) & 0x60); 1053 dib8000_write_word(state, 285, dib8000_read_word(state, 285) & 0x60);
1003 1054
1004 i = dib8000_read_word(state, 26) & 1; // P_dds_invspec 1055 i = dib8000_read_word(state, 26) & 1; // P_dds_invspec
1005 dib8000_write_word(state, 26, state->fe.dtv_property_cache.inversion ^ i); 1056 dib8000_write_word(state, 26, state->fe[0]->dtv_property_cache.inversion^i);
1006 1057
1007 if (state->fe.dtv_property_cache.isdbt_sb_mode) { 1058 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode) {
1008 //compute new dds_freq for the seg and adjust prbs 1059 //compute new dds_freq for the seg and adjust prbs
1009 int seg_offset = 1060 int seg_offset =
1010 state->fe.dtv_property_cache.isdbt_sb_segment_idx - (state->fe.dtv_property_cache.isdbt_sb_segment_count / 2) - 1061 state->fe[0]->dtv_property_cache.isdbt_sb_segment_idx -
1011 (state->fe.dtv_property_cache.isdbt_sb_segment_count % 2); 1062 (state->fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2) -
1063 (state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2);
1012 int clk = state->cfg.pll->internal; 1064 int clk = state->cfg.pll->internal;
1013 u32 segtodds = ((u32) (430 << 23) / clk) << 3; // segtodds = SegBW / Fclk * pow(2,26) 1065 u32 segtodds = ((u32) (430 << 23) / clk) << 3; // segtodds = SegBW / Fclk * pow(2,26)
1014 int dds_offset = seg_offset * segtodds; 1066 int dds_offset = seg_offset * segtodds;
1015 int new_dds, sub_channel; 1067 int new_dds, sub_channel;
1016 if ((state->fe.dtv_property_cache.isdbt_sb_segment_count % 2) == 0) // if even 1068 if ((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
1017 dds_offset -= (int)(segtodds / 2); 1069 dds_offset -= (int)(segtodds / 2);
1018 1070
1019 if (state->cfg.pll->ifreq == 0) { 1071 if (state->cfg.pll->ifreq == 0) {
1020 if ((state->fe.dtv_property_cache.inversion ^ i) == 0) { 1072 if ((state->fe[0]->dtv_property_cache.inversion ^ i) == 0) {
1021 dib8000_write_word(state, 26, dib8000_read_word(state, 26) | 1); 1073 dib8000_write_word(state, 26, dib8000_read_word(state, 26) | 1);
1022 new_dds = dds_offset; 1074 new_dds = dds_offset;
1023 } else 1075 } else
@@ -1027,35 +1079,35 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1027 // - the segment of center frequency with an odd total number of segments 1079 // - the segment of center frequency with an odd total number of segments
1028 // - the segment to the left of center frequency with an even total number of segments 1080 // - the segment to the left of center frequency with an even total number of segments
1029 // - the segment to the right of center frequency with an even total number of segments 1081 // - the segment to the right of center frequency with an even total number of segments
1030 if ((state->fe.dtv_property_cache.delivery_system == SYS_ISDBT) && (state->fe.dtv_property_cache.isdbt_sb_mode == 1) 1082 if ((state->fe[0]->dtv_property_cache.delivery_system == SYS_ISDBT)
1031 && 1083 && (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1)
1032 (((state->fe.dtv_property_cache.isdbt_sb_segment_count % 2) 1084 && (((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2)
1033 && (state->fe.dtv_property_cache.isdbt_sb_segment_idx == 1085 && (state->fe[0]->dtv_property_cache.isdbt_sb_segment_idx ==
1034 ((state->fe.dtv_property_cache.isdbt_sb_segment_count / 2) + 1))) 1086 ((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2) + 1)))
1035 || (((state->fe.dtv_property_cache.isdbt_sb_segment_count % 2) == 0) 1087 || (((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
1036 && (state->fe.dtv_property_cache.isdbt_sb_segment_idx == (state->fe.dtv_property_cache.isdbt_sb_segment_count / 2))) 1088 && (state->fe[0]->dtv_property_cache.isdbt_sb_segment_idx == (state->fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2)))
1037 || (((state->fe.dtv_property_cache.isdbt_sb_segment_count % 2) == 0) 1089 || (((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2) == 0)
1038 && (state->fe.dtv_property_cache.isdbt_sb_segment_idx == 1090 && (state->fe[0]->dtv_property_cache.isdbt_sb_segment_idx ==
1039 ((state->fe.dtv_property_cache.isdbt_sb_segment_count / 2) + 1))) 1091 ((state->fe[0]->dtv_property_cache.isdbt_sb_segment_count / 2) + 1)))
1040 )) { 1092 )) {
1041 new_dds -= ((u32) (850 << 22) / clk) << 4; // new_dds = 850 (freq shift in KHz) / Fclk * pow(2,26) 1093 new_dds -= ((u32) (850 << 22) / clk) << 4; // new_dds = 850 (freq shift in KHz) / Fclk * pow(2,26)
1042 } 1094 }
1043 } else { 1095 } else {
1044 if ((state->fe.dtv_property_cache.inversion ^ i) == 0) 1096 if ((state->fe[0]->dtv_property_cache.inversion ^ i) == 0)
1045 new_dds = state->cfg.pll->ifreq - dds_offset; 1097 new_dds = state->cfg.pll->ifreq - dds_offset;
1046 else 1098 else
1047 new_dds = state->cfg.pll->ifreq + dds_offset; 1099 new_dds = state->cfg.pll->ifreq + dds_offset;
1048 } 1100 }
1049 dib8000_write_word(state, 27, (u16) ((new_dds >> 16) & 0x01ff)); 1101 dib8000_write_word(state, 27, (u16) ((new_dds >> 16) & 0x01ff));
1050 dib8000_write_word(state, 28, (u16) (new_dds & 0xffff)); 1102 dib8000_write_word(state, 28, (u16) (new_dds & 0xffff));
1051 if (state->fe.dtv_property_cache.isdbt_sb_segment_count % 2) // if odd 1103 if (state->fe[0]->dtv_property_cache.isdbt_sb_segment_count % 2)
1052 sub_channel = ((state->fe.dtv_property_cache.isdbt_sb_subchannel + (3 * seg_offset) + 1) % 41) / 3; 1104 sub_channel = ((state->fe[0]->dtv_property_cache.isdbt_sb_subchannel + (3 * seg_offset) + 1) % 41) / 3;
1053 else // if even 1105 else
1054 sub_channel = ((state->fe.dtv_property_cache.isdbt_sb_subchannel + (3 * seg_offset)) % 41) / 3; 1106 sub_channel = ((state->fe[0]->dtv_property_cache.isdbt_sb_subchannel + (3 * seg_offset)) % 41) / 3;
1055 sub_channel -= 6; 1107 sub_channel -= 6;
1056 1108
1057 if (state->fe.dtv_property_cache.transmission_mode == TRANSMISSION_MODE_2K 1109 if (state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_2K
1058 || state->fe.dtv_property_cache.transmission_mode == TRANSMISSION_MODE_4K) { 1110 || state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_4K) {
1059 dib8000_write_word(state, 219, dib8000_read_word(state, 219) | 0x1); //adp_pass =1 1111 dib8000_write_word(state, 219, dib8000_read_word(state, 219) | 0x1); //adp_pass =1
1060 dib8000_write_word(state, 190, dib8000_read_word(state, 190) | (0x1 << 14)); //pha3_force_pha_shift = 1 1112 dib8000_write_word(state, 190, dib8000_read_word(state, 190) | (0x1 << 14)); //pha3_force_pha_shift = 1
1061 } else { 1113 } else {
@@ -1063,7 +1115,7 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1063 dib8000_write_word(state, 190, dib8000_read_word(state, 190) & 0xbfff); //pha3_force_pha_shift = 0 1115 dib8000_write_word(state, 190, dib8000_read_word(state, 190) & 0xbfff); //pha3_force_pha_shift = 0
1064 } 1116 }
1065 1117
1066 switch (state->fe.dtv_property_cache.transmission_mode) { 1118 switch (state->fe[0]->dtv_property_cache.transmission_mode) {
1067 case TRANSMISSION_MODE_2K: 1119 case TRANSMISSION_MODE_2K:
1068 switch (sub_channel) { 1120 switch (sub_channel) {
1069 case -6: 1121 case -6:
@@ -1209,7 +1261,7 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1209 } 1261 }
1210 break; 1262 break;
1211 } 1263 }
1212 } else { // if not state->fe.dtv_property_cache.isdbt_sb_mode 1264 } else {
1213 dib8000_write_word(state, 27, (u16) ((state->cfg.pll->ifreq >> 16) & 0x01ff)); 1265 dib8000_write_word(state, 27, (u16) ((state->cfg.pll->ifreq >> 16) & 0x01ff));
1214 dib8000_write_word(state, 28, (u16) (state->cfg.pll->ifreq & 0xffff)); 1266 dib8000_write_word(state, 28, (u16) (state->cfg.pll->ifreq & 0xffff));
1215 dib8000_write_word(state, 26, (u16) ((state->cfg.pll->ifreq >> 25) & 0x0003)); 1267 dib8000_write_word(state, 26, (u16) ((state->cfg.pll->ifreq >> 25) & 0x0003));
@@ -1218,7 +1270,7 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1218 dib8000_write_word(state, 10, (seq << 4)); 1270 dib8000_write_word(state, 10, (seq << 4));
1219 // dib8000_write_word(state, 287, (dib8000_read_word(state, 287) & 0xe000) | 0x1000); 1271 // dib8000_write_word(state, 287, (dib8000_read_word(state, 287) & 0xe000) | 0x1000);
1220 1272
1221 switch (state->fe.dtv_property_cache.guard_interval) { 1273 switch (state->fe[0]->dtv_property_cache.guard_interval) {
1222 case GUARD_INTERVAL_1_32: 1274 case GUARD_INTERVAL_1_32:
1223 guard = 0; 1275 guard = 0;
1224 break; 1276 break;
@@ -1238,7 +1290,7 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1238 1290
1239 max_constellation = DQPSK; 1291 max_constellation = DQPSK;
1240 for (i = 0; i < 3; i++) { 1292 for (i = 0; i < 3; i++) {
1241 switch (state->fe.dtv_property_cache.layer[i].modulation) { 1293 switch (state->fe[0]->dtv_property_cache.layer[i].modulation) {
1242 case DQPSK: 1294 case DQPSK:
1243 constellation = 0; 1295 constellation = 0;
1244 break; 1296 break;
@@ -1254,7 +1306,7 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1254 break; 1306 break;
1255 } 1307 }
1256 1308
1257 switch (state->fe.dtv_property_cache.layer[i].fec) { 1309 switch (state->fe[0]->dtv_property_cache.layer[i].fec) {
1258 case FEC_1_2: 1310 case FEC_1_2:
1259 crate = 1; 1311 crate = 1;
1260 break; 1312 break;
@@ -1273,26 +1325,26 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1273 break; 1325 break;
1274 } 1326 }
1275 1327
1276 if ((state->fe.dtv_property_cache.layer[i].interleaving > 0) && 1328 if ((state->fe[0]->dtv_property_cache.layer[i].interleaving > 0) &&
1277 ((state->fe.dtv_property_cache.layer[i].interleaving <= 3) || 1329 ((state->fe[0]->dtv_property_cache.layer[i].interleaving <= 3) ||
1278 (state->fe.dtv_property_cache.layer[i].interleaving == 4 && state->fe.dtv_property_cache.isdbt_sb_mode == 1)) 1330 (state->fe[0]->dtv_property_cache.layer[i].interleaving == 4 && state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1))
1279 ) 1331 )
1280 timeI = state->fe.dtv_property_cache.layer[i].interleaving; 1332 timeI = state->fe[0]->dtv_property_cache.layer[i].interleaving;
1281 else 1333 else
1282 timeI = 0; 1334 timeI = 0;
1283 dib8000_write_word(state, 2 + i, (constellation << 10) | ((state->fe.dtv_property_cache.layer[i].segment_count & 0xf) << 6) | 1335 dib8000_write_word(state, 2 + i, (constellation << 10) | ((state->fe[0]->dtv_property_cache.layer[i].segment_count & 0xf) << 6) |
1284 (crate << 3) | timeI); 1336 (crate << 3) | timeI);
1285 if (state->fe.dtv_property_cache.layer[i].segment_count > 0) { 1337 if (state->fe[0]->dtv_property_cache.layer[i].segment_count > 0) {
1286 switch (max_constellation) { 1338 switch (max_constellation) {
1287 case DQPSK: 1339 case DQPSK:
1288 case QPSK: 1340 case QPSK:
1289 if (state->fe.dtv_property_cache.layer[i].modulation == QAM_16 || 1341 if (state->fe[0]->dtv_property_cache.layer[i].modulation == QAM_16 ||
1290 state->fe.dtv_property_cache.layer[i].modulation == QAM_64) 1342 state->fe[0]->dtv_property_cache.layer[i].modulation == QAM_64)
1291 max_constellation = state->fe.dtv_property_cache.layer[i].modulation; 1343 max_constellation = state->fe[0]->dtv_property_cache.layer[i].modulation;
1292 break; 1344 break;
1293 case QAM_16: 1345 case QAM_16:
1294 if (state->fe.dtv_property_cache.layer[i].modulation == QAM_64) 1346 if (state->fe[0]->dtv_property_cache.layer[i].modulation == QAM_64)
1295 max_constellation = state->fe.dtv_property_cache.layer[i].modulation; 1347 max_constellation = state->fe[0]->dtv_property_cache.layer[i].modulation;
1296 break; 1348 break;
1297 } 1349 }
1298 } 1350 }
@@ -1303,34 +1355,34 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1303 //dib8000_write_word(state, 5, 13); /*p_last_seg = 13*/ 1355 //dib8000_write_word(state, 5, 13); /*p_last_seg = 13*/
1304 1356
1305 dib8000_write_word(state, 274, (dib8000_read_word(state, 274) & 0xffcf) | 1357 dib8000_write_word(state, 274, (dib8000_read_word(state, 274) & 0xffcf) |
1306 ((state->fe.dtv_property_cache.isdbt_partial_reception & 1) << 5) | ((state->fe.dtv_property_cache. 1358 ((state->fe[0]->dtv_property_cache.isdbt_partial_reception & 1) << 5) | ((state->fe[0]->dtv_property_cache.
1307 isdbt_sb_mode & 1) << 4)); 1359 isdbt_sb_mode & 1) << 4));
1308 1360
1309 dprintk("mode = %d ; guard = %d", mode, state->fe.dtv_property_cache.guard_interval); 1361 dprintk("mode = %d ; guard = %d", mode, state->fe[0]->dtv_property_cache.guard_interval);
1310 1362
1311 /* signal optimization parameter */ 1363 /* signal optimization parameter */
1312 1364
1313 if (state->fe.dtv_property_cache.isdbt_partial_reception) { 1365 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception) {
1314 seg_diff_mask = (state->fe.dtv_property_cache.layer[0].modulation == DQPSK) << permu_seg[0]; 1366 seg_diff_mask = (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK) << permu_seg[0];
1315 for (i = 1; i < 3; i++) 1367 for (i = 1; i < 3; i++)
1316 nbseg_diff += 1368 nbseg_diff +=
1317 (state->fe.dtv_property_cache.layer[i].modulation == DQPSK) * state->fe.dtv_property_cache.layer[i].segment_count; 1369 (state->fe[0]->dtv_property_cache.layer[i].modulation == DQPSK) * state->fe[0]->dtv_property_cache.layer[i].segment_count;
1318 for (i = 0; i < nbseg_diff; i++) 1370 for (i = 0; i < nbseg_diff; i++)
1319 seg_diff_mask |= 1 << permu_seg[i + 1]; 1371 seg_diff_mask |= 1 << permu_seg[i + 1];
1320 } else { 1372 } else {
1321 for (i = 0; i < 3; i++) 1373 for (i = 0; i < 3; i++)
1322 nbseg_diff += 1374 nbseg_diff +=
1323 (state->fe.dtv_property_cache.layer[i].modulation == DQPSK) * state->fe.dtv_property_cache.layer[i].segment_count; 1375 (state->fe[0]->dtv_property_cache.layer[i].modulation == DQPSK) * state->fe[0]->dtv_property_cache.layer[i].segment_count;
1324 for (i = 0; i < nbseg_diff; i++) 1376 for (i = 0; i < nbseg_diff; i++)
1325 seg_diff_mask |= 1 << permu_seg[i]; 1377 seg_diff_mask |= 1 << permu_seg[i];
1326 } 1378 }
1327 dprintk("nbseg_diff = %X (%d)", seg_diff_mask, seg_diff_mask); 1379 dprintk("nbseg_diff = %X (%d)", seg_diff_mask, seg_diff_mask);
1328 1380
1329 state->differential_constellation = (seg_diff_mask != 0); 1381 state->differential_constellation = (seg_diff_mask != 0);
1330 dib8000_set_diversity_in(&state->fe, state->diversity_onoff); 1382 dib8000_set_diversity_in(state->fe[0], state->diversity_onoff);
1331 1383
1332 if (state->fe.dtv_property_cache.isdbt_sb_mode == 1) { // ISDB-Tsb 1384 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
1333 if (state->fe.dtv_property_cache.isdbt_partial_reception == 1) // 3-segments 1385 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 1)
1334 seg_mask13 = 0x00E0; 1386 seg_mask13 = 0x00E0;
1335 else // 1-segment 1387 else // 1-segment
1336 seg_mask13 = 0x0040; 1388 seg_mask13 = 0x0040;
@@ -1340,7 +1392,7 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1340 // WRITE: Mode & Diff mask 1392 // WRITE: Mode & Diff mask
1341 dib8000_write_word(state, 0, (mode << 13) | seg_diff_mask); 1393 dib8000_write_word(state, 0, (mode << 13) | seg_diff_mask);
1342 1394
1343 if ((seg_diff_mask) || (state->fe.dtv_property_cache.isdbt_sb_mode)) 1395 if ((seg_diff_mask) || (state->fe[0]->dtv_property_cache.isdbt_sb_mode))
1344 dib8000_write_word(state, 268, (dib8000_read_word(state, 268) & 0xF9FF) | 0x0200); 1396 dib8000_write_word(state, 268, (dib8000_read_word(state, 268) & 0xF9FF) | 0x0200);
1345 else 1397 else
1346 dib8000_write_word(state, 268, (2 << 9) | 39); //init value 1398 dib8000_write_word(state, 268, (2 << 9) | 39); //init value
@@ -1351,26 +1403,25 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1351 1403
1352 dib8000_write_word(state, 353, seg_mask13); // ADDR 353 1404 dib8000_write_word(state, 353, seg_mask13); // ADDR 353
1353 1405
1354/* // P_small_narrow_band=0, P_small_last_seg=13, P_small_offset_num_car=5 */ 1406/* // P_small_narrow_band=0, P_small_last_seg=13, P_small_offset_num_car=5 */
1355 // dib8000_write_word(state, 351, (state->fe.dtv_property_cache.isdbt_sb_mode << 8) | (13 << 4) | 5 );
1356 1407
1357 // ---- SMALL ---- 1408 // ---- SMALL ----
1358 if (state->fe.dtv_property_cache.isdbt_sb_mode == 1) { 1409 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
1359 switch (state->fe.dtv_property_cache.transmission_mode) { 1410 switch (state->fe[0]->dtv_property_cache.transmission_mode) {
1360 case TRANSMISSION_MODE_2K: 1411 case TRANSMISSION_MODE_2K:
1361 if (state->fe.dtv_property_cache.isdbt_partial_reception == 0) { // 1-seg 1412 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0) {
1362 if (state->fe.dtv_property_cache.layer[0].modulation == DQPSK) // DQPSK 1413 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK)
1363 ncoeff = coeff_2k_sb_1seg_dqpsk; 1414 ncoeff = coeff_2k_sb_1seg_dqpsk;
1364 else // QPSK or QAM 1415 else // QPSK or QAM
1365 ncoeff = coeff_2k_sb_1seg; 1416 ncoeff = coeff_2k_sb_1seg;
1366 } else { // 3-segments 1417 } else { // 3-segments
1367 if (state->fe.dtv_property_cache.layer[0].modulation == DQPSK) { // DQPSK on central segment 1418 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK) {
1368 if (state->fe.dtv_property_cache.layer[1].modulation == DQPSK) // DQPSK on external segments 1419 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK)
1369 ncoeff = coeff_2k_sb_3seg_0dqpsk_1dqpsk; 1420 ncoeff = coeff_2k_sb_3seg_0dqpsk_1dqpsk;
1370 else // QPSK or QAM on external segments 1421 else // QPSK or QAM on external segments
1371 ncoeff = coeff_2k_sb_3seg_0dqpsk; 1422 ncoeff = coeff_2k_sb_3seg_0dqpsk;
1372 } else { // QPSK or QAM on central segment 1423 } else { // QPSK or QAM on central segment
1373 if (state->fe.dtv_property_cache.layer[1].modulation == DQPSK) // DQPSK on external segments 1424 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK)
1374 ncoeff = coeff_2k_sb_3seg_1dqpsk; 1425 ncoeff = coeff_2k_sb_3seg_1dqpsk;
1375 else // QPSK or QAM on external segments 1426 else // QPSK or QAM on external segments
1376 ncoeff = coeff_2k_sb_3seg; 1427 ncoeff = coeff_2k_sb_3seg;
@@ -1379,20 +1430,20 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1379 break; 1430 break;
1380 1431
1381 case TRANSMISSION_MODE_4K: 1432 case TRANSMISSION_MODE_4K:
1382 if (state->fe.dtv_property_cache.isdbt_partial_reception == 0) { // 1-seg 1433 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0) {
1383 if (state->fe.dtv_property_cache.layer[0].modulation == DQPSK) // DQPSK 1434 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK)
1384 ncoeff = coeff_4k_sb_1seg_dqpsk; 1435 ncoeff = coeff_4k_sb_1seg_dqpsk;
1385 else // QPSK or QAM 1436 else // QPSK or QAM
1386 ncoeff = coeff_4k_sb_1seg; 1437 ncoeff = coeff_4k_sb_1seg;
1387 } else { // 3-segments 1438 } else { // 3-segments
1388 if (state->fe.dtv_property_cache.layer[0].modulation == DQPSK) { // DQPSK on central segment 1439 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK) {
1389 if (state->fe.dtv_property_cache.layer[1].modulation == DQPSK) { // DQPSK on external segments 1440 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK) {
1390 ncoeff = coeff_4k_sb_3seg_0dqpsk_1dqpsk; 1441 ncoeff = coeff_4k_sb_3seg_0dqpsk_1dqpsk;
1391 } else { // QPSK or QAM on external segments 1442 } else { // QPSK or QAM on external segments
1392 ncoeff = coeff_4k_sb_3seg_0dqpsk; 1443 ncoeff = coeff_4k_sb_3seg_0dqpsk;
1393 } 1444 }
1394 } else { // QPSK or QAM on central segment 1445 } else { // QPSK or QAM on central segment
1395 if (state->fe.dtv_property_cache.layer[1].modulation == DQPSK) { // DQPSK on external segments 1446 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK) {
1396 ncoeff = coeff_4k_sb_3seg_1dqpsk; 1447 ncoeff = coeff_4k_sb_3seg_1dqpsk;
1397 } else // QPSK or QAM on external segments 1448 } else // QPSK or QAM on external segments
1398 ncoeff = coeff_4k_sb_3seg; 1449 ncoeff = coeff_4k_sb_3seg;
@@ -1403,20 +1454,20 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1403 case TRANSMISSION_MODE_AUTO: 1454 case TRANSMISSION_MODE_AUTO:
1404 case TRANSMISSION_MODE_8K: 1455 case TRANSMISSION_MODE_8K:
1405 default: 1456 default:
1406 if (state->fe.dtv_property_cache.isdbt_partial_reception == 0) { // 1-seg 1457 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0) {
1407 if (state->fe.dtv_property_cache.layer[0].modulation == DQPSK) // DQPSK 1458 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK)
1408 ncoeff = coeff_8k_sb_1seg_dqpsk; 1459 ncoeff = coeff_8k_sb_1seg_dqpsk;
1409 else // QPSK or QAM 1460 else // QPSK or QAM
1410 ncoeff = coeff_8k_sb_1seg; 1461 ncoeff = coeff_8k_sb_1seg;
1411 } else { // 3-segments 1462 } else { // 3-segments
1412 if (state->fe.dtv_property_cache.layer[0].modulation == DQPSK) { // DQPSK on central segment 1463 if (state->fe[0]->dtv_property_cache.layer[0].modulation == DQPSK) {
1413 if (state->fe.dtv_property_cache.layer[1].modulation == DQPSK) { // DQPSK on external segments 1464 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK) {
1414 ncoeff = coeff_8k_sb_3seg_0dqpsk_1dqpsk; 1465 ncoeff = coeff_8k_sb_3seg_0dqpsk_1dqpsk;
1415 } else { // QPSK or QAM on external segments 1466 } else { // QPSK or QAM on external segments
1416 ncoeff = coeff_8k_sb_3seg_0dqpsk; 1467 ncoeff = coeff_8k_sb_3seg_0dqpsk;
1417 } 1468 }
1418 } else { // QPSK or QAM on central segment 1469 } else { // QPSK or QAM on central segment
1419 if (state->fe.dtv_property_cache.layer[1].modulation == DQPSK) { // DQPSK on external segments 1470 if (state->fe[0]->dtv_property_cache.layer[1].modulation == DQPSK) {
1420 ncoeff = coeff_8k_sb_3seg_1dqpsk; 1471 ncoeff = coeff_8k_sb_3seg_1dqpsk;
1421 } else // QPSK or QAM on external segments 1472 } else // QPSK or QAM on external segments
1422 ncoeff = coeff_8k_sb_3seg; 1473 ncoeff = coeff_8k_sb_3seg;
@@ -1430,22 +1481,22 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1430 1481
1431 // P_small_coef_ext_enable=ISDB-Tsb, P_small_narrow_band=ISDB-Tsb, P_small_last_seg=13, P_small_offset_num_car=5 1482 // P_small_coef_ext_enable=ISDB-Tsb, P_small_narrow_band=ISDB-Tsb, P_small_last_seg=13, P_small_offset_num_car=5
1432 dib8000_write_word(state, 351, 1483 dib8000_write_word(state, 351,
1433 (state->fe.dtv_property_cache.isdbt_sb_mode << 9) | (state->fe.dtv_property_cache.isdbt_sb_mode << 8) | (13 << 4) | 5); 1484 (state->fe[0]->dtv_property_cache.isdbt_sb_mode << 9) | (state->fe[0]->dtv_property_cache.isdbt_sb_mode << 8) | (13 << 4) | 5);
1434 1485
1435 // ---- COFF ---- 1486 // ---- COFF ----
1436 // Carloff, the most robust 1487 // Carloff, the most robust
1437 if (state->fe.dtv_property_cache.isdbt_sb_mode == 1) { // Sound Broadcasting mode - use both TMCC and AC pilots 1488 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
1438 1489
1439 // P_coff_cpil_alpha=4, P_coff_inh=0, P_coff_cpil_winlen=64 1490 // P_coff_cpil_alpha=4, P_coff_inh=0, P_coff_cpil_winlen=64
1440 // P_coff_narrow_band=1, P_coff_square_val=1, P_coff_one_seg=~partial_rcpt, P_coff_use_tmcc=1, P_coff_use_ac=1 1491 // P_coff_narrow_band=1, P_coff_square_val=1, P_coff_one_seg=~partial_rcpt, P_coff_use_tmcc=1, P_coff_use_ac=1
1441 dib8000_write_word(state, 187, 1492 dib8000_write_word(state, 187,
1442 (4 << 12) | (0 << 11) | (63 << 5) | (0x3 << 3) | ((~state->fe.dtv_property_cache.isdbt_partial_reception & 1) << 2) 1493 (4 << 12) | (0 << 11) | (63 << 5) | (0x3 << 3) | ((~state->fe[0]->dtv_property_cache.isdbt_partial_reception & 1) << 2)
1443 | 0x3); 1494 | 0x3);
1444 1495
1445/* // P_small_coef_ext_enable = 1 */ 1496/* // P_small_coef_ext_enable = 1 */
1446/* dib8000_write_word(state, 351, dib8000_read_word(state, 351) | 0x200); */ 1497/* dib8000_write_word(state, 351, dib8000_read_word(state, 351) | 0x200); */
1447 1498
1448 if (state->fe.dtv_property_cache.isdbt_partial_reception == 0) { // Sound Broadcasting mode 1 seg 1499 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0) {
1449 1500
1450 // P_coff_winlen=63, P_coff_thres_lock=15, P_coff_one_seg_width= (P_mode == 3) , P_coff_one_seg_sym= (P_mode-1) 1501 // P_coff_winlen=63, P_coff_thres_lock=15, P_coff_one_seg_width= (P_mode == 3) , P_coff_one_seg_sym= (P_mode-1)
1451 if (mode == 3) 1502 if (mode == 3)
@@ -1469,10 +1520,10 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1469 dib8000_write_word(state, 186, 80); 1520 dib8000_write_word(state, 186, 80);
1470 } else { // Sound Broadcasting mode 3 seg 1521 } else { // Sound Broadcasting mode 3 seg
1471 // P_coff_one_seg_sym= 1, P_coff_one_seg_width= 1, P_coff_winlen=63, P_coff_thres_lock=15 1522 // P_coff_one_seg_sym= 1, P_coff_one_seg_width= 1, P_coff_winlen=63, P_coff_thres_lock=15
1472 /* if (mode == 3) */ 1523 /* if (mode == 3) */
1473 /* dib8000_write_word(state, 180, 0x2fca | ((0) << 14)); */ 1524 /* dib8000_write_word(state, 180, 0x2fca | ((0) << 14)); */
1474 /* else */ 1525 /* else */
1475 /* dib8000_write_word(state, 180, 0x2fca | ((1) << 14)); */ 1526 /* dib8000_write_word(state, 180, 0x2fca | ((1) << 14)); */
1476 dib8000_write_word(state, 180, 0x1fcf | (1 << 14)); 1527 dib8000_write_word(state, 180, 0x1fcf | (1 << 14));
1477 1528
1478 // P_ctrl_corm_thres4pre_freq_inh = 1, P_ctrl_pre_freq_mode_sat=1, 1529 // P_ctrl_corm_thres4pre_freq_inh = 1, P_ctrl_pre_freq_mode_sat=1,
@@ -1509,7 +1560,7 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1509 dib8000_write_word(state, 341, (4 << 3) | (1 << 2) | (1 << 1) | (1 << 0)); 1560 dib8000_write_word(state, 341, (4 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
1510 } 1561 }
1511 // ---- FFT ---- 1562 // ---- FFT ----
1512 if (state->fe.dtv_property_cache.isdbt_sb_mode == 1 && state->fe.dtv_property_cache.isdbt_partial_reception == 0) // 1-seg 1563 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1 && state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0)
1513 dib8000_write_word(state, 178, 64); // P_fft_powrange=64 1564 dib8000_write_word(state, 178, 64); // P_fft_powrange=64
1514 else 1565 else
1515 dib8000_write_word(state, 178, 32); // P_fft_powrange=32 1566 dib8000_write_word(state, 178, 32); // P_fft_powrange=32
@@ -1518,12 +1569,12 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1518 * 6bits; p_coff_thres_lock 6bits (for coff lock if needed) 1569 * 6bits; p_coff_thres_lock 6bits (for coff lock if needed)
1519 */ 1570 */
1520 /* if ( ( nbseg_diff>0)&&(nbseg_diff<13)) 1571 /* if ( ( nbseg_diff>0)&&(nbseg_diff<13))
1521 dib8000_write_word(state, 187, (dib8000_read_word(state, 187) & 0xfffb) | (1 << 3)); */ 1572 dib8000_write_word(state, 187, (dib8000_read_word(state, 187) & 0xfffb) | (1 << 3)); */
1522 1573
1523 dib8000_write_word(state, 189, ~seg_mask13 | seg_diff_mask); /* P_lmod4_seg_inh */ 1574 dib8000_write_word(state, 189, ~seg_mask13 | seg_diff_mask); /* P_lmod4_seg_inh */
1524 dib8000_write_word(state, 192, ~seg_mask13 | seg_diff_mask); /* P_pha3_seg_inh */ 1575 dib8000_write_word(state, 192, ~seg_mask13 | seg_diff_mask); /* P_pha3_seg_inh */
1525 dib8000_write_word(state, 225, ~seg_mask13 | seg_diff_mask); /* P_tac_seg_inh */ 1576 dib8000_write_word(state, 225, ~seg_mask13 | seg_diff_mask); /* P_tac_seg_inh */
1526 if ((!state->fe.dtv_property_cache.isdbt_sb_mode) && (state->cfg.pll->ifreq == 0)) 1577 if ((!state->fe[0]->dtv_property_cache.isdbt_sb_mode) && (state->cfg.pll->ifreq == 0))
1527 dib8000_write_word(state, 266, ~seg_mask13 | seg_diff_mask | 0x40); /* P_equal_noise_seg_inh */ 1578 dib8000_write_word(state, 266, ~seg_mask13 | seg_diff_mask | 0x40); /* P_equal_noise_seg_inh */
1528 else 1579 else
1529 dib8000_write_word(state, 266, ~seg_mask13 | seg_diff_mask); /* P_equal_noise_seg_inh */ 1580 dib8000_write_word(state, 266, ~seg_mask13 | seg_diff_mask); /* P_equal_noise_seg_inh */
@@ -1538,8 +1589,8 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1538 dib8000_write_word(state, 211, seg_mask13 & (~seg_diff_mask)); /* P_des_seg_enabled */ 1589 dib8000_write_word(state, 211, seg_mask13 & (~seg_diff_mask)); /* P_des_seg_enabled */
1539 1590
1540 /* offset loop parameters */ 1591 /* offset loop parameters */
1541 if (state->fe.dtv_property_cache.isdbt_sb_mode == 1) { 1592 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
1542 if (state->fe.dtv_property_cache.isdbt_partial_reception == 0) // Sound Broadcasting mode 1 seg 1593 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0)
1543 /* P_timf_alpha = (11-P_mode), P_corm_alpha=6, P_corm_thres=0x80 */ 1594 /* P_timf_alpha = (11-P_mode), P_corm_alpha=6, P_corm_thres=0x80 */
1544 dib8000_write_word(state, 32, ((11 - mode) << 12) | (6 << 8) | 0x40); 1595 dib8000_write_word(state, 32, ((11 - mode) << 12) | (6 << 8) | 0x40);
1545 1596
@@ -1551,8 +1602,8 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1551 /* P_timf_alpha = (9-P_mode, P_corm_alpha=6, P_corm_thres=0x80 */ 1602 /* P_timf_alpha = (9-P_mode, P_corm_alpha=6, P_corm_thres=0x80 */
1552 dib8000_write_word(state, 32, ((9 - mode) << 12) | (6 << 8) | 0x80); 1603 dib8000_write_word(state, 32, ((9 - mode) << 12) | (6 << 8) | 0x80);
1553 1604
1554 if (state->fe.dtv_property_cache.isdbt_sb_mode == 1) { 1605 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
1555 if (state->fe.dtv_property_cache.isdbt_partial_reception == 0) // Sound Broadcasting mode 1 seg 1606 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0)
1556 /* P_ctrl_pha_off_max=3 P_ctrl_sfreq_inh =0 P_ctrl_sfreq_step = (11-P_mode) */ 1607 /* P_ctrl_pha_off_max=3 P_ctrl_sfreq_inh =0 P_ctrl_sfreq_step = (11-P_mode) */
1557 dib8000_write_word(state, 37, (3 << 5) | (0 << 4) | (10 - mode)); 1608 dib8000_write_word(state, 37, (3 << 5) | (0 << 4) | (10 - mode));
1558 1609
@@ -1564,7 +1615,7 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1564 dib8000_write_word(state, 37, (3 << 5) | (0 << 4) | (8 - mode)); 1615 dib8000_write_word(state, 37, (3 << 5) | (0 << 4) | (8 - mode));
1565 1616
1566 /* P_dvsy_sync_wait - reuse mode */ 1617 /* P_dvsy_sync_wait - reuse mode */
1567 switch (state->fe.dtv_property_cache.transmission_mode) { 1618 switch (state->fe[0]->dtv_property_cache.transmission_mode) {
1568 case TRANSMISSION_MODE_8K: 1619 case TRANSMISSION_MODE_8K:
1569 mode = 256; 1620 mode = 256;
1570 break; 1621 break;
@@ -1624,15 +1675,15 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1624 } 1675 }
1625 1676
1626 // ---- ANA_FE ---- 1677 // ---- ANA_FE ----
1627 if (state->fe.dtv_property_cache.isdbt_sb_mode) { 1678 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode) {
1628 if (state->fe.dtv_property_cache.isdbt_partial_reception == 1) // 3-segments 1679 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 1)
1629 ana_fe = ana_fe_coeff_3seg; 1680 ana_fe = ana_fe_coeff_3seg;
1630 else // 1-segment 1681 else // 1-segment
1631 ana_fe = ana_fe_coeff_1seg; 1682 ana_fe = ana_fe_coeff_1seg;
1632 } else 1683 } else
1633 ana_fe = ana_fe_coeff_13seg; 1684 ana_fe = ana_fe_coeff_13seg;
1634 1685
1635 if (state->fe.dtv_property_cache.isdbt_sb_mode == 1 || state->isdbt_cfg_loaded == 0) 1686 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1 || state->isdbt_cfg_loaded == 0)
1636 for (mode = 0; mode < 24; mode++) 1687 for (mode = 0; mode < 24; mode++)
1637 dib8000_write_word(state, 117 + mode, ana_fe[mode]); 1688 dib8000_write_word(state, 117 + mode, ana_fe[mode]);
1638 1689
@@ -1648,11 +1699,11 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1648 // "P_cspu_left_edge" not used => do not care 1699 // "P_cspu_left_edge" not used => do not care
1649 // "P_cspu_right_edge" not used => do not care 1700 // "P_cspu_right_edge" not used => do not care
1650 1701
1651 if (state->fe.dtv_property_cache.isdbt_sb_mode == 1) { // ISDB-Tsb 1702 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
1652 dib8000_write_word(state, 228, 1); // P_2d_mode_byp=1 1703 dib8000_write_word(state, 228, 1); // P_2d_mode_byp=1
1653 dib8000_write_word(state, 205, dib8000_read_word(state, 205) & 0xfff0); // P_cspu_win_cut = 0 1704 dib8000_write_word(state, 205, dib8000_read_word(state, 205) & 0xfff0); // P_cspu_win_cut = 0
1654 if (state->fe.dtv_property_cache.isdbt_partial_reception == 0 // 1-segment 1705 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0
1655 && state->fe.dtv_property_cache.transmission_mode == TRANSMISSION_MODE_2K) { 1706 && state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_2K) {
1656 //dib8000_write_word(state, 219, dib8000_read_word(state, 219) & 0xfffe); // P_adp_pass = 0 1707 //dib8000_write_word(state, 219, dib8000_read_word(state, 219) & 0xfffe); // P_adp_pass = 0
1657 dib8000_write_word(state, 265, 15); // P_equal_noise_sel = 15 1708 dib8000_write_word(state, 265, 15); // P_equal_noise_sel = 15
1658 } 1709 }
@@ -1664,7 +1715,7 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1664 // ---- TMCC ---- 1715 // ---- TMCC ----
1665 for (i = 0; i < 3; i++) 1716 for (i = 0; i < 3; i++)
1666 tmcc_pow += 1717 tmcc_pow +=
1667 (((state->fe.dtv_property_cache.layer[i].modulation == DQPSK) * 4 + 1) * state->fe.dtv_property_cache.layer[i].segment_count); 1718 (((state->fe[0]->dtv_property_cache.layer[i].modulation == DQPSK) * 4 + 1) * state->fe[0]->dtv_property_cache.layer[i].segment_count);
1668 // Quantif of "P_tmcc_dec_thres_?k" is (0, 5+mode, 9); 1719 // Quantif of "P_tmcc_dec_thres_?k" is (0, 5+mode, 9);
1669 // Threshold is set at 1/4 of max power. 1720 // Threshold is set at 1/4 of max power.
1670 tmcc_pow *= (1 << (9 - 2)); 1721 tmcc_pow *= (1 << (9 - 2));
@@ -1678,7 +1729,7 @@ static void dib8000_set_channel(struct dib8000_state *state, u8 seq, u8 autosear
1678 if (state->isdbt_cfg_loaded == 0) 1729 if (state->isdbt_cfg_loaded == 0)
1679 dib8000_write_word(state, 250, 3285); /*p_2d_hspeed_thr0 */ 1730 dib8000_write_word(state, 250, 3285); /*p_2d_hspeed_thr0 */
1680 1731
1681 if (state->fe.dtv_property_cache.isdbt_sb_mode == 1) 1732 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1)
1682 state->isdbt_cfg_loaded = 0; 1733 state->isdbt_cfg_loaded = 0;
1683 else 1734 else
1684 state->isdbt_cfg_loaded = 1; 1735 state->isdbt_cfg_loaded = 1;
@@ -1693,38 +1744,38 @@ static int dib8000_autosearch_start(struct dvb_frontend *fe)
1693 1744
1694 int slist = 0; 1745 int slist = 0;
1695 1746
1696 state->fe.dtv_property_cache.inversion = 0; 1747 state->fe[0]->dtv_property_cache.inversion = 0;
1697 if (!state->fe.dtv_property_cache.isdbt_sb_mode) 1748 if (!state->fe[0]->dtv_property_cache.isdbt_sb_mode)
1698 state->fe.dtv_property_cache.layer[0].segment_count = 13; 1749 state->fe[0]->dtv_property_cache.layer[0].segment_count = 13;
1699 state->fe.dtv_property_cache.layer[0].modulation = QAM_64; 1750 state->fe[0]->dtv_property_cache.layer[0].modulation = QAM_64;
1700 state->fe.dtv_property_cache.layer[0].fec = FEC_2_3; 1751 state->fe[0]->dtv_property_cache.layer[0].fec = FEC_2_3;
1701 state->fe.dtv_property_cache.layer[0].interleaving = 0; 1752 state->fe[0]->dtv_property_cache.layer[0].interleaving = 0;
1702 1753
1703 //choose the right list, in sb, always do everything 1754 //choose the right list, in sb, always do everything
1704 if (state->fe.dtv_property_cache.isdbt_sb_mode) { 1755 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode) {
1705 state->fe.dtv_property_cache.transmission_mode = TRANSMISSION_MODE_8K; 1756 state->fe[0]->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_8K;
1706 state->fe.dtv_property_cache.guard_interval = GUARD_INTERVAL_1_8; 1757 state->fe[0]->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_8;
1707 slist = 7; 1758 slist = 7;
1708 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); 1759 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13));
1709 } else { 1760 } else {
1710 if (state->fe.dtv_property_cache.guard_interval == GUARD_INTERVAL_AUTO) { 1761 if (state->fe[0]->dtv_property_cache.guard_interval == GUARD_INTERVAL_AUTO) {
1711 if (state->fe.dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO) { 1762 if (state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO) {
1712 slist = 7; 1763 slist = 7;
1713 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); // P_mode = 1 to have autosearch start ok with mode2 1764 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); // P_mode = 1 to have autosearch start ok with mode2
1714 } else 1765 } else
1715 slist = 3; 1766 slist = 3;
1716 } else { 1767 } else {
1717 if (state->fe.dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO) { 1768 if (state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO) {
1718 slist = 2; 1769 slist = 2;
1719 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); // P_mode = 1 1770 dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); // P_mode = 1
1720 } else 1771 } else
1721 slist = 0; 1772 slist = 0;
1722 } 1773 }
1723 1774
1724 if (state->fe.dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO) 1775 if (state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO)
1725 state->fe.dtv_property_cache.transmission_mode = TRANSMISSION_MODE_8K; 1776 state->fe[0]->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_8K;
1726 if (state->fe.dtv_property_cache.guard_interval == GUARD_INTERVAL_AUTO) 1777 if (state->fe[0]->dtv_property_cache.guard_interval == GUARD_INTERVAL_AUTO)
1727 state->fe.dtv_property_cache.guard_interval = GUARD_INTERVAL_1_8; 1778 state->fe[0]->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_8;
1728 1779
1729 dprintk("using list for autosearch : %d", slist); 1780 dprintk("using list for autosearch : %d", slist);
1730 dib8000_set_channel(state, (unsigned char)slist, 1); 1781 dib8000_set_channel(state, (unsigned char)slist, 1);
@@ -1786,7 +1837,7 @@ static int dib8000_tune(struct dvb_frontend *fe)
1786 if (state == NULL) 1837 if (state == NULL)
1787 return -EINVAL; 1838 return -EINVAL;
1788 1839
1789 dib8000_set_bandwidth(state, state->fe.dtv_property_cache.bandwidth_hz / 1000); 1840 dib8000_set_bandwidth(fe, state->fe[0]->dtv_property_cache.bandwidth_hz / 1000);
1790 dib8000_set_channel(state, 0, 0); 1841 dib8000_set_channel(state, 0, 0);
1791 1842
1792 // restart demod 1843 // restart demod
@@ -1799,17 +1850,16 @@ static int dib8000_tune(struct dvb_frontend *fe)
1799 1850
1800 // never achieved a lock before - wait for timfreq to update 1851 // never achieved a lock before - wait for timfreq to update
1801 if (state->timf == 0) { 1852 if (state->timf == 0) {
1802 if (state->fe.dtv_property_cache.isdbt_sb_mode == 1) { 1853 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
1803 if (state->fe.dtv_property_cache.isdbt_partial_reception == 0) // Sound Broadcasting mode 1 seg 1854 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0)
1804 msleep(300); 1855 msleep(300);
1805 else // Sound Broadcasting mode 3 seg 1856 else // Sound Broadcasting mode 3 seg
1806 msleep(500); 1857 msleep(500);
1807 } else // 13 seg 1858 } else // 13 seg
1808 msleep(200); 1859 msleep(200);
1809 } 1860 }
1810 //dump_reg(state); 1861 if (state->fe[0]->dtv_property_cache.isdbt_sb_mode == 1) {
1811 if (state->fe.dtv_property_cache.isdbt_sb_mode == 1) { 1862 if (state->fe[0]->dtv_property_cache.isdbt_partial_reception == 0) {
1812 if (state->fe.dtv_property_cache.isdbt_partial_reception == 0) { // Sound Broadcasting mode 1 seg
1813 1863
1814 /* P_timf_alpha = (13-P_mode) , P_corm_alpha=6, P_corm_thres=0x40 alpha to check on board */ 1864 /* P_timf_alpha = (13-P_mode) , P_corm_alpha=6, P_corm_thres=0x40 alpha to check on board */
1815 dib8000_write_word(state, 32, ((13 - mode) << 12) | (6 << 8) | 0x40); 1865 dib8000_write_word(state, 32, ((13 - mode) << 12) | (6 << 8) | 0x40);
@@ -1854,26 +1904,38 @@ static int dib8000_tune(struct dvb_frontend *fe)
1854static int dib8000_wakeup(struct dvb_frontend *fe) 1904static int dib8000_wakeup(struct dvb_frontend *fe)
1855{ 1905{
1856 struct dib8000_state *state = fe->demodulator_priv; 1906 struct dib8000_state *state = fe->demodulator_priv;
1907 u8 index_frontend;
1908 int ret;
1857 1909
1858 dib8000_set_power_mode(state, DIB8000M_POWER_ALL); 1910 dib8000_set_power_mode(state, DIB8000M_POWER_ALL);
1859 dib8000_set_adc_state(state, DIBX000_ADC_ON); 1911 dib8000_set_adc_state(state, DIBX000_ADC_ON);
1860 if (dib8000_set_adc_state(state, DIBX000_SLOW_ADC_ON) != 0) 1912 if (dib8000_set_adc_state(state, DIBX000_SLOW_ADC_ON) != 0)
1861 dprintk("could not start Slow ADC"); 1913 dprintk("could not start Slow ADC");
1862 1914
1915 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
1916 ret = state->fe[index_frontend]->ops.init(state->fe[index_frontend]);
1917 if (ret < 0)
1918 return ret;
1919 }
1920
1863 return 0; 1921 return 0;
1864} 1922}
1865 1923
1866static int dib8000_sleep(struct dvb_frontend *fe) 1924static int dib8000_sleep(struct dvb_frontend *fe)
1867{ 1925{
1868 struct dib8000_state *st = fe->demodulator_priv; 1926 struct dib8000_state *state = fe->demodulator_priv;
1869 if (1) { 1927 u8 index_frontend;
1870 dib8000_set_output_mode(st, OUTMODE_HIGH_Z); 1928 int ret;
1871 dib8000_set_power_mode(st, DIB8000M_POWER_INTERFACE_ONLY);
1872 return dib8000_set_adc_state(st, DIBX000_SLOW_ADC_OFF) | dib8000_set_adc_state(st, DIBX000_ADC_OFF);
1873 } else {
1874 1929
1875 return 0; 1930 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
1931 ret = state->fe[index_frontend]->ops.sleep(state->fe[index_frontend]);
1932 if (ret < 0)
1933 return ret;
1876 } 1934 }
1935
1936 dib8000_set_output_mode(fe, OUTMODE_HIGH_Z);
1937 dib8000_set_power_mode(state, DIB8000M_POWER_INTERFACE_ONLY);
1938 return dib8000_set_adc_state(state, DIBX000_SLOW_ADC_OFF) | dib8000_set_adc_state(state, DIBX000_ADC_OFF);
1877} 1939}
1878 1940
1879enum frontend_tune_state dib8000_get_tune_state(struct dvb_frontend *fe) 1941enum frontend_tune_state dib8000_get_tune_state(struct dvb_frontend *fe)
@@ -1891,16 +1953,40 @@ int dib8000_set_tune_state(struct dvb_frontend *fe, enum frontend_tune_state tun
1891} 1953}
1892EXPORT_SYMBOL(dib8000_set_tune_state); 1954EXPORT_SYMBOL(dib8000_set_tune_state);
1893 1955
1894
1895
1896
1897static int dib8000_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep) 1956static int dib8000_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
1898{ 1957{
1899 struct dib8000_state *state = fe->demodulator_priv; 1958 struct dib8000_state *state = fe->demodulator_priv;
1900 u16 i, val = 0; 1959 u16 i, val = 0;
1960 fe_status_t stat;
1961 u8 index_frontend, sub_index_frontend;
1901 1962
1902 fe->dtv_property_cache.bandwidth_hz = 6000000; 1963 fe->dtv_property_cache.bandwidth_hz = 6000000;
1903 1964
1965 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
1966 state->fe[index_frontend]->ops.read_status(state->fe[index_frontend], &stat);
1967 if (stat&FE_HAS_SYNC) {
1968 dprintk("TMCC lock on the slave%i", index_frontend);
1969 /* synchronize the cache with the other frontends */
1970 state->fe[index_frontend]->ops.get_frontend(state->fe[index_frontend], fep);
1971 for (sub_index_frontend = 0; (sub_index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[sub_index_frontend] != NULL); sub_index_frontend++) {
1972 if (sub_index_frontend != index_frontend) {
1973 state->fe[sub_index_frontend]->dtv_property_cache.isdbt_sb_mode = state->fe[index_frontend]->dtv_property_cache.isdbt_sb_mode;
1974 state->fe[sub_index_frontend]->dtv_property_cache.inversion = state->fe[index_frontend]->dtv_property_cache.inversion;
1975 state->fe[sub_index_frontend]->dtv_property_cache.transmission_mode = state->fe[index_frontend]->dtv_property_cache.transmission_mode;
1976 state->fe[sub_index_frontend]->dtv_property_cache.guard_interval = state->fe[index_frontend]->dtv_property_cache.guard_interval;
1977 state->fe[sub_index_frontend]->dtv_property_cache.isdbt_partial_reception = state->fe[index_frontend]->dtv_property_cache.isdbt_partial_reception;
1978 for (i = 0; i < 3; i++) {
1979 state->fe[sub_index_frontend]->dtv_property_cache.layer[i].segment_count = state->fe[index_frontend]->dtv_property_cache.layer[i].segment_count;
1980 state->fe[sub_index_frontend]->dtv_property_cache.layer[i].interleaving = state->fe[index_frontend]->dtv_property_cache.layer[i].interleaving;
1981 state->fe[sub_index_frontend]->dtv_property_cache.layer[i].fec = state->fe[index_frontend]->dtv_property_cache.layer[i].fec;
1982 state->fe[sub_index_frontend]->dtv_property_cache.layer[i].modulation = state->fe[index_frontend]->dtv_property_cache.layer[i].modulation;
1983 }
1984 }
1985 }
1986 return 0;
1987 }
1988 }
1989
1904 fe->dtv_property_cache.isdbt_sb_mode = dib8000_read_word(state, 508) & 0x1; 1990 fe->dtv_property_cache.isdbt_sb_mode = dib8000_read_word(state, 508) & 0x1;
1905 1991
1906 val = dib8000_read_word(state, 570); 1992 val = dib8000_read_word(state, 570);
@@ -1992,112 +2078,200 @@ static int dib8000_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
1992 break; 2078 break;
1993 } 2079 }
1994 } 2080 }
2081
2082 /* synchronize the cache with the other frontends */
2083 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
2084 state->fe[index_frontend]->dtv_property_cache.isdbt_sb_mode = fe->dtv_property_cache.isdbt_sb_mode;
2085 state->fe[index_frontend]->dtv_property_cache.inversion = fe->dtv_property_cache.inversion;
2086 state->fe[index_frontend]->dtv_property_cache.transmission_mode = fe->dtv_property_cache.transmission_mode;
2087 state->fe[index_frontend]->dtv_property_cache.guard_interval = fe->dtv_property_cache.guard_interval;
2088 state->fe[index_frontend]->dtv_property_cache.isdbt_partial_reception = fe->dtv_property_cache.isdbt_partial_reception;
2089 for (i = 0; i < 3; i++) {
2090 state->fe[index_frontend]->dtv_property_cache.layer[i].segment_count = fe->dtv_property_cache.layer[i].segment_count;
2091 state->fe[index_frontend]->dtv_property_cache.layer[i].interleaving = fe->dtv_property_cache.layer[i].interleaving;
2092 state->fe[index_frontend]->dtv_property_cache.layer[i].fec = fe->dtv_property_cache.layer[i].fec;
2093 state->fe[index_frontend]->dtv_property_cache.layer[i].modulation = fe->dtv_property_cache.layer[i].modulation;
2094 }
2095 }
1995 return 0; 2096 return 0;
1996} 2097}
1997 2098
1998static int dib8000_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep) 2099static int dib8000_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
1999{ 2100{
2000 struct dib8000_state *state = fe->demodulator_priv; 2101 struct dib8000_state *state = fe->demodulator_priv;
2102 u8 nbr_pending, exit_condition, index_frontend;
2103 s8 index_frontend_success = -1;
2001 int time, ret; 2104 int time, ret;
2105 int time_slave = FE_CALLBACK_TIME_NEVER;
2106
2107 if (state->fe[0]->dtv_property_cache.frequency == 0) {
2108 dprintk("dib8000: must at least specify frequency ");
2109 return 0;
2110 }
2111
2112 if (state->fe[0]->dtv_property_cache.bandwidth_hz == 0) {
2113 dprintk("dib8000: no bandwidth specified, set to default ");
2114 state->fe[0]->dtv_property_cache.bandwidth_hz = 6000000;
2115 }
2002 2116
2003 fe->dtv_property_cache.delivery_system = SYS_ISDBT; 2117 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
2118 /* synchronization of the cache */
2119 state->fe[index_frontend]->dtv_property_cache.delivery_system = SYS_ISDBT;
2120 memcpy(&state->fe[index_frontend]->dtv_property_cache, &fe->dtv_property_cache, sizeof(struct dtv_frontend_properties));
2004 2121
2005 dib8000_set_output_mode(state, OUTMODE_HIGH_Z); 2122 dib8000_set_output_mode(state->fe[index_frontend], OUTMODE_HIGH_Z);
2123 if (state->fe[index_frontend]->ops.tuner_ops.set_params)
2124 state->fe[index_frontend]->ops.tuner_ops.set_params(state->fe[index_frontend], fep);
2006 2125
2007 if (fe->ops.tuner_ops.set_params) 2126 dib8000_set_tune_state(state->fe[index_frontend], CT_AGC_START);
2008 fe->ops.tuner_ops.set_params(fe, fep); 2127 }
2009 2128
2010 /* start up the AGC */ 2129 /* start up the AGC */
2011 state->tune_state = CT_AGC_START;
2012 do { 2130 do {
2013 time = dib8000_agc_startup(fe); 2131 time = dib8000_agc_startup(state->fe[0]);
2132 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
2133 time_slave = dib8000_agc_startup(state->fe[index_frontend]);
2134 if (time == FE_CALLBACK_TIME_NEVER)
2135 time = time_slave;
2136 else if ((time_slave != FE_CALLBACK_TIME_NEVER) && (time_slave > time))
2137 time = time_slave;
2138 }
2014 if (time != FE_CALLBACK_TIME_NEVER) 2139 if (time != FE_CALLBACK_TIME_NEVER)
2015 msleep(time / 10); 2140 msleep(time / 10);
2016 else 2141 else
2017 break; 2142 break;
2018 } while (state->tune_state != CT_AGC_STOP); 2143 exit_condition = 1;
2019 2144 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
2020 if (state->fe.dtv_property_cache.frequency == 0) { 2145 if (dib8000_get_tune_state(state->fe[index_frontend]) != CT_AGC_STOP) {
2021 dprintk("dib8000: must at least specify frequency "); 2146 exit_condition = 0;
2022 return 0; 2147 break;
2023 } 2148 }
2024 2149 }
2025 if (state->fe.dtv_property_cache.bandwidth_hz == 0) { 2150 } while (exit_condition == 0);
2026 dprintk("dib8000: no bandwidth specified, set to default "); 2151
2027 state->fe.dtv_property_cache.bandwidth_hz = 6000000; 2152 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
2028 } 2153 dib8000_set_tune_state(state->fe[index_frontend], CT_DEMOD_START);
2154
2155 if ((state->fe[0]->dtv_property_cache.delivery_system != SYS_ISDBT) ||
2156 (state->fe[0]->dtv_property_cache.inversion == INVERSION_AUTO) ||
2157 (state->fe[0]->dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO) ||
2158 (state->fe[0]->dtv_property_cache.guard_interval == GUARD_INTERVAL_AUTO) ||
2159 (((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 0)) != 0) &&
2160 (state->fe[0]->dtv_property_cache.layer[0].segment_count != 0xff) &&
2161 (state->fe[0]->dtv_property_cache.layer[0].segment_count != 0) &&
2162 ((state->fe[0]->dtv_property_cache.layer[0].modulation == QAM_AUTO) ||
2163 (state->fe[0]->dtv_property_cache.layer[0].fec == FEC_AUTO))) ||
2164 (((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 1)) != 0) &&
2165 (state->fe[0]->dtv_property_cache.layer[1].segment_count != 0xff) &&
2166 (state->fe[0]->dtv_property_cache.layer[1].segment_count != 0) &&
2167 ((state->fe[0]->dtv_property_cache.layer[1].modulation == QAM_AUTO) ||
2168 (state->fe[0]->dtv_property_cache.layer[1].fec == FEC_AUTO))) ||
2169 (((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 2)) != 0) &&
2170 (state->fe[0]->dtv_property_cache.layer[2].segment_count != 0xff) &&
2171 (state->fe[0]->dtv_property_cache.layer[2].segment_count != 0) &&
2172 ((state->fe[0]->dtv_property_cache.layer[2].modulation == QAM_AUTO) ||
2173 (state->fe[0]->dtv_property_cache.layer[2].fec == FEC_AUTO))) ||
2174 (((state->fe[0]->dtv_property_cache.layer[0].segment_count == 0) ||
2175 ((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (1 << 0)) == 0)) &&
2176 ((state->fe[0]->dtv_property_cache.layer[1].segment_count == 0) ||
2177 ((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (2 << 0)) == 0)) &&
2178 ((state->fe[0]->dtv_property_cache.layer[2].segment_count == 0) || ((state->fe[0]->dtv_property_cache.isdbt_layer_enabled & (3 << 0)) == 0)))) {
2179 int i = 80000;
2180 u8 found = 0;
2181 u8 tune_failed = 0;
2182
2183 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
2184 dib8000_set_bandwidth(state->fe[index_frontend], fe->dtv_property_cache.bandwidth_hz / 1000);
2185 dib8000_autosearch_start(state->fe[index_frontend]);
2186 }
2029 2187
2030 state->tune_state = CT_DEMOD_START;
2031
2032 if ((state->fe.dtv_property_cache.delivery_system != SYS_ISDBT) ||
2033 (state->fe.dtv_property_cache.inversion == INVERSION_AUTO) ||
2034 (state->fe.dtv_property_cache.transmission_mode == TRANSMISSION_MODE_AUTO) ||
2035 (state->fe.dtv_property_cache.guard_interval == GUARD_INTERVAL_AUTO) ||
2036 (((state->fe.dtv_property_cache.isdbt_layer_enabled & (1 << 0)) != 0) &&
2037 (state->fe.dtv_property_cache.layer[0].segment_count != 0xff) &&
2038 (state->fe.dtv_property_cache.layer[0].segment_count != 0) &&
2039 ((state->fe.dtv_property_cache.layer[0].modulation == QAM_AUTO) ||
2040 (state->fe.dtv_property_cache.layer[0].fec == FEC_AUTO))) ||
2041 (((state->fe.dtv_property_cache.isdbt_layer_enabled & (1 << 1)) != 0) &&
2042 (state->fe.dtv_property_cache.layer[1].segment_count != 0xff) &&
2043 (state->fe.dtv_property_cache.layer[1].segment_count != 0) &&
2044 ((state->fe.dtv_property_cache.layer[1].modulation == QAM_AUTO) ||
2045 (state->fe.dtv_property_cache.layer[1].fec == FEC_AUTO))) ||
2046 (((state->fe.dtv_property_cache.isdbt_layer_enabled & (1 << 2)) != 0) &&
2047 (state->fe.dtv_property_cache.layer[2].segment_count != 0xff) &&
2048 (state->fe.dtv_property_cache.layer[2].segment_count != 0) &&
2049 ((state->fe.dtv_property_cache.layer[2].modulation == QAM_AUTO) ||
2050 (state->fe.dtv_property_cache.layer[2].fec == FEC_AUTO))) ||
2051 (((state->fe.dtv_property_cache.layer[0].segment_count == 0) ||
2052 ((state->fe.dtv_property_cache.isdbt_layer_enabled & (1 << 0)) == 0)) &&
2053 ((state->fe.dtv_property_cache.layer[1].segment_count == 0) ||
2054 ((state->fe.dtv_property_cache.isdbt_layer_enabled & (2 << 0)) == 0)) &&
2055 ((state->fe.dtv_property_cache.layer[2].segment_count == 0) || ((state->fe.dtv_property_cache.isdbt_layer_enabled & (3 << 0)) == 0)))) {
2056 int i = 800, found;
2057
2058 dib8000_set_bandwidth(state, fe->dtv_property_cache.bandwidth_hz / 1000);
2059 dib8000_autosearch_start(fe);
2060 do { 2188 do {
2061 msleep(10); 2189 msleep(20);
2062 found = dib8000_autosearch_irq(fe); 2190 nbr_pending = 0;
2063 } while (found == 0 && i--); 2191 exit_condition = 0; /* 0: tune pending; 1: tune failed; 2:tune success */
2192 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
2193 if (((tune_failed >> index_frontend) & 0x1) == 0) {
2194 found = dib8000_autosearch_irq(state->fe[index_frontend]);
2195 switch (found) {
2196 case 0: /* tune pending */
2197 nbr_pending++;
2198 break;
2199 case 2:
2200 dprintk("autosearch succeed on the frontend%i", index_frontend);
2201 exit_condition = 2;
2202 index_frontend_success = index_frontend;
2203 break;
2204 default:
2205 dprintk("unhandled autosearch result");
2206 case 1:
2207 dprintk("autosearch failed for the frontend%i", index_frontend);
2208 break;
2209 }
2210 }
2211 }
2064 2212
2065 dprintk("Frequency %d Hz, autosearch returns: %d", fep->frequency, found); 2213 /* if all tune are done and no success, exit: tune failed */
2214 if ((nbr_pending == 0) && (exit_condition == 0))
2215 exit_condition = 1;
2216 } while ((exit_condition == 0) && i--);
2066 2217
2067 if (found == 0 || found == 1) 2218 if (exit_condition == 1) { /* tune failed */
2068 return 0; // no channel found 2219 dprintk("tune failed");
2220 return 0;
2221 }
2222
2223 dprintk("tune success on frontend%i", index_frontend_success);
2069 2224
2070 dib8000_get_frontend(fe, fep); 2225 dib8000_get_frontend(fe, fep);
2071 } 2226 }
2072 2227
2073 ret = dib8000_tune(fe); 2228 for (index_frontend = 0, ret = 0; (ret >= 0) && (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
2229 ret = dib8000_tune(state->fe[index_frontend]);
2230
2231 /* set output mode and diversity input */
2232 dib8000_set_output_mode(state->fe[0], state->cfg.output_mode);
2233 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
2234 dib8000_set_output_mode(state->fe[index_frontend], OUTMODE_DIVERSITY);
2235 dib8000_set_diversity_in(state->fe[index_frontend-1], 1);
2236 }
2074 2237
2075 /* make this a config parameter */ 2238 /* turn off the diversity of the last chip */
2076 dib8000_set_output_mode(state, state->cfg.output_mode); 2239 dib8000_set_diversity_in(state->fe[index_frontend-1], 0);
2077 2240
2078 return ret; 2241 return ret;
2079} 2242}
2080 2243
2244static u16 dib8000_read_lock(struct dvb_frontend *fe)
2245{
2246 struct dib8000_state *state = fe->demodulator_priv;
2247
2248 return dib8000_read_word(state, 568);
2249}
2250
2081static int dib8000_read_status(struct dvb_frontend *fe, fe_status_t * stat) 2251static int dib8000_read_status(struct dvb_frontend *fe, fe_status_t * stat)
2082{ 2252{
2083 struct dib8000_state *state = fe->demodulator_priv; 2253 struct dib8000_state *state = fe->demodulator_priv;
2084 u16 lock = dib8000_read_word(state, 568); 2254 u16 lock_slave = 0, lock = dib8000_read_word(state, 568);
2255 u8 index_frontend;
2256
2257 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
2258 lock_slave |= dib8000_read_lock(state->fe[index_frontend]);
2085 2259
2086 *stat = 0; 2260 *stat = 0;
2087 2261
2088 if ((lock >> 13) & 1) 2262 if (((lock >> 13) & 1) || ((lock_slave >> 13) & 1))
2089 *stat |= FE_HAS_SIGNAL; 2263 *stat |= FE_HAS_SIGNAL;
2090 2264
2091 if ((lock >> 8) & 1) /* Equal */ 2265 if (((lock >> 8) & 1) || ((lock_slave >> 8) & 1)) /* Equal */
2092 *stat |= FE_HAS_CARRIER; 2266 *stat |= FE_HAS_CARRIER;
2093 2267
2094 if (((lock >> 1) & 0xf) == 0xf) /* TMCC_SYNC */ 2268 if ((((lock >> 1) & 0xf) == 0xf) || (((lock_slave >> 1) & 0xf) == 0xf)) /* TMCC_SYNC */
2095 *stat |= FE_HAS_SYNC; 2269 *stat |= FE_HAS_SYNC;
2096 2270
2097 if (((lock >> 12) & 1) && ((lock >> 5) & 7)) /* FEC MPEG */ 2271 if ((((lock >> 12) & 1) || ((lock_slave >> 12) & 1)) && ((lock >> 5) & 7)) /* FEC MPEG */
2098 *stat |= FE_HAS_LOCK; 2272 *stat |= FE_HAS_LOCK;
2099 2273
2100 if ((lock >> 12) & 1) { 2274 if (((lock >> 12) & 1) || ((lock_slave >> 12) & 1)) {
2101 lock = dib8000_read_word(state, 554); /* Viterbi Layer A */ 2275 lock = dib8000_read_word(state, 554); /* Viterbi Layer A */
2102 if (lock & 0x01) 2276 if (lock & 0x01)
2103 *stat |= FE_HAS_VITERBI; 2277 *stat |= FE_HAS_VITERBI;
@@ -2131,50 +2305,138 @@ static int dib8000_read_unc_blocks(struct dvb_frontend *fe, u32 * unc)
2131static int dib8000_read_signal_strength(struct dvb_frontend *fe, u16 * strength) 2305static int dib8000_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
2132{ 2306{
2133 struct dib8000_state *state = fe->demodulator_priv; 2307 struct dib8000_state *state = fe->demodulator_priv;
2134 u16 val = dib8000_read_word(state, 390); 2308 u8 index_frontend;
2135 *strength = 65535 - val; 2309 u16 val;
2310
2311 *strength = 0;
2312 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
2313 state->fe[index_frontend]->ops.read_signal_strength(state->fe[index_frontend], &val);
2314 if (val > 65535 - *strength)
2315 *strength = 65535;
2316 else
2317 *strength += val;
2318 }
2319
2320 val = 65535 - dib8000_read_word(state, 390);
2321 if (val > 65535 - *strength)
2322 *strength = 65535;
2323 else
2324 *strength += val;
2136 return 0; 2325 return 0;
2137} 2326}
2138 2327
2139static int dib8000_read_snr(struct dvb_frontend *fe, u16 * snr) 2328static u32 dib8000_get_snr(struct dvb_frontend *fe)
2140{ 2329{
2141 struct dib8000_state *state = fe->demodulator_priv; 2330 struct dib8000_state *state = fe->demodulator_priv;
2331 u32 n, s, exp;
2142 u16 val; 2332 u16 val;
2143 s32 signal_mant, signal_exp, noise_mant, noise_exp;
2144 u32 result = 0;
2145 2333
2146 val = dib8000_read_word(state, 542); 2334 val = dib8000_read_word(state, 542);
2147 noise_mant = (val >> 6) & 0xff; 2335 n = (val >> 6) & 0xff;
2148 noise_exp = (val & 0x3f); 2336 exp = (val & 0x3f);
2337 if ((exp & 0x20) != 0)
2338 exp -= 0x40;
2339 n <<= exp+16;
2149 2340
2150 val = dib8000_read_word(state, 543); 2341 val = dib8000_read_word(state, 543);
2151 signal_mant = (val >> 6) & 0xff; 2342 s = (val >> 6) & 0xff;
2152 signal_exp = (val & 0x3f); 2343 exp = (val & 0x3f);
2344 if ((exp & 0x20) != 0)
2345 exp -= 0x40;
2346 s <<= exp+16;
2347
2348 if (n > 0) {
2349 u32 t = (s/n) << 16;
2350 return t + ((s << 16) - n*t) / n;
2351 }
2352 return 0xffffffff;
2353}
2354
2355static int dib8000_read_snr(struct dvb_frontend *fe, u16 * snr)
2356{
2357 struct dib8000_state *state = fe->demodulator_priv;
2358 u8 index_frontend;
2359 u32 snr_master;
2153 2360
2154 if ((noise_exp & 0x20) != 0) 2361 snr_master = dib8000_get_snr(fe);
2155 noise_exp -= 0x40; 2362 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
2156 if ((signal_exp & 0x20) != 0) 2363 snr_master += dib8000_get_snr(state->fe[index_frontend]);
2157 signal_exp -= 0x40;
2158 2364
2159 if (signal_mant != 0) 2365 if (snr_master != 0) {
2160 result = intlog10(2) * 10 * signal_exp + 10 * intlog10(signal_mant); 2366 snr_master = 10*intlog10(snr_master>>16);
2161 else 2367 *snr = snr_master / ((1 << 24) / 10);
2162 result = intlog10(2) * 10 * signal_exp - 100; 2368 }
2163 if (noise_mant != 0)
2164 result -= intlog10(2) * 10 * noise_exp + 10 * intlog10(noise_mant);
2165 else 2369 else
2166 result -= intlog10(2) * 10 * noise_exp - 100; 2370 *snr = 0;
2167 2371
2168 *snr = result / ((1 << 24) / 10);
2169 return 0; 2372 return 0;
2170} 2373}
2171 2374
2375int dib8000_set_slave_frontend(struct dvb_frontend *fe, struct dvb_frontend *fe_slave)
2376{
2377 struct dib8000_state *state = fe->demodulator_priv;
2378 u8 index_frontend = 1;
2379
2380 while ((index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL))
2381 index_frontend++;
2382 if (index_frontend < MAX_NUMBER_OF_FRONTENDS) {
2383 dprintk("set slave fe %p to index %i", fe_slave, index_frontend);
2384 state->fe[index_frontend] = fe_slave;
2385 return 0;
2386 }
2387
2388 dprintk("too many slave frontend");
2389 return -ENOMEM;
2390}
2391EXPORT_SYMBOL(dib8000_set_slave_frontend);
2392
2393int dib8000_remove_slave_frontend(struct dvb_frontend *fe)
2394{
2395 struct dib8000_state *state = fe->demodulator_priv;
2396 u8 index_frontend = 1;
2397
2398 while ((index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL))
2399 index_frontend++;
2400 if (index_frontend != 1) {
2401 dprintk("remove slave fe %p (index %i)", state->fe[index_frontend-1], index_frontend-1);
2402 state->fe[index_frontend] = NULL;
2403 return 0;
2404 }
2405
2406 dprintk("no frontend to be removed");
2407 return -ENODEV;
2408}
2409EXPORT_SYMBOL(dib8000_remove_slave_frontend);
2410
2411struct dvb_frontend *dib8000_get_slave_frontend(struct dvb_frontend *fe, int slave_index)
2412{
2413 struct dib8000_state *state = fe->demodulator_priv;
2414
2415 if (slave_index >= MAX_NUMBER_OF_FRONTENDS)
2416 return NULL;
2417 return state->fe[slave_index];
2418}
2419EXPORT_SYMBOL(dib8000_get_slave_frontend);
2420
2421
2172int dib8000_i2c_enumeration(struct i2c_adapter *host, int no_of_demods, u8 default_addr, u8 first_addr) 2422int dib8000_i2c_enumeration(struct i2c_adapter *host, int no_of_demods, u8 default_addr, u8 first_addr)
2173{ 2423{
2174 int k = 0; 2424 int k = 0, ret = 0;
2175 u8 new_addr = 0; 2425 u8 new_addr = 0;
2176 struct i2c_device client = {.adap = host }; 2426 struct i2c_device client = {.adap = host };
2177 2427
2428 client.i2c_write_buffer = kzalloc(4 * sizeof(u8), GFP_KERNEL);
2429 if (!client.i2c_write_buffer) {
2430 dprintk("%s: not enough memory", __func__);
2431 return -ENOMEM;
2432 }
2433 client.i2c_read_buffer = kzalloc(4 * sizeof(u8), GFP_KERNEL);
2434 if (!client.i2c_read_buffer) {
2435 dprintk("%s: not enough memory", __func__);
2436 ret = -ENOMEM;
2437 goto error_memory;
2438 }
2439
2178 for (k = no_of_demods - 1; k >= 0; k--) { 2440 for (k = no_of_demods - 1; k >= 0; k--) {
2179 /* designated i2c address */ 2441 /* designated i2c address */
2180 new_addr = first_addr + (k << 1); 2442 new_addr = first_addr + (k << 1);
@@ -2186,7 +2448,8 @@ int dib8000_i2c_enumeration(struct i2c_adapter *host, int no_of_demods, u8 defau
2186 client.addr = default_addr; 2448 client.addr = default_addr;
2187 if (dib8000_identify(&client) == 0) { 2449 if (dib8000_identify(&client) == 0) {
2188 dprintk("#%d: not identified", k); 2450 dprintk("#%d: not identified", k);
2189 return -EINVAL; 2451 ret = -EINVAL;
2452 goto error;
2190 } 2453 }
2191 } 2454 }
2192 2455
@@ -2212,7 +2475,12 @@ int dib8000_i2c_enumeration(struct i2c_adapter *host, int no_of_demods, u8 defau
2212 dib8000_i2c_write16(&client, 1286, 0); 2475 dib8000_i2c_write16(&client, 1286, 0);
2213 } 2476 }
2214 2477
2215 return 0; 2478error:
2479 kfree(client.i2c_read_buffer);
2480error_memory:
2481 kfree(client.i2c_write_buffer);
2482
2483 return ret;
2216} 2484}
2217 2485
2218EXPORT_SYMBOL(dib8000_i2c_enumeration); 2486EXPORT_SYMBOL(dib8000_i2c_enumeration);
@@ -2227,7 +2495,13 @@ static int dib8000_fe_get_tune_settings(struct dvb_frontend *fe, struct dvb_fron
2227static void dib8000_release(struct dvb_frontend *fe) 2495static void dib8000_release(struct dvb_frontend *fe)
2228{ 2496{
2229 struct dib8000_state *st = fe->demodulator_priv; 2497 struct dib8000_state *st = fe->demodulator_priv;
2498 u8 index_frontend;
2499
2500 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (st->fe[index_frontend] != NULL); index_frontend++)
2501 dvb_frontend_detach(st->fe[index_frontend]);
2502
2230 dibx000_exit_i2c_master(&st->i2c_master); 2503 dibx000_exit_i2c_master(&st->i2c_master);
2504 kfree(st->fe[0]);
2231 kfree(st); 2505 kfree(st);
2232} 2506}
2233 2507
@@ -2242,19 +2516,19 @@ EXPORT_SYMBOL(dib8000_get_i2c_master);
2242int dib8000_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff) 2516int dib8000_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff)
2243{ 2517{
2244 struct dib8000_state *st = fe->demodulator_priv; 2518 struct dib8000_state *st = fe->demodulator_priv;
2245 u16 val = dib8000_read_word(st, 299) & 0xffef; 2519 u16 val = dib8000_read_word(st, 299) & 0xffef;
2246 val |= (onoff & 0x1) << 4; 2520 val |= (onoff & 0x1) << 4;
2247 2521
2248 dprintk("pid filter enabled %d", onoff); 2522 dprintk("pid filter enabled %d", onoff);
2249 return dib8000_write_word(st, 299, val); 2523 return dib8000_write_word(st, 299, val);
2250} 2524}
2251EXPORT_SYMBOL(dib8000_pid_filter_ctrl); 2525EXPORT_SYMBOL(dib8000_pid_filter_ctrl);
2252 2526
2253int dib8000_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff) 2527int dib8000_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff)
2254{ 2528{
2255 struct dib8000_state *st = fe->demodulator_priv; 2529 struct dib8000_state *st = fe->demodulator_priv;
2256 dprintk("Index %x, PID %d, OnOff %d", id, pid, onoff); 2530 dprintk("Index %x, PID %d, OnOff %d", id, pid, onoff);
2257 return dib8000_write_word(st, 305 + id, onoff ? (1 << 13) | pid : 0); 2531 return dib8000_write_word(st, 305 + id, onoff ? (1 << 13) | pid : 0);
2258} 2532}
2259EXPORT_SYMBOL(dib8000_pid_filter); 2533EXPORT_SYMBOL(dib8000_pid_filter);
2260 2534
@@ -2298,10 +2572,15 @@ struct dvb_frontend *dib8000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, s
2298 state = kzalloc(sizeof(struct dib8000_state), GFP_KERNEL); 2572 state = kzalloc(sizeof(struct dib8000_state), GFP_KERNEL);
2299 if (state == NULL) 2573 if (state == NULL)
2300 return NULL; 2574 return NULL;
2575 fe = kzalloc(sizeof(struct dvb_frontend), GFP_KERNEL);
2576 if (fe == NULL)
2577 goto error;
2301 2578
2302 memcpy(&state->cfg, cfg, sizeof(struct dib8000_config)); 2579 memcpy(&state->cfg, cfg, sizeof(struct dib8000_config));
2303 state->i2c.adap = i2c_adap; 2580 state->i2c.adap = i2c_adap;
2304 state->i2c.addr = i2c_addr; 2581 state->i2c.addr = i2c_addr;
2582 state->i2c.i2c_write_buffer = state->i2c_write_buffer;
2583 state->i2c.i2c_read_buffer = state->i2c_read_buffer;
2305 state->gpio_val = cfg->gpio_val; 2584 state->gpio_val = cfg->gpio_val;
2306 state->gpio_dir = cfg->gpio_dir; 2585 state->gpio_dir = cfg->gpio_dir;
2307 2586
@@ -2311,9 +2590,9 @@ struct dvb_frontend *dib8000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, s
2311 if ((state->cfg.output_mode != OUTMODE_MPEG2_SERIAL) && (state->cfg.output_mode != OUTMODE_MPEG2_PAR_GATED_CLK)) 2590 if ((state->cfg.output_mode != OUTMODE_MPEG2_SERIAL) && (state->cfg.output_mode != OUTMODE_MPEG2_PAR_GATED_CLK))
2312 state->cfg.output_mode = OUTMODE_MPEG2_FIFO; 2591 state->cfg.output_mode = OUTMODE_MPEG2_FIFO;
2313 2592
2314 fe = &state->fe; 2593 state->fe[0] = fe;
2315 fe->demodulator_priv = state; 2594 fe->demodulator_priv = state;
2316 memcpy(&state->fe.ops, &dib8000_ops, sizeof(struct dvb_frontend_ops)); 2595 memcpy(&state->fe[0]->ops, &dib8000_ops, sizeof(struct dvb_frontend_ops));
2317 2596
2318 state->timf_default = cfg->pll->timf; 2597 state->timf_default = cfg->pll->timf;
2319 2598
diff --git a/drivers/media/dvb/frontends/dib8000.h b/drivers/media/dvb/frontends/dib8000.h
index e0a9ded11df4..617f9eba3a09 100644
--- a/drivers/media/dvb/frontends/dib8000.h
+++ b/drivers/media/dvb/frontends/dib8000.h
@@ -50,6 +50,9 @@ extern int dib8000_set_tune_state(struct dvb_frontend *fe, enum frontend_tune_st
50extern enum frontend_tune_state dib8000_get_tune_state(struct dvb_frontend *fe); 50extern enum frontend_tune_state dib8000_get_tune_state(struct dvb_frontend *fe);
51extern void dib8000_pwm_agc_reset(struct dvb_frontend *fe); 51extern void dib8000_pwm_agc_reset(struct dvb_frontend *fe);
52extern s32 dib8000_get_adc_power(struct dvb_frontend *fe, u8 mode); 52extern s32 dib8000_get_adc_power(struct dvb_frontend *fe, u8 mode);
53extern int dib8000_set_slave_frontend(struct dvb_frontend *fe, struct dvb_frontend *fe_slave);
54extern int dib8000_remove_slave_frontend(struct dvb_frontend *fe);
55extern struct dvb_frontend *dib8000_get_slave_frontend(struct dvb_frontend *fe, int slave_index);
53#else 56#else
54static inline struct dvb_frontend *dib8000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg) 57static inline struct dvb_frontend *dib8000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg)
55{ 58{
@@ -111,6 +114,23 @@ static inline s32 dib8000_get_adc_power(struct dvb_frontend *fe, u8 mode)
111 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 114 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
112 return 0; 115 return 0;
113} 116}
117static inline int dib8000_set_slave_frontend(struct dvb_frontend *fe, struct dvb_frontend *fe_slave)
118{
119 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
120 return -ENODEV;
121}
122
123int dib8000_remove_slave_frontend(struct dvb_frontend *fe)
124{
125 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
126 return -ENODEV;
127}
128
129static inline struct dvb_frontend *dib8000_get_slave_frontend(struct dvb_frontend *fe, int slave_index)
130{
131 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
132 return NULL;
133}
114#endif 134#endif
115 135
116#endif 136#endif
diff --git a/drivers/media/dvb/frontends/dib9000.c b/drivers/media/dvb/frontends/dib9000.c
new file mode 100644
index 000000000000..a0855883b5ce
--- /dev/null
+++ b/drivers/media/dvb/frontends/dib9000.c
@@ -0,0 +1,2403 @@
1/*
2 * Linux-DVB Driver for DiBcom's DiB9000 and demodulator-family.
3 *
4 * Copyright (C) 2005-10 DiBcom (http://www.dibcom.fr/)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 */
10#include <linux/kernel.h>
11#include <linux/i2c.h>
12#include <linux/mutex.h>
13
14#include "dvb_math.h"
15#include "dvb_frontend.h"
16
17#include "dib9000.h"
18#include "dibx000_common.h"
19
20static int debug;
21module_param(debug, int, 0644);
22MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
23
24#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB9000: "); printk(args); printk("\n"); } } while (0)
25#define MAX_NUMBER_OF_FRONTENDS 6
26
27struct i2c_device {
28 struct i2c_adapter *i2c_adap;
29 u8 i2c_addr;
30 u8 *i2c_read_buffer;
31 u8 *i2c_write_buffer;
32};
33
34/* lock */
35#define DIB_LOCK struct mutex
36#define DibAcquireLock(lock) do { if (mutex_lock_interruptible(lock) < 0) dprintk("could not get the lock"); } while (0)
37#define DibReleaseLock(lock) mutex_unlock(lock)
38#define DibInitLock(lock) mutex_init(lock)
39#define DibFreeLock(lock)
40
41struct dib9000_state {
42 struct i2c_device i2c;
43
44 struct dibx000_i2c_master i2c_master;
45 struct i2c_adapter tuner_adap;
46 struct i2c_adapter component_bus;
47
48 u16 revision;
49 u8 reg_offs;
50
51 enum frontend_tune_state tune_state;
52 u32 status;
53 struct dvb_frontend_parametersContext channel_status;
54
55 u8 fe_id;
56
57#define DIB9000_GPIO_DEFAULT_DIRECTIONS 0xffff
58 u16 gpio_dir;
59#define DIB9000_GPIO_DEFAULT_VALUES 0x0000
60 u16 gpio_val;
61#define DIB9000_GPIO_DEFAULT_PWM_POS 0xffff
62 u16 gpio_pwm_pos;
63
64 union { /* common for all chips */
65 struct {
66 u8 mobile_mode:1;
67 } host;
68
69 struct {
70 struct dib9000_fe_memory_map {
71 u16 addr;
72 u16 size;
73 } fe_mm[18];
74 u8 memcmd;
75
76 DIB_LOCK mbx_if_lock; /* to protect read/write operations */
77 DIB_LOCK mbx_lock; /* to protect the whole mailbox handling */
78
79 DIB_LOCK mem_lock; /* to protect the memory accesses */
80 DIB_LOCK mem_mbx_lock; /* to protect the memory-based mailbox */
81
82#define MBX_MAX_WORDS (256 - 200 - 2)
83#define DIB9000_MSG_CACHE_SIZE 2
84 u16 message_cache[DIB9000_MSG_CACHE_SIZE][MBX_MAX_WORDS];
85 u8 fw_is_running;
86 } risc;
87 } platform;
88
89 union { /* common for all platforms */
90 struct {
91 struct dib9000_config cfg;
92 } d9;
93 } chip;
94
95 struct dvb_frontend *fe[MAX_NUMBER_OF_FRONTENDS];
96 u16 component_bus_speed;
97
98 /* for the I2C transfer */
99 struct i2c_msg msg[2];
100 u8 i2c_write_buffer[255];
101 u8 i2c_read_buffer[255];
102};
103
104static const u32 fe_info[44] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
106 0, 0, 0, 0, 0, 0, 0, 0
107};
108
109enum dib9000_power_mode {
110 DIB9000_POWER_ALL = 0,
111
112 DIB9000_POWER_NO,
113 DIB9000_POWER_INTERF_ANALOG_AGC,
114 DIB9000_POWER_COR4_DINTLV_ICIRM_EQUAL_CFROD,
115 DIB9000_POWER_COR4_CRY_ESRAM_MOUT_NUD,
116 DIB9000_POWER_INTERFACE_ONLY,
117};
118
119enum dib9000_out_messages {
120 OUT_MSG_HBM_ACK,
121 OUT_MSG_HOST_BUF_FAIL,
122 OUT_MSG_REQ_VERSION,
123 OUT_MSG_BRIDGE_I2C_W,
124 OUT_MSG_BRIDGE_I2C_R,
125 OUT_MSG_BRIDGE_APB_W,
126 OUT_MSG_BRIDGE_APB_R,
127 OUT_MSG_SCAN_CHANNEL,
128 OUT_MSG_MONIT_DEMOD,
129 OUT_MSG_CONF_GPIO,
130 OUT_MSG_DEBUG_HELP,
131 OUT_MSG_SUBBAND_SEL,
132 OUT_MSG_ENABLE_TIME_SLICE,
133 OUT_MSG_FE_FW_DL,
134 OUT_MSG_FE_CHANNEL_SEARCH,
135 OUT_MSG_FE_CHANNEL_TUNE,
136 OUT_MSG_FE_SLEEP,
137 OUT_MSG_FE_SYNC,
138 OUT_MSG_CTL_MONIT,
139
140 OUT_MSG_CONF_SVC,
141 OUT_MSG_SET_HBM,
142 OUT_MSG_INIT_DEMOD,
143 OUT_MSG_ENABLE_DIVERSITY,
144 OUT_MSG_SET_OUTPUT_MODE,
145 OUT_MSG_SET_PRIORITARY_CHANNEL,
146 OUT_MSG_ACK_FRG,
147 OUT_MSG_INIT_PMU,
148};
149
150enum dib9000_in_messages {
151 IN_MSG_DATA,
152 IN_MSG_FRAME_INFO,
153 IN_MSG_CTL_MONIT,
154 IN_MSG_ACK_FREE_ITEM,
155 IN_MSG_DEBUG_BUF,
156 IN_MSG_MPE_MONITOR,
157 IN_MSG_RAWTS_MONITOR,
158 IN_MSG_END_BRIDGE_I2C_RW,
159 IN_MSG_END_BRIDGE_APB_RW,
160 IN_MSG_VERSION,
161 IN_MSG_END_OF_SCAN,
162 IN_MSG_MONIT_DEMOD,
163 IN_MSG_ERROR,
164 IN_MSG_FE_FW_DL_DONE,
165 IN_MSG_EVENT,
166 IN_MSG_ACK_CHANGE_SVC,
167 IN_MSG_HBM_PROF,
168};
169
170/* memory_access requests */
171#define FE_MM_W_CHANNEL 0
172#define FE_MM_W_FE_INFO 1
173#define FE_MM_RW_SYNC 2
174
175#define FE_SYNC_CHANNEL 1
176#define FE_SYNC_W_GENERIC_MONIT 2
177#define FE_SYNC_COMPONENT_ACCESS 3
178
179#define FE_MM_R_CHANNEL_SEARCH_STATE 3
180#define FE_MM_R_CHANNEL_UNION_CONTEXT 4
181#define FE_MM_R_FE_INFO 5
182#define FE_MM_R_FE_MONITOR 6
183
184#define FE_MM_W_CHANNEL_HEAD 7
185#define FE_MM_W_CHANNEL_UNION 8
186#define FE_MM_W_CHANNEL_CONTEXT 9
187#define FE_MM_R_CHANNEL_UNION 10
188#define FE_MM_R_CHANNEL_CONTEXT 11
189#define FE_MM_R_CHANNEL_TUNE_STATE 12
190
191#define FE_MM_R_GENERIC_MONITORING_SIZE 13
192#define FE_MM_W_GENERIC_MONITORING 14
193#define FE_MM_R_GENERIC_MONITORING 15
194
195#define FE_MM_W_COMPONENT_ACCESS 16
196#define FE_MM_RW_COMPONENT_ACCESS_BUFFER 17
197static int dib9000_risc_apb_access_read(struct dib9000_state *state, u32 address, u16 attribute, const u8 * tx, u32 txlen, u8 * b, u32 len);
198static int dib9000_risc_apb_access_write(struct dib9000_state *state, u32 address, u16 attribute, const u8 * b, u32 len);
199
200static u16 to_fw_output_mode(u16 mode)
201{
202 switch (mode) {
203 case OUTMODE_HIGH_Z:
204 return 0;
205 case OUTMODE_MPEG2_PAR_GATED_CLK:
206 return 4;
207 case OUTMODE_MPEG2_PAR_CONT_CLK:
208 return 8;
209 case OUTMODE_MPEG2_SERIAL:
210 return 16;
211 case OUTMODE_DIVERSITY:
212 return 128;
213 case OUTMODE_MPEG2_FIFO:
214 return 2;
215 case OUTMODE_ANALOG_ADC:
216 return 1;
217 default:
218 return 0;
219 }
220}
221
222static u16 dib9000_read16_attr(struct dib9000_state *state, u16 reg, u8 * b, u32 len, u16 attribute)
223{
224 u32 chunk_size = 126;
225 u32 l;
226 int ret;
227
228 if (state->platform.risc.fw_is_running && (reg < 1024))
229 return dib9000_risc_apb_access_read(state, reg, attribute, NULL, 0, b, len);
230
231 memset(state->msg, 0, 2 * sizeof(struct i2c_msg));
232 state->msg[0].addr = state->i2c.i2c_addr >> 1;
233 state->msg[0].flags = 0;
234 state->msg[0].buf = state->i2c_write_buffer;
235 state->msg[0].len = 2;
236 state->msg[1].addr = state->i2c.i2c_addr >> 1;
237 state->msg[1].flags = I2C_M_RD;
238 state->msg[1].buf = b;
239 state->msg[1].len = len;
240
241 state->i2c_write_buffer[0] = reg >> 8;
242 state->i2c_write_buffer[1] = reg & 0xff;
243
244 if (attribute & DATA_BUS_ACCESS_MODE_8BIT)
245 state->i2c_write_buffer[0] |= (1 << 5);
246 if (attribute & DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT)
247 state->i2c_write_buffer[0] |= (1 << 4);
248
249 do {
250 l = len < chunk_size ? len : chunk_size;
251 state->msg[1].len = l;
252 state->msg[1].buf = b;
253 ret = i2c_transfer(state->i2c.i2c_adap, state->msg, 2) != 2 ? -EREMOTEIO : 0;
254 if (ret != 0) {
255 dprintk("i2c read error on %d", reg);
256 return -EREMOTEIO;
257 }
258
259 b += l;
260 len -= l;
261
262 if (!(attribute & DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT))
263 reg += l / 2;
264 } while ((ret == 0) && len);
265
266 return 0;
267}
268
269static u16 dib9000_i2c_read16(struct i2c_device *i2c, u16 reg)
270{
271 struct i2c_msg msg[2] = {
272 {.addr = i2c->i2c_addr >> 1, .flags = 0,
273 .buf = i2c->i2c_write_buffer, .len = 2},
274 {.addr = i2c->i2c_addr >> 1, .flags = I2C_M_RD,
275 .buf = i2c->i2c_read_buffer, .len = 2},
276 };
277
278 i2c->i2c_write_buffer[0] = reg >> 8;
279 i2c->i2c_write_buffer[1] = reg & 0xff;
280
281 if (i2c_transfer(i2c->i2c_adap, msg, 2) != 2) {
282 dprintk("read register %x error", reg);
283 return 0;
284 }
285
286 return (i2c->i2c_read_buffer[0] << 8) | i2c->i2c_read_buffer[1];
287}
288
289static inline u16 dib9000_read_word(struct dib9000_state *state, u16 reg)
290{
291 if (dib9000_read16_attr(state, reg, state->i2c_read_buffer, 2, 0) != 0)
292 return 0;
293 return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
294}
295
296static inline u16 dib9000_read_word_attr(struct dib9000_state *state, u16 reg, u16 attribute)
297{
298 if (dib9000_read16_attr(state, reg, state->i2c_read_buffer, 2,
299 attribute) != 0)
300 return 0;
301 return (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
302}
303
304#define dib9000_read16_noinc_attr(state, reg, b, len, attribute) dib9000_read16_attr(state, reg, b, len, (attribute) | DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT)
305
306static u16 dib9000_write16_attr(struct dib9000_state *state, u16 reg, const u8 * buf, u32 len, u16 attribute)
307{
308 u32 chunk_size = 126;
309 u32 l;
310 int ret;
311
312 if (state->platform.risc.fw_is_running && (reg < 1024)) {
313 if (dib9000_risc_apb_access_write
314 (state, reg, DATA_BUS_ACCESS_MODE_16BIT | DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT | attribute, buf, len) != 0)
315 return -EINVAL;
316 return 0;
317 }
318
319 memset(&state->msg[0], 0, sizeof(struct i2c_msg));
320 state->msg[0].addr = state->i2c.i2c_addr >> 1;
321 state->msg[0].flags = 0;
322 state->msg[0].buf = state->i2c_write_buffer;
323 state->msg[0].len = len + 2;
324
325 state->i2c_write_buffer[0] = (reg >> 8) & 0xff;
326 state->i2c_write_buffer[1] = (reg) & 0xff;
327
328 if (attribute & DATA_BUS_ACCESS_MODE_8BIT)
329 state->i2c_write_buffer[0] |= (1 << 5);
330 if (attribute & DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT)
331 state->i2c_write_buffer[0] |= (1 << 4);
332
333 do {
334 l = len < chunk_size ? len : chunk_size;
335 state->msg[0].len = l + 2;
336 memcpy(&state->i2c_write_buffer[2], buf, l);
337
338 ret = i2c_transfer(state->i2c.i2c_adap, state->msg, 1) != 1 ? -EREMOTEIO : 0;
339
340 buf += l;
341 len -= l;
342
343 if (!(attribute & DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT))
344 reg += l / 2;
345 } while ((ret == 0) && len);
346
347 return ret;
348}
349
350static int dib9000_i2c_write16(struct i2c_device *i2c, u16 reg, u16 val)
351{
352 struct i2c_msg msg = {
353 .addr = i2c->i2c_addr >> 1, .flags = 0,
354 .buf = i2c->i2c_write_buffer, .len = 4
355 };
356
357 i2c->i2c_write_buffer[0] = (reg >> 8) & 0xff;
358 i2c->i2c_write_buffer[1] = reg & 0xff;
359 i2c->i2c_write_buffer[2] = (val >> 8) & 0xff;
360 i2c->i2c_write_buffer[3] = val & 0xff;
361
362 return i2c_transfer(i2c->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
363}
364
365static inline int dib9000_write_word(struct dib9000_state *state, u16 reg, u16 val)
366{
367 u8 b[2] = { val >> 8, val & 0xff };
368 return dib9000_write16_attr(state, reg, b, 2, 0);
369}
370
371static inline int dib9000_write_word_attr(struct dib9000_state *state, u16 reg, u16 val, u16 attribute)
372{
373 u8 b[2] = { val >> 8, val & 0xff };
374 return dib9000_write16_attr(state, reg, b, 2, attribute);
375}
376
377#define dib9000_write(state, reg, buf, len) dib9000_write16_attr(state, reg, buf, len, 0)
378#define dib9000_write16_noinc(state, reg, buf, len) dib9000_write16_attr(state, reg, buf, len, DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT)
379#define dib9000_write16_noinc_attr(state, reg, buf, len, attribute) dib9000_write16_attr(state, reg, buf, len, DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT | (attribute))
380
381#define dib9000_mbx_send(state, id, data, len) dib9000_mbx_send_attr(state, id, data, len, 0)
382#define dib9000_mbx_get_message(state, id, msg, len) dib9000_mbx_get_message_attr(state, id, msg, len, 0)
383
384#define MAC_IRQ (1 << 1)
385#define IRQ_POL_MSK (1 << 4)
386
387#define dib9000_risc_mem_read_chunks(state, b, len) dib9000_read16_attr(state, 1063, b, len, DATA_BUS_ACCESS_MODE_8BIT | DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT)
388#define dib9000_risc_mem_write_chunks(state, buf, len) dib9000_write16_attr(state, 1063, buf, len, DATA_BUS_ACCESS_MODE_8BIT | DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT)
389
390static void dib9000_risc_mem_setup_cmd(struct dib9000_state *state, u32 addr, u32 len, u8 reading)
391{
392 u8 b[14] = { 0 };
393
394/* dprintk("%d memcmd: %d %d %d\n", state->fe_id, addr, addr+len, len); */
395/* b[0] = 0 << 7; */
396 b[1] = 1;
397
398/* b[2] = 0; */
399/* b[3] = 0; */
400 b[4] = (u8) (addr >> 8);
401 b[5] = (u8) (addr & 0xff);
402
403/* b[10] = 0; */
404/* b[11] = 0; */
405 b[12] = (u8) (addr >> 8);
406 b[13] = (u8) (addr & 0xff);
407
408 addr += len;
409/* b[6] = 0; */
410/* b[7] = 0; */
411 b[8] = (u8) (addr >> 8);
412 b[9] = (u8) (addr & 0xff);
413
414 dib9000_write(state, 1056, b, 14);
415 if (reading)
416 dib9000_write_word(state, 1056, (1 << 15) | 1);
417 state->platform.risc.memcmd = -1; /* if it was called directly reset it - to force a future setup-call to set it */
418}
419
420static void dib9000_risc_mem_setup(struct dib9000_state *state, u8 cmd)
421{
422 struct dib9000_fe_memory_map *m = &state->platform.risc.fe_mm[cmd & 0x7f];
423 /* decide whether we need to "refresh" the memory controller */
424 if (state->platform.risc.memcmd == cmd && /* same command */
425 !(cmd & 0x80 && m->size < 67)) /* and we do not want to read something with less than 67 bytes looping - working around a bug in the memory controller */
426 return;
427 dib9000_risc_mem_setup_cmd(state, m->addr, m->size, cmd & 0x80);
428 state->platform.risc.memcmd = cmd;
429}
430
431static int dib9000_risc_mem_read(struct dib9000_state *state, u8 cmd, u8 * b, u16 len)
432{
433 if (!state->platform.risc.fw_is_running)
434 return -EIO;
435
436 DibAcquireLock(&state->platform.risc.mem_lock);
437 dib9000_risc_mem_setup(state, cmd | 0x80);
438 dib9000_risc_mem_read_chunks(state, b, len);
439 DibReleaseLock(&state->platform.risc.mem_lock);
440 return 0;
441}
442
443static int dib9000_risc_mem_write(struct dib9000_state *state, u8 cmd, const u8 * b)
444{
445 struct dib9000_fe_memory_map *m = &state->platform.risc.fe_mm[cmd];
446 if (!state->platform.risc.fw_is_running)
447 return -EIO;
448
449 DibAcquireLock(&state->platform.risc.mem_lock);
450 dib9000_risc_mem_setup(state, cmd);
451 dib9000_risc_mem_write_chunks(state, b, m->size);
452 DibReleaseLock(&state->platform.risc.mem_lock);
453 return 0;
454}
455
456static int dib9000_firmware_download(struct dib9000_state *state, u8 risc_id, u16 key, const u8 * code, u32 len)
457{
458 u16 offs;
459
460 if (risc_id == 1)
461 offs = 16;
462 else
463 offs = 0;
464
465 /* config crtl reg */
466 dib9000_write_word(state, 1024 + offs, 0x000f);
467 dib9000_write_word(state, 1025 + offs, 0);
468 dib9000_write_word(state, 1031 + offs, key);
469
470 dprintk("going to download %dB of microcode", len);
471 if (dib9000_write16_noinc(state, 1026 + offs, (u8 *) code, (u16) len) != 0) {
472 dprintk("error while downloading microcode for RISC %c", 'A' + risc_id);
473 return -EIO;
474 }
475
476 dprintk("Microcode for RISC %c loaded", 'A' + risc_id);
477
478 return 0;
479}
480
481static int dib9000_mbx_host_init(struct dib9000_state *state, u8 risc_id)
482{
483 u16 mbox_offs;
484 u16 reset_reg;
485 u16 tries = 1000;
486
487 if (risc_id == 1)
488 mbox_offs = 16;
489 else
490 mbox_offs = 0;
491
492 /* Reset mailbox */
493 dib9000_write_word(state, 1027 + mbox_offs, 0x8000);
494
495 /* Read reset status */
496 do {
497 reset_reg = dib9000_read_word(state, 1027 + mbox_offs);
498 msleep(100);
499 } while ((reset_reg & 0x8000) && --tries);
500
501 if (reset_reg & 0x8000) {
502 dprintk("MBX: init ERROR, no response from RISC %c", 'A' + risc_id);
503 return -EIO;
504 }
505 dprintk("MBX: initialized");
506 return 0;
507}
508
509#define MAX_MAILBOX_TRY 100
510static int dib9000_mbx_send_attr(struct dib9000_state *state, u8 id, u16 * data, u8 len, u16 attr)
511{
512 u8 *d, b[2];
513 u16 tmp;
514 u16 size;
515 u32 i;
516 int ret = 0;
517
518 if (!state->platform.risc.fw_is_running)
519 return -EINVAL;
520
521 DibAcquireLock(&state->platform.risc.mbx_if_lock);
522 tmp = MAX_MAILBOX_TRY;
523 do {
524 size = dib9000_read_word_attr(state, 1043, attr) & 0xff;
525 if ((size + len + 1) > MBX_MAX_WORDS && --tmp) {
526 dprintk("MBX: RISC mbx full, retrying");
527 msleep(100);
528 } else
529 break;
530 } while (1);
531
532 /*dprintk( "MBX: size: %d", size); */
533
534 if (tmp == 0) {
535 ret = -EINVAL;
536 goto out;
537 }
538#ifdef DUMP_MSG
539 dprintk("--> %02x %d ", id, len + 1);
540 for (i = 0; i < len; i++)
541 dprintk("%04x ", data[i]);
542 dprintk("\n");
543#endif
544
545 /* byte-order conversion - works on big (where it is not necessary) or little endian */
546 d = (u8 *) data;
547 for (i = 0; i < len; i++) {
548 tmp = data[i];
549 *d++ = tmp >> 8;
550 *d++ = tmp & 0xff;
551 }
552
553 /* write msg */
554 b[0] = id;
555 b[1] = len + 1;
556 if (dib9000_write16_noinc_attr(state, 1045, b, 2, attr) != 0 || dib9000_write16_noinc_attr(state, 1045, (u8 *) data, len * 2, attr) != 0) {
557 ret = -EIO;
558 goto out;
559 }
560
561 /* update register nb_mes_in_RX */
562 ret = (u8) dib9000_write_word_attr(state, 1043, 1 << 14, attr);
563
564out:
565 DibReleaseLock(&state->platform.risc.mbx_if_lock);
566
567 return ret;
568}
569
570static u8 dib9000_mbx_read(struct dib9000_state *state, u16 * data, u8 risc_id, u16 attr)
571{
572#ifdef DUMP_MSG
573 u16 *d = data;
574#endif
575
576 u16 tmp, i;
577 u8 size;
578 u8 mc_base;
579
580 if (!state->platform.risc.fw_is_running)
581 return 0;
582
583 DibAcquireLock(&state->platform.risc.mbx_if_lock);
584 if (risc_id == 1)
585 mc_base = 16;
586 else
587 mc_base = 0;
588
589 /* Length and type in the first word */
590 *data = dib9000_read_word_attr(state, 1029 + mc_base, attr);
591
592 size = *data & 0xff;
593 if (size <= MBX_MAX_WORDS) {
594 data++;
595 size--; /* Initial word already read */
596
597 dib9000_read16_noinc_attr(state, 1029 + mc_base, (u8 *) data, size * 2, attr);
598
599 /* to word conversion */
600 for (i = 0; i < size; i++) {
601 tmp = *data;
602 *data = (tmp >> 8) | (tmp << 8);
603 data++;
604 }
605
606#ifdef DUMP_MSG
607 dprintk("<-- ");
608 for (i = 0; i < size + 1; i++)
609 dprintk("%04x ", d[i]);
610 dprintk("\n");
611#endif
612 } else {
613 dprintk("MBX: message is too big for message cache (%d), flushing message", size);
614 size--; /* Initial word already read */
615 while (size--)
616 dib9000_read16_noinc_attr(state, 1029 + mc_base, (u8 *) data, 2, attr);
617 }
618 /* Update register nb_mes_in_TX */
619 dib9000_write_word_attr(state, 1028 + mc_base, 1 << 14, attr);
620
621 DibReleaseLock(&state->platform.risc.mbx_if_lock);
622
623 return size + 1;
624}
625
626static int dib9000_risc_debug_buf(struct dib9000_state *state, u16 * data, u8 size)
627{
628 u32 ts = data[1] << 16 | data[0];
629 char *b = (char *)&data[2];
630
631 b[2 * (size - 2) - 1] = '\0'; /* Bullet proof the buffer */
632 if (*b == '~') {
633 b++;
634 dprintk(b);
635 } else
636 dprintk("RISC%d: %d.%04d %s", state->fe_id, ts / 10000, ts % 10000, *b ? b : "<emtpy>");
637 return 1;
638}
639
640static int dib9000_mbx_fetch_to_cache(struct dib9000_state *state, u16 attr)
641{
642 int i;
643 u8 size;
644 u16 *block;
645 /* find a free slot */
646 for (i = 0; i < DIB9000_MSG_CACHE_SIZE; i++) {
647 block = state->platform.risc.message_cache[i];
648 if (*block == 0) {
649 size = dib9000_mbx_read(state, block, 1, attr);
650
651/* dprintk( "MBX: fetched %04x message to cache", *block); */
652
653 switch (*block >> 8) {
654 case IN_MSG_DEBUG_BUF:
655 dib9000_risc_debug_buf(state, block + 1, size); /* debug-messages are going to be printed right away */
656 *block = 0; /* free the block */
657 break;
658#if 0
659 case IN_MSG_DATA: /* FE-TRACE */
660 dib9000_risc_data_process(state, block + 1, size);
661 *block = 0;
662 break;
663#endif
664 default:
665 break;
666 }
667
668 return 1;
669 }
670 }
671 dprintk("MBX: no free cache-slot found for new message...");
672 return -1;
673}
674
675static u8 dib9000_mbx_count(struct dib9000_state *state, u8 risc_id, u16 attr)
676{
677 if (risc_id == 0)
678 return (u8) (dib9000_read_word_attr(state, 1028, attr) >> 10) & 0x1f; /* 5 bit field */
679 else
680 return (u8) (dib9000_read_word_attr(state, 1044, attr) >> 8) & 0x7f; /* 7 bit field */
681}
682
683static int dib9000_mbx_process(struct dib9000_state *state, u16 attr)
684{
685 int ret = 0;
686 u16 tmp;
687
688 if (!state->platform.risc.fw_is_running)
689 return -1;
690
691 DibAcquireLock(&state->platform.risc.mbx_lock);
692
693 if (dib9000_mbx_count(state, 1, attr)) /* 1=RiscB */
694 ret = dib9000_mbx_fetch_to_cache(state, attr);
695
696 tmp = dib9000_read_word_attr(state, 1229, attr); /* Clear the IRQ */
697/* if (tmp) */
698/* dprintk( "cleared IRQ: %x", tmp); */
699 DibReleaseLock(&state->platform.risc.mbx_lock);
700
701 return ret;
702}
703
704static int dib9000_mbx_get_message_attr(struct dib9000_state *state, u16 id, u16 * msg, u8 * size, u16 attr)
705{
706 u8 i;
707 u16 *block;
708 u16 timeout = 30;
709
710 *msg = 0;
711 do {
712 /* dib9000_mbx_get_from_cache(); */
713 for (i = 0; i < DIB9000_MSG_CACHE_SIZE; i++) {
714 block = state->platform.risc.message_cache[i];
715 if ((*block >> 8) == id) {
716 *size = (*block & 0xff) - 1;
717 memcpy(msg, block + 1, (*size) * 2);
718 *block = 0; /* free the block */
719 i = 0; /* signal that we found a message */
720 break;
721 }
722 }
723
724 if (i == 0)
725 break;
726
727 if (dib9000_mbx_process(state, attr) == -1) /* try to fetch one message - if any */
728 return -1;
729
730 } while (--timeout);
731
732 if (timeout == 0) {
733 dprintk("waiting for message %d timed out", id);
734 return -1;
735 }
736
737 return i == 0;
738}
739
740static int dib9000_risc_check_version(struct dib9000_state *state)
741{
742 u8 r[4];
743 u8 size;
744 u16 fw_version = 0;
745
746 if (dib9000_mbx_send(state, OUT_MSG_REQ_VERSION, &fw_version, 1) != 0)
747 return -EIO;
748
749 if (dib9000_mbx_get_message(state, IN_MSG_VERSION, (u16 *) r, &size) < 0)
750 return -EIO;
751
752 fw_version = (r[0] << 8) | r[1];
753 dprintk("RISC: ver: %d.%02d (IC: %d)", fw_version >> 10, fw_version & 0x3ff, (r[2] << 8) | r[3]);
754
755 if ((fw_version >> 10) != 7)
756 return -EINVAL;
757
758 switch (fw_version & 0x3ff) {
759 case 11:
760 case 12:
761 case 14:
762 case 15:
763 case 16:
764 case 17:
765 break;
766 default:
767 dprintk("RISC: invalid firmware version");
768 return -EINVAL;
769 }
770
771 dprintk("RISC: valid firmware version");
772 return 0;
773}
774
775static int dib9000_fw_boot(struct dib9000_state *state, const u8 * codeA, u32 lenA, const u8 * codeB, u32 lenB)
776{
777 /* Reconfig pool mac ram */
778 dib9000_write_word(state, 1225, 0x02); /* A: 8k C, 4 k D - B: 32k C 6 k D - IRAM 96k */
779 dib9000_write_word(state, 1226, 0x05);
780
781 /* Toggles IP crypto to Host APB interface. */
782 dib9000_write_word(state, 1542, 1);
783
784 /* Set jump and no jump in the dma box */
785 dib9000_write_word(state, 1074, 0);
786 dib9000_write_word(state, 1075, 0);
787
788 /* Set MAC as APB Master. */
789 dib9000_write_word(state, 1237, 0);
790
791 /* Reset the RISCs */
792 if (codeA != NULL)
793 dib9000_write_word(state, 1024, 2);
794 else
795 dib9000_write_word(state, 1024, 15);
796 if (codeB != NULL)
797 dib9000_write_word(state, 1040, 2);
798
799 if (codeA != NULL)
800 dib9000_firmware_download(state, 0, 0x1234, codeA, lenA);
801 if (codeB != NULL)
802 dib9000_firmware_download(state, 1, 0x1234, codeB, lenB);
803
804 /* Run the RISCs */
805 if (codeA != NULL)
806 dib9000_write_word(state, 1024, 0);
807 if (codeB != NULL)
808 dib9000_write_word(state, 1040, 0);
809
810 if (codeA != NULL)
811 if (dib9000_mbx_host_init(state, 0) != 0)
812 return -EIO;
813 if (codeB != NULL)
814 if (dib9000_mbx_host_init(state, 1) != 0)
815 return -EIO;
816
817 msleep(100);
818 state->platform.risc.fw_is_running = 1;
819
820 if (dib9000_risc_check_version(state) != 0)
821 return -EINVAL;
822
823 state->platform.risc.memcmd = 0xff;
824 return 0;
825}
826
827static u16 dib9000_identify(struct i2c_device *client)
828{
829 u16 value;
830
831 value = dib9000_i2c_read16(client, 896);
832 if (value != 0x01b3) {
833 dprintk("wrong Vendor ID (0x%x)", value);
834 return 0;
835 }
836
837 value = dib9000_i2c_read16(client, 897);
838 if (value != 0x4000 && value != 0x4001 && value != 0x4002 && value != 0x4003 && value != 0x4004 && value != 0x4005) {
839 dprintk("wrong Device ID (0x%x)", value);
840 return 0;
841 }
842
843 /* protect this driver to be used with 7000PC */
844 if (value == 0x4000 && dib9000_i2c_read16(client, 769) == 0x4000) {
845 dprintk("this driver does not work with DiB7000PC");
846 return 0;
847 }
848
849 switch (value) {
850 case 0x4000:
851 dprintk("found DiB7000MA/PA/MB/PB");
852 break;
853 case 0x4001:
854 dprintk("found DiB7000HC");
855 break;
856 case 0x4002:
857 dprintk("found DiB7000MC");
858 break;
859 case 0x4003:
860 dprintk("found DiB9000A");
861 break;
862 case 0x4004:
863 dprintk("found DiB9000H");
864 break;
865 case 0x4005:
866 dprintk("found DiB9000M");
867 break;
868 }
869
870 return value;
871}
872
873static void dib9000_set_power_mode(struct dib9000_state *state, enum dib9000_power_mode mode)
874{
875 /* by default everything is going to be powered off */
876 u16 reg_903 = 0x3fff, reg_904 = 0xffff, reg_905 = 0xffff, reg_906;
877 u8 offset;
878
879 if (state->revision == 0x4003 || state->revision == 0x4004 || state->revision == 0x4005)
880 offset = 1;
881 else
882 offset = 0;
883
884 reg_906 = dib9000_read_word(state, 906 + offset) | 0x3; /* keep settings for RISC */
885
886 /* now, depending on the requested mode, we power on */
887 switch (mode) {
888 /* power up everything in the demod */
889 case DIB9000_POWER_ALL:
890 reg_903 = 0x0000;
891 reg_904 = 0x0000;
892 reg_905 = 0x0000;
893 reg_906 = 0x0000;
894 break;
895
896 /* just leave power on the control-interfaces: GPIO and (I2C or SDIO or SRAM) */
897 case DIB9000_POWER_INTERFACE_ONLY: /* TODO power up either SDIO or I2C or SRAM */
898 reg_905 &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 2));
899 break;
900
901 case DIB9000_POWER_INTERF_ANALOG_AGC:
902 reg_903 &= ~((1 << 15) | (1 << 14) | (1 << 11) | (1 << 10));
903 reg_905 &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4) | (1 << 2));
904 reg_906 &= ~((1 << 0));
905 break;
906
907 case DIB9000_POWER_COR4_DINTLV_ICIRM_EQUAL_CFROD:
908 reg_903 = 0x0000;
909 reg_904 = 0x801f;
910 reg_905 = 0x0000;
911 reg_906 &= ~((1 << 0));
912 break;
913
914 case DIB9000_POWER_COR4_CRY_ESRAM_MOUT_NUD:
915 reg_903 = 0x0000;
916 reg_904 = 0x8000;
917 reg_905 = 0x010b;
918 reg_906 &= ~((1 << 0));
919 break;
920 default:
921 case DIB9000_POWER_NO:
922 break;
923 }
924
925 /* always power down unused parts */
926 if (!state->platform.host.mobile_mode)
927 reg_904 |= (1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) | (1 << 1);
928
929 /* P_sdio_select_clk = 0 on MC and after */
930 if (state->revision != 0x4000)
931 reg_906 <<= 1;
932
933 dib9000_write_word(state, 903 + offset, reg_903);
934 dib9000_write_word(state, 904 + offset, reg_904);
935 dib9000_write_word(state, 905 + offset, reg_905);
936 dib9000_write_word(state, 906 + offset, reg_906);
937}
938
939static int dib9000_fw_reset(struct dvb_frontend *fe)
940{
941 struct dib9000_state *state = fe->demodulator_priv;
942
943 dib9000_write_word(state, 1817, 0x0003);
944
945 dib9000_write_word(state, 1227, 1);
946 dib9000_write_word(state, 1227, 0);
947
948 switch ((state->revision = dib9000_identify(&state->i2c))) {
949 case 0x4003:
950 case 0x4004:
951 case 0x4005:
952 state->reg_offs = 1;
953 break;
954 default:
955 return -EINVAL;
956 }
957
958 /* reset the i2c-master to use the host interface */
959 dibx000_reset_i2c_master(&state->i2c_master);
960
961 dib9000_set_power_mode(state, DIB9000_POWER_ALL);
962
963 /* unforce divstr regardless whether i2c enumeration was done or not */
964 dib9000_write_word(state, 1794, dib9000_read_word(state, 1794) & ~(1 << 1));
965 dib9000_write_word(state, 1796, 0);
966 dib9000_write_word(state, 1805, 0x805);
967
968 /* restart all parts */
969 dib9000_write_word(state, 898, 0xffff);
970 dib9000_write_word(state, 899, 0xffff);
971 dib9000_write_word(state, 900, 0x0001);
972 dib9000_write_word(state, 901, 0xff19);
973 dib9000_write_word(state, 902, 0x003c);
974
975 dib9000_write_word(state, 898, 0);
976 dib9000_write_word(state, 899, 0);
977 dib9000_write_word(state, 900, 0);
978 dib9000_write_word(state, 901, 0);
979 dib9000_write_word(state, 902, 0);
980
981 dib9000_write_word(state, 911, state->chip.d9.cfg.if_drives);
982
983 dib9000_set_power_mode(state, DIB9000_POWER_INTERFACE_ONLY);
984
985 return 0;
986}
987
988static int dib9000_risc_apb_access_read(struct dib9000_state *state, u32 address, u16 attribute, const u8 * tx, u32 txlen, u8 * b, u32 len)
989{
990 u16 mb[10];
991 u8 i, s;
992
993 if (address >= 1024 || !state->platform.risc.fw_is_running)
994 return -EINVAL;
995
996 /* dprintk( "APB access thru rd fw %d %x", address, attribute); */
997
998 mb[0] = (u16) address;
999 mb[1] = len / 2;
1000 dib9000_mbx_send_attr(state, OUT_MSG_BRIDGE_APB_R, mb, 2, attribute);
1001 switch (dib9000_mbx_get_message_attr(state, IN_MSG_END_BRIDGE_APB_RW, mb, &s, attribute)) {
1002 case 1:
1003 s--;
1004 for (i = 0; i < s; i++) {
1005 b[i * 2] = (mb[i + 1] >> 8) & 0xff;
1006 b[i * 2 + 1] = (mb[i + 1]) & 0xff;
1007 }
1008 return 0;
1009 default:
1010 return -EIO;
1011 }
1012 return -EIO;
1013}
1014
1015static int dib9000_risc_apb_access_write(struct dib9000_state *state, u32 address, u16 attribute, const u8 * b, u32 len)
1016{
1017 u16 mb[10];
1018 u8 s, i;
1019
1020 if (address >= 1024 || !state->platform.risc.fw_is_running)
1021 return -EINVAL;
1022
1023 /* dprintk( "APB access thru wr fw %d %x", address, attribute); */
1024
1025 mb[0] = (unsigned short)address;
1026 for (i = 0; i < len && i < 20; i += 2)
1027 mb[1 + (i / 2)] = (b[i] << 8 | b[i + 1]);
1028
1029 dib9000_mbx_send_attr(state, OUT_MSG_BRIDGE_APB_W, mb, 1 + len / 2, attribute);
1030 return dib9000_mbx_get_message_attr(state, IN_MSG_END_BRIDGE_APB_RW, mb, &s, attribute) == 1 ? 0 : -EINVAL;
1031}
1032
1033static int dib9000_fw_memmbx_sync(struct dib9000_state *state, u8 i)
1034{
1035 u8 index_loop = 10;
1036
1037 if (!state->platform.risc.fw_is_running)
1038 return 0;
1039 dib9000_risc_mem_write(state, FE_MM_RW_SYNC, &i);
1040 do {
1041 dib9000_risc_mem_read(state, FE_MM_RW_SYNC, state->i2c_read_buffer, 1);
1042 } while (state->i2c_read_buffer[0] && index_loop--);
1043
1044 if (index_loop > 0)
1045 return 0;
1046 return -EIO;
1047}
1048
1049static int dib9000_fw_init(struct dib9000_state *state)
1050{
1051 struct dibGPIOFunction *f;
1052 u16 b[40] = { 0 };
1053 u8 i;
1054 u8 size;
1055
1056 if (dib9000_fw_boot(state, NULL, 0, state->chip.d9.cfg.microcode_B_fe_buffer, state->chip.d9.cfg.microcode_B_fe_size) != 0)
1057 return -EIO;
1058
1059 /* initialize the firmware */
1060 for (i = 0; i < ARRAY_SIZE(state->chip.d9.cfg.gpio_function); i++) {
1061 f = &state->chip.d9.cfg.gpio_function[i];
1062 if (f->mask) {
1063 switch (f->function) {
1064 case BOARD_GPIO_FUNCTION_COMPONENT_ON:
1065 b[0] = (u16) f->mask;
1066 b[1] = (u16) f->direction;
1067 b[2] = (u16) f->value;
1068 break;
1069 case BOARD_GPIO_FUNCTION_COMPONENT_OFF:
1070 b[3] = (u16) f->mask;
1071 b[4] = (u16) f->direction;
1072 b[5] = (u16) f->value;
1073 break;
1074 }
1075 }
1076 }
1077 if (dib9000_mbx_send(state, OUT_MSG_CONF_GPIO, b, 15) != 0)
1078 return -EIO;
1079
1080 /* subband */
1081 b[0] = state->chip.d9.cfg.subband.size; /* type == 0 -> GPIO - PWM not yet supported */
1082 for (i = 0; i < state->chip.d9.cfg.subband.size; i++) {
1083 b[1 + i * 4] = state->chip.d9.cfg.subband.subband[i].f_mhz;
1084 b[2 + i * 4] = (u16) state->chip.d9.cfg.subband.subband[i].gpio.mask;
1085 b[3 + i * 4] = (u16) state->chip.d9.cfg.subband.subband[i].gpio.direction;
1086 b[4 + i * 4] = (u16) state->chip.d9.cfg.subband.subband[i].gpio.value;
1087 }
1088 b[1 + i * 4] = 0; /* fe_id */
1089 if (dib9000_mbx_send(state, OUT_MSG_SUBBAND_SEL, b, 2 + 4 * i) != 0)
1090 return -EIO;
1091
1092 /* 0 - id, 1 - no_of_frontends */
1093 b[0] = (0 << 8) | 1;
1094 /* 0 = i2c-address demod, 0 = tuner */
1095 b[1] = (0 << 8) | (0);
1096 b[2] = (u16) (((state->chip.d9.cfg.xtal_clock_khz * 1000) >> 16) & 0xffff);
1097 b[3] = (u16) (((state->chip.d9.cfg.xtal_clock_khz * 1000)) & 0xffff);
1098 b[4] = (u16) ((state->chip.d9.cfg.vcxo_timer >> 16) & 0xffff);
1099 b[5] = (u16) ((state->chip.d9.cfg.vcxo_timer) & 0xffff);
1100 b[6] = (u16) ((state->chip.d9.cfg.timing_frequency >> 16) & 0xffff);
1101 b[7] = (u16) ((state->chip.d9.cfg.timing_frequency) & 0xffff);
1102 b[29] = state->chip.d9.cfg.if_drives;
1103 if (dib9000_mbx_send(state, OUT_MSG_INIT_DEMOD, b, ARRAY_SIZE(b)) != 0)
1104 return -EIO;
1105
1106 if (dib9000_mbx_send(state, OUT_MSG_FE_FW_DL, NULL, 0) != 0)
1107 return -EIO;
1108
1109 if (dib9000_mbx_get_message(state, IN_MSG_FE_FW_DL_DONE, b, &size) < 0)
1110 return -EIO;
1111
1112 if (size > ARRAY_SIZE(b)) {
1113 dprintk("error : firmware returned %dbytes needed but the used buffer has only %dbytes\n Firmware init ABORTED", size,
1114 (int)ARRAY_SIZE(b));
1115 return -EINVAL;
1116 }
1117
1118 for (i = 0; i < size; i += 2) {
1119 state->platform.risc.fe_mm[i / 2].addr = b[i + 0];
1120 state->platform.risc.fe_mm[i / 2].size = b[i + 1];
1121 }
1122
1123 return 0;
1124}
1125
1126static void dib9000_fw_set_channel_head(struct dib9000_state *state, struct dvb_frontend_parameters *ch)
1127{
1128 u8 b[9];
1129 u32 freq = state->fe[0]->dtv_property_cache.frequency / 1000;
1130 if (state->fe_id % 2)
1131 freq += 101;
1132
1133 b[0] = (u8) ((freq >> 0) & 0xff);
1134 b[1] = (u8) ((freq >> 8) & 0xff);
1135 b[2] = (u8) ((freq >> 16) & 0xff);
1136 b[3] = (u8) ((freq >> 24) & 0xff);
1137 b[4] = (u8) ((state->fe[0]->dtv_property_cache.bandwidth_hz / 1000 >> 0) & 0xff);
1138 b[5] = (u8) ((state->fe[0]->dtv_property_cache.bandwidth_hz / 1000 >> 8) & 0xff);
1139 b[6] = (u8) ((state->fe[0]->dtv_property_cache.bandwidth_hz / 1000 >> 16) & 0xff);
1140 b[7] = (u8) ((state->fe[0]->dtv_property_cache.bandwidth_hz / 1000 >> 24) & 0xff);
1141 b[8] = 0x80; /* do not wait for CELL ID when doing autosearch */
1142 if (state->fe[0]->dtv_property_cache.delivery_system == SYS_DVBT)
1143 b[8] |= 1;
1144 dib9000_risc_mem_write(state, FE_MM_W_CHANNEL_HEAD, b);
1145}
1146
1147static int dib9000_fw_get_channel(struct dvb_frontend *fe, struct dvb_frontend_parameters *channel)
1148{
1149 struct dib9000_state *state = fe->demodulator_priv;
1150 struct dibDVBTChannel {
1151 s8 spectrum_inversion;
1152
1153 s8 nfft;
1154 s8 guard;
1155 s8 constellation;
1156
1157 s8 hrch;
1158 s8 alpha;
1159 s8 code_rate_hp;
1160 s8 code_rate_lp;
1161 s8 select_hp;
1162
1163 s8 intlv_native;
1164 };
1165 struct dibDVBTChannel *ch;
1166 int ret = 0;
1167
1168 DibAcquireLock(&state->platform.risc.mem_mbx_lock);
1169 if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0) {
1170 goto error;
1171 ret = -EIO;
1172 }
1173
1174 dib9000_risc_mem_read(state, FE_MM_R_CHANNEL_UNION,
1175 state->i2c_read_buffer, sizeof(struct dibDVBTChannel));
1176 ch = (struct dibDVBTChannel *)state->i2c_read_buffer;
1177
1178
1179 switch (ch->spectrum_inversion & 0x7) {
1180 case 1:
1181 state->fe[0]->dtv_property_cache.inversion = INVERSION_ON;
1182 break;
1183 case 0:
1184 state->fe[0]->dtv_property_cache.inversion = INVERSION_OFF;
1185 break;
1186 default:
1187 case -1:
1188 state->fe[0]->dtv_property_cache.inversion = INVERSION_AUTO;
1189 break;
1190 }
1191 switch (ch->nfft) {
1192 case 0:
1193 state->fe[0]->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_2K;
1194 break;
1195 case 2:
1196 state->fe[0]->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_4K;
1197 break;
1198 case 1:
1199 state->fe[0]->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_8K;
1200 break;
1201 default:
1202 case -1:
1203 state->fe[0]->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_AUTO;
1204 break;
1205 }
1206 switch (ch->guard) {
1207 case 0:
1208 state->fe[0]->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_32;
1209 break;
1210 case 1:
1211 state->fe[0]->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_16;
1212 break;
1213 case 2:
1214 state->fe[0]->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_8;
1215 break;
1216 case 3:
1217 state->fe[0]->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_4;
1218 break;
1219 default:
1220 case -1:
1221 state->fe[0]->dtv_property_cache.guard_interval = GUARD_INTERVAL_AUTO;
1222 break;
1223 }
1224 switch (ch->constellation) {
1225 case 2:
1226 state->fe[0]->dtv_property_cache.modulation = QAM_64;
1227 break;
1228 case 1:
1229 state->fe[0]->dtv_property_cache.modulation = QAM_16;
1230 break;
1231 case 0:
1232 state->fe[0]->dtv_property_cache.modulation = QPSK;
1233 break;
1234 default:
1235 case -1:
1236 state->fe[0]->dtv_property_cache.modulation = QAM_AUTO;
1237 break;
1238 }
1239 switch (ch->hrch) {
1240 case 0:
1241 state->fe[0]->dtv_property_cache.hierarchy = HIERARCHY_NONE;
1242 break;
1243 case 1:
1244 state->fe[0]->dtv_property_cache.hierarchy = HIERARCHY_1;
1245 break;
1246 default:
1247 case -1:
1248 state->fe[0]->dtv_property_cache.hierarchy = HIERARCHY_AUTO;
1249 break;
1250 }
1251 switch (ch->code_rate_hp) {
1252 case 1:
1253 state->fe[0]->dtv_property_cache.code_rate_HP = FEC_1_2;
1254 break;
1255 case 2:
1256 state->fe[0]->dtv_property_cache.code_rate_HP = FEC_2_3;
1257 break;
1258 case 3:
1259 state->fe[0]->dtv_property_cache.code_rate_HP = FEC_3_4;
1260 break;
1261 case 5:
1262 state->fe[0]->dtv_property_cache.code_rate_HP = FEC_5_6;
1263 break;
1264 case 7:
1265 state->fe[0]->dtv_property_cache.code_rate_HP = FEC_7_8;
1266 break;
1267 default:
1268 case -1:
1269 state->fe[0]->dtv_property_cache.code_rate_HP = FEC_AUTO;
1270 break;
1271 }
1272 switch (ch->code_rate_lp) {
1273 case 1:
1274 state->fe[0]->dtv_property_cache.code_rate_LP = FEC_1_2;
1275 break;
1276 case 2:
1277 state->fe[0]->dtv_property_cache.code_rate_LP = FEC_2_3;
1278 break;
1279 case 3:
1280 state->fe[0]->dtv_property_cache.code_rate_LP = FEC_3_4;
1281 break;
1282 case 5:
1283 state->fe[0]->dtv_property_cache.code_rate_LP = FEC_5_6;
1284 break;
1285 case 7:
1286 state->fe[0]->dtv_property_cache.code_rate_LP = FEC_7_8;
1287 break;
1288 default:
1289 case -1:
1290 state->fe[0]->dtv_property_cache.code_rate_LP = FEC_AUTO;
1291 break;
1292 }
1293
1294error:
1295 DibReleaseLock(&state->platform.risc.mem_mbx_lock);
1296 return ret;
1297}
1298
1299static int dib9000_fw_set_channel_union(struct dvb_frontend *fe, struct dvb_frontend_parameters *channel)
1300{
1301 struct dib9000_state *state = fe->demodulator_priv;
1302 struct dibDVBTChannel {
1303 s8 spectrum_inversion;
1304
1305 s8 nfft;
1306 s8 guard;
1307 s8 constellation;
1308
1309 s8 hrch;
1310 s8 alpha;
1311 s8 code_rate_hp;
1312 s8 code_rate_lp;
1313 s8 select_hp;
1314
1315 s8 intlv_native;
1316 };
1317 struct dibDVBTChannel ch;
1318
1319 switch (state->fe[0]->dtv_property_cache.inversion) {
1320 case INVERSION_ON:
1321 ch.spectrum_inversion = 1;
1322 break;
1323 case INVERSION_OFF:
1324 ch.spectrum_inversion = 0;
1325 break;
1326 default:
1327 case INVERSION_AUTO:
1328 ch.spectrum_inversion = -1;
1329 break;
1330 }
1331 switch (state->fe[0]->dtv_property_cache.transmission_mode) {
1332 case TRANSMISSION_MODE_2K:
1333 ch.nfft = 0;
1334 break;
1335 case TRANSMISSION_MODE_4K:
1336 ch.nfft = 2;
1337 break;
1338 case TRANSMISSION_MODE_8K:
1339 ch.nfft = 1;
1340 break;
1341 default:
1342 case TRANSMISSION_MODE_AUTO:
1343 ch.nfft = 1;
1344 break;
1345 }
1346 switch (state->fe[0]->dtv_property_cache.guard_interval) {
1347 case GUARD_INTERVAL_1_32:
1348 ch.guard = 0;
1349 break;
1350 case GUARD_INTERVAL_1_16:
1351 ch.guard = 1;
1352 break;
1353 case GUARD_INTERVAL_1_8:
1354 ch.guard = 2;
1355 break;
1356 case GUARD_INTERVAL_1_4:
1357 ch.guard = 3;
1358 break;
1359 default:
1360 case GUARD_INTERVAL_AUTO:
1361 ch.guard = -1;
1362 break;
1363 }
1364 switch (state->fe[0]->dtv_property_cache.modulation) {
1365 case QAM_64:
1366 ch.constellation = 2;
1367 break;
1368 case QAM_16:
1369 ch.constellation = 1;
1370 break;
1371 case QPSK:
1372 ch.constellation = 0;
1373 break;
1374 default:
1375 case QAM_AUTO:
1376 ch.constellation = -1;
1377 break;
1378 }
1379 switch (state->fe[0]->dtv_property_cache.hierarchy) {
1380 case HIERARCHY_NONE:
1381 ch.hrch = 0;
1382 break;
1383 case HIERARCHY_1:
1384 case HIERARCHY_2:
1385 case HIERARCHY_4:
1386 ch.hrch = 1;
1387 break;
1388 default:
1389 case HIERARCHY_AUTO:
1390 ch.hrch = -1;
1391 break;
1392 }
1393 ch.alpha = 1;
1394 switch (state->fe[0]->dtv_property_cache.code_rate_HP) {
1395 case FEC_1_2:
1396 ch.code_rate_hp = 1;
1397 break;
1398 case FEC_2_3:
1399 ch.code_rate_hp = 2;
1400 break;
1401 case FEC_3_4:
1402 ch.code_rate_hp = 3;
1403 break;
1404 case FEC_5_6:
1405 ch.code_rate_hp = 5;
1406 break;
1407 case FEC_7_8:
1408 ch.code_rate_hp = 7;
1409 break;
1410 default:
1411 case FEC_AUTO:
1412 ch.code_rate_hp = -1;
1413 break;
1414 }
1415 switch (state->fe[0]->dtv_property_cache.code_rate_LP) {
1416 case FEC_1_2:
1417 ch.code_rate_lp = 1;
1418 break;
1419 case FEC_2_3:
1420 ch.code_rate_lp = 2;
1421 break;
1422 case FEC_3_4:
1423 ch.code_rate_lp = 3;
1424 break;
1425 case FEC_5_6:
1426 ch.code_rate_lp = 5;
1427 break;
1428 case FEC_7_8:
1429 ch.code_rate_lp = 7;
1430 break;
1431 default:
1432 case FEC_AUTO:
1433 ch.code_rate_lp = -1;
1434 break;
1435 }
1436 ch.select_hp = 1;
1437 ch.intlv_native = 1;
1438
1439 dib9000_risc_mem_write(state, FE_MM_W_CHANNEL_UNION, (u8 *) &ch);
1440
1441 return 0;
1442}
1443
1444static int dib9000_fw_tune(struct dvb_frontend *fe, struct dvb_frontend_parameters *ch)
1445{
1446 struct dib9000_state *state = fe->demodulator_priv;
1447 int ret = 10, search = state->channel_status.status == CHANNEL_STATUS_PARAMETERS_UNKNOWN;
1448 s8 i;
1449
1450 switch (state->tune_state) {
1451 case CT_DEMOD_START:
1452 dib9000_fw_set_channel_head(state, ch);
1453
1454 /* write the channel context - a channel is initialized to 0, so it is OK */
1455 dib9000_risc_mem_write(state, FE_MM_W_CHANNEL_CONTEXT, (u8 *) fe_info);
1456 dib9000_risc_mem_write(state, FE_MM_W_FE_INFO, (u8 *) fe_info);
1457
1458 if (search)
1459 dib9000_mbx_send(state, OUT_MSG_FE_CHANNEL_SEARCH, NULL, 0);
1460 else {
1461 dib9000_fw_set_channel_union(fe, ch);
1462 dib9000_mbx_send(state, OUT_MSG_FE_CHANNEL_TUNE, NULL, 0);
1463 }
1464 state->tune_state = CT_DEMOD_STEP_1;
1465 break;
1466 case CT_DEMOD_STEP_1:
1467 if (search)
1468 dib9000_risc_mem_read(state, FE_MM_R_CHANNEL_SEARCH_STATE, state->i2c_read_buffer, 1);
1469 else
1470 dib9000_risc_mem_read(state, FE_MM_R_CHANNEL_TUNE_STATE, state->i2c_read_buffer, 1);
1471 i = (s8)state->i2c_read_buffer[0];
1472 switch (i) { /* something happened */
1473 case 0:
1474 break;
1475 case -2: /* tps locks are "slower" than MPEG locks -> even in autosearch data is OK here */
1476 if (search)
1477 state->status = FE_STATUS_DEMOD_SUCCESS;
1478 else {
1479 state->tune_state = CT_DEMOD_STOP;
1480 state->status = FE_STATUS_LOCKED;
1481 }
1482 break;
1483 default:
1484 state->status = FE_STATUS_TUNE_FAILED;
1485 state->tune_state = CT_DEMOD_STOP;
1486 break;
1487 }
1488 break;
1489 default:
1490 ret = FE_CALLBACK_TIME_NEVER;
1491 break;
1492 }
1493
1494 return ret;
1495}
1496
1497static int dib9000_fw_set_diversity_in(struct dvb_frontend *fe, int onoff)
1498{
1499 struct dib9000_state *state = fe->demodulator_priv;
1500 u16 mode = (u16) onoff;
1501 return dib9000_mbx_send(state, OUT_MSG_ENABLE_DIVERSITY, &mode, 1);
1502}
1503
1504static int dib9000_fw_set_output_mode(struct dvb_frontend *fe, int mode)
1505{
1506 struct dib9000_state *state = fe->demodulator_priv;
1507 u16 outreg, smo_mode;
1508
1509 dprintk("setting output mode for demod %p to %d", fe, mode);
1510
1511 switch (mode) {
1512 case OUTMODE_MPEG2_PAR_GATED_CLK:
1513 outreg = (1 << 10); /* 0x0400 */
1514 break;
1515 case OUTMODE_MPEG2_PAR_CONT_CLK:
1516 outreg = (1 << 10) | (1 << 6); /* 0x0440 */
1517 break;
1518 case OUTMODE_MPEG2_SERIAL:
1519 outreg = (1 << 10) | (2 << 6) | (0 << 1); /* 0x0482 */
1520 break;
1521 case OUTMODE_DIVERSITY:
1522 outreg = (1 << 10) | (4 << 6); /* 0x0500 */
1523 break;
1524 case OUTMODE_MPEG2_FIFO:
1525 outreg = (1 << 10) | (5 << 6);
1526 break;
1527 case OUTMODE_HIGH_Z:
1528 outreg = 0;
1529 break;
1530 default:
1531 dprintk("Unhandled output_mode passed to be set for demod %p", &state->fe[0]);
1532 return -EINVAL;
1533 }
1534
1535 dib9000_write_word(state, 1795, outreg);
1536
1537 switch (mode) {
1538 case OUTMODE_MPEG2_PAR_GATED_CLK:
1539 case OUTMODE_MPEG2_PAR_CONT_CLK:
1540 case OUTMODE_MPEG2_SERIAL:
1541 case OUTMODE_MPEG2_FIFO:
1542 smo_mode = (dib9000_read_word(state, 295) & 0x0010) | (1 << 1);
1543 if (state->chip.d9.cfg.output_mpeg2_in_188_bytes)
1544 smo_mode |= (1 << 5);
1545 dib9000_write_word(state, 295, smo_mode);
1546 break;
1547 }
1548
1549 outreg = to_fw_output_mode(mode);
1550 return dib9000_mbx_send(state, OUT_MSG_SET_OUTPUT_MODE, &outreg, 1);
1551}
1552
1553static int dib9000_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
1554{
1555 struct dib9000_state *state = i2c_get_adapdata(i2c_adap);
1556 u16 i, len, t, index_msg;
1557
1558 for (index_msg = 0; index_msg < num; index_msg++) {
1559 if (msg[index_msg].flags & I2C_M_RD) { /* read */
1560 len = msg[index_msg].len;
1561 if (len > 16)
1562 len = 16;
1563
1564 if (dib9000_read_word(state, 790) != 0)
1565 dprintk("TunerITF: read busy");
1566
1567 dib9000_write_word(state, 784, (u16) (msg[index_msg].addr));
1568 dib9000_write_word(state, 787, (len / 2) - 1);
1569 dib9000_write_word(state, 786, 1); /* start read */
1570
1571 i = 1000;
1572 while (dib9000_read_word(state, 790) != (len / 2) && i)
1573 i--;
1574
1575 if (i == 0)
1576 dprintk("TunerITF: read failed");
1577
1578 for (i = 0; i < len; i += 2) {
1579 t = dib9000_read_word(state, 785);
1580 msg[index_msg].buf[i] = (t >> 8) & 0xff;
1581 msg[index_msg].buf[i + 1] = (t) & 0xff;
1582 }
1583 if (dib9000_read_word(state, 790) != 0)
1584 dprintk("TunerITF: read more data than expected");
1585 } else {
1586 i = 1000;
1587 while (dib9000_read_word(state, 789) && i)
1588 i--;
1589 if (i == 0)
1590 dprintk("TunerITF: write busy");
1591
1592 len = msg[index_msg].len;
1593 if (len > 16)
1594 len = 16;
1595
1596 for (i = 0; i < len; i += 2)
1597 dib9000_write_word(state, 785, (msg[index_msg].buf[i] << 8) | msg[index_msg].buf[i + 1]);
1598 dib9000_write_word(state, 784, (u16) msg[index_msg].addr);
1599 dib9000_write_word(state, 787, (len / 2) - 1);
1600 dib9000_write_word(state, 786, 0); /* start write */
1601
1602 i = 1000;
1603 while (dib9000_read_word(state, 791) > 0 && i)
1604 i--;
1605 if (i == 0)
1606 dprintk("TunerITF: write failed");
1607 }
1608 }
1609 return num;
1610}
1611
1612int dib9000_fw_set_component_bus_speed(struct dvb_frontend *fe, u16 speed)
1613{
1614 struct dib9000_state *state = fe->demodulator_priv;
1615
1616 state->component_bus_speed = speed;
1617 return 0;
1618}
1619EXPORT_SYMBOL(dib9000_fw_set_component_bus_speed);
1620
1621static int dib9000_fw_component_bus_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
1622{
1623 struct dib9000_state *state = i2c_get_adapdata(i2c_adap);
1624 u8 type = 0; /* I2C */
1625 u8 port = DIBX000_I2C_INTERFACE_GPIO_3_4;
1626 u16 scl = state->component_bus_speed; /* SCL frequency */
1627 struct dib9000_fe_memory_map *m = &state->platform.risc.fe_mm[FE_MM_RW_COMPONENT_ACCESS_BUFFER];
1628 u8 p[13] = { 0 };
1629
1630 p[0] = type;
1631 p[1] = port;
1632 p[2] = msg[0].addr << 1;
1633
1634 p[3] = (u8) scl & 0xff; /* scl */
1635 p[4] = (u8) (scl >> 8);
1636
1637 p[7] = 0;
1638 p[8] = 0;
1639
1640 p[9] = (u8) (msg[0].len);
1641 p[10] = (u8) (msg[0].len >> 8);
1642 if ((num > 1) && (msg[1].flags & I2C_M_RD)) {
1643 p[11] = (u8) (msg[1].len);
1644 p[12] = (u8) (msg[1].len >> 8);
1645 } else {
1646 p[11] = 0;
1647 p[12] = 0;
1648 }
1649
1650 DibAcquireLock(&state->platform.risc.mem_mbx_lock);
1651
1652 dib9000_risc_mem_write(state, FE_MM_W_COMPONENT_ACCESS, p);
1653
1654 { /* write-part */
1655 dib9000_risc_mem_setup_cmd(state, m->addr, msg[0].len, 0);
1656 dib9000_risc_mem_write_chunks(state, msg[0].buf, msg[0].len);
1657 }
1658
1659 /* do the transaction */
1660 if (dib9000_fw_memmbx_sync(state, FE_SYNC_COMPONENT_ACCESS) < 0) {
1661 DibReleaseLock(&state->platform.risc.mem_mbx_lock);
1662 return 0;
1663 }
1664
1665 /* read back any possible result */
1666 if ((num > 1) && (msg[1].flags & I2C_M_RD))
1667 dib9000_risc_mem_read(state, FE_MM_RW_COMPONENT_ACCESS_BUFFER, msg[1].buf, msg[1].len);
1668
1669 DibReleaseLock(&state->platform.risc.mem_mbx_lock);
1670
1671 return num;
1672}
1673
1674static u32 dib9000_i2c_func(struct i2c_adapter *adapter)
1675{
1676 return I2C_FUNC_I2C;
1677}
1678
1679static struct i2c_algorithm dib9000_tuner_algo = {
1680 .master_xfer = dib9000_tuner_xfer,
1681 .functionality = dib9000_i2c_func,
1682};
1683
1684static struct i2c_algorithm dib9000_component_bus_algo = {
1685 .master_xfer = dib9000_fw_component_bus_xfer,
1686 .functionality = dib9000_i2c_func,
1687};
1688
1689struct i2c_adapter *dib9000_get_tuner_interface(struct dvb_frontend *fe)
1690{
1691 struct dib9000_state *st = fe->demodulator_priv;
1692 return &st->tuner_adap;
1693}
1694EXPORT_SYMBOL(dib9000_get_tuner_interface);
1695
1696struct i2c_adapter *dib9000_get_component_bus_interface(struct dvb_frontend *fe)
1697{
1698 struct dib9000_state *st = fe->demodulator_priv;
1699 return &st->component_bus;
1700}
1701EXPORT_SYMBOL(dib9000_get_component_bus_interface);
1702
1703struct i2c_adapter *dib9000_get_i2c_master(struct dvb_frontend *fe, enum dibx000_i2c_interface intf, int gating)
1704{
1705 struct dib9000_state *st = fe->demodulator_priv;
1706 return dibx000_get_i2c_adapter(&st->i2c_master, intf, gating);
1707}
1708EXPORT_SYMBOL(dib9000_get_i2c_master);
1709
1710int dib9000_set_i2c_adapter(struct dvb_frontend *fe, struct i2c_adapter *i2c)
1711{
1712 struct dib9000_state *st = fe->demodulator_priv;
1713
1714 st->i2c.i2c_adap = i2c;
1715 return 0;
1716}
1717EXPORT_SYMBOL(dib9000_set_i2c_adapter);
1718
1719static int dib9000_cfg_gpio(struct dib9000_state *st, u8 num, u8 dir, u8 val)
1720{
1721 st->gpio_dir = dib9000_read_word(st, 773);
1722 st->gpio_dir &= ~(1 << num); /* reset the direction bit */
1723 st->gpio_dir |= (dir & 0x1) << num; /* set the new direction */
1724 dib9000_write_word(st, 773, st->gpio_dir);
1725
1726 st->gpio_val = dib9000_read_word(st, 774);
1727 st->gpio_val &= ~(1 << num); /* reset the direction bit */
1728 st->gpio_val |= (val & 0x01) << num; /* set the new value */
1729 dib9000_write_word(st, 774, st->gpio_val);
1730
1731 dprintk("gpio dir: %04x: gpio val: %04x", st->gpio_dir, st->gpio_val);
1732
1733 return 0;
1734}
1735
1736int dib9000_set_gpio(struct dvb_frontend *fe, u8 num, u8 dir, u8 val)
1737{
1738 struct dib9000_state *state = fe->demodulator_priv;
1739 return dib9000_cfg_gpio(state, num, dir, val);
1740}
1741EXPORT_SYMBOL(dib9000_set_gpio);
1742
1743int dib9000_fw_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff)
1744{
1745 struct dib9000_state *state = fe->demodulator_priv;
1746 u16 val = dib9000_read_word(state, 294 + 1) & 0xffef;
1747 val |= (onoff & 0x1) << 4;
1748
1749 dprintk("PID filter enabled %d", onoff);
1750 return dib9000_write_word(state, 294 + 1, val);
1751}
1752EXPORT_SYMBOL(dib9000_fw_pid_filter_ctrl);
1753
1754int dib9000_fw_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff)
1755{
1756 struct dib9000_state *state = fe->demodulator_priv;
1757 dprintk("Index %x, PID %d, OnOff %d", id, pid, onoff);
1758 return dib9000_write_word(state, 300 + 1 + id, onoff ? (1 << 13) | pid : 0);
1759}
1760EXPORT_SYMBOL(dib9000_fw_pid_filter);
1761
1762int dib9000_firmware_post_pll_init(struct dvb_frontend *fe)
1763{
1764 struct dib9000_state *state = fe->demodulator_priv;
1765 return dib9000_fw_init(state);
1766}
1767EXPORT_SYMBOL(dib9000_firmware_post_pll_init);
1768
1769static void dib9000_release(struct dvb_frontend *demod)
1770{
1771 struct dib9000_state *st = demod->demodulator_priv;
1772 u8 index_frontend;
1773
1774 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (st->fe[index_frontend] != NULL); index_frontend++)
1775 dvb_frontend_detach(st->fe[index_frontend]);
1776
1777 DibFreeLock(&state->platform.risc.mbx_if_lock);
1778 DibFreeLock(&state->platform.risc.mbx_lock);
1779 DibFreeLock(&state->platform.risc.mem_lock);
1780 DibFreeLock(&state->platform.risc.mem_mbx_lock);
1781 dibx000_exit_i2c_master(&st->i2c_master);
1782
1783 i2c_del_adapter(&st->tuner_adap);
1784 i2c_del_adapter(&st->component_bus);
1785 kfree(st->fe[0]);
1786 kfree(st);
1787}
1788
1789static int dib9000_wakeup(struct dvb_frontend *fe)
1790{
1791 return 0;
1792}
1793
1794static int dib9000_sleep(struct dvb_frontend *fe)
1795{
1796 struct dib9000_state *state = fe->demodulator_priv;
1797 u8 index_frontend;
1798 int ret;
1799
1800 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
1801 ret = state->fe[index_frontend]->ops.sleep(state->fe[index_frontend]);
1802 if (ret < 0)
1803 return ret;
1804 }
1805 return dib9000_mbx_send(state, OUT_MSG_FE_SLEEP, NULL, 0);
1806}
1807
1808static int dib9000_fe_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings *tune)
1809{
1810 tune->min_delay_ms = 1000;
1811 return 0;
1812}
1813
1814static int dib9000_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
1815{
1816 struct dib9000_state *state = fe->demodulator_priv;
1817 u8 index_frontend, sub_index_frontend;
1818 fe_status_t stat;
1819 int ret;
1820
1821 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
1822 state->fe[index_frontend]->ops.read_status(state->fe[index_frontend], &stat);
1823 if (stat & FE_HAS_SYNC) {
1824 dprintk("TPS lock on the slave%i", index_frontend);
1825
1826 /* synchronize the cache with the other frontends */
1827 state->fe[index_frontend]->ops.get_frontend(state->fe[index_frontend], fep);
1828 for (sub_index_frontend = 0; (sub_index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[sub_index_frontend] != NULL);
1829 sub_index_frontend++) {
1830 if (sub_index_frontend != index_frontend) {
1831 state->fe[sub_index_frontend]->dtv_property_cache.modulation =
1832 state->fe[index_frontend]->dtv_property_cache.modulation;
1833 state->fe[sub_index_frontend]->dtv_property_cache.inversion =
1834 state->fe[index_frontend]->dtv_property_cache.inversion;
1835 state->fe[sub_index_frontend]->dtv_property_cache.transmission_mode =
1836 state->fe[index_frontend]->dtv_property_cache.transmission_mode;
1837 state->fe[sub_index_frontend]->dtv_property_cache.guard_interval =
1838 state->fe[index_frontend]->dtv_property_cache.guard_interval;
1839 state->fe[sub_index_frontend]->dtv_property_cache.hierarchy =
1840 state->fe[index_frontend]->dtv_property_cache.hierarchy;
1841 state->fe[sub_index_frontend]->dtv_property_cache.code_rate_HP =
1842 state->fe[index_frontend]->dtv_property_cache.code_rate_HP;
1843 state->fe[sub_index_frontend]->dtv_property_cache.code_rate_LP =
1844 state->fe[index_frontend]->dtv_property_cache.code_rate_LP;
1845 state->fe[sub_index_frontend]->dtv_property_cache.rolloff =
1846 state->fe[index_frontend]->dtv_property_cache.rolloff;
1847 }
1848 }
1849 return 0;
1850 }
1851 }
1852
1853 /* get the channel from master chip */
1854 ret = dib9000_fw_get_channel(fe, fep);
1855 if (ret != 0)
1856 return ret;
1857
1858 /* synchronize the cache with the other frontends */
1859 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
1860 state->fe[index_frontend]->dtv_property_cache.inversion = fe->dtv_property_cache.inversion;
1861 state->fe[index_frontend]->dtv_property_cache.transmission_mode = fe->dtv_property_cache.transmission_mode;
1862 state->fe[index_frontend]->dtv_property_cache.guard_interval = fe->dtv_property_cache.guard_interval;
1863 state->fe[index_frontend]->dtv_property_cache.modulation = fe->dtv_property_cache.modulation;
1864 state->fe[index_frontend]->dtv_property_cache.hierarchy = fe->dtv_property_cache.hierarchy;
1865 state->fe[index_frontend]->dtv_property_cache.code_rate_HP = fe->dtv_property_cache.code_rate_HP;
1866 state->fe[index_frontend]->dtv_property_cache.code_rate_LP = fe->dtv_property_cache.code_rate_LP;
1867 state->fe[index_frontend]->dtv_property_cache.rolloff = fe->dtv_property_cache.rolloff;
1868 }
1869
1870 return 0;
1871}
1872
1873static int dib9000_set_tune_state(struct dvb_frontend *fe, enum frontend_tune_state tune_state)
1874{
1875 struct dib9000_state *state = fe->demodulator_priv;
1876 state->tune_state = tune_state;
1877 if (tune_state == CT_DEMOD_START)
1878 state->status = FE_STATUS_TUNE_PENDING;
1879
1880 return 0;
1881}
1882
1883static u32 dib9000_get_status(struct dvb_frontend *fe)
1884{
1885 struct dib9000_state *state = fe->demodulator_priv;
1886 return state->status;
1887}
1888
1889static int dib9000_set_channel_status(struct dvb_frontend *fe, struct dvb_frontend_parametersContext *channel_status)
1890{
1891 struct dib9000_state *state = fe->demodulator_priv;
1892
1893 memcpy(&state->channel_status, channel_status, sizeof(struct dvb_frontend_parametersContext));
1894 return 0;
1895}
1896
1897static int dib9000_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
1898{
1899 struct dib9000_state *state = fe->demodulator_priv;
1900 int sleep_time, sleep_time_slave;
1901 u32 frontend_status;
1902 u8 nbr_pending, exit_condition, index_frontend, index_frontend_success;
1903 struct dvb_frontend_parametersContext channel_status;
1904
1905 /* check that the correct parameters are set */
1906 if (state->fe[0]->dtv_property_cache.frequency == 0) {
1907 dprintk("dib9000: must specify frequency ");
1908 return 0;
1909 }
1910
1911 if (state->fe[0]->dtv_property_cache.bandwidth_hz == 0) {
1912 dprintk("dib9000: must specify bandwidth ");
1913 return 0;
1914 }
1915 fe->dtv_property_cache.delivery_system = SYS_DVBT;
1916
1917 /* set the master status */
1918 if (fep->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO ||
1919 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO || fep->u.ofdm.constellation == QAM_AUTO || fep->u.ofdm.code_rate_HP == FEC_AUTO) {
1920 /* no channel specified, autosearch the channel */
1921 state->channel_status.status = CHANNEL_STATUS_PARAMETERS_UNKNOWN;
1922 } else
1923 state->channel_status.status = CHANNEL_STATUS_PARAMETERS_SET;
1924
1925 /* set mode and status for the different frontends */
1926 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
1927 dib9000_fw_set_diversity_in(state->fe[index_frontend], 1);
1928
1929 /* synchronization of the cache */
1930 memcpy(&state->fe[index_frontend]->dtv_property_cache, &fe->dtv_property_cache, sizeof(struct dtv_frontend_properties));
1931
1932 state->fe[index_frontend]->dtv_property_cache.delivery_system = SYS_DVBT;
1933 dib9000_fw_set_output_mode(state->fe[index_frontend], OUTMODE_HIGH_Z);
1934
1935 dib9000_set_channel_status(state->fe[index_frontend], &state->channel_status);
1936 dib9000_set_tune_state(state->fe[index_frontend], CT_DEMOD_START);
1937 }
1938
1939 /* actual tune */
1940 exit_condition = 0; /* 0: tune pending; 1: tune failed; 2:tune success */
1941 index_frontend_success = 0;
1942 do {
1943 sleep_time = dib9000_fw_tune(state->fe[0], NULL);
1944 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
1945 sleep_time_slave = dib9000_fw_tune(state->fe[index_frontend], NULL);
1946 if (sleep_time == FE_CALLBACK_TIME_NEVER)
1947 sleep_time = sleep_time_slave;
1948 else if ((sleep_time_slave != FE_CALLBACK_TIME_NEVER) && (sleep_time_slave > sleep_time))
1949 sleep_time = sleep_time_slave;
1950 }
1951 if (sleep_time != FE_CALLBACK_TIME_NEVER)
1952 msleep(sleep_time / 10);
1953 else
1954 break;
1955
1956 nbr_pending = 0;
1957 exit_condition = 0;
1958 index_frontend_success = 0;
1959 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
1960 frontend_status = -dib9000_get_status(state->fe[index_frontend]);
1961 if (frontend_status > -FE_STATUS_TUNE_PENDING) {
1962 exit_condition = 2; /* tune success */
1963 index_frontend_success = index_frontend;
1964 break;
1965 }
1966 if (frontend_status == -FE_STATUS_TUNE_PENDING)
1967 nbr_pending++; /* some frontends are still tuning */
1968 }
1969 if ((exit_condition != 2) && (nbr_pending == 0))
1970 exit_condition = 1; /* if all tune are done and no success, exit: tune failed */
1971
1972 } while (exit_condition == 0);
1973
1974 /* check the tune result */
1975 if (exit_condition == 1) { /* tune failed */
1976 dprintk("tune failed");
1977 return 0;
1978 }
1979
1980 dprintk("tune success on frontend%i", index_frontend_success);
1981
1982 /* synchronize all the channel cache */
1983 dib9000_get_frontend(state->fe[0], fep);
1984
1985 /* retune the other frontends with the found channel */
1986 channel_status.status = CHANNEL_STATUS_PARAMETERS_SET;
1987 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
1988 /* only retune the frontends which was not tuned success */
1989 if (index_frontend != index_frontend_success) {
1990 dib9000_set_channel_status(state->fe[index_frontend], &channel_status);
1991 dib9000_set_tune_state(state->fe[index_frontend], CT_DEMOD_START);
1992 }
1993 }
1994 do {
1995 sleep_time = FE_CALLBACK_TIME_NEVER;
1996 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
1997 if (index_frontend != index_frontend_success) {
1998 sleep_time_slave = dib9000_fw_tune(state->fe[index_frontend], NULL);
1999 if (sleep_time == FE_CALLBACK_TIME_NEVER)
2000 sleep_time = sleep_time_slave;
2001 else if ((sleep_time_slave != FE_CALLBACK_TIME_NEVER) && (sleep_time_slave > sleep_time))
2002 sleep_time = sleep_time_slave;
2003 }
2004 }
2005 if (sleep_time != FE_CALLBACK_TIME_NEVER)
2006 msleep(sleep_time / 10);
2007 else
2008 break;
2009
2010 nbr_pending = 0;
2011 for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
2012 if (index_frontend != index_frontend_success) {
2013 frontend_status = -dib9000_get_status(state->fe[index_frontend]);
2014 if ((index_frontend != index_frontend_success) && (frontend_status == -FE_STATUS_TUNE_PENDING))
2015 nbr_pending++; /* some frontends are still tuning */
2016 }
2017 }
2018 } while (nbr_pending != 0);
2019
2020 /* set the output mode */
2021 dib9000_fw_set_output_mode(state->fe[0], state->chip.d9.cfg.output_mode);
2022 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
2023 dib9000_fw_set_output_mode(state->fe[index_frontend], OUTMODE_DIVERSITY);
2024
2025 /* turn off the diversity for the last frontend */
2026 dib9000_fw_set_diversity_in(state->fe[index_frontend - 1], 0);
2027
2028 return 0;
2029}
2030
2031static u16 dib9000_read_lock(struct dvb_frontend *fe)
2032{
2033 struct dib9000_state *state = fe->demodulator_priv;
2034
2035 return dib9000_read_word(state, 535);
2036}
2037
2038static int dib9000_read_status(struct dvb_frontend *fe, fe_status_t * stat)
2039{
2040 struct dib9000_state *state = fe->demodulator_priv;
2041 u8 index_frontend;
2042 u16 lock = 0, lock_slave = 0;
2043
2044 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
2045 lock_slave |= dib9000_read_lock(state->fe[index_frontend]);
2046
2047 lock = dib9000_read_word(state, 535);
2048
2049 *stat = 0;
2050
2051 if ((lock & 0x8000) || (lock_slave & 0x8000))
2052 *stat |= FE_HAS_SIGNAL;
2053 if ((lock & 0x3000) || (lock_slave & 0x3000))
2054 *stat |= FE_HAS_CARRIER;
2055 if ((lock & 0x0100) || (lock_slave & 0x0100))
2056 *stat |= FE_HAS_VITERBI;
2057 if (((lock & 0x0038) == 0x38) || ((lock_slave & 0x0038) == 0x38))
2058 *stat |= FE_HAS_SYNC;
2059 if ((lock & 0x0008) || (lock_slave & 0x0008))
2060 *stat |= FE_HAS_LOCK;
2061
2062 return 0;
2063}
2064
2065static int dib9000_read_ber(struct dvb_frontend *fe, u32 * ber)
2066{
2067 struct dib9000_state *state = fe->demodulator_priv;
2068 u16 *c;
2069
2070 DibAcquireLock(&state->platform.risc.mem_mbx_lock);
2071 if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0)
2072 return -EIO;
2073 dib9000_risc_mem_read(state, FE_MM_R_FE_MONITOR,
2074 state->i2c_read_buffer, 16 * 2);
2075 DibReleaseLock(&state->platform.risc.mem_mbx_lock);
2076
2077 c = (u16 *)state->i2c_read_buffer;
2078
2079 *ber = c[10] << 16 | c[11];
2080 return 0;
2081}
2082
2083static int dib9000_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
2084{
2085 struct dib9000_state *state = fe->demodulator_priv;
2086 u8 index_frontend;
2087 u16 *c = (u16 *)state->i2c_read_buffer;
2088 u16 val;
2089
2090 *strength = 0;
2091 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
2092 state->fe[index_frontend]->ops.read_signal_strength(state->fe[index_frontend], &val);
2093 if (val > 65535 - *strength)
2094 *strength = 65535;
2095 else
2096 *strength += val;
2097 }
2098
2099 DibAcquireLock(&state->platform.risc.mem_mbx_lock);
2100 if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0)
2101 return -EIO;
2102 dib9000_risc_mem_read(state, FE_MM_R_FE_MONITOR, (u8 *) c, 16 * 2);
2103 DibReleaseLock(&state->platform.risc.mem_mbx_lock);
2104
2105 val = 65535 - c[4];
2106 if (val > 65535 - *strength)
2107 *strength = 65535;
2108 else
2109 *strength += val;
2110 return 0;
2111}
2112
2113static u32 dib9000_get_snr(struct dvb_frontend *fe)
2114{
2115 struct dib9000_state *state = fe->demodulator_priv;
2116 u16 *c = (u16 *)state->i2c_read_buffer;
2117 u32 n, s, exp;
2118 u16 val;
2119
2120 DibAcquireLock(&state->platform.risc.mem_mbx_lock);
2121 if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0)
2122 return -EIO;
2123 dib9000_risc_mem_read(state, FE_MM_R_FE_MONITOR, (u8 *) c, 16 * 2);
2124 DibReleaseLock(&state->platform.risc.mem_mbx_lock);
2125
2126 val = c[7];
2127 n = (val >> 4) & 0xff;
2128 exp = ((val & 0xf) << 2);
2129 val = c[8];
2130 exp += ((val >> 14) & 0x3);
2131 if ((exp & 0x20) != 0)
2132 exp -= 0x40;
2133 n <<= exp + 16;
2134
2135 s = (val >> 6) & 0xFF;
2136 exp = (val & 0x3F);
2137 if ((exp & 0x20) != 0)
2138 exp -= 0x40;
2139 s <<= exp + 16;
2140
2141 if (n > 0) {
2142 u32 t = (s / n) << 16;
2143 return t + ((s << 16) - n * t) / n;
2144 }
2145 return 0xffffffff;
2146}
2147
2148static int dib9000_read_snr(struct dvb_frontend *fe, u16 * snr)
2149{
2150 struct dib9000_state *state = fe->demodulator_priv;
2151 u8 index_frontend;
2152 u32 snr_master;
2153
2154 snr_master = dib9000_get_snr(fe);
2155 for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
2156 snr_master += dib9000_get_snr(state->fe[index_frontend]);
2157
2158 if ((snr_master >> 16) != 0) {
2159 snr_master = 10 * intlog10(snr_master >> 16);
2160 *snr = snr_master / ((1 << 24) / 10);
2161 } else
2162 *snr = 0;
2163
2164 return 0;
2165}
2166
2167static int dib9000_read_unc_blocks(struct dvb_frontend *fe, u32 * unc)
2168{
2169 struct dib9000_state *state = fe->demodulator_priv;
2170 u16 *c = (u16 *)state->i2c_read_buffer;
2171
2172 DibAcquireLock(&state->platform.risc.mem_mbx_lock);
2173 if (dib9000_fw_memmbx_sync(state, FE_SYNC_CHANNEL) < 0)
2174 return -EIO;
2175 dib9000_risc_mem_read(state, FE_MM_R_FE_MONITOR, (u8 *) c, 16 * 2);
2176 DibReleaseLock(&state->platform.risc.mem_mbx_lock);
2177
2178 *unc = c[12];
2179 return 0;
2180}
2181
2182int dib9000_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, u8 first_addr)
2183{
2184 int k = 0, ret = 0;
2185 u8 new_addr = 0;
2186 struct i2c_device client = {.i2c_adap = i2c };
2187
2188 client.i2c_write_buffer = kzalloc(4 * sizeof(u8), GFP_KERNEL);
2189 if (!client.i2c_write_buffer) {
2190 dprintk("%s: not enough memory", __func__);
2191 return -ENOMEM;
2192 }
2193 client.i2c_read_buffer = kzalloc(4 * sizeof(u8), GFP_KERNEL);
2194 if (!client.i2c_read_buffer) {
2195 dprintk("%s: not enough memory", __func__);
2196 ret = -ENOMEM;
2197 goto error_memory;
2198 }
2199
2200 client.i2c_addr = default_addr + 16;
2201 dib9000_i2c_write16(&client, 1796, 0x0);
2202
2203 for (k = no_of_demods - 1; k >= 0; k--) {
2204 /* designated i2c address */
2205 new_addr = first_addr + (k << 1);
2206 client.i2c_addr = default_addr;
2207
2208 dib9000_i2c_write16(&client, 1817, 3);
2209 dib9000_i2c_write16(&client, 1796, 0);
2210 dib9000_i2c_write16(&client, 1227, 1);
2211 dib9000_i2c_write16(&client, 1227, 0);
2212
2213 client.i2c_addr = new_addr;
2214 dib9000_i2c_write16(&client, 1817, 3);
2215 dib9000_i2c_write16(&client, 1796, 0);
2216 dib9000_i2c_write16(&client, 1227, 1);
2217 dib9000_i2c_write16(&client, 1227, 0);
2218
2219 if (dib9000_identify(&client) == 0) {
2220 client.i2c_addr = default_addr;
2221 if (dib9000_identify(&client) == 0) {
2222 dprintk("DiB9000 #%d: not identified", k);
2223 ret = -EIO;
2224 goto error;
2225 }
2226 }
2227
2228 dib9000_i2c_write16(&client, 1795, (1 << 10) | (4 << 6));
2229 dib9000_i2c_write16(&client, 1794, (new_addr << 2) | 2);
2230
2231 dprintk("IC %d initialized (to i2c_address 0x%x)", k, new_addr);
2232 }
2233
2234 for (k = 0; k < no_of_demods; k++) {
2235 new_addr = first_addr | (k << 1);
2236 client.i2c_addr = new_addr;
2237
2238 dib9000_i2c_write16(&client, 1794, (new_addr << 2));
2239 dib9000_i2c_write16(&client, 1795, 0);
2240 }
2241
2242error:
2243 kfree(client.i2c_read_buffer);
2244error_memory:
2245 kfree(client.i2c_write_buffer);
2246
2247 return ret;
2248}
2249EXPORT_SYMBOL(dib9000_i2c_enumeration);
2250
2251int dib9000_set_slave_frontend(struct dvb_frontend *fe, struct dvb_frontend *fe_slave)
2252{
2253 struct dib9000_state *state = fe->demodulator_priv;
2254 u8 index_frontend = 1;
2255
2256 while ((index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL))
2257 index_frontend++;
2258 if (index_frontend < MAX_NUMBER_OF_FRONTENDS) {
2259 dprintk("set slave fe %p to index %i", fe_slave, index_frontend);
2260 state->fe[index_frontend] = fe_slave;
2261 return 0;
2262 }
2263
2264 dprintk("too many slave frontend");
2265 return -ENOMEM;
2266}
2267EXPORT_SYMBOL(dib9000_set_slave_frontend);
2268
2269int dib9000_remove_slave_frontend(struct dvb_frontend *fe)
2270{
2271 struct dib9000_state *state = fe->demodulator_priv;
2272 u8 index_frontend = 1;
2273
2274 while ((index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL))
2275 index_frontend++;
2276 if (index_frontend != 1) {
2277 dprintk("remove slave fe %p (index %i)", state->fe[index_frontend - 1], index_frontend - 1);
2278 state->fe[index_frontend] = NULL;
2279 return 0;
2280 }
2281
2282 dprintk("no frontend to be removed");
2283 return -ENODEV;
2284}
2285EXPORT_SYMBOL(dib9000_remove_slave_frontend);
2286
2287struct dvb_frontend *dib9000_get_slave_frontend(struct dvb_frontend *fe, int slave_index)
2288{
2289 struct dib9000_state *state = fe->demodulator_priv;
2290
2291 if (slave_index >= MAX_NUMBER_OF_FRONTENDS)
2292 return NULL;
2293 return state->fe[slave_index];
2294}
2295EXPORT_SYMBOL(dib9000_get_slave_frontend);
2296
2297static struct dvb_frontend_ops dib9000_ops;
2298struct dvb_frontend *dib9000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, const struct dib9000_config *cfg)
2299{
2300 struct dvb_frontend *fe;
2301 struct dib9000_state *st;
2302 st = kzalloc(sizeof(struct dib9000_state), GFP_KERNEL);
2303 if (st == NULL)
2304 return NULL;
2305 fe = kzalloc(sizeof(struct dvb_frontend), GFP_KERNEL);
2306 if (fe == NULL) {
2307 kfree(st);
2308 return NULL;
2309 }
2310
2311 memcpy(&st->chip.d9.cfg, cfg, sizeof(struct dib9000_config));
2312 st->i2c.i2c_adap = i2c_adap;
2313 st->i2c.i2c_addr = i2c_addr;
2314 st->i2c.i2c_write_buffer = st->i2c_write_buffer;
2315 st->i2c.i2c_read_buffer = st->i2c_read_buffer;
2316
2317 st->gpio_dir = DIB9000_GPIO_DEFAULT_DIRECTIONS;
2318 st->gpio_val = DIB9000_GPIO_DEFAULT_VALUES;
2319 st->gpio_pwm_pos = DIB9000_GPIO_DEFAULT_PWM_POS;
2320
2321 DibInitLock(&st->platform.risc.mbx_if_lock);
2322 DibInitLock(&st->platform.risc.mbx_lock);
2323 DibInitLock(&st->platform.risc.mem_lock);
2324 DibInitLock(&st->platform.risc.mem_mbx_lock);
2325
2326 st->fe[0] = fe;
2327 fe->demodulator_priv = st;
2328 memcpy(&st->fe[0]->ops, &dib9000_ops, sizeof(struct dvb_frontend_ops));
2329
2330 /* Ensure the output mode remains at the previous default if it's
2331 * not specifically set by the caller.
2332 */
2333 if ((st->chip.d9.cfg.output_mode != OUTMODE_MPEG2_SERIAL) && (st->chip.d9.cfg.output_mode != OUTMODE_MPEG2_PAR_GATED_CLK))
2334 st->chip.d9.cfg.output_mode = OUTMODE_MPEG2_FIFO;
2335
2336 if (dib9000_identify(&st->i2c) == 0)
2337 goto error;
2338
2339 dibx000_init_i2c_master(&st->i2c_master, DIB7000MC, st->i2c.i2c_adap, st->i2c.i2c_addr);
2340
2341 st->tuner_adap.dev.parent = i2c_adap->dev.parent;
2342 strncpy(st->tuner_adap.name, "DIB9000_FW TUNER ACCESS", sizeof(st->tuner_adap.name));
2343 st->tuner_adap.algo = &dib9000_tuner_algo;
2344 st->tuner_adap.algo_data = NULL;
2345 i2c_set_adapdata(&st->tuner_adap, st);
2346 if (i2c_add_adapter(&st->tuner_adap) < 0)
2347 goto error;
2348
2349 st->component_bus.dev.parent = i2c_adap->dev.parent;
2350 strncpy(st->component_bus.name, "DIB9000_FW COMPONENT BUS ACCESS", sizeof(st->component_bus.name));
2351 st->component_bus.algo = &dib9000_component_bus_algo;
2352 st->component_bus.algo_data = NULL;
2353 st->component_bus_speed = 340;
2354 i2c_set_adapdata(&st->component_bus, st);
2355 if (i2c_add_adapter(&st->component_bus) < 0)
2356 goto component_bus_add_error;
2357
2358 dib9000_fw_reset(fe);
2359
2360 return fe;
2361
2362component_bus_add_error:
2363 i2c_del_adapter(&st->tuner_adap);
2364error:
2365 kfree(st);
2366 return NULL;
2367}
2368EXPORT_SYMBOL(dib9000_attach);
2369
2370static struct dvb_frontend_ops dib9000_ops = {
2371 .info = {
2372 .name = "DiBcom 9000",
2373 .type = FE_OFDM,
2374 .frequency_min = 44250000,
2375 .frequency_max = 867250000,
2376 .frequency_stepsize = 62500,
2377 .caps = FE_CAN_INVERSION_AUTO |
2378 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
2379 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
2380 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
2381 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_RECOVER | FE_CAN_HIERARCHY_AUTO,
2382 },
2383
2384 .release = dib9000_release,
2385
2386 .init = dib9000_wakeup,
2387 .sleep = dib9000_sleep,
2388
2389 .set_frontend = dib9000_set_frontend,
2390 .get_tune_settings = dib9000_fe_get_tune_settings,
2391 .get_frontend = dib9000_get_frontend,
2392
2393 .read_status = dib9000_read_status,
2394 .read_ber = dib9000_read_ber,
2395 .read_signal_strength = dib9000_read_signal_strength,
2396 .read_snr = dib9000_read_snr,
2397 .read_ucblocks = dib9000_read_unc_blocks,
2398};
2399
2400MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>");
2401MODULE_AUTHOR("Olivier Grenie <ogrenie@dibcom.fr>");
2402MODULE_DESCRIPTION("Driver for the DiBcom 9000 COFDM demodulator");
2403MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/dib9000.h b/drivers/media/dvb/frontends/dib9000.h
new file mode 100644
index 000000000000..b5781a48034c
--- /dev/null
+++ b/drivers/media/dvb/frontends/dib9000.h
@@ -0,0 +1,131 @@
1#ifndef DIB9000_H
2#define DIB9000_H
3
4#include "dibx000_common.h"
5
6struct dib9000_config {
7 u8 dvbt_mode;
8 u8 output_mpeg2_in_188_bytes;
9 u8 hostbus_diversity;
10 struct dibx000_bandwidth_config *bw;
11
12 u16 if_drives;
13
14 u32 timing_frequency;
15 u32 xtal_clock_khz;
16 u32 vcxo_timer;
17 u32 demod_clock_khz;
18
19 const u8 *microcode_B_fe_buffer;
20 u32 microcode_B_fe_size;
21
22 struct dibGPIOFunction gpio_function[2];
23 struct dibSubbandSelection subband;
24
25 u8 output_mode;
26};
27
28#define DEFAULT_DIB9000_I2C_ADDRESS 18
29
30#if defined(CONFIG_DVB_DIB9000) || (defined(CONFIG_DVB_DIB9000_MODULE) && defined(MODULE))
31extern struct dvb_frontend *dib9000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, const struct dib9000_config *cfg);
32extern int dib9000_i2c_enumeration(struct i2c_adapter *host, int no_of_demods, u8 default_addr, u8 first_addr);
33extern struct i2c_adapter *dib9000_get_tuner_interface(struct dvb_frontend *fe);
34extern struct i2c_adapter *dib9000_get_i2c_master(struct dvb_frontend *fe, enum dibx000_i2c_interface intf, int gating);
35extern int dib9000_set_gpio(struct dvb_frontend *fe, u8 num, u8 dir, u8 val);
36extern int dib9000_fw_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff);
37extern int dib9000_fw_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
38extern int dib9000_firmware_post_pll_init(struct dvb_frontend *fe);
39extern int dib9000_set_slave_frontend(struct dvb_frontend *fe, struct dvb_frontend *fe_slave);
40extern int dib9000_remove_slave_frontend(struct dvb_frontend *fe);
41extern struct dvb_frontend *dib9000_get_slave_frontend(struct dvb_frontend *fe, int slave_index);
42extern struct i2c_adapter *dib9000_get_component_bus_interface(struct dvb_frontend *fe);
43extern int dib9000_set_i2c_adapter(struct dvb_frontend *fe, struct i2c_adapter *i2c);
44extern int dib9000_fw_set_component_bus_speed(struct dvb_frontend *fe, u16 speed);
45#else
46static inline struct dvb_frontend *dib9000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib9000_config *cfg)
47{
48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
49 return NULL;
50}
51
52static inline struct i2c_adapter *dib9000_get_i2c_master(struct dvb_frontend *fe, enum dibx000_i2c_interface intf, int gating)
53{
54 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
55 return NULL;
56}
57
58static inline int dib9000_i2c_enumeration(struct i2c_adapter *host, int no_of_demods, u8 default_addr, u8 first_addr)
59{
60 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
61 return -ENODEV;
62}
63
64static inline struct i2c_adapter *dib9000_get_tuner_interface(struct dvb_frontend *fe)
65{
66 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
67 return NULL;
68}
69
70static inline int dib9000_set_gpio(struct dvb_frontend *fe, u8 num, u8 dir, u8 val)
71{
72 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
73 return -ENODEV;
74}
75
76static inline int dib9000_fw_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff)
77{
78 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
79 return -ENODEV;
80}
81
82static inline int dib9000_fw_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff)
83{
84 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
85 return -ENODEV;
86}
87
88static inline int dib9000_firmware_post_pll_init(struct dvb_frontend *fe)
89{
90 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
91 return -ENODEV;
92}
93
94static inline int dib9000_set_slave_frontend(struct dvb_frontend *fe, struct dvb_frontend *fe_slave)
95{
96 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
97 return -ENODEV;
98}
99
100int dib9000_remove_slave_frontend(struct dvb_frontend *fe)
101{
102 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
103 return -ENODEV;
104}
105
106static inline struct dvb_frontend *dib9000_get_slave_frontend(struct dvb_frontend *fe, int slave_index)
107{
108 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
109 return NULL;
110}
111
112static inline struct i2c_adapter *dib9000_get_component_bus_interface(struct dvb_frontend *fe)
113{
114 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
115 return NULL;
116}
117
118static inline int dib9000_set_i2c_adapter(struct dvb_frontend *fe, struct i2c_adapter *i2c)
119{
120 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
121 return -ENODEV;
122}
123
124static inline int dib9000_fw_set_component_bus_speed(struct dvb_frontend *fe, u16 speed)
125{
126 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
127 return -ENODEV;
128}
129#endif
130
131#endif
diff --git a/drivers/media/dvb/frontends/dibx000_common.c b/drivers/media/dvb/frontends/dibx000_common.c
index 980e02f1575e..dc5d17a67579 100644
--- a/drivers/media/dvb/frontends/dibx000_common.c
+++ b/drivers/media/dvb/frontends/dibx000_common.c
@@ -10,16 +10,161 @@ MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
10 10
11static int dibx000_write_word(struct dibx000_i2c_master *mst, u16 reg, u16 val) 11static int dibx000_write_word(struct dibx000_i2c_master *mst, u16 reg, u16 val)
12{ 12{
13 u8 b[4] = { 13 mst->i2c_write_buffer[0] = (reg >> 8) & 0xff;
14 (reg >> 8) & 0xff, reg & 0xff, 14 mst->i2c_write_buffer[1] = reg & 0xff;
15 (val >> 8) & 0xff, val & 0xff, 15 mst->i2c_write_buffer[2] = (val >> 8) & 0xff;
16 }; 16 mst->i2c_write_buffer[3] = val & 0xff;
17 struct i2c_msg msg = { 17
18 .addr = mst->i2c_addr,.flags = 0,.buf = b,.len = 4 18 memset(mst->msg, 0, sizeof(struct i2c_msg));
19 }; 19 mst->msg[0].addr = mst->i2c_addr;
20 return i2c_transfer(mst->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0; 20 mst->msg[0].flags = 0;
21 mst->msg[0].buf = mst->i2c_write_buffer;
22 mst->msg[0].len = 4;
23
24 return i2c_transfer(mst->i2c_adap, mst->msg, 1) != 1 ? -EREMOTEIO : 0;
21} 25}
22 26
27static u16 dibx000_read_word(struct dibx000_i2c_master *mst, u16 reg)
28{
29 mst->i2c_write_buffer[0] = reg >> 8;
30 mst->i2c_write_buffer[1] = reg & 0xff;
31
32 memset(mst->msg, 0, 2 * sizeof(struct i2c_msg));
33 mst->msg[0].addr = mst->i2c_addr;
34 mst->msg[0].flags = 0;
35 mst->msg[0].buf = mst->i2c_write_buffer;
36 mst->msg[0].len = 2;
37 mst->msg[1].addr = mst->i2c_addr;
38 mst->msg[1].flags = I2C_M_RD;
39 mst->msg[1].buf = mst->i2c_read_buffer;
40 mst->msg[1].len = 2;
41
42 if (i2c_transfer(mst->i2c_adap, mst->msg, 2) != 2)
43 dprintk("i2c read error on %d", reg);
44
45 return (mst->i2c_read_buffer[0] << 8) | mst->i2c_read_buffer[1];
46}
47
48static int dibx000_is_i2c_done(struct dibx000_i2c_master *mst)
49{
50 int i = 100;
51 u16 status;
52
53 while (((status = dibx000_read_word(mst, mst->base_reg + 2)) & 0x0100) == 0 && --i > 0)
54 ;
55
56 /* i2c timed out */
57 if (i == 0)
58 return -EREMOTEIO;
59
60 /* no acknowledge */
61 if ((status & 0x0080) == 0)
62 return -EREMOTEIO;
63
64 return 0;
65}
66
67static int dibx000_master_i2c_write(struct dibx000_i2c_master *mst, struct i2c_msg *msg, u8 stop)
68{
69 u16 data;
70 u16 da;
71 u16 i;
72 u16 txlen = msg->len, len;
73 const u8 *b = msg->buf;
74
75 while (txlen) {
76 dibx000_read_word(mst, mst->base_reg + 2);
77
78 len = txlen > 8 ? 8 : txlen;
79 for (i = 0; i < len; i += 2) {
80 data = *b++ << 8;
81 if (i+1 < len)
82 data |= *b++;
83 dibx000_write_word(mst, mst->base_reg, data);
84 }
85 da = (((u8) (msg->addr)) << 9) |
86 (1 << 8) |
87 (1 << 7) |
88 (0 << 6) |
89 (0 << 5) |
90 ((len & 0x7) << 2) |
91 (0 << 1) |
92 (0 << 0);
93
94 if (txlen == msg->len)
95 da |= 1 << 5; /* start */
96
97 if (txlen-len == 0 && stop)
98 da |= 1 << 6; /* stop */
99
100 dibx000_write_word(mst, mst->base_reg+1, da);
101
102 if (dibx000_is_i2c_done(mst) != 0)
103 return -EREMOTEIO;
104 txlen -= len;
105 }
106
107 return 0;
108}
109
110static int dibx000_master_i2c_read(struct dibx000_i2c_master *mst, struct i2c_msg *msg)
111{
112 u16 da;
113 u8 *b = msg->buf;
114 u16 rxlen = msg->len, len;
115
116 while (rxlen) {
117 len = rxlen > 8 ? 8 : rxlen;
118 da = (((u8) (msg->addr)) << 9) |
119 (1 << 8) |
120 (1 << 7) |
121 (0 << 6) |
122 (0 << 5) |
123 ((len & 0x7) << 2) |
124 (1 << 1) |
125 (0 << 0);
126
127 if (rxlen == msg->len)
128 da |= 1 << 5; /* start */
129
130 if (rxlen-len == 0)
131 da |= 1 << 6; /* stop */
132 dibx000_write_word(mst, mst->base_reg+1, da);
133
134 if (dibx000_is_i2c_done(mst) != 0)
135 return -EREMOTEIO;
136
137 rxlen -= len;
138
139 while (len) {
140 da = dibx000_read_word(mst, mst->base_reg);
141 *b++ = (da >> 8) & 0xff;
142 len--;
143 if (len >= 1) {
144 *b++ = da & 0xff;
145 len--;
146 }
147 }
148 }
149
150 return 0;
151}
152
153int dibx000_i2c_set_speed(struct i2c_adapter *i2c_adap, u16 speed)
154{
155 struct dibx000_i2c_master *mst = i2c_get_adapdata(i2c_adap);
156
157 if (mst->device_rev < DIB7000MC && speed < 235)
158 speed = 235;
159 return dibx000_write_word(mst, mst->base_reg + 3, (u16)(60000 / speed));
160
161}
162EXPORT_SYMBOL(dibx000_i2c_set_speed);
163
164static u32 dibx000_i2c_func(struct i2c_adapter *adapter)
165{
166 return I2C_FUNC_I2C;
167}
23 168
24static int dibx000_i2c_select_interface(struct dibx000_i2c_master *mst, 169static int dibx000_i2c_select_interface(struct dibx000_i2c_master *mst,
25 enum dibx000_i2c_interface intf) 170 enum dibx000_i2c_interface intf)
@@ -32,6 +177,60 @@ static int dibx000_i2c_select_interface(struct dibx000_i2c_master *mst,
32 return 0; 177 return 0;
33} 178}
34 179
180static int dibx000_i2c_master_xfer_gpio12(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
181{
182 struct dibx000_i2c_master *mst = i2c_get_adapdata(i2c_adap);
183 int msg_index;
184 int ret = 0;
185
186 dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_GPIO_1_2);
187 for (msg_index = 0; msg_index < num; msg_index++) {
188 if (msg[msg_index].flags & I2C_M_RD) {
189 ret = dibx000_master_i2c_read(mst, &msg[msg_index]);
190 if (ret != 0)
191 return 0;
192 } else {
193 ret = dibx000_master_i2c_write(mst, &msg[msg_index], 1);
194 if (ret != 0)
195 return 0;
196 }
197 }
198
199 return num;
200}
201
202static int dibx000_i2c_master_xfer_gpio34(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
203{
204 struct dibx000_i2c_master *mst = i2c_get_adapdata(i2c_adap);
205 int msg_index;
206 int ret = 0;
207
208 dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_GPIO_3_4);
209 for (msg_index = 0; msg_index < num; msg_index++) {
210 if (msg[msg_index].flags & I2C_M_RD) {
211 ret = dibx000_master_i2c_read(mst, &msg[msg_index]);
212 if (ret != 0)
213 return 0;
214 } else {
215 ret = dibx000_master_i2c_write(mst, &msg[msg_index], 1);
216 if (ret != 0)
217 return 0;
218 }
219 }
220
221 return num;
222}
223
224static struct i2c_algorithm dibx000_i2c_master_gpio12_xfer_algo = {
225 .master_xfer = dibx000_i2c_master_xfer_gpio12,
226 .functionality = dibx000_i2c_func,
227};
228
229static struct i2c_algorithm dibx000_i2c_master_gpio34_xfer_algo = {
230 .master_xfer = dibx000_i2c_master_xfer_gpio34,
231 .functionality = dibx000_i2c_func,
232};
233
35static int dibx000_i2c_gate_ctrl(struct dibx000_i2c_master *mst, u8 tx[4], 234static int dibx000_i2c_gate_ctrl(struct dibx000_i2c_master *mst, u8 tx[4],
36 u8 addr, int onoff) 235 u8 addr, int onoff)
37{ 236{
@@ -54,35 +253,73 @@ static int dibx000_i2c_gate_ctrl(struct dibx000_i2c_master *mst, u8 tx[4],
54 return 0; 253 return 0;
55} 254}
56 255
57static u32 dibx000_i2c_func(struct i2c_adapter *adapter) 256static int dibx000_i2c_gated_gpio67_xfer(struct i2c_adapter *i2c_adap,
257 struct i2c_msg msg[], int num)
58{ 258{
59 return I2C_FUNC_I2C; 259 struct dibx000_i2c_master *mst = i2c_get_adapdata(i2c_adap);
260
261 if (num > 32) {
262 dprintk("%s: too much I2C message to be transmitted (%i).\
263 Maximum is 32", __func__, num);
264 return -ENOMEM;
265 }
266
267 memset(mst->msg, 0, sizeof(struct i2c_msg) * (2 + num));
268
269 dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_GPIO_6_7);
270
271 /* open the gate */
272 dibx000_i2c_gate_ctrl(mst, &mst->i2c_write_buffer[0], msg[0].addr, 1);
273 mst->msg[0].addr = mst->i2c_addr;
274 mst->msg[0].buf = &mst->i2c_write_buffer[0];
275 mst->msg[0].len = 4;
276
277 memcpy(&mst->msg[1], msg, sizeof(struct i2c_msg) * num);
278
279 /* close the gate */
280 dibx000_i2c_gate_ctrl(mst, &mst->i2c_write_buffer[4], 0, 0);
281 mst->msg[num + 1].addr = mst->i2c_addr;
282 mst->msg[num + 1].buf = &mst->i2c_write_buffer[4];
283 mst->msg[num + 1].len = 4;
284
285 return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
60} 286}
61 287
288static struct i2c_algorithm dibx000_i2c_gated_gpio67_algo = {
289 .master_xfer = dibx000_i2c_gated_gpio67_xfer,
290 .functionality = dibx000_i2c_func,
291};
292
62static int dibx000_i2c_gated_tuner_xfer(struct i2c_adapter *i2c_adap, 293static int dibx000_i2c_gated_tuner_xfer(struct i2c_adapter *i2c_adap,
63 struct i2c_msg msg[], int num) 294 struct i2c_msg msg[], int num)
64{ 295{
65 struct dibx000_i2c_master *mst = i2c_get_adapdata(i2c_adap); 296 struct dibx000_i2c_master *mst = i2c_get_adapdata(i2c_adap);
66 struct i2c_msg m[2 + num];
67 u8 tx_open[4], tx_close[4];
68 297
69 memset(m, 0, sizeof(struct i2c_msg) * (2 + num)); 298 if (num > 32) {
299 dprintk("%s: too much I2C message to be transmitted (%i).\
300 Maximum is 32", __func__, num);
301 return -ENOMEM;
302 }
303
304 memset(mst->msg, 0, sizeof(struct i2c_msg) * (2 + num));
70 305
71 dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_TUNER); 306 dibx000_i2c_select_interface(mst, DIBX000_I2C_INTERFACE_TUNER);
72 307
73 dibx000_i2c_gate_ctrl(mst, tx_open, msg[0].addr, 1); 308 /* open the gate */
74 m[0].addr = mst->i2c_addr; 309 dibx000_i2c_gate_ctrl(mst, &mst->i2c_write_buffer[0], msg[0].addr, 1);
75 m[0].buf = tx_open; 310 mst->msg[0].addr = mst->i2c_addr;
76 m[0].len = 4; 311 mst->msg[0].buf = &mst->i2c_write_buffer[0];
312 mst->msg[0].len = 4;
77 313
78 memcpy(&m[1], msg, sizeof(struct i2c_msg) * num); 314 memcpy(&mst->msg[1], msg, sizeof(struct i2c_msg) * num);
79 315
80 dibx000_i2c_gate_ctrl(mst, tx_close, 0, 0); 316 /* close the gate */
81 m[num + 1].addr = mst->i2c_addr; 317 dibx000_i2c_gate_ctrl(mst, &mst->i2c_write_buffer[4], 0, 0);
82 m[num + 1].buf = tx_close; 318 mst->msg[num + 1].addr = mst->i2c_addr;
83 m[num + 1].len = 4; 319 mst->msg[num + 1].buf = &mst->i2c_write_buffer[4];
320 mst->msg[num + 1].len = 4;
84 321
85 return i2c_transfer(mst->i2c_adap, m, 2 + num) == 2 + num ? num : -EIO; 322 return i2c_transfer(mst->i2c_adap, mst->msg, 2 + num) == 2 + num ? num : -EIO;
86} 323}
87 324
88static struct i2c_algorithm dibx000_i2c_gated_tuner_algo = { 325static struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
@@ -91,8 +328,8 @@ static struct i2c_algorithm dibx000_i2c_gated_tuner_algo = {
91}; 328};
92 329
93struct i2c_adapter *dibx000_get_i2c_adapter(struct dibx000_i2c_master *mst, 330struct i2c_adapter *dibx000_get_i2c_adapter(struct dibx000_i2c_master *mst,
94 enum dibx000_i2c_interface intf, 331 enum dibx000_i2c_interface intf,
95 int gating) 332 int gating)
96{ 333{
97 struct i2c_adapter *i2c = NULL; 334 struct i2c_adapter *i2c = NULL;
98 335
@@ -101,6 +338,18 @@ struct i2c_adapter *dibx000_get_i2c_adapter(struct dibx000_i2c_master *mst,
101 if (gating) 338 if (gating)
102 i2c = &mst->gated_tuner_i2c_adap; 339 i2c = &mst->gated_tuner_i2c_adap;
103 break; 340 break;
341 case DIBX000_I2C_INTERFACE_GPIO_1_2:
342 if (!gating)
343 i2c = &mst->master_i2c_adap_gpio12;
344 break;
345 case DIBX000_I2C_INTERFACE_GPIO_3_4:
346 if (!gating)
347 i2c = &mst->master_i2c_adap_gpio34;
348 break;
349 case DIBX000_I2C_INTERFACE_GPIO_6_7:
350 if (gating)
351 i2c = &mst->master_i2c_adap_gpio67;
352 break;
104 default: 353 default:
105 printk(KERN_ERR "DiBX000: incorrect I2C interface selected\n"); 354 printk(KERN_ERR "DiBX000: incorrect I2C interface selected\n");
106 break; 355 break;
@@ -126,11 +375,11 @@ void dibx000_reset_i2c_master(struct dibx000_i2c_master *mst)
126EXPORT_SYMBOL(dibx000_reset_i2c_master); 375EXPORT_SYMBOL(dibx000_reset_i2c_master);
127 376
128static int i2c_adapter_init(struct i2c_adapter *i2c_adap, 377static int i2c_adapter_init(struct i2c_adapter *i2c_adap,
129 struct i2c_algorithm *algo, const char *name, 378 struct i2c_algorithm *algo, const char *name,
130 struct dibx000_i2c_master *mst) 379 struct dibx000_i2c_master *mst)
131{ 380{
132 strncpy(i2c_adap->name, name, sizeof(i2c_adap->name)); 381 strncpy(i2c_adap->name, name, sizeof(i2c_adap->name));
133 i2c_adap->class = I2C_CLASS_TV_DIGITAL, i2c_adap->algo = algo; 382 i2c_adap->algo = algo;
134 i2c_adap->algo_data = NULL; 383 i2c_adap->algo_data = NULL;
135 i2c_set_adapdata(i2c_adap, mst); 384 i2c_set_adapdata(i2c_adap, mst);
136 if (i2c_add_adapter(i2c_adap) < 0) 385 if (i2c_add_adapter(i2c_adap) < 0)
@@ -139,7 +388,7 @@ static int i2c_adapter_init(struct i2c_adapter *i2c_adap,
139} 388}
140 389
141int dibx000_init_i2c_master(struct dibx000_i2c_master *mst, u16 device_rev, 390int dibx000_init_i2c_master(struct dibx000_i2c_master *mst, u16 device_rev,
142 struct i2c_adapter *i2c_adap, u8 i2c_addr) 391 struct i2c_adapter *i2c_adap, u8 i2c_addr)
143{ 392{
144 u8 tx[4]; 393 u8 tx[4];
145 struct i2c_msg m = {.addr = i2c_addr >> 1,.buf = tx,.len = 4 }; 394 struct i2c_msg m = {.addr = i2c_addr >> 1,.buf = tx,.len = 4 };
@@ -153,11 +402,33 @@ int dibx000_init_i2c_master(struct dibx000_i2c_master *mst, u16 device_rev,
153 else 402 else
154 mst->base_reg = 768; 403 mst->base_reg = 768;
155 404
405 mst->gated_tuner_i2c_adap.dev.parent = mst->i2c_adap->dev.parent;
406 if (i2c_adapter_init
407 (&mst->gated_tuner_i2c_adap, &dibx000_i2c_gated_tuner_algo,
408 "DiBX000 tuner I2C bus", mst) != 0)
409 printk(KERN_ERR
410 "DiBX000: could not initialize the tuner i2c_adapter\n");
411
412 mst->master_i2c_adap_gpio12.dev.parent = mst->i2c_adap->dev.parent;
413 if (i2c_adapter_init
414 (&mst->master_i2c_adap_gpio12, &dibx000_i2c_master_gpio12_xfer_algo,
415 "DiBX000 master GPIO12 I2C bus", mst) != 0)
416 printk(KERN_ERR
417 "DiBX000: could not initialize the master i2c_adapter\n");
418
419 mst->master_i2c_adap_gpio34.dev.parent = mst->i2c_adap->dev.parent;
420 if (i2c_adapter_init
421 (&mst->master_i2c_adap_gpio34, &dibx000_i2c_master_gpio34_xfer_algo,
422 "DiBX000 master GPIO34 I2C bus", mst) != 0)
423 printk(KERN_ERR
424 "DiBX000: could not initialize the master i2c_adapter\n");
425
426 mst->master_i2c_adap_gpio67.dev.parent = mst->i2c_adap->dev.parent;
156 if (i2c_adapter_init 427 if (i2c_adapter_init
157 (&mst->gated_tuner_i2c_adap, &dibx000_i2c_gated_tuner_algo, 428 (&mst->master_i2c_adap_gpio67, &dibx000_i2c_gated_gpio67_algo,
158 "DiBX000 tuner I2C bus", mst) != 0) 429 "DiBX000 master GPIO67 I2C bus", mst) != 0)
159 printk(KERN_ERR 430 printk(KERN_ERR
160 "DiBX000: could not initialize the tuner i2c_adapter\n"); 431 "DiBX000: could not initialize the master i2c_adapter\n");
161 432
162 /* initialize the i2c-master by closing the gate */ 433 /* initialize the i2c-master by closing the gate */
163 dibx000_i2c_gate_ctrl(mst, tx, 0, 0); 434 dibx000_i2c_gate_ctrl(mst, tx, 0, 0);
@@ -170,16 +441,19 @@ EXPORT_SYMBOL(dibx000_init_i2c_master);
170void dibx000_exit_i2c_master(struct dibx000_i2c_master *mst) 441void dibx000_exit_i2c_master(struct dibx000_i2c_master *mst)
171{ 442{
172 i2c_del_adapter(&mst->gated_tuner_i2c_adap); 443 i2c_del_adapter(&mst->gated_tuner_i2c_adap);
444 i2c_del_adapter(&mst->master_i2c_adap_gpio12);
445 i2c_del_adapter(&mst->master_i2c_adap_gpio34);
446 i2c_del_adapter(&mst->master_i2c_adap_gpio67);
173} 447}
174EXPORT_SYMBOL(dibx000_exit_i2c_master); 448EXPORT_SYMBOL(dibx000_exit_i2c_master);
175 449
176 450
177u32 systime(void) 451u32 systime(void)
178{ 452{
179 struct timespec t; 453 struct timespec t;
180 454
181 t = current_kernel_time(); 455 t = current_kernel_time();
182 return (t.tv_sec * 10000) + (t.tv_nsec / 100000); 456 return (t.tv_sec * 10000) + (t.tv_nsec / 100000);
183} 457}
184EXPORT_SYMBOL(systime); 458EXPORT_SYMBOL(systime);
185 459
diff --git a/drivers/media/dvb/frontends/dibx000_common.h b/drivers/media/dvb/frontends/dibx000_common.h
index 4f5d141a308d..f031165c0459 100644
--- a/drivers/media/dvb/frontends/dibx000_common.h
+++ b/drivers/media/dvb/frontends/dibx000_common.h
@@ -4,7 +4,8 @@
4enum dibx000_i2c_interface { 4enum dibx000_i2c_interface {
5 DIBX000_I2C_INTERFACE_TUNER = 0, 5 DIBX000_I2C_INTERFACE_TUNER = 0,
6 DIBX000_I2C_INTERFACE_GPIO_1_2 = 1, 6 DIBX000_I2C_INTERFACE_GPIO_1_2 = 1,
7 DIBX000_I2C_INTERFACE_GPIO_3_4 = 2 7 DIBX000_I2C_INTERFACE_GPIO_3_4 = 2,
8 DIBX000_I2C_INTERFACE_GPIO_6_7 = 3
8}; 9};
9 10
10struct dibx000_i2c_master { 11struct dibx000_i2c_master {
@@ -17,24 +18,33 @@ struct dibx000_i2c_master {
17 18
18 enum dibx000_i2c_interface selected_interface; 19 enum dibx000_i2c_interface selected_interface;
19 20
20// struct i2c_adapter tuner_i2c_adap; 21/* struct i2c_adapter tuner_i2c_adap; */
21 struct i2c_adapter gated_tuner_i2c_adap; 22 struct i2c_adapter gated_tuner_i2c_adap;
23 struct i2c_adapter master_i2c_adap_gpio12;
24 struct i2c_adapter master_i2c_adap_gpio34;
25 struct i2c_adapter master_i2c_adap_gpio67;
22 26
23 struct i2c_adapter *i2c_adap; 27 struct i2c_adapter *i2c_adap;
24 u8 i2c_addr; 28 u8 i2c_addr;
25 29
26 u16 base_reg; 30 u16 base_reg;
31
32 /* for the I2C transfer */
33 struct i2c_msg msg[34];
34 u8 i2c_write_buffer[8];
35 u8 i2c_read_buffer[2];
27}; 36};
28 37
29extern int dibx000_init_i2c_master(struct dibx000_i2c_master *mst, 38extern int dibx000_init_i2c_master(struct dibx000_i2c_master *mst,
30 u16 device_rev, struct i2c_adapter *i2c_adap, 39 u16 device_rev, struct i2c_adapter *i2c_adap,
31 u8 i2c_addr); 40 u8 i2c_addr);
32extern struct i2c_adapter *dibx000_get_i2c_adapter(struct dibx000_i2c_master 41extern struct i2c_adapter *dibx000_get_i2c_adapter(struct dibx000_i2c_master
33 *mst, 42 *mst,
34 enum dibx000_i2c_interface 43 enum dibx000_i2c_interface
35 intf, int gating); 44 intf, int gating);
36extern void dibx000_exit_i2c_master(struct dibx000_i2c_master *mst); 45extern void dibx000_exit_i2c_master(struct dibx000_i2c_master *mst);
37extern void dibx000_reset_i2c_master(struct dibx000_i2c_master *mst); 46extern void dibx000_reset_i2c_master(struct dibx000_i2c_master *mst);
47extern int dibx000_i2c_set_speed(struct i2c_adapter *i2c_adap, u16 speed);
38 48
39extern u32 systime(void); 49extern u32 systime(void);
40 50
@@ -42,7 +52,7 @@ extern u32 systime(void);
42#define BAND_UHF 0x02 52#define BAND_UHF 0x02
43#define BAND_VHF 0x04 53#define BAND_VHF 0x04
44#define BAND_SBAND 0x08 54#define BAND_SBAND 0x08
45#define BAND_FM 0x10 55#define BAND_FM 0x10
46#define BAND_CBAND 0x20 56#define BAND_CBAND 0x20
47 57
48#define BAND_OF_FREQUENCY(freq_kHz) ((freq_kHz) <= 170000 ? BAND_CBAND : \ 58#define BAND_OF_FREQUENCY(freq_kHz) ((freq_kHz) <= 170000 ? BAND_CBAND : \
@@ -135,9 +145,9 @@ enum dibx000_adc_states {
135 DIBX000_VBG_DISABLE, 145 DIBX000_VBG_DISABLE,
136}; 146};
137 147
138#define BANDWIDTH_TO_KHZ(v) ( (v) == BANDWIDTH_8_MHZ ? 8000 : \ 148#define BANDWIDTH_TO_KHZ(v) ((v) == BANDWIDTH_8_MHZ ? 8000 : \
139 (v) == BANDWIDTH_7_MHZ ? 7000 : \ 149 (v) == BANDWIDTH_7_MHZ ? 7000 : \
140 (v) == BANDWIDTH_6_MHZ ? 6000 : 8000 ) 150 (v) == BANDWIDTH_6_MHZ ? 6000 : 8000)
141 151
142#define BANDWIDTH_TO_INDEX(v) ( \ 152#define BANDWIDTH_TO_INDEX(v) ( \
143 (v) == 8000 ? BANDWIDTH_8_MHZ : \ 153 (v) == 8000 ? BANDWIDTH_8_MHZ : \
@@ -153,53 +163,57 @@ enum dibx000_adc_states {
153#define OUTMODE_MPEG2_FIFO 5 163#define OUTMODE_MPEG2_FIFO 5
154#define OUTMODE_ANALOG_ADC 6 164#define OUTMODE_ANALOG_ADC 6
155 165
166#define INPUT_MODE_OFF 0x11
167#define INPUT_MODE_DIVERSITY 0x12
168#define INPUT_MODE_MPEG 0x13
169
156enum frontend_tune_state { 170enum frontend_tune_state {
157 CT_TUNER_START = 10, 171 CT_TUNER_START = 10,
158 CT_TUNER_STEP_0, 172 CT_TUNER_STEP_0,
159 CT_TUNER_STEP_1, 173 CT_TUNER_STEP_1,
160 CT_TUNER_STEP_2, 174 CT_TUNER_STEP_2,
161 CT_TUNER_STEP_3, 175 CT_TUNER_STEP_3,
162 CT_TUNER_STEP_4, 176 CT_TUNER_STEP_4,
163 CT_TUNER_STEP_5, 177 CT_TUNER_STEP_5,
164 CT_TUNER_STEP_6, 178 CT_TUNER_STEP_6,
165 CT_TUNER_STEP_7, 179 CT_TUNER_STEP_7,
166 CT_TUNER_STOP, 180 CT_TUNER_STOP,
167 181
168 CT_AGC_START = 20, 182 CT_AGC_START = 20,
169 CT_AGC_STEP_0, 183 CT_AGC_STEP_0,
170 CT_AGC_STEP_1, 184 CT_AGC_STEP_1,
171 CT_AGC_STEP_2, 185 CT_AGC_STEP_2,
172 CT_AGC_STEP_3, 186 CT_AGC_STEP_3,
173 CT_AGC_STEP_4, 187 CT_AGC_STEP_4,
174 CT_AGC_STOP, 188 CT_AGC_STOP,
175 189
176 CT_DEMOD_START = 30, 190 CT_DEMOD_START = 30,
177 CT_DEMOD_STEP_1, 191 CT_DEMOD_STEP_1,
178 CT_DEMOD_STEP_2, 192 CT_DEMOD_STEP_2,
179 CT_DEMOD_STEP_3, 193 CT_DEMOD_STEP_3,
180 CT_DEMOD_STEP_4, 194 CT_DEMOD_STEP_4,
181 CT_DEMOD_STEP_5, 195 CT_DEMOD_STEP_5,
182 CT_DEMOD_STEP_6, 196 CT_DEMOD_STEP_6,
183 CT_DEMOD_STEP_7, 197 CT_DEMOD_STEP_7,
184 CT_DEMOD_STEP_8, 198 CT_DEMOD_STEP_8,
185 CT_DEMOD_STEP_9, 199 CT_DEMOD_STEP_9,
186 CT_DEMOD_STEP_10, 200 CT_DEMOD_STEP_10,
187 CT_DEMOD_SEARCH_NEXT = 41, 201 CT_DEMOD_SEARCH_NEXT = 41,
188 CT_DEMOD_STEP_LOCKED, 202 CT_DEMOD_STEP_LOCKED,
189 CT_DEMOD_STOP, 203 CT_DEMOD_STOP,
190 204
191 CT_DONE = 100, 205 CT_DONE = 100,
192 CT_SHUTDOWN, 206 CT_SHUTDOWN,
193 207
194}; 208};
195 209
196struct dvb_frontend_parametersContext { 210struct dvb_frontend_parametersContext {
197#define CHANNEL_STATUS_PARAMETERS_UNKNOWN 0x01 211#define CHANNEL_STATUS_PARAMETERS_UNKNOWN 0x01
198#define CHANNEL_STATUS_PARAMETERS_SET 0x02 212#define CHANNEL_STATUS_PARAMETERS_SET 0x02
199 u8 status; 213 u8 status;
200 u32 tune_time_estimation[2]; 214 u32 tune_time_estimation[2];
201 s32 tps_available; 215 s32 tps_available;
202 u16 tps[9]; 216 u16 tps[9];
203}; 217};
204 218
205#define FE_STATUS_TUNE_FAILED 0 219#define FE_STATUS_TUNE_FAILED 0
@@ -216,4 +230,49 @@ struct dvb_frontend_parametersContext {
216 230
217#define ABS(x) ((x < 0) ? (-x) : (x)) 231#define ABS(x) ((x < 0) ? (-x) : (x))
218 232
233#define DATA_BUS_ACCESS_MODE_8BIT 0x01
234#define DATA_BUS_ACCESS_MODE_16BIT 0x02
235#define DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT 0x10
236
237struct dibGPIOFunction {
238#define BOARD_GPIO_COMPONENT_BUS_ADAPTER 1
239#define BOARD_GPIO_COMPONENT_DEMOD 2
240 u8 component;
241
242#define BOARD_GPIO_FUNCTION_BOARD_ON 1
243#define BOARD_GPIO_FUNCTION_BOARD_OFF 2
244#define BOARD_GPIO_FUNCTION_COMPONENT_ON 3
245#define BOARD_GPIO_FUNCTION_COMPONENT_OFF 4
246#define BOARD_GPIO_FUNCTION_SUBBAND_PWM 5
247#define BOARD_GPIO_FUNCTION_SUBBAND_GPIO 6
248 u8 function;
249
250/* mask, direction and value are used specify which GPIO to change GPIO0
251 * is LSB and possible GPIO31 is MSB. The same bit-position as in the
252 * mask is used for the direction and the value. Direction == 1 is OUT,
253 * 0 == IN. For direction "OUT" value is either 1 or 0, for direction IN
254 * value has no meaning.
255 *
256 * In case of BOARD_GPIO_FUNCTION_PWM mask is giving the GPIO to be
257 * used to do the PWM. Direction gives the PWModulator to be used.
258 * Value gives the PWM value in device-dependent scale.
259 */
260 u32 mask;
261 u32 direction;
262 u32 value;
263};
264
265#define MAX_NB_SUBBANDS 8
266struct dibSubbandSelection {
267 u8 size; /* Actual number of subbands. */
268 struct {
269 u16 f_mhz;
270 struct dibGPIOFunction gpio;
271 } subband[MAX_NB_SUBBANDS];
272};
273
274#define DEMOD_TIMF_SET 0x00
275#define DEMOD_TIMF_GET 0x01
276#define DEMOD_TIMF_UPDATE 0x02
277
219#endif 278#endif
diff --git a/drivers/media/dvb/frontends/drx397xD.c b/drivers/media/dvb/frontends/drx397xD.c
deleted file mode 100644
index f74cca6dc26b..000000000000
--- a/drivers/media/dvb/frontends/drx397xD.c
+++ /dev/null
@@ -1,1511 +0,0 @@
1/*
2 * Driver for Micronas drx397xD demodulator
3 *
4 * Copyright (C) 2007 Henk Vergonet <Henk.Vergonet@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#define DEBUG /* uncomment if you want debugging output */
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/init.h>
25#include <linux/device.h>
26#include <linux/delay.h>
27#include <linux/string.h>
28#include <linux/firmware.h>
29#include <linux/slab.h>
30#include <asm/div64.h>
31
32#include "dvb_frontend.h"
33#include "drx397xD.h"
34
35static const char mod_name[] = "drx397xD";
36
37#define MAX_CLOCK_DRIFT 200 /* maximal 200 PPM allowed */
38
39#define F_SET_0D0h 1
40#define F_SET_0D4h 2
41
42enum fw_ix {
43#define _FW_ENTRY(a, b, c) b
44#include "drx397xD_fw.h"
45};
46
47/* chip specifics */
48struct drx397xD_state {
49 struct i2c_adapter *i2c;
50 struct dvb_frontend frontend;
51 struct drx397xD_config config;
52 enum fw_ix chip_rev;
53 int flags;
54 u32 bandwidth_parm; /* internal bandwidth conversions */
55 u32 f_osc; /* w90: actual osc frequency [Hz] */
56};
57
58/* Firmware */
59static const char *blob_name[] = {
60#define _BLOB_ENTRY(a, b) a
61#include "drx397xD_fw.h"
62};
63
64enum blob_ix {
65#define _BLOB_ENTRY(a, b) b
66#include "drx397xD_fw.h"
67};
68
69static struct {
70 const char *name;
71 const struct firmware *file;
72 rwlock_t lock;
73 int refcnt;
74 const u8 *data[ARRAY_SIZE(blob_name)];
75} fw[] = {
76#define _FW_ENTRY(a, b, c) { \
77 .name = a, \
78 .file = NULL, \
79 .lock = __RW_LOCK_UNLOCKED(fw[c].lock), \
80 .refcnt = 0, \
81 .data = { } }
82#include "drx397xD_fw.h"
83};
84
85/* use only with writer lock acquired */
86static void _drx_release_fw(struct drx397xD_state *s, enum fw_ix ix)
87{
88 memset(&fw[ix].data[0], 0, sizeof(fw[0].data));
89 if (fw[ix].file)
90 release_firmware(fw[ix].file);
91}
92
93static void drx_release_fw(struct drx397xD_state *s)
94{
95 enum fw_ix ix = s->chip_rev;
96
97 pr_debug("%s\n", __func__);
98
99 write_lock(&fw[ix].lock);
100 if (fw[ix].refcnt) {
101 fw[ix].refcnt--;
102 if (fw[ix].refcnt == 0)
103 _drx_release_fw(s, ix);
104 }
105 write_unlock(&fw[ix].lock);
106}
107
108static int drx_load_fw(struct drx397xD_state *s, enum fw_ix ix)
109{
110 const u8 *data;
111 size_t size, len;
112 int i = 0, j, rc = -EINVAL;
113
114 pr_debug("%s\n", __func__);
115
116 if (ix < 0 || ix >= ARRAY_SIZE(fw))
117 return -EINVAL;
118 s->chip_rev = ix;
119
120 write_lock(&fw[ix].lock);
121 if (fw[ix].file) {
122 rc = 0;
123 goto exit_ok;
124 }
125 memset(&fw[ix].data[0], 0, sizeof(fw[0].data));
126
127 rc = request_firmware(&fw[ix].file, fw[ix].name, s->i2c->dev.parent);
128 if (rc != 0) {
129 printk(KERN_ERR "%s: Firmware \"%s\" not available\n",
130 mod_name, fw[ix].name);
131 goto exit_err;
132 }
133
134 if (!fw[ix].file->data || fw[ix].file->size < 10)
135 goto exit_corrupt;
136
137 data = fw[ix].file->data;
138 size = fw[ix].file->size;
139
140 if (data[i++] != 2) /* check firmware version */
141 goto exit_corrupt;
142
143 do {
144 switch (data[i++]) {
145 case 0x00: /* bytecode */
146 if (i >= size)
147 break;
148 i += data[i];
149 case 0x01: /* reset */
150 case 0x02: /* sleep */
151 i++;
152 break;
153 case 0xfe: /* name */
154 len = strnlen(&data[i], size - i);
155 if (i + len + 1 >= size)
156 goto exit_corrupt;
157 if (data[i + len + 1] != 0)
158 goto exit_corrupt;
159 for (j = 0; j < ARRAY_SIZE(blob_name); j++) {
160 if (strcmp(blob_name[j], &data[i]) == 0) {
161 fw[ix].data[j] = &data[i + len + 1];
162 pr_debug("Loading %s\n", blob_name[j]);
163 }
164 }
165 i += len + 1;
166 break;
167 case 0xff: /* file terminator */
168 if (i == size) {
169 rc = 0;
170 goto exit_ok;
171 }
172 default:
173 goto exit_corrupt;
174 }
175 } while (i < size);
176
177exit_corrupt:
178 printk(KERN_ERR "%s: Firmware is corrupt\n", mod_name);
179exit_err:
180 _drx_release_fw(s, ix);
181 fw[ix].refcnt--;
182exit_ok:
183 fw[ix].refcnt++;
184 write_unlock(&fw[ix].lock);
185
186 return rc;
187}
188
189/* i2c bus IO */
190static int write_fw(struct drx397xD_state *s, enum blob_ix ix)
191{
192 const u8 *data;
193 int len, rc = 0, i = 0;
194 struct i2c_msg msg = {
195 .addr = s->config.demod_address,
196 .flags = 0
197 };
198
199 if (ix < 0 || ix >= ARRAY_SIZE(blob_name)) {
200 pr_debug("%s drx_fw_ix_t out of range\n", __func__);
201 return -EINVAL;
202 }
203 pr_debug("%s %s\n", __func__, blob_name[ix]);
204
205 read_lock(&fw[s->chip_rev].lock);
206 data = fw[s->chip_rev].data[ix];
207 if (!data) {
208 rc = -EINVAL;
209 goto exit_rc;
210 }
211
212 for (;;) {
213 switch (data[i++]) {
214 case 0: /* bytecode */
215 len = data[i++];
216 msg.len = len;
217 msg.buf = (__u8 *) &data[i];
218 if (i2c_transfer(s->i2c, &msg, 1) != 1) {
219 rc = -EIO;
220 goto exit_rc;
221 }
222 i += len;
223 break;
224 case 1: /* reset */
225 case 2: /* sleep */
226 i++;
227 break;
228 default:
229 goto exit_rc;
230 }
231 }
232exit_rc:
233 read_unlock(&fw[s->chip_rev].lock);
234
235 return 0;
236}
237
238/* Function is not endian safe, use the RD16 wrapper below */
239static int _read16(struct drx397xD_state *s, __le32 i2c_adr)
240{
241 int rc;
242 u8 a[4];
243 __le16 v;
244 struct i2c_msg msg[2] = {
245 {
246 .addr = s->config.demod_address,
247 .flags = 0,
248 .buf = a,
249 .len = sizeof(a)
250 }, {
251 .addr = s->config.demod_address,
252 .flags = I2C_M_RD,
253 .buf = (u8 *)&v,
254 .len = sizeof(v)
255 }
256 };
257
258 *(__le32 *) a = i2c_adr;
259
260 rc = i2c_transfer(s->i2c, msg, 2);
261 if (rc != 2)
262 return -EIO;
263
264 return le16_to_cpu(v);
265}
266
267/* Function is not endian safe, use the WR16.. wrappers below */
268static int _write16(struct drx397xD_state *s, __le32 i2c_adr, __le16 val)
269{
270 u8 a[6];
271 int rc;
272 struct i2c_msg msg = {
273 .addr = s->config.demod_address,
274 .flags = 0,
275 .buf = a,
276 .len = sizeof(a)
277 };
278
279 *(__le32 *)a = i2c_adr;
280 *(__le16 *)&a[4] = val;
281
282 rc = i2c_transfer(s->i2c, &msg, 1);
283 if (rc != 1)
284 return -EIO;
285
286 return 0;
287}
288
289#define WR16(ss, adr, val) \
290 _write16(ss, I2C_ADR_C0(adr), cpu_to_le16(val))
291#define WR16_E0(ss, adr, val) \
292 _write16(ss, I2C_ADR_E0(adr), cpu_to_le16(val))
293#define RD16(ss, adr) \
294 _read16(ss, I2C_ADR_C0(adr))
295
296#define EXIT_RC(cmd) \
297 if ((rc = (cmd)) < 0) \
298 goto exit_rc
299
300/* Tuner callback */
301static int PLL_Set(struct drx397xD_state *s,
302 struct dvb_frontend_parameters *fep, int *df_tuner)
303{
304 struct dvb_frontend *fe = &s->frontend;
305 u32 f_tuner, f = fep->frequency;
306 int rc;
307
308 pr_debug("%s\n", __func__);
309
310 if ((f > s->frontend.ops.tuner_ops.info.frequency_max) ||
311 (f < s->frontend.ops.tuner_ops.info.frequency_min))
312 return -EINVAL;
313
314 *df_tuner = 0;
315 if (!s->frontend.ops.tuner_ops.set_params ||
316 !s->frontend.ops.tuner_ops.get_frequency)
317 return -ENOSYS;
318
319 rc = s->frontend.ops.tuner_ops.set_params(fe, fep);
320 if (rc < 0)
321 return rc;
322
323 rc = s->frontend.ops.tuner_ops.get_frequency(fe, &f_tuner);
324 if (rc < 0)
325 return rc;
326
327 *df_tuner = f_tuner - f;
328 pr_debug("%s requested %d [Hz] tuner %d [Hz]\n", __func__, f,
329 f_tuner);
330
331 return 0;
332}
333
334/* Demodulator helper functions */
335static int SC_WaitForReady(struct drx397xD_state *s)
336{
337 int cnt = 1000;
338 int rc;
339
340 pr_debug("%s\n", __func__);
341
342 while (cnt--) {
343 rc = RD16(s, 0x820043);
344 if (rc == 0)
345 return 0;
346 }
347
348 return -1;
349}
350
351static int SC_SendCommand(struct drx397xD_state *s, int cmd)
352{
353 int rc;
354
355 pr_debug("%s\n", __func__);
356
357 WR16(s, 0x820043, cmd);
358 SC_WaitForReady(s);
359 rc = RD16(s, 0x820042);
360 if ((rc & 0xffff) == 0xffff)
361 return -1;
362
363 return 0;
364}
365
366static int HI_Command(struct drx397xD_state *s, u16 cmd)
367{
368 int rc, cnt = 1000;
369
370 pr_debug("%s\n", __func__);
371
372 rc = WR16(s, 0x420032, cmd);
373 if (rc < 0)
374 return rc;
375
376 do {
377 rc = RD16(s, 0x420032);
378 if (rc == 0) {
379 rc = RD16(s, 0x420031);
380 return rc;
381 }
382 if (rc < 0)
383 return rc;
384 } while (--cnt);
385
386 return rc;
387}
388
389static int HI_CfgCommand(struct drx397xD_state *s)
390{
391
392 pr_debug("%s\n", __func__);
393
394 WR16(s, 0x420033, 0x3973);
395 WR16(s, 0x420034, s->config.w50); /* code 4, log 4 */
396 WR16(s, 0x420035, s->config.w52); /* code 15, log 9 */
397 WR16(s, 0x420036, s->config.demod_address << 1);
398 WR16(s, 0x420037, s->config.w56); /* code (set_i2c ?? initX 1 ), log 1 */
399 /* WR16(s, 0x420033, 0x3973); */
400 if ((s->config.w56 & 8) == 0)
401 return HI_Command(s, 3);
402
403 return WR16(s, 0x420032, 0x3);
404}
405
406static const u8 fastIncrDecLUT_15273[] = {
407 0x0e, 0x0f, 0x0f, 0x10, 0x11, 0x12, 0x12, 0x13, 0x14,
408 0x15, 0x16, 0x17, 0x18, 0x1a, 0x1b, 0x1c, 0x1d, 0x1f
409};
410
411static const u8 slowIncrDecLUT_15272[] = {
412 3, 4, 4, 5, 6
413};
414
415static int SetCfgIfAgc(struct drx397xD_state *s, struct drx397xD_CfgIfAgc *agc)
416{
417 u16 w06 = agc->w06;
418 u16 w08 = agc->w08;
419 u16 w0A = agc->w0A;
420 u16 w0C = agc->w0C;
421 int quot, rem, i, rc = -EINVAL;
422
423 pr_debug("%s\n", __func__);
424
425 if (agc->w04 > 0x3ff)
426 goto exit_rc;
427
428 if (agc->d00 == 1) {
429 EXIT_RC(RD16(s, 0x0c20010));
430 rc &= ~0x10;
431 EXIT_RC(WR16(s, 0x0c20010, rc));
432 return WR16(s, 0x0c20030, agc->w04 & 0x7ff);
433 }
434
435 if (agc->d00 != 0)
436 goto exit_rc;
437 if (w0A < w08)
438 goto exit_rc;
439 if (w0A > 0x3ff)
440 goto exit_rc;
441 if (w0C > 0x3ff)
442 goto exit_rc;
443 if (w06 > 0x3ff)
444 goto exit_rc;
445
446 EXIT_RC(RD16(s, 0x0c20010));
447 rc |= 0x10;
448 EXIT_RC(WR16(s, 0x0c20010, rc));
449
450 EXIT_RC(WR16(s, 0x0c20025, (w06 >> 1) & 0x1ff));
451 EXIT_RC(WR16(s, 0x0c20031, (w0A - w08) >> 1));
452 EXIT_RC(WR16(s, 0x0c20032, ((w0A + w08) >> 1) - 0x1ff));
453
454 quot = w0C / 113;
455 rem = w0C % 113;
456 if (quot <= 8) {
457 quot = 8 - quot;
458 } else {
459 quot = 0;
460 rem += 113;
461 }
462
463 EXIT_RC(WR16(s, 0x0c20024, quot));
464
465 i = fastIncrDecLUT_15273[rem / 8];
466 EXIT_RC(WR16(s, 0x0c2002d, i));
467 EXIT_RC(WR16(s, 0x0c2002e, i));
468
469 i = slowIncrDecLUT_15272[rem / 28];
470 EXIT_RC(WR16(s, 0x0c2002b, i));
471 rc = WR16(s, 0x0c2002c, i);
472exit_rc:
473 return rc;
474}
475
476static int SetCfgRfAgc(struct drx397xD_state *s, struct drx397xD_CfgRfAgc *agc)
477{
478 u16 w04 = agc->w04;
479 u16 w06 = agc->w06;
480 int rc = -1;
481
482 pr_debug("%s %d 0x%x 0x%x\n", __func__, agc->d00, w04, w06);
483
484 if (w04 > 0x3ff)
485 goto exit_rc;
486
487 switch (agc->d00) {
488 case 1:
489 if (w04 == 0x3ff)
490 w04 = 0x400;
491
492 EXIT_RC(WR16(s, 0x0c20036, w04));
493 s->config.w9C &= ~2;
494 EXIT_RC(WR16(s, 0x0c20015, s->config.w9C));
495 EXIT_RC(RD16(s, 0x0c20010));
496 rc &= 0xbfdf;
497 EXIT_RC(WR16(s, 0x0c20010, rc));
498 EXIT_RC(RD16(s, 0x0c20013));
499 rc &= ~2;
500 break;
501 case 0:
502 /* loc_8000659 */
503 s->config.w9C &= ~2;
504 EXIT_RC(WR16(s, 0x0c20015, s->config.w9C));
505 EXIT_RC(RD16(s, 0x0c20010));
506 rc &= 0xbfdf;
507 rc |= 0x4000;
508 EXIT_RC(WR16(s, 0x0c20010, rc));
509 EXIT_RC(WR16(s, 0x0c20051, (w06 >> 4) & 0x3f));
510 EXIT_RC(RD16(s, 0x0c20013));
511 rc &= ~2;
512 break;
513 default:
514 s->config.w9C |= 2;
515 EXIT_RC(WR16(s, 0x0c20015, s->config.w9C));
516 EXIT_RC(RD16(s, 0x0c20010));
517 rc &= 0xbfdf;
518 EXIT_RC(WR16(s, 0x0c20010, rc));
519
520 EXIT_RC(WR16(s, 0x0c20036, 0));
521
522 EXIT_RC(RD16(s, 0x0c20013));
523 rc |= 2;
524 }
525 rc = WR16(s, 0x0c20013, rc);
526
527exit_rc:
528 return rc;
529}
530
531static int GetLockStatus(struct drx397xD_state *s, int *lockstat)
532{
533 int rc;
534
535 *lockstat = 0;
536
537 rc = RD16(s, 0x082004b);
538 if (rc < 0)
539 return rc;
540
541 if (s->config.d60 != 2)
542 return 0;
543
544 if ((rc & 7) == 7)
545 *lockstat |= 1;
546 if ((rc & 3) == 3)
547 *lockstat |= 2;
548 if (rc & 1)
549 *lockstat |= 4;
550 return 0;
551}
552
553static int CorrectSysClockDeviation(struct drx397xD_state *s)
554{
555 int rc = -EINVAL;
556 int lockstat;
557 u32 clk, clk_limit;
558
559 pr_debug("%s\n", __func__);
560
561 if (s->config.d5C == 0) {
562 EXIT_RC(WR16(s, 0x08200e8, 0x010));
563 EXIT_RC(WR16(s, 0x08200e9, 0x113));
564 s->config.d5C = 1;
565 return rc;
566 }
567 if (s->config.d5C != 1)
568 goto exit_rc;
569
570 rc = RD16(s, 0x0820048);
571
572 rc = GetLockStatus(s, &lockstat);
573 if (rc < 0)
574 goto exit_rc;
575 if ((lockstat & 1) == 0)
576 goto exit_rc;
577
578 EXIT_RC(WR16(s, 0x0420033, 0x200));
579 EXIT_RC(WR16(s, 0x0420034, 0xc5));
580 EXIT_RC(WR16(s, 0x0420035, 0x10));
581 EXIT_RC(WR16(s, 0x0420036, 0x1));
582 EXIT_RC(WR16(s, 0x0420037, 0xa));
583 EXIT_RC(HI_Command(s, 6));
584 EXIT_RC(RD16(s, 0x0420040));
585 clk = rc;
586 EXIT_RC(RD16(s, 0x0420041));
587 clk |= rc << 16;
588
589 if (clk <= 0x26ffff)
590 goto exit_rc;
591 if (clk > 0x610000)
592 goto exit_rc;
593
594 if (!s->bandwidth_parm)
595 return -EINVAL;
596
597 /* round & convert to Hz */
598 clk = ((u64) (clk + 0x800000) * s->bandwidth_parm + (1 << 20)) >> 21;
599 clk_limit = s->config.f_osc * MAX_CLOCK_DRIFT / 1000;
600
601 if (clk - s->config.f_osc * 1000 + clk_limit <= 2 * clk_limit) {
602 s->f_osc = clk;
603 pr_debug("%s: osc %d %d [Hz]\n", __func__,
604 s->config.f_osc * 1000, clk - s->config.f_osc * 1000);
605 }
606 rc = WR16(s, 0x08200e8, 0);
607
608exit_rc:
609 return rc;
610}
611
612static int ConfigureMPEGOutput(struct drx397xD_state *s, int type)
613{
614 int rc, si, bp;
615
616 pr_debug("%s\n", __func__);
617
618 si = s->config.wA0;
619 if (s->config.w98 == 0) {
620 si |= 1;
621 bp = 0;
622 } else {
623 si &= ~1;
624 bp = 0x200;
625 }
626 if (s->config.w9A == 0)
627 si |= 0x80;
628 else
629 si &= ~0x80;
630
631 EXIT_RC(WR16(s, 0x2150045, 0));
632 EXIT_RC(WR16(s, 0x2150010, si));
633 EXIT_RC(WR16(s, 0x2150011, bp));
634 rc = WR16(s, 0x2150012, (type == 0 ? 0xfff : 0));
635
636exit_rc:
637 return rc;
638}
639
640static int drx_tune(struct drx397xD_state *s,
641 struct dvb_frontend_parameters *fep)
642{
643 u16 v22 = 0;
644 u16 v1C = 0;
645 u16 v1A = 0;
646 u16 v18 = 0;
647 u32 edi = 0, ebx = 0, ebp = 0, edx = 0;
648 u16 v20 = 0, v1E = 0, v16 = 0, v14 = 0, v12 = 0, v10 = 0, v0E = 0;
649
650 int rc, df_tuner = 0;
651 int a, b, c, d;
652 pr_debug("%s %d\n", __func__, s->config.d60);
653
654 if (s->config.d60 != 2)
655 goto set_tuner;
656 rc = CorrectSysClockDeviation(s);
657 if (rc < 0)
658 goto set_tuner;
659
660 s->config.d60 = 1;
661 rc = ConfigureMPEGOutput(s, 0);
662 if (rc < 0)
663 goto set_tuner;
664set_tuner:
665
666 rc = PLL_Set(s, fep, &df_tuner);
667 if (rc < 0) {
668 printk(KERN_ERR "Error in pll_set\n");
669 goto exit_rc;
670 }
671 msleep(200);
672
673 a = rc = RD16(s, 0x2150016);
674 if (rc < 0)
675 goto exit_rc;
676 b = rc = RD16(s, 0x2150010);
677 if (rc < 0)
678 goto exit_rc;
679 c = rc = RD16(s, 0x2150034);
680 if (rc < 0)
681 goto exit_rc;
682 d = rc = RD16(s, 0x2150035);
683 if (rc < 0)
684 goto exit_rc;
685 rc = WR16(s, 0x2150014, c);
686 rc = WR16(s, 0x2150015, d);
687 rc = WR16(s, 0x2150010, 0);
688 rc = WR16(s, 0x2150000, 2);
689 rc = WR16(s, 0x2150036, 0x0fff);
690 rc = WR16(s, 0x2150016, a);
691
692 rc = WR16(s, 0x2150010, 2);
693 rc = WR16(s, 0x2150007, 0);
694 rc = WR16(s, 0x2150000, 1);
695 rc = WR16(s, 0x2110000, 0);
696 rc = WR16(s, 0x0800000, 0);
697 rc = WR16(s, 0x2800000, 0);
698 rc = WR16(s, 0x2110010, 0x664);
699
700 rc = write_fw(s, DRXD_ResetECRAM);
701 rc = WR16(s, 0x2110000, 1);
702
703 rc = write_fw(s, DRXD_InitSC);
704 if (rc < 0)
705 goto exit_rc;
706
707 rc = SetCfgIfAgc(s, &s->config.ifagc);
708 if (rc < 0)
709 goto exit_rc;
710
711 rc = SetCfgRfAgc(s, &s->config.rfagc);
712 if (rc < 0)
713 goto exit_rc;
714
715 if (fep->u.ofdm.transmission_mode != TRANSMISSION_MODE_2K)
716 v22 = 1;
717 switch (fep->u.ofdm.transmission_mode) {
718 case TRANSMISSION_MODE_8K:
719 edi = 1;
720 if (s->chip_rev == DRXD_FW_B1)
721 break;
722
723 rc = WR16(s, 0x2010010, 0);
724 if (rc < 0)
725 break;
726 v1C = 0x63;
727 v1A = 0x53;
728 v18 = 0x43;
729 break;
730 default:
731 edi = 0;
732 if (s->chip_rev == DRXD_FW_B1)
733 break;
734
735 rc = WR16(s, 0x2010010, 1);
736 if (rc < 0)
737 break;
738
739 v1C = 0x61;
740 v1A = 0x47;
741 v18 = 0x41;
742 }
743
744 switch (fep->u.ofdm.guard_interval) {
745 case GUARD_INTERVAL_1_4:
746 edi |= 0x0c;
747 break;
748 case GUARD_INTERVAL_1_8:
749 edi |= 0x08;
750 break;
751 case GUARD_INTERVAL_1_16:
752 edi |= 0x04;
753 break;
754 case GUARD_INTERVAL_1_32:
755 break;
756 default:
757 v22 |= 2;
758 }
759
760 ebx = 0;
761 ebp = 0;
762 v20 = 0;
763 v1E = 0;
764 v16 = 0;
765 v14 = 0;
766 v12 = 0;
767 v10 = 0;
768 v0E = 0;
769
770 switch (fep->u.ofdm.hierarchy_information) {
771 case HIERARCHY_1:
772 edi |= 0x40;
773 if (s->chip_rev == DRXD_FW_B1)
774 break;
775 rc = WR16(s, 0x1c10047, 1);
776 if (rc < 0)
777 goto exit_rc;
778 rc = WR16(s, 0x2010012, 1);
779 if (rc < 0)
780 goto exit_rc;
781 ebx = 0x19f;
782 ebp = 0x1fb;
783 v20 = 0x0c0;
784 v1E = 0x195;
785 v16 = 0x1d6;
786 v14 = 0x1ef;
787 v12 = 4;
788 v10 = 5;
789 v0E = 5;
790 break;
791 case HIERARCHY_2:
792 edi |= 0x80;
793 if (s->chip_rev == DRXD_FW_B1)
794 break;
795 rc = WR16(s, 0x1c10047, 2);
796 if (rc < 0)
797 goto exit_rc;
798 rc = WR16(s, 0x2010012, 2);
799 if (rc < 0)
800 goto exit_rc;
801 ebx = 0x08f;
802 ebp = 0x12f;
803 v20 = 0x0c0;
804 v1E = 0x11e;
805 v16 = 0x1d6;
806 v14 = 0x15e;
807 v12 = 4;
808 v10 = 5;
809 v0E = 5;
810 break;
811 case HIERARCHY_4:
812 edi |= 0xc0;
813 if (s->chip_rev == DRXD_FW_B1)
814 break;
815 rc = WR16(s, 0x1c10047, 3);
816 if (rc < 0)
817 goto exit_rc;
818 rc = WR16(s, 0x2010012, 3);
819 if (rc < 0)
820 goto exit_rc;
821 ebx = 0x14d;
822 ebp = 0x197;
823 v20 = 0x0c0;
824 v1E = 0x1ce;
825 v16 = 0x1d6;
826 v14 = 0x11a;
827 v12 = 4;
828 v10 = 6;
829 v0E = 5;
830 break;
831 default:
832 v22 |= 8;
833 if (s->chip_rev == DRXD_FW_B1)
834 break;
835 rc = WR16(s, 0x1c10047, 0);
836 if (rc < 0)
837 goto exit_rc;
838 rc = WR16(s, 0x2010012, 0);
839 if (rc < 0)
840 goto exit_rc;
841 /* QPSK QAM16 QAM64 */
842 ebx = 0x19f; /* 62 */
843 ebp = 0x1fb; /* 15 */
844 v20 = 0x16a; /* 62 */
845 v1E = 0x195; /* 62 */
846 v16 = 0x1bb; /* 15 */
847 v14 = 0x1ef; /* 15 */
848 v12 = 5; /* 16 */
849 v10 = 5; /* 16 */
850 v0E = 5; /* 16 */
851 }
852
853 switch (fep->u.ofdm.constellation) {
854 default:
855 v22 |= 4;
856 case QPSK:
857 if (s->chip_rev == DRXD_FW_B1)
858 break;
859
860 rc = WR16(s, 0x1c10046, 0);
861 if (rc < 0)
862 goto exit_rc;
863 rc = WR16(s, 0x2010011, 0);
864 if (rc < 0)
865 goto exit_rc;
866 rc = WR16(s, 0x201001a, 0x10);
867 if (rc < 0)
868 goto exit_rc;
869 rc = WR16(s, 0x201001b, 0);
870 if (rc < 0)
871 goto exit_rc;
872 rc = WR16(s, 0x201001c, 0);
873 if (rc < 0)
874 goto exit_rc;
875 rc = WR16(s, 0x1c10062, v20);
876 if (rc < 0)
877 goto exit_rc;
878 rc = WR16(s, 0x1c1002a, v1C);
879 if (rc < 0)
880 goto exit_rc;
881 rc = WR16(s, 0x1c10015, v16);
882 if (rc < 0)
883 goto exit_rc;
884 rc = WR16(s, 0x1c10016, v12);
885 if (rc < 0)
886 goto exit_rc;
887 break;
888 case QAM_16:
889 edi |= 0x10;
890 if (s->chip_rev == DRXD_FW_B1)
891 break;
892
893 rc = WR16(s, 0x1c10046, 1);
894 if (rc < 0)
895 goto exit_rc;
896 rc = WR16(s, 0x2010011, 1);
897 if (rc < 0)
898 goto exit_rc;
899 rc = WR16(s, 0x201001a, 0x10);
900 if (rc < 0)
901 goto exit_rc;
902 rc = WR16(s, 0x201001b, 4);
903 if (rc < 0)
904 goto exit_rc;
905 rc = WR16(s, 0x201001c, 0);
906 if (rc < 0)
907 goto exit_rc;
908 rc = WR16(s, 0x1c10062, v1E);
909 if (rc < 0)
910 goto exit_rc;
911 rc = WR16(s, 0x1c1002a, v1A);
912 if (rc < 0)
913 goto exit_rc;
914 rc = WR16(s, 0x1c10015, v14);
915 if (rc < 0)
916 goto exit_rc;
917 rc = WR16(s, 0x1c10016, v10);
918 if (rc < 0)
919 goto exit_rc;
920 break;
921 case QAM_64:
922 edi |= 0x20;
923 rc = WR16(s, 0x1c10046, 2);
924 if (rc < 0)
925 goto exit_rc;
926 rc = WR16(s, 0x2010011, 2);
927 if (rc < 0)
928 goto exit_rc;
929 rc = WR16(s, 0x201001a, 0x20);
930 if (rc < 0)
931 goto exit_rc;
932 rc = WR16(s, 0x201001b, 8);
933 if (rc < 0)
934 goto exit_rc;
935 rc = WR16(s, 0x201001c, 2);
936 if (rc < 0)
937 goto exit_rc;
938 rc = WR16(s, 0x1c10062, ebx);
939 if (rc < 0)
940 goto exit_rc;
941 rc = WR16(s, 0x1c1002a, v18);
942 if (rc < 0)
943 goto exit_rc;
944 rc = WR16(s, 0x1c10015, ebp);
945 if (rc < 0)
946 goto exit_rc;
947 rc = WR16(s, 0x1c10016, v0E);
948 if (rc < 0)
949 goto exit_rc;
950 break;
951 }
952
953 if (s->config.s20d24 == 1) {
954 rc = WR16(s, 0x2010013, 0);
955 } else {
956 rc = WR16(s, 0x2010013, 1);
957 edi |= 0x1000;
958 }
959
960 switch (fep->u.ofdm.code_rate_HP) {
961 default:
962 v22 |= 0x10;
963 case FEC_1_2:
964 if (s->chip_rev == DRXD_FW_B1)
965 break;
966 rc = WR16(s, 0x2090011, 0);
967 break;
968 case FEC_2_3:
969 edi |= 0x200;
970 if (s->chip_rev == DRXD_FW_B1)
971 break;
972 rc = WR16(s, 0x2090011, 1);
973 break;
974 case FEC_3_4:
975 edi |= 0x400;
976 if (s->chip_rev == DRXD_FW_B1)
977 break;
978 rc = WR16(s, 0x2090011, 2);
979 break;
980 case FEC_5_6: /* 5 */
981 edi |= 0x600;
982 if (s->chip_rev == DRXD_FW_B1)
983 break;
984 rc = WR16(s, 0x2090011, 3);
985 break;
986 case FEC_7_8: /* 7 */
987 edi |= 0x800;
988 if (s->chip_rev == DRXD_FW_B1)
989 break;
990 rc = WR16(s, 0x2090011, 4);
991 break;
992 };
993 if (rc < 0)
994 goto exit_rc;
995
996 switch (fep->u.ofdm.bandwidth) {
997 default:
998 rc = -EINVAL;
999 goto exit_rc;
1000 case BANDWIDTH_8_MHZ: /* 0 */
1001 case BANDWIDTH_AUTO:
1002 rc = WR16(s, 0x0c2003f, 0x32);
1003 s->bandwidth_parm = ebx = 0x8b8249;
1004 edx = 0;
1005 break;
1006 case BANDWIDTH_7_MHZ:
1007 rc = WR16(s, 0x0c2003f, 0x3b);
1008 s->bandwidth_parm = ebx = 0x7a1200;
1009 edx = 0x4807;
1010 break;
1011 case BANDWIDTH_6_MHZ:
1012 rc = WR16(s, 0x0c2003f, 0x47);
1013 s->bandwidth_parm = ebx = 0x68a1b6;
1014 edx = 0x0f07;
1015 break;
1016 };
1017
1018 if (rc < 0)
1019 goto exit_rc;
1020
1021 rc = WR16(s, 0x08200ec, edx);
1022 if (rc < 0)
1023 goto exit_rc;
1024
1025 rc = RD16(s, 0x0820050);
1026 if (rc < 0)
1027 goto exit_rc;
1028 rc = WR16(s, 0x0820050, rc);
1029
1030 {
1031 /* Configure bandwidth specific factor */
1032 ebx = div64_u64(((u64) (s->f_osc) << 21) + (ebx >> 1),
1033 (u64)ebx) - 0x800000;
1034 EXIT_RC(WR16(s, 0x0c50010, ebx & 0xffff));
1035 EXIT_RC(WR16(s, 0x0c50011, ebx >> 16));
1036
1037 /* drx397xD oscillator calibration */
1038 ebx = div64_u64(((u64) (s->config.f_if + df_tuner) << 28) +
1039 (s->f_osc >> 1), (u64)s->f_osc);
1040 }
1041 ebx &= 0xfffffff;
1042 if (fep->inversion == INVERSION_ON)
1043 ebx = 0x10000000 - ebx;
1044
1045 EXIT_RC(WR16(s, 0x0c30010, ebx & 0xffff));
1046 EXIT_RC(WR16(s, 0x0c30011, ebx >> 16));
1047
1048 EXIT_RC(WR16(s, 0x0800000, 1));
1049 EXIT_RC(RD16(s, 0x0800000));
1050
1051
1052 EXIT_RC(SC_WaitForReady(s));
1053 EXIT_RC(WR16(s, 0x0820042, 0));
1054 EXIT_RC(WR16(s, 0x0820041, v22));
1055 EXIT_RC(WR16(s, 0x0820040, edi));
1056 EXIT_RC(SC_SendCommand(s, 3));
1057
1058 rc = RD16(s, 0x0800000);
1059
1060 SC_WaitForReady(s);
1061 WR16(s, 0x0820042, 0);
1062 WR16(s, 0x0820041, 1);
1063 WR16(s, 0x0820040, 1);
1064 SC_SendCommand(s, 1);
1065
1066
1067 rc = WR16(s, 0x2150000, 2);
1068 rc = WR16(s, 0x2150016, a);
1069 rc = WR16(s, 0x2150010, 4);
1070 rc = WR16(s, 0x2150036, 0);
1071 rc = WR16(s, 0x2150000, 1);
1072 s->config.d60 = 2;
1073
1074exit_rc:
1075 return rc;
1076}
1077
1078/*******************************************************************************
1079 * DVB interface
1080 ******************************************************************************/
1081
1082static int drx397x_init(struct dvb_frontend *fe)
1083{
1084 struct drx397xD_state *s = fe->demodulator_priv;
1085 int rc;
1086
1087 pr_debug("%s\n", __func__);
1088
1089 s->config.rfagc.d00 = 2; /* 0x7c */
1090 s->config.rfagc.w04 = 0;
1091 s->config.rfagc.w06 = 0x3ff;
1092
1093 s->config.ifagc.d00 = 0; /* 0x68 */
1094 s->config.ifagc.w04 = 0;
1095 s->config.ifagc.w06 = 140;
1096 s->config.ifagc.w08 = 0;
1097 s->config.ifagc.w0A = 0x3ff;
1098 s->config.ifagc.w0C = 0x388;
1099
1100 /* for signal strenght calculations */
1101 s->config.ss76 = 820;
1102 s->config.ss78 = 2200;
1103 s->config.ss7A = 150;
1104
1105 /* HI_CfgCommand */
1106 s->config.w50 = 4;
1107 s->config.w52 = 9;
1108
1109 s->config.f_if = 42800000; /* d14: intermediate frequency [Hz] */
1110 s->config.f_osc = 48000; /* s66 : oscillator frequency [kHz] */
1111 s->config.w92 = 12000;
1112
1113 s->config.w9C = 0x000e;
1114 s->config.w9E = 0x0000;
1115
1116 /* ConfigureMPEGOutput params */
1117 s->config.wA0 = 4;
1118 s->config.w98 = 1;
1119 s->config.w9A = 1;
1120
1121 /* get chip revision */
1122 rc = RD16(s, 0x2410019);
1123 if (rc < 0)
1124 return -ENODEV;
1125
1126 if (rc == 0) {
1127 printk(KERN_INFO "%s: chip revision A2\n", mod_name);
1128 rc = drx_load_fw(s, DRXD_FW_A2);
1129 } else {
1130
1131 rc = (rc >> 12) - 3;
1132 switch (rc) {
1133 case 1:
1134 s->flags |= F_SET_0D4h;
1135 case 0:
1136 case 4:
1137 s->flags |= F_SET_0D0h;
1138 break;
1139 case 2:
1140 case 5:
1141 break;
1142 case 3:
1143 s->flags |= F_SET_0D4h;
1144 break;
1145 default:
1146 return -ENODEV;
1147 };
1148 printk(KERN_INFO "%s: chip revision B1.%d\n", mod_name, rc);
1149 rc = drx_load_fw(s, DRXD_FW_B1);
1150 }
1151 if (rc < 0)
1152 goto error;
1153
1154 rc = WR16(s, 0x0420033, 0x3973);
1155 if (rc < 0)
1156 goto error;
1157
1158 rc = HI_Command(s, 2);
1159
1160 msleep(1);
1161
1162 if (s->chip_rev == DRXD_FW_A2) {
1163 rc = WR16(s, 0x043012d, 0x47F);
1164 if (rc < 0)
1165 goto error;
1166 }
1167 rc = WR16_E0(s, 0x0400000, 0);
1168 if (rc < 0)
1169 goto error;
1170
1171 if (s->config.w92 > 20000 || s->config.w92 % 4000) {
1172 printk(KERN_ERR "%s: invalid osc frequency\n", mod_name);
1173 rc = -1;
1174 goto error;
1175 }
1176
1177 rc = WR16(s, 0x2410010, 1);
1178 if (rc < 0)
1179 goto error;
1180 rc = WR16(s, 0x2410011, 0x15);
1181 if (rc < 0)
1182 goto error;
1183 rc = WR16(s, 0x2410012, s->config.w92 / 4000);
1184 if (rc < 0)
1185 goto error;
1186#ifdef ORIG_FW
1187 rc = WR16(s, 0x2410015, 2);
1188 if (rc < 0)
1189 goto error;
1190#endif
1191 rc = WR16(s, 0x2410017, 0x3973);
1192 if (rc < 0)
1193 goto error;
1194
1195 s->f_osc = s->config.f_osc * 1000; /* initial estimator */
1196
1197 s->config.w56 = 1;
1198
1199 rc = HI_CfgCommand(s);
1200 if (rc < 0)
1201 goto error;
1202
1203 rc = write_fw(s, DRXD_InitAtomicRead);
1204 if (rc < 0)
1205 goto error;
1206
1207 if (s->chip_rev == DRXD_FW_A2) {
1208 rc = WR16(s, 0x2150013, 0);
1209 if (rc < 0)
1210 goto error;
1211 }
1212
1213 rc = WR16_E0(s, 0x0400002, 0);
1214 if (rc < 0)
1215 goto error;
1216 rc = WR16(s, 0x0400002, 0);
1217 if (rc < 0)
1218 goto error;
1219
1220 if (s->chip_rev == DRXD_FW_A2) {
1221 rc = write_fw(s, DRXD_ResetCEFR);
1222 if (rc < 0)
1223 goto error;
1224 }
1225 rc = write_fw(s, DRXD_microcode);
1226 if (rc < 0)
1227 goto error;
1228
1229 s->config.w9C = 0x0e;
1230 if (s->flags & F_SET_0D0h) {
1231 s->config.w9C = 0;
1232 rc = RD16(s, 0x0c20010);
1233 if (rc < 0)
1234 goto write_DRXD_InitFE_1;
1235
1236 rc &= ~0x1000;
1237 rc = WR16(s, 0x0c20010, rc);
1238 if (rc < 0)
1239 goto write_DRXD_InitFE_1;
1240
1241 rc = RD16(s, 0x0c20011);
1242 if (rc < 0)
1243 goto write_DRXD_InitFE_1;
1244
1245 rc &= ~0x8;
1246 rc = WR16(s, 0x0c20011, rc);
1247 if (rc < 0)
1248 goto write_DRXD_InitFE_1;
1249
1250 rc = WR16(s, 0x0c20012, 1);
1251 }
1252
1253write_DRXD_InitFE_1:
1254
1255 rc = write_fw(s, DRXD_InitFE_1);
1256 if (rc < 0)
1257 goto error;
1258
1259 rc = 1;
1260 if (s->chip_rev == DRXD_FW_B1) {
1261 if (s->flags & F_SET_0D0h)
1262 rc = 0;
1263 } else {
1264 if (s->flags & F_SET_0D0h)
1265 rc = 4;
1266 }
1267
1268 rc = WR16(s, 0x0C20012, rc);
1269 if (rc < 0)
1270 goto error;
1271
1272 rc = WR16(s, 0x0C20013, s->config.w9E);
1273 if (rc < 0)
1274 goto error;
1275 rc = WR16(s, 0x0C20015, s->config.w9C);
1276 if (rc < 0)
1277 goto error;
1278
1279 rc = write_fw(s, DRXD_InitFE_2);
1280 if (rc < 0)
1281 goto error;
1282 rc = write_fw(s, DRXD_InitFT);
1283 if (rc < 0)
1284 goto error;
1285 rc = write_fw(s, DRXD_InitCP);
1286 if (rc < 0)
1287 goto error;
1288 rc = write_fw(s, DRXD_InitCE);
1289 if (rc < 0)
1290 goto error;
1291 rc = write_fw(s, DRXD_InitEQ);
1292 if (rc < 0)
1293 goto error;
1294 rc = write_fw(s, DRXD_InitEC);
1295 if (rc < 0)
1296 goto error;
1297 rc = write_fw(s, DRXD_InitSC);
1298 if (rc < 0)
1299 goto error;
1300
1301 rc = SetCfgIfAgc(s, &s->config.ifagc);
1302 if (rc < 0)
1303 goto error;
1304
1305 rc = SetCfgRfAgc(s, &s->config.rfagc);
1306 if (rc < 0)
1307 goto error;
1308
1309 rc = ConfigureMPEGOutput(s, 1);
1310 rc = WR16(s, 0x08201fe, 0x0017);
1311 rc = WR16(s, 0x08201ff, 0x0101);
1312
1313 s->config.d5C = 0;
1314 s->config.d60 = 1;
1315 s->config.d48 = 1;
1316
1317error:
1318 return rc;
1319}
1320
1321static int drx397x_get_frontend(struct dvb_frontend *fe,
1322 struct dvb_frontend_parameters *params)
1323{
1324 return 0;
1325}
1326
1327static int drx397x_set_frontend(struct dvb_frontend *fe,
1328 struct dvb_frontend_parameters *params)
1329{
1330 struct drx397xD_state *s = fe->demodulator_priv;
1331
1332 s->config.s20d24 = 1;
1333
1334 return drx_tune(s, params);
1335}
1336
1337static int drx397x_get_tune_settings(struct dvb_frontend *fe,
1338 struct dvb_frontend_tune_settings
1339 *fe_tune_settings)
1340{
1341 fe_tune_settings->min_delay_ms = 10000;
1342 fe_tune_settings->step_size = 0;
1343 fe_tune_settings->max_drift = 0;
1344
1345 return 0;
1346}
1347
1348static int drx397x_read_status(struct dvb_frontend *fe, fe_status_t *status)
1349{
1350 struct drx397xD_state *s = fe->demodulator_priv;
1351 int lockstat;
1352
1353 GetLockStatus(s, &lockstat);
1354
1355 *status = 0;
1356 if (lockstat & 2) {
1357 CorrectSysClockDeviation(s);
1358 ConfigureMPEGOutput(s, 1);
1359 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI;
1360 }
1361 if (lockstat & 4)
1362 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
1363
1364 return 0;
1365}
1366
1367static int drx397x_read_ber(struct dvb_frontend *fe, unsigned int *ber)
1368{
1369 *ber = 0;
1370
1371 return 0;
1372}
1373
1374static int drx397x_read_snr(struct dvb_frontend *fe, u16 *snr)
1375{
1376 *snr = 0;
1377
1378 return 0;
1379}
1380
1381static int drx397x_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
1382{
1383 struct drx397xD_state *s = fe->demodulator_priv;
1384 int rc;
1385
1386 if (s->config.ifagc.d00 == 2) {
1387 *strength = 0xffff;
1388 return 0;
1389 }
1390 rc = RD16(s, 0x0c20035);
1391 if (rc < 0) {
1392 *strength = 0;
1393 return 0;
1394 }
1395 rc &= 0x3ff;
1396 /* Signal strength is calculated using the following formula:
1397 *
1398 * a = 2200 * 150 / (2200 + 150);
1399 * a = a * 3300 / (a + 820);
1400 * b = 2200 * 3300 / (2200 + 820);
1401 * c = (((b-a) * rc) >> 10 + a) << 4;
1402 * strength = ~c & 0xffff;
1403 *
1404 * The following does the same but with less rounding errors:
1405 */
1406 *strength = ~(7720 + (rc * 30744 >> 10));
1407
1408 return 0;
1409}
1410
1411static int drx397x_read_ucblocks(struct dvb_frontend *fe,
1412 unsigned int *ucblocks)
1413{
1414 *ucblocks = 0;
1415
1416 return 0;
1417}
1418
1419static int drx397x_sleep(struct dvb_frontend *fe)
1420{
1421 return 0;
1422}
1423
1424static void drx397x_release(struct dvb_frontend *fe)
1425{
1426 struct drx397xD_state *s = fe->demodulator_priv;
1427 printk(KERN_INFO "%s: release demodulator\n", mod_name);
1428 if (s) {
1429 drx_release_fw(s);
1430 kfree(s);
1431 }
1432
1433}
1434
1435static struct dvb_frontend_ops drx397x_ops = {
1436
1437 .info = {
1438 .name = "Micronas DRX397xD DVB-T Frontend",
1439 .type = FE_OFDM,
1440 .frequency_min = 47125000,
1441 .frequency_max = 855250000,
1442 .frequency_stepsize = 166667,
1443 .frequency_tolerance = 0,
1444 .caps = /* 0x0C01B2EAE */
1445 FE_CAN_FEC_1_2 | /* = 0x2, */
1446 FE_CAN_FEC_2_3 | /* = 0x4, */
1447 FE_CAN_FEC_3_4 | /* = 0x8, */
1448 FE_CAN_FEC_5_6 | /* = 0x20, */
1449 FE_CAN_FEC_7_8 | /* = 0x80, */
1450 FE_CAN_FEC_AUTO | /* = 0x200, */
1451 FE_CAN_QPSK | /* = 0x400, */
1452 FE_CAN_QAM_16 | /* = 0x800, */
1453 FE_CAN_QAM_64 | /* = 0x2000, */
1454 FE_CAN_QAM_AUTO | /* = 0x10000, */
1455 FE_CAN_TRANSMISSION_MODE_AUTO | /* = 0x20000, */
1456 FE_CAN_GUARD_INTERVAL_AUTO | /* = 0x80000, */
1457 FE_CAN_HIERARCHY_AUTO | /* = 0x100000, */
1458 FE_CAN_RECOVER | /* = 0x40000000, */
1459 FE_CAN_MUTE_TS /* = 0x80000000 */
1460 },
1461
1462 .release = drx397x_release,
1463 .init = drx397x_init,
1464 .sleep = drx397x_sleep,
1465
1466 .set_frontend = drx397x_set_frontend,
1467 .get_tune_settings = drx397x_get_tune_settings,
1468 .get_frontend = drx397x_get_frontend,
1469
1470 .read_status = drx397x_read_status,
1471 .read_snr = drx397x_read_snr,
1472 .read_signal_strength = drx397x_read_signal_strength,
1473 .read_ber = drx397x_read_ber,
1474 .read_ucblocks = drx397x_read_ucblocks,
1475};
1476
1477struct dvb_frontend *drx397xD_attach(const struct drx397xD_config *config,
1478 struct i2c_adapter *i2c)
1479{
1480 struct drx397xD_state *state;
1481
1482 /* allocate memory for the internal state */
1483 state = kzalloc(sizeof(struct drx397xD_state), GFP_KERNEL);
1484 if (!state)
1485 goto error;
1486
1487 /* setup the state */
1488 state->i2c = i2c;
1489 memcpy(&state->config, config, sizeof(struct drx397xD_config));
1490
1491 /* check if the demod is there */
1492 if (RD16(state, 0x2410019) < 0)
1493 goto error;
1494
1495 /* create dvb_frontend */
1496 memcpy(&state->frontend.ops, &drx397x_ops,
1497 sizeof(struct dvb_frontend_ops));
1498 state->frontend.demodulator_priv = state;
1499
1500 return &state->frontend;
1501error:
1502 kfree(state);
1503
1504 return NULL;
1505}
1506EXPORT_SYMBOL(drx397xD_attach);
1507
1508MODULE_DESCRIPTION("Micronas DRX397xD DVB-T Frontend");
1509MODULE_AUTHOR("Henk Vergonet");
1510MODULE_LICENSE("GPL");
1511
diff --git a/drivers/media/dvb/frontends/drx397xD.h b/drivers/media/dvb/frontends/drx397xD.h
deleted file mode 100644
index ba05d17290c6..000000000000
--- a/drivers/media/dvb/frontends/drx397xD.h
+++ /dev/null
@@ -1,130 +0,0 @@
1/*
2 * Driver for Micronas DVB-T drx397xD demodulator
3 *
4 * Copyright (C) 2007 Henk vergonet <Henk.Vergonet@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20 */
21
22#ifndef _DRX397XD_H_INCLUDED
23#define _DRX397XD_H_INCLUDED
24
25#include <linux/dvb/frontend.h>
26
27#define DRX_F_STEPSIZE 166667
28#define DRX_F_OFFSET 36000000
29
30#define I2C_ADR_C0(x) \
31( cpu_to_le32( \
32 (u32)( \
33 (((u32)(x) & (u32)0x000000ffUL) ) | \
34 (((u32)(x) & (u32)0x0000ff00UL) << 16) | \
35 (((u32)(x) & (u32)0x0fff0000UL) >> 8) | \
36 ( (u32)0x00c00000UL) \
37 )) \
38)
39
40#define I2C_ADR_E0(x) \
41( cpu_to_le32( \
42 (u32)( \
43 (((u32)(x) & (u32)0x000000ffUL) ) | \
44 (((u32)(x) & (u32)0x0000ff00UL) << 16) | \
45 (((u32)(x) & (u32)0x0fff0000UL) >> 8) | \
46 ( (u32)0x00e00000UL) \
47 )) \
48)
49
50struct drx397xD_CfgRfAgc /* 0x7c */
51{
52 int d00; /* 2 */
53 u16 w04;
54 u16 w06;
55};
56
57struct drx397xD_CfgIfAgc /* 0x68 */
58{
59 int d00; /* 0 */
60 u16 w04; /* 0 */
61 u16 w06;
62 u16 w08;
63 u16 w0A;
64 u16 w0C;
65};
66
67struct drx397xD_s20 {
68 int d04;
69 u32 d18;
70 u32 d1C;
71 u32 d20;
72 u32 d14;
73 u32 d24;
74 u32 d0C;
75 u32 d08;
76};
77
78struct drx397xD_config
79{
80 /* demodulator's I2C address */
81 u8 demod_address; /* 0x0f */
82
83 struct drx397xD_CfgIfAgc ifagc; /* 0x68 */
84 struct drx397xD_CfgRfAgc rfagc; /* 0x7c */
85 u32 s20d24;
86
87 /* HI_CfgCommand parameters */
88 u16 w50, w52, /* w54, */ w56;
89
90 int d5C;
91 int d60;
92 int d48;
93 int d28;
94
95 u32 f_if; /* d14: intermediate frequency [Hz] */
96 /* 36000000 on Cinergy 2400i DT */
97 /* 42800000 on Pinnacle Hybrid PRO 330e */
98
99 u16 f_osc; /* s66: 48000 oscillator frequency [kHz] */
100
101 u16 w92; /* 20000 */
102
103 u16 wA0;
104 u16 w98;
105 u16 w9A;
106
107 u16 w9C; /* 0xe0 */
108 u16 w9E; /* 0x00 */
109
110 /* used for signal strength calculations in
111 drx397x_read_signal_strength
112 */
113 u16 ss78; // 2200
114 u16 ss7A; // 150
115 u16 ss76; // 820
116};
117
118#if defined(CONFIG_DVB_DRX397XD) || (defined(CONFIG_DVB_DRX397XD_MODULE) && defined(MODULE))
119extern struct dvb_frontend* drx397xD_attach(const struct drx397xD_config *config,
120 struct i2c_adapter *i2c);
121#else
122static inline struct dvb_frontend* drx397xD_attach(const struct drx397xD_config *config,
123 struct i2c_adapter *i2c)
124{
125 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
126 return NULL;
127}
128#endif /* CONFIG_DVB_DRX397XD */
129
130#endif /* _DRX397XD_H_INCLUDED */
diff --git a/drivers/media/dvb/frontends/drx397xD_fw.h b/drivers/media/dvb/frontends/drx397xD_fw.h
deleted file mode 100644
index c8b44c1e807f..000000000000
--- a/drivers/media/dvb/frontends/drx397xD_fw.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 * Firmware definitions for Micronas drx397xD
3 *
4 * Copyright (C) 2007 Henk Vergonet <Henk.Vergonet@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifdef _FW_ENTRY
21 _FW_ENTRY("drx397xD.A2.fw", DRXD_FW_A2 = 0, DRXD_FW_A2 ),
22 _FW_ENTRY("drx397xD.B1.fw", DRXD_FW_B1, DRXD_FW_B1 ),
23#undef _FW_ENTRY
24#endif /* _FW_ENTRY */
25
26#ifdef _BLOB_ENTRY
27 _BLOB_ENTRY("InitAtomicRead", DRXD_InitAtomicRead = 0 ),
28 _BLOB_ENTRY("InitCE", DRXD_InitCE ),
29 _BLOB_ENTRY("InitCP", DRXD_InitCP ),
30 _BLOB_ENTRY("InitEC", DRXD_InitEC ),
31 _BLOB_ENTRY("InitEQ", DRXD_InitEQ ),
32 _BLOB_ENTRY("InitFE_1", DRXD_InitFE_1 ),
33 _BLOB_ENTRY("InitFE_2", DRXD_InitFE_2 ),
34 _BLOB_ENTRY("InitFT", DRXD_InitFT ),
35 _BLOB_ENTRY("InitSC", DRXD_InitSC ),
36 _BLOB_ENTRY("ResetCEFR", DRXD_ResetCEFR ),
37 _BLOB_ENTRY("ResetECRAM", DRXD_ResetECRAM ),
38 _BLOB_ENTRY("microcode", DRXD_microcode ),
39#undef _BLOB_ENTRY
40#endif /* _BLOB_ENTRY */
diff --git a/drivers/media/dvb/frontends/drxd.h b/drivers/media/dvb/frontends/drxd.h
new file mode 100644
index 000000000000..7113535844f2
--- /dev/null
+++ b/drivers/media/dvb/frontends/drxd.h
@@ -0,0 +1,61 @@
1/*
2 * drxd.h: DRXD DVB-T demodulator driver
3 *
4 * Copyright (C) 2005-2007 Micronas
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 only, as published by the Free Software Foundation.
9 *
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA
21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
22 */
23
24#ifndef _DRXD_H_
25#define _DRXD_H_
26
27#include <linux/types.h>
28#include <linux/i2c.h>
29
30struct drxd_config {
31 u8 index;
32
33 u8 pll_address;
34 u8 pll_type;
35#define DRXD_PLL_NONE 0
36#define DRXD_PLL_DTT7520X 1
37#define DRXD_PLL_MT3X0823 2
38
39 u32 clock;
40 u8 insert_rs_byte;
41
42 u8 demod_address;
43 u8 demoda_address;
44 u8 demod_revision;
45
46 /* If the tuner is not behind an i2c gate, be sure to flip this bit
47 or else the i2c bus could get wedged */
48 u8 disable_i2c_gate_ctrl;
49
50 u32 IF;
51 int (*pll_set) (void *priv, void *priv_params,
52 u8 pll_addr, u8 demoda_addr, s32 *off);
53 s16(*osc_deviation) (void *priv, s16 dev, int flag);
54};
55
56extern
57struct dvb_frontend *drxd_attach(const struct drxd_config *config,
58 void *priv, struct i2c_adapter *i2c,
59 struct device *dev);
60extern int drxd_config_i2c(struct dvb_frontend *, int);
61#endif
diff --git a/drivers/media/dvb/frontends/drxd_firm.c b/drivers/media/dvb/frontends/drxd_firm.c
new file mode 100644
index 000000000000..5418b0b1dadc
--- /dev/null
+++ b/drivers/media/dvb/frontends/drxd_firm.c
@@ -0,0 +1,929 @@
1/*
2 * drxd_firm.c : DRXD firmware tables
3 *
4 * Copyright (C) 2006-2007 Micronas
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 only, as published by the Free Software Foundation.
9 *
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA
21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
22 */
23
24/* TODO: generate this file with a script from a settings file */
25
26/* Contains A2 firmware version: 1.4.2
27 * Contains B1 firmware version: 3.3.33
28 * Contains settings from driver 1.4.23
29*/
30
31#include "drxd_firm.h"
32
33#define ADDRESS(x) ((x) & 0xFF), (((x)>>8) & 0xFF), (((x)>>16) & 0xFF), (((x)>>24) & 0xFF)
34#define LENGTH(x) ((x) & 0xFF), (((x)>>8) & 0xFF)
35
36/* Is written via block write, must be little endian */
37#define DATA16(x) ((x) & 0xFF), (((x)>>8) & 0xFF)
38
39#define WRBLOCK(a, l) ADDRESS(a), LENGTH(l)
40#define WR16(a, d) ADDRESS(a), LENGTH(1), DATA16(d)
41
42#define END_OF_TABLE 0xFF, 0xFF, 0xFF, 0xFF
43
44/* HI firmware patches */
45
46#define HI_TR_FUNC_ADDR HI_IF_RAM_USR_BEGIN__A
47#define HI_TR_FUNC_SIZE 9 /* size of this function in instruction words */
48
49u8 DRXD_InitAtomicRead[] = {
50 WRBLOCK(HI_TR_FUNC_ADDR, HI_TR_FUNC_SIZE),
51 0x26, 0x00, /* 0 -> ring.rdy; */
52 0x60, 0x04, /* r0rami.dt -> ring.xba; */
53 0x61, 0x04, /* r0rami.dt -> ring.xad; */
54 0xE3, 0x07, /* HI_RA_RAM_USR_BEGIN -> ring.iad; */
55 0x40, 0x00, /* (long immediate) */
56 0x64, 0x04, /* r0rami.dt -> ring.len; */
57 0x65, 0x04, /* r0rami.dt -> ring.ctl; */
58 0x26, 0x00, /* 0 -> ring.rdy; */
59 0x38, 0x00, /* 0 -> jumps.ad; */
60 END_OF_TABLE
61};
62
63/* Pins D0 and D1 of the parallel MPEG output can be used
64 to set the I2C address of a device. */
65
66#define HI_RST_FUNC_ADDR (HI_IF_RAM_USR_BEGIN__A + HI_TR_FUNC_SIZE)
67#define HI_RST_FUNC_SIZE 54 /* size of this function in instruction words */
68
69/* D0 Version */
70u8 DRXD_HiI2cPatch_1[] = {
71 WRBLOCK(HI_RST_FUNC_ADDR, HI_RST_FUNC_SIZE),
72 0xC8, 0x07, 0x01, 0x00, /* MASK -> reg0.dt; */
73 0xE0, 0x07, 0x15, 0x02, /* (EC__BLK << 6) + EC_OC_REG__BNK -> ring.xba; */
74 0xE1, 0x07, 0x12, 0x00, /* EC_OC_REG_OC_MPG_SIO__A -> ring.xad; */
75 0xA2, 0x00, /* M_BNK_ID_DAT -> ring.iba; */
76 0x23, 0x00, /* &data -> ring.iad; */
77 0x24, 0x00, /* 0 -> ring.len; */
78 0xA5, 0x02, /* M_RC_CTR_SWAP | M_RC_CTR_READ -> ring.ctl; */
79 0x26, 0x00, /* 0 -> ring.rdy; */
80 0x42, 0x00, /* &data+1 -> w0ram.ad; */
81 0xC0, 0x07, 0xFF, 0x0F, /* -1 -> w0ram.dt; */
82 0x63, 0x00, /* &data+1 -> ring.iad; */
83 0x65, 0x02, /* M_RC_CTR_SWAP | M_RC_CTR_WRITE -> ring.ctl; */
84 0x26, 0x00, /* 0 -> ring.rdy; */
85 0xE1, 0x07, 0x38, 0x00, /* EC_OC_REG_OCR_MPG_USR_DAT__A -> ring.xad; */
86 0xA5, 0x02, /* M_RC_CTR_SWAP | M_RC_CTR_READ -> ring.ctl; */
87 0x26, 0x00, /* 0 -> ring.rdy; */
88 0xE1, 0x07, 0x12, 0x00, /* EC_OC_REG_OC_MPG_SIO__A -> ring.xad; */
89 0x23, 0x00, /* &data -> ring.iad; */
90 0x65, 0x02, /* M_RC_CTR_SWAP | M_RC_CTR_WRITE -> ring.ctl; */
91 0x26, 0x00, /* 0 -> ring.rdy; */
92 0x42, 0x00, /* &data+1 -> w0ram.ad; */
93 0x0F, 0x04, /* r0ram.dt -> and.op; */
94 0x1C, 0x06, /* reg0.dt -> and.tr; */
95 0xCF, 0x04, /* and.rs -> add.op; */
96 0xD0, 0x07, 0x70, 0x00, /* DEF_DEV_ID -> add.tr; */
97 0xD0, 0x04, /* add.rs -> add.tr; */
98 0xC8, 0x04, /* add.rs -> reg0.dt; */
99 0x60, 0x00, /* reg0.dt -> w0ram.dt; */
100 0xC2, 0x07, 0x10, 0x00, /* SLV0_BASE -> w0rami.ad; */
101 0x01, 0x00, /* 0 -> w0rami.dt; */
102 0x01, 0x06, /* reg0.dt -> w0rami.dt; */
103 0xC2, 0x07, 0x20, 0x00, /* SLV1_BASE -> w0rami.ad; */
104 0x01, 0x00, /* 0 -> w0rami.dt; */
105 0x01, 0x06, /* reg0.dt -> w0rami.dt; */
106 0xC2, 0x07, 0x30, 0x00, /* CMD_BASE -> w0rami.ad; */
107 0x01, 0x00, /* 0 -> w0rami.dt; */
108 0x01, 0x00, /* 0 -> w0rami.dt; */
109 0x01, 0x00, /* 0 -> w0rami.dt; */
110 0x68, 0x00, /* M_IC_SEL_PT1 -> i2c.sel; */
111 0x29, 0x00, /* M_IC_CMD_RESET -> i2c.cmd; */
112 0x28, 0x00, /* M_IC_SEL_PT0 -> i2c.sel; */
113 0x29, 0x00, /* M_IC_CMD_RESET -> i2c.cmd; */
114 0xF8, 0x07, 0x2F, 0x00, /* 0x2F -> jumps.ad; */
115
116 WR16((B_HI_IF_RAM_TRP_BPT0__AX + ((2 * 0) + 1)),
117 (u16) (HI_RST_FUNC_ADDR & 0x3FF)),
118 WR16((B_HI_IF_RAM_TRP_BPT0__AX + ((2 * 1) + 1)),
119 (u16) (HI_RST_FUNC_ADDR & 0x3FF)),
120 WR16((B_HI_IF_RAM_TRP_BPT0__AX + ((2 * 2) + 1)),
121 (u16) (HI_RST_FUNC_ADDR & 0x3FF)),
122 WR16((B_HI_IF_RAM_TRP_BPT0__AX + ((2 * 3) + 1)),
123 (u16) (HI_RST_FUNC_ADDR & 0x3FF)),
124
125 /* Force quick and dirty reset */
126 WR16(B_HI_CT_REG_COMM_STATE__A, 0),
127 END_OF_TABLE
128};
129
130/* D0,D1 Version */
131u8 DRXD_HiI2cPatch_3[] = {
132 WRBLOCK(HI_RST_FUNC_ADDR, HI_RST_FUNC_SIZE),
133 0xC8, 0x07, 0x03, 0x00, /* MASK -> reg0.dt; */
134 0xE0, 0x07, 0x15, 0x02, /* (EC__BLK << 6) + EC_OC_REG__BNK -> ring.xba; */
135 0xE1, 0x07, 0x12, 0x00, /* EC_OC_REG_OC_MPG_SIO__A -> ring.xad; */
136 0xA2, 0x00, /* M_BNK_ID_DAT -> ring.iba; */
137 0x23, 0x00, /* &data -> ring.iad; */
138 0x24, 0x00, /* 0 -> ring.len; */
139 0xA5, 0x02, /* M_RC_CTR_SWAP | M_RC_CTR_READ -> ring.ctl; */
140 0x26, 0x00, /* 0 -> ring.rdy; */
141 0x42, 0x00, /* &data+1 -> w0ram.ad; */
142 0xC0, 0x07, 0xFF, 0x0F, /* -1 -> w0ram.dt; */
143 0x63, 0x00, /* &data+1 -> ring.iad; */
144 0x65, 0x02, /* M_RC_CTR_SWAP | M_RC_CTR_WRITE -> ring.ctl; */
145 0x26, 0x00, /* 0 -> ring.rdy; */
146 0xE1, 0x07, 0x38, 0x00, /* EC_OC_REG_OCR_MPG_USR_DAT__A -> ring.xad; */
147 0xA5, 0x02, /* M_RC_CTR_SWAP | M_RC_CTR_READ -> ring.ctl; */
148 0x26, 0x00, /* 0 -> ring.rdy; */
149 0xE1, 0x07, 0x12, 0x00, /* EC_OC_REG_OC_MPG_SIO__A -> ring.xad; */
150 0x23, 0x00, /* &data -> ring.iad; */
151 0x65, 0x02, /* M_RC_CTR_SWAP | M_RC_CTR_WRITE -> ring.ctl; */
152 0x26, 0x00, /* 0 -> ring.rdy; */
153 0x42, 0x00, /* &data+1 -> w0ram.ad; */
154 0x0F, 0x04, /* r0ram.dt -> and.op; */
155 0x1C, 0x06, /* reg0.dt -> and.tr; */
156 0xCF, 0x04, /* and.rs -> add.op; */
157 0xD0, 0x07, 0x70, 0x00, /* DEF_DEV_ID -> add.tr; */
158 0xD0, 0x04, /* add.rs -> add.tr; */
159 0xC8, 0x04, /* add.rs -> reg0.dt; */
160 0x60, 0x00, /* reg0.dt -> w0ram.dt; */
161 0xC2, 0x07, 0x10, 0x00, /* SLV0_BASE -> w0rami.ad; */
162 0x01, 0x00, /* 0 -> w0rami.dt; */
163 0x01, 0x06, /* reg0.dt -> w0rami.dt; */
164 0xC2, 0x07, 0x20, 0x00, /* SLV1_BASE -> w0rami.ad; */
165 0x01, 0x00, /* 0 -> w0rami.dt; */
166 0x01, 0x06, /* reg0.dt -> w0rami.dt; */
167 0xC2, 0x07, 0x30, 0x00, /* CMD_BASE -> w0rami.ad; */
168 0x01, 0x00, /* 0 -> w0rami.dt; */
169 0x01, 0x00, /* 0 -> w0rami.dt; */
170 0x01, 0x00, /* 0 -> w0rami.dt; */
171 0x68, 0x00, /* M_IC_SEL_PT1 -> i2c.sel; */
172 0x29, 0x00, /* M_IC_CMD_RESET -> i2c.cmd; */
173 0x28, 0x00, /* M_IC_SEL_PT0 -> i2c.sel; */
174 0x29, 0x00, /* M_IC_CMD_RESET -> i2c.cmd; */
175 0xF8, 0x07, 0x2F, 0x00, /* 0x2F -> jumps.ad; */
176
177 WR16((B_HI_IF_RAM_TRP_BPT0__AX + ((2 * 0) + 1)),
178 (u16) (HI_RST_FUNC_ADDR & 0x3FF)),
179 WR16((B_HI_IF_RAM_TRP_BPT0__AX + ((2 * 1) + 1)),
180 (u16) (HI_RST_FUNC_ADDR & 0x3FF)),
181 WR16((B_HI_IF_RAM_TRP_BPT0__AX + ((2 * 2) + 1)),
182 (u16) (HI_RST_FUNC_ADDR & 0x3FF)),
183 WR16((B_HI_IF_RAM_TRP_BPT0__AX + ((2 * 3) + 1)),
184 (u16) (HI_RST_FUNC_ADDR & 0x3FF)),
185
186 /* Force quick and dirty reset */
187 WR16(B_HI_CT_REG_COMM_STATE__A, 0),
188 END_OF_TABLE
189};
190
191u8 DRXD_ResetCEFR[] = {
192 WRBLOCK(CE_REG_FR_TREAL00__A, 57),
193 0x52, 0x00, /* CE_REG_FR_TREAL00__A */
194 0x00, 0x00, /* CE_REG_FR_TIMAG00__A */
195 0x52, 0x00, /* CE_REG_FR_TREAL01__A */
196 0x00, 0x00, /* CE_REG_FR_TIMAG01__A */
197 0x52, 0x00, /* CE_REG_FR_TREAL02__A */
198 0x00, 0x00, /* CE_REG_FR_TIMAG02__A */
199 0x52, 0x00, /* CE_REG_FR_TREAL03__A */
200 0x00, 0x00, /* CE_REG_FR_TIMAG03__A */
201 0x52, 0x00, /* CE_REG_FR_TREAL04__A */
202 0x00, 0x00, /* CE_REG_FR_TIMAG04__A */
203 0x52, 0x00, /* CE_REG_FR_TREAL05__A */
204 0x00, 0x00, /* CE_REG_FR_TIMAG05__A */
205 0x52, 0x00, /* CE_REG_FR_TREAL06__A */
206 0x00, 0x00, /* CE_REG_FR_TIMAG06__A */
207 0x52, 0x00, /* CE_REG_FR_TREAL07__A */
208 0x00, 0x00, /* CE_REG_FR_TIMAG07__A */
209 0x52, 0x00, /* CE_REG_FR_TREAL08__A */
210 0x00, 0x00, /* CE_REG_FR_TIMAG08__A */
211 0x52, 0x00, /* CE_REG_FR_TREAL09__A */
212 0x00, 0x00, /* CE_REG_FR_TIMAG09__A */
213 0x52, 0x00, /* CE_REG_FR_TREAL10__A */
214 0x00, 0x00, /* CE_REG_FR_TIMAG10__A */
215 0x52, 0x00, /* CE_REG_FR_TREAL11__A */
216 0x00, 0x00, /* CE_REG_FR_TIMAG11__A */
217
218 0x52, 0x00, /* CE_REG_FR_MID_TAP__A */
219
220 0x0B, 0x00, /* CE_REG_FR_SQS_G00__A */
221 0x0B, 0x00, /* CE_REG_FR_SQS_G01__A */
222 0x0B, 0x00, /* CE_REG_FR_SQS_G02__A */
223 0x0B, 0x00, /* CE_REG_FR_SQS_G03__A */
224 0x0B, 0x00, /* CE_REG_FR_SQS_G04__A */
225 0x0B, 0x00, /* CE_REG_FR_SQS_G05__A */
226 0x0B, 0x00, /* CE_REG_FR_SQS_G06__A */
227 0x0B, 0x00, /* CE_REG_FR_SQS_G07__A */
228 0x0B, 0x00, /* CE_REG_FR_SQS_G08__A */
229 0x0B, 0x00, /* CE_REG_FR_SQS_G09__A */
230 0x0B, 0x00, /* CE_REG_FR_SQS_G10__A */
231 0x0B, 0x00, /* CE_REG_FR_SQS_G11__A */
232 0x0B, 0x00, /* CE_REG_FR_SQS_G12__A */
233
234 0xFF, 0x01, /* CE_REG_FR_RIO_G00__A */
235 0x90, 0x01, /* CE_REG_FR_RIO_G01__A */
236 0x0B, 0x01, /* CE_REG_FR_RIO_G02__A */
237 0xC8, 0x00, /* CE_REG_FR_RIO_G03__A */
238 0xA0, 0x00, /* CE_REG_FR_RIO_G04__A */
239 0x85, 0x00, /* CE_REG_FR_RIO_G05__A */
240 0x72, 0x00, /* CE_REG_FR_RIO_G06__A */
241 0x64, 0x00, /* CE_REG_FR_RIO_G07__A */
242 0x59, 0x00, /* CE_REG_FR_RIO_G08__A */
243 0x50, 0x00, /* CE_REG_FR_RIO_G09__A */
244 0x49, 0x00, /* CE_REG_FR_RIO_G10__A */
245
246 0x10, 0x00, /* CE_REG_FR_MODE__A */
247 0x78, 0x00, /* CE_REG_FR_SQS_TRH__A */
248 0x00, 0x00, /* CE_REG_FR_RIO_GAIN__A */
249 0x00, 0x02, /* CE_REG_FR_BYPASS__A */
250 0x0D, 0x00, /* CE_REG_FR_PM_SET__A */
251 0x07, 0x00, /* CE_REG_FR_ERR_SH__A */
252 0x04, 0x00, /* CE_REG_FR_MAN_SH__A */
253 0x06, 0x00, /* CE_REG_FR_TAP_SH__A */
254
255 END_OF_TABLE
256};
257
258u8 DRXD_InitFEA2_1[] = {
259 WRBLOCK(FE_AD_REG_PD__A, 3),
260 0x00, 0x00, /* FE_AD_REG_PD__A */
261 0x01, 0x00, /* FE_AD_REG_INVEXT__A */
262 0x00, 0x00, /* FE_AD_REG_CLKNEG__A */
263
264 WRBLOCK(FE_AG_REG_DCE_AUR_CNT__A, 2),
265 0x10, 0x00, /* FE_AG_REG_DCE_AUR_CNT__A */
266 0x10, 0x00, /* FE_AG_REG_DCE_RUR_CNT__A */
267
268 WRBLOCK(FE_AG_REG_ACE_AUR_CNT__A, 2),
269 0x0E, 0x00, /* FE_AG_REG_ACE_AUR_CNT__A */
270 0x00, 0x00, /* FE_AG_REG_ACE_RUR_CNT__A */
271
272 WRBLOCK(FE_AG_REG_EGC_FLA_RGN__A, 5),
273 0x04, 0x00, /* FE_AG_REG_EGC_FLA_RGN__A */
274 0x1F, 0x00, /* FE_AG_REG_EGC_SLO_RGN__A */
275 0x00, 0x00, /* FE_AG_REG_EGC_JMP_PSN__A */
276 0x00, 0x00, /* FE_AG_REG_EGC_FLA_INC__A */
277 0x00, 0x00, /* FE_AG_REG_EGC_FLA_DEC__A */
278
279 WRBLOCK(FE_AG_REG_GC1_AGC_MAX__A, 2),
280 0xFF, 0x01, /* FE_AG_REG_GC1_AGC_MAX__A */
281 0x00, 0xFE, /* FE_AG_REG_GC1_AGC_MIN__A */
282
283 WRBLOCK(FE_AG_REG_IND_WIN__A, 29),
284 0x00, 0x00, /* FE_AG_REG_IND_WIN__A */
285 0x05, 0x00, /* FE_AG_REG_IND_THD_LOL__A */
286 0x0F, 0x00, /* FE_AG_REG_IND_THD_HIL__A */
287 0x00, 0x00, /* FE_AG_REG_IND_DEL__A don't care */
288 0x1E, 0x00, /* FE_AG_REG_IND_PD1_WRI__A */
289 0x0C, 0x00, /* FE_AG_REG_PDA_AUR_CNT__A */
290 0x00, 0x00, /* FE_AG_REG_PDA_RUR_CNT__A */
291 0x00, 0x00, /* FE_AG_REG_PDA_AVE_DAT__A don't care */
292 0x00, 0x00, /* FE_AG_REG_PDC_RUR_CNT__A */
293 0x01, 0x00, /* FE_AG_REG_PDC_SET_LVL__A */
294 0x02, 0x00, /* FE_AG_REG_PDC_FLA_RGN__A */
295 0x00, 0x00, /* FE_AG_REG_PDC_JMP_PSN__A don't care */
296 0xFF, 0xFF, /* FE_AG_REG_PDC_FLA_STP__A */
297 0xFF, 0xFF, /* FE_AG_REG_PDC_SLO_STP__A */
298 0x00, 0x1F, /* FE_AG_REG_PDC_PD2_WRI__A don't care */
299 0x00, 0x00, /* FE_AG_REG_PDC_MAP_DAT__A don't care */
300 0x02, 0x00, /* FE_AG_REG_PDC_MAX__A */
301 0x0C, 0x00, /* FE_AG_REG_TGA_AUR_CNT__A */
302 0x00, 0x00, /* FE_AG_REG_TGA_RUR_CNT__A */
303 0x00, 0x00, /* FE_AG_REG_TGA_AVE_DAT__A don't care */
304 0x00, 0x00, /* FE_AG_REG_TGC_RUR_CNT__A */
305 0x22, 0x00, /* FE_AG_REG_TGC_SET_LVL__A */
306 0x15, 0x00, /* FE_AG_REG_TGC_FLA_RGN__A */
307 0x00, 0x00, /* FE_AG_REG_TGC_JMP_PSN__A don't care */
308 0x01, 0x00, /* FE_AG_REG_TGC_FLA_STP__A */
309 0x0A, 0x00, /* FE_AG_REG_TGC_SLO_STP__A */
310 0x00, 0x00, /* FE_AG_REG_TGC_MAP_DAT__A don't care */
311 0x10, 0x00, /* FE_AG_REG_FGA_AUR_CNT__A */
312 0x10, 0x00, /* FE_AG_REG_FGA_RUR_CNT__A */
313
314 WRBLOCK(FE_AG_REG_BGC_FGC_WRI__A, 2),
315 0x00, 0x00, /* FE_AG_REG_BGC_FGC_WRI__A */
316 0x00, 0x00, /* FE_AG_REG_BGC_CGC_WRI__A */
317
318 WRBLOCK(FE_FD_REG_SCL__A, 3),
319 0x05, 0x00, /* FE_FD_REG_SCL__A */
320 0x03, 0x00, /* FE_FD_REG_MAX_LEV__A */
321 0x05, 0x00, /* FE_FD_REG_NR__A */
322
323 WRBLOCK(FE_CF_REG_SCL__A, 5),
324 0x16, 0x00, /* FE_CF_REG_SCL__A */
325 0x04, 0x00, /* FE_CF_REG_MAX_LEV__A */
326 0x06, 0x00, /* FE_CF_REG_NR__A */
327 0x00, 0x00, /* FE_CF_REG_IMP_VAL__A */
328 0x01, 0x00, /* FE_CF_REG_MEAS_VAL__A */
329
330 WRBLOCK(FE_CU_REG_FRM_CNT_RST__A, 2),
331 0x00, 0x08, /* FE_CU_REG_FRM_CNT_RST__A */
332 0x00, 0x00, /* FE_CU_REG_FRM_CNT_STR__A */
333
334 END_OF_TABLE
335};
336
337 /* with PGA */
338/* WR16COND( DRXD_WITH_PGA, FE_AG_REG_AG_PGA_MODE__A , 0x0004), */
339 /* without PGA */
340/* WR16COND( DRXD_WITHOUT_PGA, FE_AG_REG_AG_PGA_MODE__A , 0x0001), */
341/* WR16(FE_AG_REG_AG_AGC_SIO__A, (extAttr -> FeAgRegAgAgcSio), 0x0000 );*/
342/* WR16(FE_AG_REG_AG_PWD__A ,(extAttr -> FeAgRegAgPwd), 0x0000 );*/
343
344u8 DRXD_InitFEA2_2[] = {
345 WR16(FE_AG_REG_CDR_RUR_CNT__A, 0x0010),
346 WR16(FE_AG_REG_FGM_WRI__A, 48),
347 /* Activate measurement, activate scale */
348 WR16(FE_FD_REG_MEAS_VAL__A, 0x0001),
349
350 WR16(FE_CU_REG_COMM_EXEC__A, 0x0001),
351 WR16(FE_CF_REG_COMM_EXEC__A, 0x0001),
352 WR16(FE_IF_REG_COMM_EXEC__A, 0x0001),
353 WR16(FE_FD_REG_COMM_EXEC__A, 0x0001),
354 WR16(FE_FS_REG_COMM_EXEC__A, 0x0001),
355 WR16(FE_AD_REG_COMM_EXEC__A, 0x0001),
356 WR16(FE_AG_REG_COMM_EXEC__A, 0x0001),
357 WR16(FE_AG_REG_AG_MODE_LOP__A, 0x895E),
358
359 END_OF_TABLE
360};
361
362u8 DRXD_InitFEB1_1[] = {
363 WR16(B_FE_AD_REG_PD__A, 0x0000),
364 WR16(B_FE_AD_REG_CLKNEG__A, 0x0000),
365 WR16(B_FE_AG_REG_BGC_FGC_WRI__A, 0x0000),
366 WR16(B_FE_AG_REG_BGC_CGC_WRI__A, 0x0000),
367 WR16(B_FE_AG_REG_AG_MODE_LOP__A, 0x000a),
368 WR16(B_FE_AG_REG_IND_PD1_WRI__A, 35),
369 WR16(B_FE_AG_REG_IND_WIN__A, 0),
370 WR16(B_FE_AG_REG_IND_THD_LOL__A, 8),
371 WR16(B_FE_AG_REG_IND_THD_HIL__A, 8),
372 WR16(B_FE_CF_REG_IMP_VAL__A, 1),
373 WR16(B_FE_AG_REG_EGC_FLA_RGN__A, 7),
374 END_OF_TABLE
375};
376
377 /* with PGA */
378/* WR16(B_FE_AG_REG_AG_PGA_MODE__A , 0x0000, 0x0000); */
379 /* without PGA */
380/* WR16(B_FE_AG_REG_AG_PGA_MODE__A ,
381 B_FE_AG_REG_AG_PGA_MODE_PFN_PCN_AFY_REN, 0x0000);*/
382 /* WR16(B_FE_AG_REG_AG_AGC_SIO__A,(extAttr -> FeAgRegAgAgcSio), 0x0000 );*//*added HS 23-05-2005 */
383/* WR16(B_FE_AG_REG_AG_PWD__A ,(extAttr -> FeAgRegAgPwd), 0x0000 );*/
384
385u8 DRXD_InitFEB1_2[] = {
386 WR16(B_FE_COMM_EXEC__A, 0x0001),
387
388 /* RF-AGC setup */
389 WR16(B_FE_AG_REG_PDA_AUR_CNT__A, 0x0C),
390 WR16(B_FE_AG_REG_PDC_SET_LVL__A, 0x01),
391 WR16(B_FE_AG_REG_PDC_FLA_RGN__A, 0x02),
392 WR16(B_FE_AG_REG_PDC_FLA_STP__A, 0xFFFF),
393 WR16(B_FE_AG_REG_PDC_SLO_STP__A, 0xFFFF),
394 WR16(B_FE_AG_REG_PDC_MAX__A, 0x02),
395 WR16(B_FE_AG_REG_TGA_AUR_CNT__A, 0x0C),
396 WR16(B_FE_AG_REG_TGC_SET_LVL__A, 0x22),
397 WR16(B_FE_AG_REG_TGC_FLA_RGN__A, 0x15),
398 WR16(B_FE_AG_REG_TGC_FLA_STP__A, 0x01),
399 WR16(B_FE_AG_REG_TGC_SLO_STP__A, 0x0A),
400
401 WR16(B_FE_CU_REG_DIV_NFC_CLP__A, 0),
402 WR16(B_FE_CU_REG_CTR_NFC_OCR__A, 25000),
403 WR16(B_FE_CU_REG_CTR_NFC_ICR__A, 1),
404 END_OF_TABLE
405};
406
407u8 DRXD_InitCPA2[] = {
408 WRBLOCK(CP_REG_BR_SPL_OFFSET__A, 2),
409 0x07, 0x00, /* CP_REG_BR_SPL_OFFSET__A */
410 0x0A, 0x00, /* CP_REG_BR_STR_DEL__A */
411
412 WRBLOCK(CP_REG_RT_ANG_INC0__A, 4),
413 0x00, 0x00, /* CP_REG_RT_ANG_INC0__A */
414 0x00, 0x00, /* CP_REG_RT_ANG_INC1__A */
415 0x03, 0x00, /* CP_REG_RT_DETECT_ENA__A */
416 0x03, 0x00, /* CP_REG_RT_DETECT_TRH__A */
417
418 WRBLOCK(CP_REG_AC_NEXP_OFFS__A, 5),
419 0x32, 0x00, /* CP_REG_AC_NEXP_OFFS__A */
420 0x62, 0x00, /* CP_REG_AC_AVER_POW__A */
421 0x82, 0x00, /* CP_REG_AC_MAX_POW__A */
422 0x26, 0x00, /* CP_REG_AC_WEIGHT_MAN__A */
423 0x0F, 0x00, /* CP_REG_AC_WEIGHT_EXP__A */
424
425 WRBLOCK(CP_REG_AC_AMP_MODE__A, 2),
426 0x02, 0x00, /* CP_REG_AC_AMP_MODE__A */
427 0x01, 0x00, /* CP_REG_AC_AMP_FIX__A */
428
429 WR16(CP_REG_INTERVAL__A, 0x0005),
430 WR16(CP_REG_RT_EXP_MARG__A, 0x0004),
431 WR16(CP_REG_AC_ANG_MODE__A, 0x0003),
432
433 WR16(CP_REG_COMM_EXEC__A, 0x0001),
434 END_OF_TABLE
435};
436
437u8 DRXD_InitCPB1[] = {
438 WR16(B_CP_REG_BR_SPL_OFFSET__A, 0x0008),
439 WR16(B_CP_COMM_EXEC__A, 0x0001),
440 END_OF_TABLE
441};
442
443u8 DRXD_InitCEA2[] = {
444 WRBLOCK(CE_REG_AVG_POW__A, 4),
445 0x62, 0x00, /* CE_REG_AVG_POW__A */
446 0x78, 0x00, /* CE_REG_MAX_POW__A */
447 0x62, 0x00, /* CE_REG_ATT__A */
448 0x17, 0x00, /* CE_REG_NRED__A */
449
450 WRBLOCK(CE_REG_NE_ERR_SELECT__A, 2),
451 0x07, 0x00, /* CE_REG_NE_ERR_SELECT__A */
452 0xEB, 0xFF, /* CE_REG_NE_TD_CAL__A */
453
454 WRBLOCK(CE_REG_NE_MIXAVG__A, 2),
455 0x06, 0x00, /* CE_REG_NE_MIXAVG__A */
456 0x00, 0x00, /* CE_REG_NE_NUPD_OFS__A */
457
458 WRBLOCK(CE_REG_PE_NEXP_OFFS__A, 2),
459 0x00, 0x00, /* CE_REG_PE_NEXP_OFFS__A */
460 0x00, 0x00, /* CE_REG_PE_TIMESHIFT__A */
461
462 WRBLOCK(CE_REG_TP_A0_TAP_NEW__A, 3),
463 0x00, 0x01, /* CE_REG_TP_A0_TAP_NEW__A */
464 0x01, 0x00, /* CE_REG_TP_A0_TAP_NEW_VALID__A */
465 0x0E, 0x00, /* CE_REG_TP_A0_MU_LMS_STEP__A */
466
467 WRBLOCK(CE_REG_TP_A1_TAP_NEW__A, 3),
468 0x00, 0x00, /* CE_REG_TP_A1_TAP_NEW__A */
469 0x01, 0x00, /* CE_REG_TP_A1_TAP_NEW_VALID__A */
470 0x0A, 0x00, /* CE_REG_TP_A1_MU_LMS_STEP__A */
471
472 WRBLOCK(CE_REG_FI_SHT_INCR__A, 2),
473 0x12, 0x00, /* CE_REG_FI_SHT_INCR__A */
474 0x0C, 0x00, /* CE_REG_FI_EXP_NORM__A */
475
476 WRBLOCK(CE_REG_IR_INPUTSEL__A, 3),
477 0x00, 0x00, /* CE_REG_IR_INPUTSEL__A */
478 0x00, 0x00, /* CE_REG_IR_STARTPOS__A */
479 0xFF, 0x00, /* CE_REG_IR_NEXP_THRES__A */
480
481 WR16(CE_REG_TI_NEXP_OFFS__A, 0x0000),
482
483 END_OF_TABLE
484};
485
486u8 DRXD_InitCEB1[] = {
487 WR16(B_CE_REG_TI_PHN_ENABLE__A, 0x0001),
488 WR16(B_CE_REG_FR_PM_SET__A, 0x000D),
489
490 END_OF_TABLE
491};
492
493u8 DRXD_InitEQA2[] = {
494 WRBLOCK(EQ_REG_OT_QNT_THRES0__A, 4),
495 0x1E, 0x00, /* EQ_REG_OT_QNT_THRES0__A */
496 0x1F, 0x00, /* EQ_REG_OT_QNT_THRES1__A */
497 0x06, 0x00, /* EQ_REG_OT_CSI_STEP__A */
498 0x02, 0x00, /* EQ_REG_OT_CSI_OFFSET__A */
499
500 WR16(EQ_REG_TD_REQ_SMB_CNT__A, 0x0200),
501 WR16(EQ_REG_IS_CLIP_EXP__A, 0x001F),
502 WR16(EQ_REG_SN_OFFSET__A, (u16) (-7)),
503 WR16(EQ_REG_RC_SEL_CAR__A, 0x0002),
504 WR16(EQ_REG_COMM_EXEC__A, 0x0001),
505 END_OF_TABLE
506};
507
508u8 DRXD_InitEQB1[] = {
509 WR16(B_EQ_REG_COMM_EXEC__A, 0x0001),
510 END_OF_TABLE
511};
512
513u8 DRXD_ResetECRAM[] = {
514 /* Reset packet sync bytes in EC_VD ram */
515 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (0 * 17), 0x0000),
516 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (1 * 17), 0x0000),
517 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (2 * 17), 0x0000),
518 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (3 * 17), 0x0000),
519 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (4 * 17), 0x0000),
520 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (5 * 17), 0x0000),
521 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (6 * 17), 0x0000),
522 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (7 * 17), 0x0000),
523 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (8 * 17), 0x0000),
524 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (9 * 17), 0x0000),
525 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (10 * 17), 0x0000),
526
527 /* Reset packet sync bytes in EC_RS ram */
528 WR16(EC_RS_EC_RAM__A, 0x0000),
529 WR16(EC_RS_EC_RAM__A + 204, 0x0000),
530 END_OF_TABLE
531};
532
533u8 DRXD_InitECA2[] = {
534 WRBLOCK(EC_SB_REG_CSI_HI__A, 6),
535 0x1F, 0x00, /* EC_SB_REG_CSI_HI__A */
536 0x1E, 0x00, /* EC_SB_REG_CSI_LO__A */
537 0x01, 0x00, /* EC_SB_REG_SMB_TGL__A */
538 0x7F, 0x00, /* EC_SB_REG_SNR_HI__A */
539 0x7F, 0x00, /* EC_SB_REG_SNR_MID__A */
540 0x7F, 0x00, /* EC_SB_REG_SNR_LO__A */
541
542 WRBLOCK(EC_RS_REG_REQ_PCK_CNT__A, 2),
543 0x00, 0x10, /* EC_RS_REG_REQ_PCK_CNT__A */
544 DATA16(EC_RS_REG_VAL_PCK), /* EC_RS_REG_VAL__A */
545
546 WRBLOCK(EC_OC_REG_TMD_TOP_MODE__A, 5),
547 0x03, 0x00, /* EC_OC_REG_TMD_TOP_MODE__A */
548 0xF4, 0x01, /* EC_OC_REG_TMD_TOP_CNT__A */
549 0xC0, 0x03, /* EC_OC_REG_TMD_HIL_MAR__A */
550 0x40, 0x00, /* EC_OC_REG_TMD_LOL_MAR__A */
551 0x03, 0x00, /* EC_OC_REG_TMD_CUR_CNT__A */
552
553 WRBLOCK(EC_OC_REG_AVR_ASH_CNT__A, 2),
554 0x06, 0x00, /* EC_OC_REG_AVR_ASH_CNT__A */
555 0x02, 0x00, /* EC_OC_REG_AVR_BSH_CNT__A */
556
557 WRBLOCK(EC_OC_REG_RCN_MODE__A, 7),
558 0x07, 0x00, /* EC_OC_REG_RCN_MODE__A */
559 0x00, 0x00, /* EC_OC_REG_RCN_CRA_LOP__A */
560 0xc0, 0x00, /* EC_OC_REG_RCN_CRA_HIP__A */
561 0x00, 0x10, /* EC_OC_REG_RCN_CST_LOP__A */
562 0x00, 0x00, /* EC_OC_REG_RCN_CST_HIP__A */
563 0xFF, 0x01, /* EC_OC_REG_RCN_SET_LVL__A */
564 0x0D, 0x00, /* EC_OC_REG_RCN_GAI_LVL__A */
565
566 WRBLOCK(EC_OC_REG_RCN_CLP_LOP__A, 2),
567 0x00, 0x00, /* EC_OC_REG_RCN_CLP_LOP__A */
568 0xC0, 0x00, /* EC_OC_REG_RCN_CLP_HIP__A */
569
570 WR16(EC_SB_REG_CSI_OFS__A, 0x0001),
571 WR16(EC_VD_REG_FORCE__A, 0x0002),
572 WR16(EC_VD_REG_REQ_SMB_CNT__A, 0x0001),
573 WR16(EC_VD_REG_RLK_ENA__A, 0x0001),
574 WR16(EC_OD_REG_SYNC__A, 0x0664),
575 WR16(EC_OC_REG_OC_MON_SIO__A, 0x0000),
576 WR16(EC_OC_REG_SNC_ISC_LVL__A, 0x0D0C),
577 /* Output zero on monitorbus pads, power saving */
578 WR16(EC_OC_REG_OCR_MON_UOS__A,
579 (EC_OC_REG_OCR_MON_UOS_DAT_0_ENABLE |
580 EC_OC_REG_OCR_MON_UOS_DAT_1_ENABLE |
581 EC_OC_REG_OCR_MON_UOS_DAT_2_ENABLE |
582 EC_OC_REG_OCR_MON_UOS_DAT_3_ENABLE |
583 EC_OC_REG_OCR_MON_UOS_DAT_4_ENABLE |
584 EC_OC_REG_OCR_MON_UOS_DAT_5_ENABLE |
585 EC_OC_REG_OCR_MON_UOS_DAT_6_ENABLE |
586 EC_OC_REG_OCR_MON_UOS_DAT_7_ENABLE |
587 EC_OC_REG_OCR_MON_UOS_DAT_8_ENABLE |
588 EC_OC_REG_OCR_MON_UOS_DAT_9_ENABLE |
589 EC_OC_REG_OCR_MON_UOS_VAL_ENABLE |
590 EC_OC_REG_OCR_MON_UOS_CLK_ENABLE)),
591 WR16(EC_OC_REG_OCR_MON_WRI__A,
592 EC_OC_REG_OCR_MON_WRI_INIT),
593
594/* CHK_ERROR(ResetECRAM(demod)); */
595 /* Reset packet sync bytes in EC_VD ram */
596 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (0 * 17), 0x0000),
597 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (1 * 17), 0x0000),
598 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (2 * 17), 0x0000),
599 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (3 * 17), 0x0000),
600 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (4 * 17), 0x0000),
601 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (5 * 17), 0x0000),
602 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (6 * 17), 0x0000),
603 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (7 * 17), 0x0000),
604 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (8 * 17), 0x0000),
605 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (9 * 17), 0x0000),
606 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (10 * 17), 0x0000),
607
608 /* Reset packet sync bytes in EC_RS ram */
609 WR16(EC_RS_EC_RAM__A, 0x0000),
610 WR16(EC_RS_EC_RAM__A + 204, 0x0000),
611
612 WR16(EC_SB_REG_COMM_EXEC__A, 0x0001),
613 WR16(EC_VD_REG_COMM_EXEC__A, 0x0001),
614 WR16(EC_OD_REG_COMM_EXEC__A, 0x0001),
615 WR16(EC_RS_REG_COMM_EXEC__A, 0x0001),
616 END_OF_TABLE
617};
618
619u8 DRXD_InitECB1[] = {
620 WR16(B_EC_SB_REG_CSI_OFS0__A, 0x0001),
621 WR16(B_EC_SB_REG_CSI_OFS1__A, 0x0001),
622 WR16(B_EC_SB_REG_CSI_OFS2__A, 0x0001),
623 WR16(B_EC_SB_REG_CSI_LO__A, 0x000c),
624 WR16(B_EC_SB_REG_CSI_HI__A, 0x0018),
625 WR16(B_EC_SB_REG_SNR_HI__A, 0x007f),
626 WR16(B_EC_SB_REG_SNR_MID__A, 0x007f),
627 WR16(B_EC_SB_REG_SNR_LO__A, 0x007f),
628
629 WR16(B_EC_OC_REG_DTO_CLKMODE__A, 0x0002),
630 WR16(B_EC_OC_REG_DTO_PER__A, 0x0006),
631 WR16(B_EC_OC_REG_DTO_BUR__A, 0x0001),
632 WR16(B_EC_OC_REG_RCR_CLKMODE__A, 0x0000),
633 WR16(B_EC_OC_REG_RCN_GAI_LVL__A, 0x000D),
634 WR16(B_EC_OC_REG_OC_MPG_SIO__A, 0x0000),
635
636 /* Needed because shadow registers do not have correct default value */
637 WR16(B_EC_OC_REG_RCN_CST_LOP__A, 0x1000),
638 WR16(B_EC_OC_REG_RCN_CST_HIP__A, 0x0000),
639 WR16(B_EC_OC_REG_RCN_CRA_LOP__A, 0x0000),
640 WR16(B_EC_OC_REG_RCN_CRA_HIP__A, 0x00C0),
641 WR16(B_EC_OC_REG_RCN_CLP_LOP__A, 0x0000),
642 WR16(B_EC_OC_REG_RCN_CLP_HIP__A, 0x00C0),
643 WR16(B_EC_OC_REG_DTO_INC_LOP__A, 0x0000),
644 WR16(B_EC_OC_REG_DTO_INC_HIP__A, 0x00C0),
645
646 WR16(B_EC_OD_REG_SYNC__A, 0x0664),
647 WR16(B_EC_RS_REG_REQ_PCK_CNT__A, 0x1000),
648
649/* CHK_ERROR(ResetECRAM(demod)); */
650 /* Reset packet sync bytes in EC_VD ram */
651 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (0 * 17), 0x0000),
652 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (1 * 17), 0x0000),
653 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (2 * 17), 0x0000),
654 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (3 * 17), 0x0000),
655 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (4 * 17), 0x0000),
656 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (5 * 17), 0x0000),
657 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (6 * 17), 0x0000),
658 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (7 * 17), 0x0000),
659 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (8 * 17), 0x0000),
660 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (9 * 17), 0x0000),
661 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (10 * 17), 0x0000),
662
663 /* Reset packet sync bytes in EC_RS ram */
664 WR16(EC_RS_EC_RAM__A, 0x0000),
665 WR16(EC_RS_EC_RAM__A + 204, 0x0000),
666
667 WR16(B_EC_SB_REG_COMM_EXEC__A, 0x0001),
668 WR16(B_EC_VD_REG_COMM_EXEC__A, 0x0001),
669 WR16(B_EC_OD_REG_COMM_EXEC__A, 0x0001),
670 WR16(B_EC_RS_REG_COMM_EXEC__A, 0x0001),
671 END_OF_TABLE
672};
673
674u8 DRXD_ResetECA2[] = {
675
676 WR16(EC_OC_REG_COMM_EXEC__A, 0x0000),
677 WR16(EC_OD_REG_COMM_EXEC__A, 0x0000),
678
679 WRBLOCK(EC_OC_REG_TMD_TOP_MODE__A, 5),
680 0x03, 0x00, /* EC_OC_REG_TMD_TOP_MODE__A */
681 0xF4, 0x01, /* EC_OC_REG_TMD_TOP_CNT__A */
682 0xC0, 0x03, /* EC_OC_REG_TMD_HIL_MAR__A */
683 0x40, 0x00, /* EC_OC_REG_TMD_LOL_MAR__A */
684 0x03, 0x00, /* EC_OC_REG_TMD_CUR_CNT__A */
685
686 WRBLOCK(EC_OC_REG_AVR_ASH_CNT__A, 2),
687 0x06, 0x00, /* EC_OC_REG_AVR_ASH_CNT__A */
688 0x02, 0x00, /* EC_OC_REG_AVR_BSH_CNT__A */
689
690 WRBLOCK(EC_OC_REG_RCN_MODE__A, 7),
691 0x07, 0x00, /* EC_OC_REG_RCN_MODE__A */
692 0x00, 0x00, /* EC_OC_REG_RCN_CRA_LOP__A */
693 0xc0, 0x00, /* EC_OC_REG_RCN_CRA_HIP__A */
694 0x00, 0x10, /* EC_OC_REG_RCN_CST_LOP__A */
695 0x00, 0x00, /* EC_OC_REG_RCN_CST_HIP__A */
696 0xFF, 0x01, /* EC_OC_REG_RCN_SET_LVL__A */
697 0x0D, 0x00, /* EC_OC_REG_RCN_GAI_LVL__A */
698
699 WRBLOCK(EC_OC_REG_RCN_CLP_LOP__A, 2),
700 0x00, 0x00, /* EC_OC_REG_RCN_CLP_LOP__A */
701 0xC0, 0x00, /* EC_OC_REG_RCN_CLP_HIP__A */
702
703 WR16(EC_OD_REG_SYNC__A, 0x0664),
704 WR16(EC_OC_REG_OC_MON_SIO__A, 0x0000),
705 WR16(EC_OC_REG_SNC_ISC_LVL__A, 0x0D0C),
706 /* Output zero on monitorbus pads, power saving */
707 WR16(EC_OC_REG_OCR_MON_UOS__A,
708 (EC_OC_REG_OCR_MON_UOS_DAT_0_ENABLE |
709 EC_OC_REG_OCR_MON_UOS_DAT_1_ENABLE |
710 EC_OC_REG_OCR_MON_UOS_DAT_2_ENABLE |
711 EC_OC_REG_OCR_MON_UOS_DAT_3_ENABLE |
712 EC_OC_REG_OCR_MON_UOS_DAT_4_ENABLE |
713 EC_OC_REG_OCR_MON_UOS_DAT_5_ENABLE |
714 EC_OC_REG_OCR_MON_UOS_DAT_6_ENABLE |
715 EC_OC_REG_OCR_MON_UOS_DAT_7_ENABLE |
716 EC_OC_REG_OCR_MON_UOS_DAT_8_ENABLE |
717 EC_OC_REG_OCR_MON_UOS_DAT_9_ENABLE |
718 EC_OC_REG_OCR_MON_UOS_VAL_ENABLE |
719 EC_OC_REG_OCR_MON_UOS_CLK_ENABLE)),
720 WR16(EC_OC_REG_OCR_MON_WRI__A,
721 EC_OC_REG_OCR_MON_WRI_INIT),
722
723/* CHK_ERROR(ResetECRAM(demod)); */
724 /* Reset packet sync bytes in EC_VD ram */
725 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (0 * 17), 0x0000),
726 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (1 * 17), 0x0000),
727 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (2 * 17), 0x0000),
728 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (3 * 17), 0x0000),
729 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (4 * 17), 0x0000),
730 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (5 * 17), 0x0000),
731 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (6 * 17), 0x0000),
732 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (7 * 17), 0x0000),
733 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (8 * 17), 0x0000),
734 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (9 * 17), 0x0000),
735 WR16(EC_OD_DEINT_RAM__A + 0x3b7 + (10 * 17), 0x0000),
736
737 /* Reset packet sync bytes in EC_RS ram */
738 WR16(EC_RS_EC_RAM__A, 0x0000),
739 WR16(EC_RS_EC_RAM__A + 204, 0x0000),
740
741 WR16(EC_OD_REG_COMM_EXEC__A, 0x0001),
742 END_OF_TABLE
743};
744
745u8 DRXD_InitSC[] = {
746 WR16(SC_COMM_EXEC__A, 0),
747 WR16(SC_COMM_STATE__A, 0),
748
749#ifdef COMPILE_FOR_QT
750 WR16(SC_RA_RAM_BE_OPT_DELAY__A, 0x100),
751#endif
752
753 /* SC is not started, this is done in SetChannels() */
754 END_OF_TABLE
755};
756
757/* Diversity settings */
758
759u8 DRXD_InitDiversityFront[] = {
760 /* Start demod ********* RF in , diversity out **************************** */
761 WR16(B_SC_RA_RAM_CONFIG__A, B_SC_RA_RAM_CONFIG_FR_ENABLE__M |
762 B_SC_RA_RAM_CONFIG_FREQSCAN__M),
763
764 WR16(B_SC_RA_RAM_LC_ABS_2K__A, 0x7),
765 WR16(B_SC_RA_RAM_LC_ABS_8K__A, 0x7),
766 WR16(B_SC_RA_RAM_IR_COARSE_8K_LENGTH__A, IRLEN_COARSE_8K),
767 WR16(B_SC_RA_RAM_IR_COARSE_8K_FREQINC__A, 1 << (11 - IRLEN_COARSE_8K)),
768 WR16(B_SC_RA_RAM_IR_COARSE_8K_KAISINC__A, 1 << (17 - IRLEN_COARSE_8K)),
769 WR16(B_SC_RA_RAM_IR_FINE_8K_LENGTH__A, IRLEN_FINE_8K),
770 WR16(B_SC_RA_RAM_IR_FINE_8K_FREQINC__A, 1 << (11 - IRLEN_FINE_8K)),
771 WR16(B_SC_RA_RAM_IR_FINE_8K_KAISINC__A, 1 << (17 - IRLEN_FINE_8K)),
772
773 WR16(B_SC_RA_RAM_IR_COARSE_2K_LENGTH__A, IRLEN_COARSE_2K),
774 WR16(B_SC_RA_RAM_IR_COARSE_2K_FREQINC__A, 1 << (11 - IRLEN_COARSE_2K)),
775 WR16(B_SC_RA_RAM_IR_COARSE_2K_KAISINC__A, 1 << (17 - IRLEN_COARSE_2K)),
776 WR16(B_SC_RA_RAM_IR_FINE_2K_LENGTH__A, IRLEN_FINE_2K),
777 WR16(B_SC_RA_RAM_IR_FINE_2K_FREQINC__A, 1 << (11 - IRLEN_FINE_2K)),
778 WR16(B_SC_RA_RAM_IR_FINE_2K_KAISINC__A, 1 << (17 - IRLEN_FINE_2K)),
779
780 WR16(B_LC_RA_RAM_FILTER_CRMM_A__A, 7),
781 WR16(B_LC_RA_RAM_FILTER_CRMM_B__A, 4),
782 WR16(B_LC_RA_RAM_FILTER_SRMM_A__A, 7),
783 WR16(B_LC_RA_RAM_FILTER_SRMM_B__A, 4),
784 WR16(B_LC_RA_RAM_FILTER_SYM_SET__A, 500),
785
786 WR16(B_CC_REG_DIVERSITY__A, 0x0001),
787 WR16(B_EC_OC_REG_OC_MODE_HIP__A, 0x0010),
788 WR16(B_EQ_REG_RC_SEL_CAR__A, B_EQ_REG_RC_SEL_CAR_PASS_B_CE |
789 B_EQ_REG_RC_SEL_CAR_LOCAL_B_CE | B_EQ_REG_RC_SEL_CAR_MEAS_B_CE),
790
791 /* 0x2a ), *//* CE to PASS mux */
792
793 END_OF_TABLE
794};
795
796u8 DRXD_InitDiversityEnd[] = {
797 /* End demod *********** combining RF in and diversity in, MPEG TS out **** */
798 /* disable near/far; switch on timing slave mode */
799 WR16(B_SC_RA_RAM_CONFIG__A, B_SC_RA_RAM_CONFIG_FR_ENABLE__M |
800 B_SC_RA_RAM_CONFIG_FREQSCAN__M |
801 B_SC_RA_RAM_CONFIG_DIV_ECHO_ENABLE__M |
802 B_SC_RA_RAM_CONFIG_SLAVE__M |
803 B_SC_RA_RAM_CONFIG_DIV_BLANK_ENABLE__M
804/* MV from CtrlDiversity */
805 ),
806#ifdef DRXDDIV_SRMM_SLAVING
807 WR16(SC_RA_RAM_LC_ABS_2K__A, 0x3c7),
808 WR16(SC_RA_RAM_LC_ABS_8K__A, 0x3c7),
809#else
810 WR16(SC_RA_RAM_LC_ABS_2K__A, 0x7),
811 WR16(SC_RA_RAM_LC_ABS_8K__A, 0x7),
812#endif
813
814 WR16(B_SC_RA_RAM_IR_COARSE_8K_LENGTH__A, IRLEN_COARSE_8K),
815 WR16(B_SC_RA_RAM_IR_COARSE_8K_FREQINC__A, 1 << (11 - IRLEN_COARSE_8K)),
816 WR16(B_SC_RA_RAM_IR_COARSE_8K_KAISINC__A, 1 << (17 - IRLEN_COARSE_8K)),
817 WR16(B_SC_RA_RAM_IR_FINE_8K_LENGTH__A, IRLEN_FINE_8K),
818 WR16(B_SC_RA_RAM_IR_FINE_8K_FREQINC__A, 1 << (11 - IRLEN_FINE_8K)),
819 WR16(B_SC_RA_RAM_IR_FINE_8K_KAISINC__A, 1 << (17 - IRLEN_FINE_8K)),
820
821 WR16(B_SC_RA_RAM_IR_COARSE_2K_LENGTH__A, IRLEN_COARSE_2K),
822 WR16(B_SC_RA_RAM_IR_COARSE_2K_FREQINC__A, 1 << (11 - IRLEN_COARSE_2K)),
823 WR16(B_SC_RA_RAM_IR_COARSE_2K_KAISINC__A, 1 << (17 - IRLEN_COARSE_2K)),
824 WR16(B_SC_RA_RAM_IR_FINE_2K_LENGTH__A, IRLEN_FINE_2K),
825 WR16(B_SC_RA_RAM_IR_FINE_2K_FREQINC__A, 1 << (11 - IRLEN_FINE_2K)),
826 WR16(B_SC_RA_RAM_IR_FINE_2K_KAISINC__A, 1 << (17 - IRLEN_FINE_2K)),
827
828 WR16(B_LC_RA_RAM_FILTER_CRMM_A__A, 7),
829 WR16(B_LC_RA_RAM_FILTER_CRMM_B__A, 4),
830 WR16(B_LC_RA_RAM_FILTER_SRMM_A__A, 7),
831 WR16(B_LC_RA_RAM_FILTER_SRMM_B__A, 4),
832 WR16(B_LC_RA_RAM_FILTER_SYM_SET__A, 500),
833
834 WR16(B_CC_REG_DIVERSITY__A, 0x0001),
835 END_OF_TABLE
836};
837
838u8 DRXD_DisableDiversity[] = {
839 WR16(B_SC_RA_RAM_LC_ABS_2K__A, B_SC_RA_RAM_LC_ABS_2K__PRE),
840 WR16(B_SC_RA_RAM_LC_ABS_8K__A, B_SC_RA_RAM_LC_ABS_8K__PRE),
841 WR16(B_SC_RA_RAM_IR_COARSE_8K_LENGTH__A,
842 B_SC_RA_RAM_IR_COARSE_8K_LENGTH__PRE),
843 WR16(B_SC_RA_RAM_IR_COARSE_8K_FREQINC__A,
844 B_SC_RA_RAM_IR_COARSE_8K_FREQINC__PRE),
845 WR16(B_SC_RA_RAM_IR_COARSE_8K_KAISINC__A,
846 B_SC_RA_RAM_IR_COARSE_8K_KAISINC__PRE),
847 WR16(B_SC_RA_RAM_IR_FINE_8K_LENGTH__A,
848 B_SC_RA_RAM_IR_FINE_8K_LENGTH__PRE),
849 WR16(B_SC_RA_RAM_IR_FINE_8K_FREQINC__A,
850 B_SC_RA_RAM_IR_FINE_8K_FREQINC__PRE),
851 WR16(B_SC_RA_RAM_IR_FINE_8K_KAISINC__A,
852 B_SC_RA_RAM_IR_FINE_8K_KAISINC__PRE),
853
854 WR16(B_SC_RA_RAM_IR_COARSE_2K_LENGTH__A,
855 B_SC_RA_RAM_IR_COARSE_2K_LENGTH__PRE),
856 WR16(B_SC_RA_RAM_IR_COARSE_2K_FREQINC__A,
857 B_SC_RA_RAM_IR_COARSE_2K_FREQINC__PRE),
858 WR16(B_SC_RA_RAM_IR_COARSE_2K_KAISINC__A,
859 B_SC_RA_RAM_IR_COARSE_2K_KAISINC__PRE),
860 WR16(B_SC_RA_RAM_IR_FINE_2K_LENGTH__A,
861 B_SC_RA_RAM_IR_FINE_2K_LENGTH__PRE),
862 WR16(B_SC_RA_RAM_IR_FINE_2K_FREQINC__A,
863 B_SC_RA_RAM_IR_FINE_2K_FREQINC__PRE),
864 WR16(B_SC_RA_RAM_IR_FINE_2K_KAISINC__A,
865 B_SC_RA_RAM_IR_FINE_2K_KAISINC__PRE),
866
867 WR16(B_LC_RA_RAM_FILTER_CRMM_A__A, B_LC_RA_RAM_FILTER_CRMM_A__PRE),
868 WR16(B_LC_RA_RAM_FILTER_CRMM_B__A, B_LC_RA_RAM_FILTER_CRMM_B__PRE),
869 WR16(B_LC_RA_RAM_FILTER_SRMM_A__A, B_LC_RA_RAM_FILTER_SRMM_A__PRE),
870 WR16(B_LC_RA_RAM_FILTER_SRMM_B__A, B_LC_RA_RAM_FILTER_SRMM_B__PRE),
871 WR16(B_LC_RA_RAM_FILTER_SYM_SET__A, B_LC_RA_RAM_FILTER_SYM_SET__PRE),
872
873 WR16(B_CC_REG_DIVERSITY__A, 0x0000),
874 WR16(B_EQ_REG_RC_SEL_CAR__A, B_EQ_REG_RC_SEL_CAR_INIT), /* combining disabled */
875
876 END_OF_TABLE
877};
878
879u8 DRXD_StartDiversityFront[] = {
880 /* Start demod, RF in and diversity out, no combining */
881 WR16(B_FE_CF_REG_IMP_VAL__A, 0x0),
882 WR16(B_FE_AD_REG_FDB_IN__A, 0x0),
883 WR16(B_FE_AD_REG_INVEXT__A, 0x0),
884 WR16(B_EQ_REG_COMM_MB__A, 0x12), /* EQ to MB out */
885 WR16(B_EQ_REG_RC_SEL_CAR__A, B_EQ_REG_RC_SEL_CAR_PASS_B_CE | /* CE to PASS mux */
886 B_EQ_REG_RC_SEL_CAR_LOCAL_B_CE | B_EQ_REG_RC_SEL_CAR_MEAS_B_CE),
887
888 WR16(SC_RA_RAM_ECHO_SHIFT_LIM__A, 2),
889
890 END_OF_TABLE
891};
892
893u8 DRXD_StartDiversityEnd[] = {
894 /* End demod, combining RF in and diversity in, MPEG TS out */
895 WR16(B_FE_CF_REG_IMP_VAL__A, 0x0), /* disable impulse noise cruncher */
896 WR16(B_FE_AD_REG_INVEXT__A, 0x0), /* clock inversion (for sohard board) */
897 WR16(B_CP_REG_BR_STR_DEL__A, 10), /* apperently no mb delay matching is best */
898
899 WR16(B_EQ_REG_RC_SEL_CAR__A, B_EQ_REG_RC_SEL_CAR_DIV_ON | /* org = 0x81 combining enabled */
900 B_EQ_REG_RC_SEL_CAR_MEAS_A_CC |
901 B_EQ_REG_RC_SEL_CAR_PASS_A_CC | B_EQ_REG_RC_SEL_CAR_LOCAL_A_CC),
902
903 END_OF_TABLE
904};
905
906u8 DRXD_DiversityDelay8MHZ[] = {
907 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_2K_32__A, 1150 - 50),
908 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_2K_16__A, 1100 - 50),
909 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_2K_8__A, 1000 - 50),
910 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_2K_4__A, 800 - 50),
911 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_8K_32__A, 5420 - 50),
912 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_8K_16__A, 5200 - 50),
913 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_8K_8__A, 4800 - 50),
914 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_8K_4__A, 4000 - 50),
915 END_OF_TABLE
916};
917
918u8 DRXD_DiversityDelay6MHZ[] = /* also used ok for 7 MHz */
919{
920 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_2K_32__A, 1100 - 50),
921 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_2K_16__A, 1000 - 50),
922 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_2K_8__A, 900 - 50),
923 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_2K_4__A, 600 - 50),
924 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_8K_32__A, 5300 - 50),
925 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_8K_16__A, 5000 - 50),
926 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_8K_8__A, 4500 - 50),
927 WR16(B_SC_RA_RAM_DIVERSITY_DELAY_8K_4__A, 3500 - 50),
928 END_OF_TABLE
929};
diff --git a/drivers/media/dvb/frontends/drxd_firm.h b/drivers/media/dvb/frontends/drxd_firm.h
new file mode 100644
index 000000000000..41597e89941c
--- /dev/null
+++ b/drivers/media/dvb/frontends/drxd_firm.h
@@ -0,0 +1,115 @@
1/*
2 * drxd_firm.h
3 *
4 * Copyright (C) 2006-2007 Micronas
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 only, as published by the Free Software Foundation.
9 *
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA
21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
22 */
23
24#ifndef _DRXD_FIRM_H_
25#define _DRXD_FIRM_H_
26
27#include <linux/types.h>
28#include "drxd_map_firm.h"
29
30#define VERSION_MAJOR 1
31#define VERSION_MINOR 4
32#define VERSION_PATCH 23
33
34#define HI_TR_FUNC_ADDR HI_IF_RAM_USR_BEGIN__A
35
36#define DRXD_MAX_RETRIES (1000)
37#define HI_I2C_DELAY 84
38#define HI_I2C_BRIDGE_DELAY 750
39
40#define EQ_TD_TPS_PWR_UNKNOWN 0x00C0 /* Unknown configurations */
41#define EQ_TD_TPS_PWR_QPSK 0x016a
42#define EQ_TD_TPS_PWR_QAM16_ALPHAN 0x0195
43#define EQ_TD_TPS_PWR_QAM16_ALPHA1 0x0195
44#define EQ_TD_TPS_PWR_QAM16_ALPHA2 0x011E
45#define EQ_TD_TPS_PWR_QAM16_ALPHA4 0x01CE
46#define EQ_TD_TPS_PWR_QAM64_ALPHAN 0x019F
47#define EQ_TD_TPS_PWR_QAM64_ALPHA1 0x019F
48#define EQ_TD_TPS_PWR_QAM64_ALPHA2 0x00F8
49#define EQ_TD_TPS_PWR_QAM64_ALPHA4 0x014D
50
51#define DRXD_DEF_AG_PWD_CONSUMER 0x000E
52#define DRXD_DEF_AG_PWD_PRO 0x0000
53#define DRXD_DEF_AG_AGC_SIO 0x0000
54
55#define DRXD_FE_CTRL_MAX 1023
56
57#define DRXD_OSCDEV_DO_SCAN (16)
58
59#define DRXD_OSCDEV_DONT_SCAN (0)
60
61#define DRXD_OSCDEV_STEP (275)
62
63#define DRXD_SCAN_TIMEOUT (650)
64
65#define DRXD_BANDWIDTH_8MHZ_IN_HZ (0x8B8249L)
66#define DRXD_BANDWIDTH_7MHZ_IN_HZ (0x7A1200L)
67#define DRXD_BANDWIDTH_6MHZ_IN_HZ (0x68A1B6L)
68
69#define IRLEN_COARSE_8K (10)
70#define IRLEN_FINE_8K (10)
71#define IRLEN_COARSE_2K (7)
72#define IRLEN_FINE_2K (9)
73#define DIFF_INVALID (511)
74#define DIFF_TARGET (4)
75#define DIFF_MARGIN (1)
76
77extern u8 DRXD_InitAtomicRead[];
78extern u8 DRXD_HiI2cPatch_1[];
79extern u8 DRXD_HiI2cPatch_3[];
80
81extern u8 DRXD_InitSC[];
82
83extern u8 DRXD_ResetCEFR[];
84extern u8 DRXD_InitFEA2_1[];
85extern u8 DRXD_InitFEA2_2[];
86extern u8 DRXD_InitCPA2[];
87extern u8 DRXD_InitCEA2[];
88extern u8 DRXD_InitEQA2[];
89extern u8 DRXD_InitECA2[];
90extern u8 DRXD_ResetECA2[];
91extern u8 DRXD_ResetECRAM[];
92
93extern u8 DRXD_A2_microcode[];
94extern u32 DRXD_A2_microcode_length;
95
96extern u8 DRXD_InitFEB1_1[];
97extern u8 DRXD_InitFEB1_2[];
98extern u8 DRXD_InitCPB1[];
99extern u8 DRXD_InitCEB1[];
100extern u8 DRXD_InitEQB1[];
101extern u8 DRXD_InitECB1[];
102
103extern u8 DRXD_InitDiversityFront[];
104extern u8 DRXD_InitDiversityEnd[];
105extern u8 DRXD_DisableDiversity[];
106extern u8 DRXD_StartDiversityFront[];
107extern u8 DRXD_StartDiversityEnd[];
108
109extern u8 DRXD_DiversityDelay8MHZ[];
110extern u8 DRXD_DiversityDelay6MHZ[];
111
112extern u8 DRXD_B1_microcode[];
113extern u32 DRXD_B1_microcode_length;
114
115#endif
diff --git a/drivers/media/dvb/frontends/drxd_hard.c b/drivers/media/dvb/frontends/drxd_hard.c
new file mode 100644
index 000000000000..ea4c1c361d2b
--- /dev/null
+++ b/drivers/media/dvb/frontends/drxd_hard.c
@@ -0,0 +1,3001 @@
1/*
2 * drxd_hard.c: DVB-T Demodulator Micronas DRX3975D-A2,DRX397xD-B1
3 *
4 * Copyright (C) 2003-2007 Micronas
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 only, as published by the Free Software Foundation.
9 *
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA
21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/firmware.h>
30#include <linux/i2c.h>
31#include <linux/version.h>
32#include <asm/div64.h>
33
34#include "dvb_frontend.h"
35#include "drxd.h"
36#include "drxd_firm.h"
37
38#define DRX_FW_FILENAME_A2 "drxd-a2-1.1.fw"
39#define DRX_FW_FILENAME_B1 "drxd-b1-1.1.fw"
40
41#define CHUNK_SIZE 48
42
43#define DRX_I2C_RMW 0x10
44#define DRX_I2C_BROADCAST 0x20
45#define DRX_I2C_CLEARCRC 0x80
46#define DRX_I2C_SINGLE_MASTER 0xC0
47#define DRX_I2C_MODEFLAGS 0xC0
48#define DRX_I2C_FLAGS 0xF0
49
50#ifndef SIZEOF_ARRAY
51#define SIZEOF_ARRAY(array) (sizeof((array))/sizeof((array)[0]))
52#endif
53
54#define DEFAULT_LOCK_TIMEOUT 1100
55
56#define DRX_CHANNEL_AUTO 0
57#define DRX_CHANNEL_HIGH 1
58#define DRX_CHANNEL_LOW 2
59
60#define DRX_LOCK_MPEG 1
61#define DRX_LOCK_FEC 2
62#define DRX_LOCK_DEMOD 4
63
64/****************************************************************************/
65
66enum CSCDState {
67 CSCD_INIT = 0,
68 CSCD_SET,
69 CSCD_SAVED
70};
71
72enum CDrxdState {
73 DRXD_UNINITIALIZED = 0,
74 DRXD_STOPPED,
75 DRXD_STARTED
76};
77
78enum AGC_CTRL_MODE {
79 AGC_CTRL_AUTO = 0,
80 AGC_CTRL_USER,
81 AGC_CTRL_OFF
82};
83
84enum OperationMode {
85 OM_Default,
86 OM_DVBT_Diversity_Front,
87 OM_DVBT_Diversity_End
88};
89
90struct SCfgAgc {
91 enum AGC_CTRL_MODE ctrlMode;
92 u16 outputLevel; /* range [0, ... , 1023], 1/n of fullscale range */
93 u16 settleLevel; /* range [0, ... , 1023], 1/n of fullscale range */
94 u16 minOutputLevel; /* range [0, ... , 1023], 1/n of fullscale range */
95 u16 maxOutputLevel; /* range [0, ... , 1023], 1/n of fullscale range */
96 u16 speed; /* range [0, ... , 1023], 1/n of fullscale range */
97
98 u16 R1;
99 u16 R2;
100 u16 R3;
101};
102
103struct SNoiseCal {
104 int cpOpt;
105 u16 cpNexpOfs;
106 u16 tdCal2k;
107 u16 tdCal8k;
108};
109
110enum app_env {
111 APPENV_STATIC = 0,
112 APPENV_PORTABLE = 1,
113 APPENV_MOBILE = 2
114};
115
116enum EIFFilter {
117 IFFILTER_SAW = 0,
118 IFFILTER_DISCRETE = 1
119};
120
121struct drxd_state {
122 struct dvb_frontend frontend;
123 struct dvb_frontend_ops ops;
124 struct dvb_frontend_parameters param;
125
126 const struct firmware *fw;
127 struct device *dev;
128
129 struct i2c_adapter *i2c;
130 void *priv;
131 struct drxd_config config;
132
133 int i2c_access;
134 int init_done;
135 struct mutex mutex;
136
137 u8 chip_adr;
138 u16 hi_cfg_timing_div;
139 u16 hi_cfg_bridge_delay;
140 u16 hi_cfg_wakeup_key;
141 u16 hi_cfg_ctrl;
142
143 u16 intermediate_freq;
144 u16 osc_clock_freq;
145
146 enum CSCDState cscd_state;
147 enum CDrxdState drxd_state;
148
149 u16 sys_clock_freq;
150 s16 osc_clock_deviation;
151 u16 expected_sys_clock_freq;
152
153 u16 insert_rs_byte;
154 u16 enable_parallel;
155
156 int operation_mode;
157
158 struct SCfgAgc if_agc_cfg;
159 struct SCfgAgc rf_agc_cfg;
160
161 struct SNoiseCal noise_cal;
162
163 u32 fe_fs_add_incr;
164 u32 org_fe_fs_add_incr;
165 u16 current_fe_if_incr;
166
167 u16 m_FeAgRegAgPwd;
168 u16 m_FeAgRegAgAgcSio;
169
170 u16 m_EcOcRegOcModeLop;
171 u16 m_EcOcRegSncSncLvl;
172 u8 *m_InitAtomicRead;
173 u8 *m_HiI2cPatch;
174
175 u8 *m_ResetCEFR;
176 u8 *m_InitFE_1;
177 u8 *m_InitFE_2;
178 u8 *m_InitCP;
179 u8 *m_InitCE;
180 u8 *m_InitEQ;
181 u8 *m_InitSC;
182 u8 *m_InitEC;
183 u8 *m_ResetECRAM;
184 u8 *m_InitDiversityFront;
185 u8 *m_InitDiversityEnd;
186 u8 *m_DisableDiversity;
187 u8 *m_StartDiversityFront;
188 u8 *m_StartDiversityEnd;
189
190 u8 *m_DiversityDelay8MHZ;
191 u8 *m_DiversityDelay6MHZ;
192
193 u8 *microcode;
194 u32 microcode_length;
195
196 int type_A;
197 int PGA;
198 int diversity;
199 int tuner_mirrors;
200
201 enum app_env app_env_default;
202 enum app_env app_env_diversity;
203
204};
205
206/****************************************************************************/
207/* I2C **********************************************************************/
208/****************************************************************************/
209
210static int i2c_write(struct i2c_adapter *adap, u8 adr, u8 * data, int len)
211{
212 struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = data, .len = len };
213
214 if (i2c_transfer(adap, &msg, 1) != 1)
215 return -1;
216 return 0;
217}
218
219static int i2c_read(struct i2c_adapter *adap,
220 u8 adr, u8 *msg, int len, u8 *answ, int alen)
221{
222 struct i2c_msg msgs[2] = {
223 {
224 .addr = adr, .flags = 0,
225 .buf = msg, .len = len
226 }, {
227 .addr = adr, .flags = I2C_M_RD,
228 .buf = answ, .len = alen
229 }
230 };
231 if (i2c_transfer(adap, msgs, 2) != 2)
232 return -1;
233 return 0;
234}
235
236inline u32 MulDiv32(u32 a, u32 b, u32 c)
237{
238 u64 tmp64;
239
240 tmp64 = (u64)a * (u64)b;
241 do_div(tmp64, c);
242
243 return (u32) tmp64;
244}
245
246static int Read16(struct drxd_state *state, u32 reg, u16 *data, u8 flags)
247{
248 u8 adr = state->config.demod_address;
249 u8 mm1[4] = { reg & 0xff, (reg >> 16) & 0xff,
250 flags | ((reg >> 24) & 0xff), (reg >> 8) & 0xff
251 };
252 u8 mm2[2];
253 if (i2c_read(state->i2c, adr, mm1, 4, mm2, 2) < 0)
254 return -1;
255 if (data)
256 *data = mm2[0] | (mm2[1] << 8);
257 return mm2[0] | (mm2[1] << 8);
258}
259
260static int Read32(struct drxd_state *state, u32 reg, u32 *data, u8 flags)
261{
262 u8 adr = state->config.demod_address;
263 u8 mm1[4] = { reg & 0xff, (reg >> 16) & 0xff,
264 flags | ((reg >> 24) & 0xff), (reg >> 8) & 0xff
265 };
266 u8 mm2[4];
267
268 if (i2c_read(state->i2c, adr, mm1, 4, mm2, 4) < 0)
269 return -1;
270 if (data)
271 *data =
272 mm2[0] | (mm2[1] << 8) | (mm2[2] << 16) | (mm2[3] << 24);
273 return 0;
274}
275
276static int Write16(struct drxd_state *state, u32 reg, u16 data, u8 flags)
277{
278 u8 adr = state->config.demod_address;
279 u8 mm[6] = { reg & 0xff, (reg >> 16) & 0xff,
280 flags | ((reg >> 24) & 0xff), (reg >> 8) & 0xff,
281 data & 0xff, (data >> 8) & 0xff
282 };
283
284 if (i2c_write(state->i2c, adr, mm, 6) < 0)
285 return -1;
286 return 0;
287}
288
289static int Write32(struct drxd_state *state, u32 reg, u32 data, u8 flags)
290{
291 u8 adr = state->config.demod_address;
292 u8 mm[8] = { reg & 0xff, (reg >> 16) & 0xff,
293 flags | ((reg >> 24) & 0xff), (reg >> 8) & 0xff,
294 data & 0xff, (data >> 8) & 0xff,
295 (data >> 16) & 0xff, (data >> 24) & 0xff
296 };
297
298 if (i2c_write(state->i2c, adr, mm, 8) < 0)
299 return -1;
300 return 0;
301}
302
303static int write_chunk(struct drxd_state *state,
304 u32 reg, u8 *data, u32 len, u8 flags)
305{
306 u8 adr = state->config.demod_address;
307 u8 mm[CHUNK_SIZE + 4] = { reg & 0xff, (reg >> 16) & 0xff,
308 flags | ((reg >> 24) & 0xff), (reg >> 8) & 0xff
309 };
310 int i;
311
312 for (i = 0; i < len; i++)
313 mm[4 + i] = data[i];
314 if (i2c_write(state->i2c, adr, mm, 4 + len) < 0) {
315 printk(KERN_ERR "error in write_chunk\n");
316 return -1;
317 }
318 return 0;
319}
320
321static int WriteBlock(struct drxd_state *state,
322 u32 Address, u16 BlockSize, u8 *pBlock, u8 Flags)
323{
324 while (BlockSize > 0) {
325 u16 Chunk = BlockSize > CHUNK_SIZE ? CHUNK_SIZE : BlockSize;
326
327 if (write_chunk(state, Address, pBlock, Chunk, Flags) < 0)
328 return -1;
329 pBlock += Chunk;
330 Address += (Chunk >> 1);
331 BlockSize -= Chunk;
332 }
333 return 0;
334}
335
336static int WriteTable(struct drxd_state *state, u8 * pTable)
337{
338 int status = 0;
339
340 if (pTable == NULL)
341 return 0;
342
343 while (!status) {
344 u16 Length;
345 u32 Address = pTable[0] | (pTable[1] << 8) |
346 (pTable[2] << 16) | (pTable[3] << 24);
347
348 if (Address == 0xFFFFFFFF)
349 break;
350 pTable += sizeof(u32);
351
352 Length = pTable[0] | (pTable[1] << 8);
353 pTable += sizeof(u16);
354 if (!Length)
355 break;
356 status = WriteBlock(state, Address, Length * 2, pTable, 0);
357 pTable += (Length * 2);
358 }
359 return status;
360}
361
362/****************************************************************************/
363/****************************************************************************/
364/****************************************************************************/
365
366static int ResetCEFR(struct drxd_state *state)
367{
368 return WriteTable(state, state->m_ResetCEFR);
369}
370
371static int InitCP(struct drxd_state *state)
372{
373 return WriteTable(state, state->m_InitCP);
374}
375
376static int InitCE(struct drxd_state *state)
377{
378 int status;
379 enum app_env AppEnv = state->app_env_default;
380
381 do {
382 status = WriteTable(state, state->m_InitCE);
383 if (status < 0)
384 break;
385
386 if (state->operation_mode == OM_DVBT_Diversity_Front ||
387 state->operation_mode == OM_DVBT_Diversity_End) {
388 AppEnv = state->app_env_diversity;
389 }
390 if (AppEnv == APPENV_STATIC) {
391 status = Write16(state, CE_REG_TAPSET__A, 0x0000, 0);
392 if (status < 0)
393 break;
394 } else if (AppEnv == APPENV_PORTABLE) {
395 status = Write16(state, CE_REG_TAPSET__A, 0x0001, 0);
396 if (status < 0)
397 break;
398 } else if (AppEnv == APPENV_MOBILE && state->type_A) {
399 status = Write16(state, CE_REG_TAPSET__A, 0x0002, 0);
400 if (status < 0)
401 break;
402 } else if (AppEnv == APPENV_MOBILE && !state->type_A) {
403 status = Write16(state, CE_REG_TAPSET__A, 0x0006, 0);
404 if (status < 0)
405 break;
406 }
407
408 /* start ce */
409 status = Write16(state, B_CE_REG_COMM_EXEC__A, 0x0001, 0);
410 if (status < 0)
411 break;
412 } while (0);
413 return status;
414}
415
416static int StopOC(struct drxd_state *state)
417{
418 int status = 0;
419 u16 ocSyncLvl = 0;
420 u16 ocModeLop = state->m_EcOcRegOcModeLop;
421 u16 dtoIncLop = 0;
422 u16 dtoIncHip = 0;
423
424 do {
425 /* Store output configuration */
426 status = Read16(state, EC_OC_REG_SNC_ISC_LVL__A, &ocSyncLvl, 0);
427 if (status < 0)
428 break;
429 /* CHK_ERROR(Read16(EC_OC_REG_OC_MODE_LOP__A, &ocModeLop)); */
430 state->m_EcOcRegSncSncLvl = ocSyncLvl;
431 /* m_EcOcRegOcModeLop = ocModeLop; */
432
433 /* Flush FIFO (byte-boundary) at fixed rate */
434 status = Read16(state, EC_OC_REG_RCN_MAP_LOP__A, &dtoIncLop, 0);
435 if (status < 0)
436 break;
437 status = Read16(state, EC_OC_REG_RCN_MAP_HIP__A, &dtoIncHip, 0);
438 if (status < 0)
439 break;
440 status = Write16(state, EC_OC_REG_DTO_INC_LOP__A, dtoIncLop, 0);
441 if (status < 0)
442 break;
443 status = Write16(state, EC_OC_REG_DTO_INC_HIP__A, dtoIncHip, 0);
444 if (status < 0)
445 break;
446 ocModeLop &= ~(EC_OC_REG_OC_MODE_LOP_DTO_CTR_SRC__M);
447 ocModeLop |= EC_OC_REG_OC_MODE_LOP_DTO_CTR_SRC_STATIC;
448 status = Write16(state, EC_OC_REG_OC_MODE_LOP__A, ocModeLop, 0);
449 if (status < 0)
450 break;
451 status = Write16(state, EC_OC_REG_COMM_EXEC__A, EC_OC_REG_COMM_EXEC_CTL_HOLD, 0);
452 if (status < 0)
453 break;
454
455 msleep(1);
456 /* Output pins to '0' */
457 status = Write16(state, EC_OC_REG_OCR_MPG_UOS__A, EC_OC_REG_OCR_MPG_UOS__M, 0);
458 if (status < 0)
459 break;
460
461 /* Force the OC out of sync */
462 ocSyncLvl &= ~(EC_OC_REG_SNC_ISC_LVL_OSC__M);
463 status = Write16(state, EC_OC_REG_SNC_ISC_LVL__A, ocSyncLvl, 0);
464 if (status < 0)
465 break;
466 ocModeLop &= ~(EC_OC_REG_OC_MODE_LOP_PAR_ENA__M);
467 ocModeLop |= EC_OC_REG_OC_MODE_LOP_PAR_ENA_ENABLE;
468 ocModeLop |= 0x2; /* Magically-out-of-sync */
469 status = Write16(state, EC_OC_REG_OC_MODE_LOP__A, ocModeLop, 0);
470 if (status < 0)
471 break;
472 status = Write16(state, EC_OC_REG_COMM_INT_STA__A, 0x0, 0);
473 if (status < 0)
474 break;
475 status = Write16(state, EC_OC_REG_COMM_EXEC__A, EC_OC_REG_COMM_EXEC_CTL_ACTIVE, 0);
476 if (status < 0)
477 break;
478 } while (0);
479
480 return status;
481}
482
483static int StartOC(struct drxd_state *state)
484{
485 int status = 0;
486
487 do {
488 /* Stop OC */
489 status = Write16(state, EC_OC_REG_COMM_EXEC__A, EC_OC_REG_COMM_EXEC_CTL_HOLD, 0);
490 if (status < 0)
491 break;
492
493 /* Restore output configuration */
494 status = Write16(state, EC_OC_REG_SNC_ISC_LVL__A, state->m_EcOcRegSncSncLvl, 0);
495 if (status < 0)
496 break;
497 status = Write16(state, EC_OC_REG_OC_MODE_LOP__A, state->m_EcOcRegOcModeLop, 0);
498 if (status < 0)
499 break;
500
501 /* Output pins active again */
502 status = Write16(state, EC_OC_REG_OCR_MPG_UOS__A, EC_OC_REG_OCR_MPG_UOS_INIT, 0);
503 if (status < 0)
504 break;
505
506 /* Start OC */
507 status = Write16(state, EC_OC_REG_COMM_EXEC__A, EC_OC_REG_COMM_EXEC_CTL_ACTIVE, 0);
508 if (status < 0)
509 break;
510 } while (0);
511 return status;
512}
513
514static int InitEQ(struct drxd_state *state)
515{
516 return WriteTable(state, state->m_InitEQ);
517}
518
519static int InitEC(struct drxd_state *state)
520{
521 return WriteTable(state, state->m_InitEC);
522}
523
524static int InitSC(struct drxd_state *state)
525{
526 return WriteTable(state, state->m_InitSC);
527}
528
529static int InitAtomicRead(struct drxd_state *state)
530{
531 return WriteTable(state, state->m_InitAtomicRead);
532}
533
534static int CorrectSysClockDeviation(struct drxd_state *state);
535
536static int DRX_GetLockStatus(struct drxd_state *state, u32 * pLockStatus)
537{
538 u16 ScRaRamLock = 0;
539 const u16 mpeg_lock_mask = (SC_RA_RAM_LOCK_MPEG__M |
540 SC_RA_RAM_LOCK_FEC__M |
541 SC_RA_RAM_LOCK_DEMOD__M);
542 const u16 fec_lock_mask = (SC_RA_RAM_LOCK_FEC__M |
543 SC_RA_RAM_LOCK_DEMOD__M);
544 const u16 demod_lock_mask = SC_RA_RAM_LOCK_DEMOD__M;
545
546 int status;
547
548 *pLockStatus = 0;
549
550 status = Read16(state, SC_RA_RAM_LOCK__A, &ScRaRamLock, 0x0000);
551 if (status < 0) {
552 printk(KERN_ERR "Can't read SC_RA_RAM_LOCK__A status = %08x\n", status);
553 return status;
554 }
555
556 if (state->drxd_state != DRXD_STARTED)
557 return 0;
558
559 if ((ScRaRamLock & mpeg_lock_mask) == mpeg_lock_mask) {
560 *pLockStatus |= DRX_LOCK_MPEG;
561 CorrectSysClockDeviation(state);
562 }
563
564 if ((ScRaRamLock & fec_lock_mask) == fec_lock_mask)
565 *pLockStatus |= DRX_LOCK_FEC;
566
567 if ((ScRaRamLock & demod_lock_mask) == demod_lock_mask)
568 *pLockStatus |= DRX_LOCK_DEMOD;
569 return 0;
570}
571
572/****************************************************************************/
573
574static int SetCfgIfAgc(struct drxd_state *state, struct SCfgAgc *cfg)
575{
576 int status;
577
578 if (cfg->outputLevel > DRXD_FE_CTRL_MAX)
579 return -1;
580
581 if (cfg->ctrlMode == AGC_CTRL_USER) {
582 do {
583 u16 FeAgRegPm1AgcWri;
584 u16 FeAgRegAgModeLop;
585
586 status = Read16(state, FE_AG_REG_AG_MODE_LOP__A, &FeAgRegAgModeLop, 0);
587 if (status < 0)
588 break;
589 FeAgRegAgModeLop &= (~FE_AG_REG_AG_MODE_LOP_MODE_4__M);
590 FeAgRegAgModeLop |= FE_AG_REG_AG_MODE_LOP_MODE_4_STATIC;
591 status = Write16(state, FE_AG_REG_AG_MODE_LOP__A, FeAgRegAgModeLop, 0);
592 if (status < 0)
593 break;
594
595 FeAgRegPm1AgcWri = (u16) (cfg->outputLevel &
596 FE_AG_REG_PM1_AGC_WRI__M);
597 status = Write16(state, FE_AG_REG_PM1_AGC_WRI__A, FeAgRegPm1AgcWri, 0);
598 if (status < 0)
599 break;
600 } while (0);
601 } else if (cfg->ctrlMode == AGC_CTRL_AUTO) {
602 if (((cfg->maxOutputLevel) < (cfg->minOutputLevel)) ||
603 ((cfg->maxOutputLevel) > DRXD_FE_CTRL_MAX) ||
604 ((cfg->speed) > DRXD_FE_CTRL_MAX) ||
605 ((cfg->settleLevel) > DRXD_FE_CTRL_MAX)
606 )
607 return -1;
608 do {
609 u16 FeAgRegAgModeLop;
610 u16 FeAgRegEgcSetLvl;
611 u16 slope, offset;
612
613 /* == Mode == */
614
615 status = Read16(state, FE_AG_REG_AG_MODE_LOP__A, &FeAgRegAgModeLop, 0);
616 if (status < 0)
617 break;
618 FeAgRegAgModeLop &= (~FE_AG_REG_AG_MODE_LOP_MODE_4__M);
619 FeAgRegAgModeLop |=
620 FE_AG_REG_AG_MODE_LOP_MODE_4_DYNAMIC;
621 status = Write16(state, FE_AG_REG_AG_MODE_LOP__A, FeAgRegAgModeLop, 0);
622 if (status < 0)
623 break;
624
625 /* == Settle level == */
626
627 FeAgRegEgcSetLvl = (u16) ((cfg->settleLevel >> 1) &
628 FE_AG_REG_EGC_SET_LVL__M);
629 status = Write16(state, FE_AG_REG_EGC_SET_LVL__A, FeAgRegEgcSetLvl, 0);
630 if (status < 0)
631 break;
632
633 /* == Min/Max == */
634
635 slope = (u16) ((cfg->maxOutputLevel -
636 cfg->minOutputLevel) / 2);
637 offset = (u16) ((cfg->maxOutputLevel +
638 cfg->minOutputLevel) / 2 - 511);
639
640 status = Write16(state, FE_AG_REG_GC1_AGC_RIC__A, slope, 0);
641 if (status < 0)
642 break;
643 status = Write16(state, FE_AG_REG_GC1_AGC_OFF__A, offset, 0);
644 if (status < 0)
645 break;
646
647 /* == Speed == */
648 {
649 const u16 maxRur = 8;
650 const u16 slowIncrDecLUT[] = { 3, 4, 4, 5, 6 };
651 const u16 fastIncrDecLUT[] = { 14, 15, 15, 16,
652 17, 18, 18, 19,
653 20, 21, 22, 23,
654 24, 26, 27, 28,
655 29, 31
656 };
657
658 u16 fineSteps = (DRXD_FE_CTRL_MAX + 1) /
659 (maxRur + 1);
660 u16 fineSpeed = (u16) (cfg->speed -
661 ((cfg->speed /
662 fineSteps) *
663 fineSteps));
664 u16 invRurCount = (u16) (cfg->speed /
665 fineSteps);
666 u16 rurCount;
667 if (invRurCount > maxRur) {
668 rurCount = 0;
669 fineSpeed += fineSteps;
670 } else {
671 rurCount = maxRur - invRurCount;
672 }
673
674 /*
675 fastInc = default *
676 (2^(fineSpeed/fineSteps))
677 => range[default...2*default>
678 slowInc = default *
679 (2^(fineSpeed/fineSteps))
680 */
681 {
682 u16 fastIncrDec =
683 fastIncrDecLUT[fineSpeed /
684 ((fineSteps /
685 (14 + 1)) + 1)];
686 u16 slowIncrDec =
687 slowIncrDecLUT[fineSpeed /
688 (fineSteps /
689 (3 + 1))];
690
691 status = Write16(state, FE_AG_REG_EGC_RUR_CNT__A, rurCount, 0);
692 if (status < 0)
693 break;
694 status = Write16(state, FE_AG_REG_EGC_FAS_INC__A, fastIncrDec, 0);
695 if (status < 0)
696 break;
697 status = Write16(state, FE_AG_REG_EGC_FAS_DEC__A, fastIncrDec, 0);
698 if (status < 0)
699 break;
700 status = Write16(state, FE_AG_REG_EGC_SLO_INC__A, slowIncrDec, 0);
701 if (status < 0)
702 break;
703 status = Write16(state, FE_AG_REG_EGC_SLO_DEC__A, slowIncrDec, 0);
704 if (status < 0)
705 break;
706 }
707 }
708 } while (0);
709
710 } else {
711 /* No OFF mode for IF control */
712 return -1;
713 }
714 return status;
715}
716
717static int SetCfgRfAgc(struct drxd_state *state, struct SCfgAgc *cfg)
718{
719 int status = 0;
720
721 if (cfg->outputLevel > DRXD_FE_CTRL_MAX)
722 return -1;
723
724 if (cfg->ctrlMode == AGC_CTRL_USER) {
725 do {
726 u16 AgModeLop = 0;
727 u16 level = (cfg->outputLevel);
728
729 if (level == DRXD_FE_CTRL_MAX)
730 level++;
731
732 status = Write16(state, FE_AG_REG_PM2_AGC_WRI__A, level, 0x0000);
733 if (status < 0)
734 break;
735
736 /*==== Mode ====*/
737
738 /* Powerdown PD2, WRI source */
739 state->m_FeAgRegAgPwd &= ~(FE_AG_REG_AG_PWD_PWD_PD2__M);
740 state->m_FeAgRegAgPwd |=
741 FE_AG_REG_AG_PWD_PWD_PD2_DISABLE;
742 status = Write16(state, FE_AG_REG_AG_PWD__A, state->m_FeAgRegAgPwd, 0x0000);
743 if (status < 0)
744 break;
745
746 status = Read16(state, FE_AG_REG_AG_MODE_LOP__A, &AgModeLop, 0x0000);
747 if (status < 0)
748 break;
749 AgModeLop &= (~(FE_AG_REG_AG_MODE_LOP_MODE_5__M |
750 FE_AG_REG_AG_MODE_LOP_MODE_E__M));
751 AgModeLop |= (FE_AG_REG_AG_MODE_LOP_MODE_5_STATIC |
752 FE_AG_REG_AG_MODE_LOP_MODE_E_STATIC);
753 status = Write16(state, FE_AG_REG_AG_MODE_LOP__A, AgModeLop, 0x0000);
754 if (status < 0)
755 break;
756
757 /* enable AGC2 pin */
758 {
759 u16 FeAgRegAgAgcSio = 0;
760 status = Read16(state, FE_AG_REG_AG_AGC_SIO__A, &FeAgRegAgAgcSio, 0x0000);
761 if (status < 0)
762 break;
763 FeAgRegAgAgcSio &=
764 ~(FE_AG_REG_AG_AGC_SIO_AGC_SIO_2__M);
765 FeAgRegAgAgcSio |=
766 FE_AG_REG_AG_AGC_SIO_AGC_SIO_2_OUTPUT;
767 status = Write16(state, FE_AG_REG_AG_AGC_SIO__A, FeAgRegAgAgcSio, 0x0000);
768 if (status < 0)
769 break;
770 }
771
772 } while (0);
773 } else if (cfg->ctrlMode == AGC_CTRL_AUTO) {
774 u16 AgModeLop = 0;
775
776 do {
777 u16 level;
778 /* Automatic control */
779 /* Powerup PD2, AGC2 as output, TGC source */
780 (state->m_FeAgRegAgPwd) &=
781 ~(FE_AG_REG_AG_PWD_PWD_PD2__M);
782 (state->m_FeAgRegAgPwd) |=
783 FE_AG_REG_AG_PWD_PWD_PD2_DISABLE;
784 status = Write16(state, FE_AG_REG_AG_PWD__A, (state->m_FeAgRegAgPwd), 0x0000);
785 if (status < 0)
786 break;
787
788 status = Read16(state, FE_AG_REG_AG_MODE_LOP__A, &AgModeLop, 0x0000);
789 if (status < 0)
790 break;
791 AgModeLop &= (~(FE_AG_REG_AG_MODE_LOP_MODE_5__M |
792 FE_AG_REG_AG_MODE_LOP_MODE_E__M));
793 AgModeLop |= (FE_AG_REG_AG_MODE_LOP_MODE_5_STATIC |
794 FE_AG_REG_AG_MODE_LOP_MODE_E_DYNAMIC);
795 status = Write16(state, FE_AG_REG_AG_MODE_LOP__A, AgModeLop, 0x0000);
796 if (status < 0)
797 break;
798 /* Settle level */
799 level = (((cfg->settleLevel) >> 4) &
800 FE_AG_REG_TGC_SET_LVL__M);
801 status = Write16(state, FE_AG_REG_TGC_SET_LVL__A, level, 0x0000);
802 if (status < 0)
803 break;
804
805 /* Min/max: don't care */
806
807 /* Speed: TODO */
808
809 /* enable AGC2 pin */
810 {
811 u16 FeAgRegAgAgcSio = 0;
812 status = Read16(state, FE_AG_REG_AG_AGC_SIO__A, &FeAgRegAgAgcSio, 0x0000);
813 if (status < 0)
814 break;
815 FeAgRegAgAgcSio &=
816 ~(FE_AG_REG_AG_AGC_SIO_AGC_SIO_2__M);
817 FeAgRegAgAgcSio |=
818 FE_AG_REG_AG_AGC_SIO_AGC_SIO_2_OUTPUT;
819 status = Write16(state, FE_AG_REG_AG_AGC_SIO__A, FeAgRegAgAgcSio, 0x0000);
820 if (status < 0)
821 break;
822 }
823
824 } while (0);
825 } else {
826 u16 AgModeLop = 0;
827
828 do {
829 /* No RF AGC control */
830 /* Powerdown PD2, AGC2 as output, WRI source */
831 (state->m_FeAgRegAgPwd) &=
832 ~(FE_AG_REG_AG_PWD_PWD_PD2__M);
833 (state->m_FeAgRegAgPwd) |=
834 FE_AG_REG_AG_PWD_PWD_PD2_ENABLE;
835 status = Write16(state, FE_AG_REG_AG_PWD__A, (state->m_FeAgRegAgPwd), 0x0000);
836 if (status < 0)
837 break;
838
839 status = Read16(state, FE_AG_REG_AG_MODE_LOP__A, &AgModeLop, 0x0000);
840 if (status < 0)
841 break;
842 AgModeLop &= (~(FE_AG_REG_AG_MODE_LOP_MODE_5__M |
843 FE_AG_REG_AG_MODE_LOP_MODE_E__M));
844 AgModeLop |= (FE_AG_REG_AG_MODE_LOP_MODE_5_STATIC |
845 FE_AG_REG_AG_MODE_LOP_MODE_E_STATIC);
846 status = Write16(state, FE_AG_REG_AG_MODE_LOP__A, AgModeLop, 0x0000);
847 if (status < 0)
848 break;
849
850 /* set FeAgRegAgAgcSio AGC2 (RF) as input */
851 {
852 u16 FeAgRegAgAgcSio = 0;
853 status = Read16(state, FE_AG_REG_AG_AGC_SIO__A, &FeAgRegAgAgcSio, 0x0000);
854 if (status < 0)
855 break;
856 FeAgRegAgAgcSio &=
857 ~(FE_AG_REG_AG_AGC_SIO_AGC_SIO_2__M);
858 FeAgRegAgAgcSio |=
859 FE_AG_REG_AG_AGC_SIO_AGC_SIO_2_INPUT;
860 status = Write16(state, FE_AG_REG_AG_AGC_SIO__A, FeAgRegAgAgcSio, 0x0000);
861 if (status < 0)
862 break;
863 }
864 } while (0);
865 }
866 return status;
867}
868
869static int ReadIFAgc(struct drxd_state *state, u32 * pValue)
870{
871 int status = 0;
872
873 *pValue = 0;
874 if (state->if_agc_cfg.ctrlMode != AGC_CTRL_OFF) {
875 u16 Value;
876 status = Read16(state, FE_AG_REG_GC1_AGC_DAT__A, &Value, 0);
877 Value &= FE_AG_REG_GC1_AGC_DAT__M;
878 if (status >= 0) {
879 /* 3.3V
880 |
881 R1
882 |
883 Vin - R3 - * -- Vout
884 |
885 R2
886 |
887 GND
888 */
889 u32 R1 = state->if_agc_cfg.R1;
890 u32 R2 = state->if_agc_cfg.R2;
891 u32 R3 = state->if_agc_cfg.R3;
892
893 u32 Vmax = (3300 * R2) / (R1 + R2);
894 u32 Rpar = (R2 * R3) / (R3 + R2);
895 u32 Vmin = (3300 * Rpar) / (R1 + Rpar);
896 u32 Vout = Vmin + ((Vmax - Vmin) * Value) / 1024;
897
898 *pValue = Vout;
899 }
900 }
901 return status;
902}
903
904static int load_firmware(struct drxd_state *state, const char *fw_name)
905{
906 const struct firmware *fw;
907
908 if (request_firmware(&fw, fw_name, state->dev) < 0) {
909 printk(KERN_ERR "drxd: firmware load failure [%s]\n", fw_name);
910 return -EIO;
911 }
912
913 state->microcode = kzalloc(fw->size, GFP_KERNEL);
914 if (state->microcode == NULL) {
915 printk(KERN_ERR "drxd: firmware load failure: nomemory\n");
916 return -ENOMEM;
917 }
918
919 memcpy(state->microcode, fw->data, fw->size);
920 state->microcode_length = fw->size;
921 return 0;
922}
923
924static int DownloadMicrocode(struct drxd_state *state,
925 const u8 *pMCImage, u32 Length)
926{
927 u8 *pSrc;
928 u16 Flags;
929 u32 Address;
930 u16 nBlocks;
931 u16 BlockSize;
932 u16 BlockCRC;
933 u32 offset = 0;
934 int i, status = 0;
935
936 pSrc = (u8 *) pMCImage;
937 Flags = (pSrc[0] << 8) | pSrc[1];
938 pSrc += sizeof(u16);
939 offset += sizeof(u16);
940 nBlocks = (pSrc[0] << 8) | pSrc[1];
941 pSrc += sizeof(u16);
942 offset += sizeof(u16);
943
944 for (i = 0; i < nBlocks; i++) {
945 Address = (pSrc[0] << 24) | (pSrc[1] << 16) |
946 (pSrc[2] << 8) | pSrc[3];
947 pSrc += sizeof(u32);
948 offset += sizeof(u32);
949
950 BlockSize = ((pSrc[0] << 8) | pSrc[1]) * sizeof(u16);
951 pSrc += sizeof(u16);
952 offset += sizeof(u16);
953
954 Flags = (pSrc[0] << 8) | pSrc[1];
955 pSrc += sizeof(u16);
956 offset += sizeof(u16);
957
958 BlockCRC = (pSrc[0] << 8) | pSrc[1];
959 pSrc += sizeof(u16);
960 offset += sizeof(u16);
961
962 status = WriteBlock(state, Address, BlockSize,
963 pSrc, DRX_I2C_CLEARCRC);
964 if (status < 0)
965 break;
966 pSrc += BlockSize;
967 offset += BlockSize;
968 }
969
970 return status;
971}
972
973static int HI_Command(struct drxd_state *state, u16 cmd, u16 * pResult)
974{
975 u32 nrRetries = 0;
976 u16 waitCmd;
977 int status;
978
979 status = Write16(state, HI_RA_RAM_SRV_CMD__A, cmd, 0);
980 if (status < 0)
981 return status;
982
983 do {
984 nrRetries += 1;
985 if (nrRetries > DRXD_MAX_RETRIES) {
986 status = -1;
987 break;
988 };
989 status = Read16(state, HI_RA_RAM_SRV_CMD__A, &waitCmd, 0);
990 } while (waitCmd != 0);
991
992 if (status >= 0)
993 status = Read16(state, HI_RA_RAM_SRV_RES__A, pResult, 0);
994 return status;
995}
996
997static int HI_CfgCommand(struct drxd_state *state)
998{
999 int status = 0;
1000
1001 mutex_lock(&state->mutex);
1002 Write16(state, HI_RA_RAM_SRV_CFG_KEY__A, HI_RA_RAM_SRV_RST_KEY_ACT, 0);
1003 Write16(state, HI_RA_RAM_SRV_CFG_DIV__A, state->hi_cfg_timing_div, 0);
1004 Write16(state, HI_RA_RAM_SRV_CFG_BDL__A, state->hi_cfg_bridge_delay, 0);
1005 Write16(state, HI_RA_RAM_SRV_CFG_WUP__A, state->hi_cfg_wakeup_key, 0);
1006 Write16(state, HI_RA_RAM_SRV_CFG_ACT__A, state->hi_cfg_ctrl, 0);
1007
1008 Write16(state, HI_RA_RAM_SRV_CFG_KEY__A, HI_RA_RAM_SRV_RST_KEY_ACT, 0);
1009
1010 if ((state->hi_cfg_ctrl & HI_RA_RAM_SRV_CFG_ACT_PWD_EXE) ==
1011 HI_RA_RAM_SRV_CFG_ACT_PWD_EXE)
1012 status = Write16(state, HI_RA_RAM_SRV_CMD__A,
1013 HI_RA_RAM_SRV_CMD_CONFIG, 0);
1014 else
1015 status = HI_Command(state, HI_RA_RAM_SRV_CMD_CONFIG, 0);
1016 mutex_unlock(&state->mutex);
1017 return status;
1018}
1019
1020static int InitHI(struct drxd_state *state)
1021{
1022 state->hi_cfg_wakeup_key = (state->chip_adr);
1023 /* port/bridge/power down ctrl */
1024 state->hi_cfg_ctrl = HI_RA_RAM_SRV_CFG_ACT_SLV0_ON;
1025 return HI_CfgCommand(state);
1026}
1027
1028static int HI_ResetCommand(struct drxd_state *state)
1029{
1030 int status;
1031
1032 mutex_lock(&state->mutex);
1033 status = Write16(state, HI_RA_RAM_SRV_RST_KEY__A,
1034 HI_RA_RAM_SRV_RST_KEY_ACT, 0);
1035 if (status == 0)
1036 status = HI_Command(state, HI_RA_RAM_SRV_CMD_RESET, 0);
1037 mutex_unlock(&state->mutex);
1038 msleep(1);
1039 return status;
1040}
1041
1042static int DRX_ConfigureI2CBridge(struct drxd_state *state, int bEnableBridge)
1043{
1044 state->hi_cfg_ctrl &= (~HI_RA_RAM_SRV_CFG_ACT_BRD__M);
1045 if (bEnableBridge)
1046 state->hi_cfg_ctrl |= HI_RA_RAM_SRV_CFG_ACT_BRD_ON;
1047 else
1048 state->hi_cfg_ctrl |= HI_RA_RAM_SRV_CFG_ACT_BRD_OFF;
1049
1050 return HI_CfgCommand(state);
1051}
1052
1053#define HI_TR_WRITE 0x9
1054#define HI_TR_READ 0xA
1055#define HI_TR_READ_WRITE 0xB
1056#define HI_TR_BROADCAST 0x4
1057
1058#if 0
1059static int AtomicReadBlock(struct drxd_state *state,
1060 u32 Addr, u16 DataSize, u8 *pData, u8 Flags)
1061{
1062 int status;
1063 int i = 0;
1064
1065 /* Parameter check */
1066 if ((!pData) || ((DataSize & 1) != 0))
1067 return -1;
1068
1069 mutex_lock(&state->mutex);
1070
1071 do {
1072 /* Instruct HI to read n bytes */
1073 /* TODO use proper names forthese egisters */
1074 status = Write16(state, HI_RA_RAM_SRV_CFG_KEY__A, (HI_TR_FUNC_ADDR & 0xFFFF), 0);
1075 if (status < 0)
1076 break;
1077 status = Write16(state, HI_RA_RAM_SRV_CFG_DIV__A, (u16) (Addr >> 16), 0);
1078 if (status < 0)
1079 break;
1080 status = Write16(state, HI_RA_RAM_SRV_CFG_BDL__A, (u16) (Addr & 0xFFFF), 0);
1081 if (status < 0)
1082 break;
1083 status = Write16(state, HI_RA_RAM_SRV_CFG_WUP__A, (u16) ((DataSize / 2) - 1), 0);
1084 if (status < 0)
1085 break;
1086 status = Write16(state, HI_RA_RAM_SRV_CFG_ACT__A, HI_TR_READ, 0);
1087 if (status < 0)
1088 break;
1089
1090 status = HI_Command(state, HI_RA_RAM_SRV_CMD_EXECUTE, 0);
1091 if (status < 0)
1092 break;
1093
1094 } while (0);
1095
1096 if (status >= 0) {
1097 for (i = 0; i < (DataSize / 2); i += 1) {
1098 u16 word;
1099
1100 status = Read16(state, (HI_RA_RAM_USR_BEGIN__A + i),
1101 &word, 0);
1102 if (status < 0)
1103 break;
1104 pData[2 * i] = (u8) (word & 0xFF);
1105 pData[(2 * i) + 1] = (u8) (word >> 8);
1106 }
1107 }
1108 mutex_unlock(&state->mutex);
1109 return status;
1110}
1111
1112static int AtomicReadReg32(struct drxd_state *state,
1113 u32 Addr, u32 *pData, u8 Flags)
1114{
1115 u8 buf[sizeof(u32)];
1116 int status;
1117
1118 if (!pData)
1119 return -1;
1120 status = AtomicReadBlock(state, Addr, sizeof(u32), buf, Flags);
1121 *pData = (((u32) buf[0]) << 0) +
1122 (((u32) buf[1]) << 8) +
1123 (((u32) buf[2]) << 16) + (((u32) buf[3]) << 24);
1124 return status;
1125}
1126#endif
1127
1128static int StopAllProcessors(struct drxd_state *state)
1129{
1130 return Write16(state, HI_COMM_EXEC__A,
1131 SC_COMM_EXEC_CTL_STOP, DRX_I2C_BROADCAST);
1132}
1133
1134static int EnableAndResetMB(struct drxd_state *state)
1135{
1136 if (state->type_A) {
1137 /* disable? monitor bus observe @ EC_OC */
1138 Write16(state, EC_OC_REG_OC_MON_SIO__A, 0x0000, 0x0000);
1139 }
1140
1141 /* do inverse broadcast, followed by explicit write to HI */
1142 Write16(state, HI_COMM_MB__A, 0x0000, DRX_I2C_BROADCAST);
1143 Write16(state, HI_COMM_MB__A, 0x0000, 0x0000);
1144 return 0;
1145}
1146
1147static int InitCC(struct drxd_state *state)
1148{
1149 if (state->osc_clock_freq == 0 ||
1150 state->osc_clock_freq > 20000 ||
1151 (state->osc_clock_freq % 4000) != 0) {
1152 printk(KERN_ERR "invalid osc frequency %d\n", state->osc_clock_freq);
1153 return -1;
1154 }
1155
1156 Write16(state, CC_REG_OSC_MODE__A, CC_REG_OSC_MODE_M20, 0);
1157 Write16(state, CC_REG_PLL_MODE__A, CC_REG_PLL_MODE_BYPASS_PLL |
1158 CC_REG_PLL_MODE_PUMP_CUR_12, 0);
1159 Write16(state, CC_REG_REF_DIVIDE__A, state->osc_clock_freq / 4000, 0);
1160 Write16(state, CC_REG_PWD_MODE__A, CC_REG_PWD_MODE_DOWN_PLL, 0);
1161 Write16(state, CC_REG_UPDATE__A, CC_REG_UPDATE_KEY, 0);
1162
1163 return 0;
1164}
1165
1166static int ResetECOD(struct drxd_state *state)
1167{
1168 int status = 0;
1169
1170 if (state->type_A)
1171 status = Write16(state, EC_OD_REG_SYNC__A, 0x0664, 0);
1172 else
1173 status = Write16(state, B_EC_OD_REG_SYNC__A, 0x0664, 0);
1174
1175 if (!(status < 0))
1176 status = WriteTable(state, state->m_ResetECRAM);
1177 if (!(status < 0))
1178 status = Write16(state, EC_OD_REG_COMM_EXEC__A, 0x0001, 0);
1179 return status;
1180}
1181
1182/* Configure PGA switch */
1183
1184static int SetCfgPga(struct drxd_state *state, int pgaSwitch)
1185{
1186 int status;
1187 u16 AgModeLop = 0;
1188 u16 AgModeHip = 0;
1189 do {
1190 if (pgaSwitch) {
1191 /* PGA on */
1192 /* fine gain */
1193 status = Read16(state, B_FE_AG_REG_AG_MODE_LOP__A, &AgModeLop, 0x0000);
1194 if (status < 0)
1195 break;
1196 AgModeLop &= (~(B_FE_AG_REG_AG_MODE_LOP_MODE_C__M));
1197 AgModeLop |= B_FE_AG_REG_AG_MODE_LOP_MODE_C_DYNAMIC;
1198 status = Write16(state, B_FE_AG_REG_AG_MODE_LOP__A, AgModeLop, 0x0000);
1199 if (status < 0)
1200 break;
1201
1202 /* coarse gain */
1203 status = Read16(state, B_FE_AG_REG_AG_MODE_HIP__A, &AgModeHip, 0x0000);
1204 if (status < 0)
1205 break;
1206 AgModeHip &= (~(B_FE_AG_REG_AG_MODE_HIP_MODE_J__M));
1207 AgModeHip |= B_FE_AG_REG_AG_MODE_HIP_MODE_J_DYNAMIC;
1208 status = Write16(state, B_FE_AG_REG_AG_MODE_HIP__A, AgModeHip, 0x0000);
1209 if (status < 0)
1210 break;
1211
1212 /* enable fine and coarse gain, enable AAF,
1213 no ext resistor */
1214 status = Write16(state, B_FE_AG_REG_AG_PGA_MODE__A, B_FE_AG_REG_AG_PGA_MODE_PFY_PCY_AFY_REN, 0x0000);
1215 if (status < 0)
1216 break;
1217 } else {
1218 /* PGA off, bypass */
1219
1220 /* fine gain */
1221 status = Read16(state, B_FE_AG_REG_AG_MODE_LOP__A, &AgModeLop, 0x0000);
1222 if (status < 0)
1223 break;
1224 AgModeLop &= (~(B_FE_AG_REG_AG_MODE_LOP_MODE_C__M));
1225 AgModeLop |= B_FE_AG_REG_AG_MODE_LOP_MODE_C_STATIC;
1226 status = Write16(state, B_FE_AG_REG_AG_MODE_LOP__A, AgModeLop, 0x0000);
1227 if (status < 0)
1228 break;
1229
1230 /* coarse gain */
1231 status = Read16(state, B_FE_AG_REG_AG_MODE_HIP__A, &AgModeHip, 0x0000);
1232 if (status < 0)
1233 break;
1234 AgModeHip &= (~(B_FE_AG_REG_AG_MODE_HIP_MODE_J__M));
1235 AgModeHip |= B_FE_AG_REG_AG_MODE_HIP_MODE_J_STATIC;
1236 status = Write16(state, B_FE_AG_REG_AG_MODE_HIP__A, AgModeHip, 0x0000);
1237 if (status < 0)
1238 break;
1239
1240 /* disable fine and coarse gain, enable AAF,
1241 no ext resistor */
1242 status = Write16(state, B_FE_AG_REG_AG_PGA_MODE__A, B_FE_AG_REG_AG_PGA_MODE_PFN_PCN_AFY_REN, 0x0000);
1243 if (status < 0)
1244 break;
1245 }
1246 } while (0);
1247 return status;
1248}
1249
1250static int InitFE(struct drxd_state *state)
1251{
1252 int status;
1253
1254 do {
1255 status = WriteTable(state, state->m_InitFE_1);
1256 if (status < 0)
1257 break;
1258
1259 if (state->type_A) {
1260 status = Write16(state, FE_AG_REG_AG_PGA_MODE__A,
1261 FE_AG_REG_AG_PGA_MODE_PFN_PCN_AFY_REN,
1262 0);
1263 } else {
1264 if (state->PGA)
1265 status = SetCfgPga(state, 0);
1266 else
1267 status =
1268 Write16(state, B_FE_AG_REG_AG_PGA_MODE__A,
1269 B_FE_AG_REG_AG_PGA_MODE_PFN_PCN_AFY_REN,
1270 0);
1271 }
1272
1273 if (status < 0)
1274 break;
1275 status = Write16(state, FE_AG_REG_AG_AGC_SIO__A, state->m_FeAgRegAgAgcSio, 0x0000);
1276 if (status < 0)
1277 break;
1278 status = Write16(state, FE_AG_REG_AG_PWD__A, state->m_FeAgRegAgPwd, 0x0000);
1279 if (status < 0)
1280 break;
1281
1282 status = WriteTable(state, state->m_InitFE_2);
1283 if (status < 0)
1284 break;
1285
1286 } while (0);
1287
1288 return status;
1289}
1290
1291static int InitFT(struct drxd_state *state)
1292{
1293 /*
1294 norm OFFSET, MB says =2 voor 8K en =3 voor 2K waarschijnlijk
1295 SC stuff
1296 */
1297 return Write16(state, FT_REG_COMM_EXEC__A, 0x0001, 0x0000);
1298}
1299
1300static int SC_WaitForReady(struct drxd_state *state)
1301{
1302 u16 curCmd;
1303 int i;
1304
1305 for (i = 0; i < DRXD_MAX_RETRIES; i += 1) {
1306 int status = Read16(state, SC_RA_RAM_CMD__A, &curCmd, 0);
1307 if (status == 0 || curCmd == 0)
1308 return status;
1309 }
1310 return -1;
1311}
1312
1313static int SC_SendCommand(struct drxd_state *state, u16 cmd)
1314{
1315 int status = 0;
1316 u16 errCode;
1317
1318 Write16(state, SC_RA_RAM_CMD__A, cmd, 0);
1319 SC_WaitForReady(state);
1320
1321 Read16(state, SC_RA_RAM_CMD_ADDR__A, &errCode, 0);
1322
1323 if (errCode == 0xFFFF) {
1324 printk(KERN_ERR "Command Error\n");
1325 status = -1;
1326 }
1327
1328 return status;
1329}
1330
1331static int SC_ProcStartCommand(struct drxd_state *state,
1332 u16 subCmd, u16 param0, u16 param1)
1333{
1334 int status = 0;
1335 u16 scExec;
1336
1337 mutex_lock(&state->mutex);
1338 do {
1339 Read16(state, SC_COMM_EXEC__A, &scExec, 0);
1340 if (scExec != 1) {
1341 status = -1;
1342 break;
1343 }
1344 SC_WaitForReady(state);
1345 Write16(state, SC_RA_RAM_CMD_ADDR__A, subCmd, 0);
1346 Write16(state, SC_RA_RAM_PARAM1__A, param1, 0);
1347 Write16(state, SC_RA_RAM_PARAM0__A, param0, 0);
1348
1349 SC_SendCommand(state, SC_RA_RAM_CMD_PROC_START);
1350 } while (0);
1351 mutex_unlock(&state->mutex);
1352 return status;
1353}
1354
1355static int SC_SetPrefParamCommand(struct drxd_state *state,
1356 u16 subCmd, u16 param0, u16 param1)
1357{
1358 int status;
1359
1360 mutex_lock(&state->mutex);
1361 do {
1362 status = SC_WaitForReady(state);
1363 if (status < 0)
1364 break;
1365 status = Write16(state, SC_RA_RAM_CMD_ADDR__A, subCmd, 0);
1366 if (status < 0)
1367 break;
1368 status = Write16(state, SC_RA_RAM_PARAM1__A, param1, 0);
1369 if (status < 0)
1370 break;
1371 status = Write16(state, SC_RA_RAM_PARAM0__A, param0, 0);
1372 if (status < 0)
1373 break;
1374
1375 status = SC_SendCommand(state, SC_RA_RAM_CMD_SET_PREF_PARAM);
1376 if (status < 0)
1377 break;
1378 } while (0);
1379 mutex_unlock(&state->mutex);
1380 return status;
1381}
1382
1383#if 0
1384static int SC_GetOpParamCommand(struct drxd_state *state, u16 * result)
1385{
1386 int status = 0;
1387
1388 mutex_lock(&state->mutex);
1389 do {
1390 status = SC_WaitForReady(state);
1391 if (status < 0)
1392 break;
1393 status = SC_SendCommand(state, SC_RA_RAM_CMD_GET_OP_PARAM);
1394 if (status < 0)
1395 break;
1396 status = Read16(state, SC_RA_RAM_PARAM0__A, result, 0);
1397 if (status < 0)
1398 break;
1399 } while (0);
1400 mutex_unlock(&state->mutex);
1401 return status;
1402}
1403#endif
1404
1405static int ConfigureMPEGOutput(struct drxd_state *state, int bEnableOutput)
1406{
1407 int status;
1408
1409 do {
1410 u16 EcOcRegIprInvMpg = 0;
1411 u16 EcOcRegOcModeLop = 0;
1412 u16 EcOcRegOcModeHip = 0;
1413 u16 EcOcRegOcMpgSio = 0;
1414
1415 /*CHK_ERROR(Read16(state, EC_OC_REG_OC_MODE_LOP__A, &EcOcRegOcModeLop, 0)); */
1416
1417 if (state->operation_mode == OM_DVBT_Diversity_Front) {
1418 if (bEnableOutput) {
1419 EcOcRegOcModeHip |=
1420 B_EC_OC_REG_OC_MODE_HIP_MPG_BUS_SRC_MONITOR;
1421 } else
1422 EcOcRegOcMpgSio |= EC_OC_REG_OC_MPG_SIO__M;
1423 EcOcRegOcModeLop |=
1424 EC_OC_REG_OC_MODE_LOP_PAR_ENA_DISABLE;
1425 } else {
1426 EcOcRegOcModeLop = state->m_EcOcRegOcModeLop;
1427
1428 if (bEnableOutput)
1429 EcOcRegOcMpgSio &= (~(EC_OC_REG_OC_MPG_SIO__M));
1430 else
1431 EcOcRegOcMpgSio |= EC_OC_REG_OC_MPG_SIO__M;
1432
1433 /* Don't Insert RS Byte */
1434 if (state->insert_rs_byte) {
1435 EcOcRegOcModeLop &=
1436 (~(EC_OC_REG_OC_MODE_LOP_PAR_ENA__M));
1437 EcOcRegOcModeHip &=
1438 (~EC_OC_REG_OC_MODE_HIP_MPG_PAR_VAL__M);
1439 EcOcRegOcModeHip |=
1440 EC_OC_REG_OC_MODE_HIP_MPG_PAR_VAL_ENABLE;
1441 } else {
1442 EcOcRegOcModeLop |=
1443 EC_OC_REG_OC_MODE_LOP_PAR_ENA_DISABLE;
1444 EcOcRegOcModeHip &=
1445 (~EC_OC_REG_OC_MODE_HIP_MPG_PAR_VAL__M);
1446 EcOcRegOcModeHip |=
1447 EC_OC_REG_OC_MODE_HIP_MPG_PAR_VAL_DISABLE;
1448 }
1449
1450 /* Mode = Parallel */
1451 if (state->enable_parallel)
1452 EcOcRegOcModeLop &=
1453 (~(EC_OC_REG_OC_MODE_LOP_MPG_TRM_MDE__M));
1454 else
1455 EcOcRegOcModeLop |=
1456 EC_OC_REG_OC_MODE_LOP_MPG_TRM_MDE_SERIAL;
1457 }
1458 /* Invert Data */
1459 /* EcOcRegIprInvMpg |= 0x00FF; */
1460 EcOcRegIprInvMpg &= (~(0x00FF));
1461
1462 /* Invert Error ( we don't use the pin ) */
1463 /* EcOcRegIprInvMpg |= 0x0100; */
1464 EcOcRegIprInvMpg &= (~(0x0100));
1465
1466 /* Invert Start ( we don't use the pin ) */
1467 /* EcOcRegIprInvMpg |= 0x0200; */
1468 EcOcRegIprInvMpg &= (~(0x0200));
1469
1470 /* Invert Valid ( we don't use the pin ) */
1471 /* EcOcRegIprInvMpg |= 0x0400; */
1472 EcOcRegIprInvMpg &= (~(0x0400));
1473
1474 /* Invert Clock */
1475 /* EcOcRegIprInvMpg |= 0x0800; */
1476 EcOcRegIprInvMpg &= (~(0x0800));
1477
1478 /* EcOcRegOcModeLop =0x05; */
1479 status = Write16(state, EC_OC_REG_IPR_INV_MPG__A, EcOcRegIprInvMpg, 0);
1480 if (status < 0)
1481 break;
1482 status = Write16(state, EC_OC_REG_OC_MODE_LOP__A, EcOcRegOcModeLop, 0);
1483 if (status < 0)
1484 break;
1485 status = Write16(state, EC_OC_REG_OC_MODE_HIP__A, EcOcRegOcModeHip, 0x0000);
1486 if (status < 0)
1487 break;
1488 status = Write16(state, EC_OC_REG_OC_MPG_SIO__A, EcOcRegOcMpgSio, 0);
1489 if (status < 0)
1490 break;
1491 } while (0);
1492 return status;
1493}
1494
1495static int SetDeviceTypeId(struct drxd_state *state)
1496{
1497 int status = 0;
1498 u16 deviceId = 0;
1499
1500 do {
1501 status = Read16(state, CC_REG_JTAGID_L__A, &deviceId, 0);
1502 if (status < 0)
1503 break;
1504 /* TODO: why twice? */
1505 status = Read16(state, CC_REG_JTAGID_L__A, &deviceId, 0);
1506 if (status < 0)
1507 break;
1508 printk(KERN_INFO "drxd: deviceId = %04x\n", deviceId);
1509
1510 state->type_A = 0;
1511 state->PGA = 0;
1512 state->diversity = 0;
1513 if (deviceId == 0) { /* on A2 only 3975 available */
1514 state->type_A = 1;
1515 printk(KERN_INFO "DRX3975D-A2\n");
1516 } else {
1517 deviceId >>= 12;
1518 printk(KERN_INFO "DRX397%dD-B1\n", deviceId);
1519 switch (deviceId) {
1520 case 4:
1521 state->diversity = 1;
1522 case 3:
1523 case 7:
1524 state->PGA = 1;
1525 break;
1526 case 6:
1527 state->diversity = 1;
1528 case 5:
1529 case 8:
1530 break;
1531 default:
1532 status = -1;
1533 break;
1534 }
1535 }
1536 } while (0);
1537
1538 if (status < 0)
1539 return status;
1540
1541 /* Init Table selection */
1542 state->m_InitAtomicRead = DRXD_InitAtomicRead;
1543 state->m_InitSC = DRXD_InitSC;
1544 state->m_ResetECRAM = DRXD_ResetECRAM;
1545 if (state->type_A) {
1546 state->m_ResetCEFR = DRXD_ResetCEFR;
1547 state->m_InitFE_1 = DRXD_InitFEA2_1;
1548 state->m_InitFE_2 = DRXD_InitFEA2_2;
1549 state->m_InitCP = DRXD_InitCPA2;
1550 state->m_InitCE = DRXD_InitCEA2;
1551 state->m_InitEQ = DRXD_InitEQA2;
1552 state->m_InitEC = DRXD_InitECA2;
1553 if (load_firmware(state, DRX_FW_FILENAME_A2))
1554 return -EIO;
1555 } else {
1556 state->m_ResetCEFR = NULL;
1557 state->m_InitFE_1 = DRXD_InitFEB1_1;
1558 state->m_InitFE_2 = DRXD_InitFEB1_2;
1559 state->m_InitCP = DRXD_InitCPB1;
1560 state->m_InitCE = DRXD_InitCEB1;
1561 state->m_InitEQ = DRXD_InitEQB1;
1562 state->m_InitEC = DRXD_InitECB1;
1563 if (load_firmware(state, DRX_FW_FILENAME_B1))
1564 return -EIO;
1565 }
1566 if (state->diversity) {
1567 state->m_InitDiversityFront = DRXD_InitDiversityFront;
1568 state->m_InitDiversityEnd = DRXD_InitDiversityEnd;
1569 state->m_DisableDiversity = DRXD_DisableDiversity;
1570 state->m_StartDiversityFront = DRXD_StartDiversityFront;
1571 state->m_StartDiversityEnd = DRXD_StartDiversityEnd;
1572 state->m_DiversityDelay8MHZ = DRXD_DiversityDelay8MHZ;
1573 state->m_DiversityDelay6MHZ = DRXD_DiversityDelay6MHZ;
1574 } else {
1575 state->m_InitDiversityFront = NULL;
1576 state->m_InitDiversityEnd = NULL;
1577 state->m_DisableDiversity = NULL;
1578 state->m_StartDiversityFront = NULL;
1579 state->m_StartDiversityEnd = NULL;
1580 state->m_DiversityDelay8MHZ = NULL;
1581 state->m_DiversityDelay6MHZ = NULL;
1582 }
1583
1584 return status;
1585}
1586
1587static int CorrectSysClockDeviation(struct drxd_state *state)
1588{
1589 int status;
1590 s32 incr = 0;
1591 s32 nomincr = 0;
1592 u32 bandwidth = 0;
1593 u32 sysClockInHz = 0;
1594 u32 sysClockFreq = 0; /* in kHz */
1595 s16 oscClockDeviation;
1596 s16 Diff;
1597
1598 do {
1599 /* Retrieve bandwidth and incr, sanity check */
1600
1601 /* These accesses should be AtomicReadReg32, but that
1602 causes trouble (at least for diversity */
1603 status = Read32(state, LC_RA_RAM_IFINCR_NOM_L__A, ((u32 *) &nomincr), 0);
1604 if (status < 0)
1605 break;
1606 status = Read32(state, FE_IF_REG_INCR0__A, (u32 *) &incr, 0);
1607 if (status < 0)
1608 break;
1609
1610 if (state->type_A) {
1611 if ((nomincr - incr < -500) || (nomincr - incr > 500))
1612 break;
1613 } else {
1614 if ((nomincr - incr < -2000) || (nomincr - incr > 2000))
1615 break;
1616 }
1617
1618 switch (state->param.u.ofdm.bandwidth) {
1619 case BANDWIDTH_8_MHZ:
1620 bandwidth = DRXD_BANDWIDTH_8MHZ_IN_HZ;
1621 break;
1622 case BANDWIDTH_7_MHZ:
1623 bandwidth = DRXD_BANDWIDTH_7MHZ_IN_HZ;
1624 break;
1625 case BANDWIDTH_6_MHZ:
1626 bandwidth = DRXD_BANDWIDTH_6MHZ_IN_HZ;
1627 break;
1628 default:
1629 return -1;
1630 break;
1631 }
1632
1633 /* Compute new sysclock value
1634 sysClockFreq = (((incr + 2^23)*bandwidth)/2^21)/1000 */
1635 incr += (1 << 23);
1636 sysClockInHz = MulDiv32(incr, bandwidth, 1 << 21);
1637 sysClockFreq = (u32) (sysClockInHz / 1000);
1638 /* rounding */
1639 if ((sysClockInHz % 1000) > 500)
1640 sysClockFreq++;
1641
1642 /* Compute clock deviation in ppm */
1643 oscClockDeviation = (u16) ((((s32) (sysClockFreq) -
1644 (s32)
1645 (state->expected_sys_clock_freq)) *
1646 1000000L) /
1647 (s32)
1648 (state->expected_sys_clock_freq));
1649
1650 Diff = oscClockDeviation - state->osc_clock_deviation;
1651 /*printk(KERN_INFO "sysclockdiff=%d\n", Diff); */
1652 if (Diff >= -200 && Diff <= 200) {
1653 state->sys_clock_freq = (u16) sysClockFreq;
1654 if (oscClockDeviation != state->osc_clock_deviation) {
1655 if (state->config.osc_deviation) {
1656 state->config.osc_deviation(state->priv,
1657 oscClockDeviation,
1658 1);
1659 state->osc_clock_deviation =
1660 oscClockDeviation;
1661 }
1662 }
1663 /* switch OFF SRMM scan in SC */
1664 status = Write16(state, SC_RA_RAM_SAMPLE_RATE_COUNT__A, DRXD_OSCDEV_DONT_SCAN, 0);
1665 if (status < 0)
1666 break;
1667 /* overrule FE_IF internal value for
1668 proper re-locking */
1669 status = Write16(state, SC_RA_RAM_IF_SAVE__AX, state->current_fe_if_incr, 0);
1670 if (status < 0)
1671 break;
1672 state->cscd_state = CSCD_SAVED;
1673 }
1674 } while (0);
1675
1676 return status;
1677}
1678
1679static int DRX_Stop(struct drxd_state *state)
1680{
1681 int status;
1682
1683 if (state->drxd_state != DRXD_STARTED)
1684 return 0;
1685
1686 do {
1687 if (state->cscd_state != CSCD_SAVED) {
1688 u32 lock;
1689 status = DRX_GetLockStatus(state, &lock);
1690 if (status < 0)
1691 break;
1692 }
1693
1694 status = StopOC(state);
1695 if (status < 0)
1696 break;
1697
1698 state->drxd_state = DRXD_STOPPED;
1699
1700 status = ConfigureMPEGOutput(state, 0);
1701 if (status < 0)
1702 break;
1703
1704 if (state->type_A) {
1705 /* Stop relevant processors off the device */
1706 status = Write16(state, EC_OD_REG_COMM_EXEC__A, 0x0000, 0x0000);
1707 if (status < 0)
1708 break;
1709
1710 status = Write16(state, SC_COMM_EXEC__A, SC_COMM_EXEC_CTL_STOP, 0);
1711 if (status < 0)
1712 break;
1713 status = Write16(state, LC_COMM_EXEC__A, SC_COMM_EXEC_CTL_STOP, 0);
1714 if (status < 0)
1715 break;
1716 } else {
1717 /* Stop all processors except HI & CC & FE */
1718 status = Write16(state, B_SC_COMM_EXEC__A, SC_COMM_EXEC_CTL_STOP, 0);
1719 if (status < 0)
1720 break;
1721 status = Write16(state, B_LC_COMM_EXEC__A, SC_COMM_EXEC_CTL_STOP, 0);
1722 if (status < 0)
1723 break;
1724 status = Write16(state, B_FT_COMM_EXEC__A, SC_COMM_EXEC_CTL_STOP, 0);
1725 if (status < 0)
1726 break;
1727 status = Write16(state, B_CP_COMM_EXEC__A, SC_COMM_EXEC_CTL_STOP, 0);
1728 if (status < 0)
1729 break;
1730 status = Write16(state, B_CE_COMM_EXEC__A, SC_COMM_EXEC_CTL_STOP, 0);
1731 if (status < 0)
1732 break;
1733 status = Write16(state, B_EQ_COMM_EXEC__A, SC_COMM_EXEC_CTL_STOP, 0);
1734 if (status < 0)
1735 break;
1736 status = Write16(state, EC_OD_REG_COMM_EXEC__A, 0x0000, 0);
1737 if (status < 0)
1738 break;
1739 }
1740
1741 } while (0);
1742 return status;
1743}
1744
1745int SetOperationMode(struct drxd_state *state, int oMode)
1746{
1747 int status;
1748
1749 do {
1750 if (state->drxd_state != DRXD_STOPPED) {
1751 status = -1;
1752 break;
1753 }
1754
1755 if (oMode == state->operation_mode) {
1756 status = 0;
1757 break;
1758 }
1759
1760 if (oMode != OM_Default && !state->diversity) {
1761 status = -1;
1762 break;
1763 }
1764
1765 switch (oMode) {
1766 case OM_DVBT_Diversity_Front:
1767 status = WriteTable(state, state->m_InitDiversityFront);
1768 break;
1769 case OM_DVBT_Diversity_End:
1770 status = WriteTable(state, state->m_InitDiversityEnd);
1771 break;
1772 case OM_Default:
1773 /* We need to check how to
1774 get DRXD out of diversity */
1775 default:
1776 status = WriteTable(state, state->m_DisableDiversity);
1777 break;
1778 }
1779 } while (0);
1780
1781 if (!status)
1782 state->operation_mode = oMode;
1783 return status;
1784}
1785
1786static int StartDiversity(struct drxd_state *state)
1787{
1788 int status = 0;
1789 u16 rcControl;
1790
1791 do {
1792 if (state->operation_mode == OM_DVBT_Diversity_Front) {
1793 status = WriteTable(state, state->m_StartDiversityFront);
1794 if (status < 0)
1795 break;
1796 } else if (state->operation_mode == OM_DVBT_Diversity_End) {
1797 status = WriteTable(state, state->m_StartDiversityEnd);
1798 if (status < 0)
1799 break;
1800 if (state->param.u.ofdm.bandwidth == BANDWIDTH_8_MHZ) {
1801 status = WriteTable(state, state->m_DiversityDelay8MHZ);
1802 if (status < 0)
1803 break;
1804 } else {
1805 status = WriteTable(state, state->m_DiversityDelay6MHZ);
1806 if (status < 0)
1807 break;
1808 }
1809
1810 status = Read16(state, B_EQ_REG_RC_SEL_CAR__A, &rcControl, 0);
1811 if (status < 0)
1812 break;
1813 rcControl &= ~(B_EQ_REG_RC_SEL_CAR_FFTMODE__M);
1814 rcControl |= B_EQ_REG_RC_SEL_CAR_DIV_ON |
1815 /* combining enabled */
1816 B_EQ_REG_RC_SEL_CAR_MEAS_A_CC |
1817 B_EQ_REG_RC_SEL_CAR_PASS_A_CC |
1818 B_EQ_REG_RC_SEL_CAR_LOCAL_A_CC;
1819 status = Write16(state, B_EQ_REG_RC_SEL_CAR__A, rcControl, 0);
1820 if (status < 0)
1821 break;
1822 }
1823 } while (0);
1824 return status;
1825}
1826
1827static int SetFrequencyShift(struct drxd_state *state,
1828 u32 offsetFreq, int channelMirrored)
1829{
1830 int negativeShift = (state->tuner_mirrors == channelMirrored);
1831
1832 /* Handle all mirroring
1833 *
1834 * Note: ADC mirroring (aliasing) is implictly handled by limiting
1835 * feFsRegAddInc to 28 bits below
1836 * (if the result before masking is more than 28 bits, this means
1837 * that the ADC is mirroring.
1838 * The masking is in fact the aliasing of the ADC)
1839 *
1840 */
1841
1842 /* Compute register value, unsigned computation */
1843 state->fe_fs_add_incr = MulDiv32(state->intermediate_freq +
1844 offsetFreq,
1845 1 << 28, state->sys_clock_freq);
1846 /* Remove integer part */
1847 state->fe_fs_add_incr &= 0x0FFFFFFFL;
1848 if (negativeShift)
1849 state->fe_fs_add_incr = ((1 << 28) - state->fe_fs_add_incr);
1850
1851 /* Save the frequency shift without tunerOffset compensation
1852 for CtrlGetChannel. */
1853 state->org_fe_fs_add_incr = MulDiv32(state->intermediate_freq,
1854 1 << 28, state->sys_clock_freq);
1855 /* Remove integer part */
1856 state->org_fe_fs_add_incr &= 0x0FFFFFFFL;
1857 if (negativeShift)
1858 state->org_fe_fs_add_incr = ((1L << 28) -
1859 state->org_fe_fs_add_incr);
1860
1861 return Write32(state, FE_FS_REG_ADD_INC_LOP__A,
1862 state->fe_fs_add_incr, 0);
1863}
1864
1865static int SetCfgNoiseCalibration(struct drxd_state *state,
1866 struct SNoiseCal *noiseCal)
1867{
1868 u16 beOptEna;
1869 int status = 0;
1870
1871 do {
1872 status = Read16(state, SC_RA_RAM_BE_OPT_ENA__A, &beOptEna, 0);
1873 if (status < 0)
1874 break;
1875 if (noiseCal->cpOpt) {
1876 beOptEna |= (1 << SC_RA_RAM_BE_OPT_ENA_CP_OPT);
1877 } else {
1878 beOptEna &= ~(1 << SC_RA_RAM_BE_OPT_ENA_CP_OPT);
1879 status = Write16(state, CP_REG_AC_NEXP_OFFS__A, noiseCal->cpNexpOfs, 0);
1880 if (status < 0)
1881 break;
1882 }
1883 status = Write16(state, SC_RA_RAM_BE_OPT_ENA__A, beOptEna, 0);
1884 if (status < 0)
1885 break;
1886
1887 if (!state->type_A) {
1888 status = Write16(state, B_SC_RA_RAM_CO_TD_CAL_2K__A, noiseCal->tdCal2k, 0);
1889 if (status < 0)
1890 break;
1891 status = Write16(state, B_SC_RA_RAM_CO_TD_CAL_8K__A, noiseCal->tdCal8k, 0);
1892 if (status < 0)
1893 break;
1894 }
1895 } while (0);
1896
1897 return status;
1898}
1899
1900static int DRX_Start(struct drxd_state *state, s32 off)
1901{
1902 struct dvb_ofdm_parameters *p = &state->param.u.ofdm;
1903 int status;
1904
1905 u16 transmissionParams = 0;
1906 u16 operationMode = 0;
1907 u16 qpskTdTpsPwr = 0;
1908 u16 qam16TdTpsPwr = 0;
1909 u16 qam64TdTpsPwr = 0;
1910 u32 feIfIncr = 0;
1911 u32 bandwidth = 0;
1912 int mirrorFreqSpect;
1913
1914 u16 qpskSnCeGain = 0;
1915 u16 qam16SnCeGain = 0;
1916 u16 qam64SnCeGain = 0;
1917 u16 qpskIsGainMan = 0;
1918 u16 qam16IsGainMan = 0;
1919 u16 qam64IsGainMan = 0;
1920 u16 qpskIsGainExp = 0;
1921 u16 qam16IsGainExp = 0;
1922 u16 qam64IsGainExp = 0;
1923 u16 bandwidthParam = 0;
1924
1925 if (off < 0)
1926 off = (off - 500) / 1000;
1927 else
1928 off = (off + 500) / 1000;
1929
1930 do {
1931 if (state->drxd_state != DRXD_STOPPED)
1932 return -1;
1933 status = ResetECOD(state);
1934 if (status < 0)
1935 break;
1936 if (state->type_A) {
1937 status = InitSC(state);
1938 if (status < 0)
1939 break;
1940 } else {
1941 status = InitFT(state);
1942 if (status < 0)
1943 break;
1944 status = InitCP(state);
1945 if (status < 0)
1946 break;
1947 status = InitCE(state);
1948 if (status < 0)
1949 break;
1950 status = InitEQ(state);
1951 if (status < 0)
1952 break;
1953 status = InitSC(state);
1954 if (status < 0)
1955 break;
1956 }
1957
1958 /* Restore current IF & RF AGC settings */
1959
1960 status = SetCfgIfAgc(state, &state->if_agc_cfg);
1961 if (status < 0)
1962 break;
1963 status = SetCfgRfAgc(state, &state->rf_agc_cfg);
1964 if (status < 0)
1965 break;
1966
1967 mirrorFreqSpect = (state->param.inversion == INVERSION_ON);
1968
1969 switch (p->transmission_mode) {
1970 default: /* Not set, detect it automatically */
1971 operationMode |= SC_RA_RAM_OP_AUTO_MODE__M;
1972 /* fall through , try first guess DRX_FFTMODE_8K */
1973 case TRANSMISSION_MODE_8K:
1974 transmissionParams |= SC_RA_RAM_OP_PARAM_MODE_8K;
1975 if (state->type_A) {
1976 status = Write16(state, EC_SB_REG_TR_MODE__A, EC_SB_REG_TR_MODE_8K, 0x0000);
1977 if (status < 0)
1978 break;
1979 qpskSnCeGain = 99;
1980 qam16SnCeGain = 83;
1981 qam64SnCeGain = 67;
1982 }
1983 break;
1984 case TRANSMISSION_MODE_2K:
1985 transmissionParams |= SC_RA_RAM_OP_PARAM_MODE_2K;
1986 if (state->type_A) {
1987 status = Write16(state, EC_SB_REG_TR_MODE__A, EC_SB_REG_TR_MODE_2K, 0x0000);
1988 if (status < 0)
1989 break;
1990 qpskSnCeGain = 97;
1991 qam16SnCeGain = 71;
1992 qam64SnCeGain = 65;
1993 }
1994 break;
1995 }
1996
1997 switch (p->guard_interval) {
1998 case GUARD_INTERVAL_1_4:
1999 transmissionParams |= SC_RA_RAM_OP_PARAM_GUARD_4;
2000 break;
2001 case GUARD_INTERVAL_1_8:
2002 transmissionParams |= SC_RA_RAM_OP_PARAM_GUARD_8;
2003 break;
2004 case GUARD_INTERVAL_1_16:
2005 transmissionParams |= SC_RA_RAM_OP_PARAM_GUARD_16;
2006 break;
2007 case GUARD_INTERVAL_1_32:
2008 transmissionParams |= SC_RA_RAM_OP_PARAM_GUARD_32;
2009 break;
2010 default: /* Not set, detect it automatically */
2011 operationMode |= SC_RA_RAM_OP_AUTO_GUARD__M;
2012 /* try first guess 1/4 */
2013 transmissionParams |= SC_RA_RAM_OP_PARAM_GUARD_4;
2014 break;
2015 }
2016
2017 switch (p->hierarchy_information) {
2018 case HIERARCHY_1:
2019 transmissionParams |= SC_RA_RAM_OP_PARAM_HIER_A1;
2020 if (state->type_A) {
2021 status = Write16(state, EQ_REG_OT_ALPHA__A, 0x0001, 0x0000);
2022 if (status < 0)
2023 break;
2024 status = Write16(state, EC_SB_REG_ALPHA__A, 0x0001, 0x0000);
2025 if (status < 0)
2026 break;
2027
2028 qpskTdTpsPwr = EQ_TD_TPS_PWR_UNKNOWN;
2029 qam16TdTpsPwr = EQ_TD_TPS_PWR_QAM16_ALPHA1;
2030 qam64TdTpsPwr = EQ_TD_TPS_PWR_QAM64_ALPHA1;
2031
2032 qpskIsGainMan =
2033 SC_RA_RAM_EQ_IS_GAIN_UNKNOWN_MAN__PRE;
2034 qam16IsGainMan =
2035 SC_RA_RAM_EQ_IS_GAIN_16QAM_MAN__PRE;
2036 qam64IsGainMan =
2037 SC_RA_RAM_EQ_IS_GAIN_64QAM_MAN__PRE;
2038
2039 qpskIsGainExp =
2040 SC_RA_RAM_EQ_IS_GAIN_UNKNOWN_EXP__PRE;
2041 qam16IsGainExp =
2042 SC_RA_RAM_EQ_IS_GAIN_16QAM_EXP__PRE;
2043 qam64IsGainExp =
2044 SC_RA_RAM_EQ_IS_GAIN_64QAM_EXP__PRE;
2045 }
2046 break;
2047
2048 case HIERARCHY_2:
2049 transmissionParams |= SC_RA_RAM_OP_PARAM_HIER_A2;
2050 if (state->type_A) {
2051 status = Write16(state, EQ_REG_OT_ALPHA__A, 0x0002, 0x0000);
2052 if (status < 0)
2053 break;
2054 status = Write16(state, EC_SB_REG_ALPHA__A, 0x0002, 0x0000);
2055 if (status < 0)
2056 break;
2057
2058 qpskTdTpsPwr = EQ_TD_TPS_PWR_UNKNOWN;
2059 qam16TdTpsPwr = EQ_TD_TPS_PWR_QAM16_ALPHA2;
2060 qam64TdTpsPwr = EQ_TD_TPS_PWR_QAM64_ALPHA2;
2061
2062 qpskIsGainMan =
2063 SC_RA_RAM_EQ_IS_GAIN_UNKNOWN_MAN__PRE;
2064 qam16IsGainMan =
2065 SC_RA_RAM_EQ_IS_GAIN_16QAM_A2_MAN__PRE;
2066 qam64IsGainMan =
2067 SC_RA_RAM_EQ_IS_GAIN_64QAM_A2_MAN__PRE;
2068
2069 qpskIsGainExp =
2070 SC_RA_RAM_EQ_IS_GAIN_UNKNOWN_EXP__PRE;
2071 qam16IsGainExp =
2072 SC_RA_RAM_EQ_IS_GAIN_16QAM_A2_EXP__PRE;
2073 qam64IsGainExp =
2074 SC_RA_RAM_EQ_IS_GAIN_64QAM_A2_EXP__PRE;
2075 }
2076 break;
2077 case HIERARCHY_4:
2078 transmissionParams |= SC_RA_RAM_OP_PARAM_HIER_A4;
2079 if (state->type_A) {
2080 status = Write16(state, EQ_REG_OT_ALPHA__A, 0x0003, 0x0000);
2081 if (status < 0)
2082 break;
2083 status = Write16(state, EC_SB_REG_ALPHA__A, 0x0003, 0x0000);
2084 if (status < 0)
2085 break;
2086
2087 qpskTdTpsPwr = EQ_TD_TPS_PWR_UNKNOWN;
2088 qam16TdTpsPwr = EQ_TD_TPS_PWR_QAM16_ALPHA4;
2089 qam64TdTpsPwr = EQ_TD_TPS_PWR_QAM64_ALPHA4;
2090
2091 qpskIsGainMan =
2092 SC_RA_RAM_EQ_IS_GAIN_UNKNOWN_MAN__PRE;
2093 qam16IsGainMan =
2094 SC_RA_RAM_EQ_IS_GAIN_16QAM_A4_MAN__PRE;
2095 qam64IsGainMan =
2096 SC_RA_RAM_EQ_IS_GAIN_64QAM_A4_MAN__PRE;
2097
2098 qpskIsGainExp =
2099 SC_RA_RAM_EQ_IS_GAIN_UNKNOWN_EXP__PRE;
2100 qam16IsGainExp =
2101 SC_RA_RAM_EQ_IS_GAIN_16QAM_A4_EXP__PRE;
2102 qam64IsGainExp =
2103 SC_RA_RAM_EQ_IS_GAIN_64QAM_A4_EXP__PRE;
2104 }
2105 break;
2106 case HIERARCHY_AUTO:
2107 default:
2108 /* Not set, detect it automatically, start with none */
2109 operationMode |= SC_RA_RAM_OP_AUTO_HIER__M;
2110 transmissionParams |= SC_RA_RAM_OP_PARAM_HIER_NO;
2111 if (state->type_A) {
2112 status = Write16(state, EQ_REG_OT_ALPHA__A, 0x0000, 0x0000);
2113 if (status < 0)
2114 break;
2115 status = Write16(state, EC_SB_REG_ALPHA__A, 0x0000, 0x0000);
2116 if (status < 0)
2117 break;
2118
2119 qpskTdTpsPwr = EQ_TD_TPS_PWR_QPSK;
2120 qam16TdTpsPwr = EQ_TD_TPS_PWR_QAM16_ALPHAN;
2121 qam64TdTpsPwr = EQ_TD_TPS_PWR_QAM64_ALPHAN;
2122
2123 qpskIsGainMan =
2124 SC_RA_RAM_EQ_IS_GAIN_QPSK_MAN__PRE;
2125 qam16IsGainMan =
2126 SC_RA_RAM_EQ_IS_GAIN_16QAM_MAN__PRE;
2127 qam64IsGainMan =
2128 SC_RA_RAM_EQ_IS_GAIN_64QAM_MAN__PRE;
2129
2130 qpskIsGainExp =
2131 SC_RA_RAM_EQ_IS_GAIN_QPSK_EXP__PRE;
2132 qam16IsGainExp =
2133 SC_RA_RAM_EQ_IS_GAIN_16QAM_EXP__PRE;
2134 qam64IsGainExp =
2135 SC_RA_RAM_EQ_IS_GAIN_64QAM_EXP__PRE;
2136 }
2137 break;
2138 }
2139 status = status;
2140 if (status < 0)
2141 break;
2142
2143 switch (p->constellation) {
2144 default:
2145 operationMode |= SC_RA_RAM_OP_AUTO_CONST__M;
2146 /* fall through , try first guess
2147 DRX_CONSTELLATION_QAM64 */
2148 case QAM_64:
2149 transmissionParams |= SC_RA_RAM_OP_PARAM_CONST_QAM64;
2150 if (state->type_A) {
2151 status = Write16(state, EQ_REG_OT_CONST__A, 0x0002, 0x0000);
2152 if (status < 0)
2153 break;
2154 status = Write16(state, EC_SB_REG_CONST__A, EC_SB_REG_CONST_64QAM, 0x0000);
2155 if (status < 0)
2156 break;
2157 status = Write16(state, EC_SB_REG_SCALE_MSB__A, 0x0020, 0x0000);
2158 if (status < 0)
2159 break;
2160 status = Write16(state, EC_SB_REG_SCALE_BIT2__A, 0x0008, 0x0000);
2161 if (status < 0)
2162 break;
2163 status = Write16(state, EC_SB_REG_SCALE_LSB__A, 0x0002, 0x0000);
2164 if (status < 0)
2165 break;
2166
2167 status = Write16(state, EQ_REG_TD_TPS_PWR_OFS__A, qam64TdTpsPwr, 0x0000);
2168 if (status < 0)
2169 break;
2170 status = Write16(state, EQ_REG_SN_CEGAIN__A, qam64SnCeGain, 0x0000);
2171 if (status < 0)
2172 break;
2173 status = Write16(state, EQ_REG_IS_GAIN_MAN__A, qam64IsGainMan, 0x0000);
2174 if (status < 0)
2175 break;
2176 status = Write16(state, EQ_REG_IS_GAIN_EXP__A, qam64IsGainExp, 0x0000);
2177 if (status < 0)
2178 break;
2179 }
2180 break;
2181 case QPSK:
2182 transmissionParams |= SC_RA_RAM_OP_PARAM_CONST_QPSK;
2183 if (state->type_A) {
2184 status = Write16(state, EQ_REG_OT_CONST__A, 0x0000, 0x0000);
2185 if (status < 0)
2186 break;
2187 status = Write16(state, EC_SB_REG_CONST__A, EC_SB_REG_CONST_QPSK, 0x0000);
2188 if (status < 0)
2189 break;
2190 status = Write16(state, EC_SB_REG_SCALE_MSB__A, 0x0010, 0x0000);
2191 if (status < 0)
2192 break;
2193 status = Write16(state, EC_SB_REG_SCALE_BIT2__A, 0x0000, 0x0000);
2194 if (status < 0)
2195 break;
2196 status = Write16(state, EC_SB_REG_SCALE_LSB__A, 0x0000, 0x0000);
2197 if (status < 0)
2198 break;
2199
2200 status = Write16(state, EQ_REG_TD_TPS_PWR_OFS__A, qpskTdTpsPwr, 0x0000);
2201 if (status < 0)
2202 break;
2203 status = Write16(state, EQ_REG_SN_CEGAIN__A, qpskSnCeGain, 0x0000);
2204 if (status < 0)
2205 break;
2206 status = Write16(state, EQ_REG_IS_GAIN_MAN__A, qpskIsGainMan, 0x0000);
2207 if (status < 0)
2208 break;
2209 status = Write16(state, EQ_REG_IS_GAIN_EXP__A, qpskIsGainExp, 0x0000);
2210 if (status < 0)
2211 break;
2212 }
2213 break;
2214
2215 case QAM_16:
2216 transmissionParams |= SC_RA_RAM_OP_PARAM_CONST_QAM16;
2217 if (state->type_A) {
2218 status = Write16(state, EQ_REG_OT_CONST__A, 0x0001, 0x0000);
2219 if (status < 0)
2220 break;
2221 status = Write16(state, EC_SB_REG_CONST__A, EC_SB_REG_CONST_16QAM, 0x0000);
2222 if (status < 0)
2223 break;
2224 status = Write16(state, EC_SB_REG_SCALE_MSB__A, 0x0010, 0x0000);
2225 if (status < 0)
2226 break;
2227 status = Write16(state, EC_SB_REG_SCALE_BIT2__A, 0x0004, 0x0000);
2228 if (status < 0)
2229 break;
2230 status = Write16(state, EC_SB_REG_SCALE_LSB__A, 0x0000, 0x0000);
2231 if (status < 0)
2232 break;
2233
2234 status = Write16(state, EQ_REG_TD_TPS_PWR_OFS__A, qam16TdTpsPwr, 0x0000);
2235 if (status < 0)
2236 break;
2237 status = Write16(state, EQ_REG_SN_CEGAIN__A, qam16SnCeGain, 0x0000);
2238 if (status < 0)
2239 break;
2240 status = Write16(state, EQ_REG_IS_GAIN_MAN__A, qam16IsGainMan, 0x0000);
2241 if (status < 0)
2242 break;
2243 status = Write16(state, EQ_REG_IS_GAIN_EXP__A, qam16IsGainExp, 0x0000);
2244 if (status < 0)
2245 break;
2246 }
2247 break;
2248
2249 }
2250 status = status;
2251 if (status < 0)
2252 break;
2253
2254 switch (DRX_CHANNEL_HIGH) {
2255 default:
2256 case DRX_CHANNEL_AUTO:
2257 case DRX_CHANNEL_LOW:
2258 transmissionParams |= SC_RA_RAM_OP_PARAM_PRIO_LO;
2259 status = Write16(state, EC_SB_REG_PRIOR__A, EC_SB_REG_PRIOR_LO, 0x0000);
2260 if (status < 0)
2261 break;
2262 break;
2263 case DRX_CHANNEL_HIGH:
2264 transmissionParams |= SC_RA_RAM_OP_PARAM_PRIO_HI;
2265 status = Write16(state, EC_SB_REG_PRIOR__A, EC_SB_REG_PRIOR_HI, 0x0000);
2266 if (status < 0)
2267 break;
2268 break;
2269
2270 }
2271
2272 switch (p->code_rate_HP) {
2273 case FEC_1_2:
2274 transmissionParams |= SC_RA_RAM_OP_PARAM_RATE_1_2;
2275 if (state->type_A) {
2276 status = Write16(state, EC_VD_REG_SET_CODERATE__A, EC_VD_REG_SET_CODERATE_C1_2, 0x0000);
2277 if (status < 0)
2278 break;
2279 }
2280 break;
2281 default:
2282 operationMode |= SC_RA_RAM_OP_AUTO_RATE__M;
2283 case FEC_2_3:
2284 transmissionParams |= SC_RA_RAM_OP_PARAM_RATE_2_3;
2285 if (state->type_A) {
2286 status = Write16(state, EC_VD_REG_SET_CODERATE__A, EC_VD_REG_SET_CODERATE_C2_3, 0x0000);
2287 if (status < 0)
2288 break;
2289 }
2290 break;
2291 case FEC_3_4:
2292 transmissionParams |= SC_RA_RAM_OP_PARAM_RATE_3_4;
2293 if (state->type_A) {
2294 status = Write16(state, EC_VD_REG_SET_CODERATE__A, EC_VD_REG_SET_CODERATE_C3_4, 0x0000);
2295 if (status < 0)
2296 break;
2297 }
2298 break;
2299 case FEC_5_6:
2300 transmissionParams |= SC_RA_RAM_OP_PARAM_RATE_5_6;
2301 if (state->type_A) {
2302 status = Write16(state, EC_VD_REG_SET_CODERATE__A, EC_VD_REG_SET_CODERATE_C5_6, 0x0000);
2303 if (status < 0)
2304 break;
2305 }
2306 break;
2307 case FEC_7_8:
2308 transmissionParams |= SC_RA_RAM_OP_PARAM_RATE_7_8;
2309 if (state->type_A) {
2310 status = Write16(state, EC_VD_REG_SET_CODERATE__A, EC_VD_REG_SET_CODERATE_C7_8, 0x0000);
2311 if (status < 0)
2312 break;
2313 }
2314 break;
2315 }
2316 status = status;
2317 if (status < 0)
2318 break;
2319
2320 /* First determine real bandwidth (Hz) */
2321 /* Also set delay for impulse noise cruncher (only A2) */
2322 /* Also set parameters for EC_OC fix, note
2323 EC_OC_REG_TMD_HIL_MAR is changed
2324 by SC for fix for some 8K,1/8 guard but is restored by
2325 InitEC and ResetEC
2326 functions */
2327 switch (p->bandwidth) {
2328 case BANDWIDTH_AUTO:
2329 case BANDWIDTH_8_MHZ:
2330 /* (64/7)*(8/8)*1000000 */
2331 bandwidth = DRXD_BANDWIDTH_8MHZ_IN_HZ;
2332
2333 bandwidthParam = 0;
2334 status = Write16(state,
2335 FE_AG_REG_IND_DEL__A, 50, 0x0000);
2336 break;
2337 case BANDWIDTH_7_MHZ:
2338 /* (64/7)*(7/8)*1000000 */
2339 bandwidth = DRXD_BANDWIDTH_7MHZ_IN_HZ;
2340 bandwidthParam = 0x4807; /*binary:0100 1000 0000 0111 */
2341 status = Write16(state,
2342 FE_AG_REG_IND_DEL__A, 59, 0x0000);
2343 break;
2344 case BANDWIDTH_6_MHZ:
2345 /* (64/7)*(6/8)*1000000 */
2346 bandwidth = DRXD_BANDWIDTH_6MHZ_IN_HZ;
2347 bandwidthParam = 0x0F07; /*binary: 0000 1111 0000 0111 */
2348 status = Write16(state,
2349 FE_AG_REG_IND_DEL__A, 71, 0x0000);
2350 break;
2351 default:
2352 status = -EINVAL;
2353 }
2354 if (status < 0)
2355 break;
2356
2357 status = Write16(state, SC_RA_RAM_BAND__A, bandwidthParam, 0x0000);
2358 if (status < 0)
2359 break;
2360
2361 {
2362 u16 sc_config;
2363 status = Read16(state, SC_RA_RAM_CONFIG__A, &sc_config, 0);
2364 if (status < 0)
2365 break;
2366
2367 /* enable SLAVE mode in 2k 1/32 to
2368 prevent timing change glitches */
2369 if ((p->transmission_mode == TRANSMISSION_MODE_2K) &&
2370 (p->guard_interval == GUARD_INTERVAL_1_32)) {
2371 /* enable slave */
2372 sc_config |= SC_RA_RAM_CONFIG_SLAVE__M;
2373 } else {
2374 /* disable slave */
2375 sc_config &= ~SC_RA_RAM_CONFIG_SLAVE__M;
2376 }
2377 status = Write16(state, SC_RA_RAM_CONFIG__A, sc_config, 0);
2378 if (status < 0)
2379 break;
2380 }
2381
2382 status = SetCfgNoiseCalibration(state, &state->noise_cal);
2383 if (status < 0)
2384 break;
2385
2386 if (state->cscd_state == CSCD_INIT) {
2387 /* switch on SRMM scan in SC */
2388 status = Write16(state, SC_RA_RAM_SAMPLE_RATE_COUNT__A, DRXD_OSCDEV_DO_SCAN, 0x0000);
2389 if (status < 0)
2390 break;
2391/* CHK_ERROR(Write16(SC_RA_RAM_SAMPLE_RATE_STEP__A, DRXD_OSCDEV_STEP, 0x0000));*/
2392 state->cscd_state = CSCD_SET;
2393 }
2394
2395 /* Now compute FE_IF_REG_INCR */
2396 /*((( SysFreq/BandWidth)/2)/2) -1) * 2^23) =>
2397 ((SysFreq / BandWidth) * (2^21) ) - (2^23) */
2398 feIfIncr = MulDiv32(state->sys_clock_freq * 1000,
2399 (1ULL << 21), bandwidth) - (1 << 23);
2400 status = Write16(state, FE_IF_REG_INCR0__A, (u16) (feIfIncr & FE_IF_REG_INCR0__M), 0x0000);
2401 if (status < 0)
2402 break;
2403 status = Write16(state, FE_IF_REG_INCR1__A, (u16) ((feIfIncr >> FE_IF_REG_INCR0__W) & FE_IF_REG_INCR1__M), 0x0000);
2404 if (status < 0)
2405 break;
2406 /* Bandwidth setting done */
2407
2408 /* Mirror & frequency offset */
2409 SetFrequencyShift(state, off, mirrorFreqSpect);
2410
2411 /* Start SC, write channel settings to SC */
2412
2413 /* Enable SC after setting all other parameters */
2414 status = Write16(state, SC_COMM_STATE__A, 0, 0x0000);
2415 if (status < 0)
2416 break;
2417 status = Write16(state, SC_COMM_EXEC__A, 1, 0x0000);
2418 if (status < 0)
2419 break;
2420
2421 /* Write SC parameter registers, operation mode */
2422#if 1
2423 operationMode = (SC_RA_RAM_OP_AUTO_MODE__M |
2424 SC_RA_RAM_OP_AUTO_GUARD__M |
2425 SC_RA_RAM_OP_AUTO_CONST__M |
2426 SC_RA_RAM_OP_AUTO_HIER__M |
2427 SC_RA_RAM_OP_AUTO_RATE__M);
2428#endif
2429 status = SC_SetPrefParamCommand(state, 0x0000, transmissionParams, operationMode);
2430 if (status < 0)
2431 break;
2432
2433 /* Start correct processes to get in lock */
2434 status = SC_ProcStartCommand(state, SC_RA_RAM_PROC_LOCKTRACK, SC_RA_RAM_SW_EVENT_RUN_NMASK__M, SC_RA_RAM_LOCKTRACK_MIN);
2435 if (status < 0)
2436 break;
2437
2438 status = StartOC(state);
2439 if (status < 0)
2440 break;
2441
2442 if (state->operation_mode != OM_Default) {
2443 status = StartDiversity(state);
2444 if (status < 0)
2445 break;
2446 }
2447
2448 state->drxd_state = DRXD_STARTED;
2449 } while (0);
2450
2451 return status;
2452}
2453
2454static int CDRXD(struct drxd_state *state, u32 IntermediateFrequency)
2455{
2456 u32 ulRfAgcOutputLevel = 0xffffffff;
2457 u32 ulRfAgcSettleLevel = 528; /* Optimum value for MT2060 */
2458 u32 ulRfAgcMinLevel = 0; /* Currently unused */
2459 u32 ulRfAgcMaxLevel = DRXD_FE_CTRL_MAX; /* Currently unused */
2460 u32 ulRfAgcSpeed = 0; /* Currently unused */
2461 u32 ulRfAgcMode = 0; /*2; Off */
2462 u32 ulRfAgcR1 = 820;
2463 u32 ulRfAgcR2 = 2200;
2464 u32 ulRfAgcR3 = 150;
2465 u32 ulIfAgcMode = 0; /* Auto */
2466 u32 ulIfAgcOutputLevel = 0xffffffff;
2467 u32 ulIfAgcSettleLevel = 0xffffffff;
2468 u32 ulIfAgcMinLevel = 0xffffffff;
2469 u32 ulIfAgcMaxLevel = 0xffffffff;
2470 u32 ulIfAgcSpeed = 0xffffffff;
2471 u32 ulIfAgcR1 = 820;
2472 u32 ulIfAgcR2 = 2200;
2473 u32 ulIfAgcR3 = 150;
2474 u32 ulClock = state->config.clock;
2475 u32 ulSerialMode = 0;
2476 u32 ulEcOcRegOcModeLop = 4; /* Dynamic DTO source */
2477 u32 ulHiI2cDelay = HI_I2C_DELAY;
2478 u32 ulHiI2cBridgeDelay = HI_I2C_BRIDGE_DELAY;
2479 u32 ulHiI2cPatch = 0;
2480 u32 ulEnvironment = APPENV_PORTABLE;
2481 u32 ulEnvironmentDiversity = APPENV_MOBILE;
2482 u32 ulIFFilter = IFFILTER_SAW;
2483
2484 state->if_agc_cfg.ctrlMode = AGC_CTRL_AUTO;
2485 state->if_agc_cfg.outputLevel = 0;
2486 state->if_agc_cfg.settleLevel = 140;
2487 state->if_agc_cfg.minOutputLevel = 0;
2488 state->if_agc_cfg.maxOutputLevel = 1023;
2489 state->if_agc_cfg.speed = 904;
2490
2491 if (ulIfAgcMode == 1 && ulIfAgcOutputLevel <= DRXD_FE_CTRL_MAX) {
2492 state->if_agc_cfg.ctrlMode = AGC_CTRL_USER;
2493 state->if_agc_cfg.outputLevel = (u16) (ulIfAgcOutputLevel);
2494 }
2495
2496 if (ulIfAgcMode == 0 &&
2497 ulIfAgcSettleLevel <= DRXD_FE_CTRL_MAX &&
2498 ulIfAgcMinLevel <= DRXD_FE_CTRL_MAX &&
2499 ulIfAgcMaxLevel <= DRXD_FE_CTRL_MAX &&
2500 ulIfAgcSpeed <= DRXD_FE_CTRL_MAX) {
2501 state->if_agc_cfg.ctrlMode = AGC_CTRL_AUTO;
2502 state->if_agc_cfg.settleLevel = (u16) (ulIfAgcSettleLevel);
2503 state->if_agc_cfg.minOutputLevel = (u16) (ulIfAgcMinLevel);
2504 state->if_agc_cfg.maxOutputLevel = (u16) (ulIfAgcMaxLevel);
2505 state->if_agc_cfg.speed = (u16) (ulIfAgcSpeed);
2506 }
2507
2508 state->if_agc_cfg.R1 = (u16) (ulIfAgcR1);
2509 state->if_agc_cfg.R2 = (u16) (ulIfAgcR2);
2510 state->if_agc_cfg.R3 = (u16) (ulIfAgcR3);
2511
2512 state->rf_agc_cfg.R1 = (u16) (ulRfAgcR1);
2513 state->rf_agc_cfg.R2 = (u16) (ulRfAgcR2);
2514 state->rf_agc_cfg.R3 = (u16) (ulRfAgcR3);
2515
2516 state->rf_agc_cfg.ctrlMode = AGC_CTRL_AUTO;
2517 /* rest of the RFAgcCfg structure currently unused */
2518 if (ulRfAgcMode == 1 && ulRfAgcOutputLevel <= DRXD_FE_CTRL_MAX) {
2519 state->rf_agc_cfg.ctrlMode = AGC_CTRL_USER;
2520 state->rf_agc_cfg.outputLevel = (u16) (ulRfAgcOutputLevel);
2521 }
2522
2523 if (ulRfAgcMode == 0 &&
2524 ulRfAgcSettleLevel <= DRXD_FE_CTRL_MAX &&
2525 ulRfAgcMinLevel <= DRXD_FE_CTRL_MAX &&
2526 ulRfAgcMaxLevel <= DRXD_FE_CTRL_MAX &&
2527 ulRfAgcSpeed <= DRXD_FE_CTRL_MAX) {
2528 state->rf_agc_cfg.ctrlMode = AGC_CTRL_AUTO;
2529 state->rf_agc_cfg.settleLevel = (u16) (ulRfAgcSettleLevel);
2530 state->rf_agc_cfg.minOutputLevel = (u16) (ulRfAgcMinLevel);
2531 state->rf_agc_cfg.maxOutputLevel = (u16) (ulRfAgcMaxLevel);
2532 state->rf_agc_cfg.speed = (u16) (ulRfAgcSpeed);
2533 }
2534
2535 if (ulRfAgcMode == 2)
2536 state->rf_agc_cfg.ctrlMode = AGC_CTRL_OFF;
2537
2538 if (ulEnvironment <= 2)
2539 state->app_env_default = (enum app_env)
2540 (ulEnvironment);
2541 if (ulEnvironmentDiversity <= 2)
2542 state->app_env_diversity = (enum app_env)
2543 (ulEnvironmentDiversity);
2544
2545 if (ulIFFilter == IFFILTER_DISCRETE) {
2546 /* discrete filter */
2547 state->noise_cal.cpOpt = 0;
2548 state->noise_cal.cpNexpOfs = 40;
2549 state->noise_cal.tdCal2k = -40;
2550 state->noise_cal.tdCal8k = -24;
2551 } else {
2552 /* SAW filter */
2553 state->noise_cal.cpOpt = 1;
2554 state->noise_cal.cpNexpOfs = 0;
2555 state->noise_cal.tdCal2k = -21;
2556 state->noise_cal.tdCal8k = -24;
2557 }
2558 state->m_EcOcRegOcModeLop = (u16) (ulEcOcRegOcModeLop);
2559
2560 state->chip_adr = (state->config.demod_address << 1) | 1;
2561 switch (ulHiI2cPatch) {
2562 case 1:
2563 state->m_HiI2cPatch = DRXD_HiI2cPatch_1;
2564 break;
2565 case 3:
2566 state->m_HiI2cPatch = DRXD_HiI2cPatch_3;
2567 break;
2568 default:
2569 state->m_HiI2cPatch = NULL;
2570 }
2571
2572 /* modify tuner and clock attributes */
2573 state->intermediate_freq = (u16) (IntermediateFrequency / 1000);
2574 /* expected system clock frequency in kHz */
2575 state->expected_sys_clock_freq = 48000;
2576 /* real system clock frequency in kHz */
2577 state->sys_clock_freq = 48000;
2578 state->osc_clock_freq = (u16) ulClock;
2579 state->osc_clock_deviation = 0;
2580 state->cscd_state = CSCD_INIT;
2581 state->drxd_state = DRXD_UNINITIALIZED;
2582
2583 state->PGA = 0;
2584 state->type_A = 0;
2585 state->tuner_mirrors = 0;
2586
2587 /* modify MPEG output attributes */
2588 state->insert_rs_byte = state->config.insert_rs_byte;
2589 state->enable_parallel = (ulSerialMode != 1);
2590
2591 /* Timing div, 250ns/Psys */
2592 /* Timing div, = ( delay (nano seconds) * sysclk (kHz) )/ 1000 */
2593
2594 state->hi_cfg_timing_div = (u16) ((state->sys_clock_freq / 1000) *
2595 ulHiI2cDelay) / 1000;
2596 /* Bridge delay, uses oscilator clock */
2597 /* Delay = ( delay (nano seconds) * oscclk (kHz) )/ 1000 */
2598 state->hi_cfg_bridge_delay = (u16) ((state->osc_clock_freq / 1000) *
2599 ulHiI2cBridgeDelay) / 1000;
2600
2601 state->m_FeAgRegAgPwd = DRXD_DEF_AG_PWD_CONSUMER;
2602 /* state->m_FeAgRegAgPwd = DRXD_DEF_AG_PWD_PRO; */
2603 state->m_FeAgRegAgAgcSio = DRXD_DEF_AG_AGC_SIO;
2604 return 0;
2605}
2606
2607int DRXD_init(struct drxd_state *state, const u8 * fw, u32 fw_size)
2608{
2609 int status = 0;
2610 u32 driverVersion;
2611
2612 if (state->init_done)
2613 return 0;
2614
2615 CDRXD(state, state->config.IF ? state->config.IF : 36000000);
2616
2617 do {
2618 state->operation_mode = OM_Default;
2619
2620 status = SetDeviceTypeId(state);
2621 if (status < 0)
2622 break;
2623
2624 /* Apply I2c address patch to B1 */
2625 if (!state->type_A && state->m_HiI2cPatch != NULL)
2626 status = WriteTable(state, state->m_HiI2cPatch);
2627 if (status < 0)
2628 break;
2629
2630 if (state->type_A) {
2631 /* HI firmware patch for UIO readout,
2632 avoid clearing of result register */
2633 status = Write16(state, 0x43012D, 0x047f, 0);
2634 if (status < 0)
2635 break;
2636 }
2637
2638 status = HI_ResetCommand(state);
2639 if (status < 0)
2640 break;
2641
2642 status = StopAllProcessors(state);
2643 if (status < 0)
2644 break;
2645 status = InitCC(state);
2646 if (status < 0)
2647 break;
2648
2649 state->osc_clock_deviation = 0;
2650
2651 if (state->config.osc_deviation)
2652 state->osc_clock_deviation =
2653 state->config.osc_deviation(state->priv, 0, 0);
2654 {
2655 /* Handle clock deviation */
2656 s32 devB;
2657 s32 devA = (s32) (state->osc_clock_deviation) *
2658 (s32) (state->expected_sys_clock_freq);
2659 /* deviation in kHz */
2660 s32 deviation = (devA / (1000000L));
2661 /* rounding, signed */
2662 if (devA > 0)
2663 devB = (2);
2664 else
2665 devB = (-2);
2666 if ((devB * (devA % 1000000L) > 1000000L)) {
2667 /* add +1 or -1 */
2668 deviation += (devB / 2);
2669 }
2670
2671 state->sys_clock_freq =
2672 (u16) ((state->expected_sys_clock_freq) +
2673 deviation);
2674 }
2675 status = InitHI(state);
2676 if (status < 0)
2677 break;
2678 status = InitAtomicRead(state);
2679 if (status < 0)
2680 break;
2681
2682 status = EnableAndResetMB(state);
2683 if (status < 0)
2684 break;
2685 if (state->type_A)
2686 status = ResetCEFR(state);
2687 if (status < 0)
2688 break;
2689
2690 if (fw) {
2691 status = DownloadMicrocode(state, fw, fw_size);
2692 if (status < 0)
2693 break;
2694 } else {
2695 status = DownloadMicrocode(state, state->microcode, state->microcode_length);
2696 if (status < 0)
2697 break;
2698 }
2699
2700 if (state->PGA) {
2701 state->m_FeAgRegAgPwd = DRXD_DEF_AG_PWD_PRO;
2702 SetCfgPga(state, 0); /* PGA = 0 dB */
2703 } else {
2704 state->m_FeAgRegAgPwd = DRXD_DEF_AG_PWD_CONSUMER;
2705 }
2706
2707 state->m_FeAgRegAgAgcSio = DRXD_DEF_AG_AGC_SIO;
2708
2709 status = InitFE(state);
2710 if (status < 0)
2711 break;
2712 status = InitFT(state);
2713 if (status < 0)
2714 break;
2715 status = InitCP(state);
2716 if (status < 0)
2717 break;
2718 status = InitCE(state);
2719 if (status < 0)
2720 break;
2721 status = InitEQ(state);
2722 if (status < 0)
2723 break;
2724 status = InitEC(state);
2725 if (status < 0)
2726 break;
2727 status = InitSC(state);
2728 if (status < 0)
2729 break;
2730
2731 status = SetCfgIfAgc(state, &state->if_agc_cfg);
2732 if (status < 0)
2733 break;
2734 status = SetCfgRfAgc(state, &state->rf_agc_cfg);
2735 if (status < 0)
2736 break;
2737
2738 state->cscd_state = CSCD_INIT;
2739 status = Write16(state, SC_COMM_EXEC__A, SC_COMM_EXEC_CTL_STOP, 0);
2740 if (status < 0)
2741 break;
2742 status = Write16(state, LC_COMM_EXEC__A, SC_COMM_EXEC_CTL_STOP, 0);
2743 if (status < 0)
2744 break;
2745
2746 driverVersion = (((VERSION_MAJOR / 10) << 4) +
2747 (VERSION_MAJOR % 10)) << 24;
2748 driverVersion += (((VERSION_MINOR / 10) << 4) +
2749 (VERSION_MINOR % 10)) << 16;
2750 driverVersion += ((VERSION_PATCH / 1000) << 12) +
2751 ((VERSION_PATCH / 100) << 8) +
2752 ((VERSION_PATCH / 10) << 4) + (VERSION_PATCH % 10);
2753
2754 status = Write32(state, SC_RA_RAM_DRIVER_VERSION__AX, driverVersion, 0);
2755 if (status < 0)
2756 break;
2757
2758 status = StopOC(state);
2759 if (status < 0)
2760 break;
2761
2762 state->drxd_state = DRXD_STOPPED;
2763 state->init_done = 1;
2764 status = 0;
2765 } while (0);
2766 return status;
2767}
2768
2769int DRXD_status(struct drxd_state *state, u32 * pLockStatus)
2770{
2771 DRX_GetLockStatus(state, pLockStatus);
2772
2773 /*if (*pLockStatus&DRX_LOCK_MPEG) */
2774 if (*pLockStatus & DRX_LOCK_FEC) {
2775 ConfigureMPEGOutput(state, 1);
2776 /* Get status again, in case we have MPEG lock now */
2777 /*DRX_GetLockStatus(state, pLockStatus); */
2778 }
2779
2780 return 0;
2781}
2782
2783/****************************************************************************/
2784/****************************************************************************/
2785/****************************************************************************/
2786
2787static int drxd_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
2788{
2789 struct drxd_state *state = fe->demodulator_priv;
2790 u32 value;
2791 int res;
2792
2793 res = ReadIFAgc(state, &value);
2794 if (res < 0)
2795 *strength = 0;
2796 else
2797 *strength = 0xffff - (value << 4);
2798 return 0;
2799}
2800
2801static int drxd_read_status(struct dvb_frontend *fe, fe_status_t * status)
2802{
2803 struct drxd_state *state = fe->demodulator_priv;
2804 u32 lock;
2805
2806 DRXD_status(state, &lock);
2807 *status = 0;
2808 /* No MPEG lock in V255 firmware, bug ? */
2809#if 1
2810 if (lock & DRX_LOCK_MPEG)
2811 *status |= FE_HAS_LOCK;
2812#else
2813 if (lock & DRX_LOCK_FEC)
2814 *status |= FE_HAS_LOCK;
2815#endif
2816 if (lock & DRX_LOCK_FEC)
2817 *status |= FE_HAS_VITERBI | FE_HAS_SYNC;
2818 if (lock & DRX_LOCK_DEMOD)
2819 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
2820
2821 return 0;
2822}
2823
2824static int drxd_init(struct dvb_frontend *fe)
2825{
2826 struct drxd_state *state = fe->demodulator_priv;
2827 int err = 0;
2828
2829/* if (request_firmware(&state->fw, "drxd.fw", state->dev)<0) */
2830 return DRXD_init(state, 0, 0);
2831
2832 err = DRXD_init(state, state->fw->data, state->fw->size);
2833 release_firmware(state->fw);
2834 return err;
2835}
2836
2837int drxd_config_i2c(struct dvb_frontend *fe, int onoff)
2838{
2839 struct drxd_state *state = fe->demodulator_priv;
2840
2841 if (state->config.disable_i2c_gate_ctrl == 1)
2842 return 0;
2843
2844 return DRX_ConfigureI2CBridge(state, onoff);
2845}
2846EXPORT_SYMBOL(drxd_config_i2c);
2847
2848static int drxd_get_tune_settings(struct dvb_frontend *fe,
2849 struct dvb_frontend_tune_settings *sets)
2850{
2851 sets->min_delay_ms = 10000;
2852 sets->max_drift = 0;
2853 sets->step_size = 0;
2854 return 0;
2855}
2856
2857static int drxd_read_ber(struct dvb_frontend *fe, u32 * ber)
2858{
2859 *ber = 0;
2860 return 0;
2861}
2862
2863static int drxd_read_snr(struct dvb_frontend *fe, u16 * snr)
2864{
2865 *snr = 0;
2866 return 0;
2867}
2868
2869static int drxd_read_ucblocks(struct dvb_frontend *fe, u32 * ucblocks)
2870{
2871 *ucblocks = 0;
2872 return 0;
2873}
2874
2875static int drxd_sleep(struct dvb_frontend *fe)
2876{
2877 struct drxd_state *state = fe->demodulator_priv;
2878
2879 ConfigureMPEGOutput(state, 0);
2880 return 0;
2881}
2882
2883static int drxd_get_frontend(struct dvb_frontend *fe,
2884 struct dvb_frontend_parameters *param)
2885{
2886 return 0;
2887}
2888
2889static int drxd_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
2890{
2891 return drxd_config_i2c(fe, enable);
2892}
2893
2894static int drxd_set_frontend(struct dvb_frontend *fe,
2895 struct dvb_frontend_parameters *param)
2896{
2897 struct drxd_state *state = fe->demodulator_priv;
2898 s32 off = 0;
2899
2900 state->param = *param;
2901 DRX_Stop(state);
2902
2903 if (fe->ops.tuner_ops.set_params) {
2904 fe->ops.tuner_ops.set_params(fe, param);
2905 if (fe->ops.i2c_gate_ctrl)
2906 fe->ops.i2c_gate_ctrl(fe, 0);
2907 }
2908
2909 /* FIXME: move PLL drivers */
2910 if (state->config.pll_set &&
2911 state->config.pll_set(state->priv, param,
2912 state->config.pll_address,
2913 state->config.demoda_address, &off) < 0) {
2914 printk(KERN_ERR "Error in pll_set\n");
2915 return -1;
2916 }
2917
2918 msleep(200);
2919
2920 return DRX_Start(state, off);
2921}
2922
2923static void drxd_release(struct dvb_frontend *fe)
2924{
2925 struct drxd_state *state = fe->demodulator_priv;
2926
2927 kfree(state);
2928}
2929
2930static struct dvb_frontend_ops drxd_ops = {
2931
2932 .info = {
2933 .name = "Micronas DRXD DVB-T",
2934 .type = FE_OFDM,
2935 .frequency_min = 47125000,
2936 .frequency_max = 855250000,
2937 .frequency_stepsize = 166667,
2938 .frequency_tolerance = 0,
2939 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
2940 FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
2941 FE_CAN_FEC_AUTO |
2942 FE_CAN_QAM_16 | FE_CAN_QAM_64 |
2943 FE_CAN_QAM_AUTO |
2944 FE_CAN_TRANSMISSION_MODE_AUTO |
2945 FE_CAN_GUARD_INTERVAL_AUTO |
2946 FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER | FE_CAN_MUTE_TS},
2947
2948 .release = drxd_release,
2949 .init = drxd_init,
2950 .sleep = drxd_sleep,
2951 .i2c_gate_ctrl = drxd_i2c_gate_ctrl,
2952
2953 .set_frontend = drxd_set_frontend,
2954 .get_frontend = drxd_get_frontend,
2955 .get_tune_settings = drxd_get_tune_settings,
2956
2957 .read_status = drxd_read_status,
2958 .read_ber = drxd_read_ber,
2959 .read_signal_strength = drxd_read_signal_strength,
2960 .read_snr = drxd_read_snr,
2961 .read_ucblocks = drxd_read_ucblocks,
2962};
2963
2964struct dvb_frontend *drxd_attach(const struct drxd_config *config,
2965 void *priv, struct i2c_adapter *i2c,
2966 struct device *dev)
2967{
2968 struct drxd_state *state = NULL;
2969
2970 state = kmalloc(sizeof(struct drxd_state), GFP_KERNEL);
2971 if (!state)
2972 return NULL;
2973 memset(state, 0, sizeof(*state));
2974
2975 memcpy(&state->ops, &drxd_ops, sizeof(struct dvb_frontend_ops));
2976 state->dev = dev;
2977 state->config = *config;
2978 state->i2c = i2c;
2979 state->priv = priv;
2980
2981 mutex_init(&state->mutex);
2982
2983 if (Read16(state, 0, 0, 0) < 0)
2984 goto error;
2985
2986 memcpy(&state->frontend.ops, &drxd_ops,
2987 sizeof(struct dvb_frontend_ops));
2988 state->frontend.demodulator_priv = state;
2989 ConfigureMPEGOutput(state, 0);
2990 return &state->frontend;
2991
2992error:
2993 printk(KERN_ERR "drxd: not found\n");
2994 kfree(state);
2995 return NULL;
2996}
2997EXPORT_SYMBOL(drxd_attach);
2998
2999MODULE_DESCRIPTION("DRXD driver");
3000MODULE_AUTHOR("Micronas");
3001MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/drxd_map_firm.h b/drivers/media/dvb/frontends/drxd_map_firm.h
new file mode 100644
index 000000000000..6bc553abf215
--- /dev/null
+++ b/drivers/media/dvb/frontends/drxd_map_firm.h
@@ -0,0 +1,1013 @@
1/*
2 * drx3973d_map_firm.h
3 *
4 * Copyright (C) 2006-2007 Micronas
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 only, as published by the Free Software Foundation.
9 *
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA
21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
22 */
23
24#ifndef __DRX3973D_MAP__H__
25#define __DRX3973D_MAP__H__
26
27/*
28 * Note: originally, this file contained 12000+ lines of data
29 * Probably a few lines for every firwmare assembler instruction. However,
30 * only a few defines were actually used. So, removed all uneeded lines.
31 * If ever needed, the other lines can be easily obtained via git history.
32 */
33
34#define HI_COMM_EXEC__A 0x400000
35#define HI_COMM_MB__A 0x400002
36#define HI_CT_REG_COMM_STATE__A 0x410001
37#define HI_RA_RAM_SRV_RES__A 0x420031
38#define HI_RA_RAM_SRV_CMD__A 0x420032
39#define HI_RA_RAM_SRV_CMD_RESET 0x2
40#define HI_RA_RAM_SRV_CMD_CONFIG 0x3
41#define HI_RA_RAM_SRV_CMD_EXECUTE 0x6
42#define HI_RA_RAM_SRV_RST_KEY__A 0x420033
43#define HI_RA_RAM_SRV_RST_KEY_ACT 0x3973
44#define HI_RA_RAM_SRV_CFG_KEY__A 0x420033
45#define HI_RA_RAM_SRV_CFG_DIV__A 0x420034
46#define HI_RA_RAM_SRV_CFG_BDL__A 0x420035
47#define HI_RA_RAM_SRV_CFG_WUP__A 0x420036
48#define HI_RA_RAM_SRV_CFG_ACT__A 0x420037
49#define HI_RA_RAM_SRV_CFG_ACT_SLV0_ON 0x1
50#define HI_RA_RAM_SRV_CFG_ACT_BRD__M 0x4
51#define HI_RA_RAM_SRV_CFG_ACT_BRD_OFF 0x0
52#define HI_RA_RAM_SRV_CFG_ACT_BRD_ON 0x4
53#define HI_RA_RAM_SRV_CFG_ACT_PWD_EXE 0x8
54#define HI_RA_RAM_USR_BEGIN__A 0x420040
55#define HI_IF_RAM_TRP_BPT0__AX 0x430000
56#define HI_IF_RAM_USR_BEGIN__A 0x430200
57#define SC_COMM_EXEC__A 0x800000
58#define SC_COMM_EXEC_CTL_STOP 0x0
59#define SC_COMM_STATE__A 0x800001
60#define SC_RA_RAM_PARAM0__A 0x820040
61#define SC_RA_RAM_PARAM1__A 0x820041
62#define SC_RA_RAM_CMD_ADDR__A 0x820042
63#define SC_RA_RAM_CMD__A 0x820043
64#define SC_RA_RAM_CMD_PROC_START 0x1
65#define SC_RA_RAM_CMD_SET_PREF_PARAM 0x3
66#define SC_RA_RAM_CMD_GET_OP_PARAM 0x5
67#define SC_RA_RAM_SW_EVENT_RUN_NMASK__M 0x1
68#define SC_RA_RAM_LOCKTRACK_MIN 0x1
69#define SC_RA_RAM_OP_PARAM_MODE_2K 0x0
70#define SC_RA_RAM_OP_PARAM_MODE_8K 0x1
71#define SC_RA_RAM_OP_PARAM_GUARD_32 0x0
72#define SC_RA_RAM_OP_PARAM_GUARD_16 0x4
73#define SC_RA_RAM_OP_PARAM_GUARD_8 0x8
74#define SC_RA_RAM_OP_PARAM_GUARD_4 0xC
75#define SC_RA_RAM_OP_PARAM_CONST_QPSK 0x0
76#define SC_RA_RAM_OP_PARAM_CONST_QAM16 0x10
77#define SC_RA_RAM_OP_PARAM_CONST_QAM64 0x20
78#define SC_RA_RAM_OP_PARAM_HIER_NO 0x0
79#define SC_RA_RAM_OP_PARAM_HIER_A1 0x40
80#define SC_RA_RAM_OP_PARAM_HIER_A2 0x80
81#define SC_RA_RAM_OP_PARAM_HIER_A4 0xC0
82#define SC_RA_RAM_OP_PARAM_RATE_1_2 0x0
83#define SC_RA_RAM_OP_PARAM_RATE_2_3 0x200
84#define SC_RA_RAM_OP_PARAM_RATE_3_4 0x400
85#define SC_RA_RAM_OP_PARAM_RATE_5_6 0x600
86#define SC_RA_RAM_OP_PARAM_RATE_7_8 0x800
87#define SC_RA_RAM_OP_PARAM_PRIO_HI 0x0
88#define SC_RA_RAM_OP_PARAM_PRIO_LO 0x1000
89#define SC_RA_RAM_OP_AUTO_MODE__M 0x1
90#define SC_RA_RAM_OP_AUTO_GUARD__M 0x2
91#define SC_RA_RAM_OP_AUTO_CONST__M 0x4
92#define SC_RA_RAM_OP_AUTO_HIER__M 0x8
93#define SC_RA_RAM_OP_AUTO_RATE__M 0x10
94#define SC_RA_RAM_LOCK__A 0x82004B
95#define SC_RA_RAM_LOCK_DEMOD__M 0x1
96#define SC_RA_RAM_LOCK_FEC__M 0x2
97#define SC_RA_RAM_LOCK_MPEG__M 0x4
98#define SC_RA_RAM_BE_OPT_ENA__A 0x82004C
99#define SC_RA_RAM_BE_OPT_ENA_CP_OPT 0x1
100#define SC_RA_RAM_BE_OPT_DELAY__A 0x82004D
101#define SC_RA_RAM_CONFIG__A 0x820050
102#define SC_RA_RAM_CONFIG_FR_ENABLE__M 0x4
103#define SC_RA_RAM_CONFIG_FREQSCAN__M 0x10
104#define SC_RA_RAM_CONFIG_SLAVE__M 0x20
105#define SC_RA_RAM_IF_SAVE__AX 0x82008E
106#define SC_RA_RAM_IR_COARSE_2K_LENGTH__A 0x8200D1
107#define SC_RA_RAM_IR_COARSE_2K_LENGTH__PRE 0x9
108#define SC_RA_RAM_IR_COARSE_2K_FREQINC__A 0x8200D2
109#define SC_RA_RAM_IR_COARSE_2K_FREQINC__PRE 0x4
110#define SC_RA_RAM_IR_COARSE_2K_KAISINC__A 0x8200D3
111#define SC_RA_RAM_IR_COARSE_2K_KAISINC__PRE 0x100
112#define SC_RA_RAM_IR_COARSE_8K_LENGTH__A 0x8200D4
113#define SC_RA_RAM_IR_COARSE_8K_LENGTH__PRE 0x8
114#define SC_RA_RAM_IR_COARSE_8K_FREQINC__A 0x8200D5
115#define SC_RA_RAM_IR_COARSE_8K_FREQINC__PRE 0x8
116#define SC_RA_RAM_IR_COARSE_8K_KAISINC__A 0x8200D6
117#define SC_RA_RAM_IR_COARSE_8K_KAISINC__PRE 0x200
118#define SC_RA_RAM_IR_FINE_2K_LENGTH__A 0x8200D7
119#define SC_RA_RAM_IR_FINE_2K_LENGTH__PRE 0x9
120#define SC_RA_RAM_IR_FINE_2K_FREQINC__A 0x8200D8
121#define SC_RA_RAM_IR_FINE_2K_FREQINC__PRE 0x4
122#define SC_RA_RAM_IR_FINE_2K_KAISINC__A 0x8200D9
123#define SC_RA_RAM_IR_FINE_2K_KAISINC__PRE 0x100
124#define SC_RA_RAM_IR_FINE_8K_LENGTH__A 0x8200DA
125#define SC_RA_RAM_IR_FINE_8K_LENGTH__PRE 0xB
126#define SC_RA_RAM_IR_FINE_8K_FREQINC__A 0x8200DB
127#define SC_RA_RAM_IR_FINE_8K_FREQINC__PRE 0x1
128#define SC_RA_RAM_IR_FINE_8K_KAISINC__A 0x8200DC
129#define SC_RA_RAM_IR_FINE_8K_KAISINC__PRE 0x40
130#define SC_RA_RAM_ECHO_SHIFT_LIM__A 0x8200DD
131#define SC_RA_RAM_SAMPLE_RATE_COUNT__A 0x8200E8
132#define SC_RA_RAM_SAMPLE_RATE_STEP__A 0x8200E9
133#define SC_RA_RAM_BAND__A 0x8200EC
134#define SC_RA_RAM_LC_ABS_2K__A 0x8200F4
135#define SC_RA_RAM_LC_ABS_2K__PRE 0x1F
136#define SC_RA_RAM_LC_ABS_8K__A 0x8200F5
137#define SC_RA_RAM_LC_ABS_8K__PRE 0x1F
138#define SC_RA_RAM_EQ_IS_GAIN_UNKNOWN_MAN__PRE 0x1D6
139#define SC_RA_RAM_EQ_IS_GAIN_UNKNOWN_EXP__PRE 0x4
140#define SC_RA_RAM_EQ_IS_GAIN_QPSK_MAN__PRE 0x1BB
141#define SC_RA_RAM_EQ_IS_GAIN_QPSK_EXP__PRE 0x5
142#define SC_RA_RAM_EQ_IS_GAIN_16QAM_MAN__PRE 0x1EF
143#define SC_RA_RAM_EQ_IS_GAIN_16QAM_EXP__PRE 0x5
144#define SC_RA_RAM_EQ_IS_GAIN_16QAM_A2_MAN__PRE 0x15E
145#define SC_RA_RAM_EQ_IS_GAIN_16QAM_A2_EXP__PRE 0x5
146#define SC_RA_RAM_EQ_IS_GAIN_16QAM_A4_MAN__PRE 0x11A
147#define SC_RA_RAM_EQ_IS_GAIN_16QAM_A4_EXP__PRE 0x6
148#define SC_RA_RAM_EQ_IS_GAIN_64QAM_MAN__PRE 0x1FB
149#define SC_RA_RAM_EQ_IS_GAIN_64QAM_EXP__PRE 0x5
150#define SC_RA_RAM_EQ_IS_GAIN_64QAM_A2_MAN__PRE 0x12F
151#define SC_RA_RAM_EQ_IS_GAIN_64QAM_A2_EXP__PRE 0x5
152#define SC_RA_RAM_EQ_IS_GAIN_64QAM_A4_MAN__PRE 0x197
153#define SC_RA_RAM_EQ_IS_GAIN_64QAM_A4_EXP__PRE 0x5
154#define SC_RA_RAM_DRIVER_VERSION__AX 0x8201FE
155#define SC_RA_RAM_PROC_LOCKTRACK 0x0
156#define FE_COMM_EXEC__A 0xC00000
157#define FE_AD_REG_COMM_EXEC__A 0xC10000
158#define FE_AD_REG_FDB_IN__A 0xC10012
159#define FE_AD_REG_PD__A 0xC10013
160#define FE_AD_REG_INVEXT__A 0xC10014
161#define FE_AD_REG_CLKNEG__A 0xC10015
162#define FE_AG_REG_COMM_EXEC__A 0xC20000
163#define FE_AG_REG_AG_MODE_LOP__A 0xC20010
164#define FE_AG_REG_AG_MODE_LOP_MODE_4__M 0x10
165#define FE_AG_REG_AG_MODE_LOP_MODE_4_STATIC 0x0
166#define FE_AG_REG_AG_MODE_LOP_MODE_4_DYNAMIC 0x10
167#define FE_AG_REG_AG_MODE_LOP_MODE_5__M 0x20
168#define FE_AG_REG_AG_MODE_LOP_MODE_5_STATIC 0x0
169#define FE_AG_REG_AG_MODE_LOP_MODE_C__M 0x1000
170#define FE_AG_REG_AG_MODE_LOP_MODE_C_STATIC 0x0
171#define FE_AG_REG_AG_MODE_LOP_MODE_C_DYNAMIC 0x1000
172#define FE_AG_REG_AG_MODE_LOP_MODE_E__M 0x4000
173#define FE_AG_REG_AG_MODE_LOP_MODE_E_STATIC 0x0
174#define FE_AG_REG_AG_MODE_LOP_MODE_E_DYNAMIC 0x4000
175#define FE_AG_REG_AG_MODE_HIP__A 0xC20011
176#define FE_AG_REG_AG_PGA_MODE__A 0xC20012
177#define FE_AG_REG_AG_PGA_MODE_PFY_PCY_AFY_REN 0x0
178#define FE_AG_REG_AG_PGA_MODE_PFN_PCN_AFY_REN 0x1
179#define FE_AG_REG_AG_AGC_SIO__A 0xC20013
180#define FE_AG_REG_AG_AGC_SIO_AGC_SIO_2__M 0x2
181#define FE_AG_REG_AG_AGC_SIO_AGC_SIO_2_OUTPUT 0x0
182#define FE_AG_REG_AG_AGC_SIO_AGC_SIO_2_INPUT 0x2
183#define FE_AG_REG_AG_PWD__A 0xC20015
184#define FE_AG_REG_AG_PWD_PWD_PD2__M 0x2
185#define FE_AG_REG_AG_PWD_PWD_PD2_DISABLE 0x0
186#define FE_AG_REG_AG_PWD_PWD_PD2_ENABLE 0x2
187#define FE_AG_REG_DCE_AUR_CNT__A 0xC20016
188#define FE_AG_REG_DCE_RUR_CNT__A 0xC20017
189#define FE_AG_REG_ACE_AUR_CNT__A 0xC2001A
190#define FE_AG_REG_ACE_RUR_CNT__A 0xC2001B
191#define FE_AG_REG_CDR_RUR_CNT__A 0xC20020
192#define FE_AG_REG_EGC_RUR_CNT__A 0xC20024
193#define FE_AG_REG_EGC_SET_LVL__A 0xC20025
194#define FE_AG_REG_EGC_SET_LVL__M 0x1FF
195#define FE_AG_REG_EGC_FLA_RGN__A 0xC20026
196#define FE_AG_REG_EGC_SLO_RGN__A 0xC20027
197#define FE_AG_REG_EGC_JMP_PSN__A 0xC20028
198#define FE_AG_REG_EGC_FLA_INC__A 0xC20029
199#define FE_AG_REG_EGC_FLA_DEC__A 0xC2002A
200#define FE_AG_REG_EGC_SLO_INC__A 0xC2002B
201#define FE_AG_REG_EGC_SLO_DEC__A 0xC2002C
202#define FE_AG_REG_EGC_FAS_INC__A 0xC2002D
203#define FE_AG_REG_EGC_FAS_DEC__A 0xC2002E
204#define FE_AG_REG_PM1_AGC_WRI__A 0xC20030
205#define FE_AG_REG_PM1_AGC_WRI__M 0x7FF
206#define FE_AG_REG_GC1_AGC_RIC__A 0xC20031
207#define FE_AG_REG_GC1_AGC_OFF__A 0xC20032
208#define FE_AG_REG_GC1_AGC_MAX__A 0xC20033
209#define FE_AG_REG_GC1_AGC_MIN__A 0xC20034
210#define FE_AG_REG_GC1_AGC_DAT__A 0xC20035
211#define FE_AG_REG_GC1_AGC_DAT__M 0x3FF
212#define FE_AG_REG_PM2_AGC_WRI__A 0xC20036
213#define FE_AG_REG_IND_WIN__A 0xC2003C
214#define FE_AG_REG_IND_THD_LOL__A 0xC2003D
215#define FE_AG_REG_IND_THD_HIL__A 0xC2003E
216#define FE_AG_REG_IND_DEL__A 0xC2003F
217#define FE_AG_REG_IND_PD1_WRI__A 0xC20040
218#define FE_AG_REG_PDA_AUR_CNT__A 0xC20041
219#define FE_AG_REG_PDA_RUR_CNT__A 0xC20042
220#define FE_AG_REG_PDA_AVE_DAT__A 0xC20043
221#define FE_AG_REG_PDC_RUR_CNT__A 0xC20044
222#define FE_AG_REG_PDC_SET_LVL__A 0xC20045
223#define FE_AG_REG_PDC_FLA_RGN__A 0xC20046
224#define FE_AG_REG_PDC_JMP_PSN__A 0xC20047
225#define FE_AG_REG_PDC_FLA_STP__A 0xC20048
226#define FE_AG_REG_PDC_SLO_STP__A 0xC20049
227#define FE_AG_REG_PDC_PD2_WRI__A 0xC2004A
228#define FE_AG_REG_PDC_MAP_DAT__A 0xC2004B
229#define FE_AG_REG_PDC_MAX__A 0xC2004C
230#define FE_AG_REG_TGA_AUR_CNT__A 0xC2004D
231#define FE_AG_REG_TGA_RUR_CNT__A 0xC2004E
232#define FE_AG_REG_TGA_AVE_DAT__A 0xC2004F
233#define FE_AG_REG_TGC_RUR_CNT__A 0xC20050
234#define FE_AG_REG_TGC_SET_LVL__A 0xC20051
235#define FE_AG_REG_TGC_SET_LVL__M 0x3F
236#define FE_AG_REG_TGC_FLA_RGN__A 0xC20052
237#define FE_AG_REG_TGC_JMP_PSN__A 0xC20053
238#define FE_AG_REG_TGC_FLA_STP__A 0xC20054
239#define FE_AG_REG_TGC_SLO_STP__A 0xC20055
240#define FE_AG_REG_TGC_MAP_DAT__A 0xC20056
241#define FE_AG_REG_FGA_AUR_CNT__A 0xC20057
242#define FE_AG_REG_FGA_RUR_CNT__A 0xC20058
243#define FE_AG_REG_FGM_WRI__A 0xC20061
244#define FE_AG_REG_BGC_FGC_WRI__A 0xC20068
245#define FE_AG_REG_BGC_CGC_WRI__A 0xC20069
246#define FE_FS_REG_COMM_EXEC__A 0xC30000
247#define FE_FS_REG_ADD_INC_LOP__A 0xC30010
248#define FE_FD_REG_COMM_EXEC__A 0xC40000
249#define FE_FD_REG_SCL__A 0xC40010
250#define FE_FD_REG_MAX_LEV__A 0xC40011
251#define FE_FD_REG_NR__A 0xC40012
252#define FE_FD_REG_MEAS_VAL__A 0xC40014
253#define FE_IF_REG_COMM_EXEC__A 0xC50000
254#define FE_IF_REG_INCR0__A 0xC50010
255#define FE_IF_REG_INCR0__W 16
256#define FE_IF_REG_INCR0__M 0xFFFF
257#define FE_IF_REG_INCR1__A 0xC50011
258#define FE_IF_REG_INCR1__M 0xFF
259#define FE_CF_REG_COMM_EXEC__A 0xC60000
260#define FE_CF_REG_SCL__A 0xC60010
261#define FE_CF_REG_MAX_LEV__A 0xC60011
262#define FE_CF_REG_NR__A 0xC60012
263#define FE_CF_REG_IMP_VAL__A 0xC60013
264#define FE_CF_REG_MEAS_VAL__A 0xC60014
265#define FE_CU_REG_COMM_EXEC__A 0xC70000
266#define FE_CU_REG_FRM_CNT_RST__A 0xC70011
267#define FE_CU_REG_FRM_CNT_STR__A 0xC70012
268#define FT_COMM_EXEC__A 0x1000000
269#define FT_REG_COMM_EXEC__A 0x1010000
270#define CP_COMM_EXEC__A 0x1400000
271#define CP_REG_COMM_EXEC__A 0x1410000
272#define CP_REG_INTERVAL__A 0x1410011
273#define CP_REG_BR_SPL_OFFSET__A 0x1410023
274#define CP_REG_BR_STR_DEL__A 0x1410024
275#define CP_REG_RT_ANG_INC0__A 0x1410030
276#define CP_REG_RT_ANG_INC1__A 0x1410031
277#define CP_REG_RT_DETECT_ENA__A 0x1410032
278#define CP_REG_RT_DETECT_TRH__A 0x1410033
279#define CP_REG_RT_EXP_MARG__A 0x141003E
280#define CP_REG_AC_NEXP_OFFS__A 0x1410040
281#define CP_REG_AC_AVER_POW__A 0x1410041
282#define CP_REG_AC_MAX_POW__A 0x1410042
283#define CP_REG_AC_WEIGHT_MAN__A 0x1410043
284#define CP_REG_AC_WEIGHT_EXP__A 0x1410044
285#define CP_REG_AC_AMP_MODE__A 0x1410047
286#define CP_REG_AC_AMP_FIX__A 0x1410048
287#define CP_REG_AC_ANG_MODE__A 0x141004A
288#define CE_COMM_EXEC__A 0x1800000
289#define CE_REG_COMM_EXEC__A 0x1810000
290#define CE_REG_TAPSET__A 0x1810011
291#define CE_REG_AVG_POW__A 0x1810012
292#define CE_REG_MAX_POW__A 0x1810013
293#define CE_REG_ATT__A 0x1810014
294#define CE_REG_NRED__A 0x1810015
295#define CE_REG_NE_ERR_SELECT__A 0x1810043
296#define CE_REG_NE_TD_CAL__A 0x1810044
297#define CE_REG_NE_MIXAVG__A 0x1810046
298#define CE_REG_NE_NUPD_OFS__A 0x1810047
299#define CE_REG_PE_NEXP_OFFS__A 0x1810050
300#define CE_REG_PE_TIMESHIFT__A 0x1810051
301#define CE_REG_TP_A0_TAP_NEW__A 0x1810064
302#define CE_REG_TP_A0_TAP_NEW_VALID__A 0x1810065
303#define CE_REG_TP_A0_MU_LMS_STEP__A 0x1810066
304#define CE_REG_TP_A1_TAP_NEW__A 0x1810068
305#define CE_REG_TP_A1_TAP_NEW_VALID__A 0x1810069
306#define CE_REG_TP_A1_MU_LMS_STEP__A 0x181006A
307#define CE_REG_TI_NEXP_OFFS__A 0x1810070
308#define CE_REG_FI_SHT_INCR__A 0x1810090
309#define CE_REG_FI_EXP_NORM__A 0x1810091
310#define CE_REG_IR_INPUTSEL__A 0x18100A0
311#define CE_REG_IR_STARTPOS__A 0x18100A1
312#define CE_REG_IR_NEXP_THRES__A 0x18100A2
313#define CE_REG_FR_TREAL00__A 0x1820010
314#define CE_REG_FR_TIMAG00__A 0x1820011
315#define CE_REG_FR_TREAL01__A 0x1820012
316#define CE_REG_FR_TIMAG01__A 0x1820013
317#define CE_REG_FR_TREAL02__A 0x1820014
318#define CE_REG_FR_TIMAG02__A 0x1820015
319#define CE_REG_FR_TREAL03__A 0x1820016
320#define CE_REG_FR_TIMAG03__A 0x1820017
321#define CE_REG_FR_TREAL04__A 0x1820018
322#define CE_REG_FR_TIMAG04__A 0x1820019
323#define CE_REG_FR_TREAL05__A 0x182001A
324#define CE_REG_FR_TIMAG05__A 0x182001B
325#define CE_REG_FR_TREAL06__A 0x182001C
326#define CE_REG_FR_TIMAG06__A 0x182001D
327#define CE_REG_FR_TREAL07__A 0x182001E
328#define CE_REG_FR_TIMAG07__A 0x182001F
329#define CE_REG_FR_TREAL08__A 0x1820020
330#define CE_REG_FR_TIMAG08__A 0x1820021
331#define CE_REG_FR_TREAL09__A 0x1820022
332#define CE_REG_FR_TIMAG09__A 0x1820023
333#define CE_REG_FR_TREAL10__A 0x1820024
334#define CE_REG_FR_TIMAG10__A 0x1820025
335#define CE_REG_FR_TREAL11__A 0x1820026
336#define CE_REG_FR_TIMAG11__A 0x1820027
337#define CE_REG_FR_MID_TAP__A 0x1820028
338#define CE_REG_FR_SQS_G00__A 0x1820029
339#define CE_REG_FR_SQS_G01__A 0x182002A
340#define CE_REG_FR_SQS_G02__A 0x182002B
341#define CE_REG_FR_SQS_G03__A 0x182002C
342#define CE_REG_FR_SQS_G04__A 0x182002D
343#define CE_REG_FR_SQS_G05__A 0x182002E
344#define CE_REG_FR_SQS_G06__A 0x182002F
345#define CE_REG_FR_SQS_G07__A 0x1820030
346#define CE_REG_FR_SQS_G08__A 0x1820031
347#define CE_REG_FR_SQS_G09__A 0x1820032
348#define CE_REG_FR_SQS_G10__A 0x1820033
349#define CE_REG_FR_SQS_G11__A 0x1820034
350#define CE_REG_FR_SQS_G12__A 0x1820035
351#define CE_REG_FR_RIO_G00__A 0x1820036
352#define CE_REG_FR_RIO_G01__A 0x1820037
353#define CE_REG_FR_RIO_G02__A 0x1820038
354#define CE_REG_FR_RIO_G03__A 0x1820039
355#define CE_REG_FR_RIO_G04__A 0x182003A
356#define CE_REG_FR_RIO_G05__A 0x182003B
357#define CE_REG_FR_RIO_G06__A 0x182003C
358#define CE_REG_FR_RIO_G07__A 0x182003D
359#define CE_REG_FR_RIO_G08__A 0x182003E
360#define CE_REG_FR_RIO_G09__A 0x182003F
361#define CE_REG_FR_RIO_G10__A 0x1820040
362#define CE_REG_FR_MODE__A 0x1820041
363#define CE_REG_FR_SQS_TRH__A 0x1820042
364#define CE_REG_FR_RIO_GAIN__A 0x1820043
365#define CE_REG_FR_BYPASS__A 0x1820044
366#define CE_REG_FR_PM_SET__A 0x1820045
367#define CE_REG_FR_ERR_SH__A 0x1820046
368#define CE_REG_FR_MAN_SH__A 0x1820047
369#define CE_REG_FR_TAP_SH__A 0x1820048
370#define EQ_COMM_EXEC__A 0x1C00000
371#define EQ_REG_COMM_EXEC__A 0x1C10000
372#define EQ_REG_COMM_MB__A 0x1C10002
373#define EQ_REG_IS_GAIN_MAN__A 0x1C10015
374#define EQ_REG_IS_GAIN_EXP__A 0x1C10016
375#define EQ_REG_IS_CLIP_EXP__A 0x1C10017
376#define EQ_REG_SN_CEGAIN__A 0x1C1002A
377#define EQ_REG_SN_OFFSET__A 0x1C1002B
378#define EQ_REG_RC_SEL_CAR__A 0x1C10032
379#define EQ_REG_RC_SEL_CAR_INIT 0x0
380#define EQ_REG_RC_SEL_CAR_DIV_ON 0x1
381#define EQ_REG_RC_SEL_CAR_PASS_A_CC 0x0
382#define EQ_REG_RC_SEL_CAR_PASS_B_CE 0x2
383#define EQ_REG_RC_SEL_CAR_LOCAL_A_CC 0x0
384#define EQ_REG_RC_SEL_CAR_LOCAL_B_CE 0x8
385#define EQ_REG_RC_SEL_CAR_MEAS_A_CC 0x0
386#define EQ_REG_RC_SEL_CAR_MEAS_B_CE 0x20
387#define EQ_REG_OT_CONST__A 0x1C10046
388#define EQ_REG_OT_ALPHA__A 0x1C10047
389#define EQ_REG_OT_QNT_THRES0__A 0x1C10048
390#define EQ_REG_OT_QNT_THRES1__A 0x1C10049
391#define EQ_REG_OT_CSI_STEP__A 0x1C1004A
392#define EQ_REG_OT_CSI_OFFSET__A 0x1C1004B
393#define EQ_REG_TD_REQ_SMB_CNT__A 0x1C10061
394#define EQ_REG_TD_TPS_PWR_OFS__A 0x1C10062
395#define EC_SB_REG_COMM_EXEC__A 0x2010000
396#define EC_SB_REG_TR_MODE__A 0x2010010
397#define EC_SB_REG_TR_MODE_8K 0x0
398#define EC_SB_REG_TR_MODE_2K 0x1
399#define EC_SB_REG_CONST__A 0x2010011
400#define EC_SB_REG_CONST_QPSK 0x0
401#define EC_SB_REG_CONST_16QAM 0x1
402#define EC_SB_REG_CONST_64QAM 0x2
403#define EC_SB_REG_ALPHA__A 0x2010012
404#define EC_SB_REG_PRIOR__A 0x2010013
405#define EC_SB_REG_PRIOR_HI 0x0
406#define EC_SB_REG_PRIOR_LO 0x1
407#define EC_SB_REG_CSI_HI__A 0x2010014
408#define EC_SB_REG_CSI_LO__A 0x2010015
409#define EC_SB_REG_SMB_TGL__A 0x2010016
410#define EC_SB_REG_SNR_HI__A 0x2010017
411#define EC_SB_REG_SNR_MID__A 0x2010018
412#define EC_SB_REG_SNR_LO__A 0x2010019
413#define EC_SB_REG_SCALE_MSB__A 0x201001A
414#define EC_SB_REG_SCALE_BIT2__A 0x201001B
415#define EC_SB_REG_SCALE_LSB__A 0x201001C
416#define EC_SB_REG_CSI_OFS__A 0x201001D
417#define EC_VD_REG_COMM_EXEC__A 0x2090000
418#define EC_VD_REG_FORCE__A 0x2090010
419#define EC_VD_REG_SET_CODERATE__A 0x2090011
420#define EC_VD_REG_SET_CODERATE_C1_2 0x0
421#define EC_VD_REG_SET_CODERATE_C2_3 0x1
422#define EC_VD_REG_SET_CODERATE_C3_4 0x2
423#define EC_VD_REG_SET_CODERATE_C5_6 0x3
424#define EC_VD_REG_SET_CODERATE_C7_8 0x4
425#define EC_VD_REG_REQ_SMB_CNT__A 0x2090012
426#define EC_VD_REG_RLK_ENA__A 0x2090014
427#define EC_OD_REG_COMM_EXEC__A 0x2110000
428#define EC_OD_REG_SYNC__A 0x2110010
429#define EC_OD_DEINT_RAM__A 0x2120000
430#define EC_RS_REG_COMM_EXEC__A 0x2130000
431#define EC_RS_REG_REQ_PCK_CNT__A 0x2130010
432#define EC_RS_REG_VAL__A 0x2130011
433#define EC_RS_REG_VAL_PCK 0x1
434#define EC_RS_EC_RAM__A 0x2140000
435#define EC_OC_REG_COMM_EXEC__A 0x2150000
436#define EC_OC_REG_COMM_EXEC_CTL_ACTIVE 0x1
437#define EC_OC_REG_COMM_EXEC_CTL_HOLD 0x2
438#define EC_OC_REG_COMM_INT_STA__A 0x2150007
439#define EC_OC_REG_OC_MODE_LOP__A 0x2150010
440#define EC_OC_REG_OC_MODE_LOP_PAR_ENA__M 0x1
441#define EC_OC_REG_OC_MODE_LOP_PAR_ENA_ENABLE 0x0
442#define EC_OC_REG_OC_MODE_LOP_PAR_ENA_DISABLE 0x1
443#define EC_OC_REG_OC_MODE_LOP_DTO_CTR_SRC__M 0x4
444#define EC_OC_REG_OC_MODE_LOP_DTO_CTR_SRC_STATIC 0x0
445#define EC_OC_REG_OC_MODE_LOP_MPG_TRM_MDE__M 0x80
446#define EC_OC_REG_OC_MODE_LOP_MPG_TRM_MDE_SERIAL 0x80
447#define EC_OC_REG_OC_MODE_HIP__A 0x2150011
448#define EC_OC_REG_OC_MODE_HIP_MPG_BUS_SRC_MONITOR 0x10
449#define EC_OC_REG_OC_MODE_HIP_MPG_PAR_VAL__M 0x200
450#define EC_OC_REG_OC_MODE_HIP_MPG_PAR_VAL_DISABLE 0x0
451#define EC_OC_REG_OC_MODE_HIP_MPG_PAR_VAL_ENABLE 0x200
452#define EC_OC_REG_OC_MPG_SIO__A 0x2150012
453#define EC_OC_REG_OC_MPG_SIO__M 0xFFF
454#define EC_OC_REG_OC_MON_SIO__A 0x2150013
455#define EC_OC_REG_DTO_INC_LOP__A 0x2150014
456#define EC_OC_REG_DTO_INC_HIP__A 0x2150015
457#define EC_OC_REG_SNC_ISC_LVL__A 0x2150016
458#define EC_OC_REG_SNC_ISC_LVL_OSC__M 0xF0
459#define EC_OC_REG_TMD_TOP_MODE__A 0x215001D
460#define EC_OC_REG_TMD_TOP_CNT__A 0x215001E
461#define EC_OC_REG_TMD_HIL_MAR__A 0x215001F
462#define EC_OC_REG_TMD_LOL_MAR__A 0x2150020
463#define EC_OC_REG_TMD_CUR_CNT__A 0x2150021
464#define EC_OC_REG_AVR_ASH_CNT__A 0x2150023
465#define EC_OC_REG_AVR_BSH_CNT__A 0x2150024
466#define EC_OC_REG_RCN_MODE__A 0x2150027
467#define EC_OC_REG_RCN_CRA_LOP__A 0x2150028
468#define EC_OC_REG_RCN_CRA_HIP__A 0x2150029
469#define EC_OC_REG_RCN_CST_LOP__A 0x215002A
470#define EC_OC_REG_RCN_CST_HIP__A 0x215002B
471#define EC_OC_REG_RCN_SET_LVL__A 0x215002C
472#define EC_OC_REG_RCN_GAI_LVL__A 0x215002D
473#define EC_OC_REG_RCN_CLP_LOP__A 0x2150032
474#define EC_OC_REG_RCN_CLP_HIP__A 0x2150033
475#define EC_OC_REG_RCN_MAP_LOP__A 0x2150034
476#define EC_OC_REG_RCN_MAP_HIP__A 0x2150035
477#define EC_OC_REG_OCR_MPG_UOS__A 0x2150036
478#define EC_OC_REG_OCR_MPG_UOS__M 0xFFF
479#define EC_OC_REG_OCR_MPG_UOS_INIT 0x0
480#define EC_OC_REG_OCR_MPG_USR_DAT__A 0x2150038
481#define EC_OC_REG_OCR_MON_UOS__A 0x2150039
482#define EC_OC_REG_OCR_MON_UOS_DAT_0_ENABLE 0x1
483#define EC_OC_REG_OCR_MON_UOS_DAT_1_ENABLE 0x2
484#define EC_OC_REG_OCR_MON_UOS_DAT_2_ENABLE 0x4
485#define EC_OC_REG_OCR_MON_UOS_DAT_3_ENABLE 0x8
486#define EC_OC_REG_OCR_MON_UOS_DAT_4_ENABLE 0x10
487#define EC_OC_REG_OCR_MON_UOS_DAT_5_ENABLE 0x20
488#define EC_OC_REG_OCR_MON_UOS_DAT_6_ENABLE 0x40
489#define EC_OC_REG_OCR_MON_UOS_DAT_7_ENABLE 0x80
490#define EC_OC_REG_OCR_MON_UOS_DAT_8_ENABLE 0x100
491#define EC_OC_REG_OCR_MON_UOS_DAT_9_ENABLE 0x200
492#define EC_OC_REG_OCR_MON_UOS_VAL_ENABLE 0x400
493#define EC_OC_REG_OCR_MON_UOS_CLK_ENABLE 0x800
494#define EC_OC_REG_OCR_MON_WRI__A 0x215003A
495#define EC_OC_REG_OCR_MON_WRI_INIT 0x0
496#define EC_OC_REG_IPR_INV_MPG__A 0x2150045
497#define CC_REG_OSC_MODE__A 0x2410010
498#define CC_REG_OSC_MODE_M20 0x1
499#define CC_REG_PLL_MODE__A 0x2410011
500#define CC_REG_PLL_MODE_BYPASS_PLL 0x1
501#define CC_REG_PLL_MODE_PUMP_CUR_12 0x14
502#define CC_REG_REF_DIVIDE__A 0x2410012
503#define CC_REG_PWD_MODE__A 0x2410015
504#define CC_REG_PWD_MODE_DOWN_PLL 0x2
505#define CC_REG_UPDATE__A 0x2410017
506#define CC_REG_UPDATE_KEY 0x3973
507#define CC_REG_JTAGID_L__A 0x2410019
508#define LC_COMM_EXEC__A 0x2800000
509#define LC_RA_RAM_IFINCR_NOM_L__A 0x282000C
510#define LC_RA_RAM_FILTER_SYM_SET__A 0x282001A
511#define LC_RA_RAM_FILTER_SYM_SET__PRE 0x3E8
512#define LC_RA_RAM_FILTER_CRMM_A__A 0x2820060
513#define LC_RA_RAM_FILTER_CRMM_A__PRE 0x4
514#define LC_RA_RAM_FILTER_CRMM_B__A 0x2820061
515#define LC_RA_RAM_FILTER_CRMM_B__PRE 0x1
516#define LC_RA_RAM_FILTER_SRMM_A__A 0x2820068
517#define LC_RA_RAM_FILTER_SRMM_A__PRE 0x4
518#define LC_RA_RAM_FILTER_SRMM_B__A 0x2820069
519#define LC_RA_RAM_FILTER_SRMM_B__PRE 0x1
520#define B_HI_COMM_EXEC__A 0x400000
521#define B_HI_COMM_MB__A 0x400002
522#define B_HI_CT_REG_COMM_STATE__A 0x410001
523#define B_HI_RA_RAM_SRV_RES__A 0x420031
524#define B_HI_RA_RAM_SRV_CMD__A 0x420032
525#define B_HI_RA_RAM_SRV_CMD_RESET 0x2
526#define B_HI_RA_RAM_SRV_CMD_CONFIG 0x3
527#define B_HI_RA_RAM_SRV_CMD_EXECUTE 0x6
528#define B_HI_RA_RAM_SRV_RST_KEY__A 0x420033
529#define B_HI_RA_RAM_SRV_RST_KEY_ACT 0x3973
530#define B_HI_RA_RAM_SRV_CFG_KEY__A 0x420033
531#define B_HI_RA_RAM_SRV_CFG_DIV__A 0x420034
532#define B_HI_RA_RAM_SRV_CFG_BDL__A 0x420035
533#define B_HI_RA_RAM_SRV_CFG_WUP__A 0x420036
534#define B_HI_RA_RAM_SRV_CFG_ACT__A 0x420037
535#define B_HI_RA_RAM_SRV_CFG_ACT_SLV0_ON 0x1
536#define B_HI_RA_RAM_SRV_CFG_ACT_BRD__M 0x4
537#define B_HI_RA_RAM_SRV_CFG_ACT_BRD_OFF 0x0
538#define B_HI_RA_RAM_SRV_CFG_ACT_BRD_ON 0x4
539#define B_HI_RA_RAM_SRV_CFG_ACT_PWD_EXE 0x8
540#define B_HI_RA_RAM_USR_BEGIN__A 0x420040
541#define B_HI_IF_RAM_TRP_BPT0__AX 0x430000
542#define B_HI_IF_RAM_USR_BEGIN__A 0x430200
543#define B_SC_COMM_EXEC__A 0x800000
544#define B_SC_COMM_EXEC_CTL_STOP 0x0
545#define B_SC_COMM_STATE__A 0x800001
546#define B_SC_RA_RAM_PARAM0__A 0x820040
547#define B_SC_RA_RAM_PARAM1__A 0x820041
548#define B_SC_RA_RAM_CMD_ADDR__A 0x820042
549#define B_SC_RA_RAM_CMD__A 0x820043
550#define B_SC_RA_RAM_CMD_PROC_START 0x1
551#define B_SC_RA_RAM_CMD_SET_PREF_PARAM 0x3
552#define B_SC_RA_RAM_CMD_GET_OP_PARAM 0x5
553#define B_SC_RA_RAM_SW_EVENT_RUN_NMASK__M 0x1
554#define B_SC_RA_RAM_LOCKTRACK_MIN 0x1
555#define B_SC_RA_RAM_OP_PARAM_MODE_2K 0x0
556#define B_SC_RA_RAM_OP_PARAM_MODE_8K 0x1
557#define B_SC_RA_RAM_OP_PARAM_GUARD_32 0x0
558#define B_SC_RA_RAM_OP_PARAM_GUARD_16 0x4
559#define B_SC_RA_RAM_OP_PARAM_GUARD_8 0x8
560#define B_SC_RA_RAM_OP_PARAM_GUARD_4 0xC
561#define B_SC_RA_RAM_OP_PARAM_CONST_QPSK 0x0
562#define B_SC_RA_RAM_OP_PARAM_CONST_QAM16 0x10
563#define B_SC_RA_RAM_OP_PARAM_CONST_QAM64 0x20
564#define B_SC_RA_RAM_OP_PARAM_HIER_NO 0x0
565#define B_SC_RA_RAM_OP_PARAM_HIER_A1 0x40
566#define B_SC_RA_RAM_OP_PARAM_HIER_A2 0x80
567#define B_SC_RA_RAM_OP_PARAM_HIER_A4 0xC0
568#define B_SC_RA_RAM_OP_PARAM_RATE_1_2 0x0
569#define B_SC_RA_RAM_OP_PARAM_RATE_2_3 0x200
570#define B_SC_RA_RAM_OP_PARAM_RATE_3_4 0x400
571#define B_SC_RA_RAM_OP_PARAM_RATE_5_6 0x600
572#define B_SC_RA_RAM_OP_PARAM_RATE_7_8 0x800
573#define B_SC_RA_RAM_OP_PARAM_PRIO_HI 0x0
574#define B_SC_RA_RAM_OP_PARAM_PRIO_LO 0x1000
575#define B_SC_RA_RAM_OP_AUTO_MODE__M 0x1
576#define B_SC_RA_RAM_OP_AUTO_GUARD__M 0x2
577#define B_SC_RA_RAM_OP_AUTO_CONST__M 0x4
578#define B_SC_RA_RAM_OP_AUTO_HIER__M 0x8
579#define B_SC_RA_RAM_OP_AUTO_RATE__M 0x10
580#define B_SC_RA_RAM_LOCK__A 0x82004B
581#define B_SC_RA_RAM_LOCK_DEMOD__M 0x1
582#define B_SC_RA_RAM_LOCK_FEC__M 0x2
583#define B_SC_RA_RAM_LOCK_MPEG__M 0x4
584#define B_SC_RA_RAM_BE_OPT_ENA__A 0x82004C
585#define B_SC_RA_RAM_BE_OPT_ENA_CP_OPT 0x1
586#define B_SC_RA_RAM_BE_OPT_DELAY__A 0x82004D
587#define B_SC_RA_RAM_CONFIG__A 0x820050
588#define B_SC_RA_RAM_CONFIG_FR_ENABLE__M 0x4
589#define B_SC_RA_RAM_CONFIG_FREQSCAN__M 0x10
590#define B_SC_RA_RAM_CONFIG_SLAVE__M 0x20
591#define B_SC_RA_RAM_CONFIG_DIV_BLANK_ENABLE__M 0x200
592#define B_SC_RA_RAM_CONFIG_DIV_ECHO_ENABLE__M 0x400
593#define B_SC_RA_RAM_CO_TD_CAL_2K__A 0x82005D
594#define B_SC_RA_RAM_CO_TD_CAL_8K__A 0x82005E
595#define B_SC_RA_RAM_IF_SAVE__AX 0x82008E
596#define B_SC_RA_RAM_DIVERSITY_DELAY_2K_32__A 0x820098
597#define B_SC_RA_RAM_DIVERSITY_DELAY_2K_16__A 0x820099
598#define B_SC_RA_RAM_DIVERSITY_DELAY_2K_8__A 0x82009A
599#define B_SC_RA_RAM_DIVERSITY_DELAY_2K_4__A 0x82009B
600#define B_SC_RA_RAM_DIVERSITY_DELAY_8K_32__A 0x82009C
601#define B_SC_RA_RAM_DIVERSITY_DELAY_8K_16__A 0x82009D
602#define B_SC_RA_RAM_DIVERSITY_DELAY_8K_8__A 0x82009E
603#define B_SC_RA_RAM_DIVERSITY_DELAY_8K_4__A 0x82009F
604#define B_SC_RA_RAM_IR_COARSE_2K_LENGTH__A 0x8200D1
605#define B_SC_RA_RAM_IR_COARSE_2K_LENGTH__PRE 0x9
606#define B_SC_RA_RAM_IR_COARSE_2K_FREQINC__A 0x8200D2
607#define B_SC_RA_RAM_IR_COARSE_2K_FREQINC__PRE 0x4
608#define B_SC_RA_RAM_IR_COARSE_2K_KAISINC__A 0x8200D3
609#define B_SC_RA_RAM_IR_COARSE_2K_KAISINC__PRE 0x100
610#define B_SC_RA_RAM_IR_COARSE_8K_LENGTH__A 0x8200D4
611#define B_SC_RA_RAM_IR_COARSE_8K_LENGTH__PRE 0x8
612#define B_SC_RA_RAM_IR_COARSE_8K_FREQINC__A 0x8200D5
613#define B_SC_RA_RAM_IR_COARSE_8K_FREQINC__PRE 0x8
614#define B_SC_RA_RAM_IR_COARSE_8K_KAISINC__A 0x8200D6
615#define B_SC_RA_RAM_IR_COARSE_8K_KAISINC__PRE 0x200
616#define B_SC_RA_RAM_IR_FINE_2K_LENGTH__A 0x8200D7
617#define B_SC_RA_RAM_IR_FINE_2K_LENGTH__PRE 0x9
618#define B_SC_RA_RAM_IR_FINE_2K_FREQINC__A 0x8200D8
619#define B_SC_RA_RAM_IR_FINE_2K_FREQINC__PRE 0x4
620#define B_SC_RA_RAM_IR_FINE_2K_KAISINC__A 0x8200D9
621#define B_SC_RA_RAM_IR_FINE_2K_KAISINC__PRE 0x100
622#define B_SC_RA_RAM_IR_FINE_8K_LENGTH__A 0x8200DA
623#define B_SC_RA_RAM_IR_FINE_8K_LENGTH__PRE 0xB
624#define B_SC_RA_RAM_IR_FINE_8K_FREQINC__A 0x8200DB
625#define B_SC_RA_RAM_IR_FINE_8K_FREQINC__PRE 0x1
626#define B_SC_RA_RAM_IR_FINE_8K_KAISINC__A 0x8200DC
627#define B_SC_RA_RAM_IR_FINE_8K_KAISINC__PRE 0x40
628#define B_SC_RA_RAM_ECHO_SHIFT_LIM__A 0x8200DD
629#define B_SC_RA_RAM_SAMPLE_RATE_COUNT__A 0x8200E8
630#define B_SC_RA_RAM_SAMPLE_RATE_STEP__A 0x8200E9
631#define B_SC_RA_RAM_BAND__A 0x8200EC
632#define B_SC_RA_RAM_LC_ABS_2K__A 0x8200F4
633#define B_SC_RA_RAM_LC_ABS_2K__PRE 0x1F
634#define B_SC_RA_RAM_LC_ABS_8K__A 0x8200F5
635#define B_SC_RA_RAM_LC_ABS_8K__PRE 0x1F
636#define B_SC_RA_RAM_EQ_IS_GAIN_UNKNOWN_MAN__PRE 0x100
637#define B_SC_RA_RAM_EQ_IS_GAIN_UNKNOWN_EXP__PRE 0x4
638#define B_SC_RA_RAM_EQ_IS_GAIN_QPSK_MAN__PRE 0x1E2
639#define B_SC_RA_RAM_EQ_IS_GAIN_QPSK_EXP__PRE 0x4
640#define B_SC_RA_RAM_EQ_IS_GAIN_16QAM_MAN__PRE 0x10D
641#define B_SC_RA_RAM_EQ_IS_GAIN_16QAM_EXP__PRE 0x5
642#define B_SC_RA_RAM_EQ_IS_GAIN_16QAM_A2_MAN__PRE 0x17D
643#define B_SC_RA_RAM_EQ_IS_GAIN_16QAM_A2_EXP__PRE 0x4
644#define B_SC_RA_RAM_EQ_IS_GAIN_16QAM_A4_MAN__PRE 0x133
645#define B_SC_RA_RAM_EQ_IS_GAIN_16QAM_A4_EXP__PRE 0x5
646#define B_SC_RA_RAM_EQ_IS_GAIN_64QAM_MAN__PRE 0x114
647#define B_SC_RA_RAM_EQ_IS_GAIN_64QAM_EXP__PRE 0x5
648#define B_SC_RA_RAM_EQ_IS_GAIN_64QAM_A2_MAN__PRE 0x14A
649#define B_SC_RA_RAM_EQ_IS_GAIN_64QAM_A2_EXP__PRE 0x4
650#define B_SC_RA_RAM_EQ_IS_GAIN_64QAM_A4_MAN__PRE 0x1BB
651#define B_SC_RA_RAM_EQ_IS_GAIN_64QAM_A4_EXP__PRE 0x4
652#define B_SC_RA_RAM_DRIVER_VERSION__AX 0x8201FE
653#define B_SC_RA_RAM_PROC_LOCKTRACK 0x0
654#define B_FE_COMM_EXEC__A 0xC00000
655#define B_FE_AD_REG_COMM_EXEC__A 0xC10000
656#define B_FE_AD_REG_FDB_IN__A 0xC10012
657#define B_FE_AD_REG_PD__A 0xC10013
658#define B_FE_AD_REG_INVEXT__A 0xC10014
659#define B_FE_AD_REG_CLKNEG__A 0xC10015
660#define B_FE_AG_REG_COMM_EXEC__A 0xC20000
661#define B_FE_AG_REG_AG_MODE_LOP__A 0xC20010
662#define B_FE_AG_REG_AG_MODE_LOP_MODE_4__M 0x10
663#define B_FE_AG_REG_AG_MODE_LOP_MODE_4_STATIC 0x0
664#define B_FE_AG_REG_AG_MODE_LOP_MODE_4_DYNAMIC 0x10
665#define B_FE_AG_REG_AG_MODE_LOP_MODE_5__M 0x20
666#define B_FE_AG_REG_AG_MODE_LOP_MODE_5_STATIC 0x0
667#define B_FE_AG_REG_AG_MODE_LOP_MODE_C__M 0x1000
668#define B_FE_AG_REG_AG_MODE_LOP_MODE_C_STATIC 0x0
669#define B_FE_AG_REG_AG_MODE_LOP_MODE_C_DYNAMIC 0x1000
670#define B_FE_AG_REG_AG_MODE_LOP_MODE_E__M 0x4000
671#define B_FE_AG_REG_AG_MODE_LOP_MODE_E_STATIC 0x0
672#define B_FE_AG_REG_AG_MODE_LOP_MODE_E_DYNAMIC 0x4000
673#define B_FE_AG_REG_AG_MODE_HIP__A 0xC20011
674#define B_FE_AG_REG_AG_MODE_HIP_MODE_J__M 0x8
675#define B_FE_AG_REG_AG_MODE_HIP_MODE_J_STATIC 0x0
676#define B_FE_AG_REG_AG_MODE_HIP_MODE_J_DYNAMIC 0x8
677#define B_FE_AG_REG_AG_PGA_MODE__A 0xC20012
678#define B_FE_AG_REG_AG_PGA_MODE_PFY_PCY_AFY_REN 0x0
679#define B_FE_AG_REG_AG_PGA_MODE_PFN_PCN_AFY_REN 0x1
680#define B_FE_AG_REG_AG_AGC_SIO__A 0xC20013
681#define B_FE_AG_REG_AG_AGC_SIO_AGC_SIO_2__M 0x2
682#define B_FE_AG_REG_AG_AGC_SIO_AGC_SIO_2_OUTPUT 0x0
683#define B_FE_AG_REG_AG_AGC_SIO_AGC_SIO_2_INPUT 0x2
684#define B_FE_AG_REG_AG_PWD__A 0xC20015
685#define B_FE_AG_REG_AG_PWD_PWD_PD2__M 0x2
686#define B_FE_AG_REG_AG_PWD_PWD_PD2_DISABLE 0x0
687#define B_FE_AG_REG_AG_PWD_PWD_PD2_ENABLE 0x2
688#define B_FE_AG_REG_DCE_AUR_CNT__A 0xC20016
689#define B_FE_AG_REG_DCE_RUR_CNT__A 0xC20017
690#define B_FE_AG_REG_ACE_AUR_CNT__A 0xC2001A
691#define B_FE_AG_REG_ACE_RUR_CNT__A 0xC2001B
692#define B_FE_AG_REG_CDR_RUR_CNT__A 0xC20020
693#define B_FE_AG_REG_EGC_RUR_CNT__A 0xC20024
694#define B_FE_AG_REG_EGC_SET_LVL__A 0xC20025
695#define B_FE_AG_REG_EGC_SET_LVL__M 0x1FF
696#define B_FE_AG_REG_EGC_FLA_RGN__A 0xC20026
697#define B_FE_AG_REG_EGC_SLO_RGN__A 0xC20027
698#define B_FE_AG_REG_EGC_JMP_PSN__A 0xC20028
699#define B_FE_AG_REG_EGC_FLA_INC__A 0xC20029
700#define B_FE_AG_REG_EGC_FLA_DEC__A 0xC2002A
701#define B_FE_AG_REG_EGC_SLO_INC__A 0xC2002B
702#define B_FE_AG_REG_EGC_SLO_DEC__A 0xC2002C
703#define B_FE_AG_REG_EGC_FAS_INC__A 0xC2002D
704#define B_FE_AG_REG_EGC_FAS_DEC__A 0xC2002E
705#define B_FE_AG_REG_PM1_AGC_WRI__A 0xC20030
706#define B_FE_AG_REG_PM1_AGC_WRI__M 0x7FF
707#define B_FE_AG_REG_GC1_AGC_RIC__A 0xC20031
708#define B_FE_AG_REG_GC1_AGC_OFF__A 0xC20032
709#define B_FE_AG_REG_GC1_AGC_MAX__A 0xC20033
710#define B_FE_AG_REG_GC1_AGC_MIN__A 0xC20034
711#define B_FE_AG_REG_GC1_AGC_DAT__A 0xC20035
712#define B_FE_AG_REG_GC1_AGC_DAT__M 0x3FF
713#define B_FE_AG_REG_PM2_AGC_WRI__A 0xC20036
714#define B_FE_AG_REG_IND_WIN__A 0xC2003C
715#define B_FE_AG_REG_IND_THD_LOL__A 0xC2003D
716#define B_FE_AG_REG_IND_THD_HIL__A 0xC2003E
717#define B_FE_AG_REG_IND_DEL__A 0xC2003F
718#define B_FE_AG_REG_IND_PD1_WRI__A 0xC20040
719#define B_FE_AG_REG_PDA_AUR_CNT__A 0xC20041
720#define B_FE_AG_REG_PDA_RUR_CNT__A 0xC20042
721#define B_FE_AG_REG_PDA_AVE_DAT__A 0xC20043
722#define B_FE_AG_REG_PDC_RUR_CNT__A 0xC20044
723#define B_FE_AG_REG_PDC_SET_LVL__A 0xC20045
724#define B_FE_AG_REG_PDC_FLA_RGN__A 0xC20046
725#define B_FE_AG_REG_PDC_JMP_PSN__A 0xC20047
726#define B_FE_AG_REG_PDC_FLA_STP__A 0xC20048
727#define B_FE_AG_REG_PDC_SLO_STP__A 0xC20049
728#define B_FE_AG_REG_PDC_PD2_WRI__A 0xC2004A
729#define B_FE_AG_REG_PDC_MAP_DAT__A 0xC2004B
730#define B_FE_AG_REG_PDC_MAX__A 0xC2004C
731#define B_FE_AG_REG_TGA_AUR_CNT__A 0xC2004D
732#define B_FE_AG_REG_TGA_RUR_CNT__A 0xC2004E
733#define B_FE_AG_REG_TGA_AVE_DAT__A 0xC2004F
734#define B_FE_AG_REG_TGC_RUR_CNT__A 0xC20050
735#define B_FE_AG_REG_TGC_SET_LVL__A 0xC20051
736#define B_FE_AG_REG_TGC_SET_LVL__M 0x3F
737#define B_FE_AG_REG_TGC_FLA_RGN__A 0xC20052
738#define B_FE_AG_REG_TGC_JMP_PSN__A 0xC20053
739#define B_FE_AG_REG_TGC_FLA_STP__A 0xC20054
740#define B_FE_AG_REG_TGC_SLO_STP__A 0xC20055
741#define B_FE_AG_REG_TGC_MAP_DAT__A 0xC20056
742#define B_FE_AG_REG_FGM_WRI__A 0xC20061
743#define B_FE_AG_REG_BGC_FGC_WRI__A 0xC20068
744#define B_FE_AG_REG_BGC_CGC_WRI__A 0xC20069
745#define B_FE_FS_REG_COMM_EXEC__A 0xC30000
746#define B_FE_FS_REG_ADD_INC_LOP__A 0xC30010
747#define B_FE_FD_REG_COMM_EXEC__A 0xC40000
748#define B_FE_FD_REG_SCL__A 0xC40010
749#define B_FE_FD_REG_MAX_LEV__A 0xC40011
750#define B_FE_FD_REG_NR__A 0xC40012
751#define B_FE_FD_REG_MEAS_VAL__A 0xC40014
752#define B_FE_IF_REG_COMM_EXEC__A 0xC50000
753#define B_FE_IF_REG_INCR0__A 0xC50010
754#define B_FE_IF_REG_INCR0__W 16
755#define B_FE_IF_REG_INCR0__M 0xFFFF
756#define B_FE_IF_REG_INCR1__A 0xC50011
757#define B_FE_IF_REG_INCR1__M 0xFF
758#define B_FE_CF_REG_COMM_EXEC__A 0xC60000
759#define B_FE_CF_REG_SCL__A 0xC60010
760#define B_FE_CF_REG_MAX_LEV__A 0xC60011
761#define B_FE_CF_REG_NR__A 0xC60012
762#define B_FE_CF_REG_IMP_VAL__A 0xC60013
763#define B_FE_CF_REG_MEAS_VAL__A 0xC60014
764#define B_FE_CU_REG_COMM_EXEC__A 0xC70000
765#define B_FE_CU_REG_FRM_CNT_RST__A 0xC70011
766#define B_FE_CU_REG_FRM_CNT_STR__A 0xC70012
767#define B_FE_CU_REG_CTR_NFC_ICR__A 0xC70020
768#define B_FE_CU_REG_CTR_NFC_OCR__A 0xC70021
769#define B_FE_CU_REG_DIV_NFC_CLP__A 0xC70027
770#define B_FT_COMM_EXEC__A 0x1000000
771#define B_FT_REG_COMM_EXEC__A 0x1010000
772#define B_CP_COMM_EXEC__A 0x1400000
773#define B_CP_REG_COMM_EXEC__A 0x1410000
774#define B_CP_REG_INTERVAL__A 0x1410011
775#define B_CP_REG_BR_SPL_OFFSET__A 0x1410023
776#define B_CP_REG_BR_STR_DEL__A 0x1410024
777#define B_CP_REG_RT_ANG_INC0__A 0x1410030
778#define B_CP_REG_RT_ANG_INC1__A 0x1410031
779#define B_CP_REG_RT_DETECT_TRH__A 0x1410033
780#define B_CP_REG_AC_NEXP_OFFS__A 0x1410040
781#define B_CP_REG_AC_AVER_POW__A 0x1410041
782#define B_CP_REG_AC_MAX_POW__A 0x1410042
783#define B_CP_REG_AC_WEIGHT_MAN__A 0x1410043
784#define B_CP_REG_AC_WEIGHT_EXP__A 0x1410044
785#define B_CP_REG_AC_AMP_MODE__A 0x1410047
786#define B_CP_REG_AC_AMP_FIX__A 0x1410048
787#define B_CP_REG_AC_ANG_MODE__A 0x141004A
788#define B_CE_COMM_EXEC__A 0x1800000
789#define B_CE_REG_COMM_EXEC__A 0x1810000
790#define B_CE_REG_TAPSET__A 0x1810011
791#define B_CE_REG_AVG_POW__A 0x1810012
792#define B_CE_REG_MAX_POW__A 0x1810013
793#define B_CE_REG_ATT__A 0x1810014
794#define B_CE_REG_NRED__A 0x1810015
795#define B_CE_REG_NE_ERR_SELECT__A 0x1810043
796#define B_CE_REG_NE_TD_CAL__A 0x1810044
797#define B_CE_REG_NE_MIXAVG__A 0x1810046
798#define B_CE_REG_NE_NUPD_OFS__A 0x1810047
799#define B_CE_REG_PE_NEXP_OFFS__A 0x1810050
800#define B_CE_REG_PE_TIMESHIFT__A 0x1810051
801#define B_CE_REG_TP_A0_TAP_NEW__A 0x1810064
802#define B_CE_REG_TP_A0_TAP_NEW_VALID__A 0x1810065
803#define B_CE_REG_TP_A0_MU_LMS_STEP__A 0x1810066
804#define B_CE_REG_TP_A1_TAP_NEW__A 0x1810068
805#define B_CE_REG_TP_A1_TAP_NEW_VALID__A 0x1810069
806#define B_CE_REG_TP_A1_MU_LMS_STEP__A 0x181006A
807#define B_CE_REG_TI_PHN_ENABLE__A 0x1810073
808#define B_CE_REG_FI_SHT_INCR__A 0x1810090
809#define B_CE_REG_FI_EXP_NORM__A 0x1810091
810#define B_CE_REG_IR_INPUTSEL__A 0x18100A0
811#define B_CE_REG_IR_STARTPOS__A 0x18100A1
812#define B_CE_REG_IR_NEXP_THRES__A 0x18100A2
813#define B_CE_REG_FR_TREAL00__A 0x1820010
814#define B_CE_REG_FR_TIMAG00__A 0x1820011
815#define B_CE_REG_FR_TREAL01__A 0x1820012
816#define B_CE_REG_FR_TIMAG01__A 0x1820013
817#define B_CE_REG_FR_TREAL02__A 0x1820014
818#define B_CE_REG_FR_TIMAG02__A 0x1820015
819#define B_CE_REG_FR_TREAL03__A 0x1820016
820#define B_CE_REG_FR_TIMAG03__A 0x1820017
821#define B_CE_REG_FR_TREAL04__A 0x1820018
822#define B_CE_REG_FR_TIMAG04__A 0x1820019
823#define B_CE_REG_FR_TREAL05__A 0x182001A
824#define B_CE_REG_FR_TIMAG05__A 0x182001B
825#define B_CE_REG_FR_TREAL06__A 0x182001C
826#define B_CE_REG_FR_TIMAG06__A 0x182001D
827#define B_CE_REG_FR_TREAL07__A 0x182001E
828#define B_CE_REG_FR_TIMAG07__A 0x182001F
829#define B_CE_REG_FR_TREAL08__A 0x1820020
830#define B_CE_REG_FR_TIMAG08__A 0x1820021
831#define B_CE_REG_FR_TREAL09__A 0x1820022
832#define B_CE_REG_FR_TIMAG09__A 0x1820023
833#define B_CE_REG_FR_TREAL10__A 0x1820024
834#define B_CE_REG_FR_TIMAG10__A 0x1820025
835#define B_CE_REG_FR_TREAL11__A 0x1820026
836#define B_CE_REG_FR_TIMAG11__A 0x1820027
837#define B_CE_REG_FR_MID_TAP__A 0x1820028
838#define B_CE_REG_FR_SQS_G00__A 0x1820029
839#define B_CE_REG_FR_SQS_G01__A 0x182002A
840#define B_CE_REG_FR_SQS_G02__A 0x182002B
841#define B_CE_REG_FR_SQS_G03__A 0x182002C
842#define B_CE_REG_FR_SQS_G04__A 0x182002D
843#define B_CE_REG_FR_SQS_G05__A 0x182002E
844#define B_CE_REG_FR_SQS_G06__A 0x182002F
845#define B_CE_REG_FR_SQS_G07__A 0x1820030
846#define B_CE_REG_FR_SQS_G08__A 0x1820031
847#define B_CE_REG_FR_SQS_G09__A 0x1820032
848#define B_CE_REG_FR_SQS_G10__A 0x1820033
849#define B_CE_REG_FR_SQS_G11__A 0x1820034
850#define B_CE_REG_FR_SQS_G12__A 0x1820035
851#define B_CE_REG_FR_RIO_G00__A 0x1820036
852#define B_CE_REG_FR_RIO_G01__A 0x1820037
853#define B_CE_REG_FR_RIO_G02__A 0x1820038
854#define B_CE_REG_FR_RIO_G03__A 0x1820039
855#define B_CE_REG_FR_RIO_G04__A 0x182003A
856#define B_CE_REG_FR_RIO_G05__A 0x182003B
857#define B_CE_REG_FR_RIO_G06__A 0x182003C
858#define B_CE_REG_FR_RIO_G07__A 0x182003D
859#define B_CE_REG_FR_RIO_G08__A 0x182003E
860#define B_CE_REG_FR_RIO_G09__A 0x182003F
861#define B_CE_REG_FR_RIO_G10__A 0x1820040
862#define B_CE_REG_FR_MODE__A 0x1820041
863#define B_CE_REG_FR_SQS_TRH__A 0x1820042
864#define B_CE_REG_FR_RIO_GAIN__A 0x1820043
865#define B_CE_REG_FR_BYPASS__A 0x1820044
866#define B_CE_REG_FR_PM_SET__A 0x1820045
867#define B_CE_REG_FR_ERR_SH__A 0x1820046
868#define B_CE_REG_FR_MAN_SH__A 0x1820047
869#define B_CE_REG_FR_TAP_SH__A 0x1820048
870#define B_EQ_COMM_EXEC__A 0x1C00000
871#define B_EQ_REG_COMM_EXEC__A 0x1C10000
872#define B_EQ_REG_COMM_MB__A 0x1C10002
873#define B_EQ_REG_IS_GAIN_MAN__A 0x1C10015
874#define B_EQ_REG_IS_GAIN_EXP__A 0x1C10016
875#define B_EQ_REG_IS_CLIP_EXP__A 0x1C10017
876#define B_EQ_REG_SN_CEGAIN__A 0x1C1002A
877#define B_EQ_REG_SN_OFFSET__A 0x1C1002B
878#define B_EQ_REG_RC_SEL_CAR__A 0x1C10032
879#define B_EQ_REG_RC_SEL_CAR_INIT 0x2
880#define B_EQ_REG_RC_SEL_CAR_DIV_ON 0x1
881#define B_EQ_REG_RC_SEL_CAR_PASS_A_CC 0x0
882#define B_EQ_REG_RC_SEL_CAR_PASS_B_CE 0x2
883#define B_EQ_REG_RC_SEL_CAR_LOCAL_A_CC 0x0
884#define B_EQ_REG_RC_SEL_CAR_LOCAL_B_CE 0x8
885#define B_EQ_REG_RC_SEL_CAR_MEAS_A_CC 0x0
886#define B_EQ_REG_RC_SEL_CAR_MEAS_B_CE 0x20
887#define B_EQ_REG_RC_SEL_CAR_FFTMODE__M 0x80
888#define B_EQ_REG_OT_CONST__A 0x1C10046
889#define B_EQ_REG_OT_ALPHA__A 0x1C10047
890#define B_EQ_REG_OT_QNT_THRES0__A 0x1C10048
891#define B_EQ_REG_OT_QNT_THRES1__A 0x1C10049
892#define B_EQ_REG_OT_CSI_STEP__A 0x1C1004A
893#define B_EQ_REG_OT_CSI_OFFSET__A 0x1C1004B
894#define B_EQ_REG_TD_REQ_SMB_CNT__A 0x1C10061
895#define B_EQ_REG_TD_TPS_PWR_OFS__A 0x1C10062
896#define B_EC_SB_REG_COMM_EXEC__A 0x2010000
897#define B_EC_SB_REG_TR_MODE__A 0x2010010
898#define B_EC_SB_REG_TR_MODE_8K 0x0
899#define B_EC_SB_REG_TR_MODE_2K 0x1
900#define B_EC_SB_REG_CONST__A 0x2010011
901#define B_EC_SB_REG_CONST_QPSK 0x0
902#define B_EC_SB_REG_CONST_16QAM 0x1
903#define B_EC_SB_REG_CONST_64QAM 0x2
904#define B_EC_SB_REG_ALPHA__A 0x2010012
905#define B_EC_SB_REG_PRIOR__A 0x2010013
906#define B_EC_SB_REG_PRIOR_HI 0x0
907#define B_EC_SB_REG_PRIOR_LO 0x1
908#define B_EC_SB_REG_CSI_HI__A 0x2010014
909#define B_EC_SB_REG_CSI_LO__A 0x2010015
910#define B_EC_SB_REG_SMB_TGL__A 0x2010016
911#define B_EC_SB_REG_SNR_HI__A 0x2010017
912#define B_EC_SB_REG_SNR_MID__A 0x2010018
913#define B_EC_SB_REG_SNR_LO__A 0x2010019
914#define B_EC_SB_REG_SCALE_MSB__A 0x201001A
915#define B_EC_SB_REG_SCALE_BIT2__A 0x201001B
916#define B_EC_SB_REG_SCALE_LSB__A 0x201001C
917#define B_EC_SB_REG_CSI_OFS0__A 0x201001D
918#define B_EC_SB_REG_CSI_OFS1__A 0x201001E
919#define B_EC_SB_REG_CSI_OFS2__A 0x201001F
920#define B_EC_VD_REG_COMM_EXEC__A 0x2090000
921#define B_EC_VD_REG_FORCE__A 0x2090010
922#define B_EC_VD_REG_SET_CODERATE__A 0x2090011
923#define B_EC_VD_REG_SET_CODERATE_C1_2 0x0
924#define B_EC_VD_REG_SET_CODERATE_C2_3 0x1
925#define B_EC_VD_REG_SET_CODERATE_C3_4 0x2
926#define B_EC_VD_REG_SET_CODERATE_C5_6 0x3
927#define B_EC_VD_REG_SET_CODERATE_C7_8 0x4
928#define B_EC_VD_REG_REQ_SMB_CNT__A 0x2090012
929#define B_EC_VD_REG_RLK_ENA__A 0x2090014
930#define B_EC_OD_REG_COMM_EXEC__A 0x2110000
931#define B_EC_OD_REG_SYNC__A 0x2110664
932#define B_EC_OD_DEINT_RAM__A 0x2120000
933#define B_EC_RS_REG_COMM_EXEC__A 0x2130000
934#define B_EC_RS_REG_REQ_PCK_CNT__A 0x2130010
935#define B_EC_RS_REG_VAL__A 0x2130011
936#define B_EC_RS_REG_VAL_PCK 0x1
937#define B_EC_RS_EC_RAM__A 0x2140000
938#define B_EC_OC_REG_COMM_EXEC__A 0x2150000
939#define B_EC_OC_REG_COMM_EXEC_CTL_ACTIVE 0x1
940#define B_EC_OC_REG_COMM_EXEC_CTL_HOLD 0x2
941#define B_EC_OC_REG_COMM_INT_STA__A 0x2150007
942#define B_EC_OC_REG_OC_MODE_LOP__A 0x2150010
943#define B_EC_OC_REG_OC_MODE_LOP_PAR_ENA__M 0x1
944#define B_EC_OC_REG_OC_MODE_LOP_PAR_ENA_ENABLE 0x0
945#define B_EC_OC_REG_OC_MODE_LOP_PAR_ENA_DISABLE 0x1
946#define B_EC_OC_REG_OC_MODE_LOP_DTO_CTR_SRC__M 0x4
947#define B_EC_OC_REG_OC_MODE_LOP_DTO_CTR_SRC_STATIC 0x0
948#define B_EC_OC_REG_OC_MODE_LOP_MPG_TRM_MDE__M 0x80
949#define B_EC_OC_REG_OC_MODE_LOP_MPG_TRM_MDE_SERIAL 0x80
950#define B_EC_OC_REG_OC_MODE_HIP__A 0x2150011
951#define B_EC_OC_REG_OC_MODE_HIP_MPG_BUS_SRC_MONITOR 0x10
952#define B_EC_OC_REG_OC_MODE_HIP_MPG_PAR_VAL__M 0x200
953#define B_EC_OC_REG_OC_MODE_HIP_MPG_PAR_VAL_DISABLE 0x0
954#define B_EC_OC_REG_OC_MODE_HIP_MPG_PAR_VAL_ENABLE 0x200
955#define B_EC_OC_REG_OC_MPG_SIO__A 0x2150012
956#define B_EC_OC_REG_OC_MPG_SIO__M 0xFFF
957#define B_EC_OC_REG_DTO_INC_LOP__A 0x2150014
958#define B_EC_OC_REG_DTO_INC_HIP__A 0x2150015
959#define B_EC_OC_REG_SNC_ISC_LVL__A 0x2150016
960#define B_EC_OC_REG_SNC_ISC_LVL_OSC__M 0xF0
961#define B_EC_OC_REG_TMD_TOP_MODE__A 0x215001D
962#define B_EC_OC_REG_TMD_TOP_CNT__A 0x215001E
963#define B_EC_OC_REG_TMD_HIL_MAR__A 0x215001F
964#define B_EC_OC_REG_TMD_LOL_MAR__A 0x2150020
965#define B_EC_OC_REG_TMD_CUR_CNT__A 0x2150021
966#define B_EC_OC_REG_AVR_ASH_CNT__A 0x2150023
967#define B_EC_OC_REG_AVR_BSH_CNT__A 0x2150024
968#define B_EC_OC_REG_RCN_MODE__A 0x2150027
969#define B_EC_OC_REG_RCN_CRA_LOP__A 0x2150028
970#define B_EC_OC_REG_RCN_CRA_HIP__A 0x2150029
971#define B_EC_OC_REG_RCN_CST_LOP__A 0x215002A
972#define B_EC_OC_REG_RCN_CST_HIP__A 0x215002B
973#define B_EC_OC_REG_RCN_SET_LVL__A 0x215002C
974#define B_EC_OC_REG_RCN_GAI_LVL__A 0x215002D
975#define B_EC_OC_REG_RCN_CLP_LOP__A 0x2150032
976#define B_EC_OC_REG_RCN_CLP_HIP__A 0x2150033
977#define B_EC_OC_REG_RCN_MAP_LOP__A 0x2150034
978#define B_EC_OC_REG_RCN_MAP_HIP__A 0x2150035
979#define B_EC_OC_REG_OCR_MPG_UOS__A 0x2150036
980#define B_EC_OC_REG_OCR_MPG_UOS__M 0xFFF
981#define B_EC_OC_REG_OCR_MPG_UOS_INIT 0x0
982#define B_EC_OC_REG_OCR_MPG_USR_DAT__A 0x2150038
983#define B_EC_OC_REG_IPR_INV_MPG__A 0x2150045
984#define B_EC_OC_REG_DTO_CLKMODE__A 0x2150047
985#define B_EC_OC_REG_DTO_PER__A 0x2150048
986#define B_EC_OC_REG_DTO_BUR__A 0x2150049
987#define B_EC_OC_REG_RCR_CLKMODE__A 0x215004A
988#define B_CC_REG_OSC_MODE__A 0x2410010
989#define B_CC_REG_OSC_MODE_M20 0x1
990#define B_CC_REG_PLL_MODE__A 0x2410011
991#define B_CC_REG_PLL_MODE_BYPASS_PLL 0x1
992#define B_CC_REG_PLL_MODE_PUMP_CUR_12 0x14
993#define B_CC_REG_REF_DIVIDE__A 0x2410012
994#define B_CC_REG_PWD_MODE__A 0x2410015
995#define B_CC_REG_PWD_MODE_DOWN_PLL 0x2
996#define B_CC_REG_UPDATE__A 0x2410017
997#define B_CC_REG_UPDATE_KEY 0x3973
998#define B_CC_REG_JTAGID_L__A 0x2410019
999#define B_CC_REG_DIVERSITY__A 0x241001B
1000#define B_LC_COMM_EXEC__A 0x2800000
1001#define B_LC_RA_RAM_IFINCR_NOM_L__A 0x282000C
1002#define B_LC_RA_RAM_FILTER_SYM_SET__A 0x282001A
1003#define B_LC_RA_RAM_FILTER_SYM_SET__PRE 0x3E8
1004#define B_LC_RA_RAM_FILTER_CRMM_A__A 0x2820060
1005#define B_LC_RA_RAM_FILTER_CRMM_A__PRE 0x4
1006#define B_LC_RA_RAM_FILTER_CRMM_B__A 0x2820061
1007#define B_LC_RA_RAM_FILTER_CRMM_B__PRE 0x1
1008#define B_LC_RA_RAM_FILTER_SRMM_A__A 0x2820068
1009#define B_LC_RA_RAM_FILTER_SRMM_A__PRE 0x4
1010#define B_LC_RA_RAM_FILTER_SRMM_B__A 0x2820069
1011#define B_LC_RA_RAM_FILTER_SRMM_B__PRE 0x1
1012
1013#endif
diff --git a/drivers/media/dvb/frontends/ds3000.c b/drivers/media/dvb/frontends/ds3000.c
index fc61d9230db8..90bf573308b0 100644
--- a/drivers/media/dvb/frontends/ds3000.c
+++ b/drivers/media/dvb/frontends/ds3000.c
@@ -229,31 +229,11 @@ static u8 ds3000_dvbs2_init_tab[] = {
229 0xb8, 0x00, 229 0xb8, 0x00,
230}; 230};
231 231
232/* DS3000 doesn't need some parameters as input and auto-detects them */
233/* save input from the application of those parameters */
234struct ds3000_tuning {
235 u32 frequency;
236 u32 symbol_rate;
237 fe_spectral_inversion_t inversion;
238 enum fe_code_rate fec;
239
240 /* input values */
241 u8 inversion_val;
242 fe_modulation_t delivery;
243 u8 rolloff;
244};
245
246struct ds3000_state { 232struct ds3000_state {
247 struct i2c_adapter *i2c; 233 struct i2c_adapter *i2c;
248 const struct ds3000_config *config; 234 const struct ds3000_config *config;
249
250 struct dvb_frontend frontend; 235 struct dvb_frontend frontend;
251
252 struct ds3000_tuning dcur;
253 struct ds3000_tuning dnxt;
254
255 u8 skip_fw_load; 236 u8 skip_fw_load;
256
257 /* previous uncorrected block counter for DVB-S2 */ 237 /* previous uncorrected block counter for DVB-S2 */
258 u16 prevUCBS2; 238 u16 prevUCBS2;
259}; 239};
@@ -305,7 +285,7 @@ static int ds3000_writeFW(struct ds3000_state *state, int reg,
305 struct i2c_msg msg; 285 struct i2c_msg msg;
306 u8 *buf; 286 u8 *buf;
307 287
308 buf = kmalloc(3, GFP_KERNEL); 288 buf = kmalloc(33, GFP_KERNEL);
309 if (buf == NULL) { 289 if (buf == NULL) {
310 printk(KERN_ERR "Unable to kmalloc\n"); 290 printk(KERN_ERR "Unable to kmalloc\n");
311 ret = -ENOMEM; 291 ret = -ENOMEM;
@@ -317,10 +297,10 @@ static int ds3000_writeFW(struct ds3000_state *state, int reg,
317 msg.addr = state->config->demod_address; 297 msg.addr = state->config->demod_address;
318 msg.flags = 0; 298 msg.flags = 0;
319 msg.buf = buf; 299 msg.buf = buf;
320 msg.len = 3; 300 msg.len = 33;
321 301
322 for (i = 0; i < len; i += 2) { 302 for (i = 0; i < len; i += 32) {
323 memcpy(buf + 1, data + i, 2); 303 memcpy(buf + 1, data + i, 32);
324 304
325 dprintk("%s: write reg 0x%02x, len = %d\n", __func__, reg, len); 305 dprintk("%s: write reg 0x%02x, len = %d\n", __func__, reg, len);
326 306
@@ -401,45 +381,6 @@ static int ds3000_tuner_readreg(struct ds3000_state *state, u8 reg)
401 return b1[0]; 381 return b1[0];
402} 382}
403 383
404static int ds3000_set_inversion(struct ds3000_state *state,
405 fe_spectral_inversion_t inversion)
406{
407 dprintk("%s(%d)\n", __func__, inversion);
408
409 switch (inversion) {
410 case INVERSION_OFF:
411 case INVERSION_ON:
412 case INVERSION_AUTO:
413 break;
414 default:
415 return -EINVAL;
416 }
417
418 state->dnxt.inversion = inversion;
419
420 return 0;
421}
422
423static int ds3000_set_symbolrate(struct ds3000_state *state, u32 rate)
424{
425 int ret = 0;
426
427 dprintk("%s()\n", __func__);
428
429 dprintk("%s() symbol_rate = %d\n", __func__, state->dnxt.symbol_rate);
430
431 /* check if symbol rate is within limits */
432 if ((state->dnxt.symbol_rate >
433 state->frontend.ops.info.symbol_rate_max) ||
434 (state->dnxt.symbol_rate <
435 state->frontend.ops.info.symbol_rate_min))
436 ret = -EOPNOTSUPP;
437
438 state->dnxt.symbol_rate = rate;
439
440 return ret;
441}
442
443static int ds3000_load_firmware(struct dvb_frontend *fe, 384static int ds3000_load_firmware(struct dvb_frontend *fe,
444 const struct firmware *fw); 385 const struct firmware *fw);
445 386
@@ -509,23 +450,31 @@ static int ds3000_load_firmware(struct dvb_frontend *fe,
509 return 0; 450 return 0;
510} 451}
511 452
512static void ds3000_dump_registers(struct dvb_frontend *fe) 453static int ds3000_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
513{ 454{
514 struct ds3000_state *state = fe->demodulator_priv; 455 struct ds3000_state *state = fe->demodulator_priv;
515 int x, y, reg = 0, val; 456 u8 data;
516 457
517 for (y = 0; y < 16; y++) { 458 dprintk("%s(%d)\n", __func__, voltage);
518 dprintk("%s: %02x: ", __func__, y); 459
519 for (x = 0; x < 16; x++) { 460 data = ds3000_readreg(state, 0xa2);
520 reg = (y << 4) + x; 461 data |= 0x03; /* bit0 V/H, bit1 off/on */
521 val = ds3000_readreg(state, reg); 462
522 if (x != 15) 463 switch (voltage) {
523 dprintk("%02x ", val); 464 case SEC_VOLTAGE_18:
524 else 465 data &= ~0x03;
525 dprintk("%02x\n", val); 466 break;
526 } 467 case SEC_VOLTAGE_13:
468 data &= ~0x03;
469 data |= 0x01;
470 break;
471 case SEC_VOLTAGE_OFF:
472 break;
527 } 473 }
528 dprintk("%s: -- DS3000 DUMP DONE --\n", __func__); 474
475 ds3000_writereg(state, 0xa2, data);
476
477 return 0;
529} 478}
530 479
531static int ds3000_read_status(struct dvb_frontend *fe, fe_status_t* status) 480static int ds3000_read_status(struct dvb_frontend *fe, fe_status_t* status)
@@ -562,16 +511,6 @@ static int ds3000_read_status(struct dvb_frontend *fe, fe_status_t* status)
562 return 0; 511 return 0;
563} 512}
564 513
565#define FE_IS_TUNED (FE_HAS_SIGNAL + FE_HAS_LOCK)
566static int ds3000_is_tuned(struct dvb_frontend *fe)
567{
568 fe_status_t tunerstat;
569
570 ds3000_read_status(fe, &tunerstat);
571
572 return ((tunerstat & FE_IS_TUNED) == FE_IS_TUNED);
573}
574
575/* read DS3000 BER value */ 514/* read DS3000 BER value */
576static int ds3000_read_ber(struct dvb_frontend *fe, u32* ber) 515static int ds3000_read_ber(struct dvb_frontend *fe, u32* ber)
577{ 516{
@@ -792,13 +731,6 @@ static int ds3000_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
792 return 0; 731 return 0;
793} 732}
794 733
795/* Overwrite the current tuning params, we are about to tune */
796static void ds3000_clone_params(struct dvb_frontend *fe)
797{
798 struct ds3000_state *state = fe->demodulator_priv;
799 memcpy(&state->dcur, &state->dnxt, sizeof(state->dcur));
800}
801
802static int ds3000_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 734static int ds3000_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
803{ 735{
804 struct ds3000_state *state = fe->demodulator_priv; 736 struct ds3000_state *state = fe->demodulator_priv;
@@ -1016,287 +948,298 @@ static int ds3000_get_property(struct dvb_frontend *fe,
1016 return 0; 948 return 0;
1017} 949}
1018 950
1019static int ds3000_tune(struct dvb_frontend *fe, 951static int ds3000_set_carrier_offset(struct dvb_frontend *fe,
952 s32 carrier_offset_khz)
953{
954 struct ds3000_state *state = fe->demodulator_priv;
955 s32 tmp;
956
957 tmp = carrier_offset_khz;
958 tmp *= 65536;
959 tmp = (2 * tmp + DS3000_SAMPLE_RATE) / (2 * DS3000_SAMPLE_RATE);
960
961 if (tmp < 0)
962 tmp += 65536;
963
964 ds3000_writereg(state, 0x5f, tmp >> 8);
965 ds3000_writereg(state, 0x5e, tmp & 0xff);
966
967 return 0;
968}
969
970static int ds3000_set_frontend(struct dvb_frontend *fe,
1020 struct dvb_frontend_parameters *p) 971 struct dvb_frontend_parameters *p)
1021{ 972{
1022 struct ds3000_state *state = fe->demodulator_priv; 973 struct ds3000_state *state = fe->demodulator_priv;
1023 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 974 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1024 975
1025 int ret = 0, retune, i; 976 int i;
1026 u8 status, mlpf, mlpf_new, mlpf_max, mlpf_min, nlpf; 977 fe_status_t status;
978 u8 mlpf, mlpf_new, mlpf_max, mlpf_min, nlpf, div4;
979 s32 offset_khz;
1027 u16 value, ndiv; 980 u16 value, ndiv;
1028 u32 f3db; 981 u32 f3db;
1029 982
1030 dprintk("%s() ", __func__); 983 dprintk("%s() ", __func__);
1031 984
1032 /* Load the firmware if required */ 985 if (state->config->set_ts_params)
1033 ret = ds3000_firmware_ondemand(fe); 986 state->config->set_ts_params(fe, 0);
1034 if (ret != 0) { 987 /* Tune */
1035 printk(KERN_ERR "%s: Unable initialise the firmware\n", 988 /* unknown */
1036 __func__); 989 ds3000_tuner_writereg(state, 0x07, 0x02);
1037 return ret; 990 ds3000_tuner_writereg(state, 0x10, 0x00);
991 ds3000_tuner_writereg(state, 0x60, 0x79);
992 ds3000_tuner_writereg(state, 0x08, 0x01);
993 ds3000_tuner_writereg(state, 0x00, 0x01);
994 div4 = 0;
995
996 /* calculate and set freq divider */
997 if (p->frequency < 1146000) {
998 ds3000_tuner_writereg(state, 0x10, 0x11);
999 div4 = 1;
1000 ndiv = ((p->frequency * (6 + 8) * 4) +
1001 (DS3000_XTAL_FREQ / 2)) /
1002 DS3000_XTAL_FREQ - 1024;
1003 } else {
1004 ds3000_tuner_writereg(state, 0x10, 0x01);
1005 ndiv = ((p->frequency * (6 + 8) * 2) +
1006 (DS3000_XTAL_FREQ / 2)) /
1007 DS3000_XTAL_FREQ - 1024;
1038 } 1008 }
1039 1009
1040 state->dnxt.delivery = c->modulation; 1010 ds3000_tuner_writereg(state, 0x01, (ndiv & 0x0f00) >> 8);
1041 state->dnxt.frequency = c->frequency; 1011 ds3000_tuner_writereg(state, 0x02, ndiv & 0x00ff);
1042 state->dnxt.rolloff = 2; /* fixme */ 1012
1043 state->dnxt.fec = c->fec_inner; 1013 /* set pll */
1014 ds3000_tuner_writereg(state, 0x03, 0x06);
1015 ds3000_tuner_writereg(state, 0x51, 0x0f);
1016 ds3000_tuner_writereg(state, 0x51, 0x1f);
1017 ds3000_tuner_writereg(state, 0x50, 0x10);
1018 ds3000_tuner_writereg(state, 0x50, 0x00);
1019 msleep(5);
1020
1021 /* unknown */
1022 ds3000_tuner_writereg(state, 0x51, 0x17);
1023 ds3000_tuner_writereg(state, 0x51, 0x1f);
1024 ds3000_tuner_writereg(state, 0x50, 0x08);
1025 ds3000_tuner_writereg(state, 0x50, 0x00);
1026 msleep(5);
1027
1028 value = ds3000_tuner_readreg(state, 0x3d);
1029 value &= 0x0f;
1030 if ((value > 4) && (value < 15)) {
1031 value -= 3;
1032 if (value < 4)
1033 value = 4;
1034 value = ((value << 3) | 0x01) & 0x79;
1035 }
1044 1036
1045 ret = ds3000_set_inversion(state, p->inversion); 1037 ds3000_tuner_writereg(state, 0x60, value);
1046 if (ret != 0) 1038 ds3000_tuner_writereg(state, 0x51, 0x17);
1047 return ret; 1039 ds3000_tuner_writereg(state, 0x51, 0x1f);
1040 ds3000_tuner_writereg(state, 0x50, 0x08);
1041 ds3000_tuner_writereg(state, 0x50, 0x00);
1042
1043 /* set low-pass filter period */
1044 ds3000_tuner_writereg(state, 0x04, 0x2e);
1045 ds3000_tuner_writereg(state, 0x51, 0x1b);
1046 ds3000_tuner_writereg(state, 0x51, 0x1f);
1047 ds3000_tuner_writereg(state, 0x50, 0x04);
1048 ds3000_tuner_writereg(state, 0x50, 0x00);
1049 msleep(5);
1050
1051 f3db = ((c->symbol_rate / 1000) << 2) / 5 + 2000;
1052 if ((c->symbol_rate / 1000) < 5000)
1053 f3db += 3000;
1054 if (f3db < 7000)
1055 f3db = 7000;
1056 if (f3db > 40000)
1057 f3db = 40000;
1058
1059 /* set low-pass filter baseband */
1060 value = ds3000_tuner_readreg(state, 0x26);
1061 mlpf = 0x2e * 207 / ((value << 1) + 151);
1062 mlpf_max = mlpf * 135 / 100;
1063 mlpf_min = mlpf * 78 / 100;
1064 if (mlpf_max > 63)
1065 mlpf_max = 63;
1066
1067 /* rounded to the closest integer */
1068 nlpf = ((mlpf * f3db * 1000) + (2766 * DS3000_XTAL_FREQ / 2))
1069 / (2766 * DS3000_XTAL_FREQ);
1070 if (nlpf > 23)
1071 nlpf = 23;
1072 if (nlpf < 1)
1073 nlpf = 1;
1074
1075 /* rounded to the closest integer */
1076 mlpf_new = ((DS3000_XTAL_FREQ * nlpf * 2766) +
1077 (1000 * f3db / 2)) / (1000 * f3db);
1078
1079 if (mlpf_new < mlpf_min) {
1080 nlpf++;
1081 mlpf_new = ((DS3000_XTAL_FREQ * nlpf * 2766) +
1082 (1000 * f3db / 2)) / (1000 * f3db);
1083 }
1048 1084
1049 ret = ds3000_set_symbolrate(state, c->symbol_rate); 1085 if (mlpf_new > mlpf_max)
1050 if (ret != 0) 1086 mlpf_new = mlpf_max;
1051 return ret; 1087
1088 ds3000_tuner_writereg(state, 0x04, mlpf_new);
1089 ds3000_tuner_writereg(state, 0x06, nlpf);
1090 ds3000_tuner_writereg(state, 0x51, 0x1b);
1091 ds3000_tuner_writereg(state, 0x51, 0x1f);
1092 ds3000_tuner_writereg(state, 0x50, 0x04);
1093 ds3000_tuner_writereg(state, 0x50, 0x00);
1094 msleep(5);
1095
1096 /* unknown */
1097 ds3000_tuner_writereg(state, 0x51, 0x1e);
1098 ds3000_tuner_writereg(state, 0x51, 0x1f);
1099 ds3000_tuner_writereg(state, 0x50, 0x01);
1100 ds3000_tuner_writereg(state, 0x50, 0x00);
1101 msleep(60);
1102
1103 offset_khz = (ndiv - ndiv % 2 + 1024) * DS3000_XTAL_FREQ
1104 / (6 + 8) / (div4 + 1) / 2 - p->frequency;
1105
1106 /* ds3000 global reset */
1107 ds3000_writereg(state, 0x07, 0x80);
1108 ds3000_writereg(state, 0x07, 0x00);
1109 /* ds3000 build-in uC reset */
1110 ds3000_writereg(state, 0xb2, 0x01);
1111 /* ds3000 software reset */
1112 ds3000_writereg(state, 0x00, 0x01);
1052 1113
1053 /* discard the 'current' tuning parameters and prepare to tune */ 1114 switch (c->delivery_system) {
1054 ds3000_clone_params(fe); 1115 case SYS_DVBS:
1055 1116 /* initialise the demod in DVB-S mode */
1056 retune = 1; /* try 1 times */ 1117 for (i = 0; i < sizeof(ds3000_dvbs_init_tab); i += 2)
1057 dprintk("%s: retune = %d\n", __func__, retune); 1118 ds3000_writereg(state,
1058 dprintk("%s: frequency = %d\n", __func__, state->dcur.frequency); 1119 ds3000_dvbs_init_tab[i],
1059 dprintk("%s: symbol_rate = %d\n", __func__, state->dcur.symbol_rate); 1120 ds3000_dvbs_init_tab[i + 1]);
1060 dprintk("%s: FEC = %d \n", __func__, 1121 value = ds3000_readreg(state, 0xfe);
1061 state->dcur.fec); 1122 value &= 0xc0;
1062 dprintk("%s: Inversion = %d\n", __func__, state->dcur.inversion); 1123 value |= 0x1b;
1063 1124 ds3000_writereg(state, 0xfe, value);
1064 do { 1125 break;
1065 /* Reset status register */ 1126 case SYS_DVBS2:
1066 status = 0; 1127 /* initialise the demod in DVB-S2 mode */
1067 /* Tune */ 1128 for (i = 0; i < sizeof(ds3000_dvbs2_init_tab); i += 2)
1068 /* TS2020 init */ 1129 ds3000_writereg(state,
1069 ds3000_tuner_writereg(state, 0x42, 0x73); 1130 ds3000_dvbs2_init_tab[i],
1070 ds3000_tuner_writereg(state, 0x05, 0x01); 1131 ds3000_dvbs2_init_tab[i + 1]);
1071 ds3000_tuner_writereg(state, 0x62, 0xf5); 1132 ds3000_writereg(state, 0xfe, 0x98);
1072 /* unknown */ 1133 break;
1073 ds3000_tuner_writereg(state, 0x07, 0x02); 1134 default:
1074 ds3000_tuner_writereg(state, 0x10, 0x00); 1135 return 1;
1075 ds3000_tuner_writereg(state, 0x60, 0x79); 1136 }
1076 ds3000_tuner_writereg(state, 0x08, 0x01);
1077 ds3000_tuner_writereg(state, 0x00, 0x01);
1078 /* calculate and set freq divider */
1079 if (state->dcur.frequency < 1146000) {
1080 ds3000_tuner_writereg(state, 0x10, 0x11);
1081 ndiv = ((state->dcur.frequency * (6 + 8) * 4) +
1082 (DS3000_XTAL_FREQ / 2)) /
1083 DS3000_XTAL_FREQ - 1024;
1084 } else {
1085 ds3000_tuner_writereg(state, 0x10, 0x01);
1086 ndiv = ((state->dcur.frequency * (6 + 8) * 2) +
1087 (DS3000_XTAL_FREQ / 2)) /
1088 DS3000_XTAL_FREQ - 1024;
1089 }
1090 1137
1091 ds3000_tuner_writereg(state, 0x01, (ndiv & 0x0f00) >> 8); 1138 /* enable 27MHz clock output */
1092 ds3000_tuner_writereg(state, 0x02, ndiv & 0x00ff); 1139 ds3000_writereg(state, 0x29, 0x80);
1093 1140 /* enable ac coupling */
1094 /* set pll */ 1141 ds3000_writereg(state, 0x25, 0x8a);
1095 ds3000_tuner_writereg(state, 0x03, 0x06); 1142
1096 ds3000_tuner_writereg(state, 0x51, 0x0f); 1143 /* enhance symbol rate performance */
1097 ds3000_tuner_writereg(state, 0x51, 0x1f); 1144 if ((c->symbol_rate / 1000) <= 5000) {
1098 ds3000_tuner_writereg(state, 0x50, 0x10); 1145 value = 29777 / (c->symbol_rate / 1000) + 1;
1099 ds3000_tuner_writereg(state, 0x50, 0x00); 1146 if (value % 2 != 0)
1100 msleep(5); 1147 value++;
1101 1148 ds3000_writereg(state, 0xc3, 0x0d);
1102 /* unknown */ 1149 ds3000_writereg(state, 0xc8, value);
1103 ds3000_tuner_writereg(state, 0x51, 0x17); 1150 ds3000_writereg(state, 0xc4, 0x10);
1104 ds3000_tuner_writereg(state, 0x51, 0x1f); 1151 ds3000_writereg(state, 0xc7, 0x0e);
1105 ds3000_tuner_writereg(state, 0x50, 0x08); 1152 } else if ((c->symbol_rate / 1000) <= 10000) {
1106 ds3000_tuner_writereg(state, 0x50, 0x00); 1153 value = 92166 / (c->symbol_rate / 1000) + 1;
1107 msleep(5); 1154 if (value % 2 != 0)
1108 1155 value++;
1109 value = ds3000_tuner_readreg(state, 0x3d); 1156 ds3000_writereg(state, 0xc3, 0x07);
1110 value &= 0x0f; 1157 ds3000_writereg(state, 0xc8, value);
1111 if ((value > 4) && (value < 15)) { 1158 ds3000_writereg(state, 0xc4, 0x09);
1112 value -= 3; 1159 ds3000_writereg(state, 0xc7, 0x12);
1113 if (value < 4) 1160 } else if ((c->symbol_rate / 1000) <= 20000) {
1114 value = 4; 1161 value = 64516 / (c->symbol_rate / 1000) + 1;
1115 value = ((value << 3) | 0x01) & 0x79; 1162 ds3000_writereg(state, 0xc3, value);
1116 } 1163 ds3000_writereg(state, 0xc8, 0x0e);
1164 ds3000_writereg(state, 0xc4, 0x07);
1165 ds3000_writereg(state, 0xc7, 0x18);
1166 } else {
1167 value = 129032 / (c->symbol_rate / 1000) + 1;
1168 ds3000_writereg(state, 0xc3, value);
1169 ds3000_writereg(state, 0xc8, 0x0a);
1170 ds3000_writereg(state, 0xc4, 0x05);
1171 ds3000_writereg(state, 0xc7, 0x24);
1172 }
1117 1173
1118 ds3000_tuner_writereg(state, 0x60, value); 1174 /* normalized symbol rate rounded to the closest integer */
1119 ds3000_tuner_writereg(state, 0x51, 0x17); 1175 value = (((c->symbol_rate / 1000) << 16) +
1120 ds3000_tuner_writereg(state, 0x51, 0x1f); 1176 (DS3000_SAMPLE_RATE / 2)) / DS3000_SAMPLE_RATE;
1121 ds3000_tuner_writereg(state, 0x50, 0x08); 1177 ds3000_writereg(state, 0x61, value & 0x00ff);
1122 ds3000_tuner_writereg(state, 0x50, 0x00); 1178 ds3000_writereg(state, 0x62, (value & 0xff00) >> 8);
1123
1124 /* set low-pass filter period */
1125 ds3000_tuner_writereg(state, 0x04, 0x2e);
1126 ds3000_tuner_writereg(state, 0x51, 0x1b);
1127 ds3000_tuner_writereg(state, 0x51, 0x1f);
1128 ds3000_tuner_writereg(state, 0x50, 0x04);
1129 ds3000_tuner_writereg(state, 0x50, 0x00);
1130 msleep(5);
1131
1132 f3db = ((state->dcur.symbol_rate / 1000) << 2) / 5 + 2000;
1133 if ((state->dcur.symbol_rate / 1000) < 5000)
1134 f3db += 3000;
1135 if (f3db < 7000)
1136 f3db = 7000;
1137 if (f3db > 40000)
1138 f3db = 40000;
1139
1140 /* set low-pass filter baseband */
1141 value = ds3000_tuner_readreg(state, 0x26);
1142 mlpf = 0x2e * 207 / ((value << 1) + 151);
1143 mlpf_max = mlpf * 135 / 100;
1144 mlpf_min = mlpf * 78 / 100;
1145 if (mlpf_max > 63)
1146 mlpf_max = 63;
1147
1148 /* rounded to the closest integer */
1149 nlpf = ((mlpf * f3db * 1000) + (2766 * DS3000_XTAL_FREQ / 2))
1150 / (2766 * DS3000_XTAL_FREQ);
1151 if (nlpf > 23)
1152 nlpf = 23;
1153 if (nlpf < 1)
1154 nlpf = 1;
1155
1156 /* rounded to the closest integer */
1157 mlpf_new = ((DS3000_XTAL_FREQ * nlpf * 2766) +
1158 (1000 * f3db / 2)) / (1000 * f3db);
1159 1179
1160 if (mlpf_new < mlpf_min) { 1180 /* co-channel interference cancellation disabled */
1161 nlpf++; 1181 ds3000_writereg(state, 0x56, 0x00);
1162 mlpf_new = ((DS3000_XTAL_FREQ * nlpf * 2766) + 1182
1163 (1000 * f3db / 2)) / (1000 * f3db); 1183 /* equalizer disabled */
1164 } 1184 ds3000_writereg(state, 0x76, 0x00);
1165 1185
1166 if (mlpf_new > mlpf_max) 1186 /*ds3000_writereg(state, 0x08, 0x03);
1167 mlpf_new = mlpf_max; 1187 ds3000_writereg(state, 0xfd, 0x22);
1168 1188 ds3000_writereg(state, 0x08, 0x07);
1169 ds3000_tuner_writereg(state, 0x04, mlpf_new); 1189 ds3000_writereg(state, 0xfd, 0x42);
1170 ds3000_tuner_writereg(state, 0x06, nlpf); 1190 ds3000_writereg(state, 0x08, 0x07);*/
1171 ds3000_tuner_writereg(state, 0x51, 0x1b);
1172 ds3000_tuner_writereg(state, 0x51, 0x1f);
1173 ds3000_tuner_writereg(state, 0x50, 0x04);
1174 ds3000_tuner_writereg(state, 0x50, 0x00);
1175 msleep(5);
1176
1177 /* unknown */
1178 ds3000_tuner_writereg(state, 0x51, 0x1e);
1179 ds3000_tuner_writereg(state, 0x51, 0x1f);
1180 ds3000_tuner_writereg(state, 0x50, 0x01);
1181 ds3000_tuner_writereg(state, 0x50, 0x00);
1182 msleep(60);
1183
1184 /* ds3000 global reset */
1185 ds3000_writereg(state, 0x07, 0x80);
1186 ds3000_writereg(state, 0x07, 0x00);
1187 /* ds3000 build-in uC reset */
1188 ds3000_writereg(state, 0xb2, 0x01);
1189 /* ds3000 software reset */
1190 ds3000_writereg(state, 0x00, 0x01);
1191 1191
1192 if (state->config->ci_mode) {
1192 switch (c->delivery_system) { 1193 switch (c->delivery_system) {
1193 case SYS_DVBS: 1194 case SYS_DVBS:
1194 /* initialise the demod in DVB-S mode */ 1195 default:
1195 for (i = 0; i < sizeof(ds3000_dvbs_init_tab); i += 2) 1196 ds3000_writereg(state, 0xfd, 0x80);
1196 ds3000_writereg(state, 1197 break;
1197 ds3000_dvbs_init_tab[i],
1198 ds3000_dvbs_init_tab[i + 1]);
1199 value = ds3000_readreg(state, 0xfe);
1200 value &= 0xc0;
1201 value |= 0x1b;
1202 ds3000_writereg(state, 0xfe, value);
1203 break;
1204 case SYS_DVBS2: 1198 case SYS_DVBS2:
1205 /* initialise the demod in DVB-S2 mode */ 1199 ds3000_writereg(state, 0xfd, 0x01);
1206 for (i = 0; i < sizeof(ds3000_dvbs2_init_tab); i += 2)
1207 ds3000_writereg(state,
1208 ds3000_dvbs2_init_tab[i],
1209 ds3000_dvbs2_init_tab[i + 1]);
1210 ds3000_writereg(state, 0xfe, 0x54);
1211 break; 1200 break;
1212 default:
1213 return 1;
1214 } 1201 }
1202 }
1215 1203
1216 /* enable 27MHz clock output */ 1204 /* ds3000 out of software reset */
1217 ds3000_writereg(state, 0x29, 0x80); 1205 ds3000_writereg(state, 0x00, 0x00);
1218 /* enable ac coupling */ 1206 /* start ds3000 build-in uC */
1219 ds3000_writereg(state, 0x25, 0x8a); 1207 ds3000_writereg(state, 0xb2, 0x00);
1220
1221 /* enhance symbol rate performance */
1222 if ((state->dcur.symbol_rate / 1000) <= 5000) {
1223 value = 29777 / (state->dcur.symbol_rate / 1000) + 1;
1224 if (value % 2 != 0)
1225 value++;
1226 ds3000_writereg(state, 0xc3, 0x0d);
1227 ds3000_writereg(state, 0xc8, value);
1228 ds3000_writereg(state, 0xc4, 0x10);
1229 ds3000_writereg(state, 0xc7, 0x0e);
1230 } else if ((state->dcur.symbol_rate / 1000) <= 10000) {
1231 value = 92166 / (state->dcur.symbol_rate / 1000) + 1;
1232 if (value % 2 != 0)
1233 value++;
1234 ds3000_writereg(state, 0xc3, 0x07);
1235 ds3000_writereg(state, 0xc8, value);
1236 ds3000_writereg(state, 0xc4, 0x09);
1237 ds3000_writereg(state, 0xc7, 0x12);
1238 } else if ((state->dcur.symbol_rate / 1000) <= 20000) {
1239 value = 64516 / (state->dcur.symbol_rate / 1000) + 1;
1240 ds3000_writereg(state, 0xc3, value);
1241 ds3000_writereg(state, 0xc8, 0x0e);
1242 ds3000_writereg(state, 0xc4, 0x07);
1243 ds3000_writereg(state, 0xc7, 0x18);
1244 } else {
1245 value = 129032 / (state->dcur.symbol_rate / 1000) + 1;
1246 ds3000_writereg(state, 0xc3, value);
1247 ds3000_writereg(state, 0xc8, 0x0a);
1248 ds3000_writereg(state, 0xc4, 0x05);
1249 ds3000_writereg(state, 0xc7, 0x24);
1250 }
1251 1208
1252 /* normalized symbol rate rounded to the closest integer */ 1209 ds3000_set_carrier_offset(fe, offset_khz);
1253 value = (((state->dcur.symbol_rate / 1000) << 16) +
1254 (DS3000_SAMPLE_RATE / 2)) / DS3000_SAMPLE_RATE;
1255 ds3000_writereg(state, 0x61, value & 0x00ff);
1256 ds3000_writereg(state, 0x62, (value & 0xff00) >> 8);
1257
1258 /* co-channel interference cancellation disabled */
1259 ds3000_writereg(state, 0x56, 0x00);
1260
1261 /* equalizer disabled */
1262 ds3000_writereg(state, 0x76, 0x00);
1263
1264 /*ds3000_writereg(state, 0x08, 0x03);
1265 ds3000_writereg(state, 0xfd, 0x22);
1266 ds3000_writereg(state, 0x08, 0x07);
1267 ds3000_writereg(state, 0xfd, 0x42);
1268 ds3000_writereg(state, 0x08, 0x07);*/
1269
1270 /* ds3000 out of software reset */
1271 ds3000_writereg(state, 0x00, 0x00);
1272 /* start ds3000 build-in uC */
1273 ds3000_writereg(state, 0xb2, 0x00);
1274
1275 /* TODO: calculate and set carrier offset */
1276
1277 /* wait before retrying */
1278 for (i = 0; i < 30 ; i++) {
1279 if (ds3000_is_tuned(fe)) {
1280 dprintk("%s: Tuned\n", __func__);
1281 ds3000_dump_registers(fe);
1282 goto tuned;
1283 }
1284 msleep(1);
1285 }
1286 1210
1287 dprintk("%s: Not tuned\n", __func__); 1211 for (i = 0; i < 30 ; i++) {
1288 ds3000_dump_registers(fe); 1212 ds3000_read_status(fe, &status);
1213 if (status && FE_HAS_LOCK)
1214 break;
1289 1215
1290 } while (--retune); 1216 msleep(10);
1217 }
1291 1218
1292tuned: 1219 return 0;
1293 return ret; 1220}
1221
1222static int ds3000_tune(struct dvb_frontend *fe,
1223 struct dvb_frontend_parameters *p,
1224 unsigned int mode_flags,
1225 unsigned int *delay,
1226 fe_status_t *status)
1227{
1228 if (p) {
1229 int ret = ds3000_set_frontend(fe, p);
1230 if (ret)
1231 return ret;
1232 }
1233
1234 *delay = HZ / 5;
1235
1236 return ds3000_read_status(fe, status);
1294} 1237}
1295 1238
1296static enum dvbfe_algo ds3000_get_algo(struct dvb_frontend *fe) 1239static enum dvbfe_algo ds3000_get_algo(struct dvb_frontend *fe)
1297{ 1240{
1298 dprintk("%s()\n", __func__); 1241 dprintk("%s()\n", __func__);
1299 return DVBFE_ALGO_SW; 1242 return DVBFE_ALGO_HW;
1300} 1243}
1301 1244
1302/* 1245/*
@@ -1306,7 +1249,25 @@ static enum dvbfe_algo ds3000_get_algo(struct dvb_frontend *fe)
1306 */ 1249 */
1307static int ds3000_initfe(struct dvb_frontend *fe) 1250static int ds3000_initfe(struct dvb_frontend *fe)
1308{ 1251{
1252 struct ds3000_state *state = fe->demodulator_priv;
1253 int ret;
1254
1309 dprintk("%s()\n", __func__); 1255 dprintk("%s()\n", __func__);
1256 /* hard reset */
1257 ds3000_writereg(state, 0x08, 0x01 | ds3000_readreg(state, 0x08));
1258 msleep(1);
1259
1260 /* TS2020 init */
1261 ds3000_tuner_writereg(state, 0x42, 0x73);
1262 ds3000_tuner_writereg(state, 0x05, 0x01);
1263 ds3000_tuner_writereg(state, 0x62, 0xf5);
1264 /* Load the firmware if required */
1265 ret = ds3000_firmware_ondemand(fe);
1266 if (ret != 0) {
1267 printk(KERN_ERR "%s: Unable initialize firmware\n", __func__);
1268 return ret;
1269 }
1270
1310 return 0; 1271 return 0;
1311} 1272}
1312 1273
@@ -1345,6 +1306,7 @@ static struct dvb_frontend_ops ds3000_ops = {
1345 .read_signal_strength = ds3000_read_signal_strength, 1306 .read_signal_strength = ds3000_read_signal_strength,
1346 .read_snr = ds3000_read_snr, 1307 .read_snr = ds3000_read_snr,
1347 .read_ucblocks = ds3000_read_ucblocks, 1308 .read_ucblocks = ds3000_read_ucblocks,
1309 .set_voltage = ds3000_set_voltage,
1348 .set_tone = ds3000_set_tone, 1310 .set_tone = ds3000_set_tone,
1349 .diseqc_send_master_cmd = ds3000_send_diseqc_msg, 1311 .diseqc_send_master_cmd = ds3000_send_diseqc_msg,
1350 .diseqc_send_burst = ds3000_diseqc_send_burst, 1312 .diseqc_send_burst = ds3000_diseqc_send_burst,
@@ -1352,7 +1314,8 @@ static struct dvb_frontend_ops ds3000_ops = {
1352 1314
1353 .set_property = ds3000_set_property, 1315 .set_property = ds3000_set_property,
1354 .get_property = ds3000_get_property, 1316 .get_property = ds3000_get_property,
1355 .set_frontend = ds3000_tune, 1317 .set_frontend = ds3000_set_frontend,
1318 .tune = ds3000_tune,
1356}; 1319};
1357 1320
1358module_param(debug, int, 0644); 1321module_param(debug, int, 0644);
diff --git a/drivers/media/dvb/frontends/ds3000.h b/drivers/media/dvb/frontends/ds3000.h
index 67f67038740a..1b736888ea37 100644
--- a/drivers/media/dvb/frontends/ds3000.h
+++ b/drivers/media/dvb/frontends/ds3000.h
@@ -27,6 +27,9 @@
27struct ds3000_config { 27struct ds3000_config {
28 /* the demodulator's i2c address */ 28 /* the demodulator's i2c address */
29 u8 demod_address; 29 u8 demod_address;
30 u8 ci_mode;
31 /* Set device param to start dma */
32 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured);
30}; 33};
31 34
32#if defined(CONFIG_DVB_DS3000) || \ 35#if defined(CONFIG_DVB_DS3000) || \
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c
index 4d4d0bb5920a..62a65efdf8d6 100644
--- a/drivers/media/dvb/frontends/dvb-pll.c
+++ b/drivers/media/dvb/frontends/dvb-pll.c
@@ -64,6 +64,7 @@ struct dvb_pll_desc {
64 void (*set)(struct dvb_frontend *fe, u8 *buf, 64 void (*set)(struct dvb_frontend *fe, u8 *buf,
65 const struct dvb_frontend_parameters *params); 65 const struct dvb_frontend_parameters *params);
66 u8 *initdata; 66 u8 *initdata;
67 u8 *initdata2;
67 u8 *sleepdata; 68 u8 *sleepdata;
68 int count; 69 int count;
69 struct { 70 struct {
@@ -321,26 +322,73 @@ static struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = {
321static void opera1_bw(struct dvb_frontend *fe, u8 *buf, 322static void opera1_bw(struct dvb_frontend *fe, u8 *buf,
322 const struct dvb_frontend_parameters *params) 323 const struct dvb_frontend_parameters *params)
323{ 324{
324 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) 325 struct dvb_pll_priv *priv = fe->tuner_priv;
325 buf[2] |= 0x08; 326 u32 b_w = (params->u.qpsk.symbol_rate * 27) / 32000;
327 struct i2c_msg msg = {
328 .addr = priv->pll_i2c_address,
329 .flags = 0,
330 .buf = buf,
331 .len = 4
332 };
333 int result;
334 u8 lpf;
335
336 if (fe->ops.i2c_gate_ctrl)
337 fe->ops.i2c_gate_ctrl(fe, 1);
338
339 result = i2c_transfer(priv->i2c, &msg, 1);
340 if (result != 1)
341 printk(KERN_ERR "%s: i2c_transfer failed:%d",
342 __func__, result);
343
344 if (b_w <= 10000)
345 lpf = 0xc;
346 else if (b_w <= 12000)
347 lpf = 0x2;
348 else if (b_w <= 14000)
349 lpf = 0xa;
350 else if (b_w <= 16000)
351 lpf = 0x6;
352 else if (b_w <= 18000)
353 lpf = 0xe;
354 else if (b_w <= 20000)
355 lpf = 0x1;
356 else if (b_w <= 22000)
357 lpf = 0x9;
358 else if (b_w <= 24000)
359 lpf = 0x5;
360 else if (b_w <= 26000)
361 lpf = 0xd;
362 else if (b_w <= 28000)
363 lpf = 0x3;
364 else
365 lpf = 0xb;
366 buf[2] ^= 0x1c; /* Flip bits 3-5 */
367 /* Set lpf */
368 buf[2] |= ((lpf >> 2) & 0x3) << 3;
369 buf[3] |= (lpf & 0x3) << 2;
370
371 return;
326} 372}
327 373
328static struct dvb_pll_desc dvb_pll_opera1 = { 374static struct dvb_pll_desc dvb_pll_opera1 = {
329 .name = "Opera Tuner", 375 .name = "Opera Tuner",
330 .min = 900000, 376 .min = 900000,
331 .max = 2250000, 377 .max = 2250000,
378 .initdata = (u8[]){ 4, 0x08, 0xe5, 0xe1, 0x00 },
379 .initdata2 = (u8[]){ 4, 0x08, 0xe5, 0xe5, 0x00 },
332 .iffreq= 0, 380 .iffreq= 0,
333 .set = opera1_bw, 381 .set = opera1_bw,
334 .count = 8, 382 .count = 8,
335 .entries = { 383 .entries = {
336 { 1064000, 500, 0xe5, 0xc6 }, 384 { 1064000, 500, 0xf9, 0xc2 },
337 { 1169000, 500, 0xe5, 0xe6 }, 385 { 1169000, 500, 0xf9, 0xe2 },
338 { 1299000, 500, 0xe5, 0x24 }, 386 { 1299000, 500, 0xf9, 0x20 },
339 { 1444000, 500, 0xe5, 0x44 }, 387 { 1444000, 500, 0xf9, 0x40 },
340 { 1606000, 500, 0xe5, 0x64 }, 388 { 1606000, 500, 0xf9, 0x60 },
341 { 1777000, 500, 0xe5, 0x84 }, 389 { 1777000, 500, 0xf9, 0x80 },
342 { 1941000, 500, 0xe5, 0xa4 }, 390 { 1941000, 500, 0xf9, 0xa0 },
343 { 2250000, 500, 0xe5, 0xc4 }, 391 { 2250000, 500, 0xf9, 0xc0 },
344 } 392 }
345}; 393};
346 394
@@ -648,8 +696,17 @@ static int dvb_pll_init(struct dvb_frontend *fe)
648 int result; 696 int result;
649 if (fe->ops.i2c_gate_ctrl) 697 if (fe->ops.i2c_gate_ctrl)
650 fe->ops.i2c_gate_ctrl(fe, 1); 698 fe->ops.i2c_gate_ctrl(fe, 1);
651 if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) { 699 result = i2c_transfer(priv->i2c, &msg, 1);
700 if (result != 1)
652 return result; 701 return result;
702 if (priv->pll_desc->initdata2) {
703 msg.buf = priv->pll_desc->initdata2 + 1;
704 msg.len = priv->pll_desc->initdata2[0];
705 if (fe->ops.i2c_gate_ctrl)
706 fe->ops.i2c_gate_ctrl(fe, 1);
707 result = i2c_transfer(priv->i2c, &msg, 1);
708 if (result != 1)
709 return result;
653 } 710 }
654 return 0; 711 return 0;
655 } 712 }
diff --git a/drivers/media/dvb/frontends/eds1547.h b/drivers/media/dvb/frontends/eds1547.h
index fa79b7c83dd2..c983f2f85802 100644
--- a/drivers/media/dvb/frontends/eds1547.h
+++ b/drivers/media/dvb/frontends/eds1547.h
@@ -61,7 +61,7 @@ static u8 stv0288_earda_inittab[] = {
61 0x3d, 0x30, 61 0x3d, 0x30,
62 0x40, 0x63, 62 0x40, 0x63,
63 0x41, 0x04, 63 0x41, 0x04,
64 0x42, 0x60, 64 0x42, 0x20,
65 0x43, 0x00, 65 0x43, 0x00,
66 0x44, 0x00, 66 0x44, 0x00,
67 0x45, 0x00, 67 0x45, 0x00,
diff --git a/drivers/media/dvb/frontends/ix2505v.c b/drivers/media/dvb/frontends/ix2505v.c
new file mode 100644
index 000000000000..9a517a4bf96d
--- /dev/null
+++ b/drivers/media/dvb/frontends/ix2505v.c
@@ -0,0 +1,325 @@
1/**
2 * Driver for Sharp IX2505V (marked B0017) DVB-S silicon tuner
3 *
4 * Copyright (C) 2010 Malcolm Priestley
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License Version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 */
20
21#include <linux/module.h>
22#include <linux/dvb/frontend.h>
23#include <linux/slab.h>
24#include <linux/types.h>
25
26#include "ix2505v.h"
27
28static int ix2505v_debug;
29#define dprintk(level, args...) do { \
30 if (ix2505v_debug & level) \
31 printk(KERN_DEBUG "ix2505v: " args); \
32} while (0)
33
34#define deb_info(args...) dprintk(0x01, args)
35#define deb_i2c(args...) dprintk(0x02, args)
36
37struct ix2505v_state {
38 struct i2c_adapter *i2c;
39 const struct ix2505v_config *config;
40 u32 frequency;
41};
42
43/**
44 * Data read format of the Sharp IX2505V B0017
45 *
46 * byte1: 1 | 1 | 0 | 0 | 0 | MA1 | MA0 | 1
47 * byte2: POR | FL | RD2 | RD1 | RD0 | X | X | X
48 *
49 * byte1 = address
50 * byte2;
51 * POR = Power on Reset (VCC H=<2.2v L=>2.2v)
52 * FL = Phase Lock (H=lock L=unlock)
53 * RD0-2 = Reserved internal operations
54 *
55 * Only POR can be used to check the tuner is present
56 *
57 * Caution: after byte2 the I2C reverts to write mode continuing to read
58 * may corrupt tuning data.
59 *
60 */
61
62static int ix2505v_read_status_reg(struct ix2505v_state *state)
63{
64 u8 addr = state->config->tuner_address;
65 u8 b2[] = {0};
66 int ret;
67
68 struct i2c_msg msg[1] = {
69 { .addr = addr, .flags = I2C_M_RD, .buf = b2, .len = 1 }
70 };
71
72 ret = i2c_transfer(state->i2c, msg, 1);
73 deb_i2c("Read %s ", __func__);
74
75 return (ret == 1) ? (int) b2[0] : -1;
76}
77
78static int ix2505v_write(struct ix2505v_state *state, u8 buf[], u8 count)
79{
80 struct i2c_msg msg[1] = {
81 { .addr = state->config->tuner_address, .flags = 0,
82 .buf = buf, .len = count },
83 };
84
85 int ret;
86
87 ret = i2c_transfer(state->i2c, msg, 1);
88
89 if (ret != 1) {
90 deb_i2c("%s: i2c error, ret=%d\n", __func__, ret);
91 return -EIO;
92 }
93
94 return 0;
95}
96
97static int ix2505v_release(struct dvb_frontend *fe)
98{
99 struct ix2505v_state *state = fe->tuner_priv;
100
101 fe->tuner_priv = NULL;
102 kfree(state);
103
104 return 0;
105}
106
107/**
108 * Data write format of the Sharp IX2505V B0017
109 *
110 * byte1: 1 | 1 | 0 | 0 | 0 | 0(MA1)| 0(MA0)| 0
111 * byte2: 0 | BG1 | BG2 | N8 | N7 | N6 | N5 | N4
112 * byte3: N3 | N2 | N1 | A5 | A4 | A3 | A2 | A1
113 * byte4: 1 | 1(C1) | 1(C0) | PD5 | PD4 | TM | 0(RTS)| 1(REF)
114 * byte5: BA2 | BA1 | BA0 | PSC | PD3 |PD2/TS2|DIV/TS1|PD0/TS0
115 *
116 * byte1 = address
117 *
118 * Write order
119 * 1) byte1 -> byte2 -> byte3 -> byte4 -> byte5
120 * 2) byte1 -> byte4 -> byte5 -> byte2 -> byte3
121 * 3) byte1 -> byte2 -> byte3 -> byte4
122 * 4) byte1 -> byte4 -> byte5 -> byte2
123 * 5) byte1 -> byte2 -> byte3
124 * 6) byte1 -> byte4 -> byte5
125 * 7) byte1 -> byte2
126 * 8) byte1 -> byte4
127 *
128 * Recommended Setup
129 * 1 -> 8 -> 6
130 */
131
132static int ix2505v_set_params(struct dvb_frontend *fe,
133 struct dvb_frontend_parameters *params)
134{
135 struct ix2505v_state *state = fe->tuner_priv;
136 u32 frequency = params->frequency;
137 u32 b_w = (params->u.qpsk.symbol_rate * 27) / 32000;
138 u32 div_factor, N , A, x;
139 int ret = 0, len;
140 u8 gain, cc, ref, psc, local_osc, lpf;
141 u8 data[4] = {0};
142
143 if ((frequency < fe->ops.info.frequency_min)
144 || (frequency > fe->ops.info.frequency_max))
145 return -EINVAL;
146
147 if (state->config->tuner_gain)
148 gain = (state->config->tuner_gain < 4)
149 ? state->config->tuner_gain : 0;
150 else
151 gain = 0x0;
152
153 if (state->config->tuner_chargepump)
154 cc = state->config->tuner_chargepump;
155 else
156 cc = 0x3;
157
158 ref = 8; /* REF =1 */
159 psc = 32; /* PSC = 0 */
160
161 div_factor = (frequency * ref) / 40; /* local osc = 4Mhz */
162 x = div_factor / psc;
163 N = x/100;
164 A = ((x - (N * 100)) * psc) / 100;
165
166 data[0] = ((gain & 0x3) << 5) | (N >> 3);
167 data[1] = (N << 5) | (A & 0x1f);
168 data[2] = 0x81 | ((cc & 0x3) << 5) ; /*PD5,PD4 & TM = 0|C1,C0|REF=1*/
169
170 deb_info("Frq=%d x=%d N=%d A=%d\n", frequency, x, N, A);
171
172 if (frequency <= 1065000)
173 local_osc = (6 << 5) | 2;
174 else if (frequency <= 1170000)
175 local_osc = (7 << 5) | 2;
176 else if (frequency <= 1300000)
177 local_osc = (1 << 5);
178 else if (frequency <= 1445000)
179 local_osc = (2 << 5);
180 else if (frequency <= 1607000)
181 local_osc = (3 << 5);
182 else if (frequency <= 1778000)
183 local_osc = (4 << 5);
184 else if (frequency <= 1942000)
185 local_osc = (5 << 5);
186 else /*frequency up to 2150000*/
187 local_osc = (6 << 5);
188
189 data[3] = local_osc; /* all other bits set 0 */
190
191 if (b_w <= 10000)
192 lpf = 0xc;
193 else if (b_w <= 12000)
194 lpf = 0x2;
195 else if (b_w <= 14000)
196 lpf = 0xa;
197 else if (b_w <= 16000)
198 lpf = 0x6;
199 else if (b_w <= 18000)
200 lpf = 0xe;
201 else if (b_w <= 20000)
202 lpf = 0x1;
203 else if (b_w <= 22000)
204 lpf = 0x9;
205 else if (b_w <= 24000)
206 lpf = 0x5;
207 else if (b_w <= 26000)
208 lpf = 0xd;
209 else if (b_w <= 28000)
210 lpf = 0x3;
211 else
212 lpf = 0xb;
213
214 deb_info("Osc=%x b_w=%x lpf=%x\n", local_osc, b_w, lpf);
215 deb_info("Data 0=[%x%x%x%x]\n", data[0], data[1], data[2], data[3]);
216
217 if (fe->ops.i2c_gate_ctrl)
218 fe->ops.i2c_gate_ctrl(fe, 1);
219
220 len = sizeof(data);
221 ret |= ix2505v_write(state, data, len);
222
223 data[2] |= 0x4; /* set TM = 1 other bits same */
224
225 if (fe->ops.i2c_gate_ctrl)
226 fe->ops.i2c_gate_ctrl(fe, 1);
227
228 len = 1;
229 ret |= ix2505v_write(state, &data[2], len); /* write byte 4 only */
230
231 msleep(10);
232
233 data[2] |= ((lpf >> 2) & 0x3) << 3; /* lpf */
234 data[3] |= (lpf & 0x3) << 2;
235
236 deb_info("Data 2=[%x%x]\n", data[2], data[3]);
237
238 if (fe->ops.i2c_gate_ctrl)
239 fe->ops.i2c_gate_ctrl(fe, 1);
240
241 len = 2;
242 ret |= ix2505v_write(state, &data[2], len); /* write byte 4 & 5 */
243
244 if (state->config->min_delay_ms)
245 msleep(state->config->min_delay_ms);
246
247 state->frequency = frequency;
248
249 return ret;
250}
251
252static int ix2505v_get_frequency(struct dvb_frontend *fe, u32 *frequency)
253{
254 struct ix2505v_state *state = fe->tuner_priv;
255
256 *frequency = state->frequency;
257
258 return 0;
259}
260
261static struct dvb_tuner_ops ix2505v_tuner_ops = {
262 .info = {
263 .name = "Sharp IX2505V (B0017)",
264 .frequency_min = 950000,
265 .frequency_max = 2175000
266 },
267 .release = ix2505v_release,
268 .set_params = ix2505v_set_params,
269 .get_frequency = ix2505v_get_frequency,
270};
271
272struct dvb_frontend *ix2505v_attach(struct dvb_frontend *fe,
273 const struct ix2505v_config *config,
274 struct i2c_adapter *i2c)
275{
276 struct ix2505v_state *state = NULL;
277 int ret;
278
279 if (NULL == config) {
280 deb_i2c("%s: no config ", __func__);
281 goto error;
282 }
283
284 state = kzalloc(sizeof(struct ix2505v_state), GFP_KERNEL);
285 if (NULL == state)
286 return NULL;
287
288 state->config = config;
289 state->i2c = i2c;
290
291 if (state->config->tuner_write_only) {
292 if (fe->ops.i2c_gate_ctrl)
293 fe->ops.i2c_gate_ctrl(fe, 1);
294
295 ret = ix2505v_read_status_reg(state);
296
297 if (ret & 0x80) {
298 deb_i2c("%s: No IX2505V found\n", __func__);
299 goto error;
300 }
301
302 if (fe->ops.i2c_gate_ctrl)
303 fe->ops.i2c_gate_ctrl(fe, 0);
304 }
305
306 fe->tuner_priv = state;
307
308 memcpy(&fe->ops.tuner_ops, &ix2505v_tuner_ops,
309 sizeof(struct dvb_tuner_ops));
310 deb_i2c("%s: initialization (%s addr=0x%02x) ok\n",
311 __func__, fe->ops.tuner_ops.info.name, config->tuner_address);
312
313 return fe;
314
315error:
316 kfree(state);
317 return NULL;
318}
319EXPORT_SYMBOL(ix2505v_attach);
320
321module_param_named(debug, ix2505v_debug, int, 0644);
322MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
323MODULE_DESCRIPTION("DVB IX2505V tuner driver");
324MODULE_AUTHOR("Malcolm Priestley");
325MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/ix2505v.h b/drivers/media/dvb/frontends/ix2505v.h
new file mode 100644
index 000000000000..67e89d616d50
--- /dev/null
+++ b/drivers/media/dvb/frontends/ix2505v.h
@@ -0,0 +1,64 @@
1/**
2 * Driver for Sharp IX2505V (marked B0017) DVB-S silicon tuner
3 *
4 * Copyright (C) 2010 Malcolm Priestley
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License Version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#ifndef DVB_IX2505V_H
21#define DVB_IX2505V_H
22
23#include <linux/i2c.h>
24#include "dvb_frontend.h"
25
26/**
27 * Attach a ix2505v tuner to the supplied frontend structure.
28 *
29 * @param fe Frontend to attach to.
30 * @param config ix2505v_config structure
31 * @return FE pointer on success, NULL on failure.
32 */
33
34struct ix2505v_config {
35 u8 tuner_address;
36
37 /*Baseband AMP gain control 0/1=0dB(default) 2=-2bB 3=-4dB */
38 u8 tuner_gain;
39
40 /*Charge pump output +/- 0=120 1=260 2=555 3=1200(default) */
41 u8 tuner_chargepump;
42
43 /* delay after tune */
44 int min_delay_ms;
45
46 /* disables reads*/
47 u8 tuner_write_only;
48
49};
50
51#if defined(CONFIG_DVB_IX2505V) || \
52 (defined(CONFIG_DVB_IX2505V_MODULE) && defined(MODULE))
53extern struct dvb_frontend *ix2505v_attach(struct dvb_frontend *fe,
54 const struct ix2505v_config *config, struct i2c_adapter *i2c);
55#else
56static inline struct dvb_frontend *ix2505v_attach(struct dvb_frontend *fe,
57 const struct ix2505v_config *config, struct i2c_adapter *i2c)
58{
59 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
60 return NULL;
61}
62#endif
63
64#endif /* DVB_IX2505V_H */
diff --git a/drivers/media/dvb/frontends/lgdt3304.c b/drivers/media/dvb/frontends/lgdt3304.c
deleted file mode 100644
index 45a529b06b9d..000000000000
--- a/drivers/media/dvb/frontends/lgdt3304.c
+++ /dev/null
@@ -1,380 +0,0 @@
1/*
2 * Driver for LG ATSC lgdt3304 driver
3 *
4 * Copyright (C) 2008 Markus Rechberger <mrechberger@sundtek.de>
5 *
6 */
7
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/slab.h>
11#include <linux/delay.h>
12#include "dvb_frontend.h"
13#include "lgdt3304.h"
14
15static unsigned int debug = 0;
16module_param(debug, int, 0644);
17MODULE_PARM_DESC(debug,"lgdt3304 debugging (default off)");
18
19#define dprintk(fmt, args...) if (debug) do {\
20 printk("lgdt3304 debug: " fmt, ##args); } while (0)
21
22struct lgdt3304_state
23{
24 struct dvb_frontend frontend;
25 fe_modulation_t current_modulation;
26 __u32 snr;
27 __u32 current_frequency;
28 __u8 addr;
29 struct i2c_adapter *i2c;
30};
31
32static int i2c_write_demod_bytes (struct dvb_frontend *fe, __u8 *buf, int len)
33{
34 struct lgdt3304_state *state = fe->demodulator_priv;
35 struct i2c_msg i2cmsgs = {
36 .addr = state->addr,
37 .flags = 0,
38 .len = 3,
39 .buf = buf
40 };
41 int i;
42 int err;
43
44 for (i=0; i<len-1; i+=3){
45 if((err = i2c_transfer(state->i2c, &i2cmsgs, 1))<0) {
46 printk("%s i2c_transfer error %d\n", __func__, err);
47 if (err < 0)
48 return err;
49 else
50 return -EREMOTEIO;
51 }
52 i2cmsgs.buf += 3;
53 }
54 return 0;
55}
56
57static int lgdt3304_i2c_read_reg(struct dvb_frontend *fe, unsigned int reg)
58{
59 struct lgdt3304_state *state = fe->demodulator_priv;
60 struct i2c_msg i2cmsgs[2];
61 int ret;
62 __u8 buf;
63
64 __u8 regbuf[2] = { reg>>8, reg&0xff };
65
66 i2cmsgs[0].addr = state->addr;
67 i2cmsgs[0].flags = 0;
68 i2cmsgs[0].len = 2;
69 i2cmsgs[0].buf = regbuf;
70
71 i2cmsgs[1].addr = state->addr;
72 i2cmsgs[1].flags = I2C_M_RD;
73 i2cmsgs[1].len = 1;
74 i2cmsgs[1].buf = &buf;
75
76 if((ret = i2c_transfer(state->i2c, i2cmsgs, 2))<0) {
77 printk("%s i2c_transfer error %d\n", __func__, ret);
78 return ret;
79 }
80
81 return buf;
82}
83
84static int lgdt3304_i2c_write_reg(struct dvb_frontend *fe, int reg, int val)
85{
86 struct lgdt3304_state *state = fe->demodulator_priv;
87 char buffer[3] = { reg>>8, reg&0xff, val };
88 int ret;
89
90 struct i2c_msg i2cmsgs = {
91 .addr = state->addr,
92 .flags = 0,
93 .len = 3,
94 .buf=buffer
95 };
96 ret = i2c_transfer(state->i2c, &i2cmsgs, 1);
97 if (ret != 1) {
98 printk("%s i2c_transfer error %d\n", __func__, ret);
99 return ret;
100 }
101
102 return 0;
103}
104
105
106static int lgdt3304_soft_Reset(struct dvb_frontend *fe)
107{
108 lgdt3304_i2c_write_reg(fe, 0x0002, 0x9a);
109 lgdt3304_i2c_write_reg(fe, 0x0002, 0x9b);
110 mdelay(200);
111 return 0;
112}
113
114static int lgdt3304_set_parameters(struct dvb_frontend *fe, struct dvb_frontend_parameters *param) {
115 int err = 0;
116
117 static __u8 lgdt3304_vsb8_data[] = {
118 /* 16bit , 8bit */
119 /* regs , val */
120 0x00, 0x00, 0x02,
121 0x00, 0x00, 0x13,
122 0x00, 0x0d, 0x02,
123 0x00, 0x0e, 0x02,
124 0x00, 0x12, 0x32,
125 0x00, 0x13, 0xc4,
126 0x01, 0x12, 0x17,
127 0x01, 0x13, 0x15,
128 0x01, 0x14, 0x18,
129 0x01, 0x15, 0xff,
130 0x01, 0x16, 0x2c,
131 0x02, 0x14, 0x67,
132 0x02, 0x24, 0x8d,
133 0x04, 0x27, 0x12,
134 0x04, 0x28, 0x4f,
135 0x03, 0x08, 0x80,
136 0x03, 0x09, 0x00,
137 0x03, 0x0d, 0x00,
138 0x03, 0x0e, 0x1c,
139 0x03, 0x14, 0xe1,
140 0x05, 0x0e, 0x5b,
141 };
142
143 /* not yet tested .. */
144 static __u8 lgdt3304_qam64_data[] = {
145 /* 16bit , 8bit */
146 /* regs , val */
147 0x00, 0x00, 0x18,
148 0x00, 0x0d, 0x02,
149 //0x00, 0x0e, 0x02,
150 0x00, 0x12, 0x2a,
151 0x00, 0x13, 0x00,
152 0x03, 0x14, 0xe3,
153 0x03, 0x0e, 0x1c,
154 0x03, 0x08, 0x66,
155 0x03, 0x09, 0x66,
156 0x03, 0x0a, 0x08,
157 0x03, 0x0b, 0x9b,
158 0x05, 0x0e, 0x5b,
159 };
160
161
162 /* tested with KWorld a340 */
163 static __u8 lgdt3304_qam256_data[] = {
164 /* 16bit , 8bit */
165 /* regs , val */
166 0x00, 0x00, 0x01, //0x19,
167 0x00, 0x12, 0x2a,
168 0x00, 0x13, 0x80,
169 0x00, 0x0d, 0x02,
170 0x03, 0x14, 0xe3,
171
172 0x03, 0x0e, 0x1c,
173 0x03, 0x08, 0x66,
174 0x03, 0x09, 0x66,
175 0x03, 0x0a, 0x08,
176 0x03, 0x0b, 0x9b,
177
178 0x03, 0x0d, 0x14,
179 //0x05, 0x0e, 0x5b,
180 0x01, 0x06, 0x4a,
181 0x01, 0x07, 0x3d,
182 0x01, 0x08, 0x70,
183 0x01, 0x09, 0xa3,
184
185 0x05, 0x04, 0xfd,
186
187 0x00, 0x0d, 0x82,
188
189 0x05, 0x0e, 0x5b,
190
191 0x05, 0x0e, 0x5b,
192
193 0x00, 0x02, 0x9a,
194
195 0x00, 0x02, 0x9b,
196
197 0x00, 0x00, 0x01,
198 0x00, 0x12, 0x2a,
199 0x00, 0x13, 0x80,
200 0x00, 0x0d, 0x02,
201 0x03, 0x14, 0xe3,
202
203 0x03, 0x0e, 0x1c,
204 0x03, 0x08, 0x66,
205 0x03, 0x09, 0x66,
206 0x03, 0x0a, 0x08,
207 0x03, 0x0b, 0x9b,
208
209 0x03, 0x0d, 0x14,
210 0x01, 0x06, 0x4a,
211 0x01, 0x07, 0x3d,
212 0x01, 0x08, 0x70,
213 0x01, 0x09, 0xa3,
214
215 0x05, 0x04, 0xfd,
216
217 0x00, 0x0d, 0x82,
218
219 0x05, 0x0e, 0x5b,
220 };
221
222 struct lgdt3304_state *state = fe->demodulator_priv;
223 if (state->current_modulation != param->u.vsb.modulation) {
224 switch(param->u.vsb.modulation) {
225 case VSB_8:
226 err = i2c_write_demod_bytes(fe, lgdt3304_vsb8_data,
227 sizeof(lgdt3304_vsb8_data));
228 break;
229 case QAM_64:
230 err = i2c_write_demod_bytes(fe, lgdt3304_qam64_data,
231 sizeof(lgdt3304_qam64_data));
232 break;
233 case QAM_256:
234 err = i2c_write_demod_bytes(fe, lgdt3304_qam256_data,
235 sizeof(lgdt3304_qam256_data));
236 break;
237 default:
238 break;
239 }
240
241 if (err) {
242 printk("%s error setting modulation\n", __func__);
243 } else {
244 state->current_modulation = param->u.vsb.modulation;
245 }
246 }
247 state->current_frequency = param->frequency;
248
249 lgdt3304_soft_Reset(fe);
250
251
252 if (fe->ops.tuner_ops.set_params)
253 fe->ops.tuner_ops.set_params(fe, param);
254
255 return 0;
256}
257
258static int lgdt3304_init(struct dvb_frontend *fe) {
259 return 0;
260}
261
262static int lgdt3304_sleep(struct dvb_frontend *fe) {
263 return 0;
264}
265
266
267static int lgdt3304_read_status(struct dvb_frontend *fe, fe_status_t *status)
268{
269 struct lgdt3304_state *state = fe->demodulator_priv;
270 int r011d;
271 int qam_lck;
272
273 *status = 0;
274 dprintk("lgdt read status\n");
275
276 r011d = lgdt3304_i2c_read_reg(fe, 0x011d);
277
278 dprintk("%02x\n", r011d);
279
280 switch(state->current_modulation) {
281 case VSB_8:
282 if (r011d & 0x80) {
283 dprintk("VSB Locked\n");
284 *status |= FE_HAS_CARRIER;
285 *status |= FE_HAS_LOCK;
286 *status |= FE_HAS_SYNC;
287 *status |= FE_HAS_SIGNAL;
288 }
289 break;
290 case QAM_64:
291 case QAM_256:
292 qam_lck = r011d & 0x7;
293 switch(qam_lck) {
294 case 0x0: dprintk("Unlock\n");
295 break;
296 case 0x4: dprintk("1st Lock in acquisition state\n");
297 break;
298 case 0x6: dprintk("2nd Lock in acquisition state\n");
299 break;
300 case 0x7: dprintk("Final Lock in good reception state\n");
301 *status |= FE_HAS_CARRIER;
302 *status |= FE_HAS_LOCK;
303 *status |= FE_HAS_SYNC;
304 *status |= FE_HAS_SIGNAL;
305 break;
306 }
307 break;
308 default:
309 printk("%s unhandled modulation\n", __func__);
310 }
311
312
313 return 0;
314}
315
316static int lgdt3304_read_ber(struct dvb_frontend *fe, __u32 *ber)
317{
318 dprintk("read ber\n");
319 return 0;
320}
321
322static int lgdt3304_read_snr(struct dvb_frontend *fe, __u16 *snr)
323{
324 dprintk("read snr\n");
325 return 0;
326}
327
328static int lgdt3304_read_ucblocks(struct dvb_frontend *fe, __u32 *ucblocks)
329{
330 dprintk("read ucblocks\n");
331 return 0;
332}
333
334static void lgdt3304_release(struct dvb_frontend *fe)
335{
336 struct lgdt3304_state *state = (struct lgdt3304_state *)fe->demodulator_priv;
337 kfree(state);
338}
339
340static struct dvb_frontend_ops demod_lgdt3304={
341 .info = {
342 .name = "LG 3304",
343 .type = FE_ATSC,
344 .frequency_min = 54000000,
345 .frequency_max = 858000000,
346 .frequency_stepsize = 62500,
347 .symbol_rate_min = 5056941,
348 .symbol_rate_max = 10762000,
349 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
350 },
351 .init = lgdt3304_init,
352 .sleep = lgdt3304_sleep,
353 .set_frontend = lgdt3304_set_parameters,
354 .read_snr = lgdt3304_read_snr,
355 .read_ber = lgdt3304_read_ber,
356 .read_status = lgdt3304_read_status,
357 .read_ucblocks = lgdt3304_read_ucblocks,
358 .release = lgdt3304_release,
359};
360
361struct dvb_frontend* lgdt3304_attach(const struct lgdt3304_config *config,
362 struct i2c_adapter *i2c)
363{
364
365 struct lgdt3304_state *state;
366 state = kzalloc(sizeof(struct lgdt3304_state), GFP_KERNEL);
367 if (state == NULL)
368 return NULL;
369 state->addr = config->i2c_address;
370 state->i2c = i2c;
371
372 memcpy(&state->frontend.ops, &demod_lgdt3304, sizeof(struct dvb_frontend_ops));
373 state->frontend.demodulator_priv = state;
374 return &state->frontend;
375}
376
377EXPORT_SYMBOL_GPL(lgdt3304_attach);
378MODULE_AUTHOR("Markus Rechberger <mrechberger@empiatech.com>");
379MODULE_DESCRIPTION("LGE LGDT3304 DVB-T demodulator driver");
380MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/lgdt3304.h b/drivers/media/dvb/frontends/lgdt3304.h
deleted file mode 100644
index fc409fe59acb..000000000000
--- a/drivers/media/dvb/frontends/lgdt3304.h
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2 * Driver for DVB-T lgdt3304 demodulator
3 *
4 * Copyright (C) 2008 Markus Rechberger <mrechberger@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20 */
21
22#ifndef LGDT3304_H
23#define LGDT3304_H
24
25#include <linux/dvb/frontend.h>
26
27struct lgdt3304_config
28{
29 /* demodulator's I2C address */
30 u8 i2c_address;
31};
32
33#if defined(CONFIG_DVB_LGDT3304) || (defined(CONFIG_DVB_LGDT3304_MODULE) && defined(MODULE))
34extern struct dvb_frontend* lgdt3304_attach(const struct lgdt3304_config *config,
35 struct i2c_adapter *i2c);
36#else
37static inline struct dvb_frontend* lgdt3304_attach(const struct lgdt3304_config *config,
38 struct i2c_adapter *i2c)
39{
40 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
41 return NULL;
42}
43#endif /* CONFIG_DVB_LGDT */
44
45#endif /* LGDT3304_H */
diff --git a/drivers/media/dvb/frontends/lgs8gxx.c b/drivers/media/dvb/frontends/lgs8gxx.c
index 5ea28ae2ba8f..1172b54689f8 100644
--- a/drivers/media/dvb/frontends/lgs8gxx.c
+++ b/drivers/media/dvb/frontends/lgs8gxx.c
@@ -60,13 +60,12 @@ static int lgs8gxx_write_reg(struct lgs8gxx_state *priv, u8 reg, u8 data)
60 msg.addr += 0x02; 60 msg.addr += 0x02;
61 61
62 if (debug >= 2) 62 if (debug >= 2)
63 printk(KERN_DEBUG "%s: reg=0x%02X, data=0x%02X\n", 63 dprintk("%s: reg=0x%02X, data=0x%02X\n", __func__, reg, data);
64 __func__, reg, data);
65 64
66 ret = i2c_transfer(priv->i2c, &msg, 1); 65 ret = i2c_transfer(priv->i2c, &msg, 1);
67 66
68 if (ret != 1) 67 if (ret != 1)
69 dprintk(KERN_DEBUG "%s: error reg=0x%x, data=0x%x, ret=%i\n", 68 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
70 __func__, reg, data, ret); 69 __func__, reg, data, ret);
71 70
72 return (ret != 1) ? -1 : 0; 71 return (ret != 1) ? -1 : 0;
@@ -91,15 +90,13 @@ static int lgs8gxx_read_reg(struct lgs8gxx_state *priv, u8 reg, u8 *p_data)
91 90
92 ret = i2c_transfer(priv->i2c, msg, 2); 91 ret = i2c_transfer(priv->i2c, msg, 2);
93 if (ret != 2) { 92 if (ret != 2) {
94 dprintk(KERN_DEBUG "%s: error reg=0x%x, ret=%i\n", 93 dprintk("%s: error reg=0x%x, ret=%i\n", __func__, reg, ret);
95 __func__, reg, ret);
96 return -1; 94 return -1;
97 } 95 }
98 96
99 *p_data = b1[0]; 97 *p_data = b1[0];
100 if (debug >= 2) 98 if (debug >= 2)
101 printk(KERN_DEBUG "%s: reg=0x%02X, data=0x%02X\n", 99 dprintk("%s: reg=0x%02X, data=0x%02X\n", __func__, reg, b1[0]);
102 __func__, reg, b1[0]);
103 return 0; 100 return 0;
104} 101}
105 102
@@ -662,7 +659,7 @@ static void lgs8gxx_release(struct dvb_frontend *fe)
662} 659}
663 660
664 661
665static int lgs8gxx_write(struct dvb_frontend *fe, u8 *buf, int len) 662static int lgs8gxx_write(struct dvb_frontend *fe, const u8 buf[], int len)
666{ 663{
667 struct lgs8gxx_state *priv = fe->demodulator_priv; 664 struct lgs8gxx_state *priv = fe->demodulator_priv;
668 665
diff --git a/drivers/media/dvb/frontends/mb86a16.c b/drivers/media/dvb/frontends/mb86a16.c
index 33b63235b86e..c283112051b1 100644
--- a/drivers/media/dvb/frontends/mb86a16.c
+++ b/drivers/media/dvb/frontends/mb86a16.c
@@ -1630,7 +1630,7 @@ static enum dvbfe_search mb86a16_search(struct dvb_frontend *fe,
1630 state->srate = p->u.qpsk.symbol_rate / 1000; 1630 state->srate = p->u.qpsk.symbol_rate / 1000;
1631 1631
1632 if (!mb86a16_set_fe(state)) { 1632 if (!mb86a16_set_fe(state)) {
1633 dprintk(verbose, MB86A16_ERROR, 1, "Succesfully acquired LOCK"); 1633 dprintk(verbose, MB86A16_ERROR, 1, "Successfully acquired LOCK");
1634 return DVBFE_ALGO_SEARCH_SUCCESS; 1634 return DVBFE_ALGO_SEARCH_SUCCESS;
1635 } 1635 }
1636 1636
diff --git a/drivers/media/dvb/frontends/mb86a20s.c b/drivers/media/dvb/frontends/mb86a20s.c
new file mode 100644
index 000000000000..0f867a5055fb
--- /dev/null
+++ b/drivers/media/dvb/frontends/mb86a20s.c
@@ -0,0 +1,639 @@
1/*
2 * Fujitu mb86a20s ISDB-T/ISDB-Tsb Module driver
3 *
4 * Copyright (C) 2010 Mauro Carvalho Chehab <mchehab@redhat.com>
5 * Copyright (C) 2009-2010 Douglas Landgraf <dougsland@redhat.com>
6 *
7 * FIXME: Need to port to DVB v5.2 API
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation version 2.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
19#include <linux/kernel.h>
20#include <asm/div64.h>
21
22#include "dvb_frontend.h"
23#include "mb86a20s.h"
24
25static int debug = 1;
26module_param(debug, int, 0644);
27MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
28
29#define rc(args...) do { \
30 printk(KERN_ERR "mb86a20s: " args); \
31} while (0)
32
33#define dprintk(args...) \
34 do { \
35 if (debug) { \
36 printk(KERN_DEBUG "mb86a20s: %s: ", __func__); \
37 printk(args); \
38 } \
39 } while (0)
40
41struct mb86a20s_state {
42 struct i2c_adapter *i2c;
43 const struct mb86a20s_config *config;
44
45 struct dvb_frontend frontend;
46
47 bool need_init;
48};
49
50struct regdata {
51 u8 reg;
52 u8 data;
53};
54
55/*
56 * Initialization sequence: Use whatevere default values that PV SBTVD
57 * does on its initialisation, obtained via USB snoop
58 */
59static struct regdata mb86a20s_init[] = {
60 { 0x70, 0x0f },
61 { 0x70, 0xff },
62 { 0x08, 0x01 },
63 { 0x09, 0x3e },
64 { 0x50, 0xd1 },
65 { 0x51, 0x22 },
66 { 0x39, 0x01 },
67 { 0x71, 0x00 },
68 { 0x28, 0x2a },
69 { 0x29, 0x00 },
70 { 0x2a, 0xff },
71 { 0x2b, 0x80 },
72 { 0x28, 0x20 },
73 { 0x29, 0x33 },
74 { 0x2a, 0xdf },
75 { 0x2b, 0xa9 },
76 { 0x3b, 0x21 },
77 { 0x3c, 0x3a },
78 { 0x01, 0x0d },
79 { 0x04, 0x08 },
80 { 0x05, 0x05 },
81 { 0x04, 0x0e },
82 { 0x05, 0x00 },
83 { 0x04, 0x0f },
84 { 0x05, 0x14 },
85 { 0x04, 0x0b },
86 { 0x05, 0x8c },
87 { 0x04, 0x00 },
88 { 0x05, 0x00 },
89 { 0x04, 0x01 },
90 { 0x05, 0x07 },
91 { 0x04, 0x02 },
92 { 0x05, 0x0f },
93 { 0x04, 0x03 },
94 { 0x05, 0xa0 },
95 { 0x04, 0x09 },
96 { 0x05, 0x00 },
97 { 0x04, 0x0a },
98 { 0x05, 0xff },
99 { 0x04, 0x27 },
100 { 0x05, 0x64 },
101 { 0x04, 0x28 },
102 { 0x05, 0x00 },
103 { 0x04, 0x1e },
104 { 0x05, 0xff },
105 { 0x04, 0x29 },
106 { 0x05, 0x0a },
107 { 0x04, 0x32 },
108 { 0x05, 0x0a },
109 { 0x04, 0x14 },
110 { 0x05, 0x02 },
111 { 0x04, 0x04 },
112 { 0x05, 0x00 },
113 { 0x04, 0x05 },
114 { 0x05, 0x22 },
115 { 0x04, 0x06 },
116 { 0x05, 0x0e },
117 { 0x04, 0x07 },
118 { 0x05, 0xd8 },
119 { 0x04, 0x12 },
120 { 0x05, 0x00 },
121 { 0x04, 0x13 },
122 { 0x05, 0xff },
123 { 0x52, 0x01 },
124 { 0x50, 0xa7 },
125 { 0x51, 0x00 },
126 { 0x50, 0xa8 },
127 { 0x51, 0xff },
128 { 0x50, 0xa9 },
129 { 0x51, 0xff },
130 { 0x50, 0xaa },
131 { 0x51, 0x00 },
132 { 0x50, 0xab },
133 { 0x51, 0xff },
134 { 0x50, 0xac },
135 { 0x51, 0xff },
136 { 0x50, 0xad },
137 { 0x51, 0x00 },
138 { 0x50, 0xae },
139 { 0x51, 0xff },
140 { 0x50, 0xaf },
141 { 0x51, 0xff },
142 { 0x5e, 0x07 },
143 { 0x50, 0xdc },
144 { 0x51, 0x01 },
145 { 0x50, 0xdd },
146 { 0x51, 0xf4 },
147 { 0x50, 0xde },
148 { 0x51, 0x01 },
149 { 0x50, 0xdf },
150 { 0x51, 0xf4 },
151 { 0x50, 0xe0 },
152 { 0x51, 0x01 },
153 { 0x50, 0xe1 },
154 { 0x51, 0xf4 },
155 { 0x50, 0xb0 },
156 { 0x51, 0x07 },
157 { 0x50, 0xb2 },
158 { 0x51, 0xff },
159 { 0x50, 0xb3 },
160 { 0x51, 0xff },
161 { 0x50, 0xb4 },
162 { 0x51, 0xff },
163 { 0x50, 0xb5 },
164 { 0x51, 0xff },
165 { 0x50, 0xb6 },
166 { 0x51, 0xff },
167 { 0x50, 0xb7 },
168 { 0x51, 0xff },
169 { 0x50, 0x50 },
170 { 0x51, 0x02 },
171 { 0x50, 0x51 },
172 { 0x51, 0x04 },
173 { 0x45, 0x04 },
174 { 0x48, 0x04 },
175 { 0x50, 0xd5 },
176 { 0x51, 0x01 }, /* Serial */
177 { 0x50, 0xd6 },
178 { 0x51, 0x1f },
179 { 0x50, 0xd2 },
180 { 0x51, 0x03 },
181 { 0x50, 0xd7 },
182 { 0x51, 0x3f },
183 { 0x1c, 0x01 },
184 { 0x28, 0x06 },
185 { 0x29, 0x00 },
186 { 0x2a, 0x00 },
187 { 0x2b, 0x03 },
188 { 0x28, 0x07 },
189 { 0x29, 0x00 },
190 { 0x2a, 0x00 },
191 { 0x2b, 0x0d },
192 { 0x28, 0x08 },
193 { 0x29, 0x00 },
194 { 0x2a, 0x00 },
195 { 0x2b, 0x02 },
196 { 0x28, 0x09 },
197 { 0x29, 0x00 },
198 { 0x2a, 0x00 },
199 { 0x2b, 0x01 },
200 { 0x28, 0x0a },
201 { 0x29, 0x00 },
202 { 0x2a, 0x00 },
203 { 0x2b, 0x21 },
204 { 0x28, 0x0b },
205 { 0x29, 0x00 },
206 { 0x2a, 0x00 },
207 { 0x2b, 0x29 },
208 { 0x28, 0x0c },
209 { 0x29, 0x00 },
210 { 0x2a, 0x00 },
211 { 0x2b, 0x16 },
212 { 0x28, 0x0d },
213 { 0x29, 0x00 },
214 { 0x2a, 0x00 },
215 { 0x2b, 0x31 },
216 { 0x28, 0x0e },
217 { 0x29, 0x00 },
218 { 0x2a, 0x00 },
219 { 0x2b, 0x0e },
220 { 0x28, 0x0f },
221 { 0x29, 0x00 },
222 { 0x2a, 0x00 },
223 { 0x2b, 0x4e },
224 { 0x28, 0x10 },
225 { 0x29, 0x00 },
226 { 0x2a, 0x00 },
227 { 0x2b, 0x46 },
228 { 0x28, 0x11 },
229 { 0x29, 0x00 },
230 { 0x2a, 0x00 },
231 { 0x2b, 0x0f },
232 { 0x28, 0x12 },
233 { 0x29, 0x00 },
234 { 0x2a, 0x00 },
235 { 0x2b, 0x56 },
236 { 0x28, 0x13 },
237 { 0x29, 0x00 },
238 { 0x2a, 0x00 },
239 { 0x2b, 0x35 },
240 { 0x28, 0x14 },
241 { 0x29, 0x00 },
242 { 0x2a, 0x01 },
243 { 0x2b, 0xbe },
244 { 0x28, 0x15 },
245 { 0x29, 0x00 },
246 { 0x2a, 0x01 },
247 { 0x2b, 0x84 },
248 { 0x28, 0x16 },
249 { 0x29, 0x00 },
250 { 0x2a, 0x03 },
251 { 0x2b, 0xee },
252 { 0x28, 0x17 },
253 { 0x29, 0x00 },
254 { 0x2a, 0x00 },
255 { 0x2b, 0x98 },
256 { 0x28, 0x18 },
257 { 0x29, 0x00 },
258 { 0x2a, 0x00 },
259 { 0x2b, 0x9f },
260 { 0x28, 0x19 },
261 { 0x29, 0x00 },
262 { 0x2a, 0x07 },
263 { 0x2b, 0xb2 },
264 { 0x28, 0x1a },
265 { 0x29, 0x00 },
266 { 0x2a, 0x06 },
267 { 0x2b, 0xc2 },
268 { 0x28, 0x1b },
269 { 0x29, 0x00 },
270 { 0x2a, 0x07 },
271 { 0x2b, 0x4a },
272 { 0x28, 0x1c },
273 { 0x29, 0x00 },
274 { 0x2a, 0x01 },
275 { 0x2b, 0xbc },
276 { 0x28, 0x1d },
277 { 0x29, 0x00 },
278 { 0x2a, 0x04 },
279 { 0x2b, 0xba },
280 { 0x28, 0x1e },
281 { 0x29, 0x00 },
282 { 0x2a, 0x06 },
283 { 0x2b, 0x14 },
284 { 0x50, 0x1e },
285 { 0x51, 0x5d },
286 { 0x50, 0x22 },
287 { 0x51, 0x00 },
288 { 0x50, 0x23 },
289 { 0x51, 0xc8 },
290 { 0x50, 0x24 },
291 { 0x51, 0x00 },
292 { 0x50, 0x25 },
293 { 0x51, 0xf0 },
294 { 0x50, 0x26 },
295 { 0x51, 0x00 },
296 { 0x50, 0x27 },
297 { 0x51, 0xc3 },
298 { 0x50, 0x39 },
299 { 0x51, 0x02 },
300 { 0x50, 0xd5 },
301 { 0x51, 0x01 },
302 { 0xd0, 0x00 },
303};
304
305static struct regdata mb86a20s_reset_reception[] = {
306 { 0x70, 0xf0 },
307 { 0x70, 0xff },
308 { 0x08, 0x01 },
309 { 0x08, 0x00 },
310};
311
312static int mb86a20s_i2c_writereg(struct mb86a20s_state *state,
313 u8 i2c_addr, int reg, int data)
314{
315 u8 buf[] = { reg, data };
316 struct i2c_msg msg = {
317 .addr = i2c_addr, .flags = 0, .buf = buf, .len = 2
318 };
319 int rc;
320
321 rc = i2c_transfer(state->i2c, &msg, 1);
322 if (rc != 1) {
323 printk("%s: writereg error (rc == %i, reg == 0x%02x,"
324 " data == 0x%02x)\n", __func__, rc, reg, data);
325 return rc;
326 }
327
328 return 0;
329}
330
331static int mb86a20s_i2c_writeregdata(struct mb86a20s_state *state,
332 u8 i2c_addr, struct regdata *rd, int size)
333{
334 int i, rc;
335
336 for (i = 0; i < size; i++) {
337 rc = mb86a20s_i2c_writereg(state, i2c_addr, rd[i].reg,
338 rd[i].data);
339 if (rc < 0)
340 return rc;
341 }
342 return 0;
343}
344
345static int mb86a20s_i2c_readreg(struct mb86a20s_state *state,
346 u8 i2c_addr, u8 reg)
347{
348 u8 val;
349 int rc;
350 struct i2c_msg msg[] = {
351 { .addr = i2c_addr, .flags = 0, .buf = &reg, .len = 1 },
352 { .addr = i2c_addr, .flags = I2C_M_RD, .buf = &val, .len = 1 }
353 };
354
355 rc = i2c_transfer(state->i2c, msg, 2);
356
357 if (rc != 2) {
358 rc("%s: reg=0x%x (error=%d)\n", __func__, reg, rc);
359 return rc;
360 }
361
362 return val;
363}
364
365#define mb86a20s_readreg(state, reg) \
366 mb86a20s_i2c_readreg(state, state->config->demod_address, reg)
367#define mb86a20s_writereg(state, reg, val) \
368 mb86a20s_i2c_writereg(state, state->config->demod_address, reg, val)
369#define mb86a20s_writeregdata(state, regdata) \
370 mb86a20s_i2c_writeregdata(state, state->config->demod_address, \
371 regdata, ARRAY_SIZE(regdata))
372
373static int mb86a20s_initfe(struct dvb_frontend *fe)
374{
375 struct mb86a20s_state *state = fe->demodulator_priv;
376 int rc;
377 u8 regD5 = 1;
378
379 dprintk("\n");
380
381 if (fe->ops.i2c_gate_ctrl)
382 fe->ops.i2c_gate_ctrl(fe, 0);
383
384 /* Initialize the frontend */
385 rc = mb86a20s_writeregdata(state, mb86a20s_init);
386 if (rc < 0)
387 goto err;
388
389 if (!state->config->is_serial) {
390 regD5 &= ~1;
391
392 rc = mb86a20s_writereg(state, 0x50, 0xd5);
393 if (rc < 0)
394 goto err;
395 rc = mb86a20s_writereg(state, 0x51, regD5);
396 if (rc < 0)
397 goto err;
398 }
399
400 if (fe->ops.i2c_gate_ctrl)
401 fe->ops.i2c_gate_ctrl(fe, 1);
402
403err:
404 if (rc < 0) {
405 state->need_init = true;
406 printk(KERN_INFO "mb86a20s: Init failed. Will try again later\n");
407 } else {
408 state->need_init = false;
409 dprintk("Initialization succeeded.\n");
410 }
411 return rc;
412}
413
414static int mb86a20s_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
415{
416 struct mb86a20s_state *state = fe->demodulator_priv;
417 unsigned rf_max, rf_min, rf;
418 u8 val;
419
420 dprintk("\n");
421
422 if (fe->ops.i2c_gate_ctrl)
423 fe->ops.i2c_gate_ctrl(fe, 0);
424
425 /* Does a binary search to get RF strength */
426 rf_max = 0xfff;
427 rf_min = 0;
428 do {
429 rf = (rf_max + rf_min) / 2;
430 mb86a20s_writereg(state, 0x04, 0x1f);
431 mb86a20s_writereg(state, 0x05, rf >> 8);
432 mb86a20s_writereg(state, 0x04, 0x20);
433 mb86a20s_writereg(state, 0x04, rf);
434
435 val = mb86a20s_readreg(state, 0x02);
436 if (val & 0x08)
437 rf_min = (rf_max + rf_min) / 2;
438 else
439 rf_max = (rf_max + rf_min) / 2;
440 if (rf_max - rf_min < 4) {
441 *strength = (((rf_max + rf_min) / 2) * 65535) / 4095;
442 break;
443 }
444 } while (1);
445
446 dprintk("signal strength = %d\n", *strength);
447
448 if (fe->ops.i2c_gate_ctrl)
449 fe->ops.i2c_gate_ctrl(fe, 1);
450
451 return 0;
452}
453
454static int mb86a20s_read_status(struct dvb_frontend *fe, fe_status_t *status)
455{
456 struct mb86a20s_state *state = fe->demodulator_priv;
457 u8 val;
458
459 dprintk("\n");
460 *status = 0;
461
462 if (fe->ops.i2c_gate_ctrl)
463 fe->ops.i2c_gate_ctrl(fe, 0);
464 val = mb86a20s_readreg(state, 0x0a) & 0xf;
465 if (fe->ops.i2c_gate_ctrl)
466 fe->ops.i2c_gate_ctrl(fe, 1);
467
468 if (val >= 2)
469 *status |= FE_HAS_SIGNAL;
470
471 if (val >= 4)
472 *status |= FE_HAS_CARRIER;
473
474 if (val >= 5)
475 *status |= FE_HAS_VITERBI;
476
477 if (val >= 7)
478 *status |= FE_HAS_SYNC;
479
480 if (val >= 8) /* Maybe 9? */
481 *status |= FE_HAS_LOCK;
482
483 dprintk("val = %d, status = 0x%02x\n", val, *status);
484
485 return 0;
486}
487
488static int mb86a20s_set_frontend(struct dvb_frontend *fe,
489 struct dvb_frontend_parameters *p)
490{
491 struct mb86a20s_state *state = fe->demodulator_priv;
492 int rc;
493
494 dprintk("\n");
495
496 if (fe->ops.i2c_gate_ctrl)
497 fe->ops.i2c_gate_ctrl(fe, 1);
498 dprintk("Calling tuner set parameters\n");
499 fe->ops.tuner_ops.set_params(fe, p);
500
501 /*
502 * Make it more reliable: if, for some reason, the initial
503 * device initialization doesn't happen, initialize it when
504 * a SBTVD parameters are adjusted.
505 *
506 * Unfortunately, due to a hard to track bug at tda829x/tda18271,
507 * the agc callback logic is not called during DVB attach time,
508 * causing mb86a20s to not be initialized with Kworld SBTVD.
509 * So, this hack is needed, in order to make Kworld SBTVD to work.
510 */
511 if (state->need_init)
512 mb86a20s_initfe(fe);
513
514 if (fe->ops.i2c_gate_ctrl)
515 fe->ops.i2c_gate_ctrl(fe, 0);
516 rc = mb86a20s_writeregdata(state, mb86a20s_reset_reception);
517 if (fe->ops.i2c_gate_ctrl)
518 fe->ops.i2c_gate_ctrl(fe, 1);
519
520 return rc;
521}
522
523static int mb86a20s_get_frontend(struct dvb_frontend *fe,
524 struct dvb_frontend_parameters *p)
525{
526
527 /* FIXME: For now, it does nothing */
528
529 fe->dtv_property_cache.bandwidth_hz = 6000000;
530 fe->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_AUTO;
531 fe->dtv_property_cache.guard_interval = GUARD_INTERVAL_AUTO;
532 fe->dtv_property_cache.isdbt_partial_reception = 0;
533
534 return 0;
535}
536
537static int mb86a20s_tune(struct dvb_frontend *fe,
538 struct dvb_frontend_parameters *params,
539 unsigned int mode_flags,
540 unsigned int *delay,
541 fe_status_t *status)
542{
543 int rc = 0;
544
545 dprintk("\n");
546
547 if (params != NULL)
548 rc = mb86a20s_set_frontend(fe, params);
549
550 if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
551 mb86a20s_read_status(fe, status);
552
553 return rc;
554}
555
556static void mb86a20s_release(struct dvb_frontend *fe)
557{
558 struct mb86a20s_state *state = fe->demodulator_priv;
559
560 dprintk("\n");
561
562 kfree(state);
563}
564
565static struct dvb_frontend_ops mb86a20s_ops;
566
567struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
568 struct i2c_adapter *i2c)
569{
570 u8 rev;
571
572 /* allocate memory for the internal state */
573 struct mb86a20s_state *state =
574 kzalloc(sizeof(struct mb86a20s_state), GFP_KERNEL);
575
576 dprintk("\n");
577 if (state == NULL) {
578 rc("Unable to kzalloc\n");
579 goto error;
580 }
581
582 /* setup the state */
583 state->config = config;
584 state->i2c = i2c;
585
586 /* create dvb_frontend */
587 memcpy(&state->frontend.ops, &mb86a20s_ops,
588 sizeof(struct dvb_frontend_ops));
589 state->frontend.demodulator_priv = state;
590
591 /* Check if it is a mb86a20s frontend */
592 rev = mb86a20s_readreg(state, 0);
593
594 if (rev == 0x13) {
595 printk(KERN_INFO "Detected a Fujitsu mb86a20s frontend\n");
596 } else {
597 printk(KERN_ERR "Frontend revision %d is unknown - aborting.\n",
598 rev);
599 goto error;
600 }
601
602 return &state->frontend;
603
604error:
605 kfree(state);
606 return NULL;
607}
608EXPORT_SYMBOL(mb86a20s_attach);
609
610static struct dvb_frontend_ops mb86a20s_ops = {
611 /* Use dib8000 values per default */
612 .info = {
613 .name = "Fujitsu mb86A20s",
614 .type = FE_OFDM,
615 .caps = FE_CAN_INVERSION_AUTO | FE_CAN_RECOVER |
616 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
617 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
618 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
619 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_QAM_AUTO |
620 FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO,
621 /* Actually, those values depend on the used tuner */
622 .frequency_min = 45000000,
623 .frequency_max = 864000000,
624 .frequency_stepsize = 62500,
625 },
626
627 .release = mb86a20s_release,
628
629 .init = mb86a20s_initfe,
630 .set_frontend = mb86a20s_set_frontend,
631 .get_frontend = mb86a20s_get_frontend,
632 .read_status = mb86a20s_read_status,
633 .read_signal_strength = mb86a20s_read_signal_strength,
634 .tune = mb86a20s_tune,
635};
636
637MODULE_DESCRIPTION("DVB Frontend module for Fujitsu mb86A20s hardware");
638MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
639MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/mb86a20s.h b/drivers/media/dvb/frontends/mb86a20s.h
new file mode 100644
index 000000000000..bf22e77888b9
--- /dev/null
+++ b/drivers/media/dvb/frontends/mb86a20s.h
@@ -0,0 +1,52 @@
1/*
2 * Fujitsu mb86a20s driver
3 *
4 * Copyright (C) 2010 Mauro Carvalho Chehab <mchehab@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#ifndef MB86A20S_H
17#define MB86A20S_H
18
19#include <linux/dvb/frontend.h>
20
21/**
22 * struct mb86a20s_config - Define the per-device attributes of the frontend
23 *
24 * @demod_address: the demodulator's i2c address
25 */
26
27struct mb86a20s_config {
28 u8 demod_address;
29 bool is_serial;
30};
31
32#if defined(CONFIG_DVB_MB86A20S) || (defined(CONFIG_DVB_MB86A20S_MODULE) \
33 && defined(MODULE))
34extern struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
35 struct i2c_adapter *i2c);
36extern struct i2c_adapter *mb86a20s_get_tuner_i2c_adapter(struct dvb_frontend *);
37#else
38static inline struct dvb_frontend *mb86a20s_attach(
39 const struct mb86a20s_config *config, struct i2c_adapter *i2c)
40{
41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
42 return NULL;
43}
44static struct i2c_adapter *
45 mb86a20s_get_tuner_i2c_adapter(struct dvb_frontend *fe)
46{
47 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
48 return NULL;
49}
50#endif
51
52#endif /* MB86A20S */
diff --git a/drivers/media/dvb/frontends/mt312.c b/drivers/media/dvb/frontends/mt312.c
index 472907d43460..83e6f1a1b700 100644
--- a/drivers/media/dvb/frontends/mt312.c
+++ b/drivers/media/dvb/frontends/mt312.c
@@ -670,7 +670,7 @@ static int mt312_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
670 if (ret < 0) 670 if (ret < 0)
671 goto error; 671 goto error;
672 672
673 /* preserve this bit to not accidently shutdown ADC */ 673 /* preserve this bit to not accidentally shutdown ADC */
674 val &= 0x80; 674 val &= 0x80;
675 break; 675 break;
676 } 676 }
diff --git a/drivers/media/dvb/frontends/mt352.c b/drivers/media/dvb/frontends/mt352.c
index beba5aa0db50..319672f8e1a7 100644
--- a/drivers/media/dvb/frontends/mt352.c
+++ b/drivers/media/dvb/frontends/mt352.c
@@ -69,7 +69,7 @@ static int mt352_single_write(struct dvb_frontend *fe, u8 reg, u8 val)
69 return 0; 69 return 0;
70} 70}
71 71
72static int _mt352_write(struct dvb_frontend* fe, u8* ibuf, int ilen) 72static int _mt352_write(struct dvb_frontend* fe, const u8 ibuf[], int ilen)
73{ 73{
74 int err,i; 74 int err,i;
75 for (i=0; i < ilen-1; i++) 75 for (i=0; i < ilen-1; i++)
diff --git a/drivers/media/dvb/frontends/mt352.h b/drivers/media/dvb/frontends/mt352.h
index 595092f9f0c4..ca2562d6f289 100644
--- a/drivers/media/dvb/frontends/mt352.h
+++ b/drivers/media/dvb/frontends/mt352.h
@@ -63,7 +63,7 @@ static inline struct dvb_frontend* mt352_attach(const struct mt352_config* confi
63} 63}
64#endif // CONFIG_DVB_MT352 64#endif // CONFIG_DVB_MT352
65 65
66static inline int mt352_write(struct dvb_frontend *fe, u8 *buf, int len) { 66static inline int mt352_write(struct dvb_frontend *fe, const u8 buf[], int len) {
67 int r = 0; 67 int r = 0;
68 if (fe->ops.write) 68 if (fe->ops.write)
69 r = fe->ops.write(fe, buf, len); 69 r = fe->ops.write(fe, buf, len);
diff --git a/drivers/media/dvb/frontends/s5h1420.c b/drivers/media/dvb/frontends/s5h1420.c
index 2e9fd2893ede..17f8cdf8afef 100644
--- a/drivers/media/dvb/frontends/s5h1420.c
+++ b/drivers/media/dvb/frontends/s5h1420.c
@@ -225,7 +225,7 @@ static int s5h1420_recv_slave_reply (struct dvb_frontend* fe,
225 unsigned long timeout; 225 unsigned long timeout;
226 int result = 0; 226 int result = 0;
227 227
228 /* setup for DISEQC recieve */ 228 /* setup for DISEQC receive */
229 val = s5h1420_readreg(state, 0x3b); 229 val = s5h1420_readreg(state, 0x3b);
230 s5h1420_writereg(state, 0x3b, 0x82); /* FIXME: guess - do we need to set DIS_RDY(0x08) in receive mode? */ 230 s5h1420_writereg(state, 0x3b, 0x82); /* FIXME: guess - do we need to set DIS_RDY(0x08) in receive mode? */
231 msleep(15); 231 msleep(15);
@@ -920,7 +920,6 @@ struct dvb_frontend *s5h1420_attach(const struct s5h1420_config *config,
920 /* create tuner i2c adapter */ 920 /* create tuner i2c adapter */
921 strlcpy(state->tuner_i2c_adapter.name, "S5H1420-PN1010 tuner I2C bus", 921 strlcpy(state->tuner_i2c_adapter.name, "S5H1420-PN1010 tuner I2C bus",
922 sizeof(state->tuner_i2c_adapter.name)); 922 sizeof(state->tuner_i2c_adapter.name));
923 state->tuner_i2c_adapter.class = I2C_CLASS_TV_DIGITAL,
924 state->tuner_i2c_adapter.algo = &s5h1420_tuner_i2c_algo; 923 state->tuner_i2c_adapter.algo = &s5h1420_tuner_i2c_algo;
925 state->tuner_i2c_adapter.algo_data = NULL; 924 state->tuner_i2c_adapter.algo_data = NULL;
926 i2c_set_adapdata(&state->tuner_i2c_adapter, state); 925 i2c_set_adapdata(&state->tuner_i2c_adapter, state);
diff --git a/drivers/media/dvb/frontends/s5h1432.c b/drivers/media/dvb/frontends/s5h1432.c
new file mode 100644
index 000000000000..0c6dcb90d168
--- /dev/null
+++ b/drivers/media/dvb/frontends/s5h1432.c
@@ -0,0 +1,415 @@
1/*
2 * Samsung s5h1432 DVB-T demodulator driver
3 *
4 * Copyright (C) 2009 Bill Liu <Bill.Liu@Conexant.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/string.h>
25#include <linux/slab.h>
26#include <linux/delay.h>
27#include "dvb_frontend.h"
28#include "s5h1432.h"
29
30struct s5h1432_state {
31
32 struct i2c_adapter *i2c;
33
34 /* configuration settings */
35 const struct s5h1432_config *config;
36
37 struct dvb_frontend frontend;
38
39 fe_modulation_t current_modulation;
40 unsigned int first_tune:1;
41
42 u32 current_frequency;
43 int if_freq;
44
45 u8 inversion;
46};
47
48static int debug;
49
50#define dprintk(arg...) do { \
51 if (debug) \
52 printk(arg); \
53 } while (0)
54
55static int s5h1432_writereg(struct s5h1432_state *state,
56 u8 addr, u8 reg, u8 data)
57{
58 int ret;
59 u8 buf[] = { reg, data };
60
61 struct i2c_msg msg = {.addr = addr, .flags = 0, .buf = buf, .len = 2 };
62
63 ret = i2c_transfer(state->i2c, &msg, 1);
64
65 if (ret != 1)
66 printk(KERN_ERR "%s: writereg error 0x%02x 0x%02x 0x%04x, "
67 "ret == %i)\n", __func__, addr, reg, data, ret);
68
69 return (ret != 1) ? -1 : 0;
70}
71
72static u8 s5h1432_readreg(struct s5h1432_state *state, u8 addr, u8 reg)
73{
74 int ret;
75 u8 b0[] = { reg };
76 u8 b1[] = { 0 };
77
78 struct i2c_msg msg[] = {
79 {.addr = addr, .flags = 0, .buf = b0, .len = 1},
80 {.addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 1}
81 };
82
83 ret = i2c_transfer(state->i2c, msg, 2);
84
85 if (ret != 2)
86 printk(KERN_ERR "%s: readreg error (ret == %i)\n",
87 __func__, ret);
88 return b1[0];
89}
90
91static int s5h1432_sleep(struct dvb_frontend *fe)
92{
93 return 0;
94}
95
96static int s5h1432_set_channel_bandwidth(struct dvb_frontend *fe,
97 u32 bandwidth)
98{
99 struct s5h1432_state *state = fe->demodulator_priv;
100
101 u8 reg = 0;
102
103 /* Register [0x2E] bit 3:2 : 8MHz = 0; 7MHz = 1; 6MHz = 2 */
104 reg = s5h1432_readreg(state, S5H1432_I2C_TOP_ADDR, 0x2E);
105 reg &= ~(0x0C);
106 switch (bandwidth) {
107 case 6:
108 reg |= 0x08;
109 break;
110 case 7:
111 reg |= 0x04;
112 break;
113 case 8:
114 reg |= 0x00;
115 break;
116 default:
117 return 0;
118 }
119 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x2E, reg);
120 return 1;
121}
122
123static int s5h1432_set_IF(struct dvb_frontend *fe, u32 ifFreqHz)
124{
125 struct s5h1432_state *state = fe->demodulator_priv;
126
127 switch (ifFreqHz) {
128 case TAIWAN_HI_IF_FREQ_44_MHZ:
129 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x55);
130 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x55);
131 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0x15);
132 break;
133 case EUROPE_HI_IF_FREQ_36_MHZ:
134 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x00);
135 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x00);
136 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0x40);
137 break;
138 case IF_FREQ_6_MHZ:
139 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x00);
140 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x00);
141 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0xe0);
142 break;
143 case IF_FREQ_3point3_MHZ:
144 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x66);
145 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x66);
146 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0xEE);
147 break;
148 case IF_FREQ_3point5_MHZ:
149 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x55);
150 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x55);
151 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0xED);
152 break;
153 case IF_FREQ_4_MHZ:
154 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0xAA);
155 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0xAA);
156 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0xEA);
157 break;
158 default:
159 {
160 u32 value = 0;
161 value = (u32) (((48000 - (ifFreqHz / 1000)) * 512 *
162 (u32) 32768) / (48 * 1000));
163 printk(KERN_INFO
164 "Default IFFreq %d :reg value = 0x%x\n",
165 ifFreqHz, value);
166 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4,
167 (u8) value & 0xFF);
168 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5,
169 (u8) (value >> 8) & 0xFF);
170 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7,
171 (u8) (value >> 16) & 0xFF);
172 break;
173 }
174
175 }
176
177 return 1;
178}
179
180/* Talk to the demod, set the FEC, GUARD, QAM settings etc */
181static int s5h1432_set_frontend(struct dvb_frontend *fe,
182 struct dvb_frontend_parameters *p)
183{
184 u32 dvb_bandwidth = 8;
185 struct s5h1432_state *state = fe->demodulator_priv;
186
187 if (p->frequency == state->current_frequency) {
188 /*current_frequency = p->frequency; */
189 /*state->current_frequency = p->frequency; */
190 } else {
191 fe->ops.tuner_ops.set_params(fe, p);
192 msleep(300);
193 s5h1432_set_channel_bandwidth(fe, dvb_bandwidth);
194 switch (p->u.ofdm.bandwidth) {
195 case BANDWIDTH_6_MHZ:
196 dvb_bandwidth = 6;
197 s5h1432_set_IF(fe, IF_FREQ_4_MHZ);
198 break;
199 case BANDWIDTH_7_MHZ:
200 dvb_bandwidth = 7;
201 s5h1432_set_IF(fe, IF_FREQ_4_MHZ);
202 break;
203 case BANDWIDTH_8_MHZ:
204 dvb_bandwidth = 8;
205 s5h1432_set_IF(fe, IF_FREQ_4_MHZ);
206 break;
207 default:
208 return 0;
209 }
210 /*fe->ops.tuner_ops.set_params(fe, p); */
211/*Soft Reset chip*/
212 msleep(30);
213 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1a);
214 msleep(30);
215 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1b);
216
217 s5h1432_set_channel_bandwidth(fe, dvb_bandwidth);
218 switch (p->u.ofdm.bandwidth) {
219 case BANDWIDTH_6_MHZ:
220 dvb_bandwidth = 6;
221 s5h1432_set_IF(fe, IF_FREQ_4_MHZ);
222 break;
223 case BANDWIDTH_7_MHZ:
224 dvb_bandwidth = 7;
225 s5h1432_set_IF(fe, IF_FREQ_4_MHZ);
226 break;
227 case BANDWIDTH_8_MHZ:
228 dvb_bandwidth = 8;
229 s5h1432_set_IF(fe, IF_FREQ_4_MHZ);
230 break;
231 default:
232 return 0;
233 }
234 /*fe->ops.tuner_ops.set_params(fe,p); */
235 /*Soft Reset chip*/
236 msleep(30);
237 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1a);
238 msleep(30);
239 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1b);
240
241 }
242
243 state->current_frequency = p->frequency;
244
245 return 0;
246}
247
248static int s5h1432_init(struct dvb_frontend *fe)
249{
250 struct s5h1432_state *state = fe->demodulator_priv;
251
252 u8 reg = 0;
253 state->current_frequency = 0;
254 printk(KERN_INFO " s5h1432_init().\n");
255
256 /*Set VSB mode as default, this also does a soft reset */
257 /*Initialize registers */
258
259 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x04, 0xa8);
260 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x05, 0x01);
261 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x07, 0x70);
262 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x19, 0x80);
263 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x1b, 0x9D);
264 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x1c, 0x30);
265 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x1d, 0x20);
266 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x1e, 0x1B);
267 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x2e, 0x40);
268 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x42, 0x84);
269 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x50, 0x5a);
270 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x5a, 0xd3);
271 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x68, 0x50);
272 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xb8, 0x3c);
273 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xc4, 0x10);
274 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xcc, 0x9c);
275 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xDA, 0x00);
276 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe1, 0x94);
277 /* s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xf4, 0xa1); */
278 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xf9, 0x00);
279
280 /*For NXP tuner*/
281
282 /*Set 3.3MHz as default IF frequency */
283 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x66);
284 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x66);
285 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0xEE);
286 /* Set reg 0x1E to get the full dynamic range */
287 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x1e, 0x31);
288
289 /* Mode setting in demod */
290 reg = s5h1432_readreg(state, S5H1432_I2C_TOP_ADDR, 0x42);
291 reg |= 0x80;
292 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x42, reg);
293 /* Serial mode */
294
295 /* Soft Reset chip */
296
297 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1a);
298 msleep(30);
299 s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1b);
300
301
302 return 0;
303}
304
305static int s5h1432_read_status(struct dvb_frontend *fe, fe_status_t *status)
306{
307 return 0;
308}
309
310static int s5h1432_read_signal_strength(struct dvb_frontend *fe,
311 u16 *signal_strength)
312{
313 return 0;
314}
315
316static int s5h1432_read_snr(struct dvb_frontend *fe, u16 *snr)
317{
318 return 0;
319}
320
321static int s5h1432_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
322{
323
324 return 0;
325}
326
327static int s5h1432_read_ber(struct dvb_frontend *fe, u32 *ber)
328{
329 return 0;
330}
331
332static int s5h1432_get_frontend(struct dvb_frontend *fe,
333 struct dvb_frontend_parameters *p)
334{
335 return 0;
336}
337
338static int s5h1432_get_tune_settings(struct dvb_frontend *fe,
339 struct dvb_frontend_tune_settings *tune)
340{
341 return 0;
342}
343
344static void s5h1432_release(struct dvb_frontend *fe)
345{
346 struct s5h1432_state *state = fe->demodulator_priv;
347 kfree(state);
348}
349
350static struct dvb_frontend_ops s5h1432_ops;
351
352struct dvb_frontend *s5h1432_attach(const struct s5h1432_config *config,
353 struct i2c_adapter *i2c)
354{
355 struct s5h1432_state *state = NULL;
356
357 printk(KERN_INFO " Enter s5h1432_attach(). attach success!\n");
358 /* allocate memory for the internal state */
359 state = kmalloc(sizeof(struct s5h1432_state), GFP_KERNEL);
360 if (state == NULL)
361 goto error;
362
363 /* setup the state */
364 state->config = config;
365 state->i2c = i2c;
366 state->current_modulation = QAM_16;
367 state->inversion = state->config->inversion;
368
369 /* create dvb_frontend */
370 memcpy(&state->frontend.ops, &s5h1432_ops,
371 sizeof(struct dvb_frontend_ops));
372
373 state->frontend.demodulator_priv = state;
374
375 return &state->frontend;
376
377error:
378 kfree(state);
379 return NULL;
380}
381EXPORT_SYMBOL(s5h1432_attach);
382
383static struct dvb_frontend_ops s5h1432_ops = {
384
385 .info = {
386 .name = "Samsung s5h1432 DVB-T Frontend",
387 .type = FE_OFDM,
388 .frequency_min = 177000000,
389 .frequency_max = 858000000,
390 .frequency_stepsize = 166666,
391 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
392 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
393 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
394 FE_CAN_HIERARCHY_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
395 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_RECOVER},
396
397 .init = s5h1432_init,
398 .sleep = s5h1432_sleep,
399 .set_frontend = s5h1432_set_frontend,
400 .get_frontend = s5h1432_get_frontend,
401 .get_tune_settings = s5h1432_get_tune_settings,
402 .read_status = s5h1432_read_status,
403 .read_ber = s5h1432_read_ber,
404 .read_signal_strength = s5h1432_read_signal_strength,
405 .read_snr = s5h1432_read_snr,
406 .read_ucblocks = s5h1432_read_ucblocks,
407 .release = s5h1432_release,
408};
409
410module_param(debug, int, 0644);
411MODULE_PARM_DESC(debug, "Enable verbose debug messages");
412
413MODULE_DESCRIPTION("Samsung s5h1432 DVB-T Demodulator driver");
414MODULE_AUTHOR("Bill Liu");
415MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/s5h1432.h b/drivers/media/dvb/frontends/s5h1432.h
new file mode 100644
index 000000000000..b57438c32546
--- /dev/null
+++ b/drivers/media/dvb/frontends/s5h1432.h
@@ -0,0 +1,91 @@
1/*
2 * Samsung s5h1432 VSB/QAM demodulator driver
3 *
4 * Copyright (C) 2009 Bill Liu <Bill.Liu@Conexant.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */
21
22#ifndef __S5H1432_H__
23#define __S5H1432_H__
24
25#include <linux/dvb/frontend.h>
26
27#define S5H1432_I2C_TOP_ADDR (0x02 >> 1)
28
29#define TAIWAN_HI_IF_FREQ_44_MHZ 44000000
30#define EUROPE_HI_IF_FREQ_36_MHZ 36000000
31#define IF_FREQ_6_MHZ 6000000
32#define IF_FREQ_3point3_MHZ 3300000
33#define IF_FREQ_3point5_MHZ 3500000
34#define IF_FREQ_4_MHZ 4000000
35
36struct s5h1432_config {
37
38 /* serial/parallel output */
39#define S5H1432_PARALLEL_OUTPUT 0
40#define S5H1432_SERIAL_OUTPUT 1
41 u8 output_mode;
42
43 /* GPIO Setting */
44#define S5H1432_GPIO_OFF 0
45#define S5H1432_GPIO_ON 1
46 u8 gpio;
47
48 /* MPEG signal timing */
49#define S5H1432_MPEGTIMING_CONTINOUS_INVERTING_CLOCK 0
50#define S5H1432_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK 1
51#define S5H1432_MPEGTIMING_NONCONTINOUS_INVERTING_CLOCK 2
52#define S5H1432_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK 3
53 u16 mpeg_timing;
54
55 /* IF Freq for QAM and VSB in KHz */
56#define S5H1432_IF_3250 3250
57#define S5H1432_IF_3500 3500
58#define S5H1432_IF_4000 4000
59#define S5H1432_IF_5380 5380
60#define S5H1432_IF_44000 44000
61#define S5H1432_VSB_IF_DEFAULT s5h1432_IF_44000
62#define S5H1432_QAM_IF_DEFAULT s5h1432_IF_44000
63 u16 qam_if;
64 u16 vsb_if;
65
66 /* Spectral Inversion */
67#define S5H1432_INVERSION_OFF 0
68#define S5H1432_INVERSION_ON 1
69 u8 inversion;
70
71 /* Return lock status based on tuner lock, or demod lock */
72#define S5H1432_TUNERLOCKING 0
73#define S5H1432_DEMODLOCKING 1
74 u8 status_mode;
75};
76
77#if defined(CONFIG_DVB_S5H1432) || \
78 (defined(CONFIG_DVB_S5H1432_MODULE) && defined(MODULE))
79extern struct dvb_frontend *s5h1432_attach(const struct s5h1432_config *config,
80 struct i2c_adapter *i2c);
81#else
82static inline struct dvb_frontend *s5h1432_attach(const struct s5h1432_config
83 *config,
84 struct i2c_adapter *i2c)
85{
86 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
87 return NULL;
88}
89#endif /* CONFIG_DVB_s5h1432 */
90
91#endif /* __s5h1432_H__ */
diff --git a/drivers/media/dvb/frontends/s921.c b/drivers/media/dvb/frontends/s921.c
new file mode 100644
index 000000000000..ca0103d5f148
--- /dev/null
+++ b/drivers/media/dvb/frontends/s921.c
@@ -0,0 +1,548 @@
1/*
2 * Sharp VA3A5JZ921 One Seg Broadcast Module driver
3 * This device is labeled as just S. 921 at the top of the frontend can
4 *
5 * Copyright (C) 2009-2010 Mauro Carvalho Chehab <mchehab@redhat.com>
6 * Copyright (C) 2009-2010 Douglas Landgraf <dougsland@redhat.com>
7 *
8 * Developed for Leadership SBTVD 1seg device sold in Brazil
9 *
10 * Frontend module based on cx24123 driver, getting some info from
11 * the old s921 driver.
12 *
13 * FIXME: Need to port to DVB v5.2 API
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation version 2.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 */
24
25#include <linux/kernel.h>
26#include <asm/div64.h>
27
28#include "dvb_frontend.h"
29#include "s921.h"
30
31static int debug = 1;
32module_param(debug, int, 0644);
33MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
34
35#define rc(args...) do { \
36 printk(KERN_ERR "s921: " args); \
37} while (0)
38
39#define dprintk(args...) \
40 do { \
41 if (debug) { \
42 printk(KERN_DEBUG "s921: %s: ", __func__); \
43 printk(args); \
44 } \
45 } while (0)
46
47struct s921_state {
48 struct i2c_adapter *i2c;
49 const struct s921_config *config;
50
51 struct dvb_frontend frontend;
52
53 /* The Demod can't easily provide these, we cache them */
54 u32 currentfreq;
55};
56
57/*
58 * Various tuner defaults need to be established for a given frequency kHz.
59 * fixme: The bounds on the bands do not match the doc in real life.
60 * fixme: Some of them have been moved, other might need adjustment.
61 */
62static struct s921_bandselect_val {
63 u32 freq_low;
64 u8 band_reg;
65} s921_bandselect[] = {
66 { 0, 0x7b },
67 { 485140000, 0x5b },
68 { 515140000, 0x3b },
69 { 545140000, 0x1b },
70 { 599140000, 0xfb },
71 { 623140000, 0xdb },
72 { 659140000, 0xbb },
73 { 713140000, 0x9b },
74};
75
76struct regdata {
77 u8 reg;
78 u8 data;
79};
80
81static struct regdata s921_init[] = {
82 { 0x01, 0x80 }, /* Probably, a reset sequence */
83 { 0x01, 0x40 },
84 { 0x01, 0x80 },
85 { 0x01, 0x40 },
86
87 { 0x02, 0x00 },
88 { 0x03, 0x40 },
89 { 0x04, 0x01 },
90 { 0x05, 0x00 },
91 { 0x06, 0x00 },
92 { 0x07, 0x00 },
93 { 0x08, 0x00 },
94 { 0x09, 0x00 },
95 { 0x0a, 0x00 },
96 { 0x0b, 0x5a },
97 { 0x0c, 0x00 },
98 { 0x0d, 0x00 },
99 { 0x0f, 0x00 },
100 { 0x13, 0x1b },
101 { 0x14, 0x80 },
102 { 0x15, 0x40 },
103 { 0x17, 0x70 },
104 { 0x18, 0x01 },
105 { 0x19, 0x12 },
106 { 0x1a, 0x01 },
107 { 0x1b, 0x12 },
108 { 0x1c, 0xa0 },
109 { 0x1d, 0x00 },
110 { 0x1e, 0x0a },
111 { 0x1f, 0x08 },
112 { 0x20, 0x40 },
113 { 0x21, 0xff },
114 { 0x22, 0x4c },
115 { 0x23, 0x4e },
116 { 0x24, 0x4c },
117 { 0x25, 0x00 },
118 { 0x26, 0x00 },
119 { 0x27, 0xf4 },
120 { 0x28, 0x60 },
121 { 0x29, 0x88 },
122 { 0x2a, 0x40 },
123 { 0x2b, 0x40 },
124 { 0x2c, 0xff },
125 { 0x2d, 0x00 },
126 { 0x2e, 0xff },
127 { 0x2f, 0x00 },
128 { 0x30, 0x20 },
129 { 0x31, 0x06 },
130 { 0x32, 0x0c },
131 { 0x34, 0x0f },
132 { 0x37, 0xfe },
133 { 0x38, 0x00 },
134 { 0x39, 0x63 },
135 { 0x3a, 0x10 },
136 { 0x3b, 0x10 },
137 { 0x47, 0x00 },
138 { 0x49, 0xe5 },
139 { 0x4b, 0x00 },
140 { 0x50, 0xc0 },
141 { 0x52, 0x20 },
142 { 0x54, 0x5a },
143 { 0x55, 0x5b },
144 { 0x56, 0x40 },
145 { 0x57, 0x70 },
146 { 0x5c, 0x50 },
147 { 0x5d, 0x00 },
148 { 0x62, 0x17 },
149 { 0x63, 0x2f },
150 { 0x64, 0x6f },
151 { 0x68, 0x00 },
152 { 0x69, 0x89 },
153 { 0x6a, 0x00 },
154 { 0x6b, 0x00 },
155 { 0x6c, 0x00 },
156 { 0x6d, 0x00 },
157 { 0x6e, 0x00 },
158 { 0x70, 0x10 },
159 { 0x71, 0x00 },
160 { 0x75, 0x00 },
161 { 0x76, 0x30 },
162 { 0x77, 0x01 },
163 { 0xaf, 0x00 },
164 { 0xb0, 0xa0 },
165 { 0xb2, 0x3d },
166 { 0xb3, 0x25 },
167 { 0xb4, 0x8b },
168 { 0xb5, 0x4b },
169 { 0xb6, 0x3f },
170 { 0xb7, 0xff },
171 { 0xb8, 0xff },
172 { 0xb9, 0xfc },
173 { 0xba, 0x00 },
174 { 0xbb, 0x00 },
175 { 0xbc, 0x00 },
176 { 0xd0, 0x30 },
177 { 0xe4, 0x84 },
178 { 0xf0, 0x48 },
179 { 0xf1, 0x19 },
180 { 0xf2, 0x5a },
181 { 0xf3, 0x8e },
182 { 0xf4, 0x2d },
183 { 0xf5, 0x07 },
184 { 0xf6, 0x5a },
185 { 0xf7, 0xba },
186 { 0xf8, 0xd7 },
187};
188
189static struct regdata s921_prefreq[] = {
190 { 0x47, 0x60 },
191 { 0x68, 0x00 },
192 { 0x69, 0x89 },
193 { 0xf0, 0x48 },
194 { 0xf1, 0x19 },
195};
196
197static struct regdata s921_postfreq[] = {
198 { 0xf5, 0xae },
199 { 0xf6, 0xb7 },
200 { 0xf7, 0xba },
201 { 0xf8, 0xd7 },
202 { 0x68, 0x0a },
203 { 0x69, 0x09 },
204};
205
206static int s921_i2c_writereg(struct s921_state *state,
207 u8 i2c_addr, int reg, int data)
208{
209 u8 buf[] = { reg, data };
210 struct i2c_msg msg = {
211 .addr = i2c_addr, .flags = 0, .buf = buf, .len = 2
212 };
213 int rc;
214
215 rc = i2c_transfer(state->i2c, &msg, 1);
216 if (rc != 1) {
217 printk("%s: writereg rcor(rc == %i, reg == 0x%02x,"
218 " data == 0x%02x)\n", __func__, rc, reg, data);
219 return rc;
220 }
221
222 return 0;
223}
224
225static int s921_i2c_writeregdata(struct s921_state *state, u8 i2c_addr,
226 struct regdata *rd, int size)
227{
228 int i, rc;
229
230 for (i = 0; i < size; i++) {
231 rc = s921_i2c_writereg(state, i2c_addr, rd[i].reg, rd[i].data);
232 if (rc < 0)
233 return rc;
234 }
235 return 0;
236}
237
238static int s921_i2c_readreg(struct s921_state *state, u8 i2c_addr, u8 reg)
239{
240 u8 val;
241 int rc;
242 struct i2c_msg msg[] = {
243 { .addr = i2c_addr, .flags = 0, .buf = &reg, .len = 1 },
244 { .addr = i2c_addr, .flags = I2C_M_RD, .buf = &val, .len = 1 }
245 };
246
247 rc = i2c_transfer(state->i2c, msg, 2);
248
249 if (rc != 2) {
250 rc("%s: reg=0x%x (rcor=%d)\n", __func__, reg, rc);
251 return rc;
252 }
253
254 return val;
255}
256
257#define s921_readreg(state, reg) \
258 s921_i2c_readreg(state, state->config->demod_address, reg)
259#define s921_writereg(state, reg, val) \
260 s921_i2c_writereg(state, state->config->demod_address, reg, val)
261#define s921_writeregdata(state, regdata) \
262 s921_i2c_writeregdata(state, state->config->demod_address, \
263 regdata, ARRAY_SIZE(regdata))
264
265static int s921_pll_tune(struct dvb_frontend *fe,
266 struct dvb_frontend_parameters *p)
267{
268 struct s921_state *state = fe->demodulator_priv;
269 int band, rc, i;
270 unsigned long f_offset;
271 u8 f_switch;
272 u64 offset;
273
274 dprintk("frequency=%i\n", p->frequency);
275
276 for (band = 0; band < ARRAY_SIZE(s921_bandselect); band++)
277 if (p->frequency < s921_bandselect[band].freq_low)
278 break;
279 band--;
280
281 if (band < 0) {
282 rc("%s: frequency out of range\n", __func__);
283 return -EINVAL;
284 }
285
286 f_switch = s921_bandselect[band].band_reg;
287
288 offset = ((u64)p->frequency) * 258;
289 do_div(offset, 6000000);
290 f_offset = ((unsigned long)offset) + 2321;
291
292 rc = s921_writeregdata(state, s921_prefreq);
293 if (rc < 0)
294 return rc;
295
296 rc = s921_writereg(state, 0xf2, (f_offset >> 8) & 0xff);
297 if (rc < 0)
298 return rc;
299
300 rc = s921_writereg(state, 0xf3, f_offset & 0xff);
301 if (rc < 0)
302 return rc;
303
304 rc = s921_writereg(state, 0xf4, f_switch);
305 if (rc < 0)
306 return rc;
307
308 rc = s921_writeregdata(state, s921_postfreq);
309 if (rc < 0)
310 return rc;
311
312 for (i = 0 ; i < 6; i++) {
313 rc = s921_readreg(state, 0x80);
314 dprintk("status 0x80: %02x\n", rc);
315 }
316 rc = s921_writereg(state, 0x01, 0x40);
317 if (rc < 0)
318 return rc;
319
320 rc = s921_readreg(state, 0x01);
321 dprintk("status 0x01: %02x\n", rc);
322
323 rc = s921_readreg(state, 0x80);
324 dprintk("status 0x80: %02x\n", rc);
325
326 rc = s921_readreg(state, 0x80);
327 dprintk("status 0x80: %02x\n", rc);
328
329 rc = s921_readreg(state, 0x32);
330 dprintk("status 0x32: %02x\n", rc);
331
332 dprintk("pll tune band=%d, pll=%d\n", f_switch, (int)f_offset);
333
334 return 0;
335}
336
337static int s921_initfe(struct dvb_frontend *fe)
338{
339 struct s921_state *state = fe->demodulator_priv;
340 int rc;
341
342 dprintk("\n");
343
344 rc = s921_writeregdata(state, s921_init);
345 if (rc < 0)
346 return rc;
347
348 return 0;
349}
350
351static int s921_read_status(struct dvb_frontend *fe, fe_status_t *status)
352{
353 struct s921_state *state = fe->demodulator_priv;
354 int regstatus, rc;
355
356 *status = 0;
357
358 rc = s921_readreg(state, 0x81);
359 if (rc < 0)
360 return rc;
361
362 regstatus = rc << 8;
363
364 rc = s921_readreg(state, 0x82);
365 if (rc < 0)
366 return rc;
367
368 regstatus |= rc;
369
370 dprintk("status = %04x\n", regstatus);
371
372 /* Full Sync - We don't know what each bit means on regs 0x81/0x82 */
373 if ((regstatus & 0xff) == 0x40) {
374 *status = FE_HAS_SIGNAL |
375 FE_HAS_CARRIER |
376 FE_HAS_VITERBI |
377 FE_HAS_SYNC |
378 FE_HAS_LOCK;
379 } else if (regstatus & 0x40) {
380 /* This is close to Full Sync, but not enough to get useful info */
381 *status = FE_HAS_SIGNAL |
382 FE_HAS_CARRIER |
383 FE_HAS_VITERBI |
384 FE_HAS_SYNC;
385 }
386
387 return 0;
388}
389
390static int s921_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
391{
392 fe_status_t status;
393 struct s921_state *state = fe->demodulator_priv;
394 int rc;
395
396 /* FIXME: Use the proper register for it... 0x80? */
397 rc = s921_read_status(fe, &status);
398 if (rc < 0)
399 return rc;
400
401 *strength = (status & FE_HAS_LOCK) ? 0xffff : 0;
402
403 dprintk("strength = 0x%04x\n", *strength);
404
405 rc = s921_readreg(state, 0x01);
406 dprintk("status 0x01: %02x\n", rc);
407
408 rc = s921_readreg(state, 0x80);
409 dprintk("status 0x80: %02x\n", rc);
410
411 rc = s921_readreg(state, 0x32);
412 dprintk("status 0x32: %02x\n", rc);
413
414 return 0;
415}
416
417static int s921_set_frontend(struct dvb_frontend *fe,
418 struct dvb_frontend_parameters *p)
419{
420 struct s921_state *state = fe->demodulator_priv;
421 int rc;
422
423 dprintk("\n");
424
425 /* FIXME: We don't know how to use non-auto mode */
426
427 rc = s921_pll_tune(fe, p);
428 if (rc < 0)
429 return rc;
430
431 state->currentfreq = p->frequency;
432
433 return 0;
434}
435
436static int s921_get_frontend(struct dvb_frontend *fe,
437 struct dvb_frontend_parameters *p)
438{
439 struct s921_state *state = fe->demodulator_priv;
440
441 /* FIXME: Probably it is possible to get it from regs f1 and f2 */
442 p->frequency = state->currentfreq;
443
444 return 0;
445}
446
447static int s921_tune(struct dvb_frontend *fe,
448 struct dvb_frontend_parameters *params,
449 unsigned int mode_flags,
450 unsigned int *delay,
451 fe_status_t *status)
452{
453 int rc = 0;
454
455 dprintk("\n");
456
457 if (params != NULL)
458 rc = s921_set_frontend(fe, params);
459
460 if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
461 s921_read_status(fe, status);
462
463 return rc;
464}
465
466static int s921_get_algo(struct dvb_frontend *fe)
467{
468 return 1; /* FE_ALGO_HW */
469}
470
471static void s921_release(struct dvb_frontend *fe)
472{
473 struct s921_state *state = fe->demodulator_priv;
474
475 dprintk("\n");
476 kfree(state);
477}
478
479static struct dvb_frontend_ops s921_ops;
480
481struct dvb_frontend *s921_attach(const struct s921_config *config,
482 struct i2c_adapter *i2c)
483{
484 /* allocate memory for the internal state */
485 struct s921_state *state =
486 kzalloc(sizeof(struct s921_state), GFP_KERNEL);
487
488 dprintk("\n");
489 if (state == NULL) {
490 rc("Unable to kzalloc\n");
491 goto rcor;
492 }
493
494 /* setup the state */
495 state->config = config;
496 state->i2c = i2c;
497
498 /* create dvb_frontend */
499 memcpy(&state->frontend.ops, &s921_ops,
500 sizeof(struct dvb_frontend_ops));
501 state->frontend.demodulator_priv = state;
502
503 return &state->frontend;
504
505rcor:
506 kfree(state);
507
508 return NULL;
509}
510EXPORT_SYMBOL(s921_attach);
511
512static struct dvb_frontend_ops s921_ops = {
513 /* Use dib8000 values per default */
514 .info = {
515 .name = "Sharp S921",
516 .type = FE_OFDM,
517 .frequency_min = 470000000,
518 /*
519 * Max should be 770MHz instead, according with Sharp docs,
520 * but Leadership doc says it works up to 806 MHz. This is
521 * required to get channel 69, used in Brazil
522 */
523 .frequency_max = 806000000,
524 .frequency_tolerance = 0,
525 .caps = FE_CAN_INVERSION_AUTO |
526 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
527 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
528 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
529 FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
530 FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_RECOVER |
531 FE_CAN_HIERARCHY_AUTO,
532 },
533
534 .release = s921_release,
535
536 .init = s921_initfe,
537 .set_frontend = s921_set_frontend,
538 .get_frontend = s921_get_frontend,
539 .read_status = s921_read_status,
540 .read_signal_strength = s921_read_signal_strength,
541 .tune = s921_tune,
542 .get_frontend_algo = s921_get_algo,
543};
544
545MODULE_DESCRIPTION("DVB Frontend module for Sharp S921 hardware");
546MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
547MODULE_AUTHOR("Douglas Landgraf <dougsland@redhat.com>");
548MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/s921.h b/drivers/media/dvb/frontends/s921.h
new file mode 100644
index 000000000000..f220d8299c81
--- /dev/null
+++ b/drivers/media/dvb/frontends/s921.h
@@ -0,0 +1,47 @@
1/*
2 * Sharp s921 driver
3 *
4 * Copyright (C) 2009 Mauro Carvalho Chehab <mchehab@redhat.com>
5 * Copyright (C) 2009 Douglas Landgraf <dougsland@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation version 2.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 */
16
17#ifndef S921_H
18#define S921_H
19
20#include <linux/dvb/frontend.h>
21
22struct s921_config {
23 /* the demodulator's i2c address */
24 u8 demod_address;
25};
26
27#if defined(CONFIG_DVB_S921) || (defined(CONFIG_DVB_S921_MODULE) \
28 && defined(MODULE))
29extern struct dvb_frontend *s921_attach(const struct s921_config *config,
30 struct i2c_adapter *i2c);
31extern struct i2c_adapter *s921_get_tuner_i2c_adapter(struct dvb_frontend *);
32#else
33static inline struct dvb_frontend *s921_attach(
34 const struct s921_config *config, struct i2c_adapter *i2c)
35{
36 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
37 return NULL;
38}
39static struct i2c_adapter *
40 s921_get_tuner_i2c_adapter(struct dvb_frontend *fe)
41{
42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
43 return NULL;
44}
45#endif
46
47#endif /* S921_H */
diff --git a/drivers/media/dvb/frontends/s921_core.c b/drivers/media/dvb/frontends/s921_core.c
deleted file mode 100644
index 974b52be9aea..000000000000
--- a/drivers/media/dvb/frontends/s921_core.c
+++ /dev/null
@@ -1,216 +0,0 @@
1/*
2 * Driver for Sharp s921 driver
3 *
4 * Copyright (C) 2008 Markus Rechberger <mrechberger@sundtek.de>
5 *
6 */
7
8
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/delay.h>
12#include "s921_core.h"
13
14static int s921_isdb_init(struct s921_isdb_t *dev);
15static int s921_isdb_set_parameters(struct s921_isdb_t *dev, struct s921_isdb_t_transmission_mode_params *params);
16static int s921_isdb_tune(struct s921_isdb_t *dev, struct s921_isdb_t_tune_params *params);
17static int s921_isdb_get_status(struct s921_isdb_t *dev, void *data);
18
19static u8 init_table[]={ 0x01, 0x40, 0x02, 0x00, 0x03, 0x40, 0x04, 0x01,
20 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00,
21 0x09, 0x00, 0x0a, 0x00, 0x0b, 0x5a, 0x0c, 0x00,
22 0x0d, 0x00, 0x0f, 0x00, 0x13, 0x1b, 0x14, 0x80,
23 0x15, 0x40, 0x17, 0x70, 0x18, 0x01, 0x19, 0x12,
24 0x1a, 0x01, 0x1b, 0x12, 0x1c, 0xa0, 0x1d, 0x00,
25 0x1e, 0x0a, 0x1f, 0x08, 0x20, 0x40, 0x21, 0xff,
26 0x22, 0x4c, 0x23, 0x4e, 0x24, 0x4c, 0x25, 0x00,
27 0x26, 0x00, 0x27, 0xf4, 0x28, 0x60, 0x29, 0x88,
28 0x2a, 0x40, 0x2b, 0x40, 0x2c, 0xff, 0x2d, 0x00,
29 0x2e, 0xff, 0x2f, 0x00, 0x30, 0x20, 0x31, 0x06,
30 0x32, 0x0c, 0x34, 0x0f, 0x37, 0xfe, 0x38, 0x00,
31 0x39, 0x63, 0x3a, 0x10, 0x3b, 0x10, 0x47, 0x00,
32 0x49, 0xe5, 0x4b, 0x00, 0x50, 0xc0, 0x52, 0x20,
33 0x54, 0x5a, 0x55, 0x5b, 0x56, 0x40, 0x57, 0x70,
34 0x5c, 0x50, 0x5d, 0x00, 0x62, 0x17, 0x63, 0x2f,
35 0x64, 0x6f, 0x68, 0x00, 0x69, 0x89, 0x6a, 0x00,
36 0x6b, 0x00, 0x6c, 0x00, 0x6d, 0x00, 0x6e, 0x00,
37 0x70, 0x00, 0x71, 0x00, 0x75, 0x00, 0x76, 0x30,
38 0x77, 0x01, 0xaf, 0x00, 0xb0, 0xa0, 0xb2, 0x3d,
39 0xb3, 0x25, 0xb4, 0x8b, 0xb5, 0x4b, 0xb6, 0x3f,
40 0xb7, 0xff, 0xb8, 0xff, 0xb9, 0xfc, 0xba, 0x00,
41 0xbb, 0x00, 0xbc, 0x00, 0xd0, 0x30, 0xe4, 0x84,
42 0xf0, 0x48, 0xf1, 0x19, 0xf2, 0x5a, 0xf3, 0x8e,
43 0xf4, 0x2d, 0xf5, 0x07, 0xf6, 0x5a, 0xf7, 0xba,
44 0xf8, 0xd7 };
45
46static u8 c_table[]={ 0x58, 0x8a, 0x7b, 0x59, 0x8c, 0x7b, 0x5a, 0x8e, 0x5b,
47 0x5b, 0x90, 0x5b, 0x5c, 0x92, 0x5b, 0x5d, 0x94, 0x5b,
48 0x5e, 0x96, 0x5b, 0x5f, 0x98, 0x3b, 0x60, 0x9a, 0x3b,
49 0x61, 0x9c, 0x3b, 0x62, 0x9e, 0x3b, 0x63, 0xa0, 0x3b,
50 0x64, 0xa2, 0x1b, 0x65, 0xa4, 0x1b, 0x66, 0xa6, 0x1b,
51 0x67, 0xa8, 0x1b, 0x68, 0xaa, 0x1b, 0x69, 0xac, 0x1b,
52 0x6a, 0xae, 0x1b, 0x6b, 0xb0, 0x1b, 0x6c, 0xb2, 0x1b,
53 0x6d, 0xb4, 0xfb, 0x6e, 0xb6, 0xfb, 0x6f, 0xb8, 0xfb,
54 0x70, 0xba, 0xfb, 0x71, 0xbc, 0xdb, 0x72, 0xbe, 0xdb,
55 0x73, 0xc0, 0xdb, 0x74, 0xc2, 0xdb, 0x75, 0xc4, 0xdb,
56 0x76, 0xc6, 0xdb, 0x77, 0xc8, 0xbb, 0x78, 0xca, 0xbb,
57 0x79, 0xcc, 0xbb, 0x7a, 0xce, 0xbb, 0x7b, 0xd0, 0xbb,
58 0x7c, 0xd2, 0xbb, 0x7d, 0xd4, 0xbb, 0x7e, 0xd6, 0xbb,
59 0x7f, 0xd8, 0xbb, 0x80, 0xda, 0x9b, 0x81, 0xdc, 0x9b,
60 0x82, 0xde, 0x9b, 0x83, 0xe0, 0x9b, 0x84, 0xe2, 0x9b,
61 0x85, 0xe4, 0x9b, 0x86, 0xe6, 0x9b, 0x87, 0xe8, 0x9b,
62 0x88, 0xea, 0x9b, 0x89, 0xec, 0x9b };
63
64int s921_isdb_cmd(struct s921_isdb_t *dev, u32 cmd, void *data) {
65 switch(cmd) {
66 case ISDB_T_CMD_INIT:
67 s921_isdb_init(dev);
68 break;
69 case ISDB_T_CMD_SET_PARAM:
70 s921_isdb_set_parameters(dev, data);
71 break;
72 case ISDB_T_CMD_TUNE:
73 s921_isdb_tune(dev, data);
74 break;
75 case ISDB_T_CMD_GET_STATUS:
76 s921_isdb_get_status(dev, data);
77 break;
78 default:
79 printk("unhandled command\n");
80 return -EINVAL;
81 }
82 return 0;
83}
84
85static int s921_isdb_init(struct s921_isdb_t *dev) {
86 unsigned int i;
87 unsigned int ret;
88 printk("isdb_init\n");
89 for (i = 0; i < sizeof(init_table); i+=2) {
90 ret = dev->i2c_write(dev->priv_dev, init_table[i], init_table[i+1]);
91 if (ret != 0) {
92 printk("i2c write failed\n");
93 return ret;
94 }
95 }
96 return 0;
97}
98
99static int s921_isdb_set_parameters(struct s921_isdb_t *dev, struct s921_isdb_t_transmission_mode_params *params) {
100
101 int ret;
102 /* auto is sufficient for now, lateron this should be reflected in an extra interface */
103
104
105
106 ret = dev->i2c_write(dev->priv_dev, 0xb0, 0xa0); //mod_b2);
107 ret = dev->i2c_write(dev->priv_dev, 0xb2, 0x3d); //mod_b2);
108
109 if (ret < 0)
110 return -EINVAL;
111
112 ret = dev->i2c_write(dev->priv_dev, 0xb3, 0x25); //mod_b3);
113 if (ret < 0)
114 return -EINVAL;
115
116 ret = dev->i2c_write(dev->priv_dev, 0xb4, 0x8b); //mod_b4);
117 if (ret < 0)
118 return -EINVAL;
119
120 ret = dev->i2c_write(dev->priv_dev, 0xb5, 0x4b); //mod_b5);
121 if (ret < 0)
122 return -EINVAL;
123
124 ret = dev->i2c_write(dev->priv_dev, 0xb6, 0x3f); //mod_b6);
125 if (ret < 0)
126 return -EINVAL;
127
128 ret = dev->i2c_write(dev->priv_dev, 0xb7, 0x3f); //mod_b7);
129 if (ret < 0)
130 return -EINVAL;
131
132 return E_OK;
133}
134
135static int s921_isdb_tune(struct s921_isdb_t *dev, struct s921_isdb_t_tune_params *params) {
136
137 int ret;
138 int index;
139
140 index = (params->frequency - 473143000)/6000000;
141
142 if (index > 48) {
143 return -EINVAL;
144 }
145
146 dev->i2c_write(dev->priv_dev, 0x47, 0x60);
147
148 ret = dev->i2c_write(dev->priv_dev, 0x68, 0x00);
149 if (ret < 0)
150 return -EINVAL;
151
152 ret = dev->i2c_write(dev->priv_dev, 0x69, 0x89);
153 if (ret < 0)
154 return -EINVAL;
155
156 ret = dev->i2c_write(dev->priv_dev, 0xf0, 0x48);
157 if (ret < 0)
158 return -EINVAL;
159
160 ret = dev->i2c_write(dev->priv_dev, 0xf1, 0x19);
161 if (ret < 0)
162 return -EINVAL;
163
164 ret = dev->i2c_write(dev->priv_dev, 0xf2, c_table[index*3]);
165 if (ret < 0)
166 return -EINVAL;
167
168 ret = dev->i2c_write(dev->priv_dev, 0xf3, c_table[index*3+1]);
169 if (ret < 0)
170 return -EINVAL;
171
172 ret = dev->i2c_write(dev->priv_dev, 0xf4, c_table[index*3+2]);
173 if (ret < 0)
174 return -EINVAL;
175
176 ret = dev->i2c_write(dev->priv_dev, 0xf5, 0xae);
177 if (ret < 0)
178 return -EINVAL;
179
180 ret = dev->i2c_write(dev->priv_dev, 0xf6, 0xb7);
181 if (ret < 0)
182 return -EINVAL;
183
184 ret = dev->i2c_write(dev->priv_dev, 0xf7, 0xba);
185 if (ret < 0)
186 return -EINVAL;
187
188 ret = dev->i2c_write(dev->priv_dev, 0xf8, 0xd7);
189 if (ret < 0)
190 return -EINVAL;
191
192 ret = dev->i2c_write(dev->priv_dev, 0x68, 0x0a);
193 if (ret < 0)
194 return -EINVAL;
195
196 ret = dev->i2c_write(dev->priv_dev, 0x69, 0x09);
197 if (ret < 0)
198 return -EINVAL;
199
200 dev->i2c_write(dev->priv_dev, 0x01, 0x40);
201 return 0;
202}
203
204static int s921_isdb_get_status(struct s921_isdb_t *dev, void *data) {
205 unsigned int *ret = (unsigned int*)data;
206 u8 ifagc_dt;
207 u8 rfagc_dt;
208
209 mdelay(10);
210 ifagc_dt = dev->i2c_read(dev->priv_dev, 0x81);
211 rfagc_dt = dev->i2c_read(dev->priv_dev, 0x82);
212 if (rfagc_dt == 0x40) {
213 *ret = 1;
214 }
215 return 0;
216}
diff --git a/drivers/media/dvb/frontends/s921_core.h b/drivers/media/dvb/frontends/s921_core.h
deleted file mode 100644
index de2f10a44e72..000000000000
--- a/drivers/media/dvb/frontends/s921_core.h
+++ /dev/null
@@ -1,114 +0,0 @@
1#ifndef _S921_CORE_H
2#define _S921_CORE_H
3//#define u8 unsigned int
4//#define u32 unsigned int
5
6
7
8//#define EINVAL -1
9#define E_OK 0
10
11struct s921_isdb_t {
12 void *priv_dev;
13 int (*i2c_write)(void *dev, u8 reg, u8 val);
14 int (*i2c_read)(void *dev, u8 reg);
15};
16
17#define ISDB_T_CMD_INIT 0
18#define ISDB_T_CMD_SET_PARAM 1
19#define ISDB_T_CMD_TUNE 2
20#define ISDB_T_CMD_GET_STATUS 3
21
22struct s921_isdb_t_tune_params {
23 u32 frequency;
24};
25
26struct s921_isdb_t_status {
27};
28
29struct s921_isdb_t_transmission_mode_params {
30 u8 mode;
31 u8 layer_a_mode;
32#define ISDB_T_LA_MODE_1 0
33#define ISDB_T_LA_MODE_2 1
34#define ISDB_T_LA_MODE_3 2
35 u8 layer_a_carrier_modulation;
36#define ISDB_T_LA_CM_DQPSK 0
37#define ISDB_T_LA_CM_QPSK 1
38#define ISDB_T_LA_CM_16QAM 2
39#define ISDB_T_LA_CM_64QAM 3
40#define ISDB_T_LA_CM_NOLAYER 4
41 u8 layer_a_code_rate;
42#define ISDB_T_LA_CR_1_2 0
43#define ISDB_T_LA_CR_2_3 1
44#define ISDB_T_LA_CR_3_4 2
45#define ISDB_T_LA_CR_5_6 4
46#define ISDB_T_LA_CR_7_8 8
47#define ISDB_T_LA_CR_NOLAYER 16
48 u8 layer_a_time_interleave;
49#define ISDB_T_LA_TI_0 0
50#define ISDB_T_LA_TI_1 1
51#define ISDB_T_LA_TI_2 2
52#define ISDB_T_LA_TI_4 4
53#define ISDB_T_LA_TI_8 8
54#define ISDB_T_LA_TI_16 16
55#define ISDB_T_LA_TI_32 32
56 u8 layer_a_nseg;
57
58 u8 layer_b_mode;
59#define ISDB_T_LB_MODE_1 0
60#define ISDB_T_LB_MODE_2 1
61#define ISDB_T_LB_MODE_3 2
62 u8 layer_b_carrier_modulation;
63#define ISDB_T_LB_CM_DQPSK 0
64#define ISDB_T_LB_CM_QPSK 1
65#define ISDB_T_LB_CM_16QAM 2
66#define ISDB_T_LB_CM_64QAM 3
67#define ISDB_T_LB_CM_NOLAYER 4
68 u8 layer_b_code_rate;
69#define ISDB_T_LB_CR_1_2 0
70#define ISDB_T_LB_CR_2_3 1
71#define ISDB_T_LB_CR_3_4 2
72#define ISDB_T_LB_CR_5_6 4
73#define ISDB_T_LB_CR_7_8 8
74#define ISDB_T_LB_CR_NOLAYER 16
75 u8 layer_b_time_interleave;
76#define ISDB_T_LB_TI_0 0
77#define ISDB_T_LB_TI_1 1
78#define ISDB_T_LB_TI_2 2
79#define ISDB_T_LB_TI_4 4
80#define ISDB_T_LB_TI_8 8
81#define ISDB_T_LB_TI_16 16
82#define ISDB_T_LB_TI_32 32
83 u8 layer_b_nseg;
84
85 u8 layer_c_mode;
86#define ISDB_T_LC_MODE_1 0
87#define ISDB_T_LC_MODE_2 1
88#define ISDB_T_LC_MODE_3 2
89 u8 layer_c_carrier_modulation;
90#define ISDB_T_LC_CM_DQPSK 0
91#define ISDB_T_LC_CM_QPSK 1
92#define ISDB_T_LC_CM_16QAM 2
93#define ISDB_T_LC_CM_64QAM 3
94#define ISDB_T_LC_CM_NOLAYER 4
95 u8 layer_c_code_rate;
96#define ISDB_T_LC_CR_1_2 0
97#define ISDB_T_LC_CR_2_3 1
98#define ISDB_T_LC_CR_3_4 2
99#define ISDB_T_LC_CR_5_6 4
100#define ISDB_T_LC_CR_7_8 8
101#define ISDB_T_LC_CR_NOLAYER 16
102 u8 layer_c_time_interleave;
103#define ISDB_T_LC_TI_0 0
104#define ISDB_T_LC_TI_1 1
105#define ISDB_T_LC_TI_2 2
106#define ISDB_T_LC_TI_4 4
107#define ISDB_T_LC_TI_8 8
108#define ISDB_T_LC_TI_16 16
109#define ISDB_T_LC_TI_32 32
110 u8 layer_c_nseg;
111};
112
113int s921_isdb_cmd(struct s921_isdb_t *dev, u32 cmd, void *data);
114#endif
diff --git a/drivers/media/dvb/frontends/s921_module.c b/drivers/media/dvb/frontends/s921_module.c
deleted file mode 100644
index 0eefff61cc50..000000000000
--- a/drivers/media/dvb/frontends/s921_module.c
+++ /dev/null
@@ -1,192 +0,0 @@
1/*
2 * Driver for Sharp s921 driver
3 *
4 * Copyright (C) 2008 Markus Rechberger <mrechberger@sundtek.de>
5 *
6 * All rights reserved.
7 *
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/slab.h>
13#include <linux/delay.h>
14#include "dvb_frontend.h"
15#include "s921_module.h"
16#include "s921_core.h"
17
18static unsigned int debug = 0;
19module_param(debug, int, 0644);
20MODULE_PARM_DESC(debug,"s921 debugging (default off)");
21
22#define dprintk(fmt, args...) if (debug) do {\
23 printk("s921 debug: " fmt, ##args); } while (0)
24
25struct s921_state
26{
27 struct dvb_frontend frontend;
28 fe_modulation_t current_modulation;
29 __u32 snr;
30 __u32 current_frequency;
31 __u8 addr;
32 struct s921_isdb_t dev;
33 struct i2c_adapter *i2c;
34};
35
36static int s921_set_parameters(struct dvb_frontend *fe, struct dvb_frontend_parameters *param) {
37 struct s921_state *state = (struct s921_state *)fe->demodulator_priv;
38 struct s921_isdb_t_transmission_mode_params params;
39 struct s921_isdb_t_tune_params tune_params;
40
41 tune_params.frequency = param->frequency;
42 s921_isdb_cmd(&state->dev, ISDB_T_CMD_SET_PARAM, &params);
43 s921_isdb_cmd(&state->dev, ISDB_T_CMD_TUNE, &tune_params);
44 mdelay(100);
45 return 0;
46}
47
48static int s921_init(struct dvb_frontend *fe) {
49 printk("s921 init\n");
50 return 0;
51}
52
53static int s921_sleep(struct dvb_frontend *fe) {
54 printk("s921 sleep\n");
55 return 0;
56}
57
58static int s921_read_status(struct dvb_frontend *fe, fe_status_t *status)
59{
60 struct s921_state *state = (struct s921_state *)fe->demodulator_priv;
61 unsigned int ret;
62 mdelay(5);
63 s921_isdb_cmd(&state->dev, ISDB_T_CMD_GET_STATUS, &ret);
64 *status = 0;
65
66 printk("status: %02x\n", ret);
67 if (ret == 1) {
68 *status |= FE_HAS_CARRIER;
69 *status |= FE_HAS_VITERBI;
70 *status |= FE_HAS_LOCK;
71 *status |= FE_HAS_SYNC;
72 *status |= FE_HAS_SIGNAL;
73 }
74
75 return 0;
76}
77
78static int s921_read_ber(struct dvb_frontend *fe, __u32 *ber)
79{
80 dprintk("read ber\n");
81 return 0;
82}
83
84static int s921_read_snr(struct dvb_frontend *fe, __u16 *snr)
85{
86 dprintk("read snr\n");
87 return 0;
88}
89
90static int s921_read_ucblocks(struct dvb_frontend *fe, __u32 *ucblocks)
91{
92 dprintk("read ucblocks\n");
93 return 0;
94}
95
96static void s921_release(struct dvb_frontend *fe)
97{
98 struct s921_state *state = (struct s921_state *)fe->demodulator_priv;
99 kfree(state);
100}
101
102static struct dvb_frontend_ops demod_s921={
103 .info = {
104 .name = "SHARP S921",
105 .type = FE_OFDM,
106 .frequency_min = 473143000,
107 .frequency_max = 767143000,
108 .frequency_stepsize = 6000000,
109 .frequency_tolerance = 0,
110 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
111 FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
112 FE_CAN_FEC_AUTO |
113 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
114 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
115 FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER |
116 FE_CAN_MUTE_TS
117 },
118 .init = s921_init,
119 .sleep = s921_sleep,
120 .set_frontend = s921_set_parameters,
121 .read_snr = s921_read_snr,
122 .read_ber = s921_read_ber,
123 .read_status = s921_read_status,
124 .read_ucblocks = s921_read_ucblocks,
125 .release = s921_release,
126};
127
128static int s921_write(void *dev, u8 reg, u8 val) {
129 struct s921_state *state = dev;
130 char buf[2]={reg,val};
131 int err;
132 struct i2c_msg i2cmsgs = {
133 .addr = state->addr,
134 .flags = 0,
135 .len = 2,
136 .buf = buf
137 };
138
139 if((err = i2c_transfer(state->i2c, &i2cmsgs, 1))<0) {
140 printk("%s i2c_transfer error %d\n", __func__, err);
141 if (err < 0)
142 return err;
143 else
144 return -EREMOTEIO;
145 }
146
147 return 0;
148}
149
150static int s921_read(void *dev, u8 reg) {
151 struct s921_state *state = dev;
152 u8 b1;
153 int ret;
154 struct i2c_msg msg[2] = { { .addr = state->addr,
155 .flags = 0,
156 .buf = &reg, .len = 1 },
157 { .addr = state->addr,
158 .flags = I2C_M_RD,
159 .buf = &b1, .len = 1 } };
160
161 ret = i2c_transfer(state->i2c, msg, 2);
162 if (ret != 2)
163 return ret;
164 return b1;
165}
166
167struct dvb_frontend* s921_attach(const struct s921_config *config,
168 struct i2c_adapter *i2c)
169{
170
171 struct s921_state *state;
172 state = kzalloc(sizeof(struct s921_state), GFP_KERNEL);
173 if (state == NULL)
174 return NULL;
175
176 state->addr = config->i2c_address;
177 state->i2c = i2c;
178 state->dev.i2c_write = &s921_write;
179 state->dev.i2c_read = &s921_read;
180 state->dev.priv_dev = state;
181
182 s921_isdb_cmd(&state->dev, ISDB_T_CMD_INIT, NULL);
183
184 memcpy(&state->frontend.ops, &demod_s921, sizeof(struct dvb_frontend_ops));
185 state->frontend.demodulator_priv = state;
186 return &state->frontend;
187}
188
189EXPORT_SYMBOL_GPL(s921_attach);
190MODULE_AUTHOR("Markus Rechberger <mrechberger@empiatech.com>");
191MODULE_DESCRIPTION("Sharp S921 ISDB-T 1Seg");
192MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/s921_module.h b/drivers/media/dvb/frontends/s921_module.h
deleted file mode 100644
index 78660424ba95..000000000000
--- a/drivers/media/dvb/frontends/s921_module.h
+++ /dev/null
@@ -1,49 +0,0 @@
1/*
2 * Driver for DVB-T s921 demodulator
3 *
4 * Copyright (C) 2008 Markus Rechberger <mrechberger@sundtek.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20 */
21
22#ifndef S921_MODULE_H
23#define S921_MODULE_H
24
25#include <linux/dvb/frontend.h>
26#include "s921_core.h"
27
28int s921_isdb_init(struct s921_isdb_t *dev);
29int s921_isdb_cmd(struct s921_isdb_t *dev, u32 cmd, void *data);
30
31struct s921_config
32{
33 /* demodulator's I2C address */
34 u8 i2c_address;
35};
36
37#if defined(CONFIG_DVB_S921) || (defined(CONFIG_DVB_S921_MODULE) && defined(MODULE))
38extern struct dvb_frontend* s921_attach(const struct s921_config *config,
39 struct i2c_adapter *i2c);
40#else
41static inline struct dvb_frontend* s921_attach(const struct s921_config *config,
42 struct i2c_adapter *i2c)
43{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
45 return NULL;
46}
47#endif /* CONFIG_DVB_S921 */
48
49#endif /* S921_H */
diff --git a/drivers/media/dvb/frontends/si21xx.c b/drivers/media/dvb/frontends/si21xx.c
index d21a327db629..4b0c99a08a85 100644
--- a/drivers/media/dvb/frontends/si21xx.c
+++ b/drivers/media/dvb/frontends/si21xx.c
@@ -268,7 +268,7 @@ static int si21_writereg(struct si21xx_state *state, u8 reg, u8 data)
268 return (ret != 1) ? -EREMOTEIO : 0; 268 return (ret != 1) ? -EREMOTEIO : 0;
269} 269}
270 270
271static int si21_write(struct dvb_frontend *fe, u8 *buf, int len) 271static int si21_write(struct dvb_frontend *fe, const u8 buf[], int len)
272{ 272{
273 struct si21xx_state *state = fe->demodulator_priv; 273 struct si21xx_state *state = fe->demodulator_priv;
274 274
diff --git a/drivers/media/dvb/frontends/stb0899_algo.c b/drivers/media/dvb/frontends/stb0899_algo.c
index 2da55ec20392..d70eee00f33a 100644
--- a/drivers/media/dvb/frontends/stb0899_algo.c
+++ b/drivers/media/dvb/frontends/stb0899_algo.c
@@ -23,7 +23,7 @@
23#include "stb0899_priv.h" 23#include "stb0899_priv.h"
24#include "stb0899_reg.h" 24#include "stb0899_reg.h"
25 25
26inline u32 stb0899_do_div(u64 n, u32 d) 26static inline u32 stb0899_do_div(u64 n, u32 d)
27{ 27{
28 /* wrap do_div() for ease of use */ 28 /* wrap do_div() for ease of use */
29 29
diff --git a/drivers/media/dvb/frontends/stb0899_drv.c b/drivers/media/dvb/frontends/stb0899_drv.c
index 8e38fcee564e..37a222d9ddb3 100644
--- a/drivers/media/dvb/frontends/stb0899_drv.c
+++ b/drivers/media/dvb/frontends/stb0899_drv.c
@@ -714,7 +714,7 @@ static int stb0899_send_diseqc_msg(struct dvb_frontend *fe, struct dvb_diseqc_ma
714 reg = stb0899_read_reg(state, STB0899_DISCNTRL1); 714 reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
715 STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0); 715 STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0);
716 stb0899_write_reg(state, STB0899_DISCNTRL1, reg); 716 stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
717 717 msleep(100);
718 return 0; 718 return 0;
719} 719}
720 720
diff --git a/drivers/media/dvb/frontends/stb6100.c b/drivers/media/dvb/frontends/stb6100.c
index f73c13323e90..bc1a8af4f6e1 100644
--- a/drivers/media/dvb/frontends/stb6100.c
+++ b/drivers/media/dvb/frontends/stb6100.c
@@ -51,7 +51,7 @@ module_param(verbose, int, 0644);
51 if (x > y) \ 51 if (x > y) \
52 printk(format, ##arg); \ 52 printk(format, ##arg); \
53 } \ 53 } \
54} while(0) 54} while (0)
55 55
56struct stb6100_lkup { 56struct stb6100_lkup {
57 u32 val_low; 57 u32 val_low;
@@ -117,7 +117,10 @@ static const struct stb6100_regmask stb6100_template[] = {
117 [STB6100_TEST3] = { 0x00, 0xde }, 117 [STB6100_TEST3] = { 0x00, 0xde },
118}; 118};
119 119
120static void stb6100_normalise_regs(u8 regs[]) 120/*
121 * Currently unused. Some boards might need it in the future
122 */
123static inline void stb6100_normalise_regs(u8 regs[])
121{ 124{
122 int i; 125 int i;
123 126
@@ -157,13 +160,25 @@ static int stb6100_read_reg(struct stb6100_state *state, u8 reg)
157 u8 regs[STB6100_NUMREGS]; 160 u8 regs[STB6100_NUMREGS];
158 int rc; 161 int rc;
159 162
163 struct i2c_msg msg = {
164 .addr = state->config->tuner_address + reg,
165 .flags = I2C_M_RD,
166 .buf = regs,
167 .len = 1
168 };
169
170 rc = i2c_transfer(state->i2c, &msg, 1);
171
160 if (unlikely(reg >= STB6100_NUMREGS)) { 172 if (unlikely(reg >= STB6100_NUMREGS)) {
161 dprintk(verbose, FE_ERROR, 1, "Invalid register offset 0x%x", reg); 173 dprintk(verbose, FE_ERROR, 1, "Invalid register offset 0x%x", reg);
162 return -EINVAL; 174 return -EINVAL;
163 } 175 }
164 if ((rc = stb6100_read_regs(state, regs)) < 0) 176 if (unlikely(verbose > FE_DEBUG)) {
165 return rc; 177 dprintk(verbose, FE_DEBUG, 1, " Read from 0x%02x", state->config->tuner_address);
166 return (unsigned int)regs[reg]; 178 dprintk(verbose, FE_DEBUG, 1, " %s: 0x%02x", stb6100_regnames[reg], regs[0]);
179 }
180
181 return (unsigned int)regs[0];
167} 182}
168 183
169static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int start, int len) 184static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int start, int len)
@@ -211,20 +226,17 @@ static int stb6100_write_reg(struct stb6100_state *state, u8 reg, u8 data)
211 return stb6100_write_reg_range(state, &data, reg, 1); 226 return stb6100_write_reg_range(state, &data, reg, 1);
212} 227}
213 228
214static int stb6100_write_regs(struct stb6100_state *state, u8 regs[])
215{
216 stb6100_normalise_regs(regs);
217 return stb6100_write_reg_range(state, &regs[1], 1, STB6100_NUMREGS - 1);
218}
219 229
220static int stb6100_get_status(struct dvb_frontend *fe, u32 *status) 230static int stb6100_get_status(struct dvb_frontend *fe, u32 *status)
221{ 231{
222 int rc; 232 int rc;
223 struct stb6100_state *state = fe->tuner_priv; 233 struct stb6100_state *state = fe->tuner_priv;
224 234
225 if ((rc = stb6100_read_reg(state, STB6100_LD)) < 0) 235 rc = stb6100_read_reg(state, STB6100_LD);
236 if (rc < 0) {
237 dprintk(verbose, FE_ERROR, 1, "%s failed", __func__);
226 return rc; 238 return rc;
227 239 }
228 return (rc & STB6100_LD_LOCK) ? TUNER_STATUS_LOCKED : 0; 240 return (rc & STB6100_LD_LOCK) ? TUNER_STATUS_LOCKED : 0;
229} 241}
230 242
@@ -234,7 +246,8 @@ static int stb6100_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
234 u8 f; 246 u8 f;
235 struct stb6100_state *state = fe->tuner_priv; 247 struct stb6100_state *state = fe->tuner_priv;
236 248
237 if ((rc = stb6100_read_reg(state, STB6100_F)) < 0) 249 rc = stb6100_read_reg(state, STB6100_F);
250 if (rc < 0)
238 return rc; 251 return rc;
239 f = rc & STB6100_F_F; 252 f = rc & STB6100_F_F;
240 253
@@ -265,14 +278,21 @@ static int stb6100_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
265 /* Turn on LPF bandwidth setting clock control, 278 /* Turn on LPF bandwidth setting clock control,
266 * set bandwidth, wait 10ms, turn off. 279 * set bandwidth, wait 10ms, turn off.
267 */ 280 */
268 if ((rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d | STB6100_FCCK_FCCK)) < 0) 281 rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d | STB6100_FCCK_FCCK);
282 if (rc < 0)
269 return rc; 283 return rc;
270 if ((rc = stb6100_write_reg(state, STB6100_F, 0xc0 | tmp)) < 0) 284 rc = stb6100_write_reg(state, STB6100_F, 0xc0 | tmp);
285 if (rc < 0)
271 return rc; 286 return rc;
272 msleep(1); 287
273 if ((rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d)) < 0) 288 msleep(5); /* This is dangerous as another (related) thread may start */
289
290 rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d);
291 if (rc < 0)
274 return rc; 292 return rc;
275 293
294 msleep(10); /* This is dangerous as another (related) thread may start */
295
276 return 0; 296 return 0;
277} 297}
278 298
@@ -284,7 +304,8 @@ static int stb6100_get_frequency(struct dvb_frontend *fe, u32 *frequency)
284 struct stb6100_state *state = fe->tuner_priv; 304 struct stb6100_state *state = fe->tuner_priv;
285 u8 regs[STB6100_NUMREGS]; 305 u8 regs[STB6100_NUMREGS];
286 306
287 if ((rc = stb6100_read_regs(state, regs)) < 0) 307 rc = stb6100_read_regs(state, regs);
308 if (rc < 0)
288 return rc; 309 return rc;
289 310
290 odiv = (regs[STB6100_VCO] & STB6100_VCO_ODIV) >> STB6100_VCO_ODIV_SHIFT; 311 odiv = (regs[STB6100_VCO] & STB6100_VCO_ODIV) >> STB6100_VCO_ODIV_SHIFT;
@@ -312,8 +333,7 @@ static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency)
312 u8 regs[STB6100_NUMREGS]; 333 u8 regs[STB6100_NUMREGS];
313 u8 g, psd2, odiv; 334 u8 g, psd2, odiv;
314 335
315 if ((rc = stb6100_read_regs(state, regs)) < 0) 336 dprintk(verbose, FE_DEBUG, 1, "Version 2010-8-14 13:51");
316 return rc;
317 337
318 if (fe->ops.get_frontend) { 338 if (fe->ops.get_frontend) {
319 dprintk(verbose, FE_DEBUG, 1, "Get frontend parameters"); 339 dprintk(verbose, FE_DEBUG, 1, "Get frontend parameters");
@@ -321,96 +341,140 @@ static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency)
321 } 341 }
322 srate = p.u.qpsk.symbol_rate; 342 srate = p.u.qpsk.symbol_rate;
323 343
324 regs[STB6100_DLB] = 0xdc; 344 /* Set up tuner cleanly, LPF calibration on */
325 /* Disable LPEN */ 345 rc = stb6100_write_reg(state, STB6100_FCCK, 0x4d | STB6100_FCCK_FCCK);
326 regs[STB6100_LPEN] &= ~STB6100_LPEN_LPEN; /* PLL Loop disabled */ 346 if (rc < 0)
347 return rc; /* allow LPF calibration */
327 348
328 if ((rc = stb6100_write_regs(state, regs)) < 0) 349 /* PLL Loop disabled, bias on, VCO on, synth on */
350 regs[STB6100_LPEN] = 0xeb;
351 rc = stb6100_write_reg(state, STB6100_LPEN, regs[STB6100_LPEN]);
352 if (rc < 0)
329 return rc; 353 return rc;
330 354
331 /* Baseband gain. */ 355 /* Program the registers with their data values */
332 if (srate >= 15000000)
333 g = 9; // +4 dB
334 else if (srate >= 5000000)
335 g = 11; // +8 dB
336 else
337 g = 14; // +14 dB
338
339 regs[STB6100_G] = (regs[STB6100_G] & ~STB6100_G_G) | g;
340 regs[STB6100_G] &= ~STB6100_G_GCT; /* mask GCT */
341 regs[STB6100_G] |= (1 << 5); /* 2Vp-p Mode */
342 356
343 /* VCO divide ratio (LO divide ratio, VCO prescaler enable). */ 357 /* VCO divide ratio (LO divide ratio, VCO prescaler enable). */
344 if (frequency <= 1075000) 358 if (frequency <= 1075000)
345 odiv = 1; 359 odiv = 1;
346 else 360 else
347 odiv = 0; 361 odiv = 0;
348 regs[STB6100_VCO] = (regs[STB6100_VCO] & ~STB6100_VCO_ODIV) | (odiv << STB6100_VCO_ODIV_SHIFT);
349 362
350 if ((frequency > 1075000) && (frequency <= 1325000)) 363 /* VCO enabled, search clock off as per LL3.7, 3.4.1 */
351 psd2 = 0; 364 regs[STB6100_VCO] = 0xe0 | (odiv << STB6100_VCO_ODIV_SHIFT);
352 else
353 psd2 = 1;
354 regs[STB6100_K] = (regs[STB6100_K] & ~STB6100_K_PSD2) | (psd2 << STB6100_K_PSD2_SHIFT);
355 365
356 /* OSM */ 366 /* OSM */
357 for (ptr = lkup; 367 for (ptr = lkup;
358 (ptr->val_high != 0) && !CHKRANGE(frequency, ptr->val_low, ptr->val_high); 368 (ptr->val_high != 0) && !CHKRANGE(frequency, ptr->val_low, ptr->val_high);
359 ptr++); 369 ptr++);
370
360 if (ptr->val_high == 0) { 371 if (ptr->val_high == 0) {
361 printk(KERN_ERR "%s: frequency out of range: %u kHz\n", __func__, frequency); 372 printk(KERN_ERR "%s: frequency out of range: %u kHz\n", __func__, frequency);
362 return -EINVAL; 373 return -EINVAL;
363 } 374 }
364 regs[STB6100_VCO] = (regs[STB6100_VCO] & ~STB6100_VCO_OSM) | ptr->reg; 375 regs[STB6100_VCO] = (regs[STB6100_VCO] & ~STB6100_VCO_OSM) | ptr->reg;
376 rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]);
377 if (rc < 0)
378 return rc;
365 379
380 if ((frequency > 1075000) && (frequency <= 1325000))
381 psd2 = 0;
382 else
383 psd2 = 1;
366 /* F(VCO) = F(LO) * (ODIV == 0 ? 2 : 4) */ 384 /* F(VCO) = F(LO) * (ODIV == 0 ? 2 : 4) */
367 fvco = frequency << (1 + odiv); 385 fvco = frequency << (1 + odiv);
368 /* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1))) */ 386 /* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1))) */
369 nint = fvco / (state->reference << psd2); 387 nint = fvco / (state->reference << psd2);
370 /* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9 */ 388 /* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9 */
371 nfrac = DIV_ROUND_CLOSEST((fvco - (nint * state->reference << psd2)) 389 nfrac = DIV_ROUND_CLOSEST((fvco - (nint * state->reference << psd2))
372 << (9 - psd2), 390 << (9 - psd2), state->reference);
373 state->reference); 391
392 /* NI */
393 regs[STB6100_NI] = nint;
394 rc = stb6100_write_reg(state, STB6100_NI, regs[STB6100_NI]);
395 if (rc < 0)
396 return rc;
397
398 /* NF */
399 regs[STB6100_NF_LSB] = nfrac;
400 rc = stb6100_write_reg(state, STB6100_NF_LSB, regs[STB6100_NF_LSB]);
401 if (rc < 0)
402 return rc;
403
404 /* K */
405 regs[STB6100_K] = (0x38 & ~STB6100_K_PSD2) | (psd2 << STB6100_K_PSD2_SHIFT);
406 regs[STB6100_K] = (regs[STB6100_K] & ~STB6100_K_NF_MSB) | ((nfrac >> 8) & STB6100_K_NF_MSB);
407 rc = stb6100_write_reg(state, STB6100_K, regs[STB6100_K]);
408 if (rc < 0)
409 return rc;
410
411 /* G Baseband gain. */
412 if (srate >= 15000000)
413 g = 9; /* +4 dB */
414 else if (srate >= 5000000)
415 g = 11; /* +8 dB */
416 else
417 g = 14; /* +14 dB */
418
419 regs[STB6100_G] = (0x10 & ~STB6100_G_G) | g;
420 regs[STB6100_G] &= ~STB6100_G_GCT; /* mask GCT */
421 regs[STB6100_G] |= (1 << 5); /* 2Vp-p Mode */
422 rc = stb6100_write_reg(state, STB6100_G, regs[STB6100_G]);
423 if (rc < 0)
424 return rc;
425
426 /* F we don't write as it is set up in BW set */
427
428 /* DLB set DC servo loop BW to 160Hz (LLA 3.8 / 2.1) */
429 regs[STB6100_DLB] = 0xcc;
430 rc = stb6100_write_reg(state, STB6100_DLB, regs[STB6100_DLB]);
431 if (rc < 0)
432 return rc;
433
374 dprintk(verbose, FE_DEBUG, 1, 434 dprintk(verbose, FE_DEBUG, 1,
375 "frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u", 435 "frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u",
376 frequency, srate, (unsigned int)g, (unsigned int)odiv, 436 frequency, srate, (unsigned int)g, (unsigned int)odiv,
377 (unsigned int)psd2, state->reference, 437 (unsigned int)psd2, state->reference,
378 ptr->reg, fvco, nint, nfrac); 438 ptr->reg, fvco, nint, nfrac);
379 regs[STB6100_NI] = nint;
380 regs[STB6100_NF_LSB] = nfrac;
381 regs[STB6100_K] = (regs[STB6100_K] & ~STB6100_K_NF_MSB) | ((nfrac >> 8) & STB6100_K_NF_MSB);
382 regs[STB6100_VCO] |= STB6100_VCO_OSCH; /* VCO search enabled */
383 regs[STB6100_VCO] |= STB6100_VCO_OCK; /* VCO search clock off */
384 regs[STB6100_FCCK] |= STB6100_FCCK_FCCK; /* LPF BW setting clock enabled */
385 regs[STB6100_LPEN] &= ~STB6100_LPEN_LPEN; /* PLL loop disabled */
386 /* Power up. */
387 regs[STB6100_LPEN] |= STB6100_LPEN_SYNP | STB6100_LPEN_OSCP | STB6100_LPEN_BEN;
388 439
389 msleep(2); 440 /* Set up the test registers */
390 if ((rc = stb6100_write_regs(state, regs)) < 0) 441 regs[STB6100_TEST1] = 0x8f;
442 rc = stb6100_write_reg(state, STB6100_TEST1, regs[STB6100_TEST1]);
443 if (rc < 0)
444 return rc;
445 regs[STB6100_TEST3] = 0xde;
446 rc = stb6100_write_reg(state, STB6100_TEST3, regs[STB6100_TEST3]);
447 if (rc < 0)
391 return rc; 448 return rc;
392 449
393 msleep(2); 450 /* Bring up tuner according to LLA 3.7 3.4.1, step 2 */
394 regs[STB6100_LPEN] |= STB6100_LPEN_LPEN; /* PLL loop enabled */ 451 regs[STB6100_LPEN] = 0xfb; /* PLL Loop enabled, bias on, VCO on, synth on */
395 if ((rc = stb6100_write_reg(state, STB6100_LPEN, regs[STB6100_LPEN])) < 0) 452 rc = stb6100_write_reg(state, STB6100_LPEN, regs[STB6100_LPEN]);
453 if (rc < 0)
396 return rc; 454 return rc;
397 455
456 msleep(2);
457
458 /* Bring up tuner according to LLA 3.7 3.4.1, step 3 */
398 regs[STB6100_VCO] &= ~STB6100_VCO_OCK; /* VCO fast search */ 459 regs[STB6100_VCO] &= ~STB6100_VCO_OCK; /* VCO fast search */
399 if ((rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO])) < 0) 460 rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]);
461 if (rc < 0)
400 return rc; 462 return rc;
401 463
402 msleep(10); /* wait for LO to lock */ 464 msleep(10); /* This is dangerous as another (related) thread may start */ /* wait for LO to lock */
465
403 regs[STB6100_VCO] &= ~STB6100_VCO_OSCH; /* vco search disabled */ 466 regs[STB6100_VCO] &= ~STB6100_VCO_OSCH; /* vco search disabled */
404 regs[STB6100_VCO] |= STB6100_VCO_OCK; /* search clock off */ 467 regs[STB6100_VCO] |= STB6100_VCO_OCK; /* search clock off */
405 if ((rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO])) < 0) 468 rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]);
406 return rc; 469 if (rc < 0)
407 regs[STB6100_FCCK] &= ~STB6100_FCCK_FCCK; /* LPF BW clock disabled */
408 stb6100_normalise_regs(regs);
409 if ((rc = stb6100_write_reg_range(state, &regs[1], 1, STB6100_NUMREGS - 3)) < 0)
410 return rc; 470 return rc;
411 471
412 msleep(100); 472 rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d);
473 if (rc < 0)
474 return rc; /* Stop LPF calibration */
413 475
476 msleep(10); /* This is dangerous as another (related) thread may start */
477 /* wait for stabilisation, (should not be necessary) */
414 return 0; 478 return 0;
415} 479}
416 480
@@ -433,8 +497,8 @@ static int stb6100_init(struct dvb_frontend *fe)
433 state->bandwidth = status->bandwidth * 1000; /* Hz */ 497 state->bandwidth = status->bandwidth * 1000; /* Hz */
434 state->reference = status->refclock / 1000; /* kHz */ 498 state->reference = status->refclock / 1000; /* kHz */
435 499
436 /* Set default bandwidth. */ 500 /* Set default bandwidth. Modified, PN 13-May-10 */
437 return stb6100_set_bandwidth(fe, state->bandwidth); 501 return 0;
438} 502}
439 503
440static int stb6100_get_state(struct dvb_frontend *fe, 504static int stb6100_get_state(struct dvb_frontend *fe,
@@ -506,7 +570,7 @@ static struct dvb_tuner_ops stb6100_ops = {
506}; 570};
507 571
508struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe, 572struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe,
509 struct stb6100_config *config, 573 const struct stb6100_config *config,
510 struct i2c_adapter *i2c) 574 struct i2c_adapter *i2c)
511{ 575{
512 struct stb6100_state *state = NULL; 576 struct stb6100_state *state = NULL;
diff --git a/drivers/media/dvb/frontends/stb6100.h b/drivers/media/dvb/frontends/stb6100.h
index 395d056599a6..2ab096614b3f 100644
--- a/drivers/media/dvb/frontends/stb6100.h
+++ b/drivers/media/dvb/frontends/stb6100.h
@@ -97,13 +97,13 @@ struct stb6100_state {
97#if defined(CONFIG_DVB_STB6100) || (defined(CONFIG_DVB_STB6100_MODULE) && defined(MODULE)) 97#if defined(CONFIG_DVB_STB6100) || (defined(CONFIG_DVB_STB6100_MODULE) && defined(MODULE))
98 98
99extern struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe, 99extern struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe,
100 struct stb6100_config *config, 100 const struct stb6100_config *config,
101 struct i2c_adapter *i2c); 101 struct i2c_adapter *i2c);
102 102
103#else 103#else
104 104
105static inline struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe, 105static inline struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe,
106 struct stb6100_config *config, 106 const struct stb6100_config *config,
107 struct i2c_adapter *i2c) 107 struct i2c_adapter *i2c)
108{ 108{
109 printk(KERN_WARNING "%s: Driver disabled by Kconfig\n", __func__); 109 printk(KERN_WARNING "%s: Driver disabled by Kconfig\n", __func__);
diff --git a/drivers/media/dvb/frontends/stv0288.c b/drivers/media/dvb/frontends/stv0288.c
index 2930a5d6768a..8e0cfadba688 100644
--- a/drivers/media/dvb/frontends/stv0288.c
+++ b/drivers/media/dvb/frontends/stv0288.c
@@ -6,6 +6,8 @@
6 Copyright (C) 2008 Igor M. Liplianin <liplianin@me.by> 6 Copyright (C) 2008 Igor M. Liplianin <liplianin@me.by>
7 Removed stb6000 specific tuner code and revised some 7 Removed stb6000 specific tuner code and revised some
8 procedures. 8 procedures.
9 2010-09-01 Josef Pavlik <josef@pavlik.it>
10 Fixed diseqc_msg, diseqc_burst and set_tone problems
9 11
10 This program is free software; you can redistribute it and/or modify 12 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by 13 it under the terms of the GNU General Public License as published by
@@ -78,7 +80,7 @@ static int stv0288_writeregI(struct stv0288_state *state, u8 reg, u8 data)
78 return (ret != 1) ? -EREMOTEIO : 0; 80 return (ret != 1) ? -EREMOTEIO : 0;
79} 81}
80 82
81static int stv0288_write(struct dvb_frontend *fe, u8 *buf, int len) 83static int stv0288_write(struct dvb_frontend *fe, const u8 buf[], int len)
82{ 84{
83 struct stv0288_state *state = fe->demodulator_priv; 85 struct stv0288_state *state = fe->demodulator_priv;
84 86
@@ -156,14 +158,13 @@ static int stv0288_send_diseqc_msg(struct dvb_frontend *fe,
156 158
157 stv0288_writeregI(state, 0x09, 0); 159 stv0288_writeregI(state, 0x09, 0);
158 msleep(30); 160 msleep(30);
159 stv0288_writeregI(state, 0x05, 0x16); 161 stv0288_writeregI(state, 0x05, 0x12);/* modulated mode, single shot */
160 162
161 for (i = 0; i < m->msg_len; i++) { 163 for (i = 0; i < m->msg_len; i++) {
162 if (stv0288_writeregI(state, 0x06, m->msg[i])) 164 if (stv0288_writeregI(state, 0x06, m->msg[i]))
163 return -EREMOTEIO; 165 return -EREMOTEIO;
164 msleep(12);
165 } 166 }
166 167 msleep(m->msg_len*12);
167 return 0; 168 return 0;
168} 169}
169 170
@@ -174,13 +175,14 @@ static int stv0288_send_diseqc_burst(struct dvb_frontend *fe,
174 175
175 dprintk("%s\n", __func__); 176 dprintk("%s\n", __func__);
176 177
177 if (stv0288_writeregI(state, 0x05, 0x16))/* burst mode */ 178 if (stv0288_writeregI(state, 0x05, 0x03))/* burst mode, single shot */
178 return -EREMOTEIO; 179 return -EREMOTEIO;
179 180
180 if (stv0288_writeregI(state, 0x06, burst == SEC_MINI_A ? 0x00 : 0xff)) 181 if (stv0288_writeregI(state, 0x06, burst == SEC_MINI_A ? 0x00 : 0xff))
181 return -EREMOTEIO; 182 return -EREMOTEIO;
182 183
183 if (stv0288_writeregI(state, 0x06, 0x12)) 184 msleep(15);
185 if (stv0288_writeregI(state, 0x05, 0x12))
184 return -EREMOTEIO; 186 return -EREMOTEIO;
185 187
186 return 0; 188 return 0;
@@ -192,18 +194,19 @@ static int stv0288_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
192 194
193 switch (tone) { 195 switch (tone) {
194 case SEC_TONE_ON: 196 case SEC_TONE_ON:
195 if (stv0288_writeregI(state, 0x05, 0x10))/* burst mode */ 197 if (stv0288_writeregI(state, 0x05, 0x10))/* cont carrier */
196 return -EREMOTEIO; 198 return -EREMOTEIO;
197 return stv0288_writeregI(state, 0x06, 0xff); 199 break;
198 200
199 case SEC_TONE_OFF: 201 case SEC_TONE_OFF:
200 if (stv0288_writeregI(state, 0x05, 0x13))/* burst mode */ 202 if (stv0288_writeregI(state, 0x05, 0x12))/* burst mode off*/
201 return -EREMOTEIO; 203 return -EREMOTEIO;
202 return stv0288_writeregI(state, 0x06, 0x00); 204 break;
203 205
204 default: 206 default:
205 return -EINVAL; 207 return -EINVAL;
206 } 208 }
209 return 0;
207} 210}
208 211
209static u8 stv0288_inittab[] = { 212static u8 stv0288_inittab[] = {
@@ -250,7 +253,7 @@ static u8 stv0288_inittab[] = {
250 0x3d, 0x30, 253 0x3d, 0x30,
251 0x40, 0x63, 254 0x40, 0x63,
252 0x41, 0x04, 255 0x41, 0x04,
253 0x42, 0x60, 256 0x42, 0x20,
254 0x43, 0x00, 257 0x43, 0x00,
255 0x44, 0x00, 258 0x44, 0x00,
256 0x45, 0x00, 259 0x45, 0x00,
@@ -364,8 +367,11 @@ static int stv0288_read_status(struct dvb_frontend *fe, fe_status_t *status)
364 dprintk("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __func__, sync); 367 dprintk("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __func__, sync);
365 368
366 *status = 0; 369 *status = 0;
367 370 if (sync & 0x80)
368 if ((sync & 0x08) == 0x08) { 371 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
372 if (sync & 0x10)
373 *status |= FE_HAS_VITERBI;
374 if (sync & 0x08) {
369 *status |= FE_HAS_LOCK; 375 *status |= FE_HAS_LOCK;
370 dprintk("stv0288 has locked\n"); 376 dprintk("stv0288 has locked\n");
371 } 377 }
@@ -486,7 +492,7 @@ static int stv0288_set_frontend(struct dvb_frontend *fe,
486 tda[2] = 0x0; /* CFRL */ 492 tda[2] = 0x0; /* CFRL */
487 for (tm = -6; tm < 7;) { 493 for (tm = -6; tm < 7;) {
488 /* Viterbi status */ 494 /* Viterbi status */
489 if (stv0288_readreg(state, 0x24) & 0x80) 495 if (stv0288_readreg(state, 0x24) & 0x8)
490 break; 496 break;
491 497
492 tda[2] += 40; 498 tda[2] += 40;
diff --git a/drivers/media/dvb/frontends/stv0297.c b/drivers/media/dvb/frontends/stv0297.c
index 4fd7479bb62b..84d88f33275e 100644
--- a/drivers/media/dvb/frontends/stv0297.c
+++ b/drivers/media/dvb/frontends/stv0297.c
@@ -435,7 +435,7 @@ static int stv0297_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
435 return -EINVAL; 435 return -EINVAL;
436 } 436 }
437 437
438 // determine inversion dependant parameters 438 // determine inversion dependent parameters
439 inversion = p->inversion; 439 inversion = p->inversion;
440 if (state->config->invert) 440 if (state->config->invert)
441 inversion = (inversion == INVERSION_ON) ? INVERSION_OFF : INVERSION_ON; 441 inversion = (inversion == INVERSION_ON) ? INVERSION_OFF : INVERSION_ON;
diff --git a/drivers/media/dvb/frontends/stv0299.c b/drivers/media/dvb/frontends/stv0299.c
index 968874469726..42684bec8883 100644
--- a/drivers/media/dvb/frontends/stv0299.c
+++ b/drivers/media/dvb/frontends/stv0299.c
@@ -64,6 +64,7 @@ struct stv0299_state {
64 fe_code_rate_t fec_inner; 64 fe_code_rate_t fec_inner;
65 int errmode; 65 int errmode;
66 u32 ucblocks; 66 u32 ucblocks;
67 u8 mcr_reg;
67}; 68};
68 69
69#define STATUS_BER 0 70#define STATUS_BER 0
@@ -92,7 +93,7 @@ static int stv0299_writeregI (struct stv0299_state* state, u8 reg, u8 data)
92 return (ret != 1) ? -EREMOTEIO : 0; 93 return (ret != 1) ? -EREMOTEIO : 0;
93} 94}
94 95
95static int stv0299_write(struct dvb_frontend* fe, u8 *buf, int len) 96static int stv0299_write(struct dvb_frontend* fe, const u8 buf[], int len)
96{ 97{
97 struct stv0299_state* state = fe->demodulator_priv; 98 struct stv0299_state* state = fe->demodulator_priv;
98 99
@@ -457,6 +458,9 @@ static int stv0299_init (struct dvb_frontend* fe)
457 458
458 dprintk("stv0299: init chip\n"); 459 dprintk("stv0299: init chip\n");
459 460
461 stv0299_writeregI(state, 0x02, 0x30 | state->mcr_reg);
462 msleep(50);
463
460 for (i = 0; ; i += 2) { 464 for (i = 0; ; i += 2) {
461 reg = state->config->inittab[i]; 465 reg = state->config->inittab[i];
462 val = state->config->inittab[i+1]; 466 val = state->config->inittab[i+1];
@@ -464,6 +468,8 @@ static int stv0299_init (struct dvb_frontend* fe)
464 break; 468 break;
465 if (reg == 0x0c && state->config->op0_off) 469 if (reg == 0x0c && state->config->op0_off)
466 val &= ~0x10; 470 val &= ~0x10;
471 if (reg == 0x2)
472 state->mcr_reg = val & 0xf;
467 stv0299_writeregI(state, reg, val); 473 stv0299_writeregI(state, reg, val);
468 } 474 }
469 475
@@ -618,7 +624,7 @@ static int stv0299_sleep(struct dvb_frontend* fe)
618{ 624{
619 struct stv0299_state* state = fe->demodulator_priv; 625 struct stv0299_state* state = fe->demodulator_priv;
620 626
621 stv0299_writeregI(state, 0x02, 0x80); 627 stv0299_writeregI(state, 0x02, 0xb0 | state->mcr_reg);
622 state->initialised = 0; 628 state->initialised = 0;
623 629
624 return 0; 630 return 0;
@@ -680,7 +686,7 @@ struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,
680 state->errmode = STATUS_BER; 686 state->errmode = STATUS_BER;
681 687
682 /* check if the demod is there */ 688 /* check if the demod is there */
683 stv0299_writeregI(state, 0x02, 0x34); /* standby off */ 689 stv0299_writeregI(state, 0x02, 0x30); /* standby off */
684 msleep(200); 690 msleep(200);
685 id = stv0299_readreg(state, 0x00); 691 id = stv0299_readreg(state, 0x00);
686 692
diff --git a/drivers/media/dvb/frontends/stv0299.h b/drivers/media/dvb/frontends/stv0299.h
index 0fd96e22b650..ba219b767a69 100644
--- a/drivers/media/dvb/frontends/stv0299.h
+++ b/drivers/media/dvb/frontends/stv0299.h
@@ -65,7 +65,7 @@ struct stv0299_config
65 * First of each pair is the register, second is the value. 65 * First of each pair is the register, second is the value.
66 * List should be terminated with an 0xff, 0xff pair. 66 * List should be terminated with an 0xff, 0xff pair.
67 */ 67 */
68 u8* inittab; 68 const u8* inittab;
69 69
70 /* master clock to use */ 70 /* master clock to use */
71 u32 mclk; 71 u32 mclk;
diff --git a/drivers/media/dvb/frontends/stv0367.c b/drivers/media/dvb/frontends/stv0367.c
new file mode 100644
index 000000000000..e57ab53e2e27
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0367.c
@@ -0,0 +1,3459 @@
1/*
2 * stv0367.c
3 *
4 * Driver for ST STV0367 DVB-T & DVB-C demodulator IC.
5 *
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2010,2011 NetUP Inc.
8 * Copyright (C) 2010,2011 Igor M. Liplianin <liplianin@netup.ru>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/string.h>
29#include <linux/slab.h>
30#include <linux/i2c.h>
31
32#include "stv0367.h"
33#include "stv0367_regs.h"
34#include "stv0367_priv.h"
35
36static int stvdebug;
37module_param_named(debug, stvdebug, int, 0644);
38
39static int i2cdebug;
40module_param_named(i2c_debug, i2cdebug, int, 0644);
41
42#define dprintk(args...) \
43 do { \
44 if (stvdebug) \
45 printk(KERN_DEBUG args); \
46 } while (0)
47 /* DVB-C */
48
49struct stv0367cab_state {
50 enum stv0367_cab_signal_type state;
51 u32 mclk;
52 u32 adc_clk;
53 s32 search_range;
54 s32 derot_offset;
55 /* results */
56 int locked; /* channel found */
57 u32 freq_khz; /* found frequency (in kHz) */
58 u32 symbol_rate; /* found symbol rate (in Bds) */
59 enum stv0367cab_mod modulation; /* modulation */
60 fe_spectral_inversion_t spect_inv; /* Spectrum Inversion */
61};
62
63struct stv0367ter_state {
64 /* DVB-T */
65 enum stv0367_ter_signal_type state;
66 enum stv0367_ter_if_iq_mode if_iq_mode;
67 enum stv0367_ter_mode mode;/* mode 2K or 8K */
68 fe_guard_interval_t guard;
69 enum stv0367_ter_hierarchy hierarchy;
70 u32 frequency;
71 fe_spectral_inversion_t sense; /* current search spectrum */
72 u8 force; /* force mode/guard */
73 u8 bw; /* channel width 6, 7 or 8 in MHz */
74 u8 pBW; /* channel width used during previous lock */
75 u32 pBER;
76 u32 pPER;
77 u32 ucblocks;
78 s8 echo_pos; /* echo position */
79 u8 first_lock;
80 u8 unlock_counter;
81 u32 agc_val;
82};
83
84struct stv0367_state {
85 struct dvb_frontend fe;
86 struct i2c_adapter *i2c;
87 /* config settings */
88 const struct stv0367_config *config;
89 u8 chip_id;
90 /* DVB-C */
91 struct stv0367cab_state *cab_state;
92 /* DVB-T */
93 struct stv0367ter_state *ter_state;
94};
95
96struct st_register {
97 u16 addr;
98 u8 value;
99};
100
101/* values for STV4100 XTAL=30M int clk=53.125M*/
102static struct st_register def0367ter[STV0367TER_NBREGS] = {
103 {R367TER_ID, 0x60},
104 {R367TER_I2CRPT, 0xa0},
105 /* {R367TER_I2CRPT, 0x22},*/
106 {R367TER_TOPCTRL, 0x00},/* for xc5000; was 0x02 */
107 {R367TER_IOCFG0, 0x40},
108 {R367TER_DAC0R, 0x00},
109 {R367TER_IOCFG1, 0x00},
110 {R367TER_DAC1R, 0x00},
111 {R367TER_IOCFG2, 0x62},
112 {R367TER_SDFR, 0x00},
113 {R367TER_STATUS, 0xf8},
114 {R367TER_AUX_CLK, 0x0a},
115 {R367TER_FREESYS1, 0x00},
116 {R367TER_FREESYS2, 0x00},
117 {R367TER_FREESYS3, 0x00},
118 {R367TER_GPIO_CFG, 0x55},
119 {R367TER_GPIO_CMD, 0x00},
120 {R367TER_AGC2MAX, 0xff},
121 {R367TER_AGC2MIN, 0x00},
122 {R367TER_AGC1MAX, 0xff},
123 {R367TER_AGC1MIN, 0x00},
124 {R367TER_AGCR, 0xbc},
125 {R367TER_AGC2TH, 0x00},
126 {R367TER_AGC12C, 0x00},
127 {R367TER_AGCCTRL1, 0x85},
128 {R367TER_AGCCTRL2, 0x1f},
129 {R367TER_AGC1VAL1, 0x00},
130 {R367TER_AGC1VAL2, 0x00},
131 {R367TER_AGC2VAL1, 0x6f},
132 {R367TER_AGC2VAL2, 0x05},
133 {R367TER_AGC2PGA, 0x00},
134 {R367TER_OVF_RATE1, 0x00},
135 {R367TER_OVF_RATE2, 0x00},
136 {R367TER_GAIN_SRC1, 0xaa},/* for xc5000; was 0x2b */
137 {R367TER_GAIN_SRC2, 0xd6},/* for xc5000; was 0x04 */
138 {R367TER_INC_DEROT1, 0x55},
139 {R367TER_INC_DEROT2, 0x55},
140 {R367TER_PPM_CPAMP_DIR, 0x2c},
141 {R367TER_PPM_CPAMP_INV, 0x00},
142 {R367TER_FREESTFE_1, 0x00},
143 {R367TER_FREESTFE_2, 0x1c},
144 {R367TER_DCOFFSET, 0x00},
145 {R367TER_EN_PROCESS, 0x05},
146 {R367TER_SDI_SMOOTHER, 0x80},
147 {R367TER_FE_LOOP_OPEN, 0x1c},
148 {R367TER_FREQOFF1, 0x00},
149 {R367TER_FREQOFF2, 0x00},
150 {R367TER_FREQOFF3, 0x00},
151 {R367TER_TIMOFF1, 0x00},
152 {R367TER_TIMOFF2, 0x00},
153 {R367TER_EPQ, 0x02},
154 {R367TER_EPQAUTO, 0x01},
155 {R367TER_SYR_UPDATE, 0xf5},
156 {R367TER_CHPFREE, 0x00},
157 {R367TER_PPM_STATE_MAC, 0x23},
158 {R367TER_INR_THRESHOLD, 0xff},
159 {R367TER_EPQ_TPS_ID_CELL, 0xf9},
160 {R367TER_EPQ_CFG, 0x00},
161 {R367TER_EPQ_STATUS, 0x01},
162 {R367TER_AUTORELOCK, 0x81},
163 {R367TER_BER_THR_VMSB, 0x00},
164 {R367TER_BER_THR_MSB, 0x00},
165 {R367TER_BER_THR_LSB, 0x00},
166 {R367TER_CCD, 0x83},
167 {R367TER_SPECTR_CFG, 0x00},
168 {R367TER_CHC_DUMMY, 0x18},
169 {R367TER_INC_CTL, 0x88},
170 {R367TER_INCTHRES_COR1, 0xb4},
171 {R367TER_INCTHRES_COR2, 0x96},
172 {R367TER_INCTHRES_DET1, 0x0e},
173 {R367TER_INCTHRES_DET2, 0x11},
174 {R367TER_IIR_CELLNB, 0x8d},
175 {R367TER_IIRCX_COEFF1_MSB, 0x00},
176 {R367TER_IIRCX_COEFF1_LSB, 0x00},
177 {R367TER_IIRCX_COEFF2_MSB, 0x09},
178 {R367TER_IIRCX_COEFF2_LSB, 0x18},
179 {R367TER_IIRCX_COEFF3_MSB, 0x14},
180 {R367TER_IIRCX_COEFF3_LSB, 0x9c},
181 {R367TER_IIRCX_COEFF4_MSB, 0x00},
182 {R367TER_IIRCX_COEFF4_LSB, 0x00},
183 {R367TER_IIRCX_COEFF5_MSB, 0x36},
184 {R367TER_IIRCX_COEFF5_LSB, 0x42},
185 {R367TER_FEPATH_CFG, 0x00},
186 {R367TER_PMC1_FUNC, 0x65},
187 {R367TER_PMC1_FOR, 0x00},
188 {R367TER_PMC2_FUNC, 0x00},
189 {R367TER_STATUS_ERR_DA, 0xe0},
190 {R367TER_DIG_AGC_R, 0xfe},
191 {R367TER_COMAGC_TARMSB, 0x0b},
192 {R367TER_COM_AGC_TAR_ENMODE, 0x41},
193 {R367TER_COM_AGC_CFG, 0x3e},
194 {R367TER_COM_AGC_GAIN1, 0x39},
195 {R367TER_AUT_AGC_TARGETMSB, 0x0b},
196 {R367TER_LOCK_DET_MSB, 0x01},
197 {R367TER_AGCTAR_LOCK_LSBS, 0x40},
198 {R367TER_AUT_GAIN_EN, 0xf4},
199 {R367TER_AUT_CFG, 0xf0},
200 {R367TER_LOCKN, 0x23},
201 {R367TER_INT_X_3, 0x00},
202 {R367TER_INT_X_2, 0x03},
203 {R367TER_INT_X_1, 0x8d},
204 {R367TER_INT_X_0, 0xa0},
205 {R367TER_MIN_ERRX_MSB, 0x00},
206 {R367TER_COR_CTL, 0x23},
207 {R367TER_COR_STAT, 0xf6},
208 {R367TER_COR_INTEN, 0x00},
209 {R367TER_COR_INTSTAT, 0x3f},
210 {R367TER_COR_MODEGUARD, 0x03},
211 {R367TER_AGC_CTL, 0x08},
212 {R367TER_AGC_MANUAL1, 0x00},
213 {R367TER_AGC_MANUAL2, 0x00},
214 {R367TER_AGC_TARG, 0x16},
215 {R367TER_AGC_GAIN1, 0x53},
216 {R367TER_AGC_GAIN2, 0x1d},
217 {R367TER_RESERVED_1, 0x00},
218 {R367TER_RESERVED_2, 0x00},
219 {R367TER_RESERVED_3, 0x00},
220 {R367TER_CAS_CTL, 0x44},
221 {R367TER_CAS_FREQ, 0xb3},
222 {R367TER_CAS_DAGCGAIN, 0x12},
223 {R367TER_SYR_CTL, 0x04},
224 {R367TER_SYR_STAT, 0x10},
225 {R367TER_SYR_NCO1, 0x00},
226 {R367TER_SYR_NCO2, 0x00},
227 {R367TER_SYR_OFFSET1, 0x00},
228 {R367TER_SYR_OFFSET2, 0x00},
229 {R367TER_FFT_CTL, 0x00},
230 {R367TER_SCR_CTL, 0x70},
231 {R367TER_PPM_CTL1, 0xf8},
232 {R367TER_TRL_CTL, 0x14},/* for xc5000; was 0xac */
233 {R367TER_TRL_NOMRATE1, 0xae},/* for xc5000; was 0x1e */
234 {R367TER_TRL_NOMRATE2, 0x56},/* for xc5000; was 0x58 */
235 {R367TER_TRL_TIME1, 0x1d},
236 {R367TER_TRL_TIME2, 0xfc},
237 {R367TER_CRL_CTL, 0x24},
238 {R367TER_CRL_FREQ1, 0xad},
239 {R367TER_CRL_FREQ2, 0x9d},
240 {R367TER_CRL_FREQ3, 0xff},
241 {R367TER_CHC_CTL, 0x01},
242 {R367TER_CHC_SNR, 0xf0},
243 {R367TER_BDI_CTL, 0x00},
244 {R367TER_DMP_CTL, 0x00},
245 {R367TER_TPS_RCVD1, 0x30},
246 {R367TER_TPS_RCVD2, 0x02},
247 {R367TER_TPS_RCVD3, 0x01},
248 {R367TER_TPS_RCVD4, 0x00},
249 {R367TER_TPS_ID_CELL1, 0x00},
250 {R367TER_TPS_ID_CELL2, 0x00},
251 {R367TER_TPS_RCVD5_SET1, 0x02},
252 {R367TER_TPS_SET2, 0x02},
253 {R367TER_TPS_SET3, 0x01},
254 {R367TER_TPS_CTL, 0x00},
255 {R367TER_CTL_FFTOSNUM, 0x34},
256 {R367TER_TESTSELECT, 0x09},
257 {R367TER_MSC_REV, 0x0a},
258 {R367TER_PIR_CTL, 0x00},
259 {R367TER_SNR_CARRIER1, 0xa1},
260 {R367TER_SNR_CARRIER2, 0x9a},
261 {R367TER_PPM_CPAMP, 0x2c},
262 {R367TER_TSM_AP0, 0x00},
263 {R367TER_TSM_AP1, 0x00},
264 {R367TER_TSM_AP2 , 0x00},
265 {R367TER_TSM_AP3, 0x00},
266 {R367TER_TSM_AP4, 0x00},
267 {R367TER_TSM_AP5, 0x00},
268 {R367TER_TSM_AP6, 0x00},
269 {R367TER_TSM_AP7, 0x00},
270 {R367TER_TSTRES, 0x00},
271 {R367TER_ANACTRL, 0x0D},/* PLL stoped, restart at init!!! */
272 {R367TER_TSTBUS, 0x00},
273 {R367TER_TSTRATE, 0x00},
274 {R367TER_CONSTMODE, 0x01},
275 {R367TER_CONSTCARR1, 0x00},
276 {R367TER_CONSTCARR2, 0x00},
277 {R367TER_ICONSTEL, 0x0a},
278 {R367TER_QCONSTEL, 0x15},
279 {R367TER_TSTBISTRES0, 0x00},
280 {R367TER_TSTBISTRES1, 0x00},
281 {R367TER_TSTBISTRES2, 0x28},
282 {R367TER_TSTBISTRES3, 0x00},
283 {R367TER_RF_AGC1, 0xff},
284 {R367TER_RF_AGC2, 0x83},
285 {R367TER_ANADIGCTRL, 0x19},
286 {R367TER_PLLMDIV, 0x01},/* for xc5000; was 0x0c */
287 {R367TER_PLLNDIV, 0x06},/* for xc5000; was 0x55 */
288 {R367TER_PLLSETUP, 0x18},
289 {R367TER_DUAL_AD12, 0x0C},/* for xc5000 AGC voltage 1.6V */
290 {R367TER_TSTBIST, 0x00},
291 {R367TER_PAD_COMP_CTRL, 0x00},
292 {R367TER_PAD_COMP_WR, 0x00},
293 {R367TER_PAD_COMP_RD, 0xe0},
294 {R367TER_SYR_TARGET_FFTADJT_MSB, 0x00},
295 {R367TER_SYR_TARGET_FFTADJT_LSB, 0x00},
296 {R367TER_SYR_TARGET_CHCADJT_MSB, 0x00},
297 {R367TER_SYR_TARGET_CHCADJT_LSB, 0x00},
298 {R367TER_SYR_FLAG, 0x00},
299 {R367TER_CRL_TARGET1, 0x00},
300 {R367TER_CRL_TARGET2, 0x00},
301 {R367TER_CRL_TARGET3, 0x00},
302 {R367TER_CRL_TARGET4, 0x00},
303 {R367TER_CRL_FLAG, 0x00},
304 {R367TER_TRL_TARGET1, 0x00},
305 {R367TER_TRL_TARGET2, 0x00},
306 {R367TER_TRL_CHC, 0x00},
307 {R367TER_CHC_SNR_TARG, 0x00},
308 {R367TER_TOP_TRACK, 0x00},
309 {R367TER_TRACKER_FREE1, 0x00},
310 {R367TER_ERROR_CRL1, 0x00},
311 {R367TER_ERROR_CRL2, 0x00},
312 {R367TER_ERROR_CRL3, 0x00},
313 {R367TER_ERROR_CRL4, 0x00},
314 {R367TER_DEC_NCO1, 0x2c},
315 {R367TER_DEC_NCO2, 0x0f},
316 {R367TER_DEC_NCO3, 0x20},
317 {R367TER_SNR, 0xf1},
318 {R367TER_SYR_FFTADJ1, 0x00},
319 {R367TER_SYR_FFTADJ2, 0x00},
320 {R367TER_SYR_CHCADJ1, 0x00},
321 {R367TER_SYR_CHCADJ2, 0x00},
322 {R367TER_SYR_OFF, 0x00},
323 {R367TER_PPM_OFFSET1, 0x00},
324 {R367TER_PPM_OFFSET2, 0x03},
325 {R367TER_TRACKER_FREE2, 0x00},
326 {R367TER_DEBG_LT10, 0x00},
327 {R367TER_DEBG_LT11, 0x00},
328 {R367TER_DEBG_LT12, 0x00},
329 {R367TER_DEBG_LT13, 0x00},
330 {R367TER_DEBG_LT14, 0x00},
331 {R367TER_DEBG_LT15, 0x00},
332 {R367TER_DEBG_LT16, 0x00},
333 {R367TER_DEBG_LT17, 0x00},
334 {R367TER_DEBG_LT18, 0x00},
335 {R367TER_DEBG_LT19, 0x00},
336 {R367TER_DEBG_LT1A, 0x00},
337 {R367TER_DEBG_LT1B, 0x00},
338 {R367TER_DEBG_LT1C, 0x00},
339 {R367TER_DEBG_LT1D, 0x00},
340 {R367TER_DEBG_LT1E, 0x00},
341 {R367TER_DEBG_LT1F, 0x00},
342 {R367TER_RCCFGH, 0x00},
343 {R367TER_RCCFGM, 0x00},
344 {R367TER_RCCFGL, 0x00},
345 {R367TER_RCINSDELH, 0x00},
346 {R367TER_RCINSDELM, 0x00},
347 {R367TER_RCINSDELL, 0x00},
348 {R367TER_RCSTATUS, 0x00},
349 {R367TER_RCSPEED, 0x6f},
350 {R367TER_RCDEBUGM, 0xe7},
351 {R367TER_RCDEBUGL, 0x9b},
352 {R367TER_RCOBSCFG, 0x00},
353 {R367TER_RCOBSM, 0x00},
354 {R367TER_RCOBSL, 0x00},
355 {R367TER_RCFECSPY, 0x00},
356 {R367TER_RCFSPYCFG, 0x00},
357 {R367TER_RCFSPYDATA, 0x00},
358 {R367TER_RCFSPYOUT, 0x00},
359 {R367TER_RCFSTATUS, 0x00},
360 {R367TER_RCFGOODPACK, 0x00},
361 {R367TER_RCFPACKCNT, 0x00},
362 {R367TER_RCFSPYMISC, 0x00},
363 {R367TER_RCFBERCPT4, 0x00},
364 {R367TER_RCFBERCPT3, 0x00},
365 {R367TER_RCFBERCPT2, 0x00},
366 {R367TER_RCFBERCPT1, 0x00},
367 {R367TER_RCFBERCPT0, 0x00},
368 {R367TER_RCFBERERR2, 0x00},
369 {R367TER_RCFBERERR1, 0x00},
370 {R367TER_RCFBERERR0, 0x00},
371 {R367TER_RCFSTATESM, 0x00},
372 {R367TER_RCFSTATESL, 0x00},
373 {R367TER_RCFSPYBER, 0x00},
374 {R367TER_RCFSPYDISTM, 0x00},
375 {R367TER_RCFSPYDISTL, 0x00},
376 {R367TER_RCFSPYOBS7, 0x00},
377 {R367TER_RCFSPYOBS6, 0x00},
378 {R367TER_RCFSPYOBS5, 0x00},
379 {R367TER_RCFSPYOBS4, 0x00},
380 {R367TER_RCFSPYOBS3, 0x00},
381 {R367TER_RCFSPYOBS2, 0x00},
382 {R367TER_RCFSPYOBS1, 0x00},
383 {R367TER_RCFSPYOBS0, 0x00},
384 {R367TER_TSGENERAL, 0x00},
385 {R367TER_RC1SPEED, 0x6f},
386 {R367TER_TSGSTATUS, 0x18},
387 {R367TER_FECM, 0x01},
388 {R367TER_VTH12, 0xff},
389 {R367TER_VTH23, 0xa1},
390 {R367TER_VTH34, 0x64},
391 {R367TER_VTH56, 0x40},
392 {R367TER_VTH67, 0x00},
393 {R367TER_VTH78, 0x2c},
394 {R367TER_VITCURPUN, 0x12},
395 {R367TER_VERROR, 0x01},
396 {R367TER_PRVIT, 0x3f},
397 {R367TER_VAVSRVIT, 0x00},
398 {R367TER_VSTATUSVIT, 0xbd},
399 {R367TER_VTHINUSE, 0xa1},
400 {R367TER_KDIV12, 0x20},
401 {R367TER_KDIV23, 0x40},
402 {R367TER_KDIV34, 0x20},
403 {R367TER_KDIV56, 0x30},
404 {R367TER_KDIV67, 0x00},
405 {R367TER_KDIV78, 0x30},
406 {R367TER_SIGPOWER, 0x54},
407 {R367TER_DEMAPVIT, 0x40},
408 {R367TER_VITSCALE, 0x00},
409 {R367TER_FFEC1PRG, 0x00},
410 {R367TER_FVITCURPUN, 0x12},
411 {R367TER_FVERROR, 0x01},
412 {R367TER_FVSTATUSVIT, 0xbd},
413 {R367TER_DEBUG_LT1, 0x00},
414 {R367TER_DEBUG_LT2, 0x00},
415 {R367TER_DEBUG_LT3, 0x00},
416 {R367TER_TSTSFMET, 0x00},
417 {R367TER_SELOUT, 0x00},
418 {R367TER_TSYNC, 0x00},
419 {R367TER_TSTERR, 0x00},
420 {R367TER_TSFSYNC, 0x00},
421 {R367TER_TSTSFERR, 0x00},
422 {R367TER_TSTTSSF1, 0x01},
423 {R367TER_TSTTSSF2, 0x1f},
424 {R367TER_TSTTSSF3, 0x00},
425 {R367TER_TSTTS1, 0x00},
426 {R367TER_TSTTS2, 0x1f},
427 {R367TER_TSTTS3, 0x01},
428 {R367TER_TSTTS4, 0x00},
429 {R367TER_TSTTSRC, 0x00},
430 {R367TER_TSTTSRS, 0x00},
431 {R367TER_TSSTATEM, 0xb0},
432 {R367TER_TSSTATEL, 0x40},
433 {R367TER_TSCFGH, 0xC0},
434 {R367TER_TSCFGM, 0xc0},/* for xc5000; was 0x00 */
435 {R367TER_TSCFGL, 0x20},
436 {R367TER_TSSYNC, 0x00},
437 {R367TER_TSINSDELH, 0x00},
438 {R367TER_TSINSDELM, 0x00},
439 {R367TER_TSINSDELL, 0x00},
440 {R367TER_TSDIVN, 0x03},
441 {R367TER_TSDIVPM, 0x00},
442 {R367TER_TSDIVPL, 0x00},
443 {R367TER_TSDIVQM, 0x00},
444 {R367TER_TSDIVQL, 0x00},
445 {R367TER_TSDILSTKM, 0x00},
446 {R367TER_TSDILSTKL, 0x00},
447 {R367TER_TSSPEED, 0x40},/* for xc5000; was 0x6f */
448 {R367TER_TSSTATUS, 0x81},
449 {R367TER_TSSTATUS2, 0x6a},
450 {R367TER_TSBITRATEM, 0x0f},
451 {R367TER_TSBITRATEL, 0xc6},
452 {R367TER_TSPACKLENM, 0x00},
453 {R367TER_TSPACKLENL, 0xfc},
454 {R367TER_TSBLOCLENM, 0x0a},
455 {R367TER_TSBLOCLENL, 0x80},
456 {R367TER_TSDLYH, 0x90},
457 {R367TER_TSDLYM, 0x68},
458 {R367TER_TSDLYL, 0x01},
459 {R367TER_TSNPDAV, 0x00},
460 {R367TER_TSBUFSTATH, 0x00},
461 {R367TER_TSBUFSTATM, 0x00},
462 {R367TER_TSBUFSTATL, 0x00},
463 {R367TER_TSDEBUGM, 0xcf},
464 {R367TER_TSDEBUGL, 0x1e},
465 {R367TER_TSDLYSETH, 0x00},
466 {R367TER_TSDLYSETM, 0x68},
467 {R367TER_TSDLYSETL, 0x00},
468 {R367TER_TSOBSCFG, 0x00},
469 {R367TER_TSOBSM, 0x47},
470 {R367TER_TSOBSL, 0x1f},
471 {R367TER_ERRCTRL1, 0x95},
472 {R367TER_ERRCNT1H, 0x80},
473 {R367TER_ERRCNT1M, 0x00},
474 {R367TER_ERRCNT1L, 0x00},
475 {R367TER_ERRCTRL2, 0x95},
476 {R367TER_ERRCNT2H, 0x00},
477 {R367TER_ERRCNT2M, 0x00},
478 {R367TER_ERRCNT2L, 0x00},
479 {R367TER_FECSPY, 0x88},
480 {R367TER_FSPYCFG, 0x2c},
481 {R367TER_FSPYDATA, 0x3a},
482 {R367TER_FSPYOUT, 0x06},
483 {R367TER_FSTATUS, 0x61},
484 {R367TER_FGOODPACK, 0xff},
485 {R367TER_FPACKCNT, 0xff},
486 {R367TER_FSPYMISC, 0x66},
487 {R367TER_FBERCPT4, 0x00},
488 {R367TER_FBERCPT3, 0x00},
489 {R367TER_FBERCPT2, 0x36},
490 {R367TER_FBERCPT1, 0x36},
491 {R367TER_FBERCPT0, 0x14},
492 {R367TER_FBERERR2, 0x00},
493 {R367TER_FBERERR1, 0x03},
494 {R367TER_FBERERR0, 0x28},
495 {R367TER_FSTATESM, 0x00},
496 {R367TER_FSTATESL, 0x02},
497 {R367TER_FSPYBER, 0x00},
498 {R367TER_FSPYDISTM, 0x01},
499 {R367TER_FSPYDISTL, 0x9f},
500 {R367TER_FSPYOBS7, 0xc9},
501 {R367TER_FSPYOBS6, 0x99},
502 {R367TER_FSPYOBS5, 0x08},
503 {R367TER_FSPYOBS4, 0xec},
504 {R367TER_FSPYOBS3, 0x01},
505 {R367TER_FSPYOBS2, 0x0f},
506 {R367TER_FSPYOBS1, 0xf5},
507 {R367TER_FSPYOBS0, 0x08},
508 {R367TER_SFDEMAP, 0x40},
509 {R367TER_SFERROR, 0x00},
510 {R367TER_SFAVSR, 0x30},
511 {R367TER_SFECSTATUS, 0xcc},
512 {R367TER_SFKDIV12, 0x20},
513 {R367TER_SFKDIV23, 0x40},
514 {R367TER_SFKDIV34, 0x20},
515 {R367TER_SFKDIV56, 0x20},
516 {R367TER_SFKDIV67, 0x00},
517 {R367TER_SFKDIV78, 0x20},
518 {R367TER_SFDILSTKM, 0x00},
519 {R367TER_SFDILSTKL, 0x00},
520 {R367TER_SFSTATUS, 0xb5},
521 {R367TER_SFDLYH, 0x90},
522 {R367TER_SFDLYM, 0x60},
523 {R367TER_SFDLYL, 0x01},
524 {R367TER_SFDLYSETH, 0xc0},
525 {R367TER_SFDLYSETM, 0x60},
526 {R367TER_SFDLYSETL, 0x00},
527 {R367TER_SFOBSCFG, 0x00},
528 {R367TER_SFOBSM, 0x47},
529 {R367TER_SFOBSL, 0x05},
530 {R367TER_SFECINFO, 0x40},
531 {R367TER_SFERRCTRL, 0x74},
532 {R367TER_SFERRCNTH, 0x80},
533 {R367TER_SFERRCNTM , 0x00},
534 {R367TER_SFERRCNTL, 0x00},
535 {R367TER_SYMBRATEM, 0x2f},
536 {R367TER_SYMBRATEL, 0x50},
537 {R367TER_SYMBSTATUS, 0x7f},
538 {R367TER_SYMBCFG, 0x00},
539 {R367TER_SYMBFIFOM, 0xf4},
540 {R367TER_SYMBFIFOL, 0x0d},
541 {R367TER_SYMBOFFSM, 0xf0},
542 {R367TER_SYMBOFFSL, 0x2d},
543 {R367TER_DEBUG_LT4, 0x00},
544 {R367TER_DEBUG_LT5, 0x00},
545 {R367TER_DEBUG_LT6, 0x00},
546 {R367TER_DEBUG_LT7, 0x00},
547 {R367TER_DEBUG_LT8, 0x00},
548 {R367TER_DEBUG_LT9, 0x00},
549};
550
551#define RF_LOOKUP_TABLE_SIZE 31
552#define RF_LOOKUP_TABLE2_SIZE 16
553/* RF Level (for RF AGC->AGC1) Lookup Table, depends on the board and tuner.*/
554s32 stv0367cab_RF_LookUp1[RF_LOOKUP_TABLE_SIZE][RF_LOOKUP_TABLE_SIZE] = {
555 {/*AGC1*/
556 48, 50, 51, 53, 54, 56, 57, 58, 60, 61, 62, 63,
557 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
558 76, 77, 78, 80, 83, 85, 88,
559 }, {/*RF(dbm)*/
560 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
561 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 46, 47,
562 49, 50, 52, 53, 54, 55, 56,
563 }
564};
565/* RF Level (for IF AGC->AGC2) Lookup Table, depends on the board and tuner.*/
566s32 stv0367cab_RF_LookUp2[RF_LOOKUP_TABLE2_SIZE][RF_LOOKUP_TABLE2_SIZE] = {
567 {/*AGC2*/
568 28, 29, 31, 32, 34, 35, 36, 37,
569 38, 39, 40, 41, 42, 43, 44, 45,
570 }, {/*RF(dbm)*/
571 57, 58, 59, 60, 61, 62, 63, 64,
572 65, 66, 67, 68, 69, 70, 71, 72,
573 }
574};
575
576static struct st_register def0367cab[STV0367CAB_NBREGS] = {
577 {R367CAB_ID, 0x60},
578 {R367CAB_I2CRPT, 0xa0},
579 /*{R367CAB_I2CRPT, 0x22},*/
580 {R367CAB_TOPCTRL, 0x10},
581 {R367CAB_IOCFG0, 0x80},
582 {R367CAB_DAC0R, 0x00},
583 {R367CAB_IOCFG1, 0x00},
584 {R367CAB_DAC1R, 0x00},
585 {R367CAB_IOCFG2, 0x00},
586 {R367CAB_SDFR, 0x00},
587 {R367CAB_AUX_CLK, 0x00},
588 {R367CAB_FREESYS1, 0x00},
589 {R367CAB_FREESYS2, 0x00},
590 {R367CAB_FREESYS3, 0x00},
591 {R367CAB_GPIO_CFG, 0x55},
592 {R367CAB_GPIO_CMD, 0x01},
593 {R367CAB_TSTRES, 0x00},
594 {R367CAB_ANACTRL, 0x0d},/* was 0x00 need to check - I.M.L.*/
595 {R367CAB_TSTBUS, 0x00},
596 {R367CAB_RF_AGC1, 0xea},
597 {R367CAB_RF_AGC2, 0x82},
598 {R367CAB_ANADIGCTRL, 0x0b},
599 {R367CAB_PLLMDIV, 0x01},
600 {R367CAB_PLLNDIV, 0x08},
601 {R367CAB_PLLSETUP, 0x18},
602 {R367CAB_DUAL_AD12, 0x0C}, /* for xc5000 AGC voltage 1.6V */
603 {R367CAB_TSTBIST, 0x00},
604 {R367CAB_CTRL_1, 0x00},
605 {R367CAB_CTRL_2, 0x03},
606 {R367CAB_IT_STATUS1, 0x2b},
607 {R367CAB_IT_STATUS2, 0x08},
608 {R367CAB_IT_EN1, 0x00},
609 {R367CAB_IT_EN2, 0x00},
610 {R367CAB_CTRL_STATUS, 0x04},
611 {R367CAB_TEST_CTL, 0x00},
612 {R367CAB_AGC_CTL, 0x73},
613 {R367CAB_AGC_IF_CFG, 0x50},
614 {R367CAB_AGC_RF_CFG, 0x00},
615 {R367CAB_AGC_PWM_CFG, 0x03},
616 {R367CAB_AGC_PWR_REF_L, 0x5a},
617 {R367CAB_AGC_PWR_REF_H, 0x00},
618 {R367CAB_AGC_RF_TH_L, 0xff},
619 {R367CAB_AGC_RF_TH_H, 0x07},
620 {R367CAB_AGC_IF_LTH_L, 0x00},
621 {R367CAB_AGC_IF_LTH_H, 0x08},
622 {R367CAB_AGC_IF_HTH_L, 0xff},
623 {R367CAB_AGC_IF_HTH_H, 0x07},
624 {R367CAB_AGC_PWR_RD_L, 0xa0},
625 {R367CAB_AGC_PWR_RD_M, 0xe9},
626 {R367CAB_AGC_PWR_RD_H, 0x03},
627 {R367CAB_AGC_PWM_IFCMD_L, 0xe4},
628 {R367CAB_AGC_PWM_IFCMD_H, 0x00},
629 {R367CAB_AGC_PWM_RFCMD_L, 0xff},
630 {R367CAB_AGC_PWM_RFCMD_H, 0x07},
631 {R367CAB_IQDEM_CFG, 0x01},
632 {R367CAB_MIX_NCO_LL, 0x22},
633 {R367CAB_MIX_NCO_HL, 0x96},
634 {R367CAB_MIX_NCO_HH, 0x55},
635 {R367CAB_SRC_NCO_LL, 0xff},
636 {R367CAB_SRC_NCO_LH, 0x0c},
637 {R367CAB_SRC_NCO_HL, 0xf5},
638 {R367CAB_SRC_NCO_HH, 0x20},
639 {R367CAB_IQDEM_GAIN_SRC_L, 0x06},
640 {R367CAB_IQDEM_GAIN_SRC_H, 0x01},
641 {R367CAB_IQDEM_DCRM_CFG_LL, 0xfe},
642 {R367CAB_IQDEM_DCRM_CFG_LH, 0xff},
643 {R367CAB_IQDEM_DCRM_CFG_HL, 0x0f},
644 {R367CAB_IQDEM_DCRM_CFG_HH, 0x00},
645 {R367CAB_IQDEM_ADJ_COEFF0, 0x34},
646 {R367CAB_IQDEM_ADJ_COEFF1, 0xae},
647 {R367CAB_IQDEM_ADJ_COEFF2, 0x46},
648 {R367CAB_IQDEM_ADJ_COEFF3, 0x77},
649 {R367CAB_IQDEM_ADJ_COEFF4, 0x96},
650 {R367CAB_IQDEM_ADJ_COEFF5, 0x69},
651 {R367CAB_IQDEM_ADJ_COEFF6, 0xc7},
652 {R367CAB_IQDEM_ADJ_COEFF7, 0x01},
653 {R367CAB_IQDEM_ADJ_EN, 0x04},
654 {R367CAB_IQDEM_ADJ_AGC_REF, 0x94},
655 {R367CAB_ALLPASSFILT1, 0xc9},
656 {R367CAB_ALLPASSFILT2, 0x2d},
657 {R367CAB_ALLPASSFILT3, 0xa3},
658 {R367CAB_ALLPASSFILT4, 0xfb},
659 {R367CAB_ALLPASSFILT5, 0xf6},
660 {R367CAB_ALLPASSFILT6, 0x45},
661 {R367CAB_ALLPASSFILT7, 0x6f},
662 {R367CAB_ALLPASSFILT8, 0x7e},
663 {R367CAB_ALLPASSFILT9, 0x05},
664 {R367CAB_ALLPASSFILT10, 0x0a},
665 {R367CAB_ALLPASSFILT11, 0x51},
666 {R367CAB_TRL_AGC_CFG, 0x20},
667 {R367CAB_TRL_LPF_CFG, 0x28},
668 {R367CAB_TRL_LPF_ACQ_GAIN, 0x44},
669 {R367CAB_TRL_LPF_TRK_GAIN, 0x22},
670 {R367CAB_TRL_LPF_OUT_GAIN, 0x03},
671 {R367CAB_TRL_LOCKDET_LTH, 0x04},
672 {R367CAB_TRL_LOCKDET_HTH, 0x11},
673 {R367CAB_TRL_LOCKDET_TRGVAL, 0x20},
674 {R367CAB_IQ_QAM, 0x01},
675 {R367CAB_FSM_STATE, 0xa0},
676 {R367CAB_FSM_CTL, 0x08},
677 {R367CAB_FSM_STS, 0x0c},
678 {R367CAB_FSM_SNR0_HTH, 0x00},
679 {R367CAB_FSM_SNR1_HTH, 0x00},
680 {R367CAB_FSM_SNR2_HTH, 0x23},/* 0x00 */
681 {R367CAB_FSM_SNR0_LTH, 0x00},
682 {R367CAB_FSM_SNR1_LTH, 0x00},
683 {R367CAB_FSM_EQA1_HTH, 0x00},
684 {R367CAB_FSM_TEMPO, 0x32},
685 {R367CAB_FSM_CONFIG, 0x03},
686 {R367CAB_EQU_I_TESTTAP_L, 0x11},
687 {R367CAB_EQU_I_TESTTAP_M, 0x00},
688 {R367CAB_EQU_I_TESTTAP_H, 0x00},
689 {R367CAB_EQU_TESTAP_CFG, 0x00},
690 {R367CAB_EQU_Q_TESTTAP_L, 0xff},
691 {R367CAB_EQU_Q_TESTTAP_M, 0x00},
692 {R367CAB_EQU_Q_TESTTAP_H, 0x00},
693 {R367CAB_EQU_TAP_CTRL, 0x00},
694 {R367CAB_EQU_CTR_CRL_CONTROL_L, 0x11},
695 {R367CAB_EQU_CTR_CRL_CONTROL_H, 0x05},
696 {R367CAB_EQU_CTR_HIPOW_L, 0x00},
697 {R367CAB_EQU_CTR_HIPOW_H, 0x00},
698 {R367CAB_EQU_I_EQU_LO, 0xef},
699 {R367CAB_EQU_I_EQU_HI, 0x00},
700 {R367CAB_EQU_Q_EQU_LO, 0xee},
701 {R367CAB_EQU_Q_EQU_HI, 0x00},
702 {R367CAB_EQU_MAPPER, 0xc5},
703 {R367CAB_EQU_SWEEP_RATE, 0x80},
704 {R367CAB_EQU_SNR_LO, 0x64},
705 {R367CAB_EQU_SNR_HI, 0x03},
706 {R367CAB_EQU_GAMMA_LO, 0x00},
707 {R367CAB_EQU_GAMMA_HI, 0x00},
708 {R367CAB_EQU_ERR_GAIN, 0x36},
709 {R367CAB_EQU_RADIUS, 0xaa},
710 {R367CAB_EQU_FFE_MAINTAP, 0x00},
711 {R367CAB_EQU_FFE_LEAKAGE, 0x63},
712 {R367CAB_EQU_FFE_MAINTAP_POS, 0xdf},
713 {R367CAB_EQU_GAIN_WIDE, 0x88},
714 {R367CAB_EQU_GAIN_NARROW, 0x41},
715 {R367CAB_EQU_CTR_LPF_GAIN, 0xd1},
716 {R367CAB_EQU_CRL_LPF_GAIN, 0xa7},
717 {R367CAB_EQU_GLOBAL_GAIN, 0x06},
718 {R367CAB_EQU_CRL_LD_SEN, 0x85},
719 {R367CAB_EQU_CRL_LD_VAL, 0xe2},
720 {R367CAB_EQU_CRL_TFR, 0x20},
721 {R367CAB_EQU_CRL_BISTH_LO, 0x00},
722 {R367CAB_EQU_CRL_BISTH_HI, 0x00},
723 {R367CAB_EQU_SWEEP_RANGE_LO, 0x00},
724 {R367CAB_EQU_SWEEP_RANGE_HI, 0x00},
725 {R367CAB_EQU_CRL_LIMITER, 0x40},
726 {R367CAB_EQU_MODULUS_MAP, 0x90},
727 {R367CAB_EQU_PNT_GAIN, 0xa7},
728 {R367CAB_FEC_AC_CTR_0, 0x16},
729 {R367CAB_FEC_AC_CTR_1, 0x0b},
730 {R367CAB_FEC_AC_CTR_2, 0x88},
731 {R367CAB_FEC_AC_CTR_3, 0x02},
732 {R367CAB_FEC_STATUS, 0x12},
733 {R367CAB_RS_COUNTER_0, 0x7d},
734 {R367CAB_RS_COUNTER_1, 0xd0},
735 {R367CAB_RS_COUNTER_2, 0x19},
736 {R367CAB_RS_COUNTER_3, 0x0b},
737 {R367CAB_RS_COUNTER_4, 0xa3},
738 {R367CAB_RS_COUNTER_5, 0x00},
739 {R367CAB_BERT_0, 0x01},
740 {R367CAB_BERT_1, 0x25},
741 {R367CAB_BERT_2, 0x41},
742 {R367CAB_BERT_3, 0x39},
743 {R367CAB_OUTFORMAT_0, 0xc2},
744 {R367CAB_OUTFORMAT_1, 0x22},
745 {R367CAB_SMOOTHER_2, 0x28},
746 {R367CAB_TSMF_CTRL_0, 0x01},
747 {R367CAB_TSMF_CTRL_1, 0xc6},
748 {R367CAB_TSMF_CTRL_3, 0x43},
749 {R367CAB_TS_ON_ID_0, 0x00},
750 {R367CAB_TS_ON_ID_1, 0x00},
751 {R367CAB_TS_ON_ID_2, 0x00},
752 {R367CAB_TS_ON_ID_3, 0x00},
753 {R367CAB_RE_STATUS_0, 0x00},
754 {R367CAB_RE_STATUS_1, 0x00},
755 {R367CAB_RE_STATUS_2, 0x00},
756 {R367CAB_RE_STATUS_3, 0x00},
757 {R367CAB_TS_STATUS_0, 0x00},
758 {R367CAB_TS_STATUS_1, 0x00},
759 {R367CAB_TS_STATUS_2, 0xa0},
760 {R367CAB_TS_STATUS_3, 0x00},
761 {R367CAB_T_O_ID_0, 0x00},
762 {R367CAB_T_O_ID_1, 0x00},
763 {R367CAB_T_O_ID_2, 0x00},
764 {R367CAB_T_O_ID_3, 0x00},
765};
766
767static
768int stv0367_writeregs(struct stv0367_state *state, u16 reg, u8 *data, int len)
769{
770 u8 buf[len + 2];
771 struct i2c_msg msg = {
772 .addr = state->config->demod_address,
773 .flags = 0,
774 .buf = buf,
775 .len = len + 2
776 };
777 int ret;
778
779 buf[0] = MSB(reg);
780 buf[1] = LSB(reg);
781 memcpy(buf + 2, data, len);
782
783 if (i2cdebug)
784 printk(KERN_DEBUG "%s: %02x: %02x\n", __func__, reg, buf[2]);
785
786 ret = i2c_transfer(state->i2c, &msg, 1);
787 if (ret != 1)
788 printk(KERN_ERR "%s: i2c write error!\n", __func__);
789
790 return (ret != 1) ? -EREMOTEIO : 0;
791}
792
793static int stv0367_writereg(struct stv0367_state *state, u16 reg, u8 data)
794{
795 return stv0367_writeregs(state, reg, &data, 1);
796}
797
798static u8 stv0367_readreg(struct stv0367_state *state, u16 reg)
799{
800 u8 b0[] = { 0, 0 };
801 u8 b1[] = { 0 };
802 struct i2c_msg msg[] = {
803 {
804 .addr = state->config->demod_address,
805 .flags = 0,
806 .buf = b0,
807 .len = 2
808 }, {
809 .addr = state->config->demod_address,
810 .flags = I2C_M_RD,
811 .buf = b1,
812 .len = 1
813 }
814 };
815 int ret;
816
817 b0[0] = MSB(reg);
818 b0[1] = LSB(reg);
819
820 ret = i2c_transfer(state->i2c, msg, 2);
821 if (ret != 2)
822 printk(KERN_ERR "%s: i2c read error\n", __func__);
823
824 if (i2cdebug)
825 printk(KERN_DEBUG "%s: %02x: %02x\n", __func__, reg, b1[0]);
826
827 return b1[0];
828}
829
830static void extract_mask_pos(u32 label, u8 *mask, u8 *pos)
831{
832 u8 position = 0, i = 0;
833
834 (*mask) = label & 0xff;
835
836 while ((position == 0) && (i < 8)) {
837 position = ((*mask) >> i) & 0x01;
838 i++;
839 }
840
841 (*pos) = (i - 1);
842}
843
844static void stv0367_writebits(struct stv0367_state *state, u32 label, u8 val)
845{
846 u8 reg, mask, pos;
847
848 reg = stv0367_readreg(state, (label >> 16) & 0xffff);
849 extract_mask_pos(label, &mask, &pos);
850
851 val = mask & (val << pos);
852
853 reg = (reg & (~mask)) | val;
854 stv0367_writereg(state, (label >> 16) & 0xffff, reg);
855
856}
857
858static void stv0367_setbits(u8 *reg, u32 label, u8 val)
859{
860 u8 mask, pos;
861
862 extract_mask_pos(label, &mask, &pos);
863
864 val = mask & (val << pos);
865
866 (*reg) = ((*reg) & (~mask)) | val;
867}
868
869static u8 stv0367_readbits(struct stv0367_state *state, u32 label)
870{
871 u8 val = 0xff;
872 u8 mask, pos;
873
874 extract_mask_pos(label, &mask, &pos);
875
876 val = stv0367_readreg(state, label >> 16);
877 val = (val & mask) >> pos;
878
879 return val;
880}
881
882u8 stv0367_getbits(u8 reg, u32 label)
883{
884 u8 mask, pos;
885
886 extract_mask_pos(label, &mask, &pos);
887
888 return (reg & mask) >> pos;
889}
890
891static int stv0367ter_gate_ctrl(struct dvb_frontend *fe, int enable)
892{
893 struct stv0367_state *state = fe->demodulator_priv;
894 u8 tmp = stv0367_readreg(state, R367TER_I2CRPT);
895
896 dprintk("%s:\n", __func__);
897
898 if (enable) {
899 stv0367_setbits(&tmp, F367TER_STOP_ENABLE, 0);
900 stv0367_setbits(&tmp, F367TER_I2CT_ON, 1);
901 } else {
902 stv0367_setbits(&tmp, F367TER_STOP_ENABLE, 1);
903 stv0367_setbits(&tmp, F367TER_I2CT_ON, 0);
904 }
905
906 stv0367_writereg(state, R367TER_I2CRPT, tmp);
907
908 return 0;
909}
910
911static u32 stv0367_get_tuner_freq(struct dvb_frontend *fe)
912{
913 struct dvb_frontend_ops *frontend_ops = NULL;
914 struct dvb_tuner_ops *tuner_ops = NULL;
915 u32 freq = 0;
916 int err = 0;
917
918 dprintk("%s:\n", __func__);
919
920
921 if (&fe->ops)
922 frontend_ops = &fe->ops;
923 if (&frontend_ops->tuner_ops)
924 tuner_ops = &frontend_ops->tuner_ops;
925 if (tuner_ops->get_frequency) {
926 err = tuner_ops->get_frequency(fe, &freq);
927 if (err < 0) {
928 printk(KERN_ERR "%s: Invalid parameter\n", __func__);
929 return err;
930 }
931
932 dprintk("%s: frequency=%d\n", __func__, freq);
933
934 } else
935 return -1;
936
937 return freq;
938}
939
940static u16 CellsCoeffs_8MHz_367cofdm[3][6][5] = {
941 {
942 {0x10EF, 0xE205, 0x10EF, 0xCE49, 0x6DA7}, /* CELL 1 COEFFS 27M*/
943 {0x2151, 0xc557, 0x2151, 0xc705, 0x6f93}, /* CELL 2 COEFFS */
944 {0x2503, 0xc000, 0x2503, 0xc375, 0x7194}, /* CELL 3 COEFFS */
945 {0x20E9, 0xca94, 0x20e9, 0xc153, 0x7194}, /* CELL 4 COEFFS */
946 {0x06EF, 0xF852, 0x06EF, 0xC057, 0x7207}, /* CELL 5 COEFFS */
947 {0x0000, 0x0ECC, 0x0ECC, 0x0000, 0x3647} /* CELL 6 COEFFS */
948 }, {
949 {0x10A0, 0xE2AF, 0x10A1, 0xCE76, 0x6D6D}, /* CELL 1 COEFFS 25M*/
950 {0x20DC, 0xC676, 0x20D9, 0xC80A, 0x6F29},
951 {0x2532, 0xC000, 0x251D, 0xC391, 0x706F},
952 {0x1F7A, 0xCD2B, 0x2032, 0xC15E, 0x711F},
953 {0x0698, 0xFA5E, 0x0568, 0xC059, 0x7193},
954 {0x0000, 0x0918, 0x149C, 0x0000, 0x3642} /* CELL 6 COEFFS */
955 }, {
956 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000}, /* 30M */
957 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
958 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
959 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
960 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
961 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000}
962 }
963};
964
965static u16 CellsCoeffs_7MHz_367cofdm[3][6][5] = {
966 {
967 {0x12CA, 0xDDAF, 0x12CA, 0xCCEB, 0x6FB1}, /* CELL 1 COEFFS 27M*/
968 {0x2329, 0xC000, 0x2329, 0xC6B0, 0x725F}, /* CELL 2 COEFFS */
969 {0x2394, 0xC000, 0x2394, 0xC2C7, 0x7410}, /* CELL 3 COEFFS */
970 {0x251C, 0xC000, 0x251C, 0xC103, 0x74D9}, /* CELL 4 COEFFS */
971 {0x0804, 0xF546, 0x0804, 0xC040, 0x7544}, /* CELL 5 COEFFS */
972 {0x0000, 0x0CD9, 0x0CD9, 0x0000, 0x370A} /* CELL 6 COEFFS */
973 }, {
974 {0x1285, 0xDE47, 0x1285, 0xCD17, 0x6F76}, /*25M*/
975 {0x234C, 0xC000, 0x2348, 0xC6DA, 0x7206},
976 {0x23B4, 0xC000, 0x23AC, 0xC2DB, 0x73B3},
977 {0x253D, 0xC000, 0x25B6, 0xC10B, 0x747F},
978 {0x0721, 0xF79C, 0x065F, 0xC041, 0x74EB},
979 {0x0000, 0x08FA, 0x1162, 0x0000, 0x36FF}
980 }, {
981 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000}, /* 30M */
982 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
983 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
984 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
985 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
986 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000}
987 }
988};
989
990static u16 CellsCoeffs_6MHz_367cofdm[3][6][5] = {
991 {
992 {0x1699, 0xD5B8, 0x1699, 0xCBC3, 0x713B}, /* CELL 1 COEFFS 27M*/
993 {0x2245, 0xC000, 0x2245, 0xC568, 0x74D5}, /* CELL 2 COEFFS */
994 {0x227F, 0xC000, 0x227F, 0xC1FC, 0x76C6}, /* CELL 3 COEFFS */
995 {0x235E, 0xC000, 0x235E, 0xC0A7, 0x778A}, /* CELL 4 COEFFS */
996 {0x0ECB, 0xEA0B, 0x0ECB, 0xC027, 0x77DD}, /* CELL 5 COEFFS */
997 {0x0000, 0x0B68, 0x0B68, 0x0000, 0xC89A}, /* CELL 6 COEFFS */
998 }, {
999 {0x1655, 0xD64E, 0x1658, 0xCBEF, 0x70FE}, /*25M*/
1000 {0x225E, 0xC000, 0x2256, 0xC589, 0x7489},
1001 {0x2293, 0xC000, 0x2295, 0xC209, 0x767E},
1002 {0x2377, 0xC000, 0x23AA, 0xC0AB, 0x7746},
1003 {0x0DC7, 0xEBC8, 0x0D07, 0xC027, 0x7799},
1004 {0x0000, 0x0888, 0x0E9C, 0x0000, 0x3757}
1005
1006 }, {
1007 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000}, /* 30M */
1008 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
1009 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
1010 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
1011 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000},
1012 {0x0000, 0x0000, 0x0000, 0x0000, 0x0000}
1013 }
1014};
1015
1016static u32 stv0367ter_get_mclk(struct stv0367_state *state, u32 ExtClk_Hz)
1017{
1018 u32 mclk_Hz = 0; /* master clock frequency (Hz) */
1019 u32 m, n, p;
1020
1021 dprintk("%s:\n", __func__);
1022
1023 if (stv0367_readbits(state, F367TER_BYPASS_PLLXN) == 0) {
1024 n = (u32)stv0367_readbits(state, F367TER_PLL_NDIV);
1025 if (n == 0)
1026 n = n + 1;
1027
1028 m = (u32)stv0367_readbits(state, F367TER_PLL_MDIV);
1029 if (m == 0)
1030 m = m + 1;
1031
1032 p = (u32)stv0367_readbits(state, F367TER_PLL_PDIV);
1033 if (p > 5)
1034 p = 5;
1035
1036 mclk_Hz = ((ExtClk_Hz / 2) * n) / (m * (1 << p));
1037
1038 dprintk("N=%d M=%d P=%d mclk_Hz=%d ExtClk_Hz=%d\n",
1039 n, m, p, mclk_Hz, ExtClk_Hz);
1040 } else
1041 mclk_Hz = ExtClk_Hz;
1042
1043 dprintk("%s: mclk_Hz=%d\n", __func__, mclk_Hz);
1044
1045 return mclk_Hz;
1046}
1047
1048static int stv0367ter_filt_coeff_init(struct stv0367_state *state,
1049 u16 CellsCoeffs[3][6][5], u32 DemodXtal)
1050{
1051 int i, j, k, freq;
1052
1053 dprintk("%s:\n", __func__);
1054
1055 freq = stv0367ter_get_mclk(state, DemodXtal);
1056
1057 if (freq == 53125000)
1058 k = 1; /* equivalent to Xtal 25M on 362*/
1059 else if (freq == 54000000)
1060 k = 0; /* equivalent to Xtal 27M on 362*/
1061 else if (freq == 52500000)
1062 k = 2; /* equivalent to Xtal 30M on 362*/
1063 else
1064 return 0;
1065
1066 for (i = 1; i <= 6; i++) {
1067 stv0367_writebits(state, F367TER_IIR_CELL_NB, i - 1);
1068
1069 for (j = 1; j <= 5; j++) {
1070 stv0367_writereg(state,
1071 (R367TER_IIRCX_COEFF1_MSB + 2 * (j - 1)),
1072 MSB(CellsCoeffs[k][i-1][j-1]));
1073 stv0367_writereg(state,
1074 (R367TER_IIRCX_COEFF1_LSB + 2 * (j - 1)),
1075 LSB(CellsCoeffs[k][i-1][j-1]));
1076 }
1077 }
1078
1079 return 1;
1080
1081}
1082
1083static void stv0367ter_agc_iir_lock_detect_set(struct stv0367_state *state)
1084{
1085 dprintk("%s:\n", __func__);
1086
1087 stv0367_writebits(state, F367TER_LOCK_DETECT_LSB, 0x00);
1088
1089 /* Lock detect 1 */
1090 stv0367_writebits(state, F367TER_LOCK_DETECT_CHOICE, 0x00);
1091 stv0367_writebits(state, F367TER_LOCK_DETECT_MSB, 0x06);
1092 stv0367_writebits(state, F367TER_AUT_AGC_TARGET_LSB, 0x04);
1093
1094 /* Lock detect 2 */
1095 stv0367_writebits(state, F367TER_LOCK_DETECT_CHOICE, 0x01);
1096 stv0367_writebits(state, F367TER_LOCK_DETECT_MSB, 0x06);
1097 stv0367_writebits(state, F367TER_AUT_AGC_TARGET_LSB, 0x04);
1098
1099 /* Lock detect 3 */
1100 stv0367_writebits(state, F367TER_LOCK_DETECT_CHOICE, 0x02);
1101 stv0367_writebits(state, F367TER_LOCK_DETECT_MSB, 0x01);
1102 stv0367_writebits(state, F367TER_AUT_AGC_TARGET_LSB, 0x00);
1103
1104 /* Lock detect 4 */
1105 stv0367_writebits(state, F367TER_LOCK_DETECT_CHOICE, 0x03);
1106 stv0367_writebits(state, F367TER_LOCK_DETECT_MSB, 0x01);
1107 stv0367_writebits(state, F367TER_AUT_AGC_TARGET_LSB, 0x00);
1108
1109}
1110
1111static int stv0367_iir_filt_init(struct stv0367_state *state, u8 Bandwidth,
1112 u32 DemodXtalValue)
1113{
1114 dprintk("%s:\n", __func__);
1115
1116 stv0367_writebits(state, F367TER_NRST_IIR, 0);
1117
1118 switch (Bandwidth) {
1119 case 6:
1120 if (!stv0367ter_filt_coeff_init(state,
1121 CellsCoeffs_6MHz_367cofdm,
1122 DemodXtalValue))
1123 return 0;
1124 break;
1125 case 7:
1126 if (!stv0367ter_filt_coeff_init(state,
1127 CellsCoeffs_7MHz_367cofdm,
1128 DemodXtalValue))
1129 return 0;
1130 break;
1131 case 8:
1132 if (!stv0367ter_filt_coeff_init(state,
1133 CellsCoeffs_8MHz_367cofdm,
1134 DemodXtalValue))
1135 return 0;
1136 break;
1137 default:
1138 return 0;
1139 }
1140
1141 stv0367_writebits(state, F367TER_NRST_IIR, 1);
1142
1143 return 1;
1144}
1145
1146static void stv0367ter_agc_iir_rst(struct stv0367_state *state)
1147{
1148
1149 u8 com_n;
1150
1151 dprintk("%s:\n", __func__);
1152
1153 com_n = stv0367_readbits(state, F367TER_COM_N);
1154
1155 stv0367_writebits(state, F367TER_COM_N, 0x07);
1156
1157 stv0367_writebits(state, F367TER_COM_SOFT_RSTN, 0x00);
1158 stv0367_writebits(state, F367TER_COM_AGC_ON, 0x00);
1159
1160 stv0367_writebits(state, F367TER_COM_SOFT_RSTN, 0x01);
1161 stv0367_writebits(state, F367TER_COM_AGC_ON, 0x01);
1162
1163 stv0367_writebits(state, F367TER_COM_N, com_n);
1164
1165}
1166
1167static int stv0367ter_duration(s32 mode, int tempo1, int tempo2, int tempo3)
1168{
1169 int local_tempo = 0;
1170 switch (mode) {
1171 case 0:
1172 local_tempo = tempo1;
1173 break;
1174 case 1:
1175 local_tempo = tempo2;
1176 break ;
1177
1178 case 2:
1179 local_tempo = tempo3;
1180 break;
1181
1182 default:
1183 break;
1184 }
1185 /* msleep(local_tempo); */
1186 return local_tempo;
1187}
1188
1189static enum
1190stv0367_ter_signal_type stv0367ter_check_syr(struct stv0367_state *state)
1191{
1192 int wd = 100;
1193 unsigned short int SYR_var;
1194 s32 SYRStatus;
1195
1196 dprintk("%s:\n", __func__);
1197
1198 SYR_var = stv0367_readbits(state, F367TER_SYR_LOCK);
1199
1200 while ((!SYR_var) && (wd > 0)) {
1201 usleep_range(2000, 3000);
1202 wd -= 2;
1203 SYR_var = stv0367_readbits(state, F367TER_SYR_LOCK);
1204 }
1205
1206 if (!SYR_var)
1207 SYRStatus = FE_TER_NOSYMBOL;
1208 else
1209 SYRStatus = FE_TER_SYMBOLOK;
1210
1211 dprintk("stv0367ter_check_syr SYRStatus %s\n",
1212 SYR_var == 0 ? "No Symbol" : "OK");
1213
1214 return SYRStatus;
1215}
1216
1217static enum
1218stv0367_ter_signal_type stv0367ter_check_cpamp(struct stv0367_state *state,
1219 s32 FFTmode)
1220{
1221
1222 s32 CPAMPvalue = 0, CPAMPStatus, CPAMPMin;
1223 int wd = 0;
1224
1225 dprintk("%s:\n", __func__);
1226
1227 switch (FFTmode) {
1228 case 0: /*2k mode*/
1229 CPAMPMin = 20;
1230 wd = 10;
1231 break;
1232 case 1: /*8k mode*/
1233 CPAMPMin = 80;
1234 wd = 55;
1235 break;
1236 case 2: /*4k mode*/
1237 CPAMPMin = 40;
1238 wd = 30;
1239 break;
1240 default:
1241 CPAMPMin = 0xffff; /*drives to NOCPAMP */
1242 break;
1243 }
1244
1245 dprintk("%s: CPAMPMin=%d wd=%d\n", __func__, CPAMPMin, wd);
1246
1247 CPAMPvalue = stv0367_readbits(state, F367TER_PPM_CPAMP_DIRECT);
1248 while ((CPAMPvalue < CPAMPMin) && (wd > 0)) {
1249 usleep_range(1000, 2000);
1250 wd -= 1;
1251 CPAMPvalue = stv0367_readbits(state, F367TER_PPM_CPAMP_DIRECT);
1252 /*dprintk("CPAMPvalue= %d at wd=%d\n",CPAMPvalue,wd); */
1253 }
1254 dprintk("******last CPAMPvalue= %d at wd=%d\n", CPAMPvalue, wd);
1255 if (CPAMPvalue < CPAMPMin) {
1256 CPAMPStatus = FE_TER_NOCPAMP;
1257 printk(KERN_ERR "CPAMP failed\n");
1258 } else {
1259 printk(KERN_ERR "CPAMP OK !\n");
1260 CPAMPStatus = FE_TER_CPAMPOK;
1261 }
1262
1263 return CPAMPStatus;
1264}
1265
1266enum
1267stv0367_ter_signal_type stv0367ter_lock_algo(struct stv0367_state *state)
1268{
1269 enum stv0367_ter_signal_type ret_flag;
1270 short int wd, tempo;
1271 u8 try, u_var1 = 0, u_var2 = 0, u_var3 = 0, u_var4 = 0, mode, guard;
1272 u8 tmp, tmp2;
1273
1274 dprintk("%s:\n", __func__);
1275
1276 if (state == NULL)
1277 return FE_TER_SWNOK;
1278
1279 try = 0;
1280 do {
1281 ret_flag = FE_TER_LOCKOK;
1282
1283 stv0367_writebits(state, F367TER_CORE_ACTIVE, 0);
1284
1285 if (state->config->if_iq_mode != 0)
1286 stv0367_writebits(state, F367TER_COM_N, 0x07);
1287
1288 stv0367_writebits(state, F367TER_GUARD, 3);/* suggest 2k 1/4 */
1289 stv0367_writebits(state, F367TER_MODE, 0);
1290 stv0367_writebits(state, F367TER_SYR_TR_DIS, 0);
1291 usleep_range(5000, 10000);
1292
1293 stv0367_writebits(state, F367TER_CORE_ACTIVE, 1);
1294
1295
1296 if (stv0367ter_check_syr(state) == FE_TER_NOSYMBOL)
1297 return FE_TER_NOSYMBOL;
1298 else { /*
1299 if chip locked on wrong mode first try,
1300 it must lock correctly second try */
1301 mode = stv0367_readbits(state, F367TER_SYR_MODE);
1302 if (stv0367ter_check_cpamp(state, mode) ==
1303 FE_TER_NOCPAMP) {
1304 if (try == 0)
1305 ret_flag = FE_TER_NOCPAMP;
1306
1307 }
1308 }
1309
1310 try++;
1311 } while ((try < 10) && (ret_flag != FE_TER_LOCKOK));
1312
1313 tmp = stv0367_readreg(state, R367TER_SYR_STAT);
1314 tmp2 = stv0367_readreg(state, R367TER_STATUS);
1315 dprintk("state=%p\n", state);
1316 dprintk("LOCK OK! mode=%d SYR_STAT=0x%x R367TER_STATUS=0x%x\n",
1317 mode, tmp, tmp2);
1318
1319 tmp = stv0367_readreg(state, R367TER_PRVIT);
1320 tmp2 = stv0367_readreg(state, R367TER_I2CRPT);
1321 dprintk("PRVIT=0x%x I2CRPT=0x%x\n", tmp, tmp2);
1322
1323 tmp = stv0367_readreg(state, R367TER_GAIN_SRC1);
1324 dprintk("GAIN_SRC1=0x%x\n", tmp);
1325
1326 if ((mode != 0) && (mode != 1) && (mode != 2))
1327 return FE_TER_SWNOK;
1328
1329 /*guard=stv0367_readbits(state,F367TER_SYR_GUARD); */
1330
1331 /*suppress EPQ auto for SYR_GARD 1/16 or 1/32
1332 and set channel predictor in automatic */
1333#if 0
1334 switch (guard) {
1335
1336 case 0:
1337 case 1:
1338 stv0367_writebits(state, F367TER_AUTO_LE_EN, 0);
1339 stv0367_writereg(state, R367TER_CHC_CTL, 0x01);
1340 break;
1341 case 2:
1342 case 3:
1343 stv0367_writebits(state, F367TER_AUTO_LE_EN, 1);
1344 stv0367_writereg(state, R367TER_CHC_CTL, 0x11);
1345 break;
1346
1347 default:
1348 return FE_TER_SWNOK;
1349 }
1350#endif
1351
1352 /*reset fec an reedsolo FOR 367 only*/
1353 stv0367_writebits(state, F367TER_RST_SFEC, 1);
1354 stv0367_writebits(state, F367TER_RST_REEDSOLO, 1);
1355 usleep_range(1000, 2000);
1356 stv0367_writebits(state, F367TER_RST_SFEC, 0);
1357 stv0367_writebits(state, F367TER_RST_REEDSOLO, 0);
1358
1359 u_var1 = stv0367_readbits(state, F367TER_LK);
1360 u_var2 = stv0367_readbits(state, F367TER_PRF);
1361 u_var3 = stv0367_readbits(state, F367TER_TPS_LOCK);
1362 /* u_var4=stv0367_readbits(state,F367TER_TSFIFO_LINEOK); */
1363
1364 wd = stv0367ter_duration(mode, 125, 500, 250);
1365 tempo = stv0367ter_duration(mode, 4, 16, 8);
1366
1367 /*while ( ((!u_var1)||(!u_var2)||(!u_var3)||(!u_var4)) && (wd>=0)) */
1368 while (((!u_var1) || (!u_var2) || (!u_var3)) && (wd >= 0)) {
1369 usleep_range(1000 * tempo, 1000 * (tempo + 1));
1370 wd -= tempo;
1371 u_var1 = stv0367_readbits(state, F367TER_LK);
1372 u_var2 = stv0367_readbits(state, F367TER_PRF);
1373 u_var3 = stv0367_readbits(state, F367TER_TPS_LOCK);
1374 /*u_var4=stv0367_readbits(state, F367TER_TSFIFO_LINEOK); */
1375 }
1376
1377 if (!u_var1)
1378 return FE_TER_NOLOCK;
1379
1380
1381 if (!u_var2)
1382 return FE_TER_NOPRFOUND;
1383
1384 if (!u_var3)
1385 return FE_TER_NOTPS;
1386
1387 guard = stv0367_readbits(state, F367TER_SYR_GUARD);
1388 stv0367_writereg(state, R367TER_CHC_CTL, 0x11);
1389 switch (guard) {
1390 case 0:
1391 case 1:
1392 stv0367_writebits(state, F367TER_AUTO_LE_EN, 0);
1393 /*stv0367_writereg(state,R367TER_CHC_CTL, 0x1);*/
1394 stv0367_writebits(state, F367TER_SYR_FILTER, 0);
1395 break;
1396 case 2:
1397 case 3:
1398 stv0367_writebits(state, F367TER_AUTO_LE_EN, 1);
1399 /*stv0367_writereg(state,R367TER_CHC_CTL, 0x11);*/
1400 stv0367_writebits(state, F367TER_SYR_FILTER, 1);
1401 break;
1402
1403 default:
1404 return FE_TER_SWNOK;
1405 }
1406
1407 /* apply Sfec workaround if 8K 64QAM CR!=1/2*/
1408 if ((stv0367_readbits(state, F367TER_TPS_CONST) == 2) &&
1409 (mode == 1) &&
1410 (stv0367_readbits(state, F367TER_TPS_HPCODE) != 0)) {
1411 stv0367_writereg(state, R367TER_SFDLYSETH, 0xc0);
1412 stv0367_writereg(state, R367TER_SFDLYSETM, 0x60);
1413 stv0367_writereg(state, R367TER_SFDLYSETL, 0x0);
1414 } else
1415 stv0367_writereg(state, R367TER_SFDLYSETH, 0x0);
1416
1417 wd = stv0367ter_duration(mode, 125, 500, 250);
1418 u_var4 = stv0367_readbits(state, F367TER_TSFIFO_LINEOK);
1419
1420 while ((!u_var4) && (wd >= 0)) {
1421 usleep_range(1000 * tempo, 1000 * (tempo + 1));
1422 wd -= tempo;
1423 u_var4 = stv0367_readbits(state, F367TER_TSFIFO_LINEOK);
1424 }
1425
1426 if (!u_var4)
1427 return FE_TER_NOLOCK;
1428
1429 /* for 367 leave COM_N at 0x7 for IQ_mode*/
1430 /*if(ter_state->if_iq_mode!=FE_TER_NORMAL_IF_TUNER) {
1431 tempo=0;
1432 while ((stv0367_readbits(state,F367TER_COM_USEGAINTRK)!=1) &&
1433 (stv0367_readbits(state,F367TER_COM_AGCLOCK)!=1)&&(tempo<100)) {
1434 ChipWaitOrAbort(state,1);
1435 tempo+=1;
1436 }
1437
1438 stv0367_writebits(state,F367TER_COM_N,0x17);
1439 } */
1440
1441 stv0367_writebits(state, F367TER_SYR_TR_DIS, 1);
1442
1443 dprintk("FE_TER_LOCKOK !!!\n");
1444
1445 return FE_TER_LOCKOK;
1446
1447}
1448
1449static void stv0367ter_set_ts_mode(struct stv0367_state *state,
1450 enum stv0367_ts_mode PathTS)
1451{
1452
1453 dprintk("%s:\n", __func__);
1454
1455 if (state == NULL)
1456 return;
1457
1458 stv0367_writebits(state, F367TER_TS_DIS, 0);
1459 switch (PathTS) {
1460 default:
1461 /*for removing warning :default we can assume in parallel mode*/
1462 case STV0367_PARALLEL_PUNCT_CLOCK:
1463 stv0367_writebits(state, F367TER_TSFIFO_SERIAL, 0);
1464 stv0367_writebits(state, F367TER_TSFIFO_DVBCI, 0);
1465 break;
1466 case STV0367_SERIAL_PUNCT_CLOCK:
1467 stv0367_writebits(state, F367TER_TSFIFO_SERIAL, 1);
1468 stv0367_writebits(state, F367TER_TSFIFO_DVBCI, 1);
1469 break;
1470 }
1471}
1472
1473static void stv0367ter_set_clk_pol(struct stv0367_state *state,
1474 enum stv0367_clk_pol clock)
1475{
1476
1477 dprintk("%s:\n", __func__);
1478
1479 if (state == NULL)
1480 return;
1481
1482 switch (clock) {
1483 case STV0367_RISINGEDGE_CLOCK:
1484 stv0367_writebits(state, F367TER_TS_BYTE_CLK_INV, 1);
1485 break;
1486 case STV0367_FALLINGEDGE_CLOCK:
1487 stv0367_writebits(state, F367TER_TS_BYTE_CLK_INV, 0);
1488 break;
1489 /*case FE_TER_CLOCK_POLARITY_DEFAULT:*/
1490 default:
1491 stv0367_writebits(state, F367TER_TS_BYTE_CLK_INV, 0);
1492 break;
1493 }
1494}
1495
1496#if 0
1497static void stv0367ter_core_sw(struct stv0367_state *state)
1498{
1499
1500 dprintk("%s:\n", __func__);
1501
1502 stv0367_writebits(state, F367TER_CORE_ACTIVE, 0);
1503 stv0367_writebits(state, F367TER_CORE_ACTIVE, 1);
1504 msleep(350);
1505}
1506#endif
1507static int stv0367ter_standby(struct dvb_frontend *fe, u8 standby_on)
1508{
1509 struct stv0367_state *state = fe->demodulator_priv;
1510
1511 dprintk("%s:\n", __func__);
1512
1513 if (standby_on) {
1514 stv0367_writebits(state, F367TER_STDBY, 1);
1515 stv0367_writebits(state, F367TER_STDBY_FEC, 1);
1516 stv0367_writebits(state, F367TER_STDBY_CORE, 1);
1517 } else {
1518 stv0367_writebits(state, F367TER_STDBY, 0);
1519 stv0367_writebits(state, F367TER_STDBY_FEC, 0);
1520 stv0367_writebits(state, F367TER_STDBY_CORE, 0);
1521 }
1522
1523 return 0;
1524}
1525
1526static int stv0367ter_sleep(struct dvb_frontend *fe)
1527{
1528 return stv0367ter_standby(fe, 1);
1529}
1530
1531int stv0367ter_init(struct dvb_frontend *fe)
1532{
1533 struct stv0367_state *state = fe->demodulator_priv;
1534 struct stv0367ter_state *ter_state = state->ter_state;
1535 int i;
1536
1537 dprintk("%s:\n", __func__);
1538
1539 ter_state->pBER = 0;
1540
1541 for (i = 0; i < STV0367TER_NBREGS; i++)
1542 stv0367_writereg(state, def0367ter[i].addr,
1543 def0367ter[i].value);
1544
1545 switch (state->config->xtal) {
1546 /*set internal freq to 53.125MHz */
1547 case 25000000:
1548 stv0367_writereg(state, R367TER_PLLMDIV, 0xa);
1549 stv0367_writereg(state, R367TER_PLLNDIV, 0x55);
1550 stv0367_writereg(state, R367TER_PLLSETUP, 0x18);
1551 break;
1552 default:
1553 case 27000000:
1554 dprintk("FE_STV0367TER_SetCLKgen for 27Mhz\n");
1555 stv0367_writereg(state, R367TER_PLLMDIV, 0x1);
1556 stv0367_writereg(state, R367TER_PLLNDIV, 0x8);
1557 stv0367_writereg(state, R367TER_PLLSETUP, 0x18);
1558 break;
1559 case 30000000:
1560 stv0367_writereg(state, R367TER_PLLMDIV, 0xc);
1561 stv0367_writereg(state, R367TER_PLLNDIV, 0x55);
1562 stv0367_writereg(state, R367TER_PLLSETUP, 0x18);
1563 break;
1564 }
1565
1566 stv0367_writereg(state, R367TER_I2CRPT, 0xa0);
1567 stv0367_writereg(state, R367TER_ANACTRL, 0x00);
1568
1569 /*Set TS1 and TS2 to serial or parallel mode */
1570 stv0367ter_set_ts_mode(state, state->config->ts_mode);
1571 stv0367ter_set_clk_pol(state, state->config->clk_pol);
1572
1573 state->chip_id = stv0367_readreg(state, R367TER_ID);
1574 ter_state->first_lock = 0;
1575 ter_state->unlock_counter = 2;
1576
1577 return 0;
1578}
1579
1580static int stv0367ter_algo(struct dvb_frontend *fe,
1581 struct dvb_frontend_parameters *param)
1582{
1583 struct stv0367_state *state = fe->demodulator_priv;
1584 struct stv0367ter_state *ter_state = state->ter_state;
1585 int offset = 0, tempo = 0;
1586 u8 u_var;
1587 u8 /*constell,*/ counter, tps_rcvd[2];
1588 s8 step;
1589 s32 timing_offset = 0;
1590 u32 trl_nomrate = 0, InternalFreq = 0, temp = 0;
1591
1592 dprintk("%s:\n", __func__);
1593
1594 ter_state->frequency = param->frequency;
1595 ter_state->force = FE_TER_FORCENONE
1596 + stv0367_readbits(state, F367TER_FORCE) * 2;
1597 ter_state->if_iq_mode = state->config->if_iq_mode;
1598 switch (state->config->if_iq_mode) {
1599 case FE_TER_NORMAL_IF_TUNER: /* Normal IF mode */
1600 dprintk("ALGO: FE_TER_NORMAL_IF_TUNER selected\n");
1601 stv0367_writebits(state, F367TER_TUNER_BB, 0);
1602 stv0367_writebits(state, F367TER_LONGPATH_IF, 0);
1603 stv0367_writebits(state, F367TER_DEMUX_SWAP, 0);
1604 break;
1605 case FE_TER_LONGPATH_IF_TUNER: /* Long IF mode */
1606 dprintk("ALGO: FE_TER_LONGPATH_IF_TUNER selected\n");
1607 stv0367_writebits(state, F367TER_TUNER_BB, 0);
1608 stv0367_writebits(state, F367TER_LONGPATH_IF, 1);
1609 stv0367_writebits(state, F367TER_DEMUX_SWAP, 1);
1610 break;
1611 case FE_TER_IQ_TUNER: /* IQ mode */
1612 dprintk("ALGO: FE_TER_IQ_TUNER selected\n");
1613 stv0367_writebits(state, F367TER_TUNER_BB, 1);
1614 stv0367_writebits(state, F367TER_PPM_INVSEL, 0);
1615 break;
1616 default:
1617 printk(KERN_ERR "ALGO: wrong TUNER type selected\n");
1618 return -EINVAL;
1619 }
1620
1621 usleep_range(5000, 7000);
1622
1623 switch (param->inversion) {
1624 case INVERSION_AUTO:
1625 default:
1626 dprintk("%s: inversion AUTO\n", __func__);
1627 if (ter_state->if_iq_mode == FE_TER_IQ_TUNER)
1628 stv0367_writebits(state, F367TER_IQ_INVERT,
1629 ter_state->sense);
1630 else
1631 stv0367_writebits(state, F367TER_INV_SPECTR,
1632 ter_state->sense);
1633
1634 break;
1635 case INVERSION_ON:
1636 case INVERSION_OFF:
1637 if (ter_state->if_iq_mode == FE_TER_IQ_TUNER)
1638 stv0367_writebits(state, F367TER_IQ_INVERT,
1639 param->inversion);
1640 else
1641 stv0367_writebits(state, F367TER_INV_SPECTR,
1642 param->inversion);
1643
1644 break;
1645 }
1646
1647 if ((ter_state->if_iq_mode != FE_TER_NORMAL_IF_TUNER) &&
1648 (ter_state->pBW != ter_state->bw)) {
1649 stv0367ter_agc_iir_lock_detect_set(state);
1650
1651 /*set fine agc target to 180 for LPIF or IQ mode*/
1652 /* set Q_AGCTarget */
1653 stv0367_writebits(state, F367TER_SEL_IQNTAR, 1);
1654 stv0367_writebits(state, F367TER_AUT_AGC_TARGET_MSB, 0xB);
1655 /*stv0367_writebits(state,AUT_AGC_TARGET_LSB,0x04); */
1656
1657 /* set Q_AGCTarget */
1658 stv0367_writebits(state, F367TER_SEL_IQNTAR, 0);
1659 stv0367_writebits(state, F367TER_AUT_AGC_TARGET_MSB, 0xB);
1660 /*stv0367_writebits(state,AUT_AGC_TARGET_LSB,0x04); */
1661
1662 if (!stv0367_iir_filt_init(state, ter_state->bw,
1663 state->config->xtal))
1664 return -EINVAL;
1665 /*set IIR filter once for 6,7 or 8MHz BW*/
1666 ter_state->pBW = ter_state->bw;
1667
1668 stv0367ter_agc_iir_rst(state);
1669 }
1670
1671 if (ter_state->hierarchy == FE_TER_HIER_LOW_PRIO)
1672 stv0367_writebits(state, F367TER_BDI_LPSEL, 0x01);
1673 else
1674 stv0367_writebits(state, F367TER_BDI_LPSEL, 0x00);
1675
1676 InternalFreq = stv0367ter_get_mclk(state, state->config->xtal) / 1000;
1677 temp = (int)
1678 ((((ter_state->bw * 64 * (1 << 15) * 100)
1679 / (InternalFreq)) * 10) / 7);
1680
1681 stv0367_writebits(state, F367TER_TRL_NOMRATE_LSB, temp % 2);
1682 temp = temp / 2;
1683 stv0367_writebits(state, F367TER_TRL_NOMRATE_HI, temp / 256);
1684 stv0367_writebits(state, F367TER_TRL_NOMRATE_LO, temp % 256);
1685
1686 temp = stv0367_readbits(state, F367TER_TRL_NOMRATE_HI) * 512 +
1687 stv0367_readbits(state, F367TER_TRL_NOMRATE_LO) * 2 +
1688 stv0367_readbits(state, F367TER_TRL_NOMRATE_LSB);
1689 temp = (int)(((1 << 17) * ter_state->bw * 1000) / (7 * (InternalFreq)));
1690 stv0367_writebits(state, F367TER_GAIN_SRC_HI, temp / 256);
1691 stv0367_writebits(state, F367TER_GAIN_SRC_LO, temp % 256);
1692 temp = stv0367_readbits(state, F367TER_GAIN_SRC_HI) * 256 +
1693 stv0367_readbits(state, F367TER_GAIN_SRC_LO);
1694
1695 temp = (int)
1696 ((InternalFreq - state->config->if_khz) * (1 << 16)
1697 / (InternalFreq));
1698
1699 dprintk("DEROT temp=0x%x\n", temp);
1700 stv0367_writebits(state, F367TER_INC_DEROT_HI, temp / 256);
1701 stv0367_writebits(state, F367TER_INC_DEROT_LO, temp % 256);
1702
1703 ter_state->echo_pos = 0;
1704 ter_state->ucblocks = 0; /* liplianin */
1705 ter_state->pBER = 0; /* liplianin */
1706 stv0367_writebits(state, F367TER_LONG_ECHO, ter_state->echo_pos);
1707
1708 if (stv0367ter_lock_algo(state) != FE_TER_LOCKOK)
1709 return 0;
1710
1711 ter_state->state = FE_TER_LOCKOK;
1712 /* update results */
1713 tps_rcvd[0] = stv0367_readreg(state, R367TER_TPS_RCVD2);
1714 tps_rcvd[1] = stv0367_readreg(state, R367TER_TPS_RCVD3);
1715
1716 ter_state->mode = stv0367_readbits(state, F367TER_SYR_MODE);
1717 ter_state->guard = stv0367_readbits(state, F367TER_SYR_GUARD);
1718
1719 ter_state->first_lock = 1; /* we know sense now :) */
1720
1721 ter_state->agc_val =
1722 (stv0367_readbits(state, F367TER_AGC1_VAL_LO) << 16) +
1723 (stv0367_readbits(state, F367TER_AGC1_VAL_HI) << 24) +
1724 stv0367_readbits(state, F367TER_AGC2_VAL_LO) +
1725 (stv0367_readbits(state, F367TER_AGC2_VAL_HI) << 8);
1726
1727 /* Carrier offset calculation */
1728 stv0367_writebits(state, F367TER_FREEZE, 1);
1729 offset = (stv0367_readbits(state, F367TER_CRL_FOFFSET_VHI) << 16) ;
1730 offset += (stv0367_readbits(state, F367TER_CRL_FOFFSET_HI) << 8);
1731 offset += (stv0367_readbits(state, F367TER_CRL_FOFFSET_LO));
1732 stv0367_writebits(state, F367TER_FREEZE, 0);
1733 if (offset > 8388607)
1734 offset -= 16777216;
1735
1736 offset = offset * 2 / 16384;
1737
1738 if (ter_state->mode == FE_TER_MODE_2K)
1739 offset = (offset * 4464) / 1000;/*** 1 FFT BIN=4.464khz***/
1740 else if (ter_state->mode == FE_TER_MODE_4K)
1741 offset = (offset * 223) / 100;/*** 1 FFT BIN=2.23khz***/
1742 else if (ter_state->mode == FE_TER_MODE_8K)
1743 offset = (offset * 111) / 100;/*** 1 FFT BIN=1.1khz***/
1744
1745 if (stv0367_readbits(state, F367TER_PPM_INVSEL) == 1) {
1746 if ((stv0367_readbits(state, F367TER_INV_SPECTR) ==
1747 (stv0367_readbits(state,
1748 F367TER_STATUS_INV_SPECRUM) == 1)))
1749 offset = offset * -1;
1750 }
1751
1752 if (ter_state->bw == 6)
1753 offset = (offset * 6) / 8;
1754 else if (ter_state->bw == 7)
1755 offset = (offset * 7) / 8;
1756
1757 ter_state->frequency += offset;
1758
1759 tempo = 10; /* exit even if timing_offset stays null */
1760 while ((timing_offset == 0) && (tempo > 0)) {
1761 usleep_range(10000, 20000); /*was 20ms */
1762 /* fine tuning of timing offset if required */
1763 timing_offset = stv0367_readbits(state, F367TER_TRL_TOFFSET_LO)
1764 + 256 * stv0367_readbits(state,
1765 F367TER_TRL_TOFFSET_HI);
1766 if (timing_offset >= 32768)
1767 timing_offset -= 65536;
1768 trl_nomrate = (512 * stv0367_readbits(state,
1769 F367TER_TRL_NOMRATE_HI)
1770 + stv0367_readbits(state, F367TER_TRL_NOMRATE_LO) * 2
1771 + stv0367_readbits(state, F367TER_TRL_NOMRATE_LSB));
1772
1773 timing_offset = ((signed)(1000000 / trl_nomrate) *
1774 timing_offset) / 2048;
1775 tempo--;
1776 }
1777
1778 if (timing_offset <= 0) {
1779 timing_offset = (timing_offset - 11) / 22;
1780 step = -1;
1781 } else {
1782 timing_offset = (timing_offset + 11) / 22;
1783 step = 1;
1784 }
1785
1786 for (counter = 0; counter < abs(timing_offset); counter++) {
1787 trl_nomrate += step;
1788 stv0367_writebits(state, F367TER_TRL_NOMRATE_LSB,
1789 trl_nomrate % 2);
1790 stv0367_writebits(state, F367TER_TRL_NOMRATE_LO,
1791 trl_nomrate / 2);
1792 usleep_range(1000, 2000);
1793 }
1794
1795 usleep_range(5000, 6000);
1796 /* unlocks could happen in case of trl centring big step,
1797 then a core off/on restarts demod */
1798 u_var = stv0367_readbits(state, F367TER_LK);
1799
1800 if (!u_var) {
1801 stv0367_writebits(state, F367TER_CORE_ACTIVE, 0);
1802 msleep(20);
1803 stv0367_writebits(state, F367TER_CORE_ACTIVE, 1);
1804 }
1805
1806 return 0;
1807}
1808
1809static int stv0367ter_set_frontend(struct dvb_frontend *fe,
1810 struct dvb_frontend_parameters *param)
1811{
1812 struct dvb_ofdm_parameters *op = &param->u.ofdm;
1813 struct stv0367_state *state = fe->demodulator_priv;
1814 struct stv0367ter_state *ter_state = state->ter_state;
1815
1816 /*u8 trials[2]; */
1817 s8 num_trials, index;
1818 u8 SenseTrials[] = { INVERSION_ON, INVERSION_OFF };
1819
1820 stv0367ter_init(fe);
1821
1822 if (fe->ops.tuner_ops.set_params) {
1823 if (fe->ops.i2c_gate_ctrl)
1824 fe->ops.i2c_gate_ctrl(fe, 1);
1825 fe->ops.tuner_ops.set_params(fe, param);
1826 if (fe->ops.i2c_gate_ctrl)
1827 fe->ops.i2c_gate_ctrl(fe, 0);
1828 }
1829
1830 switch (op->transmission_mode) {
1831 default:
1832 case TRANSMISSION_MODE_AUTO:
1833 case TRANSMISSION_MODE_2K:
1834 ter_state->mode = FE_TER_MODE_2K;
1835 break;
1836/* case TRANSMISSION_MODE_4K:
1837 pLook.mode = FE_TER_MODE_4K;
1838 break;*/
1839 case TRANSMISSION_MODE_8K:
1840 ter_state->mode = FE_TER_MODE_8K;
1841 break;
1842 }
1843
1844 switch (op->guard_interval) {
1845 default:
1846 case GUARD_INTERVAL_1_32:
1847 case GUARD_INTERVAL_1_16:
1848 case GUARD_INTERVAL_1_8:
1849 case GUARD_INTERVAL_1_4:
1850 ter_state->guard = op->guard_interval;
1851 break;
1852 case GUARD_INTERVAL_AUTO:
1853 ter_state->guard = GUARD_INTERVAL_1_32;
1854 break;
1855 }
1856
1857 switch (op->bandwidth) {
1858 case BANDWIDTH_6_MHZ:
1859 ter_state->bw = FE_TER_CHAN_BW_6M;
1860 break;
1861 case BANDWIDTH_7_MHZ:
1862 ter_state->bw = FE_TER_CHAN_BW_7M;
1863 break;
1864 case BANDWIDTH_8_MHZ:
1865 default:
1866 ter_state->bw = FE_TER_CHAN_BW_8M;
1867 }
1868
1869 ter_state->hierarchy = FE_TER_HIER_NONE;
1870
1871 switch (param->inversion) {
1872 case INVERSION_OFF:
1873 case INVERSION_ON:
1874 num_trials = 1;
1875 break;
1876 default:
1877 num_trials = 2;
1878 if (ter_state->first_lock)
1879 num_trials = 1;
1880 break;
1881 }
1882
1883 ter_state->state = FE_TER_NOLOCK;
1884 index = 0;
1885
1886 while (((index) < num_trials) && (ter_state->state != FE_TER_LOCKOK)) {
1887 if (!ter_state->first_lock) {
1888 if (param->inversion == INVERSION_AUTO)
1889 ter_state->sense = SenseTrials[index];
1890
1891 }
1892 stv0367ter_algo(fe,/* &pLook, result,*/ param);
1893
1894 if ((ter_state->state == FE_TER_LOCKOK) &&
1895 (param->inversion == INVERSION_AUTO) &&
1896 (index == 1)) {
1897 /* invert spectrum sense */
1898 SenseTrials[index] = SenseTrials[0];
1899 SenseTrials[(index + 1) % 2] = (SenseTrials[1] + 1) % 2;
1900 }
1901
1902 index++;
1903 }
1904
1905 return 0;
1906}
1907
1908static int stv0367ter_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
1909{
1910 struct stv0367_state *state = fe->demodulator_priv;
1911 struct stv0367ter_state *ter_state = state->ter_state;
1912 u32 errs = 0;
1913
1914 /*wait for counting completion*/
1915 if (stv0367_readbits(state, F367TER_SFERRC_OLDVALUE) == 0) {
1916 errs =
1917 ((u32)stv0367_readbits(state, F367TER_ERR_CNT1)
1918 * (1 << 16))
1919 + ((u32)stv0367_readbits(state, F367TER_ERR_CNT1_HI)
1920 * (1 << 8))
1921 + ((u32)stv0367_readbits(state, F367TER_ERR_CNT1_LO));
1922 ter_state->ucblocks = errs;
1923 }
1924
1925 (*ucblocks) = ter_state->ucblocks;
1926
1927 return 0;
1928}
1929
1930static int stv0367ter_get_frontend(struct dvb_frontend *fe,
1931 struct dvb_frontend_parameters *param)
1932{
1933 struct stv0367_state *state = fe->demodulator_priv;
1934 struct stv0367ter_state *ter_state = state->ter_state;
1935 struct dvb_ofdm_parameters *op = &param->u.ofdm;
1936 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1937
1938 int error = 0;
1939 enum stv0367_ter_mode mode;
1940 int constell = 0,/* snr = 0,*/ Data = 0;
1941
1942 param->frequency = stv0367_get_tuner_freq(fe);
1943 if ((int)param->frequency < 0)
1944 param->frequency = c->frequency;
1945
1946 constell = stv0367_readbits(state, F367TER_TPS_CONST);
1947 if (constell == 0)
1948 op->constellation = QPSK;
1949 else if (constell == 1)
1950 op->constellation = QAM_16;
1951 else
1952 op->constellation = QAM_64;
1953
1954 param->inversion = stv0367_readbits(state, F367TER_INV_SPECTR);
1955
1956 /* Get the Hierarchical mode */
1957 Data = stv0367_readbits(state, F367TER_TPS_HIERMODE);
1958
1959 switch (Data) {
1960 case 0:
1961 op->hierarchy_information = HIERARCHY_NONE;
1962 break;
1963 case 1:
1964 op->hierarchy_information = HIERARCHY_1;
1965 break;
1966 case 2:
1967 op->hierarchy_information = HIERARCHY_2;
1968 break;
1969 case 3:
1970 op->hierarchy_information = HIERARCHY_4;
1971 break;
1972 default:
1973 op->hierarchy_information = HIERARCHY_AUTO;
1974 break; /* error */
1975 }
1976
1977 /* Get the FEC Rate */
1978 if (ter_state->hierarchy == FE_TER_HIER_LOW_PRIO)
1979 Data = stv0367_readbits(state, F367TER_TPS_LPCODE);
1980 else
1981 Data = stv0367_readbits(state, F367TER_TPS_HPCODE);
1982
1983 switch (Data) {
1984 case 0:
1985 op->code_rate_HP = FEC_1_2;
1986 break;
1987 case 1:
1988 op->code_rate_HP = FEC_2_3;
1989 break;
1990 case 2:
1991 op->code_rate_HP = FEC_3_4;
1992 break;
1993 case 3:
1994 op->code_rate_HP = FEC_5_6;
1995 break;
1996 case 4:
1997 op->code_rate_HP = FEC_7_8;
1998 break;
1999 default:
2000 op->code_rate_HP = FEC_AUTO;
2001 break; /* error */
2002 }
2003
2004 mode = stv0367_readbits(state, F367TER_SYR_MODE);
2005
2006 switch (mode) {
2007 case FE_TER_MODE_2K:
2008 op->transmission_mode = TRANSMISSION_MODE_2K;
2009 break;
2010/* case FE_TER_MODE_4K:
2011 op->transmission_mode = TRANSMISSION_MODE_4K;
2012 break;*/
2013 case FE_TER_MODE_8K:
2014 op->transmission_mode = TRANSMISSION_MODE_8K;
2015 break;
2016 default:
2017 op->transmission_mode = TRANSMISSION_MODE_AUTO;
2018 }
2019
2020 op->guard_interval = stv0367_readbits(state, F367TER_SYR_GUARD);
2021
2022 return error;
2023}
2024
2025static int stv0367ter_read_snr(struct dvb_frontend *fe, u16 *snr)
2026{
2027 struct stv0367_state *state = fe->demodulator_priv;
2028 u32 snru32 = 0;
2029 int cpt = 0;
2030 u8 cut = stv0367_readbits(state, F367TER_IDENTIFICATIONREG);
2031
2032 while (cpt < 10) {
2033 usleep_range(2000, 3000);
2034 if (cut == 0x50) /*cut 1.0 cut 1.1*/
2035 snru32 += stv0367_readbits(state, F367TER_CHCSNR) / 4;
2036 else /*cu2.0*/
2037 snru32 += 125 * stv0367_readbits(state, F367TER_CHCSNR);
2038
2039 cpt++;
2040 }
2041
2042 snru32 /= 10;/*average on 10 values*/
2043
2044 *snr = snru32 / 1000;
2045
2046 return 0;
2047}
2048
2049#if 0
2050static int stv0367ter_status(struct dvb_frontend *fe)
2051{
2052
2053 struct stv0367_state *state = fe->demodulator_priv;
2054 struct stv0367ter_state *ter_state = state->ter_state;
2055 int locked = FALSE;
2056
2057 locked = (stv0367_readbits(state, F367TER_LK));
2058 if (!locked)
2059 ter_state->unlock_counter += 1;
2060 else
2061 ter_state->unlock_counter = 0;
2062
2063 if (ter_state->unlock_counter > 2) {
2064 if (!stv0367_readbits(state, F367TER_TPS_LOCK) ||
2065 (!stv0367_readbits(state, F367TER_LK))) {
2066 stv0367_writebits(state, F367TER_CORE_ACTIVE, 0);
2067 usleep_range(2000, 3000);
2068 stv0367_writebits(state, F367TER_CORE_ACTIVE, 1);
2069 msleep(350);
2070 locked = (stv0367_readbits(state, F367TER_TPS_LOCK)) &&
2071 (stv0367_readbits(state, F367TER_LK));
2072 }
2073
2074 }
2075
2076 return locked;
2077}
2078#endif
2079static int stv0367ter_read_status(struct dvb_frontend *fe, fe_status_t *status)
2080{
2081 struct stv0367_state *state = fe->demodulator_priv;
2082
2083 dprintk("%s:\n", __func__);
2084
2085 *status = 0;
2086
2087 if (stv0367_readbits(state, F367TER_LK)) {
2088 *status |= FE_HAS_LOCK;
2089 dprintk("%s: stv0367 has locked\n", __func__);
2090 }
2091
2092 return 0;
2093}
2094
2095static int stv0367ter_read_ber(struct dvb_frontend *fe, u32 *ber)
2096{
2097 struct stv0367_state *state = fe->demodulator_priv;
2098 struct stv0367ter_state *ter_state = state->ter_state;
2099 u32 Errors = 0, tber = 0, temporary = 0;
2100 int abc = 0, def = 0;
2101
2102
2103 /*wait for counting completion*/
2104 if (stv0367_readbits(state, F367TER_SFERRC_OLDVALUE) == 0)
2105 Errors = ((u32)stv0367_readbits(state, F367TER_SFEC_ERR_CNT)
2106 * (1 << 16))
2107 + ((u32)stv0367_readbits(state, F367TER_SFEC_ERR_CNT_HI)
2108 * (1 << 8))
2109 + ((u32)stv0367_readbits(state,
2110 F367TER_SFEC_ERR_CNT_LO));
2111 /*measurement not completed, load previous value*/
2112 else {
2113 tber = ter_state->pBER;
2114 return 0;
2115 }
2116
2117 abc = stv0367_readbits(state, F367TER_SFEC_ERR_SOURCE);
2118 def = stv0367_readbits(state, F367TER_SFEC_NUM_EVENT);
2119
2120 if (Errors == 0) {
2121 tber = 0;
2122 } else if (abc == 0x7) {
2123 if (Errors <= 4) {
2124 temporary = (Errors * 1000000000) / (8 * (1 << 14));
2125 temporary = temporary;
2126 } else if (Errors <= 42) {
2127 temporary = (Errors * 100000000) / (8 * (1 << 14));
2128 temporary = temporary * 10;
2129 } else if (Errors <= 429) {
2130 temporary = (Errors * 10000000) / (8 * (1 << 14));
2131 temporary = temporary * 100;
2132 } else if (Errors <= 4294) {
2133 temporary = (Errors * 1000000) / (8 * (1 << 14));
2134 temporary = temporary * 1000;
2135 } else if (Errors <= 42949) {
2136 temporary = (Errors * 100000) / (8 * (1 << 14));
2137 temporary = temporary * 10000;
2138 } else if (Errors <= 429496) {
2139 temporary = (Errors * 10000) / (8 * (1 << 14));
2140 temporary = temporary * 100000;
2141 } else { /*if (Errors<4294967) 2^22 max error*/
2142 temporary = (Errors * 1000) / (8 * (1 << 14));
2143 temporary = temporary * 100000; /* still to *10 */
2144 }
2145
2146 /* Byte error*/
2147 if (def == 2)
2148 /*tber=Errors/(8*(1 <<14));*/
2149 tber = temporary;
2150 else if (def == 3)
2151 /*tber=Errors/(8*(1 <<16));*/
2152 tber = temporary / 4;
2153 else if (def == 4)
2154 /*tber=Errors/(8*(1 <<18));*/
2155 tber = temporary / 16;
2156 else if (def == 5)
2157 /*tber=Errors/(8*(1 <<20));*/
2158 tber = temporary / 64;
2159 else if (def == 6)
2160 /*tber=Errors/(8*(1 <<22));*/
2161 tber = temporary / 256;
2162 else
2163 /* should not pass here*/
2164 tber = 0;
2165
2166 if ((Errors < 4294967) && (Errors > 429496))
2167 tber *= 10;
2168
2169 }
2170
2171 /* save actual value */
2172 ter_state->pBER = tber;
2173
2174 (*ber) = tber;
2175
2176 return 0;
2177}
2178#if 0
2179static u32 stv0367ter_get_per(struct stv0367_state *state)
2180{
2181 struct stv0367ter_state *ter_state = state->ter_state;
2182 u32 Errors = 0, Per = 0, temporary = 0;
2183 int abc = 0, def = 0, cpt = 0;
2184
2185 while (((stv0367_readbits(state, F367TER_SFERRC_OLDVALUE) == 1) &&
2186 (cpt < 400)) || ((Errors == 0) && (cpt < 400))) {
2187 usleep_range(1000, 2000);
2188 Errors = ((u32)stv0367_readbits(state, F367TER_ERR_CNT1)
2189 * (1 << 16))
2190 + ((u32)stv0367_readbits(state, F367TER_ERR_CNT1_HI)
2191 * (1 << 8))
2192 + ((u32)stv0367_readbits(state, F367TER_ERR_CNT1_LO));
2193 cpt++;
2194 }
2195 abc = stv0367_readbits(state, F367TER_ERR_SRC1);
2196 def = stv0367_readbits(state, F367TER_NUM_EVT1);
2197
2198 if (Errors == 0)
2199 Per = 0;
2200 else if (abc == 0x9) {
2201 if (Errors <= 4) {
2202 temporary = (Errors * 1000000000) / (8 * (1 << 8));
2203 temporary = temporary;
2204 } else if (Errors <= 42) {
2205 temporary = (Errors * 100000000) / (8 * (1 << 8));
2206 temporary = temporary * 10;
2207 } else if (Errors <= 429) {
2208 temporary = (Errors * 10000000) / (8 * (1 << 8));
2209 temporary = temporary * 100;
2210 } else if (Errors <= 4294) {
2211 temporary = (Errors * 1000000) / (8 * (1 << 8));
2212 temporary = temporary * 1000;
2213 } else if (Errors <= 42949) {
2214 temporary = (Errors * 100000) / (8 * (1 << 8));
2215 temporary = temporary * 10000;
2216 } else { /*if(Errors<=429496) 2^16 errors max*/
2217 temporary = (Errors * 10000) / (8 * (1 << 8));
2218 temporary = temporary * 100000;
2219 }
2220
2221 /* pkt error*/
2222 if (def == 2)
2223 /*Per=Errors/(1 << 8);*/
2224 Per = temporary;
2225 else if (def == 3)
2226 /*Per=Errors/(1 << 10);*/
2227 Per = temporary / 4;
2228 else if (def == 4)
2229 /*Per=Errors/(1 << 12);*/
2230 Per = temporary / 16;
2231 else if (def == 5)
2232 /*Per=Errors/(1 << 14);*/
2233 Per = temporary / 64;
2234 else if (def == 6)
2235 /*Per=Errors/(1 << 16);*/
2236 Per = temporary / 256;
2237 else
2238 Per = 0;
2239
2240 }
2241 /* save actual value */
2242 ter_state->pPER = Per;
2243
2244 return Per;
2245}
2246#endif
2247static int stv0367_get_tune_settings(struct dvb_frontend *fe,
2248 struct dvb_frontend_tune_settings
2249 *fe_tune_settings)
2250{
2251 fe_tune_settings->min_delay_ms = 1000;
2252 fe_tune_settings->step_size = 0;
2253 fe_tune_settings->max_drift = 0;
2254
2255 return 0;
2256}
2257
2258static void stv0367_release(struct dvb_frontend *fe)
2259{
2260 struct stv0367_state *state = fe->demodulator_priv;
2261
2262 kfree(state->ter_state);
2263 kfree(state->cab_state);
2264 kfree(state);
2265}
2266
2267static struct dvb_frontend_ops stv0367ter_ops = {
2268 .info = {
2269 .name = "ST STV0367 DVB-T",
2270 .type = FE_OFDM,
2271 .frequency_min = 47000000,
2272 .frequency_max = 862000000,
2273 .frequency_stepsize = 15625,
2274 .frequency_tolerance = 0,
2275 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
2276 FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
2277 FE_CAN_FEC_AUTO |
2278 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
2279 FE_CAN_QAM_128 | FE_CAN_QAM_256 | FE_CAN_QAM_AUTO |
2280 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_RECOVER |
2281 FE_CAN_INVERSION_AUTO |
2282 FE_CAN_MUTE_TS
2283 },
2284 .release = stv0367_release,
2285 .init = stv0367ter_init,
2286 .sleep = stv0367ter_sleep,
2287 .i2c_gate_ctrl = stv0367ter_gate_ctrl,
2288 .set_frontend = stv0367ter_set_frontend,
2289 .get_frontend = stv0367ter_get_frontend,
2290 .get_tune_settings = stv0367_get_tune_settings,
2291 .read_status = stv0367ter_read_status,
2292 .read_ber = stv0367ter_read_ber,/* too slow */
2293/* .read_signal_strength = stv0367_read_signal_strength,*/
2294 .read_snr = stv0367ter_read_snr,
2295 .read_ucblocks = stv0367ter_read_ucblocks,
2296};
2297
2298struct dvb_frontend *stv0367ter_attach(const struct stv0367_config *config,
2299 struct i2c_adapter *i2c)
2300{
2301 struct stv0367_state *state = NULL;
2302 struct stv0367ter_state *ter_state = NULL;
2303
2304 /* allocate memory for the internal state */
2305 state = kzalloc(sizeof(struct stv0367_state), GFP_KERNEL);
2306 if (state == NULL)
2307 goto error;
2308 ter_state = kzalloc(sizeof(struct stv0367ter_state), GFP_KERNEL);
2309 if (ter_state == NULL)
2310 goto error;
2311
2312 /* setup the state */
2313 state->i2c = i2c;
2314 state->config = config;
2315 state->ter_state = ter_state;
2316 state->fe.ops = stv0367ter_ops;
2317 state->fe.demodulator_priv = state;
2318 state->chip_id = stv0367_readreg(state, 0xf000);
2319
2320 dprintk("%s: chip_id = 0x%x\n", __func__, state->chip_id);
2321
2322 /* check if the demod is there */
2323 if ((state->chip_id != 0x50) && (state->chip_id != 0x60))
2324 goto error;
2325
2326 return &state->fe;
2327
2328error:
2329 kfree(ter_state);
2330 kfree(state);
2331 return NULL;
2332}
2333EXPORT_SYMBOL(stv0367ter_attach);
2334
2335static int stv0367cab_gate_ctrl(struct dvb_frontend *fe, int enable)
2336{
2337 struct stv0367_state *state = fe->demodulator_priv;
2338
2339 dprintk("%s:\n", __func__);
2340
2341 stv0367_writebits(state, F367CAB_I2CT_ON, (enable > 0) ? 1 : 0);
2342
2343 return 0;
2344}
2345
2346static u32 stv0367cab_get_mclk(struct dvb_frontend *fe, u32 ExtClk_Hz)
2347{
2348 struct stv0367_state *state = fe->demodulator_priv;
2349 u32 mclk_Hz = 0;/* master clock frequency (Hz) */
2350 u32 M, N, P;
2351
2352
2353 if (stv0367_readbits(state, F367CAB_BYPASS_PLLXN) == 0) {
2354 N = (u32)stv0367_readbits(state, F367CAB_PLL_NDIV);
2355 if (N == 0)
2356 N = N + 1;
2357
2358 M = (u32)stv0367_readbits(state, F367CAB_PLL_MDIV);
2359 if (M == 0)
2360 M = M + 1;
2361
2362 P = (u32)stv0367_readbits(state, F367CAB_PLL_PDIV);
2363
2364 if (P > 5)
2365 P = 5;
2366
2367 mclk_Hz = ((ExtClk_Hz / 2) * N) / (M * (1 << P));
2368 dprintk("stv0367cab_get_mclk BYPASS_PLLXN mclk_Hz=%d\n",
2369 mclk_Hz);
2370 } else
2371 mclk_Hz = ExtClk_Hz;
2372
2373 dprintk("stv0367cab_get_mclk final mclk_Hz=%d\n", mclk_Hz);
2374
2375 return mclk_Hz;
2376}
2377
2378static u32 stv0367cab_get_adc_freq(struct dvb_frontend *fe, u32 ExtClk_Hz)
2379{
2380 u32 ADCClk_Hz = ExtClk_Hz;
2381
2382 ADCClk_Hz = stv0367cab_get_mclk(fe, ExtClk_Hz);
2383
2384 return ADCClk_Hz;
2385}
2386
2387enum stv0367cab_mod stv0367cab_SetQamSize(struct stv0367_state *state,
2388 u32 SymbolRate,
2389 enum stv0367cab_mod QAMSize)
2390{
2391 /* Set QAM size */
2392 stv0367_writebits(state, F367CAB_QAM_MODE, QAMSize);
2393
2394 /* Set Registers settings specific to the QAM size */
2395 switch (QAMSize) {
2396 case FE_CAB_MOD_QAM4:
2397 stv0367_writereg(state, R367CAB_IQDEM_ADJ_AGC_REF, 0x00);
2398 break;
2399 case FE_CAB_MOD_QAM16:
2400 stv0367_writereg(state, R367CAB_AGC_PWR_REF_L, 0x64);
2401 stv0367_writereg(state, R367CAB_IQDEM_ADJ_AGC_REF, 0x00);
2402 stv0367_writereg(state, R367CAB_FSM_STATE, 0x90);
2403 stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xc1);
2404 stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xa7);
2405 stv0367_writereg(state, R367CAB_EQU_CRL_LD_SEN, 0x95);
2406 stv0367_writereg(state, R367CAB_EQU_CRL_LIMITER, 0x40);
2407 stv0367_writereg(state, R367CAB_EQU_PNT_GAIN, 0x8a);
2408 break;
2409 case FE_CAB_MOD_QAM32:
2410 stv0367_writereg(state, R367CAB_IQDEM_ADJ_AGC_REF, 0x00);
2411 stv0367_writereg(state, R367CAB_AGC_PWR_REF_L, 0x6e);
2412 stv0367_writereg(state, R367CAB_FSM_STATE, 0xb0);
2413 stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xc1);
2414 stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xb7);
2415 stv0367_writereg(state, R367CAB_EQU_CRL_LD_SEN, 0x9d);
2416 stv0367_writereg(state, R367CAB_EQU_CRL_LIMITER, 0x7f);
2417 stv0367_writereg(state, R367CAB_EQU_PNT_GAIN, 0xa7);
2418 break;
2419 case FE_CAB_MOD_QAM64:
2420 stv0367_writereg(state, R367CAB_IQDEM_ADJ_AGC_REF, 0x82);
2421 stv0367_writereg(state, R367CAB_AGC_PWR_REF_L, 0x5a);
2422 if (SymbolRate > 45000000) {
2423 stv0367_writereg(state, R367CAB_FSM_STATE, 0xb0);
2424 stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xc1);
2425 stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xa5);
2426 } else if (SymbolRate > 25000000) {
2427 stv0367_writereg(state, R367CAB_FSM_STATE, 0xa0);
2428 stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xc1);
2429 stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xa6);
2430 } else {
2431 stv0367_writereg(state, R367CAB_FSM_STATE, 0xa0);
2432 stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xd1);
2433 stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xa7);
2434 }
2435 stv0367_writereg(state, R367CAB_EQU_CRL_LD_SEN, 0x95);
2436 stv0367_writereg(state, R367CAB_EQU_CRL_LIMITER, 0x40);
2437 stv0367_writereg(state, R367CAB_EQU_PNT_GAIN, 0x99);
2438 break;
2439 case FE_CAB_MOD_QAM128:
2440 stv0367_writereg(state, R367CAB_IQDEM_ADJ_AGC_REF, 0x00);
2441 stv0367_writereg(state, R367CAB_AGC_PWR_REF_L, 0x76);
2442 stv0367_writereg(state, R367CAB_FSM_STATE, 0x90);
2443 stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xb1);
2444 if (SymbolRate > 45000000)
2445 stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xa7);
2446 else if (SymbolRate > 25000000)
2447 stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xa6);
2448 else
2449 stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0x97);
2450
2451 stv0367_writereg(state, R367CAB_EQU_CRL_LD_SEN, 0x8e);
2452 stv0367_writereg(state, R367CAB_EQU_CRL_LIMITER, 0x7f);
2453 stv0367_writereg(state, R367CAB_EQU_PNT_GAIN, 0xa7);
2454 break;
2455 case FE_CAB_MOD_QAM256:
2456 stv0367_writereg(state, R367CAB_IQDEM_ADJ_AGC_REF, 0x94);
2457 stv0367_writereg(state, R367CAB_AGC_PWR_REF_L, 0x5a);
2458 stv0367_writereg(state, R367CAB_FSM_STATE, 0xa0);
2459 if (SymbolRate > 45000000)
2460 stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xc1);
2461 else if (SymbolRate > 25000000)
2462 stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xc1);
2463 else
2464 stv0367_writereg(state, R367CAB_EQU_CTR_LPF_GAIN, 0xd1);
2465
2466 stv0367_writereg(state, R367CAB_EQU_CRL_LPF_GAIN, 0xa7);
2467 stv0367_writereg(state, R367CAB_EQU_CRL_LD_SEN, 0x85);
2468 stv0367_writereg(state, R367CAB_EQU_CRL_LIMITER, 0x40);
2469 stv0367_writereg(state, R367CAB_EQU_PNT_GAIN, 0xa7);
2470 break;
2471 case FE_CAB_MOD_QAM512:
2472 stv0367_writereg(state, R367CAB_IQDEM_ADJ_AGC_REF, 0x00);
2473 break;
2474 case FE_CAB_MOD_QAM1024:
2475 stv0367_writereg(state, R367CAB_IQDEM_ADJ_AGC_REF, 0x00);
2476 break;
2477 default:
2478 break;
2479 }
2480
2481 return QAMSize;
2482}
2483
2484static u32 stv0367cab_set_derot_freq(struct stv0367_state *state,
2485 u32 adc_hz, s32 derot_hz)
2486{
2487 u32 sampled_if = 0;
2488 u32 adc_khz;
2489
2490 adc_khz = adc_hz / 1000;
2491
2492 dprintk("%s: adc_hz=%d derot_hz=%d\n", __func__, adc_hz, derot_hz);
2493
2494 if (adc_khz != 0) {
2495 if (derot_hz < 1000000)
2496 derot_hz = adc_hz / 4; /* ZIF operation */
2497 if (derot_hz > adc_hz)
2498 derot_hz = derot_hz - adc_hz;
2499 sampled_if = (u32)derot_hz / 1000;
2500 sampled_if *= 32768;
2501 sampled_if /= adc_khz;
2502 sampled_if *= 256;
2503 }
2504
2505 if (sampled_if > 8388607)
2506 sampled_if = 8388607;
2507
2508 dprintk("%s: sampled_if=0x%x\n", __func__, sampled_if);
2509
2510 stv0367_writereg(state, R367CAB_MIX_NCO_LL, sampled_if);
2511 stv0367_writereg(state, R367CAB_MIX_NCO_HL, (sampled_if >> 8));
2512 stv0367_writebits(state, F367CAB_MIX_NCO_INC_HH, (sampled_if >> 16));
2513
2514 return derot_hz;
2515}
2516
2517static u32 stv0367cab_get_derot_freq(struct stv0367_state *state, u32 adc_hz)
2518{
2519 u32 sampled_if;
2520
2521 sampled_if = stv0367_readbits(state, F367CAB_MIX_NCO_INC_LL) +
2522 (stv0367_readbits(state, F367CAB_MIX_NCO_INC_HL) << 8) +
2523 (stv0367_readbits(state, F367CAB_MIX_NCO_INC_HH) << 16);
2524
2525 sampled_if /= 256;
2526 sampled_if *= (adc_hz / 1000);
2527 sampled_if += 1;
2528 sampled_if /= 32768;
2529
2530 return sampled_if;
2531}
2532
2533static u32 stv0367cab_set_srate(struct stv0367_state *state, u32 adc_hz,
2534 u32 mclk_hz, u32 SymbolRate,
2535 enum stv0367cab_mod QAMSize)
2536{
2537 u32 QamSizeCorr = 0;
2538 u32 u32_tmp = 0, u32_tmp1 = 0;
2539 u32 adp_khz;
2540
2541 dprintk("%s:\n", __func__);
2542
2543 /* Set Correction factor of SRC gain */
2544 switch (QAMSize) {
2545 case FE_CAB_MOD_QAM4:
2546 QamSizeCorr = 1110;
2547 break;
2548 case FE_CAB_MOD_QAM16:
2549 QamSizeCorr = 1032;
2550 break;
2551 case FE_CAB_MOD_QAM32:
2552 QamSizeCorr = 954;
2553 break;
2554 case FE_CAB_MOD_QAM64:
2555 QamSizeCorr = 983;
2556 break;
2557 case FE_CAB_MOD_QAM128:
2558 QamSizeCorr = 957;
2559 break;
2560 case FE_CAB_MOD_QAM256:
2561 QamSizeCorr = 948;
2562 break;
2563 case FE_CAB_MOD_QAM512:
2564 QamSizeCorr = 0;
2565 break;
2566 case FE_CAB_MOD_QAM1024:
2567 QamSizeCorr = 944;
2568 break;
2569 default:
2570 break;
2571 }
2572
2573 /* Transfer ratio calculation */
2574 if (adc_hz != 0) {
2575 u32_tmp = 256 * SymbolRate;
2576 u32_tmp = u32_tmp / adc_hz;
2577 }
2578 stv0367_writereg(state, R367CAB_EQU_CRL_TFR, (u8)u32_tmp);
2579
2580 /* Symbol rate and SRC gain calculation */
2581 adp_khz = (mclk_hz >> 1) / 1000;/* TRL works at half the system clock */
2582 if (adp_khz != 0) {
2583 u32_tmp = SymbolRate;
2584 u32_tmp1 = SymbolRate;
2585
2586 if (u32_tmp < 2097152) { /* 2097152 = 2^21 */
2587 /* Symbol rate calculation */
2588 u32_tmp *= 2048; /* 2048 = 2^11 */
2589 u32_tmp = u32_tmp / adp_khz;
2590 u32_tmp = u32_tmp * 16384; /* 16384 = 2^14 */
2591 u32_tmp /= 125 ; /* 125 = 1000/2^3 */
2592 u32_tmp = u32_tmp * 8; /* 8 = 2^3 */
2593
2594 /* SRC Gain Calculation */
2595 u32_tmp1 *= 2048; /* *2*2^10 */
2596 u32_tmp1 /= 439; /* *2/878 */
2597 u32_tmp1 *= 256; /* *2^8 */
2598 u32_tmp1 = u32_tmp1 / adp_khz; /* /(AdpClk in kHz) */
2599 u32_tmp1 *= QamSizeCorr * 9; /* *1000*corr factor */
2600 u32_tmp1 = u32_tmp1 / 10000000;
2601
2602 } else if (u32_tmp < 4194304) { /* 4194304 = 2**22 */
2603 /* Symbol rate calculation */
2604 u32_tmp *= 1024 ; /* 1024 = 2**10 */
2605 u32_tmp = u32_tmp / adp_khz;
2606 u32_tmp = u32_tmp * 16384; /* 16384 = 2**14 */
2607 u32_tmp /= 125 ; /* 125 = 1000/2**3 */
2608 u32_tmp = u32_tmp * 16; /* 16 = 2**4 */
2609
2610 /* SRC Gain Calculation */
2611 u32_tmp1 *= 1024; /* *2*2^9 */
2612 u32_tmp1 /= 439; /* *2/878 */
2613 u32_tmp1 *= 256; /* *2^8 */
2614 u32_tmp1 = u32_tmp1 / adp_khz; /* /(AdpClk in kHz)*/
2615 u32_tmp1 *= QamSizeCorr * 9; /* *1000*corr factor */
2616 u32_tmp1 = u32_tmp1 / 5000000;
2617 } else if (u32_tmp < 8388607) { /* 8388607 = 2**23 */
2618 /* Symbol rate calculation */
2619 u32_tmp *= 512 ; /* 512 = 2**9 */
2620 u32_tmp = u32_tmp / adp_khz;
2621 u32_tmp = u32_tmp * 16384; /* 16384 = 2**14 */
2622 u32_tmp /= 125 ; /* 125 = 1000/2**3 */
2623 u32_tmp = u32_tmp * 32; /* 32 = 2**5 */
2624
2625 /* SRC Gain Calculation */
2626 u32_tmp1 *= 512; /* *2*2^8 */
2627 u32_tmp1 /= 439; /* *2/878 */
2628 u32_tmp1 *= 256; /* *2^8 */
2629 u32_tmp1 = u32_tmp1 / adp_khz; /* /(AdpClk in kHz) */
2630 u32_tmp1 *= QamSizeCorr * 9; /* *1000*corr factor */
2631 u32_tmp1 = u32_tmp1 / 2500000;
2632 } else {
2633 /* Symbol rate calculation */
2634 u32_tmp *= 256 ; /* 256 = 2**8 */
2635 u32_tmp = u32_tmp / adp_khz;
2636 u32_tmp = u32_tmp * 16384; /* 16384 = 2**13 */
2637 u32_tmp /= 125 ; /* 125 = 1000/2**3 */
2638 u32_tmp = u32_tmp * 64; /* 64 = 2**6 */
2639
2640 /* SRC Gain Calculation */
2641 u32_tmp1 *= 256; /* 2*2^7 */
2642 u32_tmp1 /= 439; /* *2/878 */
2643 u32_tmp1 *= 256; /* *2^8 */
2644 u32_tmp1 = u32_tmp1 / adp_khz; /* /(AdpClk in kHz) */
2645 u32_tmp1 *= QamSizeCorr * 9; /* *1000*corr factor */
2646 u32_tmp1 = u32_tmp1 / 1250000;
2647 }
2648 }
2649#if 0
2650 /* Filters' coefficients are calculated and written
2651 into registers only if the filters are enabled */
2652 if (stv0367_readbits(state, F367CAB_ADJ_EN)) {
2653 stv0367cab_SetIirAdjacentcoefficient(state, mclk_hz,
2654 SymbolRate);
2655 /* AllPass filter must be enabled
2656 when the adjacents filter is used */
2657 stv0367_writebits(state, F367CAB_ALLPASSFILT_EN, 1);
2658 stv0367cab_SetAllPasscoefficient(state, mclk_hz, SymbolRate);
2659 } else
2660 /* AllPass filter must be disabled
2661 when the adjacents filter is not used */
2662#endif
2663 stv0367_writebits(state, F367CAB_ALLPASSFILT_EN, 0);
2664
2665 stv0367_writereg(state, R367CAB_SRC_NCO_LL, u32_tmp);
2666 stv0367_writereg(state, R367CAB_SRC_NCO_LH, (u32_tmp >> 8));
2667 stv0367_writereg(state, R367CAB_SRC_NCO_HL, (u32_tmp >> 16));
2668 stv0367_writereg(state, R367CAB_SRC_NCO_HH, (u32_tmp >> 24));
2669
2670 stv0367_writereg(state, R367CAB_IQDEM_GAIN_SRC_L, u32_tmp1 & 0x00ff);
2671 stv0367_writebits(state, F367CAB_GAIN_SRC_HI, (u32_tmp1 >> 8) & 0x00ff);
2672
2673 return SymbolRate ;
2674}
2675
2676static u32 stv0367cab_GetSymbolRate(struct stv0367_state *state, u32 mclk_hz)
2677{
2678 u32 regsym;
2679 u32 adp_khz;
2680
2681 regsym = stv0367_readreg(state, R367CAB_SRC_NCO_LL) +
2682 (stv0367_readreg(state, R367CAB_SRC_NCO_LH) << 8) +
2683 (stv0367_readreg(state, R367CAB_SRC_NCO_HL) << 16) +
2684 (stv0367_readreg(state, R367CAB_SRC_NCO_HH) << 24);
2685
2686 adp_khz = (mclk_hz >> 1) / 1000;/* TRL works at half the system clock */
2687
2688 if (regsym < 134217728) { /* 134217728L = 2**27*/
2689 regsym = regsym * 32; /* 32 = 2**5 */
2690 regsym = regsym / 32768; /* 32768L = 2**15 */
2691 regsym = adp_khz * regsym; /* AdpClk in kHz */
2692 regsym = regsym / 128; /* 128 = 2**7 */
2693 regsym *= 125 ; /* 125 = 1000/2**3 */
2694 regsym /= 2048 ; /* 2048 = 2**11 */
2695 } else if (regsym < 268435456) { /* 268435456L = 2**28 */
2696 regsym = regsym * 16; /* 16 = 2**4 */
2697 regsym = regsym / 32768; /* 32768L = 2**15 */
2698 regsym = adp_khz * regsym; /* AdpClk in kHz */
2699 regsym = regsym / 128; /* 128 = 2**7 */
2700 regsym *= 125 ; /* 125 = 1000/2**3*/
2701 regsym /= 1024 ; /* 256 = 2**10*/
2702 } else if (regsym < 536870912) { /* 536870912L = 2**29*/
2703 regsym = regsym * 8; /* 8 = 2**3 */
2704 regsym = regsym / 32768; /* 32768L = 2**15 */
2705 regsym = adp_khz * regsym; /* AdpClk in kHz */
2706 regsym = regsym / 128; /* 128 = 2**7 */
2707 regsym *= 125 ; /* 125 = 1000/2**3 */
2708 regsym /= 512 ; /* 128 = 2**9 */
2709 } else {
2710 regsym = regsym * 4; /* 4 = 2**2 */
2711 regsym = regsym / 32768; /* 32768L = 2**15 */
2712 regsym = adp_khz * regsym; /* AdpClk in kHz */
2713 regsym = regsym / 128; /* 128 = 2**7 */
2714 regsym *= 125 ; /* 125 = 1000/2**3 */
2715 regsym /= 256 ; /* 64 = 2**8 */
2716 }
2717
2718 return regsym;
2719}
2720
2721static int stv0367cab_read_status(struct dvb_frontend *fe, fe_status_t *status)
2722{
2723 struct stv0367_state *state = fe->demodulator_priv;
2724
2725 dprintk("%s:\n", __func__);
2726
2727 *status = 0;
2728
2729 if (stv0367_readbits(state, F367CAB_QAMFEC_LOCK)) {
2730 *status |= FE_HAS_LOCK;
2731 dprintk("%s: stv0367 has locked\n", __func__);
2732 }
2733
2734 return 0;
2735}
2736
2737static int stv0367cab_standby(struct dvb_frontend *fe, u8 standby_on)
2738{
2739 struct stv0367_state *state = fe->demodulator_priv;
2740
2741 dprintk("%s:\n", __func__);
2742
2743 if (standby_on) {
2744 stv0367_writebits(state, F367CAB_BYPASS_PLLXN, 0x03);
2745 stv0367_writebits(state, F367CAB_STDBY_PLLXN, 0x01);
2746 stv0367_writebits(state, F367CAB_STDBY, 1);
2747 stv0367_writebits(state, F367CAB_STDBY_CORE, 1);
2748 stv0367_writebits(state, F367CAB_EN_BUFFER_I, 0);
2749 stv0367_writebits(state, F367CAB_EN_BUFFER_Q, 0);
2750 stv0367_writebits(state, F367CAB_POFFQ, 1);
2751 stv0367_writebits(state, F367CAB_POFFI, 1);
2752 } else {
2753 stv0367_writebits(state, F367CAB_STDBY_PLLXN, 0x00);
2754 stv0367_writebits(state, F367CAB_BYPASS_PLLXN, 0x00);
2755 stv0367_writebits(state, F367CAB_STDBY, 0);
2756 stv0367_writebits(state, F367CAB_STDBY_CORE, 0);
2757 stv0367_writebits(state, F367CAB_EN_BUFFER_I, 1);
2758 stv0367_writebits(state, F367CAB_EN_BUFFER_Q, 1);
2759 stv0367_writebits(state, F367CAB_POFFQ, 0);
2760 stv0367_writebits(state, F367CAB_POFFI, 0);
2761 }
2762
2763 return 0;
2764}
2765
2766static int stv0367cab_sleep(struct dvb_frontend *fe)
2767{
2768 return stv0367cab_standby(fe, 1);
2769}
2770
2771int stv0367cab_init(struct dvb_frontend *fe)
2772{
2773 struct stv0367_state *state = fe->demodulator_priv;
2774 struct stv0367cab_state *cab_state = state->cab_state;
2775 int i;
2776
2777 dprintk("%s:\n", __func__);
2778
2779 for (i = 0; i < STV0367CAB_NBREGS; i++)
2780 stv0367_writereg(state, def0367cab[i].addr,
2781 def0367cab[i].value);
2782
2783 switch (state->config->ts_mode) {
2784 case STV0367_DVBCI_CLOCK:
2785 dprintk("Setting TSMode = STV0367_DVBCI_CLOCK\n");
2786 stv0367_writebits(state, F367CAB_OUTFORMAT, 0x03);
2787 break;
2788 case STV0367_SERIAL_PUNCT_CLOCK:
2789 case STV0367_SERIAL_CONT_CLOCK:
2790 stv0367_writebits(state, F367CAB_OUTFORMAT, 0x01);
2791 break;
2792 case STV0367_PARALLEL_PUNCT_CLOCK:
2793 case STV0367_OUTPUTMODE_DEFAULT:
2794 stv0367_writebits(state, F367CAB_OUTFORMAT, 0x00);
2795 break;
2796 }
2797
2798 switch (state->config->clk_pol) {
2799 case STV0367_RISINGEDGE_CLOCK:
2800 stv0367_writebits(state, F367CAB_CLK_POLARITY, 0x00);
2801 break;
2802 case STV0367_FALLINGEDGE_CLOCK:
2803 case STV0367_CLOCKPOLARITY_DEFAULT:
2804 stv0367_writebits(state, F367CAB_CLK_POLARITY, 0x01);
2805 break;
2806 }
2807
2808 stv0367_writebits(state, F367CAB_SYNC_STRIP, 0x00);
2809
2810 stv0367_writebits(state, F367CAB_CT_NBST, 0x01);
2811
2812 stv0367_writebits(state, F367CAB_TS_SWAP, 0x01);
2813
2814 stv0367_writebits(state, F367CAB_FIFO_BYPASS, 0x00);
2815
2816 stv0367_writereg(state, R367CAB_ANACTRL, 0x00);/*PLL enabled and used */
2817
2818 cab_state->mclk = stv0367cab_get_mclk(fe, state->config->xtal);
2819 cab_state->adc_clk = stv0367cab_get_adc_freq(fe, state->config->xtal);
2820
2821 return 0;
2822}
2823static
2824enum stv0367_cab_signal_type stv0367cab_algo(struct stv0367_state *state,
2825 struct dvb_frontend_parameters *param)
2826{
2827 struct dvb_qam_parameters *op = &param->u.qam;
2828 struct stv0367cab_state *cab_state = state->cab_state;
2829 enum stv0367_cab_signal_type signalType = FE_CAB_NOAGC;
2830 u32 QAMFEC_Lock, QAM_Lock, u32_tmp,
2831 LockTime, TRLTimeOut, AGCTimeOut, CRLSymbols,
2832 CRLTimeOut, EQLTimeOut, DemodTimeOut, FECTimeOut;
2833 u8 TrackAGCAccum;
2834 s32 tmp;
2835
2836 dprintk("%s:\n", __func__);
2837
2838 /* Timeouts calculation */
2839 /* A max lock time of 25 ms is allowed for delayed AGC */
2840 AGCTimeOut = 25;
2841 /* 100000 symbols needed by the TRL as a maximum value */
2842 TRLTimeOut = 100000000 / op->symbol_rate;
2843 /* CRLSymbols is the needed number of symbols to achieve a lock
2844 within [-4%, +4%] of the symbol rate.
2845 CRL timeout is calculated
2846 for a lock within [-search_range, +search_range].
2847 EQL timeout can be changed depending on
2848 the micro-reflections we want to handle.
2849 A characterization must be performed
2850 with these echoes to get new timeout values.
2851 */
2852 switch (op->modulation) {
2853 case QAM_16:
2854 CRLSymbols = 150000;
2855 EQLTimeOut = 100;
2856 break;
2857 case QAM_32:
2858 CRLSymbols = 250000;
2859 EQLTimeOut = 100;
2860 break;
2861 case QAM_64:
2862 CRLSymbols = 200000;
2863 EQLTimeOut = 100;
2864 break;
2865 case QAM_128:
2866 CRLSymbols = 250000;
2867 EQLTimeOut = 100;
2868 break;
2869 case QAM_256:
2870 CRLSymbols = 250000;
2871 EQLTimeOut = 100;
2872 break;
2873 default:
2874 CRLSymbols = 200000;
2875 EQLTimeOut = 100;
2876 break;
2877 }
2878#if 0
2879 if (pIntParams->search_range < 0) {
2880 CRLTimeOut = (25 * CRLSymbols *
2881 (-pIntParams->search_range / 1000)) /
2882 (pIntParams->symbol_rate / 1000);
2883 } else
2884#endif
2885 CRLTimeOut = (25 * CRLSymbols * (cab_state->search_range / 1000)) /
2886 (op->symbol_rate / 1000);
2887
2888 CRLTimeOut = (1000 * CRLTimeOut) / op->symbol_rate;
2889 /* Timeouts below 50ms are coerced */
2890 if (CRLTimeOut < 50)
2891 CRLTimeOut = 50;
2892 /* A maximum of 100 TS packets is needed to get FEC lock even in case
2893 the spectrum inversion needs to be changed.
2894 This is equal to 20 ms in case of the lowest symbol rate of 0.87Msps
2895 */
2896 FECTimeOut = 20;
2897 DemodTimeOut = AGCTimeOut + TRLTimeOut + CRLTimeOut + EQLTimeOut;
2898
2899 dprintk("%s: DemodTimeOut=%d\n", __func__, DemodTimeOut);
2900
2901 /* Reset the TRL to ensure nothing starts until the
2902 AGC is stable which ensures a better lock time
2903 */
2904 stv0367_writereg(state, R367CAB_CTRL_1, 0x04);
2905 /* Set AGC accumulation time to minimum and lock threshold to maximum
2906 in order to speed up the AGC lock */
2907 TrackAGCAccum = stv0367_readbits(state, F367CAB_AGC_ACCUMRSTSEL);
2908 stv0367_writebits(state, F367CAB_AGC_ACCUMRSTSEL, 0x0);
2909 /* Modulus Mapper is disabled */
2910 stv0367_writebits(state, F367CAB_MODULUSMAP_EN, 0);
2911 /* Disable the sweep function */
2912 stv0367_writebits(state, F367CAB_SWEEP_EN, 0);
2913 /* The sweep function is never used, Sweep rate must be set to 0 */
2914 /* Set the derotator frequency in Hz */
2915 stv0367cab_set_derot_freq(state, cab_state->adc_clk,
2916 (1000 * (s32)state->config->if_khz + cab_state->derot_offset));
2917 /* Disable the Allpass Filter when the symbol rate is out of range */
2918 if ((op->symbol_rate > 10800000) | (op->symbol_rate < 1800000)) {
2919 stv0367_writebits(state, F367CAB_ADJ_EN, 0);
2920 stv0367_writebits(state, F367CAB_ALLPASSFILT_EN, 0);
2921 }
2922#if 0
2923 /* Check if the tuner is locked */
2924 tuner_lock = stv0367cab_tuner_get_status(fe);
2925 if (tuner_lock == 0)
2926 return FE_367CAB_NOTUNER;
2927#endif
2928 /* Relase the TRL to start demodulator acquisition */
2929 /* Wait for QAM lock */
2930 LockTime = 0;
2931 stv0367_writereg(state, R367CAB_CTRL_1, 0x00);
2932 do {
2933 QAM_Lock = stv0367_readbits(state, F367CAB_FSM_STATUS);
2934 if ((LockTime >= (DemodTimeOut - EQLTimeOut)) &&
2935 (QAM_Lock == 0x04))
2936 /*
2937 * We don't wait longer, the frequency/phase offset
2938 * must be too big
2939 */
2940 LockTime = DemodTimeOut;
2941 else if ((LockTime >= (AGCTimeOut + TRLTimeOut)) &&
2942 (QAM_Lock == 0x02))
2943 /*
2944 * We don't wait longer, either there is no signal or
2945 * it is not the right symbol rate or it is an analog
2946 * carrier
2947 */
2948 {
2949 LockTime = DemodTimeOut;
2950 u32_tmp = stv0367_readbits(state,
2951 F367CAB_AGC_PWR_WORD_LO) +
2952 (stv0367_readbits(state,
2953 F367CAB_AGC_PWR_WORD_ME) << 8) +
2954 (stv0367_readbits(state,
2955 F367CAB_AGC_PWR_WORD_HI) << 16);
2956 if (u32_tmp >= 131072)
2957 u32_tmp = 262144 - u32_tmp;
2958 u32_tmp = u32_tmp / (1 << (11 - stv0367_readbits(state,
2959 F367CAB_AGC_IF_BWSEL)));
2960
2961 if (u32_tmp < stv0367_readbits(state,
2962 F367CAB_AGC_PWRREF_LO) +
2963 256 * stv0367_readbits(state,
2964 F367CAB_AGC_PWRREF_HI) - 10)
2965 QAM_Lock = 0x0f;
2966 } else {
2967 usleep_range(10000, 20000);
2968 LockTime += 10;
2969 }
2970 dprintk("QAM_Lock=0x%x LockTime=%d\n", QAM_Lock, LockTime);
2971 tmp = stv0367_readreg(state, R367CAB_IT_STATUS1);
2972
2973 dprintk("R367CAB_IT_STATUS1=0x%x\n", tmp);
2974
2975 } while (((QAM_Lock != 0x0c) && (QAM_Lock != 0x0b)) &&
2976 (LockTime < DemodTimeOut));
2977
2978 dprintk("QAM_Lock=0x%x\n", QAM_Lock);
2979
2980 tmp = stv0367_readreg(state, R367CAB_IT_STATUS1);
2981 dprintk("R367CAB_IT_STATUS1=0x%x\n", tmp);
2982 tmp = stv0367_readreg(state, R367CAB_IT_STATUS2);
2983 dprintk("R367CAB_IT_STATUS2=0x%x\n", tmp);
2984
2985 tmp = stv0367cab_get_derot_freq(state, cab_state->adc_clk);
2986 dprintk("stv0367cab_get_derot_freq=0x%x\n", tmp);
2987
2988 if ((QAM_Lock == 0x0c) || (QAM_Lock == 0x0b)) {
2989 /* Wait for FEC lock */
2990 LockTime = 0;
2991 do {
2992 usleep_range(5000, 7000);
2993 LockTime += 5;
2994 QAMFEC_Lock = stv0367_readbits(state,
2995 F367CAB_QAMFEC_LOCK);
2996 } while (!QAMFEC_Lock && (LockTime < FECTimeOut));
2997 } else
2998 QAMFEC_Lock = 0;
2999
3000 if (QAMFEC_Lock) {
3001 signalType = FE_CAB_DATAOK;
3002 cab_state->modulation = op->modulation;
3003 cab_state->spect_inv = stv0367_readbits(state,
3004 F367CAB_QUAD_INV);
3005#if 0
3006/* not clear for me */
3007 if (state->config->if_khz != 0) {
3008 if (state->config->if_khz > cab_state->adc_clk / 1000) {
3009 cab_state->freq_khz =
3010 FE_Cab_TunerGetFrequency(pIntParams->hTuner)
3011 - stv0367cab_get_derot_freq(state, cab_state->adc_clk)
3012 - cab_state->adc_clk / 1000 + state->config->if_khz;
3013 } else {
3014 cab_state->freq_khz =
3015 FE_Cab_TunerGetFrequency(pIntParams->hTuner)
3016 - stv0367cab_get_derot_freq(state, cab_state->adc_clk)
3017 + state->config->if_khz;
3018 }
3019 } else {
3020 cab_state->freq_khz =
3021 FE_Cab_TunerGetFrequency(pIntParams->hTuner) +
3022 stv0367cab_get_derot_freq(state,
3023 cab_state->adc_clk) -
3024 cab_state->adc_clk / 4000;
3025 }
3026#endif
3027 cab_state->symbol_rate = stv0367cab_GetSymbolRate(state,
3028 cab_state->mclk);
3029 cab_state->locked = 1;
3030
3031 /* stv0367_setbits(state, F367CAB_AGC_ACCUMRSTSEL,7);*/
3032 } else {
3033 switch (QAM_Lock) {
3034 case 1:
3035 signalType = FE_CAB_NOAGC;
3036 break;
3037 case 2:
3038 signalType = FE_CAB_NOTIMING;
3039 break;
3040 case 3:
3041 signalType = FE_CAB_TIMINGOK;
3042 break;
3043 case 4:
3044 signalType = FE_CAB_NOCARRIER;
3045 break;
3046 case 5:
3047 signalType = FE_CAB_CARRIEROK;
3048 break;
3049 case 7:
3050 signalType = FE_CAB_NOBLIND;
3051 break;
3052 case 8:
3053 signalType = FE_CAB_BLINDOK;
3054 break;
3055 case 10:
3056 signalType = FE_CAB_NODEMOD;
3057 break;
3058 case 11:
3059 signalType = FE_CAB_DEMODOK;
3060 break;
3061 case 12:
3062 signalType = FE_CAB_DEMODOK;
3063 break;
3064 case 13:
3065 signalType = FE_CAB_NODEMOD;
3066 break;
3067 case 14:
3068 signalType = FE_CAB_NOBLIND;
3069 break;
3070 case 15:
3071 signalType = FE_CAB_NOSIGNAL;
3072 break;
3073 default:
3074 break;
3075 }
3076
3077 }
3078
3079 /* Set the AGC control values to tracking values */
3080 stv0367_writebits(state, F367CAB_AGC_ACCUMRSTSEL, TrackAGCAccum);
3081 return signalType;
3082}
3083
3084static int stv0367cab_set_frontend(struct dvb_frontend *fe,
3085 struct dvb_frontend_parameters *param)
3086{
3087 struct stv0367_state *state = fe->demodulator_priv;
3088 struct stv0367cab_state *cab_state = state->cab_state;
3089 struct dvb_qam_parameters *op = &param->u.qam;
3090 enum stv0367cab_mod QAMSize = 0;
3091
3092 dprintk("%s: freq = %d, srate = %d\n", __func__,
3093 param->frequency, op->symbol_rate);
3094
3095 cab_state->derot_offset = 0;
3096
3097 switch (op->modulation) {
3098 case QAM_16:
3099 QAMSize = FE_CAB_MOD_QAM16;
3100 break;
3101 case QAM_32:
3102 QAMSize = FE_CAB_MOD_QAM32;
3103 break;
3104 case QAM_64:
3105 QAMSize = FE_CAB_MOD_QAM64;
3106 break;
3107 case QAM_128:
3108 QAMSize = FE_CAB_MOD_QAM128;
3109 break;
3110 case QAM_256:
3111 QAMSize = FE_CAB_MOD_QAM256;
3112 break;
3113 default:
3114 break;
3115 }
3116
3117 stv0367cab_init(fe);
3118
3119 /* Tuner Frequency Setting */
3120 if (fe->ops.tuner_ops.set_params) {
3121 if (fe->ops.i2c_gate_ctrl)
3122 fe->ops.i2c_gate_ctrl(fe, 1);
3123 fe->ops.tuner_ops.set_params(fe, param);
3124 if (fe->ops.i2c_gate_ctrl)
3125 fe->ops.i2c_gate_ctrl(fe, 0);
3126 }
3127
3128 stv0367cab_SetQamSize(
3129 state,
3130 op->symbol_rate,
3131 QAMSize);
3132
3133 stv0367cab_set_srate(state,
3134 cab_state->adc_clk,
3135 cab_state->mclk,
3136 op->symbol_rate,
3137 QAMSize);
3138 /* Search algorithm launch, [-1.1*RangeOffset, +1.1*RangeOffset] scan */
3139 cab_state->state = stv0367cab_algo(state, param);
3140 return 0;
3141}
3142
3143static int stv0367cab_get_frontend(struct dvb_frontend *fe,
3144 struct dvb_frontend_parameters *param)
3145{
3146 struct stv0367_state *state = fe->demodulator_priv;
3147 struct stv0367cab_state *cab_state = state->cab_state;
3148 struct dvb_qam_parameters *op = &param->u.qam;
3149
3150 enum stv0367cab_mod QAMSize;
3151
3152 dprintk("%s:\n", __func__);
3153
3154 op->symbol_rate = stv0367cab_GetSymbolRate(state, cab_state->mclk);
3155
3156 QAMSize = stv0367_readbits(state, F367CAB_QAM_MODE);
3157 switch (QAMSize) {
3158 case FE_CAB_MOD_QAM16:
3159 op->modulation = QAM_16;
3160 break;
3161 case FE_CAB_MOD_QAM32:
3162 op->modulation = QAM_32;
3163 break;
3164 case FE_CAB_MOD_QAM64:
3165 op->modulation = QAM_64;
3166 break;
3167 case FE_CAB_MOD_QAM128:
3168 op->modulation = QAM_128;
3169 break;
3170 case QAM_256:
3171 op->modulation = QAM_256;
3172 break;
3173 default:
3174 break;
3175 }
3176
3177 param->frequency = stv0367_get_tuner_freq(fe);
3178
3179 dprintk("%s: tuner frequency = %d\n", __func__, param->frequency);
3180
3181 if (state->config->if_khz == 0) {
3182 param->frequency +=
3183 (stv0367cab_get_derot_freq(state, cab_state->adc_clk) -
3184 cab_state->adc_clk / 4000);
3185 return 0;
3186 }
3187
3188 if (state->config->if_khz > cab_state->adc_clk / 1000)
3189 param->frequency += (state->config->if_khz
3190 - stv0367cab_get_derot_freq(state, cab_state->adc_clk)
3191 - cab_state->adc_clk / 1000);
3192 else
3193 param->frequency += (state->config->if_khz
3194 - stv0367cab_get_derot_freq(state, cab_state->adc_clk));
3195
3196 return 0;
3197}
3198
3199#if 0
3200void stv0367cab_GetErrorCount(state, enum stv0367cab_mod QAMSize,
3201 u32 symbol_rate, FE_367qam_Monitor *Monitor_results)
3202{
3203 stv0367cab_OptimiseNByteAndGetBER(state, QAMSize, symbol_rate, Monitor_results);
3204 stv0367cab_GetPacketsCount(state, Monitor_results);
3205
3206 return;
3207}
3208
3209static int stv0367cab_read_ber(struct dvb_frontend *fe, u32 *ber)
3210{
3211 struct stv0367_state *state = fe->demodulator_priv;
3212
3213 return 0;
3214}
3215#endif
3216static s32 stv0367cab_get_rf_lvl(struct stv0367_state *state)
3217{
3218 s32 rfLevel = 0;
3219 s32 RfAgcPwm = 0, IfAgcPwm = 0;
3220 u8 i;
3221
3222 stv0367_writebits(state, F367CAB_STDBY_ADCGP, 0x0);
3223
3224 RfAgcPwm =
3225 (stv0367_readbits(state, F367CAB_RF_AGC1_LEVEL_LO) & 0x03) +
3226 (stv0367_readbits(state, F367CAB_RF_AGC1_LEVEL_HI) << 2);
3227 RfAgcPwm = 100 * RfAgcPwm / 1023;
3228
3229 IfAgcPwm =
3230 stv0367_readbits(state, F367CAB_AGC_IF_PWMCMD_LO) +
3231 (stv0367_readbits(state, F367CAB_AGC_IF_PWMCMD_HI) << 8);
3232 if (IfAgcPwm >= 2048)
3233 IfAgcPwm -= 2048;
3234 else
3235 IfAgcPwm += 2048;
3236
3237 IfAgcPwm = 100 * IfAgcPwm / 4095;
3238
3239 /* For DTT75467 on NIM */
3240 if (RfAgcPwm < 90 && IfAgcPwm < 28) {
3241 for (i = 0; i < RF_LOOKUP_TABLE_SIZE; i++) {
3242 if (RfAgcPwm <= stv0367cab_RF_LookUp1[0][i]) {
3243 rfLevel = (-1) * stv0367cab_RF_LookUp1[1][i];
3244 break;
3245 }
3246 }
3247 if (i == RF_LOOKUP_TABLE_SIZE)
3248 rfLevel = -56;
3249 } else { /*if IF AGC>10*/
3250 for (i = 0; i < RF_LOOKUP_TABLE2_SIZE; i++) {
3251 if (IfAgcPwm <= stv0367cab_RF_LookUp2[0][i]) {
3252 rfLevel = (-1) * stv0367cab_RF_LookUp2[1][i];
3253 break;
3254 }
3255 }
3256 if (i == RF_LOOKUP_TABLE2_SIZE)
3257 rfLevel = -72;
3258 }
3259 return rfLevel;
3260}
3261
3262static int stv0367cab_read_strength(struct dvb_frontend *fe, u16 *strength)
3263{
3264 struct stv0367_state *state = fe->demodulator_priv;
3265
3266 s32 signal = stv0367cab_get_rf_lvl(state);
3267
3268 dprintk("%s: signal=%d dBm\n", __func__, signal);
3269
3270 if (signal <= -72)
3271 *strength = 65535;
3272 else
3273 *strength = (22 + signal) * (-1311);
3274
3275 dprintk("%s: strength=%d\n", __func__, (*strength));
3276
3277 return 0;
3278}
3279
3280static int stv0367cab_read_snr(struct dvb_frontend *fe, u16 *snr)
3281{
3282 struct stv0367_state *state = fe->demodulator_priv;
3283 u32 noisepercentage;
3284 enum stv0367cab_mod QAMSize;
3285 u32 regval = 0, temp = 0;
3286 int power, i;
3287
3288 QAMSize = stv0367_readbits(state, F367CAB_QAM_MODE);
3289 switch (QAMSize) {
3290 case FE_CAB_MOD_QAM4:
3291 power = 21904;
3292 break;
3293 case FE_CAB_MOD_QAM16:
3294 power = 20480;
3295 break;
3296 case FE_CAB_MOD_QAM32:
3297 power = 23040;
3298 break;
3299 case FE_CAB_MOD_QAM64:
3300 power = 21504;
3301 break;
3302 case FE_CAB_MOD_QAM128:
3303 power = 23616;
3304 break;
3305 case FE_CAB_MOD_QAM256:
3306 power = 21760;
3307 break;
3308 case FE_CAB_MOD_QAM512:
3309 power = 1;
3310 break;
3311 case FE_CAB_MOD_QAM1024:
3312 power = 21280;
3313 break;
3314 default:
3315 power = 1;
3316 break;
3317 }
3318
3319 for (i = 0; i < 10; i++) {
3320 regval += (stv0367_readbits(state, F367CAB_SNR_LO)
3321 + 256 * stv0367_readbits(state, F367CAB_SNR_HI));
3322 }
3323
3324 regval /= 10; /*for average over 10 times in for loop above*/
3325 if (regval != 0) {
3326 temp = power
3327 * (1 << (3 + stv0367_readbits(state, F367CAB_SNR_PER)));
3328 temp /= regval;
3329 }
3330
3331 /* table values, not needed to calculate logarithms */
3332 if (temp >= 5012)
3333 noisepercentage = 100;
3334 else if (temp >= 3981)
3335 noisepercentage = 93;
3336 else if (temp >= 3162)
3337 noisepercentage = 86;
3338 else if (temp >= 2512)
3339 noisepercentage = 79;
3340 else if (temp >= 1995)
3341 noisepercentage = 72;
3342 else if (temp >= 1585)
3343 noisepercentage = 65;
3344 else if (temp >= 1259)
3345 noisepercentage = 58;
3346 else if (temp >= 1000)
3347 noisepercentage = 50;
3348 else if (temp >= 794)
3349 noisepercentage = 43;
3350 else if (temp >= 501)
3351 noisepercentage = 36;
3352 else if (temp >= 316)
3353 noisepercentage = 29;
3354 else if (temp >= 200)
3355 noisepercentage = 22;
3356 else if (temp >= 158)
3357 noisepercentage = 14;
3358 else if (temp >= 126)
3359 noisepercentage = 7;
3360 else
3361 noisepercentage = 0;
3362
3363 dprintk("%s: noisepercentage=%d\n", __func__, noisepercentage);
3364
3365 *snr = (noisepercentage * 65535) / 100;
3366
3367 return 0;
3368}
3369
3370static int stv0367cab_read_ucblcks(struct dvb_frontend *fe, u32 *ucblocks)
3371{
3372 struct stv0367_state *state = fe->demodulator_priv;
3373 int corrected, tscount;
3374
3375 *ucblocks = (stv0367_readreg(state, R367CAB_RS_COUNTER_5) << 8)
3376 | stv0367_readreg(state, R367CAB_RS_COUNTER_4);
3377 corrected = (stv0367_readreg(state, R367CAB_RS_COUNTER_3) << 8)
3378 | stv0367_readreg(state, R367CAB_RS_COUNTER_2);
3379 tscount = (stv0367_readreg(state, R367CAB_RS_COUNTER_2) << 8)
3380 | stv0367_readreg(state, R367CAB_RS_COUNTER_1);
3381
3382 dprintk("%s: uncorrected blocks=%d corrected blocks=%d tscount=%d\n",
3383 __func__, *ucblocks, corrected, tscount);
3384
3385 return 0;
3386};
3387
3388static struct dvb_frontend_ops stv0367cab_ops = {
3389 .info = {
3390 .name = "ST STV0367 DVB-C",
3391 .type = FE_QAM,
3392 .frequency_min = 47000000,
3393 .frequency_max = 862000000,
3394 .frequency_stepsize = 62500,
3395 .symbol_rate_min = 870000,
3396 .symbol_rate_max = 11700000,
3397 .caps = 0x400 |/* FE_CAN_QAM_4 */
3398 FE_CAN_QAM_16 | FE_CAN_QAM_32 |
3399 FE_CAN_QAM_64 | FE_CAN_QAM_128 |
3400 FE_CAN_QAM_256 | FE_CAN_FEC_AUTO
3401 },
3402 .release = stv0367_release,
3403 .init = stv0367cab_init,
3404 .sleep = stv0367cab_sleep,
3405 .i2c_gate_ctrl = stv0367cab_gate_ctrl,
3406 .set_frontend = stv0367cab_set_frontend,
3407 .get_frontend = stv0367cab_get_frontend,
3408 .read_status = stv0367cab_read_status,
3409/* .read_ber = stv0367cab_read_ber, */
3410 .read_signal_strength = stv0367cab_read_strength,
3411 .read_snr = stv0367cab_read_snr,
3412 .read_ucblocks = stv0367cab_read_ucblcks,
3413 .get_tune_settings = stv0367_get_tune_settings,
3414};
3415
3416struct dvb_frontend *stv0367cab_attach(const struct stv0367_config *config,
3417 struct i2c_adapter *i2c)
3418{
3419 struct stv0367_state *state = NULL;
3420 struct stv0367cab_state *cab_state = NULL;
3421
3422 /* allocate memory for the internal state */
3423 state = kzalloc(sizeof(struct stv0367_state), GFP_KERNEL);
3424 if (state == NULL)
3425 goto error;
3426 cab_state = kzalloc(sizeof(struct stv0367cab_state), GFP_KERNEL);
3427 if (cab_state == NULL)
3428 goto error;
3429
3430 /* setup the state */
3431 state->i2c = i2c;
3432 state->config = config;
3433 cab_state->search_range = 280000;
3434 state->cab_state = cab_state;
3435 state->fe.ops = stv0367cab_ops;
3436 state->fe.demodulator_priv = state;
3437 state->chip_id = stv0367_readreg(state, 0xf000);
3438
3439 dprintk("%s: chip_id = 0x%x\n", __func__, state->chip_id);
3440
3441 /* check if the demod is there */
3442 if ((state->chip_id != 0x50) && (state->chip_id != 0x60))
3443 goto error;
3444
3445 return &state->fe;
3446
3447error:
3448 kfree(cab_state);
3449 kfree(state);
3450 return NULL;
3451}
3452EXPORT_SYMBOL(stv0367cab_attach);
3453
3454MODULE_PARM_DESC(debug, "Set debug");
3455MODULE_PARM_DESC(i2c_debug, "Set i2c debug");
3456
3457MODULE_AUTHOR("Igor M. Liplianin");
3458MODULE_DESCRIPTION("ST STV0367 DVB-C/T demodulator driver");
3459MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/stv0367.h b/drivers/media/dvb/frontends/stv0367.h
new file mode 100644
index 000000000000..93cc4a57eea0
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0367.h
@@ -0,0 +1,66 @@
1/*
2 * stv0367.h
3 *
4 * Driver for ST STV0367 DVB-T & DVB-C demodulator IC.
5 *
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2010,2011 NetUP Inc.
8 * Copyright (C) 2010,2011 Igor M. Liplianin <liplianin@netup.ru>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#ifndef STV0367_H
27#define STV0367_H
28
29#include <linux/dvb/frontend.h>
30#include "dvb_frontend.h"
31
32struct stv0367_config {
33 u8 demod_address;
34 u32 xtal;
35 u32 if_khz;/*4500*/
36 int if_iq_mode;
37 int ts_mode;
38 int clk_pol;
39};
40
41#if defined(CONFIG_DVB_STV0367) || (defined(CONFIG_DVB_STV0367_MODULE) \
42 && defined(MODULE))
43extern struct
44dvb_frontend *stv0367ter_attach(const struct stv0367_config *config,
45 struct i2c_adapter *i2c);
46extern struct
47dvb_frontend *stv0367cab_attach(const struct stv0367_config *config,
48 struct i2c_adapter *i2c);
49#else
50static inline struct
51dvb_frontend *stv0367ter_attach(const struct stv0367_config *config,
52 struct i2c_adapter *i2c)
53{
54 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
55 return NULL;
56}
57static inline struct
58dvb_frontend *stv0367cab_attach(const struct stv0367_config *config,
59 struct i2c_adapter *i2c)
60{
61 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
62 return NULL;
63}
64#endif
65
66#endif
diff --git a/drivers/media/dvb/frontends/stv0367_priv.h b/drivers/media/dvb/frontends/stv0367_priv.h
new file mode 100644
index 000000000000..995db0689ddd
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0367_priv.h
@@ -0,0 +1,212 @@
1/*
2 * stv0367_priv.h
3 *
4 * Driver for ST STV0367 DVB-T & DVB-C demodulator IC.
5 *
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2010,2011 NetUP Inc.
8 * Copyright (C) 2010,2011 Igor M. Liplianin <liplianin@netup.ru>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25/* Common driver error constants */
26
27#ifndef STV0367_PRIV_H
28#define STV0367_PRIV_H
29
30#ifndef TRUE
31 #define TRUE (1 == 1)
32#endif
33#ifndef FALSE
34 #define FALSE (!TRUE)
35#endif
36
37#ifndef NULL
38#define NULL 0
39#endif
40
41/* MACRO definitions */
42#define ABS(X) ((X) < 0 ? (-1 * (X)) : (X))
43#define MAX(X, Y) ((X) >= (Y) ? (X) : (Y))
44#define MIN(X, Y) ((X) <= (Y) ? (X) : (Y))
45#define INRANGE(X, Y, Z) \
46 ((((X) <= (Y)) && ((Y) <= (Z))) || \
47 (((Z) <= (Y)) && ((Y) <= (X))) ? 1 : 0)
48
49#ifndef MAKEWORD
50#define MAKEWORD(X, Y) (((X) << 8) + (Y))
51#endif
52
53#define LSB(X) (((X) & 0xff))
54#define MSB(Y) (((Y) >> 8) & 0xff)
55#define MMSB(Y)(((Y) >> 16) & 0xff)
56
57enum stv0367_ter_signal_type {
58 FE_TER_NOAGC = 0,
59 FE_TER_AGCOK = 5,
60 FE_TER_NOTPS = 6,
61 FE_TER_TPSOK = 7,
62 FE_TER_NOSYMBOL = 8,
63 FE_TER_BAD_CPQ = 9,
64 FE_TER_PRFOUNDOK = 10,
65 FE_TER_NOPRFOUND = 11,
66 FE_TER_LOCKOK = 12,
67 FE_TER_NOLOCK = 13,
68 FE_TER_SYMBOLOK = 15,
69 FE_TER_CPAMPOK = 16,
70 FE_TER_NOCPAMP = 17,
71 FE_TER_SWNOK = 18
72};
73
74enum stv0367_ts_mode {
75 STV0367_OUTPUTMODE_DEFAULT,
76 STV0367_SERIAL_PUNCT_CLOCK,
77 STV0367_SERIAL_CONT_CLOCK,
78 STV0367_PARALLEL_PUNCT_CLOCK,
79 STV0367_DVBCI_CLOCK
80};
81
82enum stv0367_clk_pol {
83 STV0367_CLOCKPOLARITY_DEFAULT,
84 STV0367_RISINGEDGE_CLOCK,
85 STV0367_FALLINGEDGE_CLOCK
86};
87
88enum stv0367_ter_bw {
89 FE_TER_CHAN_BW_6M = 6,
90 FE_TER_CHAN_BW_7M = 7,
91 FE_TER_CHAN_BW_8M = 8
92};
93
94#if 0
95enum FE_TER_Rate_TPS {
96 FE_TER_TPS_1_2 = 0,
97 FE_TER_TPS_2_3 = 1,
98 FE_TER_TPS_3_4 = 2,
99 FE_TER_TPS_5_6 = 3,
100 FE_TER_TPS_7_8 = 4
101};
102#endif
103
104enum stv0367_ter_mode {
105 FE_TER_MODE_2K,
106 FE_TER_MODE_8K,
107 FE_TER_MODE_4K
108};
109#if 0
110enum FE_TER_Hierarchy_Alpha {
111 FE_TER_HIER_ALPHA_NONE, /* Regular modulation */
112 FE_TER_HIER_ALPHA_1, /* Hierarchical modulation a = 1*/
113 FE_TER_HIER_ALPHA_2, /* Hierarchical modulation a = 2*/
114 FE_TER_HIER_ALPHA_4 /* Hierarchical modulation a = 4*/
115};
116#endif
117enum stv0367_ter_hierarchy {
118 FE_TER_HIER_NONE, /*Hierarchy None*/
119 FE_TER_HIER_LOW_PRIO, /*Hierarchy : Low Priority*/
120 FE_TER_HIER_HIGH_PRIO, /*Hierarchy : High Priority*/
121 FE_TER_HIER_PRIO_ANY /*Hierarchy :Any*/
122};
123
124#if 0
125enum fe_stv0367_ter_spec {
126 FE_TER_INVERSION_NONE = 0,
127 FE_TER_INVERSION = 1,
128 FE_TER_INVERSION_AUTO = 2,
129 FE_TER_INVERSION_UNK = 4
130};
131#endif
132
133enum stv0367_ter_if_iq_mode {
134 FE_TER_NORMAL_IF_TUNER = 0,
135 FE_TER_LONGPATH_IF_TUNER = 1,
136 FE_TER_IQ_TUNER = 2
137
138};
139
140#if 0
141enum FE_TER_FECRate {
142 FE_TER_FEC_NONE = 0x00, /* no FEC rate specified */
143 FE_TER_FEC_ALL = 0xFF, /* Logical OR of all FECs */
144 FE_TER_FEC_1_2 = 1,
145 FE_TER_FEC_2_3 = (1 << 1),
146 FE_TER_FEC_3_4 = (1 << 2),
147 FE_TER_FEC_4_5 = (1 << 3),
148 FE_TER_FEC_5_6 = (1 << 4),
149 FE_TER_FEC_6_7 = (1 << 5),
150 FE_TER_FEC_7_8 = (1 << 6),
151 FE_TER_FEC_8_9 = (1 << 7)
152};
153
154enum FE_TER_Rate {
155 FE_TER_FE_1_2 = 0,
156 FE_TER_FE_2_3 = 1,
157 FE_TER_FE_3_4 = 2,
158 FE_TER_FE_5_6 = 3,
159 FE_TER_FE_6_7 = 4,
160 FE_TER_FE_7_8 = 5
161};
162#endif
163
164enum stv0367_ter_force {
165 FE_TER_FORCENONE = 0,
166 FE_TER_FORCE_M_G = 1
167};
168
169enum stv0367cab_mod {
170 FE_CAB_MOD_QAM4,
171 FE_CAB_MOD_QAM16,
172 FE_CAB_MOD_QAM32,
173 FE_CAB_MOD_QAM64,
174 FE_CAB_MOD_QAM128,
175 FE_CAB_MOD_QAM256,
176 FE_CAB_MOD_QAM512,
177 FE_CAB_MOD_QAM1024
178};
179#if 0
180enum {
181 FE_CAB_FEC_A = 1, /* J83 Annex A */
182 FE_CAB_FEC_B = (1 << 1),/* J83 Annex B */
183 FE_CAB_FEC_C = (1 << 2) /* J83 Annex C */
184} FE_CAB_FECType_t;
185#endif
186struct stv0367_cab_signal_info {
187 int locked;
188 u32 frequency; /* kHz */
189 u32 symbol_rate; /* Mbds */
190 enum stv0367cab_mod modulation;
191 fe_spectral_inversion_t spect_inv;
192 s32 Power_dBmx10; /* Power of the RF signal (dBm x 10) */
193 u32 CN_dBx10; /* Carrier to noise ratio (dB x 10) */
194 u32 BER; /* Bit error rate (x 10000000) */
195};
196
197enum stv0367_cab_signal_type {
198 FE_CAB_NOTUNER,
199 FE_CAB_NOAGC,
200 FE_CAB_NOSIGNAL,
201 FE_CAB_NOTIMING,
202 FE_CAB_TIMINGOK,
203 FE_CAB_NOCARRIER,
204 FE_CAB_CARRIEROK,
205 FE_CAB_NOBLIND,
206 FE_CAB_BLINDOK,
207 FE_CAB_NODEMOD,
208 FE_CAB_DEMODOK,
209 FE_CAB_DATAOK
210};
211
212#endif
diff --git a/drivers/media/dvb/frontends/stv0367_regs.h b/drivers/media/dvb/frontends/stv0367_regs.h
new file mode 100644
index 000000000000..a96fbdc7e25e
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0367_regs.h
@@ -0,0 +1,3614 @@
1/*
2 * stv0367_regs.h
3 *
4 * Driver for ST STV0367 DVB-T & DVB-C demodulator IC.
5 *
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2010,2011 NetUP Inc.
8 * Copyright (C) 2010,2011 Igor M. Liplianin <liplianin@netup.ru>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#ifndef STV0367_REGS_H
27#define STV0367_REGS_H
28
29/* ID */
30#define R367TER_ID 0xf000
31#define F367TER_IDENTIFICATIONREG 0xf00000ff
32
33/* I2CRPT */
34#define R367TER_I2CRPT 0xf001
35#define F367TER_I2CT_ON 0xf0010080
36#define F367TER_ENARPT_LEVEL 0xf0010070
37#define F367TER_SCLT_DELAY 0xf0010008
38#define F367TER_SCLT_NOD 0xf0010004
39#define F367TER_STOP_ENABLE 0xf0010002
40#define F367TER_SDAT_NOD 0xf0010001
41
42/* TOPCTRL */
43#define R367TER_TOPCTRL 0xf002
44#define F367TER_STDBY 0xf0020080
45#define F367TER_STDBY_FEC 0xf0020040
46#define F367TER_STDBY_CORE 0xf0020020
47#define F367TER_QAM_COFDM 0xf0020010
48#define F367TER_TS_DIS 0xf0020008
49#define F367TER_DIR_CLK_216 0xf0020004
50#define F367TER_TUNER_BB 0xf0020002
51#define F367TER_DVBT_H 0xf0020001
52
53/* IOCFG0 */
54#define R367TER_IOCFG0 0xf003
55#define F367TER_OP0_SD 0xf0030080
56#define F367TER_OP0_VAL 0xf0030040
57#define F367TER_OP0_OD 0xf0030020
58#define F367TER_OP0_INV 0xf0030010
59#define F367TER_OP0_DACVALUE_HI 0xf003000f
60
61/* DAc0R */
62#define R367TER_DAC0R 0xf004
63#define F367TER_OP0_DACVALUE_LO 0xf00400ff
64
65/* IOCFG1 */
66#define R367TER_IOCFG1 0xf005
67#define F367TER_IP0 0xf0050040
68#define F367TER_OP1_OD 0xf0050020
69#define F367TER_OP1_INV 0xf0050010
70#define F367TER_OP1_DACVALUE_HI 0xf005000f
71
72/* DAC1R */
73#define R367TER_DAC1R 0xf006
74#define F367TER_OP1_DACVALUE_LO 0xf00600ff
75
76/* IOCFG2 */
77#define R367TER_IOCFG2 0xf007
78#define F367TER_OP2_LOCK_CONF 0xf00700e0
79#define F367TER_OP2_OD 0xf0070010
80#define F367TER_OP2_VAL 0xf0070008
81#define F367TER_OP1_LOCK_CONF 0xf0070007
82
83/* SDFR */
84#define R367TER_SDFR 0xf008
85#define F367TER_OP0_FREQ 0xf00800f0
86#define F367TER_OP1_FREQ 0xf008000f
87
88/* STATUS */
89#define R367TER_STATUS 0xf009
90#define F367TER_TPS_LOCK 0xf0090080
91#define F367TER_SYR_LOCK 0xf0090040
92#define F367TER_AGC_LOCK 0xf0090020
93#define F367TER_PRF 0xf0090010
94#define F367TER_LK 0xf0090008
95#define F367TER_PR 0xf0090007
96
97/* AUX_CLK */
98#define R367TER_AUX_CLK 0xf00a
99#define F367TER_AUXFEC_CTL 0xf00a00c0
100#define F367TER_DIS_CKX4 0xf00a0020
101#define F367TER_CKSEL 0xf00a0018
102#define F367TER_CKDIV_PROG 0xf00a0006
103#define F367TER_AUXCLK_ENA 0xf00a0001
104
105/* FREESYS1 */
106#define R367TER_FREESYS1 0xf00b
107#define F367TER_FREE_SYS1 0xf00b00ff
108
109/* FREESYS2 */
110#define R367TER_FREESYS2 0xf00c
111#define F367TER_FREE_SYS2 0xf00c00ff
112
113/* FREESYS3 */
114#define R367TER_FREESYS3 0xf00d
115#define F367TER_FREE_SYS3 0xf00d00ff
116
117/* GPIO_CFG */
118#define R367TER_GPIO_CFG 0xf00e
119#define F367TER_GPIO7_NOD 0xf00e0080
120#define F367TER_GPIO7_CFG 0xf00e0040
121#define F367TER_GPIO6_NOD 0xf00e0020
122#define F367TER_GPIO6_CFG 0xf00e0010
123#define F367TER_GPIO5_NOD 0xf00e0008
124#define F367TER_GPIO5_CFG 0xf00e0004
125#define F367TER_GPIO4_NOD 0xf00e0002
126#define F367TER_GPIO4_CFG 0xf00e0001
127
128/* GPIO_CMD */
129#define R367TER_GPIO_CMD 0xf00f
130#define F367TER_GPIO7_VAL 0xf00f0008
131#define F367TER_GPIO6_VAL 0xf00f0004
132#define F367TER_GPIO5_VAL 0xf00f0002
133#define F367TER_GPIO4_VAL 0xf00f0001
134
135/* AGC2MAX */
136#define R367TER_AGC2MAX 0xf010
137#define F367TER_AGC2_MAX 0xf01000ff
138
139/* AGC2MIN */
140#define R367TER_AGC2MIN 0xf011
141#define F367TER_AGC2_MIN 0xf01100ff
142
143/* AGC1MAX */
144#define R367TER_AGC1MAX 0xf012
145#define F367TER_AGC1_MAX 0xf01200ff
146
147/* AGC1MIN */
148#define R367TER_AGC1MIN 0xf013
149#define F367TER_AGC1_MIN 0xf01300ff
150
151/* AGCR */
152#define R367TER_AGCR 0xf014
153#define F367TER_RATIO_A 0xf01400e0
154#define F367TER_RATIO_B 0xf0140018
155#define F367TER_RATIO_C 0xf0140007
156
157/* AGC2TH */
158#define R367TER_AGC2TH 0xf015
159#define F367TER_AGC2_THRES 0xf01500ff
160
161/* AGC12c */
162#define R367TER_AGC12C 0xf016
163#define F367TER_AGC1_IV 0xf0160080
164#define F367TER_AGC1_OD 0xf0160040
165#define F367TER_AGC1_LOAD 0xf0160020
166#define F367TER_AGC2_IV 0xf0160010
167#define F367TER_AGC2_OD 0xf0160008
168#define F367TER_AGC2_LOAD 0xf0160004
169#define F367TER_AGC12_MODE 0xf0160003
170
171/* AGCCTRL1 */
172#define R367TER_AGCCTRL1 0xf017
173#define F367TER_DAGC_ON 0xf0170080
174#define F367TER_INVERT_AGC12 0xf0170040
175#define F367TER_AGC1_MODE 0xf0170008
176#define F367TER_AGC2_MODE 0xf0170007
177
178/* AGCCTRL2 */
179#define R367TER_AGCCTRL2 0xf018
180#define F367TER_FRZ2_CTRL 0xf0180060
181#define F367TER_FRZ1_CTRL 0xf0180018
182#define F367TER_TIME_CST 0xf0180007
183
184/* AGC1VAL1 */
185#define R367TER_AGC1VAL1 0xf019
186#define F367TER_AGC1_VAL_LO 0xf01900ff
187
188/* AGC1VAL2 */
189#define R367TER_AGC1VAL2 0xf01a
190#define F367TER_AGC1_VAL_HI 0xf01a000f
191
192/* AGC2VAL1 */
193#define R367TER_AGC2VAL1 0xf01b
194#define F367TER_AGC2_VAL_LO 0xf01b00ff
195
196/* AGC2VAL2 */
197#define R367TER_AGC2VAL2 0xf01c
198#define F367TER_AGC2_VAL_HI 0xf01c000f
199
200/* AGC2PGA */
201#define R367TER_AGC2PGA 0xf01d
202#define F367TER_AGC2_PGA 0xf01d00ff
203
204/* OVF_RATE1 */
205#define R367TER_OVF_RATE1 0xf01e
206#define F367TER_OVF_RATE_HI 0xf01e000f
207
208/* OVF_RATE2 */
209#define R367TER_OVF_RATE2 0xf01f
210#define F367TER_OVF_RATE_LO 0xf01f00ff
211
212/* GAIN_SRC1 */
213#define R367TER_GAIN_SRC1 0xf020
214#define F367TER_INV_SPECTR 0xf0200080
215#define F367TER_IQ_INVERT 0xf0200040
216#define F367TER_INR_BYPASS 0xf0200020
217#define F367TER_STATUS_INV_SPECRUM 0xf0200010
218#define F367TER_GAIN_SRC_HI 0xf020000f
219
220/* GAIN_SRC2 */
221#define R367TER_GAIN_SRC2 0xf021
222#define F367TER_GAIN_SRC_LO 0xf02100ff
223
224/* INC_DEROT1 */
225#define R367TER_INC_DEROT1 0xf022
226#define F367TER_INC_DEROT_HI 0xf02200ff
227
228/* INC_DEROT2 */
229#define R367TER_INC_DEROT2 0xf023
230#define F367TER_INC_DEROT_LO 0xf02300ff
231
232/* PPM_CPAMP_DIR */
233#define R367TER_PPM_CPAMP_DIR 0xf024
234#define F367TER_PPM_CPAMP_DIRECT 0xf02400ff
235
236/* PPM_CPAMP_INV */
237#define R367TER_PPM_CPAMP_INV 0xf025
238#define F367TER_PPM_CPAMP_INVER 0xf02500ff
239
240/* FREESTFE_1 */
241#define R367TER_FREESTFE_1 0xf026
242#define F367TER_SYMBOL_NUMBER_INC 0xf02600c0
243#define F367TER_SEL_LSB 0xf0260004
244#define F367TER_AVERAGE_ON 0xf0260002
245#define F367TER_DC_ADJ 0xf0260001
246
247/* FREESTFE_2 */
248#define R367TER_FREESTFE_2 0xf027
249#define F367TER_SEL_SRCOUT 0xf02700c0
250#define F367TER_SEL_SYRTHR 0xf027001f
251
252/* DCOFFSET */
253#define R367TER_DCOFFSET 0xf028
254#define F367TER_SELECT_I_Q 0xf0280080
255#define F367TER_DC_OFFSET 0xf028007f
256
257/* EN_PROCESS */
258#define R367TER_EN_PROCESS 0xf029
259#define F367TER_FREE 0xf02900f0
260#define F367TER_ENAB_MANUAL 0xf0290001
261
262/* SDI_SMOOTHER */
263#define R367TER_SDI_SMOOTHER 0xf02a
264#define F367TER_DIS_SMOOTH 0xf02a0080
265#define F367TER_SDI_INC_SMOOTHER 0xf02a007f
266
267/* FE_LOOP_OPEN */
268#define R367TER_FE_LOOP_OPEN 0xf02b
269#define F367TER_TRL_LOOP_OP 0xf02b0002
270#define F367TER_CRL_LOOP_OP 0xf02b0001
271
272/* FREQOFF1 */
273#define R367TER_FREQOFF1 0xf02c
274#define F367TER_FREQ_OFFSET_LOOP_OPEN_VHI 0xf02c00ff
275
276/* FREQOFF2 */
277#define R367TER_FREQOFF2 0xf02d
278#define F367TER_FREQ_OFFSET_LOOP_OPEN_HI 0xf02d00ff
279
280/* FREQOFF3 */
281#define R367TER_FREQOFF3 0xf02e
282#define F367TER_FREQ_OFFSET_LOOP_OPEN_LO 0xf02e00ff
283
284/* TIMOFF1 */
285#define R367TER_TIMOFF1 0xf02f
286#define F367TER_TIM_OFFSET_LOOP_OPEN_HI 0xf02f00ff
287
288/* TIMOFF2 */
289#define R367TER_TIMOFF2 0xf030
290#define F367TER_TIM_OFFSET_LOOP_OPEN_LO 0xf03000ff
291
292/* EPQ */
293#define R367TER_EPQ 0xf031
294#define F367TER_EPQ1 0xf03100ff
295
296/* EPQAUTO */
297#define R367TER_EPQAUTO 0xf032
298#define F367TER_EPQ2 0xf03200ff
299
300/* SYR_UPDATE */
301#define R367TER_SYR_UPDATE 0xf033
302#define F367TER_SYR_PROTV 0xf0330080
303#define F367TER_SYR_PROTV_GAIN 0xf0330060
304#define F367TER_SYR_FILTER 0xf0330010
305#define F367TER_SYR_TRACK_THRES 0xf033000c
306
307/* CHPFREE */
308#define R367TER_CHPFREE 0xf034
309#define F367TER_CHP_FREE 0xf03400ff
310
311/* PPM_STATE_MAC */
312#define R367TER_PPM_STATE_MAC 0xf035
313#define F367TER_PPM_STATE_MACHINE_DECODER 0xf035003f
314
315/* INR_THRESHOLD */
316#define R367TER_INR_THRESHOLD 0xf036
317#define F367TER_INR_THRESH 0xf03600ff
318
319/* EPQ_TPS_ID_CELL */
320#define R367TER_EPQ_TPS_ID_CELL 0xf037
321#define F367TER_ENABLE_LGTH_TO_CF 0xf0370080
322#define F367TER_DIS_TPS_RSVD 0xf0370040
323#define F367TER_DIS_BCH 0xf0370020
324#define F367TER_DIS_ID_CEL 0xf0370010
325#define F367TER_TPS_ADJUST_SYM 0xf037000f
326
327/* EPQ_CFG */
328#define R367TER_EPQ_CFG 0xf038
329#define F367TER_EPQ_RANGE 0xf0380002
330#define F367TER_EPQ_SOFT 0xf0380001
331
332/* EPQ_STATUS */
333#define R367TER_EPQ_STATUS 0xf039
334#define F367TER_SLOPE_INC 0xf03900fc
335#define F367TER_TPS_FIELD 0xf0390003
336
337/* AUTORELOCK */
338#define R367TER_AUTORELOCK 0xf03a
339#define F367TER_BYPASS_BER_TEMPO 0xf03a0080
340#define F367TER_BER_TEMPO 0xf03a0070
341#define F367TER_BYPASS_COFDM_TEMPO 0xf03a0008
342#define F367TER_COFDM_TEMPO 0xf03a0007
343
344/* BER_THR_VMSB */
345#define R367TER_BER_THR_VMSB 0xf03b
346#define F367TER_BER_THRESHOLD_HI 0xf03b00ff
347
348/* BER_THR_MSB */
349#define R367TER_BER_THR_MSB 0xf03c
350#define F367TER_BER_THRESHOLD_MID 0xf03c00ff
351
352/* BER_THR_LSB */
353#define R367TER_BER_THR_LSB 0xf03d
354#define F367TER_BER_THRESHOLD_LO 0xf03d00ff
355
356/* CCD */
357#define R367TER_CCD 0xf03e
358#define F367TER_CCD_DETECTED 0xf03e0080
359#define F367TER_CCD_RESET 0xf03e0040
360#define F367TER_CCD_THRESHOLD 0xf03e000f
361
362/* SPECTR_CFG */
363#define R367TER_SPECTR_CFG 0xf03f
364#define F367TER_SPECT_CFG 0xf03f0003
365
366/* CONSTMU_MSB */
367#define R367TER_CONSTMU_MSB 0xf040
368#define F367TER_CONSTMU_FREEZE 0xf0400080
369#define F367TER_CONSTNU_FORCE_EN 0xf0400040
370#define F367TER_CONST_MU_MSB 0xf040003f
371
372/* CONSTMU_LSB */
373#define R367TER_CONSTMU_LSB 0xf041
374#define F367TER_CONST_MU_LSB 0xf04100ff
375
376/* CONSTMU_MAX_MSB */
377#define R367TER_CONSTMU_MAX_MSB 0xf042
378#define F367TER_CONST_MU_MAX_MSB 0xf042003f
379
380/* CONSTMU_MAX_LSB */
381#define R367TER_CONSTMU_MAX_LSB 0xf043
382#define F367TER_CONST_MU_MAX_LSB 0xf04300ff
383
384/* ALPHANOISE */
385#define R367TER_ALPHANOISE 0xf044
386#define F367TER_USE_ALLFILTER 0xf0440080
387#define F367TER_INTER_ON 0xf0440040
388#define F367TER_ALPHA_NOISE 0xf044001f
389
390/* MAXGP_MSB */
391#define R367TER_MAXGP_MSB 0xf045
392#define F367TER_MUFILTER_LENGTH 0xf04500f0
393#define F367TER_MAX_GP_MSB 0xf045000f
394
395/* MAXGP_LSB */
396#define R367TER_MAXGP_LSB 0xf046
397#define F367TER_MAX_GP_LSB 0xf04600ff
398
399/* ALPHAMSB */
400#define R367TER_ALPHAMSB 0xf047
401#define F367TER_CHC_DATARATE 0xf04700c0
402#define F367TER_ALPHA_MSB 0xf047003f
403
404/* ALPHALSB */
405#define R367TER_ALPHALSB 0xf048
406#define F367TER_ALPHA_LSB 0xf04800ff
407
408/* PILOT_ACCU */
409#define R367TER_PILOT_ACCU 0xf049
410#define F367TER_USE_SCAT4ADDAPT 0xf0490080
411#define F367TER_PILOT_ACC 0xf049001f
412
413/* PILOTMU_ACCU */
414#define R367TER_PILOTMU_ACCU 0xf04a
415#define F367TER_DISCARD_BAD_SP 0xf04a0080
416#define F367TER_DISCARD_BAD_CP 0xf04a0040
417#define F367TER_PILOT_MU_ACCU 0xf04a001f
418
419/* FILT_CHANNEL_EST */
420#define R367TER_FILT_CHANNEL_EST 0xf04b
421#define F367TER_USE_FILT_PILOT 0xf04b0080
422#define F367TER_FILT_CHANNEL 0xf04b007f
423
424/* ALPHA_NOPISE_FREQ */
425#define R367TER_ALPHA_NOPISE_FREQ 0xf04c
426#define F367TER_NOISE_FREQ_FILT 0xf04c0040
427#define F367TER_ALPHA_NOISE_FREQ 0xf04c003f
428
429/* RATIO_PILOT */
430#define R367TER_RATIO_PILOT 0xf04d
431#define F367TER_RATIO_MEAN_SP 0xf04d00f0
432#define F367TER_RATIO_MEAN_CP 0xf04d000f
433
434/* CHC_CTL */
435#define R367TER_CHC_CTL 0xf04e
436#define F367TER_TRACK_EN 0xf04e0080
437#define F367TER_NOISE_NORM_EN 0xf04e0040
438#define F367TER_FORCE_CHC_RESET 0xf04e0020
439#define F367TER_SHORT_TIME 0xf04e0010
440#define F367TER_FORCE_STATE_EN 0xf04e0008
441#define F367TER_FORCE_STATE 0xf04e0007
442
443/* EPQ_ADJUST */
444#define R367TER_EPQ_ADJUST 0xf04f
445#define F367TER_ADJUST_SCAT_IND 0xf04f00c0
446#define F367TER_ONE_SYMBOL 0xf04f0010
447#define F367TER_EPQ_DECAY 0xf04f000e
448#define F367TER_HOLD_SLOPE 0xf04f0001
449
450/* EPQ_THRES */
451#define R367TER_EPQ_THRES 0xf050
452#define F367TER_EPQ_THR 0xf05000ff
453
454/* OMEGA_CTL */
455#define R367TER_OMEGA_CTL 0xf051
456#define F367TER_OMEGA_RST 0xf0510080
457#define F367TER_FREEZE_OMEGA 0xf0510040
458#define F367TER_OMEGA_SEL 0xf051003f
459
460/* GP_CTL */
461#define R367TER_GP_CTL 0xf052
462#define F367TER_CHC_STATE 0xf05200e0
463#define F367TER_FREEZE_GP 0xf0520010
464#define F367TER_GP_SEL 0xf052000f
465
466/* MUMSB */
467#define R367TER_MUMSB 0xf053
468#define F367TER_MU_MSB 0xf053007f
469
470/* MULSB */
471#define R367TER_MULSB 0xf054
472#define F367TER_MU_LSB 0xf05400ff
473
474/* GPMSB */
475#define R367TER_GPMSB 0xf055
476#define F367TER_CSI_THRESHOLD 0xf05500e0
477#define F367TER_GP_MSB 0xf055000f
478
479/* GPLSB */
480#define R367TER_GPLSB 0xf056
481#define F367TER_GP_LSB 0xf05600ff
482
483/* OMEGAMSB */
484#define R367TER_OMEGAMSB 0xf057
485#define F367TER_OMEGA_MSB 0xf057007f
486
487/* OMEGALSB */
488#define R367TER_OMEGALSB 0xf058
489#define F367TER_OMEGA_LSB 0xf05800ff
490
491/* SCAT_NB */
492#define R367TER_SCAT_NB 0xf059
493#define F367TER_CHC_TEST 0xf05900f8
494#define F367TER_SCAT_NUMB 0xf0590003
495
496/* CHC_DUMMY */
497#define R367TER_CHC_DUMMY 0xf05a
498#define F367TER_CHC_DUM 0xf05a00ff
499
500/* INC_CTL */
501#define R367TER_INC_CTL 0xf05b
502#define F367TER_INC_BYPASS 0xf05b0080
503#define F367TER_INC_NDEPTH 0xf05b000c
504#define F367TER_INC_MADEPTH 0xf05b0003
505
506/* INCTHRES_COR1 */
507#define R367TER_INCTHRES_COR1 0xf05c
508#define F367TER_INC_THRES_COR1 0xf05c00ff
509
510/* INCTHRES_COR2 */
511#define R367TER_INCTHRES_COR2 0xf05d
512#define F367TER_INC_THRES_COR2 0xf05d00ff
513
514/* INCTHRES_DET1 */
515#define R367TER_INCTHRES_DET1 0xf05e
516#define F367TER_INC_THRES_DET1 0xf05e003f
517
518/* INCTHRES_DET2 */
519#define R367TER_INCTHRES_DET2 0xf05f
520#define F367TER_INC_THRES_DET2 0xf05f003f
521
522/* IIR_CELLNB */
523#define R367TER_IIR_CELLNB 0xf060
524#define F367TER_NRST_IIR 0xf0600080
525#define F367TER_IIR_CELL_NB 0xf0600007
526
527/* IIRCX_COEFF1_MSB */
528#define R367TER_IIRCX_COEFF1_MSB 0xf061
529#define F367TER_IIR_CX_COEFF1_MSB 0xf06100ff
530
531/* IIRCX_COEFF1_LSB */
532#define R367TER_IIRCX_COEFF1_LSB 0xf062
533#define F367TER_IIR_CX_COEFF1_LSB 0xf06200ff
534
535/* IIRCX_COEFF2_MSB */
536#define R367TER_IIRCX_COEFF2_MSB 0xf063
537#define F367TER_IIR_CX_COEFF2_MSB 0xf06300ff
538
539/* IIRCX_COEFF2_LSB */
540#define R367TER_IIRCX_COEFF2_LSB 0xf064
541#define F367TER_IIR_CX_COEFF2_LSB 0xf06400ff
542
543/* IIRCX_COEFF3_MSB */
544#define R367TER_IIRCX_COEFF3_MSB 0xf065
545#define F367TER_IIR_CX_COEFF3_MSB 0xf06500ff
546
547/* IIRCX_COEFF3_LSB */
548#define R367TER_IIRCX_COEFF3_LSB 0xf066
549#define F367TER_IIR_CX_COEFF3_LSB 0xf06600ff
550
551/* IIRCX_COEFF4_MSB */
552#define R367TER_IIRCX_COEFF4_MSB 0xf067
553#define F367TER_IIR_CX_COEFF4_MSB 0xf06700ff
554
555/* IIRCX_COEFF4_LSB */
556#define R367TER_IIRCX_COEFF4_LSB 0xf068
557#define F367TER_IIR_CX_COEFF4_LSB 0xf06800ff
558
559/* IIRCX_COEFF5_MSB */
560#define R367TER_IIRCX_COEFF5_MSB 0xf069
561#define F367TER_IIR_CX_COEFF5_MSB 0xf06900ff
562
563/* IIRCX_COEFF5_LSB */
564#define R367TER_IIRCX_COEFF5_LSB 0xf06a
565#define F367TER_IIR_CX_COEFF5_LSB 0xf06a00ff
566
567/* FEPATH_CFG */
568#define R367TER_FEPATH_CFG 0xf06b
569#define F367TER_DEMUX_SWAP 0xf06b0004
570#define F367TER_DIGAGC_SWAP 0xf06b0002
571#define F367TER_LONGPATH_IF 0xf06b0001
572
573/* PMC1_FUNC */
574#define R367TER_PMC1_FUNC 0xf06c
575#define F367TER_SOFT_RSTN 0xf06c0080
576#define F367TER_PMC1_AVERAGE_TIME 0xf06c0078
577#define F367TER_PMC1_WAIT_TIME 0xf06c0006
578#define F367TER_PMC1_2N_SEL 0xf06c0001
579
580/* PMC1_FOR */
581#define R367TER_PMC1_FOR 0xf06d
582#define F367TER_PMC1_FORCE 0xf06d0080
583#define F367TER_PMC1_FORCE_VALUE 0xf06d007c
584
585/* PMC2_FUNC */
586#define R367TER_PMC2_FUNC 0xf06e
587#define F367TER_PMC2_SOFT_STN 0xf06e0080
588#define F367TER_PMC2_ACCU_TIME 0xf06e0070
589#define F367TER_PMC2_CMDP_MN 0xf06e0008
590#define F367TER_PMC2_SWAP 0xf06e0004
591
592/* STATUS_ERR_DA */
593#define R367TER_STATUS_ERR_DA 0xf06f
594#define F367TER_COM_USEGAINTRK 0xf06f0080
595#define F367TER_COM_AGCLOCK 0xf06f0040
596#define F367TER_AUT_AGCLOCK 0xf06f0020
597#define F367TER_MIN_ERR_X_LSB 0xf06f000f
598
599/* DIG_AGC_R */
600#define R367TER_DIG_AGC_R 0xf070
601#define F367TER_COM_SOFT_RSTN 0xf0700080
602#define F367TER_COM_AGC_ON 0xf0700040
603#define F367TER_COM_EARLY 0xf0700020
604#define F367TER_AUT_SOFT_RESETN 0xf0700010
605#define F367TER_AUT_AGC_ON 0xf0700008
606#define F367TER_AUT_EARLY 0xf0700004
607#define F367TER_AUT_ROT_EN 0xf0700002
608#define F367TER_LOCK_SOFT_RESETN 0xf0700001
609
610/* COMAGC_TARMSB */
611#define R367TER_COMAGC_TARMSB 0xf071
612#define F367TER_COM_AGC_TARGET_MSB 0xf07100ff
613
614/* COM_AGC_TAR_ENMODE */
615#define R367TER_COM_AGC_TAR_ENMODE 0xf072
616#define F367TER_COM_AGC_TARGET_LSB 0xf07200f0
617#define F367TER_COM_ENMODE 0xf072000f
618
619/* COM_AGC_CFG */
620#define R367TER_COM_AGC_CFG 0xf073
621#define F367TER_COM_N 0xf07300f8
622#define F367TER_COM_STABMODE 0xf0730006
623#define F367TER_ERR_SEL 0xf0730001
624
625/* COM_AGC_GAIN1 */
626#define R367TER_COM_AGC_GAIN1 0xf074
627#define F367TER_COM_GAIN1aCK 0xf07400f0
628#define F367TER_COM_GAIN1TRK 0xf074000f
629
630/* AUT_AGC_TARGETMSB */
631#define R367TER_AUT_AGC_TARGETMSB 0xf075
632#define F367TER_AUT_AGC_TARGET_MSB 0xf07500ff
633
634/* LOCK_DET_MSB */
635#define R367TER_LOCK_DET_MSB 0xf076
636#define F367TER_LOCK_DETECT_MSB 0xf07600ff
637
638/* AGCTAR_LOCK_LSBS */
639#define R367TER_AGCTAR_LOCK_LSBS 0xf077
640#define F367TER_AUT_AGC_TARGET_LSB 0xf07700f0
641#define F367TER_LOCK_DETECT_LSB 0xf077000f
642
643/* AUT_GAIN_EN */
644#define R367TER_AUT_GAIN_EN 0xf078
645#define F367TER_AUT_ENMODE 0xf07800f0
646#define F367TER_AUT_GAIN2 0xf078000f
647
648/* AUT_CFG */
649#define R367TER_AUT_CFG 0xf079
650#define F367TER_AUT_N 0xf07900f8
651#define F367TER_INT_CHOICE 0xf0790006
652#define F367TER_INT_LOAD 0xf0790001
653
654/* LOCKN */
655#define R367TER_LOCKN 0xf07a
656#define F367TER_LOCK_N 0xf07a00f8
657#define F367TER_SEL_IQNTAR 0xf07a0004
658#define F367TER_LOCK_DETECT_CHOICE 0xf07a0003
659
660/* INT_X_3 */
661#define R367TER_INT_X_3 0xf07b
662#define F367TER_INT_X3 0xf07b00ff
663
664/* INT_X_2 */
665#define R367TER_INT_X_2 0xf07c
666#define F367TER_INT_X2 0xf07c00ff
667
668/* INT_X_1 */
669#define R367TER_INT_X_1 0xf07d
670#define F367TER_INT_X1 0xf07d00ff
671
672/* INT_X_0 */
673#define R367TER_INT_X_0 0xf07e
674#define F367TER_INT_X0 0xf07e00ff
675
676/* MIN_ERRX_MSB */
677#define R367TER_MIN_ERRX_MSB 0xf07f
678#define F367TER_MIN_ERR_X_MSB 0xf07f00ff
679
680/* COR_CTL */
681#define R367TER_COR_CTL 0xf080
682#define F367TER_CORE_ACTIVE 0xf0800020
683#define F367TER_HOLD 0xf0800010
684#define F367TER_CORE_STATE_CTL 0xf080000f
685
686/* COR_STAT */
687#define R367TER_COR_STAT 0xf081
688#define F367TER_SCATT_LOCKED 0xf0810080
689#define F367TER_TPS_LOCKED 0xf0810040
690#define F367TER_SYR_LOCKED_COR 0xf0810020
691#define F367TER_AGC_LOCKED_STAT 0xf0810010
692#define F367TER_CORE_STATE_STAT 0xf081000f
693
694/* COR_INTEN */
695#define R367TER_COR_INTEN 0xf082
696#define F367TER_INTEN 0xf0820080
697#define F367TER_INTEN_SYR 0xf0820020
698#define F367TER_INTEN_FFT 0xf0820010
699#define F367TER_INTEN_AGC 0xf0820008
700#define F367TER_INTEN_TPS1 0xf0820004
701#define F367TER_INTEN_TPS2 0xf0820002
702#define F367TER_INTEN_TPS3 0xf0820001
703
704/* COR_INTSTAT */
705#define R367TER_COR_INTSTAT 0xf083
706#define F367TER_INTSTAT_SYR 0xf0830020
707#define F367TER_INTSTAT_FFT 0xf0830010
708#define F367TER_INTSAT_AGC 0xf0830008
709#define F367TER_INTSTAT_TPS1 0xf0830004
710#define F367TER_INTSTAT_TPS2 0xf0830002
711#define F367TER_INTSTAT_TPS3 0xf0830001
712
713/* COR_MODEGUARD */
714#define R367TER_COR_MODEGUARD 0xf084
715#define F367TER_FORCE 0xf0840010
716#define F367TER_MODE 0xf084000c
717#define F367TER_GUARD 0xf0840003
718
719/* AGC_CTL */
720#define R367TER_AGC_CTL 0xf085
721#define F367TER_AGC_TIMING_FACTOR 0xf08500e0
722#define F367TER_AGC_LAST 0xf0850010
723#define F367TER_AGC_GAIN 0xf085000c
724#define F367TER_AGC_NEG 0xf0850002
725#define F367TER_AGC_SET 0xf0850001
726
727/* AGC_MANUAL1 */
728#define R367TER_AGC_MANUAL1 0xf086
729#define F367TER_AGC_VAL_LO 0xf08600ff
730
731/* AGC_MANUAL2 */
732#define R367TER_AGC_MANUAL2 0xf087
733#define F367TER_AGC_VAL_HI 0xf087000f
734
735/* AGC_TARG */
736#define R367TER_AGC_TARG 0xf088
737#define F367TER_AGC_TARGET 0xf08800ff
738
739/* AGC_GAIN1 */
740#define R367TER_AGC_GAIN1 0xf089
741#define F367TER_AGC_GAIN_LO 0xf08900ff
742
743/* AGC_GAIN2 */
744#define R367TER_AGC_GAIN2 0xf08a
745#define F367TER_AGC_LOCKED_GAIN2 0xf08a0010
746#define F367TER_AGC_GAIN_HI 0xf08a000f
747
748/* RESERVED_1 */
749#define R367TER_RESERVED_1 0xf08b
750#define F367TER_RESERVED1 0xf08b00ff
751
752/* RESERVED_2 */
753#define R367TER_RESERVED_2 0xf08c
754#define F367TER_RESERVED2 0xf08c00ff
755
756/* RESERVED_3 */
757#define R367TER_RESERVED_3 0xf08d
758#define F367TER_RESERVED3 0xf08d00ff
759
760/* CAS_CTL */
761#define R367TER_CAS_CTL 0xf08e
762#define F367TER_CCS_ENABLE 0xf08e0080
763#define F367TER_ACS_DISABLE 0xf08e0040
764#define F367TER_DAGC_DIS 0xf08e0020
765#define F367TER_DAGC_GAIN 0xf08e0018
766#define F367TER_CCSMU 0xf08e0007
767
768/* CAS_FREQ */
769#define R367TER_CAS_FREQ 0xf08f
770#define F367TER_CCS_FREQ 0xf08f00ff
771
772/* CAS_DAGCGAIN */
773#define R367TER_CAS_DAGCGAIN 0xf090
774#define F367TER_CAS_DAGC_GAIN 0xf09000ff
775
776/* SYR_CTL */
777#define R367TER_SYR_CTL 0xf091
778#define F367TER_SICTH_ENABLE 0xf0910080
779#define F367TER_LONG_ECHO 0xf0910078
780#define F367TER_AUTO_LE_EN 0xf0910004
781#define F367TER_SYR_BYPASS 0xf0910002
782#define F367TER_SYR_TR_DIS 0xf0910001
783
784/* SYR_STAT */
785#define R367TER_SYR_STAT 0xf092
786#define F367TER_SYR_LOCKED_STAT 0xf0920010
787#define F367TER_SYR_MODE 0xf092000c
788#define F367TER_SYR_GUARD 0xf0920003
789
790/* SYR_NCO1 */
791#define R367TER_SYR_NCO1 0xf093
792#define F367TER_SYR_NCO_LO 0xf09300ff
793
794/* SYR_NCO2 */
795#define R367TER_SYR_NCO2 0xf094
796#define F367TER_SYR_NCO_HI 0xf094003f
797
798/* SYR_OFFSET1 */
799#define R367TER_SYR_OFFSET1 0xf095
800#define F367TER_SYR_OFFSET_LO 0xf09500ff
801
802/* SYR_OFFSET2 */
803#define R367TER_SYR_OFFSET2 0xf096
804#define F367TER_SYR_OFFSET_HI 0xf096003f
805
806/* FFT_CTL */
807#define R367TER_FFT_CTL 0xf097
808#define F367TER_SHIFT_FFT_TRIG 0xf0970018
809#define F367TER_FFT_TRIGGER 0xf0970004
810#define F367TER_FFT_MANUAL 0xf0970002
811#define F367TER_IFFT_MODE 0xf0970001
812
813/* SCR_CTL */
814#define R367TER_SCR_CTL 0xf098
815#define F367TER_SYRADJDECAY 0xf0980070
816#define F367TER_SCR_CPEDIS 0xf0980002
817#define F367TER_SCR_DIS 0xf0980001
818
819/* PPM_CTL1 */
820#define R367TER_PPM_CTL1 0xf099
821#define F367TER_PPM_MAXFREQ 0xf0990030
822#define F367TER_PPM_MAXTIM 0xf0990008
823#define F367TER_PPM_INVSEL 0xf0990004
824#define F367TER_PPM_SCATDIS 0xf0990002
825#define F367TER_PPM_BYP 0xf0990001
826
827/* TRL_CTL */
828#define R367TER_TRL_CTL 0xf09a
829#define F367TER_TRL_NOMRATE_LSB 0xf09a0080
830#define F367TER_TRL_GAIN_FACTOR 0xf09a0078
831#define F367TER_TRL_LOOPGAIN 0xf09a0007
832
833/* TRL_NOMRATE1 */
834#define R367TER_TRL_NOMRATE1 0xf09b
835#define F367TER_TRL_NOMRATE_LO 0xf09b00ff
836
837/* TRL_NOMRATE2 */
838#define R367TER_TRL_NOMRATE2 0xf09c
839#define F367TER_TRL_NOMRATE_HI 0xf09c00ff
840
841/* TRL_TIME1 */
842#define R367TER_TRL_TIME1 0xf09d
843#define F367TER_TRL_TOFFSET_LO 0xf09d00ff
844
845/* TRL_TIME2 */
846#define R367TER_TRL_TIME2 0xf09e
847#define F367TER_TRL_TOFFSET_HI 0xf09e00ff
848
849/* CRL_CTL */
850#define R367TER_CRL_CTL 0xf09f
851#define F367TER_CRL_DIS 0xf09f0080
852#define F367TER_CRL_GAIN_FACTOR 0xf09f0078
853#define F367TER_CRL_LOOPGAIN 0xf09f0007
854
855/* CRL_FREQ1 */
856#define R367TER_CRL_FREQ1 0xf0a0
857#define F367TER_CRL_FOFFSET_LO 0xf0a000ff
858
859/* CRL_FREQ2 */
860#define R367TER_CRL_FREQ2 0xf0a1
861#define F367TER_CRL_FOFFSET_HI 0xf0a100ff
862
863/* CRL_FREQ3 */
864#define R367TER_CRL_FREQ3 0xf0a2
865#define F367TER_CRL_FOFFSET_VHI 0xf0a200ff
866
867/* TPS_SFRAME_CTL */
868#define R367TER_TPS_SFRAME_CTL 0xf0a3
869#define F367TER_TPS_SFRAME_SYNC 0xf0a30001
870
871/* CHC_SNR */
872#define R367TER_CHC_SNR 0xf0a4
873#define F367TER_CHCSNR 0xf0a400ff
874
875/* BDI_CTL */
876#define R367TER_BDI_CTL 0xf0a5
877#define F367TER_BDI_LPSEL 0xf0a50002
878#define F367TER_BDI_SERIAL 0xf0a50001
879
880/* DMP_CTL */
881#define R367TER_DMP_CTL 0xf0a6
882#define F367TER_DMP_SCALING_FACTOR 0xf0a6001e
883#define F367TER_DMP_SDDIS 0xf0a60001
884
885/* TPS_RCVD1 */
886#define R367TER_TPS_RCVD1 0xf0a7
887#define F367TER_TPS_CHANGE 0xf0a70040
888#define F367TER_BCH_OK 0xf0a70020
889#define F367TER_TPS_SYNC 0xf0a70010
890#define F367TER_TPS_FRAME 0xf0a70003
891
892/* TPS_RCVD2 */
893#define R367TER_TPS_RCVD2 0xf0a8
894#define F367TER_TPS_HIERMODE 0xf0a80070
895#define F367TER_TPS_CONST 0xf0a80003
896
897/* TPS_RCVD3 */
898#define R367TER_TPS_RCVD3 0xf0a9
899#define F367TER_TPS_LPCODE 0xf0a90070
900#define F367TER_TPS_HPCODE 0xf0a90007
901
902/* TPS_RCVD4 */
903#define R367TER_TPS_RCVD4 0xf0aa
904#define F367TER_TPS_GUARD 0xf0aa0030
905#define F367TER_TPS_MODE 0xf0aa0003
906
907/* TPS_ID_CELL1 */
908#define R367TER_TPS_ID_CELL1 0xf0ab
909#define F367TER_TPS_ID_CELL_LO 0xf0ab00ff
910
911/* TPS_ID_CELL2 */
912#define R367TER_TPS_ID_CELL2 0xf0ac
913#define F367TER_TPS_ID_CELL_HI 0xf0ac00ff
914
915/* TPS_RCVD5_SET1 */
916#define R367TER_TPS_RCVD5_SET1 0xf0ad
917#define F367TER_TPS_NA 0xf0ad00fC
918#define F367TER_TPS_SETFRAME 0xf0ad0003
919
920/* TPS_SET2 */
921#define R367TER_TPS_SET2 0xf0ae
922#define F367TER_TPS_SETHIERMODE 0xf0ae0070
923#define F367TER_TPS_SETCONST 0xf0ae0003
924
925/* TPS_SET3 */
926#define R367TER_TPS_SET3 0xf0af
927#define F367TER_TPS_SETLPCODE 0xf0af0070
928#define F367TER_TPS_SETHPCODE 0xf0af0007
929
930/* TPS_CTL */
931#define R367TER_TPS_CTL 0xf0b0
932#define F367TER_TPS_IMM 0xf0b00004
933#define F367TER_TPS_BCHDIS 0xf0b00002
934#define F367TER_TPS_UPDDIS 0xf0b00001
935
936/* CTL_FFTOSNUM */
937#define R367TER_CTL_FFTOSNUM 0xf0b1
938#define F367TER_SYMBOL_NUMBER 0xf0b1007f
939
940/* TESTSELECT */
941#define R367TER_TESTSELECT 0xf0b2
942#define F367TER_TEST_SELECT 0xf0b2001f
943
944/* MSC_REV */
945#define R367TER_MSC_REV 0xf0b3
946#define F367TER_REV_NUMBER 0xf0b300ff
947
948/* PIR_CTL */
949#define R367TER_PIR_CTL 0xf0b4
950#define F367TER_FREEZE 0xf0b40001
951
952/* SNR_CARRIER1 */
953#define R367TER_SNR_CARRIER1 0xf0b5
954#define F367TER_SNR_CARRIER_LO 0xf0b500ff
955
956/* SNR_CARRIER2 */
957#define R367TER_SNR_CARRIER2 0xf0b6
958#define F367TER_MEAN 0xf0b600c0
959#define F367TER_SNR_CARRIER_HI 0xf0b6001f
960
961/* PPM_CPAMP */
962#define R367TER_PPM_CPAMP 0xf0b7
963#define F367TER_PPM_CPC 0xf0b700ff
964
965/* TSM_AP0 */
966#define R367TER_TSM_AP0 0xf0b8
967#define F367TER_ADDRESS_BYTE_0 0xf0b800ff
968
969/* TSM_AP1 */
970#define R367TER_TSM_AP1 0xf0b9
971#define F367TER_ADDRESS_BYTE_1 0xf0b900ff
972
973/* TSM_AP2 */
974#define R367TER_TSM_AP2 0xf0bA
975#define F367TER_DATA_BYTE_0 0xf0ba00ff
976
977/* TSM_AP3 */
978#define R367TER_TSM_AP3 0xf0bB
979#define F367TER_DATA_BYTE_1 0xf0bb00ff
980
981/* TSM_AP4 */
982#define R367TER_TSM_AP4 0xf0bC
983#define F367TER_DATA_BYTE_2 0xf0bc00ff
984
985/* TSM_AP5 */
986#define R367TER_TSM_AP5 0xf0bD
987#define F367TER_DATA_BYTE_3 0xf0bd00ff
988
989/* TSM_AP6 */
990#define R367TER_TSM_AP6 0xf0bE
991#define F367TER_TSM_AP_6 0xf0be00ff
992
993/* TSM_AP7 */
994#define R367TER_TSM_AP7 0xf0bF
995#define F367TER_MEM_SELECT_BYTE 0xf0bf00ff
996
997/* TSTRES */
998#define R367TER_TSTRES 0xf0c0
999#define F367TER_FRES_DISPLAY 0xf0c00080
1000#define F367TER_FRES_FIFO_AD 0xf0c00020
1001#define F367TER_FRESRS 0xf0c00010
1002#define F367TER_FRESACS 0xf0c00008
1003#define F367TER_FRESFEC 0xf0c00004
1004#define F367TER_FRES_PRIF 0xf0c00002
1005#define F367TER_FRESCORE 0xf0c00001
1006
1007/* ANACTRL */
1008#define R367TER_ANACTRL 0xf0c1
1009#define F367TER_BYPASS_XTAL 0xf0c10040
1010#define F367TER_BYPASS_PLLXN 0xf0c1000c
1011#define F367TER_DIS_PAD_OSC 0xf0c10002
1012#define F367TER_STDBY_PLLXN 0xf0c10001
1013
1014/* TSTBUS */
1015#define R367TER_TSTBUS 0xf0c2
1016#define F367TER_TS_BYTE_CLK_INV 0xf0c20080
1017#define F367TER_CFG_IP 0xf0c20070
1018#define F367TER_CFG_TST 0xf0c2000f
1019
1020/* TSTRATE */
1021#define R367TER_TSTRATE 0xf0c6
1022#define F367TER_FORCEPHA 0xf0c60080
1023#define F367TER_FNEWPHA 0xf0c60010
1024#define F367TER_FROT90 0xf0c60008
1025#define F367TER_FR 0xf0c60007
1026
1027/* CONSTMODE */
1028#define R367TER_CONSTMODE 0xf0cb
1029#define F367TER_TST_PRIF 0xf0cb00e0
1030#define F367TER_CAR_TYPE 0xf0cb0018
1031#define F367TER_CONST_MODE 0xf0cb0003
1032
1033/* CONSTCARR1 */
1034#define R367TER_CONSTCARR1 0xf0cc
1035#define F367TER_CONST_CARR_LO 0xf0cc00ff
1036
1037/* CONSTCARR2 */
1038#define R367TER_CONSTCARR2 0xf0cd
1039#define F367TER_CONST_CARR_HI 0xf0cd001f
1040
1041/* ICONSTEL */
1042#define R367TER_ICONSTEL 0xf0ce
1043#define F367TER_PICONSTEL 0xf0ce00ff
1044
1045/* QCONSTEL */
1046#define R367TER_QCONSTEL 0xf0cf
1047#define F367TER_PQCONSTEL 0xf0cf00ff
1048
1049/* TSTBISTRES0 */
1050#define R367TER_TSTBISTRES0 0xf0d0
1051#define F367TER_BEND_PPM 0xf0d00080
1052#define F367TER_BBAD_PPM 0xf0d00040
1053#define F367TER_BEND_FFTW 0xf0d00020
1054#define F367TER_BBAD_FFTW 0xf0d00010
1055#define F367TER_BEND_FFT_BUF 0xf0d00008
1056#define F367TER_BBAD_FFT_BUF 0xf0d00004
1057#define F367TER_BEND_SYR 0xf0d00002
1058#define F367TER_BBAD_SYR 0xf0d00001
1059
1060/* TSTBISTRES1 */
1061#define R367TER_TSTBISTRES1 0xf0d1
1062#define F367TER_BEND_CHC_CP 0xf0d10080
1063#define F367TER_BBAD_CHC_CP 0xf0d10040
1064#define F367TER_BEND_CHCI 0xf0d10020
1065#define F367TER_BBAD_CHCI 0xf0d10010
1066#define F367TER_BEND_BDI 0xf0d10008
1067#define F367TER_BBAD_BDI 0xf0d10004
1068#define F367TER_BEND_SDI 0xf0d10002
1069#define F367TER_BBAD_SDI 0xf0d10001
1070
1071/* TSTBISTRES2 */
1072#define R367TER_TSTBISTRES2 0xf0d2
1073#define F367TER_BEND_CHC_INC 0xf0d20080
1074#define F367TER_BBAD_CHC_INC 0xf0d20040
1075#define F367TER_BEND_CHC_SPP 0xf0d20020
1076#define F367TER_BBAD_CHC_SPP 0xf0d20010
1077#define F367TER_BEND_CHC_CPP 0xf0d20008
1078#define F367TER_BBAD_CHC_CPP 0xf0d20004
1079#define F367TER_BEND_CHC_SP 0xf0d20002
1080#define F367TER_BBAD_CHC_SP 0xf0d20001
1081
1082/* TSTBISTRES3 */
1083#define R367TER_TSTBISTRES3 0xf0d3
1084#define F367TER_BEND_QAM 0xf0d30080
1085#define F367TER_BBAD_QAM 0xf0d30040
1086#define F367TER_BEND_SFEC_VIT 0xf0d30020
1087#define F367TER_BBAD_SFEC_VIT 0xf0d30010
1088#define F367TER_BEND_SFEC_DLINE 0xf0d30008
1089#define F367TER_BBAD_SFEC_DLINE 0xf0d30004
1090#define F367TER_BEND_SFEC_HW 0xf0d30002
1091#define F367TER_BBAD_SFEC_HW 0xf0d30001
1092
1093/* RF_AGC1 */
1094#define R367TER_RF_AGC1 0xf0d4
1095#define F367TER_RF_AGC1_LEVEL_HI 0xf0d400ff
1096
1097/* RF_AGC2 */
1098#define R367TER_RF_AGC2 0xf0d5
1099#define F367TER_REF_ADGP 0xf0d50080
1100#define F367TER_STDBY_ADCGP 0xf0d50020
1101#define F367TER_CHANNEL_SEL 0xf0d5001c
1102#define F367TER_RF_AGC1_LEVEL_LO 0xf0d50003
1103
1104/* ANADIGCTRL */
1105#define R367TER_ANADIGCTRL 0xf0d7
1106#define F367TER_SEL_CLKDEM 0xf0d70020
1107#define F367TER_EN_BUFFER_Q 0xf0d70010
1108#define F367TER_EN_BUFFER_I 0xf0d70008
1109#define F367TER_ADC_RIS_EGDE 0xf0d70004
1110#define F367TER_SGN_ADC 0xf0d70002
1111#define F367TER_SEL_AD12_SYNC 0xf0d70001
1112
1113/* PLLMDIV */
1114#define R367TER_PLLMDIV 0xf0d8
1115#define F367TER_PLL_MDIV 0xf0d800ff
1116
1117/* PLLNDIV */
1118#define R367TER_PLLNDIV 0xf0d9
1119#define F367TER_PLL_NDIV 0xf0d900ff
1120
1121/* PLLSETUP */
1122#define R367TER_PLLSETUP 0xf0dA
1123#define F367TER_PLL_PDIV 0xf0da0070
1124#define F367TER_PLL_KDIV 0xf0da000f
1125
1126/* DUAL_AD12 */
1127#define R367TER_DUAL_AD12 0xf0dB
1128#define F367TER_FS20M 0xf0db0020
1129#define F367TER_FS50M 0xf0db0010
1130#define F367TER_INMODe0 0xf0db0008
1131#define F367TER_POFFQ 0xf0db0004
1132#define F367TER_POFFI 0xf0db0002
1133#define F367TER_INMODE1 0xf0db0001
1134
1135/* TSTBIST */
1136#define R367TER_TSTBIST 0xf0dC
1137#define F367TER_TST_BYP_CLK 0xf0dc0080
1138#define F367TER_TST_GCLKENA_STD 0xf0dc0040
1139#define F367TER_TST_GCLKENA 0xf0dc0020
1140#define F367TER_TST_MEMBIST 0xf0dc001f
1141
1142/* PAD_COMP_CTRL */
1143#define R367TER_PAD_COMP_CTRL 0xf0dD
1144#define F367TER_COMPTQ 0xf0dd0010
1145#define F367TER_COMPEN 0xf0dd0008
1146#define F367TER_FREEZE2 0xf0dd0004
1147#define F367TER_SLEEP_INHBT 0xf0dd0002
1148#define F367TER_CHIP_SLEEP 0xf0dd0001
1149
1150/* PAD_COMP_WR */
1151#define R367TER_PAD_COMP_WR 0xf0de
1152#define F367TER_WR_ASRC 0xf0de007f
1153
1154/* PAD_COMP_RD */
1155#define R367TER_PAD_COMP_RD 0xf0df
1156#define F367TER_COMPOK 0xf0df0080
1157#define F367TER_RD_ASRC 0xf0df007f
1158
1159/* SYR_TARGET_FFTADJT_MSB */
1160#define R367TER_SYR_TARGET_FFTADJT_MSB 0xf100
1161#define F367TER_SYR_START 0xf1000080
1162#define F367TER_SYR_TARGET_FFTADJ_HI 0xf100000f
1163
1164/* SYR_TARGET_FFTADJT_LSB */
1165#define R367TER_SYR_TARGET_FFTADJT_LSB 0xf101
1166#define F367TER_SYR_TARGET_FFTADJ_LO 0xf10100ff
1167
1168/* SYR_TARGET_CHCADJT_MSB */
1169#define R367TER_SYR_TARGET_CHCADJT_MSB 0xf102
1170#define F367TER_SYR_TARGET_CHCADJ_HI 0xf102000f
1171
1172/* SYR_TARGET_CHCADJT_LSB */
1173#define R367TER_SYR_TARGET_CHCADJT_LSB 0xf103
1174#define F367TER_SYR_TARGET_CHCADJ_LO 0xf10300ff
1175
1176/* SYR_FLAG */
1177#define R367TER_SYR_FLAG 0xf104
1178#define F367TER_TRIG_FLG1 0xf1040080
1179#define F367TER_TRIG_FLG0 0xf1040040
1180#define F367TER_FFT_FLG1 0xf1040008
1181#define F367TER_FFT_FLG0 0xf1040004
1182#define F367TER_CHC_FLG1 0xf1040002
1183#define F367TER_CHC_FLG0 0xf1040001
1184
1185/* CRL_TARGET1 */
1186#define R367TER_CRL_TARGET1 0xf105
1187#define F367TER_CRL_START 0xf1050080
1188#define F367TER_CRL_TARGET_VHI 0xf105000f
1189
1190/* CRL_TARGET2 */
1191#define R367TER_CRL_TARGET2 0xf106
1192#define F367TER_CRL_TARGET_HI 0xf10600ff
1193
1194/* CRL_TARGET3 */
1195#define R367TER_CRL_TARGET3 0xf107
1196#define F367TER_CRL_TARGET_LO 0xf10700ff
1197
1198/* CRL_TARGET4 */
1199#define R367TER_CRL_TARGET4 0xf108
1200#define F367TER_CRL_TARGET_VLO 0xf10800ff
1201
1202/* CRL_FLAG */
1203#define R367TER_CRL_FLAG 0xf109
1204#define F367TER_CRL_FLAG1 0xf1090002
1205#define F367TER_CRL_FLAG0 0xf1090001
1206
1207/* TRL_TARGET1 */
1208#define R367TER_TRL_TARGET1 0xf10a
1209#define F367TER_TRL_TARGET_HI 0xf10a00ff
1210
1211/* TRL_TARGET2 */
1212#define R367TER_TRL_TARGET2 0xf10b
1213#define F367TER_TRL_TARGET_LO 0xf10b00ff
1214
1215/* TRL_CHC */
1216#define R367TER_TRL_CHC 0xf10c
1217#define F367TER_TRL_START 0xf10c0080
1218#define F367TER_CHC_START 0xf10c0040
1219#define F367TER_TRL_FLAG1 0xf10c0002
1220#define F367TER_TRL_FLAG0 0xf10c0001
1221
1222/* CHC_SNR_TARG */
1223#define R367TER_CHC_SNR_TARG 0xf10d
1224#define F367TER_CHC_SNR_TARGET 0xf10d00ff
1225
1226/* TOP_TRACK */
1227#define R367TER_TOP_TRACK 0xf10e
1228#define F367TER_TOP_START 0xf10e0080
1229#define F367TER_FIRST_FLAG 0xf10e0070
1230#define F367TER_TOP_FLAG1 0xf10e0008
1231#define F367TER_TOP_FLAG0 0xf10e0004
1232#define F367TER_CHC_FLAG1 0xf10e0002
1233#define F367TER_CHC_FLAG0 0xf10e0001
1234
1235/* TRACKER_FREE1 */
1236#define R367TER_TRACKER_FREE1 0xf10f
1237#define F367TER_TRACKER_FREE_1 0xf10f00ff
1238
1239/* ERROR_CRL1 */
1240#define R367TER_ERROR_CRL1 0xf110
1241#define F367TER_ERROR_CRL_VHI 0xf11000ff
1242
1243/* ERROR_CRL2 */
1244#define R367TER_ERROR_CRL2 0xf111
1245#define F367TER_ERROR_CRL_HI 0xf11100ff
1246
1247/* ERROR_CRL3 */
1248#define R367TER_ERROR_CRL3 0xf112
1249#define F367TER_ERROR_CRL_LOI 0xf11200ff
1250
1251/* ERROR_CRL4 */
1252#define R367TER_ERROR_CRL4 0xf113
1253#define F367TER_ERROR_CRL_VLO 0xf11300ff
1254
1255/* DEC_NCO1 */
1256#define R367TER_DEC_NCO1 0xf114
1257#define F367TER_DEC_NCO_VHI 0xf11400ff
1258
1259/* DEC_NCO2 */
1260#define R367TER_DEC_NCO2 0xf115
1261#define F367TER_DEC_NCO_HI 0xf11500ff
1262
1263/* DEC_NCO3 */
1264#define R367TER_DEC_NCO3 0xf116
1265#define F367TER_DEC_NCO_LO 0xf11600ff
1266
1267/* SNR */
1268#define R367TER_SNR 0xf117
1269#define F367TER_SNRATIO 0xf11700ff
1270
1271/* SYR_FFTADJ1 */
1272#define R367TER_SYR_FFTADJ1 0xf118
1273#define F367TER_SYR_FFTADJ_HI 0xf11800ff
1274
1275/* SYR_FFTADJ2 */
1276#define R367TER_SYR_FFTADJ2 0xf119
1277#define F367TER_SYR_FFTADJ_LO 0xf11900ff
1278
1279/* SYR_CHCADJ1 */
1280#define R367TER_SYR_CHCADJ1 0xf11a
1281#define F367TER_SYR_CHCADJ_HI 0xf11a00ff
1282
1283/* SYR_CHCADJ2 */
1284#define R367TER_SYR_CHCADJ2 0xf11b
1285#define F367TER_SYR_CHCADJ_LO 0xf11b00ff
1286
1287/* SYR_OFF */
1288#define R367TER_SYR_OFF 0xf11c
1289#define F367TER_SYR_OFFSET 0xf11c00ff
1290
1291/* PPM_OFFSET1 */
1292#define R367TER_PPM_OFFSET1 0xf11d
1293#define F367TER_PPM_OFFSET_HI 0xf11d00ff
1294
1295/* PPM_OFFSET2 */
1296#define R367TER_PPM_OFFSET2 0xf11e
1297#define F367TER_PPM_OFFSET_LO 0xf11e00ff
1298
1299/* TRACKER_FREE2 */
1300#define R367TER_TRACKER_FREE2 0xf11f
1301#define F367TER_TRACKER_FREE_2 0xf11f00ff
1302
1303/* DEBG_LT10 */
1304#define R367TER_DEBG_LT10 0xf120
1305#define F367TER_DEBUG_LT10 0xf12000ff
1306
1307/* DEBG_LT11 */
1308#define R367TER_DEBG_LT11 0xf121
1309#define F367TER_DEBUG_LT11 0xf12100ff
1310
1311/* DEBG_LT12 */
1312#define R367TER_DEBG_LT12 0xf122
1313#define F367TER_DEBUG_LT12 0xf12200ff
1314
1315/* DEBG_LT13 */
1316#define R367TER_DEBG_LT13 0xf123
1317#define F367TER_DEBUG_LT13 0xf12300ff
1318
1319/* DEBG_LT14 */
1320#define R367TER_DEBG_LT14 0xf124
1321#define F367TER_DEBUG_LT14 0xf12400ff
1322
1323/* DEBG_LT15 */
1324#define R367TER_DEBG_LT15 0xf125
1325#define F367TER_DEBUG_LT15 0xf12500ff
1326
1327/* DEBG_LT16 */
1328#define R367TER_DEBG_LT16 0xf126
1329#define F367TER_DEBUG_LT16 0xf12600ff
1330
1331/* DEBG_LT17 */
1332#define R367TER_DEBG_LT17 0xf127
1333#define F367TER_DEBUG_LT17 0xf12700ff
1334
1335/* DEBG_LT18 */
1336#define R367TER_DEBG_LT18 0xf128
1337#define F367TER_DEBUG_LT18 0xf12800ff
1338
1339/* DEBG_LT19 */
1340#define R367TER_DEBG_LT19 0xf129
1341#define F367TER_DEBUG_LT19 0xf12900ff
1342
1343/* DEBG_LT1a */
1344#define R367TER_DEBG_LT1A 0xf12a
1345#define F367TER_DEBUG_LT1A 0xf12a00ff
1346
1347/* DEBG_LT1b */
1348#define R367TER_DEBG_LT1B 0xf12b
1349#define F367TER_DEBUG_LT1B 0xf12b00ff
1350
1351/* DEBG_LT1c */
1352#define R367TER_DEBG_LT1C 0xf12c
1353#define F367TER_DEBUG_LT1C 0xf12c00ff
1354
1355/* DEBG_LT1D */
1356#define R367TER_DEBG_LT1D 0xf12d
1357#define F367TER_DEBUG_LT1D 0xf12d00ff
1358
1359/* DEBG_LT1E */
1360#define R367TER_DEBG_LT1E 0xf12e
1361#define F367TER_DEBUG_LT1E 0xf12e00ff
1362
1363/* DEBG_LT1F */
1364#define R367TER_DEBG_LT1F 0xf12f
1365#define F367TER_DEBUG_LT1F 0xf12f00ff
1366
1367/* RCCFGH */
1368#define R367TER_RCCFGH 0xf200
1369#define F367TER_TSRCFIFO_DVBCI 0xf2000080
1370#define F367TER_TSRCFIFO_SERIAL 0xf2000040
1371#define F367TER_TSRCFIFO_DISABLE 0xf2000020
1372#define F367TER_TSFIFO_2TORC 0xf2000010
1373#define F367TER_TSRCFIFO_HSGNLOUT 0xf2000008
1374#define F367TER_TSRCFIFO_ERRMODE 0xf2000006
1375#define F367TER_RCCFGH_0 0xf2000001
1376
1377/* RCCFGM */
1378#define R367TER_RCCFGM 0xf201
1379#define F367TER_TSRCFIFO_MANSPEED 0xf20100c0
1380#define F367TER_TSRCFIFO_PERMDATA 0xf2010020
1381#define F367TER_TSRCFIFO_NONEWSGNL 0xf2010010
1382#define F367TER_RCBYTE_OVERSAMPLING 0xf201000e
1383#define F367TER_TSRCFIFO_INVDATA 0xf2010001
1384
1385/* RCCFGL */
1386#define R367TER_RCCFGL 0xf202
1387#define F367TER_TSRCFIFO_BCLKDEL1cK 0xf20200c0
1388#define F367TER_RCCFGL_5 0xf2020020
1389#define F367TER_TSRCFIFO_DUTY50 0xf2020010
1390#define F367TER_TSRCFIFO_NSGNL2dATA 0xf2020008
1391#define F367TER_TSRCFIFO_DISSERMUX 0xf2020004
1392#define F367TER_RCCFGL_1 0xf2020002
1393#define F367TER_TSRCFIFO_STOPCKDIS 0xf2020001
1394
1395/* RCINSDELH */
1396#define R367TER_RCINSDELH 0xf203
1397#define F367TER_TSRCDEL_SYNCBYTE 0xf2030080
1398#define F367TER_TSRCDEL_XXHEADER 0xf2030040
1399#define F367TER_TSRCDEL_BBHEADER 0xf2030020
1400#define F367TER_TSRCDEL_DATAFIELD 0xf2030010
1401#define F367TER_TSRCINSDEL_ISCR 0xf2030008
1402#define F367TER_TSRCINSDEL_NPD 0xf2030004
1403#define F367TER_TSRCINSDEL_RSPARITY 0xf2030002
1404#define F367TER_TSRCINSDEL_CRC8 0xf2030001
1405
1406/* RCINSDELM */
1407#define R367TER_RCINSDELM 0xf204
1408#define F367TER_TSRCINS_BBPADDING 0xf2040080
1409#define F367TER_TSRCINS_BCHFEC 0xf2040040
1410#define F367TER_TSRCINS_LDPCFEC 0xf2040020
1411#define F367TER_TSRCINS_EMODCOD 0xf2040010
1412#define F367TER_TSRCINS_TOKEN 0xf2040008
1413#define F367TER_TSRCINS_XXXERR 0xf2040004
1414#define F367TER_TSRCINS_MATYPE 0xf2040002
1415#define F367TER_TSRCINS_UPL 0xf2040001
1416
1417/* RCINSDELL */
1418#define R367TER_RCINSDELL 0xf205
1419#define F367TER_TSRCINS_DFL 0xf2050080
1420#define F367TER_TSRCINS_SYNCD 0xf2050040
1421#define F367TER_TSRCINS_BLOCLEN 0xf2050020
1422#define F367TER_TSRCINS_SIGPCOUNT 0xf2050010
1423#define F367TER_TSRCINS_FIFO 0xf2050008
1424#define F367TER_TSRCINS_REALPACK 0xf2050004
1425#define F367TER_TSRCINS_TSCONFIG 0xf2050002
1426#define F367TER_TSRCINS_LATENCY 0xf2050001
1427
1428/* RCSTATUS */
1429#define R367TER_RCSTATUS 0xf206
1430#define F367TER_TSRCFIFO_LINEOK 0xf2060080
1431#define F367TER_TSRCFIFO_ERROR 0xf2060040
1432#define F367TER_TSRCFIFO_DATA7 0xf2060020
1433#define F367TER_RCSTATUS_4 0xf2060010
1434#define F367TER_TSRCFIFO_DEMODSEL 0xf2060008
1435#define F367TER_TSRC1FIFOSPEED_STORE 0xf2060004
1436#define F367TER_RCSTATUS_1 0xf2060002
1437#define F367TER_TSRCSERIAL_IMPOSSIBLE 0xf2060001
1438
1439/* RCSPEED */
1440#define R367TER_RCSPEED 0xf207
1441#define F367TER_TSRCFIFO_OUTSPEED 0xf20700ff
1442
1443/* RCDEBUGM */
1444#define R367TER_RCDEBUGM 0xf208
1445#define F367TER_SD_UNSYNC 0xf2080080
1446#define F367TER_ULFLOCK_DETECTM 0xf2080040
1447#define F367TER_SUL_SELECTOS 0xf2080020
1448#define F367TER_DILUL_NOSCRBLE 0xf2080010
1449#define F367TER_NUL_SCRB 0xf2080008
1450#define F367TER_UL_SCRB 0xf2080004
1451#define F367TER_SCRAULBAD 0xf2080002
1452#define F367TER_SCRAUL_UNSYNC 0xf2080001
1453
1454/* RCDEBUGL */
1455#define R367TER_RCDEBUGL 0xf209
1456#define F367TER_RS_ERR 0xf2090080
1457#define F367TER_LLFLOCK_DETECTM 0xf2090040
1458#define F367TER_NOT_SUL_SELECTOS 0xf2090020
1459#define F367TER_DILLL_NOSCRBLE 0xf2090010
1460#define F367TER_NLL_SCRB 0xf2090008
1461#define F367TER_LL_SCRB 0xf2090004
1462#define F367TER_SCRALLBAD 0xf2090002
1463#define F367TER_SCRALL_UNSYNC 0xf2090001
1464
1465/* RCOBSCFG */
1466#define R367TER_RCOBSCFG 0xf20a
1467#define F367TER_TSRCFIFO_OBSCFG 0xf20a00ff
1468
1469/* RCOBSM */
1470#define R367TER_RCOBSM 0xf20b
1471#define F367TER_TSRCFIFO_OBSDATA_HI 0xf20b00ff
1472
1473/* RCOBSL */
1474#define R367TER_RCOBSL 0xf20c
1475#define F367TER_TSRCFIFO_OBSDATA_LO 0xf20c00ff
1476
1477/* RCFECSPY */
1478#define R367TER_RCFECSPY 0xf210
1479#define F367TER_SPYRC_ENABLE 0xf2100080
1480#define F367TER_RCNO_SYNCBYTE 0xf2100040
1481#define F367TER_RCSERIAL_MODE 0xf2100020
1482#define F367TER_RCUNUSUAL_PACKET 0xf2100010
1483#define F367TER_BERRCMETER_DATAMODE 0xf210000c
1484#define F367TER_BERRCMETER_LMODE 0xf2100002
1485#define F367TER_BERRCMETER_RESET 0xf2100001
1486
1487/* RCFSPYCFG */
1488#define R367TER_RCFSPYCFG 0xf211
1489#define F367TER_FECSPYRC_INPUT 0xf21100c0
1490#define F367TER_RCRST_ON_ERROR 0xf2110020
1491#define F367TER_RCONE_SHOT 0xf2110010
1492#define F367TER_RCI2C_MODE 0xf211000c
1493#define F367TER_SPYRC_HSTERESIS 0xf2110003
1494
1495/* RCFSPYDATA */
1496#define R367TER_RCFSPYDATA 0xf212
1497#define F367TER_SPYRC_STUFFING 0xf2120080
1498#define F367TER_RCNOERR_PKTJITTER 0xf2120040
1499#define F367TER_SPYRC_CNULLPKT 0xf2120020
1500#define F367TER_SPYRC_OUTDATA_MODE 0xf212001f
1501
1502/* RCFSPYOUT */
1503#define R367TER_RCFSPYOUT 0xf213
1504#define F367TER_FSPYRC_DIRECT 0xf2130080
1505#define F367TER_RCFSPYOUT_6 0xf2130040
1506#define F367TER_SPYRC_OUTDATA_BUS 0xf2130038
1507#define F367TER_RCSTUFF_MODE 0xf2130007
1508
1509/* RCFSTATUS */
1510#define R367TER_RCFSTATUS 0xf214
1511#define F367TER_SPYRC_ENDSIM 0xf2140080
1512#define F367TER_RCVALID_SIM 0xf2140040
1513#define F367TER_RCFOUND_SIGNAL 0xf2140020
1514#define F367TER_RCDSS_SYNCBYTE 0xf2140010
1515#define F367TER_RCRESULT_STATE 0xf214000f
1516
1517/* RCFGOODPACK */
1518#define R367TER_RCFGOODPACK 0xf215
1519#define F367TER_RCGOOD_PACKET 0xf21500ff
1520
1521/* RCFPACKCNT */
1522#define R367TER_RCFPACKCNT 0xf216
1523#define F367TER_RCPACKET_COUNTER 0xf21600ff
1524
1525/* RCFSPYMISC */
1526#define R367TER_RCFSPYMISC 0xf217
1527#define F367TER_RCLABEL_COUNTER 0xf21700ff
1528
1529/* RCFBERCPT4 */
1530#define R367TER_RCFBERCPT4 0xf218
1531#define F367TER_FBERRCMETER_CPT_MMMMSB 0xf21800ff
1532
1533/* RCFBERCPT3 */
1534#define R367TER_RCFBERCPT3 0xf219
1535#define F367TER_FBERRCMETER_CPT_MMMSB 0xf21900ff
1536
1537/* RCFBERCPT2 */
1538#define R367TER_RCFBERCPT2 0xf21a
1539#define F367TER_FBERRCMETER_CPT_MMSB 0xf21a00ff
1540
1541/* RCFBERCPT1 */
1542#define R367TER_RCFBERCPT1 0xf21b
1543#define F367TER_FBERRCMETER_CPT_MSB 0xf21b00ff
1544
1545/* RCFBERCPT0 */
1546#define R367TER_RCFBERCPT0 0xf21c
1547#define F367TER_FBERRCMETER_CPT_LSB 0xf21c00ff
1548
1549/* RCFBERERR2 */
1550#define R367TER_RCFBERERR2 0xf21d
1551#define F367TER_FBERRCMETER_ERR_HI 0xf21d00ff
1552
1553/* RCFBERERR1 */
1554#define R367TER_RCFBERERR1 0xf21e
1555#define F367TER_FBERRCMETER_ERR 0xf21e00ff
1556
1557/* RCFBERERR0 */
1558#define R367TER_RCFBERERR0 0xf21f
1559#define F367TER_FBERRCMETER_ERR_LO 0xf21f00ff
1560
1561/* RCFSTATESM */
1562#define R367TER_RCFSTATESM 0xf220
1563#define F367TER_RCRSTATE_F 0xf2200080
1564#define F367TER_RCRSTATE_E 0xf2200040
1565#define F367TER_RCRSTATE_D 0xf2200020
1566#define F367TER_RCRSTATE_C 0xf2200010
1567#define F367TER_RCRSTATE_B 0xf2200008
1568#define F367TER_RCRSTATE_A 0xf2200004
1569#define F367TER_RCRSTATE_9 0xf2200002
1570#define F367TER_RCRSTATE_8 0xf2200001
1571
1572/* RCFSTATESL */
1573#define R367TER_RCFSTATESL 0xf221
1574#define F367TER_RCRSTATE_7 0xf2210080
1575#define F367TER_RCRSTATE_6 0xf2210040
1576#define F367TER_RCRSTATE_5 0xf2210020
1577#define F367TER_RCRSTATE_4 0xf2210010
1578#define F367TER_RCRSTATE_3 0xf2210008
1579#define F367TER_RCRSTATE_2 0xf2210004
1580#define F367TER_RCRSTATE_1 0xf2210002
1581#define F367TER_RCRSTATE_0 0xf2210001
1582
1583/* RCFSPYBER */
1584#define R367TER_RCFSPYBER 0xf222
1585#define F367TER_RCFSPYBER_7 0xf2220080
1586#define F367TER_SPYRCOBS_XORREAD 0xf2220040
1587#define F367TER_FSPYRCBER_OBSMODE 0xf2220020
1588#define F367TER_FSPYRCBER_SYNCBYT 0xf2220010
1589#define F367TER_FSPYRCBER_UNSYNC 0xf2220008
1590#define F367TER_FSPYRCBER_CTIME 0xf2220007
1591
1592/* RCFSPYDISTM */
1593#define R367TER_RCFSPYDISTM 0xf223
1594#define F367TER_RCPKTTIME_DISTANCE_HI 0xf22300ff
1595
1596/* RCFSPYDISTL */
1597#define R367TER_RCFSPYDISTL 0xf224
1598#define F367TER_RCPKTTIME_DISTANCE_LO 0xf22400ff
1599
1600/* RCFSPYOBS7 */
1601#define R367TER_RCFSPYOBS7 0xf228
1602#define F367TER_RCSPYOBS_SPYFAIL 0xf2280080
1603#define F367TER_RCSPYOBS_SPYFAIL1 0xf2280040
1604#define F367TER_RCSPYOBS_ERROR 0xf2280020
1605#define F367TER_RCSPYOBS_STROUT 0xf2280010
1606#define F367TER_RCSPYOBS_RESULTSTATE1 0xf228000f
1607
1608/* RCFSPYOBS6 */
1609#define R367TER_RCFSPYOBS6 0xf229
1610#define F367TER_RCSPYOBS_RESULTSTATe0 0xf22900f0
1611#define F367TER_RCSPYOBS_RESULTSTATEM1 0xf229000f
1612
1613/* RCFSPYOBS5 */
1614#define R367TER_RCFSPYOBS5 0xf22a
1615#define F367TER_RCSPYOBS_BYTEOFPACKET1 0xf22a00ff
1616
1617/* RCFSPYOBS4 */
1618#define R367TER_RCFSPYOBS4 0xf22b
1619#define F367TER_RCSPYOBS_BYTEVALUE1 0xf22b00ff
1620
1621/* RCFSPYOBS3 */
1622#define R367TER_RCFSPYOBS3 0xf22c
1623#define F367TER_RCSPYOBS_DATA1 0xf22c00ff
1624
1625/* RCFSPYOBS2 */
1626#define R367TER_RCFSPYOBS2 0xf22d
1627#define F367TER_RCSPYOBS_DATa0 0xf22d00ff
1628
1629/* RCFSPYOBS1 */
1630#define R367TER_RCFSPYOBS1 0xf22e
1631#define F367TER_RCSPYOBS_DATAM1 0xf22e00ff
1632
1633/* RCFSPYOBS0 */
1634#define R367TER_RCFSPYOBS0 0xf22f
1635#define F367TER_RCSPYOBS_DATAM2 0xf22f00ff
1636
1637/* TSGENERAL */
1638#define R367TER_TSGENERAL 0xf230
1639#define F367TER_TSGENERAL_7 0xf2300080
1640#define F367TER_TSGENERAL_6 0xf2300040
1641#define F367TER_TSFIFO_BCLK1aLL 0xf2300020
1642#define F367TER_TSGENERAL_4 0xf2300010
1643#define F367TER_MUXSTREAM_OUTMODE 0xf2300008
1644#define F367TER_TSFIFO_PERMPARAL 0xf2300006
1645#define F367TER_RST_REEDSOLO 0xf2300001
1646
1647/* RC1SPEED */
1648#define R367TER_RC1SPEED 0xf231
1649#define F367TER_TSRCFIFO1_OUTSPEED 0xf23100ff
1650
1651/* TSGSTATUS */
1652#define R367TER_TSGSTATUS 0xf232
1653#define F367TER_TSGSTATUS_7 0xf2320080
1654#define F367TER_TSGSTATUS_6 0xf2320040
1655#define F367TER_RSMEM_FULL 0xf2320020
1656#define F367TER_RS_MULTCALC 0xf2320010
1657#define F367TER_RSIN_OVERTIME 0xf2320008
1658#define F367TER_TSFIFO3_DEMODSEL 0xf2320004
1659#define F367TER_TSFIFO2_DEMODSEL 0xf2320002
1660#define F367TER_TSFIFO1_DEMODSEL 0xf2320001
1661
1662
1663/* FECM */
1664#define R367TER_FECM 0xf233
1665#define F367TER_DSS_DVB 0xf2330080
1666#define F367TER_DEMOD_BYPASS 0xf2330040
1667#define F367TER_CMP_SLOWMODE 0xf2330020
1668#define F367TER_DSS_SRCH 0xf2330010
1669#define F367TER_FECM_3 0xf2330008
1670#define F367TER_DIFF_MODEVIT 0xf2330004
1671#define F367TER_SYNCVIT 0xf2330002
1672#define F367TER_I2CSYM 0xf2330001
1673
1674/* VTH12 */
1675#define R367TER_VTH12 0xf234
1676#define F367TER_VTH_12 0xf23400ff
1677
1678/* VTH23 */
1679#define R367TER_VTH23 0xf235
1680#define F367TER_VTH_23 0xf23500ff
1681
1682/* VTH34 */
1683#define R367TER_VTH34 0xf236
1684#define F367TER_VTH_34 0xf23600ff
1685
1686/* VTH56 */
1687#define R367TER_VTH56 0xf237
1688#define F367TER_VTH_56 0xf23700ff
1689
1690/* VTH67 */
1691#define R367TER_VTH67 0xf238
1692#define F367TER_VTH_67 0xf23800ff
1693
1694/* VTH78 */
1695#define R367TER_VTH78 0xf239
1696#define F367TER_VTH_78 0xf23900ff
1697
1698/* VITCURPUN */
1699#define R367TER_VITCURPUN 0xf23a
1700#define F367TER_VIT_MAPPING 0xf23a00e0
1701#define F367TER_VIT_CURPUN 0xf23a001f
1702
1703/* VERROR */
1704#define R367TER_VERROR 0xf23b
1705#define F367TER_REGERR_VIT 0xf23b00ff
1706
1707/* PRVIT */
1708#define R367TER_PRVIT 0xf23c
1709#define F367TER_PRVIT_7 0xf23c0080
1710#define F367TER_DIS_VTHLOCK 0xf23c0040
1711#define F367TER_E7_8VIT 0xf23c0020
1712#define F367TER_E6_7VIT 0xf23c0010
1713#define F367TER_E5_6VIT 0xf23c0008
1714#define F367TER_E3_4VIT 0xf23c0004
1715#define F367TER_E2_3VIT 0xf23c0002
1716#define F367TER_E1_2VIT 0xf23c0001
1717
1718/* VAVSRVIT */
1719#define R367TER_VAVSRVIT 0xf23d
1720#define F367TER_AMVIT 0xf23d0080
1721#define F367TER_FROZENVIT 0xf23d0040
1722#define F367TER_SNVIT 0xf23d0030
1723#define F367TER_TOVVIT 0xf23d000c
1724#define F367TER_HYPVIT 0xf23d0003
1725
1726/* VSTATUSVIT */
1727#define R367TER_VSTATUSVIT 0xf23e
1728#define F367TER_VITERBI_ON 0xf23e0080
1729#define F367TER_END_LOOPVIT 0xf23e0040
1730#define F367TER_VITERBI_DEPRF 0xf23e0020
1731#define F367TER_PRFVIT 0xf23e0010
1732#define F367TER_LOCKEDVIT 0xf23e0008
1733#define F367TER_VITERBI_DELOCK 0xf23e0004
1734#define F367TER_VIT_DEMODSEL 0xf23e0002
1735#define F367TER_VITERBI_COMPOUT 0xf23e0001
1736
1737/* VTHINUSE */
1738#define R367TER_VTHINUSE 0xf23f
1739#define F367TER_VIT_INUSE 0xf23f00ff
1740
1741/* KDIV12 */
1742#define R367TER_KDIV12 0xf240
1743#define F367TER_KDIV12_MANUAL 0xf2400080
1744#define F367TER_K_DIVIDER_12 0xf240007f
1745
1746/* KDIV23 */
1747#define R367TER_KDIV23 0xf241
1748#define F367TER_KDIV23_MANUAL 0xf2410080
1749#define F367TER_K_DIVIDER_23 0xf241007f
1750
1751/* KDIV34 */
1752#define R367TER_KDIV34 0xf242
1753#define F367TER_KDIV34_MANUAL 0xf2420080
1754#define F367TER_K_DIVIDER_34 0xf242007f
1755
1756/* KDIV56 */
1757#define R367TER_KDIV56 0xf243
1758#define F367TER_KDIV56_MANUAL 0xf2430080
1759#define F367TER_K_DIVIDER_56 0xf243007f
1760
1761/* KDIV67 */
1762#define R367TER_KDIV67 0xf244
1763#define F367TER_KDIV67_MANUAL 0xf2440080
1764#define F367TER_K_DIVIDER_67 0xf244007f
1765
1766/* KDIV78 */
1767#define R367TER_KDIV78 0xf245
1768#define F367TER_KDIV78_MANUAL 0xf2450080
1769#define F367TER_K_DIVIDER_78 0xf245007f
1770
1771/* SIGPOWER */
1772#define R367TER_SIGPOWER 0xf246
1773#define F367TER_SIGPOWER_MANUAL 0xf2460080
1774#define F367TER_SIG_POWER 0xf246007f
1775
1776/* DEMAPVIT */
1777#define R367TER_DEMAPVIT 0xf247
1778#define F367TER_DEMAPVIT_7 0xf2470080
1779#define F367TER_K_DIVIDER_VIT 0xf247007f
1780
1781/* VITSCALE */
1782#define R367TER_VITSCALE 0xf248
1783#define F367TER_NVTH_NOSRANGE 0xf2480080
1784#define F367TER_VERROR_MAXMODE 0xf2480040
1785#define F367TER_KDIV_MODE 0xf2480030
1786#define F367TER_NSLOWSN_LOCKED 0xf2480008
1787#define F367TER_DELOCK_PRFLOSS 0xf2480004
1788#define F367TER_DIS_RSFLOCK 0xf2480002
1789#define F367TER_VITSCALE_0 0xf2480001
1790
1791/* FFEC1PRG */
1792#define R367TER_FFEC1PRG 0xf249
1793#define F367TER_FDSS_DVB 0xf2490080
1794#define F367TER_FDSS_SRCH 0xf2490040
1795#define F367TER_FFECPROG_5 0xf2490020
1796#define F367TER_FFECPROG_4 0xf2490010
1797#define F367TER_FFECPROG_3 0xf2490008
1798#define F367TER_FFECPROG_2 0xf2490004
1799#define F367TER_FTS1_DISABLE 0xf2490002
1800#define F367TER_FTS2_DISABLE 0xf2490001
1801
1802/* FVITCURPUN */
1803#define R367TER_FVITCURPUN 0xf24a
1804#define F367TER_FVIT_MAPPING 0xf24a00e0
1805#define F367TER_FVIT_CURPUN 0xf24a001f
1806
1807/* FVERROR */
1808#define R367TER_FVERROR 0xf24b
1809#define F367TER_FREGERR_VIT 0xf24b00ff
1810
1811/* FVSTATUSVIT */
1812#define R367TER_FVSTATUSVIT 0xf24c
1813#define F367TER_FVITERBI_ON 0xf24c0080
1814#define F367TER_F1END_LOOPVIT 0xf24c0040
1815#define F367TER_FVITERBI_DEPRF 0xf24c0020
1816#define F367TER_FPRFVIT 0xf24c0010
1817#define F367TER_FLOCKEDVIT 0xf24c0008
1818#define F367TER_FVITERBI_DELOCK 0xf24c0004
1819#define F367TER_FVIT_DEMODSEL 0xf24c0002
1820#define F367TER_FVITERBI_COMPOUT 0xf24c0001
1821
1822/* DEBUG_LT1 */
1823#define R367TER_DEBUG_LT1 0xf24d
1824#define F367TER_DBG_LT1 0xf24d00ff
1825
1826/* DEBUG_LT2 */
1827#define R367TER_DEBUG_LT2 0xf24e
1828#define F367TER_DBG_LT2 0xf24e00ff
1829
1830/* DEBUG_LT3 */
1831#define R367TER_DEBUG_LT3 0xf24f
1832#define F367TER_DBG_LT3 0xf24f00ff
1833
1834/* TSTSFMET */
1835#define R367TER_TSTSFMET 0xf250
1836#define F367TER_TSTSFEC_METRIQUES 0xf25000ff
1837
1838/* SELOUT */
1839#define R367TER_SELOUT 0xf252
1840#define F367TER_EN_SYNC 0xf2520080
1841#define F367TER_EN_TBUSDEMAP 0xf2520040
1842#define F367TER_SELOUT_5 0xf2520020
1843#define F367TER_SELOUT_4 0xf2520010
1844#define F367TER_TSTSYNCHRO_MODE 0xf2520002
1845
1846/* TSYNC */
1847#define R367TER_TSYNC 0xf253
1848#define F367TER_CURPUN_INCMODE 0xf2530080
1849#define F367TER_CERR_TSTMODE 0xf2530040
1850#define F367TER_SHIFTSOF_MODE 0xf2530030
1851#define F367TER_SLOWPHA_MODE 0xf2530008
1852#define F367TER_PXX_BYPALL 0xf2530004
1853#define F367TER_FROTA45_FIRST 0xf2530002
1854#define F367TER_TST_BCHERROR 0xf2530001
1855
1856/* TSTERR */
1857#define R367TER_TSTERR 0xf254
1858#define F367TER_TST_LONGPKT 0xf2540080
1859#define F367TER_TST_ISSYION 0xf2540040
1860#define F367TER_TST_NPDON 0xf2540020
1861#define F367TER_TSTERR_4 0xf2540010
1862#define F367TER_TRACEBACK_MODE 0xf2540008
1863#define F367TER_TST_RSPARITY 0xf2540004
1864#define F367TER_METRIQUE_MODE 0xf2540003
1865
1866/* TSFSYNC */
1867#define R367TER_TSFSYNC 0xf255
1868#define F367TER_EN_SFECSYNC 0xf2550080
1869#define F367TER_EN_SFECDEMAP 0xf2550040
1870#define F367TER_SFCERR_TSTMODE 0xf2550020
1871#define F367TER_SFECPXX_BYPALL 0xf2550010
1872#define F367TER_SFECTSTSYNCHRO_MODE 0xf255000f
1873
1874/* TSTSFERR */
1875#define R367TER_TSTSFERR 0xf256
1876#define F367TER_TSTSTERR_7 0xf2560080
1877#define F367TER_TSTSTERR_6 0xf2560040
1878#define F367TER_TSTSTERR_5 0xf2560020
1879#define F367TER_TSTSTERR_4 0xf2560010
1880#define F367TER_SFECTRACEBACK_MODE 0xf2560008
1881#define F367TER_SFEC_NCONVPROG 0xf2560004
1882#define F367TER_SFECMETRIQUE_MODE 0xf2560003
1883
1884/* TSTTSSF1 */
1885#define R367TER_TSTTSSF1 0xf258
1886#define F367TER_TSTERSSF 0xf2580080
1887#define F367TER_TSTTSSFEN 0xf2580040
1888#define F367TER_SFEC_OUTMODE 0xf2580030
1889#define F367TER_XLSF_NOFTHRESHOLD 0xf2580008
1890#define F367TER_TSTTSSF_STACKSEL 0xf2580007
1891
1892/* TSTTSSF2 */
1893#define R367TER_TSTTSSF2 0xf259
1894#define F367TER_DILSF_DBBHEADER 0xf2590080
1895#define F367TER_TSTTSSF_DISBUG 0xf2590040
1896#define F367TER_TSTTSSF_NOBADSTART 0xf2590020
1897#define F367TER_TSTTSSF_SELECT 0xf259001f
1898
1899/* TSTTSSF3 */
1900#define R367TER_TSTTSSF3 0xf25a
1901#define F367TER_TSTTSSF3_7 0xf25a0080
1902#define F367TER_TSTTSSF3_6 0xf25a0040
1903#define F367TER_TSTTSSF3_5 0xf25a0020
1904#define F367TER_TSTTSSF3_4 0xf25a0010
1905#define F367TER_TSTTSSF3_3 0xf25a0008
1906#define F367TER_TSTTSSF3_2 0xf25a0004
1907#define F367TER_TSTTSSF3_1 0xf25a0002
1908#define F367TER_DISSF_CLKENABLE 0xf25a0001
1909
1910/* TSTTS1 */
1911#define R367TER_TSTTS1 0xf25c
1912#define F367TER_TSTERS 0xf25c0080
1913#define F367TER_TSFIFO_DSSSYNCB 0xf25c0040
1914#define F367TER_TSTTS_FSPYBEFRS 0xf25c0020
1915#define F367TER_NFORCE_SYNCBYTE 0xf25c0010
1916#define F367TER_XL_NOFTHRESHOLD 0xf25c0008
1917#define F367TER_TSTTS_FRFORCEPKT 0xf25c0004
1918#define F367TER_DESCR_NOTAUTO 0xf25c0002
1919#define F367TER_TSTTSEN 0xf25c0001
1920
1921/* TSTTS2 */
1922#define R367TER_TSTTS2 0xf25d
1923#define F367TER_DIL_DBBHEADER 0xf25d0080
1924#define F367TER_TSTTS_NOBADXXX 0xf25d0040
1925#define F367TER_TSFIFO_DELSPEEDUP 0xf25d0020
1926#define F367TER_TSTTS_SELECT 0xf25d001f
1927
1928/* TSTTS3 */
1929#define R367TER_TSTTS3 0xf25e
1930#define F367TER_TSTTS_NOPKTGAIN 0xf25e0080
1931#define F367TER_TSTTS_NOPKTENE 0xf25e0040
1932#define F367TER_TSTTS_ISOLATION 0xf25e0020
1933#define F367TER_TSTTS_DISBUG 0xf25e0010
1934#define F367TER_TSTTS_NOBADSTART 0xf25e0008
1935#define F367TER_TSTTS_STACKSEL 0xf25e0007
1936
1937/* TSTTS4 */
1938#define R367TER_TSTTS4 0xf25f
1939#define F367TER_TSTTS4_7 0xf25f0080
1940#define F367TER_TSTTS4_6 0xf25f0040
1941#define F367TER_TSTTS4_5 0xf25f0020
1942#define F367TER_TSTTS_DISDSTATE 0xf25f0010
1943#define F367TER_TSTTS_FASTNOSYNC 0xf25f0008
1944#define F367TER_EXT_FECSPYIN 0xf25f0004
1945#define F367TER_TSTTS_NODPZERO 0xf25f0002
1946#define F367TER_TSTTS_NODIV3 0xf25f0001
1947
1948/* TSTTSRC */
1949#define R367TER_TSTTSRC 0xf26c
1950#define F367TER_TSTTSRC_7 0xf26c0080
1951#define F367TER_TSRCFIFO_DSSSYNCB 0xf26c0040
1952#define F367TER_TSRCFIFO_DPUNACTIVE 0xf26c0020
1953#define F367TER_TSRCFIFO_DELSPEEDUP 0xf26c0010
1954#define F367TER_TSTTSRC_NODIV3 0xf26c0008
1955#define F367TER_TSTTSRC_FRFORCEPKT 0xf26c0004
1956#define F367TER_SAT25_SDDORIGINE 0xf26c0002
1957#define F367TER_TSTTSRC_INACTIVE 0xf26c0001
1958
1959/* TSTTSRS */
1960#define R367TER_TSTTSRS 0xf26d
1961#define F367TER_TSTTSRS_7 0xf26d0080
1962#define F367TER_TSTTSRS_6 0xf26d0040
1963#define F367TER_TSTTSRS_5 0xf26d0020
1964#define F367TER_TSTTSRS_4 0xf26d0010
1965#define F367TER_TSTTSRS_3 0xf26d0008
1966#define F367TER_TSTTSRS_2 0xf26d0004
1967#define F367TER_TSTRS_DISRS2 0xf26d0002
1968#define F367TER_TSTRS_DISRS1 0xf26d0001
1969
1970/* TSSTATEM */
1971#define R367TER_TSSTATEM 0xf270
1972#define F367TER_TSDIL_ON 0xf2700080
1973#define F367TER_TSSKIPRS_ON 0xf2700040
1974#define F367TER_TSRS_ON 0xf2700020
1975#define F367TER_TSDESCRAMB_ON 0xf2700010
1976#define F367TER_TSFRAME_MODE 0xf2700008
1977#define F367TER_TS_DISABLE 0xf2700004
1978#define F367TER_TSACM_MODE 0xf2700002
1979#define F367TER_TSOUT_NOSYNC 0xf2700001
1980
1981/* TSSTATEL */
1982#define R367TER_TSSTATEL 0xf271
1983#define F367TER_TSNOSYNCBYTE 0xf2710080
1984#define F367TER_TSPARITY_ON 0xf2710040
1985#define F367TER_TSSYNCOUTRS_ON 0xf2710020
1986#define F367TER_TSDVBS2_MODE 0xf2710010
1987#define F367TER_TSISSYI_ON 0xf2710008
1988#define F367TER_TSNPD_ON 0xf2710004
1989#define F367TER_TSCRC8_ON 0xf2710002
1990#define F367TER_TSDSS_PACKET 0xf2710001
1991
1992/* TSCFGH */
1993#define R367TER_TSCFGH 0xf272
1994#define F367TER_TSFIFO_DVBCI 0xf2720080
1995#define F367TER_TSFIFO_SERIAL 0xf2720040
1996#define F367TER_TSFIFO_TEIUPDATE 0xf2720020
1997#define F367TER_TSFIFO_DUTY50 0xf2720010
1998#define F367TER_TSFIFO_HSGNLOUT 0xf2720008
1999#define F367TER_TSFIFO_ERRMODE 0xf2720006
2000#define F367TER_RST_HWARE 0xf2720001
2001
2002/* TSCFGM */
2003#define R367TER_TSCFGM 0xf273
2004#define F367TER_TSFIFO_MANSPEED 0xf27300c0
2005#define F367TER_TSFIFO_PERMDATA 0xf2730020
2006#define F367TER_TSFIFO_NONEWSGNL 0xf2730010
2007#define F367TER_TSFIFO_BITSPEED 0xf2730008
2008#define F367TER_NPD_SPECDVBS2 0xf2730004
2009#define F367TER_TSFIFO_STOPCKDIS 0xf2730002
2010#define F367TER_TSFIFO_INVDATA 0xf2730001
2011
2012/* TSCFGL */
2013#define R367TER_TSCFGL 0xf274
2014#define F367TER_TSFIFO_BCLKDEL1cK 0xf27400c0
2015#define F367TER_BCHERROR_MODE 0xf2740030
2016#define F367TER_TSFIFO_NSGNL2dATA 0xf2740008
2017#define F367TER_TSFIFO_EMBINDVB 0xf2740004
2018#define F367TER_TSFIFO_DPUNACT 0xf2740002
2019#define F367TER_TSFIFO_NPDOFF 0xf2740001
2020
2021/* TSSYNC */
2022#define R367TER_TSSYNC 0xf275
2023#define F367TER_TSFIFO_PERMUTE 0xf2750080
2024#define F367TER_TSFIFO_FISCR3B 0xf2750060
2025#define F367TER_TSFIFO_SYNCMODE 0xf2750018
2026#define F367TER_TSFIFO_SYNCSEL 0xf2750007
2027
2028/* TSINSDELH */
2029#define R367TER_TSINSDELH 0xf276
2030#define F367TER_TSDEL_SYNCBYTE 0xf2760080
2031#define F367TER_TSDEL_XXHEADER 0xf2760040
2032#define F367TER_TSDEL_BBHEADER 0xf2760020
2033#define F367TER_TSDEL_DATAFIELD 0xf2760010
2034#define F367TER_TSINSDEL_ISCR 0xf2760008
2035#define F367TER_TSINSDEL_NPD 0xf2760004
2036#define F367TER_TSINSDEL_RSPARITY 0xf2760002
2037#define F367TER_TSINSDEL_CRC8 0xf2760001
2038
2039/* TSINSDELM */
2040#define R367TER_TSINSDELM 0xf277
2041#define F367TER_TSINS_BBPADDING 0xf2770080
2042#define F367TER_TSINS_BCHFEC 0xf2770040
2043#define F367TER_TSINS_LDPCFEC 0xf2770020
2044#define F367TER_TSINS_EMODCOD 0xf2770010
2045#define F367TER_TSINS_TOKEN 0xf2770008
2046#define F367TER_TSINS_XXXERR 0xf2770004
2047#define F367TER_TSINS_MATYPE 0xf2770002
2048#define F367TER_TSINS_UPL 0xf2770001
2049
2050/* TSINSDELL */
2051#define R367TER_TSINSDELL 0xf278
2052#define F367TER_TSINS_DFL 0xf2780080
2053#define F367TER_TSINS_SYNCD 0xf2780040
2054#define F367TER_TSINS_BLOCLEN 0xf2780020
2055#define F367TER_TSINS_SIGPCOUNT 0xf2780010
2056#define F367TER_TSINS_FIFO 0xf2780008
2057#define F367TER_TSINS_REALPACK 0xf2780004
2058#define F367TER_TSINS_TSCONFIG 0xf2780002
2059#define F367TER_TSINS_LATENCY 0xf2780001
2060
2061/* TSDIVN */
2062#define R367TER_TSDIVN 0xf279
2063#define F367TER_TSFIFO_LOWSPEED 0xf2790080
2064#define F367TER_BYTE_OVERSAMPLING 0xf2790070
2065#define F367TER_TSMANUAL_PACKETNBR 0xf279000f
2066
2067/* TSDIVPM */
2068#define R367TER_TSDIVPM 0xf27a
2069#define F367TER_TSMANUAL_P_HI 0xf27a00ff
2070
2071/* TSDIVPL */
2072#define R367TER_TSDIVPL 0xf27b
2073#define F367TER_TSMANUAL_P_LO 0xf27b00ff
2074
2075/* TSDIVQM */
2076#define R367TER_TSDIVQM 0xf27c
2077#define F367TER_TSMANUAL_Q_HI 0xf27c00ff
2078
2079/* TSDIVQL */
2080#define R367TER_TSDIVQL 0xf27d
2081#define F367TER_TSMANUAL_Q_LO 0xf27d00ff
2082
2083/* TSDILSTKM */
2084#define R367TER_TSDILSTKM 0xf27e
2085#define F367TER_TSFIFO_DILSTK_HI 0xf27e00ff
2086
2087/* TSDILSTKL */
2088#define R367TER_TSDILSTKL 0xf27f
2089#define F367TER_TSFIFO_DILSTK_LO 0xf27f00ff
2090
2091/* TSSPEED */
2092#define R367TER_TSSPEED 0xf280
2093#define F367TER_TSFIFO_OUTSPEED 0xf28000ff
2094
2095/* TSSTATUS */
2096#define R367TER_TSSTATUS 0xf281
2097#define F367TER_TSFIFO_LINEOK 0xf2810080
2098#define F367TER_TSFIFO_ERROR 0xf2810040
2099#define F367TER_TSFIFO_DATA7 0xf2810020
2100#define F367TER_TSFIFO_NOSYNC 0xf2810010
2101#define F367TER_ISCR_INITIALIZED 0xf2810008
2102#define F367TER_ISCR_UPDATED 0xf2810004
2103#define F367TER_SOFFIFO_UNREGUL 0xf2810002
2104#define F367TER_DIL_READY 0xf2810001
2105
2106/* TSSTATUS2 */
2107#define R367TER_TSSTATUS2 0xf282
2108#define F367TER_TSFIFO_DEMODSEL 0xf2820080
2109#define F367TER_TSFIFOSPEED_STORE 0xf2820040
2110#define F367TER_DILXX_RESET 0xf2820020
2111#define F367TER_TSSERIAL_IMPOSSIBLE 0xf2820010
2112#define F367TER_TSFIFO_UNDERSPEED 0xf2820008
2113#define F367TER_BITSPEED_EVENT 0xf2820004
2114#define F367TER_UL_SCRAMBDETECT 0xf2820002
2115#define F367TER_ULDTV67_FALSELOCK 0xf2820001
2116
2117/* TSBITRATEM */
2118#define R367TER_TSBITRATEM 0xf283
2119#define F367TER_TSFIFO_BITRATE_HI 0xf28300ff
2120
2121/* TSBITRATEL */
2122#define R367TER_TSBITRATEL 0xf284
2123#define F367TER_TSFIFO_BITRATE_LO 0xf28400ff
2124
2125/* TSPACKLENM */
2126#define R367TER_TSPACKLENM 0xf285
2127#define F367TER_TSFIFO_PACKCPT 0xf28500e0
2128#define F367TER_DIL_RPLEN_HI 0xf285001f
2129
2130/* TSPACKLENL */
2131#define R367TER_TSPACKLENL 0xf286
2132#define F367TER_DIL_RPLEN_LO 0xf28600ff
2133
2134/* TSBLOCLENM */
2135#define R367TER_TSBLOCLENM 0xf287
2136#define F367TER_TSFIFO_PFLEN_HI 0xf28700ff
2137
2138/* TSBLOCLENL */
2139#define R367TER_TSBLOCLENL 0xf288
2140#define F367TER_TSFIFO_PFLEN_LO 0xf28800ff
2141
2142/* TSDLYH */
2143#define R367TER_TSDLYH 0xf289
2144#define F367TER_SOFFIFO_TSTIMEVALID 0xf2890080
2145#define F367TER_SOFFIFO_SPEEDUP 0xf2890040
2146#define F367TER_SOFFIFO_STOP 0xf2890020
2147#define F367TER_SOFFIFO_REGULATED 0xf2890010
2148#define F367TER_SOFFIFO_REALSBOFF_HI 0xf289000f
2149
2150/* TSDLYM */
2151#define R367TER_TSDLYM 0xf28a
2152#define F367TER_SOFFIFO_REALSBOFF_MED 0xf28a00ff
2153
2154/* TSDLYL */
2155#define R367TER_TSDLYL 0xf28b
2156#define F367TER_SOFFIFO_REALSBOFF_LO 0xf28b00ff
2157
2158/* TSNPDAV */
2159#define R367TER_TSNPDAV 0xf28c
2160#define F367TER_TSNPD_AVERAGE 0xf28c00ff
2161
2162/* TSBUFSTATH */
2163#define R367TER_TSBUFSTATH 0xf28d
2164#define F367TER_TSISCR_3BYTES 0xf28d0080
2165#define F367TER_TSISCR_NEWDATA 0xf28d0040
2166#define F367TER_TSISCR_BUFSTAT_HI 0xf28d003f
2167
2168/* TSBUFSTATM */
2169#define R367TER_TSBUFSTATM 0xf28e
2170#define F367TER_TSISCR_BUFSTAT_MED 0xf28e00ff
2171
2172/* TSBUFSTATL */
2173#define R367TER_TSBUFSTATL 0xf28f
2174#define F367TER_TSISCR_BUFSTAT_LO 0xf28f00ff
2175
2176/* TSDEBUGM */
2177#define R367TER_TSDEBUGM 0xf290
2178#define F367TER_TSFIFO_ILLPACKET 0xf2900080
2179#define F367TER_DIL_NOSYNC 0xf2900040
2180#define F367TER_DIL_ISCR 0xf2900020
2181#define F367TER_DILOUT_BSYNCB 0xf2900010
2182#define F367TER_TSFIFO_EMPTYPKT 0xf2900008
2183#define F367TER_TSFIFO_EMPTYRD 0xf2900004
2184#define F367TER_SOFFIFO_STOPM 0xf2900002
2185#define F367TER_SOFFIFO_SPEEDUPM 0xf2900001
2186
2187/* TSDEBUGL */
2188#define R367TER_TSDEBUGL 0xf291
2189#define F367TER_TSFIFO_PACKLENFAIL 0xf2910080
2190#define F367TER_TSFIFO_SYNCBFAIL 0xf2910040
2191#define F367TER_TSFIFO_VITLIBRE 0xf2910020
2192#define F367TER_TSFIFO_BOOSTSPEEDM 0xf2910010
2193#define F367TER_TSFIFO_UNDERSPEEDM 0xf2910008
2194#define F367TER_TSFIFO_ERROR_EVNT 0xf2910004
2195#define F367TER_TSFIFO_FULL 0xf2910002
2196#define F367TER_TSFIFO_OVERFLOWM 0xf2910001
2197
2198/* TSDLYSETH */
2199#define R367TER_TSDLYSETH 0xf292
2200#define F367TER_SOFFIFO_OFFSET 0xf29200e0
2201#define F367TER_SOFFIFO_SYMBOFFSET_HI 0xf292001f
2202
2203/* TSDLYSETM */
2204#define R367TER_TSDLYSETM 0xf293
2205#define F367TER_SOFFIFO_SYMBOFFSET_MED 0xf29300ff
2206
2207/* TSDLYSETL */
2208#define R367TER_TSDLYSETL 0xf294
2209#define F367TER_SOFFIFO_SYMBOFFSET_LO 0xf29400ff
2210
2211/* TSOBSCFG */
2212#define R367TER_TSOBSCFG 0xf295
2213#define F367TER_TSFIFO_OBSCFG 0xf29500ff
2214
2215/* TSOBSM */
2216#define R367TER_TSOBSM 0xf296
2217#define F367TER_TSFIFO_OBSDATA_HI 0xf29600ff
2218
2219/* TSOBSL */
2220#define R367TER_TSOBSL 0xf297
2221#define F367TER_TSFIFO_OBSDATA_LO 0xf29700ff
2222
2223/* ERRCTRL1 */
2224#define R367TER_ERRCTRL1 0xf298
2225#define F367TER_ERR_SRC1 0xf29800f0
2226#define F367TER_ERRCTRL1_3 0xf2980008
2227#define F367TER_NUM_EVT1 0xf2980007
2228
2229/* ERRCNT1H */
2230#define R367TER_ERRCNT1H 0xf299
2231#define F367TER_ERRCNT1_OLDVALUE 0xf2990080
2232#define F367TER_ERR_CNT1 0xf299007f
2233
2234/* ERRCNT1M */
2235#define R367TER_ERRCNT1M 0xf29a
2236#define F367TER_ERR_CNT1_HI 0xf29a00ff
2237
2238/* ERRCNT1L */
2239#define R367TER_ERRCNT1L 0xf29b
2240#define F367TER_ERR_CNT1_LO 0xf29b00ff
2241
2242/* ERRCTRL2 */
2243#define R367TER_ERRCTRL2 0xf29c
2244#define F367TER_ERR_SRC2 0xf29c00f0
2245#define F367TER_ERRCTRL2_3 0xf29c0008
2246#define F367TER_NUM_EVT2 0xf29c0007
2247
2248/* ERRCNT2H */
2249#define R367TER_ERRCNT2H 0xf29d
2250#define F367TER_ERRCNT2_OLDVALUE 0xf29d0080
2251#define F367TER_ERR_CNT2_HI 0xf29d007f
2252
2253/* ERRCNT2M */
2254#define R367TER_ERRCNT2M 0xf29e
2255#define F367TER_ERR_CNT2_MED 0xf29e00ff
2256
2257/* ERRCNT2L */
2258#define R367TER_ERRCNT2L 0xf29f
2259#define F367TER_ERR_CNT2_LO 0xf29f00ff
2260
2261/* FECSPY */
2262#define R367TER_FECSPY 0xf2a0
2263#define F367TER_SPY_ENABLE 0xf2a00080
2264#define F367TER_NO_SYNCBYTE 0xf2a00040
2265#define F367TER_SERIAL_MODE 0xf2a00020
2266#define F367TER_UNUSUAL_PACKET 0xf2a00010
2267#define F367TER_BERMETER_DATAMODE 0xf2a0000c
2268#define F367TER_BERMETER_LMODE 0xf2a00002
2269#define F367TER_BERMETER_RESET 0xf2a00001
2270
2271/* FSPYCFG */
2272#define R367TER_FSPYCFG 0xf2a1
2273#define F367TER_FECSPY_INPUT 0xf2a100c0
2274#define F367TER_RST_ON_ERROR 0xf2a10020
2275#define F367TER_ONE_SHOT 0xf2a10010
2276#define F367TER_I2C_MOD 0xf2a1000c
2277#define F367TER_SPY_HYSTERESIS 0xf2a10003
2278
2279/* FSPYDATA */
2280#define R367TER_FSPYDATA 0xf2a2
2281#define F367TER_SPY_STUFFING 0xf2a20080
2282#define F367TER_NOERROR_PKTJITTER 0xf2a20040
2283#define F367TER_SPY_CNULLPKT 0xf2a20020
2284#define F367TER_SPY_OUTDATA_MODE 0xf2a2001f
2285
2286/* FSPYOUT */
2287#define R367TER_FSPYOUT 0xf2a3
2288#define F367TER_FSPY_DIRECT 0xf2a30080
2289#define F367TER_FSPYOUT_6 0xf2a30040
2290#define F367TER_SPY_OUTDATA_BUS 0xf2a30038
2291#define F367TER_STUFF_MODE 0xf2a30007
2292
2293/* FSTATUS */
2294#define R367TER_FSTATUS 0xf2a4
2295#define F367TER_SPY_ENDSIM 0xf2a40080
2296#define F367TER_VALID_SIM 0xf2a40040
2297#define F367TER_FOUND_SIGNAL 0xf2a40020
2298#define F367TER_DSS_SYNCBYTE 0xf2a40010
2299#define F367TER_RESULT_STATE 0xf2a4000f
2300
2301/* FGOODPACK */
2302#define R367TER_FGOODPACK 0xf2a5
2303#define F367TER_FGOOD_PACKET 0xf2a500ff
2304
2305/* FPACKCNT */
2306#define R367TER_FPACKCNT 0xf2a6
2307#define F367TER_FPACKET_COUNTER 0xf2a600ff
2308
2309/* FSPYMISC */
2310#define R367TER_FSPYMISC 0xf2a7
2311#define F367TER_FLABEL_COUNTER 0xf2a700ff
2312
2313/* FBERCPT4 */
2314#define R367TER_FBERCPT4 0xf2a8
2315#define F367TER_FBERMETER_CPT5 0xf2a800ff
2316
2317/* FBERCPT3 */
2318#define R367TER_FBERCPT3 0xf2a9
2319#define F367TER_FBERMETER_CPT4 0xf2a900ff
2320
2321/* FBERCPT2 */
2322#define R367TER_FBERCPT2 0xf2aa
2323#define F367TER_FBERMETER_CPT3 0xf2aa00ff
2324
2325/* FBERCPT1 */
2326#define R367TER_FBERCPT1 0xf2ab
2327#define F367TER_FBERMETER_CPT2 0xf2ab00ff
2328
2329/* FBERCPT0 */
2330#define R367TER_FBERCPT0 0xf2ac
2331#define F367TER_FBERMETER_CPT1 0xf2ac00ff
2332
2333/* FBERERR2 */
2334#define R367TER_FBERERR2 0xf2ad
2335#define F367TER_FBERMETER_ERR_HI 0xf2ad00ff
2336
2337/* FBERERR1 */
2338#define R367TER_FBERERR1 0xf2ae
2339#define F367TER_FBERMETER_ERR_MED 0xf2ae00ff
2340
2341/* FBERERR0 */
2342#define R367TER_FBERERR0 0xf2af
2343#define F367TER_FBERMETER_ERR_LO 0xf2af00ff
2344
2345/* FSTATESM */
2346#define R367TER_FSTATESM 0xf2b0
2347#define F367TER_RSTATE_F 0xf2b00080
2348#define F367TER_RSTATE_E 0xf2b00040
2349#define F367TER_RSTATE_D 0xf2b00020
2350#define F367TER_RSTATE_C 0xf2b00010
2351#define F367TER_RSTATE_B 0xf2b00008
2352#define F367TER_RSTATE_A 0xf2b00004
2353#define F367TER_RSTATE_9 0xf2b00002
2354#define F367TER_RSTATE_8 0xf2b00001
2355
2356/* FSTATESL */
2357#define R367TER_FSTATESL 0xf2b1
2358#define F367TER_RSTATE_7 0xf2b10080
2359#define F367TER_RSTATE_6 0xf2b10040
2360#define F367TER_RSTATE_5 0xf2b10020
2361#define F367TER_RSTATE_4 0xf2b10010
2362#define F367TER_RSTATE_3 0xf2b10008
2363#define F367TER_RSTATE_2 0xf2b10004
2364#define F367TER_RSTATE_1 0xf2b10002
2365#define F367TER_RSTATE_0 0xf2b10001
2366
2367/* FSPYBER */
2368#define R367TER_FSPYBER 0xf2b2
2369#define F367TER_FSPYBER_7 0xf2b20080
2370#define F367TER_FSPYOBS_XORREAD 0xf2b20040
2371#define F367TER_FSPYBER_OBSMODE 0xf2b20020
2372#define F367TER_FSPYBER_SYNCBYTE 0xf2b20010
2373#define F367TER_FSPYBER_UNSYNC 0xf2b20008
2374#define F367TER_FSPYBER_CTIME 0xf2b20007
2375
2376/* FSPYDISTM */
2377#define R367TER_FSPYDISTM 0xf2b3
2378#define F367TER_PKTTIME_DISTANCE_HI 0xf2b300ff
2379
2380/* FSPYDISTL */
2381#define R367TER_FSPYDISTL 0xf2b4
2382#define F367TER_PKTTIME_DISTANCE_LO 0xf2b400ff
2383
2384/* FSPYOBS7 */
2385#define R367TER_FSPYOBS7 0xf2b8
2386#define F367TER_FSPYOBS_SPYFAIL 0xf2b80080
2387#define F367TER_FSPYOBS_SPYFAIL1 0xf2b80040
2388#define F367TER_FSPYOBS_ERROR 0xf2b80020
2389#define F367TER_FSPYOBS_STROUT 0xf2b80010
2390#define F367TER_FSPYOBS_RESULTSTATE1 0xf2b8000f
2391
2392/* FSPYOBS6 */
2393#define R367TER_FSPYOBS6 0xf2b9
2394#define F367TER_FSPYOBS_RESULTSTATe0 0xf2b900f0
2395#define F367TER_FSPYOBS_RESULTSTATEM1 0xf2b9000f
2396
2397/* FSPYOBS5 */
2398#define R367TER_FSPYOBS5 0xf2ba
2399#define F367TER_FSPYOBS_BYTEOFPACKET1 0xf2ba00ff
2400
2401/* FSPYOBS4 */
2402#define R367TER_FSPYOBS4 0xf2bb
2403#define F367TER_FSPYOBS_BYTEVALUE1 0xf2bb00ff
2404
2405/* FSPYOBS3 */
2406#define R367TER_FSPYOBS3 0xf2bc
2407#define F367TER_FSPYOBS_DATA1 0xf2bc00ff
2408
2409/* FSPYOBS2 */
2410#define R367TER_FSPYOBS2 0xf2bd
2411#define F367TER_FSPYOBS_DATa0 0xf2bd00ff
2412
2413/* FSPYOBS1 */
2414#define R367TER_FSPYOBS1 0xf2be
2415#define F367TER_FSPYOBS_DATAM1 0xf2be00ff
2416
2417/* FSPYOBS0 */
2418#define R367TER_FSPYOBS0 0xf2bf
2419#define F367TER_FSPYOBS_DATAM2 0xf2bf00ff
2420
2421/* SFDEMAP */
2422#define R367TER_SFDEMAP 0xf2c0
2423#define F367TER_SFDEMAP_7 0xf2c00080
2424#define F367TER_SFEC_K_DIVIDER_VIT 0xf2c0007f
2425
2426/* SFERROR */
2427#define R367TER_SFERROR 0xf2c1
2428#define F367TER_SFEC_REGERR_VIT 0xf2c100ff
2429
2430/* SFAVSR */
2431#define R367TER_SFAVSR 0xf2c2
2432#define F367TER_SFEC_SUMERRORS 0xf2c20080
2433#define F367TER_SERROR_MAXMODE 0xf2c20040
2434#define F367TER_SN_SFEC 0xf2c20030
2435#define F367TER_KDIV_MODE_SFEC 0xf2c2000c
2436#define F367TER_SFAVSR_1 0xf2c20002
2437#define F367TER_SFAVSR_0 0xf2c20001
2438
2439/* SFECSTATUS */
2440#define R367TER_SFECSTATUS 0xf2c3
2441#define F367TER_SFEC_ON 0xf2c30080
2442#define F367TER_SFSTATUS_6 0xf2c30040
2443#define F367TER_SFSTATUS_5 0xf2c30020
2444#define F367TER_SFSTATUS_4 0xf2c30010
2445#define F367TER_LOCKEDSFEC 0xf2c30008
2446#define F367TER_SFEC_DELOCK 0xf2c30004
2447#define F367TER_SFEC_DEMODSEL1 0xf2c30002
2448#define F367TER_SFEC_OVFON 0xf2c30001
2449
2450/* SFKDIV12 */
2451#define R367TER_SFKDIV12 0xf2c4
2452#define F367TER_SFECKDIV12_MAN 0xf2c40080
2453#define F367TER_SFEC_K_DIVIDER_12 0xf2c4007f
2454
2455/* SFKDIV23 */
2456#define R367TER_SFKDIV23 0xf2c5
2457#define F367TER_SFECKDIV23_MAN 0xf2c50080
2458#define F367TER_SFEC_K_DIVIDER_23 0xf2c5007f
2459
2460/* SFKDIV34 */
2461#define R367TER_SFKDIV34 0xf2c6
2462#define F367TER_SFECKDIV34_MAN 0xf2c60080
2463#define F367TER_SFEC_K_DIVIDER_34 0xf2c6007f
2464
2465/* SFKDIV56 */
2466#define R367TER_SFKDIV56 0xf2c7
2467#define F367TER_SFECKDIV56_MAN 0xf2c70080
2468#define F367TER_SFEC_K_DIVIDER_56 0xf2c7007f
2469
2470/* SFKDIV67 */
2471#define R367TER_SFKDIV67 0xf2c8
2472#define F367TER_SFECKDIV67_MAN 0xf2c80080
2473#define F367TER_SFEC_K_DIVIDER_67 0xf2c8007f
2474
2475/* SFKDIV78 */
2476#define R367TER_SFKDIV78 0xf2c9
2477#define F367TER_SFECKDIV78_MAN 0xf2c90080
2478#define F367TER_SFEC_K_DIVIDER_78 0xf2c9007f
2479
2480/* SFDILSTKM */
2481#define R367TER_SFDILSTKM 0xf2ca
2482#define F367TER_SFEC_PACKCPT 0xf2ca00e0
2483#define F367TER_SFEC_DILSTK_HI 0xf2ca001f
2484
2485/* SFDILSTKL */
2486#define R367TER_SFDILSTKL 0xf2cb
2487#define F367TER_SFEC_DILSTK_LO 0xf2cb00ff
2488
2489/* SFSTATUS */
2490#define R367TER_SFSTATUS 0xf2cc
2491#define F367TER_SFEC_LINEOK 0xf2cc0080
2492#define F367TER_SFEC_ERROR 0xf2cc0040
2493#define F367TER_SFEC_DATA7 0xf2cc0020
2494#define F367TER_SFEC_OVERFLOW 0xf2cc0010
2495#define F367TER_SFEC_DEMODSEL2 0xf2cc0008
2496#define F367TER_SFEC_NOSYNC 0xf2cc0004
2497#define F367TER_SFEC_UNREGULA 0xf2cc0002
2498#define F367TER_SFEC_READY 0xf2cc0001
2499
2500/* SFDLYH */
2501#define R367TER_SFDLYH 0xf2cd
2502#define F367TER_SFEC_TSTIMEVALID 0xf2cd0080
2503#define F367TER_SFEC_SPEEDUP 0xf2cd0040
2504#define F367TER_SFEC_STOP 0xf2cd0020
2505#define F367TER_SFEC_REGULATED 0xf2cd0010
2506#define F367TER_SFEC_REALSYMBOFFSET 0xf2cd000f
2507
2508/* SFDLYM */
2509#define R367TER_SFDLYM 0xf2ce
2510#define F367TER_SFEC_REALSYMBOFFSET_HI 0xf2ce00ff
2511
2512/* SFDLYL */
2513#define R367TER_SFDLYL 0xf2cf
2514#define F367TER_SFEC_REALSYMBOFFSET_LO 0xf2cf00ff
2515
2516/* SFDLYSETH */
2517#define R367TER_SFDLYSETH 0xf2d0
2518#define F367TER_SFEC_OFFSET 0xf2d000e0
2519#define F367TER_SFECDLYSETH_4 0xf2d00010
2520#define F367TER_RST_SFEC 0xf2d00008
2521#define F367TER_SFECDLYSETH_2 0xf2d00004
2522#define F367TER_SFEC_DISABLE 0xf2d00002
2523#define F367TER_SFEC_UNREGUL 0xf2d00001
2524
2525/* SFDLYSETM */
2526#define R367TER_SFDLYSETM 0xf2d1
2527#define F367TER_SFECDLYSETM_7 0xf2d10080
2528#define F367TER_SFEC_SYMBOFFSET_HI 0xf2d1007f
2529
2530/* SFDLYSETL */
2531#define R367TER_SFDLYSETL 0xf2d2
2532#define F367TER_SFEC_SYMBOFFSET_LO 0xf2d200ff
2533
2534/* SFOBSCFG */
2535#define R367TER_SFOBSCFG 0xf2d3
2536#define F367TER_SFEC_OBSCFG 0xf2d300ff
2537
2538/* SFOBSM */
2539#define R367TER_SFOBSM 0xf2d4
2540#define F367TER_SFEC_OBSDATA_HI 0xf2d400ff
2541
2542/* SFOBSL */
2543#define R367TER_SFOBSL 0xf2d5
2544#define F367TER_SFEC_OBSDATA_LO 0xf2d500ff
2545
2546/* SFECINFO */
2547#define R367TER_SFECINFO 0xf2d6
2548#define F367TER_SFECINFO_7 0xf2d60080
2549#define F367TER_SFEC_SYNCDLSB 0xf2d60070
2550#define F367TER_SFCE_S1cPHASE 0xf2d6000f
2551
2552/* SFERRCTRL */
2553#define R367TER_SFERRCTRL 0xf2d8
2554#define F367TER_SFEC_ERR_SOURCE 0xf2d800f0
2555#define F367TER_SFERRCTRL_3 0xf2d80008
2556#define F367TER_SFEC_NUM_EVENT 0xf2d80007
2557
2558/* SFERRCNTH */
2559#define R367TER_SFERRCNTH 0xf2d9
2560#define F367TER_SFERRC_OLDVALUE 0xf2d90080
2561#define F367TER_SFEC_ERR_CNT 0xf2d9007f
2562
2563/* SFERRCNTM */
2564#define R367TER_SFERRCNTM 0xf2da
2565#define F367TER_SFEC_ERR_CNT_HI 0xf2da00ff
2566
2567/* SFERRCNTL */
2568#define R367TER_SFERRCNTL 0xf2db
2569#define F367TER_SFEC_ERR_CNT_LO 0xf2db00ff
2570
2571/* SYMBRATEM */
2572#define R367TER_SYMBRATEM 0xf2e0
2573#define F367TER_DEFGEN_SYMBRATE_HI 0xf2e000ff
2574
2575/* SYMBRATEL */
2576#define R367TER_SYMBRATEL 0xf2e1
2577#define F367TER_DEFGEN_SYMBRATE_LO 0xf2e100ff
2578
2579/* SYMBSTATUS */
2580#define R367TER_SYMBSTATUS 0xf2e2
2581#define F367TER_SYMBDLINE2_OFF 0xf2e20080
2582#define F367TER_SDDL_REINIT1 0xf2e20040
2583#define F367TER_SDD_REINIT1 0xf2e20020
2584#define F367TER_TOKENID_ERROR 0xf2e20010
2585#define F367TER_SYMBRATE_OVERFLOW 0xf2e20008
2586#define F367TER_SYMBRATE_UNDERFLOW 0xf2e20004
2587#define F367TER_TOKENID_RSTEVENT 0xf2e20002
2588#define F367TER_TOKENID_RESET1 0xf2e20001
2589
2590/* SYMBCFG */
2591#define R367TER_SYMBCFG 0xf2e3
2592#define F367TER_SYMBCFG_7 0xf2e30080
2593#define F367TER_SYMBCFG_6 0xf2e30040
2594#define F367TER_SYMBCFG_5 0xf2e30020
2595#define F367TER_SYMBCFG_4 0xf2e30010
2596#define F367TER_SYMRATE_FSPEED 0xf2e3000c
2597#define F367TER_SYMRATE_SSPEED 0xf2e30003
2598
2599/* SYMBFIFOM */
2600#define R367TER_SYMBFIFOM 0xf2e4
2601#define F367TER_SYMBFIFOM_7 0xf2e40080
2602#define F367TER_SYMBFIFOM_6 0xf2e40040
2603#define F367TER_DEFGEN_SYMFIFO_HI 0xf2e4003f
2604
2605/* SYMBFIFOL */
2606#define R367TER_SYMBFIFOL 0xf2e5
2607#define F367TER_DEFGEN_SYMFIFO_LO 0xf2e500ff
2608
2609/* SYMBOFFSM */
2610#define R367TER_SYMBOFFSM 0xf2e6
2611#define F367TER_TOKENID_RESET2 0xf2e60080
2612#define F367TER_SDDL_REINIT2 0xf2e60040
2613#define F367TER_SDD_REINIT2 0xf2e60020
2614#define F367TER_SYMBOFFSM_4 0xf2e60010
2615#define F367TER_SYMBOFFSM_3 0xf2e60008
2616#define F367TER_DEFGEN_SYMBOFFSET_HI 0xf2e60007
2617
2618/* SYMBOFFSL */
2619#define R367TER_SYMBOFFSL 0xf2e7
2620#define F367TER_DEFGEN_SYMBOFFSET_LO 0xf2e700ff
2621
2622/* DEBUG_LT4 */
2623#define R367TER_DEBUG_LT4 0xf400
2624#define F367TER_F_DEBUG_LT4 0xf40000ff
2625
2626/* DEBUG_LT5 */
2627#define R367TER_DEBUG_LT5 0xf401
2628#define F367TER_F_DEBUG_LT5 0xf40100ff
2629
2630/* DEBUG_LT6 */
2631#define R367TER_DEBUG_LT6 0xf402
2632#define F367TER_F_DEBUG_LT6 0xf40200ff
2633
2634/* DEBUG_LT7 */
2635#define R367TER_DEBUG_LT7 0xf403
2636#define F367TER_F_DEBUG_LT7 0xf40300ff
2637
2638/* DEBUG_LT8 */
2639#define R367TER_DEBUG_LT8 0xf404
2640#define F367TER_F_DEBUG_LT8 0xf40400ff
2641
2642/* DEBUG_LT9 */
2643#define R367TER_DEBUG_LT9 0xf405
2644#define F367TER_F_DEBUG_LT9 0xf40500ff
2645
2646#define STV0367TER_NBREGS 445
2647
2648/* ID */
2649#define R367CAB_ID 0xf000
2650#define F367CAB_IDENTIFICATIONREGISTER 0xf00000ff
2651
2652/* I2CRPT */
2653#define R367CAB_I2CRPT 0xf001
2654#define F367CAB_I2CT_ON 0xf0010080
2655#define F367CAB_ENARPT_LEVEL 0xf0010070
2656#define F367CAB_SCLT_DELAY 0xf0010008
2657#define F367CAB_SCLT_NOD 0xf0010004
2658#define F367CAB_STOP_ENABLE 0xf0010002
2659#define F367CAB_SDAT_NOD 0xf0010001
2660
2661/* TOPCTRL */
2662#define R367CAB_TOPCTRL 0xf002
2663#define F367CAB_STDBY 0xf0020080
2664#define F367CAB_STDBY_CORE 0xf0020020
2665#define F367CAB_QAM_COFDM 0xf0020010
2666#define F367CAB_TS_DIS 0xf0020008
2667#define F367CAB_DIR_CLK_216 0xf0020004
2668
2669/* IOCFG0 */
2670#define R367CAB_IOCFG0 0xf003
2671#define F367CAB_OP0_SD 0xf0030080
2672#define F367CAB_OP0_VAL 0xf0030040
2673#define F367CAB_OP0_OD 0xf0030020
2674#define F367CAB_OP0_INV 0xf0030010
2675#define F367CAB_OP0_DACVALUE_HI 0xf003000f
2676
2677/* DAc0R */
2678#define R367CAB_DAC0R 0xf004
2679#define F367CAB_OP0_DACVALUE_LO 0xf00400ff
2680
2681/* IOCFG1 */
2682#define R367CAB_IOCFG1 0xf005
2683#define F367CAB_IP0 0xf0050040
2684#define F367CAB_OP1_OD 0xf0050020
2685#define F367CAB_OP1_INV 0xf0050010
2686#define F367CAB_OP1_DACVALUE_HI 0xf005000f
2687
2688/* DAC1R */
2689#define R367CAB_DAC1R 0xf006
2690#define F367CAB_OP1_DACVALUE_LO 0xf00600ff
2691
2692/* IOCFG2 */
2693#define R367CAB_IOCFG2 0xf007
2694#define F367CAB_OP2_LOCK_CONF 0xf00700e0
2695#define F367CAB_OP2_OD 0xf0070010
2696#define F367CAB_OP2_VAL 0xf0070008
2697#define F367CAB_OP1_LOCK_CONF 0xf0070007
2698
2699/* SDFR */
2700#define R367CAB_SDFR 0xf008
2701#define F367CAB_OP0_FREQ 0xf00800f0
2702#define F367CAB_OP1_FREQ 0xf008000f
2703
2704/* AUX_CLK */
2705#define R367CAB_AUX_CLK 0xf00a
2706#define F367CAB_AUXFEC_CTL 0xf00a00c0
2707#define F367CAB_DIS_CKX4 0xf00a0020
2708#define F367CAB_CKSEL 0xf00a0018
2709#define F367CAB_CKDIV_PROG 0xf00a0006
2710#define F367CAB_AUXCLK_ENA 0xf00a0001
2711
2712/* FREESYS1 */
2713#define R367CAB_FREESYS1 0xf00b
2714#define F367CAB_FREESYS_1 0xf00b00ff
2715
2716/* FREESYS2 */
2717#define R367CAB_FREESYS2 0xf00c
2718#define F367CAB_FREESYS_2 0xf00c00ff
2719
2720/* FREESYS3 */
2721#define R367CAB_FREESYS3 0xf00d
2722#define F367CAB_FREESYS_3 0xf00d00ff
2723
2724/* GPIO_CFG */
2725#define R367CAB_GPIO_CFG 0xf00e
2726#define F367CAB_GPIO7_OD 0xf00e0080
2727#define F367CAB_GPIO7_CFG 0xf00e0040
2728#define F367CAB_GPIO6_OD 0xf00e0020
2729#define F367CAB_GPIO6_CFG 0xf00e0010
2730#define F367CAB_GPIO5_OD 0xf00e0008
2731#define F367CAB_GPIO5_CFG 0xf00e0004
2732#define F367CAB_GPIO4_OD 0xf00e0002
2733#define F367CAB_GPIO4_CFG 0xf00e0001
2734
2735/* GPIO_CMD */
2736#define R367CAB_GPIO_CMD 0xf00f
2737#define F367CAB_GPIO7_VAL 0xf00f0008
2738#define F367CAB_GPIO6_VAL 0xf00f0004
2739#define F367CAB_GPIO5_VAL 0xf00f0002
2740#define F367CAB_GPIO4_VAL 0xf00f0001
2741
2742/* TSTRES */
2743#define R367CAB_TSTRES 0xf0c0
2744#define F367CAB_FRES_DISPLAY 0xf0c00080
2745#define F367CAB_FRES_FIFO_AD 0xf0c00020
2746#define F367CAB_FRESRS 0xf0c00010
2747#define F367CAB_FRESACS 0xf0c00008
2748#define F367CAB_FRESFEC 0xf0c00004
2749#define F367CAB_FRES_PRIF 0xf0c00002
2750#define F367CAB_FRESCORE 0xf0c00001
2751
2752/* ANACTRL */
2753#define R367CAB_ANACTRL 0xf0c1
2754#define F367CAB_BYPASS_XTAL 0xf0c10040
2755#define F367CAB_BYPASS_PLLXN 0xf0c1000c
2756#define F367CAB_DIS_PAD_OSC 0xf0c10002
2757#define F367CAB_STDBY_PLLXN 0xf0c10001
2758
2759/* TSTBUS */
2760#define R367CAB_TSTBUS 0xf0c2
2761#define F367CAB_TS_BYTE_CLK_INV 0xf0c20080
2762#define F367CAB_CFG_IP 0xf0c20070
2763#define F367CAB_CFG_TST 0xf0c2000f
2764
2765/* RF_AGC1 */
2766#define R367CAB_RF_AGC1 0xf0d4
2767#define F367CAB_RF_AGC1_LEVEL_HI 0xf0d400ff
2768
2769/* RF_AGC2 */
2770#define R367CAB_RF_AGC2 0xf0d5
2771#define F367CAB_REF_ADGP 0xf0d50080
2772#define F367CAB_STDBY_ADCGP 0xf0d50020
2773#define F367CAB_RF_AGC1_LEVEL_LO 0xf0d50003
2774
2775/* ANADIGCTRL */
2776#define R367CAB_ANADIGCTRL 0xf0d7
2777#define F367CAB_SEL_CLKDEM 0xf0d70020
2778#define F367CAB_EN_BUFFER_Q 0xf0d70010
2779#define F367CAB_EN_BUFFER_I 0xf0d70008
2780#define F367CAB_ADC_RIS_EGDE 0xf0d70004
2781#define F367CAB_SGN_ADC 0xf0d70002
2782#define F367CAB_SEL_AD12_SYNC 0xf0d70001
2783
2784/* PLLMDIV */
2785#define R367CAB_PLLMDIV 0xf0d8
2786#define F367CAB_PLL_MDIV 0xf0d800ff
2787
2788/* PLLNDIV */
2789#define R367CAB_PLLNDIV 0xf0d9
2790#define F367CAB_PLL_NDIV 0xf0d900ff
2791
2792/* PLLSETUP */
2793#define R367CAB_PLLSETUP 0xf0da
2794#define F367CAB_PLL_PDIV 0xf0da0070
2795#define F367CAB_PLL_KDIV 0xf0da000f
2796
2797/* DUAL_AD12 */
2798#define R367CAB_DUAL_AD12 0xf0db
2799#define F367CAB_FS20M 0xf0db0020
2800#define F367CAB_FS50M 0xf0db0010
2801#define F367CAB_INMODe0 0xf0db0008
2802#define F367CAB_POFFQ 0xf0db0004
2803#define F367CAB_POFFI 0xf0db0002
2804#define F367CAB_INMODE1 0xf0db0001
2805
2806/* TSTBIST */
2807#define R367CAB_TSTBIST 0xf0dc
2808#define F367CAB_TST_BYP_CLK 0xf0dc0080
2809#define F367CAB_TST_GCLKENA_STD 0xf0dc0040
2810#define F367CAB_TST_GCLKENA 0xf0dc0020
2811#define F367CAB_TST_MEMBIST 0xf0dc001f
2812
2813/* CTRL_1 */
2814#define R367CAB_CTRL_1 0xf402
2815#define F367CAB_SOFT_RST 0xf4020080
2816#define F367CAB_EQU_RST 0xf4020008
2817#define F367CAB_CRL_RST 0xf4020004
2818#define F367CAB_TRL_RST 0xf4020002
2819#define F367CAB_AGC_RST 0xf4020001
2820
2821/* CTRL_2 */
2822#define R367CAB_CTRL_2 0xf403
2823#define F367CAB_DEINT_RST 0xf4030008
2824#define F367CAB_RS_RST 0xf4030004
2825
2826/* IT_STATUS1 */
2827#define R367CAB_IT_STATUS1 0xf408
2828#define F367CAB_SWEEP_OUT 0xf4080080
2829#define F367CAB_FSM_CRL 0xf4080040
2830#define F367CAB_CRL_LOCK 0xf4080020
2831#define F367CAB_MFSM 0xf4080010
2832#define F367CAB_TRL_LOCK 0xf4080008
2833#define F367CAB_TRL_AGC_LIMIT 0xf4080004
2834#define F367CAB_ADJ_AGC_LOCK 0xf4080002
2835#define F367CAB_AGC_QAM_LOCK 0xf4080001
2836
2837/* IT_STATUS2 */
2838#define R367CAB_IT_STATUS2 0xf409
2839#define F367CAB_TSMF_CNT 0xf4090080
2840#define F367CAB_TSMF_EOF 0xf4090040
2841#define F367CAB_TSMF_RDY 0xf4090020
2842#define F367CAB_FEC_NOCORR 0xf4090010
2843#define F367CAB_SYNCSTATE 0xf4090008
2844#define F367CAB_DEINT_LOCK 0xf4090004
2845#define F367CAB_FADDING_FRZ 0xf4090002
2846#define F367CAB_TAPMON_ALARM 0xf4090001
2847
2848/* IT_EN1 */
2849#define R367CAB_IT_EN1 0xf40a
2850#define F367CAB_SWEEP_OUTE 0xf40a0080
2851#define F367CAB_FSM_CRLE 0xf40a0040
2852#define F367CAB_CRL_LOCKE 0xf40a0020
2853#define F367CAB_MFSME 0xf40a0010
2854#define F367CAB_TRL_LOCKE 0xf40a0008
2855#define F367CAB_TRL_AGC_LIMITE 0xf40a0004
2856#define F367CAB_ADJ_AGC_LOCKE 0xf40a0002
2857#define F367CAB_AGC_LOCKE 0xf40a0001
2858
2859/* IT_EN2 */
2860#define R367CAB_IT_EN2 0xf40b
2861#define F367CAB_TSMF_CNTE 0xf40b0080
2862#define F367CAB_TSMF_EOFE 0xf40b0040
2863#define F367CAB_TSMF_RDYE 0xf40b0020
2864#define F367CAB_FEC_NOCORRE 0xf40b0010
2865#define F367CAB_SYNCSTATEE 0xf40b0008
2866#define F367CAB_DEINT_LOCKE 0xf40b0004
2867#define F367CAB_FADDING_FRZE 0xf40b0002
2868#define F367CAB_TAPMON_ALARME 0xf40b0001
2869
2870/* CTRL_STATUS */
2871#define R367CAB_CTRL_STATUS 0xf40c
2872#define F367CAB_QAMFEC_LOCK 0xf40c0004
2873#define F367CAB_TSMF_LOCK 0xf40c0002
2874#define F367CAB_TSMF_ERROR 0xf40c0001
2875
2876/* TEST_CTL */
2877#define R367CAB_TEST_CTL 0xf40f
2878#define F367CAB_TST_BLK_SEL 0xf40f0060
2879#define F367CAB_TST_BUS_SEL 0xf40f001f
2880
2881/* AGC_CTL */
2882#define R367CAB_AGC_CTL 0xf410
2883#define F367CAB_AGC_LCK_TH 0xf41000f0
2884#define F367CAB_AGC_ACCUMRSTSEL 0xf4100007
2885
2886/* AGC_IF_CFG */
2887#define R367CAB_AGC_IF_CFG 0xf411
2888#define F367CAB_AGC_IF_BWSEL 0xf41100f0
2889#define F367CAB_AGC_IF_FREEZE 0xf4110002
2890
2891/* AGC_RF_CFG */
2892#define R367CAB_AGC_RF_CFG 0xf412
2893#define F367CAB_AGC_RF_BWSEL 0xf4120070
2894#define F367CAB_AGC_RF_FREEZE 0xf4120002
2895
2896/* AGC_PWM_CFG */
2897#define R367CAB_AGC_PWM_CFG 0xf413
2898#define F367CAB_AGC_RF_PWM_TST 0xf4130080
2899#define F367CAB_AGC_RF_PWM_INV 0xf4130040
2900#define F367CAB_AGC_IF_PWM_TST 0xf4130008
2901#define F367CAB_AGC_IF_PWM_INV 0xf4130004
2902#define F367CAB_AGC_PWM_CLKDIV 0xf4130003
2903
2904/* AGC_PWR_REF_L */
2905#define R367CAB_AGC_PWR_REF_L 0xf414
2906#define F367CAB_AGC_PWRREF_LO 0xf41400ff
2907
2908/* AGC_PWR_REF_H */
2909#define R367CAB_AGC_PWR_REF_H 0xf415
2910#define F367CAB_AGC_PWRREF_HI 0xf4150003
2911
2912/* AGC_RF_TH_L */
2913#define R367CAB_AGC_RF_TH_L 0xf416
2914#define F367CAB_AGC_RF_TH_LO 0xf41600ff
2915
2916/* AGC_RF_TH_H */
2917#define R367CAB_AGC_RF_TH_H 0xf417
2918#define F367CAB_AGC_RF_TH_HI 0xf417000f
2919
2920/* AGC_IF_LTH_L */
2921#define R367CAB_AGC_IF_LTH_L 0xf418
2922#define F367CAB_AGC_IF_THLO_LO 0xf41800ff
2923
2924/* AGC_IF_LTH_H */
2925#define R367CAB_AGC_IF_LTH_H 0xf419
2926#define F367CAB_AGC_IF_THLO_HI 0xf419000f
2927
2928/* AGC_IF_HTH_L */
2929#define R367CAB_AGC_IF_HTH_L 0xf41a
2930#define F367CAB_AGC_IF_THHI_LO 0xf41a00ff
2931
2932/* AGC_IF_HTH_H */
2933#define R367CAB_AGC_IF_HTH_H 0xf41b
2934#define F367CAB_AGC_IF_THHI_HI 0xf41b000f
2935
2936/* AGC_PWR_RD_L */
2937#define R367CAB_AGC_PWR_RD_L 0xf41c
2938#define F367CAB_AGC_PWR_WORD_LO 0xf41c00ff
2939
2940/* AGC_PWR_RD_M */
2941#define R367CAB_AGC_PWR_RD_M 0xf41d
2942#define F367CAB_AGC_PWR_WORD_ME 0xf41d00ff
2943
2944/* AGC_PWR_RD_H */
2945#define R367CAB_AGC_PWR_RD_H 0xf41e
2946#define F367CAB_AGC_PWR_WORD_HI 0xf41e0003
2947
2948/* AGC_PWM_IFCMD_L */
2949#define R367CAB_AGC_PWM_IFCMD_L 0xf420
2950#define F367CAB_AGC_IF_PWMCMD_LO 0xf42000ff
2951
2952/* AGC_PWM_IFCMD_H */
2953#define R367CAB_AGC_PWM_IFCMD_H 0xf421
2954#define F367CAB_AGC_IF_PWMCMD_HI 0xf421000f
2955
2956/* AGC_PWM_RFCMD_L */
2957#define R367CAB_AGC_PWM_RFCMD_L 0xf422
2958#define F367CAB_AGC_RF_PWMCMD_LO 0xf42200ff
2959
2960/* AGC_PWM_RFCMD_H */
2961#define R367CAB_AGC_PWM_RFCMD_H 0xf423
2962#define F367CAB_AGC_RF_PWMCMD_HI 0xf423000f
2963
2964/* IQDEM_CFG */
2965#define R367CAB_IQDEM_CFG 0xf424
2966#define F367CAB_IQDEM_CLK_SEL 0xf4240004
2967#define F367CAB_IQDEM_INVIQ 0xf4240002
2968#define F367CAB_IQDEM_A2dTYPE 0xf4240001
2969
2970/* MIX_NCO_LL */
2971#define R367CAB_MIX_NCO_LL 0xf425
2972#define F367CAB_MIX_NCO_INC_LL 0xf42500ff
2973
2974/* MIX_NCO_HL */
2975#define R367CAB_MIX_NCO_HL 0xf426
2976#define F367CAB_MIX_NCO_INC_HL 0xf42600ff
2977
2978/* MIX_NCO_HH */
2979#define R367CAB_MIX_NCO_HH 0xf427
2980#define F367CAB_MIX_NCO_INVCNST 0xf4270080
2981#define F367CAB_MIX_NCO_INC_HH 0xf427007f
2982
2983/* SRC_NCO_LL */
2984#define R367CAB_SRC_NCO_LL 0xf428
2985#define F367CAB_SRC_NCO_INC_LL 0xf42800ff
2986
2987/* SRC_NCO_LH */
2988#define R367CAB_SRC_NCO_LH 0xf429
2989#define F367CAB_SRC_NCO_INC_LH 0xf42900ff
2990
2991/* SRC_NCO_HL */
2992#define R367CAB_SRC_NCO_HL 0xf42a
2993#define F367CAB_SRC_NCO_INC_HL 0xf42a00ff
2994
2995/* SRC_NCO_HH */
2996#define R367CAB_SRC_NCO_HH 0xf42b
2997#define F367CAB_SRC_NCO_INC_HH 0xf42b007f
2998
2999/* IQDEM_GAIN_SRC_L */
3000#define R367CAB_IQDEM_GAIN_SRC_L 0xf42c
3001#define F367CAB_GAIN_SRC_LO 0xf42c00ff
3002
3003/* IQDEM_GAIN_SRC_H */
3004#define R367CAB_IQDEM_GAIN_SRC_H 0xf42d
3005#define F367CAB_GAIN_SRC_HI 0xf42d0003
3006
3007/* IQDEM_DCRM_CFG_LL */
3008#define R367CAB_IQDEM_DCRM_CFG_LL 0xf430
3009#define F367CAB_DCRM0_DCIN_L 0xf43000ff
3010
3011/* IQDEM_DCRM_CFG_LH */
3012#define R367CAB_IQDEM_DCRM_CFG_LH 0xf431
3013#define F367CAB_DCRM1_I_DCIN_L 0xf43100fc
3014#define F367CAB_DCRM0_DCIN_H 0xf4310003
3015
3016/* IQDEM_DCRM_CFG_HL */
3017#define R367CAB_IQDEM_DCRM_CFG_HL 0xf432
3018#define F367CAB_DCRM1_Q_DCIN_L 0xf43200f0
3019#define F367CAB_DCRM1_I_DCIN_H 0xf432000f
3020
3021/* IQDEM_DCRM_CFG_HH */
3022#define R367CAB_IQDEM_DCRM_CFG_HH 0xf433
3023#define F367CAB_DCRM1_FRZ 0xf4330080
3024#define F367CAB_DCRM0_FRZ 0xf4330040
3025#define F367CAB_DCRM1_Q_DCIN_H 0xf433003f
3026
3027/* IQDEM_ADJ_COEFf0 */
3028#define R367CAB_IQDEM_ADJ_COEFF0 0xf434
3029#define F367CAB_ADJIIR_COEFF10_L 0xf43400ff
3030
3031/* IQDEM_ADJ_COEFF1 */
3032#define R367CAB_IQDEM_ADJ_COEFF1 0xf435
3033#define F367CAB_ADJIIR_COEFF11_L 0xf43500fc
3034#define F367CAB_ADJIIR_COEFF10_H 0xf4350003
3035
3036/* IQDEM_ADJ_COEFF2 */
3037#define R367CAB_IQDEM_ADJ_COEFF2 0xf436
3038#define F367CAB_ADJIIR_COEFF12_L 0xf43600f0
3039#define F367CAB_ADJIIR_COEFF11_H 0xf436000f
3040
3041/* IQDEM_ADJ_COEFF3 */
3042#define R367CAB_IQDEM_ADJ_COEFF3 0xf437
3043#define F367CAB_ADJIIR_COEFF20_L 0xf43700c0
3044#define F367CAB_ADJIIR_COEFF12_H 0xf437003f
3045
3046/* IQDEM_ADJ_COEFF4 */
3047#define R367CAB_IQDEM_ADJ_COEFF4 0xf438
3048#define F367CAB_ADJIIR_COEFF20_H 0xf43800ff
3049
3050/* IQDEM_ADJ_COEFF5 */
3051#define R367CAB_IQDEM_ADJ_COEFF5 0xf439
3052#define F367CAB_ADJIIR_COEFF21_L 0xf43900ff
3053
3054/* IQDEM_ADJ_COEFF6 */
3055#define R367CAB_IQDEM_ADJ_COEFF6 0xf43a
3056#define F367CAB_ADJIIR_COEFF22_L 0xf43a00fc
3057#define F367CAB_ADJIIR_COEFF21_H 0xf43a0003
3058
3059/* IQDEM_ADJ_COEFF7 */
3060#define R367CAB_IQDEM_ADJ_COEFF7 0xf43b
3061#define F367CAB_ADJIIR_COEFF22_H 0xf43b000f
3062
3063/* IQDEM_ADJ_EN */
3064#define R367CAB_IQDEM_ADJ_EN 0xf43c
3065#define F367CAB_ALLPASSFILT_EN 0xf43c0008
3066#define F367CAB_ADJ_AGC_EN 0xf43c0004
3067#define F367CAB_ADJ_COEFF_FRZ 0xf43c0002
3068#define F367CAB_ADJ_EN 0xf43c0001
3069
3070/* IQDEM_ADJ_AGC_REF */
3071#define R367CAB_IQDEM_ADJ_AGC_REF 0xf43d
3072#define F367CAB_ADJ_AGC_REF 0xf43d00ff
3073
3074/* ALLPASSFILT1 */
3075#define R367CAB_ALLPASSFILT1 0xf440
3076#define F367CAB_ALLPASSFILT_COEFF1_LO 0xf44000ff
3077
3078/* ALLPASSFILT2 */
3079#define R367CAB_ALLPASSFILT2 0xf441
3080#define F367CAB_ALLPASSFILT_COEFF1_ME 0xf44100ff
3081
3082/* ALLPASSFILT3 */
3083#define R367CAB_ALLPASSFILT3 0xf442
3084#define F367CAB_ALLPASSFILT_COEFF2_LO 0xf44200c0
3085#define F367CAB_ALLPASSFILT_COEFF1_HI 0xf442003f
3086
3087/* ALLPASSFILT4 */
3088#define R367CAB_ALLPASSFILT4 0xf443
3089#define F367CAB_ALLPASSFILT_COEFF2_MEL 0xf44300ff
3090
3091/* ALLPASSFILT5 */
3092#define R367CAB_ALLPASSFILT5 0xf444
3093#define F367CAB_ALLPASSFILT_COEFF2_MEH 0xf44400ff
3094
3095/* ALLPASSFILT6 */
3096#define R367CAB_ALLPASSFILT6 0xf445
3097#define F367CAB_ALLPASSFILT_COEFF3_LO 0xf44500f0
3098#define F367CAB_ALLPASSFILT_COEFF2_HI 0xf445000f
3099
3100/* ALLPASSFILT7 */
3101#define R367CAB_ALLPASSFILT7 0xf446
3102#define F367CAB_ALLPASSFILT_COEFF3_MEL 0xf44600ff
3103
3104/* ALLPASSFILT8 */
3105#define R367CAB_ALLPASSFILT8 0xf447
3106#define F367CAB_ALLPASSFILT_COEFF3_MEH 0xf44700ff
3107
3108/* ALLPASSFILT9 */
3109#define R367CAB_ALLPASSFILT9 0xf448
3110#define F367CAB_ALLPASSFILT_COEFF4_LO 0xf44800fc
3111#define F367CAB_ALLPASSFILT_COEFF3_HI 0xf4480003
3112
3113/* ALLPASSFILT10 */
3114#define R367CAB_ALLPASSFILT10 0xf449
3115#define F367CAB_ALLPASSFILT_COEFF4_ME 0xf44900ff
3116
3117/* ALLPASSFILT11 */
3118#define R367CAB_ALLPASSFILT11 0xf44a
3119#define F367CAB_ALLPASSFILT_COEFF4_HI 0xf44a00ff
3120
3121/* TRL_AGC_CFG */
3122#define R367CAB_TRL_AGC_CFG 0xf450
3123#define F367CAB_TRL_AGC_FREEZE 0xf4500080
3124#define F367CAB_TRL_AGC_REF 0xf450007f
3125
3126/* TRL_LPF_CFG */
3127#define R367CAB_TRL_LPF_CFG 0xf454
3128#define F367CAB_NYQPOINT_INV 0xf4540040
3129#define F367CAB_TRL_SHIFT 0xf4540030
3130#define F367CAB_NYQ_COEFF_SEL 0xf454000c
3131#define F367CAB_TRL_LPF_FREEZE 0xf4540002
3132#define F367CAB_TRL_LPF_CRT 0xf4540001
3133
3134/* TRL_LPF_ACQ_GAIN */
3135#define R367CAB_TRL_LPF_ACQ_GAIN 0xf455
3136#define F367CAB_TRL_GDIR_ACQ 0xf4550070
3137#define F367CAB_TRL_GINT_ACQ 0xf4550007
3138
3139/* TRL_LPF_TRK_GAIN */
3140#define R367CAB_TRL_LPF_TRK_GAIN 0xf456
3141#define F367CAB_TRL_GDIR_TRK 0xf4560070
3142#define F367CAB_TRL_GINT_TRK 0xf4560007
3143
3144/* TRL_LPF_OUT_GAIN */
3145#define R367CAB_TRL_LPF_OUT_GAIN 0xf457
3146#define F367CAB_TRL_GAIN_OUT 0xf4570007
3147
3148/* TRL_LOCKDET_LTH */
3149#define R367CAB_TRL_LOCKDET_LTH 0xf458
3150#define F367CAB_TRL_LCK_THLO 0xf4580007
3151
3152/* TRL_LOCKDET_HTH */
3153#define R367CAB_TRL_LOCKDET_HTH 0xf459
3154#define F367CAB_TRL_LCK_THHI 0xf45900ff
3155
3156/* TRL_LOCKDET_TRGVAL */
3157#define R367CAB_TRL_LOCKDET_TRGVAL 0xf45a
3158#define F367CAB_TRL_LCK_TRG 0xf45a00ff
3159
3160/* IQ_QAM */
3161#define R367CAB_IQ_QAM 0xf45c
3162#define F367CAB_IQ_INPUT 0xf45c0008
3163#define F367CAB_DETECT_MODE 0xf45c0007
3164
3165/* FSM_STATE */
3166#define R367CAB_FSM_STATE 0xf460
3167#define F367CAB_CRL_DFE 0xf4600080
3168#define F367CAB_DFE_START 0xf4600040
3169#define F367CAB_CTRLG_START 0xf4600030
3170#define F367CAB_FSM_FORCESTATE 0xf460000f
3171
3172/* FSM_CTL */
3173#define R367CAB_FSM_CTL 0xf461
3174#define F367CAB_FEC2_EN 0xf4610040
3175#define F367CAB_SIT_EN 0xf4610020
3176#define F367CAB_TRL_AHEAD 0xf4610010
3177#define F367CAB_TRL2_EN 0xf4610008
3178#define F367CAB_FSM_EQA1_EN 0xf4610004
3179#define F367CAB_FSM_BKP_DIS 0xf4610002
3180#define F367CAB_FSM_FORCE_EN 0xf4610001
3181
3182/* FSM_STS */
3183#define R367CAB_FSM_STS 0xf462
3184#define F367CAB_FSM_STATUS 0xf462000f
3185
3186/* FSM_SNR0_HTH */
3187#define R367CAB_FSM_SNR0_HTH 0xf463
3188#define F367CAB_SNR0_HTH 0xf46300ff
3189
3190/* FSM_SNR1_HTH */
3191#define R367CAB_FSM_SNR1_HTH 0xf464
3192#define F367CAB_SNR1_HTH 0xf46400ff
3193
3194/* FSM_SNR2_HTH */
3195#define R367CAB_FSM_SNR2_HTH 0xf465
3196#define F367CAB_SNR2_HTH 0xf46500ff
3197
3198/* FSM_SNR0_LTH */
3199#define R367CAB_FSM_SNR0_LTH 0xf466
3200#define F367CAB_SNR0_LTH 0xf46600ff
3201
3202/* FSM_SNR1_LTH */
3203#define R367CAB_FSM_SNR1_LTH 0xf467
3204#define F367CAB_SNR1_LTH 0xf46700ff
3205
3206/* FSM_EQA1_HTH */
3207#define R367CAB_FSM_EQA1_HTH 0xf468
3208#define F367CAB_SNR3_HTH_LO 0xf46800f0
3209#define F367CAB_EQA1_HTH 0xf468000f
3210
3211/* FSM_TEMPO */
3212#define R367CAB_FSM_TEMPO 0xf469
3213#define F367CAB_SIT 0xf46900c0
3214#define F367CAB_WST 0xf4690038
3215#define F367CAB_ELT 0xf4690006
3216#define F367CAB_SNR3_HTH_HI 0xf4690001
3217
3218/* FSM_CONFIG */
3219#define R367CAB_FSM_CONFIG 0xf46a
3220#define F367CAB_FEC2_DFEOFF 0xf46a0004
3221#define F367CAB_PRIT_STATE 0xf46a0002
3222#define F367CAB_MODMAP_STATE 0xf46a0001
3223
3224/* EQU_I_TESTTAP_L */
3225#define R367CAB_EQU_I_TESTTAP_L 0xf474
3226#define F367CAB_I_TEST_TAP_L 0xf47400ff
3227
3228/* EQU_I_TESTTAP_M */
3229#define R367CAB_EQU_I_TESTTAP_M 0xf475
3230#define F367CAB_I_TEST_TAP_M 0xf47500ff
3231
3232/* EQU_I_TESTTAP_H */
3233#define R367CAB_EQU_I_TESTTAP_H 0xf476
3234#define F367CAB_I_TEST_TAP_H 0xf476001f
3235
3236/* EQU_TESTAP_CFG */
3237#define R367CAB_EQU_TESTAP_CFG 0xf477
3238#define F367CAB_TEST_FFE_DFE_SEL 0xf4770040
3239#define F367CAB_TEST_TAP_SELECT 0xf477003f
3240
3241/* EQU_Q_TESTTAP_L */
3242#define R367CAB_EQU_Q_TESTTAP_L 0xf478
3243#define F367CAB_Q_TEST_TAP_L 0xf47800ff
3244
3245/* EQU_Q_TESTTAP_M */
3246#define R367CAB_EQU_Q_TESTTAP_M 0xf479
3247#define F367CAB_Q_TEST_TAP_M 0xf47900ff
3248
3249/* EQU_Q_TESTTAP_H */
3250#define R367CAB_EQU_Q_TESTTAP_H 0xf47a
3251#define F367CAB_Q_TEST_TAP_H 0xf47a001f
3252
3253/* EQU_TAP_CTRL */
3254#define R367CAB_EQU_TAP_CTRL 0xf47b
3255#define F367CAB_MTAP_FRZ 0xf47b0010
3256#define F367CAB_PRE_FREEZE 0xf47b0008
3257#define F367CAB_DFE_TAPMON_EN 0xf47b0004
3258#define F367CAB_FFE_TAPMON_EN 0xf47b0002
3259#define F367CAB_MTAP_ONLY 0xf47b0001
3260
3261/* EQU_CTR_CRL_CONTROL_L */
3262#define R367CAB_EQU_CTR_CRL_CONTROL_L 0xf47c
3263#define F367CAB_EQU_CTR_CRL_CONTROL_LO 0xf47c00ff
3264
3265/* EQU_CTR_CRL_CONTROL_H */
3266#define R367CAB_EQU_CTR_CRL_CONTROL_H 0xf47d
3267#define F367CAB_EQU_CTR_CRL_CONTROL_HI 0xf47d00ff
3268
3269/* EQU_CTR_HIPOW_L */
3270#define R367CAB_EQU_CTR_HIPOW_L 0xf47e
3271#define F367CAB_CTR_HIPOW_L 0xf47e00ff
3272
3273/* EQU_CTR_HIPOW_H */
3274#define R367CAB_EQU_CTR_HIPOW_H 0xf47f
3275#define F367CAB_CTR_HIPOW_H 0xf47f00ff
3276
3277/* EQU_I_EQU_LO */
3278#define R367CAB_EQU_I_EQU_LO 0xf480
3279#define F367CAB_EQU_I_EQU_L 0xf48000ff
3280
3281/* EQU_I_EQU_HI */
3282#define R367CAB_EQU_I_EQU_HI 0xf481
3283#define F367CAB_EQU_I_EQU_H 0xf4810003
3284
3285/* EQU_Q_EQU_LO */
3286#define R367CAB_EQU_Q_EQU_LO 0xf482
3287#define F367CAB_EQU_Q_EQU_L 0xf48200ff
3288
3289/* EQU_Q_EQU_HI */
3290#define R367CAB_EQU_Q_EQU_HI 0xf483
3291#define F367CAB_EQU_Q_EQU_H 0xf4830003
3292
3293/* EQU_MAPPER */
3294#define R367CAB_EQU_MAPPER 0xf484
3295#define F367CAB_QUAD_AUTO 0xf4840080
3296#define F367CAB_QUAD_INV 0xf4840040
3297#define F367CAB_QAM_MODE 0xf4840007
3298
3299/* EQU_SWEEP_RATE */
3300#define R367CAB_EQU_SWEEP_RATE 0xf485
3301#define F367CAB_SNR_PER 0xf48500c0
3302#define F367CAB_SWEEP_RATE 0xf485003f
3303
3304/* EQU_SNR_LO */
3305#define R367CAB_EQU_SNR_LO 0xf486
3306#define F367CAB_SNR_LO 0xf48600ff
3307
3308/* EQU_SNR_HI */
3309#define R367CAB_EQU_SNR_HI 0xf487
3310#define F367CAB_SNR_HI 0xf48700ff
3311
3312/* EQU_GAMMA_LO */
3313#define R367CAB_EQU_GAMMA_LO 0xf488
3314#define F367CAB_GAMMA_LO 0xf48800ff
3315
3316/* EQU_GAMMA_HI */
3317#define R367CAB_EQU_GAMMA_HI 0xf489
3318#define F367CAB_GAMMA_ME 0xf48900ff
3319
3320/* EQU_ERR_GAIN */
3321#define R367CAB_EQU_ERR_GAIN 0xf48a
3322#define F367CAB_EQA1MU 0xf48a0070
3323#define F367CAB_CRL2MU 0xf48a000e
3324#define F367CAB_GAMMA_HI 0xf48a0001
3325
3326/* EQU_RADIUS */
3327#define R367CAB_EQU_RADIUS 0xf48b
3328#define F367CAB_RADIUS 0xf48b00ff
3329
3330/* EQU_FFE_MAINTAP */
3331#define R367CAB_EQU_FFE_MAINTAP 0xf48c
3332#define F367CAB_FFE_MAINTAP_INIT 0xf48c00ff
3333
3334/* EQU_FFE_LEAKAGE */
3335#define R367CAB_EQU_FFE_LEAKAGE 0xf48e
3336#define F367CAB_LEAK_PER 0xf48e00f0
3337#define F367CAB_EQU_OUTSEL 0xf48e0002
3338#define F367CAB_PNT2dFE 0xf48e0001
3339
3340/* EQU_FFE_MAINTAP_POS */
3341#define R367CAB_EQU_FFE_MAINTAP_POS 0xf48f
3342#define F367CAB_FFE_LEAK_EN 0xf48f0080
3343#define F367CAB_DFE_LEAK_EN 0xf48f0040
3344#define F367CAB_FFE_MAINTAP_POS 0xf48f003f
3345
3346/* EQU_GAIN_WIDE */
3347#define R367CAB_EQU_GAIN_WIDE 0xf490
3348#define F367CAB_DFE_GAIN_WIDE 0xf49000f0
3349#define F367CAB_FFE_GAIN_WIDE 0xf490000f
3350
3351/* EQU_GAIN_NARROW */
3352#define R367CAB_EQU_GAIN_NARROW 0xf491
3353#define F367CAB_DFE_GAIN_NARROW 0xf49100f0
3354#define F367CAB_FFE_GAIN_NARROW 0xf491000f
3355
3356/* EQU_CTR_LPF_GAIN */
3357#define R367CAB_EQU_CTR_LPF_GAIN 0xf492
3358#define F367CAB_CTR_GTO 0xf4920080
3359#define F367CAB_CTR_GDIR 0xf4920070
3360#define F367CAB_SWEEP_EN 0xf4920008
3361#define F367CAB_CTR_GINT 0xf4920007
3362
3363/* EQU_CRL_LPF_GAIN */
3364#define R367CAB_EQU_CRL_LPF_GAIN 0xf493
3365#define F367CAB_CRL_GTO 0xf4930080
3366#define F367CAB_CRL_GDIR 0xf4930070
3367#define F367CAB_SWEEP_DIR 0xf4930008
3368#define F367CAB_CRL_GINT 0xf4930007
3369
3370/* EQU_GLOBAL_GAIN */
3371#define R367CAB_EQU_GLOBAL_GAIN 0xf494
3372#define F367CAB_CRL_GAIN 0xf49400f8
3373#define F367CAB_CTR_INC_GAIN 0xf4940004
3374#define F367CAB_CTR_FRAC 0xf4940003
3375
3376/* EQU_CRL_LD_SEN */
3377#define R367CAB_EQU_CRL_LD_SEN 0xf495
3378#define F367CAB_CTR_BADPOINT_EN 0xf4950080
3379#define F367CAB_CTR_GAIN 0xf4950070
3380#define F367CAB_LIMANEN 0xf4950008
3381#define F367CAB_CRL_LD_SEN 0xf4950007
3382
3383/* EQU_CRL_LD_VAL */
3384#define R367CAB_EQU_CRL_LD_VAL 0xf496
3385#define F367CAB_CRL_BISTH_LIMIT 0xf4960080
3386#define F367CAB_CARE_EN 0xf4960040
3387#define F367CAB_CRL_LD_PER 0xf4960030
3388#define F367CAB_CRL_LD_WST 0xf496000c
3389#define F367CAB_CRL_LD_TFS 0xf4960003
3390
3391/* EQU_CRL_TFR */
3392#define R367CAB_EQU_CRL_TFR 0xf497
3393#define F367CAB_CRL_LD_TFR 0xf49700ff
3394
3395/* EQU_CRL_BISTH_LO */
3396#define R367CAB_EQU_CRL_BISTH_LO 0xf498
3397#define F367CAB_CRL_BISTH_LO 0xf49800ff
3398
3399/* EQU_CRL_BISTH_HI */
3400#define R367CAB_EQU_CRL_BISTH_HI 0xf499
3401#define F367CAB_CRL_BISTH_HI 0xf49900ff
3402
3403/* EQU_SWEEP_RANGE_LO */
3404#define R367CAB_EQU_SWEEP_RANGE_LO 0xf49a
3405#define F367CAB_SWEEP_RANGE_LO 0xf49a00ff
3406
3407/* EQU_SWEEP_RANGE_HI */
3408#define R367CAB_EQU_SWEEP_RANGE_HI 0xf49b
3409#define F367CAB_SWEEP_RANGE_HI 0xf49b00ff
3410
3411/* EQU_CRL_LIMITER */
3412#define R367CAB_EQU_CRL_LIMITER 0xf49c
3413#define F367CAB_BISECTOR_EN 0xf49c0080
3414#define F367CAB_PHEST128_EN 0xf49c0040
3415#define F367CAB_CRL_LIM 0xf49c003f
3416
3417/* EQU_MODULUS_MAP */
3418#define R367CAB_EQU_MODULUS_MAP 0xf49d
3419#define F367CAB_PNT_DEPTH 0xf49d00e0
3420#define F367CAB_MODULUS_CMP 0xf49d001f
3421
3422/* EQU_PNT_GAIN */
3423#define R367CAB_EQU_PNT_GAIN 0xf49e
3424#define F367CAB_PNT_EN 0xf49e0080
3425#define F367CAB_MODULUSMAP_EN 0xf49e0040
3426#define F367CAB_PNT_GAIN 0xf49e003f
3427
3428/* FEC_AC_CTR_0 */
3429#define R367CAB_FEC_AC_CTR_0 0xf4a8
3430#define F367CAB_BE_BYPASS 0xf4a80020
3431#define F367CAB_REFRESH47 0xf4a80010
3432#define F367CAB_CT_NBST 0xf4a80008
3433#define F367CAB_TEI_ENA 0xf4a80004
3434#define F367CAB_DS_ENA 0xf4a80002
3435#define F367CAB_TSMF_EN 0xf4a80001
3436
3437/* FEC_AC_CTR_1 */
3438#define R367CAB_FEC_AC_CTR_1 0xf4a9
3439#define F367CAB_DEINT_DEPTH 0xf4a900ff
3440
3441/* FEC_AC_CTR_2 */
3442#define R367CAB_FEC_AC_CTR_2 0xf4aa
3443#define F367CAB_DEINT_M 0xf4aa00f8
3444#define F367CAB_DIS_UNLOCK 0xf4aa0004
3445#define F367CAB_DESCR_MODE 0xf4aa0003
3446
3447/* FEC_AC_CTR_3 */
3448#define R367CAB_FEC_AC_CTR_3 0xf4ab
3449#define F367CAB_DI_UNLOCK 0xf4ab0080
3450#define F367CAB_DI_FREEZE 0xf4ab0040
3451#define F367CAB_MISMATCH 0xf4ab0030
3452#define F367CAB_ACQ_MODE 0xf4ab000c
3453#define F367CAB_TRK_MODE 0xf4ab0003
3454
3455/* FEC_STATUS */
3456#define R367CAB_FEC_STATUS 0xf4ac
3457#define F367CAB_DEINT_SMCNTR 0xf4ac00e0
3458#define F367CAB_DEINT_SYNCSTATE 0xf4ac0018
3459#define F367CAB_DEINT_SYNLOST 0xf4ac0004
3460#define F367CAB_DESCR_SYNCSTATE 0xf4ac0002
3461
3462/* RS_COUNTER_0 */
3463#define R367CAB_RS_COUNTER_0 0xf4ae
3464#define F367CAB_BK_CT_L 0xf4ae00ff
3465
3466/* RS_COUNTER_1 */
3467#define R367CAB_RS_COUNTER_1 0xf4af
3468#define F367CAB_BK_CT_H 0xf4af00ff
3469
3470/* RS_COUNTER_2 */
3471#define R367CAB_RS_COUNTER_2 0xf4b0
3472#define F367CAB_CORR_CT_L 0xf4b000ff
3473
3474/* RS_COUNTER_3 */
3475#define R367CAB_RS_COUNTER_3 0xf4b1
3476#define F367CAB_CORR_CT_H 0xf4b100ff
3477
3478/* RS_COUNTER_4 */
3479#define R367CAB_RS_COUNTER_4 0xf4b2
3480#define F367CAB_UNCORR_CT_L 0xf4b200ff
3481
3482/* RS_COUNTER_5 */
3483#define R367CAB_RS_COUNTER_5 0xf4b3
3484#define F367CAB_UNCORR_CT_H 0xf4b300ff
3485
3486/* BERT_0 */
3487#define R367CAB_BERT_0 0xf4b4
3488#define F367CAB_RS_NOCORR 0xf4b40004
3489#define F367CAB_CT_HOLD 0xf4b40002
3490#define F367CAB_CT_CLEAR 0xf4b40001
3491
3492/* BERT_1 */
3493#define R367CAB_BERT_1 0xf4b5
3494#define F367CAB_BERT_ON 0xf4b50020
3495#define F367CAB_BERT_ERR_SRC 0xf4b50010
3496#define F367CAB_BERT_ERR_MODE 0xf4b50008
3497#define F367CAB_BERT_NBYTE 0xf4b50007
3498
3499/* BERT_2 */
3500#define R367CAB_BERT_2 0xf4b6
3501#define F367CAB_BERT_ERRCOUNT_L 0xf4b600ff
3502
3503/* BERT_3 */
3504#define R367CAB_BERT_3 0xf4b7
3505#define F367CAB_BERT_ERRCOUNT_H 0xf4b700ff
3506
3507/* OUTFORMAT_0 */
3508#define R367CAB_OUTFORMAT_0 0xf4b8
3509#define F367CAB_CLK_POLARITY 0xf4b80080
3510#define F367CAB_FEC_TYPE 0xf4b80040
3511#define F367CAB_SYNC_STRIP 0xf4b80008
3512#define F367CAB_TS_SWAP 0xf4b80004
3513#define F367CAB_OUTFORMAT 0xf4b80003
3514
3515/* OUTFORMAT_1 */
3516#define R367CAB_OUTFORMAT_1 0xf4b9
3517#define F367CAB_CI_DIVRANGE 0xf4b900ff
3518
3519/* SMOOTHER_2 */
3520#define R367CAB_SMOOTHER_2 0xf4be
3521#define F367CAB_FIFO_BYPASS 0xf4be0020
3522
3523/* TSMF_CTRL_0 */
3524#define R367CAB_TSMF_CTRL_0 0xf4c0
3525#define F367CAB_TS_NUMBER 0xf4c0001e
3526#define F367CAB_SEL_MODE 0xf4c00001
3527
3528/* TSMF_CTRL_1 */
3529#define R367CAB_TSMF_CTRL_1 0xf4c1
3530#define F367CAB_CHECK_ERROR_BIT 0xf4c10080
3531#define F367CAB_CHCK_F_SYNC 0xf4c10040
3532#define F367CAB_H_MODE 0xf4c10008
3533#define F367CAB_D_V_MODE 0xf4c10004
3534#define F367CAB_MODE 0xf4c10003
3535
3536/* TSMF_CTRL_3 */
3537#define R367CAB_TSMF_CTRL_3 0xf4c3
3538#define F367CAB_SYNC_IN_COUNT 0xf4c300f0
3539#define F367CAB_SYNC_OUT_COUNT 0xf4c3000f
3540
3541/* TS_ON_ID_0 */
3542#define R367CAB_TS_ON_ID_0 0xf4c4
3543#define F367CAB_TS_ID_L 0xf4c400ff
3544
3545/* TS_ON_ID_1 */
3546#define R367CAB_TS_ON_ID_1 0xf4c5
3547#define F367CAB_TS_ID_H 0xf4c500ff
3548
3549/* TS_ON_ID_2 */
3550#define R367CAB_TS_ON_ID_2 0xf4c6
3551#define F367CAB_ON_ID_L 0xf4c600ff
3552
3553/* TS_ON_ID_3 */
3554#define R367CAB_TS_ON_ID_3 0xf4c7
3555#define F367CAB_ON_ID_H 0xf4c700ff
3556
3557/* RE_STATUS_0 */
3558#define R367CAB_RE_STATUS_0 0xf4c8
3559#define F367CAB_RECEIVE_STATUS_L 0xf4c800ff
3560
3561/* RE_STATUS_1 */
3562#define R367CAB_RE_STATUS_1 0xf4c9
3563#define F367CAB_RECEIVE_STATUS_LH 0xf4c900ff
3564
3565/* RE_STATUS_2 */
3566#define R367CAB_RE_STATUS_2 0xf4ca
3567#define F367CAB_RECEIVE_STATUS_HL 0xf4ca00ff
3568
3569/* RE_STATUS_3 */
3570#define R367CAB_RE_STATUS_3 0xf4cb
3571#define F367CAB_RECEIVE_STATUS_HH 0xf4cb003f
3572
3573/* TS_STATUS_0 */
3574#define R367CAB_TS_STATUS_0 0xf4cc
3575#define F367CAB_TS_STATUS_L 0xf4cc00ff
3576
3577/* TS_STATUS_1 */
3578#define R367CAB_TS_STATUS_1 0xf4cd
3579#define F367CAB_TS_STATUS_H 0xf4cd007f
3580
3581/* TS_STATUS_2 */
3582#define R367CAB_TS_STATUS_2 0xf4ce
3583#define F367CAB_ERROR 0xf4ce0080
3584#define F367CAB_EMERGENCY 0xf4ce0040
3585#define F367CAB_CRE_TS 0xf4ce0030
3586#define F367CAB_VER 0xf4ce000e
3587#define F367CAB_M_LOCK 0xf4ce0001
3588
3589/* TS_STATUS_3 */
3590#define R367CAB_TS_STATUS_3 0xf4cf
3591#define F367CAB_UPDATE_READY 0xf4cf0080
3592#define F367CAB_END_FRAME_HEADER 0xf4cf0040
3593#define F367CAB_CONTCNT 0xf4cf0020
3594#define F367CAB_TS_IDENTIFIER_SEL 0xf4cf000f
3595
3596/* T_O_ID_0 */
3597#define R367CAB_T_O_ID_0 0xf4d0
3598#define F367CAB_ON_ID_I_L 0xf4d000ff
3599
3600/* T_O_ID_1 */
3601#define R367CAB_T_O_ID_1 0xf4d1
3602#define F367CAB_ON_ID_I_H 0xf4d100ff
3603
3604/* T_O_ID_2 */
3605#define R367CAB_T_O_ID_2 0xf4d2
3606#define F367CAB_TS_ID_I_L 0xf4d200ff
3607
3608/* T_O_ID_3 */
3609#define R367CAB_T_O_ID_3 0xf4d3
3610#define F367CAB_TS_ID_I_H 0xf4d300ff
3611
3612#define STV0367CAB_NBREGS 187
3613
3614#endif
diff --git a/drivers/media/dvb/frontends/stv0900.h b/drivers/media/dvb/frontends/stv0900.h
index e3e35d1ce838..91c7ee8b2313 100644
--- a/drivers/media/dvb/frontends/stv0900.h
+++ b/drivers/media/dvb/frontends/stv0900.h
@@ -53,6 +53,8 @@ struct stv0900_config {
53 u8 tun2_type; 53 u8 tun2_type;
54 /* Set device param to start dma */ 54 /* Set device param to start dma */
55 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured); 55 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured);
56 /* Hook for Lock LED */
57 void (*set_lock_led)(struct dvb_frontend *fe, int offon);
56}; 58};
57 59
58#if defined(CONFIG_DVB_STV0900) || (defined(CONFIG_DVB_STV0900_MODULE) \ 60#if defined(CONFIG_DVB_STV0900) || (defined(CONFIG_DVB_STV0900_MODULE) \
diff --git a/drivers/media/dvb/frontends/stv0900_core.c b/drivers/media/dvb/frontends/stv0900_core.c
index 4f5e7d3a0e61..0ca316d6fffa 100644
--- a/drivers/media/dvb/frontends/stv0900_core.c
+++ b/drivers/media/dvb/frontends/stv0900_core.c
@@ -1604,6 +1604,9 @@ static enum dvbfe_search stv0900_search(struct dvb_frontend *fe,
1604 p_search.standard = STV0900_AUTO_SEARCH; 1604 p_search.standard = STV0900_AUTO_SEARCH;
1605 p_search.iq_inversion = STV0900_IQ_AUTO; 1605 p_search.iq_inversion = STV0900_IQ_AUTO;
1606 p_search.search_algo = STV0900_BLIND_SEARCH; 1606 p_search.search_algo = STV0900_BLIND_SEARCH;
1607 /* Speeds up DVB-S searching */
1608 if (c->delivery_system == SYS_DVBS)
1609 p_search.standard = STV0900_SEARCH_DVBS1;
1607 1610
1608 intp->srch_standard[demod] = p_search.standard; 1611 intp->srch_standard[demod] = p_search.standard;
1609 intp->symbol_rate[demod] = p_search.symbol_rate; 1612 intp->symbol_rate[demod] = p_search.symbol_rate;
@@ -1660,8 +1663,14 @@ static int stv0900_read_status(struct dvb_frontend *fe, enum fe_status *status)
1660 | FE_HAS_VITERBI 1663 | FE_HAS_VITERBI
1661 | FE_HAS_SYNC 1664 | FE_HAS_SYNC
1662 | FE_HAS_LOCK; 1665 | FE_HAS_LOCK;
1663 } else 1666 if (state->config->set_lock_led)
1667 state->config->set_lock_led(fe, 1);
1668 } else {
1669 *status = 0;
1670 if (state->config->set_lock_led)
1671 state->config->set_lock_led(fe, 0);
1664 dprintk("DEMOD LOCK FAIL\n"); 1672 dprintk("DEMOD LOCK FAIL\n");
1673 }
1665 1674
1666 return 0; 1675 return 0;
1667} 1676}
@@ -1831,6 +1840,9 @@ static void stv0900_release(struct dvb_frontend *fe)
1831 1840
1832 dprintk("%s\n", __func__); 1841 dprintk("%s\n", __func__);
1833 1842
1843 if (state->config->set_lock_led)
1844 state->config->set_lock_led(fe, 0);
1845
1834 if ((--(state->internal->dmds_used)) <= 0) { 1846 if ((--(state->internal->dmds_used)) <= 0) {
1835 1847
1836 dprintk("%s: Actually removing\n", __func__); 1848 dprintk("%s: Actually removing\n", __func__);
@@ -1842,6 +1854,18 @@ static void stv0900_release(struct dvb_frontend *fe)
1842 kfree(state); 1854 kfree(state);
1843} 1855}
1844 1856
1857static int stv0900_sleep(struct dvb_frontend *fe)
1858{
1859 struct stv0900_state *state = fe->demodulator_priv;
1860
1861 dprintk("%s\n", __func__);
1862
1863 if (state->config->set_lock_led)
1864 state->config->set_lock_led(fe, 0);
1865
1866 return 0;
1867}
1868
1845static int stv0900_get_frontend(struct dvb_frontend *fe, 1869static int stv0900_get_frontend(struct dvb_frontend *fe,
1846 struct dvb_frontend_parameters *p) 1870 struct dvb_frontend_parameters *p)
1847{ 1871{
@@ -1876,6 +1900,7 @@ static struct dvb_frontend_ops stv0900_ops = {
1876 .release = stv0900_release, 1900 .release = stv0900_release,
1877 .init = stv0900_init, 1901 .init = stv0900_init,
1878 .get_frontend = stv0900_get_frontend, 1902 .get_frontend = stv0900_get_frontend,
1903 .sleep = stv0900_sleep,
1879 .get_frontend_algo = stv0900_frontend_algo, 1904 .get_frontend_algo = stv0900_frontend_algo,
1880 .i2c_gate_ctrl = stv0900_i2c_gate_ctrl, 1905 .i2c_gate_ctrl = stv0900_i2c_gate_ctrl,
1881 .diseqc_send_master_cmd = stv0900_send_master_cmd, 1906 .diseqc_send_master_cmd = stv0900_send_master_cmd,
diff --git a/drivers/media/dvb/frontends/stv0900_priv.h b/drivers/media/dvb/frontends/stv0900_priv.h
index b62b0f0a4fef..e0ea74c8e093 100644
--- a/drivers/media/dvb/frontends/stv0900_priv.h
+++ b/drivers/media/dvb/frontends/stv0900_priv.h
@@ -238,7 +238,7 @@ enum fe_stv0900_demod_mode {
238}; 238};
239 239
240struct stv0900_init_params{ 240struct stv0900_init_params{
241 u32 dmd_ref_clk;/* Refrence,Input clock for the demod in Hz */ 241 u32 dmd_ref_clk;/* Reference,Input clock for the demod in Hz */
242 242
243 /* Demodulator Type (single demod or dual demod) */ 243 /* Demodulator Type (single demod or dual demod) */
244 enum fe_stv0900_demod_mode demod_mode; 244 enum fe_stv0900_demod_mode demod_mode;
diff --git a/drivers/media/dvb/frontends/stv090x.c b/drivers/media/dvb/frontends/stv090x.c
index 425e7a43ae19..52d8712411e5 100644
--- a/drivers/media/dvb/frontends/stv090x.c
+++ b/drivers/media/dvb/frontends/stv090x.c
@@ -767,8 +767,12 @@ static int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable)
767 * In case of any error, the lock is unlocked and exit within the 767 * In case of any error, the lock is unlocked and exit within the
768 * relevant operations themselves. 768 * relevant operations themselves.
769 */ 769 */
770 if (enable) 770 if (enable) {
771 mutex_lock(&state->internal->tuner_lock); 771 if (state->config->tuner_i2c_lock)
772 state->config->tuner_i2c_lock(&state->frontend, 1);
773 else
774 mutex_lock(&state->internal->tuner_lock);
775 }
772 776
773 reg = STV090x_READ_DEMOD(state, I2CRPT); 777 reg = STV090x_READ_DEMOD(state, I2CRPT);
774 if (enable) { 778 if (enable) {
@@ -784,13 +788,20 @@ static int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable)
784 goto err; 788 goto err;
785 } 789 }
786 790
787 if (!enable) 791 if (!enable) {
788 mutex_unlock(&state->internal->tuner_lock); 792 if (state->config->tuner_i2c_lock)
793 state->config->tuner_i2c_lock(&state->frontend, 0);
794 else
795 mutex_unlock(&state->internal->tuner_lock);
796 }
789 797
790 return 0; 798 return 0;
791err: 799err:
792 dprintk(FE_ERROR, 1, "I/O error"); 800 dprintk(FE_ERROR, 1, "I/O error");
793 mutex_unlock(&state->internal->tuner_lock); 801 if (state->config->tuner_i2c_lock)
802 state->config->tuner_i2c_lock(&state->frontend, 0);
803 else
804 mutex_unlock(&state->internal->tuner_lock);
794 return -1; 805 return -1;
795} 806}
796 807
@@ -1413,7 +1424,7 @@ static int stv090x_start_search(struct stv090x_state *state)
1413 if (STV090x_WRITE_DEMOD(state, CFRLOW0, 0x00) < 0) 1424 if (STV090x_WRITE_DEMOD(state, CFRLOW0, 0x00) < 0)
1414 goto err; 1425 goto err;
1415 1426
1416 /*enlarge the timing bandwith for Low SR*/ 1427 /*enlarge the timing bandwidth for Low SR*/
1417 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x68) < 0) 1428 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x68) < 0)
1418 goto err; 1429 goto err;
1419 } else { 1430 } else {
@@ -1421,17 +1432,17 @@ static int stv090x_start_search(struct stv090x_state *state)
1421 Set The carrier search up and low to auto mode */ 1432 Set The carrier search up and low to auto mode */
1422 if (STV090x_WRITE_DEMOD(state, CARCFG, 0xc4) < 0) 1433 if (STV090x_WRITE_DEMOD(state, CARCFG, 0xc4) < 0)
1423 goto err; 1434 goto err;
1424 /*reduce the timing bandwith for high SR*/ 1435 /*reduce the timing bandwidth for high SR*/
1425 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x44) < 0) 1436 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x44) < 0)
1426 goto err; 1437 goto err;
1427 } 1438 }
1428 } else { 1439 } else {
1429 /* >= Cut 3 */ 1440 /* >= Cut 3 */
1430 if (state->srate <= 5000000) { 1441 if (state->srate <= 5000000) {
1431 /* enlarge the timing bandwith for Low SR */ 1442 /* enlarge the timing bandwidth for Low SR */
1432 STV090x_WRITE_DEMOD(state, RTCS2, 0x68); 1443 STV090x_WRITE_DEMOD(state, RTCS2, 0x68);
1433 } else { 1444 } else {
1434 /* reduce timing bandwith for high SR */ 1445 /* reduce timing bandwidth for high SR */
1435 STV090x_WRITE_DEMOD(state, RTCS2, 0x44); 1446 STV090x_WRITE_DEMOD(state, RTCS2, 0x44);
1436 } 1447 }
1437 1448
@@ -1483,8 +1494,8 @@ static int stv090x_start_search(struct stv090x_state *state)
1483 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) 1494 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0)
1484 goto err; 1495 goto err;
1485 1496
1486 if ((state->search_mode == STV090x_DVBS1) || 1497 if ((state->search_mode == STV090x_SEARCH_DVBS1) ||
1487 (state->search_mode == STV090x_DSS) || 1498 (state->search_mode == STV090x_SEARCH_DSS) ||
1488 (state->search_mode == STV090x_SEARCH_AUTO)) { 1499 (state->search_mode == STV090x_SEARCH_AUTO)) {
1489 1500
1490 if (STV090x_WRITE_DEMOD(state, VITSCALE, 0x82) < 0) 1501 if (STV090x_WRITE_DEMOD(state, VITSCALE, 0x82) < 0)
@@ -2471,7 +2482,7 @@ static int stv090x_sw_algo(struct stv090x_state *state)
2471 dvbs2_fly_wheel = STV090x_GETFIELD_Px(reg, FLYWHEEL_CPT_FIELD); 2482 dvbs2_fly_wheel = STV090x_GETFIELD_Px(reg, FLYWHEEL_CPT_FIELD);
2472 } 2483 }
2473 if (dvbs2_fly_wheel < 0xd) { 2484 if (dvbs2_fly_wheel < 0xd) {
2474 /*FALSE lock, The demod is loosing lock */ 2485 /*FALSE lock, The demod is losing lock */
2475 lock = 0; 2486 lock = 0;
2476 if (trials < 2) { 2487 if (trials < 2) {
2477 if (state->internal->dev_ver >= 0x20) { 2488 if (state->internal->dev_ver >= 0x20) {
@@ -2883,10 +2894,12 @@ static int stv090x_optimize_track(struct stv090x_state *state)
2883 STV090x_SETFIELD_Px(reg, DVBS2_ENABLE_FIELD, 1); 2894 STV090x_SETFIELD_Px(reg, DVBS2_ENABLE_FIELD, 1);
2884 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) 2895 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0)
2885 goto err; 2896 goto err;
2886 if (STV090x_WRITE_DEMOD(state, ACLC, 0) < 0) 2897 if (state->internal->dev_ver >= 0x30) {
2887 goto err; 2898 if (STV090x_WRITE_DEMOD(state, ACLC, 0) < 0)
2888 if (STV090x_WRITE_DEMOD(state, BCLC, 0) < 0) 2899 goto err;
2889 goto err; 2900 if (STV090x_WRITE_DEMOD(state, BCLC, 0) < 0)
2901 goto err;
2902 }
2890 if (state->frame_len == STV090x_LONG_FRAME) { 2903 if (state->frame_len == STV090x_LONG_FRAME) {
2891 reg = STV090x_READ_DEMOD(state, DMDMODCOD); 2904 reg = STV090x_READ_DEMOD(state, DMDMODCOD);
2892 modcod = STV090x_GETFIELD_Px(reg, DEMOD_MODCOD_FIELD); 2905 modcod = STV090x_GETFIELD_Px(reg, DEMOD_MODCOD_FIELD);
@@ -2940,7 +2953,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
2940 STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x67); /* PER */ 2953 STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x67); /* PER */
2941 break; 2954 break;
2942 2955
2943 case STV090x_UNKNOWN: 2956 case STV090x_ERROR:
2944 default: 2957 default:
2945 reg = STV090x_READ_DEMOD(state, DMDCFGMD); 2958 reg = STV090x_READ_DEMOD(state, DMDCFGMD);
2946 STV090x_SETFIELD_Px(reg, DVBS1_ENABLE_FIELD, 1); 2959 STV090x_SETFIELD_Px(reg, DVBS1_ENABLE_FIELD, 1);
@@ -3189,7 +3202,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3189 goto err; 3202 goto err;
3190 if (STV090x_WRITE_DEMOD(state, CORRELMANT, 0x70) < 0) 3203 if (STV090x_WRITE_DEMOD(state, CORRELMANT, 0x70) < 0)
3191 goto err; 3204 goto err;
3192 if (stv090x_set_srate(state, 1000000) < 0) /* inital srate = 1Msps */ 3205 if (stv090x_set_srate(state, 1000000) < 0) /* initial srate = 1Msps */
3193 goto err; 3206 goto err;
3194 } else { 3207 } else {
3195 /* known srate */ 3208 /* known srate */
@@ -3846,6 +3859,7 @@ static int stv090x_sleep(struct dvb_frontend *fe)
3846{ 3859{
3847 struct stv090x_state *state = fe->demodulator_priv; 3860 struct stv090x_state *state = fe->demodulator_priv;
3848 u32 reg; 3861 u32 reg;
3862 u8 full_standby = 0;
3849 3863
3850 if (stv090x_i2c_gate_ctrl(state, 1) < 0) 3864 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
3851 goto err; 3865 goto err;
@@ -3858,24 +3872,119 @@ static int stv090x_sleep(struct dvb_frontend *fe)
3858 if (stv090x_i2c_gate_ctrl(state, 0) < 0) 3872 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
3859 goto err; 3873 goto err;
3860 3874
3861 dprintk(FE_DEBUG, 1, "Set %s to sleep", 3875 dprintk(FE_DEBUG, 1, "Set %s(%d) to sleep",
3862 state->device == STV0900 ? "STV0900" : "STV0903"); 3876 state->device == STV0900 ? "STV0900" : "STV0903",
3877 state->demod);
3863 3878
3864 reg = stv090x_read_reg(state, STV090x_SYNTCTRL); 3879 mutex_lock(&state->internal->demod_lock);
3865 STV090x_SETFIELD(reg, STANDBY_FIELD, 0x01);
3866 if (stv090x_write_reg(state, STV090x_SYNTCTRL, reg) < 0)
3867 goto err;
3868 3880
3869 reg = stv090x_read_reg(state, STV090x_TSTTNR1); 3881 switch (state->demod) {
3870 STV090x_SETFIELD(reg, ADC1_PON_FIELD, 0); 3882 case STV090x_DEMODULATOR_0:
3871 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0) 3883 /* power off ADC 1 */
3872 goto err; 3884 reg = stv090x_read_reg(state, STV090x_TSTTNR1);
3885 STV090x_SETFIELD(reg, ADC1_PON_FIELD, 0);
3886 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0)
3887 goto err;
3888 /* power off DiSEqC 1 */
3889 reg = stv090x_read_reg(state, STV090x_TSTTNR2);
3890 STV090x_SETFIELD(reg, DISEQC1_PON_FIELD, 0);
3891 if (stv090x_write_reg(state, STV090x_TSTTNR2, reg) < 0)
3892 goto err;
3893
3894 /* check whether path 2 is already sleeping, that is when
3895 ADC2 is off */
3896 reg = stv090x_read_reg(state, STV090x_TSTTNR3);
3897 if (STV090x_GETFIELD(reg, ADC2_PON_FIELD) == 0)
3898 full_standby = 1;
3899
3900 /* stop clocks */
3901 reg = stv090x_read_reg(state, STV090x_STOPCLK1);
3902 /* packet delineator 1 clock */
3903 STV090x_SETFIELD(reg, STOP_CLKPKDT1_FIELD, 1);
3904 /* ADC 1 clock */
3905 STV090x_SETFIELD(reg, STOP_CLKADCI1_FIELD, 1);
3906 /* FEC clock is shared between the two paths, only stop it
3907 when full standby is possible */
3908 if (full_standby)
3909 STV090x_SETFIELD(reg, STOP_CLKFEC_FIELD, 1);
3910 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0)
3911 goto err;
3912 reg = stv090x_read_reg(state, STV090x_STOPCLK2);
3913 /* sampling 1 clock */
3914 STV090x_SETFIELD(reg, STOP_CLKSAMP1_FIELD, 1);
3915 /* viterbi 1 clock */
3916 STV090x_SETFIELD(reg, STOP_CLKVIT1_FIELD, 1);
3917 /* TS clock is shared between the two paths, only stop it
3918 when full standby is possible */
3919 if (full_standby)
3920 STV090x_SETFIELD(reg, STOP_CLKTS_FIELD, 1);
3921 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0)
3922 goto err;
3923 break;
3924
3925 case STV090x_DEMODULATOR_1:
3926 /* power off ADC 2 */
3927 reg = stv090x_read_reg(state, STV090x_TSTTNR3);
3928 STV090x_SETFIELD(reg, ADC2_PON_FIELD, 0);
3929 if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0)
3930 goto err;
3931 /* power off DiSEqC 2 */
3932 reg = stv090x_read_reg(state, STV090x_TSTTNR4);
3933 STV090x_SETFIELD(reg, DISEQC2_PON_FIELD, 0);
3934 if (stv090x_write_reg(state, STV090x_TSTTNR4, reg) < 0)
3935 goto err;
3936
3937 /* check whether path 1 is already sleeping, that is when
3938 ADC1 is off */
3939 reg = stv090x_read_reg(state, STV090x_TSTTNR1);
3940 if (STV090x_GETFIELD(reg, ADC1_PON_FIELD) == 0)
3941 full_standby = 1;
3942
3943 /* stop clocks */
3944 reg = stv090x_read_reg(state, STV090x_STOPCLK1);
3945 /* packet delineator 2 clock */
3946 STV090x_SETFIELD(reg, STOP_CLKPKDT2_FIELD, 1);
3947 /* ADC 2 clock */
3948 STV090x_SETFIELD(reg, STOP_CLKADCI2_FIELD, 1);
3949 /* FEC clock is shared between the two paths, only stop it
3950 when full standby is possible */
3951 if (full_standby)
3952 STV090x_SETFIELD(reg, STOP_CLKFEC_FIELD, 1);
3953 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0)
3954 goto err;
3955 reg = stv090x_read_reg(state, STV090x_STOPCLK2);
3956 /* sampling 2 clock */
3957 STV090x_SETFIELD(reg, STOP_CLKSAMP2_FIELD, 1);
3958 /* viterbi 2 clock */
3959 STV090x_SETFIELD(reg, STOP_CLKVIT2_FIELD, 1);
3960 /* TS clock is shared between the two paths, only stop it
3961 when full standby is possible */
3962 if (full_standby)
3963 STV090x_SETFIELD(reg, STOP_CLKTS_FIELD, 1);
3964 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0)
3965 goto err;
3966 break;
3873 3967
3968 default:
3969 dprintk(FE_ERROR, 1, "Wrong demodulator!");
3970 break;
3971 }
3972
3973 if (full_standby) {
3974 /* general power off */
3975 reg = stv090x_read_reg(state, STV090x_SYNTCTRL);
3976 STV090x_SETFIELD(reg, STANDBY_FIELD, 0x01);
3977 if (stv090x_write_reg(state, STV090x_SYNTCTRL, reg) < 0)
3978 goto err;
3979 }
3980
3981 mutex_unlock(&state->internal->demod_lock);
3874 return 0; 3982 return 0;
3875 3983
3876err_gateoff: 3984err_gateoff:
3877 stv090x_i2c_gate_ctrl(state, 0); 3985 stv090x_i2c_gate_ctrl(state, 0);
3878err: 3986err:
3987 mutex_unlock(&state->internal->demod_lock);
3879 dprintk(FE_ERROR, 1, "I/O error"); 3988 dprintk(FE_ERROR, 1, "I/O error");
3880 return -1; 3989 return -1;
3881} 3990}
@@ -3885,21 +3994,94 @@ static int stv090x_wakeup(struct dvb_frontend *fe)
3885 struct stv090x_state *state = fe->demodulator_priv; 3994 struct stv090x_state *state = fe->demodulator_priv;
3886 u32 reg; 3995 u32 reg;
3887 3996
3888 dprintk(FE_DEBUG, 1, "Wake %s from standby", 3997 dprintk(FE_DEBUG, 1, "Wake %s(%d) from standby",
3889 state->device == STV0900 ? "STV0900" : "STV0903"); 3998 state->device == STV0900 ? "STV0900" : "STV0903",
3999 state->demod);
4000
4001 mutex_lock(&state->internal->demod_lock);
3890 4002
4003 /* general power on */
3891 reg = stv090x_read_reg(state, STV090x_SYNTCTRL); 4004 reg = stv090x_read_reg(state, STV090x_SYNTCTRL);
3892 STV090x_SETFIELD(reg, STANDBY_FIELD, 0x00); 4005 STV090x_SETFIELD(reg, STANDBY_FIELD, 0x00);
3893 if (stv090x_write_reg(state, STV090x_SYNTCTRL, reg) < 0) 4006 if (stv090x_write_reg(state, STV090x_SYNTCTRL, reg) < 0)
3894 goto err; 4007 goto err;
3895 4008
3896 reg = stv090x_read_reg(state, STV090x_TSTTNR1); 4009 switch (state->demod) {
3897 STV090x_SETFIELD(reg, ADC1_PON_FIELD, 1); 4010 case STV090x_DEMODULATOR_0:
3898 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0) 4011 /* power on ADC 1 */
3899 goto err; 4012 reg = stv090x_read_reg(state, STV090x_TSTTNR1);
4013 STV090x_SETFIELD(reg, ADC1_PON_FIELD, 1);
4014 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0)
4015 goto err;
4016 /* power on DiSEqC 1 */
4017 reg = stv090x_read_reg(state, STV090x_TSTTNR2);
4018 STV090x_SETFIELD(reg, DISEQC1_PON_FIELD, 1);
4019 if (stv090x_write_reg(state, STV090x_TSTTNR2, reg) < 0)
4020 goto err;
4021
4022 /* activate clocks */
4023 reg = stv090x_read_reg(state, STV090x_STOPCLK1);
4024 /* packet delineator 1 clock */
4025 STV090x_SETFIELD(reg, STOP_CLKPKDT1_FIELD, 0);
4026 /* ADC 1 clock */
4027 STV090x_SETFIELD(reg, STOP_CLKADCI1_FIELD, 0);
4028 /* FEC clock */
4029 STV090x_SETFIELD(reg, STOP_CLKFEC_FIELD, 0);
4030 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0)
4031 goto err;
4032 reg = stv090x_read_reg(state, STV090x_STOPCLK2);
4033 /* sampling 1 clock */
4034 STV090x_SETFIELD(reg, STOP_CLKSAMP1_FIELD, 0);
4035 /* viterbi 1 clock */
4036 STV090x_SETFIELD(reg, STOP_CLKVIT1_FIELD, 0);
4037 /* TS clock */
4038 STV090x_SETFIELD(reg, STOP_CLKTS_FIELD, 0);
4039 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0)
4040 goto err;
4041 break;
3900 4042
4043 case STV090x_DEMODULATOR_1:
4044 /* power on ADC 2 */
4045 reg = stv090x_read_reg(state, STV090x_TSTTNR3);
4046 STV090x_SETFIELD(reg, ADC2_PON_FIELD, 1);
4047 if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0)
4048 goto err;
4049 /* power on DiSEqC 2 */
4050 reg = stv090x_read_reg(state, STV090x_TSTTNR4);
4051 STV090x_SETFIELD(reg, DISEQC2_PON_FIELD, 1);
4052 if (stv090x_write_reg(state, STV090x_TSTTNR4, reg) < 0)
4053 goto err;
4054
4055 /* activate clocks */
4056 reg = stv090x_read_reg(state, STV090x_STOPCLK1);
4057 /* packet delineator 2 clock */
4058 STV090x_SETFIELD(reg, STOP_CLKPKDT2_FIELD, 0);
4059 /* ADC 2 clock */
4060 STV090x_SETFIELD(reg, STOP_CLKADCI2_FIELD, 0);
4061 /* FEC clock */
4062 STV090x_SETFIELD(reg, STOP_CLKFEC_FIELD, 0);
4063 if (stv090x_write_reg(state, STV090x_STOPCLK1, reg) < 0)
4064 goto err;
4065 reg = stv090x_read_reg(state, STV090x_STOPCLK2);
4066 /* sampling 2 clock */
4067 STV090x_SETFIELD(reg, STOP_CLKSAMP2_FIELD, 0);
4068 /* viterbi 2 clock */
4069 STV090x_SETFIELD(reg, STOP_CLKVIT2_FIELD, 0);
4070 /* TS clock */
4071 STV090x_SETFIELD(reg, STOP_CLKTS_FIELD, 0);
4072 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0)
4073 goto err;
4074 break;
4075
4076 default:
4077 dprintk(FE_ERROR, 1, "Wrong demodulator!");
4078 break;
4079 }
4080
4081 mutex_unlock(&state->internal->demod_lock);
3901 return 0; 4082 return 0;
3902err: 4083err:
4084 mutex_unlock(&state->internal->demod_lock);
3903 dprintk(FE_ERROR, 1, "I/O error"); 4085 dprintk(FE_ERROR, 1, "I/O error");
3904 return -1; 4086 return -1;
3905} 4087}
@@ -4169,6 +4351,7 @@ static int stv090x_set_tspath(struct stv090x_state *state)
4169 switch (state->config->ts1_mode) { 4351 switch (state->config->ts1_mode) {
4170 case STV090x_TSMODE_PARALLEL_PUNCTURED: 4352 case STV090x_TSMODE_PARALLEL_PUNCTURED:
4171 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); 4353 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH);
4354 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei);
4172 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x00); 4355 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x00);
4173 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x00); 4356 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x00);
4174 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) 4357 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0)
@@ -4177,6 +4360,7 @@ static int stv090x_set_tspath(struct stv090x_state *state)
4177 4360
4178 case STV090x_TSMODE_DVBCI: 4361 case STV090x_TSMODE_DVBCI:
4179 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); 4362 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH);
4363 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei);
4180 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x00); 4364 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x00);
4181 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x01); 4365 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x01);
4182 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) 4366 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0)
@@ -4185,6 +4369,7 @@ static int stv090x_set_tspath(struct stv090x_state *state)
4185 4369
4186 case STV090x_TSMODE_SERIAL_PUNCTURED: 4370 case STV090x_TSMODE_SERIAL_PUNCTURED:
4187 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); 4371 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH);
4372 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei);
4188 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x01); 4373 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x01);
4189 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x00); 4374 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x00);
4190 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) 4375 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0)
@@ -4193,6 +4378,7 @@ static int stv090x_set_tspath(struct stv090x_state *state)
4193 4378
4194 case STV090x_TSMODE_SERIAL_CONTINUOUS: 4379 case STV090x_TSMODE_SERIAL_CONTINUOUS:
4195 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH); 4380 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH);
4381 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts1_tei);
4196 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x01); 4382 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x01);
4197 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x01); 4383 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x01);
4198 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0) 4384 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0)
@@ -4206,6 +4392,7 @@ static int stv090x_set_tspath(struct stv090x_state *state)
4206 switch (state->config->ts2_mode) { 4392 switch (state->config->ts2_mode) {
4207 case STV090x_TSMODE_PARALLEL_PUNCTURED: 4393 case STV090x_TSMODE_PARALLEL_PUNCTURED:
4208 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); 4394 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH);
4395 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei);
4209 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x00); 4396 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x00);
4210 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x00); 4397 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x00);
4211 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) 4398 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0)
@@ -4214,6 +4401,7 @@ static int stv090x_set_tspath(struct stv090x_state *state)
4214 4401
4215 case STV090x_TSMODE_DVBCI: 4402 case STV090x_TSMODE_DVBCI:
4216 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); 4403 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH);
4404 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei);
4217 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x00); 4405 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x00);
4218 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x01); 4406 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x01);
4219 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) 4407 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0)
@@ -4222,6 +4410,7 @@ static int stv090x_set_tspath(struct stv090x_state *state)
4222 4410
4223 case STV090x_TSMODE_SERIAL_PUNCTURED: 4411 case STV090x_TSMODE_SERIAL_PUNCTURED:
4224 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); 4412 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH);
4413 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei);
4225 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x01); 4414 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x01);
4226 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x00); 4415 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x00);
4227 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) 4416 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0)
@@ -4230,6 +4419,7 @@ static int stv090x_set_tspath(struct stv090x_state *state)
4230 4419
4231 case STV090x_TSMODE_SERIAL_CONTINUOUS: 4420 case STV090x_TSMODE_SERIAL_CONTINUOUS:
4232 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); 4421 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH);
4422 STV090x_SETFIELD_Px(reg, TSFIFO_TEIUPDATE_FIELD, state->config->ts2_tei);
4233 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x01); 4423 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x01);
4234 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x01); 4424 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x01);
4235 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) 4425 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0)
@@ -4506,16 +4696,26 @@ static int stv090x_setup(struct dvb_frontend *fe)
4506 if (stv090x_write_reg(state, STV090x_TSTRES0, 0x00) < 0) 4696 if (stv090x_write_reg(state, STV090x_TSTRES0, 0x00) < 0)
4507 goto err; 4697 goto err;
4508 4698
4509 /* workaround for stuck DiSEqC output */
4510 if (config->diseqc_envelope_mode)
4511 stv090x_send_diseqc_burst(fe, SEC_MINI_A);
4512
4513 return 0; 4699 return 0;
4514err: 4700err:
4515 dprintk(FE_ERROR, 1, "I/O error"); 4701 dprintk(FE_ERROR, 1, "I/O error");
4516 return -1; 4702 return -1;
4517} 4703}
4518 4704
4705int stv090x_set_gpio(struct dvb_frontend *fe, u8 gpio, u8 dir, u8 value,
4706 u8 xor_value)
4707{
4708 struct stv090x_state *state = fe->demodulator_priv;
4709 u8 reg = 0;
4710
4711 STV090x_SETFIELD(reg, GPIOx_OPD_FIELD, dir);
4712 STV090x_SETFIELD(reg, GPIOx_CONFIG_FIELD, value);
4713 STV090x_SETFIELD(reg, GPIOx_XOR_FIELD, xor_value);
4714
4715 return stv090x_write_reg(state, STV090x_GPIOxCFG(gpio), reg);
4716}
4717EXPORT_SYMBOL(stv090x_set_gpio);
4718
4519static struct dvb_frontend_ops stv090x_ops = { 4719static struct dvb_frontend_ops stv090x_ops = {
4520 4720
4521 .info = { 4721 .info = {
@@ -4580,39 +4780,35 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
4580 state->internal = temp_int->internal; 4780 state->internal = temp_int->internal;
4581 state->internal->num_used++; 4781 state->internal->num_used++;
4582 dprintk(FE_INFO, 1, "Found Internal Structure!"); 4782 dprintk(FE_INFO, 1, "Found Internal Structure!");
4583 dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x",
4584 state->device == STV0900 ? "STV0900" : "STV0903",
4585 demod,
4586 state->internal->dev_ver);
4587 return &state->frontend;
4588 } else { 4783 } else {
4589 state->internal = kmalloc(sizeof(struct stv090x_internal), 4784 state->internal = kmalloc(sizeof(struct stv090x_internal),
4590 GFP_KERNEL); 4785 GFP_KERNEL);
4786 if (!state->internal)
4787 goto error;
4591 temp_int = append_internal(state->internal); 4788 temp_int = append_internal(state->internal);
4789 if (!temp_int) {
4790 kfree(state->internal);
4791 goto error;
4792 }
4592 state->internal->num_used = 1; 4793 state->internal->num_used = 1;
4593 state->internal->mclk = 0; 4794 state->internal->mclk = 0;
4594 state->internal->dev_ver = 0; 4795 state->internal->dev_ver = 0;
4595 state->internal->i2c_adap = state->i2c; 4796 state->internal->i2c_adap = state->i2c;
4596 state->internal->i2c_addr = state->config->address; 4797 state->internal->i2c_addr = state->config->address;
4597 dprintk(FE_INFO, 1, "Create New Internal Structure!"); 4798 dprintk(FE_INFO, 1, "Create New Internal Structure!");
4598 }
4599 4799
4600 mutex_init(&state->internal->demod_lock); 4800 mutex_init(&state->internal->demod_lock);
4601 mutex_init(&state->internal->tuner_lock); 4801 mutex_init(&state->internal->tuner_lock);
4602 4802
4603 if (stv090x_sleep(&state->frontend) < 0) { 4803 if (stv090x_setup(&state->frontend) < 0) {
4604 dprintk(FE_ERROR, 1, "Error putting device to sleep"); 4804 dprintk(FE_ERROR, 1, "Error setting up device");
4605 goto error; 4805 goto err_remove;
4806 }
4606 } 4807 }
4607 4808
4608 if (stv090x_setup(&state->frontend) < 0) { 4809 /* workaround for stuck DiSEqC output */
4609 dprintk(FE_ERROR, 1, "Error setting up device"); 4810 if (config->diseqc_envelope_mode)
4610 goto error; 4811 stv090x_send_diseqc_burst(&state->frontend, SEC_MINI_A);
4611 }
4612 if (stv090x_wakeup(&state->frontend) < 0) {
4613 dprintk(FE_ERROR, 1, "Error waking device");
4614 goto error;
4615 }
4616 4812
4617 dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x", 4813 dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x",
4618 state->device == STV0900 ? "STV0900" : "STV0903", 4814 state->device == STV0900 ? "STV0900" : "STV0903",
@@ -4621,6 +4817,9 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
4621 4817
4622 return &state->frontend; 4818 return &state->frontend;
4623 4819
4820err_remove:
4821 remove_dev(state->internal);
4822 kfree(state->internal);
4624error: 4823error:
4625 kfree(state); 4824 kfree(state);
4626 return NULL; 4825 return NULL;
diff --git a/drivers/media/dvb/frontends/stv090x.h b/drivers/media/dvb/frontends/stv090x.h
index dd1b93ae4e9d..29cdc2b71314 100644
--- a/drivers/media/dvb/frontends/stv090x.h
+++ b/drivers/media/dvb/frontends/stv090x.h
@@ -78,6 +78,9 @@ struct stv090x_config {
78 u32 ts1_clk; 78 u32 ts1_clk;
79 u32 ts2_clk; 79 u32 ts2_clk;
80 80
81 u8 ts1_tei : 1;
82 u8 ts2_tei : 1;
83
81 enum stv090x_i2crpt repeater_level; 84 enum stv090x_i2crpt repeater_level;
82 85
83 u8 tuner_bbgain; /* default: 10db */ 86 u8 tuner_bbgain; /* default: 10db */
@@ -97,6 +100,7 @@ struct stv090x_config {
97 int (*tuner_get_bbgain) (struct dvb_frontend *fe, u32 *gain); 100 int (*tuner_get_bbgain) (struct dvb_frontend *fe, u32 *gain);
98 int (*tuner_set_refclk) (struct dvb_frontend *fe, u32 refclk); 101 int (*tuner_set_refclk) (struct dvb_frontend *fe, u32 refclk);
99 int (*tuner_get_status) (struct dvb_frontend *fe, u32 *status); 102 int (*tuner_get_status) (struct dvb_frontend *fe, u32 *status);
103 void (*tuner_i2c_lock) (struct dvb_frontend *fe, int lock);
100}; 104};
101 105
102#if defined(CONFIG_DVB_STV090x) || (defined(CONFIG_DVB_STV090x_MODULE) && defined(MODULE)) 106#if defined(CONFIG_DVB_STV090x) || (defined(CONFIG_DVB_STV090x_MODULE) && defined(MODULE))
@@ -104,6 +108,11 @@ struct stv090x_config {
104extern struct dvb_frontend *stv090x_attach(const struct stv090x_config *config, 108extern struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
105 struct i2c_adapter *i2c, 109 struct i2c_adapter *i2c,
106 enum stv090x_demodulator demod); 110 enum stv090x_demodulator demod);
111
112/* dir = 0 -> output, dir = 1 -> input/open-drain */
113extern int stv090x_set_gpio(struct dvb_frontend *fe, u8 gpio,
114 u8 dir, u8 value, u8 xor_value);
115
107#else 116#else
108 117
109static inline struct dvb_frontend *stv090x_attach(const struct stv090x_config *config, 118static inline struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
@@ -113,6 +122,13 @@ static inline struct dvb_frontend *stv090x_attach(const struct stv090x_config *c
113 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 122 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
114 return NULL; 123 return NULL;
115} 124}
125
126static inline int stv090x_set_gpio(struct dvb_frontend *fe, u8 gpio,
127 u8 opd, u8 value, u8 xor_value)
128{
129 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
130 return -ENODEV;
131}
116#endif /* CONFIG_DVB_STV090x */ 132#endif /* CONFIG_DVB_STV090x */
117 133
118#endif /* __STV090x_H */ 134#endif /* __STV090x_H */
diff --git a/drivers/media/dvb/frontends/stv090x_reg.h b/drivers/media/dvb/frontends/stv090x_reg.h
index 2502855dd784..93741ee14297 100644
--- a/drivers/media/dvb/frontends/stv090x_reg.h
+++ b/drivers/media/dvb/frontends/stv090x_reg.h
@@ -1327,10 +1327,10 @@
1327#define STV090x_WIDTH_Px_NOSPLHT_UNNORMED_FIELD 8 1327#define STV090x_WIDTH_Px_NOSPLHT_UNNORMED_FIELD 8
1328 1328
1329#define STV090x_Px_NOSPLHy(__x, __y) (0xf48f - (__x - 1) * 0x200 - __y * 0x1) 1329#define STV090x_Px_NOSPLHy(__x, __y) (0xf48f - (__x - 1) * 0x200 - __y * 0x1)
1330#define STv090x_P1_NOSPLH0 STV090x_Px_NOSPLHy(1, 0) 1330#define STV090x_P1_NOSPLH0 STV090x_Px_NOSPLHy(1, 0)
1331#define STv090x_P1_NOSPLH1 STV090x_Px_NOSPLHy(1, 1) 1331#define STV090x_P1_NOSPLH1 STV090x_Px_NOSPLHy(1, 1)
1332#define STv090x_P2_NOSPLH0 STV090x_Px_NOSPLHy(2, 0) 1332#define STV090x_P2_NOSPLH0 STV090x_Px_NOSPLHy(2, 0)
1333#define STv090x_P2_NOSPLH1 STV090x_Px_NOSPLHy(2, 1) 1333#define STV090x_P2_NOSPLH1 STV090x_Px_NOSPLHy(2, 1)
1334#define STV090x_OFFST_Px_NOSPLH_UNNORMED_FIELD 0 1334#define STV090x_OFFST_Px_NOSPLH_UNNORMED_FIELD 0
1335#define STV090x_WIDTH_Px_NOSPLH_UNNORMED_FIELD 8 1335#define STV090x_WIDTH_Px_NOSPLH_UNNORMED_FIELD 8
1336 1336
@@ -1406,7 +1406,7 @@
1406 1406
1407#define STV090x_Px_BCLC2S28(__x) (0xf49d - (__x - 1) * 0x200) 1407#define STV090x_Px_BCLC2S28(__x) (0xf49d - (__x - 1) * 0x200)
1408#define STV090x_P1_BCLC2S28 STV090x_Px_BCLC2S28(1) 1408#define STV090x_P1_BCLC2S28 STV090x_Px_BCLC2S28(1)
1409#define STV090x_P2_BCLC2S28 STV090x_Px_BCLC2S28(1) 1409#define STV090x_P2_BCLC2S28 STV090x_Px_BCLC2S28(2)
1410#define STV090x_OFFST_Px_CAR2S2_8_BETA_M_FIELD 4 1410#define STV090x_OFFST_Px_CAR2S2_8_BETA_M_FIELD 4
1411#define STV090x_WIDTH_Px_CAR2S2_8_BETA_M_FIELD 2 1411#define STV090x_WIDTH_Px_CAR2S2_8_BETA_M_FIELD 2
1412#define STV090x_OFFST_Px_CAR2S2_8_BETA_E_FIELD 0 1412#define STV090x_OFFST_Px_CAR2S2_8_BETA_E_FIELD 0
@@ -1414,7 +1414,7 @@
1414 1414
1415#define STV090x_Px_BCLC2S216A(__x) (0xf49e - (__x - 1) * 0x200) 1415#define STV090x_Px_BCLC2S216A(__x) (0xf49e - (__x - 1) * 0x200)
1416#define STV090x_P1_BCLC2S216A STV090x_Px_BCLC2S216A(1) 1416#define STV090x_P1_BCLC2S216A STV090x_Px_BCLC2S216A(1)
1417#define STV090x_P2_BCLC2S216A STV090x_Px_BCLC2S216A(1) 1417#define STV090x_P2_BCLC2S216A STV090x_Px_BCLC2S216A(2)
1418#define STV090x_OFFST_Px_CAR2S2_16A_BETA_M_FIELD 4 1418#define STV090x_OFFST_Px_CAR2S2_16A_BETA_M_FIELD 4
1419#define STV090x_WIDTH_Px_CAR2S2_16A_BETA_M_FIELD 2 1419#define STV090x_WIDTH_Px_CAR2S2_16A_BETA_M_FIELD 2
1420#define STV090x_OFFST_Px_CAR2S2_16A_BETA_E_FIELD 0 1420#define STV090x_OFFST_Px_CAR2S2_16A_BETA_E_FIELD 0
@@ -1422,7 +1422,7 @@
1422 1422
1423#define STV090x_Px_BCLC2S232A(__x) (0xf49f - (__x - 1) * 0x200) 1423#define STV090x_Px_BCLC2S232A(__x) (0xf49f - (__x - 1) * 0x200)
1424#define STV090x_P1_BCLC2S232A STV090x_Px_BCLC2S232A(1) 1424#define STV090x_P1_BCLC2S232A STV090x_Px_BCLC2S232A(1)
1425#define STV090x_P2_BCLC2S232A STV090x_Px_BCLC2S232A(1) 1425#define STV090x_P2_BCLC2S232A STV090x_Px_BCLC2S232A(2)
1426#define STV090x_OFFST_Px_CAR2S2_32A_BETA_M_FIELD 4 1426#define STV090x_OFFST_Px_CAR2S2_32A_BETA_M_FIELD 4
1427#define STV090x_WIDTH_Px_CAR2S2_32A_BETA_M_FIELD 2 1427#define STV090x_WIDTH_Px_CAR2S2_32A_BETA_M_FIELD 2
1428#define STV090x_OFFST_Px_CAR2S2_32A_BETA_E_FIELD 0 1428#define STV090x_OFFST_Px_CAR2S2_32A_BETA_E_FIELD 0
@@ -1602,7 +1602,7 @@
1602 1602
1603#define STV090x_Px_CCIACC(__x) (0xf4c4 - (__x - 1) * 0x200) 1603#define STV090x_Px_CCIACC(__x) (0xf4c4 - (__x - 1) * 0x200)
1604#define STV090x_P1_CCIACC STV090x_Px_CCIACC(1) 1604#define STV090x_P1_CCIACC STV090x_Px_CCIACC(1)
1605#define STV090x_P2_CCIACC STV090x_Px_CCIACC(1) 1605#define STV090x_P2_CCIACC STV090x_Px_CCIACC(2)
1606#define STV090x_OFFST_Px_CCI_VALUE_FIELD 0 1606#define STV090x_OFFST_Px_CCI_VALUE_FIELD 0
1607#define STV090x_WIDTH_Px_CCI_VALUE_FIELD 8 1607#define STV090x_WIDTH_Px_CCI_VALUE_FIELD 8
1608 1608
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index f2a8abe0a243..ea485d923550 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -598,7 +598,7 @@ static int tda1004x_decode_fec(int tdafec)
598 return -1; 598 return -1;
599} 599}
600 600
601static int tda1004x_write(struct dvb_frontend* fe, u8 *buf, int len) 601static int tda1004x_write(struct dvb_frontend* fe, const u8 buf[], int len)
602{ 602{
603 struct tda1004x_state* state = fe->demodulator_priv; 603 struct tda1004x_state* state = fe->demodulator_priv;
604 604
diff --git a/drivers/media/dvb/frontends/tda8261.c b/drivers/media/dvb/frontends/tda8261.c
index 1742056a34e8..53c7d8f1df28 100644
--- a/drivers/media/dvb/frontends/tda8261.c
+++ b/drivers/media/dvb/frontends/tda8261.c
@@ -224,7 +224,6 @@ exit:
224} 224}
225 225
226EXPORT_SYMBOL(tda8261_attach); 226EXPORT_SYMBOL(tda8261_attach);
227MODULE_PARM_DESC(verbose, "Set verbosity level");
228 227
229MODULE_AUTHOR("Manu Abraham"); 228MODULE_AUTHOR("Manu Abraham");
230MODULE_DESCRIPTION("TDA8261 8PSK/QPSK Tuner"); 229MODULE_DESCRIPTION("TDA8261 8PSK/QPSK Tuner");
diff --git a/drivers/media/dvb/frontends/z0194a.h b/drivers/media/dvb/frontends/z0194a.h
index 07f3fc0998f6..96d86d6eb473 100644
--- a/drivers/media/dvb/frontends/z0194a.h
+++ b/drivers/media/dvb/frontends/z0194a.h
@@ -42,7 +42,7 @@ static int sharp_z0194a_set_symbol_rate(struct dvb_frontend *fe,
42 42
43static u8 sharp_z0194a_inittab[] = { 43static u8 sharp_z0194a_inittab[] = {
44 0x01, 0x15, 44 0x01, 0x15,
45 0x02, 0x00, 45 0x02, 0x30,
46 0x03, 0x00, 46 0x03, 0x00,
47 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */ 47 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
48 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */ 48 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
diff --git a/drivers/media/dvb/frontends/zl10036.c b/drivers/media/dvb/frontends/zl10036.c
index 4627f491656b..81aa984c551f 100644
--- a/drivers/media/dvb/frontends/zl10036.c
+++ b/drivers/media/dvb/frontends/zl10036.c
@@ -463,16 +463,16 @@ struct dvb_frontend *zl10036_attach(struct dvb_frontend *fe,
463 const struct zl10036_config *config, 463 const struct zl10036_config *config,
464 struct i2c_adapter *i2c) 464 struct i2c_adapter *i2c)
465{ 465{
466 struct zl10036_state *state = NULL; 466 struct zl10036_state *state;
467 int ret; 467 int ret;
468 468
469 if (NULL == config) { 469 if (!config) {
470 printk(KERN_ERR "%s: no config specified", __func__); 470 printk(KERN_ERR "%s: no config specified", __func__);
471 goto error; 471 return NULL;
472 } 472 }
473 473
474 state = kzalloc(sizeof(struct zl10036_state), GFP_KERNEL); 474 state = kzalloc(sizeof(struct zl10036_state), GFP_KERNEL);
475 if (NULL == state) 475 if (!state)
476 return NULL; 476 return NULL;
477 477
478 state->config = config; 478 state->config = config;
@@ -507,7 +507,7 @@ struct dvb_frontend *zl10036_attach(struct dvb_frontend *fe,
507 return fe; 507 return fe;
508 508
509error: 509error:
510 zl10036_release(fe); 510 kfree(state);
511 return NULL; 511 return NULL;
512} 512}
513EXPORT_SYMBOL(zl10036_attach); 513EXPORT_SYMBOL(zl10036_attach);
diff --git a/drivers/media/dvb/frontends/zl10353.c b/drivers/media/dvb/frontends/zl10353.c
index 8c612719adfc..adbbf6d3d044 100644
--- a/drivers/media/dvb/frontends/zl10353.c
+++ b/drivers/media/dvb/frontends/zl10353.c
@@ -64,7 +64,7 @@ static int zl10353_single_write(struct dvb_frontend *fe, u8 reg, u8 val)
64 return 0; 64 return 0;
65} 65}
66 66
67static int zl10353_write(struct dvb_frontend *fe, u8 *ibuf, int ilen) 67static int zl10353_write(struct dvb_frontend *fe, const u8 ibuf[], int ilen)
68{ 68{
69 int err, i; 69 int err, i;
70 for (i = 0; i < ilen - 1; i++) 70 for (i = 0; i < ilen - 1; i++)
diff --git a/drivers/media/dvb/mantis/Kconfig b/drivers/media/dvb/mantis/Kconfig
index fd0830ed10d8..a13a50503134 100644
--- a/drivers/media/dvb/mantis/Kconfig
+++ b/drivers/media/dvb/mantis/Kconfig
@@ -1,6 +1,6 @@
1config MANTIS_CORE 1config MANTIS_CORE
2 tristate "Mantis/Hopper PCI bridge based devices" 2 tristate "Mantis/Hopper PCI bridge based devices"
3 depends on PCI && I2C && INPUT && IR_CORE 3 depends on PCI && I2C && INPUT && RC_CORE
4 4
5 help 5 help
6 Support for PCI cards based on the Mantis and Hopper PCi bridge. 6 Support for PCI cards based on the Mantis and Hopper PCi bridge.
diff --git a/drivers/media/dvb/mantis/hopper_cards.c b/drivers/media/dvb/mantis/hopper_cards.c
index 09e9fc785189..1402062f2c89 100644
--- a/drivers/media/dvb/mantis/hopper_cards.c
+++ b/drivers/media/dvb/mantis/hopper_cards.c
@@ -44,7 +44,7 @@
44 44
45static unsigned int verbose; 45static unsigned int verbose;
46module_param(verbose, int, 0644); 46module_param(verbose, int, 0644);
47MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); 47MODULE_PARM_DESC(verbose, "verbose startup messages, default is 0 (no)");
48 48
49#define DRIVER_NAME "Hopper" 49#define DRIVER_NAME "Hopper"
50 50
@@ -251,6 +251,8 @@ static struct pci_device_id hopper_pci_table[] = {
251 { } 251 { }
252}; 252};
253 253
254MODULE_DEVICE_TABLE(pci, hopper_pci_table);
255
254static struct pci_driver hopper_pci_driver = { 256static struct pci_driver hopper_pci_driver = {
255 .name = DRIVER_NAME, 257 .name = DRIVER_NAME,
256 .id_table = hopper_pci_table, 258 .id_table = hopper_pci_table,
diff --git a/drivers/media/dvb/mantis/hopper_vp3028.c b/drivers/media/dvb/mantis/hopper_vp3028.c
index 96674c78e86b..68a29f8bdf73 100644
--- a/drivers/media/dvb/mantis/hopper_vp3028.c
+++ b/drivers/media/dvb/mantis/hopper_vp3028.c
@@ -47,17 +47,17 @@ static int vp3028_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
47 struct mantis_hwconfig *config = mantis->hwconfig; 47 struct mantis_hwconfig *config = mantis->hwconfig;
48 int err = 0; 48 int err = 0;
49 49
50 gpio_set_bits(mantis, config->reset, 0); 50 mantis_gpio_set_bits(mantis, config->reset, 0);
51 msleep(100); 51 msleep(100);
52 err = mantis_frontend_power(mantis, POWER_ON); 52 err = mantis_frontend_power(mantis, POWER_ON);
53 msleep(100); 53 msleep(100);
54 gpio_set_bits(mantis, config->reset, 1); 54 mantis_gpio_set_bits(mantis, config->reset, 1);
55 55
56 err = mantis_frontend_power(mantis, POWER_ON); 56 err = mantis_frontend_power(mantis, POWER_ON);
57 if (err == 0) { 57 if (err == 0) {
58 msleep(250); 58 msleep(250);
59 dprintk(MANTIS_ERROR, 1, "Probing for 10353 (DVB-T)"); 59 dprintk(MANTIS_ERROR, 1, "Probing for 10353 (DVB-T)");
60 fe = zl10353_attach(&hopper_vp3028_config, adapter); 60 fe = dvb_attach(zl10353_attach, &hopper_vp3028_config, adapter);
61 61
62 if (!fe) 62 if (!fe)
63 return -1; 63 return -1;
diff --git a/drivers/media/dvb/mantis/mantis_cards.c b/drivers/media/dvb/mantis/mantis_cards.c
index cf4b39ffdaad..05cbb9d95727 100644
--- a/drivers/media/dvb/mantis/mantis_cards.c
+++ b/drivers/media/dvb/mantis/mantis_cards.c
@@ -52,7 +52,7 @@
52 52
53static unsigned int verbose; 53static unsigned int verbose;
54module_param(verbose, int, 0644); 54module_param(verbose, int, 0644);
55MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); 55MODULE_PARM_DESC(verbose, "verbose startup messages, default is 0 (no)");
56 56
57static int devs; 57static int devs;
58 58
@@ -281,6 +281,8 @@ static struct pci_device_id mantis_pci_table[] = {
281 { } 281 { }
282}; 282};
283 283
284MODULE_DEVICE_TABLE(pci, mantis_pci_table);
285
284static struct pci_driver mantis_pci_driver = { 286static struct pci_driver mantis_pci_driver = {
285 .name = DRIVER_NAME, 287 .name = DRIVER_NAME,
286 .id_table = mantis_pci_table, 288 .id_table = mantis_pci_table,
diff --git a/drivers/media/dvb/mantis/mantis_common.h b/drivers/media/dvb/mantis/mantis_common.h
index d0b645a483c9..bd400d21b81f 100644
--- a/drivers/media/dvb/mantis/mantis_common.h
+++ b/drivers/media/dvb/mantis/mantis_common.h
@@ -171,7 +171,9 @@ struct mantis_pci {
171 struct work_struct uart_work; 171 struct work_struct uart_work;
172 spinlock_t uart_lock; 172 spinlock_t uart_lock;
173 173
174 struct input_dev *rc; 174 struct rc_dev *rc;
175 char input_name[80];
176 char input_phys[80];
175}; 177};
176 178
177#define MANTIS_HIF_STATUS (mantis->gpio_status) 179#define MANTIS_HIF_STATUS (mantis->gpio_status)
diff --git a/drivers/media/dvb/mantis/mantis_core.c b/drivers/media/dvb/mantis/mantis_core.c
index 8113b23ce448..22524a8e6f61 100644
--- a/drivers/media/dvb/mantis/mantis_core.c
+++ b/drivers/media/dvb/mantis/mantis_core.c
@@ -91,10 +91,7 @@ static int get_mac_address(struct mantis_pci *mantis)
91 return err; 91 return err;
92 } 92 }
93 dprintk(verbose, MANTIS_ERROR, 0, 93 dprintk(verbose, MANTIS_ERROR, 0,
94 " MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]\n", 94 " MAC Address=[%pM]\n", mantis->mac_address);
95 mantis->mac_address[0], mantis->mac_address[1],
96 mantis->mac_address[2], mantis->mac_address[3],
97 mantis->mac_address[4], mantis->mac_address[5]);
98 95
99 return 0; 96 return 0;
100} 97}
diff --git a/drivers/media/dvb/mantis/mantis_dvb.c b/drivers/media/dvb/mantis/mantis_dvb.c
index 99d82eec3b03..e5180e45d310 100644
--- a/drivers/media/dvb/mantis/mantis_dvb.c
+++ b/drivers/media/dvb/mantis/mantis_dvb.c
@@ -47,15 +47,15 @@ int mantis_frontend_power(struct mantis_pci *mantis, enum mantis_power power)
47 switch (power) { 47 switch (power) {
48 case POWER_ON: 48 case POWER_ON:
49 dprintk(MANTIS_DEBUG, 1, "Power ON"); 49 dprintk(MANTIS_DEBUG, 1, "Power ON");
50 gpio_set_bits(mantis, config->power, POWER_ON); 50 mantis_gpio_set_bits(mantis, config->power, POWER_ON);
51 msleep(100); 51 msleep(100);
52 gpio_set_bits(mantis, config->power, POWER_ON); 52 mantis_gpio_set_bits(mantis, config->power, POWER_ON);
53 msleep(100); 53 msleep(100);
54 break; 54 break;
55 55
56 case POWER_OFF: 56 case POWER_OFF:
57 dprintk(MANTIS_DEBUG, 1, "Power OFF"); 57 dprintk(MANTIS_DEBUG, 1, "Power OFF");
58 gpio_set_bits(mantis, config->power, POWER_OFF); 58 mantis_gpio_set_bits(mantis, config->power, POWER_OFF);
59 msleep(100); 59 msleep(100);
60 break; 60 break;
61 61
@@ -73,13 +73,13 @@ void mantis_frontend_soft_reset(struct mantis_pci *mantis)
73 struct mantis_hwconfig *config = mantis->hwconfig; 73 struct mantis_hwconfig *config = mantis->hwconfig;
74 74
75 dprintk(MANTIS_DEBUG, 1, "Frontend RESET"); 75 dprintk(MANTIS_DEBUG, 1, "Frontend RESET");
76 gpio_set_bits(mantis, config->reset, 0); 76 mantis_gpio_set_bits(mantis, config->reset, 0);
77 msleep(100); 77 msleep(100);
78 gpio_set_bits(mantis, config->reset, 0); 78 mantis_gpio_set_bits(mantis, config->reset, 0);
79 msleep(100); 79 msleep(100);
80 gpio_set_bits(mantis, config->reset, 1); 80 mantis_gpio_set_bits(mantis, config->reset, 1);
81 msleep(100); 81 msleep(100);
82 gpio_set_bits(mantis, config->reset, 1); 82 mantis_gpio_set_bits(mantis, config->reset, 1);
83 msleep(100); 83 msleep(100);
84 84
85 return; 85 return;
@@ -117,6 +117,7 @@ static int mantis_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
117 if (mantis->feeds == 1) { 117 if (mantis->feeds == 1) {
118 dprintk(MANTIS_DEBUG, 1, "mantis start feed & dma"); 118 dprintk(MANTIS_DEBUG, 1, "mantis start feed & dma");
119 mantis_dma_start(mantis); 119 mantis_dma_start(mantis);
120 tasklet_enable(&mantis->tasklet);
120 } 121 }
121 122
122 return mantis->feeds; 123 return mantis->feeds;
@@ -136,6 +137,7 @@ static int mantis_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
136 mantis->feeds--; 137 mantis->feeds--;
137 if (mantis->feeds == 0) { 138 if (mantis->feeds == 0) {
138 dprintk(MANTIS_DEBUG, 1, "mantis stop feed and dma"); 139 dprintk(MANTIS_DEBUG, 1, "mantis stop feed and dma");
140 tasklet_disable(&mantis->tasklet);
139 mantis_dma_stop(mantis); 141 mantis_dma_stop(mantis);
140 } 142 }
141 143
@@ -216,6 +218,7 @@ int __devinit mantis_dvb_init(struct mantis_pci *mantis)
216 218
217 dvb_net_init(&mantis->dvb_adapter, &mantis->dvbnet, &mantis->demux.dmx); 219 dvb_net_init(&mantis->dvb_adapter, &mantis->dvbnet, &mantis->demux.dmx);
218 tasklet_init(&mantis->tasklet, mantis_dma_xfer, (unsigned long) mantis); 220 tasklet_init(&mantis->tasklet, mantis_dma_xfer, (unsigned long) mantis);
221 tasklet_disable(&mantis->tasklet);
219 if (mantis->hwconfig) { 222 if (mantis->hwconfig) {
220 result = config->frontend_init(mantis, mantis->fe); 223 result = config->frontend_init(mantis, mantis->fe);
221 if (result < 0) { 224 if (result < 0) {
diff --git a/drivers/media/dvb/mantis/mantis_evm.c b/drivers/media/dvb/mantis/mantis_evm.c
index a7b369a439d6..9f73c2cfc9ea 100644
--- a/drivers/media/dvb/mantis/mantis_evm.c
+++ b/drivers/media/dvb/mantis/mantis_evm.c
@@ -111,7 +111,7 @@ void mantis_evmgr_exit(struct mantis_ca *ca)
111 struct mantis_pci *mantis = ca->ca_priv; 111 struct mantis_pci *mantis = ca->ca_priv;
112 112
113 dprintk(MANTIS_DEBUG, 1, "Mantis Host I/F Event manager exiting"); 113 dprintk(MANTIS_DEBUG, 1, "Mantis Host I/F Event manager exiting");
114 flush_scheduled_work(); 114 flush_work_sync(&ca->hif_evm_work);
115 mantis_hif_exit(ca); 115 mantis_hif_exit(ca);
116 mantis_pcmcia_exit(ca); 116 mantis_pcmcia_exit(ca);
117} 117}
diff --git a/drivers/media/dvb/mantis/mantis_i2c.c b/drivers/media/dvb/mantis/mantis_i2c.c
index 7870bcf9689a..e7794517fe26 100644
--- a/drivers/media/dvb/mantis/mantis_i2c.c
+++ b/drivers/media/dvb/mantis/mantis_i2c.c
@@ -229,7 +229,6 @@ int __devinit mantis_i2c_init(struct mantis_pci *mantis)
229 i2c_set_adapdata(i2c_adapter, mantis); 229 i2c_set_adapdata(i2c_adapter, mantis);
230 230
231 i2c_adapter->owner = THIS_MODULE; 231 i2c_adapter->owner = THIS_MODULE;
232 i2c_adapter->class = I2C_CLASS_TV_DIGITAL;
233 i2c_adapter->algo = &mantis_algo; 232 i2c_adapter->algo = &mantis_algo;
234 i2c_adapter->algo_data = NULL; 233 i2c_adapter->algo_data = NULL;
235 i2c_adapter->timeout = 500; 234 i2c_adapter->timeout = 500;
diff --git a/drivers/media/dvb/mantis/mantis_input.c b/drivers/media/dvb/mantis/mantis_input.c
index a99489b8418b..db6d54d3fec0 100644
--- a/drivers/media/dvb/mantis/mantis_input.c
+++ b/drivers/media/dvb/mantis/mantis_input.c
@@ -18,8 +18,7 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <linux/input.h> 21#include <media/rc-core.h>
22#include <media/ir-core.h>
23#include <linux/pci.h> 22#include <linux/pci.h>
24 23
25#include "dmxdev.h" 24#include "dmxdev.h"
@@ -33,8 +32,9 @@
33#include "mantis_uart.h" 32#include "mantis_uart.h"
34 33
35#define MODULE_NAME "mantis_core" 34#define MODULE_NAME "mantis_core"
35#define RC_MAP_MANTIS "rc-mantis"
36 36
37static struct ir_scancode mantis_ir_table[] = { 37static struct rc_map_table mantis_ir_table[] = {
38 { 0x29, KEY_POWER }, 38 { 0x29, KEY_POWER },
39 { 0x28, KEY_FAVORITES }, 39 { 0x28, KEY_FAVORITES },
40 { 0x30, KEY_TEXT }, 40 { 0x30, KEY_TEXT },
@@ -95,53 +95,65 @@ static struct ir_scancode mantis_ir_table[] = {
95 { 0x00, KEY_BLUE }, 95 { 0x00, KEY_BLUE },
96}; 96};
97 97
98struct ir_scancode_table ir_mantis = { 98static struct rc_map_list ir_mantis_map = {
99 .scan = mantis_ir_table, 99 .map = {
100 .size = ARRAY_SIZE(mantis_ir_table), 100 .scan = mantis_ir_table,
101 .size = ARRAY_SIZE(mantis_ir_table),
102 .rc_type = RC_TYPE_UNKNOWN,
103 .name = RC_MAP_MANTIS,
104 }
101}; 105};
102EXPORT_SYMBOL_GPL(ir_mantis);
103 106
104int mantis_input_init(struct mantis_pci *mantis) 107int mantis_input_init(struct mantis_pci *mantis)
105{ 108{
106 struct input_dev *rc; 109 struct rc_dev *dev;
107 char name[80], dev[80];
108 int err; 110 int err;
109 111
110 rc = input_allocate_device(); 112 err = rc_map_register(&ir_mantis_map);
111 if (!rc) { 113 if (err)
112 dprintk(MANTIS_ERROR, 1, "Input device allocate failed"); 114 goto out;
113 return -ENOMEM;
114 }
115 115
116 sprintf(name, "Mantis %s IR receiver", mantis->hwconfig->model_name); 116 dev = rc_allocate_device();
117 sprintf(dev, "pci-%s/ir0", pci_name(mantis->pdev)); 117 if (!dev) {
118 dprintk(MANTIS_ERROR, 1, "Remote device allocation failed");
119 err = -ENOMEM;
120 goto out_map;
121 }
118 122
119 rc->name = name; 123 sprintf(mantis->input_name, "Mantis %s IR receiver", mantis->hwconfig->model_name);
120 rc->phys = dev; 124 sprintf(mantis->input_phys, "pci-%s/ir0", pci_name(mantis->pdev));
121 125
122 rc->id.bustype = BUS_PCI; 126 dev->input_name = mantis->input_name;
123 rc->id.vendor = mantis->vendor_id; 127 dev->input_phys = mantis->input_phys;
124 rc->id.product = mantis->device_id; 128 dev->input_id.bustype = BUS_PCI;
125 rc->id.version = 1; 129 dev->input_id.vendor = mantis->vendor_id;
126 rc->dev = mantis->pdev->dev; 130 dev->input_id.product = mantis->device_id;
131 dev->input_id.version = 1;
132 dev->driver_name = MODULE_NAME;
133 dev->map_name = RC_MAP_MANTIS;
134 dev->dev.parent = &mantis->pdev->dev;
127 135
128 err = __ir_input_register(rc, &ir_mantis, NULL, MODULE_NAME); 136 err = rc_register_device(dev);
129 if (err) { 137 if (err) {
130 dprintk(MANTIS_ERROR, 1, "IR device registration failed, ret = %d", err); 138 dprintk(MANTIS_ERROR, 1, "IR device registration failed, ret = %d", err);
131 input_free_device(rc); 139 goto out_dev;
132 return -ENODEV;
133 } 140 }
134 141
135 mantis->rc = rc; 142 mantis->rc = dev;
136
137 return 0; 143 return 0;
144
145out_dev:
146 rc_free_device(dev);
147out_map:
148 rc_map_unregister(&ir_mantis_map);
149out:
150 return err;
138} 151}
139 152
140int mantis_exit(struct mantis_pci *mantis) 153int mantis_exit(struct mantis_pci *mantis)
141{ 154{
142 struct input_dev *rc = mantis->rc; 155 rc_unregister_device(mantis->rc);
143 156 rc_map_unregister(&ir_mantis_map);
144 ir_input_unregister(rc);
145
146 return 0; 157 return 0;
147} 158}
159
diff --git a/drivers/media/dvb/mantis/mantis_ioc.c b/drivers/media/dvb/mantis/mantis_ioc.c
index de148ded52d8..479086dbb9a8 100644
--- a/drivers/media/dvb/mantis/mantis_ioc.c
+++ b/drivers/media/dvb/mantis/mantis_ioc.c
@@ -68,21 +68,14 @@ int mantis_get_mac(struct mantis_pci *mantis)
68 return err; 68 return err;
69 } 69 }
70 70
71 dprintk(MANTIS_ERROR, 0, 71 dprintk(MANTIS_ERROR, 0, " MAC Address=[%pM]\n", mac_addr);
72 " MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]\n",
73 mac_addr[0],
74 mac_addr[1],
75 mac_addr[2],
76 mac_addr[3],
77 mac_addr[4],
78 mac_addr[5]);
79 72
80 return 0; 73 return 0;
81} 74}
82EXPORT_SYMBOL_GPL(mantis_get_mac); 75EXPORT_SYMBOL_GPL(mantis_get_mac);
83 76
84/* Turn the given bit on or off. */ 77/* Turn the given bit on or off. */
85void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value) 78void mantis_gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
86{ 79{
87 u32 cur; 80 u32 cur;
88 81
@@ -97,7 +90,7 @@ void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
97 mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR); 90 mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR);
98 mmwrite(0x00, MANTIS_GPIF_DOUT); 91 mmwrite(0x00, MANTIS_GPIF_DOUT);
99} 92}
100EXPORT_SYMBOL_GPL(gpio_set_bits); 93EXPORT_SYMBOL_GPL(mantis_gpio_set_bits);
101 94
102int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl) 95int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl)
103{ 96{
diff --git a/drivers/media/dvb/mantis/mantis_ioc.h b/drivers/media/dvb/mantis/mantis_ioc.h
index 188fe5a81614..d56e002b2955 100644
--- a/drivers/media/dvb/mantis/mantis_ioc.h
+++ b/drivers/media/dvb/mantis/mantis_ioc.h
@@ -44,7 +44,7 @@ enum mantis_stream_control {
44}; 44};
45 45
46extern int mantis_get_mac(struct mantis_pci *mantis); 46extern int mantis_get_mac(struct mantis_pci *mantis);
47extern void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value); 47extern void mantis_gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value);
48 48
49extern int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl); 49extern int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl);
50 50
diff --git a/drivers/media/dvb/mantis/mantis_pci.c b/drivers/media/dvb/mantis/mantis_pci.c
index 59feeb84aec7..371558af2d96 100644
--- a/drivers/media/dvb/mantis/mantis_pci.c
+++ b/drivers/media/dvb/mantis/mantis_pci.c
@@ -22,7 +22,6 @@
22#include <linux/moduleparam.h> 22#include <linux/moduleparam.h>
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <asm/io.h> 24#include <asm/io.h>
25#include <asm/pgtable.h>
26#include <asm/page.h> 25#include <asm/page.h>
27#include <linux/kmod.h> 26#include <linux/kmod.h>
28#include <linux/vmalloc.h> 27#include <linux/vmalloc.h>
@@ -49,7 +48,7 @@
49 48
50int __devinit mantis_pci_init(struct mantis_pci *mantis) 49int __devinit mantis_pci_init(struct mantis_pci *mantis)
51{ 50{
52 u8 revision, latency; 51 u8 latency;
53 struct mantis_hwconfig *config = mantis->hwconfig; 52 struct mantis_hwconfig *config = mantis->hwconfig;
54 struct pci_dev *pdev = mantis->pdev; 53 struct pci_dev *pdev = mantis->pdev;
55 int err, ret = 0; 54 int err, ret = 0;
@@ -96,9 +95,8 @@ int __devinit mantis_pci_init(struct mantis_pci *mantis)
96 } 95 }
97 96
98 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency); 97 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
99 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
100 mantis->latency = latency; 98 mantis->latency = latency;
101 mantis->revision = revision; 99 mantis->revision = pdev->revision;
102 100
103 dprintk(MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ", 101 dprintk(MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ",
104 mantis->revision, 102 mantis->revision,
diff --git a/drivers/media/dvb/mantis/mantis_uart.c b/drivers/media/dvb/mantis/mantis_uart.c
index 7d2f2398fa8b..f807c8ba26e4 100644
--- a/drivers/media/dvb/mantis/mantis_uart.c
+++ b/drivers/media/dvb/mantis/mantis_uart.c
@@ -172,7 +172,7 @@ int mantis_uart_init(struct mantis_pci *mantis)
172 mmwrite(mmread(MANTIS_UART_CTL) | MANTIS_UART_RXINT, MANTIS_UART_CTL); 172 mmwrite(mmread(MANTIS_UART_CTL) | MANTIS_UART_RXINT, MANTIS_UART_CTL);
173 173
174 schedule_work(&mantis->uart_work); 174 schedule_work(&mantis->uart_work);
175 dprintk(MANTIS_DEBUG, 1, "UART succesfully initialized"); 175 dprintk(MANTIS_DEBUG, 1, "UART successfully initialized");
176 176
177 return 0; 177 return 0;
178} 178}
@@ -182,5 +182,6 @@ void mantis_uart_exit(struct mantis_pci *mantis)
182{ 182{
183 /* disable interrupt */ 183 /* disable interrupt */
184 mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL); 184 mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL);
185 flush_work_sync(&mantis->uart_work);
185} 186}
186EXPORT_SYMBOL_GPL(mantis_uart_exit); 187EXPORT_SYMBOL_GPL(mantis_uart_exit);
diff --git a/drivers/media/dvb/mantis/mantis_vp1033.c b/drivers/media/dvb/mantis/mantis_vp1033.c
index 4a723bda0031..2ae0afa7756b 100644
--- a/drivers/media/dvb/mantis/mantis_vp1033.c
+++ b/drivers/media/dvb/mantis/mantis_vp1033.c
@@ -37,7 +37,7 @@
37 37
38u8 lgtdqcs001f_inittab[] = { 38u8 lgtdqcs001f_inittab[] = {
39 0x01, 0x15, 39 0x01, 0x15,
40 0x02, 0x00, 40 0x02, 0x30,
41 0x03, 0x00, 41 0x03, 0x00,
42 0x04, 0x2a, 42 0x04, 0x2a,
43 0x05, 0x85, 43 0x05, 0x85,
@@ -173,7 +173,7 @@ static int vp1033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
173 msleep(250); 173 msleep(250);
174 174
175 dprintk(MANTIS_ERROR, 1, "Probing for STV0299 (DVB-S)"); 175 dprintk(MANTIS_ERROR, 1, "Probing for STV0299 (DVB-S)");
176 fe = stv0299_attach(&lgtdqcs001f_config, adapter); 176 fe = dvb_attach(stv0299_attach, &lgtdqcs001f_config, adapter);
177 177
178 if (fe) { 178 if (fe) {
179 fe->ops.tuner_ops.set_params = lgtdqcs001f_tuner_set; 179 fe->ops.tuner_ops.set_params = lgtdqcs001f_tuner_set;
diff --git a/drivers/media/dvb/mantis/mantis_vp1034.c b/drivers/media/dvb/mantis/mantis_vp1034.c
index 8e6ae558ee57..26bc0cbe84d4 100644
--- a/drivers/media/dvb/mantis/mantis_vp1034.c
+++ b/drivers/media/dvb/mantis/mantis_vp1034.c
@@ -50,13 +50,13 @@ int vp1034_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
50 switch (voltage) { 50 switch (voltage) {
51 case SEC_VOLTAGE_13: 51 case SEC_VOLTAGE_13:
52 dprintk(MANTIS_ERROR, 1, "Polarization=[13V]"); 52 dprintk(MANTIS_ERROR, 1, "Polarization=[13V]");
53 gpio_set_bits(mantis, 13, 1); 53 mantis_gpio_set_bits(mantis, 13, 1);
54 gpio_set_bits(mantis, 14, 0); 54 mantis_gpio_set_bits(mantis, 14, 0);
55 break; 55 break;
56 case SEC_VOLTAGE_18: 56 case SEC_VOLTAGE_18:
57 dprintk(MANTIS_ERROR, 1, "Polarization=[18V]"); 57 dprintk(MANTIS_ERROR, 1, "Polarization=[18V]");
58 gpio_set_bits(mantis, 13, 1); 58 mantis_gpio_set_bits(mantis, 13, 1);
59 gpio_set_bits(mantis, 14, 1); 59 mantis_gpio_set_bits(mantis, 14, 1);
60 break; 60 break;
61 case SEC_VOLTAGE_OFF: 61 case SEC_VOLTAGE_OFF:
62 dprintk(MANTIS_ERROR, 1, "Frontend (dummy) POWERDOWN"); 62 dprintk(MANTIS_ERROR, 1, "Frontend (dummy) POWERDOWN");
@@ -82,7 +82,7 @@ static int vp1034_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
82 msleep(250); 82 msleep(250);
83 83
84 dprintk(MANTIS_ERROR, 1, "Probing for MB86A16 (DVB-S/DSS)"); 84 dprintk(MANTIS_ERROR, 1, "Probing for MB86A16 (DVB-S/DSS)");
85 fe = mb86a16_attach(&vp1034_mb86a16_config, adapter); 85 fe = dvb_attach(mb86a16_attach, &vp1034_mb86a16_config, adapter);
86 if (fe) { 86 if (fe) {
87 dprintk(MANTIS_ERROR, 1, 87 dprintk(MANTIS_ERROR, 1,
88 "found MB86A16 DVB-S/DSS frontend @0x%02x", 88 "found MB86A16 DVB-S/DSS frontend @0x%02x",
diff --git a/drivers/media/dvb/mantis/mantis_vp1041.c b/drivers/media/dvb/mantis/mantis_vp1041.c
index d1aa2bc0c155..38a436ca2fdf 100644
--- a/drivers/media/dvb/mantis/mantis_vp1041.c
+++ b/drivers/media/dvb/mantis/mantis_vp1041.c
@@ -316,14 +316,14 @@ static int vp1041_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
316 if (err == 0) { 316 if (err == 0) {
317 mantis_frontend_soft_reset(mantis); 317 mantis_frontend_soft_reset(mantis);
318 msleep(250); 318 msleep(250);
319 mantis->fe = stb0899_attach(&vp1041_stb0899_config, adapter); 319 mantis->fe = dvb_attach(stb0899_attach, &vp1041_stb0899_config, adapter);
320 if (mantis->fe) { 320 if (mantis->fe) {
321 dprintk(MANTIS_ERROR, 1, 321 dprintk(MANTIS_ERROR, 1,
322 "found STB0899 DVB-S/DVB-S2 frontend @0x%02x", 322 "found STB0899 DVB-S/DVB-S2 frontend @0x%02x",
323 vp1041_stb0899_config.demod_address); 323 vp1041_stb0899_config.demod_address);
324 324
325 if (stb6100_attach(mantis->fe, &vp1041_stb6100_config, adapter)) { 325 if (dvb_attach(stb6100_attach, mantis->fe, &vp1041_stb6100_config, adapter)) {
326 if (!lnbp21_attach(mantis->fe, adapter, 0, 0)) 326 if (!dvb_attach(lnbp21_attach, mantis->fe, adapter, 0, 0))
327 dprintk(MANTIS_ERROR, 1, "No LNBP21 found!"); 327 dprintk(MANTIS_ERROR, 1, "No LNBP21 found!");
328 } 328 }
329 } else { 329 } else {
diff --git a/drivers/media/dvb/mantis/mantis_vp2033.c b/drivers/media/dvb/mantis/mantis_vp2033.c
index 10ce81790a8c..06da0ddf05a7 100644
--- a/drivers/media/dvb/mantis/mantis_vp2033.c
+++ b/drivers/media/dvb/mantis/mantis_vp2033.c
@@ -132,7 +132,7 @@ static int vp2033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
132 msleep(250); 132 msleep(250);
133 133
134 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)"); 134 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
135 fe = tda10021_attach(&vp2033_tda1002x_cu1216_config, 135 fe = dvb_attach(tda10021_attach, &vp2033_tda1002x_cu1216_config,
136 adapter, 136 adapter,
137 read_pwm(mantis)); 137 read_pwm(mantis));
138 138
@@ -141,7 +141,7 @@ static int vp2033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
141 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x", 141 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
142 vp2033_tda1002x_cu1216_config.demod_address); 142 vp2033_tda1002x_cu1216_config.demod_address);
143 } else { 143 } else {
144 fe = tda10023_attach(&vp2033_tda10023_cu1216_config, 144 fe = dvb_attach(tda10023_attach, &vp2033_tda10023_cu1216_config,
145 adapter, 145 adapter,
146 read_pwm(mantis)); 146 read_pwm(mantis));
147 147
diff --git a/drivers/media/dvb/mantis/mantis_vp2040.c b/drivers/media/dvb/mantis/mantis_vp2040.c
index a7ca233e800b..f72b137b7652 100644
--- a/drivers/media/dvb/mantis/mantis_vp2040.c
+++ b/drivers/media/dvb/mantis/mantis_vp2040.c
@@ -132,7 +132,7 @@ static int vp2040_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
132 msleep(250); 132 msleep(250);
133 133
134 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)"); 134 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
135 fe = tda10021_attach(&vp2040_tda1002x_cu1216_config, 135 fe = dvb_attach(tda10021_attach, &vp2040_tda1002x_cu1216_config,
136 adapter, 136 adapter,
137 read_pwm(mantis)); 137 read_pwm(mantis));
138 138
@@ -141,7 +141,7 @@ static int vp2040_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
141 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x", 141 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
142 vp2040_tda1002x_cu1216_config.demod_address); 142 vp2040_tda1002x_cu1216_config.demod_address);
143 } else { 143 } else {
144 fe = tda10023_attach(&vp2040_tda10023_cu1216_config, 144 fe = dvb_attach(tda10023_attach, &vp2040_tda10023_cu1216_config,
145 adapter, 145 adapter,
146 read_pwm(mantis)); 146 read_pwm(mantis));
147 147
diff --git a/drivers/media/dvb/mantis/mantis_vp3030.c b/drivers/media/dvb/mantis/mantis_vp3030.c
index 1f4334214953..c09308cd3ac6 100644
--- a/drivers/media/dvb/mantis/mantis_vp3030.c
+++ b/drivers/media/dvb/mantis/mantis_vp3030.c
@@ -59,21 +59,21 @@ static int vp3030_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
59 struct mantis_hwconfig *config = mantis->hwconfig; 59 struct mantis_hwconfig *config = mantis->hwconfig;
60 int err = 0; 60 int err = 0;
61 61
62 gpio_set_bits(mantis, config->reset, 0); 62 mantis_gpio_set_bits(mantis, config->reset, 0);
63 msleep(100); 63 msleep(100);
64 err = mantis_frontend_power(mantis, POWER_ON); 64 err = mantis_frontend_power(mantis, POWER_ON);
65 msleep(100); 65 msleep(100);
66 gpio_set_bits(mantis, config->reset, 1); 66 mantis_gpio_set_bits(mantis, config->reset, 1);
67 67
68 if (err == 0) { 68 if (err == 0) {
69 msleep(250); 69 msleep(250);
70 dprintk(MANTIS_ERROR, 1, "Probing for 10353 (DVB-T)"); 70 dprintk(MANTIS_ERROR, 1, "Probing for 10353 (DVB-T)");
71 fe = zl10353_attach(&mantis_vp3030_config, adapter); 71 fe = dvb_attach(zl10353_attach, &mantis_vp3030_config, adapter);
72 72
73 if (!fe) 73 if (!fe)
74 return -1; 74 return -1;
75 75
76 tda665x_attach(fe, &env57h12d5_config, adapter); 76 dvb_attach(tda665x_attach, fe, &env57h12d5_config, adapter);
77 } else { 77 } else {
78 dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>", 78 dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>",
79 adapter->name, 79 adapter->name,
diff --git a/drivers/media/dvb/ngene/Makefile b/drivers/media/dvb/ngene/Makefile
index 0608aabb14ee..2bc96874d044 100644
--- a/drivers/media/dvb/ngene/Makefile
+++ b/drivers/media/dvb/ngene/Makefile
@@ -9,3 +9,6 @@ obj-$(CONFIG_DVB_NGENE) += ngene.o
9EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ 9EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
10EXTRA_CFLAGS += -Idrivers/media/dvb/frontends/ 10EXTRA_CFLAGS += -Idrivers/media/dvb/frontends/
11EXTRA_CFLAGS += -Idrivers/media/common/tuners/ 11EXTRA_CFLAGS += -Idrivers/media/common/tuners/
12
13# For the staging CI driver cxd2099
14EXTRA_CFLAGS += -Idrivers/staging/cxd2099/
diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
index 4692a41ad95b..fcf4be901ec8 100644
--- a/drivers/media/dvb/ngene/ngene-cards.c
+++ b/drivers/media/dvb/ngene/ngene-cards.c
@@ -48,20 +48,27 @@
48 48
49static int tuner_attach_stv6110(struct ngene_channel *chan) 49static int tuner_attach_stv6110(struct ngene_channel *chan)
50{ 50{
51 struct i2c_adapter *i2c;
51 struct stv090x_config *feconf = (struct stv090x_config *) 52 struct stv090x_config *feconf = (struct stv090x_config *)
52 chan->dev->card_info->fe_config[chan->number]; 53 chan->dev->card_info->fe_config[chan->number];
53 struct stv6110x_config *tunerconf = (struct stv6110x_config *) 54 struct stv6110x_config *tunerconf = (struct stv6110x_config *)
54 chan->dev->card_info->tuner_config[chan->number]; 55 chan->dev->card_info->tuner_config[chan->number];
55 struct stv6110x_devctl *ctl; 56 struct stv6110x_devctl *ctl;
56 57
57 ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf, 58 /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
58 &chan->i2c_adapter); 59 if (chan->number < 2)
60 i2c = &chan->dev->channel[0].i2c_adapter;
61 else
62 i2c = &chan->dev->channel[1].i2c_adapter;
63
64 ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf, i2c);
59 if (ctl == NULL) { 65 if (ctl == NULL) {
60 printk(KERN_ERR DEVICE_NAME ": No STV6110X found!\n"); 66 printk(KERN_ERR DEVICE_NAME ": No STV6110X found!\n");
61 return -ENODEV; 67 return -ENODEV;
62 } 68 }
63 69
64 feconf->tuner_init = ctl->tuner_init; 70 feconf->tuner_init = ctl->tuner_init;
71 feconf->tuner_sleep = ctl->tuner_sleep;
65 feconf->tuner_set_mode = ctl->tuner_set_mode; 72 feconf->tuner_set_mode = ctl->tuner_set_mode;
66 feconf->tuner_set_frequency = ctl->tuner_set_frequency; 73 feconf->tuner_set_frequency = ctl->tuner_set_frequency;
67 feconf->tuner_get_frequency = ctl->tuner_get_frequency; 74 feconf->tuner_get_frequency = ctl->tuner_get_frequency;
@@ -78,29 +85,106 @@ static int tuner_attach_stv6110(struct ngene_channel *chan)
78 85
79static int demod_attach_stv0900(struct ngene_channel *chan) 86static int demod_attach_stv0900(struct ngene_channel *chan)
80{ 87{
88 struct i2c_adapter *i2c;
81 struct stv090x_config *feconf = (struct stv090x_config *) 89 struct stv090x_config *feconf = (struct stv090x_config *)
82 chan->dev->card_info->fe_config[chan->number]; 90 chan->dev->card_info->fe_config[chan->number];
83 91
84 chan->fe = dvb_attach(stv090x_attach, 92 /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
85 feconf, 93 /* Note: Both adapters share the same i2c bus, but the demod */
86 &chan->i2c_adapter, 94 /* driver requires that each demod has its own i2c adapter */
87 chan->number == 0 ? STV090x_DEMODULATOR_0 : 95 if (chan->number < 2)
88 STV090x_DEMODULATOR_1); 96 i2c = &chan->dev->channel[0].i2c_adapter;
97 else
98 i2c = &chan->dev->channel[1].i2c_adapter;
99
100 chan->fe = dvb_attach(stv090x_attach, feconf, i2c,
101 (chan->number & 1) == 0 ? STV090x_DEMODULATOR_0
102 : STV090x_DEMODULATOR_1);
89 if (chan->fe == NULL) { 103 if (chan->fe == NULL) {
90 printk(KERN_ERR DEVICE_NAME ": No STV0900 found!\n"); 104 printk(KERN_ERR DEVICE_NAME ": No STV0900 found!\n");
91 return -ENODEV; 105 return -ENODEV;
92 } 106 }
93 107
94 if (!dvb_attach(lnbh24_attach, chan->fe, &chan->i2c_adapter, 0, 108 /* store channel info */
109 if (feconf->tuner_i2c_lock)
110 chan->fe->analog_demod_priv = chan;
111
112 if (!dvb_attach(lnbh24_attach, chan->fe, i2c, 0,
95 0, chan->dev->card_info->lnb[chan->number])) { 113 0, chan->dev->card_info->lnb[chan->number])) {
96 printk(KERN_ERR DEVICE_NAME ": No LNBH24 found!\n"); 114 printk(KERN_ERR DEVICE_NAME ": No LNBH24 found!\n");
97 dvb_frontend_detach(chan->fe); 115 dvb_frontend_detach(chan->fe);
116 chan->fe = NULL;
117 return -ENODEV;
118 }
119
120 return 0;
121}
122
123static void cineS2_tuner_i2c_lock(struct dvb_frontend *fe, int lock)
124{
125 struct ngene_channel *chan = fe->analog_demod_priv;
126
127 if (lock)
128 down(&chan->dev->pll_mutex);
129 else
130 up(&chan->dev->pll_mutex);
131}
132
133static int cineS2_probe(struct ngene_channel *chan)
134{
135 struct i2c_adapter *i2c;
136 struct stv090x_config *fe_conf;
137 u8 buf[3];
138 struct i2c_msg i2c_msg = { .flags = 0, .buf = buf };
139 int rc;
140
141 /* tuner 1+2: i2c adapter #0, tuner 3+4: i2c adapter #1 */
142 if (chan->number < 2)
143 i2c = &chan->dev->channel[0].i2c_adapter;
144 else
145 i2c = &chan->dev->channel[1].i2c_adapter;
146
147 fe_conf = chan->dev->card_info->fe_config[chan->number];
148 i2c_msg.addr = fe_conf->address;
149
150 /* probe demod */
151 i2c_msg.len = 2;
152 buf[0] = 0xf1;
153 buf[1] = 0x00;
154 rc = i2c_transfer(i2c, &i2c_msg, 1);
155 if (rc != 1)
156 return -ENODEV;
157
158 /* demod found, attach it */
159 rc = demod_attach_stv0900(chan);
160 if (rc < 0 || chan->number < 2)
161 return rc;
162
163 /* demod #2: reprogram outputs DPN1 & DPN2 */
164 i2c_msg.len = 3;
165 buf[0] = 0xf1;
166 switch (chan->number) {
167 case 2:
168 buf[1] = 0x5c;
169 buf[2] = 0xc2;
170 break;
171 case 3:
172 buf[1] = 0x61;
173 buf[2] = 0xcc;
174 break;
175 default:
98 return -ENODEV; 176 return -ENODEV;
99 } 177 }
178 rc = i2c_transfer(i2c, &i2c_msg, 1);
179 if (rc != 1) {
180 printk(KERN_ERR DEVICE_NAME ": could not setup DPNx\n");
181 return -EIO;
182 }
100 183
101 return 0; 184 return 0;
102} 185}
103 186
187
104static struct lgdt330x_config aver_m780 = { 188static struct lgdt330x_config aver_m780 = {
105 .demod_address = 0xb2 >> 1, 189 .demod_address = 0xb2 >> 1,
106 .demod_chip = LGDT3303, 190 .demod_chip = LGDT3303,
@@ -151,6 +235,29 @@ static struct stv090x_config fe_cineS2 = {
151 .adc2_range = STV090x_ADC_1Vpp, 235 .adc2_range = STV090x_ADC_1Vpp,
152 236
153 .diseqc_envelope_mode = true, 237 .diseqc_envelope_mode = true,
238
239 .tuner_i2c_lock = cineS2_tuner_i2c_lock,
240};
241
242static struct stv090x_config fe_cineS2_2 = {
243 .device = STV0900,
244 .demod_mode = STV090x_DUAL,
245 .clk_mode = STV090x_CLK_EXT,
246
247 .xtal = 27000000,
248 .address = 0x69,
249
250 .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
251 .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
252
253 .repeater_level = STV090x_RPTLEVEL_16,
254
255 .adc1_range = STV090x_ADC_1Vpp,
256 .adc2_range = STV090x_ADC_1Vpp,
257
258 .diseqc_envelope_mode = true,
259
260 .tuner_i2c_lock = cineS2_tuner_i2c_lock,
154}; 261};
155 262
156static struct stv6110x_config tuner_cineS2_0 = { 263static struct stv6110x_config tuner_cineS2_0 = {
@@ -175,7 +282,8 @@ static struct ngene_info ngene_info_cineS2 = {
175 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1}, 282 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
176 .lnb = {0x0b, 0x08}, 283 .lnb = {0x0b, 0x08},
177 .tsf = {3, 3}, 284 .tsf = {3, 3},
178 .fw_version = 15, 285 .fw_version = 18,
286 .msi_supported = true,
179}; 287};
180 288
181static struct ngene_info ngene_info_satixS2 = { 289static struct ngene_info ngene_info_satixS2 = {
@@ -188,46 +296,54 @@ static struct ngene_info ngene_info_satixS2 = {
188 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1}, 296 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
189 .lnb = {0x0b, 0x08}, 297 .lnb = {0x0b, 0x08},
190 .tsf = {3, 3}, 298 .tsf = {3, 3},
191 .fw_version = 15, 299 .fw_version = 18,
300 .msi_supported = true,
192}; 301};
193 302
194static struct ngene_info ngene_info_satixS2v2 = { 303static struct ngene_info ngene_info_satixS2v2 = {
195 .type = NGENE_SIDEWINDER, 304 .type = NGENE_SIDEWINDER,
196 .name = "Mystique SaTiX-S2 Dual (v2)", 305 .name = "Mystique SaTiX-S2 Dual (v2)",
197 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN}, 306 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
198 .demod_attach = {demod_attach_stv0900, demod_attach_stv0900}, 307 NGENE_IO_TSOUT},
199 .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110}, 308 .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
200 .fe_config = {&fe_cineS2, &fe_cineS2}, 309 .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110},
201 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1}, 310 .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
202 .lnb = {0x0a, 0x08}, 311 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
312 .lnb = {0x0a, 0x08, 0x0b, 0x09},
203 .tsf = {3, 3}, 313 .tsf = {3, 3},
204 .fw_version = 15, 314 .fw_version = 18,
315 .msi_supported = true,
205}; 316};
206 317
207static struct ngene_info ngene_info_cineS2v5 = { 318static struct ngene_info ngene_info_cineS2v5 = {
208 .type = NGENE_SIDEWINDER, 319 .type = NGENE_SIDEWINDER,
209 .name = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)", 320 .name = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
210 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN}, 321 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
211 .demod_attach = {demod_attach_stv0900, demod_attach_stv0900}, 322 NGENE_IO_TSOUT},
212 .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110}, 323 .demod_attach = {demod_attach_stv0900, demod_attach_stv0900, cineS2_probe, cineS2_probe},
213 .fe_config = {&fe_cineS2, &fe_cineS2}, 324 .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110},
214 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1}, 325 .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
215 .lnb = {0x0a, 0x08}, 326 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
327 .lnb = {0x0a, 0x08, 0x0b, 0x09},
216 .tsf = {3, 3}, 328 .tsf = {3, 3},
217 .fw_version = 15, 329 .fw_version = 18,
330 .msi_supported = true,
218}; 331};
219 332
333
220static struct ngene_info ngene_info_duoFlexS2 = { 334static struct ngene_info ngene_info_duoFlexS2 = {
221 .type = NGENE_SIDEWINDER, 335 .type = NGENE_SIDEWINDER,
222 .name = "Digital Devices DuoFlex S2 miniPCIe", 336 .name = "Digital Devices DuoFlex S2 miniPCIe",
223 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN}, 337 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN, NGENE_IO_TSIN,
224 .demod_attach = {demod_attach_stv0900, demod_attach_stv0900}, 338 NGENE_IO_TSOUT},
225 .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110}, 339 .demod_attach = {cineS2_probe, cineS2_probe, cineS2_probe, cineS2_probe},
226 .fe_config = {&fe_cineS2, &fe_cineS2}, 340 .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110, tuner_attach_stv6110},
227 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1}, 341 .fe_config = {&fe_cineS2, &fe_cineS2, &fe_cineS2_2, &fe_cineS2_2},
228 .lnb = {0x0a, 0x08}, 342 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1, &tuner_cineS2_0, &tuner_cineS2_1},
343 .lnb = {0x0a, 0x08, 0x0b, 0x09},
229 .tsf = {3, 3}, 344 .tsf = {3, 3},
230 .fw_version = 15, 345 .fw_version = 18,
346 .msi_supported = true,
231}; 347};
232 348
233static struct ngene_info ngene_info_m780 = { 349static struct ngene_info ngene_info_m780 = {
@@ -321,6 +437,7 @@ static struct pci_driver ngene_pci_driver = {
321 .probe = ngene_probe, 437 .probe = ngene_probe,
322 .remove = __devexit_p(ngene_remove), 438 .remove = __devexit_p(ngene_remove),
323 .err_handler = &ngene_errors, 439 .err_handler = &ngene_errors,
440 .shutdown = ngene_shutdown,
324}; 441};
325 442
326static __init int module_init_ngene(void) 443static __init int module_init_ngene(void)
diff --git a/drivers/media/dvb/ngene/ngene-core.c b/drivers/media/dvb/ngene/ngene-core.c
index 4caeb163a666..6927c726ce35 100644
--- a/drivers/media/dvb/ngene/ngene-core.c
+++ b/drivers/media/dvb/ngene/ngene-core.c
@@ -34,7 +34,6 @@
34#include <linux/io.h> 34#include <linux/io.h>
35#include <asm/div64.h> 35#include <asm/div64.h>
36#include <linux/pci.h> 36#include <linux/pci.h>
37#include <linux/smp_lock.h>
38#include <linux/timer.h> 37#include <linux/timer.h>
39#include <linux/byteorder/generic.h> 38#include <linux/byteorder/generic.h>
40#include <linux/firmware.h> 39#include <linux/firmware.h>
@@ -46,6 +45,9 @@ static int one_adapter = 1;
46module_param(one_adapter, int, 0444); 45module_param(one_adapter, int, 0444);
47MODULE_PARM_DESC(one_adapter, "Use only one adapter."); 46MODULE_PARM_DESC(one_adapter, "Use only one adapter.");
48 47
48static int shutdown_workaround;
49module_param(shutdown_workaround, int, 0644);
50MODULE_PARM_DESC(shutdown_workaround, "Activate workaround for shutdown problem with some chipsets.");
49 51
50static int debug; 52static int debug;
51module_param(debug, int, 0444); 53module_param(debug, int, 0444);
@@ -120,7 +122,7 @@ static void demux_tasklet(unsigned long data)
120 Cur->ngeneBuffer.SR.Flags &= 122 Cur->ngeneBuffer.SR.Flags &=
121 ~0x40; 123 ~0x40;
122 break; 124 break;
123 /* Stop proccessing stream */ 125 /* Stop processing stream */
124 } 126 }
125 } else { 127 } else {
126 /* We got a valid buffer, 128 /* We got a valid buffer,
@@ -131,7 +133,7 @@ static void demux_tasklet(unsigned long data)
131 printk(KERN_ERR DEVICE_NAME ": OOPS\n"); 133 printk(KERN_ERR DEVICE_NAME ": OOPS\n");
132 if (chan->HWState == HWSTATE_RUN) { 134 if (chan->HWState == HWSTATE_RUN) {
133 Cur->ngeneBuffer.SR.Flags &= ~0x40; 135 Cur->ngeneBuffer.SR.Flags &= ~0x40;
134 break; /* Stop proccessing stream */ 136 break; /* Stop processing stream */
135 } 137 }
136 } 138 }
137 if (chan->AudioDTOUpdated) { 139 if (chan->AudioDTOUpdated) {
@@ -144,7 +146,7 @@ static void demux_tasklet(unsigned long data)
144 } 146 }
145 } else { 147 } else {
146 if (chan->HWState == HWSTATE_RUN) { 148 if (chan->HWState == HWSTATE_RUN) {
147 u32 Flags = 0; 149 u32 Flags = chan->DataFormatFlags;
148 IBufferExchange *exch1 = chan->pBufferExchange; 150 IBufferExchange *exch1 = chan->pBufferExchange;
149 IBufferExchange *exch2 = chan->pBufferExchange2; 151 IBufferExchange *exch2 = chan->pBufferExchange2;
150 if (Cur->ngeneBuffer.SR.Flags & 0x01) 152 if (Cur->ngeneBuffer.SR.Flags & 0x01)
@@ -475,9 +477,9 @@ static u8 SPDIFConfiguration[10] = {
475 477
476/* Set NGENE I2S Config to transport stream compatible mode */ 478/* Set NGENE I2S Config to transport stream compatible mode */
477 479
478static u8 TS_I2SConfiguration[4] = { 0x3E, 0x1A, 0x00, 0x00 }; /*3e 18 00 00 ?*/ 480static u8 TS_I2SConfiguration[4] = { 0x3E, 0x18, 0x00, 0x00 };
479 481
480static u8 TS_I2SOutConfiguration[4] = { 0x80, 0x20, 0x00, 0x00 }; 482static u8 TS_I2SOutConfiguration[4] = { 0x80, 0x04, 0x00, 0x00 };
481 483
482static u8 ITUDecoderSetup[4][16] = { 484static u8 ITUDecoderSetup[4][16] = {
483 {0x1c, 0x13, 0x01, 0x68, 0x3d, 0x90, 0x14, 0x20, /* SDTV */ 485 {0x1c, 0x13, 0x01, 0x68, 0x3d, 0x90, 0x14, 0x20, /* SDTV */
@@ -750,13 +752,11 @@ void set_transfer(struct ngene_channel *chan, int state)
750 if (chan->mode & NGENE_IO_TSOUT) { 752 if (chan->mode & NGENE_IO_TSOUT) {
751 chan->pBufferExchange = tsout_exchange; 753 chan->pBufferExchange = tsout_exchange;
752 /* 0x66666666 = 50MHz *2^33 /250MHz */ 754 /* 0x66666666 = 50MHz *2^33 /250MHz */
753 chan->AudioDTOValue = 0x66666666; 755 chan->AudioDTOValue = 0x80000000;
754 /* set_dto(chan, 38810700+1000); */ 756 chan->AudioDTOUpdated = 1;
755 /* set_dto(chan, 19392658); */
756 } 757 }
757 if (chan->mode & NGENE_IO_TSIN) 758 if (chan->mode & NGENE_IO_TSIN)
758 chan->pBufferExchange = tsin_exchange; 759 chan->pBufferExchange = tsin_exchange;
759 /* ngwritel(0, 0x9310); */
760 spin_unlock_irq(&chan->state_lock); 760 spin_unlock_irq(&chan->state_lock);
761 } else 761 } else
762 ;/* printk(KERN_INFO DEVICE_NAME ": lock=%08x\n", 762 ;/* printk(KERN_INFO DEVICE_NAME ": lock=%08x\n",
@@ -1169,6 +1169,7 @@ static void ngene_release_buffers(struct ngene *dev)
1169 iounmap(dev->iomem); 1169 iounmap(dev->iomem);
1170 free_common_buffers(dev); 1170 free_common_buffers(dev);
1171 vfree(dev->tsout_buf); 1171 vfree(dev->tsout_buf);
1172 vfree(dev->tsin_buf);
1172 vfree(dev->ain_buf); 1173 vfree(dev->ain_buf);
1173 vfree(dev->vin_buf); 1174 vfree(dev->vin_buf);
1174 vfree(dev); 1175 vfree(dev);
@@ -1185,6 +1186,13 @@ static int ngene_get_buffers(struct ngene *dev)
1185 dvb_ringbuffer_init(&dev->tsout_rbuf, 1186 dvb_ringbuffer_init(&dev->tsout_rbuf,
1186 dev->tsout_buf, TSOUT_BUF_SIZE); 1187 dev->tsout_buf, TSOUT_BUF_SIZE);
1187 } 1188 }
1189 if (dev->card_info->io_type[2]&NGENE_IO_TSIN) {
1190 dev->tsin_buf = vmalloc(TSIN_BUF_SIZE);
1191 if (!dev->tsin_buf)
1192 return -ENOMEM;
1193 dvb_ringbuffer_init(&dev->tsin_rbuf,
1194 dev->tsin_buf, TSIN_BUF_SIZE);
1195 }
1188 if (dev->card_info->io_type[2] & NGENE_IO_AIN) { 1196 if (dev->card_info->io_type[2] & NGENE_IO_AIN) {
1189 dev->ain_buf = vmalloc(AIN_BUF_SIZE); 1197 dev->ain_buf = vmalloc(AIN_BUF_SIZE);
1190 if (!dev->ain_buf) 1198 if (!dev->ain_buf)
@@ -1258,6 +1266,10 @@ static int ngene_load_firm(struct ngene *dev)
1258 fw_name = "ngene_17.fw"; 1266 fw_name = "ngene_17.fw";
1259 dev->cmd_timeout_workaround = true; 1267 dev->cmd_timeout_workaround = true;
1260 break; 1268 break;
1269 case 18:
1270 size = 0;
1271 fw_name = "ngene_18.fw";
1272 break;
1261 } 1273 }
1262 1274
1263 if (request_firmware(&fw, fw_name, &dev->pci_dev->dev) < 0) { 1275 if (request_firmware(&fw, fw_name, &dev->pci_dev->dev) < 0) {
@@ -1267,6 +1279,8 @@ static int ngene_load_firm(struct ngene *dev)
1267 ": Copy %s to your hotplug directory!\n", fw_name); 1279 ": Copy %s to your hotplug directory!\n", fw_name);
1268 return -1; 1280 return -1;
1269 } 1281 }
1282 if (size == 0)
1283 size = fw->size;
1270 if (size != fw->size) { 1284 if (size != fw->size) {
1271 printk(KERN_ERR DEVICE_NAME 1285 printk(KERN_ERR DEVICE_NAME
1272 ": Firmware %s has invalid size!", fw_name); 1286 ": Firmware %s has invalid size!", fw_name);
@@ -1302,10 +1316,38 @@ static void ngene_stop(struct ngene *dev)
1302#endif 1316#endif
1303} 1317}
1304 1318
1319static int ngene_buffer_config(struct ngene *dev)
1320{
1321 int stat;
1322
1323 if (dev->card_info->fw_version >= 17) {
1324 u8 tsin12_config[6] = { 0x60, 0x60, 0x00, 0x00, 0x00, 0x00 };
1325 u8 tsin1234_config[6] = { 0x30, 0x30, 0x00, 0x30, 0x30, 0x00 };
1326 u8 tsio1235_config[6] = { 0x30, 0x30, 0x00, 0x28, 0x00, 0x38 };
1327 u8 *bconf = tsin12_config;
1328
1329 if (dev->card_info->io_type[2]&NGENE_IO_TSIN &&
1330 dev->card_info->io_type[3]&NGENE_IO_TSIN) {
1331 bconf = tsin1234_config;
1332 if (dev->card_info->io_type[4]&NGENE_IO_TSOUT &&
1333 dev->ci.en)
1334 bconf = tsio1235_config;
1335 }
1336 stat = ngene_command_config_free_buf(dev, bconf);
1337 } else {
1338 int bconf = BUFFER_CONFIG_4422;
1339
1340 if (dev->card_info->io_type[3] == NGENE_IO_TSIN)
1341 bconf = BUFFER_CONFIG_3333;
1342 stat = ngene_command_config_buf(dev, bconf);
1343 }
1344 return stat;
1345}
1346
1347
1305static int ngene_start(struct ngene *dev) 1348static int ngene_start(struct ngene *dev)
1306{ 1349{
1307 int stat; 1350 int stat;
1308 unsigned long flags;
1309 int i; 1351 int i;
1310 1352
1311 pci_set_master(dev->pci_dev); 1353 pci_set_master(dev->pci_dev);
@@ -1338,6 +1380,8 @@ static int ngene_start(struct ngene *dev)
1338#ifdef CONFIG_PCI_MSI 1380#ifdef CONFIG_PCI_MSI
1339 /* enable MSI if kernel and card support it */ 1381 /* enable MSI if kernel and card support it */
1340 if (pci_msi_enabled() && dev->card_info->msi_supported) { 1382 if (pci_msi_enabled() && dev->card_info->msi_supported) {
1383 unsigned long flags;
1384
1341 ngwritel(0, NGENE_INT_ENABLE); 1385 ngwritel(0, NGENE_INT_ENABLE);
1342 free_irq(dev->pci_dev->irq, dev); 1386 free_irq(dev->pci_dev->irq, dev);
1343 stat = pci_enable_msi(dev->pci_dev); 1387 stat = pci_enable_msi(dev->pci_dev);
@@ -1365,23 +1409,6 @@ static int ngene_start(struct ngene *dev)
1365 if (stat < 0) 1409 if (stat < 0)
1366 goto fail; 1410 goto fail;
1367 1411
1368 if (dev->card_info->fw_version == 17) {
1369 u8 tsin4_config[6] = {
1370 3072 / 64, 3072 / 64, 0, 3072 / 64, 3072 / 64, 0};
1371 u8 default_config[6] = {
1372 4096 / 64, 4096 / 64, 0, 2048 / 64, 2048 / 64, 0};
1373 u8 *bconf = default_config;
1374
1375 if (dev->card_info->io_type[3] == NGENE_IO_TSIN)
1376 bconf = tsin4_config;
1377 dprintk(KERN_DEBUG DEVICE_NAME ": FW 17 buffer config\n");
1378 stat = ngene_command_config_free_buf(dev, bconf);
1379 } else {
1380 int bconf = BUFFER_CONFIG_4422;
1381 if (dev->card_info->io_type[3] == NGENE_IO_TSIN)
1382 bconf = BUFFER_CONFIG_3333;
1383 stat = ngene_command_config_buf(dev, bconf);
1384 }
1385 if (!stat) 1412 if (!stat)
1386 return stat; 1413 return stat;
1387 1414
@@ -1397,9 +1424,6 @@ fail2:
1397 return stat; 1424 return stat;
1398} 1425}
1399 1426
1400
1401
1402
1403/****************************************************************************/ 1427/****************************************************************************/
1404/****************************************************************************/ 1428/****************************************************************************/
1405/****************************************************************************/ 1429/****************************************************************************/
@@ -1408,20 +1432,25 @@ static void release_channel(struct ngene_channel *chan)
1408{ 1432{
1409 struct dvb_demux *dvbdemux = &chan->demux; 1433 struct dvb_demux *dvbdemux = &chan->demux;
1410 struct ngene *dev = chan->dev; 1434 struct ngene *dev = chan->dev;
1411 struct ngene_info *ni = dev->card_info;
1412 int io = ni->io_type[chan->number];
1413 1435
1414 if (chan->dev->cmd_timeout_workaround && chan->running) 1436 if (chan->running)
1415 set_transfer(chan, 0); 1437 set_transfer(chan, 0);
1416 1438
1417 tasklet_kill(&chan->demux_tasklet); 1439 tasklet_kill(&chan->demux_tasklet);
1418 1440
1419 if (io & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) { 1441 if (chan->ci_dev) {
1420 if (chan->fe) { 1442 dvb_unregister_device(chan->ci_dev);
1421 dvb_unregister_frontend(chan->fe); 1443 chan->ci_dev = NULL;
1422 dvb_frontend_detach(chan->fe); 1444 }
1423 chan->fe = NULL; 1445
1424 } 1446 if (chan->fe) {
1447 dvb_unregister_frontend(chan->fe);
1448 dvb_frontend_detach(chan->fe);
1449 chan->fe = NULL;
1450 }
1451
1452 if (chan->has_demux) {
1453 dvb_net_release(&chan->dvbnet);
1425 dvbdemux->dmx.close(&dvbdemux->dmx); 1454 dvbdemux->dmx.close(&dvbdemux->dmx);
1426 dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, 1455 dvbdemux->dmx.remove_frontend(&dvbdemux->dmx,
1427 &chan->hw_frontend); 1456 &chan->hw_frontend);
@@ -1429,9 +1458,12 @@ static void release_channel(struct ngene_channel *chan)
1429 &chan->mem_frontend); 1458 &chan->mem_frontend);
1430 dvb_dmxdev_release(&chan->dmxdev); 1459 dvb_dmxdev_release(&chan->dmxdev);
1431 dvb_dmx_release(&chan->demux); 1460 dvb_dmx_release(&chan->demux);
1461 chan->has_demux = false;
1462 }
1432 1463
1433 if (chan->number == 0 || !one_adapter) 1464 if (chan->has_adapter) {
1434 dvb_unregister_adapter(&dev->adapter[chan->number]); 1465 dvb_unregister_adapter(&dev->adapter[chan->number]);
1466 chan->has_adapter = false;
1435 } 1467 }
1436} 1468}
1437 1469
@@ -1449,9 +1481,27 @@ static int init_channel(struct ngene_channel *chan)
1449 chan->type = io; 1481 chan->type = io;
1450 chan->mode = chan->type; /* for now only one mode */ 1482 chan->mode = chan->type; /* for now only one mode */
1451 1483
1484 if (io & NGENE_IO_TSIN) {
1485 chan->fe = NULL;
1486 if (ni->demod_attach[nr]) {
1487 ret = ni->demod_attach[nr](chan);
1488 if (ret < 0)
1489 goto err;
1490 }
1491 if (chan->fe && ni->tuner_attach[nr]) {
1492 ret = ni->tuner_attach[nr](chan);
1493 if (ret < 0)
1494 goto err;
1495 }
1496 }
1497
1498 if (!dev->ci.en && (io & NGENE_IO_TSOUT))
1499 return 0;
1500
1452 if (io & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) { 1501 if (io & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) {
1453 if (nr >= STREAM_AUDIOIN1) 1502 if (nr >= STREAM_AUDIOIN1)
1454 chan->DataFormatFlags = DF_SWAP32; 1503 chan->DataFormatFlags = DF_SWAP32;
1504
1455 if (nr == 0 || !one_adapter || dev->first_adapter == NULL) { 1505 if (nr == 0 || !one_adapter || dev->first_adapter == NULL) {
1456 adapter = &dev->adapter[nr]; 1506 adapter = &dev->adapter[nr];
1457 ret = dvb_register_adapter(adapter, "nGene", 1507 ret = dvb_register_adapter(adapter, "nGene",
@@ -1459,40 +1509,51 @@ static int init_channel(struct ngene_channel *chan)
1459 &chan->dev->pci_dev->dev, 1509 &chan->dev->pci_dev->dev,
1460 adapter_nr); 1510 adapter_nr);
1461 if (ret < 0) 1511 if (ret < 0)
1462 return ret; 1512 goto err;
1463 if (dev->first_adapter == NULL) 1513 if (dev->first_adapter == NULL)
1464 dev->first_adapter = adapter; 1514 dev->first_adapter = adapter;
1465 } else { 1515 chan->has_adapter = true;
1516 } else
1466 adapter = dev->first_adapter; 1517 adapter = dev->first_adapter;
1467 } 1518 }
1519
1520 if (dev->ci.en && (io & NGENE_IO_TSOUT)) {
1521 dvb_ca_en50221_init(adapter, dev->ci.en, 0, 1);
1522 set_transfer(chan, 1);
1523 chan->dev->channel[2].DataFormatFlags = DF_SWAP32;
1524 set_transfer(&chan->dev->channel[2], 1);
1525 dvb_register_device(adapter, &chan->ci_dev,
1526 &ngene_dvbdev_ci, (void *) chan,
1527 DVB_DEVICE_SEC);
1528 if (!chan->ci_dev)
1529 goto err;
1530 }
1468 1531
1532 if (chan->fe) {
1533 if (dvb_register_frontend(adapter, chan->fe) < 0)
1534 goto err;
1535 chan->has_demux = true;
1536 }
1537
1538 if (chan->has_demux) {
1469 ret = my_dvb_dmx_ts_card_init(dvbdemux, "SW demux", 1539 ret = my_dvb_dmx_ts_card_init(dvbdemux, "SW demux",
1470 ngene_start_feed, 1540 ngene_start_feed,
1471 ngene_stop_feed, chan); 1541 ngene_stop_feed, chan);
1472 ret = my_dvb_dmxdev_ts_card_init(&chan->dmxdev, &chan->demux, 1542 ret = my_dvb_dmxdev_ts_card_init(&chan->dmxdev, &chan->demux,
1473 &chan->hw_frontend, 1543 &chan->hw_frontend,
1474 &chan->mem_frontend, adapter); 1544 &chan->mem_frontend, adapter);
1545 ret = dvb_net_init(adapter, &chan->dvbnet, &chan->demux.dmx);
1475 } 1546 }
1476 1547
1477 if (io & NGENE_IO_TSIN) { 1548 return ret;
1549
1550err:
1551 if (chan->fe) {
1552 dvb_frontend_detach(chan->fe);
1478 chan->fe = NULL; 1553 chan->fe = NULL;
1479 if (ni->demod_attach[nr])
1480 ni->demod_attach[nr](chan);
1481 if (chan->fe) {
1482 if (dvb_register_frontend(adapter, chan->fe) < 0) {
1483 if (chan->fe->ops.release)
1484 chan->fe->ops.release(chan->fe);
1485 chan->fe = NULL;
1486 }
1487 }
1488 if (chan->fe && ni->tuner_attach[nr])
1489 if (ni->tuner_attach[nr] (chan) < 0) {
1490 printk(KERN_ERR DEVICE_NAME
1491 ": Tuner attach failed on channel %d!\n",
1492 nr);
1493 }
1494 } 1554 }
1495 return ret; 1555 release_channel(chan);
1556 return 0;
1496} 1557}
1497 1558
1498static int init_channels(struct ngene *dev) 1559static int init_channels(struct ngene *dev)
@@ -1510,18 +1571,71 @@ static int init_channels(struct ngene *dev)
1510 return 0; 1571 return 0;
1511} 1572}
1512 1573
1574static void cxd_attach(struct ngene *dev)
1575{
1576 struct ngene_ci *ci = &dev->ci;
1577
1578 ci->en = cxd2099_attach(0x40, dev, &dev->channel[0].i2c_adapter);
1579 ci->dev = dev;
1580 return;
1581}
1582
1583static void cxd_detach(struct ngene *dev)
1584{
1585 struct ngene_ci *ci = &dev->ci;
1586
1587 dvb_ca_en50221_release(ci->en);
1588 kfree(ci->en);
1589 ci->en = 0;
1590}
1591
1592/***********************************/
1593/* workaround for shutdown failure */
1594/***********************************/
1595
1596static void ngene_unlink(struct ngene *dev)
1597{
1598 struct ngene_command com;
1599
1600 com.cmd.hdr.Opcode = CMD_MEM_WRITE;
1601 com.cmd.hdr.Length = 3;
1602 com.cmd.MemoryWrite.address = 0x910c;
1603 com.cmd.MemoryWrite.data = 0xff;
1604 com.in_len = 3;
1605 com.out_len = 1;
1606
1607 down(&dev->cmd_mutex);
1608 ngwritel(0, NGENE_INT_ENABLE);
1609 ngene_command_mutex(dev, &com);
1610 up(&dev->cmd_mutex);
1611}
1612
1613void ngene_shutdown(struct pci_dev *pdev)
1614{
1615 struct ngene *dev = (struct ngene *)pci_get_drvdata(pdev);
1616
1617 if (!dev || !shutdown_workaround)
1618 return;
1619
1620 printk(KERN_INFO DEVICE_NAME ": shutdown workaround...\n");
1621 ngene_unlink(dev);
1622 pci_disable_device(pdev);
1623}
1624
1513/****************************************************************************/ 1625/****************************************************************************/
1514/* device probe/remove calls ************************************************/ 1626/* device probe/remove calls ************************************************/
1515/****************************************************************************/ 1627/****************************************************************************/
1516 1628
1517void __devexit ngene_remove(struct pci_dev *pdev) 1629void __devexit ngene_remove(struct pci_dev *pdev)
1518{ 1630{
1519 struct ngene *dev = (struct ngene *)pci_get_drvdata(pdev); 1631 struct ngene *dev = pci_get_drvdata(pdev);
1520 int i; 1632 int i;
1521 1633
1522 tasklet_kill(&dev->event_tasklet); 1634 tasklet_kill(&dev->event_tasklet);
1523 for (i = MAX_STREAM - 1; i >= 0; i--) 1635 for (i = MAX_STREAM - 1; i >= 0; i--)
1524 release_channel(&dev->channel[i]); 1636 release_channel(&dev->channel[i]);
1637 if (dev->ci.en)
1638 cxd_detach(dev);
1525 ngene_stop(dev); 1639 ngene_stop(dev);
1526 ngene_release_buffers(dev); 1640 ngene_release_buffers(dev);
1527 pci_set_drvdata(pdev, NULL); 1641 pci_set_drvdata(pdev, NULL);
@@ -1537,12 +1651,11 @@ int __devinit ngene_probe(struct pci_dev *pci_dev,
1537 if (pci_enable_device(pci_dev) < 0) 1651 if (pci_enable_device(pci_dev) < 0)
1538 return -ENODEV; 1652 return -ENODEV;
1539 1653
1540 dev = vmalloc(sizeof(struct ngene)); 1654 dev = vzalloc(sizeof(struct ngene));
1541 if (dev == NULL) { 1655 if (dev == NULL) {
1542 stat = -ENOMEM; 1656 stat = -ENOMEM;
1543 goto fail0; 1657 goto fail0;
1544 } 1658 }
1545 memset(dev, 0, sizeof(struct ngene));
1546 1659
1547 dev->pci_dev = pci_dev; 1660 dev->pci_dev = pci_dev;
1548 dev->card_info = (struct ngene_info *)id->driver_data; 1661 dev->card_info = (struct ngene_info *)id->driver_data;
@@ -1558,6 +1671,13 @@ int __devinit ngene_probe(struct pci_dev *pci_dev,
1558 if (stat < 0) 1671 if (stat < 0)
1559 goto fail1; 1672 goto fail1;
1560 1673
1674 cxd_attach(dev);
1675
1676 stat = ngene_buffer_config(dev);
1677 if (stat < 0)
1678 goto fail1;
1679
1680
1561 dev->i2c_current_bus = -1; 1681 dev->i2c_current_bus = -1;
1562 1682
1563 /* Register DVB adapters and devices for both channels */ 1683 /* Register DVB adapters and devices for both channels */
diff --git a/drivers/media/dvb/ngene/ngene-dvb.c b/drivers/media/dvb/ngene/ngene-dvb.c
index 48f980b21d66..0b4943233166 100644
--- a/drivers/media/dvb/ngene/ngene-dvb.c
+++ b/drivers/media/dvb/ngene/ngene-dvb.c
@@ -35,7 +35,6 @@
35#include <linux/io.h> 35#include <linux/io.h>
36#include <asm/div64.h> 36#include <asm/div64.h>
37#include <linux/pci.h> 37#include <linux/pci.h>
38#include <linux/smp_lock.h>
39#include <linux/timer.h> 38#include <linux/timer.h>
40#include <linux/byteorder/generic.h> 39#include <linux/byteorder/generic.h>
41#include <linux/firmware.h> 40#include <linux/firmware.h>
@@ -48,6 +47,64 @@
48/* COMMAND API interface ****************************************************/ 47/* COMMAND API interface ****************************************************/
49/****************************************************************************/ 48/****************************************************************************/
50 49
50static ssize_t ts_write(struct file *file, const char *buf,
51 size_t count, loff_t *ppos)
52{
53 struct dvb_device *dvbdev = file->private_data;
54 struct ngene_channel *chan = dvbdev->priv;
55 struct ngene *dev = chan->dev;
56
57 if (wait_event_interruptible(dev->tsout_rbuf.queue,
58 dvb_ringbuffer_free
59 (&dev->tsout_rbuf) >= count) < 0)
60 return 0;
61
62 dvb_ringbuffer_write(&dev->tsout_rbuf, buf, count);
63
64 return count;
65}
66
67static ssize_t ts_read(struct file *file, char *buf,
68 size_t count, loff_t *ppos)
69{
70 struct dvb_device *dvbdev = file->private_data;
71 struct ngene_channel *chan = dvbdev->priv;
72 struct ngene *dev = chan->dev;
73 int left, avail;
74
75 left = count;
76 while (left) {
77 if (wait_event_interruptible(
78 dev->tsin_rbuf.queue,
79 dvb_ringbuffer_avail(&dev->tsin_rbuf) > 0) < 0)
80 return -EAGAIN;
81 avail = dvb_ringbuffer_avail(&dev->tsin_rbuf);
82 if (avail > left)
83 avail = left;
84 dvb_ringbuffer_read_user(&dev->tsin_rbuf, buf, avail);
85 left -= avail;
86 buf += avail;
87 }
88 return count;
89}
90
91static const struct file_operations ci_fops = {
92 .owner = THIS_MODULE,
93 .read = ts_read,
94 .write = ts_write,
95 .open = dvb_generic_open,
96 .release = dvb_generic_release,
97};
98
99struct dvb_device ngene_dvbdev_ci = {
100 .priv = 0,
101 .readers = -1,
102 .writers = -1,
103 .users = -1,
104 .fops = &ci_fops,
105};
106
107
51/****************************************************************************/ 108/****************************************************************************/
52/* DVB functions and API interface ******************************************/ 109/* DVB functions and API interface ******************************************/
53/****************************************************************************/ 110/****************************************************************************/
@@ -64,10 +121,21 @@ static void swap_buffer(u32 *p, u32 len)
64void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags) 121void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags)
65{ 122{
66 struct ngene_channel *chan = priv; 123 struct ngene_channel *chan = priv;
124 struct ngene *dev = chan->dev;
67 125
68 126
69 if (chan->users > 0) 127 if (flags & DF_SWAP32)
128 swap_buffer(buf, len);
129 if (dev->ci.en && chan->number == 2) {
130 if (dvb_ringbuffer_free(&dev->tsin_rbuf) > len) {
131 dvb_ringbuffer_write(&dev->tsin_rbuf, buf, len);
132 wake_up_interruptible(&dev->tsin_rbuf.queue);
133 }
134 return 0;
135 }
136 if (chan->users > 0) {
70 dvb_dmx_swfilter(&chan->demux, buf, len); 137 dvb_dmx_swfilter(&chan->demux, buf, len);
138 }
71 return NULL; 139 return NULL;
72} 140}
73 141
diff --git a/drivers/media/dvb/ngene/ngene-i2c.c b/drivers/media/dvb/ngene/ngene-i2c.c
index 477fe0aade86..d28554f8ce99 100644
--- a/drivers/media/dvb/ngene/ngene-i2c.c
+++ b/drivers/media/dvb/ngene/ngene-i2c.c
@@ -37,7 +37,6 @@
37#include <asm/div64.h> 37#include <asm/div64.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/pci_ids.h> 39#include <linux/pci_ids.h>
40#include <linux/smp_lock.h>
41#include <linux/timer.h> 40#include <linux/timer.h>
42#include <linux/byteorder/generic.h> 41#include <linux/byteorder/generic.h>
43#include <linux/firmware.h> 42#include <linux/firmware.h>
@@ -165,7 +164,6 @@ int ngene_i2c_init(struct ngene *dev, int dev_nr)
165 struct i2c_adapter *adap = &(dev->channel[dev_nr].i2c_adapter); 164 struct i2c_adapter *adap = &(dev->channel[dev_nr].i2c_adapter);
166 165
167 i2c_set_adapdata(adap, &(dev->channel[dev_nr])); 166 i2c_set_adapdata(adap, &(dev->channel[dev_nr]));
168 adap->class = I2C_CLASS_TV_DIGITAL | I2C_CLASS_TV_ANALOG;
169 167
170 strcpy(adap->name, "nGene"); 168 strcpy(adap->name, "nGene");
171 169
diff --git a/drivers/media/dvb/ngene/ngene.h b/drivers/media/dvb/ngene/ngene.h
index 8fb4200f83f8..40fce9e3ae66 100644
--- a/drivers/media/dvb/ngene/ngene.h
+++ b/drivers/media/dvb/ngene/ngene.h
@@ -36,8 +36,11 @@
36#include "dmxdev.h" 36#include "dmxdev.h"
37#include "dvbdev.h" 37#include "dvbdev.h"
38#include "dvb_demux.h" 38#include "dvb_demux.h"
39#include "dvb_ca_en50221.h"
39#include "dvb_frontend.h" 40#include "dvb_frontend.h"
40#include "dvb_ringbuffer.h" 41#include "dvb_ringbuffer.h"
42#include "dvb_net.h"
43#include "cxd2099.h"
41 44
42#define DEVICE_NAME "ngene" 45#define DEVICE_NAME "ngene"
43 46
@@ -636,14 +639,18 @@ struct ngene_channel {
636 int number; 639 int number;
637 int type; 640 int type;
638 int mode; 641 int mode;
642 bool has_adapter;
643 bool has_demux;
639 644
640 struct dvb_frontend *fe; 645 struct dvb_frontend *fe;
641 struct dmxdev dmxdev; 646 struct dmxdev dmxdev;
642 struct dvb_demux demux; 647 struct dvb_demux demux;
648 struct dvb_net dvbnet;
643 struct dmx_frontend hw_frontend; 649 struct dmx_frontend hw_frontend;
644 struct dmx_frontend mem_frontend; 650 struct dmx_frontend mem_frontend;
645 int users; 651 int users;
646 struct video_device *v4l_dev; 652 struct video_device *v4l_dev;
653 struct dvb_device *ci_dev;
647 struct tasklet_struct demux_tasklet; 654 struct tasklet_struct demux_tasklet;
648 655
649 struct SBufferHeader *nextBuffer; 656 struct SBufferHeader *nextBuffer;
@@ -710,6 +717,15 @@ struct ngene_channel {
710 int running; 717 int running;
711}; 718};
712 719
720
721struct ngene_ci {
722 struct device device;
723 struct i2c_adapter i2c_adapter;
724
725 struct ngene *dev;
726 struct dvb_ca_en50221 *en;
727};
728
713struct ngene; 729struct ngene;
714 730
715typedef void (rx_cb_t)(struct ngene *, u32, u8); 731typedef void (rx_cb_t)(struct ngene *, u32, u8);
@@ -774,6 +790,10 @@ struct ngene {
774#define TSOUT_BUF_SIZE (512*188*8) 790#define TSOUT_BUF_SIZE (512*188*8)
775 struct dvb_ringbuffer tsout_rbuf; 791 struct dvb_ringbuffer tsout_rbuf;
776 792
793 u8 *tsin_buf;
794#define TSIN_BUF_SIZE (512*188*8)
795 struct dvb_ringbuffer tsin_rbuf;
796
777 u8 *ain_buf; 797 u8 *ain_buf;
778#define AIN_BUF_SIZE (128*1024) 798#define AIN_BUF_SIZE (128*1024)
779 struct dvb_ringbuffer ain_rbuf; 799 struct dvb_ringbuffer ain_rbuf;
@@ -785,6 +805,8 @@ struct ngene {
785 805
786 unsigned long exp_val; 806 unsigned long exp_val;
787 int prev_cmd; 807 int prev_cmd;
808
809 struct ngene_ci ci;
788}; 810};
789 811
790struct ngene_info { 812struct ngene_info {
@@ -863,6 +885,7 @@ struct ngene_buffer {
863int __devinit ngene_probe(struct pci_dev *pci_dev, 885int __devinit ngene_probe(struct pci_dev *pci_dev,
864 const struct pci_device_id *id); 886 const struct pci_device_id *id);
865void __devexit ngene_remove(struct pci_dev *pdev); 887void __devexit ngene_remove(struct pci_dev *pdev);
888void ngene_shutdown(struct pci_dev *pdev);
866int ngene_command(struct ngene *dev, struct ngene_command *com); 889int ngene_command(struct ngene *dev, struct ngene_command *com);
867int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level); 890int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level);
868void set_transfer(struct ngene_channel *chan, int state); 891void set_transfer(struct ngene_channel *chan, int state);
@@ -872,6 +895,7 @@ void FillTSBuffer(void *Buffer, int Length, u32 Flags);
872int ngene_i2c_init(struct ngene *dev, int dev_nr); 895int ngene_i2c_init(struct ngene *dev, int dev_nr);
873 896
874/* Provided by ngene-dvb.c */ 897/* Provided by ngene-dvb.c */
898extern struct dvb_device ngene_dvbdev_ci;
875void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags); 899void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
876void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags); 900void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
877int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed); 901int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed);
diff --git a/drivers/media/dvb/pluto2/pluto2.c b/drivers/media/dvb/pluto2/pluto2.c
index 1c798219dc7c..7cb79ec685f0 100644
--- a/drivers/media/dvb/pluto2/pluto2.c
+++ b/drivers/media/dvb/pluto2/pluto2.c
@@ -294,13 +294,13 @@ static void pluto_dma_end(struct pluto *pluto, unsigned int nbpackets)
294 294
295 /* Workaround for broken hardware: 295 /* Workaround for broken hardware:
296 * [1] On startup NBPACKETS seems to contain an uninitialized value, 296 * [1] On startup NBPACKETS seems to contain an uninitialized value,
297 * but no packets have been transfered. 297 * but no packets have been transferred.
298 * [2] Sometimes (actually very often) NBPACKETS stays at zero 298 * [2] Sometimes (actually very often) NBPACKETS stays at zero
299 * although one packet has been transfered. 299 * although one packet has been transferred.
300 * [3] Sometimes (actually rarely), the card gets into an erroneous 300 * [3] Sometimes (actually rarely), the card gets into an erroneous
301 * mode where it continuously generates interrupts, claiming it 301 * mode where it continuously generates interrupts, claiming it
302 * has recieved nbpackets>TS_DMA_PACKETS packets, but no packet 302 * has received nbpackets>TS_DMA_PACKETS packets, but no packet
303 * has been transfered. Only a reset seems to solve this 303 * has been transferred. Only a reset seems to solve this
304 */ 304 */
305 if ((nbpackets == 0) || (nbpackets > TS_DMA_PACKETS)) { 305 if ((nbpackets == 0) || (nbpackets > TS_DMA_PACKETS)) {
306 unsigned int i = 0; 306 unsigned int i = 0;
@@ -332,7 +332,7 @@ static irqreturn_t pluto_irq(int irq, void *dev_id)
332 struct pluto *pluto = dev_id; 332 struct pluto *pluto = dev_id;
333 u32 tscr; 333 u32 tscr;
334 334
335 /* check whether an interrupt occured on this device */ 335 /* check whether an interrupt occurred on this device */
336 tscr = pluto_readreg(pluto, REG_TSCR); 336 tscr = pluto_readreg(pluto, REG_TSCR);
337 if (!(tscr & (TSCR_DE | TSCR_OVR))) 337 if (!(tscr & (TSCR_DE | TSCR_OVR)))
338 return IRQ_NONE; 338 return IRQ_NONE;
@@ -647,7 +647,6 @@ static int __devinit pluto2_probe(struct pci_dev *pdev,
647 i2c_set_adapdata(&pluto->i2c_adap, pluto); 647 i2c_set_adapdata(&pluto->i2c_adap, pluto);
648 strcpy(pluto->i2c_adap.name, DRIVER_NAME); 648 strcpy(pluto->i2c_adap.name, DRIVER_NAME);
649 pluto->i2c_adap.owner = THIS_MODULE; 649 pluto->i2c_adap.owner = THIS_MODULE;
650 pluto->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
651 pluto->i2c_adap.dev.parent = &pdev->dev; 650 pluto->i2c_adap.dev.parent = &pdev->dev;
652 pluto->i2c_adap.algo_data = &pluto->i2c_bit; 651 pluto->i2c_adap.algo_data = &pluto->i2c_bit;
653 pluto->i2c_bit.data = pluto; 652 pluto->i2c_bit.data = pluto;
diff --git a/drivers/media/dvb/pt1/pt1.c b/drivers/media/dvb/pt1/pt1.c
index 69ad94934ec2..b81df5fafe26 100644
--- a/drivers/media/dvb/pt1/pt1.c
+++ b/drivers/media/dvb/pt1/pt1.c
@@ -1087,10 +1087,10 @@ pt1_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1087 pt1_update_power(pt1); 1087 pt1_update_power(pt1);
1088 1088
1089 i2c_adap = &pt1->i2c_adap; 1089 i2c_adap = &pt1->i2c_adap;
1090 i2c_adap->class = I2C_CLASS_TV_DIGITAL;
1091 i2c_adap->algo = &pt1_i2c_algo; 1090 i2c_adap->algo = &pt1_i2c_algo;
1092 i2c_adap->algo_data = NULL; 1091 i2c_adap->algo_data = NULL;
1093 i2c_adap->dev.parent = &pdev->dev; 1092 i2c_adap->dev.parent = &pdev->dev;
1093 strcpy(i2c_adap->name, DRIVER_NAME);
1094 i2c_set_adapdata(i2c_adap, pt1); 1094 i2c_set_adapdata(i2c_adap, pt1);
1095 ret = i2c_add_adapter(i2c_adap); 1095 ret = i2c_add_adapter(i2c_adap);
1096 if (ret < 0) 1096 if (ret < 0)
@@ -1157,10 +1157,10 @@ err_pt1_disable_ram:
1157 pt1->power = 0; 1157 pt1->power = 0;
1158 pt1->reset = 1; 1158 pt1->reset = 1;
1159 pt1_update_power(pt1); 1159 pt1_update_power(pt1);
1160err_pt1_cleanup_adapters:
1161 pt1_cleanup_adapters(pt1);
1162err_i2c_del_adapter: 1160err_i2c_del_adapter:
1163 i2c_del_adapter(i2c_adap); 1161 i2c_del_adapter(i2c_adap);
1162err_pt1_cleanup_adapters:
1163 pt1_cleanup_adapters(pt1);
1164err_kfree: 1164err_kfree:
1165 pci_set_drvdata(pdev, NULL); 1165 pci_set_drvdata(pdev, NULL);
1166 kfree(pt1); 1166 kfree(pt1);
diff --git a/drivers/media/dvb/siano/Kconfig b/drivers/media/dvb/siano/Kconfig
index e520bceee0af..bc6456eb2c4f 100644
--- a/drivers/media/dvb/siano/Kconfig
+++ b/drivers/media/dvb/siano/Kconfig
@@ -4,7 +4,7 @@
4 4
5config SMS_SIANO_MDTV 5config SMS_SIANO_MDTV
6 tristate "Siano SMS1xxx based MDTV receiver" 6 tristate "Siano SMS1xxx based MDTV receiver"
7 depends on DVB_CORE && IR_CORE && HAS_DMA 7 depends on DVB_CORE && RC_CORE && HAS_DMA
8 ---help--- 8 ---help---
9 Choose Y or M here if you have MDTV receiver with a Siano chipset. 9 Choose Y or M here if you have MDTV receiver with a Siano chipset.
10 10
diff --git a/drivers/media/dvb/siano/sms-cards.c b/drivers/media/dvb/siano/sms-cards.c
index 25b43e587fa6..af121db88ea0 100644
--- a/drivers/media/dvb/siano/sms-cards.c
+++ b/drivers/media/dvb/siano/sms-cards.c
@@ -64,7 +64,7 @@ static struct sms_board sms_boards[] = {
64 .type = SMS_NOVA_B0, 64 .type = SMS_NOVA_B0,
65 .fw[DEVICE_MODE_ISDBT_BDA] = "sms1xxx-hcw-55xxx-isdbt-02.fw", 65 .fw[DEVICE_MODE_ISDBT_BDA] = "sms1xxx-hcw-55xxx-isdbt-02.fw",
66 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw", 66 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
67 .rc_codes = RC_MAP_RC5_HAUPPAUGE_NEW, 67 .rc_codes = RC_MAP_HAUPPAUGE,
68 .board_cfg.leds_power = 26, 68 .board_cfg.leds_power = 26,
69 .board_cfg.led0 = 27, 69 .board_cfg.led0 = 27,
70 .board_cfg.led1 = 28, 70 .board_cfg.led1 = 28,
diff --git a/drivers/media/dvb/siano/smscoreapi.c b/drivers/media/dvb/siano/smscoreapi.c
index ff3b0fa901b3..78765ed28063 100644
--- a/drivers/media/dvb/siano/smscoreapi.c
+++ b/drivers/media/dvb/siano/smscoreapi.c
@@ -438,7 +438,7 @@ static int smscore_init_ir(struct smscore_device_t *coredev)
438 int rc; 438 int rc;
439 void *buffer; 439 void *buffer;
440 440
441 coredev->ir.input_dev = NULL; 441 coredev->ir.dev = NULL;
442 ir_io = sms_get_board(smscore_get_board_id(coredev))->board_cfg.ir; 442 ir_io = sms_get_board(smscore_get_board_id(coredev))->board_cfg.ir;
443 if (ir_io) {/* only if IR port exist we use IR sub-module */ 443 if (ir_io) {/* only if IR port exist we use IR sub-module */
444 sms_info("IR loading"); 444 sms_info("IR loading");
@@ -1504,8 +1504,7 @@ int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum,
1504 u32 msgData[3]; /* keep it 3 ! */ 1504 u32 msgData[3]; /* keep it 3 ! */
1505 } *pMsg; 1505 } *pMsg;
1506 1506
1507 if ((NewLevel > 1) || (PinNum > MAX_GPIO_PIN_NUMBER) || 1507 if ((NewLevel > 1) || (PinNum > MAX_GPIO_PIN_NUMBER))
1508 (PinNum > MAX_GPIO_PIN_NUMBER))
1509 return -EINVAL; 1508 return -EINVAL;
1510 1509
1511 totalLen = sizeof(struct SmsMsgHdr_ST) + 1510 totalLen = sizeof(struct SmsMsgHdr_ST) +
diff --git a/drivers/media/dvb/siano/smsdvb.c b/drivers/media/dvb/siano/smsdvb.c
index b80d09b035a1..37c594f82782 100644
--- a/drivers/media/dvb/siano/smsdvb.c
+++ b/drivers/media/dvb/siano/smsdvb.c
@@ -650,7 +650,7 @@ static int smsdvb_dvbt_set_frontend(struct dvb_frontend *fe,
650 if (status & FE_HAS_LOCK) 650 if (status & FE_HAS_LOCK)
651 return ret; 651 return ret;
652 652
653 /* previous tune didnt lock - enable LNA and tune again */ 653 /* previous tune didn't lock - enable LNA and tune again */
654 sms_board_lna_control(client->coredev, 1); 654 sms_board_lna_control(client->coredev, 1);
655 } 655 }
656 656
diff --git a/drivers/media/dvb/siano/smsir.c b/drivers/media/dvb/siano/smsir.c
index d0e4639ee9db..37bc5c4b8ad8 100644
--- a/drivers/media/dvb/siano/smsir.c
+++ b/drivers/media/dvb/siano/smsir.c
@@ -40,30 +40,29 @@ void sms_ir_event(struct smscore_device_t *coredev, const char *buf, int len)
40 const s32 *samples = (const void *)buf; 40 const s32 *samples = (const void *)buf;
41 41
42 for (i = 0; i < len >> 2; i++) { 42 for (i = 0; i < len >> 2; i++) {
43 struct ir_raw_event ev; 43 DEFINE_IR_RAW_EVENT(ev);
44 44
45 ev.duration = abs(samples[i]) * 1000; /* Convert to ns */ 45 ev.duration = abs(samples[i]) * 1000; /* Convert to ns */
46 ev.pulse = (samples[i] > 0) ? false : true; 46 ev.pulse = (samples[i] > 0) ? false : true;
47 47
48 ir_raw_event_store(coredev->ir.input_dev, &ev); 48 ir_raw_event_store(coredev->ir.dev, &ev);
49 } 49 }
50 ir_raw_event_handle(coredev->ir.input_dev); 50 ir_raw_event_handle(coredev->ir.dev);
51} 51}
52 52
53int sms_ir_init(struct smscore_device_t *coredev) 53int sms_ir_init(struct smscore_device_t *coredev)
54{ 54{
55 struct input_dev *input_dev; 55 int err;
56 int board_id = smscore_get_board_id(coredev); 56 int board_id = smscore_get_board_id(coredev);
57 struct rc_dev *dev;
57 58
58 sms_log("Allocating input device"); 59 sms_log("Allocating rc device");
59 input_dev = input_allocate_device(); 60 dev = rc_allocate_device();
60 if (!input_dev) { 61 if (!dev) {
61 sms_err("Not enough memory"); 62 sms_err("Not enough memory");
62 return -ENOMEM; 63 return -ENOMEM;
63 } 64 }
64 65
65 coredev->ir.input_dev = input_dev;
66
67 coredev->ir.controller = 0; /* Todo: vega/nova SPI number */ 66 coredev->ir.controller = 0; /* Todo: vega/nova SPI number */
68 coredev->ir.timeout = IR_DEFAULT_TIMEOUT; 67 coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
69 sms_log("IR port %d, timeout %d ms", 68 sms_log("IR port %d, timeout %d ms",
@@ -75,38 +74,41 @@ int sms_ir_init(struct smscore_device_t *coredev)
75 strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys)); 74 strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
76 strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys)); 75 strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
77 76
78 input_dev->name = coredev->ir.name; 77 dev->input_name = coredev->ir.name;
79 input_dev->phys = coredev->ir.phys; 78 dev->input_phys = coredev->ir.phys;
80 input_dev->dev.parent = coredev->device; 79 dev->dev.parent = coredev->device;
81 80
82#if 0 81#if 0
83 /* TODO: properly initialize the parameters bellow */ 82 /* TODO: properly initialize the parameters bellow */
84 input_dev->id.bustype = BUS_USB; 83 dev->input_id.bustype = BUS_USB;
85 input_dev->id.version = 1; 84 dev->input_id.version = 1;
86 input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); 85 dev->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
87 input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); 86 dev->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
88#endif 87#endif
89 88
90 coredev->ir.props.priv = coredev; 89 dev->priv = coredev;
91 coredev->ir.props.driver_type = RC_DRIVER_IR_RAW; 90 dev->driver_type = RC_DRIVER_IR_RAW;
92 coredev->ir.props.allowed_protos = IR_TYPE_ALL; 91 dev->allowed_protos = RC_TYPE_ALL;
92 dev->map_name = sms_get_board(board_id)->rc_codes;
93 dev->driver_name = MODULE_NAME;
93 94
94 sms_log("Input device (IR) %s is set for key events", input_dev->name); 95 sms_log("Input device (IR) %s is set for key events", dev->input_name);
95 96
96 if (ir_input_register(input_dev, sms_get_board(board_id)->rc_codes, 97 err = rc_register_device(dev);
97 &coredev->ir.props, MODULE_NAME)) { 98 if (err < 0) {
98 sms_err("Failed to register device"); 99 sms_err("Failed to register device");
99 input_free_device(input_dev); 100 rc_free_device(dev);
100 return -EACCES; 101 return err;
101 } 102 }
102 103
104 coredev->ir.dev = dev;
103 return 0; 105 return 0;
104} 106}
105 107
106void sms_ir_exit(struct smscore_device_t *coredev) 108void sms_ir_exit(struct smscore_device_t *coredev)
107{ 109{
108 if (coredev->ir.input_dev) 110 if (coredev->ir.dev)
109 ir_input_unregister(coredev->ir.input_dev); 111 rc_unregister_device(coredev->ir.dev);
110 112
111 sms_log(""); 113 sms_log("");
112} 114}
diff --git a/drivers/media/dvb/siano/smsir.h b/drivers/media/dvb/siano/smsir.h
index 926e247523bd..ae92b3a8587e 100644
--- a/drivers/media/dvb/siano/smsir.h
+++ b/drivers/media/dvb/siano/smsir.h
@@ -28,20 +28,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
28#define __SMS_IR_H__ 28#define __SMS_IR_H__
29 29
30#include <linux/input.h> 30#include <linux/input.h>
31#include <media/ir-core.h> 31#include <media/rc-core.h>
32 32
33#define IR_DEFAULT_TIMEOUT 100 33#define IR_DEFAULT_TIMEOUT 100
34 34
35struct smscore_device_t; 35struct smscore_device_t;
36 36
37struct ir_t { 37struct ir_t {
38 struct input_dev *input_dev; 38 struct rc_dev *dev;
39 char name[40]; 39 char name[40];
40 char phys[32]; 40 char phys[32];
41 41
42 char *rc_codes; 42 char *rc_codes;
43 u64 protocol; 43 u64 protocol;
44 struct ir_dev_props props;
45 44
46 u32 timeout; 45 u32 timeout;
47 u32 controller; 46 u32 controller;
diff --git a/drivers/media/dvb/siano/smsusb.c b/drivers/media/dvb/siano/smsusb.c
index 50d4338610e0..0c8164a2cc36 100644
--- a/drivers/media/dvb/siano/smsusb.c
+++ b/drivers/media/dvb/siano/smsusb.c
@@ -288,8 +288,7 @@ static int smsusb1_setmode(void *context, int mode)
288 288
289static void smsusb_term_device(struct usb_interface *intf) 289static void smsusb_term_device(struct usb_interface *intf)
290{ 290{
291 struct smsusb_device_t *dev = 291 struct smsusb_device_t *dev = usb_get_intfdata(intf);
292 (struct smsusb_device_t *) usb_get_intfdata(intf);
293 292
294 if (dev) { 293 if (dev) {
295 smsusb_stop_streaming(dev); 294 smsusb_stop_streaming(dev);
@@ -298,9 +297,8 @@ static void smsusb_term_device(struct usb_interface *intf)
298 if (dev->coredev) 297 if (dev->coredev)
299 smscore_unregister_device(dev->coredev); 298 smscore_unregister_device(dev->coredev);
300 299
301 kfree(dev);
302
303 sms_info("device %p destroyed", dev); 300 sms_info("device %p destroyed", dev);
301 kfree(dev);
304 } 302 }
305 303
306 usb_set_intfdata(intf, NULL); 304 usb_set_intfdata(intf, NULL);
@@ -445,8 +443,7 @@ static void smsusb_disconnect(struct usb_interface *intf)
445 443
446static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg) 444static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg)
447{ 445{
448 struct smsusb_device_t *dev = 446 struct smsusb_device_t *dev = usb_get_intfdata(intf);
449 (struct smsusb_device_t *)usb_get_intfdata(intf);
450 printk(KERN_INFO "%s: Entering status %d.\n", __func__, msg.event); 447 printk(KERN_INFO "%s: Entering status %d.\n", __func__, msg.event);
451 smsusb_stop_streaming(dev); 448 smsusb_stop_streaming(dev);
452 return 0; 449 return 0;
@@ -455,8 +452,7 @@ static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg)
455static int smsusb_resume(struct usb_interface *intf) 452static int smsusb_resume(struct usb_interface *intf)
456{ 453{
457 int rc, i; 454 int rc, i;
458 struct smsusb_device_t *dev = 455 struct smsusb_device_t *dev = usb_get_intfdata(intf);
459 (struct smsusb_device_t *)usb_get_intfdata(intf);
460 struct usb_device *udev = interface_to_usbdev(intf); 456 struct usb_device *udev = interface_to_usbdev(intf);
461 457
462 printk(KERN_INFO "%s: Entering.\n", __func__); 458 printk(KERN_INFO "%s: Entering.\n", __func__);
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index debea8d1d31c..9d83ced69dd6 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -89,16 +89,17 @@ config DVB_BUDGET
89config DVB_BUDGET_CI 89config DVB_BUDGET_CI
90 tristate "Budget cards with onboard CI connector" 90 tristate "Budget cards with onboard CI connector"
91 depends on DVB_BUDGET_CORE && I2C 91 depends on DVB_BUDGET_CORE && I2C
92 depends on INPUT # due to IR
93 select DVB_STV0297 if !DVB_FE_CUSTOMISE 92 select DVB_STV0297 if !DVB_FE_CUSTOMISE
94 select DVB_STV0299 if !DVB_FE_CUSTOMISE 93 select DVB_STV0299 if !DVB_FE_CUSTOMISE
95 select DVB_TDA1004X if !DVB_FE_CUSTOMISE 94 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
96 select DVB_STB0899 if !DVB_FE_CUSTOMISE 95 select DVB_STB0899 if !DVB_FE_CUSTOMISE
97 select DVB_STB6100 if !DVB_FE_CUSTOMISE 96 select DVB_STB6100 if !DVB_FE_CUSTOMISE
98 select DVB_LNBP21 if !DVB_FE_CUSTOMISE 97 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
98 select DVB_STV0288 if !DVB_FE_CUSTOMISE
99 select DVB_STB6000 if !DVB_FE_CUSTOMISE
99 select DVB_TDA10023 if !DVB_FE_CUSTOMISE 100 select DVB_TDA10023 if !DVB_FE_CUSTOMISE
100 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE 101 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE
101 depends on VIDEO_IR 102 depends on RC_CORE
102 help 103 help
103 Support for simple SAA7146 based DVB cards 104 Support for simple SAA7146 based DVB cards
104 (so called Budget- or Nova-PCI cards) without onboard 105 (so called Budget- or Nova-PCI cards) without onboard
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index a6be529eec5c..3d20719fce1a 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -26,7 +26,7 @@
26 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 26 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
27 * 27 *
28 * 28 *
29 * the project's page is at http://www.linuxtv.org/dvb/ 29 * the project's page is at http://www.linuxtv.org/
30 */ 30 */
31 31
32 32
@@ -730,6 +730,7 @@ static const struct file_operations dvb_osd_fops = {
730 .unlocked_ioctl = dvb_generic_ioctl, 730 .unlocked_ioctl = dvb_generic_ioctl,
731 .open = dvb_generic_open, 731 .open = dvb_generic_open,
732 .release = dvb_generic_release, 732 .release = dvb_generic_release,
733 .llseek = noop_llseek,
733}; 734};
734 735
735static struct dvb_device dvbdev_osd = { 736static struct dvb_device dvbdev_osd = {
@@ -2290,12 +2291,7 @@ static int frontend_init(struct av7110 *av7110)
2290/* Budgetpatch note: 2291/* Budgetpatch note:
2291 * Original hardware design by Roberto Deza: 2292 * Original hardware design by Roberto Deza:
2292 * There is a DVB_Wiki at 2293 * There is a DVB_Wiki at
2293 * http://212.227.36.83/linuxtv/wiki/index.php/Main_Page 2294 * http://www.linuxtv.org/
2294 * where is described this 'DVB TT Budget Patch', on Card Modding:
2295 * http://212.227.36.83/linuxtv/wiki/index.php/DVB_TT_Budget_Patch
2296 * On the short description there is also a link to a external file,
2297 * with more details:
2298 * http://perso.wanadoo.es/jesussolano/Ttf_tsc1.zip
2299 * 2295 *
2300 * New software triggering design by Emard that works on 2296 * New software triggering design by Emard that works on
2301 * original Roberto Deza's hardware: 2297 * original Roberto Deza's hardware:
@@ -2336,7 +2332,7 @@ static int frontend_init(struct av7110 *av7110)
2336 * increment. That's how the 7146 is programmed to do event 2332 * increment. That's how the 7146 is programmed to do event
2337 * counting in this budget-patch.c 2333 * counting in this budget-patch.c
2338 * I *think* HPS setting has something to do with the phase 2334 * I *think* HPS setting has something to do with the phase
2339 * of HS but I cant be 100% sure in that. 2335 * of HS but I can't be 100% sure in that.
2340 * 2336 *
2341 * hardware debug note: a working budget card (including budget patch) 2337 * hardware debug note: a working budget card (including budget patch)
2342 * with vpeirq() interrupt setup in mode "0x90" (every 64K) will 2338 * with vpeirq() interrupt setup in mode "0x90" (every 64K) will
@@ -2476,7 +2472,6 @@ static int __devinit av7110_attach(struct saa7146_dev* dev,
2476 get recognized before the main driver is fully loaded */ 2472 get recognized before the main driver is fully loaded */
2477 saa7146_write(dev, GPIO_CTRL, 0x500000); 2473 saa7146_write(dev, GPIO_CTRL, 0x500000);
2478 2474
2479 av7110->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
2480 strlcpy(av7110->i2c_adap.name, pci_ext->ext_priv, sizeof(av7110->i2c_adap.name)); 2475 strlcpy(av7110->i2c_adap.name, pci_ext->ext_priv, sizeof(av7110->i2c_adap.name));
2481 2476
2482 saa7146_i2c_adapter_prepare(dev, &av7110->i2c_adap, SAA7146_I2C_BUS_BIT_RATE_120); /* 275 kHz */ 2477 saa7146_i2c_adapter_prepare(dev, &av7110->i2c_adap, SAA7146_I2C_BUS_BIT_RATE_120); /* 275 kHz */
@@ -2890,7 +2885,7 @@ MODULE_DEVICE_TABLE(pci, pci_tbl);
2890 2885
2891 2886
2892static struct saa7146_extension av7110_extension_driver = { 2887static struct saa7146_extension av7110_extension_driver = {
2893 .name = "dvb", 2888 .name = "av7110",
2894 .flags = SAA7146_USE_I2C_IRQ, 2889 .flags = SAA7146_USE_I2C_IRQ,
2895 2890
2896 .module = THIS_MODULE, 2891 .module = THIS_MODULE,
diff --git a/drivers/media/dvb/ttpci/av7110_av.c b/drivers/media/dvb/ttpci/av7110_av.c
index 13efba942dac..952b33dbac4f 100644
--- a/drivers/media/dvb/ttpci/av7110_av.c
+++ b/drivers/media/dvb/ttpci/av7110_av.c
@@ -25,7 +25,7 @@
25 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 25 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
26 * 26 *
27 * 27 *
28 * the project's page is at http://www.linuxtv.org/dvb/ 28 * the project's page is at http://www.linuxtv.org/
29 */ 29 */
30 30
31#include <linux/types.h> 31#include <linux/types.h>
@@ -245,8 +245,11 @@ int av7110_pes_play(void *dest, struct dvb_ringbuffer *buf, int dlen)
245 return -1; 245 return -1;
246 } 246 }
247 while (1) { 247 while (1) {
248 if ((len = dvb_ringbuffer_avail(buf)) < 6) 248 len = dvb_ringbuffer_avail(buf);
249 if (len < 6) {
250 wake_up(&buf->queue);
249 return -1; 251 return -1;
252 }
250 sync = DVB_RINGBUFFER_PEEK(buf, 0) << 24; 253 sync = DVB_RINGBUFFER_PEEK(buf, 0) << 24;
251 sync |= DVB_RINGBUFFER_PEEK(buf, 1) << 16; 254 sync |= DVB_RINGBUFFER_PEEK(buf, 1) << 16;
252 sync |= DVB_RINGBUFFER_PEEK(buf, 2) << 8; 255 sync |= DVB_RINGBUFFER_PEEK(buf, 2) << 8;
@@ -1521,6 +1524,7 @@ static const struct file_operations dvb_video_fops = {
1521 .open = dvb_video_open, 1524 .open = dvb_video_open,
1522 .release = dvb_video_release, 1525 .release = dvb_video_release,
1523 .poll = dvb_video_poll, 1526 .poll = dvb_video_poll,
1527 .llseek = noop_llseek,
1524}; 1528};
1525 1529
1526static struct dvb_device dvbdev_video = { 1530static struct dvb_device dvbdev_video = {
@@ -1539,6 +1543,7 @@ static const struct file_operations dvb_audio_fops = {
1539 .open = dvb_audio_open, 1543 .open = dvb_audio_open,
1540 .release = dvb_audio_release, 1544 .release = dvb_audio_release,
1541 .poll = dvb_audio_poll, 1545 .poll = dvb_audio_poll,
1546 .llseek = noop_llseek,
1542}; 1547};
1543 1548
1544static struct dvb_device dvbdev_audio = { 1549static struct dvb_device dvbdev_audio = {
diff --git a/drivers/media/dvb/ttpci/av7110_ca.c b/drivers/media/dvb/ttpci/av7110_ca.c
index 4eba35a018e3..9fc1dd0ba4c3 100644
--- a/drivers/media/dvb/ttpci/av7110_ca.c
+++ b/drivers/media/dvb/ttpci/av7110_ca.c
@@ -25,7 +25,7 @@
25 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 25 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
26 * 26 *
27 * 27 *
28 * the project's page is at http://www.linuxtv.org/dvb/ 28 * the project's page is at http://www.linuxtv.org/
29 */ 29 */
30 30
31#include <linux/kernel.h> 31#include <linux/kernel.h>
@@ -277,7 +277,7 @@ static int dvb_ca_ioctl(struct file *file, unsigned int cmd, void *parg)
277 { 277 {
278 ca_slot_info_t *info=(ca_slot_info_t *)parg; 278 ca_slot_info_t *info=(ca_slot_info_t *)parg;
279 279
280 if (info->num > 1) 280 if (info->num < 0 || info->num > 1)
281 return -EINVAL; 281 return -EINVAL;
282 av7110->ci_slot[info->num].num = info->num; 282 av7110->ci_slot[info->num].num = info->num;
283 av7110->ci_slot[info->num].type = FW_CI_LL_SUPPORT(av7110->arm_app) ? 283 av7110->ci_slot[info->num].type = FW_CI_LL_SUPPORT(av7110->arm_app) ?
@@ -353,6 +353,7 @@ static const struct file_operations dvb_ca_fops = {
353 .open = dvb_ca_open, 353 .open = dvb_ca_open,
354 .release = dvb_generic_release, 354 .release = dvb_generic_release,
355 .poll = dvb_ca_poll, 355 .poll = dvb_ca_poll,
356 .llseek = default_llseek,
356}; 357};
357 358
358static struct dvb_device dvbdev_ca = { 359static struct dvb_device dvbdev_ca = {
diff --git a/drivers/media/dvb/ttpci/av7110_hw.c b/drivers/media/dvb/ttpci/av7110_hw.c
index e162691b515d..f1cbfe526989 100644
--- a/drivers/media/dvb/ttpci/av7110_hw.c
+++ b/drivers/media/dvb/ttpci/av7110_hw.c
@@ -22,7 +22,7 @@
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 23 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
24 * 24 *
25 * the project's page is at http://www.linuxtv.org/dvb/ 25 * the project's page is at http://www.linuxtv.org/
26 */ 26 */
27 27
28/* for debugging ARM communication: */ 28/* for debugging ARM communication: */
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index b070e88d8c6b..908f272fe26c 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -312,6 +312,7 @@ static ssize_t av7110_ir_proc_write(struct file *file, const char __user *buffer
312static const struct file_operations av7110_ir_proc_fops = { 312static const struct file_operations av7110_ir_proc_fops = {
313 .owner = THIS_MODULE, 313 .owner = THIS_MODULE,
314 .write = av7110_ir_proc_write, 314 .write = av7110_ir_proc_write,
315 .llseek = noop_llseek,
315}; 316};
316 317
317/* interrupt handler */ 318/* interrupt handler */
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index 8986d967d2f4..cdd31cae46c4 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -22,7 +22,7 @@
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 23 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
24 * 24 *
25 * the project's page is at http://www.linuxtv.org/dvb/ 25 * the project's page is at http://www.linuxtv.org/
26 */ 26 */
27 27
28#include <linux/kernel.h> 28#include <linux/kernel.h>
@@ -100,6 +100,7 @@ static struct v4l2_input inputs[4] = {
100 .tuner = 0, /* ignored */ 100 .tuner = 0, /* ignored */
101 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 101 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
102 .status = 0, 102 .status = 0,
103 .capabilities = V4L2_IN_CAP_STD,
103 }, { 104 }, {
104 .index = 1, 105 .index = 1,
105 .name = "Television", 106 .name = "Television",
@@ -108,6 +109,7 @@ static struct v4l2_input inputs[4] = {
108 .tuner = 0, 109 .tuner = 0,
109 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 110 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
110 .status = 0, 111 .status = 0,
112 .capabilities = V4L2_IN_CAP_STD,
111 }, { 113 }, {
112 .index = 2, 114 .index = 2,
113 .name = "Video", 115 .name = "Video",
@@ -116,6 +118,7 @@ static struct v4l2_input inputs[4] = {
116 .tuner = 0, 118 .tuner = 0,
117 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 119 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
118 .status = 0, 120 .status = 0,
121 .capabilities = V4L2_IN_CAP_STD,
119 }, { 122 }, {
120 .index = 3, 123 .index = 3,
121 .name = "Y/C", 124 .name = "Y/C",
@@ -124,6 +127,7 @@ static struct v4l2_input inputs[4] = {
124 .tuner = 0, 127 .tuner = 0,
125 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 128 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
126 .status = 0, 129 .status = 0,
130 .capabilities = V4L2_IN_CAP_STD,
127 } 131 }
128}; 132};
129 133
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 983672aa2450..e957d7690bcc 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -30,7 +30,7 @@
30 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 30 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
31 * 31 *
32 * 32 *
33 * the project's page is at http://www.linuxtv.org/dvb/ 33 * the project's page is at http://www.linuxtv.org/
34 */ 34 */
35 35
36#include "budget.h" 36#include "budget.h"
@@ -1406,8 +1406,10 @@ static int budget_av_detach(struct saa7146_dev *dev)
1406 1406
1407#define KNC1_INPUTS 2 1407#define KNC1_INPUTS 2
1408static struct v4l2_input knc1_inputs[KNC1_INPUTS] = { 1408static struct v4l2_input knc1_inputs[KNC1_INPUTS] = {
1409 {0, "Composite", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0}, 1409 { 0, "Composite", V4L2_INPUT_TYPE_TUNER, 1, 0,
1410 {1, "S-Video", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0}, 1410 V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
1411 { 1, "S-Video", V4L2_INPUT_TYPE_CAMERA, 2, 0,
1412 V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
1411}; 1413};
1412 1414
1413static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i) 1415static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index 13ac9e3ab121..926f299b5225 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -26,16 +26,15 @@
26 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 26 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
27 * 27 *
28 * 28 *
29 * the project's page is at http://www.linuxtv.org/dvb/ 29 * the project's page is at http://www.linuxtv.org/
30 */ 30 */
31 31
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <linux/input.h>
37#include <linux/spinlock.h> 36#include <linux/spinlock.h>
38#include <media/ir-core.h> 37#include <media/rc-core.h>
39 38
40#include "budget.h" 39#include "budget.h"
41 40
@@ -53,6 +52,7 @@
53#include "bsru6.h" 52#include "bsru6.h"
54#include "tda1002x.h" 53#include "tda1002x.h"
55#include "tda827x.h" 54#include "tda827x.h"
55#include "bsbe1-d01a.h"
56 56
57#define MODULE_NAME "budget_ci" 57#define MODULE_NAME "budget_ci"
58 58
@@ -96,13 +96,14 @@ MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
96DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 96DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
97 97
98struct budget_ci_ir { 98struct budget_ci_ir {
99 struct input_dev *dev; 99 struct rc_dev *dev;
100 struct tasklet_struct msp430_irq_tasklet; 100 struct tasklet_struct msp430_irq_tasklet;
101 char name[72]; /* 40 + 32 for (struct saa7146_dev).name */ 101 char name[72]; /* 40 + 32 for (struct saa7146_dev).name */
102 char phys[32]; 102 char phys[32];
103 int rc5_device; 103 int rc5_device;
104 u32 ir_key; 104 u32 ir_key;
105 bool have_command; 105 bool have_command;
106 bool full_rc5; /* Outputs a full RC5 code */
106}; 107};
107 108
108struct budget_ci { 109struct budget_ci {
@@ -118,7 +119,7 @@ struct budget_ci {
118static void msp430_ir_interrupt(unsigned long data) 119static void msp430_ir_interrupt(unsigned long data)
119{ 120{
120 struct budget_ci *budget_ci = (struct budget_ci *) data; 121 struct budget_ci *budget_ci = (struct budget_ci *) data;
121 struct input_dev *dev = budget_ci->ir.dev; 122 struct rc_dev *dev = budget_ci->ir.dev;
122 u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8; 123 u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
123 124
124 /* 125 /*
@@ -155,24 +156,29 @@ static void msp430_ir_interrupt(unsigned long data)
155 return; 156 return;
156 budget_ci->ir.have_command = false; 157 budget_ci->ir.have_command = false;
157 158
158 /* FIXME: We should generate complete scancodes with device info */
159 if (budget_ci->ir.rc5_device != IR_DEVICE_ANY && 159 if (budget_ci->ir.rc5_device != IR_DEVICE_ANY &&
160 budget_ci->ir.rc5_device != (command & 0x1f)) 160 budget_ci->ir.rc5_device != (command & 0x1f))
161 return; 161 return;
162 162
163 ir_keydown(dev, budget_ci->ir.ir_key, (command & 0x20) ? 1 : 0); 163 if (budget_ci->ir.full_rc5) {
164 rc_keydown(dev,
165 budget_ci->ir.rc5_device <<8 | budget_ci->ir.ir_key,
166 (command & 0x20) ? 1 : 0);
167 return;
168 }
169
170 /* FIXME: We should generate complete scancodes for all devices */
171 rc_keydown(dev, budget_ci->ir.ir_key, (command & 0x20) ? 1 : 0);
164} 172}
165 173
166static int msp430_ir_init(struct budget_ci *budget_ci) 174static int msp430_ir_init(struct budget_ci *budget_ci)
167{ 175{
168 struct saa7146_dev *saa = budget_ci->budget.dev; 176 struct saa7146_dev *saa = budget_ci->budget.dev;
169 struct input_dev *input_dev = budget_ci->ir.dev; 177 struct rc_dev *dev;
170 int error; 178 int error;
171 char *ir_codes = NULL;
172 179
173 180 dev = rc_allocate_device();
174 budget_ci->ir.dev = input_dev = input_allocate_device(); 181 if (!dev) {
175 if (!input_dev) {
176 printk(KERN_ERR "budget_ci: IR interface initialisation failed\n"); 182 printk(KERN_ERR "budget_ci: IR interface initialisation failed\n");
177 return -ENOMEM; 183 return -ENOMEM;
178 } 184 }
@@ -182,19 +188,20 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
182 snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys), 188 snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys),
183 "pci-%s/ir0", pci_name(saa->pci)); 189 "pci-%s/ir0", pci_name(saa->pci));
184 190
185 input_dev->name = budget_ci->ir.name; 191 dev->driver_name = MODULE_NAME;
186 192 dev->input_name = budget_ci->ir.name;
187 input_dev->phys = budget_ci->ir.phys; 193 dev->input_phys = budget_ci->ir.phys;
188 input_dev->id.bustype = BUS_PCI; 194 dev->input_id.bustype = BUS_PCI;
189 input_dev->id.version = 1; 195 dev->input_id.version = 1;
196 dev->scanmask = 0xff;
190 if (saa->pci->subsystem_vendor) { 197 if (saa->pci->subsystem_vendor) {
191 input_dev->id.vendor = saa->pci->subsystem_vendor; 198 dev->input_id.vendor = saa->pci->subsystem_vendor;
192 input_dev->id.product = saa->pci->subsystem_device; 199 dev->input_id.product = saa->pci->subsystem_device;
193 } else { 200 } else {
194 input_dev->id.vendor = saa->pci->vendor; 201 dev->input_id.vendor = saa->pci->vendor;
195 input_dev->id.product = saa->pci->device; 202 dev->input_id.product = saa->pci->device;
196 } 203 }
197 input_dev->dev.parent = &saa->pci->dev; 204 dev->dev.parent = &saa->pci->dev;
198 205
199 if (rc5_device < 0) 206 if (rc5_device < 0)
200 budget_ci->ir.rc5_device = IR_DEVICE_ANY; 207 budget_ci->ir.rc5_device = IR_DEVICE_ANY;
@@ -208,7 +215,8 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
208 case 0x1011: 215 case 0x1011:
209 case 0x1012: 216 case 0x1012:
210 /* The hauppauge keymap is a superset of these remotes */ 217 /* The hauppauge keymap is a superset of these remotes */
211 ir_codes = RC_MAP_HAUPPAUGE_NEW; 218 dev->map_name = RC_MAP_HAUPPAUGE;
219 budget_ci->ir.full_rc5 = true;
212 220
213 if (rc5_device < 0) 221 if (rc5_device < 0)
214 budget_ci->ir.rc5_device = 0x1f; 222 budget_ci->ir.rc5_device = 0x1f;
@@ -217,24 +225,24 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
217 case 0x1017: 225 case 0x1017:
218 case 0x1019: 226 case 0x1019:
219 case 0x101a: 227 case 0x101a:
228 case 0x101b:
220 /* for the Technotrend 1500 bundled remote */ 229 /* for the Technotrend 1500 bundled remote */
221 ir_codes = RC_MAP_TT_1500; 230 dev->map_name = RC_MAP_TT_1500;
222 break; 231 break;
223 default: 232 default:
224 /* unknown remote */ 233 /* unknown remote */
225 ir_codes = RC_MAP_BUDGET_CI_OLD; 234 dev->map_name = RC_MAP_BUDGET_CI_OLD;
226 break; 235 break;
227 } 236 }
228 237
229 error = ir_input_register(input_dev, ir_codes, NULL, MODULE_NAME); 238 error = rc_register_device(dev);
230 if (error) { 239 if (error) {
231 printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error); 240 printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
241 rc_free_device(dev);
232 return error; 242 return error;
233 } 243 }
234 244
235 /* note: these must be after input_register_device */ 245 budget_ci->ir.dev = dev;
236 input_dev->rep[REP_DELAY] = 400;
237 input_dev->rep[REP_PERIOD] = 250;
238 246
239 tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt, 247 tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,
240 (unsigned long) budget_ci); 248 (unsigned long) budget_ci);
@@ -248,13 +256,12 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
248static void msp430_ir_deinit(struct budget_ci *budget_ci) 256static void msp430_ir_deinit(struct budget_ci *budget_ci)
249{ 257{
250 struct saa7146_dev *saa = budget_ci->budget.dev; 258 struct saa7146_dev *saa = budget_ci->budget.dev;
251 struct input_dev *dev = budget_ci->ir.dev;
252 259
253 SAA7146_IER_DISABLE(saa, MASK_06); 260 SAA7146_IER_DISABLE(saa, MASK_06);
254 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT); 261 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
255 tasklet_kill(&budget_ci->ir.msp430_irq_tasklet); 262 tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
256 263
257 ir_input_unregister(dev); 264 rc_unregister_device(budget_ci->ir.dev);
258} 265}
259 266
260static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address) 267static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
@@ -1383,6 +1390,23 @@ static void frontend_init(struct budget_ci *budget_ci)
1383 } 1390 }
1384 break; 1391 break;
1385 1392
1393 case 0x101b: /* TT S-1500B (BSBE1-D01A - STV0288/STB6000/LNBP21) */
1394 budget_ci->budget.dvb_frontend = dvb_attach(stv0288_attach, &stv0288_bsbe1_d01a_config, &budget_ci->budget.i2c_adap);
1395 if (budget_ci->budget.dvb_frontend) {
1396 if (dvb_attach(stb6000_attach, budget_ci->budget.dvb_frontend, 0x63, &budget_ci->budget.i2c_adap)) {
1397 if (!dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, 0, 0)) {
1398 printk(KERN_ERR "%s: No LNBP21 found!\n", __func__);
1399 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1400 budget_ci->budget.dvb_frontend = NULL;
1401 }
1402 } else {
1403 printk(KERN_ERR "%s: No STB6000 found!\n", __func__);
1404 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1405 budget_ci->budget.dvb_frontend = NULL;
1406 }
1407 }
1408 break;
1409
1386 case 0x1019: // TT S2-3200 PCI 1410 case 0x1019: // TT S2-3200 PCI
1387 /* 1411 /*
1388 * NOTE! on some STB0899 versions, the internal PLL takes a longer time 1412 * NOTE! on some STB0899 versions, the internal PLL takes a longer time
@@ -1513,6 +1537,7 @@ MAKE_BUDGET_INFO(ttbtci, "TT-Budget-T-CI PCI", BUDGET_TT);
1513MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT); 1537MAKE_BUDGET_INFO(ttbcci, "TT-Budget-C-CI PCI", BUDGET_TT);
1514MAKE_BUDGET_INFO(ttc1501, "TT-Budget C-1501 PCI", BUDGET_TT); 1538MAKE_BUDGET_INFO(ttc1501, "TT-Budget C-1501 PCI", BUDGET_TT);
1515MAKE_BUDGET_INFO(tt3200, "TT-Budget S2-3200 PCI", BUDGET_TT); 1539MAKE_BUDGET_INFO(tt3200, "TT-Budget S2-3200 PCI", BUDGET_TT);
1540MAKE_BUDGET_INFO(ttbs1500b, "TT-Budget S-1500B PCI", BUDGET_TT);
1516 1541
1517static struct pci_device_id pci_tbl[] = { 1542static struct pci_device_id pci_tbl[] = {
1518 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c), 1543 MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
@@ -1523,6 +1548,7 @@ static struct pci_device_id pci_tbl[] = {
1523 MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017), 1548 MAKE_EXTENSION_PCI(ttbs2, 0x13c2, 0x1017),
1524 MAKE_EXTENSION_PCI(ttc1501, 0x13c2, 0x101a), 1549 MAKE_EXTENSION_PCI(ttc1501, 0x13c2, 0x101a),
1525 MAKE_EXTENSION_PCI(tt3200, 0x13c2, 0x1019), 1550 MAKE_EXTENSION_PCI(tt3200, 0x13c2, 0x1019),
1551 MAKE_EXTENSION_PCI(ttbs1500b, 0x13c2, 0x101b),
1526 { 1552 {
1527 .vendor = 0, 1553 .vendor = 0,
1528 } 1554 }
diff --git a/drivers/media/dvb/ttpci/budget-core.c b/drivers/media/dvb/ttpci/budget-core.c
index ba18e56d5f11..37666d4edab6 100644
--- a/drivers/media/dvb/ttpci/budget-core.c
+++ b/drivers/media/dvb/ttpci/budget-core.c
@@ -31,7 +31,7 @@
31 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 31 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
32 * 32 *
33 * 33 *
34 * the project's page is at http://www.linuxtv.org/dvb/ 34 * the project's page is at http://www.linuxtv.org/
35 */ 35 */
36 36
37 37
@@ -495,8 +495,6 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
495 if (bi->type != BUDGET_FS_ACTIVY) 495 if (bi->type != BUDGET_FS_ACTIVY)
496 saa7146_write(dev, GPIO_CTRL, 0x500000); /* GPIO 3 = 1 */ 496 saa7146_write(dev, GPIO_CTRL, 0x500000); /* GPIO 3 = 1 */
497 497
498 budget->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
499
500 strlcpy(budget->i2c_adap.name, budget->card->name, sizeof(budget->i2c_adap.name)); 498 strlcpy(budget->i2c_adap.name, budget->card->name, sizeof(budget->i2c_adap.name));
501 499
502 saa7146_i2c_adapter_prepare(dev, &budget->i2c_adap, SAA7146_I2C_BUS_BIT_RATE_120); 500 saa7146_i2c_adapter_prepare(dev, &budget->i2c_adap, SAA7146_I2C_BUS_BIT_RATE_120);
diff --git a/drivers/media/dvb/ttpci/budget-patch.c b/drivers/media/dvb/ttpci/budget-patch.c
index 9c92f9ddd223..3395d1a90516 100644
--- a/drivers/media/dvb/ttpci/budget-patch.c
+++ b/drivers/media/dvb/ttpci/budget-patch.c
@@ -27,7 +27,7 @@
27 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 27 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
28 * 28 *
29 * 29 *
30 * the project's page is at http://www.linuxtv.org/dvb/ 30 * the project's page is at http://www.linuxtv.org/
31 */ 31 */
32 32
33#include "av7110.h" 33#include "av7110.h"
@@ -539,7 +539,7 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
539** increment. That's how the 7146 is programmed to do event 539** increment. That's how the 7146 is programmed to do event
540** counting in this budget-patch.c 540** counting in this budget-patch.c
541** I *think* HPS setting has something to do with the phase 541** I *think* HPS setting has something to do with the phase
542** of HS but I cant be 100% sure in that. 542** of HS but I can't be 100% sure in that.
543 543
544** hardware debug note: a working budget card (including budget patch) 544** hardware debug note: a working budget card (including budget patch)
545** with vpeirq() interrupt setup in mode "0x90" (every 64K) will 545** with vpeirq() interrupt setup in mode "0x90" (every 64K) will
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
index 874a10a9d493..d238fb9371a7 100644
--- a/drivers/media/dvb/ttpci/budget.c
+++ b/drivers/media/dvb/ttpci/budget.c
@@ -31,7 +31,7 @@
31 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 31 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
32 * 32 *
33 * 33 *
34 * the project's page is at http://www.linuxtv.org/dvb/ 34 * the project's page is at http://www.linuxtv.org/
35 */ 35 */
36 36
37#include "budget.h" 37#include "budget.h"
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index 4a3f2b8ea37d..420bb42d5233 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -52,7 +52,7 @@
52 my TTUSB, so let it undef'd unless you want to implement another 52 my TTUSB, so let it undef'd unless you want to implement another
53 frontend. never tested. 53 frontend. never tested.
54 54
55 DEBUG: 55 debug:
56 define it to > 3 for really hardcore debugging. you probably don't want 56 define it to > 3 for really hardcore debugging. you probably don't want
57 this unless the device doesn't load at all. > 2 for bandwidth statistics. 57 this unless the device doesn't load at all. > 2 for bandwidth statistics.
58*/ 58*/
@@ -134,20 +134,19 @@ struct ttusb {
134/* ugly workaround ... don't know why it's necessary to read */ 134/* ugly workaround ... don't know why it's necessary to read */
135/* all result codes. */ 135/* all result codes. */
136 136
137#define DEBUG 0
138static int ttusb_cmd(struct ttusb *ttusb, 137static int ttusb_cmd(struct ttusb *ttusb,
139 const u8 * data, int len, int needresult) 138 const u8 * data, int len, int needresult)
140{ 139{
141 int actual_len; 140 int actual_len;
142 int err; 141 int err;
143#if DEBUG >= 3
144 int i; 142 int i;
145 143
146 printk(">"); 144 if (debug >= 3) {
147 for (i = 0; i < len; ++i) 145 printk(KERN_DEBUG ">");
148 printk(" %02x", data[i]); 146 for (i = 0; i < len; ++i)
149 printk("\n"); 147 printk(KERN_CONT " %02x", data[i]);
150#endif 148 printk(KERN_CONT "\n");
149 }
151 150
152 if (mutex_lock_interruptible(&ttusb->semusb) < 0) 151 if (mutex_lock_interruptible(&ttusb->semusb) < 0)
153 return -EAGAIN; 152 return -EAGAIN;
@@ -176,13 +175,15 @@ static int ttusb_cmd(struct ttusb *ttusb,
176 mutex_unlock(&ttusb->semusb); 175 mutex_unlock(&ttusb->semusb);
177 return err; 176 return err;
178 } 177 }
179#if DEBUG >= 3 178
180 actual_len = ttusb->last_result[3] + 4; 179 if (debug >= 3) {
181 printk("<"); 180 actual_len = ttusb->last_result[3] + 4;
182 for (i = 0; i < actual_len; ++i) 181 printk(KERN_DEBUG "<");
183 printk(" %02x", ttusb->last_result[i]); 182 for (i = 0; i < actual_len; ++i)
184 printk("\n"); 183 printk(KERN_CONT " %02x", ttusb->last_result[i]);
185#endif 184 printk(KERN_CONT "\n");
185 }
186
186 if (!needresult) 187 if (!needresult)
187 mutex_unlock(&ttusb->semusb); 188 mutex_unlock(&ttusb->semusb);
188 return 0; 189 return 0;
@@ -334,6 +335,7 @@ static int ttusb_boot_dsp(struct ttusb *ttusb)
334 err = ttusb_cmd(ttusb, b, 4, 0); 335 err = ttusb_cmd(ttusb, b, 4, 0);
335 336
336 done: 337 done:
338 release_firmware(fw);
337 if (err) { 339 if (err) {
338 dprintk("%s: usb_bulk_msg() failed, return value %i!\n", 340 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
339 __func__, err); 341 __func__, err);
@@ -635,16 +637,13 @@ static void ttusb_process_frame(struct ttusb *ttusb, u8 * data, int len)
635 ++ttusb->mux_state; 637 ++ttusb->mux_state;
636 else { 638 else {
637 ttusb->mux_state = 0; 639 ttusb->mux_state = 0;
638#if DEBUG > 3
639 if (ttusb->insync)
640 printk("%02x ", data[-1]);
641#else
642 if (ttusb->insync) { 640 if (ttusb->insync) {
643 printk("%s: lost sync.\n", 641 dprintk("%s: %02x\n",
642 __func__, data[-1]);
643 printk(KERN_INFO "%s: lost sync.\n",
644 __func__); 644 __func__);
645 ttusb->insync = 0; 645 ttusb->insync = 0;
646 } 646 }
647#endif
648 } 647 }
649 break; 648 break;
650 case 3: 649 case 3:
@@ -743,6 +742,9 @@ static void ttusb_process_frame(struct ttusb *ttusb, u8 * data, int len)
743static void ttusb_iso_irq(struct urb *urb) 742static void ttusb_iso_irq(struct urb *urb)
744{ 743{
745 struct ttusb *ttusb = urb->context; 744 struct ttusb *ttusb = urb->context;
745 struct usb_iso_packet_descriptor *d;
746 u8 *data;
747 int len, i;
746 748
747 if (!ttusb->iso_streaming) 749 if (!ttusb->iso_streaming)
748 return; 750 return;
@@ -754,21 +756,14 @@ static void ttusb_iso_irq(struct urb *urb)
754#endif 756#endif
755 757
756 if (!urb->status) { 758 if (!urb->status) {
757 int i;
758 for (i = 0; i < urb->number_of_packets; ++i) { 759 for (i = 0; i < urb->number_of_packets; ++i) {
759 struct usb_iso_packet_descriptor *d;
760 u8 *data;
761 int len;
762 numpkt++; 760 numpkt++;
763 if (time_after_eq(jiffies, lastj + HZ)) { 761 if (time_after_eq(jiffies, lastj + HZ)) {
764#if DEBUG > 2 762 dprintk("frames/s: %lu (ts: %d, stuff %d, "
765 printk 763 "sec: %d, invalid: %d, all: %d)\n",
766 ("frames/s: %d (ts: %d, stuff %d, sec: %d, invalid: %d, all: %d)\n", 764 numpkt * HZ / (jiffies - lastj),
767 numpkt * HZ / (jiffies - lastj), 765 numts, numstuff, numsec, numinvalid,
768 numts, numstuff, numsec, numinvalid, 766 numts + numstuff + numsec + numinvalid);
769 numts + numstuff + numsec +
770 numinvalid);
771#endif
772 numts = numstuff = numsec = numinvalid = 0; 767 numts = numstuff = numsec = numinvalid = 0;
773 lastj = jiffies; 768 lastj = jiffies;
774 numpkt = 0; 769 numpkt = 0;
@@ -1694,7 +1689,6 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
1694 1689
1695 i2c_set_adapdata(&ttusb->i2c_adap, ttusb); 1690 i2c_set_adapdata(&ttusb->i2c_adap, ttusb);
1696 1691
1697 ttusb->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
1698 ttusb->i2c_adap.algo = &ttusb_dec_algo; 1692 ttusb->i2c_adap.algo = &ttusb_dec_algo;
1699 ttusb->i2c_adap.algo_data = NULL; 1693 ttusb->i2c_adap.algo_data = NULL;
1700 ttusb->i2c_adap.dev.parent = &udev->dev; 1694 ttusb->i2c_adap.dev.parent = &udev->dev;
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index fe1b8037b247..f893bffa08a3 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -234,7 +234,7 @@ static void ttusb_dec_handle_irq( struct urb *urb)
234 * (with buffer[3] == 0x40) in an intervall of ~100ms. 234 * (with buffer[3] == 0x40) in an intervall of ~100ms.
235 * But to handle this correctly we had to imlemenent some 235 * But to handle this correctly we had to imlemenent some
236 * kind of timer which signals a 'key up' event if no 236 * kind of timer which signals a 'key up' event if no
237 * keyrepeat signal is recieved for lets say 200ms. 237 * keyrepeat signal is received for lets say 200ms.
238 * this should/could be added later ... 238 * this should/could be added later ...
239 * for now lets report each signal as a key down and up*/ 239 * for now lets report each signal as a key down and up*/
240 dprintk("%s:rc signal:%d\n", __func__, buffer[4]); 240 dprintk("%s:rc signal:%d\n", __func__, buffer[4]);