summaryrefslogtreecommitdiff
path: root/linux/drivers/media/dvb/ttpci/budget-av.c
diff options
context:
space:
mode:
Diffstat (limited to 'linux/drivers/media/dvb/ttpci/budget-av.c')
-rw-r--r--linux/drivers/media/dvb/ttpci/budget-av.c344
1 files changed, 336 insertions, 8 deletions
diff --git a/linux/drivers/media/dvb/ttpci/budget-av.c b/linux/drivers/media/dvb/ttpci/budget-av.c
index 036442e33..28792962d 100644
--- a/linux/drivers/media/dvb/ttpci/budget-av.c
+++ b/linux/drivers/media/dvb/ttpci/budget-av.c
@@ -31,6 +31,9 @@
*/
#include "budget.h"
+#include "stv0299.h"
+#include "tda10021.h"
+#include "tda1004x.h"
#include <media/saa7146_vv.h>
struct budget_av {
@@ -159,6 +162,328 @@ static int saa7113_setinput (struct budget_av *budget_av, int input)
return 0;
}
+
+static int philips_su1278_ty_ci_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio)
+{
+ u8 aclk = 0;
+ u8 bclk = 0;
+ u8 m1;
+
+ aclk = 0xb5;
+ if (srate < 2000000) bclk = 0x86;
+ else if (srate < 5000000) bclk = 0x89;
+ else if (srate < 15000000) bclk = 0x8f;
+ else if (srate < 45000000) bclk = 0x95;
+
+ m1 = 0x14;
+ if (srate < 4000000) m1 = 0x10;
+
+ stv0299_writereg (fe, 0x13, aclk);
+ stv0299_writereg (fe, 0x14, bclk);
+ stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff);
+ stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff);
+ stv0299_writereg (fe, 0x21, (ratio ) & 0xf0);
+ stv0299_writereg (fe, 0x0f, 0x80 | m1);
+
+ return 0;
+}
+
+static int philips_su1278_ty_ci_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
+{
+ struct budget_av* budget_av = (struct budget_av*) fe->dvb->priv;
+ u32 div;
+ u8 buf[4];
+ struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) };
+
+ if ((params->frequency < 950000) || (params->frequency > 2150000)) return -EINVAL;
+
+ div = (params->frequency + (125 - 1)) / 125; // round correctly
+ buf[0] = (div >> 8) & 0x7f;
+ buf[1] = div & 0xff;
+ buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4;
+ buf[3] = 0x20;
+
+ if (params->u.qpsk.symbol_rate < 4000000) buf[3] |= 1;
+
+ if (params->frequency < 1250000) buf[3] |= 0;
+ else if (params->frequency < 1550000) buf[3] |= 0x40;
+ else if (params->frequency < 2050000) buf[3] |= 0x80;
+ else if (params->frequency < 2150000) buf[3] |= 0xC0;
+
+ if (i2c_transfer (&budget_av->budget.i2c_adap, &msg, 1) != 1) return -EIO;
+ return 0;
+}
+
+static u8 typhoon_cinergy1200s_inittab[] = {
+ 0x01, 0x15,
+ 0x02, 0x30,
+ 0x03, 0x00,
+ 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
+ 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
+ 0x06, 0x40, /* DAC not used, set to high impendance mode */
+ 0x07, 0x00, /* DAC LSB */
+ 0x08, 0x40, /* DiSEqC off */
+ 0x09, 0x00, /* FIFO */
+ 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
+ 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
+ 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
+ 0x10, 0x3f, // AGC2 0x3d
+ 0x11, 0x84,
+ 0x12, 0xb5, // Lock detect: -64 Carrier freq detect:on
+ 0x15, 0xc9, // lock detector threshold
+ 0x16, 0x00,
+ 0x17, 0x00,
+ 0x18, 0x00,
+ 0x19, 0x00,
+ 0x1a, 0x00,
+ 0x1f, 0x50,
+ 0x20, 0x00,
+ 0x21, 0x00,
+ 0x22, 0x00,
+ 0x23, 0x00,
+ 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
+ 0x29, 0x1e, // 1/2 threshold
+ 0x2a, 0x14, // 2/3 threshold
+ 0x2b, 0x0f, // 3/4 threshold
+ 0x2c, 0x09, // 5/6 threshold
+ 0x2d, 0x05, // 7/8 threshold
+ 0x2e, 0x01,
+ 0x31, 0x1f, // test all FECs
+ 0x32, 0x19, // viterbi and synchro search
+ 0x33, 0xfc, // rs control
+ 0x34, 0x93, // error control
+ 0x0f, 0x92,
+ 0xff, 0xff
+};
+
+static struct stv0299_config typhoon_config = {
+ .demod_address = 0x68,
+ .inittab = typhoon_cinergy1200s_inittab,
+ .mclk = 88000000UL,
+ .invert = 0,
+ .enhanced_tuning = 0,
+ .skip_reinit = 0,
+ .lock_output = STV0229_LOCKOUTPUT_1,
+ .volt13_op0_op1 = STV0299_VOLT13_OP0,
+ .min_delay_ms = 100,
+ .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate,
+ .pll_set = philips_su1278_ty_ci_pll_set,
+};
+
+
+static struct stv0299_config cinergy_1200s_config = {
+ .demod_address = 0x68,
+ .inittab = typhoon_cinergy1200s_inittab,
+ .mclk = 88000000UL,
+ .invert = 0,
+ .enhanced_tuning = 0,
+ .skip_reinit = 0,
+ .lock_output = STV0229_LOCKOUTPUT_0,
+ .volt13_op0_op1 = STV0299_VOLT13_OP0,
+ .min_delay_ms = 100,
+ .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate,
+ .pll_set = philips_su1278_ty_ci_pll_set,
+};
+
+
+static int philips_cu1216_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
+{
+ struct budget* budget = (struct budget*) fe->dvb->priv;
+ u8 buf[4];
+ struct i2c_msg msg= { .addr=0x60,.flags=0,.buf=buf,.len=sizeof(buf) };
+
+#define TUNER_MUL 62500
+
+ u32 div = (params->frequency + 36125000 + TUNER_MUL/2) / TUNER_MUL;
+
+ buf[0] = (div>>8) & 0x7f;
+ buf[1] = div & 0xff;
+ buf[2] = 0x8e;
+ buf[3] =(params->frequency < 174500000 ? 0xa1 :
+ params->frequency < 454000000 ? 0x92 : 0x34);
+
+ if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO;
+ return 0;
+}
+
+static struct tda10021_config philips_cu1216_config = {
+ .demod_address = 0x0c,
+ .pll_set = philips_cu1216_pll_set,
+};
+
+
+
+
+static int philips_tu1216_pll_init(struct dvb_frontend* fe)
+{
+ struct budget* budget = (struct budget*) fe->dvb->priv;
+ static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };
+ static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
+ struct i2c_msg tuner_msg = { .addr=0x60, .flags=0, .buf=tu1216_init, .len=sizeof(tu1216_init) };
+
+ // setup PLL configuration
+ if (i2c_transfer(&budget->i2c_adap, &tuner_msg, 1) != 1) return -EIO;
+ msleep(1);
+
+ // disable the mc44BC374c (do not check for errors)
+ tuner_msg.addr = 0x65;
+ tuner_msg.buf = disable_mc44BC374c;
+ tuner_msg.len = sizeof(disable_mc44BC374c);
+ if (i2c_transfer(&budget->i2c_adap, &tuner_msg, 1) != 1) {
+ i2c_transfer(&budget->i2c_adap, &tuner_msg, 1);
+ }
+
+ return 0;
+}
+
+static int philips_tu1216_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
+{
+ struct budget* budget = (struct budget*) fe->dvb->priv;
+ u8 tuner_buf[4];
+ struct i2c_msg tuner_msg = {.addr=0x60, .flags=0, .buf=tuner_buf, .len=sizeof(tuner_buf) };
+ int tuner_frequency = 0;
+ u8 band, cp, filter;
+
+ // determine charge pump
+ tuner_frequency = params->frequency + 36130000;
+ if (tuner_frequency < 87000000) return -EINVAL;
+ else if (tuner_frequency < 130000000) cp = 3;
+ else if (tuner_frequency < 160000000) cp = 5;
+ else if (tuner_frequency < 200000000) cp = 6;
+ else if (tuner_frequency < 290000000) cp = 3;
+ else if (tuner_frequency < 420000000) cp = 5;
+ else if (tuner_frequency < 480000000) cp = 6;
+ else if (tuner_frequency < 620000000) cp = 3;
+ else if (tuner_frequency < 830000000) cp = 5;
+ else if (tuner_frequency < 895000000) cp = 7;
+ else return -EINVAL;
+
+ // determine band
+ if (params->frequency < 49000000) return -EINVAL;
+ else if (params->frequency < 159000000) band = 1;
+ else if (params->frequency < 444000000) band = 2;
+ else if (params->frequency < 861000000) band = 4;
+ else return -EINVAL;
+
+ // setup PLL filter
+ switch (params->u.ofdm.bandwidth) {
+ case BANDWIDTH_6_MHZ:
+ tda1004x_write_byte(fe, 0x0C, 0);
+ filter = 0;
+ break;
+
+ case BANDWIDTH_7_MHZ:
+ tda1004x_write_byte(fe, 0x0C, 0);
+ filter = 0;
+ break;
+
+ case BANDWIDTH_8_MHZ:
+ tda1004x_write_byte(fe, 0x0C, 0xFF);
+ filter = 1;
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ // calculate divisor
+ // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
+ tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000;
+
+ // setup tuner buffer
+ tuner_buf[0] = tuner_frequency >> 8;
+ tuner_buf[1] = tuner_frequency & 0xff;
+ tuner_buf[2] = 0xca;
+ tuner_buf[3] = (cp << 5) | (filter << 3) | band;
+
+ if (i2c_transfer(&budget->i2c_adap, &tuner_msg, 1) != 1) return -EIO;
+
+ msleep(1);
+ return 0;
+}
+
+static int philips_tu1216_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
+{
+ struct budget* budget = (struct budget*) fe->dvb->priv;
+
+ return request_firmware(fw, name, &budget->dev->pci->dev);
+}
+
+struct tda1004x_config philips_tu1216_config = {
+
+ .demod_address = 0x8,
+ .invert = 1,
+ .pll_init = philips_tu1216_pll_init,
+ .pll_set = philips_tu1216_pll_set,
+ .request_firmware = philips_tu1216_request_firmware,
+};
+
+
+
+
+static u8 read_pwm(struct budget_av* budget_av)
+{
+ u8 b = 0xff;
+ u8 pwm;
+ struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 },
+ { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} };
+
+ if ((i2c_transfer(&budget_av->budget.i2c_adap, msg, 2) != 2) || (pwm == 0xff))
+ pwm = 0x48;
+
+ return pwm;
+}
+
+
+static void frontend_init(struct budget_av *budget_av)
+{
+ switch(budget_av->budget.dev->pci->subsystem_device) {
+ case 0x4f56: // Typhoon/KNC1 DVB-S budget (stv0299/Philips SU1278(tsa5059))
+ budget_av->budget.dvb_frontend = stv0299_attach(&typhoon_config, &budget_av->budget.i2c_adap);
+ if (budget_av->budget.dvb_frontend != NULL) {
+ break;
+ }
+ break;
+
+ case 0x1154: // TerraTec Cinergy 1200 DVB-S (stv0299/Philips SU1278(tsa5059))
+ budget_av->budget.dvb_frontend = stv0299_attach(&cinergy_1200s_config, &budget_av->budget.i2c_adap);
+ if (budget_av->budget.dvb_frontend != NULL) {
+ break;
+ }
+ break;
+
+ case 0x1156: // Terratec Cinergy 1200 DVB-C (tda10021/Philips CU1216(tua6034))
+ budget_av->budget.dvb_frontend = tda10021_attach(&philips_cu1216_config, &budget_av->budget.i2c_adap, read_pwm(budget_av));
+ if (budget_av->budget.dvb_frontend) {
+ break;
+ }
+ break;
+
+ case 0x1157: // Terratec Cinergy 1200 DVB-T (tda10046/Philips TU1216(tda6651tt))
+ budget_av->budget.dvb_frontend = tda10046_attach(&philips_tu1216_config, &budget_av->budget.i2c_adap);
+ if (budget_av->budget.dvb_frontend) {
+ break;
+ }
+ break;
+ }
+
+ if (budget_av->budget.dvb_frontend == NULL) {
+ printk("budget_av: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
+ budget_av->budget.dev->pci->vendor,
+ budget_av->budget.dev->pci->device,
+ budget_av->budget.dev->pci->subsystem_vendor,
+ budget_av->budget.dev->pci->subsystem_device);
+ } else {
+ if (dvb_register_frontend(budget_av->budget.dvb_adapter, budget_av->budget.dvb_frontend)) {
+ printk("budget-av: Frontend registration failed!\n");
+ if (budget_av->budget.dvb_frontend->ops->release)
+ budget_av->budget.dvb_frontend->ops->release(budget_av->budget.dvb_frontend);
+ budget_av->budget.dvb_frontend = NULL;
+ }
+ }
+}
+
+
static int budget_av_detach (struct saa7146_dev *dev)
{
struct budget_av *budget_av = (struct budget_av*) dev->ext_priv;
@@ -173,7 +498,7 @@ static int budget_av_detach (struct saa7146_dev *dev)
saa7146_unregister_device (&budget_av->vd, dev);
}
-
+ if (budget_av->budget.dvb_frontend != NULL) dvb_unregister_frontend(budget_av->budget.dvb_frontend);
err = ttpci_budget_deinit (&budget_av->budget);
kfree (budget_av);
@@ -187,16 +512,11 @@ static int budget_av_attach (struct saa7146_dev* dev,
struct saa7146_pci_extension_data *info)
{
struct budget_av *budget_av;
- struct budget_info *bi = info->ext_priv;
u8 *mac;
int err;
dprintk(2, "dev: %p\n", dev);
- if (bi->type != BUDGET_KNC1 && bi->type != BUDGET_CIN1200) {
- return -ENODEV;
- }
-
if (!(budget_av = kmalloc(sizeof(struct budget_av), GFP_KERNEL)))
return -ENOMEM;
@@ -260,6 +580,10 @@ static int budget_av_attach (struct saa7146_dev* dev,
printk("KNC1-%d: MAC addr = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
budget_av->budget.dvb_adapter->num,
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+
+ budget_av->budget.dvb_adapter->priv = budget_av;
+ frontend_init(budget_av);
+
return 0;
}
@@ -343,11 +667,15 @@ static struct saa7146_ext_vv vv_data = {
static struct saa7146_extension budget_extension;
MAKE_BUDGET_INFO(knc1, "KNC1 DVB-S", BUDGET_KNC1);
-MAKE_BUDGET_INFO(cin1200, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200);
+MAKE_BUDGET_INFO(cin1200s, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S);
+MAKE_BUDGET_INFO(cin1200c, "Terratec Cinergy 1200 DVB-C", BUDGET_CIN1200C);
+MAKE_BUDGET_INFO(cin1200t, "Terratec Cinergy 1200 DVB-T", BUDGET_CIN1200T);
static struct pci_device_id pci_tbl [] = {
MAKE_EXTENSION_PCI(knc1, 0x1131, 0x4f56),
- MAKE_EXTENSION_PCI(cin1200, 0x153b, 0x1154),
+ MAKE_EXTENSION_PCI(cin1200s, 0x153b, 0x1154),
+ MAKE_EXTENSION_PCI(cin1200c, 0x153b, 0x1156),
+ MAKE_EXTENSION_PCI(cin1200t, 0x153b, 0x1157),
{
.vendor = 0,
}